Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedOutputSurface.java @ b7dba709

1 c5369f1b leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
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
package org.distorted.library;
21
22 a436ccc5 leszek
import android.opengl.GLES30;
23 af4cc5db Leszek Koltunski
import android.opengl.Matrix;
24 a09ada4c Leszek Koltunski
import java.util.ArrayList;
25 af4cc5db Leszek Koltunski
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27
28 efe3d8fe leszek
abstract class DistortedOutputSurface extends DistortedSurface implements DistortedSlave
29 af4cc5db Leszek Koltunski
{
30 efe3d8fe leszek
  private static final int ATTACH = 0;
31
  private static final int DETACH = 1;
32
  private static final int DETALL = 2;
33
  private static final int SORT   = 3;
34
35 a09ada4c Leszek Koltunski
  private ArrayList<DistortedNode> mChildren;
36
  private int mNumChildren;   // ==mChildren.length(), but we only create mChildren if the first one gets added
37
38 efe3d8fe leszek
  private class Job
39
    {
40
    int type;
41
    DistortedNode node;
42 be60d4ff leszek
    DistortedEffectsPostprocess dep;
43 efe3d8fe leszek
44 be60d4ff leszek
    Job(int t, DistortedNode n, DistortedEffectsPostprocess d)
45 efe3d8fe leszek
      {
46
      type = t;
47
      node = n;
48 be60d4ff leszek
      dep  = d;
49 efe3d8fe leszek
      }
50
    }
51
52
  private ArrayList<Job> mJobs = new ArrayList<>();
53
54 b7dba709 Leszek Koltunski
  DistortedFramebuffer mBuffer1, mBuffer2;
55 60c1c622 leszek
56 95c441a2 leszek
  private long mTime;
57 c2c08950 leszek
  private float mFOV;
58 af4cc5db Leszek Koltunski
  int mWidth,mHeight,mDepth;
59 c2c08950 leszek
  float mDistance, mNear;
60 af4cc5db Leszek Koltunski
  float[] mProjectionMatrix;
61
62 c7da4e65 leszek
  int mDepthCreated;
63 a436ccc5 leszek
  int[] mDepthH = new int[1];
64
  int[] mFBOH   = new int[1];
65
66 a9f41fa3 leszek
  private float mClearR, mClearG, mClearB, mClearA;
67
  private float mClearDepth;
68 0afc143a leszek
69
//private String sNew="", sOld="";
70
71 af4cc5db Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
72
73 09ab7524 Leszek Koltunski
  DistortedOutputSurface(int width, int height, int createColor, int createDepth, int fbo, int type)
74 af4cc5db Leszek Koltunski
    {
75 09ab7524 Leszek Koltunski
    super(width,height,createColor,type);
76 af4cc5db Leszek Koltunski
77
    mProjectionMatrix = new float[16];
78
79
    mWidth = width;
80
    mHeight= height;
81
82
    mFOV = 60.0f;
83 54fe333a leszek
    mNear=  0.5f;
84 af4cc5db Leszek Koltunski
85 c7da4e65 leszek
    mDepthCreated= createDepth;
86 a436ccc5 leszek
    mFBOH[0]     = fbo;
87 c7da4e65 leszek
    mDepthH[0]   = 0;
88 a436ccc5 leszek
89 95c441a2 leszek
    mTime = 0;
90
91 a9f41fa3 leszek
    mClearR = 0.0f;
92
    mClearG = 0.0f;
93
    mClearB = 0.0f;
94
    mClearA = 0.0f;
95
96
    mClearDepth = 1.0f;
97
98 af4cc5db Leszek Koltunski
    createProjection();
99
    }
100
101 c5369f1b leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
102
103 be60d4ff leszek
  private void createProjection()
104 af4cc5db Leszek Koltunski
    {
105
    if( mWidth>0 && mHeight>1 )
106
      {
107
      if( mFOV>0.0f )  // perspective projection
108
        {
109 54fe333a leszek
        float a = 2.0f*(float)Math.tan(mFOV*Math.PI/360);
110 c2c08950 leszek
        float q = mWidth*mNear;
111 54fe333a leszek
        float c = mHeight*mNear;
112
113 c2c08950 leszek
        float left   = -q/2;
114
        float right  = +q/2;
115
        float bottom = -c/2;
116
        float top    = +c/2;
117
        float near   =  c/a;
118 54fe333a leszek
119
        mDistance    = mHeight/a;
120 af4cc5db Leszek Koltunski
        float far    = 2*mDistance-near;
121
        mDepth       = (int)((far-near)/2);
122
123
        Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
124
        }
125
      else             // parallel projection
126
        {
127 54fe333a leszek
        float left   = -mWidth /2.0f;
128
        float right  = +mWidth /2.0f;
129
        float bottom = -mHeight/2.0f;
130
        float top    = +mHeight/2.0f;
131
        float near   = mWidth+mHeight-mHeight*(1.0f-mNear);
132
        mDistance    = mWidth+mHeight;
133
        float far    = mWidth+mHeight+mHeight*(1.0f-mNear);
134
        mDepth       = (int)((far-near)/2);
135 af4cc5db Leszek Koltunski
136
        Matrix.orthoM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
137
        }
138
      }
139
    }
140
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142 e02264ff leszek
// Render all children, one by one. If there are no postprocessing effects, just render to THIS.
143
// Otherwise, render to a buffer and on each change of Postprocessing Bucket, apply the postprocessing
144
// to a whole buffer and merge it.
145 39086ebb leszek
146 b2939df4 Leszek Koltunski
  int renderChildren(long time, int num, ArrayList<DistortedNode> children)
147
    {
148
    int numRenders = 0;
149 b9798977 leszek
    DistortedNode child;
150 27f42cd6 leszek
    DistortedEffectsPostprocess lastP=null, currP;
151 e137d4f5 Leszek Koltunski
    long lastB=0, currB;
152 0afc143a leszek
153
//sNew = "";
154
155 b2939df4 Leszek Koltunski
    for(int i=0; i<num; i++)
156 39086ebb leszek
      {
157 b9798977 leszek
      child = children.get(i);
158 27f42cd6 leszek
      currP = child.getEffectsPostprocess();
159 13687207 leszek
      currB = currP==null ? 0 : currP.getBucket();
160 0afc143a leszek
161
//sNew += currB;
162
163 13687207 leszek
      if( lastB!=currB && lastB!=0 )
164
        {
165
        numRenders += lastP.postprocess(time,this);
166
        }
167 b9798977 leszek
168 13687207 leszek
      if( currB==0 )
169
        {
170
        numRenders += child.draw(time,this);
171
        }
172 60c1c622 leszek
      else
173
        {
174 b7dba709 Leszek Koltunski
        if( mBuffer1==null )
175 60c1c622 leszek
          {
176 b7dba709 Leszek Koltunski
          mBuffer1 = new DistortedFramebuffer(mDepthCreated!=DONT_CREATE, DistortedSurface.TYPE_SYST, mWidth, mHeight);
177
          mBuffer2 = new DistortedFramebuffer(false                     , DistortedSurface.TYPE_SYST, mWidth, mHeight);
178 60c1c622 leszek
          }
179 b9798977 leszek
180 b7dba709 Leszek Koltunski
        numRenders += child.draw(time,mBuffer1);
181 13687207 leszek
        if( i==num-1 )
182
          {
183
          numRenders += currP.postprocess(time,this);
184
          }
185 60c1c622 leszek
        }
186 b9798977 leszek
187 60c1c622 leszek
      lastP = currP;
188
      lastB = currB;
189 95c441a2 leszek
      }
190 be60d4ff leszek
/*
191
if( !sNew.equals(sOld) )
192
  {
193
  sOld = sNew;
194
  android.util.Log.e("surface", "Surface"+getID()+": "+sOld);
195
  }
196
*/
197 39086ebb leszek
    return numRenders;
198
    }
199
200 be60d4ff leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
201
202
  void newJob(int t, DistortedNode n, DistortedEffectsPostprocess d)
203
    {
204
    mJobs.add(new Job(t,n,d));
205
    }
206
207 b2939df4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
208
// PUBLIC API
209 39086ebb leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
210 c5369f1b leszek
/**
211 d9706fd2 Leszek Koltunski
 * Draws all the attached children to this OutputSurface.
212 af4cc5db Leszek Koltunski
 * <p>
213
 * Must be called from a thread holding OpenGL Context.
214
 *
215 d9706fd2 Leszek Koltunski
 * @param time Current time, in milliseconds. This will be passed to all the Effects stored in the children Nodes.
216 7691a39f leszek
 * @return Number of objects rendered.
217 c5369f1b leszek
 */
218 b2939df4 Leszek Koltunski
  public int render(long time)
219 af4cc5db Leszek Koltunski
    {
220 c204c69d leszek
    // change tree topology (attach and detach children)
221 889cce10 Leszek Koltunski
/*
222
    boolean changed =
223
*/
224 efe3d8fe leszek
    DistortedMaster.toDo();
225 eadf0859 leszek
/*
226 f28fffc2 Leszek Koltunski
    // debugging only
227 af27df87 leszek
    if( changed )
228 c204c69d leszek
      {
229
      for(int i=0; i<mNumChildren; i++)
230
        {
231 af27df87 leszek
        mChildren.get(i).debug(0);
232 c204c69d leszek
        }
233 af27df87 leszek
234 7691a39f leszek
      DistortedNode.debugMap();
235 c204c69d leszek
      }
236 eadf0859 leszek
*/
237 09ab7524 Leszek Koltunski
    // create and delete all underlying OpenGL resources
238
    // Watch out: FIRST change topology, only then deal
239
    // with OpenGL resources. That's because changing Tree
240
    // can result in additional Framebuffers that would need
241
    // to be created immediately, before the calls to drawRecursive()
242 f8377ef8 leszek
    toDo();
243 eadf0859 leszek
/*
244 f28fffc2 Leszek Koltunski
    // debugging only
245 af27df87 leszek
    if( changed )
246
      {
247
      DistortedSurface.debugLists();
248
      }
249 eadf0859 leszek
*/
250 c834348d leszek
    // mark OpenGL state as unknown
251
    DistortedRenderState.reset();
252 2ed1c692 leszek
253 b2939df4 Leszek Koltunski
    int numRenders=0;
254 7691a39f leszek
255 d9706fd2 Leszek Koltunski
    for(int i=0; i<mNumChildren; i++)
256 af4cc5db Leszek Koltunski
      {
257 b2939df4 Leszek Koltunski
      numRenders += mChildren.get(i).renderRecursive(time);
258 af4cc5db Leszek Koltunski
      }
259 7691a39f leszek
260 95c441a2 leszek
    setAsOutput(time);
261 b2939df4 Leszek Koltunski
    numRenders += renderChildren(time,mNumChildren,mChildren);
262
263 7691a39f leszek
    return numRenders;
264 af4cc5db Leszek Koltunski
    }
265
266
///////////////////////////////////////////////////////////////////////////////////////////////////
267 c5369f1b leszek
/**
268
 * Bind this Surface as a Framebuffer we can render to.
269 02ab6f9d leszek
 *
270
 * @param time Present time, in milliseconds. The point: looking at this param the library can figure
271
 *             out if this is the first time during present frame that this FBO is being set as output.
272
 *             If so, the library, in addition to binding the Surface for output, also clears the
273
 *             Surface's color and depth attachments.
274 c5369f1b leszek
 */
275 95c441a2 leszek
  public void setAsOutput(long time)
276 a436ccc5 leszek
    {
277
    GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[0]);
278 95c441a2 leszek
279
    if( mTime!=time )
280
      {
281
      mTime = time;
282
      DistortedRenderState.colorDepthOn();
283 a9f41fa3 leszek
      GLES30.glClearColor(mClearR, mClearG, mClearB, mClearA);
284
      GLES30.glClearDepthf(mClearDepth);
285 95c441a2 leszek
      GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
286
      }
287 a436ccc5 leszek
    }
