Project

General

Profile

« Previous | Next » 

Revision 2e49718d

Added by Leszek Koltunski about 7 years ago

progress with DistortedRenderable.

This introduces a regression with MultiBlur!

View differences:

src/main/java/org/distorted/library/Distorted.java
136 136
 */
137 137
  public static void onDestroy()
138 138
    {
139
    DistortedTexture.onDestroy();
140
    DistortedFramebuffer.onDestroy();
139
    DistortedRenderable.onDestroy();
141 140
    DistortedTree.onDestroy();
142 141
    EffectQueue.onDestroy();
143 142
    DistortedEffects.onDestroy();
src/main/java/org/distorted/library/DistortedFramebuffer.java
22 22
import android.opengl.GLES30;
23 23
import android.opengl.Matrix;
24 24

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

  
28 25
///////////////////////////////////////////////////////////////////////////////////////////////////
29 26
/**
30 27
 * Class which represents a OpenGL Framebuffer object.
......
41 38
 */
42 39
public class DistortedFramebuffer extends DistortedRenderable
43 40
  {
44
  private static boolean mListMarked = false;
45
  private static LinkedList<DistortedFramebuffer> mList = new LinkedList<>();
46

  
47 41
  private int[] mDepthH = new int[1];
48 42
  private int[] mFBOH   = new int[1];
49 43

  
50
  private boolean mMarked;
51 44
  private boolean mDepthEnabled;
52 45

  
53 46
  // Projection stuff
......
142 135
      GLES30.glDeleteFramebuffers(1, mFBOH, 0);
143 136
      mFBOH[0] = 0;
144 137
      }
145

  
146
    mMarked = false;
147 138
    }
148 139

  
149 140
///////////////////////////////////////////////////////////////////////////////////////////////////
......
199 190
      }
200 191
    }
201 192

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

  
204
  static synchronized void onDestroy()
205
    {
206
    for( DistortedFramebuffer fbo : mList)
207
      {
208
      if( fbo.mColorH[0]!=DONT_CREATE ) fbo.mColorH[0] = NOT_CREATED_YET;
209
      if( fbo.mDepthEnabled           ) fbo.mDepthH[0] = NOT_CREATED_YET;
210
      }
211
    }
212

  
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214
// must be called form a thread holding OpenGL Context
215

  
216
  private static synchronized void deleteAllMarked()
217
    {
218
    if( mListMarked )
219
      {
220
      DistortedFramebuffer tmp;
221
      Iterator<DistortedFramebuffer> iterator = mList.iterator();
222

  
223
      while(iterator.hasNext())
224
        {
225
        tmp = iterator.next();
226

  
227
        if( tmp.mMarked )
228
          {
229
          tmp.delete();
230
          iterator.remove();
231
          }
232
        }
233

  
234
      mListMarked = false;
235
      }
236
    }
237

  
238 193
///////////////////////////////////////////////////////////////////////////////////////////////////
239 194
// if new size fits into the size of the underlying Texture, just change the projection without
240 195
// reallocating the Texture. Otherwise, we need to reallocate.
......
274 229
  @SuppressWarnings("unused")
275 230
  public DistortedFramebuffer(int width, int height, boolean depthEnabled)
276 231
    {
232
    super(width,height,NOT_CREATED_YET);
233

  
277 234
    mProjectionMatrix = new float[16];
278 235

  
279 236
    mHeight      = height;
280 237
    mWidth       = width;
281
    mSizeY       = height;
282
    mSizeX       = width;
283 238
    mFOV         = 60.0f;
284 239
    mX           = 0.0f;
285 240
    mY           = 0.0f;
286
    mMarked      = false;
287 241
    mDepthEnabled= depthEnabled;
288

  
289
    mFBOH[0]  =-1;
290
    mColorH[0]= NOT_CREATED_YET;
291
    mDepthH[0]= NOT_CREATED_YET;
242
    mFBOH[0]     = NOT_CREATED_YET;
243
    mDepthH[0]   = NOT_CREATED_YET;
292 244

  
293 245
    createProjection();
294

  
295
    mList.add(this);
296 246
    }
297 247

  
298 248
///////////////////////////////////////////////////////////////////////////////////////////////////
......
306 256
  @SuppressWarnings("unused")
307 257
  public DistortedFramebuffer(int width, int height)
