More immediate mode

This commit is contained in:
Luke Benstead 2018-05-12 14:54:06 +01:00
parent 146be442f4
commit 4b8991e45f
6 changed files with 53 additions and 42 deletions

View File

@ -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);
}

View File

@ -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 */
}

View File

@ -72,6 +72,7 @@ void initAttributePointers();
void initContext();
void initLights();
void initImmediateMode();
GLubyte checkImmediateModeInactive(const char* func);
pvr_poly_cxt_t* getPVRContext();
GLubyte _glKosInitTextures();

View File

@ -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:

View File

@ -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);
}

View File

@ -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);