Project

General

Profile

« Previous | Next » 

Revision 66a0fa17

Added by Leszek Koltunski over 6 years ago

OIT: some progress

View differences:

src/main/java/org/distorted/library/main/DistortedOutputSurface.java
218 218
      }
219 219
    }
220 220

  
221
///////////////////////////////////////////////////////////////////////////////////////////////////
222

  
223
  private static void initializeOIT(DistortedOutputSurface surface)
224
    {
225
    if( mBufferOIT==null )
226
      {
227
      mBufferOIT = new DistortedFramebuffer(1, BOTH_DEPTH_STENCIL, TYPE_SYST, surface.mWidth, surface.mHeight);
228
      mBufferOIT.mMipmap = 1.0f;
229
      mBufferOIT.mNear = surface.mNear;  // copy mNear as well (for blitting- see PostprocessEffect.apply() )
230
      mBufferOIT.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
231

  
232
      DistortedObject.toDo(); // create the FBOs immediately. This is safe as we must be holding the OpenGL context now.
233

  
234
      mBufferOIT.setAsOutput();
235
      GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, mBufferOIT.mColorH[0], 0);
236
      GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT | GLES31.GL_DEPTH_BUFFER_BIT | GLES31.GL_STENCIL_BUFFER_BIT);
237
      }
238

  
239
    if( mBufferOIT.mWidth != surface.mWidth || mBufferOIT.mHeight != surface.mHeight )
240
      {
241
      mBufferOIT.mWidth  = (int)(surface.mWidth *mBufferOIT.mMipmap);
242
      mBufferOIT.mHeight = (int)(surface.mHeight*mBufferOIT.mMipmap);
243

  
244
      mBufferOIT.mNear   = surface.mNear;  // Near plane is independent of the mipmap level
245

  
246
      //android.util.Log.e("surface", "viewport "+i+" to ("+from.mWidth+"x"+from.mHeight+")");
247

  
248
      mBufferOIT.createProjection();
249

  
250
      int maxw = mBufferOIT.mWidth  > mBufferOIT.mRealWidth  ? mBufferOIT.mWidth  : mBufferOIT.mRealWidth;
251
      int maxh = mBufferOIT.mHeight > mBufferOIT.mRealHeight ? mBufferOIT.mHeight : mBufferOIT.mRealHeight;
252

  
253
      if (maxw > mBufferOIT.mRealWidth || maxh > mBufferOIT.mRealHeight)
254
        {
255
        mBufferOIT.mRealWidth = maxw;
256
        mBufferOIT.mRealHeight = maxh;
257

  
258
        mBufferOIT.recreate();
259
        mBufferOIT.create();
260
        }
261
      }
262

  
263
    if( mBufferOIT.mNear != surface.mNear || mBufferOIT.mFOV != surface.mFOV )
264
      {
265
      mBufferOIT.mNear = surface.mNear;
266
      mBufferOIT.mFOV  = surface.mFOV;
267
      mBufferOIT.createProjection();
268
      }
269

  
270
    GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mBufferOIT.mFBOH[0]);
271

  
272
    DistortedRenderState.colorDepthStencilOn();
273
    GLES31.glClearColor(surface.mClearR, surface.mClearG, surface.mClearB, surface.mClearA);
274
    GLES31.glClearDepthf(surface.mClearDepth);
275
    GLES31.glClearStencil(surface.mClearStencil);
276
    GLES31.glClear(surface.mClear);
277
    DistortedRenderState.colorDepthStencilRestore();
278

  
279
    DistortedEffects.zeroOutAtomic();
280
    DistortedEffects.oitClear(surface);
281

  
282
    GLES31.glMemoryBarrier(GLES31.GL_SHADER_STORAGE_BARRIER_BIT|GLES31.GL_ATOMIC_COUNTER_BARRIER_BIT);
283
    }
284

  
285 221
///////////////////////////////////////////////////////////////////////////////////////////////////
286 222

  
287 223
  static synchronized void onDestroy()
......
334 270
      }
335 271
    }
336 272

  
273
///////////////////////////////////////////////////////////////////////////////////////////////////
274

  
275
  private static void oitClear(DistortedOutputSurface buffer)