288 af4cc5db Leszek Koltunski
289 a9f41fa3 leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
290
/**
291
 * Set the (R,G,B,A) values of GLES30.glClearColor() to set up color with which to clear
292
 * this Surface before each render.
293
 *
294
 * @param r the Red component. Default: 0.0f
295
 * @param g the Green component. Default: 0.0f
296
 * @param b the Blue component. Default: 0.0f
297
 * @param a the Alpha component. Default: 0.0f
298
 */
299
  public void glClearColor(float r, float g, float b, float a)
300
    {
301
    mClearR = r;
302
    mClearG = g;
303
    mClearB = b;
304
    mClearA = a;
305
    }
306
307
///////////////////////////////////////////////////////////////////////////////////////////////////
308
/**
309
 * Set the Depth value of GLES30.glClearDepthf() to set up depth with which to clear
310
 * the Depth buffer of Surface before each render.
311
 *
312
 * @param d the Depth. Default: 1.0f
313
 */
314
  public void glClearDepthf(float d)
315
    {
316
    mClearDepth = d;
317
    }
318
319 af4cc5db Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
320
/**
321
 * Create new Projection matrix.
322
 *
323
 * @param fov Vertical 'field of view' of the Projection frustrum (in degrees).
324 54fe333a leszek
 *            Valid values: 0<=fov<180. FOV==0 means 'parallel projection'.
325
 * @param near Distance between the screen plane and the near plane.
326
 *             Valid vaules: 0<near<1. When near==0, the Near Plane is exactly at the tip of the
327
 *             pyramid. When near==1 (illegal!) the near plane is equivalent to the screen plane.
328 af4cc5db Leszek Koltunski
 */
