Fix some issues with glDrawBuffer(GL_NONE), bug 14198
authorBrian <brian.paul@tungstengraphics.com>
Wed, 23 Jan 2008 04:11:55 +0000 (21:11 -0700)
committerBrian <brian.paul@tungstengraphics.com>
Wed, 23 Jan 2008 04:11:55 +0000 (21:11 -0700)
Set _ColorDrawBuffers[0] = NULL if no renderbuffers enabled.
Check that _ColorDrawBuffers[0] is non-null before dereferencing in a few places.

src/mesa/drivers/x11/xm_dd.c
src/mesa/main/framebuffer.c
src/mesa/swrast/s_blit.c
src/mesa/swrast/s_drawpix.c
src/mesa/swrast/s_triangle.c

index e7d41401f9aa5723efb3b57a87146db73423a8b3..56c30ab9491922eaff8765a6a33fd15663bec900 100644 (file)
@@ -436,7 +436,12 @@ xmesa_DrawPixels_8R8G8B( GLcontext *ctx,
 {
    const SWcontext *swrast = SWRAST_CONTEXT( ctx );
    struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];
-   struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb->Wrapped);
+   struct xmesa_renderbuffer *xrb;
+
+   if (!rb)
+      return;
+
+   xrb = xmesa_renderbuffer(rb->Wrapped);
 
    if (swrast->NewState)
       _swrast_validate_derived( ctx );
@@ -543,18 +548,22 @@ xmesa_DrawPixels_5R6G5B( GLcontext *ctx,
                          const struct gl_pixelstore_attrib *unpack,
                          const GLvoid *pixels )
 {
-   struct xmesa_renderbuffer *xrb
-      = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]->Wrapped);
    const XMesaContext xmesa = XMESA_CONTEXT(ctx);
    const SWcontext *swrast = SWRAST_CONTEXT( ctx );
    XMesaDisplay *dpy = xmesa->xm_visual->display;
    XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);
    const XMesaGC gc = xmbuf->cleargc;  /* effected by glColorMask */
+   struct xmesa_renderbuffer *xrb;
 
    ASSERT(dpy);
    ASSERT(gc);
    ASSERT(xmesa->xm_visual->undithered_pf == PF_5R6G5B);
 
+   if (!ctx->DrawBuffer->_ColorDrawBuffers[0])
+      return;
+
+   xrb = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]->Wrapped);
+
    if (swrast->NewState)
       _swrast_validate_derived( ctx );
 
@@ -651,14 +660,18 @@ xmesa_CopyPixels( GLcontext *ctx,
    XMesaDisplay *dpy = xmesa->xm_visual->display;
    XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);
    const XMesaGC gc = xmbuf->cleargc;  /* effected by glColorMask */
-   struct xmesa_renderbuffer *srcXrb
-      = xmesa_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer->Wrapped);
-   struct xmesa_renderbuffer *dstXrb
-      = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]->Wrapped);
+   struct xmesa_renderbuffer *srcXrb, *dstXrb;
+
+   if (!ctx->ReadBuffer->_ColorReadBuffer ||
+       !ctx->DrawBuffer->_ColorDrawBuffers[0])
+      return;
 
    ASSERT(dpy);
    ASSERT(gc);
 
+   srcXrb = xmesa_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer->Wrapped);
+   dstXrb = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]->Wrapped);
+
    if (swrast->NewState)
       _swrast_validate_derived( ctx );
 
index 06a3457488158de24d3e59d9acf94eaf92beec84..d62af98f8a1d89b4c3d3724e0fe1b58dfac645ea 100644 (file)
@@ -641,6 +641,9 @@ update_color_draw_buffers(GLcontext *ctx, struct gl_framebuffer *fb)
 {
    GLuint output;
 
+   /* set 0th buffer to NULL now in case _NumColorDrawBuffers is zero */
+   fb->_ColorDrawBuffers[0] = NULL;
+
    for (output = 0; output < fb->_NumColorDrawBuffers; output++) {
       GLint buf = fb->_ColorDrawBufferIndexes[output];
       if (buf >= 0) {
index a2c40bd9a6b30f58a29d570c7b5998ea35483ddf..af4350990c0470386d106319e1b873402f4a975e 100644 (file)
@@ -745,6 +745,9 @@ _swrast_BlitFramebuffer(GLcontext *ctx,
    };
    GLint i;
 
+   if (!ctx->DrawBuffer->_NumColorDrawBuffers)
+      return;
+
    if (!clip_blit(ctx, &srcX0, &srcY0, &srcX1, &srcY1,
                   &dstX0, &dstY0, &dstX1, &dstY1)) {
       return;
index 7bab14f200eefd663734a1580ec17603cef341dd..4733d10bb5923899da7ddaf0165eb1bb8cb00f9b 100644 (file)
@@ -54,7 +54,7 @@ fast_draw_rgba_pixels(GLcontext *ctx, GLint x, GLint y,
 {
    const GLint imgX = x, imgY = y;
    struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];
-   const GLenum rbType = rb->DataType;
+   GLenum rbType;
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
    SWspan span;
    GLboolean simpleZoom;
@@ -62,6 +62,11 @@ fast_draw_rgba_pixels(GLcontext *ctx, GLint x, GLint y,
    struct gl_pixelstore_attrib unpack;
    GLint destX, destY, drawWidth, drawHeight; /* post clipping */
 
+   if (!rb)
+      return GL_TRUE; /* no-op */
+
+   rbType = rb->DataType;
+
    if ((swrast->_RasterMask & ~CLIP_BIT) ||
        ctx->Texture._EnabledCoordUnits ||
        userUnpack->SwapBytes ||
index 5036020b7c48665c4c91afbd988637c08a0568a6..59e15645f3f5f851baded0f95b6ad63bdfa909e1 100644 (file)
@@ -130,7 +130,7 @@ _swrast_culltriangle( GLcontext *ctx,
 #define T_SCALE theight
 
 #define SETUP_CODE                                                     \
-   struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];\
+   struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0]; \
    struct gl_texture_object *obj = ctx->Texture.Unit[0].Current2D;     \
    const GLint b = obj->BaseLevel;                                     \
    const GLfloat twidth = (GLfloat) obj->Image[0][b]->Width;           \
@@ -139,8 +139,7 @@ _swrast_culltriangle( GLcontext *ctx,
    const GLchan *texture = (const GLchan *) obj->Image[0][b]->Data;    \
    const GLint smask = obj->Image[0][b]->Width - 1;                    \
    const GLint tmask = obj->Image[0][b]->Height - 1;                   \
-   if (!texture) {                                                     \
-      /* this shouldn't happen */                                      \
+   if (!rb || !texture) {                                              \
       return;                                                          \
    }
 
@@ -182,7 +181,7 @@ _swrast_culltriangle( GLcontext *ctx,
 #define T_SCALE theight
 
 #define SETUP_CODE                                                     \
-   struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];\
+   struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0]; \
    struct gl_texture_object *obj = ctx->Texture.Unit[0].Current2D;     \
    const GLint b = obj->BaseLevel;                                     \
    const GLfloat twidth = (GLfloat) obj->Image[0][b]->Width;           \
@@ -191,8 +190,7 @@ _swrast_culltriangle( GLcontext *ctx,
    const GLchan *texture = (const GLchan *) obj->Image[0][b]->Data;    \
    const GLint smask = obj->Image[0][b]->Width - 1;                    \
    const GLint tmask = obj->Image[0][b]->Height - 1;                   \
-   if (!texture) {                                                     \
-      /* this shouldn't happen */                                      \
+   if (!rb || !texture) {                                              \
       return;                                                          \
    }