0

I have to draw byte array image to glsurfaceview which is continuously comes from server in xamarin android project. code is not working for direct buffer draw but its working for bitmap draw.

my code is working if I convert byte array to bitmap and draw :

mBitmap = { .. create bitmap from byte[].. }
GLUtils.TexImage2D(GLES20.GlTexture2d, 0, mBitmap, 0);

At the same code if I put following code, then its not draw. I want to draw byte array using GLES20.GlTexImage2D(). My not working code is:

// mFrameBuffer is my byte array
ByteBuffer buffer = ByteBuffer.AllocateDirect(mFrameBuffer.Length);
buffer.Order (ByteOrder.NativeOrder());
buffer.Put (mFrameBuffer);
buffer.Position (0);
GLES20.GlTexImage2D (GLES20.GlTexture2d, 0, GLES20.GlRgb565, mWidth, mHeight, 0, GLES20.GlRgb565, GLES20.GlUnsignedByte, buffer);

How to draw image using GlTexImage2D for direct byte array.

Kinchit
  • 16
  • 2

2 Answers2

0

After buffer.position(0) you should bind some texture on some slot

int id = -1;
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, id);

After this check your bitmap config, if it's not RGB565 you should use respective color format in glTexImage2D, for example GLES20.GL_RGBA if bitmap config is Bitmap.Config.ARGB_8888.

GLES20.glTexImage2D(GL20W.GL_TEXTURE_2D, 0, GL20W.GL_RGBA, mWidth, mHeigh, 0,
            GL20W.GL_RGBA, GL20W.GL_UNSIGNED_BYTE, buffer)

Then set your screen as FrameBuffer target:

GLES20.glBindFramebuffer(GL_FRAMEBUFFER, 0);

And after this steps simply draw your texture

Levon Vardanyan
  • 400
  • 4
  • 16
0

I found solution by change format from GLES20.GlRgb565 to GLES20.GlRgba.

GLES20.GlRGB565 and GLES20.GlRGBA4 are not valid values to pass to GLES20.GlTexImage2D(), found from glTexImage2D.

Kinchit
  • 16
  • 2