Skip to content

Commit 840d090

Browse files
committed
try to initialize the texture with 0 (crashing)
Signed-off-by: Umair Khan <[email protected]>
1 parent e834f00 commit 840d090

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

src/in/omerjerk/processing/video/android/VideoBase.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package in.omerjerk.processing.video.android;
22

33
import java.lang.reflect.Method;
4+
import java.nio.ByteBuffer;
5+
import java.nio.ByteOrder;
46
import java.nio.IntBuffer;
7+
import java.util.Arrays;
58

69
import in.omerjerk.processing.video.android.helpers.FullFrameRect;
710
import in.omerjerk.processing.video.android.helpers.GlUtil;
@@ -120,11 +123,26 @@ protected void prepareFrameBuffers() {
120123
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, customTexture.get(0));
121124
GlUtil.checkGlError("glBindTexture");
122125

123-
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
124-
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
125-
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
126-
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
127-
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
126+
int[] glColor = new int[16*16];
127+
Arrays.fill(glColor, 0);
128+
IntBuffer texels = allocateDirectIntBuffer(16 * 16);
129+
texels.put(glColor);
130+
texels.rewind();
131+
/*
132+
for (int y = 0; y < height; y += 16) {
133+
int h = PApplet.min(16, height - y);
134+
for (int x = 0; x < width; x += 16) {
135+
int w = PApplet.min(16, width - x);
136+
GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, x, y, w, h, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, texels);
137+
}
138+
}
139+
GlUtil.checkGlError("glTexSubImage2D"); */
140+
141+
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
142+
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
143+
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
144+
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
145+
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, texels);
128146
GlUtil.checkGlError("glTexImage2D");
129147

130148
GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0,
@@ -145,6 +163,12 @@ protected void prepareFrameBuffers() {
145163
}
146164
}
147165

166+
protected static IntBuffer allocateDirectIntBuffer(int size) {
167+
int bytes = size * (Integer.SIZE/8);
168+
return ByteBuffer.allocateDirect(bytes).order(ByteOrder.nativeOrder()).
169+
asIntBuffer();
170+
}
171+
148172
protected void initalizeFrameBuffer() {
149173
glView.queueEvent(new Runnable() {
150174
@Override

0 commit comments

Comments
 (0)