Beispiel #1
0
static void set_vertices( void )
{
   struct pipe_vertex_element ve[2];
   struct pipe_vertex_buffer vbuf;
   void *handle;

   memset(ve, 0, sizeof ve);

   ve[0].src_offset = Offset(struct vertex, position);
   ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
   ve[1].src_offset = Offset(struct vertex, color);
   ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;

   handle = ctx->create_vertex_elements_state(ctx, 2, ve);
   ctx->bind_vertex_elements_state(ctx, handle);

   memset(&vbuf, 0, sizeof vbuf);

   vbuf.stride = sizeof( struct vertex );
   vbuf.buffer_offset = 0;
   vbuf.buffer = pipe_buffer_create_with_data(ctx,
                                              PIPE_BIND_VERTEX_BUFFER,
                                              PIPE_USAGE_STATIC,
                                              sizeof(vertices),
                                              vertices);

   ctx->set_vertex_buffers(ctx, 0, 1, &vbuf);
}
Beispiel #2
0
static void set_vertices( void )
{
   struct pipe_vertex_element ve[2];
   struct pipe_vertex_buffer vbuf;
   void *handle;
   int x,y;

   memset(ve, 0, sizeof ve);

   ve[0].src_offset = Offset(struct vertex, position);
   ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
   ve[1].src_offset = Offset(struct vertex, color);
   ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;

   handle = ctx->create_vertex_elements_state(ctx, 2, ve);
   ctx->bind_vertex_elements_state(ctx, handle);

   for (x = 0; x < MESH_SZ; x++) {
      for (y = 0; y < MESH_SZ; y++) {
         int i = y * MESH_SZ + x;
         vertices[i].position[0] = ((float)x)/MESH_SZ * 2.0 - 1.0;
         vertices[i].position[1] = ((float)y)/MESH_SZ * 2.0 - 1.0;
         vertices[i].position[2] = 0;
         vertices[i].position[3] = 1.0;

         vertices[i].color[0] = .5;
         vertices[i].color[1] = (float)x / (float)MESH_SZ;
         vertices[i].color[2] = (float)y / (float)MESH_SZ;
      }
   }

   memset(&vbuf, 0, sizeof vbuf);

   vbuf.stride = sizeof( struct vertex );
   vbuf.buffer_offset = 0;
   vbuf.buffer = pipe_buffer_create_with_data(ctx,
                                              PIPE_BIND_VERTEX_BUFFER,
                                              PIPE_USAGE_STATIC,
                                              sizeof(vertices),
                                              vertices);

   ctx->set_vertex_buffers(ctx, 0, 1, &vbuf);
}
Beispiel #3
0
static void set_vertices( void )
{
   struct pipe_vertex_element ve[3];
   struct pipe_vertex_buffer vbuf[2];
   struct pipe_index_buffer ibuf;
   void *handle;

   memset(ve, 0, sizeof ve);

   /* pos */
   ve[0].src_offset = Offset(struct vertex, position);
   ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
   ve[0].vertex_buffer_index = 0;

   /* color */
   ve[1].src_offset = Offset(struct vertex, color);
   ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
   ve[1].vertex_buffer_index = 0;

   /* per-instance info */
   ve[2].src_offset = 0;
   ve[2].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
   ve[2].vertex_buffer_index = 1;
   ve[2].instance_divisor = 1;

   handle = ctx->create_vertex_elements_state(ctx, 3, ve);
   ctx->bind_vertex_elements_state(ctx, handle);

   memset(&vbuf, 0, sizeof vbuf);

   /* vertex data */
   vbuf[0].stride = sizeof( struct vertex );
   vbuf[0].buffer_offset = 0;
   vbuf[0].buffer = pipe_buffer_create_with_data(ctx,
                                                 PIPE_BIND_VERTEX_BUFFER,
                                                 PIPE_USAGE_STATIC,
                                                 sizeof(vertices),
                                                 vertices);

   /* instance data */
   vbuf[1].stride = sizeof( inst_data[0] );
   vbuf[1].buffer_offset = 0;
   vbuf[1].buffer = pipe_buffer_create_with_data(ctx,
                                                 PIPE_BIND_VERTEX_BUFFER,
                                                 PIPE_USAGE_STATIC,
                                                 sizeof(inst_data),
                                                 inst_data);

   ctx->set_vertex_buffers(ctx, 0, 2, vbuf);

   /* index data */
   ibuf.buffer = pipe_buffer_create_with_data(ctx,
                                              PIPE_BIND_INDEX_BUFFER,
                                              PIPE_USAGE_STATIC,
                                              sizeof(indices),
                                              indices);
   ibuf.offset = 0;
   ibuf.index_size = 2;

   ctx->set_index_buffer(ctx, &ibuf);

}