1 module rlgl; 2 3 import raylib; 4 5 extern (C) @nogc nothrow: 6 7 //---------------------------------------------------------------------------------- 8 // Defines and Macros 9 //---------------------------------------------------------------------------------- 10 // Default internal render batch limits 11 12 // This is the maximum amount of elements (quads) per batch 13 // NOTE: Be careful with text, every letter maps to a quad 14 enum DEFAULT_BATCH_BUFFER_ELEMENTS = 8192; 15 16 // We reduce memory sizes for embedded systems (RPI and HTML5) 17 // NOTE: On HTML5 (emscripten) this is allocated on heap, 18 // by default it's only 16MB!...just take care... 19 20 enum DEFAULT_BATCH_BUFFERS = 1; // Default number of batch buffers (multi-buffering) 21 22 enum DEFAULT_BATCH_DRAWCALLS = 256; // Default number of batch draw calls (by state changes: mode, texture) 23 24 enum MAX_BATCH_ACTIVE_TEXTURES = 4; // Maximum number of additional textures that can be activated on batch drawing (SetShaderValueTexture()) 25 26 // Internal Matrix stack 27 28 enum MAX_MATRIX_STACK_SIZE = 32; // Maximum size of Matrix stack 29 30 // Shader and material limits 31 32 enum MAX_SHADER_LOCATIONS = 32; // Maximum number of shader locations supported 33 34 enum MAX_MATERIAL_MAPS = 12; // Maximum number of shader maps supported 35 36 // Projection matrix culling 37 38 enum RL_CULL_DISTANCE_NEAR = 0.01; // Default near cull distance 39 40 enum RL_CULL_DISTANCE_FAR = 1000.0; // Default far cull distance 41 42 // Texture parameters (equivalent to OpenGL defines) 43 enum RL_TEXTURE_WRAP_S = 0x2802; // GL_TEXTURE_WRAP_S 44 enum RL_TEXTURE_WRAP_T = 0x2803; // GL_TEXTURE_WRAP_T 45 enum RL_TEXTURE_MAG_FILTER = 0x2800; // GL_TEXTURE_MAG_FILTER 46 enum RL_TEXTURE_MIN_FILTER = 0x2801; // GL_TEXTURE_MIN_FILTER 47 enum RL_TEXTURE_ANISOTROPIC_FILTER = 0x3000; // Anisotropic filter (custom identifier) 48 49 enum RL_FILTER_NEAREST = 0x2600; // GL_NEAREST 50 enum RL_FILTER_LINEAR = 0x2601; // GL_LINEAR 51 enum RL_FILTER_MIP_NEAREST = 0x2700; // GL_NEAREST_MIPMAP_NEAREST 52 enum RL_FILTER_NEAREST_MIP_LINEAR = 0x2702; // GL_NEAREST_MIPMAP_LINEAR 53 enum RL_FILTER_LINEAR_MIP_NEAREST = 0x2701; // GL_LINEAR_MIPMAP_NEAREST 54 enum RL_FILTER_MIP_LINEAR = 0x2703; // GL_LINEAR_MIPMAP_LINEAR 55 56 enum RL_WRAP_REPEAT = 0x2901; // GL_REPEAT 57 enum RL_WRAP_CLAMP = 0x812F; // GL_CLAMP_TO_EDGE 58 enum RL_WRAP_MIRROR_REPEAT = 0x8370; // GL_MIRRORED_REPEAT 59 enum RL_WRAP_MIRROR_CLAMP = 0x8742; // GL_MIRROR_CLAMP_EXT 60 61 // Matrix modes (equivalent to OpenGL) 62 enum RL_MODELVIEW = 0x1700; // GL_MODELVIEW 63 enum RL_PROJECTION = 0x1701; // GL_PROJECTION 64 enum RL_TEXTURE = 0x1702; // GL_TEXTURE 65 66 // Primitive assembly draw modes 67 enum RL_LINES = 0x0001; // GL_LINES 68 enum RL_TRIANGLES = 0x0004; // GL_TRIANGLES 69 enum RL_QUADS = 0x0007; // GL_QUADS 70 71 //---------------------------------------------------------------------------------- 72 // Types and Structures Definition 73 //---------------------------------------------------------------------------------- 74 enum GlVersion 75 { 76 OPENGL_11 = 1, 77 OPENGL_21 = 2, 78 OPENGL_33 = 3, 79 OPENGL_ES_20 = 4 80 } 81 82 enum FramebufferAttachType 83 { 84 RL_ATTACHMENT_COLOR_CHANNEL0 = 0, 85 RL_ATTACHMENT_COLOR_CHANNEL1 = 1, 86 RL_ATTACHMENT_COLOR_CHANNEL2 = 2, 87 RL_ATTACHMENT_COLOR_CHANNEL3 = 3, 88 RL_ATTACHMENT_COLOR_CHANNEL4 = 4, 89 RL_ATTACHMENT_COLOR_CHANNEL5 = 5, 90 RL_ATTACHMENT_COLOR_CHANNEL6 = 6, 91 RL_ATTACHMENT_COLOR_CHANNEL7 = 7, 92 RL_ATTACHMENT_DEPTH = 100, 93 RL_ATTACHMENT_STENCIL = 200 94 } 95 96 enum FramebufferTexType 97 { 98 RL_ATTACHMENT_CUBEMAP_POSITIVE_X = 0, 99 RL_ATTACHMENT_CUBEMAP_NEGATIVE_X = 1, 100 RL_ATTACHMENT_CUBEMAP_POSITIVE_Y = 2, 101 RL_ATTACHMENT_CUBEMAP_NEGATIVE_Y = 3, 102 RL_ATTACHMENT_CUBEMAP_POSITIVE_Z = 4, 103 RL_ATTACHMENT_CUBEMAP_NEGATIVE_Z = 5, 104 RL_ATTACHMENT_TEXTURE2D = 100, 105 RL_ATTACHMENT_RENDERBUFFER = 200 106 } 107 108 // Prevents name mangling of functions 109 110 //------------------------------------------------------------------------------------ 111 // Functions Declaration - Matrix operations 112 //------------------------------------------------------------------------------------ 113 void rlMatrixMode (int mode); // Choose the current matrix to be transformed 114 void rlPushMatrix (); // Push the current matrix to stack 115 void rlPopMatrix (); // Pop lattest inserted matrix from stack 116 void rlLoadIdentity (); // Reset current matrix to identity matrix 117 void rlTranslatef (float x, float y, float z); // Multiply the current matrix by a translation matrix 118 void rlRotatef (float angleDeg, float x, float y, float z); // Multiply the current matrix by a rotation matrix 119 void rlScalef (float x, float y, float z); // Multiply the current matrix by a scaling matrix 120 void rlMultMatrixf (float* matf); // Multiply the current matrix by another matrix 121 void rlFrustum (double left, double right, double bottom, double top, double znear, double zfar); 122 void rlOrtho (double left, double right, double bottom, double top, double znear, double zfar); 123 void rlViewport (int x, int y, int width, int height); // Set the viewport area 124 125 //------------------------------------------------------------------------------------ 126 // Functions Declaration - Vertex level operations 127 //------------------------------------------------------------------------------------ 128 void rlBegin (int mode); // Initialize drawing mode (how to organize vertex) 129 void rlEnd (); // Finish vertex providing 130 void rlVertex2i (int x, int y); // Define one vertex (position) - 2 int 131 void rlVertex2f (float x, float y); // Define one vertex (position) - 2 float 132 void rlVertex3f (float x, float y, float z); // Define one vertex (position) - 3 float 133 void rlTexCoord2f (float x, float y); // Define one vertex (texture coordinate) - 2 float 134 void rlNormal3f (float x, float y, float z); // Define one vertex (normal) - 3 float 135 void rlColor4ub (ubyte r, ubyte g, ubyte b, ubyte a); // Define one vertex (color) - 4 byte 136 void rlColor3f (float x, float y, float z); // Define one vertex (color) - 3 float 137 void rlColor4f (float x, float y, float z, float w); // Define one vertex (color) - 4 float 138 139 //------------------------------------------------------------------------------------ 140 // Functions Declaration - OpenGL equivalent functions (common to 1.1, 3.3+, ES2) 141 // NOTE: This functions are used to completely abstract raylib code from OpenGL layer 142 //------------------------------------------------------------------------------------ 143 void rlEnableTexture (uint id); // Enable texture usage 144 void rlDisableTexture (); // Disable texture usage 145 void rlTextureParameters (uint id, int param, int value); // Set texture parameters (filter, wrap) 146 void rlEnableShader (uint id); // Enable shader program usage 147 void rlDisableShader (); // Disable shader program usage 148 void rlEnableFramebuffer (uint id); // Enable render texture (fbo) 149 void rlDisableFramebuffer (); // Disable render texture (fbo), return to default framebuffer 150 void rlEnableDepthTest (); // Enable depth test 151 void rlDisableDepthTest (); // Disable depth test 152 void rlEnableDepthMask (); // Enable depth write 153 void rlDisableDepthMask (); // Disable depth write 154 void rlEnableBackfaceCulling (); // Enable backface culling 155 void rlDisableBackfaceCulling (); // Disable backface culling 156 void rlEnableScissorTest (); // Enable scissor test 157 void rlDisableScissorTest (); // Disable scissor test 158 void rlScissor (int x, int y, int width, int height); // Scissor test 159 void rlEnableWireMode (); // Enable wire mode 160 void rlDisableWireMode (); // Disable wire mode 161 void rlSetLineWidth (float width); // Set the line drawing width 162 float rlGetLineWidth (); // Get the line drawing width 163 void rlEnableSmoothLines (); // Enable line aliasing 164 void rlDisableSmoothLines (); // Disable line aliasing 165 166 void rlClearColor (ubyte r, ubyte g, ubyte b, ubyte a); // Clear color buffer with color 167 void rlClearScreenBuffers (); // Clear used screen buffers (color and depth) 168 void rlUpdateBuffer (int bufferId, void* data, int dataSize); // Update GPU buffer with new data 169 uint rlLoadAttribBuffer (uint vaoId, int shaderLoc, void* buffer, int size, bool dynamic); // Load a new attributes buffer 170 171 //------------------------------------------------------------------------------------ 172 // Functions Declaration - rlgl functionality 173 //------------------------------------------------------------------------------------ 174 void rlglInit (int width, int height); // Initialize rlgl (buffers, shaders, textures, states) 175 void rlglClose (); // De-inititialize rlgl (buffers, shaders, textures) 176 void rlglDraw (); // Update and draw default internal buffers 177 void rlCheckErrors (); // Check and log OpenGL error codes 178 179 int rlGetVersion (); // Returns current OpenGL version 180 bool rlCheckBufferLimit (int vCount); // Check internal buffer overflow for a given number of vertex 181 void rlSetDebugMarker (const(char)* text); // Set debug marker for analysis 182 void rlSetBlendMode (int glSrcFactor, int glDstFactor, int glEquation); // // Set blending mode factor and equation (using OpenGL factors) 183 void rlLoadExtensions (void* loader); // Load OpenGL extensions 184 185 // Textures data management 186 uint rlLoadTexture (void* data, int width, int height, int format, int mipmapCount); // Load texture in GPU 187 uint rlLoadTextureDepth (int width, int height, bool useRenderBuffer); // Load depth texture/renderbuffer (to be attached to fbo) 188 uint rlLoadTextureCubemap (void* data, int size, int format); // Load texture cubemap 189 void rlUpdateTexture (uint id, int offsetX, int offsetY, int width, int height, int format, const(void)* data); // Update GPU texture with new data 190 void rlGetGlTextureFormats (int format, uint* glInternalFormat, uint* glFormat, uint* glType); // Get OpenGL internal formats 191 void rlUnloadTexture (uint id); // Unload texture from GPU memory 192 193 void rlGenerateMipmaps (Texture2D* texture); // Generate mipmap data for selected texture 194 void* rlReadTexturePixels (Texture2D texture); // Read texture pixel data 195 ubyte* rlReadScreenPixels (int width, int height); // Read screen pixel data (color buffer) 196 197 // Framebuffer management (fbo) 198 uint rlLoadFramebuffer (int width, int height); // Load an empty framebuffer 199 void rlFramebufferAttach (uint fboId, uint texId, int attachType, int texType); // Attach texture/renderbuffer to a framebuffer 200 bool rlFramebufferComplete (uint id); // Verify framebuffer is complete 201 void rlUnloadFramebuffer (uint id); // Delete framebuffer from GPU 202 203 // Vertex data management 204 void rlLoadMesh (Mesh* mesh, bool dynamic); // Upload vertex data into GPU and provided VAO/VBO ids 205 void rlUpdateMesh (Mesh mesh, int buffer, int count); // Update vertex or index data on GPU (upload new data to one buffer) 206 void rlUpdateMeshAt (Mesh mesh, int buffer, int count, int index); // Update vertex or index data on GPU, at index 207 void rlDrawMesh (Mesh mesh, Material material, Matrix transform); // Draw a 3d mesh with material and transform 208 void rlDrawMeshInstanced (Mesh mesh, Material material, Matrix* transforms, int count); // Draw a 3d mesh with material and transform 209 void rlUnloadMesh (Mesh mesh); // Unload mesh data from CPU and GPU