added new var types for shaders.

JavaSaBr-added_new_var_type
javasabr 7 years ago committed by Nehon
parent 302e746a94
commit 13112b4532
  1. 48
      jme3-core/src/main/java/com/jme3/renderer/opengl/GL3.java
  2. 10
      jme3-core/src/main/java/com/jme3/renderer/opengl/GL4.java
  3. 13
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLDebugDesktop.java
  4. 70
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java
  5. 4
      jme3-core/src/main/java/com/jme3/shader/VarType.java
  6. 15
      jme3-jogl/src/main/java/com/jme3/renderer/jogl/JoglGL.java
  7. 18
      jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglGL.java
  8. 10
      jme3-lwjgl3/src/main/java/com/jme3/renderer/lwjgl/LwjglGL.java

@ -83,6 +83,31 @@ public interface GL3 extends GL2 {
public static final int GL_RGB_INTEGER = 36248; public static final int GL_RGB_INTEGER = 36248;
public static final int GL_RGBA_INTEGER = 36249; public static final int GL_RGBA_INTEGER = 36249;
public static final int GL_UNIFORM_OFFSET = 0x8A3B;
/**
* Accepted by the {@code target} parameters of BindBuffer, BufferData, BufferSubData, MapBuffer, UnmapBuffer, GetBufferSubData, and GetBufferPointerv.
*/
public static final int GL_UNIFORM_BUFFER = 0x8A11;
/**
* Accepted by the {@code pname} parameter of GetActiveUniformBlockiv.
*/
public static final int GL_UNIFORM_BLOCK_BINDING = 0x8A3F;
public static final int GL_UNIFORM_BLOCK_DATA_SIZE = 0x8A40;
public static final int GL_UNIFORM_BLOCK_NAME_LENGTH = 0x8A41;
public static final int GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS = 0x8A42;
public static final int GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES = 0x8A43;
public static final int GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER = 0x8A44;
public static final int GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER = 0x8A45;
public static final int GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER = 0x8A46;
/**
* Accepted by the {@code target} parameters of BindBuffer, BufferData, BufferSubData, MapBuffer, UnmapBuffer, GetBufferSubData, GetBufferPointerv,
* BindBufferRange, BindBufferOffset and BindBufferBase.
*/
public static final int GL_TRANSFORM_FEEDBACK_BUFFER = 0x8C8E;
/** /**
* <p><a target="_blank" href="http://docs.gl/gl4/glBindFragDataLocation">Reference Page</a></p> * <p><a target="_blank" href="http://docs.gl/gl4/glBindFragDataLocation">Reference Page</a></p>
* <p> * <p>
@ -128,4 +153,27 @@ public interface GL3 extends GL2 {
* @param index the index of the particular element being queried. * @param index the index of the particular element being queried.
*/ */
public String glGetString(int name, int index); /// GL3+ public String glGetString(int name, int index); /// GL3+
/**
* <p><a target="_blank" href="http://docs.gl/gl4/glGetUniformBlockIndex">Reference Page</a></p>
*
* Retrieves the index of a named uniform block.
*
* @param program the name of a program containing the uniform block.
* @param uniformBlockName an array of characters to containing the name of the uniform block whose index to retrieve.
* @return the block index.
*/
public int glGetUniformBlockIndex(int program, String uniformBlockName);
/**
* <p><a target="_blank" href="http://docs.gl/gl4/glBindBufferBase">Reference Page</a></p>
*
* Binds a buffer object to an indexed buffer target.
*
* @param target the target of the bind operation. One of:<br><table><tr><td>{@link #GL_TRANSFORM_FEEDBACK_BUFFER TRANSFORM_FEEDBACK_BUFFER}</td><td>{@link #GL_UNIFORM_BUFFER UNIFORM_BUFFER}</td><td>{@link GL4#GL_ATOMIC_COUNTER_BUFFER ATOMIC_COUNTER_BUFFER}</td><td>{@link GL4#GL_SHADER_STORAGE_BUFFER SHADER_STORAGE_BUFFER}</td></tr></table>
* @param index the index of the binding point within the array specified by {@code target}
* @param buffer a buffer object to bind to the specified binding point
*/
public void glBindBufferBase(int target, int index, int buffer);
} }

