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.
49 #include "renderbuffer.h"
53 * Routines for get/put values in common buffer formats follow.
56 /* Returns a bytes per pixel of the DataType in the get/put span
57 * functions for at least a subset of the available combinations a
58 * renderbuffer can have.
60 * It would be nice to see gl_renderbuffer start talking about a
61 * gl_format instead of a GLenum DataType.
64 get_datatype_bytes(struct gl_renderbuffer
*rb
)
68 switch (rb
->DataType
) {
69 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
74 case GL_UNSIGNED_INT_24_8_EXT
:
77 case GL_UNSIGNED_SHORT
:
80 case GL_UNSIGNED_BYTE
:
88 switch (rb
->_BaseFormat
) {
89 case GL_DEPTH_COMPONENT
:
90 case GL_DEPTH_STENCIL
:
91 return component_size
;
93 return 4 * component_size
;
97 /* This is commonly used by most of the accessors. */
99 get_pointer_generic(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
105 return ((char *) rb
->Data
+
106 (y
* rb
->RowStride
+ x
) * _mesa_get_format_bytes(rb
->Format
));
109 /* GetRow() implementation for formats where DataType matches the rb->Format.
112 get_row_generic(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
113 GLuint count
, GLint x
, GLint y
, void *values
)
115 void *src
= rb
->GetPointer(ctx
, rb
, x
, y
);
116 memcpy(values
, src
, count
* _mesa_get_format_bytes(rb
->Format
));
119 /* Only used for float textures currently, but might also be used for
120 * RGBA8888, RGBA16, etc.
123 get_values_generic(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
124 GLuint count
, const GLint x
[], const GLint y
[], void *values
)
126 int format_bytes
= _mesa_get_format_bytes(rb
->Format
) / sizeof(GLfloat
);
129 for (i
= 0; i
< count
; i
++) {
130 const void *src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
131 char *dst
= (char *) values
+ i
* format_bytes
;
132 memcpy(dst
, src
, format_bytes
);
136 /* For the GL_RED/GL_RG/GL_RGB format/DataType combinations (and
137 * GL_LUMINANCE/GL_INTENSITY?), the Put functions are a matter of
138 * storing those initial components of the value per pixel into the
142 put_row_generic(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
143 GLuint count
, GLint x
, GLint y
,
144 const void *values
, const GLubyte
*mask
)
146 void *row
= rb
->GetPointer(ctx
, rb
, x
, y
);
147 int format_bytes
= _mesa_get_format_bytes(rb
->Format
) / sizeof(GLfloat
);
148 int datatype_bytes
= get_datatype_bytes(rb
);
152 for (i
= 0; i
< count
; i
++) {
153 char *dst
= (char *) row
+ i
* format_bytes
;
154 const char *src
= (const char *) values
+ i
* datatype_bytes
;
157 memcpy(dst
, src
, format_bytes
);
162 for (i
= 0; i
< count
; i
++) {
163 char *dst
= (char *) row
+ i
* format_bytes
;
164 const char *src
= (const char *) values
+ i
* datatype_bytes
;
165 memcpy(dst
, src
, format_bytes
);
171 put_mono_row_generic(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
172 GLuint count
, GLint x
, GLint y
,
173 const void *value
, const GLubyte
*mask
)
175 void *row
= rb
->GetPointer(ctx
, rb
, x
, y
);
176 int format_bytes
= _mesa_get_format_bytes(rb
->Format
) / sizeof(GLfloat
);
180 for (i
= 0; i
< count
; i
++) {
181 char *dst
= (char *) row
+ i
* format_bytes
;
183 memcpy(dst
, value
, format_bytes
);
188 for (i
= 0; i
< count
; i
++) {
189 char *dst
= (char *) row
+ i
* format_bytes
;
190 memcpy(dst
, value
, format_bytes
);
197 put_values_generic(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
198 GLuint count
, const GLint x
[], const GLint y
[],
199 const void *values
, const GLubyte
*mask
)
201 int format_bytes
= _mesa_get_format_bytes(rb
->Format
) / sizeof(GLfloat
);
202 int datatype_bytes
= get_datatype_bytes(rb
);
205 for (i
= 0; i
< count
; i
++) {
206 if (!mask
|| mask
[i
]) {
207 void *dst
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
208 const char *src
= (const char *) values
+ i
* datatype_bytes
;
209 memcpy(dst
, src
, format_bytes
);
216 put_mono_values_generic(struct gl_context
*ctx
,
217 struct gl_renderbuffer
*rb
,
218 GLuint count
, const GLint x
[], const GLint y
[],
219 const void *value
, const GLubyte
*mask
)
221 int format_bytes
= _mesa_get_format_bytes(rb
->Format
) / sizeof(GLfloat
);
224 for (i
= 0; i
< count
; i
++) {
225 if (!mask
|| mask
[i
]) {
226 void *dst
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
227 memcpy(dst
, value
, format_bytes
);
232 /**********************************************************************
233 * Functions for buffers of 1 X GLubyte values.
238 get_values_ubyte(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
239 const GLint x
[], const GLint y
[], void *values
)
241 GLubyte
*dst
= (GLubyte
*) values
;
243 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
244 for (i
= 0; i
< count
; i
++) {
245 const GLubyte
*src
= (GLubyte
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
252 put_row_ubyte(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
253 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
255 const GLubyte
*src
= (const GLubyte
*) values
;
256 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ y
* rb
->RowStride
+ x
;
257 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
260 for (i
= 0; i
< count
; i
++) {
267 memcpy(dst
, values
, count
* sizeof(GLubyte
));
273 put_mono_row_ubyte(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
274 GLint x
, GLint y
, const void *value
, const GLubyte
*mask
)
276 const GLubyte val
= *((const GLubyte
*) value
);
277 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ y
* rb
->RowStride
+ x
;
278 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
281 for (i
= 0; i
< count
; i
++) {
289 for (i
= 0; i
< count
; i
++) {
297 put_values_ubyte(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
298 const GLint x
[], const GLint y
[],
299 const void *values
, const GLubyte
*mask
)
301 const GLubyte
*src
= (const GLubyte
*) values
;
303 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
304 for (i
= 0; i
< count
; i
++) {
305 if (!mask
|| mask
[i
]) {
306 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
314 put_mono_values_ubyte(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
315 const GLint x
[], const GLint y
[],
316 const void *value
, const GLubyte
*mask
)
318 const GLubyte val
= *((const GLubyte
*) value
);
320 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
321 for (i
= 0; i
< count
; i
++) {
322 if (!mask
|| mask
[i
]) {
323 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
330 /**********************************************************************
331 * Functions for buffers of 1 X GLushort values.
336 get_values_ushort(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
337 const GLint x
[], const GLint y
[], void *values
)
339 GLushort
*dst
= (GLushort
*) values
;
341 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
);
342 for (i
= 0; i
< count
; i
++) {
343 const GLushort
*src
= (GLushort
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
350 put_row_ushort(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
351 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
353 const GLushort
*src
= (const GLushort
*) values
;
354 GLushort
*dst
= (GLushort
*) rb
->Data
+ y
* rb
->RowStride
+ x
;
355 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
);
358 for (i
= 0; i
< count
; i
++) {
365 memcpy(dst
, src
, count
* sizeof(GLushort
));
371 put_mono_row_ushort(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
372 GLint x
, GLint y
, const void *value
, const GLubyte
*mask
)
374 const GLushort val
= *((const GLushort
*) value
);
375 GLushort
*dst
= (GLushort
*) rb
->Data
+ y
* rb
->RowStride
+ x
;
376 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
);
379 for (i
= 0; i
< count
; i
++) {
387 for (i
= 0; i
< count
; i
++) {
395 put_values_ushort(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
396 const GLint x
[], const GLint y
[], const void *values
,
399 const GLushort
*src
= (const GLushort
*) values
;
401 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
);
402 for (i
= 0; i
< count
; i
++) {
403 if (!mask
|| mask
[i
]) {
404 GLushort
*dst
= (GLushort
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
412 put_mono_values_ushort(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
413 GLuint count
, const GLint x
[], const GLint y
[],
414 const void *value
, const GLubyte
*mask
)
416 const GLushort val
= *((const GLushort
*) value
);
417 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
);
420 for (i
= 0; i
< count
; i
++) {
422 GLushort
*dst
= (GLushort
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
429 for (i
= 0; i
< count
; i
++) {
430 GLushort
*dst
= (GLushort
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
437 /**********************************************************************
438 * Functions for buffers of 1 X GLuint values.
439 * Typically depth/Z or color index.
443 get_values_uint(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
444 const GLint x
[], const GLint y
[], void *values
)
446 GLuint
*dst
= (GLuint
*) values
;
448 ASSERT(rb
->DataType
== GL_UNSIGNED_INT
||
449 rb
->DataType
== GL_UNSIGNED_INT_24_8_EXT
);
450 for (i
= 0; i
< count
; i
++) {
451 const GLuint
*src
= (GLuint
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
458 put_row_uint(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
459 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
461 const GLuint
*src
= (const GLuint
*) values
;
462 GLuint
*dst
= (GLuint
*) rb
->Data
+ y
* rb
->RowStride
+ x
;
463 ASSERT(rb
->DataType
== GL_UNSIGNED_INT
||
464 rb
->DataType
== GL_UNSIGNED_INT_24_8_EXT
);
467 for (i
= 0; i
< count
; i
++) {
474 memcpy(dst
, src
, count
* sizeof(GLuint
));
480 put_mono_row_uint(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
481 GLint x
, GLint y
, const void *value
, const GLubyte
*mask
)
483 const GLuint val
= *((const GLuint
*) value
);
484 GLuint
*dst
= (GLuint
*) rb
->Data
+ y
* rb
->RowStride
+ x
;
485 ASSERT(rb
->DataType
== GL_UNSIGNED_INT
||
486 rb
->DataType
== GL_UNSIGNED_INT_24_8_EXT
);
489 for (i
= 0; i
< count
; i
++) {
497 for (i
= 0; i
< count
; i
++) {
505 put_values_uint(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
506 const GLint x
[], const GLint y
[], const void *values
,
509 const GLuint
*src
= (const GLuint
*) values
;
511 ASSERT(rb
->DataType
== GL_UNSIGNED_INT
||
512 rb
->DataType
== GL_UNSIGNED_INT_24_8_EXT
);
513 for (i
= 0; i
< count
; i
++) {
514 if (!mask
|| mask
[i
]) {
515 GLuint
*dst
= (GLuint
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
523 put_mono_values_uint(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
524 const GLint x
[], const GLint y
[], const void *value
,
527 const GLuint val
= *((const GLuint
*) value
);
529 ASSERT(rb
->DataType
== GL_UNSIGNED_INT
||
530 rb
->DataType
== GL_UNSIGNED_INT_24_8_EXT
);
531 for (i
= 0; i
< count
; i
++) {
532 if (!mask
|| mask
[i
]) {
533 GLuint
*dst
= (GLuint
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
540 /**********************************************************************
541 * Functions for buffers of 3 X GLubyte (or GLbyte) values.
542 * Typically color buffers.
543 * NOTE: the incoming and outgoing colors are RGBA! We ignore incoming
544 * alpha values and return 255 for outgoing alpha values.
548 get_pointer_ubyte3(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
551 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
552 /* No direct access since this buffer is RGB but caller will be
553 * treating it as if it were RGBA.
560 get_row_ubyte3(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
561 GLint x
, GLint y
, void *values
)
563 const GLubyte
*src
= ((const GLubyte
*) rb
->Data
) +
564 3 * (y
* rb
->RowStride
+ x
);
565 GLubyte
*dst
= (GLubyte
*) values
;
567 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
568 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
569 for (i
= 0; i
< count
; i
++) {
570 dst
[i
* 4 + 0] = src
[i
* 3 + 0];
571 dst
[i
* 4 + 1] = src
[i
* 3 + 1];
572 dst
[i
* 4 + 2] = src
[i
* 3 + 2];
573 dst
[i
* 4 + 3] = 255;
579 get_values_ubyte3(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
580 const GLint x
[], const GLint y
[], void *values
)
582 GLubyte
*dst
= (GLubyte
*) values
;
584 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
585 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
586 for (i
= 0; i
< count
; i
++) {
588 = (GLubyte
*) rb
->Data
+ 3 * (y
[i
] * rb
->RowStride
+ x
[i
]);
589 dst
[i
* 4 + 0] = src
[0];
590 dst
[i
* 4 + 1] = src
[1];
591 dst
[i
* 4 + 2] = src
[2];
592 dst
[i
* 4 + 3] = 255;
598 put_row_ubyte3(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
599 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
601 /* note: incoming values are RGB+A! */
602 const GLubyte
*src
= (const GLubyte
*) values
;
603 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ 3 * (y
* rb
->RowStride
+ x
);
605 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
606 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
607 for (i
= 0; i
< count
; i
++) {
608 if (!mask
|| mask
[i
]) {
609 dst
[i
* 3 + 0] = src
[i
* 4 + 0];
610 dst
[i
* 3 + 1] = src
[i
* 4 + 1];
611 dst
[i
* 3 + 2] = src
[i
* 4 + 2];
618 put_row_rgb_ubyte3(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
619 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
621 /* note: incoming values are RGB+A! */
622 const GLubyte
*src
= (const GLubyte
*) values
;
623 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ 3 * (y
* rb
->RowStride
+ x
);
625 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
626 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
627 for (i
= 0; i
< count
; i
++) {
628 if (!mask
|| mask
[i
]) {
629 dst
[i
* 3 + 0] = src
[i
* 3 + 0];
630 dst
[i
* 3 + 1] = src
[i
* 3 + 1];
631 dst
[i
* 3 + 2] = src
[i
* 3 + 2];
638 put_mono_row_ubyte3(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
639 GLint x
, GLint y
, const void *value
, const GLubyte
*mask
)
641 /* note: incoming value is RGB+A! */
642 const GLubyte val0
= ((const GLubyte
*) value
)[0];
643 const GLubyte val1
= ((const GLubyte
*) value
)[1];
644 const GLubyte val2
= ((const GLubyte
*) value
)[2];
645 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ 3 * (y
* rb
->RowStride
+ x
);
646 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
647 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
648 if (!mask
&& val0
== val1
&& val1
== val2
) {
650 memset(dst
, val0
, 3 * count
);
654 for (i
= 0; i
< count
; i
++) {
655 if (!mask
|| mask
[i
]) {
656 dst
[i
* 3 + 0] = val0
;
657 dst
[i
* 3 + 1] = val1
;
658 dst
[i
* 3 + 2] = val2
;
666 put_values_ubyte3(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
667 const GLint x
[], const GLint y
[], const void *values
,
670 /* note: incoming values are RGB+A! */
671 const GLubyte
*src
= (const GLubyte
*) values
;
673 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
674 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
675 for (i
= 0; i
< count
; i
++) {
676 if (!mask
|| mask
[i
]) {
677 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ 3 * (y
[i
] * rb
->RowStride
+ x
[i
]);
678 dst
[0] = src
[i
* 4 + 0];
679 dst
[1] = src
[i
* 4 + 1];
680 dst
[2] = src
[i
* 4 + 2];
687 put_mono_values_ubyte3(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
688 GLuint count
, const GLint x
[], const GLint y
[],
689 const void *value
, const GLubyte
*mask
)
691 /* note: incoming value is RGB+A! */
692 const GLubyte val0
= ((const GLubyte
*) value
)[0];
693 const GLubyte val1
= ((const GLubyte
*) value
)[1];
694 const GLubyte val2
= ((const GLubyte
*) value
)[2];
696 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
697 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
698 for (i
= 0; i
< count
; i
++) {
699 if (!mask
|| mask
[i
]) {
700 GLubyte
*dst
= ((GLubyte
*) rb
->Data
) +
701 3 * (y
[i
] * rb
->RowStride
+ x
[i
]);
710 /**********************************************************************
711 * Functions for buffers of 4 X GLubyte (or GLbyte) values.
712 * Typically color buffers.
716 get_values_ubyte4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
717 const GLint x
[], const GLint y
[], void *values
)
719 /* treat 4*GLubyte as 1*GLuint */
720 GLuint
*dst
= (GLuint
*) values
;
722 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
723 ASSERT(rb
->Format
== MESA_FORMAT_RGBA8888
);
724 for (i
= 0; i
< count
; i
++) {
725 const GLuint
*src
= (GLuint
*) rb
->Data
+ (y
[i
] * rb
->RowStride
+ x
[i
]);
732 put_row_ubyte4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
733 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
735 /* treat 4*GLubyte as 1*GLuint */
736 const GLuint
*src
= (const GLuint
*) values
;
737 GLuint
*dst
= (GLuint
*) rb
->Data
+ (y
* rb
->RowStride
+ x
);
738 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
739 ASSERT(rb
->Format
== MESA_FORMAT_RGBA8888
);
742 for (i
= 0; i
< count
; i
++) {
749 memcpy(dst
, src
, 4 * count
* sizeof(GLubyte
));
755 put_row_rgb_ubyte4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
756 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
758 /* Store RGB values in RGBA buffer */
759 const GLubyte
*src
= (const GLubyte
*) values
;
760 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ 4 * (y
* rb
->RowStride
+ x
);
762 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
763 ASSERT(rb
->Format
== MESA_FORMAT_RGBA8888
);
764 for (i
= 0; i
< count
; i
++) {
765 if (!mask
|| mask
[i
]) {
766 dst
[i
* 4 + 0] = src
[i
* 3 + 0];
767 dst
[i
* 4 + 1] = src
[i
* 3 + 1];
768 dst
[i
* 4 + 2] = src
[i
* 3 + 2];
769 dst
[i
* 4 + 3] = 0xff;
776 put_mono_row_ubyte4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
777 GLint x
, GLint y
, const void *value
, const GLubyte
*mask
)
779 /* treat 4*GLubyte as 1*GLuint */
780 const GLuint val
= *((const GLuint
*) value
);
781 GLuint
*dst
= (GLuint
*) rb
->Data
+ (y
* rb
->RowStride
+ x
);
782 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
783 ASSERT(rb
->Format
== MESA_FORMAT_RGBA8888
);
784 if (!mask
&& val
== 0) {
786 memset(dst
, 0, count
* 4 * sizeof(GLubyte
));
792 for (i
= 0; i
< count
; i
++) {
800 for (i
= 0; i
< count
; i
++) {
809 put_values_ubyte4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
810 const GLint x
[], const GLint y
[], const void *values
,
813 /* treat 4*GLubyte as 1*GLuint */
814 const GLuint
*src
= (const GLuint
*) values
;
816 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
817 ASSERT(rb
->Format
== MESA_FORMAT_RGBA8888
);
818 for (i
= 0; i
< count
; i
++) {
819 if (!mask
|| mask
[i
]) {
820 GLuint
*dst
= (GLuint
*) rb
->Data
+ (y
[i
] * rb
->RowStride
+ x
[i
]);
828 put_mono_values_ubyte4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
829 GLuint count
, const GLint x
[], const GLint y
[],
830 const void *value
, const GLubyte
*mask
)
832 /* treat 4*GLubyte as 1*GLuint */
833 const GLuint val
= *((const GLuint
*) value
);
835 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
836 ASSERT(rb
->Format
== MESA_FORMAT_RGBA8888
);
837 for (i
= 0; i
< count
; i
++) {
838 if (!mask
|| mask
[i
]) {
839 GLuint
*dst
= (GLuint
*) rb
->Data
+ (y
[i
] * rb
->RowStride
+ x
[i
]);
846 /**********************************************************************
847 * Functions for buffers of 4 X GLushort (or GLshort) values.
848 * Typically accum buffer.
852 get_values_ushort4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
853 const GLint x
[], const GLint y
[], void *values
)
855 GLushort
*dst
= (GLushort
*) values
;
857 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
|| rb
->DataType
== GL_SHORT
);
858 for (i
= 0; i
< count
; i
++) {
860 = (GLushort
*) rb
->Data
+ 4 * (y
[i
] * rb
->RowStride
+ x
[i
]);
867 put_row_ushort4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
868 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
870 const GLushort
*src
= (const GLushort
*) values
;
871 GLushort
*dst
= (GLushort
*) rb
->Data
+ 4 * (y
* rb
->RowStride
+ x
);
872 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
|| rb
->DataType
== GL_SHORT
);
875 for (i
= 0; i
< count
; i
++) {
877 dst
[i
* 4 + 0] = src
[i
* 4 + 0];
878 dst
[i
* 4 + 1] = src
[i
* 4 + 1];
879 dst
[i
* 4 + 2] = src
[i
* 4 + 2];
880 dst
[i
* 4 + 3] = src
[i
* 4 + 3];
885 memcpy(dst
, src
, 4 * count
* sizeof(GLushort
));
891 put_row_rgb_ushort4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
892 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
894 /* Put RGB values in RGBA buffer */
895 const GLushort
*src
= (const GLushort
*) values
;
896 GLushort
*dst
= (GLushort
*) rb
->Data
+ 4 * (y
* rb
->RowStride
+ x
);
897 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
|| rb
->DataType
== GL_SHORT
);
900 for (i
= 0; i
< count
; i
++) {
902 dst
[i
* 4 + 0] = src
[i
* 3 + 0];
903 dst
[i
* 4 + 1] = src
[i
* 3 + 1];
904 dst
[i
* 4 + 2] = src
[i
* 3 + 2];
905 dst
[i
* 4 + 3] = 0xffff;
910 memcpy(dst
, src
, 4 * count
* sizeof(GLushort
));
916 put_mono_row_ushort4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
917 GLint x
, GLint y
, const void *value
, const GLubyte
*mask
)
919 const GLushort val0
= ((const GLushort
*) value
)[0];
920 const GLushort val1
= ((const GLushort
*) value
)[1];
921 const GLushort val2
= ((const GLushort
*) value
)[2];
922 const GLushort val3
= ((const GLushort
*) value
)[3];
923 GLushort
*dst
= (GLushort
*) rb
->Data
+ 4 * (y
* rb
->RowStride
+ x
);
924 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
|| rb
->DataType
== GL_SHORT
);
925 if (!mask
&& val0
== 0 && val1
== 0 && val2
== 0 && val3
== 0) {
926 /* common case for clearing accum buffer */
927 memset(dst
, 0, count
* 4 * sizeof(GLushort
));
931 for (i
= 0; i
< count
; i
++) {
932 if (!mask
|| mask
[i
]) {
933 dst
[i
* 4 + 0] = val0
;
934 dst
[i
* 4 + 1] = val1
;
935 dst
[i
* 4 + 2] = val2
;
936 dst
[i
* 4 + 3] = val3
;
944 put_values_ushort4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
945 const GLint x
[], const GLint y
[], const void *values
,
948 const GLushort
*src
= (const GLushort
*) values
;
950 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
|| rb
->DataType
== GL_SHORT
);
951 for (i
= 0; i
< count
; i
++) {
952 if (!mask
|| mask
[i
]) {
954 ((GLushort
*) rb
->Data
) + 4 * (y
[i
] * rb
->RowStride
+ x
[i
]);
955 dst
[0] = src
[i
* 4 + 0];
956 dst
[1] = src
[i
* 4 + 1];
957 dst
[2] = src
[i
* 4 + 2];
958 dst
[3] = src
[i
* 4 + 3];
965 put_mono_values_ushort4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
966 GLuint count
, const GLint x
[], const GLint y
[],
967 const void *value
, const GLubyte
*mask
)
969 const GLushort val0
= ((const GLushort
*) value
)[0];
970 const GLushort val1
= ((const GLushort
*) value
)[1];
971 const GLushort val2
= ((const GLushort
*) value
)[2];
972 const GLushort val3
= ((const GLushort
*) value
)[3];
974 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
|| rb
->DataType
== GL_SHORT
);
975 for (i
= 0; i
< count
; i
++) {
976 if (!mask
|| mask
[i
]) {
977 GLushort
*dst
= ((GLushort
*) rb
->Data
) +
978 4 * (y
[i
] * rb
->RowStride
+ x
[i
]);
987 /**********************************************************************
988 * Functions for MESA_FORMAT_R8.
991 get_row_r8(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
992 GLint x
, GLint y
, void *values
)
994 const GLubyte
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
995 GLuint
*dst
= values
;
998 for (i
= 0; i
< count
; i
++) {
999 dst
[i
] = 0xff000000 | src
[i
];
1004 get_values_r8(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
1005 const GLint x
[], const GLint y
[], void *values
)
1007 GLuint
*dst
= (GLuint
*) values
;
1010 for (i
= 0; i
< count
; i
++) {
1011 const GLubyte
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
1012 dst
[i
] = 0xff000000 | *src
;
1016 /**********************************************************************
1017 * Functions for MESA_FORMAT_RG88.
1020 get_row_rg88(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
1021 GLint x
, GLint y
, void *values
)
1023 const GLushort
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
1024 GLuint
*dst
= values
;
1027 for (i
= 0; i
< count
; i
++) {
1028 dst
[i
] = 0xff000000 | src
[i
];
1033 get_values_rg88(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1034 GLuint count
, const GLint x
[], const GLint y
[], void *values
)
1036 GLuint
*dst
= (GLuint
*) values
;
1039 for (i
= 0; i
< count
; i
++) {
1040 const GLshort
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
1041 dst
[i
] = 0xff000000 | *src
;
1045 /**********************************************************************
1046 * Functions for MESA_FORMAT_R16.
1049 get_row_r16(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
1050 GLint x
, GLint y
, void *values
)
1052 const GLushort
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
1053 GLushort
*dst
= values
;
1056 for (i
= 0; i
< count
; i
++) {
1057 dst
[i
* 4 + RCOMP
] = src
[i
];
1058 dst
[i
* 4 + GCOMP
] = 0;
1059 dst
[i
* 4 + BCOMP
] = 0;
1060 dst
[i
* 4 + ACOMP
] = 0xffff;
1065 get_values_r16(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
1066 const GLint x
[], const GLint y
[], void *values
)
1068 GLushort
*dst
= values
;
1071 for (i
= 0; i
< count
; i
++) {
1072 const GLushort
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
1073 dst
[i
* 4 + RCOMP
] = *src
;
1074 dst
[i
* 4 + GCOMP
] = 0;
1075 dst
[i
* 4 + BCOMP
] = 0;
1076 dst
[i
* 4 + ACOMP
] = 0xffff;
1080 /**********************************************************************
1081 * Functions for MESA_FORMAT_RG1616.
1084 get_row_rg1616(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
1085 GLint x
, GLint y
, void *values
)
1087 const GLushort
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
1088 GLushort
*dst
= values
;
1091 for (i
= 0; i
< count
; i
++) {
1092 dst
[i
* 4 + RCOMP
] = src
[i
* 2];
1093 dst
[i
* 4 + GCOMP
] = src
[i
* 2 + 1];
1094 dst
[i
* 4 + BCOMP
] = 0;
1095 dst
[i
* 4 + ACOMP
] = 0xffff;
1100 get_values_rg1616(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1101 GLuint count
, const GLint x
[], const GLint y
[], void *values
)
1103 GLushort
*dst
= values
;
1106 for (i
= 0; i
< count
; i
++) {
1107 const GLshort
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
1108 dst
[i
* 4 + RCOMP
] = src
[0];
1109 dst
[i
* 4 + GCOMP
] = src
[1];
1110 dst
[i
* 4 + BCOMP
] = 0;
1111 dst
[i
* 4 + ACOMP
] = 0xffff;
1115 /**********************************************************************
1116 * Functions for MESA_FORMAT_INTENSITY_FLOAT32.
1119 get_row_i_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1120 GLuint count
, GLint x
, GLint y
, void *values
)
1122 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
1123 GLfloat
*dst
= values
;
1126 for (i
= 0; i
< count
; i
++) {
1127 dst
[i
* 4 + RCOMP
] =
1128 dst
[i
* 4 + GCOMP
] =
1129 dst
[i
* 4 + BCOMP
] =
1130 dst
[i
* 4 + ACOMP
] = src
[i
];
1135 get_values_i_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1136 GLuint count
, const GLint x
[], const GLint y
[],
1139 GLfloat
*dst
= values
;
1142 for (i
= 0; i
< count
; i
++) {
1143 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
1144 dst
[i
* 4 + RCOMP
] =
1145 dst
[i
* 4 + GCOMP
] =
1146 dst
[i
* 4 + BCOMP
] =
1147 dst
[i
* 4 + ACOMP
] = src
[0];
1151 /**********************************************************************
1152 * Functions for MESA_FORMAT_LUMINANCE_FLOAT32.
1155 get_row_l_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1156 GLuint count
, GLint x
, GLint y
, void *values
)
1158 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
1159 GLfloat
*dst
= values
;
1162 for (i
= 0; i
< count
; i
++) {
1163 dst
[i
* 4 + RCOMP
] =
1164 dst
[i
* 4 + GCOMP
] =
1165 dst
[i
* 4 + BCOMP
] = src
[i
];
1166 dst
[i
* 4 + ACOMP
] = 1.0;
1171 get_values_l_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1172 GLuint count
, const GLint x
[], const GLint y
[],
1175 GLfloat
*dst
= values
;
1178 for (i
= 0; i
< count
; i
++) {
1179 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
1180 dst
[i
* 4 + RCOMP
] =
1181 dst
[i
* 4 + GCOMP
] =
1182 dst
[i
* 4 + BCOMP
] = src
[0];
1183 dst
[i
* 4 + ACOMP
] = 1.0;
1187 /**********************************************************************
1188 * Functions for MESA_FORMAT_ALPHA_FLOAT32.
1191 get_row_a_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1192 GLuint count
, GLint x
, GLint y
, void *values
)
1194 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
1195 GLfloat
*dst
= values
;
1198 for (i
= 0; i
< count
; i
++) {
1199 dst
[i
* 4 + RCOMP
] = 0.0;
1200 dst
[i
* 4 + GCOMP
] = 0.0;
1201 dst
[i
* 4 + BCOMP
] = 0.0;
1202 dst
[i
* 4 + ACOMP
] = src
[i
];
1207 get_values_a_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1208 GLuint count
, const GLint x
[], const GLint y
[],
1211 GLfloat
*dst
= values
;
1214 for (i
= 0; i
< count
; i
++) {
1215 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
1216 dst
[i
* 4 + RCOMP
] = 0.0;
1217 dst
[i
* 4 + GCOMP
] = 0.0;
1218 dst
[i
* 4 + BCOMP
] = 0.0;
1219 dst
[i
* 4 + ACOMP
] = src
[0];
1224 put_row_a_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1225 GLuint count
, GLint x
, GLint y
,
1226 const void *values
, const GLubyte
*mask
)
1228 float *dst
= rb
->GetPointer(ctx
, rb
, x
, y
);
1229 const float *src
= values
;
1233 for (i
= 0; i
< count
; i
++) {
1235 dst
[i
] = src
[i
* 4 + ACOMP
];
1240 for (i
= 0; i
< count
; i
++) {
1241 dst
[i
] = src
[i
* 4 + ACOMP
];
1247 put_mono_row_a_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1248 GLuint count
, GLint x
, GLint y
,
1249 const void *value
, const GLubyte
*mask
)
1251 float *dst
= rb
->GetPointer(ctx
, rb
, x
, y
);
1252 const float *src
= value
;
1256 for (i
= 0; i
< count
; i
++) {
1258 dst
[i
] = src
[ACOMP
];
1263 for (i
= 0; i
< count
; i
++) {
1264 dst
[i
] = src
[ACOMP
];
1270 put_values_a_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1271 GLuint count
, const GLint x
[], const GLint y
[],
1272 const void *values
, const GLubyte
*mask
)
1274 const float *src
= values
;
1277 for (i
= 0; i
< count
; i
++) {
1278 if (!mask
|| mask
[i
]) {
1279 float *dst
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
1281 *dst
= src
[i
* 4 + ACOMP
];
1287 put_mono_values_a_float32(struct gl_context
*ctx
,
1288 struct gl_renderbuffer
*rb
,
1289 GLuint count
, const GLint x
[], const GLint y
[],
1290 const void *value
, const GLubyte
*mask
)
1292 const float *src
= value
;
1295 for (i
= 0; i
< count
; i
++) {
1296 if (!mask
|| mask
[i
]) {
1297 float *dst
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
1303 /**********************************************************************
1304 * Functions for MESA_FORMAT_R_FLOAT32.
1307 get_row_r_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1308 GLuint count
, GLint x
, GLint y
, void *values
)
1310 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
1311 GLfloat
*dst
= values
;
1314 for (i
= 0; i
< count
; i
++) {
1315 dst
[i
* 4 + RCOMP
] = src
[i
];
1316 dst
[i
* 4 + GCOMP
] = 0.0;
1317 dst
[i
* 4 + BCOMP
] = 0.0;
1318 dst
[i
* 4 + ACOMP
] = 1.0;
1323 get_values_r_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1324 GLuint count
, const GLint x
[], const GLint y
[],
1327 GLfloat
*dst
= values
;
1330 for (i
= 0; i
< count
; i
++) {
1331 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
1332 dst
[i
* 4 + RCOMP
] = src
[0];
1333 dst
[i
* 4 + GCOMP
] = 0.0;
1334 dst
[i
* 4 + BCOMP
] = 0.0;
1335 dst
[i
* 4 + ACOMP
] = 1.0;
1339 /**********************************************************************
1340 * Functions for MESA_FORMAT_RG_FLOAT32.
1343 get_row_rg_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1344 GLuint count
, GLint x
, GLint y
, void *values
)
1346 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
1347 GLfloat
*dst
= values
;
1350 for (i
= 0; i
< count
; i
++) {
1351 dst
[i
* 4 + RCOMP
] = src
[i
* 2 + 0];
1352 dst
[i
* 4 + GCOMP
] = src
[i
* 2 + 1];
1353 dst
[i
* 4 + BCOMP
] = 0.0;
1354 dst
[i
* 4 + ACOMP
] = 1.0;
1359 get_values_rg_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1360 GLuint count
, const GLint x
[], const GLint y
[],
1363 GLfloat
*dst
= values
;
1366 for (i
= 0; i
< count
; i
++) {
1367 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
1368 dst
[i
* 4 + RCOMP
] = src
[0];
1369 dst
[i
* 4 + GCOMP
] = src
[1];
1370 dst
[i
* 4 + BCOMP
] = 0.0;
1371 dst
[i
* 4 + ACOMP
] = 1.0;
1376 * This is the default software fallback for gl_renderbuffer's span
1379 * The assumptions are that rb->Data will be a pointer to (0,0), that pixels
1380 * are packed in the type of rb->Format, and that subsequent rows appear
1381 * rb->RowStride pixels later.
1384 _mesa_set_renderbuffer_accessors(struct gl_renderbuffer
*rb
)
1386 rb
->GetPointer
= get_pointer_generic
;
1387 rb
->GetRow
= get_row_generic
;
1389 switch (rb
->Format
) {
1390 case MESA_FORMAT_RGB888
:
1391 rb
->DataType
= GL_UNSIGNED_BYTE
;
1392 rb
->GetPointer
= get_pointer_ubyte3
;
1393 rb
->GetRow
= get_row_ubyte3
;
1394 rb
->GetValues
= get_values_ubyte3
;
1395 rb
->PutRow
= put_row_ubyte3
;
1396 rb
->PutRowRGB
= put_row_rgb_ubyte3
;
1397 rb
->PutMonoRow
= put_mono_row_ubyte3
;
1398 rb
->PutValues
= put_values_ubyte3
;
1399 rb
->PutMonoValues
= put_mono_values_ubyte3
;
1402 case MESA_FORMAT_RGBA8888
:
1403 rb
->DataType
= GL_UNSIGNED_BYTE
;
1404 rb
->GetValues
= get_values_ubyte4
;
1405 rb
->PutRow
= put_row_ubyte4
;
1406 rb
->PutRowRGB
= put_row_rgb_ubyte4
;
1407 rb
->PutMonoRow
= put_mono_row_ubyte4
;
1408 rb
->PutValues
= put_values_ubyte4
;
1409 rb
->PutMonoValues
= put_mono_values_ubyte4
;
1412 case MESA_FORMAT_R8
:
1413 rb
->DataType
= GL_UNSIGNED_BYTE
;
1414 rb
->GetValues
= get_values_r8
;
1415 rb
->GetRow
= get_row_r8
;
1416 rb
->PutRow
= put_row_generic
;
1417 rb
->PutRowRGB
= put_row_generic
;
1418 rb
->PutMonoRow
= put_mono_row_generic
;
1419 rb
->PutValues
= put_values_generic
;
1420 rb
->PutMonoValues
= put_mono_values_generic
;
1423 case MESA_FORMAT_RG88
:
1424 rb
->DataType
= GL_UNSIGNED_BYTE
;
1425 rb
->GetValues
= get_values_rg88
;
1426 rb
->GetRow
= get_row_rg88
;
1427 rb
->PutRow
= put_row_generic
;
1428 rb
->PutRowRGB
= put_row_generic
;
1429 rb
->PutMonoRow
= put_mono_row_generic
;
1430 rb
->PutValues
= put_values_generic
;
1431 rb
->PutMonoValues
= put_mono_values_generic
;
1434 case MESA_FORMAT_R16
:
1435 rb
->DataType
= GL_UNSIGNED_SHORT
;
1436 rb
->GetValues
= get_values_r16
;
1437 rb
->GetRow
= get_row_r16
;
1438 rb
->PutRow
= put_row_generic
;
1439 rb
->PutRowRGB
= put_row_generic
;
1440 rb
->PutMonoRow
= put_mono_row_generic
;
1441 rb
->PutValues
= put_values_generic
;
1442 rb
->PutMonoValues
= put_mono_values_generic
;
1445 case MESA_FORMAT_RG1616
:
1446 rb
->DataType
= GL_UNSIGNED_SHORT
;
1447 rb
->GetValues
= get_values_rg1616
;
1448 rb
->GetRow
= get_row_rg1616
;
1449 rb
->PutRow
= put_row_generic
;
1450 rb
->PutRowRGB
= put_row_generic
;
1451 rb
->PutMonoRow
= put_mono_row_generic
;
1452 rb
->PutValues
= put_values_generic
;
1453 rb
->PutMonoValues
= put_mono_values_generic
;
1456 case MESA_FORMAT_SIGNED_RGBA_16
:
1457 rb
->DataType
= GL_SHORT
;
1458 rb
->GetValues
= get_values_ushort4
;
1459 rb
->PutRow
= put_row_ushort4
;
1460 rb
->PutRowRGB
= put_row_rgb_ushort4
;
1461 rb
->PutMonoRow
= put_mono_row_ushort4
;
1462 rb
->PutValues
= put_values_ushort4
;
1463 rb
->PutMonoValues
= put_mono_values_ushort4
;
1467 case MESA_FORMAT_A8
:
1468 rb
->DataType
= GL_UNSIGNED_BYTE
;
1469 rb
->GetValues
= get_values_alpha8
;
1470 rb
->PutRow
= put_row_alpha8
;
1471 rb
->PutRowRGB
= NULL
;
1472 rb
->PutMonoRow
= put_mono_row_alpha8
;
1473 rb
->PutValues
= put_values_alpha8
;
1474 rb
->PutMonoValues
= put_mono_values_alpha8
;
1478 case MESA_FORMAT_S8
:
1479 rb
->DataType
= GL_UNSIGNED_BYTE
;
1480 rb
->GetValues
= get_values_ubyte
;
1481 rb
->PutRow
= put_row_ubyte
;
1482 rb
->PutRowRGB
= NULL
;
1483 rb
->PutMonoRow
= put_mono_row_ubyte
;
1484 rb
->PutValues
= put_values_ubyte
;
1485 rb
->PutMonoValues
= put_mono_values_ubyte
;
1488 case MESA_FORMAT_Z16
:
1489 rb
->DataType
= GL_UNSIGNED_SHORT
;
1490 rb
->GetValues
= get_values_ushort
;
1491 rb
->PutRow
= put_row_ushort
;
1492 rb
->PutRowRGB
= NULL
;
1493 rb
->PutMonoRow
= put_mono_row_ushort
;
1494 rb
->PutValues
= put_values_ushort
;
1495 rb
->PutMonoValues
= put_mono_values_ushort
;
1498 case MESA_FORMAT_Z32
:
1499 case MESA_FORMAT_X8_Z24
:
1500 case MESA_FORMAT_Z24_X8
:
1501 rb
->DataType
= GL_UNSIGNED_INT
;
1502 rb
->GetValues
= get_values_uint
;
1503 rb
->PutRow
= put_row_uint
;
1504 rb
->PutRowRGB
= NULL
;
1505 rb
->PutMonoRow
= put_mono_row_uint
;
1506 rb
->PutValues
= put_values_uint
;
1507 rb
->PutMonoValues
= put_mono_values_uint
;
1510 case MESA_FORMAT_Z24_S8
:
1511 case MESA_FORMAT_S8_Z24
:
1512 rb
->DataType
= GL_UNSIGNED_INT_24_8_EXT
;
1513 rb
->GetValues
= get_values_uint
;
1514 rb
->PutRow
= put_row_uint
;
1515 rb
->PutRowRGB
= NULL
;
1516 rb
->PutMonoRow
= put_mono_row_uint
;
1517 rb
->PutValues
= put_values_uint
;
1518 rb
->PutMonoValues
= put_mono_values_uint
;
1521 case MESA_FORMAT_RGBA_FLOAT32
:
1522 rb
->GetRow
= get_row_generic
;
1523 rb
->GetValues
= get_values_generic
;
1524 rb
->PutRow
= put_row_generic
;
1525 rb
->PutRowRGB
= NULL
;
1526 rb
->PutMonoRow
= put_mono_row_generic
;
1527 rb
->PutValues
= put_values_generic
;
1528 rb
->PutMonoValues
= put_mono_values_generic
;
1531 case MESA_FORMAT_INTENSITY_FLOAT32
:
1532 rb
->GetRow
= get_row_i_float32
;
1533 rb
->GetValues
= get_values_i_float32
;
1534 rb
->PutRow
= put_row_generic
;
1535 rb
->PutRowRGB
= NULL
;
1536 rb
->PutMonoRow
= put_mono_row_generic
;
1537 rb
->PutValues
= put_values_generic
;
1538 rb
->PutMonoValues
= put_mono_values_generic
;
1541 case MESA_FORMAT_LUMINANCE_FLOAT32
:
1542 rb
->GetRow
= get_row_l_float32
;
1543 rb
->GetValues
= get_values_l_float32
;
1544 rb
->PutRow
= put_row_generic
;
1545 rb
->PutRowRGB
= NULL
;
1546 rb
->PutMonoRow
= put_mono_row_generic
;
1547 rb
->PutValues
= put_values_generic
;
1548 rb
->PutMonoValues
= put_mono_values_generic
;
1551 case MESA_FORMAT_ALPHA_FLOAT32
:
1552 rb
->GetRow
= get_row_a_float32
;
1553 rb
->GetValues
= get_values_a_float32
;
1554 rb
->PutRow
= put_row_a_float32
;
1555 rb
->PutRowRGB
= NULL
;
1556 rb
->PutMonoRow
= put_mono_row_a_float32
;
1557 rb
->PutValues
= put_values_a_float32
;
1558 rb
->PutMonoValues
= put_mono_values_a_float32
;
1561 case MESA_FORMAT_RG_FLOAT32
:
1562 rb
->GetRow
= get_row_rg_float32
;
1563 rb
->GetValues
= get_values_rg_float32
;
1564 rb
->PutRow
= put_row_generic
;
1565 rb
->PutRowRGB
= NULL
;
1566 rb
->PutMonoRow
= put_mono_row_generic
;
1567 rb
->PutValues
= put_values_generic
;
1568 rb
->PutMonoValues
= put_mono_values_generic
;
1571 case MESA_FORMAT_R_FLOAT32
:
1572 rb
->GetRow
= get_row_r_float32
;
1573 rb
->GetValues
= get_values_r_float32
;
1574 rb
->PutRow
= put_row_generic
;
1575 rb
->PutRowRGB
= NULL
;
1576 rb
->PutMonoRow
= put_mono_row_generic
;
1577 rb
->PutValues
= put_values_generic
;
1578 rb
->PutMonoValues
= put_mono_values_generic
;
1587 * This is a software fallback for the gl_renderbuffer->AllocStorage
1589 * Device drivers will typically override this function for the buffers
1590 * which it manages (typically color buffers, Z and stencil).
1591 * Other buffers (like software accumulation and aux buffers) which the driver
1592 * doesn't manage can be handled with this function.
1594 * This one multi-purpose function can allocate stencil, depth, accum, color
1595 * or color-index buffers!
1597 * This function also plugs in the appropriate GetPointer, Get/PutRow and
1598 * Get/PutValues functions.
1601 _mesa_soft_renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1602 GLenum internalFormat
,
1603 GLuint width
, GLuint height
)
1605 switch (internalFormat
) {
1614 rb
->Format
= MESA_FORMAT_RGB888
;
1625 rb
->Format
= MESA_FORMAT_RGBA8888
;
1628 case GL_RGBA16_SNORM
:
1629 /* for accum buffer */
1630 rb
->Format
= MESA_FORMAT_SIGNED_RGBA_16
;
1634 rb
->Format
= MESA_FORMAT_A8
;
1637 case GL_STENCIL_INDEX
:
1638 case GL_STENCIL_INDEX1_EXT
:
1639 case GL_STENCIL_INDEX4_EXT
:
1640 case GL_STENCIL_INDEX8_EXT
:
1641 case GL_STENCIL_INDEX16_EXT
:
1642 rb
->Format
= MESA_FORMAT_S8
;
1644 case GL_DEPTH_COMPONENT
:
1645 case GL_DEPTH_COMPONENT16
:
1646 rb
->Format
= MESA_FORMAT_Z16
;
1648 case GL_DEPTH_COMPONENT24
:
1649 rb
->Format
= MESA_FORMAT_X8_Z24
;
1651 case GL_DEPTH_COMPONENT32
:
1652 rb
->Format
= MESA_FORMAT_Z32
;
1654 case GL_DEPTH_STENCIL_EXT
:
1655 case GL_DEPTH24_STENCIL8_EXT
:
1656 rb
->Format
= MESA_FORMAT_Z24_S8
;
1659 /* unsupported format */
1663 _mesa_set_renderbuffer_accessors(rb
);
1665 ASSERT(rb
->DataType
);
1666 ASSERT(rb
->GetPointer
);
1668 ASSERT(rb
->GetValues
);
1670 ASSERT(rb
->PutMonoRow
);
1671 ASSERT(rb
->PutValues
);
1672 ASSERT(rb
->PutMonoValues
);
1674 /* free old buffer storage */
1680 rb
->RowStride
= width
;
1682 if (width
> 0 && height
> 0) {
1683 /* allocate new buffer storage */
1684 rb
->Data
= malloc(width
* height
* _mesa_get_format_bytes(rb
->Format
));
1686 if (rb
->Data
== NULL
) {
1690 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
1691 "software renderbuffer allocation (%d x %d x %d)",
1692 width
, height
, _mesa_get_format_bytes(rb
->Format
));
1698 rb
->Height
= height
;
1699 rb
->_BaseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
1701 if (rb
->Name
== 0 &&
1702 internalFormat
== GL_RGBA16_SNORM
&&
1703 rb
->_BaseFormat
== 0) {
1704 /* NOTE: This is a special case just for accumulation buffers.
1705 * This is a very limited use case- there's no snorm texturing or
1706 * rendering going on.
1708 rb
->_BaseFormat
= GL_RGBA
;
1711 /* the internalFormat should have been error checked long ago */
1712 ASSERT(rb
->_BaseFormat
);
1720 /**********************************************************************/
1721 /**********************************************************************/
1722 /**********************************************************************/
1726 * Here we utilize the gl_renderbuffer->Wrapper field to put an alpha
1727 * buffer wrapper around an existing RGB renderbuffer (hw or sw).
1729 * When PutRow is called (for example), we store the alpha values in
1730 * this buffer, then pass on the PutRow call to the wrapped RGB
1736 alloc_storage_alpha8(struct gl_context
*ctx
, struct gl_renderbuffer
*arb
,
1737 GLenum internalFormat
, GLuint width
, GLuint height
)
1739 ASSERT(arb
!= arb
->Wrapped
);
1740 ASSERT(arb
->Format
== MESA_FORMAT_A8
);
1742 /* first, pass the call to the wrapped RGB buffer */
1743 if (!arb
->Wrapped
->AllocStorage(ctx
, arb
->Wrapped
, internalFormat
,
1748 /* next, resize my alpha buffer */
1753 arb
->Data
= malloc(width
* height
* sizeof(GLubyte
));
1754 if (arb
->Data
== NULL
) {
1757 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "software alpha buffer allocation");
1762 arb
->Height
= height
;
1763 arb
->RowStride
= width
;
1770 * Delete an alpha_renderbuffer object, as well as the wrapped RGB buffer.
1773 delete_renderbuffer_alpha8(struct gl_renderbuffer
*arb
)
1778 ASSERT(arb
->Wrapped
);
1779 ASSERT(arb
!= arb
->Wrapped
);
1780 arb
->Wrapped
->Delete(arb
->Wrapped
);
1781 arb
->Wrapped
= NULL
;
1787 get_pointer_alpha8(struct gl_context
*ctx
, struct gl_renderbuffer
*arb
,
1790 return NULL
; /* don't allow direct access! */
1795 get_row_alpha8(struct gl_context
*ctx
, struct gl_renderbuffer
*arb
, GLuint count
,
1796 GLint x
, GLint y
, void *values
)
1798 /* NOTE: 'values' is RGBA format! */
1799 const GLubyte
*src
= (const GLubyte
*) arb
->Data
+ y
* arb
->RowStride
+ x
;
1800 GLubyte
*dst
= (GLubyte
*) values
;
1802 ASSERT(arb
!= arb
->Wrapped
);
1803 ASSERT(arb
->DataType
== GL_UNSIGNED_BYTE
);
1804 /* first, pass the call to the wrapped RGB buffer */
1805 arb
->Wrapped
->GetRow(ctx
, arb
->Wrapped
, count
, x
, y
, values
);
1806 /* second, fill in alpha values from this buffer! */
1807 for (i
= 0; i
< count
; i
++) {
1808 dst
[i
* 4 + 3] = src
[i
];
1814 get_values_alpha8(struct gl_context
*ctx
, struct gl_renderbuffer
*arb
, GLuint count
,
1815 const GLint x
[], const GLint y
[], void *values
)
1817 GLubyte
*dst
= (GLubyte
*) values
;
1819 ASSERT(arb
!= arb
->Wrapped
);
1820 ASSERT(arb
->DataType
== GL_UNSIGNED_BYTE
);
1821 /* first, pass the call to the wrapped RGB buffer */
1822 arb
->Wrapped
->GetValues(ctx
, arb
->Wrapped
, count
, x
, y
, values
);
1823 /* second, fill in alpha values from this buffer! */
1824 for (i
= 0; i
< count
; i
++) {
1825 const GLubyte
*src
= (GLubyte
*) arb
->Data
+ y
[i
] * arb
->RowStride
+ x
[i
];
1826 dst
[i
* 4 + 3] = *src
;
1832 put_row_alpha8(struct gl_context
*ctx
, struct gl_renderbuffer
*arb
, GLuint count
,
1833 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
1835 const GLubyte
*src
= (const GLubyte
*) values
;
1836 GLubyte
*dst
= (GLubyte
*) arb
->Data
+ y
* arb
->RowStride
+ x
;
1838 ASSERT(arb
!= arb
->Wrapped
);
1839 ASSERT(arb
->DataType
== GL_UNSIGNED_BYTE
);
1840 /* first, pass the call to the wrapped RGB buffer */
1841 arb
->Wrapped
->PutRow(ctx
, arb
->Wrapped
, count
, x
, y
, values
, mask
);
1842 /* second, store alpha in our buffer */
1843 for (i
= 0; i
< count
; i
++) {
1844 if (!mask
|| mask
[i
]) {
1845 dst
[i
] = src
[i
* 4 + 3];
1852 put_row_rgb_alpha8(struct gl_context
*ctx
, struct gl_renderbuffer
*arb
, GLuint count
,
1853 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
1855 const GLubyte
*src
= (const GLubyte
*) values
;
1856 GLubyte
*dst
= (GLubyte
*) arb
->Data
+ y
* arb
->RowStride
+ x
;
1858 ASSERT(arb
!= arb
->Wrapped
);
1859 ASSERT(arb
->DataType
== GL_UNSIGNED_BYTE
);
1860 /* first, pass the call to the wrapped RGB buffer */
1861 arb
->Wrapped
->PutRowRGB(ctx
, arb
->Wrapped
, count
, x
, y
, values
, mask
);
1862 /* second, store alpha in our buffer */
1863 for (i
= 0; i
< count
; i
++) {
1864 if (!mask
|| mask
[i
]) {
1865 dst
[i
] = src
[i
* 4 + 3];
1872 put_mono_row_alpha8(struct gl_context
*ctx
, struct gl_renderbuffer
*arb
, GLuint count
,
1873 GLint x
, GLint y
, const void *value
, const GLubyte
*mask
)
1875 const GLubyte val
= ((const GLubyte
*) value
)[3];
1876 GLubyte
*dst
= (GLubyte
*) arb
->Data
+ y
* arb
->RowStride
+ x
;
1877 ASSERT(arb
!= arb
->Wrapped
);
1878 ASSERT(arb
->DataType
== GL_UNSIGNED_BYTE
);
1879 /* first, pass the call to the wrapped RGB buffer */
1880 arb
->Wrapped
->PutMonoRow(ctx
, arb
->Wrapped
, count
, x
, y
, value
, mask
);
1881 /* second, store alpha in our buffer */
1884 for (i
= 0; i
< count
; i
++) {
1891 memset(dst
, val
, count
);
1897 put_values_alpha8(struct gl_context
*ctx
, struct gl_renderbuffer
*arb
, GLuint count
,
1898 const GLint x
[], const GLint y
[],
1899 const void *values
, const GLubyte
*mask
)
1901 const GLubyte
*src
= (const GLubyte
*) values
;
1903 ASSERT(arb
!= arb
->Wrapped
);
1904 ASSERT(arb
->DataType
== GL_UNSIGNED_BYTE
);
1905 /* first, pass the call to the wrapped RGB buffer */
1906 arb
->Wrapped
->PutValues(ctx
, arb
->Wrapped
, count
, x
, y
, values
, mask
);
1907 /* second, store alpha in our buffer */
1908 for (i
= 0; i
< count
; i
++) {
1909 if (!mask
|| mask
[i
]) {
1910 GLubyte
*dst
= (GLubyte
*) arb
->Data
+ y
[i
] * arb
->RowStride
+ x
[i
];
1911 *dst
= src
[i
* 4 + 3];
1918 put_mono_values_alpha8(struct gl_context
*ctx
, struct gl_renderbuffer
*arb
,
1919 GLuint count
, const GLint x
[], const GLint y
[],
1920 const void *value
, const GLubyte
*mask
)
1922 const GLubyte val
= ((const GLubyte
*) value
)[3];
1924 ASSERT(arb
!= arb
->Wrapped
);
1925 ASSERT(arb
->DataType
== GL_UNSIGNED_BYTE
);
1926 /* first, pass the call to the wrapped RGB buffer */
1927 arb
->Wrapped
->PutValues(ctx
, arb
->Wrapped
, count
, x
, y
, value
, mask
);
1928 /* second, store alpha in our buffer */
1929 for (i
= 0; i
< count
; i
++) {
1930 if (!mask
|| mask
[i
]) {
1931 GLubyte
*dst
= (GLubyte
*) arb
->Data
+ y
[i
] * arb
->RowStride
+ x
[i
];
1939 copy_buffer_alpha8(struct gl_renderbuffer
* dst
, struct gl_renderbuffer
* src
)
1941 ASSERT(dst
->Format
== MESA_FORMAT_A8
);
1942 ASSERT(src
->Format
== MESA_FORMAT_A8
);
1943 ASSERT(dst
->Width
== src
->Width
);
1944 ASSERT(dst
->Height
== src
->Height
);
1945 ASSERT(dst
->RowStride
== src
->RowStride
);
1947 memcpy(dst
->Data
, src
->Data
, dst
->RowStride
* dst
->Height
* sizeof(GLubyte
));
1951 /**********************************************************************/
1952 /**********************************************************************/
1953 /**********************************************************************/
1957 * Default GetPointer routine. Always return NULL to indicate that
1958 * direct buffer access is not supported.
1961 nop_get_pointer(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLint x
, GLint y
)
1968 * Initialize the fields of a gl_renderbuffer to default values.
1971 _mesa_init_renderbuffer(struct gl_renderbuffer
*rb
, GLuint name
)
1973 _glthread_INIT_MUTEX(rb
->Mutex
);
1978 rb
->Delete
= _mesa_delete_renderbuffer
;
1980 /* The rest of these should be set later by the caller of this function or
1981 * the AllocStorage method:
1983 rb
->AllocStorage
= NULL
;
1987 rb
->InternalFormat
= GL_NONE
;
1988 rb
->Format
= MESA_FORMAT_NONE
;
1990 rb
->DataType
= GL_NONE
;
1993 /* Point back to ourself so that we don't have to check for Wrapped==NULL
1994 * all over the drivers.
1998 rb
->GetPointer
= nop_get_pointer
;
2000 rb
->GetValues
= NULL
;
2002 rb
->PutRowRGB
= NULL
;
2003 rb
->PutMonoRow
= NULL
;
2004 rb
->PutValues
= NULL
;
2005 rb
->PutMonoValues
= NULL
;
2010 * Allocate a new gl_renderbuffer object. This can be used for user-created
2011 * renderbuffers or window-system renderbuffers.
2013 struct gl_renderbuffer
*
2014 _mesa_new_renderbuffer(struct gl_context
*ctx
, GLuint name
)
2016 struct gl_renderbuffer
*rb
= CALLOC_STRUCT(gl_renderbuffer
);
2018 _mesa_init_renderbuffer(rb
, name
);
2025 * Delete a gl_framebuffer.
2026 * This is the default function for renderbuffer->Delete().
2029 _mesa_delete_renderbuffer(struct gl_renderbuffer
*rb
)
2039 * Allocate a software-based renderbuffer. This is called via the
2040 * ctx->Driver.NewRenderbuffer() function when the user creates a new
2042 * This would not be used for hardware-based renderbuffers.
2044 struct gl_renderbuffer
*
2045 _mesa_new_soft_renderbuffer(struct gl_context
*ctx
, GLuint name
)
2047 struct gl_renderbuffer
*rb
= _mesa_new_renderbuffer(ctx
, name
);
2049 rb
->AllocStorage
= _mesa_soft_renderbuffer_storage
;
2050 /* Normally, one would setup the PutRow, GetRow, etc functions here.
2051 * But we're doing that in the _mesa_soft_renderbuffer_storage() function
2060 * Add software-based color renderbuffers to the given framebuffer.
2061 * This is a helper routine for device drivers when creating a
2062 * window system framebuffer (not a user-created render/framebuffer).
2063 * Once this function is called, you can basically forget about this
2064 * renderbuffer; core Mesa will handle all the buffer management and
2068 _mesa_add_color_renderbuffers(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
2069 GLuint rgbBits
, GLuint alphaBits
,
2070 GLboolean frontLeft
, GLboolean backLeft
,
2071 GLboolean frontRight
, GLboolean backRight
)
2075 if (rgbBits
> 16 || alphaBits
> 16) {
2077 "Unsupported bit depth in _mesa_add_color_renderbuffers");
2081 assert(MAX_COLOR_ATTACHMENTS
>= 4);
2083 for (b
= BUFFER_FRONT_LEFT
; b
<= BUFFER_BACK_RIGHT
; b
++) {
2084 struct gl_renderbuffer
*rb
;
2086 if (b
== BUFFER_FRONT_LEFT
&& !frontLeft
)
2088 else if (b
== BUFFER_BACK_LEFT
&& !backLeft
)
2090 else if (b
== BUFFER_FRONT_RIGHT
&& !frontRight
)
2092 else if (b
== BUFFER_BACK_RIGHT
&& !backRight
)
2095 assert(fb
->Attachment
[b
].Renderbuffer
== NULL
);
2097 rb
= _mesa_new_renderbuffer(ctx
, 0);
2099 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating color buffer");
2105 rb
->Format
= MESA_FORMAT_RGBA8888
;
2107 rb
->Format
= MESA_FORMAT_RGB888
;
2110 assert(rgbBits
<= 16);
2111 rb
->Format
= MESA_FORMAT_NONE
; /*XXX RGBA16;*/
2113 rb
->InternalFormat
= GL_RGBA
;
2115 rb
->AllocStorage
= _mesa_soft_renderbuffer_storage
;
2116 _mesa_add_renderbuffer(fb
, b
, rb
);
2124 * Add software-based alpha renderbuffers to the given framebuffer.
2125 * This is a helper routine for device drivers when creating a
2126 * window system framebuffer (not a user-created render/framebuffer).
2127 * Once this function is called, you can basically forget about this
2128 * renderbuffer; core Mesa will handle all the buffer management and
2132 _mesa_add_alpha_renderbuffers(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
2134 GLboolean frontLeft
, GLboolean backLeft
,
2135 GLboolean frontRight
, GLboolean backRight
)
2139 /* for window system framebuffers only! */
2140 assert(fb
->Name
== 0);
2142 if (alphaBits
> 8) {
2144 "Unsupported bit depth in _mesa_add_alpha_renderbuffers");
2148 assert(MAX_COLOR_ATTACHMENTS
>= 4);
2150 /* Wrap each of the RGB color buffers with an alpha renderbuffer.
2152 for (b
= BUFFER_FRONT_LEFT
; b
<= BUFFER_BACK_RIGHT
; b
++) {
2153 struct gl_renderbuffer
*arb
;
2155 if (b
== BUFFER_FRONT_LEFT
&& !frontLeft
)
2157 else if (b
== BUFFER_BACK_LEFT
&& !backLeft
)
2159 else if (b
== BUFFER_FRONT_RIGHT
&& !frontRight
)
2161 else if (b
== BUFFER_BACK_RIGHT
&& !backRight
)
2164 /* the RGB buffer to wrap must already exist!! */
2165 assert(fb
->Attachment
[b
].Renderbuffer
);
2167 /* only GLubyte supported for now */
2168 assert(fb
->Attachment
[b
].Renderbuffer
->DataType
== GL_UNSIGNED_BYTE
);
2170 /* allocate alpha renderbuffer */
2171 arb
= _mesa_new_renderbuffer(ctx
, 0);
2173 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating alpha buffer");
2177 /* wrap the alpha renderbuffer around the RGB renderbuffer */
2178 arb
->Wrapped
= fb
->Attachment
[b
].Renderbuffer
;
2180 /* Set up my alphabuffer fields and plug in my functions.
2181 * The functions will put/get the alpha values from/to RGBA arrays
2182 * and then call the wrapped buffer's functions to handle the RGB
2185 arb
->InternalFormat
= arb
->Wrapped
->InternalFormat
;
2186 arb
->Format
= MESA_FORMAT_A8
;
2187 arb
->DataType
= arb
->Wrapped
->DataType
;
2188 arb
->AllocStorage
= alloc_storage_alpha8
;
2189 arb
->Delete
= delete_renderbuffer_alpha8
;
2190 arb
->GetPointer
= get_pointer_alpha8
;
2191 arb
->GetRow
= get_row_alpha8
;
2192 arb
->GetValues
= get_values_alpha8
;
2193 arb
->PutRow
= put_row_alpha8
;
2194 arb
->PutRowRGB
= put_row_rgb_alpha8
;
2195 arb
->PutMonoRow
= put_mono_row_alpha8
;
2196 arb
->PutValues
= put_values_alpha8
;
2197 arb
->PutMonoValues
= put_mono_values_alpha8
;
2199 /* clear the pointer to avoid assertion/sanity check failure later */
2200 fb
->Attachment
[b
].Renderbuffer
= NULL
;
2202 /* plug the alpha renderbuffer into the colorbuffer attachment */
2203 _mesa_add_renderbuffer(fb
, b
, arb
);
2211 * For framebuffers that use a software alpha channel wrapper
2212 * created by _mesa_add_alpha_renderbuffer or _mesa_add_soft_renderbuffers,
2213 * copy the back buffer alpha channel into the front buffer alpha channel.
2216 _mesa_copy_soft_alpha_renderbuffers(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2218 if (fb
->Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
&&
2219 fb
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
)
2220 copy_buffer_alpha8(fb
->Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
,
2221 fb
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
);
2224 if (fb
->Attachment
[BUFFER_FRONT_RIGHT
].Renderbuffer
&&
2225 fb
->Attachment
[BUFFER_BACK_RIGHT
].Renderbuffer
)
2226 copy_buffer_alpha8(fb
->Attachment
[BUFFER_FRONT_RIGHT
].Renderbuffer
,
2227 fb
->Attachment
[BUFFER_BACK_RIGHT
].Renderbuffer
);
2232 * Add a software-based depth renderbuffer to the given framebuffer.
2233 * This is a helper routine for device drivers when creating a
2234 * window system framebuffer (not a user-created render/framebuffer).
2235 * Once this function is called, you can basically forget about this
2236 * renderbuffer; core Mesa will handle all the buffer management and
2240 _mesa_add_depth_renderbuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
2243 struct gl_renderbuffer
*rb
;
2245 if (depthBits
> 32) {
2247 "Unsupported depthBits in _mesa_add_depth_renderbuffer");
2251 assert(fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
== NULL
);
2253 rb
= _mesa_new_renderbuffer(ctx
, 0);
2255 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating depth buffer");
2259 if (depthBits
<= 16) {
2260 rb
->Format
= MESA_FORMAT_Z16
;
2261 rb
->InternalFormat
= GL_DEPTH_COMPONENT16
;
2263 else if (depthBits
<= 24) {
2264 rb
->Format
= MESA_FORMAT_X8_Z24
;
2265 rb
->InternalFormat
= GL_DEPTH_COMPONENT24
;
2268 rb
->Format
= MESA_FORMAT_Z32
;
2269 rb
->InternalFormat
= GL_DEPTH_COMPONENT32
;
2272 rb
->AllocStorage
= _mesa_soft_renderbuffer_storage
;
2273 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, rb
);
2280 * Add a software-based stencil renderbuffer to the given framebuffer.
2281 * This is a helper routine for device drivers when creating a
2282 * window system framebuffer (not a user-created render/framebuffer).
2283 * Once this function is called, you can basically forget about this
2284 * renderbuffer; core Mesa will handle all the buffer management and
2288 _mesa_add_stencil_renderbuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
2291 struct gl_renderbuffer
*rb
;
2293 if (stencilBits
> 16) {
2295 "Unsupported stencilBits in _mesa_add_stencil_renderbuffer");
2299 assert(fb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
== NULL
);
2301 rb
= _mesa_new_renderbuffer(ctx
, 0);
2303 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating stencil buffer");
2307 assert(stencilBits
<= 8);
2308 rb
->Format
= MESA_FORMAT_S8
;
2309 rb
->InternalFormat
= GL_STENCIL_INDEX8
;
2311 rb
->AllocStorage
= _mesa_soft_renderbuffer_storage
;
2312 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, rb
);
2319 * Add a software-based accumulation renderbuffer to the given framebuffer.
2320 * This is a helper routine for device drivers when creating a
2321 * window system framebuffer (not a user-created render/framebuffer).
2322 * Once this function is called, you can basically forget about this
2323 * renderbuffer; core Mesa will handle all the buffer management and
2327 _mesa_add_accum_renderbuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
2328 GLuint redBits
, GLuint greenBits
,
2329 GLuint blueBits
, GLuint alphaBits
)
2331 struct gl_renderbuffer
*rb
;
2333 if (redBits
> 16 || greenBits
> 16 || blueBits
> 16 || alphaBits
> 16) {
2335 "Unsupported accumBits in _mesa_add_accum_renderbuffer");
2339 assert(fb
->Attachment
[BUFFER_ACCUM
].Renderbuffer
== NULL
);
2341 rb
= _mesa_new_renderbuffer(ctx
, 0);
2343 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating accum buffer");
2347 rb
->Format
= MESA_FORMAT_SIGNED_RGBA_16
;
2348 rb
->InternalFormat
= GL_RGBA16_SNORM
;
2349 rb
->AllocStorage
= _mesa_soft_renderbuffer_storage
;
2350 _mesa_add_renderbuffer(fb
, BUFFER_ACCUM
, rb
);
2358 * Add a software-based aux renderbuffer to the given framebuffer.
2359 * This is a helper routine for device drivers when creating a
2360 * window system framebuffer (not a user-created render/framebuffer).
2361 * Once this function is called, you can basically forget about this
2362 * renderbuffer; core Mesa will handle all the buffer management and
2365 * NOTE: color-index aux buffers not supported.
2368 _mesa_add_aux_renderbuffers(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
2369 GLuint colorBits
, GLuint numBuffers
)
2373 if (colorBits
> 16) {
2375 "Unsupported accumBits in _mesa_add_aux_renderbuffers");
2379 assert(numBuffers
<= MAX_AUX_BUFFERS
);
2381 for (i
= 0; i
< numBuffers
; i
++) {
2382 struct gl_renderbuffer
*rb
= _mesa_new_renderbuffer(ctx
, 0);
2384 assert(fb
->Attachment
[BUFFER_AUX0
+ i
].Renderbuffer
== NULL
);
2387 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating aux buffer");
2391 assert (colorBits
<= 8);
2392 rb
->Format
= MESA_FORMAT_RGBA8888
;
2393 rb
->InternalFormat
= GL_RGBA
;
2395 rb
->AllocStorage
= _mesa_soft_renderbuffer_storage
;
2396 _mesa_add_renderbuffer(fb
, BUFFER_AUX0
+ i
, rb
);
2403 * Create/attach software-based renderbuffers to the given framebuffer.
2404 * This is a helper routine for device drivers. Drivers can just as well
2405 * call the individual _mesa_add_*_renderbuffer() routines directly.
2408 _mesa_add_soft_renderbuffers(struct gl_framebuffer
*fb
,
2416 GLboolean frontLeft
= GL_TRUE
;
2417 GLboolean backLeft
= fb
->Visual
.doubleBufferMode
;
2418 GLboolean frontRight
= fb
->Visual
.stereoMode
;
2419 GLboolean backRight
= fb
->Visual
.stereoMode
&& fb
->Visual
.doubleBufferMode
;
2422 assert(fb
->Visual
.redBits
== fb
->Visual
.greenBits
);
2423 assert(fb
->Visual
.redBits
== fb
->Visual
.blueBits
);
2424 _mesa_add_color_renderbuffers(NULL
, fb
,
2426 fb
->Visual
.alphaBits
,
2427 frontLeft
, backLeft
,
2428 frontRight
, backRight
);
2432 assert(fb
->Visual
.depthBits
> 0);
2433 _mesa_add_depth_renderbuffer(NULL
, fb
, fb
->Visual
.depthBits
);
2437 assert(fb
->Visual
.stencilBits
> 0);
2438 _mesa_add_stencil_renderbuffer(NULL
, fb
, fb
->Visual
.stencilBits
);
2442 assert(fb
->Visual
.accumRedBits
> 0);
2443 assert(fb
->Visual
.accumGreenBits
> 0);
2444 assert(fb
->Visual
.accumBlueBits
> 0);
2445 _mesa_add_accum_renderbuffer(NULL
, fb
,
2446 fb
->Visual
.accumRedBits
,
2447 fb
->Visual
.accumGreenBits
,
2448 fb
->Visual
.accumBlueBits
,
2449 fb
->Visual
.accumAlphaBits
);
2453 assert(fb
->Visual
.numAuxBuffers
> 0);
2454 _mesa_add_aux_renderbuffers(NULL
, fb
, fb
->Visual
.redBits
,
2455 fb
->Visual
.numAuxBuffers
);
2459 assert(fb
->Visual
.alphaBits
> 0);
2460 _mesa_add_alpha_renderbuffers(NULL
, fb
, fb
->Visual
.alphaBits
,
2461 frontLeft
, backLeft
,
2462 frontRight
, backRight
);
2474 * Attach a renderbuffer to a framebuffer.
2475 * \param bufferName one of the BUFFER_x tokens
2478 _mesa_add_renderbuffer(struct gl_framebuffer
*fb
,
2479 gl_buffer_index bufferName
, struct gl_renderbuffer
*rb
)
2483 assert(bufferName
< BUFFER_COUNT
);
2485 /* There should be no previous renderbuffer on this attachment point,
2486 * with the exception of depth/stencil since the same renderbuffer may
2489 assert(bufferName
== BUFFER_DEPTH
||
2490 bufferName
== BUFFER_STENCIL
||
2491 fb
->Attachment
[bufferName
].Renderbuffer
== NULL
);
2493 /* winsys vs. user-created buffer cross check */
2501 fb
->Attachment
[bufferName
].Type
= GL_RENDERBUFFER_EXT
;
2502 fb
->Attachment
[bufferName
].Complete
= GL_TRUE
;
2503 _mesa_reference_renderbuffer(&fb
->Attachment
[bufferName
].Renderbuffer
, rb
);
2508 * Remove the named renderbuffer from the given framebuffer.
2509 * \param bufferName one of the BUFFER_x tokens
2512 _mesa_remove_renderbuffer(struct gl_framebuffer
*fb
,
2513 gl_buffer_index bufferName
)
2515 struct gl_renderbuffer
*rb
;
2517 assert(bufferName
< BUFFER_COUNT
);
2519 rb
= fb
->Attachment
[bufferName
].Renderbuffer
;
2523 _mesa_reference_renderbuffer(&rb
, NULL
);
2525 fb
->Attachment
[bufferName
].Renderbuffer
= NULL
;
2530 * Set *ptr to point to rb. If *ptr points to another renderbuffer,
2531 * dereference that buffer first. The new renderbuffer's refcount will
2532 * be incremented. The old renderbuffer's refcount will be decremented.
2533 * This is normally only called from the _mesa_reference_renderbuffer() macro
2534 * when there's a real pointer change.
2537 _mesa_reference_renderbuffer_(struct gl_renderbuffer
**ptr
,
2538 struct gl_renderbuffer
*rb
)
2541 /* Unreference the old renderbuffer */
2542 GLboolean deleteFlag
= GL_FALSE
;
2543 struct gl_renderbuffer
*oldRb
= *ptr
;
2545 _glthread_LOCK_MUTEX(oldRb
->Mutex
);
2546 ASSERT(oldRb
->RefCount
> 0);
2548 /*printf("RB DECR %p (%d) to %d\n", (void*) oldRb, oldRb->Name, oldRb->RefCount);*/
2549 deleteFlag
= (oldRb
->RefCount
== 0);
2550 _glthread_UNLOCK_MUTEX(oldRb
->Mutex
);
2553 oldRb
->Delete(oldRb
);
2561 /* reference new renderbuffer */
2562 _glthread_LOCK_MUTEX(rb
->Mutex
);
2564 /*printf("RB INCR %p (%d) to %d\n", (void*) rb, rb->Name, rb->RefCount);*/
2565 _glthread_UNLOCK_MUTEX(rb
->Mutex
);