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/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]);

Also available in: Unified diff