Project

General

Profile

« Previous | Next » 

Revision 8e34674e

Added by Leszek Koltunski over 7 years ago

Move the *List classes into static members of DistortedFramebuffer and DistortedObject.

View differences:

src/main/java/org/distorted/library/DistortedFramebuffer.java
22 22
import android.opengl.GLES20;
23 23
import android.opengl.Matrix;
24 24

  
25
import java.util.Iterator;
26
import java.util.LinkedList;
27

  
25 28
///////////////////////////////////////////////////////////////////////////////////////////////////
26 29
/**
27 30
 * Class which represents a OpenGL Framebuffer object.
......
29 32
 * User is able to create either WRITE-only Framebuffers from objects already constructed outside
30 33
 * of the library (the first constructor; primary use case: the screen) or an offscreen READ-WRITE
31 34
 * FBOs (used by the DistortedNode, but also can be used by external users of the library)
35
 *
36
 * Also, keep all objects created in a static LinkedList. The point: we need to be able to mark
37
 * Framebuffers for deletion, and delete all marked objects later at a convenient time (that's
38
 * because we can only delete from a thread that holds the OpenGL context so here we provide a
39
 * framework where one is able to mark for deletion at any place and actual deletion takes place
40
 * on the next render).
32 41
 */
33 42
public class DistortedFramebuffer
34 43
  {
......
36 45
  private static final int TEXTURE_NOT_CREATED_YET  = -2;
37 46
  private static final int TEXTURE_DONT_CREATE      = -3;
38 47

  
48
  private static boolean mListMarked = false;
49
  private static LinkedList<DistortedFramebuffer> mList = new LinkedList<>();
50

  
39 51
  private float mX, mY;
40 52
  private float mFOV;
41 53

  
42 54
  private int[] texIds = new int[1];
43 55
  private int[] fboIds = new int[1];
44 56

  
57
  private boolean mMarked;
58

  
45 59
  int mWidth,mHeight,mDepth,mDistance;
46 60
  float[] mProjectionMatrix;
47
  boolean mMarked;
48 61

  
49 62
///////////////////////////////////////////////////////////////////////////////////////////////////
50 63

  
......
112 125
      return false;
113 126
      }
114 127

  
115
    DistortedFramebufferList.add(this);
128
    mList.add(this);
116 129
    android.util.Log.e("FBO", "created ("+mWidth+","+mHeight+") "+fboIds[0]);
117 130

  
118 131
    return true;
......
135 148
///////////////////////////////////////////////////////////////////////////////////////////////////
136 149
// must be called from a thread holding OpenGL Context
137 150

  
138
  void release()
151
  private void delete()
139 152
    {
140 153
    if( texIds[0]>=0 ) deleteFBO();
141 154

  
......
150 163
    texIds[0] = TEXTURE_NOT_CREATED_YET;
151 164
    }
152 165

  
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167

  
168
  static synchronized void release()
169
    {
170
    mListMarked = false;
171
    mList.clear();
172
    }
173

  
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175
// must be called form a thread holding OpenGL Context
176

  
177
  static synchronized void deleteAllMarked()
178
    {
179
    if( mListMarked )
180
      {
181
      DistortedFramebuffer tmp;
182
      Iterator<DistortedFramebuffer> iterator = mList.iterator();
183

  
184
      while(iterator.hasNext())
185
        {
186
        tmp = iterator.next();
187

  
188
        if( tmp.mMarked )
189
          {
190
          tmp.delete();
191
          iterator.remove();
192
          }
193
        }
194

  
195
      mListMarked = false;
196
      }
197
    }
153 198
///////////////////////////////////////////////////////////////////////////////////////////////////
154 199
// PUBLIC API
155 200
///////////////////////////////////////////////////////////////////////////////////////////////////
......
203 248
    {
204 249
    android.util.Log.e("FBO", "marking for deletion ("+mWidth+","+mHeight+") "+fboIds[0]);
205 250

  
206
    DistortedFramebufferList.markForDeletion();
207
    mMarked = true;
251
    mListMarked = true;
252
    mMarked     = true;
208 253
    }
209 254

  
210 255
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff