android - Using GL_UNSIGNED_SHORT_4_4_4_4 for textures -


i have method loading texture opengl:

bool androidgraphicsmanager::settexture(     uint& id, uchar* image, uint width, uint height,     bool wrapurepeat, bool wrapvrepeat, bool usemipmaps) {     glgentextures(1, &id);     glbindtexture(gl_texture_2d, id);     glteximage2d(         gl_texture_2d, 0, gl_rgba,         width, height, 0, gl_rgba,         gl_unsigned_byte, (glvoid*) image);     int minfilter = gl_linear;      if (usemipmaps) {         glgeneratemipmap(gl_texture_2d);         minfilter = gl_nearest_mipmap_nearest;     }     gltexparameteri(gl_texture_2d,         gl_texture_min_filter, minfilter);     gltexparameteri(         gl_texture_2d,         gl_texture_mag_filter, gl_nearest);     int wrap_u = wrapurepeat ?         gl_repeat : gl_clamp_to_edge;     int wrap_v = wrapvrepeat ?         gl_repeat : gl_clamp_to_edge;     gltexparameteri(         gl_texture_2d,         gl_texture_wrap_s, wrap_u);     gltexparameteri(         gl_texture_2d,         gl_texture_wrap_t, wrap_v);     glbindtexture(gl_texture_2d, 0);     return !checkglerror("loading texture."); } 

this works fine. load texture using libpng. gives me array of unsigned chars. pass array method specified above. pictures 32bit, assume in uchar array each uchar contains single color component , 4 uchars make 1 pixel. wanted try using 16 bit textures. changed gl_unsigned_byte gl_unsigned_short_4_4_4_4. apparently isn't enough because gives me result: enter image description here else need change able display 16 bit textures?

[edit] @datenwolf suggested tried using code:

glteximage2d(     gl_texture_2d, 0, gl_rgba4,     width, height, 0, gl_rgba,     gl_unsigned_short_4_4_4_4, (glvoid*) image); 

i used on linux version of engine, result exact same in previous android screenshot. safe assume problem libpng , way produces uchar array?

[edit2] managed compress 32bit texture 16bit. needed simple iteration through 32bit texture data , few bitshifting operations compress 32 bits 16.

void* rgba8888torgba4444(void* in, int size) {     int pixelcount = size / 4;     ulong* input = static_cast<ulong*>(in);     ushort* output = new ushort[pixelcount];     (int = 0; < pixelcount; i++) {         ulong pixel = input[i];         // unpack source data 8 bit values         uint r = pixel & 0xff;         uint g = (pixel >> 8) & 0xff;         uint b = (pixel >> 16) & 0xff;         uint = (pixel >> 24) & 0xff;         // convert 4 bit vales         r >>= 4; g >>= 4; b >>= 4; >>= 4;         output[i] = r << 12 | g << 8 | b << 4 | a;     }     return static_cast<void*>(output); } 

i thought mobile device yield performance increase, unfortunately saw no gain in performance on galaxy siii. enter image description here

the best thing use image library devil kind of thing.

but if want convert image data have libpbg can similar code below.

keep in mind trade size speed when doing this.

struct color { unsigned char r:4; unsigned char g:4; unsigned char b:4; unsigned char a:4; };  float factor = 16 / 255;  color colors[imgwidth*imgheight];  for(int = 0; < imgwidth*imgheight; ++i) {     colors[i].r = image[i*4]*factor;     colors[i].g = image[i*4+1]*factor;     colors[i].b = image[i*4+2]*factor;     colors[i].a = image[i*4+3]*factor; } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -