aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa/main
diff options
context:
space:
mode:
authorMathias Fröhlich <[email protected]>2014-09-21 18:09:21 +0200
committerMathias Fröhlich <[email protected]>2014-10-24 19:21:20 +0200
commit6340e609a354770e04192b9b44e91fb06aab0159 (patch)
treea23faaf3f456f4775efd556e2701ad07021ff1b4 /src/mesa/main
parent8c7ac377b7a859705479a0b421d1dacc53ca240a (diff)
mesa: Refactor viewport transform computation.
This is for preparation of ARB_clip_control. v3: Add comments. Reviewed-by: Brian Paul <[email protected]> Signed-off-by: Mathias Froehlich <[email protected]>
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/state.c9
-rw-r--r--src/mesa/main/viewport.c52
-rw-r--r--src/mesa/main/viewport.h3
3 files changed, 44 insertions, 20 deletions
diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c
index 80287c47062..3dbbfaac76c 100644
--- a/src/mesa/main/state.c
+++ b/src/mesa/main/state.c
@@ -51,6 +51,7 @@
#include "texobj.h"
#include "texstate.h"
#include "varray.h"
+#include "viewport.h"
#include "blend.h"
@@ -281,11 +282,11 @@ update_viewport_matrix(struct gl_context *ctx)
* NOTE: RasterPos uses this.
*/
for (i = 0; i < ctx->Const.MaxViewports; i++) {
+ double scale[3], translate[3];
+
+ _mesa_get_viewport_xform(ctx, i, scale, translate);
_math_matrix_viewport(&ctx->ViewportArray[i]._WindowMap,
- ctx->ViewportArray[i].X, ctx->ViewportArray[i].Y,
- ctx->ViewportArray[i].Width, ctx->ViewportArray[i].Height,
- ctx->ViewportArray[i].Near, ctx->ViewportArray[i].Far,
- depthMax);
+ scale, translate, depthMax);
}
}
diff --git a/src/mesa/main/viewport.c b/src/mesa/main/viewport.c
index 222ae307b55..afc813dceb7 100644
--- a/src/mesa/main/viewport.c
+++ b/src/mesa/main/viewport.c
@@ -39,6 +39,8 @@ set_viewport_no_notify(struct gl_context *ctx, unsigned idx,
GLfloat x, GLfloat y,
GLfloat width, GLfloat height)
{
+ double scale[3], translate[3];
+
/* clamp width and height to the implementation dependent range */
width = MIN2(width, (GLfloat) ctx->Const.MaxViewportWidth);
height = MIN2(height, (GLfloat) ctx->Const.MaxViewportHeight);
@@ -75,14 +77,9 @@ set_viewport_no_notify(struct gl_context *ctx, unsigned idx,
* the WindowMap matrix being up to date in the driver's Viewport
* and DepthRange functions.
*/
+ _mesa_get_viewport_xform(ctx, idx, scale, translate);
_math_matrix_viewport(&ctx->ViewportArray[idx]._WindowMap,
- ctx->ViewportArray[idx].X,
- ctx->ViewportArray[idx].Y,
- ctx->ViewportArray[idx].Width,
- ctx->ViewportArray[idx].Height,
- ctx->ViewportArray[idx].Near,
- ctx->ViewportArray[idx].Far,
- ctx->DrawBuffer->_DepthMaxF);
+ scale, translate, ctx->DrawBuffer->_DepthMaxF);
#endif
}
@@ -248,6 +245,8 @@ static void
set_depth_range_no_notify(struct gl_context *ctx, unsigned idx,
GLclampd nearval, GLclampd farval)
{
+ double scale[3], translate[3];
+
if (ctx->ViewportArray[idx].Near == nearval &&
ctx->ViewportArray[idx].Far == farval)
return;
@@ -261,14 +260,9 @@ set_depth_range_no_notify(struct gl_context *ctx, unsigned idx,
* the WindowMap matrix being up to date in the driver's Viewport
* and DepthRange functions.
*/
+ _mesa_get_viewport_xform(ctx, idx, scale, translate);
_math_matrix_viewport(&ctx->ViewportArray[idx]._WindowMap,
- ctx->ViewportArray[idx].X,
- ctx->ViewportArray[idx].Y,
- ctx->ViewportArray[idx].Width,
- ctx->ViewportArray[idx].Height,
- ctx->ViewportArray[idx].Near,
- ctx->ViewportArray[idx].Far,
- ctx->DrawBuffer->_DepthMaxF);
+ scale, translate, ctx->DrawBuffer->_DepthMaxF);
#endif
}
@@ -400,6 +394,8 @@ void _mesa_init_viewport(struct gl_context *ctx)
* so just initialize all of them.
*/
for (i = 0; i < MAX_VIEWPORTS; i++) {
+ double scale[3], translate[3];
+
/* Viewport group */
ctx->ViewportArray[i].X = 0;
ctx->ViewportArray[i].Y = 0;
@@ -409,8 +405,9 @@ void _mesa_init_viewport(struct gl_context *ctx)
ctx->ViewportArray[i].Far = 1.0;
_math_matrix_ctr(&ctx->ViewportArray[i]._WindowMap);
- _math_matrix_viewport(&ctx->ViewportArray[i]._WindowMap, 0, 0, 0, 0,
- 0.0F, 1.0F, depthMax);
+ _mesa_get_viewport_xform(ctx, i, scale, translate);
+ _math_matrix_viewport(&ctx->ViewportArray[i]._WindowMap,
+ scale, translate, depthMax);
}
}
@@ -427,3 +424,26 @@ void _mesa_free_viewport_data(struct gl_context *ctx)
_math_matrix_dtr(&ctx->ViewportArray[i]._WindowMap);
}
+/**
+ * Computes the scaling and the translation part of the
+ * viewport transform matrix of the \param i-th viewport
+ * and writes that into \param scale and \param translate.
+ */
+void
+_mesa_get_viewport_xform(struct gl_context *ctx, unsigned i,
+ double scale[3], double translate[3])
+{
+ double x = ctx->ViewportArray[i].X;
+ double y = ctx->ViewportArray[i].Y;
+ double half_width = 0.5*ctx->ViewportArray[i].Width;
+ double half_height = 0.5*ctx->ViewportArray[i].Height;
+ double n = ctx->ViewportArray[i].Near;
+ double f = ctx->ViewportArray[i].Far;
+
+ scale[0] = half_width;
+ translate[0] = half_width + x;
+ scale[1] = half_height;
+ translate[1] = half_height + y;
+ scale[2] = 0.5*(f - n);
+ translate[2] = 0.5*(n + f);
+}
diff --git a/src/mesa/main/viewport.h b/src/mesa/main/viewport.h
index f2311c02b44..514ff1067ff 100644
--- a/src/mesa/main/viewport.h
+++ b/src/mesa/main/viewport.h
@@ -71,5 +71,8 @@ _mesa_init_viewport(struct gl_context *ctx);
extern void
_mesa_free_viewport_data(struct gl_context *ctx);
+extern void
+_mesa_get_viewport_xform(struct gl_context *ctx, unsigned i,
+ double scale[3], double translate[3]);
#endif