Revision 9361b337
Added by Leszek Koltunski almost 8 years ago
src/main/java/org/distorted/library/DistortedNode.java | ||
---|---|---|
18 | 18 |
private static final int TEXTURE_FAILED_TO_CREATE = -1; |
19 | 19 |
private static final int TEXTURE_NOT_CREATED_YET = -2; |
20 | 20 |
|
21 |
private DistortedBitmap mBitmap;
|
|
21 |
private DistortedObject mObject;
|
|
22 | 22 |
private NodeData mData; |
23 | 23 |
|
24 | 24 |
private DistortedNode mParent; |
25 | 25 |
private ArrayList<DistortedNode> mChildren; |
26 | 26 |
private int[] mNumChildren; // ==mChildren.length(), but we only create mChildren if the first one gets added |
27 | 27 |
|
28 |
private static HashMap<ArrayList<Long>,NodeData> mMapNodeID = new HashMap<ArrayList<Long>,NodeData>();
|
|
28 |
private static HashMap<ArrayList<Long>,NodeData> mMapNodeID = new HashMap<>(); |
|
29 | 29 |
private static long mNextNodeID =0; |
30 | 30 |
|
31 | 31 |
////////////////////////////////////////////////////////////////// |
... | ... | |
124 | 124 |
{ |
125 | 125 |
if( mNumChildren[0]<=0 ) |
126 | 126 |
{ |
127 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mBitmap.mTextureDataH[0]);
|
|
127 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mObject.mTextureDataH[0]);
|
|
128 | 128 |
|
129 | 129 |
if( mData.mProjection!=null ) |
130 | 130 |
{ |
... | ... | |
144 | 144 |
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
145 | 145 |
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); |
146 | 146 |
|
147 |
if( mBitmap.mBitmapSet[0] )
|
|
147 |
if( mObject.mBitmapSet[0] )
|
|
148 | 148 |
{ |
149 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mBitmap.mTextureDataH[0]);
|
|
150 |
mBitmap.drawNoEffectsPriv(mData.mProjection);
|
|
149 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mObject.mTextureDataH[0]);
|
|
150 |
mObject.drawNoEffectsPriv(mData.mProjection);
|
|
151 | 151 |
} |
152 | 152 |
|
153 | 153 |
synchronized(this) |
... | ... | |
163 | 163 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mData.mTextureID); // this is safe because we must have called createFBO() above before. |
164 | 164 |
} |
165 | 165 |
|
166 |
mBitmap.drawPriv(currTime, dp);
|
|
166 |
mObject.drawPriv(currTime, dp);
|
|
167 | 167 |
} |
168 | 168 |
|
169 | 169 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
189 | 189 |
|
190 | 190 |
private ArrayList<Long> generateIDList() |
191 | 191 |
{ |
192 |
ArrayList<Long> ret = new ArrayList<Long>();
|
|
192 |
ArrayList<Long> ret = new ArrayList<>(); |
|
193 | 193 |
|
194 |
ret.add( mNumChildren[0]>0 ? mBitmap.getBitmapID() : mBitmap.getID() );
|
|
194 |
ret.add( mNumChildren[0]>0 ? mObject.getBitmapID() : mObject.getID() );
|
|
195 | 195 |
DistortedNode node; |
196 | 196 |
|
197 | 197 |
for(int i=0; i<mNumChildren[0]; i++) |
... | ... | |
220 | 220 |
if( newList.size()>1 && mData.mProjection==null ) |
221 | 221 |
{ |
222 | 222 |
mData.mProjection = new DistortedProjection(true); |
223 |
mData.mProjection.onSurfaceChanged(mBitmap.getWidth(), mBitmap.getHeight());
|
|
223 |
mData.mProjection.onSurfaceChanged(mObject.getWidth(), mObject.getHeight());
|
|
224 | 224 |
mData.mFramebufferID = 0; |
225 | 225 |
mData.mTextureID = TEXTURE_NOT_CREATED_YET; |
226 | 226 |
} |
... | ... | |
260 | 260 |
/** |
261 | 261 |
* Constructs new Node of the Tree. |
262 | 262 |
* |
263 |
* @param bmp DistortedBitmap to put into the new Node.
|
|
263 |
* @param obj DistortedObject to put into the new Node.
|
|
264 | 264 |
*/ |
265 |
public DistortedNode(DistortedBitmap bmp)
|
|
265 |
public DistortedNode(DistortedObject obj)
|
|
266 | 266 |
{ |
267 |
mBitmap = bmp;
|
|
267 |
mObject = obj;
|
|
268 | 268 |
mParent = null; |
269 | 269 |
mChildren = null; |
270 | 270 |
mNumChildren = new int[1]; |
271 | 271 |
mNumChildren[0] = 0; |
272 | 272 |
|
273 |
ArrayList<Long> list = new ArrayList<Long>();
|
|
274 |
list.add(bmp.getID());
|
|
273 |
ArrayList<Long> list = new ArrayList<>(); |
|
274 |
list.add(obj.getID());
|
|
275 | 275 |
|
276 | 276 |
mData = mMapNodeID.get(list); |
277 | 277 |
|
... | ... | |
298 | 298 |
*/ |
299 | 299 |
public DistortedNode(DistortedNode node, int flags) |
300 | 300 |
{ |
301 |
mParent = null; |
|
302 |
mBitmap = new DistortedBitmap(node.mBitmap, flags); |
|
303 |
|
|
304 |
if( (flags & Distorted.CLONE_CHILDREN) != 0 ) |
|
301 |
mParent = null; |
|
302 |
|
|
303 |
if( node.mObject instanceof DistortedBitmap) |
|
304 |
mObject = new DistortedBitmap( (DistortedBitmap)node.mObject, flags); |
|
305 |
else if( node.mObject instanceof DistortedCubes) |
|
306 |
mObject = new DistortedCubes( (DistortedCubes)node.mObject, flags); |
|
307 |
|
|
308 |
if( (flags & Distorted.CLONE_CHILDREN) != 0 ) |
|
305 | 309 |
{ |
306 | 310 |
mChildren = node.mChildren; |
307 | 311 |
mNumChildren = node.mNumChildren; |
... | ... | |
338 | 342 |
{ |
339 | 343 |
ArrayList<Long> prev = generateIDList(); |
340 | 344 |
|
341 |
if( mChildren==null ) mChildren = new ArrayList<DistortedNode>(2);
|
|
345 |
if( mChildren==null ) mChildren = new ArrayList<>(2); |
|
342 | 346 |
|
343 | 347 |
node.mParent = this; |
344 | 348 |
mChildren.add(node); |
... | ... | |
358 | 362 |
{ |
359 | 363 |
ArrayList<Long> prev = generateIDList(); |
360 | 364 |
|
361 |
if( mChildren==null ) mChildren = new ArrayList<DistortedNode>(2);
|
|
365 |
if( mChildren==null ) mChildren = new ArrayList<>(2);
|
|
362 | 366 |
DistortedNode node = new DistortedNode(bmp); |
363 | 367 |
node.mParent = this; |
364 | 368 |
mChildren.add(node); |
... | ... | |
400 | 404 |
/** |
401 | 405 |
* Removes the first occurrence of a specified child from the list of children of our Node. |
402 | 406 |
* |
403 |
* @param bmp The DistortedBitmap to remove.
|
|
407 |
* @param obj DistortedObject to remove.
|
|
404 | 408 |
* @return <code>true</code> if the child was successfully removed. |
405 | 409 |
*/ |
406 |
public synchronized boolean detach(DistortedBitmap bmp)
|
|
410 |
public synchronized boolean detach(DistortedObject obj)
|
|
407 | 411 |
{ |
408 |
long id = bmp.getID();
|
|
412 |
long id = obj.getID();
|
|
409 | 413 |
DistortedNode node; |
410 | 414 |
|
411 | 415 |
for(int i=0; i<mNumChildren[0]; i++) |
412 | 416 |
{ |
413 | 417 |
node = mChildren.get(i); |
414 | 418 |
|
415 |
if( node.mBitmap.getID()==id )
|
|
419 |
if( node.mObject.getID()==id )
|
|
416 | 420 |
{ |
417 | 421 |
ArrayList<Long> prev = generateIDList(); |
418 | 422 |
|
... | ... | |
468 | 472 |
|
469 | 473 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
470 | 474 |
/** |
471 |
* Returns the DistortedBitmap object that's in the Node.
|
|
475 |
* Returns the DistortedObject object that's in the Node.
|
|
472 | 476 |
* |
473 |
* @return The DistortedBitmap contained in the Node.
|
|
477 |
* @return The DistortedObject contained in the Node.
|
|
474 | 478 |
*/ |
475 |
public DistortedBitmap getBitmap()
|
|
479 |
public DistortedObject getObject()
|
|
476 | 480 |
{ |
477 |
return mBitmap;
|
|
481 |
return mObject;
|
|
478 | 482 |
} |
479 | 483 |
|
480 | 484 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Provide support to add any class derived from DistortedObject to DistortedNode.