| 1 |
d333eb6b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
| 3 |
|
|
// //
|
| 4 |
|
|
// This file is part of Distorted. //
|
| 5 |
|
|
// //
|
| 6 |
|
|
// Distorted is free software: you can redistribute it and/or modify //
|
| 7 |
|
|
// 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 |
|
|
// Distorted 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 //
|
| 14 |
|
|
// GNU General Public License for more details. //
|
| 15 |
|
|
// //
|
| 16 |
|
|
// You should have received a copy of the GNU General Public License //
|
| 17 |
|
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
| 18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 19 |
|
|
|
| 20 |
6a06a912
|
Leszek Koltunski
|
package org.distorted.library;
|
| 21 |
|
|
|
| 22 |
|
|
import java.util.ArrayList;
|
| 23 |
|
|
import java.util.HashMap;
|
| 24 |
|
|
|
| 25 |
194ab46f
|
Leszek Koltunski
|
import android.opengl.GLES30;
|
| 26 |
6a06a912
|
Leszek Koltunski
|
|
| 27 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 28 |
|
|
/**
|
| 29 |
a09ada4c
|
Leszek Koltunski
|
* Class which represents a Node in a Tree of (InputSurface,Mesh,Effects) triplets.
|
| 30 |
c204c69d
|
leszek
|
* <p>
|
| 31 |
a09ada4c
|
Leszek Koltunski
|
* Having organized such sets into a Tree, we can then render any Node to any OutputSurface.
|
| 32 |
7b8086eb
|
Leszek Koltunski
|
* That recursively renders the set held in the Node and all its children.
|
| 33 |
c204c69d
|
leszek
|
* <p>
|
| 34 |
|
|
* The class takes special care to only render identical sub-trees once. Each Node holds a reference
|
| 35 |
|
|
* to sub-class 'NodeData'. Two identical sub-trees attached at different points of the main tree
|
| 36 |
|
|
* will point to the same NodeData; only the first of this is rendered (when mData.numRendered==0).
|
| 37 |
6a06a912
|
Leszek Koltunski
|
*/
|
| 38 |
c204c69d
|
leszek
|
public class DistortedNode implements DistortedAttacheable
|
| 39 |
6a06a912
|
Leszek Koltunski
|
{
|
| 40 |
bd3da5b2
|
Leszek Koltunski
|
private static HashMap<ArrayList<Long>,NodeData> mMapNodeID = new HashMap<>();
|
| 41 |
|
|
private static long mNextNodeID =0;
|
| 42 |
|
|
|
| 43 |
05403bba
|
Leszek Koltunski
|
private MeshObject mMesh;
|
| 44 |
07d8ef09
|
Leszek Koltunski
|
private DistortedEffects mEffects;
|
| 45 |
c5369f1b
|
leszek
|
private DistortedInputSurface mSurface;
|
| 46 |
6a06a912
|
Leszek Koltunski
|
private NodeData mData;
|
| 47 |
bd3da5b2
|
Leszek Koltunski
|
|
| 48 |
a09ada4c
|
Leszek Koltunski
|
private ArrayList<DistortedNode> mChildren;
|
| 49 |
6a06a912
|
Leszek Koltunski
|
private int[] mNumChildren; // ==mChildren.length(), but we only create mChildren if the first one gets added
|
| 50 |
|
|
|
| 51 |
|
|
private class NodeData
|
| 52 |
|
|
{
|
| 53 |
bd3da5b2
|
Leszek Koltunski
|
long ID;
|
| 54 |
6a06a912
|
Leszek Koltunski
|
int numPointingNodes;
|
| 55 |
7691a39f
|
leszek
|
int numRender;
|
| 56 |
af27df87
|
leszek
|
ArrayList<Long> key;
|
| 57 |
8c327653
|
Leszek Koltunski
|
DistortedFramebuffer mFBO;
|
| 58 |
6a06a912
|
Leszek Koltunski
|
|
| 59 |
af27df87
|
leszek
|
NodeData(long id, ArrayList<Long> k)
|
| 60 |
6a06a912
|
Leszek Koltunski
|
{
|
| 61 |
bd3da5b2
|
Leszek Koltunski
|
ID = id;
|
| 62 |
af27df87
|
leszek
|
key = k;
|
| 63 |
bd3da5b2
|
Leszek Koltunski
|
numPointingNodes= 1;
|
| 64 |
7691a39f
|
leszek
|
numRender =-1;
|
| 65 |
8c327653
|
Leszek Koltunski
|
mFBO = null;
|
| 66 |
6a06a912
|
Leszek Koltunski
|
}
|
| 67 |
bd3da5b2
|
Leszek Koltunski
|
}
|
| 68 |
6a06a912
|
Leszek Koltunski
|
|
| 69 |
436899f2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 70 |
|
|
|
| 71 |
7b8086eb
|
Leszek Koltunski
|
static synchronized void onDestroy()
|
| 72 |
436899f2
|
Leszek Koltunski
|
{
|
| 73 |
|
|
mNextNodeID = 0;
|
| 74 |
|
|
mMapNodeID.clear();
|
| 75 |
|
|
}
|
| 76 |
|
|
|
| 77 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 78 |
|
|
|
| 79 |
|
|
private ArrayList<Long> generateIDList()
|
| 80 |
|
|
{
|
| 81 |
9361b337
|
Leszek Koltunski
|
ArrayList<Long> ret = new ArrayList<>();
|
| 82 |
6a06a912
|
Leszek Koltunski
|
|
| 83 |
c5369f1b
|
leszek
|
ret.add( mSurface.getID() );
|
| 84 |
7691a39f
|
leszek
|
|
| 85 |
|
|
if( mNumChildren[0]==0 )
|
| 86 |
|
|
{
|
| 87 |
|
|
ret.add(-mEffects.getID());
|
| 88 |
|
|
}
|
| 89 |
|
|
|
| 90 |
a09ada4c
|
Leszek Koltunski
|
DistortedNode node;
|
| 91 |
6a06a912
|
Leszek Koltunski
|
|
| 92 |
|
|
for(int i=0; i<mNumChildren[0]; i++)
|
| 93 |
|
|
{
|
| 94 |
|
|
node = mChildren.get(i);
|
| 95 |
|
|
ret.add(node.mData.ID);
|
| 96 |
|
|
}
|
| 97 |
|
|
|
| 98 |
|
|
return ret;
|
| 99 |
|
|
}
|
| 100 |
|
|
|
| 101 |
fee0865c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 102 |
|
|
// Debug - print all the Node IDs
|
| 103 |
c204c69d
|
leszek
|
|
| 104 |
af27df87
|
leszek
|
@SuppressWarnings("unused")
|
| 105 |
fee0865c
|
Leszek Koltunski
|
void debug(int depth)
|
| 106 |
|
|
{
|
| 107 |
|
|
String tmp="";
|
| 108 |
|
|
int i;
|
| 109 |
|
|
|
| 110 |
|
|
for(i=0; i<depth; i++) tmp +=" ";
|
| 111 |
c204c69d
|
leszek
|
tmp += ("NodeID="+mData.ID+" (nodes pointing: "+mData.numPointingNodes+" surfaceID="+mSurface.getID()+")");
|
| 112 |
fee0865c
|
Leszek Koltunski
|
|
| 113 |
1942537e
|
Leszek Koltunski
|
android.util.Log.e("NODE", tmp);
|
| 114 |
fee0865c
|
Leszek Koltunski
|
|
| 115 |
|
|
for(i=0; i<mNumChildren[0]; i++)
|
| 116 |
|
|
mChildren.get(i).debug(depth+1);
|
| 117 |
|
|
}
|
| 118 |
|
|
|
| 119 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 120 |
|
|
// Debug - print contents of the HashMap
|
| 121 |
|
|
|
| 122 |
af27df87
|
leszek
|
@SuppressWarnings("unused")
|
| 123 |
fee0865c
|
Leszek Koltunski
|
static void debugMap()
|
| 124 |
|
|
{
|
| 125 |
|
|
NodeData tmp;
|
| 126 |
|
|
|
| 127 |
|
|
for(ArrayList<Long> key: mMapNodeID.keySet())
|
| 128 |
|
|
{
|
| 129 |
|
|
tmp = mMapNodeID.get(key);
|
| 130 |
c204c69d
|
leszek
|
android.util.Log.e("NODE", "NodeID: "+tmp.ID+" <-- "+key);
|
| 131 |
|
|
}
|
| 132 |
|
|
}
|
| 133 |
|
|
|
| 134 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 135 |
|
|
|
| 136 |
|
|
void treeIsomorphism()
|
| 137 |
|
|
{
|
| 138 |
|
|
for(int i=0; i<mNumChildren[0]; i++)
|
| 139 |
|
|
{
|
| 140 |
|
|
mChildren.get(i).treeIsomorphism();
|
| 141 |
|
|
}
|
| 142 |
|
|
|
| 143 |
|
|
ArrayList<Long> newList = generateIDList();
|
| 144 |
|
|
NodeData newData = mMapNodeID.get(newList);
|
| 145 |
|
|
|
| 146 |
|
|
if( newData==null )
|
| 147 |
|
|
{
|
| 148 |
af27df87
|
leszek
|
newData = new NodeData(++mNextNodeID,newList);
|
| 149 |
c204c69d
|
leszek
|
mMapNodeID.put(newList,newData);
|
| 150 |
|
|
}
|
| 151 |
|
|
else if( newData.ID != mData.ID )
|
| 152 |
|
|
{
|
| 153 |
|
|
newData.numPointingNodes++;
|
| 154 |
|
|
}
|
| 155 |
|
|
|
| 156 |
|
|
if( newData.ID != mData.ID )
|
| 157 |
|
|
{
|
| 158 |
|
|
boolean fboUsed = false;
|
| 159 |
|
|
|
| 160 |
|
|
if( mNumChildren[0]>0 && newData.mFBO==null )
|
| 161 |
|
|
{
|
| 162 |
|
|
if( mData.mFBO!=null )
|
| 163 |
|
|
{
|
| 164 |
af27df87
|
leszek
|
android.util.Log.d("NODE", "copying over FBO of node surfaceID="+mSurface.getID());
|
| 165 |
|
|
|
| 166 |
c204c69d
|
leszek
|
newData.mFBO = mData.mFBO;
|
| 167 |
|
|
fboUsed = true;
|
| 168 |
|
|
}
|
| 169 |
|
|
else
|
| 170 |
|
|
{
|
| 171 |
af27df87
|
leszek
|
android.util.Log.d("NODE", "creating new FBO of node surfaceID="+mSurface.getID());
|
| 172 |
09ab7524
|
Leszek Koltunski
|
newData.mFBO = new DistortedFramebuffer(true,DistortedSurface.TYPE_TREE,mSurface.getWidth(),mSurface.getHeight());
|
| 173 |
c204c69d
|
leszek
|
}
|
| 174 |
|
|
}
|
| 175 |
|
|
if( mNumChildren[0]==0 && newData.mFBO!=null )
|
| 176 |
|
|
{
|
| 177 |
af27df87
|
leszek
|
android.util.Log.d("NODE", "deleting FBO of newData node!!");
|
| 178 |
|
|
|
| 179 |
|
|
|
| 180 |
c204c69d
|
leszek
|
newData.mFBO.markForDeletion();
|
| 181 |
|
|
newData.mFBO = null;
|
| 182 |
|
|
}
|
| 183 |
|
|
|
| 184 |
|
|
if( --mData.numPointingNodes==0 )
|
| 185 |
|
|
{
|
| 186 |
af27df87
|
leszek
|
mMapNodeID.remove(mData.key);
|
| 187 |
c204c69d
|
leszek
|
|
| 188 |
|
|
if( !fboUsed && mData.mFBO!=null )
|
| 189 |
|
|
{
|
| 190 |
af27df87
|
leszek
|
android.util.Log.d("NODE", "deleting FBO of node surfaceID="+mSurface.getID());
|
| 191 |
|
|
|
| 192 |
c204c69d
|
leszek
|
mData.mFBO.markForDeletion();
|
| 193 |
|
|
mData.mFBO = null;
|
| 194 |
|
|
}
|
| 195 |
|
|
}
|
| 196 |
|
|
|
| 197 |
|
|
mData = newData;
|
| 198 |
fee0865c
|
Leszek Koltunski
|
}
|
| 199 |
|
|
}
|
| 200 |
c204c69d
|
leszek
|
|
| 201 |
a0f644b7
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 202 |
7691a39f
|
leszek
|
// return the total number of render calls issued
|
| 203 |
a0f644b7
|
Leszek Koltunski
|
|
| 204 |
d03782c0
|
leszek
|
int drawRecursive(int renderNum, long currTime, DistortedOutputSurface surface)
|
| 205 |
a0f644b7
|
Leszek Koltunski
|
{
|
| 206 |
7691a39f
|
leszek
|
int ret = 0;
|
| 207 |
c5369f1b
|
leszek
|
float halfX = mSurface.getWidth()/2.0f;
|
| 208 |
|
|
float halfY = mSurface.getHeight()/2.0f;
|
| 209 |
a0f644b7
|
Leszek Koltunski
|
|
| 210 |
d03782c0
|
leszek
|
if( mNumChildren[0]>0 && mData.numRender!=renderNum )
|
| 211 |
a0f644b7
|
Leszek Koltunski
|
{
|
| 212 |
d03782c0
|
leszek
|
mData.numRender = renderNum;
|
| 213 |
|
|
mData.mFBO.setAsOutput();
|
| 214 |
a0f644b7
|
Leszek Koltunski
|
|
| 215 |
d03782c0
|
leszek
|
GLES30.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
| 216 |
|
|
GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
|
| 217 |
a0f644b7
|
Leszek Koltunski
|
|
| 218 |
d03782c0
|
leszek
|
if( mSurface.setAsInput() )
|
| 219 |
|
|
{
|
| 220 |
|
|
ret++;
|
| 221 |
|
|
DistortedEffects.drawNoEffectsPriv(halfX, halfY, mMesh, mData.mFBO);
|
| 222 |
a0f644b7
|
Leszek Koltunski
|
}
|
| 223 |
|
|
|
| 224 |
d03782c0
|
leszek
|
for(int i=0; i<mNumChildren[0]; i++)
|
| 225 |
|
|
{
|
| 226 |
|
|
ret += mChildren.get(i).drawRecursive(renderNum, currTime, mData.mFBO);
|
| 227 |
|
|
}
|
| 228 |
a0f644b7
|
Leszek Koltunski
|
}
|
| 229 |
|
|
|
| 230 |
d03782c0
|
leszek
|
DistortedInputSurface input = mNumChildren[0]==0 ? mSurface : mData.mFBO;
|
| 231 |
7691a39f
|
leszek
|
|
| 232 |
d03782c0
|
leszek
|
if( input.setAsInput() )
|
| 233 |
|
|
{
|
| 234 |
|
|
ret++;
|
| 235 |
|
|
mEffects.drawPriv(halfX, halfY, mMesh, surface, currTime);
|
| 236 |
|
|
}
|
| 237 |
|
|
|
| 238 |
|
|
return ret;
|
| 239 |
a0f644b7
|
Leszek Koltunski
|
}
|
| 240 |
|
|
|
| 241 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 242 |
|
|
// PUBLIC API
|
| 243 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 244 |
|
|
/**
|
| 245 |
a09ada4c
|
Leszek Koltunski
|
* Constructs new Node.
|
| 246 |
6a06a912
|
Leszek Koltunski
|
*
|
| 247 |
c5369f1b
|
leszek
|
* @param surface InputSurface to put into the new Node.
|
| 248 |
07d8ef09
|
Leszek Koltunski
|
* @param effects DistortedEffects to put into the new Node.
|
| 249 |
05403bba
|
Leszek Koltunski
|
* @param mesh MeshObject to put into the new Node.
|
| 250 |
6a06a912
|
Leszek Koltunski
|
*/
|
| 251 |
a09ada4c
|
Leszek Koltunski
|
public DistortedNode(DistortedInputSurface surface, DistortedEffects effects, MeshObject mesh)
|
| 252 |
6a06a912
|
Leszek Koltunski
|
{
|
| 253 |
c5369f1b
|
leszek
|
mSurface = surface;
|
| 254 |
8ca9f899
|
Leszek Koltunski
|
mEffects = effects;
|
| 255 |
|
|
mMesh = mesh;
|
| 256 |
|
|
mChildren = null;
|
| 257 |
|
|
mNumChildren = new int[1];
|
| 258 |
|
|
mNumChildren[0]= 0;
|
| 259 |
6a06a912
|
Leszek Koltunski
|
|
| 260 |
9361b337
|
Leszek Koltunski
|
ArrayList<Long> list = new ArrayList<>();
|
| 261 |
c5369f1b
|
leszek
|
list.add(mSurface.getID());
|
| 262 |
7691a39f
|
leszek
|
list.add(-mEffects.getID());
|
| 263 |
1942537e
|
Leszek Koltunski
|
|
| 264 |
6a06a912
|
Leszek Koltunski
|
mData = mMapNodeID.get(list);
|
| 265 |
|
|
|
| 266 |
|
|
if( mData!=null )
|
| 267 |
|
|
{
|
| 268 |
|
|
mData.numPointingNodes++;
|
| 269 |
|
|
}
|
| 270 |
|
|
else
|
| 271 |
|
|
{
|
| 272 |
af27df87
|
leszek
|
mData = new NodeData(++mNextNodeID,list);
|
| 273 |
1942537e
|
Leszek Koltunski
|
mMapNodeID.put(list, mData);
|
| 274 |
6a06a912
|
Leszek Koltunski
|
}
|
| 275 |
|
|
}
|
| 276 |
|
|
|
| 277 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 278 |
|
|
/**
|
| 279 |
a09ada4c
|
Leszek Koltunski
|
* Copy-constructs new Node from another Node.
|
| 280 |
6a06a912
|
Leszek Koltunski
|
*
|
| 281 |
a09ada4c
|
Leszek Koltunski
|
* @param node The DistortedNode to copy data from.
|
| 282 |
6a06a912
|
Leszek Koltunski
|
* @param flags bit field composed of a subset of the following:
|
| 283 |
29a06526
|
Leszek Koltunski
|
* {@link Distorted#CLONE_SURFACE}, {@link Distorted#CLONE_MATRIX}, {@link Distorted#CLONE_VERTEX},
|
| 284 |
6a06a912
|
Leszek Koltunski
|
* {@link Distorted#CLONE_FRAGMENT} and {@link Distorted#CLONE_CHILDREN}.
|
| 285 |
29a06526
|
Leszek Koltunski
|
* For example flags = CLONE_SURFACE | CLONE_CHILDREN.
|
| 286 |
6a06a912
|
Leszek Koltunski
|
*/
|
| 287 |
a09ada4c
|
Leszek Koltunski
|
public DistortedNode(DistortedNode node, int flags)
|
| 288 |
6a06a912
|
Leszek Koltunski
|
{
|
| 289 |
432442f9
|
Leszek Koltunski
|
mEffects= new DistortedEffects(node.mEffects,flags);
|
| 290 |
05403bba
|
Leszek Koltunski
|
mMesh = node.mMesh;
|
| 291 |
9361b337
|
Leszek Koltunski
|
|
| 292 |
29a06526
|
Leszek Koltunski
|
if( (flags & Distorted.CLONE_SURFACE) != 0 )
|
| 293 |
e7a20702
|
Leszek Koltunski
|
{
|
| 294 |
c5369f1b
|
leszek
|
mSurface = node.mSurface;
|
| 295 |
e7a20702
|
Leszek Koltunski
|
}
|
| 296 |
|
|
else
|
| 297 |
|
|
{
|
| 298 |
c5369f1b
|
leszek
|
int w = node.mSurface.getWidth();
|
| 299 |
|
|
int h = node.mSurface.getHeight();
|
| 300 |
8ca9f899
|
Leszek Koltunski
|
|
| 301 |
c5369f1b
|
leszek
|
if( node.mSurface instanceof DistortedTexture )
|
| 302 |
8ca9f899
|
Leszek Koltunski
|
{
|
| 303 |
09ab7524
|
Leszek Koltunski
|
mSurface = new DistortedTexture(w,h, DistortedSurface.TYPE_TREE);
|
| 304 |
8ca9f899
|
Leszek Koltunski
|
}
|
| 305 |
c5369f1b
|
leszek
|
else if( node.mSurface instanceof DistortedFramebuffer )
|
| 306 |
8ca9f899
|
Leszek Koltunski
|
{
|
| 307 |
c5369f1b
|
leszek
|
boolean hasDepth = ((DistortedFramebuffer) node.mSurface).hasDepth();
|
| 308 |
09ab7524
|
Leszek Koltunski
|
mSurface = new DistortedFramebuffer(hasDepth,DistortedSurface.TYPE_TREE,w,h);
|
| 309 |
8ca9f899
|
Leszek Koltunski
|
}
|
| 310 |
e7a20702
|
Leszek Koltunski
|
}
|
| 311 |
9361b337
|
Leszek Koltunski
|
if( (flags & Distorted.CLONE_CHILDREN) != 0 )
|
| 312 |
6a06a912
|
Leszek Koltunski
|
{
|
| 313 |
c204c69d
|
leszek
|
if( node.mChildren==null ) // do NOT copy over the NULL!
|
| 314 |
|
|
{
|
| 315 |
|
|
node.mChildren = new ArrayList<>(2);
|
| 316 |
|
|
}
|
| 317 |
|
|
|
| 318 |
6a06a912
|
Leszek Koltunski
|
mChildren = node.mChildren;
|
| 319 |
|
|
mNumChildren = node.mNumChildren;
|
| 320 |
|
|
}
|
| 321 |
|
|
else
|
| 322 |
|
|
{
|
| 323 |
|
|
mChildren = null;
|
| 324 |
|
|
mNumChildren = new int[1];
|
| 325 |
|
|
mNumChildren[0] = 0;
|
| 326 |
|
|
}
|
| 327 |
|
|
|
| 328 |
|
|
ArrayList<Long> list = generateIDList();
|
| 329 |
|
|
|
| 330 |
|
|
mData = mMapNodeID.get(list);
|
| 331 |
|
|
|
| 332 |
|
|
if( mData!=null )
|
| 333 |
|
|
{
|
| 334 |
|
|
mData.numPointingNodes++;
|
| 335 |
|
|
}
|
| 336 |
|
|
else
|
| 337 |
|
|
{
|
| 338 |
af27df87
|
leszek
|
mData = new NodeData(++mNextNodeID,list);
|
| 339 |
6a06a912
|
Leszek Koltunski
|
mMapNodeID.put(list, mData);
|
| 340 |
|
|
}
|
| 341 |
|
|
}
|
| 342 |
c204c69d
|
leszek
|
|
| 343 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 344 |
|
|
/**
|
| 345 |
|
|
* Adds a new child to the last position in the list of our Node's children.
|
| 346 |
c204c69d
|
leszek
|
* <p>
|
| 347 |
|
|
* We cannot do this mid-render - actual attachment will be done just before the next render, by the
|
| 348 |
|
|
* DistortedAttachDeamon (by calling attachNow())
|
| 349 |
|
|
*
|
| 350 |
6a06a912
|
Leszek Koltunski
|
* @param node The new Node to add.
|
| 351 |
|
|
*/
|
| 352 |
c204c69d
|
leszek
|
public void attach(DistortedNode node)
|
| 353 |
6a06a912
|
Leszek Koltunski
|
{
|
| 354 |
c204c69d
|
leszek
|
DistortedAttachDaemon.attach(this,node);
|
| 355 |
6a06a912
|
Leszek Koltunski
|
}
|
| 356 |
c204c69d
|
leszek
|
|
| 357 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 358 |
|
|
/**
|
| 359 |
|
|
* Adds a new child to the last position in the list of our Node's children.
|
| 360 |
c204c69d
|
leszek
|
* <p>
|
| 361 |
|
|
* We cannot do this mid-render - actual attachment will be done just before the next render, by the
|
| 362 |
|
|
* DistortedAttachDeamon (by calling attachNow())
|
| 363 |
|
|
*
|
| 364 |
c5369f1b
|
leszek
|
* @param surface InputSurface to initialize our child Node with.
|
| 365 |
07d8ef09
|
Leszek Koltunski
|
* @param effects DistortedEffects to initialize our child Node with.
|
| 366 |
05403bba
|
Leszek Koltunski
|
* @param mesh MeshObject to initialize our child Node with.
|
| 367 |
6a06a912
|
Leszek Koltunski
|
* @return the newly constructed child Node, or null if we couldn't allocate resources.
|
| 368 |
|
|
*/
|
| 369 |
c204c69d
|
leszek
|
public DistortedNode attach(DistortedInputSurface surface, DistortedEffects effects, MeshObject mesh)
|
| 370 |
6a06a912
|
Leszek Koltunski
|
{
|
| 371 |
c204c69d
|
leszek
|
DistortedNode node = new DistortedNode(surface,effects,mesh);
|
| 372 |
|
|
DistortedAttachDaemon.attach(this,node);
|
| 373 |
|
|
return node;
|
| 374 |
|
|
}
|
| 375 |
f8377ef8
|
leszek
|
|
| 376 |
c204c69d
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 377 |
|
|
/**
|
| 378 |
|
|
* This is not really part of the public API. Has to be public only because it is a part of the
|
| 379 |
|
|
* DistortedAttacheable interface, which should really be a class that we extend here instead but
|
| 380 |
|
|
* Java has no multiple inheritance.
|
| 381 |
|
|
*
|
| 382 |
|
|
* @param node The new Node to add.
|
| 383 |
|
|
*/
|
| 384 |
|
|
public void attachNow(DistortedNode node)
|
| 385 |
|
|
{
|
| 386 |
9361b337
|
Leszek Koltunski
|
if( mChildren==null ) mChildren = new ArrayList<>(2);
|
| 387 |
c204c69d
|
leszek
|
|
| 388 |
6a06a912
|
Leszek Koltunski
|
mChildren.add(node);
|
| 389 |
|
|
mNumChildren[0]++;
|
| 390 |
|
|
}
|
| 391 |
c204c69d
|
leszek
|
|
| 392 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 393 |
|
|
/**
|
| 394 |
|
|
* Removes the first occurrence of a specified child from the list of children of our Node.
|
| 395 |
c204c69d
|
leszek
|
* <p>
|
| 396 |
|
|
* We cannot do this mid-render - actual detachment will be done just before the next render, by the
|
| 397 |
|
|
* DistortedAttachDeamon (by calling detachNow())
|
| 398 |
|
|
*
|
| 399 |
6a06a912
|
Leszek Koltunski
|
* @param node The Node to remove.
|
| 400 |
|
|
*/
|
| 401 |
c204c69d
|
leszek
|
public void detach(DistortedNode node)
|
| 402 |
6a06a912
|
Leszek Koltunski
|
{
|
| 403 |
c204c69d
|
leszek
|
DistortedAttachDaemon.detach(this,node);
|
| 404 |
6a06a912
|
Leszek Koltunski
|
}
|
| 405 |
a09ada4c
|
Leszek Koltunski
|
|
| 406 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 407 |
|
|
/**
|
| 408 |
|
|
* Removes the first occurrence of a specified child from the list of children of our Node.
|
| 409 |
a09ada4c
|
Leszek Koltunski
|
* <p>
|
| 410 |
|
|
* A bit questionable method as there can be many different Nodes attached as children, some
|
| 411 |
|
|
* of them having the same Effects but - for instance - different Mesh. Use with care.
|
| 412 |
c204c69d
|
leszek
|
* <p>
|
| 413 |
|
|
* We cannot do this mid-render - actual detachment will be done just before the next render, by the
|
| 414 |
|
|
* DistortedAttachDeamon (by calling detachNow())
|
| 415 |
a09ada4c
|
Leszek Koltunski
|
*
|
| 416 |
07d8ef09
|
Leszek Koltunski
|
* @param effects DistortedEffects to remove.
|
| 417 |
6a06a912
|
Leszek Koltunski
|
*/
|
| 418 |
c204c69d
|
leszek
|
public void detach(DistortedEffects effects)
|
| 419 |
6a06a912
|
Leszek Koltunski
|
{
|
| 420 |
07d8ef09
|
Leszek Koltunski
|
long id = effects.getID();
|
| 421 |
a09ada4c
|
Leszek Koltunski
|
DistortedNode node;
|
| 422 |
|
|
|
| 423 |
6a06a912
|
Leszek Koltunski
|
for(int i=0; i<mNumChildren[0]; i++)
|
| 424 |
|
|
{
|
| 425 |
|
|
node = mChildren.get(i);
|
| 426 |
a09ada4c
|
Leszek Koltunski
|
|
| 427 |
07d8ef09
|
Leszek Koltunski
|
if( node.mEffects.getID()==id )
|
| 428 |
6a06a912
|
Leszek Koltunski
|
{
|
| 429 |
c204c69d
|
leszek
|
DistortedAttachDaemon.detach(this,node);
|
| 430 |
|
|
break;
|
| 431 |
6a06a912
|
Leszek Koltunski
|
}
|
| 432 |
|
|
}
|
| 433 |
|
|
}
|
| 434 |
a09ada4c
|
Leszek Koltunski
|
|
| 435 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 436 |
|
|
/**
|
| 437 |
c204c69d
|
leszek
|
* This is not really part of the public API. Has to be public only because it is a part of the
|
| 438 |
|
|
* DistortedAttacheable interface, which should really be a class that we extend here instead but
|
| 439 |
|
|
* Java has no multiple inheritance.
|
| 440 |
|
|
*
|
| 441 |
|
|
* @param node The Node to remove.
|
| 442 |
6a06a912
|
Leszek Koltunski
|
*/
|
| 443 |
c204c69d
|
leszek
|
public void detachNow(DistortedNode node)
|
| 444 |
6a06a912
|
Leszek Koltunski
|
{
|
| 445 |
c204c69d
|
leszek
|
if( mNumChildren[0]>0 && mChildren.remove(node) )
|
| 446 |
6a06a912
|
Leszek Koltunski
|
{
|
| 447 |
c204c69d
|
leszek
|
mNumChildren[0]--;
|
| 448 |
af27df87
|
leszek
|
|
| 449 |
|
|
if( mNumChildren[0]==0 && mData.mFBO!=null )
|
| 450 |
|
|
{
|
| 451 |
|
|
mData.mFBO.markForDeletion();
|
| 452 |
|
|
mData.mFBO = null;
|
| 453 |
|
|
}
|
| 454 |
6a06a912
|
Leszek Koltunski
|
}
|
| 455 |
c204c69d
|
leszek
|
}
|
| 456 |
|
|
|
| 457 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 458 |
|
|
/**
|
| 459 |
|
|
* Removes all children Nodes.
|
| 460 |
|
|
* <p>
|
| 461 |
|
|
* We cannot do this mid-render - actual detachment will be done just before the next render, by the
|
| 462 |
|
|
* DistortedAttachDeamon (by calling detachAllNow())
|
| 463 |
|
|
*/
|
| 464 |
|
|
public void detachAll()
|
| 465 |
|
|
{
|
| 466 |
|
|
DistortedAttachDaemon.detachAll(this);
|
| 467 |
|
|
}
|
| 468 |
|
|
|
| 469 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 470 |
|
|
/**
|
| 471 |
|
|
* This is not really part of the public API. Has to be public only because it is a part of the
|
| 472 |
|
|
* DistortedAttacheable interface, which should really be a class that we extend here instead but
|
| 473 |
|
|
* Java has no multiple inheritance.
|
| 474 |
|
|
*/
|
| 475 |
|
|
public void detachAllNow()
|
| 476 |
|
|
{
|
| 477 |
6a06a912
|
Leszek Koltunski
|
if( mNumChildren[0]>0 )
|
| 478 |
|
|
{
|
| 479 |
|
|
mNumChildren[0] = 0;
|
| 480 |
|
|
mChildren.clear();
|
| 481 |
af27df87
|
leszek
|
|
| 482 |
|
|
if( mData.mFBO!=null )
|
| 483 |
|
|
{
|
| 484 |
|
|
mData.mFBO.markForDeletion();
|
| 485 |
|
|
mData.mFBO = null;
|
| 486 |
|
|
}
|
| 487 |
6a06a912
|
Leszek Koltunski
|
}
|
| 488 |
|
|
}
|
| 489 |
d1e740c5
|
Leszek Koltunski
|
|
| 490 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 491 |
|
|
/**
|
| 492 |
421c2728
|
Leszek Koltunski
|
* Returns the DistortedEffects object that's in the Node.
|
| 493 |
6a06a912
|
Leszek Koltunski
|
*
|
| 494 |
421c2728
|
Leszek Koltunski
|
* @return The DistortedEffects contained in the Node.
|
| 495 |
6a06a912
|
Leszek Koltunski
|
*/
|
| 496 |
421c2728
|
Leszek Koltunski
|
public DistortedEffects getEffects()
|
| 497 |
6a06a912
|
Leszek Koltunski
|
{
|
| 498 |
07d8ef09
|
Leszek Koltunski
|
return mEffects;
|
| 499 |
4e2382f3
|
Leszek Koltunski
|
}
|
| 500 |
|
|
|
| 501 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 502 |
|
|
/**
|
| 503 |
c5369f1b
|
leszek
|
* Returns the DistortedInputSurface object that's in the Node.
|
| 504 |
4e2382f3
|
Leszek Koltunski
|
*
|
| 505 |
c5369f1b
|
leszek
|
* @return The DistortedInputSurface contained in the Node.
|
| 506 |
4e2382f3
|
Leszek Koltunski
|
*/
|
| 507 |
c5369f1b
|
leszek
|
public DistortedInputSurface getSurface()
|
| 508 |
4e2382f3
|
Leszek Koltunski
|
{
|
| 509 |
c5369f1b
|
leszek
|
return mSurface;
|
| 510 |
6a06a912
|
Leszek Koltunski
|
}
|
| 511 |
|
|
|
| 512 |
8c327653
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 513 |
|
|
/**
|
| 514 |
|
|
* Returns the DistortedFramebuffer object that's in the Node.
|
| 515 |
|
|
*
|
| 516 |
|
|
* @return The DistortedFramebuffer contained in the Node.
|
| 517 |
|
|
*/
|
| 518 |
|
|
public DistortedFramebuffer getFramebuffer()
|
| 519 |
|
|
{
|
| 520 |
|
|
return mData.mFBO;
|
| 521 |
|
|
}
|
| 522 |
6a06a912
|
Leszek Koltunski
|
|
| 523 |
8c327653
|
Leszek Koltunski
|
}
|