summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2006-03-29 03:59:34 +0000
committerBrian Paul <brian.paul@tungstengraphics.com>2006-03-29 03:59:34 +0000
commit519a2e7cb7b8f026bd5fe711cdf12a20df1c46ae (patch)
tree3a5ace19786c23d217f9ed64fdad20e2726f3e53 /src
parentb687531f693548afc6d7cf7b5c6fb76926cc0dc9 (diff)
Move the computation of the viewport matrix into a new update_viewport_matrix()
function since the matrix depends on the viewport params and the framebuffer's depth buffer resolution. Fixes some renderbuffer / depth range issues. This simplifies the _mesa_set_viewport() and _mesa_DepthRange() functions too.
Diffstat (limited to 'src')
-rw-r--r--src/mesa/main/matrix.c58
-rw-r--r--src/mesa/main/mtypes.h1
-rw-r--r--src/mesa/main/state.c23
3 files changed, 34 insertions, 48 deletions
diff --git a/src/mesa/main/matrix.c b/src/mesa/main/matrix.c
index f4ec973563..069c5c9738 100644
--- a/src/mesa/main/matrix.c
+++ b/src/mesa/main/matrix.c
@@ -552,6 +552,7 @@ _mesa_Viewport( GLint x, GLint y, GLsizei width, GLsizei height )
_mesa_set_viewport(ctx, x, y, width, height);
}
+
/**
* Set new viewport parameters and update derived state (the _WindowMap
* matrix). Usually called from _mesa_Viewport().
@@ -560,22 +561,11 @@ _mesa_Viewport( GLint x, GLint y, GLsizei width, GLsizei height )
* \param x, y coordinates of the lower left corner of the viewport rectangle.
* \param width width of the viewport rectangle.
* \param height height of the viewport rectangle.
- *
- * Verifies the parameters, clamps them to the implementation dependent range
- * and updates __GLcontextRec::Viewport. Computes the scale and bias values for
- * the drivers and notifies the driver via the dd_function_table::Viewport
- * callback.
*/
void
_mesa_set_viewport( GLcontext *ctx, GLint x, GLint y,
GLsizei width, GLsizei height )
{
- const GLfloat depthMax = ctx->DrawBuffer->_DepthMaxF;
- const GLfloat n = ctx->Viewport.Near;
- const GLfloat f = ctx->Viewport.Far;
-
- ASSERT(depthMax > 0);
-
if (MESA_VERBOSE & VERBOSE_API)
_mesa_debug(ctx, "glViewport %d %d %d %d\n", x, y, width, height);
@@ -595,20 +585,6 @@ _mesa_set_viewport( GLcontext *ctx, GLint x, GLint y,
ctx->Viewport.Y = y;
ctx->Viewport.Height = height;
- /* XXX send transposed width/height to Driver.Viewport() below??? */
- if (ctx->_RotateMode) {
- GLint tmp, tmps;
- tmp = x; x = y; y = tmp;
- tmps = width; width = height; height = tmps;
- }
-
- /* Compute scale and bias values. This is really driver-specific
- * and should be maintained elsewhere if at all.
- * NOTE: RasterPos uses this.
- */
- _math_matrix_viewport(&ctx->Viewport._WindowMap, x, y, width, height,
- n, f, depthMax);
-
ctx->NewState |= _NEW_VIEWPORT;
if (ctx->Driver.Viewport) {
@@ -622,36 +598,24 @@ _mesa_set_viewport( GLcontext *ctx, GLint x, GLint y,
#if _HAVE_FULL_GL
void GLAPIENTRY
+/**
+ * Called by glDepthRange
+ *
+ * \param nearval specifies the Z buffer value which should correspond to
+ * the near clip plane
+ * \param farval specifies the Z buffer value which should correspond to
+ * the far clip plane
+ */
_mesa_DepthRange( GLclampd nearval, GLclampd farval )
{
- /*
- * nearval - specifies mapping of the near clipping plane to window
- * coordinates, default is 0
- * farval - specifies mapping of the far clipping plane to window
- * coordinates, default is 1
- *
- * After clipping and div by w, z coords are in -1.0 to 1.0,
- * corresponding to near and far clipping planes. glDepthRange
- * specifies a linear mapping of the normalized z coords in
- * this range to window z coords.
- */
- GLfloat depthMax;
- GLfloat n, f;
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
- depthMax = ctx->DrawBuffer->_DepthMaxF;
-
if (MESA_VERBOSE&VERBOSE_API)
_mesa_debug(ctx, "glDepthRange %f %f\n", nearval, farval);
- n = (GLfloat) CLAMP( nearval, 0.0, 1.0 );
- f = (GLfloat) CLAMP( farval, 0.0, 1.0 );
-
- ctx->Viewport.Near = n;
- ctx->Viewport.Far = f;
- ctx->Viewport._WindowMap.m[MAT_SZ] = depthMax * ((f - n) / 2.0F);
- ctx->Viewport._WindowMap.m[MAT_TZ] = depthMax * ((f - n) / 2.0F + n);
+ ctx->Viewport.Near = (GLfloat) CLAMP( nearval, 0.0, 1.0 );
+ ctx->Viewport.Far = (GLfloat) CLAMP( farval, 0.0, 1.0 );
ctx->NewState |= _NEW_VIEWPORT;
if (ctx->Driver.DepthRange) {
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 3eadb33e0f..00b0187846 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2855,7 +2855,6 @@ struct __GLcontextRec
GLfloat _ModelViewInvScale;
GLboolean _NeedEyeCoords;
GLboolean _ForceEyeCoords;
- GLboolean _RotateMode;
GLenum _CurrentProgram; /* currently executing program */
struct gl_shine_tab *_ShineTable[2]; /**< Active shine tables */
diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c
index 994aaff7b0..7e452bdfd7 100644
--- a/src/mesa/main/state.c
+++ b/src/mesa/main/state.c
@@ -945,6 +945,26 @@ update_program(GLcontext *ctx)
}
+static void
+update_viewport_matrix(GLcontext *ctx)
+{
+ const GLfloat depthMax = ctx->DrawBuffer->_DepthMaxF;
+
+ ASSERT(depthMax > 0);
+
+ /* Compute scale and bias values. This is really driver-specific
+ * and should be maintained elsewhere if at all.
+ * NOTE: RasterPos uses this.
+ */
+ _math_matrix_viewport(&ctx->Viewport._WindowMap,
+ ctx->Viewport.X, ctx->Viewport.Y,
+ ctx->Viewport.Width, ctx->Viewport.Height,
+ ctx->Viewport.Near, ctx->Viewport.Far,
+ depthMax);
+}
+
+
+
/**
* If __GLcontextRec::NewState is non-zero then this function \b must be called
* before rendering any primitive. Basically, function pointers and
@@ -1002,6 +1022,9 @@ _mesa_update_state( GLcontext *ctx )
if (new_state & (_NEW_ARRAY | _NEW_PROGRAM))
update_arrays( ctx );
+ if (new_state & (_NEW_BUFFERS | _NEW_VIEWPORT))
+ update_viewport_matrix(ctx);
+
if (ctx->_MaintainTexEnvProgram) {
if (new_state & (_NEW_TEXTURE | _DD_NEW_SEPARATE_SPECULAR | _NEW_FOG))
_mesa_UpdateTexEnvProgram(ctx);