Skip to content

Commit 79c93e0

Browse files
committed
added test app
1 parent 8194222 commit 79c93e0

File tree

5 files changed

+109
-10
lines changed

5 files changed

+109
-10
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3+
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
4+
*/
5+
package jme3test.texture;
6+
7+
import com.jme3.app.SimpleApplication;
8+
import com.jme3.material.Material;
9+
import com.jme3.math.Vector3f;
10+
import com.jme3.scene.Geometry;
11+
import com.jme3.scene.shape.Box;
12+
import com.jme3.scene.shape.Quad;
13+
import com.jme3.shader.VarType;
14+
import com.jme3.texture.Image;
15+
import com.jme3.texture.Texture2D;
16+
import com.jme3.texture.TextureImage;
17+
18+
/**
19+
*
20+
* @author codex
21+
*/
22+
public class TestShaderImage extends SimpleApplication {
23+
24+
private int frame = 0;
25+
26+
public static void main(String[] args) {
27+
new TestShaderImage().start();
28+
}
29+
30+
@Override
31+
public void simpleInitApp() {
32+
33+
Geometry box = new Geometry("Box", new Box(1, 1, 1));
34+
Material mat = new Material(assetManager, "Materials/ImageTest.j3md");
35+
box.setMaterial(mat);
36+
rootNode.attachChild(box);
37+
38+
int width = context.getFramebufferWidth();
39+
int height = context.getFramebufferHeight();
40+
Texture2D target = new Texture2D(width, height, Image.Format.RGBA8);
41+
TextureImage targetImage = new TextureImage(target, TextureImage.Access.WriteOnly);
42+
mat.setParam("TargetImage", VarType.Image2D, targetImage);
43+
44+
Geometry pic = new Geometry("gui_pic", new Quad(200, 200));
45+
pic.setLocalTranslation(0, height - 200, 0);
46+
Material picMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
47+
picMat.setTexture("ColorMap", target);
48+
pic.setMaterial(mat);
49+
guiNode.attachChild(pic);
50+
51+
}
52+
@Override
53+
public void simpleUpdate(float tpf) {
54+
if (frame++ < 5) {
55+
cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);
56+
}
57+
}
58+
59+
}

jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglGL.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ public void glBindTexture(int param1, int param2) {
6060
GL11.glBindTexture(param1, param2);
6161
}
6262

63-
@Override
64-
public void glBindImageTexture(final int unit, final int texture, final int level,
65-
final boolean layered, final int layer,
66-
final int access, final int format) {
67-
GL42.glBindImageTexture(unit, texture, level, layered, layer, access, format);
68-
}
63+
// @Override
64+
// public void glBindImageTexture(final int unit, final int texture, final int level,
65+
// final boolean layered, final int layer,
66+
// final int access, final int format) {
67+
// throw new NullPointerException("lwjgl");
68+
// //GL42.glBindImageTexture(unit, texture, level, layered, layer, access, format);
69+
// }
6970

7071
@Override
7172
public void glBlendEquationSeparate(int colorMode, int alphaMode){

jme3-lwjgl3/src/main/java/com/jme3/renderer/lwjgl/LwjglGL.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,20 @@ public void glBindTexture(final int target, final int texture) {
8181
GL11.glBindTexture(target, texture);
8282
}
8383

84+
// @Override
85+
// public void glBindImageTexture(final int unit, final int texture, final int level,
86+
// final boolean layered, final int layer,
87+
// final int access, final int format) {
88+
// throw new NullPointerException("lwjgl3");
89+
// //GL42.glBindImageTexture(unit, texture, level, layered, layer, access, format);
90+
// }
91+
92+
8493
@Override
85-
public void glBindImageTexture(final int unit, final int texture, final int level,
86-
final boolean layered, final int layer,
87-
final int access, final int format) {
94+
public void glBindImageTexture(int unit, int texture, int level, boolean layered, int layer, int access, int format) {
8895
GL42.glBindImageTexture(unit, texture, level, layered, layer, access, format);
8996
}
90-
97+
9198
@Override
9299
public void glBlendEquationSeparate(final int colorMode, final int alphaMode) {
93100
GL20.glBlendEquationSeparate(colorMode, alphaMode);
@@ -660,4 +667,5 @@ public void glBindBufferBase(final int target, final int index, final int buffer
660667
public void glUniformBlockBinding(final int program, final int uniformBlockIndex, final int uniformBlockBinding) {
661668
GL31.glUniformBlockBinding(program, uniformBlockIndex, uniformBlockBinding);
662669
}
670+
663671
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
#import "Common/ShaderLib/GLSLCompat.glsllib"
3+
4+
layout(RGBA8) uniform image2D m_TargetImage;
5+
6+
void main() {
7+
8+
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
9+
imageStore(m_TargetImage, ivec2(gl_FragCoord.xy), vec4(0.0, 1.0, 0.0, 1.0));
10+
11+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
MaterialDef ImageTest {
2+
3+
MaterialParameters {
4+
5+
Image2D TargetImage
6+
7+
}
8+
9+
Technique {
10+
11+
VertexShader GLSL400 GLSL320 GLSL150 : Common/MatDefs/Misc/Unshaded.vert
12+
FragmentShader GLSL400 GLSL320 GLSL150 : Materials/ImageTest.frag
13+
14+
WorldParameters {
15+
WorldViewProjectionMatrix
16+
}
17+
18+
}
19+
20+
}

0 commit comments

Comments
 (0)