Project

General

Profile

Download (48.4 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / main / DistortedLibrary.java @ a9d4bb9a

1 d333eb6b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4 46b572b5 Leszek Koltunski
// This file is part of Distorted.                                                               //
5 d333eb6b Leszek Koltunski
//                                                                                               //
6 46b572b5 Leszek Koltunski
// Distorted is free software: you can redistribute it and/or modify                             //
7 d333eb6b Leszek Koltunski
// 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 46b572b5 Leszek Koltunski
// Distorted is distributed in the hope that it will be useful,                                  //
12 d333eb6b Leszek Koltunski
// 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 46b572b5 Leszek Koltunski
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18 d333eb6b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20 fe82a979 Leszek Koltunski
package org.distorted.library.main;
21 6a06a912 Leszek Koltunski
22 30beb34f Leszek Koltunski
import android.app.ActivityManager;
23 7845dc66 Leszek Koltunski
import android.content.Context;
24 30beb34f Leszek Koltunski
import android.content.pm.ConfigurationInfo;
25 d6e94c84 Leszek Koltunski
import android.content.res.Resources;
26 b7074bc6 Leszek Koltunski
import android.opengl.GLES30;
27 edea9cf3 Leszek Koltunski
import android.opengl.GLES31;
28 bfe45b4a Leszek Koltunski
import android.util.Log;
29 310e14fb leszek
30 bfe45b4a Leszek Koltunski
import org.distorted.library.R;
31 26a4e5f6 leszek
import org.distorted.library.effect.Effect;
32 809dcae3 Leszek Koltunski
import org.distorted.library.effectqueue.EffectQueue;
33
import org.distorted.library.effectqueue.EffectQueuePostprocess;
34 bfe45b4a Leszek Koltunski
import org.distorted.library.effect.EffectType;
35
import org.distorted.library.effect.FragmentEffect;
36 aa2f0486 Leszek Koltunski
import org.distorted.library.effect.PostprocessEffect;
37 bfe45b4a Leszek Koltunski
import org.distorted.library.effect.VertexEffect;
38 07206c71 Leszek Koltunski
import org.distorted.library.effectqueue.EffectQueueVertex;
39
import org.distorted.library.mesh.DeferredJobs;
40 bfe45b4a Leszek Koltunski
import org.distorted.library.mesh.MeshBase;
41 ed06301f Leszek Koltunski
import org.distorted.library.message.EffectMessageSender;
42 bfe45b4a Leszek Koltunski
import org.distorted.library.program.DistortedProgram;
43 b7074bc6 Leszek Koltunski
import org.distorted.library.program.VertexCompilationException;
44 0273ef2a Leszek Koltunski
import org.distorted.library.type.Dynamic;
45 bfe45b4a Leszek Koltunski
46
import java.io.InputStream;
47
import java.nio.ByteBuffer;
48
import java.nio.ByteOrder;
49
import java.nio.FloatBuffer;
50
import java.nio.IntBuffer;
51 5f35f1cb Leszek Koltunski
import java.util.regex.Matcher;
52
import java.util.regex.Pattern;
53 6a06a912 Leszek Koltunski
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55
/**
56 f953bee0 Leszek Koltunski
 * A singleton class used to control various global dialog_settings.
57 6a06a912 Leszek Koltunski
 */
58 7602a827 Leszek Koltunski
public class DistortedLibrary
59 39cbf9dc Leszek Koltunski
  {
60 6a06a912 Leszek Koltunski
  /**
61 cacc63de Leszek Koltunski
   * When creating an instance of a DistortedTexture from another instance, clone the Bitmap that's
62
   * backing up our DistortedTexture.
63 6a06a912 Leszek Koltunski
   * <p>
64 cacc63de Leszek Koltunski
   * This way we can have two DistortedTextures, both backed up by the same Bitmap, to which we can
65 6a06a912 Leszek Koltunski
   * apply different effects. Used in the copy constructor.
66
   */
67 29a06526 Leszek Koltunski
  public static final int CLONE_SURFACE = 0x1;
68 6a06a912 Leszek Koltunski
  /**
69 cacc63de Leszek Koltunski
   * When creating an instance of a DistortedEffects from another instance, clone the Matrix Effects.
70 6a06a912 Leszek Koltunski
   * <p>
71 cacc63de Leszek Koltunski
   * This way we can have two different DistortedEffects sharing the MATRIX queue.
72 6a06a912 Leszek Koltunski
   */
73 015642fb Leszek Koltunski
  public static final int CLONE_MATRIX = 0x2;
74 6a06a912 Leszek Koltunski
  /**
75 cacc63de Leszek Koltunski
   * When creating an instance of a DistortedEffects from another instance, clone the Vertex Effects.
76 6a06a912 Leszek Koltunski
   * <p>
77 cacc63de Leszek Koltunski
   * This way we can have two different DistortedEffects sharing the VERTEX queue.
78 6a06a912 Leszek Koltunski
   */
79
  public static final int CLONE_VERTEX  = 0x4;
80
  /**
81 cacc63de Leszek Koltunski
   * When creating an instance of a DistortedEffects from another instance, clone the Fragment Effects.
82 6a06a912 Leszek Koltunski
   * <p>
83 cacc63de Leszek Koltunski
   * This way we can have two different DistortedEffects sharing the FRAGMENT queue.
84 6a06a912 Leszek Koltunski
   */
85
  public static final int CLONE_FRAGMENT= 0x8;
86 d6e94c84 Leszek Koltunski
   /**
87
   * When creating an instance of a DistortedEffects from another instance, clone the PostProcess Effects.
88
   * <p>
89
   * This way we can have two different DistortedEffects sharing the POSTPROCESS queue.
90
   */
91
  public static final int CLONE_POSTPROCESS= 0x10;
92 6a06a912 Leszek Koltunski
  /**
93 a09ada4c Leszek Koltunski
   * When creating an instance of a DistortedNode from another instance, clone the children Nodes.
94 6a06a912 Leszek Koltunski
   * <p>
95 cacc63de Leszek Koltunski
   * This is mainly useful for creating many similar sub-trees and rendering then at different places
96
   * on the screen with (optionally) different Effects.
97 6a06a912 Leszek Koltunski
   */
98 d6e94c84 Leszek Koltunski
  public static final int CLONE_CHILDREN= 0x20;
99 b3618cb5 Leszek Koltunski
100 5f35f1cb Leszek Koltunski
  /**
101
   * When creating a DistortedScreen (which needs to have mFBOQueueSize FBOs attached), pass this
102
   * constant for 'numOfFBOs' and the number of backing FBOs will be taken from 'mFBOQueueSize'
103
   * (the value of which is most likely unknown at the time of creation of the Screen)
104
   */
105
  public static final int WAIT_FOR_FBO_QUEUE_SIZE = -1;
106 586b5fa1 Leszek Koltunski
  /**
107
   * Work around bugs in ARM Mali driver by, instead to a single FBO, rendering to a circular queue
108 5f35f1cb Leszek Koltunski
   * of mFBOQueueSize FBOs. (otherwise we sometimes get a 'full pipeline flush' and the end result
109 586b5fa1 Leszek Koltunski
   * might be missing part of the Objects)
110 6672d895 Leszek Koltunski
   *
111 5f35f1cb Leszek Koltunski
   * This bug only exists on Mali driver r12. (or more precisely it's there in r12 but fixed in r22)
112 6672d895 Leszek Koltunski
   *
113
   * https://community.arm.com/graphics/f/discussions/10285/opengl-es-3-1-on-mali-t880-flashes
114 586b5fa1 Leszek Koltunski
   */
115 5f35f1cb Leszek Koltunski
  private static int mFBOQueueSize;
116 9ec374e8 Leszek Koltunski
  private static int mGLSL;
117
  private static String mGLSL_VERSION;
118 46d463a4 Leszek Koltunski
  private static boolean mOITCompilationAttempted, mNeedsTransformFeedback;
119 78ff6ea9 Leszek Koltunski
120
  private static int mMaxTextureSize         = Integer.MAX_VALUE;
121
  private static int mMaxNumberOfVerUniforms = Integer.MAX_VALUE;
122
  private static int mMaxNumberOfFraUniforms = Integer.MAX_VALUE;
123 6a06a912 Leszek Koltunski
124 a9d4bb9a Leszek Koltunski
  private static boolean mBuggyUBOs;
125
  private static String mVendor, mVersion, mRenderer;
126
127 bfe45b4a Leszek Koltunski
  //////////////////////////////////////////////////////////////////////////////////////////////
128
  /// MAIN PROGRAM ///
129
  private static DistortedProgram mMainProgram;
130
  private static int mMainTextureH;
131 62c869ad Leszek Koltunski
  private static int mTransformFeedbackH;
132 bfe45b4a Leszek Koltunski
133
  /// NORMAL PROGRAM /////
134
  private static DistortedProgram mNormalProgram;
135 62c869ad Leszek Koltunski
  private static int mNormalProjectionH;
136 bfe45b4a Leszek Koltunski
137
  /// MAIN OIT PROGRAM ///
138
  private static DistortedProgram mMainOITProgram;
139
  private static int mMainOITTextureH;
140
  private static int mMainOITSizeH;
141
  private static int mMainOITNumRecordsH;
142
143
  /// BLIT PROGRAM ///
144
  private static DistortedProgram mBlitProgram;
145
  private static int mBlitTextureH;
146
  private static int mBlitDepthH;
147
  private static final FloatBuffer mQuadPositions;
148
149 f046b159 Leszek Koltunski
  /// FULL PROGRAM ///
150
  private static DistortedProgram mFullProgram;
151
152 bfe45b4a Leszek Koltunski
  static
153
    {
154
    float[] positionData= { -0.5f, -0.5f,  -0.5f, 0.5f,  0.5f,-0.5f,  0.5f, 0.5f };
155
    mQuadPositions = ByteBuffer.allocateDirect(32).order(ByteOrder.nativeOrder()).asFloatBuffer();
156
    mQuadPositions.put(positionData).position(0);
157
    }
158
159
  /// BLIT DEPTH PROGRAM ///
160
  private static DistortedProgram mBlitDepthProgram;
161
  private static int mBlitDepthTextureH;
162
  private static int mBlitDepthDepthTextureH;
163
  private static int mBlitDepthDepthH;
164
  private static int mBlitDepthTexCorrH;
165
166 0bd9f644 Leszek Koltunski
  /// Program Handles ///
167
  private static int mMainProgramH, mFullProgramH, mMainOITProgramH;
168
169 bfe45b4a Leszek Koltunski
  /// OIT SSBO BUFFER ///
170
  private static int[] mLinkedListSSBO = new int[1];
171 5f35f1cb Leszek Koltunski
  private static int[] mAtomicCounter;
172 bfe45b4a Leszek Koltunski
  private static int   mCurrBuffer;
173
174
  static
175
    {
176
    mLinkedListSSBO[0]= -1;
177
    mCurrBuffer       =  0;
178
    }
179
180
  ///////////////////////////////////////////////////////////////
181
  // meaning: allocate 1.0 screenful of places for transparent
182
  // fragments in the SSBO backing up the OIT render method.
183
  private static float mBufferSize=1.0f;
184
185
  /// OIT CLEAR PROGRAM ///
186
  private static DistortedProgram mOITClearProgram;
187
  private static int mOITClearDepthH;
188
  private static int mOITClearTexCorrH;
189
  private static int mOITClearSizeH;
190
191
  /// OIT BUILD PROGRAM ///
192
  private static DistortedProgram mOITBuildProgram;
193
  private static int mOITBuildTextureH;
194
  private static int mOITBuildDepthTextureH;
195
  private static int mOITBuildDepthH;
196
  private static int mOITBuildTexCorrH;
197
  private static int mOITBuildSizeH;
198
  private static int mOITBuildNumRecordsH;
199
200
  /// OIT COLLAPSE PROGRAM ///
201
  private static DistortedProgram mOITCollapseProgram;
202
  private static int mOITCollapseDepthTextureH;
203
  private static int mOITCollapseDepthH;
204
  private static int mOITCollapseTexCorrH;
205
  private static int mOITCollapseSizeH;
206
207
  /// OIT RENDER PROGRAM ///
208
  private static DistortedProgram mOITRenderProgram;
209
  private static int mOITRenderDepthH;
210
  private static int mOITRenderTexCorrH;
211
  private static int mOITRenderSizeH;
212
213
  /// END PROGRAMS //////
214
215 d99fcc9c Leszek Koltunski
  /**
216
   * Every application using the library must implement this interface so that the library can send
217
   * it exceptions that arise. The exceptions may come at any time, for example the library will
218
   * compile its OIT problem only on the first attempt to use the OIT
219
   * Those will mainly be hardware-related: shaders do not compile on particular hardware, the required
220
   * OpenGL ES 3.0 is not supported, etc.
221
   */
222
  public interface ExceptionListener
223
    {
224
    void distortedException(Exception ex);
225
    }
226
227
  private static ExceptionListener mListener;
228
  private static Resources mResources;
229
230 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
231 c638c1b0 Leszek Koltunski
// private: hide this from Javadoc
232 6a06a912 Leszek Koltunski
233 7602a827 Leszek Koltunski
  private DistortedLibrary()
234 6a06a912 Leszek Koltunski
    {
235 8eccf334 Leszek Koltunski
236 6a06a912 Leszek Koltunski
    }
237
238 bfe45b4a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
239
240 d99fcc9c Leszek Koltunski
  private static void createMainProgram()
241 bfe45b4a Leszek Koltunski
    {
242
    // MAIN PROGRAM ////////////////////////////////////
243 d99fcc9c Leszek Koltunski
    final InputStream mainVertStream = mResources.openRawResource(R.raw.main_vertex_shader);
244
    final InputStream mainFragStream = mResources.openRawResource(R.raw.main_fragment_shader);
245 bfe45b4a Leszek Koltunski
246
    int numF = FragmentEffect.getNumEnabled();
247
    int numV = VertexEffect.getNumEnabled();
248
249 b7074bc6 Leszek Koltunski
    String mainVertHeader= mGLSL_VERSION + ("#define NUM_VERTEX "   + ( numV>0 ? getMax(EffectType.VERTEX  ) : 0 ) + "\n");
250
    String mainFragHeader= mGLSL_VERSION + ("#define NUM_FRAGMENT " + ( numF>0 ? getMax(EffectType.FRAGMENT) : 0 ) + "\n");
251 36d65d88 Leszek Koltunski
252 e8925fcd Leszek Koltunski
    mainVertHeader += "#define MAX_COMPON " + MeshBase.getMaxEffComponents() + "\n";
253 46d463a4 Leszek Koltunski
    if( MeshBase.getUseCenters() ) mainVertHeader += "#define COMP_CENTERS\n";
254 eff6e3d3 Leszek Koltunski
    if( mBuggyUBOs )               mainVertHeader += "#define BUGGY_UBOS\n";
255 36d65d88 Leszek Koltunski
256 bfe45b4a Leszek Koltunski
    String enabledEffectV= VertexEffect.getGLSL();
257
    String enabledEffectF= FragmentEffect.getGLSL();
258
259
    String[] feedback = { "v_Position", "v_endPosition" };
260
261
    try
262
      {
263 97b6c85e Leszek Koltunski
      mMainProgram = new DistortedProgram(mainVertStream, mainFragStream, mainVertHeader,
264
                                          mainFragHeader, enabledEffectV, enabledEffectF,
265
                                          mGLSL, mNeedsTransformFeedback ? feedback : null );
266 bfe45b4a Leszek Koltunski
      }
267
    catch(Exception e)
268
      {
269
      Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile MAIN program: "+e.getMessage());
270
      throw new RuntimeException(e.getMessage());
271
      }
272
273 0bd9f644 Leszek Koltunski
    mMainProgramH = mMainProgram.getProgramHandle();
274
    EffectQueue.getUniforms(mMainProgramH,0);
275 9f9924f8 Leszek Koltunski
    MeshBase.getUniforms(mMainProgramH,0);
276 0bd9f644 Leszek Koltunski
    mMainTextureH= GLES30.glGetUniformLocation( mMainProgramH, "u_Texture");
277
    mTransformFeedbackH= GLES30.glGetUniformLocation( mMainProgramH, "u_TransformFeedback");
278 bfe45b4a Leszek Koltunski
279
    // BLIT PROGRAM ////////////////////////////////////
280 d99fcc9c Leszek Koltunski
    final InputStream blitVertStream = mResources.openRawResource(R.raw.blit_vertex_shader);
281
    final InputStream blitFragStream = mResources.openRawResource(R.raw.blit_fragment_shader);
282 bfe45b4a Leszek Koltunski
283
    try
284
      {
285 b7074bc6 Leszek Koltunski
      mBlitProgram = new DistortedProgram(blitVertStream,blitFragStream, mGLSL_VERSION, mGLSL_VERSION, mGLSL);
286 bfe45b4a Leszek Koltunski
      }
287
    catch(Exception e)
288
      {
289
      Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile BLIT program: "+e.getMessage());
290
      throw new RuntimeException(e.getMessage());
291
      }
292
293
    int blitProgramH = mBlitProgram.getProgramHandle();
294 b7074bc6 Leszek Koltunski
    mBlitTextureH  = GLES30.glGetUniformLocation( blitProgramH, "u_Texture");
295
    mBlitDepthH    = GLES30.glGetUniformLocation( blitProgramH, "u_Depth");
296 bfe45b4a Leszek Koltunski
297
    // BLIT DEPTH PROGRAM ////////////////////////////////////
298 d99fcc9c Leszek Koltunski
    final InputStream blitDepthVertStream = mResources.openRawResource(R.raw.blit_depth_vertex_shader);
299
    final InputStream blitDepthFragStream = mResources.openRawResource(R.raw.blit_depth_fragment_shader);
300 bfe45b4a Leszek Koltunski
301
    try
302
      {
303 b7074bc6 Leszek Koltunski
      mBlitDepthProgram = new DistortedProgram(blitDepthVertStream,blitDepthFragStream, mGLSL_VERSION, mGLSL_VERSION, mGLSL);
304 bfe45b4a Leszek Koltunski
      }
305
    catch(Exception e)
306
      {
307
      Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile BLIT DEPTH program: "+e.getMessage());
308
      throw new RuntimeException(e.getMessage());
309
      }
310
311
    int blitDepthProgramH   = mBlitDepthProgram.getProgramHandle();
312 b7074bc6 Leszek Koltunski
    mBlitDepthTextureH      = GLES30.glGetUniformLocation( blitDepthProgramH, "u_Texture");
313
    mBlitDepthDepthTextureH = GLES30.glGetUniformLocation( blitDepthProgramH, "u_DepthTexture");
314
    mBlitDepthDepthH        = GLES30.glGetUniformLocation( blitDepthProgramH, "u_Depth");
315
    mBlitDepthTexCorrH      = GLES30.glGetUniformLocation( blitDepthProgramH, "u_TexCorr");
316 d99fcc9c Leszek Koltunski
    }
317
318
///////////////////////////////////////////////////////////////////////////////////////////////////
319 bfe45b4a Leszek Koltunski
320 d99fcc9c Leszek Koltunski
  private static void createNormalProgram(Resources resources)
321
    {
322 bfe45b4a Leszek Koltunski
    // NORMAL PROGRAM //////////////////////////////////////
323
    final InputStream normalVertexStream   = resources.openRawResource(R.raw.normal_vertex_shader);
324
    final InputStream normalFragmentStream = resources.openRawResource(R.raw.normal_fragment_shader);
325
326
    try
327
      {
328 b7074bc6 Leszek Koltunski
      mNormalProgram = new DistortedProgram(normalVertexStream,normalFragmentStream, mGLSL_VERSION, mGLSL_VERSION, mGLSL);
329 bfe45b4a Leszek Koltunski
      }
330
    catch(Exception e)
331
      {
332
      Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile NORMAL program: "+e.getMessage());
333
      throw new RuntimeException(e.getMessage());
334
      }
335
336
    int normalProgramH = mNormalProgram.getProgramHandle();
337 62c869ad Leszek Koltunski
    mNormalProjectionH = GLES30.glGetUniformLocation( normalProgramH, "u_Projection");
338 bfe45b4a Leszek Koltunski
    }
339
340 f046b159 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
341
342
  private static void createFullProgram(Resources resources)
343
    {
344
    final InputStream fullVertStream = resources.openRawResource(R.raw.main_vertex_shader);
345
    final InputStream fullFragStream = resources.openRawResource(R.raw.main_fragment_shader);
346
347
    int numV = VertexEffect.getAllEnabled();
348
349
    String fullVertHeader= mGLSL_VERSION + ("#define NUM_VERTEX "   + ( numV>0 ? getMax(EffectType.VERTEX ) : 0 ) + "\n");
350
    String fullFragHeader= mGLSL_VERSION + ("#define NUM_FRAGMENT " +                                         0   + "\n");
351 36d65d88 Leszek Koltunski
352 e8925fcd Leszek Koltunski
    fullVertHeader += "#define MAX_COMPON " + MeshBase.getMaxEffComponents() + "\n";
353 46d463a4 Leszek Koltunski
    if( MeshBase.getUseCenters() ) fullVertHeader += "#define COMP_CENTERS\n";
354 eff6e3d3 Leszek Koltunski
    if( mBuggyUBOs )               fullVertHeader += "#define BUGGY_UBOS\n";
355 36d65d88 Leszek Koltunski
356 f046b159 Leszek Koltunski
    String enabledEffectV= VertexEffect.getAllGLSL();
357
    String enabledEffectF= "{}";
358
359 667884b0 Leszek Koltunski
    fullVertHeader += "#define PREAPPLY\n";
360
361 a2878a67 Leszek Koltunski
    String[] feedback = { "v_Position", "v_endPosition" };
362 f046b159 Leszek Koltunski
363
    try
364
      {
365
      mFullProgram = new DistortedProgram(fullVertStream, fullFragStream, fullVertHeader, fullFragHeader,
366
                                          enabledEffectV, enabledEffectF, mGLSL, feedback);
367
      }
368
    catch(Exception e)
369
      {
370
      Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile FULL program: "+e.getMessage());
371
      throw new RuntimeException(e.getMessage());
372
      }
373
374 0bd9f644 Leszek Koltunski
    mFullProgramH = mFullProgram.getProgramHandle();
375
    EffectQueue.getUniforms(mFullProgramH,3);
376 9f9924f8 Leszek Koltunski
    MeshBase.getUniforms(mFullProgramH,3);
377 f046b159 Leszek Koltunski
    }
378
379 bfe45b4a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
380
381 d99fcc9c Leszek Koltunski
  private static void createOITProgram(Resources resources)
382 bfe45b4a Leszek Koltunski
    {
383
    // MAIN OIT PROGRAM ////////////////////////////////
384
    final InputStream mainVertStream = resources.openRawResource(R.raw.main_vertex_shader);
385
    final InputStream mainFragStream = resources.openRawResource(R.raw.main_fragment_shader);
386
387
    int numF = FragmentEffect.getNumEnabled();
388
    int numV = VertexEffect.getNumEnabled();
389
390 b7074bc6 Leszek Koltunski
    String mainVertHeader= mGLSL_VERSION + ("#define NUM_VERTEX "   + ( numV>0 ? getMax(EffectType.VERTEX  ) : 0 ) + "\n") + ("#define OIT\n");
391
    String mainFragHeader= mGLSL_VERSION + ("#define NUM_FRAGMENT " + ( numF>0 ? getMax(EffectType.FRAGMENT) : 0 ) + "\n") + ("#define OIT\n");
392 bfe45b4a Leszek Koltunski
393 e8925fcd Leszek Koltunski
    mainVertHeader += "#define MAX_COMPON " + MeshBase.getMaxEffComponents() + "\n";
394 46d463a4 Leszek Koltunski
    if( MeshBase.getUseCenters() ) mainVertHeader += "#define COMP_CENTERS\n";
395 eff6e3d3 Leszek Koltunski
    if( mBuggyUBOs )               mainVertHeader += "#define BUGGY_UBOS\n";
396 36d65d88 Leszek Koltunski
397 bfe45b4a Leszek Koltunski
    String enabledEffectV= VertexEffect.getGLSL();
398
    String enabledEffectF= FragmentEffect.getGLSL();
399
400
    try
401
      {
402
      mMainOITProgram = new DistortedProgram(mainVertStream, mainFragStream, mainVertHeader, mainFragHeader,
403 b7074bc6 Leszek Koltunski
                                             enabledEffectV, enabledEffectF, mGLSL, null);
404 bfe45b4a Leszek Koltunski
      }
405
    catch(Exception e)
406
      {
407
      Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile MAIN OIT program: "+e.getMessage());
408
      throw new RuntimeException(e.getMessage());
409
      }
410
411 0bd9f644 Leszek Koltunski
    mMainOITProgramH = mMainOITProgram.getProgramHandle();
412
    EffectQueue.getUniforms(mMainOITProgramH,1);
413 9f9924f8 Leszek Koltunski
    MeshBase.getUniforms(mMainOITProgramH,1);
414 0bd9f644 Leszek Koltunski
    mMainOITTextureH    = GLES30.glGetUniformLocation( mMainOITProgramH, "u_Texture");
415
    mMainOITSizeH       = GLES30.glGetUniformLocation( mMainOITProgramH, "u_Size");
416
    mMainOITNumRecordsH = GLES30.glGetUniformLocation( mMainOITProgramH, "u_numRecords");
417 bfe45b4a Leszek Koltunski
418
    // OIT CLEAR PROGRAM ////////////////////////////////////
419
    final InputStream oitClearVertStream = resources.openRawResource(R.raw.oit_vertex_shader);
420
    final InputStream oitClearFragStream = resources.openRawResource(R.raw.oit_clear_fragment_shader);
421
422
    try
423
      {
424 b7074bc6 Leszek Koltunski
      mOITClearProgram = new DistortedProgram(oitClearVertStream,oitClearFragStream, mGLSL_VERSION, mGLSL_VERSION, mGLSL);
425 bfe45b4a Leszek Koltunski
      }
426
    catch(Exception e)
427
      {
428
      Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile OIT CLEAR program: "+e.getMessage());
429
      throw new RuntimeException(e.getMessage());
430
      }
431
432
    int oitClearProgramH   = mOITClearProgram.getProgramHandle();
433 b7074bc6 Leszek Koltunski
    mOITClearDepthH        = GLES30.glGetUniformLocation( oitClearProgramH, "u_Depth");
434
    mOITClearTexCorrH      = GLES30.glGetUniformLocation( oitClearProgramH, "u_TexCorr");
435
    mOITClearSizeH         = GLES30.glGetUniformLocation( oitClearProgramH, "u_Size");
436 bfe45b4a Leszek Koltunski
437
    // OIT BUILD PROGRAM ////////////////////////////////////
438
    final InputStream oitBuildVertStream = resources.openRawResource(R.raw.oit_vertex_shader);
439
    final InputStream oitBuildFragStream = resources.openRawResource(R.raw.oit_build_fragment_shader);
440
441
    try
442
      {
443 b7074bc6 Leszek Koltunski
      mOITBuildProgram = new DistortedProgram(oitBuildVertStream,oitBuildFragStream, mGLSL_VERSION, mGLSL_VERSION, mGLSL);
444 bfe45b4a Leszek Koltunski
      }
445
    catch(Exception e)
446
      {
447
      Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile OIT BUILD program: "+e.getMessage());
448
      throw new RuntimeException(e.getMessage());
449
      }
450
451
    int oitBuildProgramH   = mOITBuildProgram.getProgramHandle();
452 b7074bc6 Leszek Koltunski
    mOITBuildTextureH      = GLES30.glGetUniformLocation( oitBuildProgramH, "u_Texture");
453
    mOITBuildDepthTextureH = GLES30.glGetUniformLocation( oitBuildProgramH, "u_DepthTexture");
454
    mOITBuildDepthH        = GLES30.glGetUniformLocation( oitBuildProgramH, "u_Depth");
455
    mOITBuildTexCorrH      = GLES30.glGetUniformLocation( oitBuildProgramH, "u_TexCorr");
456
    mOITBuildSizeH         = GLES30.glGetUniformLocation( oitBuildProgramH, "u_Size");
457
    mOITBuildNumRecordsH   = GLES30.glGetUniformLocation( oitBuildProgramH, "u_numRecords");
458 bfe45b4a Leszek Koltunski
459
    // OIT COLLAPSE PROGRAM ///////////////////////////
460
    final InputStream oitCollapseVertStream = resources.openRawResource(R.raw.oit_vertex_shader);
461
    final InputStream oitCollapseFragStream = resources.openRawResource(R.raw.oit_collapse_fragment_shader);
462
463
    try
464
      {
465 b7074bc6 Leszek Koltunski
      mOITCollapseProgram = new DistortedProgram(oitCollapseVertStream,oitCollapseFragStream, mGLSL_VERSION, mGLSL_VERSION, mGLSL);
466 bfe45b4a Leszek Koltunski
      }
467
    catch(Exception e)
468
      {
469
      Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile OIT COLLAPSE program: "+e.getMessage());
470
      throw new RuntimeException(e.getMessage());
471
      }
472
473
    int oitCollapseProgramH   = mOITCollapseProgram.getProgramHandle();
474 b7074bc6 Leszek Koltunski
    mOITCollapseDepthTextureH = GLES30.glGetUniformLocation( oitCollapseProgramH, "u_DepthTexture");
475
    mOITCollapseDepthH        = GLES30.glGetUniformLocation( oitCollapseProgramH, "u_Depth");
476
    mOITCollapseTexCorrH      = GLES30.glGetUniformLocation( oitCollapseProgramH, "u_TexCorr");
477
    mOITCollapseSizeH         = GLES30.glGetUniformLocation( oitCollapseProgramH, "u_Size");
478 bfe45b4a Leszek Koltunski
479
    // OIT RENDER PROGRAM ///////////////////////////
480
    final InputStream oitRenderVertStream = resources.openRawResource(R.raw.oit_vertex_shader);
481
    final InputStream oitRenderFragStream = resources.openRawResource(R.raw.oit_render_fragment_shader);
482
483
    try
484
      {
485 b7074bc6 Leszek Koltunski
      mOITRenderProgram = new DistortedProgram(oitRenderVertStream,oitRenderFragStream, mGLSL_VERSION, mGLSL_VERSION, mGLSL);
486 bfe45b4a Leszek Koltunski
      }
487
    catch(Exception e)
488
      {
489
      Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile OIT RENDER program: "+e.getMessage());
490
      throw new RuntimeException(e.getMessage());
491
      }
492
493
    int oitRenderProgramH   = mOITRenderProgram.getProgramHandle();
494 b7074bc6 Leszek Koltunski
    mOITRenderDepthH        = GLES30.glGetUniformLocation( oitRenderProgramH, "u_Depth");
495
    mOITRenderTexCorrH      = GLES30.glGetUniformLocation( oitRenderProgramH, "u_TexCorr");
496
    mOITRenderSizeH         = GLES30.glGetUniformLocation( oitRenderProgramH, "u_Size");
497 bfe45b4a Leszek Koltunski
    }
498
499
///////////////////////////////////////////////////////////////////////////////////////////////////
500
501 62c869ad Leszek Koltunski
  private static void displayNormals(float[] projection, MeshBase mesh)
502 bfe45b4a Leszek Koltunski
    {
503 d99fcc9c Leszek Koltunski
    if( mNormalProgram==null )
504
      {
505
      try
506
        {
507
        createNormalProgram(mResources);
508
        }
509
      catch(Exception ex)
510
        {
511
        mListener.distortedException(ex);
512
        return;
513
        }
514
      }
515
516 bfe45b4a Leszek Koltunski
    int num = mesh.getNumVertices();
517
    int tfo = mesh.getTFO();
518
519 62c869ad Leszek Koltunski
    GLES30.glUniform1i(DistortedLibrary.mTransformFeedbackH, 1);
520 b7074bc6 Leszek Koltunski
    GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, tfo );
521
    GLES30.glBeginTransformFeedback( GLES30.GL_POINTS);
522 7602a827 Leszek Koltunski
    InternalRenderState.switchOffDrawing();
523 b7074bc6 Leszek Koltunski
    GLES30.glDrawArrays( GLES30.GL_POINTS, 0, num );
524 7602a827 Leszek Koltunski
    InternalRenderState.restoreDrawing();
525 b7074bc6 Leszek Koltunski
    GLES30.glEndTransformFeedback();
526
    GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);
527 c02f32f7 Leszek Koltunski
    GLES30.glUniform1i(DistortedLibrary.mTransformFeedbackH, 0);
528 bfe45b4a Leszek Koltunski
529 f046b159 Leszek Koltunski
    mNormalProgram.useProgram();
530 62c869ad Leszek Koltunski
    GLES30.glUniformMatrix4fv(mNormalProjectionH, 1, false, projection, 0);
531 f046b159 Leszek Koltunski
    mesh.bindTransformAttribs(mNormalProgram);
532 b7074bc6 Leszek Koltunski
    GLES30.glLineWidth(8.0f);
533
    GLES30.glDrawArrays(GLES30.GL_LINES, 0, 2*num);
534 bfe45b4a Leszek Koltunski
    }
