aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorphil <[email protected]>2016-11-06 22:00:11 +1300
committerphil <[email protected]>2016-11-06 22:00:11 +1300
commit59f4133064790f9c74ae6c5c8710e64d5fd2e47d (patch)
treece023910b8e07dd3b6eb87bab6141dc6975a4629 /src
parent51db13b3650d71c108f444a820c0967a4aa28bfa (diff)
struct lightSource was always receiving all lights as enabled
Now it only receiving enabled lights and the variable enabled has been removed
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/jogamp/java3d/Jogl2es2Context.java13
-rw-r--r--src/main/java/org/jogamp/java3d/Jogl2es2Pipeline.java66
2 files changed, 43 insertions, 36 deletions
diff --git a/src/main/java/org/jogamp/java3d/Jogl2es2Context.java b/src/main/java/org/jogamp/java3d/Jogl2es2Context.java
index 143f556..6ed3add 100644
--- a/src/main/java/org/jogamp/java3d/Jogl2es2Context.java
+++ b/src/main/java/org/jogamp/java3d/Jogl2es2Context.java
@@ -62,11 +62,11 @@ public class Jogl2es2Context extends JoglContext
super.setShaderProgram(object);
shaderProgram = object;
shaderProgramId = object == null ? -1 : object.getValue();
- programData = allProgramData.get(shaderProgramId);
+ programData = allProgramData.get(new Integer(shaderProgramId));
if (programData == null)
{
programData = new ProgramData();
- allProgramData.put(shaderProgramId, programData);
+ allProgramData.put(new Integer(shaderProgramId), programData);
}
}
@@ -134,6 +134,7 @@ public class Jogl2es2Context extends JoglContext
public glFrontMaterial materialData = new glFrontMaterial();
// should use getMaximumLights() in pipeline? though it's up to the shader
public static int MAX_LIGHTS = 32;
+ public int maxLights;
public int numberOfLights;
public glLightSource[] glLightSource = new glLightSource[MAX_LIGHTS];
@@ -428,7 +429,6 @@ public class Jogl2es2Context extends JoglContext
}
// struct lightSource
// {
- // int enabled;
// vec4 position;
// vec4 diffuse;
// vec4 specular;
@@ -445,6 +445,7 @@ public class Jogl2es2Context extends JoglContext
public static class glLightSource
{
public int enabled = -1;
+ public int prevLightSlot = -1;
public Vector4f position = new Vector4f();
//public Vector4f ambient = new Vector4f();//removed as an oddity
public Vector4f diffuse = new Vector4f();
@@ -459,6 +460,7 @@ public class Jogl2es2Context extends JoglContext
public void clear()
{
enabled = -1;
+ prevLightSlot = -1;
position.set(-999f, -999f, -999f, -999f);
diffuse.set(-999f, -999f, -999f, -999f);
specular.set(-999f, -999f, -999f, -999f);
@@ -473,6 +475,7 @@ public class Jogl2es2Context extends JoglContext
public void set(glLightSource ogfm)
{
enabled = ogfm.enabled;
+ prevLightSlot = ogfm.prevLightSlot;
position.set(ogfm.position);
diffuse.set(ogfm.diffuse);
specular.set(ogfm.specular);
@@ -490,8 +493,8 @@ public class Jogl2es2Context extends JoglContext
if (o instanceof glLightSource)
{
glLightSource ogfm = (glLightSource) o;
- return enabled == ogfm.enabled && ogfm.position.equals(position) && ogfm.diffuse.equals(diffuse)
- && ogfm.specular.equals(specular) && ogfm.constantAttenuation == constantAttenuation
+ return enabled == ogfm.enabled && prevLightSlot == ogfm.prevLightSlot && ogfm.position.equals(position)
+ && ogfm.diffuse.equals(diffuse) && ogfm.specular.equals(specular) && ogfm.constantAttenuation == constantAttenuation
&& ogfm.linearAttenuation == linearAttenuation && ogfm.quadraticAttenuation == quadraticAttenuation
&& ogfm.spotCutoff == spotCutoff && ogfm.spotExponent == spotExponent && ogfm.spotDirection.equals(spotDirection);
}
diff --git a/src/main/java/org/jogamp/java3d/Jogl2es2Pipeline.java b/src/main/java/org/jogamp/java3d/Jogl2es2Pipeline.java
index aa15c4f..250433a 100644
--- a/src/main/java/org/jogamp/java3d/Jogl2es2Pipeline.java
+++ b/src/main/java/org/jogamp/java3d/Jogl2es2Pipeline.java
@@ -3271,40 +3271,43 @@ class Jogl2es2Pipeline extends Jogl2es2DEPPipeline
}
// the lighting structures
- for (int i = 0; i < ctx.numberOfLights; i++)
+ int lightSlotToUse = 0;
+ for (int i = 0; i < ctx.maxLights; i++)
{
- if (locs.glLightSource[i].present())
+ if (locs.glLightSource[lightSlotToUse].present())
{
- if (!MINIMISE_NATIVE_CALLS_FFP
- || (shaderProgramId != ctx.prevShaderProgram || !ctx.gl_state.glLightSource[i].equals(ctx.glLightSource[i])))
+ if (ctx.glLightSource[i].enabled == 1)
{
- if (locs.glLightSource[i].enabled != -1)
- gl.glUniform1i(locs.glLightSource[i].enabled, ctx.glLightSource[i].enabled);
- if (ctx.glLightSource[i].enabled == 1)
+ if (!MINIMISE_NATIVE_CALLS_FFP
+ || (shaderProgramId != ctx.prevShaderProgram || !ctx.gl_state.glLightSource[i].equals(ctx.glLightSource[i])))
{
- if (locs.glLightSource[i].position != -1)
- gl.glUniform4f(locs.glLightSource[i].position, ctx.glLightSource[i].position.x, ctx.glLightSource[i].position.y,
- ctx.glLightSource[i].position.z, ctx.glLightSource[i].position.w);
- if (locs.glLightSource[i].diffuse != -1)
- gl.glUniform4f(locs.glLightSource[i].diffuse, ctx.glLightSource[i].diffuse.x, ctx.glLightSource[i].diffuse.y,
- ctx.glLightSource[i].diffuse.z, ctx.glLightSource[i].diffuse.w);
- if (locs.glLightSource[i].specular != -1)
- gl.glUniform4f(locs.glLightSource[i].specular, ctx.glLightSource[i].specular.x, ctx.glLightSource[i].specular.y,
- ctx.glLightSource[i].specular.z, ctx.glLightSource[i].specular.w);
- if (locs.glLightSource[i].constantAttenuation != -1)
- gl.glUniform1f(locs.glLightSource[i].constantAttenuation, ctx.glLightSource[i].constantAttenuation);
- if (locs.glLightSource[i].linearAttenuation != -1)
- gl.glUniform1f(locs.glLightSource[i].linearAttenuation, ctx.glLightSource[i].linearAttenuation);
- if (locs.glLightSource[i].quadraticAttenuation != -1)
- gl.glUniform1f(locs.glLightSource[i].quadraticAttenuation, ctx.glLightSource[i].quadraticAttenuation);
- if (locs.glLightSource[i].spotCutoff != -1)
- gl.glUniform1f(locs.glLightSource[i].spotCutoff, ctx.glLightSource[i].spotCutoff);
- if (locs.glLightSource[i].spotExponent != -1)
- gl.glUniform1f(locs.glLightSource[i].spotExponent, ctx.glLightSource[i].spotExponent);
- if (locs.glLightSource[i].spotDirection != -1)
- gl.glUniform3f(locs.glLightSource[i].spotDirection, ctx.glLightSource[i].spotDirection.x,
+ ctx.glLightSource[i].prevLightSlot = lightSlotToUse;// record for the equals check
+ if (locs.glLightSource[lightSlotToUse].position != -1)
+ gl.glUniform4f(locs.glLightSource[lightSlotToUse].position, ctx.glLightSource[i].position.x,
+ ctx.glLightSource[i].position.y, ctx.glLightSource[i].position.z, ctx.glLightSource[i].position.w);
+ if (locs.glLightSource[lightSlotToUse].diffuse != -1)
+ gl.glUniform4f(locs.glLightSource[lightSlotToUse].diffuse, ctx.glLightSource[i].diffuse.x,
+ ctx.glLightSource[i].diffuse.y, ctx.glLightSource[i].diffuse.z, ctx.glLightSource[i].diffuse.w);
+ if (locs.glLightSource[lightSlotToUse].specular != -1)
+ gl.glUniform4f(locs.glLightSource[lightSlotToUse].specular, ctx.glLightSource[i].specular.x,
+ ctx.glLightSource[i].specular.y, ctx.glLightSource[i].specular.z, ctx.glLightSource[i].specular.w);
+ if (locs.glLightSource[lightSlotToUse].constantAttenuation != -1)
+ gl.glUniform1f(locs.glLightSource[lightSlotToUse].constantAttenuation,
+ ctx.glLightSource[i].constantAttenuation);
+ if (locs.glLightSource[lightSlotToUse].linearAttenuation != -1)
+ gl.glUniform1f(locs.glLightSource[lightSlotToUse].linearAttenuation, ctx.glLightSource[i].linearAttenuation);
+ if (locs.glLightSource[lightSlotToUse].quadraticAttenuation != -1)
+ gl.glUniform1f(locs.glLightSource[lightSlotToUse].quadraticAttenuation,
+ ctx.glLightSource[i].quadraticAttenuation);
+ if (locs.glLightSource[lightSlotToUse].spotCutoff != -1)
+ gl.glUniform1f(locs.glLightSource[lightSlotToUse].spotCutoff, ctx.glLightSource[i].spotCutoff);
+ if (locs.glLightSource[lightSlotToUse].spotExponent != -1)
+ gl.glUniform1f(locs.glLightSource[lightSlotToUse].spotExponent, ctx.glLightSource[i].spotExponent);
+ if (locs.glLightSource[lightSlotToUse].spotDirection != -1)
+ gl.glUniform3f(locs.glLightSource[lightSlotToUse].spotDirection, ctx.glLightSource[i].spotDirection.x,
ctx.glLightSource[i].spotDirection.y, ctx.glLightSource[i].spotDirection.z);
}
+ lightSlotToUse++;
if (DO_OUTPUT_ERRORS)
outputErrors(ctx);
@@ -3452,7 +3455,6 @@ class Jogl2es2Pipeline extends Jogl2es2DEPPipeline
for (int i = 0; i < locs.glLightSource.length; i++)
{
locs.glLightSource[i] = new glLightSourceLocs();
- locs.glLightSource[i].enabled = gl.glGetUniformLocation(shaderProgramId, "glLightSource[" + i + "].enabled");
locs.glLightSource[i].position = gl.glGetUniformLocation(shaderProgramId, "glLightSource[" + i + "].position");
locs.glLightSource[i].diffuse = gl.glGetUniformLocation(shaderProgramId, "glLightSource[" + i + "].diffuse");
locs.glLightSource[i].specular = gl.glGetUniformLocation(shaderProgramId, "glLightSource[" + i + "].specular");
@@ -6435,10 +6437,11 @@ class Jogl2es2Pipeline extends Jogl2es2DEPPipeline
((Jogl2es2Context) ctx).perFrameStats.setLightEnables++;
Jogl2es2Context joglesctx = (Jogl2es2Context) ctx;
- joglesctx.numberOfLights = maxLights;
+ joglesctx.maxLights = maxLights;
+ joglesctx.numberOfLights = 0;
for (int i = 0; i < maxLights; i++)
{
- boolean enable = ((enableMask << i) != 0);
+ boolean enable = (enableMask & (1 << i)) >> i != 0;
if (joglesctx.glLightSource[i] == null)
{
joglesctx.glLightSource[i] = new glLightSource();
@@ -6446,6 +6449,7 @@ class Jogl2es2Pipeline extends Jogl2es2DEPPipeline
}
joglesctx.glLightSource[i].enabled = enable ? 1 : 0;
+ joglesctx.numberOfLights += enable ? 1 : 0;
}
}