Fixed bugs reported as of 9-06-2014
This commit is contained in:
parent
092a04cccf
commit
b6e9ff70b5
2
Makefile
2
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
|
||||
|
|
101
gl-api.c
101
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();
|
||||
|
|
25
gl-arrays.c
25
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);
|
||||
|
||||
|
|
16
gl-rgb.c
16
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);
|
||||
|
|
115
glu-texture.c
Executable file
115
glu-texture.c
Executable file
|
@ -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));
|
||||
}
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user