Project

General

Profile

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

library / src / main / java / org / distorted / library / main / DistortedLibrary.java @ 5ec42229

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