535
536 f046b159 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
537 0bd9f644 Leszek Koltunski
/**
538
 * Execute all VertexEffects and adjust all vertices
539
 *
540
 * @y.exclude
541
 */
542 07206c71 Leszek Koltunski
  public static void adjustVertices(MeshBase mesh, EffectQueueVertex queue)
543 f046b159 Leszek Koltunski
    {
544 d99fcc9c Leszek Koltunski
    if( mFullProgram==null )
545 f046b159 Leszek Koltunski
      {
546 d99fcc9c Leszek Koltunski
      try
547
        {
548
        createFullProgram(mResources);
549
        }
550
      catch(Exception ex)
551
        {
552
        mListener.distortedException(ex);
553
        return;
554
        }
555 f046b159 Leszek Koltunski
      }
556 d99fcc9c Leszek Koltunski
557
    int num = mesh.getNumVertices();
558
    int tfo = mesh.getTFO();
559
560
    mFullProgram.useProgram();
561
    mesh.bindVertexAttribs(mFullProgram);
562
    queue.compute(1);
563 78ff6ea9 Leszek Koltunski
    queue.send(0.0f,mFullProgramH,3);
564 9f9924f8 Leszek Koltunski
    mesh.send(mFullProgramH,3);
565 d99fcc9c Leszek Koltunski
566
    GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, tfo );
