Project

General

Profile

« Previous | Next » 

Revision aa2f0486

Added by Leszek Koltunski almost 7 years ago

Now all PostprocessEffects are truly self-contained, including dynamic enable() and all shader sources.

View differences:

src/main/java/org/distorted/library/effect/PostprocessEffect.java
20 20
package org.distorted.library.effect;
21 21

  
22 22
import org.distorted.library.main.DistortedFramebuffer;
23
import org.distorted.library.program.DistortedProgram;
23 24

  
24 25
import java.nio.ByteBuffer;
25 26
import java.nio.ByteOrder;
26 27
import java.nio.FloatBuffer;
28
import java.util.ArrayList;
27 29

  
28 30
///////////////////////////////////////////////////////////////////////////////////////////////////
29 31
// POSTPROCESSING EFFECTS.
......
54 56
    mQuadTextureInv.put(textureInv).position(0);
55 57
    }
56 58

  
59
  private static class Source
60
    {
61
    private String mName, mVertexShader, mFragmentShader;
62

  
63
    public Source(String name, String vertex, String fragment)
64
      {
65
      mName           = name;
66
      mVertexShader   = vertex;
67
      mFragmentShader = fragment;
68
      }
69
    }
70

  
71
  static ArrayList<DistortedProgram> mPrograms = new ArrayList<>();
72
  private static ArrayList<Source> mSources = new ArrayList<>();
73
  private static int mNumSources = 0;
74

  
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

  
77
  static int register(final String name, final String vertexShader, final String fragmentShader)
78
    {
79
    mSources.add(new Source(name,vertexShader,fragmentShader));
80

  
81
    return mNumSources++;
82
    }
83

  
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

  
86
  public static void createPrograms()
87
    {
88
    Source source;
89
    int len = mSources.size();
90

  
91
    for(int i=0; i<len; i++)
92
      {
93
      source = mSources.remove(0);
94

  
95
      //android.util.Log.d("postprocess", "compilaing: "+source.mName);
96

  
97
      try
98
        {
99
        mPrograms.add (new DistortedProgram(source.mVertexShader,source.mFragmentShader));
100
        }
101
      catch(Exception e)
102
        {
103
        android.util.Log.e("Effects", "exception trying to compile "+source.mName+" program: "+e.getMessage());
104
        throw new RuntimeException(e.getMessage());
105
        }
106
      }
107
    }
108

  
57 109
///////////////////////////////////////////////////////////////////////////////////////////////////
58 110

  
59 111
  public abstract int apply(float[] uniforms, int index, float qualityScale, DistortedFramebuffer buffer);

Also available in: Unified diff