• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Main repository of MikuMikuStudio


コミットメタ情報

リビジョンcc0807758b42fe049353e88d2a78c626b46ac27c (tree)
日時2013-05-16 09:34:16
作者shadowisLORD <shadowisLORD@75d0...>
コミッターshadowisLORD

ログメッセージ

  • Remove deprecated fields from shader class
  • Add package private deleteNativeBuffers() in NativeObject (usage TBD)

git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@10617 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

変更サマリ

差分

--- a/engine/src/core/com/jme3/audio/AudioBuffer.java
+++ b/engine/src/core/com/jme3/audio/AudioBuffer.java
@@ -32,6 +32,7 @@
3232 package com.jme3.audio;
3333
3434 import com.jme3.audio.AudioData.DataType;
35+import com.jme3.util.BufferUtils;
3536 import com.jme3.util.NativeObject;
3637 import java.nio.ByteBuffer;
3738
@@ -102,10 +103,13 @@ public class AudioBuffer extends AudioData {
102103 setUpdateNeeded();
103104 }
104105
105- public void deleteObject(AudioRenderer ar) {
106-
106+ @Override
107+ protected void deleteNativeBuffers() {
108+ if (audioData != null) {
109+ BufferUtils.destroyDirectBuffer(audioData);
110+ }
107111 }
108-
112+
109113 @Override
110114 public void deleteObject(Object rendererObject) {
111115 ((AudioRenderer)rendererObject).deleteAudioData(this);
--- a/engine/src/core/com/jme3/audio/AudioData.java
+++ b/engine/src/core/com/jme3/audio/AudioData.java
@@ -53,11 +53,11 @@ public abstract class AudioData extends NativeObject {
5353 }
5454
5555 public AudioData(){
56- super(AudioData.class);
56+ super();
5757 }
5858
5959 protected AudioData(int id){
60- super(AudioData.class, id);
60+ super(id);
6161 }
6262
6363 /**
--- a/engine/src/core/com/jme3/audio/Filter.java
+++ b/engine/src/core/com/jme3/audio/Filter.java
@@ -40,11 +40,11 @@ import java.io.IOException;
4040 public abstract class Filter extends NativeObject implements Savable {
4141
4242 public Filter(){
43- super(Filter.class);
43+ super();
4444 }
4545
4646 protected Filter(int id){
47- super(Filter.class, id);
47+ super(id);
4848 }
4949
5050 public void write(JmeExporter ex) throws IOException {
--- a/engine/src/core/com/jme3/renderer/Caps.java
+++ b/engine/src/core/com/jme3/renderer/Caps.java
@@ -32,6 +32,7 @@
3232 package com.jme3.renderer;
3333
3434 import com.jme3.shader.Shader;
35+import com.jme3.shader.Shader.ShaderSource;
3536 import com.jme3.texture.FrameBuffer;
3637 import com.jme3.texture.FrameBuffer.RenderBuffer;
3738 import com.jme3.texture.Image;
@@ -346,29 +347,30 @@ public enum Caps {
346347 * @return True if it is supported, false otherwise.
347348 */
348349 public static boolean supports(Collection<Caps> caps, Shader shader){
349- String lang = shader.getLanguage();
350- if (lang.startsWith("GLSL")){
351- int ver = Integer.parseInt(lang.substring(4));
352- switch (ver){
353- case 100:
354- return caps.contains(Caps.GLSL100);
355- case 110:
356- return caps.contains(Caps.GLSL110);
357- case 120:
358- return caps.contains(Caps.GLSL120);
359- case 130:
360- return caps.contains(Caps.GLSL130);
361- case 140:
362- return caps.contains(Caps.GLSL140);
363- case 150:
364- return caps.contains(Caps.GLSL150);
365- case 330:
366- return caps.contains(Caps.GLSL330);
367- default:
368- return false;
350+ for (ShaderSource source : shader.getSources()) {
351+ if (source.getLanguage().startsWith("GLSL")) {
352+ int ver = Integer.parseInt(source.getLanguage().substring(4));
353+ switch (ver) {
354+ case 100:
355+ if (!caps.contains(Caps.GLSL100)) return false;
356+ case 110:
357+ if (!caps.contains(Caps.GLSL110)) return false;
358+ case 120:
359+ if (!caps.contains(Caps.GLSL120)) return false;
360+ case 130:
361+ if (!caps.contains(Caps.GLSL130)) return false;
362+ case 140:
363+ if (!caps.contains(Caps.GLSL140)) return false;
364+ case 150:
365+ if (!caps.contains(Caps.GLSL150)) return false;
366+ case 330:
367+ if (!caps.contains(Caps.GLSL330)) return false;
368+ default:
369+ return false;
370+ }
369371 }
370372 }
371- return false;
373+ return true;
372374 }
373375
374376 }
--- a/engine/src/core/com/jme3/scene/VertexBuffer.java
+++ b/engine/src/core/com/jme3/scene/VertexBuffer.java
@@ -319,7 +319,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
319319 * Must call setupData() to initialize.
320320 */
321321 public VertexBuffer(Type type){
322- super(VertexBuffer.class);
322+ super();
323323 this.bufType = type;
324324 }
325325
@@ -327,13 +327,54 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
327327 * Serialization only. Do not use.
328328 */
329329 public VertexBuffer(){
330- super(VertexBuffer.class);
330+ super();
331331 }
332332
333333 protected VertexBuffer(int id){
334- super(VertexBuffer.class, id);
334+ super(id);
335335 }
336336
337+ public boolean invariant() {
338+ // Does the VB hold any data?
339+ if (data == null) {
340+ throw new AssertionError();
341+ }
342+ // Does offset exceed buffer limit or negative?
343+ if (offset > data.limit() || offset < 0) {
344+ throw new AssertionError();
345+ }
346+ // Are components between 1 and 4?
347+ if (components < 1 || components > 4) {
348+ throw new AssertionError();
349+ }
350+
351+ // Does usage comply with buffer directness?
352+ //if (usage == Usage.CpuOnly && data.isDirect()) {
353+ // throw new AssertionError();
354+ /*} else*/ if (usage != Usage.CpuOnly && !data.isDirect()) {
355+ throw new AssertionError();
356+ }
357+
358+ // Double/Char/Long buffers are not supported for VertexBuffers.
359+ // For the rest, ensure they comply with the "Format" value.
360+ if (data instanceof DoubleBuffer) {
361+ throw new AssertionError();
362+ } else if (data instanceof CharBuffer) {
363+ throw new AssertionError();
364+ } else if (data instanceof LongBuffer) {
365+ throw new AssertionError();
366+ } else if (data instanceof FloatBuffer && format != Format.Float) {
367+ throw new AssertionError();
368+ } else if (data instanceof IntBuffer && format != Format.Int && format != Format.UnsignedInt) {
369+ throw new AssertionError();
370+ } else if (data instanceof ShortBuffer && format != Format.Short && format != Format.UnsignedShort) {
371+ throw new AssertionError();
372+ } else if (data instanceof ByteBuffer && format != Format.Byte && format != Format.UnsignedByte) {
373+ throw new AssertionError();
374+ }
375+ return true;
376+ }
377+
337378 /**
338379 * @return The offset after which the data is sent to the GPU.
339380 *
@@ -950,7 +991,14 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
950991 public void deleteObject(Object rendererObject) {
951992 ((Renderer)rendererObject).deleteBuffer(this);
952993 }
953-
994+
995+ @Override
996+ protected void deleteNativeBuffers() {
997+ if (data != null) {
998+ BufferUtils.destroyDirectBuffer(data);
999+ }
1000+ }
1001+
9541002 @Override
9551003 public NativeObject createDestructableClone(){
9561004 return new VertexBuffer(id);
--- a/engine/src/core/com/jme3/shader/Shader.java
+++ b/engine/src/core/com/jme3/shader/Shader.java
@@ -41,14 +41,6 @@ import java.util.ArrayList;
4141 import java.util.Collection;
4242
4343 public final class Shader extends NativeObject {
44-
45- /**
46- *
47- * @deprecated shader language now specified per shader source. See
48- * {@link ShaderSource#setLanguage(String)
49- */
50- @Deprecated
51- private String language;
5244
5345 /**
5446 * A list of all shader sources currently attached.
@@ -98,7 +90,7 @@ public final class Shader extends NativeObject {
9890 String defines;
9991
10092 public ShaderSource(ShaderType type){
101- super(ShaderSource.class);
93+ super();
10294 this.sourceType = type;
10395 if (type == null) {
10496 throw new IllegalArgumentException("The shader type must be specified");
@@ -106,13 +98,13 @@ public final class Shader extends NativeObject {
10698 }
10799
108100 protected ShaderSource(ShaderSource ss){
109- super(ShaderSource.class, ss.id);
101+ super(ss.id);
110102 // No data needs to be copied.
111103 // (This is a destructable clone)
112104 }
113105
114106 public ShaderSource(){
115- super(ShaderSource.class);
107+ super();
116108 }
117109
118110 public void setName(String name){
@@ -191,17 +183,6 @@ public final class Shader extends NativeObject {
191183 }
192184
193185 /**
194- * @deprecated Shader sources are now associated with the shader
195- * language.
196- */
197- @Deprecated
198- public Shader(String language){
199- super(Shader.class);
200- this.language = language;
201- initialize();
202- }
203-
204- /**
205186 * Initializes the shader for use, must be called after the
206187 * constructor without arguments is used.
207188 */
@@ -216,14 +197,14 @@ public final class Shader extends NativeObject {
216197 * after this constructor for the shader to be usable.
217198 */
218199 public Shader(){
219- super(Shader.class);
200+ super();
220201 }
221202
222203 /**
223204 * Do not use this constructor. Used for destructable clones only.
224205 */
225206 protected Shader(Shader s){
226- super(Shader.class, s.id);
207+ super(s.id);
227208
228209 // Shader sources cannot be shared, therefore they must
229210 // be destroyed together with the parent shader.
@@ -234,43 +215,6 @@ public final class Shader extends NativeObject {
234215 }
235216
236217 /**
237- * @deprecated Use the method that takes a language argument instead.
238- * {@link #addSource(com.jme3.shader.Shader.ShaderType, java.lang.String, java.lang.String, java.lang.String, java.lang.String) }
239- */
240- @Deprecated
241- public void addSource(ShaderType type, String name, String source, String defines) {
242- addSource(type, name, source, defines, this.language);
243- }
244-
245- /**
246- * @deprecated Use the method that takes a language argument instead.
247- * {@link #addSource(com.jme3.shader.Shader.ShaderType, java.lang.String, java.lang.String, java.lang.String, java.lang.String) }
248- */
249- @Deprecated
250- public void addSource(ShaderType type, String source, String defines){
251- addSource(type, null, source, defines);
252- }
253-
254- /**
255- * @deprecated Use the method that takes a language argument instead.
256- * {@link #addSource(com.jme3.shader.Shader.ShaderType, java.lang.String, java.lang.String, java.lang.String, java.lang.String) }
257- */
258- @Deprecated
259- public void addSource(ShaderType type, String source){
260- addSource(type, source, null);
261- }
262-
263- /**
264- * @deprecated Shader sources may not be shared.
265- * {@link #addSource(com.jme3.shader.Shader.ShaderType, java.lang.String, java.lang.String, java.lang.String, java.lang.String) }
266- */
267- @Deprecated
268- private void addSource(ShaderSource source){
269- shaderSourceList.add(source);
270- setUpdateNeeded();
271- }
272-
273- /**
274218 * Adds source code to a certain pipeline.
275219 *
276220 * @param type The pipeline to control
@@ -324,15 +268,6 @@ public final class Shader extends NativeObject {
324268 return shaderSourceList;
325269 }
326270
327- /**
328- * @deprecated Shaders no longer have a language variable,
329- * use {@link ShaderSource#getLanguage() } instead.
330- */
331- @Deprecated
332- public String getLanguage(){
333- return language;
334- }
335-
336271 @Override
337272 public String toString() {
338273 return getClass().getSimpleName() +
@@ -342,33 +277,6 @@ public final class Shader extends NativeObject {
342277 }
343278
344279 /**
345- * @deprecated This method is not needed since deleting
346- * a shader causes the sources to delete as well, thus its not required
347- * for them to be GC'd to be removed from GL.
348- */
349- @Deprecated
350- public void resetSources(){
351- shaderSourceList.clear();
352- }
353-
354- /**
355- * @deprecated Unusable shaders cause the renderer to crash,
356- * therefore this field no longer serves any purpose.
357- */
358- @Deprecated
359- public boolean isUsable(){
360- return true;
361- }
362-
363- /**
364- * @deprecated Unusable shaders cause the renderer to crash,
365- * therefore this field no longer serves any purpose.
366- */
367- @Deprecated
368- public void setUsable(boolean usable){
369- }
370-
371- /**
372280 * Usually called when the shader itself changes or during any
373281 * time when the variable locations need to be refreshed.
374282 */
--- a/engine/src/core/com/jme3/texture/FrameBuffer.java
+++ b/engine/src/core/com/jme3/texture/FrameBuffer.java
@@ -175,7 +175,7 @@ public class FrameBuffer extends NativeObject {
175175 * @throws IllegalArgumentException If width or height are not positive.
176176 */
177177 public FrameBuffer(int width, int height, int samples){
178- super(FrameBuffer.class);
178+ super();
179179 if (width <= 0 || height <= 0)
180180 throw new IllegalArgumentException("FrameBuffer must have valid size.");
181181
@@ -185,7 +185,7 @@ public class FrameBuffer extends NativeObject {
185185 }
186186
187187 protected FrameBuffer(FrameBuffer src){
188- super(FrameBuffer.class, src.id);
188+ super(src.id);
189189 /*
190190 for (RenderBuffer renderBuf : src.colorBufs){
191191 RenderBuffer clone = renderBuf.createDestructableClone();
--- a/engine/src/core/com/jme3/texture/Image.java
+++ b/engine/src/core/com/jme3/texture/Image.java
@@ -34,6 +34,7 @@ package com.jme3.texture;
3434 import com.jme3.export.*;
3535 import com.jme3.renderer.Caps;
3636 import com.jme3.renderer.Renderer;
37+import com.jme3.util.BufferUtils;
3738 import com.jme3.util.NativeObject;
3839 import java.io.IOException;
3940 import java.nio.ByteBuffer;
@@ -376,6 +377,13 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
376377 }
377378
378379 @Override
380+ protected void deleteNativeBuffers() {
381+ for (ByteBuffer buf : data) {
382+ BufferUtils.destroyDirectBuffer(buf);
383+ }
384+ }
385+
386+ @Override
379387 public void deleteObject(Object rendererObject) {
380388 ((Renderer)rendererObject).deleteImage(this);
381389 }
@@ -402,12 +410,12 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
402410 * are undefined.
403411 */
404412 public Image() {
405- super(Image.class);
413+ super();
406414 data = new ArrayList<ByteBuffer>(1);
407415 }
408416
409417 protected Image(int id){
410- super(Image.class, id);
418+ super(id);
411419 }
412420
413421 /**
--- a/engine/src/core/com/jme3/util/NativeObject.java
+++ b/engine/src/core/com/jme3/util/NativeObject.java
@@ -31,6 +31,8 @@
3131 */
3232 package com.jme3.util;
3333
34+import java.nio.Buffer;
35+
3436 /**
3537 * Describes a native object. An encapsulation of a certain object
3638 * on the native side of the graphics or audio library.
@@ -41,11 +43,13 @@ package com.jme3.util;
4143 */
4244 public abstract class NativeObject implements Cloneable {
4345
46+ public static final int INVALID_ID = -1;
47+
4448 /**
4549 * The ID of the object, usually depends on its type.
4650 * Typically returned from calls like glGenTextures, glGenBuffers, etc.
4751 */
48- protected int id = -1;
52+ protected int id = INVALID_ID;
4953
5054 /**
5155 * A reference to a "handle". By hard referencing a certain object, it's
@@ -61,18 +65,12 @@ public abstract class NativeObject implements Cloneable {
6165 protected boolean updateNeeded = true;
6266
6367 /**
64- * The type of the GLObject, usually specified by a subclass.
65- */
66- protected final Class<?> type;
67-
68- /**
6968 * Creates a new GLObject with the given type. Should be
7069 * called by the subclasses.
7170 *
7271 * @param type The type that the subclass represents.
7372 */
74- public NativeObject(Class<?> type){
75- this.type = type;
73+ public NativeObject(){
7674 this.handleRef = new Object();
7775 }
7876
@@ -80,8 +78,7 @@ public abstract class NativeObject implements Cloneable {
8078 * Protected constructor that doesn't allocate handle ref.
8179 * This is used in subclasses for the createDestructableClone().
8280 */
83- protected NativeObject(Class<?> type, int id){
84- this.type = type;
81+ protected NativeObject(int id){
8582 this.id = id;
8683 }
8784
@@ -91,9 +88,9 @@ public abstract class NativeObject implements Cloneable {
9188 * @param id The ID to set
9289 */
9390 public void setId(int id){
94- if (this.id != -1)
91+ if (this.id != INVALID_ID) {
9592 throw new IllegalStateException("ID has already been set for this GL object.");
96-
93+ }
9794 this.id = id;
9895 }
9996
@@ -129,7 +126,7 @@ public abstract class NativeObject implements Cloneable {
129126
130127 @Override
131128 public String toString(){
132- return "Native" + type.getSimpleName() + " " + id;
129+ return "Native" + getClass().getSimpleName() + " " + id;
133130 }
134131
135132 /**
@@ -137,19 +134,41 @@ public abstract class NativeObject implements Cloneable {
137134 * createDestructableClone().
138135 */
139136 @Override
140- protected NativeObject clone(){
141- try{
137+ protected NativeObject clone() {
138+ try {
142139 NativeObject obj = (NativeObject) super.clone();
143140 obj.handleRef = new Object();
144- obj.id = -1;
141+ obj.id = INVALID_ID;
145142 obj.updateNeeded = true;
146143 return obj;
147- }catch (CloneNotSupportedException ex){
144+ } catch (CloneNotSupportedException ex) {
148145 throw new AssertionError();
149146 }
150147 }
151148
152149 /**
150+ * Deletes any associated native {@link Buffer buffers}.
151+ * This is necessary because it is unlikely that native buffers
152+ * will be garbage collected naturally (due to how GC works), therefore
153+ * the collection must be handled manually.
154+ *
155+ * Only implementations that manage native buffers need to override
156+ * this method. Note that the behavior that occurs when a
157+ * deleted native buffer is used is not defined, therefore this
158+ * method is protected
159+ */
160+ protected void deleteNativeBuffers() {
161+ }
162+
163+ /**
164+ * Package-private version of {@link #deleteNativeBuffers() }, to be used
165+ * from the {@link NativeObjectManager}.
166+ */
167+ void deleteNativeBuffersInternal() {
168+ deleteNativeBuffers();
169+ }
170+
171+ /**
153172 * Called when the GL context is restarted to reset all IDs. Prevents
154173 * "white textures" on display restart.
155174 */
@@ -162,7 +181,7 @@ public abstract class NativeObject implements Cloneable {
162181 * @param rendererObject The renderer to be used to delete the object
163182 */
164183 public abstract void deleteObject(Object rendererObject);
165-
184+
166185 /**
167186 * Creates a shallow clone of this GL Object. The deleteObject method
168187 * should be functional for this object.
--- a/engine/src/tools/jme3tools/shadercheck/CgcValidator.java
+++ b/engine/src/tools/jme3tools/shadercheck/CgcValidator.java
@@ -95,15 +95,14 @@ public class CgcValidator implements Validator {
9595 }
9696
9797 public void validate(Shader shader, StringBuilder results) {
98- String language = shader.getLanguage();
9998 for (ShaderSource source : shader.getSources()){
10099 results.append("Checking: ").append(source.getName());
101100 switch (source.getType()){
102101 case Fragment:
103- executeCg(source.getSource(), language, source.getDefines(), "arbfp1", results);
102+ executeCg(source.getSource(), source.getLanguage(), source.getDefines(), "arbfp1", results);
104103 break;
105104 case Vertex:
106- executeCg(source.getSource(), language, source.getDefines(), "arbvp1", results);
105+ executeCg(source.getSource(), source.getLanguage(), source.getDefines(), "arbvp1", results);
107106 break;
108107 }
109108 }
--- a/engine/src/tools/jme3tools/shadercheck/GpuAnalyzerValidator.java
+++ b/engine/src/tools/jme3tools/shadercheck/GpuAnalyzerValidator.java
@@ -105,15 +105,14 @@ public class GpuAnalyzerValidator implements Validator {
105105 }
106106
107107 public void validate(Shader shader, StringBuilder results) {
108- String language = shader.getLanguage();
109108 for (ShaderSource source : shader.getSources()){
110109 results.append("Checking: ").append(source.getName());
111110 switch (source.getType()){
112111 case Fragment:
113- executeAnalyzer(source.getSource(), language, source.getDefines(), "HD5770", results);
112+ executeAnalyzer(source.getSource(), source.getLanguage(), source.getDefines(), "HD5770", results);
114113 break;
115114 case Vertex:
116- executeAnalyzer(source.getSource(), language, source.getDefines(), "HD5770", results);
115+ executeAnalyzer(source.getSource(), source.getLanguage(), source.getDefines(), "HD5770", results);
117116 break;
118117 }
119118 }