Project

General

Profile

« Previous | Next » 

Revision da9b3f07

Added by Leszek Koltunski almost 7 years ago

Progress with support for Effect classes.

The library compiles now!

View differences:

src/main/java/org/distorted/library/main/DistortedEffects.java
24 24

  
25 25
import org.distorted.library.R;
26 26
import org.distorted.library.effect.Effect;
27
import org.distorted.library.effect.EffectName;
28
import org.distorted.library.effect.EffectType;
27 29
import org.distorted.library.message.EffectListener;
28 30
import org.distorted.library.program.DistortedProgram;
29 31
import org.distorted.library.program.FragmentCompilationException;
......
50 52
  /// MAIN PROGRAM ///
51 53
  private static DistortedProgram mMainProgram;
52 54
  private static int mMainTextureH;
53
  private static ArrayList<Effect> mEnabledEffects = new ArrayList<>();
55
  private static ArrayList<EffectName> mEnabledEffects = new ArrayList<>();
54 56

  
55 57
  /// BLIT PROGRAM ///
56 58
  private static DistortedProgram mBlitProgram;
......
99 101

  
100 102
    boolean foundF = false;
101 103
    boolean foundV = false;
102
    int type, effects = mEnabledEffects.size();
103
    Effect effect;
104
    int effects = mEnabledEffects.size();
105
    EffectName effect;
106
    EffectType type;
104 107

  
105 108
    for(int i=0; i<effects; i++)
106 109
      {
107 110
      effect = mEnabledEffects.remove(0);
108 111
      type   = effect.getType();
109 112

  
110
      if( type == Effect.VERTEX )
113
      if( type == EffectType.VERTEX )
111 114
        {
112
        mainVertHeader += ("#define "+effect.getString()+" "+effect.getName()+"\n");
115
        mainVertHeader += ("#define "+effect.name()+" "+effect.ordinal()+"\n");
113 116
        foundV = true;
114 117
        }
115
      else if( type == Effect.FRAGMENT )
118
      else if( type == EffectType.FRAGMENT )
116 119
        {
117
        mainFragHeader += ("#define "+effect.getString()+" "+effect.getName()+"\n");
120
        mainFragHeader += ("#define "+effect.name()+" "+effect.ordinal()+"\n");
118 121
        foundF = true;
119 122
        }
120 123
      }
......
433 436
/**
434 437
 * Aborts all Effects of a given type, for example all MATRIX Effects.
435 438
 * 
436
 * @param type one of the constants defined in {@link Effect}
439
 * @param type one of the constants defined in {@link EffectType}
437 440
 * @return Number of effects aborted.
438 441
 */
439
  public int abortByType(int type)
442
  public int abortByType(EffectType type)
440 443
    {
441 444
    switch(type)
442 445
      {
443
      case Effect.MATRIX     : return mM.abortAll(true);
444
      case Effect.VERTEX     : return mV.abortAll(true);
445
      case Effect.FRAGMENT   : return mF.abortAll(true);
446
  //  case Effect.POSTPROCESS: return mP.abortAll(true);
447
      default                : return 0;
446
      case MATRIX     : return mM.abortAll(true);
447
      case VERTEX     : return mV.abortAll(true);
448
      case FRAGMENT   : return mF.abortAll(true);
449
  //  case POSTPROCESS: return mP.abortAll(true);
450
      default         : return 0;
448 451
      }
449 452
    }
450 453
    
......
459 462
    {
460 463
    switch(effect.getType())
461 464
      {
462
      case Effect.MATRIX     : return mM.removeEffect(effect);
463
      case Effect.VERTEX     : return mV.removeEffect(effect);
464
      case Effect.FRAGMENT   : return mF.removeEffect(effect);
465
  //  case Effect.POSTPROCESS: return mP.removeEffect(effect);
466
      default                : return 0;
465
      case MATRIX     : return mM.removeEffect(effect);
466
      case VERTEX     : return mV.removeEffect(effect);
467
      case FRAGMENT   : return mF.removeEffect(effect);
468
  //  case POSTPROCESS: return mP.removeEffect(effect);
469
      default         : return 0;
467 470
      }
468 471
    }
469 472

  
......
471 474
/**
472 475
 * Abort all Effects of a given name, for example all rotations.
473 476
 * 
474
 * @param name one of the constants defined in
475
 *             {@link org.distorted.library.effect.MatrixEffect},
476
 *             {@link org.distorted.library.effect.VertexEffect},
477
 *             {@link org.distorted.library.effect.FragmentEffect} or
478
 *             {@link org.distorted.library.effect.PostprocessEffect}
477
 * @param name one of the constants defined in {@link EffectName}
479 478
 * @return number of Effects aborted.
480 479
 */
481
  public int abortByName(int name)
480
  public int abortByName(EffectName name)
482 481
    {
483
    switch(Effect.getType(name))
482
    switch(name.getType())
484 483
      {
485
      case Effect.MATRIX     : return mM.removeByName(name);
486
      case Effect.VERTEX     : return mV.removeByName(name);
487
      case Effect.FRAGMENT   : return mF.removeByName(name);
488
  //  case Effect.POSTPROCESS: return mP.removeByName(name);
484
      case MATRIX     : return mM.removeByName(name);
485
      case VERTEX     : return mV.removeByName(name);
486
      case FRAGMENT   : return mF.removeByName(name);
487
  //  case POSTPROCESS: return mP.removeByName(name);
489 488
      default                : return 0;
490 489
      }
491 490
    }
......
498 497
 * This needs to be called BEFORE shaders get compiled, i.e. before the call to Distorted.onCreate().
499 498
 * The point: by enabling only the effects we need, we can optimize the shaders.
500 499
 *
501
 * @param name one of the constants defined in
502
 *             {@link org.distorted.library.effect.MatrixEffect},
503
 *             {@link org.distorted.library.effect.VertexEffect},
504
 *             {@link org.distorted.library.effect.FragmentEffect} or
505
 *             {@link org.distorted.library.effect.PostprocessEffect}
500
 * @param name one of the constants defined in {@link EffectName}
506 501
 */
507
  public static void enableEffect(int name)
502
  public static void enableEffect(EffectName name)
508 503
    {
509
    mEffectEnabled[name] = true;
504
    mEnabledEffects.add(name);
510 505
    }
511 506

  
512 507
///////////////////////////////////////////////////////////////////////////////////////////////////
......
518 513
  @SuppressWarnings("unused")
519 514
  public static int getMaxMatrix()
520 515
    {
521
    return EffectQueue.getMax(Effect.MATRIX);
516
    return EffectQueue.getMax(EffectType.MATRIX.ordinal());
522 517
    }
523 518

  
524 519
///////////////////////////////////////////////////////////////////////////////////////////////////
......
530 525
  @SuppressWarnings("unused")
531 526
  public static int getMaxVertex()
532 527
    {
533
    return EffectQueue.getMax(Effect.VERTEX);
528
    return EffectQueue.getMax(EffectType.VERTEX.ordinal());
534 529
    }
535 530

  
536 531
///////////////////////////////////////////////////////////////////////////////////////////////////
......
542 537
  @SuppressWarnings("unused")
543 538
  public static int getMaxFragment()
544 539
    {
545
    return EffectQueue.getMax(Effect.FRAGMENT);
540
    return EffectQueue.getMax(EffectType.FRAGMENT.ordinal());
546 541
    }
547 542

  
548 543
///////////////////////////////////////////////////////////////////////////////////////////////////
......
564 559
  @SuppressWarnings("unused")
565 560
  public static boolean setMaxMatrix(int max)
566 561
    {
567
    return EffectQueue.setMax(Effect.MATRIX,max);
562
    return EffectQueue.setMax(EffectType.MATRIX.ordinal(),max);
568 563
    }
569 564

  
570 565
///////////////////////////////////////////////////////////////////////////////////////////////////
......
586 581
  @SuppressWarnings("unused")
587 582
  public static boolean setMaxVertex(int max)
588 583
    {
589
    return EffectQueue.setMax(Effect.VERTEX,max);
584
    return EffectQueue.setMax(EffectType.VERTEX.ordinal(),max);
590 585
    }
591 586

  
592 587
///////////////////////////////////////////////////////////////////////////////////////////////////
......
608 603
  @SuppressWarnings("unused")
609 604
  public static boolean setMaxFragment(int max)
610 605
    {
611
    return EffectQueue.setMax(Effect.FRAGMENT,max);
606
    return EffectQueue.setMax(EffectType.FRAGMENT.ordinal(),max);
612 607
    }
613 608

  
614 609
///////////////////////////////////////////////////////////////////////////////////////////////////
......
621 616
    {
622 617
    switch(effect.getType())
623 618
      {
624
      case Effect.VERTEX      : mV.add(effect); break;
625
      case Effect.FRAGMENT    : mF.add(effect); break;
626
      case Effect.MATRIX      : mM.add(effect); break;
627
   // case Effect.POSTPROCESS : mP.add(effect); break;
619
      case VERTEX      : mV.add(effect); break;
620
      case FRAGMENT    : mF.add(effect); break;
621
      case MATRIX      : mM.add(effect); break;
622
   // case POSTPROCESS : mP.add(effect); break;
628 623
      }
629 624
    }
630 625
  }

Also available in: Unified diff