From fa01c8fd48ee990cd9baa3ed89c62d7293854729 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Tue, 3 Jan 2012 14:01:47 +0100 Subject: [PATCH] DXT1 should work for Mac now --- dxt_compress/compress_dxt1_fp.glsl | 33 +++++++++++++++++++++--------- dxt_compress/dxt_encoder.c | 4 ++-- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/dxt_compress/compress_dxt1_fp.glsl b/dxt_compress/compress_dxt1_fp.glsl index fb2a275c7..eccb1ebb4 100644 --- a/dxt_compress/compress_dxt1_fp.glsl +++ b/dxt_compress/compress_dxt1_fp.glsl @@ -2,6 +2,11 @@ #define lerp mix +// Image formats +const int FORMAT_RGB = 0; +const int FORMAT_YUV = 1; + + // Covert YUV to RGB vec3 ConvertYUVToRGB(vec3 color) { @@ -155,20 +160,19 @@ unsigned int EmitIndicesDXT1(vec3 col[16], vec3 mincol, vec3 maxcol) return indices; } -vec4 TEX0; uniform sampler2D image; -//uniform int imageFormat = FORMAT_RGB; +uniform int imageFormat; uniform vec2 imageSize; -//out uvec4 colorInt; +varying out uvec4 colorInt; void main() { // Read block vec3 block[16]; - //if ( int(imageFormat) == FORMAT_YUV ) - // ExtractColorBlockYUV(block, image, TEX0, imageSize); - //else - ExtractColorBlockRGB(block, image, TEX0, imageSize); + if ( int(imageFormat) == FORMAT_YUV ) + ExtractColorBlockYUV(block, image, gl_TexCoord[0], imageSize); + else + ExtractColorBlockRGB(block, image, gl_TexCoord[0], imageSize); // Find min and max colors vec3 mincol, maxcol; @@ -179,10 +183,19 @@ void main() InsetBBox(mincol, maxcol); uvec4 outp; - outp.x = EmitEndPointsDXT1(mincol, maxcol); + /*outp.x = EmitEndPointsDXT1(mincol, maxcol); outp.w = EmitIndicesDXT1(block, mincol, maxcol); outp.y = 0u; - outp.z = 0u; + outp.z = 0u;*/ - //colorInt = outp; + uvec2 res; + res.x = EmitEndPointsDXT1(mincol, maxcol); + res.y = EmitIndicesDXT1(block, mincol, maxcol); + + outp.y = res.x >> 16u; + outp.x = res.x & 0xffffu; + outp.w = res.y >> 16u; + outp.z = res.y & 0xffffu; + + colorInt = outp; } diff --git a/dxt_compress/dxt_encoder.c b/dxt_compress/dxt_encoder.c index dfb876e6e..c47dd451e 100644 --- a/dxt_compress/dxt_encoder.c +++ b/dxt_compress/dxt_encoder.c @@ -154,7 +154,7 @@ dxt_encoder_create(enum dxt_type type, int width, int height, enum dxt_format fo if ( encoder->type == DXT_TYPE_DXT5_YCOCG ) glTexImage2D(GL_TEXTURE_2D, 0 , GL_RGBA32UI_EXT, encoder->width / 4, encoder->height / 4, 0, GL_RGBA_INTEGER_EXT, GL_INT, 0); else - glTexImage2D(GL_TEXTURE_2D, 0 , GL_LUMINANCE_ALPHA32UI_EXT, encoder->width / 4, encoder->height / 4, 0, GL_LUMINANCE_ALPHA_INTEGER_EXT, GL_INT, 0); + glTexImage2D(GL_TEXTURE_2D, 0 , GL_RGBA16UI_EXT, encoder->width / 4, encoder->height / 4, 0, GL_RGBA_INTEGER_EXT, GL_INT, 0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fbo_tex, 0); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); @@ -327,7 +327,7 @@ dxt_encoder_compress(struct dxt_encoder* encoder, DXT_IMAGE_TYPE* image, unsigne if ( encoder->type == DXT_TYPE_DXT5_YCOCG ) glReadPixels(0, 0, encoder->width / 4, encoder->height / 4, GL_RGBA_INTEGER_EXT, GL_UNSIGNED_INT, image_compressed); else - glReadPixels(0, 0, encoder->width / 4, encoder->height / 4, GL_LUMINANCE_ALPHA_INTEGER_EXT, GL_UNSIGNED_INT, image_compressed); + glReadPixels(0, 0, encoder->width / 4 , encoder->height / 4 , GL_RGBA_INTEGER_EXT, GL_UNSIGNED_SHORT, image_compressed); #ifdef DEBUG glFinish();