Project

General

Profile

« Previous | Next » 

Revision 9e771d06

Added by Leszek Koltunski almost 6 years ago

Progress with thr Glow effect - moving glow app looks ok now.

View differences:

src/main/java/org/distorted/library/main/EffectQueuePostprocess.java
40 40
  private static final int INDEX = EffectType.POSTPROCESS.ordinal();
41 41

  
42 42
  private int mHalo;
43
  private float mR, mG, mB, mA;
43 44

  
44 45
  private static DistortedProgram mPreProgram;
45 46
  private static int mPreColorH;
47
  private static int mPreTextureH;
46 48

  
47 49
///////////////////////////////////////////////////////////////////////////////////////////////////
48 50

  
......
59 61
    if( mTime==0 ) mTime = currTime;
60 62
    long step = (currTime-mTime);
61 63

  
64
    mR = mG = mB = mA = 0.0f;
62 65
    mHalo = 0;
63 66
    int halo;
64 67

  
......
84 87
      if( halo>mHalo ) mHalo = halo;
85 88
      }
86 89

  
90
    // TODO  (now only really works in case of 1 effect!)
91
    if( mNumEffects>0 )
92
      {
93
      mR = mUniforms[1];
94
      mG = mUniforms[2];
95
      mB = mUniforms[3];
96
      mA = mUniforms[4];
97
      }
98

  
87 99
    mTime = currTime;
88 100
    }
89 101

  
......
115 127
    int preProgramH = mPreProgram.getProgramHandle();
116 128
    EffectQueueVertex.getUniforms( preProgramH,2 );
117 129
    EffectQueueMatrix.getUniforms( preProgramH,2 );
118
    mPreColorH= GLES31.glGetUniformLocation( preProgramH, "u_Color");
119
    }
120

  
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122
// TODO
123

  
124
  private int getWriteColor()
125
    {
126
    return mNumEffects>0 ? ((PostprocessEffect)mEffects[0]).getWriteColor() : 0;
127
    }
128

  
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

  
131
  private int getHalo()
132
    {
133
    return mNumEffects>0 ? mHalo : 0;
130
    mPreColorH  = GLES31.glGetUniformLocation( preProgramH, "u_Color"  );
131
    mPreTextureH= GLES31.glGetUniformLocation( preProgramH, "u_Texture");
134 132
    }
135 133

  
136 134
///////////////////////////////////////////////////////////////////////////////////////////////////
137 135
// TODO  (now only really works in case of 1 effect!)
138 136

  
139
  private int getInternalQuality()
137
  int getQuality()
140 138
    {
141
    return mNumEffects>0 ? ((PostprocessEffect)mEffects[0]).getInternalQuality() : 0;
139
    return mNumEffects>0 ? ((PostprocessEffect)mEffects[0]).getQuality() : 0;
142 140
    }
143 141

  
144 142
///////////////////////////////////////////////////////////////////////////////////////////////////
145 143
// TODO  (now only really works in case of 1 effect!)
146 144

  
147
  int getQuality()
145
  boolean getRender()
148 146
    {
149
    return mNumEffects>0 ? ((PostprocessEffect)mEffects[0]).getQuality() : 0;
147
    return mNumEffects>0 ? ((PostprocessEffect)mEffects[0]).getRender() : false;
150 148
    }
151 149

  
152 150
///////////////////////////////////////////////////////////////////////////////////////////////////
153 151

  
154
  int preprocess(DistortedOutputSurface[] buffers, DistortedNode node)
152
  int preprocess(DistortedOutputSurface buffer, DistortedNode node)
155 153
    {
156
    int quality = getInternalQuality();
157
    DistortedOutputSurface surface = buffers[quality];
158

  
159
    surface.setAsOutput();
154
    buffer.setAsOutput();
160 155
    DistortedSurface input = node.getInternalSurface();
161 156

  
162 157
    if( input.setAsInput() )
163 158
      {
164 159
      MeshObject mesh = node.getMesh();
165
      int  writeColor = getWriteColor();
166
      float    margin = getHalo()*surface.mMipmap;
160
      float    margin = mHalo*buffer.mMipmap;
167 161

  
168 162
      float halfW = input.getWidth() / 2.0f;
169 163
      float halfH = input.getHeight()/ 2.0f;
170 164
      float halfZ = halfW*mesh.zFactor;
171 165

  
172
      DistortedRenderState.setUpStencilMark(writeColor!=0);
166
      DistortedRenderState.setUpStencilMark(mA!=0.0f);
173 167

  
174
      GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
168
      GLES31.glViewport(0, 0, buffer.mWidth, buffer.mHeight );
175 169

  
176 170
      mPreProgram.useProgram();
177 171

  
......
181 175
      GLES31.glVertexAttribPointer(mPreProgram.mAttribute[2], MeshObject.TEX_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET2);
182 176
      GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, 0);
183 177

  
184
      node.getEffects().send(halfW, halfH, halfZ, margin, surface, 2);
185

  
186
      float a = (writeColor&255);
178
      node.getEffects().send(halfW, halfH, halfZ, margin, buffer, 2);
187 179

  
188
      if( a!=0.0f )
180
      if( mA!=0.0f )
189 181
        {
190
        writeColor = (writeColor>>8);
191
        float b = writeColor&255;
192
        writeColor = (writeColor>>8);
193
        float g = writeColor&255;
194
        writeColor = (writeColor>>8);
195
        float r = writeColor&255;
196

  
197
        GLES31.glUniform4f(mPreColorH, r, g, b, a);
182
        GLES31.glUniform4f(mPreColorH, mR, mG, mB, mA);
183
        GLES31.glUniform1i(mPreTextureH, 0);
198 184
        }
199 185

  
200 186
      GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, mesh.numVertices);
......
208 194

  
209 195
///////////////////////////////////////////////////////////////////////////////////////////////////
210 196

  
211
  int postprocess(DistortedOutputSurface[] buffers)
197
  int postprocess(DistortedFramebuffer buffer)
212 198
    {
213 199
    int numRenders = 0;
214 200

  
......
216 202

  
217 203
    for(int i=0; i<mNumEffects; i++)
218 204
      {
219
      numRenders += ((PostprocessEffect)mEffects[i]).apply(mUniforms,NUM_UNIFORMS*i, buffers);
205
      numRenders += ((PostprocessEffect)mEffects[i]).apply(mUniforms,NUM_UNIFORMS*i, buffer);
220 206
      }
221 207

  
222 208
    GLES31.glEnable(GLES31.GL_BLEND);

Also available in: Unified diff