20 |
*/ |
*/ |
21 |
public static String colorFormat; |
public static String colorFormat; |
22 |
|
|
23 |
|
public static boolean align4 = false; |
24 |
|
|
25 |
/** Unfortunately we need to store the textures at two different levels |
/** Unfortunately we need to store the textures at two different levels |
26 |
* since adjusting TEXTURE_BASE_LEVEL does not have enough effect. |
* since adjusting TEXTURE_BASE_LEVEL does not have enough effect. |
27 |
* |
* |
35 |
if(GL.hasExtension("GL_EXT_texture_compression_s3tc")) { |
if(GL.hasExtension("GL_EXT_texture_compression_s3tc")) { |
36 |
monochromeFormat = "COMPRESSED_RGB_S3TC_DXT1_EXT"; |
monochromeFormat = "COMPRESSED_RGB_S3TC_DXT1_EXT"; |
37 |
colorFormat = "COMPRESSED_RGB_S3TC_DXT1_EXT"; |
colorFormat = "COMPRESSED_RGB_S3TC_DXT1_EXT"; |
38 |
|
align4 = true; |
39 |
} else { |
} else { |
40 |
// Otherwise, pick as small formats as possible: these are BIG images. |
// Otherwise, pick as small formats as possible: these are BIG images. |
41 |
monochromeFormat = "LUMINANCE4"; |
monochromeFormat = "LUMINANCE4"; |
73 |
GL.Image img = GL.createImage(file); |
GL.Image img = GL.createImage(file); |
74 |
this.w = img.getSize(0); |
this.w = img.getSize(0); |
75 |
this.h = img.getSize(1); |
this.h = img.getSize(1); |
76 |
|
if(align4) { |
77 |
|
// Compressed textures have to be 4-aligned |
78 |
|
this.w /= 4 ; this.h /= 4; |
79 |
|
this.w *= 4 ; this.h *= 4; |
80 |
|
} |
81 |
int overw = 1; while(overw < w) overw *= 2; |
int overw = 1; while(overw < w) overw *= 2; |
82 |
int overh = 1; while(overh < h) overh *= 2; |
int overh = 1; while(overh < h) overh *= 2; |
83 |
tex = GL.createTexture(); |
tex = GL.createTexture(); |
84 |
texLR = GL.createTexture(); |
texLR = GL.createTexture(); |
85 |
tex.loadNull2D(0, colorFormat, overw, overh, 0, "RGB", "FLOAT"); |
tex.loadNull2D(0, colorFormat, overw, overh, 0, "RGB", "FLOAT"); |
86 |
tex.loadSubImage(0, img, 0, 0); |
if(dbg) pa("Loading image into texture: "+colorFormat+" "+w+" "+h+" "+overw+" "+overh); |
87 |
|
tex.loadSubImage(0, img, 0, 0, 0, 0, w, h); |
88 |
tex.downsampleInto(texLR, "TEXTURE_2D", LODscale, colorFormat, "RGB"); |
tex.downsampleInto(texLR, "TEXTURE_2D", LODscale, colorFormat, "RGB"); |
89 |
rect = new Rect(); |
rect = new Rect(); |
90 |
rect.texId = tex.getTexId(); |
rect.texId = tex.getTexId(); |