308 258
    {
259
    super(width,height,NOT_CREATED_YET);
260

  
309 261
    mProjectionMatrix = new float[16];
310 262

  
311 263
    mHeight      = height;
312 264
    mWidth       = width;
313
    mSizeY       = height;
314
    mSizeX       = width;
315 265
    mFOV         = 60.0f;
316 266
    mX           = 0.0f;
317 267
    mY           = 0.0f;
318
    mMarked      = false;
319 268
    mDepthEnabled= false;
320

  
321
    mFBOH[0]  =-1;
322
    mColorH[0]= NOT_CREATED_YET;
323
    mDepthH[0]= NOT_CREATED_YET;
269
    mFBOH[0]     = NOT_CREATED_YET;
270
    mDepthH[0]   = NOT_CREATED_YET;
324 271

  
325 272
    createProjection();
326

  
327
    mList.add(this);
328 273
    }
329 274

  
330 275
///////////////////////////////////////////////////////////////////////////////////////////////////
......
337 282
 */
338 283
  public DistortedFramebuffer(int fbo)
339 284
    {
285
    super(0,0,DONT_CREATE);
286

  
340 287
    mProjectionMatrix = new float[16];
341 288

  
342 289
    mFOV         = 60.0f;
343 290
    mX           = 0.0f;
344 291
    mY           = 0.0f;
345
    mMarked      = false;
346 292
    mDepthEnabled= true;
347

  
348
    mFBOH[0]  = fbo;
349
    mColorH[0]= DONT_CREATE;
350
    mDepthH[0]= DONT_CREATE;
293
    mFBOH[0]     = fbo;
294
    mDepthH[0]   = DONT_CREATE;
351 295
    }
352 296

  
353 297
///////////////////////////////////////////////////////////////////////////////////////////////////
......
381 325

  
382 326
    if( ren.setAsInput() )
383 327
      {
384
      DistortedFramebuffer.deleteAllMarked();
385
      DistortedTexture.deleteAllMarked();
328
      DistortedRenderable.deleteAllMarked();
386 329
      effects.drawPriv(ren.getWidth()/2.0f, ren.getHeight()/2.0f, mesh, this, time);
387 330
      }
388 331
    }
......
398 341
 */
399 342
  public void renderTo(DistortedTree dt, long time)
400 343
    {
401
    DistortedFramebuffer.deleteAllMarked();
402
    DistortedTexture.deleteAllMarked();
344
    DistortedRenderable.deleteAllMarked();
403 345
    create();
404 346
    dt.drawRecursive(time,this);
405 347
    }
406 348

  
407
///////////////////////////////////////////////////////////////////////////////////////////////////
408
/**
409
 * Mark the underlying OpenGL object for deletion. Actual deletion will take place on the next render.
410
 */
411
  public void markForDeletion()
412
    {
413
    mListMarked = true;
414
    mMarked     = true;
415
    }
416

  
417 349
///////////////////////////////////////////////////////////////////////////////////////////////////
418 350
/**
419 351
 * Create new Projection matrix.
src/main/java/org/distorted/library/DistortedRenderable.java
21 21

  
22 22
import android.opengl.GLES30;
23 23

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

  
24 27
///////////////////////////////////////////////////////////////////////////////////////////////////
25 28

  
26 29
abstract class DistortedRenderable
......
29 32
  static final int NOT_CREATED_YET  = -2;
30 33
  static final int DONT_CREATE      = -3;
31 34

  
35
  private static boolean mListMarked = false;
36
  private static LinkedList<DistortedRenderable> mList = new LinkedList<>();
37

  
38
  private boolean mMarked;
32 39
  int[] mColorH = new int[1];
33 40
  int mSizeX, mSizeY;  // in screen space
34 41

  
......
37 44
  abstract void create();
38 45
  abstract void delete();
39 46

  
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48
// must be called form a thread holding OpenGL Context
49

  
50
  static synchronized void deleteAllMarked()
51
    {
52
    if( mListMarked )
53
      {
54
      DistortedRenderable tmp;
55
      Iterator<DistortedRenderable> iterator = mList.iterator();
56

  
57
      while(iterator.hasNext())
58
        {
59
        tmp = iterator.next();
60

  
61
        if( tmp.mMarked )
62
          {
63
          tmp.delete();
64
          tmp.mMarked = false;
65
          iterator.remove();
66
          }
67
        }
68

  
69
      mListMarked = false;
70
      }
71
    }
72

  
40 73
///////////////////////////////////////////////////////////////////////////////////////////////////
41 74

  
42 75
  long getID()
......
57 90
    return false;
58 91
    }
59 92

  
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

  
95
  static synchronized void onDestroy()
96
    {
97
    for( DistortedRenderable ren : mList)
98
      {
99
      ren.delete();
100
      ren.mMarked = false;
101
      }
102

  
103
    mListMarked = false;
104
    mList.clear();
105
    }
106

  
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

  
109
  DistortedRenderable(int width, int height, int color)
110
    {
111
    mSizeX    = width ;
112
    mSizeY    = height;
113
    mColorH[0]= color;
114
    mMarked   = false;
115
    mList.add(this);
116
    }
117

  
60 118
///////////////////////////////////////////////////////////////////////////////////////////////////
61 119
// PUBLIC API
62 120
///////////////////////////////////////////////////////////////////////////////////////////////////
121
/**
122
 * Mark the underlying OpenGL object for deletion. Actual deletion will take place on the next render.
123
 */
