Project

General

Profile

« Previous | Next » 

Revision 226144d0

Added by Leszek Koltunski over 7 years ago

Progress with VBOs - this time abstract out a new class, DistortedObject - i.e. everything that uploads something to GPU and thus needs to be auto re-created upon loss of the context.

View differences:

src/main/java/org/distorted/library/Distorted.java
130 130
 */
131 131
  public static void onPause()
132 132
    {
133
    DistortedSurface.onPause();
133
    DistortedObject.onPause();
134 134
    DistortedNode.onPause();
135
    MeshObject.onPause();
136 135
    }
137 136

  
138 137
///////////////////////////////////////////////////////////////////////////////////////////////////
......
142 141
 */
143 142
  public static void onDestroy()
144 143
    {
145
    DistortedSurface.onDestroy();
144
    DistortedObject.onDestroy();
146 145
    DistortedNode.onDestroy();
147 146
    DistortedEffects.onDestroy();
148 147
    DistortedEffectsPostprocess.onDestroy();
149 148
    DistortedMaster.onDestroy();
150 149
    EffectQueue.onDestroy();
151
    MeshObject.onDestroy();
152 150
    EffectMessageSender.stopSending();
153 151

  
154 152
    mInitialized = false;
src/main/java/org/distorted/library/DistortedEffects.java
51 51
 */
52 52
public class DistortedEffects
53 53
  {
54
  private static final int POSITION_DATA_SIZE= 3; // Main Program: size of the position data in elements
55
  private static final int NORMAL_DATA_SIZE  = 3; // Main Program: size of the normal data in elements
56
  private static final int TEX_DATA_SIZE     = 2; // Main Program: size of the texture coordinate data in elements.
57

  
58 54
  /// MAIN PROGRAM ///
59 55
  private static DistortedProgram mMainProgram;
60 56
  private static int mMainTextureH;
......
305 301
    mF.send(halfW,halfH);
306 302

  
307 303
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mPosVBO[0]);
308
    GLES30.glVertexAttribPointer(mMainProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, 0);
304
    GLES30.glVertexAttribPointer(mMainProgram.mAttribute[0], MeshObject.POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, 0);
309 305
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mNorVBO[0]);
310
    GLES30.glVertexAttribPointer(mMainProgram.mAttribute[1], NORMAL_DATA_SIZE  , GLES30.GL_FLOAT, false, 0, 0);
306
    GLES30.glVertexAttribPointer(mMainProgram.mAttribute[1], MeshObject.NORMAL_DATA_SIZE  , GLES30.GL_FLOAT, false, 0, 0);
311 307
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mTexVBO[0]);
312
    GLES30.glVertexAttribPointer(mMainProgram.mAttribute[2], TEX_DATA_SIZE     , GLES30.GL_FLOAT, false, 0, 0);
308
    GLES30.glVertexAttribPointer(mMainProgram.mAttribute[2], MeshObject.TEX_DATA_SIZE     , GLES30.GL_FLOAT, false, 0, 0);
313 309
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
314 310
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0 );
315 311

  
src/main/java/org/distorted/library/DistortedObject.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
import java.util.HashMap;
23
import java.util.LinkedList;
24

  
25
///////////////////////////////////////////////////////////////////////////////////////////////////
26
/**
27
 * Any Object which gets uploaded to GPU memory and thus needs to be re-created (transparently to
28
 * applications!) whenever we lose OpenGL context.
29
 *
30
 * Keep all objects created in a static LinkedList. The point: we need to be able to mark
31
 * Objects for deletion, and delete all marked Objects later at a convenient time (that's
32
 * because we can only delete from a thread that holds the OpenGL context so here we provide a
33
 * framework where one is able to mark for deletion at any time and actual deletion takes place
34
 * on the next render).
35
*/
36
abstract class DistortedObject
37
{
38
  static final int FAILED_TO_CREATE = 1;
39
  static final int NOT_CREATED_YET  = 2;
40
  static final int DONT_CREATE      = 3;
41
  static final int CREATED          = 4;
42

  
43
  static final int TYPE_USER = 0;
44
  static final int TYPE_TREE = 1;
45
  static final int TYPE_SYST = 2;
46

  
47
  private static final int JOB_CREATE = 0;
48
  private static final int JOB_DELETE = 1;
49

  
50
  private class Job
51
    {
52
    DistortedObject object;
53
    int action;
54

  
55
    Job(DistortedObject o, int a)
56
      {
57
      object = o;
58
      action = a;
59
      }
60
    }
61

  
62
  private static boolean mToDo = false;
63
  private static LinkedList<DistortedObject> mDoneList = new LinkedList<>();
64
  private static HashMap<Long,Job> mToDoMap = new HashMap<>();
65
  private static long mNextClientID = 0;
66
  private static long mNextSystemID = 0;
67

  
68
  private long mID;
69
  private int mType;
70

  
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

  
73
  abstract void create();
74
  abstract void delete();
75
  abstract void recreate();
76
  abstract String printDetails();
77

  
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79
// must be called from a thread holding OpenGL Context
80

  
81
  static synchronized boolean toDo()
82
    {
83
    if( mToDo )
84
      {
85
      Job job;
86
      DistortedObject object;
87

  
88
      for(Long key: mToDoMap.keySet())
89
        {
90
        job = mToDoMap.get(key);
91
        object = job.object;
92

  
93
        //android.util.Log.d("Object", object.getClass().getSimpleName()+"  ---> need to "
94
        //                  +(job.action==JOB_CREATE ? "create":"delete")+" objectID="+object.mID );
95

  
96
        if( job.action==JOB_CREATE )
97
          {
98
          object.create();
99
          mDoneList.add(object);
100
          }
101
        else if( job.action==JOB_DELETE )
102
          {
103
          object.delete();
104
          }
105
        }
106

  
107
      mToDoMap.clear();
108
      mToDo = false;
109
      return true;
110
      }
111

  
112
    return false;
113
    }
114

  
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

  
117
  static synchronized void onPause()
118
    {
119
    DistortedObject object;
120
    int num = mDoneList.size();
121

  
122
    for(int i=0; i<num; i++)
123
      {
124
      object = mDoneList.removeFirst();
125
      mToDoMap.put(object.mID, object.new Job(object,JOB_CREATE) );
126
      object.recreate();
127
      }
128

  
129
    mToDo = true;
130
    }
131

  
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133

  
134
  static synchronized void onDestroy()
135
    {
136
    mToDoMap.clear();
137
    mDoneList.clear();
138

  
139
    mToDo = true;
140
    mNextClientID = 0;
141
    }
142

  
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

  
145
  @SuppressWarnings("unused")
146
  static void debugLists()
147
    {
148
    android.util.Log.e("Object", "Done list:");
149

  
150
    DistortedObject object;
151
    int num = mDoneList.size();
152

  
153
    for(int i=0; i<num; i++)
154
      {
155
      object = mDoneList.get(i);
156
      object.print("");
157
      }
158

  
159
    android.util.Log.e("Object", "ToDo list:");
160

  
161
    Job job;
162

  
163
    for(Long key: mToDoMap.keySet())
164
      {
165
      job = mToDoMap.get(key);
166
      job.object.print(job.action==JOB_CREATE ? " create":" delete");
167
      }
168
    }
169

  
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

  
172
  private void print(String msg)
173
    {
174
    String str = "ID:"+mID;
175

  
176
    switch(mType)
177
      {
178
      case TYPE_SYST: str+=" SYSTEM "; break;
179
      case TYPE_USER: str+=" USER   "; break;
180
      case TYPE_TREE: str+=" TREE   "; break;
181
      default       : str+=" ERROR? ";
182
      }
183

  
184
    android.util.Log.e("Object", str+printDetails()+msg);
185
    }
186

  
187

  
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189

  
190
  DistortedObject(int create, int type)
191
    {
192
    mID  = type==TYPE_SYST ? --mNextSystemID : ++mNextClientID;
193
    mType= type;
194

  
195
    if( create!=DONT_CREATE )
196
      {
197
      mToDoMap.put(mID, new Job(this,JOB_CREATE) );
198
      mToDo = true;
199
      }
200
    }
201

  
202
///////////////////////////////////////////////////////////////////////////////////////////////////
203

  
204
  synchronized void markForCreation()
205
    {
206
    mDoneList.remove(this);
207
    mToDoMap.put(mID, new Job(this,JOB_CREATE) );
208
    mToDo = true;
209
    }
210

  
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212
// PUBLIC API
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214
/**
215
 * Mark the underlying OpenGL object for deletion. Actual deletion will take place on the next render.
216
 */
217
  synchronized public void markForDeletion()
218
    {
219
    mDoneList.remove(this);
220
    mToDoMap.put(mID, new Job(this,JOB_DELETE) );
221
    mToDo = true;
222
    }
223

  
224
////////////////////////////////////////////////////////////////////////////////////////////////////
225
/**
226
 * Return unique ID of this Object.
227
 */
228
  public long getID()
229
    {
230
    return mID;
231
    }
232

  
233
}
src/main/java/org/distorted/library/DistortedOutputSurface.java
77 77

  
78 78
    mProjectionMatrix = new float[16];
79 79

  
80
    mWidth = width;
81
    mHeight= height;
82

  
83 80
    mFOV = 60.0f;
84 81
    mNear=  0.5f;
85 82

  
......
181 178

  
182 179
          for(int j=0; j<EffectQuality.LENGTH; j++)
183 180
            {
184
            mBuffer1[j] = new DistortedFramebuffer( mDepthCreated!=DONT_CREATE, DistortedSurface.TYPE_SYST,
181
            mBuffer1[j] = new DistortedFramebuffer( mDepthCreated!=DONT_CREATE, DistortedObject.TYPE_SYST,
185 182
                                                    (int)(mWidth*mipmap), (int)(mHeight*mipmap) );
186
            mBuffer2[j] = new DistortedFramebuffer(false                     , DistortedSurface.TYPE_SYST,
183
            mBuffer2[j] = new DistortedFramebuffer( false                     , DistortedObject.TYPE_SYST,
187 184
                                                    (int)(mWidth*mipmap), (int)(mHeight*mipmap) );
188 185
            mBuffer1[j].mMipmap = mipmap;
189 186
            mipmap *= EffectQuality.MULTIPLIER;
190 187
            }
191
          DistortedSurface.toDo();  // create immediately
188
          DistortedObject.toDo();  // create immediately
192 189
          }
193 190

  
194 191
        numRenders += child.draw(time,mBuffer1[currP.getQuality()]);
......
260 257
/*
261 258
    if( changed2 )
262 259
      {
263
      DistortedSurface.debugLists();
264
      }
265
*/
266
    // create and delete all Meshes (we need to create Vertex Buffer Objects)
267
/*
268
    boolean changed3 =
269
*/
270
    MeshObject.toDo();
271
/*
272
    if( changed3 )
273
      {
274
      MeshObject.debugLists();
260
      DistortedObject.debugLists();
275 261
      }
276 262
*/
277 263
    // mark OpenGL state as unknown
src/main/java/org/distorted/library/DistortedSurface.java
19 19

  
20 20
package org.distorted.library;
21 21

  
22
import java.util.HashMap;
23
import java.util.LinkedList;
24

  
25 22
///////////////////////////////////////////////////////////////////////////////////////////////////
26
/**
27
 * Keep all objects created in a static LinkedList. The point: we need to be able to mark
28
 * Objects for deletion, and delete all marked Objects later at a convenient time (that's
29
 * because we can only delete from a thread that holds the OpenGL context so here we provide a
30
 * framework where one is able to mark for deletion at any time and actual deletion takes place
31
 * on the next render).
32
*/
33
abstract class DistortedSurface
34
  {
35
  static final int FAILED_TO_CREATE = 1;
36
  static final int NOT_CREATED_YET  = 2;
37
  static final int DONT_CREATE      = 3;
38
  static final int CREATED          = 4;
39

  
40
  static final int TYPE_USER = 0;
41
  static final int TYPE_TREE = 1;
42
  static final int TYPE_SYST = 2;
43

  
44
  private static final int JOB_CREATE = 0;
45
  private static final int JOB_DELETE = 1;
46

  
47
  private class Job
48
    {
49
    DistortedSurface surface;
50
    int action;
51

  
52
    Job(DistortedSurface s, int a)
53
      {
54
      surface = s;
55
      action  = a;
56
      }
57
    }
58

  
59
  private static boolean mToDo = false;
60
  private static LinkedList<DistortedSurface> mDoneList = new LinkedList<>();
61
  private static HashMap<Long,Job> mToDoMap = new HashMap<>();
62
  private static long mNextClientID = 0;
63
  private static long mNextSystemID = 0;
64 23

  
65
  private long mID;
66
  private int mType;
24
abstract class DistortedSurface extends DistortedObject
25
{
67 26
  int mColorCreated;
68 27
  int[] mColorH = new int[1];
69 28
  int mWidth, mHeight;
70 29

  
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

  
73
  abstract void create();
74
  abstract void delete();
75
  abstract void recreate();
76

  
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
// must be called from a thread holding OpenGL Context
79

  
80
  static synchronized boolean toDo()
81
    {
82
    if( mToDo )
83
      {
84
      Job job;
85
      DistortedSurface surface;
86

  
87
      for(Long key: mToDoMap.keySet())
88
        {
89
        job = mToDoMap.get(key);
90
        surface = job.surface;
91

  
92
        //android.util.Log.d("SURFACE", "  ---> need to "+(job.action==JOB_CREATE ? "create":"delete")+" surfaceID="+surface.getID() );
93

  
94
        if( job.action==JOB_CREATE )
95
          {
96
          surface.create();
97
          mDoneList.add(surface);
98
          }
99
        else if( job.action==JOB_DELETE )
100
          {
101
          surface.delete();
102
          }
103
        }
104

  
105
      mToDoMap.clear();
106
      mToDo = false;
107
      return true;
108
      }
109

  
110
    return false;
111
    }
112

  
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

  
115
  static synchronized void onPause()
116
    {
117
    DistortedSurface surface;
118
    int num = mDoneList.size();
119

  
120
    for(int i=0; i<num; i++)
121
      {
122
      surface = mDoneList.removeFirst();
123
      mToDoMap.put(surface.getID(), surface.new Job(surface,JOB_CREATE) );
124
      surface.recreate();
125
      }
126

  
127
    mToDo = true;
128
    }
129

  
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

  
132
  static synchronized void onDestroy()
133
    {
134
    mToDoMap.clear();
135
    mDoneList.clear();
136

  
137
    mToDo = true;
138
    mNextClientID = 0;
139
    }
140

  
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142

  
143
  @SuppressWarnings("unused")
144
  static void debugLists()
145
    {
146
    android.util.Log.e("Surface", "Done list:");
147

  
148
    DistortedSurface surface;
149
    int num = mDoneList.size();
150

  
151
    for(int i=0; i<num; i++)
152
      {
153
      surface = mDoneList.get(i);
154
      surface.print(i, "");
155
      }
156

  
157
    android.util.Log.e("Surface", "ToDo list:");
158

  
159
    Job job;
160
    int i=0;
161

  
162
    for(Long key: mToDoMap.keySet())
163
      {
164
      job = mToDoMap.get(key);
165
      job.surface.print(i++, job.action==JOB_CREATE ? " create":" delete");
166
      }
167
    }
168

  
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170

  
171
  private void print(int i, String extra)
172
    {
173
    String str;
174

  
175
    if( this instanceof DistortedFramebuffer ) str = (i+": Framebuffer ");
176
    else if( this instanceof DistortedTexture) str = (i+": Texture     ");
177
    else if( this instanceof DistortedScreen ) str = (i+": Screen      ");
178
    else                                       str = (i+": UNKNOWN     ");
179

  
180
    str += ("("+getWidth()+","+getHeight()+") surfaceID:"+getID());
181

  
182
    switch(mType)
183
      {
184
      case TYPE_SYST: str+=" SYSTEM"; break;
185
      case TYPE_USER: str+=" USER"  ; break;
186
      case TYPE_TREE: str+=" TREE"  ; break;
187
      default       : str+=" ERROR??";
188
      }
189

  
190
    android.util.Log.e("Surface", str+extra);
191
    }
192

  
193 30
///////////////////////////////////////////////////////////////////////////////////////////////////
194 31

  
195 32
  DistortedSurface(int width, int height, int create, int type)
196 33
    {
34
    super(create,type);
35

  
197 36
    mWidth        = width ;
198 37
    mHeight       = height;
199 38
    mColorCreated = create;
200 39
    mColorH[0]    = 0;
201
    mID           = type==TYPE_SYST ? --mNextSystemID : ++mNextClientID;
202
    mType         = type;
203

  
204
    if( create!=DONT_CREATE )
205
      {
206
      mToDoMap.put(mID, new Job(this,JOB_CREATE) );
207
      mToDo = true;
208
      }
209 40
    }
210 41

  
211 42
///////////////////////////////////////////////////////////////////////////////////////////////////
43
// debugging only
212 44

  
213
  synchronized void markForCreation()
45
  String printDetails()
214 46
    {
215
    mDoneList.remove(this);
216
    mToDoMap.put(mID, new Job(this,JOB_CREATE) );
217
    mToDo = true;
47
    return getClass().getSimpleName()+" "+mWidth+"x"+mHeight;
218 48
    }
219 49

  
220 50
///////////////////////////////////////////////////////////////////////////////////////////////////
221 51
// PUBLIC API
222 52
///////////////////////////////////////////////////////////////////////////////////////////////////
223
/**
224
 * Mark the underlying OpenGL object for deletion. Actual deletion will take place on the next render.
225
 */
226
  synchronized public void markForDeletion()
227
    {
228
    mDoneList.remove(this);
229
    mToDoMap.put(mID, new Job(this,JOB_DELETE) );
230
    mToDo = true;
231
    }
232

  
233
////////////////////////////////////////////////////////////////////////////////////////////////////
234
/**
235
 * Return unique ID of this Surface.
236
 */
237
  public long getID()
238
    {
239
    return mID;
240
    }
241

  
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243

  
244 53
/**
245 54
 * Return the width of this Surface.
246 55
 *
......
276 85
    {
277 86
    return mesh==null ? 0 : (int)(mWidth*mesh.zFactor);
278 87
    }
279
  }
88
}
src/main/java/org/distorted/library/MeshObject.java
22 22
import android.opengl.GLES30;
23 23

  
24 24
import java.nio.FloatBuffer;
25
import java.util.HashMap;
26
import java.util.LinkedList;
27 25

  
28 26
///////////////////////////////////////////////////////////////////////////////////////////////////
29 27
/**
......
33 31
 * If you want to render to a particular shape, extend from here, construct the three FloatBuffers and
34 32
 * provide correct dataLength, i.e. the number of vertices.
35 33
 */
36
public abstract class MeshObject
34
public abstract class MeshObject extends DistortedObject
37 35
   {
38 36
   static final int BYTES_PER_FLOAT   = 4; //
39 37
   static final int POSITION_DATA_SIZE= 3; // Size of the position data in elements
40 38
   static final int NORMAL_DATA_SIZE  = 3; // Size of the normal data in elements.
41 39
   static final int TEX_DATA_SIZE     = 2; // Size of the texture coordinate data in elements.
42 40

  
43
   ///// CREATING/DELETING Vertex Buffer Objects ///////////////////////////
44
   private static final int JOB_CREATE = 0;
45
   private static final int JOB_DELETE = 1;
46

  
47
   private class Job
48
     {
49
     MeshObject mesh;
50
     int action;
51

  
52
     Job(MeshObject o, int a)
53
       {
54
       mesh   = o;
55
       action = a;
56
       }
57
     }
58

  
59
   private static boolean mToDo = false;
60
   private static LinkedList<MeshObject> mDoneList = new LinkedList<>();
61
   private static HashMap<Long,Job> mToDoMap = new HashMap<>();
62
   /////////////////////////////////////////////////////////////////////////
63

  
64
   private static long mNextID = 0;
65
   private long mID;
66

  
67 41
   int dataLength;
68 42
   FloatBuffer mMeshPositions, mMeshNormals, mMeshTexture;
69 43
   int[] mPosVBO = new int[1];
......
77 51

  
78 52
   MeshObject(float factor)
79 53
     {
80
     zFactor = factor;
81
     mID     = mNextID++;
54
     super(DistortedObject.NOT_CREATED_YET,DistortedObject.TYPE_USER);
82 55

  
56
     zFactor = factor;
83 57
     recreate();
84

  
85
     mToDoMap.put(mID, new Job(this,JOB_CREATE) );
86
     mToDo = true;
87
     }
88

  
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90
// must be called from a thread holding OpenGL Context
91

  
92
   static synchronized boolean toDo()
93
     {
94
     if( mToDo )
95
       {
96
       Job job;
97
       MeshObject mesh;
98

  
99
       for(Long key: mToDoMap.keySet())
100
         {
101
         job = mToDoMap.get(key);
102
         mesh = job.mesh;
103

  
104
         //android.util.Log.d("MESH", "  ---> need to "+(job.action==JOB_CREATE ? "create":"delete") );
105

  
106
         if( job.action==JOB_CREATE )
107
           {
108
           mesh.create();
109
           mDoneList.add(mesh);
110
           }
111
         else if( job.action==JOB_DELETE )
112
           {
113
           mesh.delete();
114
           }
115
         }
116

  
117
       mToDoMap.clear();
118
       mToDo = false;
119
       return true;
120
       }
121

  
122
     return false;
123 58
     }
124 59

  
125 60
///////////////////////////////////////////////////////////////////////////////////////////////////
......
128 63
// Do NOT release mMeshPositions etc as we will need them when we need to re-create the buffers after
129 64
// a loss of OpenGL context!
130 65

  
131
   private void create()
66
   void create()
132 67
     {
133 68
     if( mPosVBO[0]<0 )
134 69
       {
......
155 90
///////////////////////////////////////////////////////////////////////////////////////////////////
156 91
// must be called from a thread holding OpenGL Context
157 92

  
158
   private void delete()
93
   void delete()
159 94
     {
160 95
     if( mPosVBO[0]>=0 )
161 96
       {
......
176 111

  
177 112
///////////////////////////////////////////////////////////////////////////////////////////////////
178 113

  
179
   private void recreate()
114
   void recreate()
180 115
     {
181 116
     mPosVBO[0] = -1;
182 117
     mNorVBO[0] = -1;
......
184 119
     }
185 120

  
186 121
///////////////////////////////////////////////////////////////////////////////////////////////////
122
// debugging only
187 123

  
188
  static synchronized void onPause()
189
    {
190
    MeshObject mesh;
191
    int num = mDoneList.size();
192

  
193
    for(int i=0; i<num; i++)
194
      {
195
      mesh = mDoneList.removeFirst();
196
      mToDoMap.put(mesh.getID(), mesh.new Job(mesh,JOB_CREATE) );
197
      mesh.recreate();
198
      }
199

  
200
    mToDo = true;
201
    }
202

  
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204

  
205
  static synchronized void onDestroy()
206
    {
207
    mToDoMap.clear();
208
    mDoneList.clear();
209

  
210
    mToDo = true;
211
    mNextID = 0;
212
    }
213

  
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215

  
216
  @SuppressWarnings("unused")
217
  static void debugLists()
218
    {
219
    android.util.Log.e("Mesh", "Done list:");
220

  
221
    MeshObject mesh;
222
    int num = mDoneList.size();
223

  
224
    for(int i=0; i<num; i++)
225
      {
226
      mesh = mDoneList.get(i);
227
      mesh.print(i, "");
228
      }
229

  
230
    android.util.Log.e("Mesh", "ToDo list:");
231

  
232
    Job job;
233
    int i=0;
234

  
235
    for(Long key: mToDoMap.keySet())
236
      {
237
      job = mToDoMap.get(key);
238
      job.mesh.print(i++, job.action==JOB_CREATE ? " create":" delete");
239
      }
240
    }
241

  
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243

  
244
  private void print(int i, String extra)
245
    {
246
    String str;
247

  
248
         if( this instanceof MeshFlat ) str = (i+": MeshFlat  ");
249
    else if( this instanceof MeshCubes) str = (i+": MeshCubes ");
250
    else                                str = (i+": UNKNOWN   ");
251

  
252
    str += ( "dataLength: "+dataLength+" meshID:"+getID());
124
   String printDetails()
125
     {
126
     return getClass().getSimpleName()+" vertices:"+dataLength;
127
     }
253 128

  
254
    android.util.Log.e("Mesh", str+extra);
255
    }
256 129
///////////////////////////////////////////////////////////////////////////////////////////////////
257 130
/**
258 131
 * Get the minimal set of Vertices which have the same convex hull as the whole set.
......
263 136
 * This is used to be able to quickly compute, in window coordinates, the Mesh'es bounding rectangle.
264 137
 */
265 138
   abstract float[] getBoundingVertices();
266

  
267
///////////////////////////////////////////////////////////////////////////////////////////////////
268

  
269
   synchronized void markForCreation()
270
     {
271
     mDoneList.remove(this);
272
     mToDoMap.put(mID, new Job(this,JOB_CREATE) );
273
     mToDo = true;
274
     }
275

  
276
///////////////////////////////////////////////////////////////////////////////////////////////////
277
// PUBLIC API
278
///////////////////////////////////////////////////////////////////////////////////////////////////
279
/**
280
 * Mark the underlying OpenGL object for deletion. Actual deletion will take place on the next render.
281
 */
282
   synchronized public void markForDeletion()
283
     {
284
     mDoneList.remove(this);
285
     mToDoMap.put(mID, new Job(this,JOB_DELETE) );
286
     mToDo = true;
287
     }
288

  
289
///////////////////////////////////////////////////////////////////////////////////////////////////
290
/**
291
 * Return unique ID of this Mesh.
292
 */
293
   public long getID()
294
    {
295
    return mID;
296
    }
297 139
   }
140

  

Also available in: Unified diff