* master: (94 commits) First attempt to fix a bug reported by david_bernard_31, the size of the strings in the shader code was wrongly computed for the JOGL backend Allows to choose between the forward compatible profile and the backward compatible profile in the JOGL backend Displays the JOGL version instead of the NEWT version Updates JOGL (2.3.2) Bugfix: fix to importing blend files with linked content. native loader: set lwjgl library path for lwjgl3 Updated lwjgl3 module to use LWJGL 3.0.0b #35 which is the current stable build. Change duplicated docstring in FlyByCamera.unregisterInput light : fixed pointLight v. bounding sphere unit test light : replaced duplicated code by methods from Intersection Removed native library jemalloc.dll for LWJGL3 as this will not be needed until 3.0.0b and after. light : added unit tests for the new support of bounding spheres intersections (for lightFilter) Fixed Issue #46 : The MaterialViewer will now simply ignore not available textures instead of crashing Lights (see #362) : added light v. sphere intersection, and implementations of intersectsSphere(), second attempt GImpactCollisionShape : fix for #188, added a call to updateBound() in native jni binding, just after creating the shape, (native createShape() method) Bugfix: fixed a bug that caused importer to crash when the author of the blend file assigned non existing UV coordinates group name to a mesh. Bugfix: fixed a bug that caused subdivision surface modifier to crash if at least one not connected vertex was in the mesh. The LWJGL 3 renderer was missing a call to GLContext.createFromCurrent(), sorted now. Changed the default app title in AppSettings to use the full name string from JmeVersion. This way no more manual changing of this will be needed for future versions. This also closes #320 which highlighted this issue. Thanks @8Keep. Fixed #316 where some post processing effects were not working when using OPENGL_3 renderer due to an error in the fragment shader. ...define_list_fix
commit
c47da8e9a1
@ -1,14 +0,0 @@ |
||||
#if __VERSION__ >= 130 |
||||
out vec4 outFragColor; |
||||
# define texture1D texture |
||||
# define texture2D texture |
||||
# define texture3D texture |
||||
# define texture2DLod texture |
||||
# if defined VERTEX_SHADER |
||||
# define varying out |
||||
# define attribute in |
||||
# elif defined FRAGMENT_SHADER |
||||
# define varying in |
||||
# define gl_FragColor outFragColor |
||||
# endif |
||||
#endif |
@ -0,0 +1,34 @@ |
||||
#if defined GL_ES |
||||
# define hfloat highp float |
||||
# define hvec2 highp vec2 |
||||
# define hvec3 highp vec3 |
||||
# define hvec4 highp vec4 |
||||
# define lfloat lowp float |
||||
# define lvec2 lowp vec2 |
||||
# define lvec3 lowp vec3 |
||||
# define lvec4 lowp vec4 |
||||
#else |
||||
# define hfloat float |
||||
# define hvec2 vec2 |
||||
# define hvec3 vec3 |
||||
# define hvec4 vec4 |
||||
# define lfloat float |
||||
# define lvec2 vec2 |
||||
# define lvec3 vec3 |
||||
# define lvec4 vec4 |
||||
#endif |
||||
|
||||
#if __VERSION__ >= 130 |
||||
out vec4 outFragColor; |
||||
# define texture1D texture |
||||
# define texture2D texture |
||||
# define texture3D texture |
||||
# define texture2DLod texture |
||||
# if defined VERTEX_SHADER |
||||
# define varying out |
||||
# define attribute in |
||||
# elif defined FRAGMENT_SHADER |
||||
# define varying in |
||||
# define gl_FragColor outFragColor |
||||
# endif |
||||
#endif |
@ -0,0 +1,203 @@ |
||||
/* |
||||
* Copyright (c) 2009-2015 jMonkeyEngine |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* |
||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
package com.jme3.collision; |
||||
|
||||
import static com.jme3.collision.CollisionUtil.*; |
||||
|
||||
import com.jme3.bounding.BoundingBox; |
||||
import com.jme3.bounding.BoundingSphere; |
||||
import com.jme3.math.FastMath; |
||||
import com.jme3.math.Ray; |
||||
import com.jme3.math.Vector3f; |
||||
import com.jme3.scene.Geometry; |
||||
import com.jme3.scene.shape.Quad; |
||||
import org.junit.Test; |
||||
|
||||
/** |
||||
* Tests collision detection between bounding volumes. |
||||
* |
||||
* @author Kirill Vainer |
||||
*/ |
||||
public class BoundingCollisionTest { |
||||
|
||||
@Test |
||||
public void testBoxBoxCollision() { |
||||
BoundingBox box1 = new BoundingBox(Vector3f.ZERO, 1, 1, 1); |
||||
BoundingBox box2 = new BoundingBox(Vector3f.ZERO, 1, 1, 1); |
||||
checkCollision(box1, box2, 1); |
||||
|
||||
// Put it at the very edge - should still intersect.
|
||||
box2.setCenter(new Vector3f(2f, 0f, 0f)); |
||||
checkCollision(box1, box2, 1); |
||||
|
||||
// Put it a wee bit farther - no intersection expected
|
||||
box2.setCenter(new Vector3f(2f + FastMath.ZERO_TOLERANCE, 0, 0)); |
||||
checkCollision(box1, box2, 0); |
||||
|
||||
// Check the corners.
|
||||
box2.setCenter(new Vector3f(2f, 2f, 2f)); |
||||
checkCollision(box1, box2, 1); |
||||
|
||||
box2.setCenter(new Vector3f(2f, 2f, 2f + FastMath.ZERO_TOLERANCE)); |
||||
checkCollision(box1, box2, 0); |
||||
} |
||||
|
||||
@Test |
||||
public void testSphereSphereCollision() { |
||||
BoundingSphere sphere1 = new BoundingSphere(1, Vector3f.ZERO); |
||||
BoundingSphere sphere2 = new BoundingSphere(1, Vector3f.ZERO); |
||||
checkCollision(sphere1, sphere2, 1); |
||||
|
||||
// Put it at the very edge - should still intersect.
|
||||
sphere2.setCenter(new Vector3f(2f, 0f, 0f)); |
||||
checkCollision(sphere1, sphere2, 1); |
||||
|
||||
// Put it a wee bit farther - no intersection expected
|
||||
sphere2.setCenter(new Vector3f(2f + FastMath.ZERO_TOLERANCE, 0, 0)); |
||||
checkCollision(sphere1, sphere2, 0); |
||||
} |
||||
|
||||
@Test |
||||
public void testBoxSphereCollision() { |
||||
BoundingBox box1 = new BoundingBox(Vector3f.ZERO, 1, 1, 1); |
||||
BoundingSphere sphere2 = new BoundingSphere(1, Vector3f.ZERO); |
||||
checkCollision(box1, sphere2, 1); |
||||
|
||||
// Put it at the very edge - for sphere vs. box, it will not intersect
|
||||
sphere2.setCenter(new Vector3f(2f, 0f, 0f)); |
||||
checkCollision(box1, sphere2, 0); |
||||
|
||||
// Put it a wee bit closer - should intersect.
|
||||
sphere2.setCenter(new Vector3f(2f - FastMath.ZERO_TOLERANCE, 0, 0)); |
||||
checkCollision(box1, sphere2, 1); |
||||
|
||||
// Test if the algorithm converts the sphere
|
||||
// to a box before testing the collision (incorrect)
|
||||
float sqrt3 = FastMath.sqrt(3); |
||||
|
||||
sphere2.setCenter(Vector3f.UNIT_XYZ.mult(2)); |
||||
sphere2.setRadius(sqrt3); |
||||
checkCollision(box1, sphere2, 0); |
||||
|
||||
// Make it a wee bit larger.
|
||||
sphere2.setRadius(sqrt3 + FastMath.ZERO_TOLERANCE); |
||||
checkCollision(box1, sphere2, 1); |
||||
} |
||||
|
||||
@Test |
||||
public void testBoxRayCollision() { |
||||
BoundingBox box = new BoundingBox(Vector3f.ZERO, 1, 1, 1); |
||||
Ray ray = new Ray(Vector3f.ZERO, Vector3f.UNIT_Z); |
||||
|
||||
// XXX: seems incorrect, ray inside box should only generate
|
||||
// one result...
|
||||
checkCollision(box, ray, 2); |
||||
|
||||
ray.setOrigin(new Vector3f(0, 0, -5)); |
||||
checkCollision(box, ray, 2); |
||||
|
||||
// XXX: is this right? the ray origin is on the box's side..
|
||||
ray.setOrigin(new Vector3f(0, 0, 2f)); |
||||
checkCollision(box, ray, 0); |
||||
|
||||
ray.setOrigin(new Vector3f(0, 0, -2f)); |
||||
checkCollision(box, ray, 2); |
||||
|
||||
// parallel to the edge, touching the side
|
||||
ray.setOrigin(new Vector3f(0, 1f, -2f)); |
||||
checkCollision(box, ray, 2); |
||||
|
||||
// still parallel, but not touching the side
|
||||
ray.setOrigin(new Vector3f(0, 1f + FastMath.ZERO_TOLERANCE, -2f)); |
||||
checkCollision(box, ray, 0); |
||||
} |
||||
|
||||
@Test |
||||
public void testBoxTriangleCollision() { |
||||
BoundingBox box = new BoundingBox(Vector3f.ZERO, 1, 1, 1); |
||||
Geometry geom = new Geometry("geom", new Quad(1, 1)); |
||||
checkCollision(box, geom, 2); // Both triangles intersect
|
||||
|
||||
// The box touches the edges of the triangles.
|
||||
box.setCenter(new Vector3f(-1f, 0, 0)); |
||||
checkCollision(box, geom, 2); |
||||
|
||||
// Move it slightly farther..
|
||||
box.setCenter(new Vector3f(-1f - FastMath.ZERO_TOLERANCE, 0, 0)); |
||||
checkCollision(box, geom, 0); |
||||
|
||||
// Parallel triangle / box side, touching
|
||||
box.setCenter(new Vector3f(0, 0, -1f)); |
||||
checkCollision(box, geom, 2); |
||||
|
||||
// Not touching
|
||||
box.setCenter(new Vector3f(0, 0, -1f - FastMath.ZERO_TOLERANCE)); |
||||
checkCollision(box, geom, 0); |
||||
|
||||
// Test collisions only against one of the triangles
|
||||
box.setCenter(new Vector3f(-1f, 1.5f, 0f)); |
||||
checkCollision(box, geom, 1); |
||||
|
||||
box.setCenter(new Vector3f(1.5f, -1f, 0f)); |
||||
checkCollision(box, geom, 1); |
||||
} |
||||
|
||||
@Test |
||||
public void testSphereTriangleCollision() { |
||||
BoundingSphere sphere = new BoundingSphere(1, Vector3f.ZERO); |
||||
Geometry geom = new Geometry("geom", new Quad(1, 1)); |
||||
checkCollision(sphere, geom, 2); |
||||
|
||||
// The box touches the edges of the triangles.
|
||||
sphere.setCenter(new Vector3f(-1f + FastMath.ZERO_TOLERANCE, 0, 0)); |
||||
checkCollision(sphere, geom, 2); |
||||
|
||||
// Move it slightly farther..
|
||||
sphere.setCenter(new Vector3f(-1f - FastMath.ZERO_TOLERANCE, 0, 0)); |
||||
checkCollision(sphere, geom, 0); |
||||
|
||||
// Parallel triangle / box side, touching
|
||||
sphere.setCenter(new Vector3f(0, 0, -1f)); |
||||
checkCollision(sphere, geom, 2); |
||||
|
||||
// Not touching
|
||||
sphere.setCenter(new Vector3f(0, 0, -1f - FastMath.ZERO_TOLERANCE)); |
||||
checkCollision(sphere, geom, 0); |
||||
|
||||
// Test collisions only against one of the triangles
|
||||
sphere.setCenter(new Vector3f(-0.9f, 1.2f, 0f)); |
||||
checkCollision(sphere, geom, 1); |
||||
|
||||
sphere.setCenter(new Vector3f(1.2f, -0.9f, 0f)); |
||||
checkCollision(sphere, geom, 1); |
||||
} |
||||
} |
@ -0,0 +1,80 @@ |
||||
/* |
||||
* Copyright (c) 2009-2015 jMonkeyEngine |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* |
||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
package com.jme3.collision; |
||||
|
||||
import com.jme3.bounding.BoundingVolume; |
||||
|
||||
/** |
||||
* Utilities for testing collision. |
||||
* |
||||
* @author Kirill Vainer |
||||
*/ |
||||
final class CollisionUtil { |
||||
|
||||
private static void checkCollisionBase(Collidable a, Collidable b, int expected) { |
||||
// Test bounding volume methods
|
||||
if (a instanceof BoundingVolume && b instanceof BoundingVolume) { |
||||
BoundingVolume bv1 = (BoundingVolume) a; |
||||
BoundingVolume bv2 = (BoundingVolume) b; |
||||
assert bv1.intersects(bv2) == (expected != 0); |
||||
} |
||||
|
||||
// Test standard collideWith method
|
||||
CollisionResults results = new CollisionResults(); |
||||
int numCollisions = a.collideWith(b, results); |
||||
assert results.size() == numCollisions; |
||||
assert numCollisions == expected; |
||||
|
||||
// force the results to be sorted here..
|
||||
results.getClosestCollision(); |
||||
|
||||
if (results.size() > 0) { |
||||
assert results.getCollision(0) == results.getClosestCollision(); |
||||
} |
||||
if (results.size() == 1) { |
||||
assert results.getClosestCollision() == results.getFarthestCollision(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Tests various collisions between the two collidables and |
||||
* the transitive property. |
||||
* |
||||
* @param a First collidable |
||||
* @param b Second collidable |
||||
* @param expect Number of expected results |
||||
*/ |
||||
public static void checkCollision(Collidable a, Collidable b, int expected) { |
||||
checkCollisionBase(a, b, expected); |
||||
checkCollisionBase(b, a, expected); |
||||
} |
||||
} |
@ -0,0 +1,271 @@ |
||||
/* |
||||
* Copyright (c) 2009-2015 jMonkeyEngine |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* |
||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
package com.jme3.light; |
||||
|
||||
import com.jme3.bounding.BoundingSphere; |
||||
import com.jme3.math.FastMath; |
||||
import com.jme3.math.Vector3f; |
||||
import com.jme3.renderer.Camera; |
||||
import com.jme3.scene.Geometry; |
||||
import com.jme3.scene.shape.Box; |
||||
import com.jme3.util.TempVars; |
||||
import org.junit.Before; |
||||
import org.junit.Test; |
||||
|
||||
/** |
||||
* Test light filtering for various light types. |
||||
* |
||||
* @author Kirill Vainer |
||||
*/ |
||||
public class LightFilterTest { |
||||
|
||||
private DefaultLightFilter filter; |
||||
private Camera cam; |
||||
private Geometry geom; |
||||
private LightList list; |
||||
|
||||
private void checkFilteredLights(int expected) { |
||||
geom.updateGeometricState(); |
||||
filter.setCamera(cam); // setCamera resets the intersection cache
|
||||
list.clear(); |
||||
filter.filterLights(geom, list); |
||||
assert list.size() == expected; |
||||
} |
||||
|
||||
@Before |
||||
public void setUp() { |
||||
filter = new DefaultLightFilter(); |
||||
|
||||
cam = new Camera(512, 512); |
||||
cam.setFrustumPerspective(45, 1, 1, 1000); |
||||
cam.setLocation(Vector3f.ZERO); |
||||
cam.lookAtDirection(Vector3f.UNIT_Z, Vector3f.UNIT_Y); |
||||
filter.setCamera(cam); |
||||
|
||||
Box box = new Box(1, 1, 1); |
||||
geom = new Geometry("geom", box); |
||||
geom.setLocalTranslation(0, 0, 10); |
||||
geom.updateGeometricState(); |
||||
list = new LightList(geom); |
||||
} |
||||
|
||||
@Test |
||||
public void testAmbientFiltering() { |
||||
geom.addLight(new AmbientLight()); |
||||
checkFilteredLights(1); // Ambient lights must never be filtered
|
||||
|
||||
// Test for bounding Sphere
|
||||
geom.setModelBound(new BoundingSphere(0.5f, Vector3f.ZERO)); |
||||
checkFilteredLights(1); // Ambient lights must never be filtered
|
||||
} |
||||
|
||||
@Test |
||||
public void testDirectionalFiltering() { |
||||
geom.addLight(new DirectionalLight(Vector3f.UNIT_Y)); |
||||
checkFilteredLights(1); // Directional lights must never be filtered
|
||||
|
||||
// Test for bounding Sphere
|
||||
geom.setModelBound(new BoundingSphere(0.5f, Vector3f.ZERO)); |
||||
checkFilteredLights(1); // Directional lights must never be filtered
|
||||
} |
||||
|
||||
@Test |
||||
public void testPointFiltering() { |
||||
PointLight pl = new PointLight(Vector3f.ZERO); |
||||
geom.addLight(pl); |
||||
checkFilteredLights(1); // Infinite point lights must never be filtered
|
||||
|
||||
// Light at origin does not intersect geom which is at Z=10
|
||||
pl.setRadius(1); |
||||
checkFilteredLights(0); |
||||
|
||||
// Put it closer to geom, the very edge of the sphere touches the box.
|
||||
// Still not considered an intersection though.
|
||||
pl.setPosition(new Vector3f(0, 0, 8f)); |
||||
checkFilteredLights(0); |
||||
|
||||
// And more close - now its an intersection.
|
||||
pl.setPosition(new Vector3f(0, 0, 8f + FastMath.ZERO_TOLERANCE)); |
||||
checkFilteredLights(1); |
||||
|
||||
// Move the geometry away
|
||||
geom.move(0, 0, FastMath.ZERO_TOLERANCE); |
||||
checkFilteredLights(0); |
||||
|
||||
// Test if the algorithm converts the sphere
|
||||
// to a box before testing the collision (incorrect)
|
||||
float sqrt3 = FastMath.sqrt(3); |
||||
|
||||
pl.setPosition(new Vector3f(2, 2, 8)); |
||||
pl.setRadius(sqrt3); |
||||
checkFilteredLights(0); |
||||
|
||||
// Make it a wee bit larger.
|
||||
pl.setRadius(sqrt3 + FastMath.ZERO_TOLERANCE); |
||||
checkFilteredLights(1); |
||||
|
||||
// Rotate the camera so it is up, light is outside frustum.
|
||||
cam.lookAtDirection(Vector3f.UNIT_Y, Vector3f.UNIT_Y); |
||||
checkFilteredLights(0); |
||||
|
||||
// ==================================
|
||||
// Tests for bounding Sphere
|
||||
geom.setModelBound(new BoundingSphere(1f, Vector3f.ZERO)); |
||||
geom.setLocalTranslation(0, 0, 2); |
||||
pl.setPosition(new Vector3f(0, 0, 2f)); |
||||
|
||||
// Infinite point lights must never be filtered
|
||||
pl.setRadius(0); |
||||
checkFilteredLights(1); |
||||
|
||||
pl.setRadius(1f); |
||||
// Put the light at the very close to the geom,
|
||||
// the very edge of the sphere touches the other bounding sphere
|
||||
// Still not considered an intersection though.
|
||||
pl.setPosition(new Vector3f(0, 0, 0)); |
||||
checkFilteredLights(0); |
||||
|
||||
// And more close - now its an intersection.
|
||||
pl.setPosition(new Vector3f(0, 0, 0f + FastMath.ZERO_TOLERANCE)); |
||||
checkFilteredLights(1); |
||||
|
||||
geom.setLocalTranslation(0, 0, 0); |
||||
// In this case its an intersection for pointLight v. box
|
||||
// But not for pointLight v. sphere
|
||||
// Vector3f(0, 0.5f, 0.5f).normalize().mult(2) ~ >= (0.0, 1.4142135, 1.4142135)
|
||||
//pl.setPosition(new Vector3f(0, 0.5f, 0.5f).normalizeLocal().multLocal(2 + FastMath.ZERO_TOLERANCE));
|
||||
pl.setPosition(new Vector3f(0f, 1.4142135f, 1.4142135f).multLocal(1+FastMath.ZERO_TOLERANCE)); |
||||
checkFilteredLights(0); |
||||
|
||||
// Make the distance a wee bit closer, now its an intersection
|
||||
//pl.setPosition(new Vector3f(0, 0.5f, 0.5f).normalizeLocal().multLocal(2 - FastMath.ZERO_TOLERANCE));
|
||||
pl.setPosition(new Vector3f(0f, 1.4142135f, 1.4142135f).multLocal(1-FastMath.ZERO_TOLERANCE)); |
||||
checkFilteredLights(1); |
||||
|
||||
// it's a point light, also test for the other corner
|
||||
pl.setPosition(new Vector3f(0f, -1.4142135f, -1.4142135f).multLocal(1-FastMath.ZERO_TOLERANCE)); |
||||
checkFilteredLights(0); |
||||
|
||||
} |
||||
|
||||
@Test |
||||
public void testSpotFiltering() { |
||||
SpotLight sl = new SpotLight(Vector3f.ZERO, Vector3f.UNIT_Z); |
||||
sl.setSpotRange(0); |
||||
geom.addLight(sl); |
||||
checkFilteredLights(1); // Infinite spot lights are only filtered
|
||||
// if the geometry is outside the infinite cone.
|
||||
|
||||
TempVars vars = TempVars.get(); |
||||
try { |
||||
// The spot is not touching the near plane of the camera yet,
|
||||
// should still be culled.
|
||||
sl.setSpotRange(1f - FastMath.ZERO_TOLERANCE); |
||||
assert !sl.intersectsFrustum(cam, vars); |
||||
// should be culled from the geometry's PoV
|
||||
checkFilteredLights(0); |
||||
|
||||
// Now it touches the near plane.
|
||||
sl.setSpotRange(1f); |
||||
// still culled from the geometry's PoV
|
||||
checkFilteredLights(0); |
||||
assert sl.intersectsFrustum(cam, vars); |
||||
} finally { |
||||
vars.release(); |
||||
} |
||||
|
||||
// make it barely reach the geometry
|
||||
sl.setSpotRange(9f); |
||||
checkFilteredLights(0); |
||||
|
||||
// make it reach the geometry (touching its bound)
|
||||
sl.setSpotRange(9f + FastMath.ZERO_TOLERANCE); |
||||
checkFilteredLights(1); |
||||
|
||||
// rotate the cone a bit so it no longer faces the geom
|
||||
sl.setDirection(new Vector3f(0.316f, 0, 0.948f).normalizeLocal()); |
||||
checkFilteredLights(0); |
||||
|
||||
// extent the range much farther
|
||||
sl.setSpotRange(20); |
||||
checkFilteredLights(0); |
||||
|
||||
// Create box of size X=10 (double the extent)
|
||||
// now, the spot will touch the box.
|
||||
geom.setMesh(new Box(5, 1, 1)); |
||||
checkFilteredLights(1); |
||||
|
||||
// ==================================
|
||||
// Tests for bounding sphere, with a radius of 1f (in the box geom)
|
||||
sl.setPosition(Vector3f.ZERO); |
||||
sl.setDirection(Vector3f.UNIT_Z); |
||||
geom.setLocalTranslation(Vector3f.ZERO); |
||||
geom.setModelBound(new BoundingSphere(1f, Vector3f.ZERO)); |
||||
|
||||
// Infinit spot lights are only filtered
|
||||
// if the geometry is outside the infinite cone.
|
||||
sl.setSpotRange(0); |
||||
checkFilteredLights(1); |
||||
|
||||
//the geommetry is outside the infinit cone (cone direction going away from the geom)
|
||||
sl.setPosition(Vector3f.UNIT_Z.mult(1+FastMath.ZERO_TOLERANCE)); |
||||
checkFilteredLights(0); |
||||
|
||||
//place the spote ligth in the corner of the box geom, (in order to test bounding sphere)
|
||||
sl.setDirection(new Vector3f(1, 1, 0).normalizeLocal()); |
||||
geom.setLocalTranslation(0, 0, 10); |
||||
sl.setPosition(sl.getDirection().mult(-2f).add(geom.getLocalTranslation())); |
||||
|
||||
// make it barely reach the sphere, incorect with a box
|
||||
sl.setSpotRange(1f - FastMath.ZERO_TOLERANCE); |
||||
checkFilteredLights(0); |
||||
|
||||
// make it reach the sphere
|
||||
sl.setSpotRange(1f + FastMath.ZERO_TOLERANCE); |
||||
checkFilteredLights(1); |
||||
|
||||
// extent the range
|
||||
sl.setPosition(Vector3f.ZERO); |
||||
sl.setDirection(Vector3f.UNIT_Z); |
||||
sl.setSpotRange(20); |
||||
checkFilteredLights(1); |
||||
|
||||
// rotate the cone a bit so it no longer faces the geom
|
||||
sl.setDirection(new Vector3f(0, 0.3f, 0.7f).normalizeLocal()); |
||||
checkFilteredLights(0); |
||||
|
||||
// Create sphere of size X=10 (double the radius)
|
||||
// now, the spot will touch the sphere.
|
||||
geom.setModelBound(new BoundingSphere(5f, Vector3f.ZERO)); |
||||
checkFilteredLights(1); |
||||
} |
||||
} |
@ -0,0 +1,115 @@ |
||||
/* |
||||
* Copyright (c) 2009-2015 jMonkeyEngine |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* |
||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
package com.jme3.light; |
||||
|
||||
import com.jme3.math.Vector3f; |
||||
import com.jme3.scene.Geometry; |
||||
import com.jme3.scene.Mesh; |
||||
import com.jme3.scene.Node; |
||||
import org.junit.Test; |
||||
|
||||
/** |
||||
* Test light sorting (in the scene graph) for various light types. |
||||
* |
||||
* @author Kirill Vainer |
||||
*/ |
||||
public class LightSortTest { |
||||
|
||||
@Test |
||||
public void testSimpleSort() { |
||||
Geometry g = new Geometry("test", new Mesh()); |
||||
LightList list = new LightList(g); |
||||
|
||||
list.add(new SpotLight(Vector3f.ZERO, Vector3f.UNIT_X)); |
||||
list.add(new PointLight(Vector3f.UNIT_X)); |
||||
list.add(new DirectionalLight(Vector3f.UNIT_X)); |
||||
list.add(new AmbientLight()); |
||||
|
||||
list.sort(true); |
||||
|
||||
assert list.get(0) instanceof AmbientLight; // Ambients always first
|
||||
assert list.get(1) instanceof DirectionalLight; // .. then directionals
|
||||
assert list.get(2) instanceof SpotLight; // Spot is 0 units away from geom
|
||||
assert list.get(3) instanceof PointLight; // .. and point is 1 unit away.
|
||||
} |
||||
|
||||
@Test |
||||
public void testSceneGraphSort() { |
||||
Node n = new Node("node"); |
||||
Geometry g = new Geometry("geom", new Mesh()); |
||||
SpotLight spot = new SpotLight(Vector3f.ZERO, Vector3f.UNIT_X); |
||||
PointLight point = new PointLight(Vector3f.UNIT_X); |
||||
DirectionalLight directional = new DirectionalLight(Vector3f.UNIT_X); |
||||
AmbientLight ambient = new AmbientLight(); |
||||
|
||||
// Some lights are on the node
|
||||
n.addLight(spot); |
||||
n.addLight(point); |
||||
|
||||
// .. and some on the geometry.
|
||||
g.addLight(directional); |
||||
g.addLight(ambient); |
||||
|
||||
n.attachChild(g); |
||||
n.updateGeometricState(); |
||||
|
||||
LightList list = g.getWorldLightList(); |
||||
|
||||
// check the sorting (when geom is at 0,0,0)
|
||||
assert list.get(0) instanceof AmbientLight; |
||||
assert list.get(1) instanceof DirectionalLight; |
||||
assert list.get(2) instanceof SpotLight; |
||||
assert list.get(3) instanceof PointLight; |
||||
|
||||
// move the geometry closer to the point light
|
||||
g.setLocalTranslation(Vector3f.UNIT_X); |
||||
n.updateGeometricState(); |
||||
|
||||
assert list.get(0) instanceof AmbientLight; |
||||
assert list.get(1) instanceof DirectionalLight; |
||||
assert list.get(2) instanceof PointLight; |
||||
assert list.get(3) instanceof SpotLight; |
||||
|
||||
// now move the point light away from the geometry
|
||||
// and the spot light closer
|
||||
|
||||
// XXX: doesn't work! jME can't detect that the light moved!
|
||||
// point.setPosition(Vector3f.ZERO);
|
||||
// spot.setPosition(Vector3f.UNIT_X);
|
||||
// n.updateGeometricState();
|
||||
//
|
||||
// assert list.get(0) instanceof AmbientLight;
|
||||
// assert list.get(1) instanceof DirectionalLight;
|
||||
// assert list.get(2) instanceof SpotLight;
|
||||
// assert list.get(3) instanceof PointLight;
|
||||
} |
||||
} |
@ -0,0 +1,117 @@ |
||||
package com.jme3.material.plugins; |
||||
|
||||
import com.jme3.asset.AssetInfo; |
||||
import com.jme3.asset.AssetKey; |
||||
import com.jme3.asset.AssetManager; |
||||
import com.jme3.asset.TextureKey; |
||||
import com.jme3.material.MatParamTexture; |
||||
import com.jme3.material.Material; |
||||
import com.jme3.material.MaterialDef; |
||||
import com.jme3.shader.VarType; |
||||
import com.jme3.texture.Texture; |
||||
import org.junit.Before; |
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
import org.mockito.Mock; |
||||
import org.mockito.Mockito; |
||||
import org.mockito.runners.MockitoJUnitRunner; |
||||
|
||||
import static org.mockito.Matchers.any; |
||||
import static org.mockito.Mockito.verify; |
||||
import static org.mockito.Mockito.when; |
||||
|
||||
/** |
||||
* @author Daniel Johansson |
||||
* @since 2015-07-20 |
||||
*/ |
||||
@RunWith(MockitoJUnitRunner.class) |
||||
public class J3MLoaderTest { |
||||
|
||||
private J3MLoader j3MLoader; |
||||
|
||||
@Mock |
||||
private AssetInfo assetInfo; |
||||
|
||||
@Mock |
||||
private AssetManager assetManager; |
||||
|
||||
@Mock |
||||
private AssetKey<Material> assetKey; |
||||
|
||||
@Mock |
||||
private MaterialDef materialDef; |
||||
|
||||
@Before |
||||
public void setUp() throws Exception { |
||||
when(assetKey.getExtension()).thenReturn(".j3m"); |
||||
when(assetInfo.getManager()).thenReturn(assetManager); |
||||
when(assetInfo.getKey()).thenReturn(assetKey); |
||||
when(assetManager.loadAsset(any(AssetKey.class))).thenReturn(materialDef); |
||||
|
||||
j3MLoader = new J3MLoader(); |
||||
} |
||||
|
||||
@Test |
||||
public void oldStyleTextureParameters_shouldBeSupported() throws Exception { |
||||
when(assetInfo.openStream()).thenReturn(J3MLoader.class.getResourceAsStream("/texture-parameters-oldstyle.j3m")); |
||||
|
||||
final Texture textureOldStyle = Mockito.mock(Texture.class); |
||||
final Texture textureOldStyleUsingQuotes = Mockito.mock(Texture.class); |
||||
|
||||
final TextureKey textureKeyUsingQuotes = setupMockForTexture("OldStyleUsingQuotes", "old style using quotes/texture.png", true, textureOldStyleUsingQuotes); |
||||
final TextureKey textureKeyOldStyle = setupMockForTexture("OldStyle", "old style/texture.png", true, textureOldStyle); |
||||
|
||||
j3MLoader.load(assetInfo); |
||||
|
||||
verify(assetManager).loadTexture(textureKeyUsingQuotes); |
||||
verify(assetManager).loadTexture(textureKeyOldStyle); |
||||
verify(textureOldStyle).setWrap(Texture.WrapMode.Repeat); |
||||
verify(textureOldStyleUsingQuotes).setWrap(Texture.WrapMode.Repeat); |
||||
} |
||||
|
||||
@Test |
||||
public void newStyleTextureParameters_shouldBeSupported() throws Exception { |
||||
when(assetInfo.openStream()).thenReturn(J3MLoader.class.getResourceAsStream("/texture-parameters-newstyle.j3m")); |
||||
|
||||
final Texture textureNoParameters = Mockito.mock(Texture.class); |
||||
final Texture textureFlip = Mockito.mock(Texture.class); |
||||
final Texture textureRepeat = Mockito.mock(Texture.class); |
||||
final Texture textureRepeatAxis = Mockito.mock(Texture.class); |
||||
final Texture textureMin = Mockito.mock(Texture.class); |
||||
final Texture textureMag = Mockito.mock(Texture.class); |
||||
final Texture textureCombined = Mockito.mock(Texture.class); |
||||
|
||||
final TextureKey textureKeyNoParameters = setupMockForTexture("Empty", "empty.png", false, textureNoParameters); |
||||
final TextureKey textureKeyFlip = setupMockForTexture("Flip", "flip.png", true, textureFlip); |
||||
setupMockForTexture("Repeat", "repeat.png", false, textureRepeat); |
||||
setupMockForTexture("RepeatAxis", "repeat-axis.png", false, textureRepeatAxis); |
||||
setupMockForTexture("Min", "min.png", false, textureMin); |
||||
setupMockForTexture("Mag", "mag.png", false, textureMag); |
||||
setupMockForTexture("Combined", "combined.png", true, textureCombined); |
||||
|
||||
j3MLoader.load(assetInfo); |
||||
|
||||
verify(assetManager).loadTexture(textureKeyNoParameters); |
||||
verify(assetManager).loadTexture(textureKeyFlip); |
||||
|
||||
verify(textureRepeat).setWrap(Texture.WrapMode.Repeat); |
||||
verify(textureRepeatAxis).setWrap(Texture.WrapAxis.T, Texture.WrapMode.Repeat); |
||||
verify(textureMin).setMinFilter(Texture.MinFilter.Trilinear); |
||||
verify(textureMag).setMagFilter(Texture.MagFilter.Bilinear); |
||||
|
||||
verify(textureCombined).setMagFilter(Texture.MagFilter.Nearest); |
||||
verify(textureCombined).setMinFilter(Texture.MinFilter.BilinearNoMipMaps); |
||||
verify(textureCombined).setWrap(Texture.WrapMode.Repeat); |
||||
} |
||||
|
||||
private TextureKey setupMockForTexture(final String paramName, final String path, final boolean flipY, final Texture texture) { |
||||
when(materialDef.getMaterialParam(paramName)).thenReturn(new MatParamTexture(VarType.Texture2D, paramName, texture, 0, null)); |
||||
|
||||
final TextureKey textureKey = new TextureKey(path, flipY); |
||||
textureKey.setGenerateMips(true); |
||||
|
||||
when(assetManager.loadTexture(textureKey)).thenReturn(texture); |
||||
|
||||
return textureKey; |
||||
} |
||||
} |
@ -0,0 +1,59 @@ |
||||
/* |
||||
* Copyright (c) 2009-2015 jMonkeyEngine |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* |
||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
package com.jme3.math; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
/** |
||||
* Verifies that algorithms in {@link FastMath} are working correctly. |
||||
* |
||||
* @author Kirill Vainer |
||||
*/ |
||||
public class FastMathTest { |
||||
|
||||
private int nearestPowerOfTwoSlow(int number) { |
||||
return (int) Math.pow(2, Math.ceil(Math.log(number) / Math.log(2))); |
||||
} |
||||
|
||||
@Test |
||||
public void testNearestPowerOfTwo() { |
||||
for (int i = -100; i < 1; i++) { |
||||
assert FastMath.nearestPowerOfTwo(i) == 1; |
||||
} |
||||
for (int i = 1; i < 10000; i++) { |
||||
int nextPowerOf2 = FastMath.nearestPowerOfTwo(i); |
||||
assert i <= nextPowerOf2; |
||||
assert FastMath.isPowerOfTwo(nextPowerOf2); |
||||
assert nextPowerOf2 == nearestPowerOfTwoSlow(i); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,73 @@ |
||||
/* |
||||
* Copyright (c) 2009-2015 jMonkeyEngine |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* |
||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
package com.jme3.util; |
||||
|
||||
import java.util.Map.Entry; |
||||
import org.junit.Test; |
||||
|
||||
/** |
||||
* Check if the {@link ListMap} class is working correctly. |
||||
* |
||||
* @author Kirill Vainer |
||||
*/ |
||||
public class ListMapTest { |
||||
|
||||
@Test |
||||
public void testListMap() { |
||||
ListMap<String, String> listMap = new ListMap<String, String>(); |
||||
listMap.put("bob", "hello"); |
||||
assert "hello".equals(listMap.get("bob")); |
||||
assert "hello".equals(listMap.remove("bob")); |
||||
assert listMap.size() == 0; |
||||
assert listMap.isEmpty(); |
||||
|
||||
listMap.put("abc", "1"); |
||||
listMap.put("def", "2"); |
||||
listMap.put("ghi", "3"); |
||||
listMap.put("jkl", "4"); |
||||
listMap.put("mno", "5"); |
||||
assert "3".equals(listMap.get("ghi")); |
||||
assert listMap.size() == 5; |
||||
assert !listMap.isEmpty(); |
||||
|
||||
// check iteration order, should be consistent
|
||||
for (int i = 0; i < listMap.size(); i++) { |
||||
String expectedValue = Integer.toString(i + 1); |
||||
String key = listMap.getKey(i); |
||||
String value = listMap.getValue(i); |
||||
Entry<String, String> entry = listMap.getEntry(i); |
||||
assert key.equals(entry.getKey()); |
||||
assert value.equals(entry.getValue()); |
||||
assert expectedValue.equals(value); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,11 @@ |
||||
Material Test : matdef.j3md { |
||||
MaterialParameters { |
||||
Empty: "empty.png" |
||||
Flip: Flip "flip.png" |
||||
Repeat: WrapRepeat "repeat.png" |
||||
Min: MinTrilinear "min.png" |
||||
Mag: MagBilinear "mag.png" |
||||
RepeatAxis: WrapRepeat_T "repeat-axis.png" |
||||
Combined: MagNearest MinBilinearNoMipMaps Flip WrapRepeat "combined.png" |
||||
} |
||||
} |
@ -0,0 +1,6 @@ |
||||
Material Test : matdef.j3md { |
||||
MaterialParameters { |
||||
OldStyle: Flip Repeat old style/texture.png |
||||
OldStyleUsingQuotes: Repeat Flip "old style using quotes/texture.png" |
||||
} |
||||
} |
@ -0,0 +1,603 @@ |
||||
package com.jme3.renderer.jogl; |
||||
|
||||
import com.jme3.renderer.RendererException; |
||||
import com.jme3.renderer.opengl.GL; |
||||
import com.jme3.renderer.opengl.GL2; |
||||
import com.jme3.renderer.opengl.GL3; |
||||
|
||||
import java.nio.Buffer; |
||||
import java.nio.ByteBuffer; |
||||
import java.nio.ByteOrder; |
||||
import java.nio.FloatBuffer; |
||||
import java.nio.IntBuffer; |
||||
import java.nio.ShortBuffer; |
||||
|
||||
import com.jme3.renderer.opengl.GL4; |
||||
import com.jogamp.opengl.GLContext; |
||||
|
||||
public class JoglGL implements GL, GL2, GL3, GL4 { |
||||
|
||||
private static int getLimitBytes(ByteBuffer buffer) { |
||||
checkLimit(buffer); |
||||
return buffer.limit(); |
||||
} |
||||
|
||||
private static int getLimitBytes(ShortBuffer buffer) { |
||||
checkLimit(buffer); |
||||
return buffer.limit() * 2; |
||||
} |
||||
|
||||
private static int getLimitBytes(FloatBuffer buffer) { |
||||
checkLimit(buffer); |
||||
return buffer.limit() * 4; |
||||
} |
||||
|
||||
private static int getLimitCount(Buffer buffer, int elementSize) { |
||||
checkLimit(buffer); |
||||
return buffer.limit() / elementSize; |
||||
} |
||||
|
||||
private static void checkLimit(Buffer buffer) { |
||||
if (buffer == null) { |
||||
return; |
||||
} |
||||
if (buffer.limit() == 0) { |
||||
throw new RendererException("Attempting to upload empty buffer (limit = 0), that's an error"); |
||||
} |
||||
if (buffer.remaining() == 0) { |
||||
throw new RendererException("Attempting to upload empty buffer (remaining = 0), that's an error"); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void resetStats() { |
||||
} |
||||
|
||||
@Override |
||||
public void glActiveTexture(int param1) { |
||||
GLContext.getCurrentGL().glActiveTexture(param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glAlphaFunc(int param1, float param2) { |
||||
GLContext.getCurrentGL().getGL2ES1().glAlphaFunc(param1, param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glAttachShader(int param1, int param2) { |
||||
GLContext.getCurrentGL().getGL2ES2().glAttachShader(param1, param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glBindBuffer(int param1, int param2) { |
||||
GLContext.getCurrentGL().glBindBuffer(param1, param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glBindTexture(int param1, int param2) { |
||||
GLContext.getCurrentGL().glBindTexture(param1, param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glBlendFunc(int param1, int param2) { |
||||
GLContext.getCurrentGL().glBlendFunc(param1, param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glBufferData(int param1, long param2, int param3) { |
||||
GLContext.getCurrentGL().glBufferData(param1, param2, null, param3); |
||||
} |
||||
|
||||
@Override |
||||
public void glBufferData(int param1, FloatBuffer param2, int param3) { |
||||
checkLimit(param2); |
||||
GLContext.getCurrentGL().glBufferData(param1, getLimitBytes(param2), param2, param3); |
||||
} |
||||
|
||||
@Override |
||||
public void glBufferData(int param1, ShortBuffer param2, int param3) { |
||||
checkLimit(param2); |
||||
GLContext.getCurrentGL().glBufferData(param1, getLimitBytes(param2), param2, param3); |
||||
} |
||||
|
||||
@Override |
||||
public void glBufferData(int param1, ByteBuffer param2, int param3) { |
||||
checkLimit(param2); |
||||
GLContext.getCurrentGL().glBufferData(param1, getLimitBytes(param2), param2, param3); |
||||
} |
||||
|
||||
@Override |
||||
public void glBufferSubData(int param1, long param2, FloatBuffer param3) { |
||||
checkLimit(param3); |
||||
GLContext.getCurrentGL().glBufferSubData(param1, param2, getLimitBytes(param3), param3); |
||||
} |
||||
|
||||
@Override |
||||
public void glBufferSubData(int param1, long param2, ShortBuffer param3) { |
||||
checkLimit(param3); |
||||
GLContext.getCurrentGL().glBufferSubData(param1, param2, getLimitBytes(param3), param3); |
||||
} |
||||
|
||||
@Override |
||||
public void glBufferSubData(int param1, long param2, ByteBuffer param3) { |
||||
checkLimit(param3); |
||||
GLContext.getCurrentGL().glBufferSubData(param1, param2, getLimitBytes(param3), param3); |
||||
} |
||||
|
||||
@Override |
||||
public void glClear(int param1) { |
||||
GLContext.getCurrentGL().glClear(param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glClearColor(float param1, float param2, float param3, float param4) { |
||||
GLContext.getCurrentGL().glClearColor(param1, param2, param3, param4); |
||||
} |
||||
|
||||
@Override |
||||
public void glColorMask(boolean param1, boolean param2, boolean param3, boolean param4) { |
||||
GLContext.getCurrentGL().glColorMask(param1, param2, param3, param4); |
||||
} |
||||
|
||||
@Override |
||||
public void glCompileShader(int param1) { |
||||
GLContext.getCurrentGL().getGL2ES2().glCompileShader(param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glCompressedTexImage2D(int param1, int param2, int param3, int param4, int param5, int param6, ByteBuffer param7) { |
||||
checkLimit(param7); |
||||
GLContext.getCurrentGL().glCompressedTexImage2D(param1, param2, param3, param4, param5, param6, getLimitBytes(param7), param7); |
||||
} |
||||
|
||||
@Override |
||||
public void glCompressedTexImage3D(int param1, int param2, int param3, int param4, int param5, int param6, int param7, ByteBuffer param8) { |
||||
checkLimit(param8); |
||||
GLContext.getCurrentGL().getGL2ES2().glCompressedTexImage3D(param1, param2, param3, param4, param5, param6, param7, getLimitBytes(param8), param8); |
||||
} |
||||
|
||||
@Override |
||||
public void glCompressedTexSubImage2D(int param1, int param2, int param3, int param4, int param5, int param6, int param7, ByteBuffer param8) { |
||||
checkLimit(param8); |
||||
GLContext.getCurrentGL().glCompressedTexSubImage2D(param1, param2, param3, param4, param5, param6, param7, getLimitBytes(param8), param8); |
||||
} |
||||
|
||||
@Override |
||||
public void glCompressedTexSubImage3D(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, ByteBuffer param10) { |
||||
checkLimit(param10); |
||||
GLContext.getCurrentGL().getGL2ES2().glCompressedTexSubImage3D(param1, param2, param3, param4, param5, param6, param7, param8, param9, getLimitBytes(param10), param10); |
||||
} |
||||
|
||||
@Override |
||||
public int glCreateProgram() { |
||||
return GLContext.getCurrentGL().getGL2ES2().glCreateProgram(); |
||||
} |
||||
|
||||
@Override |
||||
public int glCreateShader(int param1) { |
||||
return GLContext.getCurrentGL().getGL2ES2().glCreateShader(param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glCullFace(int param1) { |
||||
GLContext.getCurrentGL().glCullFace(param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glDeleteBuffers(IntBuffer param1) { |
||||
checkLimit(param1); |
||||
GLContext.getCurrentGL().glDeleteBuffers(param1.limit(), param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glDeleteProgram(int param1) { |
||||
GLContext.getCurrentGL().getGL2ES2().glDeleteProgram(param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glDeleteShader(int param1) { |
||||
GLContext.getCurrentGL().getGL2ES2().glDeleteShader(param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glDeleteTextures(IntBuffer param1) { |
||||
checkLimit(param1); |
||||
GLContext.getCurrentGL().glDeleteTextures(param1.limit() ,param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glDepthFunc(int param1) { |
||||
GLContext.getCurrentGL().glDepthFunc(param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glDepthMask(boolean param1) { |
||||
GLContext.getCurrentGL().glDepthMask(param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glDepthRange(double param1, double param2) { |
||||
GLContext.getCurrentGL().glDepthRange(param1, param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glDetachShader(int param1, int param2) { |
||||
GLContext.getCurrentGL().getGL2ES2().glDetachShader(param1, param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glDisable(int param1) { |
||||
GLContext.getCurrentGL().glDisable(param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glDisableVertexAttribArray(int param1) { |
||||
GLContext.getCurrentGL().getGL2ES2().glDisableVertexAttribArray(param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glDrawArrays(int param1, int param2, int param3) { |
||||
GLContext.getCurrentGL().glDrawArrays(param1, param2, param3); |
||||
} |
||||
|
||||
@Override |
||||
public void glDrawBuffer(int param1) { |
||||
GLContext.getCurrentGL().getGL2GL3().glDrawBuffer(param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glDrawRangeElements(int param1, int param2, int param3, int param4, int param5, long param6) { |
||||
GLContext.getCurrentGL().getGL2ES3().glDrawRangeElements(param1, param2, param3, param4, param5, param6); |
||||
} |
||||
|
||||
@Override |
||||
public void glEnable(int param1) { |
||||
GLContext.getCurrentGL().glEnable(param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glEnableVertexAttribArray(int param1) { |
||||
GLContext.getCurrentGL().getGL2ES2().glEnableVertexAttribArray(param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glGenBuffers(IntBuffer param1) { |
||||
checkLimit(param1); |
||||
GLContext.getCurrentGL().glGenBuffers(param1.limit(), param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glGenTextures(IntBuffer param1) { |
||||
checkLimit(param1); |
||||
GLContext.getCurrentGL().glGenTextures(param1.limit(), param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glGetBoolean(int param1, ByteBuffer param2) { |
||||
checkLimit(param2); |
||||
GLContext.getCurrentGL().glGetBooleanv(param1, param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glGetBufferSubData(int target, long offset, ByteBuffer data) { |
||||
checkLimit(data); |
||||
GLContext.getCurrentGL().getGL2GL3().glGetBufferSubData(target, offset, getLimitBytes(data), data); |
||||
} |
||||
|
||||
@Override |
||||
public int glGetError() { |
||||
return GLContext.getCurrentGL().glGetError(); |
||||
} |
||||
|
||||
@Override |
||||
public void glGetInteger(int param1, IntBuffer param2) { |
||||
checkLimit(param2); |
||||
GLContext.getCurrentGL().glGetIntegerv(param1, param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glGetProgram(int param1, int param2, IntBuffer param3) { |
||||
checkLimit(param3); |
||||
GLContext.getCurrentGL().getGL2ES2().glGetProgramiv(param1, param2, param3); |
||||
} |
||||
|
||||
@Override |
||||
public void glGetShader(int param1, int param2, IntBuffer param3) { |
||||
checkLimit(param3); |
||||
GLContext.getCurrentGL().getGL2ES2().glGetShaderiv(param1, param2, param3); |
||||
} |
||||
|
||||
@Override |
||||
public String glGetString(int param1) { |
||||
return GLContext.getCurrentGL().glGetString(param1); |
||||
} |
||||
|
||||
@Override |
||||
public String glGetString(int param1, int param2) { |
||||
return GLContext.getCurrentGL().getGL2ES3().glGetStringi(param1, param2); |
||||
} |
||||
|
||||
@Override |
||||
public boolean glIsEnabled(int param1) { |
||||
return GLContext.getCurrentGL().glIsEnabled(param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glLineWidth(float param1) { |
||||
GLContext.getCurrentGL().glLineWidth(param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glLinkProgram(int param1) { |
||||
GLContext.getCurrentGL().getGL2ES2().glLinkProgram(param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glPixelStorei(int param1, int param2) { |
||||
GLContext.getCurrentGL().glPixelStorei(param1, param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glPointSize(float param1) { |
||||
GLContext.getCurrentGL().getGL2ES1().glPointSize(param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glPolygonMode(int param1, int param2) { |
||||
GLContext.getCurrentGL().getGL2().glPolygonMode(param1, param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glPolygonOffset(float param1, float param2) { |
||||
GLContext.getCurrentGL().glPolygonOffset(param1, param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glReadBuffer(int param1) { |
||||
GLContext.getCurrentGL().getGL2ES3().glReadBuffer(param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glReadPixels(int param1, int param2, int param3, int param4, int param5, int param6, ByteBuffer param7) { |
||||
checkLimit(param7); |
||||
GLContext.getCurrentGL().glReadPixels(param1, param2, param3, param4, param5, param6, param7); |
||||
} |
||||
|
||||
@Override |
||||
public void glReadPixels(int param1, int param2, int param3, int param4, int param5, int param6, long param7) { |
||||
GLContext.getCurrentGL().glReadPixels(param1, param2, param3, param4, param5, param6, param7); |
||||
} |
||||
|
||||
@Override |
||||
public void glScissor(int param1, int param2, int param3, int param4) { |
||||
GLContext.getCurrentGL().glScissor(param1, param2, param3, param4); |
||||
} |
||||
|
||||
@Override |
||||
public void glStencilFuncSeparate(int param1, int param2, int param3, int param4) { |
||||
GLContext.getCurrentGL().getGL2ES2().glStencilFuncSeparate(param1, param2, param3, param4); |
||||
} |
||||
|
||||
@Override |
||||
public void glStencilOpSeparate(int param1, int param2, int param3, int param4) { |
||||
GLContext.getCurrentGL().getGL2ES2().glStencilOpSeparate(param1, param2, param3, param4); |
||||
} |
||||
|
||||
@Override |
||||
public void glTexImage2D(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, ByteBuffer param9) { |
||||
checkLimit(param9); |
||||
GLContext.getCurrentGL().glTexImage2D(param1, param2, param3, param4, param5, param6, param7, param8, param9); |
||||
} |
||||
|
||||
@Override |
||||
public void glTexImage3D(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, ByteBuffer param10) { |
||||
checkLimit(param10); |
||||
GLContext.getCurrentGL().getGL2ES2().glTexImage3D(param1, param2, param3, param4, param5, param6, param7, param8, param9, param10); |
||||
} |
||||
|
||||
@Override |
||||
public void glTexParameterf(int param1, int param2, float param3) { |
||||
GLContext.getCurrentGL().glTexParameterf(param1, param2, param3); |
||||
} |
||||
|
||||
@Override |
||||
public void glTexParameteri(int param1, int param2, int param3) { |
||||
GLContext.getCurrentGL().glTexParameteri(param1, param2, param3); |
||||
} |
||||
|
||||
@Override |
||||
public void glTexSubImage2D(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, ByteBuffer param9) { |
||||
checkLimit(param9); |
||||
GLContext.getCurrentGL().glTexSubImage2D(param1, param2, param3, param4, param5, param6, param7, param8, param9); |
||||
} |
||||
|
||||
@Override |
||||
public void glTexSubImage3D(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10, ByteBuffer param11) { |
||||
checkLimit(param11); |
||||
GLContext.getCurrentGL().getGL2ES2().glTexSubImage3D(param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11); |
||||
} |
||||
|
||||
@Override |
||||
public void glUniform1(int param1, FloatBuffer param2) { |
||||
checkLimit(param2); |
||||
GLContext.getCurrentGL().getGL2ES2().glUniform1fv(param1, getLimitCount(param2, 1), param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glUniform1(int param1, IntBuffer param2) { |
||||
checkLimit(param2); |
||||
GLContext.getCurrentGL().getGL2ES2().glUniform1iv(param1, getLimitCount(param2, 1), param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glUniform1f(int param1, float param2) { |
||||
GLContext.getCurrentGL().getGL2ES2().glUniform1f(param1, param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glUniform1i(int param1, int param2) { |
||||
GLContext.getCurrentGL().getGL2ES2().glUniform1i(param1, param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glUniform2(int param1, IntBuffer param2) { |
||||
checkLimit(param2); |
||||
GLContext.getCurrentGL().getGL2ES2().glUniform2iv(param1, getLimitCount(param2, 2), param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glUniform2(int param1, FloatBuffer param2) { |
||||
checkLimit(param2); |
||||
GLContext.getCurrentGL().getGL2ES2().glUniform2fv(param1, getLimitCount(param2, 2), param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glUniform2f(int param1, float param2, float param3) { |
||||
GLContext.getCurrentGL().getGL2ES2().glUniform2f(param1, param2, param3); |
||||
} |
||||
|
||||
@Override |
||||
public void glUniform3(int param1, IntBuffer param2) { |
||||
checkLimit(param2); |
||||
GLContext.getCurrentGL().getGL2ES2().glUniform3iv(param1, getLimitCount(param2, 3), param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glUniform3(int param1, FloatBuffer param2) { |
||||
checkLimit(param2); |
||||
GLContext.getCurrentGL().getGL2ES2().glUniform3fv(param1, getLimitCount(param2, 3), param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glUniform3f(int param1, float param2, float param3, float param4) { |
||||
GLContext.getCurrentGL().getGL2ES2().glUniform3f(param1, param2, param3, param4); |
||||
} |
||||
|
||||
@Override |
||||
public void glUniform4(int param1, FloatBuffer param2) { |
||||
checkLimit(param2); |
||||
GLContext.getCurrentGL().getGL2ES2().glUniform4fv(param1, getLimitCount(param2, 4), param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glUniform4(int param1, IntBuffer param2) { |
||||
checkLimit(param2); |
||||
GLContext.getCurrentGL().getGL2ES2().glUniform4iv(param1, getLimitCount(param2, 4), param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glUniform4f(int param1, float param2, float param3, float param4, float param5) { |
||||
GLContext.getCurrentGL().getGL2ES2().glUniform4f(param1, param2, param3, param4, param5); |
||||
} |
||||
|
||||
@Override |
||||
public void glUniformMatrix3(int param1, boolean param2, FloatBuffer param3) { |
||||
checkLimit(param3); |
||||
GLContext.getCurrentGL().getGL2ES2().glUniformMatrix3fv(param1, getLimitCount(param3, 3 * 3), param2, param3); |
||||
} |
||||
|
||||
@Override |
||||
public void glUniformMatrix4(int param1, boolean param2, FloatBuffer param3) { |
||||
checkLimit(param3); |
||||
GLContext.getCurrentGL().getGL2ES2().glUniformMatrix4fv(param1, getLimitCount(param3, 4 * 4), param2, param3); |
||||
} |
||||
|
||||
@Override |
||||
public void glUseProgram(int param1) { |
||||
GLContext.getCurrentGL().getGL2ES2().glUseProgram(param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glVertexAttribPointer(int param1, int param2, int param3, boolean param4, int param5, long param6) { |
||||
GLContext.getCurrentGL().getGL2ES2().glVertexAttribPointer(param1, param2, param3, param4, param5, param6); |
||||
} |
||||
|
||||
@Override |
||||
public void glViewport(int param1, int param2, int param3, int param4) { |
||||
GLContext.getCurrentGL().glViewport(param1, param2, param3, param4); |
||||
} |
||||
|
||||
@Override |
||||
public int glGetAttribLocation(int param1, String param2) { |
||||
// JOGL 2.0 doesn't need a null-terminated string
|
||||
return GLContext.getCurrentGL().getGL2ES2().glGetAttribLocation(param1, param2); |
||||
} |
||||
|
||||
@Override |
||||
public int glGetUniformLocation(int param1, String param2) { |
||||
// JOGL 2.0 doesn't need a null-terminated string
|
||||
return GLContext.getCurrentGL().getGL2ES2().glGetUniformLocation(param1, param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glShaderSource(int param1, String[] param2, IntBuffer param3) { |
||||
checkLimit(param3); |
||||
|
||||
int param3pos = param3.position(); |
||||
try { |
||||
for (final String param2string : param2) { |
||||
param3.put(Math.max(param2string.length(), param2string.getBytes().length)); |
||||
} |
||||
} finally { |
||||
param3.position(param3pos); |
||||
} |
||||
GLContext.getCurrentGL().getGL2ES2().glShaderSource(param1, param2.length, param2, param3); |
||||
} |
||||
|
||||
@Override |
||||
public String glGetProgramInfoLog(int program, int maxSize) { |
||||
ByteBuffer buffer = ByteBuffer.allocateDirect(maxSize); |
||||
buffer.order(ByteOrder.nativeOrder()); |
||||
ByteBuffer tmp = ByteBuffer.allocateDirect(4); |
||||
tmp.order(ByteOrder.nativeOrder()); |
||||
IntBuffer intBuffer = tmp.asIntBuffer(); |
||||
|
||||
GLContext.getCurrentGL().getGL2ES2().glGetProgramInfoLog(program, maxSize, intBuffer, buffer); |
||||
int numBytes = intBuffer.get(0); |
||||
byte[] bytes = new byte[numBytes]; |
||||
buffer.get(bytes); |
||||
return new String(bytes); |
||||
} |
||||
|
||||
@Override |
||||
public String glGetShaderInfoLog(int shader, int maxSize) { |
||||
ByteBuffer buffer = ByteBuffer.allocateDirect(maxSize); |
||||
buffer.order(ByteOrder.nativeOrder()); |
||||
ByteBuffer tmp = ByteBuffer.allocateDirect(4); |
||||
tmp.order(ByteOrder.nativeOrder()); |
||||
IntBuffer intBuffer = tmp.asIntBuffer(); |
||||
|
||||
GLContext.getCurrentGL().getGL2ES2().glGetShaderInfoLog(shader, maxSize, intBuffer, buffer); |
||||
int numBytes = intBuffer.get(0); |
||||
byte[] bytes = new byte[numBytes]; |
||||
buffer.get(bytes); |
||||
return new String(bytes); |
||||
} |
||||
|
||||
@Override |
||||
public void glBindFragDataLocation(int param1, int param2, String param3) { |
||||
GLContext.getCurrentGL().getGL2GL3().glBindFragDataLocation(param1, param2, param3); |
||||
} |
||||
|
||||
@Override |
||||
public void glBindVertexArray(int param1) { |
||||
GLContext.getCurrentGL().getGL2ES3().glBindVertexArray(param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glGenVertexArrays(IntBuffer param1) { |
||||
checkLimit(param1); |
||||
GLContext.getCurrentGL().getGL2ES3().glGenVertexArrays(param1.limit(), param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glPatchParameter(int count) { |
||||
GLContext.getCurrentGL().getGL3().glPatchParameteri(com.jogamp.opengl.GL3.GL_PATCH_VERTICES, count); |
||||
} |
||||
|
||||
@Override |
||||
public void glDeleteVertexArrays(IntBuffer arrays) { |
||||
checkLimit(arrays); |
||||
GLContext.getCurrentGL().getGL2ES3().glDeleteVertexArrays(arrays.limit(), arrays); |
||||
} |
||||
} |
@ -0,0 +1,88 @@ |
||||
package com.jme3.renderer.jogl; |
||||
|
||||
import com.jme3.renderer.RendererException; |
||||
import com.jme3.renderer.opengl.GLExt; |
||||
import com.jogamp.opengl.GLContext; |
||||
|
||||
import java.nio.Buffer; |
||||
import java.nio.FloatBuffer; |
||||
import java.nio.IntBuffer; |
||||
|
||||
public class JoglGLExt implements GLExt { |
||||
|
||||
private static int getLimitBytes(IntBuffer buffer) { |
||||
checkLimit(buffer); |
||||
return buffer.limit() * 4; |
||||
} |
||||
|
||||
private static void checkLimit(Buffer buffer) { |
||||
if (buffer == null) { |
||||
return; |
||||
} |
||||
if (buffer.limit() == 0) { |
||||
throw new RendererException("Attempting to upload empty buffer (limit = 0), that's an error"); |
||||
} |
||||
if (buffer.remaining() == 0) { |
||||
throw new RendererException("Attempting to upload empty buffer (remaining = 0), that's an error"); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void glBufferData(int target, IntBuffer data, int usage) { |
||||
checkLimit(data); |
||||
GLContext.getCurrentGL().glBufferData(target, getLimitBytes(data), data, usage); |
||||
} |
||||
|
||||
@Override |
||||
public void glBufferSubData(int target, long offset, IntBuffer data) { |
||||
checkLimit(data); |
||||
GLContext.getCurrentGL().glBufferSubData(target, getLimitBytes(data), offset, data); |
||||
} |
||||
|
||||
@Override |
||||
public void glDrawArraysInstancedARB(int mode, int first, int count, int primcount) { |
||||
GLContext.getCurrentGL().getGL2ES3().glDrawArraysInstanced(mode, first, count, primcount); |
||||
} |
||||
|
||||
@Override |
||||
public void glDrawBuffers(IntBuffer bufs) { |
||||
checkLimit(bufs); |
||||
GLContext.getCurrentGL().getGL2ES2().glDrawBuffers(bufs.limit(), bufs); |
||||
} |
||||
|
||||
@Override |
||||
public void glDrawElementsInstancedARB(int mode, int indices_count, int type, long indices_buffer_offset, int primcount) { |
||||
GLContext.getCurrentGL().getGL2ES3().glDrawElementsInstanced(mode, indices_count, type, indices_buffer_offset, primcount); |
||||
} |
||||
|
||||
@Override |
||||
public void glGetMultisample(int pname, int index, FloatBuffer val) { |
||||
checkLimit(val); |
||||
GLContext.getCurrentGL().getGL2ES2().glGetMultisamplefv(pname, index, val); |
||||
} |
||||
|
||||
@Override |
||||
public void glTexImage2DMultisample(int target, int samples, int internalformat, int width, int height, boolean fixedsamplelocations) { |
||||
GLContext.getCurrentGL().getGL2ES2().glTexImage2DMultisample(target, samples, internalformat, width, height, fixedsamplelocations); |
||||
} |
||||
|
||||
@Override |
||||
public void glVertexAttribDivisorARB(int index, int divisor) { |
||||
GLContext.getCurrentGL().getGL2ES3().glVertexAttribDivisor(index, divisor); |
||||
} |
||||
|
||||
@Override |
||||
public Object glFenceSync(int condition, int flags) { |
||||
return GLContext.getCurrentGL().getGL3ES3().glFenceSync(condition, flags); |
||||
} |
||||
|
||||
@Override |
||||
public int glClientWaitSync(Object sync, int flags, long timeout) { |
||||
return GLContext.getCurrentGL().getGL3ES3().glClientWaitSync(((Long) sync).longValue(), flags, timeout); |
||||
} |
||||
|
||||
@Override |
||||
public void glDeleteSync(Object sync) { |
||||
GLContext.getCurrentGL().getGL3ES3().glDeleteSync(((Long) sync).longValue()); |
||||
} |
||||
} |
@ -0,0 +1,97 @@ |
||||
package com.jme3.renderer.jogl; |
||||
|
||||
import com.jme3.renderer.RendererException; |
||||
import com.jme3.renderer.opengl.GLFbo; |
||||
import com.jogamp.opengl.GLContext; |
||||
|
||||
import java.nio.Buffer; |
||||
import java.nio.IntBuffer; |
||||
|
||||
/** |
||||
* Implements GLFbo |
||||
* |
||||
* @author Kirill Vainer |
||||
*/ |
||||
public class JoglGLFbo implements GLFbo { |
||||
|
||||
private static void checkLimit(Buffer buffer) { |
||||
if (buffer == null) { |
||||
return; |
||||
} |
||||
if (buffer.limit() == 0) { |
||||
throw new RendererException("Attempting to upload empty buffer (limit = 0), that's an error"); |
||||
} |
||||
if (buffer.remaining() == 0) { |
||||
throw new RendererException("Attempting to upload empty buffer (remaining = 0), that's an error"); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void glBlitFramebufferEXT(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, int mask, int filter) { |
||||
GLContext.getCurrentGL().getGL2ES3().glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
||||
} |
||||
|
||||
@Override |
||||
public void glRenderbufferStorageMultisampleEXT(int target, int samples, int internalformat, int width, int height) { |
||||
GLContext.getCurrentGL().glRenderbufferStorageMultisample(target, samples, internalformat, width, height); |
||||
} |
||||
|
||||
@Override |
||||
public void glBindFramebufferEXT(int param1, int param2) { |
||||
GLContext.getCurrentGL().glBindFramebuffer(param1, param2); |
||||
} |
||||
|
||||
@Override |
||||
public void glBindRenderbufferEXT(int param1, int param2) { |
||||
GLContext.getCurrentGL().glBindRenderbuffer(param1, param2); |
||||
} |
||||
|
||||
@Override |
||||
public int glCheckFramebufferStatusEXT(int param1) { |
||||
return GLContext.getCurrentGL().glCheckFramebufferStatus(param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glDeleteFramebuffersEXT(IntBuffer param1) { |
||||
checkLimit(param1); |
||||
GLContext.getCurrentGL().glDeleteFramebuffers(param1.limit(), param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glDeleteRenderbuffersEXT(IntBuffer param1) { |
||||
checkLimit(param1); |
||||
GLContext.getCurrentGL().glDeleteRenderbuffers(param1.limit(), param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glFramebufferRenderbufferEXT(int param1, int param2, int param3, int param4) { |
||||
GLContext.getCurrentGL().glFramebufferRenderbuffer(param1, param2, param3, param4); |
||||
} |
||||
|
||||
@Override |
||||
public void glFramebufferTexture2DEXT(int param1, int param2, int param3, int param4, int param5) { |
||||
GLContext.getCurrentGL().glFramebufferTexture2D(param1, param2, param3, param4, param5); |
||||
} |
||||
|
||||
@Override |
||||
public void glGenFramebuffersEXT(IntBuffer param1) { |
||||
checkLimit(param1); |
||||
GLContext.getCurrentGL().glGenFramebuffers(param1.limit(), param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glGenRenderbuffersEXT(IntBuffer param1) { |
||||
checkLimit(param1); |
||||
GLContext.getCurrentGL().glGenRenderbuffers(param1.limit(), param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glGenerateMipmapEXT(int param1) { |
||||
GLContext.getCurrentGL().glGenerateMipmap(param1); |
||||
} |
||||
|
||||
@Override |
||||
public void glRenderbufferStorageEXT(int param1, int param2, int param3, int param4) { |
||||
GLContext.getCurrentGL().glRenderbufferStorage(param1, param2, param3, param4); |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,80 @@ |
||||
/* |
||||
* Copyright (c) 2009-2015 jMonkeyEngine |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* |
||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
package com.jme3.system.jogl; |
||||
|
||||
import java.util.HashMap; |
||||
|
||||
import com.jogamp.opengl.GL2ES2; |
||||
import com.jogamp.opengl.GLDebugListener; |
||||
import com.jogamp.opengl.GLDebugMessage; |
||||
|
||||
class JoglGLDebugOutputHandler implements GLDebugListener { |
||||
|
||||
private static final HashMap<Integer, String> constMap = new HashMap<Integer, String>(); |
||||
private static final String MESSAGE_FORMAT = |
||||
"[JME3] OpenGL debug message\r\n" + |
||||
" ID: %d\r\n" + |
||||
" Source: %s\r\n" + |
||||
" Type: %s\r\n" + |
||||
" Severity: %s\r\n" + |
||||
" Message: %s"; |
||||
|
||||
static { |
||||
constMap.put(GL2ES2.GL_DEBUG_SOURCE_API, "API"); |
||||
constMap.put(GL2ES2.GL_DEBUG_SOURCE_APPLICATION, "APPLICATION"); |
||||
constMap.put(GL2ES2.GL_DEBUG_SOURCE_OTHER, "OTHER"); |
||||
constMap.put(GL2ES2.GL_DEBUG_SOURCE_SHADER_COMPILER, "SHADER_COMPILER"); |
||||
constMap.put(GL2ES2.GL_DEBUG_SOURCE_THIRD_PARTY, "THIRD_PARTY"); |
||||
constMap.put(GL2ES2.GL_DEBUG_SOURCE_WINDOW_SYSTEM, "WINDOW_SYSTEM"); |
||||
|
||||
constMap.put(GL2ES2.GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR, "DEPRECATED_BEHAVIOR"); |
||||
constMap.put(GL2ES2.GL_DEBUG_TYPE_ERROR, "ERROR"); |
||||
constMap.put(GL2ES2.GL_DEBUG_TYPE_OTHER, "OTHER"); |
||||
constMap.put(GL2ES2.GL_DEBUG_TYPE_PERFORMANCE, "PERFORMANCE"); |
||||
constMap.put(GL2ES2.GL_DEBUG_TYPE_PORTABILITY, "PORTABILITY"); |
||||
constMap.put(GL2ES2.GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR, "UNDEFINED_BEHAVIOR"); |
||||
|
||||
constMap.put(GL2ES2.GL_DEBUG_SEVERITY_HIGH, "HIGH"); |
||||
constMap.put(GL2ES2.GL_DEBUG_SEVERITY_MEDIUM, "MEDIUM"); |
||||
constMap.put(GL2ES2.GL_DEBUG_SEVERITY_LOW, "LOW"); |
||||
} |
||||
|
||||
@Override |
||||
public void messageSent(GLDebugMessage event) { |
||||
String sourceStr = constMap.get(event.getDbgSource()); |
||||
String typeStr = constMap.get(event.getDbgType()); |
||||
String severityStr = constMap.get(event.getDbgSeverity()); |
||||
|
||||
System.err.println(String.format(MESSAGE_FORMAT, event.getDbgId(), sourceStr, typeStr, severityStr, event.getDbgMsg())); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,15 @@ |
||||
if (!hasProperty('mainClass')) { |
||||
ext.mainClass = '' |
||||
} |
||||
|
||||
repositories { |
||||
maven { |
||||
url "https://oss.sonatype.org/content/repositories/snapshots" |
||||
} |
||||
} |
||||
|
||||
dependencies { |
||||
compile project(':jme3-core') |
||||
compile project(':jme3-desktop') |
||||
compile files('lib/lwjgl-3.0.0b-35.jar', 'lib/lwjgl-3.0.0b-35-natives.jar') |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue