Project

General

Profile

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

library / src / main / java / org / distorted / library / main / InternalOutputSurface.java @ 97b6c85e

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