Skip to content

Commit fe84d1e

Browse files
committed
added methods to Material interface for compatibility with old GlMaterial usage
1 parent 93067db commit fe84d1e

16 files changed

Lines changed: 943 additions & 130 deletions

File tree

jme3-core/src/main/java/com/jme3/material/GlMaterial.java

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@
5656
import com.jme3.scene.Geometry;
5757
import com.jme3.shader.*;
5858
import com.jme3.shader.bufferobject.BufferObject;
59-
import com.jme3.texture.GlImage;
60-
import com.jme3.texture.GlTexture;
61-
import com.jme3.texture.TextureImage;
59+
import com.jme3.texture.*;
6260
import com.jme3.texture.image.ColorSpace;
6361
import com.jme3.util.ListMap;
6462
import com.jme3.util.SafeArrayList;
63+
import com.jme3.vulkan.buffers.GpuBuffer;
6564
import com.jme3.vulkan.commands.CommandBuffer;
65+
import com.jme3.vulkan.frames.VersionedResource;
6666
import com.jme3.vulkan.pipelines.Pipeline;
6767
import org.lwjgl.opengl.GL45;
6868

@@ -104,23 +104,9 @@ public class GlMaterial implements Material, CloneableSmartAsset, Cloneable, Sav
104104
private boolean receivesShadows = false;
105105
private int sortingId = -1;
106106

107-
@Override
108-
public void bind(CommandBuffer cmd, Pipeline pipeline, int offset) {
109-
// todo: implement properly
110-
int loc = GL45.glGetUniformLocation(pipeline.getNativeObject().intValue(), "MyUniformName");
111-
GL45.glUniform1f(loc, 123.4f);
112-
}
113-
114107
@Override
115108
public void setParam(String uniform, String param, Object value) {
116-
// todo: implement
117-
throw new UnsupportedOperationException("Not implemented yet.");
118-
}
119-
120-
@Override
121-
public <T extends com.jme3.vulkan.material.uniforms.Uniform> T getUniform(String name) {
122-
// todo: implement
123-
throw new UnsupportedOperationException("Not implemented yet.");
109+
setParam(param, value);
124110
}
125111

