From: Ian Romanick <ian.d.roman...@intel.com> v2: Use MAX_VIEWPORTS instead of ctx->Const.MaxViewports because the driver may not set ctx->Const.MaxViewports yet.
Signed-off-by: Ian Romanick <ian.d.roman...@intel.com> --- src/mesa/main/context.c | 10 +++++++++- src/mesa/main/viewport.c | 33 +++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index f840918..d4d0653 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -1434,11 +1434,19 @@ void _mesa_check_init_viewport(struct gl_context *ctx, GLuint width, GLuint height) { if (!ctx->ViewportInitialized && width > 0 && height > 0) { + unsigned i; + /* Note: set flag here, before calling _mesa_set_viewport(), to prevent * potential infinite recursion. */ ctx->ViewportInitialized = GL_TRUE; - _mesa_set_viewport(ctx, 0, 0, 0, width, height); + + /* Note: ctx->Const.MaxViewports may not have been set by the driver + * yet, so just initialize all of them. + */ + for (i = 0; i < MAX_VIEWPORTS; i++) { + _mesa_set_viewport(ctx, i, 0, 0, width, height); + } _mesa_set_scissor(ctx, 0, 0, 0, width, height); } } diff --git a/src/mesa/main/viewport.c b/src/mesa/main/viewport.c index ac891c8..cc031b0 100644 --- a/src/mesa/main/viewport.c +++ b/src/mesa/main/viewport.c @@ -197,18 +197,24 @@ _mesa_DepthRangef(GLclampf nearval, GLclampf farval) void _mesa_init_viewport(struct gl_context *ctx) { GLfloat depthMax = 65535.0F; /* sorf of arbitrary */ + unsigned i; - /* Viewport group */ - ctx->ViewportArray[0].X = 0; - ctx->ViewportArray[0].Y = 0; - ctx->ViewportArray[0].Width = 0; - ctx->ViewportArray[0].Height = 0; - ctx->ViewportArray[0].Near = 0.0; - ctx->ViewportArray[0].Far = 1.0; - _math_matrix_ctr(&ctx->ViewportArray[0]._WindowMap); - - _math_matrix_viewport(&ctx->ViewportArray[0]._WindowMap, 0, 0, 0, 0, - 0.0F, 1.0F, depthMax); + /* Note: ctx->Const.MaxViewports may not have been set by the driver yet, + * so just initialize all of them. + */ + for (i = 0; i < MAX_VIEWPORTS; i++) { + /* Viewport group */ + ctx->ViewportArray[i].X = 0; + ctx->ViewportArray[i].Y = 0; + ctx->ViewportArray[i].Width = 0; + ctx->ViewportArray[i].Height = 0; + ctx->ViewportArray[i].Near = 0.0; + 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); + } } @@ -218,6 +224,9 @@ void _mesa_init_viewport(struct gl_context *ctx) */ void _mesa_free_viewport_data(struct gl_context *ctx) { - _math_matrix_dtr(&ctx->ViewportArray[0]._WindowMap); + unsigned i; + + for (i = 0; i < MAX_VIEWPORTS; i++) + _math_matrix_dtr(&ctx->ViewportArray[i]._WindowMap); } -- 1.8.1.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev