Project

General

Profile

« Previous | Next » 

Revision c204c69d

Added by Leszek Koltunski about 7 years ago

New, cleaner way to create/destroy DistortedSurfaces.

Serious regression in StarWars (crashes!). Looks like the Node's internal FBO is being deleted and not re-created in time.

View differences:

src/main/java/org/distorted/library/DistortedOutputSurface.java
24 24

  
25 25
///////////////////////////////////////////////////////////////////////////////////////////////////
26 26

  
27
abstract class DistortedOutputSurface extends DistortedSurface
27
abstract class DistortedOutputSurface extends DistortedSurface implements DistortedAttacheable
28 28
{
29 29
  private ArrayList<DistortedNode> mChildren;
30 30
  private int mNumChildren;   // ==mChildren.length(), but we only create mChildren if the first one gets added
......
99 99
 */
100 100
  public void render(long time)
101 101
    {
102
    // change tree topology (attach and detach children)
103
    // create and delete all underlying OpenGL resources
104
    // Watch out: FIRST change topology, only then deal
105
    // with OpenGL resources. That's because changing Tree
106
    // can result in additional Framebuffers that would need
107
    // to be created immediately, before the calls to drawRecursive()
108

  
109
    if( DistortedAttachDaemon.toDo() )
110
      {
111
      for(int i=0; i<mNumChildren; i++)
112
        {
113
        mChildren.get(i).treeIsomorphism();
114
        }
115
      }
116

  
102 117
    toDo();
103 118

  
104 119
    for(int i=0; i<mNumChildren; i++)
......
159 174
///////////////////////////////////////////////////////////////////////////////////////////////////
160 175
/**
161 176
 * Adds a new child to the last position in the list of our Surface's children.
177
 * <p>
178
 * We cannot do this mid-render - actual attachment will be done just before the next render, by the
179
 * DistortedAttachDeamon (by calling attachNow())
162 180
 *
163 181
 * @param node The new Node to add.
164 182
 */
165
  public synchronized void attach(DistortedNode node)
183
  public void attach(DistortedNode node)
166 184
    {
167
    if( mChildren==null ) mChildren = new ArrayList<>(2);
168
    mChildren.add(node);
169
    mNumChildren++;
185
    DistortedAttachDaemon.attach(this,node);
170 186
    }
171 187

  
172 188
///////////////////////////////////////////////////////////////////////////////////////////////////
173 189
/**
174 190
 * Adds a new child to the last position in the list of our Surface's children.
191
 * <p>
192
 * We cannot do this mid-render - actual attachment will be done just before the next render, by the
193
 * DistortedAttachDeamon (by calling attachNow())
175 194
 *
176 195
 * @param surface InputSurface to initialize our child Node with.
177 196
 * @param effects DistortedEffects to initialize our child Node with.
178 197
 * @param mesh MeshObject to initialize our child Node with.
179 198
 * @return the newly constructed child Node, or null if we couldn't allocate resources.
180 199
 */
181
  public synchronized DistortedNode attach(DistortedInputSurface surface, DistortedEffects effects, MeshObject mesh)
200
  public DistortedNode attach(DistortedInputSurface surface, DistortedEffects effects, MeshObject mesh)
182 201
    {
183
    if( mChildren==null ) mChildren = new ArrayList<>(2);
184 202
    DistortedNode node = new DistortedNode(surface,effects,mesh);
203
    DistortedAttachDaemon.attach(this,node);
204
    return node;
205
    }
206

  
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208
/**
209
 * This is not really part of the public API. Has to be public only because it is a part of the
210
 * DistortedAttacheable interface, which should really be a class that we extend here instead but
211
 * Java has no multiple inheritance.
212
 *
213
 * @param node new Node to add.
214
 */
215
  public void attachNow(DistortedNode node)
216
    {
217
    if( mChildren==null ) mChildren = new ArrayList<>(2);
185 218
    mChildren.add(node);
186 219
    mNumChildren++;
187

  
188
    return node;
189 220
    }
190 221

  
191 222
///////////////////////////////////////////////////////////////////////////////////////////////////
192 223
/**
193 224
 * Removes the first occurrence of a specified child from the list of children of our Surface.
225
 * <p>
226
 * We cannot do this mid-render - actual attachment will be done just before the next render, by the
227
 * DistortedAttachDeamon (by calling detachNow())
228
 *
229
 * @param node The Node to remove.
230
 */
231
  public void detach(DistortedNode node)
232
    {
233
    DistortedAttachDaemon.detach(this,node);
234
    }
235

  
236
///////////////////////////////////////////////////////////////////////////////////////////////////
237
/**
238
 * This is not really part of the public API. Has to be public only because it is a part of the
239
 * DistortedAttacheable interface, which should really be a class that we extend here instead but
240
 * Java has no multiple inheritance.
194 241
 *
195 242
 * @param node The Node to remove.
196
 * @return <code>true</code> if the child was successfully removed.
197 243
 */
198
  public synchronized boolean detach(DistortedNode node)
244
  public void detachNow(DistortedNode node)
199 245
    {
200 246
    if( mNumChildren>0 && mChildren.remove(node) )
201 247
      {
202 248
      mNumChildren--;
203
      return true;
204 249
      }
205

  
206
    return false;
207 250
    }
208 251

  
209 252
///////////////////////////////////////////////////////////////////////////////////////////////////
210 253
/**
211 254
 * Removes all children Nodes.
255
 * <p>
256
 * We cannot do this mid-render - actual attachment will be done just before the next render, by the
257
 * DistortedAttachDeamon (by calling detachAllNow())
258
 */
259
  public void detachAll()
260
    {
261
    DistortedAttachDaemon.detachAll(this);
262
    }
263

  
264
///////////////////////////////////////////////////////////////////////////////////////////////////
265
/**
266
 * This is not really part of the public API. Has to be public only because it is a part of the
267
 * DistortedAttacheable interface, which should really be a class that we extend here instead but
268
 * Java has no multiple inheritance.
212 269
 */
213
  public synchronized void detachAll()
270
  public void detachAllNow()
214 271
    {
215 272
    if( mNumChildren>0 )
216 273
      {

Also available in: Unified diff