rlgl.d 80 KB

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