Project

General

Profile

« Previous | Next » 

Revision 2f35828c

Added by Leszek Koltunski about 6 years ago

- remove counting of transparent pixels from main fragment shader
- remove debugs and tidy up
- some fixes for the Mali GPU

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;
29
import java.nio.IntBuffer;
30 27
import java.util.ArrayList;
31 28

  
32 29
///////////////////////////////////////////////////////////////////////////////////////////////////
......
105 102
                    // mWidth,mHeight are the sizes of the Viewport, those -
106 103
                    // sizes of the backing up texture.
107 104

  
108
  ////////////////////////////////////////////////////////////////////////////////
109
  // section dealing with Shader Storage Buffer Object (for counting transparency)
110
  private static final int FRAME_DELAY = 3;
111
  private static int mBufferSize       =10;
112
  private static DistortedObjectCounter mSurfaceCounter = new DistortedObjectCounter();
113
  private static int[] mSSBO = new int[1];
114
  private static IntBuffer mIntBuffer;
115

  
116
  static
117
    {
118
    mSSBO[0]= -1;
119
    }
120

  
121
  private int mSurfaceID;
122
  private int mLastIndex;
123
  private int[] mLastValue = new int[FRAME_DELAY];
124
  private int mLastDiff = -1;
125

  
126
  private static final int RUNNING_AVERAGE = 10;
127
  private int[] mRunningAvg = new int[RUNNING_AVERAGE];
128
  private int mAvgIndex;
129
  private int mAvgSum;
130
  // end section
131
  ////////////////////////////////////////////////////////////////////////////////
132

  
133 105
///////////////////////////////////////////////////////////////////////////////////////////////////
134 106

  
135 107
  abstract void prepareDebug(long time);
136 108
  abstract void renderDebug(long time);
137
  abstract void createSurface();
138
  abstract void deleteSurface();
139
  abstract void recreateSurface();
140 109

  
141 110
///////////////////////////////////////////////////////////////////////////////////////////////////
142 111

  
......
175 144
    createProjection();
176 145
    }
177 146

  
178
///////////////////////////////////////////////////////////////////////////////////////////////////
179
// Must be called from a thread holding OpenGL Context
180

  
181
  void create()
182
    {
183
    if( mSSBO[0]<0 )
184
      {
185
      GLES31.glGenBuffers(1,mSSBO,0);
186

  
187
      // here bind the new SSBO and map it
188
      GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mSSBO[0]);
189
      GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, FRAME_DELAY *mBufferSize*4 , null, GLES31.GL_DYNAMIC_READ);
190
      ByteBuffer buf = (ByteBuffer) GLES31.glMapBufferRange(GLES31.GL_SHADER_STORAGE_BUFFER, 0, FRAME_DELAY *mBufferSize*4, GLES31.GL_MAP_READ_BIT );
191
      mIntBuffer = buf.order(ByteOrder.nativeOrder()).asIntBuffer();
192
      GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER,0, mSSBO[0]);
193
      }
194

  
195
    mSurfaceID = mSurfaceCounter.returnNext();
196

  
197
    if( mSurfaceID>=mBufferSize )
198
      {
199
      // increase size of the Buffer, copy over old values, remap.
200
      int[] tmp = new int[FRAME_DELAY *mBufferSize];
201
      for(int i = 0; i< FRAME_DELAY *mBufferSize; i++) tmp[i] = mIntBuffer.get(i);
202

  
203
      mBufferSize*= 2;
204

  
205
      GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 0, 0);
206
      GLES31.glUnmapBuffer(GLES31.GL_SHADER_STORAGE_BUFFER);
207
      GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER,0);
208

  
209
      GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mSSBO[0]);
210
      GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, FRAME_DELAY *mBufferSize*4 , null, GLES31.GL_DYNAMIC_READ);
211
      ByteBuffer buf = (ByteBuffer) GLES31.glMapBufferRange(GLES31.GL_SHADER_STORAGE_BUFFER, 0, FRAME_DELAY *mBufferSize*4, GLES31.GL_MAP_READ_BIT );
212
      mIntBuffer = buf.order(ByteOrder.nativeOrder()).asIntBuffer();
213
      GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER,0, mSSBO[0]);
214

  
215
      for(int i=0;i<tmp.length;i++) mIntBuffer.put(i,tmp[i]);
216
      }
217

  
218
    createSurface();
219
    }
220

  
221
///////////////////////////////////////////////////////////////////////////////////////////////////
222
// Must be called from a thread holding OpenGL Context
223

  
224
  void delete()
225
    {
226
    mSurfaceCounter.release(mSurfaceID);
227
    deleteSurface();
228
    }
229

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

  
232
  void recreate()
233
    {
234
    mSSBO[0]  = -1;
235
    mLastDiff = -1;
236

  
237
    for(int i = 0; i< FRAME_DELAY; i++) mLastValue[i] = 0;
238
    mSurfaceCounter.releaseAll();
239

  
240
    recreateSurface();
241
    }
242

  
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

  
245
  int getNewCounter()
246
    {
247
    return FRAME_DELAY*mSurfaceID + mLastIndex;
248
    }
249

  
250 147
///////////////////////////////////////////////////////////////////////////////////////////////////
251 148

  
252 149
  private void createProjection()
......
363 260
          surface.mRealWidth = maxw;
364 261
          surface.mRealHeight = maxh;
365 262

  
366
          surface.recreateSurface();
367
          surface.createSurface();
263
          surface.recreate();
264
          surface.create();
368 265
          }
369 266
        }
370 267
      }
......
634 531
      GLES31.glClearStencil(mClearStencil);
635 532
      GLES31.glClear(mClear);
636 533
      DistortedRenderState.colorDepthStencilRestore();
637
/*
638
      if( mSSBO[0]>=0 )
639
        {
640
        // yes, this DOES keep on working when 'value' overflows into negative territory.
641
        int value = mIntBuffer.get(FRAME_DELAY*mSurfaceID+mLastIndex);
642

  
643
        if( value-mLastValue[mLastIndex]!=mLastDiff )
644
          {
645
          android.util.Log.d("surface", "id " + mSurfaceID +
646
                             (mType == TYPE_USER ? " USER" : (mType == TYPE_SYST ? " SYST" : " TREE")) +
647
                             " viewport: (" + mWidth + "x" + mHeight + ") last frame: " + (value - mLastValue[mLastIndex])
648
                             + " avg: " + (mAvgSum/RUNNING_AVERAGE)
649
                            );
650
          }
651

  
652
        mLastDiff = value-mLastValue[mLastIndex];
653
        mLastValue[mLastIndex] = value;
654

  
655
        mAvgSum += (mLastDiff-mRunningAvg[mAvgIndex]);
656
        mRunningAvg[mAvgIndex] = mLastDiff;
657
        if( ++mAvgIndex>=RUNNING_AVERAGE ) mAvgIndex =0;
658
        }
659

  
660
      if( ++mLastIndex >= FRAME_DELAY ) mLastIndex=0;
661
*/
662 534
      }
663 535
    }
664 536

  

Also available in: Unified diff