2
0
mirror of https://github.com/raylib-cs/raylib-cs synced 2025-09-09 03:01:41 -04:00

Initial 3.7 update

- Many breaking changes in this update. This is a work in
progress and needs testing.
This commit is contained in:
2021-04-22 10:46:24 +01:00
parent b6cf094a34
commit 3224a58371
3 changed files with 618 additions and 351 deletions

View File

@@ -5,9 +5,19 @@ using System.Security;
namespace Raylib_cs
{
// ----------------------------------------------------------------------------------
// Types and Structures Definition
// ----------------------------------------------------------------------------------
// 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,
@@ -30,7 +40,7 @@ namespace Raylib_cs
RL_ATTACHMENT_STENCIL = 200,
}
public enum FramebufferTexType
public enum FramebufferAttachTextureType
{
RL_ATTACHMENT_CUBEMAP_POSITIVE_X = 0,
RL_ATTACHMENT_CUBEMAP_NEGATIVE_X,
@@ -55,28 +65,40 @@ namespace Raylib_cs
public const int MAX_MATRIX_STACK_SIZE = 32;
public const float RL_CULL_DISTANCE_NEAR = 0.01f;
public const float RL_CULL_DISTANCE_FAR = 1000.0f;
// Texture parameters (equivalent to OpenGL defines)
public const int RL_TEXTURE_WRAP_S = 0x2802;
public const int RL_TEXTURE_WRAP_T = 0x2803;
public const int RL_TEXTURE_MAG_FILTER = 0x2800;
public const int RL_TEXTURE_MIN_FILTER = 0x2801;
public const int RL_TEXTURE_ANISOTROPIC_FILTER = 0x3000;
public const int RL_FILTER_NEAREST = 0x2600;
public const int RL_FILTER_LINEAR = 0x2601;
public const int RL_FILTER_MIP_NEAREST = 0x2700;
public const int RL_FILTER_NEAREST_MIP_LINEAR = 0x2702;
public const int RL_FILTER_LINEAR_MIP_NEAREST = 0x2701;
public const int RL_FILTER_MIP_LINEAR = 0x2703;
public const int RL_WRAP_REPEAT = 0x2901;
public const int RL_WRAP_CLAMP = 0x812F;
public const int RL_WRAP_MIRROR_REPEAT = 0x8370;
public const int RL_WRAP_MIRROR_CLAMP = 0x8742;
public const int RL_TEXTURE_FILTER_NEAREST = 0x2600;
public const int RL_TEXTURE_FILTER_LINEAR = 0x2601;
public const int RL_TEXTURE_FILTER_MIP_NEAREST = 0x2700;
public const int RL_TEXTURE_FILTER_NEAREST_MIP_LINEAR = 0x2702;
public const int RL_TEXTURE_FILTER_LINEAR_MIP_NEAREST = 0x2701;
public const int RL_TEXTURE_FILTER_MIP_LINEAR = 0x2703;
public const int RL_TEXTURE_FILTER_ANISOTROPIC = 0x3000;
public const int RL_TEXTURE_WRAP_REPEAT = 0x2901;
public const int RL_TEXTURE_WRAP_CLAMP = 0x812F;
public const int RL_TEXTURE_WRAP_MIRROR_REPEAT = 0x8370;
public const int RL_TEXTURE_WRAP_MIRROR_CLAMP = 0x8742;
// Matrix modes (equivalent to OpenGL)
public const int RL_MODELVIEW = 0x1700;
public const int RL_PROJECTION = 0x1701;
public const int RL_TEXTURE = 0x1702;
// Primitive assembly draw modes
public const int RL_LINES = 0x0001;
public const int RL_TRIANGLES = 0x0004;
public const int RL_QUADS = 0x0007;
// GL equivalent data types
public const int RL_UNSIGNED_BYTE = 0x1401;
public const int RL_FLOAT = 0x1406;
// ------------------------------------------------------------------------------------
// Functions Declaration - Matrix operations
// ------------------------------------------------------------------------------------
@@ -123,6 +145,7 @@ namespace Raylib_cs
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlViewport(int x, int y, int width, int height);
// ------------------------------------------------------------------------------------
// Functions Declaration - Vertex level operations
// ------------------------------------------------------------------------------------
@@ -167,23 +190,88 @@ namespace Raylib_cs
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlColor4f(float x, float y, float z, float w);
// ------------------------------------------------------------------------------------
// Functions Declaration - OpenGL equivalent functions (common to 1.1, 3.3+, ES2)
// NOTE: This functions are used to completely abstract raylib code from OpenGL layer
// ------------------------------------------------------------------------------------
// Enable texture usage
// Vertex buffers state
// Enable vertex array (VAO, if supported)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool rlEnableVertexArray(uint vaoId);
// Disable vertex array (VAO, if supported)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableVertexArray();
// Enable vertex buffer (VBO)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableVertexBuffer(uint id);
// Disable vertex buffer (VBO)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableVertexBuffer();
// Enable vertex buffer element (VBO element)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableVertexBufferElement(uint id);
// Disable vertex buffer element (VBO element)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableVertexBufferElement();
// Enable vertex attribute index
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableVertexAttribute(uint index);
// Disable vertex attribute index
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableVertexAttribute(uint index);
// Textures state
// Select and active a texture slot
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlActiveTextureSlot(int slot);
// Enable texture
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableTexture(uint id);
// Disable texture usage
// Disable texture
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableTexture();
// Enable texture cubemap
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableTextureCubemap(uint id);
// Disable texture cubemap
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableTextureCubemap();
// Set texture parameters (filter, wrap)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlTextureParameters(uint id, int param, int value);
// Shader state
// Enable shader program
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableShader(uint id);
// Disable shader program
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableShader();
// Framebuffer state
// Enable render texture (fbo)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableFramebuffer(uint id);
@@ -192,6 +280,9 @@ namespace Raylib_cs
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableFramebuffer();
// General render state
// Enable depth test
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableDepthTest();
@@ -252,6 +343,19 @@ namespace Raylib_cs
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableSmoothLines();
// Enable stereo rendering
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableStereoRender();
// Disable stereo rendering
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableStereoRender();
// Check if stereo render is enabled
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool rlIsStereoRenderEnabled();
// Clear color buffer with color
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlClearColor(byte r, byte g, byte b, byte a);
@@ -260,15 +364,18 @@ namespace Raylib_cs
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlClearScreenBuffers();
// Update GPU buffer with new data
// data refers to a void *
// Check and log OpenGL error codes
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlUpdateBuffer(int bufferId, IntPtr data, int dataSize);
public static extern void rlCheckErrors();
// Load a new attributes buffer
// buffer refers to a void *
// Set blending mode
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint rlLoadAttribBuffer(uint vaoId, int shaderLoc, IntPtr buffer, int size, bool dynamic);
public static extern void rlSetBlendMode(int mode);
// Set blending mode factor and equation (using OpenGL factors)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetBlendModeFactors(int glSrcFactor, int glDstFactor, int glEquation);
// ------------------------------------------------------------------------------------
// Functions Declaration - rlgl functionality
@@ -282,35 +389,109 @@ namespace Raylib_cs
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlglClose();
// Update and draw default internal buffers
// Load OpenGL extensions
// loader refers to a void *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlglDraw();
// Check and log OpenGL error codes
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlCheckErrors();
public static extern void rlLoadExtensions(IntPtr loader);
// Returns current OpenGL version
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern GlVersion rlGetVersion();
// Get default framebuffer width
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int rlGetFramebufferWidth();
// Get default framebuffer height
[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();
// Render batch management
// Load a render batch system
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern RenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements);
// Unload render batch system
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlUnloadRenderBatch(RenderBatch batch);
// Draw render batch data (Update->Draw->Reset)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDrawRenderBatch(ref RenderBatch batch);
// Set the active render batch for rlgl (NULL for default internal)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetRenderBatchActive(ref RenderBatch batch);
// Update and draw internal render batch
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDrawRenderBatchActive();
// Check internal buffer overflow for a given number of vertex
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool rlCheckBufferLimit(int vCount);
public static extern bool rlCheckRenderBatchLimit(int vCount);
// Set debug marker for analysis
// Set current texture for render batch and check buffers limits
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetDebugMarker(string text);
public static extern void rlSetTexture(uint id);
// Set blending mode factor and equation (using OpenGL factors)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetBlendMode(int glSrcFactor, int glDstFactor, int glEquation);
// Load OpenGL extensions
// loader refers to a void *
// Vertex buffers management
// Load vertex array (vao) if supported
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlLoadExtensions(IntPtr loader);
public static extern uint rlLoadVertexArray();
// Load a vertex buffer attribute
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint rlLoadVertexBuffer(IntPtr buffer, int size, bool dynamic);
// Load a new attributes element buffer
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint rlLoadVertexBufferElement(IntPtr buffer, int size, bool dynamic);
// Update GPU buffer with new data
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlUpdateVertexBuffer(int bufferId, IntPtr data, int dataSize, int offset);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlUnloadVertexArray(uint vaoId);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlUnloadVertexBuffer(uint vboId);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetVertexAttribute(uint index, int compSize, int type, bool normalized, int stride, IntPtr pointer);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetVertexAttributeDivisor(uint index, int divisor);
// Set vertex attribute default value
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetVertexAttributeDefault(int locIndex, IntPtr value, int attribType, int count);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDrawVertexArray(int offset, int count);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDrawVertexArrayElements(int offset, int count, IntPtr buffer);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDrawVertexArrayInstanced(int offset, int count, int instances);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDrawVertexArrayElementsInstanced(int offset, int count, IntPtr buffer, int instances);
// Textures data management
@@ -322,7 +503,7 @@ namespace Raylib_cs
// Load depth texture/renderbuffer (to be attached to fbo)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint rlLoadTextureDepth(int width, int height, int bits, bool useRenderBuffer);
public static extern uint rlLoadTextureDepth(int width, int height, bool useRenderBuffer);
// Load texture cubemap
// data refers to a void *
@@ -352,8 +533,9 @@ namespace Raylib_cs
public static extern IntPtr rlReadTexturePixels(Texture2D texture);
// Read screen pixel data (color buffer)
// IntPtr refers to a unsigned char *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern byte[] rlReadScreenPixels(int width, int height);
public static extern IntPtr rlReadScreenPixels(int width, int height);
// Framebuffer management (fbo)
@@ -364,7 +546,7 @@ namespace Raylib_cs
// Attach texture/renderbuffer to a framebuffer
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlFramebufferAttach(uint fboId, uint texId, FramebufferAttachType attachType, FramebufferTexType texType);
public static extern void rlFramebufferAttach(uint fboId, uint texId, FramebufferAttachType attachType, FramebufferAttachTextureType texType, int mipLevel);
// Verify framebuffer is complete
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@@ -376,29 +558,97 @@ namespace Raylib_cs
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool rlUnloadFramebuffer(uint id);
// Vertex data management
// Upload vertex data into GPU and provided VAO/VBO ids
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlLoadMesh(ref Mesh mesh, bool dynamic);
// Update vertex or index data on GPU (upload new data to one buffer)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlUpdateMesh(Mesh mesh, int buffer, int num);
// Shaders management
// Update vertex or index data on GPU, at index
// Load shader from code strings
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlUpdateMeshAt(Mesh mesh, int buffer, int num, int index);
public static extern uint rlLoadShaderCode(string vsCode, string fsCode);
// Draw a 3d mesh with material and transform
// Compile custom shader and return shader id (type: GL_VERTEX_SHADER, GL_FRAGMENT_SHADER)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDrawMesh(Mesh mesh, Material material, Matrix4x4 transform);
public static extern uint rlCompileShader(string shaderCode, int type);
// Draw a 3d mesh with material and transform
// Load custom shader program
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDrawMeshInstanced(Mesh mesh, Material material, Matrix4x4[] transforms, int count);
public static extern uint rlLoadShaderProgram(uint vShaderId, uint fShaderId);
// Unload mesh data from CPU and GPU
// Unload shader program
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlUnloadMesh(Mesh mesh);
public static extern void rlUnloadShaderProgram(uint id);
// Get shader location uniform
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int rlGetLocationUniform(uint shaderId, string uniformName);
// Get shader location attribute
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int rlGetLocationAttrib(uint shaderId, string attribName);
// Set shader value uniform
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetUniform(int locIndex, IntPtr value, int uniformType, int count);
// Set shader value matrix
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetUniformMatrix(int locIndex, Matrix4x4 mat);
// Set shader value sampler
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetUniformSampler(int locIndex, uint textureId);
// Set shader currently active
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetShader(Shader shader);
// Matrix state management
// Get internal modelview matrix
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 rlGetMatrixModelView();
// Get internal projection matrix
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 rlGetMatrixProjection();
// Get internal accumulated transform matrix
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 rlGetMatrixTramsform();
// Get internal projection matrix for stereo render (selected eye)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 rlGetMatrixProjectionStereo(int eye);
// Get internal view offset matrix for stereo render (selected eye)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 rlGetMatrixViewOffsetStereo(int eye);
// Set a custom projection matrix (replaces internal projection matrix)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetMatrixProjection(Matrix4x4 view);
// Set a custom modelview matrix (replaces internal modelview matrix)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetMatrixModelView(Matrix4x4 proj);
// Set eyes projection matrices for stereo rendering
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetMatrixProjectionStereo(Matrix4x4 left, Matrix4x4 right);
// Set eyes view offsets matrices for stereo rendering
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetMatrixViewOffsetStereo(Matrix4x4 left, Matrix4x4 right);
// Quick and dirty cube/quad buffers load->draw->unload
// Load and draw a cube
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlLoadDrawCube();
// Load and draw a quad
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlLoadDrawQuad();
}
}