diff --git a/jme3-core/src/main/java/com/jme3/renderer/Renderer.java b/jme3-core/src/main/java/com/jme3/renderer/Renderer.java index 9f562ea61..5e70a1df4 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/Renderer.java +++ b/jme3-core/src/main/java/com/jme3/renderer/Renderer.java @@ -37,6 +37,7 @@ import com.jme3.scene.Mesh; import com.jme3.scene.VertexBuffer; import com.jme3.shader.Shader; import com.jme3.shader.Shader.ShaderSource; +import com.jme3.shader.ShaderStorageBufferObject; import com.jme3.system.AppSettings; import com.jme3.texture.FrameBuffer; import com.jme3.texture.Image; @@ -267,12 +268,26 @@ public interface Renderer { */ public void updateBufferData(VertexBuffer vb); + /** + * Uploads a shader storage buffer object to the GPU. + * + * @param ssbo the shader storage buffer object to upload. + */ + public void updateBufferData(ShaderStorageBufferObject ssbo); + /** * Deletes a vertex buffer from the GPU. * @param vb The vertex buffer to delete */ public void deleteBuffer(VertexBuffer vb); + /** + * Deletes a shader storage buffer object from the GPU. + * + * @param ssbo the shader storage buffer object to delete. + */ + public void deleteBuffer(ShaderStorageBufferObject ssbo); + /** * Renders count meshes, with the geometry data supplied and * per-instance data supplied. diff --git a/jme3-core/src/main/java/com/jme3/renderer/opengl/GL.java b/jme3-core/src/main/java/com/jme3/renderer/opengl/GL.java index e0a1975c1..1f80ad709 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/opengl/GL.java +++ b/jme3-core/src/main/java/com/jme3/renderer/opengl/GL.java @@ -45,156 +45,156 @@ import java.nio.ShortBuffer; */ public interface GL { - static final int GL_ALPHA = 0x1906; - static final int GL_ALWAYS = 0x207; - static final int GL_ARRAY_BUFFER = 0x8892; - static final int GL_BACK = 0x405; - static final int GL_BLEND = 0xBE2; - static final int GL_BLUE = 0x1905; - static final int GL_BYTE = 0x1400; - static final int GL_CLAMP_TO_EDGE = 0x812F; - static final int GL_COLOR_BUFFER_BIT = 0x4000; - static final int GL_COMPILE_STATUS = 0x8B81; - static final int GL_CULL_FACE = 0xB44; - static final int GL_DECR = 0x1E03; - static final int GL_DECR_WRAP = 0x8508; - static final int GL_DEPTH_BUFFER_BIT = 0x100; - static final int GL_DEPTH_COMPONENT = 0x1902; - static final int GL_DEPTH_COMPONENT16 = 0x81A5; - static final int GL_DEPTH_TEST = 0xB71; - static final int GL_DOUBLE = 0x140A; - static final int GL_DST_ALPHA = 0x0304; - static final int GL_DST_COLOR = 0x306; - static final int GL_DYNAMIC_DRAW = 0x88E8; - static final int GL_ELEMENT_ARRAY_BUFFER = 0x8893; - static final int GL_EQUAL = 0x202; - static final int GL_EXTENSIONS = 0x1F03; - static final int GL_FALSE = 0x0; - static final int GL_FLOAT = 0x1406; - static final int GL_FRAGMENT_SHADER = 0x8B30; - static final int GL_FRONT = 0x404; - static final int GL_FUNC_ADD = 0x8006; - static final int GL_FUNC_SUBTRACT = 0x800A; - static final int GL_FUNC_REVERSE_SUBTRACT = 0x800B; - static final int GL_FRONT_AND_BACK = 0x408; - static final int GL_GEQUAL = 0x206; - static final int GL_GREATER = 0x204; - static final int GL_GREEN = 0x1904; - static final int GL_INCR = 0x1E02; - static final int GL_INCR_WRAP = 0x8507; - static final int GL_INFO_LOG_LENGTH = 0x8B84; - static final int GL_INT = 0x1404; - static final int GL_INVALID_ENUM = 0x500; - static final int GL_INVALID_VALUE = 0x501; - static final int GL_INVALID_OPERATION = 0x502; - static final int GL_INVERT = 0x150A; - static final int GL_KEEP = 0x1E00; - static final int GL_LEQUAL = 0x203; - static final int GL_LESS = 0x201; - static final int GL_LINEAR = 0x2601; - static final int GL_LINEAR_MIPMAP_LINEAR = 0x2703; - static final int GL_LINEAR_MIPMAP_NEAREST = 0x2701; - static final int GL_LINES = 0x1; - static final int GL_LINE_LOOP = 0x2; - static final int GL_LINE_STRIP = 0x3; - static final int GL_LINK_STATUS = 0x8B82; - static final int GL_LUMINANCE = 0x1909; - static final int GL_LUMINANCE_ALPHA = 0x190A; - static final int GL_MAX = 0x8008; - static final int GL_MAX_CUBE_MAP_TEXTURE_SIZE = 0x851C; - static final int GL_MAX_FRAGMENT_UNIFORM_COMPONENTS = 0x8B49; - static final int GL_MAX_FRAGMENT_UNIFORM_VECTORS = 0x8DFD; - static final int GL_MAX_TEXTURE_IMAGE_UNITS = 0x8872; - static final int GL_MAX_TEXTURE_SIZE = 0xD33; - static final int GL_MAX_VERTEX_ATTRIBS = 0x8869; - static final int GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS = 0x8B4C; - static final int GL_MAX_VERTEX_UNIFORM_COMPONENTS = 0x8B4A; - static final int GL_MAX_VERTEX_UNIFORM_VECTORS = 0x8DFB; - static final int GL_MIRRORED_REPEAT = 0x8370; - static final int GL_MIN = 0x8007; - static final int GL_NEAREST = 0x2600; - static final int GL_NEAREST_MIPMAP_LINEAR = 0x2702; - static final int GL_NEAREST_MIPMAP_NEAREST = 0x2700; - static final int GL_NEVER = 0x200; - static final int GL_NO_ERROR = 0x0; - static final int GL_NONE = 0x0; - static final int GL_NOTEQUAL = 0x205; - static final int GL_ONE = 0x1; - static final int GL_ONE_MINUS_DST_ALPHA = 0x0305; - static final int GL_ONE_MINUS_DST_COLOR = 0x307; - static final int GL_ONE_MINUS_SRC_ALPHA = 0x303; - static final int GL_ONE_MINUS_SRC_COLOR = 0x301; - static final int GL_OUT_OF_MEMORY = 0x505; - static final int GL_POINTS = 0x0; - static final int GL_POLYGON_OFFSET_FILL = 0x8037; - static final int GL_QUERY_RESULT = 0x8866; - static final int GL_QUERY_RESULT_AVAILABLE = 0x8867; - static final int GL_RED = 0x1903; - static final int GL_RENDERER = 0x1F01; - static final int GL_REPEAT = 0x2901; - static final int GL_REPLACE = 0x1E01; - static final int GL_RGB = 0x1907; - static final int GL_RGB565 = 0x8D62; - static final int GL_RGB5_A1 = 0x8057; - static final int GL_RGBA = 0x1908; - static final int GL_RGBA4 = 0x8056; - static final int GL_SCISSOR_TEST = 0xC11; - static final int GL_SHADING_LANGUAGE_VERSION = 0x8B8C; - static final int GL_SHORT = 0x1402; - static final int GL_SRC_ALPHA = 0x302; - static final int GL_SRC_ALPHA_SATURATE = 0x0308; - static final int GL_SRC_COLOR = 0x300; - static final int GL_STATIC_DRAW = 0x88E4; - static final int GL_STENCIL_BUFFER_BIT = 0x400; - static final int GL_STENCIL_TEST = 0xB90; - static final int GL_STREAM_DRAW = 0x88E0; - static final int GL_STREAM_READ = 0x88E1; - static final int GL_TEXTURE = 0x1702; - static final int GL_TEXTURE0 = 0x84C0; - static final int GL_TEXTURE1 = 0x84C1; - static final int GL_TEXTURE2 = 0x84C2; - static final int GL_TEXTURE3 = 0x84C3; - static final int GL_TEXTURE4 = 0x84C4; - static final int GL_TEXTURE5 = 0x84C5; - static final int GL_TEXTURE6 = 0x84C6; - static final int GL_TEXTURE7 = 0x84C7; - static final int GL_TEXTURE8 = 0x84C8; - static final int GL_TEXTURE9 = 0x84C9; - static final int GL_TEXTURE10 = 0x84CA; - static final int GL_TEXTURE11 = 0x84CB; - static final int GL_TEXTURE12 = 0x84CC; - static final int GL_TEXTURE13 = 0x84CD; - static final int GL_TEXTURE14 = 0x84CE; - static final int GL_TEXTURE15 = 0x84CF; - static final int GL_TEXTURE_2D = 0xDE1; - static final int GL_TEXTURE_CUBE_MAP = 0x8513; - static final int GL_TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515; - static final int GL_TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516; - static final int GL_TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517; - static final int GL_TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518; - static final int GL_TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519; - static final int GL_TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851A; - static final int GL_TEXTURE_MAG_FILTER = 0x2800; - static final int GL_TEXTURE_MIN_FILTER = 0x2801; - static final int GL_TEXTURE_WRAP_S = 0x2802; - static final int GL_TEXTURE_WRAP_T = 0x2803; - static final int GL_TIME_ELAPSED = 0x88BF; - static final int GL_TRIANGLES = 0x4; - static final int GL_TRIANGLE_FAN = 0x6; - static final int GL_TRIANGLE_STRIP = 0x5; - static final int GL_TRUE = 0x1; - static final int GL_UNPACK_ALIGNMENT = 0xCF5; - static final int GL_UNSIGNED_BYTE = 0x1401; - static final int GL_UNSIGNED_INT = 0x1405; - static final int GL_UNSIGNED_SHORT = 0x1403; - static final int GL_UNSIGNED_SHORT_5_6_5 = 0x8363; - static final int GL_UNSIGNED_SHORT_5_5_5_1 = 0x8034; - static final int GL_VENDOR = 0x1F00; - static final int GL_VERSION = 0x1F02; - static final int GL_VERTEX_SHADER = 0x8B31; - static final int GL_ZERO = 0x0; - - void resetStats(); + public static final int GL_ALPHA = 0x1906; + public static final int GL_ALWAYS = 0x207; + public static final int GL_ARRAY_BUFFER = 0x8892; + public static final int GL_BACK = 0x405; + public static final int GL_BLEND = 0xBE2; + public static final int GL_BLUE = 0x1905; + public static final int GL_BYTE = 0x1400; + public static final int GL_CLAMP_TO_EDGE = 0x812F; + public static final int GL_COLOR_BUFFER_BIT = 0x4000; + public static final int GL_COMPILE_STATUS = 0x8B81; + public static final int GL_CULL_FACE = 0xB44; + public static final int GL_DECR = 0x1E03; + public static final int GL_DECR_WRAP = 0x8508; + public static final int GL_DEPTH_BUFFER_BIT = 0x100; + public static final int GL_DEPTH_COMPONENT = 0x1902; + public static final int GL_DEPTH_COMPONENT16 = 0x81A5; + public static final int GL_DEPTH_TEST = 0xB71; + public static final int GL_DOUBLE = 0x140A; + public static final int GL_DST_ALPHA = 0x0304; + public static final int GL_DST_COLOR = 0x306; + public static final int GL_DYNAMIC_DRAW = 0x88E8; + public static final int GL_ELEMENT_ARRAY_BUFFER = 0x8893; + public static final int GL_EQUAL = 0x202; + public static final int GL_EXTENSIONS = 0x1F03; + public static final int GL_FALSE = 0x0; + public static final int GL_FLOAT = 0x1406; + public static final int GL_FRAGMENT_SHADER = 0x8B30; + public static final int GL_FRONT = 0x404; + public static final int GL_FUNC_ADD = 0x8006; + public static final int GL_FUNC_SUBTRACT = 0x800A; + public static final int GL_FUNC_REVERSE_SUBTRACT = 0x800B; + public static final int GL_FRONT_AND_BACK = 0x408; + public static final int GL_GEQUAL = 0x206; + public static final int GL_GREATER = 0x204; + public static final int GL_GREEN = 0x1904; + public static final int GL_INCR = 0x1E02; + public static final int GL_INCR_WRAP = 0x8507; + public static final int GL_INFO_LOG_LENGTH = 0x8B84; + public static final int GL_INT = 0x1404; + public static final int GL_INVALID_ENUM = 0x500; + public static final int GL_INVALID_VALUE = 0x501; + public static final int GL_INVALID_OPERATION = 0x502; + public static final int GL_INVERT = 0x150A; + public static final int GL_KEEP = 0x1E00; + public static final int GL_LEQUAL = 0x203; + public static final int GL_LESS = 0x201; + public static final int GL_LINEAR = 0x2601; + public static final int GL_LINEAR_MIPMAP_LINEAR = 0x2703; + public static final int GL_LINEAR_MIPMAP_NEAREST = 0x2701; + public static final int GL_LINES = 0x1; + public static final int GL_LINE_LOOP = 0x2; + public static final int GL_LINE_STRIP = 0x3; + public static final int GL_LINK_STATUS = 0x8B82; + public static final int GL_LUMINANCE = 0x1909; + public static final int GL_LUMINANCE_ALPHA = 0x190A; + public static final int GL_MAX = 0x8008; + public static final int GL_MAX_CUBE_MAP_TEXTURE_SIZE = 0x851C; + public static final int GL_MAX_FRAGMENT_UNIFORM_COMPONENTS = 0x8B49; + public static final int GL_MAX_FRAGMENT_UNIFORM_VECTORS = 0x8DFD; + public static final int GL_MAX_TEXTURE_IMAGE_UNITS = 0x8872; + public static final int GL_MAX_TEXTURE_SIZE = 0xD33; + public static final int GL_MAX_VERTEX_ATTRIBS = 0x8869; + public static final int GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS = 0x8B4C; + public static final int GL_MAX_VERTEX_UNIFORM_COMPONENTS = 0x8B4A; + public static final int GL_MAX_VERTEX_UNIFORM_VECTORS = 0x8DFB; + public static final int GL_MIRRORED_REPEAT = 0x8370; + public static final int GL_MIN = 0x8007; + public static final int GL_NEAREST = 0x2600; + public static final int GL_NEAREST_MIPMAP_LINEAR = 0x2702; + public static final int GL_NEAREST_MIPMAP_NEAREST = 0x2700; + public static final int GL_NEVER = 0x200; + public static final int GL_NO_ERROR = 0x0; + public static final int GL_NONE = 0x0; + public static final int GL_NOTEQUAL = 0x205; + public static final int GL_ONE = 0x1; + public static final int GL_ONE_MINUS_DST_ALPHA = 0x0305; + public static final int GL_ONE_MINUS_DST_COLOR = 0x307; + public static final int GL_ONE_MINUS_SRC_ALPHA = 0x303; + public static final int GL_ONE_MINUS_SRC_COLOR = 0x301; + public static final int GL_OUT_OF_MEMORY = 0x505; + public static final int GL_POINTS = 0x0; + public static final int GL_POLYGON_OFFSET_FILL = 0x8037; + public static final int GL_QUERY_RESULT = 0x8866; + public static final int GL_QUERY_RESULT_AVAILABLE = 0x8867; + public static final int GL_RED = 0x1903; + public static final int GL_RENDERER = 0x1F01; + public static final int GL_REPEAT = 0x2901; + public static final int GL_REPLACE = 0x1E01; + public static final int GL_RGB = 0x1907; + public static final int GL_RGB565 = 0x8D62; + public static final int GL_RGB5_A1 = 0x8057; + public static final int GL_RGBA = 0x1908; + public static final int GL_RGBA4 = 0x8056; + public static final int GL_SCISSOR_TEST = 0xC11; + public static final int GL_SHADING_LANGUAGE_VERSION = 0x8B8C; + public static final int GL_SHORT = 0x1402; + public static final int GL_SRC_ALPHA = 0x302; + public static final int GL_SRC_ALPHA_SATURATE = 0x0308; + public static final int GL_SRC_COLOR = 0x300; + public static final int GL_STATIC_DRAW = 0x88E4; + public static final int GL_STENCIL_BUFFER_BIT = 0x400; + public static final int GL_STENCIL_TEST = 0xB90; + public static final int GL_STREAM_DRAW = 0x88E0; + public static final int GL_STREAM_READ = 0x88E1; + public static final int GL_TEXTURE = 0x1702; + public static final int GL_TEXTURE0 = 0x84C0; + public static final int GL_TEXTURE1 = 0x84C1; + public static final int GL_TEXTURE2 = 0x84C2; + public static final int GL_TEXTURE3 = 0x84C3; + public static final int GL_TEXTURE4 = 0x84C4; + public static final int GL_TEXTURE5 = 0x84C5; + public static final int GL_TEXTURE6 = 0x84C6; + public static final int GL_TEXTURE7 = 0x84C7; + public static final int GL_TEXTURE8 = 0x84C8; + public static final int GL_TEXTURE9 = 0x84C9; + public static final int GL_TEXTURE10 = 0x84CA; + public static final int GL_TEXTURE11 = 0x84CB; + public static final int GL_TEXTURE12 = 0x84CC; + public static final int GL_TEXTURE13 = 0x84CD; + public static final int GL_TEXTURE14 = 0x84CE; + public static final int GL_TEXTURE15 = 0x84CF; + public static final int GL_TEXTURE_2D = 0xDE1; + public static final int GL_TEXTURE_CUBE_MAP = 0x8513; + public static final int GL_TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515; + public static final int GL_TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516; + public static final int GL_TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517; + public static final int GL_TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518; + public static final int GL_TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519; + public static final int GL_TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851A; + public static final int GL_TEXTURE_MAG_FILTER = 0x2800; + public static final int GL_TEXTURE_MIN_FILTER = 0x2801; + public static final int GL_TEXTURE_WRAP_S = 0x2802; + public static final int GL_TEXTURE_WRAP_T = 0x2803; + public static final int GL_TIME_ELAPSED = 0x88BF; + public static final int GL_TRIANGLES = 0x4; + public static final int GL_TRIANGLE_FAN = 0x6; + public static final int GL_TRIANGLE_STRIP = 0x5; + public static final int GL_TRUE = 0x1; + public static final int GL_UNPACK_ALIGNMENT = 0xCF5; + public static final int GL_UNSIGNED_BYTE = 0x1401; + public static final int GL_UNSIGNED_INT = 0x1405; + public static final int GL_UNSIGNED_SHORT = 0x1403; + public static final int GL_UNSIGNED_SHORT_5_6_5 = 0x8363; + public static final int GL_UNSIGNED_SHORT_5_5_5_1 = 0x8034; + public static final int GL_VENDOR = 0x1F00; + public static final int GL_VERSION = 0x1F02; + public static final int GL_VERTEX_SHADER = 0x8B31; + public static final int GL_ZERO = 0x0; + + public void resetStats(); /** *

Reference Page

@@ -204,7 +204,7 @@ public interface GL { * * @param texture which texture unit to make active. One of:
{@link #GL_TEXTURE0 TEXTURE0}GL_TEXTURE[1-31]
*/ - void glActiveTexture(int texture); + public void glActiveTexture(int texture); /** *

Reference Page

@@ -225,7 +225,7 @@ public interface GL { * @param program the program object to which a shader object will be attached. * @param shader the shader object that is to be attached. */ - void glAttachShader(int program, int shader); + public void glAttachShader(int program, int shader); /** *

Reference Page

@@ -235,7 +235,7 @@ public interface GL { * @param target the target type of query object established. * @param query the name of a query object. */ - void glBeginQuery(int target, int query); + public void glBeginQuery(int target, int query); /** *

Reference Page

@@ -245,7 +245,7 @@ public interface GL { * @param target the target to which the buffer object is bound. * @param buffer the name of a buffer object. */ - void glBindBuffer(int target, int buffer); + public void glBindBuffer(int target, int buffer); /** *

Reference Page

@@ -259,7 +259,7 @@ public interface GL { * @param target the texture target. * @param texture the texture object to bind. */ - void glBindTexture(int target, int texture); + public void glBindTexture(int target, int texture); /** *

Reference Page

@@ -269,7 +269,7 @@ public interface GL { * @param colorMode the RGB blend equation, how the red, green, and blue components of the source and destination colors are combined. * @param alphaMode the alpha blend equation, how the alpha component of the source and destination colors are combined */ - void glBlendEquationSeparate(int colorMode, int alphaMode); + public void glBlendEquationSeparate(int colorMode, int alphaMode); /** *

Reference Page

@@ -279,7 +279,7 @@ public interface GL { * @param sfactor the source weighting factor. * @param dfactor the destination weighting factor. */ - void glBlendFunc(int sfactor, int dfactor); + public void glBlendFunc(int sfactor, int dfactor); /** *

Reference Page

@@ -291,7 +291,7 @@ public interface GL { * @param sfactorAlpha how the alpha source blending factor is computed. The initial value is GL_ONE. * @param dfactorAlpha how the alpha destination blending factor is computed. The initial value is GL_ZERO. */ - void glBlendFuncSeparate(int sfactorRGB, int dfactorRGB, int sfactorAlpha, int dfactorAlpha); + public void glBlendFuncSeparate(int sfactorRGB, int dfactorRGB, int sfactorAlpha, int dfactorAlpha); /** *

Reference Page

@@ -321,7 +321,7 @@ public interface GL { * @param dataSize the size in bytes of the buffer object's new data store * @param usage the expected usage pattern of the data store. */ - void glBufferData(int target, long dataSize, int usage); + public void glBufferData(int target, long dataSize, int usage); /** *

Reference Page

@@ -351,7 +351,7 @@ public interface GL { * @param data a pointer to data that will be copied into the data store for initialization, or {@code NULL} if no data is to be copied. * @param usage the expected usage pattern of the data store. */ - void glBufferData(int target, FloatBuffer data, int usage); + public void glBufferData(int target, FloatBuffer data, int usage); /** *

Reference Page

@@ -381,7 +381,7 @@ public interface GL { * @param data a pointer to data that will be copied into the data store for initialization, or {@code NULL} if no data is to be copied * @param usage the expected usage pattern of the data store. */ - void glBufferData(int target, ShortBuffer data, int usage); + public void glBufferData(int target, ShortBuffer data, int usage); /** *

Reference Page

@@ -411,7 +411,7 @@ public interface GL { * @param data a pointer to data that will be copied into the data store for initialization, or {@code NULL} if no data is to be copied. * @param usage the expected usage pattern of the data store. */ - void glBufferData(int target, ByteBuffer data, int usage); + public void glBufferData(int target, ByteBuffer data, int usage); /** *

Reference Page

@@ -422,7 +422,7 @@ public interface GL { * @param offset the offset into the buffer object's data store where data replacement will begin, measured in bytes. * @param data a pointer to the new data that will be copied into the data store. */ - void glBufferSubData(int target, long offset, FloatBuffer data); + public void glBufferSubData(int target, long offset, FloatBuffer data); /** *

Reference Page

@@ -433,7 +433,7 @@ public interface GL { * @param offset the offset into the buffer object's data store where data replacement will begin, measured in bytes. * @param data a pointer to the new data that will be copied into the data store. */ - void glBufferSubData(int target, long offset, ShortBuffer data); + public void glBufferSubData(int target, long offset, ShortBuffer data); /** *

Reference Page

@@ -444,7 +444,7 @@ public interface GL { * @param offset the offset into the buffer object's data store where data replacement will begin, measured in bytes. * @param data a pointer to the new data that will be copied into the data store. */ - void glBufferSubData(int target, long offset, ByteBuffer data); + public void glBufferSubData(int target, long offset, ByteBuffer data); /** *

Reference Page

@@ -454,7 +454,7 @@ public interface GL { * * @param mask Zero or the bitwise OR of one or more values indicating which buffers are to be cleared. */ - void glClear(int mask); + public void glClear(int mask); /** *

Reference Page

@@ -466,7 +466,7 @@ public interface GL { * @param blue the value to which to clear the B channel of the color buffer. * @param alpha the value to which to clear the A channel of the color buffer. */ - void glClearColor(float red, float green, float blue, float alpha); + public void glClearColor(float red, float green, float blue, float alpha); /** *

Reference Page

@@ -478,7 +478,7 @@ public interface GL { * @param blue whether B values are written or not. * @param alpha whether A values are written or not. */ - void glColorMask(boolean red, boolean green, boolean blue, boolean alpha); + public void glColorMask(boolean red, boolean green, boolean blue, boolean alpha); /** *

Reference Page

@@ -487,7 +487,7 @@ public interface GL { * * @param shader the shader object to be compiled. */ - void glCompileShader(int shader); + public void glCompileShader(int shader); /** *

Reference Page

@@ -502,7 +502,7 @@ public interface GL { * @param border must be 0 * @param data a pointer to the compressed image data */ - void glCompressedTexImage2D(int target, int level, int internalFormat, int width, int height, int border, + public void glCompressedTexImage2D(int target, int level, int internalFormat, int width, int height, int border, ByteBuffer data); /** @@ -519,7 +519,7 @@ public interface GL { * @param format the format of the compressed image data stored at address {@code data}. * @param data a pointer to the compressed image data. */ - void glCompressedTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, + public void glCompressedTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, ByteBuffer data); /** @@ -527,7 +527,7 @@ public interface GL { *

* Creates a program object. */ - int glCreateProgram(); + public int glCreateProgram(); /** *

Reference Page

@@ -536,7 +536,7 @@ public interface GL { * * @param shaderType the type of shader to be created. One of:
{@link #GL_VERTEX_SHADER VERTEX_SHADER}{@link #GL_FRAGMENT_SHADER FRAGMENT_SHADER}{@link GL3#GL_GEOMETRY_SHADER GEOMETRY_SHADER}{@link GL4#GL_TESS_CONTROL_SHADER TESS_CONTROL_SHADER}
{@link GL4#GL_TESS_EVALUATION_SHADER TESS_EVALUATION_SHADER}
*/ - int glCreateShader(int shaderType); + public int glCreateShader(int shaderType); /** *

Reference Page

@@ -547,7 +547,7 @@ public interface GL { * * @param mode the CullFace mode. One of:
{@link #GL_FRONT FRONT}{@link #GL_BACK BACK}{@link #GL_FRONT_AND_BACK FRONT_AND_BACK}
*/ - void glCullFace(int mode); + public void glCullFace(int mode); /** *

Reference Page

@@ -556,7 +556,7 @@ public interface GL { * * @param buffers an array of buffer objects to be deleted. */ - void glDeleteBuffers(IntBuffer buffers); + public void glDeleteBuffers(IntBuffer buffers); /** *

Reference Page

@@ -565,7 +565,7 @@ public interface GL { * * @param program the program object to be deleted. */ - void glDeleteProgram(int program); + public void glDeleteProgram(int program); /** *

Reference Page

@@ -574,7 +574,7 @@ public interface GL { * * @param shader the shader object to be deleted. */ - void glDeleteShader(int shader); + public void glDeleteShader(int shader); /** *

Reference Page

@@ -589,7 +589,7 @@ public interface GL { * * @param textures contains {@code n} names of texture objects to be deleted. */ - void glDeleteTextures(IntBuffer textures); + public void glDeleteTextures(IntBuffer textures); /** *

Reference Page

@@ -598,7 +598,7 @@ public interface GL { * * @param func the depth test comparison. One of:
{@link #GL_NEVER NEVER}{@link #GL_ALWAYS ALWAYS}{@link #GL_LESS LESS}{@link #GL_LEQUAL LEQUAL}{@link #GL_EQUAL EQUAL}{@link #GL_GREATER GREATER}{@link #GL_GEQUAL GEQUAL}{@link #GL_NOTEQUAL NOTEQUAL}
*/ - void glDepthFunc(int func); + public void glDepthFunc(int func); /** *

Reference Page

@@ -607,7 +607,7 @@ public interface GL { * * @param flag whether depth values are written or not. */ - void glDepthMask(boolean flag); + public void glDepthMask(boolean flag); /** *

Reference Page

@@ -617,7 +617,7 @@ public interface GL { * @param nearVal the near depth range. * @param farVal the far depth range. */ - void glDepthRange(double nearVal, double farVal); + public void glDepthRange(double nearVal, double farVal); /** *

Reference Page

@@ -627,7 +627,7 @@ public interface GL { * @param program the program object from which to detach the shader object. * @param shader the shader object to be detached. */ - void glDetachShader(int program, int shader); + public void glDetachShader(int program, int shader); /** *

Reference Page

@@ -636,7 +636,7 @@ public interface GL { * * @param cap the OpenGL state to disable. */ - void glDisable(int cap); + public void glDisable(int cap); /** *

Reference Page

@@ -645,7 +645,7 @@ public interface GL { * * @param index the index of the generic vertex attribute to be disabled. */ - void glDisableVertexAttribArray(int index); + public void glDisableVertexAttribArray(int index); /** *

Reference Page

@@ -660,7 +660,7 @@ public interface GL { * @param first the first vertex to transfer to the GL. * @param count the number of vertices after {@code first} to transfer to the GL. */ - void glDrawArrays(int mode, int first, int count); + public void glDrawArrays(int mode, int first, int count); /** *

Reference Page

@@ -700,7 +700,7 @@ public interface GL { * @param type the type of the values in {@code indices}. * @param indices a pointer to the location where the indices are stored. */ - void glDrawRangeElements(int mode, int start, int end, int count, int type, long indices); /// GL2+ + public void glDrawRangeElements(int mode, int start, int end, int count, int type, long indices); /// GL2+ /** *

Reference Page

@@ -709,7 +709,7 @@ public interface GL { * * @param cap the OpenGL state to enable. */ - void glEnable(int cap); + public void glEnable(int cap); /** *

Reference Page

@@ -718,7 +718,7 @@ public interface GL { * * @param index the index of the generic vertex attribute to be enabled. */ - void glEnableVertexAttribArray(int index); + public void glEnableVertexAttribArray(int index); /** *

Reference Page

@@ -727,7 +727,7 @@ public interface GL { * * @param target the query object target. */ - void glEndQuery(int target); + public void glEndQuery(int target); /** *

Reference Page

@@ -736,7 +736,7 @@ public interface GL { * * @param buffers a buffer in which the generated buffer object names are stored. */ - void glGenBuffers(IntBuffer buffers); + public void glGenBuffers(IntBuffer buffers); /** *

Reference Page

@@ -746,7 +746,7 @@ public interface GL { * * @param textures a scalar or buffer in which to place the returned texture names. */ - void glGenTextures(IntBuffer textures); + public void glGenTextures(IntBuffer textures); /** *

Reference Page

@@ -755,7 +755,7 @@ public interface GL { * * @param ids a buffer in which the generated query object names are stored. */ - void glGenQueries(int number, IntBuffer ids); + public void glGenQueries(int number, IntBuffer ids); /** *

Reference Page

@@ -765,7 +765,7 @@ public interface GL { * @param program the program object to be queried. * @param name a null terminated string containing the name of the attribute variable whose location is to be queried. */ - int glGetAttribLocation(int program, String name); + public int glGetAttribLocation(int program, String name); /** *

Reference Page

@@ -779,7 +779,7 @@ public interface GL { * @param pname the state variable. * @param params a scalar or buffer in which to place the returned data. */ - void glGetBoolean(int pname, ByteBuffer params); + public void glGetBoolean(int pname, ByteBuffer params); /** *

Reference Page

@@ -790,7 +790,7 @@ public interface GL { * @param offset the offset into the buffer object's data store from which data will be returned, measured in bytes. * @param data a pointer to the location where buffer object data is returned. */ - void glGetBufferSubData(int target, long offset, ByteBuffer data); + public void glGetBufferSubData(int target, long offset, ByteBuffer data); /** *

Reference Page

@@ -800,7 +800,7 @@ public interface GL { * further error will again record its code. If a call to {@code GetError} returns {@link #GL_NO_ERROR NO_ERROR}, then there has been no detectable error since * the last call to {@code GetError} (or since the GL was initialized). */ - int glGetError(); + public int glGetError(); /** *

Reference Page

@@ -814,7 +814,7 @@ public interface GL { * @param pname the state variable. * @param params a scalar or buffer in which to place the returned data. */ - void glGetInteger(int pname, IntBuffer params); + public void glGetInteger(int pname, IntBuffer params); /** *

Reference Page

@@ -825,7 +825,7 @@ public interface GL { * @param pname the object parameter. * @param params the requested object parameter. */ - void glGetProgram(int program, int pname, IntBuffer params); + public void glGetProgram(int program, int pname, IntBuffer params); /** *

Reference Page

@@ -835,7 +835,7 @@ public interface GL { * @param program the program object whose information log is to be queried. * @param maxSize the size of the character buffer for storing the returned information log. */ - String glGetProgramInfoLog(int program, int maxSize); + public String glGetProgramInfoLog(int program, int maxSize); /** * Unsigned version. @@ -843,7 +843,7 @@ public interface GL { * @param query the name of a query object * @param pname the symbolic name of a query object parameter */ - long glGetQueryObjectui64(int query, int pname); + public long glGetQueryObjectui64(int query, int pname); /** *

Reference Page

@@ -853,7 +853,7 @@ public interface GL { * @param query the name of a query object * @param pname the symbolic name of a query object parameter. One of:
{@link #GL_QUERY_RESULT QUERY_RESULT}{@link #GL_QUERY_RESULT_AVAILABLE QUERY_RESULT_AVAILABLE}
*/ - int glGetQueryObjectiv(int query, int pname); + public int glGetQueryObjectiv(int query, int pname); /** *

Reference Page

@@ -864,7 +864,7 @@ public interface GL { * @param pname the object parameter. * @param params the requested object parameter. */ - void glGetShader(int shader, int pname, IntBuffer params); + public void glGetShader(int shader, int pname, IntBuffer params); /** *

Reference Page

@@ -874,7 +874,7 @@ public interface GL { * @param shader the shader object whose information log is to be queried. * @param maxSize the size of the character buffer for storing the returned information log. */ - String glGetShaderInfoLog(int shader, int maxSize); + public String glGetShaderInfoLog(int shader, int maxSize); /** *

Reference Page

@@ -883,7 +883,7 @@ public interface GL { * * @param name the property to query. One of:
{@link #GL_RENDERER RENDERER}{@link #GL_VENDOR VENDOR}{@link #GL_EXTENSIONS EXTENSIONS}{@link #GL_VERSION VERSION}{@link GL2#GL_SHADING_LANGUAGE_VERSION SHADING_LANGUAGE_VERSION}
*/ - String glGetString(int name); + public String glGetString(int name); /** *

Reference Page

@@ -893,7 +893,7 @@ public interface GL { * @param program the program object to be queried. * @param name a null terminated string containing the name of the uniform variable whose location is to be queried. */ - int glGetUniformLocation(int program, String name); + public int glGetUniformLocation(int program, String name); /** *

Reference Page

@@ -902,7 +902,7 @@ public interface GL { * * @param cap the enable state to query. */ - boolean glIsEnabled(int cap); + public boolean glIsEnabled(int cap); /** *

Reference Page

@@ -911,7 +911,7 @@ public interface GL { * * @param width the line width. */ - void glLineWidth(float width); + public void glLineWidth(float width); /** *

Reference Page

@@ -920,7 +920,7 @@ public interface GL { * * @param program the program object to be linked. */ - void glLinkProgram(int program); + public void glLinkProgram(int program); /** *

Reference Page

@@ -930,7 +930,7 @@ public interface GL { * @param pname the pixel store parameter to set. * @param param the parameter value */ - void glPixelStorei(int pname, int param); + public void glPixelStorei(int pname, int param); /** *

Reference Page

@@ -944,7 +944,7 @@ public interface GL { * @param factor the maximum depth slope factor. * @param units the constant scale. */ - void glPolygonOffset(float factor, float units); + public void glPolygonOffset(float factor, float units); /** *

Reference Page

@@ -963,7 +963,7 @@ public interface GL { * @param type the pixel type. * @param data a buffer in which to place the returned pixel data. */ - void glReadPixels(int x, int y, int width, int height, int format, int type, ByteBuffer data); + public void glReadPixels(int x, int y, int width, int height, int format, int type, ByteBuffer data); /** @@ -983,7 +983,7 @@ public interface GL { * @param type the pixel type. * @param offset a buffer in which to place the returned pixel data/ */ - void glReadPixels(int x, int y, int width, int height, int format, int type, long offset); + public void glReadPixels(int x, int y, int width, int height, int format, int type, long offset); /** *

Reference Page

@@ -998,7 +998,7 @@ public interface GL { * @param width the scissor rectangle width. * @param height the scissor rectangle height. */ - void glScissor(int x, int y, int width, int height); + public void glScissor(int x, int y, int width, int height); /** *

Reference Page

@@ -1013,7 +1013,7 @@ public interface GL { * @param shader the shader object whose source code is to be replaced, * @param strings an array of pointers to strings containing the source code to be loaded into the shader */ - void glShaderSource(int shader, String[] strings, IntBuffer length); + public void glShaderSource(int shader, String[] strings, IntBuffer length); /** *

Reference Page

@@ -1026,7 +1026,7 @@ public interface GL { * buffer. The initial value is 0. * @param mask a mask that is ANDed with both the reference value and the stored stencil value when the test is done. The initial value is all 1's. */ - void glStencilFuncSeparate(int face, int func, int ref, int mask); + public void glStencilFuncSeparate(int face, int func, int ref, int mask); /** *

Reference Page

@@ -1039,7 +1039,7 @@ public interface GL { * @param dppass the stencil action when both the stencil test and the depth test pass, or when the stencil test passes and either there is no depth buffer or depth * testing is not enabled. The initial value is GL_KEEP. */ - void glStencilOpSeparate(int face, int sfail, int dpfail, int dppass); + public void glStencilOpSeparate(int face, int sfail, int dpfail, int dppass); /** *

Reference Page

@@ -1056,7 +1056,7 @@ public interface GL { * @param type the texel data type. * @param data the texel data. */ - void glTexImage2D(int target, int level, int internalFormat, int width, int height, int border, int format, + public void glTexImage2D(int target, int level, int internalFormat, int width, int height, int border, int format, int type, ByteBuffer data); /** @@ -1068,7 +1068,7 @@ public interface GL { * @param pname the parameter to set. * @param param the parameter value. */ - void glTexParameterf(int target, int pname, float param); + public void glTexParameterf(int target, int pname, float param); /** *

Reference Page

@@ -1079,7 +1079,7 @@ public interface GL { * @param pname the parameter to set. * @param param the parameter value. */ - void glTexParameteri(int target, int pname, int param); + public void glTexParameteri(int target, int pname, int param); /** *

Reference Page

@@ -1097,7 +1097,7 @@ public interface GL { * @param type the pixel data type. * @param data the pixel data. */ - void glTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, int type, + public void glTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, int type, ByteBuffer data); /** @@ -1108,7 +1108,7 @@ public interface GL { * @param location the location of the uniform variable to be modified. * @param value a pointer to an array of {@code count} values that will be used to update the specified uniform variable. */ - void glUniform1(int location, FloatBuffer value); + public void glUniform1(int location, FloatBuffer value); /** *

Reference Page

@@ -1118,7 +1118,7 @@ public interface GL { * @param location the location of the uniform variable to be modified. * @param value a pointer to an array of {@code count} values that will be used to update the specified uniform variable. */ - void glUniform1(int location, IntBuffer value); + public void glUniform1(int location, IntBuffer value); /** *

Reference Page

@@ -1128,7 +1128,7 @@ public interface GL { * @param location the location of the uniform variable to be modified. * @param v0 the uniform value. */ - void glUniform1f(int location, float v0); + public void glUniform1f(int location, float v0); /** *

Reference Page

@@ -1138,7 +1138,7 @@ public interface GL { * @param location the location of the uniform variable to be modified. * @param v0 the uniform value. */ - void glUniform1i(int location, int v0); + public void glUniform1i(int location, int v0); /** *

Reference Page

@@ -1148,7 +1148,7 @@ public interface GL { * @param location the location of the uniform variable to be modified. * @param value a pointer to an array of {@code count} values that will be used to update the specified uniform variable. */ - void glUniform2(int location, IntBuffer value); + public void glUniform2(int location, IntBuffer value); /** *

Reference Page

@@ -1158,7 +1158,7 @@ public interface GL { * @param location the location of the uniform variable to be modified. * @param value a pointer to an array of {@code count} values that will be used to update the specified uniform variable. */ - void glUniform2(int location, FloatBuffer value); + public void glUniform2(int location, FloatBuffer value); /** *

Reference Page

@@ -1169,7 +1169,7 @@ public interface GL { * @param v0 the uniform x value. * @param v1 the uniform y value. */ - void glUniform2f(int location, float v0, float v1); + public void glUniform2f(int location, float v0, float v1); /** *

Reference Page

@@ -1179,7 +1179,7 @@ public interface GL { * @param location the location of the uniform variable to be modified. * @param value a pointer to an array of {@code count} values that will be used to update the specified uniform variable. */ - void glUniform3(int location, IntBuffer value); + public void glUniform3(int location, IntBuffer value); /** *

Reference Page

@@ -1189,7 +1189,7 @@ public interface GL { * @param location the location of the uniform variable to be modified. * @param value a pointer to an array of {@code count} values that will be used to update the specified uniform variable. */ - void glUniform3(int location, FloatBuffer value); + public void glUniform3(int location, FloatBuffer value); /** *

Reference Page

@@ -1201,7 +1201,7 @@ public interface GL { * @param v1 the uniform y value. * @param v2 the uniform z value. */ - void glUniform3f(int location, float v0, float v1, float v2); + public void glUniform3f(int location, float v0, float v1, float v2); /** *

Reference Page

@@ -1211,7 +1211,7 @@ public interface GL { * @param location the location of the uniform variable to be modified. * @param value a pointer to an array of {@code count} values that will be used to update the specified uniform variable. */ - void glUniform4(int location, FloatBuffer value); + public void glUniform4(int location, FloatBuffer value); /** *

Reference Page

@@ -1221,7 +1221,7 @@ public interface GL { * @param location the location of the uniform variable to be modified. * @param value a pointer to an array of {@code count} values that will be used to update the specified uniform variable. */ - void glUniform4(int location, IntBuffer value); + public void glUniform4(int location, IntBuffer value); /** *

Reference Page

@@ -1234,7 +1234,7 @@ public interface GL { * @param v2 the uniform z value. * @param v3 the uniform w value. */ - void glUniform4f(int location, float v0, float v1, float v2, float v3); + public void glUniform4f(int location, float v0, float v1, float v2, float v3); /** *

Reference Page

@@ -1245,7 +1245,7 @@ public interface GL { * @param transpose whether to transpose the matrix as the values are loaded into the uniform variable. * @param value a pointer to an array of {@code count} values that will be used to update the specified uniform variable. */ - void glUniformMatrix3(int location, boolean transpose, FloatBuffer value); + public void glUniformMatrix3(int location, boolean transpose, FloatBuffer value); /** *

Reference Page

@@ -1256,7 +1256,7 @@ public interface GL { * @param transpose whether to transpose the matrix as the values are loaded into the uniform variable. * @param value a pointer to an array of {@code count} values that will be used to update the specified uniform variable. */ - void glUniformMatrix4(int location, boolean transpose, FloatBuffer value); + public void glUniformMatrix4(int location, boolean transpose, FloatBuffer value); /** *

Reference Page

@@ -1265,7 +1265,7 @@ public interface GL { * * @param program the program object whose executables are to be used as part of current rendering state. */ - void glUseProgram(int program); + public void glUseProgram(int program); /** *

Reference Page

@@ -1281,7 +1281,7 @@ public interface GL { * @param pointer the vertex attribute data or the offset of the first component of the first generic vertex attribute in the array in the data store of the buffer * currently bound to the {@link GL#GL_ARRAY_BUFFER ARRAY_BUFFER} target. The initial value is 0. */ - void glVertexAttribPointer(int index, int size, int type, boolean normalized, int stride, long pointer); + public void glVertexAttribPointer(int index, int size, int type, boolean normalized, int stride, long pointer); /** *

Reference Page

@@ -1297,5 +1297,5 @@ public interface GL { * @param width the viewport width. * @param height the viewport height. */ - void glViewport(int x, int y, int width, int height); -} + public void glViewport(int x, int y, int width, int height); +} \ No newline at end of file diff --git a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java index 76b16c692..42cfb0b2d 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java +++ b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java @@ -49,6 +49,7 @@ import com.jme3.shader.Attribute; import com.jme3.shader.Shader; import com.jme3.shader.Shader.ShaderSource; import com.jme3.shader.Shader.ShaderType; +import com.jme3.shader.ShaderStorageBufferObject; import com.jme3.shader.Uniform; import com.jme3.texture.FrameBuffer; import com.jme3.texture.FrameBuffer.RenderBuffer; @@ -1050,6 +1051,7 @@ public final class GLRenderer implements Renderer { } } + @Override public void postFrame() { objManager.deleteUnused(this); OpenCLObjectManager.getInstance().deleteUnusedObjects(); @@ -1182,38 +1184,17 @@ 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); + case ShaderStorageBufferObject: { - 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(); + final ShaderStorageBufferObject ssbo = (ShaderStorageBufferObject) uniform.getValue(); + if (ssbo.getUniqueId() == -1 || ssbo.isUpdateNeeded()) { + updateBufferData(ssbo); + } - 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()); } @@ -1229,6 +1210,16 @@ public final class GLRenderer implements Renderer { } } + protected void updateShaderStorageBlocks(Shader shader) { + ListMap uniforms = shader.getUniformMap(); + for (int i = 0; i < uniforms.size(); i++) { + Uniform uniform = uniforms.getValue(i); + if (uniform.isUpdateNeeded()) { + updateUniform(shader, uniform); + } + } + } + protected void resetUniformLocations(Shader shader) { ListMap uniforms = shader.getUniformMap(); for (int i = 0; i < uniforms.size(); i++) { @@ -2535,6 +2526,37 @@ public final class GLRenderer implements Renderer { vb.clearUpdateNeeded(); } + @Override + public void updateBufferData(final ShaderStorageBufferObject ssbo) { + + final ByteBuffer data = ssbo.getData(); + if (data == null) { + throw new IllegalArgumentException("Can't upload SSBO without data."); + } + + int bufferId = ssbo.getId(); + if (bufferId == -1) { + + // create buffer + intBuf1.clear(); + gl.glGenBuffers(intBuf1); + bufferId = intBuf1.get(0); + + ssbo.setId(bufferId); + + objManager.registerObject(ssbo); + } + + gl4.glBindBuffer(GL4.GL_SHADER_STORAGE_BUFFER, bufferId); + + data.rewind(); + + gl4.glBufferData(GL4.GL_SHADER_STORAGE_BUFFER, data, GL4.GL_DYNAMIC_COPY); + gl4.glBindBuffer(GL4.GL_SHADER_STORAGE_BUFFER, 0); + + ssbo.clearUpdateNeeded(); + } + public void deleteBuffer(VertexBuffer vb) { int bufId = vb.getId(); if (bufId != -1) { @@ -2548,6 +2570,23 @@ public final class GLRenderer implements Renderer { } } + @Override + public void deleteBuffer(final ShaderStorageBufferObject ssbo) { + + int bufferId = ssbo.getId(); + if (bufferId == -1) { + return; + } + + intBuf1.clear(); + intBuf1.put(0, bufferId); + intBuf1.flip(); + + gl.glDeleteBuffers(intBuf1); + + ssbo.resetObject(); + } + public void clearVertexAttribs() { IDList attribList = context.attribIndexList; for (int i = 0; i < attribList.oldLen; i++) { diff --git a/jme3-core/src/main/java/com/jme3/shader/Shader.java b/jme3-core/src/main/java/com/jme3/shader/Shader.java index 72ecbca17..79c317093 100644 --- a/jme3-core/src/main/java/com/jme3/shader/Shader.java +++ b/jme3-core/src/main/java/com/jme3/shader/Shader.java @@ -51,6 +51,11 @@ public final class Shader extends NativeObject { * Maps uniform name to the uniform variable. */ private final ListMap uniforms; + + /** + * Maps storage block name to the storage block variable. + */ + private final ListMap storageBlocks; /** * Uniforms bound to {@link UniformBinding}s. @@ -220,10 +225,11 @@ public final class Shader extends NativeObject { */ public Shader(){ super(); - shaderSourceList = new ArrayList(); - uniforms = new ListMap(); - attribs = new IntMap(); - boundUniforms = new ArrayList(); + shaderSourceList = new ArrayList<>(); + uniforms = new ListMap<>(); + storageBlocks = new ListMap<>(); + attribs = new IntMap<>(); + boundUniforms = new ArrayList<>(); } /** @@ -240,6 +246,7 @@ public final class Shader extends NativeObject { } uniforms = null; + storageBlocks = null; boundUniforms = null; attribs = null; } @@ -288,10 +295,40 @@ public final class Shader extends NativeObject { return uniform; } + /** + * Get or create a storage block by the name. + * + * @param name the storage block's name. + * @return the storage block. + */ + public StorageBlock getStorageBlock(String name) { + + assert name.startsWith("sb_"); + + StorageBlock storageBlock = storageBlocks.get(name); + + if (storageBlock == null) { + storageBlock = new StorageBlock(); + storageBlock.name = name; + storageBlocks.put(name, storageBlock); + } + + return storageBlock; + } + public void removeUniform(String name){ uniforms.remove(name); } + /** + * Remove a storage block by the name. + * + * @param name the storage block's name. + */ + public void removeStorageBlock(String name){ + storageBlocks.remove(name); + } + public Attribute getAttribute(VertexBuffer.Type attribType){ int ordinal = attribType.ordinal(); Attribute attrib = attribs.get(ordinal); @@ -306,7 +343,16 @@ public final class Shader extends NativeObject { public ListMap getUniformMap(){ return uniforms; } - + + /** + * Get the storage blocks map. + * + * @return the storage blocks map. + */ + public ListMap getStorageBlockMap() { + return storageBlocks; + } + public ArrayList getBoundUniforms() { return boundUniforms; } @@ -320,6 +366,7 @@ public final class Shader extends NativeObject { return getClass().getSimpleName() + "[numSources=" + shaderSourceList.size() + ", numUniforms=" + uniforms.size() + + ", numStorageBlocks=" + storageBlocks.size() + ", shaderSources=" + getSources() + "]"; } @@ -343,7 +390,7 @@ public final class Shader extends NativeObject { * Resets all uniforms that do not have the "set-by-current-material" flag * to their default value (usually all zeroes or false). * When a uniform is modified, that flag is set, to remove the flag, - * use {@link #clearUniformsSetByCurrent() }. + * use {@link #clearUniformsSetByCurrentFlag() }. */ public void resetUniformsNotSetByCurrent() { int size = uniforms.size(); diff --git a/jme3-core/src/main/java/com/jme3/shader/ShaderStorageBufferObject.java b/jme3-core/src/main/java/com/jme3/shader/ShaderStorageBufferObject.java new file mode 100644 index 000000000..5ed5e5154 --- /dev/null +++ b/jme3-core/src/main/java/com/jme3/shader/ShaderStorageBufferObject.java @@ -0,0 +1,144 @@ +package com.jme3.shader; + +import com.jme3.renderer.Renderer; +import com.jme3.util.BufferUtils; +import com.jme3.util.NativeObject; + +import java.nio.ByteBuffer; + +/** + * The implementation of SSBO. + * + * @author JavaSaBr + */ +public class ShaderStorageBufferObject extends NativeObject { + + /** + * The buffer's data. + */ + private ByteBuffer data; + + /** + * The binding number. + */ + private int binding; + + public ShaderStorageBufferObject() { + this.handleRef = new Object(); + this.binding = 1; + } + + public ShaderStorageBufferObject(final int id) { + super(id); + } + + /** + * Set the binding number. + * + * @param binding the binding number. + */ + public void setBinding(final int binding) { + this.binding = binding; + } + + /** + * Get the binding number. + * + * @return the binding number. + */ + public int getBinding() { + return binding; + } + + /** + * Called to initialize the data in the {@link ShaderStorageBufferObject}. Must only + * be called once. + * + * @param data the native byte buffer. + */ + public void setupData(final ByteBuffer data) { + + if (id != -1) { + throw new UnsupportedOperationException("Data has already been sent. Cannot setupData again."); + } else if (data.isReadOnly()) { + throw new IllegalArgumentException("VertexBuffer data cannot be read-only."); + } + + this.data = data; + + setUpdateNeeded(); + } + + /** + * Called to update the data in the buffer with new data. Can only + * be called after {@link #setupData(java.nio.ByteBuffer) } + * has been called. Note that it is fine to call this method on the + * data already set, e.g. ssbo.updateData(ssbo.getData()), this will just + * set the proper update flag indicating the data should be sent to the GPU + * again. + *

+ * It is allowed to specify a buffer with different capacity than the + * originally set buffer. + * + * @param data the native data buffer to set. + */ + public void updateData(final ByteBuffer data) { + + if (data == null) { + throw new IllegalArgumentException("SSBO can't be without data buffer."); + } + + // Check if the data buffer is read-only which is a sign + // of a bug on the part of the caller + if (data.isReadOnly()) { + throw new IllegalArgumentException("SSBO's data cannot be read-only."); + } + + this.data = data; + + setUpdateNeeded(); + } + + /** + * Get the buffer's data. + * + * @return the buffer's data. + */ + public ByteBuffer getData() { + return data; + } + + @Override + public void resetObject() { + this.id = -1; + setUpdateNeeded(); + } + + @Override + public void deleteObject(final Object rendererObject) { + + if (rendererObject instanceof Renderer) { + throw new IllegalArgumentException("This ssbo can't be deleted from " + rendererObject); + } + + ((Renderer) rendererObject).deleteBuffer(this); + } + + @Override + protected void deleteNativeBuffers() { + super.deleteNativeBuffers(); + if (data != null) { + BufferUtils.destroyDirectBuffer(data); + } + } + + @Override + public NativeObject createDestructableClone() { + return new ShaderStorageBufferObject(id); + } + + @Override + public long getUniqueId() { + return ((long) OBJTYPE_SSBO << 32) | ((long) id); + } +} diff --git a/jme3-core/src/main/java/com/jme3/shader/StorageBlock.java b/jme3-core/src/main/java/com/jme3/shader/StorageBlock.java new file mode 100644 index 000000000..6a905cee0 --- /dev/null +++ b/jme3-core/src/main/java/com/jme3/shader/StorageBlock.java @@ -0,0 +1,455 @@ +/* + * Copyright (c) 2009-2017 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.jme3.shader; + +import com.jme3.math.*; +import com.jme3.util.BufferUtils; +import com.jme3.util.TempVars; + +import java.nio.Buffer; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; + +public class StorageBlock extends ShaderVariable { + + private static final Integer ZERO_INT = 0; + private static final Float ZERO_FLT = Float.valueOf(0); + private static final FloatBuffer ZERO_BUF = BufferUtils.createFloatBuffer(4*4); + + /** + * Currently set value of the uniform. + */ + protected Object value = null; + + /** + * For arrays or matrices, efficient format + * that can be sent to GL faster. + */ + protected FloatBuffer multiData = null; + + /** + * Type of uniform + */ + protected VarType varType; + + /** + * Binding to a renderer value, or null if user-defined uniform + */ + protected UniformBinding binding; + + /** + * Used to track which uniforms to clear to avoid + * values leaking from other materials that use that shader. + */ + protected boolean setByCurrentMaterial = false; + + @Override + public int hashCode() { + int hash = 5; + hash = 31 * hash + (this.value != null ? this.value.hashCode() : 0); + hash = 31 * hash + (this.varType != null ? this.varType.hashCode() : 0); + hash = 31 * hash + (this.binding != null ? this.binding.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + final StorageBlock other = (StorageBlock) obj; + if (this.value != other.value && (this.value == null || !this.value.equals(other.value))) { + return false; + } + return this.binding == other.binding && this.varType == other.varType; + } + + @Override + public String toString(){ + StringBuilder sb = new StringBuilder(); + sb.append("Uniform[name="); + sb.append(name); + if (varType != null){ + sb.append(", type="); + sb.append(varType); + sb.append(", value="); + sb.append(value); + }else{ + sb.append(", value="); + } + sb.append("]"); + return sb.toString(); + } + + public void setBinding(UniformBinding binding){ + this.binding = binding; + } + + public UniformBinding getBinding(){ + return binding; + } + + public VarType getVarType() { + return varType; + } + + public Object getValue(){ + return value; + } + + public FloatBuffer getMultiData() { + return multiData; + } + + public boolean isSetByCurrentMaterial() { + return setByCurrentMaterial; + } + + public void clearSetByCurrentMaterial(){ + setByCurrentMaterial = false; + } + + public void clearValue(){ + updateNeeded = true; + + if (multiData != null){ + multiData.clear(); + + while (multiData.remaining() > 0){ + ZERO_BUF.clear(); + ZERO_BUF.limit( Math.min(multiData.remaining(), 16) ); + multiData.put(ZERO_BUF); + } + + multiData.clear(); + + return; + } + + if (varType == null) { + return; + } + + switch (varType){ + case Int: + this.value = ZERO_INT; + break; + case Boolean: + this.value = Boolean.FALSE; + break; + case Float: + this.value = ZERO_FLT; + break; + case Vector2: + if (this.value != null) { + ((Vector2f) this.value).set(Vector2f.ZERO); + } + break; + case Vector3: + if (this.value != null) { + ((Vector3f) this.value).set(Vector3f.ZERO); + } + break; + case Vector4: + if (this.value != null) { + if (this.value instanceof ColorRGBA) { + ((ColorRGBA) this.value).set(ColorRGBA.BlackNoAlpha); + } else if (this.value instanceof Vector4f) { + ((Vector4f) this.value).set(Vector4f.ZERO); + } else { + ((Quaternion) this.value).set(Quaternion.ZERO); + } + } + break; + default: + // won't happen because those are either textures + // or multidata types + } + } + + public void setValue(VarType type, Object value){ + if (location == LOC_NOT_DEFINED) { + return; + } + + if (varType != null && varType != type) { + throw new IllegalArgumentException("Expected a " + varType.name() + " value!"); + } + + if (value == null) { + throw new IllegalArgumentException("for uniform " + name + ": value cannot be null"); + } + + setByCurrentMaterial = true; + + switch (type){ + case Matrix3: + if (value.equals(this.value)) { + return; + } + Matrix3f m3 = (Matrix3f) value; + if (multiData == null) { + multiData = BufferUtils.createFloatBuffer(9); + } + m3.fillFloatBuffer(multiData, true); + multiData.clear(); + if (this.value == null) { + this.value = new Matrix3f(m3); + } else { + ((Matrix3f)this.value).set(m3); + } + break; + case Matrix4: + if (value.equals(this.value)) { + return; + } + Matrix4f m4 = (Matrix4f) value; + if (multiData == null) { + multiData = BufferUtils.createFloatBuffer(16); + } + m4.fillFloatBuffer(multiData, true); + multiData.clear(); + if (this.value == null) { + this.value = new Matrix4f(m4); + } else { + ((Matrix4f)this.value).copy(m4); + } + break; + case IntArray: + int[] ia = (int[]) value; + if (this.value == null) { + this.value = BufferUtils.createIntBuffer(ia); + } else { + this.value = BufferUtils.ensureLargeEnough((IntBuffer)this.value, ia.length); + } + ((IntBuffer)this.value).clear(); + break; + case FloatArray: + float[] fa = (float[]) value; + if (multiData == null) { + multiData = BufferUtils.createFloatBuffer(fa); + } else { + multiData = BufferUtils.ensureLargeEnough(multiData, fa.length); + } + multiData.put(fa); + multiData.clear(); + break; + case Vector2Array: + Vector2f[] v2a = (Vector2f[]) value; + if (multiData == null) { + multiData = BufferUtils.createFloatBuffer(v2a); + } else { + multiData = BufferUtils.ensureLargeEnough(multiData, v2a.length * 2); + } + for (int i = 0; i < v2a.length; i++) { + BufferUtils.setInBuffer(v2a[i], multiData, i); + } + multiData.clear(); + break; + case Vector3Array: + Vector3f[] v3a = (Vector3f[]) value; + if (multiData == null) { + multiData = BufferUtils.createFloatBuffer(v3a); + } else { + multiData = BufferUtils.ensureLargeEnough(multiData, v3a.length * 3); + } + for (int i = 0; i < v3a.length; i++) { + BufferUtils.setInBuffer(v3a[i], multiData, i); + } + multiData.clear(); + break; + case Vector4Array: + Vector4f[] v4a = (Vector4f[]) value; + if (multiData == null) { + multiData = BufferUtils.createFloatBuffer(v4a); + } else { + multiData = BufferUtils.ensureLargeEnough(multiData, v4a.length * 4); + } + for (int i = 0; i < v4a.length; i++) { + BufferUtils.setInBuffer(v4a[i], multiData, i); + } + multiData.clear(); + break; + case Matrix3Array: + Matrix3f[] m3a = (Matrix3f[]) value; + if (multiData == null) { + multiData = BufferUtils.createFloatBuffer(m3a.length * 9); + } else { + multiData = BufferUtils.ensureLargeEnough(multiData, m3a.length * 9); + } + for (int i = 0; i < m3a.length; i++) { + m3a[i].fillFloatBuffer(multiData, true); + } + multiData.clear(); + break; + case Matrix4Array: + Matrix4f[] m4a = (Matrix4f[]) value; + if (multiData == null) { + multiData = BufferUtils.createFloatBuffer(m4a.length * 16); + } else { + multiData = BufferUtils.ensureLargeEnough(multiData, m4a.length * 16); + } + for (int i = 0; i < m4a.length; i++) { + m4a[i].fillFloatBuffer(multiData, true); + } + multiData.clear(); + break; + case Vector2: + if (value.equals(this.value)) { + return; + } + if (this.value == null) { + this.value = new Vector2f((Vector2f) value); + } else { + ((Vector2f) this.value).set((Vector2f) value); + } + break; + case Vector3: + if (value.equals(this.value)) { + return; + } + if (this.value == null) { + this.value = new Vector3f((Vector3f) value); + } else { + ((Vector3f) this.value).set((Vector3f) value); + } + break; + case Vector4: + if (value.equals(this.value)) { + return; + } + + TempVars vars = TempVars.get(); + Vector4f vec4 = vars.vect4f1; + //handle the null case + if (this.value == null) { + try { + this.value = value.getClass().newInstance(); + } catch (InstantiationException | IllegalAccessException e) { + throw new IllegalArgumentException("Cannot instanciate param of class " + value.getClass().getCanonicalName()); + } + } + //feed the pivot vec 4 with the correct value + if (value instanceof ColorRGBA) { + ColorRGBA c = (ColorRGBA) value; + vec4.set(c.r, c.g, c.b, c.a); + } else if (value instanceof Vector4f) { + vec4.set((Vector4f) value); + } else { + Quaternion q = (Quaternion) value; + vec4.set(q.getX(), q.getY(), q.getZ(), q.getW()); + } + + //feed this.value with the collected values. + if (this.value instanceof ColorRGBA) { + ((ColorRGBA) this.value).set(vec4.x, vec4.y, vec4.z, vec4.w); + } else if (value instanceof Vector4f) { + ((Vector4f) this.value).set(vec4); + } else { + ((Quaternion) this.value).set(vec4.x, vec4.y, vec4.z, vec4.w); + } + vars.release(); + break; + // Only use check if equals optimization for primitive values + case Int: + case Float: + case Boolean: + if (value.equals(this.value)) { + return; + } + this.value = value; + break; + default: + this.value = value; + break; + } + +// if (multiData != null) { +// this.value = multiData; +// } + + varType = type; + updateNeeded = true; + } + + public void setVector4Length(int length){ + if (location == -1) { + return; + } + + multiData = BufferUtils.ensureLargeEnough(multiData, length * 4); + value = multiData; + varType = VarType.Vector4Array; + updateNeeded = true; + setByCurrentMaterial = true; + } + + public void setVector4InArray(float x, float y, float z, float w, int index){ + if (location == -1) { + return; + } + + if (varType != null && varType != VarType.Vector4Array) { + throw new IllegalArgumentException("Expected a " + varType.name() + " value!"); + } + + multiData.position(index * 4); + multiData.put(x).put(y).put(z).put(w); + multiData.rewind(); + updateNeeded = true; + setByCurrentMaterial = true; + } + + public boolean isUpdateNeeded(){ + return updateNeeded; + } + + public void clearUpdateNeeded(){ + updateNeeded = false; + } + + public void reset(){ + setByCurrentMaterial = false; + location = -2; + updateNeeded = true; + } + + public void deleteNativeBuffers() { + if (value instanceof Buffer) { + BufferUtils.destroyDirectBuffer((Buffer)value); + value = null; // ???? + } + } +} diff --git a/jme3-core/src/main/java/com/jme3/shader/VarType.java b/jme3-core/src/main/java/com/jme3/shader/VarType.java index 6e33eb5b3..25ea22c9a 100644 --- a/jme3-core/src/main/java/com/jme3/shader/VarType.java +++ b/jme3-core/src/main/java/com/jme3/shader/VarType.java @@ -58,8 +58,7 @@ public enum VarType { TextureArray(false,true,"sampler2DArray|sampler2DArrayShadow"), TextureCubeMap(false,true,"samplerCube"), Int("int"), - Struct(false, false, "dynamic"), - StructArray(false, false, "dynamic"); + ShaderStorageBufferObject(false, false, "dynamic"); private boolean usesMultiData = false; private boolean textureType = false; diff --git a/jme3-core/src/main/java/com/jme3/system/NullRenderer.java b/jme3-core/src/main/java/com/jme3/system/NullRenderer.java index 1eb2b1533..6b39e2879 100644 --- a/jme3-core/src/main/java/com/jme3/system/NullRenderer.java +++ b/jme3-core/src/main/java/com/jme3/system/NullRenderer.java @@ -46,6 +46,7 @@ import com.jme3.scene.Mesh; import com.jme3.scene.VertexBuffer; import com.jme3.shader.Shader; import com.jme3.shader.Shader.ShaderSource; +import com.jme3.shader.ShaderStorageBufferObject; import com.jme3.texture.FrameBuffer; import com.jme3.texture.Image; import com.jme3.texture.Texture; @@ -148,9 +149,17 @@ public class NullRenderer implements Renderer { public void updateBufferData(VertexBuffer vb) { } + @Override + public void updateBufferData(ShaderStorageBufferObject ssbo) { + } + public void deleteBuffer(VertexBuffer vb) { } + @Override + public void deleteBuffer(ShaderStorageBufferObject ssbo) { + } + public void renderMesh(Mesh mesh, int lod, int count, VertexBuffer[] instanceData) { } diff --git a/jme3-core/src/main/java/com/jme3/util/NativeObject.java b/jme3-core/src/main/java/com/jme3/util/NativeObject.java index 508e6623d..d660c13a3 100644 --- a/jme3-core/src/main/java/com/jme3/util/NativeObject.java +++ b/jme3-core/src/main/java/com/jme3/util/NativeObject.java @@ -52,7 +52,8 @@ public abstract class NativeObject implements Cloneable { OBJTYPE_SHADERSOURCE = 5, OBJTYPE_AUDIOBUFFER = 6, OBJTYPE_AUDIOSTREAM = 7, - OBJTYPE_FILTER = 8; + OBJTYPE_FILTER = 8, + OBJTYPE_SSBO = 9; /** * The object manager to which this NativeObject is registered to.