Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Mesa 3-D graphics library |
Brian Paul | f084f60 | 2005-09-13 23:37:50 +0000 | [diff] [blame] | 3 | * Version: 6.5 |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. |
| 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | * copy of this software and associated documentation files (the "Software"), |
| 9 | * to deal in the Software without restriction, including without limitation |
| 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | * and/or sell copies of the Software, and to permit persons to whom the |
| 12 | * Software is furnished to do so, subject to the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice shall be included |
| 15 | * in all copies or substantial portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 21 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | |
| 26 | /** |
| 27 | * Functions for allocating/managing framebuffers and renderbuffers. |
| 28 | * Also, routines for reading/writing renderbuffer data as ubytes, |
| 29 | * ushorts, uints, etc. |
| 30 | */ |
| 31 | |
| 32 | |
| 33 | #include "glheader.h" |
| 34 | #include "imports.h" |
| 35 | #include "context.h" |
| 36 | #include "mtypes.h" |
| 37 | #include "fbobject.h" |
| 38 | #include "framebuffer.h" |
| 39 | #include "renderbuffer.h" |
| 40 | |
| 41 | |
| 42 | |
| 43 | /** |
| 44 | * Compute/set the _DepthMax field for the given framebuffer. |
| 45 | * This value depends on the Z buffer resolution. |
| 46 | */ |
| 47 | static void |
| 48 | compute_depth_max(struct gl_framebuffer *fb) |
| 49 | { |
| 50 | if (fb->Visual.depthBits == 0) { |
| 51 | /* Special case. Even if we don't have a depth buffer we need |
| 52 | * good values for DepthMax for Z vertex transformation purposes |
| 53 | * and for per-fragment fog computation. |
| 54 | */ |
| 55 | fb->_DepthMax = (1 << 16) - 1; |
| 56 | } |
| 57 | else if (fb->Visual.depthBits < 32) { |
| 58 | fb->_DepthMax = (1 << fb->Visual.depthBits) - 1; |
| 59 | } |
| 60 | else { |
| 61 | /* Special case since shift values greater than or equal to the |
| 62 | * number of bits in the left hand expression's type are undefined. |
| 63 | */ |
| 64 | fb->_DepthMax = 0xffffffff; |
| 65 | } |
| 66 | fb->_DepthMaxF = (GLfloat) fb->_DepthMax; |
| 67 | fb->_MRD = 1.0; /* Minimum resolvable depth value, for polygon offset */ |
| 68 | } |
| 69 | |
| 70 | |
| 71 | /** |
| 72 | * Create and initialize a gl_framebuffer object. |
| 73 | * This is intended for creating _window_system_ framebuffers, not generic |
| 74 | * framebuffer objects ala GL_EXT_framebuffer_object. |
| 75 | * |
| 76 | * \sa _mesa_new_framebuffer |
| 77 | */ |
| 78 | struct gl_framebuffer * |
| 79 | _mesa_create_framebuffer(const GLvisual *visual) |
| 80 | { |
| 81 | struct gl_framebuffer *fb = CALLOC_STRUCT(gl_framebuffer); |
| 82 | assert(visual); |
| 83 | if (fb) { |
| 84 | _mesa_initialize_framebuffer(fb, visual); |
| 85 | } |
| 86 | return fb; |
| 87 | } |
| 88 | |
| 89 | |
| 90 | /** |
| 91 | * Allocate a new gl_framebuffer object. |
| 92 | * This is the default function for ctx->Driver.NewFramebuffer(). |
| 93 | * This is for allocating user-created framebuffers, not window-system |
| 94 | * framebuffers! |
| 95 | * \sa _mesa_create_framebuffer |
| 96 | */ |
| 97 | struct gl_framebuffer * |
| 98 | _mesa_new_framebuffer(GLcontext *ctx, GLuint name) |
| 99 | { |
| 100 | struct gl_framebuffer *fb; |
| 101 | assert(name != 0); |
| 102 | fb = CALLOC_STRUCT(gl_framebuffer); |
| 103 | if (fb) { |
| 104 | fb->Name = name; |
| 105 | fb->RefCount = 1; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 106 | fb->ColorDrawBuffer[0] = GL_COLOR_ATTACHMENT0_EXT; |
| 107 | fb->_ColorDrawBufferMask[0] = BUFFER_BIT_COLOR0; |
| 108 | fb->ColorReadBuffer = GL_COLOR_ATTACHMENT0_EXT; |
Brian Paul | 048b13d | 2005-09-23 03:22:20 +0000 | [diff] [blame] | 109 | fb->_ColorReadBufferIndex = BUFFER_COLOR0; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 110 | fb->Delete = _mesa_destroy_framebuffer; |
| 111 | } |
| 112 | return fb; |
| 113 | } |
| 114 | |
| 115 | |
| 116 | /** |
Brian Paul | f084f60 | 2005-09-13 23:37:50 +0000 | [diff] [blame] | 117 | * Initialize a gl_framebuffer object. Typically used to initialize |
| 118 | * window system-created framebuffers, not user-created framebuffers. |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 119 | * \sa _mesa_create_framebuffer |
| 120 | */ |
| 121 | void |
| 122 | _mesa_initialize_framebuffer(struct gl_framebuffer *fb, const GLvisual *visual) |
| 123 | { |
| 124 | assert(fb); |
| 125 | assert(visual); |
| 126 | |
| 127 | _mesa_bzero(fb, sizeof(struct gl_framebuffer)); |
| 128 | |
| 129 | /* save the visual */ |
| 130 | fb->Visual = *visual; |
| 131 | |
| 132 | /* Init glRead/DrawBuffer state */ |
| 133 | if (visual->doubleBufferMode) { |
| 134 | fb->ColorDrawBuffer[0] = GL_BACK; |
| 135 | fb->_ColorDrawBufferMask[0] = BUFFER_BIT_BACK_LEFT; |
| 136 | fb->ColorReadBuffer = GL_BACK; |
Brian Paul | 048b13d | 2005-09-23 03:22:20 +0000 | [diff] [blame] | 137 | fb->_ColorReadBufferIndex = BUFFER_BACK_LEFT; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 138 | } |
| 139 | else { |
| 140 | fb->ColorDrawBuffer[0] = GL_FRONT; |
| 141 | fb->_ColorDrawBufferMask[0] = BUFFER_BIT_FRONT_LEFT; |
| 142 | fb->ColorReadBuffer = GL_FRONT; |
Brian Paul | 048b13d | 2005-09-23 03:22:20 +0000 | [diff] [blame] | 143 | fb->_ColorReadBufferIndex = BUFFER_FRONT_LEFT; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | fb->Delete = _mesa_destroy_framebuffer; |
Brian Paul | d95000d | 2005-09-28 15:46:46 +0000 | [diff] [blame] | 147 | fb->_Status = GL_FRAMEBUFFER_COMPLETE_EXT; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 148 | |
| 149 | compute_depth_max(fb); |
| 150 | } |
| 151 | |
| 152 | |
| 153 | /** |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 154 | * Deallocate buffer and everything attached to it. |
Brian Paul | f084f60 | 2005-09-13 23:37:50 +0000 | [diff] [blame] | 155 | * Typically called via the gl_framebuffer->Delete() method. |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 156 | */ |
| 157 | void |
Brian Paul | f084f60 | 2005-09-13 23:37:50 +0000 | [diff] [blame] | 158 | _mesa_destroy_framebuffer(struct gl_framebuffer *fb) |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 159 | { |
Brian Paul | f084f60 | 2005-09-13 23:37:50 +0000 | [diff] [blame] | 160 | if (fb) { |
| 161 | _mesa_free_framebuffer_data(fb); |
| 162 | FREE(fb); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
| 166 | |
| 167 | /** |
| 168 | * Free all the data hanging off the given gl_framebuffer, but don't free |
| 169 | * the gl_framebuffer object itself. |
| 170 | */ |
| 171 | void |
| 172 | _mesa_free_framebuffer_data(struct gl_framebuffer *fb) |
| 173 | { |
| 174 | GLuint i; |
| 175 | |
| 176 | assert(fb); |
| 177 | |
| 178 | for (i = 0; i < BUFFER_COUNT; i++) { |
| 179 | struct gl_renderbuffer_attachment *att = &fb->Attachment[i]; |
| 180 | if (att->Type == GL_RENDERBUFFER_EXT && att->Renderbuffer) { |
| 181 | struct gl_renderbuffer *rb = att->Renderbuffer; |
| 182 | rb->RefCount--; |
| 183 | if (rb->RefCount == 0) { |
| 184 | rb->Delete(rb); |
| 185 | } |
| 186 | } |
| 187 | att->Type = GL_NONE; |
| 188 | att->Renderbuffer = NULL; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | |
| 193 | /** |
| 194 | * Resize the given framebuffer's renderbuffers to the new width and height. |
| 195 | * This should only be used for window-system framebuffers, not |
| 196 | * user-created renderbuffers (i.e. made with GL_EXT_framebuffer_object). |
| 197 | * This will typically be called via ctx->Driver.ResizeBuffers() |
| 198 | */ |
| 199 | void |
| 200 | _mesa_resize_framebuffer(GLcontext *ctx, struct gl_framebuffer *fb, |
| 201 | GLuint width, GLuint height) |
| 202 | { |
| 203 | GLuint i; |
| 204 | |
| 205 | /* For window system framebuffers, Name is zero */ |
| 206 | assert(fb->Name == 0); |
| 207 | |
| 208 | for (i = 0; i < BUFFER_COUNT; i++) { |
| 209 | struct gl_renderbuffer_attachment *att = &fb->Attachment[i]; |
| 210 | if (att->Type == GL_RENDERBUFFER_EXT && att->Renderbuffer) { |
| 211 | struct gl_renderbuffer *rb = att->Renderbuffer; |
| 212 | /* only resize if size is changing */ |
| 213 | if (rb->Width != width || rb->Height != height) { |
| 214 | if (rb->AllocStorage(ctx, rb, rb->InternalFormat, width, height)) { |
| 215 | rb->Width = width; |
| 216 | rb->Height = height; |
| 217 | } |
| 218 | else { |
| 219 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "Resizing framebuffer"); |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | fb->Width = width; |
| 226 | fb->Height = height; |
| 227 | } |
| 228 | |
| 229 | |
| 230 | /** |
| 231 | * Examine all the framebuffer's renderbuffers to update the Width/Height |
| 232 | * fields of the framebuffer. If we have renderbuffers with different |
| 233 | * sizes, set the framebuffer's width and height to zero. |
| 234 | * Note: this is only intended for user-created framebuffers, not |
| 235 | * window-system framebuffes. |
| 236 | */ |
| 237 | static void |
| 238 | update_framebuffer_size(struct gl_framebuffer *fb) |
| 239 | { |
| 240 | GLboolean haveSize = GL_FALSE; |
| 241 | GLuint i; |
| 242 | |
| 243 | /* user-created framebuffers only */ |
| 244 | assert(fb->Name); |
| 245 | |
| 246 | for (i = 0; i < BUFFER_COUNT; i++) { |
| 247 | struct gl_renderbuffer_attachment *att = &fb->Attachment[i]; |
| 248 | const struct gl_renderbuffer *rb = att->Renderbuffer; |
| 249 | if (rb) { |
| 250 | if (haveSize) { |
| 251 | if (rb->Width != fb->Width && rb->Height != fb->Height) { |
| 252 | /* size mismatch! */ |
| 253 | fb->Width = 0; |
| 254 | fb->Height = 0; |
| 255 | return; |
| 256 | } |
| 257 | } |
| 258 | else { |
| 259 | fb->Width = rb->Width; |
| 260 | fb->Height = rb->Height; |
| 261 | haveSize = GL_TRUE; |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | |
| 268 | /** |
| 269 | * Update the context's current drawing buffer's Xmin, Xmax, Ymin, Ymax fields. |
| 270 | * These values are computed from the buffer's width and height and |
| 271 | * the scissor box, if it's enabled. |
| 272 | * \param ctx the GL context. |
| 273 | */ |
| 274 | void |
| 275 | _mesa_update_draw_buffer_bounds(GLcontext *ctx) |
| 276 | { |
| 277 | struct gl_framebuffer *buffer = ctx->DrawBuffer; |
| 278 | |
| 279 | if (buffer->Name) { |
| 280 | /* user-created framebuffer size depends on the renderbuffers */ |
| 281 | update_framebuffer_size(buffer); |
| 282 | } |
| 283 | |
| 284 | buffer->_Xmin = 0; |
| 285 | buffer->_Ymin = 0; |
| 286 | buffer->_Xmax = buffer->Width; |
| 287 | buffer->_Ymax = buffer->Height; |
| 288 | |
| 289 | if (ctx->Scissor.Enabled) { |
| 290 | if (ctx->Scissor.X > buffer->_Xmin) { |
| 291 | buffer->_Xmin = ctx->Scissor.X; |
| 292 | } |
| 293 | if (ctx->Scissor.Y > buffer->_Ymin) { |
| 294 | buffer->_Ymin = ctx->Scissor.Y; |
| 295 | } |
| 296 | if (ctx->Scissor.X + ctx->Scissor.Width < buffer->_Xmax) { |
| 297 | buffer->_Xmax = ctx->Scissor.X + ctx->Scissor.Width; |
| 298 | } |
| 299 | if (ctx->Scissor.Y + ctx->Scissor.Height < buffer->_Ymax) { |
| 300 | buffer->_Ymax = ctx->Scissor.Y + ctx->Scissor.Height; |
| 301 | } |
| 302 | /* finally, check for empty region */ |
| 303 | if (buffer->_Xmin > buffer->_Xmax) { |
| 304 | buffer->_Xmin = buffer->_Xmax; |
| 305 | } |
| 306 | if (buffer->_Ymin > buffer->_Ymax) { |
| 307 | buffer->_Ymin = buffer->_Ymax; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | ASSERT(buffer->_Xmin <= buffer->_Xmax); |
| 312 | ASSERT(buffer->_Ymin <= buffer->_Ymax); |
| 313 | } |
| 314 | |
| 315 | |
| 316 | /** |
| 317 | * The glGet queries of the framebuffer red/green/blue size, stencil size, |
| 318 | * etc. are satisfied by the fields of ctx->DrawBuffer->Visual. These can |
Brian Paul | f084f60 | 2005-09-13 23:37:50 +0000 | [diff] [blame] | 319 | * change depending on the renderbuffer bindings. This function updates |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 320 | * the given framebuffer's Visual from the current renderbuffer bindings. |
| 321 | * This is only intended for user-created framebuffers. |
Brian Paul | eb063cf | 2005-10-04 14:48:24 +0000 | [diff] [blame] | 322 | * |
| 323 | * Also note: ctx->DrawBuffer->Visual.depthBits might not equal |
| 324 | * ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer.DepthBits. |
| 325 | * The former one is used to convert floating point depth values into |
| 326 | * integer Z values. |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 327 | */ |
| 328 | void |
| 329 | _mesa_update_framebuffer_visual(struct gl_framebuffer *fb) |
| 330 | { |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame^] | 331 | GLuint i; |
| 332 | |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 333 | assert(fb->Name != 0); |
| 334 | |
| 335 | _mesa_bzero(&fb->Visual, sizeof(fb->Visual)); |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame^] | 336 | fb->Visual.rgbMode = GL_TRUE; /* assume this */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 337 | |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame^] | 338 | /* find first RGB or CI renderbuffer */ |
| 339 | for (i = 0; i < BUFFER_COUNT; i++) { |
| 340 | if (fb->Attachment[i].Renderbuffer) { |
| 341 | const struct gl_renderbuffer *rb = fb->Attachment[i].Renderbuffer; |
| 342 | if (rb->_BaseFormat == GL_RGBA || rb->_BaseFormat == GL_RGB) { |
| 343 | fb->Visual.redBits = rb->RedBits; |
| 344 | fb->Visual.greenBits = rb->GreenBits; |
| 345 | fb->Visual.blueBits = rb->BlueBits; |
| 346 | fb->Visual.alphaBits = rb->AlphaBits; |
| 347 | fb->Visual.rgbBits = fb->Visual.redBits |
| 348 | + fb->Visual.greenBits + fb->Visual.blueBits; |
| 349 | fb->Visual.floatMode = GL_FALSE; |
| 350 | break; |
| 351 | } |
| 352 | else if (rb->_BaseFormat == GL_COLOR_INDEX) { |
| 353 | fb->Visual.indexBits = rb->IndexBits; |
| 354 | fb->Visual.rgbMode = GL_FALSE; |
| 355 | break; |
| 356 | } |
| 357 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | if (fb->Attachment[BUFFER_DEPTH].Renderbuffer) { |
| 361 | fb->Visual.haveDepthBuffer = GL_TRUE; |
| 362 | fb->Visual.depthBits |
Brian Paul | 676d0ac | 2005-09-22 05:19:57 +0000 | [diff] [blame] | 363 | = fb->Attachment[BUFFER_DEPTH].Renderbuffer->DepthBits; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | if (fb->Attachment[BUFFER_STENCIL].Renderbuffer) { |
| 367 | fb->Visual.haveStencilBuffer = GL_TRUE; |
| 368 | fb->Visual.stencilBits |
Brian Paul | 676d0ac | 2005-09-22 05:19:57 +0000 | [diff] [blame] | 369 | = fb->Attachment[BUFFER_STENCIL].Renderbuffer->StencilBits; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | compute_depth_max(fb); |
| 373 | } |
| 374 | |
| 375 | |
| 376 | /** |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 377 | * Update state related to the current draw/read framebuffers. |
Brian Paul | 5278359 | 2005-08-31 21:38:53 +0000 | [diff] [blame] | 378 | * Specifically, update these framebuffer fields: |
| 379 | * _ColorDrawBuffers |
Brian Paul | 5278359 | 2005-08-31 21:38:53 +0000 | [diff] [blame] | 380 | * _NumColorDrawBuffers |
| 381 | * _ColorReadBuffer |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 382 | * If the current framebuffer is user-created, make sure it's complete. |
Brian Paul | 5278359 | 2005-08-31 21:38:53 +0000 | [diff] [blame] | 383 | * The following functions can effect this state: glReadBuffer, |
| 384 | * glDrawBuffer, glDrawBuffersARB, glFramebufferRenderbufferEXT. |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 385 | */ |
| 386 | void |
| 387 | _mesa_update_framebuffer(GLcontext *ctx) |
| 388 | { |
| 389 | struct gl_framebuffer *fb = ctx->DrawBuffer; |
| 390 | GLuint output; |
| 391 | |
| 392 | /* Completeness only matters for user-created framebuffers */ |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame^] | 393 | if (fb->Name != 0) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 394 | _mesa_test_framebuffer_completeness(ctx, fb); |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame^] | 395 | _mesa_update_framebuffer_visual(fb); |
| 396 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 397 | |
| 398 | /* |
Brian Paul | 048b13d | 2005-09-23 03:22:20 +0000 | [diff] [blame] | 399 | * Update the list of color drawing renderbuffer pointers. |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 400 | * Later, when we're rendering we'll loop from 0 to _NumColorDrawBuffers |
Brian Paul | f084f60 | 2005-09-13 23:37:50 +0000 | [diff] [blame] | 401 | * writing colors. We need the inner loop here because |
| 402 | * glDrawBuffer(GL_FRONT_AND_BACK) can specify writing to two or four |
| 403 | * color buffers (for example). |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 404 | */ |
| 405 | for (output = 0; output < ctx->Const.MaxDrawBuffers; output++) { |
Brian Paul | e00ac11 | 2005-09-15 05:00:45 +0000 | [diff] [blame] | 406 | GLbitfield bufferMask = fb->_ColorDrawBufferMask[output]; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 407 | GLuint count = 0; |
Brian Paul | 048b13d | 2005-09-23 03:22:20 +0000 | [diff] [blame] | 408 | GLuint i; |
| 409 | for (i = 0; bufferMask && i < BUFFER_COUNT; i++) { |
| 410 | const GLuint bufferBit = 1 << i; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 411 | if (bufferBit & bufferMask) { |
Brian Paul | 048b13d | 2005-09-23 03:22:20 +0000 | [diff] [blame] | 412 | struct gl_renderbuffer *rb = fb->Attachment[i].Renderbuffer; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 413 | if (rb) { |
| 414 | fb->_ColorDrawBuffers[output][count] = rb; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 415 | count++; |
| 416 | } |
| 417 | else { |
Brian Paul | a6296dd | 2005-10-03 16:11:47 +0000 | [diff] [blame] | 418 | /*_mesa_warning(ctx, "DrawBuffer names a missing buffer!\n");*/ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 419 | } |
| 420 | bufferMask &= ~bufferBit; |
| 421 | } |
| 422 | } |
| 423 | fb->_NumColorDrawBuffers[output] = count; |
| 424 | } |
| 425 | |
| 426 | /* |
Brian Paul | 048b13d | 2005-09-23 03:22:20 +0000 | [diff] [blame] | 427 | * Update the color read renderbuffer pointer. |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 428 | * Unlike the DrawBuffer, we can only read from one (or zero) color buffers. |
| 429 | */ |
Brian Paul | 048b13d | 2005-09-23 03:22:20 +0000 | [diff] [blame] | 430 | if (fb->_ColorReadBufferIndex == -1) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 431 | fb->_ColorReadBuffer = NULL; /* legal! */ |
Brian Paul | 048b13d | 2005-09-23 03:22:20 +0000 | [diff] [blame] | 432 | } |
| 433 | else { |
| 434 | ASSERT(fb->_ColorReadBufferIndex >= 0); |
| 435 | ASSERT(fb->_ColorReadBufferIndex < BUFFER_COUNT); |
| 436 | fb->_ColorReadBuffer |
| 437 | = fb->Attachment[fb->_ColorReadBufferIndex].Renderbuffer; |
Brian Paul | 048b13d | 2005-09-23 03:22:20 +0000 | [diff] [blame] | 438 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 439 | compute_depth_max(fb); |
| 440 | } |