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 software-based renderbuffers.
28 * Also, routines for reading/writing software-based renderbuffer data as
29 * ubytes, ushorts, uints, etc.
33 #include "main/glheader.h"
34 #include "main/imports.h"
35 #include "main/context.h"
36 #include "main/fbobject.h"
37 #include "main/formats.h"
38 #include "main/mtypes.h"
39 #include "main/renderbuffer.h"
40 #include "swrast/s_renderbuffer.h"
44 * Routines for get/put values in common buffer formats follow.
47 /* Returns a bytes per pixel of the DataType in the get/put span
48 * functions for at least a subset of the available combinations a
49 * renderbuffer can have.
51 * It would be nice to see gl_renderbuffer start talking about a
52 * gl_format instead of a GLenum DataType.
55 get_datatype_bytes(struct gl_renderbuffer
*rb
)
59 switch (rb
->DataType
) {
60 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
65 case GL_UNSIGNED_INT_24_8_EXT
:
68 case GL_UNSIGNED_SHORT
:
71 case GL_UNSIGNED_BYTE
:
79 switch (rb
->_BaseFormat
) {
80 case GL_DEPTH_COMPONENT
:
81 case GL_DEPTH_STENCIL
:
82 return component_size
;
84 return 4 * component_size
;
88 /* This is commonly used by most of the accessors. */
90 get_pointer_generic(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
96 return ((char *) rb
->Data
+
97 (y
* rb
->RowStride
+ x
) * _mesa_get_format_bytes(rb
->Format
));
100 /* GetRow() implementation for formats where DataType matches the rb->Format.
103 get_row_generic(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
104 GLuint count
, GLint x
, GLint y
, void *values
)
106 void *src
= rb
->GetPointer(ctx
, rb
, x
, y
);
107 memcpy(values
, src
, count
* _mesa_get_format_bytes(rb
->Format
));
110 /* Only used for float textures currently, but might also be used for
111 * RGBA8888, RGBA16, etc.
114 get_values_generic(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
115 GLuint count
, const GLint x
[], const GLint y
[], void *values
)
117 int format_bytes
= _mesa_get_format_bytes(rb
->Format
) / sizeof(GLfloat
);
120 for (i
= 0; i
< count
; i
++) {
121 const void *src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
122 char *dst
= (char *) values
+ i
* format_bytes
;
123 memcpy(dst
, src
, format_bytes
);
127 /* For the GL_RED/GL_RG/GL_RGB format/DataType combinations (and
128 * GL_LUMINANCE/GL_INTENSITY?), the Put functions are a matter of
129 * storing those initial components of the value per pixel into the
133 put_row_generic(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
134 GLuint count
, GLint x
, GLint y
,
135 const void *values
, const GLubyte
*mask
)
137 void *row
= rb
->GetPointer(ctx
, rb
, x
, y
);
138 int format_bytes
= _mesa_get_format_bytes(rb
->Format
) / sizeof(GLfloat
);
139 int datatype_bytes
= get_datatype_bytes(rb
);
143 for (i
= 0; i
< count
; i
++) {
144 char *dst
= (char *) row
+ i
* format_bytes
;
145 const char *src
= (const char *) values
+ i
* datatype_bytes
;
148 memcpy(dst
, src
, format_bytes
);
153 for (i
= 0; i
< count
; i
++) {
154 char *dst
= (char *) row
+ i
* format_bytes
;
155 const char *src
= (const char *) values
+ i
* datatype_bytes
;
156 memcpy(dst
, src
, format_bytes
);
163 put_values_generic(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
164 GLuint count
, const GLint x
[], const GLint y
[],
165 const void *values
, const GLubyte
*mask
)
167 int format_bytes
= _mesa_get_format_bytes(rb
->Format
) / sizeof(GLfloat
);
168 int datatype_bytes
= get_datatype_bytes(rb
);
171 for (i
= 0; i
< count
; i
++) {
172 if (!mask
|| mask
[i
]) {
173 void *dst
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
174 const char *src
= (const char *) values
+ i
* datatype_bytes
;
175 memcpy(dst
, src
, format_bytes
);
182 /**********************************************************************
183 * Functions for buffers of 1 X GLubyte values.
188 get_values_ubyte(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
189 const GLint x
[], const GLint y
[], void *values
)
191 GLubyte
*dst
= (GLubyte
*) values
;
193 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
194 for (i
= 0; i
< count
; i
++) {
195 const GLubyte
*src
= (GLubyte
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
202 put_row_ubyte(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
203 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
205 const GLubyte
*src
= (const GLubyte
*) values
;
206 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ y
* rb
->RowStride
+ x
;
207 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
210 for (i
= 0; i
< count
; i
++) {
217 memcpy(dst
, values
, count
* sizeof(GLubyte
));
223 put_values_ubyte(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
224 const GLint x
[], const GLint y
[],
225 const void *values
, const GLubyte
*mask
)
227 const GLubyte
*src
= (const GLubyte
*) values
;
229 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
230 for (i
= 0; i
< count
; i
++) {
231 if (!mask
|| mask
[i
]) {
232 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
239 /**********************************************************************
240 * Functions for buffers of 1 X GLushort values.
245 get_values_ushort(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
246 const GLint x
[], const GLint y
[], void *values
)
248 GLushort
*dst
= (GLushort
*) values
;
250 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
);
251 for (i
= 0; i
< count
; i
++) {
252 const GLushort
*src
= (GLushort
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
259 put_row_ushort(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
260 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
262 const GLushort
*src
= (const GLushort
*) values
;
263 GLushort
*dst
= (GLushort
*) rb
->Data
+ y
* rb
->RowStride
+ x
;
264 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
);
267 for (i
= 0; i
< count
; i
++) {
274 memcpy(dst
, src
, count
* sizeof(GLushort
));
280 put_values_ushort(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
281 const GLint x
[], const GLint y
[], const void *values
,
284 const GLushort
*src
= (const GLushort
*) values
;
286 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
);
287 for (i
= 0; i
< count
; i
++) {
288 if (!mask
|| mask
[i
]) {
289 GLushort
*dst
= (GLushort
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
296 /**********************************************************************
297 * Functions for buffers of 1 X GLuint values.
298 * Typically depth/Z or color index.
302 get_values_uint(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
303 const GLint x
[], const GLint y
[], void *values
)
305 GLuint
*dst
= (GLuint
*) values
;
307 ASSERT(rb
->DataType
== GL_UNSIGNED_INT
||
308 rb
->DataType
== GL_UNSIGNED_INT_24_8_EXT
);
309 for (i
= 0; i
< count
; i
++) {
310 const GLuint
*src
= (GLuint
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
317 put_row_uint(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
318 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
320 const GLuint
*src
= (const GLuint
*) values
;
321 GLuint
*dst
= (GLuint
*) rb
->Data
+ y
* rb
->RowStride
+ x
;
322 ASSERT(rb
->DataType
== GL_UNSIGNED_INT
||
323 rb
->DataType
== GL_UNSIGNED_INT_24_8_EXT
);
326 for (i
= 0; i
< count
; i
++) {
333 memcpy(dst
, src
, count
* sizeof(GLuint
));
339 put_values_uint(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
340 const GLint x
[], const GLint y
[], const void *values
,
343 const GLuint
*src
= (const GLuint
*) values
;
345 ASSERT(rb
->DataType
== GL_UNSIGNED_INT
||
346 rb
->DataType
== GL_UNSIGNED_INT_24_8_EXT
);
347 for (i
= 0; i
< count
; i
++) {
348 if (!mask
|| mask
[i
]) {
349 GLuint
*dst
= (GLuint
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
356 /**********************************************************************
357 * Functions for buffers of 3 X GLubyte (or GLbyte) values.
358 * Typically color buffers.
359 * NOTE: the incoming and outgoing colors are RGBA! We ignore incoming
360 * alpha values and return 255 for outgoing alpha values.
364 get_pointer_ubyte3(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
367 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
368 /* No direct access since this buffer is RGB but caller will be
369 * treating it as if it were RGBA.
376 get_row_ubyte3(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
377 GLint x
, GLint y
, void *values
)
379 const GLubyte
*src
= ((const GLubyte
*) rb
->Data
) +
380 3 * (y
* rb
->RowStride
+ x
);
381 GLubyte
*dst
= (GLubyte
*) values
;
383 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
384 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
385 for (i
= 0; i
< count
; i
++) {
386 dst
[i
* 4 + 0] = src
[i
* 3 + 0];
387 dst
[i
* 4 + 1] = src
[i
* 3 + 1];
388 dst
[i
* 4 + 2] = src
[i
* 3 + 2];
389 dst
[i
* 4 + 3] = 255;
395 get_values_ubyte3(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
396 const GLint x
[], const GLint y
[], void *values
)
398 GLubyte
*dst
= (GLubyte
*) values
;
400 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
401 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
402 for (i
= 0; i
< count
; i
++) {
404 = (GLubyte
*) rb
->Data
+ 3 * (y
[i
] * rb
->RowStride
+ x
[i
]);
405 dst
[i
* 4 + 0] = src
[0];
406 dst
[i
* 4 + 1] = src
[1];
407 dst
[i
* 4 + 2] = src
[2];
408 dst
[i
* 4 + 3] = 255;
414 put_row_ubyte3(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
415 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
417 /* note: incoming values are RGB+A! */
418 const GLubyte
*src
= (const GLubyte
*) values
;
419 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ 3 * (y
* rb
->RowStride
+ x
);
421 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
422 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
423 for (i
= 0; i
< count
; i
++) {
424 if (!mask
|| mask
[i
]) {
425 dst
[i
* 3 + 0] = src
[i
* 4 + 0];
426 dst
[i
* 3 + 1] = src
[i
* 4 + 1];
427 dst
[i
* 3 + 2] = src
[i
* 4 + 2];
434 put_values_ubyte3(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
435 const GLint x
[], const GLint y
[], const void *values
,
438 /* note: incoming values are RGB+A! */
439 const GLubyte
*src
= (const GLubyte
*) values
;
441 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
442 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
443 for (i
= 0; i
< count
; i
++) {
444 if (!mask
|| mask
[i
]) {
445 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ 3 * (y
[i
] * rb
->RowStride
+ x
[i
]);
446 dst
[0] = src
[i
* 4 + 0];
447 dst
[1] = src
[i
* 4 + 1];
448 dst
[2] = src
[i
* 4 + 2];
454 /**********************************************************************
455 * Functions for buffers of 4 X GLubyte (or GLbyte) values.
456 * Typically color buffers.
460 get_values_ubyte4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
461 const GLint x
[], const GLint y
[], void *values
)
463 /* treat 4*GLubyte as 1*GLuint */
464 GLuint
*dst
= (GLuint
*) values
;
466 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
467 ASSERT(rb
->Format
== MESA_FORMAT_RGBA8888
||
468 rb
->Format
== MESA_FORMAT_RGBA8888_REV
);
469 for (i
= 0; i
< count
; i
++) {
470 const GLuint
*src
= (GLuint
*) rb
->Data
+ (y
[i
] * rb
->RowStride
+ x
[i
]);
477 put_row_ubyte4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
478 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
480 /* treat 4*GLubyte as 1*GLuint */
481 const GLuint
*src
= (const GLuint
*) values
;
482 GLuint
*dst
= (GLuint
*) rb
->Data
+ (y
* rb
->RowStride
+ x
);
483 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
484 ASSERT(rb
->Format
== MESA_FORMAT_RGBA8888
||
485 rb
->Format
== MESA_FORMAT_RGBA8888_REV
);
488 for (i
= 0; i
< count
; i
++) {
495 memcpy(dst
, src
, 4 * count
* sizeof(GLubyte
));
501 put_values_ubyte4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
502 const GLint x
[], const GLint y
[], const void *values
,
505 /* treat 4*GLubyte as 1*GLuint */
506 const GLuint
*src
= (const GLuint
*) values
;
508 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
509 ASSERT(rb
->Format
== MESA_FORMAT_RGBA8888
||
510 rb
->Format
== MESA_FORMAT_RGBA8888_REV
);
511 for (i
= 0; i
< count
; i
++) {
512 if (!mask
|| mask
[i
]) {
513 GLuint
*dst
= (GLuint
*) rb
->Data
+ (y
[i
] * rb
->RowStride
+ x
[i
]);
520 /**********************************************************************
521 * Functions for buffers of 4 X GLushort (or GLshort) values.
522 * Typically accum buffer.
526 get_values_ushort4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
527 const GLint x
[], const GLint y
[], void *values
)
529 GLushort
*dst
= (GLushort
*) values
;
531 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
|| rb
->DataType
== GL_SHORT
);
532 for (i
= 0; i
< count
; i
++) {
534 = (GLushort
*) rb
->Data
+ 4 * (y
[i
] * rb
->RowStride
+ x
[i
]);
541 put_row_ushort4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
542 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
544 const GLushort
*src
= (const GLushort
*) values
;
545 GLushort
*dst
= (GLushort
*) rb
->Data
+ 4 * (y
* rb
->RowStride
+ x
);
546 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
|| rb
->DataType
== GL_SHORT
);
549 for (i
= 0; i
< count
; i
++) {
551 dst
[i
* 4 + 0] = src
[i
* 4 + 0];
552 dst
[i
* 4 + 1] = src
[i
* 4 + 1];
553 dst
[i
* 4 + 2] = src
[i
* 4 + 2];
554 dst
[i
* 4 + 3] = src
[i
* 4 + 3];
559 memcpy(dst
, src
, 4 * count
* sizeof(GLushort
));
565 put_values_ushort4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
566 const GLint x
[], const GLint y
[], const void *values
,
569 const GLushort
*src
= (const GLushort
*) values
;
571 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
|| rb
->DataType
== GL_SHORT
);
572 for (i
= 0; i
< count
; i
++) {
573 if (!mask
|| mask
[i
]) {
575 ((GLushort
*) rb
->Data
) + 4 * (y
[i
] * rb
->RowStride
+ x
[i
]);
576 dst
[0] = src
[i
* 4 + 0];
577 dst
[1] = src
[i
* 4 + 1];
578 dst
[2] = src
[i
* 4 + 2];
579 dst
[3] = src
[i
* 4 + 3];
585 /**********************************************************************
586 * Functions for MESA_FORMAT_R8.
589 get_row_r8(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
590 GLint x
, GLint y
, void *values
)
592 const GLubyte
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
593 GLuint
*dst
= values
;
596 for (i
= 0; i
< count
; i
++) {
597 dst
[i
] = 0xff000000 | src
[i
];
602 get_values_r8(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
603 const GLint x
[], const GLint y
[], void *values
)
605 GLuint
*dst
= (GLuint
*) values
;
608 for (i
= 0; i
< count
; i
++) {
609 const GLubyte
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
610 dst
[i
] = 0xff000000 | *src
;
614 /**********************************************************************
615 * Functions for MESA_FORMAT_GR88.
618 get_row_rg88(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
619 GLint x
, GLint y
, void *values
)
621 const GLushort
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
622 GLuint
*dst
= values
;
625 for (i
= 0; i
< count
; i
++) {
626 dst
[i
] = 0xff000000 | src
[i
];
631 get_values_rg88(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
632 GLuint count
, const GLint x
[], const GLint y
[], void *values
)
634 GLuint
*dst
= (GLuint
*) values
;
637 for (i
= 0; i
< count
; i
++) {
638 const GLshort
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
639 dst
[i
] = 0xff000000 | *src
;
643 /**********************************************************************
644 * Functions for MESA_FORMAT_R16.
647 get_row_r16(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
648 GLint x
, GLint y
, void *values
)
650 const GLushort
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
651 GLushort
*dst
= values
;
654 for (i
= 0; i
< count
; i
++) {
655 dst
[i
* 4 + RCOMP
] = src
[i
];
656 dst
[i
* 4 + GCOMP
] = 0;
657 dst
[i
* 4 + BCOMP
] = 0;
658 dst
[i
* 4 + ACOMP
] = 0xffff;
663 get_values_r16(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
664 const GLint x
[], const GLint y
[], void *values
)
666 GLushort
*dst
= values
;
669 for (i
= 0; i
< count
; i
++) {
670 const GLushort
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
671 dst
[i
* 4 + RCOMP
] = *src
;
672 dst
[i
* 4 + GCOMP
] = 0;
673 dst
[i
* 4 + BCOMP
] = 0;
674 dst
[i
* 4 + ACOMP
] = 0xffff;
678 /**********************************************************************
679 * Functions for MESA_FORMAT_RG1616.
682 get_row_rg1616(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
683 GLint x
, GLint y
, void *values
)
685 const GLushort
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
686 GLushort
*dst
= values
;
689 for (i
= 0; i
< count
; i
++) {
690 dst
[i
* 4 + RCOMP
] = src
[i
* 2];
691 dst
[i
* 4 + GCOMP
] = src
[i
* 2 + 1];
692 dst
[i
* 4 + BCOMP
] = 0;
693 dst
[i
* 4 + ACOMP
] = 0xffff;
698 get_values_rg1616(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
699 GLuint count
, const GLint x
[], const GLint y
[], void *values
)
701 GLushort
*dst
= values
;
704 for (i
= 0; i
< count
; i
++) {
705 const GLshort
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
706 dst
[i
* 4 + RCOMP
] = src
[0];
707 dst
[i
* 4 + GCOMP
] = src
[1];
708 dst
[i
* 4 + BCOMP
] = 0;
709 dst
[i
* 4 + ACOMP
] = 0xffff;
713 /**********************************************************************
714 * Functions for MESA_FORMAT_INTENSITY_FLOAT32.
717 get_row_i_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
718 GLuint count
, GLint x
, GLint y
, void *values
)
720 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
721 GLfloat
*dst
= values
;
724 for (i
= 0; i
< count
; i
++) {
728 dst
[i
* 4 + ACOMP
] = src
[i
];
733 get_values_i_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
734 GLuint count
, const GLint x
[], const GLint y
[],
737 GLfloat
*dst
= values
;
740 for (i
= 0; i
< count
; i
++) {
741 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
745 dst
[i
* 4 + ACOMP
] = src
[0];
749 /**********************************************************************
750 * Functions for MESA_FORMAT_LUMINANCE_FLOAT32.
753 get_row_l_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
754 GLuint count
, GLint x
, GLint y
, void *values
)
756 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
757 GLfloat
*dst
= values
;
760 for (i
= 0; i
< count
; i
++) {
763 dst
[i
* 4 + BCOMP
] = src
[i
];
764 dst
[i
* 4 + ACOMP
] = 1.0;
769 get_values_l_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
770 GLuint count
, const GLint x
[], const GLint y
[],
773 GLfloat
*dst
= values
;
776 for (i
= 0; i
< count
; i
++) {
777 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
780 dst
[i
* 4 + BCOMP
] = src
[0];
781 dst
[i
* 4 + ACOMP
] = 1.0;
785 /**********************************************************************
786 * Functions for MESA_FORMAT_ALPHA_FLOAT32.
789 get_row_a_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
790 GLuint count
, GLint x
, GLint y
, void *values
)
792 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
793 GLfloat
*dst
= values
;
796 for (i
= 0; i
< count
; i
++) {
797 dst
[i
* 4 + RCOMP
] = 0.0;
798 dst
[i
* 4 + GCOMP
] = 0.0;
799 dst
[i
* 4 + BCOMP
] = 0.0;
800 dst
[i
* 4 + ACOMP
] = src
[i
];
805 get_values_a_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
806 GLuint count
, const GLint x
[], const GLint y
[],
809 GLfloat
*dst
= values
;
812 for (i
= 0; i
< count
; i
++) {
813 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
814 dst
[i
* 4 + RCOMP
] = 0.0;
815 dst
[i
* 4 + GCOMP
] = 0.0;
816 dst
[i
* 4 + BCOMP
] = 0.0;
817 dst
[i
* 4 + ACOMP
] = src
[0];
822 put_row_a_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
823 GLuint count
, GLint x
, GLint y
,
824 const void *values
, const GLubyte
*mask
)
826 float *dst
= rb
->GetPointer(ctx
, rb
, x
, y
);
827 const float *src
= values
;
831 for (i
= 0; i
< count
; i
++) {
833 dst
[i
] = src
[i
* 4 + ACOMP
];
838 for (i
= 0; i
< count
; i
++) {
839 dst
[i
] = src
[i
* 4 + ACOMP
];
845 put_values_a_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
846 GLuint count
, const GLint x
[], const GLint y
[],
847 const void *values
, const GLubyte
*mask
)
849 const float *src
= values
;
852 for (i
= 0; i
< count
; i
++) {
853 if (!mask
|| mask
[i
]) {
854 float *dst
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
856 *dst
= src
[i
* 4 + ACOMP
];
861 /**********************************************************************
862 * Functions for MESA_FORMAT_R_FLOAT32.
865 get_row_r_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
866 GLuint count
, GLint x
, GLint y
, void *values
)
868 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
869 GLfloat
*dst
= values
;
872 for (i
= 0; i
< count
; i
++) {
873 dst
[i
* 4 + RCOMP
] = src
[i
];
874 dst
[i
* 4 + GCOMP
] = 0.0;
875 dst
[i
* 4 + BCOMP
] = 0.0;
876 dst
[i
* 4 + ACOMP
] = 1.0;
881 get_values_r_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
882 GLuint count
, const GLint x
[], const GLint y
[],
885 GLfloat
*dst
= values
;
888 for (i
= 0; i
< count
; i
++) {
889 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
890 dst
[i
* 4 + RCOMP
] = src
[0];
891 dst
[i
* 4 + GCOMP
] = 0.0;
892 dst
[i
* 4 + BCOMP
] = 0.0;
893 dst
[i
* 4 + ACOMP
] = 1.0;
897 /**********************************************************************
898 * Functions for MESA_FORMAT_RG_FLOAT32.
901 get_row_rg_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
902 GLuint count
, GLint x
, GLint y
, void *values
)
904 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
905 GLfloat
*dst
= values
;
908 for (i
= 0; i
< count
; i
++) {
909 dst
[i
* 4 + RCOMP
] = src
[i
* 2 + 0];
910 dst
[i
* 4 + GCOMP
] = src
[i
* 2 + 1];
911 dst
[i
* 4 + BCOMP
] = 0.0;
912 dst
[i
* 4 + ACOMP
] = 1.0;
917 get_values_rg_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
918 GLuint count
, const GLint x
[], const GLint y
[],
921 GLfloat
*dst
= values
;
924 for (i
= 0; i
< count
; i
++) {
925 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
926 dst
[i
* 4 + RCOMP
] = src
[0];
927 dst
[i
* 4 + GCOMP
] = src
[1];
928 dst
[i
* 4 + BCOMP
] = 0.0;
929 dst
[i
* 4 + ACOMP
] = 1.0;
934 * This is the default software fallback for gl_renderbuffer's span
937 * The assumptions are that rb->Data will be a pointer to (0,0), that pixels
938 * are packed in the type of rb->Format, and that subsequent rows appear
939 * rb->RowStride pixels later.
942 _swrast_set_renderbuffer_accessors(struct gl_renderbuffer
*rb
)
944 rb
->GetPointer
= get_pointer_generic
;
945 rb
->GetRow
= get_row_generic
;
947 switch (rb
->Format
) {
948 case MESA_FORMAT_RGB888
:
949 rb
->DataType
= GL_UNSIGNED_BYTE
;
950 rb
->GetPointer
= get_pointer_ubyte3
;
951 rb
->GetRow
= get_row_ubyte3
;
952 rb
->GetValues
= get_values_ubyte3
;
953 rb
->PutRow
= put_row_ubyte3
;
954 rb
->PutValues
= put_values_ubyte3
;
957 case MESA_FORMAT_RGBA8888
:
958 case MESA_FORMAT_RGBA8888_REV
:
959 rb
->DataType
= GL_UNSIGNED_BYTE
;
960 rb
->GetValues
= get_values_ubyte4
;
961 rb
->PutRow
= put_row_ubyte4
;
962 rb
->PutValues
= put_values_ubyte4
;
966 rb
->DataType
= GL_UNSIGNED_BYTE
;
967 rb
->GetValues
= get_values_r8
;
968 rb
->GetRow
= get_row_r8
;
969 rb
->PutRow
= put_row_generic
;
970 rb
->PutValues
= put_values_generic
;
973 case MESA_FORMAT_GR88
:
974 rb
->DataType
= GL_UNSIGNED_BYTE
;
975 rb
->GetValues
= get_values_rg88
;
976 rb
->GetRow
= get_row_rg88
;
977 rb
->PutRow
= put_row_generic
;
978 rb
->PutValues
= put_values_generic
;
981 case MESA_FORMAT_R16
:
982 rb
->DataType
= GL_UNSIGNED_SHORT
;
983 rb
->GetValues
= get_values_r16
;
984 rb
->GetRow
= get_row_r16
;
985 rb
->PutRow
= put_row_generic
;
986 rb
->PutValues
= put_values_generic
;
989 case MESA_FORMAT_RG1616
:
990 rb
->DataType
= GL_UNSIGNED_SHORT
;
991 rb
->GetValues
= get_values_rg1616
;
992 rb
->GetRow
= get_row_rg1616
;
993 rb
->PutRow
= put_row_generic
;
994 rb
->PutValues
= put_values_generic
;
997 case MESA_FORMAT_SIGNED_RGBA_16
:
998 rb
->DataType
= GL_SHORT
;
999 rb
->GetValues
= get_values_ushort4
;
1000 rb
->PutRow
= put_row_ushort4
;
1001 rb
->PutValues
= put_values_ushort4
;
1004 case MESA_FORMAT_S8
:
1005 rb
->DataType
= GL_UNSIGNED_BYTE
;
1006 rb
->GetValues
= get_values_ubyte
;
1007 rb
->PutRow
= put_row_ubyte
;
1008 rb
->PutValues
= put_values_ubyte
;
1011 case MESA_FORMAT_Z16
:
1012 rb
->DataType
= GL_UNSIGNED_SHORT
;
1013 rb
->GetValues
= get_values_ushort
;
1014 rb
->PutRow
= put_row_ushort
;
1015 rb
->PutValues
= put_values_ushort
;
1018 case MESA_FORMAT_Z32
:
1019 case MESA_FORMAT_X8_Z24
:
1020 case MESA_FORMAT_Z24_X8
:
1021 rb
->DataType
= GL_UNSIGNED_INT
;
1022 rb
->GetValues
= get_values_uint
;
1023 rb
->PutRow
= put_row_uint
;
1024 rb
->PutValues
= put_values_uint
;
1027 case MESA_FORMAT_Z24_S8
:
1028 case MESA_FORMAT_S8_Z24
:
1029 rb
->DataType
= GL_UNSIGNED_INT_24_8_EXT
;
1030 rb
->GetValues
= get_values_uint
;
1031 rb
->PutRow
= put_row_uint
;
1032 rb
->PutValues
= put_values_uint
;
1035 case MESA_FORMAT_RGBA_FLOAT32
:
1036 rb
->GetRow
= get_row_generic
;
1037 rb
->GetValues
= get_values_generic
;
1038 rb
->PutRow
= put_row_generic
;
1039 rb
->PutValues
= put_values_generic
;
1042 case MESA_FORMAT_INTENSITY_FLOAT32
:
1043 rb
->GetRow
= get_row_i_float32
;
1044 rb
->GetValues
= get_values_i_float32
;
1045 rb
->PutRow
= put_row_generic
;
1046 rb
->PutValues
= put_values_generic
;
1049 case MESA_FORMAT_LUMINANCE_FLOAT32
:
1050 rb
->GetRow
= get_row_l_float32
;
1051 rb
->GetValues
= get_values_l_float32
;
1052 rb
->PutRow
= put_row_generic
;
1053 rb
->PutValues
= put_values_generic
;
1056 case MESA_FORMAT_ALPHA_FLOAT32
:
1057 rb
->GetRow
= get_row_a_float32
;
1058 rb
->GetValues
= get_values_a_float32
;
1059 rb
->PutRow
= put_row_a_float32
;
1060 rb
->PutValues
= put_values_a_float32
;
1063 case MESA_FORMAT_RG_FLOAT32
:
1064 rb
->GetRow
= get_row_rg_float32
;
1065 rb
->GetValues
= get_values_rg_float32
;
1066 rb
->PutRow
= put_row_generic
;
1067 rb
->PutValues
= put_values_generic
;
1070 case MESA_FORMAT_R_FLOAT32
:
1071 rb
->GetRow
= get_row_r_float32
;
1072 rb
->GetValues
= get_values_r_float32
;
1073 rb
->PutRow
= put_row_generic
;
1074 rb
->PutValues
= put_values_generic
;
1083 * This is a software fallback for the gl_renderbuffer->AllocStorage
1085 * Device drivers will typically override this function for the buffers
1086 * which it manages (typically color buffers, Z and stencil).
1087 * Other buffers (like software accumulation and aux buffers) which the driver
1088 * doesn't manage can be handled with this function.
1090 * This one multi-purpose function can allocate stencil, depth, accum, color
1091 * or color-index buffers!
1093 * This function also plugs in the appropriate GetPointer, Get/PutRow and
1094 * Get/PutValues functions.
1097 soft_renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1098 GLenum internalFormat
,
1099 GLuint width
, GLuint height
)
1101 switch (internalFormat
) {
1110 rb
->Format
= MESA_FORMAT_RGB888
;
1121 if (_mesa_little_endian())
1122 rb
->Format
= MESA_FORMAT_RGBA8888_REV
;
1124 rb
->Format
= MESA_FORMAT_RGBA8888
;
1127 case GL_RGBA16_SNORM
:
1128 /* for accum buffer */
1129 rb
->Format
= MESA_FORMAT_SIGNED_RGBA_16
;
1131 case GL_STENCIL_INDEX
:
1132 case GL_STENCIL_INDEX1_EXT
:
1133 case GL_STENCIL_INDEX4_EXT
:
1134 case GL_STENCIL_INDEX8_EXT
:
1135 case GL_STENCIL_INDEX16_EXT
:
1136 rb
->Format
= MESA_FORMAT_S8
;
1138 case GL_DEPTH_COMPONENT
:
1139 case GL_DEPTH_COMPONENT16
:
1140 rb
->Format
= MESA_FORMAT_Z16
;
1142 case GL_DEPTH_COMPONENT24
:
1143 rb
->Format
= MESA_FORMAT_X8_Z24
;
1145 case GL_DEPTH_COMPONENT32
:
1146 rb
->Format
= MESA_FORMAT_Z32
;
1148 case GL_DEPTH_STENCIL_EXT
:
1149 case GL_DEPTH24_STENCIL8_EXT
:
1150 rb
->Format
= MESA_FORMAT_Z24_S8
;
1153 /* unsupported format */
1157 _swrast_set_renderbuffer_accessors(rb
);
1159 ASSERT(rb
->DataType
);
1160 ASSERT(rb
->GetPointer
);
1162 ASSERT(rb
->GetValues
);
1164 ASSERT(rb
->PutValues
);
1166 /* free old buffer storage */
1172 rb
->RowStride
= width
;
1174 if (width
> 0 && height
> 0) {
1175 /* allocate new buffer storage */
1176 rb
->Data
= malloc(width
* height
* _mesa_get_format_bytes(rb
->Format
));
1178 if (rb
->Data
== NULL
) {
1182 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
1183 "software renderbuffer allocation (%d x %d x %d)",
1184 width
, height
, _mesa_get_format_bytes(rb
->Format
));
1190 rb
->Height
= height
;
1191 rb
->_BaseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
1193 if (rb
->Name
== 0 &&
1194 internalFormat
== GL_RGBA16_SNORM
&&
1195 rb
->_BaseFormat
== 0) {
1196 /* NOTE: This is a special case just for accumulation buffers.
1197 * This is a very limited use case- there's no snorm texturing or
1198 * rendering going on.
1200 rb
->_BaseFormat
= GL_RGBA
;
1203 /* the internalFormat should have been error checked long ago */
1204 ASSERT(rb
->_BaseFormat
);
1212 _swrast_map_soft_renderbuffer(struct gl_context
*ctx
,
1213 struct gl_renderbuffer
*rb
,
1214 GLuint x
, GLuint y
, GLuint w
, GLuint h
,
1219 GLubyte
*map
= rb
->Data
;
1220 int cpp
= _mesa_get_format_bytes(rb
->Format
);
1221 int stride
= rb
->RowStride
* cpp
;
1229 *out_stride
= stride
;
1234 _swrast_unmap_soft_renderbuffer(struct gl_context
*ctx
,
1235 struct gl_renderbuffer
*rb
)
1242 * Allocate a software-based renderbuffer. This is called via the
1243 * ctx->Driver.NewRenderbuffer() function when the user creates a new
1245 * This would not be used for hardware-based renderbuffers.
1247 struct gl_renderbuffer
*
1248 _swrast_new_soft_renderbuffer(struct gl_context
*ctx
, GLuint name
)
1250 struct gl_renderbuffer
*rb
= _mesa_new_renderbuffer(ctx
, name
);
1252 rb
->AllocStorage
= soft_renderbuffer_storage
;
1253 /* Normally, one would setup the PutRow, GetRow, etc functions here.
1254 * But we're doing that in the soft_renderbuffer_storage() function
1263 * Add software-based color renderbuffers to the given framebuffer.
1264 * This is a helper routine for device drivers when creating a
1265 * window system framebuffer (not a user-created render/framebuffer).
1266 * Once this function is called, you can basically forget about this
1267 * renderbuffer; core Mesa will handle all the buffer management and
1271 add_color_renderbuffers(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1272 GLuint rgbBits
, GLuint alphaBits
,
1273 GLboolean frontLeft
, GLboolean backLeft
,
1274 GLboolean frontRight
, GLboolean backRight
)
1278 if (rgbBits
> 16 || alphaBits
> 16) {
1280 "Unsupported bit depth in add_color_renderbuffers");
1284 assert(MAX_COLOR_ATTACHMENTS
>= 4);
1286 for (b
= BUFFER_FRONT_LEFT
; b
<= BUFFER_BACK_RIGHT
; b
++) {
1287 struct gl_renderbuffer
*rb
;
1289 if (b
== BUFFER_FRONT_LEFT
&& !frontLeft
)
1291 else if (b
== BUFFER_BACK_LEFT
&& !backLeft
)
1293 else if (b
== BUFFER_FRONT_RIGHT
&& !frontRight
)
1295 else if (b
== BUFFER_BACK_RIGHT
&& !backRight
)
1298 assert(fb
->Attachment
[b
].Renderbuffer
== NULL
);
1300 rb
= _mesa_new_renderbuffer(ctx
, 0);
1302 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating color buffer");
1306 rb
->InternalFormat
= GL_RGBA
;
1308 rb
->AllocStorage
= soft_renderbuffer_storage
;
1309 _mesa_add_renderbuffer(fb
, b
, rb
);
1317 * Add a software-based depth renderbuffer to the given framebuffer.
1318 * This is a helper routine for device drivers when creating a
1319 * window system framebuffer (not a user-created render/framebuffer).
1320 * Once this function is called, you can basically forget about this
1321 * renderbuffer; core Mesa will handle all the buffer management and
1325 add_depth_renderbuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1328 struct gl_renderbuffer
*rb
;
1330 if (depthBits
> 32) {
1332 "Unsupported depthBits in add_depth_renderbuffer");
1336 assert(fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
== NULL
);
1338 rb
= _mesa_new_renderbuffer(ctx
, 0);
1340 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating depth buffer");
1344 if (depthBits
<= 16) {
1345 rb
->InternalFormat
= GL_DEPTH_COMPONENT16
;
1347 else if (depthBits
<= 24) {
1348 rb
->InternalFormat
= GL_DEPTH_COMPONENT24
;
1351 rb
->InternalFormat
= GL_DEPTH_COMPONENT32
;
1354 rb
->AllocStorage
= soft_renderbuffer_storage
;
1355 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, rb
);
1362 * Add a software-based stencil renderbuffer to the given framebuffer.
1363 * This is a helper routine for device drivers when creating a
1364 * window system framebuffer (not a user-created render/framebuffer).
1365 * Once this function is called, you can basically forget about this
1366 * renderbuffer; core Mesa will handle all the buffer management and
1370 add_stencil_renderbuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1373 struct gl_renderbuffer
*rb
;
1375 if (stencilBits
> 16) {
1377 "Unsupported stencilBits in add_stencil_renderbuffer");
1381 assert(fb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
== NULL
);
1383 rb
= _mesa_new_renderbuffer(ctx
, 0);
1385 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating stencil buffer");
1389 assert(stencilBits
<= 8);
1390 rb
->InternalFormat
= GL_STENCIL_INDEX8
;
1392 rb
->AllocStorage
= soft_renderbuffer_storage
;
1393 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, rb
);
1400 add_depth_stencil_renderbuffer(struct gl_context
*ctx
,
1401 struct gl_framebuffer
*fb
)
1403 struct gl_renderbuffer
*rb
;
1405 assert(fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
== NULL
);
1406 assert(fb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
== NULL
);
1408 rb
= _mesa_new_renderbuffer(ctx
, 0);
1410 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating depth+stencil buffer");
1414 rb
->InternalFormat
= GL_DEPTH_STENCIL
;
1416 rb
->AllocStorage
= soft_renderbuffer_storage
;
1417 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, rb
);
1418 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, rb
);
1425 * Add a software-based accumulation renderbuffer to the given framebuffer.
1426 * This is a helper routine for device drivers when creating a
1427 * window system framebuffer (not a user-created render/framebuffer).
1428 * Once this function is called, you can basically forget about this
1429 * renderbuffer; core Mesa will handle all the buffer management and
1433 add_accum_renderbuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1434 GLuint redBits
, GLuint greenBits
,
1435 GLuint blueBits
, GLuint alphaBits
)
1437 struct gl_renderbuffer
*rb
;
1439 if (redBits
> 16 || greenBits
> 16 || blueBits
> 16 || alphaBits
> 16) {
1441 "Unsupported accumBits in add_accum_renderbuffer");
1445 assert(fb
->Attachment
[BUFFER_ACCUM
].Renderbuffer
== NULL
);
1447 rb
= _mesa_new_renderbuffer(ctx
, 0);
1449 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating accum buffer");
1453 rb
->InternalFormat
= GL_RGBA16_SNORM
;
1454 rb
->AllocStorage
= soft_renderbuffer_storage
;
1455 _mesa_add_renderbuffer(fb
, BUFFER_ACCUM
, rb
);
1463 * Add a software-based aux renderbuffer to the given framebuffer.
1464 * This is a helper routine for device drivers when creating a
1465 * window system framebuffer (not a user-created render/framebuffer).
1466 * Once this function is called, you can basically forget about this
1467 * renderbuffer; core Mesa will handle all the buffer management and
1470 * NOTE: color-index aux buffers not supported.
1473 add_aux_renderbuffers(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1474 GLuint colorBits
, GLuint numBuffers
)
1478 if (colorBits
> 16) {
1480 "Unsupported colorBits in add_aux_renderbuffers");
1484 assert(numBuffers
<= MAX_AUX_BUFFERS
);
1486 for (i
= 0; i
< numBuffers
; i
++) {
1487 struct gl_renderbuffer
*rb
= _mesa_new_renderbuffer(ctx
, 0);
1489 assert(fb
->Attachment
[BUFFER_AUX0
+ i
].Renderbuffer
== NULL
);
1492 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating aux buffer");
1496 assert (colorBits
<= 8);
1497 rb
->InternalFormat
= GL_RGBA
;
1499 rb
->AllocStorage
= soft_renderbuffer_storage
;
1500 _mesa_add_renderbuffer(fb
, BUFFER_AUX0
+ i
, rb
);
1507 * Create/attach software-based renderbuffers to the given framebuffer.
1508 * This is a helper routine for device drivers. Drivers can just as well
1509 * call the individual _mesa_add_*_renderbuffer() routines directly.
1512 _swrast_add_soft_renderbuffers(struct gl_framebuffer
*fb
,
1520 GLboolean frontLeft
= GL_TRUE
;
1521 GLboolean backLeft
= fb
->Visual
.doubleBufferMode
;
1522 GLboolean frontRight
= fb
->Visual
.stereoMode
;
1523 GLboolean backRight
= fb
->Visual
.stereoMode
&& fb
->Visual
.doubleBufferMode
;
1526 assert(fb
->Visual
.redBits
== fb
->Visual
.greenBits
);
1527 assert(fb
->Visual
.redBits
== fb
->Visual
.blueBits
);
1528 add_color_renderbuffers(NULL
, fb
,
1530 fb
->Visual
.alphaBits
,
1531 frontLeft
, backLeft
,
1532 frontRight
, backRight
);
1536 /* This is pretty much for debugging purposes only since there's a perf
1537 * hit for using combined depth/stencil in swrast.
1539 if (depth
&& fb
->Visual
.depthBits
== 24 &&
1540 stencil
&& fb
->Visual
.stencilBits
== 8) {
1541 /* use combined depth/stencil buffer */
1542 add_depth_stencil_renderbuffer(NULL
, fb
);
1546 (void) add_depth_stencil_renderbuffer
;
1550 assert(fb
->Visual
.depthBits
> 0);
1551 add_depth_renderbuffer(NULL
, fb
, fb
->Visual
.depthBits
);
1555 assert(fb
->Visual
.stencilBits
> 0);
1556 add_stencil_renderbuffer(NULL
, fb
, fb
->Visual
.stencilBits
);
1561 assert(fb
->Visual
.accumRedBits
> 0);
1562 assert(fb
->Visual
.accumGreenBits
> 0);
1563 assert(fb
->Visual
.accumBlueBits
> 0);
1564 add_accum_renderbuffer(NULL
, fb
,
1565 fb
->Visual
.accumRedBits
,
1566 fb
->Visual
.accumGreenBits
,
1567 fb
->Visual
.accumBlueBits
,
1568 fb
->Visual
.accumAlphaBits
);
1572 assert(fb
->Visual
.numAuxBuffers
> 0);
1573 add_aux_renderbuffers(NULL
, fb
, fb
->Visual
.redBits
,
1574 fb
->Visual
.numAuxBuffers
);