From d89997a2776672bb97faabbdd87290957e291801 Mon Sep 17 00:00:00 2001 From: Luke Benstead Date: Mon, 4 Mar 2019 20:41:33 +0000 Subject: [PATCH 1/2] Simplify the element drawing --- GL/draw.c | 44 ++++++++-------------------------------- containers/named_array.c | 4 ---- 2 files changed, 8 insertions(+), 40 deletions(-) diff --git a/GL/draw.c b/GL/draw.c index 018656b..cf54a27 100644 --- a/GL/draw.c +++ b/GL/draw.c @@ -460,6 +460,8 @@ static inline PolyBuildFunc _calcBuildFunc(const GLenum type) { return &_buildStrip; } +static inline void nullFloatParseFunc(GLfloat* out, const GLubyte* in) {} + static inline void genElementsCommon( ClipVertex* output, const GLubyte* iptr, GLuint istride, GLenum type, @@ -473,9 +475,9 @@ static inline void genElementsCommon( ) { const FloatParseFunc vertexFunc = _calcVertexParseFunc(); const ByteParseFunc diffuseFunc = _calcDiffuseParseFunc(); - const FloatParseFunc uvFunc = _calcUVParseFunc(); - const FloatParseFunc stFunc = _calcSTParseFunc(); - const FloatParseFunc normalFunc = _calcNormalParseFunc(); + const FloatParseFunc uvFunc = (doTexture) ? _calcUVParseFunc() : &nullFloatParseFunc; + const FloatParseFunc stFunc = (doMultitexture) ? _calcSTParseFunc() : &nullFloatParseFunc; + const FloatParseFunc normalFunc = (doLighting) ? _calcNormalParseFunc() : &nullFloatParseFunc; const IndexParseFunc indexFunc = _calcParseIndexFunc(type); @@ -487,40 +489,10 @@ static inline void genElementsCommon( GLuint j = indexFunc(idx); vertex->flags = PVR_CMD_VERTEX; vertexFunc(vertex->xyz, vptr + (j * vstride)); - } - - idx = iptr; - vertex = output; - for(i = 0; i < count; ++i, idx += istride, ++vertex) { - GLuint j = indexFunc(idx); diffuseFunc(vertex->bgra, cptr + (j * cstride)); - } - - if(doTexture) { - idx = iptr; - vertex = output; - for(i = 0; i < count; ++i, idx += istride, ++vertex) { - GLuint j = indexFunc(idx); - uvFunc(vertex->uv, uvptr + (j * uvstride)); - } - } - - if(doMultitexture) { - idx = iptr; - vertex = output; - for(i = 0; i < count; ++i, idx += istride, ++vertex) { - GLuint j = indexFunc(idx); - stFunc(vertex->st, stptr + (j * ststride)); - } - } - - if(doLighting) { - idx = iptr; - vertex = output; - for(i = 0; i < count; ++i, idx += istride, ++vertex) { - GLuint j = indexFunc(idx); - normalFunc(vertex->nxyz, nptr + (j * nstride)); - } + uvFunc(vertex->uv, uvptr + (j * uvstride)); + stFunc(vertex->st, stptr + (j * ststride)); + normalFunc(vertex->nxyz, nptr + (j * nstride)); } } diff --git a/containers/named_array.c b/containers/named_array.c index 0194128..c028e96 100644 --- a/containers/named_array.c +++ b/containers/named_array.c @@ -81,10 +81,6 @@ void named_array_release(NamedArray* array, unsigned int new_id) { } void* named_array_get(NamedArray* array, unsigned int id) { - if(id == 0) { - return NULL; - } - if(!named_array_used(array, id)) { return NULL; } From 2ac9cac22dbe4305b1b9036d3b7443c7f8975b75 Mon Sep 17 00:00:00 2001 From: Luke Benstead Date: Mon, 4 Mar 2019 20:56:17 +0000 Subject: [PATCH 2/2] Use the shared palette in the sample --- samples/paletted/main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/samples/paletted/main.c b/samples/paletted/main.c index da1501e..3cbce97 100644 --- a/samples/paletted/main.c +++ b/samples/paletted/main.c @@ -110,6 +110,9 @@ void LoadGLTextures() { exit(1); } + glEnable(GL_SHARED_TEXTURE_PALETTE_EXT); + glColorTableEXT(GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGBA8, image1->palette_width, GL_RGBA, GL_UNSIGNED_BYTE, image1->palette); + // Create Texture glGenTextures(1, &texture[0]); glBindTexture(GL_TEXTURE_2D, texture[0]); // 2d texture (x and y size) @@ -117,8 +120,6 @@ void LoadGLTextures() { glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); // scale linearly when image bigger than texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); // scale linearly when image smalled than texture - glColorTableEXT(GL_TEXTURE_2D, GL_RGBA8, image1->palette_width, GL_RGBA, GL_UNSIGNED_BYTE, image1->palette); - // 2d texture, level of detail 0 (normal), 3 components (red, green, blue), x size from image, y size from image, // border 0 (normal), rgb color data, unsigned byte data, and finally the data itself. glTexImage2D(GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, image1->width, image1->height, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE_TWID_KOS, image1->data);