Project

General

Profile

« Previous | Next » 

Revision d6e94c84

Added by Leszek Koltunski over 7 years ago

progress with Postprocessing.

View differences:

src/main/java/org/distorted/library/DistortedEffects.java
40 40
  private static long mNextID =0;
41 41
  private long mID;
42 42

  
43
  private EffectQueueMatrix    mM;
44
  private EffectQueueFragment  mF;
45
  private EffectQueueVertex    mV;
43
  private EffectQueueMatrix      mM;
44
  private EffectQueueFragment    mF;
45
  private EffectQueueVertex      mV;
46
  private EffectQueuePostprocess mP;
46 47

  
47
  private boolean matrixCloned, vertexCloned, fragmentCloned;
48
  private boolean matrixCloned, vertexCloned, fragmentCloned, postprocessCloned;
48 49

  
49 50
///////////////////////////////////////////////////////////////////////////////////////////////////
50 51
    
......
82 83
      mF = new EffectQueueFragment(mID);
83 84
      fragmentCloned = false;
84 85
      }
86

  
87
    if( (flags & Distorted.CLONE_POSTPROCESS) != 0 )
88
      {
89
      mP = d.mP;
90
      postprocessCloned = true;
91
      }
92
    else
93
      {
94
      mP = new EffectQueuePostprocess(mID);
95
      postprocessCloned = false;
96
      }
85 97
    }
86 98

  
87 99
///////////////////////////////////////////////////////////////////////////////////////////////////
88 100
   
89 101
  void drawPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedFramebuffer df, long currTime)
90 102
    {
91
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
92

  
93
    float halfZ = halfInputW*mesh.zFactor;
94

  
95 103
    mM.compute(currTime);
96
    mM.send(df,halfInputW,halfInputH,halfZ);
97
      
98 104
    mV.compute(currTime);
99
    mV.send(halfInputW,halfInputH,halfZ);
100
        
101 105
    mF.compute(currTime);
102
    mF.send(halfInputW,halfInputH);
106
    mP.compute(currTime);
103 107

  
104
    mesh.draw();
108
    float halfZ = halfInputW*mesh.zFactor;
109

  
110
    GLES20.glUseProgram(Distorted.mainProgramH);
111

  
112
    if( mP.mNumEffects==0 )
113
      {
114
      GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
115

  
116
      mM.send(df,halfInputW,halfInputH,halfZ);
117
      mV.send(halfInputW,halfInputH,halfZ);
118
      mF.send(halfInputW,halfInputH);
119

  
120
      mesh.draw();
121
      }
122
    else
123
      {
124
      DistortedFramebuffer fbo = null;
125
      // TODO : set this as output
126

  
127
      // render to the FBO just like above
128
      /*
129
      GLES20.glViewport(0, 0, fbo.mWidth, fbo.mHeight);
130

  
131
      mM.send(fbo,halfInputW,halfInputH,halfZ);
132
      mV.send(halfInputW,halfInputH,halfZ);
133
      mF.send(halfInputW,halfInputH);
134

  
135
      mesh.draw();
136
      */
137

  
138
      GLES20.glUseProgram(Distorted.postProgramH);
139

  
140
      // apply postprocess effects
141
      mP.postprocess(fbo,df);
142
      }
105 143
    }
106 144

  
107 145
///////////////////////////////////////////////////////////////////////////////////////////////////
108 146
   
109
  void drawNoEffectsPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedFramebuffer df)
147
  static void drawNoEffectsPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedFramebuffer df)
110 148
    {
111 149
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
112 150

  
113
    mM.sendZero(df,halfInputW,halfInputH,halfInputW*mesh.zFactor);
114
    mV.sendZero();
115
    mF.sendZero();
151
    EffectQueueMatrix.sendZero(df,halfInputW,halfInputH,halfInputW*mesh.zFactor);
152
    EffectQueueVertex.sendZero();
153
    EffectQueueFragment.sendZero();
154
    EffectQueuePostprocess.sendZero(2*halfInputW,2*halfInputH);
116 155

  
117 156
    mesh.draw();
118 157
    }
......
121 160
   
122 161
  private void releasePriv()
123 162
    {
124
    if( !matrixCloned  ) mM.abortAll(false);
125
    if( !vertexCloned  ) mV.abortAll(false);
126
    if( !fragmentCloned) mF.abortAll(false);
163
    if( !matrixCloned     ) mM.abortAll(false);
164
    if( !vertexCloned     ) mV.abortAll(false);
165
    if( !fragmentCloned   ) mF.abortAll(false);
166
    if( !postprocessCloned) mP.abortAll(false);
127 167

  
128 168
    mM = null;
129 169
    mV = null;
130 170
    mF = null;
171
    mP = null;
131 172
    }
132 173

  
133 174
///////////////////////////////////////////////////////////////////////////////////////////////////
......
197 238
    mV.registerForMessages(el);
