Project

General

Profile

« Previous | Next » 

Revision 12f45260

Added by Leszek Koltunski about 6 years ago

First try at the SSBO (doesn't work - reads in the application don't pick up changes in the shader; crashes.

View differences:

src/main/java/org/distorted/library/main/DistortedOutputSurface.java
24 24

  
25 25
import org.distorted.library.effect.EffectQuality;
26 26

  
27
import java.nio.ByteBuffer;
28
import java.nio.ByteOrder;
27 29
import java.util.ArrayList;
28 30

  
29 31
///////////////////////////////////////////////////////////////////////////////////////////////////
......
96 98

  
97 99
  private int mDebugLevel;
98 100

  
101
  ////////////////////////////////////////////////////////////////////////////////
102
  // section dealing with Shader Storage Buffer Object (for counting transparency)
103
  private static final int BUFFERING = 3;
104
  private static int mBufferSize     =10;
105
  private static DistortedObjectCounter mSurfaceCounter = new DistortedObjectCounter();
106
  private static int[] mSSBO = new int[1];
107
  private static ByteBuffer mSSBOBuffer;
108

  
109
  static
110
    {
111
    mSSBO[0]    = -1;
112
    mSSBOBuffer = ByteBuffer.allocateDirect(BUFFERING*mBufferSize*4).order(ByteOrder.nativeOrder());
113
    }
114

  
115
  private int mSurfaceID;
116
  private int mLastIndex;
117

  
118
  // end section
119
  ////////////////////////////////////////////////////////////////////////////////
120

  
99 121
///////////////////////////////////////////////////////////////////////////////////////////////////
100 122

  
101 123
  abstract void prepareDebug(long time);
102 124
  abstract void renderDebug(long time);
125
  abstract void createSurface();
126
  abstract void deleteSurface();
127
  abstract void recreateSurface();
103 128

  
104 129
///////////////////////////////////////////////////////////////////////////////////////////////////
105 130

  
......
137 162
    createProjection();
138 163
    }
139 164

  
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166
// Must be called from a thread holding OpenGL Context
167

  
168
  void create()
169
    {
170
    if( mSSBO[0]<0 )
171
      {
172
      GLES31.glGenBuffers(1,mSSBO,0);
173

  
174
      // here bind the new SSBO and map it
175
      GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mSSBO[0]);
176
      GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, BUFFERING*mBufferSize*4 , null, GLES31.GL_DYNAMIC_READ);
177
      mSSBOBuffer = (ByteBuffer) GLES31.glMapBufferRange(GLES31.GL_SHADER_STORAGE_BUFFER, 0, BUFFERING*mBufferSize*4, GLES31.GL_MAP_WRITE_BIT | GLES31.GL_MAP_WRITE_BIT );
178
      GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER,1, mSSBO[0]);
179
      }
180

  
181
    mSurfaceID = mSurfaceCounter.returnNext();
182

  
183
    if( mSurfaceID>=mBufferSize )
184
      {
185
      // increase the size of mSSBOBuffer, copy over old values, remap.
186
      // TODO (don't need this if there are never more than mBufferSize=10 Surfaces)
187
      }
188

  
189
    createSurface();
190
    }
191

  
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193
// Must be called from a thread holding OpenGL Context
194

  
195
  void delete()
196
    {
197
    mSurfaceCounter.release(mSurfaceID);
198
    deleteSurface();
199
    }
200

  
201
///////////////////////////////////////////////////////////////////////////////////////////////////
202

  
203
  void recreate()
204
    {
205
    mSSBO[0] = -1;
206
    mSurfaceCounter.releaseAll();
207
    recreateSurface();
208
    }
209

  
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211

  
212
  int resetNewCounter()
213
    {
214
    //mSSBOBuffer.putInt(BUFFERING*mSurfaceID+mLastIndex,0);
215
    return BUFFERING*mSurfaceID + mLastIndex;
216
    }
217

  
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219

  
220
  int returnOldCounter()
221
    {
222
    int ret = mSSBOBuffer.getInt(BUFFERING*mSurfaceID+mLastIndex);
223

  
224
    mLastIndex++;
225
    if( mLastIndex>=BUFFERING ) mLastIndex-=BUFFERING;
226

  
227
    return ret;
228
    }
229

  
230
///////////////////////////////////////////////////////////////////////////////////////////////////
231

  
232
  int returnCounter()
233
    {
234
    return mSSBOBuffer.getInt(0);
235
    }
236

  
140 237
///////////////////////////////////////////////////////////////////////////////////////////////////
141 238

  
142 239
  private void createProjection()

Also available in: Unified diff