Revision 046113dc
Added by Leszek Koltunski over 7 years ago
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; |
|
26 | 25 |
import org.distorted.library.program.DistortedProgram; |
27 | 26 |
import org.distorted.library.type.Data1D; |
28 | 27 |
|
... | ... | |
118 | 117 |
GLES30.glUniform1fv( mProgram1.mUniform[2] , radius+1, mOffsets,0); |
119 | 118 |
GLES30.glUniform1fv( mProgram1.mUniform[3] , radius+1, weightsCache,offset); |
120 | 119 |
GLES30.glUniform1i ( mProgram1.mUniform[4] , radius); |
121 |
|
|
122 | 120 |
GLES30.glVertexAttribPointer(mProgram1.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
123 | 121 |
GLES30.glVertexAttribPointer(mProgram1.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture); |
124 |
|
|
125 |
DistortedRenderState.useStencilMark(); |
|
126 | 122 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
127 |
DistortedRenderState.unuseStencilMark(); |
|
128 |
GLES30.glActiveTexture(GLES30.GL_TEXTURE0); |
|
129 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0); |
|
130 | 123 |
|
131 | 124 |
// vertical blur |
132 | 125 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/w1; |
... | ... | |
144 | 137 |
GLES30.glUniform1fv( mProgram2.mUniform[2] , radius+1, mOffsets,0); |
145 | 138 |
GLES30.glUniform1fv( mProgram2.mUniform[3] , radius+1, weightsCache,offset); |
146 | 139 |
GLES30.glUniform1i ( mProgram2.mUniform[4] , radius); |
147 |
|
|
148 | 140 |
GLES30.glVertexAttribPointer(mProgram2.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
149 | 141 |
GLES30.glVertexAttribPointer(mProgram2.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture); |
150 |
|
|
151 |
DistortedRenderState.useStencilMark(); |
|
152 | 142 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
153 |
DistortedRenderState.unuseStencilMark(); |
|
154 |
GLES30.glActiveTexture(GLES30.GL_TEXTURE0); |
|
155 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0); |
|
156 | 143 |
|
157 | 144 |
return 2; |
158 | 145 |
} |
src/main/java/org/distorted/library/effect/PostprocessEffectGlow.java | ||
---|---|---|
22 | 22 |
import android.opengl.GLES30; |
23 | 23 |
|
24 | 24 |
import org.distorted.library.main.DistortedFramebuffer; |
25 |
import org.distorted.library.main.DistortedRenderState; |
|
26 | 25 |
import org.distorted.library.program.DistortedProgram; |
27 | 26 |
import org.distorted.library.type.Data1D; |
28 | 27 |
import org.distorted.library.type.Data4D; |
... | ... | |
124 | 123 |
GLES30.glUniform1fv( mProgram1.mUniform[2] , radius+1, mOffsets,0); |
125 | 124 |
GLES30.glUniform1fv( mProgram1.mUniform[3] , radius+1, weightsCache,offset); |
126 | 125 |
GLES30.glUniform1i ( mProgram1.mUniform[4] , radius); |
127 |
|
|
128 | 126 |
GLES30.glVertexAttribPointer(mProgram1.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
129 | 127 |
GLES30.glVertexAttribPointer(mProgram1.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture); |
130 |
|
|
131 |
DistortedRenderState.useStencilMark(); |
|
132 | 128 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
133 |
DistortedRenderState.unuseStencilMark(); |
|
134 |
GLES30.glActiveTexture(GLES30.GL_TEXTURE0); |
|
135 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0); |
|
136 | 129 |
|
137 | 130 |
// vertical blur |
138 | 131 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/w1; |
... | ... | |
150 | 143 |
GLES30.glUniform1fv( mProgram2.mUniform[2] , radius+1, mOffsets,0); |
151 | 144 |
GLES30.glUniform1fv( mProgram2.mUniform[3] , radius+1, weightsCache,offset); |
152 | 145 |
GLES30.glUniform1i ( mProgram2.mUniform[4] , radius); |
153 |
|
|
154 | 146 |
GLES30.glVertexAttribPointer(mProgram2.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
155 | 147 |
GLES30.glVertexAttribPointer(mProgram2.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture); |
156 |
|
|
157 |
DistortedRenderState.useStencilMark(); |
|
158 | 148 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
159 |
DistortedRenderState.unuseStencilMark(); |
|
160 |
GLES30.glActiveTexture(GLES30.GL_TEXTURE0); |
|
161 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0); |
|
162 | 149 |
|
163 | 150 |
return 2; |
164 | 151 |
} |
src/main/java/org/distorted/library/main/DistortedRenderState.java | ||
---|---|---|
28 | 28 |
* This is a member of DistortedNode. Remembers the OpenGL state we want to set just before rendering |
29 | 29 |
* the Node. |
30 | 30 |
*/ |
31 |
public class DistortedRenderState
|
|
31 |
class DistortedRenderState |
|
32 | 32 |
{ |
33 | 33 |
// TODO: figure this out dynamically; this assumes 8 bit stencil buffer. |
34 | 34 |
private static final int STENCIL_MASK = (1<<8)-1; |
... | ... | |
259 | 259 |
|
260 | 260 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
261 | 261 |
|
262 |
public static void useStencilMark()
|
|
262 |
static void useStencilMark() |
|
263 | 263 |
{ |
264 | 264 |
if( cState.stencilTest!=1 ) |
265 | 265 |
{ |
... | ... | |
299 | 299 |
|
300 | 300 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
301 | 301 |
|
302 |
public static void unuseStencilMark()
|
|
302 |
static void unuseStencilMark() |
|
303 | 303 |
{ |
304 | 304 |
if( sState.stencilTest!=cState.stencilTest ) |
305 | 305 |
{ |
src/main/java/org/distorted/library/main/EffectQueuePostprocess.java | ||
---|---|---|
93 | 93 |
{ |
94 | 94 |
int numRenders = 0; |
95 | 95 |
|
96 |
DistortedRenderState.useStencilMark(); |
|
97 |
|
|
96 | 98 |
for(int i=0; i<mNumEffects; i++) |
97 | 99 |
{ |
98 | 100 |
numRenders += ((PostprocessEffect)mEffects[i]).apply(mUniforms,NUM_UNIFORMS*i,mQualityScale,surface.mBuffer[mQualityLevel]); |
99 | 101 |
} |
102 |
DistortedRenderState.unuseStencilMark(); |
|
100 | 103 |
|
101 | 104 |
return numRenders; |
102 | 105 |
} |
Also available in: Unified diff
make RenderState package-local.