java - Loading Android OpenGL ES 2.0 textures using an array, not a Buffer -
this question similar how around performance issues buffer.put() , android opengl i'm asking because:
- it's different - issue textures, not vertex buffers
- though question clear, seems of answers miss point
- the question 3 years old , maybe there's new solve problem
- it surprises me issue...i feel must misunderstanding something.
anyway i'm using opengl es 2.0 on android. have large texture (say 1024x1024) must updated every frame. there no way around afaik - content of texture video.
the problem android java interface opengl usings java.nio.buffer objects, not arrays. last parameter of
public static void gles20.glteximage2d (int target, int level, int internalformat, int width, int height, int border, int format, int type, buffer pixels)
is buffer, not byte[]
or int[]
.
so, instead of generating texture's content (for every frame) directly int[] can passed glteximage2d
, have generate content int[], call intbuffer.put() entire huge array. traceview , calls system.nanotime() around call show takes lot of cpu, not surprisingly.
how 1 work around this? tried use intbuffer.array() content array, but
- the
array()
call not succeed buffers allocatedintbuffer.allocatedirect()
- the
glteximage2d()
call not work buffers allocatedintbuffer.allocate()
other things can think of:
- call
glteximage2d
native code, assume isn't issue android gl native code interface - do work on thread. don't know if causes contention issues between thread producing texture content , gl thread calls glteximage2d. , anyway, it's still cpu cycles copy memory when isn't logically necessary.
i seems wouldn't issue if there version of gles20.glteximage2d took int[] or other array type, instead of buffer.
a buffer
in android can backed array. means buffer wrapping array , modifications array reflected in buffer.
http://developer.android.com/reference/java/nio/buffer.html#array()
you can follow code found on website create bytebuffer
around byte array:
Comments
Post a Comment