Project

General

Profile

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

library / src / main / java / org / distorted / library / main / InternalOutputSurface.java @ 22d3c4b4

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