diff --git a/GL/draw.c b/GL/draw.c index 807d43a..b1f98ef 100644 --- a/GL/draw.c +++ b/GL/draw.c @@ -86,7 +86,9 @@ static GLboolean _glIsVertexDataFastPathCompatible() { if(UV_POINTER.size != 2) return GL_FALSE; if(DIFFUSE_POINTER.type != GL_UNSIGNED_BYTE) return GL_FALSE; - if(DIFFUSE_POINTER.size != 4) return GL_FALSE; + + /* BGRA is the required color order */ + if(DIFFUSE_POINTER.size != GL_BGRA) return GL_FALSE; return GL_TRUE; } @@ -381,6 +383,30 @@ static void _readVertexData3ubARGB(const GLubyte* input, GLuint count, GLubyte s } } +static void _readVertexData4ubRevARGB(const GLubyte* input, GLuint count, GLubyte stride, GLubyte* output) { + ITERATE(count) { + output[0] = input[0]; + output[1] = input[1]; + output[2] = input[2]; + output[3] = input[3]; + + input += stride; + output += sizeof(Vertex); + } +} + +static void _readVertexData4fRevARGB(const float* input, GLuint count, GLubyte stride, GLubyte* output) { + ITERATE(count) { + output[0] = (GLubyte) clamp(input[0] * 255.0f, 0, 255); + output[1] = (GLubyte) clamp(input[1] * 255.0f, 0, 255); + output[2] = (GLubyte) clamp(input[2] * 255.0f, 0, 255); + output[3] = (GLubyte) clamp(input[3] * 255.0f, 0, 255); + + input = (float*) (((GLubyte*) input) + stride); + output += sizeof(Vertex); + } +} + static void _fillWithNegZVE(GLuint count, GLfloat* output) { ITERATE(count) { output[0] = output[1] = 0.0f; @@ -430,6 +456,14 @@ static void _readVertexData4uiARGB(const GLuint* input, GLuint count, GLubyte st assert(0 && "Not Implemented"); } +static void _readVertexData4usRevARGB(const GLushort* input, GLuint count, GLubyte stride, GLubyte* output) { + assert(0 && "Not Implemented"); +} + +static void _readVertexData4uiRevARGB(const GLuint* input, GLuint count, GLubyte stride, GLubyte* output) { + assert(0 && "Not Implemented"); +} + GLuint* _glGetEnabledAttributes() { return &ENABLED_VERTEX_ATTRIBUTES; } @@ -792,7 +826,28 @@ static inline void _readDiffuseData(const GLuint first, const GLuint count, Vert default: assert(0 && "Not Implemented"); } - } else { + } else if(DIFFUSE_POINTER.size == GL_BGRA) { + switch(DIFFUSE_POINTER.type) { + case GL_DOUBLE: + case GL_FLOAT: + _readVertexData4fRevARGB(cptr, count, cstride, output[0].bgra); + break; + case GL_BYTE: + case GL_UNSIGNED_BYTE: + _readVertexData4ubRevARGB(cptr, count, cstride, output[0].bgra); + break; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + _readVertexData4usRevARGB(cptr, count, cstride, output[0].bgra); + break; + case GL_INT: + case GL_UNSIGNED_INT: + _readVertexData4uiRevARGB(cptr, count, cstride, output[0].bgra); + break; + default: + assert(0 && "Not Implemented"); + } + }else { assert(0 && "Not Implemented"); } } @@ -802,6 +857,7 @@ static void generate(SubmissionTarget* target, const GLenum mode, const GLsizei /* Read from the client buffers and generate an array of ClipVertices */ TRACE(); + static const uint32_t FAST_PATH_BYTE_SIZE = (sizeof(GLfloat) * 3) + (sizeof(GLfloat) * 2) + (sizeof(GLubyte) * 4); const GLsizei istride = byte_size(type); if(!indices) { @@ -815,12 +871,9 @@ static void generate(SubmissionTarget* target, const GLenum mode, const GLsizei Vertex* it = start; ITERATE(count) { it->flags = PVR_CMD_VERTEX; - - memcpy(it->xyz, pos, sizeof(GLfloat) * 3); - memcpy(it->uv, pos + 3, sizeof(GLfloat) * 2); - memcpy(it->bgra, pos + 5, sizeof(GLubyte) * 4); - pos += 32 / sizeof(GLfloat); + memcpy(it->xyz, pos, FAST_PATH_BYTE_SIZE); it++; + pos += 32 / sizeof(GLfloat); } } else { _readPositionData(first, count, start); @@ -1385,7 +1438,7 @@ void APIENTRY glVertexPointer(GLint size, GLenum type, GLsizei stride, const void APIENTRY glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) { TRACE(); - if(size != 3 && size != 4) { + if(size != 3 && size != 4 && size != GL_BGRA) { _glKosThrowError(GL_INVALID_VALUE, __func__); _glKosPrintError(); return; diff --git a/GL/immediate.c b/GL/immediate.c index eceb8e2..ae3ad7a 100644 --- a/GL/immediate.c +++ b/GL/immediate.c @@ -55,7 +55,7 @@ void _glInitImmediateMode(GLuint initial_size) { UV_ATTRIB.size = 2; DIFFUSE_ATTRIB.ptr = VERTEX_ATTRIB.ptr + (sizeof(GLfloat) * 5); - DIFFUSE_ATTRIB.size = 4; + DIFFUSE_ATTRIB.size = GL_BGRA; /* Flipped color order */ DIFFUSE_ATTRIB.type = GL_UNSIGNED_BYTE; DIFFUSE_ATTRIB.stride = 32; @@ -152,10 +152,10 @@ void APIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z) { vert->u = UV_COORD[0]; vert->v = UV_COORD[1]; - vert->rgba[0] = COLOR[0]; - vert->rgba[1] = COLOR[1]; - vert->rgba[2] = COLOR[2]; - vert->rgba[3] = COLOR[3]; + vert->bgra[R8IDX] = COLOR[0]; + vert->bgra[G8IDX] = COLOR[1]; + vert->bgra[B8IDX] = COLOR[2]; + vert->bgra[A8IDX] = COLOR[3]; memcpy(st, ST_COORD, sizeof(GLfloat) * 2); memcpy(n, NORMAL, sizeof(GLfloat) * 3); diff --git a/GL/state.c b/GL/state.c index ef026a5..239f5d9 100644 --- a/GL/state.c +++ b/GL/state.c @@ -671,7 +671,7 @@ const GLubyte *glGetString(GLenum name) { return (const GLubyte*) "1.2 (partial) - GLdc 1.1"; case GL_EXTENSIONS: - return (const GLubyte*) "GL_ARB_framebuffer_object, GL_ARB_multitexture, GL_ARB_texture_rg, GL_EXT_paletted_texture, GL_EXT_shared_texture_palette, GL_KOS_multiple_shared_palette"; + return (const GLubyte*) "GL_ARB_framebuffer_object, GL_ARB_multitexture, GL_ARB_texture_rg, GL_EXT_paletted_texture, GL_EXT_shared_texture_palette, GL_KOS_multiple_shared_palette, GL_ARB_vertex_array_bgra"; } return (const GLubyte*) "GL_KOS_ERROR: ENUM Unsupported\n"; diff --git a/include/glkos.h b/include/glkos.h index 082895c..5af510b 100644 --- a/include/glkos.h +++ b/include/glkos.h @@ -60,7 +60,7 @@ typedef struct { GLfloat z; GLfloat u; GLfloat v; - GLubyte rgba[4]; + GLubyte bgra[4]; GLuint padding1; } GLVertexKOS;