Properly restore enabled client state when using immediate mode

This commit is contained in:
Luke Benstead 2018-08-21 16:08:06 +01:00
parent edae8a9166
commit 9b0322ce8a
4 changed files with 65 additions and 8 deletions

View File

@ -22,12 +22,6 @@ static AttribPointer ST_POINTER;
static AttribPointer NORMAL_POINTER;
static AttribPointer DIFFUSE_POINTER;
#define VERTEX_ENABLED_FLAG (1 << 0)
#define UV_ENABLED_FLAG (1 << 1)
#define ST_ENABLED_FLAG (1 << 2)
#define DIFFUSE_ENABLED_FLAG (1 << 3)
#define NORMAL_ENABLED_FLAG (1 << 4)
static GLuint ENABLED_VERTEX_ATTRIBUTES = 0;
static GLubyte ACTIVE_CLIENT_TEXTURE = 0;
@ -78,6 +72,10 @@ typedef void (*FloatParseFunc)(GLfloat* out, const GLubyte* in);
typedef void (*ByteParseFunc)(GLubyte* out, const GLubyte* in);
typedef void (*PolyBuildFunc)(ClipVertex* first, ClipVertex* previous, ClipVertex* vertex, ClipVertex* next, const GLsizei i);
GLuint _glGetEnabledAttributes() {
return ENABLED_VERTEX_ATTRIBUTES;
}
static inline void _parseVec3FromShort3(GLfloat* out, const GLubyte* in) {
GLshort* ptr = (GLshort*) in;

View File

@ -154,6 +154,13 @@ void APIENTRY glNormal3fv(const GLfloat* v) {
void APIENTRY glEnd() {
IMMEDIATE_MODE_ACTIVE = GL_FALSE;
GLboolean vertexArrayEnabled, colorArrayEnabled, normalArrayEnabled;
GLboolean texArray0Enabled, texArray1Enabled;
glGetBooleanv(GL_VERTEX_ARRAY, &vertexArrayEnabled);
glGetBooleanv(GL_COLOR_ARRAY, &colorArrayEnabled);
glGetBooleanv(GL_NORMAL_ARRAY, &normalArrayEnabled);
/* FIXME: Push pointer state */
glEnableClientState(GL_VERTEX_ARRAY);
@ -168,23 +175,48 @@ void APIENTRY glEnd() {
glGetIntegerv(GL_CLIENT_ACTIVE_TEXTURE, &activeTexture);
glClientActiveTextureARB(GL_TEXTURE0);
glGetBooleanv(GL_TEXTURE_COORD_ARRAY, &texArray0Enabled);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, UV_COORDS.data);
glClientActiveTextureARB(GL_TEXTURE1);
glGetBooleanv(GL_TEXTURE_COORD_ARRAY, &texArray1Enabled);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, ST_COORDS.data);
glDrawArrays(ACTIVE_POLYGON_MODE, 0, VERTICES.size / 3);
glClientActiveTextureARB((GLuint) activeTexture);
aligned_vector_clear(&VERTICES);
aligned_vector_clear(&COLOURS);
aligned_vector_clear(&UV_COORDS);
aligned_vector_clear(&ST_COORDS);
aligned_vector_clear(&NORMALS);
if(!vertexArrayEnabled) {
glDisableClientState(GL_VERTEX_ARRAY);
}
if(!colorArrayEnabled) {
glDisableClientState(GL_COLOR_ARRAY);
}
if(!normalArrayEnabled) {
glDisableClientState(GL_NORMAL_ARRAY);
}
if(!texArray0Enabled) {
glClientActiveTextureARB(GL_TEXTURE0);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
if(!texArray1Enabled) {
glClientActiveTextureARB(GL_TEXTURE1);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
glClientActiveTextureARB((GLuint) activeTexture);
/* FIXME: Pop pointers */
}

View File

@ -9,6 +9,12 @@
#define TRACE_ENABLED 0
#define TRACE() if(TRACE_ENABLED) {fprintf(stderr, "%s\n", __func__);}
#define VERTEX_ENABLED_FLAG (1 << 0)
#define UV_ENABLED_FLAG (1 << 1)
#define ST_ENABLED_FLAG (1 << 2)
#define DIFFUSE_ENABLED_FLAG (1 << 3)
#define NORMAL_ENABLED_FLAG (1 << 4)
#define MAX_TEXTURE_SIZE 1024
#define CLIP_VERTEX_INT_PADDING 6
@ -99,6 +105,8 @@ GLubyte _glKosInitTextures();
void _glUpdatePVRTextureContext(pvr_poly_cxt_t* context, GLshort textureUnit);
GLuint _glGetEnabledAttributes();
TextureObject* getTexture0();
TextureObject* getTexture1();
TextureObject* getBoundTexture();

View File

@ -483,10 +483,29 @@ static GLenum COMPRESSED_FORMATS [] = {
static GLint NUM_COMPRESSED_FORMATS = sizeof(COMPRESSED_FORMATS) / sizeof(GLenum);
void APIENTRY glGetBooleanv(GLenum pname, GLboolean* params) {
GLuint enabledAttrs = _glGetEnabledAttributes();
GLuint activeClientTexture = _glGetActiveClientTexture();
switch(pname) {
case GL_TEXTURE_2D:
*params = TEXTURES_ENABLED[_glGetActiveTexture()];
break;
case GL_VERTEX_ARRAY:
*params = (enabledAttrs & VERTEX_ENABLED_FLAG) == VERTEX_ENABLED_FLAG;
break;
case GL_COLOR_ARRAY:
*params = (enabledAttrs & DIFFUSE_ENABLED_FLAG) == DIFFUSE_ENABLED_FLAG;
break;
case GL_NORMAL_ARRAY:
*params = (enabledAttrs & NORMAL_ENABLED_FLAG) == NORMAL_ENABLED_FLAG;
break;
case GL_TEXTURE_COORD_ARRAY: {
if(activeClientTexture == 0) {
*params = (enabledAttrs & UV_ENABLED_FLAG) == UV_ENABLED_FLAG;
} else {
*params = (enabledAttrs & ST_ENABLED_FLAG) == ST_ENABLED_FLAG;
}
} break;
default:
_glKosThrowError(GL_INVALID_ENUM, __func__);
_glKosPrintError();