329 54fe333a leszek
  public void setProjection(float fov, float near)
330 af4cc5db Leszek Koltunski
    {
331 8069e806 Leszek Koltunski
    if( fov < 180.0f && fov >=0.0f )
332
      {
333
      mFOV = fov;
334
      }
335
336
    if( near<   1.0f && near> 0.0f )
337
      {
338
      mNear= near;
339
      }
340
    else if( near<=0.0f )
341
      {
342
      mNear = 0.01f;
343
      }
344
    else if( near>=1.0f )
345
      {
346
      mNear=0.99f;
347
      }
348 af4cc5db Leszek Koltunski
349
    createProjection();
350
    }
351
352
///////////////////////////////////////////////////////////////////////////////////////////////////
353 c5369f1b leszek
/**
354 af4cc5db Leszek Koltunski
 * Resize the underlying Framebuffer.
355 c7da4e65 leszek
 * <p>
356
 * This method can be safely called mid-render as it doesn't interfere with rendering.
357 af4cc5db Leszek Koltunski
 *
358
 * @param width The new width.
359
 * @param height The new height.
360 c5369f1b leszek
 */
361 af4cc5db Leszek Koltunski
  public void resize(int width, int height)
362
    {
363
    if( mWidth!=width || mHeight!=height )
364
      {
365
      mWidth = width;
366
      mHeight= height;
367
      mSizeX = width;
368
      mSizeY = height;
369 f8377ef8 leszek
370
      createProjection();
371
372 c7da4e65 leszek
      if( mColorCreated==CREATED )
373 f8377ef8 leszek
        {
374 f28fffc2 Leszek Koltunski
        markForCreation();
375 f8377ef8 leszek
        recreate();
376
        }
377 af4cc5db Leszek Koltunski
      }
378
    }
379 a09ada4c Leszek Koltunski
380 a436ccc5 leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
381
/**
382
 * Create a new DEPTH buffer and attach it or (param=false) detach an existing DEPTH attachment and recreate it.
383
 *
384
 * @param enable <bold>true</bold> if we want to attach a new DEPTH buffer to the FBO.<br>
385
 *               <bold>false</bold> if we want to detach the DEPTH attachment.
386
 */
387
  public void enableDepth(boolean enable)
388
    {
389 c7da4e65 leszek
    if( enable && mDepthCreated==DONT_CREATE )
390
      {
391
      mDepthCreated = NOT_CREATED_YET;
392 f28fffc2 Leszek Koltunski
      markForCreation();
393 c7da4e65 leszek
      }
394
    if( !enable && mDepthCreated!=DONT_CREATE )
395 a436ccc5 leszek
      {
396 c7da4e65 leszek
      mDepthCreated = DONT_CREATE;
397 f28fffc2 Leszek Koltunski
      markForCreation();
398 a436ccc5 leszek
      }
399
    }
400
401
///////////////////////////////////////////////////////////////////////////////////////////////////
402
/**
403
 * Return true if the Surface contains a DEPTH attachment.
404
 *
405
 * @return <bold>true</bold> if the FBO contains a DEPTH attachment.
406
 */
407
  public boolean hasDepth()
408
    {
409 c7da4e65 leszek
    return mDepthCreated==CREATED;
410 a436ccc5 leszek
    }
411
412 a09ada4c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
413
/**
414
 * Adds a new child to the last position in the list of our Surface's children.
415 c204c69d leszek
 * <p>
416
 * We cannot do this mid-render - actual attachment will be done just before the next render, by the
417 efe3d8fe leszek
 * DistortedMaster (by calling doWork())
418 a09ada4c Leszek Koltunski
 *
419
 * @param node The new Node to add.
420
 */
421 c204c69d leszek
  public void attach(DistortedNode node)
422 a09ada4c Leszek Koltunski
    {
423 be60d4ff leszek
    mJobs.add(new Job(ATTACH,node,null));
424 efe3d8fe leszek
    DistortedMaster.newSlave(this);
425 a09ada4c Leszek Koltunski
    }
426
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428
/**
429
 * Adds a new child to the last position in the list of our Surface's children.
430 c204c69d leszek
 * <p>
431
 * We cannot do this mid-render - actual attachment will be done just before the next render, by the
432 efe3d8fe leszek
 * DistortedMaster (by calling doWork())
433 a09ada4c Leszek Koltunski
 *
434
 * @param surface InputSurface to initialize our child Node with.
435
 * @param effects DistortedEffects to initialize our child Node with.
436
 * @param mesh MeshObject to initialize our child Node with.
437
 * @return the newly constructed child Node, or null if we couldn't allocate resources.
438
 */
439 c204c69d leszek
  public DistortedNode attach(DistortedInputSurface surface, DistortedEffects effects, MeshObject mesh)
440 a09ada4c Leszek Koltunski
    {
441
    DistortedNode node = new DistortedNode(surface,effects,mesh);
442 be60d4ff leszek
    mJobs.add(new Job(ATTACH,node,null));
443 efe3d8fe leszek
    DistortedMaster.newSlave(this);
444 c204c69d leszek
    return node;
445
    }
446
447 af27df87 leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
448
/**
449
 * Removes the first occurrence of a specified child from the list of children of our Surface.
450
 * <p>
451
 * A bit questionable method as there can be many different Nodes attached as children, some
452
 * of them having the same Effects but - for instance - different Mesh. Use with care.
453
 * <p>
454
 * We cannot do this mid-render - actual detachment will be done just before the next render, by the
455 efe3d8fe leszek
 * DistortedMaster (by calling doWork())
456 af27df87 leszek
 *
457
 * @param effects DistortedEffects to remove.
458
 */
459
  public void detach(DistortedEffects effects)
460
    {
461
    long id = effects.getID();
462
    DistortedNode node;
463 8baa1fe6 Leszek Koltunski
    boolean detached = false;
464 af27df87 leszek
465
    for(int i=0; i<mNumChildren; i++)
466
      {
467
      node = mChildren.get(i);
468
469
      if( node.getEffects().getID()==id )
470
        {
471 8baa1fe6 Leszek Koltunski
        detached = true;
472 be60d4ff leszek
        mJobs.add(new Job(DETACH,node,null));
473 efe3d8fe leszek
        DistortedMaster.newSlave(this);
474 af27df87 leszek
        break;
475
        }
476
      }
477 8baa1fe6 Leszek Koltunski
478
    if( !detached )
479
      {
480
      // if we failed to detach any, it still might be the case that
481 efe3d8fe leszek
      // there's an ATTACH job that we need to cancel.
482
      int num = mJobs.size();
483
      Job job;
484
485
      for(int i=0; i<num; i++)
486
        {
487
        job = mJobs.get(i);
488
489
        if( job.type==ATTACH && job.node.getEffects()==effects )
490
          {
491
          mJobs.remove(i);
492
          break;
493
          }
494
        }
495 8baa1fe6 Leszek Koltunski
      }
496 af27df87 leszek
    }
