Project

General

Profile

« Previous | Next » 

Revision 984dc935

Added by Leszek Koltunski over 7 years ago

10% speedup with postprocessing.

View differences:

src/main/java/org/distorted/library/DistortedEffectsPostprocess.java
108 108
    return mP.mQualityLevel;
109 109
    }
110 110

  
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

  
113
  int getHalo()
114
    {
115
    return mP.getHalo();
116
    }
117

  
111 118
///////////////////////////////////////////////////////////////////////////////////////////////////
112 119

  
113 120
  static void onDestroy()
src/main/java/org/distorted/library/DistortedNode.java
259 259

  
260 260
///////////////////////////////////////////////////////////////////////////////////////////////////
261 261

  
262
  int markStencilAndDraw(long currTime, DistortedOutputSurface surface, int quality)
262
  int markStencilAndDraw(long currTime, DistortedOutputSurface surface, DistortedEffectsPostprocess effects)
263 263
    {
264 264
    DistortedInputSurface input = mNumChildren[0]==0 ? mSurface : mData.mFBO;
265 265

  
266 266
    if( input.setAsInput() )
267 267
      {
268
      int quality = effects.getQuality();
268 269
      DistortedFramebuffer buffer1 = surface.mBuffer1[quality];
269 270
      DistortedFramebuffer buffer2 = surface.mBuffer2[quality];
270 271
      float w = mSurface.getWidth() /2.0f;
271 272
      float h = mSurface.getHeight()/2.0f;
272 273

  
273
      // Mark area of our object + marginInPixels pixels around with 1s in Stencil buffer
274
      buffer2.setAsOutput(currTime);
275
      DistortedRenderState.setUpStencilMark();
276
      mEffects.drawPriv(w, h, mMesh, buffer2, currTime, EffectQueuePostprocess.MAX_BLUR*buffer2.mMipmap);
277

  
278 274
      // Actually draw our object.
279 275
      buffer1.setAsOutput(currTime);
280 276
      mState.apply();
281 277
      mEffects.drawPriv(w, h, mMesh, buffer1, currTime, 0);
278

  
279
      // Mark area of our object + marginInPixels pixels around with 1s in Stencil buffer
280
      buffer2.setAsOutput(currTime);
281
      DistortedRenderState.setUpStencilMark();
282
      mEffects.drawPriv(w, h, mMesh, buffer2, currTime, effects.getHalo()*buffer2.mMipmap);
283
      DistortedRenderState.unsetUpStencilMark();
284

  
282 285
      return 1;
283 286
      }
284 287
    return 0;
src/main/java/org/distorted/library/DistortedOutputSurface.java
200 200
          DistortedObject.toDo(); // create the FBOs immediately. This is safe as we must be holding the OpenGL context now.
201 201
          }
202 202

  
203
        int quality = currP.getQuality();
204
        numRenders += child.markStencilAndDraw(time,this,quality);
203
        numRenders += child.markStencilAndDraw(time,this,currP);
205 204

  
206 205
        if( i==num-1 )
207 206
          {
src/main/java/org/distorted/library/DistortedRenderState.java
164 164
    {
165 165
    if( cState.stencilTest!=1 )
166 166
      {
167
      sState.stencilTest = cState.stencilTest;
167 168
      cState.stencilTest = 1;
168 169
      //android.util.Log.d("State", "stencil test on");
169 170
      GLES30.glEnable(GLES30.GL_STENCIL_TEST);
170 171
      }
171 172
    if( cState.stencilFuncFunc!=GLES30.GL_ALWAYS || cState.stencilFuncRef!=1 || cState.stencilFuncMask!=STENCIL_MASK )
172 173
      {
174
      sState.stencilFuncFunc = cState.stencilFuncFunc;
175
      sState.stencilFuncRef  = cState.stencilFuncRef;
176
      sState.stencilFuncMask = cState.stencilFuncMask;
173 177
      cState.stencilFuncFunc = GLES30.GL_ALWAYS;
174 178
      cState.stencilFuncRef  = 1;
175 179
      cState.stencilFuncMask = STENCIL_MASK;
......
178 182
      }
179 183
    if( cState.stencilOpSfail!=GLES30.GL_KEEP || cState.stencilOpDpfail!=GLES30.GL_KEEP || cState.stencilOpDppass!=GLES30.GL_REPLACE )
180 184
      {
185
      sState.stencilOpSfail = cState.stencilOpSfail;
186
      sState.stencilOpDpfail= cState.stencilOpDpfail;
187
      sState.stencilOpDppass= cState.stencilOpDppass;
181 188
      cState.stencilOpSfail = GLES30.GL_KEEP;
182 189
      cState.stencilOpDpfail= GLES30.GL_KEEP;
183 190
      cState.stencilOpDppass= GLES30.GL_REPLACE;
......
186 193
      }
187 194
    if( cState.colorMaskR!=0 || cState.colorMaskG!=0 || cState.colorMaskB!=0 || cState.colorMaskA!=0 )
188 195
      {
196
      sState.colorMaskR = cState.colorMaskR;
197
      sState.colorMaskG = cState.colorMaskG;
198
      sState.colorMaskB = cState.colorMaskB;
199
      sState.colorMaskA = cState.colorMaskA;
189 200
      cState.colorMaskR = 0;
190 201
      cState.colorMaskG = 0;
191 202
      cState.colorMaskB = 0;
......
195 206
      }
196 207
    if( cState.depthMask!=0 )
197 208
      {
209
      sState.depthMask = cState.depthMask;
198 210
      cState.depthMask = 0;
199 211
      //android.util.Log.d("State", "switch off depth writing");
200 212
      GLES30.glDepthMask(false);
201 213
      }
202 214
    if( cState.stencilMask!= STENCIL_MASK )
203 215
      {
216
      sState.stencilMask = cState.stencilMask;
204 217
      cState.stencilMask = STENCIL_MASK;
205 218
      //android.util.Log.d("State", "stencil mask on");
206 219
      GLES30.glStencilMask(cState.stencilMask);
207 220
      }
208 221
    }
209 222

  
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224

  
225
  static void unsetUpStencilMark()
226
    {
227
    if( sState.stencilTest!=cState.stencilTest )
228
      {
229
      cState.stencilTest = sState.stencilTest;
230

  
231
      if (cState.stencilTest == 0)
232
        {
233
        GLES30.glDisable(GLES30.GL_STENCIL_TEST);
234
        }
235
      else
236
        {
237
        GLES30.glEnable(GLES30.GL_STENCIL_TEST);
238
        }
239
      }
240
    if( sState.colorMaskR!=cState.colorMaskR || sState.colorMaskG!=cState.colorMaskG || sState.colorMaskB!=cState.colorMaskB || sState.colorMaskA!=cState.colorMaskA)
241
      {
242
      cState.colorMaskR = sState.colorMaskR;
243
      cState.colorMaskG = sState.colorMaskG;
244
      cState.colorMaskB = sState.colorMaskB;
245
      cState.colorMaskA = sState.colorMaskA;
246
      GLES30.glColorMask(cState.colorMaskR==1,cState.colorMaskG==1,cState.colorMaskB==1,cState.colorMaskA==1);
247
      }
248
    if( sState.depthMask!=cState.depthMask )
249
      {
250
      cState.depthMask = sState.depthMask;
251
      GLES30.glDepthMask(cState.depthMask==1);
252
      }
253
    if( sState.stencilMask!=cState.stencilMask )
254
      {
255
      cState.stencilMask = sState.stencilMask;
256
      GLES30.glStencilMask(cState.stencilMask);
257
      }
258
    }
259

  
210 260
///////////////////////////////////////////////////////////////////////////////////////////////////
211 261

  
212 262
  static void useStencilMark()
src/main/java/org/distorted/library/EffectQueuePostprocess.java
257 257
      }
258 258
    }
259 259

  
260
///////////////////////////////////////////////////////////////////////////////////////////////////
261

  
262
  int getHalo()
263
    {
264
    return mNumEffects>0 ? (int)mUniforms[0] : 0;
265
    }
266

  
260 267
///////////////////////////////////////////////////////////////////////////////////////////////////
261 268

  
262 269
  int postprocess(long time, DistortedOutputSurface surface)
......
319 326

  
320 327
      // after each postprocess, clear the STENCIL
321 328
      buffer2.setAsOutput(time);
329
      GLES30.glStencilMask(0xff);
330
      GLES30.glClearStencil(0);
322 331
      GLES30.glClear(GLES30.GL_STENCIL_BUFFER_BIT);
323 332
      }
324 333

  

Also available in: Unified diff