Project

General

Profile

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

library / src / main / java / org / distorted / library / main / InternalOutputSurface.java @ 1dec66e0

1 c5369f1b leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
2 2e569ff6 Leszek Koltunski
// Copyright 2016 Leszek Koltunski  leszek@koltunski.pl                                          //
3 c5369f1b leszek
//                                                                                               //
4 46b572b5 Leszek Koltunski
// This file is part of Distorted.                                                               //
5 c5369f1b leszek
//                                                                                               //
6 2e569ff6 Leszek Koltunski
// This library is free software; you can redistribute it and/or                                 //
7
// modify it under the terms of the GNU Lesser General Public                                    //
8
// License as published by the Free Software Foundation; either                                  //
9
// version 2.1 of the License, or (at your option) any later version.                            //
10 c5369f1b leszek
//                                                                                               //
11 2e569ff6 Leszek Koltunski
// This library is distributed in the hope that it will be useful,                               //
12 c5369f1b leszek
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13 2e569ff6 Leszek Koltunski
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                             //
14
// Lesser General Public License for more details.                                               //
15 c5369f1b leszek
//                                                                                               //
16 2e569ff6 Leszek Koltunski
// You should have received a copy of the GNU Lesser General Public                              //
17
// License along with this library; if not, write to the Free Software                           //
18
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA                //
19 c5369f1b leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
20
21 fe82a979 Leszek Koltunski
package org.distorted.library.main;
22 c5369f1b leszek
23 b7074bc6 Leszek Koltunski
import android.opengl.GLES30;
24 e6519ac8 Leszek Koltunski
import android.opengl.GLES31;
25 86e99907 leszek
26 3521c6fe leszek
import org.distorted.library.effect.EffectQuality;
27 809dcae3 Leszek Koltunski
import org.distorted.library.effectqueue.EffectQueuePostprocess;
28 1dec66e0 Leszek Koltunski
import org.distorted.library.helpers.MatrixHelper;
29 715e7726 Leszek Koltunski
import org.distorted.library.mesh.MeshBase;
30 3521c6fe leszek
31 af4cc5db Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
32 70b6a155 Leszek Koltunski
/**
33
 * This is not really part of the public API.
34
 *
35
 * @y.exclude
36
 */
37 7602a827 Leszek Koltunski
public abstract class InternalOutputSurface extends InternalSurface implements InternalChildrenList.Parent
38 af4cc5db Leszek Koltunski
{
39 23eecbd9 Leszek Koltunski
  public static final int NO_DEPTH_NO_STENCIL = 0;
40
  public static final int DEPTH_NO_STENCIL    = 1;
41
  public static final int BOTH_DEPTH_STENCIL  = 2;
42 89de975c leszek
43 66103fb2 Leszek Koltunski
  static final float DEFAULT_FOV = 60.0f;
44
  static final float DEFAULT_NEAR=  0.1f;
45 209ea1c7 Leszek Koltunski
46 66103fb2 Leszek Koltunski
  private float mFOV;
47 d58407a8 Leszek Koltunski
  private final int mTmpFBO;
48 66103fb2 Leszek Koltunski
49
  private long[] mTime;
50
  private float mClearR, mClearG, mClearB, mClearA, mClearDepth;
51
  private int mClear, mClearStencil;
52
  private boolean mRenderWayOIT;
53 d58407a8 Leszek Koltunski
  private final InternalChildrenList mChildren;
54 66103fb2 Leszek Koltunski
55
  // Global buffers used for postprocessing
56 d58407a8 Leszek Koltunski
  private final static DistortedFramebuffer[] mBuffer= new DistortedFramebuffer[EffectQuality.LENGTH];
57 178983f4 Leszek Koltunski
  private final boolean[] mBufferInitialized;
58 66103fb2 Leszek Koltunski
59
  float mDistance, mNear, mMipmap;
60 af4cc5db Leszek Koltunski
  float[] mProjectionMatrix;
61 46b572b5 Leszek Koltunski
  int mDepthStencilCreated, mDepthStencil;
62
  int[] mDepthStencilH, mFBOH;
63
  int mRealWidth;   // the Surface can be backed up by a texture larger than the viewport we have to it.
64
  int mRealHeight;  // mWidth,mHeight are the sizes of the Viewport, those - sizes of the backing up texture.
65 7602a827 Leszek Koltunski
  int mCurrFBO;     // internal current FBO (see DistortedLibrary.FBO_QUEUE_SIZE)
66 d58b50e7 Leszek Koltunski
  int mWidth, mHeight;
67 5f7e4f2c Leszek Koltunski
68 1dec66e0 Leszek Koltunski
static final float[] tmpM = new float[16];
69
70 af4cc5db Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
71
72 9ec374e8 Leszek Koltunski
  InternalOutputSurface(int width, int height, int createColor, int numfbos, int numcolors, int depthStencil, int fbo, int type, int storage)
73 af4cc5db Leszek Koltunski
    {
74 9ec374e8 Leszek Koltunski
    super(createColor,numfbos,numcolors,type,storage);
75 8ebbc730 Leszek Koltunski
76 406e2f6b Leszek Koltunski
    mRenderWayOIT = false;
77 5f7e4f2c Leszek Koltunski
    mCurrFBO      = 0;
78 406e2f6b Leszek Koltunski
79 d58b50e7 Leszek Koltunski
    mRealWidth = mWidth = width;
80
    mRealHeight= mHeight= height;
81 a4b182d4 Leszek Koltunski
82 af4cc5db Leszek Koltunski
    mProjectionMatrix = new float[16];
83
84 209ea1c7 Leszek Koltunski
    mFOV = DEFAULT_FOV;
85
    mNear= DEFAULT_NEAR;
86 af4cc5db Leszek Koltunski
87 23eecbd9 Leszek Koltunski
    mDepthStencilCreated= (depthStencil== NO_DEPTH_NO_STENCIL ? DONT_CREATE:NOT_CREATED_YET);
88 89de975c leszek
    mDepthStencil = depthStencil;
89
90 a9f41fa3 leszek
    mClearR = 0.0f;
91
    mClearG = 0.0f;
92
    mClearB = 0.0f;
93
    mClearA = 0.0f;
94
95
    mClearDepth = 1.0f;
96 23eecbd9 Leszek Koltunski
    mClearStencil = 0;
97 b7074bc6 Leszek Koltunski
    mClear = GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT;
98 a9f41fa3 leszek
99 8426bd6a Leszek Koltunski
    mMipmap = 1.0f;
100 78db8663 Leszek Koltunski
101 7602a827 Leszek Koltunski
    mChildren = new InternalChildrenList(this);
102 11845a9e Leszek Koltunski
103 5f35f1cb Leszek Koltunski
    mTmpFBO = fbo;
104
105 fdb60725 Leszek Koltunski
    mFBOH = new int[10];  // Crashlytics shows the library occasionally crashing in setAsOutput()
106
    mTime = new long[10]; // when trying to read from 'null array' mFBOH. Probably sometimes a
107
                          // a Framebuffer gets created in the wrong moment, just after we did a
108
                          // round of create(), but before we start rendering.
109
                          // Create an empty FBO and Time here so that setAsOutput() is always safe to call.
110
111 178983f4 Leszek Koltunski
    mBufferInitialized = new boolean[EffectQuality.LENGTH];
112
113 5f35f1cb Leszek Koltunski
    allocateStuffDependantOnNumFBOS();
114 af4cc5db Leszek Koltunski
    createProjection();
115
    }
116
117 5f35f1cb Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
118
119
  void allocateStuffDependantOnNumFBOS()
120
    {
121
    if( mNumFBOs>0 )
122
      {
123
      mDepthStencilH   = new int[mNumFBOs];
124
      mDepthStencilH[0]= 0;
125
126
      mFBOH   = new int[mNumFBOs];
127
      mFBOH[0]= mTmpFBO;
128
129
      mTime = new long[mNumFBOs];
130
      for(int i=0; i<mNumFBOs;i++) mTime[i]=0;
131
      }
132
    }
133
134 c5369f1b leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
135
136 be60d4ff leszek
  private void createProjection()
137 af4cc5db Leszek Koltunski
    {
138
    if( mWidth>0 && mHeight>1 )
139
      {
140
      if( mFOV>0.0f )  // perspective projection
141
        {
142 54fe333a leszek
        float a = 2.0f*(float)Math.tan(mFOV*Math.PI/360);
143 8426bd6a Leszek Koltunski
        float q = mWidth*mNear;
144
        float c = mHeight*mNear;
145 54fe333a leszek
146 c2c08950 leszek
        float left   = -q/2;
147
        float right  = +q/2;
148
        float bottom = -c/2;
149
        float top    = +c/2;
150
        float near   =  c/a;
151 54fe333a leszek
152 8426bd6a Leszek Koltunski
        mDistance    = mHeight/a;
153 af4cc5db Leszek Koltunski
        float far    = 2*mDistance-near;
154
155 1dec66e0 Leszek Koltunski
        MatrixHelper.frustum(mProjectionMatrix, left, right, bottom, top, near, far);
156 af4cc5db Leszek Koltunski
        }
157
      else             // parallel projection
158
        {
159 8426bd6a Leszek Koltunski
        float left   = -mWidth/2.0f;
160
        float right  = +mWidth/2.0f;
161
        float bottom = -mHeight/2.0f;
162
        float top    = +mHeight/2.0f;
163
        float near   = mWidth+mHeight-mHeight*(1.0f-mNear);
164
        mDistance    = mWidth+mHeight;
165
        float far    = mWidth+mHeight+mHeight*(1.0f-mNear);
166 af4cc5db Leszek Koltunski
167 1dec66e0 Leszek Koltunski
        MatrixHelper.ortho(mProjectionMatrix, left, right, bottom, top, near, far);
168 af4cc5db Leszek Koltunski
        }
169
      }
170
    }
171
172 1d6d261e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
173
174 66103fb2 Leszek Koltunski
  private static void createPostprocessingBuffers(int quality, int width, int height, float near)
175 1d6d261e Leszek Koltunski
    {
176 8b7b2398 Leszek Koltunski
    final float CLEAR_R = 1.0f;
177
    final float CLEAR_G = 1.0f;
178
    final float CLEAR_B = 1.0f;
179
    final float CLEAR_A = 0.0f;
180
    final float CLEAR_D = 1.0f;
181
    final int   CLEAR_S = 0;
182
183 5f35f1cb Leszek Koltunski
    final int queueSize = DistortedLibrary.getQueueSize();
184 1d6d261e Leszek Koltunski
    float mipmap=1.0f;
185
186 66103fb2 Leszek Koltunski
    for (int j=0; j<quality; j++) mipmap *= EffectQuality.MULTIPLIER;
187 a4b182d4 Leszek Koltunski
188 9ec374e8 Leszek Koltunski
    mBuffer[quality] = new DistortedFramebuffer(queueSize,2,BOTH_DEPTH_STENCIL,TYPE_SYST, STORAGE_COMMON, (int)(width*mipmap), (int)(height*mipmap) );
189 66103fb2 Leszek Koltunski
    mBuffer[quality].mMipmap = mipmap;
190
    mBuffer[quality].mNear = near;  // copy mNear as well (for blitting- see PostprocessEffect.apply() )
191
    mBuffer[quality].glClearColor(CLEAR_R, CLEAR_G, CLEAR_B, CLEAR_A);
192 1d6d261e Leszek Koltunski
193 9ec374e8 Leszek Koltunski
    InternalStackFrameList.toDo(); // create the FBOs immediately. This is safe as we must be holding the OpenGL context now.
194 1d6d261e Leszek Koltunski
195 7602a827 Leszek Koltunski
    InternalRenderState.colorDepthStencilOn();
196 b7074bc6 Leszek Koltunski
    GLES30.glClearColor(CLEAR_R, CLEAR_G, CLEAR_B, CLEAR_A);
197
    GLES30.glClearDepthf(CLEAR_D);
198
    GLES30.glClearStencil(CLEAR_S);
199 1d6d261e Leszek Koltunski
200 5f35f1cb Leszek Koltunski
    for(int k=0; k<queueSize; k++)
201 1d6d261e Leszek Koltunski
      {
202 b7074bc6 Leszek Koltunski
      GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mBuffer[quality].mFBOH[k]);
203
      GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, mBuffer[quality].mColorH[2*k+1], 0);
204
      GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT | GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_STENCIL_BUFFER_BIT);
205
      GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, mBuffer[quality].mColorH[2*k  ], 0);
206
      GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
207 1d6d261e Leszek Koltunski
      }
208 586b5fa1 Leszek Koltunski
209 7602a827 Leszek Koltunski
    InternalRenderState.colorDepthStencilRestore();
210 8b7b2398 Leszek Koltunski
211 b7074bc6 Leszek Koltunski
    GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0);
212 1d6d261e Leszek Koltunski
    }
213
214 a4b182d4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
215
216 8d98b65f Leszek Koltunski
  static synchronized void onPause()
217 a4b182d4 Leszek Koltunski
    {
218 66103fb2 Leszek Koltunski
    for (int j=0; j<EffectQuality.LENGTH; j++)
219
      if( mBuffer[j]!=null )
220 df5f8dd9 Leszek Koltunski
        {
221 66103fb2 Leszek Koltunski
        mBuffer[j].markForDeletion();
222 df5f8dd9 Leszek Koltunski
        mBuffer[j] = null;
223
        }
224 ce154014 Leszek Koltunski
    }
225 a4b182d4 Leszek Koltunski
226 97020807 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
227
228 7602a827 Leszek Koltunski
  private int blitWithDepth(long currTime, InternalOutputSurface buffer, int fbo)
229 97020807 Leszek Koltunski
    {
230 b7074bc6 Leszek Koltunski
    GLES30.glViewport(0, 0, mWidth, mHeight);
231 5f7e4f2c Leszek Koltunski
    setAsOutput(currTime);
232 b7074bc6 Leszek Koltunski
    GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
233
    GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, buffer.mColorH[2*fbo]);
234
    GLES30.glActiveTexture(GLES30.GL_TEXTURE1);
235
    GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, buffer.mDepthStencilH[fbo]);
236 97020807 Leszek Koltunski
237 b7074bc6 Leszek Koltunski
    GLES30.glDisable(GLES30.GL_STENCIL_TEST);
238
    GLES30.glStencilMask(0x00);
239 97020807 Leszek Koltunski
240 7602a827 Leszek Koltunski
    DistortedLibrary.blitDepthPriv(this, buffer.getWidthCorrection(), buffer.getHeightCorrection() );
241 b7074bc6 Leszek Koltunski
    GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
242
    GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
243
    GLES30.glActiveTexture(GLES30.GL_TEXTURE1);
244
    GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
245 97020807 Leszek Koltunski
246
    // clear buffers
247 b7074bc6 Leszek Koltunski
    GLES30.glStencilMask(0xff);
248
    GLES30.glDepthMask(true);
249
    GLES30.glColorMask(true,true,true,true);
250
    GLES30.glClearColor(buffer.mClearR,buffer.mClearG,buffer.mClearB,buffer.mClearA);
251
    GLES30.glClearDepthf(buffer.mClearDepth);
252
    GLES30.glClearStencil(buffer.mClearStencil);
253 97020807 Leszek Koltunski
254 5f7e4f2c Leszek Koltunski
    buffer.setAsOutput();
255 b7074bc6 Leszek Koltunski
    GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, buffer.mColorH[2*fbo+1], 0);
256
    GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT|GLES30.GL_DEPTH_BUFFER_BIT|GLES30.GL_STENCIL_BUFFER_BIT);
257
    GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, buffer.mColorH[2*fbo  ], 0);
258
    GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
259 97020807 Leszek Koltunski
260
    return 1;
261
    }
262
263 66a0fa17 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
264
265 7602a827 Leszek Koltunski
  private static void oitClear(InternalOutputSurface buffer)
266 66a0fa17 Leszek Koltunski
    {
267 7602a827 Leszek Koltunski
    int counter = DistortedLibrary.zeroOutAtomic();
268
    DistortedLibrary.oitClear(buffer,counter);
269 66a0fa17 Leszek Koltunski
    GLES31.glMemoryBarrier(GLES31.GL_SHADER_STORAGE_BARRIER_BIT|GLES31.GL_ATOMIC_COUNTER_BARRIER_BIT);
270
    }
271
272 6b962e80 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
273
274 7602a827 Leszek Koltunski
  private int oitBuild(long time, InternalOutputSurface buffer, int fbo)
275 6b962e80 Leszek Koltunski
    {
276 b7074bc6 Leszek Koltunski
    GLES30.glViewport(0, 0, mWidth, mHeight);
277 5f7e4f2c Leszek Koltunski
    setAsOutput(time);
278 b7074bc6 Leszek Koltunski
    GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
279
    GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, buffer.mColorH[2*fbo]);
280
    GLES30.glActiveTexture(GLES30.GL_TEXTURE1);
281
    GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, buffer.mDepthStencilH[fbo]);
282 6b962e80 Leszek Koltunski
283 7602a827 Leszek Koltunski
    InternalRenderState.colorDepthStencilOn();
284
    InternalRenderState.enableDepthTest();
285 6b962e80 Leszek Koltunski
286 7602a827 Leszek Koltunski
    DistortedLibrary.oitBuild(this, buffer.getWidthCorrection(), buffer.getHeightCorrection() );
287 b7074bc6 Leszek Koltunski
    GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
288
    GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
289
    GLES30.glActiveTexture(GLES30.GL_TEXTURE1);
290
    GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
291 6b962e80 Leszek Koltunski
292 7602a827 Leszek Koltunski
    InternalRenderState.colorDepthStencilRestore();
293
    InternalRenderState.restoreDepthTest();
294 56c6ca24 Leszek Koltunski
295 8777ce17 Leszek Koltunski
    return 1;
296
    }
297
298
///////////////////////////////////////////////////////////////////////////////////////////////////
299 baa3989b Leszek Koltunski
// two phases: 1. collapse the SSBO 2. blend the ssbo's color
300 8777ce17 Leszek Koltunski
301 1f19fba8 Leszek Koltunski
  private int oitRender(long currTime, int fbo)
302 8777ce17 Leszek Koltunski
    {
303 c207da02 Leszek Koltunski
    float corrW = getWidthCorrection();
304
    float corrH = getHeightCorrection();
305 c8d70463 Leszek Koltunski
306 5fdae11d Leszek Koltunski
    // Do the Collapse Pass only if we do have a Depth attachment.
307
    // Otherwise there's no point (in fact we then would create a feedback loop!)
308 88c7b603 Leszek Koltunski
309 1f19fba8 Leszek Koltunski
    if( mDepthStencilH[fbo] != 0 )
310 5fdae11d Leszek Koltunski
      {
311 b7074bc6 Leszek Koltunski
      GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0);
312
      GLES30.glActiveTexture(GLES30.GL_TEXTURE1);
313
      GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mDepthStencilH[fbo]);
