Project

General

Profile

« Previous | Next » 

Revision 5f7e4f2c

Added by Leszek Koltunski almost 6 years ago

Hide the FBO_QUEUE thing inside the library. The queue is running internally now, without public setAsOutputFBO() thing (simplifies writing postprocess effects)

View differences:

src/main/java/org/distorted/library/main/DistortedOutputSurface.java
94 94
                    // mWidth,mHeight are the sizes of the Viewport, those -
95 95
                    // sizes of the backing up texture.
96 96

  
97
  int mCurrFBO;     // internal current FBO (see Distorted.FBO_QUEUE_SIZE)
98

  
97 99
///////////////////////////////////////////////////////////////////////////////////////////////////
98 100

  
99 101
  DistortedOutputSurface(int width, int height, int createColor, int numfbos, int numcolors, int depthStencil, int fbo, int type)
......
101 103
    super(width,height,createColor,numfbos,numcolors,type);
102 104

  
103 105
    mRenderWayOIT = false;
106
    mCurrFBO      = 0;
104 107

  
105 108
    mDepthStencilH = new int[numfbos];
106 109
    mFBOH          = new int[numfbos];
......
275 278
  private int blitWithDepth(long currTime, DistortedOutputSurface buffer,int fbo)
276 279
    {
277 280
    GLES31.glViewport(0, 0, mWidth, mHeight);
278
    setAsOutputFBO(currTime,fbo);
281
    setAsOutput(currTime);
279 282
    GLES31.glActiveTexture(GLES31.GL_TEXTURE0);
280 283
    GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, buffer.mColorH[2*fbo]);
281 284
    GLES31.glActiveTexture(GLES31.GL_TEXTURE1);
......
298 301
    GLES31.glClearDepthf(1.0f);
299 302
    GLES31.glClearStencil(0);
300 303

  
301
    buffer.setAsOutputFBO(fbo);
304
    buffer.setAsOutput();
302 305
    GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, buffer.mColorH[2*fbo+1], 0);
303 306
    GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT|GLES31.GL_DEPTH_BUFFER_BIT|GLES31.GL_STENCIL_BUFFER_BIT);
304 307
    GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, buffer.mColorH[2*fbo  ], 0);
......
321 324
  private int oitBuild(long time, DistortedOutputSurface buffer, int fbo)
322 325
    {
323 326
    GLES31.glViewport(0, 0, mWidth, mHeight);
324
    setAsOutputFBO(time,fbo);
327
    setAsOutput(time);
325 328
    GLES31.glActiveTexture(GLES31.GL_TEXTURE0);
326 329
    GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, buffer.mColorH[2*fbo]);
327 330
    GLES31.glActiveTexture(GLES31.GL_TEXTURE1);
......
363 366
      GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, 0);
364 367
      }
365 368

  
366
    setAsOutputFBO(currTime,fbo);
369
    setAsOutput(currTime);
367 370
    DistortedRenderState.switchColorDepthOnStencilOff();
368 371
    DistortedEffects.oitRender(this, corrW, corrH);
369 372
    DistortedRenderState.restoreColorDepthStencil();
......
383 386
    DistortedRenderState.colorDepthStencilRestore();
384 387
    }
385 388

  
389
///////////////////////////////////////////////////////////////////////////////////////////////////
390

  
391
  void setCurrFBO(int fbo)
392
    {
393
    mCurrFBO = fbo;
394
    }
395

  
386 396
///////////////////////////////////////////////////////////////////////////////////////////////////
387 397
// Render all children, one by one. If there are no postprocessing effects, just render to THIS.
388 398
// Otherwise, render to a buffer and on each change of Postprocessing Bucket, apply the postprocessing
......
395 405
    EffectQueuePostprocess lastQueue=null, currQueue;
396 406
    long lastBucket=0, currBucket;
397 407

  
408
    setCurrFBO(fbo);
409

  
410
    if( mBuffer!=null )
411
      {
412
      for (int i=0; i<EffectQuality.LENGTH; i++)
413
        {
414
        mBuffer[i].setCurrFBO(fbo);
415
        }
416
      }
417

  
398 418
    if( oit && numChildren>0 )
