summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2014-01-21 15:26:29 +1000
committerDave Airlie <airlied@redhat.com>2014-02-11 14:14:50 +1000
commit0705fa35cdaf15ec969c28dc85e88b8be1149a3b (patch)
tree73b98d63456cd60823101bc864baf2dfd150609e
parentc116ee604260faca75aaf2b0d8bbbd78b9c71154 (diff)
st/mesa: add support for GL_ARB_viewport_array (v0.2)
this just ties the mesa code to the pre-existing gallium interface, I'm not sure what to do with the CSO stuff yet. 0.2: fix min/max bounds Acked-by: Ilia Mirkin <imirkin@alum.mit.edu> Signed-off-by: Dave Airlie <airlied@redhat.com>
-rw-r--r--src/mesa/state_tracker/st_atom_scissor.c77
-rw-r--r--src/mesa/state_tracker/st_atom_viewport.c37
-rw-r--r--src/mesa/state_tracker/st_context.h4
-rw-r--r--src/mesa/state_tracker/st_draw_feedback.c2
-rw-r--r--src/mesa/state_tracker/st_extensions.c9
5 files changed, 73 insertions, 56 deletions
diff --git a/src/mesa/state_tracker/st_atom_scissor.c b/src/mesa/state_tracker/st_atom_scissor.c
index a1f72da47e0..a19ade1fafe 100644
--- a/src/mesa/state_tracker/st_atom_scissor.c
+++ b/src/mesa/state_tracker/st_atom_scissor.c
@@ -43,51 +43,56 @@
static void
update_scissor( struct st_context *st )
{
- struct pipe_scissor_state scissor;
+ struct pipe_scissor_state scissor[PIPE_MAX_VIEWPORTS];
const struct gl_context *ctx = st->ctx;
const struct gl_framebuffer *fb = ctx->DrawBuffer;
GLint miny, maxy;
+ int i;
+ bool changed = false;
+ for (i = 0 ; i < ctx->Const.MaxViewports; i++) {
+ scissor[i].minx = 0;
+ scissor[i].miny = 0;
+ scissor[i].maxx = fb->Width;
+ scissor[i].maxy = fb->Height;
- scissor.minx = 0;
- scissor.miny = 0;
- scissor.maxx = fb->Width;
- scissor.maxy = fb->Height;
+ if (ctx->Scissor.EnableFlags & (1 << i)) {
+ /* need to be careful here with xmax or ymax < 0 */
+ GLint xmax = MAX2(0, ctx->Scissor.ScissorArray[i].X + ctx->Scissor.ScissorArray[i].Width);
+ GLint ymax = MAX2(0, ctx->Scissor.ScissorArray[i].Y + ctx->Scissor.ScissorArray[i].Height);
- if (ctx->Scissor.EnableFlags & 1) {
- /* need to be careful here with xmax or ymax < 0 */
- GLint xmax = MAX2(0, ctx->Scissor.ScissorArray[0].X + ctx->Scissor.ScissorArray[0].Width);
- GLint ymax = MAX2(0, ctx->Scissor.ScissorArray[0].Y + ctx->Scissor.ScissorArray[0].Height);
+ if (ctx->Scissor.ScissorArray[i].X > (GLint)scissor[i].minx)
+ scissor[i].minx = ctx->Scissor.ScissorArray[i].X;
+ if (ctx->Scissor.ScissorArray[i].Y > (GLint)scissor[i].miny)
+ scissor[i].miny = ctx->Scissor.ScissorArray[i].Y;
- if (ctx->Scissor.ScissorArray[0].X > (GLint)scissor.minx)
- scissor.minx = ctx->Scissor.ScissorArray[0].X;
- if (ctx->Scissor.ScissorArray[0].Y > (GLint)scissor.miny)
- scissor.miny = ctx->Scissor.ScissorArray[0].Y;
+ if (xmax < (GLint) scissor[i].maxx)
+ scissor[i].maxx = xmax;
+ if (ymax < (GLint) scissor[i].maxy)
+ scissor[i].maxy = ymax;
+
+ /* check for null space */
+ if (scissor[i].minx >= scissor[i].maxx || scissor[i].miny >= scissor[i].maxy)
+ scissor[i].minx = scissor[i].miny = scissor[i].maxx = scissor[i].maxy = 0;
+ }
- if (xmax < (GLint) scissor.maxx)
- scissor.maxx = xmax;
- if (ymax < (GLint) scissor.maxy)
- scissor.maxy = ymax;
+ /* Now invert Y if needed.
+ * Gallium drivers use the convention Y=0=top for surfaces.
+ */
+ if (st_fb_orientation(fb) == Y_0_TOP) {
+ miny = fb->Height - scissor[i].maxy;
+ maxy = fb->Height - scissor[i].miny;
+ scissor[i].miny = miny;
+ scissor[i].maxy = maxy;
+ }
- /* check for null space */
- if (scissor.minx >= scissor.maxx || scissor.miny >= scissor.maxy)
- scissor.minx = scissor.miny = scissor.maxx = scissor.maxy = 0;
- }
-
- /* Now invert Y if needed.
- * Gallium drivers use the convention Y=0=top for surfaces.
- */
- if (st_fb_orientation(fb) == Y_0_TOP) {
- miny = fb->Height - scissor.maxy;
- maxy = fb->Height - scissor.miny;
- scissor.miny = miny;
- scissor.maxy = maxy;
- }
-
- if (memcmp(&scissor, &st->state.scissor, sizeof(scissor)) != 0) {
- /* state has changed */
- st->state.scissor = scissor; /* struct copy */
- st->pipe->set_scissor_states(st->pipe, 0, 1, &scissor); /* activate */
+ if (memcmp(&scissor[i], &st->state.scissor[i], sizeof(scissor)) != 0) {
+ /* state has changed */
+ st->state.scissor[i] = scissor[i]; /* struct copy */
+ changed = true;
+ }
}
+ if (changed)
+ st->pipe->set_scissor_states(st->pipe, 0, ctx->Const.MaxViewports, scissor); /* activate */
}
diff --git a/src/mesa/state_tracker/st_atom_viewport.c b/src/mesa/state_tracker/st_atom_viewport.c
index 8c6d679a041..7584f9b3d55 100644
--- a/src/mesa/state_tracker/st_atom_viewport.c
+++ b/src/mesa/state_tracker/st_atom_viewport.c
@@ -43,7 +43,7 @@ update_viewport( struct st_context *st )
{
struct gl_context *ctx = st->ctx;
GLfloat yScale, yBias;
-
+ int i;
/* _NEW_BUFFERS
*/
if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
@@ -61,26 +61,29 @@ update_viewport( struct st_context *st )
/* _NEW_VIEWPORT
*/
+ for (i = 0; i < ctx->Const.MaxViewports; i++)
{
- GLfloat x = ctx->ViewportArray[0].X;
- GLfloat y = ctx->ViewportArray[0].Y;
- GLfloat z = ctx->ViewportArray[0].Near;
- GLfloat half_width = ctx->ViewportArray[0].Width * 0.5f;
- GLfloat half_height = ctx->ViewportArray[0].Height * 0.5f;
- GLfloat half_depth = (GLfloat)(ctx->ViewportArray[0].Far - ctx->ViewportArray[0].Near) * 0.5f;
+ GLfloat x = ctx->ViewportArray[i].X;
+ GLfloat y = ctx->ViewportArray[i].Y;
+ GLfloat z = ctx->ViewportArray[i].Near;
+ GLfloat half_width = ctx->ViewportArray[i].Width * 0.5f;
+ GLfloat half_height = ctx->ViewportArray[i].Height * 0.5f;
+ GLfloat half_depth = (GLfloat)(ctx->ViewportArray[i].Far - ctx->ViewportArray[i].Near) * 0.5f;
- st->state.viewport.scale[0] = half_width;
- st->state.viewport.scale[1] = half_height * yScale;
- st->state.viewport.scale[2] = half_depth;
- st->state.viewport.scale[3] = 1.0;
-
- st->state.viewport.translate[0] = half_width + x;
- st->state.viewport.translate[1] = (half_height + y) * yScale + yBias;
- st->state.viewport.translate[2] = half_depth + z;
- st->state.viewport.translate[3] = 0.0;
+ st->state.viewport[i].scale[0] = half_width;
+ st->state.viewport[i].scale[1] = half_height * yScale;
+ st->state.viewport[i].scale[2] = half_depth;
+ st->state.viewport[i].scale[3] = 1.0;
- cso_set_viewport(st->cso_context, &st->state.viewport);
+ st->state.viewport[i].translate[0] = half_width + x;
+ st->state.viewport[i].translate[1] = (half_height + y) * yScale + yBias;
+ st->state.viewport[i].translate[2] = half_depth + z;
+ st->state.viewport[i].translate[3] = 0.0;
}
+
+ cso_set_viewport(st->cso_context, &st->state.viewport[0]);
+ if (ctx->Const.MaxViewports > 1)
+ st->pipe->set_viewport_states(st->pipe, 1, ctx->Const.MaxViewports - 1, &st->state.viewport[1]);
}
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index 996e0c6bce9..9c699a015c0 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -115,8 +115,8 @@ struct st_context
unsigned size;
} constants[PIPE_SHADER_TYPES];
struct pipe_framebuffer_state framebuffer;
- struct pipe_scissor_state scissor;
- struct pipe_viewport_state viewport;
+ struct pipe_scissor_state scissor[PIPE_MAX_VIEWPORTS];
+ struct pipe_viewport_state viewport[PIPE_MAX_VIEWPORTS];
unsigned sample_mask;
GLuint poly_stipple[32]; /**< In OpenGL's bottom-to-top order */
diff --git a/src/mesa/state_tracker/st_draw_feedback.c b/src/mesa/state_tracker/st_draw_feedback.c
index 09cd9511d9b..177f6b5aefa 100644
--- a/src/mesa/state_tracker/st_draw_feedback.c
+++ b/src/mesa/state_tracker/st_draw_feedback.c
@@ -156,7 +156,7 @@ st_feedback_draw_vbo(struct gl_context *ctx,
* code sends state updates to the pipe, not to our private draw module.
*/
assert(draw);
- draw_set_viewport_states(draw, 0, 1, &st->state.viewport);
+ draw_set_viewport_states(draw, 0, 1, &st->state.viewport[0]);
draw_set_clip_state(draw, &st->state.clip);
draw_set_rasterizer_state(draw, &st->state.rasterizer, NULL);
draw_bind_vertex_shader(draw, st->vp_variant->draw_shader);
diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index f9b7a445f1f..1f391c9f0dd 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -779,4 +779,13 @@ void st_init_extensions(struct st_context *st)
if (!ctx->Extensions.EXT_transform_feedback)
ctx->Const.DisableVaryingPacking = GL_TRUE;
}
+
+ if (ctx->API == API_OPENGL_CORE) {
+ ctx->Const.MaxViewports = screen->get_param(screen, PIPE_CAP_MAX_VIEWPORTS);
+ if (ctx->Const.MaxViewports >= 16) {
+ ctx->Const.ViewportBounds.Min = -(float)ctx->Const.MaxViewportWidth;
+ ctx->Const.ViewportBounds.Max = ctx->Const.MaxViewportWidth;
+ ctx->Extensions.ARB_viewport_array = GL_TRUE;
+ }
+ }
}