Project

General

Profile

« Previous | Next » 

Revision 60c1c622

Added by Leszek Koltunski about 7 years ago

Move the Postprocessing buffers to OutputSurface.

View differences:

src/main/java/org/distorted/library/DistortedOutputSurface.java
30 30
  private ArrayList<DistortedNode> mChildren;
31 31
  private int mNumChildren;   // ==mChildren.length(), but we only create mChildren if the first one gets added
32 32

  
33
  DistortedFramebuffer mBuffer1, mBuffer2;
34

  
33 35
  private long mTime;
34 36
  private float mFOV;
35 37
  int mWidth,mHeight,mDepth;
......
43 45
  private float mClearR, mClearG, mClearB, mClearA;
44 46
  private float mClearDepth;
45 47

  
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

  
48
  abstract DistortedFramebuffer getBuffer();
49

  
50 48
///////////////////////////////////////////////////////////////////////////////////////////////////
51 49

  
52 50
  DistortedOutputSurface(int width, int height, int createColor, int createDepth, int fbo, int type)
......
123 121
    {
124 122
    int numRenders = 0;
125 123
    DistortedNode child;
126
    DistortedFramebuffer fbo;
127
    DistortedOutputSurface surface;
124
    EffectQueuePostprocess lastP=null, currP=null;
125
    long lastB=0, currB=0;
128 126

  
129
    // 1. Render all children that have postprocessing effects to their own buffer FBOs
127
    // Render all children, one by one.
128
    // If there are no postprocessing effects, just render to THIS.
129
    // Otherwise, render to a buffer and on each change of Postprocessing Bucket,
130
    // apply the postprocessing to a whole buffer and merge it.
131
    //
132
    // TODO: in order for this to be efficient, the children really need to be sorted
133
    // to keep the same Buckets together.
130 134

  
131 135
    for(int i=0; i<num; i++)
132 136
      {
133 137
      child = children.get(i);
134
      fbo   = child.getPostprocessingBuffer();
138
      currP = child.getPostprocess();
139
      currB = currP.getBucket();
135 140

  
136
      if( fbo!=null )
141
      if( i>0 && currB!=lastB )
137 142
        {
138
        fbo.resizeFast(mWidth,mHeight);
139
        numRenders += child.draw(time,fbo);
143
        numRenders += lastP.postprocess(time,this);
140 144
        }
141
      }
142

  
143
    // 2. If we have rendered anything so far, and we are a Screen, then render to an
144
    //    intermediate FBO instead.
145

  
146
    surface = this;//numRenders>0 ? getBuffer() : this;
147

  
148
    // 3. Render all children without postprocessing effects to buffer
149

  
150
    for(int i=0; i<num; i++)
151
      {
152
      child = children.get(i);
153
      fbo   = child.getPostprocessingBuffer();
154 145

  
155
      if( fbo==null )
146
      if( currB==0 )
156 147
        {
157
        numRenders += child.draw(time,surface);
148
        numRenders += child.draw(time,this);
158 149
        }
159
      }
150
      else
151
        {
152
        if( mBuffer1==null )
153
          {
154
          mBuffer1 = new DistortedFramebuffer(mDepthCreated!=DONT_CREATE, DistortedSurface.TYPE_TREE, mWidth, mHeight);
155
          mBuffer2 = new DistortedFramebuffer(false                     , DistortedSurface.TYPE_TREE, mWidth, mHeight);
156
          }
160 157

  
161
    // 4. For all postprocessing fbo,
162
    //       postprocess fbo
163
    //       merge to buffer
158
        numRenders += child.draw(time,mBuffer1);
159
        }
164 160

  
165
    for(int i=0; i<num; i++)
166
      {
167
      numRenders += children.get(i).postprocess(time,surface);
161
      lastP = currP;
162
      lastB = currB;
168 163
      }
169 164

  
170
    // 5. finally blit to this if we have to
171

  
172
    if( surface!=this && ((DistortedFramebuffer)surface).setAsInput() )
165
    if( currB!=0 )
173 166
      {
174
      numRenders++;
175
      DistortedEffects.blitPriv(this);
167
      numRenders += currP.postprocess(time,this);
176 168
      }
177 169

  
178 170
    return numRenders;

Also available in: Unified diff