rlgl.d 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926
  1. module raylib.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-2022 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 approximation
  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_ALPHA_PREMULTIPLY = 5, // Blend premultiplied textures considering alpha
  322. RL_BLEND_CUSTOM = 6 // Blend textures using custom src/dst factors (use rlSetBlendFactors())
  323. }
  324. // Shader location point type
  325. enum rlShaderLocationIndex
  326. {
  327. RL_SHADER_LOC_VERTEX_POSITION = 0, // Shader location: vertex attribute: position
  328. RL_SHADER_LOC_VERTEX_TEXCOORD01 = 1, // Shader location: vertex attribute: texcoord01
  329. RL_SHADER_LOC_VERTEX_TEXCOORD02 = 2, // Shader location: vertex attribute: texcoord02
  330. RL_SHADER_LOC_VERTEX_NORMAL = 3, // Shader location: vertex attribute: normal
  331. RL_SHADER_LOC_VERTEX_TANGENT = 4, // Shader location: vertex attribute: tangent
  332. RL_SHADER_LOC_VERTEX_COLOR = 5, // Shader location: vertex attribute: color
  333. RL_SHADER_LOC_MATRIX_MVP = 6, // Shader location: matrix uniform: model-view-projection
  334. RL_SHADER_LOC_MATRIX_VIEW = 7, // Shader location: matrix uniform: view (camera transform)
  335. RL_SHADER_LOC_MATRIX_PROJECTION = 8, // Shader location: matrix uniform: projection
  336. RL_SHADER_LOC_MATRIX_MODEL = 9, // Shader location: matrix uniform: model (transform)
  337. RL_SHADER_LOC_MATRIX_NORMAL = 10, // Shader location: matrix uniform: normal
  338. RL_SHADER_LOC_VECTOR_VIEW = 11, // Shader location: vector uniform: view
  339. RL_SHADER_LOC_COLOR_DIFFUSE = 12, // Shader location: vector uniform: diffuse color
  340. RL_SHADER_LOC_COLOR_SPECULAR = 13, // Shader location: vector uniform: specular color
  341. RL_SHADER_LOC_COLOR_AMBIENT = 14, // Shader location: vector uniform: ambient color
  342. RL_SHADER_LOC_MAP_ALBEDO = 15, // Shader location: sampler2d texture: albedo (same as: RL_SHADER_LOC_MAP_DIFFUSE)
  343. RL_SHADER_LOC_MAP_METALNESS = 16, // Shader location: sampler2d texture: metalness (same as: RL_SHADER_LOC_MAP_SPECULAR)
  344. RL_SHADER_LOC_MAP_NORMAL = 17, // Shader location: sampler2d texture: normal
  345. RL_SHADER_LOC_MAP_ROUGHNESS = 18, // Shader location: sampler2d texture: roughness
  346. RL_SHADER_LOC_MAP_OCCLUSION = 19, // Shader location: sampler2d texture: occlusion
  347. RL_SHADER_LOC_MAP_EMISSION = 20, // Shader location: sampler2d texture: emission
  348. RL_SHADER_LOC_MAP_HEIGHT = 21, // Shader location: sampler2d texture: height
  349. RL_SHADER_LOC_MAP_CUBEMAP = 22, // Shader location: samplerCube texture: cubemap
  350. RL_SHADER_LOC_MAP_IRRADIANCE = 23, // Shader location: samplerCube texture: irradiance
  351. RL_SHADER_LOC_MAP_PREFILTER = 24, // Shader location: samplerCube texture: prefilter
  352. RL_SHADER_LOC_MAP_BRDF = 25 // Shader location: sampler2d texture: brdf
  353. }
  354. enum RL_SHADER_LOC_MAP_DIFFUSE = rlShaderLocationIndex.RL_SHADER_LOC_MAP_ALBEDO;
  355. enum RL_SHADER_LOC_MAP_SPECULAR = rlShaderLocationIndex.RL_SHADER_LOC_MAP_METALNESS;
  356. // Shader uniform data type
  357. enum rlShaderUniformDataType
  358. {
  359. RL_SHADER_UNIFORM_FLOAT = 0, // Shader uniform type: float
  360. RL_SHADER_UNIFORM_VEC2 = 1, // Shader uniform type: vec2 (2 float)
  361. RL_SHADER_UNIFORM_VEC3 = 2, // Shader uniform type: vec3 (3 float)
  362. RL_SHADER_UNIFORM_VEC4 = 3, // Shader uniform type: vec4 (4 float)
  363. RL_SHADER_UNIFORM_INT = 4, // Shader uniform type: int
  364. RL_SHADER_UNIFORM_IVEC2 = 5, // Shader uniform type: ivec2 (2 int)
  365. RL_SHADER_UNIFORM_IVEC3 = 6, // Shader uniform type: ivec3 (3 int)
  366. RL_SHADER_UNIFORM_IVEC4 = 7, // Shader uniform type: ivec4 (4 int)
  367. RL_SHADER_UNIFORM_SAMPLER2D = 8 // Shader uniform type: sampler2d
  368. }
  369. // Shader attribute data types
  370. enum rlShaderAttributeDataType
  371. {
  372. RL_SHADER_ATTRIB_FLOAT = 0, // Shader attribute type: float
  373. RL_SHADER_ATTRIB_VEC2 = 1, // Shader attribute type: vec2 (2 float)
  374. RL_SHADER_ATTRIB_VEC3 = 2, // Shader attribute type: vec3 (3 float)
  375. RL_SHADER_ATTRIB_VEC4 = 3 // Shader attribute type: vec4 (4 float)
  376. }
  377. //------------------------------------------------------------------------------------
  378. // Functions Declaration - Matrix operations
  379. //------------------------------------------------------------------------------------
  380. // Prevents name mangling of functions
  381. void rlMatrixMode(int mode); // Choose the current matrix to be transformed
  382. void rlPushMatrix(); // Push the current matrix to stack
  383. void rlPopMatrix(); // Pop lattest inserted matrix from stack
  384. void rlLoadIdentity(); // Reset current matrix to identity matrix
  385. void rlTranslatef(float x, float y, float z); // Multiply the current matrix by a translation matrix
  386. void rlRotatef(float angle, float x, float y, float z); // Multiply the current matrix by a rotation matrix
  387. void rlScalef(float x, float y, float z); // Multiply the current matrix by a scaling matrix
  388. void rlMultMatrixf(float* matf); // Multiply the current matrix by another matrix
  389. void rlFrustum(double left, double right, double bottom, double top, double znear, double zfar);
  390. void rlOrtho(double left, double right, double bottom, double top, double znear, double zfar);
  391. void rlViewport(int x, int y, int width, int height); // Set the viewport area
  392. //------------------------------------------------------------------------------------
  393. // Functions Declaration - Vertex level operations
  394. //------------------------------------------------------------------------------------
  395. void rlBegin(int mode); // Initialize drawing mode (how to organize vertex)
  396. void rlEnd(); // Finish vertex providing
  397. void rlVertex2i(int x, int y); // Define one vertex (position) - 2 int
  398. void rlVertex2f(float x, float y); // Define one vertex (position) - 2 float
  399. void rlVertex3f(float x, float y, float z); // Define one vertex (position) - 3 float
  400. void rlTexCoord2f(float x, float y); // Define one vertex (texture coordinate) - 2 float
  401. void rlNormal3f(float x, float y, float z); // Define one vertex (normal) - 3 float
  402. void rlColor4ub(ubyte r, ubyte g, ubyte b, ubyte a); // Define one vertex (color) - 4 byte
  403. void rlColor3f(float x, float y, float z); // Define one vertex (color) - 3 float
  404. void rlColor4f(float x, float y, float z, float w); // Define one vertex (color) - 4 float
  405. //------------------------------------------------------------------------------------
  406. // Functions Declaration - OpenGL style functions (common to 1.1, 3.3+, ES2)
  407. // NOTE: This functions are used to completely abstract raylib code from OpenGL layer,
  408. // some of them are direct wrappers over OpenGL calls, some others are custom
  409. //------------------------------------------------------------------------------------
  410. // Vertex buffers state
  411. bool rlEnableVertexArray(uint vaoId); // Enable vertex array (VAO, if supported)
  412. void rlDisableVertexArray(); // Disable vertex array (VAO, if supported)
  413. void rlEnableVertexBuffer(uint id); // Enable vertex buffer (VBO)
  414. void rlDisableVertexBuffer(); // Disable vertex buffer (VBO)
  415. void rlEnableVertexBufferElement(uint id); // Enable vertex buffer element (VBO element)
  416. void rlDisableVertexBufferElement(); // Disable vertex buffer element (VBO element)
  417. void rlEnableVertexAttribute(uint index); // Enable vertex attribute index
  418. void rlDisableVertexAttribute(uint index); // Disable vertex attribute index
  419. // Enable attribute state pointer
  420. // Disable attribute state pointer
  421. // Textures state
  422. void rlActiveTextureSlot(int slot); // Select and active a texture slot
  423. void rlEnableTexture(uint id); // Enable texture
  424. void rlDisableTexture(); // Disable texture
  425. void rlEnableTextureCubemap(uint id); // Enable texture cubemap
  426. void rlDisableTextureCubemap(); // Disable texture cubemap
  427. void rlTextureParameters(uint id, int param, int value); // Set texture parameters (filter, wrap)
  428. // Shader state
  429. void rlEnableShader(uint id); // Enable shader program
  430. void rlDisableShader(); // Disable shader program
  431. // Framebuffer state
  432. void rlEnableFramebuffer(uint id); // Enable render texture (fbo)
  433. void rlDisableFramebuffer(); // Disable render texture (fbo), return to default framebuffer
  434. void rlActiveDrawBuffers(int count); // Activate multiple draw color buffers
  435. // General render state
  436. void rlEnableColorBlend(); // Enable color blending
  437. void rlDisableColorBlend(); // Disable color blending
  438. void rlEnableDepthTest(); // Enable depth test
  439. void rlDisableDepthTest(); // Disable depth test
  440. void rlEnableDepthMask(); // Enable depth write
  441. void rlDisableDepthMask(); // Disable depth write
  442. void rlEnableBackfaceCulling(); // Enable backface culling
  443. void rlDisableBackfaceCulling(); // Disable backface culling
  444. void rlEnableScissorTest(); // Enable scissor test
  445. void rlDisableScissorTest(); // Disable scissor test
  446. void rlScissor(int x, int y, int width, int height); // Scissor test
  447. void rlEnableWireMode(); // Enable wire mode
  448. void rlDisableWireMode(); // Disable wire mode
  449. void rlSetLineWidth(float width); // Set the line drawing width
  450. float rlGetLineWidth(); // Get the line drawing width
  451. void rlEnableSmoothLines(); // Enable line aliasing
  452. void rlDisableSmoothLines(); // Disable line aliasing
  453. void rlEnableStereoRender(); // Enable stereo rendering
  454. void rlDisableStereoRender(); // Disable stereo rendering
  455. bool rlIsStereoRenderEnabled(); // Check if stereo render is enabled
  456. void rlClearColor(ubyte r, ubyte g, ubyte b, ubyte a); // Clear color buffer with color
  457. void rlClearScreenBuffers(); // Clear used screen buffers (color and depth)
  458. void rlCheckErrors(); // Check and log OpenGL error codes
  459. void rlSetBlendMode(int mode); // Set blending mode
  460. void rlSetBlendFactors(int glSrcFactor, int glDstFactor, int glEquation); // Set blending mode factor and equation (using OpenGL factors)
  461. //------------------------------------------------------------------------------------
  462. // Functions Declaration - rlgl functionality
  463. //------------------------------------------------------------------------------------
  464. // rlgl initialization functions
  465. void rlglInit(int width, int height); // Initialize rlgl (buffers, shaders, textures, states)
  466. void rlglClose(); // De-inititialize rlgl (buffers, shaders, textures)
  467. void rlLoadExtensions(void* loader); // Load OpenGL extensions (loader function required)
  468. int rlGetVersion(); // Get current OpenGL version
  469. void rlSetFramebufferWidth(int width); // Set current framebuffer width
  470. int rlGetFramebufferWidth(); // Get default framebuffer width
  471. void rlSetFramebufferHeight(int height); // Set current framebuffer height
  472. int rlGetFramebufferHeight(); // Get default framebuffer height
  473. uint rlGetTextureIdDefault(); // Get default texture id
  474. uint rlGetShaderIdDefault(); // Get default shader id
  475. int* rlGetShaderLocsDefault(); // Get default shader locations
  476. // Render batch management
  477. // NOTE: rlgl provides a default render batch to behave like OpenGL 1.1 immediate mode
  478. // but this render batch API is exposed in case of custom batches are required
  479. rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements); // Load a render batch system
  480. void rlUnloadRenderBatch(rlRenderBatch batch); // Unload render batch system
  481. void rlDrawRenderBatch(rlRenderBatch* batch); // Draw render batch data (Update->Draw->Reset)
  482. void rlSetRenderBatchActive(rlRenderBatch* batch); // Set the active render batch for rlgl (NULL for default internal)
  483. void rlDrawRenderBatchActive(); // Update and draw internal render batch
  484. bool rlCheckRenderBatchLimit(int vCount); // Check internal buffer overflow for a given number of vertex
  485. void rlSetTexture(uint id); // Set current texture for render batch and check buffers limits
  486. //------------------------------------------------------------------------------------------------------------------------
  487. // Vertex buffers management
  488. uint rlLoadVertexArray(); // Load vertex array (vao) if supported
  489. uint rlLoadVertexBuffer(const(void)* buffer, int size, bool dynamic); // Load a vertex buffer attribute
  490. uint rlLoadVertexBufferElement(const(void)* buffer, int size, bool dynamic); // Load a new attributes element buffer
  491. void rlUpdateVertexBuffer(uint bufferId, const(void)* data, int dataSize, int offset); // Update GPU buffer with new data
  492. void rlUpdateVertexBufferElements(uint id, const(void)* data, int dataSize, int offset); // Update vertex buffer elements with new data
  493. void rlUnloadVertexArray(uint vaoId);
  494. void rlUnloadVertexBuffer(uint vboId);
  495. void rlSetVertexAttribute(uint index, int compSize, int type, bool normalized, int stride, const(void)* pointer);
  496. void rlSetVertexAttributeDivisor(uint index, int divisor);
  497. void rlSetVertexAttributeDefault(int locIndex, const(void)* value, int attribType, int count); // Set vertex attribute default value
  498. void rlDrawVertexArray(int offset, int count);
  499. void rlDrawVertexArrayElements(int offset, int count, const(void)* buffer);
  500. void rlDrawVertexArrayInstanced(int offset, int count, int instances);
  501. void rlDrawVertexArrayElementsInstanced(int offset, int count, const(void)* buffer, int instances);
  502. // Textures management
  503. uint rlLoadTexture(const(void)* data, int width, int height, int format, int mipmapCount); // Load texture in GPU
  504. uint rlLoadTextureDepth(int width, int height, bool useRenderBuffer); // Load depth texture/renderbuffer (to be attached to fbo)
  505. uint rlLoadTextureCubemap(const(void)* data, int size, int format); // Load texture cubemap
  506. void rlUpdateTexture(uint id, int offsetX, int offsetY, int width, int height, int format, const(void)* data); // Update GPU texture with new data
  507. void rlGetGlTextureFormats(int format, uint* glInternalFormat, uint* glFormat, uint* glType); // Get OpenGL internal formats
  508. const(char)* rlGetPixelFormatName(uint format); // Get name string for pixel format
  509. void rlUnloadTexture(uint id); // Unload texture from GPU memory
  510. void rlGenTextureMipmaps(uint id, int width, int height, int format, int* mipmaps); // Generate mipmap data for selected texture
  511. void* rlReadTexturePixels(uint id, int width, int height, int format); // Read texture pixel data
  512. ubyte* rlReadScreenPixels(int width, int height); // Read screen pixel data (color buffer)
  513. // Framebuffer management (fbo)
  514. uint rlLoadFramebuffer(int width, int height); // Load an empty framebuffer
  515. void rlFramebufferAttach(uint fboId, uint texId, int attachType, int texType, int mipLevel); // Attach texture/renderbuffer to a framebuffer
  516. bool rlFramebufferComplete(uint id); // Verify framebuffer is complete
  517. void rlUnloadFramebuffer(uint id); // Delete framebuffer from GPU
  518. // Shaders management
  519. uint rlLoadShaderCode(const(char)* vsCode, const(char)* fsCode); // Load shader from code strings
  520. uint rlCompileShader(const(char)* shaderCode, int type); // Compile custom shader and return shader id (type: RL_VERTEX_SHADER, RL_FRAGMENT_SHADER, RL_COMPUTE_SHADER)
  521. uint rlLoadShaderProgram(uint vShaderId, uint fShaderId); // Load custom shader program
  522. void rlUnloadShaderProgram(uint id); // Unload shader program
  523. int rlGetLocationUniform(uint shaderId, const(char)* uniformName); // Get shader location uniform
  524. int rlGetLocationAttrib(uint shaderId, const(char)* attribName); // Get shader location attribute
  525. void rlSetUniform(int locIndex, const(void)* value, int uniformType, int count); // Set shader value uniform
  526. void rlSetUniformMatrix(int locIndex, Matrix mat); // Set shader value matrix
  527. void rlSetUniformSampler(int locIndex, uint textureId); // Set shader value sampler
  528. void rlSetShader(uint id, int* locs); // Set shader currently active (id and locations)
  529. // Compute shader management
  530. uint rlLoadComputeShaderProgram(uint shaderId); // Load compute shader program
  531. void rlComputeShaderDispatch(uint groupX, uint groupY, uint groupZ); // Dispatch compute shader (equivalent to *draw* for graphics pilepine)
  532. // Shader buffer storage object management (ssbo)
  533. uint rlLoadShaderBuffer(ulong size, const(void)* data, int usageHint); // Load shader storage buffer object (SSBO)
  534. void rlUnloadShaderBuffer(uint ssboId); // Unload shader storage buffer object (SSBO)
  535. void rlUpdateShaderBufferElements(uint id, const(void)* data, ulong dataSize, ulong offset); // Update SSBO buffer data
  536. ulong rlGetShaderBufferSize(uint id); // Get SSBO buffer size
  537. void rlReadShaderBufferElements(uint id, void* dest, ulong count, ulong offset); // Bind SSBO buffer
  538. void rlBindShaderBuffer(uint id, uint index); // Copy SSBO buffer data
  539. // Buffer management
  540. void rlCopyBuffersElements(uint destId, uint srcId, ulong destOffset, ulong srcOffset, ulong count); // Copy SSBO buffer data
  541. void rlBindImageTexture(uint id, uint index, uint format, int readonly); // Bind image texture
  542. // Matrix state management
  543. Matrix rlGetMatrixModelview(); // Get internal modelview matrix
  544. Matrix rlGetMatrixProjection(); // Get internal projection matrix
  545. Matrix rlGetMatrixTransform(); // Get internal accumulated transform matrix
  546. Matrix rlGetMatrixProjectionStereo(int eye); // Get internal projection matrix for stereo render (selected eye)
  547. Matrix rlGetMatrixViewOffsetStereo(int eye); // Get internal view offset matrix for stereo render (selected eye)
  548. void rlSetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix)
  549. void rlSetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix)
  550. void rlSetMatrixProjectionStereo(Matrix right, Matrix left); // Set eyes projection matrices for stereo rendering
  551. void rlSetMatrixViewOffsetStereo(Matrix right, Matrix left); // Set eyes view offsets matrices for stereo rendering
  552. // Quick and dirty cube/quad buffers load->draw->unload
  553. void rlLoadDrawCube(); // Load and draw a cube
  554. void rlLoadDrawQuad(); // Load and draw a quad
  555. // RLGL_H
  556. /***********************************************************************************
  557. *
  558. * RLGL IMPLEMENTATION
  559. *
  560. ************************************************************************************/
  561. // OpenGL 1.1 library for OSX
  562. // OpenGL extensions library
  563. // APIENTRY for OpenGL function pointer declarations is required
  564. // WINGDIAPI definition. Some Windows OpenGL headers need it
  565. // OpenGL 1.1 library
  566. // OpenGL 3 library for OSX
  567. // OpenGL 3 extensions library for OSX
  568. // GLAD extensions loading library, includes OpenGL headers
  569. //#include <EGL/egl.h> // EGL library -> not required, platform layer
  570. // OpenGL ES 2.0 library
  571. // OpenGL ES 2.0 extensions library
  572. // It seems OpenGL ES 2.0 instancing entry points are not defined on Raspberry Pi
  573. // provided headers (despite being defined in official Khronos GLES2 headers)
  574. // Required for: malloc(), free()
  575. // Required for: strcmp(), strlen() [Used in rlglInit(), on extensions loading]
  576. // Required for: sqrtf(), sinf(), cosf(), floor(), log()
  577. //----------------------------------------------------------------------------------
  578. // Defines and Macros
  579. //----------------------------------------------------------------------------------
  580. // Default shader vertex attribute names to set location points
  581. // Binded by default to shader location: 0
  582. // Binded by default to shader location: 1
  583. // Binded by default to shader location: 2
  584. // Binded by default to shader location: 3
  585. // Binded by default to shader location: 4
  586. // Binded by default to shader location: 5
  587. // model-view-projection matrix
  588. // view matrix
  589. // projection matrix
  590. // model matrix
  591. // normal matrix (transpose(inverse(matModelView))
  592. // color diffuse (base tint color, multiplied by texture color)
  593. // texture0 (texture slot active 0)
  594. // texture1 (texture slot active 1)
  595. // texture2 (texture slot active 2)
  596. //----------------------------------------------------------------------------------
  597. // Types and Structures Definition
  598. //----------------------------------------------------------------------------------
  599. // Current render batch
  600. // Default internal render batch
  601. // Current active render batch vertex counter (generic, used for all batches)
  602. // Current active texture coordinate (added on glVertex*())
  603. // Current active normal (added on glVertex*())
  604. // Current active color (added on glVertex*())
  605. // Current matrix mode
  606. // Current matrix pointer
  607. // Default modelview matrix
  608. // Default projection matrix
  609. // Transform matrix to be used with rlTranslate, rlRotate, rlScale
  610. // Require transform matrix application to current draw-call vertex (if required)
  611. // Matrix stack for push/pop
  612. // Matrix stack counter
  613. // Default texture used on shapes/poly drawing (required by shader)
  614. // Active texture ids to be enabled on batch drawing (0 active by default)
  615. // Default vertex shader id (used by default shader program)
  616. // Default fragment shader id (used by default shader program)
  617. // Default shader program id, supports vertex color and diffuse texture
  618. // Default shader locations pointer to be used on rendering
  619. // Current shader id to be used on rendering (by default, defaultShaderId)
  620. // Current shader locations pointer to be used on rendering (by default, defaultShaderLocs)
  621. // Stereo rendering flag
  622. // VR stereo rendering eyes projection matrices
  623. // VR stereo rendering eyes view offset matrices
  624. // Blending mode active
  625. // Blending source factor
  626. // Blending destination factor
  627. // Blending equation
  628. // Current framebuffer width
  629. // Current framebuffer height
  630. // Renderer state
  631. // VAO support (OpenGL ES2 could not support VAO extension) (GL_ARB_vertex_array_object)
  632. // Instancing supported (GL_ANGLE_instanced_arrays, GL_EXT_draw_instanced + GL_EXT_instanced_arrays)
  633. // NPOT textures full support (GL_ARB_texture_non_power_of_two, GL_OES_texture_npot)
  634. // Depth textures supported (GL_ARB_depth_texture, GL_WEBGL_depth_texture, GL_OES_depth_texture)
  635. // float textures support (32 bit per channel) (GL_OES_texture_float)
  636. // DDS texture compression support (GL_EXT_texture_compression_s3tc, GL_WEBGL_compressed_texture_s3tc, GL_WEBKIT_WEBGL_compressed_texture_s3tc)
  637. // ETC1 texture compression support (GL_OES_compressed_ETC1_RGB8_texture, GL_WEBGL_compressed_texture_etc1)
  638. // ETC2/EAC texture compression support (GL_ARB_ES3_compatibility)
  639. // PVR texture compression support (GL_IMG_texture_compression_pvrtc)
  640. // ASTC texture compression support (GL_KHR_texture_compression_astc_hdr, GL_KHR_texture_compression_astc_ldr)
  641. // Clamp mirror wrap mode supported (GL_EXT_texture_mirror_clamp)
  642. // Anisotropic texture filtering support (GL_EXT_texture_filter_anisotropic)
  643. // Compute shaders support (GL_ARB_compute_shader)
  644. // Shader storage buffer object support (GL_ARB_shader_storage_buffer_object)
  645. // Maximum anisotropy level supported (minimum is 2.0f)
  646. // Maximum bits for depth component
  647. // Extensions supported flags
  648. // OpenGL extension functions loader signature (same as GLADloadproc)
  649. // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
  650. //----------------------------------------------------------------------------------
  651. // Global Variables Definition
  652. //----------------------------------------------------------------------------------
  653. // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
  654. // NOTE: VAO functionality is exposed through extensions (OES)
  655. // NOTE: Instancing functionality could also be available through extension
  656. //----------------------------------------------------------------------------------
  657. // Module specific Functions Declaration
  658. //----------------------------------------------------------------------------------
  659. // Load default shader
  660. // Unload default shader
  661. // Get compressed format official GL identifier name
  662. // RLGL_SHOW_GL_DETAILS_INFO
  663. // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
  664. // Generate mipmaps data on CPU side
  665. // Generate next mipmap level on CPU side
  666. // Get pixel data size in bytes (image or texture)
  667. // Auxiliar matrix math functions
  668. // Get identity matrix
  669. // Multiply two matrices
  670. //----------------------------------------------------------------------------------
  671. // Module Functions Definition - Matrix operations
  672. //----------------------------------------------------------------------------------
  673. // Fallback to OpenGL 1.1 function calls
  674. //---------------------------------------
  675. // Choose the current matrix to be transformed
  676. //else if (mode == RL_TEXTURE) // Not supported
  677. // Push the current matrix into RLGL.State.stack
  678. // Pop lattest inserted matrix from RLGL.State.stack
  679. // Reset current matrix to identity matrix
  680. // Multiply the current matrix by a translation matrix
  681. // NOTE: We transpose matrix with multiplication order
  682. // Multiply the current matrix by a rotation matrix
  683. // NOTE: The provided angle must be in degrees
  684. // Axis vector (x, y, z) normalization
  685. // Rotation matrix generation
  686. // NOTE: We transpose matrix with multiplication order
  687. // Multiply the current matrix by a scaling matrix
  688. // NOTE: We transpose matrix with multiplication order
  689. // Multiply the current matrix by another matrix
  690. // Matrix creation from array
  691. // Multiply the current matrix by a perspective matrix generated by parameters
  692. // Multiply the current matrix by an orthographic matrix generated by parameters
  693. // NOTE: If left-right and top-botton values are equal it could create a division by zero,
  694. // response to it is platform/compiler dependant
  695. // Set the viewport area (transformation from normalized device coordinates to window coordinates)
  696. // NOTE: We store current viewport dimensions
  697. //----------------------------------------------------------------------------------
  698. // Module Functions Definition - Vertex level operations
  699. //----------------------------------------------------------------------------------
  700. // Fallback to OpenGL 1.1 function calls
  701. //---------------------------------------
  702. // Initialize drawing mode (how to organize vertex)
  703. // Draw mode can be RL_LINES, RL_TRIANGLES and RL_QUADS
  704. // NOTE: In all three cases, vertex are accumulated over default internal vertex buffer
  705. // Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4,
  706. // that way, following QUADS drawing will keep aligned with index processing
  707. // It implies adding some extra alignment vertex at the end of the draw,
  708. // those vertex are not processed but they are considered as an additional offset
  709. // for the next set of vertex to be drawn
  710. // Finish vertex providing
  711. // NOTE: Depth increment is dependant on rlOrtho(): z-near and z-far values,
  712. // as well as depth buffer bit-depth (16bit or 24bit or 32bit)
  713. // Correct increment formula would be: depthInc = (zfar - znear)/pow(2, bits)
  714. // Verify internal buffers limits
  715. // NOTE: This check is combined with usage of rlCheckRenderBatchLimit()
  716. // WARNING: If we are between rlPushMatrix() and rlPopMatrix() and we need to force a rlDrawRenderBatch(),
  717. // we need to call rlPopMatrix() before to recover *RLGL.State.currentMatrix (RLGL.State.modelview) for the next forced draw call!
  718. // If we have multiple matrix pushed, it will require "RLGL.State.stackCounter" pops before launching the draw
  719. // Define one vertex (position)
  720. // NOTE: Vertex position data is the basic information required for drawing
  721. // Transform provided vector if required
  722. // Verify that current vertex buffer elements limit has not been reached
  723. // Add vertices
  724. // Add current texcoord
  725. // TODO: Add current normal
  726. // By default rlVertexBuffer type does not store normals
  727. // Add current color
  728. // Define one vertex (position)
  729. // Define one vertex (position)
  730. // Define one vertex (texture coordinate)
  731. // NOTE: Texture coordinates are limited to QUADS only
  732. // Define one vertex (normal)
  733. // NOTE: Normals limited to TRIANGLES only?
  734. // Define one vertex (color)
  735. // Define one vertex (color)
  736. // Define one vertex (color)
  737. //--------------------------------------------------------------------------------------
  738. // Module Functions Definition - OpenGL style functions (common to 1.1, 3.3+, ES2)
  739. //--------------------------------------------------------------------------------------
  740. // Set current texture to use
  741. // NOTE: If quads batch limit is reached, we force a draw call and next batch starts
  742. // Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4,
  743. // that way, following QUADS drawing will keep aligned with index processing
  744. // It implies adding some extra alignment vertex at the end of the draw,
  745. // those vertex are not processed but they are considered as an additional offset
  746. // for the next set of vertex to be drawn
  747. // Select and active a texture slot
  748. // Enable texture
  749. // Disable texture
  750. // Enable texture cubemap
  751. // Disable texture cubemap
  752. // Set texture parameters (wrap mode/filter mode)
  753. // Reset anisotropy filter, in case it was set
  754. // Enable shader program
  755. // Disable shader program
  756. // Enable rendering to texture (fbo)
  757. // Disable rendering to texture
  758. // Activate multiple draw color buffers
  759. // NOTE: One color buffer is always active by default
  760. // NOTE: Maximum number of draw buffers supported is implementation dependant,
  761. // it can be queried with glGet*() but it must be at least 8
  762. //GLint maxDrawBuffers = 0;
  763. //glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
  764. //----------------------------------------------------------------------------------
  765. // General render state configuration
  766. //----------------------------------------------------------------------------------
  767. // Enable color blending
  768. // Disable color blending
  769. // Enable depth test
  770. // Disable depth test
  771. // Enable depth write
  772. // Disable depth write
  773. // Enable backface culling
  774. // Disable backface culling
  775. // Enable scissor test
  776. // Disable scissor test
  777. // Scissor test
  778. // Enable wire mode
  779. // NOTE: glPolygonMode() not available on OpenGL ES
  780. // Disable wire mode
  781. // NOTE: glPolygonMode() not available on OpenGL ES
  782. // Set the line drawing width
  783. // Get the line drawing width
  784. // Enable line aliasing
  785. // Disable line aliasing
  786. // Enable stereo rendering
  787. // Disable stereo rendering
  788. // Check if stereo render is enabled
  789. // Clear color buffer with color
  790. // Color values clamp to 0.0f(0) and 1.0f(255)
  791. // Clear used screen buffers (color and depth)
  792. // Clear used buffers: Color and Depth (Depth is used for 3D)
  793. //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // Stencil buffer not used...
  794. // Check and log OpenGL error codes
  795. // Set blend mode
  796. // NOTE: Using GL blend src/dst factors and GL equation configured with rlSetBlendFactors()
  797. // Set blending mode factor and equation
  798. //----------------------------------------------------------------------------------
  799. // Module Functions Definition - OpenGL Debug
  800. //----------------------------------------------------------------------------------
  801. // Ignore non-significant error/warning codes (NVidia drivers)
  802. // NOTE: Here there are the details with a sample output:
  803. // - #131169 - Framebuffer detailed info: The driver allocated storage for renderbuffer 2. (severity: low)
  804. // - #131185 - Buffer detailed info: Buffer object 1 (bound to GL_ELEMENT_ARRAY_BUFFER_ARB, usage hint is GL_ENUM_88e4)
  805. // will use VIDEO memory as the source for buffer object operations. (severity: low)
  806. // - #131218 - Program/shader state performance warning: Vertex shader in program 7 is being recompiled based on GL state. (severity: medium)
  807. // - #131204 - Texture state usage warning: The texture object (0) bound to texture image unit 0 does not have
  808. // a defined base level and cannot be used for texture mapping. (severity: low)
  809. //----------------------------------------------------------------------------------
  810. // Module Functions Definition - rlgl functionality
  811. //----------------------------------------------------------------------------------
  812. // Initialize rlgl: OpenGL extensions, default buffers/shaders/textures, OpenGL states
  813. // Enable OpenGL debug context if required
  814. // glDebugMessageControl(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, GL_DEBUG_SEVERITY_HIGH, 0, 0, GL_TRUE); // TODO: Filter message
  815. // Debug context options:
  816. // - GL_DEBUG_OUTPUT - Faster version but not useful for breakpoints
  817. // - 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
  818. // Init default white texture
  819. // 1 pixel RGBA (4 bytes)
  820. // Init default Shader (customized for GL 3.3 and ES2)
  821. // Loaded: RLGL.State.defaultShaderId + RLGL.State.defaultShaderLocs
  822. // Init default vertex arrays buffers
  823. // Init stack matrices (emulating OpenGL 1.1)
  824. // Init internal matrices
  825. // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
  826. // Initialize OpenGL default states
  827. //----------------------------------------------------------
  828. // Init state: Depth test
  829. // Type of depth testing to apply
  830. // Disable depth testing for 2D (only used for 3D)
  831. // Init state: Blending mode
  832. // Color blending function (how colors are mixed)
  833. // Enable color blending (required to work with transparencies)
  834. // Init state: Culling
  835. // NOTE: All shapes/models triangles are drawn CCW
  836. // Cull the back face (default)
  837. // Front face are defined counter clockwise (default)
  838. // Enable backface culling
  839. // Init state: Cubemap seamless
  840. // Seamless cubemaps (not supported on OpenGL ES 2.0)
  841. // Init state: Color hints (deprecated in OpenGL 3.0+)
  842. // Improve quality of color and texture coordinate interpolation
  843. // Smooth shading between vertex (vertex colors interpolation)
  844. // Store screen size into global variables
  845. //----------------------------------------------------------
  846. // Init state: Color/Depth buffers clear
  847. // Set clear color (black)
  848. // Set clear depth value (default)
  849. // Clear color and depth buffers (depth buffer required for 3D)
  850. // Vertex Buffer Object deinitialization (memory free)
  851. // Unload default shader
  852. // Unload default texture
  853. // Load OpenGL extensions
  854. // NOTE: External loader function must be provided
  855. // Also defined for GRAPHICS_API_OPENGL_21
  856. // NOTE: glad is generated and contains only required OpenGL 3.3 Core extensions (and lower versions)
  857. // Get number of supported extensions
  858. // Get supported extensions list
  859. // WARNING: glGetStringi() not available on OpenGL 2.1
  860. // Register supported extensions flags
  861. // OpenGL 3.3 extensions supported by default (core)
  862. // NOTE: With GLAD, we can check if an extension is supported using the GLAD_GL_xxx booleans
  863. // Texture compression: DXT
  864. // Texture compression: ETC2/EAC
  865. // GRAPHICS_API_OPENGL_33
  866. // Get supported extensions list
  867. // Allocate 512 strings pointers (2 KB)
  868. // One big const string
  869. // NOTE: We have to duplicate string because glGetString() returns a const string
  870. // Get extensions string size in bytes
  871. // Check required extensions
  872. // Check VAO support
  873. // NOTE: Only check on OpenGL ES, OpenGL 3.3 has VAO support as core feature
  874. // The extension is supported by our hardware and driver, try to get related functions pointers
  875. // NOTE: emscripten does not support VAOs natively, it uses emulation and it reduces overall performance...
  876. //glIsVertexArray = (PFNGLISVERTEXARRAYOESPROC)loader("glIsVertexArrayOES"); // NOTE: Fails in WebGL, omitted
  877. // Check instanced rendering support
  878. // Web ANGLE
  879. // Standard EXT
  880. // Check NPOT textures support
  881. // NOTE: Only check on OpenGL ES, OpenGL 3.3 has NPOT textures full support as core feature
  882. // Check texture float support
  883. // Check depth texture support
  884. // Check texture compression support: DXT
  885. // Check texture compression support: ETC1
  886. // Check texture compression support: ETC2/EAC
  887. // Check texture compression support: PVR
  888. // Check texture compression support: ASTC
  889. // Check anisotropic texture filter support
  890. // Check clamp mirror wrap mode support
  891. // Free extensions pointers
  892. // Duplicated string must be deallocated
  893. // GRAPHICS_API_OPENGL_ES2
  894. // Check OpenGL information and capabilities
  895. //------------------------------------------------------------------------------
  896. // Show current OpenGL and GLSL version
  897. // NOTE: Anisotropy levels capability is an extension
  898. // Show some OpenGL GPU capabilities
  899. // GRAPHICS_API_OPENGL_43
  900. // RLGL_SHOW_GL_DETAILS_INFO
  901. // Show some basic info about GL supported features
  902. // RLGL_SHOW_GL_DETAILS_INFO
  903. // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
  904. // Get current OpenGL version
  905. // NOTE: Force OpenGL 3.3 on OSX
  906. // Set current framebuffer width
  907. // Set current framebuffer height
  908. // Get default framebuffer width
  909. // Get default framebuffer height
  910. // Get default internal texture (white texture)
  911. // NOTE: Default texture is a 1x1 pixel UNCOMPRESSED_R8G8B8A8
  912. // Get default shader id
  913. // Get default shader locs
  914. // Render batch management
  915. //------------------------------------------------------------------------------------------------
  916. // Load render batch
  917. // Initialize CPU (RAM) vertex buffers (position, texcoord, color data and indexes)
  918. //--------------------------------------------------------------------------------------------
  919. // 3 float by vertex, 4 vertex by quad
  920. // 2 float by texcoord, 4 texcoord by quad
  921. // 4 float by color, 4 colors by quad
  922. // 6 int by quad (indices)
  923. // 6 int by quad (indices)
  924. // Indices can be initialized right now
  925. //--------------------------------------------------------------------------------------------
  926. // Upload to GPU (VRAM) vertex data and initialize VAOs/VBOs
  927. //--------------------------------------------------------------------------------------------
  928. // Initialize Quads VAO
  929. // Quads - Vertex buffers binding and attributes enable
  930. // Vertex position buffer (shader-location = 0)
  931. // Vertex texcoord buffer (shader-location = 1)
  932. // Vertex color buffer (shader-location = 3)
  933. // Fill index buffer
  934. // Unbind the current VAO
  935. //--------------------------------------------------------------------------------------------
  936. // Init draw calls tracking system
  937. //--------------------------------------------------------------------------------------------
  938. //batch.draws[i].vaoId = 0;
  939. //batch.draws[i].shaderId = 0;
  940. //batch.draws[i].RLGL.State.projection = rlMatrixIdentity();
  941. //batch.draws[i].RLGL.State.modelview = rlMatrixIdentity();
  942. // Record buffer count
  943. // Reset draws counter
  944. // Reset depth value
  945. //--------------------------------------------------------------------------------------------
  946. // Unload default internal buffers vertex data from CPU and GPU
  947. // Unbind everything
  948. // Unload all vertex buffers data
  949. // Unbind VAO attribs data
  950. // Delete VBOs from GPU (VRAM)
  951. // Delete VAOs from GPU (VRAM)
  952. // Free vertex arrays memory from CPU (RAM)
  953. // Unload arrays
  954. // Draw render batch
  955. // NOTE: We require a pointer to reset batch and increase current buffer (multi-buffer)
  956. // Update batch vertex buffers
  957. //------------------------------------------------------------------------------------------------------------
  958. // NOTE: If there is not vertex data, buffers doesn't need to be updated (vertexCount > 0)
  959. // TODO: If no data changed on the CPU arrays --> No need to re-update GPU arrays (change flag required)
  960. // Activate elements VAO
  961. // Vertex positions buffer
  962. //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].vertices, GL_DYNAMIC_DRAW); // Update all buffer
  963. // Texture coordinates buffer
  964. //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].texcoords, GL_DYNAMIC_DRAW); // Update all buffer
  965. // Colors buffer
  966. //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].colors, GL_DYNAMIC_DRAW); // Update all buffer
  967. // NOTE: glMapBuffer() causes sync issue.
  968. // If GPU is working with this buffer, glMapBuffer() will wait(stall) until GPU to finish its job.
  969. // To avoid waiting (idle), you can call first glBufferData() with NULL pointer before glMapBuffer().
  970. // If you do that, the previous data in PBO will be discarded and glMapBuffer() returns a new
  971. // allocated pointer immediately even if GPU is still working with the previous data.
  972. // Another option: map the buffer object into client's memory
  973. // Probably this code could be moved somewhere else...
  974. // batch->vertexBuffer[batch->currentBuffer].vertices = (float *)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
  975. // if (batch->vertexBuffer[batch->currentBuffer].vertices)
  976. // {
  977. // Update vertex data
  978. // }
  979. // glUnmapBuffer(GL_ARRAY_BUFFER);
  980. // Unbind the current VAO
  981. //------------------------------------------------------------------------------------------------------------
  982. // Draw batch vertex buffers (considering VR stereo if required)
  983. //------------------------------------------------------------------------------------------------------------
  984. // Setup current eye viewport (half screen width)
  985. // Set current eye view offset to modelview matrix
  986. // Set current eye projection matrix
  987. // Draw buffers
  988. // Set current shader and upload current MVP matrix
  989. // Create modelview-projection matrix and upload to shader
  990. // Bind vertex attrib: position (shader-location = 0)
  991. // Bind vertex attrib: texcoord (shader-location = 1)
  992. // Bind vertex attrib: color (shader-location = 3)
  993. // Setup some default shader values
  994. // Active default sampler2D: texture0
  995. // Activate additional sampler textures
  996. // Those additional textures will be common for all draw calls of the batch
  997. // Activate default sampler2D texture0 (one texture is always active for default batch shader)
  998. // NOTE: Batch system accumulates calls by texture0 changes, additional textures are enabled for all the draw calls
  999. // Bind current draw call texture, activated as GL_TEXTURE0 and binded to sampler2D texture0 by default
  1000. // We need to define the number of indices to be processed: elementCount*6
  1001. // NOTE: The final parameter tells the GPU the offset in bytes from the
  1002. // start of the index buffer to the location of the first index to process
  1003. // Unbind textures
  1004. // Unbind VAO
  1005. // Unbind shader program
  1006. // Restore viewport to default measures
  1007. //------------------------------------------------------------------------------------------------------------
  1008. // Reset batch buffers
  1009. //------------------------------------------------------------------------------------------------------------
  1010. // Reset vertex counter for next frame
  1011. // Reset depth for next draw
  1012. // Restore projection/modelview matrices
  1013. // Reset RLGL.currentBatch->draws array
  1014. // Reset active texture units for next batch
  1015. // Reset draws counter to one draw for the batch
  1016. //------------------------------------------------------------------------------------------------------------
  1017. // Change to next buffer in the list (in case of multi-buffering)
  1018. // Set the active render batch for rlgl
  1019. // Update and draw internal render batch
  1020. // NOTE: Stereo rendering is checked inside
  1021. // Check internal buffer overflow for a given number of vertex
  1022. // and force a rlRenderBatch draw call if required
  1023. // NOTE: Stereo rendering is checked inside
  1024. // Restore state of last batch so we can continue adding vertices
  1025. // Textures data management
  1026. //-----------------------------------------------------------------------------------------
  1027. // Convert image data to OpenGL texture (returns OpenGL valid Id)
  1028. // Free any old binding
  1029. // Check texture format support by OpenGL 1.1 (compressed textures not supported)
  1030. // GRAPHICS_API_OPENGL_11
  1031. // Generate texture id
  1032. // Mipmap data offset
  1033. // Load the different mipmap levels
  1034. // Security check for NPOT textures
  1035. // Texture parameters configuration
  1036. // NOTE: glTexParameteri does NOT affect texture uploading, just the way it's used
  1037. // 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
  1038. // Set texture to repeat on x-axis
  1039. // Set texture to repeat on y-axis
  1040. // NOTE: If using negative texture coordinates (LoadOBJ()), it does not work!
  1041. // Set texture to clamp on x-axis
  1042. // Set texture to clamp on y-axis
  1043. // Set texture to repeat on x-axis
  1044. // Set texture to repeat on y-axis
  1045. // Magnification and minification filters
  1046. // Alternative: GL_LINEAR
  1047. // Alternative: GL_LINEAR
  1048. // Activate Trilinear filtering if mipmaps are available
  1049. // At this point we have the texture loaded in GPU and texture parameters configured
  1050. // NOTE: If mipmaps were not in data, they are not generated automatically
  1051. // Unbind current texture
  1052. // Load depth texture/renderbuffer (to be attached to fbo)
  1053. // WARNING: OpenGL ES 2.0 requires GL_OES_depth_texture/WEBGL_depth_texture extensions
  1054. // In case depth textures not supported, we force renderbuffer usage
  1055. // NOTE: We let the implementation to choose the best bit-depth
  1056. // Possible formats: GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT32 and GL_DEPTH_COMPONENT32F
  1057. // Create the renderbuffer that will serve as the depth attachment for the framebuffer
  1058. // NOTE: A renderbuffer is simpler than a texture and could offer better performance on embedded devices
  1059. // Load texture cubemap
  1060. // NOTE: Cubemap data is expected to be 6 images in a single data array (one after the other),
  1061. // expected the following convention: +X, -X, +Y, -Y, +Z, -Z
  1062. // Load cubemap faces
  1063. // 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)
  1064. // Set cubemap texture sampling parameters
  1065. // Flag not supported on OpenGL ES 2.0
  1066. // Update already loaded texture in GPU with new data
  1067. // NOTE: We don't know safely if internal texture format is the expected one...
  1068. // Get OpenGL internal formats and data type from raylib PixelFormat
  1069. // NOTE: on OpenGL ES 2.0 (WebGL), internalFormat must match format and options allowed are: GL_LUMINANCE, GL_RGB, GL_RGBA
  1070. // NOTE: Requires extension OES_texture_float
  1071. // NOTE: Requires extension OES_texture_float
  1072. // NOTE: Requires extension OES_texture_float
  1073. // NOTE: Requires OpenGL ES 2.0 or OpenGL 4.3
  1074. // NOTE: Requires OpenGL ES 3.0 or OpenGL 4.3
  1075. // NOTE: Requires OpenGL ES 3.0 or OpenGL 4.3
  1076. // NOTE: Requires PowerVR GPU
  1077. // NOTE: Requires PowerVR GPU
  1078. // NOTE: Requires OpenGL ES 3.1 or OpenGL 4.3
  1079. // NOTE: Requires OpenGL ES 3.1 or OpenGL 4.3
  1080. // Unload texture from GPU memory
  1081. // Generate mipmap data for selected texture
  1082. // Check if texture is power-of-two (POT)
  1083. // WARNING: Manual mipmap generation only works for RGBA 32bit textures!
  1084. // Retrieve texture data from VRAM
  1085. // NOTE: Texture data size is reallocated to fit mipmaps data
  1086. // NOTE: CPU mipmap generation only supports RGBA 32bit data
  1087. // Load the mipmaps
  1088. // Once mipmaps have been generated and data has been uploaded to GPU VRAM, we can discard RAM data
  1089. //glHint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE); // Hint for mipmaps generation algorithm: GL_FASTEST, GL_NICEST, GL_DONT_CARE
  1090. // Generate mipmaps automatically
  1091. // Read texture pixel data
  1092. // NOTE: Using texture id, we can retrieve some texture info (but not on OpenGL ES 2.0)
  1093. // Possible texture info: GL_TEXTURE_RED_SIZE, GL_TEXTURE_GREEN_SIZE, GL_TEXTURE_BLUE_SIZE, GL_TEXTURE_ALPHA_SIZE
  1094. //int width, height, format;
  1095. //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
  1096. //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
  1097. //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &format);
  1098. // 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.
  1099. // Use glPixelStorei to modify padding with the GL_[UN]PACK_ALIGNMENT setting.
  1100. // GL_PACK_ALIGNMENT affects operations that read from OpenGL memory (glReadPixels, glGetTexImage, etc.)
  1101. // GL_UNPACK_ALIGNMENT affects operations that write to OpenGL memory (glTexImage, etc.)
  1102. // glGetTexImage() is not available on OpenGL ES 2.0
  1103. // Texture width and height are required on OpenGL ES 2.0. There is no way to get it from texture id.
  1104. // Two possible Options:
  1105. // 1 - Bind texture to color fbo attachment and glReadPixels()
  1106. // 2 - Create an fbo, activate it, render quad with texture, glReadPixels()
  1107. // We are using Option 1, just need to care for texture format on retrieval
  1108. // NOTE: This behaviour could be conditioned by graphic driver...
  1109. // Attach our texture to FBO
  1110. // We read data as RGBA because FBO texture is configured as RGBA, despite binding another texture format
  1111. // Clean up temporal fbo
  1112. // Read screen pixel data (color buffer)
  1113. // NOTE 1: glReadPixels returns image flipped vertically -> (0,0) is the bottom left corner of the framebuffer
  1114. // NOTE 2: We are getting alpha channel! Be careful, it can be transparent if not cleared properly!
  1115. // Flip image vertically!
  1116. // Flip line
  1117. // Set alpha component value to 255 (no trasparent image retrieval)
  1118. // NOTE: Alpha value has already been applied to RGB in framebuffer, we don't need it!
  1119. // NOTE: image data should be freed
  1120. // Framebuffer management (fbo)
  1121. //-----------------------------------------------------------------------------------------
  1122. // Load a framebuffer to be used for rendering
  1123. // NOTE: No textures attached
  1124. // Create the framebuffer object
  1125. // Unbind any framebuffer
  1126. // Attach color buffer texture to an fbo (unloads previous attachment)
  1127. // NOTE: Attach type: 0-Color, 1-Depth renderbuffer, 2-Depth texture
  1128. // Verify render texture is complete
  1129. // Unload framebuffer from GPU memory
  1130. // NOTE: All attached textures/cubemaps/renderbuffers are also deleted
  1131. // Query depth attachment to automatically delete texture/renderbuffer
  1132. // Bind framebuffer to query depth texture type
  1133. // NOTE: If a texture object is deleted while its image is attached to the *currently bound* framebuffer,
  1134. // the texture image is automatically detached from the currently bound framebuffer.
  1135. // Vertex data management
  1136. //-----------------------------------------------------------------------------------------
  1137. // Load a new attributes buffer
  1138. // Load a new attributes element buffer
  1139. // Enable vertex buffer (VBO)
  1140. // Disable vertex buffer (VBO)
  1141. // Enable vertex buffer element (VBO element)
  1142. // Disable vertex buffer element (VBO element)
  1143. // Update vertex buffer with new data
  1144. // NOTE: dataSize and offset must be provided in bytes
  1145. // Update vertex buffer elements with new data
  1146. // NOTE: dataSize and offset must be provided in bytes
  1147. // Enable vertex array object (VAO)
  1148. // Disable vertex array object (VAO)
  1149. // Enable vertex attribute index
  1150. // Disable vertex attribute index
  1151. // Draw vertex array
  1152. // Draw vertex array elements
  1153. // Draw vertex array instanced
  1154. // Draw vertex array elements instanced
  1155. // Enable vertex state pointer
  1156. //case GL_INDEX_ARRAY: if (buffer != NULL) glIndexPointer(GL_SHORT, 0, buffer); break; // Indexed colors
  1157. // Disable vertex state pointer
  1158. // Load vertex array object (VAO)
  1159. // Set vertex attribute
  1160. // Set vertex attribute divisor
  1161. // Unload vertex array object (VAO)
  1162. // Unload vertex buffer (VBO)
  1163. //TRACELOG(RL_LOG_INFO, "VBO: Unloaded vertex data from VRAM (GPU)");
  1164. // Shaders management
  1165. //-----------------------------------------------------------------------------------------------
  1166. // Load shader from code strings
  1167. // NOTE: If shader string is NULL, using default vertex/fragment shaders
  1168. // Compile vertex shader (if provided)
  1169. // In case no vertex shader was provided or compilation failed, we use default vertex shader
  1170. // Compile fragment shader (if provided)
  1171. // In case no fragment shader was provided or compilation failed, we use default fragment shader
  1172. // In case vertex and fragment shader are the default ones, no need to recompile, we can just assign the default shader program id
  1173. // One of or both shader are new, we need to compile a new shader program
  1174. // We can detach and delete vertex/fragment shaders (if not default ones)
  1175. // NOTE: We detach shader before deletion to make sure memory is freed
  1176. // In case shader program loading failed, we assign default shader
  1177. // In case shader loading fails, we return the default shader
  1178. /*
  1179. else
  1180. {
  1181. // Get available shader uniforms
  1182. // NOTE: This information is useful for debug...
  1183. int uniformCount = -1;
  1184. glGetProgramiv(id, GL_ACTIVE_UNIFORMS, &uniformCount);
  1185. for (int i = 0; i < uniformCount; i++)
  1186. {
  1187. int namelen = -1;
  1188. int num = -1;
  1189. char name[256] = { 0 }; // Assume no variable names longer than 256
  1190. GLenum type = GL_ZERO;
  1191. // Get the name of the uniforms
  1192. glGetActiveUniform(id, i, sizeof(name) - 1, &namelen, &num, &type, name);
  1193. name[namelen] = 0;
  1194. TRACELOGD("SHADER: [ID %i] Active uniform (%s) set at location: %i", id, name, glGetUniformLocation(id, name));
  1195. }
  1196. }
  1197. */
  1198. // Compile custom shader and return shader id
  1199. //case GL_GEOMETRY_SHADER:
  1200. //case GL_GEOMETRY_SHADER:
  1201. // Load custom shader strings and return program id
  1202. // NOTE: Default attribute shader locations must be binded before linking
  1203. // NOTE: If some attrib name is no found on the shader, it locations becomes -1
  1204. // NOTE: All uniform variables are intitialised to 0 when a program links
  1205. // Get the size of compiled shader program (not available on OpenGL ES 2.0)
  1206. // NOTE: If GL_LINK_STATUS is GL_FALSE, program binary length is zero.
  1207. //GLint binarySize = 0;
  1208. //glGetProgramiv(id, GL_PROGRAM_BINARY_LENGTH, &binarySize);
  1209. // Unload shader program
  1210. // Get shader location uniform
  1211. // Get shader location attribute
  1212. // Set shader value uniform
  1213. // Set shader value attribute
  1214. // Set shader value uniform matrix
  1215. // Set shader value uniform sampler
  1216. // Check if texture is already active
  1217. // Register a new active texture for the internal batch system
  1218. // NOTE: Default texture is always activated as GL_TEXTURE0
  1219. // Activate new texture unit
  1220. // Save texture id for binding on drawing
  1221. // Set shader currently active (id and locations)
  1222. // Load compute shader program
  1223. // NOTE: All uniform variables are intitialised to 0 when a program links
  1224. // Get the size of compiled shader program (not available on OpenGL ES 2.0)
  1225. // NOTE: If GL_LINK_STATUS is GL_FALSE, program binary length is zero.
  1226. //GLint binarySize = 0;
  1227. //glGetProgramiv(id, GL_PROGRAM_BINARY_LENGTH, &binarySize);
  1228. // Dispatch compute shader (equivalent to *draw* for graphics pilepine)
  1229. // Load shader storage buffer object (SSBO)
  1230. // Unload shader storage buffer object (SSBO)
  1231. // Update SSBO buffer data
  1232. // Get SSBO buffer size
  1233. // Read SSBO buffer data
  1234. // Bind SSBO buffer
  1235. // Copy SSBO buffer data
  1236. // Bind image texture
  1237. // Matrix state management
  1238. //-----------------------------------------------------------------------------------------
  1239. // Get internal modelview matrix
  1240. // Get internal projection matrix
  1241. // Get internal accumulated transform matrix
  1242. // TODO: Consider possible transform matrices in the RLGL.State.stack
  1243. // Is this the right order? or should we start with the first stored matrix instead of the last one?
  1244. //Matrix matStackTransform = rlMatrixIdentity();
  1245. //for (int i = RLGL.State.stackCounter; i > 0; i--) matStackTransform = rlMatrixMultiply(RLGL.State.stack[i], matStackTransform);
  1246. // Get internal projection matrix for stereo render (selected eye)
  1247. // Get internal view offset matrix for stereo render (selected eye)
  1248. // Set a custom modelview matrix (replaces internal modelview matrix)
  1249. // Set a custom projection matrix (replaces internal projection matrix)
  1250. // Set eyes projection matrices for stereo rendering
  1251. // Set eyes view offsets matrices for stereo rendering
  1252. // Load and draw a quad in NDC
  1253. // Positions Texcoords
  1254. // Gen VAO to contain VBO
  1255. // Gen and fill vertex buffer (VBO)
  1256. // Bind vertex attributes (position, texcoords)
  1257. // Positions
  1258. // Texcoords
  1259. // Draw quad
  1260. // Delete buffers (VBO and VAO)
  1261. // Load and draw a cube in NDC
  1262. // Positions Normals Texcoords
  1263. // Gen VAO to contain VBO
  1264. // Gen and fill vertex buffer (VBO)
  1265. // Bind vertex attributes (position, normals, texcoords)
  1266. // Positions
  1267. // Normals
  1268. // Texcoords
  1269. // Draw cube
  1270. // Delete VBO and VAO
  1271. // Get name string for pixel format
  1272. // 8 bit per pixel (no alpha)
  1273. // 8*2 bpp (2 channels)
  1274. // 16 bpp
  1275. // 24 bpp
  1276. // 16 bpp (1 bit alpha)
  1277. // 16 bpp (4 bit alpha)
  1278. // 32 bpp
  1279. // 32 bpp (1 channel - float)
  1280. // 32*3 bpp (3 channels - float)
  1281. // 32*4 bpp (4 channels - float)
  1282. // 4 bpp (no alpha)
  1283. // 4 bpp (1 bit alpha)
  1284. // 8 bpp
  1285. // 8 bpp
  1286. // 4 bpp
  1287. // 4 bpp
  1288. // 8 bpp
  1289. // 4 bpp
  1290. // 4 bpp
  1291. // 8 bpp
  1292. // 2 bpp
  1293. //----------------------------------------------------------------------------------
  1294. // Module specific Functions Definition
  1295. //----------------------------------------------------------------------------------
  1296. // Load default shader (just vertex positioning and texture coloring)
  1297. // NOTE: This shader program is used for internal buffers
  1298. // NOTE: Loaded: RLGL.State.defaultShaderId, RLGL.State.defaultShaderLocs
  1299. // NOTE: All locations must be reseted to -1 (no location)
  1300. // Vertex shader directly defined, no external file required
  1301. // Fragment shader directly defined, no external file required
  1302. // Precision required for OpenGL ES2 (WebGL)
  1303. // NOTE: Compiled vertex/fragment shaders are not deleted,
  1304. // they are kept for re-use as default shaders in case some shader loading fails
  1305. // Compile default vertex shader
  1306. // Compile default fragment shader
  1307. // Set default shader locations: attributes locations
  1308. // Set default shader locations: uniform locations
  1309. // Unload default shader
  1310. // NOTE: Unloads: RLGL.State.defaultShaderId, RLGL.State.defaultShaderLocs
  1311. // Get compressed format official GL identifier name
  1312. // GL_EXT_texture_compression_s3tc
  1313. // GL_3DFX_texture_compression_FXT1
  1314. // GL_IMG_texture_compression_pvrtc
  1315. // GL_OES_compressed_ETC1_RGB8_texture
  1316. // GL_ARB_texture_compression_rgtc
  1317. // GL_ARB_texture_compression_bptc
  1318. // GL_ARB_ES3_compatibility
  1319. // GL_KHR_texture_compression_astc_hdr
  1320. // RLGL_SHOW_GL_DETAILS_INFO
  1321. // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
  1322. // Mipmaps data is generated after image data
  1323. // NOTE: Only works with RGBA (4 bytes) data!
  1324. // Required mipmap levels count (including base level)
  1325. // Size in bytes (will include mipmaps...), RGBA only
  1326. // Count mipmap levels required
  1327. // Add mipmap size (in bytes)
  1328. // RGBA: 4 bytes
  1329. // Generate mipmaps
  1330. // NOTE: Every mipmap data is stored after data (RGBA - 4 bytes)
  1331. // Size of last mipmap
  1332. // Mipmap size to store after offset
  1333. // Add mipmap to data
  1334. // free mipmap data
  1335. // Manual mipmap generation (basic scaling algorithm)
  1336. // Scaling algorithm works perfectly (box-filter)
  1337. // GRAPHICS_API_OPENGL_11
  1338. // Get pixel data size in bytes (image or texture)
  1339. // NOTE: Size depends on pixel format
  1340. // Size in bytes
  1341. // Bits per pixel
  1342. // Total data size in bytes
  1343. // Most compressed formats works on 4x4 blocks,
  1344. // if texture is smaller, minimum dataSize is 8 or 16
  1345. // Auxiliar math functions
  1346. // Get identity matrix
  1347. // Get two matrix multiplication
  1348. // NOTE: When multiplying matrices... the order matters!
  1349. // RLGL_IMPLEMENTATION