Project

General

Profile

« Previous | Next » 

Revision 728a7820

Added by Leszek Koltunski over 3 years ago

Fix the fact that we would keep adding new InternalBuffers to the 'Done' list - split 'invalidate()' and 'recreate()' to two separate actions!

View differences:

src/main/java/org/distorted/library/main/InternalBuffer.java
38 38
 */
39 39
public class InternalBuffer extends InternalObject
40 40
  {
41
  private static final int RECREATE = 1;
42
  private static final int UPDATE   = 2;
43

  
44
  private int mStatus;
41 45
  private final int[] mIndex;
42 46
  private int mTarget, mSize, mUsage;
43 47
  private Buffer mBuffer;
......
62 66

  
63 67
  public int createImmediatelyFloat(int size, float[] buffer)
64 68
    {
65
    if( mIndex[0]<0 )
69
    if( (mStatus & RECREATE) != 0 )
66 70
      {
67 71
      mSize= size;
68 72

  
......
84 88

  
85 89
      markWasCreatedImmediately();
86 90
      }
91
    else if( (mStatus & UPDATE) != 0 )
92
      {
93
      updateFloat(buffer);
94
      }
95

  
96
    mStatus = 0;
87 97

  
88 98
    return mIndex[0];
89 99
    }
......
93 103

  
94 104
  public int createImmediatelyInt(int size, int[] buffer)
95 105
    {
96
    if( mIndex[0]<0 )
106
    if( (mStatus & RECREATE) != 0 )
97 107
      {
98 108
      mSize= size;
99 109

  
......
115 125

  
116 126
      markWasCreatedImmediately();
117 127
      }
128
    else if( (mStatus & UPDATE) != 0  )
129
      {
130
      updateInt(buffer);
131
      }
132

  
133
    mStatus = 0;
118 134

  
119 135
    return mIndex[0];
120 136
    }
......
147 163

  
148 164
  public void invalidate()
149 165
    {
150
    recreate();
166
    mStatus |= UPDATE;
151 167
    }
152 168

  
153 169
///////////////////////////////////////////////////////////////////////////////////////////////////
......
155 171

  
156 172
  void create()
157 173
    {
158
    if( mIndex[0]<0 )
159
      {
160
      GLES30.glGenBuffers( 1, mIndex, 0);
161
      GLES30.glBindBuffer( mTarget, mIndex[0]);
162
      GLES30.glBufferData( mTarget, mSize, mBuffer, mUsage);
163
      GLES30.glBindBuffer( mTarget, 0);
164
      }
174
    GLES30.glGenBuffers( 1, mIndex, 0);
175
    GLES30.glBindBuffer( mTarget, mIndex[0]);
176
    GLES30.glBufferData( mTarget, mSize, mBuffer, mUsage);
177
    GLES30.glBindBuffer( mTarget, 0);
165 178
    }
166 179

  
167 180
///////////////////////////////////////////////////////////////////////////////////////////////////
......
169 182

  
170 183
  void delete()
171 184
    {
172
    if( mIndex[0]>=0 )
173
      {
174
      GLES30.glDeleteBuffers(1, mIndex, 0);
175
      mIndex[0] = -1;
176
      removeFromDone();
177
      }
185
    GLES30.glDeleteBuffers(1, mIndex, 0);
186
    mStatus |= RECREATE;
187
    removeFromDone();
178 188
    }
179 189

  
180 190
///////////////////////////////////////////////////////////////////////////////////////////////////
181 191

  
182
  void recreate()
192
  public void recreate()
183 193
    {
184
    mIndex[0] = -1;
194
    mStatus |= RECREATE;
185 195
    }
186 196

  
187 197
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff