* Prevent shader leaks
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7891 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
6c4a13ddde
commit
3bd4146f4b
@ -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<ShaderSource>();
|
||||
// uniforms = new HashMap<String, Uniform>();
|
||||
uniforms = new ListMap<String, Uniform>();
|
||||
attribs = new IntMap<Attribute>();
|
||||
//uniforms = new ListMap<String, Uniform>();
|
||||
//attribs = new IntMap<Attribute>();
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user