diff --git a/Raylib-cs/Rlgl.cs b/Raylib-cs/Rlgl.cs index 34587d3..dffbbcd 100644 --- a/Raylib-cs/Rlgl.cs +++ b/Raylib-cs/Rlgl.cs @@ -5,53 +5,6 @@ using System.Security; namespace Raylib_cs { - /// RenderBatch type - [StructLayout(LayoutKind.Sequential)] - public struct RenderBatch - { - int buffersCount; // Number of vertex buffers (multi-buffering support) - int currentBuffer; // Current buffer tracking in case of multi-buffering - IntPtr vertexBuffer; // Dynamic buffer(s) for vertex data - - IntPtr draws; // Draw calls array, depends on textureId - int drawsCounter; // Draw calls counter - float currentDepth; // Current depth value for next draw - } - - public enum GlVersion - { - OPENGL_11 = 1, - OPENGL_21, - OPENGL_33, - OPENGL_ES_20 - } - - public enum FramebufferAttachType - { - RL_ATTACHMENT_COLOR_CHANNEL0 = 0, - RL_ATTACHMENT_COLOR_CHANNEL1, - RL_ATTACHMENT_COLOR_CHANNEL2, - RL_ATTACHMENT_COLOR_CHANNEL3, - RL_ATTACHMENT_COLOR_CHANNEL4, - RL_ATTACHMENT_COLOR_CHANNEL5, - RL_ATTACHMENT_COLOR_CHANNEL6, - RL_ATTACHMENT_COLOR_CHANNEL7, - RL_ATTACHMENT_DEPTH = 100, - RL_ATTACHMENT_STENCIL = 200, - } - - public enum FramebufferAttachTextureType - { - RL_ATTACHMENT_CUBEMAP_POSITIVE_X = 0, - RL_ATTACHMENT_CUBEMAP_NEGATIVE_X, - RL_ATTACHMENT_CUBEMAP_POSITIVE_Y, - RL_ATTACHMENT_CUBEMAP_NEGATIVE_Y, - RL_ATTACHMENT_CUBEMAP_POSITIVE_Z, - RL_ATTACHMENT_CUBEMAP_NEGATIVE_Z, - RL_ATTACHMENT_TEXTURE2D = 100, - RL_ATTACHMENT_RENDERBUFFER = 200, - } - [SuppressUnmanagedCodeSecurity] public static class Rlgl { @@ -99,6 +52,22 @@ namespace Raylib_cs public const int RL_UNSIGNED_BYTE = 0x1401; public const int RL_FLOAT = 0x1406; + // Buffer usage hint + public const int RL_STREAM_DRAW = 0x88E0; + public const int RL_STREAM_READ = 0x88E1; + public const int RL_STREAM_COPY = 0x88E2; + public const int RL_STATIC_DRAW = 0x88E4; + public const int RL_STATIC_READ = 0x88E5; + public const int RL_STATIC_COPY = 0x88E6; + public const int RL_DYNAMIC_DRAW = 0x88E8; + public const int RL_DYNAMIC_READ = 0x88E9; + public const int RL_DYNAMIC_COPY = 0x88EA; + + // GL Shader type + public const int RL_FRAGMENT_SHADER = 0x8B30; + public const int RL_VERTEX_SHADER = 0x8B31; + public const int RL_COMPUTE_SHADER = 0x91B9; + // ------------------------------------------------------------------------------------ // Functions Declaration - Matrix operations // ------------------------------------------------------------------------------------ @@ -125,7 +94,7 @@ namespace Raylib_cs /// Multiply the current matrix by a rotation matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlRotatef(float angleDeg, float x, float y, float z); + public static extern void rlRotatef(float angle, float x, float y, float z); /// Multiply the current matrix by a scaling matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -133,7 +102,7 @@ namespace Raylib_cs /// Multiply the current matrix by another matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlMultMatrixf(ref float[] matf); + public static extern void rlMultMatrixf(float[] matf); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlFrustum(double left, double right, double bottom, double top, double znear, double zfar); @@ -230,6 +199,17 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlDisableVertexAttribute(uint index); + /// Enable attribute state pointer
+ /// buffer refers to a void *
+ /// NOTE: Only available for GRAPHICS_API_OPENGL_11
+ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void rlEnableStatePointer(int vertexAttribType, IntPtr buffer); + + /// Disable attribute state pointer
+ /// NOTE: Only available for GRAPHICS_API_OPENGL_11
+ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void rlDisableStatePointer(int vertexAttribType); + // Textures state @@ -279,9 +259,21 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlDisableFramebuffer(); + /// Activate multiple draw color buffers + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void rlActiveDrawBuffers(int count); + // General render state + /// Enable color blending + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void rlEnableColorBlend(); + + /// Disable color blending + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void rlDisableColorBlend(); + /// Enable depth test [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlEnableDepthTest(); @@ -368,7 +360,7 @@ namespace Raylib_cs /// Set blending mode [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlSetBlendMode(int mode); + public static extern void rlSetBlendMode(BlendMode mode); /// Set blending mode factor and equation (using OpenGL factors) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -387,12 +379,12 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlglClose(); - /// Load OpenGL extensions - /// loader refers to a void * + /// Load OpenGL extensions
+ /// loader refers to a void *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlLoadExtensions(IntPtr loader); - /// Returns current OpenGL version + /// Get current OpenGL version [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern GlVersion rlGetVersion(); @@ -404,18 +396,23 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int rlGetFramebufferHeight(); - /// Get default shader - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Shader rlGetShaderDefault(); - /// Get default texture [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Texture2D rlGetTextureDefault(); + public static extern uint rlGetTextureIdDefault(); + /// Get default shader + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern uint rlGetShaderIdDefault(); + + /// Get default shader locations + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static unsafe extern int* rlGetShaderLocsDefault(); // Render batch management - /// Load a render batch system + /// Load a render batch system
+ /// NOTE: rlgl provides a default render batch to behave like OpenGL 1.1 immediate mode
+ /// but this render batch API is exposed in case custom batches are required
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern RenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements); @@ -460,7 +457,7 @@ namespace Raylib_cs /// Update GPU buffer with new data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlUpdateVertexBuffer(int bufferId, IntPtr data, int dataSize, int offset); + public static extern void rlUpdateVertexBuffer(uint bufferId, IntPtr data, int dataSize, int offset); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlUnloadVertexArray(uint vaoId); @@ -516,18 +513,22 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlGetGlTextureFormats(PixelFormat format, ref uint glInternalFormat, ref uint glFormat, ref uint glType); + /// Get OpenGL internal formats + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr rlGetPixelFormatName(PixelFormat format); + /// Unload texture from GPU memory [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlUnloadTexture(uint id); /// Generate mipmap data for selected texture [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlGenerateMipmaps(ref Texture2D texture); + public static extern void rlGenTextureMipmaps(uint id, int width, int height, PixelFormat format, ref int[] mipmaps); /// Read texture pixel data
/// IntPtr refers to a void *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr rlReadTexturePixels(Texture2D texture); + public static extern IntPtr rlReadTexturePixels(uint id, int width, int height, PixelFormat format); /// Read screen pixel data (color buffer)
/// IntPtr refers to a unsigned char *
@@ -560,7 +561,8 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint rlLoadShaderCode(string vsCode, string fsCode); - /// Compile custom shader and return shader id (type: GL_VERTEX_SHADER, GL_FRAGMENT_SHADER) + /// Compile custom shader and return shader id
+ /// (type: RL_VERTEX_SHADER, RL_FRAGMENT_SHADER, RL_COMPUTE_SHADER)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint rlCompileShader(string shaderCode, int type); @@ -597,6 +599,52 @@ namespace Raylib_cs public static extern void rlSetShader(Shader shader); + // Compute shader management + + /// Load compute shader program + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern uint rlLoadComputeShaderProgram(uint shaderId); + + /// Dispatch compute shader (equivalent to *draw* for graphics pilepine) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void rlComputeShaderDispatch(uint groupX, uint groupY, uint groupZ); + + /// Load shader storage buffer object (SSBO) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern unsafe uint rlLoadShaderBuffer(ulong size, void* data, int usageHint); + + /// Unload shader storage buffer object (SSBO) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void rlUnloadShaderBuffer(uint ssboId); + + /// Update SSBO buffer data + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void rlUpdateShaderBufferElements(Shader shader); + + /// Get SSBO buffer size + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern unsafe ulong rlGetShaderBufferSize(uint id, void* dest, ulong count, ulong offset); + + /// Bind SSBO buffer + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern unsafe void rlReadShaderBufferElements(uint id, void* dest, ulong count, ulong offset); + + /// Copy SSBO buffer data + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void rlBindShaderBuffer(uint id, uint index); + + + // Buffer management + + /// Copy SSBO buffer data + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void rlCopyBuffersElements(uint destId, uint srcId, ulong destOffset, ulong srcOffset, ulong count); + + /// Bind image texture + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void rlBindImageTexture(uint id, uint index, uint format, int readOnly); + + // Matrix state management /// Get internal modelview matrix diff --git a/Raylib-cs/types/RenderBatch.cs b/Raylib-cs/types/RenderBatch.cs new file mode 100644 index 0000000..e3e3c05 --- /dev/null +++ b/Raylib-cs/types/RenderBatch.cs @@ -0,0 +1,148 @@ +using System; +using System.Runtime.InteropServices; + +namespace Raylib_cs +{ + /// + /// RenderBatch type + /// + [StructLayout(LayoutKind.Sequential)] + public struct RenderBatch + { + /// + /// Number of vertex buffers (multi-buffering support) + /// + int buffersCount; + + /// + /// Current buffer tracking in case of multi-buffering + /// + int currentBuffer; + + /// + /// Dynamic buffer(s) for vertex data + /// + IntPtr vertexBuffer; + + /// + /// Draw calls array, depends on textureId + /// + IntPtr draws; + + /// + /// Draw calls counter + /// + int drawsCounter; + + /// + /// Current depth value for next draw + /// + float currentDepth; + } + + /// + /// Dynamic vertex buffers (position + texcoords + colors + indices arrays) + /// + [StructLayout(LayoutKind.Sequential)] + public unsafe struct VertexBuffer + { + /// + /// Number of elements in the buffer (QUADS) + /// + public int elementCount; + + /// + /// Vertex position (XYZ - 3 components per vertex) (shader-location = 0, float *) + /// + public IntPtr vertices; + + /// + /// Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1, float *) + /// + public IntPtr texcoords; + + /// + /// Vertex colors (RGBA - 4 components per vertex) (shader-location = 3, unsigned char *) + /// + public IntPtr colors; + + /// + /// Vertex indices (in case vertex data comes indexed) (6 indices per quad)
+ /// unsigned int * for GRAPHICS_API_OPENGL_11 or GRAPHICS_API_OPENGL_33
+ /// unsigned short * for GRAPHICS_API_OPENGL_ES2 + ///
+ public IntPtr indices; + + /// + /// OpenGL Vertex Array Object id + /// + public uint vaoId; + + /// + /// OpenGL Vertex Buffer Objects id (4 types of vertex data) + /// + public fixed uint vboId[4]; + } + + /// + /// Dynamic vertex buffers (position + texcoords + colors + indices arrays) + /// + [StructLayout(LayoutKind.Sequential)] + public struct DrawCall + { + /// + /// Drawing mode: LINES, TRIANGLES, QUADS + /// + int mode; + + /// + /// Number of vertices for the draw call + /// + int vertexCount; + + /// + /// Number of vertices required for index alignment (LINES, TRIANGLES) + /// + int vertexAlignment; + + /// + /// Texture id to be used on the draw -> Use to create new draw call if changes + /// + uint textureId; + } + + public enum GlVersion + { + OPENGL_11 = 1, + OPENGL_21, + OPENGL_33, + OPENGL_43, + OPENGL_ES_20 + } + + public enum FramebufferAttachType + { + RL_ATTACHMENT_COLOR_CHANNEL0 = 0, + RL_ATTACHMENT_COLOR_CHANNEL1, + RL_ATTACHMENT_COLOR_CHANNEL2, + RL_ATTACHMENT_COLOR_CHANNEL3, + RL_ATTACHMENT_COLOR_CHANNEL4, + RL_ATTACHMENT_COLOR_CHANNEL5, + RL_ATTACHMENT_COLOR_CHANNEL6, + RL_ATTACHMENT_COLOR_CHANNEL7, + RL_ATTACHMENT_DEPTH = 100, + RL_ATTACHMENT_STENCIL = 200, + } + + public enum FramebufferAttachTextureType + { + RL_ATTACHMENT_CUBEMAP_POSITIVE_X = 0, + RL_ATTACHMENT_CUBEMAP_NEGATIVE_X, + RL_ATTACHMENT_CUBEMAP_POSITIVE_Y, + RL_ATTACHMENT_CUBEMAP_NEGATIVE_Y, + RL_ATTACHMENT_CUBEMAP_POSITIVE_Z, + RL_ATTACHMENT_CUBEMAP_NEGATIVE_Z, + RL_ATTACHMENT_TEXTURE2D = 100, + RL_ATTACHMENT_RENDERBUFFER = 200, + } +}