Revision a436ccc5
Added by Leszek Koltunski almost 8 years ago
src/main/java/org/distorted/library/DistortedFramebuffer.java | ||
---|---|---|
30 | 30 |
*/ |
31 | 31 |
public class DistortedFramebuffer extends DistortedOutputSurface implements DistortedInputSurface |
32 | 32 |
{ |
33 |
private int[] mDepthH = new int[1]; |
|
34 |
private int[] mFBOH = new int[1]; |
|
35 |
private boolean mDepthEnabled; |
|
36 | 33 |
|
37 | 34 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
38 | 35 |
// Must be called from a thread holding OpenGL Context |
... | ... | |
160 | 157 |
// create 'system' Framebuffers, i.e. those that are used internally by the library. |
161 | 158 |
// Those do not get removed in onDestroy(); |
162 | 159 |
|
163 |
public DistortedFramebuffer(boolean depthEnabled, int width, int height)
|
|
160 |
DistortedFramebuffer(boolean depthEnabled, int width, int height) |
|
164 | 161 |
{ |
165 |
super(width,height,NOT_CREATED_YET,true); |
|
166 |
mDepthEnabled= depthEnabled; |
|
167 |
mFBOH[0] = NOT_CREATED_YET; |
|
168 |
mDepthH[0] = NOT_CREATED_YET; |
|
162 |
super(width,height,NOT_CREATED_YET,NOT_CREATED_YET,true, depthEnabled); |
|
169 | 163 |
} |
170 | 164 |
|
171 | 165 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
181 | 175 |
@SuppressWarnings("unused") |
182 | 176 |
public DistortedFramebuffer(int width, int height, boolean depthEnabled) |
183 | 177 |
{ |
184 |
super(width,height,NOT_CREATED_YET,false); |
|
185 |
mDepthEnabled= depthEnabled; |
|
186 |
mFBOH[0] = NOT_CREATED_YET; |
|
187 |
mDepthH[0] = NOT_CREATED_YET; |
|
178 |
super(width,height,NOT_CREATED_YET,NOT_CREATED_YET,false, depthEnabled); |
|
188 | 179 |
} |
189 | 180 |
|
190 | 181 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
198 | 189 |
@SuppressWarnings("unused") |
199 | 190 |
public DistortedFramebuffer(int width, int height) |
200 | 191 |
{ |
201 |
super(width,height,NOT_CREATED_YET,false); |
|
202 |
mDepthEnabled= false; |
|
203 |
mFBOH[0] = NOT_CREATED_YET; |
|
204 |
mDepthH[0] = NOT_CREATED_YET; |
|
192 |
super(width,height,NOT_CREATED_YET,NOT_CREATED_YET,false,false); |
|
205 | 193 |
} |
206 | 194 |
|
207 | 195 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
208 | 196 |
/** |
209 | 197 |
* Bind the underlying rectangle of pixels as a OpenGL Texture. |
210 | 198 |
* |
211 |
* @returns <code>true</code> if successful.
|
|
199 |
* @return <code>true</code> if successful. |
|
212 | 200 |
*/ |
213 | 201 |
public boolean setAsInput() |
214 | 202 |
{ |
... | ... | |
221 | 209 |
return false; |
222 | 210 |
} |
223 | 211 |
|
224 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
225 |
/** |
|
226 |
* Bind this Surface as a Framebuffer we can render to. |
|
227 |
*/ |
|
228 |
public void setAsOutput() |
|
229 |
{ |
|
230 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[0]); |
|
231 |
|
|
232 |
if( mDepthH[0]!=NOT_CREATED_YET ) |
|
233 |
{ |
|
234 |
GLES30.glEnable(GLES30.GL_DEPTH_TEST); |
|
235 |
GLES30.glDepthMask(true); |
|
236 |
} |
|
237 |
else |
|
238 |
{ |
|
239 |
GLES30.glDisable(GLES30.GL_DEPTH_TEST); |
|
240 |
GLES30.glDepthMask(false); |
|
241 |
} |
|
242 |
} |
|
243 |
|
|
244 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
245 |
/** |
|
246 |
* Create a new DEPTH buffer and attach it or (param=false) detach an existing DEPTh attachment and recreate it. |
|
247 |
* |
|
248 |
* @param enable <bold>true</bold> if we want to attach a new DEPTH buffer to the FBO.<br> |
|
249 |
* <bold>false</bold> if we want to detach the DEPTH attachment. |
|
250 |
*/ |
|
251 |
public void enableDepthAttachment(boolean enable) |
|
252 |
{ |
|
253 |
if( mDepthEnabled!=enable ) |
|
254 |
{ |
|
255 |
mDepthEnabled = enable; |
|
256 |
moveToToDo(); |
|
257 |
} |
|
258 |
} |
|
259 |
|
|
260 | 212 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
261 | 213 |
/** |
262 | 214 |
* Return the ID of the Texture (COLOR attachment 0) that's backing this FBO. |
... | ... | |
272 | 224 |
{ |
273 | 225 |
return mColorH[0]; |
274 | 226 |
} |
275 |
|
|
276 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
277 |
/** |
|
278 |
* Return true if the FBO contains a DEPTH attachment. |
|
279 |
* |
|
280 |
* @return <bold>true</bold> if the FBO contains a DEPTH attachment. |
|
281 |
*/ |
|
282 |
public boolean hasDepth() |
|
283 |
{ |
|
284 |
return mDepthEnabled; |
|
285 |
} |
|
286 | 227 |
} |
src/main/java/org/distorted/library/DistortedOutputSurface.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.library; |
21 | 21 |
|
22 |
import android.opengl.GLES30; |
|
22 | 23 |
import android.opengl.Matrix; |
23 | 24 |
import java.util.ArrayList; |
24 | 25 |
|
... | ... | |
34 | 35 |
float mDistance; |
35 | 36 |
float[] mProjectionMatrix; |
36 | 37 |
|
38 |
boolean mDepthEnabled; |
|
39 |
int[] mDepthH = new int[1]; |
|
40 |
int[] mFBOH = new int[1]; |
|
41 |
|
|
37 | 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
38 | 43 |
|
39 |
DistortedOutputSurface(int width, int height, int color, boolean system)
|
|
44 |
DistortedOutputSurface(int width, int height, int color, int fbo, boolean system, boolean depth)
|
|
40 | 45 |
{ |
41 | 46 |
super(width,height,color,system); |
42 | 47 |
|
... | ... | |
49 | 54 |
mX = 0.0f; |
50 | 55 |
mY = 0.0f; |
51 | 56 |
|
57 |
mDepthEnabled= depth; |
|
58 |
mFBOH[0] = fbo; |
|
59 |
mDepthH[0] = color; |
|
60 |
|
|
52 | 61 |
createProjection(); |
53 | 62 |
} |
54 | 63 |
|
... | ... | |
136 | 145 |
/** |
137 | 146 |
* Bind this Surface as a Framebuffer we can render to. |
138 | 147 |
*/ |
139 |
public abstract void setAsOutput(); |
|
148 |
public void setAsOutput() |
|
149 |
{ |
|
150 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[0]); |
|
151 |
|
|
152 |
if( mDepthEnabled && mDepthH[0]!=NOT_CREATED_YET ) |
|
153 |
{ |
|
154 |
GLES30.glEnable(GLES30.GL_DEPTH_TEST); |
|
155 |
GLES30.glDepthMask(true); |
|
156 |
} |
|
157 |
else |
|
158 |
{ |
|
159 |
GLES30.glDisable(GLES30.GL_DEPTH_TEST); |
|
160 |
GLES30.glDepthMask(false); |
|
161 |
} |
|
162 |
} |
|
140 | 163 |
|
141 | 164 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
142 | 165 |
/** |
... | ... | |
181 | 204 |
} |
182 | 205 |
} |
183 | 206 |
|
207 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
208 |
/** |
|
209 |
* Create a new DEPTH buffer and attach it or (param=false) detach an existing DEPTH attachment and recreate it. |
|
210 |
* |
|
211 |
* @param enable <bold>true</bold> if we want to attach a new DEPTH buffer to the FBO.<br> |
|
212 |
* <bold>false</bold> if we want to detach the DEPTH attachment. |
|
213 |
*/ |
|
214 |
public void enableDepth(boolean enable) |
|
215 |
{ |
|
216 |
if( mDepthEnabled!=enable ) |
|
217 |
{ |
|
218 |
mDepthEnabled = enable; |
|
219 |
moveToToDo(); |
|
220 |
} |
|
221 |
} |
|
222 |
|
|
223 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
224 |
/** |
|
225 |
* Return true if the Surface contains a DEPTH attachment. |
|
226 |
* |
|
227 |
* @return <bold>true</bold> if the FBO contains a DEPTH attachment. |
|
228 |
*/ |
|
229 |
public boolean hasDepth() |
|
230 |
{ |
|
231 |
return mDepthEnabled; |
|
232 |
} |
|
233 |
|
|
184 | 234 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
185 | 235 |
/** |
186 | 236 |
* Adds a new child to the last position in the list of our Surface's children. |
src/main/java/org/distorted/library/DistortedScreen.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.library; |
21 | 21 |
|
22 |
import android.opengl.GLES30; |
|
23 |
|
|
24 | 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
25 | 23 |
/** |
26 | 24 |
* Class which represents the Screen. |
... | ... | |
32 | 30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
33 | 31 |
// here we don't manage underlying OpenGL assets ourselves |
34 | 32 |
|
35 |
void create() {} |
|
36 |
void delete() {} |
|
33 |
void create() {}
|
|
34 |
void delete() {}
|
|
37 | 35 |
void recreate() {} |
38 | 36 |
|
39 | 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
46 | 44 |
*/ |
47 | 45 |
public DistortedScreen() |
48 | 46 |
{ |
49 |
super(0,0,DONT_CREATE,false); |
|
50 |
} |
|
51 |
|
|
52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 |
/** |
|
54 |
* Bind this Surface as a Framebuffer we can render to. |
|
55 |
*/ |
|
56 |
public void setAsOutput() |
|
57 |
{ |
|
58 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0); |
|
59 |
GLES30.glEnable(GLES30.GL_DEPTH_TEST); |
|
60 |
GLES30.glDepthMask(true); |
|
47 |
super(0,0,DONT_CREATE,0,false,true); |
|
61 | 48 |
} |
62 | 49 |
} |
Also available in: Unified diff
1. Make it possible to enable/disable DEPTH test when rendering to a Screen
2. Using this, remove the 'Root' Node from StarWars.