#include "pipe/p_defines.h"
#include "pipe/p_shader_tokens.h"
#include "util/u_inlines.h"
-#include "util/u_draw_quad.h"
#include "util/u_simple_shaders.h"
#include "util/u_upload_mgr.h"
#include "program/prog_instruction.h"
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);
}
{
struct st_context *st = st_context(ctx);
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_height = (float) st->state.framebuffer.height;
const float x0 = (float) x;
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_y1 = y1 / fb_height * 2.0f - 1.0f;
- float (*vertices)[3][4]; /**< vertex pos + color + texcoord */
- unsigned offset, i;
+ struct st_util_vertex *verts;
/* limit checks */
{
tBot = (float) height;
}
- u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]), 4,
- &offset, &vbuf, (void **) &vertices);
- if (!vbuf) {
+ vb.stride = sizeof(struct st_util_vertex);
+
+ 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");
restore_render_state(ctx);
return;
/* Positions are in clip coords since we need to do clipping in case
* the bitmap quad goes beyond the window bounds.
*/
- vertices[0][0][0] = clip_x0;
- vertices[0][0][1] = clip_y0;
- vertices[0][2][0] = sLeft;
- vertices[0][2][1] = tTop;
-
- vertices[1][0][0] = clip_x1;
- vertices[1][0][1] = clip_y0;
- vertices[1][2][0] = sRight;
- vertices[1][2][1] = tTop;
-
- vertices[2][0][0] = clip_x1;
- vertices[2][0][1] = clip_y1;
- vertices[2][2][0] = sRight;
- vertices[2][2][1] = tBot;
-
- vertices[3][0][0] = clip_x0;
- vertices[3][0][1] = clip_y1;
- vertices[3][2][0] = sLeft;
- vertices[3][2][1] = tBot;
-
- /* same for all verts: */
- for (i = 0; i < 4; i++) {
- vertices[i][0][2] = z;
- vertices[i][0][3] = 1.0f;
- 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*/
- }
+ verts[0].x = clip_x0;
+ 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;
+
+ verts[1].x = clip_x1;
+ 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;
+
+ verts[2].x = clip_x1;
+ 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;
+
+ verts[3].x = clip_x0;
+ verts[3].y = clip_y1;
+ verts[3].z = z;
+ verts[3].r = color[0];
+ verts[3].g = color[1];
+ verts[3].b = color[2];
+ verts[3].a = color[3];
+ verts[3].s = sLeft;
+ verts[3].t = tBot;
u_upload_unmap(st->uploader);
- util_draw_vertex_buffer(pipe, st->cso_context, vbuf,
- cso_get_aux_vertex_buffer_slot(st->cso_context),
- offset,
- PIPE_PRIM_TRIANGLE_FAN,
- 4, /* verts */
- 3); /* attribs/vert */
+ cso_set_vertex_buffers(st->cso_context,
+ cso_get_aux_vertex_buffer_slot(st->cso_context),
+ 1, &vb);
+
+ cso_draw_arrays(st->cso_context, PIPE_PRIM_TRIANGLE_FAN, 0, 4);
restore_render_state(ctx);
- pipe_resource_reference(&vbuf, NULL);
+ pipe_resource_reference(&vb.buffer, NULL);
/* We uploaded modified constants, need to invalidate them. */
st->dirty.mesa |= _NEW_PROGRAM_CONSTANTS;
#include "util/u_framebuffer.h"
#include "util/u_inlines.h"
#include "util/u_simple_shaders.h"
-#include "util/u_draw_quad.h"
#include "util/u_upload_mgr.h"
#include "cso_cache/cso_context.h"
{
struct cso_context *cso = st->cso_context;
struct pipe_vertex_buffer vb = {0};
- GLuint i;
- float (*vertices)[2][4]; /**< vertex pos + color */
+ struct st_util_vertex *verts;
- vb.stride = 8 * sizeof(float);
+ vb.stride = sizeof(struct st_util_vertex);
- u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]), 4,
- &vb.buffer_offset, &vb.buffer,
- (void **) &vertices);
+ u_upload_alloc(st->uploader, 0, 4 * sizeof(struct st_util_vertex), 4,
+ &vb.buffer_offset, &vb.buffer, (void **) &verts);
if (!vb.buffer) {
return;
}
/* Convert Z from [0,1] to [-1,1] range */
z = z * 2.0f - 1.0f;
- /* positions */
- vertices[0][0][0] = x0;
- vertices[0][0][1] = y0;
-
- vertices[1][0][0] = x1;
- vertices[1][0][1] = y0;
-
- vertices[2][0][0] = x1;
- vertices[2][0][1] = y1;
-
- vertices[3][0][0] = x0;
- vertices[3][0][1] = y1;
-
- /* same for all verts: */
- for (i = 0; i < 4; i++) {
- vertices[i][0][2] = z;
- vertices[i][0][3] = 1.0;
- 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];
- }
+ /* Note: if we're only clearing depth/stencil we still setup vertices
+ * with color, but they'll be ignored.
+ */
+ 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];
+
+ verts[1].x = x1;
+ 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];
+
+ verts[2].x = x1;
+ 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];
+
+ verts[3].x = x0;
+ verts[3].y = y1;
+ verts[3].z = z;
+ verts[3].r = color->f[0];
+ verts[3].g = color->f[1];
+ verts[3].b = color->f[2];
+ verts[3].a = color->f[3];
u_upload_unmap(st->uploader);
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_sample_mask(st->cso_context, ~0);
cso_set_min_samples(st->cso_context, 1);
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "tgsi/tgsi_ureg.h"
-#include "util/u_draw_quad.h"
#include "util/u_format.h"
#include "util/u_inlines.h"
#include "util/u_math.h"
return NULL;
/* MOV result.pos, vertex.pos; */
- ureg_MOV(ureg,
+ ureg_MOV(ureg,
ureg_DECL_output( ureg, TGSI_SEMANTIC_POSITION, 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) {
- /* MOV result.color0, vertex.attr[2]; */
- ureg_MOV(ureg,
+ /* MOV result.color0, vertex.attr[1]; */
+ ureg_MOV(ureg,
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 );
st->drawpix.vert_shaders[passColor] =
GLboolean invertTex, GLfloat maxXcoord, GLfloat maxYcoord)
{
struct st_context *st = st_context(ctx);
- struct pipe_context *pipe = st->pipe;
- GLfloat (*verts)[3][4]; /* four verts, three attribs, XYZW */
- struct pipe_resource *buf = NULL;
- unsigned offset;
+ struct pipe_vertex_buffer vb = {0};
+ struct st_util_vertex *verts;
+
+ vb.stride = sizeof(struct st_util_vertex);
- u_upload_alloc(st->uploader, 0, 4 * sizeof(verts[0]), 4, &offset,
- &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;
}
const GLfloat sLeft = 0.0f, sRight = maxXcoord;
const GLfloat tTop = invertTex ? maxYcoord : 0.0f;
const GLfloat tBot = invertTex ? 0.0f : maxYcoord;
- GLuint i;
/* upper-left */
- verts[0][0][0] = clip_x0; /* v[0].attr[0].x */
- verts[0][0][1] = clip_y0; /* v[0].attr[0].y */
+ verts[0].x = clip_x0;
+ 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 */
- verts[1][0][0] = clip_x1;
- verts[1][0][1] = clip_y0;
+ verts[1].x = clip_x1;
+ 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 */
- verts[2][0][0] = clip_x1;
- verts[2][0][1] = clip_y1;
+ verts[2].x = clip_x1;
+ 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 */
- verts[3][0][0] = clip_x0;
- verts[3][0][1] = clip_y1;
-
- verts[0][1][0] = sLeft; /* v[0].attr[1].S */
- verts[0][1][1] = tTop; /* v[0].attr[1].T */
- verts[1][1][0] = sRight;
- verts[1][1][1] = tTop;
- verts[2][1][0] = sRight;
- verts[2][1][1] = 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*/
- }
- }
+ verts[3].x = clip_x0;
+ verts[3].y = clip_y1;
+ verts[3].z = z;
+ verts[3].r = color[0];
+ verts[3].g = color[1];
+ verts[3].b = color[2];
+ verts[3].a = color[3];
+ verts[3].s = sLeft;
+ verts[3].t = tBot;
}
u_upload_unmap(st->uploader);
- util_draw_vertex_buffer(pipe, st->cso_context, buf,
- cso_get_aux_vertex_buffer_slot(st->cso_context),
- offset,
- PIPE_PRIM_QUADS,
- 4, /* verts */
- 3); /* attribs/vert */
- pipe_resource_reference(&buf, NULL);
+
+ cso_set_vertex_buffers(st->cso_context,
+ cso_get_aux_vertex_buffer_slot(st->cso_context),
+ 1, &vb);
+
+ cso_draw_arrays(st->cso_context, PIPE_PRIM_QUADS, 0, 4);
+
+ pipe_resource_reference(&vb.buffer, NULL);
}
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);
/* Compute Gallium window coords (y=0=top) with pixel zoom.
{
void *driver_vp, *driver_fp;
struct st_context *st = st_context(ctx);
- const GLfloat *color;
struct pipe_context *pipe = st->pipe;
GLboolean write_stencil = GL_FALSE, write_depth = GL_FALSE;
struct pipe_sampler_view *sv[2] = { NULL };
driver_fp = get_drawpix_z_stencil_program(st, write_depth,
write_stencil);
driver_vp = make_passthrough_vertex_shader(st, GL_TRUE);
- color = ctx->Current.RasterColor;
}
else {
fpv = get_color_fp_variant(st);
driver_fp = fpv->driver_shader;
driver_vp = make_passthrough_vertex_shader(st, GL_FALSE);
- color = NULL;
if (ctx->Pixel.MapColorFlag) {
pipe_sampler_view_reference(&sv[1],
st->pixel_xfer.pixelmap_sampler_view);
num_sampler_view,
driver_vp,
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);
if (num_sampler_view > 1)
pipe_sampler_view_reference(&sv[1], NULL);
struct pipe_sampler_view *sv[2] = { NULL };
struct st_fp_variant *fpv = NULL;
int num_sampler_view = 1;
- GLfloat *color;
enum pipe_format srcFormat;
unsigned srcBind;
GLboolean invertTex = GL_FALSE;
fpv = get_color_fp_variant(st);
rbRead = st_get_color_read_renderbuffer(ctx);
- color = NULL;
driver_fp = fpv->driver_shader;
driver_vp = make_passthrough_vertex_shader(st, GL_FALSE);
assert(type == GL_DEPTH);
rbRead = st_renderbuffer(ctx->ReadBuffer->
Attachment[BUFFER_DEPTH].Renderbuffer);
- color = ctx->Current.Attrib[VERT_ATTRIB_COLOR0];
driver_fp = get_drawpix_z_stencil_program(st, GL_TRUE, GL_FALSE);
driver_vp = make_passthrough_vertex_shader(st, GL_TRUE);
num_sampler_view,
driver_vp,
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_sampler_view_reference(&sv[0], NULL);
else
st->internal_target = PIPE_TEXTURE_RECT;
- /* Vertex element objects used for drawing rectangles for glBitmap,
- * glDrawPixels, glClear, etc.
+ /* Setup vertex element info for 'struct st_util_vertex'.
*/
- for (i = 0; i < ARRAY_SIZE(st->velems_util_draw); i++) {
- memset(&st->velems_util_draw[i], 0, sizeof(struct pipe_vertex_element));
- st->velems_util_draw[i].src_offset = i * 4 * sizeof(float);
- st->velems_util_draw[i].instance_divisor = 0;
- st->velems_util_draw[i].vertex_buffer_index =
- cso_get_aux_vertex_buffer_slot(st->cso_context);
- st->velems_util_draw[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
+ {
+ const unsigned slot = cso_get_aux_vertex_buffer_slot(st->cso_context);
+
+ /* If this assertion ever fails all state tracker calls to
+ * cso_get_aux_vertex_buffer_slot() should be audited. This
+ * particular call would have to be moved to just before each
+ * 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 */
};
+/** 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_iface iface;
bool use_gs;
} pbo_upload;
- /** used for anything using util_draw_vertex_buffer */
- struct pipe_vertex_element velems_util_draw[3];
+ /** for drawing with st_util_vertex */
+ struct pipe_vertex_element util_velems[3];
void *passthrough_fs; /**< simple pass-through frag shader */