Revision 5a683295
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/examples/objecttree/ObjectTreeRenderer.java | ||
---|---|---|
37 | 37 |
import org.distorted.library.main.DistortedScreen; |
38 | 38 |
import org.distorted.library.main.DistortedLibrary; |
39 | 39 |
import org.distorted.library.mesh.MeshCubes; |
40 |
import org.distorted.library.mesh.MeshRectangles;
|
|
40 |
import org.distorted.library.mesh.MeshQuad;
|
|
41 | 41 |
import org.distorted.library.main.DistortedTexture; |
42 | 42 |
import org.distorted.library.type.Dynamic; |
43 | 43 |
import org.distorted.library.type.Dynamic1D; |
... | ... | |
55 | 55 |
|
56 | 56 |
class ObjectTreeRenderer implements GLSurfaceView.Renderer |
57 | 57 |
{ |
58 |
private static final int NODE_FBO_SIZE = 300; |
|
59 |
|
|
58 | 60 |
private GLSurfaceView mView; |
59 |
private DistortedEffects mEffects; |
|
61 |
private DistortedEffects mEffectsNode, mEffectsGrid;
|
|
60 | 62 |
private DistortedTexture mLisaTexture, mGridTexture; |
61 | 63 |
private DistortedScreen mScreen; |
62 | 64 |
private DistortedNode mRoot; |
63 |
private MeshRectangles mMeshRectangles;
|
|
65 |
private MeshQuad mMeshQuad;
|
|
64 | 66 |
private MeshCubes mMeshCubes; |
65 | 67 |
private boolean mDepth; |
66 | 68 |
private Static3D mScale; |
69 |
private float mLisaAspectRatio; |
|
67 | 70 |
|
68 | 71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
69 | 72 |
|
... | ... | |
76 | 79 |
chromaDyn.add(new Static1D(0.0f)); |
77 | 80 |
chromaDyn.add(new Static1D(0.8f)); |
78 | 81 |
|
79 |
mEffects= new DistortedEffects(); |
|
80 |
mEffects.apply(new MatrixEffectScale(mScale)); |
|
81 |
mEffects.apply(new FragmentEffectChroma(chromaDyn, new Static3D(0,0,1))); |
|
82 |
mEffectsNode= new DistortedEffects(); |
|
83 |
mEffectsNode.apply(new MatrixEffectScale(mScale)); |
|
84 |
mEffectsNode.apply(new FragmentEffectChroma(chromaDyn, new Static3D(0,0,1))); |
|
85 |
|
|
86 |
mEffectsGrid = new DistortedEffects(); |
|
87 |
|
|
88 |
float factor = NODE_FBO_SIZE/2; |
|
89 |
MatrixEffectScale scale = new MatrixEffectScale( new Static3D(factor,factor,factor/10) ); |
|
90 |
mEffectsGrid.apply(scale); |
|
91 |
|
|
92 |
Dynamic1D rotDyn = new Dynamic1D(12000,0.0f); |
|
93 |
rotDyn.add(new Static1D( 0)); |
|
94 |
rotDyn.add(new Static1D(360)); |
|
95 |
rotDyn.setMode(Dynamic.MODE_JUMP); |
|
96 |
MatrixEffectRotate rotate = new MatrixEffectRotate(rotDyn, new Static3D(1,0,0), new Static3D(0,0,0)); |
|
97 |
mEffectsGrid.apply(rotate); |
|
98 |
|
|
99 |
Dynamic1D sinkDyn = new Dynamic1D(3000,0.0f); |
|
100 |
sinkDyn.add(new Static1D(1.0f)); |
|
101 |
sinkDyn.add(new Static1D(0.3f)); |
|
102 |
VertexEffectSink sink = new VertexEffectSink(sinkDyn, new Static3D(0,0,0) ); |
|
103 |
mEffectsGrid.apply(sink); |
|
82 | 104 |
|
83 | 105 |
mScreen = new DistortedScreen(); |
84 | 106 |
} |
... | ... | |
116 | 138 |
|
117 | 139 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
118 | 140 |
{ |
119 |
float horiRatio = (float)width / mMeshRectangles.getStretchX();
|
|
120 |
float vertRatio = (float)height/ mMeshRectangles.getStretchY();
|
|
121 |
float factor = horiRatio > vertRatio ? vertRatio : horiRatio;
|
|
141 |
float hor = width /mLisaAspectRatio;
|
|
142 |
float ver = height;
|
|
143 |
float factor= hor>ver ? ver : hor;
|
|
122 | 144 |
|
123 | 145 |
mScale.set( factor,factor,factor ); |
124 | 146 |
mScreen.resize(width, height); |
... | ... | |
128 | 150 |
|
129 | 151 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
130 | 152 |
{ |
131 |
// TODO |
|
132 |
// This appears to be needed in case we create the app anew with NO DEPTH |
|
133 |
// (i.e. we set 'no depth' and then rotate screen). Investigate. |
|
134 |
GLES31.glEnable(GLES31.GL_CULL_FACE); |
|
135 |
GLES31.glCullFace(GLES31.GL_BACK); |
|
136 |
GLES31.glFrontFace(GLES31.GL_CW); |
|
137 |
|
|
138 | 153 |
Resources res = mView.getContext().getResources(); |
139 | 154 |
|
140 |
InputStream is1 = res.openRawResource(R.raw.monalisa);
|
|
141 |
InputStream is2 = res.openRawResource(R.raw.grid);
|
|
155 |
InputStream isLisa = res.openRawResource(R.raw.monalisa);
|
|
156 |
InputStream isGrid = res.openRawResource(R.raw.grid);
|
|
142 | 157 |
|
143 |
Bitmap bitmap1, bitmap2;
|
|
158 |
Bitmap bitmapLisa, bitmapGrid;
|
|
144 | 159 |
|
145 | 160 |
try |
146 | 161 |
{ |
147 |
bitmap1 = BitmapFactory.decodeStream(is1);
|
|
148 |
bitmap2 = BitmapFactory.decodeStream(is2);
|
|
162 |
bitmapLisa = BitmapFactory.decodeStream(isLisa);
|
|
163 |
bitmapGrid = BitmapFactory.decodeStream(isGrid);
|
|
149 | 164 |
} |
150 | 165 |
finally |
151 | 166 |
{ |
152 | 167 |
try |
153 | 168 |
{ |
154 |
is1.close();
|
|
155 |
is2.close();
|
|
169 |
isLisa.close();
|
|
170 |
isGrid.close();
|
|
156 | 171 |
} |
157 | 172 |
catch(IOException e) { } |
158 | 173 |
} |
159 | 174 |
|
160 |
final int GRID = 20; |
|
161 |
final Static4D mapFB = new Static4D(0.0f,0.0f,1.0f ,1.0f ); |
|
162 |
final Static4D mapLR = new Static4D(0.0f,0.0f,1.0f/GRID,1.0f ); |
|
163 |
final Static4D mapTB = new Static4D(0.0f,0.0f,1.0f ,1.0f/GRID); |
|
164 |
|
|
165 |
int lisaWidth = bitmap1.getWidth(); |
|
166 |
int lisaHeight= bitmap1.getHeight(); |
|
167 |
int gridWidth = bitmap2.getWidth(); |
|
168 |
int gridHeight= bitmap2.getHeight(); |
|
169 |
int gridDepth = gridWidth/GRID; |
|
175 |
mLisaAspectRatio = ((float)bitmapLisa.getWidth())/bitmapLisa.getHeight(); |
|
170 | 176 |
|
171 | 177 |
if( mLisaTexture==null ) mLisaTexture = new DistortedTexture(); |
172 | 178 |
if( mGridTexture==null ) mGridTexture = new DistortedTexture(); |
173 |
mLisaTexture.setTexture(bitmap1); |
|
174 |
mGridTexture.setTexture(bitmap2); |
|
175 |
|
|
176 |
DistortedEffects gridEffects = new DistortedEffects(); |
|
179 |
mLisaTexture.setTexture(bitmapLisa); |
|
180 |
mGridTexture.setTexture(bitmapGrid); |
|
177 | 181 |
|
178 |
if( mMeshRectangles ==null ) |
|
179 |
{ |
|
180 |
mMeshRectangles = new MeshRectangles(1,1); |
|
181 |
mMeshRectangles.setStretch(lisaWidth,lisaHeight,0); |
|
182 |
} |
|
182 |
final int GRID = 20; |
|
183 |
final Static4D mapFB = new Static4D(0.0f,0.0f,1.0f ,1.0f ); |
|
184 |
final Static4D mapLR = new Static4D(0.0f,0.0f,1.0f/GRID,1.0f ); |
|
185 |
final Static4D mapTB = new Static4D(0.0f,0.0f,1.0f ,1.0f/GRID); |
|
183 | 186 |
|
184 |
if( mMeshCubes==null) |
|
185 |
{ |
|
186 |
mMeshCubes= new MeshCubes(GRID,GRID,1, mapFB, mapFB, mapLR, mapLR, mapTB, mapTB); |
|
187 |
mMeshCubes.setStretch(gridWidth,gridHeight,gridDepth); |
|
188 |
} |
|
187 |
if( mMeshQuad ==null ) mMeshQuad = new MeshQuad(); |
|
188 |
if( mMeshCubes==null ) mMeshCubes= new MeshCubes(GRID,GRID,1, mapFB, mapFB, mapLR, mapLR, mapTB, mapTB); |
|
189 | 189 |
|
190 |
mRoot = new DistortedNode(mLisaTexture, mEffects, mMeshRectangles); |
|
191 |
mRoot.attach(mGridTexture,gridEffects,mMeshCubes); |
|
190 |
mRoot = new DistortedNode(mLisaTexture, mEffectsNode, mMeshQuad); |
|
191 |
mRoot.resizeFBO(NODE_FBO_SIZE,NODE_FBO_SIZE); |
|
192 |
mRoot.attach(mGridTexture, mEffectsGrid, mMeshCubes); |
|
192 | 193 |
|
193 | 194 |
setDepthPriv(); |
194 | 195 |
|
195 | 196 |
mScreen.detachAll(); |
196 | 197 |
mScreen.attach(mRoot); |
197 | 198 |
|
198 |
float factor = lisaWidth/(2.0f*gridWidth); |
|
199 |
MatrixEffectScale scale = new MatrixEffectScale( new Static3D(factor,factor,factor) ); |
|
200 |
gridEffects.apply(scale); |
|
201 |
|
|
202 |
Dynamic1D rotDyn = new Dynamic1D(12000,0.0f); |
|
203 |
rotDyn.add(new Static1D( 0)); |
|
204 |
rotDyn.add(new Static1D(360)); |
|
205 |
rotDyn.setMode(Dynamic.MODE_JUMP); |
|
206 |
MatrixEffectRotate rotate = new MatrixEffectRotate(rotDyn, new Static3D(1,0,0), new Static3D(0,0,0)); |
|
207 |
gridEffects.apply(rotate); |
|
208 |
|
|
209 |
Dynamic1D sinkDyn = new Dynamic1D(3000,0.0f); |
|
210 |
sinkDyn.add(new Static1D(1.0f)); |
|
211 |
sinkDyn.add(new Static1D(0.3f)); |
|
212 |
VertexEffectSink sink = new VertexEffectSink(sinkDyn, new Static3D(0,0,0) ); |
|
213 |
gridEffects.apply(sink); |
|
214 |
|
|
215 | 199 |
VertexEffectSink.enable(); |
216 | 200 |
FragmentEffectChroma.enable(); |
217 | 201 |
|
Also available in: Unified diff
Size of the FBO internal to Nodes is now NO MORE taken from the Mesh's stretch values.
Instead, the size is copied from child's FBO size (if there is one) or if the child is a leaf with texture in it (which is sizeless) then we get the default 100x100 ( which means we probably have to explicitly call Node.resizeFBO() )