Merge branch 'GL_EXT_shared_texture_palette' into 'master'
Implement GL_EXT_shared_texture_palette See merge request simulant/GLdc!28
This commit is contained in:
commit
cdd2447e07
|
@ -139,6 +139,9 @@ TextureObject* getBoundTexture();
|
||||||
GLubyte _glGetActiveTexture();
|
GLubyte _glGetActiveTexture();
|
||||||
GLuint _glGetActiveClientTexture();
|
GLuint _glGetActiveClientTexture();
|
||||||
|
|
||||||
|
GLboolean _glIsSharedTexturePaletteEnabled();
|
||||||
|
void _glApplyColorTable();
|
||||||
|
|
||||||
GLboolean isBlendingEnabled();
|
GLboolean isBlendingEnabled();
|
||||||
GLboolean _glIsMipmapComplete(const TextureObject* obj);
|
GLboolean _glIsMipmapComplete(const TextureObject* obj);
|
||||||
GLubyte* _glGetMipmapLocation(TextureObject* obj, GLuint level);
|
GLubyte* _glGetMipmapLocation(TextureObject* obj, GLuint level);
|
||||||
|
|
18
GL/state.c
18
GL/state.c
|
@ -27,6 +27,13 @@ static GLenum FRONT_FACE = GL_CCW;
|
||||||
static GLboolean CULLING_ENABLED = GL_FALSE;
|
static GLboolean CULLING_ENABLED = GL_FALSE;
|
||||||
static GLboolean COLOR_MATERIAL_ENABLED = GL_FALSE;
|
static GLboolean COLOR_MATERIAL_ENABLED = GL_FALSE;
|
||||||
|
|
||||||
|
/* Is the shared texture palette enabled? */
|
||||||
|
static GLboolean SHARED_PALETTE_ENABLED = GL_FALSE;
|
||||||
|
|
||||||
|
GLboolean _glIsSharedTexturePaletteEnabled() {
|
||||||
|
return SHARED_PALETTE_ENABLED;
|
||||||
|
}
|
||||||
|
|
||||||
static int _calc_pvr_face_culling() {
|
static int _calc_pvr_face_culling() {
|
||||||
if(!CULLING_ENABLED) {
|
if(!CULLING_ENABLED) {
|
||||||
return PVR_CULLING_NONE;
|
return PVR_CULLING_NONE;
|
||||||
|
@ -214,6 +221,9 @@ void _glUpdatePVRTextureContext(pvr_poly_cxt_t* context, GLshort textureUnit) {
|
||||||
} else {
|
} else {
|
||||||
context->txr.enable = PVR_TEXTURE_DISABLE;
|
context->txr.enable = PVR_TEXTURE_DISABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Apply the texture palette if necessary */
|
||||||
|
_glApplyColorTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
static GLboolean LIGHTING_ENABLED = GL_FALSE;
|
static GLboolean LIGHTING_ENABLED = GL_FALSE;
|
||||||
|
@ -291,6 +301,9 @@ GLAPI void APIENTRY glEnable(GLenum cap) {
|
||||||
case GL_COLOR_MATERIAL:
|
case GL_COLOR_MATERIAL:
|
||||||
COLOR_MATERIAL_ENABLED = GL_TRUE;
|
COLOR_MATERIAL_ENABLED = GL_TRUE;
|
||||||
break;
|
break;
|
||||||
|
case GL_SHARED_TEXTURE_PALETTE_EXT:
|
||||||
|
SHARED_PALETTE_ENABLED = GL_TRUE;
|
||||||
|
break;
|
||||||
case GL_LIGHT0:
|
case GL_LIGHT0:
|
||||||
case GL_LIGHT1:
|
case GL_LIGHT1:
|
||||||
case GL_LIGHT2:
|
case GL_LIGHT2:
|
||||||
|
@ -338,6 +351,9 @@ GLAPI void APIENTRY glDisable(GLenum cap) {
|
||||||
case GL_COLOR_MATERIAL:
|
case GL_COLOR_MATERIAL:
|
||||||
COLOR_MATERIAL_ENABLED = GL_FALSE;
|
COLOR_MATERIAL_ENABLED = GL_FALSE;
|
||||||
break;
|
break;
|
||||||
|
case GL_SHARED_TEXTURE_PALETTE_EXT:
|
||||||
|
SHARED_PALETTE_ENABLED = GL_FALSE;
|
||||||
|
break;
|
||||||
case GL_LIGHT0:
|
case GL_LIGHT0:
|
||||||
case GL_LIGHT1:
|
case GL_LIGHT1:
|
||||||
case GL_LIGHT2:
|
case GL_LIGHT2:
|
||||||
|
@ -601,7 +617,7 @@ const GLbyte *glGetString(GLenum name) {
|
||||||
return "GLdc 1.x";
|
return "GLdc 1.x";
|
||||||
|
|
||||||
case GL_EXTENSIONS:
|
case GL_EXTENSIONS:
|
||||||
return "GL_ARB_framebuffer_object, GL_ARB_multitexture, GL_ARB_texture_rg, GL_EXT_paletted_texture";
|
return "GL_ARB_framebuffer_object, GL_ARB_multitexture, GL_ARB_texture_rg, GL_EXT_paletted_texture, GL_EXT_shared_texture_palette";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "GL_KOS_ERROR: ENUM Unsupported\n";
|
return "GL_KOS_ERROR: ENUM Unsupported\n";
|
||||||
|
|
71
GL/texture.c
71
GL/texture.c
|
@ -17,26 +17,43 @@ static TextureObject* TEXTURE_UNITS[MAX_TEXTURE_UNITS] = {NULL, NULL};
|
||||||
static NamedArray TEXTURE_OBJECTS;
|
static NamedArray TEXTURE_OBJECTS;
|
||||||
static GLubyte ACTIVE_TEXTURE = 0;
|
static GLubyte ACTIVE_TEXTURE = 0;
|
||||||
|
|
||||||
|
static TexturePalette* SHARED_PALETTE = NULL;
|
||||||
|
|
||||||
static GLuint _determinePVRFormat(GLint internalFormat, GLenum type);
|
static GLuint _determinePVRFormat(GLint internalFormat, GLenum type);
|
||||||
|
|
||||||
#define PACK_ARGB8888(a,r,g,b) ( ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF) )
|
#define PACK_ARGB8888(a,r,g,b) ( ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF) )
|
||||||
|
|
||||||
static void _glApplyColorTable() {
|
void _glApplyColorTable() {
|
||||||
TextureObject* active = getBoundTexture();
|
/*
|
||||||
|
* FIXME:
|
||||||
|
*
|
||||||
|
* - Different palette formats (GL_RGB -> PVR_PAL_RGB565)
|
||||||
|
* - Store the active palette, don't resubmit eah time
|
||||||
|
*/
|
||||||
|
|
||||||
if(!active) {
|
TexturePalette* src = NULL;
|
||||||
return; //? Unload the palette? Make White?
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!active->palette || !active->palette->data) {
|
if(_glIsSharedTexturePaletteEnabled()) {
|
||||||
return;
|
src = SHARED_PALETTE;
|
||||||
|
} else {
|
||||||
|
TextureObject* active = getBoundTexture();
|
||||||
|
|
||||||
|
if(!active) {
|
||||||
|
return; //? Unload the palette? Make White?
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!active->palette || !active->palette->data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
src = active->palette;
|
||||||
}
|
}
|
||||||
|
|
||||||
pvr_set_pal_format(PVR_PAL_ARGB8888);
|
pvr_set_pal_format(PVR_PAL_ARGB8888);
|
||||||
|
|
||||||
GLushort i = 0;
|
GLushort i = 0;
|
||||||
for(; i < active->palette->width; ++i) {
|
for(; i < src->width; ++i) {
|
||||||
GLubyte* entry = &active->palette->data[i * 4];
|
GLubyte* entry = &src->data[i * 4];
|
||||||
pvr_set_pal_entry(i, PACK_ARGB8888(entry[3], entry[1], entry[2], entry[0]));
|
pvr_set_pal_entry(i, PACK_ARGB8888(entry[3], entry[1], entry[2], entry[0]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,6 +134,8 @@ static GLuint _glGetMipmapDataSize(TextureObject* obj) {
|
||||||
|
|
||||||
GLubyte _glKosInitTextures() {
|
GLubyte _glKosInitTextures() {
|
||||||
named_array_init(&TEXTURE_OBJECTS, sizeof(TextureObject), 256);
|
named_array_init(&TEXTURE_OBJECTS, sizeof(TextureObject), 256);
|
||||||
|
|
||||||
|
SHARED_PALETTE = (TexturePalette*) malloc(sizeof(TexturePalette));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,9 +237,6 @@ void APIENTRY glBindTexture(GLenum target, GLuint texture) {
|
||||||
|
|
||||||
if(texture) {
|
if(texture) {
|
||||||
TEXTURE_UNITS[ACTIVE_TEXTURE] = (TextureObject*) named_array_get(&TEXTURE_OBJECTS, texture);
|
TEXTURE_UNITS[ACTIVE_TEXTURE] = (TextureObject*) named_array_get(&TEXTURE_OBJECTS, texture);
|
||||||
|
|
||||||
// If this is a paletted texture, we need to reapply the color table
|
|
||||||
_glApplyColorTable();
|
|
||||||
} else {
|
} else {
|
||||||
TEXTURE_UNITS[ACTIVE_TEXTURE] = NULL;
|
TEXTURE_UNITS[ACTIVE_TEXTURE] = NULL;
|
||||||
}
|
}
|
||||||
|
@ -947,20 +963,30 @@ GLAPI void APIENTRY glColorTableEXT(GLenum target, GLenum internalFormat, GLsize
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureObject* active = getBoundTexture();
|
TexturePalette* palette = NULL;
|
||||||
if(active->palette) {
|
|
||||||
free(active->palette->data);
|
if(target == GL_SHARED_TEXTURE_PALETTE_EXT) {
|
||||||
active->palette->data = NULL;
|
palette = SHARED_PALETTE;
|
||||||
} else {
|
} else {
|
||||||
active->palette = (TexturePalette*) malloc(sizeof(TexturePalette));
|
TextureObject* active = getBoundTexture();
|
||||||
|
if(!active->palette) {
|
||||||
|
active->palette = (TexturePalette*) malloc(sizeof(TexturePalette));
|
||||||
|
}
|
||||||
|
|
||||||
|
palette = active->palette;
|
||||||
}
|
}
|
||||||
|
|
||||||
active->palette->data = (GLubyte*) malloc(width * 4);
|
if(target) {
|
||||||
active->palette->format = format;
|
free(palette->data);
|
||||||
active->palette->width = width;
|
palette->data = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
palette->data = (GLubyte*) malloc(width * 4);
|
||||||
|
palette->format = format;
|
||||||
|
palette->width = width;
|
||||||
|
|
||||||
GLubyte* src = (GLubyte*) data;
|
GLubyte* src = (GLubyte*) data;
|
||||||
GLubyte* dst = (GLubyte*) active->palette->data;
|
GLubyte* dst = (GLubyte*) palette->data;
|
||||||
|
|
||||||
/* Transform and copy the source palette to the texture */
|
/* Transform and copy the source palette to the texture */
|
||||||
GLushort i = 0;
|
GLushort i = 0;
|
||||||
|
@ -970,9 +996,6 @@ GLAPI void APIENTRY glColorTableEXT(GLenum target, GLenum internalFormat, GLsize
|
||||||
src += sourceStride;
|
src += sourceStride;
|
||||||
dst += 4;
|
dst += 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Apply the palette immediately, we'll also do this when binding the texture */
|
|
||||||
_glApplyColorTable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLAPI void APIENTRY glColorSubTableEXT(GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data) {
|
GLAPI void APIENTRY glColorSubTableEXT(GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data) {
|
||||||
|
|
|
@ -153,6 +153,8 @@ GLAPI GLboolean APIENTRY glIsFramebufferEXT(GLuint framebuffer);
|
||||||
|
|
||||||
#define GL_TEXTURE_INDEX_SIZE_EXT 0x80ED
|
#define GL_TEXTURE_INDEX_SIZE_EXT 0x80ED
|
||||||
|
|
||||||
|
#define GL_SHARED_TEXTURE_PALETTE_EXT 0x81FB
|
||||||
|
|
||||||
GLAPI void APIENTRY glColorTableEXT(GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const GLvoid *data);
|
GLAPI void APIENTRY glColorTableEXT(GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const GLvoid *data);
|
||||||
GLAPI void APIENTRY glColorSubTableEXT(GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data);
|
GLAPI void APIENTRY glColorSubTableEXT(GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data);
|
||||||
GLAPI void APIENTRY glGetColorTableEXT(GLenum target, GLenum format, GLenum type, GLvoid *data);
|
GLAPI void APIENTRY glGetColorTableEXT(GLenum target, GLenum format, GLenum type, GLvoid *data);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user