rlgl.d 72 KB

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