2
0
mirror of https://github.com/raylib-cs/raylib-cs synced 2025-10-13 04:51:53 -04:00
Files
raylib-cs/Raylib-cs/types/RenderBatch.cs
Matorio 75aabd1cc0 Explicit core types and autonomous types. (#304)
* All the "var" variables were changed to explicit types on the raylib class
* "MakeDirectory" overload, and string version of "GetApplicationDirectory" and "GetWorkingDirectory" methods
* Added "Dimensions" property to "Texture2D"
* New overloads for the "LoadFileData" and "SaveFileData" methods
* Raymath's const "NativeLibName" is now referencing to "Raylib.NativeLibName"
* Color constructors are more readable
* Added "Dimensions" property to "Image"
* Changed all the "var" for explicit types on the "Logging" class
* Changed "Int64" for "long" on CBool, and using constructor on the operators instead setting the value manually
* Added indexer to "FilePathLists"
* Changed all "var" for explicit types on "Utf8Buffer"
* New "GetRandomSequence" method overloads in "Raylib.Utils" acepting "int" and "float"
* Added new extension "byte.Lerp"
* Added new extension "Log" for "TraceLogLevel"
* Constructors on Color no longer just truncate the float value, but also round it (+ 0.5f)
* New static method on Color, "Color.Lerp"
* Added static method "FromHSV" to Color
* Added new getter method "GetHSV" on Color
* Added index security on the FilePathList indexer
* Added Rectangle extension
* Added "MoveTowards" extensions to RaylibExtensions
* Added "TranslateLocal" and "TranslateGlobal" to Transform
* Removed unnecessary "partial" declarations
* Updating calls and docs
* Moved the "AudioCallback" delegate into the "AudioMixed.cs" File
* Properties and structs marked as read-only on the "Model.cs" file
* Updated the "README.md" to mentions Raylib-cs targets net6.0 and net8.0 (and also explicitly added that the
"STAThread" attribute comes from the "System" namespace)
* Added a few sizing utils to "Rectangle"
* Added "GetScreenCenter" to "Raylib.Utils"
2025-09-21 09:09:38 +01:00

312 lines
6.7 KiB
C#

using System;
using System.Runtime.InteropServices;
namespace Raylib_cs;
/// <summary>
/// RenderBatch type
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public unsafe struct RenderBatch
{
/// <summary>
/// Number of vertex buffers (multi-buffering support)
/// </summary>
public int BufferCount;
/// <summary>
/// Current buffer tracking in case of multi-buffering
/// </summary>
public int CurrentBuffer;
/// <summary>
/// Dynamic buffer(s) for vertex data
/// </summary>
public VertexBuffer* VertexBuffer;
/// <summary>
/// Draw calls array, depends on textureId
/// </summary>
public DrawCall* Draws;
/// <summary>
/// Draw calls counter
/// </summary>
public int DrawCounter;
/// <summary>
/// Current depth value for next draw
/// </summary>
public float CurrentDepth;
}
/// <summary>
/// Dynamic vertex buffers (position + texcoords + colors + indices arrays)
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public unsafe struct VertexBuffer
{
/// <summary>
/// Number of elements in the buffer (QUADS)
/// </summary>
public int ElementCount;
/// <summary>
/// Vertex position (XYZ - 3 components per vertex) (shader-location = 0)
/// </summary>
public float* Vertices;
/// <summary>
/// Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
/// </summary>
public float* TexCoords;
/// <summary>
/// Vertex normal (XYZ - 3 components per vertex) (shader-location = 2)
/// </summary>
public float* Normals;
/// <summary>
/// Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
/// </summary>
public byte* Colors;
/// <summary>
/// Vertex indices (in case vertex data comes indexed) (6 indices per quad)<br/>
/// unsigned int* for GRAPHICS_API_OPENGL_11 or GRAPHICS_API_OPENGL_33<br/>
/// unsigned short* for GRAPHICS_API_OPENGL_ES2
/// </summary>
public void* Indices;
/// <summary>
/// OpenGL Vertex Array Object id
/// </summary>
public uint VaoId;
/// <summary>
/// OpenGL Vertex Buffer Objects id (5 types of vertex data)
/// </summary>
public fixed uint VboId[5];
/// <summary>
/// Access <see cref="Vertices"/>
/// </summary>
public readonly Span<T> VerticesAs<T>() where T : unmanaged
{
return new(Vertices, ElementCount * sizeof(float) / sizeof(T));
}
/// <summary>
/// Access <see cref="TexCoords"/>
/// </summary>
public readonly Span<T> TexCoordsAs<T>() where T : unmanaged
{
return new(TexCoords, ElementCount * sizeof(float) / sizeof(T));
}
/// <summary>
/// Access <see cref="Normals"/>
/// </summary>
public readonly Span<T> NormalsAs<T>() where T : unmanaged
{
return new(Normals, ElementCount * sizeof(float) / sizeof(T));
}
/// <summary>
/// Access <see cref="Colors"/>
/// </summary>
public readonly Span<T> ColorsAs<T>() where T : unmanaged
{
return new(Colors, ElementCount * sizeof(byte) / sizeof(T));
}
}
/// <summary>
/// Draw call type<br/>
/// NOTE: Only texture changes register a new draw, other state-change-related elements are not
/// used at this moment (vaoId, shaderId, matrices), raylib just forces a batch draw call if any
/// of those state-change happens (this is done in core module)
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public partial struct DrawCall
{
/// <summary>
/// Drawing mode: LINES, TRIANGLES, QUADS
/// </summary>
public DrawMode Mode;
/// <summary>
/// Number of vertices for the draw call
/// </summary>
public int VertexCount;
/// <summary>
/// Number of vertices required for index alignment (LINES, TRIANGLES)
/// </summary>
public int VertexAlignment;
/// <summary>
/// Texture id to be used on the draw -> Use to create new draw call if changes
/// </summary>
public uint TextureId;
}
public enum GlVersion
{
OpenGl11 = 1,
OpenGl21,
OpenGl33,
OpenGl43,
OpenGlEs20
}
public enum FramebufferAttachType
{
ColorChannel0 = 0,
ColorChannel1,
ColorChannel2,
ColorChannel3,
ColorChannel4,
ColorChannel5,
ColorChannel6,
ColorChannel7,
Depth = 100,
Stencil = 200,
}
public enum FramebufferAttachTextureType
{
CubemapPositiveX = 0,
CubemapNegativeX,
CubemapPositiveY,
CubemapNegativeY,
CubemapPositiveZ,
CubemapNegativeZ,
Texture2D = 100,
Renderbuffer = 200,
}
/// <summary>
/// Matrix Modes (equivalent to OpenGL)
/// </summary>
public enum MatrixMode
{
/// <summary>
/// GL_MODELVIEW
/// </summary>
ModelView = 0x1700,
/// <summary>
/// GL_PROJECTION
/// </summary>
Projection = 0x1701,
/// <summary>
/// GL_TEXTURE
/// </summary>
Texture = 0x1702
}
/// <summary>
/// Primitive assembly draw modes
/// </summary>
public enum DrawMode
{
/// <summary>
/// GL_LINES
/// </summary>
Lines = 0x0001,
/// <summary>
/// GL_TRIANGLES
/// </summary>
Triangles = 0x0004,
/// <summary>
/// GL_QUADS
/// </summary>
Quads = 0x0007
}
/// <summary>
/// Texture parameters (equivalent to OpenGL defines)
/// </summary>
public enum TextureFilters
{
/// <summary>
/// RL_TEXTURE_FILTER_NEAREST
/// <br/>
/// GL_NEAREST
/// </summary>
Nearest = 0x2600,
/// <summary>
/// RL_TEXTURE_FILTER_LINEAR
/// <br/>
/// GL_LINEAR
/// </summary>
Linear = 0x2601,
/// <summary>
/// RL_TEXTURE_FILTER_MIP_NEAREST
/// <br/>
/// GL_NEAREST_MIPMAP_NEAREST
/// </summary>
MipNearest = 0x2700,
/// <summary>
/// RL_TEXTURE_FILTER_NEAREST_MIP_LINEAR
/// <br/>
/// GL_NEAREST_MIPMAP_LINEAR
/// </summary>
NearestMipLinear = 0x2702,
/// <summary>
/// RL_TEXTURE_FILTER_LINEAR_MIP_NEAREST
/// <br/>
/// GL_LINEAR_MIPMAP_NEAREST
/// </summary>
LinearMipNearest = 0x2701,
/// <summary>
/// RL_TEXTURE_FILTER_MIP_LINEAR
/// <br/>
/// GL_LINEAR_MIPMAP_LINEAR
/// </summary>
MipLinear = 0x2703,
/// <summary>
/// RL_TEXTURE_FILTER_ANISOTROPIC
/// <br/>
/// Anisotropic filter (custom identifier)
/// </summary>
Anisotropic = 0x3000
}
/// <summary>
/// GL Shader type
/// </summary>
public enum ShaderType
{
/// <summary>
/// RL_FRAGMENT_SHADER
/// <br/>
/// GL_FRAGMENT_SHADER
/// </summary>
Fragment = 0x8B30,
/// <summary>
/// RL_VERTEX_SHADER
/// <br/>
/// GL_VERTEX_SHADER
/// </summary>
Vertex = 0x8B31,
/// <summary>
/// RL_COMPUTE_SHADER
/// <br/>
/// GL_COMPUTE_SHADER
/// </summary>
Compute = 0x91b9
}