Revision 57578636
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/DistortedFramebuffer.java | ||
---|---|---|
67 | 67 |
{ |
68 | 68 |
if( mFOV>0.0f ) // perspective projection |
69 | 69 |
{ |
70 |
float left =(-mX-mWidth/2 )/mHeight; |
|
71 |
float right =(-mX+mWidth/2 )/mHeight; |
|
72 |
float bottom =(-mY-mHeight/2)/mHeight; |
|
73 |
float top =(-mY+mHeight/2)/mHeight; |
|
74 |
float near= (float)( (top-bottom) / (2*Math.tan(mFOV*Math.PI/360)) ); |
|
75 |
mDistance = (int)(mHeight*near/(top-bottom)); |
|
76 |
float far = 2*mDistance-near; |
|
77 |
mDepth = (int)((far-near)/2); |
|
70 |
float left = (-mX-mWidth/2 )/mHeight;
|
|
71 |
float right = (-mX+mWidth/2 )/mHeight;
|
|
72 |
float bottom = (-mY-mHeight/2)/mHeight;
|
|
73 |
float top = (-mY+mHeight/2)/mHeight;
|
|
74 |
float near = (float)( (top-bottom) / (2*Math.tan(mFOV*Math.PI/360)) );
|
|
75 |
mDistance = (int)(mHeight*near/(top-bottom));
|
|
76 |
float far = 2*mDistance-near;
|
|
77 |
mDepth = (int)((far-near)/2);
|
|
78 | 78 |
|
79 | 79 |
Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far); |
80 | 80 |
} |
81 | 81 |
else // parallel projection |
82 | 82 |
{ |
83 |
float left =-mX-mWidth/2; |
|
84 |
float right =-mX+mWidth/2; |
|
85 |
float bottom =-mY-mHeight/2; |
|
86 |
float top =-mY+mHeight/2; |
|
87 |
float near= (float)( (top-bottom) / (2*Math.tan(Math.PI/360)) ); |
|
88 |
mDistance = (int)(mHeight*near/(top-bottom)); |
|
89 |
float far = 2*mDistance-near; |
|
90 |
mDepth = (int)((far-near)/2); |
|
83 |
float left = -mX-mWidth/2;
|
|
84 |
float right = -mX+mWidth/2;
|
|
85 |
float bottom = -mY-mHeight/2;
|
|
86 |
float top = -mY+mHeight/2;
|
|
87 |
float near = (float)( (top-bottom) / (2*Math.tan(Math.PI/360)) );
|
|
88 |
mDistance = (int)(mHeight*near/(top-bottom));
|
|
89 |
float far = 2*mDistance-near;
|
|
90 |
mDepth = (int)((far-near)/2);
|
|
91 | 91 |
|
92 | 92 |
Matrix.orthoM(mProjectionMatrix, 0, left, right, bottom, top, near, far); |
93 | 93 |
} |
... | ... | |
193 | 193 |
mListMarked = false; |
194 | 194 |
} |
195 | 195 |
} |
196 |
|
|
197 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
198 |
// Set this as the Framebuffer to write to. |
|
199 |
|
|
200 |
void setAsOutput() |
|
201 |
{ |
|
202 |
if( texIds[0]==TEXTURE_NOT_CREATED_YET ) createFBO(); |
|
203 |
|
|
204 |
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]); |
|
205 |
} |
|
206 |
|
|
207 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
208 |
// Set this as the Framebuffer to read from. |
|
209 |
|
|
210 |
void setAsInput() |
|
211 |
{ |
|
212 |
if( texIds[0]==TEXTURE_NOT_CREATED_YET ) createFBO(); |
|
213 |
|
|
214 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texIds[0]); |
|
215 |
} |
|
216 |
|
|
196 | 217 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
197 | 218 |
// PUBLIC API |
198 | 219 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
199 | 220 |
/** |
200 |
* Create a new offscreen FBO.
|
|
221 |
* Create a new offscreen Framebuffer.
|
|
201 | 222 |
* |
202 | 223 |
* @param width Width of the COLOR attachment. |
203 | 224 |
* @param height Height of the COLOR attachment. |
... | ... | |
206 | 227 |
{ |
207 | 228 |
mProjectionMatrix = new float[16]; |
208 | 229 |
|
209 |
mHeight = height; |
|
210 |
mWidth = width; |
|
211 |
fboIds[0] = -1; |
|
212 |
texIds[0] = TEXTURE_NOT_CREATED_YET; |
|
213 |
mFOV = 60.0f; |
|
214 |
mX = 0.0f; |
|
215 |
mY = 0.0f; |
|
216 |
|
|
217 |
mMarked = false; |
|
230 |
mHeight = height; |
|
231 |
mWidth = width; |
|
232 |
fboIds[0]= -1; |
|
233 |
texIds[0]= TEXTURE_NOT_CREATED_YET; |
|
234 |
mFOV = 60.0f; |
|
235 |
mX = 0.0f; |
|
236 |
mY = 0.0f; |
|
237 |
mMarked = false; |
|
218 | 238 |
|
219 | 239 |
createProjection(); |
220 | 240 |
} |
221 | 241 |
|
222 | 242 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
223 | 243 |
/** |
224 |
* Create a new DistortedFramebuffer from an already created OpenGL Framebuffer. |
|
244 |
* Create a new Framebuffer from an already created OpenGL Framebuffer. |
|
245 |
* <p> |
|
246 |
* Has to be followed by a 'resize()' to set the size. |
|
225 | 247 |
* |
226 | 248 |
* @param fbo the ID of a OpenGL Framebuffer object. Typically 0 (the screen) |
227 | 249 |
*/ |
... | ... | |
229 | 251 |
{ |
230 | 252 |
mProjectionMatrix = new float[16]; |
231 | 253 |
|
232 |
fboIds[0] = fbo; |
|
233 |
texIds[0] = TEXTURE_DONT_CREATE; |
|
234 |
mFOV = 60.0f; |
|
235 |
mX = 0.0f; |
|
236 |
mY = 0.0f; |
|
237 |
|
|
238 |
mMarked = false; |
|
254 |
fboIds[0]= fbo; |
|
255 |
texIds[0]= TEXTURE_DONT_CREATE; |
|
256 |
mFOV = 60.0f; |
|
257 |
mX = 0.0f; |
|
258 |
mY = 0.0f; |
|
259 |
mMarked = false; |
|
239 | 260 |
} |
240 | 261 |
|
241 | 262 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
292 | 313 |
if( texIds[0]>0 ) markForDeletion(); |
293 | 314 |
} |
294 | 315 |
} |
295 |
|
|
296 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
297 |
/** |
|
298 |
* Set this as the Framebuffer to write to. |
|
299 |
*/ |
|
300 |
|
|
301 |
public void setAsOutput() |
|
302 |
{ |
|
303 |
if( texIds[0]==TEXTURE_NOT_CREATED_YET ) createFBO(); |
|
304 |
|
|
305 |
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]); |
|
306 |
} |
|
307 |
|
|
308 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
309 |
/** |
|
310 |
* Set this as the Framebuffer to read from. |
|
311 |
*/ |
|
312 |
|
|
313 |
public void setAsInput() |
|
314 |
{ |
|
315 |
if( texIds[0]==TEXTURE_NOT_CREATED_YET ) createFBO(); |
|
316 |
|
|
317 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texIds[0]); |
|
318 |
} |
|
319 |
|
|
320 | 316 |
} |
Also available in: Unified diff
Improvements for DFramebuffer.