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,61 +131,25 @@ 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* s2 = (GLushort*) src2;
GLushort* s3 = (GLushort*) src3;
GLushort* s4 = (GLushort*) src4;
GLushort* d1 = (GLushort*) t;
a = A1555(*s1) + A1555(*s2) + A1555(*s3) + A1555(*s4);
r = R1555(*s1) + R1555(*s2) + R1555(*s3) + R1555(*s4);
g = G1555(*s1) + G1555(*s2) + G1555(*s3) + G1555(*s4);
b = B1555(*s1) + B1555(*s2) + B1555(*s3) + B1555(*s4);
a /= 4;
r /= 4;
g /= 4;
b /= 4;
*d1 = PACK_ARGB1555((GLubyte) a, (GLubyte) r, (GLubyte) g, (GLubyte) b);
} else if((pvrFormat & PVR_TXRFMT_ARGB4444) == PVR_TXRFMT_ARGB4444) {
GLushort* s1 = (GLushort*) src1;
GLushort* s2 = (GLushort*) src2;
GLushort* s3 = (GLushort*) src3;
GLushort* s4 = (GLushort*) src4;
GLushort* d1 = (GLushort*) t;
a = A4444(*s1) + A4444(*s2) + A4444(*s3) + A4444(*s4);
r = R4444(*s1) + R4444(*s2) + R4444(*s3) + R4444(*s4);
g = G4444(*s1) + G4444(*s2) + G4444(*s3) + G4444(*s4);
b = B4444(*s1) + B4444(*s2) + B4444(*s3) + B4444(*s4);
a /= 4;
r /= 4;
g /= 4;
b /= 4;
*d1 = PACK_ARGB4444(a, r, g, b);
} else 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;
@ -202,10 +166,43 @@ GLboolean _glCalculateAverageTexel(GLuint pvrFormat, const GLubyte* src1, const
*d1 = PACK_RGB565(r, g, b); *d1 = PACK_RGB565(r, g, b);
} else { } else {
fprintf(stderr, "ERROR: Unsupported PVR format for mipmap generation"); if((pvrFormat & PVR_TXRFMT_ARGB4444) == PVR_TXRFMT_ARGB4444) {
_glKosThrowError(GL_INVALID_OPERATION, __func__); GLushort* s1 = (GLushort*) src1;
_glKosPrintError(); GLushort* s2 = (GLushort*) src2;
return GL_FALSE; GLushort* s3 = (GLushort*) src3;
GLushort* s4 = (GLushort*) src4;
GLushort* d1 = (GLushort*) t;
a = A4444(*s1) + A4444(*s2) + A4444(*s3) + A4444(*s4);
r = R4444(*s1) + R4444(*s2) + R4444(*s3) + R4444(*s4);
g = G4444(*s1) + G4444(*s2) + G4444(*s3) + G4444(*s4);
b = B4444(*s1) + B4444(*s2) + B4444(*s3) + B4444(*s4);
a /= 4;
r /= 4;
g /= 4;
b /= 4;
*d1 = PACK_ARGB4444(a, r, g, b);
} else {
GLushort* s1 = (GLushort*) src1;
GLushort* s2 = (GLushort*) src2;
GLushort* s3 = (GLushort*) src3;
GLushort* s4 = (GLushort*) src4;
GLushort* d1 = (GLushort*) t;
a = A1555(*s1) + A1555(*s2) + A1555(*s3) + A1555(*s4);
r = R1555(*s1) + R1555(*s2) + R1555(*s3) + R1555(*s4);
g = G1555(*s1) + G1555(*s2) + G1555(*s3) + G1555(*s4);
b = B1555(*s1) + B1555(*s2) + B1555(*s3) + B1555(*s4);
a /= 4;
r /= 4;
g /= 4;
b /= 4;
*d1 = PACK_ARGB1555((GLubyte) a, (GLubyte) r, (GLubyte) g, (GLubyte) b);
}
} }
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);