diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gallium/tests/graw/tri-instanced.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/src/gallium/tests/graw/tri-instanced.c b/src/gallium/tests/graw/tri-instanced.c index 1500f1b97fa..30e205f1434 100644 --- a/src/gallium/tests/graw/tri-instanced.c +++ b/src/gallium/tests/graw/tri-instanced.c @@ -2,6 +2,9 @@ * Test draw instancing. */ +#include <stdio.h> +#include <string.h> + #include "state_tracker/graw.h" #include "pipe/p_screen.h" #include "pipe/p_context.h" @@ -11,6 +14,7 @@ #include "util/u_debug.h" /* debug_dump_surface_bmp() */ #include "util/u_memory.h" /* Offset() */ + enum pipe_format formats[] = { PIPE_FORMAT_R8G8B8A8_UNORM, PIPE_FORMAT_B8G8R8A8_UNORM, @@ -23,6 +27,7 @@ static const int HEIGHT = 300; static struct pipe_screen *screen = NULL; static struct pipe_context *ctx = NULL; static struct pipe_surface *surf = NULL; +static struct pipe_resource *indexBuffer = NULL; static void *window = NULL; struct vertex { @@ -31,6 +36,9 @@ struct vertex { }; +static int draw_elements = 0; + + /** * Vertex data. * Each vertex has three attributes: position, color and translation. @@ -66,6 +74,9 @@ static float inst_data[NUM_INST][4] = }; +static ushort indices[3] = { 0, 2, 1 }; + + static void set_viewport( float x, float y, float width, float height, float near, float far) @@ -138,6 +149,14 @@ static void set_vertices( void ) ctx->set_vertex_buffers(ctx, 2, vbuf); + + /* index data */ + indexBuffer = screen->user_buffer_create(screen, + indices, + sizeof(indices), + PIPE_BIND_VERTEX_BUFFER); + + } static void set_vertex_shader( void ) @@ -178,8 +197,17 @@ static void draw( void ) float clear_color[4] = {1,0,1,1}; ctx->clear(ctx, PIPE_CLEAR_COLOR, clear_color, 0, 0); + /* draw NUM_INST triangles */ - ctx->draw_arrays_instanced(ctx, PIPE_PRIM_TRIANGLES, 0, 3, 0, NUM_INST); + if (draw_elements) + ctx->draw_elements_instanced(ctx, indexBuffer, 2, + 0, /* indexBias */ + PIPE_PRIM_TRIANGLES, + 0, 3, /* start, count */ + 0, NUM_INST); /* startInst, instCount */ + else + ctx->draw_arrays_instanced(ctx, PIPE_PRIM_TRIANGLES, 0, 3, 0, NUM_INST); + ctx->flush(ctx, PIPE_FLUSH_RENDER_CACHE, NULL); #if 0 @@ -286,8 +314,24 @@ static void init( void ) } +static void options(int argc, char *argv[]) +{ + int i; + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-e") == 0) + draw_elements = 1; + } + if (draw_elements) + printf("Using pipe_context::draw_elements_instanced()\n"); + else + printf("Using pipe_context::draw_arrays_instanced()\n"); +} + + int main( int argc, char *argv[] ) { + options(argc, argv); + init(); graw_set_display_func( draw ); |