glteximage2d - Generating and updating 8-bit gray-scale texture in OpenGL ES 2.0 -
for opengl texture cache need initialize large (≥ 2048x2048) texture , update little sections of it.
the following (pseudo-)code works:
// setup texture int[] buffer = new int[2048*2048 / 4]; // generate dummy buffer 1 byte per pixel int id = glgentexture(); glbindtexture(gl_texture_2d, id); glteximage2d(gl_texture_2d, 0, gl_alpha, 2048, 2048, 0, gl_alpha, gl_unsigned_byte, buffer); // perform update glbindtexture(gl_texture_2d, id); gltexsubimage2d(gl_texture_2d, 0, x, y, width, height, gl_alpha, gl_unsigned_byte, data);
but find totally unnecessary creation of 4mb int-buffer bit undesirable least. so, tried following instead:
// setup texture int id = glgentexture(); glbindtexture(gl_texture_2d, id); glcopyteximage2d(gl_texture_2d, 0, gl_alpha, 0, 0, 2048, 2048, 0);
this gave me gl_invalid_operation error, believe caused fact frame-buffer not contain alpha value, rather setting 1, call fails.
next attempt:
// setup texture int id = glgentexture(); glbindtexture(gl_texture_2d, id); glcopyteximage2d(gl_texture_2d, 0, gl_luminance, 0, 0, 2048, 2048, 0);
this works, gltexsubimage2d call fails gl_invalid_operation because specifies gl_alpha instead of gl_luminance. so, changed get:
// perform update glbindtexture(gl_texture_2d, id); gltexsubimage2d(gl_texture_2d, 0, x, y, width, height, gl_luminance, gl_unsigned_byte, data);
and changed shader read value r
rather a
component.
this works on devices, on iphone 3gs, still gl_invalid_operation error in gltexsubimage2d call. why? , how can fix this? there way, example, change internal texture format? or can create other framebuffer have alpha component can use source glcopyteximage2d?
data
can null
in glteximage2d()
call if want allocate empty texture:
data
may null pointer. in case, texture memory allocated accommodate texture ofwidth
,height
. can download subtextures initialize texture memory. image undefined if user tries apply uninitialized portion of texture image primitive.
Comments
Post a Comment