summaryrefslogtreecommitdiffstats
path: root/src/mesa/main
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2009-10-28 21:24:11 -0600
committerBrian Paul <[email protected]>2009-10-28 21:24:11 -0600
commit1f196b786d6bd0c6a5dbdc638574ff716cc3d4de (patch)
tree5ae2753b99070f8b35c51576bd39e52df63879d6 /src/mesa/main
parent0ea575d721821262a862ceef010db9b1a8b4a6d9 (diff)
parent086f9fc0e2aef27f54eda87c733685500555bf20 (diff)
Merge branch 'texformat-rework'
Conflicts: src/mesa/drivers/dri/radeon/radeon_fbo.c src/mesa/drivers/dri/s3v/s3v_tex.c src/mesa/drivers/dri/s3v/s3v_xmesa.c src/mesa/drivers/dri/trident/trident_context.c src/mesa/main/debug.c src/mesa/main/mipmap.c src/mesa/main/texformat.c src/mesa/main/texgetimage.c
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/colormac.h14
-rw-r--r--src/mesa/main/dd.h11
-rw-r--r--src/mesa/main/debug.c7
-rw-r--r--src/mesa/main/depthstencil.c344
-rw-r--r--src/mesa/main/fbobject.c202
-rw-r--r--src/mesa/main/formats.c1110
-rw-r--r--src/mesa/main/formats.h181
-rw-r--r--src/mesa/main/framebuffer.c70
-rw-r--r--src/mesa/main/mipmap.c78
-rw-r--r--src/mesa/main/mtypes.h102
-rw-r--r--src/mesa/main/rbadaptors.c18
-rw-r--r--src/mesa/main/renderbuffer.c255
-rw-r--r--src/mesa/main/texcompress.c243
-rw-r--r--src/mesa/main/texcompress.h21
-rw-r--r--src/mesa/main/texcompress_fxt1.c99
-rw-r--r--src/mesa/main/texcompress_fxt1.h53
-rw-r--r--src/mesa/main/texcompress_s3tc.c291
-rw-r--r--src/mesa/main/texcompress_s3tc.h75
-rw-r--r--src/mesa/main/texfetch.c665
-rw-r--r--src/mesa/main/texfetch.h40
-rw-r--r--src/mesa/main/texfetch_tmp.h (renamed from src/mesa/main/texformat_tmp.h)214
-rw-r--r--src/mesa/main/texformat.c1779
-rw-r--r--src/mesa/main/texformat.h264
-rw-r--r--src/mesa/main/texgetimage.c67
-rw-r--r--src/mesa/main/teximage.c134
-rw-r--r--src/mesa/main/texobj.c5
-rw-r--r--src/mesa/main/texparam.c88
-rw-r--r--src/mesa/main/texrender.c47
-rw-r--r--src/mesa/main/texstore.c1205
-rw-r--r--src/mesa/main/texstore.h77
30 files changed, 3654 insertions, 4105 deletions
diff --git a/src/mesa/main/colormac.h b/src/mesa/main/colormac.h
index 815624ee508..7ae781ae23d 100644
--- a/src/mesa/main/colormac.h
+++ b/src/mesa/main/colormac.h
@@ -140,9 +140,9 @@
*/
#define UNCLAMPED_FLOAT_TO_RGB_CHAN(dst, f) \
do { \
- UNCLAMPED_FLOAT_TO_CHAN(dst[0], f[0]); \
- UNCLAMPED_FLOAT_TO_CHAN(dst[1], f[1]); \
- UNCLAMPED_FLOAT_TO_CHAN(dst[2], f[2]); \
+ UNCLAMPED_FLOAT_TO_CHAN((dst)[0], (f)[0]); \
+ UNCLAMPED_FLOAT_TO_CHAN((dst)[1], (f)[1]); \
+ UNCLAMPED_FLOAT_TO_CHAN((dst)[2], (f)[2]); \
} while (0)
@@ -156,10 +156,10 @@ do { \
*/
#define UNCLAMPED_FLOAT_TO_RGBA_CHAN(dst, f) \
do { \
- UNCLAMPED_FLOAT_TO_CHAN(dst[0], f[0]); \
- UNCLAMPED_FLOAT_TO_CHAN(dst[1], f[1]); \
- UNCLAMPED_FLOAT_TO_CHAN(dst[2], f[2]); \
- UNCLAMPED_FLOAT_TO_CHAN(dst[3], f[3]); \
+ UNCLAMPED_FLOAT_TO_CHAN((dst)[0], (f)[0]); \
+ UNCLAMPED_FLOAT_TO_CHAN((dst)[1], (f)[1]); \
+ UNCLAMPED_FLOAT_TO_CHAN((dst)[2], (f)[2]); \
+ UNCLAMPED_FLOAT_TO_CHAN((dst)[3], (f)[3]); \
} while (0)
diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index 25aaddea81f..99f2cad4028 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -184,8 +184,8 @@ struct dd_function_table {
* functions. The driver should examine \p internalFormat and return a
* pointer to an appropriate gl_texture_format.
*/
- const struct gl_texture_format *(*ChooseTextureFormat)( GLcontext *ctx,
- GLint internalFormat, GLenum srcFormat, GLenum srcType );
+ GLuint (*ChooseTextureFormat)( GLcontext *ctx, GLint internalFormat,
+ GLenum srcFormat, GLenum srcType );
/**
* Called by glTexImage1D().
@@ -475,13 +475,6 @@ struct dd_function_table {
struct gl_texture_object *texObj,
struct gl_texture_image *texImage);
- /**
- * Called to query number of bytes of storage needed to store the
- * specified compressed texture.
- */
- GLuint (*CompressedTextureSize)( GLcontext *ctx, GLsizei width,
- GLsizei height, GLsizei depth,
- GLenum format );
/*@}*/
/**
diff --git a/src/mesa/main/debug.c b/src/mesa/main/debug.c
index 24ced0d6c96..ee8cc29301d 100644
--- a/src/mesa/main/debug.c
+++ b/src/mesa/main/debug.c
@@ -28,6 +28,7 @@
#include "colormac.h"
#include "context.h"
#include "enums.h"
+#include "formats.h"
#include "hash.h"
#include "imports.h"
#include "debug.h"
@@ -36,7 +37,6 @@
#include "readpix.h"
#include "texgetimage.h"
#include "texobj.h"
-#include "texformat.h"
/**
@@ -388,10 +388,11 @@ dump_texture(struct gl_texture_object *texObj, GLuint writeImages)
for (j = 0; j < numFaces; j++) {
struct gl_texture_image *texImg = texObj->Image[j][i];
if (texImg) {
- _mesa_printf(" Face %u level %u: %d x %d x %d, format %u at %p\n",
+ _mesa_printf(" Face %u level %u: %d x %d x %d, format %s at %p\n",
j, i,
texImg->Width, texImg->Height, texImg->Depth,
- texImg->TexFormat->MesaFormat, texImg->Data);
+ _mesa_get_format_name(texImg->TexFormat),
+ texImg->Data);
if (writeImages == WRITE_ALL ||
(writeImages == WRITE_ONE && !written)) {
write_texture_image(texObj, j, i);
diff --git a/src/mesa/main/depthstencil.c b/src/mesa/main/depthstencil.c
index 7be2aacaf2c..193c7f8255f 100644
--- a/src/mesa/main/depthstencil.c
+++ b/src/mesa/main/depthstencil.c
@@ -26,6 +26,7 @@
#include "imports.h"
#include "context.h"
#include "fbobject.h"
+#include "formats.h"
#include "mtypes.h"
#include "depthstencil.h"
#include "renderbuffer.h"
@@ -40,8 +41,8 @@
* a combined Z+stencil buffer! That implies we need three different sets
* of Get/Put functions.
*
- * We solve this by wrapping the Z24_S8 renderbuffer with depth and stencil
- * adaptors, each with the right kind of depth/stencil Get/Put functions.
+ * We solve this by wrapping the Z24_S8 or S8_Z24 renderbuffer with depth and
+ * stencil adaptors, each with the right kind of depth/stencil Get/Put functions.
*/
@@ -62,8 +63,8 @@ nop_get_pointer(GLcontext *ctx, struct gl_renderbuffer *rb, GLint x, GLint y)
static void
delete_wrapper(struct gl_renderbuffer *rb)
{
- ASSERT(rb->_ActualFormat == GL_DEPTH_COMPONENT24 ||
- rb->_ActualFormat == GL_STENCIL_INDEX8_EXT);
+ ASSERT(rb->Format == MESA_FORMAT_Z24_S8 ||
+ rb->Format == MESA_FORMAT_S8_Z24);
_mesa_reference_renderbuffer(&rb->Wrapped, NULL);
_mesa_free(rb);
}
@@ -82,7 +83,8 @@ alloc_wrapper_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
(void) internalFormat;
- ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
+ ASSERT(dsrb->Format == MESA_FORMAT_Z24_S8 ||
+ dsrb->Format == MESA_FORMAT_S8_Z24);
retVal = dsrb->AllocStorage(ctx, dsrb, dsrb->InternalFormat, width, height);
if (retVal) {
@@ -108,14 +110,21 @@ get_row_z24(GLcontext *ctx, struct gl_renderbuffer *z24rb, GLuint count,
GLuint *dst = (GLuint *) values;
const GLuint *src = (const GLuint *) dsrb->GetPointer(ctx, dsrb, x, y);
ASSERT(z24rb->DataType == GL_UNSIGNED_INT);
- ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
if (!src) {
dsrb->GetRow(ctx, dsrb, count, x, y, temp);
src = temp;
}
- for (i = 0; i < count; i++) {
- dst[i] = src[i] >> 8;
+ if (dsrb->Format == MESA_FORMAT_Z24_S8) {
+ for (i = 0; i < count; i++) {
+ dst[i] = src[i] >> 8;
+ }
+ }
+ else {
+ assert(dsrb->Format == MESA_FORMAT_S8_Z24);
+ for (i = 0; i < count; i++) {
+ dst[i] = src[i] & 0xffffff;
+ }
}
}
@@ -127,13 +136,20 @@ get_values_z24(GLcontext *ctx, struct gl_renderbuffer *z24rb, GLuint count,
GLuint temp[MAX_WIDTH], i;
GLuint *dst = (GLuint *) values;
ASSERT(z24rb->DataType == GL_UNSIGNED_INT);
- ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
ASSERT(count <= MAX_WIDTH);
/* don't bother trying direct access */
dsrb->GetValues(ctx, dsrb, count, x, y, temp);
- for (i = 0; i < count; i++) {
- dst[i] = temp[i] >> 8;
+ if (dsrb->Format == MESA_FORMAT_Z24_S8) {
+ for (i = 0; i < count; i++) {
+ dst[i] = temp[i] >> 8;
+ }
+ }
+ else {
+ assert(dsrb->Format == MESA_FORMAT_S8_Z24);
+ for (i = 0; i < count; i++) {
+ dst[i] = temp[i] & 0xffffff;
+ }
}
}
@@ -145,14 +161,23 @@ put_row_z24(GLcontext *ctx, struct gl_renderbuffer *z24rb, GLuint count,
const GLuint *src = (const GLuint *) values;
GLuint *dst = (GLuint *) dsrb->GetPointer(ctx, dsrb, x, y);
ASSERT(z24rb->DataType == GL_UNSIGNED_INT);
- ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
if (dst) {
/* direct access */
GLuint i;
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- dst[i] = (src[i] << 8) | (dst[i] & 0xff);
+ if (dsrb->Format == MESA_FORMAT_Z24_S8) {
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ dst[i] = (src[i] << 8) | (dst[i] & 0xff);
+ }
+ }
+ }
+ else {
+ assert(dsrb->Format == MESA_FORMAT_S8_Z24);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ dst[i] = (src[i] & 0xffffff) | (dst[i] & 0xff000000);
+ }
}
}
}
@@ -160,9 +185,19 @@ put_row_z24(GLcontext *ctx, struct gl_renderbuffer *z24rb, GLuint count,
/* get, modify, put */
GLuint temp[MAX_WIDTH], i;
dsrb->GetRow(ctx, dsrb, count, x, y, temp);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- temp[i] = (src[i] << 8) | (temp[i] & 0xff);
+ if (dsrb->Format == MESA_FORMAT_Z24_S8) {
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ temp[i] = (src[i] << 8) | (temp[i] & 0xff);
+ }
+ }
+ }
+ else {
+ assert(dsrb->Format == MESA_FORMAT_S8_Z24);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ temp[i] = (src[i] & 0xffffff) | (temp[i] & 0xff000000);
+ }
}
}
dsrb->PutRow(ctx, dsrb, count, x, y, temp, mask);
@@ -174,17 +209,27 @@ put_mono_row_z24(GLcontext *ctx, struct gl_renderbuffer *z24rb, GLuint count,
GLint x, GLint y, const void *value, const GLubyte *mask)
{
struct gl_renderbuffer *dsrb = z24rb->Wrapped;
- const GLuint shiftedVal = *((GLuint *) value) << 8;
GLuint *dst = (GLuint *) dsrb->GetPointer(ctx, dsrb, x, y);
ASSERT(z24rb->DataType == GL_UNSIGNED_INT);
- ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
if (dst) {
/* direct access */
GLuint i;
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- dst[i] = shiftedVal | (dst[i] & 0xff);
+ if (dsrb->Format == MESA_FORMAT_Z24_S8) {
+ const GLuint shiftedVal = *((GLuint *) value) << 8;
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ dst[i] = shiftedVal | (dst[i] & 0xff);
+ }
+ }
+ }
+ else {
+ const GLuint shiftedVal = *((GLuint *) value);
+ assert(dsrb->Format == MESA_FORMAT_S8_Z24);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ dst[i] = shiftedVal | (dst[i] & 0xff000000);
+ }
}
}
}
@@ -192,9 +237,21 @@ put_mono_row_z24(GLcontext *ctx, struct gl_renderbuffer *z24rb, GLuint count,
/* get, modify, put */
GLuint temp[MAX_WIDTH], i;
dsrb->GetRow(ctx, dsrb, count, x, y, temp);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- temp[i] = shiftedVal | (temp[i] & 0xff);
+ if (dsrb->Format == MESA_FORMAT_Z24_S8) {
+ const GLuint shiftedVal = *((GLuint *) value) << 8;
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ temp[i] = shiftedVal | (temp[i] & 0xff);
+ }
+ }
+ }
+ else {
+ const GLuint shiftedVal = *((GLuint *) value);
+ assert(dsrb->Format == MESA_FORMAT_S8_Z24);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ temp[i] = shiftedVal | (temp[i] & 0xff000000);
+ }
}
}
dsrb->PutRow(ctx, dsrb, count, x, y, temp, mask);
@@ -209,15 +266,25 @@ put_values_z24(GLcontext *ctx, struct gl_renderbuffer *z24rb, GLuint count,
struct gl_renderbuffer *dsrb = z24rb->Wrapped;
const GLuint *src = (const GLuint *) values;
ASSERT(z24rb->DataType == GL_UNSIGNED_INT);
- ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
if (dsrb->GetPointer(ctx, dsrb, 0, 0)) {
/* direct access */
GLuint i;
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- GLuint *dst = (GLuint *) dsrb->GetPointer(ctx, dsrb, x[i], y[i]);
- *dst = (src[i] << 8) | (*dst & 0xff);
+ if (dsrb->Format == MESA_FORMAT_Z24_S8) {
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ GLuint *dst = (GLuint *) dsrb->GetPointer(ctx, dsrb, x[i], y[i]);
+ *dst = (src[i] << 8) | (*dst & 0xff);
+ }
+ }
+ }
+ else {
+ assert(dsrb->Format == MESA_FORMAT_S8_Z24);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ GLuint *dst = (GLuint *) dsrb->GetPointer(ctx, dsrb, x[i], y[i]);
+ *dst = (src[i] & 0xffffff) | (*dst & 0xff000000);
+ }
}
}
}
@@ -225,9 +292,19 @@ put_values_z24(GLcontext *ctx, struct gl_renderbuffer *z24rb, GLuint count,
/* get, modify, put */
GLuint temp[MAX_WIDTH], i;
dsrb->GetValues(ctx, dsrb, count, x, y, temp);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- temp[i] = (src[i] << 8) | (temp[i] & 0xff);
+ if (dsrb->Format == MESA_FORMAT_Z24_S8) {
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ temp[i] = (src[i] << 8) | (temp[i] & 0xff);
+ }
+ }
+ }
+ else {
+ assert(dsrb->Format == MESA_FORMAT_S8_Z24);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ temp[i] = (src[i] & 0xffffff) | (temp[i] & 0xff000000);
+ }
}
}
dsrb->PutValues(ctx, dsrb, count, x, y, temp, mask);
@@ -241,12 +318,23 @@ put_mono_values_z24(GLcontext *ctx, struct gl_renderbuffer *z24rb,
{
struct gl_renderbuffer *dsrb = z24rb->Wrapped;
GLuint temp[MAX_WIDTH], i;
- const GLuint shiftedVal = *((GLuint *) value) << 8;
/* get, modify, put */
dsrb->GetValues(ctx, dsrb, count, x, y, temp);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- temp[i] = shiftedVal | (temp[i] & 0xff);
+ if (dsrb->Format == MESA_FORMAT_Z24_S8) {
+ const GLuint shiftedVal = *((GLuint *) value) << 8;
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ temp[i] = shiftedVal | (temp[i] & 0xff);
+ }
+ }
+ }
+ else {
+ const GLuint shiftedVal = *((GLuint *) value);
+ assert(dsrb->Format == MESA_FORMAT_S8_Z24);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ temp[i] = shiftedVal | (temp[i] & 0xff000000);
+ }
}
}
dsrb->PutValues(ctx, dsrb, count, x, y, temp, mask);
@@ -264,7 +352,8 @@ _mesa_new_z24_renderbuffer_wrapper(GLcontext *ctx,
{
struct gl_renderbuffer *z24rb;
- ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
+ ASSERT(dsrb->Format == MESA_FORMAT_Z24_S8 ||
+ dsrb->Format == MESA_FORMAT_S8_Z24);
ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
z24rb = _mesa_new_renderbuffer(ctx, 0);
@@ -277,10 +366,9 @@ _mesa_new_z24_renderbuffer_wrapper(GLcontext *ctx,
z24rb->Width = dsrb->Width;
z24rb->Height = dsrb->Height;
z24rb->InternalFormat = GL_DEPTH_COMPONENT24;
- z24rb->_ActualFormat = GL_DEPTH_COMPONENT24;
+ z24rb->Format = MESA_FORMAT_X8_Z24;
z24rb->_BaseFormat = GL_DEPTH_COMPONENT;
z24rb->DataType = GL_UNSIGNED_INT;
- z24rb->DepthBits = 24;
z24rb->Data = NULL;
z24rb->Delete = delete_wrapper;
z24rb->AllocStorage = alloc_wrapper_storage;
@@ -310,14 +398,21 @@ get_row_s8(GLcontext *ctx, struct gl_renderbuffer *s8rb, GLuint count,
GLubyte *dst = (GLubyte *) values;
const GLuint *src = (const GLuint *) dsrb->GetPointer(ctx, dsrb, x, y);
ASSERT(s8rb->DataType == GL_UNSIGNED_BYTE);
- ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
if (!src) {
dsrb->GetRow(ctx, dsrb, count, x, y, temp);
src = temp;
}
- for (i = 0; i < count; i++) {
- dst[i] = src[i] & 0xff;
+ if (dsrb->Format == MESA_FORMAT_Z24_S8) {
+ for (i = 0; i < count; i++) {
+ dst[i] = src[i] & 0xff;
+ }
+ }
+ else {
+ assert(dsrb->Format == MESA_FORMAT_S8_Z24);
+ for (i = 0; i < count; i++) {
+ dst[i] = src[i] >> 24;
+ }
}
}
@@ -329,13 +424,20 @@ get_values_s8(GLcontext *ctx, struct gl_renderbuffer *s8rb, GLuint count,
GLuint temp[MAX_WIDTH], i;
GLubyte *dst = (GLubyte *) values;
ASSERT(s8rb->DataType == GL_UNSIGNED_BYTE);
- ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
ASSERT(count <= MAX_WIDTH);
/* don't bother trying direct access */
dsrb->GetValues(ctx, dsrb, count, x, y, temp);
- for (i = 0; i < count; i++) {
- dst[i] = temp[i] & 0xff;
+ if (dsrb->Format == MESA_FORMAT_Z24_S8) {
+ for (i = 0; i < count; i++) {
+ dst[i] = temp[i] & 0xff;
+ }
+ }
+ else {
+ assert(dsrb->Format == MESA_FORMAT_S8_Z24);
+ for (i = 0; i < count; i++) {
+ dst[i] = temp[i] >> 24;
+ }
}
}
@@ -347,14 +449,23 @@ put_row_s8(GLcontext *ctx, struct gl_renderbuffer *s8rb, GLuint count,
const GLubyte *src = (const GLubyte *) values;
GLuint *dst = (GLuint *) dsrb->GetPointer(ctx, dsrb, x, y);
ASSERT(s8rb->DataType == GL_UNSIGNED_BYTE);
- ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
if (dst) {
/* direct access */
GLuint i;
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- dst[i] = (dst[i] & 0xffffff00) | src[i];
+ if (dsrb->Format == MESA_FORMAT_Z24_S8) {
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ dst[i] = (dst[i] & 0xffffff00) | src[i];
+ }
+ }
+ }
+ else {
+ assert(dsrb->Format == MESA_FORMAT_S8_Z24);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ dst[i] = (dst[i] & 0xffffff) | (src[i] << 24);
+ }
}
}
}
@@ -362,9 +473,19 @@ put_row_s8(GLcontext *ctx, struct gl_renderbuffer *s8rb, GLuint count,
/* get, modify, put */
GLuint temp[MAX_WIDTH], i;
dsrb->GetRow(ctx, dsrb, count, x, y, temp);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- temp[i] = (temp[i] & 0xffffff00) | src[i];
+ if (dsrb->Format == MESA_FORMAT_Z24_S8) {
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ temp[i] = (temp[i] & 0xffffff00) | src[i];
+ }
+ }
+ }
+ else {
+ assert(dsrb->Format == MESA_FORMAT_S8_Z24);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ temp[i] = (temp[i] & 0xffffff) | (src[i] << 24);
+ }
}
}
dsrb->PutRow(ctx, dsrb, count, x, y, temp, mask);
@@ -379,14 +500,23 @@ put_mono_row_s8(GLcontext *ctx, struct gl_renderbuffer *s8rb, GLuint count,
const GLubyte val = *((GLubyte *) value);
GLuint *dst = (GLuint *) dsrb->GetPointer(ctx, dsrb, x, y);
ASSERT(s8rb->DataType == GL_UNSIGNED_BYTE);
- ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
if (dst) {
/* direct access */
GLuint i;
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- dst[i] = (dst[i] & 0xffffff00) | val;
+ if (dsrb->Format == MESA_FORMAT_Z24_S8) {
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ dst[i] = (dst[i] & 0xffffff00) | val;
+ }
+ }
+ }
+ else {
+ assert(dsrb->Format == MESA_FORMAT_S8_Z24);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ dst[i] = (dst[i] & 0xffffff) | (val << 24);
+ }
}
}
}
@@ -394,9 +524,19 @@ put_mono_row_s8(GLcontext *ctx, struct gl_renderbuffer *s8rb, GLuint count,
/* get, modify, put */
GLuint temp[MAX_WIDTH], i;
dsrb->GetRow(ctx, dsrb, count, x, y, temp);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- temp[i] = (temp[i] & 0xffffff00) | val;
+ if (dsrb->Format == MESA_FORMAT_Z24_S8) {
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ temp[i] = (temp[i] & 0xffffff00) | val;
+ }
+ }
+ }
+ else {
+ assert(dsrb->Format == MESA_FORMAT_S8_Z24);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ temp[i] = (temp[i] & 0xffffff) | (val << 24);
+ }
}
}
dsrb->PutRow(ctx, dsrb, count, x, y, temp, mask);
@@ -411,15 +551,25 @@ put_values_s8(GLcontext *ctx, struct gl_renderbuffer *s8rb, GLuint count,
struct gl_renderbuffer *dsrb = s8rb->Wrapped;
const GLubyte *src = (const GLubyte *) values;
ASSERT(s8rb->DataType == GL_UNSIGNED_BYTE);
- ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
if (dsrb->GetPointer(ctx, dsrb, 0, 0)) {
/* direct access */
GLuint i;
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- GLuint *dst = (GLuint *) dsrb->GetPointer(ctx, dsrb, x[i], y[i]);
- *dst = (*dst & 0xffffff00) | src[i];
+ if (dsrb->Format == MESA_FORMAT_Z24_S8) {
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ GLuint *dst = (GLuint *) dsrb->GetPointer(ctx, dsrb, x[i], y[i]);
+ *dst = (*dst & 0xffffff00) | src[i];
+ }
+ }
+ }
+ else {
+ assert(dsrb->Format == MESA_FORMAT_S8_Z24);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ GLuint *dst = (GLuint *) dsrb->GetPointer(ctx, dsrb, x[i], y[i]);
+ *dst = (*dst & 0xffffff) | (src[i] << 24);
+ }
}
}
}
@@ -427,9 +577,19 @@ put_values_s8(GLcontext *ctx, struct gl_renderbuffer *s8rb, GLuint count,
/* get, modify, put */
GLuint temp[MAX_WIDTH], i;
dsrb->GetValues(ctx, dsrb, count, x, y, temp);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- temp[i] = (temp[i] & 0xffffff00) | src[i];
+ if (dsrb->Format == MESA_FORMAT_Z24_S8) {
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ temp[i] = (temp[i] & 0xffffff00) | src[i];
+ }
+ }
+ }
+ else {
+ assert(dsrb->Format == MESA_FORMAT_S8_Z24);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ temp[i] = (temp[i] & 0xffffff) | (src[i] << 24);
+ }
}
}
dsrb->PutValues(ctx, dsrb, count, x, y, temp, mask);
@@ -446,9 +606,19 @@ put_mono_values_s8(GLcontext *ctx, struct gl_renderbuffer *s8rb, GLuint count,
const GLubyte val = *((GLubyte *) value);
/* get, modify, put */
dsrb->GetValues(ctx, dsrb, count, x, y, temp);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- temp[i] = (temp[i] & 0xffffff) | val;
+ if (dsrb->Format == MESA_FORMAT_Z24_S8) {
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ temp[i] = (temp[i] & 0xffffff00) | val;
+ }
+ }
+ }
+ else {
+ assert(dsrb->Format == MESA_FORMAT_S8_Z24);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ temp[i] = (temp[i] & 0xffffff) | (val << 24);
+ }
}
}
dsrb->PutValues(ctx, dsrb, count, x, y, temp, mask);
@@ -465,7 +635,8 @@ _mesa_new_s8_renderbuffer_wrapper(GLcontext *ctx, struct gl_renderbuffer *dsrb)
{
struct gl_renderbuffer *s8rb;
- ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
+ ASSERT(dsrb->Format == MESA_FORMAT_Z24_S8 ||
+ dsrb->Format == MESA_FORMAT_S8_Z24);
ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
s8rb = _mesa_new_renderbuffer(ctx, 0);
@@ -478,10 +649,9 @@ _mesa_new_s8_renderbuffer_wrapper(GLcontext *ctx, struct gl_renderbuffer *dsrb)
s8rb->Width = dsrb->Width;
s8rb->Height = dsrb->Height;
s8rb->InternalFormat = GL_STENCIL_INDEX8_EXT;
- s8rb->_ActualFormat = GL_STENCIL_INDEX8_EXT;
+ s8rb->Format = MESA_FORMAT_S8;
s8rb->_BaseFormat = GL_STENCIL_INDEX;
s8rb->DataType = GL_UNSIGNED_BYTE;
- s8rb->StencilBits = 8;
s8rb->Data = NULL;
s8rb->Delete = delete_wrapper;
s8rb->AllocStorage = alloc_wrapper_storage;
@@ -528,10 +698,10 @@ _mesa_extract_stencil(GLcontext *ctx,
ASSERT(dsRb);
ASSERT(stencilRb);
- ASSERT(dsRb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
+ ASSERT(dsRb->Format == MESA_FORMAT_Z24_S8);
ASSERT(dsRb->DataType == GL_UNSIGNED_INT_24_8_EXT);
- ASSERT(stencilRb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT ||
- stencilRb->_ActualFormat == GL_STENCIL_INDEX8_EXT);
+ ASSERT(stencilRb->Format == MESA_FORMAT_Z24_S8 ||
+ stencilRb->Format == MESA_FORMAT_S8);
ASSERT(dsRb->Width == stencilRb->Width);
ASSERT(dsRb->Height == stencilRb->Height);
@@ -541,7 +711,7 @@ _mesa_extract_stencil(GLcontext *ctx,
for (row = 0; row < height; row++) {
GLuint depthStencil[MAX_WIDTH];
dsRb->GetRow(ctx, dsRb, width, 0, row, depthStencil);
- if (stencilRb->_ActualFormat == GL_STENCIL_INDEX8_EXT) {
+ if (stencilRb->Format == MESA_FORMAT_S8) {
/* 8bpp stencil */
GLubyte stencil[MAX_WIDTH];
GLuint i;
@@ -553,7 +723,7 @@ _mesa_extract_stencil(GLcontext *ctx,
else {
/* 32bpp stencil */
/* the 24 depth bits will be ignored */
- ASSERT(stencilRb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
+ ASSERT(stencilRb->Format == MESA_FORMAT_Z24_S8);
ASSERT(stencilRb->DataType == GL_UNSIGNED_INT_24_8_EXT);
stencilRb->PutRow(ctx, stencilRb, width, 0, row, depthStencil, NULL);
}
@@ -577,10 +747,10 @@ _mesa_insert_stencil(GLcontext *ctx,
ASSERT(dsRb);
ASSERT(stencilRb);
- ASSERT(dsRb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
+ ASSERT(dsRb->Format == MESA_FORMAT_Z24_S8);
ASSERT(dsRb->DataType == GL_UNSIGNED_INT_24_8_EXT);
- ASSERT(stencilRb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT ||
- stencilRb->_ActualFormat == GL_STENCIL_INDEX8_EXT);
+ ASSERT(stencilRb->Format == MESA_FORMAT_Z24_S8 ||
+ stencilRb->Format == MESA_FORMAT_S8);
ASSERT(dsRb->Width == stencilRb->Width);
ASSERT(dsRb->Height == stencilRb->Height);
@@ -593,7 +763,7 @@ _mesa_insert_stencil(GLcontext *ctx,
dsRb->GetRow(ctx, dsRb, width, 0, row, depthStencil);
- if (stencilRb->_ActualFormat == GL_STENCIL_INDEX8_EXT) {
+ if (stencilRb->Format == MESA_FORMAT_S8) {
/* 8bpp stencil */
GLubyte stencil[MAX_WIDTH];
GLuint i;
@@ -605,7 +775,7 @@ _mesa_insert_stencil(GLcontext *ctx,
else {
/* 32bpp stencil buffer */
GLuint stencil[MAX_WIDTH], i;
- ASSERT(stencilRb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
+ ASSERT(stencilRb->Format == MESA_FORMAT_Z24_S8);
ASSERT(stencilRb->DataType == GL_UNSIGNED_INT_24_8_EXT);
stencilRb->GetRow(ctx, stencilRb, width, 0, row, stencil);
for (i = 0; i < width; i++) {
@@ -631,7 +801,7 @@ _mesa_promote_stencil(GLcontext *ctx, struct gl_renderbuffer *stencilRb)
GLubyte *data;
GLint i, j, k;
- ASSERT(stencilRb->_ActualFormat == GL_STENCIL_INDEX8_EXT);
+ ASSERT(stencilRb->Format == MESA_FORMAT_S8);
ASSERT(stencilRb->Data);
data = (GLubyte *) stencilRb->Data;
@@ -650,6 +820,4 @@ _mesa_promote_stencil(GLcontext *ctx, struct gl_renderbuffer *stencilRb)
stencilRb->PutRow(ctx, stencilRb, width, 0, i, depthStencil, NULL);
}
_mesa_free(data);
-
- stencilRb->_BaseFormat = GL_DEPTH_STENCIL_EXT;
}
diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c
index 55709ebf9e3..1d6ccf7fdd8 100644
--- a/src/mesa/main/fbobject.c
+++ b/src/mesa/main/fbobject.c
@@ -36,6 +36,7 @@
#include "context.h"
#include "enums.h"
#include "fbobject.h"
+#include "formats.h"
#include "framebuffer.h"
#include "hash.h"
#include "macros.h"
@@ -356,6 +357,7 @@ test_attachment_completeness(const GLcontext *ctx, GLenum format,
if (att->Type == GL_TEXTURE) {
const struct gl_texture_object *texObj = att->Texture;
struct gl_texture_image *texImage;
+ GLenum baseFormat;
if (!texObj) {
att_incomplete("no texobj");
@@ -382,26 +384,28 @@ test_attachment_completeness(const GLcontext *ctx, GLenum format,
return;
}
+ baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
+
if (format == GL_COLOR) {
- if (texImage->TexFormat->BaseFormat != GL_RGB &&
- texImage->TexFormat->BaseFormat != GL_RGBA) {
+ if (baseFormat != GL_RGB &&
+ baseFormat != GL_RGBA) {
att_incomplete("bad format");
att->Complete = GL_FALSE;
return;
}
- if (texImage->TexFormat->TexelBytes == 0) {
+ if (_mesa_is_format_compressed(texImage->TexFormat)) {
att_incomplete("compressed internalformat");
att->Complete = GL_FALSE;
return;
}
}
else if (format == GL_DEPTH) {
- if (texImage->TexFormat->BaseFormat == GL_DEPTH_COMPONENT) {
+ if (baseFormat == GL_DEPTH_COMPONENT) {
/* OK */
}
else if (ctx->Extensions.EXT_packed_depth_stencil &&
ctx->Extensions.ARB_depth_texture &&
- texImage->TexFormat->BaseFormat == GL_DEPTH_STENCIL_EXT) {
+ baseFormat == GL_DEPTH_STENCIL_EXT) {
/* OK */
}
else {
@@ -412,10 +416,9 @@ test_attachment_completeness(const GLcontext *ctx, GLenum format,
}
else {
ASSERT(format == GL_STENCIL);
- ASSERT(att->Renderbuffer->StencilBits);
if (ctx->Extensions.EXT_packed_depth_stencil &&
ctx->Extensions.ARB_depth_texture &&
- att->Renderbuffer->_BaseFormat == GL_DEPTH_STENCIL_EXT) {
+ baseFormat == GL_DEPTH_STENCIL_EXT) {
/* OK */
}
else {
@@ -427,6 +430,9 @@ test_attachment_completeness(const GLcontext *ctx, GLenum format,
}
}
else if (att->Type == GL_RENDERBUFFER_EXT) {
+ const GLenum baseFormat =
+ _mesa_get_format_base_format(att->Renderbuffer->Format);
+
ASSERT(att->Renderbuffer);
if (!att->Renderbuffer->InternalFormat ||
att->Renderbuffer->Width < 1 ||
@@ -436,24 +442,19 @@ test_attachment_completeness(const GLcontext *ctx, GLenum format,
return;
}
if (format == GL_COLOR) {
- if (att->Renderbuffer->_BaseFormat != GL_RGB &&
- att->Renderbuffer->_BaseFormat != GL_RGBA) {
+ if (baseFormat != GL_RGB &&
+ baseFormat != GL_RGBA) {
att_incomplete("bad renderbuffer color format");
att->Complete = GL_FALSE;
return;
}
- ASSERT(att->Renderbuffer->RedBits);
- ASSERT(att->Renderbuffer->GreenBits);
- ASSERT(att->Renderbuffer->BlueBits);
}
else if (format == GL_DEPTH) {
- if (att->Renderbuffer->_BaseFormat == GL_DEPTH_COMPONENT) {
- ASSERT(att->Renderbuffer->DepthBits);
+ if (baseFormat == GL_DEPTH_COMPONENT) {
/* OK */
}
else if (ctx->Extensions.EXT_packed_depth_stencil &&
- att->Renderbuffer->_BaseFormat == GL_DEPTH_STENCIL_EXT) {
- ASSERT(att->Renderbuffer->DepthBits);
+ baseFormat == GL_DEPTH_STENCIL_EXT) {
/* OK */
}
else {
@@ -464,13 +465,11 @@ test_attachment_completeness(const GLcontext *ctx, GLenum format,
}
else {
assert(format == GL_STENCIL);
- if (att->Renderbuffer->_BaseFormat == GL_STENCIL_INDEX) {
- ASSERT(att->Renderbuffer->StencilBits);
+ if (baseFormat == GL_STENCIL_INDEX) {
/* OK */
}
else if (ctx->Extensions.EXT_packed_depth_stencil &&
- att->Renderbuffer->_BaseFormat == GL_DEPTH_STENCIL_EXT) {
- ASSERT(att->Renderbuffer->StencilBits);
+ baseFormat == GL_DEPTH_STENCIL_EXT) {
/* OK */
}
else {
@@ -970,42 +969,27 @@ renderbuffer_storage(GLenum target, GLenum internalFormat,
}
/* These MUST get set by the AllocStorage func */
- rb->_ActualFormat = 0;
- rb->RedBits =
- rb->GreenBits =
- rb->BlueBits =
- rb->AlphaBits =
- rb->IndexBits =
- rb->DepthBits =
- rb->StencilBits = 0;
+ rb->Format = MESA_FORMAT_NONE;
rb->NumSamples = samples;
/* Now allocate the storage */
ASSERT(rb->AllocStorage);
if (rb->AllocStorage(ctx, rb, internalFormat, width, height)) {
/* No error - check/set fields now */
- assert(rb->_ActualFormat);
+ assert(rb->Format != MESA_FORMAT_NONE);
assert(rb->Width == (GLuint) width);
assert(rb->Height == (GLuint) height);
- assert(rb->RedBits || rb->GreenBits || rb->BlueBits || rb->AlphaBits ||
- rb->DepthBits || rb->StencilBits || rb->IndexBits);
rb->InternalFormat = internalFormat;
- rb->_BaseFormat = baseFormat;
+ rb->_BaseFormat = _mesa_base_fbo_format(ctx, internalFormat);
+ assert(rb->_BaseFormat != 0);
}
else {
/* Probably ran out of memory - clear the fields */
rb->Width = 0;
rb->Height = 0;
+ rb->Format = MESA_FORMAT_NONE;
rb->InternalFormat = GL_NONE;
- rb->_ActualFormat = GL_NONE;
rb->_BaseFormat = GL_NONE;
- rb->RedBits =
- rb->GreenBits =
- rb->BlueBits =
- rb->AlphaBits =
- rb->IndexBits =
- rb->DepthBits =
- rb->StencilBits =
rb->NumSamples = 0;
}
@@ -1018,6 +1002,53 @@ renderbuffer_storage(GLenum target, GLenum internalFormat,
}
+/**
+ * Helper function for _mesa_GetRenderbufferParameterivEXT() and
+ * _mesa_GetFramebufferAttachmentParameterivEXT()
+ * We have to be careful to respect the base format. For example, if a
+ * renderbuffer/texture was created with internalFormat=GL_RGB but the
+ * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
+ * we need to return zero.
+ */
+static GLint
+get_component_bits(GLenum pname, GLenum baseFormat, gl_format format)
+{
+ switch (pname) {
+ case GL_RENDERBUFFER_RED_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
+ case GL_RENDERBUFFER_GREEN_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
+ case GL_RENDERBUFFER_BLUE_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
+ if (baseFormat == GL_RGB || baseFormat == GL_RGBA)
+ return _mesa_get_format_bits(format, pname);
+ else
+ return 0;
+ case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
+ if (baseFormat == GL_RGBA || baseFormat == GL_ALPHA)
+ return _mesa_get_format_bits(format, pname);
+ else
+ return 0;
+ case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
+ if (baseFormat == GL_DEPTH_COMPONENT || baseFormat == GL_DEPTH_STENCIL)
+ return _mesa_get_format_bits(format, pname);
+ else
+ return 0;
+ case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
+ if (baseFormat == GL_STENCIL_INDEX || baseFormat == GL_DEPTH_STENCIL)
+ return _mesa_get_format_bits(format, pname);
+ else
+ return 0;
+ default:
+ return 0;
+ }
+}
+
+
+
void GLAPIENTRY
_mesa_RenderbufferStorageEXT(GLenum target, GLenum internalFormat,
GLsizei width, GLsizei height)
@@ -1074,22 +1105,12 @@ _mesa_GetRenderbufferParameterivEXT(GLenum target, GLenum pname, GLint *params)
*params = rb->InternalFormat;
return;
case GL_RENDERBUFFER_RED_SIZE_EXT:
- *params = rb->RedBits;
- break;
case GL_RENDERBUFFER_GREEN_SIZE_EXT:
- *params = rb->GreenBits;
- break;
case GL_RENDERBUFFER_BLUE_SIZE_EXT:
- *params = rb->BlueBits;
- break;
case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
- *params = rb->AlphaBits;
- break;
case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
- *params = rb->DepthBits;
- break;
case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
- *params = rb->StencilBits;
+ *params = get_component_bits(pname, rb->_BaseFormat, rb->Format);
break;
case GL_RENDERBUFFER_SAMPLES:
if (ctx->Extensions.ARB_framebuffer_object) {
@@ -1673,7 +1694,9 @@ _mesa_FramebufferRenderbufferEXT(GLenum target, GLenum attachment,
if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
/* make sure the renderbuffer is a depth/stencil format */
- if (rb->_BaseFormat != GL_DEPTH_STENCIL) {
+ const GLenum baseFormat =
+ _mesa_get_format_base_format(att->Renderbuffer->Format);
+ if (baseFormat != GL_DEPTH_STENCIL) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glFramebufferRenderbufferEXT(renderbuffer"
" is not DEPTH_STENCIL format)");
@@ -1819,7 +1842,7 @@ _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment,
"glGetFramebufferAttachmentParameterivEXT(pname)");
}
else {
- *params = att->Renderbuffer->ColorEncoding;
+ *params = _mesa_get_format_color_encoding(att->Renderbuffer->Format);
}
return;
case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
@@ -1829,61 +1852,44 @@ _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment,
return;
}
else {
- *params = att->Renderbuffer->ComponentType;
+ gl_format format = att->Renderbuffer->Format;
+ if (format == MESA_FORMAT_CI8 || format == MESA_FORMAT_S8) {
+ /* special cases */
+ *params = GL_INDEX;
+ }
+ else {
+ *params = _mesa_get_format_datatype(format);
+ }
}
return;
case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
- if (!ctx->Extensions.ARB_framebuffer_object) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetFramebufferAttachmentParameterivEXT(pname)");
- }
- else {
- *params = att->Renderbuffer->RedBits;
- }
- return;
case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
- if (!ctx->Extensions.ARB_framebuffer_object) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetFramebufferAttachmentParameterivEXT(pname)");
- }
- else {
- *params = att->Renderbuffer->GreenBits;
- }
- return;
case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
- if (!ctx->Extensions.ARB_framebuffer_object) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetFramebufferAttachmentParameterivEXT(pname)");
- }
- else {
- *params = att->Renderbuffer->BlueBits;
- }
- return;
case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
- if (!ctx->Extensions.ARB_framebuffer_object) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetFramebufferAttachmentParameterivEXT(pname)");
- }
- else {
- *params = att->Renderbuffer->AlphaBits;
- }
- return;
case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
+ case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
if (!ctx->Extensions.ARB_framebuffer_object) {
_mesa_error(ctx, GL_INVALID_ENUM,
"glGetFramebufferAttachmentParameterivEXT(pname)");
}
- else {
- *params = att->Renderbuffer->DepthBits;
+ else if (att->Texture) {
+ const struct gl_texture_image *texImage =
+ _mesa_select_tex_image(ctx, att->Texture, att->Texture->Target,
+ att->TextureLevel);
+ if (texImage) {
+ *params = get_component_bits(pname, texImage->_BaseFormat,
+ texImage->TexFormat);
+ }
+ else {
+ *params = 0;
+ }
}
- return;
- case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
- if (!ctx->Extensions.ARB_framebuffer_object) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetFramebufferAttachmentParameterivEXT(pname)");
+ else if (att->Renderbuffer) {
+ *params = get_component_bits(pname, att->Renderbuffer->_BaseFormat,
+ att->Renderbuffer->Format);
}
else {
- *params = att->Renderbuffer->StencilBits;
+ *params = 0;
}
return;
default:
@@ -2024,7 +2030,8 @@ _mesa_BlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
struct gl_renderbuffer *drawRb = drawFb->_StencilBuffer;
if (!readRb ||
!drawRb ||
- readRb->StencilBits != drawRb->StencilBits) {
+ _mesa_get_format_bits(readRb->Format, GL_STENCIL_BITS) !=
+ _mesa_get_format_bits(drawRb->Format, GL_STENCIL_BITS)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glBlitFramebufferEXT(stencil buffer size mismatch");
return;
@@ -2036,7 +2043,8 @@ _mesa_BlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
struct gl_renderbuffer *drawRb = drawFb->_DepthBuffer;
if (!readRb ||
!drawRb ||
- readRb->DepthBits != drawRb->DepthBits) {
+ _mesa_get_format_bits(readRb->Format, GL_DEPTH_BITS) !=
+ _mesa_get_format_bits(drawRb->Format, GL_DEPTH_BITS)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glBlitFramebufferEXT(depth buffer size mismatch");
return;
@@ -2064,7 +2072,7 @@ _mesa_BlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
/* color formats must match */
if (colorReadRb &&
colorDrawRb &&
- colorReadRb->_ActualFormat != colorDrawRb->_ActualFormat) {
+ colorReadRb->Format != colorDrawRb->Format) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glBlitFramebufferEXT(bad src/dst multisample pixel formats");
return;
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
new file mode 100644
index 00000000000..72d043c4c39
--- /dev/null
+++ b/src/mesa/main/formats.c
@@ -0,0 +1,1110 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.7
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (c) 2008-2009 VMware, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#include "imports.h"
+#include "formats.h"
+#include "config.h"
+#include "texstore.h"
+
+
+/**
+ * Information about texture formats.
+ */
+struct gl_format_info
+{
+ gl_format Name;
+
+ /** text name for debugging */
+ const char *StrName;
+
+ /**
+ * Base format is one of GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE,
+ * GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA, GL_COLOR_INDEX,
+ * GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
+ */
+ GLenum BaseFormat;
+
+ /**
+ * Logical data type: one of GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALED,
+ * GL_UNSIGNED_INT, GL_SIGNED_INT, GL_FLOAT.
+ */
+ GLenum DataType;
+
+ GLubyte RedBits;
+ GLubyte GreenBits;
+ GLubyte BlueBits;
+ GLubyte AlphaBits;
+ GLubyte LuminanceBits;
+ GLubyte IntensityBits;
+ GLubyte IndexBits;
+ GLubyte DepthBits;
+ GLubyte StencilBits;
+
+ /**
+ * To describe compressed formats. If not compressed, Width=Height=1.
+ */
+ GLubyte BlockWidth, BlockHeight;
+ GLubyte BytesPerBlock;
+};
+
+
+/**
+ * Info about each format.
+ * These must be in the same order as the MESA_FORMAT_* enums so that
+ * we can do lookups without searching.
+ */
+static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
+{
+ {
+ MESA_FORMAT_NONE, /* Name */
+ "MESA_FORMAT_NONE", /* StrName */
+ GL_NONE, /* BaseFormat */
+ GL_NONE, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 0, 0, 0 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_RGBA8888, /* Name */
+ "MESA_FORMAT_RGBA8888", /* StrName */
+ GL_RGBA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 4 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_RGBA8888_REV, /* Name */
+ "MESA_FORMAT_RGBA8888_REV", /* StrName */
+ GL_RGBA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 4 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_ARGB8888, /* Name */
+ "MESA_FORMAT_ARGB8888", /* StrName */
+ GL_RGBA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 4 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_ARGB8888_REV, /* Name */
+ "MESA_FORMAT_ARGB8888_REV", /* StrName */
+ GL_RGBA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 4 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_XRGB8888, /* Name */
+ "MESA_FORMAT_XRGB8888", /* StrName */
+ GL_RGB, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 4 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_RGB888, /* Name */
+ "MESA_FORMAT_RGB888", /* StrName */
+ GL_RGB, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 3 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_BGR888, /* Name */
+ "MESA_FORMAT_BGR888", /* StrName */
+ GL_RGB, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 3 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_RGB565, /* Name */
+ "MESA_FORMAT_RGB565", /* StrName */
+ GL_RGB, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_RGB565_REV, /* Name */
+ "MESA_FORMAT_RGB565_REV", /* StrName */
+ GL_RGB, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_ARGB4444, /* Name */
+ "MESA_FORMAT_ARGB4444", /* StrName */
+ GL_RGBA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_ARGB4444_REV, /* Name */
+ "MESA_FORMAT_ARGB4444_REV", /* StrName */
+ GL_RGBA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_RGBA5551, /* Name */
+ "MESA_FORMAT_RGBA5551", /* StrName */
+ GL_RGBA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_ARGB1555, /* Name */
+ "MESA_FORMAT_ARGB1555", /* StrName */
+ GL_RGBA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_ARGB1555_REV, /* Name */
+ "MESA_FORMAT_ARGB1555_REV", /* StrName */
+ GL_RGBA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_AL88, /* Name */
+ "MESA_FORMAT_AL88", /* StrName */
+ GL_LUMINANCE_ALPHA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
+ 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_AL88_REV, /* Name */
+ "MESA_FORMAT_AL88_REV", /* StrName */
+ GL_LUMINANCE_ALPHA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
+ 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_RGB332, /* Name */
+ "MESA_FORMAT_RGB332", /* StrName */
+ GL_RGB, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 3, 3, 2, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 1 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_A8, /* Name */
+ "MESA_FORMAT_A8", /* StrName */
+ GL_ALPHA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 1 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_L8, /* Name */
+ "MESA_FORMAT_L8", /* StrName */
+ GL_LUMINANCE, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 1 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_I8, /* Name */
+ "MESA_FORMAT_I8", /* StrName */
+ GL_INTENSITY, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 8, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 1 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_CI8, /* Name */
+ "MESA_FORMAT_CI8", /* StrName */
+ GL_COLOR_INDEX, /* BaseFormat */
+ GL_UNSIGNED_INT, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 8, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 1 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_YCBCR, /* Name */
+ "MESA_FORMAT_YCBCR", /* StrName */
+ GL_YCBCR_MESA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_YCBCR_REV, /* Name */
+ "MESA_FORMAT_YCBCR_REV", /* StrName */
+ GL_YCBCR_MESA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_Z24_S8, /* Name */
+ "MESA_FORMAT_Z24_S8", /* StrName */
+ GL_DEPTH_STENCIL, /* BaseFormat */
+ GL_UNSIGNED_INT, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 4 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_S8_Z24, /* Name */
+ "MESA_FORMAT_S8_Z24", /* StrName */
+ GL_DEPTH_STENCIL, /* BaseFormat */
+ GL_UNSIGNED_INT, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 4 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_Z16, /* Name */
+ "MESA_FORMAT_Z16", /* StrName */
+ GL_DEPTH_COMPONENT, /* BaseFormat */
+ GL_UNSIGNED_INT, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 16, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_X8_Z24, /* Name */
+ "MESA_FORMAT_X8_Z24", /* StrName */
+ GL_DEPTH_COMPONENT, /* BaseFormat */
+ GL_UNSIGNED_INT, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 4 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_Z32, /* Name */
+ "MESA_FORMAT_Z32", /* StrName */
+ GL_DEPTH_COMPONENT, /* BaseFormat */
+ GL_UNSIGNED_INT, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 32, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 4 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_S8, /* Name */
+ "MESA_FORMAT_S8", /* StrName */
+ GL_STENCIL_INDEX, /* BaseFormat */
+ GL_UNSIGNED_INT, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 8, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 1 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_SRGB8,
+ "MESA_FORMAT_SRGB8",
+ GL_RGB,
+ GL_UNSIGNED_NORMALIZED,
+ 8, 8, 8, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 3
+ },
+ {
+ MESA_FORMAT_SRGBA8,
+ "MESA_FORMAT_SRGBA8",
+ GL_RGBA,
+ GL_UNSIGNED_NORMALIZED,
+ 8, 8, 8, 8,
+ 0, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_SARGB8,
+ "MESA_FORMAT_SARGB8",
+ GL_RGBA,
+ GL_UNSIGNED_NORMALIZED,
+ 8, 8, 8, 8,
+ 0, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_SL8,
+ "MESA_FORMAT_SL8",
+ GL_LUMINANCE_ALPHA,
+ GL_UNSIGNED_NORMALIZED,
+ 0, 0, 0, 8,
+ 8, 0, 0, 0, 0,
+ 1, 1, 2
+ },
+ {
+ MESA_FORMAT_SLA8,
+ "MESA_FORMAT_SLA8",
+ GL_LUMINANCE_ALPHA,
+ GL_UNSIGNED_NORMALIZED,
+ 0, 0, 0, 8,
+ 8, 0, 0, 0, 0,
+ 1, 1, 2
+ },
+ {
+ MESA_FORMAT_SRGB_DXT1, /* Name */
+ "MESA_FORMAT_SRGB_DXT1", /* StrName */
+ GL_RGB, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 4, 4, 8 /* 8 bytes per 4x4 block */
+ },
+ {
+ MESA_FORMAT_SRGBA_DXT1,
+ "MESA_FORMAT_SRGBA_DXT1",
+ GL_RGBA,
+ GL_UNSIGNED_NORMALIZED,
+ 4, 4, 4, 4,
+ 0, 0, 0, 0, 0,
+ 4, 4, 8 /* 8 bytes per 4x4 block */
+ },
+ {
+ MESA_FORMAT_SRGBA_DXT3,
+ "MESA_FORMAT_SRGBA_DXT3",
+ GL_RGBA,
+ GL_UNSIGNED_NORMALIZED,
+ 4, 4, 4, 4,
+ 0, 0, 0, 0, 0,
+ 4, 4, 16 /* 16 bytes per 4x4 block */
+ },
+ {
+ MESA_FORMAT_SRGBA_DXT5,
+ "MESA_FORMAT_SRGBA_DXT5",
+ GL_RGBA,
+ GL_UNSIGNED_NORMALIZED,
+ 4, 4, 4, 4,
+ 0, 0, 0, 0, 0,
+ 4, 4, 16 /* 16 bytes per 4x4 block */
+ },
+
+ {
+ MESA_FORMAT_RGB_FXT1,
+ "MESA_FORMAT_RGB_FXT1",
+ GL_RGB,
+ GL_UNSIGNED_NORMALIZED,
+ 8, 8, 8, 0,
+ 0, 0, 0, 0, 0,
+ 8, 4, 16 /* 16 bytes per 8x4 block */
+ },
+ {
+ MESA_FORMAT_RGBA_FXT1,
+ "MESA_FORMAT_RGBA_FXT1",
+ GL_RGBA,
+ GL_UNSIGNED_NORMALIZED,
+ 8, 8, 8, 8,
+ 0, 0, 0, 0, 0,
+ 8, 4, 16 /* 16 bytes per 8x4 block */
+ },
+
+ {
+ MESA_FORMAT_RGB_DXT1, /* Name */
+ "MESA_FORMAT_RGB_DXT1", /* StrName */
+ GL_RGB, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 4, 4, 8 /* 8 bytes per 4x4 block */
+ },
+ {
+ MESA_FORMAT_RGBA_DXT1,
+ "MESA_FORMAT_RGBA_DXT1",
+ GL_RGBA,
+ GL_UNSIGNED_NORMALIZED,
+ 4, 4, 4, 4,
+ 0, 0, 0, 0, 0,
+ 4, 4, 8 /* 8 bytes per 4x4 block */
+ },
+ {
+ MESA_FORMAT_RGBA_DXT3,
+ "MESA_FORMAT_RGBA_DXT3",
+ GL_RGBA,
+ GL_UNSIGNED_NORMALIZED,
+ 4, 4, 4, 4,
+ 0, 0, 0, 0, 0,
+ 4, 4, 16 /* 16 bytes per 4x4 block */
+ },
+ {
+ MESA_FORMAT_RGBA_DXT5,
+ "MESA_FORMAT_RGBA_DXT5",
+ GL_RGBA,
+ GL_UNSIGNED_NORMALIZED,
+ 4, 4, 4, 4,
+ 0, 0, 0, 0, 0,
+ 4, 4, 16 /* 16 bytes per 4x4 block */
+ },
+ {
+ MESA_FORMAT_RGBA_FLOAT32,
+ "MESA_FORMAT_RGBA_FLOAT32",
+ GL_RGBA,
+ GL_FLOAT,
+ 32, 32, 32, 32,
+ 0, 0, 0, 0, 0,
+ 1, 1, 16
+ },
+ {
+ MESA_FORMAT_RGBA_FLOAT16,
+ "MESA_FORMAT_RGBA_FLOAT16",
+ GL_RGBA,
+ GL_FLOAT,
+ 16, 16, 16, 16,
+ 0, 0, 0, 0, 0,
+ 1, 1, 8
+ },
+ {
+ MESA_FORMAT_RGB_FLOAT32,
+ "MESA_FORMAT_RGB_FLOAT32",
+ GL_RGB,
+ GL_FLOAT,
+ 32, 32, 32, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 12
+ },
+ {
+ MESA_FORMAT_RGB_FLOAT16,
+ "MESA_FORMAT_RGB_FLOAT16",
+ GL_RGB,
+ GL_FLOAT,
+ 16, 16, 16, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 6
+ },
+ {
+ MESA_FORMAT_ALPHA_FLOAT32,
+ "MESA_FORMAT_ALPHA_FLOAT32",
+ GL_ALPHA,
+ GL_FLOAT,
+ 0, 0, 0, 32,
+ 0, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_ALPHA_FLOAT16,
+ "MESA_FORMAT_ALPHA_FLOAT16",
+ GL_ALPHA,
+ GL_FLOAT,
+ 0, 0, 0, 16,
+ 0, 0, 0, 0, 0,
+ 1, 1, 2
+ },
+ {
+ MESA_FORMAT_LUMINANCE_FLOAT32,
+ "MESA_FORMAT_LUMINANCE_FLOAT32",
+ GL_ALPHA,
+ GL_FLOAT,
+ 0, 0, 0, 0,
+ 32, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_LUMINANCE_FLOAT16,
+ "MESA_FORMAT_LUMINANCE_FLOAT16",
+ GL_ALPHA,
+ GL_FLOAT,
+ 0, 0, 0, 0,
+ 16, 0, 0, 0, 0,
+ 1, 1, 2
+ },
+ {
+ MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
+ "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32",
+ GL_LUMINANCE_ALPHA,
+ GL_FLOAT,
+ 0, 0, 0, 32,
+ 32, 0, 0, 0, 0,
+ 1, 1, 8
+ },
+ {
+ MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,
+ "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16",
+ GL_LUMINANCE_ALPHA,
+ GL_FLOAT,
+ 0, 0, 0, 16,
+ 16, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_INTENSITY_FLOAT32,
+ "MESA_FORMAT_INTENSITY_FLOAT32",
+ GL_INTENSITY,
+ GL_FLOAT,
+ 0, 0, 0, 0,
+ 0, 32, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_INTENSITY_FLOAT16,
+ "MESA_FORMAT_INTENSITY_FLOAT16",
+ GL_INTENSITY,
+ GL_FLOAT,
+ 0, 0, 0, 0,
+ 0, 16, 0, 0, 0,
+ 1, 1, 2
+ },
+ {
+ MESA_FORMAT_DUDV8,
+ "MESA_FORMAT_DUDV8",
+ GL_DUDV_ATI,
+ GL_SIGNED_NORMALIZED,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 2
+ },
+ {
+ MESA_FORMAT_SIGNED_RGBA8888,
+ "MESA_FORMAT_SIGNED_RGBA8888",
+ GL_RGBA,
+ GL_SIGNED_NORMALIZED,
+ 8, 8, 8, 8,
+ 0, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_SIGNED_RGBA8888_REV,
+ "MESA_FORMAT_SIGNED_RGBA8888_REV",
+ GL_RGBA,
+ GL_SIGNED_NORMALIZED,
+ 8, 8, 8, 8,
+ 0, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_SIGNED_RGBA_16,
+ "MESA_FORMAT_SIGNED_RGBA_16",
+ GL_RGBA,
+ GL_SIGNED_NORMALIZED,
+ 16, 16, 16, 16,
+ 0, 0, 0, 0, 0,
+ 1, 1, 8
+ }
+};
+
+
+
+static const struct gl_format_info *
+_mesa_get_format_info(gl_format format)
+{
+ const struct gl_format_info *info = &format_info[format];
+ assert(info->Name == format);
+ return info;
+}
+
+
+/** Return string name of format (for debugging) */
+const char *
+_mesa_get_format_name(gl_format format)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+ ASSERT(info->BytesPerBlock);
+ return info->StrName;
+}
+
+
+
+/**
+ * Return bytes needed to store a block of pixels in the given format.
+ * Normally, a block is 1x1 (a single pixel). But for compressed formats
+ * a block may be 4x4 or 8x4, etc.
+ */
+GLuint
+_mesa_get_format_bytes(gl_format format)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+ ASSERT(info->BytesPerBlock);
+ return info->BytesPerBlock;
+}
+
+
+/**
+ * Return bits per component for the given format.
+ * \param format one of MESA_FORMAT_x
+ * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
+ */
+GLint
+_mesa_get_format_bits(gl_format format, GLenum pname)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+
+ switch (pname) {
+ case GL_RED_BITS:
+ case GL_TEXTURE_RED_SIZE:
+ case GL_RENDERBUFFER_RED_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
+ return info->RedBits;
+ case GL_GREEN_BITS:
+ case GL_TEXTURE_GREEN_SIZE:
+ case GL_RENDERBUFFER_GREEN_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
+ return info->GreenBits;
+ case GL_BLUE_BITS:
+ case GL_TEXTURE_BLUE_SIZE:
+ case GL_RENDERBUFFER_BLUE_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
+ return info->BlueBits;
+ case GL_ALPHA_BITS:
+ case GL_TEXTURE_ALPHA_SIZE:
+ case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
+ return info->AlphaBits;
+ case GL_TEXTURE_INTENSITY_SIZE:
+ return info->IntensityBits;
+ case GL_TEXTURE_LUMINANCE_SIZE:
+ return info->LuminanceBits;
+ case GL_INDEX_BITS:
+ case GL_TEXTURE_INDEX_SIZE_EXT:
+ return info->IndexBits;
+ case GL_DEPTH_BITS:
+ case GL_TEXTURE_DEPTH_SIZE_ARB:
+ case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
+ return info->DepthBits;
+ case GL_STENCIL_BITS:
+ case GL_TEXTURE_STENCIL_SIZE_EXT:
+ case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
+ return info->StencilBits;
+ default:
+ _mesa_problem(NULL, "bad pname in _mesa_get_format_bits()");
+ return 0;
+ }
+}
+
+
+/**
+ * Return the data type (or more specifically, the data representation)
+ * for the given format.
+ * The return value will be one of:
+ * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
+ * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
+ * GL_UNSIGNED_INT = an ordinary unsigned integer
+ * GL_FLOAT = an ordinary float
+ */
+GLenum
+_mesa_get_format_datatype(gl_format format)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+ return info->DataType;
+}
+
+
+/**
+ * Return the basic format for the given type. The result will be
+ * one of GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA,
+ * GL_INTENSITY, GL_YCBCR_MESA, GL_COLOR_INDEX, GL_DEPTH_COMPONENT,
+ * GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
+ */
+GLenum
+_mesa_get_format_base_format(gl_format format)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+ return info->BaseFormat;
+}
+
+
+/**
+ * Return the block size (in pixels) for the given format. Normally
+ * the block size is 1x1. But compressed formats will have block sizes
+ * of 4x4 or 8x4 pixels, etc.
+ * \param bw returns block width in pixels
+ * \param bh returns block height in pixels
+ */
+void
+_mesa_get_format_block_size(gl_format format, GLuint *bw, GLuint *bh)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+ *bw = info->BlockWidth;
+ *bh = info->BlockHeight;
+}
+
+
+/** Is the given format a compressed format? */
+GLboolean
+_mesa_is_format_compressed(gl_format format)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+ return info->BlockWidth > 1 || info->BlockHeight > 1;
+}
+
+
+/**
+ * Return color encoding for given format.
+ * \return GL_LINEAR or GL_SRGB
+ */
+GLenum
+_mesa_get_format_color_encoding(gl_format format)
+{
+ /* XXX this info should be encoded in gl_format_info */
+ switch (format) {
+ case MESA_FORMAT_SRGB8:
+ case MESA_FORMAT_SRGBA8:
+ case MESA_FORMAT_SARGB8:
+ case MESA_FORMAT_SL8:
+ case MESA_FORMAT_SLA8:
+ case MESA_FORMAT_SRGB_DXT1:
+ case MESA_FORMAT_SRGBA_DXT1:
+ case MESA_FORMAT_SRGBA_DXT3:
+ case MESA_FORMAT_SRGBA_DXT5:
+ return GL_SRGB;
+ default:
+ return GL_LINEAR;
+ }
+}
+
+
+/**
+ * Return number of bytes needed to store an image of the given size
+ * in the given format.
+ */
+GLuint
+_mesa_format_image_size(gl_format format, GLsizei width,
+ GLsizei height, GLsizei depth)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+ /* Strictly speaking, a conditional isn't needed here */
+ if (info->BlockWidth > 1 || info->BlockHeight > 1) {
+ /* compressed format */
+ const GLuint bw = info->BlockWidth, bh = info->BlockHeight;
+ const GLuint wblocks = (width + bw - 1) / bw;
+ const GLuint hblocks = (height + bh - 1) / bh;
+ const GLuint sz = wblocks * hblocks * info->BytesPerBlock;
+ return sz;
+ }
+ else {
+ /* non-compressed */
+ const GLuint sz = width * height * depth * info->BytesPerBlock;
+ return sz;
+ }
+}
+
+
+
+GLint
+_mesa_format_row_stride(gl_format format, GLsizei width)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+ /* Strictly speaking, a conditional isn't needed here */
+ if (info->BlockWidth > 1 || info->BlockHeight > 1) {
+ /* compressed format */
+ const GLuint bw = info->BlockWidth;
+ const GLuint wblocks = (width + bw - 1) / bw;
+ const GLint stride = wblocks * info->BytesPerBlock;
+ return stride;
+ }
+ else {
+ const GLint stride = width * info->BytesPerBlock;
+ return stride;
+ }
+}
+
+
+
+/**
+ * Do sanity checking of the format info table.
+ */
+void
+_mesa_test_formats(void)
+{
+ GLuint i;
+
+ assert(Elements(format_info) == MESA_FORMAT_COUNT);
+
+ for (i = 0; i < MESA_FORMAT_COUNT; i++) {
+ const struct gl_format_info *info = _mesa_get_format_info(i);
+ assert(info);
+
+ assert(info->Name == i);
+
+ if (info->Name == MESA_FORMAT_NONE)
+ continue;
+
+ if (info->BlockWidth == 1 && info->BlockHeight == 1) {
+ if (info->RedBits > 0) {
+ GLuint t = info->RedBits + info->GreenBits
+ + info->BlueBits + info->AlphaBits;
+ assert(t / 8 == info->BytesPerBlock);
+ }
+ }
+
+ assert(info->DataType == GL_UNSIGNED_NORMALIZED ||
+ info->DataType == GL_SIGNED_NORMALIZED ||
+ info->DataType == GL_UNSIGNED_INT ||
+ info->DataType == GL_FLOAT);
+
+ if (info->BaseFormat == GL_RGB) {
+ assert(info->RedBits > 0);
+ assert(info->GreenBits > 0);
+ assert(info->BlueBits > 0);
+ assert(info->AlphaBits == 0);
+ assert(info->LuminanceBits == 0);
+ assert(info->IntensityBits == 0);
+ }
+ else if (info->BaseFormat == GL_RGBA) {
+ assert(info->RedBits > 0);
+ assert(info->GreenBits > 0);
+ assert(info->BlueBits > 0);
+ assert(info->AlphaBits > 0);
+ assert(info->LuminanceBits == 0);
+ assert(info->IntensityBits == 0);
+ }
+ else if (info->BaseFormat == GL_LUMINANCE) {
+ assert(info->RedBits == 0);
+ assert(info->GreenBits == 0);
+ assert(info->BlueBits == 0);
+ assert(info->AlphaBits == 0);
+ assert(info->LuminanceBits > 0);
+ assert(info->IntensityBits == 0);
+ }
+ else if (info->BaseFormat == GL_INTENSITY) {
+ assert(info->RedBits == 0);
+ assert(info->GreenBits == 0);
+ assert(info->BlueBits == 0);
+ assert(info->AlphaBits == 0);
+ assert(info->LuminanceBits == 0);
+ assert(info->IntensityBits > 0);
+ }
+
+ }
+}
+
+
+
+/**
+ * Return datatype and number of components per texel for the given gl_format.
+ * Only used for mipmap generation code.
+ */
+void
+_mesa_format_to_type_and_comps(gl_format format,
+ GLenum *datatype, GLuint *comps)
+{
+ switch (format) {
+ case MESA_FORMAT_RGBA8888:
+ case MESA_FORMAT_RGBA8888_REV:
+ case MESA_FORMAT_ARGB8888:
+ case MESA_FORMAT_ARGB8888_REV:
+ case MESA_FORMAT_XRGB8888:
+ *datatype = GL_UNSIGNED_BYTE;
+ *comps = 4;
+ return;
+ case MESA_FORMAT_RGB888:
+ case MESA_FORMAT_BGR888:
+ *datatype = GL_UNSIGNED_BYTE;
+ *comps = 3;
+ return;
+ case MESA_FORMAT_RGB565:
+ case MESA_FORMAT_RGB565_REV:
+ *datatype = GL_UNSIGNED_SHORT_5_6_5;
+ *comps = 3;
+ return;
+
+ case MESA_FORMAT_ARGB4444:
+ case MESA_FORMAT_ARGB4444_REV:
+ *datatype = GL_UNSIGNED_SHORT_4_4_4_4;
+ *comps = 4;
+ return;
+
+ case MESA_FORMAT_ARGB1555:
+ case MESA_FORMAT_ARGB1555_REV:
+ *datatype = GL_UNSIGNED_SHORT_1_5_5_5_REV;
+ *comps = 4;
+ return;
+
+ case MESA_FORMAT_AL88:
+ case MESA_FORMAT_AL88_REV:
+ *datatype = GL_UNSIGNED_BYTE;
+ *comps = 2;
+ return;
+ case MESA_FORMAT_RGB332:
+ *datatype = GL_UNSIGNED_BYTE_3_3_2;
+ *comps = 3;
+ return;
+
+ case MESA_FORMAT_A8:
+ case MESA_FORMAT_L8:
+ case MESA_FORMAT_I8:
+ case MESA_FORMAT_CI8:
+ *datatype = GL_UNSIGNED_BYTE;
+ *comps = 1;
+ return;
+
+ case MESA_FORMAT_YCBCR:
+ case MESA_FORMAT_YCBCR_REV:
+ *datatype = GL_UNSIGNED_SHORT;
+ *comps = 2;
+ return;
+
+ case MESA_FORMAT_Z24_S8:
+ *datatype = GL_UNSIGNED_INT;
+ *comps = 1; /* XXX OK? */
+ return;
+
+ case MESA_FORMAT_S8_Z24:
+ *datatype = GL_UNSIGNED_INT;
+ *comps = 1; /* XXX OK? */
+ return;
+
+ case MESA_FORMAT_Z16:
+ *datatype = GL_UNSIGNED_SHORT;
+ *comps = 1;
+ return;
+
+ case MESA_FORMAT_X8_Z24:
+ *datatype = GL_UNSIGNED_INT;
+ *comps = 1;
+ return;
+
+ case MESA_FORMAT_Z32:
+ *datatype = GL_UNSIGNED_INT;
+ *comps = 1;
+ return;
+
+ case MESA_FORMAT_DUDV8:
+ *datatype = GL_BYTE;
+ *comps = 2;
+ return;
+
+ case MESA_FORMAT_SIGNED_RGBA8888:
+ case MESA_FORMAT_SIGNED_RGBA8888_REV:
+ *datatype = GL_BYTE;
+ *comps = 4;
+ return;
+ case MESA_FORMAT_SIGNED_RGBA_16:
+ *datatype = GL_SHORT;
+ *comps = 4;
+ return;
+
+#if FEATURE_EXT_texture_sRGB
+ case MESA_FORMAT_SRGB8:
+ *datatype = GL_UNSIGNED_BYTE;
+ *comps = 3;
+ return;
+ case MESA_FORMAT_SRGBA8:
+ case MESA_FORMAT_SARGB8:
+ *datatype = GL_UNSIGNED_BYTE;
+ *comps = 4;
+ return;
+ case MESA_FORMAT_SL8:
+ *datatype = GL_UNSIGNED_BYTE;
+ *comps = 1;
+ return;
+ case MESA_FORMAT_SLA8:
+ *datatype = GL_UNSIGNED_BYTE;
+ *comps = 2;
+ return;
+#endif
+
+#if FEATURE_texture_fxt1
+ case MESA_FORMAT_RGB_FXT1:
+ case MESA_FORMAT_RGBA_FXT1:
+#endif
+#if FEATURE_texture_s3tc
+ case MESA_FORMAT_RGB_DXT1:
+ case MESA_FORMAT_RGBA_DXT1:
+ case MESA_FORMAT_RGBA_DXT3:
+ case MESA_FORMAT_RGBA_DXT5:
+#if FEATURE_EXT_texture_sRGB
+ case MESA_FORMAT_SRGB_DXT1:
+ case MESA_FORMAT_SRGBA_DXT1:
+ case MESA_FORMAT_SRGBA_DXT3:
+ case MESA_FORMAT_SRGBA_DXT5:
+#endif
+ /* XXX generate error instead? */
+ *datatype = GL_UNSIGNED_BYTE;
+ *comps = 0;
+ return;
+#endif
+
+ case MESA_FORMAT_RGBA_FLOAT32:
+ *datatype = GL_FLOAT;
+ *comps = 4;
+ return;
+ case MESA_FORMAT_RGBA_FLOAT16:
+ *datatype = GL_HALF_FLOAT_ARB;
+ *comps = 4;
+ return;
+ case MESA_FORMAT_RGB_FLOAT32:
+ *datatype = GL_FLOAT;
+ *comps = 3;
+ return;
+ case MESA_FORMAT_RGB_FLOAT16:
+ *datatype = GL_HALF_FLOAT_ARB;
+ *comps = 3;
+ return;
+ case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32:
+ *datatype = GL_FLOAT;
+ *comps = 2;
+ return;
+ case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:
+ *datatype = GL_HALF_FLOAT_ARB;
+ *comps = 2;
+ return;
+ case MESA_FORMAT_ALPHA_FLOAT32:
+ case MESA_FORMAT_LUMINANCE_FLOAT32:
+ case MESA_FORMAT_INTENSITY_FLOAT32:
+ *datatype = GL_FLOAT;
+ *comps = 1;
+ return;
+ case MESA_FORMAT_ALPHA_FLOAT16:
+ case MESA_FORMAT_LUMINANCE_FLOAT16:
+ case MESA_FORMAT_INTENSITY_FLOAT16:
+ *datatype = GL_HALF_FLOAT_ARB;
+ *comps = 1;
+ return;
+
+ default:
+ _mesa_problem(NULL, "bad format in _mesa_format_to_type_and_comps");
+ *datatype = 0;
+ *comps = 1;
+ }
+}
diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h
new file mode 100644
index 00000000000..91ea023077f
--- /dev/null
+++ b/src/mesa/main/formats.h
@@ -0,0 +1,181 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.7
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (c) 2008-2009 VMware, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * Authors:
+ * Brian Paul
+ */
+
+
+#ifndef FORMATS_H
+#define FORMATS_H
+
+
+#include "main/mtypes.h"
+
+
+
+/**
+ * Mesa texture/renderbuffer image formats.
+ */
+typedef enum
+{
+ MESA_FORMAT_NONE = 0,
+
+ /**
+ * \name Basic hardware formats
+ */
+ /*@{*/
+ /* msb <------ TEXEL BITS -----------> lsb */
+ /* ---- ---- ---- ---- ---- ---- ---- ---- */
+ MESA_FORMAT_RGBA8888, /* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */
+ MESA_FORMAT_RGBA8888_REV, /* AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR */
+ MESA_FORMAT_ARGB8888, /* AAAA AAAA RRRR RRRR GGGG GGGG BBBB BBBB */
+ MESA_FORMAT_ARGB8888_REV, /* BBBB BBBB GGGG GGGG RRRR RRRR AAAA AAAA */
+ MESA_FORMAT_XRGB8888, /* xxxx xxxx RRRR RRRR GGGG GGGG BBBB BBBB */
+ MESA_FORMAT_RGB888, /* RRRR RRRR GGGG GGGG BBBB BBBB */
+ MESA_FORMAT_BGR888, /* BBBB BBBB GGGG GGGG RRRR RRRR */
+ MESA_FORMAT_RGB565, /* RRRR RGGG GGGB BBBB */
+ MESA_FORMAT_RGB565_REV, /* GGGB BBBB RRRR RGGG */
+ MESA_FORMAT_ARGB4444, /* AAAA RRRR GGGG BBBB */
+ MESA_FORMAT_ARGB4444_REV, /* GGGG BBBB AAAA RRRR */
+ MESA_FORMAT_RGBA5551, /* RRRR RGGG GGBB BBBA */
+ MESA_FORMAT_ARGB1555, /* ARRR RRGG GGGB BBBB */
+ MESA_FORMAT_ARGB1555_REV, /* GGGB BBBB ARRR RRGG */
+ MESA_FORMAT_AL88, /* AAAA AAAA LLLL LLLL */
+ MESA_FORMAT_AL88_REV, /* LLLL LLLL AAAA AAAA */
+ MESA_FORMAT_RGB332, /* RRRG GGBB */
+ MESA_FORMAT_A8, /* AAAA AAAA */
+ MESA_FORMAT_L8, /* LLLL LLLL */
+ MESA_FORMAT_I8, /* IIII IIII */
+ MESA_FORMAT_CI8, /* CCCC CCCC */
+ MESA_FORMAT_YCBCR, /* YYYY YYYY UorV UorV */
+ MESA_FORMAT_YCBCR_REV, /* UorV UorV YYYY YYYY */
+ MESA_FORMAT_Z24_S8, /* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ SSSS SSSS */
+ MESA_FORMAT_S8_Z24, /* SSSS SSSS ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
+ MESA_FORMAT_Z16, /* ZZZZ ZZZZ ZZZZ ZZZZ */
+ MESA_FORMAT_X8_Z24, /* xxxx xxxx ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
+ MESA_FORMAT_Z32, /* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
+ MESA_FORMAT_S8, /* SSSS SSSS */
+ /*@}*/
+
+ /**
+ * \name 8-bit/channel sRGB formats
+ */
+ /*@{*/
+ MESA_FORMAT_SRGB8,
+ MESA_FORMAT_SRGBA8,
+ MESA_FORMAT_SARGB8,
+ MESA_FORMAT_SL8,
+ MESA_FORMAT_SLA8,
+ MESA_FORMAT_SRGB_DXT1,
+ MESA_FORMAT_SRGBA_DXT1,
+ MESA_FORMAT_SRGBA_DXT3,
+ MESA_FORMAT_SRGBA_DXT5,
+ /*@}*/
+
+ /**
+ * \name Compressed texture formats.
+ */
+ /*@{*/
+ MESA_FORMAT_RGB_FXT1,
+ MESA_FORMAT_RGBA_FXT1,
+ MESA_FORMAT_RGB_DXT1,
+ MESA_FORMAT_RGBA_DXT1,
+ MESA_FORMAT_RGBA_DXT3,
+ MESA_FORMAT_RGBA_DXT5,
+ /*@}*/
+
+ /**
+ * \name Floating point texture formats.
+ */
+ /*@{*/
+ MESA_FORMAT_RGBA_FLOAT32,
+ MESA_FORMAT_RGBA_FLOAT16,
+ MESA_FORMAT_RGB_FLOAT32,
+ MESA_FORMAT_RGB_FLOAT16,
+ MESA_FORMAT_ALPHA_FLOAT32,
+ MESA_FORMAT_ALPHA_FLOAT16,
+ MESA_FORMAT_LUMINANCE_FLOAT32,
+ MESA_FORMAT_LUMINANCE_FLOAT16,
+ MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
+ MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,
+ MESA_FORMAT_INTENSITY_FLOAT32,
+ MESA_FORMAT_INTENSITY_FLOAT16,
+ /*@}*/
+
+ /**
+ * \name Signed fixed point texture formats.
+ */
+ /*@{*/
+ MESA_FORMAT_DUDV8,
+ MESA_FORMAT_SIGNED_RGBA8888,
+ MESA_FORMAT_SIGNED_RGBA8888_REV,
+ MESA_FORMAT_SIGNED_RGBA_16,
+ /*@}*/
+
+ MESA_FORMAT_COUNT,
+} gl_format;
+
+
+extern const char *
+_mesa_get_format_name(gl_format format);
+
+extern GLuint
+_mesa_get_format_bytes(gl_format format);
+
+extern GLint
+_mesa_get_format_bits(gl_format format, GLenum pname);
+
+extern GLenum
+_mesa_get_format_datatype(gl_format format);
+
+extern GLenum
+_mesa_get_format_base_format(gl_format format);
+
+extern void
+_mesa_get_format_block_size(gl_format format, GLuint *bw, GLuint *bh);
+
+extern GLboolean
+_mesa_is_format_compressed(gl_format format);
+
+extern GLenum
+_mesa_get_format_color_encoding(gl_format format);
+
+extern GLuint
+_mesa_format_image_size(gl_format format, GLsizei width,
+ GLsizei height, GLsizei depth);
+
+extern GLint
+_mesa_format_row_stride(gl_format format, GLsizei width);
+
+extern void
+_mesa_format_to_type_and_comps(gl_format format,
+ GLenum *datatype, GLuint *comps);
+
+extern void
+_mesa_test_formats(void);
+
+#endif /* FORMATS_H */
diff --git a/src/mesa/main/framebuffer.c b/src/mesa/main/framebuffer.c
index dc79b8ca61a..154dedacd50 100644
--- a/src/mesa/main/framebuffer.c
+++ b/src/mesa/main/framebuffer.c
@@ -35,6 +35,7 @@
#include "buffers.h"
#include "context.h"
#include "depthstencil.h"
+#include "formats.h"
#include "macros.h"
#include "mtypes.h"
#include "fbobject.h"
@@ -281,7 +282,6 @@ _mesa_resize_framebuffer(GLcontext *ctx, struct gl_framebuffer *fb,
struct gl_renderbuffer *rb = att->Renderbuffer;
/* only resize if size is changing */
if (rb->Width != width || rb->Height != height) {
- /* could just as well pass rb->_ActualFormat here */
if (rb->AllocStorage(ctx, rb, rb->InternalFormat, width, height)) {
ASSERT(rb->Width == width);
ASSERT(rb->Height == height);
@@ -523,19 +523,22 @@ _mesa_update_framebuffer_visual(struct gl_framebuffer *fb)
for (i = 0; i < BUFFER_COUNT; i++) {
if (fb->Attachment[i].Renderbuffer) {
const struct gl_renderbuffer *rb = fb->Attachment[i].Renderbuffer;
- if (rb->_BaseFormat == GL_RGBA || rb->_BaseFormat == GL_RGB) {
- fb->Visual.redBits = rb->RedBits;
- fb->Visual.greenBits = rb->GreenBits;
- fb->Visual.blueBits = rb->BlueBits;
- fb->Visual.alphaBits = rb->AlphaBits;
+ const GLenum baseFormat = _mesa_get_format_base_format(rb->Format);
+ const gl_format fmt = rb->Format;
+
+ if (baseFormat == GL_RGBA || baseFormat == GL_RGB) {
+ fb->Visual.redBits = _mesa_get_format_bits(fmt, GL_RED_BITS);
+ fb->Visual.greenBits = _mesa_get_format_bits(fmt, GL_GREEN_BITS);
+ fb->Visual.blueBits = _mesa_get_format_bits(fmt, GL_BLUE_BITS);
+ fb->Visual.alphaBits = _mesa_get_format_bits(fmt, GL_ALPHA_BITS);
fb->Visual.rgbBits = fb->Visual.redBits
+ fb->Visual.greenBits + fb->Visual.blueBits;
fb->Visual.floatMode = GL_FALSE;
fb->Visual.samples = rb->NumSamples;
break;
}
- else if (rb->_BaseFormat == GL_COLOR_INDEX) {
- fb->Visual.indexBits = rb->IndexBits;
+ else if (baseFormat == GL_COLOR_INDEX) {
+ fb->Visual.indexBits = _mesa_get_format_bits(fmt, GL_INDEX_BITS);
fb->Visual.rgbMode = GL_FALSE;
break;
}
@@ -543,27 +546,30 @@ _mesa_update_framebuffer_visual(struct gl_framebuffer *fb)
}
if (fb->Attachment[BUFFER_DEPTH].Renderbuffer) {
+ const struct gl_renderbuffer *rb =
+ fb->Attachment[BUFFER_DEPTH].Renderbuffer;
+ const gl_format fmt = rb->Format;
fb->Visual.haveDepthBuffer = GL_TRUE;
- fb->Visual.depthBits
- = fb->Attachment[BUFFER_DEPTH].Renderbuffer->DepthBits;
+ fb->Visual.depthBits = _mesa_get_format_bits(fmt, GL_DEPTH_BITS);
}
if (fb->Attachment[BUFFER_STENCIL].Renderbuffer) {
+ const struct gl_renderbuffer *rb =
+ fb->Attachment[BUFFER_STENCIL].Renderbuffer;
+ const gl_format fmt = rb->Format;
fb->Visual.haveStencilBuffer = GL_TRUE;
- fb->Visual.stencilBits
- = fb->Attachment[BUFFER_STENCIL].Renderbuffer->StencilBits;
+ fb->Visual.stencilBits = _mesa_get_format_bits(fmt, GL_STENCIL_BITS);
}
if (fb->Attachment[BUFFER_ACCUM].Renderbuffer) {
+ const struct gl_renderbuffer *rb =
+ fb->Attachment[BUFFER_ACCUM].Renderbuffer;
+ const gl_format fmt = rb->Format;
fb->Visual.haveAccumBuffer = GL_TRUE;
- fb->Visual.accumRedBits
- = fb->Attachment[BUFFER_ACCUM].Renderbuffer->RedBits;
- fb->Visual.accumGreenBits
- = fb->Attachment[BUFFER_ACCUM].Renderbuffer->GreenBits;
- fb->Visual.accumBlueBits
- = fb->Attachment[BUFFER_ACCUM].Renderbuffer->BlueBits;
- fb->Visual.accumAlphaBits
- = fb->Attachment[BUFFER_ACCUM].Renderbuffer->AlphaBits;
+ fb->Visual.accumRedBits = _mesa_get_format_bits(fmt, GL_RED_BITS);
+ fb->Visual.accumGreenBits = _mesa_get_format_bits(fmt, GL_GREEN_BITS);
+ fb->Visual.accumBlueBits = _mesa_get_format_bits(fmt, GL_BLUE_BITS);
+ fb->Visual.accumAlphaBits = _mesa_get_format_bits(fmt, GL_ALPHA_BITS);
}
compute_depth_max(fb);
@@ -592,11 +598,11 @@ _mesa_update_depth_buffer(GLcontext *ctx,
depthRb = fb->Attachment[attIndex].Renderbuffer;
- if (depthRb && depthRb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT) {
+ if (depthRb && depthRb->_BaseFormat == GL_DEPTH_STENCIL) {
/* The attached depth buffer is a GL_DEPTH_STENCIL renderbuffer */
if (!fb->_DepthBuffer
|| fb->_DepthBuffer->Wrapped != depthRb
- || fb->_DepthBuffer->_BaseFormat != GL_DEPTH_COMPONENT) {
+ || _mesa_get_format_base_format(fb->_DepthBuffer->Format) != GL_DEPTH_COMPONENT) {
/* need to update wrapper */
struct gl_renderbuffer *wrapper
= _mesa_new_z24_renderbuffer_wrapper(ctx, depthRb);
@@ -633,11 +639,11 @@ _mesa_update_stencil_buffer(GLcontext *ctx,
stencilRb = fb->Attachment[attIndex].Renderbuffer;
- if (stencilRb && stencilRb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT) {
+ if (stencilRb && stencilRb->_BaseFormat == GL_DEPTH_STENCIL) {
/* The attached stencil buffer is a GL_DEPTH_STENCIL renderbuffer */
if (!fb->_StencilBuffer
|| fb->_StencilBuffer->Wrapped != stencilRb
- || fb->_StencilBuffer->_BaseFormat != GL_STENCIL_INDEX) {
+ || _mesa_get_format_base_format(fb->_StencilBuffer->Format) != GL_STENCIL_INDEX) {
/* need to update wrapper */
struct gl_renderbuffer *wrapper
= _mesa_new_s8_renderbuffer_wrapper(ctx, stencilRb);
@@ -854,30 +860,32 @@ _mesa_source_buffer_exists(GLcontext *ctx, GLenum format)
if (ctx->ReadBuffer->_ColorReadBuffer == NULL) {
return GL_FALSE;
}
- ASSERT(ctx->ReadBuffer->_ColorReadBuffer->RedBits > 0 ||
- ctx->ReadBuffer->_ColorReadBuffer->IndexBits > 0);
+ ASSERT(_mesa_get_format_bits(ctx->ReadBuffer->_ColorReadBuffer->Format, GL_RED_BITS) > 0 ||
+ _mesa_get_format_bits(ctx->ReadBuffer->_ColorReadBuffer->Format, GL_INDEX_BITS) > 0);
break;
case GL_DEPTH:
case GL_DEPTH_COMPONENT:
if (!att[BUFFER_DEPTH].Renderbuffer) {
return GL_FALSE;
}
- ASSERT(att[BUFFER_DEPTH].Renderbuffer->DepthBits > 0);
+ /*ASSERT(att[BUFFER_DEPTH].Renderbuffer->DepthBits > 0);*/
break;
case GL_STENCIL:
case GL_STENCIL_INDEX:
if (!att[BUFFER_STENCIL].Renderbuffer) {
return GL_FALSE;
}
- ASSERT(att[BUFFER_STENCIL].Renderbuffer->StencilBits > 0);
+ /*ASSERT(att[BUFFER_STENCIL].Renderbuffer->StencilBits > 0);*/
break;
case GL_DEPTH_STENCIL_EXT:
if (!att[BUFFER_DEPTH].Renderbuffer ||
!att[BUFFER_STENCIL].Renderbuffer) {
return GL_FALSE;
}
+ /*
ASSERT(att[BUFFER_DEPTH].Renderbuffer->DepthBits > 0);
ASSERT(att[BUFFER_STENCIL].Renderbuffer->StencilBits > 0);
+ */
break;
default:
_mesa_problem(ctx,
@@ -932,22 +940,24 @@ _mesa_dest_buffer_exists(GLcontext *ctx, GLenum format)
if (!att[BUFFER_DEPTH].Renderbuffer) {
return GL_FALSE;
}
- ASSERT(att[BUFFER_DEPTH].Renderbuffer->DepthBits > 0);
+ /*ASSERT(att[BUFFER_DEPTH].Renderbuffer->DepthBits > 0);*/
break;
case GL_STENCIL:
case GL_STENCIL_INDEX:
if (!att[BUFFER_STENCIL].Renderbuffer) {
return GL_FALSE;
}
- ASSERT(att[BUFFER_STENCIL].Renderbuffer->StencilBits > 0);
+ /*ASSERT(att[BUFFER_STENCIL].Renderbuffer->StencilBits > 0);*/
break;
case GL_DEPTH_STENCIL_EXT:
if (!att[BUFFER_DEPTH].Renderbuffer ||
!att[BUFFER_STENCIL].Renderbuffer) {
return GL_FALSE;
}
+ /*
ASSERT(att[BUFFER_DEPTH].Renderbuffer->DepthBits > 0);
ASSERT(att[BUFFER_STENCIL].Renderbuffer->StencilBits > 0);
+ */
break;
default:
_mesa_problem(ctx,
diff --git a/src/mesa/main/mipmap.c b/src/mesa/main/mipmap.c
index c3928fa513f..7350c7a3d2c 100644
--- a/src/mesa/main/mipmap.c
+++ b/src/mesa/main/mipmap.c
@@ -28,10 +28,11 @@
*/
#include "imports.h"
+#include "formats.h"
#include "mipmap.h"
#include "texcompress.h"
-#include "texformat.h"
#include "teximage.h"
+#include "texstore.h"
#include "image.h"
@@ -1493,7 +1494,7 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
struct gl_texture_object *texObj)
{
const struct gl_texture_image *srcImage;
- const struct gl_texture_format *convertFormat;
+ gl_format convertFormat;
const GLubyte *srcData = NULL;
GLubyte *dstData = NULL;
GLint level, maxLevels;
@@ -1508,7 +1509,8 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
ASSERT(maxLevels > 0); /* bad target */
/* Find convertFormat - the format that do_row() will process */
- if (srcImage->IsCompressed) {
+
+ if (_mesa_is_format_compressed(srcImage->TexFormat)) {
/* setup for compressed textures - need to allocate temporary
* image buffers to hold uncompressed images.
*/
@@ -1520,11 +1522,11 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
texObj->Target == GL_TEXTURE_CUBE_MAP_ARB);
if (srcImage->_BaseFormat == GL_RGB) {
- convertFormat = &_mesa_texformat_rgb;
+ convertFormat = MESA_FORMAT_RGB888;
components = 3;
}
else if (srcImage->_BaseFormat == GL_RGBA) {
- convertFormat = &_mesa_texformat_rgba;
+ convertFormat = MESA_FORMAT_RGBA8888;
components = 4;
}
else {
@@ -1588,7 +1590,11 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
&dstWidth, &dstHeight, &dstDepth);
if (!nextLevel) {
/* all done */
- break;
+ if (_mesa_is_format_compressed(srcImage->TexFormat)) {
+ _mesa_free((void *) srcData);
+ _mesa_free(dstData);
+ }
+ return;
}
/* get dest gl_texture_image */
@@ -1609,25 +1615,17 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
dstImage->TexFormat = srcImage->TexFormat;
dstImage->FetchTexelc = srcImage->FetchTexelc;
dstImage->FetchTexelf = srcImage->FetchTexelf;
- dstImage->IsCompressed = srcImage->IsCompressed;
- if (dstImage->IsCompressed) {
- dstImage->CompressedSize
- = ctx->Driver.CompressedTextureSize(ctx, dstImage->Width,
- dstImage->Height,
- dstImage->Depth,
- dstImage->TexFormat->MesaFormat);
- ASSERT(dstImage->CompressedSize > 0);
- }
-
- ASSERT(dstImage->TexFormat);
- ASSERT(dstImage->FetchTexelc);
- ASSERT(dstImage->FetchTexelf);
/* Alloc new teximage data buffer.
* Setup src and dest data pointers.
*/
- if (dstImage->IsCompressed) {
- dstImage->Data = _mesa_alloc_texmemory(dstImage->CompressedSize);
+ if (_mesa_is_format_compressed(dstImage->TexFormat)) {
+ GLuint dstCompressedSize =
+ _mesa_format_image_size(dstImage->TexFormat, dstImage->Width,
+ dstImage->Height, dstImage->Depth);
+ ASSERT(dstCompressedSize > 0);
+
+ dstImage->Data = _mesa_alloc_texmemory(dstCompressedSize);
if (!dstImage->Data) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "generating mipmaps");
return;
@@ -1637,7 +1635,7 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
ASSERT(dstData);
}
else {
- bytesPerTexel = dstImage->TexFormat->TexelBytes;
+ bytesPerTexel = _mesa_get_format_bytes(dstImage->TexFormat);
ASSERT(dstWidth * dstHeight * dstDepth * bytesPerTexel > 0);
dstImage->Data = _mesa_alloc_texmemory(dstWidth * dstHeight
* dstDepth * bytesPerTexel);
@@ -1649,6 +1647,10 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
dstData = (GLubyte *) dstImage->Data;
}
+ ASSERT(dstImage->TexFormat);
+ ASSERT(dstImage->FetchTexelc);
+ ASSERT(dstImage->FetchTexelf);
+
_mesa_generate_mipmap_level(target, datatype, comps, border,
srcWidth, srcHeight, srcDepth,
srcData, srcImage->RowStride,
@@ -1656,22 +1658,24 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
dstData, dstImage->RowStride);
- if (dstImage->IsCompressed) {
+ if (_mesa_is_format_compressed(dstImage->TexFormat)) {
GLubyte *temp;
/* compress image from dstData into dstImage->Data */
- const GLenum srcFormat = convertFormat->BaseFormat;
+ const GLenum srcFormat = _mesa_get_format_base_format(convertFormat);
GLint dstRowStride
- = _mesa_compressed_row_stride(dstImage->TexFormat->MesaFormat, dstWidth);
+ = _mesa_format_row_stride(dstImage->TexFormat, dstWidth);
ASSERT(srcFormat == GL_RGB || srcFormat == GL_RGBA);
- dstImage->TexFormat->StoreImage(ctx, 2, dstImage->_BaseFormat,
- dstImage->TexFormat,
- dstImage->Data,
- 0, 0, 0, /* dstX/Y/Zoffset */
- dstRowStride, 0, /* strides */
- dstWidth, dstHeight, 1, /* size */
- srcFormat, CHAN_TYPE,
- dstData, /* src data, actually */
- &ctx->DefaultPacking);
+
+ _mesa_texstore(ctx, 2, dstImage->_BaseFormat,
+ dstImage->TexFormat,
+ dstImage->Data,
+ 0, 0, 0, /* dstX/Y/Zoffset */
+ dstRowStride, 0, /* strides */
+ dstWidth, dstHeight, 1, /* size */
+ srcFormat, CHAN_TYPE,
+ dstData, /* src data, actually */
+ &ctx->DefaultPacking);
+
/* swap src and dest pointers */
temp = (GLubyte *) srcData;
srcData = dstData;
@@ -1679,12 +1683,6 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
}
} /* loop over mipmap levels */
-
- if (srcImage->IsCompressed) {
- /* free uncompressed image buffers */
- _mesa_free((void *) srcData);
- _mesa_free(dstData);
- }
}
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 052fbaaaeab..41acc6fddaa 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1115,91 +1115,6 @@ typedef void (*StoreTexelFunc)(struct gl_texture_image *texImage,
/**
- * This macro defines the (many) parameters to the texstore functions.
- * \param dims either 1 or 2 or 3
- * \param baseInternalFormat user-specified base internal format
- * \param dstFormat destination Mesa texture format
- * \param dstAddr destination image address
- * \param dstX/Y/Zoffset destination x/y/z offset (ala TexSubImage), in texels
- * \param dstRowStride destination image row stride, in bytes
- * \param dstImageOffsets offset of each 2D slice within 3D texture, in texels
- * \param srcWidth/Height/Depth source image size, in pixels
- * \param srcFormat incoming image format
- * \param srcType incoming image data type
- * \param srcAddr source image address
- * \param srcPacking source image packing parameters
- */
-#define TEXSTORE_PARAMS \
- GLcontext *ctx, GLuint dims, \
- GLenum baseInternalFormat, \
- const struct gl_texture_format *dstFormat, \
- GLvoid *dstAddr, \
- GLint dstXoffset, GLint dstYoffset, GLint dstZoffset, \
- GLint dstRowStride, const GLuint *dstImageOffsets, \
- GLint srcWidth, GLint srcHeight, GLint srcDepth, \
- GLenum srcFormat, GLenum srcType, \
- const GLvoid *srcAddr, \
- const struct gl_pixelstore_attrib *srcPacking
-
-
-
-/**
- * Texture image storage function.
- */
-typedef GLboolean (*StoreTexImageFunc)(TEXSTORE_PARAMS);
-
-
-/**
- * Texture format record
- */
-struct gl_texture_format
-{
- GLint MesaFormat; /**< One of the MESA_FORMAT_* values */
-
- GLenum BaseFormat; /**< Either GL_RGB, GL_RGBA, GL_ALPHA,
- * GL_LUMINANCE, GL_LUMINANCE_ALPHA,
- * GL_INTENSITY, GL_COLOR_INDEX or
- * GL_DEPTH_COMPONENT.
- */
- GLenum DataType; /**< GL_FLOAT or GL_UNSIGNED_NORMALIZED_ARB */
-
- /**
- * Bits per texel component. These are just rough approximations
- * for compressed texture formats.
- */
- /*@{*/
- GLubyte RedBits;
- GLubyte GreenBits;
- GLubyte BlueBits;
- GLubyte AlphaBits;
- GLubyte LuminanceBits;
- GLubyte IntensityBits;
- GLubyte IndexBits;
- GLubyte DepthBits;
- GLubyte StencilBits; /**< GL_EXT_packed_depth_stencil */
- /*@}*/
-
- GLuint TexelBytes; /**< Bytes per texel, 0 if compressed format */
-
- StoreTexImageFunc StoreImage;
-
- /**
- * \name Texel fetch function pointers
- */
- /*@{*/
- FetchTexelFuncC FetchTexel1D;
- FetchTexelFuncC FetchTexel2D;
- FetchTexelFuncC FetchTexel3D;
- FetchTexelFuncF FetchTexel1Df;
- FetchTexelFuncF FetchTexel2Df;
- FetchTexelFuncF FetchTexel3Df;
- /*@}*/
-
- StoreTexelFunc StoreTexel;
-};
-
-
-/**
* Texture image state. Describes the dimensions of a texture image,
* the texel format and pointers to Texel Fetch functions.
*/
@@ -1229,16 +1144,13 @@ struct gl_texture_image
GLboolean IsClientData; /**< Data owned by client? */
GLboolean _IsPowerOfTwo; /**< Are all dimensions powers of two? */
- const struct gl_texture_format *TexFormat;
+ GLuint TexFormat; /**< XXX Really gl_format */
struct gl_texture_object *TexObject; /**< Pointer back to parent object */
FetchTexelFuncC FetchTexelc; /**< GLchan texel fetch function pointer */
FetchTexelFuncF FetchTexelf; /**< Float texel fetch function pointer */
- GLboolean IsCompressed; /**< GL_ARB_texture_compression */
- GLuint CompressedSize; /**< GL_ARB_texture_compression */
-
GLuint RowStride; /**< Padded width in units of texels */
GLuint *ImageOffsets; /**< if 3D texture: array [Depth] of offsets to
each 2D slice in 'Data', in texels */
@@ -2158,19 +2070,9 @@ struct gl_renderbuffer
GLint RefCount;
GLuint Width, Height;
GLenum InternalFormat; /**< The user-specified format */
- GLenum _ActualFormat; /**< The driver-chosen format */
GLenum _BaseFormat; /**< Either GL_RGB, GL_RGBA, GL_DEPTH_COMPONENT or
GL_STENCIL_INDEX. */
- GLenum ColorEncoding; /**< GL_LINEAR or GL_SRGB */
- GLenum ComponentType; /**< GL_FLOAT, GL_INT, GL_UNSIGNED_INT,
- GL_UNSIGNED_NORMALIZED or GL_INDEX */
- GLubyte RedBits; /**< Bits of red per pixel */
- GLubyte GreenBits;
- GLubyte BlueBits;
- GLubyte AlphaBits;
- GLubyte IndexBits;
- GLubyte DepthBits;
- GLubyte StencilBits;
+ GLuint Format; /**< The actual format: MESA_FORMAT_x */
GLubyte NumSamples;
GLenum DataType; /**< Type of values passed to the Get/Put functions */
diff --git a/src/mesa/main/rbadaptors.c b/src/mesa/main/rbadaptors.c
index c1ac0606c86..1060c5796ed 100644
--- a/src/mesa/main/rbadaptors.c
+++ b/src/mesa/main/rbadaptors.c
@@ -218,14 +218,10 @@ _mesa_new_renderbuffer_16wrap8(GLcontext *ctx, struct gl_renderbuffer *rb8)
_glthread_UNLOCK_MUTEX(rb8->Mutex);
rb16->InternalFormat = rb8->InternalFormat;
- rb16->_ActualFormat = rb8->_ActualFormat;
+ rb16->Format = rb8->Format; /* XXX is this right? */
rb16->_BaseFormat = rb8->_BaseFormat;
rb16->DataType = GL_UNSIGNED_SHORT;
/* Note: passing through underlying bits/channel */
- rb16->RedBits = rb8->RedBits;
- rb16->GreenBits = rb8->GreenBits;
- rb16->BlueBits = rb8->BlueBits;
- rb16->AlphaBits = rb8->AlphaBits;
rb16->Wrapped = rb8;
rb16->AllocStorage = AllocStorage_wrapper;
@@ -385,14 +381,10 @@ _mesa_new_renderbuffer_32wrap8(GLcontext *ctx, struct gl_renderbuffer *rb8)
_glthread_UNLOCK_MUTEX(rb8->Mutex);
rb32->InternalFormat = rb8->InternalFormat;
- rb32->_ActualFormat = rb8->_ActualFormat;
+ rb32->Format = rb8->Format; /* XXX is this right? */
rb32->_BaseFormat = rb8->_BaseFormat;
rb32->DataType = GL_FLOAT;
/* Note: passing through underlying bits/channel */
- rb32->RedBits = rb8->RedBits;
- rb32->GreenBits = rb8->GreenBits;
- rb32->BlueBits = rb8->BlueBits;
- rb32->AlphaBits = rb8->AlphaBits;
rb32->Wrapped = rb8;
rb32->AllocStorage = AllocStorage_wrapper;
@@ -552,14 +544,10 @@ _mesa_new_renderbuffer_32wrap16(GLcontext *ctx, struct gl_renderbuffer *rb16)
_glthread_UNLOCK_MUTEX(rb16->Mutex);
rb32->InternalFormat = rb16->InternalFormat;
- rb32->_ActualFormat = rb16->_ActualFormat;
+ rb32->Format = rb16->Format; /* XXX is this right? */
rb32->_BaseFormat = rb16->_BaseFormat;
rb32->DataType = GL_FLOAT;
/* Note: passing through underlying bits/channel */
- rb32->RedBits = rb16->RedBits;
- rb32->GreenBits = rb16->GreenBits;
- rb32->BlueBits = rb16->BlueBits;
- rb32->AlphaBits = rb16->AlphaBits;
rb32->Wrapped = rb16;
rb32->AllocStorage = AllocStorage_wrapper;
diff --git a/src/mesa/main/renderbuffer.c b/src/mesa/main/renderbuffer.c
index 5bef7c84fb2..3bb062bae2a 100644
--- a/src/mesa/main/renderbuffer.c
+++ b/src/mesa/main/renderbuffer.c
@@ -43,6 +43,8 @@
#include "glheader.h"
#include "imports.h"
#include "context.h"
+#include "fbobject.h"
+#include "formats.h"
#include "mtypes.h"
#include "fbobject.h"
#include "renderbuffer.h"
@@ -72,7 +74,7 @@ get_pointer_ubyte(GLcontext *ctx, struct gl_renderbuffer *rb,
if (!rb->Data)
return NULL;
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- /* Can't assert _ActualFormat since these funcs may be used for serveral
+ /* 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;
@@ -448,7 +450,7 @@ static void *
get_pointer_ubyte3(GLcontext *ctx, struct gl_renderbuffer *rb,
GLint x, GLint y)
{
- ASSERT(rb->_ActualFormat == GL_RGB8);
+ ASSERT(rb->Format == MESA_FORMAT_RGB888);
/* No direct access since this buffer is RGB but caller will be
* treating it as if it were RGBA.
*/
@@ -463,7 +465,7 @@ get_row_ubyte3(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
const GLubyte *src = (const GLubyte *) rb->Data + 3 * (y * rb->Width + x);
GLubyte *dst = (GLubyte *) values;
GLuint i;
- ASSERT(rb->_ActualFormat == GL_RGB8);
+ ASSERT(rb->Format == MESA_FORMAT_RGB888);
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
for (i = 0; i < count; i++) {
dst[i * 4 + 0] = src[i * 3 + 0];
@@ -480,7 +482,7 @@ get_values_ubyte3(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
{
GLubyte *dst = (GLubyte *) values;
GLuint i;
- ASSERT(rb->_ActualFormat == GL_RGB8);
+ ASSERT(rb->Format == MESA_FORMAT_RGB888);
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
for (i = 0; i < count; i++) {
const GLubyte *src
@@ -501,7 +503,7 @@ put_row_ubyte3(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
const GLubyte *src = (const GLubyte *) values;
GLubyte *dst = (GLubyte *) rb->Data + 3 * (y * rb->Width + x);
GLuint i;
- ASSERT(rb->_ActualFormat == GL_RGB8);
+ ASSERT(rb->Format == MESA_FORMAT_RGB888);
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
@@ -521,7 +523,7 @@ put_row_rgb_ubyte3(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
const GLubyte *src = (const GLubyte *) values;
GLubyte *dst = (GLubyte *) rb->Data + 3 * (y * rb->Width + x);
GLuint i;
- ASSERT(rb->_ActualFormat == GL_RGB8);
+ ASSERT(rb->Format == MESA_FORMAT_RGB888);
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
@@ -542,7 +544,7 @@ put_mono_row_ubyte3(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
const GLubyte val1 = ((const GLubyte *) value)[1];
const GLubyte val2 = ((const GLubyte *) value)[2];
GLubyte *dst = (GLubyte *) rb->Data + 3 * (y * rb->Width + x);
- ASSERT(rb->_ActualFormat == GL_RGB8);
+ ASSERT(rb->Format == MESA_FORMAT_RGB888);
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
if (!mask && val0 == val1 && val1 == val2) {
/* optimized case */
@@ -569,7 +571,7 @@ put_values_ubyte3(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
/* note: incoming values are RGB+A! */
const GLubyte *src = (const GLubyte *) values;
GLuint i;
- ASSERT(rb->_ActualFormat == GL_RGB8);
+ ASSERT(rb->Format == MESA_FORMAT_RGB888);
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
@@ -592,7 +594,7 @@ put_mono_values_ubyte3(GLcontext *ctx, struct gl_renderbuffer *rb,
const GLubyte val1 = ((const GLubyte *) value)[1];
const GLubyte val2 = ((const GLubyte *) value)[2];
GLuint i;
- ASSERT(rb->_ActualFormat == GL_RGB8);
+ ASSERT(rb->Format == MESA_FORMAT_RGB888);
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
@@ -617,7 +619,7 @@ get_pointer_ubyte4(GLcontext *ctx, struct gl_renderbuffer *rb,
if (!rb->Data)
return NULL;
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- ASSERT(rb->_ActualFormat == GL_RGBA8);
+ ASSERT(rb->Format == MESA_FORMAT_RGBA8888);
return (GLubyte *) rb->Data + 4 * (y * rb->Width + x);
}
@@ -628,7 +630,7 @@ get_row_ubyte4(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
{
const GLubyte *src = (const GLubyte *) rb->Data + 4 * (y * rb->Width + x);
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- ASSERT(rb->_ActualFormat == GL_RGBA8);
+ ASSERT(rb->Format == MESA_FORMAT_RGBA8888);
_mesa_memcpy(values, src, 4 * count * sizeof(GLubyte));
}
@@ -641,7 +643,7 @@ get_values_ubyte4(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
GLuint *dst = (GLuint *) values;
GLuint i;
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- ASSERT(rb->_ActualFormat == GL_RGBA8);
+ ASSERT(rb->Format == MESA_FORMAT_RGBA8888);
for (i = 0; i < count; i++) {
const GLuint *src = (GLuint *) rb->Data + (y[i] * rb->Width + x[i]);
dst[i] = *src;
@@ -657,7 +659,7 @@ put_row_ubyte4(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
const GLuint *src = (const GLuint *) values;
GLuint *dst = (GLuint *) rb->Data + (y * rb->Width + x);
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- ASSERT(rb->_ActualFormat == GL_RGBA8);
+ ASSERT(rb->Format == MESA_FORMAT_RGBA8888);
if (mask) {
GLuint i;
for (i = 0; i < count; i++) {
@@ -681,7 +683,7 @@ put_row_rgb_ubyte4(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
GLubyte *dst = (GLubyte *) rb->Data + 4 * (y * rb->Width + x);
GLuint i;
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- ASSERT(rb->_ActualFormat == GL_RGBA8);
+ ASSERT(rb->Format == MESA_FORMAT_RGBA8888);
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
dst[i * 4 + 0] = src[i * 3 + 0];
@@ -701,7 +703,7 @@ put_mono_row_ubyte4(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
const GLuint val = *((const GLuint *) value);
GLuint *dst = (GLuint *) rb->Data + (y * rb->Width + x);
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- ASSERT(rb->_ActualFormat == GL_RGBA8);
+ ASSERT(rb->Format == MESA_FORMAT_RGBA8888);
if (!mask && val == 0) {
/* common case */
_mesa_bzero(dst, count * 4 * sizeof(GLubyte));
@@ -735,7 +737,7 @@ put_values_ubyte4(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
const GLuint *src = (const GLuint *) values;
GLuint i;
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- ASSERT(rb->_ActualFormat == GL_RGBA8);
+ 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]);
@@ -754,7 +756,7 @@ put_mono_values_ubyte4(GLcontext *ctx, struct gl_renderbuffer *rb,
const GLuint val = *((const GLuint *) value);
GLuint i;
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- ASSERT(rb->_ActualFormat == GL_RGBA8);
+ 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]);
@@ -947,15 +949,6 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
{
GLuint pixelSize;
- /* first clear these fields */
- rb->RedBits =
- rb->GreenBits =
- rb->BlueBits =
- rb->AlphaBits =
- rb->IndexBits =
- rb->DepthBits =
- rb->StencilBits = 0;
-
switch (internalFormat) {
case GL_RGB:
case GL_R3_G3_B2:
@@ -965,8 +958,7 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
case GL_RGB10:
case GL_RGB12:
case GL_RGB16:
- rb->_ActualFormat = GL_RGB8;
- rb->_BaseFormat = GL_RGB;
+ rb->Format = MESA_FORMAT_RGB888;
rb->DataType = GL_UNSIGNED_BYTE;
rb->GetPointer = get_pointer_ubyte3;
rb->GetRow = get_row_ubyte3;
@@ -976,10 +968,6 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
rb->PutMonoRow = put_mono_row_ubyte3;
rb->PutValues = put_values_ubyte3;
rb->PutMonoValues = put_mono_values_ubyte3;
- rb->RedBits = 8 * sizeof(GLubyte);
- rb->GreenBits = 8 * sizeof(GLubyte);
- rb->BlueBits = 8 * sizeof(GLubyte);
- rb->AlphaBits = 0;
pixelSize = 3 * sizeof(GLubyte);
break;
case GL_RGBA:
@@ -987,8 +975,11 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
case GL_RGBA4:
case GL_RGB5_A1:
case GL_RGBA8:
- rb->_ActualFormat = GL_RGBA8;
- rb->_BaseFormat = GL_RGBA;
+#if 1
+ case GL_RGB10_A2:
+ case GL_RGBA12:
+#endif
+ rb->Format = MESA_FORMAT_RGBA8888;
rb->DataType = GL_UNSIGNED_BYTE;
rb->GetPointer = get_pointer_ubyte4;
rb->GetRow = get_row_ubyte4;
@@ -998,18 +989,12 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
rb->PutMonoRow = put_mono_row_ubyte4;
rb->PutValues = put_values_ubyte4;
rb->PutMonoValues = put_mono_values_ubyte4;
- rb->RedBits = 8 * sizeof(GLubyte);
- rb->GreenBits = 8 * sizeof(GLubyte);
- rb->BlueBits = 8 * sizeof(GLubyte);
- rb->AlphaBits = 8 * sizeof(GLubyte);
pixelSize = 4 * sizeof(GLubyte);
break;
- case GL_RGB10_A2:
- case GL_RGBA12:
case GL_RGBA16:
- rb->_ActualFormat = GL_RGBA16;
- rb->_BaseFormat = GL_RGBA;
- rb->DataType = GL_UNSIGNED_SHORT;
+ /* for accum buffer */
+ rb->Format = MESA_FORMAT_SIGNED_RGBA_16;
+ rb->DataType = GL_SHORT;
rb->GetPointer = get_pointer_ushort4;
rb->GetRow = get_row_ushort4;
rb->GetValues = get_values_ushort4;
@@ -1018,16 +1003,11 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
rb->PutMonoRow = put_mono_row_ushort4;
rb->PutValues = put_values_ushort4;
rb->PutMonoValues = put_mono_values_ushort4;
- rb->RedBits = 8 * sizeof(GLushort);
- rb->GreenBits = 8 * sizeof(GLushort);
- rb->BlueBits = 8 * sizeof(GLushort);
- rb->AlphaBits = 8 * sizeof(GLushort);
pixelSize = 4 * sizeof(GLushort);
break;
-#if 00
+#if 0
case GL_ALPHA8:
- rb->_ActualFormat = GL_ALPHA8;
- rb->_BaseFormat = GL_RGBA; /* Yes, not GL_ALPHA! */
+ rb->Format = MESA_FORMAT_A8;
rb->DataType = GL_UNSIGNED_BYTE;
rb->GetPointer = get_pointer_alpha8;
rb->GetRow = get_row_alpha8;
@@ -1037,10 +1017,6 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
rb->PutMonoRow = put_mono_row_alpha8;
rb->PutValues = put_values_alpha8;
rb->PutMonoValues = put_mono_values_alpha8;
- rb->RedBits = 0; /*red*/
- rb->GreenBits = 0; /*green*/
- rb->BlueBits = 0; /*blue*/
- rb->AlphaBits = 8 * sizeof(GLubyte);
pixelSize = sizeof(GLubyte);
break;
#endif
@@ -1048,8 +1024,8 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
case GL_STENCIL_INDEX1_EXT:
case GL_STENCIL_INDEX4_EXT:
case GL_STENCIL_INDEX8_EXT:
- rb->_ActualFormat = GL_STENCIL_INDEX8_EXT;
- rb->_BaseFormat = GL_STENCIL_INDEX;
+ case GL_STENCIL_INDEX16_EXT:
+ rb->Format = MESA_FORMAT_S8;
rb->DataType = GL_UNSIGNED_BYTE;
rb->GetPointer = get_pointer_ubyte;
rb->GetRow = get_row_ubyte;
@@ -1059,28 +1035,11 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
rb->PutMonoRow = put_mono_row_ubyte;
rb->PutValues = put_values_ubyte;
rb->PutMonoValues = put_mono_values_ubyte;
- rb->StencilBits = 8 * sizeof(GLubyte);
pixelSize = sizeof(GLubyte);
break;
- case GL_STENCIL_INDEX16_EXT:
- rb->_ActualFormat = GL_STENCIL_INDEX16_EXT;
- rb->_BaseFormat = GL_STENCIL_INDEX;
- 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;
- rb->StencilBits = 8 * sizeof(GLushort);
- pixelSize = sizeof(GLushort);
- break;
case GL_DEPTH_COMPONENT:
case GL_DEPTH_COMPONENT16:
- rb->_ActualFormat = GL_DEPTH_COMPONENT16;
- rb->_BaseFormat = GL_DEPTH_COMPONENT;
+ rb->Format = MESA_FORMAT_Z16;
rb->DataType = GL_UNSIGNED_SHORT;
rb->GetPointer = get_pointer_ushort;
rb->GetRow = get_row_ushort;
@@ -1090,12 +1049,22 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
rb->PutMonoRow = put_mono_row_ushort;
rb->PutValues = put_values_ushort;
rb->PutMonoValues = put_mono_values_ushort;
- rb->DepthBits = 8 * sizeof(GLushort);
pixelSize = sizeof(GLushort);
break;
case GL_DEPTH_COMPONENT24:
+ 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->_BaseFormat = GL_DEPTH_COMPONENT;
rb->DataType = GL_UNSIGNED_INT;
rb->GetPointer = get_pointer_uint;
rb->GetRow = get_row_uint;
@@ -1105,20 +1074,12 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
rb->PutMonoRow = put_mono_row_uint;
rb->PutValues = put_values_uint;
rb->PutMonoValues = put_mono_values_uint;
- if (internalFormat == GL_DEPTH_COMPONENT24) {
- rb->_ActualFormat = GL_DEPTH_COMPONENT24;
- rb->DepthBits = 24;
- }
- else {
- rb->_ActualFormat = GL_DEPTH_COMPONENT32;
- rb->DepthBits = 32;
- }
+ rb->Format = MESA_FORMAT_Z32;
pixelSize = sizeof(GLuint);
break;
case GL_DEPTH_STENCIL_EXT:
case GL_DEPTH24_STENCIL8_EXT:
- rb->_ActualFormat = GL_DEPTH24_STENCIL8_EXT;
- rb->_BaseFormat = GL_DEPTH_STENCIL_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;
@@ -1128,13 +1089,12 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
rb->PutMonoRow = put_mono_row_uint;
rb->PutValues = put_values_uint;
rb->PutMonoValues = put_mono_values_uint;
- rb->DepthBits = 24;
- rb->StencilBits = 8;
pixelSize = sizeof(GLuint);
break;
case GL_COLOR_INDEX8_EXT:
- rb->_ActualFormat = GL_COLOR_INDEX8_EXT;
- rb->_BaseFormat = GL_COLOR_INDEX;
+ case GL_COLOR_INDEX16_EXT:
+ case COLOR_INDEX32:
+ rb->Format = MESA_FORMAT_CI8;
rb->DataType = GL_UNSIGNED_BYTE;
rb->GetPointer = get_pointer_ubyte;
rb->GetRow = get_row_ubyte;
@@ -1144,39 +1104,8 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
rb->PutMonoRow = put_mono_row_ubyte;
rb->PutValues = put_values_ubyte;
rb->PutMonoValues = put_mono_values_ubyte;
- rb->IndexBits = 8 * sizeof(GLubyte);
pixelSize = sizeof(GLubyte);
break;
- case GL_COLOR_INDEX16_EXT:
- rb->_ActualFormat = GL_COLOR_INDEX16_EXT;
- rb->_BaseFormat = GL_COLOR_INDEX;
- 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;
- rb->IndexBits = 8 * sizeof(GLushort);
- pixelSize = sizeof(GLushort);
- break;
- case COLOR_INDEX32:
- rb->_ActualFormat = COLOR_INDEX32;
- rb->_BaseFormat = GL_COLOR_INDEX;
- 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->IndexBits = 8 * sizeof(GLuint);
- pixelSize = sizeof(GLuint);
- break;
default:
_mesa_problem(ctx, "Bad internalFormat in _mesa_soft_renderbuffer_storage");
return GL_FALSE;
@@ -1213,6 +1142,7 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
rb->Width = width;
rb->Height = height;
+ rb->_BaseFormat = _mesa_base_fbo_format(ctx, rb->InternalFormat);
return GL_TRUE;
}
@@ -1239,7 +1169,7 @@ alloc_storage_alpha8(GLcontext *ctx, struct gl_renderbuffer *arb,
GLenum internalFormat, GLuint width, GLuint height)
{
ASSERT(arb != arb->Wrapped);
- ASSERT(arb->_ActualFormat == GL_ALPHA8);
+ ASSERT(arb->Format == MESA_FORMAT_A8);
/* first, pass the call to the wrapped RGB buffer */
if (!arb->Wrapped->AllocStorage(ctx, arb->Wrapped, internalFormat,
@@ -1439,8 +1369,8 @@ put_mono_values_alpha8(GLcontext *ctx, struct gl_renderbuffer *arb,
static void
copy_buffer_alpha8(struct gl_renderbuffer* dst, struct gl_renderbuffer* src)
{
- ASSERT(dst->_ActualFormat == GL_ALPHA8);
- ASSERT(src->_ActualFormat == GL_ALPHA8);
+ ASSERT(dst->Format == MESA_FORMAT_A8);
+ ASSERT(src->Format == MESA_FORMAT_A8);
ASSERT(dst->Width == src->Width);
ASSERT(dst->Height == src->Height);
@@ -1486,16 +1416,7 @@ _mesa_init_renderbuffer(struct gl_renderbuffer *rb, GLuint name)
rb->Width = 0;
rb->Height = 0;
rb->InternalFormat = GL_NONE;
- rb->_ActualFormat = GL_NONE;
- rb->_BaseFormat = GL_NONE;
-
- rb->ComponentType = GL_UNSIGNED_NORMALIZED; /* ARB_fbo */
- rb->ColorEncoding = GL_LINEAR; /* ARB_fbo */
-
- rb->RedBits = rb->GreenBits = rb->BlueBits = rb->AlphaBits = 0;
- rb->IndexBits = 0;
- rb->DepthBits = 0;
- rb->StencilBits = 0;
+ rb->Format = MESA_FORMAT_NONE;
rb->DataType = GL_NONE;
rb->Data = NULL;
@@ -1612,18 +1533,15 @@ _mesa_add_color_renderbuffers(GLcontext *ctx, struct gl_framebuffer *fb,
if (rgbBits <= 8) {
if (alphaBits)
- rb->_ActualFormat = GL_RGBA8;
+ rb->Format = MESA_FORMAT_RGBA8888;
else
- rb->_ActualFormat = GL_RGB8;
+ rb->Format = MESA_FORMAT_RGB888;
}
else {
assert(rgbBits <= 16);
- if (alphaBits)
- rb->_ActualFormat = GL_RGBA16;
- else
- rb->_ActualFormat = GL_RGBA16; /* don't really have RGB16 yet */
+ rb->Format = MESA_FORMAT_NONE; /*XXX RGBA16;*/
}
- rb->InternalFormat = rb->_ActualFormat;
+ rb->InternalFormat = GL_RGBA;
rb->AllocStorage = _mesa_soft_renderbuffer_storage;
_mesa_add_renderbuffer(fb, b, rb);
@@ -1677,15 +1595,9 @@ _mesa_add_color_index_renderbuffers(GLcontext *ctx, struct gl_framebuffer *fb,
return GL_FALSE;
}
- if (indexBits <= 8) {
- /* only support GLuint for now */
- /*rb->InternalFormat = GL_COLOR_INDEX8_EXT;*/
- rb->_ActualFormat = COLOR_INDEX32;
- }
- else {
- rb->_ActualFormat = COLOR_INDEX32;
- }
- rb->InternalFormat = rb->_ActualFormat;
+ assert(indexBits <= 8);
+ rb->Format = MESA_FORMAT_CI8;
+ rb->InternalFormat = GL_COLOR_INDEX;
rb->AllocStorage = _mesa_soft_renderbuffer_storage;
_mesa_add_renderbuffer(fb, b, rb);
@@ -1758,8 +1670,7 @@ _mesa_add_alpha_renderbuffers(GLcontext *ctx, struct gl_framebuffer *fb,
* values.
*/
arb->InternalFormat = arb->Wrapped->InternalFormat;
- arb->_ActualFormat = GL_ALPHA8;
- arb->_BaseFormat = arb->Wrapped->_BaseFormat;
+ arb->Format = MESA_FORMAT_A8;
arb->DataType = arb->Wrapped->DataType;
arb->AllocStorage = alloc_storage_alpha8;
arb->Delete = delete_renderbuffer_alpha8;
@@ -1833,15 +1744,17 @@ _mesa_add_depth_renderbuffer(GLcontext *ctx, struct gl_framebuffer *fb,
}
if (depthBits <= 16) {
- rb->_ActualFormat = GL_DEPTH_COMPONENT16;
+ rb->Format = MESA_FORMAT_Z16;
+ rb->InternalFormat = GL_DEPTH_COMPONENT16;
}
else if (depthBits <= 24) {
- rb->_ActualFormat = GL_DEPTH_COMPONENT24;
+ rb->Format = MESA_FORMAT_X8_Z24;
+ rb->InternalFormat = GL_DEPTH_COMPONENT24;
}
else {
- rb->_ActualFormat = GL_DEPTH_COMPONENT32;
+ rb->Format = MESA_FORMAT_Z32;
+ rb->InternalFormat = GL_DEPTH_COMPONENT32;
}
- rb->InternalFormat = rb->_ActualFormat;
rb->AllocStorage = _mesa_soft_renderbuffer_storage;
_mesa_add_renderbuffer(fb, BUFFER_DEPTH, rb);
@@ -1878,14 +1791,9 @@ _mesa_add_stencil_renderbuffer(GLcontext *ctx, struct gl_framebuffer *fb,
return GL_FALSE;
}
- if (stencilBits <= 8) {
- rb->_ActualFormat = GL_STENCIL_INDEX8_EXT;
- }
- else {
- /* not really supported (see s_stencil.c code) */
- rb->_ActualFormat = GL_STENCIL_INDEX16_EXT;
- }
- rb->InternalFormat = rb->_ActualFormat;
+ assert(stencilBits <= 8);
+ rb->Format = MESA_FORMAT_S8;
+ rb->InternalFormat = GL_STENCIL_INDEX8;
rb->AllocStorage = _mesa_soft_renderbuffer_storage;
_mesa_add_renderbuffer(fb, BUFFER_STENCIL, rb);
@@ -1923,7 +1831,7 @@ _mesa_add_accum_renderbuffer(GLcontext *ctx, struct gl_framebuffer *fb,
return GL_FALSE;
}
- rb->_ActualFormat = GL_RGBA16;
+ rb->Format = MESA_FORMAT_SIGNED_RGBA_16;
rb->InternalFormat = GL_RGBA16;
rb->AllocStorage = _mesa_soft_renderbuffer_storage;
_mesa_add_renderbuffer(fb, BUFFER_ACCUM, rb);
@@ -1967,13 +1875,9 @@ _mesa_add_aux_renderbuffers(GLcontext *ctx, struct gl_framebuffer *fb,
return GL_FALSE;
}
- if (colorBits <= 8) {
- rb->_ActualFormat = GL_RGBA8;
- }
- else {
- rb->_ActualFormat = GL_RGBA16;
- }
- rb->InternalFormat = rb->_ActualFormat;
+ assert (colorBits <= 8);
+ rb->Format = MESA_FORMAT_RGBA8888;
+ rb->InternalFormat = GL_RGBA;
rb->AllocStorage = _mesa_soft_renderbuffer_storage;
_mesa_add_renderbuffer(fb, BUFFER_AUX0 + i, rb);
@@ -2071,6 +1975,8 @@ void
_mesa_add_renderbuffer(struct gl_framebuffer *fb,
GLuint bufferName, struct gl_renderbuffer *rb)
{
+ GLenum baseFormat;
+
assert(fb);
assert(rb);
assert(bufferName < BUFFER_COUNT);
@@ -2095,7 +2001,8 @@ _mesa_add_renderbuffer(struct gl_framebuffer *fb,
* and the device driver is expecting 8-bit values (GLubyte), we can
* use a "renderbuffer adaptor/wrapper" to do the necessary conversions.
*/
- if (rb->_BaseFormat == GL_RGBA) {
+ baseFormat = _mesa_get_format_base_format(rb->Format);
+ if (baseFormat == GL_RGBA) {
if (CHAN_BITS == 16 && rb->DataType == GL_UNSIGNED_BYTE) {
GET_CURRENT_CONTEXT(ctx);
rb = _mesa_new_renderbuffer_16wrap8(ctx, rb);
@@ -2202,7 +2109,7 @@ _mesa_new_depthstencil_renderbuffer(GLcontext *ctx, GLuint name)
/* init fields not covered by _mesa_new_renderbuffer() */
dsrb->InternalFormat = GL_DEPTH24_STENCIL8_EXT;
- dsrb->_ActualFormat = GL_DEPTH24_STENCIL8_EXT;
+ dsrb->Format = MESA_FORMAT_Z24_S8;
dsrb->AllocStorage = _mesa_soft_renderbuffer_storage;
return dsrb;
diff --git a/src/mesa/main/texcompress.c b/src/mesa/main/texcompress.c
index 2cda4dd8598..11f8857fa7c 100644
--- a/src/mesa/main/texcompress.c
+++ b/src/mesa/main/texcompress.c
@@ -34,10 +34,10 @@
#include "imports.h"
#include "colormac.h"
#include "context.h"
+#include "formats.h"
#include "image.h"
#include "mipmap.h"
#include "texcompress.h"
-#include "texformat.h"
#include "texstore.h"
@@ -113,252 +113,75 @@ _mesa_get_compressed_formats(GLcontext *ctx, GLint *formats, GLboolean all)
}
-
/**
- * Return number of bytes needed to store a texture of the given size
- * using the specified compressed format.
- * This is called via the ctx->Driver.CompressedTextureSize function,
- * unless a device driver overrides it.
- *
- * \param width texture width in texels.
- * \param height texture height in texels.
- * \param depth texture depth in texels.
- * \param mesaFormat one of the MESA_FORMAT_* compressed formats
- *
- * \return size in bytes, or zero if bad format
+ * Convert a compressed MESA_FORMAT_x to a GLenum.
*/
-GLuint
-_mesa_compressed_texture_size( GLcontext *ctx,
- GLsizei width, GLsizei height, GLsizei depth,
- GLuint mesaFormat )
+gl_format
+_mesa_glenum_to_compressed_format(GLenum format)
{
- GLuint size;
-
- ASSERT(depth == 1);
- (void) depth;
- (void) size;
-
- switch (mesaFormat) {
-#if FEATURE_texture_fxt1
- case MESA_FORMAT_RGB_FXT1:
- case MESA_FORMAT_RGBA_FXT1:
- /* round up width to next multiple of 8, height to next multiple of 4 */
- width = (width + 7) & ~7;
- height = (height + 3) & ~3;
- /* 16 bytes per 8x4 tile of RGB[A] texels */
- size = width * height / 2;
- /* Textures smaller than 8x4 will effectively be made into 8x4 and
- * take 16 bytes.
- */
- return size;
-#endif
-#if FEATURE_texture_s3tc
- case MESA_FORMAT_RGB_DXT1:
- case MESA_FORMAT_RGBA_DXT1:
-#if FEATURE_EXT_texture_sRGB
- case MESA_FORMAT_SRGB_DXT1:
- case MESA_FORMAT_SRGBA_DXT1:
-#endif
- /* round up width, height to next multiple of 4 */
- width = (width + 3) & ~3;
- height = (height + 3) & ~3;
- /* 8 bytes per 4x4 tile of RGB[A] texels */
- size = width * height / 2;
- /* Textures smaller than 4x4 will effectively be made into 4x4 and
- * take 8 bytes.
- */
- return size;
- case MESA_FORMAT_RGBA_DXT3:
- case MESA_FORMAT_RGBA_DXT5:
-#if FEATURE_EXT_texture_sRGB
- case MESA_FORMAT_SRGBA_DXT3:
- case MESA_FORMAT_SRGBA_DXT5:
-#endif
- /* round up width, height to next multiple of 4 */
- width = (width + 3) & ~3;
- height = (height + 3) & ~3;
- /* 16 bytes per 4x4 tile of RGBA texels */
- size = width * height; /* simple! */
- /* Textures smaller than 4x4 will effectively be made into 4x4 and
- * take 16 bytes.
- */
- return size;
-#endif
- default:
- _mesa_problem(ctx, "bad mesaFormat in _mesa_compressed_texture_size");
- return 0;
- }
-}
-
-
-/**
- * As above, but format is specified by a GLenum (GL_COMPRESSED_*) token.
- *
- * Note: This function CAN NOT return a padded hardware texture size.
- * That's why we don't call the ctx->Driver.CompressedTextureSize() function.
- *
- * We use this function to validate the <imageSize> parameter
- * of glCompressedTex[Sub]Image1/2/3D(), which must be an exact match.
- */
-GLuint
-_mesa_compressed_texture_size_glenum(GLcontext *ctx,
- GLsizei width, GLsizei height,
- GLsizei depth, GLenum glformat)
-{
- GLuint mesaFormat;
-
- switch (glformat) {
-#if FEATURE_texture_fxt1
+ switch (format) {
case GL_COMPRESSED_RGB_FXT1_3DFX:
- mesaFormat = MESA_FORMAT_RGB_FXT1;
- break;
+ return MESA_FORMAT_RGB_FXT1;
case GL_COMPRESSED_RGBA_FXT1_3DFX:
- mesaFormat = MESA_FORMAT_RGBA_FXT1;
- break;
-#endif
-#if FEATURE_texture_s3tc
+ return MESA_FORMAT_RGBA_FXT1;
+
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
case GL_RGB_S3TC:
- mesaFormat = MESA_FORMAT_RGB_DXT1;
- break;
+ return MESA_FORMAT_RGB_DXT1;
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
case GL_RGB4_S3TC:
- mesaFormat = MESA_FORMAT_RGBA_DXT1;
- break;
+ return MESA_FORMAT_RGBA_DXT1;
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
case GL_RGBA_S3TC:
- mesaFormat = MESA_FORMAT_RGBA_DXT3;
- break;
+ return MESA_FORMAT_RGBA_DXT3;
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
case GL_RGBA4_S3TC:
- mesaFormat = MESA_FORMAT_RGBA_DXT5;
- break;
-#if FEATURE_EXT_texture_sRGB
+ return MESA_FORMAT_RGBA_DXT5;
+
case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
- mesaFormat = MESA_FORMAT_SRGB_DXT1;
- break;
+ return MESA_FORMAT_SRGB_DXT1;
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
- mesaFormat = MESA_FORMAT_SRGBA_DXT1;
- break;
+ return MESA_FORMAT_SRGBA_DXT1;
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
- mesaFormat = MESA_FORMAT_SRGBA_DXT3;
- break;
+ return MESA_FORMAT_SRGBA_DXT3;
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
- mesaFormat = MESA_FORMAT_SRGBA_DXT5;
- break;
-#endif
-#endif
- default:
- return 0;
- }
+ return MESA_FORMAT_SRGBA_DXT5;
- return _mesa_compressed_texture_size(ctx, width, height, depth, mesaFormat);
-}
-
-
-/*
- * Compute the bytes per row in a compressed texture image.
- * We use this for computing the destination address for sub-texture updates.
- * \param mesaFormat one of the MESA_FORMAT_* compressed formats
- * \param width image width in pixels
- * \return stride, in bytes, between rows for compressed image
- */
-GLint
-_mesa_compressed_row_stride(GLuint mesaFormat, GLsizei width)
-{
- GLint stride;
-
- switch (mesaFormat) {
-#if FEATURE_texture_fxt1
- case MESA_FORMAT_RGB_FXT1:
- case MESA_FORMAT_RGBA_FXT1:
- stride = ((width + 7) / 8) * 16; /* 16 bytes per 8x4 tile */
- break;
-#endif
-#if FEATURE_texture_s3tc
- case MESA_FORMAT_RGB_DXT1:
- case MESA_FORMAT_RGBA_DXT1:
-#if FEATURE_EXT_texture_sRGB
- case MESA_FORMAT_SRGB_DXT1:
- case MESA_FORMAT_SRGBA_DXT1:
-#endif
- stride = ((width + 3) / 4) * 8; /* 8 bytes per 4x4 tile */
- break;
- case MESA_FORMAT_RGBA_DXT3:
- case MESA_FORMAT_RGBA_DXT5:
-#if FEATURE_EXT_texture_sRGB
- case MESA_FORMAT_SRGBA_DXT3:
- case MESA_FORMAT_SRGBA_DXT5:
-#endif
- stride = ((width + 3) / 4) * 16; /* 16 bytes per 4x4 tile */
- break;
-#endif
default:
- _mesa_problem(NULL, "bad mesaFormat in _mesa_compressed_row_stride");
- return 0;
+ return MESA_FORMAT_NONE;
}
-
- return stride;
}
/*
* Return the address of the pixel at (col, row, img) in a
* compressed texture image.
- * \param col, row, img - image position (3D)
+ * \param col, row, img - image position (3D), should be a multiple of the
+ * format's block size.
* \param format - compressed image format
- * \param width - image width
+ * \param width - image width (stride) in pixels
* \param image - the image address
- * \return address of pixel at (row, col)
+ * \return address of pixel at (row, col, img)
*/
GLubyte *
_mesa_compressed_image_address(GLint col, GLint row, GLint img,
- GLuint mesaFormat,
+ gl_format mesaFormat,
GLsizei width, const GLubyte *image)
{
- GLubyte *addr;
+ /* XXX only 2D images implemented, not 3D */
+ const GLuint blockSize = _mesa_get_format_bytes(mesaFormat);
+ GLuint bw, bh;
+ GLint offset;
- (void) img;
+ _mesa_get_format_block_size(mesaFormat, &bw, &bh);
- /* We try to spot a "complete" subtexture "above" ROW, COL;
- * this texture is given by appropriate rounding of WIDTH x ROW.
- * Then we just add the amount left (usually on the left).
- *
- * Example for X*Y microtiles (Z bytes each)
- * offset = Z * (((width + X - 1) / X) * (row / Y) + col / X);
- */
+ ASSERT(col % bw == 0);
+ ASSERT(row % bh == 0);
- switch (mesaFormat) {
-#if FEATURE_texture_fxt1
- case MESA_FORMAT_RGB_FXT1:
- case MESA_FORMAT_RGBA_FXT1:
- addr = (GLubyte *) image + 16 * (((width + 7) / 8) * (row / 4) + col / 8);
- break;
-#endif
-#if FEATURE_texture_s3tc
- case MESA_FORMAT_RGB_DXT1:
- case MESA_FORMAT_RGBA_DXT1:
-#if FEATURE_EXT_texture_sRGB
- case MESA_FORMAT_SRGB_DXT1:
- case MESA_FORMAT_SRGBA_DXT1:
-#endif
- addr = (GLubyte *) image + 8 * (((width + 3) / 4) * (row / 4) + col / 4);
- break;
- case MESA_FORMAT_RGBA_DXT3:
- case MESA_FORMAT_RGBA_DXT5:
-#if FEATURE_EXT_texture_sRGB
- case MESA_FORMAT_SRGBA_DXT3:
- case MESA_FORMAT_SRGBA_DXT5:
-#endif
- addr = (GLubyte *) image + 16 * (((width + 3) / 4) * (row / 4) + col / 4);
- break;
-#endif
- default:
- _mesa_problem(NULL, "bad mesaFormat in _mesa_compressed_image_address");
- addr = NULL;
- }
+ offset = ((width + bw - 1) / bw) * (row / bh) + col / bw;
+ offset *= blockSize;
- return addr;
+ return (GLubyte *) image + offset;
}
diff --git a/src/mesa/main/texcompress.h b/src/mesa/main/texcompress.h
index 0f1a38f88e9..9c58425fc93 100644
--- a/src/mesa/main/texcompress.h
+++ b/src/mesa/main/texcompress.h
@@ -26,29 +26,19 @@
#define TEXCOMPRESS_H
#include "mtypes.h"
+#include "formats.h"
#if _HAVE_FULL_GL
extern GLuint
_mesa_get_compressed_formats(GLcontext *ctx, GLint *formats, GLboolean all);
-extern GLuint
-_mesa_compressed_texture_size( GLcontext *ctx,
- GLsizei width, GLsizei height, GLsizei depth,
- GLuint mesaFormat );
-
-extern GLuint
-_mesa_compressed_texture_size_glenum(GLcontext *ctx,
- GLsizei width, GLsizei height,
- GLsizei depth, GLenum glformat);
-
-extern GLint
-_mesa_compressed_row_stride(GLuint mesaFormat, GLsizei width);
-
+extern gl_format
+_mesa_glenum_to_compressed_format(GLenum format);
extern GLubyte *
_mesa_compressed_image_address(GLint col, GLint row, GLint img,
- GLuint mesaFormat,
+ gl_format mesaFormat,
GLsizei width, const GLubyte *image);
@@ -67,9 +57,6 @@ _mesa_init_texture_fxt1( GLcontext *ctx );
/* no-op macros */
#define _mesa_get_compressed_formats( c, f ) 0
-#define _mesa_compressed_texture_size( c, w, h, d, f ) 0
-#define _mesa_compressed_texture_size_glenum( c, w, h, d, f ) 0
-#define _mesa_compressed_row_stride( f, w) 0
#define _mesa_compressed_image_address(c, r, i, f, w, i2 ) 0
#define _mesa_compress_teximage( c, w, h, sF, s, sRS, dF, d, drs ) ((void)0)
diff --git a/src/mesa/main/texcompress_fxt1.c b/src/mesa/main/texcompress_fxt1.c
index fc151605c9e..ef42fb92b77 100644
--- a/src/mesa/main/texcompress_fxt1.c
+++ b/src/mesa/main/texcompress_fxt1.c
@@ -37,7 +37,7 @@
#include "image.h"
#include "mipmap.h"
#include "texcompress.h"
-#include "texformat.h"
+#include "texcompress_fxt1.h"
#include "texstore.h"
@@ -62,10 +62,10 @@ _mesa_init_texture_fxt1( GLcontext *ctx )
/**
- * Called via TexFormat->StoreImage to store an RGB_FXT1 texture.
+ * Store user's image in rgb_fxt1 format.
*/
-static GLboolean
-texstore_rgb_fxt1(TEXSTORE_PARAMS)
+GLboolean
+_mesa_texstore_rgb_fxt1(TEXSTORE_PARAMS)
{
const GLchan *pixels;
GLint srcRowStride;
@@ -73,7 +73,7 @@ texstore_rgb_fxt1(TEXSTORE_PARAMS)
const GLint texWidth = dstRowStride * 8 / 16; /* a bit of a hack */
const GLchan *tempImage = NULL;
- ASSERT(dstFormat == &_mesa_texformat_rgb_fxt1);
+ ASSERT(dstFormat == MESA_FORMAT_RGB_FXT1);
ASSERT(dstXoffset % 8 == 0);
ASSERT(dstYoffset % 4 == 0);
ASSERT(dstZoffset == 0);
@@ -87,7 +87,7 @@ texstore_rgb_fxt1(TEXSTORE_PARAMS)
/* convert image to RGB/GLchan */
tempImage = _mesa_make_temp_chan_image(ctx, dims,
baseInternalFormat,
- dstFormat->BaseFormat,
+ _mesa_get_format_base_format(dstFormat),
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
srcPacking);
@@ -105,7 +105,7 @@ texstore_rgb_fxt1(TEXSTORE_PARAMS)
}
dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
- dstFormat->MesaFormat,
+ dstFormat,
texWidth, (GLubyte *) dstAddr);
fxt1_encode(srcWidth, srcHeight, 3, pixels, srcRowStride,
@@ -119,10 +119,10 @@ texstore_rgb_fxt1(TEXSTORE_PARAMS)
/**
- * Called via TexFormat->StoreImage to store an RGBA_FXT1 texture.
+ * Store user's image in rgba_fxt1 format.
*/
-static GLboolean
-texstore_rgba_fxt1(TEXSTORE_PARAMS)
+GLboolean
+_mesa_texstore_rgba_fxt1(TEXSTORE_PARAMS)
{
const GLchan *pixels;
GLint srcRowStride;
@@ -130,7 +130,7 @@ texstore_rgba_fxt1(TEXSTORE_PARAMS)
GLint texWidth = dstRowStride * 8 / 16; /* a bit of a hack */
const GLchan *tempImage = NULL;
- ASSERT(dstFormat == &_mesa_texformat_rgba_fxt1);
+ ASSERT(dstFormat == MESA_FORMAT_RGBA_FXT1);
ASSERT(dstXoffset % 8 == 0);
ASSERT(dstYoffset % 4 == 0);
ASSERT(dstZoffset == 0);
@@ -144,7 +144,7 @@ texstore_rgba_fxt1(TEXSTORE_PARAMS)
/* convert image to RGBA/GLchan */
tempImage = _mesa_make_temp_chan_image(ctx, dims,
baseInternalFormat,
- dstFormat->BaseFormat,
+ _mesa_get_format_base_format(dstFormat),
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
srcPacking);
@@ -162,7 +162,7 @@ texstore_rgba_fxt1(TEXSTORE_PARAMS)
}
dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
- dstFormat->MesaFormat,
+ dstFormat,
texWidth, (GLubyte *) dstAddr);
fxt1_encode(srcWidth, srcHeight, 4, pixels, srcRowStride,
@@ -175,18 +175,18 @@ texstore_rgba_fxt1(TEXSTORE_PARAMS)
}
-static void
-fetch_texel_2d_rgba_fxt1( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLchan *texel )
+void
+_mesa_fetch_texel_2d_rgba_fxt1( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLchan *texel )
{
(void) k;
fxt1_decode_1(texImage->Data, texImage->RowStride, i, j, texel);
}
-static void
-fetch_texel_2d_f_rgba_fxt1( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
+void
+_mesa_fetch_texel_2d_f_rgba_fxt1( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
{
/* just sample as GLchan and convert to float here */
GLchan rgba[4];
@@ -199,9 +199,9 @@ fetch_texel_2d_f_rgba_fxt1( const struct gl_texture_image *texImage,
}
-static void
-fetch_texel_2d_rgb_fxt1( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLchan *texel )
+void
+_mesa_fetch_texel_2d_rgb_fxt1( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLchan *texel )
{
(void) k;
fxt1_decode_1(texImage->Data, texImage->RowStride, i, j, texel);
@@ -209,9 +209,9 @@ fetch_texel_2d_rgb_fxt1( const struct gl_texture_image *texImage,
}
-static void
-fetch_texel_2d_f_rgb_fxt1( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
+void
+_mesa_fetch_texel_2d_f_rgb_fxt1( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
{
/* just sample as GLchan and convert to float here */
GLchan rgba[4];
@@ -225,55 +225,6 @@ fetch_texel_2d_f_rgb_fxt1( const struct gl_texture_image *texImage,
-const struct gl_texture_format _mesa_texformat_rgb_fxt1 = {
- MESA_FORMAT_RGB_FXT1, /* MesaFormat */
- GL_RGB, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 4, /*approx*/ /* RedBits */
- 4, /*approx*/ /* GreenBits */
- 4, /*approx*/ /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 0, /* TexelBytes */
- texstore_rgb_fxt1, /* StoreTexImageFunc */
- NULL, /*impossible*/ /* FetchTexel1D */
- fetch_texel_2d_rgb_fxt1, /* FetchTexel2D */
- NULL, /*impossible*/ /* FetchTexel3D */
- NULL, /*impossible*/ /* FetchTexel1Df */
- fetch_texel_2d_f_rgb_fxt1, /* FetchTexel2Df */
- NULL, /*impossible*/ /* FetchTexel3Df */
- NULL /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_rgba_fxt1 = {
- MESA_FORMAT_RGBA_FXT1, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 4, /*approx*/ /* RedBits */
- 4, /*approx*/ /* GreenBits */
- 4, /*approx*/ /* BlueBits */
- 1, /*approx*/ /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 0, /* TexelBytes */
- texstore_rgba_fxt1, /* StoreTexImageFunc */
- NULL, /*impossible*/ /* FetchTexel1D */
- fetch_texel_2d_rgba_fxt1, /* FetchTexel2D */
- NULL, /*impossible*/ /* FetchTexel3D */
- NULL, /*impossible*/ /* FetchTexel1Df */
- fetch_texel_2d_f_rgba_fxt1, /* FetchTexel2Df */
- NULL, /*impossible*/ /* FetchTexel3Df */
- NULL /* StoreTexel */
-};
-
-
/***************************************************************************\
* FXT1 encoder
*
diff --git a/src/mesa/main/texcompress_fxt1.h b/src/mesa/main/texcompress_fxt1.h
new file mode 100644
index 00000000000..b74f955fcd6
--- /dev/null
+++ b/src/mesa/main/texcompress_fxt1.h
@@ -0,0 +1,53 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.1
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef TEXCOMPRESS_FXT1_H
+#define TEXCOMPRESS_FXT1_H
+
+#include "texstore.h"
+
+extern GLboolean
+_mesa_texstore_rgb_fxt1(TEXSTORE_PARAMS);
+
+extern GLboolean
+_mesa_texstore_rgba_fxt1(TEXSTORE_PARAMS);
+
+extern void
+_mesa_fetch_texel_2d_rgba_fxt1(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLchan *texel);
+
+extern void
+_mesa_fetch_texel_2d_f_rgba_fxt1(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel);
+
+extern void
+_mesa_fetch_texel_2d_rgb_fxt1(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLchan *texel);
+
+extern void
+_mesa_fetch_texel_2d_f_rgb_fxt1(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel);
+
+
+#endif /* TEXCOMPRESS_FXT1_H */
diff --git a/src/mesa/main/texcompress_s3tc.c b/src/mesa/main/texcompress_s3tc.c
index a1c0f18f36f..9fc73fec511 100644
--- a/src/mesa/main/texcompress_s3tc.c
+++ b/src/mesa/main/texcompress_s3tc.c
@@ -41,7 +41,7 @@
#include "dlopen.h"
#include "image.h"
#include "texcompress.h"
-#include "texformat.h"
+#include "texcompress_s3tc.h"
#include "texstore.h"
#ifdef __MINGW32__
@@ -153,10 +153,10 @@ _mesa_init_texture_s3tc( GLcontext *ctx )
}
/**
- * Called via TexFormat->StoreImage to store an RGB_DXT1 texture.
+ * Store user's image in rgb_dxt1 format.
*/
-static GLboolean
-texstore_rgb_dxt1(TEXSTORE_PARAMS)
+GLboolean
+_mesa_texstore_rgb_dxt1(TEXSTORE_PARAMS)
{
const GLchan *pixels;
GLint srcRowStride;
@@ -164,7 +164,7 @@ texstore_rgb_dxt1(TEXSTORE_PARAMS)
const GLint texWidth = dstRowStride * 4 / 8; /* a bit of a hack */
const GLchan *tempImage = NULL;
- ASSERT(dstFormat == &_mesa_texformat_rgb_dxt1);
+ ASSERT(dstFormat == MESA_FORMAT_RGB_DXT1);
ASSERT(dstXoffset % 4 == 0);
ASSERT(dstYoffset % 4 == 0);
ASSERT(dstZoffset % 4 == 0);
@@ -178,7 +178,7 @@ texstore_rgb_dxt1(TEXSTORE_PARAMS)
/* convert image to RGB/GLchan */
tempImage = _mesa_make_temp_chan_image(ctx, dims,
baseInternalFormat,
- dstFormat->BaseFormat,
+ _mesa_get_format_base_format(dstFormat),
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
srcPacking);
@@ -196,7 +196,7 @@ texstore_rgb_dxt1(TEXSTORE_PARAMS)
}
dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
- dstFormat->MesaFormat,
+ dstFormat,
texWidth, (GLubyte *) dstAddr);
if (ext_tx_compress_dxtn) {
@@ -216,10 +216,10 @@ texstore_rgb_dxt1(TEXSTORE_PARAMS)
/**
- * Called via TexFormat->StoreImage to store an RGBA_DXT1 texture.
+ * Store user's image in rgba_dxt1 format.
*/
-static GLboolean
-texstore_rgba_dxt1(TEXSTORE_PARAMS)
+GLboolean
+_mesa_texstore_rgba_dxt1(TEXSTORE_PARAMS)
{
const GLchan *pixels;
GLint srcRowStride;
@@ -227,7 +227,7 @@ texstore_rgba_dxt1(TEXSTORE_PARAMS)
const GLint texWidth = dstRowStride * 4 / 8; /* a bit of a hack */
const GLchan *tempImage = NULL;
- ASSERT(dstFormat == &_mesa_texformat_rgba_dxt1);
+ ASSERT(dstFormat == MESA_FORMAT_RGBA_DXT1);
ASSERT(dstXoffset % 4 == 0);
ASSERT(dstYoffset % 4 == 0);
ASSERT(dstZoffset % 4 == 0);
@@ -241,7 +241,7 @@ texstore_rgba_dxt1(TEXSTORE_PARAMS)
/* convert image to RGBA/GLchan */
tempImage = _mesa_make_temp_chan_image(ctx, dims,
baseInternalFormat,
- dstFormat->BaseFormat,
+ _mesa_get_format_base_format(dstFormat),
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
srcPacking);
@@ -259,7 +259,7 @@ texstore_rgba_dxt1(TEXSTORE_PARAMS)
}
dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
- dstFormat->MesaFormat,
+ dstFormat,
texWidth, (GLubyte *) dstAddr);
if (ext_tx_compress_dxtn) {
(*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels,
@@ -278,10 +278,10 @@ texstore_rgba_dxt1(TEXSTORE_PARAMS)
/**
- * Called via TexFormat->StoreImage to store an RGBA_DXT3 texture.
+ * Store user's image in rgba_dxt3 format.
*/
-static GLboolean
-texstore_rgba_dxt3(TEXSTORE_PARAMS)
+GLboolean
+_mesa_texstore_rgba_dxt3(TEXSTORE_PARAMS)
{
const GLchan *pixels;
GLint srcRowStride;
@@ -289,7 +289,7 @@ texstore_rgba_dxt3(TEXSTORE_PARAMS)
const GLint texWidth = dstRowStride * 4 / 16; /* a bit of a hack */
const GLchan *tempImage = NULL;
- ASSERT(dstFormat == &_mesa_texformat_rgba_dxt3);
+ ASSERT(dstFormat == MESA_FORMAT_RGBA_DXT3);
ASSERT(dstXoffset % 4 == 0);
ASSERT(dstYoffset % 4 == 0);
ASSERT(dstZoffset % 4 == 0);
@@ -303,7 +303,7 @@ texstore_rgba_dxt3(TEXSTORE_PARAMS)
/* convert image to RGBA/GLchan */
tempImage = _mesa_make_temp_chan_image(ctx, dims,
baseInternalFormat,
- dstFormat->BaseFormat,
+ _mesa_get_format_base_format(dstFormat),
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
srcPacking);
@@ -320,7 +320,7 @@ texstore_rgba_dxt3(TEXSTORE_PARAMS)
}
dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
- dstFormat->MesaFormat,
+ dstFormat,
texWidth, (GLubyte *) dstAddr);
if (ext_tx_compress_dxtn) {
(*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels,
@@ -339,10 +339,10 @@ texstore_rgba_dxt3(TEXSTORE_PARAMS)
/**
- * Called via TexFormat->StoreImage to store an RGBA_DXT5 texture.
+ * Store user's image in rgba_dxt5 format.
*/
-static GLboolean
-texstore_rgba_dxt5(TEXSTORE_PARAMS)
+GLboolean
+_mesa_texstore_rgba_dxt5(TEXSTORE_PARAMS)
{
const GLchan *pixels;
GLint srcRowStride;
@@ -350,7 +350,7 @@ texstore_rgba_dxt5(TEXSTORE_PARAMS)
const GLint texWidth = dstRowStride * 4 / 16; /* a bit of a hack */
const GLchan *tempImage = NULL;
- ASSERT(dstFormat == &_mesa_texformat_rgba_dxt5);
+ ASSERT(dstFormat == MESA_FORMAT_RGBA_DXT5);
ASSERT(dstXoffset % 4 == 0);
ASSERT(dstYoffset % 4 == 0);
ASSERT(dstZoffset % 4 == 0);
@@ -364,7 +364,7 @@ texstore_rgba_dxt5(TEXSTORE_PARAMS)
/* convert image to RGBA/GLchan */
tempImage = _mesa_make_temp_chan_image(ctx, dims,
baseInternalFormat,
- dstFormat->BaseFormat,
+ _mesa_get_format_base_format(dstFormat),
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
srcPacking);
@@ -381,7 +381,7 @@ texstore_rgba_dxt5(TEXSTORE_PARAMS)
}
dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
- dstFormat->MesaFormat,
+ dstFormat,
texWidth, (GLubyte *) dstAddr);
if (ext_tx_compress_dxtn) {
(*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels,
@@ -414,9 +414,9 @@ fetch_texel_2d_rgb_dxt1( const struct gl_texture_image *texImage,
}
-static void
-fetch_texel_2d_f_rgb_dxt1( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
+void
+_mesa_fetch_texel_2d_f_rgb_dxt1(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel)
{
/* just sample as GLchan and convert to float here */
GLchan rgba[4];
@@ -442,9 +442,9 @@ fetch_texel_2d_rgba_dxt1( const struct gl_texture_image *texImage,
}
-static void
-fetch_texel_2d_f_rgba_dxt1( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
+void
+_mesa_fetch_texel_2d_f_rgba_dxt1(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel)
{
/* just sample as GLchan and convert to float here */
GLchan rgba[4];
@@ -471,9 +471,9 @@ fetch_texel_2d_rgba_dxt3( const struct gl_texture_image *texImage,
}
-static void
-fetch_texel_2d_f_rgba_dxt3( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
+void
+_mesa_fetch_texel_2d_f_rgba_dxt3(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel)
{
/* just sample as GLchan and convert to float here */
GLchan rgba[4];
@@ -499,9 +499,9 @@ fetch_texel_2d_rgba_dxt5( const struct gl_texture_image *texImage,
}
-static void
-fetch_texel_2d_f_rgba_dxt5( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
+void
+_mesa_fetch_texel_2d_f_rgba_dxt5(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel)
{
/* just sample as GLchan and convert to float here */
GLchan rgba[4];
@@ -513,9 +513,9 @@ fetch_texel_2d_f_rgba_dxt5( const struct gl_texture_image *texImage,
}
#if FEATURE_EXT_texture_sRGB
-static void
-fetch_texel_2d_f_srgb_dxt1( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
+void
+_mesa_fetch_texel_2d_f_srgb_dxt1( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
{
/* just sample as GLchan and convert to float here */
GLchan rgba[4];
@@ -526,9 +526,9 @@ fetch_texel_2d_f_srgb_dxt1( const struct gl_texture_image *texImage,
texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
}
-static void
-fetch_texel_2d_f_srgba_dxt1( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
+void
+_mesa_fetch_texel_2d_f_srgba_dxt1(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel)
{
/* just sample as GLchan and convert to float here */
GLchan rgba[4];
@@ -539,9 +539,9 @@ fetch_texel_2d_f_srgba_dxt1( const struct gl_texture_image *texImage,
texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
}
-static void
-fetch_texel_2d_f_srgba_dxt3( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
+void
+_mesa_fetch_texel_2d_f_srgba_dxt3(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel)
{
/* just sample as GLchan and convert to float here */
GLchan rgba[4];
@@ -552,9 +552,9 @@ fetch_texel_2d_f_srgba_dxt3( const struct gl_texture_image *texImage,
texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
}
-static void
-fetch_texel_2d_f_srgba_dxt5( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
+void
+_mesa_fetch_texel_2d_f_srgba_dxt5(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel)
{
/* just sample as GLchan and convert to float here */
GLchan rgba[4];
@@ -566,196 +566,3 @@ fetch_texel_2d_f_srgba_dxt5( const struct gl_texture_image *texImage,
}
#endif
-const struct gl_texture_format _mesa_texformat_rgb_dxt1 = {
- MESA_FORMAT_RGB_DXT1, /* MesaFormat */
- GL_RGB, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 4, /*approx*/ /* RedBits */
- 4, /*approx*/ /* GreenBits */
- 4, /*approx*/ /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 0, /* TexelBytes */
- texstore_rgb_dxt1, /* StoreTexImageFunc */
- NULL, /*impossible*/ /* FetchTexel1D */
- fetch_texel_2d_rgb_dxt1, /* FetchTexel2D */
- NULL, /*impossible*/ /* FetchTexel3D */
- NULL, /*impossible*/ /* FetchTexel1Df */
- fetch_texel_2d_f_rgb_dxt1, /* FetchTexel2Df */
- NULL, /*impossible*/ /* FetchTexel3Df */
- NULL /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_rgba_dxt1 = {
- MESA_FORMAT_RGBA_DXT1, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 4, /*approx*/ /* RedBits */
- 4, /*approx*/ /* GreenBits */
- 4, /*approx*/ /* BlueBits */
- 1, /*approx*/ /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 0, /* TexelBytes */
- texstore_rgba_dxt1, /* StoreTexImageFunc */
- NULL, /*impossible*/ /* FetchTexel1D */
- fetch_texel_2d_rgba_dxt1, /* FetchTexel2D */
- NULL, /*impossible*/ /* FetchTexel3D */
- NULL, /*impossible*/ /* FetchTexel1Df */
- fetch_texel_2d_f_rgba_dxt1, /* FetchTexel2Df */
- NULL, /*impossible*/ /* FetchTexel3Df */
- NULL /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_rgba_dxt3 = {
- MESA_FORMAT_RGBA_DXT3, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 4, /*approx*/ /* RedBits */
- 4, /*approx*/ /* GreenBits */
- 4, /*approx*/ /* BlueBits */
- 4, /*approx*/ /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 0, /* TexelBytes */
- texstore_rgba_dxt3, /* StoreTexImageFunc */
- NULL, /*impossible*/ /* FetchTexel1D */
- fetch_texel_2d_rgba_dxt3, /* FetchTexel2D */
- NULL, /*impossible*/ /* FetchTexel3D */
- NULL, /*impossible*/ /* FetchTexel1Df */
- fetch_texel_2d_f_rgba_dxt3, /* FetchTexel2Df */
- NULL, /*impossible*/ /* FetchTexel3Df */
- NULL /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_rgba_dxt5 = {
- MESA_FORMAT_RGBA_DXT5, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 4,/*approx*/ /* RedBits */
- 4,/*approx*/ /* GreenBits */
- 4,/*approx*/ /* BlueBits */
- 4,/*approx*/ /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 0, /* TexelBytes */
- texstore_rgba_dxt5, /* StoreTexImageFunc */
- NULL, /*impossible*/ /* FetchTexel1D */
- fetch_texel_2d_rgba_dxt5, /* FetchTexel2D */
- NULL, /*impossible*/ /* FetchTexel3D */
- NULL, /*impossible*/ /* FetchTexel1Df */
- fetch_texel_2d_f_rgba_dxt5, /* FetchTexel2Df */
- NULL, /*impossible*/ /* FetchTexel3Df */
- NULL /* StoreTexel */
-};
-
-#if FEATURE_EXT_texture_sRGB
-const struct gl_texture_format _mesa_texformat_srgb_dxt1 = {
- MESA_FORMAT_SRGB_DXT1, /* MesaFormat */
- GL_RGB, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 4, /*approx*/ /* RedBits */
- 4, /*approx*/ /* GreenBits */
- 4, /*approx*/ /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 0, /* TexelBytes */
- texstore_rgb_dxt1, /* StoreTexImageFunc */
- NULL, /*impossible*/ /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /*impossible*/ /* FetchTexel3D */
- NULL, /*impossible*/ /* FetchTexel1Df */
- fetch_texel_2d_f_srgb_dxt1, /* FetchTexel2Df */
- NULL, /*impossible*/ /* FetchTexel3Df */
- NULL /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_srgba_dxt1 = {
- MESA_FORMAT_SRGBA_DXT1, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 4, /*approx*/ /* RedBits */
- 4, /*approx*/ /* GreenBits */
- 4, /*approx*/ /* BlueBits */
- 1, /*approx*/ /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 0, /* TexelBytes */
- texstore_rgba_dxt1, /* StoreTexImageFunc */
- NULL, /*impossible*/ /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /*impossible*/ /* FetchTexel3D */
- NULL, /*impossible*/ /* FetchTexel1Df */
- fetch_texel_2d_f_srgba_dxt1, /* FetchTexel2Df */
- NULL, /*impossible*/ /* FetchTexel3Df */
- NULL /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_srgba_dxt3 = {
- MESA_FORMAT_SRGBA_DXT3, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 4, /*approx*/ /* RedBits */
- 4, /*approx*/ /* GreenBits */
- 4, /*approx*/ /* BlueBits */
- 4, /*approx*/ /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 0, /* TexelBytes */
- texstore_rgba_dxt3, /* StoreTexImageFunc */
- NULL, /*impossible*/ /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /*impossible*/ /* FetchTexel3D */
- NULL, /*impossible*/ /* FetchTexel1Df */
- fetch_texel_2d_f_srgba_dxt3, /* FetchTexel2Df */
- NULL, /*impossible*/ /* FetchTexel3Df */
- NULL /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_srgba_dxt5 = {
- MESA_FORMAT_SRGBA_DXT5, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 4,/*approx*/ /* RedBits */
- 4,/*approx*/ /* GreenBits */
- 4,/*approx*/ /* BlueBits */
- 4,/*approx*/ /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 0, /* TexelBytes */
- texstore_rgba_dxt5, /* StoreTexImageFunc */
- NULL, /*impossible*/ /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /*impossible*/ /* FetchTexel3D */
- NULL, /*impossible*/ /* FetchTexel1Df */
- fetch_texel_2d_f_srgba_dxt5, /* FetchTexel2Df */
- NULL, /*impossible*/ /* FetchTexel3Df */
- NULL /* StoreTexel */
-};
-#endif
diff --git a/src/mesa/main/texcompress_s3tc.h b/src/mesa/main/texcompress_s3tc.h
new file mode 100644
index 00000000000..4041d244d16
--- /dev/null
+++ b/src/mesa/main/texcompress_s3tc.h
@@ -0,0 +1,75 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.1
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef TEXCOMPRESS_S3TC_H
+#define TEXCOMPRESS_S3TC_H
+
+#include "texstore.h"
+
+extern GLboolean
+_mesa_texstore_rgb_dxt1(TEXSTORE_PARAMS);
+
+extern GLboolean
+_mesa_texstore_rgba_dxt1(TEXSTORE_PARAMS);
+
+extern GLboolean
+_mesa_texstore_rgba_dxt3(TEXSTORE_PARAMS);
+
+extern GLboolean
+_mesa_texstore_rgba_dxt5(TEXSTORE_PARAMS);
+
+extern void
+_mesa_fetch_texel_2d_f_rgb_dxt1(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel);
+
+extern void
+_mesa_fetch_texel_2d_f_rgba_dxt1(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel);
+
+extern void
+_mesa_fetch_texel_2d_f_rgba_dxt3(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel);
+
+extern void
+_mesa_fetch_texel_2d_f_rgba_dxt5(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel);
+
+extern void
+_mesa_fetch_texel_2d_f_srgb_dxt1(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel);
+
+extern void
+_mesa_fetch_texel_2d_f_srgba_dxt1(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel);
+
+extern void
+_mesa_fetch_texel_2d_f_srgba_dxt3(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel);
+
+extern void
+_mesa_fetch_texel_2d_f_srgba_dxt5(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel);
+
+
+#endif /* TEXCOMPRESS_S3TC_H */
diff --git a/src/mesa/main/texfetch.c b/src/mesa/main/texfetch.c
new file mode 100644
index 00000000000..e6e28aef196
--- /dev/null
+++ b/src/mesa/main/texfetch.c
@@ -0,0 +1,665 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.7
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (c) 2009 VMware, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/**
+ * \file texfetch.c
+ *
+ * Texel fetch/store functions
+ *
+ * \author Gareth Hughes
+ */
+
+
+#include "colormac.h"
+#include "context.h"
+#include "texcompress.h"
+#include "texcompress_fxt1.h"
+#include "texcompress_s3tc.h"
+#include "texfetch.h"
+
+
+/**
+ * Convert an 8-bit sRGB value from non-linear space to a
+ * linear RGB value in [0, 1].
+ * Implemented with a 256-entry lookup table.
+ */
+static INLINE GLfloat
+nonlinear_to_linear(GLubyte cs8)
+{
+ static GLfloat table[256];
+ static GLboolean tableReady = GL_FALSE;
+ if (!tableReady) {
+ /* compute lookup table now */
+ GLuint i;
+ for (i = 0; i < 256; i++) {
+ const GLfloat cs = UBYTE_TO_FLOAT(i);
+ if (cs <= 0.04045) {
+ table[i] = cs / 12.92f;
+ }
+ else {
+ table[i] = (GLfloat) _mesa_pow((cs + 0.055) / 1.055, 2.4);
+ }
+ }
+ tableReady = GL_TRUE;
+ }
+ return table[cs8];
+}
+
+
+
+/* Texel fetch routines for all supported formats
+ */
+#define DIM 1
+#include "texfetch_tmp.h"
+
+#define DIM 2
+#include "texfetch_tmp.h"
+
+#define DIM 3
+#include "texfetch_tmp.h"
+
+/**
+ * Null texel fetch function.
+ *
+ * Have to have this so the FetchTexel function pointer is never NULL.
+ */
+static void fetch_null_texelf( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ (void) texImage; (void) i; (void) j; (void) k;
+ texel[RCOMP] = 0.0;
+ texel[GCOMP] = 0.0;
+ texel[BCOMP] = 0.0;
+ texel[ACOMP] = 0.0;
+ _mesa_warning(NULL, "fetch_null_texelf() called!");
+}
+
+static void store_null_texel(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ (void) texImage;
+ (void) i;
+ (void) j;
+ (void) k;
+ (void) texel;
+ /* no-op */
+}
+
+
+
+/**
+ * Table to map MESA_FORMAT_ to texel fetch/store funcs.
+ * XXX this is somewhat temporary.
+ */
+static struct {
+ GLuint Name;
+ FetchTexelFuncF Fetch1D;
+ FetchTexelFuncF Fetch2D;
+ FetchTexelFuncF Fetch3D;
+ StoreTexelFunc StoreTexel;
+}
+texfetch_funcs[MESA_FORMAT_COUNT] =
+{
+ {
+ MESA_FORMAT_SRGB8,
+ fetch_texel_1d_srgb8,
+ fetch_texel_2d_srgb8,
+ fetch_texel_3d_srgb8,
+ store_texel_srgb8
+ },
+ {
+ MESA_FORMAT_SRGBA8,
+ fetch_texel_1d_srgba8,
+ fetch_texel_2d_srgba8,
+ fetch_texel_3d_srgba8,
+ store_texel_srgba8
+ },
+ {
+ MESA_FORMAT_SARGB8,
+ fetch_texel_1d_sargb8,
+ fetch_texel_2d_sargb8,
+ fetch_texel_3d_sargb8,
+ store_texel_sargb8
+ },
+ {
+ MESA_FORMAT_SL8,
+ fetch_texel_1d_sl8,
+ fetch_texel_2d_sl8,
+ fetch_texel_3d_sl8,
+ store_texel_sl8
+ },
+ {
+ MESA_FORMAT_SLA8,
+ fetch_texel_1d_sla8,
+ fetch_texel_2d_sla8,
+ fetch_texel_3d_sla8,
+ store_texel_sla8
+ },
+ {
+ MESA_FORMAT_RGB_FXT1,
+ NULL,
+ _mesa_fetch_texel_2d_f_rgb_fxt1,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_RGBA_FXT1,
+ NULL,
+ _mesa_fetch_texel_2d_f_rgba_fxt1,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_RGB_DXT1,
+ NULL,
+ _mesa_fetch_texel_2d_f_rgb_dxt1,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_RGBA_DXT1,
+ NULL,
+ _mesa_fetch_texel_2d_f_rgba_dxt1,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_RGBA_DXT3,
+ NULL,
+ _mesa_fetch_texel_2d_f_rgba_dxt3,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_RGBA_DXT5,
+ NULL,
+ _mesa_fetch_texel_2d_f_rgba_dxt5,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_SRGB_DXT1,
+ NULL,
+ _mesa_fetch_texel_2d_f_srgb_dxt1,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_SRGBA_DXT1,
+ NULL,
+ _mesa_fetch_texel_2d_f_srgba_dxt1,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_SRGBA_DXT3,
+ NULL,
+ _mesa_fetch_texel_2d_f_srgba_dxt3,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_SRGBA_DXT5,
+ NULL,
+ _mesa_fetch_texel_2d_f_srgba_dxt5,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_RGBA_FLOAT32,
+ fetch_texel_1d_f_rgba_f32,
+ fetch_texel_2d_f_rgba_f32,
+ fetch_texel_3d_f_rgba_f32,
+ store_texel_rgba_f32
+ },
+ {
+ MESA_FORMAT_RGBA_FLOAT16,
+ fetch_texel_1d_f_rgba_f16,
+ fetch_texel_2d_f_rgba_f16,
+ fetch_texel_3d_f_rgba_f16,
+ store_texel_rgba_f16
+ },
+ {
+ MESA_FORMAT_RGB_FLOAT32,
+ fetch_texel_1d_f_rgb_f32,
+ fetch_texel_2d_f_rgb_f32,
+ fetch_texel_3d_f_rgb_f32,
+ store_texel_rgb_f32
+ },
+ {
+ MESA_FORMAT_RGB_FLOAT16,
+ fetch_texel_1d_f_rgb_f16,
+ fetch_texel_2d_f_rgb_f16,
+ fetch_texel_3d_f_rgb_f16,
+ store_texel_rgb_f16
+ },
+ {
+ MESA_FORMAT_ALPHA_FLOAT32,
+ fetch_texel_1d_f_alpha_f32,
+ fetch_texel_2d_f_alpha_f32,
+ fetch_texel_3d_f_alpha_f32,
+ store_texel_alpha_f32
+ },
+ {
+ MESA_FORMAT_ALPHA_FLOAT16,
+ fetch_texel_1d_f_alpha_f16,
+ fetch_texel_2d_f_alpha_f16,
+ fetch_texel_3d_f_alpha_f16,
+ store_texel_alpha_f16
+ },
+ {
+ MESA_FORMAT_LUMINANCE_FLOAT32,
+ fetch_texel_1d_f_luminance_f32,
+ fetch_texel_2d_f_luminance_f32,
+ fetch_texel_3d_f_luminance_f32,
+ store_texel_luminance_f32
+ },
+ {
+ MESA_FORMAT_LUMINANCE_FLOAT16,
+ fetch_texel_1d_f_luminance_f16,
+ fetch_texel_2d_f_luminance_f16,
+ fetch_texel_3d_f_luminance_f16,
+ store_texel_luminance_f16
+ },
+ {
+ MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
+ fetch_texel_1d_f_luminance_alpha_f32,
+ fetch_texel_2d_f_luminance_alpha_f32,
+ fetch_texel_3d_f_luminance_alpha_f32,
+ store_texel_luminance_alpha_f32
+ },
+ {
+ MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,
+ fetch_texel_1d_f_luminance_alpha_f16,
+ fetch_texel_2d_f_luminance_alpha_f16,
+ fetch_texel_3d_f_luminance_alpha_f16,
+ store_texel_luminance_alpha_f16
+ },
+ {
+ MESA_FORMAT_INTENSITY_FLOAT32,
+ fetch_texel_1d_f_intensity_f32,
+ fetch_texel_2d_f_intensity_f32,
+ fetch_texel_3d_f_intensity_f32,
+ store_texel_intensity_f32
+ },
+ {
+ MESA_FORMAT_INTENSITY_FLOAT16,
+ fetch_texel_1d_f_intensity_f16,
+ fetch_texel_2d_f_intensity_f16,
+ fetch_texel_3d_f_intensity_f16,
+ store_texel_intensity_f16
+ },
+ {
+ MESA_FORMAT_DUDV8,
+ fetch_texel_1d_dudv8,
+ fetch_texel_2d_dudv8,
+ fetch_texel_3d_dudv8,
+ NULL
+ },
+ {
+ MESA_FORMAT_SIGNED_RGBA8888,
+ fetch_texel_1d_signed_rgba8888,
+ fetch_texel_2d_signed_rgba8888,
+ fetch_texel_3d_signed_rgba8888,
+ store_texel_signed_rgba8888
+ },
+ {
+ MESA_FORMAT_SIGNED_RGBA8888_REV,
+ fetch_texel_1d_signed_rgba8888_rev,
+ fetch_texel_2d_signed_rgba8888_rev,
+ fetch_texel_3d_signed_rgba8888_rev,
+ store_texel_signed_rgba8888_rev
+ },
+ {
+ MESA_FORMAT_SIGNED_RGBA_16,
+ NULL, /* XXX to do */
+ NULL,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_RGBA8888,
+ fetch_texel_1d_f_rgba8888,
+ fetch_texel_2d_f_rgba8888,
+ fetch_texel_3d_f_rgba8888,
+ store_texel_rgba8888
+ },
+ {
+ MESA_FORMAT_RGBA8888_REV,
+ fetch_texel_1d_f_rgba8888_rev,
+ fetch_texel_2d_f_rgba8888_rev,
+ fetch_texel_3d_f_rgba8888_rev,
+ store_texel_rgba8888_rev
+ },
+ {
+ MESA_FORMAT_ARGB8888,
+ fetch_texel_1d_f_argb8888,
+ fetch_texel_2d_f_argb8888,
+ fetch_texel_3d_f_argb8888,
+ store_texel_argb8888
+ },
+ {
+ MESA_FORMAT_ARGB8888_REV,
+ fetch_texel_1d_f_argb8888_rev,
+ fetch_texel_2d_f_argb8888_rev,
+ fetch_texel_3d_f_argb8888_rev,
+ store_texel_argb8888_rev
+ },
+ {
+ MESA_FORMAT_XRGB8888,
+ fetch_texel_1d_f_xrgb8888,
+ fetch_texel_2d_f_xrgb8888,
+ fetch_texel_3d_f_xrgb8888,
+ store_texel_xrgb8888
+ },
+ {
+ MESA_FORMAT_RGB888,
+ fetch_texel_1d_f_rgb888,
+ fetch_texel_2d_f_rgb888,
+ fetch_texel_3d_f_rgb888,
+ store_texel_rgb888
+ },
+ {
+ MESA_FORMAT_BGR888,
+ fetch_texel_1d_f_bgr888,
+ fetch_texel_2d_f_bgr888,
+ fetch_texel_3d_f_bgr888,
+ store_texel_bgr888
+ },
+ {
+ MESA_FORMAT_RGB565,
+ fetch_texel_1d_f_rgb565,
+ fetch_texel_2d_f_rgb565,
+ fetch_texel_3d_f_rgb565,
+ store_texel_rgb565
+ },
+ {
+ MESA_FORMAT_RGB565_REV,
+ fetch_texel_1d_f_rgb565_rev,
+ fetch_texel_2d_f_rgb565_rev,
+ fetch_texel_3d_f_rgb565_rev,
+ store_texel_rgb565_rev
+ },
+ {
+ MESA_FORMAT_ARGB4444,
+ fetch_texel_1d_f_argb4444,
+ fetch_texel_2d_f_argb4444,
+ fetch_texel_3d_f_argb4444,
+ store_texel_argb4444
+ },
+ {
+ MESA_FORMAT_ARGB4444_REV,
+ fetch_texel_1d_f_argb4444_rev,
+ fetch_texel_2d_f_argb4444_rev,
+ fetch_texel_3d_f_argb4444_rev,
+ store_texel_argb4444_rev
+ },
+ {
+ MESA_FORMAT_RGBA5551,
+ fetch_texel_1d_f_rgba5551,
+ fetch_texel_2d_f_rgba5551,
+ fetch_texel_3d_f_rgba5551,
+ store_texel_rgba5551
+ },
+ {
+ MESA_FORMAT_ARGB1555,
+ fetch_texel_1d_f_argb1555,
+ fetch_texel_2d_f_argb1555,
+ fetch_texel_3d_f_argb1555,
+ store_texel_argb1555
+ },
+ {
+ MESA_FORMAT_ARGB1555_REV,
+ fetch_texel_1d_f_argb1555_rev,
+ fetch_texel_2d_f_argb1555_rev,
+ fetch_texel_3d_f_argb1555_rev,
+ store_texel_argb1555_rev
+ },
+ {
+ MESA_FORMAT_AL88,
+ fetch_texel_1d_f_al88,
+ fetch_texel_2d_f_al88,
+ fetch_texel_3d_f_al88,
+ store_texel_al88
+ },
+ {
+ MESA_FORMAT_AL88_REV,
+ fetch_texel_1d_f_al88_rev,
+ fetch_texel_2d_f_al88_rev,
+ fetch_texel_3d_f_al88_rev,
+ store_texel_al88_rev
+ },
+ {
+ MESA_FORMAT_RGB332,
+ fetch_texel_1d_f_rgb332,
+ fetch_texel_2d_f_rgb332,
+ fetch_texel_3d_f_rgb332,
+ store_texel_rgb332
+ },
+ {
+ MESA_FORMAT_A8,
+ fetch_texel_1d_f_a8,
+ fetch_texel_2d_f_a8,
+ fetch_texel_3d_f_a8,
+ store_texel_a8
+ },
+ {
+ MESA_FORMAT_L8,
+ fetch_texel_1d_f_l8,
+ fetch_texel_2d_f_l8,
+ fetch_texel_3d_f_l8,
+ store_texel_l8
+ },
+ {
+ MESA_FORMAT_I8,
+ fetch_texel_1d_f_i8,
+ fetch_texel_2d_f_i8,
+ fetch_texel_3d_f_i8,
+ store_texel_i8
+ },
+ {
+ MESA_FORMAT_CI8,
+ fetch_texel_1d_f_ci8,
+ fetch_texel_2d_f_ci8,
+ fetch_texel_3d_f_ci8,
+ store_texel_ci8
+ },
+ {
+ MESA_FORMAT_YCBCR,
+ fetch_texel_1d_f_ycbcr,
+ fetch_texel_2d_f_ycbcr,
+ fetch_texel_3d_f_ycbcr,
+ store_texel_ycbcr
+ },
+ {
+ MESA_FORMAT_YCBCR_REV,
+ fetch_texel_1d_f_ycbcr_rev,
+ fetch_texel_2d_f_ycbcr_rev,
+ fetch_texel_3d_f_ycbcr_rev,
+ store_texel_ycbcr_rev
+ },
+ {
+ MESA_FORMAT_Z24_S8,
+ fetch_texel_1d_f_z24_s8,
+ fetch_texel_2d_f_z24_s8,
+ fetch_texel_3d_f_z24_s8,
+ store_texel_z24_s8
+ },
+ {
+ MESA_FORMAT_S8_Z24,
+ fetch_texel_1d_f_s8_z24,
+ fetch_texel_2d_f_s8_z24,
+ fetch_texel_3d_f_s8_z24,
+ store_texel_s8_z24
+ },
+ {
+ MESA_FORMAT_Z16,
+ fetch_texel_1d_f_z16,
+ fetch_texel_2d_f_z16,
+ fetch_texel_3d_f_z16,
+ store_texel_z16
+ },
+ {
+ MESA_FORMAT_X8_Z24,
+ fetch_texel_1d_f_s8_z24,
+ fetch_texel_2d_f_s8_z24,
+ fetch_texel_3d_f_s8_z24,
+ store_texel_s8_z24
+ },
+ {
+ MESA_FORMAT_Z32,
+ fetch_texel_1d_f_z32,
+ fetch_texel_2d_f_z32,
+ fetch_texel_3d_f_z32,
+ store_texel_z32
+ }
+};
+
+
+static FetchTexelFuncF
+_mesa_get_texel_fetch_func(gl_format format, GLuint dims)
+{
+ FetchTexelFuncF f;
+ GLuint i;
+ /* XXX replace loop with direct table lookup */
+ for (i = 0; i < MESA_FORMAT_COUNT; i++) {
+ if (texfetch_funcs[i].Name == format) {
+ switch (dims) {
+ case 1:
+ f = texfetch_funcs[i].Fetch1D;
+ break;
+ case 2:
+ f = texfetch_funcs[i].Fetch2D;
+ break;
+ case 3:
+ f = texfetch_funcs[i].Fetch3D;
+ break;
+ }
+ if (!f)
+ f = fetch_null_texelf;
+ return f;
+ }
+ }
+ return NULL;
+}
+
+
+StoreTexelFunc
+_mesa_get_texel_store_func(gl_format format)
+{
+ GLuint i;
+ /* XXX replace loop with direct table lookup */
+ for (i = 0; i < MESA_FORMAT_COUNT; i++) {
+ if (texfetch_funcs[i].Name == format) {
+ if (texfetch_funcs[i].StoreTexel)
+ return texfetch_funcs[i].StoreTexel;
+ else
+ return store_null_texel;
+ }
+ }
+ return NULL;
+}
+
+
+
+/**
+ * Adaptor for fetching a GLchan texel from a float-valued texture.
+ */
+static void
+fetch_texel_float_to_chan(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLchan *texelOut)
+{
+ GLfloat temp[4];
+ GLenum baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
+
+ ASSERT(texImage->FetchTexelf);
+ texImage->FetchTexelf(texImage, i, j, k, temp);
+ if (baseFormat == GL_DEPTH_COMPONENT ||
+ baseFormat == GL_DEPTH_STENCIL_EXT) {
+ /* just one channel */
+ UNCLAMPED_FLOAT_TO_CHAN(texelOut[0], temp[0]);
+ }
+ else {
+ /* four channels */
+ UNCLAMPED_FLOAT_TO_CHAN(texelOut[0], temp[0]);
+ UNCLAMPED_FLOAT_TO_CHAN(texelOut[1], temp[1]);
+ UNCLAMPED_FLOAT_TO_CHAN(texelOut[2], temp[2]);
+ UNCLAMPED_FLOAT_TO_CHAN(texelOut[3], temp[3]);
+ }
+}
+
+
+#if 0
+/**
+ * Adaptor for fetching a float texel from a GLchan-valued texture.
+ */
+static void
+fetch_texel_chan_to_float(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texelOut)
+{
+ GLchan temp[4];
+ GLenum baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
+
+ ASSERT(texImage->FetchTexelc);
+ texImage->FetchTexelc(texImage, i, j, k, temp);
+ if (baseFormat == GL_DEPTH_COMPONENT ||
+ baseFormat == GL_DEPTH_STENCIL_EXT) {
+ /* just one channel */
+ texelOut[0] = CHAN_TO_FLOAT(temp[0]);
+ }
+ else {
+ /* four channels */
+ texelOut[0] = CHAN_TO_FLOAT(temp[0]);
+ texelOut[1] = CHAN_TO_FLOAT(temp[1]);
+ texelOut[2] = CHAN_TO_FLOAT(temp[2]);
+ texelOut[3] = CHAN_TO_FLOAT(temp[3]);
+ }
+}
+#endif
+
+
+/**
+ * Initialize the texture image's FetchTexelc and FetchTexelf methods.
+ */
+void
+_mesa_set_fetch_functions(struct gl_texture_image *texImage, GLuint dims)
+{
+ ASSERT(dims == 1 || dims == 2 || dims == 3);
+ ASSERT(texImage->TexFormat);
+
+ if (!texImage->FetchTexelf) {
+ texImage->FetchTexelf =
+ _mesa_get_texel_fetch_func(texImage->TexFormat, dims);
+ }
+
+ /* now check if we need to use a float/chan adaptor */
+ if (!texImage->FetchTexelc) {
+ texImage->FetchTexelc = fetch_texel_float_to_chan;
+ }
+
+ ASSERT(texImage->FetchTexelc);
+ ASSERT(texImage->FetchTexelf);
+}
diff --git a/src/mesa/main/texfetch.h b/src/mesa/main/texfetch.h
new file mode 100644
index 00000000000..ef13bf27fec
--- /dev/null
+++ b/src/mesa/main/texfetch.h
@@ -0,0 +1,40 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.7
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (c) 2009 VMware, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#ifndef TEXFETCH_H
+#define TEXFETCH_H
+
+#include "mtypes.h"
+#include "formats.h"
+
+
+extern StoreTexelFunc
+_mesa_get_texel_store_func(gl_format format);
+
+extern void
+_mesa_set_fetch_functions(struct gl_texture_image *texImage, GLuint dims);
+
+#endif
diff --git a/src/mesa/main/texformat_tmp.h b/src/mesa/main/texfetch_tmp.h
index eb160deff93..27434946ec8 100644
--- a/src/mesa/main/texformat_tmp.h
+++ b/src/mesa/main/texfetch_tmp.h
@@ -1,9 +1,9 @@
/*
* Mesa 3-D graphics library
- * Version: 6.5.1
+ * Version: 7.7
*
- * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
- * Copyright (c) 2008 VMware, Inc.
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (c) 2008-2009 VMware, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -25,18 +25,16 @@
/**
- * \file texformat_tmp.h
+ * \file texfetch_tmp.h
* Texel fetch functions template.
*
- * This template file is used by texformat.c to generate texel fetch functions
+ * This template file is used by texfetch.c to generate texel fetch functions
* for 1-D, 2-D and 3-D texture images.
*
* It should be expanded by defining \p DIM as the number texture dimensions
* (1, 2 or 3). According to the value of \p DIM a series of macros is defined
* for the texel lookup in the gl_texture_image::Data.
*
- * \sa texformat.c and FetchTexel.
- *
* \author Gareth Hughes
* \author Brian Paul
*/
@@ -70,152 +68,6 @@
#endif
-/* MESA_FORMAT_RGBA **********************************************************/
-
-/* Fetch texel from 1D, 2D or 3D RGBA texture, returning 4 GLfloats */
-static void FETCH(f_rgba)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 4);
- texel[RCOMP] = CHAN_TO_FLOAT(src[0]);
- texel[GCOMP] = CHAN_TO_FLOAT(src[1]);
- texel[BCOMP] = CHAN_TO_FLOAT(src[2]);
- texel[ACOMP] = CHAN_TO_FLOAT(src[3]);
-}
-
-#if DIM == 3
-/* Store a GLchan RGBA texel */
-static void store_texel_rgba(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLchan *rgba = (const GLchan *) texel;
- GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 4);
- dst[0] = rgba[RCOMP];
- dst[1] = rgba[GCOMP];
- dst[2] = rgba[BCOMP];
- dst[3] = rgba[ACOMP];
-}
-#endif
-
-/* MESA_FORMAT_RGB ***********************************************************/
-
-/* Fetch texel from 1D, 2D or 3D RGB texture, returning 4 GLfloats */
-static void FETCH(f_rgb)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 3);
- texel[RCOMP] = CHAN_TO_FLOAT(src[0]);
- texel[GCOMP] = CHAN_TO_FLOAT(src[1]);
- texel[BCOMP] = CHAN_TO_FLOAT(src[2]);
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_rgb(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLchan *rgba = (const GLchan *) texel;
- GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 3);
- dst[0] = rgba[RCOMP];
- dst[1] = rgba[GCOMP];
- dst[2] = rgba[BCOMP];
-}
-#endif
-
-/* MESA_FORMAT_ALPHA *********************************************************/
-
-/* Fetch texel from 1D, 2D or 3D ALPHA texture, returning 4 GLchans */
-static void FETCH(f_alpha)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = 0.0F;
- texel[ACOMP] = CHAN_TO_FLOAT(src[0]);
-}
-
-#if DIM == 3
-static void store_texel_alpha(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLchan *rgba = (const GLchan *) texel;
- GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
- dst[0] = rgba[ACOMP];
-}
-#endif
-
-/* MESA_FORMAT_LUMINANCE *****************************************************/
-
-/* Fetch texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
-static void FETCH(f_luminance)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = CHAN_TO_FLOAT(src[0]);
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_luminance(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLchan *rgba = (const GLchan *) texel;
- GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
- dst[0] = rgba[RCOMP];
-}
-#endif
-
-/* MESA_FORMAT_LUMINANCE_ALPHA ***********************************************/
-
-/* Fetch texel from 1D, 2D or 3D L_A texture, returning 4 GLchans */
-static void FETCH(f_luminance_alpha)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel)
-{
- const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 2);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = CHAN_TO_FLOAT(src[0]);
- texel[ACOMP] = CHAN_TO_FLOAT(src[1]);
-}
-
-#if DIM == 3
-static void store_texel_luminance_alpha(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLchan *rgba = (const GLchan *) texel;
- GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 2);
- dst[0] = rgba[RCOMP];
- dst[1] = rgba[ACOMP];
-}
-#endif
-
-/* MESA_FORMAT_INTENSITY *****************************************************/
-
-/* Fetch texel from 1D, 2D or 3D INT. texture, returning 4 GLchans */
-static void FETCH(f_intensity)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] =
- texel[ACOMP] = CHAN_TO_FLOAT(src[0]);
-}
-
-#if DIM == 3
-static void store_texel_intensity(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLchan *rgba = (const GLchan *) texel;
- GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
- dst[0] = rgba[RCOMP];
-}
-#endif
-
-
/* MESA_FORMAT_Z32 ***********************************************************/
/* Fetch depth texel from 1D, 2D or 3D 32-bit depth texture,
@@ -683,6 +535,30 @@ static void store_texel_argb8888_rev(struct gl_texture_image *texImage,
#endif
+/* MESA_FORMAT_XRGB8888 ******************************************************/
+
+/* Fetch texel from 1D, 2D or 3D xrgb8888 texture, return 4 GLchans */
+static void FETCH(f_xrgb8888)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
+ texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
+ texel[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
+ texel[ACOMP] = 1.0f;
+}
+
+#if DIM == 3
+static void store_texel_xrgb8888(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_8888(0xff, rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
+}
+#endif
+
+
/* MESA_FORMAT_RGB888 ********************************************************/
/* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
@@ -787,30 +663,6 @@ static void store_texel_rgb565_rev(struct gl_texture_image *texImage,
}
#endif
-/* MESA_FORMAT_RGBA4444 ******************************************************/
-
-/* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
-static void FETCH(f_rgba4444)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- const GLushort s = *src;
- texel[RCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
- texel[GCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
- texel[BCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
- texel[ACOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
-}
-
-#if DIM == 3
-static void store_texel_rgba4444(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- *dst = PACK_COLOR_4444(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
-}
-#endif
-
/* MESA_FORMAT_ARGB4444 ******************************************************/
@@ -1161,8 +1013,6 @@ static void store_texel_ci8(struct gl_texture_image *texImage,
#endif
-#if FEATURE_EXT_texture_sRGB
-
/* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
/* Note: component order is same as for MESA_FORMAT_RGB888 */
static void FETCH(srgb8)(const struct gl_texture_image *texImage,
@@ -1272,8 +1122,6 @@ static void store_texel_sla8(struct gl_texture_image *texImage,
}
#endif
-#endif /* FEATURE_EXT_texture_sRGB */
-
/* MESA_FORMAT_DUDV8 ********************************************************/
@@ -1424,7 +1272,7 @@ static void FETCH(f_z24_s8)( const struct gl_texture_image *texImage,
const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
texel[0] = ((*src) >> 8) * scale;
- ASSERT(texImage->TexFormat->MesaFormat == MESA_FORMAT_Z24_S8);
+ ASSERT(texImage->TexFormat == MESA_FORMAT_Z24_S8);
ASSERT(texel[0] >= 0.0F);
ASSERT(texel[0] <= 1.0F);
}
@@ -1451,7 +1299,7 @@ static void FETCH(f_s8_z24)( const struct gl_texture_image *texImage,
const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
texel[0] = ((*src) & 0x00ffffff) * scale;
- ASSERT(texImage->TexFormat->MesaFormat == MESA_FORMAT_S8_Z24);
+ ASSERT(texImage->TexFormat == MESA_FORMAT_S8_Z24);
ASSERT(texel[0] >= 0.0F);
ASSERT(texel[0] <= 1.0F);
}
diff --git a/src/mesa/main/texformat.c b/src/mesa/main/texformat.c
index 9d5534e3960..39c561e2789 100644
--- a/src/mesa/main/texformat.c
+++ b/src/mesa/main/texformat.c
@@ -1,9 +1,9 @@
/*
* Mesa 3-D graphics library
- * Version: 6.5.1
+ * Version: 7.7
*
- * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
- * Copyright (c) 2008 VMware, Inc.
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (c) 2008-2009 VMware, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -29,1435 +29,15 @@
* Texture formats.
*
* \author Gareth Hughes
+ * \author Brian Paul
*/
-#include "colormac.h"
#include "context.h"
+#include "texcompress.h"
+#include "texcompress_fxt1.h"
+#include "texcompress_s3tc.h"
#include "texformat.h"
-#include "texstore.h"
-
-
-#if FEATURE_EXT_texture_sRGB
-
-/**
- * Convert an 8-bit sRGB value from non-linear space to a
- * linear RGB value in [0, 1].
- * Implemented with a 256-entry lookup table.
- */
-static INLINE GLfloat
-nonlinear_to_linear(GLubyte cs8)
-{
- static GLfloat table[256];
- static GLboolean tableReady = GL_FALSE;
- if (!tableReady) {
- /* compute lookup table now */
- GLuint i;
- for (i = 0; i < 256; i++) {
- const GLfloat cs = UBYTE_TO_FLOAT(i);
- if (cs <= 0.04045) {
- table[i] = cs / 12.92f;
- }
- else {
- table[i] = (GLfloat) _mesa_pow((cs + 0.055) / 1.055, 2.4);
- }
- }
- tableReady = GL_TRUE;
- }
- return table[cs8];
-}
-
-
-#endif /* FEATURE_EXT_texture_sRGB */
-
-
-/* Texel fetch routines for all supported formats
- */
-#define DIM 1
-#include "texformat_tmp.h"
-
-#define DIM 2
-#include "texformat_tmp.h"
-
-#define DIM 3
-#include "texformat_tmp.h"
-
-/**
- * Null texel fetch function.
- *
- * Have to have this so the FetchTexel function pointer is never NULL.
- */
-static void fetch_null_texel( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLchan *texel )
-{
- (void) texImage; (void) i; (void) j; (void) k;
- texel[RCOMP] = 0;
- texel[GCOMP] = 0;
- texel[BCOMP] = 0;
- texel[ACOMP] = 0;
- _mesa_warning(NULL, "fetch_null_texel() called!");
-}
-
-static void fetch_null_texelf( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- (void) texImage; (void) i; (void) j; (void) k;
- texel[RCOMP] = 0.0;
- texel[GCOMP] = 0.0;
- texel[BCOMP] = 0.0;
- texel[ACOMP] = 0.0;
- _mesa_warning(NULL, "fetch_null_texelf() called!");
-}
-
-static void store_null_texel(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- (void) texImage;
- (void) i;
- (void) j;
- (void) k;
- (void) texel;
- /* no-op */
-}
-
-
-/**
- * Notes about the predefined gl_texture_formats:
- *
- * 1. There are 1D, 2D and 3D functions for fetching texels from texture
- * images, returning both GLchan values and GLfloat values. (six
- * functions in total)
- * You don't have to provide both the GLchan and GLfloat functions;
- * just one or the other is OK. Mesa will use an "adaptor" to convert
- * between GLchan/GLfloat when needed.
- * Since the adaptors have small performance penalty, we provide both
- * GLchan and GLfloat functions for some common formats like RGB, RGBA.
- */
-
-
-/***************************************************************/
-/** \name Default GLchan-based formats */
-/*@{*/
-
-const struct gl_texture_format _mesa_texformat_rgba = {
- MESA_FORMAT_RGBA, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- CHAN_BITS, /* RedBits */
- CHAN_BITS, /* GreenBits */
- CHAN_BITS, /* BlueBits */
- CHAN_BITS, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 4 * sizeof(GLchan), /* TexelBytes */
- _mesa_texstore_rgba, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_rgba, /* FetchTexel1Df */
- fetch_texel_2d_f_rgba, /* FetchTexel2Df */
- fetch_texel_3d_f_rgba, /* FetchTexel3Df */
- store_texel_rgba /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_rgb = {
- MESA_FORMAT_RGB, /* MesaFormat */
- GL_RGB, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- CHAN_BITS, /* RedBits */
- CHAN_BITS, /* GreenBits */
- CHAN_BITS, /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 3 * sizeof(GLchan), /* TexelBytes */
- _mesa_texstore_rgba,/*yes*/ /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_rgb, /* FetchTexel1Df */
- fetch_texel_2d_f_rgb, /* FetchTexel2Df */
- fetch_texel_3d_f_rgb, /* FetchTexel3Df */
- store_texel_rgb /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_alpha = {
- MESA_FORMAT_ALPHA, /* MesaFormat */
- GL_ALPHA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- CHAN_BITS, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- sizeof(GLchan), /* TexelBytes */
- _mesa_texstore_rgba,/*yes*/ /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_alpha, /* FetchTexel1Df */
- fetch_texel_2d_f_alpha, /* FetchTexel2Df */
- fetch_texel_3d_f_alpha, /* FetchTexel3Df */
- store_texel_alpha /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_luminance = {
- MESA_FORMAT_LUMINANCE, /* MesaFormat */
- GL_LUMINANCE, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 0, /* AlphaBits */
- CHAN_BITS, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- sizeof(GLchan), /* TexelBytes */
- _mesa_texstore_rgba,/*yes*/ /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_luminance, /* FetchTexel1Df */
- fetch_texel_2d_f_luminance, /* FetchTexel2Df */
- fetch_texel_3d_f_luminance, /* FetchTexel3Df */
- store_texel_luminance /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_luminance_alpha = {
- MESA_FORMAT_LUMINANCE_ALPHA, /* MesaFormat */
- GL_LUMINANCE_ALPHA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- CHAN_BITS, /* AlphaBits */
- CHAN_BITS, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 2 * sizeof(GLchan), /* TexelBytes */
- _mesa_texstore_rgba,/*yes*/ /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_luminance_alpha, /* FetchTexel1Df */
- fetch_texel_2d_f_luminance_alpha, /* FetchTexel2Df */
- fetch_texel_3d_f_luminance_alpha, /* FetchTexel3Df */
- store_texel_luminance_alpha /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_intensity = {
- MESA_FORMAT_INTENSITY, /* MesaFormat */
- GL_INTENSITY, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- CHAN_BITS, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- sizeof(GLchan), /* TexelBytes */
- _mesa_texstore_rgba,/*yes*/ /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_intensity, /* FetchTexel1Df */
- fetch_texel_2d_f_intensity, /* FetchTexel2Df */
- fetch_texel_3d_f_intensity, /* FetchTexel3Df */
- store_texel_intensity /* StoreTexel */
-};
-
-
-#if FEATURE_EXT_texture_sRGB
-
-const struct gl_texture_format _mesa_texformat_srgb8 = {
- MESA_FORMAT_SRGB8, /* MesaFormat */
- GL_RGB, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 8, /* RedBits */
- 8, /* GreenBits */
- 8, /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 3, /* TexelBytes */
- _mesa_texstore_srgb8, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_srgb8, /* FetchTexel1Df */
- fetch_texel_2d_srgb8, /* FetchTexel2Df */
- fetch_texel_3d_srgb8, /* FetchTexel3Df */
- store_texel_srgb8 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_srgba8 = {
- MESA_FORMAT_SRGBA8, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 8, /* RedBits */
- 8, /* GreenBits */
- 8, /* BlueBits */
- 8, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 4, /* TexelBytes */
- _mesa_texstore_srgba8, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_srgba8, /* FetchTexel1Df */
- fetch_texel_2d_srgba8, /* FetchTexel2Df */
- fetch_texel_3d_srgba8, /* FetchTexel3Df */
- store_texel_srgba8 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_sargb8 = {
- MESA_FORMAT_SARGB8, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 8, /* RedBits */
- 8, /* GreenBits */
- 8, /* BlueBits */
- 8, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 4, /* TexelBytes */
- _mesa_texstore_sargb8, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_sargb8, /* FetchTexel1Df */
- fetch_texel_2d_sargb8, /* FetchTexel2Df */
- fetch_texel_3d_sargb8, /* FetchTexel3Df */
- store_texel_sargb8 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_sl8 = {
- MESA_FORMAT_SL8, /* MesaFormat */
- GL_LUMINANCE, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 0, /* AlphaBits */
- 8, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 1, /* TexelBytes */
- _mesa_texstore_sl8, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_sl8, /* FetchTexel1Df */
- fetch_texel_2d_sl8, /* FetchTexel2Df */
- fetch_texel_3d_sl8, /* FetchTexel3Df */
- store_texel_sl8 /* StoreTexel */
-};
-
-/* Note: this format name looks like a misnomer, make it sal8? */
-const struct gl_texture_format _mesa_texformat_sla8 = {
- MESA_FORMAT_SLA8, /* MesaFormat */
- GL_LUMINANCE_ALPHA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 8, /* AlphaBits */
- 8, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 2, /* TexelBytes */
- _mesa_texstore_sla8, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_sla8, /* FetchTexel1Df */
- fetch_texel_2d_sla8, /* FetchTexel2Df */
- fetch_texel_3d_sla8, /* FetchTexel3Df */
- store_texel_sla8 /* StoreTexel */
-};
-
-#endif /* FEATURE_EXT_texture_sRGB */
-
-const struct gl_texture_format _mesa_texformat_rgba_float32 = {
- MESA_FORMAT_RGBA_FLOAT32, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_FLOAT, /* DataType */
- 8 * sizeof(GLfloat), /* RedBits */
- 8 * sizeof(GLfloat), /* GreenBits */
- 8 * sizeof(GLfloat), /* BlueBits */
- 8 * sizeof(GLfloat), /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 4 * sizeof(GLfloat), /* TexelBytes */
- _mesa_texstore_rgba_float32, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel1D */
- fetch_texel_1d_f_rgba_f32, /* FetchTexel1Df */
- fetch_texel_2d_f_rgba_f32, /* FetchTexel2Df */
- fetch_texel_3d_f_rgba_f32, /* FetchTexel3Df */
- store_texel_rgba_f32 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_rgba_float16 = {
- MESA_FORMAT_RGBA_FLOAT16, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_FLOAT, /* DataType */
- 8 * sizeof(GLhalfARB), /* RedBits */
- 8 * sizeof(GLhalfARB), /* GreenBits */
- 8 * sizeof(GLhalfARB), /* BlueBits */
- 8 * sizeof(GLhalfARB), /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 4 * sizeof(GLhalfARB), /* TexelBytes */
- _mesa_texstore_rgba_float16, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel1D */
- fetch_texel_1d_f_rgba_f16, /* FetchTexel1Df */
- fetch_texel_2d_f_rgba_f16, /* FetchTexel2Df */
- fetch_texel_3d_f_rgba_f16, /* FetchTexel3Df */
- store_texel_rgba_f16 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_rgb_float32 = {
- MESA_FORMAT_RGB_FLOAT32, /* MesaFormat */
- GL_RGB, /* BaseFormat */
- GL_FLOAT, /* DataType */
- 8 * sizeof(GLfloat), /* RedBits */
- 8 * sizeof(GLfloat), /* GreenBits */
- 8 * sizeof(GLfloat), /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 3 * sizeof(GLfloat), /* TexelBytes */
- _mesa_texstore_rgba_float32,/*yes*/ /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel1D */
- fetch_texel_1d_f_rgb_f32, /* FetchTexel1Df */
- fetch_texel_2d_f_rgb_f32, /* FetchTexel2Df */
- fetch_texel_3d_f_rgb_f32, /* FetchTexel3Df */
- store_texel_rgb_f32 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_rgb_float16 = {
- MESA_FORMAT_RGB_FLOAT16, /* MesaFormat */
- GL_RGB, /* BaseFormat */
- GL_FLOAT, /* DataType */
- 8 * sizeof(GLhalfARB), /* RedBits */
- 8 * sizeof(GLhalfARB), /* GreenBits */
- 8 * sizeof(GLhalfARB), /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 3 * sizeof(GLhalfARB), /* TexelBytes */
- _mesa_texstore_rgba_float16,/*yes*/ /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel1D */
- fetch_texel_1d_f_rgb_f16, /* FetchTexel1Df */
- fetch_texel_2d_f_rgb_f16, /* FetchTexel2Df */
- fetch_texel_3d_f_rgb_f16, /* FetchTexel3Df */
- store_texel_rgb_f16 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_alpha_float32 = {
- MESA_FORMAT_ALPHA_FLOAT32, /* MesaFormat */
- GL_ALPHA, /* BaseFormat */
- GL_FLOAT, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 8 * sizeof(GLfloat), /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 1 * sizeof(GLfloat), /* TexelBytes */
- _mesa_texstore_rgba_float32,/*yes*/ /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel1D */
- fetch_texel_1d_f_alpha_f32, /* FetchTexel1Df */
- fetch_texel_2d_f_alpha_f32, /* FetchTexel2Df */
- fetch_texel_3d_f_alpha_f32, /* FetchTexel3Df */
- store_texel_alpha_f32 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_alpha_float16 = {
- MESA_FORMAT_ALPHA_FLOAT16, /* MesaFormat */
- GL_ALPHA, /* BaseFormat */
- GL_FLOAT, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 8 * sizeof(GLhalfARB), /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 1 * sizeof(GLhalfARB), /* TexelBytes */
- _mesa_texstore_rgba_float16,/*yes*/ /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel1D */
- fetch_texel_1d_f_alpha_f16, /* FetchTexel1Df */
- fetch_texel_2d_f_alpha_f16, /* FetchTexel2Df */
- fetch_texel_3d_f_alpha_f16, /* FetchTexel3Df */
- store_texel_alpha_f16 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_luminance_float32 = {
- MESA_FORMAT_LUMINANCE_FLOAT32, /* MesaFormat */
- GL_LUMINANCE, /* BaseFormat */
- GL_FLOAT, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 0, /* AlphaBits */
- 8 * sizeof(GLfloat), /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 1 * sizeof(GLfloat), /* TexelBytes */
- _mesa_texstore_rgba_float32,/*yes*/ /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_luminance_f32, /* FetchTexel1Df */
- fetch_texel_2d_f_luminance_f32, /* FetchTexel2Df */
- fetch_texel_3d_f_luminance_f32, /* FetchTexel3Df */
- store_texel_luminance_f32 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_luminance_float16 = {
- MESA_FORMAT_LUMINANCE_FLOAT16, /* MesaFormat */
- GL_LUMINANCE, /* BaseFormat */
- GL_FLOAT, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 0, /* AlphaBits */
- 8 * sizeof(GLhalfARB), /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 1 * sizeof(GLhalfARB), /* TexelBytes */
- _mesa_texstore_rgba_float16,/*yes*/ /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_luminance_f16, /* FetchTexel1Df */
- fetch_texel_2d_f_luminance_f16, /* FetchTexel2Df */
- fetch_texel_3d_f_luminance_f16, /* FetchTexel3Df */
- store_texel_luminance_f16 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_luminance_alpha_float32 = {
- MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32, /* MesaFormat */
- GL_LUMINANCE_ALPHA, /* BaseFormat */
- GL_FLOAT, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 8 * sizeof(GLfloat), /* AlphaBits */
- 8 * sizeof(GLfloat), /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 2 * sizeof(GLfloat), /* TexelBytes */
- _mesa_texstore_rgba_float32, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_luminance_alpha_f32,/* FetchTexel1Df */
- fetch_texel_2d_f_luminance_alpha_f32,/* FetchTexel2Df */
- fetch_texel_3d_f_luminance_alpha_f32,/* FetchTexel3Df */
- store_texel_luminance_alpha_f32 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_luminance_alpha_float16 = {
- MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16, /* MesaFormat */
- GL_LUMINANCE_ALPHA, /* BaseFormat */
- GL_FLOAT, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 8 * sizeof(GLhalfARB), /* AlphaBits */
- 8 * sizeof(GLhalfARB), /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 2 * sizeof(GLhalfARB), /* TexelBytes */
- _mesa_texstore_rgba_float16, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_luminance_alpha_f16,/* FetchTexel1Df */
- fetch_texel_2d_f_luminance_alpha_f16,/* FetchTexel2Df */
- fetch_texel_3d_f_luminance_alpha_f16,/* FetchTexel3Df */
- store_texel_luminance_alpha_f16 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_intensity_float32 = {
- MESA_FORMAT_INTENSITY_FLOAT32, /* MesaFormat */
- GL_INTENSITY, /* BaseFormat */
- GL_FLOAT, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 8 * sizeof(GLfloat), /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 1 * sizeof(GLfloat), /* TexelBytes */
- _mesa_texstore_rgba_float32,/*yes*/ /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_intensity_f32, /* FetchTexel1Df */
- fetch_texel_2d_f_intensity_f32, /* FetchTexel2Df */
- fetch_texel_3d_f_intensity_f32, /* FetchTexel3Df */
- store_texel_intensity_f32 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_intensity_float16 = {
- MESA_FORMAT_INTENSITY_FLOAT16, /* MesaFormat */
- GL_INTENSITY, /* BaseFormat */
- GL_FLOAT, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 8 * sizeof(GLhalfARB), /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 1 * sizeof(GLhalfARB), /* TexelBytes */
- _mesa_texstore_rgba_float16,/*yes*/ /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_intensity_f16, /* FetchTexel1Df */
- fetch_texel_2d_f_intensity_f16, /* FetchTexel2Df */
- fetch_texel_3d_f_intensity_f16, /* FetchTexel3Df */
- store_texel_intensity_f16 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_dudv8 = {
- MESA_FORMAT_DUDV8, /* MesaFormat */
- GL_DUDV_ATI, /* BaseFormat */
- GL_SIGNED_NORMALIZED, /* DataType */
- /* maybe should add dudvBits field, but spec seems to be
- lacking the ability to query with GetTexLevelParameter anyway */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 2, /* TexelBytes */
- _mesa_texstore_dudv8, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_dudv8, /* FetchTexel1Df */
- fetch_texel_2d_dudv8, /* FetchTexel2Df */
- fetch_texel_3d_dudv8, /* FetchTexel3Df */
- NULL /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_signed_rgba8888 = {
- MESA_FORMAT_SIGNED_RGBA8888, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_SIGNED_NORMALIZED, /* DataType */
- 8, /* RedBits */
- 8, /* GreenBits */
- 8, /* BlueBits */
- 8, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 4, /* TexelBytes */
- _mesa_texstore_signed_rgba8888, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_signed_rgba8888, /* FetchTexel1Df */
- fetch_texel_2d_signed_rgba8888, /* FetchTexel2Df */
- fetch_texel_3d_signed_rgba8888, /* FetchTexel3Df */
- store_texel_signed_rgba8888 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_signed_rgba8888_rev = {
- MESA_FORMAT_SIGNED_RGBA8888_REV, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_SIGNED_NORMALIZED, /* DataType */
- 8, /* RedBits */
- 8, /* GreenBits */
- 8, /* BlueBits */
- 8, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 4, /* TexelBytes */
- _mesa_texstore_signed_rgba8888, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_signed_rgba8888_rev, /* FetchTexel1Df */
- fetch_texel_2d_signed_rgba8888_rev, /* FetchTexel2Df */
- fetch_texel_3d_signed_rgba8888_rev, /* FetchTexel3Df */
- store_texel_signed_rgba8888_rev /* StoreTexel */
-};
-
-/*@}*/
-
-
-/***************************************************************/
-/** \name Hardware formats */
-/*@{*/
-
-const struct gl_texture_format _mesa_texformat_rgba8888 = {
- MESA_FORMAT_RGBA8888, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 8, /* RedBits */
- 8, /* GreenBits */
- 8, /* BlueBits */
- 8, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 4, /* TexelBytes */
- _mesa_texstore_rgba8888, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_rgba8888, /* FetchTexel1Df */
- fetch_texel_2d_f_rgba8888, /* FetchTexel2Df */
- fetch_texel_3d_f_rgba8888, /* FetchTexel3Df */
- store_texel_rgba8888 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_rgba8888_rev = {
- MESA_FORMAT_RGBA8888_REV, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 8, /* RedBits */
- 8, /* GreenBits */
- 8, /* BlueBits */
- 8, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 4, /* TexelBytes */
- _mesa_texstore_rgba8888, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_rgba8888_rev, /* FetchTexel1Df */
- fetch_texel_2d_f_rgba8888_rev, /* FetchTexel2Df */
- fetch_texel_3d_f_rgba8888_rev, /* FetchTexel3Df */
- store_texel_rgba8888_rev /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_argb8888 = {
- MESA_FORMAT_ARGB8888, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 8, /* RedBits */
- 8, /* GreenBits */
- 8, /* BlueBits */
- 8, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 4, /* TexelBytes */
- _mesa_texstore_argb8888, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_argb8888, /* FetchTexel1Df */
- fetch_texel_2d_f_argb8888, /* FetchTexel2Df */
- fetch_texel_3d_f_argb8888, /* FetchTexel3Df */
- store_texel_argb8888 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_argb8888_rev = {
- MESA_FORMAT_ARGB8888_REV, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 8, /* RedBits */
- 8, /* GreenBits */
- 8, /* BlueBits */
- 8, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 4, /* TexelBytes */
- _mesa_texstore_argb8888, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_argb8888_rev, /* FetchTexel1Df */
- fetch_texel_2d_f_argb8888_rev, /* FetchTexel2Df */
- fetch_texel_3d_f_argb8888_rev, /* FetchTexel3Df */
- store_texel_argb8888_rev /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_rgb888 = {
- MESA_FORMAT_RGB888, /* MesaFormat */
- GL_RGB, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 8, /* RedBits */
- 8, /* GreenBits */
- 8, /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 3, /* TexelBytes */
- _mesa_texstore_rgb888, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_rgb888, /* FetchTexel1Df */
- fetch_texel_2d_f_rgb888, /* FetchTexel2Df */
- fetch_texel_3d_f_rgb888, /* FetchTexel3Df */
- store_texel_rgb888 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_bgr888 = {
- MESA_FORMAT_BGR888, /* MesaFormat */
- GL_RGB, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 8, /* RedBits */
- 8, /* GreenBits */
- 8, /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 3, /* TexelBytes */
- _mesa_texstore_bgr888, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_bgr888, /* FetchTexel1Df */
- fetch_texel_2d_f_bgr888, /* FetchTexel2Df */
- fetch_texel_3d_f_bgr888, /* FetchTexel3Df */
- store_texel_bgr888 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_rgb565 = {
- MESA_FORMAT_RGB565, /* MesaFormat */
- GL_RGB, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 5, /* RedBits */
- 6, /* GreenBits */
- 5, /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 2, /* TexelBytes */
- _mesa_texstore_rgb565, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_rgb565, /* FetchTexel1Df */
- fetch_texel_2d_f_rgb565, /* FetchTexel2Df */
- fetch_texel_3d_f_rgb565, /* FetchTexel3Df */
- store_texel_rgb565 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_rgb565_rev = {
- MESA_FORMAT_RGB565_REV, /* MesaFormat */
- GL_RGB, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 5, /* RedBits */
- 6, /* GreenBits */
- 5, /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 2, /* TexelBytes */
- _mesa_texstore_rgb565, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_rgb565_rev, /* FetchTexel1Df */
- fetch_texel_2d_f_rgb565_rev, /* FetchTexel2Df */
- fetch_texel_3d_f_rgb565_rev, /* FetchTexel3Df */
- store_texel_rgb565_rev /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_rgba4444 = {
- MESA_FORMAT_RGBA4444, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 4, /* RedBits */
- 4, /* GreenBits */
- 4, /* BlueBits */
- 4, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 2, /* TexelBytes */
- _mesa_texstore_rgba4444, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_rgba4444, /* FetchTexel1Df */
- fetch_texel_2d_f_rgba4444, /* FetchTexel2Df */
- fetch_texel_3d_f_rgba4444, /* FetchTexel3Df */
- store_texel_rgba4444 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_argb4444 = {
- MESA_FORMAT_ARGB4444, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 4, /* RedBits */
- 4, /* GreenBits */
- 4, /* BlueBits */
- 4, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 2, /* TexelBytes */
- _mesa_texstore_argb4444, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_argb4444, /* FetchTexel1Df */
- fetch_texel_2d_f_argb4444, /* FetchTexel2Df */
- fetch_texel_3d_f_argb4444, /* FetchTexel3Df */
- store_texel_argb4444 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_argb4444_rev = {
- MESA_FORMAT_ARGB4444_REV, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 4, /* RedBits */
- 4, /* GreenBits */
- 4, /* BlueBits */
- 4, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 2, /* TexelBytes */
- _mesa_texstore_argb4444, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_argb4444_rev, /* FetchTexel1Df */
- fetch_texel_2d_f_argb4444_rev, /* FetchTexel2Df */
- fetch_texel_3d_f_argb4444_rev, /* FetchTexel3Df */
- store_texel_argb4444_rev /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_rgba5551 = {
- MESA_FORMAT_RGBA5551, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 5, /* RedBits */
- 5, /* GreenBits */
- 5, /* BlueBits */
- 1, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 2, /* TexelBytes */
- _mesa_texstore_rgba5551, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_rgba5551, /* FetchTexel1Df */
- fetch_texel_2d_f_rgba5551, /* FetchTexel2Df */
- fetch_texel_3d_f_rgba5551, /* FetchTexel3Df */
- store_texel_rgba5551 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_argb1555 = {
- MESA_FORMAT_ARGB1555, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 5, /* RedBits */
- 5, /* GreenBits */
- 5, /* BlueBits */
- 1, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 2, /* TexelBytes */
- _mesa_texstore_argb1555, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_argb1555, /* FetchTexel1Df */
- fetch_texel_2d_f_argb1555, /* FetchTexel2Df */
- fetch_texel_3d_f_argb1555, /* FetchTexel3Df */
- store_texel_argb1555 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_argb1555_rev = {
- MESA_FORMAT_ARGB1555_REV, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 5, /* RedBits */
- 5, /* GreenBits */
- 5, /* BlueBits */
- 1, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 2, /* TexelBytes */
- _mesa_texstore_argb1555, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_argb1555_rev, /* FetchTexel1Df */
- fetch_texel_2d_f_argb1555_rev, /* FetchTexel2Df */
- fetch_texel_3d_f_argb1555_rev, /* FetchTexel3Df */
- store_texel_argb1555_rev /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_al88 = {
- MESA_FORMAT_AL88, /* MesaFormat */
- GL_LUMINANCE_ALPHA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 8, /* AlphaBits */
- 8, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 2, /* TexelBytes */
- _mesa_texstore_al88, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_al88, /* FetchTexel1Df */
- fetch_texel_2d_f_al88, /* FetchTexel2Df */
- fetch_texel_3d_f_al88, /* FetchTexel3Df */
- store_texel_al88 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_al88_rev = {
- MESA_FORMAT_AL88_REV, /* MesaFormat */
- GL_LUMINANCE_ALPHA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 8, /* AlphaBits */
- 8, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 2, /* TexelBytes */
- _mesa_texstore_al88, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_al88_rev, /* FetchTexel1Df */
- fetch_texel_2d_f_al88_rev, /* FetchTexel2Df */
- fetch_texel_3d_f_al88_rev, /* FetchTexel3Df */
- store_texel_al88_rev /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_rgb332 = {
- MESA_FORMAT_RGB332, /* MesaFormat */
- GL_RGB, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 3, /* RedBits */
- 3, /* GreenBits */
- 2, /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 1, /* TexelBytes */
- _mesa_texstore_rgb332, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_rgb332, /* FetchTexel1Df */
- fetch_texel_2d_f_rgb332, /* FetchTexel2Df */
- fetch_texel_3d_f_rgb332, /* FetchTexel3Df */
- store_texel_rgb332 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_a8 = {
- MESA_FORMAT_A8, /* MesaFormat */
- GL_ALPHA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 8, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 1, /* TexelBytes */
- _mesa_texstore_a8, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_a8, /* FetchTexel1Df */
- fetch_texel_2d_f_a8, /* FetchTexel2Df */
- fetch_texel_3d_f_a8, /* FetchTexel3Df */
- store_texel_a8 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_l8 = {
- MESA_FORMAT_L8, /* MesaFormat */
- GL_LUMINANCE, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 0, /* AlphaBits */
- 8, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 1, /* TexelBytes */
- _mesa_texstore_a8,/*yes*/ /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_l8, /* FetchTexel1Df */
- fetch_texel_2d_f_l8, /* FetchTexel2Df */
- fetch_texel_3d_f_l8, /* FetchTexel3Df */
- store_texel_l8 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_i8 = {
- MESA_FORMAT_I8, /* MesaFormat */
- GL_INTENSITY, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 8, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 1, /* TexelBytes */
- _mesa_texstore_a8,/*yes*/ /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_i8, /* FetchTexel1Df */
- fetch_texel_2d_f_i8, /* FetchTexel2Df */
- fetch_texel_3d_f_i8, /* FetchTexel3Df */
- store_texel_i8 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_ci8 = {
- MESA_FORMAT_CI8, /* MesaFormat */
- GL_COLOR_INDEX, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 8, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 1, /* TexelBytes */
- _mesa_texstore_ci8, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_ci8, /* FetchTexel1Df */
- fetch_texel_2d_f_ci8, /* FetchTexel2Df */
- fetch_texel_3d_f_ci8, /* FetchTexel3Df */
- store_texel_ci8 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_ycbcr = {
- MESA_FORMAT_YCBCR, /* MesaFormat */
- GL_YCBCR_MESA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 2, /* TexelBytes */
- _mesa_texstore_ycbcr, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_ycbcr, /* FetchTexel1Df */
- fetch_texel_2d_f_ycbcr, /* FetchTexel2Df */
- fetch_texel_3d_f_ycbcr, /* FetchTexel3Df */
- store_texel_ycbcr /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_ycbcr_rev = {
- MESA_FORMAT_YCBCR_REV, /* MesaFormat */
- GL_YCBCR_MESA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 2, /* TexelBytes */
- _mesa_texstore_ycbcr, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_ycbcr_rev, /* FetchTexel1Df */
- fetch_texel_2d_f_ycbcr_rev, /* FetchTexel2Df */
- fetch_texel_3d_f_ycbcr_rev, /* FetchTexel3Df */
- store_texel_ycbcr_rev /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_z24_s8 = {
- MESA_FORMAT_Z24_S8, /* MesaFormat */
- GL_DEPTH_STENCIL_EXT, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 24, /* DepthBits */
- 8, /* StencilBits */
- 4, /* TexelBytes */
- _mesa_texstore_z24_s8, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_z24_s8, /* FetchTexel1Df */
- fetch_texel_2d_f_z24_s8, /* FetchTexel2Df */
- fetch_texel_3d_f_z24_s8, /* FetchTexel3Df */
- store_texel_z24_s8 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_s8_z24 = {
- MESA_FORMAT_S8_Z24, /* MesaFormat */
- GL_DEPTH_STENCIL_EXT, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 24, /* DepthBits */
- 8, /* StencilBits */
- 4, /* TexelBytes */
- _mesa_texstore_s8_z24, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel2D */
- NULL, /* FetchTexel3D */
- fetch_texel_1d_f_s8_z24, /* FetchTexel1Df */
- fetch_texel_2d_f_s8_z24, /* FetchTexel2Df */
- fetch_texel_3d_f_s8_z24, /* FetchTexel3Df */
- store_texel_s8_z24 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_z16 = {
- MESA_FORMAT_Z16, /* MesaFormat */
- GL_DEPTH_COMPONENT, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- sizeof(GLushort) * 8, /* DepthBits */
- 0, /* StencilBits */
- sizeof(GLushort), /* TexelBytes */
- _mesa_texstore_z16, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel1D */
- fetch_texel_1d_f_z16, /* FetchTexel1Df */
- fetch_texel_2d_f_z16, /* FetchTexel2Df */
- fetch_texel_3d_f_z16, /* FetchTexel3Df */
- store_texel_z16 /* StoreTexel */
-};
-
-const struct gl_texture_format _mesa_texformat_z32 = {
- MESA_FORMAT_Z32, /* MesaFormat */
- GL_DEPTH_COMPONENT, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- sizeof(GLuint) * 8, /* DepthBits */
- 0, /* StencilBits */
- sizeof(GLuint), /* TexelBytes */
- _mesa_texstore_z32, /* StoreTexImageFunc */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel1D */
- NULL, /* FetchTexel1D */
- fetch_texel_1d_f_z32, /* FetchTexel1Df */
- fetch_texel_2d_f_z32, /* FetchTexel2Df */
- fetch_texel_3d_f_z32, /* FetchTexel3Df */
- store_texel_z32 /* StoreTexel */
-};
-
-/*@}*/
-
-
-/***************************************************************/
-/** \name Null format (useful for proxy textures) */
-/*@{*/
-
-const struct gl_texture_format _mesa_null_texformat = {
- -1, /* MesaFormat */
- 0, /* BaseFormat */
- GL_NONE, /* DataType */
- 0, /* RedBits */
- 0, /* GreenBits */
- 0, /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* StencilBits */
- 0, /* TexelBytes */
- NULL, /* StoreTexImageFunc */
- fetch_null_texel, /* FetchTexel1D */
- fetch_null_texel, /* FetchTexel2D */
- fetch_null_texel, /* FetchTexel3D */
- fetch_null_texelf, /* FetchTexel1Df */
- fetch_null_texelf, /* FetchTexel2Df */
- fetch_null_texelf, /* FetchTexel3Df */
- store_null_texel /* StoreTexel */
-};
-
-/*@}*/
/**
@@ -1475,7 +55,7 @@ const struct gl_texture_format _mesa_null_texformat = {
* This is called via dd_function_table::ChooseTextureFormat. Hardware drivers
* will typically override this function with a specialized version.
*/
-const struct gl_texture_format *
+gl_format
_mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
GLenum format, GLenum type )
{
@@ -1489,15 +69,14 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
case GL_RGB10_A2:
case GL_RGBA12:
case GL_RGBA16:
- return &_mesa_texformat_rgba;
case GL_RGBA8:
- return &_mesa_texformat_rgba8888;
+ return MESA_FORMAT_RGBA8888;
case GL_RGB5_A1:
- return &_mesa_texformat_argb1555;
+ return MESA_FORMAT_ARGB1555;
case GL_RGBA2:
- return &_mesa_texformat_argb4444_rev; /* just to test another format*/
+ return MESA_FORMAT_ARGB4444_REV; /* just to test another format*/
case GL_RGBA4:
- return &_mesa_texformat_argb4444;
+ return MESA_FORMAT_ARGB4444;
/* RGB formats */
case 3:
@@ -1505,24 +84,22 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
case GL_RGB10:
case GL_RGB12:
case GL_RGB16:
- return &_mesa_texformat_rgb;
case GL_RGB8:
- return &_mesa_texformat_rgb888;
+ return MESA_FORMAT_RGB888;
case GL_R3_G3_B2:
- return &_mesa_texformat_rgb332;
+ return MESA_FORMAT_RGB332;
case GL_RGB4:
- return &_mesa_texformat_rgb565_rev; /* just to test another format */
+ return MESA_FORMAT_RGB565_REV; /* just to test another format */
case GL_RGB5:
- return &_mesa_texformat_rgb565;
+ return MESA_FORMAT_RGB565;
/* Alpha formats */
case GL_ALPHA:
case GL_ALPHA4:
case GL_ALPHA12:
case GL_ALPHA16:
- return &_mesa_texformat_alpha;
case GL_ALPHA8:
- return &_mesa_texformat_a8;
+ return MESA_FORMAT_A8;
/* Luminance formats */
case 1:
@@ -1530,9 +107,8 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
case GL_LUMINANCE4:
case GL_LUMINANCE12:
case GL_LUMINANCE16:
- return &_mesa_texformat_luminance;
case GL_LUMINANCE8:
- return &_mesa_texformat_l8;
+ return MESA_FORMAT_L8;
/* Luminance/Alpha formats */
case 2:
@@ -1542,17 +118,15 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
case GL_LUMINANCE12_ALPHA4:
case GL_LUMINANCE12_ALPHA12:
case GL_LUMINANCE16_ALPHA16:
- return &_mesa_texformat_luminance_alpha;
case GL_LUMINANCE8_ALPHA8:
- return &_mesa_texformat_al88;
+ return MESA_FORMAT_AL88;
case GL_INTENSITY:
case GL_INTENSITY4:
case GL_INTENSITY12:
case GL_INTENSITY16:
- return &_mesa_texformat_intensity;
case GL_INTENSITY8:
- return &_mesa_texformat_i8;
+ return MESA_FORMAT_I8;
case GL_COLOR_INDEX:
case GL_COLOR_INDEX1_EXT:
@@ -1561,7 +135,7 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
case GL_COLOR_INDEX12_EXT:
case GL_COLOR_INDEX16_EXT:
case GL_COLOR_INDEX8_EXT:
- return &_mesa_texformat_ci8;
+ return MESA_FORMAT_CI8;
default:
; /* fallthrough */
@@ -1572,9 +146,9 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
case GL_DEPTH_COMPONENT:
case GL_DEPTH_COMPONENT24:
case GL_DEPTH_COMPONENT32:
- return &_mesa_texformat_z32;
+ return MESA_FORMAT_Z32;
case GL_DEPTH_COMPONENT16:
- return &_mesa_texformat_z16;
+ return MESA_FORMAT_Z16;
default:
; /* fallthrough */
}
@@ -1582,35 +156,27 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
switch (internalFormat) {
case GL_COMPRESSED_ALPHA_ARB:
- return &_mesa_texformat_alpha;
+ return MESA_FORMAT_A8;
case GL_COMPRESSED_LUMINANCE_ARB:
- return &_mesa_texformat_luminance;
+ return MESA_FORMAT_L8;
case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
- return &_mesa_texformat_luminance_alpha;
+ return MESA_FORMAT_AL88;
case GL_COMPRESSED_INTENSITY_ARB:
- return &_mesa_texformat_intensity;
+ return MESA_FORMAT_I8;
case GL_COMPRESSED_RGB_ARB:
-#if FEATURE_texture_s3tc
if (ctx->Extensions.EXT_texture_compression_s3tc ||
ctx->Extensions.S3_s3tc)
- return &_mesa_texformat_rgb_dxt1;
-#endif
-#if FEATURE_texture_fxt1
+ return MESA_FORMAT_RGB_DXT1;
if (ctx->Extensions.TDFX_texture_compression_FXT1)
- return &_mesa_texformat_rgb_fxt1;
-#endif
- return &_mesa_texformat_rgb;
+ return MESA_FORMAT_RGB_FXT1;
+ return MESA_FORMAT_RGB888;
case GL_COMPRESSED_RGBA_ARB:
-#if FEATURE_texture_s3tc
if (ctx->Extensions.EXT_texture_compression_s3tc ||
ctx->Extensions.S3_s3tc)
- return &_mesa_texformat_rgba_dxt5; /* Not rgba_dxt1, see spec */
-#endif
-#if FEATURE_texture_fxt1
+ return MESA_FORMAT_RGBA_DXT3; /* Not rgba_dxt1, see spec */
if (ctx->Extensions.TDFX_texture_compression_FXT1)
- return &_mesa_texformat_rgba_fxt1;
-#endif
- return &_mesa_texformat_rgba;
+ return MESA_FORMAT_RGBA_FXT1;
+ return MESA_FORMAT_RGBA8888;
default:
; /* fallthrough */
}
@@ -1618,9 +184,9 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
if (ctx->Extensions.MESA_ycbcr_texture) {
if (internalFormat == GL_YCBCR_MESA) {
if (type == GL_UNSIGNED_SHORT_8_8_MESA)
- return &_mesa_texformat_ycbcr;
+ return MESA_FORMAT_YCBCR;
else
- return &_mesa_texformat_ycbcr_rev;
+ return MESA_FORMAT_YCBCR_REV;
}
}
@@ -1628,9 +194,9 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
if (ctx->Extensions.TDFX_texture_compression_FXT1) {
switch (internalFormat) {
case GL_COMPRESSED_RGB_FXT1_3DFX:
- return &_mesa_texformat_rgb_fxt1;
+ return MESA_FORMAT_RGB_FXT1;
case GL_COMPRESSED_RGBA_FXT1_3DFX:
- return &_mesa_texformat_rgba_fxt1;
+ return MESA_FORMAT_RGBA_FXT1;
default:
; /* fallthrough */
}
@@ -1641,13 +207,13 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
if (ctx->Extensions.EXT_texture_compression_s3tc) {
switch (internalFormat) {
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
- return &_mesa_texformat_rgb_dxt1;
+ return MESA_FORMAT_RGB_DXT1;
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
- return &_mesa_texformat_rgba_dxt1;
+ return MESA_FORMAT_RGBA_DXT1;
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
- return &_mesa_texformat_rgba_dxt3;
+ return MESA_FORMAT_RGBA_DXT3;
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
- return &_mesa_texformat_rgba_dxt5;
+ return MESA_FORMAT_RGBA_DXT5;
default:
; /* fallthrough */
}
@@ -1657,10 +223,10 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
switch (internalFormat) {
case GL_RGB_S3TC:
case GL_RGB4_S3TC:
- return &_mesa_texformat_rgb_dxt1;
+ return MESA_FORMAT_RGB_DXT1;
case GL_RGBA_S3TC:
case GL_RGBA4_S3TC:
- return &_mesa_texformat_rgba_dxt3;
+ return MESA_FORMAT_RGBA_DXT3;
default:
; /* fallthrough */
}
@@ -1670,29 +236,29 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
if (ctx->Extensions.ARB_texture_float) {
switch (internalFormat) {
case GL_ALPHA16F_ARB:
- return &_mesa_texformat_alpha_float16;
+ return MESA_FORMAT_ALPHA_FLOAT16;
case GL_ALPHA32F_ARB:
- return &_mesa_texformat_alpha_float32;
+ return MESA_FORMAT_ALPHA_FLOAT32;
case GL_LUMINANCE16F_ARB:
- return &_mesa_texformat_luminance_float16;
+ return MESA_FORMAT_LUMINANCE_FLOAT16;
case GL_LUMINANCE32F_ARB:
- return &_mesa_texformat_luminance_float32;
+ return MESA_FORMAT_LUMINANCE_FLOAT32;
case GL_LUMINANCE_ALPHA16F_ARB:
- return &_mesa_texformat_luminance_alpha_float16;
+ return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16;
case GL_LUMINANCE_ALPHA32F_ARB:
- return &_mesa_texformat_luminance_alpha_float32;
+ return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32;
case GL_INTENSITY16F_ARB:
- return &_mesa_texformat_intensity_float16;
+ return MESA_FORMAT_INTENSITY_FLOAT16;
case GL_INTENSITY32F_ARB:
- return &_mesa_texformat_intensity_float32;
+ return MESA_FORMAT_INTENSITY_FLOAT32;
case GL_RGB16F_ARB:
- return &_mesa_texformat_rgb_float16;
+ return MESA_FORMAT_RGB_FLOAT16;
case GL_RGB32F_ARB:
- return &_mesa_texformat_rgb_float32;
+ return MESA_FORMAT_RGB_FLOAT32;
case GL_RGBA16F_ARB:
- return &_mesa_texformat_rgba_float16;
+ return MESA_FORMAT_RGBA_FLOAT16;
case GL_RGBA32F_ARB:
- return &_mesa_texformat_rgba_float32;
+ return MESA_FORMAT_RGBA_FLOAT32;
default:
; /* fallthrough */
}
@@ -1702,7 +268,7 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
switch (internalFormat) {
case GL_DEPTH_STENCIL_EXT:
case GL_DEPTH24_STENCIL8_EXT:
- return &_mesa_texformat_z24_s8;
+ return MESA_FORMAT_Z24_S8;
default:
; /* fallthrough */
}
@@ -1712,7 +278,7 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
switch (internalFormat) {
case GL_DUDV_ATI:
case GL_DU8DV8_ATI:
- return &_mesa_texformat_dudv8;
+ return MESA_FORMAT_DUDV8;
default:
; /* fallthrough */
}
@@ -1722,7 +288,7 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
switch (internalFormat) {
case GL_RGBA_SNORM:
case GL_RGBA8_SNORM:
- return &_mesa_texformat_signed_rgba8888;
+ return MESA_FORMAT_SIGNED_RGBA8888;
default:
; /* fallthrough */
}
@@ -1734,48 +300,48 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
switch (internalFormat) {
case GL_SRGB_EXT:
case GL_SRGB8_EXT:
- return &_mesa_texformat_srgb8;
+ return MESA_FORMAT_SRGB8;
case GL_SRGB_ALPHA_EXT:
case GL_SRGB8_ALPHA8_EXT:
- return &_mesa_texformat_srgba8;
+ return MESA_FORMAT_SRGBA8;
case GL_SLUMINANCE_EXT:
case GL_SLUMINANCE8_EXT:
- return &_mesa_texformat_sl8;
+ return MESA_FORMAT_SL8;
case GL_SLUMINANCE_ALPHA_EXT:
case GL_SLUMINANCE8_ALPHA8_EXT:
- return &_mesa_texformat_sla8;
+ return MESA_FORMAT_SLA8;
case GL_COMPRESSED_SLUMINANCE_EXT:
- return &_mesa_texformat_sl8;
+ return MESA_FORMAT_SL8;
case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
- return &_mesa_texformat_sla8;
+ return MESA_FORMAT_SLA8;
case GL_COMPRESSED_SRGB_EXT:
#if FEATURE_texture_s3tc
if (ctx->Extensions.EXT_texture_compression_s3tc)
- return &_mesa_texformat_srgb_dxt1;
+ return MESA_FORMAT_SRGB_DXT1;
#endif
- return &_mesa_texformat_srgb8;
+ return MESA_FORMAT_SRGB8;
case GL_COMPRESSED_SRGB_ALPHA_EXT:
#if FEATURE_texture_s3tc
if (ctx->Extensions.EXT_texture_compression_s3tc)
- return &_mesa_texformat_srgba_dxt3; /* Not srgba_dxt1, see spec */
+ return MESA_FORMAT_SRGBA_DXT3; /* Not srgba_dxt1, see spec */
#endif
- return &_mesa_texformat_srgba8;
+ return MESA_FORMAT_SRGBA8;
#if FEATURE_texture_s3tc
case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
if (ctx->Extensions.EXT_texture_compression_s3tc)
- return &_mesa_texformat_srgb_dxt1;
+ return MESA_FORMAT_SRGB_DXT1;
break;
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
if (ctx->Extensions.EXT_texture_compression_s3tc)
- return &_mesa_texformat_srgba_dxt1;
+ return MESA_FORMAT_SRGBA_DXT1;
break;
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
if (ctx->Extensions.EXT_texture_compression_s3tc)
- return &_mesa_texformat_srgba_dxt3;
+ return MESA_FORMAT_SRGBA_DXT3;
break;
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
if (ctx->Extensions.EXT_texture_compression_s3tc)
- return &_mesa_texformat_srgba_dxt5;
+ return MESA_FORMAT_SRGBA_DXT5;
break;
#endif
default:
@@ -1785,205 +351,6 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
#endif /* FEATURE_EXT_texture_sRGB */
_mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
- return NULL;
+ return MESA_FORMAT_NONE;
}
-
-
-/**
- * Return datatype and number of components per texel for the
- * given gl_texture_format.
- */
-void
-_mesa_format_to_type_and_comps(const struct gl_texture_format *format,
- GLenum *datatype, GLuint *comps)
-{
- switch (format->MesaFormat) {
- case MESA_FORMAT_RGBA8888:
- case MESA_FORMAT_RGBA8888_REV:
- case MESA_FORMAT_ARGB8888:
- case MESA_FORMAT_ARGB8888_REV:
- *datatype = CHAN_TYPE;
- *comps = 4;
- return;
- case MESA_FORMAT_RGB888:
- case MESA_FORMAT_BGR888:
- *datatype = GL_UNSIGNED_BYTE;
- *comps = 3;
- return;
- case MESA_FORMAT_RGB565:
- case MESA_FORMAT_RGB565_REV:
- *datatype = GL_UNSIGNED_SHORT_5_6_5;
- *comps = 3;
- return;
-
- case MESA_FORMAT_ARGB4444:
- case MESA_FORMAT_ARGB4444_REV:
- *datatype = GL_UNSIGNED_SHORT_4_4_4_4;
- *comps = 4;
- return;
-
- case MESA_FORMAT_ARGB1555:
- case MESA_FORMAT_ARGB1555_REV:
- *datatype = GL_UNSIGNED_SHORT_1_5_5_5_REV;
- *comps = 4;
- return;
-
- case MESA_FORMAT_AL88:
- case MESA_FORMAT_AL88_REV:
- *datatype = GL_UNSIGNED_BYTE;
- *comps = 2;
- return;
- case MESA_FORMAT_RGB332:
- *datatype = GL_UNSIGNED_BYTE_3_3_2;
- *comps = 3;
- return;
-
- case MESA_FORMAT_A8:
- case MESA_FORMAT_L8:
- case MESA_FORMAT_I8:
- case MESA_FORMAT_CI8:
- *datatype = GL_UNSIGNED_BYTE;
- *comps = 1;
- return;
-
- case MESA_FORMAT_YCBCR:
- case MESA_FORMAT_YCBCR_REV:
- *datatype = GL_UNSIGNED_SHORT;
- *comps = 2;
- return;
-
- case MESA_FORMAT_Z24_S8:
- *datatype = GL_UNSIGNED_INT;
- *comps = 1; /* XXX OK? */
- return;
-
- case MESA_FORMAT_S8_Z24:
- *datatype = GL_UNSIGNED_INT;
- *comps = 1; /* XXX OK? */
- return;
-
- case MESA_FORMAT_Z16:
- *datatype = GL_UNSIGNED_SHORT;
- *comps = 1;
- return;
-
- case MESA_FORMAT_Z32:
- *datatype = GL_UNSIGNED_INT;
- *comps = 1;
- return;
-
- case MESA_FORMAT_DUDV8:
- *datatype = GL_BYTE;
- *comps = 2;
- return;
-
- case MESA_FORMAT_SIGNED_RGBA8888:
- case MESA_FORMAT_SIGNED_RGBA8888_REV:
- *datatype = GL_BYTE;
- *comps = 4;
- return;
-
-#if FEATURE_EXT_texture_sRGB
- case MESA_FORMAT_SRGB8:
- *datatype = GL_UNSIGNED_BYTE;
- *comps = 3;
- return;
- case MESA_FORMAT_SRGBA8:
- case MESA_FORMAT_SARGB8:
- *datatype = GL_UNSIGNED_BYTE;
- *comps = 4;
- return;
- case MESA_FORMAT_SL8:
- *datatype = GL_UNSIGNED_BYTE;
- *comps = 1;
- return;
- case MESA_FORMAT_SLA8:
- *datatype = GL_UNSIGNED_BYTE;
- *comps = 2;
- return;
-#endif
-
-#if FEATURE_texture_fxt1
- case MESA_FORMAT_RGB_FXT1:
- case MESA_FORMAT_RGBA_FXT1:
-#endif
-#if FEATURE_texture_s3tc
- case MESA_FORMAT_RGB_DXT1:
- case MESA_FORMAT_RGBA_DXT1:
- case MESA_FORMAT_RGBA_DXT3:
- case MESA_FORMAT_RGBA_DXT5:
-#if FEATURE_EXT_texture_sRGB
- case MESA_FORMAT_SRGB_DXT1:
- case MESA_FORMAT_SRGBA_DXT1:
- case MESA_FORMAT_SRGBA_DXT3:
- case MESA_FORMAT_SRGBA_DXT5:
-#endif
- /* XXX generate error instead? */
- *datatype = GL_UNSIGNED_BYTE;
- *comps = 0;
- return;
-#endif
-
- case MESA_FORMAT_RGBA:
- *datatype = CHAN_TYPE;
- *comps = 4;
- return;
- case MESA_FORMAT_RGB:
- *datatype = CHAN_TYPE;
- *comps = 3;
- return;
- case MESA_FORMAT_LUMINANCE_ALPHA:
- *datatype = CHAN_TYPE;
- *comps = 2;
- return;
- case MESA_FORMAT_ALPHA:
- case MESA_FORMAT_LUMINANCE:
- case MESA_FORMAT_INTENSITY:
- *datatype = CHAN_TYPE;
- *comps = 1;
- return;
-
- case MESA_FORMAT_RGBA_FLOAT32:
- *datatype = GL_FLOAT;
- *comps = 4;
- return;
- case MESA_FORMAT_RGBA_FLOAT16:
- *datatype = GL_HALF_FLOAT_ARB;
- *comps = 4;
- return;
- case MESA_FORMAT_RGB_FLOAT32:
- *datatype = GL_FLOAT;
- *comps = 3;
- return;
- case MESA_FORMAT_RGB_FLOAT16:
- *datatype = GL_HALF_FLOAT_ARB;
- *comps = 3;
- return;
- case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32:
- *datatype = GL_FLOAT;
- *comps = 2;
- return;
- case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:
- *datatype = GL_HALF_FLOAT_ARB;
- *comps = 2;
- return;
- case MESA_FORMAT_ALPHA_FLOAT32:
- case MESA_FORMAT_LUMINANCE_FLOAT32:
- case MESA_FORMAT_INTENSITY_FLOAT32:
- *datatype = GL_FLOAT;
- *comps = 1;
- return;
- case MESA_FORMAT_ALPHA_FLOAT16:
- case MESA_FORMAT_LUMINANCE_FLOAT16:
- case MESA_FORMAT_INTENSITY_FLOAT16:
- *datatype = GL_HALF_FLOAT_ARB;
- *comps = 1;
- return;
-
- default:
- _mesa_problem(NULL, "bad format in _mesa_format_to_type_and_comps");
- *datatype = 0;
- *comps = 1;
- }
-}
diff --git a/src/mesa/main/texformat.h b/src/mesa/main/texformat.h
index 5aa1d756cbc..bda5fd6d8ce 100644
--- a/src/mesa/main/texformat.h
+++ b/src/mesa/main/texformat.h
@@ -1,9 +1,9 @@
/*
* Mesa 3-D graphics library
- * Version: 6.5.1
+ * Version: 7.75
*
- * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
- * Copyright (c) 2008 VMware, Inc.
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (c) 2008-2009 VMware, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -23,271 +23,17 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-
-/**
- * \file texformat.h
- * Texture formats definitions.
- *
- * \author Gareth Hughes
- */
-
-
#ifndef TEXFORMAT_H
#define TEXFORMAT_H
#include "mtypes.h"
+#include "formats.h"
-/**
- * Mesa internal texture image formats.
- * All texture images are stored in one of these formats.
- *
- * NOTE: when you add a new format, be sure to update the do_row()
- * function in texstore.c used for auto mipmap generation.
- */
-enum _format {
- /**
- * \name Hardware-friendly formats.
- *
- * Drivers can override the default formats and convert texture images to
- * one of these as required. The driver's
- * dd_function_table::ChooseTextureFormat function will choose one of these
- * formats.
- *
- * \note In the default case, some of these formats will be duplicates of
- * the generic formats listed below. However, these formats guarantee their
- * internal component sizes, while GLchan may vary between GLubyte, GLushort
- * and GLfloat.
- */
- /*@{*/
- /* msb <------ TEXEL BITS -----------> lsb */
- /* ---- ---- ---- ---- ---- ---- ---- ---- */
- MESA_FORMAT_RGBA8888, /* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */
- MESA_FORMAT_RGBA8888_REV, /* AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR */
- MESA_FORMAT_ARGB8888, /* AAAA AAAA RRRR RRRR GGGG GGGG BBBB BBBB */
- MESA_FORMAT_ARGB8888_REV, /* BBBB BBBB GGGG GGGG RRRR RRRR AAAA AAAA */
- MESA_FORMAT_RGB888, /* RRRR RRRR GGGG GGGG BBBB BBBB */
- MESA_FORMAT_BGR888, /* BBBB BBBB GGGG GGGG RRRR RRRR */
- MESA_FORMAT_RGB565, /* RRRR RGGG GGGB BBBB */
- MESA_FORMAT_RGB565_REV, /* GGGB BBBB RRRR RGGG */
- MESA_FORMAT_RGBA4444, /* RRRR GGGG BBBB AAAA */
- MESA_FORMAT_ARGB4444, /* AAAA RRRR GGGG BBBB */
- MESA_FORMAT_ARGB4444_REV, /* GGGG BBBB AAAA RRRR */
- MESA_FORMAT_RGBA5551, /* RRRR RGGG GGBB BBBA */
- MESA_FORMAT_ARGB1555, /* ARRR RRGG GGGB BBBB */
- MESA_FORMAT_ARGB1555_REV, /* GGGB BBBB ARRR RRGG */
- MESA_FORMAT_AL88, /* AAAA AAAA LLLL LLLL */
- MESA_FORMAT_AL88_REV, /* LLLL LLLL AAAA AAAA */
- MESA_FORMAT_RGB332, /* RRRG GGBB */
- MESA_FORMAT_A8, /* AAAA AAAA */
- MESA_FORMAT_L8, /* LLLL LLLL */
- MESA_FORMAT_I8, /* IIII IIII */
- MESA_FORMAT_CI8, /* CCCC CCCC */
- MESA_FORMAT_YCBCR, /* YYYY YYYY UorV UorV */
- MESA_FORMAT_YCBCR_REV, /* UorV UorV YYYY YYYY */
- MESA_FORMAT_Z24_S8, /* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ SSSS SSSS */
- MESA_FORMAT_S8_Z24, /* SSSS SSSS ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
- MESA_FORMAT_Z16, /* ZZZZ ZZZZ ZZZZ ZZZZ */
- MESA_FORMAT_Z32, /* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
- /*@}*/
-
-#if FEATURE_EXT_texture_sRGB
- /**
- * \name 8-bit/channel sRGB formats
- */
- /*@{*/
- MESA_FORMAT_SRGB8,
- MESA_FORMAT_SRGBA8,
- MESA_FORMAT_SARGB8,
- MESA_FORMAT_SL8,
- MESA_FORMAT_SLA8,
-#if FEATURE_texture_s3tc
- MESA_FORMAT_SRGB_DXT1,
- MESA_FORMAT_SRGBA_DXT1,
- MESA_FORMAT_SRGBA_DXT3,
- MESA_FORMAT_SRGBA_DXT5,
-#endif
- /*@}*/
-#endif
-
- /**
- * \name Compressed texture formats.
- */
- /*@{*/
-#if FEATURE_texture_fxt1
- MESA_FORMAT_RGB_FXT1,
- MESA_FORMAT_RGBA_FXT1,
-#endif
-#if FEATURE_texture_s3tc
- MESA_FORMAT_RGB_DXT1,
- MESA_FORMAT_RGBA_DXT1,
- MESA_FORMAT_RGBA_DXT3,
- MESA_FORMAT_RGBA_DXT5,
-#endif
- /*@}*/
-
- /**
- * \name Generic GLchan-based formats.
- *
- * Software-oriented texture formats. Texels are arrays of GLchan
- * values so there are no byte order issues.
- *
- * \note Because these are based on the GLchan data type, one cannot assume
- * 8 bits per channel with these formats. If you require GLubyte channels,
- * use one of the hardware formats above.
- */
- /*@{*/
- MESA_FORMAT_RGBA,
- MESA_FORMAT_RGB,
- MESA_FORMAT_ALPHA,
- MESA_FORMAT_LUMINANCE,
- MESA_FORMAT_LUMINANCE_ALPHA,
- MESA_FORMAT_INTENSITY,
- /*@}*/
-
- /**
- * \name Floating point texture formats.
- */
- /*@{*/
- MESA_FORMAT_RGBA_FLOAT32,
- MESA_FORMAT_RGBA_FLOAT16,
- MESA_FORMAT_RGB_FLOAT32,
- MESA_FORMAT_RGB_FLOAT16,
- MESA_FORMAT_ALPHA_FLOAT32,
- MESA_FORMAT_ALPHA_FLOAT16,
- MESA_FORMAT_LUMINANCE_FLOAT32,
- MESA_FORMAT_LUMINANCE_FLOAT16,
- MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
- MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,
- MESA_FORMAT_INTENSITY_FLOAT32,
- MESA_FORMAT_INTENSITY_FLOAT16,
- /*@}*/
-
- /**
- * \name Signed fixed point texture formats.
- */
- /*@{*/
- MESA_FORMAT_DUDV8,
- MESA_FORMAT_SIGNED_RGBA8888,
- MESA_FORMAT_SIGNED_RGBA8888_REV
- /*@}*/
-};
-
-
-/** GLchan-valued formats */
-/*@{*/
-extern const struct gl_texture_format _mesa_texformat_rgba;
-extern const struct gl_texture_format _mesa_texformat_rgb;
-extern const struct gl_texture_format _mesa_texformat_alpha;
-extern const struct gl_texture_format _mesa_texformat_luminance;
-extern const struct gl_texture_format _mesa_texformat_luminance_alpha;
-extern const struct gl_texture_format _mesa_texformat_intensity;
-/*@}*/
-
-#if FEATURE_EXT_texture_sRGB
-/** sRGB (nonlinear) formats */
-/*@{*/
-extern const struct gl_texture_format _mesa_texformat_srgb8;
-extern const struct gl_texture_format _mesa_texformat_srgba8;
-extern const struct gl_texture_format _mesa_texformat_sargb8;
-extern const struct gl_texture_format _mesa_texformat_sl8;
-extern const struct gl_texture_format _mesa_texformat_sla8;
-#if FEATURE_texture_s3tc
-extern const struct gl_texture_format _mesa_texformat_srgb_dxt1;
-extern const struct gl_texture_format _mesa_texformat_srgba_dxt1;
-extern const struct gl_texture_format _mesa_texformat_srgba_dxt3;
-extern const struct gl_texture_format _mesa_texformat_srgba_dxt5;
-#endif
-/*@}*/
-#endif
-
-/** Floating point texture formats */
-/*@{*/
-extern const struct gl_texture_format _mesa_texformat_rgba_float32;
-extern const struct gl_texture_format _mesa_texformat_rgba_float16;
-extern const struct gl_texture_format _mesa_texformat_rgb_float32;
-extern const struct gl_texture_format _mesa_texformat_rgb_float16;
-extern const struct gl_texture_format _mesa_texformat_alpha_float32;
-extern const struct gl_texture_format _mesa_texformat_alpha_float16;
-extern const struct gl_texture_format _mesa_texformat_luminance_float32;
-extern const struct gl_texture_format _mesa_texformat_luminance_float16;
-extern const struct gl_texture_format _mesa_texformat_luminance_alpha_float32;
-extern const struct gl_texture_format _mesa_texformat_luminance_alpha_float16;
-extern const struct gl_texture_format _mesa_texformat_intensity_float32;
-extern const struct gl_texture_format _mesa_texformat_intensity_float16;
-/*@}*/
-
-/** Signed fixed point texture formats */
-/*@{*/
-extern const struct gl_texture_format _mesa_texformat_dudv8;
-extern const struct gl_texture_format _mesa_texformat_signed_rgba8888;
-extern const struct gl_texture_format _mesa_texformat_signed_rgba8888_rev;
-/*@}*/
-
-/** \name Assorted hardware-friendly formats */
-/*@{*/
-extern const struct gl_texture_format _mesa_texformat_rgba8888;
-extern const struct gl_texture_format _mesa_texformat_rgba8888_rev;
-extern const struct gl_texture_format _mesa_texformat_argb8888;
-extern const struct gl_texture_format _mesa_texformat_argb8888_rev;
-extern const struct gl_texture_format _mesa_texformat_rgb888;
-extern const struct gl_texture_format _mesa_texformat_bgr888;
-extern const struct gl_texture_format _mesa_texformat_rgb565;
-extern const struct gl_texture_format _mesa_texformat_rgb565_rev;
-extern const struct gl_texture_format _mesa_texformat_rgba4444;
-extern const struct gl_texture_format _mesa_texformat_argb4444;
-extern const struct gl_texture_format _mesa_texformat_argb4444_rev;
-extern const struct gl_texture_format _mesa_texformat_argb1555;
-extern const struct gl_texture_format _mesa_texformat_argb1555_rev;
-extern const struct gl_texture_format _mesa_texformat_rgba5551;
-extern const struct gl_texture_format _mesa_texformat_al88;
-extern const struct gl_texture_format _mesa_texformat_al88_rev;
-extern const struct gl_texture_format _mesa_texformat_rgb332;
-extern const struct gl_texture_format _mesa_texformat_a8;
-extern const struct gl_texture_format _mesa_texformat_l8;
-extern const struct gl_texture_format _mesa_texformat_i8;
-extern const struct gl_texture_format _mesa_texformat_ci8;
-extern const struct gl_texture_format _mesa_texformat_z24_s8;
-extern const struct gl_texture_format _mesa_texformat_s8_z24;
-extern const struct gl_texture_format _mesa_texformat_z16;
-extern const struct gl_texture_format _mesa_texformat_z32;
-/*@}*/
-
-/** \name YCbCr formats */
-/*@{*/
-extern const struct gl_texture_format _mesa_texformat_ycbcr;
-extern const struct gl_texture_format _mesa_texformat_ycbcr_rev;
-/*@}*/
-
-/** \name Compressed formats */
-/*@{*/
-#if FEATURE_texture_fxt1
-extern const struct gl_texture_format _mesa_texformat_rgb_fxt1;
-extern const struct gl_texture_format _mesa_texformat_rgba_fxt1;
-#endif
-#if FEATURE_texture_s3tc
-extern const struct gl_texture_format _mesa_texformat_rgb_dxt1;
-extern const struct gl_texture_format _mesa_texformat_rgba_dxt1;
-extern const struct gl_texture_format _mesa_texformat_rgba_dxt3;
-extern const struct gl_texture_format _mesa_texformat_rgba_dxt5;
-#endif
-/*@}*/
-
-/** \name The null format */
-/*@{*/
-extern const struct gl_texture_format _mesa_null_texformat;
-/*@}*/
-
-
-extern const struct gl_texture_format *
+extern gl_format
_mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
GLenum format, GLenum type );
-extern void
-_mesa_format_to_type_and_comps(const struct gl_texture_format *format,
- GLenum *datatype, GLuint *comps);
-
-
#endif
diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
index 25200199235..1338d4552db 100644
--- a/src/mesa/main/texgetimage.c
+++ b/src/mesa/main/texgetimage.c
@@ -33,9 +33,9 @@
#include "bufferobj.h"
#include "enums.h"
#include "context.h"
+#include "formats.h"
#include "image.h"
#include "texcompress.h"
-#include "texformat.h"
#include "texgetimage.h"
#include "teximage.h"
#include "texstate.h"
@@ -50,7 +50,7 @@
static GLboolean
is_srgb_teximage(const struct gl_texture_image *texImage)
{
- switch (texImage->TexFormat->MesaFormat) {
+ switch (texImage->TexFormat) {
case MESA_FORMAT_SRGB8:
case MESA_FORMAT_SRGBA8:
case MESA_FORMAT_SARGB8:
@@ -162,15 +162,16 @@ _mesa_get_teximage(GLcontext *ctx, GLenum target, GLint level,
if (format == GL_COLOR_INDEX) {
GLuint indexRow[MAX_WIDTH];
GLint col;
+ GLuint indexBits = _mesa_get_format_bits(texImage->TexFormat, GL_TEXTURE_INDEX_SIZE_EXT);
/* Can't use FetchTexel here because that returns RGBA */
- if (texImage->TexFormat->IndexBits == 8) {
+ if (indexBits == 8) {
const GLubyte *src = (const GLubyte *) texImage->Data;
src += width * (img * texImage->Height + row);
for (col = 0; col < width; col++) {
indexRow[col] = src[col];
}
}
- else if (texImage->TexFormat->IndexBits == 16) {
+ else if (indexBits == 16) {
const GLushort *src = (const GLushort *) texImage->Data;
src += width * (img * texImage->Height + row);
for (col = 0; col < width; col++) {
@@ -211,9 +212,9 @@ _mesa_get_teximage(GLcontext *ctx, GLenum target, GLint level,
(const GLushort *) texImage->Data + row * rowstride,
width * sizeof(GLushort));
/* check for byte swapping */
- if ((texImage->TexFormat->MesaFormat == MESA_FORMAT_YCBCR
+ if ((texImage->TexFormat == MESA_FORMAT_YCBCR
&& type == GL_UNSIGNED_SHORT_8_8_REV_MESA) ||
- (texImage->TexFormat->MesaFormat == MESA_FORMAT_YCBCR_REV
+ (texImage->TexFormat == MESA_FORMAT_YCBCR_REV
&& type == GL_UNSIGNED_SHORT_8_8_MESA)) {
if (!ctx->Pack.SwapBytes)
_mesa_swap2((GLushort *) dest, width);
@@ -259,6 +260,8 @@ _mesa_get_teximage(GLcontext *ctx, GLenum target, GLint level,
GLfloat rgba[MAX_WIDTH][4];
GLint col;
GLbitfield transferOps = 0x0;
+ GLenum dataType =
+ _mesa_get_format_datatype(texImage->TexFormat);
/* clamp does not apply to GetTexImage (final conversion)?
* Looks like we need clamp though when going from format
@@ -267,8 +270,8 @@ _mesa_get_teximage(GLcontext *ctx, GLenum target, GLint level,
if (format == GL_LUMINANCE || format == GL_LUMINANCE_ALPHA)
transferOps |= IMAGE_CLAMP_BIT;
else if (!type_with_negative_values(type) &&
- (texImage->TexFormat->DataType == GL_FLOAT ||
- texImage->TexFormat->DataType == GL_SIGNED_NORMALIZED))
+ (dataType == GL_FLOAT ||
+ dataType == GL_SIGNED_NORMALIZED))
transferOps |= IMAGE_CLAMP_BIT;
for (col = 0; col < width; col++) {
@@ -319,7 +322,10 @@ _mesa_get_compressed_teximage(GLcontext *ctx, GLenum target, GLint level,
struct gl_texture_object *texObj,
struct gl_texture_image *texImage)
{
- GLuint size;
+ const GLuint size = _mesa_format_image_size(texImage->TexFormat,
+ texImage->Width,
+ texImage->Height,
+ texImage->Depth);
if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
/* pack texture image into a PBO */
@@ -339,11 +345,6 @@ _mesa_get_compressed_teximage(GLcontext *ctx, GLenum target, GLint level,
return;
}
- /* don't use texImage->CompressedSize since that may be padded out */
- size = _mesa_compressed_texture_size(ctx, texImage->Width, texImage->Height,
- texImage->Depth,
- texImage->TexFormat->MesaFormat);
-
/* just memcpy, no pixelstore or pixel transfer */
_mesa_memcpy(img, texImage->Data, size);
@@ -367,6 +368,7 @@ getteximage_error_check(GLcontext *ctx, GLenum target, GLint level,
struct gl_texture_object *texObj;
struct gl_texture_image *texImage;
const GLuint maxLevels = _mesa_max_texture_levels(ctx, target);
+ GLenum baseFormat;
if (maxLevels == 0) {
_mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(target=0x%x)", target);
@@ -429,40 +431,42 @@ getteximage_error_check(GLcontext *ctx, GLenum target, GLint level,
/* out of memory */
return GL_TRUE;
}
+
+ baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
/* Make sure the requested image format is compatible with the
* texture's format. Note that a color index texture can be converted
* to RGBA so that combo is allowed.
*/
if (_mesa_is_color_format(format)
- && !_mesa_is_color_format(texImage->TexFormat->BaseFormat)
- && !_mesa_is_index_format(texImage->TexFormat->BaseFormat)) {
+ && !_mesa_is_color_format(baseFormat)
+ && !_mesa_is_index_format(baseFormat)) {
_mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
return GL_TRUE;
}
else if (_mesa_is_index_format(format)
- && !_mesa_is_index_format(texImage->TexFormat->BaseFormat)) {
+ && !_mesa_is_index_format(baseFormat)) {
_mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
return GL_TRUE;
}
else if (_mesa_is_depth_format(format)
- && !_mesa_is_depth_format(texImage->TexFormat->BaseFormat)
- && !_mesa_is_depthstencil_format(texImage->TexFormat->BaseFormat)) {
+ && !_mesa_is_depth_format(baseFormat)
+ && !_mesa_is_depthstencil_format(baseFormat)) {
_mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
return GL_TRUE;
}
else if (_mesa_is_ycbcr_format(format)
- && !_mesa_is_ycbcr_format(texImage->TexFormat->BaseFormat)) {
+ && !_mesa_is_ycbcr_format(baseFormat)) {
_mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
return GL_TRUE;
}
else if (_mesa_is_depthstencil_format(format)
- && !_mesa_is_depthstencil_format(texImage->TexFormat->BaseFormat)) {
+ && !_mesa_is_depthstencil_format(baseFormat)) {
_mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
return GL_TRUE;
}
else if (_mesa_is_dudv_format(format)
- && !_mesa_is_dudv_format(texImage->TexFormat->BaseFormat)) {
+ && !_mesa_is_dudv_format(baseFormat)) {
_mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
return GL_TRUE;
}
@@ -519,10 +523,10 @@ _mesa_GetTexImage( GLenum target, GLint level, GLenum format,
if (MESA_VERBOSE & (VERBOSE_API | VERBOSE_TEXTURE)) {
struct gl_texture_image *texImage =
_mesa_select_tex_image(ctx, texObj, target, level);
- _mesa_debug(ctx, "glGetTexImage(tex %u) format = %d, w=%d, h=%d,"
+ _mesa_debug(ctx, "glGetTexImage(tex %u) format = %s, w=%d, h=%d,"
" dstFmt=0x%x, dstType=0x%x\n",
texObj->Name,
- texImage->TexFormat->MesaFormat,
+ _mesa_get_format_name(texImage->TexFormat),
texImage->Width, texImage->Height,
format, type);
}
@@ -590,13 +594,15 @@ getcompressedteximage_error_check(GLcontext *ctx, GLenum target, GLint level,
return GL_TRUE;
}
- if (!texImage->IsCompressed) {
+ if (!_mesa_is_format_compressed(texImage->TexFormat)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glGetCompressedTexImageARB(texture is not compressed)");
return GL_TRUE;
}
if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
+ GLuint compressedSize;
+
/* make sure PBO is not mapped */
if (_mesa_bufferobj_mapped(ctx->Pack.BufferObj)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
@@ -604,8 +610,13 @@ getcompressedteximage_error_check(GLcontext *ctx, GLenum target, GLint level,
return GL_TRUE;
}
+ compressedSize = _mesa_format_image_size(texImage->TexFormat,
+ texImage->Width,
+ texImage->Height,
+ texImage->Depth);
+
/* do bounds checking on PBO write */
- if ((const GLubyte *) img + texImage->CompressedSize >
+ if ((const GLubyte *) img + compressedSize >
(const GLubyte *) ctx->Pack.BufferObj->Size) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glGetCompressedTexImage(out of bounds PBO write)");
@@ -636,9 +647,9 @@ _mesa_GetCompressedTexImageARB(GLenum target, GLint level, GLvoid *img)
struct gl_texture_image *texImage =
_mesa_select_tex_image(ctx, texObj, target, level);
_mesa_debug(ctx,
- "glGetCompressedTexImage(tex %u) format = %d, w=%d, h=%d\n",
+ "glGetCompressedTexImage(tex %u) format = %s, w=%d, h=%d\n",
texObj->Name,
- texImage->TexFormat->MesaFormat,
+ _mesa_get_format_name(texImage->TexFormat),
texImage->Width, texImage->Height);
}
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index fe11adb6f13..0db98795dc5 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -43,7 +43,7 @@
#include "macros.h"
#include "state.h"
#include "texcompress.h"
-#include "texformat.h"
+#include "texfetch.h"
#include "teximage.h"
#include "texstate.h"
#include "texstore.h"
@@ -900,11 +900,9 @@ clear_teximage_fields(struct gl_texture_image *img)
img->HeightLog2 = 0;
img->DepthLog2 = 0;
img->Data = NULL;
- img->TexFormat = &_mesa_null_texformat;
+ img->TexFormat = MESA_FORMAT_NONE;
img->FetchTexelc = NULL;
img->FetchTexelf = NULL;
- img->IsCompressed = 0;
- img->CompressedSize = 0;
}
@@ -967,9 +965,6 @@ _mesa_init_teximage_fields(GLcontext *ctx, GLenum target,
img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2);
- img->IsCompressed = GL_FALSE;
- img->CompressedSize = 0;
-
if ((width == 1 || _mesa_is_pow_two(img->Width2)) &&
(height == 1 || _mesa_is_pow_two(img->Height2)) &&
(depth == 1 || _mesa_is_pow_two(img->Depth2)))
@@ -1002,6 +997,9 @@ _mesa_init_teximage_fields(GLcontext *ctx, GLenum target,
img->HeightScale = (GLfloat) img->Height;
img->DepthScale = (GLfloat) img->Depth;
}
+
+ img->FetchTexelc = NULL;
+ img->FetchTexelf = NULL;
}
@@ -1601,7 +1599,7 @@ subtexture_error_check2( GLcontext *ctx, GLuint dimensions,
}
#endif
- if (destTex->IsCompressed) {
+ if (_mesa_is_format_compressed(destTex->TexFormat)) {
if (!target_can_be_compressed(ctx, target)) {
_mesa_error(ctx, GL_INVALID_ENUM,
"glTexSubImage%D(target)", dimensions);
@@ -1963,7 +1961,7 @@ copytexsubimage_error_check2( GLcontext *ctx, GLuint dimensions,
}
}
- if (teximage->IsCompressed) {
+ if (_mesa_is_format_compressed(teximage->TexFormat)) {
if (!target_can_be_compressed(ctx, target)) {
_mesa_error(ctx, GL_INVALID_ENUM,
"glCopyTexSubImage%d(target)", dimensions);
@@ -2207,6 +2205,12 @@ _mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat,
postConvWidth, 1, 1,
border, internalFormat);
+ /* Choose actual texture format */
+ texImage->TexFormat =
+ ctx->Driver.ChooseTextureFormat(ctx, internalFormat,
+ format, type);
+ ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
+
/* Give the texture to the driver. <pixels> may be null. */
ASSERT(ctx->Driver.TexImage1D);
ctx->Driver.TexImage1D(ctx, target, level, internalFormat,
@@ -2215,6 +2219,8 @@ _mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat,
ASSERT(texImage->TexFormat);
+ _mesa_set_fetch_functions(texImage, 1);
+
check_gen_mipmap(ctx, target, texObj, level);
update_fbo_texture(ctx, texObj, face, level);
@@ -2242,8 +2248,8 @@ _mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat,
_mesa_init_teximage_fields(ctx, target, texImage,
postConvWidth, 1, 1,
border, internalFormat);
- texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx,
- internalFormat, format, type);
+ texImage->TexFormat =
+ ctx->Driver.ChooseTextureFormat(ctx, internalFormat, format, type);
}
}
else {
@@ -2319,6 +2325,12 @@ _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat,
postConvWidth, postConvHeight, 1,
border, internalFormat);
+ /* Choose actual texture format */
+ texImage->TexFormat =
+ ctx->Driver.ChooseTextureFormat(ctx, internalFormat,
+ format, type);
+ ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
+
/* Give the texture to the driver. <pixels> may be null. */
ASSERT(ctx->Driver.TexImage2D);
ctx->Driver.TexImage2D(ctx, target, level, internalFormat,
@@ -2327,6 +2339,8 @@ _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat,
ASSERT(texImage->TexFormat);
+ _mesa_set_fetch_functions(texImage, 2);
+
check_gen_mipmap(ctx, target, texObj, level);
update_fbo_texture(ctx, texObj, face, level);
@@ -2360,8 +2374,8 @@ _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat,
_mesa_init_teximage_fields(ctx, target, texImage,
postConvWidth, postConvHeight, 1,
border, internalFormat);
- texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx,
- internalFormat, format, type);
+ texImage->TexFormat =
+ ctx->Driver.ChooseTextureFormat(ctx, internalFormat, format, type);
}
}
else {
@@ -2427,6 +2441,12 @@ _mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat,
width, height, depth,
border, internalFormat);
+ /* Choose actual texture format */
+ texImage->TexFormat =
+ ctx->Driver.ChooseTextureFormat(ctx, internalFormat,
+ format, type);
+ ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
+
/* Give the texture to the driver. <pixels> may be null. */
ASSERT(ctx->Driver.TexImage3D);
ctx->Driver.TexImage3D(ctx, target, level, internalFormat,
@@ -2435,6 +2455,8 @@ _mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat,
ASSERT(texImage->TexFormat);
+ _mesa_set_fetch_functions(texImage, 3);
+
check_gen_mipmap(ctx, target, texObj, level);
update_fbo_texture(ctx, texObj, face, level);
@@ -2462,8 +2484,8 @@ _mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat,
/* no error, set the tex image parameters */
_mesa_init_teximage_fields(ctx, target, texImage, width, height,
depth, border, internalFormat);
- texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx,
- internalFormat, format, type);
+ texImage->TexFormat =
+ ctx->Driver.ChooseTextureFormat(ctx, internalFormat, format, type);
}
}
else {
@@ -2729,12 +2751,20 @@ _mesa_CopyTexImage1D( GLenum target, GLint level,
_mesa_init_teximage_fields(ctx, target, texImage, postConvWidth, 1, 1,
border, internalFormat);
+ /* Choose actual texture format */
+ texImage->TexFormat =
+ ctx->Driver.ChooseTextureFormat(ctx, internalFormat,
+ GL_NONE, GL_NONE);
+ ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
+
ASSERT(ctx->Driver.CopyTexImage1D);
ctx->Driver.CopyTexImage1D(ctx, target, level, internalFormat,
x, y, width, border);
ASSERT(texImage->TexFormat);
+ _mesa_set_fetch_functions(texImage, 1);
+
check_gen_mipmap(ctx, target, texObj, level);
update_fbo_texture(ctx, texObj, face, level);
@@ -2802,12 +2832,20 @@ _mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat,
postConvWidth, postConvHeight, 1,
border, internalFormat);
+ /* Choose actual texture format */
+ texImage->TexFormat =
+ ctx->Driver.ChooseTextureFormat(ctx, internalFormat,
+ GL_NONE, GL_NONE);
+ ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
+
ASSERT(ctx->Driver.CopyTexImage2D);
ctx->Driver.CopyTexImage2D(ctx, target, level, internalFormat,
x, y, width, height, border);
ASSERT(texImage->TexFormat);
+ _mesa_set_fetch_functions(texImage, 2);
+
check_gen_mipmap(ctx, target, texObj, level);
update_fbo_texture(ctx, texObj, face, level);
@@ -3017,6 +3055,29 @@ _mesa_CopyTexSubImage3D( GLenum target, GLint level,
/**
+ * Return expected size of a compressed texture.
+ */
+static GLuint
+compressed_tex_size(GLsizei width, GLsizei height, GLsizei depth,
+ GLenum glformat)
+{
+ gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat);
+ return _mesa_format_image_size(mesaFormat, width, height, depth);
+}
+
+
+/*
+ * Return compressed texture block size, in pixels.
+ */
+static void
+get_compressed_block_size(GLenum glformat, GLuint *bw, GLuint *bh)
+{
+ gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat);
+ _mesa_get_format_block_size(mesaFormat, bw, bh);
+}
+
+
+/**
* Error checking for glCompressedTexImage[123]D().
* \return error code or GL_NO_ERROR.
*/
@@ -3098,8 +3159,7 @@ compressed_texture_error_check(GLcontext *ctx, GLint dimensions,
if (level < 0 || level >= maxLevels)
return GL_INVALID_VALUE;
- expectedSize = _mesa_compressed_texture_size_glenum(ctx, width, height,
- depth, internalFormat);
+ expectedSize = compressed_tex_size(width, height, depth, internalFormat);
if (expectedSize != imageSize)
return GL_INVALID_VALUE;
@@ -3132,6 +3192,7 @@ compressed_subtexture_error_check(GLcontext *ctx, GLint dimensions,
GLenum format, GLsizei imageSize)
{
GLint expectedSize, maxLevels = 0, maxTextureSize;
+ GLuint bw, bh;
(void) zoffset;
if (dimensions == 1) {
@@ -3181,20 +3242,21 @@ compressed_subtexture_error_check(GLcontext *ctx, GLint dimensions,
if (level < 0 || level >= maxLevels)
return GL_INVALID_VALUE;
- /* XXX these tests are specific to the compressed format.
- * this code should be generalized in some way.
+ /*
+ * do checks which depend on compression block size
*/
- if ((xoffset & 3) != 0 || (yoffset & 3) != 0)
+ get_compressed_block_size(format, &bw, &bh);
+
+ if ((xoffset % bw != 0) || (yoffset % bh != 0))
return GL_INVALID_VALUE;
- if ((width & 3) != 0 && width != 2 && width != 1)
+ if ((width % bw != 0) && width != 2 && width != 1)
return GL_INVALID_VALUE;
- if ((height & 3) != 0 && height != 2 && height != 1)
+ if ((height % bh != 0) && height != 2 && height != 1)
return GL_INVALID_VALUE;
- expectedSize = _mesa_compressed_texture_size_glenum(ctx, width, height,
- depth, format);
+ expectedSize = compressed_tex_size(width, height, depth, format);
if (expectedSize != imageSize)
return GL_INVALID_VALUE;
@@ -3295,12 +3357,20 @@ _mesa_CompressedTexImage1DARB(GLenum target, GLint level,
_mesa_init_teximage_fields(ctx, target, texImage, width, 1, 1,
border, internalFormat);
+ /* Choose actual texture format */
+ texImage->TexFormat =
+ ctx->Driver.ChooseTextureFormat(ctx, internalFormat,
+ GL_NONE, GL_NONE);
+ ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
+
ASSERT(ctx->Driver.CompressedTexImage1D);
ctx->Driver.CompressedTexImage1D(ctx, target, level,
internalFormat, width, border,
imageSize, data,
texObj, texImage);
+ _mesa_set_fetch_functions(texImage, 1);
+
check_gen_mipmap(ctx, target, texObj, level);
/* state update */
@@ -3397,12 +3467,20 @@ _mesa_CompressedTexImage2DARB(GLenum target, GLint level,
_mesa_init_teximage_fields(ctx, target, texImage, width, height, 1,
border, internalFormat);
+ /* Choose actual texture format */
+ texImage->TexFormat =
+ ctx->Driver.ChooseTextureFormat(ctx, internalFormat,
+ GL_NONE, GL_NONE);
+ ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
+
ASSERT(ctx->Driver.CompressedTexImage2D);
ctx->Driver.CompressedTexImage2D(ctx, target, level,
internalFormat, width, height,
border, imageSize, data,
texObj, texImage);
+ _mesa_set_fetch_functions(texImage, 2);
+
check_gen_mipmap(ctx, target, texObj, level);
/* state update */
@@ -3498,6 +3576,12 @@ _mesa_CompressedTexImage3DARB(GLenum target, GLint level,
width, height, depth,
border, internalFormat);
+ /* Choose actual texture format */
+ texImage->TexFormat =
+ ctx->Driver.ChooseTextureFormat(ctx, internalFormat,
+ GL_NONE, GL_NONE);
+ ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
+
ASSERT(ctx->Driver.CompressedTexImage3D);
ctx->Driver.CompressedTexImage3D(ctx, target, level,
internalFormat,
@@ -3505,6 +3589,8 @@ _mesa_CompressedTexImage3DARB(GLenum target, GLint level,
border, imageSize, data,
texObj, texImage);
+ _mesa_set_fetch_functions(texImage, 3);
+
check_gen_mipmap(ctx, target, texObj, level);
/* state update */
diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index 31832184c0e..aaccc03a7c6 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -33,6 +33,7 @@
#include "context.h"
#include "enums.h"
#include "fbobject.h"
+#include "formats.h"
#include "hash.h"
#include "imports.h"
#include "macros.h"
@@ -740,6 +741,10 @@ _mesa_get_fallback_texture(GLcontext *ctx)
_mesa_init_teximage_fields(ctx, GL_TEXTURE_2D, texImage,
8, 8, 1, 0, GL_RGBA);
+ texImage->TexFormat =
+ ctx->Driver.ChooseTextureFormat(ctx, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
+ ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
+
/* set image data */
ctx->Driver.TexImage2D(ctx, GL_TEXTURE_2D, 0, GL_RGBA,
8, 8, 0,
diff --git a/src/mesa/main/texparam.c b/src/mesa/main/texparam.c
index 9d1fdd05664..42584760921 100644
--- a/src/mesa/main/texparam.c
+++ b/src/mesa/main/texparam.c
@@ -31,9 +31,10 @@
#include "main/glheader.h"
+#include "main/colormac.h"
#include "main/context.h"
#include "main/enums.h"
-#include "main/colormac.h"
+#include "main/formats.h"
#include "main/macros.h"
#include "main/texcompress.h"
#include "main/texparam.h"
@@ -726,6 +727,7 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
const struct gl_texture_image *img = NULL;
GLboolean isProxy;
GLint maxLevels;
+ gl_format texFormat;
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END(ctx);
@@ -763,6 +765,8 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
goto out;
}
+ texFormat = img->TexFormat;
+
isProxy = _mesa_is_proxy_texture(target);
switch (pname) {
@@ -776,10 +780,9 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
*params = img->Depth;
break;
case GL_TEXTURE_INTERNAL_FORMAT:
- if (img->IsCompressed) {
+ if (_mesa_is_format_compressed(img->TexFormat)) {
/* need to return the actual compressed format */
- *params = _mesa_compressed_format_to_glenum(ctx,
- img->TexFormat->MesaFormat);
+ *params = _mesa_compressed_format_to_glenum(ctx, img->TexFormat);
}
else {
/* return the user's requested internal format */
@@ -790,20 +793,10 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
*params = img->Border;
break;
case GL_TEXTURE_RED_SIZE:
- if (img->_BaseFormat == GL_RGB || img->_BaseFormat == GL_RGBA)
- *params = img->TexFormat->RedBits;
- else
- *params = 0;
- break;
case GL_TEXTURE_GREEN_SIZE:
- if (img->_BaseFormat == GL_RGB || img->_BaseFormat == GL_RGBA)
- *params = img->TexFormat->GreenBits;
- else
- *params = 0;
- break;
case GL_TEXTURE_BLUE_SIZE:
if (img->_BaseFormat == GL_RGB || img->_BaseFormat == GL_RGBA)
- *params = img->TexFormat->BlueBits;
+ *params = _mesa_get_format_bits(texFormat, pname);
else
*params = 0;
break;
@@ -811,36 +804,44 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
if (img->_BaseFormat == GL_ALPHA ||
img->_BaseFormat == GL_LUMINANCE_ALPHA ||
img->_BaseFormat == GL_RGBA)
- *params = img->TexFormat->AlphaBits;
+ *params = _mesa_get_format_bits(texFormat, pname);
else
*params = 0;
break;
case GL_TEXTURE_INTENSITY_SIZE:
if (img->_BaseFormat != GL_INTENSITY)
*params = 0;
- else if (img->TexFormat->IntensityBits > 0)
- *params = img->TexFormat->IntensityBits;
- else /* intensity probably stored as rgb texture */
- *params = MIN2(img->TexFormat->RedBits, img->TexFormat->GreenBits);
+ else {
+ *params = _mesa_get_format_bits(texFormat, pname);
+ if (*params == 0) {
+ /* intensity probably stored as rgb texture */
+ *params = MIN2(_mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE),
+ _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE));
+ }
+ }
break;
case GL_TEXTURE_LUMINANCE_SIZE:
if (img->_BaseFormat != GL_LUMINANCE &&
img->_BaseFormat != GL_LUMINANCE_ALPHA)
*params = 0;
- else if (img->TexFormat->LuminanceBits > 0)
- *params = img->TexFormat->LuminanceBits;
- else /* luminance probably stored as rgb texture */
- *params = MIN2(img->TexFormat->RedBits, img->TexFormat->GreenBits);
+ else {
+ *params = _mesa_get_format_bits(texFormat, pname);
+ if (*params == 0) {
+ /* luminance probably stored as rgb texture */
+ *params = MIN2(_mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE),
+ _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE));
+ }
+ }
break;
case GL_TEXTURE_INDEX_SIZE_EXT:
if (img->_BaseFormat == GL_COLOR_INDEX)
- *params = img->TexFormat->IndexBits;
+ *params = _mesa_get_format_bits(texFormat, pname);
else
*params = 0;
break;
case GL_TEXTURE_DEPTH_SIZE_ARB:
if (ctx->Extensions.ARB_depth_texture)
- *params = img->TexFormat->DepthBits;
+ *params = _mesa_get_format_bits(texFormat, pname);
else
_mesa_error(ctx, GL_INVALID_ENUM,
"glGetTexLevelParameter[if]v(pname)");
@@ -848,7 +849,7 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
case GL_TEXTURE_STENCIL_SIZE_EXT:
if (ctx->Extensions.EXT_packed_depth_stencil ||
ctx->Extensions.ARB_framebuffer_object) {
- *params = img->TexFormat->StencilBits;
+ *params = _mesa_get_format_bits(texFormat, pname);
}
else {
_mesa_error(ctx, GL_INVALID_ENUM,
@@ -858,13 +859,9 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
/* GL_ARB_texture_compression */
case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
- if (img->IsCompressed && !isProxy) {
- /* Don't use ctx->Driver.CompressedTextureSize() since that
- * may returned a padded hardware size.
- */
- *params = _mesa_compressed_texture_size(ctx, img->Width,
- img->Height, img->Depth,
- img->TexFormat->MesaFormat);
+ if (_mesa_is_format_compressed(img->TexFormat) && !isProxy) {
+ *params = _mesa_format_image_size(texFormat, img->Width,
+ img->Height, img->Depth);
}
else {
_mesa_error(ctx, GL_INVALID_OPERATION,
@@ -872,13 +869,14 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
}
break;
case GL_TEXTURE_COMPRESSED:
- *params = (GLint) img->IsCompressed;
+ *params = (GLint) _mesa_is_format_compressed(img->TexFormat);
break;
/* GL_ARB_texture_float */
case GL_TEXTURE_RED_TYPE_ARB:
if (ctx->Extensions.ARB_texture_float) {
- *params = img->TexFormat->RedBits ? img->TexFormat->DataType : GL_NONE;
+ *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE) ?
+ _mesa_get_format_datatype(texFormat) : GL_NONE;
}
else {
_mesa_error(ctx, GL_INVALID_ENUM,
@@ -887,7 +885,8 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
break;
case GL_TEXTURE_GREEN_TYPE_ARB:
if (ctx->Extensions.ARB_texture_float) {
- *params = img->TexFormat->GreenBits ? img->TexFormat->DataType : GL_NONE;
+ *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE) ?
+ _mesa_get_format_datatype(texFormat) : GL_NONE;
}
else {
_mesa_error(ctx, GL_INVALID_ENUM,
@@ -896,7 +895,8 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
break;
case GL_TEXTURE_BLUE_TYPE_ARB:
if (ctx->Extensions.ARB_texture_float) {
- *params = img->TexFormat->BlueBits ? img->TexFormat->DataType : GL_NONE;
+ *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_BLUE_SIZE) ?
+ _mesa_get_format_datatype(texFormat) : GL_NONE;
}
else {
_mesa_error(ctx, GL_INVALID_ENUM,
@@ -905,7 +905,8 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
break;
case GL_TEXTURE_ALPHA_TYPE_ARB:
if (ctx->Extensions.ARB_texture_float) {
- *params = img->TexFormat->AlphaBits ? img->TexFormat->DataType : GL_NONE;
+ *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_ALPHA_SIZE) ?
+ _mesa_get_format_datatype(texFormat) : GL_NONE;
}
else {
_mesa_error(ctx, GL_INVALID_ENUM,
@@ -914,7 +915,8 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
break;
case GL_TEXTURE_LUMINANCE_TYPE_ARB:
if (ctx->Extensions.ARB_texture_float) {
- *params = img->TexFormat->LuminanceBits ? img->TexFormat->DataType : GL_NONE;
+ *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_LUMINANCE_SIZE) ?
+ _mesa_get_format_datatype(texFormat) : GL_NONE;
}
else {
_mesa_error(ctx, GL_INVALID_ENUM,
@@ -923,7 +925,8 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
break;
case GL_TEXTURE_INTENSITY_TYPE_ARB:
if (ctx->Extensions.ARB_texture_float) {
- *params = img->TexFormat->IntensityBits ? img->TexFormat->DataType : GL_NONE;
+ *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_INTENSITY_SIZE) ?
+ _mesa_get_format_datatype(texFormat) : GL_NONE;
}
else {
_mesa_error(ctx, GL_INVALID_ENUM,
@@ -932,7 +935,8 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
break;
case GL_TEXTURE_DEPTH_TYPE_ARB:
if (ctx->Extensions.ARB_texture_float) {
- *params = img->TexFormat->DepthBits ? img->TexFormat->DataType : GL_NONE;
+ *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_DEPTH_SIZE) ?
+ _mesa_get_format_datatype(texFormat) : GL_NONE;
}
else {
_mesa_error(ctx, GL_INVALID_ENUM,
diff --git a/src/mesa/main/texrender.c b/src/mesa/main/texrender.c
index 53be83b05ce..e2432be6ca4 100644
--- a/src/mesa/main/texrender.c
+++ b/src/mesa/main/texrender.c
@@ -1,7 +1,8 @@
#include "context.h"
+#include "colormac.h"
#include "fbobject.h"
-#include "texformat.h"
+#include "texfetch.h"
#include "texrender.h"
#include "renderbuffer.h"
@@ -46,7 +47,9 @@ texture_get_row(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
if (rb->DataType == CHAN_TYPE) {
GLchan *rgbaOut = (GLchan *) values;
for (i = 0; i < count; i++) {
- trb->TexImage->FetchTexelc(trb->TexImage, x + i, y, z, rgbaOut + 4 * i);
+ GLfloat rgba[4];
+ trb->TexImage->FetchTexelf(trb->TexImage, x + i, y, z, rgba);
+ UNCLAMPED_FLOAT_TO_RGBA_CHAN(rgbaOut + 4 * i, rgba);
}
}
else if (rb->DataType == GL_UNSIGNED_SHORT) {
@@ -100,8 +103,10 @@ texture_get_values(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
if (rb->DataType == CHAN_TYPE) {
GLchan *rgbaOut = (GLchan *) values;
for (i = 0; i < count; i++) {
- trb->TexImage->FetchTexelc(trb->TexImage, x[i], y[i] + trb->Yoffset,
- z, rgbaOut + 4 * i);
+ GLfloat rgba[4];
+ trb->TexImage->FetchTexelf(trb->TexImage, x[i], y[i] + trb->Yoffset,
+ z, rgba);
+ UNCLAMPED_FLOAT_TO_RGBA_CHAN(rgbaOut + 4 * i, rgba);
}
}
else if (rb->DataType == GL_UNSIGNED_SHORT) {
@@ -462,6 +467,7 @@ update_wrapper(GLcontext *ctx, const struct gl_renderbuffer_attachment *att)
{
struct texture_renderbuffer *trb
= (struct texture_renderbuffer *) att->Renderbuffer;
+ gl_format texFormat;
(void) ctx;
ASSERT(trb);
@@ -469,7 +475,7 @@ update_wrapper(GLcontext *ctx, const struct gl_renderbuffer_attachment *att)
trb->TexImage = att->Texture->Image[att->CubeMapFace][att->TextureLevel];
ASSERT(trb->TexImage);
- trb->Store = trb->TexImage->TexFormat->StoreTexel;
+ trb->Store = _mesa_get_texel_store_func(trb->TexImage->TexFormat);
if (!trb->Store) {
/* we'll never draw into some textures (compressed formats) */
trb->Store = store_nop;
@@ -484,41 +490,30 @@ update_wrapper(GLcontext *ctx, const struct gl_renderbuffer_attachment *att)
trb->Zoffset = att->Zoffset;
}
+ texFormat = trb->TexImage->TexFormat;
+
trb->Base.Width = trb->TexImage->Width;
trb->Base.Height = trb->TexImage->Height;
trb->Base.InternalFormat = trb->TexImage->InternalFormat;
/* XXX may need more special cases here */
- if (trb->TexImage->TexFormat->MesaFormat == MESA_FORMAT_Z24_S8) {
- trb->Base._ActualFormat = GL_DEPTH24_STENCIL8_EXT;
+ if (trb->TexImage->TexFormat == MESA_FORMAT_Z24_S8) {
+ trb->Base.Format = MESA_FORMAT_Z24_S8;
trb->Base.DataType = GL_UNSIGNED_INT_24_8_EXT;
}
- else if (trb->TexImage->TexFormat->MesaFormat == MESA_FORMAT_Z16) {
- trb->Base._ActualFormat = GL_DEPTH_COMPONENT;
+ else if (trb->TexImage->TexFormat == MESA_FORMAT_Z16) {
+ trb->Base.Format = MESA_FORMAT_Z16;
trb->Base.DataType = GL_UNSIGNED_SHORT;
}
- else if (trb->TexImage->TexFormat->MesaFormat == MESA_FORMAT_Z32) {
- trb->Base._ActualFormat = GL_DEPTH_COMPONENT;
+ else if (trb->TexImage->TexFormat == MESA_FORMAT_Z32) {
+ trb->Base.Format = MESA_FORMAT_Z32;
trb->Base.DataType = GL_UNSIGNED_INT;
}
else {
- trb->Base._ActualFormat = trb->TexImage->InternalFormat;
+ trb->Base.Format = trb->TexImage->TexFormat;
trb->Base.DataType = CHAN_TYPE;
}
- trb->Base._BaseFormat = trb->TexImage->TexFormat->BaseFormat;
-#if 0
- /* fix/avoid this assertion someday */
- ASSERT(trb->Base._BaseFormat == GL_RGB ||
- trb->Base._BaseFormat == GL_RGBA ||
- trb->Base._BaseFormat == GL_DEPTH_COMPONENT);
-#endif
trb->Base.Data = trb->TexImage->Data;
-
- trb->Base.RedBits = trb->TexImage->TexFormat->RedBits;
- trb->Base.GreenBits = trb->TexImage->TexFormat->GreenBits;
- trb->Base.BlueBits = trb->TexImage->TexFormat->BlueBits;
- trb->Base.AlphaBits = trb->TexImage->TexFormat->AlphaBits;
- trb->Base.DepthBits = trb->TexImage->TexFormat->DepthBits;
- trb->Base.StencilBits = trb->TexImage->TexFormat->StencilBits;
+ trb->Base._BaseFormat = _mesa_base_fbo_format(ctx, trb->Base.InternalFormat);
}
diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index 7da9e84b24a..8ee378e6670 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -62,7 +62,8 @@
#include "mipmap.h"
#include "imports.h"
#include "texcompress.h"
-#include "texformat.h"
+#include "texcompress_fxt1.h"
+#include "texcompress_s3tc.h"
#include "teximage.h"
#include "texstore.h"
#include "enums.h"
@@ -75,6 +76,12 @@ enum {
/**
+ * Texture image storage function.
+ */
+typedef GLboolean (*StoreTexImageFunc)(TEXSTORE_PARAMS);
+
+
+/**
* Return GL_TRUE if the given image format is one that be converted
* to another format by swizzling.
*/
@@ -431,8 +438,8 @@ make_temp_float_image(GLcontext *ctx, GLuint dims,
else {
/* no convolution */
const GLint components = _mesa_components_in_format(logicalBaseFormat);
- const GLint srcStride = _mesa_image_row_stride(srcPacking,
- srcWidth, srcFormat, srcType);
+ const GLint srcStride =
+ _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
GLfloat *dst;
GLint img, row;
@@ -596,14 +603,13 @@ _mesa_make_temp_chan_image(GLcontext *ctx, GLuint dims,
dst = tempImage;
for (img = 0; img < srcDepth; img++) {
- const GLint srcStride = _mesa_image_row_stride(srcPacking,
- srcWidth, srcFormat,
- srcType);
- const GLubyte *src
- = (const GLubyte *) _mesa_image_address(dims, srcPacking, srcAddr,
- srcWidth, srcHeight,
- srcFormat, srcType,
- img, 0, 0);
+ const GLint srcStride =
+ _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
+ const GLubyte *src =
+ (const GLubyte *) _mesa_image_address(dims, srcPacking, srcAddr,
+ srcWidth, srcHeight,
+ srcFormat, srcType,
+ img, 0, 0);
for (row = 0; row < srcHeight; row++) {
_mesa_unpack_color_span_chan(ctx, srcWidth, logicalBaseFormat, dst,
srcFormat, srcType, src, srcPacking,
@@ -928,7 +934,7 @@ _mesa_swizzle_ubyte_image(GLcontext *ctx,
static void
memcpy_texture(GLcontext *ctx,
GLuint dimensions,
- const struct gl_texture_format *dstFormat,
+ gl_format dstFormat,
GLvoid *dstAddr,
GLint dstXoffset, GLint dstYoffset, GLint dstZoffset,
GLint dstRowStride,
@@ -944,7 +950,8 @@ memcpy_texture(GLcontext *ctx,
srcWidth, srcHeight, srcFormat, srcType);
const GLubyte *srcImage = (const GLubyte *) _mesa_image_address(dimensions,
srcPacking, srcAddr, srcWidth, srcHeight, srcFormat, srcType, 0, 0, 0);
- const GLint bytesPerRow = srcWidth * dstFormat->TexelBytes;
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLint bytesPerRow = srcWidth * texelBytes;
#if 0
/* XXX update/re-enable for dstImageOffsets array */
@@ -953,7 +960,7 @@ memcpy_texture(GLcontext *ctx,
GLubyte *dstImage = (GLubyte *) dstAddr
+ dstZoffset * dstImageStride
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
if (dstRowStride == srcRowStride &&
dstRowStride == bytesPerRow &&
@@ -984,9 +991,9 @@ memcpy_texture(GLcontext *ctx,
for (img = 0; img < srcDepth; img++) {
const GLubyte *srcRow = srcImage;
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
ctx->Driver.TextureMemCpy(dstRow, srcRow, bytesPerRow);
dstRow += dstRowStride;
@@ -999,38 +1006,23 @@ memcpy_texture(GLcontext *ctx,
/**
- * Store an image in any of the formats:
- * _mesa_texformat_rgba
- * _mesa_texformat_rgb
- * _mesa_texformat_alpha
- * _mesa_texformat_luminance
- * _mesa_texformat_luminance_alpha
- * _mesa_texformat_intensity
- *
+ * Store a 32-bit integer depth component texture image.
*/
-GLboolean
-_mesa_texstore_rgba(TEXSTORE_PARAMS)
+static GLboolean
+_mesa_texstore_z32(TEXSTORE_PARAMS)
{
- const GLint components = _mesa_components_in_format(baseInternalFormat);
-
- ASSERT(dstFormat == &_mesa_texformat_rgba ||
- dstFormat == &_mesa_texformat_rgb ||
- dstFormat == &_mesa_texformat_alpha ||
- dstFormat == &_mesa_texformat_luminance ||
- dstFormat == &_mesa_texformat_luminance_alpha ||
- dstFormat == &_mesa_texformat_intensity);
- ASSERT(baseInternalFormat == GL_RGBA ||
- baseInternalFormat == GL_RGB ||
- baseInternalFormat == GL_ALPHA ||
- baseInternalFormat == GL_LUMINANCE ||
- baseInternalFormat == GL_LUMINANCE_ALPHA ||
- baseInternalFormat == GL_INTENSITY);
- ASSERT(dstFormat->TexelBytes == components * sizeof(GLchan));
+ const GLuint depthScale = 0xffffffff;
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ (void) dims;
+ ASSERT(dstFormat == MESA_FORMAT_Z32);
+ ASSERT(texelBytes == sizeof(GLuint));
- if (!ctx->_ImageTransferState &&
+ if (ctx->Pixel.DepthScale == 1.0f &&
+ ctx->Pixel.DepthBias == 0.0f &&
!srcPacking->SwapBytes &&
- baseInternalFormat == srcFormat &&
- srcType == CHAN_TYPE) {
+ baseInternalFormat == GL_DEPTH_COMPONENT &&
+ srcFormat == GL_DEPTH_COMPONENT &&
+ srcType == GL_UNSIGNED_INT) {
/* simple memcpy path */
memcpy_texture(ctx, dims,
dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
@@ -1039,154 +1031,48 @@ _mesa_texstore_rgba(TEXSTORE_PARAMS)
srcWidth, srcHeight, srcDepth, srcFormat, srcType,
srcAddr, srcPacking);
}
- else if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- dstFormat == &_mesa_texformat_rgb &&
- srcFormat == GL_RGBA &&
- srcType == CHAN_TYPE) {
- /* extract RGB from RGBA */
- GLint img, row, col;
- for (img = 0; img < srcDepth; img++) {
- GLchan *dstImage = (GLchan *)
- ((GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes);
-
- const GLint srcRowStride = _mesa_image_row_stride(srcPacking,
- srcWidth, srcFormat, srcType);
- GLchan *srcRow = (GLchan *) _mesa_image_address(dims, srcPacking,
- srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
- GLchan *dstRow = dstImage;
- for (row = 0; row < srcHeight; row++) {
- for (col = 0; col < srcWidth; col++) {
- dstRow[col * 3 + RCOMP] = srcRow[col * 4 + RCOMP];
- dstRow[col * 3 + GCOMP] = srcRow[col * 4 + GCOMP];
- dstRow[col * 3 + BCOMP] = srcRow[col * 4 + BCOMP];
- }
- dstRow += dstRowStride / sizeof(GLchan);
- srcRow = (GLchan *) ((GLubyte *) srcRow + srcRowStride);
- }
- }
- }
- else if (!ctx->_ImageTransferState &&
- CHAN_TYPE == GL_UNSIGNED_BYTE &&
- (srcType == GL_UNSIGNED_BYTE ||
- srcType == GL_UNSIGNED_INT_8_8_8_8 ||
- srcType == GL_UNSIGNED_INT_8_8_8_8_REV) &&
- can_swizzle(baseInternalFormat) &&
- can_swizzle(srcFormat)) {
-
- const GLubyte *dstmap;
- GLuint components;
-
- /* dstmap - how to swizzle from RGBA to dst format:
- */
- if (dstFormat == &_mesa_texformat_rgba) {
- dstmap = mappings[IDX_RGBA].from_rgba;
- components = 4;
- }
- else if (dstFormat == &_mesa_texformat_rgb) {
- dstmap = mappings[IDX_RGB].from_rgba;
- components = 3;
- }
- else if (dstFormat == &_mesa_texformat_alpha) {
- dstmap = mappings[IDX_ALPHA].from_rgba;
- components = 1;
- }
- else if (dstFormat == &_mesa_texformat_luminance) {
- dstmap = mappings[IDX_LUMINANCE].from_rgba;
- components = 1;
- }
- else if (dstFormat == &_mesa_texformat_luminance_alpha) {
- dstmap = mappings[IDX_LUMINANCE_ALPHA].from_rgba;
- components = 2;
- }
- else if (dstFormat == &_mesa_texformat_intensity) {
- dstmap = mappings[IDX_INTENSITY].from_rgba;
- components = 1;
- }
- else {
- _mesa_problem(ctx, "Unexpected dstFormat in _mesa_texstore_rgba");
- return GL_FALSE;
- }
-
- _mesa_swizzle_ubyte_image(ctx, dims,
- srcFormat,
- srcType,
- baseInternalFormat,
- dstmap, components,
- dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride, dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcAddr,
- srcPacking);
- }
else {
/* general path */
- const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
- baseInternalFormat,
- dstFormat->BaseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking);
- const GLchan *src = tempImage;
- GLint bytesPerRow;
GLint img, row;
- if (!tempImage)
- return GL_FALSE;
- _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
- bytesPerRow = srcWidth * components * sizeof(GLchan);
for (img = 0; img < srcDepth; img++) {
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
- _mesa_memcpy(dstRow, src, bytesPerRow);
+ const GLvoid *src = _mesa_image_address(dims, srcPacking,
+ srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
+ _mesa_unpack_depth_span(ctx, srcWidth,
+ GL_UNSIGNED_INT, (GLuint *) dstRow,
+ depthScale, srcType, src, srcPacking);
dstRow += dstRowStride;
- src += srcWidth * components;
}
}
-
- _mesa_free((void *) tempImage);
}
return GL_TRUE;
}
/**
- * Store a 32-bit integer depth component texture image.
+ * Store a 24-bit integer depth component texture image.
*/
-GLboolean
-_mesa_texstore_z32(TEXSTORE_PARAMS)
+static GLboolean
+_mesa_texstore_x8_z24(TEXSTORE_PARAMS)
{
- const GLuint depthScale = 0xffffffff;
+ const GLuint depthScale = 0xffffff;
+ const GLuint texelBytes = 4;
+
(void) dims;
- ASSERT(dstFormat == &_mesa_texformat_z32);
- ASSERT(dstFormat->TexelBytes == sizeof(GLuint));
+ ASSERT(dstFormat == MESA_FORMAT_X8_Z24);
- if (ctx->Pixel.DepthScale == 1.0f &&
- ctx->Pixel.DepthBias == 0.0f &&
- !srcPacking->SwapBytes &&
- baseInternalFormat == GL_DEPTH_COMPONENT &&
- srcFormat == GL_DEPTH_COMPONENT &&
- srcType == GL_UNSIGNED_INT) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else {
+ {
/* general path */
GLint img, row;
for (img = 0; img < srcDepth; img++) {
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
const GLvoid *src = _mesa_image_address(dims, srcPacking,
srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
@@ -1200,18 +1086,20 @@ _mesa_texstore_z32(TEXSTORE_PARAMS)
return GL_TRUE;
}
+
#define STRIDE_3D 0
/**
* Store a 16-bit integer depth component texture image.
*/
-GLboolean
+static GLboolean
_mesa_texstore_z16(TEXSTORE_PARAMS)
{
const GLuint depthScale = 0xffff;
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
(void) dims;
- ASSERT(dstFormat == &_mesa_texformat_z16);
- ASSERT(dstFormat->TexelBytes == sizeof(GLushort));
+ ASSERT(dstFormat == MESA_FORMAT_Z16);
+ ASSERT(texelBytes == sizeof(GLushort));
if (ctx->Pixel.DepthScale == 1.0f &&
ctx->Pixel.DepthBias == 0.0f &&
@@ -1232,9 +1120,9 @@ _mesa_texstore_z16(TEXSTORE_PARAMS)
GLint img, row;
for (img = 0; img < srcDepth; img++) {
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
const GLvoid *src = _mesa_image_address(dims, srcPacking,
srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
@@ -1253,16 +1141,19 @@ _mesa_texstore_z16(TEXSTORE_PARAMS)
/**
* Store an rgb565 or rgb565_rev texture image.
*/
-GLboolean
+static GLboolean
_mesa_texstore_rgb565(TEXSTORE_PARAMS)
{
- ASSERT(dstFormat == &_mesa_texformat_rgb565 ||
- dstFormat == &_mesa_texformat_rgb565_rev);
- ASSERT(dstFormat->TexelBytes == 2);
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_RGB565 ||
+ dstFormat == MESA_FORMAT_RGB565_REV);
+ ASSERT(texelBytes == 2);
if (!ctx->_ImageTransferState &&
!srcPacking->SwapBytes &&
- dstFormat == &_mesa_texformat_rgb565 &&
+ dstFormat == MESA_FORMAT_RGB565 &&
baseInternalFormat == GL_RGB &&
srcFormat == GL_RGB &&
srcType == GL_UNSIGNED_SHORT_5_6_5) {
@@ -1281,20 +1172,20 @@ _mesa_texstore_rgb565(TEXSTORE_PARAMS)
srcType == GL_UNSIGNED_BYTE &&
dims == 2) {
/* do optimized tex store */
- const GLint srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth,
- srcFormat, srcType);
+ const GLint srcRowStride =
+ _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
const GLubyte *src = (const GLubyte *)
_mesa_image_address(dims, srcPacking, srcAddr, srcWidth, srcHeight,
srcFormat, srcType, 0, 0, 0);
GLubyte *dst = (GLubyte *) dstAddr
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
GLint row, col;
for (row = 0; row < srcHeight; row++) {
const GLubyte *srcUB = (const GLubyte *) src;
GLushort *dstUS = (GLushort *) dst;
/* check for byteswapped format */
- if (dstFormat == &_mesa_texformat_rgb565) {
+ if (dstFormat == MESA_FORMAT_RGB565) {
for (col = 0; col < srcWidth; col++) {
dstUS[col] = PACK_COLOR_565( srcUB[0], srcUB[1], srcUB[2] );
srcUB += 3;
@@ -1314,7 +1205,7 @@ _mesa_texstore_rgb565(TEXSTORE_PARAMS)
/* general path */
const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
baseInternalFormat,
- dstFormat->BaseFormat,
+ baseFormat,
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
srcPacking);
@@ -1325,13 +1216,13 @@ _mesa_texstore_rgb565(TEXSTORE_PARAMS)
_mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
for (img = 0; img < srcDepth; img++) {
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
GLushort *dstUS = (GLushort *) dstRow;
/* check for byteswapped format */
- if (dstFormat == &_mesa_texformat_rgb565) {
+ if (dstFormat == MESA_FORMAT_RGB565) {
for (col = 0; col < srcWidth; col++) {
dstUS[col] = PACK_COLOR_565( CHAN_TO_UBYTE(src[RCOMP]),
CHAN_TO_UBYTE(src[GCOMP]),
@@ -1359,18 +1250,20 @@ _mesa_texstore_rgb565(TEXSTORE_PARAMS)
/**
* Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
*/
-GLboolean
+static GLboolean
_mesa_texstore_rgba8888(TEXSTORE_PARAMS)
{
const GLboolean littleEndian = _mesa_little_endian();
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
- ASSERT(dstFormat == &_mesa_texformat_rgba8888 ||
- dstFormat == &_mesa_texformat_rgba8888_rev);
- ASSERT(dstFormat->TexelBytes == 4);
+ ASSERT(dstFormat == MESA_FORMAT_RGBA8888 ||
+ dstFormat == MESA_FORMAT_RGBA8888_REV);
+ ASSERT(texelBytes == 4);
if (!ctx->_ImageTransferState &&
!srcPacking->SwapBytes &&
- dstFormat == &_mesa_texformat_rgba8888 &&
+ dstFormat == MESA_FORMAT_RGBA8888 &&
baseInternalFormat == GL_RGBA &&
((srcFormat == GL_RGBA && srcType == GL_UNSIGNED_INT_8_8_8_8) ||
(srcFormat == GL_RGBA && srcType == GL_UNSIGNED_BYTE && !littleEndian) ||
@@ -1386,7 +1279,7 @@ _mesa_texstore_rgba8888(TEXSTORE_PARAMS)
}
else if (!ctx->_ImageTransferState &&
!srcPacking->SwapBytes &&
- dstFormat == &_mesa_texformat_rgba8888_rev &&
+ dstFormat == MESA_FORMAT_RGBA8888_REV &&
baseInternalFormat == GL_RGBA &&
((srcFormat == GL_RGBA && srcType == GL_UNSIGNED_INT_8_8_8_8_REV) ||
(srcFormat == GL_RGBA && srcType == GL_UNSIGNED_BYTE && littleEndian) ||
@@ -1411,8 +1304,8 @@ _mesa_texstore_rgba8888(TEXSTORE_PARAMS)
/* dstmap - how to swizzle from RGBA to dst format:
*/
- if ((littleEndian && dstFormat == &_mesa_texformat_rgba8888) ||
- (!littleEndian && dstFormat == &_mesa_texformat_rgba8888_rev)) {
+ if ((littleEndian && dstFormat == MESA_FORMAT_RGBA8888) ||
+ (!littleEndian && dstFormat == MESA_FORMAT_RGBA8888_REV)) {
dstmap[3] = 0;
dstmap[2] = 1;
dstmap[1] = 2;
@@ -1439,7 +1332,7 @@ _mesa_texstore_rgba8888(TEXSTORE_PARAMS)
/* general path */
const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
baseInternalFormat,
- dstFormat->BaseFormat,
+ baseFormat,
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
srcPacking);
@@ -1450,12 +1343,12 @@ _mesa_texstore_rgba8888(TEXSTORE_PARAMS)
_mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
for (img = 0; img < srcDepth; img++) {
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
GLuint *dstUI = (GLuint *) dstRow;
- if (dstFormat == &_mesa_texformat_rgba8888) {
+ if (dstFormat == MESA_FORMAT_RGBA8888) {
for (col = 0; col < srcWidth; col++) {
dstUI[col] = PACK_COLOR_8888( CHAN_TO_UBYTE(src[RCOMP]),
CHAN_TO_UBYTE(src[GCOMP]),
@@ -1482,18 +1375,22 @@ _mesa_texstore_rgba8888(TEXSTORE_PARAMS)
}
-GLboolean
+static GLboolean
_mesa_texstore_argb8888(TEXSTORE_PARAMS)
{
const GLboolean littleEndian = _mesa_little_endian();
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
- ASSERT(dstFormat == &_mesa_texformat_argb8888 ||
- dstFormat == &_mesa_texformat_argb8888_rev);
- ASSERT(dstFormat->TexelBytes == 4);
+ ASSERT(dstFormat == MESA_FORMAT_ARGB8888 ||
+ dstFormat == MESA_FORMAT_ARGB8888_REV ||
+ dstFormat == MESA_FORMAT_XRGB8888);
+ ASSERT(texelBytes == 4);
if (!ctx->_ImageTransferState &&
!srcPacking->SwapBytes &&
- dstFormat == &_mesa_texformat_argb8888 &&
+ (dstFormat == MESA_FORMAT_ARGB8888 ||
+ dstFormat == MESA_FORMAT_XRGB8888) &&
baseInternalFormat == GL_RGBA &&
srcFormat == GL_BGRA &&
((srcType == GL_UNSIGNED_BYTE && littleEndian) ||
@@ -1508,7 +1405,7 @@ _mesa_texstore_argb8888(TEXSTORE_PARAMS)
}
else if (!ctx->_ImageTransferState &&
!srcPacking->SwapBytes &&
- dstFormat == &_mesa_texformat_argb8888_rev &&
+ dstFormat == MESA_FORMAT_ARGB8888_REV &&
baseInternalFormat == GL_RGBA &&
srcFormat == GL_BGRA &&
((srcType == GL_UNSIGNED_BYTE && !littleEndian) ||
@@ -1523,21 +1420,22 @@ _mesa_texstore_argb8888(TEXSTORE_PARAMS)
}
else if (!ctx->_ImageTransferState &&
!srcPacking->SwapBytes &&
- dstFormat == &_mesa_texformat_argb8888 &&
+ (dstFormat == MESA_FORMAT_ARGB8888 ||
+ dstFormat == MESA_FORMAT_XRGB8888) &&
srcFormat == GL_RGB &&
(baseInternalFormat == GL_RGBA ||
baseInternalFormat == GL_RGB) &&
srcType == GL_UNSIGNED_BYTE) {
int img, row, col;
for (img = 0; img < srcDepth; img++) {
- const GLint srcRowStride = _mesa_image_row_stride(srcPacking,
- srcWidth, srcFormat, srcType);
+ const GLint srcRowStride =
+ _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
GLuint *d4 = (GLuint *) dstRow;
for (col = 0; col < srcWidth; col++) {
@@ -1553,7 +1451,7 @@ _mesa_texstore_argb8888(TEXSTORE_PARAMS)
}
else if (!ctx->_ImageTransferState &&
!srcPacking->SwapBytes &&
- dstFormat == &_mesa_texformat_argb8888 &&
+ dstFormat == MESA_FORMAT_ARGB8888 &&
srcFormat == GL_RGBA &&
baseInternalFormat == GL_RGBA &&
srcType == GL_UNSIGNED_BYTE) {
@@ -1566,14 +1464,14 @@ _mesa_texstore_argb8888(TEXSTORE_PARAMS)
* Strangely the same isn't required for the RGB path, above.
*/
for (img = 0; img < srcDepth; img++) {
- const GLint srcRowStride = _mesa_image_row_stride(srcPacking,
- srcWidth, srcFormat, srcType);
+ const GLint srcRowStride =
+ _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
GLuint *d4 = (GLuint *) dstRow;
for (col = 0; col < srcWidth; col++) {
@@ -1598,16 +1496,18 @@ _mesa_texstore_argb8888(TEXSTORE_PARAMS)
/* dstmap - how to swizzle from RGBA to dst format:
*/
- if ((littleEndian && dstFormat == &_mesa_texformat_argb8888) ||
- (!littleEndian && dstFormat == &_mesa_texformat_argb8888_rev)) {
+ if ((littleEndian && dstFormat == MESA_FORMAT_ARGB8888) ||
+ (littleEndian && dstFormat == MESA_FORMAT_XRGB8888) ||
+ (!littleEndian && dstFormat == MESA_FORMAT_ARGB8888_REV)) {
dstmap[3] = 3; /* alpha */
dstmap[2] = 0; /* red */
dstmap[1] = 1; /* green */
dstmap[0] = 2; /* blue */
}
else {
- assert((littleEndian && dstFormat == &_mesa_texformat_argb8888_rev) ||
- (!littleEndian && dstFormat == &_mesa_texformat_argb8888));
+ assert((littleEndian && dstFormat == MESA_FORMAT_ARGB8888_REV) ||
+ (!littleEndian && dstFormat == MESA_FORMAT_ARGB8888) ||
+ (!littleEndian && dstFormat == MESA_FORMAT_XRGB8888));
dstmap[3] = 2;
dstmap[2] = 1;
dstmap[1] = 0;
@@ -1630,7 +1530,7 @@ _mesa_texstore_argb8888(TEXSTORE_PARAMS)
/* general path */
const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
baseInternalFormat,
- dstFormat->BaseFormat,
+ baseFormat,
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
srcPacking);
@@ -1641,12 +1541,12 @@ _mesa_texstore_argb8888(TEXSTORE_PARAMS)
_mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
for (img = 0; img < srcDepth; img++) {
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
GLuint *dstUI = (GLuint *) dstRow;
- if (dstFormat == &_mesa_texformat_argb8888) {
+ if (dstFormat == MESA_FORMAT_ARGB8888) {
for (col = 0; col < srcWidth; col++) {
dstUI[col] = PACK_COLOR_8888( CHAN_TO_UBYTE(src[ACOMP]),
CHAN_TO_UBYTE(src[RCOMP]),
@@ -1655,6 +1555,15 @@ _mesa_texstore_argb8888(TEXSTORE_PARAMS)
src += 4;
}
}
+ else if (dstFormat == MESA_FORMAT_XRGB8888) {
+ for (col = 0; col < srcWidth; col++) {
+ dstUI[col] = PACK_COLOR_8888( 0xff,
+ CHAN_TO_UBYTE(src[RCOMP]),
+ CHAN_TO_UBYTE(src[GCOMP]),
+ CHAN_TO_UBYTE(src[BCOMP]) );
+ src += 4;
+ }
+ }
else {
for (col = 0; col < srcWidth; col++) {
dstUI[col] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src[ACOMP]),
@@ -1673,13 +1582,15 @@ _mesa_texstore_argb8888(TEXSTORE_PARAMS)
}
-GLboolean
+static GLboolean
_mesa_texstore_rgb888(TEXSTORE_PARAMS)
{
const GLboolean littleEndian = _mesa_little_endian();
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
- ASSERT(dstFormat == &_mesa_texformat_rgb888);
- ASSERT(dstFormat->TexelBytes == 3);
+ ASSERT(dstFormat == MESA_FORMAT_RGB888);
+ ASSERT(texelBytes == 3);
if (!ctx->_ImageTransferState &&
!srcPacking->SwapBytes &&
@@ -1702,14 +1613,14 @@ _mesa_texstore_rgb888(TEXSTORE_PARAMS)
/* extract RGB from RGBA */
GLint img, row, col;
for (img = 0; img < srcDepth; img++) {
- const GLint srcRowStride = _mesa_image_row_stride(srcPacking,
- srcWidth, srcFormat, srcType);
+ const GLint srcRowStride =
+ _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
for (col = 0; col < srcWidth; col++) {
dstRow[col * 3 + 0] = srcRow[col * 4 + BCOMP];
@@ -1749,7 +1660,7 @@ _mesa_texstore_rgb888(TEXSTORE_PARAMS)
/* general path */
const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
baseInternalFormat,
- dstFormat->BaseFormat,
+ baseFormat,
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
srcPacking);
@@ -1760,9 +1671,9 @@ _mesa_texstore_rgb888(TEXSTORE_PARAMS)
_mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
for (img = 0; img < srcDepth; img++) {
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
#if 0
if (littleEndian) {
@@ -1798,13 +1709,15 @@ _mesa_texstore_rgb888(TEXSTORE_PARAMS)
}
-GLboolean
+static GLboolean
_mesa_texstore_bgr888(TEXSTORE_PARAMS)
{
const GLboolean littleEndian = _mesa_little_endian();
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
- ASSERT(dstFormat == &_mesa_texformat_bgr888);
- ASSERT(dstFormat->TexelBytes == 3);
+ ASSERT(dstFormat == MESA_FORMAT_BGR888);
+ ASSERT(texelBytes == 3);
if (!ctx->_ImageTransferState &&
!srcPacking->SwapBytes &&
@@ -1827,14 +1740,14 @@ _mesa_texstore_bgr888(TEXSTORE_PARAMS)
/* extract BGR from RGBA */
int img, row, col;
for (img = 0; img < srcDepth; img++) {
- const GLint srcRowStride = _mesa_image_row_stride(srcPacking,
- srcWidth, srcFormat, srcType);
+ const GLint srcRowStride =
+ _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
for (col = 0; col < srcWidth; col++) {
dstRow[col * 3 + 0] = srcRow[col * 4 + RCOMP];
@@ -1874,7 +1787,7 @@ _mesa_texstore_bgr888(TEXSTORE_PARAMS)
/* general path */
const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
baseInternalFormat,
- dstFormat->BaseFormat,
+ baseFormat,
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
srcPacking);
@@ -1885,9 +1798,9 @@ _mesa_texstore_bgr888(TEXSTORE_PARAMS)
_mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
for (img = 0; img < srcDepth; img++) {
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
for (col = 0; col < srcWidth; col++) {
dstRow[col * 3 + 0] = CHAN_TO_UBYTE(src[RCOMP]);
@@ -1903,71 +1816,20 @@ _mesa_texstore_bgr888(TEXSTORE_PARAMS)
return GL_TRUE;
}
-GLboolean
-_mesa_texstore_rgba4444(TEXSTORE_PARAMS)
-{
- ASSERT(dstFormat == &_mesa_texformat_rgba4444);
- ASSERT(dstFormat->TexelBytes == 2);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- dstFormat == &_mesa_texformat_rgba4444 &&
- baseInternalFormat == GL_RGBA &&
- srcFormat == GL_RGBA &&
- srcType == GL_UNSIGNED_SHORT_4_4_4_4){
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else {
- /* general path */
- const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
- baseInternalFormat,
- dstFormat->BaseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking);
- const GLchan *src = tempImage;
- GLint img, row, col;
- if (!tempImage)
- return GL_FALSE;
- _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLushort *dstUS = (GLushort *) dstRow;
- for (col = 0; col < srcWidth; col++) {
- dstUS[col] = PACK_COLOR_4444( CHAN_TO_UBYTE(src[RCOMP]),
- CHAN_TO_UBYTE(src[GCOMP]),
- CHAN_TO_UBYTE(src[BCOMP]),
- CHAN_TO_UBYTE(src[ACOMP]) );
- src += 4;
- }
- dstRow += dstRowStride;
- }
- }
- _mesa_free((void *) tempImage);
- }
- return GL_TRUE;
-}
-GLboolean
+static GLboolean
_mesa_texstore_argb4444(TEXSTORE_PARAMS)
{
- ASSERT(dstFormat == &_mesa_texformat_argb4444 ||
- dstFormat == &_mesa_texformat_argb4444_rev);
- ASSERT(dstFormat->TexelBytes == 2);
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_ARGB4444 ||
+ dstFormat == MESA_FORMAT_ARGB4444_REV);
+ ASSERT(texelBytes == 2);
if (!ctx->_ImageTransferState &&
!srcPacking->SwapBytes &&
- dstFormat == &_mesa_texformat_argb4444 &&
+ dstFormat == MESA_FORMAT_ARGB4444 &&
baseInternalFormat == GL_RGBA &&
srcFormat == GL_BGRA &&
srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV) {
@@ -1983,7 +1845,7 @@ _mesa_texstore_argb4444(TEXSTORE_PARAMS)
/* general path */
const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
baseInternalFormat,
- dstFormat->BaseFormat,
+ baseFormat,
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
srcPacking);
@@ -1994,12 +1856,12 @@ _mesa_texstore_argb4444(TEXSTORE_PARAMS)
_mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
for (img = 0; img < srcDepth; img++) {
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
GLushort *dstUS = (GLushort *) dstRow;
- if (dstFormat == &_mesa_texformat_argb4444) {
+ if (dstFormat == MESA_FORMAT_ARGB4444) {
for (col = 0; col < srcWidth; col++) {
dstUS[col] = PACK_COLOR_4444( CHAN_TO_UBYTE(src[ACOMP]),
CHAN_TO_UBYTE(src[RCOMP]),
@@ -2025,15 +1887,18 @@ _mesa_texstore_argb4444(TEXSTORE_PARAMS)
return GL_TRUE;
}
-GLboolean
+static GLboolean
_mesa_texstore_rgba5551(TEXSTORE_PARAMS)
{
- ASSERT(dstFormat == &_mesa_texformat_rgba5551);
- ASSERT(dstFormat->TexelBytes == 2);
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_RGBA5551);
+ ASSERT(texelBytes == 2);
if (!ctx->_ImageTransferState &&
!srcPacking->SwapBytes &&
- dstFormat == &_mesa_texformat_rgba5551 &&
+ dstFormat == MESA_FORMAT_RGBA5551 &&
baseInternalFormat == GL_RGBA &&
srcFormat == GL_RGBA &&
srcType == GL_UNSIGNED_SHORT_5_5_5_1) {
@@ -2049,7 +1914,7 @@ _mesa_texstore_rgba5551(TEXSTORE_PARAMS)
/* general path */
const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
baseInternalFormat,
- dstFormat->BaseFormat,
+ baseFormat,
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
srcPacking);
@@ -2060,9 +1925,9 @@ _mesa_texstore_rgba5551(TEXSTORE_PARAMS)
_mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
for (img = 0; img < srcDepth; img++) {
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
GLushort *dstUS = (GLushort *) dstRow;
for (col = 0; col < srcWidth; col++) {
@@ -2080,16 +1945,19 @@ _mesa_texstore_rgba5551(TEXSTORE_PARAMS)
return GL_TRUE;
}
-GLboolean
+static GLboolean
_mesa_texstore_argb1555(TEXSTORE_PARAMS)
{
- ASSERT(dstFormat == &_mesa_texformat_argb1555 ||
- dstFormat == &_mesa_texformat_argb1555_rev);
- ASSERT(dstFormat->TexelBytes == 2);
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_ARGB1555 ||
+ dstFormat == MESA_FORMAT_ARGB1555_REV);
+ ASSERT(texelBytes == 2);
if (!ctx->_ImageTransferState &&
!srcPacking->SwapBytes &&
- dstFormat == &_mesa_texformat_argb1555 &&
+ dstFormat == MESA_FORMAT_ARGB1555 &&
baseInternalFormat == GL_RGBA &&
srcFormat == GL_BGRA &&
srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV) {
@@ -2105,7 +1973,7 @@ _mesa_texstore_argb1555(TEXSTORE_PARAMS)
/* general path */
const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
baseInternalFormat,
- dstFormat->BaseFormat,
+ baseFormat,
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
srcPacking);
@@ -2116,12 +1984,12 @@ _mesa_texstore_argb1555(TEXSTORE_PARAMS)
_mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
for (img = 0; img < srcDepth; img++) {
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
GLushort *dstUS = (GLushort *) dstRow;
- if (dstFormat == &_mesa_texformat_argb1555) {
+ if (dstFormat == MESA_FORMAT_ARGB1555) {
for (col = 0; col < srcWidth; col++) {
dstUS[col] = PACK_COLOR_1555( CHAN_TO_UBYTE(src[ACOMP]),
CHAN_TO_UBYTE(src[RCOMP]),
@@ -2148,18 +2016,20 @@ _mesa_texstore_argb1555(TEXSTORE_PARAMS)
}
-GLboolean
+static GLboolean
_mesa_texstore_al88(TEXSTORE_PARAMS)
{
const GLboolean littleEndian = _mesa_little_endian();
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
- ASSERT(dstFormat == &_mesa_texformat_al88 ||
- dstFormat == &_mesa_texformat_al88_rev);
- ASSERT(dstFormat->TexelBytes == 2);
+ ASSERT(dstFormat == MESA_FORMAT_AL88 ||
+ dstFormat == MESA_FORMAT_AL88_REV);
+ ASSERT(texelBytes == 2);
if (!ctx->_ImageTransferState &&
!srcPacking->SwapBytes &&
- dstFormat == &_mesa_texformat_al88 &&
+ dstFormat == MESA_FORMAT_AL88 &&
baseInternalFormat == GL_LUMINANCE_ALPHA &&
srcFormat == GL_LUMINANCE_ALPHA &&
srcType == GL_UNSIGNED_BYTE &&
@@ -2182,8 +2052,8 @@ _mesa_texstore_al88(TEXSTORE_PARAMS)
/* dstmap - how to swizzle from RGBA to dst format:
*/
- if ((littleEndian && dstFormat == &_mesa_texformat_al88) ||
- (!littleEndian && dstFormat == &_mesa_texformat_al88_rev)) {
+ if ((littleEndian && dstFormat == MESA_FORMAT_AL88) ||
+ (!littleEndian && dstFormat == MESA_FORMAT_AL88_REV)) {
dstmap[0] = 0;
dstmap[1] = 3;
}
@@ -2208,7 +2078,7 @@ _mesa_texstore_al88(TEXSTORE_PARAMS)
/* general path */
const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
baseInternalFormat,
- dstFormat->BaseFormat,
+ baseFormat,
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
srcPacking);
@@ -2219,12 +2089,12 @@ _mesa_texstore_al88(TEXSTORE_PARAMS)
_mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
for (img = 0; img < srcDepth; img++) {
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
GLushort *dstUS = (GLushort *) dstRow;
- if (dstFormat == &_mesa_texformat_al88) {
+ if (dstFormat == MESA_FORMAT_AL88) {
for (col = 0; col < srcWidth; col++) {
/* src[0] is luminance, src[1] is alpha */
dstUS[col] = PACK_COLOR_88( CHAN_TO_UBYTE(src[1]),
@@ -2249,11 +2119,14 @@ _mesa_texstore_al88(TEXSTORE_PARAMS)
}
-GLboolean
+static GLboolean
_mesa_texstore_rgb332(TEXSTORE_PARAMS)
{
- ASSERT(dstFormat == &_mesa_texformat_rgb332);
- ASSERT(dstFormat->TexelBytes == 1);
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_RGB332);
+ ASSERT(texelBytes == 1);
if (!ctx->_ImageTransferState &&
!srcPacking->SwapBytes &&
@@ -2271,7 +2144,7 @@ _mesa_texstore_rgb332(TEXSTORE_PARAMS)
/* general path */
const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
baseInternalFormat,
- dstFormat->BaseFormat,
+ baseFormat,
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
srcPacking);
@@ -2282,9 +2155,9 @@ _mesa_texstore_rgb332(TEXSTORE_PARAMS)
_mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
for (img = 0; img < srcDepth; img++) {
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
for (col = 0; col < srcWidth; col++) {
dstRow[col] = PACK_COLOR_332( CHAN_TO_UBYTE(src[RCOMP]),
@@ -2304,13 +2177,16 @@ _mesa_texstore_rgb332(TEXSTORE_PARAMS)
/**
* Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
*/
-GLboolean
+static GLboolean
_mesa_texstore_a8(TEXSTORE_PARAMS)
{
- ASSERT(dstFormat == &_mesa_texformat_a8 ||
- dstFormat == &_mesa_texformat_l8 ||
- dstFormat == &_mesa_texformat_i8);
- ASSERT(dstFormat->TexelBytes == 1);
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_A8 ||
+ dstFormat == MESA_FORMAT_L8 ||
+ dstFormat == MESA_FORMAT_I8);
+ ASSERT(texelBytes == 1);
if (!ctx->_ImageTransferState &&
!srcPacking->SwapBytes &&
@@ -2333,7 +2209,7 @@ _mesa_texstore_a8(TEXSTORE_PARAMS)
/* dstmap - how to swizzle from RGBA to dst format:
*/
- if (dstFormat == &_mesa_texformat_a8) {
+ if (dstFormat == MESA_FORMAT_A8) {
dstmap[0] = 3;
}
else {
@@ -2357,7 +2233,7 @@ _mesa_texstore_a8(TEXSTORE_PARAMS)
/* general path */
const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
baseInternalFormat,
- dstFormat->BaseFormat,
+ baseFormat,
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
srcPacking);
@@ -2368,9 +2244,9 @@ _mesa_texstore_a8(TEXSTORE_PARAMS)
_mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
for (img = 0; img < srcDepth; img++) {
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
for (col = 0; col < srcWidth; col++) {
dstRow[col] = CHAN_TO_UBYTE(src[col]);
@@ -2386,12 +2262,14 @@ _mesa_texstore_a8(TEXSTORE_PARAMS)
-GLboolean
+static GLboolean
_mesa_texstore_ci8(TEXSTORE_PARAMS)
{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+
(void) dims; (void) baseInternalFormat;
- ASSERT(dstFormat == &_mesa_texformat_ci8);
- ASSERT(dstFormat->TexelBytes == 1);
+ ASSERT(dstFormat == MESA_FORMAT_CI8);
+ ASSERT(texelBytes == 1);
ASSERT(baseInternalFormat == GL_COLOR_INDEX);
if (!ctx->_ImageTransferState &&
@@ -2411,9 +2289,9 @@ _mesa_texstore_ci8(TEXSTORE_PARAMS)
GLint img, row;
for (img = 0; img < srcDepth; img++) {
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
const GLvoid *src = _mesa_image_address(dims, srcPacking,
srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
@@ -2429,17 +2307,19 @@ _mesa_texstore_ci8(TEXSTORE_PARAMS)
/**
- * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_rev.
+ * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
*/
-GLboolean
+static GLboolean
_mesa_texstore_ycbcr(TEXSTORE_PARAMS)
{
const GLboolean littleEndian = _mesa_little_endian();
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+
(void) ctx; (void) dims; (void) baseInternalFormat;
- ASSERT((dstFormat == &_mesa_texformat_ycbcr) ||
- (dstFormat == &_mesa_texformat_ycbcr_rev));
- ASSERT(dstFormat->TexelBytes == 2);
+ ASSERT((dstFormat == MESA_FORMAT_YCBCR) ||
+ (dstFormat == MESA_FORMAT_YCBCR_REV));
+ ASSERT(texelBytes == 2);
ASSERT(ctx->Extensions.MESA_ycbcr_texture);
ASSERT(srcFormat == GL_YCBCR_MESA);
ASSERT((srcType == GL_UNSIGNED_SHORT_8_8_MESA) ||
@@ -2458,14 +2338,14 @@ _mesa_texstore_ycbcr(TEXSTORE_PARAMS)
/* XXX the logic here _might_ be wrong */
if (srcPacking->SwapBytes ^
(srcType == GL_UNSIGNED_SHORT_8_8_REV_MESA) ^
- (dstFormat == &_mesa_texformat_ycbcr_rev) ^
+ (dstFormat == MESA_FORMAT_YCBCR_REV) ^
!littleEndian) {
GLint img, row;
for (img = 0; img < srcDepth; img++) {
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
_mesa_swap2((GLushort *) dstRow, srcWidth);
dstRow += dstRowStride;
@@ -2475,13 +2355,14 @@ _mesa_texstore_ycbcr(TEXSTORE_PARAMS)
return GL_TRUE;
}
-GLboolean
+static GLboolean
_mesa_texstore_dudv8(TEXSTORE_PARAMS)
{
const GLboolean littleEndian = _mesa_little_endian();
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- ASSERT(dstFormat == &_mesa_texformat_dudv8);
- ASSERT(dstFormat->TexelBytes == 2);
+ ASSERT(dstFormat == MESA_FORMAT_DUDV8);
+ ASSERT(texelBytes == 2);
ASSERT(ctx->Extensions.ATI_envmap_bumpmap);
ASSERT((srcFormat == GL_DU8DV8_ATI) ||
(srcFormat == GL_DUDV_ATI));
@@ -2527,8 +2408,8 @@ _mesa_texstore_dudv8(TEXSTORE_PARAMS)
else {
/* general path - note this is defined for 2d textures only */
const GLint components = _mesa_components_in_format(baseInternalFormat);
- const GLint srcStride = _mesa_image_row_stride(srcPacking,
- srcWidth, srcFormat, srcType);
+ const GLint srcStride = _mesa_image_row_stride(srcPacking, srcWidth,
+ srcFormat, srcType);
GLbyte *tempImage, *dst, *src;
GLint row;
@@ -2554,11 +2435,11 @@ _mesa_texstore_dudv8(TEXSTORE_PARAMS)
src = tempImage;
dst = (GLbyte *) dstAddr
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
- memcpy(dst, src, srcWidth * dstFormat->TexelBytes);
+ memcpy(dst, src, srcWidth * texelBytes);
dst += dstRowStride;
- src += srcWidth * dstFormat->TexelBytes;
+ src += srcWidth * texelBytes;
}
_mesa_free((void *) tempImage);
}
@@ -2568,18 +2449,20 @@ _mesa_texstore_dudv8(TEXSTORE_PARAMS)
/**
* Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or MESA_FORMAT_SIGNED_RGBA8888_REV
*/
-GLboolean
+static GLboolean
_mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS)
{
const GLboolean littleEndian = _mesa_little_endian();
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
- ASSERT(dstFormat == &_mesa_texformat_signed_rgba8888 ||
- dstFormat == &_mesa_texformat_signed_rgba8888_rev);
- ASSERT(dstFormat->TexelBytes == 4);
+ ASSERT(dstFormat == MESA_FORMAT_SIGNED_RGBA8888 ||
+ dstFormat == MESA_FORMAT_SIGNED_RGBA8888_REV);
+ ASSERT(texelBytes == 4);
if (!ctx->_ImageTransferState &&
!srcPacking->SwapBytes &&
- dstFormat == &_mesa_texformat_signed_rgba8888 &&
+ dstFormat == MESA_FORMAT_SIGNED_RGBA8888 &&
baseInternalFormat == GL_RGBA &&
((srcFormat == GL_RGBA && srcType == GL_BYTE && !littleEndian) ||
(srcFormat == GL_ABGR_EXT && srcType == GL_BYTE && littleEndian))) {
@@ -2593,7 +2476,7 @@ _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS)
}
else if (!ctx->_ImageTransferState &&
!srcPacking->SwapBytes &&
- dstFormat == &_mesa_texformat_signed_rgba8888_rev &&
+ dstFormat == MESA_FORMAT_SIGNED_RGBA8888_REV &&
baseInternalFormat == GL_RGBA &&
((srcFormat == GL_RGBA && srcType == GL_BYTE && littleEndian) ||
(srcFormat == GL_ABGR_EXT && srcType == GL_BYTE && !littleEndian))) {
@@ -2614,8 +2497,8 @@ _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS)
/* dstmap - how to swizzle from RGBA to dst format:
*/
- if ((littleEndian && dstFormat == &_mesa_texformat_signed_rgba8888) ||
- (!littleEndian && dstFormat == &_mesa_texformat_signed_rgba8888_rev)) {
+ if ((littleEndian && dstFormat == MESA_FORMAT_SIGNED_RGBA8888) ||
+ (!littleEndian && dstFormat == MESA_FORMAT_SIGNED_RGBA8888_REV)) {
dstmap[3] = 0;
dstmap[2] = 1;
dstmap[1] = 2;
@@ -2642,7 +2525,7 @@ _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS)
/* general path */
const GLfloat *tempImage = make_temp_float_image(ctx, dims,
baseInternalFormat,
- dstFormat->BaseFormat,
+ baseFormat,
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
srcPacking);
@@ -2653,12 +2536,12 @@ _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS)
_mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
for (img = 0; img < srcDepth; img++) {
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
GLuint *dstUI = (GLuint *) dstRow;
- if (dstFormat == &_mesa_texformat_signed_rgba8888) {
+ if (dstFormat == MESA_FORMAT_SIGNED_RGBA8888) {
for (col = 0; col < srcWidth; col++) {
dstUI[col] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow[RCOMP]),
FLOAT_TO_BYTE_TEX(srcRow[GCOMP]),
@@ -2687,7 +2570,7 @@ _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS)
/**
* Store a combined depth/stencil texture image.
*/
-GLboolean
+static GLboolean
_mesa_texstore_z24_s8(TEXSTORE_PARAMS)
{
const GLfloat depthScale = (GLfloat) 0xffffff;
@@ -2696,7 +2579,7 @@ _mesa_texstore_z24_s8(TEXSTORE_PARAMS)
/ sizeof(GLuint);
GLint img, row;
- ASSERT(dstFormat == &_mesa_texformat_z24_s8);
+ ASSERT(dstFormat == MESA_FORMAT_Z24_S8);
ASSERT(srcFormat == GL_DEPTH_STENCIL_EXT || srcFormat == GL_DEPTH_COMPONENT);
ASSERT(srcFormat != GL_DEPTH_STENCIL_EXT || srcType == GL_UNSIGNED_INT_24_8_EXT);
@@ -2788,7 +2671,7 @@ _mesa_texstore_z24_s8(TEXSTORE_PARAMS)
/**
* Store a combined depth/stencil texture image.
*/
-GLboolean
+static GLboolean
_mesa_texstore_s8_z24(TEXSTORE_PARAMS)
{
const GLuint depthScale = 0xffffff;
@@ -2797,7 +2680,7 @@ _mesa_texstore_s8_z24(TEXSTORE_PARAMS)
/ sizeof(GLuint);
GLint img, row;
- ASSERT(dstFormat == &_mesa_texformat_s8_z24);
+ ASSERT(dstFormat == MESA_FORMAT_S8_Z24);
ASSERT(srcFormat == GL_DEPTH_STENCIL_EXT || srcFormat == GL_DEPTH_COMPONENT);
ASSERT(srcFormat != GL_DEPTH_STENCIL_EXT || srcType == GL_UNSIGNED_INT_24_8_EXT);
@@ -2877,24 +2760,26 @@ _mesa_texstore_s8_z24(TEXSTORE_PARAMS)
* _mesa_texformat_luminance_alpha_float32
* _mesa_texformat_intensity_float32
*/
-GLboolean
+static GLboolean
_mesa_texstore_rgba_float32(TEXSTORE_PARAMS)
{
- const GLint components = _mesa_components_in_format(dstFormat->BaseFormat);
-
- ASSERT(dstFormat == &_mesa_texformat_rgba_float32 ||
- dstFormat == &_mesa_texformat_rgb_float32 ||
- dstFormat == &_mesa_texformat_alpha_float32 ||
- dstFormat == &_mesa_texformat_luminance_float32 ||
- dstFormat == &_mesa_texformat_luminance_alpha_float32 ||
- dstFormat == &_mesa_texformat_intensity_float32);
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+ const GLint components = _mesa_components_in_format(baseFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_RGBA_FLOAT32 ||
+ dstFormat == MESA_FORMAT_RGB_FLOAT32 ||
+ dstFormat == MESA_FORMAT_ALPHA_FLOAT32 ||
+ dstFormat == MESA_FORMAT_LUMINANCE_FLOAT32 ||
+ dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32 ||
+ dstFormat == MESA_FORMAT_INTENSITY_FLOAT32);
ASSERT(baseInternalFormat == GL_RGBA ||
baseInternalFormat == GL_RGB ||
baseInternalFormat == GL_ALPHA ||
baseInternalFormat == GL_LUMINANCE ||
baseInternalFormat == GL_LUMINANCE_ALPHA ||
baseInternalFormat == GL_INTENSITY);
- ASSERT(dstFormat->TexelBytes == components * sizeof(GLfloat));
+ ASSERT(texelBytes == components * sizeof(GLfloat));
if (!ctx->_ImageTransferState &&
!srcPacking->SwapBytes &&
@@ -2912,7 +2797,7 @@ _mesa_texstore_rgba_float32(TEXSTORE_PARAMS)
/* general path */
const GLfloat *tempImage = make_temp_float_image(ctx, dims,
baseInternalFormat,
- dstFormat->BaseFormat,
+ baseFormat,
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
srcPacking);
@@ -2925,9 +2810,9 @@ _mesa_texstore_rgba_float32(TEXSTORE_PARAMS)
bytesPerRow = srcWidth * components * sizeof(GLfloat);
for (img = 0; img < srcDepth; img++) {
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
_mesa_memcpy(dstRow, srcRow, bytesPerRow);
dstRow += dstRowStride;
@@ -2944,24 +2829,26 @@ _mesa_texstore_rgba_float32(TEXSTORE_PARAMS)
/**
* As above, but store 16-bit floats.
*/
-GLboolean
+static GLboolean
_mesa_texstore_rgba_float16(TEXSTORE_PARAMS)
{
- const GLint components = _mesa_components_in_format(dstFormat->BaseFormat);
-
- ASSERT(dstFormat == &_mesa_texformat_rgba_float16 ||
- dstFormat == &_mesa_texformat_rgb_float16 ||
- dstFormat == &_mesa_texformat_alpha_float16 ||
- dstFormat == &_mesa_texformat_luminance_float16 ||
- dstFormat == &_mesa_texformat_luminance_alpha_float16 ||
- dstFormat == &_mesa_texformat_intensity_float16);
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+ const GLint components = _mesa_components_in_format(baseFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_RGBA_FLOAT16 ||
+ dstFormat == MESA_FORMAT_RGB_FLOAT16 ||
+ dstFormat == MESA_FORMAT_ALPHA_FLOAT16 ||
+ dstFormat == MESA_FORMAT_LUMINANCE_FLOAT16 ||
+ dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16 ||
+ dstFormat == MESA_FORMAT_INTENSITY_FLOAT16);
ASSERT(baseInternalFormat == GL_RGBA ||
baseInternalFormat == GL_RGB ||
baseInternalFormat == GL_ALPHA ||
baseInternalFormat == GL_LUMINANCE ||
baseInternalFormat == GL_LUMINANCE_ALPHA ||
baseInternalFormat == GL_INTENSITY);
- ASSERT(dstFormat->TexelBytes == components * sizeof(GLhalfARB));
+ ASSERT(texelBytes == components * sizeof(GLhalfARB));
if (!ctx->_ImageTransferState &&
!srcPacking->SwapBytes &&
@@ -2979,7 +2866,7 @@ _mesa_texstore_rgba_float16(TEXSTORE_PARAMS)
/* general path */
const GLfloat *tempImage = make_temp_float_image(ctx, dims,
baseInternalFormat,
- dstFormat->BaseFormat,
+ baseFormat,
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
srcPacking);
@@ -2990,9 +2877,9 @@ _mesa_texstore_rgba_float16(TEXSTORE_PARAMS)
_mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
for (img = 0; img < srcDepth; img++) {
GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
- + dstXoffset * dstFormat->TexelBytes;
+ + dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
GLhalfARB *dstTexel = (GLhalfARB *) dstRow;
GLint i;
@@ -3011,20 +2898,18 @@ _mesa_texstore_rgba_float16(TEXSTORE_PARAMS)
#if FEATURE_EXT_texture_sRGB
-GLboolean
+static GLboolean
_mesa_texstore_srgb8(TEXSTORE_PARAMS)
{
- const struct gl_texture_format *newDstFormat;
- StoreTexImageFunc store;
+ gl_format newDstFormat;
GLboolean k;
- ASSERT(dstFormat == &_mesa_texformat_srgb8);
+ ASSERT(dstFormat == MESA_FORMAT_SRGB8);
/* reuse normal rgb texstore code */
- newDstFormat = &_mesa_texformat_rgb888;
- store = _mesa_texstore_rgb888;
+ newDstFormat = MESA_FORMAT_RGB888;
- k = store(ctx, dims, baseInternalFormat,
+ k = _mesa_texstore_rgb888(ctx, dims, baseInternalFormat,
newDstFormat, dstAddr,
dstXoffset, dstYoffset, dstZoffset,
dstRowStride, dstImageOffsets,
@@ -3035,17 +2920,16 @@ _mesa_texstore_srgb8(TEXSTORE_PARAMS)
}
-GLboolean
+static GLboolean
_mesa_texstore_srgba8(TEXSTORE_PARAMS)
{
- const struct gl_texture_format *newDstFormat;
+ gl_format newDstFormat;
GLboolean k;
- ASSERT(dstFormat == &_mesa_texformat_srgba8);
+ ASSERT(dstFormat == MESA_FORMAT_SRGBA8);
/* reuse normal rgba texstore code */
- newDstFormat = &_mesa_texformat_rgba8888;
-
+ newDstFormat = MESA_FORMAT_RGBA8888;
k = _mesa_texstore_rgba8888(ctx, dims, baseInternalFormat,
newDstFormat, dstAddr,
dstXoffset, dstYoffset, dstZoffset,
@@ -3057,16 +2941,16 @@ _mesa_texstore_srgba8(TEXSTORE_PARAMS)
}
-GLboolean
+static GLboolean
_mesa_texstore_sargb8(TEXSTORE_PARAMS)
{
- const struct gl_texture_format *newDstFormat;
+ gl_format newDstFormat;
GLboolean k;
- ASSERT(dstFormat == &_mesa_texformat_sargb8);
+ ASSERT(dstFormat == MESA_FORMAT_SARGB8);
/* reuse normal rgba texstore code */
- newDstFormat = &_mesa_texformat_argb8888;
+ newDstFormat = MESA_FORMAT_ARGB8888;
k = _mesa_texstore_argb8888(ctx, dims, baseInternalFormat,
newDstFormat, dstAddr,
@@ -3079,15 +2963,15 @@ _mesa_texstore_sargb8(TEXSTORE_PARAMS)
}
-GLboolean
+static GLboolean
_mesa_texstore_sl8(TEXSTORE_PARAMS)
{
- const struct gl_texture_format *newDstFormat;
+ gl_format newDstFormat;
GLboolean k;
- ASSERT(dstFormat == &_mesa_texformat_sl8);
+ ASSERT(dstFormat == MESA_FORMAT_SL8);
- newDstFormat = &_mesa_texformat_l8;
+ newDstFormat = MESA_FORMAT_L8;
/* _mesa_textore_a8 handles luminance8 too */
k = _mesa_texstore_a8(ctx, dims, baseInternalFormat,
@@ -3101,16 +2985,16 @@ _mesa_texstore_sl8(TEXSTORE_PARAMS)
}
-GLboolean
+static GLboolean
_mesa_texstore_sla8(TEXSTORE_PARAMS)
{
- const struct gl_texture_format *newDstFormat;
+ gl_format newDstFormat;
GLboolean k;
- ASSERT(dstFormat == &_mesa_texformat_sla8);
+ ASSERT(dstFormat == MESA_FORMAT_SLA8);
/* reuse normal luminance/alpha texstore code */
- newDstFormat = &_mesa_texformat_al88;
+ newDstFormat = MESA_FORMAT_AL88;
k = _mesa_texstore_al88(ctx, dims, baseInternalFormat,
newDstFormat, dstAddr,
@@ -3125,6 +3009,122 @@ _mesa_texstore_sla8(TEXSTORE_PARAMS)
#endif /* FEATURE_EXT_texture_sRGB */
+
+
+/**
+ * Table mapping MESA_FORMAT_8 to _mesa_texstore_*()
+ * XXX this is somewhat temporary.
+ */
+static struct {
+ gl_format Name;
+ StoreTexImageFunc Store;
+}
+texstore_funcs[MESA_FORMAT_COUNT] =
+{
+ { MESA_FORMAT_NONE, NULL },
+ { MESA_FORMAT_RGBA8888, _mesa_texstore_rgba8888 },
+ { MESA_FORMAT_RGBA8888_REV, _mesa_texstore_rgba8888 },
+ { MESA_FORMAT_ARGB8888, _mesa_texstore_argb8888 },
+ { MESA_FORMAT_ARGB8888_REV, _mesa_texstore_argb8888 },
+ { MESA_FORMAT_XRGB8888, _mesa_texstore_argb8888 },
+ { MESA_FORMAT_RGB888, _mesa_texstore_rgb888 },
+ { MESA_FORMAT_BGR888, _mesa_texstore_bgr888 },
+ { MESA_FORMAT_RGB565, _mesa_texstore_rgb565 },
+ { MESA_FORMAT_RGB565_REV, _mesa_texstore_rgb565 },
+ { MESA_FORMAT_ARGB4444, _mesa_texstore_argb4444 },
+ { MESA_FORMAT_ARGB4444_REV, _mesa_texstore_argb4444 },
+ { MESA_FORMAT_RGBA5551, _mesa_texstore_rgba5551 },
+ { MESA_FORMAT_ARGB1555, _mesa_texstore_argb1555 },
+ { MESA_FORMAT_ARGB1555_REV, _mesa_texstore_argb1555 },
+ { MESA_FORMAT_AL88, _mesa_texstore_al88 },
+ { MESA_FORMAT_AL88_REV, _mesa_texstore_al88 },
+ { MESA_FORMAT_RGB332, _mesa_texstore_rgb332 },
+ { MESA_FORMAT_A8, _mesa_texstore_a8 },
+ { MESA_FORMAT_L8, _mesa_texstore_a8 },
+ { MESA_FORMAT_I8, _mesa_texstore_a8 },
+ { MESA_FORMAT_CI8, _mesa_texstore_ci8 },
+ { MESA_FORMAT_YCBCR, _mesa_texstore_ycbcr },
+ { MESA_FORMAT_YCBCR_REV, _mesa_texstore_ycbcr },
+ { MESA_FORMAT_Z24_S8, _mesa_texstore_z24_s8 },
+ { MESA_FORMAT_S8_Z24, _mesa_texstore_s8_z24 },
+ { MESA_FORMAT_Z16, _mesa_texstore_z16 },
+ { MESA_FORMAT_X8_Z24, _mesa_texstore_x8_z24 },
+ { MESA_FORMAT_Z32, _mesa_texstore_z32 },
+ { MESA_FORMAT_S8, NULL/*_mesa_texstore_s8*/ },
+ { MESA_FORMAT_SRGB8, _mesa_texstore_srgb8 },
+ { MESA_FORMAT_SRGBA8, _mesa_texstore_srgba8 },
+ { MESA_FORMAT_SARGB8, _mesa_texstore_sargb8 },
+ { MESA_FORMAT_SL8, _mesa_texstore_sl8 },
+ { MESA_FORMAT_SLA8, _mesa_texstore_sla8 },
+ { MESA_FORMAT_SRGB_DXT1, _mesa_texstore_rgb_dxt1 },
+ { MESA_FORMAT_SRGBA_DXT1, _mesa_texstore_rgba_dxt1 },
+ { MESA_FORMAT_SRGBA_DXT3, _mesa_texstore_rgba_dxt3 },
+ { MESA_FORMAT_SRGBA_DXT5, _mesa_texstore_rgba_dxt5 },
+ { MESA_FORMAT_RGB_FXT1, _mesa_texstore_rgb_fxt1 },
+ { MESA_FORMAT_RGBA_FXT1, _mesa_texstore_rgba_fxt1 },
+ { MESA_FORMAT_RGB_DXT1, _mesa_texstore_rgb_dxt1 },
+ { MESA_FORMAT_RGBA_DXT1, _mesa_texstore_rgba_dxt1 },
+ { MESA_FORMAT_RGBA_DXT3, _mesa_texstore_rgba_dxt3 },
+ { MESA_FORMAT_RGBA_DXT5, _mesa_texstore_rgba_dxt5 },
+ { MESA_FORMAT_RGBA_FLOAT32, _mesa_texstore_rgba_float32 },
+ { MESA_FORMAT_RGBA_FLOAT16, _mesa_texstore_rgba_float16 },
+ { MESA_FORMAT_RGB_FLOAT32, _mesa_texstore_rgba_float32 },
+ { MESA_FORMAT_RGB_FLOAT16, _mesa_texstore_rgba_float16 },
+ { MESA_FORMAT_ALPHA_FLOAT32, _mesa_texstore_rgba_float32 },
+ { MESA_FORMAT_ALPHA_FLOAT16, _mesa_texstore_rgba_float16 },
+ { MESA_FORMAT_LUMINANCE_FLOAT32, _mesa_texstore_rgba_float32 },
+ { MESA_FORMAT_LUMINANCE_FLOAT16, _mesa_texstore_rgba_float16 },
+ { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32, _mesa_texstore_rgba_float32 },
+ { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16, _mesa_texstore_rgba_float16 },
+ { MESA_FORMAT_INTENSITY_FLOAT32, _mesa_texstore_rgba_float32 },
+ { MESA_FORMAT_INTENSITY_FLOAT16, _mesa_texstore_rgba_float16 },
+ { MESA_FORMAT_DUDV8, _mesa_texstore_dudv8 },
+ { MESA_FORMAT_SIGNED_RGBA8888, _mesa_texstore_signed_rgba8888 },
+ { MESA_FORMAT_SIGNED_RGBA8888_REV, _mesa_texstore_signed_rgba8888 },
+ { MESA_FORMAT_SIGNED_RGBA_16, NULL },
+};
+
+
+/**
+ * Return the StoreTexImageFunc pointer to store an image in the given format.
+ */
+static StoreTexImageFunc
+_mesa_get_texstore_func(gl_format format)
+{
+ GLuint i;
+#ifdef DEBUG
+ for (i = 0; i < MESA_FORMAT_COUNT; i++) {
+ ASSERT(texstore_funcs[i].Name == i);
+ }
+#endif
+ ASSERT(texstore_funcs[format].Name == format);
+ return texstore_funcs[format].Store;
+}
+
+
+/**
+ * Store user data into texture memory.
+ * Called via glTex[Sub]Image1/2/3D()
+ */
+GLboolean
+_mesa_texstore(TEXSTORE_PARAMS)
+{
+ StoreTexImageFunc storeImage;
+ GLboolean success;
+
+ storeImage = _mesa_get_texstore_func(dstFormat);
+
+ assert(storeImage);
+
+ success = storeImage(ctx, dims, baseInternalFormat,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride, dstImageOffsets,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr, srcPacking);
+ return success;
+}
+
+
/**
* Check if an unpack PBO is active prior to fetching a texture image.
* If so, do bounds checking and map the buffer into main memory.
@@ -3213,113 +3213,23 @@ _mesa_unmap_teximage_pbo(GLcontext *ctx,
}
-
-/**
- * Adaptor for fetching a GLchan texel from a float-valued texture.
- */
-static void
-fetch_texel_float_to_chan(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLchan *texelOut)
+/** Return texture size in bytes */
+static GLuint
+texture_size(const struct gl_texture_image *texImage)
{
- GLfloat temp[4];
- ASSERT(texImage->FetchTexelf);
- texImage->FetchTexelf(texImage, i, j, k, temp);
- if (texImage->TexFormat->BaseFormat == GL_DEPTH_COMPONENT ||
- texImage->TexFormat->BaseFormat == GL_DEPTH_STENCIL_EXT) {
- /* just one channel */
- UNCLAMPED_FLOAT_TO_CHAN(texelOut[0], temp[0]);
- }
- else {
- /* four channels */
- UNCLAMPED_FLOAT_TO_CHAN(texelOut[0], temp[0]);
- UNCLAMPED_FLOAT_TO_CHAN(texelOut[1], temp[1]);
- UNCLAMPED_FLOAT_TO_CHAN(texelOut[2], temp[2]);
- UNCLAMPED_FLOAT_TO_CHAN(texelOut[3], temp[3]);
- }
-}
-
-
-/**
- * Adaptor for fetching a float texel from a GLchan-valued texture.
- */
-static void
-fetch_texel_chan_to_float(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texelOut)
-{
- GLchan temp[4];
- ASSERT(texImage->FetchTexelc);
- texImage->FetchTexelc(texImage, i, j, k, temp);
- if (texImage->TexFormat->BaseFormat == GL_DEPTH_COMPONENT ||
- texImage->TexFormat->BaseFormat == GL_DEPTH_STENCIL_EXT) {
- /* just one channel */
- texelOut[0] = CHAN_TO_FLOAT(temp[0]);
- }
- else {
- /* four channels */
- texelOut[0] = CHAN_TO_FLOAT(temp[0]);
- texelOut[1] = CHAN_TO_FLOAT(temp[1]);
- texelOut[2] = CHAN_TO_FLOAT(temp[2]);
- texelOut[3] = CHAN_TO_FLOAT(temp[3]);
- }
-}
-
-
-/**
- * Initialize the texture image's FetchTexelc and FetchTexelf methods.
- */
-void
-_mesa_set_fetch_functions(struct gl_texture_image *texImage, GLuint dims)
-{
- ASSERT(dims == 1 || dims == 2 || dims == 3);
- ASSERT(texImage->TexFormat);
-
- switch (dims) {
- case 1:
- texImage->FetchTexelc = texImage->TexFormat->FetchTexel1D;
- texImage->FetchTexelf = texImage->TexFormat->FetchTexel1Df;
- break;
- case 2:
- texImage->FetchTexelc = texImage->TexFormat->FetchTexel2D;
- texImage->FetchTexelf = texImage->TexFormat->FetchTexel2Df;
- break;
- case 3:
- texImage->FetchTexelc = texImage->TexFormat->FetchTexel3D;
- texImage->FetchTexelf = texImage->TexFormat->FetchTexel3Df;
- break;
- default:
- ;
- }
-
- /* now check if we need to use a float/chan adaptor */
- if (!texImage->FetchTexelc) {
- texImage->FetchTexelc = fetch_texel_float_to_chan;
- }
- else if (!texImage->FetchTexelf) {
- texImage->FetchTexelf = fetch_texel_chan_to_float;
- }
-
-
- ASSERT(texImage->FetchTexelc);
- ASSERT(texImage->FetchTexelf);
+ GLuint sz = _mesa_format_image_size(texImage->TexFormat, texImage->Width,
+ texImage->Height, texImage->Depth);
+ return sz;
}
-static void
-compute_texture_size(GLcontext *ctx, struct gl_texture_image *texImage)
+/** Return row stride in bytes */
+static GLuint
+texture_row_stride(const struct gl_texture_image *texImage)
{
- if (texImage->TexFormat->TexelBytes == 0) {
- /* must be a compressed format */
- texImage->IsCompressed = GL_TRUE;
- texImage->CompressedSize =
- ctx->Driver.CompressedTextureSize(ctx, texImage->Width,
- texImage->Height, texImage->Depth,
- texImage->TexFormat->MesaFormat);
- }
- else {
- /* non-compressed format */
- texImage->IsCompressed = GL_FALSE;
- texImage->CompressedSize = 0;
- }
+ GLuint stride = _mesa_format_row_stride(texImage->TexFormat,
+ texImage->Width);
+ return stride;
}
@@ -3341,21 +3251,11 @@ _mesa_store_teximage1d(GLcontext *ctx, GLenum target, GLint level,
struct gl_texture_object *texObj,
struct gl_texture_image *texImage)
{
- GLint sizeInBytes;
+ GLuint sizeInBytes;
(void) border;
- texImage->TexFormat
- = ctx->Driver.ChooseTextureFormat(ctx, internalFormat, format, type);
- ASSERT(texImage->TexFormat);
-
- _mesa_set_fetch_functions(texImage, 1);
- compute_texture_size(ctx, texImage);
-
/* allocate memory */
- if (texImage->IsCompressed)
- sizeInBytes = texImage->CompressedSize;
- else
- sizeInBytes = texImage->Width * texImage->TexFormat->TexelBytes;
+ sizeInBytes = texture_size(texImage);
texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
if (!texImage->Data) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D");
@@ -3372,16 +3272,14 @@ _mesa_store_teximage1d(GLcontext *ctx, GLenum target, GLint level,
}
else {
const GLint dstRowStride = 0;
- GLboolean success;
- ASSERT(texImage->TexFormat->StoreImage);
- success = texImage->TexFormat->StoreImage(ctx, 1, texImage->_BaseFormat,
- texImage->TexFormat,
- texImage->Data,
- 0, 0, 0, /* dstX/Y/Zoffset */
- dstRowStride,
- texImage->ImageOffsets,
- width, 1, 1,
- format, type, pixels, packing);
+ GLboolean success = _mesa_texstore(ctx, 1, texImage->_BaseFormat,
+ texImage->TexFormat,
+ texImage->Data,
+ 0, 0, 0, /* dstX/Y/Zoffset */
+ dstRowStride,
+ texImage->ImageOffsets,
+ width, 1, 1,
+ format, type, pixels, packing);
if (!success) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D");
}
@@ -3410,23 +3308,11 @@ _mesa_store_teximage2d(GLcontext *ctx, GLenum target, GLint level,
struct gl_texture_object *texObj,
struct gl_texture_image *texImage)
{
- GLint texelBytes, sizeInBytes;
+ GLuint sizeInBytes;
(void) border;
- texImage->TexFormat
- = ctx->Driver.ChooseTextureFormat(ctx, internalFormat, format, type);
- ASSERT(texImage->TexFormat);
-
- _mesa_set_fetch_functions(texImage, 2);
- compute_texture_size(ctx, texImage);
-
- texelBytes = texImage->TexFormat->TexelBytes;
-
/* allocate memory */
- if (texImage->IsCompressed)
- sizeInBytes = texImage->CompressedSize;
- else
- sizeInBytes = texImage->Width * texImage->Height * texelBytes;
+ sizeInBytes = texture_size(texImage);
texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
if (!texImage->Data) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
@@ -3442,24 +3328,15 @@ _mesa_store_teximage2d(GLcontext *ctx, GLenum target, GLint level,
return;
}
else {
- GLint dstRowStride;
- GLboolean success;
- if (texImage->IsCompressed) {
- dstRowStride
- = _mesa_compressed_row_stride(texImage->TexFormat->MesaFormat, width);
- }
- else {
- dstRowStride = texImage->RowStride * texImage->TexFormat->TexelBytes;
- }
- ASSERT(texImage->TexFormat->StoreImage);
- success = texImage->TexFormat->StoreImage(ctx, 2, texImage->_BaseFormat,
- texImage->TexFormat,
- texImage->Data,
- 0, 0, 0, /* dstX/Y/Zoffset */
- dstRowStride,
- texImage->ImageOffsets,
- width, height, 1,
- format, type, pixels, packing);
+ GLint dstRowStride = texture_row_stride(texImage);
+ GLboolean success = _mesa_texstore(ctx, 2, texImage->_BaseFormat,
+ texImage->TexFormat,
+ texImage->Data,
+ 0, 0, 0, /* dstX/Y/Zoffset */
+ dstRowStride,
+ texImage->ImageOffsets,
+ width, height, 1,
+ format, type, pixels, packing);
if (!success) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
}
@@ -3484,23 +3361,11 @@ _mesa_store_teximage3d(GLcontext *ctx, GLenum target, GLint level,
struct gl_texture_object *texObj,
struct gl_texture_image *texImage)
{
- GLint texelBytes, sizeInBytes;
+ GLuint sizeInBytes;
(void) border;
- texImage->TexFormat
- = ctx->Driver.ChooseTextureFormat(ctx, internalFormat, format, type);
- ASSERT(texImage->TexFormat);
-
- _mesa_set_fetch_functions(texImage, 3);
- compute_texture_size(ctx, texImage);
-
- texelBytes = texImage->TexFormat->TexelBytes;
-
/* allocate memory */
- if (texImage->IsCompressed)
- sizeInBytes = texImage->CompressedSize;
- else
- sizeInBytes = width * height * depth * texelBytes;
+ sizeInBytes = texture_size(texImage);
texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
if (!texImage->Data) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D");
@@ -3516,24 +3381,15 @@ _mesa_store_teximage3d(GLcontext *ctx, GLenum target, GLint level,
return;
}
else {
- GLint dstRowStride;
- GLboolean success;
- if (texImage->IsCompressed) {
- dstRowStride
- = _mesa_compressed_row_stride(texImage->TexFormat->MesaFormat, width);
- }
- else {
- dstRowStride = texImage->RowStride * texImage->TexFormat->TexelBytes;
- }
- ASSERT(texImage->TexFormat->StoreImage);
- success = texImage->TexFormat->StoreImage(ctx, 3, texImage->_BaseFormat,
- texImage->TexFormat,
- texImage->Data,
- 0, 0, 0, /* dstX/Y/Zoffset */
- dstRowStride,
- texImage->ImageOffsets,
- width, height, depth,
- format, type, pixels, packing);
+ GLint dstRowStride = texture_row_stride(texImage);
+ GLboolean success = _mesa_texstore(ctx, 3, texImage->_BaseFormat,
+ texImage->TexFormat,
+ texImage->Data,
+ 0, 0, 0, /* dstX/Y/Zoffset */
+ dstRowStride,
+ texImage->ImageOffsets,
+ width, height, depth,
+ format, type, pixels, packing);
if (!success) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D");
}
@@ -3565,16 +3421,14 @@ _mesa_store_texsubimage1d(GLcontext *ctx, GLenum target, GLint level,
{
const GLint dstRowStride = 0;
- GLboolean success;
- ASSERT(texImage->TexFormat->StoreImage);
- success = texImage->TexFormat->StoreImage(ctx, 1, texImage->_BaseFormat,
- texImage->TexFormat,
- texImage->Data,
- xoffset, 0, 0, /* offsets */
- dstRowStride,
- texImage->ImageOffsets,
- width, 1, 1,
- format, type, pixels, packing);
+ GLboolean success = _mesa_texstore(ctx, 1, texImage->_BaseFormat,
+ texImage->TexFormat,
+ texImage->Data,
+ xoffset, 0, 0, /* offsets */
+ dstRowStride,
+ texImage->ImageOffsets,
+ width, 1, 1,
+ format, type, pixels, packing);
if (!success) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage1D");
}
@@ -3605,24 +3459,15 @@ _mesa_store_texsubimage2d(GLcontext *ctx, GLenum target, GLint level,
return;
{
- GLint dstRowStride = 0;
- GLboolean success;
- if (texImage->IsCompressed) {
- dstRowStride = _mesa_compressed_row_stride(texImage->TexFormat->MesaFormat,
- texImage->Width);
- }
- else {
- dstRowStride = texImage->RowStride * texImage->TexFormat->TexelBytes;
- }
- ASSERT(texImage->TexFormat->StoreImage);
- success = texImage->TexFormat->StoreImage(ctx, 2, texImage->_BaseFormat,
- texImage->TexFormat,
- texImage->Data,
- xoffset, yoffset, 0,
- dstRowStride,
- texImage->ImageOffsets,
- width, height, 1,
- format, type, pixels, packing);
+ GLint dstRowStride = texture_row_stride(texImage);
+ GLboolean success = _mesa_texstore(ctx, 2, texImage->_BaseFormat,
+ texImage->TexFormat,
+ texImage->Data,
+ xoffset, yoffset, 0,
+ dstRowStride,
+ texImage->ImageOffsets,
+ width, height, 1,
+ format, type, pixels, packing);
if (!success) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage2D");
}
@@ -3653,24 +3498,15 @@ _mesa_store_texsubimage3d(GLcontext *ctx, GLenum target, GLint level,
return;
{
- GLint dstRowStride;
- GLboolean success;
- if (texImage->IsCompressed) {
- dstRowStride = _mesa_compressed_row_stride(texImage->TexFormat->MesaFormat,
- texImage->Width);
- }
- else {
- dstRowStride = texImage->RowStride * texImage->TexFormat->TexelBytes;
- }
- ASSERT(texImage->TexFormat->StoreImage);
- success = texImage->TexFormat->StoreImage(ctx, 3, texImage->_BaseFormat,
- texImage->TexFormat,
- texImage->Data,
- xoffset, yoffset, zoffset,
- dstRowStride,
- texImage->ImageOffsets,
- width, height, depth,
- format, type, pixels, packing);
+ GLint dstRowStride = texture_row_stride(texImage);
+ GLboolean success = _mesa_texstore(ctx, 3, texImage->_BaseFormat,
+ texImage->TexFormat,
+ texImage->Data,
+ xoffset, yoffset, zoffset,
+ dstRowStride,
+ texImage->ImageOffsets,
+ width, height, depth,
+ format, type, pixels, packing);
if (!success) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage3D");
}
@@ -3726,13 +3562,6 @@ _mesa_store_compressed_teximage2d(GLcontext *ctx, GLenum target, GLint level,
ASSERT(texImage->Depth == 1);
ASSERT(texImage->Data == NULL); /* was freed in glCompressedTexImage2DARB */
- texImage->TexFormat
- = ctx->Driver.ChooseTextureFormat(ctx, internalFormat, 0, 0);
- ASSERT(texImage->TexFormat);
-
- _mesa_set_fetch_functions(texImage, 2);
- compute_texture_size(ctx, texImage);
-
/* allocate storage */
texImage->Data = _mesa_alloc_texmemory(imageSize);
if (!texImage->Data) {
@@ -3747,7 +3576,6 @@ _mesa_store_compressed_teximage2d(GLcontext *ctx, GLenum target, GLint level,
return;
/* copy the data */
- ASSERT(texImage->CompressedSize == (GLuint) imageSize);
MEMCPY(texImage->Data, data, imageSize);
_mesa_unmap_teximage_pbo(ctx, &ctx->Unpack);
@@ -3820,15 +3648,20 @@ _mesa_store_compressed_texsubimage2d(GLcontext *ctx, GLenum target,
GLint i, rows;
GLubyte *dest;
const GLubyte *src;
- const GLuint mesaFormat = texImage->TexFormat->MesaFormat;
+ const gl_format texFormat = texImage->TexFormat;
+ const GLint destWidth = texImage->Width;
+ GLuint bw, bh;
+
+ _mesa_get_format_block_size(texFormat, &bw, &bh);
+ (void) level;
(void) format;
/* these should have been caught sooner */
- ASSERT((width & 3) == 0 || width == 2 || width == 1);
- ASSERT((height & 3) == 0 || height == 2 || height == 1);
- ASSERT((xoffset & 3) == 0);
- ASSERT((yoffset & 3) == 0);
+ ASSERT((width % bw) == 0 || width == 2 || width == 1);
+ ASSERT((height % bh) == 0 || height == 2 || height == 1);
+ ASSERT((xoffset % bw) == 0);
+ ASSERT((yoffset % bh) == 0);
/* get pointer to src pixels (may be in a pbo which we'll map here) */
data = _mesa_validate_pbo_compressed_teximage(ctx, imageSize, data,
@@ -3837,18 +3670,18 @@ _mesa_store_compressed_texsubimage2d(GLcontext *ctx, GLenum target,
if (!data)
return;
- srcRowStride = _mesa_compressed_row_stride(mesaFormat, width);
+ srcRowStride = _mesa_format_row_stride(texFormat, width);
src = (const GLubyte *) data;
- destRowStride = _mesa_compressed_row_stride(mesaFormat, texImage->Width);
+ destRowStride = _mesa_format_row_stride(texFormat, destWidth);
dest = _mesa_compressed_image_address(xoffset, yoffset, 0,
- texImage->TexFormat->MesaFormat,
- texImage->Width,
+ texFormat, destWidth,
(GLubyte *) texImage->Data);
- bytesPerRow = srcRowStride;
- rows = height / 4;
+ bytesPerRow = srcRowStride; /* bytes per row of blocks */
+ rows = height / bh; /* rows in blocks */
+ /* copy rows of blocks */
for (i = 0; i < rows; i++) {
MEMCPY(dest, src, bytesPerRow);
dest += destRowStride;
diff --git a/src/mesa/main/texstore.h b/src/mesa/main/texstore.h
index 313f2d6a598..3211086dd63 100644
--- a/src/mesa/main/texstore.h
+++ b/src/mesa/main/texstore.h
@@ -37,49 +37,40 @@
#include "mtypes.h"
+#include "formats.h"
-extern GLboolean _mesa_texstore_rgba(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_color_index(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_rgba8888(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_argb8888(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_rgb888(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_bgr888(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_rgb565(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_rgb565_rev(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_rgba4444(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_argb4444(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_argb4444_rev(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_rgba5551(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_argb1555(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_argb1555_rev(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_al88(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_al88_rev(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_rgb332(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_a8(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_ci8(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_ycbcr(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_z24_s8(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_s8_z24(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_z16(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_z32(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_rgba_float32(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_rgba_float16(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_rgb_fxt1(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_rgba_fxt1(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_rgb_dxt1(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_rgba_dxt1(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_rgba_dxt3(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_rgba_dxt5(TEXSTORE_PARAMS);
-#if FEATURE_EXT_texture_sRGB
-extern GLboolean _mesa_texstore_srgb8(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_srgba8(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_sargb8(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_sl8(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_sla8(TEXSTORE_PARAMS);
-#endif
-extern GLboolean _mesa_texstore_dudv8(TEXSTORE_PARAMS);
-extern GLboolean _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS);
+/**
+ * This macro defines the (many) parameters to the texstore functions.
+ * \param dims either 1 or 2 or 3
+ * \param baseInternalFormat user-specified base internal format
+ * \param dstFormat destination Mesa texture format
+ * \param dstAddr destination image address
+ * \param dstX/Y/Zoffset destination x/y/z offset (ala TexSubImage), in texels
+ * \param dstRowStride destination image row stride, in bytes
+ * \param dstImageOffsets offset of each 2D slice within 3D texture, in texels
+ * \param srcWidth/Height/Depth source image size, in pixels
+ * \param srcFormat incoming image format
+ * \param srcType incoming image data type
+ * \param srcAddr source image address
+ * \param srcPacking source image packing parameters
+ */
+#define TEXSTORE_PARAMS \
+ GLcontext *ctx, GLuint dims, \
+ GLenum baseInternalFormat, \
+ gl_format dstFormat, \
+ GLvoid *dstAddr, \
+ GLint dstXoffset, GLint dstYoffset, GLint dstZoffset, \
+ GLint dstRowStride, const GLuint *dstImageOffsets, \
+ GLint srcWidth, GLint srcHeight, GLint srcDepth, \
+ GLenum srcFormat, GLenum srcType, \
+ const GLvoid *srcAddr, \
+ const struct gl_pixelstore_attrib *srcPacking
+
+
+extern GLboolean
+_mesa_texstore(TEXSTORE_PARAMS);
+
extern GLchan *
_mesa_make_temp_chan_image(GLcontext *ctx, GLuint dims,
@@ -92,10 +83,6 @@ _mesa_make_temp_chan_image(GLcontext *ctx, GLuint dims,
extern void
-_mesa_set_fetch_functions(struct gl_texture_image *texImage, GLuint dims);
-
-
-extern void
_mesa_store_teximage1d(GLcontext *ctx, GLenum target, GLint level,
GLint internalFormat,
GLint width, GLint border,