124
  public void markForDeletion()
125
    {
126
    mListMarked = true;
127
    mMarked     = true;
128
    }
129

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

  
63 132
/**
64 133
 * Returns the height of the Renderable.
65 134
 *
src/main/java/org/distorted/library/DistortedTexture.java
24 24
import android.opengl.GLES30;
25 25
import android.opengl.GLUtils;
26 26

  
27
import java.util.Iterator;
28
import java.util.LinkedList;
29

  
30 27
///////////////////////////////////////////////////////////////////////////////////////////////////
31 28
/**
32 29
 * Class which represents a OpenGL Texture object.
......
41 38
 */
42 39
public class DistortedTexture extends DistortedRenderable
43 40
  {
44
  private static boolean mListMarked = false;
45
  private static LinkedList<DistortedTexture> mList = new LinkedList<>();
46

  
47
  private static int mTextureH;
48

  
49
  private boolean mMarked;
50 41
  private Bitmap mBmp= null;
51 42

  
52 43
///////////////////////////////////////////////////////////////////////////////////////////////////
......
74 65
    {
75 66
    if( mBmp!=null && mColorH !=null )
76 67
      {
77
      if( mColorH[0]==0 )
68
      if( mColorH[0]==NOT_CREATED_YET )
78 69
        {
79 70
        GLES30.glGenTextures(1, mColorH, 0);
80 71
        GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[0]);
......
99 90

  
100 91
  void delete()
101 92
    {
102
    if( mColorH !=null && mColorH[0]>0 )
93
    if( mColorH !=null && mColorH[0]>=0 )
103 94
      {
104 95
      GLES30.glDeleteTextures(1, mColorH, 0);
105
      mColorH[0] = 0;
96
      mColorH[0] = NOT_CREATED_YET;
106 97
      }
107

  
108
    mMarked = false;
109 98
    }
110 99

  
111 100
///////////////////////////////////////////////////////////////////////////////////////////////////
112 101

  
113 102
  static void getUniforms(int mProgramH)
114 103
    {
115
    mTextureH= GLES30.glGetUniformLocation( mProgramH, "u_Texture");
104
    int textureH= GLES30.glGetUniformLocation( mProgramH, "u_Texture");
116 105

  
117 106
    GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
118
    GLES30.glUniform1i(mTextureH, 0);
119
    }
120

  
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

  
123
  static synchronized void onDestroy()
124
    {
125
    mListMarked = false;
126
    mList.clear();
127
    }
128

  
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130
// must be called form a thread holding OpenGL Context
131

  
132
  static synchronized void deleteAllMarked()
133
    {
134
    if( mListMarked )
135
      {
136
      DistortedTexture tmp;
137
      Iterator<DistortedTexture> iterator = mList.iterator();
138

  
139
      while(iterator.hasNext())
140
        {
141
        tmp = iterator.next();
142

  
143
        if( tmp.mMarked )
144
          {
145
          tmp.delete();
146
          iterator.remove();
147
          }
148
        }
149

  
150
      mListMarked = false;
151
      }
107
    GLES30.glUniform1i(textureH, 0);
152 108
    }
153 109

  
154 110
///////////////////////////////////////////////////////////////////////////////////////////////////
......
159 115
 */
160 116
  public DistortedTexture(int width, int height)
161 117
    {
162
    mSizeX    = width ;
163
    mSizeY    = height;
164
    mColorH[0]= 0;
165
    mBmp      = null;
166
    mMarked   = false;
167

  
168
    mList.add(this);
169
    }
170

  
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172
/**
173
 * Mark the underlying OpenGL object for deletion. Actual deletion will take place on the next render.
174
 */
175
  public void markForDeletion()
176
    {
177
    mListMarked = true;
178
    mMarked     = true;
118
    super(width,height,NOT_CREATED_YET);
119
    mBmp= null;
179 120
    }
180 121

  
181 122
///////////////////////////////////////////////////////////////////////////////////////////////////
......
187 128
 *
188 129
 * @param bmp The android.graphics.Bitmap object to apply effects to and display.
189 130
 */
190

  
191 131
  public void setTexture(Bitmap bmp)
192 132
    {
193 133
    mBmp= bmp;

Also available in: Unified diff