314 7602a827 Leszek Koltunski
      InternalRenderState.switchOffColorDepthStencil();
315
      DistortedLibrary.oitCollapse(this, corrW, corrH);
316 b7074bc6 Leszek Koltunski
      GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
317 5fdae11d Leszek Koltunski
      }
318 8777ce17 Leszek Koltunski
319 5f7e4f2c Leszek Koltunski
    setAsOutput(currTime);
320 7602a827 Leszek Koltunski
    InternalRenderState.switchColorDepthOnStencilOff();
321
    DistortedLibrary.oitRender(this, corrW, corrH);
322
    InternalRenderState.restoreColorDepthStencil();
323 33f59f22 Leszek Koltunski
324 8777ce17 Leszek Koltunski
    return 1;
325
    }
326
327 88c7b603 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
328
329 d5b709df Leszek Koltunski
  private void clear()
330 88c7b603 Leszek Koltunski
    {
331 7602a827 Leszek Koltunski
    InternalRenderState.colorDepthStencilOn();
332 b7074bc6 Leszek Koltunski
    GLES30.glClearColor(mClearR, mClearG, mClearB, mClearA);
333
    GLES30.glClearDepthf(mClearDepth);
334
    GLES30.glClearStencil(mClearStencil);
335
    GLES30.glClear(mClear);
336 7602a827 Leszek Koltunski
    InternalRenderState.colorDepthStencilRestore();
337 88c7b603 Leszek Koltunski
    }
338
339 5f7e4f2c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
340
341
  void setCurrFBO(int fbo)
342
    {
343
    mCurrFBO = fbo;
344
    }
345
346 178983f4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
347
// Render all children from the current bucket to the buffer, apply the postprocessing once to the
348
// whole buffer (queue.postprocess) and merge it to 'this' (oitBuild or blitWithDepth depending on
349
// the type of rendering)
350
351
  private int accumulateAndBlit(EffectQueuePostprocess queue, InternalChildrenList children, DistortedFramebuffer buffer,
352
                                int begIndex, int endIndex, boolean isFinal, long time, int fbo, boolean oit )
353
    {
354
    int numRenders = 0;
355
356
    for(int j=begIndex; j<endIndex; j++)
357
       {
358
       DistortedNode node = children.getChild(j);
359
360
       if( node.getSurface().setAsInput() )
361
         {
362
         buffer.setAsOutput();
363
         numRenders += queue.preprocess( buffer, node, buffer.mDistance, buffer.mMipmap, buffer.mProjectionMatrix );
364
         }
365
       }
366
    numRenders += queue.postprocess(buffer);
367
368
    if( oit )
369
      {
370
      numRenders += oitBuild(time, buffer, fbo);
371
      GLES31.glMemoryBarrier(GLES31.GL_SHADER_STORAGE_BARRIER_BIT | GLES31.GL_ATOMIC_COUNTER_BARRIER_BIT);
372
      buffer.clearBuffer(fbo);
373
      }
374
    else
375
      {
376
      numRenders += blitWithDepth(time, buffer, fbo);
377
      if( !isFinal ) buffer.clearBuffer(fbo);
378
      }
379
380
    return numRenders;
381
    }
382
383
///////////////////////////////////////////////////////////////////////////////////////////////////
384
385
  private int renderChildToThisOrToBuffer(DistortedNode child, DistortedFramebuffer buffer, long time, boolean oit, boolean toThis)
386
    {
387
    int numRenders;
388
389
    if( toThis )
390
      {
391
      setAsOutput(time);
392
393
      if( oit )
394
        {
395
        numRenders = child.drawOIT(time, this);
396
        GLES31.glMemoryBarrier(GLES31.GL_SHADER_STORAGE_BARRIER_BIT | GLES31.GL_ATOMIC_COUNTER_BARRIER_BIT);
397
        }
398
      else
399
        {
400
        numRenders = child.draw(time, this);
401
        }
402
      }
403
    else
404
      {
405
      buffer.setAsOutput(time);
406
      numRenders = child.drawNoBlend(time, buffer);
407
      }
408
409
    return numRenders;
410
    }
411
412
///////////////////////////////////////////////////////////////////////////////////////////////////
413
// The postprocessing buffers mBuffer[] are generally speaking too large (there's just one static
414
// set of them) so before we use them for output, we need to adjust the Viewport as if they were
415
// smaller. That takes care of outputting pixels to them. When we use them as input, we have to
416
// adjust the texture coords - see the get{Width|Height}Correction functions.
417
//
418
// Also, adjust the Buffers so their Projection is the same like the surface we are supposed to be
419
// rendering to.
420
421
  private void clonePostprocessingViewportAndProjection(InternalOutputSurface surface, InternalOutputSurface from)
422
    {
423
    if( surface.mWidth != from.mWidth || surface.mHeight != from.mHeight ||
424
        surface.mFOV   != from.mFOV   || surface.mNear   != from.mNear    )
425
      {
426
      surface.mWidth  = (int)(from.mWidth *surface.mMipmap);
427
      surface.mHeight = (int)(from.mHeight*surface.mMipmap);
428
      surface.mFOV    = from.mFOV;
429
      surface.mNear   = from.mNear;  // Near plane is independent of the mipmap level
430
431
      surface.createProjection();
432
433
      int maxw = Math.max(surface.mWidth , surface.mRealWidth );
434
      int maxh = Math.max(surface.mHeight, surface.mRealHeight);
435
436
      if (maxw > surface.mRealWidth || maxh > surface.mRealHeight)
437
        {
438
        surface.mRealWidth = maxw;
439
        surface.mRealHeight = maxh;
440
441
        surface.recreate();
442
        surface.create();
443
        }
444
      }
445
    }
446
447
///////////////////////////////////////////////////////////////////////////////////////////////////
448
449
  private DistortedFramebuffer initializeBuffer(EffectQueuePostprocess queue, int fbo )
450
    {
451
    int currQuality = queue.getQuality();
452
    if( mBuffer[currQuality]==null ) createPostprocessingBuffers(currQuality, mWidth, mHeight, mNear);
453
    mBuffer[currQuality].setCurrFBO(fbo);
454
455
    if( !mBufferInitialized[currQuality] )
456
      {
457
      mBufferInitialized[currQuality] = true;
458
      clonePostprocessingViewportAndProjection(mBuffer[currQuality],this);
459
      }
460
461
    return mBuffer[currQuality];
462
    }
463
464 af4cc5db Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
465 e02264ff leszek
// Render all children, one by one. If there are no postprocessing effects, just render to THIS.
466
// Otherwise, render to a buffer and on each change of Postprocessing Bucket, apply the postprocessing
467 9a3607b3 Leszek Koltunski
// to a whole buffer (lastQueue.postprocess) and merge it (this.oitBuild or blitWithDepth - depending
468
// on the type of rendering)
469 39086ebb leszek
470 7602a827 Leszek Koltunski
  int renderChildren(long time, int numChildren, InternalChildrenList children, int fbo, boolean oit)
471 b2939df4 Leszek Koltunski
    {
472 809dcae3 Leszek Koltunski
    int numRenders=0, bucketChange=0;
473 2386a081 Leszek Koltunski
    DistortedNode child;
474 809dcae3 Leszek Koltunski
    DistortedFramebuffer buffer=null;
475 70b6a155 Leszek Koltunski
    EffectQueuePostprocess lastQueue=null, currQueue;
476 33f59f22 Leszek Koltunski
    long lastBucket=0, currBucket;
477 178983f4 Leszek Koltunski
    boolean toThis=false;
478 56c6ca24 Leszek Koltunski
479 5f7e4f2c Leszek Koltunski
    setCurrFBO(fbo);
480 22d3c4b4 Leszek Koltunski
    if( numChildren==0 ) setAsOutput(time);
481 178983f4 Leszek Koltunski
    if( oit && numChildren>0 ) oitClear(this);
482
    for(int i=0; i<EffectQuality.LENGTH; i++) mBufferInitialized[i]=false;
483 c1a38ba3 Leszek Koltunski
484 8e28b6ff leszek
    for(int i=0; i<numChildren; i++)
485 39086ebb leszek
      {
486 11845a9e Leszek Koltunski
      child = children.getChild(i);
487 a0397f32 Leszek Koltunski
      currQueue = (EffectQueuePostprocess)child.getEffects().getQueues()[3];
488 70b6a155 Leszek Koltunski
      currBucket= currQueue.getID();
489 b9798977 leszek
490 178983f4 Leszek Koltunski
      if( currBucket!=0 && lastBucket!=currBucket )
491 56c6ca24 Leszek Koltunski
        {
492 178983f4 Leszek Koltunski
        buffer = initializeBuffer(currQueue,fbo);
493
        if( lastBucket!=0 ) numRenders += accumulateAndBlit(lastQueue,children,buffer,bucketChange,i,false,time,fbo,oit);
494
        bucketChange= i;
495
        toThis = currQueue.getRenderDirectly();
496 56c6ca24 Leszek Koltunski
        }
497 178983f4 Leszek Koltunski
      numRenders += renderChildToThisOrToBuffer(child,buffer,time,oit,currBucket==0 || toThis);
498
      if( currBucket!=0 && i==numChildren-1 ) numRenders += accumulateAndBlit(currQueue,children,buffer,bucketChange,numChildren,true,time,fbo,oit);
499 b9798977 leszek
500 70b6a155 Leszek Koltunski
      lastQueue = currQueue;
501
      lastBucket= currBucket;
502 c1a38ba3 Leszek Koltunski
      }
503
504 178983f4 Leszek Koltunski
    if( oit && numChildren>0 ) numRenders += oitRender(time, fbo);  // merge the OIT linked list
505
506 39086ebb leszek
    return numRenders;
507
    }
508
509 be60d4ff leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
510 11845a9e Leszek Koltunski
/**
511 d5b709df Leszek Koltunski
 * Not part of the public API.
512 11845a9e Leszek Koltunski
 *
513
 * @y.exclude
514
 */
515 d5b709df Leszek Koltunski
  public void adjustIsomorphism() { }
516 11845a9e Leszek Koltunski
517 ae2802b1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
518
/**
519
 * Not part of the Public API.
520
 *
521
 * @y.exclude
522
 */
523
  public float getWidthCorrection()
524
    {
525
    return (float)mWidth/mRealWidth;
526
    }
527
528
///////////////////////////////////////////////////////////////////////////////////////////////////
529
/**
530
 * Not part of the Public API.
531
 *
532
 * @y.exclude
533
 */
534
  public float getHeightCorrection()
535
    {
536
    return (float)mHeight/mRealHeight;
537
    }
538
539 61ce8e90 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
540
541 9e771d06 Leszek Koltunski
  void clearBuffer(int fbo)
542 61ce8e90 Leszek Koltunski
    {
543 7602a827 Leszek Koltunski
    InternalRenderState.colorDepthStencilOn();
544 a07e0204 Leszek Koltunski
545 b7074bc6 Leszek Koltunski
    GLES30.glClearColor(mClearR, mClearG, mClearB, mClearA);
546
    GLES30.glClearDepthf(mClearDepth);
547
    GLES30.glClearStencil(mClearStencil);
548 61ce8e90 Leszek Koltunski
549 b7074bc6 Leszek Koltunski
    GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[fbo]);
550
    GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, mColorH[2*fbo+1], 0);
551
    GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT|GLES30.GL_DEPTH_BUFFER_BIT|GLES30.GL_STENCIL_BUFFER_BIT);
552
    GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, mColorH[2*fbo  ], 0);
553
    GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
554 a07e0204 Leszek Koltunski
555 7602a827 Leszek Koltunski
    InternalRenderState.colorDepthStencilRestore();
556 61ce8e90 Leszek Koltunski
    }
557
558 809dcae3 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
559
560
  void setAsOutput(long time)
561
    {
562 b7074bc6 Leszek Koltunski
    GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[mCurrFBO]);
563 809dcae3 Leszek Koltunski
564
    if( mTime[mCurrFBO]!=time )
565
      {
566
      mTime[mCurrFBO] = time;
567
      clear();
568
      }
569
    }
570
571 b2939df4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
572
// PUBLIC API
573 39086ebb leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
574 c5369f1b leszek
/**
575 8ebbc730 Leszek Koltunski
 * Draws all the attached children to this OutputSurface's 0th FBO.
576 af4cc5db Leszek Koltunski
 * <p>
577
 * Must be called from a thread holding OpenGL Context.
578
 *
579 d9706fd2 Leszek Koltunski
 * @param time Current time, in milliseconds. This will be passed to all the Effects stored in the children Nodes.
580 7691a39f leszek
 * @return Number of objects rendered.
581 c5369f1b leszek
 */
582 b2939df4 Leszek Koltunski
  public int render(long time)
583 8ebbc730 Leszek Koltunski
    {
584
    return render(time,0);
585
    }
586
587
///////////////////////////////////////////////////////////////////////////////////////////////////
588
/**
589
 * Draws all the attached children to this OutputSurface.
590
 * <p>
591
 * Must be called from a thread holding OpenGL Context.
592
 *
593
 * @param time Current time, in milliseconds. This will be passed to all the Effects stored in the children Nodes.
594
 * @param fbo The surface can have many FBOs backing it up - render this to FBO number 'fbo'.
595
 * @return Number of objects rendered.
596
 */
597
  public int render(long time, int fbo)
598 af4cc5db Leszek Koltunski
    {
599 7602a827 Leszek Koltunski
    InternalMaster.toDo();
600 9ec374e8 Leszek Koltunski
    InternalStackFrameList.toDo();
601 7602a827 Leszek Koltunski
    InternalRenderState.reset();
602 2ed1c692 leszek
603 11845a9e Leszek Koltunski
    int numRenders=0, numChildren = mChildren.getNumChildren();
604 d5b709df Leszek Koltunski
    DistortedNode node;
605
    long oldBucket=0, newBucket;
606 7691a39f leszek
607 11845a9e Leszek Koltunski
    for(int i=0; i<numChildren; i++)
608 af4cc5db Leszek Koltunski
      {
609 d5b709df Leszek Koltunski
      node = mChildren.getChild(i);
610
      newBucket = node.getBucket();
611
      numRenders += node.renderRecursive(time);
612
      if( newBucket<oldBucket ) mChildren.rearrangeByBuckets(i,newBucket);
613
      else oldBucket=newBucket;
614 af4cc5db Leszek Koltunski
      }
615 7691a39f leszek
616 11845a9e Leszek Koltunski
    numRenders += renderChildren(time,numChildren,mChildren,fbo, mRenderWayOIT);
617 b2939df4 Leszek Koltunski
618 7691a39f leszek
    return numRenders;
619 af4cc5db Leszek Koltunski
    }
620
621 40f0cea6 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
622
/**
623
 * Recursively print all the effect queues attached to the children Nodes and to this Node.
624
 */
625
  public void debug()
626
    {
627
    int numChildren = mChildren.getNumChildren();
628
629
    for(int i=0; i<numChildren; i++)
630
      {
631
      DistortedNode node = mChildren.getChild(i);
632
      node.debug(0);
633
      }
634
    }
635
636 1dfc9074 leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
637
/**
638
 * Bind this Surface as a Framebuffer we can render to.
639
 * <p>
640
 * This version does not attempt to clear anything.
641
 */
642
  public void setAsOutput()
643
    {
644 b7074bc6 Leszek Koltunski
    GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[mCurrFBO]);
645 1dfc9074 leszek
    }
646
647
///////////////////////////////////////////////////////////////////////////////////////////////////
648
/**
649
 * Return the Near plane of the Projection included in the Surface.
650
 *
651
 * @return the Near plane.
652
 */
653
  public float getNear()
654
    {
655
    return mNear;
656
    }
657
658 638b5b5c leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
659
/**
660
 * Set mipmap level.
661
 * <p>
662
 * Trick for speeding up your renders - one can create a pyramid of OutputSurface objects, each next
663
 * one some constant FACTOR smaller than the previous (0.5 is the common value), then set the Mipmap
664
 * Level of the i-th object to be FACTOR^i (we start counting from 0). When rendering any scene into
665
 * such prepared OutputSurface, the library will make sure to scale any Effects used so that the end
666
 * scene will end up looking identical no matter which object we render to. Identical, that is, except
667
 * for the loss of quality and gain in speed associated with rendering to a smaller Surface.
668 8426bd6a Leszek Koltunski
 * <p>
669
 * Example: if you create two FBOs, one 1000x1000 and another 500x500 in size, and set the second one
670
 * mipmap to 0.5 (the first one's is 1.0 by default), define Effects to be a single move by (100,100),
671
 * and render a skinned Mesh into both FBO, the end result will look proportionally the same, because
672
 * in the second case the move vector (100,100) will be auto-scaled to (50,50).
673 638b5b5c leszek
 *
674
 * @param mipmap The mipmap level. Acceptable range: 0&lt;mipmap&lt;infinity, although mipmap&gt;1
675
 *               does not make any sense (that would result in loss of speed and no gain in quality)
676
 */
677
  public void setMipmap(float mipmap)
678
    {
679
    mMipmap = mipmap;
680
    }
681
682 a9f41fa3 leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
683
/**
684 e6519ac8 Leszek Koltunski
 * Set the (R,G,B,A) values of GLES31.glClearColor() to set up color with which to clear
685 ad16ed3b Leszek Koltunski
 * this Surface at the beginning of each frame.
686 a9f41fa3 leszek
 *
687
 * @param r the Red component. Default: 0.0f
688
 * @param g the Green component. Default: 0.0f
689
 * @param b the Blue component. Default: 0.0f
690
 * @param a the Alpha component. Default: 0.0f
691
 */
692
  public void glClearColor(float r, float g, float b, float a)
693
    {
694
    mClearR = r;
695
    mClearG = g;
696
    mClearB = b;
697
    mClearA = a;
698
    }
699
700
///////////////////////////////////////////////////////////////////////////////////////////////////
701
/**
702 23eecbd9 Leszek Koltunski
 * Uses glClearDepthf() to set up a value with which to clear
703
 * the Depth buffer of our Surface at the beginning of each frame.
704 a9f41fa3 leszek
 *
705
 * @param d the Depth. Default: 1.0f
706
 */
