Project

General

Profile

« Previous | Next » 

Revision f046b159

Added by Leszek Koltunski almost 4 years ago

First attempt at the MeshBase.apply(VertexEffect) API.

View differences:

src/main/java/org/distorted/library/main/DistortedLibrary.java
129 129
  private static int mBlitDepthH;
130 130
  private static final FloatBuffer mQuadPositions;
131 131

  
132
  /// FULL PROGRAM ///
133
  private static DistortedProgram mFullProgram;
134

  
132 135
  static
133 136
    {
134 137
    float[] positionData= { -0.5f, -0.5f,  -0.5f, 0.5f,  0.5f,-0.5f,  0.5f, 0.5f };
......
288 291
    mNormalMVPMatrixH  = GLES30.glGetUniformLocation( normalProgramH, "u_MVPMatrix");
289 292
    }
290 293

  
294
///////////////////////////////////////////////////////////////////////////////////////////////////
295

  
296
  private static void createFullProgram(Resources resources)
297
    {
298
    final InputStream fullVertStream = resources.openRawResource(R.raw.main_vertex_shader);
299
    final InputStream fullFragStream = resources.openRawResource(R.raw.main_fragment_shader);
300

  
301
    int numV = VertexEffect.getAllEnabled();
302

  
303
    String fullVertHeader= mGLSL_VERSION + ("#define NUM_VERTEX "   + ( numV>0 ? getMax(EffectType.VERTEX ) : 0 ) + "\n");
304
    String fullFragHeader= mGLSL_VERSION + ("#define NUM_FRAGMENT " +                                         0   + "\n");
305
    String enabledEffectV= VertexEffect.getAllGLSL();
306
    String enabledEffectF= "{}";
307

  
308
    String[] feedback = { "v_Position", "v_endPosition" };
309

  
310
    try
311
      {
312
      mFullProgram = new DistortedProgram(fullVertStream, fullFragStream, fullVertHeader, fullFragHeader,
313
                                          enabledEffectV, enabledEffectF, mGLSL, feedback);
314
      }
315
    catch(Exception e)
316
      {
317
      Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile FULL program: "+e.getMessage());
318
      throw new RuntimeException(e.getMessage());
319
      }
320

  
321
    int fullProgramH = mFullProgram.getProgramHandle();
322
    EffectQueue.getUniforms(fullProgramH,3);
323
    }
324

  
291 325
///////////////////////////////////////////////////////////////////////////////////////////////////
292 326

  
293 327
  private static void createProgramsOIT(Resources resources)
......
418 452
    GLES30.glEndTransformFeedback();
419 453
    GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);
420 454

  
421
    DistortedLibrary.mNormalProgram.useProgram();
422
    GLES30.glUniformMatrix4fv(DistortedLibrary.mNormalMVPMatrixH, 1, false, EffectQueue.getMVP(queues) , 0);
423
    mesh.bindTransformAttribs(DistortedLibrary.mNormalProgram);
455
    mNormalProgram.useProgram();
456
    GLES30.glUniformMatrix4fv(mNormalMVPMatrixH, 1, false, EffectQueue.getMVP(queues) , 0);
457
    mesh.bindTransformAttribs(mNormalProgram);
424 458
    GLES30.glLineWidth(8.0f);
425 459
    GLES30.glDrawArrays(GLES30.GL_LINES, 0, 2*num);
426 460
    }
427 461

  
462
///////////////////////////////////////////////////////////////////////////////////////////////////
463
// execute all VertexEffects and adjust all vertices
464

  
465
  public static void adjustVertices(MeshBase mesh)
466
    {
467
    if( mFullProgram!=null )
468
      {
469
      GLES30.glViewport(0, 0, 500, 500 ); // TODO ???
470

  
471
      int num = mesh.getNumVertices();
472
      int tfo = mesh.getTFO();
473

  
474
      mFullProgram.useProgram();
475
      mesh.bindVertexAttribs(mFullProgram);
476
      mesh.computeQueue();
477
      mesh.sendQueue();
478

  
479
      GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, tfo );
480
      GLES30.glBeginTransformFeedback( GLES30.GL_POINTS);
481
      InternalRenderState.switchOffDrawing();
482
      GLES30.glDrawArrays( GLES30.GL_POINTS, 0, num );
483
      InternalRenderState.restoreDrawing();
484
      GLES30.glEndTransformFeedback();
485
      GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);
486

  
487
      mesh.copyTransformToVertex();
488
      }
489
    }
490

  
428 491
///////////////////////////////////////////////////////////////////////////////////////////////////
429 492

  
430 493
  static void drawPrivOIT(DistortedEffects effects, MeshBase mesh, InternalOutputSurface surface, long currTime)
......
460 523

  
461 524
  static void drawPriv(DistortedEffects effects, MeshBase mesh, InternalOutputSurface surface, long currTime)
462 525
    {
463
    if( mMainOITProgram!=null )
526
    if( mMainProgram!=null )
464 527
      {
465 528
      EffectQueue[] queues = effects.getQueues();
466 529

  
......
824 887
      exception = ex;
825 888
      }
826 889

  
890
    try
891
      {
892
      createFullProgram(resources);
893
      }
894
    catch(Exception ex)
895
      {
896
      exception = ex;
897
      }
898

  
827 899
    if( mGLSL>=310)
828 900
      {
829 901
      try

Also available in: Unified diff