399 419
      {
400 420
      oitClear(this);
......
408 428

  
409 429
      if( currBucket==0 )
410 430
        {
411
        setAsOutputFBO(time,fbo);
431
        setAsOutput(time);
412 432

  
413 433
        if( oit )
414 434
          {
......
422 442
        }
423 443
      else
424 444
        {
425
        if( mBuffer==null ) createPostprocessingBuffers(mWidth,mHeight,mNear);
445
        if( mBuffer==null )
446
          {
447
          createPostprocessingBuffers(mWidth,mHeight,mNear);
448

  
449
          for (int j=0; j<EffectQuality.LENGTH; j++)
450
            {
451
            mBuffer[j].setCurrFBO(fbo);
452
            }
453
          }
426 454

  
427 455
        if( lastBucket!=currBucket )
428 456
          {
......
435 463
            for(int j=bucketChange; j<i; j++)
436 464
              {
437 465
              child2 = children.get(j);
438
              mBuffer[internalQuality].setAsOutputFBO(fbo);
466
              mBuffer[internalQuality].setAsOutput();
439 467
              numRenders += child2.markStencilAndDepth(time,mBuffer[internalQuality],lastQueue);
440 468
              }
441 469

  
442
            numRenders += lastQueue.postprocess(mBuffer,fbo);
470
            numRenders += lastQueue.postprocess(mBuffer);
443 471

  
444 472
            if( oit )
445 473
              {
......
458 486
          bucketChange    = i;
459 487
          }
460 488

  
461
        mBuffer[quality].setAsOutputFBO(time,fbo);
489
        mBuffer[quality].setAsOutput(time);
462 490
        child1.drawNoBlend(time,mBuffer[quality]);
463 491

  
464 492
        if( i==numChildren-1 )
......
466 494
          for(int j=bucketChange; j<numChildren; j++)
467 495
            {
468 496
            child2 = children.get(j);
469
            mBuffer[internalQuality].setAsOutputFBO(fbo);
497
            mBuffer[internalQuality].setAsOutput();
470 498
            numRenders += child2.markStencilAndDepth(time,mBuffer[internalQuality],currQueue);
471 499
            }
472 500

  
473
          numRenders += currQueue.postprocess(mBuffer,fbo);
501
          numRenders += currQueue.postprocess(mBuffer);
474 502

  
475 503
          if( oit )
476 504
            {
......
545 573
    DistortedRenderState.colorDepthStencilRestore();
546 574
    }
547 575

  
548
///////////////////////////////////////////////////////////////////////////////////////////////////
549

  
550
  private void setAsOutputFBO(long time, int fbo)
551
    {
552
    if( fbo>=0 && fbo<mNumFBOs )
553
      {
554
      GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[fbo]);
555

  
556
      if (mTime[fbo] != time)
557
        {
558
        mTime[fbo] = time;
559
        clear();
560
        }
561
      }
562
    else
563
      {
564
      android.util.Log.e("surface", "error in setAsOutput1, fbo="+fbo);
565
      }
566
    }
567

  
568
///////////////////////////////////////////////////////////////////////////////////////////////////
569
/**
570
 * Not part of the Public API.
571
 *
572
 * @y.exclude
573
 */
574
  public void setAsOutputFBO(int fbo)
575
    {
576
    if( fbo>=0 && fbo<mNumFBOs )
577
      {
578
      GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[fbo]);
579
      }
580
    else
581
      {
582
      android.util.Log.e("surface", "error in setAsOutput2, fbo="+fbo);
583
      }
584
    }
585

  
586 576
///////////////////////////////////////////////////////////////////////////////////////////////////
587 577
// PUBLIC API
588 578
///////////////////////////////////////////////////////////////////////////////////////////////////
......
668 658
 */
669 659
  public void setAsOutput(long time)
670 660
    {
671
    GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[0]);
661
    GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[mCurrFBO]);
672 662

  
673
    if( mTime[0]!=time )
663
    if( mTime[mCurrFBO]!=time )
674 664
      {
675
      mTime[0] = time;
665
      mTime[mCurrFBO] = time;
676 666
      clear();
677 667
      }
678 668
    }
......
685 675
 */
686 676
  public void setAsOutput()
687 677
    {
688
    GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[0]);
678
    GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[mCurrFBO]);
689 679
    }
690 680

  
691 681
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff