Project

General

Profile

« Previous | Next » 

Revision c7da4e65

Added by Leszek Koltunski about 7 years ago

Fix OutputSurface.resize(): before it couldn't be called mid-render.

View differences:

src/main/java/org/distorted/library/DistortedEffects.java
342 342
 */
343 343
  public DistortedEffects()
344 344
    {
345
    mID = mNextID++;
345
    mID = ++mNextID;
346 346
    initializeEffectLists(this,0);
347 347
    }
348 348

  
......
358 358
 */
359 359
  public DistortedEffects(DistortedEffects dc, int flags)
360 360
    {
361
    mID = mNextID++;
361
    mID = ++mNextID;
362 362
    initializeEffectLists(dc,flags);
363 363
    }
364 364

  
src/main/java/org/distorted/library/DistortedFramebuffer.java
37 37

  
38 38
  void create()
39 39
    {
40
    if( mColorH[0]==NOT_CREATED_YET )
40
    if( mColorCreated==NOT_CREATED_YET )
41 41
      {
42 42
      GLES30.glGenTextures(1, mColorH, 0);
43 43
      GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[0]);
......
51 51
      GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[0]);
52 52
      GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, mColorH[0], 0);
53 53

  
54
      checkStatus("color");
54
      mColorCreated = checkStatus("color");
55 55
      }
56
    if( mDepthEnabled && mDepthH[0]==NOT_CREATED_YET ) // we need to create a new DEPTH attachment
56
    if( mDepthCreated==NOT_CREATED_YET ) // we need to create a new DEPTH attachment
57 57
      {
58 58
      GLES30.glGenTextures(1, mDepthH, 0);
59 59
      GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mDepthH[0]);
......
66 66
      GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[0]);
67 67
      GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_ATTACHMENT, GLES30.GL_TEXTURE_2D, mDepthH[0], 0);
68 68

  
69
      checkStatus("depth");
69
      mDepthCreated = checkStatus("depth");
70 70
      }
71
    if( !mDepthEnabled && mDepthH[0]!=NOT_CREATED_YET ) // we need to detach and recreate the DEPTH attachment.
71
    if( mDepthCreated==DONT_CREATE && mDepthH[0]>0 ) // we need to detach and recreate the DEPTH attachment.
72 72
      {
73 73
      GLES30.glDeleteTextures(1, mDepthH, 0);
74
      mDepthH[0]=NOT_CREATED_YET;
74
      mDepthH[0]=0;
75 75
      }
76 76
    }
77 77

  
78 78
///////////////////////////////////////////////////////////////////////////////////////////////////
79 79

  
80
  private boolean checkStatus(String message)
80
  private int checkStatus(String message)
81 81
    {
82 82
    int status = GLES30.glCheckFramebufferStatus(GLES30.GL_FRAMEBUFFER);
83 83

  
......
88 88
      GLES30.glDeleteTextures(1, mColorH, 0);
89 89
      GLES30.glDeleteTextures(1, mDepthH, 0);
90 90
      GLES30.glDeleteFramebuffers(1, mFBOH, 0);
91
      mFBOH[0]   = 0;
92
      mColorH[0] = FAILED_TO_CREATE;
93
      mDepthH[0] = FAILED_TO_CREATE;
91
      mFBOH[0]= 0;
94 92

  
95
      return false;
93
      return FAILED_TO_CREATE;
96 94
      }
97 95

  
98
    return true;
96
    return CREATED;
99 97
    }
100 98

  
101 99
///////////////////////////////////////////////////////////////////////////////////////////////////
......
103 101

  
104 102
  void delete()
