1 |
f6fb3c6d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Distorted. //
|
5 |
|
|
// //
|
6 |
|
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
|
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
|
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
|
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
|
|
package org.distorted.library;
|
21 |
|
|
|
22 |
|
|
import android.opengl.GLES20;
|
23 |
|
|
import android.opengl.Matrix;
|
24 |
|
|
|
25 |
8e34674e
|
Leszek Koltunski
|
import java.util.Iterator;
|
26 |
|
|
import java.util.LinkedList;
|
27 |
|
|
|
28 |
f6fb3c6d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
29 |
dedacd82
|
Leszek Koltunski
|
/**
|
30 |
|
|
* Class which represents a OpenGL Framebuffer object.
|
31 |
71c3fecc
|
Leszek Koltunski
|
* <p>
|
32 |
65362dd4
|
Leszek Koltunski
|
* User is able to create either Framebuffers from objects already constructed outside
|
33 |
|
|
* of the library (the first constructor; primary use case: the screen) or an offscreen
|
34 |
e0b6c593
|
Leszek Koltunski
|
* FBOs.
|
35 |
71c3fecc
|
Leszek Koltunski
|
* <p>
|
36 |
e0b6c593
|
Leszek Koltunski
|
* Keep all objects created in a static LinkedList. The point: we need to be able to mark
|
37 |
8e34674e
|
Leszek Koltunski
|
* Framebuffers for deletion, and delete all marked objects later at a convenient time (that's
|
38 |
|
|
* because we can only delete from a thread that holds the OpenGL context so here we provide a
|
39 |
65362dd4
|
Leszek Koltunski
|
* framework where one is able to mark for deletion at any time and actual deletion takes place
|
40 |
8e34674e
|
Leszek Koltunski
|
* on the next render).
|
41 |
dedacd82
|
Leszek Koltunski
|
*/
|
42 |
ed13a5de
|
Leszek Koltunski
|
public class DistortedFramebuffer
|
43 |
f6fb3c6d
|
Leszek Koltunski
|
{
|
44 |
|
|
private static final int TEXTURE_FAILED_TO_CREATE = -1;
|
45 |
|
|
private static final int TEXTURE_NOT_CREATED_YET = -2;
|
46 |
b448e6b9
|
Leszek Koltunski
|
private static final int TEXTURE_DONT_CREATE = -3;
|
47 |
f6fb3c6d
|
Leszek Koltunski
|
|
48 |
8e34674e
|
Leszek Koltunski
|
private static boolean mListMarked = false;
|
49 |
|
|
private static LinkedList<DistortedFramebuffer> mList = new LinkedList<>();
|
50 |
|
|
|
51 |
1942537e
|
Leszek Koltunski
|
private float mX, mY, mFOV;
|
52 |
f6fb3c6d
|
Leszek Koltunski
|
|
53 |
7cf783cb
|
Leszek Koltunski
|
int[] texIds = new int[1];
|
54 |
|
|
int[] fboIds = new int[1];
|
55 |
7304d89f
|
Leszek Koltunski
|
|
56 |
8e34674e
|
Leszek Koltunski
|
private boolean mMarked;
|
57 |
|
|
|
58 |
e6cf7d50
|
Leszek Koltunski
|
int mWidth,mHeight,mDepth;
|
59 |
|
|
float mDistance;
|
60 |
f6fb3c6d
|
Leszek Koltunski
|
float[] mProjectionMatrix;
|
61 |
bd3da5b2
|
Leszek Koltunski
|
|
62 |
f6fb3c6d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
63 |
6537ba91
|
Leszek Koltunski
|
// Must be called from a thread holding OpenGL Context
|
64 |
f6fb3c6d
|
Leszek Koltunski
|
|
65 |
7cf783cb
|
Leszek Koltunski
|
boolean createFBO()
|
66 |
f6fb3c6d
|
Leszek Koltunski
|
{
|
67 |
7cf783cb
|
Leszek Koltunski
|
if( texIds[0]==TEXTURE_NOT_CREATED_YET )
|
68 |
|
|
{
|
69 |
|
|
GLES20.glGenTextures(1, texIds, 0);
|
70 |
|
|
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texIds[0]);
|
71 |
|
|
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
|
72 |
|
|
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
|
73 |
|
|
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
|
74 |
|
|
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);
|
75 |
|
|
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, mWidth, mHeight, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
|
76 |
f6fb3c6d
|
Leszek Koltunski
|
|
77 |
7cf783cb
|
Leszek Koltunski
|
GLES20.glGenFramebuffers(1, fboIds, 0);
|
78 |
|
|
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]);
|
79 |
|
|
GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, texIds[0], 0);
|
80 |
dedacd82
|
Leszek Koltunski
|
|
81 |
7cf783cb
|
Leszek Koltunski
|
int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
|
82 |
f6fb3c6d
|
Leszek Koltunski
|
|
83 |
7cf783cb
|
Leszek Koltunski
|
if(status != GLES20.GL_FRAMEBUFFER_COMPLETE)
|
84 |
|
|
{
|
85 |
|
|
android.util.Log.e("DistortedFramebuffer", "failed to create framebuffer, error="+status);
|
86 |
|
|
GLES20.glDeleteTextures(1, texIds, 0);
|
87 |
|
|
GLES20.glDeleteFramebuffers(1, fboIds, 0);
|
88 |
|
|
fboIds[0] = 0;
|
89 |
|
|
texIds[0] = TEXTURE_FAILED_TO_CREATE;
|
90 |
|
|
return false;
|
91 |
|
|
}
|
92 |
f6fb3c6d
|
Leszek Koltunski
|
|
93 |
7cf783cb
|
Leszek Koltunski
|
mList.add(this);
|
94 |
|
|
//android.util.Log.e("FBO", "created ("+mWidth+","+mHeight+") "+fboIds[0]);
|
95 |
|
|
}
|
96 |
16d8b8f3
|
Leszek Koltunski
|
|
97 |
f6fb3c6d
|
Leszek Koltunski
|
return true;
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
101 |
6537ba91
|
Leszek Koltunski
|
// Must be called from a thread holding OpenGL Context
|
102 |
f6fb3c6d
|
Leszek Koltunski
|
|
103 |
|
|
private void deleteFBO()
|
104 |
|
|
{
|
105 |
e6cf7d50
|
Leszek Koltunski
|
if( texIds[0]>=0 )
|
106 |
|
|
{
|
107 |
46e25345
|
Leszek Koltunski
|
//android.util.Log.e("FBO", "deleting ("+mWidth+","+mHeight+") "+fboIds[0]);
|
108 |
f6fb3c6d
|
Leszek Koltunski
|
|
109 |
e6cf7d50
|
Leszek Koltunski
|
GLES20.glDeleteTextures(1, texIds, 0);
|
110 |
|
|
GLES20.glDeleteFramebuffers(1, fboIds, 0);
|
111 |
bd3da5b2
|
Leszek Koltunski
|
|
112 |
e6cf7d50
|
Leszek Koltunski
|
fboIds[0] = 0;
|
113 |
|
|
texIds[0] = TEXTURE_NOT_CREATED_YET;
|
114 |
|
|
}
|
115 |
bd3da5b2
|
Leszek Koltunski
|
|
116 |
|
|
mMarked = false;
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
120 |
|
|
|
121 |
|
|
void reset()
|
122 |
|
|
{
|
123 |
1942537e
|
Leszek Koltunski
|
if( texIds[0]!=TEXTURE_DONT_CREATE)
|
124 |
|
|
texIds[0] = TEXTURE_NOT_CREATED_YET;
|
125 |
bd3da5b2
|
Leszek Koltunski
|
}
|
126 |
|
|
|
127 |
09d4f4b1
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
128 |
|
|
|
129 |
|
|
private void createProjection()
|
130 |
|
|
{
|
131 |
|
|
if( mWidth>0 && mHeight>1 )
|
132 |
|
|
{
|
133 |
|
|
if( mFOV>0.0f ) // perspective projection
|
134 |
|
|
{
|
135 |
|
|
float left = (-mX-mWidth /2.0f)/mHeight;
|
136 |
|
|
float right = (-mX+mWidth /2.0f)/mHeight;
|
137 |
|
|
float bottom = (-mY-mHeight/2.0f)/mHeight;
|
138 |
|
|
float top = (-mY+mHeight/2.0f)/mHeight;
|
139 |
|
|
float near = (top-bottom) / (2.0f*(float)Math.tan(mFOV*Math.PI/360));
|
140 |
|
|
mDistance = mHeight*near/(top-bottom);
|
141 |
|
|
float far = 2*mDistance-near;
|
142 |
|
|
mDepth = (int)((far-near)/2);
|
143 |
|
|
|
144 |
|
|
Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
|
145 |
|
|
}
|
146 |
|
|
else // parallel projection
|
147 |
|
|
{
|
148 |
|
|
float left = -mX-mWidth /2.0f;
|
149 |
|
|
float right = -mX+mWidth /2.0f;
|
150 |
|
|
float bottom = -mY-mHeight/2.0f;
|
151 |
|
|
float top = -mY+mHeight/2.0f;
|
152 |
|
|
float near = (mWidth+mHeight)/2;
|
153 |
|
|
mDistance = 2*near;
|
154 |
|
|
float far = 3*near;
|
155 |
|
|
mDepth = (int)near;
|
156 |
|
|
|
157 |
|
|
Matrix.orthoM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
|
158 |
|
|
}
|
159 |
|
|
}
|
160 |
|
|
}
|
161 |
|
|
|
162 |
8e34674e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
163 |
|
|
|
164 |
7b8086eb
|
Leszek Koltunski
|
static synchronized void onDestroy()
|
165 |
8e34674e
|
Leszek Koltunski
|
{
|
166 |
7cf783cb
|
Leszek Koltunski
|
// There are issues with this. Namely, if one
|
167 |
|
|
// 1. creates a DObjectTree (somewhere else than onSurfaceCreated of constructor so it does not get re-created on re-launch)
|
168 |
80ae684e
|
Leszek Koltunski
|
// 2. exits the app (here mList would be cleared)
|
169 |
7cf783cb
|
Leszek Koltunski
|
// 3. re-launches the app
|
170 |
|
|
// 4. deletes some nodes
|
171 |
|
|
// then the underlying Framebuffers will never be deleted!
|
172 |
|
|
|
173 |
8e34674e
|
Leszek Koltunski
|
mListMarked = false;
|
174 |
|
|
mList.clear();
|
175 |
|
|
}
|
176 |
|
|
|
177 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
178 |
|
|
// must be called form a thread holding OpenGL Context
|
179 |
|
|
|
180 |
|
|
static synchronized void deleteAllMarked()
|
181 |
|
|
{
|
182 |
|
|
if( mListMarked )
|
183 |
|
|
{
|
184 |
|
|
DistortedFramebuffer tmp;
|
185 |
|
|
Iterator<DistortedFramebuffer> iterator = mList.iterator();
|
186 |
|
|
|
187 |
|
|
while(iterator.hasNext())
|
188 |
|
|
{
|
189 |
|
|
tmp = iterator.next();
|
190 |
|
|
|
191 |
|
|
if( tmp.mMarked )
|
192 |
|
|
{
|
193 |
e6cf7d50
|
Leszek Koltunski
|
tmp.deleteFBO();
|
194 |
8e34674e
|
Leszek Koltunski
|
iterator.remove();
|
195 |
|
|
}
|
196 |
|
|
}
|
197 |
|
|
|
198 |
|
|
mListMarked = false;
|
199 |
|
|
}
|
200 |
|
|
}
|
201 |
57578636
|
Leszek Koltunski
|
|
202 |
f6fb3c6d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
203 |
|
|
// PUBLIC API
|
204 |
dedacd82
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
205 |
|
|
/**
|
206 |
57578636
|
Leszek Koltunski
|
* Create a new offscreen Framebuffer.
|
207 |
dedacd82
|
Leszek Koltunski
|
*
|
208 |
|
|
* @param width Width of the COLOR attachment.
|
209 |
|
|
* @param height Height of the COLOR attachment.
|
210 |
|
|
*/
|
211 |
1942537e
|
Leszek Koltunski
|
@SuppressWarnings("unused")
|
212 |
ed13a5de
|
Leszek Koltunski
|
public DistortedFramebuffer(int width, int height)
|
213 |
f6fb3c6d
|
Leszek Koltunski
|
{
|
214 |
|
|
mProjectionMatrix = new float[16];
|
215 |
|
|
|
216 |
57578636
|
Leszek Koltunski
|
mHeight = height;
|
217 |
|
|
mWidth = width;
|
218 |
|
|
fboIds[0]= -1;
|
219 |
|
|
texIds[0]= TEXTURE_NOT_CREATED_YET;
|
220 |
|
|
mFOV = 60.0f;
|
221 |
|
|
mX = 0.0f;
|
222 |
|
|
mY = 0.0f;
|
223 |
|
|
mMarked = false;
|
224 |
bd3da5b2
|
Leszek Koltunski
|
|
225 |
f6fb3c6d
|
Leszek Koltunski
|
createProjection();
|
226 |
|
|
}
|
227 |
|
|
|
228 |
b448e6b9
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
229 |
dedacd82
|
Leszek Koltunski
|
/**
|
230 |
57578636
|
Leszek Koltunski
|
* Create a new Framebuffer from an already created OpenGL Framebuffer.
|
231 |
|
|
* <p>
|
232 |
|
|
* Has to be followed by a 'resize()' to set the size.
|
233 |
dedacd82
|
Leszek Koltunski
|
*
|
234 |
|
|
* @param fbo the ID of a OpenGL Framebuffer object. Typically 0 (the screen)
|
235 |
|
|
*/
|
236 |
ed13a5de
|
Leszek Koltunski
|
public DistortedFramebuffer(int fbo)
|
237 |
b448e6b9
|
Leszek Koltunski
|
{
|
238 |
|
|
mProjectionMatrix = new float[16];
|
239 |
|
|
|
240 |
57578636
|
Leszek Koltunski
|
fboIds[0]= fbo;
|
241 |
|
|
texIds[0]= TEXTURE_DONT_CREATE;
|
242 |
|
|
mFOV = 60.0f;
|
243 |
|
|
mX = 0.0f;
|
244 |
|
|
mY = 0.0f;
|
245 |
|
|
mMarked = false;
|
246 |
b448e6b9
|
Leszek Koltunski
|
}
|
247 |
|
|
|
248 |
a0f644b7
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
249 |
|
|
/**
|
250 |
|
|
* Draw the (texture,grid,effects) object to the Framebuffer.
|
251 |
|
|
* <p>
|
252 |
d254d550
|
Leszek Koltunski
|
* Must be called from a thread holding OpenGL Context.
|
253 |
a0f644b7
|
Leszek Koltunski
|
*
|
254 |
|
|
* @param tex input Texture to use.
|
255 |
|
|
* @param grid Class descendant from GridObject
|
256 |
|
|
* @param effects The DistortedEffects to use when rendering
|
257 |
|
|
* @param time Current time, in milliseconds.
|
258 |
|
|
*/
|
259 |
|
|
public void renderTo(DistortedTexture tex, GridObject grid, DistortedEffects effects, long time)
|
260 |
|
|
{
|
261 |
|
|
tex.createTexture();
|
262 |
|
|
createFBO();
|
263 |
|
|
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]);
|
264 |
|
|
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex.mTextureDataH[0]);
|
265 |
52358355
|
Leszek Koltunski
|
effects.drawPriv(tex.mHalfX, tex.mHalfY, grid, this, time);
|
266 |
a0f644b7
|
Leszek Koltunski
|
DistortedFramebuffer.deleteAllMarked();
|
267 |
|
|
DistortedTexture.deleteAllMarked();
|
268 |
|
|
}
|
269 |
|
|
|
270 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
271 |
52358355
|
Leszek Koltunski
|
/**
|
272 |
|
|
* Draw the (framebuffer,grid,effects) object to the Framebuffer.
|
273 |
|
|
* <p>
|
274 |
d254d550
|
Leszek Koltunski
|
* Must be called from a thread holding OpenGL Context.
|
275 |
52358355
|
Leszek Koltunski
|
*
|
276 |
a0700272
|
Leszek Koltunski
|
* @param fbo The Framebuffer (previously created with the first constructor, drawing FROM the screen
|
277 |
|
|
* is unsupported!) whose COLOR attachment 0 will be used as input texture.
|
278 |
484a52a7
|
Leszek Koltunski
|
* Please note that rendering from an FBO to itself is unsupported by OpenGL!
|
279 |
52358355
|
Leszek Koltunski
|
* @param grid Class descendant from GridObject
|
280 |
|
|
* @param effects The DistortedEffects to use when rendering
|
281 |
|
|
* @param time Current time, in milliseconds.
|
282 |
|
|
*/
|
283 |
|
|
public void renderTo(DistortedFramebuffer fbo, GridObject grid, DistortedEffects effects, long time)
|
284 |
|
|
{
|
285 |
|
|
fbo.createFBO();
|
286 |
|
|
|
287 |
a0700272
|
Leszek Koltunski
|
if( fbo.texIds[0]>0 ) // fbo created with the first constructor
|
288 |
52358355
|
Leszek Koltunski
|
{
|
289 |
|
|
createFBO();
|
290 |
|
|
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]);
|
291 |
|
|
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, fbo.texIds[0]);
|
292 |
|
|
effects.drawPriv(fbo.mWidth/2, fbo.mHeight/2, grid, this, time);
|
293 |
|
|
DistortedFramebuffer.deleteAllMarked();
|
294 |
|
|
DistortedTexture.deleteAllMarked();
|
295 |
|
|
}
|
296 |
|
|
}
|
297 |
|
|
|
298 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
299 |
a0f644b7
|
Leszek Koltunski
|
/**
|
300 |
|
|
* Draws the Tree, and all its children, to the Framebuffer.
|
301 |
|
|
* <p>
|
302 |
d254d550
|
Leszek Koltunski
|
* Must be called from a thread holding OpenGL Context.
|
303 |
a0f644b7
|
Leszek Koltunski
|
*
|
304 |
|
|
* @param dt DistortedTree to render.
|
305 |
|
|
* @param time Current time, in milliseconds. This will be passed to all the Effects stored in the Tree.
|
306 |
|
|
*/
|
307 |
|
|
public void renderTo(DistortedTree dt, long time)
|
308 |
|
|
{
|
309 |
|
|
createFBO();
|
310 |
|
|
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]);
|
311 |
|
|
dt.drawRecursive(time,this);
|
312 |
|
|
DistortedFramebuffer.deleteAllMarked();
|
313 |
|
|
DistortedTexture.deleteAllMarked();
|
314 |
|
|
}
|
315 |
|
|
|
316 |
f6fb3c6d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
317 |
dedacd82
|
Leszek Koltunski
|
/**
|
318 |
|
|
* Mark the underlying OpenGL object for deletion. Actual deletion will take place on the next render.
|
319 |
|
|
*/
|
320 |
bd3da5b2
|
Leszek Koltunski
|
public void markForDeletion()
|
321 |
f6fb3c6d
|
Leszek Koltunski
|
{
|
322 |
46e25345
|
Leszek Koltunski
|
//android.util.Log.e("FBO", "marking for deletion ("+mWidth+","+mHeight+") "+fboIds[0]);
|
323 |
16d8b8f3
|
Leszek Koltunski
|
|
324 |
8e34674e
|
Leszek Koltunski
|
mListMarked = true;
|
325 |
|
|
mMarked = true;
|
326 |
f6fb3c6d
|
Leszek Koltunski
|
}
|
327 |
|
|
|
328 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
329 |
dedacd82
|
Leszek Koltunski
|
/**
|
330 |
|
|
* Create new Projection matrix.
|
331 |
|
|
*
|
332 |
|
|
* @param fov Vertical 'field of view' of the Projection frustrum (in degrees).
|
333 |
46a52b78
|
Leszek Koltunski
|
* @param x X-coordinate of the point at which our camera looks at. 0 is the center.
|
334 |
|
|
* @param y Y-coordinate of the point at which our camera looks at. 0 is the center.
|
335 |
dedacd82
|
Leszek Koltunski
|
*/
|
336 |
|
|
public void setProjection(float fov, float x, float y)
|
337 |
f6fb3c6d
|
Leszek Koltunski
|
{
|
338 |
dedacd82
|
Leszek Koltunski
|
mFOV = fov;
|
339 |
f6fb3c6d
|
Leszek Koltunski
|
mX = x;
|
340 |
|
|
mY = y;
|
341 |
|
|
|
342 |
|
|
createProjection();
|
343 |
|
|
}
|
344 |
|
|
|
345 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
346 |
dedacd82
|
Leszek Koltunski
|
/**
|
347 |
|
|
* Resize the underlying Framebuffer.
|
348 |
|
|
*
|
349 |
|
|
* As the Framebuffer is not created until the first render, typical usage of this API is actually
|
350 |
|
|
* to set the size of an not-yet-created Framebuffer of an object that has been created with the
|
351 |
|
|
* second constructor.
|
352 |
71c3fecc
|
Leszek Koltunski
|
* <p>
|
353 |
65362dd4
|
Leszek Koltunski
|
* Fully creating an object, rendering to it, then resizing mid-render is also possible. Actual
|
354 |
|
|
* resize takes place on the next render.
|
355 |
dedacd82
|
Leszek Koltunski
|
*
|
356 |
|
|
* @param width The new width.
|
357 |
|
|
* @param height The new height.
|
358 |
|
|
*/
|
359 |
f6fb3c6d
|
Leszek Koltunski
|
public void resize(int width, int height)
|
360 |
|
|
{
|
361 |
bd3da5b2
|
Leszek Koltunski
|
if( mWidth!=width || mHeight!=height )
|
362 |
|
|
{
|
363 |
|
|
mWidth = width;
|
364 |
|
|
mHeight= height;
|
365 |
f6fb3c6d
|
Leszek Koltunski
|
|
366 |
bd3da5b2
|
Leszek Koltunski
|
createProjection();
|
367 |
f6fb3c6d
|
Leszek Koltunski
|
|
368 |
7304d89f
|
Leszek Koltunski
|
if( texIds[0]>0 ) markForDeletion();
|
369 |
bd3da5b2
|
Leszek Koltunski
|
}
|
370 |
f6fb3c6d
|
Leszek Koltunski
|
}
|
371 |
d1e740c5
|
Leszek Koltunski
|
|
372 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
373 |
|
|
/**
|
374 |
09d4f4b1
|
Leszek Koltunski
|
* Return the ID of the Texture (COLOR attachment 0) that's backing this FBO.
|
375 |
|
|
* <p>
|
376 |
|
|
* Catch: this will only work if the library has had time to actually create the texture. Remember
|
377 |
|
|
* that the texture gets created only on first render, thus creating a Texture object and immediately
|
378 |
|
|
* calling this method will return an invalid (negative) result.
|
379 |
|
|
*
|
380 |
ab12f06b
|
Leszek Koltunski
|
* @return If there was not a single render between creation of the Object and calling this method on
|
381 |
|
|
* it, return a negative value. Otherwise, return ID of COLOR attachment 0.
|
382 |
d1e740c5
|
Leszek Koltunski
|
*/
|
383 |
09d4f4b1
|
Leszek Koltunski
|
public int getTextureID()
|
384 |
d1e740c5
|
Leszek Koltunski
|
{
|
385 |
09d4f4b1
|
Leszek Koltunski
|
return texIds[0];
|
386 |
d1e740c5
|
Leszek Koltunski
|
}
|
387 |
f6fb3c6d
|
Leszek Koltunski
|
}
|