707
  public void glClearDepthf(float d)
708
    {
709
    mClearDepth = d;
710
    }
711
712 23eecbd9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
713
/**
714
 * Uses glClearStencil() to set up a value with which to clear the
715
 * Stencil buffer of our Surface at the beginning of each frame.
716
 *
717
 * @param s the Stencil. Default: 0
718
 */
719
  public void glClearStencil(int s)
720
    {
721
    mClearStencil = s;
722
    }
723
724 ad16ed3b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
725
/**
726
 * Which buffers to Clear at the beginning of each frame?
727
 * <p>
728
 * Valid values: 0, or bitwise OR of one or more values from the set GL_COLOR_BUFFER_BIT,
729
 *               GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT.
730
 * Default: GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT.
731
 *
732
 * @param mask bitwise OR of BUFFER_BITs to clear.
733
 */
734
  public void glClear(int mask)
735
    {
736
    mClear = mask;
737
    }
738
739 af4cc5db Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
740
/**
741
 * Create new Projection matrix.
742
 *
743
 * @param fov Vertical 'field of view' of the Projection frustrum (in degrees).
744 54fe333a leszek
 *            Valid values: 0<=fov<180. FOV==0 means 'parallel projection'.
745 7690aab1 Leszek Koltunski
 * @param near The Near plane.
746 af4cc5db Leszek Koltunski
 */
747 54fe333a leszek
  public void setProjection(float fov, float near)
748 af4cc5db Leszek Koltunski
    {
749 8069e806 Leszek Koltunski
    if( fov < 180.0f && fov >=0.0f )
750
      {
751
      mFOV = fov;
752
      }
753
754
    if( near<   1.0f && near> 0.0f )
755
      {
756
      mNear= near;
757
      }
758
    else if( near<=0.0f )
759
      {
760
      mNear = 0.01f;
761
      }
762
    else if( near>=1.0f )
763
      {
764
      mNear=0.99f;
765
      }
766 af4cc5db Leszek Koltunski
767 66103fb2 Leszek Koltunski
    for(int j=0; j<EffectQuality.LENGTH; j++)
768 61ce8e90 Leszek Koltunski
      {
769 66103fb2 Leszek Koltunski
      if( mBuffer[j]!=null ) mBuffer[j].mNear = mNear;
770 61ce8e90 Leszek Koltunski
      }
771
772 af4cc5db Leszek Koltunski
    createProjection();
773
    }
774
775 f211a191 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
776
/**
777
 * Return the vertical field of view angle.
778
 *
779
 * @return Vertival Field of View Angle, in degrees.
780
 */
781
  public float getFOV()
782
    {
783
    return mFOV;
784
    }
785
786 af4cc5db Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
787 c5369f1b leszek
/**
788 af4cc5db Leszek Koltunski
 * Resize the underlying Framebuffer.
789 c7da4e65 leszek
 * <p>
790
 * This method can be safely called mid-render as it doesn't interfere with rendering.
791 af4cc5db Leszek Koltunski
 *
792
 * @param width The new width.
793
 * @param height The new height.
794 c5369f1b leszek
 */
795 af4cc5db Leszek Koltunski
  public void resize(int width, int height)
796
    {
797
    if( mWidth!=width || mHeight!=height )
798
      {
799 a4b182d4 Leszek Koltunski
      mWidth = mRealWidth = width;
800
      mHeight= mRealHeight= height;
801 f8377ef8 leszek
802
      createProjection();
803
804 c7da4e65 leszek
      if( mColorCreated==CREATED )
805 f8377ef8 leszek
        {
806 f28fffc2 Leszek Koltunski
        markForCreation();
807 f8377ef8 leszek
        recreate();
808
        }
809 af4cc5db Leszek Koltunski
      }
810
    }
811 a09ada4c Leszek Koltunski
812 a436ccc5 leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
813
/**
814 89de975c leszek
 * Return true if the Surface contains a DEPTH attachment.
815 a436ccc5 leszek
 *
816 89de975c leszek
 * @return <bold>true</bold> if the Surface contains a DEPTH attachment.
817 a436ccc5 leszek
 */
818 89de975c leszek
  public boolean hasDepth()
819 a436ccc5 leszek
    {
820 89de975c leszek
    return mDepthStencilCreated==CREATED;
821 a436ccc5 leszek
    }
822
823
///////////////////////////////////////////////////////////////////////////////////////////////////
824
/**
825 89de975c leszek
 * Return true if the Surface contains a STENCIL attachment.
826 a436ccc5 leszek
 *
827 89de975c leszek
 * @return <bold>true</bold> if the Surface contains a STENCIL attachment.
828 a436ccc5 leszek
 */
829 89de975c leszek
  public boolean hasStencil()
830 a436ccc5 leszek
    {
831 89de975c leszek
    return (mDepthStencilCreated==CREATED && mDepthStencil==BOTH_DEPTH_STENCIL);
832 a436ccc5 leszek
    }
833
834 406e2f6b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
835
/**
836 cd1f5056 Leszek Koltunski
 * When rendering this Node, should we use the Order Independent Transparency render mode?
837 406e2f6b Leszek Koltunski
 * <p>
838 b7074bc6 Leszek Koltunski
 * This feature requires OpenGL ES 3.1. If we are running on OpenGL 3.0, this will do nothing.
839
 * Also, if you are running on a buggy driver ( Imagination GE8100/8300 driver build 1.8@4490469 )
840
 * then do nothing.
841
 *
842 406e2f6b Leszek Koltunski
 * There are two modes of rendering: the fast 'normal' way, which however renders transparent
843
 * fragments in different ways depending on which fragments get rendered first, or the slower
844
 * 'oit' way, which renders transparent fragments correctly regardless of their order.
845
 *
846
 * @param oit True if we want to render more slowly, but in a way which accounts for transparency.
847
 */
848
  public void setOrderIndependentTransparency(boolean oit)
849
    {
850 d99fcc9c Leszek Koltunski
    if( DistortedLibrary.getGLSL()>=310 )
851 b7074bc6 Leszek Koltunski
      {
852
      mRenderWayOIT = oit;
853
      }
854 406e2f6b Leszek Koltunski
    }
855
856 12f9e4bb Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
857
/**
858 cd1f5056 Leszek Koltunski
 * When rendering this Node, should we use the Order Independent Transparency render mode?
859 12f9e4bb Leszek Koltunski
 * <p>
860 b7074bc6 Leszek Koltunski
 * This feature requires OpenGL ES 3.1. If we are running on OpenGL 3.0, this will do nothing.
861
 * Also, if you are running on a buggy driver ( Imagination GE8100/8300 driver build 1.8@4490469 )
862
 * then do nothing.
863
 *
864 12f9e4bb Leszek Koltunski
 * There are two modes of rendering: the fast 'normal' way, which however renders transparent
865
 * fragments in different ways depending on which fragments get rendered first, or the slower
866
 * 'oit' way, which renders transparent fragments correctly regardless of their order.
867
 *
868
 * @param oit True if we want to render more slowly, but in a way which accounts for transparency.
869
 * @param initialSize Initial number of transparent fragments we expect, in screenfuls.
870 f953bee0 Leszek Koltunski
 *                    I.e '1.0' means 'the scene we are going to render contains dialog_about 1 screen
871 12f9e4bb Leszek Koltunski
 *                    worth of transparent fragments'. Valid values: 0.0 &lt; initialSize &lt; 10.0
872
 *                    Even if you get this wrong, the library will detect that there are more
873
 *                    transparent fragments than it has space for and readjust its internal buffers,
874
 *                    but only after a few frames during which one will probably see missing objects.
875
 */
876 66103fb2 Leszek Koltunski
  public void setOrderIndependentTransparency(boolean oit, float initialSize)
877
    {
878 d99fcc9c Leszek Koltunski
    if( DistortedLibrary.getGLSL()>=310 )
879 66103fb2 Leszek Koltunski
      {
880 b7074bc6 Leszek Koltunski
      mRenderWayOIT = oit;
881
882
      if( initialSize>0.0f && initialSize<10.0f )
883
        {
884
        DistortedLibrary.setSSBOSize(initialSize);
885
        }
886 66103fb2 Leszek Koltunski
      }
887
    }
888 12f9e4bb Leszek Koltunski
889 a09ada4c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
890
/**
891
 * Adds a new child to the last position in the list of our Surface's children.
892 c204c69d leszek
 * <p>
893
 * We cannot do this mid-render - actual attachment will be done just before the next render, by the
894 7602a827 Leszek Koltunski
 * InternalMaster (by calling doWork())
895 a09ada4c Leszek Koltunski
 *
896
 * @param node The new Node to add.
897
 */
898 c204c69d leszek
  public void attach(DistortedNode node)
899 a09ada4c Leszek Koltunski
    {
900 11845a9e Leszek Koltunski
    mChildren.attach(node);
901 a09ada4c Leszek Koltunski
    }
902
903
///////////////////////////////////////////////////////////////////////////////////////////////////
904
/**
905
 * Adds a new child to the last position in the list of our Surface's children.
906 c204c69d leszek
 * <p>
907
 * We cannot do this mid-render - actual attachment will be done just before the next render, by the
908 7602a827 Leszek Koltunski
 * InternalMaster (by calling doWork())
909 a09ada4c Leszek Koltunski
 *
910
 * @param surface InputSurface to initialize our child Node with.
911
 * @param effects DistortedEffects to initialize our child Node with.
912 715e7726 Leszek Koltunski
 * @param mesh MeshBase to initialize our child Node with.
913 a09ada4c Leszek Koltunski
 * @return the newly constructed child Node, or null if we couldn't allocate resources.
914
 */
915 7602a827 Leszek Koltunski
  public DistortedNode attach(InternalSurface surface, DistortedEffects effects, MeshBase mesh)
916 a09ada4c Leszek Koltunski
    {
917 11845a9e Leszek Koltunski
    return mChildren.attach(surface,effects,mesh);
918 c204c69d leszek
    }
919
920 af27df87 leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
921
/**
922
 * Removes the first occurrence of a specified child from the list of children of our Surface.
923
 * <p>
924
 * A bit questionable method as there can be many different Nodes attached as children, some
925
 * of them having the same Effects but - for instance - different Mesh. Use with care.
926
 * <p>
927
 * We cannot do this mid-render - actual detachment will be done just before the next render, by the
928 7602a827 Leszek Koltunski
 * InternalMaster (by calling doWork())
929 af27df87 leszek
 *
930
 * @param effects DistortedEffects to remove.
931
 */
932
  public void detach(DistortedEffects effects)
933
    {
934 11845a9e Leszek Koltunski
    mChildren.detach(effects);
935 af27df87 leszek
    }
936
937 a09ada4c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
938
/**
939
 * Removes the first occurrence of a specified child from the list of children of our Surface.
940 c204c69d leszek
 * <p>
941
 * We cannot do this mid-render - actual attachment will be done just before the next render, by the
942 7602a827 Leszek Koltunski
 * InternalMaster (by calling doWork())
943 c204c69d leszek
 *
944
 * @param node The Node to remove.
945
 */
946
  public void detach(DistortedNode node)
947
    {
948 11845a9e Leszek Koltunski
    mChildren.detach(node);
949 a09ada4c Leszek Koltunski
    }
950
951
///////////////////////////////////////////////////////////////////////////////////////////////////
952
/**
953
 * Removes all children Nodes.
954 c204c69d leszek
 * <p>
955
 * We cannot do this mid-render - actual attachment will be done just before the next render, by the
956 7602a827 Leszek Koltunski
 * InternalMaster (by calling doWork())
957 c204c69d leszek
 */
958
  public void detachAll()
959
    {
960 11845a9e Leszek Koltunski
    mChildren.detachAll();
961 a09ada4c Leszek Koltunski
    }
962 d58b50e7 Leszek Koltunski
963
///////////////////////////////////////////////////////////////////////////////////////////////////
964
/**
965
 * Return the width of this Surface.
966
 *
967
 * @return width of the Object, in pixels.
968
 */
969
  public int getWidth()
970
    {
971
    return mWidth;
972
    }
973
974
///////////////////////////////////////////////////////////////////////////////////////////////////
975
/**
976
 * Return the height of this Surface.
977
 *
978
 * @return height of the Object, in pixels.
979
 */
980
  public int getHeight()
981
    {
982
    return mHeight;
983
    }
984 178983f4 Leszek Koltunski
}