@ -42,6 +42,16 @@ public interface GL4 extends GL3 {
public static final int GL_TESS_EVALUATION_SHADER = 0x8E87; public static final int GL_TESS_EVALUATION_SHADER = 0x8E87;
public static final int GL_PATCHES = 0xE; public static final int GL_PATCHES = 0xE;
/**
* Accepted by the {@code target} parameter of BindBufferBase and BindBufferRange.
*/
public static final int GL_ATOMIC_COUNTER_BUFFER = 0x92C0;
/**
* Accepted by the {@code target} parameters of BindBuffer, BufferData, BufferSubData, MapBuffer, UnmapBuffer, GetBufferSubData, and GetBufferPointerv.
*/
public static final int GL_SHADER_STORAGE_BUFFER = 0x90D2;
/** /**
* <p><a target="_blank" href="http://docs.gl/gl4/glPatchParameteri">Reference Page</a></p> * <p><a target="_blank" href="http://docs.gl/gl4/glPatchParameteri">Reference Page</a></p>
* <p> * <p>

@ -83,6 +83,19 @@ public class GLDebugDesktop extends GLDebugES implements GL2, GL3, GL4 {
return result; return result;
} }
@Override
public int glGetUniformBlockIndex(final int program, final String uniformBlockName) {
final int result = gl3.glGetUniformBlockIndex(program, uniformBlockName);
checkError();
return result;
}
@Override
public void glBindBufferBase(final int target, final int index, final int buffer) {
gl3.glBindBufferBase(target, index, buffer);
checkError();
}
@Override @Override
public void glDeleteVertexArrays(IntBuffer arrays) { public void glDeleteVertexArrays(IntBuffer arrays) {
gl3.glDeleteVertexArrays(arrays); gl3.glDeleteVertexArrays(arrays);

@ -61,17 +61,17 @@ import com.jme3.util.BufferUtils;
import com.jme3.util.ListMap; import com.jme3.util.ListMap;
import com.jme3.util.MipMapGenerator; import com.jme3.util.MipMapGenerator;
import com.jme3.util.NativeObjectManager; import com.jme3.util.NativeObjectManager;
import java.nio.*; import jme3tools.shader.ShaderDebug;
import java.util.Arrays;
import java.util.EnumMap; import java.nio.ByteBuffer;
import java.util.EnumSet; import java.nio.FloatBuffer;
import java.util.HashSet; import java.nio.IntBuffer;
import java.util.List; import java.nio.ShortBuffer;
import java.util.*;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import jme3tools.shader.ShaderDebug;
public final class GLRenderer implements Renderer { public final class GLRenderer implements Renderer {
@ -1056,6 +1056,18 @@ public final class GLRenderer implements Renderer {
gl.resetStats(); gl.resetStats();
} }
protected void bindProgram(Shader shader) {
int shaderId = shader.getId();
if (context.boundShaderProgram != shaderId) {
gl.glUseProgram(shaderId);
statistics.onShaderUse(shader, true);
context.boundShader = shader;
context.boundShaderProgram = shaderId;
} else {
statistics.onShaderUse(shader, false);
}
}
/*********************************************************************\ /*********************************************************************\
|* Shaders *| |* Shaders *|
\*********************************************************************/ \*********************************************************************/
@ -1070,18 +1082,6 @@ public final class GLRenderer implements Renderer {
} }
} }
protected void bindProgram(Shader shader) {
int shaderId = shader.getId();
if (context.boundShaderProgram != shaderId) {
gl.glUseProgram(shaderId);
statistics.onShaderUse(shader, true);
context.boundShader = shader;
context.boundShaderProgram = shaderId;
} else {
statistics.onShaderUse(shader, false);
}
}
protected void updateUniform(Shader shader, Uniform uniform) { protected void updateUniform(Shader shader, Uniform uniform) {
int shaderId = shader.getId(); int shaderId = shader.getId();
@ -1182,6 +1182,38 @@ public final class GLRenderer implements Renderer {
Integer i = (Integer) uniform.getValue(); Integer i = (Integer) uniform.getValue();
gl.glUniform1i(loc, i.intValue()); gl.glUniform1i(loc, i.intValue());
break; break;
case Struct: {
final ByteBuffer data = (ByteBuffer) uniform.getValue();
intBuf1.clear();
gl3.glGenBuffers(intBuf1);
final int bufferAddress = intBuf1.get();
final int blockIndex = gl3.glGetUniformBlockIndex(shaderId, uniform.getName());
gl3.glBindBuffer(GL3.GL_UNIFORM_BUFFER, bufferAddress);
gl3.glBufferData(GL3.GL_UNIFORM_BUFFER, data, GL.GL_DYNAMIC_DRAW);
gl3.glBindBufferBase(GL3.GL_UNIFORM_BUFFER, blockIndex, bufferAddress);
break;
}
case StructArray: {
//TODO
final ByteBuffer data = (ByteBuffer) uniform.getValue();
intBuf1.clear();
gl3.glGenBuffers(intBuf1);
final int bufferAddress = intBuf1.get();
final int blockIndex = gl3.glGetUniformBlockIndex(shaderId, uniform.getName());
gl3.glBindBuffer(GL3.GL_UNIFORM_BUFFER, bufferAddress);
gl3.glBufferData(GL3.GL_UNIFORM_BUFFER, data, GL.GL_DYNAMIC_DRAW);
gl3.glBindBufferBase(GL3.GL_UNIFORM_BUFFER, blockIndex, bufferAddress);
break;
}
default: default:
throw new UnsupportedOperationException("Unsupported uniform type: " + uniform.getVarType()); throw new UnsupportedOperationException("Unsupported uniform type: " + uniform.getVarType());
} }

@ -57,7 +57,9 @@ public enum VarType {
Texture3D(false,true,"sampler3D"), Texture3D(false,true,"sampler3D"),
TextureArray(false,true,"sampler2DArray|sampler2DArrayShadow"), TextureArray(false,true,"sampler2DArray|sampler2DArrayShadow"),
TextureCubeMap(false,true,"samplerCube"), TextureCubeMap(false,true,"samplerCube"),
Int("int"); Int("int"),
Struct(false, false, "dynamic"),
StructArray(false, false, "dynamic");
private boolean usesMultiData = false; private boolean usesMultiData = false;
private boolean textureType = false; private boolean textureType = false;

@ -4,12 +4,11 @@ import com.jme3.renderer.RendererException;
import com.jme3.renderer.opengl.GL; import com.jme3.renderer.opengl.GL;
import com.jme3.renderer.opengl.GL2; import com.jme3.renderer.opengl.GL2;
import com.jme3.renderer.opengl.GL3; import com.jme3.renderer.opengl.GL3;
import java.nio.*;
import com.jme3.renderer.opengl.GL4; import com.jme3.renderer.opengl.GL4;
import com.jogamp.opengl.GLContext; import com.jogamp.opengl.GLContext;
import java.nio.*;
public class JoglGL implements GL, GL2, GL3, GL4 { public class JoglGL implements GL, GL2, GL3, GL4 {
private static int getLimitBytes(ByteBuffer buffer) { private static int getLimitBytes(ByteBuffer buffer) {
@ -634,4 +633,14 @@ public class JoglGL implements GL, GL2, GL3, GL4 {
checkLimit(arrays); checkLimit(arrays);
GLContext.getCurrentGL().getGL2ES3().glDeleteVertexArrays(arrays.limit(), arrays); GLContext.getCurrentGL().getGL2ES3().glDeleteVertexArrays(arrays.limit(), arrays);
} }
@Override
public int glGetUniformBlockIndex(final int program, final String uniformBlockName) {
return GLContext.getCurrentGL().getGL3bc().glGetUniformBlockIndex(program, uniformBlockName);
}
@Override
public void glBindBufferBase(final int target, final int index, final int buffer) {
GLContext.getCurrentGL().getGL3bc().glBindBufferBase(target, index, buffer);
}
} }

@ -4,16 +4,12 @@ import com.jme3.renderer.RendererException;
import com.jme3.renderer.opengl.GL; import com.jme3.renderer.opengl.GL;
import com.jme3.renderer.opengl.GL2; import com.jme3.renderer.opengl.GL2;
import com.jme3.renderer.opengl.GL3; import com.jme3.renderer.opengl.GL3;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
import com.jme3.renderer.opengl.GL4; import com.jme3.renderer.opengl.GL4;
import com.jme3.util.BufferUtils; import com.jme3.util.BufferUtils;
import org.lwjgl.opengl.*; import org.lwjgl.opengl.*;
import java.nio.*;
public final class LwjglGL implements GL, GL2, GL3, GL4 { public final class LwjglGL implements GL, GL2, GL3, GL4 {
IntBuffer tmpBuff = BufferUtils.createIntBuffer(1); IntBuffer tmpBuff = BufferUtils.createIntBuffer(1);
@ -493,4 +489,14 @@ public final class LwjglGL implements GL, GL2, GL3, GL4 {
checkLimit(arrays); checkLimit(arrays);
ARBVertexArrayObject.glDeleteVertexArrays(arrays); ARBVertexArrayObject.glDeleteVertexArrays(arrays);
} }
@Override
public int glGetUniformBlockIndex(final int program, final String uniformBlockName) {
return GL31.glGetUniformBlockIndex(program, uniformBlockName);
}
@Override
public void glBindBufferBase(final int target, final int index, final int buffer) {
GL30.glBindBufferBase(target, index, buffer);
}
} }

@ -621,4 +621,14 @@ public class LwjglGL extends LwjglRender implements GL, GL2, GL3, GL4 {
checkLimit(arrays); checkLimit(arrays);
ARBVertexArrayObject.glDeleteVertexArrays(arrays); ARBVertexArrayObject.glDeleteVertexArrays(arrays);
} }
@Override
public int glGetUniformBlockIndex(final int program, final String uniformBlockName) {
return GL31.glGetUniformBlockIndex(program, uniformBlockName);
}
@Override
public void glBindBufferBase(final int target, final int index, final int buffer) {
GL30.glBindBufferBase(target, index, buffer);
}
} }

Loading…
Cancel
Save