567
    GLES30.glBeginTransformFeedback( GLES30.GL_POINTS);
568
    InternalRenderState.switchOffDrawing();
569
    GLES30.glDrawArrays( GLES30.GL_POINTS, 0, num );
570
    InternalRenderState.restoreDrawing();
571
    GLES30.glEndTransformFeedback();
572
    mesh.copyTransformToVertex();
573
    GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);
574 f046b159 Leszek Koltunski
    }
575
576 bfe45b4a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
577
578 c90aca24 Leszek Koltunski
  static void drawPrivOIT(DistortedEffects effects, MeshBase mesh, InternalOutputSurface surface, long currTime)
579 bfe45b4a Leszek Koltunski
    {
580 06ddd60d Leszek Koltunski
    if( mMainOITProgram!=null )
581
      {
582
      EffectQueue[] queues = effects.getQueues();
583 c90aca24 Leszek Koltunski
584 06ddd60d Leszek Koltunski
      EffectQueue.compute(queues, currTime);
585
      GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
586 bfe45b4a Leszek Koltunski
587 06ddd60d Leszek Koltunski
      mMainOITProgram.useProgram();
588
      GLES30.glUniform1i(mMainOITTextureH, 0);
589
      GLES30.glUniform2ui(mMainOITSizeH, surface.mWidth, surface.mHeight);
590
      GLES30.glUniform1ui(mMainOITNumRecordsH, (int)(mBufferSize*surface.mWidth*surface.mHeight) );
591
      mesh.bindVertexAttribs(mMainOITProgram);
592 9f9924f8 Leszek Koltunski
      mesh.send(mMainOITProgramH,1);
593 bfe45b4a Leszek Koltunski
594 06ddd60d Leszek Koltunski
      float inflate     = mesh.getInflate();
595
      float distance    = surface.mDistance;
596
      float mipmap      = surface.mMipmap;
597
      float[] projection= surface.mProjectionMatrix;
598 bfe45b4a Leszek Koltunski
599 78ff6ea9 Leszek Koltunski
      EffectQueue.send(queues, mMainOITProgramH, distance, mipmap, projection, inflate, 1 );
600 06ddd60d Leszek Koltunski
      GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() );
601 bfe45b4a Leszek Koltunski
602 06ddd60d Leszek Koltunski
      if( mesh.getShowNormals() )
603
        {
604
        mMainProgram.useProgram();
605 9f9924f8 Leszek Koltunski
        mesh.send(mMainProgramH,0);
606 78ff6ea9 Leszek Koltunski
        EffectQueue.send(queues, mMainProgramH, distance, mipmap, projection, inflate, 0 );
607 62c869ad Leszek Koltunski
        displayNormals(projection,mesh);
608 06ddd60d Leszek Koltunski
        }
609 bfe45b4a Leszek Koltunski
      }
