* Remove deprecated fields from shader class

* Add package private deleteNativeBuffers() in NativeObject (usage TBD)

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10617 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
sha..RD 12 years ago
parent 66ed9ff986
commit bf2a663022
  1. 8
      engine/src/core/com/jme3/audio/AudioBuffer.java
  2. 4
      engine/src/core/com/jme3/audio/AudioData.java
  3. 4
      engine/src/core/com/jme3/audio/Filter.java
  4. 24
      engine/src/core/com/jme3/renderer/Caps.java
  5. 54
      engine/src/core/com/jme3/scene/VertexBuffer.java
  6. 102
      engine/src/core/com/jme3/shader/Shader.java
  7. 4
      engine/src/core/com/jme3/texture/FrameBuffer.java
  8. 12
      engine/src/core/com/jme3/texture/Image.java
  9. 47
      engine/src/core/com/jme3/util/NativeObject.java
  10. 5
      engine/src/tools/jme3tools/shadercheck/CgcValidator.java
  11. 5
      engine/src/tools/jme3tools/shadercheck/GpuAnalyzerValidator.java

@ -32,6 +32,7 @@
package com.jme3.audio; package com.jme3.audio;
import com.jme3.audio.AudioData.DataType; import com.jme3.audio.AudioData.DataType;
import com.jme3.util.BufferUtils;
import com.jme3.util.NativeObject; import com.jme3.util.NativeObject;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -102,8 +103,11 @@ public class AudioBuffer extends AudioData {
setUpdateNeeded(); setUpdateNeeded();
} }
public void deleteObject(AudioRenderer ar) { @Override
protected void deleteNativeBuffers() {
if (audioData != null) {
BufferUtils.destroyDirectBuffer(audioData);
}
} }
@Override @Override

@ -53,11 +53,11 @@ public abstract class AudioData extends NativeObject {
} }
public AudioData(){ public AudioData(){
super(AudioData.class); super();
} }
protected AudioData(int id){ protected AudioData(int id){
super(AudioData.class, id); super(id);
} }
/** /**

@ -40,11 +40,11 @@ import java.io.IOException;
public abstract class Filter extends NativeObject implements Savable { public abstract class Filter extends NativeObject implements Savable {
public Filter(){ public Filter(){
super(Filter.class); super();
} }
protected Filter(int id){ protected Filter(int id){
super(Filter.class, id); super(id);
} }
public void write(JmeExporter ex) throws IOException { public void write(JmeExporter ex) throws IOException {

@ -32,6 +32,7 @@
package com.jme3.renderer; package com.jme3.renderer;
import com.jme3.shader.Shader; import com.jme3.shader.Shader;
import com.jme3.shader.Shader.ShaderSource;
import com.jme3.texture.FrameBuffer; import com.jme3.texture.FrameBuffer;
import com.jme3.texture.FrameBuffer.RenderBuffer; import com.jme3.texture.FrameBuffer.RenderBuffer;
import com.jme3.texture.Image; import com.jme3.texture.Image;
@ -346,29 +347,30 @@ public enum Caps {
* @return True if it is supported, false otherwise. * @return True if it is supported, false otherwise.
*/ */
public static boolean supports(Collection<Caps> caps, Shader shader){ public static boolean supports(Collection<Caps> caps, Shader shader){
String lang = shader.getLanguage(); for (ShaderSource source : shader.getSources()) {
if (lang.startsWith("GLSL")){ if (source.getLanguage().startsWith("GLSL")) {
int ver = Integer.parseInt(lang.substring(4)); int ver = Integer.parseInt(source.getLanguage().substring(4));
switch (ver) { switch (ver) {
case 100: case 100:
return caps.contains(Caps.GLSL100); if (!caps.contains(Caps.GLSL100)) return false;
case 110: case 110:
return caps.contains(Caps.GLSL110); if (!caps.contains(Caps.GLSL110)) return false;
case 120: case 120:
return caps.contains(Caps.GLSL120); if (!caps.contains(Caps.GLSL120)) return false;
case 130: case 130:
return caps.contains(Caps.GLSL130); if (!caps.contains(Caps.GLSL130)) return false;
case 140: case 140:
return caps.contains(Caps.GLSL140); if (!caps.contains(Caps.GLSL140)) return false;
case 150: case 150:
return caps.contains(Caps.GLSL150); if (!caps.contains(Caps.GLSL150)) return false;
case 330: case 330:
return caps.contains(Caps.GLSL330); if (!caps.contains(Caps.GLSL330)) return false;
default: default:
return false; return false;
} }
} }
return false; }
return true;
} }
} }

