Revision 3c8433ae
Added by Leszek Koltunski almost 8 years ago
src/main/java/org/distorted/examples/save/SaveRenderer.java | ||
---|---|---|
32 | 32 |
|
33 | 33 |
import org.distorted.library.Distorted; |
34 | 34 |
import org.distorted.library.DistortedBitmap; |
35 |
import org.distorted.library.DistortedFramebuffer; |
|
35 | 36 |
import org.distorted.library.EffectTypes; |
36 | 37 |
import org.distorted.library.type.Dynamic1D; |
37 | 38 |
import org.distorted.library.type.Static1D; |
... | ... | |
50 | 51 |
{ |
51 | 52 |
private GLSurfaceView mView; |
52 | 53 |
private DistortedBitmap mGirl; |
54 |
private DistortedFramebuffer mOffscreen; |
|
53 | 55 |
private Static3D pLeft, pRight; |
54 | 56 |
private Static4D sinkRegion; |
55 | 57 |
private Dynamic1D diSink; |
56 | 58 |
private Static1D s0; |
57 | 59 |
|
60 |
private int fboHeight, fboWidth; |
|
58 | 61 |
private int bmpHeight, bmpWidth; |
59 | 62 |
private int scrHeight, scrWidth; |
60 | 63 |
private float boobsSink; |
... | ... | |
78 | 81 |
|
79 | 82 |
diSink = new Dynamic1D(0,0.5f); |
80 | 83 |
diSink.add(s0); |
84 |
|
|
85 |
fboHeight = 150; |
|
86 |
fboWidth = 100; |
|
81 | 87 |
} |
82 | 88 |
|
83 | 89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
116 | 122 |
public void onDrawFrame(GL10 glUnused) |
117 | 123 |
{ |
118 | 124 |
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); |
119 |
|
|
120 |
mGirl.draw(System.currentTimeMillis()); |
|
121 | 125 |
|
122 |
if( isSaving ) // we should save the buffer to location pointed at by mPath
|
|
126 |
if( isSaving ) // render to an offscreen buffer and read pixels
|
|
123 | 127 |
{ |
124 |
ByteBuffer buf = ByteBuffer.allocateDirect( scrWidth*scrHeight*4 ); |
|
128 |
long scaleID = mGirl.scale(new Static3D( (float)fboWidth/scrWidth, (float)fboHeight/scrHeight, 1.0f)); |
|
129 |
mGirl.draw(System.currentTimeMillis(), mOffscreen); |
|
130 |
mGirl.abortEffect(scaleID); |
|
131 |
|
|
132 |
ByteBuffer buf = ByteBuffer.allocateDirect( fboWidth*fboHeight*4 ); |
|
125 | 133 |
buf.order(ByteOrder.LITTLE_ENDIAN); |
126 |
GLES20.glReadPixels( 0, 0, scrWidth, scrHeight , GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, buf);
|
|
134 |
mOffscreen.setAsInput();
|
|
127 | 135 |
|
128 |
SaveWorkerThread.newBuffer(buf,scrWidth,scrHeight,mPath); |
|
136 |
GLES20.glReadPixels( 0, 0, fboWidth, fboHeight , GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, buf); |
|
137 |
SaveWorkerThread.newBuffer(buf,fboWidth,fboHeight,mPath); |
|
129 | 138 |
|
130 | 139 |
isSaving = false; |
131 | 140 |
} |
141 |
else |
|
142 |
{ |
|
143 |
mGirl.draw(System.currentTimeMillis()); |
|
144 |
} |
|
132 | 145 |
} |
133 | 146 |
|
134 | 147 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
190 | 203 |
mGirl.sink( diSink, pLeft , sinkRegion); |
191 | 204 |
mGirl.sink( diSink, pRight, sinkRegion); |
192 | 205 |
|
206 |
mOffscreen = new DistortedFramebuffer(fboWidth,fboHeight); |
|
207 |
|
|
193 | 208 |
try |
194 | 209 |
{ |
195 | 210 |
Distorted.onSurfaceCreated(mView.getContext()); |
Also available in: Unified diff
Move the 'Save' app to using a DistortedFramebuffer.