1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 /**
27 * Functions for allocating/managing software-based renderbuffers.
28 * Also, routines for reading/writing software-based renderbuffer data as
29 * ubytes, ushorts, uints, etc.
30 */
31
32
33 #include "main/glheader.h"
34
35 #include "main/context.h"
36 #include "main/fbobject.h"
37 #include "main/formats.h"
38 #include "main/mtypes.h"
39 #include "main/renderbuffer.h"
40 #include "util/u_memory.h"
41 #include "swrast/s_context.h"
42 #include "swrast/s_renderbuffer.h"
43
44
45 /**
46 * This is a software fallback for the gl_renderbuffer->AllocStorage
47 * function.
48 * Device drivers will typically override this function for the buffers
49 * which it manages (typically color buffers, Z and stencil).
50 * Other buffers (like software accumulation and aux buffers) which the driver
51 * doesn't manage can be handled with this function.
52 *
53 * This one multi-purpose function can allocate stencil, depth, accum, color
54 * or color-index buffers!
55 */
56 static GLboolean
soft_renderbuffer_storage(struct gl_context * ctx,struct gl_renderbuffer * rb,GLenum internalFormat,GLuint width,GLuint height)57 soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
58 GLenum internalFormat,
59 GLuint width, GLuint height)
60 {
61 struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
62 GLuint bpp;
63
64 switch (internalFormat) {
65 case GL_RGB:
66 case GL_R3_G3_B2:
67 case GL_RGB4:
68 case GL_RGB5:
69 case GL_RGB8:
70 case GL_RGB10:
71 case GL_RGB12:
72 case GL_RGB16:
73 rb->Format = MESA_FORMAT_BGR_UNORM8;
74 break;
75 case GL_RGBA:
76 case GL_RGBA2:
77 case GL_RGBA4:
78 case GL_RGB5_A1:
79 case GL_RGBA8:
80 case GL_RGB10_A2:
81 case GL_RGBA12:
82 #if UTIL_ARCH_LITTLE_ENDIAN
83 rb->Format = MESA_FORMAT_R8G8B8A8_UNORM;
84 #else
85 rb->Format = MESA_FORMAT_A8B8G8R8_UNORM;
86 #endif
87 break;
88 case GL_RGBA16:
89 case GL_RGBA16_SNORM:
90 /* for accum buffer */
91 rb->Format = MESA_FORMAT_RGBA_SNORM16;
92 break;
93 case GL_STENCIL_INDEX:
94 case GL_STENCIL_INDEX1_EXT:
95 case GL_STENCIL_INDEX4_EXT:
96 case GL_STENCIL_INDEX8_EXT:
97 case GL_STENCIL_INDEX16_EXT:
98 rb->Format = MESA_FORMAT_S_UINT8;
99 break;
100 case GL_DEPTH_COMPONENT:
101 case GL_DEPTH_COMPONENT16:
102 rb->Format = MESA_FORMAT_Z_UNORM16;
103 break;
104 case GL_DEPTH_COMPONENT24:
105 rb->Format = MESA_FORMAT_Z24_UNORM_X8_UINT;
106 break;
107 case GL_DEPTH_COMPONENT32:
108 rb->Format = MESA_FORMAT_Z_UNORM32;
109 break;
110 case GL_DEPTH_STENCIL_EXT:
111 case GL_DEPTH24_STENCIL8_EXT:
112 rb->Format = MESA_FORMAT_S8_UINT_Z24_UNORM;
113 break;
114 default:
115 /* unsupported format */
116 return GL_FALSE;
117 }
118
119 bpp = _mesa_get_format_bytes(rb->Format);
120
121 /* free old buffer storage */
122 free(srb->Buffer);
123 srb->Buffer = NULL;
124
125 srb->RowStride = width * bpp;
126
127 if (width > 0 && height > 0) {
128 /* allocate new buffer storage */
129 srb->Buffer = malloc(srb->RowStride * height);
130
131 if (srb->Buffer == NULL) {
132 rb->Width = 0;
133 rb->Height = 0;
134 _mesa_error(ctx, GL_OUT_OF_MEMORY,
135 "software renderbuffer allocation (%d x %d x %d)",
136 width, height, bpp);
137 return GL_FALSE;
138 }
139 }
140
141 rb->Width = width;
142 rb->Height = height;
143 rb->_BaseFormat = _mesa_base_fbo_format(ctx, internalFormat);
144
145 if (rb->Name == 0 &&
146 internalFormat == GL_RGBA16_SNORM &&
147 rb->_BaseFormat == 0) {
148 /* NOTE: This is a special case just for accumulation buffers.
149 * This is a very limited use case- there's no snorm texturing or
150 * rendering going on.
151 */
152 rb->_BaseFormat = GL_RGBA;
153 }
154 else {
155 /* the internalFormat should have been error checked long ago */
156 assert(rb->_BaseFormat);
157 }
158
159 return GL_TRUE;
160 }
161
162
163 /**
164 * Called via gl_renderbuffer::Delete()
165 */
166 static void
soft_renderbuffer_delete(struct gl_context * ctx,struct gl_renderbuffer * rb)167 soft_renderbuffer_delete(struct gl_context *ctx, struct gl_renderbuffer *rb)
168 {
169 struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
170
171 free(srb->Buffer);
172 srb->Buffer = NULL;
173 _mesa_delete_renderbuffer(ctx, rb);
174 }
175
176
177 void
_swrast_map_soft_renderbuffer(struct gl_context * ctx,struct gl_renderbuffer * rb,GLuint x,GLuint y,GLuint w,GLuint h,GLbitfield mode,GLubyte ** out_map,GLint * out_stride,bool flip_y)178 _swrast_map_soft_renderbuffer(struct gl_context *ctx,
179 struct gl_renderbuffer *rb,
180 GLuint x, GLuint y, GLuint w, GLuint h,
181 GLbitfield mode,
182 GLubyte **out_map,
183 GLint *out_stride,
184 bool flip_y)
185 {
186 struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
187 GLubyte *map = srb->Buffer;
188 int cpp = _mesa_get_format_bytes(rb->Format);
189 int stride = rb->Width * cpp;
190
191 if (!map) {
192 *out_map = NULL;
193 *out_stride = 0;
194 }
195
196 map += y * stride;
197 map += x * cpp;
198
199 *out_map = map;
200 *out_stride = stride;
201 }
202
203
204 void
_swrast_unmap_soft_renderbuffer(struct gl_context * ctx,struct gl_renderbuffer * rb)205 _swrast_unmap_soft_renderbuffer(struct gl_context *ctx,
206 struct gl_renderbuffer *rb)
207 {
208 }
209
210
211
212 /**
213 * Allocate a software-based renderbuffer. This is called via the
214 * ctx->Driver.NewRenderbuffer() function when the user creates a new
215 * renderbuffer.
216 * This would not be used for hardware-based renderbuffers.
217 */
218 struct gl_renderbuffer *
_swrast_new_soft_renderbuffer(struct gl_context * ctx,GLuint name)219 _swrast_new_soft_renderbuffer(struct gl_context *ctx, GLuint name)
220 {
221 struct swrast_renderbuffer *srb = CALLOC_STRUCT(swrast_renderbuffer);
222 if (srb) {
223 _mesa_init_renderbuffer(&srb->Base, name);
224 srb->Base.AllocStorage = soft_renderbuffer_storage;
225 srb->Base.Delete = soft_renderbuffer_delete;
226 }
227 return &srb->Base;
228 }
229
230
231 /**
232 * Add software-based color renderbuffers to the given framebuffer.
233 * This is a helper routine for device drivers when creating a
234 * window system framebuffer (not a user-created render/framebuffer).
235 * Once this function is called, you can basically forget about this
236 * renderbuffer; core Mesa will handle all the buffer management and
237 * rendering!
238 */
239 static GLboolean
add_color_renderbuffers(struct gl_context * ctx,struct gl_framebuffer * fb,GLuint rgbBits,GLuint alphaBits,GLboolean frontLeft,GLboolean backLeft,GLboolean frontRight,GLboolean backRight)240 add_color_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,
241 GLuint rgbBits, GLuint alphaBits,
242 GLboolean frontLeft, GLboolean backLeft,
243 GLboolean frontRight, GLboolean backRight)
244 {
245 gl_buffer_index b;
246
247 if (rgbBits > 16 || alphaBits > 16) {
248 _mesa_problem(ctx,
249 "Unsupported bit depth in add_color_renderbuffers");
250 return GL_FALSE;
251 }
252
253 assert(MAX_COLOR_ATTACHMENTS >= 4);
254
255 for (b = BUFFER_FRONT_LEFT; b <= BUFFER_BACK_RIGHT; b++) {
256 struct gl_renderbuffer *rb;
257
258 if (b == BUFFER_FRONT_LEFT && !frontLeft)
259 continue;
260 else if (b == BUFFER_BACK_LEFT && !backLeft)
261 continue;
262 else if (b == BUFFER_FRONT_RIGHT && !frontRight)
263 continue;
264 else if (b == BUFFER_BACK_RIGHT && !backRight)
265 continue;
266
267 assert(fb->Attachment[b].Renderbuffer == NULL);
268
269 rb = ctx->Driver.NewRenderbuffer(ctx, 0);
270 if (!rb) {
271 _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating color buffer");
272 return GL_FALSE;
273 }
274
275 rb->InternalFormat = GL_RGBA;
276
277 rb->AllocStorage = soft_renderbuffer_storage;
278 _mesa_attach_and_own_rb(fb, b, rb);
279 }
280
281 return GL_TRUE;
282 }
283
284
285 /**
286 * Add a software-based depth renderbuffer to the given framebuffer.
287 * This is a helper routine for device drivers when creating a
288 * window system framebuffer (not a user-created render/framebuffer).
289 * Once this function is called, you can basically forget about this
290 * renderbuffer; core Mesa will handle all the buffer management and
291 * rendering!
292 */
293 static GLboolean
add_depth_renderbuffer(struct gl_context * ctx,struct gl_framebuffer * fb,GLuint depthBits)294 add_depth_renderbuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
295 GLuint depthBits)
296 {
297 struct gl_renderbuffer *rb;
298
299 if (depthBits > 32) {
300 _mesa_problem(ctx,
301 "Unsupported depthBits in add_depth_renderbuffer");
302 return GL_FALSE;
303 }
304
305 assert(fb->Attachment[BUFFER_DEPTH].Renderbuffer == NULL);
306
307 rb = _swrast_new_soft_renderbuffer(ctx, 0);
308 if (!rb) {
309 _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating depth buffer");
310 return GL_FALSE;
311 }
312
313 if (depthBits <= 16) {
314 rb->InternalFormat = GL_DEPTH_COMPONENT16;
315 }
316 else if (depthBits <= 24) {
317 rb->InternalFormat = GL_DEPTH_COMPONENT24;
318 }
319 else {
320 rb->InternalFormat = GL_DEPTH_COMPONENT32;
321 }
322
323 rb->AllocStorage = soft_renderbuffer_storage;
324 _mesa_attach_and_own_rb(fb, BUFFER_DEPTH, rb);
325
326 return GL_TRUE;
327 }
328
329
330 /**
331 * Add a software-based stencil renderbuffer to the given framebuffer.
332 * This is a helper routine for device drivers when creating a
333 * window system framebuffer (not a user-created render/framebuffer).
334 * Once this function is called, you can basically forget about this
335 * renderbuffer; core Mesa will handle all the buffer management and
336 * rendering!
337 */
338 static GLboolean
add_stencil_renderbuffer(struct gl_context * ctx,struct gl_framebuffer * fb,GLuint stencilBits)339 add_stencil_renderbuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
340 GLuint stencilBits)
341 {
342 struct gl_renderbuffer *rb;
343
344 if (stencilBits > 16) {
345 _mesa_problem(ctx,
346 "Unsupported stencilBits in add_stencil_renderbuffer");
347 return GL_FALSE;
348 }
349
350 assert(fb->Attachment[BUFFER_STENCIL].Renderbuffer == NULL);
351
352 rb = _swrast_new_soft_renderbuffer(ctx, 0);
353 if (!rb) {
354 _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating stencil buffer");
355 return GL_FALSE;
356 }
357
358 assert(stencilBits <= 8);
359 rb->InternalFormat = GL_STENCIL_INDEX8;
360
361 rb->AllocStorage = soft_renderbuffer_storage;
362 _mesa_attach_and_own_rb(fb, BUFFER_STENCIL, rb);
363
364 return GL_TRUE;
365 }
366
367
368 static GLboolean
add_depth_stencil_renderbuffer(struct gl_context * ctx,struct gl_framebuffer * fb)369 add_depth_stencil_renderbuffer(struct gl_context *ctx,
370 struct gl_framebuffer *fb)
371 {
372 struct gl_renderbuffer *rb;
373
374 assert(fb->Attachment[BUFFER_DEPTH].Renderbuffer == NULL);
375 assert(fb->Attachment[BUFFER_STENCIL].Renderbuffer == NULL);
376
377 rb = _swrast_new_soft_renderbuffer(ctx, 0);
378 if (!rb) {
379 _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating depth+stencil buffer");
380 return GL_FALSE;
381 }
382
383 rb->InternalFormat = GL_DEPTH_STENCIL;
384
385 rb->AllocStorage = soft_renderbuffer_storage;
386 _mesa_attach_and_own_rb(fb, BUFFER_DEPTH, rb);
387 _mesa_attach_and_reference_rb(fb, BUFFER_STENCIL, rb);
388
389 return GL_TRUE;
390 }
391
392
393 /**
394 * Add a software-based accumulation renderbuffer to the given framebuffer.
395 * This is a helper routine for device drivers when creating a
396 * window system framebuffer (not a user-created render/framebuffer).
397 * Once this function is called, you can basically forget about this
398 * renderbuffer; core Mesa will handle all the buffer management and
399 * rendering!
400 */
401 static GLboolean
add_accum_renderbuffer(struct gl_context * ctx,struct gl_framebuffer * fb,GLuint redBits,GLuint greenBits,GLuint blueBits,GLuint alphaBits)402 add_accum_renderbuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
403 GLuint redBits, GLuint greenBits,
404 GLuint blueBits, GLuint alphaBits)
405 {
406 struct gl_renderbuffer *rb;
407
408 if (redBits > 16 || greenBits > 16 || blueBits > 16 || alphaBits > 16) {
409 _mesa_problem(ctx,
410 "Unsupported accumBits in add_accum_renderbuffer");
411 return GL_FALSE;
412 }
413
414 assert(fb->Attachment[BUFFER_ACCUM].Renderbuffer == NULL);
415
416 rb = _swrast_new_soft_renderbuffer(ctx, 0);
417 if (!rb) {
418 _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating accum buffer");
419 return GL_FALSE;
420 }
421
422 rb->InternalFormat = GL_RGBA16_SNORM;
423 rb->AllocStorage = soft_renderbuffer_storage;
424 _mesa_attach_and_own_rb(fb, BUFFER_ACCUM, rb);
425
426 return GL_TRUE;
427 }
428
429
430
431 /**
432 * Create/attach software-based renderbuffers to the given framebuffer.
433 * This is a helper routine for device drivers. Drivers can just as well
434 * call the individual _mesa_add_*_renderbuffer() routines directly.
435 */
436 void
_swrast_add_soft_renderbuffers(struct gl_framebuffer * fb,GLboolean color,GLboolean depth,GLboolean stencil,GLboolean accum,GLboolean alpha)437 _swrast_add_soft_renderbuffers(struct gl_framebuffer *fb,
438 GLboolean color,
439 GLboolean depth,
440 GLboolean stencil,
441 GLboolean accum,
442 GLboolean alpha)
443 {
444 GLboolean frontLeft = GL_TRUE;
445 GLboolean backLeft = fb->Visual.doubleBufferMode;
446 GLboolean frontRight = fb->Visual.stereoMode;
447 GLboolean backRight = fb->Visual.stereoMode && fb->Visual.doubleBufferMode;
448
449 if (color) {
450 assert(fb->Visual.redBits == fb->Visual.greenBits);
451 assert(fb->Visual.redBits == fb->Visual.blueBits);
452 add_color_renderbuffers(NULL, fb,
453 fb->Visual.redBits,
454 fb->Visual.alphaBits,
455 frontLeft, backLeft,
456 frontRight, backRight);
457 }
458
459 #if 0
460 /* This is pretty much for debugging purposes only since there's a perf
461 * hit for using combined depth/stencil in swrast.
462 */
463 if (depth && fb->Visual.depthBits == 24 &&
464 stencil && fb->Visual.stencilBits == 8) {
465 /* use combined depth/stencil buffer */
466 add_depth_stencil_renderbuffer(NULL, fb);
467 }
468 else
469 #else
470 (void) add_depth_stencil_renderbuffer;
471 #endif
472 {
473 if (depth) {
474 assert(fb->Visual.depthBits > 0);
475 add_depth_renderbuffer(NULL, fb, fb->Visual.depthBits);
476 }
477
478 if (stencil) {
479 assert(fb->Visual.stencilBits > 0);
480 add_stencil_renderbuffer(NULL, fb, fb->Visual.stencilBits);
481 }
482 }
483
484 if (accum) {
485 assert(fb->Visual.accumRedBits > 0);
486 assert(fb->Visual.accumGreenBits > 0);
487 assert(fb->Visual.accumBlueBits > 0);
488 add_accum_renderbuffer(NULL, fb,
489 fb->Visual.accumRedBits,
490 fb->Visual.accumGreenBits,
491 fb->Visual.accumBlueBits,
492 fb->Visual.accumAlphaBits);
493 }
494 }
495
496
497
498 static void
map_attachment(struct gl_context * ctx,struct gl_framebuffer * fb,gl_buffer_index buffer)499 map_attachment(struct gl_context *ctx,
500 struct gl_framebuffer *fb,
501 gl_buffer_index buffer)
502 {
503 struct gl_texture_object *texObj = fb->Attachment[buffer].Texture;
504 struct gl_renderbuffer *rb = fb->Attachment[buffer].Renderbuffer;
505 struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
506
507 if (texObj) {
508 /* map texture image (render to texture) */
509 const GLuint level = fb->Attachment[buffer].TextureLevel;
510 const GLuint face = fb->Attachment[buffer].CubeMapFace;
511 const GLuint slice = fb->Attachment[buffer].Zoffset;
512 struct gl_texture_image *texImage = texObj->Image[face][level];
513 if (texImage) {
514 ctx->Driver.MapTextureImage(ctx, texImage, slice,
515 0, 0, texImage->Width, texImage->Height,
516 GL_MAP_READ_BIT | GL_MAP_WRITE_BIT,
517 &srb->Map, &srb->RowStride);
518 }
519 }
520 else if (rb) {
521 /* Map ordinary renderbuffer */
522 ctx->Driver.MapRenderbuffer(ctx, rb,
523 0, 0, rb->Width, rb->Height,
524 GL_MAP_READ_BIT | GL_MAP_WRITE_BIT,
525 &srb->Map, &srb->RowStride,
526 fb->FlipY);
527 }
528
529 assert(srb->Map);
530 }
531
532
533 static void
unmap_attachment(struct gl_context * ctx,struct gl_framebuffer * fb,gl_buffer_index buffer)534 unmap_attachment(struct gl_context *ctx,
535 struct gl_framebuffer *fb,
536 gl_buffer_index buffer)
537 {
538 struct gl_texture_object *texObj = fb->Attachment[buffer].Texture;
539 struct gl_renderbuffer *rb = fb->Attachment[buffer].Renderbuffer;
540 struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
541
542 if (texObj) {
543 /* unmap texture image (render to texture) */
544 const GLuint level = fb->Attachment[buffer].TextureLevel;
545 const GLuint face = fb->Attachment[buffer].CubeMapFace;
546 const GLuint slice = fb->Attachment[buffer].Zoffset;
547 struct gl_texture_image *texImage = texObj->Image[face][level];
548 if (texImage) {
549 ctx->Driver.UnmapTextureImage(ctx, texImage, slice);
550 }
551 }
552 else if (rb) {
553 /* unmap ordinary renderbuffer */
554 ctx->Driver.UnmapRenderbuffer(ctx, rb);
555 }
556
557 srb->Map = NULL;
558 }
559
560
561 /**
562 * Determine what type to use (ubyte vs. float) for span colors for the
563 * given renderbuffer.
564 * See also _swrast_write_rgba_span().
565 */
566 static void
find_renderbuffer_colortype(struct gl_renderbuffer * rb)567 find_renderbuffer_colortype(struct gl_renderbuffer *rb)
568 {
569 struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
570 GLuint rbMaxBits = _mesa_get_format_max_bits(rb->Format);
571 GLenum rbDatatype = _mesa_get_format_datatype(rb->Format);
572
573 if (rbDatatype == GL_UNSIGNED_NORMALIZED && rbMaxBits <= 8) {
574 /* the buffer's values fit in GLubyte values */
575 srb->ColorType = GL_UNSIGNED_BYTE;
576 }
577 else {
578 /* use floats otherwise */
579 srb->ColorType = GL_FLOAT;
580 }
581 }
582
583
584 /**
585 * Map the renderbuffers we'll use for tri/line/point rendering.
586 */
587 void
_swrast_map_renderbuffers(struct gl_context * ctx)588 _swrast_map_renderbuffers(struct gl_context *ctx)
589 {
590 struct gl_framebuffer *fb = ctx->DrawBuffer;
591 struct gl_renderbuffer *depthRb, *stencilRb;
592 GLuint buf;
593
594 depthRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
595 if (depthRb) {
596 /* map depth buffer */
597 map_attachment(ctx, fb, BUFFER_DEPTH);
598 }
599
600 stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
601 if (stencilRb && stencilRb != depthRb) {
602 /* map stencil buffer */
603 map_attachment(ctx, fb, BUFFER_STENCIL);
604 }
605
606 for (buf = 0; buf < fb->_NumColorDrawBuffers; buf++) {
607 if (fb->_ColorDrawBufferIndexes[buf] != BUFFER_NONE) {
608 map_attachment(ctx, fb, fb->_ColorDrawBufferIndexes[buf]);
609 find_renderbuffer_colortype(fb->_ColorDrawBuffers[buf]);
610 }
611 }
612 }
613
614
615 /**
616 * Unmap renderbuffers after rendering.
617 */
618 void
_swrast_unmap_renderbuffers(struct gl_context * ctx)619 _swrast_unmap_renderbuffers(struct gl_context *ctx)
620 {
621 struct gl_framebuffer *fb = ctx->DrawBuffer;
622 struct gl_renderbuffer *depthRb, *stencilRb;
623 GLuint buf;
624
625 depthRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
626 if (depthRb) {
627 /* map depth buffer */
628 unmap_attachment(ctx, fb, BUFFER_DEPTH);
629 }
630
631 stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
632 if (stencilRb && stencilRb != depthRb) {
633 /* map stencil buffer */
634 unmap_attachment(ctx, fb, BUFFER_STENCIL);
635 }
636
637 for (buf = 0; buf < fb->_NumColorDrawBuffers; buf++) {
638 if (fb->_ColorDrawBufferIndexes[buf] != BUFFER_NONE) {
639 unmap_attachment(ctx, fb, fb->_ColorDrawBufferIndexes[buf]);
640 }
641 }
642 }
643