Project

General

Profile

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

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

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