PUBLIC void *graw_parse_fragment_shader( struct pipe_context *pipe,
const char *text );
+/* Parse a single command-line option, if any. Options include:
+ *
+ * -o <filename>
+ *
+ * If an option has been successfully parsed, argi is updated
+ * to point just after the option and return TRUE.
+ */
+PUBLIC boolean graw_parse_args(int *argi, int argc, char *argv[]);
+
+/* Saves surface contents to a file.
+ *
+ * If filename is NULL, the filename provided with the `-o' option
+ * is used. If the option has not been specified, the surface
+ * will not be saved.
+ *
+ * Returns TRUE if the surface has been saved.
+ */
+PUBLIC boolean graw_save_surface_to_file(struct pipe_context *pipe,
+ struct pipe_surface *surface,
+ const char *filename);
+
#endif
#include "pipe/p_context.h"
#include "pipe/p_state.h"
#include "tgsi/tgsi_text.h"
+#include "util/u_debug.h"
#include "util/u_memory.h"
#include "state_tracker/graw.h"
return pipe->create_fs_state(pipe, &state);
}
+static char out_filename[256] = "";
+
+PUBLIC boolean
+graw_parse_args(int *argi,
+ int argc,
+ char *argv[])
+{
+ if (strcmp(argv[*argi], "-o") == 0) {
+ if (*argi + 1 >= argc) {
+ return FALSE;
+ }
+
+ strncpy(out_filename, argv[*argi + 1], sizeof(out_filename) - 1);
+ out_filename[sizeof(out_filename) - 1] = '\0';
+ *argi += 2;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+PUBLIC boolean
+graw_save_surface_to_file(struct pipe_context *pipe,
+ struct pipe_surface *surface,
+ const char *filename)
+{
+ if (!filename || !*filename) {
+ filename = out_filename;
+ if (!filename || !*filename) {
+ return FALSE;
+ }
+ }
+
+ /* XXX: Make that working in release builds.
+ */
+ debug_dump_surface_bmp(pipe, filename, surface);
+ return TRUE;
+}
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
-#include "util/u_debug.h" /* debug_dump_surface_bmp() */
-
enum pipe_format formats[] = {
PIPE_FORMAT_R8G8B8A8_UNORM,
PIPE_FORMAT_B8G8R8A8_UNORM,
ctx->clear(ctx, PIPE_CLEAR_COLOR, clear_color, 0, 0);
ctx->flush(ctx, PIPE_FLUSH_RENDER_CACHE, NULL);
-#if 0
- /* At the moment, libgraw leaks out/makes available some of the
- * symbols from gallium/auxiliary, including these debug helpers.
- * Will eventually want to bless some of these paths, and lock the
- * others down so they aren't accessible from test programs.
- *
- * This currently just happens to work on debug builds - a release
- * build will probably fail to link here:
- */
- debug_dump_surface_bmp(ctx, "result.bmp", surf);
-#endif
+ graw_save_surface_to_file(ctx, surf, NULL);
screen->flush_frontbuffer(screen, surf, window);
}
ctx->set_framebuffer_state(ctx, &fb);
}
+static void args(int argc, char *argv[])
+{
+ int i;
+ for (i = 1; i < argc;) {
+ if (graw_parse_args(&i, argc, argv)) {
+ continue;
+ }
+ exit(1);
+ }
+}
int main( int argc, char *argv[] )
{
+ args(argc, argv);
init();
graw_set_display_func( draw );
#include "pipe/p_defines.h"
#include <stdio.h> /* for fread(), etc */
-#include "util/u_debug.h" /* debug_dump_surface_bmp() */
#include "util/u_inlines.h"
#include "util/u_memory.h" /* Offset() */
#include "util/u_draw_quad.h"
util_draw_arrays(ctx, PIPE_PRIM_TRIANGLES, 0, 3);
ctx->flush(ctx, PIPE_FLUSH_RENDER_CACHE, NULL);
-#if 0
- /* At the moment, libgraw leaks out/makes available some of the
- * symbols from gallium/auxiliary, including these debug helpers.
- * Will eventually want to bless some of these paths, and lock the
- * others down so they aren't accessible from test programs.
- *
- * This currently just happens to work on debug builds - a release
- * build will probably fail to link here:
- */
- debug_dump_surface_bmp(ctx, "result.bmp", surf);
-#endif
+ graw_save_surface_to_file(ctx, surf, NULL);
screen->flush_frontbuffer(screen, surf, window);
}
{
int i;
- for (i = 1; i < argc; i++) {
+ for (i = 1; i < argc;) {
+ if (graw_parse_args(&i, argc, argv)) {
+ continue;
+ }
if (strcmp(argv[i], "-fps") == 0) {
show_fps = 1;
+ i++;
}
else if (i == argc - 1) {
- filename = argv[i];
+ filename = argv[i];
+ i++;
}
else {
- usage(argv[0]);
- exit(1);
+ usage(argv[0]);
+ exit(1);
}
}
#include "pipe/p_defines.h"
#include <stdio.h> /* for fread(), etc */
-#include "util/u_debug.h" /* debug_dump_surface_bmp() */
#include "util/u_inlines.h"
#include "util/u_memory.h" /* Offset() */
#include "util/u_draw_quad.h"
ctx->flush(ctx, PIPE_FLUSH_RENDER_CACHE, NULL);
-#if 0
- /* At the moment, libgraw leaks out/makes available some of the
- * symbols from gallium/auxiliary, including these debug helpers.
- * Will eventually want to bless some of these paths, and lock the
- * others down so they aren't accessible from test programs.
- *
- * This currently just happens to work on debug builds - a release
- * build will probably fail to link here:
- */
- debug_dump_surface_bmp(ctx, "result.bmp", surf);
-#endif
+ graw_save_surface_to_file(ctx, surf, NULL);
screen->flush_frontbuffer(screen, surf, window);
}
{
int i;
- for (i = 1; i < argc; i++) {
+ for (i = 1; i < argc;) {
+ if (graw_parse_args(&i, argc, argv)) {
+ continue;
+ }
if (strcmp(argv[i], "-fps") == 0) {
show_fps = 1;
+ i++;
}
else if (strcmp(argv[i], "-strip") == 0) {
draw_strip = 1;
+ i++;
}
else if (i == argc - 1) {
- filename = argv[i];
+ filename = argv[i];
+ i++;
}
else {
- usage(argv[0]);
- exit(1);
+ usage(argv[0]);
+ exit(1);
}
}
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
-#include "util/u_debug.h" /* debug_dump_surface_bmp() */
#include "util/u_inlines.h"
#include "util/u_memory.h" /* Offset() */
#include "util/u_draw_quad.h"
util_draw_arrays(ctx, PIPE_PRIM_QUADS, 0, 4);
ctx->flush(ctx, PIPE_FLUSH_RENDER_CACHE, NULL);
-#if 0
- /* At the moment, libgraw leaks out/makes available some of the
- * symbols from gallium/auxiliary, including these debug helpers.
- * Will eventually want to bless some of these paths, and lock the
- * others down so they aren't accessible from test programs.
- *
- * This currently just happens to work on debug builds - a release
- * build will probably fail to link here:
- */
- debug_dump_surface_bmp(ctx, "result.bmp", surf);
-#endif
+ graw_save_surface_to_file(ctx, surf, NULL);
screen->flush_frontbuffer(screen, surf, window);
}
set_fragment_shader();
}
+static void args(int argc, char *argv[])
+{
+ int i;
+
+ for (i = 1; i < argc;) {
+ if (graw_parse_args(&i, argc, argv)) {
+ continue;
+ }
+ exit(1);
+ }
+}
int main( int argc, char *argv[] )
{
+ args(argc, argv);
init();
graw_set_display_func( draw );
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
-#include "util/u_debug.h" /* debug_dump_surface_bmp() */
#include "util/u_memory.h" /* Offset() */
#include "util/u_draw_quad.h"
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
-#include "util/u_debug.h" /* debug_dump_surface_bmp() */
#include "util/u_memory.h" /* Offset() */
#include "util/u_draw_quad.h"
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
-#include "util/u_debug.h" /* debug_dump_surface_bmp() */
#include "util/u_memory.h" /* Offset() */
#include "util/u_draw_quad.h"
ctx->flush(ctx, PIPE_FLUSH_RENDER_CACHE, NULL);
-#if 0
- /* At the moment, libgraw leaks out/makes available some of the
- * symbols from gallium/auxiliary, including these debug helpers.
- * Will eventually want to bless some of these paths, and lock the
- * others down so they aren't accessible from test programs.
- *
- * This currently just happens to work on debug builds - a release
- * build will probably fail to link here:
- */
- debug_dump_surface_bmp(ctx, "result.bmp", surf);
-#endif
+ graw_save_surface_to_file(ctx, surf, NULL);
screen->flush_frontbuffer(screen, surf, window);
}
static void options(int argc, char *argv[])
{
int i;
- for (i = 1; i < argc; i++) {
- if (strcmp(argv[i], "-e") == 0)
+
+ for (i = 1; i < argc;) {
+ if (graw_parse_args(&i, argc, argv)) {
+ continue;
+ }
+ if (strcmp(argv[i], "-e") == 0) {
draw_elements = 1;
+ i++;
+ }
+ else {
+ i++;
+ }
}
if (draw_elements)
printf("Using pipe_context::draw_elements_instanced()\n");
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
-#include "util/u_debug.h" /* debug_dump_surface_bmp() */
#include "util/u_memory.h" /* Offset() */
#include "util/u_draw_quad.h"
util_draw_arrays(ctx, PIPE_PRIM_TRIANGLES, 0, 3);
ctx->flush(ctx, PIPE_FLUSH_RENDER_CACHE, NULL);
-#if 0
- /* At the moment, libgraw leaks out/makes available some of the
- * symbols from gallium/auxiliary, including these debug helpers.
- * Will eventually want to bless some of these paths, and lock the
- * others down so they aren't accessible from test programs.
- *
- * This currently just happens to work on debug builds - a release
- * build will probably fail to link here:
- */
- debug_dump_surface_bmp(ctx, "result.bmp", surf);
-#endif
+ graw_save_surface_to_file(ctx, surf, NULL);
screen->flush_frontbuffer(screen, surf, window);
}
set_fragment_shader();
}
+static void args(int argc, char *argv[])
+{
+ int i;
+
+ for (i = 1; i < argc;) {
+ if (graw_parse_args(&i, argc, argv)) {
+ continue;
+ }
+ exit(1);
+ }
+}
int main( int argc, char *argv[] )
{
+ args(argc, argv);
init();
graw_set_display_func( draw );
#include <stdio.h> /* for fread(), etc */
-#include "util/u_debug.h" /* debug_dump_surface_bmp() */
#include "util/u_inlines.h"
#include "util/u_memory.h" /* Offset() */
#include "util/u_draw_quad.h"
util_draw_arrays(ctx, PIPE_PRIM_POINTS, 0, Elements(vertices));
ctx->flush(ctx, PIPE_FLUSH_RENDER_CACHE, NULL);
-#if 0
- /* At the moment, libgraw leaks out/makes available some of the
- * symbols from gallium/auxiliary, including these debug helpers.
- * Will eventually want to bless some of these paths, and lock the
- * others down so they aren't accessible from test programs.
- *
- * This currently just happens to work on debug builds - a release
- * build will probably fail to link here:
- */
- debug_dump_surface_bmp(ctx, "result.bmp", surf);
-#endif
+ graw_save_surface_to_file(ctx, surf, NULL);
screen->flush_frontbuffer(screen, surf, window);
}
{
int i;
- for (i = 1; i < argc; i++) {
+ for (i = 1; i < argc;) {
+ if (graw_parse_args(&i, argc, argv)) {
+ continue;
+ }
if (strcmp(argv[i], "-fps") == 0) {
show_fps = 1;
+ i++;
}
else if (i == argc - 1) {
- filename = argv[i];
+ filename = argv[i];
+ i++;
}
else {
- usage(argv[0]);
- exit(1);
+ usage(argv[0]);
+ exit(1);
}
}