497
498 a09ada4c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
499
/**
500
 * Removes the first occurrence of a specified child from the list of children of our Surface.
501 c204c69d leszek
 * <p>
502
 * We cannot do this mid-render - actual attachment will be done just before the next render, by the
503 efe3d8fe leszek
 * DistortedMaster (by calling doWork())
504 c204c69d leszek
 *
505
 * @param node The Node to remove.
506
 */
507
  public void detach(DistortedNode node)
508
    {
509 be60d4ff leszek
    mJobs.add(new Job(DETACH,node,null));
510 efe3d8fe leszek
    DistortedMaster.newSlave(this);
511 a09ada4c Leszek Koltunski
    }
512
513
///////////////////////////////////////////////////////////////////////////////////////////////////
514
/**
515
 * Removes all children Nodes.
516 c204c69d leszek
 * <p>
517
 * We cannot do this mid-render - actual attachment will be done just before the next render, by the
518 efe3d8fe leszek
 * DistortedMaster (by calling doWork())
519 c204c69d leszek
 */
520
  public void detachAll()
521
    {
522 be60d4ff leszek
    mJobs.add(new Job(DETALL,null,null));
523 efe3d8fe leszek
    DistortedMaster.newSlave(this);
524 c204c69d leszek
    }
525
526
///////////////////////////////////////////////////////////////////////////////////////////////////
527
/**
528
 * This is not really part of the public API. Has to be public only because it is a part of the
529 efe3d8fe leszek
 * DistortedSlave interface, which should really be a class that we extend here instead but
530 c204c69d leszek
 * Java has no multiple inheritance.
531 43fbf0dd leszek
 *
532
 * @y.exclude
533 a09ada4c Leszek Koltunski
 */
534 efe3d8fe leszek
  public void doWork()
535 a09ada4c Leszek Koltunski
    {
536 efe3d8fe leszek
    int num = mJobs.size();
537
    Job job;
538
539
    for(int i=0; i<num; i++)
540
      {
541
      job = mJobs.remove(0);
542
543
      switch(job.type)
544
        {
545 be60d4ff leszek
        case ATTACH: if( mChildren==null ) mChildren = new ArrayList<>(2);
546
                     job.node.setSurfaceParent(this);
547
                     DistortedMaster.addSorted(mChildren,job.node);
548 efe3d8fe leszek
                     mNumChildren++;
549
                     break;
550 be60d4ff leszek
        case DETACH: if( mNumChildren>0 && mChildren.remove(job.node) )
551 efe3d8fe leszek
                       {
552 be60d4ff leszek
                       job.node.setSurfaceParent(null);
553 efe3d8fe leszek
                       mNumChildren--;
554
                       }
555
                     break;
556 be60d4ff leszek
        case DETALL: if( mNumChildren>0 )
557 efe3d8fe leszek
                       {
558 be60d4ff leszek
                       DistortedNode tmp;
559
560
                       for(int j=mNumChildren-1; j>=0; j--)
561
                         {
562
                         tmp = mChildren.remove(j);
563
                         tmp.setSurfaceParent(null);
564
                         }
565
566 efe3d8fe leszek
                       mNumChildren = 0;
567
                       }
568
                     break;
569 be60d4ff leszek
        case SORT  : job.node.setPost(job.dep);
570
                     mChildren.remove(job.node);
571
                     DistortedMaster.addSorted(mChildren,job.node);
572 efe3d8fe leszek
                     break;
573
        }
574
      }
575 a09ada4c Leszek Koltunski
    }
576 af4cc5db Leszek Koltunski
}