diff --git a/engine/src/core/com/jme3/shader/Shader.java b/engine/src/core/com/jme3/shader/Shader.java index 4844f639f..db64a05bf 100644 --- a/engine/src/core/com/jme3/shader/Shader.java +++ b/engine/src/core/com/jme3/shader/Shader.java @@ -98,7 +98,7 @@ public final class Shader extends GLObject implements Savable { * Shader source describes a shader object in OpenGL. Each shader source * is assigned a certain pipeline which it controls (described by it's type). */ - public class ShaderSource extends GLObject implements Savable { + public static class ShaderSource extends GLObject implements Savable { ShaderType shaderType; @@ -236,11 +236,13 @@ public final class Shader extends GLObject implements Savable { protected Shader(Shader s){ super(Type.Shader, s.id); shaderList = new ArrayList(); -// uniforms = new HashMap(); - uniforms = new ListMap(); - attribs = new IntMap(); + //uniforms = new ListMap(); + //attribs = new IntMap(); + + // NOTE: Because ShaderSources are registered separately with + // the GLObjectManager for (ShaderSource source : s.shaderList){ - addSource((ShaderSource) source.createDestructableClone()); + shaderList.add( (ShaderSource)source.createDestructableClone() ); } } @@ -315,7 +317,7 @@ public final class Shader extends GLObject implements Savable { * Adds an existing shader source to this shader. * @param source */ - public void addSource(ShaderSource source){ + private void addSource(ShaderSource source){ shaderList.add(source); setUpdateNeeded(); } diff --git a/engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglRenderer.java b/engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglRenderer.java index 1ac166652..33ade7ac0 100644 --- a/engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglRenderer.java +++ b/engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglRenderer.java @@ -955,6 +955,8 @@ public class LwjglRenderer implements Renderer { } source.setId(id); + }else{ + throw new RendererException("Cannot recompile shader source"); } // upload shader source @@ -1034,7 +1036,10 @@ public class LwjglRenderer implements Renderer { glDeleteShader(id); } else { // register for cleanup since the ID is usable - objManager.registerForCleanup(source); + // NOTE: From now on cleanup is handled + // by the parent shader object so no need + // to register. + //objManager.registerForCleanup(source); } } @@ -1188,13 +1193,14 @@ public class LwjglRenderer implements Renderer { logger.warning("Shader is not uploaded to GPU, cannot delete."); return; } + for (ShaderSource source : shader.getSources()) { if (source.getId() != -1) { glDetachShader(shader.getId(), source.getId()); - // the next part is done by the GLObjectManager automatically -// glDeleteShader(source.getId()); + deleteShaderSource(source); } } + // kill all references so sources can be collected // if needed. shader.resetSources();