42 |
42 |
private final int BYTESFLOAT = 4;
|
43 |
43 |
private final int POSITION = 3;
|
44 |
44 |
|
45 |
|
private final boolean USEPOINTS=false;
|
|
45 |
private final boolean USEPOINTS=true;
|
46 |
46 |
|
47 |
47 |
private GLSurfaceView mView;
|
48 |
48 |
private DistortedProgram mFeedbackProgram;
|
... | ... | |
62 |
62 |
{
|
63 |
63 |
mFeedbackProgram.useProgram();
|
64 |
64 |
|
65 |
|
int numVertices = (USEPOINTS ? mVertices : 3*(mVertices-2));
|
66 |
|
|
67 |
65 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mVBO[0]);
|
68 |
|
GLES30.glVertexAttribPointer(mFeedbackProgram.mAttribute[0], USEPOINTS ? 1:POSITION, GLES30.GL_FLOAT, false, 0, 0);
|
|
66 |
GLES30.glVertexAttribPointer(mFeedbackProgram.mAttribute[0], POSITION, GLES30.GL_FLOAT, false, 0, 0);
|
69 |
67 |
GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, mTBO[0]);
|
70 |
68 |
|
71 |
69 |
GLES30.glEnable(GLES30.GL_RASTERIZER_DISCARD);
|
72 |
70 |
GLES30.glBeginTransformFeedback( USEPOINTS ? GLES30.GL_POINTS : GLES30.GL_TRIANGLES);
|
73 |
|
GLES30.glDrawArrays( USEPOINTS ? GLES30.GL_POINTS : GLES30.GL_TRIANGLE_STRIP, 0, USEPOINTS ? mVertices*POSITION : mVertices);
|
|
71 |
GLES30.glDrawArrays( USEPOINTS ? GLES30.GL_POINTS : GLES30.GL_TRIANGLE_STRIP, 0, mVertices);
|
|
72 |
|
|
73 |
int error = GLES30.glGetError();
|
|
74 |
|
|
75 |
if( error != GLES30.GL_NO_ERROR )
|
|
76 |
{
|
|
77 |
throw new RuntimeException("DrawArrays: glError 0x" + Integer.toHexString(error));
|
|
78 |
}
|
|
79 |
|
74 |
80 |
GLES30.glEndTransformFeedback();
|
75 |
81 |
GLES30.glDisable(GLES30.GL_RASTERIZER_DISCARD);
|
76 |
82 |
GLES30.glFlush();
|
77 |
83 |
|
|
84 |
int numVertices = 3*(mVertices);
|
|
85 |
|
78 |
86 |
Buffer mappedBuffer = GLES30.glMapBufferRange(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, numVertices*POSITION*BYTESFLOAT, GLES30.GL_MAP_READ_BIT);
|
79 |
87 |
FloatBuffer fb = ((ByteBuffer) mappedBuffer).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
80 |
88 |
String msg = "";
|
... | ... | |
115 |
123 |
String header= "#version 300 es\n";
|
116 |
124 |
String[] feedback = { "outValue" };
|
117 |
125 |
|
118 |
|
if(USEPOINTS)
|
119 |
|
{
|
120 |
|
header += "#define USEPOINTS 1\n";
|
121 |
|
}
|
122 |
|
else
|
123 |
|
{
|
124 |
|
header += "#define USEPOINTS 0\n";
|
125 |
|
}
|
126 |
|
|
127 |
126 |
try
|
128 |
127 |
{
|
129 |
128 |
mFeedbackProgram = new DistortedProgram(vertStream,fragStream, header, header, glsl, feedback );
|
... | ... | |
141 |
140 |
mVBO = new int[1];
|
142 |
141 |
GLES30.glGenBuffers(1, mVBO, 0);
|
143 |
142 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mVBO[0]);
|
144 |
|
GLES30.glBufferData(GLES30.GL_ARRAY_BUFFER, mVertices*POSITION*BYTESFLOAT, data, GLES30.GL_STATIC_READ);
|
|
143 |
GLES30.glBufferData(GLES30.GL_ARRAY_BUFFER, mVertices*POSITION*BYTESFLOAT, data, GLES30.GL_STATIC_DRAW);
|
145 |
144 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);
|
146 |
145 |
|
147 |
|
int numVertices = (USEPOINTS ? mVertices : 3*(mVertices-2));
|
148 |
|
|
149 |
146 |
mTBO = new int[1];
|
150 |
147 |
GLES30.glGenBuffers(1, mTBO, 0);
|
151 |
148 |
GLES30.glBindBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, mTBO[0]);
|
152 |
|
GLES30.glBufferData(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, numVertices*POSITION*BYTESFLOAT, null, GLES30.GL_STATIC_READ);
|
|
149 |
GLES30.glBufferData(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 3*(mVertices)*POSITION*BYTESFLOAT, null, GLES30.GL_STATIC_READ);
|
153 |
150 |
GLES30.glBindBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0);
|
154 |
151 |
}
|
155 |
152 |
}
|
This commit (and reading the OpenGL ES 3.0 spec) pretty conclusively proves that, sadly, Nexus 4's Transform Feedback implementation is incomplete (doesn't work with GL_TRIANGLES primitiveMode)