From 3df4244bc24235629621e4c9281d135ed5e281d8 Mon Sep 17 00:00:00 2001 From: Josh Pearson Date: Wed, 9 Sep 2015 11:25:51 -0700 Subject: [PATCH] Formatting cleanup, and cleanup on gl-fog.c --- gl-api.c | 32 ++++------ gl-arrays.c | 47 ++++++-------- gl-cap.c | 28 ++++----- gl-fog.c | 79 +++++++++++------------- gl-light.c | 6 +- gl-matrix.c | 8 +-- gl-pvr.c | 10 +-- gl-rgb.c | 168 ++++++++++++++++++++++----------------------------- gl-rgb.h | 4 +- gl-texture.c | 63 +++++++++---------- 10 files changed, 197 insertions(+), 248 deletions(-) diff --git a/gl-api.c b/gl-api.c index dedfa6b..0f54352 100755 --- a/gl-api.c +++ b/gl-api.c @@ -267,27 +267,25 @@ void APIENTRY glColor4fv(const GLfloat *rgba) { //== Texture Coordinate Submission ==// void APIENTRY glTexCoord2f(GLfloat u, GLfloat v) { - if(_glKosEnabledTextureMatrix()) - { + if(_glKosEnabledTextureMatrix()) { _glKosMatrixLoadTexture(); mat_trans_texture2_nomod(u, v, GL_KOS_VERTEX_UV[0], GL_KOS_VERTEX_UV[1]); - + _glKosMatrixLoadRender(); } else { GL_KOS_VERTEX_UV[0] = u; GL_KOS_VERTEX_UV[1] = v; - } + } } void APIENTRY glTexCoord2fv(const GLfloat *uv) { - if(_glKosEnabledTextureMatrix()) - { + if(_glKosEnabledTextureMatrix()) { _glKosMatrixLoadTexture(); - + mat_trans_texture2_nomod(uv[0], uv[1], GL_KOS_VERTEX_UV[0], GL_KOS_VERTEX_UV[1]); - + _glKosMatrixLoadRender(); } else { @@ -946,32 +944,26 @@ GLuint _glKosVertexColor() { return GL_KOS_VERTEX_COLOR; } -void glAlphaFunc(GLenum func, GLclampf ref) -{ +void glAlphaFunc(GLenum func, GLclampf ref) { ; } -void glLineWidth(GLfloat width) -{ +void glLineWidth(GLfloat width) { ; } -void glPolygonOffset(GLfloat factor, GLfloat units) -{ +void glPolygonOffset(GLfloat factor, GLfloat units) { ; } -void glGetTexParameteriv(GLenum target, GLenum pname, GLint * params) -{ +void glGetTexParameteriv(GLenum target, GLenum pname, GLint *params) { ; } -void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) -{ +void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) { ; } -void glPixelStorei(GLenum pname, GLint param) -{ +void glPixelStorei(GLenum pname, GLint param) { ; } diff --git a/gl-arrays.c b/gl-arrays.c index 3deee29..7a4cbe4 100755 --- a/gl-arrays.c +++ b/gl-arrays.c @@ -461,18 +461,16 @@ static inline void _glKosElementTexCoord2fU16(pvr_vertex_t *dst, GLuint count) { GLuint i, index; GLfloat *t = GL_KOS_TEXCOORD0_POINTER; - if(_glKosEnabledTextureMatrix()) - { + if(_glKosEnabledTextureMatrix()) { _glKosMatrixLoadTexture(); - - for(i = 0; i < count; i++) - { + + for(i = 0; i < count; i++) { index = GL_KOS_INDEX_POINTER_U16[i] * GL_KOS_TEXCOORD0_STRIDE; - + mat_trans_texture2_nomod(t[index], t[index + 1], dst[i].u, dst[i].v); } - - _glKosMatrixLoadRender(); + + _glKosMatrixLoadRender(); } else { for(i = 0; i < count; i++) { @@ -487,18 +485,16 @@ static inline void _glKosElementTexCoord2fU8(pvr_vertex_t *dst, GLuint count) { GLuint i, index; GLfloat *t = GL_KOS_TEXCOORD0_POINTER; - if(_glKosEnabledTextureMatrix()) - { + if(_glKosEnabledTextureMatrix()) { _glKosMatrixLoadTexture(); - - for(i = 0; i < count; i++) - { + + for(i = 0; i < count; i++) { index = GL_KOS_INDEX_POINTER_U8[i] * GL_KOS_TEXCOORD0_STRIDE; - + mat_trans_texture2_nomod(t[index], t[index + 1], dst[i].u, dst[i].v); } - - _glKosMatrixLoadRender(); + + _glKosMatrixLoadRender(); } else { for(i = 0; i < count; i++) { @@ -1050,22 +1046,19 @@ static inline void _glKosArrayColor4f(pvr_vertex_t *dst, GLuint count) { static inline void _glKosArrayTexCoord2f(pvr_vertex_t *dst, GLuint count) { GLuint i; GLfloat *uv = GL_KOS_TEXCOORD0_POINTER; - - if(_glKosEnabledTextureMatrix()) - { + + if(_glKosEnabledTextureMatrix()) { _glKosMatrixLoadTexture(); - - for(i = 0; i < count; i++) - { + + for(i = 0; i < count; i++) { mat_trans_texture2_nomod(uv[0], uv[1], dst[i].u, dst[i].v); - + uv += GL_KOS_TEXCOORD0_STRIDE; } - - _glKosMatrixLoadRender(); + + _glKosMatrixLoadRender(); } - else - { + else { for(i = 0; i < count; i++) { dst[i].u = uv[0]; dst[i].v = uv[1]; diff --git a/gl-cap.c b/gl-cap.c index 10e2617..af4ac60 100755 --- a/gl-cap.c +++ b/gl-cap.c @@ -67,7 +67,7 @@ void APIENTRY glEnable(GLenum cap) { case GL_CULL_FACE: GL_KOS_ENABLE_CAP |= GL_KOS_ENABLE_CULLING; break; - + case GL_KOS_TEXTURE_MATRIX: GL_KOS_ENABLE_CAP |= GL_KOS_ENABLE_TEXTURE_MAT; break; @@ -110,7 +110,7 @@ void APIENTRY glDisable(GLenum cap) { case GL_CULL_FACE: GL_KOS_ENABLE_CAP &= ~GL_KOS_ENABLE_CULLING; break; - + case GL_KOS_TEXTURE_MATRIX: GL_KOS_ENABLE_CAP &= ~GL_KOS_ENABLE_TEXTURE_MAT; break; @@ -144,7 +144,7 @@ GLboolean APIENTRY glIsEnabled(GLenum cap) { case GL_BLEND: return _glKosEnabledBlend() ? GL_TRUE : GL_FALSE; - + case GL_KOS_TEXTURE_MATRIX: return _glKosEnabledTextureMatrix() ? GL_TRUE : GL_FALSE; } @@ -228,23 +228,21 @@ void APIENTRY glGetFloatv(GLenum pname, GLfloat *params) { } } -const GLbyte* glGetString(GLenum name) -{ - switch(name) - { +const GLbyte *glGetString(GLenum name) { + switch(name) { case GL_VENDOR: - return "KallistiOS"; - + return "KallistiOS"; + case GL_RENDERER: - return "PowerVR2 CLX2 100mHz"; - + return "PowerVR2 CLX2 100mHz"; + case GL_VERSION: - return "KGL 1.x"; - + return "KGL 1.x"; + case GL_EXTENSIONS: - return "GL_ARB_framebuffer_object, GL_ARB_multitexture"; + return "GL_ARB_framebuffer_object, GL_ARB_multitexture"; } - + return "GL_KOS_ERROR: ENUM Unsupported\n"; } diff --git a/gl-fog.c b/gl-fog.c index 82dcd4b..71eb36b 100755 --- a/gl-fog.c +++ b/gl-fog.c @@ -11,92 +11,85 @@ #include "gl.h" -static GLuint FOG_MODE = GL_EXP; /* GL_LINEAR, GL_EXP, or GL_EXP2 FOG */ -static GLfloat FOG_DENSITY = 1.0f, /* Density - GL_EXP, or GL_EXP2 FOG */ - FOG_START = 0.0f, /* Linear FOG */ - FOG_END = 1.0f; /* Linear FOG */ +static GLuint GL_KOS_FOG_MODE = GL_EXP; /* GL_LINEAR, GL_EXP, or GL_EXP2 FOG */ +static GLfloat GL_KOS_FOG_DENSITY = 1.0f, /* Density - GL_EXP, or GL_EXP2 FOG */ + GL_KOS_FOG_START = 0.0f, /* Linear FOG */ + GL_KOS_FOG_END = 1.0f; /* Linear FOG */ void APIENTRY glFogi(GLenum pname, GLint param) { switch(pname) { case GL_FOG_MODE: switch(param) { case GL_LINEAR: - return pvr_fog_table_linear(FOG_START, FOG_END); + pvr_fog_table_linear(GL_KOS_FOG_START, GL_KOS_FOG_END); + break; case GL_EXP: - return pvr_fog_table_exp(FOG_DENSITY); + pvr_fog_table_exp(GL_KOS_FOG_DENSITY); + break; case GL_EXP2: - return pvr_fog_table_exp2(FOG_DENSITY); - - default: - return; + pvr_fog_table_exp2(GL_KOS_FOG_DENSITY); + break; } - - default: - return; } } void APIENTRY glFogf(GLenum pname, GLfloat param) { switch(pname) { case GL_FOG_START: - FOG_START = param; + GL_KOS_FOG_START = param; - if(FOG_MODE == GL_LINEAR) - return pvr_fog_table_linear(FOG_START, FOG_END); + if(GL_KOS_FOG_MODE == GL_LINEAR) + pvr_fog_table_linear(GL_KOS_FOG_START, GL_KOS_FOG_END); - return; + break; case GL_FOG_END: - FOG_END = param; + GL_KOS_FOG_END = param; - if(FOG_MODE == GL_LINEAR) - return pvr_fog_table_linear(FOG_START, FOG_END); + if(GL_KOS_FOG_MODE == GL_LINEAR) + pvr_fog_table_linear(GL_KOS_FOG_START, GL_KOS_FOG_END); - return; + break; case GL_FOG_DENSITY: - FOG_DENSITY = param; + GL_KOS_FOG_DENSITY = param; - if(FOG_MODE == GL_EXP) - return pvr_fog_table_exp(FOG_DENSITY); + if(GL_KOS_FOG_MODE == GL_EXP) + pvr_fog_table_exp(GL_KOS_FOG_DENSITY); - if(FOG_MODE == GL_EXP2) - return pvr_fog_table_exp2(FOG_DENSITY); + else if(GL_KOS_FOG_MODE == GL_EXP2) + pvr_fog_table_exp2(GL_KOS_FOG_DENSITY); - return; - - default: - return; + break; } } void APIENTRY glFogfv(GLenum pname, const GLfloat *params) { switch(pname) { case GL_FOG_MODE: - return glFogi(pname, (GLint) * params); + glFogi(pname, (GLint) * params); + break; case GL_FOG_DENSITY: - FOG_DENSITY = *params; + GL_KOS_FOG_DENSITY = *params; - if(FOG_MODE == GL_EXP) - return pvr_fog_table_exp(FOG_DENSITY); + if(GL_KOS_FOG_MODE == GL_EXP) + pvr_fog_table_exp(GL_KOS_FOG_DENSITY); - if(FOG_MODE == GL_EXP2) - return pvr_fog_table_exp2(FOG_DENSITY); + else if(GL_KOS_FOG_MODE == GL_EXP2) + pvr_fog_table_exp2(GL_KOS_FOG_DENSITY); - return; + break; case GL_FOG_START: case GL_FOG_END: - return glFogf(pname, *params); + glFogf(pname, *params); + break; case GL_FOG_COLOR: - return pvr_fog_table_color(params[3], params[0], params[1], params[2]); - - case GL_FOG_INDEX: - default: - return; + pvr_fog_table_color(params[3], params[0], params[1], params[2]); + break; } } diff --git a/gl-light.c b/gl-light.c index 78f7fbc..b37ba98 100755 --- a/gl-light.c +++ b/gl-light.c @@ -76,7 +76,7 @@ void _glKosEnableLight(const GLuint light) { GL_LIGHT_ENABLED |= (1 << (light & 0xF)); } -/* Disable a light - GL_LIGHT0->GL_LIGHT7 */ +/* Disable a light - GL_LIGHT0->GL_LIGHT0 + GL_KOS_MAX_LIGHTS */ void _glKosDisableLight(const GLuint light) { if(light < GL_LIGHT0 || light > GL_LIGHT0 + GL_KOS_MAX_LIGHTS) { _glKosThrowError(GL_INVALID_ENUM, "glDisable(GL_LIGHT)"); @@ -152,7 +152,7 @@ static inline void glCopy3f(const float *src, float *dst) { /* GL Light Parameters ******************************************************/ void glLightfv(GLenum light, GLenum pname, const GLfloat *params) { - if(light < GL_LIGHT0 || light > GL_LIGHT7) return; + if(light < GL_LIGHT0 || light > GL_LIGHT0 + GL_KOS_MAX_LIGHTS) return; switch(pname) { case GL_AMBIENT: @@ -217,7 +217,7 @@ void glLightfv(GLenum light, GLenum pname, const GLfloat *params) { } void glLightf(GLenum light, GLenum pname, GLfloat param) { - if(light < GL_LIGHT0 || light > GL_LIGHT7) return; + if(light < GL_LIGHT0 || light > GL_LIGHT0 + GL_KOS_MAX_LIGHTS) return; switch(pname) { case GL_CONSTANT_ATTENUATION: diff --git a/gl-matrix.c b/gl-matrix.c index 1e9484a..b840d2d 100755 --- a/gl-matrix.c +++ b/gl-matrix.c @@ -123,11 +123,11 @@ void glScalef(GLfloat x, GLfloat y, GLfloat z) { mat_store(Matrix + MatrixMode); } -void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) { +void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) { float r = DEG2RAD * -angle; - - vec3f_normalize(x, y, z); - + + vec3f_normalize(x, y, z); + mat_load(Matrix + MatrixMode); mat_rotate(r * x, r * y, r * z); mat_store(Matrix + MatrixMode); diff --git a/gl-pvr.c b/gl-pvr.c index 0ecfbe2..106f531 100755 --- a/gl-pvr.c +++ b/gl-pvr.c @@ -87,7 +87,7 @@ static inline void pvr_hdr_submit(const GLuint *src) { d[5] = *(src++); d[6] = *(src++); d[7] = *(src++); - + asm("pref @%0" : : "r"(d)); } @@ -208,17 +208,17 @@ static inline void glutSwapBuffer() { PVR_DMA_TA, 1, NULL, 0); #else pvr_list_submit(_glKosVertexBufAddress(GL_KOS_LIST_OP), _glKosVertexBufCount(GL_KOS_LIST_OP)); -#endif +#endif pvr_list_finish(); pvr_list_begin(PVR_LIST_TR_POLY); #ifdef GL_KOS_USE_DMA pvr_dma_transfer(_glKosVertexBufAddress(GL_KOS_LIST_TR), 0, _glKosVertexBufCount(GL_KOS_LIST_TR) * 32, - PVR_DMA_TA, 1, NULL, 0); + PVR_DMA_TA, 1, NULL, 0); #else pvr_list_submit(_glKosVertexBufAddress(GL_KOS_LIST_TR), _glKosVertexBufCount(GL_KOS_LIST_TR)); -#endif +#endif /* Multi-Texture Pass - Modify U/V coords of submitted vertices */ GLuint i, v; glTexCoord *mt = _glKosMultiUVBufAddress(); @@ -236,7 +236,7 @@ static inline void glutSwapBuffer() { pvr_hdr_submit((GLuint *)&GL_MTOBJS[i].hdr); pvr_dma_transfer(GL_MTOBJS[i].src, 0, GL_MTOBJS[i].count * 32, PVR_DMA_TA, 1, NULL, 0); -#else +#else pvr_list_submit((pvr_poly_hdr_t *)&GL_MTOBJS[i].hdr, 1); pvr_list_submit((pvr_vertex_t *)GL_MTOBJS[i].src, GL_MTOBJS[i].count); #endif diff --git a/gl-rgb.c b/gl-rgb.c index 7c8f391..500555a 100755 --- a/gl-rgb.c +++ b/gl-rgb.c @@ -119,51 +119,45 @@ uint16 __glKosAverageBiPixelARGB4444(uint16 p1, uint16 p2) { //===================================================================================================// //== Colorspace Conversion ==// -static uint16 _glConvPixelRGBAU32(uint8 r, uint8 g, uint8 b, uint8 a) -{ +static uint16 _glConvPixelRGBAU32(uint8 r, uint8 g, uint8 b, uint8 a) { return (uint16)((a & RGB4_MAX) << ARGB4444_ALPHA_SHIFT) | - ((r & RGB4_MAX) << ARGB4444_RED_SHIFT) | - ((g & RGB4_MAX) << ARGB4444_GREEN_SHIFT) | - ((b & RGB4_MAX)); + ((r & RGB4_MAX) << ARGB4444_RED_SHIFT) | + ((g & RGB4_MAX) << ARGB4444_GREEN_SHIFT) | + ((b & RGB4_MAX)); } -static uint16 _glConvPixelRGBU24(uint8 r, uint8 g, uint8 b) -{ - return (uint16)((r & RGB5_MAX) << RGB565_RED_SHIFT) | - ((g & RGB6_MAX) << RGB565_GREEN_SHIFT) | - ((b & RGB5_MAX)); +static uint16 _glConvPixelRGBU24(uint8 r, uint8 g, uint8 b) { + return (uint16)((r & RGB5_MAX) << RGB565_RED_SHIFT) | + ((g & RGB6_MAX) << RGB565_GREEN_SHIFT) | + ((b & RGB5_MAX)); } -static void _glConvPixelsRGBF(int w, int h, float * src, uint16 * dst) -{ +static void _glConvPixelsRGBF(int w, int h, float *src, uint16 *dst) { int i; - for(i = 0; i < w * h; i++) - { + + for(i = 0; i < w * h; i++) { dst[i] = _glConvPixelRGBU24((uint8)(src[i * 3 + 0] * RGB5_MAX), (uint8)(src[i * 3 + 1] * RGB6_MAX), (uint8)(src[i * 3 + 2] * RGB5_MAX)); - } + } } -static void _glConvPixelsRGBAF(int w, int h, float * src, uint16 * dst) -{ +static void _glConvPixelsRGBAF(int w, int h, float *src, uint16 *dst) { int i; - for(i = 0; i < w * h; i++) - { + + for(i = 0; i < w * h; i++) { dst[i] = _glConvPixelRGBAU32((uint8)(src[i * 4 + 0] * RGB4_MAX), (uint8)(src[i * 4 + 1] * RGB4_MAX), (uint8)(src[i * 4 + 2] * RGB4_MAX), (uint8)(src[i * 4 + 3] * RGB4_MAX)); - } + } } -static void _glConvPixelsRGBU24(int w, int h, uint8 * src, uint16 * dst) -{ +static void _glConvPixelsRGBU24(int w, int h, uint8 *src, uint16 *dst) { unsigned char r, g, b; int i; - - for(i = 0; i < w * h; i++) - { + + for(i = 0; i < w * h; i++) { r = (src[i * 3 + 0] * RGB5_MAX) / RGB8_MAX; g = (src[i * 3 + 1] * RGB6_MAX) / RGB8_MAX; b = (src[i * 3 + 2] * RGB5_MAX) / RGB8_MAX; @@ -172,13 +166,11 @@ static void _glConvPixelsRGBU24(int w, int h, uint8 * src, uint16 * dst) } } -static void _glConvPixelsRGBAU32(int w, int h, uint8 * src, uint16 * dst) -{ +static void _glConvPixelsRGBAU32(int w, int h, uint8 *src, uint16 *dst) { unsigned char r, g, b, a; int i; - - for(i = 0; i < w * h; i++) - { + + for(i = 0; i < w * h; i++) { r = (src[i * 4 + 0] * RGB4_MAX) / RGB8_MAX; g = (src[i * 4 + 1] * RGB4_MAX) / RGB8_MAX; b = (src[i * 4 + 2] * RGB4_MAX) / RGB8_MAX; @@ -188,13 +180,11 @@ static void _glConvPixelsRGBAU32(int w, int h, uint8 * src, uint16 * dst) } } -static void _glConvPixelsRGBS24(int w, int h, int8 * src, uint16 * dst) -{ +static void _glConvPixelsRGBS24(int w, int h, int8 *src, uint16 *dst) { unsigned char r, g, b; int i; - - for(i = 0; i < w * h; i++) - { + + for(i = 0; i < w * h; i++) { r = ((src[i * 3 + 0] + S8_NEG_OFT) * RGB5_MAX) / RGB8_MAX; g = ((src[i * 3 + 1] + S8_NEG_OFT) * RGB6_MAX) / RGB8_MAX; b = ((src[i * 3 + 2] + S8_NEG_OFT) * RGB5_MAX) / RGB8_MAX; @@ -203,13 +193,11 @@ static void _glConvPixelsRGBS24(int w, int h, int8 * src, uint16 * dst) } } -static void _glConvPixelsRGBAS32(int w, int h, int8 * src, uint16 * dst) -{ +static void _glConvPixelsRGBAS32(int w, int h, int8 *src, uint16 *dst) { unsigned char r, g, b, a; int i; - - for(i = 0; i < w * h; i++) - { + + for(i = 0; i < w * h; i++) { r = ((src[i * 4 + 0] + S8_NEG_OFT) * RGB4_MAX) / RGB8_MAX; g = ((src[i * 4 + 1] + S8_NEG_OFT) * RGB4_MAX) / RGB8_MAX; b = ((src[i * 4 + 2] + S8_NEG_OFT) * RGB4_MAX) / RGB8_MAX; @@ -219,13 +207,11 @@ static void _glConvPixelsRGBAS32(int w, int h, int8 * src, uint16 * dst) } } -static void _glConvPixelsRGBS48(int w, int h, int16 * src, uint16 * dst) -{ +static void _glConvPixelsRGBS48(int w, int h, int16 *src, uint16 *dst) { unsigned char r, g, b; int i; - - for(i = 0; i < w * h; i++) - { + + for(i = 0; i < w * h; i++) { r = ((src[i * 3 + 0] + S16_NEG_OFT) * RGB5_MAX) / RGB16_MAX; g = ((src[i * 3 + 1] + S16_NEG_OFT) * RGB6_MAX) / RGB16_MAX; b = ((src[i * 3 + 2] + S16_NEG_OFT) * RGB5_MAX) / RGB16_MAX; @@ -234,13 +220,11 @@ static void _glConvPixelsRGBS48(int w, int h, int16 * src, uint16 * dst) } } -static void _glConvPixelsRGBAS64(int w, int h, int16 * src, uint16 * dst) -{ +static void _glConvPixelsRGBAS64(int w, int h, int16 *src, uint16 *dst) { unsigned char r, g, b, a; int i; - - for(i = 0; i < w * h; i++) - { + + for(i = 0; i < w * h; i++) { r = ((src[i * 4 + 0] + S16_NEG_OFT) * RGB4_MAX) / RGB16_MAX; g = ((src[i * 4 + 1] + S16_NEG_OFT) * RGB4_MAX) / RGB16_MAX; b = ((src[i * 4 + 2] + S16_NEG_OFT) * RGB4_MAX) / RGB16_MAX; @@ -250,13 +234,11 @@ static void _glConvPixelsRGBAS64(int w, int h, int16 * src, uint16 * dst) } } -static void _glConvPixelsRGBU48(int w, int h, uint16 * src, uint16 * dst) -{ +static void _glConvPixelsRGBU48(int w, int h, uint16 *src, uint16 *dst) { unsigned char r, g, b; int i; - - for(i = 0; i < w * h; i++) - { + + for(i = 0; i < w * h; i++) { r = ((src[i * 3 + 0]) * RGB5_MAX) / RGB16_MAX; g = ((src[i * 3 + 1]) * RGB6_MAX) / RGB16_MAX; b = ((src[i * 3 + 2]) * RGB5_MAX) / RGB16_MAX; @@ -265,13 +247,11 @@ static void _glConvPixelsRGBU48(int w, int h, uint16 * src, uint16 * dst) } } -static void _glConvPixelsRGBAU64(int w, int h, uint16 * src, uint16 * dst) -{ +static void _glConvPixelsRGBAU64(int w, int h, uint16 *src, uint16 *dst) { unsigned char r, g, b, a; int i; - - for(i = 0; i < w * h; i++) - { + + for(i = 0; i < w * h; i++) { r = (src[i * 4 + 0] * RGB4_MAX) / RGB16_MAX; g = (src[i * 4 + 1] * RGB4_MAX) / RGB16_MAX; b = (src[i * 4 + 2] * RGB4_MAX) / RGB16_MAX; @@ -281,54 +261,50 @@ static void _glConvPixelsRGBAU64(int w, int h, uint16 * src, uint16 * dst) } } -void _glPixelConvertRGB(int format, int w, int h, void * src, uint16 * dst) -{ - switch(format) - { +void _glPixelConvertRGB(int format, int w, int h, void *src, uint16 *dst) { + switch(format) { case GL_BYTE: - _glConvPixelsRGBS24(w, h, (int8 *)src, dst); - break; - + _glConvPixelsRGBS24(w, h, (int8 *)src, dst); + break; + case GL_UNSIGNED_BYTE: - _glConvPixelsRGBU24(w, h, (uint8 *)src, dst); - break; - + _glConvPixelsRGBU24(w, h, (uint8 *)src, dst); + break; + case GL_SHORT: - _glConvPixelsRGBS48(w, h, (int16 *)src, dst); - break; - + _glConvPixelsRGBS48(w, h, (int16 *)src, dst); + break; + case GL_UNSIGNED_SHORT: - _glConvPixelsRGBU48(w, h, (uint16 *)src, dst); - break; - + _glConvPixelsRGBU48(w, h, (uint16 *)src, dst); + break; + case GL_FLOAT: - _glConvPixelsRGBF(w, h, (float *)src, dst); - break; + _glConvPixelsRGBF(w, h, (float *)src, dst); + break; } } -void _glPixelConvertRGBA(int format, int w, int h, void * src, uint16 * dst) -{ - switch(format) - { +void _glPixelConvertRGBA(int format, int w, int h, void *src, uint16 *dst) { + switch(format) { case GL_BYTE: - _glConvPixelsRGBAS32(w, h, (int8 *)src, dst); - break; - + _glConvPixelsRGBAS32(w, h, (int8 *)src, dst); + break; + case GL_UNSIGNED_BYTE: - _glConvPixelsRGBAU32(w, h, (uint8 *)src, dst); - break; - + _glConvPixelsRGBAU32(w, h, (uint8 *)src, dst); + break; + case GL_SHORT: - _glConvPixelsRGBAS64(w, h, (int16 *)src, dst); - break; - + _glConvPixelsRGBAS64(w, h, (int16 *)src, dst); + break; + case GL_UNSIGNED_SHORT: - _glConvPixelsRGBAU64(w, h, (uint16 *)src, dst); - break; - + _glConvPixelsRGBAU64(w, h, (uint16 *)src, dst); + break; + case GL_FLOAT: - _glConvPixelsRGBAF(w, h, (float *)src, dst); - break; + _glConvPixelsRGBAF(w, h, (float *)src, dst); + break; } } diff --git a/gl-rgb.h b/gl-rgb.h index 9a4cb73..3d4632e 100755 --- a/gl-rgb.h +++ b/gl-rgb.h @@ -64,7 +64,7 @@ typedef GLfloat GLrgba4f[4]; #define S8_NEG_OFT 128 // Absolute Value of Minimum 8bit Signed Range // #define S16_NEG_OFT 32768 // Absolute Value of Minimum bit Signed Range // -void _glPixelConvertRGB(int format, int w, int h, void * src, uint16 * dst); -void _glPixelConvertRGBA(int format, int w, int h, void * src, uint16 * dst); +void _glPixelConvertRGB(int format, int w, int h, void *src, uint16 *dst); +void _glPixelConvertRGBA(int format, int w, int h, void *src, uint16 *dst); #endif diff --git a/gl-texture.c b/gl-texture.c index fa5a3ef..80c4ffa 100755 --- a/gl-texture.c +++ b/gl-texture.c @@ -254,43 +254,40 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat, GL_KOS_TEXTURE_UNIT[GL_KOS_ACTIVE_TEXTURE]->data = pvr_mem_malloc(bytes); - if(data) - { - switch(type) - { + if(data) { + switch(type) { case GL_BYTE: /* Texture Formats that need conversion for PVR */ case GL_UNSIGNED_BYTE: case GL_SHORT: case GL_UNSIGNED_SHORT: - case GL_FLOAT: - { - uint16 *tex; + case GL_FLOAT: { + uint16 *tex; - tex = (uint16 *)malloc(width * height * sizeof(uint16)); - if(!tex) { - _glKosThrowError(GL_OUT_OF_MEMORY, "glTexImage2D"); - _glKosPrintError(); - return; - } + tex = (uint16 *)malloc(width * height * sizeof(uint16)); - switch(internalFormat) - { - case GL_RGB: - _glPixelConvertRGB(type, width, height, (void *)data, tex); - GL_KOS_TEXTURE_UNIT[GL_KOS_ACTIVE_TEXTURE]->color = (PVR_TXRFMT_RGB565 | PVR_TXRFMT_NONTWIDDLED); - sq_cpy(GL_KOS_TEXTURE_UNIT[GL_KOS_ACTIVE_TEXTURE]->data, tex, bytes); - break; + if(!tex) { + _glKosThrowError(GL_OUT_OF_MEMORY, "glTexImage2D"); + _glKosPrintError(); + return; + } - case GL_RGBA: - _glPixelConvertRGBA(type, width, height, (void *)data, tex); - GL_KOS_TEXTURE_UNIT[GL_KOS_ACTIVE_TEXTURE]->color = (PVR_TXRFMT_ARGB4444 | PVR_TXRFMT_NONTWIDDLED); - sq_cpy(GL_KOS_TEXTURE_UNIT[GL_KOS_ACTIVE_TEXTURE]->data, tex, bytes); - break; - } + switch(internalFormat) { + case GL_RGB: + _glPixelConvertRGB(type, width, height, (void *)data, tex); + GL_KOS_TEXTURE_UNIT[GL_KOS_ACTIVE_TEXTURE]->color = (PVR_TXRFMT_RGB565 | PVR_TXRFMT_NONTWIDDLED); + sq_cpy(GL_KOS_TEXTURE_UNIT[GL_KOS_ACTIVE_TEXTURE]->data, tex, bytes); + break; - free(tex); - } - break; + case GL_RGBA: + _glPixelConvertRGBA(type, width, height, (void *)data, tex); + GL_KOS_TEXTURE_UNIT[GL_KOS_ACTIVE_TEXTURE]->color = (PVR_TXRFMT_ARGB4444 | PVR_TXRFMT_NONTWIDDLED); + sq_cpy(GL_KOS_TEXTURE_UNIT[GL_KOS_ACTIVE_TEXTURE]->data, tex, bytes); + break; + } + + free(tex); + } + break; case GL_UNSIGNED_SHORT_5_6_5: /* Texture Formats that do not need conversion */ case GL_UNSIGNED_SHORT_5_6_5_TWID: @@ -298,12 +295,12 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat, case GL_UNSIGNED_SHORT_1_5_5_5_TWID: case GL_UNSIGNED_SHORT_4_4_4_4: case GL_UNSIGNED_SHORT_4_4_4_4_TWID: - sq_cpy(GL_KOS_TEXTURE_UNIT[GL_KOS_ACTIVE_TEXTURE]->data, data, bytes); - break; + sq_cpy(GL_KOS_TEXTURE_UNIT[GL_KOS_ACTIVE_TEXTURE]->data, data, bytes); + break; default: /* Unsupported Texture Format */ - _glKosThrowError(GL_INVALID_OPERATION, "glTexImage2D"); - break; + _glKosThrowError(GL_INVALID_OPERATION, "glTexImage2D"); + break; } } }