Revision 5055b5d4
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/examples/save/SaveRenderer.java | ||
---|---|---|
35 | 35 |
import org.distorted.library.DistortedFramebuffer; |
36 | 36 |
import org.distorted.library.EffectTypes; |
37 | 37 |
import org.distorted.library.type.Dynamic1D; |
38 |
import org.distorted.library.type.Dynamic3D; |
|
38 | 39 |
import org.distorted.library.type.Static1D; |
39 | 40 |
import org.distorted.library.type.Static3D; |
40 | 41 |
import org.distorted.library.type.Static4D; |
... | ... | |
56 | 57 |
private Static4D sinkRegion; |
57 | 58 |
private Dynamic1D diSink; |
58 | 59 |
private Static1D s0; |
60 |
private Dynamic3D mScaleDyn; |
|
61 |
private Static3D mScaleFactor; |
|
59 | 62 |
|
60 |
private int fboHeight, fboWidth;
|
|
63 |
private float mScale;
|
|
61 | 64 |
private int bmpHeight, bmpWidth; |
62 | 65 |
private int scrHeight, scrWidth; |
63 | 66 |
private float boobsSink; |
... | ... | |
79 | 82 |
|
80 | 83 |
s0 = new Static1D(boobsSink); |
81 | 84 |
|
82 |
diSink = new Dynamic1D(0,0.5f);
|
|
85 |
diSink = new Dynamic1D(); |
|
83 | 86 |
diSink.add(s0); |
84 | 87 |
|
85 |
fboHeight = 150; |
|
86 |
fboWidth = 100; |
|
88 |
mScale = 1.0f; |
|
89 |
mScaleDyn = new Dynamic3D(); |
|
90 |
mScaleFactor = new Static3D(mScale,mScale,1.0f); |
|
91 |
mScaleDyn.add(mScaleFactor); |
|
87 | 92 |
} |
88 | 93 |
|
89 | 94 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
94 | 99 |
s0.set(boobsSink); |
95 | 100 |
} |
96 | 101 |
|
102 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
103 |
|
|
104 |
void setScale(float s) |
|
105 |
{ |
|
106 |
mScale = s; |
|
107 |
mScaleFactor.set(s,s,1.0f); |
|
108 |
|
|
109 |
// when we move our scroll bar, this does NOT keep allocating and deallocating |
|
110 |
// the whole WxH texture - the allocation happens only once, on next render, i.e. - |
|
111 |
// when one presses the 'SAVE' button. |
|
112 |
|
|
113 |
if( mOffscreen!=null ) |
|
114 |
mOffscreen.resize( (int)(mScale*bmpWidth),(int)(mScale*bmpHeight)); |
|
115 |
} |
|
116 |
|
|
97 | 117 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
98 | 118 |
|
99 | 119 |
void Save() |
... | ... | |
125 | 145 |
|
126 | 146 |
if( isSaving ) // render to an offscreen buffer and read pixels |
127 | 147 |
{ |
128 |
long scaleID = mGirl.scale(new Static3D( (float)fboWidth/scrWidth, (float)fboHeight/scrHeight, 1.0f)); |
|
148 |
mGirl.abortEffects(EffectTypes.MATRIX); |
|
149 |
mGirl.scale(mScaleFactor); |
|
129 | 150 |
mGirl.draw(System.currentTimeMillis(), mOffscreen); |
130 |
mGirl.abortEffect(scaleID);
|
|
151 |
applyMatrixEffects(scrWidth,scrHeight);
|
|
131 | 152 |
|
132 |
ByteBuffer buf = ByteBuffer.allocateDirect( fboWidth*fboHeight*4 ); |
|
153 |
int fW =(int)(mScale*bmpWidth); |
|
154 |
int fH =(int)(mScale*bmpHeight); |
|
155 |
ByteBuffer buf = ByteBuffer.allocateDirect(fW*fH*4); |
|
133 | 156 |
buf.order(ByteOrder.LITTLE_ENDIAN); |
134 | 157 |
mOffscreen.setAsInput(); |
135 | 158 |
|
136 |
GLES20.glReadPixels( 0, 0, fboWidth, fboHeight , GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, buf);
|
|
137 |
SaveWorkerThread.newBuffer(buf,fboWidth,fboHeight,mPath);
|
|
159 |
GLES20.glReadPixels( 0, 0, fW, fH, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, buf);
|
|
160 |
SaveWorkerThread.newBuffer(buf,fW,fH,mPath);
|
|
138 | 161 |
|
139 | 162 |
isSaving = false; |
140 | 163 |
} |
141 |
else |
|
142 |
{ |
|
143 |
mGirl.draw(System.currentTimeMillis()); |
|
144 |
} |
|
164 |
|
|
165 |
mGirl.draw(System.currentTimeMillis()); |
|
145 | 166 |
} |
146 | 167 |
|
168 |
|
|
147 | 169 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
148 |
|
|
149 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
150 |
{ |
|
151 |
scrWidth = width; |
|
152 |
scrHeight= height; |
|
153 | 170 |
|
171 |
private void applyMatrixEffects(int width, int height) |
|
172 |
{ |
|
154 | 173 |
mGirl.abortEffects(EffectTypes.MATRIX); |
155 |
|
|
156 |
if( bmpHeight/bmpWidth > height/width )
|
|
174 |
|
|
175 |
if( (float)bmpHeight/bmpWidth > (float)height/width )
|
|
157 | 176 |
{ |
158 | 177 |
int w = (height*bmpWidth)/bmpHeight; |
159 | 178 |
float factor = (float)height/bmpHeight; |
... | ... | |
169 | 188 |
mGirl.move( new Static3D(0,(height-h)/2,0) ); |
170 | 189 |
mGirl.scale(factor); |
171 | 190 |
} |
172 |
|
|
191 |
|
|
192 |
mGirl.scale(mScaleDyn); |
|
193 |
} |
|
194 |
|
|
195 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
196 |
|
|
197 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
198 |
{ |
|
199 |
scrWidth = width; |
|
200 |
scrHeight= height; |
|
201 |
applyMatrixEffects(width, height); |
|
173 | 202 |
Distorted.onSurfaceChanged(width, height); |
174 | 203 |
} |
175 | 204 |
|
... | ... | |
203 | 232 |
mGirl.sink( diSink, pLeft , sinkRegion); |
204 | 233 |
mGirl.sink( diSink, pRight, sinkRegion); |
205 | 234 |
|
206 |
mOffscreen = new DistortedFramebuffer(fboWidth,fboHeight);
|
|
235 |
mOffscreen = new DistortedFramebuffer(bmpWidth,bmpHeight);
|
|
207 | 236 |
|
208 | 237 |
try |
209 | 238 |
{ |
Also available in: Unified diff
1. (hopefully) finish the 'Save' app (now we can adjust the size of the resulting file)
2. Fix one long-standing bug in almost every single app.