Project

General

Profile

« Previous | Next » 

Revision b9798977

Added by Leszek Koltunski about 7 years ago

Advances in Multiblur - breaks BLUR for now.

View differences:

src/main/java/org/distorted/library/DistortedEffects.java
95 95
  private static long mNextID =0;
96 96
  private long mID;
97 97

  
98
  private static DistortedFramebuffer mBufferFBO = new DistortedFramebuffer(true,DistortedSurface.TYPE_SYST,1,1);
99

  
100 98
  private EffectQueueMatrix      mM;
101 99
  private EffectQueueFragment    mF;
102 100
  private EffectQueueVertex      mV;
......
281 279
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
282 280
    }
283 281

  
282
///////////////////////////////////////////////////////////////////////////////////////////////////
283

  
284
  DistortedFramebuffer getPostprocessingBuffer()
285
    {
286
    return mP.mNumEffects==0 ? null : mP.mMainBuffer;
287
    }
288

  
284 289
///////////////////////////////////////////////////////////////////////////////////////////////////
285 290

  
286 291
  void drawPriv(float halfW, float halfH, MeshObject mesh, DistortedOutputSurface surface, long currTime)
......
293 298
    float halfZ = halfW*mesh.zFactor;
294 299
    GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight);
295 300

  
296
    if( mP.mNumEffects==0 )
297
      {
298
      mMainProgram.useProgram();
299
      GLES30.glUniform1i(mMainTextureH, 0);
300
      surface.setAsOutput();
301
      mM.send(surface,halfW,halfH,halfZ);
302
      mV.send(halfW,halfH,halfZ);
303
      mF.send(halfW,halfH);
304
      GLES30.glVertexAttribPointer(mMainProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mesh.mMeshPositions);
305
      GLES30.glVertexAttribPointer(mMainProgram.mAttribute[1], NORMAL_DATA_SIZE  , GLES30.GL_FLOAT, false, 0, mesh.mMeshNormals);
306
      GLES30.glVertexAttribPointer(mMainProgram.mAttribute[2], TEX_DATA_SIZE     , GLES30.GL_FLOAT, false, 0, mesh.mMeshTexture);
307
      GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
308
      }
309
    else
310
      {
311
      if( mV.mNumEffects==0 && mF.mNumEffects==0 && (mesh instanceof MeshFlat) && mM.canUseShortcut() )
312
        {
313
        mM.constructMatrices(surface,halfW,halfH);
314
        mP.render(2*halfW, 2*halfH, mM.getMVP(), surface);
315
        }
316
      else
317
        {
318
        mMainProgram.useProgram();
319
        GLES30.glUniform1i(mMainTextureH, 0);
320
        mBufferFBO.resizeFast(surface.mWidth, surface.mHeight);
321
        mBufferFBO.setAsOutput();
322
        GLES30.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
323
        GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
324
        mM.send(mBufferFBO,halfW,halfH,halfZ);
325
        mV.send(halfW,halfH,halfZ);
326
        mF.send(halfW,halfH);
327
        GLES30.glVertexAttribPointer(mMainProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mesh.mMeshPositions);
328
        GLES30.glVertexAttribPointer(mMainProgram.mAttribute[1], NORMAL_DATA_SIZE  , GLES30.GL_FLOAT, false, 0, mesh.mMeshNormals);
329
        GLES30.glVertexAttribPointer(mMainProgram.mAttribute[2], TEX_DATA_SIZE     , GLES30.GL_FLOAT, false, 0, mesh.mMeshTexture);
330
        GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
331

  
332
        Matrix.setIdentityM(mTmpMatrix, 0);
333
        Matrix.translateM(mTmpMatrix, 0, 0, 0, -surface.mDistance);
334
        Matrix.multiplyMM(mMVPMatrix, 0, surface.mProjectionMatrix, 0, mTmpMatrix, 0);
335

  
336
        mBufferFBO.setAsInput();
337
        mP.render(surface.mWidth, surface.mHeight, mMVPMatrix, surface);
338
        }
339
      }