276
    {
277
    if( mBufferOIT==null )
278
      {
279
      mBufferOIT = new DistortedFramebuffer(1, BOTH_DEPTH_STENCIL, TYPE_SYST, buffer.mWidth, buffer.mHeight);
280
      mBufferOIT.mMipmap = 1.0f;
281
      mBufferOIT.mNear = buffer.mNear;  // copy mNear as well (for blitting- see PostprocessEffect.apply() )
282
      mBufferOIT.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
283

  
284
      DistortedObject.toDo(); // create the FBOs immediately. This is safe as we must be holding the OpenGL context now.
285
      }
286

  
287
    if( mBufferOIT.mWidth != buffer.mWidth || mBufferOIT.mHeight != buffer.mHeight )
288
      {
289
      mBufferOIT.mWidth  = (int)(buffer.mWidth *mBufferOIT.mMipmap);
290
      mBufferOIT.mHeight = (int)(buffer.mHeight*mBufferOIT.mMipmap);
291

  
292
      mBufferOIT.mNear   = buffer.mNear;  // Near plane is independent of the mipmap level
293

  
294
      //android.util.Log.e("surface", "viewport "+i+" to ("+from.mWidth+"x"+from.mHeight+")");
295

  
296
      mBufferOIT.createProjection();
297

  
298
      int maxw = mBufferOIT.mWidth  > mBufferOIT.mRealWidth  ? mBufferOIT.mWidth  : mBufferOIT.mRealWidth;
299
      int maxh = mBufferOIT.mHeight > mBufferOIT.mRealHeight ? mBufferOIT.mHeight : mBufferOIT.mRealHeight;
300

  
301
      if (maxw > mBufferOIT.mRealWidth || maxh > mBufferOIT.mRealHeight)
302
        {
303
        mBufferOIT.mRealWidth = maxw;
304
        mBufferOIT.mRealHeight = maxh;
305

  
306
        mBufferOIT.recreate();
307
        mBufferOIT.create();
308
        }
309
      }
310

  
311
    if( mBufferOIT.mNear != buffer.mNear || mBufferOIT.mFOV != buffer.mFOV )
312
      {
313
      mBufferOIT.mNear = buffer.mNear;
314
      mBufferOIT.mFOV  = buffer.mFOV;
315
      mBufferOIT.createProjection();
316
      }
317

  
318
    GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mBufferOIT.mFBOH[0]);
319
    DistortedRenderState.colorDepthStencilOn();
320
    GLES31.glClearColor(buffer.mClearR, buffer.mClearG, buffer.mClearB, buffer.mClearA);
321
    GLES31.glClearDepthf(buffer.mClearDepth);
322
    GLES31.glClearStencil(buffer.mClearStencil);
323
    GLES31.glClear(buffer.mClear);
324
    DistortedRenderState.colorDepthStencilRestore();
325

  
326
    DistortedEffects.zeroOutAtomic();
327
    DistortedEffects.oitClear(buffer);
328

  
329
    GLES31.glMemoryBarrier(GLES31.GL_SHADER_STORAGE_BARRIER_BIT|GLES31.GL_ATOMIC_COUNTER_BARRIER_BIT);
330
    }
331

  
337 332
///////////////////////////////////////////////////////////////////////////////////////////////////
338 333

  
339 334
  private int oitBuild(DistortedOutputSurface buffer)
......
387 382

  
388 383
///////////////////////////////////////////////////////////////////////////////////////////////////
389 384

  
390
  private void clearBuffer(DistortedOutputSurface buffer)
385
  private static void clearBuffer(DistortedOutputSurface buffer)
391 386
    {
392 387
    GLES31.glStencilMask(0xff);
393 388
    GLES31.glDepthMask(true);
......
397 392
    GLES31.glClearStencil(0);
398 393

  
399 394
    buffer.setAsOutput();
400
    GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, buffer.mColorH[1], 0);
395
    GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, buffer.mColorH[buffer.mNumColors-1], 0);
401 396
    GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT|GLES31.GL_DEPTH_BUFFER_BIT|GLES31.GL_STENCIL_BUFFER_BIT);
402
    GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, buffer.mColorH[0], 0);
403
    GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT);
397

  
398
    for(int i=buffer.mNumColors-2; i>=0; i--)
399
      {
400
      GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, buffer.mColorH[i], 0);
401
      GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT);
402
      }
404 403
    }
405 404

  
406 405
///////////////////////////////////////////////////////////////////////////////////////////////////
......
415 414
    EffectQueuePostprocess lastQueue=null, currQueue;
416 415
    long lastBucket=0, currBucket=0;
417 416

  
418
    initializeOIT(this);
417
    oitClear(this);
419 418

  
420 419
    for(int i=0; i<numChildren; i++)
421 420
      {

Also available in: Unified diff