610
    }
611
612
///////////////////////////////////////////////////////////////////////////////////////////////////
613
614 c90aca24 Leszek Koltunski
  static void drawPriv(DistortedEffects effects, MeshBase mesh, InternalOutputSurface surface, long currTime)
615 bfe45b4a Leszek Koltunski
    {
616 f046b159 Leszek Koltunski
    if( mMainProgram!=null )
617 f482efa3 Leszek Koltunski
      {
618
      EffectQueue[] queues = effects.getQueues();
619 bfe45b4a Leszek Koltunski
620 f482efa3 Leszek Koltunski
      EffectQueue.compute(queues, currTime);
621
      GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
622 46b572b5 Leszek Koltunski
623 f482efa3 Leszek Koltunski
      mMainProgram.useProgram();
624
      GLES30.glUniform1i(DistortedLibrary.mMainTextureH, 0);
625
      mesh.bindVertexAttribs(DistortedLibrary.mMainProgram);
626 9f9924f8 Leszek Koltunski
      mesh.send(mMainProgramH,0);
627 809dcae3 Leszek Koltunski
628 f482efa3 Leszek Koltunski
      float inflate     = mesh.getInflate();
629
      float distance    = surface.mDistance;
630
      float mipmap      = surface.mMipmap;
631
      float[] projection= surface.mProjectionMatrix;
632 809dcae3 Leszek Koltunski
633 78ff6ea9 Leszek Koltunski
      EffectQueue.send(queues, mMainProgramH, distance, mipmap, projection, inflate, 0 );
634 f482efa3 Leszek Koltunski
      GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() );
635 bfe45b4a Leszek Koltunski
636 62c869ad Leszek Koltunski
      if( mesh.getShowNormals() ) displayNormals(projection,mesh);
637 f482efa3 Leszek Koltunski
      }
