Project

General

Profile

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

library / src / main / java / org / distorted / library / main / InternalOutputSurface.java @ 7602a827

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