Revision b7074bc6
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/library/effect/PostprocessEffect.java | ||
---|---|---|
79 | 79 |
private static ArrayList<Source> mSources = new ArrayList<>(); |
80 | 80 |
private static int mNumSources = 0; |
81 | 81 |
|
82 |
private class Job |
|
82 |
private static class Job
|
|
83 | 83 |
{ |
84 | 84 |
int type; |
85 | 85 |
int level; |
... | ... | |
92 | 92 |
} |
93 | 93 |
|
94 | 94 |
private ArrayList<Job> mJobs = new ArrayList<>(); |
95 |
private int mQualityLevel; |
|
95 | 96 |
|
96 |
int mQualityLevel; |
|
97 | 97 |
float mQualityScale; |
98 | 98 |
|
99 | 99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
111 | 111 |
* |
112 | 112 |
* @y.exclude |
113 | 113 |
*/ |
114 |
public static void createPrograms() |
|
114 |
public static void createPrograms(int GLSL)
|
|
115 | 115 |
{ |
116 | 116 |
Source source; |
117 | 117 |
int len = mSources.size(); |
118 | 118 |
|
119 |
String version = "#version "+GLSL+" es\n"; |
|
120 |
|
|
119 | 121 |
for(int i=0; i<len; i++) |
120 | 122 |
{ |
121 | 123 |
source = mSources.remove(0); |
122 | 124 |
|
123 |
//android.util.Log.d("postprocess", "compiling: "+source.mName); |
|
124 |
|
|
125 | 125 |
try |
126 | 126 |
{ |
127 |
mPrograms.add (new DistortedProgram(source.mVertexShader,source.mFragmentShader));
|
|
127 |
mPrograms.add (new DistortedProgram(version+source.mVertexShader,version+source.mFragmentShader));
|
|
128 | 128 |
} |
129 | 129 |
catch(Exception e) |
130 | 130 |
{ |
src/main/java/org/distorted/library/effect/PostprocessEffectBlur.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.library.effect; |
21 | 21 |
|
22 |
import android.opengl.GLES31;
|
|
22 |
import android.opengl.GLES30;
|
|
23 | 23 |
|
24 |
import org.distorted.library.main.DistortedLibrary; |
|
25 | 24 |
import org.distorted.library.main.DistortedFramebuffer; |
26 | 25 |
import org.distorted.library.main.InternalRenderState; |
27 | 26 |
import org.distorted.library.program.DistortedProgram; |
... | ... | |
37 | 36 |
|
38 | 37 |
private Data1D mBlurRadius; |
39 | 38 |
|
40 |
private static final float GAUSSIAN[] = // G(0.00), G(0.03), G(0.06), ..., G(3.00), 0
|
|
39 |
private static final float[] GAUSSIAN = // G(0.00), G(0.03), G(0.06), ..., G(3.00), 0
|
|
41 | 40 |
{ // where G(x)= (1/(sqrt(2*PI))) * e^(-(x^2)/2). The last 0 terminates. |
42 | 41 |
0.398948f, 0.398769f, 0.398231f, 0.397336f, 0.396086f, 0.394485f, 0.392537f, 0.390247f, 0.387622f, 0.384668f, |
43 | 42 |
0.381393f, 0.377806f, 0.373916f, 0.369733f, 0.365268f, 0.360532f, 0.355538f, 0.350297f, 0.344823f, 0.339129f, |
... | ... | |
188 | 187 |
|
189 | 188 |
int offset = radius + radius*radius/4; |
190 | 189 |
radius = (radius+1)/2; |
191 |
GLES31.glViewport(0, 0, (int)w, (int)h);
|
|
190 |
GLES30.glViewport(0, 0, (int)w, (int)h);
|
|
192 | 191 |
|
193 | 192 |
// horizontal blur |
194 | 193 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]*offsetCorrW; |
... | ... | |
197 | 196 |
buffer.bindForOutput(1); |
198 | 197 |
buffer.setAsInput(0); |
199 | 198 |
|
200 |
GLES31.glColorMask(true,true,true,true);
|
|
201 |
GLES31.glClearColor(1.0f,1.0f,1.0f,0.0f);
|
|
202 |
GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT);
|
|
199 |
GLES30.glColorMask(true,true,true,true);
|
|
200 |
GLES30.glClearColor(1.0f,1.0f,1.0f,0.0f);
|
|
201 |
GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
|
|
203 | 202 |
|
204 |
GLES31.glUniform1f ( mProgram1.mUniform[0] , n );
|
|
205 |
GLES31.glUniform2f ( mProgram1.mUniform[1] , corrW, corrH );
|
|
206 |
GLES31.glUniform1i ( mProgram1.mUniform[2] , 0 );
|
|
207 |
GLES31.glUniform1fv( mProgram1.mUniform[3] , radius+1, mOffsets,0);
|
|
208 |
GLES31.glUniform1fv( mProgram1.mUniform[4] , radius+1, weightsCache,offset);
|
|
209 |
GLES31.glUniform1i ( mProgram1.mUniform[5] , radius);
|
|
210 |
GLES31.glVertexAttribPointer(mProgram1.mAttribute[0], POS_DATA_SIZE, GLES31.GL_FLOAT, false, 0, mQuadPositions);
|
|
211 |
GLES31.glVertexAttribPointer(mProgram1.mAttribute[1], TEX_DATA_SIZE, GLES31.GL_FLOAT, false, 0, mQuadTexture);
|
|
212 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
|
|
203 |
GLES30.glUniform1f ( mProgram1.mUniform[0] , n );
|
|
204 |
GLES30.glUniform2f ( mProgram1.mUniform[1] , corrW, corrH );
|
|
205 |
GLES30.glUniform1i ( mProgram1.mUniform[2] , 0 );
|
|
206 |
GLES30.glUniform1fv( mProgram1.mUniform[3] , radius+1, mOffsets,0);
|
|
207 |
GLES30.glUniform1fv( mProgram1.mUniform[4] , radius+1, weightsCache,offset);
|
|
208 |
GLES30.glUniform1i ( mProgram1.mUniform[5] , radius);
|
|
209 |
GLES30.glVertexAttribPointer(mProgram1.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions);
|
|
210 |
GLES30.glVertexAttribPointer(mProgram1.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture);
|
|
211 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
|
|
213 | 212 |
|
214 | 213 |
// vertical blur |
215 | 214 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]*offsetCorrH; |
... | ... | |
218 | 217 |
buffer.bindForOutput(0); |
219 | 218 |
buffer.setAsInput(1); |
220 | 219 |
|
221 |
GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT);
|
|
220 |
GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
|
|
222 | 221 |
|
223 |
GLES31.glUniform1f ( mProgram2.mUniform[0] , n );
|
|
224 |
GLES31.glUniform2f ( mProgram2.mUniform[1] , corrW, corrH );
|
|
225 |
GLES31.glUniform1i ( mProgram2.mUniform[2] , 0 );
|
|
226 |
GLES31.glUniform1fv( mProgram2.mUniform[3] , radius+1, mOffsets,0);
|
|
227 |
GLES31.glUniform1fv( mProgram2.mUniform[4] , radius+1, weightsCache,offset);
|
|
228 |
GLES31.glUniform1i ( mProgram2.mUniform[5] , radius);
|
|
229 |
GLES31.glVertexAttribPointer(mProgram2.mAttribute[0], POS_DATA_SIZE, GLES31.GL_FLOAT, false, 0, mQuadPositions);
|
|
230 |
GLES31.glVertexAttribPointer(mProgram2.mAttribute[1], TEX_DATA_SIZE, GLES31.GL_FLOAT, false, 0, mQuadTexture);
|
|
231 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
|
|
222 |
GLES30.glUniform1f ( mProgram2.mUniform[0] , n );
|
|
223 |
GLES30.glUniform2f ( mProgram2.mUniform[1] , corrW, corrH );
|
|
224 |
GLES30.glUniform1i ( mProgram2.mUniform[2] , 0 );
|
|
225 |
GLES30.glUniform1fv( mProgram2.mUniform[3] , radius+1, mOffsets,0);
|
|
226 |
GLES30.glUniform1fv( mProgram2.mUniform[4] , radius+1, weightsCache,offset);
|
|
227 |
GLES30.glUniform1i ( mProgram2.mUniform[5] , radius);
|
|
228 |
GLES30.glVertexAttribPointer(mProgram2.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions);
|
|
229 |
GLES30.glVertexAttribPointer(mProgram2.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture);
|
|
230 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
|
|
232 | 231 |
|
233 | 232 |
InternalRenderState.unuseStencilMark(); |
234 | 233 |
|
... | ... | |
245 | 244 |
{ |
246 | 245 |
final String blurVertex = |
247 | 246 |
|
248 |
DistortedLibrary.GLSL_VERSION + |
|
249 | 247 |
"precision lowp float; \n"+ |
250 | 248 |
"in vec2 a_Position; \n"+ |
251 | 249 |
"in vec2 a_TexCoord; \n"+ |
... | ... | |
261 | 259 |
|
262 | 260 |
final String blurFragment1 = |
263 | 261 |
|
264 |
DistortedLibrary.GLSL_VERSION + |
|
265 | 262 |
"#define MAX_BLUR "+MAX_HALO+ "\n"+ |
266 | 263 |
"precision lowp float; \n"+ |
267 | 264 |
"in vec2 v_TexCoord; \n"+ |
... | ... | |
284 | 281 |
|
285 | 282 |
final String blurFragment2 = |
286 | 283 |
|
287 |
DistortedLibrary.GLSL_VERSION + |
|
288 | 284 |
"#define MAX_BLUR "+MAX_HALO+ "\n"+ |
289 | 285 |
"precision lowp float; \n"+ |
290 | 286 |
"in vec2 v_TexCoord; \n"+ |
src/main/java/org/distorted/library/effect/PostprocessEffectGlow.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.library.effect; |
21 | 21 |
|
22 |
import android.opengl.GLES31;
|
|
22 |
import android.opengl.GLES30;
|
|
23 | 23 |
|
24 |
import org.distorted.library.main.DistortedLibrary; |
|
25 | 24 |
import org.distorted.library.main.DistortedFramebuffer; |
26 | 25 |
import org.distorted.library.main.InternalRenderState; |
27 | 26 |
import org.distorted.library.program.DistortedProgram; |
... | ... | |
39 | 38 |
private Data1D mGlowRadius; |
40 | 39 |
private Data4D mColor; |
41 | 40 |
|
42 |
private static final float GAUSSIAN[] = // G(0.00), G(0.03), G(0.06), ..., G(3.00), 0
|
|
41 |
private static final float[] GAUSSIAN = // G(0.00), G(0.03), G(0.06), ..., G(3.00), 0
|
|
43 | 42 |
{ // where G(x)= (1/(sqrt(2*PI))) * e^(-(x^2)/2). The last 0 terminates. |
44 | 43 |
0.398948f, 0.398769f, 0.398231f, 0.397336f, 0.396086f, 0.394485f, 0.392537f, 0.390247f, 0.387622f, 0.384668f, |
45 | 44 |
0.381393f, 0.377806f, 0.373916f, 0.369733f, 0.365268f, 0.360532f, 0.355538f, 0.350297f, 0.344823f, 0.339129f, |
... | ... | |
191 | 190 |
|
192 | 191 |
int offset = radius + radius*radius/4; |
193 | 192 |
radius = (radius+1)/2; |
194 |
GLES31.glViewport(0, 0, (int)w, (int)h);
|
|
193 |
GLES30.glViewport(0, 0, (int)w, (int)h);
|
|
195 | 194 |
|
196 | 195 |
// horizontal blur |
197 | 196 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]*offsetCorrW; |
... | ... | |
200 | 199 |
buffer.bindForOutput(1); |
201 | 200 |
buffer.setAsInput(0); |
202 | 201 |
|
203 |
GLES31.glColorMask(true,true,true,true);
|
|
204 |
GLES31.glClearColor(1.0f,1.0f,1.0f,0.0f);
|
|
205 |
GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT);
|
|
202 |
GLES30.glColorMask(true,true,true,true);
|
|
203 |
GLES30.glClearColor(1.0f,1.0f,1.0f,0.0f);
|
|
204 |
GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
|
|
206 | 205 |
|
207 |
GLES31.glUniform1f ( mProgram1.mUniform[0] , n );
|
|
208 |
GLES31.glUniform2f ( mProgram1.mUniform[1] , corrW, corrH );
|
|
209 |
GLES31.glUniform1i ( mProgram1.mUniform[2] , 0 );
|
|
210 |
GLES31.glUniform1fv( mProgram1.mUniform[3] , radius+1, mOffsets,0);
|
|
211 |
GLES31.glUniform1fv( mProgram1.mUniform[4] , radius+1, weightsCache,offset);
|
|
212 |
GLES31.glUniform1i ( mProgram1.mUniform[5] , radius);
|
|
213 |
GLES31.glVertexAttribPointer(mProgram1.mAttribute[0], POS_DATA_SIZE, GLES31.GL_FLOAT, false, 0, mQuadPositions);
|
|
214 |
GLES31.glVertexAttribPointer(mProgram1.mAttribute[1], TEX_DATA_SIZE, GLES31.GL_FLOAT, false, 0, mQuadTexture);
|
|
215 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
|
|
206 |
GLES30.glUniform1f ( mProgram1.mUniform[0] , n );
|
|
207 |
GLES30.glUniform2f ( mProgram1.mUniform[1] , corrW, corrH );
|
|
208 |
GLES30.glUniform1i ( mProgram1.mUniform[2] , 0 );
|
|
209 |
GLES30.glUniform1fv( mProgram1.mUniform[3] , radius+1, mOffsets,0);
|
|
210 |
GLES30.glUniform1fv( mProgram1.mUniform[4] , radius+1, weightsCache,offset);
|
|
211 |
GLES30.glUniform1i ( mProgram1.mUniform[5] , radius);
|
|
212 |
GLES30.glVertexAttribPointer(mProgram1.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions);
|
|
213 |
GLES30.glVertexAttribPointer(mProgram1.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture);
|
|
214 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
|
|
216 | 215 |
|
217 | 216 |
// vertical blur |
218 | 217 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]*offsetCorrH; |
... | ... | |
221 | 220 |
buffer.bindForOutput(0); |
222 | 221 |
buffer.setAsInput(1); |
223 | 222 |
|
224 |
GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT);
|
|
223 |
GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
|
|
225 | 224 |
|
226 |
GLES31.glUniform1f ( mProgram2.mUniform[0] , n );
|
|
227 |
GLES31.glUniform2f ( mProgram2.mUniform[1] , corrW, corrH );
|
|
228 |
GLES31.glUniform1i ( mProgram2.mUniform[2] , 0 );
|
|
229 |
GLES31.glUniform1fv( mProgram2.mUniform[3] , radius+1, mOffsets,0);
|
|
230 |
GLES31.glUniform1fv( mProgram2.mUniform[4] , radius+1, weightsCache,offset);
|
|
231 |
GLES31.glUniform1i ( mProgram2.mUniform[5] , radius);
|
|
232 |
GLES31.glVertexAttribPointer(mProgram2.mAttribute[0], POS_DATA_SIZE, GLES31.GL_FLOAT, false, 0, mQuadPositions);
|
|
233 |
GLES31.glVertexAttribPointer(mProgram2.mAttribute[1], TEX_DATA_SIZE, GLES31.GL_FLOAT, false, 0, mQuadTexture);
|
|
234 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
|
|
225 |
GLES30.glUniform1f ( mProgram2.mUniform[0] , n );
|
|
226 |
GLES30.glUniform2f ( mProgram2.mUniform[1] , corrW, corrH );
|
|
227 |
GLES30.glUniform1i ( mProgram2.mUniform[2] , 0 );
|
|
228 |
GLES30.glUniform1fv( mProgram2.mUniform[3] , radius+1, mOffsets,0);
|
|
229 |
GLES30.glUniform1fv( mProgram2.mUniform[4] , radius+1, weightsCache,offset);
|
|
230 |
GLES30.glUniform1i ( mProgram2.mUniform[5] , radius);
|
|
231 |
GLES30.glVertexAttribPointer(mProgram2.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions);
|
|
232 |
GLES30.glVertexAttribPointer(mProgram2.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture);
|
|
233 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
|
|
235 | 234 |
|
236 | 235 |
InternalRenderState.unuseStencilMark(); |
237 | 236 |
|
... | ... | |
248 | 247 |
{ |
249 | 248 |
final String glowVertex = |
250 | 249 |
|
251 |
DistortedLibrary.GLSL_VERSION + |
|
252 | 250 |
"precision lowp float; \n"+ |
253 | 251 |
"in vec2 a_Position; \n"+ |
254 | 252 |
"in vec2 a_TexCoord; \n"+ |
... | ... | |
264 | 262 |
|
265 | 263 |
final String glowFragment1 = |
266 | 264 |
|
267 |
DistortedLibrary.GLSL_VERSION + |
|
268 | 265 |
"#define MAX_BLUR "+MAX_HALO+ "\n"+ |
269 | 266 |
"precision lowp float; \n"+ |
270 | 267 |
"in vec2 v_TexCoord; \n"+ |
... | ... | |
287 | 284 |
|
288 | 285 |
final String glowFragment2 = |
289 | 286 |
|
290 |
DistortedLibrary.GLSL_VERSION + |
|
291 | 287 |
"#define MAX_BLUR "+MAX_HALO+ "\n"+ |
292 | 288 |
"precision lowp float; \n"+ |
293 | 289 |
"in vec2 v_TexCoord; \n"+ |
src/main/java/org/distorted/library/effectqueue/EffectQueueFragment.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.library.effectqueue; |
21 | 21 |
|
22 |
import android.opengl.GLES31;
|
|
22 |
import android.opengl.GLES30;
|
|
23 | 23 |
|
24 | 24 |
import org.distorted.library.effect.EffectType; |
25 | 25 |
import org.distorted.library.effect.FragmentEffect; |
... | ... | |
47 | 47 |
|
48 | 48 |
static void uniforms(int mProgramH, int variant) |
49 | 49 |
{ |
50 |
mNumEffectsH[variant]= GLES31.glGetUniformLocation( mProgramH, "fNumEffects");
|
|
51 |
mNameH[variant] = GLES31.glGetUniformLocation( mProgramH, "fName");
|
|
52 |
mUniformsH[variant] = GLES31.glGetUniformLocation( mProgramH, "fUniforms");
|
|
50 |
mNumEffectsH[variant]= GLES30.glGetUniformLocation( mProgramH, "fNumEffects");
|
|
51 |
mNameH[variant] = GLES30.glGetUniformLocation( mProgramH, "fName");
|
|
52 |
mUniformsH[variant] = GLES30.glGetUniformLocation( mProgramH, "fUniforms");
|
|
53 | 53 |
} |
54 | 54 |
|
55 | 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
77 | 77 |
|
78 | 78 |
void send(int variant) |
79 | 79 |
{ |
80 |
GLES31.glUniform1i( mNumEffectsH[variant], mNumEffects);
|
|
80 |
GLES30.glUniform1i( mNumEffectsH[variant], mNumEffects);
|
|
81 | 81 |
|
82 | 82 |
if( mNumEffects>0 ) |
83 | 83 |
{ |
84 |
GLES31.glUniform1iv( mNameH[variant] , mNumEffects, mName ,0);
|
|
85 |
GLES31.glUniform4fv( mUniformsH[variant],(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0);
|
|
84 |
GLES30.glUniform1iv( mNameH[variant] , mNumEffects, mName ,0);
|
|
85 |
GLES30.glUniform4fv( mUniformsH[variant],(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0);
|
|
86 | 86 |
} |
87 | 87 |
} |
88 | 88 |
} |
src/main/java/org/distorted/library/effectqueue/EffectQueueMatrix.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.library.effectqueue; |
21 | 21 |
|
22 |
import android.opengl.GLES31;
|
|
22 |
import android.opengl.GLES30;
|
|
23 | 23 |
import android.opengl.Matrix; |
24 | 24 |
|
25 | 25 |
import org.distorted.library.effect.EffectType; |
... | ... | |
58 | 58 |
|
59 | 59 |
static void uniforms(int mProgramH, int variant) |
60 | 60 |
{ |
61 |
mBoundingH[variant] = GLES31.glGetUniformLocation(mProgramH, "u_Bounding");
|
|
62 |
mStretchH[variant] = GLES31.glGetUniformLocation(mProgramH, "u_Stretch");
|
|
63 |
mMVPMatrixH[variant]= GLES31.glGetUniformLocation(mProgramH, "u_MVPMatrix");
|
|
64 |
mMVMatrixH[variant] = GLES31.glGetUniformLocation(mProgramH, "u_MVMatrix");
|
|
61 |
mBoundingH[variant] = GLES30.glGetUniformLocation(mProgramH, "u_Bounding");
|
|
62 |
mStretchH[variant] = GLES30.glGetUniformLocation(mProgramH, "u_Stretch");
|
|
63 |
mMVPMatrixH[variant]= GLES30.glGetUniformLocation(mProgramH, "u_MVPMatrix");
|
|
64 |
mMVMatrixH[variant] = GLES30.glGetUniformLocation(mProgramH, "u_MVMatrix");
|
|
65 | 65 |
} |
66 | 66 |
|
67 | 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
164 | 164 |
// combined Model-View-Projection matrix |
165 | 165 |
Matrix.multiplyMM(mMVPMatrix, 0, projection, 0, mModelViewMatrix, 0); |
166 | 166 |
|
167 |
GLES31.glUniform3f( mBoundingH[variant] , mesh.getBoundingX(), mesh.getBoundingY(), mesh.getBoundingZ());
|
|
168 |
GLES31.glUniform3f( mStretchH[variant] , mesh.getStretchX() , mesh.getStretchY() , mesh.getStretchZ() );
|
|
169 |
GLES31.glUniformMatrix4fv(mMVMatrixH[variant] , 1, false, mModelViewMatrix, 0);
|
|
170 |
GLES31.glUniformMatrix4fv(mMVPMatrixH[variant], 1, false, mMVPMatrix , 0);
|
|
167 |
GLES30.glUniform3f( mBoundingH[variant] , mesh.getBoundingX(), mesh.getBoundingY(), mesh.getBoundingZ());
|
|
168 |
GLES30.glUniform3f( mStretchH[variant] , mesh.getStretchX() , mesh.getStretchY() , mesh.getStretchZ() );
|
|
169 |
GLES30.glUniformMatrix4fv(mMVMatrixH[variant] , 1, false, mModelViewMatrix, 0);
|
|
170 |
GLES30.glUniformMatrix4fv(mMVPMatrixH[variant], 1, false, mMVPMatrix , 0);
|
|
171 | 171 |
} |
172 | 172 |
} |
src/main/java/org/distorted/library/effectqueue/EffectQueuePostprocess.java | ||
---|---|---|
20 | 20 |
package org.distorted.library.effectqueue; |
21 | 21 |
|
22 | 22 |
import android.content.res.Resources; |
23 |
import android.opengl.GLES31;
|
|
23 |
import android.opengl.GLES30;
|
|
24 | 24 |
import android.util.Log; |
25 | 25 |
|
26 | 26 |
import org.distorted.library.R; |
... | ... | |
108 | 108 |
|
109 | 109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
110 | 110 |
|
111 |
public static void createPrograms(Resources resources) |
|
111 |
public static void createPrograms(Resources resources, int GLSL)
|
|
112 | 112 |
{ |
113 | 113 |
final InputStream mainVertStream = resources.openRawResource(R.raw.main_vertex_shader); |
114 | 114 |
final InputStream mainFragStream = resources.openRawResource(R.raw.preprocess_fragment_shader); |
115 | 115 |
|
116 | 116 |
int numV = VertexEffect.getNumEnabled(); |
117 | 117 |
|
118 |
String mainVertHeader= DistortedLibrary.GLSL_VERSION + ("#define NUM_VERTEX " + ( numV>0 ? DistortedLibrary.getMax(EffectType.VERTEX ) : 0 ) + "\n"); |
|
119 |
String mainFragHeader= DistortedLibrary.GLSL_VERSION + "\n"; |
|
118 |
String version = "#version "+GLSL+" es\n"; |
|
119 |
String mainVertHeader= version + ("#define NUM_VERTEX " + ( numV>0 ? DistortedLibrary.getMax(EffectType.VERTEX ) : 0 ) + "\n"); |
|
120 |
String mainFragHeader= version + "\n"; |
|
120 | 121 |
|
121 | 122 |
String enabledEffectV= VertexEffect.getGLSL(); |
122 | 123 |
|
123 | 124 |
try |
124 | 125 |
{ |
125 | 126 |
mPreProgram = new DistortedProgram(mainVertStream, mainFragStream, mainVertHeader, mainFragHeader, |
126 |
enabledEffectV, null, DistortedLibrary.GLSL, null);
|
|
127 |
enabledEffectV, null, GLSL, null); |
|
127 | 128 |
} |
128 | 129 |
catch(Exception e) |
129 | 130 |
{ |
... | ... | |
134 | 135 |
int preProgramH = mPreProgram.getProgramHandle(); |
135 | 136 |
EffectQueueVertex.getUniforms( preProgramH,2 ); |
136 | 137 |
EffectQueueMatrix.getUniforms( preProgramH,2 ); |
137 |
mPreColorH = GLES31.glGetUniformLocation( preProgramH, "u_Color" );
|
|
138 |
mPreTextureH= GLES31.glGetUniformLocation( preProgramH, "u_Texture");
|
|
138 |
mPreColorH = GLES30.glGetUniformLocation( preProgramH, "u_Color" );
|
|
139 |
mPreTextureH= GLES30.glGetUniformLocation( preProgramH, "u_Texture");
|
|
139 | 140 |
} |
140 | 141 |
|
141 | 142 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
167 | 168 |
InternalRenderState.setUpStencilMark(mA!=0.0f); |
168 | 169 |
InternalRenderState.disableBlending(); |
169 | 170 |
|
170 |
GLES31.glViewport(0, 0, width, height );
|
|
171 |
GLES30.glViewport(0, 0, width, height );
|
|
171 | 172 |
|
172 | 173 |
mPreProgram.useProgram(); |
173 | 174 |
|
... | ... | |
190 | 191 |
|
191 | 192 |
if( mA!=0.0f ) |
192 | 193 |
{ |
193 |
GLES31.glUniform4f(mPreColorH, mR, mG, mB, mA);
|
|
194 |
GLES31.glUniform1i(mPreTextureH, 0);
|
|
194 |
GLES30.glUniform4f(mPreColorH, mR, mG, mB, mA);
|
|
195 |
GLES30.glUniform1i(mPreTextureH, 0);
|
|
195 | 196 |
} |
196 | 197 |
|
197 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() );
|
|
198 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() );
|
|
198 | 199 |
|
199 | 200 |
InternalRenderState.restoreBlending(); |
200 | 201 |
InternalRenderState.unsetUpStencilMark(); |
... | ... | |
208 | 209 |
{ |
209 | 210 |
int numRenders = 0; |
210 | 211 |
|
211 |
GLES31.glDisable(GLES31.GL_BLEND);
|
|
212 |
GLES30.glDisable(GLES30.GL_BLEND);
|
|
212 | 213 |
|
213 | 214 |
for(int i=0; i<mNumEffects; i++) |
214 | 215 |
{ |
215 | 216 |
numRenders += ((PostprocessEffect)mEffects[i]).apply(mUniforms,NUM_UNIFORMS*i, buffer); |
216 | 217 |
} |
217 | 218 |
|
218 |
GLES31.glEnable(GLES31.GL_BLEND);
|
|
219 |
GLES30.glEnable(GLES30.GL_BLEND);
|
|
219 | 220 |
|
220 | 221 |
return numRenders; |
221 | 222 |
} |
src/main/java/org/distorted/library/effectqueue/EffectQueueVertex.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.library.effectqueue; |
21 | 21 |
|
22 |
import android.opengl.GLES31;
|
|
22 |
import android.opengl.GLES30;
|
|
23 | 23 |
|
24 | 24 |
import org.distorted.library.effect.EffectType; |
25 | 25 |
import org.distorted.library.effect.VertexEffect; |
... | ... | |
48 | 48 |
|
49 | 49 |
static void uniforms(int mProgramH, int variant) |
50 | 50 |
{ |
51 |
mNumEffectsH[variant]= GLES31.glGetUniformLocation( mProgramH, "vNumEffects");
|
|
52 |
mNameH[variant] = GLES31.glGetUniformLocation( mProgramH, "vName");
|
|
53 |
mUniformsH[variant] = GLES31.glGetUniformLocation( mProgramH, "vUniforms");
|
|
54 |
mInflateH[variant] = GLES31.glGetUniformLocation( mProgramH, "u_Inflate");
|
|
51 |
mNumEffectsH[variant]= GLES30.glGetUniformLocation( mProgramH, "vNumEffects");
|
|
52 |
mNameH[variant] = GLES30.glGetUniformLocation( mProgramH, "vName");
|
|
53 |
mUniformsH[variant] = GLES30.glGetUniformLocation( mProgramH, "vUniforms");
|
|
54 |
mInflateH[variant] = GLES30.glGetUniformLocation( mProgramH, "u_Inflate");
|
|
55 | 55 |
} |
56 | 56 |
|
57 | 57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
79 | 79 |
|
80 | 80 |
void send(float inflate, int variant) |
81 | 81 |
{ |
82 |
GLES31.glUniform1i( mNumEffectsH[variant], mNumEffects);
|
|
83 |
GLES31.glUniform1f( mInflateH[variant] , inflate );
|
|
82 |
GLES30.glUniform1i( mNumEffectsH[variant], mNumEffects);
|
|
83 |
GLES30.glUniform1f( mInflateH[variant] , inflate );
|
|
84 | 84 |
|
85 | 85 |
if( mNumEffects>0 ) |
86 | 86 |
{ |
87 |
GLES31.glUniform1iv( mNameH[variant] , mNumEffects, mName ,0);
|
|
88 |
GLES31.glUniform4fv( mUniformsH[variant],(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0);
|
|
87 |
GLES30.glUniform1iv( mNameH[variant] , mNumEffects, mName ,0);
|
|
88 |
GLES30.glUniform4fv( mUniformsH[variant],(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0);
|
|
89 | 89 |
} |
90 | 90 |
} |
91 | 91 |
} |
src/main/java/org/distorted/library/main/DistortedFramebuffer.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.library.main; |
21 | 21 |
|
22 |
import android.opengl.GLES31; |
|
22 |
import android.opengl.GLES30; |
|
23 |
import android.util.Log; |
|
23 | 24 |
|
24 | 25 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
25 | 26 |
/** |
... | ... | |
41 | 42 |
|
42 | 43 |
if( mColorCreated==NOT_CREATED_YET ) |
43 | 44 |
{ |
44 |
GLES31.glGenTextures( mNumFBOs*mNumColors, mColorH, 0);
|
|
45 |
GLES31.glGenFramebuffers(mNumFBOs, mFBOH, 0);
|
|
45 |
GLES30.glGenTextures( mNumFBOs*mNumColors, mColorH, 0);
|
|
46 |
GLES30.glGenFramebuffers(mNumFBOs, mFBOH, 0);
|
|
46 | 47 |
|
47 | 48 |
for(int i=0; i<mNumFBOs; i++) |
48 | 49 |
{ |
49 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[i]);
|
|
50 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[i]);
|
|
50 | 51 |
|
51 | 52 |
for(int j=0; j<mNumColors; j++) |
52 | 53 |
{ |
53 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mColorH[i*mNumColors+j]);
|
|
54 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_WRAP_S, GLES31.GL_REPEAT);
|
|
55 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_WRAP_T, GLES31.GL_REPEAT);
|
|
56 |
GLES31.glTexParameterf(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MIN_FILTER, GLES31.GL_NEAREST);
|
|
57 |
GLES31.glTexParameterf(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MAG_FILTER, GLES31.GL_LINEAR);
|
|
58 |
GLES31.glTexImage2D(GLES31.GL_TEXTURE_2D, 0, GLES31.GL_RGBA, mRealWidth, mRealHeight, 0, GLES31.GL_RGBA, GLES31.GL_UNSIGNED_BYTE, null);
|
|
54 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[i*mNumColors+j]);
|
|
55 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_REPEAT);
|
|
56 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_REPEAT);
|
|
57 |
GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_NEAREST);
|
|
58 |
GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR);
|
|
59 |
GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_RGBA, mRealWidth, mRealHeight, 0, GLES30.GL_RGBA, GLES30.GL_UNSIGNED_BYTE, null);
|
|
59 | 60 |
} |
60 | 61 |
|
61 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, mColorH[i*mNumColors], 0);
|
|
62 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, 0);
|
|
62 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, mColorH[i*mNumColors], 0);
|
|
63 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
|
|
63 | 64 |
} |
64 | 65 |
|
65 | 66 |
// TODO |
66 | 67 |
mColorCreated = checkStatus("color"); |
67 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0);
|
|
68 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0);
|
|
68 | 69 |
} |
69 | 70 |
|
70 | 71 |
////////////////////////////////////////////////////////////// |
... | ... | |
72 | 73 |
|
73 | 74 |
if( mDepthStencilCreated==NOT_CREATED_YET ) // we need to create a new DEPTH or STENCIL attachment |
74 | 75 |
{ |
75 |
GLES31.glGenTextures(mNumFBOs, mDepthStencilH, 0);
|
|
76 |
GLES30.glGenTextures(mNumFBOs, mDepthStencilH, 0);
|
|
76 | 77 |
|
77 | 78 |
for(int i=0; i<mNumFBOs; i++) |
78 | 79 |
{ |
79 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mDepthStencilH[i]);
|
|
80 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_WRAP_S, GLES31.GL_REPEAT);
|
|
81 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_WRAP_T, GLES31.GL_REPEAT);
|
|
82 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MIN_FILTER, GLES31.GL_NEAREST);
|
|
83 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MAG_FILTER, GLES31.GL_NEAREST);
|
|
80 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mDepthStencilH[i]);
|
|
81 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_REPEAT);
|
|
82 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_REPEAT);
|
|
83 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_NEAREST);
|
|
84 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_NEAREST);
|
|
84 | 85 |
|
85 | 86 |
if (mDepthStencil == DEPTH_NO_STENCIL) |
86 | 87 |
{ |
87 |
GLES31.glTexImage2D(GLES31.GL_TEXTURE_2D, 0, GLES31.GL_DEPTH_COMPONENT, mRealWidth, mRealHeight, 0, GLES31.GL_DEPTH_COMPONENT, GLES31.GL_UNSIGNED_INT, null);
|
|
88 |
GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_DEPTH_COMPONENT, mRealWidth, mRealHeight, 0, GLES30.GL_DEPTH_COMPONENT, GLES30.GL_UNSIGNED_INT, null);
|
|
88 | 89 |
} |
89 | 90 |
else if (mDepthStencil == BOTH_DEPTH_STENCIL) |
90 | 91 |
{ |
91 |
GLES31.glTexImage2D(GLES31.GL_TEXTURE_2D, 0, GLES31.GL_DEPTH24_STENCIL8, mRealWidth, mRealHeight, 0, GLES31.GL_DEPTH_STENCIL, GLES31.GL_UNSIGNED_INT_24_8, null);
|
|
92 |
GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_DEPTH24_STENCIL8, mRealWidth, mRealHeight, 0, GLES30.GL_DEPTH_STENCIL, GLES30.GL_UNSIGNED_INT_24_8, null);
|
|
92 | 93 |
} |
93 | 94 |
} |
94 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, 0);
|
|
95 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
|
|
95 | 96 |
|
96 | 97 |
for(int i=0; i<mNumFBOs; i++) |
97 | 98 |
{ |
98 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[i]);
|
|
99 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[i]);
|
|
99 | 100 |
|
100 | 101 |
if (mDepthStencil == DEPTH_NO_STENCIL) |
101 | 102 |
{ |
102 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_DEPTH_ATTACHMENT, GLES31.GL_TEXTURE_2D, mDepthStencilH[i], 0);
|
|
103 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_ATTACHMENT, GLES30.GL_TEXTURE_2D, mDepthStencilH[i], 0);
|
|
103 | 104 |
} |
104 | 105 |
else if (mDepthStencil == BOTH_DEPTH_STENCIL) |
105 | 106 |
{ |
106 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_DEPTH_STENCIL_ATTACHMENT, GLES31.GL_TEXTURE_2D, mDepthStencilH[i], 0);
|
|
107 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_STENCIL_ATTACHMENT, GLES30.GL_TEXTURE_2D, mDepthStencilH[i], 0);
|
|
107 | 108 |
} |
108 | 109 |
} |
109 | 110 |
|
110 | 111 |
// TODO |
111 | 112 |
mDepthStencilCreated = checkStatus("depth"); |
112 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0);
|
|
113 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0);
|
|
113 | 114 |
} |
114 | 115 |
|
115 | 116 |
////////////////////////////////////////////////////////////// |
... | ... | |
124 | 125 |
|
125 | 126 |
for(int i=0; i<mNumFBOs; i++) |
126 | 127 |
{ |
127 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[i]);
|
|
128 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_DEPTH_ATTACHMENT, GLES31.GL_TEXTURE_2D, 0, 0);
|
|
129 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_DEPTH_STENCIL_ATTACHMENT, GLES31.GL_TEXTURE_2D, 0, 0);
|
|
128 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[i]);
|
|
129 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_ATTACHMENT, GLES30.GL_TEXTURE_2D, 0, 0);
|
|
130 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_STENCIL_ATTACHMENT, GLES30.GL_TEXTURE_2D, 0, 0);
|
|
130 | 131 |
mDepthStencilH[i]=0; |
131 | 132 |
} |
132 | 133 |
|
133 |
GLES31.glDeleteTextures(mNumFBOs, mDepthStencilH, 0);
|
|
134 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0);
|
|
134 |
GLES30.glDeleteTextures(mNumFBOs, mDepthStencilH, 0);
|
|
135 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0);
|
|
135 | 136 |
} |
136 | 137 |
} |
137 | 138 |
|
... | ... | |
140 | 141 |
|
141 | 142 |
private int checkStatus(String message) |
142 | 143 |
{ |
143 |
int status = GLES31.glCheckFramebufferStatus(GLES31.GL_FRAMEBUFFER);
|
|
144 |
int status = GLES30.glCheckFramebufferStatus(GLES30.GL_FRAMEBUFFER);
|
|
144 | 145 |
|
145 |
if(status != GLES31.GL_FRAMEBUFFER_COMPLETE)
|
|
146 |
if(status != GLES30.GL_FRAMEBUFFER_COMPLETE)
|
|
146 | 147 |
{ |
147 |
android.util.Log.e("DistortedFramebuffer", "FRAMEBUFFER INCOMPLETE, "+message+" error="+status);
|
|
148 |
Log.e("DistortedFramebuffer", "FRAMEBUFFER INCOMPLETE, "+message+" error="+status); |
|
148 | 149 |
|
149 |
GLES31.glDeleteTextures(1, mColorH, 0);
|
|
150 |
GLES31.glDeleteTextures(1, mDepthStencilH, 0);
|
|
151 |
GLES31.glDeleteFramebuffers(1, mFBOH, 0);
|
|
150 |
GLES30.glDeleteTextures(1, mColorH, 0);
|
|
151 |
GLES30.glDeleteTextures(1, mDepthStencilH, 0);
|
|
152 |
GLES30.glDeleteFramebuffers(1, mFBOH, 0);
|
|
152 | 153 |
mFBOH[0]= 0; |
153 | 154 |
|
154 | 155 |
return FAILED_TO_CREATE; |
... | ... | |
164 | 165 |
{ |
165 | 166 |
if( mColorH[0]>0 ) |
166 | 167 |
{ |
167 |
GLES31.glDeleteTextures(mNumFBOs*mNumColors, mColorH, 0);
|
|
168 |
GLES30.glDeleteTextures(mNumFBOs*mNumColors, mColorH, 0);
|
|
168 | 169 |
mColorCreated = NOT_CREATED_YET; |
169 | 170 |
|
170 | 171 |
for(int i=0; i<mNumFBOs*mNumColors; i++) mColorH[i] = 0; |
... | ... | |
172 | 173 |
|
173 | 174 |
if( mDepthStencilH[0]>0 ) |
174 | 175 |
{ |
175 |
GLES31.glDeleteTextures(mNumFBOs, mDepthStencilH, 0);
|
|
176 |
GLES30.glDeleteTextures(mNumFBOs, mDepthStencilH, 0);
|
|
176 | 177 |
mDepthStencilCreated = NOT_CREATED_YET; |
177 | 178 |
|
178 | 179 |
for(int i=0; i<mNumFBOs; i++) mDepthStencilH[i] = 0; |
179 | 180 |
} |
180 | 181 |
|
181 |
GLES31.glDeleteFramebuffers(mNumFBOs, mFBOH, 0);
|
|
182 |
GLES30.glDeleteFramebuffers(mNumFBOs, mFBOH, 0);
|
|
182 | 183 |
for(int i=0; i<mNumFBOs; i++) mFBOH[i] = 0; |
183 | 184 |
} |
184 | 185 |
|
... | ... | |
205 | 206 |
{ |
206 | 207 |
if( texture>=0 && texture<mNumColors && fbo>=0 && fbo<mNumFBOs && mColorH[mNumColors*fbo + texture]>0 ) |
207 | 208 |
{ |
208 |
GLES31.glActiveTexture(GLES31.GL_TEXTURE0);
|
|
209 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mColorH[mNumColors*fbo + texture]);
|
|
209 |
GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
|
|
210 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[mNumColors*fbo + texture]);
|
|
210 | 211 |
return true; |
211 | 212 |
} |
212 | 213 |
|
... | ... | |
262 | 263 |
{ |
263 | 264 |
if( texture>=0 && texture<mNumColors && mColorH[texture]>0 ) |
264 | 265 |
{ |
265 |
GLES31.glActiveTexture(GLES31.GL_TEXTURE0);
|
|
266 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mColorH[2*mCurrFBO+texture]);
|
|
266 |
GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
|
|
267 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[2*mCurrFBO+texture]);
|
|
267 | 268 |
return true; |
268 | 269 |
} |
269 | 270 |
|
... | ... | |
280 | 281 |
{ |
281 | 282 |
if( texture>=0 && texture<mNumColors && mColorH[texture]>0 ) |
282 | 283 |
{ |
283 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, mColorH[2*mCurrFBO+texture], 0);
|
|
284 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, mColorH[2*mCurrFBO+texture], 0);
|
|
284 | 285 |
} |
285 | 286 |
} |
286 | 287 |
|
src/main/java/org/distorted/library/main/DistortedLibrary.java | ||
---|---|---|
23 | 23 |
import android.content.Context; |
24 | 24 |
import android.content.pm.ConfigurationInfo; |
25 | 25 |
import android.content.res.Resources; |
26 |
import android.opengl.GLES30; |
|
26 | 27 |
import android.opengl.GLES31; |
27 | 28 |
import android.util.Log; |
28 | 29 |
|
... | ... | |
37 | 38 |
import org.distorted.library.mesh.MeshBase; |
38 | 39 |
import org.distorted.library.message.EffectMessageSender; |
39 | 40 |
import org.distorted.library.program.DistortedProgram; |
41 |
import org.distorted.library.program.VertexCompilationException; |
|
40 | 42 |
|
41 | 43 |
import java.io.InputStream; |
42 | 44 |
import java.nio.ByteBuffer; |
... | ... | |
50 | 52 |
*/ |
51 | 53 |
public class DistortedLibrary |
52 | 54 |
{ |
53 |
public static final int GLSL = 310; |
|
54 |
public static final String GLSL_VERSION= "#version 310 es\n"; |
|
55 |
private static int mGLSL; |
|
56 |
private static String mGLSL_VERSION; |
|
57 |
private static boolean mOITCompilationSuccessful; |
|
55 | 58 |
/** |
56 | 59 |
* When creating an instance of a DistortedTexture from another instance, clone the Bitmap that's |
57 | 60 |
* backing up our DistortedTexture. |
... | ... | |
207 | 210 |
int numF = FragmentEffect.getNumEnabled(); |
208 | 211 |
int numV = VertexEffect.getNumEnabled(); |
209 | 212 |
|
210 |
String mainVertHeader= DistortedLibrary.GLSL_VERSION + ("#define NUM_VERTEX " + ( numV>0 ? getMax(EffectType.VERTEX ) : 0 ) + "\n");
|
|
211 |
String mainFragHeader= DistortedLibrary.GLSL_VERSION + ("#define NUM_FRAGMENT " + ( numF>0 ? getMax(EffectType.FRAGMENT) : 0 ) + "\n");
|
|
213 |
String mainVertHeader= mGLSL_VERSION + ("#define NUM_VERTEX " + ( numV>0 ? getMax(EffectType.VERTEX ) : 0 ) + "\n");
|
|
214 |
String mainFragHeader= mGLSL_VERSION + ("#define NUM_FRAGMENT " + ( numF>0 ? getMax(EffectType.FRAGMENT) : 0 ) + "\n");
|
|
212 | 215 |
String enabledEffectV= VertexEffect.getGLSL(); |
213 | 216 |
String enabledEffectF= FragmentEffect.getGLSL(); |
214 | 217 |
|
... | ... | |
217 | 220 |
try |
218 | 221 |
{ |
219 | 222 |
mMainProgram = new DistortedProgram(mainVertStream, mainFragStream, mainVertHeader, mainFragHeader, |
220 |
enabledEffectV, enabledEffectF, DistortedLibrary.GLSL, feedback);
|
|
223 |
enabledEffectV, enabledEffectF, mGLSL, feedback);
|
|
221 | 224 |
} |
222 | 225 |
catch(Exception e) |
223 | 226 |
{ |
... | ... | |
227 | 230 |
|
228 | 231 |
int mainProgramH = mMainProgram.getProgramHandle(); |
229 | 232 |
EffectQueue.getUniforms(mainProgramH,0); |
230 |
mMainTextureH= GLES31.glGetUniformLocation( mainProgramH, "u_Texture");
|
|
233 |
mMainTextureH= GLES30.glGetUniformLocation( mainProgramH, "u_Texture");
|
|
231 | 234 |
|
232 | 235 |
// BLIT PROGRAM //////////////////////////////////// |
233 | 236 |
final InputStream blitVertStream = resources.openRawResource(R.raw.blit_vertex_shader); |
... | ... | |
235 | 238 |
|
236 | 239 |
try |
237 | 240 |
{ |
238 |
mBlitProgram = new DistortedProgram(blitVertStream,blitFragStream, DistortedLibrary.GLSL_VERSION, DistortedLibrary.GLSL_VERSION, DistortedLibrary.GLSL);
|
|
241 |
mBlitProgram = new DistortedProgram(blitVertStream,blitFragStream, mGLSL_VERSION, mGLSL_VERSION, mGLSL);
|
|
239 | 242 |
} |
240 | 243 |
catch(Exception e) |
241 | 244 |
{ |
... | ... | |
244 | 247 |
} |
245 | 248 |
|
246 | 249 |
int blitProgramH = mBlitProgram.getProgramHandle(); |
247 |
mBlitTextureH = GLES31.glGetUniformLocation( blitProgramH, "u_Texture");
|
|
248 |
mBlitDepthH = GLES31.glGetUniformLocation( blitProgramH, "u_Depth");
|
|
250 |
mBlitTextureH = GLES30.glGetUniformLocation( blitProgramH, "u_Texture");
|
|
251 |
mBlitDepthH = GLES30.glGetUniformLocation( blitProgramH, "u_Depth");
|
|
249 | 252 |
|
250 | 253 |
// BLIT DEPTH PROGRAM //////////////////////////////////// |
251 | 254 |
final InputStream blitDepthVertStream = resources.openRawResource(R.raw.blit_depth_vertex_shader); |
... | ... | |
253 | 256 |
|
254 | 257 |
try |
255 | 258 |
{ |
256 |
mBlitDepthProgram = new DistortedProgram(blitDepthVertStream,blitDepthFragStream, DistortedLibrary.GLSL_VERSION, DistortedLibrary.GLSL_VERSION, DistortedLibrary.GLSL);
|
|
259 |
mBlitDepthProgram = new DistortedProgram(blitDepthVertStream,blitDepthFragStream, mGLSL_VERSION, mGLSL_VERSION, mGLSL);
|
|
257 | 260 |
} |
258 | 261 |
catch(Exception e) |
259 | 262 |
{ |
... | ... | |
262 | 265 |
} |
263 | 266 |
|
264 | 267 |
int blitDepthProgramH = mBlitDepthProgram.getProgramHandle(); |
265 |
mBlitDepthTextureH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_Texture");
|
|
266 |
mBlitDepthDepthTextureH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_DepthTexture");
|
|
267 |
mBlitDepthDepthH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_Depth");
|
|
268 |
mBlitDepthTexCorrH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_TexCorr");
|
|
268 |
mBlitDepthTextureH = GLES30.glGetUniformLocation( blitDepthProgramH, "u_Texture");
|
|
269 |
mBlitDepthDepthTextureH = GLES30.glGetUniformLocation( blitDepthProgramH, "u_DepthTexture");
|
|
270 |
mBlitDepthDepthH = GLES30.glGetUniformLocation( blitDepthProgramH, "u_Depth");
|
|
271 |
mBlitDepthTexCorrH = GLES30.glGetUniformLocation( blitDepthProgramH, "u_TexCorr");
|
|
269 | 272 |
|
270 | 273 |
// NORMAL PROGRAM ////////////////////////////////////// |
271 | 274 |
final InputStream normalVertexStream = resources.openRawResource(R.raw.normal_vertex_shader); |
... | ... | |
273 | 276 |
|
274 | 277 |
try |
275 | 278 |
{ |
276 |
mNormalProgram = new DistortedProgram(normalVertexStream,normalFragmentStream, DistortedLibrary.GLSL_VERSION, DistortedLibrary.GLSL_VERSION, DistortedLibrary.GLSL);
|
|
279 |
mNormalProgram = new DistortedProgram(normalVertexStream,normalFragmentStream, mGLSL_VERSION, mGLSL_VERSION, mGLSL);
|
|
277 | 280 |
} |
278 | 281 |
catch(Exception e) |
279 | 282 |
{ |
... | ... | |
282 | 285 |
} |
283 | 286 |
|
284 | 287 |
int normalProgramH = mNormalProgram.getProgramHandle(); |
285 |
mNormalMVPMatrixH = GLES31.glGetUniformLocation( normalProgramH, "u_MVPMatrix");
|
|
288 |
mNormalMVPMatrixH = GLES30.glGetUniformLocation( normalProgramH, "u_MVPMatrix");
|
|
286 | 289 |
} |
287 | 290 |
|
288 | 291 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
296 | 299 |
int numF = FragmentEffect.getNumEnabled(); |
297 | 300 |
int numV = VertexEffect.getNumEnabled(); |
298 | 301 |
|
299 |
String mainVertHeader= DistortedLibrary.GLSL_VERSION + |
|
300 |
("#define NUM_VERTEX " + ( numV>0 ? getMax(EffectType.VERTEX ) : 0 ) + "\n") + |
|
301 |
("#define OIT\n"); |
|
302 |
String mainFragHeader= DistortedLibrary.GLSL_VERSION + |
|
303 |
("#define NUM_FRAGMENT " + ( numF>0 ? getMax(EffectType.FRAGMENT) : 0 ) + "\n") + |
|
304 |
("#define OIT\n"); |
|
302 |
String mainVertHeader= mGLSL_VERSION + ("#define NUM_VERTEX " + ( numV>0 ? getMax(EffectType.VERTEX ) : 0 ) + "\n") + ("#define OIT\n"); |
|
303 |
String mainFragHeader= mGLSL_VERSION + ("#define NUM_FRAGMENT " + ( numF>0 ? getMax(EffectType.FRAGMENT) : 0 ) + "\n") + ("#define OIT\n"); |
|
305 | 304 |
|
306 | 305 |
String enabledEffectV= VertexEffect.getGLSL(); |
307 | 306 |
String enabledEffectF= FragmentEffect.getGLSL(); |
... | ... | |
309 | 308 |
try |
310 | 309 |
{ |
311 | 310 |
mMainOITProgram = new DistortedProgram(mainVertStream, mainFragStream, mainVertHeader, mainFragHeader, |
312 |
enabledEffectV, enabledEffectF, DistortedLibrary.GLSL, null);
|
|
311 |
enabledEffectV, enabledEffectF, mGLSL, null);
|
|
313 | 312 |
} |
314 | 313 |
catch(Exception e) |
315 | 314 |
{ |
... | ... | |
319 | 318 |
|
320 | 319 |
int mainOITProgramH = mMainOITProgram.getProgramHandle(); |
321 | 320 |
EffectQueue.getUniforms(mainOITProgramH,1); |
322 |
mMainOITTextureH = GLES31.glGetUniformLocation( mainOITProgramH, "u_Texture");
|
|
323 |
mMainOITSizeH = GLES31.glGetUniformLocation( mainOITProgramH, "u_Size");
|
|
324 |
mMainOITNumRecordsH = GLES31.glGetUniformLocation( mainOITProgramH, "u_numRecords");
|
|
321 |
mMainOITTextureH = GLES30.glGetUniformLocation( mainOITProgramH, "u_Texture");
|
|
322 |
mMainOITSizeH = GLES30.glGetUniformLocation( mainOITProgramH, "u_Size");
|
|
323 |
mMainOITNumRecordsH = GLES30.glGetUniformLocation( mainOITProgramH, "u_numRecords");
|
|
325 | 324 |
|
326 | 325 |
// OIT CLEAR PROGRAM //////////////////////////////////// |
327 | 326 |
final InputStream oitClearVertStream = resources.openRawResource(R.raw.oit_vertex_shader); |
... | ... | |
329 | 328 |
|
330 | 329 |
try |
331 | 330 |
{ |
332 |
mOITClearProgram = new DistortedProgram(oitClearVertStream,oitClearFragStream, DistortedLibrary.GLSL_VERSION, DistortedLibrary.GLSL_VERSION, DistortedLibrary.GLSL);
|
|
331 |
mOITClearProgram = new DistortedProgram(oitClearVertStream,oitClearFragStream, mGLSL_VERSION, mGLSL_VERSION, mGLSL);
|
|
333 | 332 |
} |
334 | 333 |
catch(Exception e) |
335 | 334 |
{ |
... | ... | |
338 | 337 |
} |
339 | 338 |
|
340 | 339 |
int oitClearProgramH = mOITClearProgram.getProgramHandle(); |
341 |
mOITClearDepthH = GLES31.glGetUniformLocation( oitClearProgramH, "u_Depth");
|
|
342 |
mOITClearTexCorrH = GLES31.glGetUniformLocation( oitClearProgramH, "u_TexCorr");
|
|
343 |
mOITClearSizeH = GLES31.glGetUniformLocation( oitClearProgramH, "u_Size");
|
|
340 |
mOITClearDepthH = GLES30.glGetUniformLocation( oitClearProgramH, "u_Depth");
|
|
341 |
mOITClearTexCorrH = GLES30.glGetUniformLocation( oitClearProgramH, "u_TexCorr");
|
|
342 |
mOITClearSizeH = GLES30.glGetUniformLocation( oitClearProgramH, "u_Size");
|
|
344 | 343 |
|
345 | 344 |
// OIT BUILD PROGRAM //////////////////////////////////// |
346 | 345 |
final InputStream oitBuildVertStream = resources.openRawResource(R.raw.oit_vertex_shader); |
... | ... | |
348 | 347 |
|
349 | 348 |
try |
350 | 349 |
{ |
351 |
mOITBuildProgram = new DistortedProgram(oitBuildVertStream,oitBuildFragStream, DistortedLibrary.GLSL_VERSION, DistortedLibrary.GLSL_VERSION, DistortedLibrary.GLSL);
|
|
350 |
mOITBuildProgram = new DistortedProgram(oitBuildVertStream,oitBuildFragStream, mGLSL_VERSION, mGLSL_VERSION, mGLSL);
|
|
352 | 351 |
} |
353 | 352 |
catch(Exception e) |
354 | 353 |
{ |
... | ... | |
357 | 356 |
} |
358 | 357 |
|
359 | 358 |
int oitBuildProgramH = mOITBuildProgram.getProgramHandle(); |
360 |
mOITBuildTextureH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_Texture");
|
|
361 |
mOITBuildDepthTextureH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_DepthTexture");
|
|
362 |
mOITBuildDepthH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_Depth");
|
|
363 |
mOITBuildTexCorrH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_TexCorr");
|
|
364 |
mOITBuildSizeH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_Size");
|
|
365 |
mOITBuildNumRecordsH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_numRecords");
|
|
359 |
mOITBuildTextureH = GLES30.glGetUniformLocation( oitBuildProgramH, "u_Texture");
|
|
360 |
mOITBuildDepthTextureH = GLES30.glGetUniformLocation( oitBuildProgramH, "u_DepthTexture");
|
|
361 |
mOITBuildDepthH = GLES30.glGetUniformLocation( oitBuildProgramH, "u_Depth");
|
|
362 |
mOITBuildTexCorrH = GLES30.glGetUniformLocation( oitBuildProgramH, "u_TexCorr");
|
|
363 |
mOITBuildSizeH = GLES30.glGetUniformLocation( oitBuildProgramH, "u_Size");
|
|
364 |
mOITBuildNumRecordsH = GLES30.glGetUniformLocation( oitBuildProgramH, "u_numRecords");
|
|
366 | 365 |
|
367 | 366 |
// OIT COLLAPSE PROGRAM /////////////////////////// |
368 | 367 |
final InputStream oitCollapseVertStream = resources.openRawResource(R.raw.oit_vertex_shader); |
... | ... | |
370 | 369 |
|
371 | 370 |
try |
372 | 371 |
{ |
373 |
mOITCollapseProgram = new DistortedProgram(oitCollapseVertStream,oitCollapseFragStream, DistortedLibrary.GLSL_VERSION, DistortedLibrary.GLSL_VERSION, DistortedLibrary.GLSL);
|
|
372 |
mOITCollapseProgram = new DistortedProgram(oitCollapseVertStream,oitCollapseFragStream, mGLSL_VERSION, mGLSL_VERSION, mGLSL);
|
|
374 | 373 |
} |
375 | 374 |
catch(Exception e) |
376 | 375 |
{ |
... | ... | |
379 | 378 |
} |
380 | 379 |
|
381 | 380 |
int oitCollapseProgramH = mOITCollapseProgram.getProgramHandle(); |
382 |
mOITCollapseDepthTextureH = GLES31.glGetUniformLocation( oitCollapseProgramH, "u_DepthTexture");
|
|
383 |
mOITCollapseDepthH = GLES31.glGetUniformLocation( oitCollapseProgramH, "u_Depth");
|
|
384 |
mOITCollapseTexCorrH = GLES31.glGetUniformLocation( oitCollapseProgramH, "u_TexCorr");
|
|
385 |
mOITCollapseSizeH = GLES31.glGetUniformLocation( oitCollapseProgramH, "u_Size");
|
|
381 |
mOITCollapseDepthTextureH = GLES30.glGetUniformLocation( oitCollapseProgramH, "u_DepthTexture");
|
|
382 |
mOITCollapseDepthH = GLES30.glGetUniformLocation( oitCollapseProgramH, "u_Depth");
|
|
383 |
mOITCollapseTexCorrH = GLES30.glGetUniformLocation( oitCollapseProgramH, "u_TexCorr");
|
|
384 |
mOITCollapseSizeH = GLES30.glGetUniformLocation( oitCollapseProgramH, "u_Size");
|
|
386 | 385 |
|
387 | 386 |
// OIT RENDER PROGRAM /////////////////////////// |
388 | 387 |
final InputStream oitRenderVertStream = resources.openRawResource(R.raw.oit_vertex_shader); |
... | ... | |
390 | 389 |
|
391 | 390 |
try |
392 | 391 |
{ |
393 |
mOITRenderProgram = new DistortedProgram(oitRenderVertStream,oitRenderFragStream, DistortedLibrary.GLSL_VERSION, DistortedLibrary.GLSL_VERSION, DistortedLibrary.GLSL);
|
|
392 |
mOITRenderProgram = new DistortedProgram(oitRenderVertStream,oitRenderFragStream, mGLSL_VERSION, mGLSL_VERSION, mGLSL);
|
|
394 | 393 |
} |
395 | 394 |
catch(Exception e) |
396 | 395 |
{ |
... | ... | |
399 | 398 |
} |
400 | 399 |
|
401 | 400 |
int oitRenderProgramH = mOITRenderProgram.getProgramHandle(); |
402 |
mOITRenderDepthH = GLES31.glGetUniformLocation( oitRenderProgramH, "u_Depth");
|
|
403 |
mOITRenderTexCorrH = GLES31.glGetUniformLocation( oitRenderProgramH, "u_TexCorr");
|
|
404 |
mOITRenderSizeH = GLES31.glGetUniformLocation( oitRenderProgramH, "u_Size");
|
|
401 |
mOITRenderDepthH = GLES30.glGetUniformLocation( oitRenderProgramH, "u_Depth");
|
|
402 |
mOITRenderTexCorrH = GLES30.glGetUniformLocation( oitRenderProgramH, "u_TexCorr");
|
|
403 |
mOITRenderSizeH = GLES30.glGetUniformLocation( oitRenderProgramH, "u_Size");
|
|
405 | 404 |
} |
406 | 405 |
|
407 | 406 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
411 | 410 |
int num = mesh.getNumVertices(); |
412 | 411 |
int tfo = mesh.getTFO(); |
413 | 412 |
|
414 |
GLES31.glBindBufferBase(GLES31.GL_TRANSFORM_FEEDBACK_BUFFER, 0, tfo );
|
|
415 |
GLES31.glBeginTransformFeedback( GLES31.GL_POINTS);
|
|
413 |
GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, tfo );
|
|
414 |
GLES30.glBeginTransformFeedback( GLES30.GL_POINTS);
|
|
416 | 415 |
InternalRenderState.switchOffDrawing(); |
417 |
GLES31.glDrawArrays( GLES31.GL_POINTS, 0, num );
|
|
416 |
GLES30.glDrawArrays( GLES30.GL_POINTS, 0, num );
|
|
418 | 417 |
InternalRenderState.restoreDrawing(); |
419 |
GLES31.glEndTransformFeedback();
|
|
420 |
GLES31.glBindBufferBase(GLES31.GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);
|
|
418 |
GLES30.glEndTransformFeedback();
|
|
419 |
GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);
|
|
421 | 420 |
|
422 | 421 |
DistortedLibrary.mNormalProgram.useProgram(); |
423 |
GLES31.glUniformMatrix4fv(DistortedLibrary.mNormalMVPMatrixH, 1, false, EffectQueue.getMVP(queues) , 0);
|
|
422 |
GLES30.glUniformMatrix4fv(DistortedLibrary.mNormalMVPMatrixH, 1, false, EffectQueue.getMVP(queues) , 0);
|
|
424 | 423 |
mesh.bindTransformAttribs(DistortedLibrary.mNormalProgram); |
425 |
GLES31.glLineWidth(8.0f);
|
|
426 |
GLES31.glDrawArrays(GLES31.GL_LINES, 0, 2*num);
|
|
424 |
GLES30.glLineWidth(8.0f);
|
|
425 |
GLES30.glDrawArrays(GLES30.GL_LINES, 0, 2*num);
|
|
427 | 426 |
} |
428 | 427 |
|
429 | 428 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
433 | 432 |
EffectQueue[] queues = effects.getQueues(); |
434 | 433 |
|
435 | 434 |
EffectQueue.compute(queues, currTime); |
436 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
|
435 |
GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
|
437 | 436 |
|
438 | 437 |
DistortedLibrary.mMainOITProgram.useProgram(); |
439 |
GLES31.glUniform1i(DistortedLibrary.mMainOITTextureH, 0);
|
|
440 |
GLES31.glUniform2ui(DistortedLibrary.mMainOITSizeH, surface.mWidth, surface.mHeight);
|
|
441 |
GLES31.glUniform1ui(DistortedLibrary.mMainOITNumRecordsH, (int)(DistortedLibrary.mBufferSize*surface.mWidth*surface.mHeight) );
|
|
438 |
GLES30.glUniform1i(DistortedLibrary.mMainOITTextureH, 0);
|
|
439 |
GLES30.glUniform2ui(DistortedLibrary.mMainOITSizeH, surface.mWidth, surface.mHeight);
|
|
440 |
GLES30.glUniform1ui(DistortedLibrary.mMainOITNumRecordsH, (int)(DistortedLibrary.mBufferSize*surface.mWidth*surface.mHeight) );
|
|
442 | 441 |
mesh.bindVertexAttribs(DistortedLibrary.mMainOITProgram); |
443 | 442 |
|
444 | 443 |
float inflate = mesh.getInflate(); |
... | ... | |
447 | 446 |
float[] projection= surface.mProjectionMatrix; |
448 | 447 |
|
449 | 448 |
EffectQueue.send(queues, distance, mipmap, projection, inflate, mesh, 1 ); |
450 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() );
|
|
449 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() );
|
|
451 | 450 |
|
452 | 451 |
if( mesh.getShowNormals() ) |
453 | 452 |
{ |
... | ... | |
464 | 463 |
EffectQueue[] queues = effects.getQueues(); |
465 | 464 |
|
466 | 465 |
EffectQueue.compute(queues, currTime); |
467 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
|
466 |
GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
|
468 | 467 |
|
469 | 468 |
DistortedLibrary.mMainProgram.useProgram(); |
470 |
GLES31.glUniform1i(DistortedLibrary.mMainTextureH, 0);
|
|
469 |
GLES30.glUniform1i(DistortedLibrary.mMainTextureH, 0);
|
|
471 | 470 |
mesh.bindVertexAttribs(DistortedLibrary.mMainProgram); |
472 | 471 |
|
473 | 472 |
float inflate = mesh.getInflate(); |
... | ... | |
476 | 475 |
float[] projection= surface.mProjectionMatrix; |
477 | 476 |
|
478 | 477 |
EffectQueue.send(queues, distance, mipmap, projection, inflate, mesh, 0 ); |
479 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() );
|
|
478 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() );
|
|
480 | 479 |
|
481 | 480 |
if( mesh.getShowNormals() ) displayNormals(queues,mesh); |
482 | 481 |
} |
... | ... | |
487 | 486 |
{ |
488 | 487 |
mBlitProgram.useProgram(); |
489 | 488 |
|
490 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
|
491 |
GLES31.glUniform1i(mBlitTextureH, 0);
|
|
492 |
GLES31.glUniform1f( mBlitDepthH , 1.0f-surface.mNear);
|
|
493 |
GLES31.glVertexAttribPointer(mBlitProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
|
|
494 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
|
|
489 |
GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
|
490 |
GLES30.glUniform1i(mBlitTextureH, 0);
|
|
491 |
GLES30.glUniform1f( mBlitDepthH , 1.0f-surface.mNear);
|
|
492 |
GLES30.glVertexAttribPointer(mBlitProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
|
|
493 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
|
|
495 | 494 |
} |
496 | 495 |
|
497 | 496 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
500 | 499 |
{ |
501 | 500 |
mBlitDepthProgram.useProgram(); |
502 | 501 |
|
503 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
|
504 |
GLES31.glUniform1i(mBlitDepthTextureH, 0);
|
|
505 |
GLES31.glUniform1i(mBlitDepthDepthTextureH, 1);
|
|
506 |
GLES31.glUniform2f(mBlitDepthTexCorrH, corrW, corrH );
|
|
507 |
GLES31.glUniform1f( mBlitDepthDepthH , 1.0f-surface.mNear);
|
|
508 |
GLES31.glVertexAttribPointer(mBlitDepthProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
|
|
509 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
|
|
502 |
GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
|
503 |
GLES30.glUniform1i(mBlitDepthTextureH, 0);
|
|
504 |
GLES30.glUniform1i(mBlitDepthDepthTextureH, 1);
|
|
505 |
GLES30.glUniform2f(mBlitDepthTexCorrH, corrW, corrH );
|
|
506 |
GLES30.glUniform1f( mBlitDepthDepthH , 1.0f-surface.mNear);
|
|
507 |
GLES30.glVertexAttribPointer(mBlitDepthProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
|
|
508 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
|
|
510 | 509 |
} |
511 | 510 |
|
512 | 511 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
512 |
// yes it is safe to be mixing 3.0 and 3.1 like that, senior members of the OpenGL discussions forum assert |
|
513 | 513 |
|
514 | 514 |
private static int printPreviousBuffer() |
515 | 515 |
{ |
516 | 516 |
int counter = 0; |
517 | 517 |
|
518 |
ByteBuffer atomicBuf = (ByteBuffer)GLES31.glMapBufferRange( GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, 4,
|
|
519 |
GLES31.GL_MAP_READ_BIT);
|
|
518 |
ByteBuffer atomicBuf = (ByteBuffer)GLES30.glMapBufferRange( GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, 4,
|
|
519 |
GLES30.GL_MAP_READ_BIT);
|
|
520 | 520 |
if( atomicBuf!=null ) |
521 | 521 |
{ |
522 | 522 |
IntBuffer atomicIntBuf = atomicBuf.order(ByteOrder.nativeOrder()).asIntBuffer(); |
... | ... | |
524 | 524 |
} |
525 | 525 |
else |
526 | 526 |
{ |
527 |
android.util.Log.e("effects", "print: failed to map atomic buffer");
|
|
527 |
Log.e("effects", "print: failed to map atomic buffer"); |
|
528 | 528 |
} |
529 | 529 |
|
530 |
GLES31.glUnmapBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER);
|
|
530 |
GLES30.glUnmapBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER);
|
|
531 | 531 |
|
532 | 532 |
return counter; |
533 | 533 |
} |
... | ... | |
536 | 536 |
|
537 | 537 |
private static void zeroBuffer() |
538 | 538 |
{ |
539 |
ByteBuffer atomicBuf = (ByteBuffer)GLES31.glMapBufferRange( GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, 4,
|
|
540 |
GLES31.GL_MAP_WRITE_BIT|GLES31.GL_MAP_INVALIDATE_BUFFER_BIT);
|
|
539 |
ByteBuffer atomicBuf = (ByteBuffer)GLES30.glMapBufferRange( GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, 4,
|
|
540 |
GLES30.GL_MAP_WRITE_BIT|GLES30.GL_MAP_INVALIDATE_BUFFER_BIT);
|
|
541 | 541 |
if( atomicBuf!=null ) |
542 | 542 |
{ |
543 | 543 |
IntBuffer atomicIntBuf = atomicBuf.order(ByteOrder.nativeOrder()).asIntBuffer(); |
... | ... | |
545 | 545 |
} |
546 | 546 |
else |
547 | 547 |
{ |
548 |
android.util.Log.e("effects", "zero: failed to map atomic buffer");
|
|
548 |
Log.e("effects", "zero: failed to map atomic buffer"); |
|
549 | 549 |
} |
550 | 550 |
|
551 |
GLES31.glUnmapBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER);
|
|
551 |
GLES30.glUnmapBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER);
|
|
552 | 552 |
} |
553 | 553 |
|
554 | 554 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
560 | 560 |
|
561 | 561 |
if( mAtomicCounter[0]<0 ) |
562 | 562 |
{ |
563 |
GLES31.glGenBuffers(DistortedLibrary.FBO_QUEUE_SIZE,mAtomicCounter,0);
|
|
563 |
GLES30.glGenBuffers(DistortedLibrary.FBO_QUEUE_SIZE,mAtomicCounter,0);
|
|
564 | 564 |
|
565 | 565 |
for(int i = 0; i< DistortedLibrary.FBO_QUEUE_SIZE; i++) |
566 | 566 |
{ |
567 |
GLES31.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, mAtomicCounter[i]);
|
|
568 |
GLES31.glBufferData(GLES31.GL_ATOMIC_COUNTER_BUFFER, 4, null, GLES31.GL_DYNAMIC_DRAW);
|
|
567 |
GLES30.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, mAtomicCounter[i]);
|
|
568 |
GLES30.glBufferData(GLES31.GL_ATOMIC_COUNTER_BUFFER, 4, null, GLES30.GL_DYNAMIC_DRAW);
|
|
569 | 569 |
zeroBuffer(); |
570 | 570 |
} |
571 | 571 |
} |
... | ... | |
574 | 574 |
// dialog_about 3%; doing it only once every 5 frames affects speed by less than 1%. |
575 | 575 |
if( mCurrBuffer==0 ) |
576 | 576 |
{ |
577 |
GLES31.glBindBufferBase(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, mAtomicCounter[mCurrBuffer]);
|
|
577 |
GLES30.glBindBufferBase(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, mAtomicCounter[mCurrBuffer]);
|
|
578 | 578 |
counter = printPreviousBuffer(); |
579 | 579 |
} |
580 | 580 |
|
581 | 581 |
if( ++mCurrBuffer>= DistortedLibrary.FBO_QUEUE_SIZE ) mCurrBuffer = 0; |
582 | 582 |
|
583 |
GLES31.glBindBufferBase(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, mAtomicCounter[mCurrBuffer]);
|
|
583 |
GLES30.glBindBufferBase(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, mAtomicCounter[mCurrBuffer]);
|
|
584 | 584 |
zeroBuffer(); |
585 | 585 |
|
586 | 586 |
return counter; |
... | ... | |
593 | 593 |
{ |
594 | 594 |
if( mLinkedListSSBO[0]<0 ) |
595 | 595 |
{ |
596 |
GLES31.glGenBuffers(1,mLinkedListSSBO,0);
|
|
596 |
GLES30.glGenBuffers(1,mLinkedListSSBO,0);
|
|
597 | 597 |
|
598 | 598 |
int size = (int)(surface.mWidth*surface.mHeight*(3*mBufferSize+1)*4); |
599 |
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mLinkedListSSBO[0]);
|
|
600 |
GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, size, null, GLES31.GL_DYNAMIC_READ|GLES31.GL_DYNAMIC_DRAW);
|
|
601 |
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, 0);
|
|
599 |
GLES30.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mLinkedListSSBO[0]);
|
|
600 |
GLES30.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, size, null, GLES30.GL_DYNAMIC_READ|GLES30.GL_DYNAMIC_DRAW);
|
|
601 |
GLES30.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, 0);
|
|
602 | 602 |
|
603 |
GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 1, mLinkedListSSBO[0]);
|
|
603 |
GLES30.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 1, mLinkedListSSBO[0]);
|
|
604 | 604 |
} |
605 | 605 |
|
606 | 606 |
// See if we have overflown the SSBO in one of the previous frames. |
... | ... | |
614 | 614 |
|
615 | 615 |
mBufferSize *= (int)(overflow+1.0f); |
616 | 616 |
int size = (int)(surface.mWidth*surface.mHeight*(3*mBufferSize+1)*4); |
617 |
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mLinkedListSSBO[0]);
|
|
618 |
GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, size, null, GLES31.GL_DYNAMIC_READ|GLES31.GL_DYNAMIC_DRAW);
|
|
619 |
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, 0);
|
|
617 |
GLES30.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mLinkedListSSBO[0]);
|
|
618 |
GLES30.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, size, null, GLES30.GL_DYNAMIC_READ|GLES30.GL_DYNAMIC_DRAW);
|
|
619 |
GLES30.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, 0);
|
|
620 | 620 |
} |
621 | 621 |
|
622 | 622 |
mOITClearProgram.useProgram(); |
623 | 623 |
|
624 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
|
625 |
GLES31.glUniform2f(mOITClearTexCorrH, 1.0f, 1.0f ); // corrections do not really matter here - only present because of common vertex shader.
|
|
626 |
GLES31.glUniform1f( mOITClearDepthH , 1.0f); // likewise depth
|
|
627 |
GLES31.glUniform2ui(mOITClearSizeH, surface.mWidth, surface.mHeight);
|
|
628 |
GLES31.glVertexAttribPointer(mOITClearProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
|
|
629 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
|
|
624 |
GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
|
625 |
GLES30.glUniform2f(mOITClearTexCorrH, 1.0f, 1.0f ); // corrections do not really matter here - only present because of common vertex shader.
|
|
626 |
GLES30.glUniform1f( mOITClearDepthH , 1.0f); // likewise depth
|
|
627 |
GLES30.glUniform2ui(mOITClearSizeH, surface.mWidth, surface.mHeight);
|
|
628 |
GLES30.glVertexAttribPointer(mOITClearProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
|
|
629 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
|
|
630 | 630 |
} |
631 | 631 |
|
632 | 632 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
636 | 636 |
{ |
637 | 637 |
mOITBuildProgram.useProgram(); |
638 | 638 |
|
639 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
|
640 |
GLES31.glUniform1i(mOITBuildTextureH, 0);
|
|
641 |
GLES31.glUniform1i(mOITBuildDepthTextureH, 1);
|
|
642 |
GLES31.glUniform2f(mOITBuildTexCorrH, corrW, corrH );
|
|
643 |
GLES31.glUniform2ui(mOITBuildSizeH, surface.mWidth, surface.mHeight);
|
|
644 |
GLES31.glUniform1ui(mOITBuildNumRecordsH, (int)(mBufferSize*surface.mWidth*surface.mHeight) );
|
|
645 |
GLES31.glUniform1f(mOITBuildDepthH , 1.0f-surface.mNear);
|
|
646 |
GLES31.glVertexAttribPointer(mOITBuildProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
|
|
647 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
|
|
639 |
GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
|
640 |
GLES30.glUniform1i(mOITBuildTextureH, 0);
|
|
641 |
GLES30.glUniform1i(mOITBuildDepthTextureH, 1);
|
|
642 |
GLES30.glUniform2f(mOITBuildTexCorrH, corrW, corrH );
|
|
643 |
GLES30.glUniform2ui(mOITBuildSizeH, surface.mWidth, surface.mHeight);
|
|
644 |
GLES30.glUniform1ui(mOITBuildNumRecordsH, (int)(mBufferSize*surface.mWidth*surface.mHeight) );
|
|
645 |
GLES30.glUniform1f(mOITBuildDepthH , 1.0f-surface.mNear);
|
|
646 |
GLES30.glVertexAttribPointer(mOITBuildProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
|
|
647 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
|
|
648 | 648 |
} |
649 | 649 |
|
650 | 650 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
654 | 654 |
{ |
655 | 655 |
mOITCollapseProgram.useProgram(); |
656 | 656 |
|
657 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
|
658 |
GLES31.glUniform1i(mOITCollapseDepthTextureH, 1);
|
|
659 |
GLES31.glUniform2f(mOITCollapseTexCorrH, corrW, corrH );
|
|
660 |
GLES31.glUniform2ui(mOITCollapseSizeH, surface.mWidth, surface.mHeight);
|
|
661 |
GLES31.glUniform1f( mOITCollapseDepthH , 1.0f-surface.mNear);
|
|
662 |
GLES31.glVertexAttribPointer(mOITCollapseProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
|
|
663 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
|
|
657 |
GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
|
658 |
GLES30.glUniform1i(mOITCollapseDepthTextureH, 1);
|
|
659 |
GLES30.glUniform2f(mOITCollapseTexCorrH, corrW, corrH );
|
|
660 |
GLES30.glUniform2ui(mOITCollapseSizeH, surface.mWidth, surface.mHeight);
|
|
661 |
GLES30.glUniform1f( mOITCollapseDepthH , 1.0f-surface.mNear);
|
|
662 |
GLES30.glVertexAttribPointer(mOITCollapseProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
|
|
663 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
|
|
664 | 664 |
} |
665 | 665 |
|
666 | 666 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
670 | 670 |
{ |
671 | 671 |
mOITRenderProgram.useProgram(); |
672 | 672 |
|
673 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
|
674 |
GLES31.glUniform2f(mOITRenderTexCorrH, corrW, corrH );
|
|
675 |
GLES31.glUniform2ui(mOITRenderSizeH, surface.mWidth, surface.mHeight);
|
|
676 |
GLES31.glUniform1f( mOITRenderDepthH , 1.0f-surface.mNear);
|
|
677 |
GLES31.glVertexAttribPointer(mOITRenderProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
|
|
678 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
|
|
673 |
GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
|
674 |
GLES30.glUniform2f(mOITRenderTexCorrH, corrW, corrH );
|
|
675 |
GLES30.glUniform2ui(mOITRenderSizeH, surface.mWidth, surface.mHeight);
|
|
676 |
GLES30.glUniform1f( mOITRenderDepthH , 1.0f-surface.mNear);
|
|
677 |
GLES30.glVertexAttribPointer(mOITRenderProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
|
|
678 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
|
|
679 | 679 |
} |
680 | 680 |
|
681 | 681 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
687 | 687 |
|
688 | 688 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
689 | 689 |
// ARM Mali driver r12 has problems when we keep swapping many FBOs (fixed in r22) |
690 |
// PowerVR GE8100 compiler fails to compile OIT programs. |
|
690 |
// PowerVR GE8100 / GE8300 compiler fails to compile OIT programs.
|
|
691 | 691 |
|
692 | 692 |
private static void detectBuggyDrivers() |
693 | 693 |
{ |
694 |
String vendor = GLES31.glGetString(GLES31.GL_VENDOR);
|
|
695 |
String version = GLES31.glGetString(GLES31.GL_VERSION);
|
|
696 |
String renderer= GLES31.glGetString(GLES31.GL_RENDERER);
|
|
694 |
String vendor = GLES30.glGetString(GLES30.GL_VENDOR);
|
|
695 |
String version = GLES30.glGetString(GLES30.GL_VERSION);
|
|
696 |
String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
|
|
697 | 697 |
|
698 | 698 |
/* |
699 |
android.util.Log.e("DISTORTED", "GLSL Version "+GLES31.glGetString(GLES31.GL_SHADING_LANGUAGE_VERSION));
|
|
700 |
android.util.Log.e("DISTORTED", "GL Version " +GLES31.glGetString(GLES31.GL_VERSION));
|
|
701 |
android.util.Log.e("DISTORTED", "GL Vendor " +GLES31.glGetString(GLES31.GL_VENDOR));
|
|
702 |
android.util.Log.e("DISTORTED", "GL Renderer " +GLES31.glGetString(GLES31.GL_RENDERER));
|
|
699 |
android.util.Log.e("DISTORTED", "GLSL Version "+GLES30.glGetString(GLES31.GL_SHADING_LANGUAGE_VERSION));
|
|
700 |
android.util.Log.e("DISTORTED", "GL Version " +GLES30.glGetString(GLES31.GL_VERSION));
|
|
701 |
android.util.Log.e("DISTORTED", "GL Vendor " +GLES30.glGetString(GLES31.GL_VENDOR));
|
|
702 |
android.util.Log.e("DISTORTED", "GL Renderer " +GLES30.glGetString(GLES31.GL_RENDERER));
|
|
703 | 703 |
*/ |
704 | 704 |
|
705 | 705 |
if( vendor.contains("ARM") ) |
706 | 706 |
{ |
707 | 707 |
if( version.contains("r12") ) |
708 | 708 |
{ |
709 |
android.util.Log.e("DISTORTED", "You are running this on a ARM Mali driver r12.\nThis is a buggy driver, please update to r22. Problems with flashing expected.");
|
|
709 |
Log.e("DISTORTED", "You are running this on a ARM Mali driver r12.\nThis is a buggy driver, please update to r22. Problems with flashing expected."); |
|
710 | 710 |
} |
711 | 711 |
} |
712 | 712 |
else if( vendor.contains("Imagination") ) |
713 | 713 |
{ |
714 | 714 |
if( renderer.contains("GE8") ) |
715 | 715 |
{ |
716 |
android.util.Log.e("DISTORTED", "You are running this on a PowerVR GE8XXX.\nDue to a buggy compiler OIT rendering will not work");
|
|
716 |
Log.e("DISTORTED", "You are running this on a PowerVR GE8XXX.\nDue to a buggy compiler OIT rendering will not work"); |
|
717 | 717 |
} |
718 | 718 |
} |
719 | 719 |
} |
720 | 720 |
|
721 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
722 |
/** |
|
723 |
* Return OpenGL ES version supported by the hardware we are running on. |
|
724 |
* There are only two possibilities: 300 (OpenGL ES 3.0) or 310 (at least OpenGL ES 3.1) |
|
725 |
*/ |
|
726 |
static int getGLSL() |
|
727 |
{ |
|
728 |
return mGLSL; |
|
729 |
} |
|
730 |
|
|
731 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
732 |
/** |
|
733 |
* Have we successfully managed to compile the OIT programs? |
|
734 |
* Some hardware ( Imagination GE8100 / 8300, driver build 1.8@4490469 present in my HTC phone and, |
|
735 |
* sadly, Amazon Fire Stick 4K ) fails to compile the shaders. See relevant thread in Imagination's |
|
736 |
* support forum: |
|
737 |
* |
|
738 |
* https://forums.imgtec.com/t/ge8100-in-htc-desire-12-android-7-1-1-fragment-shader-fails-to-compile/2708 |
|
739 |
*/ |
|
740 |
public static boolean OITCompilationSuccessful() |
|
741 |
{ |
|
742 |
return mOITCompilationSuccessful; |
|
743 |
} |
|
744 |
|
|
721 | 745 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
722 | 746 |
/** |
723 | 747 |
* Have we called onCreate yet, ie have we initialized the library? |
... | ... | |
741 | 765 |
{ |
742 | 766 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
743 | 767 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
744 |
android.util.Log.e("DISTORTED", "Using OpenGL ES "+configurationInfo.getGlEsVersion()); |
|
768 |
|
|
769 |
int glESversion = configurationInfo.reqGlEsVersion; |
|
770 |
int major = glESversion >> 16; |
|
771 |
int minor = glESversion & 0xff; |
|
772 |
|
|
773 |
if( major< 3 ) |
|
774 |
{ |
|
775 |
mGLSL = 100*major + 10*minor; |
|
776 |
throw new VertexCompilationException("at least OpenGL ES 3.0 required, this device supports only "+major+"."+minor); |
|
777 |
} |
|
778 |
else |
|
779 |
{ |
|
780 |
mGLSL = (major==3 && minor==0) ? 300 : 310; |
|
781 |
} |
|
782 |
|
|
783 |
android.util.Log.e("DISTORTED", "Using OpenGL ES "+major+"."+minor); |
|
784 |
mGLSL_VERSION = "#version "+mGLSL+" es\n"; |
|
745 | 785 |
|
746 | 786 |
mInitialized = true; |
787 |
mOITCompilationSuccessful = false; |
|
747 | 788 |
|
748 | 789 |
detectBuggyDrivers(); |
749 | 790 |
|
... | ... | |
762 | 803 |
exception = ex; |
763 | 804 |
} |
764 | 805 |
|
765 |
try
|
|
806 |
if( mGLSL>=310)
|
|
766 | 807 |
{ |
767 |
createProgramsOIT(resources); |
|
768 |
} |
|
769 |
catch(Exception ex) |
|
770 |
{ |
|
771 |
exception = ex; |
|
808 |
try |
|
809 |
{ |
|
810 |
createProgramsOIT(resources); |
|
811 |
mOITCompilationSuccessful = true; |
|
812 |
} |
|
813 |
catch(Exception ex) |
|
814 |
{ |
|
815 |
exception = ex; |
|
816 |
} |
|
772 | 817 |
} |
773 | 818 |
|
774 | 819 |
try |
775 | 820 |
{ |
776 |
EffectQueuePostprocess.createPrograms(resources); |
|
821 |
EffectQueuePostprocess.createPrograms(resources, mGLSL);
|
|
777 | 822 |
} |
778 | 823 |
catch(Exception ex) |
779 | 824 |
{ |
... | ... | |
782 | 827 |
|
783 | 828 |
try |
784 | 829 |
{ |
785 |
PostprocessEffect.createPrograms(); |
|
830 |
PostprocessEffect.createPrograms(mGLSL);
|
|
786 | 831 |
} |
787 | 832 |
catch(Exception ex) |
788 | 833 |
{ |
src/main/java/org/distorted/library/main/DistortedNode.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.library.main; |
21 | 21 |
|
22 |
import android.opengl.GLES31;
|
|
22 |
import android.opengl.GLES30;
|
|
23 | 23 |
|
24 | 24 |
import org.distorted.library.mesh.MeshBase; |
25 | 25 |
|
... | ... | |
159 | 159 |
if( input.setAsInput() ) |
160 | 160 |
{ |
161 | 161 |
mState.apply(); |
162 |
GLES31.glDisable(GLES31.GL_BLEND);
|
|
162 |
GLES30.glDisable(GLES30.GL_BLEND);
|
|
163 | 163 |
DistortedLibrary.drawPriv(mEffects, mMesh, surface, currTime); |
164 |
GLES31.glEnable(GLES31.GL_BLEND);
|
|
164 |
GLES30.glEnable(GLES30.GL_BLEND);
|
|
165 | 165 |
return 1; |
166 | 166 |
} |
167 | 167 |
|
src/main/java/org/distorted/library/main/DistortedScreen.java | ||
---|---|---|
24 | 24 |
import android.graphics.Bitmap; |
25 | 25 |
import android.graphics.Canvas; |
26 | 26 |
import android.graphics.Paint; |
27 |
import android.opengl.GLES31;
|
|
27 |
import android.opengl.GLES30;
|
|
28 | 28 |
|
29 | 29 |
import org.distorted.library.effect.MatrixEffectMove; |
30 | 30 |
import org.distorted.library.effect.MatrixEffectScale; |
... | ... | |
115 | 115 |
|
116 | 116 |
int numrender = super.render(time,mCurRenderedFBO); |
117 | 117 |
|
118 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0);
|
|
118 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0);
|
|
119 | 119 |
|
120 | 120 |
// workaround for the Mali issues: blit the framebuffer we have computed DistortedLibrary.FBO_QUEUE_SIZE |
121 | 121 |
// frames ago. Looks like FBO_QUEUE_SIZE=2 solves the issue already but I decided to play it safe and |
... | ... | |
124 | 124 |
// on speed. Maybe a slight positive effect if any! |
125 | 125 |
setAsInput(mToBeBlittedFBO,0); |
126 | 126 |
|
127 |
GLES31.glColorMask(true,true,true,true);
|
|
128 |
GLES31.glDepthMask(false);
|
|
129 |
GLES31.glDisable(GLES31.GL_STENCIL_TEST);
|
|
130 |
GLES31.glDisable(GLES31.GL_DEPTH_TEST);
|
|
131 |
GLES31.glDisable(GLES31.GL_BLEND);
|
|
127 |
GLES30.glColorMask(true,true,true,true);
|
|
128 |
GLES30.glDepthMask(false);
|
|
129 |
GLES30.glDisable(GLES30.GL_STENCIL_TEST);
|
|
130 |
GLES30.glDisable(GLES30.GL_DEPTH_TEST);
|
|
131 |
GLES30.glDisable(GLES30.GL_BLEND);
|
|
132 | 132 |
|
133 | 133 |
DistortedLibrary.blitPriv(this); |
134 | 134 |
|
src/main/java/org/distorted/library/main/DistortedTexture.java | ||
---|---|---|
23 | 23 |
import android.graphics.Canvas; |
24 | 24 |
import android.graphics.Matrix; |
25 | 25 |
import android.graphics.Paint; |
Also available in: Unified diff
Lower requirements - now only OpenGL ES 3.0 is required; if running on such platform, OIT part of the API ( which is the only one which actually requires 3.1) is switched off.