* Test draw instancing.
*/
+#include <stdio.h>
+#include <string.h>
+
#include "state_tracker/graw.h"
#include "pipe/p_screen.h"
#include "pipe/p_context.h"
#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,
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 {
};
+static int draw_elements = 0;
+
+
/**
* Vertex data.
* Each vertex has three attributes: position, color and translation.
};
+static ushort indices[3] = { 0, 2, 1 };
+
+
static void set_viewport( float x, float y,
float width, float height,
float near, float far)
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 )
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
}
+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 );