Revision a436ccc5
Added by Leszek Koltunski about 7 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 |
} |
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.