summaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/main/buffers.c60
-rw-r--r--src/mesa/main/framebuffer.c49
-rw-r--r--src/mesa/main/mtypes.h2
3 files changed, 50 insertions, 61 deletions
diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c
index 2a1af42d79b..bfec9b547d0 100644
--- a/src/mesa/main/buffers.c
+++ b/src/mesa/main/buffers.c
@@ -273,48 +273,49 @@ draw_buffer_enum_to_bitmask(GLenum buffer)
/**
* Helper routine used by glReadBuffer.
- * Given a GLenum naming (a) color buffer(s), return the corresponding
- * bitmask of DD_* flags.
+ * Given a GLenum naming a color buffer, return the index of the corresponding
+ * renderbuffer (a BUFFER_* value).
+ * return -1 for an invalid buffer.
*/
-static GLbitfield
-read_buffer_enum_to_bitmask(GLenum buffer)
+static GLint
+read_buffer_enum_to_index(GLenum buffer)
{
switch (buffer) {
case GL_FRONT:
- return BUFFER_BIT_FRONT_LEFT;
+ return BUFFER_FRONT_LEFT;
case GL_BACK:
- return BUFFER_BIT_BACK_LEFT;
+ return BUFFER_BACK_LEFT;
case GL_RIGHT:
- return BUFFER_BIT_FRONT_RIGHT;
+ return BUFFER_FRONT_RIGHT;
case GL_FRONT_RIGHT:
- return BUFFER_BIT_FRONT_RIGHT;
+ return BUFFER_FRONT_RIGHT;
case GL_BACK_RIGHT:
- return BUFFER_BIT_BACK_RIGHT;
+ return BUFFER_BACK_RIGHT;
case GL_BACK_LEFT:
- return BUFFER_BIT_BACK_LEFT;
+ return BUFFER_BACK_LEFT;
case GL_LEFT:
- return BUFFER_BIT_FRONT_LEFT;
+ return BUFFER_FRONT_LEFT;
case GL_FRONT_LEFT:
- return BUFFER_BIT_FRONT_LEFT;
+ return BUFFER_FRONT_LEFT;
case GL_AUX0:
- return BUFFER_BIT_AUX0;
+ return BUFFER_AUX0;
case GL_AUX1:
- return BUFFER_BIT_AUX1;
+ return BUFFER_AUX1;
case GL_AUX2:
- return BUFFER_BIT_AUX2;
+ return BUFFER_AUX2;
case GL_AUX3:
- return BUFFER_BIT_AUX3;
+ return BUFFER_AUX3;
case GL_COLOR_ATTACHMENT0_EXT:
- return BUFFER_BIT_COLOR0;
+ return BUFFER_COLOR0;
case GL_COLOR_ATTACHMENT1_EXT:
- return BUFFER_BIT_COLOR1;
+ return BUFFER_COLOR1;
case GL_COLOR_ATTACHMENT2_EXT:
- return BUFFER_BIT_COLOR2;
+ return BUFFER_COLOR2;
case GL_COLOR_ATTACHMENT3_EXT:
- return BUFFER_BIT_COLOR3;
+ return BUFFER_COLOR3;
default:
/* error */
- return BAD_MASK;
+ return -1;
}
}
@@ -526,7 +527,8 @@ void GLAPIENTRY
_mesa_ReadBuffer(GLenum buffer)
{
struct gl_framebuffer *fb;
- GLbitfield srcMask, supportedMask;
+ GLbitfield supportedMask;
+ GLint srcBuffer;
GLuint bufferID;
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
@@ -538,18 +540,18 @@ _mesa_ReadBuffer(GLenum buffer)
_mesa_debug(ctx, "glReadBuffer %s\n", _mesa_lookup_enum_by_nr(buffer));
if (bufferID > 0 && buffer == GL_NONE) {
- /* legal! */
- srcMask = 0x0;
+ /* This is legal for user-created framebuffer objects */
+ srcBuffer = -1;
}
else {
- /* general case */
- srcMask = read_buffer_enum_to_bitmask(buffer);
- if (srcMask == BAD_MASK) {
+ /* general case / window-system framebuffer */
+ srcBuffer = read_buffer_enum_to_index(buffer);
+ if (srcBuffer == -1) {
_mesa_error(ctx, GL_INVALID_ENUM, "glReadBuffer(buffer)");
return;
}
supportedMask = supported_buffer_bitmask(ctx, bufferID);
- if ((srcMask & supportedMask) == 0) {
+ if (((1 << srcBuffer) & supportedMask) == 0) {
_mesa_error(ctx, GL_INVALID_OPERATION, "glReadBuffer(buffer)");
return;
}
@@ -559,7 +561,7 @@ _mesa_ReadBuffer(GLenum buffer)
ctx->Pixel.ReadBuffer = buffer;
}
fb->ColorReadBuffer = buffer;
- fb->_ColorReadBufferMask = srcMask;
+ fb->_ColorReadBufferIndex = srcBuffer;
ctx->NewState |= _NEW_PIXEL;
diff --git a/src/mesa/main/framebuffer.c b/src/mesa/main/framebuffer.c
index 4ad82c85ffe..abfde18e3ea 100644
--- a/src/mesa/main/framebuffer.c
+++ b/src/mesa/main/framebuffer.c
@@ -106,7 +106,7 @@ _mesa_new_framebuffer(GLcontext *ctx, GLuint name)
fb->ColorDrawBuffer[0] = GL_COLOR_ATTACHMENT0_EXT;
fb->_ColorDrawBufferMask[0] = BUFFER_BIT_COLOR0;
fb->ColorReadBuffer = GL_COLOR_ATTACHMENT0_EXT;
- fb->_ColorReadBufferMask = BUFFER_BIT_COLOR0;
+ fb->_ColorReadBufferIndex = BUFFER_COLOR0;
fb->Delete = _mesa_destroy_framebuffer;
}
return fb;
@@ -134,13 +134,13 @@ _mesa_initialize_framebuffer(struct gl_framebuffer *fb, const GLvisual *visual)
fb->ColorDrawBuffer[0] = GL_BACK;
fb->_ColorDrawBufferMask[0] = BUFFER_BIT_BACK_LEFT;
fb->ColorReadBuffer = GL_BACK;
- fb->_ColorReadBufferMask = BUFFER_BIT_BACK_LEFT;
+ fb->_ColorReadBufferIndex = BUFFER_BACK_LEFT;
}
else {
fb->ColorDrawBuffer[0] = GL_FRONT;
fb->_ColorDrawBufferMask[0] = BUFFER_BIT_FRONT_LEFT;
fb->ColorReadBuffer = GL_FRONT;
- fb->_ColorReadBufferMask = BUFFER_BIT_FRONT_LEFT;
+ fb->_ColorReadBufferIndex = BUFFER_FRONT_LEFT;
}
fb->Delete = _mesa_destroy_framebuffer;
@@ -358,24 +358,6 @@ _mesa_update_framebuffer_visual(struct gl_framebuffer *fb)
/**
- * Given a framebuffer and a buffer bit (like BUFFER_BIT_FRONT_LEFT), return
- * the corresponding renderbuffer.
- */
-static struct gl_renderbuffer *
-get_renderbuffer(struct gl_framebuffer *fb, GLbitfield bufferBit)
-{
- GLuint index;
- for (index = 0; index < BUFFER_COUNT; index++) {
- if ((1 << index) == bufferBit) {
- return fb->Attachment[index].Renderbuffer;
- }
- }
- _mesa_problem(NULL, "Bad bufferBit in get_renderbuffer");
- return NULL;
-}
-
-
-/**
* Update state related to the current draw/read framebuffers.
* Specifically, update these framebuffer fields:
* _ColorDrawBuffers
@@ -396,7 +378,7 @@ _mesa_update_framebuffer(GLcontext *ctx)
_mesa_test_framebuffer_completeness(ctx, fb);
/*
- * Update the list of drawing renderbuffer pointers.
+ * Update the list of color drawing renderbuffer pointers.
* Later, when we're rendering we'll loop from 0 to _NumColorDrawBuffers
* writing colors. We need the inner loop here because
* glDrawBuffer(GL_FRONT_AND_BACK) can specify writing to two or four
@@ -405,11 +387,11 @@ _mesa_update_framebuffer(GLcontext *ctx)
for (output = 0; output < ctx->Const.MaxDrawBuffers; output++) {
GLbitfield bufferMask = fb->_ColorDrawBufferMask[output];
GLuint count = 0;
- GLuint bufferBit;
- /* for each bit that's set in the bufferMask... */
- for (bufferBit = 1; bufferMask; bufferBit <<= 1) {
+ GLuint i;
+ for (i = 0; bufferMask && i < BUFFER_COUNT; i++) {
+ const GLuint bufferBit = 1 << i;
if (bufferBit & bufferMask) {
- struct gl_renderbuffer *rb = get_renderbuffer(fb, bufferBit);
+ struct gl_renderbuffer *rb = fb->Attachment[i].Renderbuffer;
if (rb) {
fb->_ColorDrawBuffers[output][count] = rb;
count++;
@@ -424,13 +406,18 @@ _mesa_update_framebuffer(GLcontext *ctx)
}
/*
- * Update the read renderbuffer pointer.
+ * Update the color read renderbuffer pointer.
* Unlike the DrawBuffer, we can only read from one (or zero) color buffers.
*/
- if (fb->_ColorReadBufferMask == 0x0)
+ if (fb->_ColorReadBufferIndex == -1) {
fb->_ColorReadBuffer = NULL; /* legal! */
- else
- fb->_ColorReadBuffer = get_renderbuffer(fb, fb->_ColorReadBufferMask);
-
+ }
+ else {
+ ASSERT(fb->_ColorReadBufferIndex >= 0);
+ ASSERT(fb->_ColorReadBufferIndex < BUFFER_COUNT);
+ fb->_ColorReadBuffer
+ = fb->Attachment[fb->_ColorReadBufferIndex].Renderbuffer;
+ printf("Read buffer index %d\n", fb->_ColorReadBufferIndex);
+ }
compute_depth_max(fb);
}
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index f8f9c137c85..beb371fb014 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2198,7 +2198,7 @@ struct gl_framebuffer
/* These are computed from ColorDrawBuffer and ColorReadBuffer */
GLbitfield _ColorDrawBufferMask[MAX_DRAW_BUFFERS]; /* Mask of BUFFER_BIT_* flags */
- GLbitfield _ColorReadBufferMask; /* Zero or one of BUFFER_BIT_ flags */
+ GLint _ColorReadBufferIndex; /* -1 = None */
/* These are computed from _Draw/ReadBufferMask, above. */
GLuint _NumColorDrawBuffers[MAX_DRAW_BUFFERS];