301
    mMainProgram.useProgram();
302
    GLES30.glUniform1i(mMainTextureH, 0);
303
    surface.setAsOutput();
304
    mM.send(surface,halfW,halfH,halfZ);
305
    mV.send(halfW,halfH,halfZ);
306
    mF.send(halfW,halfH);
307
    GLES30.glVertexAttribPointer(mMainProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mesh.mMeshPositions);
308
    GLES30.glVertexAttribPointer(mMainProgram.mAttribute[1], NORMAL_DATA_SIZE  , GLES30.GL_FLOAT, false, 0, mesh.mMeshNormals);
309
    GLES30.glVertexAttribPointer(mMainProgram.mAttribute[2], TEX_DATA_SIZE     , GLES30.GL_FLOAT, false, 0, mesh.mMeshTexture);
310
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
340 311

  
341 312
    /// DEBUG ONLY //////
342 313
    // displayBoundingRect(halfInputW, halfInputH, halfZ, df, mM.getMVP(), mesh.getBoundingVertices() );
src/main/java/org/distorted/library/DistortedFramebuffer.java
31 31
public class DistortedFramebuffer extends DistortedOutputSurface implements DistortedInputSurface
32 32
  {
33 33

  
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

  
36
  DistortedFramebuffer getBuffer()
37
    {
38
    return this;
39
    }
40

  
34 41
///////////////////////////////////////////////////////////////////////////////////////////////////
35 42
// Must be called from a thread holding OpenGL Context
36 43
// Watch out - this has the side-effect of binding a Texture and a Framebuffer!
src/main/java/org/distorted/library/DistortedNode.java
211 211
    return 0;
212 212
    }
213 213

  
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215

  
216
  DistortedFramebuffer getPostprocessingBuffer()
217
    {
218
    return mEffects.getPostprocessingBuffer();
219
    }
220

  
214 221
///////////////////////////////////////////////////////////////////////////////////////////////////
215 222
// return the total number of render calls issued
216 223

  
src/main/java/org/distorted/library/DistortedOutputSurface.java
39 39
  int[] mDepthH = new int[1];
40 40
  int[] mFBOH   = new int[1];
41 41

  
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

  
44
  abstract DistortedFramebuffer getBuffer();
45

  
42 46
///////////////////////////////////////////////////////////////////////////////////////////////////
43 47

  
44 48
  DistortedOutputSurface(int width, int height, int createColor, int createDepth, int fbo, int type)
......
105 109
  int renderChildren(long time, int num, ArrayList<DistortedNode> children)