@ -319,7 +319,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* Must call setupData() to initialize. * Must call setupData() to initialize.
*/ */
public VertexBuffer(Type type){ public VertexBuffer(Type type){
super(VertexBuffer.class); super();
this.bufType = type; this.bufType = type;
} }
@ -327,11 +327,52 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* Serialization only. Do not use. * Serialization only. Do not use.
*/ */
public VertexBuffer(){ public VertexBuffer(){
super(VertexBuffer.class); super();
} }
protected VertexBuffer(int id){ protected VertexBuffer(int id){
super(VertexBuffer.class, id); super(id);
}
public boolean invariant() {
// Does the VB hold any data?
if (data == null) {
throw new AssertionError();
}
// Does offset exceed buffer limit or negative?
if (offset > data.limit() || offset < 0) {
throw new AssertionError();
}
// Are components between 1 and 4?
if (components < 1 || components > 4) {
throw new AssertionError();
}
// Does usage comply with buffer directness?
//if (usage == Usage.CpuOnly && data.isDirect()) {
// throw new AssertionError();
/*} else*/ if (usage != Usage.CpuOnly && !data.isDirect()) {
throw new AssertionError();
}
// Double/Char/Long buffers are not supported for VertexBuffers.
// For the rest, ensure they comply with the "Format" value.
if (data instanceof DoubleBuffer) {
throw new AssertionError();
} else if (data instanceof CharBuffer) {
throw new AssertionError();
} else if (data instanceof LongBuffer) {
throw new AssertionError();
} else if (data instanceof FloatBuffer && format != Format.Float) {
throw new AssertionError();
} else if (data instanceof IntBuffer && format != Format.Int && format != Format.UnsignedInt) {
throw new AssertionError();
} else if (data instanceof ShortBuffer && format != Format.Short && format != Format.UnsignedShort) {
throw new AssertionError();
} else if (data instanceof ByteBuffer && format != Format.Byte && format != Format.UnsignedByte) {
throw new AssertionError();
}
return true;
} }
/** /**
@ -951,6 +992,13 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
((Renderer)rendererObject).deleteBuffer(this); ((Renderer)rendererObject).deleteBuffer(this);
} }
@Override
protected void deleteNativeBuffers() {
if (data != null) {
BufferUtils.destroyDirectBuffer(data);
}
}
@Override @Override
public NativeObject createDestructableClone(){ public NativeObject createDestructableClone(){
return new VertexBuffer(id); return new VertexBuffer(id);

@ -42,14 +42,6 @@ import java.util.Collection;
public final class Shader extends NativeObject { public final class Shader extends NativeObject {
/**
*
* @deprecated shader language now specified per shader source. See
* {@link ShaderSource#setLanguage(String)
*/
@Deprecated
private String language;
/** /**
* A list of all shader sources currently attached. * A list of all shader sources currently attached.
*/ */
@ -98,7 +90,7 @@ public final class Shader extends NativeObject {
String defines; String defines;
public ShaderSource(ShaderType type){ public ShaderSource(ShaderType type){
super(ShaderSource.class); super();
this.sourceType = type; this.sourceType = type;
if (type == null) { if (type == null) {
throw new IllegalArgumentException("The shader type must be specified"); throw new IllegalArgumentException("The shader type must be specified");
@ -106,13 +98,13 @@ public final class Shader extends NativeObject {
} }
protected ShaderSource(ShaderSource ss){ protected ShaderSource(ShaderSource ss){
super(ShaderSource.class, ss.id); super(ss.id);
// No data needs to be copied. // No data needs to be copied.
// (This is a destructable clone) // (This is a destructable clone)
} }
public ShaderSource(){ public ShaderSource(){
super(ShaderSource.class); super();
} }
public void setName(String name){ public void setName(String name){
@ -190,17 +182,6 @@ public final class Shader extends NativeObject {
} }
} }
/**
* @deprecated Shader sources are now associated with the shader
* language.
*/
@Deprecated
public Shader(String language){
super(Shader.class);
this.language = language;
initialize();
}
/** /**
* Initializes the shader for use, must be called after the * Initializes the shader for use, must be called after the
* constructor without arguments is used. * constructor without arguments is used.
@ -216,14 +197,14 @@ public final class Shader extends NativeObject {
* after this constructor for the shader to be usable. * after this constructor for the shader to be usable.
*/ */
public Shader(){ public Shader(){
super(Shader.class); super();
} }
/** /**
* Do not use this constructor. Used for destructable clones only. * Do not use this constructor. Used for destructable clones only.
*/ */
protected Shader(Shader s){ protected Shader(Shader s){
super(Shader.class, s.id); super(s.id);
// Shader sources cannot be shared, therefore they must // Shader sources cannot be shared, therefore they must
// be destroyed together with the parent shader. // be destroyed together with the parent shader.
@ -233,43 +214,6 @@ public final class Shader extends NativeObject {
} }
} }
/**
* @deprecated Use the method that takes a language argument instead.
* {@link #addSource(com.jme3.shader.Shader.ShaderType, java.lang.String, java.lang.String, java.lang.String, java.lang.String) }
*/
@Deprecated
public void addSource(ShaderType type, String name, String source, String defines) {
addSource(type, name, source, defines, this.language);
}
/**
* @deprecated Use the method that takes a language argument instead.
* {@link #addSource(com.jme3.shader.Shader.ShaderType, java.lang.String, java.lang.String, java.lang.String, java.lang.String) }
*/
@Deprecated
public void addSource(ShaderType type, String source, String defines){
addSource(type, null, source, defines);
}
/**
* @deprecated Use the method that takes a language argument instead.
* {@link #addSource(com.jme3.shader.Shader.ShaderType, java.lang.String, java.lang.String, java.lang.String, java.lang.String) }
*/
@Deprecated
public void addSource(ShaderType type, String source){
addSource(type, source, null);
}
/**
* @deprecated Shader sources may not be shared.
* {@link #addSource(com.jme3.shader.Shader.ShaderType, java.lang.String, java.lang.String, java.lang.String, java.lang.String) }
*/
@Deprecated
private void addSource(ShaderSource source){
shaderSourceList.add(source);
setUpdateNeeded();
}
/** /**
* Adds source code to a certain pipeline. * Adds source code to a certain pipeline.
* *
@ -324,15 +268,6 @@ public final class Shader extends NativeObject {
return shaderSourceList; return shaderSourceList;
} }
/**
* @deprecated Shaders no longer have a language variable,
* use {@link ShaderSource#getLanguage() } instead.
*/
@Deprecated
public String getLanguage(){
return language;
}
@Override @Override
public String toString() { public String toString() {
return getClass().getSimpleName() + return getClass().getSimpleName() +
@ -341,33 +276,6 @@ public final class Shader extends NativeObject {
", shaderSources=" + getSources() + "]"; ", shaderSources=" + getSources() + "]";
} }
/**
* @deprecated This method is not needed since deleting
* a shader causes the sources to delete as well, thus its not required
* for them to be GC'd to be removed from GL.
*/
@Deprecated
public void resetSources(){
shaderSourceList.clear();
}
/**
* @deprecated Unusable shaders cause the renderer to crash,
* therefore this field no longer serves any purpose.
*/
@Deprecated
public boolean isUsable(){
return true;
}
/**
* @deprecated Unusable shaders cause the renderer to crash,
* therefore this field no longer serves any purpose.
*/
@Deprecated
public void setUsable(boolean usable){
}
/** /**
* Usually called when the shader itself changes or during any * Usually called when the shader itself changes or during any
* time when the variable locations need to be refreshed. * time when the variable locations need to be refreshed.

@ -175,7 +175,7 @@ public class FrameBuffer extends NativeObject {
* @throws IllegalArgumentException If width or height are not positive. * @throws IllegalArgumentException If width or height are not positive.
*/ */
public FrameBuffer(int width, int height, int samples){ public FrameBuffer(int width, int height, int samples){
super(FrameBuffer.class); super();
if (width <= 0 || height <= 0) if (width <= 0 || height <= 0)
throw new IllegalArgumentException("FrameBuffer must have valid size."); throw new IllegalArgumentException("FrameBuffer must have valid size.");
@ -185,7 +185,7 @@ public class FrameBuffer extends NativeObject {
} }
protected FrameBuffer(FrameBuffer src){ protected FrameBuffer(FrameBuffer src){
super(FrameBuffer.class, src.id); super(src.id);
/* /*
for (RenderBuffer renderBuf : src.colorBufs){ for (RenderBuffer renderBuf : src.colorBufs){
RenderBuffer clone = renderBuf.createDestructableClone(); RenderBuffer clone = renderBuf.createDestructableClone();

@ -34,6 +34,7 @@ package com.jme3.texture;
import com.jme3.export.*; import com.jme3.export.*;
import com.jme3.renderer.Caps; import com.jme3.renderer.Caps;
import com.jme3.renderer.Renderer; import com.jme3.renderer.Renderer;
import com.jme3.util.BufferUtils;
import com.jme3.util.NativeObject; import com.jme3.util.NativeObject;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -375,6 +376,13 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
setUpdateNeeded(); setUpdateNeeded();
} }
@Override
protected void deleteNativeBuffers() {
for (ByteBuffer buf : data) {
BufferUtils.destroyDirectBuffer(buf);
}
}
@Override @Override
public void deleteObject(Object rendererObject) { public void deleteObject(Object rendererObject) {
((Renderer)rendererObject).deleteImage(this); ((Renderer)rendererObject).deleteImage(this);
@ -402,12 +410,12 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
* are undefined. * are undefined.
*/ */
public Image() { public Image() {
super(Image.class); super();
data = new ArrayList<ByteBuffer>(1); data = new ArrayList<ByteBuffer>(1);
} }
protected Image(int id){ protected Image(int id){
super(Image.class, id); super(id);
} }
/** /**

@ -31,6 +31,8 @@
*/ */
package com.jme3.util; package com.jme3.util;
import java.nio.Buffer;
/** /**
* Describes a native object. An encapsulation of a certain object * Describes a native object. An encapsulation of a certain object
* on the native side of the graphics or audio library. * on the native side of the graphics or audio library.
@ -41,11 +43,13 @@ package com.jme3.util;
*/ */
public abstract class NativeObject implements Cloneable { public abstract class NativeObject implements Cloneable {
public static final int INVALID_ID = -1;
/** /**
* The ID of the object, usually depends on its type. * The ID of the object, usually depends on its type.
* Typically returned from calls like glGenTextures, glGenBuffers, etc. * Typically returned from calls like glGenTextures, glGenBuffers, etc.
*/ */
protected int id = -1; protected int id = INVALID_ID;
/** /**
* A reference to a "handle". By hard referencing a certain object, it's * A reference to a "handle". By hard referencing a certain object, it's
@ -60,19 +64,13 @@ public abstract class NativeObject implements Cloneable {
*/ */
protected boolean updateNeeded = true; protected boolean updateNeeded = true;
/**
* The type of the GLObject, usually specified by a subclass.
*/
protected final Class<?> type;
/** /**
* Creates a new GLObject with the given type. Should be * Creates a new GLObject with the given type. Should be
* called by the subclasses. * called by the subclasses.
* *
* @param type The type that the subclass represents. * @param type The type that the subclass represents.
*/ */
public NativeObject(Class<?> type){ public NativeObject(){
this.type = type;
this.handleRef = new Object(); this.handleRef = new Object();
} }
@ -80,8 +78,7 @@ public abstract class NativeObject implements Cloneable {
* Protected constructor that doesn't allocate handle ref. * Protected constructor that doesn't allocate handle ref.
* This is used in subclasses for the createDestructableClone(). * This is used in subclasses for the createDestructableClone().
*/ */
protected NativeObject(Class<?> type, int id){ protected NativeObject(int id){
this.type = type;
this.id = id; this.id = id;
} }
@ -91,9 +88,9 @@ public abstract class NativeObject implements Cloneable {
* @param id The ID to set * @param id The ID to set
*/ */
public void setId(int id){ public void setId(int id){
if (this.id != -1) if (this.id != INVALID_ID) {
throw new IllegalStateException("ID has already been set for this GL object."); throw new IllegalStateException("ID has already been set for this GL object.");
}
this.id = id; this.id = id;
} }
@ -129,7 +126,7 @@ public abstract class NativeObject implements Cloneable {
@Override @Override
public String toString(){ public String toString(){
return "Native" + type.getSimpleName() + " " + id; return "Native" + getClass().getSimpleName() + " " + id;
} }
/** /**
@ -141,7 +138,7 @@ public abstract class NativeObject implements Cloneable {
try { try {
NativeObject obj = (NativeObject) super.clone(); NativeObject obj = (NativeObject) super.clone();
obj.handleRef = new Object(); obj.handleRef = new Object();
obj.id = -1; obj.id = INVALID_ID;
obj.updateNeeded = true; obj.updateNeeded = true;
return obj; return obj;
} catch (CloneNotSupportedException ex) { } catch (CloneNotSupportedException ex) {
@ -149,6 +146,28 @@ public abstract class NativeObject implements Cloneable {
} }
} }
/**
* Deletes any associated native {@link Buffer buffers}.
* This is necessary because it is unlikely that native buffers
* will be garbage collected naturally (due to how GC works), therefore
* the collection must be handled manually.
*
* Only implementations that manage native buffers need to override
* this method. Note that the behavior that occurs when a
* deleted native buffer is used is not defined, therefore this
* method is protected
*/
protected void deleteNativeBuffers() {
}
/**
* Package-private version of {@link #deleteNativeBuffers() }, to be used
* from the {@link NativeObjectManager}.
*/
void deleteNativeBuffersInternal() {
deleteNativeBuffers();
}
/** /**
* Called when the GL context is restarted to reset all IDs. Prevents * Called when the GL context is restarted to reset all IDs. Prevents
* "white textures" on display restart. * "white textures" on display restart.

@ -95,15 +95,14 @@ public class CgcValidator implements Validator {
} }
public void validate(Shader shader, StringBuilder results) { public void validate(Shader shader, StringBuilder results) {
String language = shader.getLanguage();
for (ShaderSource source : shader.getSources()){ for (ShaderSource source : shader.getSources()){
results.append("Checking: ").append(source.getName()); results.append("Checking: ").append(source.getName());
switch (source.getType()){ switch (source.getType()){
case Fragment: case Fragment:
executeCg(source.getSource(), language, source.getDefines(), "arbfp1", results); executeCg(source.getSource(), source.getLanguage(), source.getDefines(), "arbfp1", results);
break; break;
case Vertex: case Vertex:
executeCg(source.getSource(), language, source.getDefines(), "arbvp1", results); executeCg(source.getSource(), source.getLanguage(), source.getDefines(), "arbvp1", results);
break; break;
} }
} }

@ -105,15 +105,14 @@ public class GpuAnalyzerValidator implements Validator {
} }
public void validate(Shader shader, StringBuilder results) { public void validate(Shader shader, StringBuilder results) {
String language = shader.getLanguage();
for (ShaderSource source : shader.getSources()){ for (ShaderSource source : shader.getSources()){
results.append("Checking: ").append(source.getName()); results.append("Checking: ").append(source.getName());
switch (source.getType()){ switch (source.getType()){
case Fragment: case Fragment:
executeAnalyzer(source.getSource(), language, source.getDefines(), "HD5770", results); executeAnalyzer(source.getSource(), source.getLanguage(), source.getDefines(), "HD5770", results);
break; break;
case Vertex: case Vertex:
executeAnalyzer(source.getSource(), language, source.getDefines(), "HD5770", results); executeAnalyzer(source.getSource(), source.getLanguage(), source.getDefines(), "HD5770", results);
break; break;
} }
} }

Loading…
Cancel
Save