X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fbuffers.c;h=3cbd671baba794e9b9fe7c7814a3b82dadcf2edd;hb=ff938bf059a41a9bdf4c2c93cebe4a3b8a89c201;hp=28fbc34ff7815e13c0a7748e98adc16f9ad0c906;hpb=28b014ee256290eb0494b967e40c475c0c895f57;p=mesa.git diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c index 28fbc34ff78..3cbd671baba 100644 --- a/src/mesa/main/buffers.c +++ b/src/mesa/main/buffers.c @@ -1,13 +1,8 @@ -/** - * \file buffers.c - * Frame buffer management. - */ - /* * Mesa 3-D graphics library - * Version: 6.5 + * Version: 7.1 * - * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -28,6 +23,13 @@ */ +/** + * \file buffers.c + * General framebuffer-related functions, like glClear, glScissor, etc. + */ + + + #include "glheader.h" #include "buffers.h" #include "colormac.h" @@ -116,6 +118,8 @@ _mesa_Clear( GLbitfield mask ) GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); + FLUSH_CURRENT(ctx, 0); + if (MESA_VERBOSE & VERBOSE_API) _mesa_debug(ctx, "glClear 0x%x\n", mask); @@ -138,11 +142,10 @@ _mesa_Clear( GLbitfield mask ) return; } + if (ctx->DrawBuffer->Width == 0 || ctx->DrawBuffer->Height == 0) + return; + if (ctx->RenderMode == GL_RENDER) { - const GLint x = ctx->DrawBuffer->_Xmin; - const GLint y = ctx->DrawBuffer->_Ymin; - const GLint height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin; - const GLint width = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin; GLbitfield bufferMask; /* don't clear depth buffer if depth writing disabled */ @@ -175,8 +178,7 @@ _mesa_Clear( GLbitfield mask ) } ASSERT(ctx->Driver.Clear); - ctx->Driver.Clear( ctx, bufferMask, (GLboolean) !ctx->Scissor.Enabled, - x, y, width, height ); + ctx->Driver.Clear(ctx, bufferMask); } } @@ -184,17 +186,19 @@ _mesa_Clear( GLbitfield mask ) /** * Return bitmask of BUFFER_BIT_* flags indicating which color buffers are - * available to the rendering context. - * This depends on the framebuffer we're writing to. For window system - * framebuffers we look at the framebuffer's visual. But for user- - * create framebuffers we look at the number of supported color attachments. + * available to the rendering context (for drawing or reading). + * This depends on the type of framebuffer. For window system framebuffers + * we look at the framebuffer's visual. But for user-create framebuffers we + * look at the number of supported color attachments. + * \param fb the framebuffer to draw to, or read from + * \return bitmask of BUFFER_BIT_* flags */ static GLbitfield -supported_buffer_bitmask(const GLcontext *ctx, GLuint framebufferID) +supported_buffer_bitmask(const GLcontext *ctx, const struct gl_framebuffer *fb) { GLbitfield mask = 0x0; - if (framebufferID > 0) { + if (fb->Name > 0) { /* A user-created renderbuffer */ GLuint i; ASSERT(ctx->Extensions.EXT_framebuffer_object); @@ -203,20 +207,20 @@ supported_buffer_bitmask(const GLcontext *ctx, GLuint framebufferID) } } else { - /* A window system renderbuffer */ + /* A window system framebuffer */ GLint i; mask = BUFFER_BIT_FRONT_LEFT; /* always have this */ - if (ctx->Visual.stereoMode) { + if (fb->Visual.stereoMode) { mask |= BUFFER_BIT_FRONT_RIGHT; - if (ctx->Visual.doubleBufferMode) { + if (fb->Visual.doubleBufferMode) { mask |= BUFFER_BIT_BACK_LEFT | BUFFER_BIT_BACK_RIGHT; } } - else if (ctx->Visual.doubleBufferMode) { + else if (fb->Visual.doubleBufferMode) { mask |= BUFFER_BIT_BACK_LEFT; } - for (i = 0; i < ctx->Visual.numAuxBuffers; i++) { + for (i = 0; i < fb->Visual.numAuxBuffers; i++) { mask |= (BUFFER_BIT_AUX0 << i); } } @@ -338,7 +342,6 @@ read_buffer_enum_to_index(GLenum buffer) void GLAPIENTRY _mesa_DrawBuffer(GLenum buffer) { - GLuint bufferID; GLbitfield destMask; GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex... */ @@ -347,13 +350,12 @@ _mesa_DrawBuffer(GLenum buffer) _mesa_debug(ctx, "glDrawBuffer %s\n", _mesa_lookup_enum_by_nr(buffer)); } - bufferID = ctx->DrawBuffer->Name; - if (buffer == GL_NONE) { destMask = 0x0; } else { - const GLbitfield supportedMask = supported_buffer_bitmask(ctx, bufferID); + const GLbitfield supportedMask + = supported_buffer_bitmask(ctx, ctx->DrawBuffer); destMask = draw_buffer_enum_to_bitmask(buffer); if (destMask == BAD_MASK) { /* totally bogus buffer */ @@ -370,6 +372,14 @@ _mesa_DrawBuffer(GLenum buffer) /* if we get here, there's no error so set new state */ _mesa_drawbuffers(ctx, 1, &buffer, &destMask); + + /* + * Call device driver function. + */ + if (ctx->Driver.DrawBuffers) + ctx->Driver.DrawBuffers(ctx, 1, &buffer); + else if (ctx->Driver.DrawBuffer) + ctx->Driver.DrawBuffer(ctx, buffer); } @@ -386,7 +396,6 @@ void GLAPIENTRY _mesa_DrawBuffersARB(GLsizei n, const GLenum *buffers) { GLint output; - GLuint bufferID; GLbitfield usedBufferMask, supportedMask; GLbitfield destMask[MAX_DRAW_BUFFERS]; GET_CURRENT_CONTEXT(ctx); @@ -401,9 +410,7 @@ _mesa_DrawBuffersARB(GLsizei n, const GLenum *buffers) return; } - bufferID = ctx->DrawBuffer->Name; - - supportedMask = supported_buffer_bitmask(ctx, bufferID); + supportedMask = supported_buffer_bitmask(ctx, ctx->DrawBuffer); usedBufferMask = 0x0; /* complicated error checking... */ @@ -438,6 +445,14 @@ _mesa_DrawBuffersARB(GLsizei n, const GLenum *buffers) /* OK, if we get here, there were no errors so set the new state */ _mesa_drawbuffers(ctx, n, buffers, destMask); + + /* + * Call device driver function. + */ + if (ctx->Driver.DrawBuffers) + ctx->Driver.DrawBuffers(ctx, n, buffers); + else if (ctx->Driver.DrawBuffer) + ctx->Driver.DrawBuffer(ctx, buffers[0]); } @@ -460,22 +475,21 @@ set_color_output(GLcontext *ctx, GLuint output, GLenum buffer, ASSERT(output < ctx->Const.MaxDrawBuffers); + /* Set per-FBO state */ fb->ColorDrawBuffer[output] = buffer; fb->_ColorDrawBufferMask[output] = destMask; - - if (fb->Name == 0) { - /* Set traditional state var */ - ctx->Color.DrawBuffer[output] = buffer; - } - /* not really needed, will be set later */ fb->_NumColorDrawBuffers[output] = 0; + + if (fb->Name == 0) + /* Set traditional state var */ + ctx->Color.DrawBuffer[output] = buffer; } /** * Helper routine used by _mesa_DrawBuffer, _mesa_DrawBuffersARB and - * _mesa_PopAttrib to set drawbuffer state. + * other places (window fbo fixup) to set fbo (and the old ctx) fields. * All error checking will have been done prior to calling this function * so nothing should go wrong at this point. * \param ctx current context @@ -494,8 +508,8 @@ _mesa_drawbuffers(GLcontext *ctx, GLuint n, const GLenum *buffers, if (!destMask) { /* compute destMask values now */ - const GLuint bufferID = ctx->DrawBuffer->Name; - const GLbitfield supportedMask = supported_buffer_bitmask(ctx, bufferID); + const GLbitfield supportedMask + = supported_buffer_bitmask(ctx, ctx->DrawBuffer); for (output = 0; output < n; output++) { mask[output] = draw_buffer_enum_to_bitmask(buffers[output]); ASSERT(mask[output] != BAD_MASK); @@ -513,40 +527,23 @@ _mesa_drawbuffers(GLcontext *ctx, GLuint n, const GLenum *buffers, set_color_output(ctx, output, GL_NONE, 0x0); } - ctx->NewState |= _NEW_COLOR; - - /* - * Call device driver function. - */ - if (ctx->Driver.DrawBuffers) - ctx->Driver.DrawBuffers(ctx, n, buffers); - else if (ctx->Driver.DrawBuffer) - ctx->Driver.DrawBuffer(ctx, buffers[0]); + ctx->NewState |= _NEW_BUFFERS; } - -/** - * Called by glReadBuffer to set the source renderbuffer for reading pixels. - * \param mode color buffer such as GL_FRONT, GL_BACK, etc. - */ -void GLAPIENTRY -_mesa_ReadBuffer(GLenum buffer) +GLboolean +_mesa_readbuffer_update_fields(GLcontext *ctx, GLenum buffer) { struct gl_framebuffer *fb; GLbitfield supportedMask; GLint srcBuffer; - GLuint bufferID; - GET_CURRENT_CONTEXT(ctx); - ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); fb = ctx->ReadBuffer; - bufferID = fb->Name; if (MESA_VERBOSE & VERBOSE_API) _mesa_debug(ctx, "glReadBuffer %s\n", _mesa_lookup_enum_by_nr(buffer)); - if (bufferID > 0 && buffer == GL_NONE) { + if (fb->Name > 0 && buffer == GL_NONE) { /* This is legal for user-created framebuffer objects */ srcBuffer = -1; } @@ -555,22 +552,43 @@ _mesa_ReadBuffer(GLenum buffer) srcBuffer = read_buffer_enum_to_index(buffer); if (srcBuffer == -1) { _mesa_error(ctx, GL_INVALID_ENUM, "glReadBuffer(buffer=0x%x)", buffer); - return; + return GL_FALSE; } - supportedMask = supported_buffer_bitmask(ctx, bufferID); + supportedMask = supported_buffer_bitmask(ctx, fb); if (((1 << srcBuffer) & supportedMask) == 0) { _mesa_error(ctx, GL_INVALID_OPERATION, "glReadBuffer(buffer=0x%x)", buffer); - return; + return GL_FALSE; } } - if (bufferID == 0) { + if (fb->Name == 0) { ctx->Pixel.ReadBuffer = buffer; } fb->ColorReadBuffer = buffer; fb->_ColorReadBufferIndex = srcBuffer; - ctx->NewState |= _NEW_PIXEL; + return GL_TRUE; +} + + + +/** + * Called by glReadBuffer to set the source renderbuffer for reading pixels. + * \param mode color buffer such as GL_FRONT, GL_BACK, etc. + */ +void GLAPIENTRY +_mesa_ReadBuffer(GLenum buffer) +{ + GET_CURRENT_CONTEXT(ctx); + ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); + + if (MESA_VERBOSE & VERBOSE_API) + _mesa_debug(ctx, "glReadBuffer %s\n", _mesa_lookup_enum_by_nr(buffer)); + + if (!_mesa_readbuffer_update_fields(ctx, buffer)) + return; + + ctx->NewState |= _NEW_BUFFERS; /* * Call device driver function. @@ -583,6 +601,9 @@ _mesa_ReadBuffer(GLenum buffer) #if _HAVE_FULL_GL /** + * XXX THIS IS OBSOLETE - drivers should take care of detecting window + * size changes and act accordingly, likely calling _mesa_resize_framebuffer(). + * * GL_MESA_resize_buffers extension. * * When this function is called, we'll ask the window system how large @@ -593,16 +614,18 @@ _mesa_ReadBuffer(GLenum buffer) * \note This function should only be called through the GL API, not * from device drivers (as was done in the past). */ -void GLAPIENTRY -_mesa_ResizeBuffersMESA( void ) -{ - GET_CURRENT_CONTEXT(ctx); +void _mesa_resizebuffers( GLcontext *ctx ) +{ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx ); if (MESA_VERBOSE & VERBOSE_API) _mesa_debug(ctx, "glResizeBuffersMESA\n"); + if (!ctx->Driver.GetBufferSize) { + return; + } + if (ctx->WinSysDrawBuffer) { GLuint newWidth, newHeight; GLframebuffer *buffer = ctx->WinSysDrawBuffer; @@ -640,6 +663,19 @@ _mesa_ResizeBuffersMESA( void ) } +/* + * XXX THIS IS OBSOLETE + */ +void GLAPIENTRY +_mesa_ResizeBuffersMESA( void ) +{ + GET_CURRENT_CONTEXT(ctx); + + if (ctx->Extensions.MESA_resize_buffers) + _mesa_resizebuffers( ctx ); +} + + /* * XXX move somewhere else someday? */