106 110
    {
107 111
    int numRenders = 0;
112
    DistortedNode child;
113
    DistortedFramebuffer fbo;
114
    DistortedOutputSurface buffer;
115

  
116
    // 1. Render all children that have postprocessing effects to their own buffer FBOs
108 117

  
109 118
    for(int i=0; i<num; i++)
110 119
      {
111
      numRenders += children.get(i).draw(time,this);
120
      child = children.get(i);
121
      fbo   = child.getPostprocessingBuffer();
122

  
123
      if( fbo!=null )
124
        {
125
        fbo.resizeFast(mWidth,mHeight);
126
        numRenders += child.draw(time,fbo);
127
        }
128
      }
129

  
130
    // 2. If we have rendered anything so far, and we are a Screen, then render to an
131
    //    intermediate FBO instead.
132

  
133
    buffer = numRenders>0 ? getBuffer() : this;
134

  
135
    // 3. Render all children without postprocessing effects to buffer
136

  
137
    for(int i=0; i<num; i++)
138
      {
139
      child = children.get(i);
140
      fbo   = child.getPostprocessingBuffer();
141

  
142
      if( fbo==null )
143
        {
144
        numRenders += child.draw(time,buffer);
145
        }
146
      }
147

  
148
    // 4. For all postprocessing fbo,
149
    //       postprocess fbo
150
    //       merge to buffer
151

  
152
    // TODO
153

  
154
    // 5. finally blit to this if we have to
155

  
156
    if( buffer!=this && ((DistortedFramebuffer)buffer).setAsInput() )
157
      {
158
      numRenders++;
159
      DistortedEffects.blitPriv(this);
112 160
      }
113 161

  
114 162
    return numRenders;
src/main/java/org/distorted/library/DistortedScreen.java
27 27
 */
28 28
public class DistortedScreen extends DistortedOutputSurface
29 29
  {
30
  DistortedFramebuffer mBuffer = null;
31

  
30 32
///////////////////////////////////////////////////////////////////////////////////////////////////
31 33
// here we don't manage underlying OpenGL assets ourselves
32 34

  
......
34 36
  void delete()   {}
35 37
  void recreate() {}
36 38

  
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

  
41
  DistortedFramebuffer getBuffer()
42
    {
43
    if( mBuffer==null )
44
      {
45
      mBuffer = new DistortedFramebuffer(true,DistortedSurface.TYPE_SYST,mWidth,mHeight);
46
      }
47

  
48
    if( mBuffer.mWidth != mWidth || mBuffer.mHeight != mHeight )
49
      {
50
      mBuffer.resizeFast(mWidth,mHeight);
51
      }
52

  
53
    return mBuffer;
54
    }
55

  
37 56
///////////////////////////////////////////////////////////////////////////////////////////////////
38 57
// PUBLIC API
39 58
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/EffectQueuePostprocess.java
69 69
    mQuadTextureInv.put(textureInv).position(0);
70 70
    }
71 71

  
72
  private static DistortedFramebuffer mBufferFBO = new DistortedFramebuffer(true,DistortedSurface.TYPE_SYST,1,1);
72
  private static DistortedFramebuffer mPostBuffer = new DistortedFramebuffer(true,DistortedSurface.TYPE_SYST,1,1);
73
                 DistortedFramebuffer mMainBuffer = new DistortedFramebuffer(true,DistortedSurface.TYPE_SYST,1,1);
73 74

  
74 75
  private static float[] mMVPMatrix = new float[16];
75 76
  private static float[] mTmpMatrix = new float[16];
......
245 246
    GLES30.glUniform1i( mRadiusH, radius);
246 247
    GLES30.glUniform2f( mObjDH , w, h );
247 248

  
248
    mBufferFBO.resizeFast( (int)w, (int)h);
249
    mBufferFBO.setAsOutput();
249
    mPostBuffer.resizeFast( (int)w, (int)h);
250
    mPostBuffer.setAsOutput();
250 251
    GLES30.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
251 252
    GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
252 253
    GLES30.glViewport(0, 0, (int)w, (int)h);
253 254

  
254 255
    Matrix.setIdentityM(mTmpMatrix, 0);
255
    Matrix.translateM(mTmpMatrix, 0, 0, 0, -mBufferFBO.mDistance);
256
    Matrix.multiplyMM(mMVPMatrix, 0, mBufferFBO.mProjectionMatrix, 0, mTmpMatrix, 0);
256
    Matrix.translateM(mTmpMatrix, 0, 0, 0, -mPostBuffer.mDistance);
257
    Matrix.multiplyMM(mMVPMatrix, 0, mPostBuffer.mProjectionMatrix, 0, mTmpMatrix, 0);
257 258

  
258 259
    // horizontal blur
259 260
    GLES30.glUniform1fv( mOffsetsH ,radius+1, mOffsets,0);
......
262 263
    GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTextureInv);
263 264
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
264 265

  
265
    mBufferFBO.setAsInput();
266
    mPostBuffer.setAsInput();
266 267
    surface.setAsOutput();
267 268

  
268 269
    GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight);

Also available in: Unified diff