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
);
162 put_mono_row_generic(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
163 GLuint count
, GLint x
, GLint y
,
164 const void *value
, const GLubyte
*mask
)
166 void *row
= rb
->GetPointer(ctx
, rb
, x
, y
);
167 int format_bytes
= _mesa_get_format_bytes(rb
->Format
) / sizeof(GLfloat
);
171 for (i
= 0; i
< count
; i
++) {
172 char *dst
= (char *) row
+ i
* format_bytes
;
174 memcpy(dst
, value
, format_bytes
);
179 for (i
= 0; i
< count
; i
++) {
180 char *dst
= (char *) row
+ i
* format_bytes
;
181 memcpy(dst
, value
, format_bytes
);
188 put_values_generic(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
189 GLuint count
, const GLint x
[], const GLint y
[],
190 const void *values
, const GLubyte
*mask
)
192 int format_bytes
= _mesa_get_format_bytes(rb
->Format
) / sizeof(GLfloat
);
193 int datatype_bytes
= get_datatype_bytes(rb
);
196 for (i
= 0; i
< count
; i
++) {
197 if (!mask
|| mask
[i
]) {
198 void *dst
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
199 const char *src
= (const char *) values
+ i
* datatype_bytes
;
200 memcpy(dst
, src
, format_bytes
);
207 put_mono_values_generic(struct gl_context
*ctx
,
208 struct gl_renderbuffer
*rb
,
209 GLuint count
, const GLint x
[], const GLint y
[],
210 const void *value
, const GLubyte
*mask
)
212 int format_bytes
= _mesa_get_format_bytes(rb
->Format
) / sizeof(GLfloat
);
215 for (i
= 0; i
< count
; i
++) {
216 if (!mask
|| mask
[i
]) {
217 void *dst
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
218 memcpy(dst
, value
, format_bytes
);
223 /**********************************************************************
224 * Functions for buffers of 1 X GLubyte values.
229 get_values_ubyte(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
230 const GLint x
[], const GLint y
[], void *values
)
232 GLubyte
*dst
= (GLubyte
*) values
;
234 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
235 for (i
= 0; i
< count
; i
++) {
236 const GLubyte
*src
= (GLubyte
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
243 put_row_ubyte(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
244 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
246 const GLubyte
*src
= (const GLubyte
*) values
;
247 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ y
* rb
->RowStride
+ x
;
248 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
251 for (i
= 0; i
< count
; i
++) {
258 memcpy(dst
, values
, count
* sizeof(GLubyte
));
264 put_mono_row_ubyte(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
265 GLint x
, GLint y
, const void *value
, const GLubyte
*mask
)
267 const GLubyte val
= *((const GLubyte
*) value
);
268 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ y
* rb
->RowStride
+ x
;
269 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
272 for (i
= 0; i
< count
; i
++) {
280 for (i
= 0; i
< count
; i
++) {
288 put_values_ubyte(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
289 const GLint x
[], const GLint y
[],
290 const void *values
, const GLubyte
*mask
)
292 const GLubyte
*src
= (const GLubyte
*) values
;
294 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
295 for (i
= 0; i
< count
; i
++) {
296 if (!mask
|| mask
[i
]) {
297 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
305 put_mono_values_ubyte(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
306 const GLint x
[], const GLint y
[],
307 const void *value
, const GLubyte
*mask
)
309 const GLubyte val
= *((const GLubyte
*) value
);
311 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
312 for (i
= 0; i
< count
; i
++) {
313 if (!mask
|| mask
[i
]) {
314 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
321 /**********************************************************************
322 * Functions for buffers of 1 X GLushort values.
327 get_values_ushort(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
328 const GLint x
[], const GLint y
[], void *values
)
330 GLushort
*dst
= (GLushort
*) values
;
332 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
);
333 for (i
= 0; i
< count
; i
++) {
334 const GLushort
*src
= (GLushort
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
341 put_row_ushort(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
342 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
344 const GLushort
*src
= (const GLushort
*) values
;
345 GLushort
*dst
= (GLushort
*) rb
->Data
+ y
* rb
->RowStride
+ x
;
346 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
);
349 for (i
= 0; i
< count
; i
++) {
356 memcpy(dst
, src
, count
* sizeof(GLushort
));
362 put_mono_row_ushort(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
363 GLint x
, GLint y
, const void *value
, const GLubyte
*mask
)
365 const GLushort val
= *((const GLushort
*) value
);
366 GLushort
*dst
= (GLushort
*) rb
->Data
+ y
* rb
->RowStride
+ x
;
367 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
);
370 for (i
= 0; i
< count
; i
++) {
378 for (i
= 0; i
< count
; i
++) {
386 put_values_ushort(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
387 const GLint x
[], const GLint y
[], const void *values
,
390 const GLushort
*src
= (const GLushort
*) values
;
392 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
);
393 for (i
= 0; i
< count
; i
++) {
394 if (!mask
|| mask
[i
]) {
395 GLushort
*dst
= (GLushort
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
403 put_mono_values_ushort(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
404 GLuint count
, const GLint x
[], const GLint y
[],
405 const void *value
, const GLubyte
*mask
)
407 const GLushort val
= *((const GLushort
*) value
);
408 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
);
411 for (i
= 0; i
< count
; i
++) {
413 GLushort
*dst
= (GLushort
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
420 for (i
= 0; i
< count
; i
++) {
421 GLushort
*dst
= (GLushort
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
428 /**********************************************************************
429 * Functions for buffers of 1 X GLuint values.
430 * Typically depth/Z or color index.
434 get_values_uint(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
435 const GLint x
[], const GLint y
[], void *values
)
437 GLuint
*dst
= (GLuint
*) values
;
439 ASSERT(rb
->DataType
== GL_UNSIGNED_INT
||
440 rb
->DataType
== GL_UNSIGNED_INT_24_8_EXT
);
441 for (i
= 0; i
< count
; i
++) {
442 const GLuint
*src
= (GLuint
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
449 put_row_uint(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
450 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
452 const GLuint
*src
= (const GLuint
*) values
;
453 GLuint
*dst
= (GLuint
*) rb
->Data
+ y
* rb
->RowStride
+ x
;
454 ASSERT(rb
->DataType
== GL_UNSIGNED_INT
||
455 rb
->DataType
== GL_UNSIGNED_INT_24_8_EXT
);
458 for (i
= 0; i
< count
; i
++) {
465 memcpy(dst
, src
, count
* sizeof(GLuint
));
471 put_mono_row_uint(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
472 GLint x
, GLint y
, const void *value
, const GLubyte
*mask
)
474 const GLuint val
= *((const GLuint
*) value
);
475 GLuint
*dst
= (GLuint
*) rb
->Data
+ y
* rb
->RowStride
+ x
;
476 ASSERT(rb
->DataType
== GL_UNSIGNED_INT
||
477 rb
->DataType
== GL_UNSIGNED_INT_24_8_EXT
);
480 for (i
= 0; i
< count
; i
++) {
488 for (i
= 0; i
< count
; i
++) {
496 put_values_uint(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
497 const GLint x
[], const GLint y
[], const void *values
,
500 const GLuint
*src
= (const GLuint
*) values
;
502 ASSERT(rb
->DataType
== GL_UNSIGNED_INT
||
503 rb
->DataType
== GL_UNSIGNED_INT_24_8_EXT
);
504 for (i
= 0; i
< count
; i
++) {
505 if (!mask
|| mask
[i
]) {
506 GLuint
*dst
= (GLuint
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
514 put_mono_values_uint(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
515 const GLint x
[], const GLint y
[], const void *value
,
518 const GLuint val
= *((const GLuint
*) value
);
520 ASSERT(rb
->DataType
== GL_UNSIGNED_INT
||
521 rb
->DataType
== GL_UNSIGNED_INT_24_8_EXT
);
522 for (i
= 0; i
< count
; i
++) {
523 if (!mask
|| mask
[i
]) {
524 GLuint
*dst
= (GLuint
*) rb
->Data
+ y
[i
] * rb
->RowStride
+ x
[i
];
531 /**********************************************************************
532 * Functions for buffers of 3 X GLubyte (or GLbyte) values.
533 * Typically color buffers.
534 * NOTE: the incoming and outgoing colors are RGBA! We ignore incoming
535 * alpha values and return 255 for outgoing alpha values.
539 get_pointer_ubyte3(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
542 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
543 /* No direct access since this buffer is RGB but caller will be
544 * treating it as if it were RGBA.
551 get_row_ubyte3(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
552 GLint x
, GLint y
, void *values
)
554 const GLubyte
*src
= ((const GLubyte
*) rb
->Data
) +
555 3 * (y
* rb
->RowStride
+ x
);
556 GLubyte
*dst
= (GLubyte
*) values
;
558 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
559 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
560 for (i
= 0; i
< count
; i
++) {
561 dst
[i
* 4 + 0] = src
[i
* 3 + 0];
562 dst
[i
* 4 + 1] = src
[i
* 3 + 1];
563 dst
[i
* 4 + 2] = src
[i
* 3 + 2];
564 dst
[i
* 4 + 3] = 255;
570 get_values_ubyte3(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
571 const GLint x
[], const GLint y
[], void *values
)
573 GLubyte
*dst
= (GLubyte
*) values
;
575 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
576 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
577 for (i
= 0; i
< count
; i
++) {
579 = (GLubyte
*) rb
->Data
+ 3 * (y
[i
] * rb
->RowStride
+ x
[i
]);
580 dst
[i
* 4 + 0] = src
[0];
581 dst
[i
* 4 + 1] = src
[1];
582 dst
[i
* 4 + 2] = src
[2];
583 dst
[i
* 4 + 3] = 255;
589 put_row_ubyte3(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
590 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
592 /* note: incoming values are RGB+A! */
593 const GLubyte
*src
= (const GLubyte
*) values
;
594 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ 3 * (y
* rb
->RowStride
+ x
);
596 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
597 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
598 for (i
= 0; i
< count
; i
++) {
599 if (!mask
|| mask
[i
]) {
600 dst
[i
* 3 + 0] = src
[i
* 4 + 0];
601 dst
[i
* 3 + 1] = src
[i
* 4 + 1];
602 dst
[i
* 3 + 2] = src
[i
* 4 + 2];
609 put_row_rgb_ubyte3(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
610 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
612 /* note: incoming values are RGB+A! */
613 const GLubyte
*src
= (const GLubyte
*) values
;
614 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ 3 * (y
* rb
->RowStride
+ x
);
616 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
617 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
618 for (i
= 0; i
< count
; i
++) {
619 if (!mask
|| mask
[i
]) {
620 dst
[i
* 3 + 0] = src
[i
* 3 + 0];
621 dst
[i
* 3 + 1] = src
[i
* 3 + 1];
622 dst
[i
* 3 + 2] = src
[i
* 3 + 2];
629 put_mono_row_ubyte3(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
630 GLint x
, GLint y
, const void *value
, const GLubyte
*mask
)
632 /* note: incoming value is RGB+A! */
633 const GLubyte val0
= ((const GLubyte
*) value
)[0];
634 const GLubyte val1
= ((const GLubyte
*) value
)[1];
635 const GLubyte val2
= ((const GLubyte
*) value
)[2];
636 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ 3 * (y
* rb
->RowStride
+ x
);
637 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
638 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
639 if (!mask
&& val0
== val1
&& val1
== val2
) {
641 memset(dst
, val0
, 3 * count
);
645 for (i
= 0; i
< count
; i
++) {
646 if (!mask
|| mask
[i
]) {
647 dst
[i
* 3 + 0] = val0
;
648 dst
[i
* 3 + 1] = val1
;
649 dst
[i
* 3 + 2] = val2
;
657 put_values_ubyte3(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
658 const GLint x
[], const GLint y
[], const void *values
,
661 /* note: incoming values are RGB+A! */
662 const GLubyte
*src
= (const GLubyte
*) values
;
664 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
665 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
666 for (i
= 0; i
< count
; i
++) {
667 if (!mask
|| mask
[i
]) {
668 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ 3 * (y
[i
] * rb
->RowStride
+ x
[i
]);
669 dst
[0] = src
[i
* 4 + 0];
670 dst
[1] = src
[i
* 4 + 1];
671 dst
[2] = src
[i
* 4 + 2];
678 put_mono_values_ubyte3(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
679 GLuint count
, const GLint x
[], const GLint y
[],
680 const void *value
, const GLubyte
*mask
)
682 /* note: incoming value is RGB+A! */
683 const GLubyte val0
= ((const GLubyte
*) value
)[0];
684 const GLubyte val1
= ((const GLubyte
*) value
)[1];
685 const GLubyte val2
= ((const GLubyte
*) value
)[2];
687 ASSERT(rb
->Format
== MESA_FORMAT_RGB888
);
688 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
689 for (i
= 0; i
< count
; i
++) {
690 if (!mask
|| mask
[i
]) {
691 GLubyte
*dst
= ((GLubyte
*) rb
->Data
) +
692 3 * (y
[i
] * rb
->RowStride
+ x
[i
]);
701 /**********************************************************************
702 * Functions for buffers of 4 X GLubyte (or GLbyte) values.
703 * Typically color buffers.
707 get_values_ubyte4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
708 const GLint x
[], const GLint y
[], void *values
)
710 /* treat 4*GLubyte as 1*GLuint */
711 GLuint
*dst
= (GLuint
*) values
;
713 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
714 ASSERT(rb
->Format
== MESA_FORMAT_RGBA8888
||
715 rb
->Format
== MESA_FORMAT_RGBA8888_REV
);
716 for (i
= 0; i
< count
; i
++) {
717 const GLuint
*src
= (GLuint
*) rb
->Data
+ (y
[i
] * rb
->RowStride
+ x
[i
]);
724 put_row_ubyte4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
725 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
727 /* treat 4*GLubyte as 1*GLuint */
728 const GLuint
*src
= (const GLuint
*) values
;
729 GLuint
*dst
= (GLuint
*) rb
->Data
+ (y
* rb
->RowStride
+ x
);
730 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
731 ASSERT(rb
->Format
== MESA_FORMAT_RGBA8888
||
732 rb
->Format
== MESA_FORMAT_RGBA8888_REV
);
735 for (i
= 0; i
< count
; i
++) {
742 memcpy(dst
, src
, 4 * count
* sizeof(GLubyte
));
748 put_row_rgb_ubyte4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
749 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
751 /* Store RGB values in RGBA buffer */
752 const GLubyte
*src
= (const GLubyte
*) values
;
753 GLubyte
*dst
= (GLubyte
*) rb
->Data
+ 4 * (y
* rb
->RowStride
+ x
);
755 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
756 ASSERT(rb
->Format
== MESA_FORMAT_RGBA8888
||
757 rb
->Format
== MESA_FORMAT_RGBA8888_REV
);
758 for (i
= 0; i
< count
; i
++) {
759 if (!mask
|| mask
[i
]) {
760 dst
[i
* 4 + 0] = src
[i
* 3 + 0];
761 dst
[i
* 4 + 1] = src
[i
* 3 + 1];
762 dst
[i
* 4 + 2] = src
[i
* 3 + 2];
763 dst
[i
* 4 + 3] = 0xff;
770 put_mono_row_ubyte4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
771 GLint x
, GLint y
, const void *value
, const GLubyte
*mask
)
773 /* treat 4*GLubyte as 1*GLuint */
774 const GLuint val
= *((const GLuint
*) value
);
775 GLuint
*dst
= (GLuint
*) rb
->Data
+ (y
* rb
->RowStride
+ x
);
776 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
777 ASSERT(rb
->Format
== MESA_FORMAT_RGBA8888
||
778 rb
->Format
== MESA_FORMAT_RGBA8888_REV
);
779 if (!mask
&& val
== 0) {
781 memset(dst
, 0, count
* 4 * sizeof(GLubyte
));
787 for (i
= 0; i
< count
; i
++) {
795 for (i
= 0; i
< count
; i
++) {
804 put_values_ubyte4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
805 const GLint x
[], const GLint y
[], const void *values
,
808 /* treat 4*GLubyte as 1*GLuint */
809 const GLuint
*src
= (const GLuint
*) values
;
811 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
812 ASSERT(rb
->Format
== MESA_FORMAT_RGBA8888
||
813 rb
->Format
== MESA_FORMAT_RGBA8888_REV
);
814 for (i
= 0; i
< count
; i
++) {
815 if (!mask
|| mask
[i
]) {
816 GLuint
*dst
= (GLuint
*) rb
->Data
+ (y
[i
] * rb
->RowStride
+ x
[i
]);
824 put_mono_values_ubyte4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
825 GLuint count
, const GLint x
[], const GLint y
[],
826 const void *value
, const GLubyte
*mask
)
828 /* treat 4*GLubyte as 1*GLuint */
829 const GLuint val
= *((const GLuint
*) value
);
831 ASSERT(rb
->DataType
== GL_UNSIGNED_BYTE
);
832 ASSERT(rb
->Format
== MESA_FORMAT_RGBA8888
||
833 rb
->Format
== MESA_FORMAT_RGBA8888_REV
);
834 for (i
= 0; i
< count
; i
++) {
835 if (!mask
|| mask
[i
]) {
836 GLuint
*dst
= (GLuint
*) rb
->Data
+ (y
[i
] * rb
->RowStride
+ x
[i
]);
843 /**********************************************************************
844 * Functions for buffers of 4 X GLushort (or GLshort) values.
845 * Typically accum buffer.
849 get_values_ushort4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
850 const GLint x
[], const GLint y
[], void *values
)
852 GLushort
*dst
= (GLushort
*) values
;
854 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
|| rb
->DataType
== GL_SHORT
);
855 for (i
= 0; i
< count
; i
++) {
857 = (GLushort
*) rb
->Data
+ 4 * (y
[i
] * rb
->RowStride
+ x
[i
]);
864 put_row_ushort4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
865 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
867 const GLushort
*src
= (const GLushort
*) values
;
868 GLushort
*dst
= (GLushort
*) rb
->Data
+ 4 * (y
* rb
->RowStride
+ x
);
869 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
|| rb
->DataType
== GL_SHORT
);
872 for (i
= 0; i
< count
; i
++) {
874 dst
[i
* 4 + 0] = src
[i
* 4 + 0];
875 dst
[i
* 4 + 1] = src
[i
* 4 + 1];
876 dst
[i
* 4 + 2] = src
[i
* 4 + 2];
877 dst
[i
* 4 + 3] = src
[i
* 4 + 3];
882 memcpy(dst
, src
, 4 * count
* sizeof(GLushort
));
888 put_row_rgb_ushort4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
889 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
891 /* Put RGB values in RGBA buffer */
892 const GLushort
*src
= (const GLushort
*) values
;
893 GLushort
*dst
= (GLushort
*) rb
->Data
+ 4 * (y
* rb
->RowStride
+ x
);
894 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
|| rb
->DataType
== GL_SHORT
);
897 for (i
= 0; i
< count
; i
++) {
899 dst
[i
* 4 + 0] = src
[i
* 3 + 0];
900 dst
[i
* 4 + 1] = src
[i
* 3 + 1];
901 dst
[i
* 4 + 2] = src
[i
* 3 + 2];
902 dst
[i
* 4 + 3] = 0xffff;
907 memcpy(dst
, src
, 4 * count
* sizeof(GLushort
));
913 put_mono_row_ushort4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
914 GLint x
, GLint y
, const void *value
, const GLubyte
*mask
)
916 const GLushort val0
= ((const GLushort
*) value
)[0];
917 const GLushort val1
= ((const GLushort
*) value
)[1];
918 const GLushort val2
= ((const GLushort
*) value
)[2];
919 const GLushort val3
= ((const GLushort
*) value
)[3];
920 GLushort
*dst
= (GLushort
*) rb
->Data
+ 4 * (y
* rb
->RowStride
+ x
);
921 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
|| rb
->DataType
== GL_SHORT
);
922 if (!mask
&& val0
== 0 && val1
== 0 && val2
== 0 && val3
== 0) {
923 /* common case for clearing accum buffer */
924 memset(dst
, 0, count
* 4 * sizeof(GLushort
));
928 for (i
= 0; i
< count
; i
++) {
929 if (!mask
|| mask
[i
]) {
930 dst
[i
* 4 + 0] = val0
;
931 dst
[i
* 4 + 1] = val1
;
932 dst
[i
* 4 + 2] = val2
;
933 dst
[i
* 4 + 3] = val3
;
941 put_values_ushort4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
942 const GLint x
[], const GLint y
[], const void *values
,
945 const GLushort
*src
= (const GLushort
*) values
;
947 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
|| rb
->DataType
== GL_SHORT
);
948 for (i
= 0; i
< count
; i
++) {
949 if (!mask
|| mask
[i
]) {
951 ((GLushort
*) rb
->Data
) + 4 * (y
[i
] * rb
->RowStride
+ x
[i
]);
952 dst
[0] = src
[i
* 4 + 0];
953 dst
[1] = src
[i
* 4 + 1];
954 dst
[2] = src
[i
* 4 + 2];
955 dst
[3] = src
[i
* 4 + 3];
962 put_mono_values_ushort4(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
963 GLuint count
, const GLint x
[], const GLint y
[],
964 const void *value
, const GLubyte
*mask
)
966 const GLushort val0
= ((const GLushort
*) value
)[0];
967 const GLushort val1
= ((const GLushort
*) value
)[1];
968 const GLushort val2
= ((const GLushort
*) value
)[2];
969 const GLushort val3
= ((const GLushort
*) value
)[3];
971 ASSERT(rb
->DataType
== GL_UNSIGNED_SHORT
|| rb
->DataType
== GL_SHORT
);
972 for (i
= 0; i
< count
; i
++) {
973 if (!mask
|| mask
[i
]) {
974 GLushort
*dst
= ((GLushort
*) rb
->Data
) +
975 4 * (y
[i
] * rb
->RowStride
+ x
[i
]);
984 /**********************************************************************
985 * Functions for MESA_FORMAT_R8.
988 get_row_r8(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
989 GLint x
, GLint y
, void *values
)
991 const GLubyte
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
992 GLuint
*dst
= values
;
995 for (i
= 0; i
< count
; i
++) {
996 dst
[i
] = 0xff000000 | src
[i
];
1001 get_values_r8(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
1002 const GLint x
[], const GLint y
[], void *values
)
1004 GLuint
*dst
= (GLuint
*) values
;
1007 for (i
= 0; i
< count
; i
++) {
1008 const GLubyte
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
1009 dst
[i
] = 0xff000000 | *src
;
1013 /**********************************************************************
1014 * Functions for MESA_FORMAT_GR88.
1017 get_row_rg88(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
1018 GLint x
, GLint y
, void *values
)
1020 const GLushort
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
1021 GLuint
*dst
= values
;
1024 for (i
= 0; i
< count
; i
++) {
1025 dst
[i
] = 0xff000000 | src
[i
];
1030 get_values_rg88(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1031 GLuint count
, const GLint x
[], const GLint y
[], void *values
)
1033 GLuint
*dst
= (GLuint
*) values
;
1036 for (i
= 0; i
< count
; i
++) {
1037 const GLshort
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
1038 dst
[i
] = 0xff000000 | *src
;
1042 /**********************************************************************
1043 * Functions for MESA_FORMAT_R16.
1046 get_row_r16(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
1047 GLint x
, GLint y
, void *values
)
1049 const GLushort
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
1050 GLushort
*dst
= values
;
1053 for (i
= 0; i
< count
; i
++) {
1054 dst
[i
* 4 + RCOMP
] = src
[i
];
1055 dst
[i
* 4 + GCOMP
] = 0;
1056 dst
[i
* 4 + BCOMP
] = 0;
1057 dst
[i
* 4 + ACOMP
] = 0xffff;
1062 get_values_r16(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
1063 const GLint x
[], const GLint y
[], void *values
)
1065 GLushort
*dst
= values
;
1068 for (i
= 0; i
< count
; i
++) {
1069 const GLushort
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
1070 dst
[i
* 4 + RCOMP
] = *src
;
1071 dst
[i
* 4 + GCOMP
] = 0;
1072 dst
[i
* 4 + BCOMP
] = 0;
1073 dst
[i
* 4 + ACOMP
] = 0xffff;
1077 /**********************************************************************
1078 * Functions for MESA_FORMAT_RG1616.
1081 get_row_rg1616(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
1082 GLint x
, GLint y
, void *values
)
1084 const GLushort
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
1085 GLushort
*dst
= values
;
1088 for (i
= 0; i
< count
; i
++) {
1089 dst
[i
* 4 + RCOMP
] = src
[i
* 2];
1090 dst
[i
* 4 + GCOMP
] = src
[i
* 2 + 1];
1091 dst
[i
* 4 + BCOMP
] = 0;
1092 dst
[i
* 4 + ACOMP
] = 0xffff;
1097 get_values_rg1616(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1098 GLuint count
, const GLint x
[], const GLint y
[], void *values
)
1100 GLushort
*dst
= values
;
1103 for (i
= 0; i
< count
; i
++) {
1104 const GLshort
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
1105 dst
[i
* 4 + RCOMP
] = src
[0];
1106 dst
[i
* 4 + GCOMP
] = src
[1];
1107 dst
[i
* 4 + BCOMP
] = 0;
1108 dst
[i
* 4 + ACOMP
] = 0xffff;
1112 /**********************************************************************
1113 * Functions for MESA_FORMAT_INTENSITY_FLOAT32.
1116 get_row_i_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1117 GLuint count
, GLint x
, GLint y
, void *values
)
1119 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
1120 GLfloat
*dst
= values
;
1123 for (i
= 0; i
< count
; i
++) {
1124 dst
[i
* 4 + RCOMP
] =
1125 dst
[i
* 4 + GCOMP
] =
1126 dst
[i
* 4 + BCOMP
] =
1127 dst
[i
* 4 + ACOMP
] = src
[i
];
1132 get_values_i_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1133 GLuint count
, const GLint x
[], const GLint y
[],
1136 GLfloat
*dst
= values
;
1139 for (i
= 0; i
< count
; i
++) {
1140 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
1141 dst
[i
* 4 + RCOMP
] =
1142 dst
[i
* 4 + GCOMP
] =
1143 dst
[i
* 4 + BCOMP
] =
1144 dst
[i
* 4 + ACOMP
] = src
[0];
1148 /**********************************************************************
1149 * Functions for MESA_FORMAT_LUMINANCE_FLOAT32.
1152 get_row_l_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1153 GLuint count
, GLint x
, GLint y
, void *values
)
1155 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
1156 GLfloat
*dst
= values
;
1159 for (i
= 0; i
< count
; i
++) {
1160 dst
[i
* 4 + RCOMP
] =
1161 dst
[i
* 4 + GCOMP
] =
1162 dst
[i
* 4 + BCOMP
] = src
[i
];
1163 dst
[i
* 4 + ACOMP
] = 1.0;
1168 get_values_l_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1169 GLuint count
, const GLint x
[], const GLint y
[],
1172 GLfloat
*dst
= values
;
1175 for (i
= 0; i
< count
; i
++) {
1176 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
1177 dst
[i
* 4 + RCOMP
] =
1178 dst
[i
* 4 + GCOMP
] =
1179 dst
[i
* 4 + BCOMP
] = src
[0];
1180 dst
[i
* 4 + ACOMP
] = 1.0;
1184 /**********************************************************************
1185 * Functions for MESA_FORMAT_ALPHA_FLOAT32.
1188 get_row_a_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1189 GLuint count
, GLint x
, GLint y
, void *values
)
1191 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
1192 GLfloat
*dst
= values
;
1195 for (i
= 0; i
< count
; i
++) {
1196 dst
[i
* 4 + RCOMP
] = 0.0;
1197 dst
[i
* 4 + GCOMP
] = 0.0;
1198 dst
[i
* 4 + BCOMP
] = 0.0;
1199 dst
[i
* 4 + ACOMP
] = src
[i
];
1204 get_values_a_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1205 GLuint count
, const GLint x
[], const GLint y
[],
1208 GLfloat
*dst
= values
;
1211 for (i
= 0; i
< count
; i
++) {
1212 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
1213 dst
[i
* 4 + RCOMP
] = 0.0;
1214 dst
[i
* 4 + GCOMP
] = 0.0;
1215 dst
[i
* 4 + BCOMP
] = 0.0;
1216 dst
[i
* 4 + ACOMP
] = src
[0];
1221 put_row_a_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1222 GLuint count
, GLint x
, GLint y
,
1223 const void *values
, const GLubyte
*mask
)
1225 float *dst
= rb
->GetPointer(ctx
, rb
, x
, y
);
1226 const float *src
= values
;
1230 for (i
= 0; i
< count
; i
++) {
1232 dst
[i
] = src
[i
* 4 + ACOMP
];
1237 for (i
= 0; i
< count
; i
++) {
1238 dst
[i
] = src
[i
* 4 + ACOMP
];
1244 put_mono_row_a_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1245 GLuint count
, GLint x
, GLint y
,
1246 const void *value
, const GLubyte
*mask
)
1248 float *dst
= rb
->GetPointer(ctx
, rb
, x
, y
);
1249 const float *src
= value
;
1253 for (i
= 0; i
< count
; i
++) {
1255 dst
[i
] = src
[ACOMP
];
1260 for (i
= 0; i
< count
; i
++) {
1261 dst
[i
] = src
[ACOMP
];
1267 put_values_a_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1268 GLuint count
, const GLint x
[], const GLint y
[],
1269 const void *values
, const GLubyte
*mask
)
1271 const float *src
= values
;
1274 for (i
= 0; i
< count
; i
++) {
1275 if (!mask
|| mask
[i
]) {
1276 float *dst
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
1278 *dst
= src
[i
* 4 + ACOMP
];
1284 put_mono_values_a_float32(struct gl_context
*ctx
,
1285 struct gl_renderbuffer
*rb
,
1286 GLuint count
, const GLint x
[], const GLint y
[],
1287 const void *value
, const GLubyte
*mask
)
1289 const float *src
= value
;
1292 for (i
= 0; i
< count
; i
++) {
1293 if (!mask
|| mask
[i
]) {
1294 float *dst
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
1300 /**********************************************************************
1301 * Functions for MESA_FORMAT_R_FLOAT32.
1304 get_row_r_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1305 GLuint count
, GLint x
, GLint y
, void *values
)
1307 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
1308 GLfloat
*dst
= values
;
1311 for (i
= 0; i
< count
; i
++) {
1312 dst
[i
* 4 + RCOMP
] = src
[i
];
1313 dst
[i
* 4 + GCOMP
] = 0.0;
1314 dst
[i
* 4 + BCOMP
] = 0.0;
1315 dst
[i
* 4 + ACOMP
] = 1.0;
1320 get_values_r_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1321 GLuint count
, const GLint x
[], const GLint y
[],
1324 GLfloat
*dst
= values
;
1327 for (i
= 0; i
< count
; i
++) {
1328 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
1329 dst
[i
* 4 + RCOMP
] = src
[0];
1330 dst
[i
* 4 + GCOMP
] = 0.0;
1331 dst
[i
* 4 + BCOMP
] = 0.0;
1332 dst
[i
* 4 + ACOMP
] = 1.0;
1336 /**********************************************************************
1337 * Functions for MESA_FORMAT_RG_FLOAT32.
1340 get_row_rg_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1341 GLuint count
, GLint x
, GLint y
, void *values
)
1343 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
, y
);
1344 GLfloat
*dst
= values
;
1347 for (i
= 0; i
< count
; i
++) {
1348 dst
[i
* 4 + RCOMP
] = src
[i
* 2 + 0];
1349 dst
[i
* 4 + GCOMP
] = src
[i
* 2 + 1];
1350 dst
[i
* 4 + BCOMP
] = 0.0;
1351 dst
[i
* 4 + ACOMP
] = 1.0;
1356 get_values_rg_float32(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1357 GLuint count
, const GLint x
[], const GLint y
[],
1360 GLfloat
*dst
= values
;
1363 for (i
= 0; i
< count
; i
++) {
1364 const GLfloat
*src
= rb
->GetPointer(ctx
, rb
, x
[i
], y
[i
]);
1365 dst
[i
* 4 + RCOMP
] = src
[0];
1366 dst
[i
* 4 + GCOMP
] = src
[1];
1367 dst
[i
* 4 + BCOMP
] = 0.0;
1368 dst
[i
* 4 + ACOMP
] = 1.0;
1373 * This is the default software fallback for gl_renderbuffer's span
1376 * The assumptions are that rb->Data will be a pointer to (0,0), that pixels
1377 * are packed in the type of rb->Format, and that subsequent rows appear
1378 * rb->RowStride pixels later.
1381 _swrast_set_renderbuffer_accessors(struct gl_renderbuffer
*rb
)
1383 rb
->GetPointer
= get_pointer_generic
;
1384 rb
->GetRow
= get_row_generic
;
1386 switch (rb
->Format
) {
1387 case MESA_FORMAT_RGB888
:
1388 rb
->DataType
= GL_UNSIGNED_BYTE
;
1389 rb
->GetPointer
= get_pointer_ubyte3
;
1390 rb
->GetRow
= get_row_ubyte3
;
1391 rb
->GetValues
= get_values_ubyte3
;
1392 rb
->PutRow
= put_row_ubyte3
;
1393 rb
->PutRowRGB
= put_row_rgb_ubyte3
;
1394 rb
->PutMonoRow
= put_mono_row_ubyte3
;
1395 rb
->PutValues
= put_values_ubyte3
;
1396 rb
->PutMonoValues
= put_mono_values_ubyte3
;
1399 case MESA_FORMAT_RGBA8888
:
1400 case MESA_FORMAT_RGBA8888_REV
:
1401 rb
->DataType
= GL_UNSIGNED_BYTE
;
1402 rb
->GetValues
= get_values_ubyte4
;
1403 rb
->PutRow
= put_row_ubyte4
;
1404 rb
->PutRowRGB
= put_row_rgb_ubyte4
;
1405 rb
->PutMonoRow
= put_mono_row_ubyte4
;
1406 rb
->PutValues
= put_values_ubyte4
;
1407 rb
->PutMonoValues
= put_mono_values_ubyte4
;
1410 case MESA_FORMAT_R8
:
1411 rb
->DataType
= GL_UNSIGNED_BYTE
;
1412 rb
->GetValues
= get_values_r8
;
1413 rb
->GetRow
= get_row_r8
;
1414 rb
->PutRow
= put_row_generic
;
1415 rb
->PutRowRGB
= put_row_generic
;
1416 rb
->PutMonoRow
= put_mono_row_generic
;
1417 rb
->PutValues
= put_values_generic
;
1418 rb
->PutMonoValues
= put_mono_values_generic
;
1421 case MESA_FORMAT_GR88
:
1422 rb
->DataType
= GL_UNSIGNED_BYTE
;
1423 rb
->GetValues
= get_values_rg88
;
1424 rb
->GetRow
= get_row_rg88
;
1425 rb
->PutRow
= put_row_generic
;
1426 rb
->PutRowRGB
= put_row_generic
;
1427 rb
->PutMonoRow
= put_mono_row_generic
;
1428 rb
->PutValues
= put_values_generic
;
1429 rb
->PutMonoValues
= put_mono_values_generic
;
1432 case MESA_FORMAT_R16
:
1433 rb
->DataType
= GL_UNSIGNED_SHORT
;
1434 rb
->GetValues
= get_values_r16
;
1435 rb
->GetRow
= get_row_r16
;
1436 rb
->PutRow
= put_row_generic
;
1437 rb
->PutRowRGB
= put_row_generic
;
1438 rb
->PutMonoRow
= put_mono_row_generic
;
1439 rb
->PutValues
= put_values_generic
;
1440 rb
->PutMonoValues
= put_mono_values_generic
;
1443 case MESA_FORMAT_RG1616
:
1444 rb
->DataType
= GL_UNSIGNED_SHORT
;
1445 rb
->GetValues
= get_values_rg1616
;
1446 rb
->GetRow
= get_row_rg1616
;
1447 rb
->PutRow
= put_row_generic
;
1448 rb
->PutRowRGB
= put_row_generic
;
1449 rb
->PutMonoRow
= put_mono_row_generic
;
1450 rb
->PutValues
= put_values_generic
;
1451 rb
->PutMonoValues
= put_mono_values_generic
;
1454 case MESA_FORMAT_SIGNED_RGBA_16
:
1455 rb
->DataType
= GL_SHORT
;
1456 rb
->GetValues
= get_values_ushort4
;
1457 rb
->PutRow
= put_row_ushort4
;
1458 rb
->PutRowRGB
= put_row_rgb_ushort4
;
1459 rb
->PutMonoRow
= put_mono_row_ushort4
;
1460 rb
->PutValues
= put_values_ushort4
;
1461 rb
->PutMonoValues
= put_mono_values_ushort4
;
1464 case MESA_FORMAT_S8
:
1465 rb
->DataType
= GL_UNSIGNED_BYTE
;
1466 rb
->GetValues
= get_values_ubyte
;
1467 rb
->PutRow
= put_row_ubyte
;
1468 rb
->PutRowRGB
= NULL
;
1469 rb
->PutMonoRow
= put_mono_row_ubyte
;
1470 rb
->PutValues
= put_values_ubyte
;
1471 rb
->PutMonoValues
= put_mono_values_ubyte
;
1474 case MESA_FORMAT_Z16
:
1475 rb
->DataType
= GL_UNSIGNED_SHORT
;
1476 rb
->GetValues
= get_values_ushort
;
1477 rb
->PutRow
= put_row_ushort
;
1478 rb
->PutRowRGB
= NULL
;
1479 rb
->PutMonoRow
= put_mono_row_ushort
;
1480 rb
->PutValues
= put_values_ushort
;
1481 rb
->PutMonoValues
= put_mono_values_ushort
;
1484 case MESA_FORMAT_Z32
:
1485 case MESA_FORMAT_X8_Z24
:
1486 case MESA_FORMAT_Z24_X8
:
1487 rb
->DataType
= GL_UNSIGNED_INT
;
1488 rb
->GetValues
= get_values_uint
;
1489 rb
->PutRow
= put_row_uint
;
1490 rb
->PutRowRGB
= NULL
;
1491 rb
->PutMonoRow
= put_mono_row_uint
;
1492 rb
->PutValues
= put_values_uint
;
1493 rb
->PutMonoValues
= put_mono_values_uint
;
1496 case MESA_FORMAT_Z24_S8
:
1497 case MESA_FORMAT_S8_Z24
:
1498 rb
->DataType
= GL_UNSIGNED_INT_24_8_EXT
;
1499 rb
->GetValues
= get_values_uint
;
1500 rb
->PutRow
= put_row_uint
;
1501 rb
->PutRowRGB
= NULL
;
1502 rb
->PutMonoRow
= put_mono_row_uint
;
1503 rb
->PutValues
= put_values_uint
;
1504 rb
->PutMonoValues
= put_mono_values_uint
;
1507 case MESA_FORMAT_RGBA_FLOAT32
:
1508 rb
->GetRow
= get_row_generic
;
1509 rb
->GetValues
= get_values_generic
;
1510 rb
->PutRow
= put_row_generic
;
1511 rb
->PutRowRGB
= NULL
;
1512 rb
->PutMonoRow
= put_mono_row_generic
;
1513 rb
->PutValues
= put_values_generic
;
1514 rb
->PutMonoValues
= put_mono_values_generic
;
1517 case MESA_FORMAT_INTENSITY_FLOAT32
:
1518 rb
->GetRow
= get_row_i_float32
;
1519 rb
->GetValues
= get_values_i_float32
;
1520 rb
->PutRow
= put_row_generic
;
1521 rb
->PutRowRGB
= NULL
;
1522 rb
->PutMonoRow
= put_mono_row_generic
;
1523 rb
->PutValues
= put_values_generic
;
1524 rb
->PutMonoValues
= put_mono_values_generic
;
1527 case MESA_FORMAT_LUMINANCE_FLOAT32
:
1528 rb
->GetRow
= get_row_l_float32
;
1529 rb
->GetValues
= get_values_l_float32
;
1530 rb
->PutRow
= put_row_generic
;
1531 rb
->PutRowRGB
= NULL
;
1532 rb
->PutMonoRow
= put_mono_row_generic
;
1533 rb
->PutValues
= put_values_generic
;
1534 rb
->PutMonoValues
= put_mono_values_generic
;
1537 case MESA_FORMAT_ALPHA_FLOAT32
:
1538 rb
->GetRow
= get_row_a_float32
;
1539 rb
->GetValues
= get_values_a_float32
;
1540 rb
->PutRow
= put_row_a_float32
;
1541 rb
->PutRowRGB
= NULL
;
1542 rb
->PutMonoRow
= put_mono_row_a_float32
;
1543 rb
->PutValues
= put_values_a_float32
;
1544 rb
->PutMonoValues
= put_mono_values_a_float32
;
1547 case MESA_FORMAT_RG_FLOAT32
:
1548 rb
->GetRow
= get_row_rg_float32
;
1549 rb
->GetValues
= get_values_rg_float32
;
1550 rb
->PutRow
= put_row_generic
;
1551 rb
->PutRowRGB
= NULL
;
1552 rb
->PutMonoRow
= put_mono_row_generic
;
1553 rb
->PutValues
= put_values_generic
;
1554 rb
->PutMonoValues
= put_mono_values_generic
;
1557 case MESA_FORMAT_R_FLOAT32
:
1558 rb
->GetRow
= get_row_r_float32
;
1559 rb
->GetValues
= get_values_r_float32
;
1560 rb
->PutRow
= put_row_generic
;
1561 rb
->PutRowRGB
= NULL
;
1562 rb
->PutMonoRow
= put_mono_row_generic
;
1563 rb
->PutValues
= put_values_generic
;
1564 rb
->PutMonoValues
= put_mono_values_generic
;
1573 * This is a software fallback for the gl_renderbuffer->AllocStorage
1575 * Device drivers will typically override this function for the buffers
1576 * which it manages (typically color buffers, Z and stencil).
1577 * Other buffers (like software accumulation and aux buffers) which the driver
1578 * doesn't manage can be handled with this function.
1580 * This one multi-purpose function can allocate stencil, depth, accum, color
1581 * or color-index buffers!
1583 * This function also plugs in the appropriate GetPointer, Get/PutRow and
1584 * Get/PutValues functions.
1587 soft_renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1588 GLenum internalFormat
,
1589 GLuint width
, GLuint height
)
1591 switch (internalFormat
) {
1600 rb
->Format
= MESA_FORMAT_RGB888
;
1611 if (_mesa_little_endian())
1612 rb
->Format
= MESA_FORMAT_RGBA8888_REV
;
1614 rb
->Format
= MESA_FORMAT_RGBA8888
;
1617 case GL_RGBA16_SNORM
:
1618 /* for accum buffer */
1619 rb
->Format
= MESA_FORMAT_SIGNED_RGBA_16
;
1621 case GL_STENCIL_INDEX
:
1622 case GL_STENCIL_INDEX1_EXT
:
1623 case GL_STENCIL_INDEX4_EXT
:
1624 case GL_STENCIL_INDEX8_EXT
:
1625 case GL_STENCIL_INDEX16_EXT
:
1626 rb
->Format
= MESA_FORMAT_S8
;
1628 case GL_DEPTH_COMPONENT
:
1629 case GL_DEPTH_COMPONENT16
:
1630 rb
->Format
= MESA_FORMAT_Z16
;
1632 case GL_DEPTH_COMPONENT24
:
1633 rb
->Format
= MESA_FORMAT_X8_Z24
;
1635 case GL_DEPTH_COMPONENT32
:
1636 rb
->Format
= MESA_FORMAT_Z32
;
1638 case GL_DEPTH_STENCIL_EXT
:
1639 case GL_DEPTH24_STENCIL8_EXT
:
1640 rb
->Format
= MESA_FORMAT_Z24_S8
;
1643 /* unsupported format */
1647 _swrast_set_renderbuffer_accessors(rb
);
1649 ASSERT(rb
->DataType
);
1650 ASSERT(rb
->GetPointer
);
1652 ASSERT(rb
->GetValues
);
1654 ASSERT(rb
->PutMonoRow
);
1655 ASSERT(rb
->PutValues
);
1656 ASSERT(rb
->PutMonoValues
);
1658 /* free old buffer storage */
1664 rb
->RowStride
= width
;
1666 if (width
> 0 && height
> 0) {
1667 /* allocate new buffer storage */
1668 rb
->Data
= malloc(width
* height
* _mesa_get_format_bytes(rb
->Format
));
1670 if (rb
->Data
== NULL
) {
1674 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
1675 "software renderbuffer allocation (%d x %d x %d)",
1676 width
, height
, _mesa_get_format_bytes(rb
->Format
));
1682 rb
->Height
= height
;
1683 rb
->_BaseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
1685 if (rb
->Name
== 0 &&
1686 internalFormat
== GL_RGBA16_SNORM
&&
1687 rb
->_BaseFormat
== 0) {
1688 /* NOTE: This is a special case just for accumulation buffers.
1689 * This is a very limited use case- there's no snorm texturing or
1690 * rendering going on.
1692 rb
->_BaseFormat
= GL_RGBA
;
1695 /* the internalFormat should have been error checked long ago */
1696 ASSERT(rb
->_BaseFormat
);
1704 _swrast_map_soft_renderbuffer(struct gl_context
*ctx
,
1705 struct gl_renderbuffer
*rb
,
1706 GLuint x
, GLuint y
, GLuint w
, GLuint h
,
1711 GLubyte
*map
= rb
->Data
;
1712 int cpp
= _mesa_get_format_bytes(rb
->Format
);
1713 int stride
= rb
->RowStride
* cpp
;
1721 *out_stride
= stride
;
1726 _swrast_unmap_soft_renderbuffer(struct gl_context
*ctx
,
1727 struct gl_renderbuffer
*rb
)
1734 * Allocate a software-based renderbuffer. This is called via the
1735 * ctx->Driver.NewRenderbuffer() function when the user creates a new
1737 * This would not be used for hardware-based renderbuffers.
1739 struct gl_renderbuffer
*
1740 _swrast_new_soft_renderbuffer(struct gl_context
*ctx
, GLuint name
)
1742 struct gl_renderbuffer
*rb
= _mesa_new_renderbuffer(ctx
, name
);
1744 rb
->AllocStorage
= soft_renderbuffer_storage
;
1745 /* Normally, one would setup the PutRow, GetRow, etc functions here.
1746 * But we're doing that in the soft_renderbuffer_storage() function
1755 * Add software-based color renderbuffers to the given framebuffer.
1756 * This is a helper routine for device drivers when creating a
1757 * window system framebuffer (not a user-created render/framebuffer).
1758 * Once this function is called, you can basically forget about this
1759 * renderbuffer; core Mesa will handle all the buffer management and
1763 add_color_renderbuffers(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1764 GLuint rgbBits
, GLuint alphaBits
,
1765 GLboolean frontLeft
, GLboolean backLeft
,
1766 GLboolean frontRight
, GLboolean backRight
)
1770 if (rgbBits
> 16 || alphaBits
> 16) {
1772 "Unsupported bit depth in add_color_renderbuffers");
1776 assert(MAX_COLOR_ATTACHMENTS
>= 4);
1778 for (b
= BUFFER_FRONT_LEFT
; b
<= BUFFER_BACK_RIGHT
; b
++) {
1779 struct gl_renderbuffer
*rb
;
1781 if (b
== BUFFER_FRONT_LEFT
&& !frontLeft
)
1783 else if (b
== BUFFER_BACK_LEFT
&& !backLeft
)
1785 else if (b
== BUFFER_FRONT_RIGHT
&& !frontRight
)
1787 else if (b
== BUFFER_BACK_RIGHT
&& !backRight
)
1790 assert(fb
->Attachment
[b
].Renderbuffer
== NULL
);
1792 rb
= _mesa_new_renderbuffer(ctx
, 0);
1794 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating color buffer");
1798 rb
->InternalFormat
= GL_RGBA
;
1800 rb
->AllocStorage
= soft_renderbuffer_storage
;
1801 _mesa_add_renderbuffer(fb
, b
, rb
);
1809 * Add a software-based depth renderbuffer to the given framebuffer.
1810 * This is a helper routine for device drivers when creating a
1811 * window system framebuffer (not a user-created render/framebuffer).
1812 * Once this function is called, you can basically forget about this
1813 * renderbuffer; core Mesa will handle all the buffer management and
1817 add_depth_renderbuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1820 struct gl_renderbuffer
*rb
;
1822 if (depthBits
> 32) {
1824 "Unsupported depthBits in add_depth_renderbuffer");
1828 assert(fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
== NULL
);
1830 rb
= _mesa_new_renderbuffer(ctx
, 0);
1832 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating depth buffer");
1836 if (depthBits
<= 16) {
1837 rb
->InternalFormat
= GL_DEPTH_COMPONENT16
;
1839 else if (depthBits
<= 24) {
1840 rb
->InternalFormat
= GL_DEPTH_COMPONENT24
;
1843 rb
->InternalFormat
= GL_DEPTH_COMPONENT32
;
1846 rb
->AllocStorage
= soft_renderbuffer_storage
;
1847 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, rb
);
1854 * Add a software-based stencil renderbuffer to the given framebuffer.
1855 * This is a helper routine for device drivers when creating a
1856 * window system framebuffer (not a user-created render/framebuffer).
1857 * Once this function is called, you can basically forget about this
1858 * renderbuffer; core Mesa will handle all the buffer management and
1862 add_stencil_renderbuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1865 struct gl_renderbuffer
*rb
;
1867 if (stencilBits
> 16) {
1869 "Unsupported stencilBits in add_stencil_renderbuffer");
1873 assert(fb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
== NULL
);
1875 rb
= _mesa_new_renderbuffer(ctx
, 0);
1877 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating stencil buffer");
1881 assert(stencilBits
<= 8);
1882 rb
->InternalFormat
= GL_STENCIL_INDEX8
;
1884 rb
->AllocStorage
= soft_renderbuffer_storage
;
1885 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, rb
);
1892 * Add a software-based accumulation renderbuffer to the given framebuffer.
1893 * This is a helper routine for device drivers when creating a
1894 * window system framebuffer (not a user-created render/framebuffer).
1895 * Once this function is called, you can basically forget about this
1896 * renderbuffer; core Mesa will handle all the buffer management and
1900 add_accum_renderbuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1901 GLuint redBits
, GLuint greenBits
,
1902 GLuint blueBits
, GLuint alphaBits
)
1904 struct gl_renderbuffer
*rb
;
1906 if (redBits
> 16 || greenBits
> 16 || blueBits
> 16 || alphaBits
> 16) {
1908 "Unsupported accumBits in add_accum_renderbuffer");
1912 assert(fb
->Attachment
[BUFFER_ACCUM
].Renderbuffer
== NULL
);
1914 rb
= _mesa_new_renderbuffer(ctx
, 0);
1916 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating accum buffer");
1920 rb
->InternalFormat
= GL_RGBA16_SNORM
;
1921 rb
->AllocStorage
= soft_renderbuffer_storage
;
1922 _mesa_add_renderbuffer(fb
, BUFFER_ACCUM
, rb
);
1930 * Add a software-based aux renderbuffer to the given framebuffer.
1931 * This is a helper routine for device drivers when creating a
1932 * window system framebuffer (not a user-created render/framebuffer).
1933 * Once this function is called, you can basically forget about this
1934 * renderbuffer; core Mesa will handle all the buffer management and
1937 * NOTE: color-index aux buffers not supported.
1940 add_aux_renderbuffers(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1941 GLuint colorBits
, GLuint numBuffers
)
1945 if (colorBits
> 16) {
1947 "Unsupported colorBits in add_aux_renderbuffers");
1951 assert(numBuffers
<= MAX_AUX_BUFFERS
);
1953 for (i
= 0; i
< numBuffers
; i
++) {
1954 struct gl_renderbuffer
*rb
= _mesa_new_renderbuffer(ctx
, 0);
1956 assert(fb
->Attachment
[BUFFER_AUX0
+ i
].Renderbuffer
== NULL
);
1959 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Allocating aux buffer");
1963 assert (colorBits
<= 8);
1964 rb
->InternalFormat
= GL_RGBA
;
1966 rb
->AllocStorage
= soft_renderbuffer_storage
;
1967 _mesa_add_renderbuffer(fb
, BUFFER_AUX0
+ i
, rb
);
1974 * Create/attach software-based renderbuffers to the given framebuffer.
1975 * This is a helper routine for device drivers. Drivers can just as well
1976 * call the individual _mesa_add_*_renderbuffer() routines directly.
1979 _swrast_add_soft_renderbuffers(struct gl_framebuffer
*fb
,
1987 GLboolean frontLeft
= GL_TRUE
;
1988 GLboolean backLeft
= fb
->Visual
.doubleBufferMode
;
1989 GLboolean frontRight
= fb
->Visual
.stereoMode
;
1990 GLboolean backRight
= fb
->Visual
.stereoMode
&& fb
->Visual
.doubleBufferMode
;
1993 assert(fb
->Visual
.redBits
== fb
->Visual
.greenBits
);
1994 assert(fb
->Visual
.redBits
== fb
->Visual
.blueBits
);
1995 add_color_renderbuffers(NULL
, fb
,
1997 fb
->Visual
.alphaBits
,
1998 frontLeft
, backLeft
,
1999 frontRight
, backRight
);
2003 assert(fb
->Visual
.depthBits
> 0);
2004 add_depth_renderbuffer(NULL
, fb
, fb
->Visual
.depthBits
);
2008 assert(fb
->Visual
.stencilBits
> 0);
2009 add_stencil_renderbuffer(NULL
, fb
, fb
->Visual
.stencilBits
);
2013 assert(fb
->Visual
.accumRedBits
> 0);
2014 assert(fb
->Visual
.accumGreenBits
> 0);
2015 assert(fb
->Visual
.accumBlueBits
> 0);
2016 add_accum_renderbuffer(NULL
, fb
,
2017 fb
->Visual
.accumRedBits
,
2018 fb
->Visual
.accumGreenBits
,
2019 fb
->Visual
.accumBlueBits
,
2020 fb
->Visual
.accumAlphaBits
);
2024 assert(fb
->Visual
.numAuxBuffers
> 0);
2025 add_aux_renderbuffers(NULL
, fb
, fb
->Visual
.redBits
,
2026 fb
->Visual
.numAuxBuffers
);