summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2010-07-20 08:39:30 -0600
committerBrian Paul <brianp@vmware.com>2010-07-20 08:50:32 -0600
commit895086467e03b15d376dcdff0d772408dda03f88 (patch)
tree095ad859702fe61d962403430625a68399dcdda6
parent3b2ca688a7016fe504768ecb72f2e42c7b2905ac (diff)
graw/tests: pass -e option to test draw_elements_instanced()
-rw-r--r--src/gallium/tests/graw/tri-instanced.c46
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 );