1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2016 Leszek Koltunski leszek@koltunski.pl //
|
3
|
// //
|
4
|
// This file is part of Distorted. //
|
5
|
// //
|
6
|
// This library is free software; you can redistribute it and/or //
|
7
|
// modify it under the terms of the GNU Lesser General Public //
|
8
|
// License as published by the Free Software Foundation; either //
|
9
|
// version 2.1 of the License, or (at your option) any later version. //
|
10
|
// //
|
11
|
// This library is distributed in the hope that it will be useful, //
|
12
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
|
14
|
// Lesser General Public License for more details. //
|
15
|
// //
|
16
|
// You should have received a copy of the GNU Lesser General Public //
|
17
|
// License along with this library; if not, write to the Free Software //
|
18
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA //
|
19
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
20
|
|
21
|
package org.distorted.library.main;
|
22
|
|
23
|
import android.opengl.GLES30;
|
24
|
|
25
|
import org.distorted.library.mesh.MeshBase;
|
26
|
|
27
|
import java.util.ArrayList;
|
28
|
import java.util.Collections;
|
29
|
|
30
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
31
|
/**
|
32
|
* Class which represents a Node in a Tree of (InputSurface,Mesh,Effects) triplets.
|
33
|
* <p>
|
34
|
* Having organized such sets into a Tree, we can then render any Node to any OutputSurface.
|
35
|
* That recursively renders the set held in the Node and all its children.
|
36
|
* <p>
|
37
|
* The class takes special care to only render identical sub-trees once. Each Node holds a reference
|
38
|
* to sub-class 'NodeData'. Two identical sub-trees attached at different points of the main tree
|
39
|
* will point to the same NodeData; only the first of this is rendered (mData.numRender!).
|
40
|
*/
|
41
|
public class DistortedNode implements InternalChildrenList.Parent
|
42
|
{
|
43
|
private static final int DEFAULT_FBO_SIZE = 100;
|
44
|
|
45
|
private final DistortedEffects mEffects;
|
46
|
private final InternalRenderState mState;
|
47
|
private final InternalChildrenList mChildren;
|
48
|
private InternalChildrenList.Parent mParent;
|
49
|
private InternalSurface mSurface;
|
50
|
private InternalNodeData mData;
|
51
|
private MeshBase mMesh;
|
52
|
|
53
|
private int mFboW, mFboH, mFboDepthStencil;
|
54
|
private boolean mRenderWayOIT;
|
55
|
private float mFOV, mNear;
|
56
|
private long mLastTime;
|
57
|
|
58
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
59
|
|
60
|
public void markForDeletion()
|
61
|
{
|
62
|
if( mData.removeData() )
|
63
|
{
|
64
|
mData.mFBO.markForDeletion();
|
65
|
mData.mFBO = null;
|
66
|
}
|
67
|
}
|
68
|
|
69
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70
|
// [3] --> the postprocessing queue. See EffectType.
|
71
|
|
72
|
long getBucket()
|
73
|
{
|
74
|
return mEffects.getQueues()[3].getID();
|
75
|
}
|
76
|
|
77
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
78
|
|
79
|
private ArrayList<Long> generateIDList()
|
80
|
{
|
81
|
ArrayList<Long> ret = new ArrayList<>();
|
82
|
int numChildren = mChildren.getNumChildren();
|
83
|
|
84
|
if( numChildren==0 )
|
85
|
{
|
86
|
// add a negative number so this leaf never gets confused with a internal node
|
87
|
// with a single child that happens to have ID identical to some leaf's Effects ID.
|
88
|
ret.add(-mEffects.getID());
|
89
|
}
|
90
|
else
|
91
|
{
|
92
|
DistortedNode node;
|
93
|
|
94
|
for(int i=0; i<numChildren; i++)
|
95
|
{
|
96
|
node = mChildren.getChild(i);
|
97
|
ret.add(node.mData.ID);
|
98
|
}
|
99
|
|
100
|
// A bit questionable decision here - we are sorting the children IDs, which means
|
101
|
// that order in which we draw the children is going to be undefined (well, this is not
|
102
|
// strictly speaking true - when rendering, if no postprocessing and isomorphism are
|
103
|
// involved, we *DO* render the children in order they were added; if however there
|
104
|
// are two internal nodes with the same list of identical children, just added in a
|
105
|
// different order each time, then we consider them isomorphic, i.e. identical and only
|
106
|
// render the first one. If then two children of such 'pseudo-isomorphic' nodes are at
|
107
|
// exactly the same Z-height this might result in some unexpected sights).
|
108
|
//
|
109
|
// Reason: with the children being sorted by postprocessing buckets, the order is
|
110
|
// undefined anyway (although only when postprocessing is applied).
|
111
|
//
|
112
|
// See the consequences in the 'Olympic' app - remove a few leaves and add them back in
|
113
|
// different order. You will see the number of renders go back to the original 15.
|
114
|
Collections.sort(ret);
|
115
|
}
|
116
|
|
117
|
ret.add( 0, mSurface.getID() );
|
118
|
|
119
|
return ret;
|
120
|
}
|
121
|
|
122
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
123
|
/**
|
124
|
* This is not really part of the public API. Has to be public only because it is a part of the
|
125
|
* InternalChildrenList.Parent interface.
|
126
|
*
|
127
|
* @y.exclude
|
128
|
*/
|
129
|
public void adjustIsomorphism()
|
130
|
{
|
131
|
InternalNodeData newData = InternalNodeData.returnData(generateIDList());
|
132
|
boolean deleteOldFBO = mData.removeData();
|
133
|
boolean createNewFBO = (mChildren.getNumChildren()>0 && newData.mFBO==null);
|
134
|
|
135
|
if( deleteOldFBO && createNewFBO )
|
136
|
{
|
137
|
newData.mFBO = mData.mFBO;
|
138
|
}
|
139
|
else if( deleteOldFBO )
|
140
|
{
|
141
|
mData.mFBO.markForDeletion();
|
142
|
mData.mFBO = null;
|
143
|
}
|
144
|
else if( createNewFBO )
|
145
|
{
|
146
|
newData.mFBO = allocateNewFBO();
|
147
|
}
|
148
|
|
149
|
mData = newData;
|
150
|
|
151
|
if( mParent!=null ) mParent.adjustIsomorphism();
|
152
|
}
|
153
|
|
154
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
155
|
// return the total number of render calls issued
|
156
|
|
157
|
int drawNoBlend(long currTime, InternalOutputSurface surface)
|
158
|
{
|
159
|
InternalSurface input = getSurface();
|
160
|
|
161
|
if( input.setAsInput() )
|
162
|
{
|
163
|
mState.apply();
|
164
|
GLES30.glDisable(GLES30.GL_BLEND);
|
165
|
if( mLastTime==0 ) mLastTime=currTime;
|
166
|
DistortedLibrary.drawPriv(mEffects, mMesh, surface, currTime, (currTime-mLastTime));
|
167
|
mLastTime = currTime;
|
168
|
GLES30.glEnable(GLES30.GL_BLEND);
|
169
|
return 1;
|
170
|
}
|
171
|
|
172
|
return 0;
|
173
|
}
|
174
|
|
175
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
176
|
// Use the Order Independent Transparency method to draw a non-postprocessed child.
|
177
|
|
178
|
int drawOIT(long currTime, InternalOutputSurface surface)
|
179
|
{
|
180
|
InternalSurface input = getSurface();
|
181
|
|
182
|
if( input.setAsInput() )
|
183
|
{
|
184
|
mState.apply();
|
185
|
if( mLastTime==0 ) mLastTime=currTime;
|
186
|
DistortedLibrary.drawPrivOIT(mEffects, mMesh, surface, currTime, (currTime-mLastTime));
|
187
|
mLastTime = currTime;
|
188
|
return 1;
|
189
|
}
|
190
|
|
191
|
return 0;
|
192
|
}
|
193
|
|
194
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
195
|
// return the total number of render calls issued
|
196
|
|
197
|
int draw(long currTime, InternalOutputSurface surface)
|
198
|
{
|
199
|
InternalSurface input = getSurface();
|
200
|
|
201
|
if( input.setAsInput() )
|
202
|
{
|
203
|
mState.apply();
|
204
|
if( mLastTime==0 ) mLastTime=currTime;
|
205
|
DistortedLibrary.drawPriv(mEffects, mMesh, surface, currTime, (currTime-mLastTime));
|
206
|
mLastTime = currTime;
|
207
|
return 1;
|
208
|
}
|
209
|
|
210
|
return 0;
|
211
|
}
|
212
|
|
213
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
214
|
// return the total number of render calls issued
|
215
|
|
216
|
int renderRecursive(long currTime)
|
217
|
{
|
218
|
int numRenders = 0;
|
219
|
int numChildren = mChildren.getNumChildren();
|
220
|
|
221
|
if( numChildren>0 && mData.notRenderedYetAtThisTime(currTime) )
|
222
|
{
|
223
|
DistortedNode node;
|
224
|
long oldBucket=0, newBucket;
|
225
|
|
226
|
for (int i=0; i<numChildren; i++)
|
227
|
{
|
228
|
node = mChildren.getChild(i);
|
229
|
newBucket = node.getBucket();
|
230
|
numRenders += node.renderRecursive(currTime);
|
231
|
if( newBucket<oldBucket ) mChildren.rearrangeByBuckets(i,newBucket);
|
232
|
else oldBucket=newBucket;
|
233
|
}
|
234
|
|
235
|
if( mData.mFBO==null ) mData.mFBO = allocateNewFBO();
|
236
|
mData.mFBO.setAsOutput(currTime);
|
237
|
|
238
|
if( mSurface.setAsInput() )
|
239
|
{
|
240
|
numRenders++;
|
241
|
DistortedLibrary.blitPriv(mData.mFBO);
|
242
|
}
|
243
|
|
244
|
numRenders += mData.mFBO.renderChildren(currTime,numChildren,mChildren,0, mRenderWayOIT);
|
245
|
}
|
246
|
|
247
|
return numRenders;
|
248
|
}
|
249
|
|
250
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
251
|
|
252
|
private DistortedFramebuffer allocateNewFBO()
|
253
|
{
|
254
|
int width, height;
|
255
|
|
256
|
if( mFboW>0 && mFboH>0 )
|
257
|
{
|
258
|
width = mFboW;
|
259
|
height= mFboH;
|
260
|
}
|
261
|
else
|
262
|
{
|
263
|
if( mSurface instanceof DistortedFramebuffer )
|
264
|
{
|
265
|
DistortedFramebuffer fbo = (DistortedFramebuffer)mSurface;
|
266
|
width = fbo.mWidth;
|
267
|
height= fbo.mHeight;
|
268
|
}
|
269
|
else
|
270
|
{
|
271
|
width = DEFAULT_FBO_SIZE;
|
272
|
height= DEFAULT_FBO_SIZE;
|
273
|
}
|
274
|
}
|
275
|
|
276
|
DistortedFramebuffer fbo = new DistortedFramebuffer(1,mFboDepthStencil, InternalSurface.TYPE_TREE, width, height);
|
277
|
|
278
|
if( mFOV!=InternalOutputSurface.DEFAULT_FOV || mNear!=InternalOutputSurface.DEFAULT_NEAR )
|
279
|
{
|
280
|
fbo.setProjection(mFOV,mNear);
|
281
|
}
|
282
|
|
283
|
return fbo;
|
284
|
}
|
285
|
|
286
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
287
|
|
288
|
void resetLastTime()
|
289
|
{
|
290
|
mLastTime = 0;
|
291
|
}
|
292
|
|
293
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
294
|
|
295
|
void setParent(InternalChildrenList.Parent parent)
|
296
|
{
|
297
|
mParent = parent;
|
298
|
}
|
299
|
|
300
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
301
|
// PUBLIC API
|
302
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
303
|
/**
|
304
|
* Constructs new Node.
|
305
|
*
|
306
|
* @param surface InputSurface to put into the new Node.
|
307
|
* @param effects DistortedEffects to put into the new Node.
|
308
|
* @param mesh MeshBase to put into the new Node.
|
309
|
*/
|
310
|
public DistortedNode(InternalSurface surface, DistortedEffects effects, MeshBase mesh)
|
311
|
{
|
312
|
mLastTime = 0;
|
313
|
mSurface = surface;
|
314
|
mEffects = effects;
|
315
|
mMesh = mesh;
|
316
|
mState = new InternalRenderState();
|
317
|
mChildren = new InternalChildrenList(this);
|
318
|
mParent = null;
|
319
|
mRenderWayOIT = false;
|
320
|
|
321
|
mFOV = InternalOutputSurface.DEFAULT_FOV;
|
322
|
mNear= InternalOutputSurface.DEFAULT_NEAR;
|
323
|
|
324
|
mFboW = 0; // i.e. take this from
|
325
|
mFboH = 0; // mEffects's stretch{X,Y}
|
326
|
mFboDepthStencil = DistortedFramebuffer.DEPTH_NO_STENCIL;
|
327
|
|
328
|
mData = InternalNodeData.returnData(generateIDList());
|
329
|
}
|
330
|
|
331
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
332
|
/**
|
333
|
* Copy-constructs new Node from another Node.
|
334
|
*
|
335
|
* @param node The DistortedNode to copy data from.
|
336
|
* @param flags bit field composed of a subset of the following:
|
337
|
* {@link DistortedLibrary#CLONE_SURFACE}, {@link DistortedLibrary#CLONE_MATRIX}, {@link DistortedLibrary#CLONE_VERTEX},
|
338
|
* {@link DistortedLibrary#CLONE_FRAGMENT} and {@link DistortedLibrary#CLONE_CHILDREN}.
|
339
|
* For example flags = CLONE_SURFACE | CLONE_CHILDREN.
|
340
|
*/
|
341
|
public DistortedNode(DistortedNode node, int flags)
|
342
|
{
|
343
|
mLastTime = 0;
|
344
|
mEffects = new DistortedEffects(node.mEffects,flags);
|
345
|
mMesh = node.mMesh;
|
346
|
mState = new InternalRenderState();
|
347
|
mParent = null;
|
348
|
mRenderWayOIT = false;
|
349
|
|
350
|
mFOV = InternalOutputSurface.DEFAULT_FOV;
|
351
|
mNear= InternalOutputSurface.DEFAULT_NEAR;
|
352
|
|
353
|
mFboW = node.mFboW;
|
354
|
mFboH = node.mFboH;
|
355
|
mFboDepthStencil = node.mFboDepthStencil;
|
356
|
|
357
|
if( (flags & DistortedLibrary.CLONE_SURFACE) != 0 )
|
358
|
{
|
359
|
mSurface = node.mSurface;
|
360
|
}
|
361
|
else
|
362
|
{
|
363
|
if( node.mSurface instanceof DistortedTexture )
|
364
|
{
|
365
|
mSurface = new DistortedTexture(InternalSurface.TYPE_TREE);
|
366
|
}
|
367
|
else if( node.mSurface instanceof DistortedFramebuffer )
|
368
|
{
|
369
|
DistortedFramebuffer fbo = (DistortedFramebuffer)node.mSurface;
|
370
|
|
371
|
int w = fbo.getWidth();
|
372
|
int h = fbo.getHeight();
|
373
|
int depthStencil = DistortedFramebuffer.NO_DEPTH_NO_STENCIL;
|
374
|
|
375
|
if( fbo.hasDepth() )
|
376
|
{
|
377
|
boolean hasStencil = fbo.hasStencil();
|
378
|
depthStencil = (hasStencil ? DistortedFramebuffer.BOTH_DEPTH_STENCIL:DistortedFramebuffer.DEPTH_NO_STENCIL);
|
379
|
}
|
380
|
|
381
|
mSurface = new DistortedFramebuffer(1,depthStencil, InternalSurface.TYPE_TREE,w,h);
|
382
|
}
|
383
|
}
|
384
|
|
385
|
if( (flags & DistortedLibrary.CLONE_CHILDREN) != 0 )
|
386
|
{
|
387
|
mChildren = node.mChildren;
|
388
|
}
|
389
|
else
|
390
|
{
|
391
|
mChildren = new InternalChildrenList(this);
|
392
|
}
|
393
|
|
394
|
mData = InternalNodeData.returnData(generateIDList());
|
395
|
}
|
396
|
|
397
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
398
|
/**
|
399
|
* Change the input surface while keeping everything else about the Node the same.
|
400
|
*
|
401
|
* @param surface The new input surface.
|
402
|
*/
|
403
|
public void changeInputSurface(InternalSurface surface)
|
404
|
{
|
405
|
mSurface = surface;
|
406
|
}
|
407
|
|
408
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
409
|
|
410
|
/**
|
411
|
* When rendering this Node, should we use the Order Independent Transparency render more?
|
412
|
* <p>
|
413
|
* There are two modes of rendering: the fast 'normal' way, which however renders transparent
|
414
|
* fragments in different ways depending on which fragments get rendered first, or the slower
|
415
|
* 'oit' way, which renders transparent fragments correctly regardless of their order.
|
416
|
*
|
417
|
* @param oit True if we want to render more slowly, but in a way which accounts for transparency.
|
418
|
*/
|
419
|
public void setOrderIndependentTransparency(boolean oit)
|
420
|
{
|
421
|
mRenderWayOIT = oit;
|
422
|
}
|
423
|
|
424
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
425
|
/**
|
426
|
* When rendering this Node, should we use the Order Independent Transparency render more?
|
427
|
* <p>
|
428
|
* There are two modes of rendering: the fast 'normal' way, which however renders transparent
|
429
|
* fragments in different ways depending on which fragments get rendered first, or the slower
|
430
|
* 'oit' way, which renders transparent fragments correctly regardless of their order.
|
431
|
*
|
432
|
* @param oit True if we want to render more slowly, but in a way which accounts for transparency.
|
433
|
* @param initialSize Initial number of transparent fragments we expect, in screenfulls.
|
434
|
* I.e '1.0' means 'the scene we are going to render contains dialog_about 1 screen
|
435
|
* worth of transparent fragments'. Valid values: 0.0 < initialSize < 10.0
|
436
|
* Even if you get this wrong, the library will detect that there are more
|
437
|
* transparent fragments than it has space for and readjust its internal buffers,
|
438
|
* but only after a few frames during which one will probably see missing objects.
|
439
|
*/
|
440
|
public void setOrderIndependentTransparency(boolean oit, float initialSize)
|
441
|
{
|
442
|
mRenderWayOIT = oit;
|
443
|
|
444
|
if( initialSize>0.0f && initialSize<10.0f )
|
445
|
DistortedLibrary.setSSBOSize(initialSize);
|
446
|
}
|
447
|
|
448
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
449
|
/**
|
450
|
* Adds a new child to the last position in the list of our Node's children.
|
451
|
* <p>
|
452
|
* We cannot do this mid-render - actual attachment will be done just before the next render, by the
|
453
|
* InternalMaster (by calling doWork())
|
454
|
*
|
455
|
* @param node The new Node to add.
|
456
|
*/
|
457
|
public void attach(DistortedNode node)
|
458
|
{
|
459
|
mChildren.attach(node);
|
460
|
}
|
461
|
|
462
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
463
|
/**
|
464
|
* Adds a new child to the last position in the list of our Node's children.
|
465
|
* <p>
|
466
|
* We cannot do this mid-render - actual attachment will be done just before the next render, by the
|
467
|
* InternalMaster (by calling doWork())
|
468
|
*
|
469
|
* @param surface InputSurface to initialize our child Node with.
|
470
|
* @param effects DistortedEffects to initialize our child Node with.
|
471
|
* @param mesh MeshBase to initialize our child Node with.
|
472
|
* @return the newly constructed child Node, or null if we couldn't allocate resources.
|
473
|
*/
|
474
|
public DistortedNode attach(InternalSurface surface, DistortedEffects effects, MeshBase mesh)
|
475
|
{
|
476
|
return mChildren.attach(surface,effects,mesh);
|
477
|
}
|
478
|
|
479
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
480
|
/**
|
481
|
* Removes the first occurrence of a specified child from the list of children of our Node.
|
482
|
* <p>
|
483
|
* We cannot do this mid-render - actual detachment will be done just before the next render, by the
|
484
|
* InternalMaster (by calling doWork())
|
485
|
*
|
486
|
* @param node The Node to remove.
|
487
|
*/
|
488
|
public void detach(DistortedNode node)
|
489
|
{
|
490
|
mChildren.detach(node);
|
491
|
}
|
492
|
|
493
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
494
|
/**
|
495
|
* Removes the first occurrence of a specified child from the list of children of our Node.
|
496
|
* <p>
|
497
|
* A bit questionable method as there can be many different Nodes attached as children, some
|
498
|
* of them having the same Effects but - for instance - different Mesh. Use with care.
|
499
|
* <p>
|
500
|
* We cannot do this mid-render - actual detachment will be done just before the next render, by the
|
501
|
* InternalMaster (by calling doWork())
|
502
|
*
|
503
|
* @param effects DistortedEffects to remove.
|
504
|
*/
|
505
|
public void detach(DistortedEffects effects)
|
506
|
{
|
507
|
mChildren.detach(effects);
|
508
|
}
|
509
|
|
510
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
511
|
/**
|
512
|
* Removes all children Nodes.
|
513
|
* <p>
|
514
|
* We cannot do this mid-render - actual detachment will be done just before the next render, by the
|
515
|
* InternalMaster (by calling doWork())
|
516
|
*/
|
517
|
public void detachAll()
|
518
|
{
|
519
|
mChildren.detachAll();
|
520
|
}
|
521
|
|
522
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
523
|
/**
|
524
|
* Returns the DistortedEffects object that's in the Node.
|
525
|
*
|
526
|
* @return The DistortedEffects contained in the Node.
|
527
|
*/
|
528
|
public DistortedEffects getEffects()
|
529
|
{
|
530
|
return mEffects;
|
531
|
}
|
532
|
|
533
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
534
|
/**
|
535
|
* Returns the surface this object gets rendered to.
|
536
|
*
|
537
|
* @return The InternalSurface contained in the Node (if a leaf), or the FBO (if an internal Node)
|
538
|
*/
|
539
|
public InternalSurface getSurface()
|
540
|
{
|
541
|
return mChildren.getNumChildren()==0 ? mSurface : mData.mFBO;
|
542
|
}
|
543
|
|
544
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
545
|
/**
|
546
|
* Returns the FBO contained in this object, even if it is a leaf.
|
547
|
*
|
548
|
* @return The DistortedFramebuffer.
|
549
|
*/
|
550
|
public DistortedFramebuffer getFramebuffer()
|
551
|
{
|
552
|
return mData.mFBO;
|
553
|
}
|
554
|
|
555
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
556
|
/**
|
557
|
* Returns the Mesh object that's in the Node.
|
558
|
*
|
559
|
* @return Mesh contained in the Node.
|
560
|
*/
|
561
|
public MeshBase getMesh()
|
562
|
{
|
563
|
return mMesh;
|
564
|
}
|
565
|
|
566
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
567
|
/**
|
568
|
* Set a new Mesh.
|
569
|
*/
|
570
|
public void setMesh(MeshBase mesh)
|
571
|
{
|
572
|
mMesh = mesh;
|
573
|
}
|
574
|
|
575
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
576
|
/**
|
577
|
* Resizes the DistortedFramebuffer object that we render this Node to.
|
578
|
*/
|
579
|
public void resizeFBO(int width, int height)
|
580
|
{
|
581
|
mFboW = width;
|
582
|
mFboH = height;
|
583
|
|
584
|
if ( mData.mFBO !=null )
|
585
|
{
|
586
|
// TODO: potentially allocate a new NodeData if we have to
|
587
|
mData.mFBO.resize(width,height);
|
588
|
}
|
589
|
}
|
590
|
|
591
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
592
|
/**
|
593
|
* Set Projection Matrix for the Framebuffer contained in this Node.
|
594
|
* <p>
|
595
|
* If this Node is a Leaf and has no Framebuffer in it, this call does nothing.
|
596
|
*
|
597
|
* @param fov Vertical 'field of view' of the Projection frustrum (in degrees).
|
598
|
* Valid values: 0<=fov<180. FOV==0 means 'parallel projection'.
|
599
|
* @param near The Near plane.
|
600
|
*/
|
601
|
public void setProjection(float fov, float near)
|
602
|
{
|
603
|
if( fov < 180.0f && fov >=0.0f )
|
604
|
{
|
605
|
mFOV = fov;
|
606
|
}
|
607
|
|
608
|
if( near< 1.0f && near> 0.0f )
|
609
|
{
|
610
|
mNear= near;
|
611
|
}
|
612
|
else if( near<=0.0f )
|
613
|
{
|
614
|
mNear = 0.01f;
|
615
|
}
|
616
|
else if( near>=1.0f )
|
617
|
{
|
618
|
mNear=0.99f;
|
619
|
}
|
620
|
|
621
|
if( mData.mFBO!=null )
|
622
|
{
|
623
|
mData.mFBO.setProjection(mFOV,mNear);
|
624
|
}
|
625
|
}
|
626
|
|
627
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
628
|
/**
|
629
|
* Enables/disables DEPTH and STENCIL buffers in the Framebuffer object that we render this Node to.
|
630
|
*/
|
631
|
public void enableDepthStencil(int depthStencil)
|
632
|
{
|
633
|
mFboDepthStencil = depthStencil;
|
634
|
|
635
|
if ( mData.mFBO !=null )
|
636
|
{
|
637
|
// TODO: potentially allocate a new NodeData if we have to
|
638
|
mData.mFBO.enableDepthStencil(depthStencil);
|
639
|
}
|
640
|
}
|
641
|
|
642
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
643
|
// APIs that control how to set the OpenGL state just before rendering this Node.
|
644
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
645
|
/**
|
646
|
* When rendering this Node, use ColorMask (r,g,b,a).
|
647
|
*
|
648
|
* @param r Write to the RED color channel when rendering this Node?
|
649
|
* @param g Write to the GREEN color channel when rendering this Node?
|
650
|
* @param b Write to the BLUE color channel when rendering this Node?
|
651
|
* @param a Write to the ALPHA channel when rendering this Node?
|
652
|
*/
|
653
|
@SuppressWarnings("unused")
|
654
|
public void glColorMask(boolean r, boolean g, boolean b, boolean a)
|
655
|
{
|
656
|
mState.glColorMask(r,g,b,a);
|
657
|
}
|
658
|
|
659
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
660
|
/**
|
661
|
* When rendering this Node, switch on writing to Depth buffer?
|
662
|
*
|
663
|
* @param mask Write to the Depth buffer when rendering this Node?
|
664
|
*/
|
665
|
@SuppressWarnings("unused")
|
666
|
public void glDepthMask(boolean mask)
|
667
|
{
|
668
|
mState.glDepthMask(mask);
|
669
|
}
|
670
|
|
671
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
672
|
/**
|
673
|
* When rendering this Node, which bits of the Stencil buffer to write to?
|
674
|
*
|
675
|
* @param mask Marks the bits of the Stencil buffer we will write to when rendering this Node.
|
676
|
*/
|
677
|
@SuppressWarnings("unused")
|
678
|
public void glStencilMask(int mask)
|
679
|
{
|
680
|
mState.glStencilMask(mask);
|
681
|
}
|
682
|
|
683
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
684
|
/**
|
685
|
* When rendering this Node, which Tests to enable?
|
686
|
*
|
687
|
* @param test Valid values: GL_DEPTH_TEST, GL_STENCIL_TEST, GL_BLEND
|
688
|
*/
|
689
|
@SuppressWarnings("unused")
|
690
|
public void glEnable(int test)
|
691
|
{
|
692
|
mState.glEnable(test);
|
693
|
}
|
694
|
|
695
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
696
|
/**
|
697
|
* When rendering this Node, which Tests to enable?
|
698
|
*
|
699
|
* @param test Valid values: GL_DEPTH_TEST, GL_STENCIL_TEST, GL_BLEND
|
700
|
*/
|
701
|
@SuppressWarnings("unused")
|
702
|
public void glDisable(int test)
|
703
|
{
|
704
|
mState.glDisable(test);
|
705
|
}
|
706
|
|
707
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
708
|
/**
|
709
|
* When rendering this Node, use the following StencilFunc.
|
710
|
*
|
711
|
* @param func Valid values: GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER, GL_NOTEQUAL
|
712
|
* @param ref Reference valut to compare our stencil with.
|
713
|
* @param mask Mask used when comparing.
|
714
|
*/
|
715
|
@SuppressWarnings("unused")
|
716
|
public void glStencilFunc(int func, int ref, int mask)
|
717
|
{
|
718
|
mState.glStencilFunc(func,ref,mask);
|
719
|
}
|
720
|
|
721
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
722
|
/**
|
723
|
* When rendering this Node, use the following StencilOp.
|
724
|
* <p>
|
725
|
* Valid values of all 3 parameters: GL_KEEP, GL_ZERO, GL_REPLACE, GL_INCR, GL_DECR, GL_INVERT, GL_INCR_WRAP, GL_DECR_WRAP
|
726
|
*
|
727
|
* @param sfail What to do when Stencil Test fails.
|
728
|
* @param dpfail What to do when Depth Test fails.
|
729
|
* @param dppass What to do when Depth Test passes.
|
730
|
*/
|
731
|
@SuppressWarnings("unused")
|
732
|
public void glStencilOp(int sfail, int dpfail, int dppass)
|
733
|
{
|
734
|
mState.glStencilOp(sfail,dpfail,dppass);
|
735
|
}
|
736
|
|
737
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
738
|
/**
|
739
|
* When rendering this Node, use the following DepthFunc.
|
740
|
*
|
741
|
* @param func Valid values: GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER, GL_NOTEQUAL
|
742
|
*/
|
743
|
@SuppressWarnings("unused")
|
744
|
public void glDepthFunc(int func)
|
745
|
{
|
746
|
mState.glDepthFunc(func);
|
747
|
}
|
748
|
|
749
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
750
|
/**
|
751
|
* When rendering this Node, use the following Blending mode.
|
752
|
* <p>
|
753
|
* Valid values: GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
|
754
|
* GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR,
|
755
|
* GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_SRC_ALPHA_SATURATE
|
756
|
*
|
757
|
* @param src Source Blend function
|
758
|
* @param dst Destination Blend function
|
759
|
*/
|
760
|
@SuppressWarnings("unused")
|
761
|
public void glBlendFunc(int src, int dst)
|
762
|
{
|
763
|
mState.glBlendFunc(src,dst);
|
764
|
}
|
765
|
|
766
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
767
|
/**
|
768
|
* Before rendering this Node, clear the following buffers.
|
769
|
* <p>
|
770
|
* Valid values: 0, or bitwise OR of one or more values from the set GL_COLOR_BUFFER_BIT,
|
771
|
* GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT.
|
772
|
* Default: 0
|
773
|
*
|
774
|
* @param mask bitwise OR of BUFFER_BITs to clear.
|
775
|
*/
|
776
|
@SuppressWarnings("unused")
|
777
|
public void glClear(int mask)
|
778
|
{
|
779
|
mState.glClear(mask);
|
780
|
}
|
781
|
|
782
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
783
|
/**
|
784
|
* Recursively print all the effect queues attached to the children Nodes and to this Node.
|
785
|
*/
|
786
|
public void debug(int depth)
|
787
|
{
|
788
|
String dbg = mEffects.debug(depth);
|
789
|
android.util.Log.e("D", dbg);
|
790
|
|
791
|
int numChildren = mChildren.getNumChildren();
|
792
|
|
793
|
for(int i=0; i<numChildren; i++)
|
794
|
{
|
795
|
DistortedNode node = mChildren.getChild(i);
|
796
|
node.debug(depth+1);
|
797
|
}
|
798
|
}
|
799
|
}
|