rlgl.d 85 KB

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