Revision b6a5d557
Added by Leszek Koltunski almost 8 years ago
src/main/java/org/distorted/library/Distorted.java | ||
---|---|---|
27 | 27 |
import android.content.Context; |
28 | 28 |
import android.opengl.GLES20; |
29 | 29 |
import android.os.Build; |
30 |
import android.util.Log; |
|
31 | 30 |
|
32 | 31 |
import org.distorted.library.exception.*; |
33 | 32 |
|
... | ... | |
82 | 81 |
*/ |
83 | 82 |
public static final int CLONE_CHILDREN= 0x10; |
84 | 83 |
|
85 |
private static final String TAG = Distorted.class.getSimpleName(); |
|
86 | 84 |
private static boolean mInitialized = false; |
87 | 85 |
|
88 | 86 |
static int mPositionH; // model position information |
89 | 87 |
static int mNormalH; // model normal information. |
90 | 88 |
static int mTextureCoordH; // model texture coordinate information. |
91 | 89 |
|
92 |
static DistortedFramebuffer mFramebuffer = new DistortedFramebuffer(0); // output to the screen |
|
93 |
|
|
94 | 90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
95 | 91 |
|
96 | 92 |
private Distorted() |
... | ... | |
110 | 106 |
GLES20.glGetIntegerv(GLES20.GL_MAX_FRAGMENT_UNIFORM_VECTORS, param, 0); |
111 | 107 |
maxF = param[0]; |
112 | 108 |
|
113 |
Log.d(TAG, "Max vectors in vertex shader: "+maxV);
|
|
114 |
Log.d(TAG, "Max vectors in fragment shader: "+maxF);
|
|
109 |
//Log.d("Distorted", "Max vectors in vertex shader: "+maxV);
|
|
110 |
//Log.d("Distorted", "Max vectors in fragment shader: "+maxF);
|
|
115 | 111 |
|
116 | 112 |
if( !Build.FINGERPRINT.contains("generic") ) |
117 | 113 |
{ |
... | ... | |
200 | 196 |
final int[] numberOfUniforms = new int[1]; |
201 | 197 |
GLES20.glGetProgramiv(programHandle, GLES20.GL_ACTIVE_UNIFORMS, numberOfUniforms, 0); |
202 | 198 |
|
203 |
android.util.Log.d(TAG, "number of active uniforms="+numberOfUniforms[0]);
|
|
199 |
//android.util.Log.d("Distorted", "number of active uniforms="+numberOfUniforms[0]);
|
|
204 | 200 |
} |
205 | 201 |
|
206 | 202 |
return programHandle; |
... | ... | |
278 | 274 |
return readTextFileFromRawResource( c, R.raw.main_fragment_shader); |
279 | 275 |
} |
280 | 276 |
|
281 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
282 |
// Public API |
|
283 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
284 |
/** |
|
285 |
* Sets Vertical Field of View angle and the point the camera is looking at. This changes the Projection Matrix. |
|
286 |
* |
|
287 |
* @param fov Vertical Field Of View angle, in degrees. If T is the middle of the top edge of the |
|
288 |
* screen, E is the eye point, and B is the middle of the bottom edge of the screen, then |
|
289 |
* fov = angle(TEB) |
|
290 |
* @param x X-coordinate of the point the camera is looking at. -scrWidth/2 < x < scrWidth/2 |
|
291 |
* @param y Y-coordinate of the point the camera is looking at. -scrHeight/2 < y < scrHeight/2 |
|
292 |
*/ |
|
293 |
public static void setProjection(float fov, float x, float y) |
|
294 |
{ |
|
295 |
mFramebuffer.setProjection(fov,x,y); |
|
296 |
} |
|
297 |
|
|
298 | 277 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
299 | 278 |
/** |
300 | 279 |
* When OpenGL context gets created, you need to call this method so that the library can initialise its internal data structures. |
... | ... | |
324 | 303 |
|
325 | 304 |
int programH = createAndLinkProgram(vertexShaderHandle, fragmentShaderHandle, new String[] {"a_Position", "a_Color", "a_Normal", "a_TexCoordinate"}); |
326 | 305 |
|
327 |
mFramebuffer.setProjection(60.0f,0.0f,0.0f); |
|
328 |
|
|
329 | 306 |
GLES20.glUseProgram(programH); |
330 | 307 |
|
331 | 308 |
int textureUniformH = GLES20.glGetUniformLocation(programH, "u_Texture"); |
... | ... | |
354 | 331 |
DistortedObjectTree.reset(); |
355 | 332 |
EffectMessageSender.startSending(); |
356 | 333 |
} |
357 |
|
|
358 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
359 |
/** |
|
360 |
* Call this when the physical size of the surface we are rendering to changes. |
|
361 |
* I.e. must be called from GLSurfaceView.onSurfaceChanged() |
|
362 |
* |
|
363 |
* @param surfaceWidth new width of the surface. |
|
364 |
* @param surfaceHeight new height of the surface. |
|
365 |
*/ |
|
366 |
public static void onSurfaceChanged(int surfaceWidth, int surfaceHeight) |
|
367 |
{ |
|
368 |
mFramebuffer.resize(surfaceWidth,surfaceHeight); |
|
369 |
} |
|
370 | 334 |
|
371 | 335 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
372 | 336 |
/** |
src/main/java/org/distorted/library/DistortedEffectQueues.java | ||
---|---|---|
154 | 154 |
* Copy constructor. |
155 | 155 |
* <p> |
156 | 156 |
* Whatever we do not clone gets created just like in the default constructor. |
157 |
* We only call this from the descendant's classes' constructors where we have to pay attention |
|
158 |
* to give it the appropriate type of a DistortedObject! |
|
159 | 157 |
* |
160 | 158 |
* @param dc Source object to create our object from |
161 | 159 |
* @param flags A bitmask of values specifying what to copy. |
... | ... | |
169 | 167 |
|
170 | 168 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
171 | 169 |
/** |
172 |
* Draw the DistortedObject to the location specified by current Matrix effects. |
|
173 |
* <p> |
|
174 |
* Must be called from a thread holding OpenGL Context |
|
175 |
* |
|
176 |
* @param currTime current time, in milliseconds. |
|
177 |
* This gets passed on to Dynamics inside the Effects that are currently applied to the |
|
178 |
* Object. |
|
179 |
*/ |
|
180 |
public void draw(long currTime, DistortedTexture tex, GridObject grid) |
|
181 |
{ |
|
182 |
tex.createTexture(); |
|
183 |
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); |
|
184 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex.mTextureDataH[0]); |
|
185 |
drawPriv(currTime, tex, grid, Distorted.mFramebuffer); |
|
186 |
DistortedFramebuffer.deleteAllMarked(); |
|
187 |
DistortedTexture.deleteAllMarked(); |
|
188 |
} |
|
189 |
|
|
190 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
191 |
/** |
|
192 |
* Draw the DistortedObject to the Framebuffer passed. |
|
170 |
* Draw the (texture,grid) object to the Framebuffer passed. |
|
193 | 171 |
* <p> |
194 | 172 |
* Must be called from a thread holding OpenGL Context |
195 | 173 |
* |
src/main/java/org/distorted/library/DistortedObjectTree.java | ||
---|---|---|
449 | 449 |
RecomputeNodeID(prev); |
450 | 450 |
} |
451 | 451 |
} |
452 |
|
|
453 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
454 |
/** |
|
455 |
* Draws the Node, and all its children, to the default framebuffer 0 (i.e. the screen). |
|
456 |
* <p> |
|
457 |
* Must be called from a thread holding OpenGL Context |
|
458 |
* |
|
459 |
* @param currTime Current time, in milliseconds. |
|
460 |
*/ |
|
461 |
public void draw(long currTime) |
|
462 |
{ |
|
463 |
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); |
|
464 |
drawRecursive(currTime,Distorted.mFramebuffer); |
|
465 |
DistortedFramebuffer.deleteAllMarked(); |
|
466 |
DistortedTexture.deleteAllMarked(); |
|
467 |
} |
|
468 | 452 |
|
469 | 453 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
470 | 454 |
/** |
Also available in: Unified diff
Change in the API: we always have to create a DistortedFramebuffer to render to.