diff --git a/GL/clip.c b/GL/clip.c index 4216577..a3b3d76 100644 --- a/GL/clip.c +++ b/GL/clip.c @@ -14,11 +14,11 @@ static unsigned char ZCLIP_ENABLED = 1; -unsigned char isClippingEnabled() { +unsigned char _glIsClippingEnabled() { return ZCLIP_ENABLED; } -void enableClipping(unsigned char v) { +void _glEnableClipping(unsigned char v) { ZCLIP_ENABLED = v; } diff --git a/GL/draw.c b/GL/draw.c index 8a5a26e..8748d01 100644 --- a/GL/draw.c +++ b/GL/draw.c @@ -19,7 +19,7 @@ static AttribPointer DIFFUSE_POINTER; static GLuint ENABLED_VERTEX_ATTRIBUTES = 0; static GLubyte ACTIVE_CLIENT_TEXTURE = 0; -void initAttributePointers() { +void _glInitAttributePointers() { TRACE(); VERTEX_POINTER.ptr = NULL; @@ -263,12 +263,12 @@ static inline IndexParseFunc _calcParseIndexFunc(GLenum type) { static inline void transformToEyeSpace(GLfloat* point) { - _matrixLoadModelView(); + _glMatrixLoadModelView(); mat_trans_single3_nodiv(point[0], point[1], point[2]); } static inline void transformNormalToEyeSpace(GLfloat* normal) { - _matrixLoadNormal(); + _glMatrixLoadNormal(); mat_trans_normal3(normal[0], normal[1], normal[2]); } @@ -933,7 +933,7 @@ static void transform(ClipVertex* output, const GLsizei count) { ClipVertex* vertex = output; - _applyRenderMatrix(); /* Apply the Render Matrix Stack */ + _glApplyRenderMatrix(); /* Apply the Render Matrix Stack */ GLsizei i = count; while(i--) { @@ -999,7 +999,7 @@ static void mat_transform_normal3(const float* xyz, const float* xyzOut, const u } static void light(ClipVertex* output, const GLsizei count) { - if(!isLightingEnabled()) { + if(!_glIsLightingEnabled()) { return; } @@ -1021,10 +1021,10 @@ static void light(ClipVertex* output, const GLsizei count) { ClipVertex* vertex = output; EyeSpaceData* eye_space = (EyeSpaceData*) eye_space_data->data; - _matrixLoadModelView(); + _glMatrixLoadModelView(); mat_transform3(vertex->xyz, eye_space->xyz, count, sizeof(ClipVertex), sizeof(EyeSpaceData)); - _matrixLoadNormal(); + _glMatrixLoadNormal(); mat_transform_normal3(vertex->nxyz, eye_space->n, count, sizeof(ClipVertex), sizeof(EyeSpaceData)); GLsizei i; @@ -1038,7 +1038,7 @@ static void light(ClipVertex* output, const GLsizei count) { GLfloat to_add [] = {0.0f, 0.0f, 0.0f, 0.0f}; GLubyte j; for(j = 0; j < MAX_LIGHTS; ++j) { - if(isLightEnabled(j)) { + if(_glIsLightEnabled(j)) { _glCalculateLightingContribution(j, ES->xyz, ES->n, vertex->bgra, to_add); total[0] += to_add[0]; @@ -1070,7 +1070,7 @@ static void divide(ClipVertex* output, const GLsizei count) { static void push(PVRHeader* header, ClipVertex* output, const GLsizei count, PolyList* activePolyList, GLshort textureUnit) { // Compile the header - pvr_poly_cxt_t cxt = *getPVRContext(); + pvr_poly_cxt_t cxt = *_glGetPVRContext(); cxt.list_type = activePolyList->list_type; _glUpdatePVRTextureContext(&cxt, textureUnit); @@ -1104,14 +1104,14 @@ static void submitVertices(GLenum mode, GLsizei first, GLsizei count, GLenum typ glActiveTextureARB(GL_TEXTURE1); glGetBooleanv(GL_TEXTURE_2D, &doMultitexture); - doLighting = isLightingEnabled(); + doLighting = _glIsLightingEnabled(); glActiveTextureARB(activeTexture); profiler_push(__func__); - PolyList* activeList = activePolyList(); + PolyList* activeList = _glActivePolyList(); /* Make room in the list buffer */ GLsizei spaceNeeded = (mode == GL_POLYGON || mode == GL_TRIANGLE_FAN) ? ((count - 2) * 3) : count; @@ -1139,7 +1139,7 @@ static void submitVertices(GLenum mode, GLsizei first, GLsizei count, GLenum typ profiler_checkpoint("transform"); - if(isClippingEnabled()) { + if(_glIsClippingEnabled()) { uint32_t offset = ((start - 1) - (ClipVertex*) activeList->vector.data); @@ -1183,7 +1183,7 @@ static void submitVertices(GLenum mode, GLsizei first, GLsizei count, GLenum typ profiler_checkpoint("divide"); - push(header, start, spaceNeeded, activePolyList(), 0); + push(header, start, spaceNeeded, _glActivePolyList(), 0); profiler_checkpoint("push"); /* @@ -1200,7 +1200,7 @@ static void submitVertices(GLenum mode, GLsizei first, GLsizei count, GLenum typ return; } - TextureObject* texture1 = getTexture1(); + TextureObject* texture1 = _glGetTexture1(); if(!texture1 || ((ENABLED_VERTEX_ATTRIBUTES & ST_ENABLED_FLAG) != ST_ENABLED_FLAG)) { /* Multitexture implicitly disabled */ @@ -1212,7 +1212,7 @@ static void submitVertices(GLenum mode, GLsizei first, GLsizei count, GLenum typ (hence the - 1) */ ClipVertex* vertex = aligned_vector_push_back( - &transparentPolyList()->vector, start - 1, spaceNeeded + 1 + &_glTransparentPolyList()->vector, start - 1, spaceNeeded + 1 ); PVRHeader* mtHeader = (PVRHeader*) vertex++; @@ -1240,7 +1240,7 @@ static void submitVertices(GLenum mode, GLsizei first, GLsizei count, GLenum typ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* Send the buffer again to the transparent list */ - push(mtHeader, mtStart, spaceNeeded, transparentPolyList(), 1); + push(mtHeader, mtStart, spaceNeeded, _glTransparentPolyList(), 1); /* Reset state */ glDepthFunc(depthFunc); @@ -1252,7 +1252,7 @@ static void submitVertices(GLenum mode, GLsizei first, GLsizei count, GLenum typ void APIENTRY glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices) { TRACE(); - if(checkImmediateModeInactive(__func__)) { + if(_glCheckImmediateModeInactive(__func__)) { return; } @@ -1262,7 +1262,7 @@ void APIENTRY glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvo void APIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei count) { TRACE(); - if(checkImmediateModeInactive(__func__)) { + if(_glCheckImmediateModeInactive(__func__)) { return; } diff --git a/GL/flush.c b/GL/flush.c index 0afd625..877e576 100644 --- a/GL/flush.c +++ b/GL/flush.c @@ -38,7 +38,7 @@ static void pvr_list_submit(void *src, int n) { d[0] = d[8] = 0; } -static void _initPVR() { +static void _glInitPVR() { pvr_init_params_t params = { /* Enable opaque and translucent polygons with size 32 and 32 */ { PVR_BINSIZE_32, PVR_BINSIZE_0, PVR_BINSIZE_32, PVR_BINSIZE_0, PVR_BINSIZE_32 }, @@ -52,31 +52,31 @@ static void _initPVR() { } -PolyList* activePolyList() { - if(isBlendingEnabled()) { +PolyList* _glActivePolyList() { + if(_glIsBlendingEnabled()) { return &TR_LIST; } else { return &OP_LIST; } } -PolyList *transparentPolyList() { +PolyList *_glTransparentPolyList() { return &TR_LIST; } void APIENTRY glKosInit() { TRACE(); - _initPVR(); + _glInitPVR(); - initMatrices(); - initAttributePointers(); + _glInitMatrices(); + _glInitAttributePointers(); _glInitContext(); _glInitLights(); - initImmediateMode(); - initFramebuffers(); + _glInitImmediateMode(); + _glInitFramebuffers(); - _glKosInitTextures(); + _glInitTextures(); OP_LIST.list_type = PVR_LIST_OP_POLY; PT_LIST.list_type = PVR_LIST_PT_POLY; diff --git a/GL/framebuffer.c b/GL/framebuffer.c index d06d72f..2e89999 100644 --- a/GL/framebuffer.c +++ b/GL/framebuffer.c @@ -16,11 +16,11 @@ static FrameBuffer* ACTIVE_FRAMEBUFFER = NULL; static NamedArray FRAMEBUFFERS; -void initFramebuffers() { +void _glInitFramebuffers() { named_array_init(&FRAMEBUFFERS, sizeof(FrameBuffer), 32); } -void wipeTextureOnFramebuffers(GLuint texture) { +void _glWipeTextureOnFramebuffers(GLuint texture) { /* Spec says we don't update inactive framebuffers, they'll presumably just cause * a GL_INVALID_OPERATION if we try to render to them */ if(ACTIVE_FRAMEBUFFER && ACTIVE_FRAMEBUFFER->texture_id == texture) { @@ -201,7 +201,7 @@ void APIENTRY glGenerateMipmapEXT(GLenum target) { return; } - TextureObject* tex = getBoundTexture(); + TextureObject* tex = _glGetBoundTexture(); if(!tex || !tex->data || !tex->mipmapCount) { _glKosThrowError(GL_INVALID_OPERATION, __func__); diff --git a/GL/immediate.c b/GL/immediate.c index 69a5fea..d805246 100644 --- a/GL/immediate.c +++ b/GL/immediate.c @@ -28,7 +28,7 @@ static GLfloat UV_COORD[2] = {0.0f, 0.0f}; static GLfloat ST_COORD[2] = {0.0f, 0.0f}; -void initImmediateMode() { +void _glInitImmediateMode() { aligned_vector_init(&VERTICES, sizeof(GLfloat)); aligned_vector_init(&COLOURS, sizeof(GLfloat)); aligned_vector_init(&UV_COORDS, sizeof(GLfloat)); @@ -36,7 +36,7 @@ void initImmediateMode() { aligned_vector_init(&NORMALS, sizeof(GLfloat)); } -GLubyte checkImmediateModeInactive(const char* func) { +GLubyte _glCheckImmediateModeInactive(const char* func) { /* Returns 1 on error */ if(IMMEDIATE_MODE_ACTIVE) { _glKosThrowError(GL_INVALID_OPERATION, func); diff --git a/GL/lighting.c b/GL/lighting.c index c1d1735..04d2a52 100644 --- a/GL/lighting.c +++ b/GL/lighting.c @@ -109,7 +109,7 @@ void APIENTRY glLightfv(GLenum light, GLenum pname, const GLfloat *params) { memcpy(LIGHTS[idx].specular, params, sizeof(GLfloat) * 4); break; case GL_POSITION: { - _matrixLoadModelView(); + _glMatrixLoadModelView(); memcpy(LIGHTS[idx].position, params, sizeof(GLfloat) * 4); LIGHTS[idx].is_directional = (params[3] == 0.0f) ? GL_TRUE : GL_FALSE; diff --git a/GL/matrix.c b/GL/matrix.c index f70aac8..084a660 100644 --- a/GL/matrix.c +++ b/GL/matrix.c @@ -41,7 +41,7 @@ matrix_t* _glGetProjectionMatrix() { return (matrix_t*) stack_top(&MATRIX_STACKS[1]); } -void initMatrices() { +void _glInitMatrices() { init_stack(&MATRIX_STACKS[0], sizeof(matrix_t), 32); init_stack(&MATRIX_STACKS[1], sizeof(matrix_t), 32); init_stack(&MATRIX_STACKS[2], sizeof(matrix_t), 32); @@ -389,20 +389,20 @@ void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez, GLfloat centerx, glhLookAtf2(eye, point, up); } -void _applyRenderMatrix() { +void _glApplyRenderMatrix() { mat_load(&SCREENVIEW_MATRIX); mat_apply(stack_top(MATRIX_STACKS + (GL_PROJECTION & 0xF))); mat_apply(stack_top(MATRIX_STACKS + (GL_MODELVIEW & 0xF))); } -void _matrixLoadTexture() { +void _glMatrixLoadTexture() { mat_load(stack_top(MATRIX_STACKS + (GL_TEXTURE & 0xF))); } -void _matrixLoadModelView() { +void _glMatrixLoadModelView() { mat_load(stack_top(MATRIX_STACKS + (GL_MODELVIEW & 0xF))); } -void _matrixLoadNormal() { +void _glMatrixLoadNormal() { mat_load(&NORMAL_MATRIX); } diff --git a/GL/private.h b/GL/private.h index 8fb07b0..1295878 100644 --- a/GL/private.h +++ b/GL/private.h @@ -93,28 +93,28 @@ typedef struct { } LightSource; -PolyList *activePolyList(); -PolyList *transparentPolyList(); +PolyList *_glActivePolyList(); +PolyList *_glTransparentPolyList(); -void initAttributePointers(); +void _glInitAttributePointers(); void _glInitContext(); void _glInitLights(); -void initImmediateMode(); -void initMatrices(); -void initFramebuffers(); +void _glInitImmediateMode(); +void _glInitMatrices(); +void _glInitFramebuffers(); -void _matrixLoadNormal(); -void _matrixLoadModelView(); -void _matrixLoadTexture(); -void _applyRenderMatrix(); +void _glMatrixLoadNormal(); +void _glMatrixLoadModelView(); +void _glMatrixLoadTexture(); +void _glApplyRenderMatrix(); matrix_t* _glGetProjectionMatrix(); -void wipeTextureOnFramebuffers(GLuint texture); -GLubyte checkImmediateModeInactive(const char* func); +void _glWipeTextureOnFramebuffers(GLuint texture); +GLubyte _glCheckImmediateModeInactive(const char* func); -pvr_poly_cxt_t* getPVRContext(); -GLubyte _glKosInitTextures(); +pvr_poly_cxt_t* _glGetPVRContext(); +GLubyte _glInitTextures(); void _glUpdatePVRTextureContext(pvr_poly_cxt_t* context, GLshort textureUnit); @@ -135,27 +135,27 @@ AttribPointer* _glGetUVAttribPointer(); AttribPointer* _glGetSTAttribPointer(); GLenum _glGetShadeModel(); -TextureObject* getTexture0(); -TextureObject* getTexture1(); -TextureObject* getBoundTexture(); +TextureObject* _glGetTexture0(); +TextureObject* _glGetTexture1(); +TextureObject* _glGetBoundTexture(); GLubyte _glGetActiveTexture(); GLuint _glGetActiveClientTexture(); GLboolean _glIsSharedTexturePaletteEnabled(); void _glApplyColorTable(); -GLboolean isBlendingEnabled(); +GLboolean _glIsBlendingEnabled(); GLboolean _glIsMipmapComplete(const TextureObject* obj); GLubyte* _glGetMipmapLocation(TextureObject* obj, GLuint level); GLuint _glGetMipmapLevelCount(TextureObject* obj); -GLboolean isLightingEnabled(); -GLboolean isLightEnabled(GLubyte light); +GLboolean _glIsLightingEnabled(); +GLboolean _glIsLightEnabled(GLubyte light); GLboolean _glIsColorMaterialEnabled(); void _glCalculateLightingContribution(const GLint light, const GLfloat* pos, const GLfloat* normal, uint8_t* bgra, GLfloat* colour); -unsigned char isClippingEnabled(); -void enableClipping(unsigned char v); +unsigned char _glIsClippingEnabled(); +void _glEnableClipping(unsigned char v); void _glKosThrowError(GLenum error, const char *function); void _glKosPrintError(); diff --git a/GL/state.c b/GL/state.c index 0e5a2c8..d7df94c 100644 --- a/GL/state.c +++ b/GL/state.c @@ -14,7 +14,7 @@ static pvr_poly_cxt_t GL_CONTEXT; -pvr_poly_cxt_t* getPVRContext() { +pvr_poly_cxt_t* _glGetPVRContext() { return &GL_CONTEXT; } @@ -80,7 +80,7 @@ static GLenum BLEND_SFACTOR = GL_ONE; static GLenum BLEND_DFACTOR = GL_ZERO; static GLboolean BLEND_ENABLED = GL_FALSE; -GLboolean isBlendingEnabled() { +GLboolean _glIsBlendingEnabled() { return BLEND_ENABLED; } @@ -147,7 +147,7 @@ GLboolean _glCheckValidEnum(GLint param, GLenum* values, const char* func) { static GLboolean TEXTURES_ENABLED [] = {GL_FALSE, GL_FALSE}; void _glUpdatePVRTextureContext(pvr_poly_cxt_t* context, GLshort textureUnit) { - const TextureObject *tx1 = (textureUnit == 0) ? getTexture0() : getTexture1(); + const TextureObject *tx1 = (textureUnit == 0) ? _glGetTexture0() : _glGetTexture1(); if(!TEXTURES_ENABLED[textureUnit] || !tx1) { context->txr.enable = PVR_TEXTURE_DISABLE; @@ -222,19 +222,16 @@ void _glUpdatePVRTextureContext(pvr_poly_cxt_t* context, GLshort textureUnit) { } else { context->txr.enable = PVR_TEXTURE_DISABLE; } - - /* Apply the texture palette if necessary */ - _glApplyColorTable(); } static GLboolean LIGHTING_ENABLED = GL_FALSE; static GLboolean LIGHT_ENABLED[MAX_LIGHTS]; -GLboolean isLightingEnabled() { +GLboolean _glIsLightingEnabled() { return LIGHTING_ENABLED; } -GLboolean isLightEnabled(unsigned char light) { +GLboolean _glIsLightEnabled(unsigned char light) { return LIGHT_ENABLED[light & 0xF]; } @@ -302,8 +299,12 @@ GLAPI void APIENTRY glEnable(GLenum cap) { case GL_COLOR_MATERIAL: COLOR_MATERIAL_ENABLED = GL_TRUE; break; - case GL_SHARED_TEXTURE_PALETTE_EXT: + case GL_SHARED_TEXTURE_PALETTE_EXT: { SHARED_PALETTE_ENABLED = GL_TRUE; + + /* Apply the texture palette if necessary */ + _glApplyColorTable(); + } break; case GL_LIGHT0: case GL_LIGHT1: @@ -316,7 +317,7 @@ GLAPI void APIENTRY glEnable(GLenum cap) { LIGHT_ENABLED[cap & 0xF] = GL_TRUE; break; case GL_NEARZ_CLIPPING_KOS: - enableClipping(GL_TRUE); + _glEnableClipping(GL_TRUE); break; default: break; @@ -352,8 +353,12 @@ GLAPI void APIENTRY glDisable(GLenum cap) { case GL_COLOR_MATERIAL: COLOR_MATERIAL_ENABLED = GL_FALSE; break; - case GL_SHARED_TEXTURE_PALETTE_EXT: + case GL_SHARED_TEXTURE_PALETTE_EXT: { SHARED_PALETTE_ENABLED = GL_FALSE; + + /* Restore whatever palette may exist on a bound texture */ + _glApplyColorTable(); + } break; case GL_LIGHT0: case GL_LIGHT1: @@ -366,7 +371,7 @@ GLAPI void APIENTRY glDisable(GLenum cap) { LIGHT_ENABLED[cap & 0xF] = GL_FALSE; break; case GL_NEARZ_CLIPPING_KOS: - enableClipping(GL_FALSE); + _glEnableClipping(GL_FALSE); break; default: break; @@ -486,7 +491,7 @@ void glPixelStorei(GLenum pname, GLint param) { */ void APIENTRY glScissor(GLint x, GLint y, GLsizei width, GLsizei height) { /*!!! FIXME: Shouldn't this be added to *all* lists? */ - PVRTileClipCommand *c = aligned_vector_extend(&activePolyList()->vector, 1); + PVRTileClipCommand *c = aligned_vector_extend(&_glActivePolyList()->vector, 1); GLint miny, maxx, maxy; GLsizei gl_scissor_width = CLAMP(width, 0, vid_mode->width); @@ -584,7 +589,7 @@ void APIENTRY glGetIntegerv(GLenum pname, GLint *params) { *params = MAX_LIGHTS; break; case GL_TEXTURE_BINDING_2D: - *params = getBoundTexture()->index; + *params = _glGetBoundTexture()->index; break; case GL_DEPTH_FUNC: *params = DEPTH_FUNC; diff --git a/GL/texture.c b/GL/texture.c index 3edbd02..677ed53 100644 --- a/GL/texture.c +++ b/GL/texture.c @@ -32,12 +32,14 @@ void _glApplyColorTable() { * - Store the active palette, don't resubmit eah time */ + static TexturePalette* last_bound = NULL; + TexturePalette* src = NULL; if(_glIsSharedTexturePaletteEnabled()) { src = SHARED_PALETTE; } else { - TextureObject* active = getBoundTexture(); + TextureObject* active = _glGetBoundTexture(); if(!active) { return; //? Unload the palette? Make White? @@ -50,6 +52,13 @@ void _glApplyColorTable() { src = active->palette; } + /* Don't reapply the palette if it was the last one we applied */ + if(src == last_bound) { + return; + } + + last_bound = src; + pvr_set_pal_format(PVR_PAL_ARGB8888); GLushort i = 0; @@ -133,22 +142,25 @@ static GLuint _glGetMipmapDataSize(TextureObject* obj) { return size; } -GLubyte _glKosInitTextures() { +GLubyte _glInitTextures() { named_array_init(&TEXTURE_OBJECTS, sizeof(TextureObject), MAX_TEXTURE_COUNT); + // Reserve zero so that it is never given to anyone as an ID! + named_array_reserve(&TEXTURE_OBJECTS, 0); + SHARED_PALETTE = (TexturePalette*) malloc(sizeof(TexturePalette)); return 1; } -TextureObject* getTexture0() { +TextureObject* _glGetTexture0() { return TEXTURE_UNITS[0]; } -TextureObject* getTexture1() { +TextureObject* _glGetTexture1() { return TEXTURE_UNITS[1]; } -TextureObject* getBoundTexture() { +TextureObject* _glGetBoundTexture() { return TEXTURE_UNITS[ACTIVE_TEXTURE]; } @@ -192,6 +204,9 @@ void APIENTRY glGenTextures(GLsizei n, GLuint *textures) { while(n--) { GLuint id = 0; TextureObject* txr = (TextureObject*) named_array_alloc(&TEXTURE_OBJECTS, &id); + + assert(id); // Generated IDs must never be zero + _glInitializeTextureObject(txr, id); *textures = id; @@ -207,7 +222,7 @@ void APIENTRY glDeleteTextures(GLsizei n, GLuint *textures) { TextureObject* txr = (TextureObject*) named_array_get(&TEXTURE_OBJECTS, *textures); /* Make sure we update framebuffer objects that have this texture attached */ - wipeTextureOnFramebuffers(*textures); + _glWipeTextureOnFramebuffers(*textures); if(txr == TEXTURE_UNITS[ACTIVE_TEXTURE]) { TEXTURE_UNITS[ACTIVE_TEXTURE] = NULL; @@ -219,7 +234,7 @@ void APIENTRY glDeleteTextures(GLsizei n, GLuint *textures) { } if(txr->palette && txr->palette->data) { - free(txr->palette->data); + pvr_mem_free(txr->palette->data); txr->palette->data = NULL; } @@ -243,12 +258,15 @@ void APIENTRY glBindTexture(GLenum target, GLuint texture) { if(texture) { /* If this didn't come from glGenTextures, then we should initialize the - * texture the first time it's bound */ + * texture the first time it's bound */ if(!named_array_used(&TEXTURE_OBJECTS, texture)) { TextureObject* txr = named_array_reserve(&TEXTURE_OBJECTS, texture); _glInitializeTextureObject(txr, texture); } TEXTURE_UNITS[ACTIVE_TEXTURE] = (TextureObject*) named_array_get(&TEXTURE_OBJECTS, texture); + + /* Apply the texture palette if necessary */ + _glApplyColorTable(); } else { TEXTURE_UNITS[ACTIVE_TEXTURE] = NULL; } @@ -521,7 +539,11 @@ static GLuint _determinePVRFormat(GLint internalFormat, GLenum type) { case GL_COMPRESSED_ARGB_1555_VQ_MIPMAP_TWID_KOS: return PVR_TXRFMT_ARGB1555 | PVR_TXRFMT_TWIDDLED | PVR_TXRFMT_VQ_ENABLE; case GL_COLOR_INDEX8_EXT: - return PVR_TXRFMT_PAL8BPP; + if(type == GL_UNSIGNED_BYTE_TWID_KOS) { + return PVR_TXRFMT_PAL8BPP | PVR_TXRFMT_TWIDDLED; + } else { + return PVR_TXRFMT_PAL8BPP | PVR_TXRFMT_NONTWIDDLED; + } default: return 0; } @@ -875,7 +897,7 @@ void APIENTRY glTexParameterf(GLenum target, GLenum pname, GLint param) { void APIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param) { TRACE(); - TextureObject* active = getBoundTexture(); + TextureObject* active = _glGetBoundTexture(); if(!active) { return; @@ -942,6 +964,10 @@ void APIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param) { } } +void APIENTRY glTexParameterf(GLenum target, GLenum pname, GLint param) { + glTexParameteri(target, pname, (GLint) param); +} + GLAPI void APIENTRY glColorTableEXT(GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const GLvoid *data) { GLenum validTargets[] = {GL_TEXTURE_2D, GL_SHARED_TEXTURE_PALETTE_EXT, 0}; GLenum validInternalFormats[] = {GL_RGB8, GL_RGBA8, 0}; @@ -990,7 +1016,7 @@ GLAPI void APIENTRY glColorTableEXT(GLenum target, GLenum internalFormat, GLsize if(target == GL_SHARED_TEXTURE_PALETTE_EXT) { palette = SHARED_PALETTE; } else { - TextureObject* active = getBoundTexture(); + TextureObject* active = _glGetBoundTexture(); if(!active->palette) { active->palette = (TexturePalette*) malloc(sizeof(TexturePalette)); } @@ -999,11 +1025,11 @@ GLAPI void APIENTRY glColorTableEXT(GLenum target, GLenum internalFormat, GLsize } if(target) { - free(palette->data); + pvr_mem_free(palette->data); palette->data = NULL; } - palette->data = (GLubyte*) malloc(width * 4); + palette->data = (GLubyte*) pvr_mem_malloc(width * 4); palette->format = format; palette->width = width; @@ -1018,6 +1044,9 @@ GLAPI void APIENTRY glColorTableEXT(GLenum target, GLenum internalFormat, GLsize src += sourceStride; dst += 4; } + + /* Apply the texture palette if necessary */ + _glApplyColorTable(); } GLAPI void APIENTRY glColorSubTableEXT(GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data) { diff --git a/containers/named_array.c b/containers/named_array.c index 0214b43..b05573e 100644 --- a/containers/named_array.c +++ b/containers/named_array.c @@ -42,7 +42,6 @@ void named_array_init(NamedArray* array, unsigned int element_size, unsigned int } char named_array_used(NamedArray* array, unsigned int id) { - unsigned int i = id / 8; unsigned int j = id % 8; @@ -54,11 +53,11 @@ void* named_array_alloc(NamedArray* array, unsigned int* new_id) { unsigned int i = 0, j = 0; for(i = 0; i < array->marker_count; ++i) { for(j = 0; j < 8; ++j) { - unsigned int id = (i * 8) + j + 1; + unsigned int id = (i * 8) + j; if(!named_array_used(array, id)) { array->used_markers[i] |= (unsigned char) 1 << j; *new_id = id; - unsigned char* ptr = &array->elements[(id - 1) * array->element_size]; + unsigned char* ptr = &array->elements[id * array->element_size]; memset(ptr, 0, array->element_size); return ptr; } @@ -76,7 +75,7 @@ void* named_array_reserve(NamedArray* array, unsigned int id) { array->used_markers[i] |= (unsigned char) 1 << j; assert(named_array_used(array, id)); - unsigned char* ptr = &array->elements[(id - 1) * array->element_size]; + unsigned char* ptr = &array->elements[id * array->element_size]; memset(ptr, 0, array->element_size); return ptr; } @@ -85,8 +84,6 @@ void* named_array_reserve(NamedArray* array, unsigned int id) { } void named_array_release(NamedArray* array, unsigned int new_id) { - new_id--; - unsigned int i = new_id / 8; unsigned int j = new_id % 8; @@ -102,7 +99,7 @@ void* named_array_get(NamedArray* array, unsigned int id) { return NULL; } - return &array->elements[(id - 1) * array->element_size]; + return &array->elements[id * array->element_size]; } void named_array_cleanup(NamedArray* array) { diff --git a/include/glkos.h b/include/glkos.h index a6602c0..c0da05c 100644 --- a/include/glkos.h +++ b/include/glkos.h @@ -32,6 +32,8 @@ __BEGIN_DECLS #define GL_NEARZ_CLIPPING_KOS 0xEEFA +#define GL_UNSIGNED_BYTE_TWID_KOS 0xEEFB + GLAPI void APIENTRY glKosSwapBuffers(); diff --git a/samples/paletted/main.c b/samples/paletted/main.c index 534d99e..da1501e 100644 --- a/samples/paletted/main.c +++ b/samples/paletted/main.c @@ -121,8 +121,8 @@ void LoadGLTextures() { // 2d texture, level of detail 0 (normal), 3 components (red, green, blue), x size from image, y size from image, // border 0 (normal), rgb color data, unsigned byte data, and finally the data itself. - glTexImage2D(GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, image1->width, image1->height, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, image1->data); -}; + glTexImage2D(GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, image1->width, image1->height, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE_TWID_KOS, image1->data); +} /* A general OpenGL initialization function. Sets all of the initial parameters. */ void InitGL(int Width, int Height) // We call this right after our OpenGL window is created.