diff --git a/experimental/draw.c b/experimental/draw.c index 9faf048..7e821b6 100644 --- a/experimental/draw.c +++ b/experimental/draw.c @@ -216,12 +216,20 @@ static void submitVertices(GLenum mode, GLsizei first, GLsizei count, GLenum typ void APIENTRY glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices) { TRACE(); + if(checkImmediateModeInactive(__func__)) { + return; + } + submitVertices(mode, 0, count, type, indices); } void APIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei count) { TRACE(); + if(checkImmediateModeInactive(__func__)) { + return; + } + submitVertices(mode, first, count, GL_UNSIGNED_SHORT, NULL); } diff --git a/experimental/immediate.c b/experimental/immediate.c index e26b391..d43c579 100644 --- a/experimental/immediate.c +++ b/experimental/immediate.c @@ -6,10 +6,23 @@ static GLenum ACTIVE_POLYGON_MODE = GL_TRIANGLES; static AlignedVector VERTICES; static AlignedVector COLOURS; +static AlignedVector TEXCOORDS; void initImmediateMode() { aligned_vector_init(&VERTICES, sizeof(GLfloat)); aligned_vector_init(&COLOURS, sizeof(GLfloat)); + aligned_vector_init(&TEXCOORDS, sizeof(GLfloat)); +} + +GLubyte checkImmediateModeInactive(const char* func) { + /* Returns 1 on error */ + if(IMMEDIATE_MODE_ACTIVE) { + _glKosThrowError(GL_INVALID_OPERATION, func); + _glKosPrintError(); + return 1; + } + + return 0; } void APIENTRY glBegin(GLenum mode) { @@ -30,29 +43,58 @@ void APIENTRY glColor4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a) { aligned_vector_push_back(&COLOURS, &a, 1); } +void APIENTRY glColor4fv(const GLfloat* v) { + glColor4f(v[0], v[1], v[2], v[3]); +} + void APIENTRY glColor3f(GLfloat r, GLfloat g, GLfloat b) { static float a = 1.0f; glColor4f(r, g, b, a); } +void APIENTRY glColor3fv(const GLfloat* v) { + glColor3f(v[0], v[1], v[2]); +} + void APIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z) { aligned_vector_push_back(&VERTICES, &x, 1); aligned_vector_push_back(&VERTICES, &y, 1); aligned_vector_push_back(&VERTICES, &z, 1); } +void APIENTRY glVertex3fv(const GLfloat* v) { + glVertex3f(v[0], v[1], v[2]); +} + +void APIENTRY glVertex4fv(const GLfloat* v) { + glVertex4f(v[0], v[1], v[2], v[3]); +} + +void APIENTRY glTexCoord2f(GLfloat u, GLfloat v) { + aligned_vector_push_back(&TEXCOORDS, &u, 1); + aligned_vector_push_back(&TEXCOORDS, &v, 1); +} + +void APIENTRY glTexCoord2fv(const GLfloat* v) { + glTexCoord2f(v[0], v[1]); +} + void APIENTRY glEnd() { IMMEDIATE_MODE_ACTIVE = GL_FALSE; - /* FIXME: Push pointers */ + /* FIXME: Push pointer state */ glVertexPointer(3, GL_FLOAT, 0, VERTICES.data); glColorPointer(4, GL_FLOAT, 0, COLOURS.data); + glClientActiveTextureARB(GL_TEXTURE0); + glTexCoordPointer(2, GL_FLOAT, 0, TEXCOORDS.data); + glDrawArrays(ACTIVE_POLYGON_MODE, 0, VERTICES.size / 3); aligned_vector_clear(&VERTICES); aligned_vector_clear(&COLOURS); + aligned_vector_clear(&TEXCOORDS); /* FIXME: Pop pointers */ } diff --git a/experimental/private.h b/experimental/private.h index 0c3ab27..1ead5c5 100644 --- a/experimental/private.h +++ b/experimental/private.h @@ -72,6 +72,7 @@ void initAttributePointers(); void initContext(); void initLights(); void initImmediateMode(); +GLubyte checkImmediateModeInactive(const char* func); pvr_poly_cxt_t* getPVRContext(); GLubyte _glKosInitTextures(); diff --git a/experimental/state.c b/experimental/state.c index a6fdc09..108ce67 100644 --- a/experimental/state.c +++ b/experimental/state.c @@ -395,7 +395,6 @@ void APIENTRY glScissor(GLint x, GLint y, GLsizei width, GLsizei height) { c->ey = CLAMP((maxy / 32) - 1, 0, vid_mode->height / 32); } - GLboolean APIENTRY glIsEnabled(GLenum cap) { switch(cap) { case GL_DEPTH_TEST: diff --git a/gl-api.c b/gl-api.c index eac3947..852d42d 100644 --- a/gl-api.c +++ b/gl-api.c @@ -248,48 +248,9 @@ void APIENTRY glColor4ub(GLubyte r, GLubyte g, GLubyte b, GLubyte a) { GL_KOS_VERTEX_COLOR = a << 24 | r << 16 | g << 8 | b; } -void APIENTRY glColor3fv(const GLfloat *rgb) { - GL_KOS_VERTEX_COLOR = PVR_PACK_COLOR(1.0f, rgb[0], rgb[1], rgb[2]); -} - -void APIENTRY glColor4fv(const GLfloat *rgba) { - GL_KOS_VERTEX_COLOR = PVR_PACK_COLOR(rgba[3], rgba[0], rgba[1], rgba[2]); -} - -//== Texture Coordinate Submission ==// - -void APIENTRY glTexCoord2f(GLfloat u, GLfloat v) { - 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()) { - _glKosMatrixLoadTexture(); - - mat_trans_texture2_nomod(uv[0], uv[1], GL_KOS_VERTEX_UV[0], GL_KOS_VERTEX_UV[1]); - - _glKosMatrixLoadRender(); - } - else { - GL_KOS_VERTEX_UV[0] = uv[0]; - GL_KOS_VERTEX_UV[1] = uv[1]; - } -} //== Vertex Position Submission Functions ==// -void APIENTRY(*glVertex3fv)(const GLfloat *); - void APIENTRY glVertex2f(GLfloat x, GLfloat y) { return _glKosVertex3ft(x, y, 0.0f); } diff --git a/include/gl.h b/include/gl.h index a999be1..2bbb566 100644 --- a/include/gl.h +++ b/include/gl.h @@ -446,7 +446,7 @@ GLAPI void APIENTRY glKosVertex2fv(const GLfloat *xy); /* Primitive 3D Position Submission */ GLAPI void APIENTRY glVertex3f(GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY(*glVertex3fv)(const GLfloat *); +GLAPI void APIENTRY glVertex3fv(const GLfloat *); /* 2D Non-Textured Rectangle Submission */ GLAPI GLvoid APIENTRY glRectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2);