Fixed stride on glDrawArrays, clean up on lighting code, added glRect function

This commit is contained in:
Josh Pearson 2014-12-13 15:17:57 -08:00
parent 8c34258eb4
commit 704a46e8dc
4 changed files with 193 additions and 157 deletions

164
gl-api.c
View File

@ -43,14 +43,14 @@ static GLfloat GL_KOS_POINT_SIZE = 0.02;
static pvr_poly_cxt_t GL_KOS_POLY_CXT; static pvr_poly_cxt_t GL_KOS_POLY_CXT;
static inline void _glKosFlagsSetTriangleStrip(); static inline GLvoid _glKosFlagsSetTriangleStrip();
static inline void _glKosFlagsSetTriangle(); static inline GLvoid _glKosFlagsSetTriangle();
static inline void _glKosFlagsSetQuad(); static inline GLvoid _glKosFlagsSetQuad();
//====================================================================================================// //====================================================================================================//
//== API Initialization ==// //== API Initialization ==//
void APIENTRY glKosInit() { GLvoid APIENTRY glKosInit() {
_glKosInitPVR(); _glKosInitPVR();
_glKosInitTextures(); _glKosInitTextures();
@ -65,7 +65,7 @@ void APIENTRY glKosInit() {
//====================================================================================================// //====================================================================================================//
//== Blending / Shading functions ==// //== Blending / Shading functions ==//
void APIENTRY glShadeModel(GLenum mode) { GLvoid APIENTRY glShadeModel(GLenum mode) {
switch(mode) { switch(mode) {
case GL_FLAT: case GL_FLAT:
GL_KOS_SHADE_FUNC = PVR_SHADE_FLAT; GL_KOS_SHADE_FUNC = PVR_SHADE_FLAT;
@ -77,7 +77,7 @@ void APIENTRY glShadeModel(GLenum mode) {
} }
} }
void APIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor) { GLvoid APIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor) {
GL_KOS_BLEND_FUNC = 0; GL_KOS_BLEND_FUNC = 0;
switch(sfactor) { switch(sfactor) {
@ -160,12 +160,12 @@ void APIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor) {
//====================================================================================================// //====================================================================================================//
//== Depth / Clear functions ==// //== Depth / Clear functions ==//
void APIENTRY glClear(GLuint mode) { GLvoid APIENTRY glClear(GLuint mode) {
if(mode & GL_COLOR_BUFFER_BIT) if(mode & GL_COLOR_BUFFER_BIT)
pvr_set_bg_color(GL_KOS_COLOR_CLEAR[0], GL_KOS_COLOR_CLEAR[1], GL_KOS_COLOR_CLEAR[2]); pvr_set_bg_color(GL_KOS_COLOR_CLEAR[0], GL_KOS_COLOR_CLEAR[1], GL_KOS_COLOR_CLEAR[2]);
} }
void APIENTRY glClearColor(float r, float g, float b, float a) { GLvoid APIENTRY glClearColor(float r, float g, float b, float a) {
if(r > 1) r = 1; if(r > 1) r = 1;
if(g > 1) g = 1; if(g > 1) g = 1;
@ -180,11 +180,11 @@ void APIENTRY glClearColor(float r, float g, float b, float a) {
} }
//== NoOp ==// //== NoOp ==//
void APIENTRY glClearDepthf(GLfloat depth) { GLvoid APIENTRY glClearDepthf(GLfloat depth) {
; ;
} }
void APIENTRY glDepthFunc(GLenum func) { GLvoid APIENTRY glDepthFunc(GLenum func) {
switch(func) { switch(func) {
case GL_LESS: case GL_LESS:
GL_KOS_DEPTH_FUNC = PVR_DEPTHCMP_GEQUAL; GL_KOS_DEPTH_FUNC = PVR_DEPTHCMP_GEQUAL;
@ -207,14 +207,14 @@ void APIENTRY glDepthFunc(GLenum func) {
} }
} }
void APIENTRY glDepthMask(GLboolean flag) { GLvoid APIENTRY glDepthMask(GLboolean flag) {
GL_KOS_DEPTH_WRITE = !flag; GL_KOS_DEPTH_WRITE = !flag;
} }
//====================================================================================================// //====================================================================================================//
//== Culling functions ==// //== Culling functions ==//
void APIENTRY glFrontFace(GLenum mode) { GLvoid APIENTRY glFrontFace(GLenum mode) {
switch(mode) { switch(mode) {
case GL_CW: case GL_CW:
case GL_CCW: case GL_CCW:
@ -223,7 +223,7 @@ void APIENTRY glFrontFace(GLenum mode) {
} }
} }
void APIENTRY glCullFace(GLenum mode) { GLvoid APIENTRY glCullFace(GLenum mode) {
switch(mode) { switch(mode) {
case GL_FRONT: case GL_FRONT:
case GL_BACK: case GL_BACK:
@ -238,57 +238,115 @@ void APIENTRY glCullFace(GLenum mode) {
//== Vertex Color Submission ==// //== Vertex Color Submission ==//
void APIENTRY glColor1ui(GLuint argb) { GLvoid APIENTRY glColor1ui(GLuint argb) {
GL_KOS_VERTEX_COLOR = argb; GL_KOS_VERTEX_COLOR = argb;
} }
void APIENTRY glColor4ub(GLubyte r, GLubyte g, GLubyte b, GLubyte a) { GLvoid APIENTRY glColor4ub(GLubyte r, GLubyte g, GLubyte b, GLubyte a) {
GL_KOS_VERTEX_COLOR = a << 24 | r << 16 | g << 8 | b; GL_KOS_VERTEX_COLOR = a << 24 | r << 16 | g << 8 | b;
} }
void APIENTRY glColor3f(GLfloat r, GLfloat g, GLfloat b) { GLvoid APIENTRY glColor3f(GLfloat r, GLfloat g, GLfloat b) {
GL_KOS_VERTEX_COLOR = PVR_PACK_COLOR(1.0f, r, g, b); GL_KOS_VERTEX_COLOR = PVR_PACK_COLOR(1.0f, r, g, b);
} }
void APIENTRY glColor3fv(GLfloat *rgb) { GLvoid APIENTRY glColor3fv(const GLfloat *rgb) {
GL_KOS_VERTEX_COLOR = PVR_PACK_COLOR(1.0f, rgb[0], rgb[1], rgb[2]); GL_KOS_VERTEX_COLOR = PVR_PACK_COLOR(1.0f, rgb[0], rgb[1], rgb[2]);
} }
void APIENTRY glColor4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a) { GLvoid APIENTRY glColor4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
GL_KOS_VERTEX_COLOR = PVR_PACK_COLOR(a, r, g, b); GL_KOS_VERTEX_COLOR = PVR_PACK_COLOR(a, r, g, b);
} }
void APIENTRY glColor4fv(GLfloat *rgba) { GLvoid APIENTRY glColor4fv(const GLfloat *rgba) {
GL_KOS_VERTEX_COLOR = PVR_PACK_COLOR(rgba[3], rgba[0], rgba[1], rgba[2]); GL_KOS_VERTEX_COLOR = PVR_PACK_COLOR(rgba[3], rgba[0], rgba[1], rgba[2]);
} }
//== Texture Coordinate Submission ==// //== Texture Coordinate Submission ==//
void APIENTRY glTexCoord2f(GLfloat u, GLfloat v) { GLvoid APIENTRY glTexCoord2f(GLfloat u, GLfloat v) {
GL_KOS_VERTEX_UV[0] = u; GL_KOS_VERTEX_UV[0] = u;
GL_KOS_VERTEX_UV[1] = v; GL_KOS_VERTEX_UV[1] = v;
} }
void APIENTRY glTexCoord2fv(GLfloat *uv) { GLvoid APIENTRY glTexCoord2fv(const GLfloat *uv) {
GL_KOS_VERTEX_UV[0] = uv[0]; GL_KOS_VERTEX_UV[0] = uv[0];
GL_KOS_VERTEX_UV[1] = uv[1]; GL_KOS_VERTEX_UV[1] = uv[1];
} }
//== Vertex Position Submission Functions ==// //== Vertex Position Submission Functions ==//
void APIENTRY(*glVertex3f)(GLfloat, GLfloat, GLfloat); GLvoid APIENTRY(*glVertex3f)(GLfloat, GLfloat, GLfloat);
void APIENTRY(*glVertex3fv)(GLfloat *); GLvoid APIENTRY(*glVertex3fv)(GLfloat *);
void APIENTRY glVertex2f(GLfloat x, GLfloat y) { GLvoid APIENTRY glVertex2f(GLfloat x, GLfloat y) {
return _glKosVertex3ft(x, y, 0.0f); return _glKosVertex3ft(x, y, 0.0f);
} }
void APIENTRY glVertex2fv(GLfloat *xy) { GLvoid APIENTRY glVertex2fv(const GLfloat *xy) {
return _glKosVertex3ft(xy[0], xy[1], 0.0f); return _glKosVertex3ft(xy[0], xy[1], 0.0f);
} }
void APIENTRY glKosVertex2f(GLfloat x, GLfloat y) { GLAPI void APIENTRY glRectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) {
pvr_vertex_t * v = _glKosVertexBufPointer();
v[0].z = v[3].z = 0;
mat_trans_single3_nomod(x1, y1, v[0].z, v[0].x, v[0].y, v[0].z);
mat_trans_single3_nomod(x2, y2, v[3].z, v[3].x, v[3].y, v[3].z);
v[0].argb = v[1].argb = v[2].argb = v[3].argb = GL_KOS_VERTEX_COLOR;
v[0].flags = v[1].flags = v[2].flags = PVR_CMD_VERTEX;
v[3].flags = PVR_CMD_VERTEX_EOL;
v[1].x = v[0].x;
v[1].y = v[3].y;
v[1].z = v[3].z;
v[2].x = v[3].x;
v[2].y = v[0].y;
v[2].z = v[0].z;
_glKosVertexBufAdd(4);
GL_KOS_VERTEX_COUNT += 4;
}
GLAPI void APIENTRY glRectfv(const GLfloat *v1, const GLfloat *v2) {
pvr_vertex_t * v = _glKosVertexBufPointer();
v[0].z = v[3].z = 0;
mat_trans_single3_nomod(v1[0], v1[1], v[0].z, v[0].x, v[0].y, v[0].z);
mat_trans_single3_nomod(v2[0], v2[1], v[3].z, v[3].x, v[3].y, v[3].z);
v[0].argb = v[1].argb = v[2].argb = v[3].argb = GL_KOS_VERTEX_COLOR;
v[0].flags = v[1].flags = v[2].flags = PVR_CMD_VERTEX;
v[3].flags = PVR_CMD_VERTEX_EOL;
v[1].x = v[0].x;
v[1].y = v[3].y;
v[1].z = v[3].z;
v[2].x = v[3].x;
v[2].y = v[0].y;
v[2].z = v[0].z;
_glKosVertexBufAdd(4);
GL_KOS_VERTEX_COUNT += 4;
}
GLAPI void APIENTRY glRecti(GLint x1, GLint y1, GLint x2, GLint y2) {
return glRectf((GLfloat)x1, (GLfloat)y1, (GLfloat)x2, (GLfloat)y2);
}
GLAPI void APIENTRY glRectiv(const GLint *v1, const GLint *v2) {
return glRectfv((GLfloat *)v1, (GLfloat *)v2);
}
GLvoid APIENTRY glKosVertex2f(GLfloat x, GLfloat y) {
pvr_vertex_t *v = _glKosVertexBufPointer(); pvr_vertex_t *v = _glKosVertexBufPointer();
v->x = x; v->x = x;
@ -303,7 +361,7 @@ void APIENTRY glKosVertex2f(GLfloat x, GLfloat y) {
++GL_KOS_VERTEX_COUNT; ++GL_KOS_VERTEX_COUNT;
} }
void APIENTRY glKosVertex2fv(GLfloat *xy) { GLvoid APIENTRY glKosVertex2fv(const GLfloat *xy) {
pvr_vertex_t *v = _glKosVertexBufPointer(); pvr_vertex_t *v = _glKosVertexBufPointer();
v->x = xy[0]; v->x = xy[0];
@ -321,7 +379,7 @@ void APIENTRY glKosVertex2fv(GLfloat *xy) {
//====================================================================================================// //====================================================================================================//
//== GL Begin / End ==// //== GL Begin / End ==//
void APIENTRY glBegin(GLenum mode) { GLvoid APIENTRY glBegin(GLenum mode) {
_glKosMatrixApplyRender(); _glKosMatrixApplyRender();
_glKosArrayBufReset(); _glKosArrayBufReset();
@ -354,7 +412,7 @@ void APIENTRY glBegin(GLenum mode) {
} }
} }
void APIENTRY glEnd() { GLvoid APIENTRY glEnd() {
if(_glKosEnabledNearZClip()) { /* Z-Clipping Enabled */ if(_glKosEnabledNearZClip()) { /* Z-Clipping Enabled */
if(_glKosEnabledLighting()) { if(_glKosEnabledLighting()) {
_glKosVertexComputeLighting(_glKosClipBufAddress(), GL_KOS_VERTEX_COUNT); _glKosVertexComputeLighting(_glKosClipBufAddress(), GL_KOS_VERTEX_COUNT);
@ -426,7 +484,7 @@ void APIENTRY glEnd() {
hand corner of the screen to be modified and glScissor(0, 0, 0, 0) hand corner of the screen to be modified and glScissor(0, 0, 0, 0)
disallows modification to all 'tiles' on the screen. disallows modification to all 'tiles' on the screen.
*/ */
void APIENTRY glScissor(GLint x, GLint y, GLsizei width, GLsizei height) { GLvoid APIENTRY glScissor(GLint x, GLint y, GLsizei width, GLsizei height) {
pvr_cmd_tclip_t *c = _glKosVertexBufPointer(); pvr_cmd_tclip_t *c = _glKosVertexBufPointer();
GLint miny, maxx, maxy; GLint miny, maxx, maxy;
@ -449,7 +507,7 @@ void APIENTRY glScissor(GLint x, GLint y, GLsizei width, GLsizei height) {
_glKosVertexBufIncrement(); _glKosVertexBufIncrement();
} }
void APIENTRY glHint(GLenum target, GLenum mode) { GLvoid APIENTRY glHint(GLenum target, GLenum mode) {
switch(target) { switch(target) {
case GL_PERSPECTIVE_CORRECTION_HINT: case GL_PERSPECTIVE_CORRECTION_HINT:
if(mode == GL_NICEST) if(mode == GL_NICEST)
@ -465,7 +523,7 @@ void APIENTRY glHint(GLenum target, GLenum mode) {
//====================================================================================================// //====================================================================================================//
//== Internal API Vertex Submission functions ==// //== Internal API Vertex Submission functions ==//
void _glKosVertex3fs(GLfloat x, GLfloat y, GLfloat z) { GLvoid _glKosVertex3fs(GLfloat x, GLfloat y, GLfloat z) {
pvr_vertex_t *v = _glKosVertexBufPointer(); pvr_vertex_t *v = _glKosVertexBufPointer();
mat_trans_single3_nomod(x, y, z, v->x, v->y, v->z); mat_trans_single3_nomod(x, y, z, v->x, v->y, v->z);
@ -478,7 +536,7 @@ void _glKosVertex3fs(GLfloat x, GLfloat y, GLfloat z) {
++GL_KOS_VERTEX_COUNT; ++GL_KOS_VERTEX_COUNT;
} }
void _glKosVertex3fsv(GLfloat *xyz) { GLvoid _glKosVertex3fsv(GLfloat *xyz) {
pvr_vertex_t *v = _glKosVertexBufPointer(); pvr_vertex_t *v = _glKosVertexBufPointer();
mat_trans_single3_nomod(xyz[0], xyz[1], xyz[2], v->x, v->y, v->z); mat_trans_single3_nomod(xyz[0], xyz[1], xyz[2], v->x, v->y, v->z);
@ -491,7 +549,7 @@ void _glKosVertex3fsv(GLfloat *xyz) {
++GL_KOS_VERTEX_COUNT; ++GL_KOS_VERTEX_COUNT;
} }
void _glKosVertex3ft(GLfloat x, GLfloat y, GLfloat z) { GLvoid _glKosVertex3ft(GLfloat x, GLfloat y, GLfloat z) {
pvr_vertex_t *v = _glKosVertexBufPointer(); pvr_vertex_t *v = _glKosVertexBufPointer();
mat_trans_single3_nomod(x, y, z, v->x, v->y, v->z); mat_trans_single3_nomod(x, y, z, v->x, v->y, v->z);
@ -505,7 +563,7 @@ void _glKosVertex3ft(GLfloat x, GLfloat y, GLfloat z) {
++GL_KOS_VERTEX_COUNT; ++GL_KOS_VERTEX_COUNT;
} }
void _glKosVertex3ftv(GLfloat *xyz) { GLvoid _glKosVertex3ftv(GLfloat *xyz) {
pvr_vertex_t *v = _glKosVertexBufPointer(); pvr_vertex_t *v = _glKosVertexBufPointer();
mat_trans_single3_nomod(xyz[0], xyz[1], xyz[2], v->x, v->y, v->z); mat_trans_single3_nomod(xyz[0], xyz[1], xyz[2], v->x, v->y, v->z);
@ -519,7 +577,7 @@ void _glKosVertex3ftv(GLfloat *xyz) {
++GL_KOS_VERTEX_COUNT; ++GL_KOS_VERTEX_COUNT;
} }
void _glKosVertex3fc(GLfloat x, GLfloat y, GLfloat z) { GLvoid _glKosVertex3fc(GLfloat x, GLfloat y, GLfloat z) {
pvr_vertex_t *v = _glKosClipBufPointer(); pvr_vertex_t *v = _glKosClipBufPointer();
v->x = x; v->x = x;
@ -534,7 +592,7 @@ void _glKosVertex3fc(GLfloat x, GLfloat y, GLfloat z) {
++GL_KOS_VERTEX_COUNT; ++GL_KOS_VERTEX_COUNT;
} }
void _glKosVertex3fcv(GLfloat *xyz) { GLvoid _glKosVertex3fcv(GLfloat *xyz) {
pvr_vertex_t *v = _glKosClipBufPointer(); pvr_vertex_t *v = _glKosClipBufPointer();
v->x = xyz[0]; v->x = xyz[0];
@ -551,7 +609,7 @@ void _glKosVertex3fcv(GLfloat *xyz) {
/* GL_POINTS */ /* GL_POINTS */
inline void _glKosVertex3fpa(GLfloat x, GLfloat y, GLfloat z) { inline GLvoid _glKosVertex3fpa(GLfloat x, GLfloat y, GLfloat z) {
pvr_vertex_t *v = _glKosVertexBufPointer(); pvr_vertex_t *v = _glKosVertexBufPointer();
mat_trans_single3_nomod(x, y, z, v->x, v->y, v->z); mat_trans_single3_nomod(x, y, z, v->x, v->y, v->z);
@ -562,7 +620,7 @@ inline void _glKosVertex3fpa(GLfloat x, GLfloat y, GLfloat z) {
_glKosVertexBufIncrement(); _glKosVertexBufIncrement();
} }
inline void _glKosVertex3fpb(GLfloat x, GLfloat y, GLfloat z) { inline GLvoid _glKosVertex3fpb(GLfloat x, GLfloat y, GLfloat z) {
pvr_vertex_t *v = _glKosVertexBufPointer(); pvr_vertex_t *v = _glKosVertexBufPointer();
mat_trans_single3_nomod(x, y, z, v->x, v->y, v->z); mat_trans_single3_nomod(x, y, z, v->x, v->y, v->z);
@ -573,21 +631,21 @@ inline void _glKosVertex3fpb(GLfloat x, GLfloat y, GLfloat z) {
_glKosVertexBufIncrement(); _glKosVertexBufIncrement();
} }
void _glKosVertex3fp(GLfloat x, GLfloat y, GLfloat z) { GLvoid _glKosVertex3fp(GLfloat x, GLfloat y, GLfloat z) {
_glKosVertex3fpa(x - GL_KOS_POINT_SIZE, y - GL_KOS_POINT_SIZE, z); _glKosVertex3fpa(x - GL_KOS_POINT_SIZE, y - GL_KOS_POINT_SIZE, z);
_glKosVertex3fpa(x + GL_KOS_POINT_SIZE, y - GL_KOS_POINT_SIZE, z); _glKosVertex3fpa(x + GL_KOS_POINT_SIZE, y - GL_KOS_POINT_SIZE, z);
_glKosVertex3fpa(x - GL_KOS_POINT_SIZE, y + GL_KOS_POINT_SIZE, z); _glKosVertex3fpa(x - GL_KOS_POINT_SIZE, y + GL_KOS_POINT_SIZE, z);
_glKosVertex3fpb(x + GL_KOS_POINT_SIZE, y + GL_KOS_POINT_SIZE, z); _glKosVertex3fpb(x + GL_KOS_POINT_SIZE, y + GL_KOS_POINT_SIZE, z);
} }
void _glKosVertex3fpv(GLfloat *xyz) { GLvoid _glKosVertex3fpv(GLfloat *xyz) {
_glKosVertex3fpa(xyz[0] - GL_KOS_POINT_SIZE, xyz[1] - GL_KOS_POINT_SIZE, xyz[2]); _glKosVertex3fpa(xyz[0] - GL_KOS_POINT_SIZE, xyz[1] - GL_KOS_POINT_SIZE, xyz[2]);
_glKosVertex3fpa(xyz[0] + GL_KOS_POINT_SIZE, xyz[1] - GL_KOS_POINT_SIZE, xyz[2]); _glKosVertex3fpa(xyz[0] + GL_KOS_POINT_SIZE, xyz[1] - GL_KOS_POINT_SIZE, xyz[2]);
_glKosVertex3fpa(xyz[0] - GL_KOS_POINT_SIZE, xyz[1] + GL_KOS_POINT_SIZE, xyz[2]); _glKosVertex3fpa(xyz[0] - GL_KOS_POINT_SIZE, xyz[1] + GL_KOS_POINT_SIZE, xyz[2]);
_glKosVertex3fpb(xyz[0] + GL_KOS_POINT_SIZE, xyz[1] + GL_KOS_POINT_SIZE, xyz[2]); _glKosVertex3fpb(xyz[0] + GL_KOS_POINT_SIZE, xyz[1] + GL_KOS_POINT_SIZE, xyz[2]);
} }
void _glKosTransformClipBuf(pvr_vertex_t *v, GLuint verts) { GLvoid _glKosTransformClipBuf(pvr_vertex_t *v, GLuint verts) {
register float __x __asm__("fr12"); register float __x __asm__("fr12");
register float __y __asm__("fr13"); register float __y __asm__("fr13");
register float __z __asm__("fr14"); register float __z __asm__("fr14");
@ -606,13 +664,13 @@ void _glKosTransformClipBuf(pvr_vertex_t *v, GLuint verts) {
} }
} }
static inline void _glKosVertexSwap(pvr_vertex_t *v1, pvr_vertex_t *v2) { static inline GLvoid _glKosVertexSwap(pvr_vertex_t *v1, pvr_vertex_t *v2) {
pvr_vertex_t tmp = *v1; pvr_vertex_t tmp = *v1;
*v1 = *v2; *v1 = *v2;
*v2 = * &tmp; *v2 = * &tmp;
} }
static inline void _glKosFlagsSetQuad() { static inline GLvoid _glKosFlagsSetQuad() {
pvr_vertex_t *v = (pvr_vertex_t *)_glKosVertexBufPointer() - GL_KOS_VERTEX_COUNT; pvr_vertex_t *v = (pvr_vertex_t *)_glKosVertexBufPointer() - GL_KOS_VERTEX_COUNT;
GLuint i; GLuint i;
@ -624,7 +682,7 @@ static inline void _glKosFlagsSetQuad() {
} }
} }
static inline void _glKosFlagsSetTriangle() { static inline GLvoid _glKosFlagsSetTriangle() {
pvr_vertex_t *v = (pvr_vertex_t *)_glKosVertexBufPointer() - GL_KOS_VERTEX_COUNT; pvr_vertex_t *v = (pvr_vertex_t *)_glKosVertexBufPointer() - GL_KOS_VERTEX_COUNT;
GLuint i; GLuint i;
@ -635,7 +693,7 @@ static inline void _glKosFlagsSetTriangle() {
} }
} }
static inline void _glKosFlagsSetTriangleStrip() { static inline GLvoid _glKosFlagsSetTriangleStrip() {
pvr_vertex_t *v = (pvr_vertex_t *)_glKosVertexBufPointer() - GL_KOS_VERTEX_COUNT; pvr_vertex_t *v = (pvr_vertex_t *)_glKosVertexBufPointer() - GL_KOS_VERTEX_COUNT;
GLuint i; GLuint i;
@ -650,7 +708,7 @@ static inline void _glKosFlagsSetTriangleStrip() {
//====================================================================================================// //====================================================================================================//
//== GL KOS PVR Header Parameter Compilation Functions ==// //== GL KOS PVR Header Parameter Compilation Functions ==//
static inline void _glKosApplyDepthFunc() { static inline GLvoid _glKosApplyDepthFunc() {
if(_glKosEnabledDepthTest()) if(_glKosEnabledDepthTest())
GL_KOS_POLY_CXT.depth.comparison = GL_KOS_DEPTH_FUNC; GL_KOS_POLY_CXT.depth.comparison = GL_KOS_DEPTH_FUNC;
else else
@ -659,17 +717,17 @@ static inline void _glKosApplyDepthFunc() {
GL_KOS_POLY_CXT.depth.write = GL_KOS_DEPTH_WRITE; GL_KOS_POLY_CXT.depth.write = GL_KOS_DEPTH_WRITE;
} }
static inline void _glKosApplyScissorFunc() { static inline GLvoid _glKosApplyScissorFunc() {
if(_glKosEnabledScissorTest()) if(_glKosEnabledScissorTest())
GL_KOS_POLY_CXT.gen.clip_mode = PVR_USERCLIP_INSIDE; GL_KOS_POLY_CXT.gen.clip_mode = PVR_USERCLIP_INSIDE;
} }
static inline void _glKosApplyFogFunc() { static inline GLvoid _glKosApplyFogFunc() {
if(_glKosEnabledFog()) if(_glKosEnabledFog())
GL_KOS_POLY_CXT.gen.fog_type = PVR_FOG_TABLE; GL_KOS_POLY_CXT.gen.fog_type = PVR_FOG_TABLE;
} }
static inline void _glKosApplyCullingFunc() { static inline GLvoid _glKosApplyCullingFunc() {
if(_glKosEnabledCulling()) { if(_glKosEnabledCulling()) {
if(GL_KOS_CULL_FUNC == GL_BACK) { if(GL_KOS_CULL_FUNC == GL_BACK) {
if(GL_KOS_FACE_FRONT == GL_CW) if(GL_KOS_FACE_FRONT == GL_CW)
@ -688,14 +746,14 @@ static inline void _glKosApplyCullingFunc() {
GL_KOS_POLY_CXT.gen.culling = PVR_CULLING_NONE; GL_KOS_POLY_CXT.gen.culling = PVR_CULLING_NONE;
} }
static inline void _glKosApplyBlendFunc() { static inline GLvoid _glKosApplyBlendFunc() {
if(_glKosEnabledBlend()) { if(_glKosEnabledBlend()) {
GL_KOS_POLY_CXT.blend.src = (GL_KOS_BLEND_FUNC & 0xF0) >> 4; GL_KOS_POLY_CXT.blend.src = (GL_KOS_BLEND_FUNC & 0xF0) >> 4;
GL_KOS_POLY_CXT.blend.dst = (GL_KOS_BLEND_FUNC & 0x0F); GL_KOS_POLY_CXT.blend.dst = (GL_KOS_BLEND_FUNC & 0x0F);
} }
} }
void _glKosCompileHdr() { GLvoid _glKosCompileHdr() {
pvr_poly_hdr_t *hdr = _glKosVertexBufPointer(); pvr_poly_hdr_t *hdr = _glKosVertexBufPointer();
pvr_poly_cxt_col(&GL_KOS_POLY_CXT, _glKosList() * 2); pvr_poly_cxt_col(&GL_KOS_POLY_CXT, _glKosList() * 2);
@ -717,7 +775,7 @@ void _glKosCompileHdr() {
_glKosVertexBufIncrement(); _glKosVertexBufIncrement();
} }
void _glKosCompileHdrT(GL_TEXTURE_OBJECT *tex) { GLvoid _glKosCompileHdrT(GL_TEXTURE_OBJECT *tex) {
pvr_poly_hdr_t *hdr = _glKosVertexBufPointer(); pvr_poly_hdr_t *hdr = _glKosVertexBufPointer();
pvr_poly_cxt_txr(&GL_KOS_POLY_CXT, pvr_poly_cxt_txr(&GL_KOS_POLY_CXT,

View File

@ -61,7 +61,7 @@ GLAPI void APIENTRY glVertexPointer(GLint size, GLenum type,
} }
(stride) ? (GL_VERTEX_STRIDE = stride / 4) : (GL_VERTEX_STRIDE = 3); (stride) ? (GL_VERTEX_STRIDE = stride / 4) : (GL_VERTEX_STRIDE = 3);
GL_VERTEX_POINTER = (float *)pointer; GL_VERTEX_POINTER = (float *)pointer;
GL_VERTEX_PTR_MODE |= GL_USE_ARRAY; GL_VERTEX_PTR_MODE |= GL_USE_ARRAY;
@ -199,11 +199,11 @@ static void _glKosArraysTransform(GLuint count) {
register float __x __asm__("fr12"); register float __x __asm__("fr12");
register float __y __asm__("fr13"); register float __y __asm__("fr13");
register float __z __asm__("fr14"); register float __z __asm__("fr14");
while(count--) { while(count--) {
__x = *src++; __x = src[0];
__y = *src++; __y = src[1];
__z = *src++; __z = src[2];
mat_trans_fv12() mat_trans_fv12()
@ -212,6 +212,8 @@ static void _glKosArraysTransform(GLuint count) {
dst->z = __z; dst->z = __z;
++dst; ++dst;
src += GL_VERTEX_STRIDE;
} }
} }
@ -226,9 +228,9 @@ static void _glKosArraysTransformClip(GLuint count) {
register float __w __asm__("fr15"); register float __w __asm__("fr15");
while(count--) { while(count--) {
__x = *src++; __x = src[0];
__y = *src++; __y = src[1];
__z = *src++; __z = src[2];
mat_trans_fv12_nodivw() mat_trans_fv12_nodivw()
@ -236,7 +238,10 @@ static void _glKosArraysTransformClip(GLuint count) {
dst->y = __y; dst->y = __y;
dst->z = __z; dst->z = __z;
*W++ = __w; *W++ = __w;
++dst; ++dst;
src += GL_VERTEX_STRIDE;
} }
} }
@ -911,7 +916,7 @@ GLAPI void APIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei count) {
} }
} }
else { else {
/* Transform vertices with no perspective divde, store w component */ /* Transform vertices with no perspective divide, store w component */
_glKosArraysTransformClip(count); _glKosArraysTransformClip(count);
/* Finally, clip the input vertex data into the output vertex buffer */ /* Finally, clip the input vertex data into the output vertex buffer */

View File

@ -66,16 +66,18 @@ void _glKosInitLighting() { /* Called internally by glInit() */
memcpy(&GL_MATERIAL, &GL_DEFAULT_MATERIAL, sizeof(glMaterial)); memcpy(&GL_MATERIAL, &GL_DEFAULT_MATERIAL, sizeof(glMaterial));
} }
/* Enable a light - GL_LIGHT0->GL_LIGHT7 */ /* Enable a light - GL_LIGHT0->GL_LIGHT15 */
void _glKosEnableLight(const GLuint light) { void _glKosEnableLight(const GLuint light) {
if(light < GL_LIGHT0 || light > GL_LIGHT7) return; if(light < GL_LIGHT0 || light > GL_LIGHT0 + GL_KOS_MAX_LIGHTS)
return;
GL_LIGHT_ENABLED |= (1 << (light & 0xF)); GL_LIGHT_ENABLED |= (1 << (light & 0xF));
} }
/* Disable a light - GL_LIGHT0->GL_LIGHT7 */ /* Disable a light - GL_LIGHT0->GL_LIGHT15 */
void _glKosDisableLight(const GLuint light) { void _glKosDisableLight(const GLuint light) {
if(light < GL_LIGHT0 || light > GL_LIGHT7) return; if(light < GL_LIGHT0 || light > GL_LIGHT0 + GL_KOS_MAX_LIGHTS)
return;
GL_LIGHT_ENABLED &= ~(1 << (light & 0xF)); GL_LIGHT_ENABLED &= ~(1 << (light & 0xF));
} }
@ -89,34 +91,34 @@ GLubyte _glKosGetMaxLights() {
} }
/* Vertex Normal Submission */ /* Vertex Normal Submission */
void glNormal3f(float x, float y, float z) { void glNormal3f(GLfloat x, GLfloat y, GLfloat z) {
GL_VERTEX_NORMAL[0] = x; GL_VERTEX_NORMAL[0] = x;
GL_VERTEX_NORMAL[1] = y; GL_VERTEX_NORMAL[1] = y;
GL_VERTEX_NORMAL[2] = z; GL_VERTEX_NORMAL[2] = z;
} }
void glNormal3fv(float *xyz) { void glNormal3fv(const GLfloat *xyz) {
GL_VERTEX_NORMAL[0] = xyz[0]; GL_VERTEX_NORMAL[0] = xyz[0];
GL_VERTEX_NORMAL[1] = xyz[1]; GL_VERTEX_NORMAL[1] = xyz[1];
GL_VERTEX_NORMAL[2] = xyz[2]; GL_VERTEX_NORMAL[2] = xyz[2];
} }
/* Global Ambient Light Parameters */ /* Global Ambient Light Parameters */
void glKosLightAmbient4fv(float *rgba) { void glKosLightAmbient4fv(const GLfloat *rgba) {
GL_GLOBAL_AMBIENT[0] = rgba[0]; GL_GLOBAL_AMBIENT[0] = rgba[0];
GL_GLOBAL_AMBIENT[1] = rgba[1]; GL_GLOBAL_AMBIENT[1] = rgba[1];
GL_GLOBAL_AMBIENT[2] = rgba[2]; GL_GLOBAL_AMBIENT[2] = rgba[2];
GL_GLOBAL_AMBIENT[3] = rgba[3]; GL_GLOBAL_AMBIENT[3] = rgba[3];
} }
void glKosLightAmbient4f(float r, float g, float b, float a) { void glKosLightAmbient4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
GL_GLOBAL_AMBIENT[0] = r; GL_GLOBAL_AMBIENT[0] = r;
GL_GLOBAL_AMBIENT[1] = g; GL_GLOBAL_AMBIENT[1] = g;
GL_GLOBAL_AMBIENT[2] = b; GL_GLOBAL_AMBIENT[2] = b;
GL_GLOBAL_AMBIENT[3] = a; GL_GLOBAL_AMBIENT[3] = a;
} }
void glKosLightAmbient3fv(float *rgb) { void glKosLightAmbient3fv(const float *rgb) {
GL_GLOBAL_AMBIENT[0] = rgb[0]; GL_GLOBAL_AMBIENT[0] = rgb[0];
GL_GLOBAL_AMBIENT[1] = rgb[1]; GL_GLOBAL_AMBIENT[1] = rgb[1];
GL_GLOBAL_AMBIENT[2] = rgb[2]; GL_GLOBAL_AMBIENT[2] = rgb[2];
@ -406,7 +408,7 @@ void _glKosVertexLights(glVertex *P, pvr_vertex_t *v, GLuint count) {
float S; float S;
#endif #endif
unsigned char i; unsigned char i;
float L[4] __attribute__((aligned(8))); float L[4];
float C[3] = { 0, 0, 0 }; float C[3] = { 0, 0, 0 };
colorui *color = (colorui *)&v->argb; colorui *color = (colorui *)&v->argb;
@ -456,7 +458,7 @@ void _glKosVertexLight(glVertex *P, pvr_vertex_t *v) {
float S; float S;
#endif #endif
unsigned char i; unsigned char i;
float L[4] __attribute__((aligned(8))); float L[4];
/* Compute Ambient */ /* Compute Ambient */
float C[3] = { GL_MATERIAL.Ke[0] + GL_MATERIAL.Ka[0] *GL_GLOBAL_AMBIENT[0], float C[3] = { GL_MATERIAL.Ke[0] + GL_MATERIAL.Ka[0] *GL_GLOBAL_AMBIENT[0],
@ -501,7 +503,7 @@ GLuint _glKosVertexLightColor(glVertex *P) {
#endif #endif
GLuint color; GLuint color;
GLubyte i; GLubyte i;
float L[4] __attribute__((aligned(8))); float L[4];
/* Compute Ambient */ /* Compute Ambient */
float C[3] = { GL_MATERIAL.Ke[0] + GL_MATERIAL.Ka[0] *GL_GLOBAL_AMBIENT[0], float C[3] = { GL_MATERIAL.Ke[0] + GL_MATERIAL.Ka[0] *GL_GLOBAL_AMBIENT[0],
@ -564,9 +566,3 @@ void _glKosVertexComputeLighting(pvr_vertex_t *v, int verts) {
_glKosVertexLight(s++, v++); _glKosVertexLight(s++, v++);
} }
} }
void _glKosLightTransformScreenSpace(float *xyz) {
_glKosMatrixApplyScreenSpace();
mat_trans_single(xyz[0], xyz[1], xyz[2]);
_glKosMatrixLoadRender();
}

View File

@ -1,7 +1,7 @@
/* KallistiGL for KallistiOS ##version## /* KallistiGL for KallistiOS ##version##
libgl/gl-sh4-light.S libgl/gl-sh4-light.S
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson Copyright (C) 2013-2014 Josh Pearson
Dynamic Vertex Lighting Dynamic Vertex Lighting
@ -41,45 +41,34 @@ __glKosSpecular:
fsub fr0, fr4 ! fv4 = V = normalize ( E - P ) fsub fr0, fr4 ! fv4 = V = normalize ( E - P )
fsub fr1, fr5 fsub fr1, fr5
fsub fr2, fr6 fsub fr2, fr6
fldi0 fr3 ! load 0 for P w fldi0 fr3 ! load 0 for P w
fldi0 fr7 ! load 0 for E w fldi0 fr7 ! load 0 for E w
fipr fv4, fv4 ! Normalize V vector fipr fv4, fv4 ! Normalize V vector
fsqrt fr7 fsrra fr7
fmul fr7, fr4
fcmp/gt fr3, fr7 ! V w <=0 = skip ndiv fmul fr7, fr5
bf .SKIPVndiv fmul fr7, fr6
fdiv fr7, fr4
fdiv fr7, fr5
fdiv fr7, fr6
.SKIPVndiv:
fadd fr4, fr8 ! fv8 = H = normalize( L + V ) fadd fr4, fr8 ! fv8 = H = normalize( L + V )
fadd fr5, fr9 fadd fr5, fr9
fadd fr6, fr10 fadd fr6, fr10
fldi0 fr11 ! load 0 for H w fldi0 fr11 ! load 0 for H w
fipr fv8, fv8 ! Normalize H vector fipr fv8, fv8 ! Normalize H vector
fsqrt fr11 fsrra fr11
fmul fr11, fr8
fcmp/gt fr3, fr11 ! H w <=0 = skip ndiv fmul fr11, fr9
bf .SKIPHndiv fmul fr11, fr10
fdiv fr11, fr8
fdiv fr11, fr9
fdiv fr11, fr10
.SKIPHndiv:
fmov @r4+, fr0 ! load N to fv0 fmov @r4+, fr0 ! load N to fv0
fmov @r4+, fr1 fmov @r4+, fr1
fmov @r4+, fr2 fmov @r4+, fr2
fipr fv0, fv8 ! N dot H for specular term fipr fv0, fv8 ! N dot H for specular term
rts rts
fmov fr11, fr0 ! move N dot H to fr0 for return fmov fr11, fr0 ! move N dot H to fr0 for return
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@ -130,17 +119,11 @@ __glKosSpotlight:
fsub fr6, fr14 fsub fr6, fr14
fldi0 fr15 ! set fv12 w component to 0 fldi0 fr15 ! set fv12 w component to 0
fipr fv12, fv12 ! Normalize vector fipr fv12, fv12 ! Normalize vector
fsqrt fr15 fsrra fr15
fmul fr15, fr12
fcmp/gt fr11, fr15 ! Check for Normalization division fmul fr15, fr13
bf .SPOTcosdir ! If w < 0, skip division fmul fr15, fr14
fdiv fr12, fr15
fdiv fr13, fr15
fdiv fr14, fr15
.SPOTcosdir:
fldi0 fr15 ! set fv12 w component to 0 fldi0 fr15 ! set fv12 w component to 0
fipr fv12, fv8 ! fr11 now holds light cosDir fipr fv12, fv8 ! fr11 now holds light cosDir
@ -148,53 +131,47 @@ __glKosSpotlight:
fmov @r4+, fr15 ! load light cutOff to fr15 fmov @r4+, fr15 ! load light cutOff to fr15
mov #1, r1 ! load 1 for boolean flag = indicate light cutOff was read mov #1, r1 ! load 1 for boolean flag = indicate light cutOff was read
fcmp/gt fr15, fr11 ! cosDir > cutOff ? 0 : 1 fcmp/gt fr15, fr11 ! cosDir > cutOff ? 0 : 1
bt .RET0spot ! vertex outside of spotlight = return 0 bt .RET0spot ! vertex outside of spotlight = return 0
.VERTEXLIGHT0: .VERTEXLIGHT0:
fsub fr0, fr4 ! fv4 = L vector = ( light position - vertex position) fsub fr0, fr4 ! fv4 = L vector = ( light position - vertex position)
fsub fr1, fr5 fsub fr1, fr5
fsub fr2, fr6 fsub fr2, fr6
fldi0 fr7 ! load 0 for L w fldi0 fr7 ! load 0 for L w
fldi0 fr11 ! load 0 for N w fldi0 fr11 ! load 0 for N w
fipr fv4, fv4 ! Normalize L vector fipr fv4, fv4 ! Normalize L vector
fsqrt fr7 fsrra fr7
fmul fr7, fr4
fcmp/gt fr11, fr7 ! Normalization division if w component > 0 fmul fr7, fr5
bf .SDIVlv fmul fr7, fr6 ! fv4 = Normalized L Vector
fdiv fr7, fr4 fmov fr7, fr3 ! copy L w to fr3
fdiv fr7, fr5
fdiv fr7, fr6 ! fv4 = Normalized L Vector
.SDIVlv: fldi0 fr7 ! load 0 for L w
fmov fr7, fr3 ! copy L w to fr3 fcmp/gt fr7, fr3
bf .RET0spot ! if L w < 0, return 0 now to avoid pointless computations
fldi0 fr7 ! load 0 for L w fmov @r5+, fr8 ! load normal to fv8
fmov @r5+, fr9 ! load normal to fv8
fmov @r5+, fr10 ! load normal to fv8
fcmp/gt fr7, fr3 fipr fv8, fv4 ! N dot L
bf .RET0spot ! if L w < 0, return 0 now to avoid pointless computations
fmov @r5+, fr8 ! load normal to fv8 fcmp/gt fr11, fr7 ! L w < = 0 ? L w = 0
fmov @r5+, fr9 ! load normal to fv8 bf .RET0spot: ! if L w < 0, return 0 now to avoid pointless computations
fmov @r5+, fr10 ! load normal to fv8
fipr fv8, fv4 ! N dot L
fcmp/gt fr11, fr7 ! L w < = 0 ? L w = 0
bf .RET0spot: ! if L w < 0, return 0 now to avoid pointless computations
.WRITEDi: .WRITEDi:
fschg fschg
fmov dr4, @r6 ! write L vector x to output fmov dr4, @r6 ! write L vector x to output
fschg fschg
add #8, r6 add #8, r6
fmov fr6, @r6 ! write L vector z to output fmov fr6, @r6 ! write L vector z to output
add #4, r6 add #4, r6
cmp/gt r2, r1 cmp/gt r2, r1
bt .READattenf bt .READattenf
@ -208,16 +185,16 @@ __glKosSpotlight:
fmov @r4+, fr10 fmov @r4+, fr10
fldi1 fr11 fldi1 fr11
fmul fr3, fr9 ! calculate attenuation fmul fr3, fr9 ! calculate attenuation
fmul fr3, fr10 fmul fr3, fr10
fmul fr3, fr10 fmul fr3, fr10
fadd fr9, fr8 fadd fr9, fr8
fadd fr10, fr8 fadd fr10, fr8
fdiv fr8, fr11 ! fr11 = A fdiv fr8, fr11 ! fr11 = A
fmul fr7, fr11 ! D * A fmul fr7, fr11 ! D * A
fmov fr11, @r6 ! write D*A to output fmov fr11, @r6 ! write D*A to output
.RET1spot: .RET1spot: