From 61d94dd207459e0c42d98c9d6eb7df5eabdfd8a4 Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Thu, 22 Apr 2010 21:11:56 -0400 Subject: mesa: Move GL_RGB565 workaround into fbobject.c --- src/mesa/main/glheader.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/mesa/main/glheader.h') diff --git a/src/mesa/main/glheader.h b/src/mesa/main/glheader.h index 77544c88c66..7f01d9f39bd 100644 --- a/src/mesa/main/glheader.h +++ b/src/mesa/main/glheader.h @@ -85,6 +85,10 @@ typedef void *GLeglImageOES; #define GL_PROGRAM_BINARY_LENGTH_OES 0x8741 #endif +/* GLES 2.0 token */ +#ifndef GL_RGB565 +#define GL_RGB565 0x8D62 +#endif /** * Special, internal token -- cgit v1.2.3 From 08fae07f5246052dccdd89689e27dc8820a24ff7 Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Sat, 24 Apr 2010 19:18:35 -0400 Subject: mesa: Handle GL_TEXTURE_GEN_STR_OES in _mesa_Enable() --- src/mesa/es/main/es_enable.c | 91 -------------------------------------------- src/mesa/es/sources.mak | 1 - src/mesa/main/APIspec.xml | 6 +-- src/mesa/main/enable.c | 28 ++++++++++++++ src/mesa/main/glheader.h | 6 ++- src/mesa/main/mtypes.h | 1 + 6 files changed, 37 insertions(+), 96 deletions(-) delete mode 100644 src/mesa/es/main/es_enable.c (limited to 'src/mesa/main/glheader.h') diff --git a/src/mesa/es/main/es_enable.c b/src/mesa/es/main/es_enable.c deleted file mode 100644 index 351caacd776..00000000000 --- a/src/mesa/es/main/es_enable.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2009 Chia-I Wu - * - * 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 (including the next - * paragraph) 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 - * THE AUTHORS OR COPYRIGHT HOLDERS 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 "GLES/gl.h" -#include "GLES/glext.h" - -#include "main/compiler.h" /* for ASSERT */ - - -#ifndef GL_TEXTURE_GEN_S -#define GL_TEXTURE_GEN_S 0x0C60 -#define GL_TEXTURE_GEN_T 0x0C61 -#define GL_TEXTURE_GEN_R 0x0C62 -#endif - - -extern void GL_APIENTRY _es_Disable(GLenum cap); -extern void GL_APIENTRY _es_Enable(GLenum cap); -extern GLboolean GL_APIENTRY _es_IsEnabled(GLenum cap); - -extern void GL_APIENTRY _mesa_Disable(GLenum cap); -extern void GL_APIENTRY _mesa_Enable(GLenum cap); -extern GLboolean GL_APIENTRY _mesa_IsEnabled(GLenum cap); - - -void GL_APIENTRY -_es_Disable(GLenum cap) -{ - switch (cap) { - case GL_TEXTURE_GEN_STR_OES: - /* disable S, T, and R at the same time */ - _mesa_Disable(GL_TEXTURE_GEN_S); - _mesa_Disable(GL_TEXTURE_GEN_T); - _mesa_Disable(GL_TEXTURE_GEN_R); - break; - default: - _mesa_Disable(cap); - break; - } -} - - -void GL_APIENTRY -_es_Enable(GLenum cap) -{ - switch (cap) { - case GL_TEXTURE_GEN_STR_OES: - /* enable S, T, and R at the same time */ - _mesa_Enable(GL_TEXTURE_GEN_S); - _mesa_Enable(GL_TEXTURE_GEN_T); - _mesa_Enable(GL_TEXTURE_GEN_R); - break; - default: - _mesa_Enable(cap); - break; - } -} - - -GLboolean GL_APIENTRY -_es_IsEnabled(GLenum cap) -{ - switch (cap) { - case GL_TEXTURE_GEN_STR_OES: - cap = GL_TEXTURE_GEN_S; - default: - break; - } - - return _mesa_IsEnabled(cap); -} diff --git a/src/mesa/es/sources.mak b/src/mesa/es/sources.mak index 8526820c806..e02fce76fd0 100644 --- a/src/mesa/es/sources.mak +++ b/src/mesa/es/sources.mak @@ -5,7 +5,6 @@ include $(MESA)/sources.mak LOCAL_ES1_SOURCES := \ main/drawtex.c \ main/es_cpaltex.c \ - main/es_enable.c \ main/es_query_matrix.c \ main/es_texgen.c \ glapi/glapi-es1/main/enums.c diff --git a/src/mesa/main/APIspec.xml b/src/mesa/main/APIspec.xml index 7ed303dab00..17eece1bb43 100644 --- a/src/mesa/main/APIspec.xml +++ b/src/mesa/main/APIspec.xml @@ -3921,8 +3921,8 @@ - - + + @@ -3969,7 +3969,7 @@ - + diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c index 72787226dc4..db30123c0fb 100644 --- a/src/mesa/main/enable.c +++ b/src/mesa/main/enable.c @@ -682,6 +682,25 @@ _mesa_set_enable(GLcontext *ctx, GLenum cap, GLboolean state) } break; +#if FEATURE_ES1 + case GL_TEXTURE_GEN_STR_OES: + /* disable S, T, and R at the same time */ + { + struct gl_texture_unit *texUnit = get_texcoord_unit(ctx); + if (texUnit) { + GLuint newenabled = + texUnit->TexGenEnabled & ~STR_BITS; + if (state) + newenabled |= STR_BITS; + if (texUnit->TexGenEnabled == newenabled) + return; + FLUSH_VERTICES(ctx, _NEW_TEXTURE); + texUnit->TexGenEnabled = newenabled; + } + } + break; +#endif + /* * CLIENT STATE!!! */ @@ -1301,6 +1320,15 @@ _mesa_IsEnabled( GLenum cap ) } } return GL_FALSE; +#if FEATURE_ES1 + case GL_TEXTURE_GEN_STR_OES: + { + const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx); + if (texUnit) { + return (texUnit->TexGenEnabled & STR_BITS) == STR_BITS ? GL_TRUE : GL_FALSE; + } + } +#endif /* * CLIENT STATE!!! diff --git a/src/mesa/main/glheader.h b/src/mesa/main/glheader.h index 7f01d9f39bd..6d423eacee8 100644 --- a/src/mesa/main/glheader.h +++ b/src/mesa/main/glheader.h @@ -85,11 +85,15 @@ typedef void *GLeglImageOES; #define GL_PROGRAM_BINARY_LENGTH_OES 0x8741 #endif -/* GLES 2.0 token */ +/* GLES 2.0 tokens */ #ifndef GL_RGB565 #define GL_RGB565 0x8D62 #endif +#ifndef GL_TEXTURE_GEN_STR_OES +#define GL_TEXTURE_GEN_STR_OES 0x8D60 +#endif + /** * Special, internal token */ diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index e5e099acc3c..9640b79ea7f 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1076,6 +1076,7 @@ typedef enum #define T_BIT 2 #define R_BIT 4 #define Q_BIT 8 +#define STR_BITS (S_BIT | T_BIT | R_BIT) /*@}*/ -- cgit v1.2.3 From 7179a822628963d8cfa0817cf072c5acb70638a7 Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Sat, 24 Apr 2010 19:34:57 -0400 Subject: mesa: Move support for paletted textures to main/teximage.c --- src/mesa/es/main/es_cpaltex.c | 231 ------------------------------------------ src/mesa/es/sources.mak | 2 - src/mesa/main/APIspec.xml | 4 +- src/mesa/main/glheader.h | 13 +++ src/mesa/main/teximage.c | 20 +++- src/mesa/main/texpal.c | 204 +++++++++++++++++++++++++++++++++++++ src/mesa/main/texpal.h | 38 +++++++ src/mesa/sources.mak | 1 + 8 files changed, 277 insertions(+), 236 deletions(-) delete mode 100644 src/mesa/es/main/es_cpaltex.c create mode 100644 src/mesa/main/texpal.c create mode 100644 src/mesa/main/texpal.h (limited to 'src/mesa/main/glheader.h') diff --git a/src/mesa/es/main/es_cpaltex.c b/src/mesa/es/main/es_cpaltex.c deleted file mode 100644 index 0c497774ff8..00000000000 --- a/src/mesa/es/main/es_cpaltex.c +++ /dev/null @@ -1,231 +0,0 @@ -/************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - **************************************************************************/ - - -/** - * Code to convert compressed/paletted texture images to ordinary images. - * See the GL_OES_compressed_paletted_texture spec at - * http://khronos.org/registry/gles/extensions/OES/OES_compressed_paletted_texture.txt - * - * XXX this makes it impossible to add hardware support... - */ - - -#include "GLES/gl.h" -#include "GLES/glext.h" - -#include "main/compiler.h" /* for ASSERT */ - - -void GL_APIENTRY _es_CompressedTexImage2DARB(GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); - -void GL_APIENTRY _mesa_GetIntegerv(GLenum pname, GLint *params); -void GL_APIENTRY _mesa_PixelStorei(GLenum pname, GLint param); -void GL_APIENTRY _mesa_TexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -void GL_APIENTRY _mesa_CompressedTexImage2DARB(GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); - -void *_mesa_get_current_context(void); -void _mesa_error(void *ctx, GLenum error, const char *fmtString, ... ); - - -static const struct cpal_format_info { - GLenum cpal_format; - GLenum format; - GLenum type; - GLuint palette_size; - GLuint size; -} formats[] = { - { GL_PALETTE4_RGB8_OES, GL_RGB, GL_UNSIGNED_BYTE, 16, 3 }, - { GL_PALETTE4_RGBA8_OES, GL_RGBA, GL_UNSIGNED_BYTE, 16, 4 }, - { GL_PALETTE4_R5_G6_B5_OES, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 16, 2 }, - { GL_PALETTE4_RGBA4_OES, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 16, 2 }, - { GL_PALETTE4_RGB5_A1_OES, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 16, 2 }, - { GL_PALETTE8_RGB8_OES, GL_RGB, GL_UNSIGNED_BYTE, 256, 3 }, - { GL_PALETTE8_RGBA8_OES, GL_RGBA, GL_UNSIGNED_BYTE, 256, 4 }, - { GL_PALETTE8_R5_G6_B5_OES, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 256, 2 }, - { GL_PALETTE8_RGBA4_OES, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 256, 2 }, - { GL_PALETTE8_RGB5_A1_OES, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 256, 2 } -}; - - -/** - * Get a color/entry from the palette. - */ -static GLuint -get_palette_entry(const struct cpal_format_info *info, const GLubyte *palette, - GLuint index, GLubyte *pixel) -{ - memcpy(pixel, palette + info->size * index, info->size); - return info->size; -} - - -/** - * Convert paletted texture to color texture. - */ -static void -paletted_to_color(const struct cpal_format_info *info, const GLubyte *palette, - const void *indices, GLuint num_pixels, GLubyte *image) -{ - GLubyte *pix = image; - GLuint remain, i; - - if (info->palette_size == 16) { - /* 4 bits per index */ - const GLubyte *ind = (const GLubyte *) indices; - - /* two pixels per iteration */ - remain = num_pixels % 2; - for (i = 0; i < num_pixels / 2; i++) { - pix += get_palette_entry(info, palette, (ind[i] >> 4) & 0xf, pix); - pix += get_palette_entry(info, palette, ind[i] & 0xf, pix); - } - if (remain) { - get_palette_entry(info, palette, (ind[i] >> 4) & 0xf, pix); - } - } - else { - /* 8 bits per index */ - const GLubyte *ind = (const GLubyte *) indices; - for (i = 0; i < num_pixels; i++) - pix += get_palette_entry(info, palette, ind[i], pix); - } -} - - -static const struct cpal_format_info * -cpal_get_info(GLint level, GLenum internalFormat, - GLsizei width, GLsizei height, GLsizei imageSize) -{ - const struct cpal_format_info *info; - GLint lvl, num_levels; - GLsizei w, h, expect_size; - - info = &formats[internalFormat - GL_PALETTE4_RGB8_OES]; - ASSERT(info->cpal_format == internalFormat); - - if (level > 0) { - _mesa_error(_mesa_get_current_context(), GL_INVALID_VALUE, - "glCompressedTexImage2D(level=%d)", level); - return NULL; - } - - num_levels = -level + 1; - expect_size = info->palette_size * info->size; - for (lvl = 0; lvl < num_levels; lvl++) { - w = width >> lvl; - if (!w) - w = 1; - h = height >> lvl; - if (!h) - h = 1; - - if (info->palette_size == 16) - expect_size += (w * h + 1) / 2; - else - expect_size += w * h; - } - if (expect_size > imageSize) { - _mesa_error(_mesa_get_current_context(), GL_INVALID_VALUE, - "glCompressedTexImage2D(imageSize=%d)", imageSize); - return NULL; - } - return info; -} - -/** - * Convert a call to glCompressedTexImage2D() where internalFormat is a - * compressed palette format into a regular GLubyte/RGBA glTexImage2D() call. - */ -static void -cpal_compressed_teximage2d(GLenum target, GLint level, GLenum internalFormat, - GLsizei width, GLsizei height, GLsizei imageSize, - const void *palette) -{ - const struct cpal_format_info *info; - GLint lvl, num_levels; - const GLubyte *indices; - GLint saved_align, align; - - info = cpal_get_info(level, internalFormat, width, height, imageSize); - if (!info) - return; - - info = &formats[internalFormat - GL_PALETTE4_RGB8_OES]; - ASSERT(info->cpal_format == internalFormat); - num_levels = -level + 1; - - /* first image follows the palette */ - indices = (const GLubyte *) palette + info->palette_size * info->size; - - _mesa_GetIntegerv(GL_UNPACK_ALIGNMENT, &saved_align); - align = saved_align; - - for (lvl = 0; lvl < num_levels; lvl++) { - GLsizei w, h; - GLuint num_texels; - GLubyte *image = NULL; - - w = width >> lvl; - if (!w) - w = 1; - h = height >> lvl; - if (!h) - h = 1; - num_texels = w * h; - if (w * info->size % align) { - _mesa_PixelStorei(GL_UNPACK_ALIGNMENT, 1); - align = 1; - } - - /* allocate and fill dest image buffer */ - if (palette) { - image = (GLubyte *) malloc(num_texels * info->size); - paletted_to_color(info, palette, indices, num_texels, image); - } - - _mesa_TexImage2D(target, lvl, info->format, w, h, 0, - info->format, info->type, image); - if (image) - free(image); - - /* advance index pointer to point to next src mipmap */ - if (info->palette_size == 16) - indices += (num_texels + 1) / 2; - else - indices += num_texels; - } - - if (saved_align != align) - _mesa_PixelStorei(GL_UNPACK_ALIGNMENT, saved_align); -} - - -void GL_APIENTRY -_es_CompressedTexImage2DARB(GLenum target, GLint level, GLenum internalFormat, - GLsizei width, GLsizei height, GLint border, - GLsizei imageSize, const GLvoid *data) -{ - switch (internalFormat) { - case GL_PALETTE4_RGB8_OES: - case GL_PALETTE4_RGBA8_OES: - case GL_PALETTE4_R5_G6_B5_OES: - case GL_PALETTE4_RGBA4_OES: - case GL_PALETTE4_RGB5_A1_OES: - case GL_PALETTE8_RGB8_OES: - case GL_PALETTE8_RGBA8_OES: - case GL_PALETTE8_R5_G6_B5_OES: - case GL_PALETTE8_RGBA4_OES: - case GL_PALETTE8_RGB5_A1_OES: - cpal_compressed_teximage2d(target, level, internalFormat, - width, height, imageSize, data); - break; - default: - _mesa_CompressedTexImage2DARB(target, level, internalFormat, - width, height, border, imageSize, data); - } -} diff --git a/src/mesa/es/sources.mak b/src/mesa/es/sources.mak index e02fce76fd0..339912dfdc8 100644 --- a/src/mesa/es/sources.mak +++ b/src/mesa/es/sources.mak @@ -4,7 +4,6 @@ include $(MESA)/sources.mak LOCAL_ES1_SOURCES := \ main/drawtex.c \ - main/es_cpaltex.c \ main/es_query_matrix.c \ main/es_texgen.c \ glapi/glapi-es1/main/enums.c @@ -23,7 +22,6 @@ LOCAL_ES1_INCLUDES := \ -I$(MESA)/state_tracker LOCAL_ES2_SOURCES := \ - main/es_cpaltex.c \ glapi/glapi-es2/main/enums.c LOCAL_ES2_GALLIUM_SOURCES := \ diff --git a/src/mesa/main/APIspec.xml b/src/mesa/main/APIspec.xml index 17eece1bb43..268bd5d3db2 100644 --- a/src/mesa/main/APIspec.xml +++ b/src/mesa/main/APIspec.xml @@ -4040,7 +4040,7 @@ - + @@ -4217,7 +4217,7 @@ - + diff --git a/src/mesa/main/glheader.h b/src/mesa/main/glheader.h index 6d423eacee8..5b8e2f2d811 100644 --- a/src/mesa/main/glheader.h +++ b/src/mesa/main/glheader.h @@ -94,6 +94,19 @@ typedef void *GLeglImageOES; #define GL_TEXTURE_GEN_STR_OES 0x8D60 #endif +#ifndef GL_OES_compressed_paletted_texture +#define GL_PALETTE4_RGB8_OES 0x8B90 +#define GL_PALETTE4_RGBA8_OES 0x8B91 +#define GL_PALETTE4_R5_G6_B5_OES 0x8B92 +#define GL_PALETTE4_RGBA4_OES 0x8B93 +#define GL_PALETTE4_RGB5_A1_OES 0x8B94 +#define GL_PALETTE8_RGB8_OES 0x8B95 +#define GL_PALETTE8_RGBA8_OES 0x8B96 +#define GL_PALETTE8_R5_G6_B5_OES 0x8B97 +#define GL_PALETTE8_RGBA4_OES 0x8B98 +#define GL_PALETTE8_RGB5_A1_OES 0x8B99 +#endif + /** * Special, internal token */ diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c index b31ca86f11d..0c583ed14d3 100644 --- a/src/mesa/main/teximage.c +++ b/src/mesa/main/teximage.c @@ -46,6 +46,7 @@ #include "texfetch.h" #include "teximage.h" #include "texstate.h" +#include "texpal.h" #include "mtypes.h" @@ -3408,7 +3409,6 @@ _mesa_CompressedTexImage1DARB(GLenum target, GLint level, } } - void GLAPIENTRY _mesa_CompressedTexImage2DARB(GLenum target, GLint level, GLenum internalFormat, GLsizei width, @@ -3424,6 +3424,24 @@ _mesa_CompressedTexImage2DARB(GLenum target, GLint level, _mesa_lookup_enum_by_nr(internalFormat), width, height, border, imageSize, data); +#if FEATURE_ES + switch (internalFormat) { + case GL_PALETTE4_RGB8_OES: + case GL_PALETTE4_RGBA8_OES: + case GL_PALETTE4_R5_G6_B5_OES: + case GL_PALETTE4_RGBA4_OES: + case GL_PALETTE4_RGB5_A1_OES: + case GL_PALETTE8_RGB8_OES: + case GL_PALETTE8_RGBA8_OES: + case GL_PALETTE8_R5_G6_B5_OES: + case GL_PALETTE8_RGBA4_OES: + case GL_PALETTE8_RGB5_A1_OES: + _mesa_cpal_compressed_teximage2d(target, level, internalFormat, + width, height, imageSize, data); + return; + } +#endif + if (target == GL_TEXTURE_2D || (ctx->Extensions.ARB_texture_cube_map && target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && diff --git a/src/mesa/main/texpal.c b/src/mesa/main/texpal.c new file mode 100644 index 00000000000..a25e7aa4ff8 --- /dev/null +++ b/src/mesa/main/texpal.c @@ -0,0 +1,204 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + **************************************************************************/ + + +/** + * Code to convert compressed/paletted texture images to ordinary images. + * See the GL_OES_compressed_paletted_texture spec at + * http://khronos.org/registry/gles/extensions/OES/OES_compressed_paletted_texture.txt + * + * XXX this makes it impossible to add hardware support... + */ + + +#include "glheader.h" +#include "compiler.h" /* for ASSERT */ +#include "context.h" +#include "mtypes.h" +#include "imports.h" +#include "pixelstore.h" +#include "teximage.h" +#include "texpal.h" + +#if FEATURE_ES + + +static const struct cpal_format_info { + GLenum cpal_format; + GLenum format; + GLenum type; + GLuint palette_size; + GLuint size; +} formats[] = { + { GL_PALETTE4_RGB8_OES, GL_RGB, GL_UNSIGNED_BYTE, 16, 3 }, + { GL_PALETTE4_RGBA8_OES, GL_RGBA, GL_UNSIGNED_BYTE, 16, 4 }, + { GL_PALETTE4_R5_G6_B5_OES, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 16, 2 }, + { GL_PALETTE4_RGBA4_OES, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 16, 2 }, + { GL_PALETTE4_RGB5_A1_OES, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 16, 2 }, + { GL_PALETTE8_RGB8_OES, GL_RGB, GL_UNSIGNED_BYTE, 256, 3 }, + { GL_PALETTE8_RGBA8_OES, GL_RGBA, GL_UNSIGNED_BYTE, 256, 4 }, + { GL_PALETTE8_R5_G6_B5_OES, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 256, 2 }, + { GL_PALETTE8_RGBA4_OES, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 256, 2 }, + { GL_PALETTE8_RGB5_A1_OES, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 256, 2 } +}; + + +/** + * Get a color/entry from the palette. + */ +static GLuint +get_palette_entry(const struct cpal_format_info *info, const GLubyte *palette, + GLuint index, GLubyte *pixel) +{ + memcpy(pixel, palette + info->size * index, info->size); + return info->size; +} + + +/** + * Convert paletted texture to color texture. + */ +static void +paletted_to_color(const struct cpal_format_info *info, const GLubyte *palette, + const void *indices, GLuint num_pixels, GLubyte *image) +{ + GLubyte *pix = image; + GLuint remain, i; + + if (info->palette_size == 16) { + /* 4 bits per index */ + const GLubyte *ind = (const GLubyte *) indices; + + /* two pixels per iteration */ + remain = num_pixels % 2; + for (i = 0; i < num_pixels / 2; i++) { + pix += get_palette_entry(info, palette, (ind[i] >> 4) & 0xf, pix); + pix += get_palette_entry(info, palette, ind[i] & 0xf, pix); + } + if (remain) { + get_palette_entry(info, palette, (ind[i] >> 4) & 0xf, pix); + } + } + else { + /* 8 bits per index */ + const GLubyte *ind = (const GLubyte *) indices; + for (i = 0; i < num_pixels; i++) + pix += get_palette_entry(info, palette, ind[i], pix); + } +} + + +static const struct cpal_format_info * +cpal_get_info(GLint level, GLenum internalFormat, + GLsizei width, GLsizei height, GLsizei imageSize) +{ + const struct cpal_format_info *info; + GLint lvl, num_levels; + GLsizei w, h, expect_size; + + info = &formats[internalFormat - GL_PALETTE4_RGB8_OES]; + ASSERT(info->cpal_format == internalFormat); + + if (level > 0) { + _mesa_error(_mesa_get_current_context(), GL_INVALID_VALUE, + "glCompressedTexImage2D(level=%d)", level); + return NULL; + } + + num_levels = -level + 1; + expect_size = info->palette_size * info->size; + for (lvl = 0; lvl < num_levels; lvl++) { + w = width >> lvl; + if (!w) + w = 1; + h = height >> lvl; + if (!h) + h = 1; + + if (info->palette_size == 16) + expect_size += (w * h + 1) / 2; + else + expect_size += w * h; + } + if (expect_size > imageSize) { + _mesa_error(_mesa_get_current_context(), GL_INVALID_VALUE, + "glCompressedTexImage2D(imageSize=%d)", imageSize); + return NULL; + } + return info; +} + +/** + * Convert a call to glCompressedTexImage2D() where internalFormat is a + * compressed palette format into a regular GLubyte/RGBA glTexImage2D() call. + */ +void +_mesa_cpal_compressed_teximage2d(GLenum target, GLint level, + GLenum internalFormat, + GLsizei width, GLsizei height, + GLsizei imageSize, const void *palette) +{ + const struct cpal_format_info *info; + GLint lvl, num_levels; + const GLubyte *indices; + GLint saved_align, align; + GET_CURRENT_CONTEXT(ctx); + + info = cpal_get_info(level, internalFormat, width, height, imageSize); + if (!info) + return; + + info = &formats[internalFormat - GL_PALETTE4_RGB8_OES]; + ASSERT(info->cpal_format == internalFormat); + num_levels = -level + 1; + + /* first image follows the palette */ + indices = (const GLubyte *) palette + info->palette_size * info->size; + + saved_align = ctx->Unpack.Alignment; + align = saved_align; + + for (lvl = 0; lvl < num_levels; lvl++) { + GLsizei w, h; + GLuint num_texels; + GLubyte *image = NULL; + + w = width >> lvl; + if (!w) + w = 1; + h = height >> lvl; + if (!h) + h = 1; + num_texels = w * h; + if (w * info->size % align) { + _mesa_PixelStorei(GL_UNPACK_ALIGNMENT, 1); + align = 1; + } + + /* allocate and fill dest image buffer */ + if (palette) { + image = (GLubyte *) malloc(num_texels * info->size); + paletted_to_color(info, palette, indices, num_texels, image); + } + + _mesa_TexImage2D(target, lvl, info->format, w, h, 0, + info->format, info->type, image); + if (image) + free(image); + + /* advance index pointer to point to next src mipmap */ + if (info->palette_size == 16) + indices += (num_texels + 1) / 2; + else + indices += num_texels; + } + + if (saved_align != align) + _mesa_PixelStorei(GL_UNPACK_ALIGNMENT, saved_align); +} + +#endif diff --git a/src/mesa/main/texpal.h b/src/mesa/main/texpal.h new file mode 100644 index 00000000000..eeff5a9e24c --- /dev/null +++ b/src/mesa/main/texpal.h @@ -0,0 +1,38 @@ +/* + * Mesa 3-D graphics library + * Version: 7.8 + * + * Copyright (C) 1999-2010 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 TEXPAL_H +#define TEXPAL_H + + +#include "main/glheader.h" +extern void +_mesa_cpal_compressed_teximage2d(GLenum target, GLint level, + GLenum internalFormat, + GLsizei width, GLsizei height, + GLsizei imageSize, const void *palette); + + +#endif /* TEXPAL_H */ diff --git a/src/mesa/sources.mak b/src/mesa/sources.mak index df16e70c958..5e11192b44e 100644 --- a/src/mesa/sources.mak +++ b/src/mesa/sources.mak @@ -80,6 +80,7 @@ MAIN_SOURCES = \ main/texgetimage.c \ main/teximage.c \ main/texobj.c \ + main/texpal.c \ main/texparam.c \ main/texrender.c \ main/texstate.c \ -- cgit v1.2.3