More mipmap generation fixes

This commit is contained in:
Luke Benstead 2019-09-25 13:32:13 +01:00
parent 36a3f7082f
commit 2e1e28ce51
3 changed files with 47 additions and 50 deletions

View File

@ -131,43 +131,42 @@ static inline GLuint B4444(GLuint v) {
return (v & MASK) >> 0; return (v & MASK) >> 0;
} }
static inline GLuint R565(GLuint v) { static inline GLubyte R565(GLshort v) {
const GLuint MASK = (31 << 11); const GLuint MASK = (31 << 11);
return (v & MASK) >> 11; return (v & MASK) >> 8;
} }
static inline GLuint G565(GLuint v) { static inline GLubyte G565(GLushort v) {
const GLuint MASK = (63 << 5); const GLuint MASK = (31 << 5);
return (v & MASK) >> 5; return (v & MASK) >> 3;
} }
static inline GLuint B565(GLuint v) { static inline GLubyte B565(GLushort v) {
const GLuint MASK = (31 << 0); const GLuint MASK = (31 << 0);
return (v & MASK) >> 0; return (v & MASK);
} }
GLboolean _glCalculateAverageTexel(GLuint pvrFormat, const GLubyte* src1, const GLubyte* src2, const GLubyte* src3, const GLubyte* src4, GLubyte* t) { GLboolean _glCalculateAverageTexel(GLuint pvrFormat, const GLubyte* src1, const GLubyte* src2, const GLubyte* src3, const GLubyte* src4, GLubyte* t) {
GLuint a, r, g, b; GLuint a, r, g, b;
if((pvrFormat & PVR_TXRFMT_ARGB1555) == PVR_TXRFMT_ARGB1555) { if((pvrFormat & PVR_TXRFMT_RGB565) == PVR_TXRFMT_RGB565) {
GLushort* s1 = (GLushort*) src1; GLushort* s1 = (GLushort*) src1;
GLushort* s2 = (GLushort*) src2; GLushort* s2 = (GLushort*) src2;
GLushort* s3 = (GLushort*) src3; GLushort* s3 = (GLushort*) src3;
GLushort* s4 = (GLushort*) src4; GLushort* s4 = (GLushort*) src4;
GLushort* d1 = (GLushort*) t; GLushort* d1 = (GLushort*) t;
a = A1555(*s1) + A1555(*s2) + A1555(*s3) + A1555(*s4); r = R565(*s1) + R565(*s2) + R565(*s3) + R565(*s4);
r = R1555(*s1) + R1555(*s2) + R1555(*s3) + R1555(*s4); g = G565(*s1) + G565(*s2) + G565(*s3) + G565(*s4);
g = G1555(*s1) + G1555(*s2) + G1555(*s3) + G1555(*s4); b = B565(*s1) + B565(*s2) + B565(*s3) + B565(*s4);
b = B1555(*s1) + B1555(*s2) + B1555(*s3) + B1555(*s4);
a /= 4;
r /= 4; r /= 4;
g /= 4; g /= 4;
b /= 4; b /= 4;
*d1 = PACK_ARGB1555((GLubyte) a, (GLubyte) r, (GLubyte) g, (GLubyte) b); *d1 = PACK_RGB565(r, g, b);
} else if((pvrFormat & PVR_TXRFMT_ARGB4444) == PVR_TXRFMT_ARGB4444) { } else {
if((pvrFormat & PVR_TXRFMT_ARGB4444) == PVR_TXRFMT_ARGB4444) {
GLushort* s1 = (GLushort*) src1; GLushort* s1 = (GLushort*) src1;
GLushort* s2 = (GLushort*) src2; GLushort* s2 = (GLushort*) src2;
GLushort* s3 = (GLushort*) src3; GLushort* s3 = (GLushort*) src3;
@ -185,27 +184,25 @@ GLboolean _glCalculateAverageTexel(GLuint pvrFormat, const GLubyte* src1, const
b /= 4; b /= 4;
*d1 = PACK_ARGB4444(a, r, g, b); *d1 = PACK_ARGB4444(a, r, g, b);
} else if((pvrFormat & PVR_TXRFMT_RGB565) == PVR_TXRFMT_RGB565) { } else {
GLushort* s1 = (GLushort*) src1; GLushort* s1 = (GLushort*) src1;
GLushort* s2 = (GLushort*) src2; GLushort* s2 = (GLushort*) src2;
GLushort* s3 = (GLushort*) src3; GLushort* s3 = (GLushort*) src3;
GLushort* s4 = (GLushort*) src4; GLushort* s4 = (GLushort*) src4;
GLushort* d1 = (GLushort*) t; GLushort* d1 = (GLushort*) t;
r = R565(*s1) + R565(*s2) + R565(*s3) + R565(*s4); a = A1555(*s1) + A1555(*s2) + A1555(*s3) + A1555(*s4);
g = G565(*s1) + G565(*s2) + G565(*s3) + G565(*s4); r = R1555(*s1) + R1555(*s2) + R1555(*s3) + R1555(*s4);
b = B565(*s1) + B565(*s2) + B565(*s3) + B565(*s4); g = G1555(*s1) + G1555(*s2) + G1555(*s3) + G1555(*s4);
b = B1555(*s1) + B1555(*s2) + B1555(*s3) + B1555(*s4);
a /= 4;
r /= 4; r /= 4;
g /= 4; g /= 4;
b /= 4; b /= 4;
*d1 = PACK_RGB565(r, g, b); *d1 = PACK_ARGB1555((GLubyte) a, (GLubyte) r, (GLubyte) g, (GLubyte) b);
} else { }
fprintf(stderr, "ERROR: Unsupported PVR format for mipmap generation");
_glKosThrowError(GL_INVALID_OPERATION, __func__);
_glKosPrintError();
return GL_FALSE;
} }
return GL_TRUE; return GL_TRUE;
@ -291,6 +288,7 @@ void APIENTRY glGenerateMipmapEXT(GLenum target) {
GLuint thisHeight = (prevHeight > 1) ? prevHeight / 2 : 1; GLuint thisHeight = (prevHeight > 1) ? prevHeight / 2 : 1;
if((tex->color & PVR_TXRFMT_TWIDDLED) == PVR_TXRFMT_TWIDDLED) { if((tex->color & PVR_TXRFMT_TWIDDLED) == PVR_TXRFMT_TWIDDLED) {
fprintf(stderr, "Format: %d\n", tex->color);
_glGenerateMipmapTwiddled(tex->color, prevData, thisWidth, thisHeight, thisData); _glGenerateMipmapTwiddled(tex->color, prevData, thisWidth, thisHeight, thisData);
} else { } else {
_glGenerateMipmap(tex->color, prevData, thisWidth, thisHeight, thisData); _glGenerateMipmap(tex->color, prevData, thisWidth, thisHeight, thisData);

View File

@ -22,7 +22,7 @@
(((GLushort)(a > 0) << 15) | (((GLushort) r >> 3) << 10) | (((GLushort)g >> 3) << 5) | ((GLushort)b >> 3)) (((GLushort)(a > 0) << 15) | (((GLushort) r >> 3) << 10) | (((GLushort)g >> 3) << 5) | ((GLushort)b >> 3))
#define PACK_RGB565(r,g,b) \ #define PACK_RGB565(r,g,b) \
((r >> 3) << 15 | (g >> 2) << 11 | b >> 3) (((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3))
#define TRACE_ENABLED 0 #define TRACE_ENABLED 0
#define TRACE() if(TRACE_ENABLED) {fprintf(stderr, "%s\n", __func__);} #define TRACE() if(TRACE_ENABLED) {fprintf(stderr, "%s\n", __func__);}

View File

@ -1110,7 +1110,6 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
* make it twiddled when determining the format but I worry that would make the * make it twiddled when determining the format but I worry that would make the
* code less flexible to change in the future */ * code less flexible to change in the future */
active->color &= ~PVR_TXRFMT_NONTWIDDLED; active->color &= ~PVR_TXRFMT_NONTWIDDLED;
active->color |= PVR_TXRFMT_TWIDDLED;
} else { } else {
/* We should only get here if we converted twiddled data... which is never currently */ /* We should only get here if we converted twiddled data... which is never currently */
assert(conversionBuffer); assert(conversionBuffer);