1 |
d333eb6b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Distorted. //
|
5 |
|
|
// //
|
6 |
|
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
|
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
|
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
|
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
fe82a979
|
Leszek Koltunski
|
package org.distorted.library.main;
|
21 |
6a06a912
|
Leszek Koltunski
|
|
22 |
c90b9e01
|
Leszek Koltunski
|
import android.content.res.Resources;
|
23 |
e6519ac8
|
Leszek Koltunski
|
import android.opengl.GLES31;
|
24 |
|
|
import android.util.Log;
|
25 |
6a06a912
|
Leszek Koltunski
|
|
26 |
fe82a979
|
Leszek Koltunski
|
import org.distorted.library.R;
|
27 |
|
|
import org.distorted.library.effect.Effect;
|
28 |
da9b3f07
|
Leszek Koltunski
|
import org.distorted.library.effect.EffectName;
|
29 |
|
|
import org.distorted.library.effect.EffectType;
|
30 |
7cd24173
|
leszek
|
import org.distorted.library.effect.FragmentEffect;
|
31 |
|
|
import org.distorted.library.effect.VertexEffect;
|
32 |
715e7726
|
Leszek Koltunski
|
import org.distorted.library.mesh.MeshBase;
|
33 |
e458a4ba
|
Leszek Koltunski
|
import org.distorted.library.message.EffectListener;
|
34 |
55c14a19
|
Leszek Koltunski
|
import org.distorted.library.program.DistortedProgram;
|
35 |
a4835695
|
Leszek Koltunski
|
|
36 |
c90b9e01
|
Leszek Koltunski
|
import java.io.InputStream;
|
37 |
c638c1b0
|
Leszek Koltunski
|
import java.nio.ByteBuffer;
|
38 |
|
|
import java.nio.ByteOrder;
|
39 |
|
|
import java.nio.FloatBuffer;
|
40 |
8777ce17
|
Leszek Koltunski
|
import java.nio.IntBuffer;
|
41 |
c638c1b0
|
Leszek Koltunski
|
|
42 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43 |
b329f352
|
Leszek Koltunski
|
/**
|
44 |
faa3ff56
|
Leszek Koltunski
|
* Class containing Matrix, Vertex, Fragment and Postprocessing effect queues.
|
45 |
b73dcaa7
|
Leszek Koltunski
|
* <p>
|
46 |
715e7726
|
Leszek Koltunski
|
* The queues hold actual effects to be applied to a given (InputSurface,MeshBase) combo.
|
47 |
b329f352
|
Leszek Koltunski
|
*/
|
48 |
86d322b5
|
Leszek Koltunski
|
public class DistortedEffects
|
49 |
d425545a
|
Leszek Koltunski
|
{
|
50 |
1aedf874
|
leszek
|
/// MAIN PROGRAM ///
|
51 |
|
|
private static DistortedProgram mMainProgram;
|
52 |
|
|
private static int mMainTextureH;
|
53 |
8fa96e69
|
Leszek Koltunski
|
|
54 |
c1e24646
|
leszek
|
/// BLIT PROGRAM ///
|
55 |
|
|
private static DistortedProgram mBlitProgram;
|
56 |
|
|
private static int mBlitTextureH;
|
57 |
c2c08950
|
leszek
|
private static int mBlitDepthH;
|
58 |
c90b9e01
|
Leszek Koltunski
|
private static final FloatBuffer mQuadPositions;
|
59 |
|
|
|
60 |
|
|
static
|
61 |
|
|
{
|
62 |
|
|
float[] positionData= { -0.5f, -0.5f, -0.5f, 0.5f, 0.5f,-0.5f, 0.5f, 0.5f };
|
63 |
|
|
mQuadPositions = ByteBuffer.allocateDirect(32).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
64 |
|
|
mQuadPositions.put(positionData).position(0);
|
65 |
|
|
}
|
66 |
|
|
|
67 |
97020807
|
Leszek Koltunski
|
/// BLIT DEPTH PROGRAM ///
|
68 |
|
|
private static DistortedProgram mBlitDepthProgram;
|
69 |
|
|
private static int mBlitDepthTextureH;
|
70 |
|
|
private static int mBlitDepthDepthTextureH;
|
71 |
|
|
private static int mBlitDepthDepthH;
|
72 |
|
|
private static int mBlitDepthTexCorrH;
|
73 |
|
|
|
74 |
c1a38ba3
|
Leszek Koltunski
|
/// NORMAL PROGRAM /////
|
75 |
|
|
private static DistortedProgram mNormalProgram;
|
76 |
|
|
private static int mNormalMVPMatrixH;
|
77 |
|
|
|
78 |
33f59f22
|
Leszek Koltunski
|
/// OIT SSBO BUFFER ///
|
79 |
|
|
private static int[] mLinkedListSSBO = new int[1];
|
80 |
12f9e4bb
|
Leszek Koltunski
|
private static int[] mAtomicCounter = new int[Distorted.FBO_QUEUE_SIZE];
|
81 |
|
|
private static int mCurrBuffer;
|
82 |
33f59f22
|
Leszek Koltunski
|
|
83 |
|
|
static
|
84 |
|
|
{
|
85 |
|
|
mLinkedListSSBO[0]= -1;
|
86 |
12f9e4bb
|
Leszek Koltunski
|
mCurrBuffer = 0;
|
87 |
|
|
|
88 |
|
|
for(int i=0; i<Distorted.FBO_QUEUE_SIZE; i++) mAtomicCounter[i] = -1;
|
89 |
33f59f22
|
Leszek Koltunski
|
}
|
90 |
|
|
|
91 |
344ac0e4
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////
|
92 |
acb44099
|
Leszek Koltunski
|
// meaning: allocate 1.0 screenful of places for transparent
|
93 |
|
|
// fragments in the SSBO backing up the OIT render method.
|
94 |
|
|
private static float mBufferSize=1.0f;
|
95 |
33f59f22
|
Leszek Koltunski
|
|
96 |
56c6ca24
|
Leszek Koltunski
|
/// OIT CLEAR PROGRAM ///
|
97 |
|
|
private static DistortedProgram mOITClearProgram;
|
98 |
|
|
private static int mOITClearDepthH;
|
99 |
|
|
private static int mOITClearTexCorrH;
|
100 |
|
|
private static int mOITClearSizeH;
|
101 |
|
|
|
102 |
|
|
/// OIT BUILD PROGRAM ///
|
103 |
|
|
private static DistortedProgram mOITBuildProgram;
|
104 |
|
|
private static int mOITBuildTextureH;
|
105 |
|
|
private static int mOITBuildDepthTextureH;
|
106 |
|
|
private static int mOITBuildDepthH;
|
107 |
|
|
private static int mOITBuildTexCorrH;
|
108 |
|
|
private static int mOITBuildSizeH;
|
109 |
|
|
private static int mOITBuildNumRecordsH;
|
110 |
8777ce17
|
Leszek Koltunski
|
|
111 |
33f59f22
|
Leszek Koltunski
|
/// OIT COLLAPSE PROGRAM ///
|
112 |
|
|
private static DistortedProgram mOITCollapseProgram;
|
113 |
|
|
private static int mOITCollapseDepthTextureH;
|
114 |
|
|
private static int mOITCollapseDepthH;
|
115 |
|
|
private static int mOITCollapseTexCorrH;
|
116 |
|
|
private static int mOITCollapseSizeH;
|
117 |
cee0369a
|
Leszek Koltunski
|
|
118 |
56c6ca24
|
Leszek Koltunski
|
/// OIT RENDER PROGRAM ///
|
119 |
|
|
private static DistortedProgram mOITRenderProgram;
|
120 |
|
|
private static int mOITRenderDepthH;
|
121 |
|
|
private static int mOITRenderTexCorrH;
|
122 |
|
|
private static int mOITRenderSizeH;
|
123 |
7170e4eb
|
leszek
|
|
124 |
c1a38ba3
|
Leszek Koltunski
|
/// MAIN OIT PROGRAM ///
|
125 |
|
|
private static DistortedProgram mMainOITProgram;
|
126 |
|
|
private static int mMainOITTextureH;
|
127 |
|
|
private static int mMainOITSizeH;
|
128 |
|
|
private static int mMainOITNumRecordsH;
|
129 |
3fc9327a
|
Leszek Koltunski
|
/// END PROGRAMS //////
|
130 |
c638c1b0
|
Leszek Koltunski
|
|
131 |
8e34674e
|
Leszek Koltunski
|
private static long mNextID =0;
|
132 |
4e2382f3
|
Leszek Koltunski
|
private long mID;
|
133 |
8e34674e
|
Leszek Koltunski
|
|
134 |
310e14fb
|
leszek
|
private EffectQueueMatrix mM;
|
135 |
3fc9327a
|
Leszek Koltunski
|
private EffectQueueFragment mF;
|
136 |
310e14fb
|
leszek
|
private EffectQueueVertex mV;
|
137 |
80b3acf6
|
Leszek Koltunski
|
private EffectQueuePostprocess mP;
|
138 |
|
|
|
139 |
|
|
private boolean matrixCloned, vertexCloned, fragmentCloned, postprocessCloned;
|
140 |
3d590d8d
|
Leszek Koltunski
|
|
141 |
9361b337
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
142 |
55c14a19
|
Leszek Koltunski
|
|
143 |
c25273e0
|
Leszek Koltunski
|
static void createPrograms(Resources resources)
|
144 |
55c14a19
|
Leszek Koltunski
|
{
|
145 |
cab7c165
|
Leszek Koltunski
|
// MAIN PROGRAM ////////////////////////////////////
|
146 |
1aedf874
|
leszek
|
final InputStream mainVertStream = resources.openRawResource(R.raw.main_vertex_shader);
|
147 |
|
|
final InputStream mainFragStream = resources.openRawResource(R.raw.main_fragment_shader);
|
148 |
|
|
|
149 |
7cd24173
|
leszek
|
int numF = FragmentEffect.getNumEnabled();
|
150 |
|
|
int numV = VertexEffect.getNumEnabled();
|
151 |
c90b9e01
|
Leszek Koltunski
|
|
152 |
7cd24173
|
leszek
|
String mainVertHeader= Distorted.GLSL_VERSION + ("#define NUM_VERTEX " + ( numV>0 ? getMax(EffectType.VERTEX ) : 0 ) + "\n");
|
153 |
|
|
String mainFragHeader= Distorted.GLSL_VERSION + ("#define NUM_FRAGMENT " + ( numF>0 ? getMax(EffectType.FRAGMENT) : 0 ) + "\n");
|
154 |
|
|
String enabledEffectV= VertexEffect.getGLSL();
|
155 |
|
|
String enabledEffectF= FragmentEffect.getGLSL();
|
156 |
c90b9e01
|
Leszek Koltunski
|
|
157 |
03cb451d
|
Leszek Koltunski
|
//android.util.Log.e("Effects", "vertHeader= "+mainVertHeader);
|
158 |
|
|
//android.util.Log.e("Effects", "fragHeader= "+mainFragHeader);
|
159 |
7cd24173
|
leszek
|
//android.util.Log.e("Effects", "enabledV= "+enabledEffectV);
|
160 |
|
|
//android.util.Log.e("Effects", "enabledF= "+enabledEffectF);
|
161 |
c90b9e01
|
Leszek Koltunski
|
|
162 |
3fc9327a
|
Leszek Koltunski
|
String[] feedback = { "v_Position", "v_endPosition" };
|
163 |
cab7c165
|
Leszek Koltunski
|
|
164 |
cee0369a
|
Leszek Koltunski
|
try
|
165 |
|
|
{
|
166 |
|
|
mMainProgram = new DistortedProgram(mainVertStream, mainFragStream, mainVertHeader, mainFragHeader,
|
167 |
|
|
enabledEffectV, enabledEffectF, Distorted.GLSL, feedback);
|
168 |
|
|
}
|
169 |
|
|
catch(Exception e)
|
170 |
|
|
{
|
171 |
|
|
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile MAIN program: "+e.getMessage());
|
172 |
|
|
throw new RuntimeException(e.getMessage());
|
173 |
|
|
}
|
174 |
c90b9e01
|
Leszek Koltunski
|
|
175 |
c1e24646
|
leszek
|
int mainProgramH = mMainProgram.getProgramHandle();
|
176 |
86c352e0
|
Leszek Koltunski
|
EffectQueueFragment.getUniforms(mainProgramH,0);
|
177 |
|
|
EffectQueueVertex.getUniforms(mainProgramH,0);
|
178 |
|
|
EffectQueueMatrix.getUniforms(mainProgramH,0);
|
179 |
e6519ac8
|
Leszek Koltunski
|
mMainTextureH= GLES31.glGetUniformLocation( mainProgramH, "u_Texture");
|
180 |
c1e24646
|
leszek
|
|
181 |
1aedf874
|
leszek
|
// BLIT PROGRAM ////////////////////////////////////
|
182 |
c1e24646
|
leszek
|
final InputStream blitVertStream = resources.openRawResource(R.raw.blit_vertex_shader);
|
183 |
|
|
final InputStream blitFragStream = resources.openRawResource(R.raw.blit_fragment_shader);
|
184 |
|
|
|
185 |
f2367b75
|
Leszek Koltunski
|
try
|
186 |
|
|
{
|
187 |
56c6ca24
|
Leszek Koltunski
|
mBlitProgram = new DistortedProgram(blitVertStream,blitFragStream,Distorted.GLSL_VERSION,Distorted.GLSL_VERSION, Distorted.GLSL);
|
188 |
f2367b75
|
Leszek Koltunski
|
}
|
189 |
|
|
catch(Exception e)
|
190 |
|
|
{
|
191 |
cee0369a
|
Leszek Koltunski
|
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile BLIT program: "+e.getMessage());
|
192 |
f2367b75
|
Leszek Koltunski
|
throw new RuntimeException(e.getMessage());
|
193 |
|
|
}
|
194 |
c1e24646
|
leszek
|
|
195 |
|
|
int blitProgramH = mBlitProgram.getProgramHandle();
|
196 |
e6519ac8
|
Leszek Koltunski
|
mBlitTextureH = GLES31.glGetUniformLocation( blitProgramH, "u_Texture");
|
197 |
|
|
mBlitDepthH = GLES31.glGetUniformLocation( blitProgramH, "u_Depth");
|
198 |
c90b9e01
|
Leszek Koltunski
|
|
199 |
97020807
|
Leszek Koltunski
|
// BLIT DEPTH PROGRAM ////////////////////////////////////
|
200 |
|
|
final InputStream blitDepthVertStream = resources.openRawResource(R.raw.blit_depth_vertex_shader);
|
201 |
|
|
final InputStream blitDepthFragStream = resources.openRawResource(R.raw.blit_depth_fragment_shader);
|
202 |
|
|
|
203 |
|
|
try
|
204 |
|
|
{
|
205 |
|
|
mBlitDepthProgram = new DistortedProgram(blitDepthVertStream,blitDepthFragStream,Distorted.GLSL_VERSION,Distorted.GLSL_VERSION, Distorted.GLSL);
|
206 |
|
|
}
|
207 |
|
|
catch(Exception e)
|
208 |
|
|
{
|
209 |
|
|
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile BLIT DEPTH program: "+e.getMessage());
|
210 |
|
|
throw new RuntimeException(e.getMessage());
|
211 |
|
|
}
|
212 |
|
|
|
213 |
|
|
int blitDepthProgramH = mBlitDepthProgram.getProgramHandle();
|
214 |
|
|
mBlitDepthTextureH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_Texture");
|
215 |
|
|
mBlitDepthDepthTextureH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_DepthTexture");
|
216 |
|
|
mBlitDepthDepthH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_Depth");
|
217 |
|
|
mBlitDepthTexCorrH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_TexCorr");
|
218 |
|
|
|
219 |
c25273e0
|
Leszek Koltunski
|
// NORMAL PROGRAM //////////////////////////////////////
|
220 |
|
|
final InputStream normalVertexStream = resources.openRawResource(R.raw.normal_vertex_shader);
|
221 |
|
|
final InputStream normalFragmentStream = resources.openRawResource(R.raw.normal_fragment_shader);
|
222 |
|
|
|
223 |
|
|
try
|
224 |
|
|
{
|
225 |
|
|
mNormalProgram = new DistortedProgram(normalVertexStream,normalFragmentStream, Distorted.GLSL_VERSION, Distorted.GLSL_VERSION, Distorted.GLSL);
|
226 |
|
|
}
|
227 |
|
|
catch(Exception e)
|
228 |
|
|
{
|
229 |
|
|
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile NORMAL program: "+e.getMessage());
|
230 |
|
|
throw new RuntimeException(e.getMessage());
|
231 |
|
|
}
|
232 |
|
|
|
233 |
|
|
int normalProgramH = mNormalProgram.getProgramHandle();
|
234 |
|
|
mNormalMVPMatrixH = GLES31.glGetUniformLocation( normalProgramH, "u_MVPMatrix");
|
235 |
|
|
}
|
236 |
|
|
|
237 |
031fbe7a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
238 |
c25273e0
|
Leszek Koltunski
|
|
239 |
|
|
static void createProgramsOIT(Resources resources)
|
240 |
|
|
{
|
241 |
c1a38ba3
|
Leszek Koltunski
|
// MAIN OIT PROGRAM ////////////////////////////////
|
242 |
|
|
final InputStream mainVertStream = resources.openRawResource(R.raw.main_vertex_shader);
|
243 |
|
|
final InputStream mainFragStream = resources.openRawResource(R.raw.main_fragment_shader);
|
244 |
|
|
|
245 |
|
|
int numF = FragmentEffect.getNumEnabled();
|
246 |
|
|
int numV = VertexEffect.getNumEnabled();
|
247 |
|
|
|
248 |
|
|
String mainVertHeader= Distorted.GLSL_VERSION +
|
249 |
|
|
("#define NUM_VERTEX " + ( numV>0 ? getMax(EffectType.VERTEX ) : 0 ) + "\n") +
|
250 |
|
|
("#define OIT\n");
|
251 |
|
|
String mainFragHeader= Distorted.GLSL_VERSION +
|
252 |
|
|
("#define NUM_FRAGMENT " + ( numF>0 ? getMax(EffectType.FRAGMENT) : 0 ) + "\n") +
|
253 |
|
|
("#define OIT\n");
|
254 |
|
|
|
255 |
|
|
String enabledEffectV= VertexEffect.getGLSL();
|
256 |
|
|
String enabledEffectF= FragmentEffect.getGLSL();
|
257 |
|
|
|
258 |
|
|
try
|
259 |
|
|
{
|
260 |
|
|
mMainOITProgram = new DistortedProgram(mainVertStream, mainFragStream, mainVertHeader, mainFragHeader,
|
261 |
86c352e0
|
Leszek Koltunski
|
enabledEffectV, enabledEffectF, Distorted.GLSL, null);
|
262 |
c1a38ba3
|
Leszek Koltunski
|
}
|
263 |
|
|
catch(Exception e)
|
264 |
|
|
{
|
265 |
|
|
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile MAIN OIT program: "+e.getMessage());
|
266 |
|
|
throw new RuntimeException(e.getMessage());
|
267 |
|
|
}
|
268 |
|
|
|
269 |
|
|
int mainOITProgramH = mMainOITProgram.getProgramHandle();
|
270 |
86c352e0
|
Leszek Koltunski
|
EffectQueueFragment.getUniforms(mainOITProgramH,1);
|
271 |
|
|
EffectQueueVertex.getUniforms(mainOITProgramH,1);
|
272 |
|
|
EffectQueueMatrix.getUniforms(mainOITProgramH,1);
|
273 |
c1a38ba3
|
Leszek Koltunski
|
mMainOITTextureH = GLES31.glGetUniformLocation( mainOITProgramH, "u_Texture");
|
274 |
|
|
mMainOITSizeH = GLES31.glGetUniformLocation( mainOITProgramH, "u_Size");
|
275 |
|
|
mMainOITNumRecordsH = GLES31.glGetUniformLocation( mainOITProgramH, "u_numRecords");
|
276 |
|
|
|
277 |
56c6ca24
|
Leszek Koltunski
|
// OIT CLEAR PROGRAM ////////////////////////////////////
|
278 |
|
|
final InputStream oitClearVertStream = resources.openRawResource(R.raw.oit_vertex_shader);
|
279 |
|
|
final InputStream oitClearFragStream = resources.openRawResource(R.raw.oit_clear_fragment_shader);
|
280 |
7170e4eb
|
leszek
|
|
281 |
|
|
try
|
282 |
|
|
{
|
283 |
56c6ca24
|
Leszek Koltunski
|
mOITClearProgram = new DistortedProgram(oitClearVertStream,oitClearFragStream,Distorted.GLSL_VERSION,Distorted.GLSL_VERSION, Distorted.GLSL);
|
284 |
7170e4eb
|
leszek
|
}
|
285 |
|
|
catch(Exception e)
|
286 |
|
|
{
|
287 |
56c6ca24
|
Leszek Koltunski
|
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile OIT CLEAR program: "+e.getMessage());
|
288 |
7170e4eb
|
leszek
|
throw new RuntimeException(e.getMessage());
|
289 |
|
|
}
|
290 |
|
|
|
291 |
56c6ca24
|
Leszek Koltunski
|
int oitClearProgramH = mOITClearProgram.getProgramHandle();
|
292 |
|
|
mOITClearDepthH = GLES31.glGetUniformLocation( oitClearProgramH, "u_Depth");
|
293 |
|
|
mOITClearTexCorrH = GLES31.glGetUniformLocation( oitClearProgramH, "u_TexCorr");
|
294 |
|
|
mOITClearSizeH = GLES31.glGetUniformLocation( oitClearProgramH, "u_Size");
|
295 |
|
|
|
296 |
|
|
// OIT BUILD PROGRAM ////////////////////////////////////
|
297 |
|
|
final InputStream oitBuildVertStream = resources.openRawResource(R.raw.oit_vertex_shader);
|
298 |
|
|
final InputStream oitBuildFragStream = resources.openRawResource(R.raw.oit_build_fragment_shader);
|
299 |
|
|
|
300 |
|
|
try
|
301 |
|
|
{
|
302 |
|
|
mOITBuildProgram = new DistortedProgram(oitBuildVertStream,oitBuildFragStream,Distorted.GLSL_VERSION,Distorted.GLSL_VERSION, Distorted.GLSL);
|
303 |
|
|
}
|
304 |
|
|
catch(Exception e)
|
305 |
|
|
{
|
306 |
|
|
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile OIT BUILD program: "+e.getMessage());
|
307 |
|
|
throw new RuntimeException(e.getMessage());
|
308 |
|
|
}
|
309 |
|
|
|
310 |
|
|
int oitBuildProgramH = mOITBuildProgram.getProgramHandle();
|
311 |
|
|
mOITBuildTextureH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_Texture");
|
312 |
|
|
mOITBuildDepthTextureH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_DepthTexture");
|
313 |
|
|
mOITBuildDepthH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_Depth");
|
314 |
|
|
mOITBuildTexCorrH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_TexCorr");
|
315 |
|
|
mOITBuildSizeH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_Size");
|
316 |
|
|
mOITBuildNumRecordsH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_numRecords");
|
317 |
8777ce17
|
Leszek Koltunski
|
|
318 |
33f59f22
|
Leszek Koltunski
|
// OIT COLLAPSE PROGRAM ///////////////////////////
|
319 |
|
|
final InputStream oitCollapseVertStream = resources.openRawResource(R.raw.oit_vertex_shader);
|
320 |
|
|
final InputStream oitCollapseFragStream = resources.openRawResource(R.raw.oit_collapse_fragment_shader);
|
321 |
|
|
|
322 |
|
|
try
|
323 |
|
|
{
|
324 |
|
|
mOITCollapseProgram = new DistortedProgram(oitCollapseVertStream,oitCollapseFragStream,Distorted.GLSL_VERSION,Distorted.GLSL_VERSION, Distorted.GLSL);
|
325 |
|
|
}
|
326 |
|
|
catch(Exception e)
|
327 |
|
|
{
|
328 |
|
|
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile OIT COLLAPSE program: "+e.getMessage());
|
329 |
|
|
throw new RuntimeException(e.getMessage());
|
330 |
|
|
}
|
331 |
|
|
|
332 |
|
|
int oitCollapseProgramH = mOITCollapseProgram.getProgramHandle();
|
333 |
|
|
mOITCollapseDepthTextureH = GLES31.glGetUniformLocation( oitCollapseProgramH, "u_DepthTexture");
|
334 |
|
|
mOITCollapseDepthH = GLES31.glGetUniformLocation( oitCollapseProgramH, "u_Depth");
|
335 |
|
|
mOITCollapseTexCorrH = GLES31.glGetUniformLocation( oitCollapseProgramH, "u_TexCorr");
|
336 |
|
|
mOITCollapseSizeH = GLES31.glGetUniformLocation( oitCollapseProgramH, "u_Size");
|
337 |
|
|
|
338 |
|
|
// OIT RENDER PROGRAM ///////////////////////////
|
339 |
56c6ca24
|
Leszek Koltunski
|
final InputStream oitRenderVertStream = resources.openRawResource(R.raw.oit_vertex_shader);
|
340 |
|
|
final InputStream oitRenderFragStream = resources.openRawResource(R.raw.oit_render_fragment_shader);
|
341 |
8777ce17
|
Leszek Koltunski
|
|
342 |
|
|
try
|
343 |
|
|
{
|
344 |
56c6ca24
|
Leszek Koltunski
|
mOITRenderProgram = new DistortedProgram(oitRenderVertStream,oitRenderFragStream,Distorted.GLSL_VERSION,Distorted.GLSL_VERSION, Distorted.GLSL);
|
345 |
8777ce17
|
Leszek Koltunski
|
}
|
346 |
|
|
catch(Exception e)
|
347 |
|
|
{
|
348 |
56c6ca24
|
Leszek Koltunski
|
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile OIT RENDER program: "+e.getMessage());
|
349 |
8777ce17
|
Leszek Koltunski
|
throw new RuntimeException(e.getMessage());
|
350 |
|
|
}
|
351 |
|
|
|
352 |
56c6ca24
|
Leszek Koltunski
|
int oitRenderProgramH = mOITRenderProgram.getProgramHandle();
|
353 |
|
|
mOITRenderDepthH = GLES31.glGetUniformLocation( oitRenderProgramH, "u_Depth");
|
354 |
|
|
mOITRenderTexCorrH = GLES31.glGetUniformLocation( oitRenderProgramH, "u_TexCorr");
|
355 |
|
|
mOITRenderSizeH = GLES31.glGetUniformLocation( oitRenderProgramH, "u_Size");
|
356 |
55c14a19
|
Leszek Koltunski
|
}
|
357 |
|
|
|
358 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
359 |
|
|
|
360 |
421c2728
|
Leszek Koltunski
|
private void initializeEffectLists(DistortedEffects d, int flags)
|
361 |
d425545a
|
Leszek Koltunski
|
{
|
362 |
015642fb
|
Leszek Koltunski
|
if( (flags & Distorted.CLONE_MATRIX) != 0 )
|
363 |
6a06a912
|
Leszek Koltunski
|
{
|
364 |
d425545a
|
Leszek Koltunski
|
mM = d.mM;
|
365 |
|
|
matrixCloned = true;
|
366 |
|
|
}
|
367 |
|
|
else
|
368 |
|
|
{
|
369 |
4e2382f3
|
Leszek Koltunski
|
mM = new EffectQueueMatrix(mID);
|
370 |
d425545a
|
Leszek Koltunski
|
matrixCloned = false;
|
371 |
|
|
}
|
372 |
6a06a912
|
Leszek Koltunski
|
|
373 |
d425545a
|
Leszek Koltunski
|
if( (flags & Distorted.CLONE_VERTEX) != 0 )
|
374 |
|
|
{
|
375 |
|
|
mV = d.mV;
|
376 |
|
|
vertexCloned = true;
|
377 |
|
|
}
|
378 |
|
|
else
|
379 |
|
|
{
|
380 |
4e2382f3
|
Leszek Koltunski
|
mV = new EffectQueueVertex(mID);
|
381 |
d425545a
|
Leszek Koltunski
|
vertexCloned = false;
|
382 |
|
|
}
|
383 |
6a06a912
|
Leszek Koltunski
|
|
384 |
d425545a
|
Leszek Koltunski
|
if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
|
385 |
|
|
{
|
386 |
|
|
mF = d.mF;
|
387 |
|
|
fragmentCloned = true;
|
388 |
6a06a912
|
Leszek Koltunski
|
}
|
389 |
d425545a
|
Leszek Koltunski
|
else
|
390 |
|
|
{
|
391 |
4e2382f3
|
Leszek Koltunski
|
mF = new EffectQueueFragment(mID);
|
392 |
d425545a
|
Leszek Koltunski
|
fragmentCloned = false;
|
393 |
|
|
}
|
394 |
80b3acf6
|
Leszek Koltunski
|
|
395 |
|
|
if( (flags & Distorted.CLONE_POSTPROCESS) != 0 )
|
396 |
|
|
{
|
397 |
|
|
mP = d.mP;
|
398 |
|
|
postprocessCloned = true;
|
399 |
|
|
}
|
400 |
|
|
else
|
401 |
|
|
{
|
402 |
|
|
mP = new EffectQueuePostprocess(mID);
|
403 |
|
|
postprocessCloned = false;
|
404 |
|
|
}
|
405 |
|
|
}
|
406 |
|
|
|
407 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
408 |
|
|
|
409 |
70b6a155
|
Leszek Koltunski
|
EffectQueuePostprocess getPostprocess()
|
410 |
80b3acf6
|
Leszek Koltunski
|
{
|
411 |
70b6a155
|
Leszek Koltunski
|
return mP;
|
412 |
80b3acf6
|
Leszek Koltunski
|
}
|
413 |
|
|
|
414 |
26a4e5f6
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
415 |
|
|
|
416 |
|
|
void newNode(DistortedNode node)
|
417 |
|
|
{
|
418 |
|
|
mP.newNode(node);
|
419 |
|
|
}
|
420 |
|
|
|
421 |
c43abe6c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
422 |
|
|
|
423 |
|
|
void removeNode(DistortedNode node)
|
424 |
|
|
{
|
425 |
|
|
mP.removeNode(node);
|
426 |
|
|
}
|
427 |
|
|
|
428 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
429 |
c90b9e01
|
Leszek Koltunski
|
|
430 |
715e7726
|
Leszek Koltunski
|
private void displayNormals(MeshBase mesh)
|
431 |
c90b9e01
|
Leszek Koltunski
|
{
|
432 |
6c00149d
|
Leszek Koltunski
|
int num = mesh.getNumVertices();
|
433 |
da681e7e
|
Leszek Koltunski
|
int tfo = mesh.getTFO();
|
434 |
6c00149d
|
Leszek Koltunski
|
|
435 |
da681e7e
|
Leszek Koltunski
|
GLES31.glBindBufferBase(GLES31.GL_TRANSFORM_FEEDBACK_BUFFER, 0, tfo );
|
436 |
e6519ac8
|
Leszek Koltunski
|
GLES31.glBeginTransformFeedback( GLES31.GL_POINTS);
|
437 |
604b2899
|
Leszek Koltunski
|
DistortedRenderState.switchOffDrawing();
|
438 |
6c00149d
|
Leszek Koltunski
|
GLES31.glDrawArrays( GLES31.GL_POINTS, 0, num );
|
439 |
604b2899
|
Leszek Koltunski
|
DistortedRenderState.restoreDrawing();
|
440 |
e6519ac8
|
Leszek Koltunski
|
GLES31.glEndTransformFeedback();
|
441 |
|
|
GLES31.glBindBufferBase(GLES31.GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);
|
442 |
604b2899
|
Leszek Koltunski
|
|
443 |
3fc9327a
|
Leszek Koltunski
|
mNormalProgram.useProgram();
|
444 |
e6519ac8
|
Leszek Koltunski
|
GLES31.glUniformMatrix4fv(mNormalMVPMatrixH, 1, false, mM.getMVP() , 0);
|
445 |
da681e7e
|
Leszek Koltunski
|
mesh.bindTransformAttribs(mNormalProgram);
|
446 |
e6519ac8
|
Leszek Koltunski
|
GLES31.glLineWidth(8.0f);
|
447 |
6c00149d
|
Leszek Koltunski
|
GLES31.glDrawArrays(GLES31.GL_LINES, 0, 2*num);
|
448 |
c90b9e01
|
Leszek Koltunski
|
}
|
449 |
1aedf874
|
leszek
|
|
450 |
c1a38ba3
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
451 |
|
|
|
452 |
8e88389e
|
Leszek Koltunski
|
void send(float halfX, float halfY, float halfZ, float marginInPixels, DistortedOutputSurface surface, int variant)
|
453 |
a13dde77
|
Leszek Koltunski
|
{
|
454 |
8e88389e
|
Leszek Koltunski
|
float inflate=0.0f;
|
455 |
|
|
|
456 |
|
|
mM.send(surface,halfX,halfY,halfZ,variant);
|
457 |
|
|
|
458 |
|
|
if( marginInPixels!=0.0f )
|
459 |
|
|
{
|
460 |
|
|
inflate = mM.magnify(surface,halfX,halfY,halfZ,marginInPixels);
|
461 |
|
|
}
|
462 |
|
|
|
463 |
7a5e538a
|
Leszek Koltunski
|
mV.send(inflate,variant);
|
464 |
a13dde77
|
Leszek Koltunski
|
}
|
465 |
|
|
|
466 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
467 |
|
|
|
468 |
715e7726
|
Leszek Koltunski
|
void drawPrivOIT(float halfW, float halfH, MeshBase mesh, DistortedOutputSurface surface, long currTime)
|
469 |
c1a38ba3
|
Leszek Koltunski
|
{
|
470 |
6c00149d
|
Leszek Koltunski
|
float halfZ = halfW*mesh.getZFactor();
|
471 |
c1a38ba3
|
Leszek Koltunski
|
|
472 |
|
|
mM.compute(currTime);
|
473 |
|
|
mV.compute(currTime,halfW,halfH,halfZ);
|
474 |
b24e4719
|
Leszek Koltunski
|
mF.compute(currTime,halfW,halfH,halfZ);
|
475 |
c1a38ba3
|
Leszek Koltunski
|
mP.compute(currTime);
|
476 |
|
|
|
477 |
|
|
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
478 |
|
|
|
479 |
|
|
mMainOITProgram.useProgram();
|
480 |
|
|
GLES31.glUniform1i(mMainOITTextureH, 0);
|
481 |
|
|
GLES31.glUniform2ui(mMainOITSizeH, surface.mWidth, surface.mHeight);
|
482 |
acb44099
|
Leszek Koltunski
|
GLES31.glUniform1ui(mMainOITNumRecordsH, (int)(mBufferSize*surface.mWidth*surface.mHeight) );
|
483 |
c1a38ba3
|
Leszek Koltunski
|
|
484 |
da681e7e
|
Leszek Koltunski
|
mesh.bindVertexAttribs(mMainOITProgram);
|
485 |
c1a38ba3
|
Leszek Koltunski
|
|
486 |
7a5e538a
|
Leszek Koltunski
|
float inflate = mesh.getInflate();
|
487 |
|
|
|
488 |
|
|
mM.send(surface,halfW,halfH,halfZ,1);
|
489 |
|
|
mV.send(inflate,1);
|
490 |
86c352e0
|
Leszek Koltunski
|
mF.send(1);
|
491 |
c1a38ba3
|
Leszek Koltunski
|
|
492 |
6c00149d
|
Leszek Koltunski
|
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() );
|
493 |
c1a38ba3
|
Leszek Koltunski
|
|
494 |
6c00149d
|
Leszek Koltunski
|
if( mesh.getShowNormals() )
|
495 |
99730f26
|
Leszek Koltunski
|
{
|
496 |
|
|
mMainProgram.useProgram();
|
497 |
7a5e538a
|
Leszek Koltunski
|
mM.send(surface,halfW,halfH,halfZ,0);
|
498 |
|
|
mV.send(inflate,0);
|
499 |
99730f26
|
Leszek Koltunski
|
mF.send(0);
|
500 |
|
|
displayNormals(mesh);
|
501 |
|
|
}
|
502 |
c1a38ba3
|
Leszek Koltunski
|
}
|
503 |
|
|
|
504 |
c90b9e01
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
505 |
|
|
|
506 |
715e7726
|
Leszek Koltunski
|
void drawPriv(float halfW, float halfH, MeshBase mesh, DistortedOutputSurface surface, long currTime)
|
507 |
d425545a
|
Leszek Koltunski
|
{
|
508 |
6c00149d
|
Leszek Koltunski
|
float halfZ = halfW*mesh.getZFactor();
|
509 |
638b5b5c
|
leszek
|
|
510 |
8fbd0237
|
Leszek Koltunski
|
mM.compute(currTime);
|
511 |
|
|
mV.compute(currTime,halfW,halfH,halfZ);
|
512 |
b24e4719
|
Leszek Koltunski
|
mF.compute(currTime,halfW,halfH,halfZ);
|
513 |
1149be8f
|
leszek
|
mP.compute(currTime);
|
514 |
8fbd0237
|
Leszek Koltunski
|
|
515 |
e6519ac8
|
Leszek Koltunski
|
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
516 |
d6e94c84
|
Leszek Koltunski
|
|
517 |
b9798977
|
leszek
|
mMainProgram.useProgram();
|
518 |
e6519ac8
|
Leszek Koltunski
|
GLES31.glUniform1i(mMainTextureH, 0);
|
519 |
12f45260
|
Leszek Koltunski
|
|
520 |
da681e7e
|
Leszek Koltunski
|
mesh.bindVertexAttribs(mMainProgram);
|
521 |
cab7c165
|
Leszek Koltunski
|
|
522 |
7a5e538a
|
Leszek Koltunski
|
mM.send(surface,halfW,halfH,halfZ,0);
|
523 |
|
|
mV.send( mesh.getInflate(),0);
|
524 |
86c352e0
|
Leszek Koltunski
|
mF.send(0);
|
525 |
42571056
|
Leszek Koltunski
|
|
526 |
6c00149d
|
Leszek Koltunski
|
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() );
|
527 |
c90b9e01
|
Leszek Koltunski
|
|
528 |
6c00149d
|
Leszek Koltunski
|
if( mesh.getShowNormals() ) displayNormals(mesh);
|
529 |
d425545a
|
Leszek Koltunski
|
}
|
530 |
6a06a912
|
Leszek Koltunski
|
|
531 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
532 |
7266d8ef
|
Leszek Koltunski
|
/**
|
533 |
|
|
* Only for use by the library itself.
|
534 |
|
|
*
|
535 |
|
|
* @y.exclude
|
536 |
|
|
*/
|
537 |
|
|
public static void blitPriv(DistortedOutputSurface surface)
|
538 |
d425545a
|
Leszek Koltunski
|
{
|
539 |
c1e24646
|
leszek
|
mBlitProgram.useProgram();
|
540 |
|
|
|
541 |
e6519ac8
|
Leszek Koltunski
|
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
542 |
|
|
GLES31.glUniform1i(mBlitTextureH, 0);
|
543 |
|
|
GLES31.glUniform1f( mBlitDepthH , 1.0f-surface.mNear);
|
544 |
|
|
GLES31.glVertexAttribPointer(mBlitProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
|
545 |
|
|
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
|
546 |
d425545a
|
Leszek Koltunski
|
}
|
547 |
7170e4eb
|
leszek
|
|
548 |
97020807
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
549 |
|
|
|
550 |
|
|
static void blitDepthPriv(DistortedOutputSurface surface, float corrW, float corrH)
|
551 |
|
|
{
|
552 |
|
|
mBlitDepthProgram.useProgram();
|
553 |
|
|
|
554 |
|
|
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
555 |
|
|
GLES31.glUniform1i(mBlitDepthTextureH, 0);
|
556 |
|
|
GLES31.glUniform1i(mBlitDepthDepthTextureH, 1);
|
557 |
|
|
GLES31.glUniform2f(mBlitDepthTexCorrH, corrW, corrH );
|
558 |
|
|
GLES31.glUniform1f( mBlitDepthDepthH , 1.0f-surface.mNear);
|
559 |
|
|
GLES31.glVertexAttribPointer(mBlitDepthProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
|
560 |
|
|
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
|
561 |
|
|
}
|
562 |
|
|
|
563 |
375b3950
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
564 |
|
|
|
565 |
12f9e4bb
|
Leszek Koltunski
|
private static int printPreviousBuffer()
|
566 |
375b3950
|
Leszek Koltunski
|
{
|
567 |
12f9e4bb
|
Leszek Koltunski
|
int counter = 0;
|
568 |
|
|
|
569 |
|
|
ByteBuffer atomicBuf = (ByteBuffer)GLES31.glMapBufferRange( GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, 4,
|
570 |
|
|
GLES31.GL_MAP_READ_BIT);
|
571 |
|
|
if( atomicBuf!=null )
|
572 |
|
|
{
|
573 |
|
|
IntBuffer atomicIntBuf = atomicBuf.order(ByteOrder.nativeOrder()).asIntBuffer();
|
574 |
|
|
counter = atomicIntBuf.get(0);
|
575 |
|
|
}
|
576 |
|
|
else
|
577 |
acb44099
|
Leszek Koltunski
|
{
|
578 |
12f9e4bb
|
Leszek Koltunski
|
android.util.Log.e("effects", "print: failed to map atomic buffer");
|
579 |
acb44099
|
Leszek Koltunski
|
}
|
580 |
|
|
|
581 |
12f9e4bb
|
Leszek Koltunski
|
GLES31.glUnmapBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER);
|
582 |
375b3950
|
Leszek Koltunski
|
|
583 |
12f9e4bb
|
Leszek Koltunski
|
return counter;
|
584 |
|
|
}
|
585 |
|
|
|
586 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
587 |
|
|
|
588 |
|
|
private static void zeroBuffer()
|
589 |
|
|
{
|
590 |
375b3950
|
Leszek Koltunski
|
ByteBuffer atomicBuf = (ByteBuffer)GLES31.glMapBufferRange( GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, 4,
|
591 |
12f9e4bb
|
Leszek Koltunski
|
GLES31.GL_MAP_WRITE_BIT|GLES31.GL_MAP_INVALIDATE_BUFFER_BIT);
|
592 |
375b3950
|
Leszek Koltunski
|
if( atomicBuf!=null )
|
593 |
|
|
{
|
594 |
|
|
IntBuffer atomicIntBuf = atomicBuf.order(ByteOrder.nativeOrder()).asIntBuffer();
|
595 |
c92d84ec
|
Leszek Koltunski
|
atomicIntBuf.put(0,0);
|
596 |
375b3950
|
Leszek Koltunski
|
}
|
597 |
|
|
else
|
598 |
|
|
{
|
599 |
12f9e4bb
|
Leszek Koltunski
|
android.util.Log.e("effects", "zero: failed to map atomic buffer");
|
600 |
375b3950
|
Leszek Koltunski
|
}
|
601 |
|
|
|
602 |
|
|
GLES31.glUnmapBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER);
|
603 |
12f9e4bb
|
Leszek Koltunski
|
}
|
604 |
|
|
|
605 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
606 |
|
|
// reset atomic counter to 0
|
607 |
|
|
|
608 |
|
|
static int zeroOutAtomic()
|
609 |
|
|
{
|
610 |
|
|
int counter = 0;
|
611 |
|
|
|
612 |
|
|
if( mAtomicCounter[0]<0 )
|
613 |
|
|
{
|
614 |
|
|
GLES31.glGenBuffers(Distorted.FBO_QUEUE_SIZE,mAtomicCounter,0);
|
615 |
|
|
|
616 |
|
|
for(int i=0; i<Distorted.FBO_QUEUE_SIZE; i++)
|
617 |
|
|
{
|
618 |
|
|
GLES31.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, mAtomicCounter[i]);
|
619 |
|
|
GLES31.glBufferData(GLES31.GL_ATOMIC_COUNTER_BUFFER, 4, null, GLES31.GL_DYNAMIC_DRAW);
|
620 |
|
|
zeroBuffer();
|
621 |
|
|
}
|
622 |
|
|
}
|
623 |
|
|
|
624 |
|
|
// reading the value of the buffer on every frame would slow down rendering by
|
625 |
|
|
// about 3%; doing it only once every 5 frames affects speed by less than 1%.
|
626 |
|
|
if( mCurrBuffer==0 )
|
627 |
|
|
{
|
628 |
|
|
GLES31.glBindBufferBase(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, mAtomicCounter[mCurrBuffer]);
|
629 |
|
|
counter = printPreviousBuffer();
|
630 |
|
|
}
|
631 |
|
|
|
632 |
|
|
if( ++mCurrBuffer>=Distorted.FBO_QUEUE_SIZE ) mCurrBuffer = 0;
|
633 |
|
|
|
634 |
|
|
GLES31.glBindBufferBase(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, mAtomicCounter[mCurrBuffer]);
|
635 |
|
|
zeroBuffer();
|
636 |
|
|
|
637 |
|
|
return counter;
|
638 |
375b3950
|
Leszek Koltunski
|
}
|
639 |
|
|
|
640 |
7170e4eb
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
641 |
56c6ca24
|
Leszek Koltunski
|
// Pass1 of the OIT algorithm. Clear per-pixel head-poiners.
|
642 |
|
|
|
643 |
12f9e4bb
|
Leszek Koltunski
|
static void oitClear(DistortedOutputSurface surface, int counter)
|
644 |
56c6ca24
|
Leszek Koltunski
|
{
|
645 |
acb44099
|
Leszek Koltunski
|
if( mLinkedListSSBO[0]<0 )
|
646 |
|
|
{
|
647 |
|
|
GLES31.glGenBuffers(1,mLinkedListSSBO,0);
|
648 |
12f9e4bb
|
Leszek Koltunski
|
|
649 |
|
|
int size = (int)(surface.mWidth*surface.mHeight*(3*mBufferSize+1)*4);
|
650 |
acb44099
|
Leszek Koltunski
|
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mLinkedListSSBO[0]);
|
651 |
|
|
GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, size, null, GLES31.GL_DYNAMIC_READ|GLES31.GL_DYNAMIC_DRAW);
|
652 |
12f9e4bb
|
Leszek Koltunski
|
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, 0);
|
653 |
|
|
|
654 |
acb44099
|
Leszek Koltunski
|
GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 1, mLinkedListSSBO[0]);
|
655 |
12f9e4bb
|
Leszek Koltunski
|
}
|
656 |
|
|
|
657 |
|
|
// See if we have overflown the SSBO in one of the previous frames.
|
658 |
|
|
// If yes, assume we need to make the SSBO larger.
|
659 |
|
|
float overflow = counter/(mBufferSize*surface.mWidth*surface.mHeight);
|
660 |
|
|
|
661 |
|
|
if( overflow>1.0f )
|
662 |
|
|
{
|
663 |
|
|
//android.util.Log.e("effects", "previous frame rendered "+counter+
|
664 |
|
|
// " fragments, but there was only "+(mBufferSize*surface.mWidth*surface.mHeight)+" space");
|
665 |
|
|
|
666 |
|
|
mBufferSize *= (int)(overflow+1.0f);
|
667 |
|
|
int size = (int)(surface.mWidth*surface.mHeight*(3*mBufferSize+1)*4);
|
668 |
|
|
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mLinkedListSSBO[0]);
|
669 |
|
|
GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, size, null, GLES31.GL_DYNAMIC_READ|GLES31.GL_DYNAMIC_DRAW);
|
670 |
acb44099
|
Leszek Koltunski
|
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, 0);
|
671 |
|
|
}
|
672 |
|
|
|
673 |
56c6ca24
|
Leszek Koltunski
|
mOITClearProgram.useProgram();
|
674 |
|
|
|
675 |
|
|
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
676 |
|
|
GLES31.glUniform2f(mOITClearTexCorrH, 1.0f, 1.0f ); // corrections do not really matter here - only present because of common vertex shader.
|
677 |
|
|
GLES31.glUniform1f( mOITClearDepthH , 1.0f); // likewise depth
|
678 |
344ac0e4
|
Leszek Koltunski
|
GLES31.glUniform2ui(mOITClearSizeH, surface.mWidth, surface.mHeight);
|
679 |
56c6ca24
|
Leszek Koltunski
|
GLES31.glVertexAttribPointer(mOITClearProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
|
680 |
|
|
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
|
681 |
|
|
}
|
682 |
|
|
|
683 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
684 |
|
|
// Pass2 of the OIT algorithm - build per-pixel linked lists.
|
685 |
7170e4eb
|
leszek
|
|
686 |
56c6ca24
|
Leszek Koltunski
|
static void oitBuild(DistortedOutputSurface surface, float corrW, float corrH)
|
687 |
7170e4eb
|
leszek
|
{
|
688 |
56c6ca24
|
Leszek Koltunski
|
mOITBuildProgram.useProgram();
|
689 |
7170e4eb
|
leszek
|
|
690 |
e6519ac8
|
Leszek Koltunski
|
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
691 |
56c6ca24
|
Leszek Koltunski
|
GLES31.glUniform1i(mOITBuildTextureH, 0);
|
692 |
|
|
GLES31.glUniform1i(mOITBuildDepthTextureH, 1);
|
693 |
|
|
GLES31.glUniform2f(mOITBuildTexCorrH, corrW, corrH );
|
694 |
344ac0e4
|
Leszek Koltunski
|
GLES31.glUniform2ui(mOITBuildSizeH, surface.mWidth, surface.mHeight);
|
695 |
acb44099
|
Leszek Koltunski
|
GLES31.glUniform1ui(mOITBuildNumRecordsH, (int)(mBufferSize*surface.mWidth*surface.mHeight) );
|
696 |
56c6ca24
|
Leszek Koltunski
|
GLES31.glUniform1f(mOITBuildDepthH , 1.0f-surface.mNear);
|
697 |
|
|
GLES31.glVertexAttribPointer(mOITBuildProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
|
698 |
e6519ac8
|
Leszek Koltunski
|
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
|
699 |
8777ce17
|
Leszek Koltunski
|
}
|
700 |
|
|
|
701 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
702 |
33f59f22
|
Leszek Koltunski
|
// Pass3 of the OIT algorithm. Cut occluded parts of the linked list.
|
703 |
|
|
|
704 |
|
|
static void oitCollapse(DistortedOutputSurface surface, float corrW, float corrH)
|
705 |
|
|
{
|
706 |
|
|
mOITCollapseProgram.useProgram();
|
707 |
|
|
|
708 |
|
|
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
709 |
|
|
GLES31.glUniform1i(mOITCollapseDepthTextureH, 1);
|
710 |
|
|
GLES31.glUniform2f(mOITCollapseTexCorrH, corrW, corrH );
|
711 |
344ac0e4
|
Leszek Koltunski
|
GLES31.glUniform2ui(mOITCollapseSizeH, surface.mWidth, surface.mHeight);
|
712 |
33f59f22
|
Leszek Koltunski
|
GLES31.glUniform1f( mOITCollapseDepthH , 1.0f-surface.mNear);
|
713 |
|
|
GLES31.glVertexAttribPointer(mOITCollapseProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
|
714 |
|
|
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
|
715 |
|
|
}
|
716 |
|
|
|
717 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
718 |
|
|
// Pass4 of the OIT algorithm. Render all the transparent pixels from the per-pixel linked lists.
|
719 |
8777ce17
|
Leszek Koltunski
|
|
720 |
56c6ca24
|
Leszek Koltunski
|
static void oitRender(DistortedOutputSurface surface, float corrW, float corrH)
|
721 |
8777ce17
|
Leszek Koltunski
|
{
|
722 |
56c6ca24
|
Leszek Koltunski
|
mOITRenderProgram.useProgram();
|
723 |
8777ce17
|
Leszek Koltunski
|
|
724 |
|
|
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
725 |
56c6ca24
|
Leszek Koltunski
|
GLES31.glUniform2f(mOITRenderTexCorrH, corrW, corrH );
|
726 |
344ac0e4
|
Leszek Koltunski
|
GLES31.glUniform2ui(mOITRenderSizeH, surface.mWidth, surface.mHeight);
|
727 |
56c6ca24
|
Leszek Koltunski
|
GLES31.glUniform1f( mOITRenderDepthH , 1.0f-surface.mNear);
|
728 |
|
|
GLES31.glVertexAttribPointer(mOITRenderProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
|
729 |
8777ce17
|
Leszek Koltunski
|
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
|
730 |
7170e4eb
|
leszek
|
}
|
731 |
|
|
|
732 |
cee0369a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
733 |
|
|
|
734 |
8e34674e
|
Leszek Koltunski
|
private void releasePriv()
|
735 |
d425545a
|
Leszek Koltunski
|
{
|
736 |
344ac0e4
|
Leszek Koltunski
|
if( !matrixCloned ) mM.abortAll(false);
|
737 |
|
|
if( !vertexCloned ) mV.abortAll(false);
|
738 |
|
|
if( !fragmentCloned ) mF.abortAll(false);
|
739 |
|
|
if( !postprocessCloned ) mP.abortAll(false);
|
740 |
d425545a
|
Leszek Koltunski
|
|
741 |
4e2382f3
|
Leszek Koltunski
|
mM = null;
|
742 |
|
|
mV = null;
|
743 |
|
|
mF = null;
|
744 |
80b3acf6
|
Leszek Koltunski
|
mP = null;
|
745 |
8e34674e
|
Leszek Koltunski
|
}
|
746 |
|
|
|
747 |
1942537e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
748 |
|
|
|
749 |
78e89fb5
|
Leszek Koltunski
|
static void onPause()
|
750 |
1942537e
|
Leszek Koltunski
|
{
|
751 |
8777ce17
|
Leszek Koltunski
|
mLinkedListSSBO[0]= -1;
|
752 |
12f9e4bb
|
Leszek Koltunski
|
|
753 |
|
|
for(int i=0; i<Distorted.FBO_QUEUE_SIZE; i++) mAtomicCounter[i] = -1;
|
754 |
1942537e
|
Leszek Koltunski
|
}
|
755 |
|
|
|
756 |
78e89fb5
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
757 |
|
|
|
758 |
|
|
static void onDestroy()
|
759 |
|
|
{
|
760 |
|
|
mNextID = 0;
|
761 |
|
|
}
|
762 |
|
|
|
763 |
12f9e4bb
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
764 |
|
|
|
765 |
|
|
static void setSSBOSize(float size)
|
766 |
|
|
{
|
767 |
|
|
mBufferSize = size;
|
768 |
|
|
}
|
769 |
|
|
|
770 |
8e34674e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
771 |
|
|
// PUBLIC API
|
772 |
ada90d33
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
773 |
d425545a
|
Leszek Koltunski
|
/**
|
774 |
4e2382f3
|
Leszek Koltunski
|
* Create empty effect queue.
|
775 |
d425545a
|
Leszek Koltunski
|
*/
|
776 |
421c2728
|
Leszek Koltunski
|
public DistortedEffects()
|
777 |
d425545a
|
Leszek Koltunski
|
{
|
778 |
c7da4e65
|
leszek
|
mID = ++mNextID;
|
779 |
4e2382f3
|
Leszek Koltunski
|
initializeEffectLists(this,0);
|
780 |
d425545a
|
Leszek Koltunski
|
}
|
781 |
ada90d33
|
Leszek Koltunski
|
|
782 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
783 |
d425545a
|
Leszek Koltunski
|
/**
|
784 |
4e2382f3
|
Leszek Koltunski
|
* Copy constructor.
|
785 |
d425545a
|
Leszek Koltunski
|
* <p>
|
786 |
|
|
* Whatever we do not clone gets created just like in the default constructor.
|
787 |
|
|
*
|
788 |
|
|
* @param dc Source object to create our object from
|
789 |
|
|
* @param flags A bitmask of values specifying what to copy.
|
790 |
e6ab30eb
|
Leszek Koltunski
|
* For example, CLONE_VERTEX | CLONE_MATRIX.
|
791 |
d425545a
|
Leszek Koltunski
|
*/
|
792 |
421c2728
|
Leszek Koltunski
|
public DistortedEffects(DistortedEffects dc, int flags)
|
793 |
d425545a
|
Leszek Koltunski
|
{
|
794 |
c7da4e65
|
leszek
|
mID = ++mNextID;
|
795 |
4e2382f3
|
Leszek Koltunski
|
initializeEffectLists(dc,flags);
|
796 |
d425545a
|
Leszek Koltunski
|
}
|
797 |
ada90d33
|
Leszek Koltunski
|
|
798 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
799 |
|
|
/**
|
800 |
07305c87
|
Leszek Koltunski
|
* Releases all resources. After this call, the queue should not be used anymore.
|
801 |
6a06a912
|
Leszek Koltunski
|
*/
|
802 |
13687207
|
leszek
|
@SuppressWarnings("unused")
|
803 |
8e34674e
|
Leszek Koltunski
|
public synchronized void delete()
|
804 |
d425545a
|
Leszek Koltunski
|
{
|
805 |
|
|
releasePriv();
|
806 |
|
|
}
|
807 |
6a06a912
|
Leszek Koltunski
|
|
808 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
809 |
|
|
/**
|
810 |
4e2382f3
|
Leszek Koltunski
|
* Returns unique ID of this instance.
|
811 |
|
|
*
|
812 |
|
|
* @return ID of the object.
|
813 |
6a06a912
|
Leszek Koltunski
|
*/
|
814 |
4e2382f3
|
Leszek Koltunski
|
public long getID()
|
815 |
d425545a
|
Leszek Koltunski
|
{
|
816 |
4e2382f3
|
Leszek Koltunski
|
return mID;
|
817 |
d425545a
|
Leszek Koltunski
|
}
|
818 |
4e2382f3
|
Leszek Koltunski
|
|
819 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
820 |
|
|
/**
|
821 |
|
|
* Adds the calling class to the list of Listeners that get notified each time some event happens
|
822 |
faa3ff56
|
Leszek Koltunski
|
* to one of the Effects in our queues. Nothing will happen if 'el' is already in the list.
|
823 |
6a06a912
|
Leszek Koltunski
|
*
|
824 |
|
|
* @param el A class implementing the EffectListener interface that wants to get notifications.
|
825 |
|
|
*/
|
826 |
13687207
|
leszek
|
@SuppressWarnings("unused")
|
827 |
3fc994b2
|
Leszek Koltunski
|
public void registerForMessages(EffectListener el)
|
828 |
d425545a
|
Leszek Koltunski
|
{
|
829 |
26a4e5f6
|
leszek
|
mM.registerForMessages(el);
|
830 |
3fc994b2
|
Leszek Koltunski
|
mV.registerForMessages(el);
|
831 |
|
|
mF.registerForMessages(el);
|
832 |
80b3acf6
|
Leszek Koltunski
|
mP.registerForMessages(el);
|
833 |
d425545a
|
Leszek Koltunski
|
}
|
834 |
6a06a912
|
Leszek Koltunski
|
|
835 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
836 |
|
|
/**
|
837 |
faa3ff56
|
Leszek Koltunski
|
* Removes the calling class from the list of Listeners that get notified if something happens to Effects in our queue.
|
838 |
6a06a912
|
Leszek Koltunski
|
*
|
839 |
|
|
* @param el A class implementing the EffectListener interface that no longer wants to get notifications.
|
840 |
|
|
*/
|
841 |
13687207
|
leszek
|
@SuppressWarnings("unused")
|
842 |
3fc994b2
|
Leszek Koltunski
|
public void deregisterForMessages(EffectListener el)
|
843 |
d425545a
|
Leszek Koltunski
|
{
|
844 |
26a4e5f6
|
leszek
|
mM.deregisterForMessages(el);
|
845 |
3fc994b2
|
Leszek Koltunski
|
mV.deregisterForMessages(el);
|
846 |
|
|
mF.deregisterForMessages(el);
|
847 |
80b3acf6
|
Leszek Koltunski
|
mP.deregisterForMessages(el);
|
848 |
d425545a
|
Leszek Koltunski
|
}
|
849 |
6a06a912
|
Leszek Koltunski
|
|
850 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
851 |
|
|
/**
|
852 |
d07f2950
|
Leszek Koltunski
|
* Aborts all Effects.
|
853 |
|
|
* @return Number of effects aborted.
|
854 |
6a06a912
|
Leszek Koltunski
|
*/
|
855 |
d425545a
|
Leszek Koltunski
|
public int abortAllEffects()
|
856 |
13687207
|
leszek
|
{
|
857 |
|
|
return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true);
|
858 |
|
|
}
|
859 |
6a06a912
|
Leszek Koltunski
|
|
860 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
861 |
|
|
/**
|
862 |
d07f2950
|
Leszek Koltunski
|
* Aborts all Effects of a given type, for example all MATRIX Effects.
|
863 |
6a06a912
|
Leszek Koltunski
|
*
|
864 |
da9b3f07
|
Leszek Koltunski
|
* @param type one of the constants defined in {@link EffectType}
|
865 |
d07f2950
|
Leszek Koltunski
|
* @return Number of effects aborted.
|
866 |
6a06a912
|
Leszek Koltunski
|
*/
|
867 |
da9b3f07
|
Leszek Koltunski
|
public int abortByType(EffectType type)
|
868 |
d425545a
|
Leszek Koltunski
|
{
|
869 |
|
|
switch(type)
|
870 |
6a06a912
|
Leszek Koltunski
|
{
|
871 |
da9b3f07
|
Leszek Koltunski
|
case MATRIX : return mM.abortAll(true);
|
872 |
|
|
case VERTEX : return mV.abortAll(true);
|
873 |
|
|
case FRAGMENT : return mF.abortAll(true);
|
874 |
80b3acf6
|
Leszek Koltunski
|
case POSTPROCESS: return mP.abortAll(true);
|
875 |
da9b3f07
|
Leszek Koltunski
|
default : return 0;
|
876 |
6a06a912
|
Leszek Koltunski
|
}
|
877 |
d425545a
|
Leszek Koltunski
|
}
|
878 |
47316d20
|
leszek
|
|
879 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
880 |
|
|
/**
|
881 |
faa3ff56
|
Leszek Koltunski
|
* Aborts an Effect by its ID.
|
882 |
47316d20
|
leszek
|
*
|
883 |
|
|
* @param id the Id of the Effect to be removed, as returned by getID().
|
884 |
|
|
* @return Number of effects aborted.
|
885 |
|
|
*/
|
886 |
|
|
public int abortById(long id)
|
887 |
|
|
{
|
888 |
|
|
long type = id&EffectType.MASK;
|
889 |
|
|
|
890 |
2ef5dd9e
|
leszek
|
if( type == EffectType.MATRIX.ordinal() ) return mM.removeById(id);
|
891 |
|
|
if( type == EffectType.VERTEX.ordinal() ) return mV.removeById(id);
|
892 |
|
|
if( type == EffectType.FRAGMENT.ordinal() ) return mF.removeById(id);
|
893 |
80b3acf6
|
Leszek Koltunski
|
if( type == EffectType.POSTPROCESS.ordinal() ) return mP.removeById(id);
|
894 |
47316d20
|
leszek
|
|
895 |
|
|
return 0;
|
896 |
|
|
}
|
897 |
|
|
|
898 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
899 |
|
|
/**
|
900 |
|
|
* Aborts a single Effect.
|
901 |
|
|
*
|
902 |
6bb59aad
|
Leszek Koltunski
|
* @param effect the Effect we want to abort.
|
903 |
476bbc81
|
Leszek Koltunski
|
* @return number of Effects aborted. Always either 0 or 1.
|
904 |
6a06a912
|
Leszek Koltunski
|
*/
|
905 |
6bb59aad
|
Leszek Koltunski
|
public int abortEffect(Effect effect)
|
906 |
d425545a
|
Leszek Koltunski
|
{
|
907 |
6bb59aad
|
Leszek Koltunski
|
switch(effect.getType())
|
908 |
|
|
{
|
909 |
da9b3f07
|
Leszek Koltunski
|
case MATRIX : return mM.removeEffect(effect);
|
910 |
|
|
case VERTEX : return mV.removeEffect(effect);
|
911 |
|
|
case FRAGMENT : return mF.removeEffect(effect);
|
912 |
80b3acf6
|
Leszek Koltunski
|
case POSTPROCESS: return mP.removeEffect(effect);
|
913 |
da9b3f07
|
Leszek Koltunski
|
default : return 0;
|
914 |
6bb59aad
|
Leszek Koltunski
|
}
|
915 |
d425545a
|
Leszek Koltunski
|
}
|
916 |
6a06a912
|
Leszek Koltunski
|
|
917 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
918 |
|
|
/**
|
919 |
e8c81a8e
|
Leszek Koltunski
|
* Abort all Effects of a given name, for example all rotations.
|
920 |
6a06a912
|
Leszek Koltunski
|
*
|
921 |
da9b3f07
|
Leszek Koltunski
|
* @param name one of the constants defined in {@link EffectName}
|
922 |
476bbc81
|
Leszek Koltunski
|
* @return number of Effects aborted.
|
923 |
6a06a912
|
Leszek Koltunski
|
*/
|
924 |
da9b3f07
|
Leszek Koltunski
|
public int abortByName(EffectName name)
|
925 |
d425545a
|
Leszek Koltunski
|
{
|
926 |
da9b3f07
|
Leszek Koltunski
|
switch(name.getType())
|
927 |
6a06a912
|
Leszek Koltunski
|
{
|
928 |
da9b3f07
|
Leszek Koltunski
|
case MATRIX : return mM.removeByName(name);
|
929 |
|
|
case VERTEX : return mV.removeByName(name);
|
930 |
|
|
case FRAGMENT : return mF.removeByName(name);
|
931 |
80b3acf6
|
Leszek Koltunski
|
case POSTPROCESS: return mP.removeByName(name);
|
932 |
6bb59aad
|
Leszek Koltunski
|
default : return 0;
|
933 |
6a06a912
|
Leszek Koltunski
|
}
|
934 |
d425545a
|
Leszek Koltunski
|
}
|
935 |
432442f9
|
Leszek Koltunski
|
|
936 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
937 |
|
|
/**
|
938 |
faa3ff56
|
Leszek Koltunski
|
* Returns the maximum number of effects of a given type that can be simultaneously applied to a
|
939 |
715e7726
|
Leszek Koltunski
|
* single (InputSurface,MeshBase) combo.
|
940 |
432442f9
|
Leszek Koltunski
|
*
|
941 |
fe6fe99a
|
leszek
|
* @param type {@link EffectType}
|
942 |
|
|
* @return The maximum number of effects of a given type.
|
943 |
432442f9
|
Leszek Koltunski
|
*/
|
944 |
13687207
|
leszek
|
@SuppressWarnings("unused")
|
945 |
fe6fe99a
|
leszek
|
public static int getMax(EffectType type)
|
946 |
432442f9
|
Leszek Koltunski
|
{
|
947 |
fe6fe99a
|
leszek
|
return EffectQueue.getMax(type.ordinal());
|
948 |
432442f9
|
Leszek Koltunski
|
}
|
949 |
|
|
|
950 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
951 |
|
|
/**
|
952 |
fe6fe99a
|
leszek
|
* Sets the maximum number of effects that can be stored in a single EffectQueue at one time.
|
953 |
432442f9
|
Leszek Koltunski
|
* This can fail if:
|
954 |
|
|
* <ul>
|
955 |
|
|
* <li>the value of 'max' is outside permitted range (0 ≤ max ≤ Byte.MAX_VALUE)
|
956 |
|
|
* <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
|
957 |
|
|
* before the Vertex Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
|
958 |
|
|
* time only decreasing the value of 'max' is permitted.
|
959 |
|
|
* <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
|
960 |
|
|
* </ul>
|
961 |
|
|
*
|
962 |
fe6fe99a
|
leszek
|
* @param type {@link EffectType}
|
963 |
|
|
* @param max new maximum number of simultaneous effects. Has to be a non-negative number not greater
|
964 |
80b3acf6
|
Leszek Koltunski
|
* than Byte.MAX_VALUE
|
965 |
|
|
* @return <code>true</code> if operation was successful, <code>false</code> otherwise.
|
966 |
|
|
*/
|
967 |
|
|
@SuppressWarnings("unused")
|
968 |
fe6fe99a
|
leszek
|
public static boolean setMax(EffectType type, int max)
|
969 |
80b3acf6
|
Leszek Koltunski
|
{
|
970 |
fe6fe99a
|
leszek
|
return EffectQueue.setMax(type.ordinal(),max);
|
971 |
80b3acf6
|
Leszek Koltunski
|
}
|
972 |
|
|
|
973 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
974 |
|
|
/**
|
975 |
6bb59aad
|
Leszek Koltunski
|
* Add a new Effect to our queue.
|
976 |
f2fe7e28
|
Leszek Koltunski
|
*
|
977 |
6bb59aad
|
Leszek Koltunski
|
* @param effect The Effect to add.
|
978 |
ae77d55e
|
Leszek Koltunski
|
* @return <code>true</code> if operation was successful, <code>false</code> otherwise.
|
979 |
6a06a912
|
Leszek Koltunski
|
*/
|
980 |
ae77d55e
|
Leszek Koltunski
|
public boolean apply(Effect effect)
|
981 |
d425545a
|
Leszek Koltunski
|
{
|
982 |
6bb59aad
|
Leszek Koltunski
|
switch(effect.getType())
|
983 |
|
|
{
|
984 |
26a4e5f6
|
leszek
|
case MATRIX : return mM.add(effect);
|
985 |
ae77d55e
|
Leszek Koltunski
|
case VERTEX : return mV.add(effect);
|
986 |
|
|
case FRAGMENT : return mF.add(effect);
|
987 |
80b3acf6
|
Leszek Koltunski
|
case POSTPROCESS : return mP.add(effect);
|
988 |
6bb59aad
|
Leszek Koltunski
|
}
|
989 |
ae77d55e
|
Leszek Koltunski
|
|
990 |
|
|
return false;
|
991 |
4fde55a0
|
Leszek Koltunski
|
}
|
992 |
f2fe7e28
|
Leszek Koltunski
|
}
|