Added support for 2D vertices using glDrawArrays. Fixed a small bug in matrix transform stack.

This commit is contained in:
Josh Pearson 2014-12-20 16:49:56 -08:00
parent 8b276ca731
commit 4af2c8aacc
3 changed files with 123 additions and 52 deletions

View File

@ -603,8 +603,7 @@ GLvoid _glKosVertex3fpv(const GLfloat *xyz) {
_glKosFinishRect(); _glKosFinishRect();
} }
static inline void _glKosFinishRect() static inline void _glKosFinishRect() {
{
pvr_vertex_t * v = _glKosVertexBufPointer(); pvr_vertex_t * v = _glKosVertexBufPointer();
v[0].argb = v[1].argb = v[2].argb = v[3].argb = GL_KOS_VERTEX_COLOR; v[0].argb = v[1].argb = v[2].argb = v[3].argb = GL_KOS_VERTEX_COLOR;
@ -887,7 +886,6 @@ GLubyte _glKosDepthMask() {
return !GL_KOS_DEPTH_WRITE; return !GL_KOS_DEPTH_WRITE;
} }
GLuint _glKosVertexColor() GLuint _glKosVertexColor() {
{
return GL_KOS_VERTEX_COLOR; return GL_KOS_VERTEX_COLOR;
} }

View File

@ -33,6 +33,7 @@ static GLfloat GL_ARRAY_BUFW[GL_MAX_ARRAY_VERTICES];
static GLfloat GL_ARRAY_DSTW[GL_MAX_ARRAY_VERTICES]; static GLfloat GL_ARRAY_DSTW[GL_MAX_ARRAY_VERTICES];
static glVertex *GL_ARRAY_BUF_PTR; static glVertex *GL_ARRAY_BUF_PTR;
static GLuint GL_VERTEX_PTR_MODE = 0; static GLuint GL_VERTEX_PTR_MODE = 0;
static GLubyte GL_KOS_VERTEX_SIZE = 0;
//========================================================================================// //========================================================================================//
//== Local Function Definitions ==// //== Local Function Definitions ==//
@ -46,8 +47,9 @@ static inline void _glKosArraysTransformPositions(GLfloat *position, GLuint coun
/* Submit a Vertex Position Pointer */ /* Submit a Vertex Position Pointer */
GLAPI void APIENTRY glVertexPointer(GLint size, GLenum type, GLAPI void APIENTRY glVertexPointer(GLint size, GLenum type,
GLsizei stride, const GLvoid *pointer) { GLsizei stride, const GLvoid *pointer) {
if(size != 3) /* Expect 3D X,Y,Z vertex... could do 2d X,Y later */ if(size != 2) /* Expect 2D X,Y or 3D X,Y,Z vertex... */
_glKosThrowError(GL_INVALID_VALUE, "glVertexPointer"); if(size != 3)
_glKosThrowError(GL_INVALID_VALUE, "glVertexPointer");
if(type != GL_FLOAT) /* Expect Floating point vertices */ if(type != GL_FLOAT) /* Expect Floating point vertices */
_glKosThrowError(GL_INVALID_ENUM, "glVertexPointer"); _glKosThrowError(GL_INVALID_ENUM, "glVertexPointer");
@ -60,6 +62,8 @@ GLAPI void APIENTRY glVertexPointer(GLint size, GLenum type,
return; return;
} }
GL_KOS_VERTEX_SIZE = size;
(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;
@ -191,6 +195,30 @@ static inline void _glKosArraysTransformPositions(GLfloat *position, GLuint coun
//========================================================================================// //========================================================================================//
//== Arrays Vertex Transform ==/ //== Arrays Vertex Transform ==/
static void _glKosArraysTransform2D(GLuint count) {
GLfloat *src = GL_VERTEX_POINTER;
pvr_vertex_t *dst = _glKosVertexBufPointer();
register float __x __asm__("fr12");
register float __y __asm__("fr13");
register float __z __asm__("fr14");
while(count--) {
__x = src[0];
__y = src[1];
__z = 0;
mat_trans_fv12()
dst->x = __x;
dst->y = __y;
dst->z = __z;
++dst;
src += GL_VERTEX_STRIDE;
}
}
static void _glKosArraysTransform(GLuint count) { static void _glKosArraysTransform(GLuint count) {
GLfloat *src = GL_VERTEX_POINTER; GLfloat *src = GL_VERTEX_POINTER;
@ -508,21 +536,19 @@ static inline void _glKosArrayFlagsSetTriangleStrip(pvr_vertex_t *dst, GLuint co
//== OpenGL Error Code Genration ==// //== OpenGL Error Code Genration ==//
static GLuint _glKosArraysVerifyParameter(GLenum mode, GLsizei count, GLenum type, GLubyte element) { static GLuint _glKosArraysVerifyParameter(GLenum mode, GLsizei count, GLenum type, GLubyte element) {
GLuint GL_ERROR_CODE = 0;
if(mode != GL_QUADS) if(mode != GL_QUADS)
if(mode != GL_TRIANGLES) if(mode != GL_TRIANGLES)
if(mode != GL_TRIANGLE_STRIP) if(mode != GL_TRIANGLE_STRIP)
GL_ERROR_CODE |= GL_INVALID_ENUM; _glKosThrowError(GL_INVALID_ENUM, "glDrawArrays");
if(count < 0) if(count < 0)
GL_ERROR_CODE |= GL_INVALID_VALUE; _glKosThrowError(GL_INVALID_VALUE, "glDrawArrays");
if(!(GL_VERTEX_PTR_MODE & GL_USE_ARRAY)) if(!(GL_VERTEX_PTR_MODE & GL_USE_ARRAY))
GL_ERROR_CODE |= GL_INVALID_OPERATION; _glKosThrowError(GL_INVALID_OPERATION, "glDrawArrays");
if(count > GL_MAX_ARRAY_VERTICES) if(count > GL_MAX_ARRAY_VERTICES)
GL_ERROR_CODE |= GL_OUT_OF_MEMORY; _glKosThrowError(GL_OUT_OF_MEMORY, "glDrawArrays");
if(element) { if(element) {
switch(type) { switch(type) {
@ -531,31 +557,19 @@ static GLuint _glKosArraysVerifyParameter(GLenum mode, GLsizei count, GLenum typ
break; break;
default: default:
GL_ERROR_CODE |= GL_INVALID_ENUM; _glKosThrowError(GL_INVALID_ENUM, "glDrawArrays");
} }
} }
else if(type > count) else if(type > count)
GL_ERROR_CODE |= GL_INVALID_VALUE; _glKosThrowError(GL_INVALID_VALUE, "glDrawArrays");
return GL_ERROR_CODE; if(_glKosGetError())
} {
_glKosPrintError();
void _glKosPrintErrorString(GLuint error) { return 0;
if(error) {
printf("GL_ERROR_CODE GENERATED:\n");
if(error & GL_INVALID_ENUM)
printf("\tGL_INVALID_ENUM\n");
if(error & GL_INVALID_VALUE)
printf("\tGL_INVALID_VALUE\n");
if(error & GL_INVALID_OPERATION)
printf("\tGL_INVALID__OPERATION\n");
if(error & GL_OUT_OF_MEMORY)
printf("\tGL_OUT_OF_MEMORY\n");
} }
return 1;
} }
//========================================================================================// //========================================================================================//
@ -563,15 +577,8 @@ void _glKosPrintErrorString(GLuint error) {
GLAPI void APIENTRY 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 */ /* Before we process the vertex data, ensure all parameters are valid */
GLuint error = _glKosArraysVerifyParameter(mode, count, type, 1); if(!_glKosArraysVerifyParameter(mode, count, type, 1))
if(error) {
_glKosPrintErrorString(error);
_glKosArraysResetState();
return; return;
}
switch(type) { switch(type) {
case GL_UNSIGNED_BYTE: case GL_UNSIGNED_BYTE:
@ -823,15 +830,74 @@ static inline void _glKosArrayTexCoord2f(pvr_vertex_t *dst, GLuint count) {
//========================================================================================// //========================================================================================//
//== Open GL Draw Arrays ==// //== Open GL Draw Arrays ==//
static void _glKosDrawArrays2D(GLenum mode, GLint first, GLsizei count) {
pvr_vertex_t *dst = _glKosVertexBufPointer();
/* Check for Color Submission */
if(GL_VERTEX_PTR_MODE & GL_USE_COLOR) {
switch(GL_COLOR_TYPE) {
case GL_FLOAT:
switch(GL_COLOR_COMPONENTS) {
case 3:
_glKosArrayColor3f(dst, count);
break;
case 4:
_glKosArrayColor4f(dst, count);
break;
}
break;
case GL_UNSIGNED_INT:
if(GL_COLOR_COMPONENTS == 1)
_glKosArrayColor1ui(dst, count);
break;
case GL_UNSIGNED_BYTE:
if(GL_COLOR_COMPONENTS == 4)
_glKosArrayColor4ub(dst, count);
break;
}
}
else
_glKosArrayColor0(dst, count); /* No colors bound */
/* Check if Texture Coordinates are enabled */
if((GL_VERTEX_PTR_MODE & GL_USE_TEXTURE) && (_glKosEnabledTexture2D() >= 0))
_glKosArrayTexCoord2f(dst, count);
_glKosMatrixApplyRender(); /* Apply the Render Matrix Stack */
/* Transform Vertex Positions */
_glKosArraysTransform2D(count);
/* Set the vertex flags for use with the PVR */
switch(mode) {
case GL_QUADS:
_glKosArrayFlagsSetQuad(dst, count);
break;
case GL_TRIANGLES:
_glKosArrayFlagsSetTriangle(dst, count);
break;
case GL_TRIANGLE_STRIP:
_glKosArrayFlagsSetTriangleStrip(dst, count);
break;
}
_glKosVertexBufAdd(count);
_glKosArraysResetState();
}
GLAPI void APIENTRY 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 */ /* Before we process the vertex data, ensure all parameters are valid */
GLuint error = _glKosArraysVerifyParameter(mode, count, first, 0); if(!_glKosArraysVerifyParameter(mode, count, first, 0))
return;
if(error) {
_glKosPrintErrorString(error);
return _glKosArraysResetState();
}
GL_VERTEX_POINTER += first; /* Add Pointer Offset */ GL_VERTEX_POINTER += first; /* Add Pointer Offset */
GL_TEXCOORD_POINTER += first; GL_TEXCOORD_POINTER += first;
@ -844,6 +910,9 @@ GLAPI void APIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei count) {
else else
_glKosCompileHdr(); _glKosCompileHdr();
if(GL_KOS_VERTEX_SIZE == 2)
return _glKosDrawArrays2D(mode, first, count);
pvr_vertex_t *dst; /* Destination of Output Vertex Array */ pvr_vertex_t *dst; /* Destination of Output Vertex Array */
if(_glKosEnabledNearZClip()) if(_glKosEnabledNearZClip())

View File

@ -106,7 +106,10 @@ void glLoadIdentity() {
mat_store(Matrix + MatrixMode); mat_store(Matrix + MatrixMode);
if(MatrixMode == GL_MODELVIEW) if(MatrixMode == GL_MODELVIEW)
{
mat_store(&MatrixMdlRot); mat_store(&MatrixMdlRot);
mat_store(&MatrixLookAt);
}
} }
void glTranslatef(GLfloat x, GLfloat y, GLfloat z) { void glTranslatef(GLfloat x, GLfloat y, GLfloat z) {
@ -339,7 +342,9 @@ void glhLookAtf2(vector3f eyePosition3D,
// Does not modify internal Modelview matrix // Does not modify internal Modelview matrix
mat_load(&MatrixLookAt); mat_load(&MatrixLookAt);
mat_translate(-eyePosition3D[0], -eyePosition3D[1], -eyePosition3D[2]); mat_translate(-eyePosition3D[0], -eyePosition3D[1], -eyePosition3D[2]);
mat_store(&MatrixLookAt);
mat_apply(Matrix + GL_MODELVIEW);
mat_store(Matrix + GL_MODELVIEW);
} }
void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez, GLfloat centerx, void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez, GLfloat centerx,
@ -354,7 +359,6 @@ void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez, GLfloat centerx,
void _glKosMatrixApplyRender() { void _glKosMatrixApplyRender() {
mat_load(Matrix + GL_SCREENVIEW); mat_load(Matrix + GL_SCREENVIEW);
mat_apply(Matrix + GL_PROJECTION); mat_apply(Matrix + GL_PROJECTION);
mat_apply(&MatrixLookAt);
mat_apply(Matrix + GL_MODELVIEW); mat_apply(Matrix + GL_MODELVIEW);
mat_store(Matrix + GL_RENDER); mat_store(Matrix + GL_RENDER);
} }