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/PostprocessEffectBlur.java
56 56
  // We need room for MAX_BLUR of them, and sum(i=0...N, floor((i+3)/2)) = N + floor(N*N/4)
57 57
  private static float[] weightsCache = new float[MAX_HALO + MAX_HALO*MAX_HALO/4];
58 58
  private static float[] offsetsCache = new float[MAX_HALO + MAX_HALO*MAX_HALO/4];
59

  
60
  private static DistortedProgram mBlur1Program, mBlur2Program;
61 59
  private static float[] mWeights = new float[MAX_HALO];
62 60
  private static float[] mOffsets = new float[MAX_HALO];
63 61

  
62
  private static DistortedProgram mBlur1Program, mBlur2Program;
63
  private static int mBlur1Index, mBlur2Index;
64

  
64 65
///////////////////////////////////////////////////////////////////////////////////////////////////
65 66
/**
66 67
 * Blur the object.
......
85 86

  
86 87
  public int apply(float[] uniforms, int index, float qualityScale, DistortedFramebuffer buffer)
87 88
    {
89
    if( mBlur1Program==null)
90
      {
91
      mBlur1Program = mPrograms.get(mBlur1Index);
92
      mBlur2Program = mPrograms.get(mBlur2Index);
93
      }
94

  
88 95
    buffer.setAsOutput();
89 96

  
90 97
    float w1  = buffer.getWidth();
......
149 156
///////////////////////////////////////////////////////////////////////////////////////////////////
150 157

  
151 158
  public static void enable()
152
    {
153
    }
154

  
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

  
157
  public static void createProgram()
158 159
    {
159 160
    final String blurVertex =
160 161

  
......
217 218
      "fragColor = pixel;                                                                                    \n"+
218 219
      "}";
219 220

  
220
    try
221
      {
222
      mBlur1Program = new DistortedProgram(blurVertex,blurFragment1);
223
      }
224
    catch(Exception e)
225
      {
226
      android.util.Log.e("Effects", "exception trying to compile BLUR1 program: "+e.getMessage());
227
      throw new RuntimeException(e.getMessage());
228
      }
229

  
230
    try
231
      {
232
      mBlur2Program = new DistortedProgram(blurVertex,blurFragment2);
233
      }
234
    catch(Exception e)
235
      {
236
      android.util.Log.e("Effects", "exception trying to compile BLUR2 program: "+e.getMessage());
237
      throw new RuntimeException(e.getMessage());
238
      }
221
    mBlur1Index = PostprocessEffect.register("BLUR1", blurVertex,blurFragment1);
222
    mBlur2Index = PostprocessEffect.register("BLUR2", blurVertex,blurFragment2);
239 223
    }
240 224

  
241 225
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff