Project

General

Profile

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

library / src / main / java / org / distorted / library / main / InternalOutputSurface.java @ d58b50e7

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