Revision bd3da5b2
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/DistortedRenderTarget.java | ||
---|---|---|
37 | 37 |
int mWidth,mHeight,mDepth,mDistance; |
38 | 38 |
float[] mProjectionMatrix; |
39 | 39 |
|
40 |
boolean mMarked; |
|
41 |
|
|
40 | 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
41 | 43 |
|
42 | 44 |
private void createProjection() |
... | ... | |
107 | 109 |
} |
108 | 110 |
|
109 | 111 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
112 |
// must be called form a thread holding OpenGL Context |
|
110 | 113 |
|
111 | 114 |
private void deleteFBO() |
112 | 115 |
{ |
... | ... | |
123 | 126 |
mTextureID = TEXTURE_NOT_CREATED_YET; |
124 | 127 |
} |
125 | 128 |
|
129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
130 |
// must be called form a thread holding OpenGL Context |
|
131 |
|
|
132 |
void release() |
|
133 |
{ |
|
134 |
if( mTextureID>=0 ) deleteFBO(); |
|
135 |
|
|
136 |
mProjectionMatrix = null; |
|
137 |
mMarked = false; |
|
138 |
} |
|
139 |
|
|
140 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
141 |
|
|
142 |
void reset() |
|
143 |
{ |
|
144 |
mTextureID = TEXTURE_NOT_CREATED_YET; |
|
145 |
} |
|
146 |
|
|
126 | 147 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
127 | 148 |
// PUBLIC API |
128 | 149 |
|
... | ... | |
132 | 153 |
|
133 | 154 |
mHeight = height; |
134 | 155 |
mWidth = width; |
135 |
mFramebufferID = -1;
|
|
156 |
mFramebufferID = 0;
|
|
136 | 157 |
mTextureID = TEXTURE_NOT_CREATED_YET; |
137 | 158 |
mFOV = 60.0f; |
138 | 159 |
mX = 0.0f; |
139 | 160 |
mY = 0.0f; |
140 | 161 |
|
162 |
mMarked = false; |
|
163 |
|
|
141 | 164 |
createProjection(); |
142 | 165 |
} |
143 | 166 |
|
... | ... | |
152 | 175 |
mFOV = 60.0f; |
153 | 176 |
mX = 0.0f; |
154 | 177 |
mY = 0.0f; |
178 |
|
|
179 |
mMarked = false; |
|
155 | 180 |
} |
156 | 181 |
|
157 | 182 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
158 | 183 |
|
159 |
public void release()
|
|
184 |
public void markForDeletion()
|
|
160 | 185 |
{ |
161 |
if( mTextureID>=0 ) deleteFBO(); |
|
162 |
|
|
163 |
mProjectionMatrix = null; |
|
186 |
DistortedRenderTargetList.markForDeletion(); |
|
187 |
mMarked = true; |
|
164 | 188 |
} |
165 | 189 |
|
166 | 190 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
178 | 202 |
|
179 | 203 |
public void resize(int width, int height) |
180 | 204 |
{ |
181 |
mWidth = width; |
|
182 |
mHeight= height; |
|
205 |
if( mWidth!=width || mHeight!=height ) |
|
206 |
{ |
|
207 |
mWidth = width; |
|
208 |
mHeight= height; |
|
183 | 209 |
|
184 |
createProjection(); |
|
210 |
createProjection();
|
|
185 | 211 |
|
186 |
if( mTextureID>0 ) deleteFBO(); |
|
212 |
if( mTextureID>0 ) markForDeletion(); |
|
213 |
} |
|
187 | 214 |
} |
188 | 215 |
|
189 | 216 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
194 | 221 |
} |
195 | 222 |
|
196 | 223 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
197 |
// set this as Render Target. Must be called from a thread holding OpenGL context. |
|
224 |
// set this as Render Target to draw to. Must be called from a thread holding OpenGL context.
|
|
198 | 225 |
|
199 |
public void use()
|
|
226 |
public void setOutput()
|
|
200 | 227 |
{ |
201 | 228 |
if( mTextureID==TEXTURE_NOT_CREATED_YET ) createFBO(); |
202 | 229 |
|
203 | 230 |
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFramebufferID); |
204 | 231 |
} |
232 |
|
|
233 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
234 |
// set this as Render Target to draw from. Must be called from a thread holding OpenGL context. |
|
235 |
|
|
236 |
public void setInput() |
|
237 |
{ |
|
238 |
if( mTextureID==TEXTURE_NOT_CREATED_YET ) createFBO(); |
|
239 |
|
|
240 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureID); |
|
241 |
} |
|
242 |
|
|
205 | 243 |
} |
Also available in: Unified diff
Move DistortedNode and Distorted to use the new DistortedRenderTarget.