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 |
e458a4ba
|
Leszek Koltunski
|
import org.distorted.library.message.EffectListener;
|
33 |
55c14a19
|
Leszek Koltunski
|
import org.distorted.library.program.DistortedProgram;
|
34 |
a4835695
|
Leszek Koltunski
|
|
35 |
c90b9e01
|
Leszek Koltunski
|
import java.io.InputStream;
|
36 |
c638c1b0
|
Leszek Koltunski
|
import java.nio.ByteBuffer;
|
37 |
|
|
import java.nio.ByteOrder;
|
38 |
|
|
import java.nio.FloatBuffer;
|
39 |
8777ce17
|
Leszek Koltunski
|
import java.nio.IntBuffer;
|
40 |
c638c1b0
|
Leszek Koltunski
|
|
41 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42 |
b329f352
|
Leszek Koltunski
|
/**
|
43 |
faa3ff56
|
Leszek Koltunski
|
* Class containing Matrix, Vertex, Fragment and Postprocessing effect queues.
|
44 |
b73dcaa7
|
Leszek Koltunski
|
* <p>
|
45 |
faa3ff56
|
Leszek Koltunski
|
* The queues hold actual effects to be applied to a given (InputSurface,MeshObject) combo.
|
46 |
b329f352
|
Leszek Koltunski
|
*/
|
47 |
86d322b5
|
Leszek Koltunski
|
public class DistortedEffects
|
48 |
d425545a
|
Leszek Koltunski
|
{
|
49 |
1aedf874
|
leszek
|
/// MAIN PROGRAM ///
|
50 |
|
|
private static DistortedProgram mMainProgram;
|
51 |
|
|
private static int mMainTextureH;
|
52 |
8fa96e69
|
Leszek Koltunski
|
|
53 |
c1e24646
|
leszek
|
/// BLIT PROGRAM ///
|
54 |
|
|
private static DistortedProgram mBlitProgram;
|
55 |
|
|
private static int mBlitTextureH;
|
56 |
c2c08950
|
leszek
|
private static int mBlitDepthH;
|
57 |
c90b9e01
|
Leszek Koltunski
|
private static final FloatBuffer mQuadPositions;
|
58 |
|
|
|
59 |
|
|
static
|
60 |
|
|
{
|
61 |
|
|
float[] positionData= { -0.5f, -0.5f, -0.5f, 0.5f, 0.5f,-0.5f, 0.5f, 0.5f };
|
62 |
|
|
mQuadPositions = ByteBuffer.allocateDirect(32).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
63 |
|
|
mQuadPositions.put(positionData).position(0);
|
64 |
|
|
}
|
65 |
|
|
|
66 |
33f59f22
|
Leszek Koltunski
|
/// OIT SSBO BUFFER ///
|
67 |
|
|
private static int[] mLinkedListSSBO = new int[1];
|
68 |
|
|
private static int[] mAtomicCounter = new int[1];
|
69 |
|
|
|
70 |
|
|
static
|
71 |
|
|
{
|
72 |
|
|
mLinkedListSSBO[0]= -1;
|
73 |
|
|
mAtomicCounter[0] = -1;
|
74 |
|
|
}
|
75 |
|
|
|
76 |
344ac0e4
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////
|
77 |
|
|
// this has to be at least as big as the number of pixels in
|
78 |
|
|
// the screen, lest the oitClear() pass overwrite memory.
|
79 |
33f59f22
|
Leszek Koltunski
|
private static int mBufferSize=(0x1<<23); // 8 million entries
|
80 |
|
|
|
81 |
56c6ca24
|
Leszek Koltunski
|
/// OIT CLEAR PROGRAM ///
|
82 |
|
|
private static DistortedProgram mOITClearProgram;
|
83 |
|
|
private static int mOITClearDepthH;
|
84 |
|
|
private static int mOITClearTexCorrH;
|
85 |
|
|
private static int mOITClearSizeH;
|
86 |
|
|
|
87 |
|
|
/// OIT BUILD PROGRAM ///
|
88 |
|
|
private static DistortedProgram mOITBuildProgram;
|
89 |
|
|
private static int mOITBuildTextureH;
|
90 |
|
|
private static int mOITBuildDepthTextureH;
|
91 |
|
|
private static int mOITBuildDepthH;
|
92 |
|
|
private static int mOITBuildTexCorrH;
|
93 |
|
|
private static int mOITBuildSizeH;
|
94 |
|
|
private static int mOITBuildNumRecordsH;
|
95 |
8777ce17
|
Leszek Koltunski
|
|
96 |
33f59f22
|
Leszek Koltunski
|
/// OIT COLLAPSE PROGRAM ///
|
97 |
|
|
private static DistortedProgram mOITCollapseProgram;
|
98 |
|
|
private static int mOITCollapseDepthTextureH;
|
99 |
|
|
private static int mOITCollapseDepthH;
|
100 |
|
|
private static int mOITCollapseTexCorrH;
|
101 |
|
|
private static int mOITCollapseSizeH;
|
102 |
cee0369a
|
Leszek Koltunski
|
|
103 |
56c6ca24
|
Leszek Koltunski
|
/// OIT RENDER PROGRAM ///
|
104 |
|
|
private static DistortedProgram mOITRenderProgram;
|
105 |
|
|
private static int mOITRenderDepthH;
|
106 |
|
|
private static int mOITRenderTexCorrH;
|
107 |
|
|
private static int mOITRenderSizeH;
|
108 |
7170e4eb
|
leszek
|
|
109 |
3fc9327a
|
Leszek Koltunski
|
/// NORMAL PROGRAM /////
|
110 |
|
|
private static DistortedProgram mNormalProgram;
|
111 |
|
|
private static int mNormalMVPMatrixH;
|
112 |
|
|
/// END PROGRAMS //////
|
113 |
c638c1b0
|
Leszek Koltunski
|
|
114 |
8e34674e
|
Leszek Koltunski
|
private static long mNextID =0;
|
115 |
4e2382f3
|
Leszek Koltunski
|
private long mID;
|
116 |
8e34674e
|
Leszek Koltunski
|
|
117 |
310e14fb
|
leszek
|
private EffectQueueMatrix mM;
|
118 |
3fc9327a
|
Leszek Koltunski
|
private EffectQueueFragment mF;
|
119 |
310e14fb
|
leszek
|
private EffectQueueVertex mV;
|
120 |
80b3acf6
|
Leszek Koltunski
|
private EffectQueuePostprocess mP;
|
121 |
|
|
|
122 |
|
|
private boolean matrixCloned, vertexCloned, fragmentCloned, postprocessCloned;
|
123 |
3d590d8d
|
Leszek Koltunski
|
|
124 |
9361b337
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
125 |
55c14a19
|
Leszek Koltunski
|
|
126 |
c90b9e01
|
Leszek Koltunski
|
static void createProgram(Resources resources)
|
127 |
55c14a19
|
Leszek Koltunski
|
{
|
128 |
cab7c165
|
Leszek Koltunski
|
// MAIN PROGRAM ////////////////////////////////////
|
129 |
1aedf874
|
leszek
|
final InputStream mainVertStream = resources.openRawResource(R.raw.main_vertex_shader);
|
130 |
|
|
final InputStream mainFragStream = resources.openRawResource(R.raw.main_fragment_shader);
|
131 |
|
|
|
132 |
7cd24173
|
leszek
|
int numF = FragmentEffect.getNumEnabled();
|
133 |
|
|
int numV = VertexEffect.getNumEnabled();
|
134 |
c90b9e01
|
Leszek Koltunski
|
|
135 |
7cd24173
|
leszek
|
String mainVertHeader= Distorted.GLSL_VERSION + ("#define NUM_VERTEX " + ( numV>0 ? getMax(EffectType.VERTEX ) : 0 ) + "\n");
|
136 |
|
|
String mainFragHeader= Distorted.GLSL_VERSION + ("#define NUM_FRAGMENT " + ( numF>0 ? getMax(EffectType.FRAGMENT) : 0 ) + "\n");
|
137 |
|
|
String enabledEffectV= VertexEffect.getGLSL();
|
138 |
|
|
String enabledEffectF= FragmentEffect.getGLSL();
|
139 |
c90b9e01
|
Leszek Koltunski
|
|
140 |
03cb451d
|
Leszek Koltunski
|
//android.util.Log.e("Effects", "vertHeader= "+mainVertHeader);
|
141 |
|
|
//android.util.Log.e("Effects", "fragHeader= "+mainFragHeader);
|
142 |
7cd24173
|
leszek
|
//android.util.Log.e("Effects", "enabledV= "+enabledEffectV);
|
143 |
|
|
//android.util.Log.e("Effects", "enabledF= "+enabledEffectF);
|
144 |
c90b9e01
|
Leszek Koltunski
|
|
145 |
3fc9327a
|
Leszek Koltunski
|
String[] feedback = { "v_Position", "v_endPosition" };
|
146 |
cab7c165
|
Leszek Koltunski
|
|
147 |
cee0369a
|
Leszek Koltunski
|
try
|
148 |
|
|
{
|
149 |
|
|
mMainProgram = new DistortedProgram(mainVertStream, mainFragStream, mainVertHeader, mainFragHeader,
|
150 |
|
|
enabledEffectV, enabledEffectF, Distorted.GLSL, feedback);
|
151 |
|
|
}
|
152 |
|
|
catch(Exception e)
|
153 |
|
|
{
|
154 |
|
|
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile MAIN program: "+e.getMessage());
|
155 |
|
|
throw new RuntimeException(e.getMessage());
|
156 |
|
|
}
|
157 |
c90b9e01
|
Leszek Koltunski
|
|
158 |
c1e24646
|
leszek
|
int mainProgramH = mMainProgram.getProgramHandle();
|
159 |
c90b9e01
|
Leszek Koltunski
|
EffectQueueFragment.getUniforms(mainProgramH);
|
160 |
1aedf874
|
leszek
|
EffectQueueVertex.getUniforms(mainProgramH);
|
161 |
|
|
EffectQueueMatrix.getUniforms(mainProgramH);
|
162 |
e6519ac8
|
Leszek Koltunski
|
mMainTextureH= GLES31.glGetUniformLocation( mainProgramH, "u_Texture");
|
163 |
c1e24646
|
leszek
|
|
164 |
1aedf874
|
leszek
|
// BLIT PROGRAM ////////////////////////////////////
|
165 |
c1e24646
|
leszek
|
final InputStream blitVertStream = resources.openRawResource(R.raw.blit_vertex_shader);
|
166 |
|
|
final InputStream blitFragStream = resources.openRawResource(R.raw.blit_fragment_shader);
|
167 |
|
|
|
168 |
f2367b75
|
Leszek Koltunski
|
try
|
169 |
|
|
{
|
170 |
56c6ca24
|
Leszek Koltunski
|
mBlitProgram = new DistortedProgram(blitVertStream,blitFragStream,Distorted.GLSL_VERSION,Distorted.GLSL_VERSION, Distorted.GLSL);
|
171 |
f2367b75
|
Leszek Koltunski
|
}
|
172 |
|
|
catch(Exception e)
|
173 |
|
|
{
|
174 |
cee0369a
|
Leszek Koltunski
|
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile BLIT program: "+e.getMessage());
|
175 |
f2367b75
|
Leszek Koltunski
|
throw new RuntimeException(e.getMessage());
|
176 |
|
|
}
|
177 |
c1e24646
|
leszek
|
|
178 |
|
|
int blitProgramH = mBlitProgram.getProgramHandle();
|
179 |
e6519ac8
|
Leszek Koltunski
|
mBlitTextureH = GLES31.glGetUniformLocation( blitProgramH, "u_Texture");
|
180 |
|
|
mBlitDepthH = GLES31.glGetUniformLocation( blitProgramH, "u_Depth");
|
181 |
c90b9e01
|
Leszek Koltunski
|
|
182 |
56c6ca24
|
Leszek Koltunski
|
// OIT CLEAR PROGRAM ////////////////////////////////////
|
183 |
|
|
final InputStream oitClearVertStream = resources.openRawResource(R.raw.oit_vertex_shader);
|
184 |
|
|
final InputStream oitClearFragStream = resources.openRawResource(R.raw.oit_clear_fragment_shader);
|
185 |
7170e4eb
|
leszek
|
|
186 |
|
|
try
|
187 |
|
|
{
|
188 |
56c6ca24
|
Leszek Koltunski
|
mOITClearProgram = new DistortedProgram(oitClearVertStream,oitClearFragStream,Distorted.GLSL_VERSION,Distorted.GLSL_VERSION, Distorted.GLSL);
|
189 |
7170e4eb
|
leszek
|
}
|
190 |
|
|
catch(Exception e)
|
191 |
|
|
{
|
192 |
56c6ca24
|
Leszek Koltunski
|
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile OIT CLEAR program: "+e.getMessage());
|
193 |
7170e4eb
|
leszek
|
throw new RuntimeException(e.getMessage());
|
194 |
|
|
}
|
195 |
|
|
|
196 |
56c6ca24
|
Leszek Koltunski
|
int oitClearProgramH = mOITClearProgram.getProgramHandle();
|
197 |
|
|
mOITClearDepthH = GLES31.glGetUniformLocation( oitClearProgramH, "u_Depth");
|
198 |
|
|
mOITClearTexCorrH = GLES31.glGetUniformLocation( oitClearProgramH, "u_TexCorr");
|
199 |
|
|
mOITClearSizeH = GLES31.glGetUniformLocation( oitClearProgramH, "u_Size");
|
200 |
|
|
|
201 |
|
|
// OIT BUILD PROGRAM ////////////////////////////////////
|
202 |
|
|
final InputStream oitBuildVertStream = resources.openRawResource(R.raw.oit_vertex_shader);
|
203 |
|
|
final InputStream oitBuildFragStream = resources.openRawResource(R.raw.oit_build_fragment_shader);
|
204 |
|
|
|
205 |
|
|
try
|
206 |
|
|
{
|
207 |
|
|
mOITBuildProgram = new DistortedProgram(oitBuildVertStream,oitBuildFragStream,Distorted.GLSL_VERSION,Distorted.GLSL_VERSION, Distorted.GLSL);
|
208 |
|
|
}
|
209 |
|
|
catch(Exception e)
|
210 |
|
|
{
|
211 |
|
|
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile OIT BUILD program: "+e.getMessage());
|
212 |
|
|
throw new RuntimeException(e.getMessage());
|
213 |
|
|
}
|
214 |
|
|
|
215 |
|
|
int oitBuildProgramH = mOITBuildProgram.getProgramHandle();
|
216 |
|
|
mOITBuildTextureH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_Texture");
|
217 |
|
|
mOITBuildDepthTextureH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_DepthTexture");
|
218 |
|
|
mOITBuildDepthH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_Depth");
|
219 |
|
|
mOITBuildTexCorrH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_TexCorr");
|
220 |
|
|
mOITBuildSizeH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_Size");
|
221 |
|
|
mOITBuildNumRecordsH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_numRecords");
|
222 |
8777ce17
|
Leszek Koltunski
|
|
223 |
|
|
if( mLinkedListSSBO[0]<0 )
|
224 |
|
|
{
|
225 |
|
|
GLES31.glGenBuffers(1,mLinkedListSSBO,0);
|
226 |
|
|
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mLinkedListSSBO[0]);
|
227 |
cee0369a
|
Leszek Koltunski
|
GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, mBufferSize*4 , null, GLES31.GL_DYNAMIC_READ|GLES31.GL_DYNAMIC_DRAW);
|
228 |
344ac0e4
|
Leszek Koltunski
|
GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 1, mLinkedListSSBO[0]);
|
229 |
c731c612
|
Leszek Koltunski
|
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, 0);
|
230 |
8777ce17
|
Leszek Koltunski
|
}
|
231 |
|
|
|
232 |
|
|
if( mAtomicCounter[0]<0 )
|
233 |
|
|
{
|
234 |
|
|
GLES31.glGenBuffers(1,mAtomicCounter,0);
|
235 |
c731c612
|
Leszek Koltunski
|
GLES31.glBindBufferBase(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, mAtomicCounter[0]);
|
236 |
8777ce17
|
Leszek Koltunski
|
GLES31.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, mAtomicCounter[0] );
|
237 |
375b3950
|
Leszek Koltunski
|
GLES31.glBufferData(GLES31.GL_ATOMIC_COUNTER_BUFFER, 4, null, GLES31.GL_DYNAMIC_DRAW);
|
238 |
8777ce17
|
Leszek Koltunski
|
GLES31.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0);
|
239 |
|
|
}
|
240 |
|
|
|
241 |
33f59f22
|
Leszek Koltunski
|
// OIT COLLAPSE PROGRAM ///////////////////////////
|
242 |
|
|
final InputStream oitCollapseVertStream = resources.openRawResource(R.raw.oit_vertex_shader);
|
243 |
|
|
final InputStream oitCollapseFragStream = resources.openRawResource(R.raw.oit_collapse_fragment_shader);
|
244 |
|
|
|
245 |
|
|
try
|
246 |
|
|
{
|
247 |
|
|
mOITCollapseProgram = new DistortedProgram(oitCollapseVertStream,oitCollapseFragStream,Distorted.GLSL_VERSION,Distorted.GLSL_VERSION, Distorted.GLSL);
|
248 |
|
|
}
|
249 |
|
|
catch(Exception e)
|
250 |
|
|
{
|
251 |
|
|
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile OIT COLLAPSE program: "+e.getMessage());
|
252 |
|
|
throw new RuntimeException(e.getMessage());
|
253 |
|
|
}
|
254 |
|
|
|
255 |
|
|
int oitCollapseProgramH = mOITCollapseProgram.getProgramHandle();
|
256 |
|
|
mOITCollapseDepthTextureH = GLES31.glGetUniformLocation( oitCollapseProgramH, "u_DepthTexture");
|
257 |
|
|
mOITCollapseDepthH = GLES31.glGetUniformLocation( oitCollapseProgramH, "u_Depth");
|
258 |
|
|
mOITCollapseTexCorrH = GLES31.glGetUniformLocation( oitCollapseProgramH, "u_TexCorr");
|
259 |
|
|
mOITCollapseSizeH = GLES31.glGetUniformLocation( oitCollapseProgramH, "u_Size");
|
260 |
|
|
|
261 |
|
|
// OIT RENDER PROGRAM ///////////////////////////
|
262 |
56c6ca24
|
Leszek Koltunski
|
final InputStream oitRenderVertStream = resources.openRawResource(R.raw.oit_vertex_shader);
|
263 |
|
|
final InputStream oitRenderFragStream = resources.openRawResource(R.raw.oit_render_fragment_shader);
|
264 |
8777ce17
|
Leszek Koltunski
|
|
265 |
|
|
try
|
266 |
|
|
{
|
267 |
56c6ca24
|
Leszek Koltunski
|
mOITRenderProgram = new DistortedProgram(oitRenderVertStream,oitRenderFragStream,Distorted.GLSL_VERSION,Distorted.GLSL_VERSION, Distorted.GLSL);
|
268 |
8777ce17
|
Leszek Koltunski
|
}
|
269 |
|
|
catch(Exception e)
|
270 |
|
|
{
|
271 |
56c6ca24
|
Leszek Koltunski
|
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile OIT RENDER program: "+e.getMessage());
|
272 |
8777ce17
|
Leszek Koltunski
|
throw new RuntimeException(e.getMessage());
|
273 |
|
|
}
|
274 |
|
|
|
275 |
56c6ca24
|
Leszek Koltunski
|
int oitRenderProgramH = mOITRenderProgram.getProgramHandle();
|
276 |
|
|
mOITRenderDepthH = GLES31.glGetUniformLocation( oitRenderProgramH, "u_Depth");
|
277 |
|
|
mOITRenderTexCorrH = GLES31.glGetUniformLocation( oitRenderProgramH, "u_TexCorr");
|
278 |
|
|
mOITRenderSizeH = GLES31.glGetUniformLocation( oitRenderProgramH, "u_Size");
|
279 |
7170e4eb
|
leszek
|
|
280 |
3fc9327a
|
Leszek Koltunski
|
// NORMAL PROGRAM //////////////////////////////////////
|
281 |
|
|
final InputStream normalVertexStream = resources.openRawResource(R.raw.normal_vertex_shader);
|
282 |
|
|
final InputStream normalFragmentStream = resources.openRawResource(R.raw.normal_fragment_shader);
|
283 |
c90b9e01
|
Leszek Koltunski
|
|
284 |
f2367b75
|
Leszek Koltunski
|
try
|
285 |
|
|
{
|
286 |
3fc9327a
|
Leszek Koltunski
|
mNormalProgram = new DistortedProgram(normalVertexStream,normalFragmentStream, Distorted.GLSL_VERSION, Distorted.GLSL_VERSION, Distorted.GLSL);
|
287 |
f2367b75
|
Leszek Koltunski
|
}
|
288 |
|
|
catch(Exception e)
|
289 |
|
|
{
|
290 |
cee0369a
|
Leszek Koltunski
|
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile NORMAL program: "+e.getMessage());
|
291 |
f2367b75
|
Leszek Koltunski
|
throw new RuntimeException(e.getMessage());
|
292 |
|
|
}
|
293 |
c90b9e01
|
Leszek Koltunski
|
|
294 |
3fc9327a
|
Leszek Koltunski
|
int normalProgramH = mNormalProgram.getProgramHandle();
|
295 |
e6519ac8
|
Leszek Koltunski
|
mNormalMVPMatrixH = GLES31.glGetUniformLocation( normalProgramH, "u_MVPMatrix");
|
296 |
55c14a19
|
Leszek Koltunski
|
}
|
297 |
|
|
|
298 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
299 |
|
|
|
300 |
421c2728
|
Leszek Koltunski
|
private void initializeEffectLists(DistortedEffects d, int flags)
|
301 |
d425545a
|
Leszek Koltunski
|
{
|
302 |
015642fb
|
Leszek Koltunski
|
if( (flags & Distorted.CLONE_MATRIX) != 0 )
|
303 |
6a06a912
|
Leszek Koltunski
|
{
|
304 |
d425545a
|
Leszek Koltunski
|
mM = d.mM;
|
305 |
|
|
matrixCloned = true;
|
306 |
|
|
}
|
307 |
|
|
else
|
308 |
|
|
{
|
309 |
4e2382f3
|
Leszek Koltunski
|
mM = new EffectQueueMatrix(mID);
|
310 |
d425545a
|
Leszek Koltunski
|
matrixCloned = false;
|
311 |
|
|
}
|
312 |
6a06a912
|
Leszek Koltunski
|
|
313 |
d425545a
|
Leszek Koltunski
|
if( (flags & Distorted.CLONE_VERTEX) != 0 )
|
314 |
|
|
{
|
315 |
|
|
mV = d.mV;
|
316 |
|
|
vertexCloned = true;
|
317 |
|
|
}
|
318 |
|
|
else
|
319 |
|
|
{
|
320 |
4e2382f3
|
Leszek Koltunski
|
mV = new EffectQueueVertex(mID);
|
321 |
d425545a
|
Leszek Koltunski
|
vertexCloned = false;
|
322 |
|
|
}
|
323 |
6a06a912
|
Leszek Koltunski
|
|
324 |
d425545a
|
Leszek Koltunski
|
if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
|
325 |
|
|
{
|
326 |
|
|
mF = d.mF;
|
327 |
|
|
fragmentCloned = true;
|
328 |
6a06a912
|
Leszek Koltunski
|
}
|
329 |
d425545a
|
Leszek Koltunski
|
else
|
330 |
|
|
{
|
331 |
4e2382f3
|
Leszek Koltunski
|
mF = new EffectQueueFragment(mID);
|
332 |
d425545a
|
Leszek Koltunski
|
fragmentCloned = false;
|
333 |
|
|
}
|
334 |
80b3acf6
|
Leszek Koltunski
|
|
335 |
|
|
if( (flags & Distorted.CLONE_POSTPROCESS) != 0 )
|
336 |
|
|
{
|
337 |
|
|
mP = d.mP;
|
338 |
|
|
postprocessCloned = true;
|
339 |
|
|
}
|
340 |
|
|
else
|
341 |
|
|
{
|
342 |
|
|
mP = new EffectQueuePostprocess(mID);
|
343 |
|
|
postprocessCloned = false;
|
344 |
|
|
}
|
345 |
|
|
}
|
346 |
|
|
|
347 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
348 |
|
|
|
349 |
70b6a155
|
Leszek Koltunski
|
EffectQueuePostprocess getPostprocess()
|
350 |
80b3acf6
|
Leszek Koltunski
|
{
|
351 |
70b6a155
|
Leszek Koltunski
|
return mP;
|
352 |
80b3acf6
|
Leszek Koltunski
|
}
|
353 |
|
|
|
354 |
26a4e5f6
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
355 |
|
|
|
356 |
|
|
void newNode(DistortedNode node)
|
357 |
|
|
{
|
358 |
|
|
mM.newNode(node);
|
359 |
|
|
mF.newNode(node);
|
360 |
|
|
mV.newNode(node);
|
361 |
|
|
mP.newNode(node);
|
362 |
|
|
}
|
363 |
|
|
|
364 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
365 |
c90b9e01
|
Leszek Koltunski
|
|
366 |
3fc9327a
|
Leszek Koltunski
|
private void displayNormals(MeshObject mesh)
|
367 |
c90b9e01
|
Leszek Koltunski
|
{
|
368 |
e6519ac8
|
Leszek Koltunski
|
GLES31.glBindBufferBase(GLES31.GL_TRANSFORM_FEEDBACK_BUFFER, 0, mesh.mAttTFO[0]);
|
369 |
|
|
GLES31.glBeginTransformFeedback( GLES31.GL_POINTS);
|
370 |
604b2899
|
Leszek Koltunski
|
DistortedRenderState.switchOffDrawing();
|
371 |
e6519ac8
|
Leszek Koltunski
|
GLES31.glDrawArrays( GLES31.GL_POINTS, 0, mesh.numVertices);
|
372 |
604b2899
|
Leszek Koltunski
|
DistortedRenderState.restoreDrawing();
|
373 |
e6519ac8
|
Leszek Koltunski
|
GLES31.glEndTransformFeedback();
|
374 |
|
|
GLES31.glBindBufferBase(GLES31.GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);
|
375 |
604b2899
|
Leszek Koltunski
|
|
376 |
3fc9327a
|
Leszek Koltunski
|
mNormalProgram.useProgram();
|
377 |
e6519ac8
|
Leszek Koltunski
|
GLES31.glUniformMatrix4fv(mNormalMVPMatrixH, 1, false, mM.getMVP() , 0);
|
378 |
|
|
GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, mesh.mAttTFO[0]);
|
379 |
|
|
GLES31.glVertexAttribPointer(mNormalProgram.mAttribute[0], MeshObject.POS_DATA_SIZE, GLES31.GL_FLOAT, false, 0, 0);
|
380 |
|
|
GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, 0);
|
381 |
|
|
GLES31.glLineWidth(8.0f);
|
382 |
|
|
GLES31.glDrawArrays(GLES31.GL_LINES, 0, 2*mesh.numVertices);
|
383 |
c90b9e01
|
Leszek Koltunski
|
}
|
384 |
1aedf874
|
leszek
|
|
385 |
c90b9e01
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
386 |
|
|
|
387 |
270c27bc
|
Leszek Koltunski
|
void drawPriv(float halfW, float halfH, MeshObject mesh, DistortedOutputSurface surface, long currTime, float marginInPixels)
|
388 |
d425545a
|
Leszek Koltunski
|
{
|
389 |
c1e24646
|
leszek
|
float halfZ = halfW*mesh.zFactor;
|
390 |
638b5b5c
|
leszek
|
|
391 |
8fbd0237
|
Leszek Koltunski
|
mM.compute(currTime);
|
392 |
|
|
mV.compute(currTime,halfW,halfH,halfZ);
|
393 |
|
|
mF.compute(currTime,halfW,halfH);
|
394 |
1149be8f
|
leszek
|
mP.compute(currTime);
|
395 |
8fbd0237
|
Leszek Koltunski
|
|
396 |
e6519ac8
|
Leszek Koltunski
|
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
397 |
d6e94c84
|
Leszek Koltunski
|
|
398 |
b9798977
|
leszek
|
mMainProgram.useProgram();
|
399 |
e6519ac8
|
Leszek Koltunski
|
GLES31.glUniform1i(mMainTextureH, 0);
|
400 |
12f45260
|
Leszek Koltunski
|
|
401 |
8777ce17
|
Leszek Koltunski
|
GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, mesh.mAttVBO[0]);
|
402 |
|
|
GLES31.glVertexAttribPointer(mMainProgram.mAttribute[0], MeshObject.POS_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET0);
|
403 |
|
|
GLES31.glVertexAttribPointer(mMainProgram.mAttribute[1], MeshObject.NOR_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET1);
|
404 |
|
|
GLES31.glVertexAttribPointer(mMainProgram.mAttribute[2], MeshObject.TEX_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET2);
|
405 |
|
|
GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, 0);
|
406 |
cab7c165
|
Leszek Koltunski
|
|
407 |
270c27bc
|
Leszek Koltunski
|
mM.send(surface,halfW,halfH,halfZ,marginInPixels);
|
408 |
8fbd0237
|
Leszek Koltunski
|
mV.send();
|
409 |
|
|
mF.send();
|
410 |
42571056
|
Leszek Koltunski
|
|
411 |
e6519ac8
|
Leszek Koltunski
|
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, mesh.numVertices);
|
412 |
c90b9e01
|
Leszek Koltunski
|
|
413 |
3fc9327a
|
Leszek Koltunski
|
if( mesh.mShowNormals ) displayNormals(mesh);
|
414 |
d425545a
|
Leszek Koltunski
|
}
|
415 |
6a06a912
|
Leszek Koltunski
|
|
416 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
417 |
7266d8ef
|
Leszek Koltunski
|
/**
|
418 |
|
|
* Only for use by the library itself.
|
419 |
|
|
*
|
420 |
|
|
* @y.exclude
|
421 |
|
|
*/
|
422 |
|
|
public static void blitPriv(DistortedOutputSurface surface)
|
423 |
d425545a
|
Leszek Koltunski
|
{
|
424 |
c1e24646
|
leszek
|
mBlitProgram.useProgram();
|
425 |
|
|
|
426 |
e6519ac8
|
Leszek Koltunski
|
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
427 |
|
|
GLES31.glUniform1i(mBlitTextureH, 0);
|
428 |
|
|
GLES31.glUniform1f( mBlitDepthH , 1.0f-surface.mNear);
|
429 |
|
|
GLES31.glVertexAttribPointer(mBlitProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
|
430 |
|
|
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
|
431 |
d425545a
|
Leszek Koltunski
|
}
|
432 |
7170e4eb
|
leszek
|
|
433 |
375b3950
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
434 |
|
|
// reset atomic counter to 0
|
435 |
|
|
|
436 |
|
|
static void zeroOutAtomic()
|
437 |
|
|
{
|
438 |
|
|
GLES31.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, mAtomicCounter[0] );
|
439 |
|
|
|
440 |
|
|
ByteBuffer atomicBuf = (ByteBuffer)GLES31.glMapBufferRange( GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, 4,
|
441 |
56c6ca24
|
Leszek Koltunski
|
GLES31.GL_MAP_WRITE_BIT|GLES31.GL_MAP_INVALIDATE_BUFFER_BIT);
|
442 |
375b3950
|
Leszek Koltunski
|
if( atomicBuf!=null )
|
443 |
|
|
{
|
444 |
|
|
IntBuffer atomicIntBuf = atomicBuf.order(ByteOrder.nativeOrder()).asIntBuffer();
|
445 |
|
|
|
446 |
c92d84ec
|
Leszek Koltunski
|
//int counter = atomicIntBuf.get(0);
|
447 |
375b3950
|
Leszek Koltunski
|
//android.util.Log.e("counter", "now = "+counter+" w="+surface.mWidth+" h="+surface.mHeight
|
448 |
|
|
// +" diff="+(counter-surface.mWidth*surface.mHeight));
|
449 |
c92d84ec
|
Leszek Koltunski
|
atomicIntBuf.put(0,0);
|
450 |
375b3950
|
Leszek Koltunski
|
}
|
451 |
|
|
else
|
452 |
|
|
{
|
453 |
c92d84ec
|
Leszek Koltunski
|
android.util.Log.e("effects", "failed to map atomic buffer");
|
454 |
375b3950
|
Leszek Koltunski
|
}
|
455 |
|
|
|
456 |
|
|
GLES31.glUnmapBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER);
|
457 |
|
|
GLES31.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0);
|
458 |
|
|
}
|
459 |
|
|
|
460 |
7170e4eb
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
461 |
56c6ca24
|
Leszek Koltunski
|
// Pass1 of the OIT algorithm. Clear per-pixel head-poiners.
|
462 |
|
|
|
463 |
|
|
static void oitClear(DistortedOutputSurface surface)
|
464 |
|
|
{
|
465 |
|
|
mOITClearProgram.useProgram();
|
466 |
|
|
|
467 |
|
|
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
468 |
|
|
GLES31.glUniform2f(mOITClearTexCorrH, 1.0f, 1.0f ); // corrections do not really matter here - only present because of common vertex shader.
|
469 |
|
|
GLES31.glUniform1f( mOITClearDepthH , 1.0f); // likewise depth
|
470 |
344ac0e4
|
Leszek Koltunski
|
GLES31.glUniform2ui(mOITClearSizeH, surface.mWidth, surface.mHeight);
|
471 |
56c6ca24
|
Leszek Koltunski
|
GLES31.glVertexAttribPointer(mOITClearProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
|
472 |
|
|
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
|
473 |
|
|
}
|
474 |
|
|
|
475 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
476 |
|
|
// Pass2 of the OIT algorithm - build per-pixel linked lists.
|
477 |
7170e4eb
|
leszek
|
|
478 |
56c6ca24
|
Leszek Koltunski
|
static void oitBuild(DistortedOutputSurface surface, float corrW, float corrH)
|
479 |
7170e4eb
|
leszek
|
{
|
480 |
56c6ca24
|
Leszek Koltunski
|
mOITBuildProgram.useProgram();
|
481 |
7170e4eb
|
leszek
|
|
482 |
e6519ac8
|
Leszek Koltunski
|
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
483 |
56c6ca24
|
Leszek Koltunski
|
GLES31.glUniform1i(mOITBuildTextureH, 0);
|
484 |
|
|
GLES31.glUniform1i(mOITBuildDepthTextureH, 1);
|
485 |
|
|
GLES31.glUniform2f(mOITBuildTexCorrH, corrW, corrH );
|
486 |
344ac0e4
|
Leszek Koltunski
|
GLES31.glUniform2ui(mOITBuildSizeH, surface.mWidth, surface.mHeight);
|
487 |
56c6ca24
|
Leszek Koltunski
|
GLES31.glUniform1ui(mOITBuildNumRecordsH, (mBufferSize-surface.mWidth*surface.mHeight)/3 ); // see the fragment shader
|
488 |
|
|
GLES31.glUniform1f(mOITBuildDepthH , 1.0f-surface.mNear);
|
489 |
|
|
GLES31.glVertexAttribPointer(mOITBuildProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
|
490 |
e6519ac8
|
Leszek Koltunski
|
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
|
491 |
8777ce17
|
Leszek Koltunski
|
}
|
492 |
|
|
|
493 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
494 |
33f59f22
|
Leszek Koltunski
|
// Pass3 of the OIT algorithm. Cut occluded parts of the linked list.
|
495 |
|
|
|
496 |
|
|
static void oitCollapse(DistortedOutputSurface surface, float corrW, float corrH)
|
497 |
|
|
{
|
498 |
|
|
mOITCollapseProgram.useProgram();
|
499 |
|
|
|
500 |
|
|
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
501 |
|
|
GLES31.glUniform1i(mOITCollapseDepthTextureH, 1);
|
502 |
|
|
GLES31.glUniform2f(mOITCollapseTexCorrH, corrW, corrH );
|
503 |
344ac0e4
|
Leszek Koltunski
|
GLES31.glUniform2ui(mOITCollapseSizeH, surface.mWidth, surface.mHeight);
|
504 |
33f59f22
|
Leszek Koltunski
|
GLES31.glUniform1f( mOITCollapseDepthH , 1.0f-surface.mNear);
|
505 |
|
|
GLES31.glVertexAttribPointer(mOITCollapseProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
|
506 |
|
|
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
|
507 |
|
|
}
|
508 |
|
|
|
509 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
510 |
|
|
// Pass4 of the OIT algorithm. Render all the transparent pixels from the per-pixel linked lists.
|
511 |
8777ce17
|
Leszek Koltunski
|
|
512 |
56c6ca24
|
Leszek Koltunski
|
static void oitRender(DistortedOutputSurface surface, float corrW, float corrH)
|
513 |
8777ce17
|
Leszek Koltunski
|
{
|
514 |
56c6ca24
|
Leszek Koltunski
|
mOITRenderProgram.useProgram();
|
515 |
8777ce17
|
Leszek Koltunski
|
|
516 |
|
|
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
517 |
56c6ca24
|
Leszek Koltunski
|
GLES31.glUniform2f(mOITRenderTexCorrH, corrW, corrH );
|
518 |
344ac0e4
|
Leszek Koltunski
|
GLES31.glUniform2ui(mOITRenderSizeH, surface.mWidth, surface.mHeight);
|
519 |
56c6ca24
|
Leszek Koltunski
|
GLES31.glUniform1f( mOITRenderDepthH , 1.0f-surface.mNear);
|
520 |
|
|
GLES31.glVertexAttribPointer(mOITRenderProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
|
521 |
8777ce17
|
Leszek Koltunski
|
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
|
522 |
7170e4eb
|
leszek
|
}
|
523 |
|
|
|
524 |
cee0369a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
525 |
|
|
|
526 |
8e34674e
|
Leszek Koltunski
|
private void releasePriv()
|
527 |
d425545a
|
Leszek Koltunski
|
{
|
528 |
344ac0e4
|
Leszek Koltunski
|
if( !matrixCloned ) mM.abortAll(false);
|
529 |
|
|
if( !vertexCloned ) mV.abortAll(false);
|
530 |
|
|
if( !fragmentCloned ) mF.abortAll(false);
|
531 |
|
|
if( !postprocessCloned ) mP.abortAll(false);
|
532 |
d425545a
|
Leszek Koltunski
|
|
533 |
4e2382f3
|
Leszek Koltunski
|
mM = null;
|
534 |
|
|
mV = null;
|
535 |
|
|
mF = null;
|
536 |
80b3acf6
|
Leszek Koltunski
|
mP = null;
|
537 |
8e34674e
|
Leszek Koltunski
|
}
|
538 |
|
|
|
539 |
1942537e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
540 |
|
|
|
541 |
78e89fb5
|
Leszek Koltunski
|
static void onPause()
|
542 |
1942537e
|
Leszek Koltunski
|
{
|
543 |
8777ce17
|
Leszek Koltunski
|
mLinkedListSSBO[0]= -1;
|
544 |
|
|
mAtomicCounter[0] = -1;
|
545 |
1942537e
|
Leszek Koltunski
|
}
|
546 |
|
|
|
547 |
78e89fb5
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
548 |
|
|
|
549 |
|
|
static void onDestroy()
|
550 |
|
|
{
|
551 |
|
|
mNextID = 0;
|
552 |
|
|
}
|
553 |
|
|
|
554 |
8e34674e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
555 |
|
|
// PUBLIC API
|
556 |
ada90d33
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
557 |
d425545a
|
Leszek Koltunski
|
/**
|
558 |
4e2382f3
|
Leszek Koltunski
|
* Create empty effect queue.
|
559 |
d425545a
|
Leszek Koltunski
|
*/
|
560 |
421c2728
|
Leszek Koltunski
|
public DistortedEffects()
|
561 |
d425545a
|
Leszek Koltunski
|
{
|
562 |
c7da4e65
|
leszek
|
mID = ++mNextID;
|
563 |
4e2382f3
|
Leszek Koltunski
|
initializeEffectLists(this,0);
|
564 |
d425545a
|
Leszek Koltunski
|
}
|
565 |
ada90d33
|
Leszek Koltunski
|
|
566 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
567 |
d425545a
|
Leszek Koltunski
|
/**
|
568 |
4e2382f3
|
Leszek Koltunski
|
* Copy constructor.
|
569 |
d425545a
|
Leszek Koltunski
|
* <p>
|
570 |
|
|
* Whatever we do not clone gets created just like in the default constructor.
|
571 |
|
|
*
|
572 |
|
|
* @param dc Source object to create our object from
|
573 |
|
|
* @param flags A bitmask of values specifying what to copy.
|
574 |
e6ab30eb
|
Leszek Koltunski
|
* For example, CLONE_VERTEX | CLONE_MATRIX.
|
575 |
d425545a
|
Leszek Koltunski
|
*/
|
576 |
421c2728
|
Leszek Koltunski
|
public DistortedEffects(DistortedEffects dc, int flags)
|
577 |
d425545a
|
Leszek Koltunski
|
{
|
578 |
c7da4e65
|
leszek
|
mID = ++mNextID;
|
579 |
4e2382f3
|
Leszek Koltunski
|
initializeEffectLists(dc,flags);
|
580 |
d425545a
|
Leszek Koltunski
|
}
|
581 |
ada90d33
|
Leszek Koltunski
|
|
582 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
583 |
|
|
/**
|
584 |
07305c87
|
Leszek Koltunski
|
* Releases all resources. After this call, the queue should not be used anymore.
|
585 |
6a06a912
|
Leszek Koltunski
|
*/
|
586 |
13687207
|
leszek
|
@SuppressWarnings("unused")
|
587 |
8e34674e
|
Leszek Koltunski
|
public synchronized void delete()
|
588 |
d425545a
|
Leszek Koltunski
|
{
|
589 |
|
|
releasePriv();
|
590 |
|
|
}
|
591 |
6a06a912
|
Leszek Koltunski
|
|
592 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
593 |
|
|
/**
|
594 |
4e2382f3
|
Leszek Koltunski
|
* Returns unique ID of this instance.
|
595 |
|
|
*
|
596 |
|
|
* @return ID of the object.
|
597 |
6a06a912
|
Leszek Koltunski
|
*/
|
598 |
4e2382f3
|
Leszek Koltunski
|
public long getID()
|
599 |
d425545a
|
Leszek Koltunski
|
{
|
600 |
4e2382f3
|
Leszek Koltunski
|
return mID;
|
601 |
d425545a
|
Leszek Koltunski
|
}
|
602 |
4e2382f3
|
Leszek Koltunski
|
|
603 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
604 |
|
|
/**
|
605 |
|
|
* Adds the calling class to the list of Listeners that get notified each time some event happens
|
606 |
faa3ff56
|
Leszek Koltunski
|
* to one of the Effects in our queues. Nothing will happen if 'el' is already in the list.
|
607 |
6a06a912
|
Leszek Koltunski
|
*
|
608 |
|
|
* @param el A class implementing the EffectListener interface that wants to get notifications.
|
609 |
|
|
*/
|
610 |
13687207
|
leszek
|
@SuppressWarnings("unused")
|
611 |
3fc994b2
|
Leszek Koltunski
|
public void registerForMessages(EffectListener el)
|
612 |
d425545a
|
Leszek Koltunski
|
{
|
613 |
26a4e5f6
|
leszek
|
mM.registerForMessages(el);
|
614 |
3fc994b2
|
Leszek Koltunski
|
mV.registerForMessages(el);
|
615 |
|
|
mF.registerForMessages(el);
|
616 |
80b3acf6
|
Leszek Koltunski
|
mP.registerForMessages(el);
|
617 |
d425545a
|
Leszek Koltunski
|
}
|
618 |
6a06a912
|
Leszek Koltunski
|
|
619 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
620 |
|
|
/**
|
621 |
faa3ff56
|
Leszek Koltunski
|
* Removes the calling class from the list of Listeners that get notified if something happens to Effects in our queue.
|
622 |
6a06a912
|
Leszek Koltunski
|
*
|
623 |
|
|
* @param el A class implementing the EffectListener interface that no longer wants to get notifications.
|
624 |
|
|
*/
|
625 |
13687207
|
leszek
|
@SuppressWarnings("unused")
|
626 |
3fc994b2
|
Leszek Koltunski
|
public void deregisterForMessages(EffectListener el)
|
627 |
d425545a
|
Leszek Koltunski
|
{
|
628 |
26a4e5f6
|
leszek
|
mM.deregisterForMessages(el);
|
629 |
3fc994b2
|
Leszek Koltunski
|
mV.deregisterForMessages(el);
|
630 |
|
|
mF.deregisterForMessages(el);
|
631 |
80b3acf6
|
Leszek Koltunski
|
mP.deregisterForMessages(el);
|
632 |
d425545a
|
Leszek Koltunski
|
}
|
633 |
6a06a912
|
Leszek Koltunski
|
|
634 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
635 |
|
|
/**
|
636 |
d07f2950
|
Leszek Koltunski
|
* Aborts all Effects.
|
637 |
|
|
* @return Number of effects aborted.
|
638 |
6a06a912
|
Leszek Koltunski
|
*/
|
639 |
d425545a
|
Leszek Koltunski
|
public int abortAllEffects()
|
640 |
13687207
|
leszek
|
{
|
641 |
|
|
return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true);
|
642 |
|
|
}
|
643 |
6a06a912
|
Leszek Koltunski
|
|
644 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
645 |
|
|
/**
|
646 |
d07f2950
|
Leszek Koltunski
|
* Aborts all Effects of a given type, for example all MATRIX Effects.
|
647 |
6a06a912
|
Leszek Koltunski
|
*
|
648 |
da9b3f07
|
Leszek Koltunski
|
* @param type one of the constants defined in {@link EffectType}
|
649 |
d07f2950
|
Leszek Koltunski
|
* @return Number of effects aborted.
|
650 |
6a06a912
|
Leszek Koltunski
|
*/
|
651 |
da9b3f07
|
Leszek Koltunski
|
public int abortByType(EffectType type)
|
652 |
d425545a
|
Leszek Koltunski
|
{
|
653 |
|
|
switch(type)
|
654 |
6a06a912
|
Leszek Koltunski
|
{
|
655 |
da9b3f07
|
Leszek Koltunski
|
case MATRIX : return mM.abortAll(true);
|
656 |
|
|
case VERTEX : return mV.abortAll(true);
|
657 |
|
|
case FRAGMENT : return mF.abortAll(true);
|
658 |
80b3acf6
|
Leszek Koltunski
|
case POSTPROCESS: return mP.abortAll(true);
|
659 |
da9b3f07
|
Leszek Koltunski
|
default : return 0;
|
660 |
6a06a912
|
Leszek Koltunski
|
}
|
661 |
d425545a
|
Leszek Koltunski
|
}
|
662 |
47316d20
|
leszek
|
|
663 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
664 |
|
|
/**
|
665 |
faa3ff56
|
Leszek Koltunski
|
* Aborts an Effect by its ID.
|
666 |
47316d20
|
leszek
|
*
|
667 |
|
|
* @param id the Id of the Effect to be removed, as returned by getID().
|
668 |
|
|
* @return Number of effects aborted.
|
669 |
|
|
*/
|
670 |
|
|
public int abortById(long id)
|
671 |
|
|
{
|
672 |
|
|
long type = id&EffectType.MASK;
|
673 |
|
|
|
674 |
2ef5dd9e
|
leszek
|
if( type == EffectType.MATRIX.ordinal() ) return mM.removeById(id);
|
675 |
|
|
if( type == EffectType.VERTEX.ordinal() ) return mV.removeById(id);
|
676 |
|
|
if( type == EffectType.FRAGMENT.ordinal() ) return mF.removeById(id);
|
677 |
80b3acf6
|
Leszek Koltunski
|
if( type == EffectType.POSTPROCESS.ordinal() ) return mP.removeById(id);
|
678 |
47316d20
|
leszek
|
|
679 |
|
|
return 0;
|
680 |
|
|
}
|
681 |
|
|
|
682 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
683 |
|
|
/**
|
684 |
|
|
* Aborts a single Effect.
|
685 |
|
|
*
|
686 |
6bb59aad
|
Leszek Koltunski
|
* @param effect the Effect we want to abort.
|
687 |
476bbc81
|
Leszek Koltunski
|
* @return number of Effects aborted. Always either 0 or 1.
|
688 |
6a06a912
|
Leszek Koltunski
|
*/
|
689 |
6bb59aad
|
Leszek Koltunski
|
public int abortEffect(Effect effect)
|
690 |
d425545a
|
Leszek Koltunski
|
{
|
691 |
6bb59aad
|
Leszek Koltunski
|
switch(effect.getType())
|
692 |
|
|
{
|
693 |
da9b3f07
|
Leszek Koltunski
|
case MATRIX : return mM.removeEffect(effect);
|
694 |
|
|
case VERTEX : return mV.removeEffect(effect);
|
695 |
|
|
case FRAGMENT : return mF.removeEffect(effect);
|
696 |
80b3acf6
|
Leszek Koltunski
|
case POSTPROCESS: return mP.removeEffect(effect);
|
697 |
da9b3f07
|
Leszek Koltunski
|
default : return 0;
|
698 |
6bb59aad
|
Leszek Koltunski
|
}
|
699 |
d425545a
|
Leszek Koltunski
|
}
|
700 |
6a06a912
|
Leszek Koltunski
|
|
701 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
702 |
|
|
/**
|
703 |
e8c81a8e
|
Leszek Koltunski
|
* Abort all Effects of a given name, for example all rotations.
|
704 |
6a06a912
|
Leszek Koltunski
|
*
|
705 |
da9b3f07
|
Leszek Koltunski
|
* @param name one of the constants defined in {@link EffectName}
|
706 |
476bbc81
|
Leszek Koltunski
|
* @return number of Effects aborted.
|
707 |
6a06a912
|
Leszek Koltunski
|
*/
|
708 |
da9b3f07
|
Leszek Koltunski
|
public int abortByName(EffectName name)
|
709 |
d425545a
|
Leszek Koltunski
|
{
|
710 |
da9b3f07
|
Leszek Koltunski
|
switch(name.getType())
|
711 |
6a06a912
|
Leszek Koltunski
|
{
|
712 |
da9b3f07
|
Leszek Koltunski
|
case MATRIX : return mM.removeByName(name);
|
713 |
|
|
case VERTEX : return mV.removeByName(name);
|
714 |
|
|
case FRAGMENT : return mF.removeByName(name);
|
715 |
80b3acf6
|
Leszek Koltunski
|
case POSTPROCESS: return mP.removeByName(name);
|
716 |
6bb59aad
|
Leszek Koltunski
|
default : return 0;
|
717 |
6a06a912
|
Leszek Koltunski
|
}
|
718 |
d425545a
|
Leszek Koltunski
|
}
|
719 |
432442f9
|
Leszek Koltunski
|
|
720 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
721 |
|
|
/**
|
722 |
faa3ff56
|
Leszek Koltunski
|
* Returns the maximum number of effects of a given type that can be simultaneously applied to a
|
723 |
|
|
* single (InputSurface,MeshObject) combo.
|
724 |
432442f9
|
Leszek Koltunski
|
*
|
725 |
fe6fe99a
|
leszek
|
* @param type {@link EffectType}
|
726 |
|
|
* @return The maximum number of effects of a given type.
|
727 |
432442f9
|
Leszek Koltunski
|
*/
|
728 |
13687207
|
leszek
|
@SuppressWarnings("unused")
|
729 |
fe6fe99a
|
leszek
|
public static int getMax(EffectType type)
|
730 |
432442f9
|
Leszek Koltunski
|
{
|
731 |
fe6fe99a
|
leszek
|
return EffectQueue.getMax(type.ordinal());
|
732 |
432442f9
|
Leszek Koltunski
|
}
|
733 |
|
|
|
734 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
735 |
|
|
/**
|
736 |
fe6fe99a
|
leszek
|
* Sets the maximum number of effects that can be stored in a single EffectQueue at one time.
|
737 |
432442f9
|
Leszek Koltunski
|
* This can fail if:
|
738 |
|
|
* <ul>
|
739 |
|
|
* <li>the value of 'max' is outside permitted range (0 ≤ max ≤ Byte.MAX_VALUE)
|
740 |
|
|
* <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
|
741 |
|
|
* before the Vertex Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
|
742 |
|
|
* time only decreasing the value of 'max' is permitted.
|
743 |
|
|
* <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
|
744 |
|
|
* </ul>
|
745 |
|
|
*
|
746 |
fe6fe99a
|
leszek
|
* @param type {@link EffectType}
|
747 |
|
|
* @param max new maximum number of simultaneous effects. Has to be a non-negative number not greater
|
748 |
80b3acf6
|
Leszek Koltunski
|
* than Byte.MAX_VALUE
|
749 |
|
|
* @return <code>true</code> if operation was successful, <code>false</code> otherwise.
|
750 |
|
|
*/
|
751 |
|
|
@SuppressWarnings("unused")
|
752 |
fe6fe99a
|
leszek
|
public static boolean setMax(EffectType type, int max)
|
753 |
80b3acf6
|
Leszek Koltunski
|
{
|
754 |
fe6fe99a
|
leszek
|
return EffectQueue.setMax(type.ordinal(),max);
|
755 |
80b3acf6
|
Leszek Koltunski
|
}
|
756 |
|
|
|
757 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
758 |
|
|
/**
|
759 |
6bb59aad
|
Leszek Koltunski
|
* Add a new Effect to our queue.
|
760 |
f2fe7e28
|
Leszek Koltunski
|
*
|
761 |
6bb59aad
|
Leszek Koltunski
|
* @param effect The Effect to add.
|
762 |
ae77d55e
|
Leszek Koltunski
|
* @return <code>true</code> if operation was successful, <code>false</code> otherwise.
|
763 |
6a06a912
|
Leszek Koltunski
|
*/
|
764 |
ae77d55e
|
Leszek Koltunski
|
public boolean apply(Effect effect)
|
765 |
d425545a
|
Leszek Koltunski
|
{
|
766 |
6bb59aad
|
Leszek Koltunski
|
switch(effect.getType())
|
767 |
|
|
{
|
768 |
26a4e5f6
|
leszek
|
case MATRIX : return mM.add(effect);
|
769 |
ae77d55e
|
Leszek Koltunski
|
case VERTEX : return mV.add(effect);
|
770 |
|
|
case FRAGMENT : return mF.add(effect);
|
771 |
80b3acf6
|
Leszek Koltunski
|
case POSTPROCESS : return mP.add(effect);
|
772 |
6bb59aad
|
Leszek Koltunski
|
}
|
773 |
ae77d55e
|
Leszek Koltunski
|
|
774 |
|
|
return false;
|
775 |
4fde55a0
|
Leszek Koltunski
|
}
|
776 |
f2fe7e28
|
Leszek Koltunski
|
}
|