Project

General

Profile

« Previous | Next » 

Revision 9b94626c

Added by Leszek Koltunski almost 6 years ago

Port some obvious stuff from OIT branch.

View differences:

src/main/java/org/distorted/library/main/Distorted.java
86 86
   *
87 87
   * https://community.arm.com/graphics/f/discussions/10285/opengl-es-3-1-on-mali-t880-flashes
88 88
   */
89
  public static final int FBO_QUEUE_SIZE = 3;
89
  public static final int FBO_QUEUE_SIZE = 4;
90 90

  
91 91
  private static boolean mInitialized=false;
92 92

  
......
142 142

  
143 143
///////////////////////////////////////////////////////////////////////////////////////////////////
144 144
/**
145
 * Call this so that the Library can mark OpenGL objects that would need to be recreated when we
146
 * get resumed.
145
 * Call this so that the Library can release the OpenGL related data that needs to be recreated.
147 146
 * Must be called from Activity.onPause().
148 147
 */
149 148
  public static void onPause()
......
172 171

  
173 172
    mInitialized = false;
174 173
    }
174

  
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176
/**
177
 * Return 2 or 3 depending if we have OpenGL Es 2.0 or 3.x context created.
178
 */
179
  public static int getGlVersion()
180
    {
181
    return GLSL == 300 ? 3:2;
182
    }
175 183
  }
src/main/java/org/distorted/library/main/DistortedEffects.java
334 334
    }
335 335

  
336 336
///////////////////////////////////////////////////////////////////////////////////////////////////
337
   
337

  
338 338
  private void releasePriv()
339 339
    {
340
    if( !matrixCloned   )   mM.abortAll(false);
341
    if( !vertexCloned   )   mV.abortAll(false);
342
    if( !fragmentCloned )   mF.abortAll(false);
343
    if( !postprocessCloned) mP.abortAll(false);
340
    if( !matrixCloned      ) mM.abortAll(false);
341
    if( !vertexCloned      ) mV.abortAll(false);
342
    if( !fragmentCloned    ) mF.abortAll(false);
343
    if( !postprocessCloned ) mP.abortAll(false);
344 344

  
345 345
    mM = null;
346 346
    mV = null;
......
352 352

  
353 353
  static void onDestroy()
354 354
    {
355
    mNextID = 0;
355
    mNextID =  0;
356 356
    }
357 357

  
358 358
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/main/DistortedOutputSurface.java
70 70
  private ArrayList<Job> mJobs = new ArrayList<>();
71 71

  
72 72
  // Global buffers used for postprocessing.
73
  private static DistortedOutputSurface[] mBuffer = null;
73
  private static DistortedOutputSurface[] mBuffer = new DistortedOutputSurface[EffectQuality.LENGTH];
74 74

  
75 75
  private float mFOV;
76 76
  float mDistance, mNear;
......
175 175

  
176 176
  private static void createPostprocessingBuffers(int width, int height, float near)
177 177
    {
178
    mBuffer = new DistortedOutputSurface[EffectQuality.LENGTH];
179 178
    float mipmap=1.0f;
180 179

  
181
    for(int j=0; j<EffectQuality.LENGTH; j++)
180
    for (int j=0; j<EffectQuality.LENGTH; j++)
182 181
      {
183 182
      mBuffer[j] = new DistortedFramebuffer(Distorted.FBO_QUEUE_SIZE,2,BOTH_DEPTH_STENCIL,TYPE_SYST, (int)(width*mipmap), (int)(height*mipmap) );
184 183
      mBuffer[j].mMipmap = mipmap;
185
      mBuffer[j].mNear   = near;  // copy mNear as well (for blitting- see PostprocessEffect.apply() )
186
      mBuffer[j].glClearColor(1.0f,1.0f,1.0f,0.0f);
184
      mBuffer[j].mNear = near;  // copy mNear as well (for blitting- see PostprocessEffect.apply() )
185
      mBuffer[j].glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
187 186

  
188 187
      mipmap *= EffectQuality.MULTIPLIER;
189 188
      }
......
192 191

  
193 192
    GLES31.glStencilMask(0xff);
194 193
    GLES31.glDepthMask(true);
195
    GLES31.glColorMask(true,true,true,true);
196
    GLES31.glClearColor(1.0f,1.0f,1.0f,0.0f);
194
    GLES31.glColorMask(true, true, true, true);
195
    GLES31.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
197 196
    GLES31.glClearDepthf(1.0f);
198 197
    GLES31.glClearStencil(0);
199 198

  
200
    for(int j=0; j<EffectQuality.LENGTH; j++)
199
    for (int j=0; j<EffectQuality.LENGTH; j++)
201 200
      {
202 201
      for(int k=0; k<Distorted.FBO_QUEUE_SIZE; k++)
203 202
        {
......
216 215

  
217 216
  static synchronized void onDestroy()
218 217
    {
219
    if( mBuffer!=null )
218
    for(int j=0; j<EffectQuality.LENGTH; j++)
220 219
      {
221
      for (int i=0; i<EffectQuality.LENGTH; i++)
222
        {
223
        mBuffer[i] = null;
224
        }
225

  
226
      mBuffer = null;
220
      mBuffer[j] = null;
227 221
      }
228 222
    }
229 223

  
......
341 335
        }
342 336
      else
343 337
        {
344
        if( mBuffer==null ) createPostprocessingBuffers(mWidth,mHeight,mNear);
338
        if( mBuffer[0]==null ) createPostprocessingBuffers(mWidth,mHeight,mNear);
345 339

  
346 340
        if( lastBucket!=currBucket )
347 341
          {
......
360 354

  
361 355
            numRenders += lastQueue.postprocess(mBuffer,fbo);
362 356
            numRenders += blitWithDepth(time, mBuffer[quality],fbo);
363

  
364
            mBuffer[quality].setAsOutputAndClear(time,fbo);
357
            mBuffer[quality].clearBuffer(time,fbo);
365 358
            }
366 359

  
367 360
          internalQuality = currQueue.getInternalQuality();
......
384 377
          numRenders += currQueue.postprocess(mBuffer,fbo);
385 378
          numRenders += blitWithDepth(time, mBuffer[quality],fbo);
386 379
          }
387
        } // end postprocessed child case
380
        } // end else (postprocessed child)
388 381

  
389 382
      lastQueue = currQueue;
390 383
      lastBucket= currBucket;
......
423 416
    }