638 bfe45b4a Leszek Koltunski
    }
639
640
///////////////////////////////////////////////////////////////////////////////////////////////////
641
642 7602a827 Leszek Koltunski
  static void blitPriv(InternalOutputSurface surface)
643 bfe45b4a Leszek Koltunski
    {
644 f482efa3 Leszek Koltunski
    if( mBlitProgram!=null )
645
      {
646
      mBlitProgram.useProgram();
647 bfe45b4a Leszek Koltunski
648 f482efa3 Leszek Koltunski
      GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
649
      GLES30.glUniform1i(mBlitTextureH, 0);
650
      GLES30.glUniform1f( mBlitDepthH , 1.0f-surface.mNear);
651
      GLES30.glVertexAttribPointer(mBlitProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
652
      GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
653
      }
654 bfe45b4a Leszek Koltunski
    }
655
656
///////////////////////////////////////////////////////////////////////////////////////////////////
657
658 7602a827 Leszek Koltunski
  static void blitDepthPriv(InternalOutputSurface surface, float corrW, float corrH)
659 bfe45b4a Leszek Koltunski
    {
660 f482efa3 Leszek Koltunski
    if( mBlitDepthProgram!=null )
661
      {
662
      mBlitDepthProgram.useProgram();
663
664
      GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
665
      GLES30.glUniform1i(mBlitDepthTextureH, 0);
666
      GLES30.glUniform1i(mBlitDepthDepthTextureH, 1);
667
      GLES30.glUniform2f(mBlitDepthTexCorrH, corrW, corrH );
668
      GLES30.glUniform1f( mBlitDepthDepthH , 1.0f-surface.mNear);
669
      GLES30.glVertexAttribPointer(mBlitDepthProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
670
      GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
671
      }
672 bfe45b4a Leszek Koltunski
    }
673
674
///////////////////////////////////////////////////////////////////////////////////////////////////
675 b7074bc6 Leszek Koltunski
// yes it is safe to be mixing 3.0 and 3.1 like that, senior members of the OpenGL discussions forum assert
676 bfe45b4a Leszek Koltunski
677
  private static int printPreviousBuffer()
678
    {
679
    int counter = 0;
680
681 b7074bc6 Leszek Koltunski
    ByteBuffer atomicBuf = (ByteBuffer)GLES30.glMapBufferRange( GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, 4,
682
                                                                GLES30.GL_MAP_READ_BIT);
683 bfe45b4a Leszek Koltunski
    if( atomicBuf!=null )
684
      {
685
      IntBuffer atomicIntBuf = atomicBuf.order(ByteOrder.nativeOrder()).asIntBuffer();
686
      counter = atomicIntBuf.get(0);
687
      }
688
    else
689
      {
690 b7074bc6 Leszek Koltunski
      Log.e("effects", "print: failed to map atomic buffer");
691 bfe45b4a Leszek Koltunski
      }
692
693 b7074bc6 Leszek Koltunski
    GLES30.glUnmapBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER);
694 bfe45b4a Leszek Koltunski
695
    return counter;
696
    }
697
698
///////////////////////////////////////////////////////////////////////////////////////////////////
699
700
  private static void zeroBuffer()
701
    {
702 b7074bc6 Leszek Koltunski
    ByteBuffer atomicBuf = (ByteBuffer)GLES30.glMapBufferRange( GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, 4,
703 fd836a41 Leszek Koltunski
                                                                GLES30.GL_MAP_WRITE_BIT|GLES30.GL_MAP_INVALIDATE_BUFFER_BIT);
704 bfe45b4a Leszek Koltunski
    if( atomicBuf!=null )
705
      {
706
      IntBuffer atomicIntBuf = atomicBuf.order(ByteOrder.nativeOrder()).asIntBuffer();
707
      atomicIntBuf.put(0,0);
708
      }
709
    else
710
      {
711 b7074bc6 Leszek Koltunski
      Log.e("effects", "zero: failed to map atomic buffer");
712 bfe45b4a Leszek Koltunski
      }
713
714 b7074bc6 Leszek Koltunski
    GLES30.glUnmapBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER);
715 bfe45b4a Leszek Koltunski
    }
716
717
///////////////////////////////////////////////////////////////////////////////////////////////////
718
// reset atomic counter to 0
719
720
  static int zeroOutAtomic()
721
    {
722
    int counter = 0;
723
724 5f35f1cb Leszek Koltunski
    if( mAtomicCounter==null )
725 bfe45b4a Leszek Koltunski
      {
726 5f35f1cb Leszek Koltunski
      mAtomicCounter = new int[mFBOQueueSize];
727
728
      GLES30.glGenBuffers(mFBOQueueSize,mAtomicCounter,0);
729 bfe45b4a Leszek Koltunski
730 5f35f1cb Leszek Koltunski
      for(int i=0; i<mFBOQueueSize; i++)
731 bfe45b4a Leszek Koltunski
        {
732 b7074bc6 Leszek Koltunski
        GLES30.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, mAtomicCounter[i]);
733
        GLES30.glBufferData(GLES31.GL_ATOMIC_COUNTER_BUFFER, 4, null, GLES30.GL_DYNAMIC_DRAW);
734 bfe45b4a Leszek Koltunski
        zeroBuffer();
735
        }
736
      }
