added new var types for shaders.
This commit is contained in:
parent
302e746a94
commit
13112b4532
@ -83,6 +83,31 @@ public interface GL3 extends GL2 {
|
||||
public static final int GL_RGB_INTEGER = 36248;
|
||||
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>
|
||||
@ -128,4 +153,27 @@ public interface GL3 extends GL2 {
|
||||
* @param index the index of the particular element being queried.
|
||||
*/
|
||||
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_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>
|
||||
|
@ -83,6 +83,19 @@ public class GLDebugDesktop extends GLDebugES implements GL2, GL3, GL4 {
|
||||
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
|
||||
public void glDeleteVertexArrays(IntBuffer arrays) {
|
||||
gl3.glDeleteVertexArrays(arrays);
|
||||
|
@ -61,17 +61,17 @@ import com.jme3.util.BufferUtils;
|
||||
import com.jme3.util.ListMap;
|
||||
import com.jme3.util.MipMapGenerator;
|
||||
import com.jme3.util.NativeObjectManager;
|
||||
import java.nio.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumMap;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import jme3tools.shader.ShaderDebug;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ShortBuffer;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import jme3tools.shader.ShaderDebug;
|
||||
|
||||
public final class GLRenderer implements Renderer {
|
||||
|
||||
@ -1056,6 +1056,18 @@ public final class GLRenderer implements Renderer {
|
||||
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 *|
|
||||
\*********************************************************************/
|
||||
@ -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) {
|
||||
int shaderId = shader.getId();
|
||||
|
||||
@ -1182,6 +1182,38 @@ public final class GLRenderer implements Renderer {
|
||||
Integer i = (Integer) uniform.getValue();
|
||||
gl.glUniform1i(loc, i.intValue());
|
||||
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:
|
||||
throw new UnsupportedOperationException("Unsupported uniform type: " + uniform.getVarType());
|
||||
}
|
||||
|
@ -57,7 +57,9 @@ public enum VarType {
|
||||
Texture3D(false,true,"sampler3D"),
|
||||
TextureArray(false,true,"sampler2DArray|sampler2DArrayShadow"),
|
||||
TextureCubeMap(false,true,"samplerCube"),
|
||||
Int("int");
|
||||
Int("int"),
|
||||
Struct(false, false, "dynamic"),
|
||||
StructArray(false, false, "dynamic");
|
||||
|
||||
private boolean usesMultiData = 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.GL2;
|
||||
import com.jme3.renderer.opengl.GL3;
|
||||
|
||||
import java.nio.*;
|
||||
|
||||
import com.jme3.renderer.opengl.GL4;
|
||||
import com.jogamp.opengl.GLContext;
|
||||
|
||||
import java.nio.*;
|
||||
|
||||
public class JoglGL implements GL, GL2, GL3, GL4 {
|
||||
|
||||
private static int getLimitBytes(ByteBuffer buffer) {
|
||||
@ -634,4 +633,14 @@ public class JoglGL implements GL, GL2, GL3, GL4 {
|
||||
checkLimit(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.GL2;
|
||||
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.util.BufferUtils;
|
||||
import org.lwjgl.opengl.*;
|
||||
|
||||
import java.nio.*;
|
||||
|
||||
public final class LwjglGL implements GL, GL2, GL3, GL4 {
|
||||
|
||||
IntBuffer tmpBuff = BufferUtils.createIntBuffer(1);
|
||||
@ -493,4 +489,14 @@ public final class LwjglGL implements GL, GL2, GL3, GL4 {
|
||||
checkLimit(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);
|
||||
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…
x
Reference in New Issue
Block a user