Project

General

Profile

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

library / src / main / java / org / distorted / library / main / InternalOutputSurface.java @ 0fb3f8b8

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