737
738
    // reading the value of the buffer on every frame would slow down rendering by
739 d99fcc9c Leszek Koltunski
    // about 3%; doing it only once every 5 frames affects speed by less than 1%.
740 bfe45b4a Leszek Koltunski
    if( mCurrBuffer==0 )
741
      {
742 b7074bc6 Leszek Koltunski
      GLES30.glBindBufferBase(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, mAtomicCounter[mCurrBuffer]);
743 bfe45b4a Leszek Koltunski
      counter = printPreviousBuffer();
744
      }
745
746 5f35f1cb Leszek Koltunski
    if( ++mCurrBuffer>=mFBOQueueSize ) mCurrBuffer = 0;
747 bfe45b4a Leszek Koltunski
748 b7074bc6 Leszek Koltunski
    GLES30.glBindBufferBase(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, mAtomicCounter[mCurrBuffer]);
749 bfe45b4a Leszek Koltunski
    zeroBuffer();
750
751
    return counter;
752
    }
753
754
///////////////////////////////////////////////////////////////////////////////////////////////////
755 809dcae3 Leszek Koltunski
// Pass1 of the OIT algorithm. Clear per-pixel head-pointers.
756 bfe45b4a Leszek Koltunski
757 7602a827 Leszek Koltunski
  static void oitClear(InternalOutputSurface surface, int counter)
758 bfe45b4a Leszek Koltunski
    {
759 d99fcc9c Leszek Koltunski
    if( mOITClearProgram==null )
760 bfe45b4a Leszek Koltunski
      {
761 d99fcc9c Leszek Koltunski
      if( mGLSL>=310 && !mOITCompilationAttempted )
762 f482efa3 Leszek Koltunski
        {
763 d99fcc9c Leszek Koltunski
        mOITCompilationAttempted = true;
764 bfe45b4a Leszek Koltunski
765 d99fcc9c Leszek Koltunski
        try
766
          {
767
          createOITProgram(mResources);
768
          }
769
        catch(Exception ex)
770
          {
771
          mListener.distortedException(ex);
772
          return;
773
          }
774 f482efa3 Leszek Koltunski
        }
775 d99fcc9c Leszek Koltunski
      else
776 f482efa3 Leszek Koltunski
        {
777 d99fcc9c Leszek Koltunski
        return;
778 f482efa3 Leszek Koltunski
        }
779 d99fcc9c Leszek Koltunski
      }
780 bfe45b4a Leszek Koltunski
781 d99fcc9c Leszek Koltunski
    if( mLinkedListSSBO[0]<0 )
782
      {
783
      GLES30.glGenBuffers(1,mLinkedListSSBO,0);
784 bfe45b4a Leszek Koltunski
785 d99fcc9c Leszek Koltunski
      int size = (int)(surface.mWidth*surface.mHeight*(3*mBufferSize+1)*4);
786
      GLES30.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mLinkedListSSBO[0]);
787
      GLES30.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, size, null, GLES30.GL_DYNAMIC_READ|GLES30.GL_DYNAMIC_DRAW);
788
      GLES30.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, 0);
789
790
      GLES30.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 1, mLinkedListSSBO[0]);
791
      }
792
793
    // See if we have overflown the SSBO in one of the previous frames.
794
    // If yes, assume we need to make the SSBO larger.
795
    float overflow = counter/(mBufferSize*surface.mWidth*surface.mHeight);
796
797
    if( overflow>1.0f )
798
      {
799
      mBufferSize *= (int)(overflow+1.0f);
800
      int size = (int)(surface.mWidth*surface.mHeight*(3*mBufferSize+1)*4);
801
      GLES30.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mLinkedListSSBO[0]);
802
      GLES30.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, size, null, GLES30.GL_DYNAMIC_READ|GLES30.GL_DYNAMIC_DRAW);
803
      GLES30.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, 0);
804 f482efa3 Leszek Koltunski
      }
805 d99fcc9c Leszek Koltunski
806
    mOITClearProgram.useProgram();
807
808
    GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
809
    GLES30.glUniform2f(mOITClearTexCorrH, 1.0f, 1.0f );   // corrections do not really matter here - only present because of common vertex shader.
810
    GLES30.glUniform1f( mOITClearDepthH , 1.0f);          // likewise depth
811
    GLES30.glUniform2ui(mOITClearSizeH, surface.mWidth, surface.mHeight);
812
    GLES30.glVertexAttribPointer(mOITClearProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
813
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
814 bfe45b4a Leszek Koltunski
    }
815
816
///////////////////////////////////////////////////////////////////////////////////////////////////
817
// Pass2 of the OIT algorithm - build per-pixel linked lists.
818
819 7602a827 Leszek Koltunski
  static void oitBuild(InternalOutputSurface surface, float corrW, float corrH)
820 bfe45b4a Leszek Koltunski
    {
821 f482efa3 Leszek Koltunski
    if( mOITBuildProgram!=null )
822
      {
823
      mOITBuildProgram.useProgram();
824
825
      GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
826
      GLES30.glUniform1i(mOITBuildTextureH, 0);
827
      GLES30.glUniform1i(mOITBuildDepthTextureH, 1);
828
      GLES30.glUniform2f(mOITBuildTexCorrH, corrW, corrH );
829
      GLES30.glUniform2ui(mOITBuildSizeH, surface.mWidth, surface.mHeight);
830
      GLES30.glUniform1ui(mOITBuildNumRecordsH, (int)(mBufferSize*surface.mWidth*surface.mHeight) );
831
      GLES30.glUniform1f(mOITBuildDepthH , 1.0f-surface.mNear);
832
      GLES30.glVertexAttribPointer(mOITBuildProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
833
      GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
834
      }
835 bfe45b4a Leszek Koltunski
    }
836
837
///////////////////////////////////////////////////////////////////////////////////////////////////
838
// Pass3 of the OIT algorithm. Cut occluded parts of the linked list.
839
840 7602a827 Leszek Koltunski
  static void oitCollapse(InternalOutputSurface surface, float corrW, float corrH)
841 bfe45b4a Leszek Koltunski
    {
842 f482efa3 Leszek Koltunski
    if( mOITCollapseProgram!=null )
843
      {
844
      mOITCollapseProgram.useProgram();
845
846
      GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
847
      GLES30.glUniform1i(mOITCollapseDepthTextureH, 1);
848
      GLES30.glUniform2f(mOITCollapseTexCorrH, corrW, corrH );
849
      GLES30.glUniform2ui(mOITCollapseSizeH, surface.mWidth, surface.mHeight);
850
      GLES30.glUniform1f( mOITCollapseDepthH , 1.0f-surface.mNear);
851
      GLES30.glVertexAttribPointer(mOITCollapseProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
852
      GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
853
      }
854 bfe45b4a Leszek Koltunski
    }
855
856
///////////////////////////////////////////////////////////////////////////////////////////////////
857
// Pass4 of the OIT algorithm. Render all the transparent pixels from the per-pixel linked lists.
858
859 7602a827 Leszek Koltunski
  static void oitRender(InternalOutputSurface surface, float corrW, float corrH)
860 bfe45b4a Leszek Koltunski
    {
861 f482efa3 Leszek Koltunski
    if( mOITRenderProgram!=null )
862
      {
863
      mOITRenderProgram.useProgram();
864
865
      GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
866
      GLES30.glUniform2f(mOITRenderTexCorrH, corrW, corrH );
867
      GLES30.glUniform2ui(mOITRenderSizeH, surface.mWidth, surface.mHeight);
868
      GLES30.glUniform1f( mOITRenderDepthH , 1.0f-surface.mNear);
869
      GLES30.glVertexAttribPointer(mOITRenderProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
870
      GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
871
      }
872 bfe45b4a Leszek Koltunski
    }
873
874
///////////////////////////////////////////////////////////////////////////////////////////////////
875
876
  static void setSSBOSize(float size)
877
    {
878
    mBufferSize = size;
879
    }
880
881 5f35f1cb Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
882
883
  static int getQueueSize()
884
    {
885
    return mFBOQueueSize;
886
    }
887
888 edea9cf3 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
889
// ARM Mali driver r12 has problems when we keep swapping many FBOs (fixed in r22)
890 b7074bc6 Leszek Koltunski
// PowerVR GE8100 / GE8300 compiler fails to compile OIT programs.
891 edea9cf3 Leszek Koltunski
892 5f35f1cb Leszek Koltunski
  private static void detectBuggyDriversAndSetQueueSize(int queueSize)
893 edea9cf3 Leszek Koltunski
    {
894 a9d4bb9a Leszek Koltunski
    mVendor  = GLES30.glGetString(GLES30.GL_VENDOR);
895
    mVersion = GLES30.glGetString(GLES30.GL_VERSION);
896
    mRenderer= GLES30.glGetString(GLES30.GL_RENDERER);
897 edea9cf3 Leszek Koltunski
898 5f35f1cb Leszek Koltunski
    mFBOQueueSize = 1;
899 edea9cf3 Leszek Koltunski
900 a9d4bb9a Leszek Koltunski
    if( mVendor.contains("ARM") )
901 edea9cf3 Leszek Koltunski
      {
902 5f35f1cb Leszek Koltunski
      try
903 edea9cf3 Leszek Koltunski
        {
904 5f35f1cb Leszek Koltunski
        String regex = ".*r(\\d+)p\\d.*";
905
        Pattern pattern = Pattern.compile(regex);
906 a9d4bb9a Leszek Koltunski
        Matcher matcher = pattern.matcher(mVersion);
907 5f35f1cb Leszek Koltunski
908
        if( matcher.find() )
909
          {
910
          String driverVersion = matcher.group(1);
911
912
          if( driverVersion!=null )
913
            {
914
            int drvVersion = Integer.parseInt(driverVersion);
915
916
            if( drvVersion<22 )
917
              {
918
              Log.e("DISTORTED", "You are running this on a ARM Mali driver r"+driverVersion+".\n" +
919
                    "This is a buggy driver, please update to r22. Inserting workaround which uses a lot of memory.");
920
921
              mFBOQueueSize = queueSize;
922
              }
923
            }
924
          }
925
        }
926
      catch(Exception ex)
927
        {
928
        android.util.Log.e("library", "exception trying to pattern match version: "+ex.toString());
929 edea9cf3 Leszek Koltunski
        }
930
      }
931 a9d4bb9a Leszek Koltunski
    else if( mVendor.contains("Imagination") )
932 edea9cf3 Leszek Koltunski
      {
933 a9d4bb9a Leszek Koltunski
      if( mRenderer.contains("GE8") )
934 edea9cf3 Leszek Koltunski
        {
935 b7074bc6 Leszek Koltunski
        Log.e("DISTORTED", "You are running this on a PowerVR GE8XXX.\nDue to a buggy compiler OIT rendering will not work");
936 a79650a2 Leszek Koltunski
        Log.e("DISTORTED", "GLSL Version "+GLES30.glGetString(GLES31.GL_SHADING_LANGUAGE_VERSION));
937 edea9cf3 Leszek Koltunski
        }
938
      }
939 a9d4bb9a Leszek Koltunski
    else if( mVendor.contains("Qualcomm"))
940 97b6c85e Leszek Koltunski
      {
941 a9d4bb9a Leszek Koltunski
      if( mVersion.contains("V@331.0") )
942 97b6c85e Leszek Koltunski
        {
943
        Log.e("DISTORTED", "You are running this on an Adreno 3xx driver version 331.\nStrange shit might happen.");
944 eff6e3d3 Leszek Koltunski
        mBuggyUBOs = true;
945 97b6c85e Leszek Koltunski
        }
946
      }
947 edea9cf3 Leszek Koltunski
    }
948
949 b7074bc6 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
950
/**
951
 * Return OpenGL ES version supported by the hardware we are running on.
952 60fdf71d Leszek Koltunski
 * There are only three possibilities: 300 (OpenGL ES 3.0) or 310 (at least OpenGL ES 3.1)
953
 * or 200 (OpenGL ES 2.0)
954 b7074bc6 Leszek Koltunski
 */
955 60fdf71d Leszek Koltunski
  public static int getGLSL()
956 b7074bc6 Leszek Koltunski
    {
957
    return mGLSL;
958
    }
959
960 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
961
/**
962 c43abe6c Leszek Koltunski
 * When OpenGL context gets created, call this method so that the library can initialise its internal data structures.
963 9519d1b1 Leszek Koltunski
 * I.e. best called from GLSurfaceView.Renderer.onSurfaceCreated().
964 6a06a912 Leszek Koltunski
 * <p>
965 432442f9 Leszek Koltunski
 * Needs to be called from a thread holding the OpenGL context.
966 5f35f1cb Leszek Koltunski
 *
967 9ec374e8 Leszek Koltunski
 * @param context  Context of the App using the library - used to open up Resources and read Shader code.
968 d99fcc9c Leszek Koltunski
 * @param listener The library will send all (asynchronous!) exceptions there.
969 6a06a912 Leszek Koltunski
 */
970 9519d1b1 Leszek Koltunski
  public static void onSurfaceCreated(final Context context, final ExceptionListener listener)
971 5f35f1cb Leszek Koltunski
    {
972 9519d1b1 Leszek Koltunski
    onSurfaceCreated(context,listener,4);
973 5f35f1cb Leszek Koltunski
    }
974
975
///////////////////////////////////////////////////////////////////////////////////////////////////
976
/**
977
 * When OpenGL context gets created, call this method so that the library can initialise its internal data structures.
978 9519d1b1 Leszek Koltunski
 * I.e. best called from GLSurfaceView.Renderer.onSurfaceCreated().
979 5f35f1cb Leszek Koltunski
 * <p>
980
 * Needs to be called from a thread holding the OpenGL context.
981
 *   
982 9ec374e8 Leszek Koltunski
 * @param context   Context of the App using the library - used to open up Resources and read Shader code.
983
 * @param listener  The library will send all (asynchronous!) exceptions there.
984 9519d1b1 Leszek Koltunski
 * @param queueSize the size of the FBO queue, a workaround for the bug on Mali drivers. Use a small integer - 1,...,4
985 5f35f1cb Leszek Koltunski
 */
986 9519d1b1 Leszek Koltunski
  public static void onSurfaceCreated(final Context context, final ExceptionListener listener, int queueSize)
987 d6e94c84 Leszek Koltunski
    {
988 30beb34f Leszek Koltunski
    final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
989
    final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
990 b7074bc6 Leszek Koltunski
991
    int glESversion = configurationInfo.reqGlEsVersion;
992
    int major = glESversion >> 16;
993
    int minor = glESversion & 0xff;
994
995 d99fcc9c Leszek Koltunski
    mListener = listener;
996
997 b7074bc6 Leszek Koltunski
    if( major< 3 )
998
      {
999
      mGLSL = 100*major + 10*minor;
1000 d99fcc9c Leszek Koltunski
      VertexCompilationException ex = new VertexCompilationException("at least OpenGL ES 3.0 required, this device supports only "+major+"."+minor);
1001
      mListener.distortedException(ex);
1002 b7074bc6 Leszek Koltunski
      }
1003
    else
1004
      {
1005
      mGLSL = (major==3 && minor==0) ? 300 : 310;
1006
      }
1007
1008 78ff6ea9 Leszek Koltunski
    int[] tmp = new int[1];
1009
    GLES30.glGetIntegerv(GLES30.GL_MAX_TEXTURE_SIZE, tmp, 0);
1010
    mMaxTextureSize = tmp[0];
1011
    GLES30.glGetIntegerv(GLES30.GL_MAX_VERTEX_UNIFORM_VECTORS  , tmp, 0);
1012
    mMaxNumberOfVerUniforms = tmp[0];
1013
    GLES30.glGetIntegerv(GLES30.GL_MAX_FRAGMENT_UNIFORM_VECTORS, tmp, 0);
1014
    mMaxNumberOfFraUniforms = tmp[0];
1015 2bd3d0fb Leszek Koltunski
1016 b7074bc6 Leszek Koltunski
    android.util.Log.e("DISTORTED", "Using OpenGL ES "+major+"."+minor);
1017 8f011621 Leszek Koltunski
/*
1018 78ff6ea9 Leszek Koltunski
    android.util.Log.e("DISTORTED", "max texture size: "+mMaxTextureSize);
1019
    android.util.Log.e("DISTORTED", "max num vert: "+mMaxNumberOfVerUniforms);
1020
    android.util.Log.e("DISTORTED", "max num frag: "+mMaxNumberOfFraUniforms);
1021 8f011621 Leszek Koltunski
*/
1022 b7074bc6 Leszek Koltunski
    mGLSL_VERSION = "#version "+mGLSL+" es\n";
1023 edea9cf3 Leszek Koltunski
1024 9ec374e8 Leszek Koltunski
    InternalStackFrameList.setInitialized(true);
1025 d99fcc9c Leszek Koltunski
    mOITCompilationAttempted = false;
1026 edea9cf3 Leszek Koltunski
1027 5f35f1cb Leszek Koltunski
    detectBuggyDriversAndSetQueueSize(queueSize);
1028 0e924ba5 Leszek Koltunski
    EffectMessageSender.startSending();
1029
1030 d99fcc9c Leszek Koltunski
    mResources = context.getResources();
1031 edea9cf3 Leszek Koltunski
1032
    try
1033
      {
1034 d99fcc9c Leszek Koltunski
      createMainProgram();
1035 edea9cf3 Leszek Koltunski
      }
1036
    catch(Exception ex)
1037
      {
1038 d99fcc9c Leszek Koltunski
      mListener.distortedException(ex);
1039 edea9cf3 Leszek Koltunski
      }
1040
1041 f046b159 Leszek Koltunski
    try
1042
      {
1043 d99fcc9c Leszek Koltunski
      EffectQueuePostprocess.createPrograms(mResources, mGLSL);
1044 f046b159 Leszek Koltunski
      }
1045
    catch(Exception ex)
1046
      {
1047 d99fcc9c Leszek Koltunski
      mListener.distortedException(ex);
1048 a13dde77 Leszek Koltunski
      }
1049
1050 edea9cf3 Leszek Koltunski
    try
1051
      {
1052 b7074bc6 Leszek Koltunski
      PostprocessEffect.createPrograms(mGLSL);
1053 edea9cf3 Leszek Koltunski
      }
1054
    catch(Exception ex)
1055
      {
1056 d99fcc9c Leszek Koltunski
      mListener.distortedException(ex);
1057 edea9cf3 Leszek Koltunski
      }
1058 6a06a912 Leszek Koltunski
    }
1059
1060 9ec374e8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1061
/**
1062
 * Call this so that the Library can initialize its internal data structures.
1063
 * Must be called from Activity.onCreate().
1064
 */
1065
  public static void onCreate()
1066
    {
1067
    onCreate(0);
1068
    }
1069
1070
///////////////////////////////////////////////////////////////////////////////////////////////////
1071
/**
1072
 * Call this so that the Library can initialize its internal data structures.
1073
 * Must be called from Activity.onCreate().
1074
 *
1075
 * @param id id of an Activity that is using the library; anything unique so that the Library can
1076
 *           tell between Activities in case you're going to be using it from more than one.
1077
 */
1078
  public static void onCreate(long id)
1079
    {
1080
    InternalStackFrameList.onCreate(id);
1081
    }
1082
1083
///////////////////////////////////////////////////////////////////////////////////////////////////
1084
/**
1085
 * Call this so that the Library can resume its operations.
1086
 * Must be called from Activity.onResume().
1087
 */
1088
  public static void onResume()
1089
    {
1090
    onCreate(0);
1091
    }
1092
1093
///////////////////////////////////////////////////////////////////////////////////////////////////
1094
/**
1095
 * Call this so that the Library can resume its operations.
1096
 * Must be called from Activity.onResume().
1097
 *
1098
 * @param id id of an Activity that is using the library; anything unique so that the Library can
1099
 *           tell between Activities in case you're going to be using it from more than one.
1100
 */
1101
  public static void onResume(long id)
1102
    {
1103
    InternalStackFrameList.onResume(id);
1104
    }
1105
1106 05ecc6fe Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1107
/**
1108 78e89fb5 Leszek Koltunski
 * Call this so that the Library can release the OpenGL related data that needs to be recreated.
1109 05ecc6fe Leszek Koltunski
 * Must be called from Activity.onPause().
1110
 */
1111
  public static void onPause()
1112
    {
1113 9ec374e8 Leszek Koltunski
    onPause(0);
1114
    }
1115
1116
///////////////////////////////////////////////////////////////////////////////////////////////////
1117
/**
1118
 * Call this so that the Library can release the OpenGL related data that needs to be recreated.
1119
 * Must be called from Activity.onPause().
1120
 *
1121
 * @param id id of an Activity that is using the library; anything unique so that the Library can
1122
 *           tell between Activities in case you're going to be using it from more than one.
1123
 */
1124
  public static void onPause(long id)
1125
    {
1126
    InternalStackFrameList.onPause(id);
1127 30094332 Leszek Koltunski
    Dynamic.onPause();  // common for all frames
1128 c8dbce40 Leszek Koltunski
1129 bfe45b4a Leszek Koltunski
    mLinkedListSSBO[0]= -1;
1130 5f35f1cb Leszek Koltunski
    mAtomicCounter = null;
1131 fd836a41 Leszek Koltunski
1132 d99fcc9c Leszek Koltunski
    mNormalProgram     = null;
1133
    mMainOITProgram    = null;
1134
    mMainProgram       = null;
1135
    mFullProgram       = null;
1136
    mOITClearProgram   = null;
1137
    mOITBuildProgram   = null;
1138
    mOITCollapseProgram= null;
1139
    mOITRenderProgram  = null;
1140
    mBlitDepthProgram  = null;
1141
    mBlitProgram       = null;
1142 6a06a912 Leszek Koltunski
    }
1143 bfe45b4a Leszek Koltunski
1144 c8dbce40 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1145
/**
1146
 * Call this so that the Library can release its internal data structures.
1147 9ec374e8 Leszek Koltunski
 * Must be called from Activity.onDestroy().
1148 c8dbce40 Leszek Koltunski
 */
1149
  public static void onDestroy()
1150
    {
1151 9ec374e8 Leszek Koltunski
    onDestroy(0);
1152
    }
1153
1154
///////////////////////////////////////////////////////////////////////////////////////////////////
1155
/**
1156
 * Call this so that the Library can release its internal data structures.
1157
 * Must be called from Activity.onDestroy().
1158
 *
1159
 * @param id id of an Activity that is using the library; anything unique so that the Library can
1160
 *           tell between Activities in case you're going to be using it from more than one.
1161
 */
1162
  public static void onDestroy(long id)
1163
    {
1164
    if( InternalStackFrameList.isInitialized() )
1165 c8dbce40 Leszek Koltunski
      {
1166 9ec374e8 Leszek Koltunski
      InternalStackFrameList.onDestroy(id);
1167 3bbe4d67 Leszek Koltunski
1168
      InternalOutputSurface.onDestroy(); // those three really destroy
1169
      Effect.onDestroy();                // static data that does not
1170
      DeferredJobs.onDestroy();          // need to be part of a frame
1171 30094332 Leszek Koltunski
1172
      mOITCompilationAttempted = false;
1173 ddd46f8b Leszek Koltunski
      mNeedsTransformFeedback  = false;
1174 c8dbce40 Leszek Koltunski
      }
1175
    }
1176
1177 2bd3d0fb Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1178
/**
1179
 * Return the maximum size of the texture supported by the driver.
1180
 */
1181
  public static int getMaxTextureSize()
1182
    {
1183
    return mMaxTextureSize;
1184
    }
1185
1186 97b6c85e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1187
/**
1188
 * Call this before calling onSurfaceCreated() if you want to access normal vectors in CPU.
1189
 */
1190
  public static void needTransformFeedback()
1191
    {
1192
    mNeedsTransformFeedback = true;
1193
    }
1194
1195 bfe45b4a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1196
/**
1197
 * Returns the maximum number of effects of a given type that can be simultaneously applied to a
1198
 * single (InputSurface,MeshBase) combo.
1199
 *
1200
 * @param type {@link EffectType}
1201
 * @return The maximum number of effects of a given type.
1202
 */
1203
  @SuppressWarnings("unused")
1204
  public static int getMax(EffectType type)
1205
    {
1206
    return EffectQueue.getMax(type.ordinal());
1207
    }
1208
1209
///////////////////////////////////////////////////////////////////////////////////////////////////
1210
/**
1211
 * Sets the maximum number of effects that can be stored in a single EffectQueue at one time.
1212
 * This can fail if:
1213
 * <ul>
1214
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
1215
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
1216 9519d1b1 Leszek Koltunski
 *     before the Vertex Shader gets compiled, i.e. before the call to {@link DistortedLibrary#onSurfaceCreated}. After this
1217 bfe45b4a Leszek Koltunski
 *     time only decreasing the value of 'max' is permitted.
1218
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
1219
 * </ul>
1220
 *
1221
 * @param type {@link EffectType}
1222
 * @param max new maximum number of simultaneous effects. Has to be a non-negative number not greater
1223
 *            than Byte.MAX_VALUE
1224
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
1225
 */
1226
  @SuppressWarnings("unused")
1227
  public static boolean setMax(EffectType type, int max)
1228
    {
1229
    return EffectQueue.setMax(type.ordinal(),max);
1230
    }
1231 a9d4bb9a Leszek Koltunski
1232
///////////////////////////////////////////////////////////////////////////////////////////////////
1233
/**
1234
 * Return a String defining the vendor of the graphics driver.
1235
 */
1236
  public static String getDriverVendor()
1237
    {
1238
    return mVendor;
1239
    }
1240
1241
///////////////////////////////////////////////////////////////////////////////////////////////////
1242
/**
1243
 * Return a String defining the version of the graphics driver.
1244
 */
1245
  public static String getDriverVersion()
1246
    {
1247
    return mVersion;
1248
    }
1249
1250
///////////////////////////////////////////////////////////////////////////////////////////////////
1251
/**
1252
 * Return a String defining the renderer of the graphics driver.
1253
 */
1254
  public static String getDriverRenderer()
1255
    {
1256
    return mRenderer;
1257
    }
1258 f8f6d457 leszek
  }