Revision f6d884d5
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/examples/plainmonalisa/RenderThread.java | ||
---|---|---|
32 | 32 |
|
33 | 33 |
import org.distorted.library.Distorted; |
34 | 34 |
import org.distorted.library.GridFlat; |
35 |
import org.distorted.library.DistortedObject; |
|
35 |
import org.distorted.library.DistortedTexture; |
|
36 |
import org.distorted.library.DistortedEffectQueues; |
|
36 | 37 |
import org.distorted.library.EffectTypes; |
37 | 38 |
import org.distorted.library.type.Dynamic3D; |
38 | 39 |
import org.distorted.library.type.Static3D; |
... | ... | |
44 | 45 |
|
45 | 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
46 | 47 |
|
47 |
public class RenderThread extends Thread
|
|
48 |
class RenderThread extends Thread |
|
48 | 49 |
{ |
49 | 50 |
private static final String TAG = "RenderThread"; |
50 | 51 |
|
... | ... | |
60 | 61 |
private EglCore eglCore; |
61 | 62 |
private EGLSurface eglSurface; |
62 | 63 |
|
63 |
private DistortedObject monaLisa; |
|
64 |
private DistortedTexture mTexture; |
|
65 |
private DistortedEffectQueues mQueues; |
|
64 | 66 |
private GridFlat mGrid; |
65 | 67 |
private int bmpHeight, bmpWidth; |
66 |
|
|
67 |
private Static3D pLeft, pRight; |
|
68 |
private Static4D rLeft, rRight; |
|
69 |
|
|
70 |
private Dynamic3D dLeft, dRight; |
|
71 |
|
|
72 |
SurfaceView mView; |
|
68 |
private SurfaceView mView; |
|
73 | 69 |
|
74 | 70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
75 | 71 |
|
76 |
public RenderThread(SurfaceHolder holder, SurfaceView view)
|
|
72 |
RenderThread(SurfaceHolder holder, SurfaceView view) |
|
77 | 73 |
{ |
78 | 74 |
mSurfaceHolder = holder; |
79 | 75 |
mView = view; |
80 | 76 |
|
81 |
pLeft = new Static3D( 90, 258, 0); |
|
82 |
pRight= new Static3D(176, 255, 0); |
|
77 |
Static3D pLeft = new Static3D( 90, 258, 0);
|
|
78 |
Static3D pRight= new Static3D(176, 255, 0);
|
|
83 | 79 |
|
84 |
rLeft = new Static4D(-10,-10,25,25); |
|
85 |
rRight= new Static4D( 10, -5,25,25); |
|
80 |
Static4D rLeft = new Static4D(-10,-10,25,25);
|
|
81 |
Static4D rRight= new Static4D( 10, -5,25,25);
|
|
86 | 82 |
|
87 |
dLeft = new Dynamic3D(1000,0.0f); |
|
88 |
dRight= new Dynamic3D(1000,0.0f); |
|
83 |
Dynamic3D dLeft = new Dynamic3D(1000,0.0f);
|
|
84 |
Dynamic3D dRight= new Dynamic3D(1000,0.0f);
|
|
89 | 85 |
|
90 | 86 |
dLeft.add( new Static3D( 0, 0,0) ); |
91 | 87 |
dLeft.add( new Static3D(-20,-20,0) ); |
92 | 88 |
|
93 | 89 |
dRight.add( new Static3D( 0, 0,0) ); |
94 | 90 |
dRight.add( new Static3D( 20,-10,0) ); |
91 |
|
|
92 |
mQueues = new DistortedEffectQueues(); |
|
93 |
mQueues.distort( dLeft, pLeft , rLeft ); |
|
94 |
mQueues.distort(dRight, pRight, rRight); |
|
95 |
} |
|
96 |
|
|
97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
98 |
|
|
99 |
private static void checkGlError(String op) |
|
100 |
{ |
|
101 |
int error = GLES20.glGetError(); |
|
102 |
|
|
103 |
if (error != GLES20.GL_NO_ERROR) |
|
104 |
{ |
|
105 |
String msg = op + ": glError 0x" + Integer.toHexString(error); |
|
106 |
Log.e(TAG, msg); |
|
107 |
throw new RuntimeException(msg); |
|
108 |
} |
|
95 | 109 |
} |
96 | 110 |
|
97 | 111 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
133 | 147 |
|
134 | 148 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
135 | 149 |
|
136 |
public void waitUntilReady()
|
|
150 |
void waitUntilReady() |
|
137 | 151 |
{ |
138 | 152 |
synchronized (mStartLock) |
139 | 153 |
{ |
... | ... | |
158 | 172 |
|
159 | 173 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
160 | 174 |
|
161 |
public RenderHandler getHandler()
|
|
175 |
RenderHandler getHandler() |
|
162 | 176 |
{ |
163 | 177 |
return mHandler; |
164 | 178 |
} |
... | ... | |
193 | 207 |
bmpHeight = bmp.getHeight(); |
194 | 208 |
bmpWidth = bmp.getWidth(); |
195 | 209 |
|
196 |
monaLisa = new DistortedObject(bmpWidth,bmpHeight,1); |
|
197 |
monaLisa.distort( dLeft, pLeft , rLeft ); |
|
198 |
monaLisa.distort(dRight, pRight, rRight); |
|
199 |
monaLisa.setTexture(bmp); |
|
210 |
mTexture = new DistortedTexture(bmpWidth,bmpHeight,0); |
|
211 |
mTexture.setTexture(bmp); |
|
200 | 212 |
|
201 | 213 |
mGrid= new GridFlat(9,9*bmpHeight/bmpWidth); // more-or-less square Grid with 9 columns. |
202 | 214 |
|
... | ... | |
216 | 228 |
{ |
217 | 229 |
Log.d(TAG, "surfaceChanged " + width + "x" + height); |
218 | 230 |
|
219 |
monaLisa.abortEffects(EffectTypes.MATRIX);
|
|
231 |
mQueues.abortEffects(EffectTypes.MATRIX);
|
|
220 | 232 |
|
221 | 233 |
if( (float)bmpHeight/bmpWidth > (float)height/width ) |
222 | 234 |
{ |
223 | 235 |
int w = (height*bmpWidth)/bmpHeight; |
224 | 236 |
float factor = (float)height/bmpHeight; |
225 | 237 |
|
226 |
monaLisa.move( new Static3D((width-w)/2,0,0) );
|
|
227 |
monaLisa.scale( factor );
|
|
238 |
mQueues.move( new Static3D((width-w)/2,0,0) );
|
|
239 |
mQueues.scale( factor );
|
|
228 | 240 |
} |
229 | 241 |
else |
230 | 242 |
{ |
231 | 243 |
int h = (width*bmpHeight)/bmpWidth; |
232 | 244 |
float factor = (float)width/bmpWidth; |
233 | 245 |
|
234 |
monaLisa.move( new Static3D(0,(height-h)/2,0) );
|
|
235 |
monaLisa.scale( factor );
|
|
246 |
mQueues.move( new Static3D(0,(height-h)/2,0) );
|
|
247 |
mQueues.scale( factor );
|
|
236 | 248 |
} |
237 | 249 |
|
238 | 250 |
Distorted.onSurfaceChanged(width, height); |
... | ... | |
240 | 252 |
|
241 | 253 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
242 | 254 |
|
243 |
public void doFrame(long frameTimeNs)
|
|
255 |
void doFrame(long frameTimeNs) |
|
244 | 256 |
{ |
245 | 257 |
if( PlainMonaLisaSurfaceView.isPaused() ) |
246 | 258 |
{ |
... | ... | |
251 | 263 |
eglCore.makeCurrent(eglSurface); |
252 | 264 |
|
253 | 265 |
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); |
254 |
monaLisa.draw(System.currentTimeMillis(), mGrid);
|
|
266 |
mQueues.draw(System.currentTimeMillis(), mTexture,mGrid);
|
|
255 | 267 |
|
256 | 268 |
eglCore.swapBuffers(eglSurface); |
257 | 269 |
} |
258 | 270 |
|
259 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
260 |
|
|
261 |
public static void checkGlError(String op) |
|
262 |
{ |
|
263 |
int error = GLES20.glGetError(); |
|
264 |
|
|
265 |
if (error != GLES20.GL_NO_ERROR) |
|
266 |
{ |
|
267 |
String msg = op + ": glError 0x" + Integer.toHexString(error); |
|
268 |
Log.e(TAG, msg); |
|
269 |
throw new RuntimeException(msg); |
|
270 |
} |
|
271 |
} |
|
272 | 271 |
} |
Also available in: Unified diff
Complete the split DistortedObject -> (DistortedTexture,DistortedEffectQueue)