198 239
    mF.registerForMessages(el);
199 240
    mM.registerForMessages(el);
241
    mP.registerForMessages(el);
200 242
    }
201 243

  
202 244
///////////////////////////////////////////////////////////////////////////////////////////////////
......
210 252
    mV.deregisterForMessages(el);
211 253
    mF.deregisterForMessages(el);
212 254
    mM.deregisterForMessages(el);
255
    mP.deregisterForMessages(el);
213 256
    }
214 257

  
215 258
///////////////////////////////////////////////////////////////////////////////////////////////////
......
219 262
 */
220 263
  public int abortAllEffects()
221 264
      {
222
      return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true);
265
      return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true) + mP.abortAll(true);
223 266
      }
224 267

  
225 268
///////////////////////////////////////////////////////////////////////////////////////////////////
......
233 276
    {
234 277
    switch(type)
235 278
      {
236
      case MATRIX  : return mM.abortAll(true);
237
      case VERTEX  : return mV.abortAll(true);
238
      case FRAGMENT: return mF.abortAll(true);
239
      default      : return 0;
279
      case MATRIX     : return mM.abortAll(true);
280
      case VERTEX     : return mV.abortAll(true);
281
      case FRAGMENT   : return mF.abortAll(true);
282
      case POSTPROCESS: return mP.abortAll(true);
283
      default         : return 0;
240 284
      }
241 285
    }
242 286
    
......
251 295
    {
252 296
    int type = (int)(id&EffectTypes.MASK);
253 297

  
254
    if( type==EffectTypes.MATRIX.type   ) return mM.removeByID(id>>EffectTypes.LENGTH);
255
    if( type==EffectTypes.VERTEX.type   ) return mV.removeByID(id>>EffectTypes.LENGTH);
256
    if( type==EffectTypes.FRAGMENT.type ) return mF.removeByID(id>>EffectTypes.LENGTH);
298
    if( type==EffectTypes.MATRIX.type      ) return mM.removeByID(id>>EffectTypes.LENGTH);
299
    if( type==EffectTypes.VERTEX.type      ) return mV.removeByID(id>>EffectTypes.LENGTH);
300
    if( type==EffectTypes.FRAGMENT.type    ) return mF.removeByID(id>>EffectTypes.LENGTH);
301
    if( type==EffectTypes.POSTPROCESS.type ) return mP.removeByID(id>>EffectTypes.LENGTH);
257 302

  
258 303
    return 0;
259 304
    }
......
269 314
    {
270 315
    switch(name.getType())
271 316
      {
272
      case MATRIX  : return mM.removeByType(name);
273
      case VERTEX  : return mV.removeByType(name);
274
      case FRAGMENT: return mF.removeByType(name);
275
      default      : return 0;
317
      case MATRIX     : return mM.removeByType(name);
318
      case VERTEX     : return mV.removeByType(name);
319
      case FRAGMENT   : return mF.removeByType(name);
320
      case POSTPROCESS: return mP.removeByType(name);
321
      default         : return 0;
276 322
      }
277 323
    }
278 324
    
......
288 334
    {
289 335
    int type = (int)(id&EffectTypes.MASK);
290 336

  
291
    if( type==EffectTypes.MATRIX.type   )  return mM.printByID(id>>EffectTypes.LENGTH);
292
    if( type==EffectTypes.VERTEX.type   )  return mV.printByID(id>>EffectTypes.LENGTH);
293
    if( type==EffectTypes.FRAGMENT.type )  return mF.printByID(id>>EffectTypes.LENGTH);
337
    if( type==EffectTypes.MATRIX.type      )  return mM.printByID(id>>EffectTypes.LENGTH);
338
    if( type==EffectTypes.VERTEX.type      )  return mV.printByID(id>>EffectTypes.LENGTH);
339
    if( type==EffectTypes.FRAGMENT.type    )  return mF.printByID(id>>EffectTypes.LENGTH);
340
    if( type==EffectTypes.POSTPROCESS.type )  return mP.printByID(id>>EffectTypes.LENGTH);
294 341

  
295 342
    return false;
296 343
    }
......
864 911
    {
865 912
    return mV.add(EffectNames.WAVE, wave, center, region);
866 913
    }
914

  
915
///////////////////////////////////////////////////////////////////////////////////////////////////
916
// Postprocess-based effects
917
///////////////////////////////////////////////////////////////////////////////////////////////////
918
/**
919
 * Blur the object.
920
 *
921
 * @param radius The 'strength' if the effect, in pixels. 0 = no blur, 10 = when blurring a given pixel,
922
 *               take into account 10 pixels in each direction.
923
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
924
 * @return ID of the effect added, or -1 if we failed to add one.
925
 */
926
  public long blur(Data1D radius, Data2D center)
927
    {
928
    return mP.add(EffectNames.BLUR, radius, center);
929
    }
867 930
  }

Also available in: Unified diff