105 103
    {
106
    if( mColorH[0]>=0 )
104
    if( mColorH[0]>0 )
107 105
      {
108
      if( mDepthH[0]>=0 )
106
      if( mDepthH[0]>0 )
109 107
        {
110 108
        GLES30.glDeleteTextures(1, mDepthH, 0);
111
        mDepthH[0]=NOT_CREATED_YET;
109
        mDepthH[0]=0;
110
        mDepthCreated = NOT_CREATED_YET;
112 111
        }
113 112

  
114 113
      GLES30.glDeleteTextures(1, mColorH, 0);
115
      mColorH[0] = NOT_CREATED_YET;
114
      mColorH[0] = 0;
115
      mColorCreated = NOT_CREATED_YET;
116 116

  
117 117
      GLES30.glDeleteFramebuffers(1, mFBOH, 0);
118 118
      mFBOH[0] = 0;
......
124 124

  
125 125
  void recreate()
126 126
    {
127
    if( mColorH[0]!=DONT_CREATE ) mColorH[0] = NOT_CREATED_YET;
128
    if( mDepthEnabled           ) mDepthH[0] = NOT_CREATED_YET;
127
    if( mColorCreated!=DONT_CREATE ) mColorCreated = NOT_CREATED_YET;
128
    if( mDepthCreated!=DONT_CREATE ) mDepthCreated = NOT_CREATED_YET;
129 129
    }
130 130

  
131 131
///////////////////////////////////////////////////////////////////////////////////////////////////
......
159 159

  
160 160
  DistortedFramebuffer(boolean depthEnabled, int width, int height)
161 161
    {
162
    super(width,height,NOT_CREATED_YET,NOT_CREATED_YET,true, depthEnabled);
162
    super(width,height,NOT_CREATED_YET, (depthEnabled ? NOT_CREATED_YET:DONT_CREATE),NOT_CREATED_YET, true);
163 163
    }
164 164

  
165 165
///////////////////////////////////////////////////////////////////////////////////////////////////
......
175 175
  @SuppressWarnings("unused")
176 176
  public DistortedFramebuffer(int width, int height, boolean depthEnabled)
177 177
    {
178
    super(width,height,NOT_CREATED_YET,NOT_CREATED_YET,false, depthEnabled);
178
    super(width,height,NOT_CREATED_YET,(depthEnabled ? NOT_CREATED_YET:DONT_CREATE),NOT_CREATED_YET,false);
179 179
    }
180 180

  
181 181
///////////////////////////////////////////////////////////////////////////////////////////////////
......
189 189
  @SuppressWarnings("unused")
190 190
  public DistortedFramebuffer(int width, int height)
191 191
    {
192
    super(width,height,NOT_CREATED_YET,NOT_CREATED_YET,false,false);
192
    super(width,height,NOT_CREATED_YET,DONT_CREATE,NOT_CREATED_YET,false);
193 193
    }
194 194

  
195 195
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/DistortedOutputSurface.java
37 37
  float mDistance;
38 38
  float[] mProjectionMatrix;
39 39

  
40
  boolean mDepthEnabled;
40
  int mDepthCreated;
41 41
  int[] mDepthH = new int[1];
42 42
  int[] mFBOH   = new int[1];
43 43

  
44 44
///////////////////////////////////////////////////////////////////////////////////////////////////
45 45

  
46
  DistortedOutputSurface(int width, int height, int color, int fbo, boolean system, boolean depth)
46
  DistortedOutputSurface(int width, int height, int createColor, int createDepth, int fbo, boolean system)
47 47
    {
48
    super(width,height,color,system);
48
    super(width,height,createColor,system);
49 49

  
50 50
    mProjectionMatrix = new float[16];
51 51

  
......
56 56
    mX   =  0.0f;
57 57
    mY   =  0.0f;
58 58

  
59
    mDepthEnabled= depth;
59
    mDepthCreated= createDepth;
60 60
    mFBOH[0]     = fbo;
61
    mDepthH[0]   = color;
61
    mDepthH[0]   = 0;
62 62

  
63 63
    createProjection();
64 64
    }
......
158 158
    {
159 159
    GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[0]);
160 160

  
161
    if( mDepthEnabled && mDepthH[0]!=NOT_CREATED_YET )
161
    if( mDepthCreated==CREATED )
162 162
      {
163 163
      GLES30.glEnable(GLES30.GL_DEPTH_TEST);
164 164
      GLES30.glDepthMask(true);
......
190 190
///////////////////////////////////////////////////////////////////////////////////////////////////
191 191
/**
192 192
 * Resize the underlying Framebuffer.
193
 * <p>
194
 * This method can be safely called mid-render as it doesn't interfere with rendering.
193 195
 *
194 196
 * @param width The new width.
195 197
 * @param height The new height.
......
205 207

  
206 208
      createProjection();
207 209

  
208
      if( mColorH[0]>0 )
210
      if( mColorCreated==CREATED )
209 211
        {
210 212
        moveToToDo();
211 213
        recreate();
......
222 224
 */
223 225
  public void enableDepth(boolean enable)
224 226
    {
225
    if( mDepthEnabled!=enable )
227
    if( enable && mDepthCreated==DONT_CREATE )
228
      {
229
      mDepthCreated = NOT_CREATED_YET;
230
      moveToToDo();
231
      }
232
    if( !enable && mDepthCreated!=DONT_CREATE )
226 233
      {
227
      mDepthEnabled = enable;
234
      mDepthCreated = DONT_CREATE;
228 235
      moveToToDo();
229 236
      }
230 237
    }
......
237 244
 */
238 245
  public boolean hasDepth()
239 246
    {
240
    return mDepthEnabled;
247
    return mDepthCreated==CREATED;
241 248
    }
242 249

  
243 250
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/DistortedScreen.java
44 44
 */
45 45
  public DistortedScreen()
46 46
    {
47
    super(0,0,DONT_CREATE,0,false,true);
47
    super(0,0,CREATED,CREATED,0,false);
48 48
    }
49 49
  }
src/main/java/org/distorted/library/DistortedSurface.java
31 31
*/
32 32
abstract class DistortedSurface
33 33
  {
34
  static final int FAILED_TO_CREATE = -1;
35
  static final int NOT_CREATED_YET  = -2;
36
  static final int DONT_CREATE      = -3;
34
  static final int FAILED_TO_CREATE = 1;
35
  static final int NOT_CREATED_YET  = 2;
36
  static final int DONT_CREATE      = 3;
37
  static final int CREATED          = 4;
37 38

  
38 39
  private static boolean mToDo = false;
39 40
  private static LinkedList<DistortedSurface> mDoneList = new LinkedList<>();
......
44 45
  private long mID;
45 46
  private boolean mMarked;
46 47
  private boolean mSystem;
48
  int mColorCreated;
47 49
  int[] mColorH = new int[1];
48 50
  int mSizeX, mSizeY;  // in screen space
49 51

  
......
169 171

  
170 172
///////////////////////////////////////////////////////////////////////////////////////////////////
171 173

  
172
  DistortedSurface(int width, int height, int color, boolean system)
174
  DistortedSurface(int width, int height, int create, boolean system)
173 175
    {
174
    mSizeX    = width ;
175
    mSizeY    = height;
176
    mColorH[0]= color;
177
    mMarked   = false;
178
    mID       = system ? --mNextSystemID : ++mNextClientID;
179
    mSystem   = system;
180

  
181
    if( color!=DONT_CREATE )
176
    mSizeX        = width ;
177
    mSizeY        = height;
178
    mColorCreated = create;
179
    mColorH[0]    = 0;
180
    mMarked       = false;
181
    mID           = system ? --mNextSystemID : ++mNextClientID;
182
    mSystem       = system;
183

  
184
    if( create!=DONT_CREATE )
182 185
      {
183 186
      mToDoList.add(this);
184 187
      mToDo = true;
src/main/java/org/distorted/library/DistortedTexture.java
57 57

  
58 58
  void create()
59 59
    {
60
    if( mBmp!=null && mColorH !=null )
60
    if( mBmp!=null )
61 61
      {
62
      if( mColorH[0]==NOT_CREATED_YET )
62
      if( mColorCreated==NOT_CREATED_YET )
63 63
        {
64
        mColorCreated = CREATED;
64 65
        GLES30.glGenTextures(1, mColorH, 0);
65 66
        GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[0]);
66 67
        GLES30.glTexParameteri ( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_LINEAR );
......
84 85

  
85 86
  void delete()
86 87
    {
87
    if( mColorH !=null && mColorH[0]>=0 )
88
    if( mColorH[0]>=0 )
88 89
      {
89 90
      GLES30.glDeleteTextures(1, mColorH, 0);
90
      mColorH[0] = NOT_CREATED_YET;
91
      mColorH[0] = 0;
92
      mColorCreated = NOT_CREATED_YET;
91 93
      }
92 94
    }
93 95

  
......
96 98

  
97 99
  void recreate()
98 100
    {
99
    if( mColorH[0]!=DONT_CREATE ) mColorH[0] = NOT_CREATED_YET;
101
    if( mColorCreated!=DONT_CREATE ) mColorCreated = NOT_CREATED_YET;
100 102
    }
101 103

  
102 104
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff