PDA

View Full Version : Right upgrade from GLES20 to GLES30



golanitay1984
09-15-2016, 02:12 AM
As I understood, from GLES30 there is no more gl_FragColor buffer (I saw it HERE)

Since I can't read a "Special Variables ", how can I read an "out" buffer?

This is my GL code:

private static final String VERTEX_SHADER =
"#version 300 es\n"+
"uniform mat4 uMVPMatrix;\n" +
"uniform mat4 uSTMatrix;\n" +
"in vec4 aPosition;\n" +
"in vec4 aTextureCoord;\n" +
"out vec2 vTextureCoord;\n" +
"void main() {\n" +
" gl_Position = uMVPMatrix * aPosition;\n" +
" vTextureCoord = (uSTMatrix * aTextureCoord).xy;\n" +
"}\n";

private static final String FRAGMENT_SHADER =
"#version 300 es\n"+
"#extension GL_OES_EGL_image_external_essl3 : require\n" +
"precision mediump float;\n" + // highp here doesn't seem to matter
"in vec2 vTextureCoord;\n" +
"uniform sampler2D sTexture;\n" +
"layout(location = 0) out vec4 fragColor ;\n" +
"void main() {\n" +
" vec4 tc = texture(sTexture, vTextureCoord);\n" +
" fragColor.r = tc.r * 0.3 + tc.g * 0.59 + tc.b * 0.11;\n" +
" fragColor.g = tc.r * 0.3 + tc.g * 0.59 + tc.b * 0.11;\n" +
" fragColor.b = tc.r * 0.3 + tc.g * 0.59 + tc.b * 0.11;\n" +
"}\n";

Here I tried to read the data:

ByteBuffer mPixelBuf = ByteBuffer.allocateDirect(mWidth * mHeight * 4);
mPixelBuf.order(ByteOrder.LITTLE_ENDIAN);

GLES30.glReadPixels(startX, startY, frameWidth, frameHeight, GLES30.GL_RGBA, GLES30.GL_UNSIGNED_BYTE, mPixelBuf);


There are no gl errors in the code.

The output mPixelBuf only zeroes.

How can I make sure that fragColor is reading?

Thanks