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
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/mesh/MeshBase.java
180 180
     mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER, GLES30.GL_STATIC_READ);
181 181
     mVertAttribs1= new float[mNumVertices*VERT1_ATTRIBS];
182 182
     System.arraycopy(original.mVertAttribs1,0,mVertAttribs1,0,mNumVertices*VERT1_ATTRIBS);
183
     mVBO1.invalidate();
184 183
     }
185 184

  
186 185
///////////////////////////////////////////////////////////////////////////////////////////////////
......
202 201
     mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER, GLES30.GL_STATIC_READ);
203 202
     mVertAttribs2= new float[mNumVertices*VERT2_ATTRIBS];
204 203
     System.arraycopy(original.mVertAttribs2,0,mVertAttribs2,0,mNumVertices*VERT2_ATTRIBS);
205
     mVBO2.invalidate();
206 204
     }
207 205

  
208 206
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/mesh/UniformBlockAssociation.java
63 63

  
64 64
///////////////////////////////////////////////////////////////////////////////////////////////////
65 65

  
66
   boolean matchesAssociation( int comp, int andAssoc, int equAssoc)
67
     {
68
     return (andAssoc & mAssociations[4*comp]) != 0 || (equAssoc == mAssociations[4*comp+2]);
69
     }
66
  boolean matchesAssociation( int comp, int andAssoc, int equAssoc)
67
    {
68
    return (andAssoc & mAssociations[4*comp]) != 0 || (equAssoc == mAssociations[4*comp+2]);
69
    }
70 70

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

  
73
   void setEffectAssociationNow(int comp, int andAssociation, int equAssociation)
74
     {
75
     mAssociations[4*comp  ] = andAssociation;
76
     mAssociations[4*comp+2] = equAssociation;
73
  void setEffectAssociationNow(int comp, int andAssociation, int equAssociation)
74
    {
75
    mAssociations[4*comp  ] = andAssociation;
76
    mAssociations[4*comp+2] = equAssociation;
77 77

  
78
     mUBO.invalidate();
79
     }
78
    mUBO.invalidate();
79
    }
80 80

  
81 81
///////////////////////////////////////////////////////////////////////////////////////////////////
82 82

  
83
   int getIndex()
84
     {
85
     return mUBO.createImmediatelyInt( BLOCK_SIZE, mAssociations);
86
     }
83
  int getIndex()
84
    {
85
    return mUBO.createImmediatelyInt( BLOCK_SIZE, mAssociations);
86
    }
87 87

  
88 88
///////////////////////////////////////////////////////////////////////////////////////////////////
89 89

  
90
   void copy(int compTo, UniformBlockAssociation assocFrom, int compFrom)
91
     {
92
     mAssociations[4*compTo  ] = assocFrom.mAssociations[4*compFrom  ];
93
     mAssociations[4*compTo+2] = assocFrom.mAssociations[4*compFrom+2];
94
     }
90
  void copy(int compTo, UniformBlockAssociation assocFrom, int compFrom)
91
    {
92
    mAssociations[4*compTo  ] = assocFrom.mAssociations[4*compFrom  ];
93
    mAssociations[4*compTo+2] = assocFrom.mAssociations[4*compFrom+2];
94
    }
95

  
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97

  
98
  void print()
99
    {
100
    StringBuilder builder = new StringBuilder();
101

  
102
    builder.append(mUBO.getID());
103
    builder.append(' ');
104

  
105
    for(int i=0; i<8; i++)
106
      {
107
      builder.append(mAssociations[4*i]);
108
      builder.append(' ');
109
      builder.append(mAssociations[4*i+2]);
110
      builder.append(' ');
111
      }
112

  
113
    String res = builder.toString();
114

  
115
    android.util.Log.e("uba", res);
116
    }
95 117
  }

Also available in: Unified diff