2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
27 * Functions for allocating/managing renderbuffers.
28 * Also, routines for reading/writing software-based renderbuffer data as
29 * ubytes, ushorts, uints, etc.
31 * The 'alpha8' renderbuffer is interesting. It's used to add a software-based
32 * alpha channel to RGB renderbuffers. This is done by wrapping the RGB
33 * renderbuffer with the alpha renderbuffer. We can do this because of the
34 * OO-nature of renderbuffers.
36 * Down the road we'll use this for run-time support of 8, 16 and 32-bit
37 * color channels. For example, Mesa may use 32-bit/float color channels
38 * internally (swrast) and use wrapper renderbuffers to convert 32-bit
39 * values down to 16 or 8-bit values for whatever kind of framebuffer we have.
50 #include "renderbuffer.h"
52 #include "rbadaptors.h"
55 /* 32-bit color index format. Not a public format. */
56 #define COLOR_INDEX32 0x424243
60 * Routines for get/put values in common buffer formats follow.
61 * Someday add support for arbitrary row stride to make them more
65 /**********************************************************************
66 * Functions for buffers of 1 X GLubyte values.
71 get_pointer_ubyte(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
76 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
77 /* Can't assert rb->Format since these funcs may be used for serveral
78 * different formats (GL_ALPHA8, GL_STENCIL_INDEX8, etc).
80 return (GLubyte
*) rb
->Data
+ y
* rb
->Width
+ x
;
85 get_row_ubyte(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
86 GLint x
, GLint y
, void *values
)
88 const GLubyte
*src
= (const GLubyte
*) rb
->Data
+ y
* rb
->Width
+ x
;
89 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
90 _mesa_memcpy(values
, src
, count
* sizeof(GLubyte
));
95 get_values_ubyte(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
96 const GLint x
[], const GLint y
[], void *values
)
98 GLubyte
*dst
= (GLubyte
*) values
;
100 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
101 for (i
= 0; i
< count
; i
++) {
102 const GLubyte
*src
= (GLubyte
*) rb
->Data
+ y
[i
] * rb
->Width
+ x
[i
];
109 put_row_ubyte(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
110 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
112 const GLubyte
*src
= (const GLubyte
*) values
;
113 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ y
* rb
->Width
+ x
;
114 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
117 for (i
= 0; i
< count
; i
++) {
124 _mesa_memcpy(dst
, values
, count
* sizeof(GLubyte
));
130 put_mono_row_ubyte(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
131 GLint x
, GLint y
, const void *value
, const GLubyte
*mask
)
133 const GLubyte val
= *((const GLubyte
*) value
);
134 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ y
* rb
->Width
+ x
;
135 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
138 for (i
= 0; i
< count
; i
++) {
146 for (i
= 0; i
< count
; i
++) {
154 put_values_ubyte(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
155 const GLint x
[], const GLint y
[],
156 const void *values
, const GLubyte
*mask
)
158 const GLubyte
*src
= (const GLubyte
*) values
;
160 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
161 for (i
= 0; i
< count
; i
++) {
162 if (!mask
|| mask
[i
]) {
163 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ y
[i
] * rb
->Width
+ x
[i
];
171 put_mono_values_ubyte(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
172 const GLint x
[], const GLint y
[],
173 const void *value
, const GLubyte
*mask
)
175 const GLubyte val
= *((const GLubyte
*) value
);
177 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
178 for (i
= 0; i
< count
; i
++) {
179 if (!mask
|| mask
[i
]) {
180 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ y
[i
] * rb
->Width
+ x
[i
];
187 /**********************************************************************
188 * Functions for buffers of 1 X GLushort values.
193 get_pointer_ushort(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
198 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
);
199 ASSERT(rb
->Width
> 0);
200 return (GLushort
*) rb
->Data
+ y
* rb
->Width
+ x
;
205 get_row_ushort(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
206 GLint x
, GLint y
, void *values
)
208 const void *src
= rb
->GetPointer(ctx
, rb
, x
, y
);
209 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
);
210 _mesa_memcpy(values
, src
, count
* sizeof(GLushort
));
215 get_values_ushort(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
216 const GLint x
[], const GLint y
[], void *values
)
218 GLushort
*dst
= (GLushort
*) values
;
220 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
);
221 for (i
= 0; i
< count
; i
++) {
222 const GLushort
*src
= (GLushort
*) rb
->Data
+ y
[i
] * rb
->Width
+ x
[i
];
229 put_row_ushort(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
230 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
232 const GLushort
*src
= (const GLushort
*) values
;
233 GLushort
*dst
= (GLushort
*) rb
->Data
+ y
* rb
->Width
+ x
;
234 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
);
237 for (i
= 0; i
< count
; i
++) {
244 _mesa_memcpy(dst
, src
, count
* sizeof(GLushort
));
250 put_mono_row_ushort(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
251 GLint x
, GLint y
, const void *value
, const GLubyte
*mask
)
253 const GLushort val
= *((const GLushort
*) value
);
254 GLushort
*dst
= (GLushort
*) rb
->Data
+ y
* rb
->Width
+ x
;
255 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
);
258 for (i
= 0; i
< count
; i
++) {
266 for (i
= 0; i
< count
; i
++) {
274 put_values_ushort(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
275 const GLint x
[], const GLint y
[], const void *values
,
278 const GLushort
*src
= (const GLushort
*) values
;
280 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
);
281 for (i
= 0; i
< count
; i
++) {
282 if (!mask
|| mask
[i
]) {
283 GLushort
*dst
= (GLushort
*) rb
->Data
+ y
[i
] * rb
->Width
+ x
[i
];
291 put_mono_values_ushort(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
292 GLuint count
, const GLint x
[], const GLint y
[],
293 const void *value
, const GLubyte
*mask
)
295 const GLushort val
= *((const GLushort
*) value
);
296 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
);
299 for (i
= 0; i
< count
; i
++) {
301 GLushort
*dst
= (GLushort
*) rb
->Data
+ y
[i
] * rb
->Width
+ x
[i
];
308 for (i
= 0; i
< count
; i
++) {
309 GLushort
*dst
= (GLushort
*) rb
->Data
+ y
[i
] * rb
->Width
+ x
[i
];
316 /**********************************************************************
317 * Functions for buffers of 1 X GLuint values.
318 * Typically depth/Z or color index.
322 get_pointer_uint(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
327 ASSERT(rb
->DataType
== GL_UNSIGNED_INT
||
328 rb
->DataType
== GL_UNSIGNED_INT_24_8_EXT
);
329 return (GLuint
*) rb
->Data
+ y
* rb
->Width
+ x
;
334 get_row_uint(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
335 GLint x
, GLint y
, void *values
)
337 const void *src
= rb
->GetPointer(ctx
, rb
, x
, y
);
338 ASSERT(rb
->DataType
== GL_UNSIGNED_INT
||
339 rb
->DataType
== GL_UNSIGNED_INT_24_8_EXT
);
340 _mesa_memcpy(values
, src
, count
* sizeof(GLuint
));
345 get_values_uint(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
346 const GLint x
[], const GLint y
[], void *values
)
348 GLuint
*dst
= (GLuint
*) values
;
350 ASSERT(rb
->DataType
== GL_UNSIGNED_INT
||
351 rb
->DataType
== GL_UNSIGNED_INT_24_8_EXT
);
352 for (i
= 0; i
< count
; i
++) {
353 const GLuint
*src
= (GLuint
*) rb
->Data
+ y
[i
] * rb
->Width
+ x
[i
];
360 put_row_uint(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
361 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
363 const GLuint
*src
= (const GLuint
*) values
;
364 GLuint
*dst
= (GLuint
*) rb
->Data
+ y
* rb
->Width
+ x
;
365 ASSERT(rb
->DataType
== GL_UNSIGNED_INT
||
366 rb
->DataType
== GL_UNSIGNED_INT_24_8_EXT
);
369 for (i
= 0; i
< count
; i
++) {
376 _mesa_memcpy(dst
, src
, count
* sizeof(GLuint
));
382 put_mono_row_uint(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
383 GLint x
, GLint y
, const void *value
, const GLubyte
*mask
)
385 const GLuint val
= *((const GLuint
*) value
);
386 GLuint
*dst
= (GLuint
*) rb
->Data
+ y
* rb
->Width
+ x
;
387 ASSERT(rb
->DataType
== GL_UNSIGNED_INT
||
388 rb
->DataType
== GL_UNSIGNED_INT_24_8_EXT
);
391 for (i
= 0; i
< count
; i
++) {
399 for (i
= 0; i
< count
; i
++) {
407 put_values_uint(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
408 const GLint x
[], const GLint y
[], const void *values
,
411 const GLuint
*src
= (const GLuint
*) values
;
413 ASSERT(rb
->DataType
== GL_UNSIGNED_INT
||
414 rb
->DataType
== GL_UNSIGNED_INT_24_8_EXT
);
415 for (i
= 0; i
< count
; i
++) {
416 if (!mask
|| mask
[i
]) {
417 GLuint
*dst
= (GLuint
*) rb
->Data
+ y
[i
] * rb
->Width
+ x
[i
];
425 put_mono_values_uint(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
426 const GLint x
[], const GLint y
[], const void *value
,
429 const GLuint val
= *((const GLuint
*) value
);
431 ASSERT(rb
->DataType
== GL_UNSIGNED_INT
||
432 rb
->DataType
== GL_UNSIGNED_INT_24_8_EXT
);
433 for (i
= 0; i
< count
; i
++) {
434 if (!mask
|| mask
[i
]) {
435 GLuint
*dst
= (GLuint
*) rb
->Data
+ y
[i
] * rb
->Width
+ x
[i
];
442 /**********************************************************************
443 * Functions for buffers of 3 X GLubyte (or GLbyte) values.
444 * Typically color buffers.
445 * NOTE: the incoming and outgoing colors are RGBA! We ignore incoming
446 * alpha values and return 255 for outgoing alpha values.
450 get_pointer_ubyte3(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
453 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
454 /* No direct access since this buffer is RGB but caller will be
455 * treating it as if it were RGBA.
462 get_row_ubyte3(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
463 GLint x
, GLint y
, void *values
)
465 const GLubyte
*src
= (const GLubyte
*) rb
->Data
+ 3 * (y
* rb
->Width
+ x
);
466 GLubyte
*dst
= (GLubyte
*) values
;
468 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
469 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
470 for (i
= 0; i
< count
; i
++) {
471 dst
[i
* 4 + 0] = src
[i
* 3 + 0];
472 dst
[i
* 4 + 1] = src
[i
* 3 + 1];
473 dst
[i
* 4 + 2] = src
[i
* 3 + 2];
474 dst
[i
* 4 + 3] = 255;
480 get_values_ubyte3(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
481 const GLint x
[], const GLint y
[], void *values
)
483 GLubyte
*dst
= (GLubyte
*) values
;
485 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
486 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
487 for (i
= 0; i
< count
; i
++) {
489 = (GLubyte
*) rb
->Data
+ 3 * (y
[i
] * rb
->Width
+ x
[i
]);
490 dst
[i
* 4 + 0] = src
[0];
491 dst
[i
* 4 + 1] = src
[1];
492 dst
[i
* 4 + 2] = src
[2];
493 dst
[i
* 4 + 3] = 255;
499 put_row_ubyte3(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
500 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
502 /* note: incoming values are RGB+A! */
503 const GLubyte
*src
= (const GLubyte
*) values
;
504 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ 3 * (y
* rb
->Width
+ x
);
506 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
507 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
508 for (i
= 0; i
< count
; i
++) {
509 if (!mask
|| mask
[i
]) {
510 dst
[i
* 3 + 0] = src
[i
* 4 + 0];
511 dst
[i
* 3 + 1] = src
[i
* 4 + 1];
512 dst
[i
* 3 + 2] = src
[i
* 4 + 2];
519 put_row_rgb_ubyte3(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
520 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
522 /* note: incoming values are RGB+A! */
523 const GLubyte
*src
= (const GLubyte
*) values
;
524 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ 3 * (y
* rb
->Width
+ x
);
526 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
527 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
528 for (i
= 0; i
< count
; i
++) {
529 if (!mask
|| mask
[i
]) {
530 dst
[i
* 3 + 0] = src
[i
* 3 + 0];
531 dst
[i
* 3 + 1] = src
[i
* 3 + 1];
532 dst
[i
* 3 + 2] = src
[i
* 3 + 2];
539 put_mono_row_ubyte3(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
540 GLint x
, GLint y
, const void *value
, const GLubyte
*mask
)
542 /* note: incoming value is RGB+A! */
543 const GLubyte val0
= ((const GLubyte
*) value
)[0];
544 const GLubyte val1
= ((const GLubyte
*) value
)[1];
545 const GLubyte val2
= ((const GLubyte
*) value
)[2];
546 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ 3 * (y
* rb
->Width
+ x
);
547 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
548 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
549 if (!mask
&& val0
== val1
&& val1
== val2
) {
551 _mesa_memset(dst
, val0
, 3 * count
);
555 for (i
= 0; i
< count
; i
++) {
556 if (!mask
|| mask
[i
]) {
557 dst
[i
* 3 + 0] = val0
;
558 dst
[i
* 3 + 1] = val1
;
559 dst
[i
* 3 + 2] = val2
;
567 put_values_ubyte3(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
568 const GLint x
[], const GLint y
[], const void *values
,
571 /* note: incoming values are RGB+A! */
572 const GLubyte
*src
= (const GLubyte
*) values
;
574 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
575 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
576 for (i
= 0; i
< count
; i
++) {
577 if (!mask
|| mask
[i
]) {
578 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ 3 * (y
[i
] * rb
->Width
+ x
[i
]);
579 dst
[0] = src
[i
* 4 + 0];
580 dst
[1] = src
[i
* 4 + 1];
581 dst
[2] = src
[i
* 4 + 2];
588 put_mono_values_ubyte3(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
589 GLuint count
, const GLint x
[], const GLint y
[],
590 const void *value
, const GLubyte
*mask
)
592 /* note: incoming value is RGB+A! */
593 const GLubyte val0
= ((const GLubyte
*) value
)[0];
594 const GLubyte val1
= ((const GLubyte
*) value
)[1];
595 const GLubyte val2
= ((const GLubyte
*) value
)[2];
597 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
598 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
599 for (i
= 0; i
< count
; i
++) {
600 if (!mask
|| mask
[i
]) {
601 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ 3 * (y
[i
] * rb
->Width
+ x
[i
]);
610 /**********************************************************************
611 * Functions for buffers of 4 X GLubyte (or GLbyte) values.
612 * Typically color buffers.
616 get_pointer_ubyte4(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
621 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
622 ASSERT(rb
->Format
== MESA_FORMAT_RGBA8888
);
623 return (GLubyte
*) rb
->Data
+ 4 * (y
* rb
->Width
+ x
);
628 get_row_ubyte4(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
629 GLint x
, GLint y
, void *values
)
631 const GLubyte
*src
= (const GLubyte
*) rb
->Data
+ 4 * (y
* rb
->Width
+ x
);
632 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
633 ASSERT(rb
->Format
== MESA_FORMAT_RGBA8888
);
634 _mesa_memcpy(values
, src
, 4 * count
* sizeof(GLubyte
));
639 get_values_ubyte4(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
640 const GLint x
[], const GLint y
[], void *values
)
642 /* treat 4*GLubyte as 1*GLuint */
643 GLuint
*dst
= (GLuint
*) values
;
645 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
646 ASSERT(rb
->Format
== MESA_FORMAT_RGBA8888
);
647 for (i
= 0; i
< count
; i
++) {
648 const GLuint
*src
= (GLuint
*) rb
->Data
+ (y
[i
] * rb
->Width
+ x
[i
]);
655 put_row_ubyte4(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
656 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
658 /* treat 4*GLubyte as 1*GLuint */
659 const GLuint
*src
= (const GLuint
*) values
;
660 GLuint
*dst
= (GLuint
*) rb
->Data
+ (y
* rb
->Width
+ x
);
661 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
662 ASSERT(rb
->Format
== MESA_FORMAT_RGBA8888
);
665 for (i
= 0; i
< count
; i
++) {
672 _mesa_memcpy(dst
, src
, 4 * count
* sizeof(GLubyte
));
678 put_row_rgb_ubyte4(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
679 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
681 /* Store RGB values in RGBA buffer */
682 const GLubyte
*src
= (const GLubyte
*) values
;
683 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ 4 * (y
* rb
->Width
+ x
);
685 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
686 ASSERT(rb
->Format
== MESA_FORMAT_RGBA8888
);
687 for (i
= 0; i
< count
; i
++) {
688 if (!mask
|| mask
[i
]) {
689 dst
[i
* 4 + 0] = src
[i
* 3 + 0];
690 dst
[i
* 4 + 1] = src
[i
* 3 + 1];
691 dst
[i
* 4 + 2] = src
[i
* 3 + 2];
692 dst
[i
* 4 + 3] = 0xff;
699 put_mono_row_ubyte4(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
700 GLint x
, GLint y
, const void *value
, const GLubyte
*mask
)
702 /* treat 4*GLubyte as 1*GLuint */
703 const GLuint val
= *((const GLuint
*) value
);
704 GLuint
*dst
= (GLuint
*) rb
->Data
+ (y
* rb
->Width
+ x
);
705 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
706 ASSERT(rb
->Format
== MESA_FORMAT_RGBA8888
);
707 if (!mask
&& val
== 0) {
709 _mesa_bzero(dst
, count
* 4 * sizeof(GLubyte
));
715 for (i
= 0; i
< count
; i
++) {
723 for (i
= 0; i
< count
; i
++) {
732 put_values_ubyte4(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
733 const GLint x
[], const GLint y
[], const void *values
,
736 /* treat 4*GLubyte as 1*GLuint */
737 const GLuint
*src
= (const GLuint
*) values
;
739 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
740 ASSERT(rb
->Format
== MESA_FORMAT_RGBA8888
);
741 for (i
= 0; i
< count
; i
++) {
742 if (!mask
|| mask
[i
]) {
743 GLuint
*dst
= (GLuint
*) rb
->Data
+ (y
[i
] * rb
->Width
+ x
[i
]);
751 put_mono_values_ubyte4(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
752 GLuint count
, const GLint x
[], const GLint y
[],
753 const void *value
, const GLubyte
*mask
)
755 /* treat 4*GLubyte as 1*GLuint */
756 const GLuint val
= *((const GLuint
*) value
);
758 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
759 ASSERT(rb
->Format
== MESA_FORMAT_RGBA8888
);
760 for (i
= 0; i
< count
; i
++) {
761 if (!mask
|| mask
[i
]) {
762 GLuint
*dst
= (GLuint
*) rb
->Data
+ (y
[i
] * rb
->Width
+ x
[i
]);
769 /**********************************************************************
770 * Functions for buffers of 4 X GLushort (or GLshort) values.
771 * Typically accum buffer.
775 get_pointer_ushort4(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
780 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
|| rb
->DataType
== GL_SHORT
);
781 return (GLushort
*) rb
->Data
+ 4 * (y
* rb
->Width
+ x
);
786 get_row_ushort4(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
787 GLint x
, GLint y
, void *values
)
789 const GLshort
*src
= (const GLshort
*) rb
->Data
+ 4 * (y
* rb
->Width
+ x
);
790 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
|| rb
->DataType
== GL_SHORT
);
791 _mesa_memcpy(values
, src
, 4 * count
* sizeof(GLshort
));
796 get_values_ushort4(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
797 const GLint x
[], const GLint y
[], void *values
)
799 GLushort
*dst
= (GLushort
*) values
;
801 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
|| rb
->DataType
== GL_SHORT
);
802 for (i
= 0; i
< count
; i
++) {
804 = (GLushort
*) rb
->Data
+ 4 * (y
[i
] * rb
->Width
+ x
[i
]);
811 put_row_ushort4(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
812 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
814 const GLushort
*src
= (const GLushort
*) values
;
815 GLushort
*dst
= (GLushort
*) rb
->Data
+ 4 * (y
* rb
->Width
+ x
);
816 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
|| rb
->DataType
== GL_SHORT
);
819 for (i
= 0; i
< count
; i
++) {
821 dst
[i
* 4 + 0] = src
[i
* 4 + 0];
822 dst
[i
* 4 + 1] = src
[i
* 4 + 1];
823 dst
[i
* 4 + 2] = src
[i
* 4 + 2];
824 dst
[i
* 4 + 3] = src
[i
* 4 + 3];
829 _mesa_memcpy(dst
, src
, 4 * count
* sizeof(GLushort
));
835 put_row_rgb_ushort4(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
836 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
838 /* Put RGB values in RGBA buffer */
839 const GLushort
*src
= (const GLushort
*) values
;
840 GLushort
*dst
= (GLushort
*) rb
->Data
+ 4 * (y
* rb
->Width
+ x
);
841 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
|| rb
->DataType
== GL_SHORT
);
844 for (i
= 0; i
< count
; i
++) {
846 dst
[i
* 4 + 0] = src
[i
* 3 + 0];
847 dst
[i
* 4 + 1] = src
[i
* 3 + 1];
848 dst
[i
* 4 + 2] = src
[i
* 3 + 2];
849 dst
[i
* 4 + 3] = 0xffff;
854 _mesa_memcpy(dst
, src
, 4 * count
* sizeof(GLushort
));
860 put_mono_row_ushort4(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
861 GLint x
, GLint y
, const void *value
, const GLubyte
*mask
)
863 const GLushort val0
= ((const GLushort
*) value
)[0];
864 const GLushort val1
= ((const GLushort
*) value
)[1];
865 const GLushort val2
= ((const GLushort
*) value
)[2];
866 const GLushort val3
= ((const GLushort
*) value
)[3];
867 GLushort
*dst
= (GLushort
*) rb
->Data
+ 4 * (y
* rb
->Width
+ x
);
868 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
|| rb
->DataType
== GL_SHORT
);
869 if (!mask
&& val0
== 0 && val1
== 0 && val2
== 0 && val3
== 0) {
870 /* common case for clearing accum buffer */
871 _mesa_bzero(dst
, count
* 4 * sizeof(GLushort
));
875 for (i
= 0; i
< count
; i
++) {
876 if (!mask
|| mask
[i
]) {
877 dst
[i
* 4 + 0] = val0
;
878 dst
[i
* 4 + 1] = val1
;
879 dst
[i
* 4 + 2] = val2
;
880 dst
[i
* 4 + 3] = val3
;
888 put_values_ushort4(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
889 const GLint x
[], const GLint y
[], const void *values
,
892 const GLushort
*src
= (const GLushort
*) values
;
894 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
|| rb
->DataType
== GL_SHORT
);
895 for (i
= 0; i
< count
; i
++) {
896 if (!mask
|| mask
[i
]) {
897 GLushort
*dst
= (GLushort
*) rb
->Data
+ 4 * (y
[i
] * rb
->Width
+ x
[i
]);
898 dst
[0] = src
[i
* 4 + 0];
899 dst
[1] = src
[i
* 4 + 1];
900 dst
[2] = src
[i
* 4 + 2];
901 dst
[3] = src
[i
* 4 + 3];
908 put_mono_values_ushort4(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
909 GLuint count
, const GLint x
[], const GLint y
[],
910 const void *value
, const GLubyte
*mask
)
912 const GLushort val0
= ((const GLushort
*) value
)[0];
913 const GLushort val1
= ((const GLushort
*) value
)[1];
914 const GLushort val2
= ((const GLushort
*) value
)[2];
915 const GLushort val3
= ((const GLushort
*) value
)[3];
917 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
|| rb
->DataType
== GL_SHORT
);
918 for (i
= 0; i
< count
; i
++) {
919 if (!mask
|| mask
[i
]) {
920 GLushort
*dst
= (GLushort
*) rb
->Data
+ 4 * (y
[i
] * rb
->Width
+ x
[i
]);
932 * This is a software fallback for the gl_renderbuffer->AllocStorage
934 * Device drivers will typically override this function for the buffers
935 * which it manages (typically color buffers, Z and stencil).
936 * Other buffers (like software accumulation and aux buffers) which the driver
937 * doesn't manage can be handled with this function.
939 * This one multi-purpose function can allocate stencil, depth, accum, color
940 * or color-index buffers!
942 * This function also plugs in the appropriate GetPointer, Get/PutRow and
943 * Get/PutValues functions.
946 _mesa_soft_renderbuffer_storage(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
947 GLenum internalFormat
,
948 GLuint width
, GLuint height
)
952 switch (internalFormat
) {
961 rb
->Format
= MESA_FORMAT_RGB888
;
962 rb
->DataType
= GL_UNSIGNED_BYTE
;
963 rb
->GetPointer
= get_pointer_ubyte3
;
964 rb
->GetRow
= get_row_ubyte3
;
965 rb
->GetValues
= get_values_ubyte3
;
966 rb
->PutRow
= put_row_ubyte3
;
967 rb
->PutRowRGB
= put_row_rgb_ubyte3
;
968 rb
->PutMonoRow
= put_mono_row_ubyte3
;
969 rb
->PutValues
= put_values_ubyte3
;
970 rb
->PutMonoValues
= put_mono_values_ubyte3
;
971 pixelSize
= 3 * sizeof(GLubyte
);
982 rb
->Format
= MESA_FORMAT_RGBA8888
;
983 rb
->DataType
= GL_UNSIGNED_BYTE
;
984 rb
->GetPointer
= get_pointer_ubyte4
;
985 rb
->GetRow
= get_row_ubyte4
;
986 rb
->GetValues
= get_values_ubyte4
;
987 rb
->PutRow
= put_row_ubyte4
;
988 rb
->PutRowRGB
= put_row_rgb_ubyte4
;
989 rb
->PutMonoRow
= put_mono_row_ubyte4
;
990 rb
->PutValues
= put_values_ubyte4
;
991 rb
->PutMonoValues
= put_mono_values_ubyte4
;
992 pixelSize
= 4 * sizeof(GLubyte
);
995 /* for accum buffer */
996 rb
->Format
= MESA_FORMAT_SIGNED_RGBA_16
;
997 rb
->DataType
= GL_SHORT
;
998 rb
->GetPointer
= get_pointer_ushort4
;
999 rb
->GetRow
= get_row_ushort4
;
1000 rb
->GetValues
= get_values_ushort4
;
1001 rb
->PutRow
= put_row_ushort4
;
1002 rb
->PutRowRGB
= put_row_rgb_ushort4
;
1003 rb
->PutMonoRow
= put_mono_row_ushort4
;
1004 rb
->PutValues
= put_values_ushort4
;
1005 rb
->PutMonoValues
= put_mono_values_ushort4
;
1006 pixelSize
= 4 * sizeof(GLushort
);
1010 rb
->Format
= MESA_FORMAT_A8
;
1011 rb
->DataType
= GL_UNSIGNED_BYTE
;
1012 rb
->GetPointer
= get_pointer_alpha8
;
1013 rb
->GetRow
= get_row_alpha8
;
1014 rb
->GetValues
= get_values_alpha8
;
1015 rb
->PutRow
= put_row_alpha8
;
1016 rb
->PutRowRGB
= NULL
;
1017 rb
->PutMonoRow
= put_mono_row_alpha8
;
1018 rb
->PutValues
= put_values_alpha8
;
1019 rb
->PutMonoValues
= put_mono_values_alpha8
;
1020 pixelSize
= sizeof(GLubyte
);
1023 case GL_STENCIL_INDEX
:
1024 case GL_STENCIL_INDEX1_EXT
:
1025 case GL_STENCIL_INDEX4_EXT
:
1026 case GL_STENCIL_INDEX8_EXT
:
1027 case GL_STENCIL_INDEX16_EXT
:
1028 rb
->Format
= MESA_FORMAT_S8
;
1029 rb
->DataType
= GL_UNSIGNED_BYTE
;
1030 rb
->GetPointer
= get_pointer_ubyte
;
1031 rb
->GetRow
= get_row_ubyte
;
1032 rb
->GetValues
= get_values_ubyte
;
1033 rb
->PutRow
= put_row_ubyte
;
1034 rb
->PutRowRGB
= NULL
;
1035 rb
->PutMonoRow
= put_mono_row_ubyte
;
1036 rb
->PutValues
= put_values_ubyte
;
1037 rb
->PutMonoValues
= put_mono_values_ubyte
;
1038 pixelSize
= sizeof(GLubyte
);
1040 case GL_DEPTH_COMPONENT
:
1041 case GL_DEPTH_COMPONENT16
:
1042 rb
->Format
= MESA_FORMAT_Z16
;
1043 rb
->DataType
= GL_UNSIGNED_SHORT
;
1044 rb
->GetPointer
= get_pointer_ushort
;
1045 rb
->GetRow
= get_row_ushort
;
1046 rb
->GetValues
= get_values_ushort
;
1047 rb
->PutRow
= put_row_ushort
;
1048 rb
->PutRowRGB
= NULL
;
1049 rb
->PutMonoRow
= put_mono_row_ushort
;
1050 rb
->PutValues
= put_values_ushort
;
1051 rb
->PutMonoValues
= put_mono_values_ushort
;
1052 pixelSize
= sizeof(GLushort
);
1054 case GL_DEPTH_COMPONENT24
:
1055 rb
->DataType
= GL_UNSIGNED_INT
;
1056 rb
->GetPointer
= get_pointer_uint
;
1057 rb
->GetRow
= get_row_uint
;
1058 rb
->GetValues
= get_values_uint
;
1059 rb
->PutRow
= put_row_uint
;
1060 rb
->PutRowRGB
= NULL
;
1061 rb
->PutMonoRow
= put_mono_row_uint
;
1062 rb
->PutValues
= put_values_uint
;
1063 rb
->PutMonoValues
= put_mono_values_uint
;
1064 rb
->Format
= MESA_FORMAT_X8_Z24
;
1065 pixelSize
= sizeof(GLuint
);
1067 case GL_DEPTH_COMPONENT32
:
1068 rb
->DataType
= GL_UNSIGNED_INT
;
1069 rb
->GetPointer
= get_pointer_uint
;
1070 rb
->GetRow
= get_row_uint
;
1071 rb
->GetValues
= get_values_uint
;
1072 rb
->PutRow
= put_row_uint
;
1073 rb
->PutRowRGB
= NULL
;
1074 rb
->PutMonoRow
= put_mono_row_uint
;
1075 rb
->PutValues
= put_values_uint
;
1076 rb
->PutMonoValues
= put_mono_values_uint
;
1077 rb
->Format
= MESA_FORMAT_Z32
;
1078 pixelSize
= sizeof(GLuint
);
1080 case GL_DEPTH_STENCIL_EXT
:
1081 case GL_DEPTH24_STENCIL8_EXT
:
1082 rb
->Format
= MESA_FORMAT_Z24_S8
;
1083 rb
->DataType
= GL_UNSIGNED_INT_24_8_EXT
;
1084 rb
->GetPointer
= get_pointer_uint
;
1085 rb
->GetRow
= get_row_uint
;
1086 rb
->GetValues
= get_values_uint
;
1087 rb
->PutRow
= put_row_uint
;
1088 rb
->PutRowRGB
= NULL
;
1089 rb
->PutMonoRow
= put_mono_row_uint
;
1090 rb
->PutValues
= put_values_uint
;
1091 rb
->PutMonoValues
= put_mono_values_uint
;
1092 pixelSize
= sizeof(GLuint
);
1094 case GL_COLOR_INDEX8_EXT
:
1095 case GL_COLOR_INDEX16_EXT
:
1097 rb
->Format
= MESA_FORMAT_CI8
;
1098 rb
->DataType
= GL_UNSIGNED_BYTE
;
1099 rb
->GetPointer
= get_pointer_ubyte
;
1100 rb
->GetRow
= get_row_ubyte
;
1101 rb
->GetValues
= get_values_ubyte
;
1102 rb
->PutRow
= put_row_ubyte
;
1103 rb
->PutRowRGB
= NULL
;
1104 rb
->PutMonoRow
= put_mono_row_ubyte
;
1105 rb
->PutValues
= put_values_ubyte
;
1106 rb
->PutMonoValues
= put_mono_values_ubyte
;
1107 pixelSize
= sizeof(GLubyte
);
1110 _mesa_problem(ctx
, "Bad internalFormat in _mesa_soft_renderbuffer_storage");
1114 ASSERT(rb
->DataType
);
1115 ASSERT(rb
->GetPointer
);
1117 ASSERT(rb
->GetValues
);
1119 ASSERT(rb
->PutMonoRow
);
1120 ASSERT(rb
->PutValues
);
1121 ASSERT(rb
->PutMonoValues
);
1123 /* free old buffer storage */
1125 _mesa_free(rb
->Data
);
1129 if (width
> 0 && height
> 0) {
1130 /* allocate new buffer storage */
1131 rb
->Data
= malloc(width
* height
* pixelSize
);
1133 if (rb
->Data
== NULL
) {
1136 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
1137 "software renderbuffer allocation (%d x %d x %d)",
1138 width
, height
, pixelSize
);
1144 rb
->Height
= height
;
1145 rb
->_BaseFormat
= _mesa_base_fbo_format(ctx
, rb
->InternalFormat
);
1152 /**********************************************************************/
1153 /**********************************************************************/
1154 /**********************************************************************/
1158 * Here we utilize the gl_renderbuffer->Wrapper field to put an alpha
1159 * buffer wrapper around an existing RGB renderbuffer (hw or sw).
1161 * When PutRow is called (for example), we store the alpha values in
1162 * this buffer, then pass on the PutRow call to the wrapped RGB
1168 alloc_storage_alpha8(GLcontext
*ctx
, struct gl_renderbuffer
*arb
,
1169 GLenum internalFormat
, GLuint width
, GLuint height
)
1171 ASSERT(arb
!= arb
->Wrapped
);
1172 ASSERT(arb
->Format
== MESA_FORMAT_A8
);
1174 /* first, pass the call to the wrapped RGB buffer */
1175 if (!arb
->Wrapped
->AllocStorage(ctx
, arb
->Wrapped
, internalFormat
,
1180 /* next, resize my alpha buffer */
1182 _mesa_free(arb
->Data
);
1185 arb
->Data
= _mesa_malloc(width
* height
* sizeof(GLubyte
));
1186 if (arb
->Data
== NULL
) {
1189 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "software alpha buffer allocation");
1194 arb
->Height
= height
;
1201 * Delete an alpha_renderbuffer object, as well as the wrapped RGB buffer.
1204 delete_renderbuffer_alpha8(struct gl_renderbuffer
*arb
)
1207 _mesa_free(arb
->Data
);
1209 ASSERT(arb
->Wrapped
);
1210 ASSERT(arb
!= arb
->Wrapped
);
1211 arb
->Wrapped
->Delete(arb
->Wrapped
);
1212 arb
->Wrapped
= NULL
;
1218 get_pointer_alpha8(GLcontext
*ctx
, struct gl_renderbuffer
*arb
,
1221 return NULL
; /* don't allow direct access! */
1226 get_row_alpha8(GLcontext
*ctx
, struct gl_renderbuffer
*arb
, GLuint count
,
1227 GLint x
, GLint y
, void *values
)
1229 /* NOTE: 'values' is RGBA format! */
1230 const GLubyte
*src
= (const GLubyte
*) arb
->Data
+ y
* arb
->Width
+ x
;
1231 GLubyte
*dst
= (GLubyte
*) values
;
1233 ASSERT(arb
!= arb
->Wrapped
);
1234 ASSERT(arb
->DataType
== GL_UNSIGNED_BYTE
);
1235 /* first, pass the call to the wrapped RGB buffer */
1236 arb
->Wrapped
->GetRow(ctx
, arb
->Wrapped
, count
, x
, y
, values
);
1237 /* second, fill in alpha values from this buffer! */
1238 for (i
= 0; i
< count
; i
++) {
1239 dst
[i
* 4 + 3] = src
[i
];
1245 get_values_alpha8(GLcontext
*ctx
, struct gl_renderbuffer
*arb
, GLuint count
,
1246 const GLint x
[], const GLint y
[], void *values
)
1248 GLubyte
*dst
= (GLubyte
*) values
;
1250 ASSERT(arb
!= arb
->Wrapped
);
1251 ASSERT(arb
->DataType
== GL_UNSIGNED_BYTE
);
1252 /* first, pass the call to the wrapped RGB buffer */
1253 arb
->Wrapped
->GetValues(ctx
, arb
->Wrapped
, count
, x
, y
, values
);
1254 /* second, fill in alpha values from this buffer! */
1255 for (i
= 0; i
< count
; i
++) {
1256 const GLubyte
*src
= (GLubyte
*) arb
->Data
+ y
[i
] * arb
->Width
+ x
[i
];
1257 dst
[i
* 4 + 3] = *src
;
1263 put_row_alpha8(GLcontext
*ctx
, struct gl_renderbuffer
*arb
, GLuint count
,
1264 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
1266 const GLubyte
*src
= (const GLubyte
*) values
;
1267 GLubyte
*dst
= (GLubyte
*) arb
->Data
+ y
* arb
->Width
+ x
;
1269 ASSERT(arb
!= arb
->Wrapped
);
1270 ASSERT(arb
->DataType
== GL_UNSIGNED_BYTE
);
1271 /* first, pass the call to the wrapped RGB buffer */
1272 arb
->Wrapped
->PutRow(ctx
, arb
->Wrapped
, count
, x
, y
, values
, mask
);
1273 /* second, store alpha in our buffer */
1274 for (i
= 0; i
< count
; i
++) {
1275 if (!mask
|| mask
[i
]) {
1276 dst
[i
] = src
[i
* 4 + 3];
1283 put_row_rgb_alpha8(GLcontext
*ctx
, struct gl_renderbuffer
*arb
, GLuint count
,
1284 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
1286 const GLubyte
*src
= (const GLubyte
*) values
;
1287 GLubyte
*dst
= (GLubyte
*) arb
->Data
+ y
* arb
->Width
+ x
;
1289 ASSERT(arb
!= arb
->Wrapped
);
1290 ASSERT(arb
->DataType
== GL_UNSIGNED_BYTE
);
1291 /* first, pass the call to the wrapped RGB buffer */
1292 arb
->Wrapped
->PutRowRGB(ctx
, arb
->Wrapped
, count
, x
, y
, values
, mask
);
1293 /* second, store alpha in our buffer */
1294 for (i
= 0; i
< count
; i
++) {
1295 if (!mask
|| mask
[i
]) {
1296 dst
[i
] = src
[i
* 4 + 3];
1303 put_mono_row_alpha8(GLcontext
*ctx
, struct gl_renderbuffer
*arb
, GLuint count
,
1304 GLint x
, GLint y
, const void *value
, const GLubyte
*mask
)
1306 const GLubyte val
= ((const GLubyte
*) value
)[3];
1307 GLubyte
*dst
= (GLubyte
*) arb
->Data
+ y
* arb
->Width
+ x
;
1308 ASSERT(arb
!= arb
->Wrapped
);
1309 ASSERT(arb
->DataType
== GL_UNSIGNED_BYTE
);
1310 /* first, pass the call to the wrapped RGB buffer */
1311 arb
->Wrapped
->PutMonoRow(ctx
, arb
->Wrapped
, count
, x
, y
, value
, mask
);
1312 /* second, store alpha in our buffer */
1315 for (i
= 0; i
< count
; i
++) {
1322 _mesa_memset(dst
, val
, count
);
1328 put_values_alpha8(GLcontext
*ctx
, struct gl_renderbuffer
*arb
, GLuint count
,
1329 const GLint x
[], const GLint y
[],
1330 const void *values
, const GLubyte
*mask
)
1332 const GLubyte
*src
= (const GLubyte
*) values
;
1334 ASSERT(arb
!= arb
->Wrapped
);
1335 ASSERT(arb
->DataType
== GL_UNSIGNED_BYTE
);
1336 /* first, pass the call to the wrapped RGB buffer */
1337 arb
->Wrapped
->PutValues(ctx
, arb
->Wrapped
, count
, x
, y
, values
, mask
);
1338 /* second, store alpha in our buffer */
1339 for (i
= 0; i
< count
; i
++) {
1340 if (!mask
|| mask
[i
]) {
1341 GLubyte
*dst
= (GLubyte
*) arb
->Data
+ y
[i
] * arb
->Width
+ x
[i
];
1342 *dst
= src
[i
* 4 + 3];
1349 put_mono_values_alpha8(GLcontext
*ctx
, struct gl_renderbuffer
*arb
,
1350 GLuint count
, const GLint x
[], const GLint y
[],
1351 const void *value
, const GLubyte
*mask
)
1353 const GLubyte val
= ((const GLubyte
*) value
)[3];
1355 ASSERT(arb
!= arb
->Wrapped
);
1356 ASSERT(arb
->DataType
== GL_UNSIGNED_BYTE
);
1357 /* first, pass the call to the wrapped RGB buffer */
1358 arb
->Wrapped
->PutValues(ctx
, arb
->Wrapped
, count
, x
, y
, value
, mask
);
1359 /* second, store alpha in our buffer */
1360 for (i
= 0; i
< count
; i
++) {
1361 if (!mask
|| mask
[i
]) {
1362 GLubyte
*dst
= (GLubyte
*) arb
->Data
+ y
[i
] * arb
->Width
+ x
[i
];
1370 copy_buffer_alpha8(struct gl_renderbuffer
* dst
, struct gl_renderbuffer
* src
)
1372 ASSERT(dst
->Format
== MESA_FORMAT_A8
);
1373 ASSERT(src
->Format
== MESA_FORMAT_A8
);
1374 ASSERT(dst
->Width
== src
->Width
);
1375 ASSERT(dst
->Height
== src
->Height
);
1377 _mesa_memcpy(dst
->Data
, src
->Data
, dst
->Width
* dst
->Height
* sizeof(GLubyte
));
1381 /**********************************************************************/
1382 /**********************************************************************/
1383 /**********************************************************************/
1387 * Default GetPointer routine. Always return NULL to indicate that
1388 * direct buffer access is not supported.
1391 nop_get_pointer(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLint x
, GLint y
)
1398 * Initialize the fields of a gl_renderbuffer to default values.
1401 _mesa_init_renderbuffer(struct gl_renderbuffer
*rb
, GLuint name
)
1403 _glthread_INIT_MUTEX(rb
->Mutex
);
1405 rb
->Magic
= RB_MAGIC
;
1409 rb
->Delete
= _mesa_delete_renderbuffer
;
1411 /* The rest of these should be set later by the caller of this function or
1412 * the AllocStorage method:
1414 rb
->AllocStorage
= NULL
;
1418 rb
->InternalFormat
= GL_NONE
;
1419 rb
->Format
= MESA_FORMAT_NONE
;
1421 rb
->DataType
= GL_NONE
;
1424 /* Point back to ourself so that we don't have to check for Wrapped==NULL
1425 * all over the drivers.
1429 rb
->GetPointer
= nop_get_pointer
;
1431 rb
->GetValues
= NULL
;
1433 rb
->PutRowRGB
= NULL
;
1434 rb
->PutMonoRow
= NULL
;
1435 rb
->PutValues
= NULL
;
1436 rb
->PutMonoValues
= NULL
;
1441 * Allocate a new gl_renderbuffer object. This can be used for user-created
1442 * renderbuffers or window-system renderbuffers.
1444 struct gl_renderbuffer
*
1445 _mesa_new_renderbuffer(GLcontext
*ctx
, GLuint name
)
1447 struct gl_renderbuffer
*rb
= CALLOC_STRUCT(gl_renderbuffer
);
1449 _mesa_init_renderbuffer(rb
, name
);
1456 * Delete a gl_framebuffer.
1457 * This is the default function for renderbuffer->Delete().
1460 _mesa_delete_renderbuffer(struct gl_renderbuffer
*rb
)
1463 _mesa_free(rb
->Data
);
1470 * Allocate a software-based renderbuffer. This is called via the
1471 * ctx->Driver.NewRenderbuffer() function when the user creates a new
1473 * This would not be used for hardware-based renderbuffers.
1475 struct gl_renderbuffer
*
1476 _mesa_new_soft_renderbuffer(GLcontext
*ctx
, GLuint name
)
1478 struct gl_renderbuffer
*rb
= _mesa_new_renderbuffer(ctx
, name
);
1480 rb
->AllocStorage
= _mesa_soft_renderbuffer_storage
;
1481 /* Normally, one would setup the PutRow, GetRow, etc functions here.
1482 * But we're doing that in the _mesa_soft_renderbuffer_storage() function
1491 * Add software-based color renderbuffers to the given framebuffer.
1492 * This is a helper routine for device drivers when creating a
1493 * window system framebuffer (not a user-created render/framebuffer).
1494 * Once this function is called, you can basically forget about this
1495 * renderbuffer; core Mesa will handle all the buffer management and
1499 _mesa_add_color_renderbuffers(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
1500 GLuint rgbBits
, GLuint alphaBits
,
1501 GLboolean frontLeft
, GLboolean backLeft
,
1502 GLboolean frontRight
, GLboolean backRight
)
1506 if (rgbBits
> 16 || alphaBits
> 16) {
1508 "Unsupported bit depth in _mesa_add_color_renderbuffers");
1512 assert(MAX_COLOR_ATTACHMENTS
>= 4);
1514 for (b
= BUFFER_FRONT_LEFT
; b
<= BUFFER_BACK_RIGHT
; b
++) {
1515 struct gl_renderbuffer
*rb
;
1517 if (b
== BUFFER_FRONT_LEFT
&& !frontLeft
)
1519 else if (b
== BUFFER_BACK_LEFT
&& !backLeft
)
1521 else if (b
== BUFFER_FRONT_RIGHT
&& !frontRight
)
1523 else if (b
== BUFFER_BACK_RIGHT
&& !backRight
)
1526 assert(fb
->Attachment
[b
].Renderbuffer
== NULL
);
1528 rb
= _mesa_new_renderbuffer(ctx
, 0);
1530 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating color buffer");
1536 rb
->Format
= MESA_FORMAT_RGBA8888
;
1538 rb
->Format
= MESA_FORMAT_RGB888
;
1541 assert(rgbBits
<= 16);
1542 rb
->Format
= MESA_FORMAT_NONE
; /*XXX RGBA16;*/
1544 rb
->InternalFormat
= GL_RGBA
;
1546 rb
->AllocStorage
= _mesa_soft_renderbuffer_storage
;
1547 _mesa_add_renderbuffer(fb
, b
, rb
);
1555 * Add software-based color index renderbuffers to the given framebuffer.
1556 * This is a helper routine for device drivers when creating a
1557 * window system framebuffer (not a user-created render/framebuffer).
1558 * Once this function is called, you can basically forget about this
1559 * renderbuffer; core Mesa will handle all the buffer management and
1563 _mesa_add_color_index_renderbuffers(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
1565 GLboolean frontLeft
, GLboolean backLeft
,
1566 GLboolean frontRight
, GLboolean backRight
)
1570 if (indexBits
> 8) {
1572 "Unsupported bit depth in _mesa_add_color_index_renderbuffers");
1576 assert(MAX_COLOR_ATTACHMENTS
>= 4);
1578 for (b
= BUFFER_FRONT_LEFT
; b
<= BUFFER_BACK_RIGHT
; b
++) {
1579 struct gl_renderbuffer
*rb
;
1581 if (b
== BUFFER_FRONT_LEFT
&& !frontLeft
)
1583 else if (b
== BUFFER_BACK_LEFT
&& !backLeft
)
1585 else if (b
== BUFFER_FRONT_RIGHT
&& !frontRight
)
1587 else if (b
== BUFFER_BACK_RIGHT
&& !backRight
)
1590 assert(fb
->Attachment
[b
].Renderbuffer
== NULL
);
1592 rb
= _mesa_new_renderbuffer(ctx
, 0);
1594 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating color buffer");
1598 assert(indexBits
<= 8);
1599 rb
->Format
= MESA_FORMAT_CI8
;
1600 rb
->InternalFormat
= GL_COLOR_INDEX
;
1602 rb
->AllocStorage
= _mesa_soft_renderbuffer_storage
;
1603 _mesa_add_renderbuffer(fb
, b
, rb
);
1611 * Add software-based alpha renderbuffers to the given framebuffer.
1612 * This is a helper routine for device drivers when creating a
1613 * window system framebuffer (not a user-created render/framebuffer).
1614 * Once this function is called, you can basically forget about this
1615 * renderbuffer; core Mesa will handle all the buffer management and
1619 _mesa_add_alpha_renderbuffers(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
1621 GLboolean frontLeft
, GLboolean backLeft
,
1622 GLboolean frontRight
, GLboolean backRight
)
1626 /* for window system framebuffers only! */
1627 assert(fb
->Name
== 0);
1629 if (alphaBits
> 8) {
1631 "Unsupported bit depth in _mesa_add_alpha_renderbuffers");
1635 assert(MAX_COLOR_ATTACHMENTS
>= 4);
1637 /* Wrap each of the RGB color buffers with an alpha renderbuffer.
1639 for (b
= BUFFER_FRONT_LEFT
; b
<= BUFFER_BACK_RIGHT
; b
++) {
1640 struct gl_renderbuffer
*arb
;
1642 if (b
== BUFFER_FRONT_LEFT
&& !frontLeft
)
1644 else if (b
== BUFFER_BACK_LEFT
&& !backLeft
)
1646 else if (b
== BUFFER_FRONT_RIGHT
&& !frontRight
)
1648 else if (b
== BUFFER_BACK_RIGHT
&& !backRight
)
1651 /* the RGB buffer to wrap must already exist!! */
1652 assert(fb
->Attachment
[b
].Renderbuffer
);
1654 /* only GLubyte supported for now */
1655 assert(fb
->Attachment
[b
].Renderbuffer
->DataType
== GL_UNSIGNED_BYTE
);
1657 /* allocate alpha renderbuffer */
1658 arb
= _mesa_new_renderbuffer(ctx
, 0);
1660 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating alpha buffer");
1664 /* wrap the alpha renderbuffer around the RGB renderbuffer */
1665 arb
->Wrapped
= fb
->Attachment
[b
].Renderbuffer
;
1667 /* Set up my alphabuffer fields and plug in my functions.
1668 * The functions will put/get the alpha values from/to RGBA arrays
1669 * and then call the wrapped buffer's functions to handle the RGB
1672 arb
->InternalFormat
= arb
->Wrapped
->InternalFormat
;
1673 arb
->Format
= MESA_FORMAT_A8
;
1674 arb
->DataType
= arb
->Wrapped
->DataType
;
1675 arb
->AllocStorage
= alloc_storage_alpha8
;
1676 arb
->Delete
= delete_renderbuffer_alpha8
;
1677 arb
->GetPointer
= get_pointer_alpha8
;
1678 arb
->GetRow
= get_row_alpha8
;
1679 arb
->GetValues
= get_values_alpha8
;
1680 arb
->PutRow
= put_row_alpha8
;
1681 arb
->PutRowRGB
= put_row_rgb_alpha8
;
1682 arb
->PutMonoRow
= put_mono_row_alpha8
;
1683 arb
->PutValues
= put_values_alpha8
;
1684 arb
->PutMonoValues
= put_mono_values_alpha8
;
1686 /* clear the pointer to avoid assertion/sanity check failure later */
1687 fb
->Attachment
[b
].Renderbuffer
= NULL
;
1689 /* plug the alpha renderbuffer into the colorbuffer attachment */
1690 _mesa_add_renderbuffer(fb
, b
, arb
);
1698 * For framebuffers that use a software alpha channel wrapper
1699 * created by _mesa_add_alpha_renderbuffer or _mesa_add_soft_renderbuffers,
1700 * copy the back buffer alpha channel into the front buffer alpha channel.
1703 _mesa_copy_soft_alpha_renderbuffers(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
1705 if (fb
->Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
&&
1706 fb
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
)
1707 copy_buffer_alpha8(fb
->Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
,
1708 fb
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
);
1711 if (fb
->Attachment
[BUFFER_FRONT_RIGHT
].Renderbuffer
&&
1712 fb
->Attachment
[BUFFER_BACK_RIGHT
].Renderbuffer
)
1713 copy_buffer_alpha8(fb
->Attachment
[BUFFER_FRONT_RIGHT
].Renderbuffer
,
1714 fb
->Attachment
[BUFFER_BACK_RIGHT
].Renderbuffer
);
1719 * Add a software-based depth renderbuffer to the given framebuffer.
1720 * This is a helper routine for device drivers when creating a
1721 * window system framebuffer (not a user-created render/framebuffer).
1722 * Once this function is called, you can basically forget about this
1723 * renderbuffer; core Mesa will handle all the buffer management and
1727 _mesa_add_depth_renderbuffer(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
1730 struct gl_renderbuffer
*rb
;
1732 if (depthBits
> 32) {
1734 "Unsupported depthBits in _mesa_add_depth_renderbuffer");
1738 assert(fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
== NULL
);
1740 rb
= _mesa_new_renderbuffer(ctx
, 0);
1742 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating depth buffer");
1746 if (depthBits
<= 16) {
1747 rb
->Format
= MESA_FORMAT_Z16
;
1748 rb
->InternalFormat
= GL_DEPTH_COMPONENT16
;
1750 else if (depthBits
<= 24) {
1751 rb
->Format
= MESA_FORMAT_X8_Z24
;
1752 rb
->InternalFormat
= GL_DEPTH_COMPONENT24
;
1755 rb
->Format
= MESA_FORMAT_Z32
;
1756 rb
->InternalFormat
= GL_DEPTH_COMPONENT32
;
1759 rb
->AllocStorage
= _mesa_soft_renderbuffer_storage
;
1760 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, rb
);
1767 * Add a software-based stencil renderbuffer to the given framebuffer.
1768 * This is a helper routine for device drivers when creating a
1769 * window system framebuffer (not a user-created render/framebuffer).
1770 * Once this function is called, you can basically forget about this
1771 * renderbuffer; core Mesa will handle all the buffer management and
1775 _mesa_add_stencil_renderbuffer(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
1778 struct gl_renderbuffer
*rb
;
1780 if (stencilBits
> 16) {
1782 "Unsupported stencilBits in _mesa_add_stencil_renderbuffer");
1786 assert(fb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
== NULL
);
1788 rb
= _mesa_new_renderbuffer(ctx
, 0);
1790 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating stencil buffer");
1794 assert(stencilBits
<= 8);
1795 rb
->Format
= MESA_FORMAT_S8
;
1796 rb
->InternalFormat
= GL_STENCIL_INDEX8
;
1798 rb
->AllocStorage
= _mesa_soft_renderbuffer_storage
;
1799 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, rb
);
1806 * Add a software-based accumulation renderbuffer to the given framebuffer.
1807 * This is a helper routine for device drivers when creating a
1808 * window system framebuffer (not a user-created render/framebuffer).
1809 * Once this function is called, you can basically forget about this
1810 * renderbuffer; core Mesa will handle all the buffer management and
1814 _mesa_add_accum_renderbuffer(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
1815 GLuint redBits
, GLuint greenBits
,
1816 GLuint blueBits
, GLuint alphaBits
)
1818 struct gl_renderbuffer
*rb
;
1820 if (redBits
> 16 || greenBits
> 16 || blueBits
> 16 || alphaBits
> 16) {
1822 "Unsupported accumBits in _mesa_add_accum_renderbuffer");
1826 assert(fb
->Attachment
[BUFFER_ACCUM
].Renderbuffer
== NULL
);
1828 rb
= _mesa_new_renderbuffer(ctx
, 0);
1830 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating accum buffer");
1834 rb
->Format
= MESA_FORMAT_SIGNED_RGBA_16
;
1835 rb
->InternalFormat
= GL_RGBA16
;
1836 rb
->AllocStorage
= _mesa_soft_renderbuffer_storage
;
1837 _mesa_add_renderbuffer(fb
, BUFFER_ACCUM
, rb
);
1845 * Add a software-based accumulation renderbuffer to the given framebuffer.
1846 * This is a helper routine for device drivers when creating a
1847 * window system framebuffer (not a user-created render/framebuffer).
1848 * Once this function is called, you can basically forget about this
1849 * renderbuffer; core Mesa will handle all the buffer management and
1852 * NOTE: color-index aux buffers not supported.
1855 _mesa_add_aux_renderbuffers(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
1856 GLuint colorBits
, GLuint numBuffers
)
1860 if (colorBits
> 16) {
1862 "Unsupported accumBits in _mesa_add_aux_renderbuffers");
1866 assert(numBuffers
<= MAX_AUX_BUFFERS
);
1868 for (i
= 0; i
< numBuffers
; i
++) {
1869 struct gl_renderbuffer
*rb
= _mesa_new_renderbuffer(ctx
, 0);
1871 assert(fb
->Attachment
[BUFFER_AUX0
+ i
].Renderbuffer
== NULL
);
1874 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating accum buffer");
1878 assert (colorBits
<= 8);
1879 rb
->Format
= MESA_FORMAT_RGBA8888
;
1880 rb
->InternalFormat
= GL_RGBA
;
1882 rb
->AllocStorage
= _mesa_soft_renderbuffer_storage
;
1883 _mesa_add_renderbuffer(fb
, BUFFER_AUX0
+ i
, rb
);
1890 * Create/attach software-based renderbuffers to the given framebuffer.
1891 * This is a helper routine for device drivers. Drivers can just as well
1892 * call the individual _mesa_add_*_renderbuffer() routines directly.
1895 _mesa_add_soft_renderbuffers(struct gl_framebuffer
*fb
,
1903 GLboolean frontLeft
= GL_TRUE
;
1904 GLboolean backLeft
= fb
->Visual
.doubleBufferMode
;
1905 GLboolean frontRight
= fb
->Visual
.stereoMode
;
1906 GLboolean backRight
= fb
->Visual
.stereoMode
&& fb
->Visual
.doubleBufferMode
;
1909 if (fb
->Visual
.rgbMode
) {
1910 assert(fb
->Visual
.redBits
== fb
->Visual
.greenBits
);
1911 assert(fb
->Visual
.redBits
== fb
->Visual
.blueBits
);
1912 _mesa_add_color_renderbuffers(NULL
, fb
,
1914 fb
->Visual
.alphaBits
,
1915 frontLeft
, backLeft
,
1916 frontRight
, backRight
);
1919 _mesa_add_color_index_renderbuffers(NULL
, fb
,
1920 fb
->Visual
.indexBits
,
1921 frontLeft
, backLeft
,
1922 frontRight
, backRight
);
1927 assert(fb
->Visual
.depthBits
> 0);
1928 _mesa_add_depth_renderbuffer(NULL
, fb
, fb
->Visual
.depthBits
);
1932 assert(fb
->Visual
.stencilBits
> 0);
1933 _mesa_add_stencil_renderbuffer(NULL
, fb
, fb
->Visual
.stencilBits
);
1937 assert(fb
->Visual
.rgbMode
);
1938 assert(fb
->Visual
.accumRedBits
> 0);
1939 assert(fb
->Visual
.accumGreenBits
> 0);
1940 assert(fb
->Visual
.accumBlueBits
> 0);
1941 _mesa_add_accum_renderbuffer(NULL
, fb
,
1942 fb
->Visual
.accumRedBits
,
1943 fb
->Visual
.accumGreenBits
,
1944 fb
->Visual
.accumBlueBits
,
1945 fb
->Visual
.accumAlphaBits
);
1949 assert(fb
->Visual
.rgbMode
);
1950 assert(fb
->Visual
.numAuxBuffers
> 0);
1951 _mesa_add_aux_renderbuffers(NULL
, fb
, fb
->Visual
.redBits
,
1952 fb
->Visual
.numAuxBuffers
);
1956 assert(fb
->Visual
.rgbMode
);
1957 assert(fb
->Visual
.alphaBits
> 0);
1958 _mesa_add_alpha_renderbuffers(NULL
, fb
, fb
->Visual
.alphaBits
,
1959 frontLeft
, backLeft
,
1960 frontRight
, backRight
);
1972 * Attach a renderbuffer to a framebuffer.
1975 _mesa_add_renderbuffer(struct gl_framebuffer
*fb
,
1976 GLuint bufferName
, struct gl_renderbuffer
*rb
)
1982 assert(bufferName
< BUFFER_COUNT
);
1984 /* There should be no previous renderbuffer on this attachment point,
1985 * with the exception of depth/stencil since the same renderbuffer may
1988 assert(bufferName
== BUFFER_DEPTH
||
1989 bufferName
== BUFFER_STENCIL
||
1990 fb
->Attachment
[bufferName
].Renderbuffer
== NULL
);
1992 /* winsys vs. user-created buffer cross check */
2000 /* If Mesa's compiled with deep color channels (16 or 32 bits / channel)
2001 * and the device driver is expecting 8-bit values (GLubyte), we can
2002 * use a "renderbuffer adaptor/wrapper" to do the necessary conversions.
2004 baseFormat
= _mesa_get_format_base_format(rb
->Format
);
2005 if (baseFormat
== GL_RGBA
) {
2006 if (CHAN_BITS
== 16 && rb
->DataType
== GL_UNSIGNED_BYTE
) {
2007 GET_CURRENT_CONTEXT(ctx
);
2008 rb
= _mesa_new_renderbuffer_16wrap8(ctx
, rb
);
2010 else if (CHAN_BITS
== 32 && rb
->DataType
== GL_UNSIGNED_BYTE
) {
2011 GET_CURRENT_CONTEXT(ctx
);
2012 rb
= _mesa_new_renderbuffer_32wrap8(ctx
, rb
);
2014 else if (CHAN_BITS
== 32 && rb
->DataType
== GL_UNSIGNED_SHORT
) {
2015 GET_CURRENT_CONTEXT(ctx
);
2016 rb
= _mesa_new_renderbuffer_32wrap16(ctx
, rb
);
2020 fb
->Attachment
[bufferName
].Type
= GL_RENDERBUFFER_EXT
;
2021 fb
->Attachment
[bufferName
].Complete
= GL_TRUE
;
2022 _mesa_reference_renderbuffer(&fb
->Attachment
[bufferName
].Renderbuffer
, rb
);
2027 * Remove the named renderbuffer from the given framebuffer.
2030 _mesa_remove_renderbuffer(struct gl_framebuffer
*fb
, GLuint bufferName
)
2032 struct gl_renderbuffer
*rb
;
2034 assert(bufferName
< BUFFER_COUNT
);
2036 rb
= fb
->Attachment
[bufferName
].Renderbuffer
;
2040 _mesa_reference_renderbuffer(&rb
, NULL
);
2042 fb
->Attachment
[bufferName
].Renderbuffer
= NULL
;
2047 * Set *ptr to point to rb. If *ptr points to another renderbuffer,
2048 * dereference that buffer first. The new renderbuffer's refcount will
2049 * be incremented. The old renderbuffer's refcount will be decremented.
2052 _mesa_reference_renderbuffer(struct gl_renderbuffer
**ptr
,
2053 struct gl_renderbuffer
*rb
)
2062 /* Unreference the old renderbuffer */
2063 GLboolean deleteFlag
= GL_FALSE
;
2064 struct gl_renderbuffer
*oldRb
= *ptr
;
2066 assert(oldRb
->Magic
== RB_MAGIC
);
2067 _glthread_LOCK_MUTEX(oldRb
->Mutex
);
2068 assert(oldRb
->Magic
== RB_MAGIC
);
2069 ASSERT(oldRb
->RefCount
> 0);
2071 /*printf("RB DECR %p (%d) to %d\n", (void*) oldRb, oldRb->Name, oldRb->RefCount);*/
2072 deleteFlag
= (oldRb
->RefCount
== 0);
2073 _glthread_UNLOCK_MUTEX(oldRb
->Mutex
);
2076 oldRb
->Magic
= 0; /* now invalid memory! */
2077 oldRb
->Delete(oldRb
);
2085 assert(rb
->Magic
== RB_MAGIC
);
2086 /* reference new renderbuffer */
2087 _glthread_LOCK_MUTEX(rb
->Mutex
);
2089 /*printf("RB INCR %p (%d) to %d\n", (void*) rb, rb->Name, rb->RefCount);*/
2090 _glthread_UNLOCK_MUTEX(rb
->Mutex
);
2097 * Create a new combined depth/stencil renderbuffer for implementing
2098 * the GL_EXT_packed_depth_stencil extension.
2099 * \return new depth/stencil renderbuffer
2101 struct gl_renderbuffer
*
2102 _mesa_new_depthstencil_renderbuffer(GLcontext
*ctx
, GLuint name
)
2104 struct gl_renderbuffer
*dsrb
;
2106 dsrb
= _mesa_new_renderbuffer(ctx
, name
);
2110 /* init fields not covered by _mesa_new_renderbuffer() */
2111 dsrb
->InternalFormat
= GL_DEPTH24_STENCIL8_EXT
;
2112 dsrb
->Format
= MESA_FORMAT_Z24_S8
;
2113 dsrb
->AllocStorage
= _mesa_soft_renderbuffer_storage
;