rlgl.d 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968
  1. module raylib.rlgl;
  2. import raylib;
  3. /**********************************************************************************************
  4. *
  5. * rlgl v4.5 - A multi-OpenGL abstraction layer with an immediate-mode style API
  6. *
  7. * An abstraction layer for multiple OpenGL versions (1.1, 2.1, 3.3 Core, 4.3 Core, ES 2.0)
  8. * that provides a pseudo-OpenGL 1.1 immediate-mode style API (rlVertex, rlTranslate, rlRotate...)
  9. *
  10. * When choosing an OpenGL backend different than OpenGL 1.1, some internal buffer are
  11. * initialized on rlglInit() to accumulate vertex data.
  12. *
  13. * When an internal state change is required all the stored vertex data is renderer in batch,
  14. * additionally, rlDrawRenderBatchActive() could be called to force flushing of the batch.
  15. *
  16. * Some additional resources are also loaded for convenience, here the complete list:
  17. * - Default batch (RLGL.defaultBatch): RenderBatch system to accumulate vertex data
  18. * - Default texture (RLGL.defaultTextureId): 1x1 white pixel R8G8B8A8
  19. * - Default shader (RLGL.State.defaultShaderId, RLGL.State.defaultShaderLocs)
  20. *
  21. * Internal buffer (and additional resources) must be manually unloaded calling rlglClose().
  22. *
  23. *
  24. * CONFIGURATION:
  25. *
  26. * #define GRAPHICS_API_OPENGL_11
  27. * #define GRAPHICS_API_OPENGL_21
  28. * #define GRAPHICS_API_OPENGL_33
  29. * #define GRAPHICS_API_OPENGL_43
  30. * #define GRAPHICS_API_OPENGL_ES2
  31. * Use selected OpenGL graphics backend, should be supported by platform
  32. * Those preprocessor defines are only used on rlgl module, if OpenGL version is
  33. * required by any other module, use rlGetVersion() to check it
  34. *
  35. * #define RLGL_IMPLEMENTATION
  36. * Generates the implementation of the library into the included file.
  37. * If not defined, the library is in header only mode and can be included in other headers
  38. * or source files without problems. But only ONE file should hold the implementation.
  39. *
  40. * #define RLGL_RENDER_TEXTURES_HINT
  41. * Enable framebuffer objects (fbo) support (enabled by default)
  42. * Some GPUs could not support them despite the OpenGL version
  43. *
  44. * #define RLGL_SHOW_GL_DETAILS_INFO
  45. * Show OpenGL extensions and capabilities detailed logs on init
  46. *
  47. * #define RLGL_ENABLE_OPENGL_DEBUG_CONTEXT
  48. * Enable debug context (only available on OpenGL 4.3)
  49. *
  50. * rlgl capabilities could be customized just defining some internal
  51. * values before library inclusion (default values listed):
  52. *
  53. * #define RL_DEFAULT_BATCH_BUFFER_ELEMENTS 8192 // Default internal render batch elements limits
  54. * #define RL_DEFAULT_BATCH_BUFFERS 1 // Default number of batch buffers (multi-buffering)
  55. * #define RL_DEFAULT_BATCH_DRAWCALLS 256 // Default number of batch draw calls (by state changes: mode, texture)
  56. * #define RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS 4 // Maximum number of textures units that can be activated on batch drawing (SetShaderValueTexture())
  57. *
  58. * #define RL_MAX_MATRIX_STACK_SIZE 32 // Maximum size of internal Matrix stack
  59. * #define RL_MAX_SHADER_LOCATIONS 32 // Maximum number of shader locations supported
  60. * #define RL_CULL_DISTANCE_NEAR 0.01 // Default projection matrix near cull distance
  61. * #define RL_CULL_DISTANCE_FAR 1000.0 // Default projection matrix far cull distance
  62. *
  63. * When loading a shader, the following vertex attribute and uniform
  64. * location names are tried to be set automatically:
  65. *
  66. * #define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Bound by default to shader location: 0
  67. * #define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Bound by default to shader location: 1
  68. * #define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Bound by default to shader location: 2
  69. * #define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Bound by default to shader location: 3
  70. * #define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Bound by default to shader location: 4
  71. * #define RL_DEFAULT_SHADER_UNIFORM_NAME_MVP "mvp" // model-view-projection matrix
  72. * #define RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW "matView" // view matrix
  73. * #define RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION "matProjection" // projection matrix
  74. * #define RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL "matModel" // model matrix
  75. * #define RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL "matNormal" // normal matrix (transpose(inverse(matModelView))
  76. * #define RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR "colDiffuse" // color diffuse (base tint color, multiplied by texture color)
  77. * #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0 "texture0" // texture0 (texture slot active 0)
  78. * #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1 "texture1" // texture1 (texture slot active 1)
  79. * #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2 "texture2" // texture2 (texture slot active 2)
  80. *
  81. * DEPENDENCIES:
  82. *
  83. * - OpenGL libraries (depending on platform and OpenGL version selected)
  84. * - GLAD OpenGL extensions loading library (only for OpenGL 3.3 Core, 4.3 Core)
  85. *
  86. *
  87. * LICENSE: zlib/libpng
  88. *
  89. * Copyright (c) 2014-2023 Ramon Santamaria (@raysan5)
  90. *
  91. * This software is provided "as-is", without any express or implied warranty. In no event
  92. * will the authors be held liable for any damages arising from the use of this software.
  93. *
  94. * Permission is granted to anyone to use this software for any purpose, including commercial
  95. * applications, and to alter it and redistribute it freely, subject to the following restrictions:
  96. *
  97. * 1. The origin of this software must not be misrepresented; you must not claim that you
  98. * wrote the original software. If you use this software in a product, an acknowledgment
  99. * in the product documentation would be appreciated but is not required.
  100. *
  101. * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
  102. * as being the original software.
  103. *
  104. * 3. This notice may not be removed or altered from any source distribution.
  105. *
  106. **********************************************************************************************/
  107. extern (C):
  108. enum RLGL_VERSION = "4.5";
  109. // Function specifiers in case library is build/used as a shared library (Windows)
  110. // NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll
  111. // We are building the library as a Win32 shared library (.dll)
  112. // We are using the library as a Win32 shared library (.dll)
  113. // Function specifiers definition // Functions defined as 'extern' by default (implicit specifiers)
  114. // Support TRACELOG macros
  115. // Allow custom memory allocators
  116. // Security check in case no GRAPHICS_API_OPENGL_* defined
  117. // Security check in case multiple GRAPHICS_API_OPENGL_* defined
  118. // OpenGL 2.1 uses most of OpenGL 3.3 Core functionality
  119. // WARNING: Specific parts are checked with #if defines
  120. // OpenGL 4.3 uses OpenGL 3.3 Core functionality
  121. // Support framebuffer objects by default
  122. // NOTE: Some driver implementation do not support it, despite they should
  123. //----------------------------------------------------------------------------------
  124. // Defines and Macros
  125. //----------------------------------------------------------------------------------
  126. // Default internal render batch elements limits
  127. // This is the maximum amount of elements (quads) per batch
  128. // NOTE: Be careful with text, every letter maps to a quad
  129. enum RL_DEFAULT_BATCH_BUFFER_ELEMENTS = 8192;
  130. // We reduce memory sizes for embedded systems (RPI and HTML5)
  131. // NOTE: On HTML5 (emscripten) this is allocated on heap,
  132. // by default it's only 16MB!...just take care...
  133. enum RL_DEFAULT_BATCH_BUFFERS = 1; // Default number of batch buffers (multi-buffering)
  134. enum RL_DEFAULT_BATCH_DRAWCALLS = 256; // Default number of batch draw calls (by state changes: mode, texture)
  135. enum RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS = 4; // Maximum number of textures units that can be activated on batch drawing (SetShaderValueTexture())
  136. // Internal Matrix stack
  137. enum RL_MAX_MATRIX_STACK_SIZE = 32; // Maximum size of Matrix stack
  138. // Shader limits
  139. enum RL_MAX_SHADER_LOCATIONS = 32; // Maximum number of shader locations supported
  140. // Projection matrix culling
  141. enum RL_CULL_DISTANCE_NEAR = 0.01; // Default near cull distance
  142. enum RL_CULL_DISTANCE_FAR = 1000.0; // Default far cull distance
  143. // Texture parameters (equivalent to OpenGL defines)
  144. enum RL_TEXTURE_WRAP_S = 0x2802; // GL_TEXTURE_WRAP_S
  145. enum RL_TEXTURE_WRAP_T = 0x2803; // GL_TEXTURE_WRAP_T
  146. enum RL_TEXTURE_MAG_FILTER = 0x2800; // GL_TEXTURE_MAG_FILTER
  147. enum RL_TEXTURE_MIN_FILTER = 0x2801; // GL_TEXTURE_MIN_FILTER
  148. enum RL_TEXTURE_FILTER_NEAREST = 0x2600; // GL_NEAREST
  149. enum RL_TEXTURE_FILTER_LINEAR = 0x2601; // GL_LINEAR
  150. enum RL_TEXTURE_FILTER_MIP_NEAREST = 0x2700; // GL_NEAREST_MIPMAP_NEAREST
  151. enum RL_TEXTURE_FILTER_NEAREST_MIP_LINEAR = 0x2702; // GL_NEAREST_MIPMAP_LINEAR
  152. enum RL_TEXTURE_FILTER_LINEAR_MIP_NEAREST = 0x2701; // GL_LINEAR_MIPMAP_NEAREST
  153. enum RL_TEXTURE_FILTER_MIP_LINEAR = 0x2703; // GL_LINEAR_MIPMAP_LINEAR
  154. enum RL_TEXTURE_FILTER_ANISOTROPIC = 0x3000; // Anisotropic filter (custom identifier)
  155. enum RL_TEXTURE_MIPMAP_BIAS_RATIO = 0x4000; // Texture mipmap bias, percentage ratio (custom identifier)
  156. enum RL_TEXTURE_WRAP_REPEAT = 0x2901; // GL_REPEAT
  157. enum RL_TEXTURE_WRAP_CLAMP = 0x812F; // GL_CLAMP_TO_EDGE
  158. enum RL_TEXTURE_WRAP_MIRROR_REPEAT = 0x8370; // GL_MIRRORED_REPEAT
  159. enum RL_TEXTURE_WRAP_MIRROR_CLAMP = 0x8742; // GL_MIRROR_CLAMP_EXT
  160. // Matrix modes (equivalent to OpenGL)
  161. enum RL_MODELVIEW = 0x1700; // GL_MODELVIEW
  162. enum RL_PROJECTION = 0x1701; // GL_PROJECTION
  163. enum RL_TEXTURE = 0x1702; // GL_TEXTURE
  164. // Primitive assembly draw modes
  165. enum RL_LINES = 0x0001; // GL_LINES
  166. enum RL_TRIANGLES = 0x0004; // GL_TRIANGLES
  167. enum RL_QUADS = 0x0007; // GL_QUADS
  168. // GL equivalent data types
  169. enum RL_UNSIGNED_BYTE = 0x1401; // GL_UNSIGNED_BYTE
  170. enum RL_FLOAT = 0x1406; // GL_FLOAT
  171. // GL buffer usage hint
  172. enum RL_STREAM_DRAW = 0x88E0; // GL_STREAM_DRAW
  173. enum RL_STREAM_READ = 0x88E1; // GL_STREAM_READ
  174. enum RL_STREAM_COPY = 0x88E2; // GL_STREAM_COPY
  175. enum RL_STATIC_DRAW = 0x88E4; // GL_STATIC_DRAW
  176. enum RL_STATIC_READ = 0x88E5; // GL_STATIC_READ
  177. enum RL_STATIC_COPY = 0x88E6; // GL_STATIC_COPY
  178. enum RL_DYNAMIC_DRAW = 0x88E8; // GL_DYNAMIC_DRAW
  179. enum RL_DYNAMIC_READ = 0x88E9; // GL_DYNAMIC_READ
  180. enum RL_DYNAMIC_COPY = 0x88EA; // GL_DYNAMIC_COPY
  181. // GL Shader type
  182. enum RL_FRAGMENT_SHADER = 0x8B30; // GL_FRAGMENT_SHADER
  183. enum RL_VERTEX_SHADER = 0x8B31; // GL_VERTEX_SHADER
  184. enum RL_COMPUTE_SHADER = 0x91B9; // GL_COMPUTE_SHADER
  185. // GL blending factors
  186. enum RL_ZERO = 0; // GL_ZERO
  187. enum RL_ONE = 1; // GL_ONE
  188. enum RL_SRC_COLOR = 0x0300; // GL_SRC_COLOR
  189. enum RL_ONE_MINUS_SRC_COLOR = 0x0301; // GL_ONE_MINUS_SRC_COLOR
  190. enum RL_SRC_ALPHA = 0x0302; // GL_SRC_ALPHA
  191. enum RL_ONE_MINUS_SRC_ALPHA = 0x0303; // GL_ONE_MINUS_SRC_ALPHA
  192. enum RL_DST_ALPHA = 0x0304; // GL_DST_ALPHA
  193. enum RL_ONE_MINUS_DST_ALPHA = 0x0305; // GL_ONE_MINUS_DST_ALPHA
  194. enum RL_DST_COLOR = 0x0306; // GL_DST_COLOR
  195. enum RL_ONE_MINUS_DST_COLOR = 0x0307; // GL_ONE_MINUS_DST_COLOR
  196. enum RL_SRC_ALPHA_SATURATE = 0x0308; // GL_SRC_ALPHA_SATURATE
  197. enum RL_CONSTANT_COLOR = 0x8001; // GL_CONSTANT_COLOR
  198. enum RL_ONE_MINUS_CONSTANT_COLOR = 0x8002; // GL_ONE_MINUS_CONSTANT_COLOR
  199. enum RL_CONSTANT_ALPHA = 0x8003; // GL_CONSTANT_ALPHA
  200. enum RL_ONE_MINUS_CONSTANT_ALPHA = 0x8004; // GL_ONE_MINUS_CONSTANT_ALPHA
  201. // GL blending functions/equations
  202. enum RL_FUNC_ADD = 0x8006; // GL_FUNC_ADD
  203. enum RL_MIN = 0x8007; // GL_MIN
  204. enum RL_MAX = 0x8008; // GL_MAX
  205. enum RL_FUNC_SUBTRACT = 0x800A; // GL_FUNC_SUBTRACT
  206. enum RL_FUNC_REVERSE_SUBTRACT = 0x800B; // GL_FUNC_REVERSE_SUBTRACT
  207. enum RL_BLEND_EQUATION = 0x8009; // GL_BLEND_EQUATION
  208. enum RL_BLEND_EQUATION_RGB = 0x8009; // GL_BLEND_EQUATION_RGB // (Same as BLEND_EQUATION)
  209. enum RL_BLEND_EQUATION_ALPHA = 0x883D; // GL_BLEND_EQUATION_ALPHA
  210. enum RL_BLEND_DST_RGB = 0x80C8; // GL_BLEND_DST_RGB
  211. enum RL_BLEND_SRC_RGB = 0x80C9; // GL_BLEND_SRC_RGB
  212. enum RL_BLEND_DST_ALPHA = 0x80CA; // GL_BLEND_DST_ALPHA
  213. enum RL_BLEND_SRC_ALPHA = 0x80CB; // GL_BLEND_SRC_ALPHA
  214. enum RL_BLEND_COLOR = 0x8005; // GL_BLEND_COLOR
  215. //----------------------------------------------------------------------------------
  216. // Types and Structures Definition
  217. //----------------------------------------------------------------------------------
  218. // Boolean type
  219. // Matrix, 4x4 components, column major, OpenGL style, right handed
  220. // Matrix first row (4 components)
  221. // Matrix second row (4 components)
  222. // Matrix third row (4 components)
  223. // Matrix fourth row (4 components)
  224. // Dynamic vertex buffers (position + texcoords + colors + indices arrays)
  225. struct rlVertexBuffer
  226. {
  227. int elementCount; // Number of elements in the buffer (QUADS)
  228. float* vertices; // Vertex position (XYZ - 3 components per vertex) (shader-location = 0)
  229. float* texcoords; // Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
  230. ubyte* colors; // Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
  231. uint* indices; // Vertex indices (in case vertex data comes indexed) (6 indices per quad)
  232. // Vertex indices (in case vertex data comes indexed) (6 indices per quad)
  233. uint vaoId; // OpenGL Vertex Array Object id
  234. uint[4] vboId; // OpenGL Vertex Buffer Objects id (4 types of vertex data)
  235. }
  236. // Draw call type
  237. // NOTE: Only texture changes register a new draw, other state-change-related elements are not
  238. // used at this moment (vaoId, shaderId, matrices), raylib just forces a batch draw call if any
  239. // of those state-change happens (this is done in core module)
  240. struct rlDrawCall
  241. {
  242. int mode; // Drawing mode: LINES, TRIANGLES, QUADS
  243. int vertexCount; // Number of vertex of the draw
  244. int vertexAlignment; // Number of vertex required for index alignment (LINES, TRIANGLES)
  245. //unsigned int vaoId; // Vertex array id to be used on the draw -> Using RLGL.currentBatch->vertexBuffer.vaoId
  246. //unsigned int shaderId; // Shader id to be used on the draw -> Using RLGL.currentShaderId
  247. uint textureId; // Texture id to be used on the draw -> Use to create new draw call if changes
  248. //Matrix projection; // Projection matrix for this draw -> Using RLGL.projection by default
  249. //Matrix modelview; // Modelview matrix for this draw -> Using RLGL.modelview by default
  250. }
  251. // rlRenderBatch type
  252. struct rlRenderBatch
  253. {
  254. int bufferCount; // Number of vertex buffers (multi-buffering support)
  255. int currentBuffer; // Current buffer tracking in case of multi-buffering
  256. rlVertexBuffer* vertexBuffer; // Dynamic buffer(s) for vertex data
  257. rlDrawCall* draws; // Draw calls array, depends on textureId
  258. int drawCounter; // Draw calls counter
  259. float currentDepth; // Current depth value for next draw
  260. }
  261. // OpenGL version
  262. enum rlGlVersion
  263. {
  264. RL_OPENGL_11 = 1, // OpenGL 1.1
  265. RL_OPENGL_21 = 2, // OpenGL 2.1 (GLSL 120)
  266. RL_OPENGL_33 = 3, // OpenGL 3.3 (GLSL 330)
  267. RL_OPENGL_43 = 4, // OpenGL 4.3 (using GLSL 330)
  268. RL_OPENGL_ES_20 = 5 // OpenGL ES 2.0 (GLSL 100)
  269. }
  270. // Trace log level
  271. // NOTE: Organized by priority level
  272. enum rlTraceLogLevel
  273. {
  274. RL_LOG_ALL = 0, // Display all logs
  275. RL_LOG_TRACE = 1, // Trace logging, intended for internal use only
  276. RL_LOG_DEBUG = 2, // Debug logging, used for internal debugging, it should be disabled on release builds
  277. RL_LOG_INFO = 3, // Info logging, used for program execution info
  278. RL_LOG_WARNING = 4, // Warning logging, used on recoverable failures
  279. RL_LOG_ERROR = 5, // Error logging, used on unrecoverable failures
  280. RL_LOG_FATAL = 6, // Fatal logging, used to abort program: exit(EXIT_FAILURE)
  281. RL_LOG_NONE = 7 // Disable logging
  282. }
  283. // Texture pixel formats
  284. // NOTE: Support depends on OpenGL version
  285. enum rlPixelFormat
  286. {
  287. RL_PIXELFORMAT_UNCOMPRESSED_GRAYSCALE = 1, // 8 bit per pixel (no alpha)
  288. RL_PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA = 2, // 8*2 bpp (2 channels)
  289. RL_PIXELFORMAT_UNCOMPRESSED_R5G6B5 = 3, // 16 bpp
  290. RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8 = 4, // 24 bpp
  291. RL_PIXELFORMAT_UNCOMPRESSED_R5G5B5A1 = 5, // 16 bpp (1 bit alpha)
  292. RL_PIXELFORMAT_UNCOMPRESSED_R4G4B4A4 = 6, // 16 bpp (4 bit alpha)
  293. RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 = 7, // 32 bpp
  294. RL_PIXELFORMAT_UNCOMPRESSED_R32 = 8, // 32 bpp (1 channel - float)
  295. RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32 = 9, // 32*3 bpp (3 channels - float)
  296. RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32A32 = 10, // 32*4 bpp (4 channels - float)
  297. RL_PIXELFORMAT_COMPRESSED_DXT1_RGB = 11, // 4 bpp (no alpha)
  298. RL_PIXELFORMAT_COMPRESSED_DXT1_RGBA = 12, // 4 bpp (1 bit alpha)
  299. RL_PIXELFORMAT_COMPRESSED_DXT3_RGBA = 13, // 8 bpp
  300. RL_PIXELFORMAT_COMPRESSED_DXT5_RGBA = 14, // 8 bpp
  301. RL_PIXELFORMAT_COMPRESSED_ETC1_RGB = 15, // 4 bpp
  302. RL_PIXELFORMAT_COMPRESSED_ETC2_RGB = 16, // 4 bpp
  303. RL_PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA = 17, // 8 bpp
  304. RL_PIXELFORMAT_COMPRESSED_PVRT_RGB = 18, // 4 bpp
  305. RL_PIXELFORMAT_COMPRESSED_PVRT_RGBA = 19, // 4 bpp
  306. RL_PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA = 20, // 8 bpp
  307. RL_PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA = 21 // 2 bpp
  308. }
  309. // Texture parameters: filter mode
  310. // NOTE 1: Filtering considers mipmaps if available in the texture
  311. // NOTE 2: Filter is accordingly set for minification and magnification
  312. enum rlTextureFilter
  313. {
  314. RL_TEXTURE_FILTER_POINT = 0, // No filter, just pixel approximation
  315. RL_TEXTURE_FILTER_BILINEAR = 1, // Linear filtering
  316. RL_TEXTURE_FILTER_TRILINEAR = 2, // Trilinear filtering (linear with mipmaps)
  317. RL_TEXTURE_FILTER_ANISOTROPIC_4X = 3, // Anisotropic filtering 4x
  318. RL_TEXTURE_FILTER_ANISOTROPIC_8X = 4, // Anisotropic filtering 8x
  319. RL_TEXTURE_FILTER_ANISOTROPIC_16X = 5 // Anisotropic filtering 16x
  320. }
  321. // Color blending modes (pre-defined)
  322. enum rlBlendMode
  323. {
  324. RL_BLEND_ALPHA = 0, // Blend textures considering alpha (default)
  325. RL_BLEND_ADDITIVE = 1, // Blend textures adding colors
  326. RL_BLEND_MULTIPLIED = 2, // Blend textures multiplying colors
  327. RL_BLEND_ADD_COLORS = 3, // Blend textures adding colors (alternative)
  328. RL_BLEND_SUBTRACT_COLORS = 4, // Blend textures subtracting colors (alternative)
  329. RL_BLEND_ALPHA_PREMULTIPLY = 5, // Blend premultiplied textures considering alpha
  330. RL_BLEND_CUSTOM = 6, // Blend textures using custom src/dst factors (use rlSetBlendFactors())
  331. RL_BLEND_CUSTOM_SEPARATE = 7 // Blend textures using custom src/dst factors (use rlSetBlendFactorsSeparate())
  332. }
  333. // Shader location point type
  334. enum rlShaderLocationIndex
  335. {
  336. RL_SHADER_LOC_VERTEX_POSITION = 0, // Shader location: vertex attribute: position
  337. RL_SHADER_LOC_VERTEX_TEXCOORD01 = 1, // Shader location: vertex attribute: texcoord01
  338. RL_SHADER_LOC_VERTEX_TEXCOORD02 = 2, // Shader location: vertex attribute: texcoord02
  339. RL_SHADER_LOC_VERTEX_NORMAL = 3, // Shader location: vertex attribute: normal
  340. RL_SHADER_LOC_VERTEX_TANGENT = 4, // Shader location: vertex attribute: tangent
  341. RL_SHADER_LOC_VERTEX_COLOR = 5, // Shader location: vertex attribute: color
  342. RL_SHADER_LOC_MATRIX_MVP = 6, // Shader location: matrix uniform: model-view-projection
  343. RL_SHADER_LOC_MATRIX_VIEW = 7, // Shader location: matrix uniform: view (camera transform)
  344. RL_SHADER_LOC_MATRIX_PROJECTION = 8, // Shader location: matrix uniform: projection
  345. RL_SHADER_LOC_MATRIX_MODEL = 9, // Shader location: matrix uniform: model (transform)
  346. RL_SHADER_LOC_MATRIX_NORMAL = 10, // Shader location: matrix uniform: normal
  347. RL_SHADER_LOC_VECTOR_VIEW = 11, // Shader location: vector uniform: view
  348. RL_SHADER_LOC_COLOR_DIFFUSE = 12, // Shader location: vector uniform: diffuse color
  349. RL_SHADER_LOC_COLOR_SPECULAR = 13, // Shader location: vector uniform: specular color
  350. RL_SHADER_LOC_COLOR_AMBIENT = 14, // Shader location: vector uniform: ambient color
  351. RL_SHADER_LOC_MAP_ALBEDO = 15, // Shader location: sampler2d texture: albedo (same as: RL_SHADER_LOC_MAP_DIFFUSE)
  352. RL_SHADER_LOC_MAP_METALNESS = 16, // Shader location: sampler2d texture: metalness (same as: RL_SHADER_LOC_MAP_SPECULAR)
  353. RL_SHADER_LOC_MAP_NORMAL = 17, // Shader location: sampler2d texture: normal
  354. RL_SHADER_LOC_MAP_ROUGHNESS = 18, // Shader location: sampler2d texture: roughness
  355. RL_SHADER_LOC_MAP_OCCLUSION = 19, // Shader location: sampler2d texture: occlusion
  356. RL_SHADER_LOC_MAP_EMISSION = 20, // Shader location: sampler2d texture: emission
  357. RL_SHADER_LOC_MAP_HEIGHT = 21, // Shader location: sampler2d texture: height
  358. RL_SHADER_LOC_MAP_CUBEMAP = 22, // Shader location: samplerCube texture: cubemap
  359. RL_SHADER_LOC_MAP_IRRADIANCE = 23, // Shader location: samplerCube texture: irradiance
  360. RL_SHADER_LOC_MAP_PREFILTER = 24, // Shader location: samplerCube texture: prefilter
  361. RL_SHADER_LOC_MAP_BRDF = 25 // Shader location: sampler2d texture: brdf
  362. }
  363. enum RL_SHADER_LOC_MAP_DIFFUSE = rlShaderLocationIndex.RL_SHADER_LOC_MAP_ALBEDO;
  364. enum RL_SHADER_LOC_MAP_SPECULAR = rlShaderLocationIndex.RL_SHADER_LOC_MAP_METALNESS;
  365. // Shader uniform data type
  366. enum rlShaderUniformDataType
  367. {
  368. RL_SHADER_UNIFORM_FLOAT = 0, // Shader uniform type: float
  369. RL_SHADER_UNIFORM_VEC2 = 1, // Shader uniform type: vec2 (2 float)
  370. RL_SHADER_UNIFORM_VEC3 = 2, // Shader uniform type: vec3 (3 float)
  371. RL_SHADER_UNIFORM_VEC4 = 3, // Shader uniform type: vec4 (4 float)
  372. RL_SHADER_UNIFORM_INT = 4, // Shader uniform type: int
  373. RL_SHADER_UNIFORM_IVEC2 = 5, // Shader uniform type: ivec2 (2 int)
  374. RL_SHADER_UNIFORM_IVEC3 = 6, // Shader uniform type: ivec3 (3 int)
  375. RL_SHADER_UNIFORM_IVEC4 = 7, // Shader uniform type: ivec4 (4 int)
  376. RL_SHADER_UNIFORM_SAMPLER2D = 8 // Shader uniform type: sampler2d
  377. }
  378. // Shader attribute data types
  379. enum rlShaderAttributeDataType
  380. {
  381. RL_SHADER_ATTRIB_FLOAT = 0, // Shader attribute type: float
  382. RL_SHADER_ATTRIB_VEC2 = 1, // Shader attribute type: vec2 (2 float)
  383. RL_SHADER_ATTRIB_VEC3 = 2, // Shader attribute type: vec3 (3 float)
  384. RL_SHADER_ATTRIB_VEC4 = 3 // Shader attribute type: vec4 (4 float)
  385. }
  386. // Framebuffer attachment type
  387. // NOTE: By default up to 8 color channels defined, but it can be more
  388. enum rlFramebufferAttachType
  389. {
  390. RL_ATTACHMENT_COLOR_CHANNEL0 = 0, // Framebuffer attachment type: color 0
  391. RL_ATTACHMENT_COLOR_CHANNEL1 = 1, // Framebuffer attachment type: color 1
  392. RL_ATTACHMENT_COLOR_CHANNEL2 = 2, // Framebuffer attachment type: color 2
  393. RL_ATTACHMENT_COLOR_CHANNEL3 = 3, // Framebuffer attachment type: color 3
  394. RL_ATTACHMENT_COLOR_CHANNEL4 = 4, // Framebuffer attachment type: color 4
  395. RL_ATTACHMENT_COLOR_CHANNEL5 = 5, // Framebuffer attachment type: color 5
  396. RL_ATTACHMENT_COLOR_CHANNEL6 = 6, // Framebuffer attachment type: color 6
  397. RL_ATTACHMENT_COLOR_CHANNEL7 = 7, // Framebuffer attachment type: color 7
  398. RL_ATTACHMENT_DEPTH = 100, // Framebuffer attachment type: depth
  399. RL_ATTACHMENT_STENCIL = 200 // Framebuffer attachment type: stencil
  400. }
  401. // Framebuffer texture attachment type
  402. enum rlFramebufferAttachTextureType
  403. {
  404. RL_ATTACHMENT_CUBEMAP_POSITIVE_X = 0, // Framebuffer texture attachment type: cubemap, +X side
  405. RL_ATTACHMENT_CUBEMAP_NEGATIVE_X = 1, // Framebuffer texture attachment type: cubemap, -X side
  406. RL_ATTACHMENT_CUBEMAP_POSITIVE_Y = 2, // Framebuffer texture attachment type: cubemap, +Y side
  407. RL_ATTACHMENT_CUBEMAP_NEGATIVE_Y = 3, // Framebuffer texture attachment type: cubemap, -Y side
  408. RL_ATTACHMENT_CUBEMAP_POSITIVE_Z = 4, // Framebuffer texture attachment type: cubemap, +Z side
  409. RL_ATTACHMENT_CUBEMAP_NEGATIVE_Z = 5, // Framebuffer texture attachment type: cubemap, -Z side
  410. RL_ATTACHMENT_TEXTURE2D = 100, // Framebuffer texture attachment type: texture2d
  411. RL_ATTACHMENT_RENDERBUFFER = 200 // Framebuffer texture attachment type: renderbuffer
  412. }
  413. // Face culling mode
  414. enum rlCullMode
  415. {
  416. RL_CULL_FACE_FRONT = 0,
  417. RL_CULL_FACE_BACK = 1
  418. }
  419. //------------------------------------------------------------------------------------
  420. // Functions Declaration - Matrix operations
  421. //------------------------------------------------------------------------------------
  422. // Prevents name mangling of functions
  423. void rlMatrixMode(int mode); // Choose the current matrix to be transformed
  424. void rlPushMatrix(); // Push the current matrix to stack
  425. void rlPopMatrix(); // Pop latest inserted matrix from stack
  426. void rlLoadIdentity(); // Reset current matrix to identity matrix
  427. void rlTranslatef(float x, float y, float z); // Multiply the current matrix by a translation matrix
  428. void rlRotatef(float angle, float x, float y, float z); // Multiply the current matrix by a rotation matrix
  429. void rlScalef(float x, float y, float z); // Multiply the current matrix by a scaling matrix
  430. void rlMultMatrixf(const(float)* matf); // Multiply the current matrix by another matrix
  431. void rlFrustum(double left, double right, double bottom, double top, double znear, double zfar);
  432. void rlOrtho(double left, double right, double bottom, double top, double znear, double zfar);
  433. void rlViewport(int x, int y, int width, int height); // Set the viewport area
  434. //------------------------------------------------------------------------------------
  435. // Functions Declaration - Vertex level operations
  436. //------------------------------------------------------------------------------------
  437. void rlBegin(int mode); // Initialize drawing mode (how to organize vertex)
  438. void rlEnd(); // Finish vertex providing
  439. void rlVertex2i(int x, int y); // Define one vertex (position) - 2 int
  440. void rlVertex2f(float x, float y); // Define one vertex (position) - 2 float
  441. void rlVertex3f(float x, float y, float z); // Define one vertex (position) - 3 float
  442. void rlTexCoord2f(float x, float y); // Define one vertex (texture coordinate) - 2 float
  443. void rlNormal3f(float x, float y, float z); // Define one vertex (normal) - 3 float
  444. void rlColor4ub(ubyte r, ubyte g, ubyte b, ubyte a); // Define one vertex (color) - 4 byte
  445. void rlColor3f(float x, float y, float z); // Define one vertex (color) - 3 float
  446. void rlColor4f(float x, float y, float z, float w); // Define one vertex (color) - 4 float
  447. //------------------------------------------------------------------------------------
  448. // Functions Declaration - OpenGL style functions (common to 1.1, 3.3+, ES2)
  449. // NOTE: This functions are used to completely abstract raylib code from OpenGL layer,
  450. // some of them are direct wrappers over OpenGL calls, some others are custom
  451. //------------------------------------------------------------------------------------
  452. // Vertex buffers state
  453. bool rlEnableVertexArray(uint vaoId); // Enable vertex array (VAO, if supported)
  454. void rlDisableVertexArray(); // Disable vertex array (VAO, if supported)
  455. void rlEnableVertexBuffer(uint id); // Enable vertex buffer (VBO)
  456. void rlDisableVertexBuffer(); // Disable vertex buffer (VBO)
  457. void rlEnableVertexBufferElement(uint id); // Enable vertex buffer element (VBO element)
  458. void rlDisableVertexBufferElement(); // Disable vertex buffer element (VBO element)
  459. void rlEnableVertexAttribute(uint index); // Enable vertex attribute index
  460. void rlDisableVertexAttribute(uint index); // Disable vertex attribute index
  461. // Enable attribute state pointer
  462. // Disable attribute state pointer
  463. // Textures state
  464. void rlActiveTextureSlot(int slot); // Select and active a texture slot
  465. void rlEnableTexture(uint id); // Enable texture
  466. void rlDisableTexture(); // Disable texture
  467. void rlEnableTextureCubemap(uint id); // Enable texture cubemap
  468. void rlDisableTextureCubemap(); // Disable texture cubemap
  469. void rlTextureParameters(uint id, int param, int value); // Set texture parameters (filter, wrap)
  470. void rlCubemapParameters(uint id, int param, int value); // Set cubemap parameters (filter, wrap)
  471. // Shader state
  472. void rlEnableShader(uint id); // Enable shader program
  473. void rlDisableShader(); // Disable shader program
  474. // Framebuffer state
  475. void rlEnableFramebuffer(uint id); // Enable render texture (fbo)
  476. void rlDisableFramebuffer(); // Disable render texture (fbo), return to default framebuffer
  477. void rlActiveDrawBuffers(int count); // Activate multiple draw color buffers
  478. // General render state
  479. void rlEnableColorBlend(); // Enable color blending
  480. void rlDisableColorBlend(); // Disable color blending
  481. void rlEnableDepthTest(); // Enable depth test
  482. void rlDisableDepthTest(); // Disable depth test
  483. void rlEnableDepthMask(); // Enable depth write
  484. void rlDisableDepthMask(); // Disable depth write
  485. void rlEnableBackfaceCulling(); // Enable backface culling
  486. void rlDisableBackfaceCulling(); // Disable backface culling
  487. void rlSetCullFace(int mode); // Set face culling mode
  488. void rlEnableScissorTest(); // Enable scissor test
  489. void rlDisableScissorTest(); // Disable scissor test
  490. void rlScissor(int x, int y, int width, int height); // Scissor test
  491. void rlEnableWireMode(); // Enable wire mode
  492. void rlDisableWireMode(); // Disable wire mode
  493. void rlSetLineWidth(float width); // Set the line drawing width
  494. float rlGetLineWidth(); // Get the line drawing width
  495. void rlEnableSmoothLines(); // Enable line aliasing
  496. void rlDisableSmoothLines(); // Disable line aliasing
  497. void rlEnableStereoRender(); // Enable stereo rendering
  498. void rlDisableStereoRender(); // Disable stereo rendering
  499. bool rlIsStereoRenderEnabled(); // Check if stereo render is enabled
  500. void rlClearColor(ubyte r, ubyte g, ubyte b, ubyte a); // Clear color buffer with color
  501. void rlClearScreenBuffers(); // Clear used screen buffers (color and depth)
  502. void rlCheckErrors(); // Check and log OpenGL error codes
  503. void rlSetBlendMode(int mode); // Set blending mode
  504. void rlSetBlendFactors(int glSrcFactor, int glDstFactor, int glEquation); // Set blending mode factor and equation (using OpenGL factors)
  505. void rlSetBlendFactorsSeparate(int glSrcRGB, int glDstRGB, int glSrcAlpha, int glDstAlpha, int glEqRGB, int glEqAlpha); // Set blending mode factors and equations separately (using OpenGL factors)
  506. //------------------------------------------------------------------------------------
  507. // Functions Declaration - rlgl functionality
  508. //------------------------------------------------------------------------------------
  509. // rlgl initialization functions
  510. void rlglInit(int width, int height); // Initialize rlgl (buffers, shaders, textures, states)
  511. void rlglClose(); // De-initialize rlgl (buffers, shaders, textures)
  512. void rlLoadExtensions(void* loader); // Load OpenGL extensions (loader function required)
  513. int rlGetVersion(); // Get current OpenGL version
  514. void rlSetFramebufferWidth(int width); // Set current framebuffer width
  515. int rlGetFramebufferWidth(); // Get default framebuffer width
  516. void rlSetFramebufferHeight(int height); // Set current framebuffer height
  517. int rlGetFramebufferHeight(); // Get default framebuffer height
  518. uint rlGetTextureIdDefault(); // Get default texture id
  519. uint rlGetShaderIdDefault(); // Get default shader id
  520. int* rlGetShaderLocsDefault(); // Get default shader locations
  521. // Render batch management
  522. // NOTE: rlgl provides a default render batch to behave like OpenGL 1.1 immediate mode
  523. // but this render batch API is exposed in case of custom batches are required
  524. rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements); // Load a render batch system
  525. void rlUnloadRenderBatch(rlRenderBatch batch); // Unload render batch system
  526. void rlDrawRenderBatch(rlRenderBatch* batch); // Draw render batch data (Update->Draw->Reset)
  527. void rlSetRenderBatchActive(rlRenderBatch* batch); // Set the active render batch for rlgl (NULL for default internal)
  528. void rlDrawRenderBatchActive(); // Update and draw internal render batch
  529. bool rlCheckRenderBatchLimit(int vCount); // Check internal buffer overflow for a given number of vertex
  530. void rlSetTexture(uint id); // Set current texture for render batch and check buffers limits
  531. //------------------------------------------------------------------------------------------------------------------------
  532. // Vertex buffers management
  533. uint rlLoadVertexArray(); // Load vertex array (vao) if supported
  534. uint rlLoadVertexBuffer(const(void)* buffer, int size, bool dynamic); // Load a vertex buffer attribute
  535. uint rlLoadVertexBufferElement(const(void)* buffer, int size, bool dynamic); // Load a new attributes element buffer
  536. void rlUpdateVertexBuffer(uint bufferId, const(void)* data, int dataSize, int offset); // Update GPU buffer with new data
  537. void rlUpdateVertexBufferElements(uint id, const(void)* data, int dataSize, int offset); // Update vertex buffer elements with new data
  538. void rlUnloadVertexArray(uint vaoId);
  539. void rlUnloadVertexBuffer(uint vboId);
  540. void rlSetVertexAttribute(uint index, int compSize, int type, bool normalized, int stride, const(void)* pointer);
  541. void rlSetVertexAttributeDivisor(uint index, int divisor);
  542. void rlSetVertexAttributeDefault(int locIndex, const(void)* value, int attribType, int count); // Set vertex attribute default value
  543. void rlDrawVertexArray(int offset, int count);
  544. void rlDrawVertexArrayElements(int offset, int count, const(void)* buffer);
  545. void rlDrawVertexArrayInstanced(int offset, int count, int instances);
  546. void rlDrawVertexArrayElementsInstanced(int offset, int count, const(void)* buffer, int instances);
  547. // Textures management
  548. uint rlLoadTexture(const(void)* data, int width, int height, int format, int mipmapCount); // Load texture in GPU
  549. uint rlLoadTextureDepth(int width, int height, bool useRenderBuffer); // Load depth texture/renderbuffer (to be attached to fbo)
  550. uint rlLoadTextureCubemap(const(void)* data, int size, int format); // Load texture cubemap
  551. void rlUpdateTexture(uint id, int offsetX, int offsetY, int width, int height, int format, const(void)* data); // Update GPU texture with new data
  552. void rlGetGlTextureFormats(int format, uint* glInternalFormat, uint* glFormat, uint* glType); // Get OpenGL internal formats
  553. const(char)* rlGetPixelFormatName(uint format); // Get name string for pixel format
  554. void rlUnloadTexture(uint id); // Unload texture from GPU memory
  555. void rlGenTextureMipmaps(uint id, int width, int height, int format, int* mipmaps); // Generate mipmap data for selected texture
  556. void* rlReadTexturePixels(uint id, int width, int height, int format); // Read texture pixel data
  557. ubyte* rlReadScreenPixels(int width, int height); // Read screen pixel data (color buffer)
  558. // Framebuffer management (fbo)
  559. uint rlLoadFramebuffer(int width, int height); // Load an empty framebuffer
  560. void rlFramebufferAttach(uint fboId, uint texId, int attachType, int texType, int mipLevel); // Attach texture/renderbuffer to a framebuffer
  561. bool rlFramebufferComplete(uint id); // Verify framebuffer is complete
  562. void rlUnloadFramebuffer(uint id); // Delete framebuffer from GPU
  563. // Shaders management
  564. uint rlLoadShaderCode(const(char)* vsCode, const(char)* fsCode); // Load shader from code strings
  565. uint rlCompileShader(const(char)* shaderCode, int type); // Compile custom shader and return shader id (type: RL_VERTEX_SHADER, RL_FRAGMENT_SHADER, RL_COMPUTE_SHADER)
  566. uint rlLoadShaderProgram(uint vShaderId, uint fShaderId); // Load custom shader program
  567. void rlUnloadShaderProgram(uint id); // Unload shader program
  568. int rlGetLocationUniform(uint shaderId, const(char)* uniformName); // Get shader location uniform
  569. int rlGetLocationAttrib(uint shaderId, const(char)* attribName); // Get shader location attribute
  570. void rlSetUniform(int locIndex, const(void)* value, int uniformType, int count); // Set shader value uniform
  571. void rlSetUniformMatrix(int locIndex, Matrix mat); // Set shader value matrix
  572. void rlSetUniformSampler(int locIndex, uint textureId); // Set shader value sampler
  573. void rlSetShader(uint id, int* locs); // Set shader currently active (id and locations)
  574. // Compute shader management
  575. uint rlLoadComputeShaderProgram(uint shaderId); // Load compute shader program
  576. void rlComputeShaderDispatch(uint groupX, uint groupY, uint groupZ); // Dispatch compute shader (equivalent to *draw* for graphics pipeline)
  577. // Shader buffer storage object management (ssbo)
  578. uint rlLoadShaderBuffer(uint size, const(void)* data, int usageHint); // Load shader storage buffer object (SSBO)
  579. void rlUnloadShaderBuffer(uint ssboId); // Unload shader storage buffer object (SSBO)
  580. void rlUpdateShaderBuffer(uint id, const(void)* data, uint dataSize, uint offset); // Update SSBO buffer data
  581. void rlBindShaderBuffer(uint id, uint index); // Bind SSBO buffer
  582. void rlReadShaderBuffer(uint id, void* dest, uint count, uint offset); // Read SSBO buffer data (GPU->CPU)
  583. void rlCopyShaderBuffer(uint destId, uint srcId, uint destOffset, uint srcOffset, uint count); // Copy SSBO data between buffers
  584. uint rlGetShaderBufferSize(uint id); // Get SSBO buffer size
  585. // Buffer management
  586. void rlBindImageTexture(uint id, uint index, int format, bool readonly); // Bind image texture
  587. // Matrix state management
  588. Matrix rlGetMatrixModelview(); // Get internal modelview matrix
  589. Matrix rlGetMatrixProjection(); // Get internal projection matrix
  590. Matrix rlGetMatrixTransform(); // Get internal accumulated transform matrix
  591. Matrix rlGetMatrixProjectionStereo(int eye); // Get internal projection matrix for stereo render (selected eye)
  592. Matrix rlGetMatrixViewOffsetStereo(int eye); // Get internal view offset matrix for stereo render (selected eye)
  593. void rlSetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix)
  594. void rlSetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix)
  595. void rlSetMatrixProjectionStereo(Matrix right, Matrix left); // Set eyes projection matrices for stereo rendering
  596. void rlSetMatrixViewOffsetStereo(Matrix right, Matrix left); // Set eyes view offsets matrices for stereo rendering
  597. // Quick and dirty cube/quad buffers load->draw->unload
  598. void rlLoadDrawCube(); // Load and draw a cube
  599. void rlLoadDrawQuad(); // Load and draw a quad
  600. // RLGL_H
  601. /***********************************************************************************
  602. *
  603. * RLGL IMPLEMENTATION
  604. *
  605. ************************************************************************************/
  606. // OpenGL 1.1 library for OSX
  607. // OpenGL extensions library
  608. // APIENTRY for OpenGL function pointer declarations is required
  609. // WINGDIAPI definition. Some Windows OpenGL headers need it
  610. // OpenGL 1.1 library
  611. // GLAD extensions loading library, includes OpenGL headers
  612. // NOTE: OpenGL ES 2.0 can be enabled on PLATFORM_DESKTOP,
  613. // in that case, functions are loaded from a custom glad for OpenGL ES 2.0
  614. //#include <EGL/egl.h> // EGL library -> not required, platform layer
  615. // OpenGL ES 2.0 library
  616. // OpenGL ES 2.0 extensions library
  617. // It seems OpenGL ES 2.0 instancing entry points are not defined on Raspberry Pi
  618. // provided headers (despite being defined in official Khronos GLES2 headers)
  619. // Required for: malloc(), free()
  620. // Required for: strcmp(), strlen() [Used in rlglInit(), on extensions loading]
  621. // Required for: sqrtf(), sinf(), cosf(), floor(), log()
  622. //----------------------------------------------------------------------------------
  623. // Defines and Macros
  624. //----------------------------------------------------------------------------------
  625. // Default shader vertex attribute names to set location points
  626. // Bound by default to shader location: 0
  627. // Bound by default to shader location: 1
  628. // Bound by default to shader location: 2
  629. // Bound by default to shader location: 3
  630. // Bound by default to shader location: 4
  631. // Bound by default to shader location: 5
  632. // model-view-projection matrix
  633. // view matrix
  634. // projection matrix
  635. // model matrix
  636. // normal matrix (transpose(inverse(matModelView))
  637. // color diffuse (base tint color, multiplied by texture color)
  638. // texture0 (texture slot active 0)
  639. // texture1 (texture slot active 1)
  640. // texture2 (texture slot active 2)
  641. //----------------------------------------------------------------------------------
  642. // Types and Structures Definition
  643. //----------------------------------------------------------------------------------
  644. // Current render batch
  645. // Default internal render batch
  646. // Current active render batch vertex counter (generic, used for all batches)
  647. // Current active texture coordinate (added on glVertex*())
  648. // Current active normal (added on glVertex*())
  649. // Current active color (added on glVertex*())
  650. // Current matrix mode
  651. // Current matrix pointer
  652. // Default modelview matrix
  653. // Default projection matrix
  654. // Transform matrix to be used with rlTranslate, rlRotate, rlScale
  655. // Require transform matrix application to current draw-call vertex (if required)
  656. // Matrix stack for push/pop
  657. // Matrix stack counter
  658. // Default texture used on shapes/poly drawing (required by shader)
  659. // Active texture ids to be enabled on batch drawing (0 active by default)
  660. // Default vertex shader id (used by default shader program)
  661. // Default fragment shader id (used by default shader program)
  662. // Default shader program id, supports vertex color and diffuse texture
  663. // Default shader locations pointer to be used on rendering
  664. // Current shader id to be used on rendering (by default, defaultShaderId)
  665. // Current shader locations pointer to be used on rendering (by default, defaultShaderLocs)
  666. // Stereo rendering flag
  667. // VR stereo rendering eyes projection matrices
  668. // VR stereo rendering eyes view offset matrices
  669. // Blending variables
  670. // Blending mode active
  671. // Blending source factor
  672. // Blending destination factor
  673. // Blending equation
  674. // Blending source RGB factor
  675. // Blending destination RGB factor
  676. // Blending source alpha factor
  677. // Blending destination alpha factor
  678. // Blending equation for RGB
  679. // Blending equation for alpha
  680. // Custom blending factor and equation modification status
  681. // Current framebuffer width
  682. // Current framebuffer height
  683. // Renderer state
  684. // VAO support (OpenGL ES2 could not support VAO extension) (GL_ARB_vertex_array_object)
  685. // Instancing supported (GL_ANGLE_instanced_arrays, GL_EXT_draw_instanced + GL_EXT_instanced_arrays)
  686. // NPOT textures full support (GL_ARB_texture_non_power_of_two, GL_OES_texture_npot)
  687. // Depth textures supported (GL_ARB_depth_texture, GL_OES_depth_texture)
  688. // Depth textures supported WebGL specific (GL_WEBGL_depth_texture)
  689. // float textures support (32 bit per channel) (GL_OES_texture_float)
  690. // DDS texture compression support (GL_EXT_texture_compression_s3tc, GL_WEBGL_compressed_texture_s3tc, GL_WEBKIT_WEBGL_compressed_texture_s3tc)
  691. // ETC1 texture compression support (GL_OES_compressed_ETC1_RGB8_texture, GL_WEBGL_compressed_texture_etc1)
  692. // ETC2/EAC texture compression support (GL_ARB_ES3_compatibility)
  693. // PVR texture compression support (GL_IMG_texture_compression_pvrtc)
  694. // ASTC texture compression support (GL_KHR_texture_compression_astc_hdr, GL_KHR_texture_compression_astc_ldr)
  695. // Clamp mirror wrap mode supported (GL_EXT_texture_mirror_clamp)
  696. // Anisotropic texture filtering support (GL_EXT_texture_filter_anisotropic)
  697. // Compute shaders support (GL_ARB_compute_shader)
  698. // Shader storage buffer object support (GL_ARB_shader_storage_buffer_object)
  699. // Maximum anisotropy level supported (minimum is 2.0f)
  700. // Maximum bits for depth component
  701. // Extensions supported flags
  702. // OpenGL extension functions loader signature (same as GLADloadproc)
  703. // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
  704. //----------------------------------------------------------------------------------
  705. // Global Variables Definition
  706. //----------------------------------------------------------------------------------
  707. // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
  708. // NOTE: VAO functionality is exposed through extensions (OES)
  709. // NOTE: Instancing functionality could also be available through extension
  710. //----------------------------------------------------------------------------------
  711. // Module specific Functions Declaration
  712. //----------------------------------------------------------------------------------
  713. // Load default shader
  714. // Unload default shader
  715. // Get compressed format official GL identifier name
  716. // RLGL_SHOW_GL_DETAILS_INFO
  717. // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
  718. // Get pixel data size in bytes (image or texture)
  719. // Auxiliar matrix math functions
  720. // Get identity matrix
  721. // Multiply two matrices
  722. //----------------------------------------------------------------------------------
  723. // Module Functions Definition - Matrix operations
  724. //----------------------------------------------------------------------------------
  725. // Fallback to OpenGL 1.1 function calls
  726. //---------------------------------------
  727. // Choose the current matrix to be transformed
  728. //else if (mode == RL_TEXTURE) // Not supported
  729. // Push the current matrix into RLGL.State.stack
  730. // Pop lattest inserted matrix from RLGL.State.stack
  731. // Reset current matrix to identity matrix
  732. // Multiply the current matrix by a translation matrix
  733. // NOTE: We transpose matrix with multiplication order
  734. // Multiply the current matrix by a rotation matrix
  735. // NOTE: The provided angle must be in degrees
  736. // Axis vector (x, y, z) normalization
  737. // Rotation matrix generation
  738. // NOTE: We transpose matrix with multiplication order
  739. // Multiply the current matrix by a scaling matrix
  740. // NOTE: We transpose matrix with multiplication order
  741. // Multiply the current matrix by another matrix
  742. // Matrix creation from array
  743. // Multiply the current matrix by a perspective matrix generated by parameters
  744. // Multiply the current matrix by an orthographic matrix generated by parameters
  745. // NOTE: If left-right and top-botton values are equal it could create a division by zero,
  746. // response to it is platform/compiler dependant
  747. // Set the viewport area (transformation from normalized device coordinates to window coordinates)
  748. // NOTE: We store current viewport dimensions
  749. //----------------------------------------------------------------------------------
  750. // Module Functions Definition - Vertex level operations
  751. //----------------------------------------------------------------------------------
  752. // Fallback to OpenGL 1.1 function calls
  753. //---------------------------------------
  754. // Initialize drawing mode (how to organize vertex)
  755. // Draw mode can be RL_LINES, RL_TRIANGLES and RL_QUADS
  756. // NOTE: In all three cases, vertex are accumulated over default internal vertex buffer
  757. // Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4,
  758. // that way, following QUADS drawing will keep aligned with index processing
  759. // It implies adding some extra alignment vertex at the end of the draw,
  760. // those vertex are not processed but they are considered as an additional offset
  761. // for the next set of vertex to be drawn
  762. // Finish vertex providing
  763. // NOTE: Depth increment is dependant on rlOrtho(): z-near and z-far values,
  764. // as well as depth buffer bit-depth (16bit or 24bit or 32bit)
  765. // Correct increment formula would be: depthInc = (zfar - znear)/pow(2, bits)
  766. // Define one vertex (position)
  767. // NOTE: Vertex position data is the basic information required for drawing
  768. // Transform provided vector if required
  769. // WARNING: We can't break primitives when launching a new batch.
  770. // RL_LINES comes in pairs, RL_TRIANGLES come in groups of 3 vertices and RL_QUADS come in groups of 4 vertices.
  771. // We must check current draw.mode when a new vertex is required and finish the batch only if the draw.mode draw.vertexCount is %2, %3 or %4
  772. // Reached the maximum number of vertices for RL_LINES drawing
  773. // Launch a draw call but keep current state for next vertices comming
  774. // NOTE: We add +1 vertex to the check for security
  775. // Add vertices
  776. // Add current texcoord
  777. // TODO: Add current normal
  778. // By default rlVertexBuffer type does not store normals
  779. // Add current color
  780. // Define one vertex (position)
  781. // Define one vertex (position)
  782. // Define one vertex (texture coordinate)
  783. // NOTE: Texture coordinates are limited to QUADS only
  784. // Define one vertex (normal)
  785. // NOTE: Normals limited to TRIANGLES only?
  786. // Define one vertex (color)
  787. // Define one vertex (color)
  788. // Define one vertex (color)
  789. //--------------------------------------------------------------------------------------
  790. // Module Functions Definition - OpenGL style functions (common to 1.1, 3.3+, ES2)
  791. //--------------------------------------------------------------------------------------
  792. // Set current texture to use
  793. // NOTE: If quads batch limit is reached, we force a draw call and next batch starts
  794. // Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4,
  795. // that way, following QUADS drawing will keep aligned with index processing
  796. // It implies adding some extra alignment vertex at the end of the draw,
  797. // those vertex are not processed but they are considered as an additional offset
  798. // for the next set of vertex to be drawn
  799. // Select and active a texture slot
  800. // Enable texture
  801. // Disable texture
  802. // Enable texture cubemap
  803. // Disable texture cubemap
  804. // Set texture parameters (wrap mode/filter mode)
  805. // Reset anisotropy filter, in case it was set
  806. // Set cubemap parameters (wrap mode/filter mode)
  807. // Reset anisotropy filter, in case it was set
  808. // Enable shader program
  809. // Disable shader program
  810. // Enable rendering to texture (fbo)
  811. // Disable rendering to texture
  812. // Activate multiple draw color buffers
  813. // NOTE: One color buffer is always active by default
  814. // NOTE: Maximum number of draw buffers supported is implementation dependant,
  815. // it can be queried with glGet*() but it must be at least 8
  816. //GLint maxDrawBuffers = 0;
  817. //glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
  818. //----------------------------------------------------------------------------------
  819. // General render state configuration
  820. //----------------------------------------------------------------------------------
  821. // Enable color blending
  822. // Disable color blending
  823. // Enable depth test
  824. // Disable depth test
  825. // Enable depth write
  826. // Disable depth write
  827. // Enable backface culling
  828. // Disable backface culling
  829. // Set face culling mode
  830. // Enable scissor test
  831. // Disable scissor test
  832. // Scissor test
  833. // Enable wire mode
  834. // NOTE: glPolygonMode() not available on OpenGL ES
  835. // Disable wire mode
  836. // NOTE: glPolygonMode() not available on OpenGL ES
  837. // Set the line drawing width
  838. // Get the line drawing width
  839. // Enable line aliasing
  840. // Disable line aliasing
  841. // Enable stereo rendering
  842. // Disable stereo rendering
  843. // Check if stereo render is enabled
  844. // Clear color buffer with color
  845. // Color values clamp to 0.0f(0) and 1.0f(255)
  846. // Clear used screen buffers (color and depth)
  847. // Clear used buffers: Color and Depth (Depth is used for 3D)
  848. //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // Stencil buffer not used...
  849. // Check and log OpenGL error codes
  850. // Set blend mode
  851. // NOTE: Using GL blend src/dst factors and GL equation configured with rlSetBlendFactors()
  852. // NOTE: Using GL blend src/dst factors and GL equation configured with rlSetBlendFactorsSeparate()
  853. // Set blending mode factor and equation
  854. // Set blending mode factor and equation separately for RGB and alpha
  855. //----------------------------------------------------------------------------------
  856. // Module Functions Definition - OpenGL Debug
  857. //----------------------------------------------------------------------------------
  858. // Ignore non-significant error/warning codes (NVidia drivers)
  859. // NOTE: Here there are the details with a sample output:
  860. // - #131169 - Framebuffer detailed info: The driver allocated storage for renderbuffer 2. (severity: low)
  861. // - #131185 - Buffer detailed info: Buffer object 1 (bound to GL_ELEMENT_ARRAY_BUFFER_ARB, usage hint is GL_ENUM_88e4)
  862. // will use VIDEO memory as the source for buffer object operations. (severity: low)
  863. // - #131218 - Program/shader state performance warning: Vertex shader in program 7 is being recompiled based on GL state. (severity: medium)
  864. // - #131204 - Texture state usage warning: The texture object (0) bound to texture image unit 0 does not have
  865. // a defined base level and cannot be used for texture mapping. (severity: low)
  866. //----------------------------------------------------------------------------------
  867. // Module Functions Definition - rlgl functionality
  868. //----------------------------------------------------------------------------------
  869. // Initialize rlgl: OpenGL extensions, default buffers/shaders/textures, OpenGL states
  870. // Enable OpenGL debug context if required
  871. // glDebugMessageControl(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, GL_DEBUG_SEVERITY_HIGH, 0, 0, GL_TRUE); // TODO: Filter message
  872. // Debug context options:
  873. // - GL_DEBUG_OUTPUT - Faster version but not useful for breakpoints
  874. // - GL_DEBUG_OUTPUT_SYNCHRONUS - Callback is in sync with errors, so a breakpoint can be placed on the callback in order to get a stacktrace for the GL error
  875. // Init default white texture
  876. // 1 pixel RGBA (4 bytes)
  877. // Init default Shader (customized for GL 3.3 and ES2)
  878. // Loaded: RLGL.State.defaultShaderId + RLGL.State.defaultShaderLocs
  879. // Init default vertex arrays buffers
  880. // Init stack matrices (emulating OpenGL 1.1)
  881. // Init internal matrices
  882. // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
  883. // Initialize OpenGL default states
  884. //----------------------------------------------------------
  885. // Init state: Depth test
  886. // Type of depth testing to apply
  887. // Disable depth testing for 2D (only used for 3D)
  888. // Init state: Blending mode
  889. // Color blending function (how colors are mixed)
  890. // Enable color blending (required to work with transparencies)
  891. // Init state: Culling
  892. // NOTE: All shapes/models triangles are drawn CCW
  893. // Cull the back face (default)
  894. // Front face are defined counter clockwise (default)
  895. // Enable backface culling
  896. // Init state: Cubemap seamless
  897. // Seamless cubemaps (not supported on OpenGL ES 2.0)
  898. // Init state: Color hints (deprecated in OpenGL 3.0+)
  899. // Improve quality of color and texture coordinate interpolation
  900. // Smooth shading between vertex (vertex colors interpolation)
  901. // Store screen size into global variables
  902. //----------------------------------------------------------
  903. // Init state: Color/Depth buffers clear
  904. // Set clear color (black)
  905. // Set clear depth value (default)
  906. // Clear color and depth buffers (depth buffer required for 3D)
  907. // Vertex Buffer Object deinitialization (memory free)
  908. // Unload default shader
  909. // Unload default texture
  910. // Load OpenGL extensions
  911. // NOTE: External loader function must be provided
  912. // Also defined for GRAPHICS_API_OPENGL_21
  913. // NOTE: glad is generated and contains only required OpenGL 3.3 Core extensions (and lower versions)
  914. // Get number of supported extensions
  915. // Get supported extensions list
  916. // WARNING: glGetStringi() not available on OpenGL 2.1
  917. // Register supported extensions flags
  918. // Optional OpenGL 2.1 extensions
  919. // Register supported extensions flags
  920. // OpenGL 3.3 extensions supported by default (core)
  921. // Optional OpenGL 3.3 extensions
  922. // Texture compression: DXT
  923. // Texture compression: ETC2/EAC
  924. // GRAPHICS_API_OPENGL_33
  925. // Get supported extensions list
  926. // Allocate 512 strings pointers (2 KB)
  927. // One big const string
  928. // NOTE: We have to duplicate string because glGetString() returns a const string
  929. // Get extensions string size in bytes
  930. // Check required extensions
  931. // Check VAO support
  932. // NOTE: Only check on OpenGL ES, OpenGL 3.3 has VAO support as core feature
  933. // The extension is supported by our hardware and driver, try to get related functions pointers
  934. // NOTE: emscripten does not support VAOs natively, it uses emulation and it reduces overall performance...
  935. //glIsVertexArray = (PFNGLISVERTEXARRAYOESPROC)loader("glIsVertexArrayOES"); // NOTE: Fails in WebGL, omitted
  936. // Check instanced rendering support
  937. // Web ANGLE
  938. // Standard EXT
  939. // Check NPOT textures support
  940. // NOTE: Only check on OpenGL ES, OpenGL 3.3 has NPOT textures full support as core feature
  941. // Check texture float support
  942. // Check depth texture support
  943. // WebGL requires unsized internal format
  944. // Not available on WebGL
  945. // Not available on WebGL
  946. // Check texture compression support: DXT
  947. // Check texture compression support: ETC1
  948. // Check texture compression support: ETC2/EAC
  949. // Check texture compression support: PVR
  950. // Check texture compression support: ASTC
  951. // Check anisotropic texture filter support
  952. // Check clamp mirror wrap mode support
  953. // Free extensions pointers
  954. // Duplicated string must be deallocated
  955. // GRAPHICS_API_OPENGL_ES2
  956. // Check OpenGL information and capabilities
  957. //------------------------------------------------------------------------------
  958. // Show current OpenGL and GLSL version
  959. // NOTE: Anisotropy levels capability is an extension
  960. // Show some OpenGL GPU capabilities
  961. // GRAPHICS_API_OPENGL_43
  962. // RLGL_SHOW_GL_DETAILS_INFO
  963. // Show some basic info about GL supported features
  964. // RLGL_SHOW_GL_DETAILS_INFO
  965. // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
  966. // Get current OpenGL version
  967. // Set current framebuffer width
  968. // Set current framebuffer height
  969. // Get default framebuffer width
  970. // Get default framebuffer height
  971. // Get default internal texture (white texture)
  972. // NOTE: Default texture is a 1x1 pixel UNCOMPRESSED_R8G8B8A8
  973. // Get default shader id
  974. // Get default shader locs
  975. // Render batch management
  976. //------------------------------------------------------------------------------------------------
  977. // Load render batch
  978. // Initialize CPU (RAM) vertex buffers (position, texcoord, color data and indexes)
  979. //--------------------------------------------------------------------------------------------
  980. // 3 float by vertex, 4 vertex by quad
  981. // 2 float by texcoord, 4 texcoord by quad
  982. // 4 float by color, 4 colors by quad
  983. // 6 int by quad (indices)
  984. // 6 int by quad (indices)
  985. // Indices can be initialized right now
  986. //--------------------------------------------------------------------------------------------
  987. // Upload to GPU (VRAM) vertex data and initialize VAOs/VBOs
  988. //--------------------------------------------------------------------------------------------
  989. // Initialize Quads VAO
  990. // Quads - Vertex buffers binding and attributes enable
  991. // Vertex position buffer (shader-location = 0)
  992. // Vertex texcoord buffer (shader-location = 1)
  993. // Vertex color buffer (shader-location = 3)
  994. // Fill index buffer
  995. // Unbind the current VAO
  996. //--------------------------------------------------------------------------------------------
  997. // Init draw calls tracking system
  998. //--------------------------------------------------------------------------------------------
  999. //batch.draws[i].vaoId = 0;
  1000. //batch.draws[i].shaderId = 0;
  1001. //batch.draws[i].RLGL.State.projection = rlMatrixIdentity();
  1002. //batch.draws[i].RLGL.State.modelview = rlMatrixIdentity();
  1003. // Record buffer count
  1004. // Reset draws counter
  1005. // Reset depth value
  1006. //--------------------------------------------------------------------------------------------
  1007. // Unload default internal buffers vertex data from CPU and GPU
  1008. // Unbind everything
  1009. // Unload all vertex buffers data
  1010. // Unbind VAO attribs data
  1011. // Delete VBOs from GPU (VRAM)
  1012. // Delete VAOs from GPU (VRAM)
  1013. // Free vertex arrays memory from CPU (RAM)
  1014. // Unload arrays
  1015. // Draw render batch
  1016. // NOTE: We require a pointer to reset batch and increase current buffer (multi-buffer)
  1017. // Update batch vertex buffers
  1018. //------------------------------------------------------------------------------------------------------------
  1019. // NOTE: If there is not vertex data, buffers doesn't need to be updated (vertexCount > 0)
  1020. // TODO: If no data changed on the CPU arrays --> No need to re-update GPU arrays (change flag required)
  1021. // Activate elements VAO
  1022. // Vertex positions buffer
  1023. //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].vertices, GL_DYNAMIC_DRAW); // Update all buffer
  1024. // Texture coordinates buffer
  1025. //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].texcoords, GL_DYNAMIC_DRAW); // Update all buffer
  1026. // Colors buffer
  1027. //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].colors, GL_DYNAMIC_DRAW); // Update all buffer
  1028. // NOTE: glMapBuffer() causes sync issue.
  1029. // If GPU is working with this buffer, glMapBuffer() will wait(stall) until GPU to finish its job.
  1030. // To avoid waiting (idle), you can call first glBufferData() with NULL pointer before glMapBuffer().
  1031. // If you do that, the previous data in PBO will be discarded and glMapBuffer() returns a new
  1032. // allocated pointer immediately even if GPU is still working with the previous data.
  1033. // Another option: map the buffer object into client's memory
  1034. // Probably this code could be moved somewhere else...
  1035. // batch->vertexBuffer[batch->currentBuffer].vertices = (float *)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
  1036. // if (batch->vertexBuffer[batch->currentBuffer].vertices)
  1037. // {
  1038. // Update vertex data
  1039. // }
  1040. // glUnmapBuffer(GL_ARRAY_BUFFER);
  1041. // Unbind the current VAO
  1042. //------------------------------------------------------------------------------------------------------------
  1043. // Draw batch vertex buffers (considering VR stereo if required)
  1044. //------------------------------------------------------------------------------------------------------------
  1045. // Setup current eye viewport (half screen width)
  1046. // Set current eye view offset to modelview matrix
  1047. // Set current eye projection matrix
  1048. // Draw buffers
  1049. // Set current shader and upload current MVP matrix
  1050. // Create modelview-projection matrix and upload to shader
  1051. // Bind vertex attrib: position (shader-location = 0)
  1052. // Bind vertex attrib: texcoord (shader-location = 1)
  1053. // Bind vertex attrib: color (shader-location = 3)
  1054. // Setup some default shader values
  1055. // Active default sampler2D: texture0
  1056. // Activate additional sampler textures
  1057. // Those additional textures will be common for all draw calls of the batch
  1058. // Activate default sampler2D texture0 (one texture is always active for default batch shader)
  1059. // NOTE: Batch system accumulates calls by texture0 changes, additional textures are enabled for all the draw calls
  1060. // Bind current draw call texture, activated as GL_TEXTURE0 and Bound to sampler2D texture0 by default
  1061. // We need to define the number of indices to be processed: elementCount*6
  1062. // NOTE: The final parameter tells the GPU the offset in bytes from the
  1063. // start of the index buffer to the location of the first index to process
  1064. // Unbind textures
  1065. // Unbind VAO
  1066. // Unbind shader program
  1067. // Restore viewport to default measures
  1068. //------------------------------------------------------------------------------------------------------------
  1069. // Reset batch buffers
  1070. //------------------------------------------------------------------------------------------------------------
  1071. // Reset vertex counter for next frame
  1072. // Reset depth for next draw
  1073. // Restore projection/modelview matrices
  1074. // Reset RLGL.currentBatch->draws array
  1075. // Reset active texture units for next batch
  1076. // Reset draws counter to one draw for the batch
  1077. //------------------------------------------------------------------------------------------------------------
  1078. // Change to next buffer in the list (in case of multi-buffering)
  1079. // Set the active render batch for rlgl
  1080. // Update and draw internal render batch
  1081. // NOTE: Stereo rendering is checked inside
  1082. // Check internal buffer overflow for a given number of vertex
  1083. // and force a rlRenderBatch draw call if required
  1084. // Store current primitive drawing mode and texture id
  1085. // NOTE: Stereo rendering is checked inside
  1086. // Restore state of last batch so we can continue adding vertices
  1087. // Textures data management
  1088. //-----------------------------------------------------------------------------------------
  1089. // Convert image data to OpenGL texture (returns OpenGL valid Id)
  1090. // Free any old binding
  1091. // Check texture format support by OpenGL 1.1 (compressed textures not supported)
  1092. // GRAPHICS_API_OPENGL_11
  1093. // Generate texture id
  1094. // Mipmap data offset
  1095. // Load the different mipmap levels
  1096. // Security check for NPOT textures
  1097. // Texture parameters configuration
  1098. // NOTE: glTexParameteri does NOT affect texture uploading, just the way it's used
  1099. // NOTE: OpenGL ES 2.0 with no GL_OES_texture_npot support (i.e. WebGL) has limited NPOT support, so CLAMP_TO_EDGE must be used
  1100. // Set texture to repeat on x-axis
  1101. // Set texture to repeat on y-axis
  1102. // NOTE: If using negative texture coordinates (LoadOBJ()), it does not work!
  1103. // Set texture to clamp on x-axis
  1104. // Set texture to clamp on y-axis
  1105. // Set texture to repeat on x-axis
  1106. // Set texture to repeat on y-axis
  1107. // Magnification and minification filters
  1108. // Alternative: GL_LINEAR
  1109. // Alternative: GL_LINEAR
  1110. // Activate Trilinear filtering if mipmaps are available
  1111. // At this point we have the texture loaded in GPU and texture parameters configured
  1112. // NOTE: If mipmaps were not in data, they are not generated automatically
  1113. // Unbind current texture
  1114. // Load depth texture/renderbuffer (to be attached to fbo)
  1115. // WARNING: OpenGL ES 2.0 requires GL_OES_depth_texture and WebGL requires WEBGL_depth_texture extensions
  1116. // In case depth textures not supported, we force renderbuffer usage
  1117. // NOTE: We let the implementation to choose the best bit-depth
  1118. // Possible formats: GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT32 and GL_DEPTH_COMPONENT32F
  1119. // WARNING: WebGL platform requires unsized internal format definition (GL_DEPTH_COMPONENT)
  1120. // while other platforms using OpenGL ES 2.0 require/support sized internal formats depending on the GPU capabilities
  1121. // Create the renderbuffer that will serve as the depth attachment for the framebuffer
  1122. // NOTE: A renderbuffer is simpler than a texture and could offer better performance on embedded devices
  1123. // Load texture cubemap
  1124. // NOTE: Cubemap data is expected to be 6 images in a single data array (one after the other),
  1125. // expected the following convention: +X, -X, +Y, -Y, +Z, -Z
  1126. // Load cubemap faces
  1127. // Instead of using a sized internal texture format (GL_RGB16F, GL_RGB32F), we let the driver to choose the better format for us (GL_RGB)
  1128. // Set cubemap texture sampling parameters
  1129. // Flag not supported on OpenGL ES 2.0
  1130. // Update already loaded texture in GPU with new data
  1131. // NOTE: We don't know safely if internal texture format is the expected one...
  1132. // Get OpenGL internal formats and data type from raylib PixelFormat
  1133. // NOTE: on OpenGL ES 2.0 (WebGL), internalFormat must match format and options allowed are: GL_LUMINANCE, GL_RGB, GL_RGBA
  1134. // NOTE: Requires extension OES_texture_float
  1135. // NOTE: Requires extension OES_texture_float
  1136. // NOTE: Requires extension OES_texture_float
  1137. // NOTE: Requires OpenGL ES 2.0 or OpenGL 4.3
  1138. // NOTE: Requires OpenGL ES 3.0 or OpenGL 4.3
  1139. // NOTE: Requires OpenGL ES 3.0 or OpenGL 4.3
  1140. // NOTE: Requires PowerVR GPU
  1141. // NOTE: Requires PowerVR GPU
  1142. // NOTE: Requires OpenGL ES 3.1 or OpenGL 4.3
  1143. // NOTE: Requires OpenGL ES 3.1 or OpenGL 4.3
  1144. // Unload texture from GPU memory
  1145. // Generate mipmap data for selected texture
  1146. // NOTE: Only supports GPU mipmap generation
  1147. // Check if texture is power-of-two (POT)
  1148. //glHint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE); // Hint for mipmaps generation algorithm: GL_FASTEST, GL_NICEST, GL_DONT_CARE
  1149. // Generate mipmaps automatically
  1150. // Read texture pixel data
  1151. // NOTE: Using texture id, we can retrieve some texture info (but not on OpenGL ES 2.0)
  1152. // Possible texture info: GL_TEXTURE_RED_SIZE, GL_TEXTURE_GREEN_SIZE, GL_TEXTURE_BLUE_SIZE, GL_TEXTURE_ALPHA_SIZE
  1153. //int width, height, format;
  1154. //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
  1155. //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
  1156. //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &format);
  1157. // NOTE: Each row written to or read from by OpenGL pixel operations like glGetTexImage are aligned to a 4 byte boundary by default, which may add some padding.
  1158. // Use glPixelStorei to modify padding with the GL_[UN]PACK_ALIGNMENT setting.
  1159. // GL_PACK_ALIGNMENT affects operations that read from OpenGL memory (glReadPixels, glGetTexImage, etc.)
  1160. // GL_UNPACK_ALIGNMENT affects operations that write to OpenGL memory (glTexImage, etc.)
  1161. // glGetTexImage() is not available on OpenGL ES 2.0
  1162. // Texture width and height are required on OpenGL ES 2.0. There is no way to get it from texture id.
  1163. // Two possible Options:
  1164. // 1 - Bind texture to color fbo attachment and glReadPixels()
  1165. // 2 - Create an fbo, activate it, render quad with texture, glReadPixels()
  1166. // We are using Option 1, just need to care for texture format on retrieval
  1167. // NOTE: This behaviour could be conditioned by graphic driver...
  1168. // Attach our texture to FBO
  1169. // We read data as RGBA because FBO texture is configured as RGBA, despite binding another texture format
  1170. // Clean up temporal fbo
  1171. // Read screen pixel data (color buffer)
  1172. // NOTE 1: glReadPixels returns image flipped vertically -> (0,0) is the bottom left corner of the framebuffer
  1173. // NOTE 2: We are getting alpha channel! Be careful, it can be transparent if not cleared properly!
  1174. // Flip image vertically!
  1175. // Flip line
  1176. // Set alpha component value to 255 (no trasparent image retrieval)
  1177. // NOTE: Alpha value has already been applied to RGB in framebuffer, we don't need it!
  1178. // NOTE: image data should be freed
  1179. // Framebuffer management (fbo)
  1180. //-----------------------------------------------------------------------------------------
  1181. // Load a framebuffer to be used for rendering
  1182. // NOTE: No textures attached
  1183. // Create the framebuffer object
  1184. // Unbind any framebuffer
  1185. // Attach color buffer texture to an fbo (unloads previous attachment)
  1186. // NOTE: Attach type: 0-Color, 1-Depth renderbuffer, 2-Depth texture
  1187. // Verify render texture is complete
  1188. // Unload framebuffer from GPU memory
  1189. // NOTE: All attached textures/cubemaps/renderbuffers are also deleted
  1190. // Query depth attachment to automatically delete texture/renderbuffer
  1191. // Bind framebuffer to query depth texture type
  1192. // NOTE: If a texture object is deleted while its image is attached to the *currently bound* framebuffer,
  1193. // the texture image is automatically detached from the currently bound framebuffer.
  1194. // Vertex data management
  1195. //-----------------------------------------------------------------------------------------
  1196. // Load a new attributes buffer
  1197. // Load a new attributes element buffer
  1198. // Enable vertex buffer (VBO)
  1199. // Disable vertex buffer (VBO)
  1200. // Enable vertex buffer element (VBO element)
  1201. // Disable vertex buffer element (VBO element)
  1202. // Update vertex buffer with new data
  1203. // NOTE: dataSize and offset must be provided in bytes
  1204. // Update vertex buffer elements with new data
  1205. // NOTE: dataSize and offset must be provided in bytes
  1206. // Enable vertex array object (VAO)
  1207. // Disable vertex array object (VAO)
  1208. // Enable vertex attribute index
  1209. // Disable vertex attribute index
  1210. // Draw vertex array
  1211. // Draw vertex array elements
  1212. // Draw vertex array instanced
  1213. // Draw vertex array elements instanced
  1214. // Enable vertex state pointer
  1215. //case GL_INDEX_ARRAY: if (buffer != NULL) glIndexPointer(GL_SHORT, 0, buffer); break; // Indexed colors
  1216. // Disable vertex state pointer
  1217. // Load vertex array object (VAO)
  1218. // Set vertex attribute
  1219. // Set vertex attribute divisor
  1220. // Unload vertex array object (VAO)
  1221. // Unload vertex buffer (VBO)
  1222. //TRACELOG(RL_LOG_INFO, "VBO: Unloaded vertex data from VRAM (GPU)");
  1223. // Shaders management
  1224. //-----------------------------------------------------------------------------------------------
  1225. // Load shader from code strings
  1226. // NOTE: If shader string is NULL, using default vertex/fragment shaders
  1227. // Compile vertex shader (if provided)
  1228. // In case no vertex shader was provided or compilation failed, we use default vertex shader
  1229. // Compile fragment shader (if provided)
  1230. // In case no fragment shader was provided or compilation failed, we use default fragment shader
  1231. // In case vertex and fragment shader are the default ones, no need to recompile, we can just assign the default shader program id
  1232. // One of or both shader are new, we need to compile a new shader program
  1233. // We can detach and delete vertex/fragment shaders (if not default ones)
  1234. // NOTE: We detach shader before deletion to make sure memory is freed
  1235. // WARNING: Shader program linkage could fail and returned id is 0
  1236. // WARNING: Shader program linkage could fail and returned id is 0
  1237. // In case shader program loading failed, we assign default shader
  1238. // In case shader loading fails, we return the default shader
  1239. /*
  1240. else
  1241. {
  1242. // Get available shader uniforms
  1243. // NOTE: This information is useful for debug...
  1244. int uniformCount = -1;
  1245. glGetProgramiv(id, GL_ACTIVE_UNIFORMS, &uniformCount);
  1246. for (int i = 0; i < uniformCount; i++)
  1247. {
  1248. int namelen = -1;
  1249. int num = -1;
  1250. char name[256] = { 0 }; // Assume no variable names longer than 256
  1251. GLenum type = GL_ZERO;
  1252. // Get the name of the uniforms
  1253. glGetActiveUniform(id, i, sizeof(name) - 1, &namelen, &num, &type, name);
  1254. name[namelen] = 0;
  1255. TRACELOGD("SHADER: [ID %i] Active uniform (%s) set at location: %i", id, name, glGetUniformLocation(id, name));
  1256. }
  1257. }
  1258. */
  1259. // Compile custom shader and return shader id
  1260. //case GL_GEOMETRY_SHADER:
  1261. //case GL_GEOMETRY_SHADER:
  1262. // Load custom shader strings and return program id
  1263. // NOTE: Default attribute shader locations must be Bound before linking
  1264. // NOTE: If some attrib name is no found on the shader, it locations becomes -1
  1265. // NOTE: All uniform variables are intitialised to 0 when a program links
  1266. // Get the size of compiled shader program (not available on OpenGL ES 2.0)
  1267. // NOTE: If GL_LINK_STATUS is GL_FALSE, program binary length is zero.
  1268. //GLint binarySize = 0;
  1269. //glGetProgramiv(id, GL_PROGRAM_BINARY_LENGTH, &binarySize);
  1270. // Unload shader program
  1271. // Get shader location uniform
  1272. // Get shader location attribute
  1273. // Set shader value uniform
  1274. // Set shader value attribute
  1275. // Set shader value uniform matrix
  1276. // Set shader value uniform sampler
  1277. // Check if texture is already active
  1278. // Register a new active texture for the internal batch system
  1279. // NOTE: Default texture is always activated as GL_TEXTURE0
  1280. // Activate new texture unit
  1281. // Save texture id for binding on drawing
  1282. // Set shader currently active (id and locations)
  1283. // Load compute shader program
  1284. // NOTE: All uniform variables are intitialised to 0 when a program links
  1285. // Get the size of compiled shader program (not available on OpenGL ES 2.0)
  1286. // NOTE: If GL_LINK_STATUS is GL_FALSE, program binary length is zero.
  1287. //GLint binarySize = 0;
  1288. //glGetProgramiv(id, GL_PROGRAM_BINARY_LENGTH, &binarySize);
  1289. // Dispatch compute shader (equivalent to *draw* for graphics pilepine)
  1290. // Load shader storage buffer object (SSBO)
  1291. // Unload shader storage buffer object (SSBO)
  1292. // Update SSBO buffer data
  1293. // Get SSBO buffer size
  1294. // Read SSBO buffer data (GPU->CPU)
  1295. // Bind SSBO buffer
  1296. // Copy SSBO buffer data
  1297. // Bind image texture
  1298. // Matrix state management
  1299. //-----------------------------------------------------------------------------------------
  1300. // Get internal modelview matrix
  1301. // Get internal projection matrix
  1302. // Get internal accumulated transform matrix
  1303. // TODO: Consider possible transform matrices in the RLGL.State.stack
  1304. // Is this the right order? or should we start with the first stored matrix instead of the last one?
  1305. //Matrix matStackTransform = rlMatrixIdentity();
  1306. //for (int i = RLGL.State.stackCounter; i > 0; i--) matStackTransform = rlMatrixMultiply(RLGL.State.stack[i], matStackTransform);
  1307. // Get internal projection matrix for stereo render (selected eye)
  1308. // Get internal view offset matrix for stereo render (selected eye)
  1309. // Set a custom modelview matrix (replaces internal modelview matrix)
  1310. // Set a custom projection matrix (replaces internal projection matrix)
  1311. // Set eyes projection matrices for stereo rendering
  1312. // Set eyes view offsets matrices for stereo rendering
  1313. // Load and draw a quad in NDC
  1314. // Positions Texcoords
  1315. // Gen VAO to contain VBO
  1316. // Gen and fill vertex buffer (VBO)
  1317. // Bind vertex attributes (position, texcoords)
  1318. // Positions
  1319. // Texcoords
  1320. // Draw quad
  1321. // Delete buffers (VBO and VAO)
  1322. // Load and draw a cube in NDC
  1323. // Positions Normals Texcoords
  1324. // Gen VAO to contain VBO
  1325. // Gen and fill vertex buffer (VBO)
  1326. // Bind vertex attributes (position, normals, texcoords)
  1327. // Positions
  1328. // Normals
  1329. // Texcoords
  1330. // Draw cube
  1331. // Delete VBO and VAO
  1332. // Get name string for pixel format
  1333. // 8 bit per pixel (no alpha)
  1334. // 8*2 bpp (2 channels)
  1335. // 16 bpp
  1336. // 24 bpp
  1337. // 16 bpp (1 bit alpha)
  1338. // 16 bpp (4 bit alpha)
  1339. // 32 bpp
  1340. // 32 bpp (1 channel - float)
  1341. // 32*3 bpp (3 channels - float)
  1342. // 32*4 bpp (4 channels - float)
  1343. // 4 bpp (no alpha)
  1344. // 4 bpp (1 bit alpha)
  1345. // 8 bpp
  1346. // 8 bpp
  1347. // 4 bpp
  1348. // 4 bpp
  1349. // 8 bpp
  1350. // 4 bpp
  1351. // 4 bpp
  1352. // 8 bpp
  1353. // 2 bpp
  1354. //----------------------------------------------------------------------------------
  1355. // Module specific Functions Definition
  1356. //----------------------------------------------------------------------------------
  1357. // Load default shader (just vertex positioning and texture coloring)
  1358. // NOTE: This shader program is used for internal buffers
  1359. // NOTE: Loaded: RLGL.State.defaultShaderId, RLGL.State.defaultShaderLocs
  1360. // NOTE: All locations must be reseted to -1 (no location)
  1361. // Vertex shader directly defined, no external file required
  1362. // Fragment shader directly defined, no external file required
  1363. // Precision required for OpenGL ES2 (WebGL)
  1364. // NOTE: Compiled vertex/fragment shaders are not deleted,
  1365. // they are kept for re-use as default shaders in case some shader loading fails
  1366. // Compile default vertex shader
  1367. // Compile default fragment shader
  1368. // Set default shader locations: attributes locations
  1369. // Set default shader locations: uniform locations
  1370. // Unload default shader
  1371. // NOTE: Unloads: RLGL.State.defaultShaderId, RLGL.State.defaultShaderLocs
  1372. // Get compressed format official GL identifier name
  1373. // GL_EXT_texture_compression_s3tc
  1374. // GL_3DFX_texture_compression_FXT1
  1375. // GL_IMG_texture_compression_pvrtc
  1376. // GL_OES_compressed_ETC1_RGB8_texture
  1377. // GL_ARB_texture_compression_rgtc
  1378. // GL_ARB_texture_compression_bptc
  1379. // GL_ARB_ES3_compatibility
  1380. // GL_KHR_texture_compression_astc_hdr
  1381. // RLGL_SHOW_GL_DETAILS_INFO
  1382. // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
  1383. // Get pixel data size in bytes (image or texture)
  1384. // NOTE: Size depends on pixel format
  1385. // Size in bytes
  1386. // Bits per pixel
  1387. // Total data size in bytes
  1388. // Most compressed formats works on 4x4 blocks,
  1389. // if texture is smaller, minimum dataSize is 8 or 16
  1390. // Auxiliar math functions
  1391. // Get identity matrix
  1392. // Get two matrix multiplication
  1393. // NOTE: When multiplying matrices... the order matters!
  1394. // RLGL_IMPLEMENTATION