1 package com.intel.realsense.librealsense;
3 import android.graphics.Rect;
4 import android.opengl.GLES10;
6 import java.nio.ByteBuffer;
7 import java.nio.ByteOrder;
8 import java.nio.IntBuffer;
14 mGlTexture = IntBuffer.allocate(1);
15 GLES10.glGenTextures(1, mGlTexture);
18 public int getTexture() {
return mGlTexture.array()[0]; }
26 ratio = (float)vf.getWidth() / (float)vf.getHeight();
28 float newHeight = in.height();
29 float newWidth = in.height() * ratio;
30 if(newWidth > in.width()){
31 ratio = in.width() / newWidth;
36 float newLeft = in.left + (in.width() - newWidth) / 2
f;
37 float newTop = in.top + (in.height() - newHeight) / 2
f;
38 float newRight = newLeft + newWidth;
39 float newBottom = newTop + newHeight;
40 return new Rect((
int)newLeft, (
int)newTop, (
int)newRight, (
int)newBottom);
50 int size = vf.getStride() * vf.getHeight();
52 mBuffer = ByteBuffer.allocate(size);
53 mBuffer.order(ByteOrder.LITTLE_ENDIAN);
60 draw(r, mGlTexture.get(0));
65 public synchronized void close() {
68 GLES10.glDeleteTextures(1, mGlTexture);
73 GLES10.glBindTexture(GLES10.GL_TEXTURE_2D, texture);
79 GLES10.glTexImage2D(GLES10.GL_TEXTURE_2D, 0, GLES10.GL_RGB, vf.
getWidth(), vf.
getHeight(), 0, GLES10.GL_RGB, GLES10.GL_UNSIGNED_BYTE,
buffer);
82 GLES10.glTexImage2D(GLES10.GL_TEXTURE_2D, 0, GLES10.GL_RGBA, vf.
getWidth(), vf.
getHeight(), 0, GLES10.GL_RGBA, GLES10.GL_UNSIGNED_BYTE,
buffer);
85 GLES10.glTexImage2D(GLES10.GL_TEXTURE_2D, 0, GLES10.GL_LUMINANCE, vf.
getWidth(), vf.
getHeight(), 0, GLES10.GL_LUMINANCE, GLES10.GL_UNSIGNED_BYTE,
buffer);
88 throw new RuntimeException(
"The requested format is not supported by the viewer");
93 GLES10.glTexParameterx(GLES10.GL_TEXTURE_2D, GLES10.GL_TEXTURE_MAG_FILTER, GLES10.GL_LINEAR);
94 GLES10.glTexParameterx(GLES10.GL_TEXTURE_2D, GLES10.GL_TEXTURE_MIN_FILTER, GLES10.GL_LINEAR);
95 GLES10.glTexParameterx(GLES10.GL_TEXTURE_2D, GLES10.GL_TEXTURE_WRAP_S, 0x2900);
96 GLES10.glTexParameterx(GLES10.GL_TEXTURE_2D, GLES10.GL_TEXTURE_WRAP_T, 0x2900);
97 GLES10.glPixelStorei(0x0CF2, 0);
98 GLES10.glBindTexture(GLES10.GL_TEXTURE_2D, 0);
105 GLES10.glBindTexture(GLES10.GL_TEXTURE_2D, texture);
106 GLES10.glEnable(GLES10.GL_TEXTURE_2D);
111 r.width(), r.height(),
114 ByteBuffer ver = ByteBuffer.allocateDirect(verArray.length * 4);
115 ver.order(ByteOrder.nativeOrder());
123 ByteBuffer tex = ByteBuffer.allocateDirect(texArray.length * 4);
124 tex.order(ByteOrder.nativeOrder());
126 ver.asFloatBuffer().put(verArray);
127 tex.asFloatBuffer().put(texArray);
129 GLES10.glEnableClientState(GLES10.GL_VERTEX_ARRAY);
130 GLES10.glEnableClientState(GLES10.GL_TEXTURE_COORD_ARRAY);
132 GLES10.glVertexPointer(2, GLES10.GL_FLOAT, 0, ver);
133 GLES10.glTexCoordPointer(2, GLES10.GL_FLOAT, 0, tex);
134 GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN,0,4);
136 GLES10.glDisableClientState(GLES10.GL_VERTEX_ARRAY);
137 GLES10.glDisableClientState(GLES10.GL_TEXTURE_COORD_ARRAY);
139 GLES10.glDisable(GLES10.GL_TEXTURE_2D);
140 GLES10.glBindTexture(GLES10.GL_TEXTURE_2D, 0);
synchronized void close()
VideoStreamProfile getProfile()
synchronized void draw(Rect rect)
static void setViewport(Rect r)
void getData(byte[] data)
static void draw(Rect r, int texture)
Rect adjustRatio(Rect in)
static void upload(VideoFrame vf, ByteBuffer buffer, int texture)
boolean is(Extension extension)