st/mesa: overhaul vertex setup for clearing, glDrawPixels, glBitmap

Define a new st_util_vertex structure which is a bit smaller (9 floats
versus the previous 12 floats per vertex).  Clean up the glClear,
glDrawPixels and glBitmap code that sets up the vertex data and does the
drawing so it's all very similar.  This can lead to more consolidation.

v2: add assertion that vertex buffer slot == 0 to catch possible future
change in cso_get_aux_vertex_buffer_slot() behavior.

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
This commit is contained in:
Brian Paul 2016-02-16 10:22:31 -07:00
parent 2b1535f82f
commit b63fe0552b
5 changed files with 187 additions and 155 deletions

View file

@ -49,7 +49,6 @@
#include "pipe/p_defines.h" #include "pipe/p_defines.h"
#include "pipe/p_shader_tokens.h" #include "pipe/p_shader_tokens.h"
#include "util/u_inlines.h" #include "util/u_inlines.h"
#include "util/u_draw_quad.h"
#include "util/u_simple_shaders.h" #include "util/u_simple_shaders.h"
#include "util/u_upload_mgr.h" #include "util/u_upload_mgr.h"
#include "program/prog_instruction.h" #include "program/prog_instruction.h"
@ -282,7 +281,8 @@ setup_render_state(struct gl_context *ctx,
cso_set_viewport(cso, &vp); cso_set_viewport(cso, &vp);
} }
cso_set_vertex_elements(cso, 3, st->velems_util_draw); cso_set_vertex_elements(cso, 3, st->util_velems);
cso_set_stream_outputs(st->cso_context, 0, NULL, NULL); cso_set_stream_outputs(st->cso_context, 0, NULL, NULL);
} }
@ -322,7 +322,7 @@ draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
{ {
struct st_context *st = st_context(ctx); struct st_context *st = st_context(ctx);
struct pipe_context *pipe = st->pipe; struct pipe_context *pipe = st->pipe;
struct pipe_resource *vbuf = NULL; struct pipe_vertex_buffer vb = {0};
const float fb_width = (float) st->state.framebuffer.width; const float fb_width = (float) st->state.framebuffer.width;
const float fb_height = (float) st->state.framebuffer.height; const float fb_height = (float) st->state.framebuffer.height;
const float x0 = (float) x; const float x0 = (float) x;
@ -335,8 +335,7 @@ draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
const float clip_y0 = y0 / fb_height * 2.0f - 1.0f; const float clip_y0 = y0 / fb_height * 2.0f - 1.0f;
const float clip_x1 = x1 / fb_width * 2.0f - 1.0f; const float clip_x1 = x1 / fb_width * 2.0f - 1.0f;
const float clip_y1 = y1 / fb_height * 2.0f - 1.0f; const float clip_y1 = y1 / fb_height * 2.0f - 1.0f;
float (*vertices)[3][4]; /**< vertex pos + color + texcoord */ struct st_util_vertex *verts;
unsigned offset, i;
/* limit checks */ /* limit checks */
{ {
@ -360,9 +359,11 @@ draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
tBot = (float) height; tBot = (float) height;
} }
u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]), 4, vb.stride = sizeof(struct st_util_vertex);
&offset, &vbuf, (void **) &vertices);
if (!vbuf) { u_upload_alloc(st->uploader, 0, 4 * sizeof(struct st_util_vertex), 4,
&vb.buffer_offset, &vb.buffer, (void **) &verts);
if (!vb.buffer) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glBitmap"); _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBitmap");
restore_render_state(ctx); restore_render_state(ctx);
return; return;
@ -371,50 +372,57 @@ draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
/* Positions are in clip coords since we need to do clipping in case /* Positions are in clip coords since we need to do clipping in case
* the bitmap quad goes beyond the window bounds. * the bitmap quad goes beyond the window bounds.
*/ */
vertices[0][0][0] = clip_x0; verts[0].x = clip_x0;
vertices[0][0][1] = clip_y0; verts[0].y = clip_y0;
vertices[0][2][0] = sLeft; verts[0].z = z;
vertices[0][2][1] = tTop; verts[0].r = color[0];
verts[0].g = color[1];
verts[0].b = color[2];
verts[0].a = color[3];
verts[0].s = sLeft;
verts[0].t = tTop;
vertices[1][0][0] = clip_x1; verts[1].x = clip_x1;
vertices[1][0][1] = clip_y0; verts[1].y = clip_y0;
vertices[1][2][0] = sRight; verts[1].z = z;
vertices[1][2][1] = tTop; verts[1].r = color[0];
verts[1].g = color[1];
verts[1].b = color[2];
verts[1].a = color[3];
verts[1].s = sRight;
verts[1].t = tTop;
vertices[2][0][0] = clip_x1; verts[2].x = clip_x1;
vertices[2][0][1] = clip_y1; verts[2].y = clip_y1;
vertices[2][2][0] = sRight; verts[2].z = z;
vertices[2][2][1] = tBot; verts[2].r = color[0];
verts[2].g = color[1];
verts[2].b = color[2];
verts[2].a = color[3];
verts[2].s = sRight;
verts[2].t = tBot;
vertices[3][0][0] = clip_x0; verts[3].x = clip_x0;
vertices[3][0][1] = clip_y1; verts[3].y = clip_y1;
vertices[3][2][0] = sLeft; verts[3].z = z;
vertices[3][2][1] = tBot; verts[3].r = color[0];
verts[3].g = color[1];
/* same for all verts: */ verts[3].b = color[2];
for (i = 0; i < 4; i++) { verts[3].a = color[3];
vertices[i][0][2] = z; verts[3].s = sLeft;
vertices[i][0][3] = 1.0f; verts[3].t = tBot;
vertices[i][1][0] = color[0];
vertices[i][1][1] = color[1];
vertices[i][1][2] = color[2];
vertices[i][1][3] = color[3];
vertices[i][2][2] = 0.0; /*R*/
vertices[i][2][3] = 1.0; /*Q*/
}
u_upload_unmap(st->uploader); u_upload_unmap(st->uploader);
util_draw_vertex_buffer(pipe, st->cso_context, vbuf, cso_set_vertex_buffers(st->cso_context,
cso_get_aux_vertex_buffer_slot(st->cso_context), cso_get_aux_vertex_buffer_slot(st->cso_context),
offset, 1, &vb);
PIPE_PRIM_TRIANGLE_FAN,
4, /* verts */ cso_draw_arrays(st->cso_context, PIPE_PRIM_TRIANGLE_FAN, 0, 4);
3); /* attribs/vert */
restore_render_state(ctx); restore_render_state(ctx);
pipe_resource_reference(&vbuf, NULL); pipe_resource_reference(&vb.buffer, NULL);
/* We uploaded modified constants, need to invalidate them. */ /* We uploaded modified constants, need to invalidate them. */
st->dirty.mesa |= _NEW_PROGRAM_CONSTANTS; st->dirty.mesa |= _NEW_PROGRAM_CONSTANTS;

View file

@ -55,7 +55,6 @@
#include "util/u_framebuffer.h" #include "util/u_framebuffer.h"
#include "util/u_inlines.h" #include "util/u_inlines.h"
#include "util/u_simple_shaders.h" #include "util/u_simple_shaders.h"
#include "util/u_draw_quad.h"
#include "util/u_upload_mgr.h" #include "util/u_upload_mgr.h"
#include "cso_cache/cso_context.h" #include "cso_cache/cso_context.h"
@ -180,14 +179,12 @@ draw_quad(struct st_context *st,
{ {
struct cso_context *cso = st->cso_context; struct cso_context *cso = st->cso_context;
struct pipe_vertex_buffer vb = {0}; struct pipe_vertex_buffer vb = {0};
GLuint i; struct st_util_vertex *verts;
float (*vertices)[2][4]; /**< vertex pos + color */
vb.stride = 8 * sizeof(float); vb.stride = sizeof(struct st_util_vertex);
u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]), 4, u_upload_alloc(st->uploader, 0, 4 * sizeof(struct st_util_vertex), 4,
&vb.buffer_offset, &vb.buffer, &vb.buffer_offset, &vb.buffer, (void **) &verts);
(void **) &vertices);
if (!vb.buffer) { if (!vb.buffer) {
return; return;
} }
@ -195,28 +192,40 @@ draw_quad(struct st_context *st,
/* Convert Z from [0,1] to [-1,1] range */ /* Convert Z from [0,1] to [-1,1] range */
z = z * 2.0f - 1.0f; z = z * 2.0f - 1.0f;
/* positions */ /* Note: if we're only clearing depth/stencil we still setup vertices
vertices[0][0][0] = x0; * with color, but they'll be ignored.
vertices[0][0][1] = y0; */
verts[0].x = x0;
verts[0].y = y0;
verts[0].z = z;
verts[0].r = color->f[0];
verts[0].g = color->f[1];
verts[0].b = color->f[2];
verts[0].a = color->f[3];
vertices[1][0][0] = x1; verts[1].x = x1;
vertices[1][0][1] = y0; verts[1].y = y0;
verts[1].z = z;
verts[1].r = color->f[0];
verts[1].g = color->f[1];
verts[1].b = color->f[2];
verts[1].a = color->f[3];
vertices[2][0][0] = x1; verts[2].x = x1;
vertices[2][0][1] = y1; verts[2].y = y1;
verts[2].z = z;
verts[2].r = color->f[0];
verts[2].g = color->f[1];
verts[2].b = color->f[2];
verts[2].a = color->f[3];
vertices[3][0][0] = x0; verts[3].x = x0;
vertices[3][0][1] = y1; verts[3].y = y1;
verts[3].z = z;
/* same for all verts: */ verts[3].r = color->f[0];
for (i = 0; i < 4; i++) { verts[3].g = color->f[1];
vertices[i][0][2] = z; verts[3].b = color->f[2];
vertices[i][0][3] = 1.0; verts[3].a = color->f[3];
vertices[i][1][0] = color->f[0];
vertices[i][1][1] = color->f[1];
vertices[i][1][2] = color->f[2];
vertices[i][1][3] = color->f[3];
}
u_upload_unmap(st->uploader); u_upload_unmap(st->uploader);
@ -331,7 +340,7 @@ clear_with_quad(struct gl_context *ctx, unsigned clear_buffers)
cso_set_depth_stencil_alpha(st->cso_context, &depth_stencil); cso_set_depth_stencil_alpha(st->cso_context, &depth_stencil);
} }
cso_set_vertex_elements(st->cso_context, 2, st->velems_util_draw); cso_set_vertex_elements(st->cso_context, 2, st->util_velems);
cso_set_stream_outputs(st->cso_context, 0, NULL, NULL); cso_set_stream_outputs(st->cso_context, 0, NULL, NULL);
cso_set_sample_mask(st->cso_context, ~0); cso_set_sample_mask(st->cso_context, ~0);
cso_set_min_samples(st->cso_context, 1); cso_set_min_samples(st->cso_context, 1);

