From b6e9ff70b5413975cc40084a8dfd9a891741c690 Mon Sep 17 00:00:00 2001 From: "U-PH3NOM-PC\\PH3NOM" Date: Sun, 7 Sep 2014 15:41:26 -0700 Subject: [PATCH] Fixed bugs reported as of 9-06-2014 --- Makefile | 2 +- gl-api.c | 101 +------------------------------------------- gl-arrays.c | 25 +++++------ gl-rgb.c | 16 +++---- glu-texture.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/gl.h | 5 +-- 6 files changed, 138 insertions(+), 126 deletions(-) create mode 100755 glu-texture.c diff --git a/Makefile b/Makefile index b018d22..56756b9 100755 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ TARGET = libgl.a OBJS = gl-rgb.o gl-fog.o gl-sh4-light.o gl-light.o gl-clip.o gl-pvr.o -OBJS += gl-arrays.o gl-matrix.o gl-api.o +OBJS += gl-arrays.o gl-matrix.o gl-api.o glu-texture.o SUBDIRS = KOS_CFLAGS += -ffast-math -O3 -Iinclude diff --git a/gl-api.c b/gl-api.c index a53aacd..c1d1f52 100755 --- a/gl-api.c +++ b/gl-api.c @@ -193,22 +193,6 @@ static GLuint _glKosNextTexture() { return 0; /* Invalid Texture! */ } -GLuint glKosMipMapTexSize(GLuint width, GLuint height) { - GLuint b = 0; - - while(width >= 1 && height >= 1) { - b += width * height * 2; - - if(width >= 1) - width /= 2; - - if(height >= 1) - height /= 2; - } - - return b; -} - void glGenTextures(GLsizei n, GLuint *textures) { while(n--) *textures++ = _glKosNextTexture(); @@ -350,89 +334,6 @@ void glTexEnvf(GLenum target, GLenum pname, GLfloat param) { glTexEnvi(target, pname, param); } -GLint gluBuild2DBiMipmaps(GLenum target, GLint internalFormat, GLsizei width, - GLsizei height, GLenum format, GLenum type, const void *data) { - if(target != GL_TEXTURE_2D) - return -1; - - if(width < 1 || height < 1) - return 0; - - uint32 i = 0; - uint16 x , y; - - uint16 *src = (uint16 *)data; - uint16 *dst = (uint16 *)data + (width * height); - - for(y = 0; y < height; y += 2) { - for(x = 0; x < width; x += 2) { - switch(type) { - case GL_UNSIGNED_SHORT_5_6_5: - dst[i++] = __glKosAverageBiPixelRGB565(*src, *(src + 1)); - break; - - case GL_UNSIGNED_SHORT_4_4_4_4: - dst[i++] = __glKosAverageBiPixelARGB4444(*src, *(src + 1)); - break; - - case GL_UNSIGNED_SHORT_1_5_5_5: - dst[i++] = __glKosAverageBiPixelARGB1555(*src, *(src + 1)); - break; - } - - src += 2; - } - - src += width; - } - - return gluBuild2DBiMipmaps(target, internalFormat, width / 2, height / 2, - format, type, (uint16 *)data + (width * height)); -} - -GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, - GLsizei height, GLenum format, GLenum type, const void *data) { - if(target != GL_TEXTURE_2D) - return -1; - - if(width < 1 || height < 1) - return 0; - - if(width == 1 || height == 1) - return gluBuild2DBiMipmaps(target, internalFormat, width, height, format, type, data); - - uint32 i = 0; - uint16 x, y; - - uint16 *src = (uint16 *)data; - uint16 *dst = (uint16 *)data + (width * height); - - for(y = 0; y < height; y += 2) { - for(x = 0; x < width; x += 2) { - switch(type) { - case GL_UNSIGNED_SHORT_5_6_5: - dst[i++] = __glKosAverageQuadPixelRGB565(*src, *(src + 1), *(src + width), *(src + width + 1)); - break; - - case GL_UNSIGNED_SHORT_4_4_4_4: - dst[i++] = __glKosAverageQuadPixelARGB4444(*src, *(src + 1), *(src + width), *(src + width + 1)); - break; - - case GL_UNSIGNED_SHORT_1_5_5_5: - dst[i++] = __glKosAverageQuadPixelARGB1555(*src, *(src + 1), *(src + width), *(src + width + 1)); - break; - } - - src += 2; - } - - src += width; - } - - return gluBuild2DMipmaps(target, internalFormat, width / 2, height / 2, - format, type, (uint16 *)data + (width * height)); -} - /* Blending / Shading functions ********************************************************/ void glShadeModel(GLenum mode) { @@ -1022,7 +923,7 @@ void glBegin(unsigned int mode) { GL_VERTEX_MODE = mode; - GL_BOUND_TEX < 0 ? _glKosCompileHdr() : _glKosCompileHdrTx(); + !GL_TEXTURE_ENABLED ? _glKosCompileHdr() : _glKosCompileHdrTx(); if(GL_TEXTURE_ENABLED & GL_TEXTURE_1) _glKosCompileHdrTx2(); diff --git a/gl-arrays.c b/gl-arrays.c index a4f61ab..06f3597 100755 --- a/gl-arrays.c +++ b/gl-arrays.c @@ -43,7 +43,7 @@ static GLuint GL_VERTEX_PTR_MODE = 0; static GLuint GL_ARRAY_TEXTURE_ENABLED = 0; static GLuint GL_ARRAY_ACTIVE_TEXTURE = 0; -void glClientActiveTexture(GLenum texture) { +GLAPI void APIENTRY glClientActiveTexture(GLenum texture) { if(texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + GL_MAX_TEXTURE_UNITS) return; @@ -140,8 +140,8 @@ static inline void _glKosArraysTransformPositions(GLfloat *position, GLuint coun //== Open GL API Public Functions ==// /* Submit a Vertex Position Pointer */ -void glVertexPointer(GLint size, GLenum type, - GLsizei stride, const GLvoid *pointer) { +GLAPI void APIENTRY glVertexPointer(GLint size, GLenum type, + GLsizei stride, const GLvoid *pointer) { if(size != 3) return; /* Expect 3D X,Y,Z vertex... could do 2d X,Y later */ if(type != GL_FLOAT) return; /* Expect Floating point vertices */ @@ -154,10 +154,7 @@ void glVertexPointer(GLint size, GLenum type, } /* Submit a Vertex Normal Pointer */ -void glNormalPointer(GLint size, GLenum type, - GLsizei stride, const GLvoid *pointer) { - if(size != 3) return; - +GLAPI void APIENTRY glNormalPointer(GLenum type, GLsizei stride, const GLvoid *pointer) { if(type != GL_FLOAT) return; /* Expect Floating point vertices */ (stride) ? (GL_NORMAL_STRIDE = stride / 4) : (GL_NORMAL_STRIDE = 3); @@ -168,8 +165,8 @@ void glNormalPointer(GLint size, GLenum type, } /* Submit a Texture Coordinate Pointer */ -void glTexCoordPointer(GLint size, GLenum type, - GLsizei stride, const GLvoid *pointer) { +GLAPI void APIENTRY glTexCoordPointer(GLint size, GLenum type, + GLsizei stride, const GLvoid *pointer) { if(size != 2) return; /* Expect u and v */ if(type != GL_FLOAT) return; /* Expect Floating point vertices */ @@ -193,8 +190,8 @@ void glTexCoordPointer(GLint size, GLenum type, } /* Submit a Color Pointer */ -void glColorPointer(GLint size, GLenum type, - GLsizei stride, const GLvoid *pointer) { +GLAPI void APIENTRY glColorPointer(GLint size, GLenum type, + GLsizei stride, const GLvoid *pointer) { if((type == GL_UNSIGNED_INT) && (size == 1)) { GL_COLOR_COMPONENTS = 1; GL_COLOR_POINTER = (GLvoid *)pointer; @@ -639,7 +636,7 @@ void _glKosPrintErrorString(GLuint error) { //========================================================================================// //== OpenGL Elemental Array Submission ==// -void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices) { +GLAPI void APIENTRY glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices) { /* Before we process the vertex data, ensure all parameters are valid */ GLuint error = _glKosArraysVerifyParameter(mode, count, type, 1); @@ -909,9 +906,9 @@ static inline void _glKosArrayTexCoord2f(pvr_vertex_t *dst, GLuint count) { } //========================================================================================// -//== Openg GL Draw Arrays ==// +//== Open GL Draw Arrays ==// -void glDrawArrays(GLenum mode, GLint first, GLsizei count) { +GLAPI void APIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei count) { /* Before we process the vertex data, ensure all parameters are valid */ GLuint error = _glKosArraysVerifyParameter(mode, count, first, 0); diff --git a/gl-rgb.c b/gl-rgb.c index c63dd05..d2daca4 100755 --- a/gl-rgb.c +++ b/gl-rgb.c @@ -96,20 +96,20 @@ uint16 __glKosAverageBiPixelRGB565(uint16 p1, uint16 p2) { } uint16 __glKosAverageBiPixelARGB1555(uint16 p1, uint16 p2) { - uint8 A = (ARGB1555_ALPHA(p1) + ARGB1555_ALPHA(p2)) / 4; - uint8 R = (ARGB1555_RED(p1) + ARGB1555_RED(p2)) / 4; - uint8 G = (ARGB1555_GREEN(p1) + ARGB1555_GREEN(p2)) / 4; - uint8 B = (ARGB1555_BLUE(p1) + ARGB1555_BLUE(p2)) / 4; + uint8 A = (ARGB1555_ALPHA(p1) + ARGB1555_ALPHA(p2)) / 2; + uint8 R = (ARGB1555_RED(p1) + ARGB1555_RED(p2)) / 2; + uint8 G = (ARGB1555_GREEN(p1) + ARGB1555_GREEN(p2)) / 2; + uint8 B = (ARGB1555_BLUE(p1) + ARGB1555_BLUE(p2)) / 2; return ((A & RGB1_MAX) << ARGB1555_ALPHA_SHIFT) | ((R & RGB5_MAX) << ARGB1555_RED_SHIFT) | ((G & RGB5_MAX) << ARGB1555_GREEN_SHIFT) | (B & RGB5_MAX); } uint16 __glKosAverageBiPixelARGB4444(uint16 p1, uint16 p2) { - uint8 A = (ARGB4444_ALPHA(p1) + ARGB4444_ALPHA(p2)) / 4; - uint8 R = (ARGB4444_RED(p1) + ARGB4444_RED(p2)) / 4; - uint8 G = (ARGB4444_GREEN(p1) + ARGB4444_GREEN(p2)) / 4; - uint8 B = (ARGB4444_BLUE(p1) + ARGB4444_BLUE(p2)) / 4; + uint8 A = (ARGB4444_ALPHA(p1) + ARGB4444_ALPHA(p2)) / 2; + uint8 R = (ARGB4444_RED(p1) + ARGB4444_RED(p2)) / 2; + uint8 G = (ARGB4444_GREEN(p1) + ARGB4444_GREEN(p2)) / 2; + uint8 B = (ARGB4444_BLUE(p1) + ARGB4444_BLUE(p2)) / 2; return ((A & RGB4_MAX) << ARGB4444_ALPHA_SHIFT) | ((R & RGB4_MAX) << ARGB4444_RED_SHIFT) | ((G & RGB4_MAX) << ARGB4444_GREEN_SHIFT) | (B & RGB4_MAX); diff --git a/glu-texture.c b/glu-texture.c new file mode 100755 index 0000000..7b08eac --- /dev/null +++ b/glu-texture.c @@ -0,0 +1,115 @@ +/* KallistiGL for KallistiOS ##version## + + libgl/glu-texture.c + Copyright (C) 2013-2014 Josh "PH3NOM" Pearson + + A set of functions for working with ARGB pixel data, used by gluBuild2DMipmaps(...). +*/ + +#include "gl.h" +#include "gl-api.h" +#include "gl-rgb.h" +#include "glu.h" + +GLAPI GLuint APIENTRY glKosMipMapTexSize(GLuint width, GLuint height) { + GLuint b = 0; + + while(width >= 1 && height >= 1) { + b += width * height * 2; + + if(width >= 1) + width /= 2; + + if(height >= 1) + height /= 2; + } + + return b; +} + +static GLint gluBuild2DBiMipmaps(GLenum target, GLint internalFormat, GLsizei width, + GLsizei height, GLenum format, GLenum type, const void *data) { + if(target != GL_TEXTURE_2D) + return -1; + + if(width < 1 || height < 1) + return 0; + + uint32 i = 0; + uint16 x , y; + + uint16 *src = (uint16 *)data; + uint16 *dst = (uint16 *)data + (width * height); + + for(y = 0; y < height; y += 2) { + for(x = 0; x < width; x += 2) { + switch(type) { + case GL_UNSIGNED_SHORT_5_6_5: + dst[i++] = __glKosAverageBiPixelRGB565(*src, *(src + 1)); + break; + + case GL_UNSIGNED_SHORT_4_4_4_4: + dst[i++] = __glKosAverageBiPixelARGB4444(*src, *(src + 1)); + break; + + case GL_UNSIGNED_SHORT_1_5_5_5: + dst[i++] = __glKosAverageBiPixelARGB1555(*src, *(src + 1)); + break; + } + + src += 2; + } + + src += width; + } + + return gluBuild2DBiMipmaps(target, internalFormat, width / 2, height / 2, + format, type, (uint16 *)data + (width * height)); +} + +GLint APIENTRY gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, + GLsizei height, GLenum format, GLenum type, const void *data) { + if(target != GL_TEXTURE_2D) + return -1; + + if(type != GL_UNSIGNED_SHORT_5_6_5 && type != GL_UNSIGNED_SHORT_4_4_4_4 + && type != GL_UNSIGNED_SHORT_1_5_5_5) + return -1; + + if(width < 1 || height < 1) + return 0; + + if(width == 1 || height == 1) + return gluBuild2DBiMipmaps(target, internalFormat, width, height, format, type, data); + + uint32 i = 0; + uint16 x, y; + + uint16 *src = (uint16 *)data; + uint16 *dst = (uint16 *)data + (width * height); + + for(y = 0; y < height; y += 2) { + for(x = 0; x < width; x += 2) { + switch(type) { + case GL_UNSIGNED_SHORT_5_6_5: + dst[i++] = __glKosAverageQuadPixelRGB565(*src, *(src + 1), *(src + width), *(src + width + 1)); + break; + + case GL_UNSIGNED_SHORT_4_4_4_4: + dst[i++] = __glKosAverageQuadPixelARGB4444(*src, *(src + 1), *(src + width), *(src + width + 1)); + break; + + case GL_UNSIGNED_SHORT_1_5_5_5: + dst[i++] = __glKosAverageQuadPixelARGB1555(*src, *(src + 1), *(src + width), *(src + width + 1)); + break; + } + + src += 2; + } + + src += width; + } + + return gluBuild2DMipmaps(target, internalFormat, width / 2, height / 2, + format, type, (uint16 *)data + (width * height)); +} \ No newline at end of file diff --git a/include/gl.h b/include/gl.h index 3e92d33..e803842 100755 --- a/include/gl.h +++ b/include/gl.h @@ -435,8 +435,7 @@ GLAPI void APIENTRY glTexCoordPointer(GLint size, GLenum type, /* If a Normal Pointer is set and GL Lighting has been enabled, Vertex Lighting will be used instead of glColorPointer */ -GLAPI void APIENTRY glNormalPointer(GLint size, GLenum type, - GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glNormalPointer(GLenum type, GLsizei stride, const GLvoid *pointer); /* Use either this OR glNormalPointer to color vertices, NOT both */ GLAPI void APIENTRY glColorPointer(GLint size, GLenum type, @@ -515,7 +514,7 @@ GLAPI GLuint APIENTRY glKosMipMapTexSize(GLuint width, GLuint height); void glGetIntegerv(GLenum pname, GLint *params); void glGetFloatv(GLenum pname, GLfloat *params); -/* Multi-Texture Extensions */ +/* Multi-Texture Extensions - Does not currently work with Z-Clipping Enabled */ GLAPI void APIENTRY glActiveTexture(GLenum texture); GLAPI void APIENTRY glClientActiveTexture(GLenum texture);