1 |
d333eb6b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
46b572b5
|
Leszek Koltunski
|
// This file is part of Distorted. //
|
5 |
d333eb6b
|
Leszek Koltunski
|
// //
|
6 |
46b572b5
|
Leszek Koltunski
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
d333eb6b
|
Leszek Koltunski
|
// 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 |
d333eb6b
|
Leszek Koltunski
|
// 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 |
d333eb6b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
fe82a979
|
Leszek Koltunski
|
package org.distorted.library.main;
|
21 |
6a06a912
|
Leszek Koltunski
|
|
22 |
8dccc3c2
|
Leszek Koltunski
|
import android.opengl.GLES31;
|
23 |
|
|
|
24 |
715e7726
|
Leszek Koltunski
|
import org.distorted.library.mesh.MeshBase;
|
25 |
6c00149d
|
Leszek Koltunski
|
|
26 |
6a06a912
|
Leszek Koltunski
|
import java.util.ArrayList;
|
27 |
c9f953c2
|
Leszek Koltunski
|
import java.util.Collections;
|
28 |
6a06a912
|
Leszek Koltunski
|
|
29 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30 |
|
|
/**
|
31 |
a09ada4c
|
Leszek Koltunski
|
* Class which represents a Node in a Tree of (InputSurface,Mesh,Effects) triplets.
|
32 |
c204c69d
|
leszek
|
* <p>
|
33 |
a09ada4c
|
Leszek Koltunski
|
* Having organized such sets into a Tree, we can then render any Node to any OutputSurface.
|
34 |
7b8086eb
|
Leszek Koltunski
|
* That recursively renders the set held in the Node and all its children.
|
35 |
c204c69d
|
leszek
|
* <p>
|
36 |
|
|
* The class takes special care to only render identical sub-trees once. Each Node holds a reference
|
37 |
|
|
* to sub-class 'NodeData'. Two identical sub-trees attached at different points of the main tree
|
38 |
3a70bd6d
|
leszek
|
* will point to the same NodeData; only the first of this is rendered (mData.numRender!).
|
39 |
6a06a912
|
Leszek Koltunski
|
*/
|
40 |
7602a827
|
Leszek Koltunski
|
public class DistortedNode implements InternalChildrenList.Parent
|
41 |
6a06a912
|
Leszek Koltunski
|
{
|
42 |
715e7726
|
Leszek Koltunski
|
private MeshBase mMesh;
|
43 |
07d8ef09
|
Leszek Koltunski
|
private DistortedEffects mEffects;
|
44 |
7602a827
|
Leszek Koltunski
|
private InternalSurface mSurface;
|
45 |
|
|
private InternalRenderState mState;
|
46 |
|
|
private InternalNodeData mData;
|
47 |
|
|
private InternalChildrenList mChildren;
|
48 |
|
|
private InternalChildrenList.Parent mParent;
|
49 |
11845a9e
|
Leszek Koltunski
|
|
50 |
23eecbd9
|
Leszek Koltunski
|
private int mFboW, mFboH, mFboDepthStencil;
|
51 |
11845a9e
|
Leszek Koltunski
|
private boolean mRenderWayOIT;
|
52 |
bd3da5b2
|
Leszek Koltunski
|
|
53 |
c43abe6c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
54 |
|
|
|
55 |
|
|
public void markForDeletion()
|
56 |
|
|
{
|
57 |
8bfefd68
|
Leszek Koltunski
|
if( mData.removeData() )
|
58 |
c43abe6c
|
Leszek Koltunski
|
{
|
59 |
8bfefd68
|
Leszek Koltunski
|
mData.mFBO.markForDeletion();
|
60 |
|
|
mData.mFBO = null;
|
61 |
c43abe6c
|
Leszek Koltunski
|
}
|
62 |
d5b709df
|
Leszek Koltunski
|
}
|
63 |
|
|
|
64 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
65 |
46b572b5
|
Leszek Koltunski
|
// [3] --> the postprocessing queue. See EffectType.
|
66 |
c43abe6c
|
Leszek Koltunski
|
|
67 |
d5b709df
|
Leszek Koltunski
|
long getBucket()
|
68 |
|
|
{
|
69 |
|
|
return mEffects.getQueues()[3].getID();
|
70 |
c43abe6c
|
Leszek Koltunski
|
}
|
71 |
|
|
|
72 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
73 |
|
|
|
74 |
|
|
private ArrayList<Long> generateIDList()
|
75 |
|
|
{
|
76 |
9361b337
|
Leszek Koltunski
|
ArrayList<Long> ret = new ArrayList<>();
|
77 |
11845a9e
|
Leszek Koltunski
|
int numChildren = mChildren.getNumChildren();
|
78 |
7691a39f
|
leszek
|
|
79 |
11845a9e
|
Leszek Koltunski
|
if( numChildren==0 )
|
80 |
7691a39f
|
leszek
|
{
|
81 |
c9f953c2
|
Leszek Koltunski
|
// add a negative number so this leaf never gets confused with a internal node
|
82 |
|
|
// with a single child that happens to have ID identical to some leaf's Effects ID.
|
83 |
7691a39f
|
leszek
|
ret.add(-mEffects.getID());
|
84 |
|
|
}
|
85 |
c9f953c2
|
Leszek Koltunski
|
else
|
86 |
6a06a912
|
Leszek Koltunski
|
{
|
87 |
c9f953c2
|
Leszek Koltunski
|
DistortedNode node;
|
88 |
6a06a912
|
Leszek Koltunski
|
|
89 |
11845a9e
|
Leszek Koltunski
|
for(int i=0; i<numChildren; i++)
|
90 |
c9f953c2
|
Leszek Koltunski
|
{
|
91 |
11845a9e
|
Leszek Koltunski
|
node = mChildren.getChild(i);
|
92 |
c9f953c2
|
Leszek Koltunski
|
ret.add(node.mData.ID);
|
93 |
|
|
}
|
94 |
|
|
|
95 |
|
|
// A bit questionable decision here - we are sorting the children IDs, which means
|
96 |
|
|
// that order in which we draw the children is going to be undefined (well, this is not
|
97 |
|
|
// strictly speaking true - when rendering, if no postprocessing and isomorphism are
|
98 |
|
|
// involved, we *DO* render the children in order they were added; if however there
|
99 |
|
|
// are two internal nodes with the same list of identical children, just added in a
|
100 |
|
|
// different order each time, then we consider them isomorphic, i.e. identical and only
|
101 |
|
|
// render the first one. If then two children of such 'pseudo-isomorphic' nodes are at
|
102 |
|
|
// exactly the same Z-height this might result in some unexpected sights).
|
103 |
|
|
//
|
104 |
|
|
// Reason: with the children being sorted by postprocessing buckets, the order is
|
105 |
|
|
// undefined anyway (although only when postprocessing is applied).
|
106 |
|
|
//
|
107 |
|
|
// See the consequences in the 'Olympic' app - remove a few leaves and add them back in
|
108 |
d5e053a5
|
Leszek Koltunski
|
// different order. You will see the number of renders go back to the original 15.
|
109 |
c9f953c2
|
Leszek Koltunski
|
Collections.sort(ret);
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
ret.add( 0, mSurface.getID() );
|
113 |
|
|
|
114 |
6a06a912
|
Leszek Koltunski
|
return ret;
|
115 |
|
|
}
|
116 |
|
|
|
117 |
9cae4322
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
118 |
11845a9e
|
Leszek Koltunski
|
/**
|
119 |
|
|
* This is not really part of the public API. Has to be public only because it is a part of the
|
120 |
7602a827
|
Leszek Koltunski
|
* InternalChildrenList.Parent interface.
|
121 |
11845a9e
|
Leszek Koltunski
|
*
|
122 |
|
|
* @y.exclude
|
123 |
|
|
*/
|
124 |
|
|
public void adjustIsomorphism()
|
125 |
9cae4322
|
Leszek Koltunski
|
{
|
126 |
7602a827
|
Leszek Koltunski
|
InternalNodeData newData = InternalNodeData.returnData(generateIDList());
|
127 |
8bfefd68
|
Leszek Koltunski
|
boolean deleteOldFBO = mData.removeData();
|
128 |
11845a9e
|
Leszek Koltunski
|
boolean createNewFBO = (mChildren.getNumChildren()>0 && newData.mFBO==null);
|
129 |
c204c69d
|
leszek
|
|
130 |
f28fffc2
|
Leszek Koltunski
|
if( deleteOldFBO && createNewFBO )
|
131 |
|
|
{
|
132 |
8bfefd68
|
Leszek Koltunski
|
newData.mFBO = mData.mFBO;
|
133 |
f28fffc2
|
Leszek Koltunski
|
}
|
134 |
|
|
else if( deleteOldFBO )
|
135 |
|
|
{
|
136 |
|
|
mData.mFBO.markForDeletion();
|
137 |
|
|
mData.mFBO = null;
|
138 |
|
|
}
|
139 |
|
|
else if( createNewFBO )
|
140 |
|
|
{
|
141 |
11845a9e
|
Leszek Koltunski
|
newData.mFBO = allocateNewFBO();
|
142 |
f28fffc2
|
Leszek Koltunski
|
}
|
143 |
af27df87
|
leszek
|
|
144 |
f28fffc2
|
Leszek Koltunski
|
mData = newData;
|
145 |
c204c69d
|
leszek
|
|
146 |
f28fffc2
|
Leszek Koltunski
|
if( mParent!=null ) mParent.adjustIsomorphism();
|
147 |
fee0865c
|
Leszek Koltunski
|
}
|
148 |
c204c69d
|
leszek
|
|
149 |
8dccc3c2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
150 |
|
|
// return the total number of render calls issued
|
151 |
|
|
|
152 |
7602a827
|
Leszek Koltunski
|
int drawNoBlend(long currTime, InternalOutputSurface surface)
|
153 |
8dccc3c2
|
Leszek Koltunski
|
{
|
154 |
eddf0cb7
|
Leszek Koltunski
|
InternalSurface input = getSurface();
|
155 |
8dccc3c2
|
Leszek Koltunski
|
|
156 |
|
|
if( input.setAsInput() )
|
157 |
|
|
{
|
158 |
|
|
mState.apply();
|
159 |
|
|
GLES31.glDisable(GLES31.GL_BLEND);
|
160 |
7602a827
|
Leszek Koltunski
|
DistortedLibrary.drawPriv(mEffects.getQueues(), mSurface.getWidth()/2.0f, mSurface.getHeight()/2.0f, mMesh, surface, currTime);
|
161 |
8dccc3c2
|
Leszek Koltunski
|
GLES31.glEnable(GLES31.GL_BLEND);
|
162 |
|
|
return 1;
|
163 |
|
|
}
|
164 |
c1a38ba3
|
Leszek Koltunski
|
|
165 |
|
|
return 0;
|
166 |
|
|
}
|
167 |
|
|
|
168 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
169 |
|
|
// Use the Order Independent Transparency method to draw a non-postprocessed child.
|
170 |
|
|
|
171 |
7602a827
|
Leszek Koltunski
|
int drawOIT(long currTime, InternalOutputSurface surface)
|
172 |
c1a38ba3
|
Leszek Koltunski
|
{
|
173 |
eddf0cb7
|
Leszek Koltunski
|
InternalSurface input = getSurface();
|
174 |
c1a38ba3
|
Leszek Koltunski
|
|
175 |
|
|
if( input.setAsInput() )
|
176 |
|
|
{
|
177 |
|
|
mState.apply();
|
178 |
7602a827
|
Leszek Koltunski
|
DistortedLibrary.drawPrivOIT(mEffects.getQueues(), mSurface.getWidth()/2.0f, mSurface.getHeight()/2.0f, mMesh, surface, currTime);
|
179 |
c1a38ba3
|
Leszek Koltunski
|
return 1;
|
180 |
|
|
}
|
181 |
8dccc3c2
|
Leszek Koltunski
|
|
182 |
|
|
return 0;
|
183 |
|
|
}
|
184 |
|
|
|
185 |
39086ebb
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
186 |
|
|
// return the total number of render calls issued
|
187 |
|
|
|
188 |
7602a827
|
Leszek Koltunski
|
int draw(long currTime, InternalOutputSurface surface)
|
189 |
39086ebb
|
leszek
|
{
|
190 |
eddf0cb7
|
Leszek Koltunski
|
InternalSurface input = getSurface();
|
191 |
39086ebb
|
leszek
|
|
192 |
|
|
if( input.setAsInput() )
|
193 |
|
|
{
|
194 |
|
|
mState.apply();
|
195 |
7602a827
|
Leszek Koltunski
|
DistortedLibrary.drawPriv(mEffects.getQueues(), mSurface.getWidth()/2.0f, mSurface.getHeight()/2.0f, mMesh, surface, currTime);
|
196 |
39086ebb
|
leszek
|
return 1;
|
197 |
|
|
}
|
198 |
|
|
|
199 |
|
|
return 0;
|
200 |
|
|
}
|
201 |
|
|
|
202 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
203 |
|
|
// return the total number of render calls issued
|
204 |
|
|
|
205 |
|
|
int renderRecursive(long currTime)
|
206 |
|
|
{
|
207 |
|
|
int numRenders = 0;
|
208 |
11845a9e
|
Leszek Koltunski
|
int numChildren = mChildren.getNumChildren();
|
209 |
39086ebb
|
leszek
|
|
210 |
11845a9e
|
Leszek Koltunski
|
if( numChildren>0 && mData.notRenderedYetAtThisTime(currTime) )
|
211 |
39086ebb
|
leszek
|
{
|
212 |
d5b709df
|
Leszek Koltunski
|
DistortedNode node;
|
213 |
|
|
long oldBucket=0, newBucket;
|
214 |
|
|
|
215 |
11845a9e
|
Leszek Koltunski
|
for (int i=0; i<numChildren; i++)
|
216 |
0c303a2c
|
Leszek Koltunski
|
{
|
217 |
d5b709df
|
Leszek Koltunski
|
node = mChildren.getChild(i);
|
218 |
|
|
newBucket = node.getBucket();
|
219 |
|
|
numRenders += node.renderRecursive(currTime);
|
220 |
|
|
if( newBucket<oldBucket ) mChildren.rearrangeByBuckets(i,newBucket);
|
221 |
|
|
else oldBucket=newBucket;
|
222 |
0c303a2c
|
Leszek Koltunski
|
}
|
223 |
|
|
|
224 |
11845a9e
|
Leszek Koltunski
|
if( mData.mFBO==null ) mData.mFBO = allocateNewFBO();
|
225 |
95c441a2
|
leszek
|
mData.mFBO.setAsOutput(currTime);
|
226 |
39086ebb
|
leszek
|
|
227 |
|
|
if( mSurface.setAsInput() )
|
228 |
|
|
{
|
229 |
|
|
numRenders++;
|
230 |
7602a827
|
Leszek Koltunski
|
DistortedLibrary.blitPriv(mData.mFBO);
|
231 |
39086ebb
|
leszek
|
}
|
232 |
|
|
|
233 |
11845a9e
|
Leszek Koltunski
|
numRenders += mData.mFBO.renderChildren(currTime,numChildren,mChildren,0, mRenderWayOIT);
|
234 |
39086ebb
|
leszek
|
}
|
235 |
|
|
|
236 |
|
|
return numRenders;
|
237 |
|
|
}
|
238 |
|
|
|
239 |
be60d4ff
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
240 |
|
|
|
241 |
11845a9e
|
Leszek Koltunski
|
private DistortedFramebuffer allocateNewFBO()
|
242 |
be60d4ff
|
leszek
|
{
|
243 |
11845a9e
|
Leszek Koltunski
|
int width = mFboW <= 0 ? mSurface.getWidth() : mFboW;
|
244 |
|
|
int height = mFboH <= 0 ? mSurface.getHeight() : mFboH;
|
245 |
7602a827
|
Leszek Koltunski
|
return new DistortedFramebuffer(1,mFboDepthStencil, InternalSurface.TYPE_TREE, width, height);
|
246 |
11845a9e
|
Leszek Koltunski
|
}
|
247 |
|
|
|
248 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
249 |
|
|
|
250 |
7602a827
|
Leszek Koltunski
|
void setParent(InternalChildrenList.Parent parent)
|
251 |
11845a9e
|
Leszek Koltunski
|
{
|
252 |
|
|
mParent = parent;
|
253 |
be60d4ff
|
leszek
|
}
|
254 |
|
|
|
255 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
256 |
|
|
// PUBLIC API
|
257 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
258 |
|
|
/**
|
259 |
a09ada4c
|
Leszek Koltunski
|
* Constructs new Node.
|
260 |
6a06a912
|
Leszek Koltunski
|
*
|
261 |
c5369f1b
|
leszek
|
* @param surface InputSurface to put into the new Node.
|
262 |
07d8ef09
|
Leszek Koltunski
|
* @param effects DistortedEffects to put into the new Node.
|
263 |
715e7726
|
Leszek Koltunski
|
* @param mesh MeshBase to put into the new Node.
|
264 |
6a06a912
|
Leszek Koltunski
|
*/
|
265 |
7602a827
|
Leszek Koltunski
|
public DistortedNode(InternalSurface surface, DistortedEffects effects, MeshBase mesh)
|
266 |
6a06a912
|
Leszek Koltunski
|
{
|
267 |
c5369f1b
|
leszek
|
mSurface = surface;
|
268 |
8ca9f899
|
Leszek Koltunski
|
mEffects = effects;
|
269 |
|
|
mMesh = mesh;
|
270 |
7602a827
|
Leszek Koltunski
|
mState = new InternalRenderState();
|
271 |
|
|
mChildren = new InternalChildrenList(this);
|
272 |
f28fffc2
|
Leszek Koltunski
|
mParent = null;
|
273 |
406e2f6b
|
Leszek Koltunski
|
mRenderWayOIT = false;
|
274 |
f28fffc2
|
Leszek Koltunski
|
|
275 |
23eecbd9
|
Leszek Koltunski
|
mFboW = 0; // i.e. take this from
|
276 |
|
|
mFboH = 0; // mSurface's dimensions
|
277 |
|
|
mFboDepthStencil = DistortedFramebuffer.DEPTH_NO_STENCIL;
|
278 |
|
|
|
279 |
7602a827
|
Leszek Koltunski
|
mData = InternalNodeData.returnData(generateIDList());
|
280 |
6a06a912
|
Leszek Koltunski
|
}
|
281 |
|
|
|
282 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
283 |
|
|
/**
|
284 |
a09ada4c
|
Leszek Koltunski
|
* Copy-constructs new Node from another Node.
|
285 |
6a06a912
|
Leszek Koltunski
|
*
|
286 |
a09ada4c
|
Leszek Koltunski
|
* @param node The DistortedNode to copy data from.
|
287 |
6a06a912
|
Leszek Koltunski
|
* @param flags bit field composed of a subset of the following:
|
288 |
7602a827
|
Leszek Koltunski
|
* {@link DistortedLibrary#CLONE_SURFACE}, {@link DistortedLibrary#CLONE_MATRIX}, {@link DistortedLibrary#CLONE_VERTEX},
|
289 |
|
|
* {@link DistortedLibrary#CLONE_FRAGMENT} and {@link DistortedLibrary#CLONE_CHILDREN}.
|
290 |
29a06526
|
Leszek Koltunski
|
* For example flags = CLONE_SURFACE | CLONE_CHILDREN.
|
291 |
6a06a912
|
Leszek Koltunski
|
*/
|
292 |
a09ada4c
|
Leszek Koltunski
|
public DistortedNode(DistortedNode node, int flags)
|
293 |
6a06a912
|
Leszek Koltunski
|
{
|
294 |
be60d4ff
|
leszek
|
mEffects = new DistortedEffects(node.mEffects,flags);
|
295 |
|
|
mMesh = node.mMesh;
|
296 |
7602a827
|
Leszek Koltunski
|
mState = new InternalRenderState();
|
297 |
be60d4ff
|
leszek
|
mParent = null;
|
298 |
406e2f6b
|
Leszek Koltunski
|
mRenderWayOIT = false;
|
299 |
9361b337
|
Leszek Koltunski
|
|
300 |
23eecbd9
|
Leszek Koltunski
|
mFboW = node.mFboW;
|
301 |
|
|
mFboH = node.mFboH;
|
302 |
|
|
mFboDepthStencil = node.mFboDepthStencil;
|
303 |
|
|
|
304 |
7602a827
|
Leszek Koltunski
|
if( (flags & DistortedLibrary.CLONE_SURFACE) != 0 )
|
305 |
e7a20702
|
Leszek Koltunski
|
{
|
306 |
c5369f1b
|
leszek
|
mSurface = node.mSurface;
|
307 |
e7a20702
|
Leszek Koltunski
|
}
|
308 |
|
|
else
|
309 |
|
|
{
|
310 |
c5369f1b
|
leszek
|
int w = node.mSurface.getWidth();
|
311 |
|
|
int h = node.mSurface.getHeight();
|
312 |
8ca9f899
|
Leszek Koltunski
|
|
313 |
c5369f1b
|
leszek
|
if( node.mSurface instanceof DistortedTexture )
|
314 |
8ca9f899
|
Leszek Koltunski
|
{
|
315 |
7602a827
|
Leszek Koltunski
|
mSurface = new DistortedTexture(w,h, InternalSurface.TYPE_TREE);
|
316 |
8ca9f899
|
Leszek Koltunski
|
}
|
317 |
c5369f1b
|
leszek
|
else if( node.mSurface instanceof DistortedFramebuffer )
|
318 |
8ca9f899
|
Leszek Koltunski
|
{
|
319 |
23eecbd9
|
Leszek Koltunski
|
int depthStencil = DistortedFramebuffer.NO_DEPTH_NO_STENCIL;
|
320 |
89de975c
|
leszek
|
|
321 |
|
|
if( ((DistortedFramebuffer) node.mSurface).hasDepth() )
|
322 |
|
|
{
|
323 |
|
|
boolean hasStencil = ((DistortedFramebuffer) node.mSurface).hasStencil();
|
324 |
|
|
depthStencil = (hasStencil ? DistortedFramebuffer.BOTH_DEPTH_STENCIL:DistortedFramebuffer.DEPTH_NO_STENCIL);
|
325 |
|
|
}
|
326 |
|
|
|
327 |
7602a827
|
Leszek Koltunski
|
mSurface = new DistortedFramebuffer(1,depthStencil, InternalSurface.TYPE_TREE,w,h);
|
328 |
8ca9f899
|
Leszek Koltunski
|
}
|
329 |
e7a20702
|
Leszek Koltunski
|
}
|
330 |
11845a9e
|
Leszek Koltunski
|
|
331 |
7602a827
|
Leszek Koltunski
|
if( (flags & DistortedLibrary.CLONE_CHILDREN) != 0 )
|
332 |
6a06a912
|
Leszek Koltunski
|
{
|
333 |
|
|
mChildren = node.mChildren;
|
334 |
|
|
}
|
335 |
|
|
else
|
336 |
|
|
{
|
337 |
7602a827
|
Leszek Koltunski
|
mChildren = new InternalChildrenList(this);
|
338 |
6a06a912
|
Leszek Koltunski
|
}
|
339 |
26a4e5f6
|
leszek
|
|
340 |
7602a827
|
Leszek Koltunski
|
mData = InternalNodeData.returnData(generateIDList());
|
341 |
6a06a912
|
Leszek Koltunski
|
}
|
342 |
c204c69d
|
leszek
|
|
343 |
406e2f6b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
344 |
|
|
/**
|
345 |
|
|
* When rendering this Node, should we use the Order Independent Transparency render more?
|
346 |
|
|
* <p>
|
347 |
|
|
* There are two modes of rendering: the fast 'normal' way, which however renders transparent
|
348 |
|
|
* fragments in different ways depending on which fragments get rendered first, or the slower
|
349 |
|
|
* 'oit' way, which renders transparent fragments correctly regardless of their order.
|
350 |
|
|
*
|
351 |
|
|
* @param oit True if we want to render more slowly, but in a way which accounts for transparency.
|
352 |
|
|
*/
|
353 |
|
|
public void setOrderIndependentTransparency(boolean oit)
|
354 |
|
|
{
|
355 |
|
|
mRenderWayOIT = oit;
|
356 |
|
|
}
|
357 |
|
|
|
358 |
12f9e4bb
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
359 |
|
|
/**
|
360 |
|
|
* When rendering this Node, should we use the Order Independent Transparency render more?
|
361 |
|
|
* <p>
|
362 |
|
|
* There are two modes of rendering: the fast 'normal' way, which however renders transparent
|
363 |
|
|
* fragments in different ways depending on which fragments get rendered first, or the slower
|
364 |
|
|
* 'oit' way, which renders transparent fragments correctly regardless of their order.
|
365 |
|
|
*
|
366 |
|
|
* @param oit True if we want to render more slowly, but in a way which accounts for transparency.
|
367 |
|
|
* @param initialSize Initial number of transparent fragments we expect, in screenfulls.
|
368 |
|
|
* I.e '1.0' means 'the scene we are going to render contains about 1 screen
|
369 |
|
|
* worth of transparent fragments'. Valid values: 0.0 < initialSize < 10.0
|
370 |
|
|
* Even if you get this wrong, the library will detect that there are more
|
371 |
|
|
* transparent fragments than it has space for and readjust its internal buffers,
|
372 |
|
|
* but only after a few frames during which one will probably see missing objects.
|
373 |
|
|
*/
|
374 |
|
|
public void setOrderIndependentTransparency(boolean oit, float initialSize)
|
375 |
|
|
{
|
376 |
|
|
mRenderWayOIT = oit;
|
377 |
|
|
|
378 |
|
|
if( initialSize>0.0f && initialSize<10.0f )
|
379 |
7602a827
|
Leszek Koltunski
|
DistortedLibrary.setSSBOSize(initialSize);
|
380 |
12f9e4bb
|
Leszek Koltunski
|
}
|
381 |
|
|
|
382 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
383 |
|
|
/**
|
384 |
|
|
* Adds a new child to the last position in the list of our Node's children.
|
385 |
c204c69d
|
leszek
|
* <p>
|
386 |
|
|
* We cannot do this mid-render - actual attachment will be done just before the next render, by the
|
387 |
7602a827
|
Leszek Koltunski
|
* InternalMaster (by calling doWork())
|
388 |
c204c69d
|
leszek
|
*
|
389 |
6a06a912
|
Leszek Koltunski
|
* @param node The new Node to add.
|
390 |
|
|
*/
|
391 |
c204c69d
|
leszek
|
public void attach(DistortedNode node)
|
392 |
6a06a912
|
Leszek Koltunski
|
{
|
393 |
11845a9e
|
Leszek Koltunski
|
mChildren.attach(node);
|
394 |
6a06a912
|
Leszek Koltunski
|
}
|
395 |
c204c69d
|
leszek
|
|
396 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
397 |
|
|
/**
|
398 |
|
|
* Adds a new child to the last position in the list of our Node's children.
|
399 |
c204c69d
|
leszek
|
* <p>
|
400 |
|
|
* We cannot do this mid-render - actual attachment will be done just before the next render, by the
|
401 |
7602a827
|
Leszek Koltunski
|
* InternalMaster (by calling doWork())
|
402 |
c204c69d
|
leszek
|
*
|
403 |
c5369f1b
|
leszek
|
* @param surface InputSurface to initialize our child Node with.
|
404 |
07d8ef09
|
Leszek Koltunski
|
* @param effects DistortedEffects to initialize our child Node with.
|
405 |
715e7726
|
Leszek Koltunski
|
* @param mesh MeshBase to initialize our child Node with.
|
406 |
6a06a912
|
Leszek Koltunski
|
* @return the newly constructed child Node, or null if we couldn't allocate resources.
|
407 |
|
|
*/
|
408 |
7602a827
|
Leszek Koltunski
|
public DistortedNode attach(InternalSurface surface, DistortedEffects effects, MeshBase mesh)
|
409 |
6a06a912
|
Leszek Koltunski
|
{
|
410 |
11845a9e
|
Leszek Koltunski
|
return mChildren.attach(surface,effects,mesh);
|
411 |
c204c69d
|
leszek
|
}
|
412 |
f8377ef8
|
leszek
|
|
413 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
414 |
|
|
/**
|
415 |
|
|
* Removes the first occurrence of a specified child from the list of children of our Node.
|
416 |
c204c69d
|
leszek
|
* <p>
|
417 |
|
|
* We cannot do this mid-render - actual detachment will be done just before the next render, by the
|
418 |
7602a827
|
Leszek Koltunski
|
* InternalMaster (by calling doWork())
|
419 |
c204c69d
|
leszek
|
*
|
420 |
6a06a912
|
Leszek Koltunski
|
* @param node The Node to remove.
|
421 |
|
|
*/
|
422 |
c204c69d
|
leszek
|
public void detach(DistortedNode node)
|
423 |
6a06a912
|
Leszek Koltunski
|
{
|
424 |
11845a9e
|
Leszek Koltunski
|
mChildren.detach(node);
|
425 |
6a06a912
|
Leszek Koltunski
|
}
|
426 |
a09ada4c
|
Leszek Koltunski
|
|
427 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
428 |
|
|
/**
|
429 |
|
|
* Removes the first occurrence of a specified child from the list of children of our Node.
|
430 |
a09ada4c
|
Leszek Koltunski
|
* <p>
|
431 |
|
|
* A bit questionable method as there can be many different Nodes attached as children, some
|
432 |
|
|
* of them having the same Effects but - for instance - different Mesh. Use with care.
|
433 |
c204c69d
|
leszek
|
* <p>
|
434 |
|
|
* We cannot do this mid-render - actual detachment will be done just before the next render, by the
|
435 |
7602a827
|
Leszek Koltunski
|
* InternalMaster (by calling doWork())
|
436 |
a09ada4c
|
Leszek Koltunski
|
*
|
437 |
07d8ef09
|
Leszek Koltunski
|
* @param effects DistortedEffects to remove.
|
438 |
6a06a912
|
Leszek Koltunski
|
*/
|
439 |
c204c69d
|
leszek
|
public void detach(DistortedEffects effects)
|
440 |
6a06a912
|
Leszek Koltunski
|
{
|
441 |
11845a9e
|
Leszek Koltunski
|
mChildren.detach(effects);
|
442 |
c204c69d
|
leszek
|
}
|
443 |
|
|
|
444 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
445 |
|
|
/**
|
446 |
|
|
* Removes all children Nodes.
|
447 |
|
|
* <p>
|
448 |
|
|
* We cannot do this mid-render - actual detachment will be done just before the next render, by the
|
449 |
7602a827
|
Leszek Koltunski
|
* InternalMaster (by calling doWork())
|
450 |
c204c69d
|
leszek
|
*/
|
451 |
|
|
public void detachAll()
|
452 |
|
|
{
|
453 |
11845a9e
|
Leszek Koltunski
|
mChildren.detachAll();
|
454 |
6a06a912
|
Leszek Koltunski
|
}
|
455 |
13687207
|
leszek
|
|
456 |
27f42cd6
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
457 |
6a06a912
|
Leszek Koltunski
|
/**
|
458 |
421c2728
|
Leszek Koltunski
|
* Returns the DistortedEffects object that's in the Node.
|
459 |
6a06a912
|
Leszek Koltunski
|
*
|
460 |
421c2728
|
Leszek Koltunski
|
* @return The DistortedEffects contained in the Node.
|
461 |
6a06a912
|
Leszek Koltunski
|
*/
|
462 |
421c2728
|
Leszek Koltunski
|
public DistortedEffects getEffects()
|
463 |
6a06a912
|
Leszek Koltunski
|
{
|
464 |
07d8ef09
|
Leszek Koltunski
|
return mEffects;
|
465 |
4e2382f3
|
Leszek Koltunski
|
}
|
466 |
|
|
|
467 |
a13dde77
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
468 |
|
|
/**
|
469 |
eddf0cb7
|
Leszek Koltunski
|
* Returns the surface this object gets rendered to.
|
470 |
a13dde77
|
Leszek Koltunski
|
*
|
471 |
7602a827
|
Leszek Koltunski
|
* @return The InternalSurface contained in the Node (if a leaf), or the FBO (if an internal Node)
|
472 |
a13dde77
|
Leszek Koltunski
|
*/
|
473 |
eddf0cb7
|
Leszek Koltunski
|
public InternalSurface getSurface()
|
474 |
a13dde77
|
Leszek Koltunski
|
{
|
475 |
11845a9e
|
Leszek Koltunski
|
return mChildren.getNumChildren()==0 ? mSurface : mData.mFBO;
|
476 |
a13dde77
|
Leszek Koltunski
|
}
|
477 |
|
|
|
478 |
f1a82766
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
479 |
|
|
/**
|
480 |
|
|
* Returns the Mesh object that's in the Node.
|
481 |
|
|
*
|
482 |
|
|
* @return Mesh contained in the Node.
|
483 |
|
|
*/
|
484 |
715e7726
|
Leszek Koltunski
|
public MeshBase getMesh()
|
485 |
f1a82766
|
Leszek Koltunski
|
{
|
486 |
|
|
return mMesh;
|
487 |
|
|
}
|
488 |
|
|
|
489 |
8c327653
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
490 |
|
|
/**
|
491 |
23eecbd9
|
Leszek Koltunski
|
* Resizes the DistortedFramebuffer object that we render this Node to.
|
492 |
8c327653
|
Leszek Koltunski
|
*/
|
493 |
23eecbd9
|
Leszek Koltunski
|
public void resize(int width, int height)
|
494 |
8c327653
|
Leszek Koltunski
|
{
|
495 |
23eecbd9
|
Leszek Koltunski
|
mFboW = width;
|
496 |
|
|
mFboH = height;
|
497 |
|
|
|
498 |
|
|
if ( mData.mFBO !=null )
|
499 |
|
|
{
|
500 |
|
|
// TODO: potentially allocate a new NodeData if we have to
|
501 |
|
|
mData.mFBO.resize(width,height);
|
502 |
|
|
}
|
503 |
|
|
}
|
504 |
|
|
|
505 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
506 |
|
|
/**
|
507 |
|
|
* Enables/disables DEPTH and STENCIL buffers in the Framebuffer object that we render this Node to.
|
508 |
|
|
*/
|
509 |
|
|
public void enableDepthStencil(int depthStencil)
|
510 |
|
|
{
|
511 |
|
|
mFboDepthStencil = depthStencil;
|
512 |
|
|
|
513 |
|
|
if ( mData.mFBO !=null )
|
514 |
|
|
{
|
515 |
|
|
// TODO: potentially allocate a new NodeData if we have to
|
516 |
|
|
mData.mFBO.enableDepthStencil(depthStencil);
|
517 |
|
|
}
|
518 |
8c327653
|
Leszek Koltunski
|
}
|
519 |
6a06a912
|
Leszek Koltunski
|
|
520 |
ad16ed3b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
521 |
|
|
// APIs that control how to set the OpenGL state just before rendering this Node.
|
522 |
c834348d
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
523 |
|
|
/**
|
524 |
|
|
* When rendering this Node, use ColorMask (r,g,b,a).
|
525 |
|
|
*
|
526 |
|
|
* @param r Write to the RED color channel when rendering this Node?
|
527 |
|
|
* @param g Write to the GREEN color channel when rendering this Node?
|
528 |
|
|
* @param b Write to the BLUE color channel when rendering this Node?
|
529 |
|
|
* @param a Write to the ALPHA channel when rendering this Node?
|
530 |
|
|
*/
|
531 |
13687207
|
leszek
|
@SuppressWarnings("unused")
|
532 |
c834348d
|
leszek
|
public void glColorMask(boolean r, boolean g, boolean b, boolean a)
|
533 |
|
|
{
|
534 |
|
|
mState.glColorMask(r,g,b,a);
|
535 |
|
|
}
|
536 |
|
|
|
537 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
538 |
|
|
/**
|
539 |
|
|
* When rendering this Node, switch on writing to Depth buffer?
|
540 |
|
|
*
|
541 |
|
|
* @param mask Write to the Depth buffer when rendering this Node?
|
542 |
|
|
*/
|
543 |
13687207
|
leszek
|
@SuppressWarnings("unused")
|
544 |
c834348d
|
leszek
|
public void glDepthMask(boolean mask)
|
545 |
|
|
{
|
546 |
|
|
mState.glDepthMask(mask);
|
547 |
|
|
}
|
548 |
|
|
|
549 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
550 |
|
|
/**
|
551 |
|
|
* When rendering this Node, which bits of the Stencil buffer to write to?
|
552 |
|
|
*
|
553 |
|
|
* @param mask Marks the bits of the Stencil buffer we will write to when rendering this Node.
|
554 |
|
|
*/
|
555 |
13687207
|
leszek
|
@SuppressWarnings("unused")
|
556 |
c834348d
|
leszek
|
public void glStencilMask(int mask)
|
557 |
|
|
{
|
558 |
|
|
mState.glStencilMask(mask);
|
559 |
|
|
}
|
560 |
|
|
|
561 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
562 |
|
|
/**
|
563 |
|
|
* When rendering this Node, which Tests to enable?
|
564 |
|
|
*
|
565 |
|
|
* @param test Valid values: GL_DEPTH_TEST, GL_STENCIL_TEST, GL_BLEND
|
566 |
|
|
*/
|
567 |
13687207
|
leszek
|
@SuppressWarnings("unused")
|
568 |
c834348d
|
leszek
|
public void glEnable(int test)
|
569 |
|
|
{
|
570 |
|
|
mState.glEnable(test);
|
571 |
|
|
}
|
572 |
|
|
|
573 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
574 |
|
|
/**
|
575 |
|
|
* When rendering this Node, which Tests to enable?
|
576 |
|
|
*
|
577 |
|
|
* @param test Valid values: GL_DEPTH_TEST, GL_STENCIL_TEST, GL_BLEND
|
578 |
|
|
*/
|
579 |
13687207
|
leszek
|
@SuppressWarnings("unused")
|
580 |
c834348d
|
leszek
|
public void glDisable(int test)
|
581 |
|
|
{
|
582 |
|
|
mState.glDisable(test);
|
583 |
|
|
}
|
584 |
|
|
|
585 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
586 |
|
|
/**
|
587 |
|
|
* When rendering this Node, use the following StencilFunc.
|
588 |
|
|
*
|
589 |
|
|
* @param func Valid values: GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER, GL_NOTEQUAL
|
590 |
|
|
* @param ref Reference valut to compare our stencil with.
|
591 |
|
|
* @param mask Mask used when comparing.
|
592 |
|
|
*/
|
593 |
13687207
|
leszek
|
@SuppressWarnings("unused")
|
594 |
c834348d
|
leszek
|
public void glStencilFunc(int func, int ref, int mask)
|
595 |
|
|
{
|
596 |
|
|
mState.glStencilFunc(func,ref,mask);
|
597 |
|
|
}
|
598 |
|
|
|
599 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
600 |
|
|
/**
|
601 |
|
|
* When rendering this Node, use the following StencilOp.
|
602 |
|
|
* <p>
|
603 |
|
|
* Valid values of all 3 parameters: GL_KEEP, GL_ZERO, GL_REPLACE, GL_INCR, GL_DECR, GL_INVERT, GL_INCR_WRAP, GL_DECR_WRAP
|
604 |
|
|
*
|
605 |
|
|
* @param sfail What to do when Stencil Test fails.
|
606 |
|
|
* @param dpfail What to do when Depth Test fails.
|
607 |
|
|
* @param dppass What to do when Depth Test passes.
|
608 |
|
|
*/
|
609 |
13687207
|
leszek
|
@SuppressWarnings("unused")
|
610 |
c834348d
|
leszek
|
public void glStencilOp(int sfail, int dpfail, int dppass)
|
611 |
|
|
{
|
612 |
|
|
mState.glStencilOp(sfail,dpfail,dppass);
|
613 |
|
|
}
|
614 |
|
|
|
615 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
616 |
|
|
/**
|
617 |
|
|
* When rendering this Node, use the following DepthFunc.
|
618 |
|
|
*
|
619 |
|
|
* @param func Valid values: GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER, GL_NOTEQUAL
|
620 |
|
|
*/
|
621 |
13687207
|
leszek
|
@SuppressWarnings("unused")
|
622 |
c834348d
|
leszek
|
public void glDepthFunc(int func)
|
623 |
|
|
{
|
624 |
|
|
mState.glDepthFunc(func);
|
625 |
|
|
}
|
626 |
|
|
|
627 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
628 |
|
|
/**
|
629 |
|
|
* When rendering this Node, use the following Blending mode.
|
630 |
|
|
* <p>
|
631 |
|
|
* Valid values: GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
|
632 |
|
|
* GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR,
|
633 |
|
|
* GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_SRC_ALPHA_SATURATE
|
634 |
|
|
*
|
635 |
|
|
* @param src Source Blend function
|
636 |
|
|
* @param dst Destination Blend function
|
637 |
|
|
*/
|
638 |
13687207
|
leszek
|
@SuppressWarnings("unused")
|
639 |
c834348d
|
leszek
|
public void glBlendFunc(int src, int dst)
|
640 |
|
|
{
|
641 |
|
|
mState.glBlendFunc(src,dst);
|
642 |
|
|
}
|
643 |
ad16ed3b
|
Leszek Koltunski
|
|
644 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
645 |
|
|
/**
|
646 |
|
|
* Before rendering this Node, clear the following buffers.
|
647 |
|
|
* <p>
|
648 |
|
|
* Valid values: 0, or bitwise OR of one or more values from the set GL_COLOR_BUFFER_BIT,
|
649 |
|
|
* GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT.
|
650 |
|
|
* Default: 0
|
651 |
|
|
*
|
652 |
|
|
* @param mask bitwise OR of BUFFER_BITs to clear.
|
653 |
|
|
*/
|
654 |
|
|
@SuppressWarnings("unused")
|
655 |
|
|
public void glClear(int mask)
|
656 |
|
|
{
|
657 |
|
|
mState.glClear(mask);
|
658 |
|
|
}
|
659 |
8c327653
|
Leszek Koltunski
|
}
|