Move binding functions into interop folder
This commit is contained in:
parent
370ab8d9f3
commit
5e01171a42
5 changed files with 2 additions and 2 deletions
2115
Raylib-cs/interop/Raylib.cs
Normal file
2115
Raylib-cs/interop/Raylib.cs
Normal file
File diff suppressed because it is too large
Load diff
416
Raylib-cs/interop/Raymath.cs
Normal file
416
Raylib-cs/interop/Raymath.cs
Normal file
|
|
@ -0,0 +1,416 @@
|
|||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace Raylib_cs
|
||||
{
|
||||
// NOTE: Helper types to be used instead of array return types for *ToFloat functions
|
||||
public unsafe struct float3
|
||||
{
|
||||
public fixed float v[3];
|
||||
}
|
||||
|
||||
public unsafe struct float16
|
||||
{
|
||||
public fixed float v[16];
|
||||
}
|
||||
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
public static unsafe partial class Raymath
|
||||
{
|
||||
/// <summary>
|
||||
/// Used by DllImport to load the native library
|
||||
/// </summary>
|
||||
public const string nativeLibName = "raylib";
|
||||
|
||||
/// <summary>Clamp float value</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float Clamp(float value, float min, float max);
|
||||
|
||||
/// <summary>Calculate linear interpolation between two vectors</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float Lerp(float start, float end, float amount);
|
||||
|
||||
/// <summary>Normalize input value within input range</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float Normalize(float value, float start, float end);
|
||||
|
||||
/// <summary>Remap input value within input range to output range</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float Remap(float value, float inputStart, float inputEnd, float outputStart, float outputEnd);
|
||||
|
||||
|
||||
/// <summary>Vector with components value 0.0f</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector2 Vector2Zero();
|
||||
|
||||
/// <summary>Vector with components value 1.0f</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector2 Vector2One();
|
||||
|
||||
/// <summary>Add two vectors (v1 + v2)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector2 Vector2Add(Vector2 v1, Vector2 v2);
|
||||
|
||||
/// <summary>Add vector and float value</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector2 Vector2AddValue(Vector2 v, float add);
|
||||
|
||||
/// <summary>Subtract two vectors (v1 - v2)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector2 Vector2Subtract(Vector2 v1, Vector2 v2);
|
||||
|
||||
/// <summary>Subtract vector by float value</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector2 Vector2SubtractValue(Vector2 v, float sub);
|
||||
|
||||
/// <summary>Calculate vector length</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float Vector2Length(Vector2 v);
|
||||
|
||||
/// <summary>Calculate vector square length</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float Vector2LengthSqr(Vector2 v);
|
||||
|
||||
/// <summary>Calculate two vectors dot product</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float Vector2DotProduct(Vector2 v1, Vector2 v2);
|
||||
|
||||
/// <summary>Calculate distance between two vectors</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float Vector2Distance(Vector2 v1, Vector2 v2);
|
||||
|
||||
/// <summary>Calculate angle from two vectors in X-axis</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float Vector2Angle(Vector2 v1, Vector2 v2);
|
||||
|
||||
/// <summary>Scale vector (multiply by value)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector2 Vector2Scale(Vector2 v, float scale);
|
||||
|
||||
/// <summary>Multiply vector by vector</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector2 Vector2Multiply(Vector2 v1, Vector2 v2);
|
||||
|
||||
/// <summary>Negate vector</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector2 Vector2Negate(Vector2 v);
|
||||
|
||||
/// <summary>Divide vector by vector</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector2 Vector2Divide(Vector2 v1, Vector2 v2);
|
||||
|
||||
/// <summary>Normalize provided vector</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector2 Vector2Normalize(Vector2 v);
|
||||
|
||||
/// <summary>Calculate linear interpolation between two vectors</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector2 Vector2Lerp(Vector2 v1, Vector2 v2, float amount);
|
||||
|
||||
/// <summary>Calculate linear interpolation between two vectors</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector2 Vector2Rotate(Vector2 v, float degs);
|
||||
|
||||
|
||||
/// <summary>Vector with components value 0.0f</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector3 Vector3Zero();
|
||||
|
||||
/// <summary>Vector with components value 1.0f</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector3 Vector3One();
|
||||
|
||||
/// <summary>Add two vectors</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector3 Vector3Add(Vector3 v1, Vector3 v2);
|
||||
|
||||
/// <summary>Add vector and float value</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector3 Vector3AddValue(Vector3 v, float add);
|
||||
|
||||
/// <summary>Subtract two vectors</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector3 Vector3Subtract(Vector3 v1, Vector3 v2);
|
||||
|
||||
/// <summary>Subtract vector and float value</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector3 Vector3SubtractValue(Vector3 v, float sub);
|
||||
|
||||
/// <summary>Multiply vector by scalar</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector3 Vector3Scale(Vector3 v, float scalar);
|
||||
|
||||
/// <summary>Multiply vector by vector</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector3 Vector3Multiply(Vector3 v1, Vector3 v2);
|
||||
|
||||
/// <summary>Calculate two vectors cross product</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector3 Vector3CrossProduct(Vector3 v1, Vector3 v2);
|
||||
|
||||
/// <summary>Calculate one vector perpendicular vector</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector3 Vector3Perpendicular(Vector3 v);
|
||||
|
||||
/// <summary>Calculate vector length</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float Vector3Length(Vector3 v);
|
||||
|
||||
/// <summary>Calculate vector square length</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float Vector3LengthSqr(Vector3 v);
|
||||
|
||||
/// <summary>Calculate two vectors dot product</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float Vector3DotProduct(Vector3 v1, Vector3 v2);
|
||||
|
||||
/// <summary>Calculate distance between two vectors</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float Vector3Distance(Vector3 v1, Vector3 v2);
|
||||
|
||||
/// <summary>Calculate angle between two vectors in XY and XZ</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector2 Vector3Angle(Vector3 v1, Vector3 v2);
|
||||
|
||||
/// <summary>Negate provided vector (invert direction)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector3 Vector3Negate(Vector3 v);
|
||||
|
||||
/// <summary>Divide vector by vector</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector3 Vector3Divide(Vector3 v1, Vector3 v2);
|
||||
|
||||
/// <summary>Normalize provided vector</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector3 Vector3Normalize(Vector3 v);
|
||||
|
||||
/// <summary>Orthonormalize provided vectors<br/>
|
||||
/// Makes vectors normalized and orthogonal to each other<br/>
|
||||
/// Gram-Schmidt function implementation</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void Vector3OrthoNormalize(Vector3* v1, Vector3* v2);
|
||||
|
||||
/// <summary>Transforms a Vector3 by a given Matrix</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector3 Vector3Transform(Vector3 v, Matrix4x4 mat);
|
||||
|
||||
/// <summary>Transform a vector by quaternion rotation</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector3 Vector3RotateByQuaternion(Vector3 v, Quaternion q);
|
||||
|
||||
/// <summary>Calculate linear interpolation between two vectors</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float amount);
|
||||
|
||||
/// <summary>Calculate reflected vector to normal</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector3 Vector3Reflect(Vector3 v, Vector3 normal);
|
||||
|
||||
/// <summary>Return min value for each pair of components</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector3 Vector3Min(Vector3 v1, Vector3 v2);
|
||||
|
||||
/// <summary>Return max value for each pair of components</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector3 Vector3Max(Vector3 v1, Vector3 v2);
|
||||
|
||||
/// <summary>Compute barycenter coordinates (u, v, w) for point p with respect to triangle (a, b, c)<br/>
|
||||
/// NOTE: Assumes P is on the plane of the triangle</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector3 Vector3Barycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c);
|
||||
|
||||
/// <summary>Projects a Vector3 from screen space into object space<br/>
|
||||
/// NOTE: We are avoiding calling other raymath functions despite available</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector3 Vector3Unproject(Vector3 source, Matrix4x4 projection, Matrix4x4 view);
|
||||
|
||||
/// <summary>Get Vector3 as float array</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float3 Vector3ToFloatV(Vector3 v);
|
||||
|
||||
|
||||
/// <summary>Compute matrix determinant</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float MatrixDeterminant(Matrix4x4 mat);
|
||||
|
||||
/// <summary>Get the trace of the matrix (sum of the values along the diagonal)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float MatrixTrace(Matrix4x4 mat);
|
||||
|
||||
/// <summary>Transposes provided matrix</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 MatrixTranspose(Matrix4x4 mat);
|
||||
|
||||
/// <summary>Invert provided matrix</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 MatrixInvert(Matrix4x4 mat);
|
||||
|
||||
/// <summary>Normalize provided matrix</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 MatrixNormalize(Matrix4x4 mat);
|
||||
|
||||
/// <summary>Get identity matrix</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 MatrixIdentity();
|
||||
|
||||
/// <summary>Add two matrices</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 MatrixAdd(Matrix4x4 left, Matrix4x4 right);
|
||||
|
||||
/// <summary>Subtract two matrices (left - right)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 MatrixSubtract(Matrix4x4 left, Matrix4x4 right);
|
||||
|
||||
/// <summary>Get two matrix multiplication<br/>
|
||||
/// NOTE: When multiplying matrices... the order matters!</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 MatrixMultiply(Matrix4x4 left, Matrix4x4 right);
|
||||
|
||||
/// <summary>Get translation matrix</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 MatrixTranslate(float x, float y, float z);
|
||||
|
||||
/// <summary>Create rotation matrix from axis and angle<br/>
|
||||
/// NOTE: Angle should be provided in radians</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 MatrixRotate(Vector3 axis, float angle);
|
||||
|
||||
/// <summary>Get x-rotation matrix (angle in radians)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 MatrixRotateX(float angle);
|
||||
|
||||
/// <summary>Get y-rotation matrix (angle in radians)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 MatrixRotateY(float angle);
|
||||
|
||||
/// <summary>Get z-rotation matrix (angle in radians)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 MatrixRotateZ(float angle);
|
||||
|
||||
/// <summary>Get xyz-rotation matrix (angles in radians)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 MatrixRotateXYZ(Vector3 ang);
|
||||
|
||||
/// <summary>Get zyx-rotation matrix (angles in radians)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 MatrixRotateZYX(Vector3 ang);
|
||||
|
||||
/// <summary>Get scaling matrix</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 MatrixScale(float x, float y, float z);
|
||||
|
||||
/// <summary>Get perspective projection matrix</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 MatrixFrustum(double left, double right, double bottom, double top, double near, double far);
|
||||
|
||||
/// <summary>Get perspective projection matrix<br/>
|
||||
/// NOTE: Angle should be provided in radians</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 MatrixPerspective(double fovy, double aspect, double near, double far);
|
||||
|
||||
/// <summary>Get orthographic projection matrix</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 MatrixOrtho(double left, double right, double bottom, double top, double near, double far);
|
||||
|
||||
/// <summary>Get camera look-at matrix (view matrix)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up);
|
||||
|
||||
/// <summary>Get float array of matrix data</summary>
|
||||
[DllImport(Raylib.nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float16 MatrixToFloatV(Matrix4x4 m);
|
||||
|
||||
|
||||
/// <summary>Add 2 quaternions</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Quaternion QuaternionAdd(Quaternion q1, Quaternion q2);
|
||||
|
||||
/// <summary>Add quaternion and float value</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Quaternion QuaternionAddValue(Quaternion q, float add);
|
||||
|
||||
/// <summary>Subtract 2 quaternions</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Quaternion QuaternionSubtract(Quaternion q1, Quaternion q2);
|
||||
|
||||
/// <summary>Subtract quaternion and float value</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Quaternion QuaternionSubtractValue(Quaternion q, float add);
|
||||
|
||||
/// <summary>Get identity quaternion</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Quaternion QuaternionIdentity();
|
||||
|
||||
/// <summary>Computes the length of a quaternion</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float QuaternionLength(Quaternion q);
|
||||
|
||||
/// <summary>Normalize provided quaternion</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Quaternion QuaternionNormalize(Quaternion q);
|
||||
|
||||
/// <summary>Invert provided quaternion</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Quaternion QuaternionInvert(Quaternion q);
|
||||
|
||||
/// <summary>Calculate two quaternion multiplication</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Quaternion QuaternionMultiply(Quaternion q1, Quaternion q2);
|
||||
|
||||
/// <summary>Scale quaternion by float value</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Quaternion QuaternionScale(Quaternion q, float mul);
|
||||
|
||||
/// <summary>Divide two quaternions</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Quaternion QuaternionDivide(Quaternion q1, Quaternion q2);
|
||||
|
||||
/// <summary>Calculate linear interpolation between two quaternions</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Quaternion QuaternionLerp(Quaternion q1, Quaternion q2, float amount);
|
||||
|
||||
/// <summary>Calculate slerp-optimized interpolation between two quaternions</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Quaternion QuaternionNlerp(Quaternion q1, Quaternion q2, float amount);
|
||||
|
||||
/// <summary>Calculates spherical linear interpolation between two quaternions</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount);
|
||||
|
||||
/// <summary>Calculate quaternion based on the rotation from one vector to another</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Quaternion QuaternionFromVector3ToVector3(Vector3 from, Vector3 to);
|
||||
|
||||
/// <summary>Get a quaternion for a given rotation matrix</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Quaternion QuaternionFromMatrix(Matrix4x4 mat);
|
||||
|
||||
/// <summary>Get a matrix for a given quaternion</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 QuaternionToMatrix(Quaternion q);
|
||||
|
||||
/// <summary>Get rotation quaternion for an angle and axis<br/>
|
||||
/// NOTE: angle must be provided in radians</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle);
|
||||
|
||||
/// <summary>Get the rotation angle and axis for a given quaternion</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void QuaternionToAxisAngle(Quaternion q, Vector3* outAxis, float* outAngle);
|
||||
|
||||
/// <summary>Get the quaternion equivalent to Euler angles<br/>
|
||||
/// NOTE: Rotation order is ZYX</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Quaternion QuaternionFromEuler(float pitch, float yaw, float roll);
|
||||
|
||||
/// <summary>Get the Euler angles equivalent to quaternion (roll, pitch, yaw)<br/>
|
||||
/// NOTE: Angles are returned in a Vector3 struct in radians</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector3 QuaternionToEuler(Quaternion q);
|
||||
|
||||
/// <summary>Transform a quaternion given a transformation matrix</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Quaternion QuaternionTransform(Quaternion q, Matrix4x4 mat);
|
||||
}
|
||||
}
|
||||
699
Raylib-cs/interop/Rlgl.cs
Normal file
699
Raylib-cs/interop/Rlgl.cs
Normal file
|
|
@ -0,0 +1,699 @@
|
|||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace Raylib_cs
|
||||
{
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
public static unsafe partial class Rlgl
|
||||
{
|
||||
/// <summary>
|
||||
/// Used by DllImport to load the native library
|
||||
/// </summary>
|
||||
public const string nativeLibName = "raylib";
|
||||
|
||||
public const int DEFAULT_BATCH_BUFFER_ELEMENTS = 8192;
|
||||
public const int DEFAULT_BATCH_BUFFERS = 1;
|
||||
public const int DEFAULT_BATCH_DRAWCALLS = 256;
|
||||
public const int MAX_BATCH_ACTIVE_TEXTURES = 4;
|
||||
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_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;
|
||||
|
||||
|
||||
// GL equivalent data types
|
||||
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;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------
|
||||
// Functions Declaration - Matrix operations
|
||||
// ------------------------------------------------------------------------------------
|
||||
|
||||
/// <summary>Choose the current matrix to be transformed</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlMatrixMode(int mode);
|
||||
|
||||
public static void rlMatrixMode(MatrixMode mode)
|
||||
{
|
||||
rlMatrixMode((int)mode);
|
||||
}
|
||||
|
||||
/// <summary>Push the current matrix to stack</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlPushMatrix();
|
||||
|
||||
/// <summary>Pop lattest inserted matrix from stack</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlPopMatrix();
|
||||
|
||||
/// <summary>Reset current matrix to identity matrix</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlLoadIdentity();
|
||||
|
||||
/// <summary>Multiply the current matrix by a translation matrix</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlTranslatef(float x, float y, float z);
|
||||
|
||||
/// <summary>Multiply the current matrix by a rotation matrix</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlRotatef(float angle, float x, float y, float z);
|
||||
|
||||
/// <summary>Multiply the current matrix by a scaling matrix</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlScalef(float x, float y, float z);
|
||||
|
||||
/// <summary>
|
||||
/// Multiply the current matrix by another matrix
|
||||
/// <br/>
|
||||
/// Current Matrix can be set via <see cref="rlMatrixMode(int)"/>
|
||||
/// </summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlMultMatrixf(float* matf);
|
||||
|
||||
/// <inheritdoc cref="rlMultMatrixf(float*)"/>
|
||||
public static void rlMultMatrixf(Matrix4x4 matf)
|
||||
{
|
||||
float16 f = Raymath.MatrixToFloatV(matf);
|
||||
rlMultMatrixf(f.v);
|
||||
}
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlFrustum(double left, double right, double bottom, double top, double znear, double zfar);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlOrtho(double left, double right, double bottom, double top, double znear, double zfar);
|
||||
|
||||
/// <summary>Set the viewport area</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlViewport(int x, int y, int width, int height);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------
|
||||
// Functions Declaration - Vertex level operations
|
||||
// ------------------------------------------------------------------------------------
|
||||
|
||||
/// <summary>Initialize drawing mode (how to organize vertex)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlBegin(int mode);
|
||||
|
||||
public static void rlBegin(DrawMode mode)
|
||||
{
|
||||
rlBegin((int)mode);
|
||||
}
|
||||
|
||||
/// <summary>Finish vertex providing</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlEnd();
|
||||
|
||||
/// <summary>Define one vertex (position) - 2 int</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlVertex2i(int x, int y);
|
||||
|
||||
/// <summary>Define one vertex (position) - 2 float</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlVertex2f(float x, float y);
|
||||
|
||||
/// <summary>Define one vertex (position) - 3 float</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlVertex3f(float x, float y, float z);
|
||||
|
||||
/// <summary>Define one vertex (texture coordinate) - 2 float</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlTexCoord2f(float x, float y);
|
||||
|
||||
/// <summary>Define one vertex (normal) - 3 float</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlNormal3f(float x, float y, float z);
|
||||
|
||||
/// <summary>Define one vertex (color) - 4 byte</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlColor4ub(byte r, byte g, byte b, byte a);
|
||||
|
||||
/// <summary>Define one vertex (color) - 3 float</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlColor3f(float x, float y, float z);
|
||||
|
||||
/// <summary>Define one vertex (color) - 4 float</summary>
|
||||
[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
|
||||
// ------------------------------------------------------------------------------------
|
||||
|
||||
/// <summary>Vertex buffers state</summary>
|
||||
|
||||
/// <summary>Enable vertex array (VAO, if supported)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern CBool rlEnableVertexArray(uint vaoId);
|
||||
|
||||
/// <summary>Disable vertex array (VAO, if supported)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlDisableVertexArray();
|
||||
|
||||
/// <summary>Enable vertex buffer (VBO)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlEnableVertexBuffer(uint id);
|
||||
|
||||
/// <summary>Disable vertex buffer (VBO)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlDisableVertexBuffer();
|
||||
|
||||
/// <summary>Enable vertex buffer element (VBO element)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlEnableVertexBufferElement(uint id);
|
||||
|
||||
/// <summary>Disable vertex buffer element (VBO element)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlDisableVertexBufferElement();
|
||||
|
||||
/// <summary>Enable vertex attribute index</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlEnableVertexAttribute(uint index);
|
||||
|
||||
/// <summary>Disable vertex attribute index</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlDisableVertexAttribute(uint index);
|
||||
|
||||
/// <summary>Enable attribute state pointer<br/>
|
||||
/// NOTE: Only available for GRAPHICS_API_OPENGL_11</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlEnableStatePointer(int vertexAttribType, void* buffer);
|
||||
|
||||
/// <summary>Disable attribute state pointer<br/>
|
||||
/// NOTE: Only available for GRAPHICS_API_OPENGL_11</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlDisableStatePointer(int vertexAttribType);
|
||||
|
||||
|
||||
// Textures state
|
||||
|
||||
/// <summary>Select and active a texture slot</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlActiveTextureSlot(int slot);
|
||||
|
||||
/// <summary>Enable texture</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlEnableTexture(uint id);
|
||||
|
||||
/// <summary>Disable texture</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlDisableTexture();
|
||||
|
||||
/// <summary>Enable texture cubemap</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlEnableTextureCubemap(uint id);
|
||||
|
||||
/// <summary>Disable texture cubemap</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlDisableTextureCubemap();
|
||||
|
||||
/// <summary>Set texture parameters (filter, wrap)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlTextureParameters(uint id, int param, int value);
|
||||
|
||||
|
||||
// Shader state
|
||||
|
||||
/// <summary>Enable shader program</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlEnableShader(uint id);
|
||||
|
||||
/// <summary>Disable shader program</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlDisableShader();
|
||||
|
||||
|
||||
// Framebuffer state
|
||||
|
||||
/// <summary>Enable render texture (fbo)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlEnableFramebuffer(uint id);
|
||||
|
||||
/// <summary>Disable render texture (fbo), return to default framebuffer</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlDisableFramebuffer();
|
||||
|
||||
/// <summary>Activate multiple draw color buffers</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlActiveDrawBuffers(int count);
|
||||
|
||||
|
||||
// General render state
|
||||
|
||||
/// <summary>Enable color blending</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlEnableColorBlend();
|
||||
|
||||
/// <summary>Disable color blending</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlDisableColorBlend();
|
||||
|
||||
/// <summary>Enable depth test</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlEnableDepthTest();
|
||||
|
||||
/// <summary>Disable depth test</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlDisableDepthTest();
|
||||
|
||||
/// <summary>Enable depth write</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlEnableDepthMask();
|
||||
|
||||
/// <summary>Disable depth write</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlDisableDepthMask();
|
||||
|
||||
/// <summary>Enable backface culling</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlEnableBackfaceCulling();
|
||||
|
||||
/// <summary>Disable backface culling</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlDisableBackfaceCulling();
|
||||
|
||||
/// <summary>Enable scissor test</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlEnableScissorTest();
|
||||
|
||||
/// <summary>Disable scissor test</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlDisableScissorTest();
|
||||
|
||||
/// <summary>Scissor test</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlScissor(int x, int y, int width, int height);
|
||||
|
||||
/// <summary>Enable wire mode</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlEnableWireMode();
|
||||
|
||||
/// <summary>Disable wire mode</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlDisableWireMode();
|
||||
|
||||
/// <summary>Set the line drawing width</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlSetLineWidth(float width);
|
||||
|
||||
/// <summary>Get the line drawing width</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float rlGetLineWidth();
|
||||
|
||||
/// <summary>Enable line aliasing</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlEnableSmoothLines();
|
||||
|
||||
/// <summary>Disable line aliasing</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlDisableSmoothLines();
|
||||
|
||||
/// <summary>Enable stereo rendering</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlEnableStereoRender();
|
||||
|
||||
/// <summary>Disable stereo rendering</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlDisableStereoRender();
|
||||
|
||||
/// <summary>Check if stereo render is enabled</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern CBool rlIsStereoRenderEnabled();
|
||||
|
||||
/// <summary>Clear color buffer with color</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlClearColor(byte r, byte g, byte b, byte a);
|
||||
|
||||
/// <summary>Clear used screen buffers (color and depth)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlClearScreenBuffers();
|
||||
|
||||
/// <summary>Check and log OpenGL error codes</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlCheckErrors();
|
||||
|
||||
/// <summary>Set blending mode</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlSetBlendMode(BlendMode mode);
|
||||
|
||||
/// <summary>Set blending mode factor and equation (using OpenGL factors)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlSetBlendFactors(int glSrcFactor, int glDstFactor, int glEquation);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------
|
||||
// Functions Declaration - rlgl functionality
|
||||
// ------------------------------------------------------------------------------------
|
||||
|
||||
/// <summary>Initialize rlgl (buffers, shaders, textures, states)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlglInit(int width, int height);
|
||||
|
||||
/// <summary>De-inititialize rlgl (buffers, shaders, textures)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlglClose();
|
||||
|
||||
/// <summary>Load OpenGL extensions</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlLoadExtensions(void* loader);
|
||||
|
||||
/// <summary>Get current OpenGL version</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern GlVersion rlGetVersion();
|
||||
|
||||
/// <summary>Get default framebuffer width</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int rlGetFramebufferWidth();
|
||||
|
||||
/// <summary>Get default framebuffer height</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int rlGetFramebufferHeight();
|
||||
|
||||
/// <summary>Get default texture</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint rlGetTextureIdDefault();
|
||||
|
||||
/// <summary>Get default shader</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint rlGetShaderIdDefault();
|
||||
|
||||
/// <summary>Get default shader locations</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int* rlGetShaderLocsDefault();
|
||||
|
||||
// Render batch management
|
||||
|
||||
/// <summary>Load a render batch system<br/>
|
||||
/// NOTE: rlgl provides a default render batch to behave like OpenGL 1.1 immediate mode<br/>
|
||||
/// but this render batch API is exposed in case custom batches are required</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern RenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements);
|
||||
|
||||
/// <summary>Unload render batch system</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlUnloadRenderBatch(RenderBatch batch);
|
||||
|
||||
/// <summary>Draw render batch data (Update->Draw->Reset)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlDrawRenderBatch(RenderBatch* batch);
|
||||
|
||||
/// <summary>Set the active render batch for rlgl (NULL for default internal)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlSetRenderBatchActive(RenderBatch* batch);
|
||||
|
||||
/// <summary>Update and draw internal render batch</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlDrawRenderBatchActive();
|
||||
|
||||
/// <summary>Check internal buffer overflow for a given number of vertex</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern CBool rlCheckRenderBatchLimit(int vCount);
|
||||
|
||||
/// <summary>Set current texture for render batch and check buffers limits</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlSetTexture(uint id);
|
||||
|
||||
|
||||
// Vertex buffers management
|
||||
|
||||
/// <summary>Load vertex array (vao) if supported</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint rlLoadVertexArray();
|
||||
|
||||
/// <summary>Load a vertex buffer attribute</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint rlLoadVertexBuffer(void* buffer, int size, CBool dynamic);
|
||||
|
||||
/// <summary>Load a new attributes element buffer</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint rlLoadVertexBufferElement(void* buffer, int size, CBool dynamic);
|
||||
|
||||
/// <summary>Update GPU buffer with new data</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlUpdateVertexBuffer(uint bufferId, void* 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, CBool normalized, int stride, void* pointer);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlSetVertexAttributeDivisor(uint index, int divisor);
|
||||
|
||||
/// <summary>Set vertex attribute default value</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlSetVertexAttributeDefault(int locIndex, void* 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, void* 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, void* buffer, int instances);
|
||||
|
||||
|
||||
// Textures data management
|
||||
|
||||
/// <summary>Load texture in GPU</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint rlLoadTexture(void* data, int width, int height, PixelFormat format, int mipmapCount);
|
||||
|
||||
/// <summary>Load depth texture/renderbuffer (to be attached to fbo)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint rlLoadTextureDepth(int width, int height, CBool useRenderBuffer);
|
||||
|
||||
/// <summary>Load texture cubemap</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint rlLoadTextureCubemap(void* data, int size, PixelFormat format);
|
||||
|
||||
/// <summary>Update GPU texture with new data</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlUpdateTexture(uint id, int width, int height, PixelFormat format, void* data);
|
||||
|
||||
/// <summary>Get OpenGL internal formats</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlGetGlTextureFormats(PixelFormat format, int* glInternalFormat, int* glFormat, int* glType);
|
||||
|
||||
/// <summary>Get OpenGL internal formats</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern sbyte* rlGetPixelFormatName(PixelFormat format);
|
||||
|
||||
/// <summary>Unload texture from GPU memory</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlUnloadTexture(uint id);
|
||||
|
||||
/// <summary>Generate mipmap data for selected texture</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlGenTextureMipmaps(uint id, int width, int height, PixelFormat format, int* mipmaps);
|
||||
|
||||
/// <summary>Read texture pixel data</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void* rlReadTexturePixels(uint id, int width, int height, PixelFormat format);
|
||||
|
||||
/// <summary>Read screen pixel data (color buffer)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern byte* rlReadScreenPixels(int width, int height);
|
||||
|
||||
|
||||
// Framebuffer management (fbo)
|
||||
|
||||
/// <summary>Load an empty framebuffer</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint rlLoadFramebuffer(int width, int height);
|
||||
|
||||
/// <summary>Attach texture/renderbuffer to a framebuffer</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlFramebufferAttach(uint fboId, uint texId, FramebufferAttachType attachType, FramebufferAttachTextureType texType, int mipLevel);
|
||||
|
||||
/// <summary>Verify framebuffer is complete</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern CBool rlFramebufferComplete(uint id);
|
||||
|
||||
/// <summary>Delete framebuffer from GPU</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern CBool rlUnloadFramebuffer(uint id);
|
||||
|
||||
|
||||
// Shaders management
|
||||
|
||||
/// <summary>Load shader from code strings</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint rlLoadShaderCode(sbyte* vsCode, sbyte* fsCode);
|
||||
|
||||
/// <summary>Compile custom shader and return shader id<br/>
|
||||
/// (type: RL_VERTEX_SHADER, RL_FRAGMENT_SHADER, RL_COMPUTE_SHADER)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint rlCompileShader(sbyte* shaderCode, int type);
|
||||
|
||||
/// <summary>Load custom shader program</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint rlLoadShaderProgram(uint vShaderId, uint fShaderId);
|
||||
|
||||
/// <summary>Unload shader program</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlUnloadShaderProgram(uint id);
|
||||
|
||||
/// <summary>Get shader location uniform</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int rlGetLocationUniform(uint shaderId, sbyte* uniformName);
|
||||
|
||||
/// <summary>Get shader location attribute</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int rlGetLocationAttrib(uint shaderId, sbyte* attribName);
|
||||
|
||||
/// <summary>Set shader value uniform</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlSetUniform(int locIndex, void* value, int uniformType, int count);
|
||||
|
||||
/// <summary>Set shader value matrix</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlSetUniformMatrix(int locIndex, Matrix4x4 mat);
|
||||
|
||||
/// <summary>Set shader value sampler</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlSetUniformSampler(int locIndex, uint textureId);
|
||||
|
||||
/// <summary>Set shader currently active</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlSetShader(Shader shader);
|
||||
|
||||
|
||||
// Compute shader management
|
||||
|
||||
/// <summary>Load compute shader program</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint rlLoadComputeShaderProgram(uint shaderId);
|
||||
|
||||
/// <summary>Dispatch compute shader (equivalent to *draw* for graphics pilepine)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlComputeShaderDispatch(uint groupX, uint groupY, uint groupZ);
|
||||
|
||||
/// <summary>Load shader storage buffer object (SSBO)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint rlLoadShaderBuffer(ulong size, void* data, int usageHint);
|
||||
|
||||
/// <summary>Unload shader storage buffer object (SSBO)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlUnloadShaderBuffer(uint ssboId);
|
||||
|
||||
/// <summary>Update SSBO buffer data</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlUpdateShaderBufferElements(Shader shader);
|
||||
|
||||
/// <summary>Get SSBO buffer size</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern ulong rlGetShaderBufferSize(uint id, void* dest, ulong count, ulong offset);
|
||||
|
||||
/// <summary>Bind SSBO buffer</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlReadShaderBufferElements(uint id, void* dest, ulong count, ulong offset);
|
||||
|
||||
/// <summary> Copy SSBO buffer data</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlBindShaderBuffer(uint id, uint index);
|
||||
|
||||
|
||||
// Buffer management
|
||||
|
||||
/// <summary>Copy SSBO buffer data</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlCopyBuffersElements(uint destId, uint srcId, ulong destOffset, ulong srcOffset, ulong count);
|
||||
|
||||
/// <summary>Bind image texture</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlBindImageTexture(uint id, uint index, uint format, int readOnly);
|
||||
|
||||
|
||||
// Matrix state management
|
||||
|
||||
/// <summary>Get internal modelview matrix</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 rlGetMatrixModelview();
|
||||
|
||||
/// <summary>Get internal projection matrix</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 rlGetMatrixProjection();
|
||||
|
||||
/// <summary>Get internal accumulated transform matrix</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 rlGetMatrixTramsform();
|
||||
|
||||
/// <summary>Get internal projection matrix for stereo render (selected eye)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 rlGetMatrixProjectionStereo(int eye);
|
||||
|
||||
/// <summary>Get internal view offset matrix for stereo render (selected eye)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Matrix4x4 rlGetMatrixViewOffsetStereo(int eye);
|
||||
|
||||
/// <summary>Set a custom projection matrix (replaces internal projection matrix)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlSetMatrixProjection(Matrix4x4 view);
|
||||
|
||||
/// <summary>Set a custom modelview matrix (replaces internal modelview matrix)</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlSetMatrixModelview(Matrix4x4 proj);
|
||||
|
||||
/// <summary>Set eyes projection matrices for stereo rendering</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlSetMatrixProjectionStereo(Matrix4x4 left, Matrix4x4 right);
|
||||
|
||||
/// <summary>Set eyes view offsets matrices for stereo rendering</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlSetMatrixViewOffsetStereo(Matrix4x4 left, Matrix4x4 right);
|
||||
|
||||
|
||||
// Quick and dirty cube/quad buffers load->draw->unload
|
||||
|
||||
/// <summary>Load and draw a cube</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlLoadDrawCube();
|
||||
|
||||
/// <summary>Load and draw a quad</summary>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void rlLoadDrawQuad();
|
||||
}
|
||||
}
|
||||
166
Raylib-cs/types/Logging.cs
Normal file
166
Raylib-cs/types/Logging.cs
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Raylib_cs
|
||||
{
|
||||
internal readonly struct Native
|
||||
{
|
||||
internal const string Msvcrt = "msvcrt";
|
||||
internal const string Libc = "libc";
|
||||
internal const string LibSystem = "libSystem";
|
||||
|
||||
[DllImport(LibSystem, EntryPoint = "vasprintf", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int vasprintf_apple(ref IntPtr buffer, IntPtr format, IntPtr args);
|
||||
|
||||
[DllImport(Libc, EntryPoint = "vsprintf", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int vsprintf_linux(IntPtr buffer, IntPtr format, IntPtr args);
|
||||
|
||||
[DllImport(Msvcrt, EntryPoint = "vsprintf", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int vsprintf_windows(IntPtr buffer, IntPtr format, IntPtr args);
|
||||
|
||||
[DllImport(Libc, EntryPoint = "vsnprintf", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int vsnprintf_linux(IntPtr buffer, UIntPtr size, IntPtr format, IntPtr args);
|
||||
|
||||
[DllImport(Msvcrt, EntryPoint = "vsnprintf", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int vsnprintf_windows(IntPtr buffer, UIntPtr size, IntPtr format, IntPtr args);
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 4)]
|
||||
struct VaListLinuxX64
|
||||
{
|
||||
uint gpOffset;
|
||||
uint fpOffset;
|
||||
IntPtr overflowArgArea;
|
||||
IntPtr regSaveArea;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Logging workaround for formatting strings from native code
|
||||
/// </summary>
|
||||
public static unsafe class Logging
|
||||
{
|
||||
static Logging()
|
||||
{
|
||||
Raylib.SetTraceLogCallback(&LogConsole);
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static unsafe void LogConsole(int msgType, sbyte* text, sbyte* args)
|
||||
{
|
||||
var message = GetLogMessage(new IntPtr(text), new IntPtr(args));
|
||||
Console.WriteLine(message);
|
||||
}
|
||||
|
||||
public static string GetLogMessage(IntPtr format, IntPtr args)
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
return AppleLogCallback(format, args);
|
||||
}
|
||||
|
||||
// Special marshalling is needed on Linux desktop 64 bits.
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && IntPtr.Size == 8)
|
||||
{
|
||||
return LinuxX64LogCallback(format, args);
|
||||
}
|
||||
|
||||
var byteLength = vsnprintf(IntPtr.Zero, UIntPtr.Zero, format, args) + 1;
|
||||
if (byteLength <= 1)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var buffer = Marshal.AllocHGlobal(byteLength);
|
||||
vsprintf(buffer, format, args);
|
||||
|
||||
string result = Marshal.PtrToStringUTF8(buffer);
|
||||
Marshal.FreeHGlobal(buffer);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static string AppleLogCallback(IntPtr format, IntPtr args)
|
||||
{
|
||||
IntPtr buffer = IntPtr.Zero;
|
||||
try
|
||||
{
|
||||
var count = Native.vasprintf_apple(ref buffer, format, args);
|
||||
if (count == -1)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
return Marshal.PtrToStringUTF8(buffer) ?? string.Empty;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.FreeHGlobal(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
static string LinuxX64LogCallback(IntPtr format, IntPtr args)
|
||||
{
|
||||
// The args pointer cannot be reused between two calls. We need to make a copy of the underlying structure.
|
||||
var listStructure = Marshal.PtrToStructure<VaListLinuxX64>(args);
|
||||
IntPtr listPointer = IntPtr.Zero;
|
||||
int byteLength = 0;
|
||||
string result = "";
|
||||
|
||||
// Get length of args
|
||||
listPointer = Marshal.AllocHGlobal(Marshal.SizeOf(listStructure));
|
||||
Marshal.StructureToPtr(listStructure, listPointer, false);
|
||||
byteLength = Native.vsnprintf_linux(IntPtr.Zero, UIntPtr.Zero, format, listPointer) + 1;
|
||||
|
||||
// Allocate buffer for result
|
||||
Marshal.StructureToPtr(listStructure, listPointer, false);
|
||||
|
||||
IntPtr utf8Buffer = IntPtr.Zero;
|
||||
utf8Buffer = Marshal.AllocHGlobal(byteLength);
|
||||
|
||||
// Print result into buffer
|
||||
Native.vsprintf_linux(utf8Buffer, format, listPointer);
|
||||
result = Marshal.PtrToStringUTF8(utf8Buffer);
|
||||
|
||||
Marshal.FreeHGlobal(listPointer);
|
||||
Marshal.FreeHGlobal(utf8Buffer);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// https://github.com/dotnet/runtime/issues/51052
|
||||
static int vsnprintf(IntPtr buffer, UIntPtr size, IntPtr format, IntPtr args)
|
||||
{
|
||||
var os = Environment.OSVersion;
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
return Native.vsnprintf_windows(buffer, size, format, args);
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
return Native.vsnprintf_linux(buffer, size, format, args);
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("ANDROID")))
|
||||
{
|
||||
return Native.vsprintf_linux(buffer, format, args);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// https://github.com/dotnet/runtime/issues/51052
|
||||
static int vsprintf(IntPtr buffer, IntPtr format, IntPtr args)
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
return Native.vsprintf_windows(buffer, format, args);
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
return Native.vsprintf_linux(buffer, format, args);
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("ANDROID")))
|
||||
{
|
||||
return Native.vsprintf_linux(buffer, format, args);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
929
Raylib-cs/types/Raylib.Utils.cs
Normal file
929
Raylib-cs/types/Raylib.Utils.cs
Normal file
|
|
@ -0,0 +1,929 @@
|
|||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Raylib_cs
|
||||
{
|
||||
public static unsafe partial class Raylib
|
||||
{
|
||||
/// <summary>Initialize window and OpenGL context</summary>
|
||||
public static void InitWindow(int width, int height, string title)
|
||||
{
|
||||
using var str1 = title.ToUTF8Buffer();
|
||||
InitWindow(width, height, str1.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Set title for window (only PLATFORM_DESKTOP)</summary>
|
||||
public static void SetWindowTitle(string title)
|
||||
{
|
||||
using var str1 = title.ToUTF8Buffer();
|
||||
SetWindowTitle(str1.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Get the human-readable, UTF-8 encoded name of the primary monitor</summary>
|
||||
public static string GetMonitorName_(int monitor)
|
||||
{
|
||||
return Utf8StringUtils.GetUTF8String(GetMonitorName(monitor));
|
||||
}
|
||||
|
||||
/// <summary>Get clipboard text content</summary>
|
||||
public static string GetClipboardText_()
|
||||
{
|
||||
return Utf8StringUtils.GetUTF8String(GetClipboardText());
|
||||
}
|
||||
|
||||
/// <summary>Set clipboard text content</summary>
|
||||
public static void SetClipboardText(string text)
|
||||
{
|
||||
using var str1 = text.ToUTF8Buffer();
|
||||
SetClipboardText(str1.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Load shader from files and bind default locations</summary>
|
||||
public static Shader LoadShader(string vsFileName, string fsFileName)
|
||||
{
|
||||
using var str1 = vsFileName.ToUTF8Buffer();
|
||||
using var str2 = fsFileName.ToUTF8Buffer();
|
||||
return LoadShader(str1.AsPointer(), str2.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Load shader from code string and bind default locations</summary>
|
||||
public static Shader LoadShaderFromMemory(string vsCode, string fsCode)
|
||||
{
|
||||
using var str1 = vsCode.ToUTF8Buffer();
|
||||
using var str2 = fsCode.ToUTF8Buffer();
|
||||
return LoadShaderFromMemory(str1.AsPointer(), str2.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Get shader uniform location</summary>
|
||||
public static int GetShaderLocation(Shader shader, string uniformName)
|
||||
{
|
||||
using var str1 = uniformName.ToUTF8Buffer();
|
||||
return GetShaderLocation(shader, str1.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Get shader attribute location</summary>
|
||||
public static int GetShaderLocationAttrib(Shader shader, string attribName)
|
||||
{
|
||||
using var str1 = attribName.ToUTF8Buffer();
|
||||
return GetShaderLocationAttrib(shader, str1.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Takes a screenshot of current screen (saved a .png)</summary>
|
||||
public static void TakeScreenshot(string fileName)
|
||||
{
|
||||
using var str1 = fileName.ToUTF8Buffer();
|
||||
TakeScreenshot(str1.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Check file extension</summary>
|
||||
public static CBool IsFileExtension(string fileName, string ext)
|
||||
{
|
||||
using var str1 = fileName.ToUTF8Buffer();
|
||||
using var str2 = ext.ToUTF8Buffer();
|
||||
return IsFileExtension(str1.AsPointer(), str2.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Get file modification time (last write time)</summary>
|
||||
public static long GetFileModTime(string fileName)
|
||||
{
|
||||
using var str1 = fileName.ToUTF8Buffer();
|
||||
return GetFileModTime(str1.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Load image from file into CPU memory (RAM)</summary>
|
||||
public static Image LoadImage(string fileName)
|
||||
{
|
||||
using var str1 = fileName.ToUTF8Buffer();
|
||||
return LoadImage(str1.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Load image from RAW file data</summary>
|
||||
public static Image LoadImageRaw(string fileName, int width, int height, PixelFormat format, int headerSize)
|
||||
{
|
||||
using var str1 = fileName.ToUTF8Buffer();
|
||||
return LoadImageRaw(str1.AsPointer(), width, height, format, headerSize);
|
||||
}
|
||||
|
||||
/// <summary>Load image sequence from file (frames appended to image.data)</summary>
|
||||
public static Image LoadImageAnim(string fileName, int[] frames)
|
||||
{
|
||||
using var str1 = fileName.ToUTF8Buffer();
|
||||
fixed (int* p = frames)
|
||||
{
|
||||
return LoadImageAnim(str1.AsPointer(), p);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Export image data to file</summary>
|
||||
public static void ExportImage(Image image, string fileName)
|
||||
{
|
||||
using var str1 = fileName.ToUTF8Buffer();
|
||||
ExportImage(image, str1.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Export image as code file defining an array of bytes</summary>
|
||||
public static void ExportImageAsCode(Image image, string fileName)
|
||||
{
|
||||
using var str1 = fileName.ToUTF8Buffer();
|
||||
ExportImageAsCode(image, str1.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR)</summary>
|
||||
public static void TraceLog(TraceLogLevel logLevel, string text)
|
||||
{
|
||||
using var str1 = text.ToUTF8Buffer();
|
||||
TraceLog(logLevel, str1.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Set shader uniform value vector</summary>
|
||||
public static void SetShaderValueV<T>(Shader shader, int uniformLoc, T[] values, ShaderUniformDataType uniformType, int count)
|
||||
where T : unmanaged
|
||||
{
|
||||
SetShaderValueV(shader, uniformLoc, (Span<T>)values, uniformType, count);
|
||||
}
|
||||
|
||||
/// <summary>Set shader uniform value vector</summary>
|
||||
public static void SetShaderValueV<T>(Shader shader, int uniformLoc, Span<T> values, ShaderUniformDataType uniformType, int count)
|
||||
where T : unmanaged
|
||||
{
|
||||
fixed (T* valuePtr = values)
|
||||
{
|
||||
SetShaderValueV(shader, uniformLoc, valuePtr, uniformType, count);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Set shader uniform value</summary>
|
||||
public static void SetShaderValue<T>(Shader shader, int uniformLoc, T value, ShaderUniformDataType uniformType)
|
||||
where T : unmanaged
|
||||
{
|
||||
SetShaderValue(shader, uniformLoc, &value, uniformType);
|
||||
}
|
||||
|
||||
/// <summary>Set shader uniform value</summary>
|
||||
public static void SetShaderValue<T>(Shader shader, int uniformLoc, T[] values, ShaderUniformDataType uniformType)
|
||||
where T : unmanaged
|
||||
{
|
||||
SetShaderValue(shader, uniformLoc, (Span<T>)values, uniformType);
|
||||
}
|
||||
|
||||
/// <summary>Set shader uniform value</summary>
|
||||
public static void SetShaderValue<T>(Shader shader, int uniformLoc, Span<T> values, ShaderUniformDataType uniformType)
|
||||
where T : unmanaged
|
||||
{
|
||||
fixed (T* valuePtr = values)
|
||||
{
|
||||
SetShaderValue(shader, uniformLoc, valuePtr, uniformType);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Load file data as byte array (read)</summary>
|
||||
public static byte* LoadFileData(string fileName, ref uint bytesRead)
|
||||
{
|
||||
using var str1 = fileName.ToUTF8Buffer();
|
||||
fixed (uint* p = &bytesRead)
|
||||
{
|
||||
return LoadFileData(str1.AsPointer(), p);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Get dropped files names (memory should be freed)</summary>
|
||||
public static string[] GetDroppedFiles()
|
||||
{
|
||||
int count;
|
||||
var buffer = GetDroppedFiles(&count);
|
||||
var files = new string[count];
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
files[i] = Marshal.PtrToStringUTF8((IntPtr)buffer[i]);
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
/// <summary>Return gamepad internal name id</summary>
|
||||
public static string GetGamepadName_(int gamepad)
|
||||
{
|
||||
return Utf8StringUtils.GetUTF8String(GetGamepadName(gamepad));
|
||||
}
|
||||
|
||||
/// <summary>Update camera position for selected mode</summary>
|
||||
public static void UpdateCamera(ref Camera3D camera)
|
||||
{
|
||||
fixed (Camera3D* c = &camera)
|
||||
{
|
||||
UpdateCamera(c);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Check the collision between two lines defined by two points each, returns collision point by reference</summary>
|
||||
public static CBool CheckCollisionLines(Vector2 startPos1, Vector2 endPos1, Vector2 startPos2, Vector2 endPos2, ref Vector2 collisionPoint)
|
||||
{
|
||||
fixed (Vector2* p = &collisionPoint)
|
||||
{
|
||||
return CheckCollisionLines(startPos1, endPos1, startPos2, endPos2, p);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Create an image from text (default font)</summary>
|
||||
public static Image ImageText(string text, int fontSize, Color color)
|
||||
{
|
||||
using var str1 = text.ToUTF8Buffer();
|
||||
return ImageText(str1.AsPointer(), fontSize, color);
|
||||
}
|
||||
|
||||
/// <summary>Create an image from text (custom sprite font)</summary>
|
||||
public static Image ImageTextEx(Font font, string text, float fontSize, float spacing, Color tint)
|
||||
{
|
||||
using var str1 = text.ToUTF8Buffer();
|
||||
return ImageTextEx(font, str1.AsPointer(), fontSize, spacing, tint);
|
||||
}
|
||||
|
||||
/// <summary>Convert image to POT (power-of-two)</summary>
|
||||
public static void ImageToPOT(ref Image image, Color fill)
|
||||
{
|
||||
fixed (Image* p = &image)
|
||||
{
|
||||
ImageToPOT(p, fill);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Convert image data to desired format</summary>
|
||||
public static void ImageFormat(ref Image image, PixelFormat newFormat)
|
||||
{
|
||||
fixed (Image* p = &image)
|
||||
{
|
||||
ImageFormat(p, newFormat);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Apply alpha mask to image</summary>
|
||||
public static void ImageAlphaMask(ref Image image, Image alphaMask)
|
||||
{
|
||||
fixed (Image* p = &image)
|
||||
{
|
||||
ImageAlphaMask(p, alphaMask);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Clear alpha channel to desired color</summary>
|
||||
public static void ImageAlphaClear(ref Image image, Color color, float threshold)
|
||||
{
|
||||
fixed (Image* p = &image)
|
||||
{
|
||||
ImageAlphaClear(p, color, threshold);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Crop image depending on alpha value</summary>
|
||||
public static void ImageAlphaCrop(ref Image image, float threshold)
|
||||
{
|
||||
fixed (Image* p = &image)
|
||||
{
|
||||
ImageAlphaCrop(p, threshold);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Premultiply alpha channel</summary>
|
||||
public static void ImageAlphaPremultiply(ref Image image)
|
||||
{
|
||||
fixed (Image* p = &image)
|
||||
{
|
||||
ImageAlphaPremultiply(p);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Crop an image to a defined rectangle</summary>
|
||||
public static void ImageCrop(ref Image image, Rectangle crop)
|
||||
{
|
||||
fixed (Image* p = &image)
|
||||
{
|
||||
ImageCrop(p, crop);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Resize image (Bicubic scaling algorithm)</summary>
|
||||
public static void ImageResize(ref Image image, int newWidth, int newHeight)
|
||||
{
|
||||
fixed (Image* p = &image)
|
||||
{
|
||||
ImageResize(p, newWidth, newHeight);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Resize image (Nearest-Neighbor scaling algorithm)</summary>
|
||||
public static void ImageResizeNN(ref Image image, int newWidth, int newHeight)
|
||||
{
|
||||
fixed (Image* p = &image)
|
||||
{
|
||||
ImageResizeNN(p, newWidth, newHeight);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Resize canvas and fill with color</summary>
|
||||
public static void ImageResizeCanvas(ref Image image, int newWidth, int newHeight, int offsetX, int offsetY, Color color)
|
||||
{
|
||||
fixed (Image* p = &image)
|
||||
{
|
||||
ImageResizeCanvas(p, newWidth, newHeight, offsetX, offsetY, color);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Generate all mipmap levels for a provided image</summary>
|
||||
public static void ImageMipmaps(ref Image image)
|
||||
{
|
||||
fixed (Image* p = &image)
|
||||
{
|
||||
ImageMipmaps(p);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Dither image data to 16bpp or lower (Floyd-Steinberg dithering)</summary>
|
||||
public static void ImageDither(ref Image image, int rBpp, int gBpp, int bBpp, int aBpp)
|
||||
{
|
||||
fixed (Image* p = &image)
|
||||
{
|
||||
ImageDither(p, rBpp, gBpp, bBpp, aBpp);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Flip image vertically</summary>
|
||||
public static void ImageFlipVertical(ref Image image)
|
||||
{
|
||||
fixed (Image* p = &image)
|
||||
{
|
||||
ImageFlipVertical(p);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Flip image horizontally</summary>
|
||||
public static void ImageFlipHorizontal(ref Image image)
|
||||
{
|
||||
fixed (Image* p = &image)
|
||||
{
|
||||
ImageFlipHorizontal(p);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Rotate image clockwise 90deg</summary>
|
||||
public static void ImageRotateCW(ref Image image)
|
||||
{
|
||||
fixed (Image* p = &image)
|
||||
{
|
||||
ImageRotateCW(p);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Rotate image counter-clockwise 90deg</summary>
|
||||
public static void ImageRotateCCW(ref Image image)
|
||||
{
|
||||
fixed (Image* p = &image)
|
||||
{
|
||||
ImageRotateCCW(p);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Modify image color: tint</summary>
|
||||
public static void ImageColorTint(ref Image image, Color color)
|
||||
{
|
||||
fixed (Image* p = &image)
|
||||
{
|
||||
ImageColorTint(p, color);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Modify image color: invert</summary>
|
||||
public static void ImageColorInvert(ref Image image)
|
||||
{
|
||||
fixed (Image* p = &image)
|
||||
{
|
||||
ImageColorInvert(p);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Modify image color: grayscale</summary>
|
||||
public static void ImageColorGrayscale(ref Image image)
|
||||
{
|
||||
fixed (Image* p = &image)
|
||||
{
|
||||
ImageColorGrayscale(p);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Modify image color: contrast (-100 to 100)</summary>
|
||||
public static void ImageColorContrast(ref Image image, float contrast)
|
||||
{
|
||||
fixed (Image* p = &image)
|
||||
{
|
||||
ImageColorContrast(p, contrast);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Modify image color: brightness (-255 to 255)</summary>
|
||||
public static void ImageColorBrightness(ref Image image, int brightness)
|
||||
{
|
||||
fixed (Image* p = &image)
|
||||
{
|
||||
ImageColorBrightness(p, brightness);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Modify image color: replace color</summary>
|
||||
public static void ImageColorReplace(ref Image image, Color color, Color replace)
|
||||
{
|
||||
fixed (Image* p = &image)
|
||||
{
|
||||
ImageColorReplace(p, color, replace);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Clear image background with given color</summary>
|
||||
public static void ImageClearBackground(ref Image dst, Color color)
|
||||
{
|
||||
fixed (Image* p = &dst)
|
||||
{
|
||||
ImageClearBackground(p, color);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Draw pixel within an image</summary>
|
||||
public static void ImageDrawPixel(ref Image dst, int posX, int posY, Color color)
|
||||
{
|
||||
fixed (Image* p = &dst)
|
||||
{
|
||||
ImageDrawPixel(p, posX, posY, color);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Draw pixel within an image (Vector version)</summary>
|
||||
public static void ImageDrawPixelV(ref Image dst, Vector2 position, Color color)
|
||||
{
|
||||
fixed (Image* p = &dst)
|
||||
{
|
||||
ImageDrawPixelV(p, position, color);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Draw line within an image</summary>
|
||||
public static void ImageDrawLine(ref Image dst, int startPosX, int startPosY, int endPosX, int endPosY, Color color)
|
||||
{
|
||||
fixed (Image* p = &dst)
|
||||
{
|
||||
ImageDrawLine(p, startPosX, startPosY, endPosX, endPosY, color);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Draw line within an image (Vector version)</summary>
|
||||
public static void ImageDrawLineV(ref Image dst, Vector2 start, Vector2 end, Color color)
|
||||
{
|
||||
fixed (Image* p = &dst)
|
||||
{
|
||||
ImageDrawLineV(p, start, end, color);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Draw circle within an image</summary>
|
||||
public static void ImageDrawCircle(ref Image dst, int centerX, int centerY, int radius, Color color)
|
||||
{
|
||||
fixed (Image* p = &dst)
|
||||
{
|
||||
ImageDrawCircle(p, centerX, centerY, radius, color);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Draw circle within an image (Vector version)</summary>
|
||||
public static void ImageDrawCircleV(ref Image dst, Vector2 center, int radius, Color color)
|
||||
{
|
||||
fixed (Image* p = &dst)
|
||||
{
|
||||
ImageDrawCircleV(p, center, radius, color);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Draw rectangle within an image</summary>
|
||||
public static void ImageDrawRectangle(ref Image dst, int posX, int posY, int width, int height, Color color)
|
||||
{
|
||||
fixed (Image* p = &dst)
|
||||
{
|
||||
ImageDrawRectangle(p, posX, posY, width, height, color);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Draw rectangle within an image (Vector version)</summary>
|
||||
public static void ImageDrawRectangleV(ref Image dst, Vector2 position, Vector2 size, Color color)
|
||||
{
|
||||
fixed (Image* p = &dst)
|
||||
{
|
||||
ImageDrawRectangleV(p, position, size, color);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Draw rectangle within an image</summary>
|
||||
public static void ImageDrawRectangleRec(ref Image dst, Rectangle rec, Color color)
|
||||
{
|
||||
fixed (Image* p = &dst)
|
||||
{
|
||||
ImageDrawRectangleRec(p, rec, color);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Draw rectangle lines within an image</summary>
|
||||
public static void ImageDrawRectangleLines(ref Image dst, Rectangle rec, int thick, Color color)
|
||||
{
|
||||
fixed (Image* p = &dst)
|
||||
{
|
||||
ImageDrawRectangleLines(p, rec, thick, color);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Draw a source image within a destination image (tint applied to source)</summary>
|
||||
public static void ImageDraw(ref Image dst, Image src, Rectangle srcRec, Rectangle dstRec, Color tint)
|
||||
{
|
||||
fixed (Image* p = &dst)
|
||||
{
|
||||
ImageDraw(p, src, srcRec, dstRec, tint);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Draw text (using default font) within an image (destination)</summary>
|
||||
public static void ImageDrawText(ref Image dst, string text, int x, int y, int fontSize, Color color)
|
||||
{
|
||||
using var str1 = text.ToUTF8Buffer();
|
||||
fixed (Image* p = &dst)
|
||||
{
|
||||
ImageDrawText(p, str1.AsPointer(), x, y, fontSize, color);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Draw text (custom sprite font) within an image (destination)</summary>
|
||||
public static void ImageDrawTextEx(ref Image dst, Font font, string text, Vector2 position, int fontSize, float spacing, Color color)
|
||||
{
|
||||
using var str1 = text.ToUTF8Buffer();
|
||||
fixed (Image* p = &dst)
|
||||
{
|
||||
ImageDrawTextEx(p, font, str1.AsPointer(), position, fontSize, spacing, color);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Load texture from file into GPU memory (VRAM)</summary>
|
||||
public static Texture2D LoadTexture(string fileName)
|
||||
{
|
||||
using var str1 = fileName.ToUTF8Buffer();
|
||||
return LoadTexture(str1.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Generate GPU mipmaps for a texture</summary>
|
||||
public static void GenTextureMipmaps(ref Texture2D texture)
|
||||
{
|
||||
fixed (Texture2D* p = &texture)
|
||||
{
|
||||
GenTextureMipmaps(p);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Load font from file into GPU memory (VRAM)</summary>
|
||||
public static Font LoadFont(string fileName)
|
||||
{
|
||||
using var str1 = fileName.ToUTF8Buffer();
|
||||
return LoadFont(str1.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Load font from file with extended parameters</summary>
|
||||
public static Font LoadFontEx(string fileName, int fontSize, int[] fontChars, int charsCount)
|
||||
{
|
||||
using var str1 = fileName.ToUTF8Buffer();
|
||||
return LoadFontEx(str1.AsPointer(), fontSize, fontChars, charsCount);
|
||||
}
|
||||
|
||||
/// <summary>Upload vertex data into GPU and provided VAO/VBO ids</summary>
|
||||
public static void UploadMesh(ref Mesh mesh, CBool dynamic)
|
||||
{
|
||||
fixed (Mesh* p = &mesh)
|
||||
{
|
||||
UploadMesh(p, dynamic);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Unload mesh from memory (RAM and/or VRAM)</summary>
|
||||
public static void UnloadMesh(ref Mesh mesh)
|
||||
{
|
||||
fixed (Mesh* p = &mesh)
|
||||
{
|
||||
UnloadMesh(p);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Set texture for a material map type (MAP_DIFFUSE, MAP_SPECULAR...)</summary>
|
||||
public static void SetMaterialTexture(ref Material material, MaterialMapIndex mapType, Texture2D texture)
|
||||
{
|
||||
fixed (Material* p = &material)
|
||||
{
|
||||
SetMaterialTexture(p, mapType, texture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Set material for a mesh</summary>
|
||||
public static void SetModelMeshMaterial(ref Model model, int meshId, int materialId)
|
||||
{
|
||||
fixed (Model* p = &model)
|
||||
{
|
||||
SetModelMeshMaterial(p, meshId, materialId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Load model animations from file</summary>
|
||||
public static ReadOnlySpan<ModelAnimation> LoadModelAnimations(string fileName, ref uint animsCount)
|
||||
{
|
||||
using var str1 = fileName.ToUTF8Buffer();
|
||||
fixed (uint* p = &animsCount)
|
||||
{
|
||||
var model = LoadModelAnimations(str1.AsPointer(), p);
|
||||
|
||||
if ((IntPtr)model == IntPtr.Zero)
|
||||
{
|
||||
throw new ApplicationException("Failed to load animation");
|
||||
}
|
||||
|
||||
return new ReadOnlySpan<ModelAnimation>(model, (int)animsCount);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Compute mesh tangents</summary>
|
||||
public static void GenMeshTangents(ref Mesh mesh)
|
||||
{
|
||||
fixed (Mesh* p = &mesh)
|
||||
{
|
||||
GenMeshTangents(p);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Compute mesh binormals</summary>
|
||||
public static void GenMeshBinormals(ref Mesh mesh)
|
||||
{
|
||||
fixed (Mesh* p = &mesh)
|
||||
{
|
||||
GenMeshBinormals(p);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Convert wave data to desired format</summary>
|
||||
public static void WaveFormat(ref Wave wave, int sampleRate, int sampleSize, int channels)
|
||||
{
|
||||
fixed (Wave* p = &wave)
|
||||
{
|
||||
WaveFormat(p, sampleRate, sampleSize, channels);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Crop a wave to defined samples range</summary>
|
||||
public static void WaveCrop(ref Wave wave, int initSample, int finalSample)
|
||||
{
|
||||
fixed (Wave* p = &wave)
|
||||
{
|
||||
WaveCrop(p, initSample, finalSample);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Draw lines sequence</summary>
|
||||
public static void DrawLineStrip(Vector2[] points, int numPoints, Color color)
|
||||
{
|
||||
fixed (Vector2* p = points)
|
||||
{
|
||||
DrawLineStrip(p, numPoints, color);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Draw a triangle fan defined by points (first vertex is the center)</summary>
|
||||
public static void DrawTriangleFan(Vector2[] points, int numPoints, Color color)
|
||||
{
|
||||
fixed (Vector2* p = points)
|
||||
{
|
||||
DrawTriangleFan(p, numPoints, color);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Draw a triangle strip defined by points</summary>
|
||||
public static void DrawTriangleStrip(Vector2[] points, int pointsCount, Color color)
|
||||
{
|
||||
fixed (Vector2* p = points)
|
||||
{
|
||||
DrawTriangleStrip(p, pointsCount, color);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Draw a textured polygon</summary>
|
||||
public static void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2[] points, Vector2[] texcoords, int pointsCount, Color tint)
|
||||
{
|
||||
fixed (Vector2* p = points)
|
||||
{
|
||||
fixed (Vector2* p1 = texcoords)
|
||||
{
|
||||
DrawTexturePoly(texture, center, p, p1, pointsCount, tint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Draw text (using default font)</summary>
|
||||
public static void DrawText(string text, int posX, int posY, int fontSize, Color color)
|
||||
{
|
||||
using var str1 = text.ToUTF8Buffer();
|
||||
DrawText(str1.AsPointer(), posX, posY, fontSize, color);
|
||||
}
|
||||
|
||||
/// <summary>Draw text using font and additional parameters</summary>
|
||||
public static void DrawTextEx(Font font, string text, Vector2 position, float fontSize, float spacing, Color tint)
|
||||
{
|
||||
using var str1 = text.ToUTF8Buffer();
|
||||
DrawTextEx(font, str1.AsPointer(), position, fontSize, spacing, tint);
|
||||
}
|
||||
|
||||
/// <summary>Draw text using Font and pro parameters (rotation)</summary>
|
||||
public static void DrawTextPro(Font font, string text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint)
|
||||
{
|
||||
using var str1 = text.ToUTF8Buffer();
|
||||
DrawTextPro(font, str1.AsPointer(), position, origin, rotation, fontSize, spacing, tint);
|
||||
}
|
||||
|
||||
/// <summary>Measure string width for default font</summary>
|
||||
public static int MeasureText(string text, int fontSize)
|
||||
{
|
||||
using var str1 = text.ToUTF8Buffer();
|
||||
return MeasureText(str1.AsPointer(), fontSize);
|
||||
}
|
||||
|
||||
/// <summary>Measure string size for Font</summary>
|
||||
public static Vector2 MeasureTextEx(Font font, string text, float fontSize, float spacing)
|
||||
{
|
||||
using var str1 = text.ToUTF8Buffer();
|
||||
return MeasureTextEx(font, str1.AsPointer(), fontSize, spacing);
|
||||
}
|
||||
|
||||
/// <summary>Append text at specific position and move cursor!</summary>
|
||||
public static void TextAppend(string text, string append, int position)
|
||||
{
|
||||
using var str1 = text.ToUTF8Buffer();
|
||||
using var str2 = append.ToUTF8Buffer();
|
||||
TextAppend(str1.AsPointer(), str2.AsPointer(), &position);
|
||||
}
|
||||
|
||||
/// <summary>Get Pascal case notation version of provided string</summary>
|
||||
public static string TextToPascal(string text)
|
||||
{
|
||||
using var str1 = text.ToUTF8Buffer();
|
||||
return Utf8StringUtils.GetUTF8String(TextToPascal(str1.AsPointer()));
|
||||
}
|
||||
|
||||
/// <summary>Get integer value from text (negative values not supported)</summary>
|
||||
public static int TextToInteger(string text)
|
||||
{
|
||||
using var str1 = text.ToUTF8Buffer();
|
||||
return TextToInteger(str1.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Get all codepoints in a string, codepoints count returned by parameters</summary>
|
||||
public static int[] LoadCodepoints(string text, ref int count)
|
||||
{
|
||||
using var str1 = text.ToUTF8Buffer();
|
||||
fixed (int* c = &count)
|
||||
{
|
||||
var pointsPtr = LoadCodepoints(str1.AsPointer(), c);
|
||||
var codepoints = new ReadOnlySpan<int>(pointsPtr, count).ToArray();
|
||||
UnloadCodepoints(pointsPtr);
|
||||
return codepoints;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Get total number of characters (codepoints) in a UTF8 encoded string</summary>
|
||||
public static int GetCodepointCount(string text)
|
||||
{
|
||||
using var str1 = text.ToUTF8Buffer();
|
||||
return GetCodepointCount(str1.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Returns next codepoint in a UTF8 encoded string; 0x3f('?') is returned on failure</summary>
|
||||
/// <returns>single codepoint / "char"</returns>
|
||||
public static int GetCodepoint(string text, ref int bytesProcessed)
|
||||
{
|
||||
using var str1 = text.ToUTF8Buffer();
|
||||
fixed (int* p = &bytesProcessed)
|
||||
{
|
||||
return GetCodepoint(str1.AsPointer(), p);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Encode codepoint into utf8 text (char array length returned as parameter)</summary>
|
||||
public static string CodepointToUTF8(int codepoint, ref int byteSize)
|
||||
{
|
||||
fixed (int* l1 = &byteSize)
|
||||
{
|
||||
var ptr = CodepointToUTF8(codepoint, l1);
|
||||
return Utf8StringUtils.GetUTF8String(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Encode codepoint into utf8 text (char array length returned as parameter)</summary>
|
||||
public static string TextCodepointsToUTF8(int[] codepoints, int length)
|
||||
{
|
||||
fixed (int* c1 = codepoints)
|
||||
{
|
||||
var ptr = TextCodepointsToUTF8(c1, length);
|
||||
var text = Utf8StringUtils.GetUTF8String(ptr);
|
||||
MemFree(ptr);
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Draw a model (with texture if set)</summary>
|
||||
public static Model LoadModel(string fileName)
|
||||
{
|
||||
using var str1 = fileName.ToUTF8Buffer();
|
||||
return LoadModel(str1.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Export mesh data to file, returns true on success</summary>
|
||||
public static CBool ExportMesh(Mesh mesh, string fileName)
|
||||
{
|
||||
using var str1 = fileName.ToUTF8Buffer();
|
||||
return ExportMesh(mesh, str1.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Draw a triangle strip defined by points</summary>
|
||||
public static void DrawTriangleStrip3D(Vector3[] points, int pointsCount, Color color)
|
||||
{
|
||||
fixed (Vector3* p = points)
|
||||
{
|
||||
DrawTriangleStrip3D(p, pointsCount, color);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Draw multiple mesh instances with material and different transforms</summary>
|
||||
public static void DrawMeshInstanced(Mesh mesh, Material material, Matrix4x4[] transforms, int instances)
|
||||
{
|
||||
fixed (Matrix4x4* p = transforms)
|
||||
{
|
||||
DrawMeshInstanced(mesh, material, p, instances);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Load wave data from file</summary>
|
||||
public static Wave LoadWave(string fileName)
|
||||
{
|
||||
using var str1 = fileName.ToUTF8Buffer();
|
||||
return LoadWave(str1.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Load sound from file</summary>
|
||||
public static Sound LoadSound(string fileName)
|
||||
{
|
||||
using var str1 = fileName.ToUTF8Buffer();
|
||||
return LoadSound(str1.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Export wave data to file</summary>
|
||||
public static void ExportWave(Wave wave, string fileName)
|
||||
{
|
||||
using var str1 = fileName.ToUTF8Buffer();
|
||||
ExportWave(wave, str1.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Export wave sample data to code (.h)</summary>
|
||||
public static void ExportWaveAsCode(Wave wave, string fileName)
|
||||
{
|
||||
using var str1 = fileName.ToUTF8Buffer();
|
||||
ExportWaveAsCode(wave, str1.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Load music stream from file</summary>
|
||||
public static Music LoadMusicStream(string fileName)
|
||||
{
|
||||
using var str1 = fileName.ToUTF8Buffer();
|
||||
return LoadMusicStream(str1.AsPointer());
|
||||
}
|
||||
|
||||
public static string SubText(this string input, int position, int length)
|
||||
{
|
||||
return input.Substring(position, Math.Min(length, input.Length));
|
||||
}
|
||||
|
||||
public static Material GetMaterial(ref Model model, int materialIndex)
|
||||
{
|
||||
return model.materials[materialIndex];
|
||||
}
|
||||
|
||||
public static Texture2D GetMaterialTexture(ref Model model, int materialIndex, MaterialMapIndex mapIndex)
|
||||
{
|
||||
return model.materials[materialIndex].maps[(int)mapIndex].texture;
|
||||
}
|
||||
|
||||
public static void SetMaterialTexture(ref Model model, int materialIndex, MaterialMapIndex mapIndex, ref Texture2D texture)
|
||||
{
|
||||
SetMaterialTexture(&model.materials[materialIndex], mapIndex, texture);
|
||||
}
|
||||
|
||||
public static void SetMaterialShader(ref Model model, int materialIndex, ref Shader shader)
|
||||
{
|
||||
model.materials[materialIndex].shader = shader;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue