aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/main/renderbuffer.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-04-27 06:58:32 +0000
committermarha <marha@users.sourceforge.net>2011-04-27 06:58:32 +0000
commit96d6df5da9cddedf4931bf8e17f96e242467c661 (patch)
tree07977c913b04e80b7dbd302e7a5890422aeacb1b /mesalib/src/mesa/main/renderbuffer.c
parent71372d36e1a3f0230b88808f70d35446fda12260 (diff)
downloadvcxsrv-96d6df5da9cddedf4931bf8e17f96e242467c661.tar.gz
vcxsrv-96d6df5da9cddedf4931bf8e17f96e242467c661.tar.bz2
vcxsrv-96d6df5da9cddedf4931bf8e17f96e242467c661.zip
xserver libX11 libxtrans mesa pixman xkeyboard-config git update 27 Apr 2011
Diffstat (limited to 'mesalib/src/mesa/main/renderbuffer.c')
-rw-r--r--mesalib/src/mesa/main/renderbuffer.c1055
1 files changed, 812 insertions, 243 deletions
diff --git a/mesalib/src/mesa/main/renderbuffer.c b/mesalib/src/mesa/main/renderbuffer.c
index e6d5fe4bf..fa884c0de 100644
--- a/mesalib/src/mesa/main/renderbuffer.c
+++ b/mesalib/src/mesa/main/renderbuffer.c
@@ -51,40 +51,187 @@
/*
* Routines for get/put values in common buffer formats follow.
- * Someday add support for arbitrary row stride to make them more
- * flexible.
*/
-/**********************************************************************
- * Functions for buffers of 1 X GLubyte values.
- * Typically stencil.
+/* Returns a bytes per pixel of the DataType in the get/put span
+ * functions for at least a subset of the available combinations a
+ * renderbuffer can have.
+ *
+ * It would be nice to see gl_renderbuffer start talking about a
+ * gl_format instead of a GLenum DataType.
*/
+static int
+get_datatype_bytes(struct gl_renderbuffer *rb)
+{
+ int component_size;
+ switch (rb->DataType) {
+ case GL_FLOAT:
+ case GL_UNSIGNED_INT:
+ case GL_UNSIGNED_INT_24_8_EXT:
+ component_size = 4;
+ break;
+ case GL_UNSIGNED_SHORT:
+ component_size = 2;
+ break;
+ case GL_UNSIGNED_BYTE:
+ component_size = 1;
+ break;
+ default:
+ component_size = 1;
+ assert(0);
+ }
+
+ switch (rb->_BaseFormat) {
+ case GL_DEPTH_COMPONENT:
+ case GL_DEPTH_STENCIL:
+ return component_size;
+ default:
+ return 4 * component_size;
+ }
+}
+
+/* This is commonly used by most of the accessors. */
static void *
-get_pointer_ubyte(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLint x, GLint y)
+get_pointer_generic(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLint x, GLint y)
{
if (!rb->Data)
return NULL;
- ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- /* Can't assert rb->Format since these funcs may be used for serveral
- * different formats (GL_ALPHA8, GL_STENCIL_INDEX8, etc).
- */
- return (GLubyte *) rb->Data + y * rb->Width + x;
+
+ return ((char *) rb->Data +
+ (y * rb->RowStride + x) * _mesa_get_format_bytes(rb->Format));
}
+/* GetRow() implementation for formats where DataType matches the rb->Format.
+ */
+static void
+get_row_generic(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, GLint x, GLint y, void *values)
+{
+ void *src = rb->GetPointer(ctx, rb, x, y);
+ memcpy(values, src, count * _mesa_get_format_bytes(rb->Format));
+}
+/* Only used for float textures currently, but might also be used for
+ * RGBA8888, RGBA16, etc.
+ */
static void
-get_row_ubyte(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, void *values)
+get_values_generic(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[], void *values)
{
- const GLubyte *src = (const GLubyte *) rb->Data + y * rb->Width + x;
- ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- memcpy(values, src, count * sizeof(GLubyte));
+ int format_bytes = _mesa_get_format_bytes(rb->Format) / sizeof(GLfloat);
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ const void *src = rb->GetPointer(ctx, rb, x[i], y[i]);
+ char *dst = (char *) values + i * format_bytes;
+ memcpy(dst, src, format_bytes);
+ }
+}
+
+/* For the GL_RED/GL_RG/GL_RGB format/DataType combinations (and
+ * GL_LUMINANCE/GL_INTENSITY?), the Put functions are a matter of
+ * storing those initial components of the value per pixel into the
+ * destination.
+ */
+static void
+put_row_generic(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, GLint x, GLint y,
+ const void *values, const GLubyte *mask)
+{
+ void *row = rb->GetPointer(ctx, rb, x, y);
+ int format_bytes = _mesa_get_format_bytes(rb->Format) / sizeof(GLfloat);
+ int datatype_bytes = get_datatype_bytes(rb);
+ unsigned int i;
+
+ if (mask) {
+ for (i = 0; i < count; i++) {
+ char *dst = (char *) row + i * format_bytes;
+ const char *src = (const char *) values + i * datatype_bytes;
+
+ if (mask[i]) {
+ memcpy(dst, src, format_bytes);
+ }
+ }
+ }
+ else {
+ for (i = 0; i < count; i++) {
+ char *dst = (char *) row + i * format_bytes;
+ const char *src = (const char *) values + i * datatype_bytes;
+ memcpy(dst, src, format_bytes);
+ }
+ }
+}
+
+static void
+put_mono_row_generic(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, GLint x, GLint y,
+ const void *value, const GLubyte *mask)
+{
+ void *row = rb->GetPointer(ctx, rb, x, y);
+ int format_bytes = _mesa_get_format_bytes(rb->Format) / sizeof(GLfloat);
+ unsigned int i;
+
+ if (mask) {
+ for (i = 0; i < count; i++) {
+ char *dst = (char *) row + i * format_bytes;
+ if (mask[i]) {
+ memcpy(dst, value, format_bytes);
+ }
+ }
+ }
+ else {
+ for (i = 0; i < count; i++) {
+ char *dst = (char *) row + i * format_bytes;
+ memcpy(dst, value, format_bytes);
+ }
+ }
+}
+
+
+static void
+put_values_generic(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[],
+ const void *values, const GLubyte *mask)
+{
+ int format_bytes = _mesa_get_format_bytes(rb->Format) / sizeof(GLfloat);
+ int datatype_bytes = get_datatype_bytes(rb);
+ unsigned int i;
+
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ void *dst = rb->GetPointer(ctx, rb, x[i], y[i]);
+ const char *src = (const char *) values + i * datatype_bytes;
+ memcpy(dst, src, format_bytes);
+ }
+ }
}
static void
+put_mono_values_generic(struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[],
+ const void *value, const GLubyte *mask)
+{
+ int format_bytes = _mesa_get_format_bytes(rb->Format) / sizeof(GLfloat);
+ unsigned int i;
+
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ void *dst = rb->GetPointer(ctx, rb, x[i], y[i]);
+ memcpy(dst, value, format_bytes);
+ }
+ }
+}
+
+/**********************************************************************
+ * Functions for buffers of 1 X GLubyte values.
+ * Typically stencil.
+ */
+
+static void
get_values_ubyte(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
const GLint x[], const GLint y[], void *values)
{
@@ -92,7 +239,7 @@ get_values_ubyte(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint coun
GLuint i;
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
for (i = 0; i < count; i++) {
- const GLubyte *src = (GLubyte *) rb->Data + y[i] * rb->Width + x[i];
+ const GLubyte *src = (GLubyte *) rb->Data + y[i] * rb->RowStride + x[i];
dst[i] = *src;
}
}
@@ -103,7 +250,7 @@ put_row_ubyte(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
GLint x, GLint y, const void *values, const GLubyte *mask)
{
const GLubyte *src = (const GLubyte *) values;
- GLubyte *dst = (GLubyte *) rb->Data + y * rb->Width + x;
+ GLubyte *dst = (GLubyte *) rb->Data + y * rb->RowStride + x;
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
if (mask) {
GLuint i;
@@ -124,7 +271,7 @@ put_mono_row_ubyte(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint co
GLint x, GLint y, const void *value, const GLubyte *mask)
{
const GLubyte val = *((const GLubyte *) value);
- GLubyte *dst = (GLubyte *) rb->Data + y * rb->Width + x;
+ GLubyte *dst = (GLubyte *) rb->Data + y * rb->RowStride + x;
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
if (mask) {
GLuint i;
@@ -153,7 +300,7 @@ put_values_ubyte(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint coun
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
- GLubyte *dst = (GLubyte *) rb->Data + y[i] * rb->Width + x[i];
+ GLubyte *dst = (GLubyte *) rb->Data + y[i] * rb->RowStride + x[i];
*dst = src[i];
}
}
@@ -170,7 +317,7 @@ put_mono_values_ubyte(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
- GLubyte *dst = (GLubyte *) rb->Data + y[i] * rb->Width + x[i];
+ GLubyte *dst = (GLubyte *) rb->Data + y[i] * rb->RowStride + x[i];
*dst = val;
}
}
@@ -182,28 +329,6 @@ put_mono_values_ubyte(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint
* Typically depth/Z.
*/
-static void *
-get_pointer_ushort(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLint x, GLint y)
-{
- if (!rb->Data)
- return NULL;
- ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
- ASSERT(rb->Width > 0);
- return (GLushort *) rb->Data + y * rb->Width + x;
-}
-
-
-static void
-get_row_ushort(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, void *values)
-{
- const void *src = rb->GetPointer(ctx, rb, x, y);
- ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
- memcpy(values, src, count * sizeof(GLushort));
-}
-
-
static void
get_values_ushort(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
const GLint x[], const GLint y[], void *values)
@@ -212,7 +337,7 @@ get_values_ushort(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint cou
GLuint i;
ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
for (i = 0; i < count; i++) {
- const GLushort *src = (GLushort *) rb->Data + y[i] * rb->Width + x[i];
+ const GLushort *src = (GLushort *) rb->Data + y[i] * rb->RowStride + x[i];
dst[i] = *src;
}
}
@@ -223,7 +348,7 @@ put_row_ushort(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
GLint x, GLint y, const void *values, const GLubyte *mask)
{
const GLushort *src = (const GLushort *) values;
- GLushort *dst = (GLushort *) rb->Data + y * rb->Width + x;
+ GLushort *dst = (GLushort *) rb->Data + y * rb->RowStride + x;
ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
if (mask) {
GLuint i;
@@ -244,7 +369,7 @@ put_mono_row_ushort(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint c
GLint x, GLint y, const void *value, const GLubyte *mask)
{
const GLushort val = *((const GLushort *) value);
- GLushort *dst = (GLushort *) rb->Data + y * rb->Width + x;
+ GLushort *dst = (GLushort *) rb->Data + y * rb->RowStride + x;
ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
if (mask) {
GLuint i;
@@ -273,7 +398,7 @@ put_values_ushort(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint cou
ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
- GLushort *dst = (GLushort *) rb->Data + y[i] * rb->Width + x[i];
+ GLushort *dst = (GLushort *) rb->Data + y[i] * rb->RowStride + x[i];
*dst = src[i];
}
}
@@ -291,7 +416,7 @@ put_mono_values_ushort(struct gl_context *ctx, struct gl_renderbuffer *rb,
GLuint i;
for (i = 0; i < count; i++) {
if (mask[i]) {
- GLushort *dst = (GLushort *) rb->Data + y[i] * rb->Width + x[i];
+ GLushort *dst = (GLushort *) rb->Data + y[i] * rb->RowStride + x[i];
*dst = val;
}
}
@@ -299,7 +424,7 @@ put_mono_values_ushort(struct gl_context *ctx, struct gl_renderbuffer *rb,
else {
GLuint i;
for (i = 0; i < count; i++) {
- GLushort *dst = (GLushort *) rb->Data + y[i] * rb->Width + x[i];
+ GLushort *dst = (GLushort *) rb->Data + y[i] * rb->RowStride + x[i];
*dst = val;
}
}
@@ -311,29 +436,6 @@ put_mono_values_ushort(struct gl_context *ctx, struct gl_renderbuffer *rb,
* Typically depth/Z or color index.
*/
-static void *
-get_pointer_uint(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLint x, GLint y)
-{
- if (!rb->Data)
- return NULL;
- ASSERT(rb->DataType == GL_UNSIGNED_INT ||
- rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
- return (GLuint *) rb->Data + y * rb->Width + x;
-}
-
-
-static void
-get_row_uint(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, void *values)
-{
- const void *src = rb->GetPointer(ctx, rb, x, y);
- ASSERT(rb->DataType == GL_UNSIGNED_INT ||
- rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
- memcpy(values, src, count * sizeof(GLuint));
-}
-
-
static void
get_values_uint(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
const GLint x[], const GLint y[], void *values)
@@ -343,7 +445,7 @@ get_values_uint(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count
ASSERT(rb->DataType == GL_UNSIGNED_INT ||
rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
for (i = 0; i < count; i++) {
- const GLuint *src = (GLuint *) rb->Data + y[i] * rb->Width + x[i];
+ const GLuint *src = (GLuint *) rb->Data + y[i] * rb->RowStride + x[i];
dst[i] = *src;
}
}
@@ -354,7 +456,7 @@ put_row_uint(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
GLint x, GLint y, const void *values, const GLubyte *mask)
{
const GLuint *src = (const GLuint *) values;
- GLuint *dst = (GLuint *) rb->Data + y * rb->Width + x;
+ GLuint *dst = (GLuint *) rb->Data + y * rb->RowStride + x;
ASSERT(rb->DataType == GL_UNSIGNED_INT ||
rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
if (mask) {
@@ -376,7 +478,7 @@ put_mono_row_uint(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint cou
GLint x, GLint y, const void *value, const GLubyte *mask)
{
const GLuint val = *((const GLuint *) value);
- GLuint *dst = (GLuint *) rb->Data + y * rb->Width + x;
+ GLuint *dst = (GLuint *) rb->Data + y * rb->RowStride + x;
ASSERT(rb->DataType == GL_UNSIGNED_INT ||
rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
if (mask) {
@@ -407,7 +509,7 @@ put_values_uint(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count
rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
- GLuint *dst = (GLuint *) rb->Data + y[i] * rb->Width + x[i];
+ GLuint *dst = (GLuint *) rb->Data + y[i] * rb->RowStride + x[i];
*dst = src[i];
}
}
@@ -425,7 +527,7 @@ put_mono_values_uint(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint
rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
- GLuint *dst = (GLuint *) rb->Data + y[i] * rb->Width + x[i];
+ GLuint *dst = (GLuint *) rb->Data + y[i] * rb->RowStride + x[i];
*dst = val;
}
}
@@ -455,7 +557,8 @@ static void
get_row_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
GLint x, GLint y, void *values)
{
- const GLubyte *src = (const GLubyte *) rb->Data + 3 * (y * rb->Width + x);
+ const GLubyte *src = ((const GLubyte *) rb->Data) +
+ 3 * (y * rb->RowStride + x);
GLubyte *dst = (GLubyte *) values;
GLuint i;
ASSERT(rb->Format == MESA_FORMAT_RGB888);
@@ -479,7 +582,7 @@ get_values_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint cou
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
for (i = 0; i < count; i++) {
const GLubyte *src
- = (GLubyte *) rb->Data + 3 * (y[i] * rb->Width + x[i]);
+ = (GLubyte *) rb->Data + 3 * (y[i] * rb->RowStride + x[i]);
dst[i * 4 + 0] = src[0];
dst[i * 4 + 1] = src[1];
dst[i * 4 + 2] = src[2];
@@ -494,7 +597,7 @@ put_row_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
{
/* note: incoming values are RGB+A! */
const GLubyte *src = (const GLubyte *) values;
- GLubyte *dst = (GLubyte *) rb->Data + 3 * (y * rb->Width + x);
+ GLubyte *dst = (GLubyte *) rb->Data + 3 * (y * rb->RowStride + x);
GLuint i;
ASSERT(rb->Format == MESA_FORMAT_RGB888);
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
@@ -514,7 +617,7 @@ put_row_rgb_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint co
{
/* note: incoming values are RGB+A! */
const GLubyte *src = (const GLubyte *) values;
- GLubyte *dst = (GLubyte *) rb->Data + 3 * (y * rb->Width + x);
+ GLubyte *dst = (GLubyte *) rb->Data + 3 * (y * rb->RowStride + x);
GLuint i;
ASSERT(rb->Format == MESA_FORMAT_RGB888);
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
@@ -536,7 +639,7 @@ put_mono_row_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint c
const GLubyte val0 = ((const GLubyte *) value)[0];
const GLubyte val1 = ((const GLubyte *) value)[1];
const GLubyte val2 = ((const GLubyte *) value)[2];
- GLubyte *dst = (GLubyte *) rb->Data + 3 * (y * rb->Width + x);
+ GLubyte *dst = (GLubyte *) rb->Data + 3 * (y * rb->RowStride + x);
ASSERT(rb->Format == MESA_FORMAT_RGB888);
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
if (!mask && val0 == val1 && val1 == val2) {
@@ -568,7 +671,7 @@ put_values_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint cou
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
- GLubyte *dst = (GLubyte *) rb->Data + 3 * (y[i] * rb->Width + x[i]);
+ GLubyte *dst = (GLubyte *) rb->Data + 3 * (y[i] * rb->RowStride + x[i]);
dst[0] = src[i * 4 + 0];
dst[1] = src[i * 4 + 1];
dst[2] = src[i * 4 + 2];
@@ -591,7 +694,8 @@ put_mono_values_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb,
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
- GLubyte *dst = (GLubyte *) rb->Data + 3 * (y[i] * rb->Width + x[i]);
+ GLubyte *dst = ((GLubyte *) rb->Data) +
+ 3 * (y[i] * rb->RowStride + x[i]);
dst[0] = val0;
dst[1] = val1;
dst[2] = val2;
@@ -605,29 +709,6 @@ put_mono_values_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb,
* Typically color buffers.
*/
-static void *
-get_pointer_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLint x, GLint y)
-{
- if (!rb->Data)
- return NULL;
- ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- ASSERT(rb->Format == MESA_FORMAT_RGBA8888);
- return (GLubyte *) rb->Data + 4 * (y * rb->Width + x);
-}
-
-
-static void
-get_row_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, void *values)
-{
- const GLubyte *src = (const GLubyte *) rb->Data + 4 * (y * rb->Width + x);
- ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- ASSERT(rb->Format == MESA_FORMAT_RGBA8888);
- memcpy(values, src, 4 * count * sizeof(GLubyte));
-}
-
-
static void
get_values_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
const GLint x[], const GLint y[], void *values)
@@ -638,7 +719,7 @@ get_values_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint cou
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
ASSERT(rb->Format == MESA_FORMAT_RGBA8888);
for (i = 0; i < count; i++) {
- const GLuint *src = (GLuint *) rb->Data + (y[i] * rb->Width + x[i]);
+ const GLuint *src = (GLuint *) rb->Data + (y[i] * rb->RowStride + x[i]);
dst[i] = *src;
}
}
@@ -650,7 +731,7 @@ put_row_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
{
/* treat 4*GLubyte as 1*GLuint */
const GLuint *src = (const GLuint *) values;
- GLuint *dst = (GLuint *) rb->Data + (y * rb->Width + x);
+ GLuint *dst = (GLuint *) rb->Data + (y * rb->RowStride + x);
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
ASSERT(rb->Format == MESA_FORMAT_RGBA8888);
if (mask) {
@@ -673,7 +754,7 @@ put_row_rgb_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint co
{
/* Store RGB values in RGBA buffer */
const GLubyte *src = (const GLubyte *) values;
- GLubyte *dst = (GLubyte *) rb->Data + 4 * (y * rb->Width + x);
+ GLubyte *dst = (GLubyte *) rb->Data + 4 * (y * rb->RowStride + x);
GLuint i;
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
ASSERT(rb->Format == MESA_FORMAT_RGBA8888);
@@ -694,7 +775,7 @@ put_mono_row_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint c
{
/* treat 4*GLubyte as 1*GLuint */
const GLuint val = *((const GLuint *) value);
- GLuint *dst = (GLuint *) rb->Data + (y * rb->Width + x);
+ GLuint *dst = (GLuint *) rb->Data + (y * rb->RowStride + x);
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
ASSERT(rb->Format == MESA_FORMAT_RGBA8888);
if (!mask && val == 0) {
@@ -733,7 +814,7 @@ put_values_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint cou
ASSERT(rb->Format == MESA_FORMAT_RGBA8888);
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
- GLuint *dst = (GLuint *) rb->Data + (y[i] * rb->Width + x[i]);
+ GLuint *dst = (GLuint *) rb->Data + (y[i] * rb->RowStride + x[i]);
*dst = src[i];
}
}
@@ -752,7 +833,7 @@ put_mono_values_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb,
ASSERT(rb->Format == MESA_FORMAT_RGBA8888);
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
- GLuint *dst = (GLuint *) rb->Data + (y[i] * rb->Width + x[i]);
+ GLuint *dst = (GLuint *) rb->Data + (y[i] * rb->RowStride + x[i]);
*dst = val;
}
}
@@ -764,27 +845,6 @@ put_mono_values_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb,
* Typically accum buffer.
*/
-static void *
-get_pointer_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLint x, GLint y)
-{
- if (!rb->Data)
- return NULL;
- ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
- return (GLushort *) rb->Data + 4 * (y * rb->Width + x);
-}
-
-
-static void
-get_row_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, void *values)
-{
- const GLshort *src = (const GLshort *) rb->Data + 4 * (y * rb->Width + x);
- ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
- memcpy(values, src, 4 * count * sizeof(GLshort));
-}
-
-
static void
get_values_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
const GLint x[], const GLint y[], void *values)
@@ -794,7 +854,7 @@ get_values_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint co
ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
for (i = 0; i < count; i++) {
const GLushort *src
- = (GLushort *) rb->Data + 4 * (y[i] * rb->Width + x[i]);
+ = (GLushort *) rb->Data + 4 * (y[i] * rb->RowStride + x[i]);
dst[i] = *src;
}
}
@@ -805,7 +865,7 @@ put_row_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count
GLint x, GLint y, const void *values, const GLubyte *mask)
{
const GLushort *src = (const GLushort *) values;
- GLushort *dst = (GLushort *) rb->Data + 4 * (y * rb->Width + x);
+ GLushort *dst = (GLushort *) rb->Data + 4 * (y * rb->RowStride + x);
ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
if (mask) {
GLuint i;
@@ -830,7 +890,7 @@ put_row_rgb_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint c
{
/* Put RGB values in RGBA buffer */
const GLushort *src = (const GLushort *) values;
- GLushort *dst = (GLushort *) rb->Data + 4 * (y * rb->Width + x);
+ GLushort *dst = (GLushort *) rb->Data + 4 * (y * rb->RowStride + x);
ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
if (mask) {
GLuint i;
@@ -857,7 +917,7 @@ put_mono_row_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint
const GLushort val1 = ((const GLushort *) value)[1];
const GLushort val2 = ((const GLushort *) value)[2];
const GLushort val3 = ((const GLushort *) value)[3];
- GLushort *dst = (GLushort *) rb->Data + 4 * (y * rb->Width + x);
+ GLushort *dst = (GLushort *) rb->Data + 4 * (y * rb->RowStride + x);
ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
if (!mask && val0 == 0 && val1 == 0 && val2 == 0 && val3 == 0) {
/* common case for clearing accum buffer */
@@ -887,7 +947,8 @@ put_values_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint co
ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
- GLushort *dst = (GLushort *) rb->Data + 4 * (y[i] * rb->Width + x[i]);
+ GLushort *dst =
+ ((GLushort *) rb->Data) + 4 * (y[i] * rb->RowStride + x[i]);
dst[0] = src[i * 4 + 0];
dst[1] = src[i * 4 + 1];
dst[2] = src[i * 4 + 2];
@@ -910,7 +971,8 @@ put_mono_values_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb,
ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
- GLushort *dst = (GLushort *) rb->Data + 4 * (y[i] * rb->Width + x[i]);
+ GLushort *dst = ((GLushort *) rb->Data) +
+ 4 * (y[i] * rb->RowStride + x[i]);
dst[0] = val0;
dst[1] = val1;
dst[2] = val2;
@@ -919,39 +981,410 @@ put_mono_values_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb,
}
}
+/**********************************************************************
+ * Functions for MESA_FORMAT_R8.
+ */
+static void
+get_row_r8(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, void *values)
+{
+ const GLubyte *src = rb->GetPointer(ctx, rb, x, y);
+ GLuint *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ dst[i] = 0xff000000 | src[i];
+ }
+}
+
+static void
+get_values_r8(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ const GLint x[], const GLint y[], void *values)
+{
+ GLuint *dst = (GLuint *) values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ const GLubyte *src = rb->GetPointer(ctx, rb, x[i], y[i]);
+ dst[i] = 0xff000000 | *src;
+ }
+}
+
+/**********************************************************************
+ * Functions for MESA_FORMAT_RG88.
+ */
+static void
+get_row_rg88(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, void *values)
+{
+ const GLushort *src = rb->GetPointer(ctx, rb, x, y);
+ GLuint *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ dst[i] = 0xff000000 | src[i];
+ }
+}
+
+static void
+get_values_rg88(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[], void *values)
+{
+ GLuint *dst = (GLuint *) values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ const GLshort *src = rb->GetPointer(ctx, rb, x[i], y[i]);
+ dst[i] = 0xff000000 | *src;
+ }
+}
+
+/**********************************************************************
+ * Functions for MESA_FORMAT_R16.
+ */
+static void
+get_row_r16(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, void *values)
+{
+ const GLushort *src = rb->GetPointer(ctx, rb, x, y);
+ GLushort *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ dst[i * 4 + RCOMP] = src[i];
+ dst[i * 4 + GCOMP] = 0;
+ dst[i * 4 + BCOMP] = 0;
+ dst[i * 4 + ACOMP] = 0xffff;
+ }
+}
+
+static void
+get_values_r16(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ const GLint x[], const GLint y[], void *values)
+{
+ GLushort *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ const GLushort *src = rb->GetPointer(ctx, rb, x[i], y[i]);
+ dst[i * 4 + RCOMP] = *src;
+ dst[i * 4 + GCOMP] = 0;
+ dst[i * 4 + BCOMP] = 0;
+ dst[i * 4 + ACOMP] = 0xffff;
+ }
+}
+
+/**********************************************************************
+ * Functions for MESA_FORMAT_RG1616.
+ */
+static void
+get_row_rg1616(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, void *values)
+{
+ const GLushort *src = rb->GetPointer(ctx, rb, x, y);
+ GLushort *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ dst[i * 4 + RCOMP] = src[i * 2];
+ dst[i * 4 + GCOMP] = src[i * 2 + 1];
+ dst[i * 4 + BCOMP] = 0;
+ dst[i * 4 + ACOMP] = 0xffff;
+ }
+}
+
+static void
+get_values_rg1616(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[], void *values)
+{
+ GLushort *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ const GLshort *src = rb->GetPointer(ctx, rb, x[i], y[i]);
+ dst[i * 4 + RCOMP] = src[0];
+ dst[i * 4 + GCOMP] = src[1];
+ dst[i * 4 + BCOMP] = 0;
+ dst[i * 4 + ACOMP] = 0xffff;
+ }
+}
+
+/**********************************************************************
+ * Functions for MESA_FORMAT_INTENSITY_FLOAT32.
+ */
+static void
+get_row_i_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, GLint x, GLint y, void *values)
+{
+ const GLfloat *src = rb->GetPointer(ctx, rb, x, y);
+ GLfloat *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ dst[i * 4 + RCOMP] =
+ dst[i * 4 + GCOMP] =
+ dst[i * 4 + BCOMP] =
+ dst[i * 4 + ACOMP] = src[i];
+ }
+}
+static void
+get_values_i_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[],
+ void *values)
+{
+ GLfloat *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ const GLfloat *src = rb->GetPointer(ctx, rb, x[i], y[i]);
+ dst[i * 4 + RCOMP] =
+ dst[i * 4 + GCOMP] =
+ dst[i * 4 + BCOMP] =
+ dst[i * 4 + ACOMP] = src[0];
+ }
+}
+
+/**********************************************************************
+ * Functions for MESA_FORMAT_LUMINANCE_FLOAT32.
+ */
+static void
+get_row_l_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, GLint x, GLint y, void *values)
+{
+ const GLfloat *src = rb->GetPointer(ctx, rb, x, y);
+ GLfloat *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ dst[i * 4 + RCOMP] =
+ dst[i * 4 + GCOMP] =
+ dst[i * 4 + BCOMP] = src[i];
+ dst[i * 4 + ACOMP] = 1.0;
+ }
+}
+
+static void
+get_values_l_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[],
+ void *values)
+{
+ GLfloat *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ const GLfloat *src = rb->GetPointer(ctx, rb, x[i], y[i]);
+ dst[i * 4 + RCOMP] =
+ dst[i * 4 + GCOMP] =
+ dst[i * 4 + BCOMP] = src[0];
+ dst[i * 4 + ACOMP] = 1.0;
+ }
+}
+
+/**********************************************************************
+ * Functions for MESA_FORMAT_ALPHA_FLOAT32.
+ */
+static void
+get_row_a_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, GLint x, GLint y, void *values)
+{
+ const GLfloat *src = rb->GetPointer(ctx, rb, x, y);
+ GLfloat *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ dst[i * 4 + RCOMP] = 0.0;
+ dst[i * 4 + GCOMP] = 0.0;
+ dst[i * 4 + BCOMP] = 0.0;
+ dst[i * 4 + ACOMP] = src[i];
+ }
+}
+
+static void
+get_values_a_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[],
+ void *values)
+{
+ GLfloat *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ const GLfloat *src = rb->GetPointer(ctx, rb, x[i], y[i]);
+ dst[i * 4 + RCOMP] = 0.0;
+ dst[i * 4 + GCOMP] = 0.0;
+ dst[i * 4 + BCOMP] = 0.0;
+ dst[i * 4 + ACOMP] = src[0];
+ }
+}
+
+static void
+put_row_a_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, GLint x, GLint y,
+ const void *values, const GLubyte *mask)
+{
+ float *dst = rb->GetPointer(ctx, rb, x, y);
+ const float *src = values;
+ unsigned int i;
+
+ if (mask) {
+ for (i = 0; i < count; i++) {
+ if (mask[i]) {
+ dst[i] = src[i * 4 + ACOMP];
+ }
+ }
+ }
+ else {
+ for (i = 0; i < count; i++) {
+ dst[i] = src[i * 4 + ACOMP];
+ }
+ }
+}
+
+static void
+put_mono_row_a_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, GLint x, GLint y,
+ const void *value, const GLubyte *mask)
+{
+ float *dst = rb->GetPointer(ctx, rb, x, y);
+ const float *src = value;
+ unsigned int i;
+
+ if (mask) {
+ for (i = 0; i < count; i++) {
+ if (mask[i]) {
+ dst[i] = src[ACOMP];
+ }
+ }
+ }
+ else {
+ for (i = 0; i < count; i++) {
+ dst[i] = src[ACOMP];
+ }
+ }
+}
+
+static void
+put_values_a_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[],
+ const void *values, const GLubyte *mask)
+{
+ const float *src = values;
+ unsigned int i;
+
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ float *dst = rb->GetPointer(ctx, rb, x[i], y[i]);
+
+ *dst = src[i * 4 + ACOMP];
+ }
+ }
+}
+
+static void
+put_mono_values_a_float32(struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[],
+ const void *value, const GLubyte *mask)
+{
+ const float *src = value;
+ unsigned int i;
+
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ float *dst = rb->GetPointer(ctx, rb, x[i], y[i]);
+ *dst = src[ACOMP];
+ }
+ }
+}
+
+/**********************************************************************
+ * Functions for MESA_FORMAT_R_FLOAT32.
+ */
+static void
+get_row_r_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, GLint x, GLint y, void *values)
+{
+ const GLfloat *src = rb->GetPointer(ctx, rb, x, y);
+ GLfloat *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ dst[i * 4 + RCOMP] = src[i];
+ dst[i * 4 + GCOMP] = 0.0;
+ dst[i * 4 + BCOMP] = 0.0;
+ dst[i * 4 + ACOMP] = 1.0;
+ }
+}
+
+static void
+get_values_r_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[],
+ void *values)
+{
+ GLfloat *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ const GLfloat *src = rb->GetPointer(ctx, rb, x[i], y[i]);
+ dst[i * 4 + RCOMP] = src[0];
+ dst[i * 4 + GCOMP] = 0.0;
+ dst[i * 4 + BCOMP] = 0.0;
+ dst[i * 4 + ACOMP] = 1.0;
+ }
+}
+
+/**********************************************************************
+ * Functions for MESA_FORMAT_RG_FLOAT32.
+ */
+static void
+get_row_rg_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, GLint x, GLint y, void *values)
+{
+ const GLfloat *src = rb->GetPointer(ctx, rb, x, y);
+ GLfloat *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ dst[i * 4 + RCOMP] = src[i * 2 + 0];
+ dst[i * 4 + GCOMP] = src[i * 2 + 1];
+ dst[i * 4 + BCOMP] = 0.0;
+ dst[i * 4 + ACOMP] = 1.0;
+ }
+}
+
+static void
+get_values_rg_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[],
+ void *values)
+{
+ GLfloat *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ const GLfloat *src = rb->GetPointer(ctx, rb, x[i], y[i]);
+ dst[i * 4 + RCOMP] = src[0];
+ dst[i * 4 + GCOMP] = src[1];
+ dst[i * 4 + BCOMP] = 0.0;
+ dst[i * 4 + ACOMP] = 1.0;
+ }
+}
/**
- * This is a software fallback for the gl_renderbuffer->AllocStorage
- * function.
- * Device drivers will typically override this function for the buffers
- * which it manages (typically color buffers, Z and stencil).
- * Other buffers (like software accumulation and aux buffers) which the driver
- * doesn't manage can be handled with this function.
- *
- * This one multi-purpose function can allocate stencil, depth, accum, color
- * or color-index buffers!
+ * This is the default software fallback for gl_renderbuffer's span
+ * access functions.
*
- * This function also plugs in the appropriate GetPointer, Get/PutRow and
- * Get/PutValues functions.
+ * The assumptions are that rb->Data will be a pointer to (0,0), that pixels
+ * are packed in the type of rb->Format, and that subsequent rows appear
+ * rb->RowStride pixels later.
*/
-GLboolean
-_mesa_soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLenum internalFormat,
- GLuint width, GLuint height)
+void
+_mesa_set_renderbuffer_accessors(struct gl_renderbuffer *rb)
{
- GLuint pixelSize;
+ rb->GetPointer = get_pointer_generic;
+ rb->GetRow = get_row_generic;
- switch (internalFormat) {
- case GL_RGB:
- case GL_R3_G3_B2:
- case GL_RGB4:
- case GL_RGB5:
- case GL_RGB8:
- case GL_RGB10:
- case GL_RGB12:
- case GL_RGB16:
- rb->Format = MESA_FORMAT_RGB888;
+ switch (rb->Format) {
+ case MESA_FORMAT_RGB888:
rb->DataType = GL_UNSIGNED_BYTE;
rb->GetPointer = get_pointer_ubyte3;
rb->GetRow = get_row_ubyte3;
@@ -961,135 +1394,271 @@ _mesa_soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *
rb->PutMonoRow = put_mono_row_ubyte3;
rb->PutValues = put_values_ubyte3;
rb->PutMonoValues = put_mono_values_ubyte3;
- pixelSize = 3 * sizeof(GLubyte);
break;
- case GL_RGBA:
- case GL_RGBA2:
- case GL_RGBA4:
- case GL_RGB5_A1:
- case GL_RGBA8:
-#if 1
- case GL_RGB10_A2:
- case GL_RGBA12:
-#endif
- rb->Format = MESA_FORMAT_RGBA8888;
+
+ case MESA_FORMAT_RGBA8888:
rb->DataType = GL_UNSIGNED_BYTE;
- rb->GetPointer = get_pointer_ubyte4;
- rb->GetRow = get_row_ubyte4;
rb->GetValues = get_values_ubyte4;
rb->PutRow = put_row_ubyte4;
rb->PutRowRGB = put_row_rgb_ubyte4;
rb->PutMonoRow = put_mono_row_ubyte4;
rb->PutValues = put_values_ubyte4;
rb->PutMonoValues = put_mono_values_ubyte4;
- pixelSize = 4 * sizeof(GLubyte);
break;
- case GL_RGBA16:
- case GL_RGBA16_SNORM:
- /* for accum buffer */
- rb->Format = MESA_FORMAT_SIGNED_RGBA_16;
+
+ case MESA_FORMAT_R8:
+ rb->DataType = GL_UNSIGNED_BYTE;
+ rb->GetValues = get_values_r8;
+ rb->GetRow = get_row_r8;
+ rb->PutRow = put_row_generic;
+ rb->PutRowRGB = put_row_generic;
+ rb->PutMonoRow = put_mono_row_generic;
+ rb->PutValues = put_values_generic;
+ rb->PutMonoValues = put_mono_values_generic;
+ break;
+
+ case MESA_FORMAT_RG88:
+ rb->DataType = GL_UNSIGNED_BYTE;
+ rb->GetValues = get_values_rg88;
+ rb->GetRow = get_row_rg88;
+ rb->PutRow = put_row_generic;
+ rb->PutRowRGB = put_row_generic;
+ rb->PutMonoRow = put_mono_row_generic;
+ rb->PutValues = put_values_generic;
+ rb->PutMonoValues = put_mono_values_generic;
+ break;
+
+ case MESA_FORMAT_R16:
+ rb->DataType = GL_UNSIGNED_SHORT;
+ rb->GetValues = get_values_r16;
+ rb->GetRow = get_row_r16;
+ rb->PutRow = put_row_generic;
+ rb->PutRowRGB = put_row_generic;
+ rb->PutMonoRow = put_mono_row_generic;
+ rb->PutValues = put_values_generic;
+ rb->PutMonoValues = put_mono_values_generic;
+ break;
+
+ case MESA_FORMAT_RG1616:
+ rb->DataType = GL_UNSIGNED_SHORT;
+ rb->GetValues = get_values_rg1616;
+ rb->GetRow = get_row_rg1616;
+ rb->PutRow = put_row_generic;
+ rb->PutRowRGB = put_row_generic;
+ rb->PutMonoRow = put_mono_row_generic;
+ rb->PutValues = put_values_generic;
+ rb->PutMonoValues = put_mono_values_generic;
+ break;
+
+ case MESA_FORMAT_SIGNED_RGBA_16:
rb->DataType = GL_SHORT;
- rb->GetPointer = get_pointer_ushort4;
- rb->GetRow = get_row_ushort4;
rb->GetValues = get_values_ushort4;
rb->PutRow = put_row_ushort4;
rb->PutRowRGB = put_row_rgb_ushort4;
rb->PutMonoRow = put_mono_row_ushort4;
rb->PutValues = put_values_ushort4;
rb->PutMonoValues = put_mono_values_ushort4;
- pixelSize = 4 * sizeof(GLushort);
break;
+
#if 0
- case GL_ALPHA8:
- rb->Format = MESA_FORMAT_A8;
+ case MESA_FORMAT_A8:
rb->DataType = GL_UNSIGNED_BYTE;
- rb->GetPointer = get_pointer_alpha8;
- rb->GetRow = get_row_alpha8;
rb->GetValues = get_values_alpha8;
rb->PutRow = put_row_alpha8;
rb->PutRowRGB = NULL;
rb->PutMonoRow = put_mono_row_alpha8;
rb->PutValues = put_values_alpha8;
rb->PutMonoValues = put_mono_values_alpha8;
- pixelSize = sizeof(GLubyte);
break;
#endif
- case GL_STENCIL_INDEX:
- case GL_STENCIL_INDEX1_EXT:
- case GL_STENCIL_INDEX4_EXT:
- case GL_STENCIL_INDEX8_EXT:
- case GL_STENCIL_INDEX16_EXT:
- rb->Format = MESA_FORMAT_S8;
+
+ case MESA_FORMAT_S8:
rb->DataType = GL_UNSIGNED_BYTE;
- rb->GetPointer = get_pointer_ubyte;
- rb->GetRow = get_row_ubyte;
rb->GetValues = get_values_ubyte;
rb->PutRow = put_row_ubyte;
rb->PutRowRGB = NULL;
rb->PutMonoRow = put_mono_row_ubyte;
rb->PutValues = put_values_ubyte;
rb->PutMonoValues = put_mono_values_ubyte;
- pixelSize = sizeof(GLubyte);
break;
- case GL_DEPTH_COMPONENT:
- case GL_DEPTH_COMPONENT16:
- rb->Format = MESA_FORMAT_Z16;
+
+ case MESA_FORMAT_Z16:
rb->DataType = GL_UNSIGNED_SHORT;
- rb->GetPointer = get_pointer_ushort;
- rb->GetRow = get_row_ushort;
rb->GetValues = get_values_ushort;
rb->PutRow = put_row_ushort;
rb->PutRowRGB = NULL;
rb->PutMonoRow = put_mono_row_ushort;
rb->PutValues = put_values_ushort;
rb->PutMonoValues = put_mono_values_ushort;
- pixelSize = sizeof(GLushort);
break;
- case GL_DEPTH_COMPONENT24:
+
+ case MESA_FORMAT_Z32:
+ case MESA_FORMAT_X8_Z24:
+ case MESA_FORMAT_Z24_X8:
rb->DataType = GL_UNSIGNED_INT;
- rb->GetPointer = get_pointer_uint;
- rb->GetRow = get_row_uint;
rb->GetValues = get_values_uint;
rb->PutRow = put_row_uint;
rb->PutRowRGB = NULL;
rb->PutMonoRow = put_mono_row_uint;
rb->PutValues = put_values_uint;
rb->PutMonoValues = put_mono_values_uint;
- rb->Format = MESA_FORMAT_X8_Z24;
- pixelSize = sizeof(GLuint);
break;
- case GL_DEPTH_COMPONENT32:
- rb->DataType = GL_UNSIGNED_INT;
- rb->GetPointer = get_pointer_uint;
- rb->GetRow = get_row_uint;
+
+ case MESA_FORMAT_Z24_S8:
+ case MESA_FORMAT_S8_Z24:
+ rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
rb->GetValues = get_values_uint;
rb->PutRow = put_row_uint;
rb->PutRowRGB = NULL;
rb->PutMonoRow = put_mono_row_uint;
rb->PutValues = put_values_uint;
rb->PutMonoValues = put_mono_values_uint;
+ break;
+
+ case MESA_FORMAT_RGBA_FLOAT32:
+ rb->GetRow = get_row_generic;
+ rb->GetValues = get_values_generic;
+ rb->PutRow = put_row_generic;
+ rb->PutRowRGB = NULL;
+ rb->PutMonoRow = put_mono_row_generic;
+ rb->PutValues = put_values_generic;
+ rb->PutMonoValues = put_mono_values_generic;
+ break;
+
+ case MESA_FORMAT_INTENSITY_FLOAT32:
+ rb->GetRow = get_row_i_float32;
+ rb->GetValues = get_values_i_float32;
+ rb->PutRow = put_row_generic;
+ rb->PutRowRGB = NULL;
+ rb->PutMonoRow = put_mono_row_generic;
+ rb->PutValues = put_values_generic;
+ rb->PutMonoValues = put_mono_values_generic;
+ break;
+
+ case MESA_FORMAT_LUMINANCE_FLOAT32:
+ rb->GetRow = get_row_l_float32;
+ rb->GetValues = get_values_l_float32;
+ rb->PutRow = put_row_generic;
+ rb->PutRowRGB = NULL;
+ rb->PutMonoRow = put_mono_row_generic;
+ rb->PutValues = put_values_generic;
+ rb->PutMonoValues = put_mono_values_generic;
+ break;
+
+ case MESA_FORMAT_ALPHA_FLOAT32:
+ rb->GetRow = get_row_a_float32;
+ rb->GetValues = get_values_a_float32;
+ rb->PutRow = put_row_a_float32;
+ rb->PutRowRGB = NULL;
+ rb->PutMonoRow = put_mono_row_a_float32;
+ rb->PutValues = put_values_a_float32;
+ rb->PutMonoValues = put_mono_values_a_float32;
+ break;
+
+ case MESA_FORMAT_RG_FLOAT32:
+ rb->GetRow = get_row_rg_float32;
+ rb->GetValues = get_values_rg_float32;
+ rb->PutRow = put_row_generic;
+ rb->PutRowRGB = NULL;
+ rb->PutMonoRow = put_mono_row_generic;
+ rb->PutValues = put_values_generic;
+ rb->PutMonoValues = put_mono_values_generic;
+ break;
+
+ case MESA_FORMAT_R_FLOAT32:
+ rb->GetRow = get_row_r_float32;
+ rb->GetValues = get_values_r_float32;
+ rb->PutRow = put_row_generic;
+ rb->PutRowRGB = NULL;
+ rb->PutMonoRow = put_mono_row_generic;
+ rb->PutValues = put_values_generic;
+ rb->PutMonoValues = put_mono_values_generic;
+ break;
+
+ default:
+ break;
+ }
+}
+
+/**
+ * This is a software fallback for the gl_renderbuffer->AllocStorage
+ * function.
+ * Device drivers will typically override this function for the buffers
+ * which it manages (typically color buffers, Z and stencil).
+ * Other buffers (like software accumulation and aux buffers) which the driver
+ * doesn't manage can be handled with this function.
+ *
+ * This one multi-purpose function can allocate stencil, depth, accum, color
+ * or color-index buffers!
+ *
+ * This function also plugs in the appropriate GetPointer, Get/PutRow and
+ * Get/PutValues functions.
+ */
+GLboolean
+_mesa_soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLenum internalFormat,
+ GLuint width, GLuint height)
+{
+ switch (internalFormat) {
+ case GL_RGB:
+ case GL_R3_G3_B2:
+ case GL_RGB4:
+ case GL_RGB5:
+ case GL_RGB8:
+ case GL_RGB10:
+ case GL_RGB12:
+ case GL_RGB16:
+ rb->Format = MESA_FORMAT_RGB888;
+ break;
+ case GL_RGBA:
+ case GL_RGBA2:
+ case GL_RGBA4:
+ case GL_RGB5_A1:
+ case GL_RGBA8:
+#if 1
+ case GL_RGB10_A2:
+ case GL_RGBA12:
+#endif
+ rb->Format = MESA_FORMAT_RGBA8888;
+ break;
+ case GL_RGBA16:
+ case GL_RGBA16_SNORM:
+ /* for accum buffer */
+ rb->Format = MESA_FORMAT_SIGNED_RGBA_16;
+ break;
+#if 0
+ case GL_ALPHA8:
+ rb->Format = MESA_FORMAT_A8;
+ break;
+#endif
+ case GL_STENCIL_INDEX:
+ case GL_STENCIL_INDEX1_EXT:
+ case GL_STENCIL_INDEX4_EXT:
+ case GL_STENCIL_INDEX8_EXT:
+ case GL_STENCIL_INDEX16_EXT:
+ rb->Format = MESA_FORMAT_S8;
+ break;
+ case GL_DEPTH_COMPONENT:
+ case GL_DEPTH_COMPONENT16:
+ rb->Format = MESA_FORMAT_Z16;
+ break;
+ case GL_DEPTH_COMPONENT24:
+ rb->Format = MESA_FORMAT_X8_Z24;
+ break;
+ case GL_DEPTH_COMPONENT32:
rb->Format = MESA_FORMAT_Z32;
- pixelSize = sizeof(GLuint);
break;
case GL_DEPTH_STENCIL_EXT:
case GL_DEPTH24_STENCIL8_EXT:
rb->Format = MESA_FORMAT_Z24_S8;
- rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
- rb->GetPointer = get_pointer_uint;
- rb->GetRow = get_row_uint;
- rb->GetValues = get_values_uint;
- rb->PutRow = put_row_uint;
- rb->PutRowRGB = NULL;
- rb->PutMonoRow = put_mono_row_uint;
- rb->PutValues = put_values_uint;
- rb->PutMonoValues = put_mono_values_uint;
- pixelSize = sizeof(GLuint);
break;
default:
/* unsupported format */
return GL_FALSE;
}
+ _mesa_set_renderbuffer_accessors(rb);
+
ASSERT(rb->DataType);
ASSERT(rb->GetPointer);
ASSERT(rb->GetRow);
@@ -1105,16 +1674,19 @@ _mesa_soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *
rb->Data = NULL;
}
+ rb->RowStride = width;
+
if (width > 0 && height > 0) {
/* allocate new buffer storage */
- rb->Data = malloc(width * height * pixelSize);
+ rb->Data = malloc(width * height * _mesa_get_format_bytes(rb->Format));
if (rb->Data == NULL) {
rb->Width = 0;
rb->Height = 0;
+ rb->RowStride = 0;
_mesa_error(ctx, GL_OUT_OF_MEMORY,
"software renderbuffer allocation (%d x %d x %d)",
- width, height, pixelSize);
+ width, height, _mesa_get_format_bytes(rb->Format));
return GL_FALSE;
}
}
@@ -1185,6 +1757,7 @@ alloc_storage_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb,
arb->Width = width;
arb->Height = height;
+ arb->RowStride = width;
return GL_TRUE;
}
@@ -1220,7 +1793,7 @@ get_row_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb, GLuint count
GLint x, GLint y, void *values)
{
/* NOTE: 'values' is RGBA format! */
- const GLubyte *src = (const GLubyte *) arb->Data + y * arb->Width + x;
+ const GLubyte *src = (const GLubyte *) arb->Data + y * arb->RowStride + x;
GLubyte *dst = (GLubyte *) values;
GLuint i;
ASSERT(arb != arb->Wrapped);
@@ -1246,7 +1819,7 @@ get_values_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb, GLuint co
arb->Wrapped->GetValues(ctx, arb->Wrapped, count, x, y, values);
/* second, fill in alpha values from this buffer! */
for (i = 0; i < count; i++) {
- const GLubyte *src = (GLubyte *) arb->Data + y[i] * arb->Width + x[i];
+ const GLubyte *src = (GLubyte *) arb->Data + y[i] * arb->RowStride + x[i];
dst[i * 4 + 3] = *src;
}
}
@@ -1257,7 +1830,7 @@ put_row_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb, GLuint count
GLint x, GLint y, const void *values, const GLubyte *mask)
{
const GLubyte *src = (const GLubyte *) values;
- GLubyte *dst = (GLubyte *) arb->Data + y * arb->Width + x;
+ GLubyte *dst = (GLubyte *) arb->Data + y * arb->RowStride + x;
GLuint i;
ASSERT(arb != arb->Wrapped);
ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
@@ -1277,7 +1850,7 @@ put_row_rgb_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb, GLuint c
GLint x, GLint y, const void *values, const GLubyte *mask)
{
const GLubyte *src = (const GLubyte *) values;
- GLubyte *dst = (GLubyte *) arb->Data + y * arb->Width + x;
+ GLubyte *dst = (GLubyte *) arb->Data + y * arb->RowStride + x;
GLuint i;
ASSERT(arb != arb->Wrapped);
ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
@@ -1297,7 +1870,7 @@ put_mono_row_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb, GLuint
GLint x, GLint y, const void *value, const GLubyte *mask)
{
const GLubyte val = ((const GLubyte *) value)[3];
- GLubyte *dst = (GLubyte *) arb->Data + y * arb->Width + x;
+ GLubyte *dst = (GLubyte *) arb->Data + y * arb->RowStride + x;
ASSERT(arb != arb->Wrapped);
ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
/* first, pass the call to the wrapped RGB buffer */
@@ -1331,7 +1904,7 @@ put_values_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb, GLuint co
/* second, store alpha in our buffer */
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
- GLubyte *dst = (GLubyte *) arb->Data + y[i] * arb->Width + x[i];
+ GLubyte *dst = (GLubyte *) arb->Data + y[i] * arb->RowStride + x[i];
*dst = src[i * 4 + 3];
}
}
@@ -1352,7 +1925,7 @@ put_mono_values_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb,
/* second, store alpha in our buffer */
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
- GLubyte *dst = (GLubyte *) arb->Data + y[i] * arb->Width + x[i];
+ GLubyte *dst = (GLubyte *) arb->Data + y[i] * arb->RowStride + x[i];
*dst = val;
}
}
@@ -1366,8 +1939,9 @@ copy_buffer_alpha8(struct gl_renderbuffer* dst, struct gl_renderbuffer* src)
ASSERT(src->Format == MESA_FORMAT_A8);
ASSERT(dst->Width == src->Width);
ASSERT(dst->Height == src->Height);
+ ASSERT(dst->RowStride == src->RowStride);
- memcpy(dst->Data, src->Data, dst->Width * dst->Height * sizeof(GLubyte));
+ memcpy(dst->Data, src->Data, dst->RowStride * dst->Height * sizeof(GLubyte));
}
@@ -1395,7 +1969,6 @@ _mesa_init_renderbuffer(struct gl_renderbuffer *rb, GLuint name)
{
_glthread_INIT_MUTEX(rb->Mutex);
- rb->Magic = RB_MAGIC;
rb->ClassID = 0;
rb->Name = name;
rb->RefCount = 0;
@@ -1970,9 +2543,7 @@ _mesa_reference_renderbuffer(struct gl_renderbuffer **ptr,
GLboolean deleteFlag = GL_FALSE;
struct gl_renderbuffer *oldRb = *ptr;
- assert(oldRb->Magic == RB_MAGIC);
_glthread_LOCK_MUTEX(oldRb->Mutex);
- assert(oldRb->Magic == RB_MAGIC);
ASSERT(oldRb->RefCount > 0);
oldRb->RefCount--;
/*printf("RB DECR %p (%d) to %d\n", (void*) oldRb, oldRb->Name, oldRb->RefCount);*/
@@ -1980,7 +2551,6 @@ _mesa_reference_renderbuffer(struct gl_renderbuffer **ptr,
_glthread_UNLOCK_MUTEX(oldRb->Mutex);
if (deleteFlag) {
- oldRb->Magic = 0; /* now invalid memory! */
oldRb->Delete(oldRb);
}
@@ -1989,7 +2559,6 @@ _mesa_reference_renderbuffer(struct gl_renderbuffer **ptr,
assert(!*ptr);
if (rb) {
- assert(rb->Magic == RB_MAGIC);
/* reference new renderbuffer */
_glthread_LOCK_MUTEX(rb->Mutex);
rb->RefCount++;