Revision 7266d8ef
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/effect/PostprocessEffect.java | ||
---|---|---|
149 | 149 |
*/ |
150 | 150 |
public abstract int getQuality(); |
151 | 151 |
|
152 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
153 |
/** |
|
154 |
* Only for use by the library itself. |
|
155 |
* |
|
156 |
* @y.exclude |
|
157 |
*/ |
|
158 |
public int getInternalQuality() |
|
159 |
{ |
|
160 |
return mQualityLevel; |
|
161 |
} |
|
162 |
|
|
152 | 163 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
153 | 164 |
/** |
154 | 165 |
* This is not really part of the public API. Has to be public only because it is a part of the |
src/main/java/org/distorted/library/effect/PostprocessEffectBlur.java | ||
---|---|---|
22 | 22 |
import android.opengl.GLES30; |
23 | 23 |
|
24 | 24 |
import org.distorted.library.main.DistortedFramebuffer; |
25 |
import org.distorted.library.main.DistortedRenderState; |
|
25 | 26 |
import org.distorted.library.program.DistortedProgram; |
26 | 27 |
import org.distorted.library.type.Data1D; |
27 | 28 |
|
... | ... | |
146 | 147 |
mProgram2 = mPrograms.get(mIndex2); |
147 | 148 |
} |
148 | 149 |
|
150 |
DistortedRenderState.useStencilMark(); |
|
151 |
|
|
149 | 152 |
DistortedFramebuffer buffer = buffers[mQualityLevel]; |
150 | 153 |
|
151 | 154 |
buffer.setAsOutput(); |
... | ... | |
198 | 201 |
GLES30.glVertexAttribPointer(mProgram2.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture); |
199 | 202 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
200 | 203 |
|
204 |
DistortedRenderState.unuseStencilMark(); |
|
205 |
|
|
201 | 206 |
return 2; |
202 | 207 |
} |
203 | 208 |
|
src/main/java/org/distorted/library/effect/PostprocessEffectGlow.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
import android.opengl.GLES30; |
23 | 23 |
|
24 |
import org.distorted.library.main.DistortedEffects; |
|
24 | 25 |
import org.distorted.library.main.DistortedFramebuffer; |
26 |
import org.distorted.library.main.DistortedRenderState; |
|
25 | 27 |
import org.distorted.library.program.DistortedProgram; |
26 | 28 |
import org.distorted.library.type.Data1D; |
27 | 29 |
import org.distorted.library.type.Data4D; |
... | ... | |
149 | 151 |
mProgram2 = mPrograms.get(mIndex2); |
150 | 152 |
} |
151 | 153 |
|
154 |
DistortedRenderState.useStencilMark(); |
|
155 |
|
|
152 | 156 |
DistortedFramebuffer inBuffer = buffers[0]; |
153 |
DistortedFramebuffer outBuffer = buffers[1];
|
|
157 |
DistortedFramebuffer outBuffer = buffers[mQualityLevel];
|
|
154 | 158 |
|
155 | 159 |
float w1 = outBuffer.getWidth(); |
156 | 160 |
float h1 = outBuffer.getHeight(); |
... | ... | |
165 | 169 |
int offset = radius + radius*radius/4; |
166 | 170 |
radius = (radius+1)/2; |
167 | 171 |
|
172 |
outBuffer.setAsOutput(); |
|
168 | 173 |
GLES30.glViewport(0, 0, (int)w1, (int)h1); |
169 | 174 |
|
170 | 175 |
// horizontal glow |
171 | 176 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/w1; |
172 | 177 |
|
173 | 178 |
mProgram1.useProgram(); |
174 |
outBuffer.setAsOutput(); |
|
175 |
outBuffer.bindForOutput(0); |
|
179 |
outBuffer.bindForOutput(1); |
|
176 | 180 |
inBuffer.setAsInput(0); |
177 | 181 |
|
178 | 182 |
GLES30.glUniform1f ( mProgram1.mUniform[0] , near); |
... | ... | |
184 | 188 |
GLES30.glVertexAttribPointer(mProgram1.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
185 | 189 |
GLES30.glVertexAttribPointer(mProgram1.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture); |
186 | 190 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
187 |
/* |
|
188 |
GLES30.glViewport(0, 0, (int)w2, (int)h2); |
|
189 | 191 |
|
190 | 192 |
// vertical glow |
191 | 193 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/h1; |
192 | 194 |
|
193 | 195 |
mProgram2.useProgram(); |
194 |
inBuffer.setAsOutput(); |
|
195 |
inBuffer.bindForOutput(0); |
|
196 |
outBuffer.bindForOutput(0); |
|
196 | 197 |
outBuffer.setAsInput(1); |
197 | 198 |
|
198 | 199 |
GLES30.glUniform1f ( mProgram2.mUniform[0] , near); |
... | ... | |
204 | 205 |
GLES30.glVertexAttribPointer(mProgram2.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
205 | 206 |
GLES30.glVertexAttribPointer(mProgram2.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture); |
206 | 207 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
207 |
*/ |
|
208 |
|
|
209 |
DistortedRenderState.unuseStencilMark(); |
|
210 |
|
|
211 |
// blit back to inBuffer if we have to |
|
212 |
if( mQualityLevel>0 ) |
|
213 |
{ |
|
214 |
inBuffer.setAsOutput(); |
|
215 |
outBuffer.setAsInput(0); |
|
216 |
DistortedEffects.blitPriv(inBuffer); |
|
217 |
return 3; |
|
218 |
} |
|
219 |
|
|
208 | 220 |
return 2; |
209 | 221 |
} |
210 | 222 |
|
src/main/java/org/distorted/library/main/DistortedEffects.java | ||
---|---|---|
250 | 250 |
return mP.getQuality(); |
251 | 251 |
} |
252 | 252 |
|
253 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
254 |
|
|
255 |
int getInternalQuality() |
|
256 |
{ |
|
257 |
return mP.getInternalQuality(); |
|
258 |
} |
|
259 |
|
|
253 | 260 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
254 | 261 |
|
255 | 262 |
int getHalo() |
... | ... | |
332 | 339 |
} |
333 | 340 |
|
334 | 341 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
335 |
|
|
336 |
static void blitPriv(DistortedOutputSurface surface) |
|
342 |
/** |
|
343 |
* Only for use by the library itself. |
|
344 |
* |
|
345 |
* @y.exclude |
|
346 |
*/ |
|
347 |
public static void blitPriv(DistortedOutputSurface surface) |
|
337 | 348 |
{ |
338 | 349 |
mBlitProgram.useProgram(); |
339 | 350 |
|
src/main/java/org/distorted/library/main/DistortedOutputSurface.java | ||
---|---|---|
251 | 251 |
|
252 | 252 |
int renderChildren(long time, int numChildren, ArrayList<DistortedNode> children) |
253 | 253 |
{ |
254 |
int quality=0, numRenders = 0, bucketChange = 0; |
|
254 |
int quality=0, internalQuality = 0, numRenders = 0, bucketChange = 0;
|
|
255 | 255 |
DistortedNode child1, child2; |
256 | 256 |
DistortedEffects lastEffects=null, currEffects; |
257 | 257 |
long lastBucket=0, currBucket; |
... | ... | |
278 | 278 |
for(int j=bucketChange; j<i; j++) |
279 | 279 |
{ |
280 | 280 |
child2 = children.get(j); |
281 |
numRenders += child2.markStencilAndDepth(time,mBuffer[quality],lastEffects);
|
|
281 |
numRenders += child2.markStencilAndDepth(time,mBuffer[internalQuality],lastEffects);
|
|
282 | 282 |
} |
283 | 283 |
|
284 | 284 |
numRenders += lastEffects.postprocess(this); |
285 | 285 |
numRenders += blitWithDepth(time, mBuffer[quality]); |
286 | 286 |
} |
287 | 287 |
|
288 |
internalQuality = currEffects.getInternalQuality(); |
|
288 | 289 |
quality = currEffects.getQuality(); |
289 | 290 |
bucketChange = i; |
290 | 291 |
} |
... | ... | |
296 | 297 |
for(int j=bucketChange; j<numChildren; j++) |
297 | 298 |
{ |
298 | 299 |
child2 = children.get(j); |
299 |
numRenders += child2.markStencilAndDepth(time,mBuffer[quality],currEffects);
|
|
300 |
numRenders += child2.markStencilAndDepth(time,mBuffer[internalQuality],currEffects);
|
|
300 | 301 |
} |
301 | 302 |
|
302 | 303 |
numRenders += currEffects.postprocess(this); |
303 |
numRenders += blitWithDepth(time, mBuffer[1]);
|
|
304 |
numRenders += blitWithDepth(time, mBuffer[quality]);
|
|
304 | 305 |
} |
305 | 306 |
} |
306 | 307 |
|
src/main/java/org/distorted/library/main/DistortedRenderState.java | ||
---|---|---|
27 | 27 |
* <p> |
28 | 28 |
* This is a member of DistortedNode. Remembers the OpenGL state we want to set just before rendering |
29 | 29 |
* the Node. |
30 |
* <p> |
|
31 |
* Only for use by the library itself. |
|
32 |
* |
|
33 |
* @y.exclude |
|
30 | 34 |
*/ |
31 |
class DistortedRenderState |
|
35 |
public class DistortedRenderState
|
|
32 | 36 |
{ |
33 | 37 |
// TODO: figure this out dynamically; this assumes 8 bit stencil buffer. |
34 | 38 |
private static final int STENCIL_MASK = (1<<8)-1; |
... | ... | |
258 | 262 |
} |
259 | 263 |
|
260 | 264 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
261 |
|
|
262 |
static void useStencilMark() |
|
265 |
/** |
|
266 |
* Only for use by the library itself. |
|
267 |
* |
|
268 |
* @y.exclude |
|
269 |
*/ |
|
270 |
public static void useStencilMark() |
|
263 | 271 |
{ |
264 | 272 |
if( cState.stencilTest!=1 ) |
265 | 273 |
{ |
... | ... | |
298 | 306 |
} |
299 | 307 |
|
300 | 308 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
301 |
|
|
302 |
static void unuseStencilMark() |
|
309 |
/** |
|
310 |
* Only for use by the library itself. |
|
311 |
* |
|
312 |
* @y.exclude |
|
313 |
*/ |
|
314 |
public static void unuseStencilMark() |
|
303 | 315 |
{ |
304 | 316 |
if( sState.stencilTest!=cState.stencilTest ) |
305 | 317 |
{ |
src/main/java/org/distorted/library/main/EffectQueuePostprocess.java | ||
---|---|---|
90 | 90 |
return mNumEffects>0 ? ((PostprocessEffect)mEffects[0]).getQuality() : 0; |
91 | 91 |
} |
92 | 92 |
|
93 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
94 |
|
|
95 |
int getInternalQuality() |
|
96 |
{ |
|
97 |
return mNumEffects>0 ? ((PostprocessEffect)mEffects[0]).getInternalQuality() : 0; |
|
98 |
} |
|
99 |
|
|
93 | 100 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
94 | 101 |
|
95 | 102 |
int postprocess(DistortedOutputSurface surface) |
96 | 103 |
{ |
97 | 104 |
int numRenders = 0; |
98 | 105 |
|
99 |
DistortedRenderState.useStencilMark(); |
|
100 |
|
|
101 | 106 |
for(int i=0; i<mNumEffects; i++) |
102 | 107 |
{ |
103 | 108 |
numRenders += ((PostprocessEffect)mEffects[i]).apply(mUniforms,NUM_UNIFORMS*i, surface.mBuffer); |
104 | 109 |
} |
105 | 110 |
|
106 |
DistortedRenderState.unuseStencilMark(); |
|
107 |
|
|
108 | 111 |
return numRenders; |
109 | 112 |
} |
110 | 113 |
} |
Also available in: Unified diff
Fix quality levels in Glow.