Revision bd3da5b2
Added by Leszek Koltunski almost 8 years ago
src/main/java/org/distorted/library/Distorted.java | ||
---|---|---|
91 | 91 |
static int mTextureCoordH; // pass in model texture coordinate information. |
92 | 92 |
static int mProgramH; // This is a handle to our shading program. |
93 | 93 |
|
94 |
static DistortedProjection mProjection = new DistortedProjection(); |
|
95 |
static float mFOV = 60.0f; |
|
96 |
|
|
94 |
static DistortedRenderTarget mRenderTarget = new DistortedRenderTarget(0); |
|
95 |
|
|
97 | 96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
98 | 97 |
|
99 | 98 |
private Distorted() |
... | ... | |
293 | 292 |
*/ |
294 | 293 |
public static void setFov(float fov) |
295 | 294 |
{ |
296 |
mFOV = fov; |
|
297 |
|
|
298 |
if( mProjection.width>0 && mProjection.height>0 ) |
|
299 |
mProjection.onSurfaceChanged( mProjection.width, mProjection.height); |
|
295 |
mRenderTarget.setProjection(fov,0.0f,0.0f); |
|
300 | 296 |
} |
301 | 297 |
|
302 | 298 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
366 | 362 |
*/ |
367 | 363 |
public static void onSurfaceChanged(int surfaceWidth, int surfaceHeight) |
368 | 364 |
{ |
369 |
mProjection.onSurfaceChanged(surfaceWidth, surfaceHeight);
|
|
365 |
mRenderTarget.resize(surfaceWidth,surfaceHeight);
|
|
370 | 366 |
} |
371 | 367 |
|
372 | 368 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/library/DistortedNode.java | ||
---|---|---|
34 | 34 |
*/ |
35 | 35 |
public class DistortedNode |
36 | 36 |
{ |
37 |
private static final int TEXTURE_FAILED_TO_CREATE = -1;
|
|
38 |
private static final int TEXTURE_NOT_CREATED_YET = -2;
|
|
39 |
|
|
37 |
private static HashMap<ArrayList<Long>,NodeData> mMapNodeID = new HashMap<>();
|
|
38 |
private static long mNextNodeID =0;
|
|
39 |
|
|
40 | 40 |
private DistortedObject mObject; |
41 | 41 |
private NodeData mData; |
42 |
|
|
42 |
|
|
43 | 43 |
private DistortedNode mParent; |
44 | 44 |
private ArrayList<DistortedNode> mChildren; |
45 | 45 |
private int[] mNumChildren; // ==mChildren.length(), but we only create mChildren if the first one gets added |
46 |
|
|
47 |
private static HashMap<ArrayList<Long>,NodeData> mMapNodeID = new HashMap<>(); |
|
48 |
private static long mNextNodeID =0; |
|
49 | 46 |
|
50 |
////////////////////////////////////////////////////////////////// |
|
51 |
|
|
52 | 47 |
private class NodeData |
53 | 48 |
{ |
54 |
long ID;
|
|
49 |
long ID; |
|
55 | 50 |
int numPointingNodes; |
56 |
int mFramebufferID; |
|
57 |
int mTextureID; |
|
58 |
DistortedProjection mProjection; |
|
51 |
DistortedRenderTarget mDRT; |
|
59 | 52 |
boolean mRendered; |
60 |
|
|
61 |
////////////////////////////////////////////////////////////////// |
|
62 |
|
|
63 |
NodeData(long id) |
|
64 |
{ |
|
65 |
ID = id; |
|
66 |
numPointingNodes= 1; |
|
67 |
mFramebufferID = 0; |
|
68 |
mTextureID = TEXTURE_NOT_CREATED_YET; |
|
69 |
mProjection = null; |
|
70 |
mRendered = false; |
|
71 |
} |
|
72 |
|
|
73 |
////////////////////////////////////////////////////////////////// |
|
74 |
|
|
75 |
boolean createFBO() |
|
76 |
{ |
|
77 |
int[] textureIds = new int[1]; |
|
78 |
GLES20.glGenTextures(1, textureIds, 0); |
|
79 |
mTextureID = textureIds[0]; |
|
80 |
int[] mFBORenderToTexture = new int[1]; |
|
81 |
|
|
82 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureID); |
|
83 |
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST); |
|
84 |
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); |
|
85 |
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT); |
|
86 |
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT); |
|
87 |
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, mProjection.width, mProjection.height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null); |
|
88 |
|
|
89 |
GLES20.glGenFramebuffers(1, mFBORenderToTexture, 0); |
|
90 |
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFBORenderToTexture[0]); |
|
91 |
GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, mTextureID, 0); |
|
92 |
int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER); |
|
93 |
|
|
94 |
if(status != GLES20.GL_FRAMEBUFFER_COMPLETE) |
|
95 |
{ |
|
96 |
android.util.Log.e("Node", "failed to create framebuffer, error="+status); |
|
97 |
|
|
98 |
GLES20.glDeleteTextures(1, textureIds, 0); |
|
99 |
GLES20.glDeleteFramebuffers(1, mFBORenderToTexture, 0); |
|
100 |
mFramebufferID = 0; |
|
101 |
mTextureID = TEXTURE_FAILED_TO_CREATE; |
|
102 |
return false; |
|
103 |
} |
|
104 |
|
|
105 |
mFramebufferID = mFBORenderToTexture[0]; |
|
106 |
|
|
107 |
return true; |
|
108 |
} |
|
109 |
|
|
110 |
////////////////////////////////////////////////////////////////// |
|
111 | 53 |
|
112 |
void deleteFBO()
|
|
54 |
NodeData(long id)
|
|
113 | 55 |
{ |
114 |
int[] textureIds = new int[1]; |
|
115 |
int[] mFBORenderToTexture = new int[1]; |
|
116 |
|
|
117 |
textureIds[0] = mTextureID; |
|
118 |
mFBORenderToTexture[0] = mFramebufferID; |
|
119 |
|
|
120 |
GLES20.glDeleteTextures(1, textureIds, 0); |
|
121 |
GLES20.glDeleteFramebuffers(1, mFBORenderToTexture, 0); |
|
122 |
|
|
123 |
mFramebufferID = 0; |
|
124 |
mTextureID = TEXTURE_NOT_CREATED_YET; |
|
56 |
ID = id; |
|
57 |
numPointingNodes= 1; |
|
58 |
mDRT = null; |
|
59 |
mRendered = false; |
|
125 | 60 |
} |
126 |
} |
|
61 |
}
|
|
127 | 62 |
|
128 | 63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
129 | 64 |
|
... | ... | |
147 | 82 |
|
148 | 83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
149 | 84 |
|
150 |
private void drawRecursive(long currTime, DistortedProjection dp, int mFBO)
|
|
85 |
private void drawRecursive(long currTime, DistortedRenderTarget drt)
|
|
151 | 86 |
{ |
152 | 87 |
if( mNumChildren[0]<=0 ) |
153 | 88 |
{ |
154 | 89 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mObject.mTextureDataH[0]); |
155 |
|
|
156 |
if( mData.mProjection!=null ) |
|
157 |
{ |
|
158 |
mData.deleteFBO(); |
|
159 |
mData.mProjection = null; |
|
160 |
} |
|
161 | 90 |
} |
162 | 91 |
else |
163 | 92 |
{ |
164 | 93 |
if( mData.mRendered==false ) |
165 | 94 |
{ |
166 | 95 |
mData.mRendered = true; |
167 |
|
|
168 |
if( mData.mTextureID==TEXTURE_NOT_CREATED_YET ) mData.createFBO(); |
|
169 |
|
|
170 |
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mData.mFramebufferID); |
|
96 |
mData.mDRT.setOutput(); |
|
97 |
|
|
171 | 98 |
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
172 | 99 |
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); |
173 | 100 |
|
174 | 101 |
if( mObject.mBitmapSet[0] ) |
175 | 102 |
{ |
176 | 103 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mObject.mTextureDataH[0]); |
177 |
mObject.drawNoEffectsPriv(mData.mProjection);
|
|
104 |
mObject.drawNoEffectsPriv(mData.mDRT);
|
|
178 | 105 |
} |
179 | 106 |
|
180 | 107 |
synchronized(this) |
181 | 108 |
{ |
182 | 109 |
for(int i=0; i<mNumChildren[0]; i++) |
183 | 110 |
{ |
184 |
mChildren.get(i).drawRecursive(currTime, mData.mProjection, mData.mFramebufferID);
|
|
111 |
mChildren.get(i).drawRecursive(currTime, mData.mDRT);
|
|
185 | 112 |
} |
186 | 113 |
} |
187 | 114 |
} |
188 |
|
|
189 |
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFBO);
|
|
190 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mData.mTextureID); // this is safe because we must have called createFBO() above before.
|
|
115 |
|
|
116 |
drt.setOutput();
|
|
117 |
mData.mDRT.setInput(); // this is safe because we must have called createFBO() above before.
|
|
191 | 118 |
} |
192 | 119 |
|
193 |
mObject.drawPriv(currTime, dp);
|
|
120 |
mObject.drawPriv(currTime, drt);
|
|
194 | 121 |
} |
195 | 122 |
|
196 | 123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
246 | 173 |
if( otherNodesPoint ) mData = new NodeData(++mNextNodeID); |
247 | 174 |
else mData.ID = ++mNextNodeID; // numPointingNodes must be 1 already |
248 | 175 |
|
249 |
if( newList.size()>1 && mData.mProjection==null ) |
|
250 |
{ |
|
251 |
mData.mProjection = new DistortedProjection(); |
|
252 |
mData.mProjection.onSurfaceChanged(mObject.getWidth(), mObject.getHeight()); |
|
253 |
mData.mFramebufferID = 0; |
|
254 |
mData.mTextureID = TEXTURE_NOT_CREATED_YET; |
|
255 |
} |
|
256 |
|
|
176 |
if( newList.size()>1 && mData.mDRT==null ) |
|
177 |
mData.mDRT = new DistortedRenderTarget(mObject.getWidth(), mObject.getHeight()); |
|
178 |
|
|
257 | 179 |
mMapNodeID.put(newList, mData); |
258 | 180 |
} |
259 | 181 |
else |
... | ... | |
275 | 197 |
{ |
276 | 198 |
tmp = mMapNodeID.get(key); |
277 | 199 |
|
278 |
if( tmp.mProjection!=null )
|
|
200 |
if( tmp.mDRT != null )
|
|
279 | 201 |
{ |
280 |
tmp.mTextureID = TEXTURE_NOT_CREATED_YET;
|
|
202 |
tmp.mDRT.reset();
|
|
281 | 203 |
tmp.mRendered = false; |
282 | 204 |
} |
283 | 205 |
} |
... | ... | |
522 | 444 |
GLES20.glActiveTexture(GLES20.GL_TEXTURE0); |
523 | 445 |
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); |
524 | 446 |
GLES20.glUniform1i(Distorted.mTextureUniformH, 0); |
525 |
|
|
447 |
|
|
448 |
DistortedRenderTargetList.deleteAllMarked(); |
|
449 |
|
|
526 | 450 |
markRecursive(); |
527 |
drawRecursive(currTime,Distorted.mProjection,0);
|
|
451 |
drawRecursive(currTime,Distorted.mRenderTarget);
|
|
528 | 452 |
} |
529 | 453 |
|
530 | 454 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/library/DistortedObject.java | ||
---|---|---|
159 | 159 |
|
160 | 160 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
161 | 161 |
|
162 |
void drawPriv(long currTime, DistortedProjection dp)
|
|
162 |
void drawPriv(long currTime, DistortedRenderTarget drt)
|
|
163 | 163 |
{ |
164 |
GLES20.glViewport(0, 0, dp.width, dp.height);
|
|
164 |
GLES20.glViewport(0, 0, drt.mWidth, drt.mHeight);
|
|
165 | 165 |
|
166 | 166 |
mM.compute(currTime); |
167 |
mM.send(dp);
|
|
167 |
mM.send(drt);
|
|
168 | 168 |
|
169 | 169 |
mV.compute(currTime); |
170 | 170 |
mV.send(); |
... | ... | |
177 | 177 |
|
178 | 178 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
179 | 179 |
|
180 |
void drawNoEffectsPriv(DistortedProjection dp)
|
|
180 |
void drawNoEffectsPriv(DistortedRenderTarget drt)
|
|
181 | 181 |
{ |
182 |
GLES20.glViewport(0, 0, dp.width, dp.height);
|
|
183 |
mM.sendZero(dp);
|
|
182 |
GLES20.glViewport(0, 0, drt.mWidth, drt.mHeight);
|
|
183 |
mM.sendZero(drt);
|
|
184 | 184 |
mV.sendZero(); |
185 | 185 |
mF.sendZero(); |
186 | 186 |
mGrid.draw(); |
... | ... | |
275 | 275 |
GLES20.glUniform1i(Distorted.mTextureUniformH, 0); |
276 | 276 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]); |
277 | 277 |
|
278 |
drawPriv(currTime, Distorted.mProjection);
|
|
278 |
drawPriv(currTime, Distorted.mRenderTarget);
|
|
279 | 279 |
} |
280 | 280 |
|
281 | 281 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/library/DistortedProjection.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
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.Matrix; |
|
23 |
|
|
24 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
25 |
/** |
|
26 |
* Only used within the Distorted Library itself. |
|
27 |
*/ |
|
28 |
class DistortedProjection |
|
29 |
{ |
|
30 |
int width,height,depth,distance; |
|
31 |
float[] projectionMatrix; |
|
32 |
|
|
33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
34 |
|
|
35 |
DistortedProjection() |
|
36 |
{ |
|
37 |
projectionMatrix = new float[16]; |
|
38 |
} |
|
39 |
|
|
40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
41 |
|
|
42 |
void onSurfaceChanged(int surfaceWidth, int surfaceHeight) |
|
43 |
{ |
|
44 |
width = surfaceWidth; |
|
45 |
height= surfaceHeight; |
|
46 |
|
|
47 |
float ratio = (float) surfaceWidth / surfaceHeight; |
|
48 |
float left =-ratio; // |
|
49 |
float right = ratio; // Create a new perspective projection matrix. |
|
50 |
float bottom = -1.0f; // |
|
51 |
float top = 1.0f; // any change to those values will have serious consequences! |
|
52 |
float near, far; |
|
53 |
|
|
54 |
if( Distorted.mFOV>0.0f ) // perspective projection |
|
55 |
{ |
|
56 |
near= (float)(top / Math.tan(Distorted.mFOV*Math.PI/360)); |
|
57 |
distance = (int)(height*near/(top-bottom)); |
|
58 |
far = 2*distance-near; |
|
59 |
|
|
60 |
Matrix.frustumM(projectionMatrix, 0, left, right, bottom, top, near, far); |
|
61 |
} |
|
62 |
else // parallel projection |
|
63 |
{ |
|
64 |
near= (float)(top / Math.tan(Math.PI/360)); |
|
65 |
distance = (int)(height*near/(top-bottom)); |
|
66 |
far = 2*distance-near; |
|
67 |
|
|
68 |
Matrix.orthoM(projectionMatrix, 0, -surfaceWidth/2, surfaceWidth/2,-surfaceHeight/2, surfaceHeight/2, near, far); |
|
69 |
} |
|
70 |
|
|
71 |
depth = (int)((far-near)/2); |
|
72 |
} |
|
73 |
} |
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 |
} |
src/main/java/org/distorted/library/DistortedRenderTargetList.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
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 java.util.LinkedList; |
|
23 |
import java.util.Iterator; |
|
24 |
|
|
25 |
/** |
|
26 |
* List of all DistortedRenderTarget objects currently created by the application. |
|
27 |
* |
|
28 |
* The point: we need to be able ot mark RenderTargets for deletion, and delete all marked |
|
29 |
* objects later at a convenient time. Thus we keep all of them in a LinkedList here. |
|
30 |
*/ |
|
31 |
|
|
32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
33 |
|
|
34 |
final class DistortedRenderTargetList |
|
35 |
{ |
|
36 |
private static boolean mMarked = false; |
|
37 |
private static LinkedList<DistortedRenderTarget> mList = new LinkedList<>(); |
|
38 |
|
|
39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
40 |
|
|
41 |
static synchronized void add(DistortedRenderTarget drt) |
|
42 |
{ |
|
43 |
mList.add(drt); |
|
44 |
} |
|
45 |
|
|
46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
47 |
|
|
48 |
static synchronized void markForDeletion() |
|
49 |
{ |
|
50 |
mMarked = true; |
|
51 |
} |
|
52 |
|
|
53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
54 |
// must be called form a thread holding OpenGL Context |
|
55 |
|
|
56 |
static synchronized void deleteAllMarked() |
|
57 |
{ |
|
58 |
if( mMarked ) |
|
59 |
{ |
|
60 |
DistortedRenderTarget tmp; |
|
61 |
Iterator<DistortedRenderTarget> iterator = mList.iterator(); |
|
62 |
|
|
63 |
while(iterator.hasNext()) |
|
64 |
{ |
|
65 |
tmp = iterator.next(); |
|
66 |
|
|
67 |
if( tmp.mMarked ) |
|
68 |
{ |
|
69 |
tmp.release(); |
|
70 |
iterator.remove(); |
|
71 |
} |
|
72 |
} |
|
73 |
|
|
74 |
mMarked = false; |
|
75 |
} |
|
76 |
} |
|
77 |
} |
src/main/java/org/distorted/library/EffectQueueMatrix.java | ||
---|---|---|
153 | 153 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
154 | 154 |
// here construct the ModelView Matrix |
155 | 155 |
|
156 |
synchronized void send(DistortedProjection dp)
|
|
156 |
synchronized void send(DistortedRenderTarget drt)
|
|
157 | 157 |
{ |
158 | 158 |
Matrix.setIdentityM(mViewMatrix, 0); |
159 |
Matrix.translateM(mViewMatrix, 0, -dp.width/2, dp.height/2, -dp.distance);
|
|
159 |
Matrix.translateM(mViewMatrix, 0, -drt.mWidth/2, drt.mHeight/2, -drt.mDistance);
|
|
160 | 160 |
|
161 | 161 |
float x,y,z, sx,sy,sz; |
162 | 162 |
|
... | ... | |
230 | 230 |
} |
231 | 231 |
|
232 | 232 |
Matrix.translateM(mViewMatrix, 0, mObjHalfX,-mObjHalfY, 0); |
233 |
Matrix.multiplyMM(mMVPMatrix, 0, dp.projectionMatrix, 0, mViewMatrix, 0);
|
|
233 |
Matrix.multiplyMM(mMVPMatrix, 0, drt.mProjectionMatrix, 0, mViewMatrix, 0);
|
|
234 | 234 |
|
235 | 235 |
GLES20.glUniform3f( mObjDH , mObjHalfX, mObjHalfY, mObjHalfZ); |
236 |
GLES20.glUniform1f( mDepthH, dp.depth);
|
|
236 |
GLES20.glUniform1f( mDepthH, drt.mDepth);
|
|
237 | 237 |
GLES20.glUniformMatrix4fv(mMVMatrixH , 1, false, mViewMatrix, 0); |
238 | 238 |
GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0); |
239 | 239 |
} |
... | ... | |
241 | 241 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
242 | 242 |
// here construct the ModelView Matrix, but without any effects |
243 | 243 |
|
244 |
synchronized void sendZero(DistortedProjection dp)
|
|
244 |
synchronized void sendZero(DistortedRenderTarget drt)
|
|
245 | 245 |
{ |
246 | 246 |
Matrix.setIdentityM(mTmpMatrix, 0); |
247 |
Matrix.translateM(mTmpMatrix, 0, mObjHalfX-dp.width/2, dp.height/2-mObjHalfY, -dp.distance);
|
|
248 |
Matrix.multiplyMM(mMVPMatrix, 0, dp.projectionMatrix, 0, mTmpMatrix, 0);
|
|
247 |
Matrix.translateM(mTmpMatrix, 0, mObjHalfX-drt.mWidth/2, drt.mHeight/2-mObjHalfY, -drt.mDistance);
|
|
248 |
Matrix.multiplyMM(mMVPMatrix, 0, drt.mProjectionMatrix, 0, mTmpMatrix, 0);
|
|
249 | 249 |
|
250 | 250 |
GLES20.glUniform3f( mObjDH , mObjHalfX, mObjHalfY, mObjHalfZ); |
251 |
GLES20.glUniform1f( mDepthH, dp.depth);
|
|
251 |
GLES20.glUniform1f( mDepthH, drt.mDepth);
|
|
252 | 252 |
GLES20.glUniformMatrix4fv(mMVMatrixH , 1, false, mTmpMatrix, 0); |
253 | 253 |
GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix, 0); |
254 | 254 |
} |
Also available in: Unified diff
Move DistortedNode and Distorted to use the new DistortedRenderTarget.