summaryrefslogtreecommitdiff
path: root/src/mesa
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2009-06-17 08:43:17 -0600
committerBrian Paul <brianp@vmware.com>2009-06-17 11:30:30 -0600
commit1b1acf6fa8189867a15416a098fe70e05913a48b (patch)
tree4dadc0aebb5fa7816feb099e605b67e5b448e3ee /src/mesa
parent1fa42650382e3e0efe612d69e491ea8545a00b93 (diff)
mesa: rework viewport/scissor initialization code
The first time a context is bound to a drawable, the viewport and scissor bounds are initialized to the buffer's size. This is actually a bit tricky. A new _mesa_check_init_viewport() function is called in several places to check if the viewport has been initialized. We also use a new ctx->ViewportInitialized flag instead of the overloaded ctx->FirstTimeCurrent flag. Hand-picked from mesa_7_5_branch, commit 3f856c6b6b7fa95ef97a8712876de88d7d57932e
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/main/context.c41
-rw-r--r--src/mesa/main/context.h3
-rw-r--r--src/mesa/main/mtypes.h2
3 files changed, 34 insertions, 12 deletions
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 9f9a556497d..515c55a284a 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -1553,6 +1553,24 @@ initialize_framebuffer_size(GLcontext *ctx, GLframebuffer *fb)
/**
+ * Check if the viewport/scissor size has not yet been initialized.
+ * Initialize the size if the given width and height are non-zero.
+ */
+void
+_mesa_check_init_viewport(GLcontext *ctx, GLuint width, GLuint height)
+{
+ if (!ctx->ViewportInitialized && width > 0 && height > 0) {
+ /* Note: set flag here, before calling _mesa_set_viewport(), to prevent
+ * potential infinite recursion.
+ */
+ ctx->ViewportInitialized = GL_TRUE;
+ _mesa_set_viewport(ctx, 0, 0, width, height);
+ _mesa_set_scissor(ctx, 0, 0, width, height);
+ }
+}
+
+
+/**
* Bind the given context to the given drawBuffer and readBuffer and
* make it the current context for the calling thread.
* We'll render into the drawBuffer and read pixels from the
@@ -1669,25 +1687,24 @@ _mesa_make_current( GLcontext *newCtx, GLframebuffer *drawBuffer,
ASSERT(drawBuffer->Height > 0);
#endif
- if (newCtx->FirstTimeCurrent) {
- /* set initial viewport and scissor size now */
- _mesa_set_viewport(newCtx, 0, 0,
- drawBuffer->Width, drawBuffer->Height);
- _mesa_set_scissor(newCtx, 0, 0,
- drawBuffer->Width, drawBuffer->Height );
- check_context_limits(newCtx);
+ if (drawBuffer) {
+ _mesa_check_init_viewport(newCtx,
+ drawBuffer->Width, drawBuffer->Height);
}
}
- /* We can use this to help debug user's problems. Tell them to set
- * the MESA_INFO env variable before running their app. Then the
- * first time each context is made current we'll print some useful
- * information.
- */
if (newCtx->FirstTimeCurrent) {
+ check_context_limits(newCtx);
+
+ /* We can use this to help debug user's problems. Tell them to set
+ * the MESA_INFO env variable before running their app. Then the
+ * first time each context is made current we'll print some useful
+ * information.
+ */
if (_mesa_getenv("MESA_INFO")) {
_mesa_print_info();
}
+
newCtx->FirstTimeCurrent = GL_FALSE;
}
}
diff --git a/src/mesa/main/context.h b/src/mesa/main/context.h
index 54f1af911d3..8c1196dd9cb 100644
--- a/src/mesa/main/context.h
+++ b/src/mesa/main/context.h
@@ -132,6 +132,9 @@ extern void
_mesa_make_current( GLcontext *ctx, GLframebuffer *drawBuffer,
GLframebuffer *readBuffer );
+extern void
+_mesa_check_init_viewport(GLcontext *ctx, GLuint width, GLuint height);
+
extern GLboolean
_mesa_share_state(GLcontext *ctx, GLcontext *ctxToShare);
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index d7326590d5f..6bad937c5ce 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -3076,6 +3076,8 @@ struct __GLcontextRec
GLenum RenderMode; /**< either GL_RENDER, GL_SELECT, GL_FEEDBACK */
GLbitfield NewState; /**< bitwise-or of _NEW_* flags */
+ GLboolean ViewportInitialized; /**< has viewport size been initialized? */
+
GLbitfield varying_vp_inputs; /**< mask of VERT_BIT_* flags */
/** \name Derived state */