424 417

  
425 418
///////////////////////////////////////////////////////////////////////////////////////////////////
426
/**
427
 * Bind this Surface as a Framebuffer we can render to; always clear it's color bit.
428
 *
429
 * Useful for drawing to the postprocessing buffer, which must sometimes be cleared multiple times
430
 * per frame.
431
 */
432
  private void setAsOutputAndClear(long time,int fbo)
419

  
420
  private void clearBuffer(long time,int fbo)
433 421
    {
434 422
    GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[fbo]);
435 423

  
......
578 566
 * <p>
579 567
 * This version does not attempt to clear anything.
580 568
 */
581

  
582 569
  public void setAsOutput()
583 570
    {
584 571
    GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[0]);
src/main/java/org/distorted/library/main/DistortedScreen.java
1 1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2018 Leszek Koltunski                                                               //
2
// Copyright 2016 Leszek Koltunski                                                               //
3 3
//                                                                                               //
4 4
// This file is part of Distorted.                                                               //
5 5
//                                                                                               //
......
55 55
  private static MatrixEffectMove mMoveEffect = new MatrixEffectMove( new Static3D(5,5,0) );
56 56
  ///// END DEBUGGING //////////////////////////
57 57

  
58
  private int mCurrFBO, mLastFBO;
58
  private int mCurRenderedFBO;    // During the first FBO_QUEUE_SIZE frames, we blit the very first
59
  private int mToBeBlittedFBO;    // FBO one we have rendered. Then, we keep blitting the one we
60
  private boolean mFirstCircle;   // rendered FBO_QUEUE_SIZE ago.
59 61

  
60 62
///////////////////////////////////////////////////////////////////////////////////////////////////
61 63
// PUBLIC API
......
69 71
    {
70 72
    super(Distorted.FBO_QUEUE_SIZE,1,BOTH_DEPTH_STENCIL, TYPE_SYST, 1,1);
71 73
    mShowFPS = false;
72
    mCurrFBO = 0;
73
    mLastFBO = 1;
74
    mCurRenderedFBO = 0;
75
    mToBeBlittedFBO = 0;
76
    mFirstCircle = true;
74 77
    }
75 78

  
76 79
///////////////////////////////////////////////////////////////////////////////////////////////////
......
84 87
 */
85 88
  public int render(long time)
86 89
    {
87
    if( ++mCurrFBO>=Distorted.FBO_QUEUE_SIZE ) mCurrFBO=0;
88
    if( ++mLastFBO>=Distorted.FBO_QUEUE_SIZE ) mLastFBO=0;
89

  
90 90
    if( mShowFPS )
91 91
      {
92 92
      if( lastTime==0 ) lastTime = time;
......
107 107
      lastTime = time;
108 108
      }
109 109

  
110
    int numrender = super.render(time,mCurrFBO);
110
    int numrender = super.render(time,mCurRenderedFBO);
111 111

  
112 112
    GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0);
113 113

  
......
116 116
    // make it equal to 3.
117 117
    // This of course introduces a delay and uses more memory, but it does not appear to have any effect
118 118
    // on speed. Maybe a slight positive effect if any!
119
    setAsInput(mLastFBO,0);
119
    setAsInput(mToBeBlittedFBO,0);
120 120

  
121 121
    GLES31.glColorMask(true,true,true,true);
122 122
    GLES31.glDepthMask(false);
......
131 131
      fpsEffects.drawPriv(fpsW / 2.0f, fpsH / 2.0f, fpsMesh, this, time, 0);
132 132
      }
133 133

  
134
    if( ++mCurRenderedFBO>=Distorted.FBO_QUEUE_SIZE )
135
      {
136
      mCurRenderedFBO = 0;
137
      if (mFirstCircle) mFirstCircle = false;
138
      }
139
    if( !mFirstCircle && ++mToBeBlittedFBO>=Distorted.FBO_QUEUE_SIZE )
140
      {
141
      mToBeBlittedFBO=0;
142
      }
143

  
134 144
    return numrender+1;
135 145
    }
136 146

  
......
169 179
      durations[NUM_FRAMES] = NUM_FRAMES * 16;              // close to 1000/16 ~ 60
170 180
      }
171 181
    }
172
  }
182
  }

Also available in: Unified diff