126112
/**
@@ -578,6 +564,7 @@ public void setParam(String name, VarType type, Object value) {
578564
* @param name the name of the parameter defined in the material definition (j3md)
579565
* @param value the value of the parameter
580566
*/
567+
@Override
581568
public void setParam(String name, Object value) {
582569
MatParam p = getMaterialDef().getMaterialParam(name);
583570
setParam(name, p.getVarType(), value);
@@ -669,15 +656,20 @@ private void checkTextureParamColorSpace(String name, GlTexture value) {
669656
* (.j3md) (e.g. Texture for Lighting.j3md)
670657
* @param value the Texture object previously loaded by the asset manager
671658
*/
672-
public void setTexture(String name, GlTexture value) {
659+
@Override
660+
public void setTexture(String name, VersionedResource<? extends Texture> value) {
673661
if (value == null) {
674662
// clear it
675663
clearParam(name);
676664
return;
677665
}
666+
if (!(value.get() instanceof GlTexture)) {
667+
throw new IllegalArgumentException("Must be a GlTexture.");
668+
}
678669

679670
VarType paramType = null;
680-
switch (value.getType()) {
671+
GlTexture.Type type = ((GlTexture)value.get()).getType();
672+
switch (type) {
681673
case TwoDimensional:
682674
paramType = VarType.Texture2D;
683675
break;
@@ -691,10 +683,10 @@ public void setTexture(String name, GlTexture value) {
691683
paramType = VarType.TextureCubeMap;
692684
break;
693685
default:
694-
throw new UnsupportedOperationException("Unknown texture type: " + value.getType());
686+
throw new UnsupportedOperationException("Unknown texture type: " + type);
695687
}
696688

697-
setTextureParam(name, paramType, value);
689+
setTextureParam(name, paramType, (GlTexture)value);
698690
}
699691

700692
/**
@@ -703,6 +695,7 @@ public void setTexture(String name, GlTexture value) {
703695
* @param name the name of the matrix defined in the material definition (j3md)
704696
* @param value the Matrix4f object
705697
*/
698+
@Override
706699
public void setMatrix4(String name, Matrix4f value) {
707700
setParam(name, VarType.Matrix4, value);
708701
}
@@ -713,6 +706,7 @@ public void setMatrix4(String name, Matrix4f value) {
713706
* @param name the name of the boolean defined in the material definition (j3md)
714707
* @param value the boolean value
715708
*/
709+
@Override
716710
public void setBoolean(String name, boolean value) {
717711
setParam(name, VarType.Boolean, value);
718712
}
@@ -723,6 +717,7 @@ public void setBoolean(String name, boolean value) {
723717
* @param name the name of the float defined in the material definition (j3md)
724718
* @param value the float value
725719
*/
720+
@Override
726721
public void setFloat(String name, float value) {
727722
setParam(name, VarType.Float, value);
728723
}
@@ -734,6 +729,7 @@ public void setFloat(String name, float value) {
734729
* @param name the name of the float defined in the material definition (j3md)
735730
* @param value the float value
736731
*/
732+
@Override
737733
public void setFloat(String name, Float value) {
738734
setParam(name, VarType.Float, value);
739735
}
@@ -744,6 +740,7 @@ public void setFloat(String name, Float value) {
744740
* @param name the name of the int defined in the material definition (j3md)
745741
* @param value the int value
746742
*/
743+
@Override
747744
public void setInt(String name, int value) {
748745
setParam(name, VarType.Int, value);
749746
}
@@ -754,6 +751,7 @@ public void setInt(String name, int value) {
754751
* @param name the name of the color defined in the material definition (j3md)
755752
* @param value the ColorRGBA value
756753
*/
754+
@Override
757755
public void setColor(String name, ColorRGBA value) {
758756
setParam(name, VarType.Vector4, value);
759757
}
@@ -778,12 +776,18 @@ public void setShaderStorageBufferObject(final String name, final BufferObject v
778776
setParam(name, VarType.ShaderStorageBufferObject, value);
779777
}
780778

779+
@Override
780+
public void setUniform(String name, VersionedResource<? extends GpuBuffer> buffer) {
781+
782+
}
783+
781784
/**
782785
* Pass a Vector2f to the material shader.
783786
*
784787
* @param name the name of the Vector2f defined in the material definition (j3md)
785788
* @param value the Vector2f value
786789
*/
790+
@Override
787791
public void setVector2(String name, Vector2f value) {
788792
setParam(name, VarType.Vector2, value);
789793
}
@@ -794,6 +798,7 @@ public void setVector2(String name, Vector2f value) {
794798
* @param name the name of the Vector3f defined in the material definition (j3md)
795799
* @param value the Vector3f value
796800
*/
801+
@Override
797802
public void setVector3(String name, Vector3f value) {
798803
setParam(name, VarType.Vector3, value);
799804
}
@@ -804,6 +809,7 @@ public void setVector3(String name, Vector3f value) {
804809
* @param name the name of the Vector4f defined in the material definition (j3md)
805810
* @param value the Vector4f value
806811
*/
812+
@Override
807813
public void setVector4(String name, Vector4f value) {
808814
setParam(name, VarType.Vector4, value);
809815
}
@@ -1106,6 +1112,7 @@ private void resetUniformsNotSetByCurrent(Shader shader) {
11061112
* @param lights Presorted and filtered light list to use for rendering
11071113
* @param renderManager The render manager requesting the rendering
11081114
*/
1115+
@Override
11091116
public void render(Geometry geometry, LightList lights, RenderManager renderManager) {
11101117
if (technique == null) {
11111118
selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);

jme3-core/src/main/java/com/jme3/material/Material.java

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
package com.jme3.material;
3333

3434
import com.jme3.export.Savable;
35+
import com.jme3.light.LightList;
36+
import com.jme3.math.*;
37+
import com.jme3.renderer.RenderManager;
3538
import com.jme3.scene.Geometry;
3639
import com.jme3.texture.Texture;
37-
import com.jme3.vulkan.commands.CommandBuffer;
38-
import com.jme3.vulkan.frames.SingleResource;
39-
import com.jme3.vulkan.material.uniforms.TextureUniform;
40-
import com.jme3.vulkan.material.uniforms.Uniform;
41-
import com.jme3.vulkan.pipelines.Pipeline;
40+
import com.jme3.vulkan.buffers.GpuBuffer;
41+
import com.jme3.vulkan.frames.VersionedResource;
4242

4343
/**
4444
* <code>Material</code> describes the rendering style for a given
@@ -53,19 +53,56 @@
5353
*/
5454
public interface Material extends Savable {
5555

56-
void bind(CommandBuffer cmd, Pipeline pipeline, int offset);
56+
String DEFAULT_UNIFORM_BUFFER = "DefaultUniformBuffer";
57+
58+
void render(Geometry geometry, LightList lights, RenderManager renderManager);
59+
60+
void setUniform(String name, VersionedResource<? extends GpuBuffer> buffer);
61+
62+
void setTexture(String name, VersionedResource<? extends Texture> texture);
5763

5864
void setParam(String uniform, String param, Object value);
5965

60-
<T extends Uniform> T getUniform(String name);
66+
/* ----- COMPATABILITY WITH OLD MATERIAL ----- */
67+
68+
default void setParam(String param, Object value) {
69+
setParam(DEFAULT_UNIFORM_BUFFER, param, value);
70+
}
71+
72+
default void setBoolean(String param, boolean value) {
73+
setParam(param, value);
74+
}
75+
76+
default void setInt(String param, int value) {
77+
setParam(param, value);
78+
}
79+
80+
default void setFloat(String param, float value) {
81+
setParam(param, value);
82+
}
83+
84+
default void setFloat(String param, Float value) {
85+
setParam(param, value);
86+
}
87+
88+
default void setColor(String param, ColorRGBA value) {
89+
setParam(param, value);
90+
}
91+
92+
default void setVector2(String param, Vector2f value) {
93+
setParam(param, value);
94+
}
95+
96+
default void setVector3(String param, Vector3f value) {
97+
setParam(param, value);
98+
}
6199

62-
default void bind(CommandBuffer cmd, Pipeline pipeline) {
63-
bind(cmd, pipeline, 0);
100+
default void setVector4(String param, Vector4f value) {
101+
setParam(param, value);
64102
}
65103

66-
default void setTexture(String name, Texture texture) {
67-
TextureUniform u = getUniform(name);
68-
u.setResource(new SingleResource<>(texture));
104+
default void setMatrix4(String param, Matrix4f value) {
105+
setParam(param, value);
69106
}
70107

71108
}

jme3-core/src/main/java/com/jme3/texture/GlImage.java

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import com.jme3.texture.image.LastTextureState;
4444
import com.jme3.util.natives.GlNative;
4545
import com.jme3.vulkan.images.GpuImage;
46-
import com.jme3.vulkan.images.VulkanImage;
4746
import com.jme3.vulkan.util.IntEnum;
4847

4948
import java.io.IOException;
@@ -62,33 +61,11 @@
6261
* @author Joshua Slack
6362
* @version $Id: Image.java 4131 2009-03-19 20:15:28Z blaine.dev $
6463
*/
65-
public class GlImage extends GlNative<Integer> implements GpuImage, ImageView<GlImage>, Savable /*, Cloneable*/ {
64+
public class GlImage extends GlNative<Integer> implements GpuImage, Savable /*, Cloneable*/ {
6665

6766
@Override
68-
public GlImage getImage() {
69-
return this;
70-
}
71-
72-
@Override
73-
public int getBaseMipmap() {
74-
return 0;
75-
}
76-
77-
@Override
78-
public int getMipmapCount() {
79-
// todo: determine if this is correct
80-
return mipMapSizes.length;
81-
}
82-
83-
@Override
84-
public int getBaseLayer() {
85-
return 0;
86-
}
87-
88-
@Override
89-
public int getLayerCount() {
90-
// todo: determine if this is correct
91-
return 1;
67+
public IntEnum<Type> getType() {
68+
return Type.TwoDemensional;
9269
}
9370

9471
public enum Format {
@@ -1114,11 +1091,6 @@ public long getId() {
11141091
return object;
11151092
}
11161093

1117-
@Override
1118-
public IntEnum<Type> getType() {
1119-
return VulkanImage.Type.TwoDemensional;
1120-
}
1121-
11221094
/**
11231095
* <code>getWidth</code> returns the width of this image.
11241096
*

0 commit comments

Comments
 (0)