View file

@ -63,7 +63,6 @@
#include "pipe/p_context.h" #include "pipe/p_context.h"
#include "pipe/p_defines.h" #include "pipe/p_defines.h"
#include "tgsi/tgsi_ureg.h" #include "tgsi/tgsi_ureg.h"
#include "util/u_draw_quad.h"
#include "util/u_format.h" #include "util/u_format.h"
#include "util/u_inlines.h" #include "util/u_inlines.h"
#include "util/u_math.h" #include "util/u_math.h"
@ -162,22 +161,22 @@ make_passthrough_vertex_shader(struct st_context *st,
return NULL; return NULL;
/* MOV result.pos, vertex.pos; */ /* MOV result.pos, vertex.pos; */
ureg_MOV(ureg, ureg_MOV(ureg,
ureg_DECL_output( ureg, TGSI_SEMANTIC_POSITION, 0 ), ureg_DECL_output( ureg, TGSI_SEMANTIC_POSITION, 0 ),
ureg_DECL_vs_input( ureg, 0 )); ureg_DECL_vs_input( ureg, 0 ));
/* MOV result.texcoord0, vertex.attr[1]; */
ureg_MOV(ureg,
ureg_DECL_output( ureg, texcoord_semantic, 0 ),
ureg_DECL_vs_input( ureg, 1 ));
if (passColor) { if (passColor) {
/* MOV result.color0, vertex.attr[2]; */ /* MOV result.color0, vertex.attr[1]; */
ureg_MOV(ureg, ureg_MOV(ureg,
ureg_DECL_output( ureg, TGSI_SEMANTIC_COLOR, 0 ), ureg_DECL_output( ureg, TGSI_SEMANTIC_COLOR, 0 ),
ureg_DECL_vs_input( ureg, 2 )); ureg_DECL_vs_input( ureg, 1 ));
} }
/* MOV result.texcoord0, vertex.attr[2]; */
ureg_MOV(ureg,
ureg_DECL_output( ureg, texcoord_semantic, 0 ),
ureg_DECL_vs_input( ureg, 2 ));
ureg_END( ureg ); ureg_END( ureg );
st->drawpix.vert_shaders[passColor] = st->drawpix.vert_shaders[passColor] =
@ -453,14 +452,14 @@ draw_quad(struct gl_context *ctx, GLfloat x0, GLfloat y0, GLfloat z,
GLboolean invertTex, GLfloat maxXcoord, GLfloat maxYcoord) GLboolean invertTex, GLfloat maxXcoord, GLfloat maxYcoord)
{ {
struct st_context *st = st_context(ctx); struct st_context *st = st_context(ctx);
struct pipe_context *pipe = st->pipe; struct pipe_vertex_buffer vb = {0};
GLfloat (*verts)[3][4]; /* four verts, three attribs, XYZW */ struct st_util_vertex *verts;
struct pipe_resource *buf = NULL;
unsigned offset;
u_upload_alloc(st->uploader, 0, 4 * sizeof(verts[0]), 4, &offset, vb.stride = sizeof(struct st_util_vertex);
&buf, (void **) &verts);
if (!buf) { u_upload_alloc(st->uploader, 0, 4 * sizeof(struct st_util_vertex), 4,
&vb.buffer_offset, &vb.buffer, (void **) &verts);
if (!vb.buffer) {
return; return;
} }
@ -476,64 +475,61 @@ draw_quad(struct gl_context *ctx, GLfloat x0, GLfloat y0, GLfloat z,
const GLfloat sLeft = 0.0f, sRight = maxXcoord; const GLfloat sLeft = 0.0f, sRight = maxXcoord;
const GLfloat tTop = invertTex ? maxYcoord : 0.0f; const GLfloat tTop = invertTex ? maxYcoord : 0.0f;
const GLfloat tBot = invertTex ? 0.0f : maxYcoord; const GLfloat tBot = invertTex ? 0.0f : maxYcoord;
GLuint i;
/* upper-left */ /* upper-left */
verts[0][0][0] = clip_x0; /* v[0].attr[0].x */ verts[0].x = clip_x0;
verts[0][0][1] = clip_y0; /* v[0].attr[0].y */ verts[0].y = clip_y0;
verts[0].z = z;
verts[0].r = color[0];
verts[0].g = color[1];
verts[0].b = color[2];
verts[0].a = color[3];
verts[0].s = sLeft;
verts[0].t = tTop;
/* upper-right */ /* upper-right */
verts[1][0][0] = clip_x1; verts[1].x = clip_x1;
verts[1][0][1] = clip_y0; verts[1].y = clip_y0;
verts[1].z = z;
verts[1].r = color[0];
verts[1].g = color[1];
verts[1].b = color[2];
verts[1].a = color[3];
verts[1].s = sRight;
verts[1].t = tTop;
/* lower-right */ /* lower-right */
verts[2][0][0] = clip_x1; verts[2].x = clip_x1;
verts[2][0][1] = clip_y1; verts[2].y = clip_y1;
verts[2].z = z;
verts[2].r = color[0];
verts[2].g = color[1];
verts[2].b = color[2];
verts[2].a = color[3];
verts[2].s = sRight;
verts[2].t = tBot;
/* lower-left */ /* lower-left */
verts[3][0][0] = clip_x0; verts[3].x = clip_x0;
verts[3][0][1] = clip_y1; verts[3].y = clip_y1;
verts[3].z = z;
verts[0][1][0] = sLeft; /* v[0].attr[1].S */ verts[3].r = color[0];
verts[0][1][1] = tTop; /* v[0].attr[1].T */ verts[3].g = color[1];
verts[1][1][0] = sRight; verts[3].b = color[2];
verts[1][1][1] = tTop; verts[3].a = color[3];
verts[2][1][0] = sRight; verts[3].s = sLeft;
verts[2][1][1] = tBot; verts[3].t = tBot;
verts[3][1][0] = sLeft;
verts[3][1][1] = tBot;
/* same for all verts: */
if (color) {
for (i = 0; i < 4; i++) {
verts[i][0][2] = z; /* v[i].attr[0].z */
verts[i][0][3] = 1.0f; /* v[i].attr[0].w */
verts[i][2][0] = color[0]; /* v[i].attr[2].r */
verts[i][2][1] = color[1]; /* v[i].attr[2].g */
verts[i][2][2] = color[2]; /* v[i].attr[2].b */
verts[i][2][3] = color[3]; /* v[i].attr[2].a */
verts[i][1][2] = 0.0f; /* v[i].attr[1].R */
verts[i][1][3] = 1.0f; /* v[i].attr[1].Q */
}
}
else {
for (i = 0; i < 4; i++) {
verts[i][0][2] = z; /*Z*/
verts[i][0][3] = 1.0f; /*W*/
verts[i][1][2] = 0.0f; /*R*/
verts[i][1][3] = 1.0f; /*Q*/
}
}
} }
u_upload_unmap(st->uploader); u_upload_unmap(st->uploader);
util_draw_vertex_buffer(pipe, st->cso_context, buf,
cso_get_aux_vertex_buffer_slot(st->cso_context), cso_set_vertex_buffers(st->cso_context,
offset, cso_get_aux_vertex_buffer_slot(st->cso_context),
PIPE_PRIM_QUADS, 1, &vb);
4, /* verts */
3); /* attribs/vert */ cso_draw_arrays(st->cso_context, PIPE_PRIM_QUADS, 0, 4);
pipe_resource_reference(&buf, NULL);
pipe_resource_reference(&vb.buffer, NULL);
} }
@ -707,7 +703,7 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
cso_set_viewport(cso, &vp); cso_set_viewport(cso, &vp);
} }
cso_set_vertex_elements(cso, 3, st->velems_util_draw); cso_set_vertex_elements(cso, 3, st->util_velems);
cso_set_stream_outputs(st->cso_context, 0, NULL, NULL); cso_set_stream_outputs(st->cso_context, 0, NULL, NULL);
/* Compute Gallium window coords (y=0=top) with pixel zoom. /* Compute Gallium window coords (y=0=top) with pixel zoom.
@ -1060,7 +1056,6 @@ st_DrawPixels(struct gl_context *ctx, GLint x, GLint y,
{ {
void *driver_vp, *driver_fp; void *driver_vp, *driver_fp;
struct st_context *st = st_context(ctx); struct st_context *st = st_context(ctx);
const GLfloat *color;
struct pipe_context *pipe = st->pipe; struct pipe_context *pipe = st->pipe;
GLboolean write_stencil = GL_FALSE, write_depth = GL_FALSE; GLboolean write_stencil = GL_FALSE, write_depth = GL_FALSE;
struct pipe_sampler_view *sv[2] = { NULL }; struct pipe_sampler_view *sv[2] = { NULL };
@ -1106,7 +1101,6 @@ st_DrawPixels(struct gl_context *ctx, GLint x, GLint y,
driver_fp = get_drawpix_z_stencil_program(st, write_depth, driver_fp = get_drawpix_z_stencil_program(st, write_depth,
write_stencil); write_stencil);
driver_vp = make_passthrough_vertex_shader(st, GL_TRUE); driver_vp = make_passthrough_vertex_shader(st, GL_TRUE);
color = ctx->Current.RasterColor;
} }
else { else {
fpv = get_color_fp_variant(st); fpv = get_color_fp_variant(st);
@ -1114,7 +1108,6 @@ st_DrawPixels(struct gl_context *ctx, GLint x, GLint y,
driver_fp = fpv->driver_shader; driver_fp = fpv->driver_shader;
driver_vp = make_passthrough_vertex_shader(st, GL_FALSE); driver_vp = make_passthrough_vertex_shader(st, GL_FALSE);
color = NULL;
if (ctx->Pixel.MapColorFlag) { if (ctx->Pixel.MapColorFlag) {
pipe_sampler_view_reference(&sv[1], pipe_sampler_view_reference(&sv[1],
st->pixel_xfer.pixelmap_sampler_view); st->pixel_xfer.pixelmap_sampler_view);
@ -1172,7 +1165,8 @@ st_DrawPixels(struct gl_context *ctx, GLint x, GLint y,
num_sampler_view, num_sampler_view,
driver_vp, driver_vp,
driver_fp, fpv, driver_fp, fpv,
color, GL_FALSE, write_depth, write_stencil); ctx->Current.RasterColor,
GL_FALSE, write_depth, write_stencil);
pipe_sampler_view_reference(&sv[0], NULL); pipe_sampler_view_reference(&sv[0], NULL);
if (num_sampler_view > 1) if (num_sampler_view > 1)
pipe_sampler_view_reference(&sv[1], NULL); pipe_sampler_view_reference(&sv[1], NULL);
@ -1427,7 +1421,6 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
struct pipe_sampler_view *sv[2] = { NULL }; struct pipe_sampler_view *sv[2] = { NULL };
struct st_fp_variant *fpv = NULL; struct st_fp_variant *fpv = NULL;
int num_sampler_view = 1; int num_sampler_view = 1;
GLfloat *color;
enum pipe_format srcFormat; enum pipe_format srcFormat;
unsigned srcBind; unsigned srcBind;
GLboolean invertTex = GL_FALSE; GLboolean invertTex = GL_FALSE;
@ -1469,7 +1462,6 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
fpv = get_color_fp_variant(st); fpv = get_color_fp_variant(st);
rbRead = st_get_color_read_renderbuffer(ctx); rbRead = st_get_color_read_renderbuffer(ctx);
color = NULL;
driver_fp = fpv->driver_shader; driver_fp = fpv->driver_shader;
driver_vp = make_passthrough_vertex_shader(st, GL_FALSE); driver_vp = make_passthrough_vertex_shader(st, GL_FALSE);
@ -1490,7 +1482,6 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
assert(type == GL_DEPTH); assert(type == GL_DEPTH);
rbRead = st_renderbuffer(ctx->ReadBuffer-> rbRead = st_renderbuffer(ctx->ReadBuffer->
Attachment[BUFFER_DEPTH].Renderbuffer); Attachment[BUFFER_DEPTH].Renderbuffer);
color = ctx->Current.Attrib[VERT_ATTRIB_COLOR0];
driver_fp = get_drawpix_z_stencil_program(st, GL_TRUE, GL_FALSE); driver_fp = get_drawpix_z_stencil_program(st, GL_TRUE, GL_FALSE);
driver_vp = make_passthrough_vertex_shader(st, GL_TRUE); driver_vp = make_passthrough_vertex_shader(st, GL_TRUE);
@ -1622,7 +1613,8 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
num_sampler_view, num_sampler_view,
driver_vp, driver_vp,
driver_fp, fpv, driver_fp, fpv,
color, invertTex, GL_FALSE, GL_FALSE); ctx->Current.Attrib[VERT_ATTRIB_COLOR0],
invertTex, GL_FALSE, GL_FALSE);
pipe_resource_reference(&pt, NULL); pipe_resource_reference(&pt, NULL);
pipe_sampler_view_reference(&sv[0], NULL); pipe_sampler_view_reference(&sv[0], NULL);

View file

@ -248,16 +248,30 @@ st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe,
else else
st->internal_target = PIPE_TEXTURE_RECT; st->internal_target = PIPE_TEXTURE_RECT;
/* Vertex element objects used for drawing rectangles for glBitmap, /* Setup vertex element info for 'struct st_util_vertex'.
* glDrawPixels, glClear, etc.
*/ */
for (i = 0; i < ARRAY_SIZE(st->velems_util_draw); i++) { {
memset(&st->velems_util_draw[i], 0, sizeof(struct pipe_vertex_element)); const unsigned slot = cso_get_aux_vertex_buffer_slot(st->cso_context);
st->velems_util_draw[i].src_offset = i * 4 * sizeof(float);
st->velems_util_draw[i].instance_divisor = 0; /* If this assertion ever fails all state tracker calls to
st->velems_util_draw[i].vertex_buffer_index = * cso_get_aux_vertex_buffer_slot() should be audited. This
cso_get_aux_vertex_buffer_slot(st->cso_context); * particular call would have to be moved to just before each
st->velems_util_draw[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; * drawing call.
*/
assert(slot == 0);
STATIC_ASSERT(sizeof(struct st_util_vertex) == 9 * sizeof(float));
memset(&st->util_velems, 0, sizeof(st->util_velems));
st->util_velems[0].src_offset = 0;
st->util_velems[0].vertex_buffer_index = slot;
st->util_velems[0].src_format = PIPE_FORMAT_R32G32B32_FLOAT;
st->util_velems[1].src_offset = 3 * sizeof(float);
st->util_velems[1].vertex_buffer_index = slot;
st->util_velems[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
st->util_velems[2].src_offset = 7 * sizeof(float);
st->util_velems[2].vertex_buffer_index = slot;
st->util_velems[2].src_format = PIPE_FORMAT_R32G32_FLOAT;
} }
/* we want all vertex data to be placed in buffer objects */ /* we want all vertex data to be placed in buffer objects */

View file

@ -89,6 +89,15 @@ enum st_pipeline {
}; };
/** For drawing quads for glClear, glDraw/CopyPixels, glBitmap, etc. */
struct st_util_vertex
{
float x, y, z;
float r, g, b, a;
float s, t;
};
struct st_context struct st_context
{ {
struct st_context_iface iface; struct st_context_iface iface;
@ -230,8 +239,8 @@ struct st_context
bool use_gs; bool use_gs;
} pbo_upload; } pbo_upload;
/** used for anything using util_draw_vertex_buffer */ /** for drawing with st_util_vertex */
struct pipe_vertex_element velems_util_draw[3]; struct pipe_vertex_element util_velems[3];
void *passthrough_fs; /**< simple pass-through frag shader */ void *passthrough_fs; /**< simple pass-through frag shader */