renderer_gl.h 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768
  1. /*
  2. * Copyright 2011-2023 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
  4. */
  5. #ifndef BGFX_RENDERER_GL_H_HEADER_GUARD
  6. #define BGFX_RENDERER_GL_H_HEADER_GUARD
  7. #define BGFX_USE_EGL (BGFX_CONFIG_RENDERER_OPENGLES && (0 \
  8. || BX_PLATFORM_ANDROID \
  9. || BX_PLATFORM_BSD \
  10. || BX_PLATFORM_LINUX \
  11. || BX_PLATFORM_NX \
  12. || BX_PLATFORM_RPI \
  13. || BX_PLATFORM_WINDOWS \
  14. ) )
  15. #define BGFX_USE_HTML5 (BGFX_CONFIG_RENDERER_OPENGLES && (0 \
  16. || BX_PLATFORM_EMSCRIPTEN \
  17. ) )
  18. #define BGFX_USE_WGL (BGFX_CONFIG_RENDERER_OPENGL && (0 \
  19. || BX_PLATFORM_WINDOWS \
  20. ) )
  21. #define BGFX_USE_GLX (BGFX_CONFIG_RENDERER_OPENGL && (0 \
  22. || BX_PLATFORM_BSD \
  23. || BX_PLATFORM_LINUX \
  24. ) )
  25. #define BGFX_USE_GL_DYNAMIC_LIB (0 \
  26. || BX_PLATFORM_BSD \
  27. || BX_PLATFORM_LINUX \
  28. || BX_PLATFORM_OSX \
  29. || BX_PLATFORM_WINDOWS \
  30. )
  31. // Keep a state cache of GL uniform values to avoid redundant uploads
  32. // on the following platforms.
  33. #define BGFX_GL_CONFIG_UNIFORM_CACHE BX_PLATFORM_EMSCRIPTEN
  34. #ifndef BGFX_GL_CONFIG_BLIT_EMULATION
  35. # define BGFX_GL_CONFIG_BLIT_EMULATION 0
  36. #endif // BGFX_GL_CONFIG_BLIT_EMULATION
  37. #ifndef BGFX_GL_CONFIG_TEXTURE_READ_BACK_EMULATION
  38. # define BGFX_GL_CONFIG_TEXTURE_READ_BACK_EMULATION 0
  39. #endif // BGFX_GL_CONFIG_TEXTURE_READ_BACK_EMULATION
  40. #define BGFX_GL_PROFILER_BEGIN(_view, _abgr) \
  41. BX_MACRO_BLOCK_BEGIN \
  42. GL_CHECK(glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, s_viewName[view]) ); \
  43. BGFX_PROFILER_BEGIN(s_viewName[view], _abgr); \
  44. BX_MACRO_BLOCK_END
  45. #define BGFX_GL_PROFILER_BEGIN_LITERAL(_name, _abgr) \
  46. BX_MACRO_BLOCK_BEGIN \
  47. GL_CHECK(glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "" _name) ); \
  48. BGFX_PROFILER_BEGIN_LITERAL("" _name, _abgr); \
  49. BX_MACRO_BLOCK_END
  50. #define BGFX_GL_PROFILER_END() \
  51. BX_MACRO_BLOCK_BEGIN \
  52. BGFX_PROFILER_END(); \
  53. GL_CHECK(glPopDebugGroup() ); \
  54. BX_MACRO_BLOCK_END
  55. #if BGFX_CONFIG_RENDERER_OPENGL
  56. # if BGFX_CONFIG_RENDERER_OPENGL >= 31
  57. # include <gl/glcorearb.h>
  58. # if BX_PLATFORM_OSX
  59. # define GL_ARB_shader_objects // OSX collsion with GLhandleARB in gltypes.h
  60. # endif // BX_PLATFORM_OSX
  61. # else
  62. # if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
  63. # define GL_PROTOTYPES
  64. # define GL_GLEXT_LEGACY
  65. # include <GL/gl.h>
  66. # undef GL_PROTOTYPES
  67. # elif BX_PLATFORM_OSX
  68. # define GL_GLEXT_LEGACY
  69. # define long ptrdiff_t
  70. # include <OpenGL/gl.h>
  71. # undef long
  72. # undef GL_VERSION_1_2
  73. # undef GL_VERSION_1_3
  74. # undef GL_VERSION_1_4
  75. # undef GL_VERSION_1_5
  76. # undef GL_VERSION_2_0
  77. # elif BX_PLATFORM_WINDOWS
  78. # ifndef WIN32_LEAN_AND_MEAN
  79. # define WIN32_LEAN_AND_MEAN
  80. # endif // WIN32_LEAN_AND_MEAN
  81. # include <windows.h>
  82. # include <GL/gl.h>
  83. # else
  84. # include <GL/gl.h>
  85. # endif // BX_PLATFORM_
  86. # include <gl/glext.h>
  87. # endif // BGFX_CONFIG_RENDERER_OPENGL >= 31
  88. #elif BGFX_CONFIG_RENDERER_OPENGLES
  89. typedef double GLdouble;
  90. # if BGFX_CONFIG_RENDERER_OPENGLES < 30
  91. # if BX_PLATFORM_IOS
  92. # include <OpenGLES/ES2/gl.h>
  93. # include <OpenGLES/ES2/glext.h>
  94. //#define GL_UNSIGNED_INT_10_10_10_2_OES 0x8DF6
  95. #define GL_UNSIGNED_INT_2_10_10_10_REV_EXT 0x8368
  96. #define GL_TEXTURE_3D_OES 0x806F
  97. #define GL_SAMPLER_3D_OES 0x8B5F
  98. #define GL_TEXTURE_WRAP_R_OES 0x8072
  99. #define GL_PROGRAM_BINARY_LENGTH_OES 0x8741
  100. # else
  101. # include <GLES2/gl2platform.h>
  102. # include <GLES2/gl2.h>
  103. # include <GLES2/gl2ext.h>
  104. # endif // BX_PLATFORM_
  105. typedef int64_t GLint64;
  106. typedef uint64_t GLuint64;
  107. # define GL_PROGRAM_BINARY_LENGTH GL_PROGRAM_BINARY_LENGTH_OES
  108. # define GL_HALF_FLOAT GL_HALF_FLOAT_OES
  109. # define GL_RGBA8 GL_RGBA8_OES
  110. # define GL_UNSIGNED_INT_2_10_10_10_REV GL_UNSIGNED_INT_2_10_10_10_REV_EXT
  111. # ifndef GL_TEXTURE_3D
  112. # define GL_TEXTURE_3D GL_TEXTURE_3D_OES
  113. # endif // GL_TEXTURE_3D
  114. # define GL_SAMPLER_3D GL_SAMPLER_3D_OES
  115. # define GL_TEXTURE_WRAP_R GL_TEXTURE_WRAP_R_OES
  116. # ifndef GL_MIN
  117. # define GL_MIN GL_MIN_EXT
  118. # endif // GL_MIN
  119. # ifndef GL_MAX
  120. # define GL_MAX GL_MAX_EXT
  121. # endif // GL_MAX
  122. # define GL_DEPTH_COMPONENT24 GL_DEPTH_COMPONENT24_OES
  123. # define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES
  124. # define GL_DEPTH_COMPONENT32 GL_DEPTH_COMPONENT32_OES
  125. # define GL_UNSIGNED_INT_24_8 GL_UNSIGNED_INT_24_8_OES
  126. # elif BGFX_CONFIG_RENDERER_OPENGLES >= 30
  127. # include <GLES3/gl3platform.h>
  128. # if BGFX_CONFIG_RENDERER_OPENGLES >= 32
  129. # include <GLES3/gl32.h>
  130. # elif BGFX_CONFIG_RENDERER_OPENGLES >= 31
  131. # include <GLES3/gl31.h>
  132. # else
  133. # include <GLES3/gl3.h>
  134. # endif // BGFX_CONFIG_RENDERER_OPENGLES
  135. # include <GLES2/gl2ext.h>
  136. # endif // BGFX_CONFIG_RENDERER_
  137. # if BGFX_USE_EGL
  138. # include "glcontext_egl.h"
  139. # endif // BGFX_USE_EGL
  140. # if BGFX_USE_HTML5
  141. # include "glcontext_html5.h"
  142. # endif // BGFX_USE_EGL
  143. #endif // BGFX_CONFIG_RENDERER_OPENGL
  144. #include "renderer.h"
  145. #include "debug_renderdoc.h"
  146. #include "emscripten.h"
  147. #ifndef GL_LUMINANCE
  148. # define GL_LUMINANCE 0x1909
  149. #endif // GL_LUMINANCE
  150. #ifndef GL_BGR
  151. # define GL_BGR 0x80E0
  152. #endif // GL_BGR
  153. #ifndef GL_BGRA
  154. # define GL_BGRA 0x80E1
  155. #endif // GL_BGRA
  156. #ifndef GL_R8
  157. # define GL_R8 0x8229
  158. #endif // GL_R8
  159. #ifndef GL_R8I
  160. # define GL_R8I 0x8231
  161. #endif // GL_R8I
  162. #ifndef GL_R8UI
  163. # define GL_R8UI 0x8232
  164. #endif // GL_R8UI
  165. #ifndef GL_R8_SNORM
  166. # define GL_R8_SNORM 0x8F94
  167. #endif // GL_R8_SNORM
  168. #ifndef GL_R16
  169. # define GL_R16 0x822A
  170. #endif // GL_R16
  171. #ifndef GL_R16I
  172. # define GL_R16I 0x8233
  173. #endif // GL_R16I
  174. #ifndef GL_R16UI
  175. # define GL_R16UI 0x8234
  176. #endif // GL_R16UI
  177. #ifndef GL_R16F
  178. # define GL_R16F 0x822D
  179. #endif // GL_R16F
  180. #ifndef GL_R16_SNORM
  181. # define GL_R16_SNORM 0x8F98
  182. #endif // GL_R16_SNORM
  183. #ifndef GL_R32UI
  184. # define GL_R32UI 0x8236
  185. #endif // GL_R32UI
  186. #ifndef GL_R32F
  187. # define GL_R32F 0x822E
  188. #endif // GL_R32F
  189. #ifndef GL_RG8
  190. # define GL_RG8 0x822B
  191. #endif // GL_RG8
  192. #ifndef GL_RG8I
  193. # define GL_RG8I 0x8237
  194. #endif // GL_RG8I
  195. #ifndef GL_RG8UI
  196. # define GL_RG8UI 0x8238
  197. #endif // GL_RG8UI
  198. #ifndef GL_RG8_SNORM
  199. # define GL_RG8_SNORM 0x8F95
  200. #endif // GL_RG8_SNORM
  201. #ifndef GL_RG16
  202. # define GL_RG16 0x822C
  203. #endif // GL_RG16
  204. #ifndef GL_RG16UI
  205. # define GL_RG16UI 0x823A
  206. #endif // GL_RG16UI
  207. #ifndef GL_RG16F
  208. # define GL_RG16F 0x822F
  209. #endif // GL_RG16F
  210. #ifndef GL_RG16I
  211. # define GL_RG16I 0x8239
  212. #endif // GL_RG16I
  213. #ifndef GL_RG16UI
  214. # define GL_RG16UI 0x823A
  215. #endif // GL_RG16UI
  216. #ifndef GL_RG16_SNORM
  217. # define GL_RG16_SNORM 0x8F99
  218. #endif // GL_RG16_SNORM
  219. #ifndef GL_R32I
  220. # define GL_R32I 0x8235
  221. #endif // GL_R32I
  222. #ifndef GL_R32UI
  223. # define GL_R32UI 0x8236
  224. #endif // GL_R32UI
  225. #ifndef GL_RG32I
  226. # define GL_RG32I 0x823B
  227. #endif // GL_RG32I
  228. #ifndef GL_RG32UI
  229. # define GL_RG32UI 0x823C
  230. #endif // GL_RG32UI
  231. #ifndef GL_RG32F
  232. # define GL_RG32F 0x8230
  233. #endif // GL_RG32F
  234. #ifndef GL_RGB8
  235. # define GL_RGB8 0x8051
  236. #endif // GL_RGB8
  237. #ifndef GL_SRGB
  238. # define GL_SRGB 0x8C40
  239. #endif // GL_SRGB
  240. #ifndef GL_SRGB8
  241. # define GL_SRGB8 0x8C41
  242. #endif // GL_SRGB8
  243. #ifndef GL_RGB8I
  244. # define GL_RGB8I 0x8D8F
  245. #endif // GL_RGB8I
  246. #ifndef GL_RGB8UI
  247. # define GL_RGB8UI 0x8D7D
  248. #endif // GL_RGB8UI
  249. #ifndef GL_RGB8_SNORM
  250. # define GL_RGB8_SNORM 0x8F96
  251. #endif // GL_RGB8_SNORM
  252. #ifndef GL_RGBA8I
  253. # define GL_RGBA8I 0x8D8E
  254. #endif // GL_RGBA8I
  255. #ifndef GL_RGBA8UI
  256. # define GL_RGBA8UI 0x8D7C
  257. #endif // GL_RGBA8UI
  258. #ifndef GL_RGBA8_SNORM
  259. # define GL_RGBA8_SNORM 0x8F97
  260. #endif // GL_RGBA8_SNORM
  261. #ifndef GL_RGBA16I
  262. # define GL_RGBA16I 0x8D88
  263. #endif // GL_RGBA16I
  264. #ifndef GL_RGBA16UI
  265. # define GL_RGBA16UI 0x8D76
  266. #endif // GL_RGBA16UI
  267. #ifndef GL_RGBA16_SNORM
  268. # define GL_RGBA16_SNORM 0x8F9B
  269. #endif // GL_RGBA16_SNORM
  270. #ifndef GL_RGBA32UI
  271. # define GL_RGBA32UI 0x8D70
  272. #endif // GL_RGBA32UI
  273. #ifndef GL_RGBA32F
  274. # define GL_RGBA32F 0x8814
  275. #endif // GL_RGBA32F
  276. #ifndef GL_RGBA32I
  277. # define GL_RGBA32I 0x8D82
  278. #endif // GL_RGBA32I
  279. #ifndef GL_STENCIL_INDEX
  280. # define GL_STENCIL_INDEX 0x1901
  281. #endif // GL_STENCIL_INDEX
  282. #ifndef GL_RED
  283. # define GL_RED 0x1903
  284. #endif // GL_RED
  285. #ifndef GL_RED_INTEGER
  286. # define GL_RED_INTEGER 0x8D94
  287. #endif // GL_RED_INTEGER
  288. #ifndef GL_RG
  289. # define GL_RG 0x8227
  290. #endif // GL_RG
  291. #ifndef GL_RG_INTEGER
  292. # define GL_RG_INTEGER 0x8228
  293. #endif // GL_RG_INTEGER
  294. #ifndef GL_GREEN
  295. # define GL_GREEN 0x1904
  296. #endif // GL_GREEN
  297. #ifndef GL_BLUE
  298. # define GL_BLUE 0x1905
  299. #endif // GL_BLUE
  300. #ifndef GL_RGB_INTEGER
  301. # define GL_RGB_INTEGER 0x8D98
  302. #endif // GL_RGB_INTEGER
  303. #ifndef GL_RGBA_INTEGER
  304. # define GL_RGBA_INTEGER 0x8D99
  305. #endif // GL_RGBA_INTEGER
  306. #ifndef GL_RGB10_A2
  307. # define GL_RGB10_A2 0x8059
  308. #endif // GL_RGB10_A2
  309. #ifndef GL_RGBA16
  310. # define GL_RGBA16 0x805B
  311. #endif // GL_RGBA16
  312. #ifndef GL_RGBA16F
  313. # define GL_RGBA16F 0x881A
  314. #endif // GL_RGBA16F
  315. #ifndef GL_R16UI
  316. # define GL_R16UI 0x8234
  317. #endif // GL_R16UI
  318. #ifndef GL_RGBA16UI
  319. # define GL_RGBA16UI 0x8D76
  320. #endif // GL_RGBA16UI
  321. #ifndef GL_RGB9_E5
  322. # define GL_RGB9_E5 0x8C3D
  323. #endif // GL_RGB9_E5
  324. #ifndef GL_UNSIGNED_INT_5_9_9_9_REV
  325. # define GL_UNSIGNED_INT_5_9_9_9_REV 0x8C3E
  326. #endif // GL_UNSIGNED_INT_5_9_9_9_REV
  327. #ifndef GL_R11F_G11F_B10F
  328. # define GL_R11F_G11F_B10F 0x8C3A
  329. #endif // GL_R11F_G11F_B10F
  330. #ifndef GL_UNSIGNED_SHORT_5_6_5_REV
  331. # define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364
  332. #endif // GL_UNSIGNED_SHORT_5_6_5_REV
  333. #ifndef GL_UNSIGNED_SHORT_1_5_5_5_REV
  334. # define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
  335. #endif // GL_UNSIGNED_SHORT_1_5_5_5_REV
  336. #ifndef GL_UNSIGNED_SHORT_4_4_4_4_REV
  337. # define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365
  338. #endif // GL_UNSIGNED_SHORT_4_4_4_4_REV
  339. #ifndef GL_UNSIGNED_INT_10F_11F_11F_REV
  340. # define GL_UNSIGNED_INT_10F_11F_11F_REV 0x8C3B
  341. #endif // GL_UNSIGNED_INT_10F_11F_11F_REV
  342. #ifndef GL_COMPRESSED_RGB_S3TC_DXT1_EXT
  343. # define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
  344. #endif // GL_COMPRESSED_RGB_S3TC_DXT1_EXT
  345. #ifndef GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
  346. # define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
  347. #endif // GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
  348. #ifndef GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
  349. # define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
  350. #endif // GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
  351. #ifndef GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
  352. # define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
  353. #endif // GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
  354. #ifndef GL_COMPRESSED_LUMINANCE_LATC1_EXT
  355. # define GL_COMPRESSED_LUMINANCE_LATC1_EXT 0x8C70
  356. #endif // GL_COMPRESSED_LUMINANCE_LATC1_EXT
  357. #ifndef GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
  358. # define GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT 0x8C72
  359. #endif // GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
  360. #ifndef GL_COMPRESSED_RED_RGTC1
  361. # define GL_COMPRESSED_RED_RGTC1 0x8DBB
  362. #endif // GL_COMPRESSED_RED_RGTC1
  363. #ifndef GL_COMPRESSED_RG_RGTC2
  364. # define GL_COMPRESSED_RG_RGTC2 0x8DBD
  365. #endif // GL_COMPRESSED_RG_RGTC2
  366. #ifndef GL_ETC1_RGB8_OES
  367. # define GL_ETC1_RGB8_OES 0x8D64
  368. #endif // GL_ETC1_RGB8_OES
  369. #ifndef GL_COMPRESSED_RGB8_ETC2
  370. # define GL_COMPRESSED_RGB8_ETC2 0x9274
  371. #endif // GL_COMPRESSED_RGB8_ETC2
  372. #ifndef GL_COMPRESSED_RGBA8_ETC2_EAC
  373. # define GL_COMPRESSED_RGBA8_ETC2_EAC 0x9278
  374. #endif // GL_COMPRESSED_RGBA8_ETC2_EAC
  375. #ifndef GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
  376. # define GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9276
  377. #endif // GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
  378. #ifndef GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG
  379. # define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01
  380. #endif // GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG
  381. #ifndef GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG
  382. # define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03
  383. #endif // GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG
  384. #ifndef GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG
  385. # define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00
  386. #endif // GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG
  387. #ifndef GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
  388. # define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02
  389. #endif // GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
  390. #ifndef GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG
  391. # define GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG 0x9137
  392. #endif // GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG
  393. #ifndef GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG
  394. # define GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG 0x9138
  395. #endif // GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG
  396. #ifndef GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT
  397. # define GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT 0x8A54
  398. #endif // GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT
  399. #ifndef GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT
  400. # define GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT 0x8A55
  401. #endif // GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT
  402. #ifndef GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT
  403. # define GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT 0x8A56
  404. #endif // GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT
  405. #ifndef GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT
  406. # define GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT 0x8A57
  407. #endif // GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT
  408. #ifndef ATC_RGB_AMD
  409. #define GL_ATC_RGB_AMD 0x8C92
  410. #endif // ATC_RGB_AMD
  411. #ifndef GL_ATC_RGBA_EXPLICIT_ALPHA_AMD
  412. # define GL_ATC_RGBA_EXPLICIT_ALPHA_AMD 0x8C93
  413. #endif // GL_ATC_RGBA_EXPLICIT_ALPHA_AMD
  414. #ifndef ATC_RGBA_INTERPOLATED_ALPHA_AMD
  415. # define GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE
  416. #endif // ATC_RGBA_INTERPOLATED_ALPHA_AMD
  417. #ifndef GL_COMPRESSED_RGBA_ASTC_4x4_KHR
  418. # define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0
  419. #endif // GL_COMPRESSED_RGBA_ASTC_4x4_KHR
  420. #ifndef GL_COMPRESSED_RGBA_ASTC_5x4_KHR
  421. # define GL_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1
  422. #endif // GL_COMPRESSED_RGBA_ASTC_5x4_KHR
  423. #ifndef GL_COMPRESSED_RGBA_ASTC_5x5_KHR
  424. # define GL_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2
  425. #endif // GL_COMPRESSED_RGBA_ASTC_5x5_KHR
  426. #ifndef GL_COMPRESSED_RGBA_ASTC_6x5_KHR
  427. # define GL_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3
  428. #endif // GL_COMPRESSED_RGBA_ASTC_6x5_KHR
  429. #ifndef GL_COMPRESSED_RGBA_ASTC_6x6_KHR
  430. # define GL_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4
  431. #endif // GL_COMPRESSED_RGBA_ASTC_6x6_KHR
  432. #ifndef GL_COMPRESSED_RGBA_ASTC_8x5_KHR
  433. # define GL_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5
  434. #endif // GL_COMPRESSED_RGBA_ASTC_8x5_KHR
  435. #ifndef GL_COMPRESSED_RGBA_ASTC_8x6_KHR
  436. # define GL_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6
  437. #endif // GL_COMPRESSED_RGBA_ASTC_8x6_KHR
  438. #ifndef GL_COMPRESSED_RGBA_ASTC_8x8_KHR
  439. # define GL_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7
  440. #endif // GL_COMPRESSED_RGBA_ASTC_8x8_KHR
  441. #ifndef GL_COMPRESSED_RGBA_ASTC_10x5_KHR
  442. # define GL_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8
  443. #endif // GL_COMPRESSED_RGBA_ASTC_10x5_KHR
  444. #ifndef GL_COMPRESSED_RGBA_ASTC_10x6_KHR
  445. # define GL_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9
  446. #endif // GL_COMPRESSED_RGBA_ASTC_10x6_KHR
  447. #ifndef GL_COMPRESSED_RGBA_ASTC_10x8_KHR
  448. # define GL_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA
  449. #endif // GL_COMPRESSED_RGBA_ASTC_10x8_KHR
  450. #ifndef GL_COMPRESSED_RGBA_ASTC_10x10_KHR
  451. # define GL_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB
  452. #endif // GL_COMPRESSED_RGBA_ASTC_10x10_KHR
  453. #ifndef GL_COMPRESSED_RGBA_ASTC_12x10_KHR
  454. # define GL_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC
  455. #endif // GL_COMPRESSED_RGBA_ASTC_12x10_KHR
  456. #ifndef GL_COMPRESSED_RGBA_ASTC_12x12_KHR
  457. # define GL_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD
  458. #endif // GL_COMPRESSED_RGBA_ASTC_12x12_KHR
  459. #ifndef GL_COMPRESSED_SRGB8_ASTC_4x4_KHR
  460. # define GL_COMPRESSED_SRGB8_ASTC_4x4_KHR 0x93D0
  461. #endif // GL_COMPRESSED_SRGB8_ASTC_4x4_KHR
  462. #ifndef GL_COMPRESSED_SRGB8_ASTC_5x4_KHR
  463. # define GL_COMPRESSED_SRGB8_ASTC_5x4_KHR 0x93D1
  464. #endif // GL_COMPRESSED_SRGB8_ASTC_5x4_KHR
  465. #ifndef GL_COMPRESSED_SRGB8_ASTC_5x5_KHR
  466. # define GL_COMPRESSED_SRGB8_ASTC_5x5_KHR 0x93D2
  467. #endif // GL_COMPRESSED_SRGB8_ASTC_5x5_KHR
  468. #ifndef GL_COMPRESSED_SRGB8_ASTC_6x5_KHR
  469. # define GL_COMPRESSED_SRGB8_ASTC_6x5_KHR 0x93D3
  470. #endif // GL_COMPRESSED_SRGB8_ASTC_6x5_KHR
  471. #ifndef GL_COMPRESSED_SRGB8_ASTC_6x6_KHR
  472. # define GL_COMPRESSED_SRGB8_ASTC_6x6_KHR 0x93D4
  473. #endif // GL_COMPRESSED_SRGB8_ASTC_6x6_KHR
  474. #ifndef GL_COMPRESSED_SRGB8_ASTC_8x5_KHR
  475. # define GL_COMPRESSED_SRGB8_ASTC_8x5_KHR 0x93D5
  476. #endif // GL_COMPRESSED_SRGB8_ASTC_8x5_KHR
  477. #ifndef GL_COMPRESSED_SRGB8_ASTC_8x6_KHR
  478. # define GL_COMPRESSED_SRGB8_ASTC_8x6_KHR 0x93D6
  479. #endif // GL_COMPRESSED_SRGB8_ASTC_8x6_KHR
  480. #ifndef GL_COMPRESSED_SRGB8_ASTC_8x8_KHR
  481. # define GL_COMPRESSED_SRGB8_ASTC_8x8_KHR 0x93D7
  482. #endif // GL_COMPRESSED_SRGB8_ASTC_8x8_KHR
  483. #ifndef GL_COMPRESSED_SRGB8_ASTC_10x5_KHR
  484. # define GL_COMPRESSED_SRGB8_ASTC_10x5_KHR 0x93D8
  485. #endif // GL_COMPRESSED_SRGB8_ASTC_10x5_KHR
  486. #ifndef GL_COMPRESSED_SRGB8_ASTC_10x6_KHR
  487. # define GL_COMPRESSED_SRGB8_ASTC_10x6_KHR 0x93D9
  488. #endif // GL_COMPRESSED_SRGB8_ASTC_10x6_KHR
  489. #ifndef GL_COMPRESSED_SRGB8_ASTC_10x8_KHR
  490. # define GL_COMPRESSED_SRGB8_ASTC_10x8_KHR 0x93DA
  491. #endif // GL_COMPRESSED_SRGB8_ASTC_10x8_KHR
  492. #ifndef GL_COMPRESSED_SRGB8_ASTC_10x10_KHR
  493. # define GL_COMPRESSED_SRGB8_ASTC_10x10_KHR 0x93DB
  494. #endif // GL_COMPRESSED_SRGB8_ASTC_10x10_KHR
  495. #ifndef GL_COMPRESSED_SRGB8_ASTC_12x10_KHR
  496. # define GL_COMPRESSED_SRGB8_ASTC_12x10_KHR 0x93DC
  497. #endif // GL_COMPRESSED_SRGB8_ASTC_12x10_KHR
  498. #ifndef GL_COMPRESSED_SRGB8_ASTC_12x12_KHR
  499. # define GL_COMPRESSED_SRGB8_ASTC_12x12_KHR 0x93DD
  500. #endif // GL_COMPRESSED_SRGB8_ASTC_12x12_KHR
  501. #ifndef GL_COMPRESSED_RGBA_BPTC_UNORM_ARB
  502. # define GL_COMPRESSED_RGBA_BPTC_UNORM_ARB 0x8E8C
  503. #endif // GL_COMPRESSED_RGBA_BPTC_UNORM_ARB
  504. #ifndef GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB
  505. # define GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB 0x8E8D
  506. #endif // GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB
  507. #ifndef GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
  508. # define GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB 0x8E8E
  509. #endif // GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
  510. #ifndef GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
  511. # define GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB 0x8E8F
  512. #endif // GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
  513. #ifndef GL_SRGB_EXT
  514. # define GL_SRGB_EXT 0x8C40
  515. #endif // GL_SRGB_EXT
  516. #ifndef GL_SRGB_ALPHA_EXT
  517. # define GL_SRGB_ALPHA_EXT 0x8C42
  518. #endif // GL_SRGB_ALPHA_EXT
  519. #ifndef GL_SRGB8_ALPHA8
  520. # define GL_SRGB8_ALPHA8 0x8C43
  521. #endif // GL_SRGB8_ALPHA8
  522. #ifndef GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
  523. # define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT 0x8C4D
  524. #endif // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
  525. #ifndef GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
  526. # define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT 0x8C4E
  527. #endif // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
  528. #ifndef GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
  529. # define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT 0x8C4F
  530. #endif // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
  531. #ifndef GL_COMPRESSED_SRGB8_ETC2
  532. # define GL_COMPRESSED_SRGB8_ETC2 0x9275
  533. #endif // GL_COMPRESSED_SRGB8_ETC2
  534. #ifndef GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
  535. # define GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9277
  536. #endif // GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
  537. #ifndef GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE
  538. # define GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE 0x93A0
  539. #endif // GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE
  540. #ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT
  541. # define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
  542. #endif // GL_TEXTURE_MAX_ANISOTROPY_EXT
  543. #ifndef GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
  544. # define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
  545. #endif // GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
  546. #ifndef GL_TEXTURE_SWIZZLE_RGBA
  547. # define GL_TEXTURE_SWIZZLE_RGBA 0x8E46
  548. #endif // GL_TEXTURE_SWIZZLE_RGBA
  549. #ifndef GL_MAX_SAMPLES
  550. # define GL_MAX_SAMPLES 0x8D57
  551. #endif // GL_MAX_SAMPLES
  552. #ifndef GL_MAX_SAMPLES_IMG
  553. # define GL_MAX_SAMPLES_IMG 0x9135
  554. #endif // GL_MAX_SAMPLES_IMG
  555. #ifndef GL_MAX_COLOR_ATTACHMENTS
  556. # define GL_MAX_COLOR_ATTACHMENTS 0x8CDF
  557. #endif // GL_MAX_COLOR_ATTACHMENTS
  558. #ifndef GL_MAX_DRAW_BUFFERS
  559. # define GL_MAX_DRAW_BUFFERS 0x8824
  560. #endif // GL_MAX_DRAW_BUFFERS
  561. #ifndef GL_MAX_ARRAY_TEXTURE_LAYERS
  562. # define GL_MAX_ARRAY_TEXTURE_LAYERS 0x88FF
  563. #endif // GL_MAX_ARRAY_TEXTURE_LAYERS
  564. #ifndef GL_MAX_LABEL_LENGTH
  565. # define GL_MAX_LABEL_LENGTH 0x82E8
  566. #endif // GL_MAX_LABEL_LENGTH
  567. #ifndef GL_QUERY_RESULT
  568. # define GL_QUERY_RESULT 0x8866
  569. #endif // GL_QUERY_RESULT
  570. #ifndef GL_QUERY_RESULT_AVAILABLE
  571. # define GL_QUERY_RESULT_AVAILABLE 0x8867
  572. #endif // GL_QUERY_RESULT_AVAILABLE
  573. #ifndef GL_SAMPLES_PASSED
  574. # define GL_SAMPLES_PASSED 0x8914
  575. #endif // GL_SAMPLES_PASSED
  576. #ifndef GL_ANY_SAMPLES_PASSED
  577. # define GL_ANY_SAMPLES_PASSED 0x8C2F
  578. #endif // GL_ANY_SAMPLES_PASSED
  579. #ifndef GL_READ_FRAMEBUFFER
  580. # define GL_READ_FRAMEBUFFER 0x8CA8
  581. #endif /// GL_READ_FRAMEBUFFER
  582. #ifndef GL_DRAW_FRAMEBUFFER
  583. # define GL_DRAW_FRAMEBUFFER 0x8CA9
  584. #endif // GL_DRAW_FRAMEBUFFER
  585. #ifndef GL_TIME_ELAPSED
  586. # define GL_TIME_ELAPSED 0x88BF
  587. #endif // GL_TIME_ELAPSED
  588. #ifndef GL_TIMESTAMP
  589. # define GL_TIMESTAMP 0x8E28
  590. #endif // GL_TIMESTAMP
  591. #ifndef GL_VBO_FREE_MEMORY_ATI
  592. # define GL_VBO_FREE_MEMORY_ATI 0x87FB
  593. #endif // GL_VBO_FREE_MEMORY_ATI
  594. #ifndef GL_TEXTURE_FREE_MEMORY_ATI
  595. # define GL_TEXTURE_FREE_MEMORY_ATI 0x87FC
  596. #endif // GL_TEXTURE_FREE_MEMORY_ATI
  597. #ifndef GL_RENDERBUFFER_FREE_MEMORY_ATI
  598. # define GL_RENDERBUFFER_FREE_MEMORY_ATI 0x87FD
  599. #endif // GL_RENDERBUFFER_FREE_MEMORY_ATI
  600. // https://web.archive.org/web/20190207230448/http://developer.download.nvidia.com/opengl/specs/GL_NVX_gpu_memory_info.txt
  601. #ifndef GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX
  602. # define GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX 0x9047
  603. #endif // GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX
  604. #ifndef GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX
  605. # define GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX 0x9048
  606. #endif // GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX
  607. #ifndef GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX
  608. # define GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX 0x9049
  609. #endif // GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX
  610. #ifndef GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX
  611. # define GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX 0x904A
  612. #endif // GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX
  613. #ifndef GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX
  614. # define GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX 0x904B
  615. #endif // GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX
  616. #ifndef GL_UNPACK_ROW_LENGTH
  617. # define GL_UNPACK_ROW_LENGTH 0x0CF2
  618. #endif // GL_UNPACK_ROW_LENGTH
  619. #ifndef GL_DEPTH_STENCIL
  620. # define GL_DEPTH_STENCIL 0x84F9
  621. #endif // GL_DEPTH_STENCIL
  622. #ifndef GL_DEPTH_COMPONENT32
  623. # define GL_DEPTH_COMPONENT32 0x81A7
  624. #endif // GL_DEPTH_COMPONENT32
  625. #ifndef GL_DEPTH_COMPONENT32F
  626. # define GL_DEPTH_COMPONENT32F 0x8CAC
  627. #endif // GL_DEPTH_COMPONENT32F
  628. #ifndef GL_DEPTH_STENCIL_ATTACHMENT
  629. # define GL_DEPTH_STENCIL_ATTACHMENT 0x821A
  630. #endif // GL_DEPTH_STENCIL_ATTACHMENT
  631. #ifndef GL_TEXTURE_COMPARE_MODE
  632. # define GL_TEXTURE_COMPARE_MODE 0x884C
  633. #endif // GL_TEXTURE_COMPARE_MODE
  634. #ifndef GL_TEXTURE_COMPARE_FUNC
  635. # define GL_TEXTURE_COMPARE_FUNC 0x884D
  636. #endif // GL_TEXTURE_COMPARE_FUNC
  637. #ifndef GL_COMPARE_REF_TO_TEXTURE
  638. # define GL_COMPARE_REF_TO_TEXTURE 0x884E
  639. #endif // GL_COMPARE_REF_TO_TEXTURE
  640. #ifndef GL_INT_SAMPLER_2D
  641. # define GL_INT_SAMPLER_2D 0x8DCA
  642. #endif // GL_INT_SAMPLER_2D
  643. #ifndef GL_UNSIGNED_INT_SAMPLER_2D
  644. # define GL_UNSIGNED_INT_SAMPLER_2D 0x8DD2
  645. #endif // GL_UNSIGNED_INT_SAMPLER_2D
  646. #ifndef GL_INT_SAMPLER_2D_ARRAY
  647. # define GL_INT_SAMPLER_2D_ARRAY 0x8DCF
  648. #endif // GL_INT_SAMPLER_2D_ARRAY
  649. #ifndef GL_UNSIGNED_INT_SAMPLER_2D_ARRAY
  650. # define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY 0x8DD7
  651. #endif // GL_UNSIGNED_INT_SAMPLER_2D_ARRAY
  652. #ifndef GL_INT_SAMPLER_3D
  653. # define GL_INT_SAMPLER_3D 0x8DCB
  654. #endif // GL_INT_SAMPLER_3D
  655. #ifndef GL_UNSIGNED_INT_SAMPLER_3D
  656. # define GL_UNSIGNED_INT_SAMPLER_3D 0x8DD3
  657. #endif // GL_UNSIGNED_INT_SAMPLER_3D
  658. #ifndef GL_INT_SAMPLER_CUBE
  659. # define GL_INT_SAMPLER_CUBE 0x8DCC
  660. #endif // GL_INT_SAMPLER_CUBEER_3D
  661. #ifndef GL_UNSIGNED_INT_SAMPLER_CUBE
  662. # define GL_UNSIGNED_INT_SAMPLER_CUBE 0x8DD4
  663. #endif // GL_UNSIGNED_INT_SAMPLER_CUBE
  664. #ifndef GL_SAMPLER_2D_MULTISAMPLE
  665. # define GL_SAMPLER_2D_MULTISAMPLE 0x9108
  666. #endif // GL_SAMPLER_2D_MULTISAMPLE
  667. #ifndef GL_INT_SAMPLER_2D_MULTISAMPLE
  668. # define GL_INT_SAMPLER_2D_MULTISAMPLE 0x9109
  669. #endif // GL_INT_SAMPLER_2D_MULTISAMPLE
  670. #ifndef GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE
  671. # define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE 0x910A
  672. #endif // GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE
  673. #ifndef GL_SAMPLER_2D_SHADOW
  674. # define GL_SAMPLER_2D_SHADOW 0x8B62
  675. #endif // GL_SAMPLER_2D_SHADOW
  676. #ifndef GL_SAMPLER_2D_ARRAY
  677. # define GL_SAMPLER_2D_ARRAY 0x8DC1
  678. #endif // GL_SAMPLER_2D_ARRAY
  679. #ifndef GL_SAMPLER_2D_ARRAY_SHADOW
  680. # define GL_SAMPLER_2D_ARRAY_SHADOW 0x8DC4
  681. #endif // GL_SAMPLER_2D_ARRAY_SHADOW
  682. #ifndef GL_TEXTURE_MAX_LEVEL
  683. # define GL_TEXTURE_MAX_LEVEL 0x813D
  684. #endif // GL_TEXTURE_MAX_LEVEL
  685. #ifndef GL_COMPUTE_SHADER
  686. # define GL_COMPUTE_SHADER 0x91B9
  687. #endif // GL_COMPUTE_SHADER
  688. #ifndef GL_READ_ONLY
  689. # define GL_READ_ONLY 0x88B8
  690. #endif // GL_READ_ONLY
  691. #ifndef GL_WRITE_ONLY
  692. # define GL_WRITE_ONLY 0x88B9
  693. #endif // GL_WRITE_ONLY
  694. #ifndef GL_READ_WRITE
  695. # define GL_READ_WRITE 0x88BA
  696. #endif // GL_READ_WRITE
  697. #ifndef GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT
  698. # define GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT 0x00000001
  699. #endif // GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT
  700. #ifndef GL_ELEMENT_ARRAY_BARRIER_BIT
  701. # define GL_ELEMENT_ARRAY_BARRIER_BIT 0x00000002
  702. #endif // GL_ELEMENT_ARRAY_BARRIER_BIT
  703. #ifndef GL_SHADER_IMAGE_ACCESS_BARRIER_BIT
  704. # define GL_SHADER_IMAGE_ACCESS_BARRIER_BIT 0x00000020
  705. #endif // GL_SHADER_IMAGE_ACCESS_BARRIER_BIT
  706. #ifndef GL_SHADER_STORAGE_BARRIER_BIT
  707. # define GL_SHADER_STORAGE_BARRIER_BIT 0x00002000
  708. #endif // GL_SHADER_STORAGE_BARRIER_BIT
  709. #ifndef GL_SHADER_STORAGE_BUFFER
  710. # define GL_SHADER_STORAGE_BUFFER 0x90D2
  711. #endif // GL_SHADER_STORAGE_BUFFER
  712. #ifndef GL_IMAGE_1D
  713. # define GL_IMAGE_1D 0x904C
  714. #endif // GL_IMAGE_1D
  715. #ifndef GL_IMAGE_2D
  716. # define GL_IMAGE_2D 0x904D
  717. #endif // GL_IMAGE_2D
  718. #ifndef GL_IMAGE_2D_ARRAY
  719. # define GL_IMAGE_2D_ARRAY 0x9053
  720. #endif // GL_IMAGE_2D_ARRAY
  721. #ifndef GL_IMAGE_3D
  722. # define GL_IMAGE_3D 0x904E
  723. #endif // GL_IMAGE_3D
  724. #ifndef GL_IMAGE_CUBE
  725. # define GL_IMAGE_CUBE 0x9050
  726. #endif // GL_IMAGE_CUBE
  727. #ifndef GL_INT_IMAGE_1D
  728. # define GL_INT_IMAGE_1D 0x9057
  729. #endif // GL_INT_IMAGE_1D
  730. #ifndef GL_INT_IMAGE_2D
  731. # define GL_INT_IMAGE_2D 0x9058
  732. #endif // GL_INT_IMAGE_2D
  733. #ifndef GL_INT_IMAGE_3D
  734. # define GL_INT_IMAGE_3D 0x9059
  735. #endif // GL_INT_IMAGE_3D
  736. #ifndef GL_INT_IMAGE_CUBE
  737. # define GL_INT_IMAGE_CUBE 0x905B
  738. #endif // GL_INT_IMAGE_CUBE
  739. #ifndef GL_UNSIGNED_INT_IMAGE_1D
  740. # define GL_UNSIGNED_INT_IMAGE_1D 0x9062
  741. #endif // GL_UNSIGNED_INT_IMAGE_1D
  742. #ifndef GL_UNSIGNED_INT_IMAGE_2D
  743. # define GL_UNSIGNED_INT_IMAGE_2D 0x9063
  744. #endif // GL_UNSIGNED_INT_IMAGE_2D
  745. #ifndef GL_UNSIGNED_INT_IMAGE_3D
  746. # define GL_UNSIGNED_INT_IMAGE_3D 0x9064
  747. #endif // GL_UNSIGNED_INT_IMAGE_3D
  748. #ifndef GL_UNSIGNED_INT_IMAGE_CUBE
  749. # define GL_UNSIGNED_INT_IMAGE_CUBE 0x9066
  750. #endif // GL_UNSIGNED_INT_IMAGE_CUBE
  751. #ifndef GL_PROGRAM_INPUT
  752. # define GL_PROGRAM_INPUT 0x92E3
  753. #endif // GL_PROGRAM_INPUT
  754. #ifndef GL_ACTIVE_RESOURCES
  755. # define GL_ACTIVE_RESOURCES 0x92F5
  756. #endif // GL_ACTIVE_RESOURCES
  757. #ifndef GL_UNIFORM
  758. # define GL_UNIFORM 0x92E1
  759. #endif // GL_UNIFORM
  760. #ifndef GL_BUFFER_VARIABLE
  761. # define GL_BUFFER_VARIABLE 0x92E5
  762. #endif // GL_BUFFER_VARIABLE
  763. #ifndef GL_UNSIGNED_INT_VEC2
  764. # define GL_UNSIGNED_INT_VEC2 0x8DC6
  765. #endif // GL_UNSIGNED_INT_VEC2
  766. #ifndef GL_UNSIGNED_INT_VEC3
  767. # define GL_UNSIGNED_INT_VEC3 0x8DC7
  768. #endif // GL_UNSIGNED_INT_VEC3
  769. #ifndef GL_UNSIGNED_INT_VEC4
  770. # define GL_UNSIGNED_INT_VEC4 0x8DC8
  771. #endif // GL_UNSIGNED_INT_VEC4
  772. #ifndef GL_TYPE
  773. # define GL_TYPE 0x92FA
  774. #endif // GL_TYPE
  775. #ifndef GL_ARRAY_SIZE
  776. # define GL_ARRAY_SIZE 0x92FB
  777. #endif // GL_ARRAY_SIZE
  778. #ifndef GL_LOCATION
  779. # define GL_LOCATION 0x930E
  780. #endif // GL_LOCATION
  781. #ifndef GL_UNSIGNED_INT_10_10_10_2
  782. # define GL_UNSIGNED_INT_10_10_10_2 0x8DF6
  783. #endif // GL_UNSIGNED_INT_10_10_10_2
  784. #ifndef GL_FRAMEBUFFER_SRGB
  785. # define GL_FRAMEBUFFER_SRGB 0x8DB9
  786. #endif // GL_FRAMEBUFFER_SRGB
  787. #ifndef GL_NUM_EXTENSIONS
  788. # define GL_NUM_EXTENSIONS 0x821D
  789. #endif // GL_NUM_EXTENSIONS
  790. #ifndef GL_SAMPLE_ALPHA_TO_COVERAGE
  791. # define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E
  792. #endif // GL_SAMPLE_ALPHA_TO_COVERAGE
  793. #ifndef GL_CONSERVATIVE_RASTERIZATION_NV
  794. # define GL_CONSERVATIVE_RASTERIZATION_NV 0x9346
  795. #endif // GL_CONSERVATIVE_RASTERIZATION_NV
  796. #ifndef GL_NEGATIVE_ONE_TO_ONE
  797. # define GL_NEGATIVE_ONE_TO_ONE 0x935E
  798. #endif // GL_NEGATIVE_ONE_TO_ONE
  799. #ifndef GL_ZERO_TO_ONE
  800. # define GL_ZERO_TO_ONE 0x935F
  801. #endif // GL_ZERO_TO_ONE
  802. #ifndef GL_LOWER_LEFT
  803. # define GL_LOWER_LEFT 0x8CA1
  804. #endif // GL_LOWER_LEFT
  805. #ifndef GL_UPPER_LEFT
  806. # define GL_UPPER_LEFT 0x8CA2
  807. #endif // GL_UPPER_LEFT
  808. #ifndef GL_SHADER
  809. # define GL_SHADER 0x82E1
  810. #endif // GL_SHADER
  811. #ifndef GL_TEXTURE
  812. # define GL_TEXTURE 0x1702
  813. #endif // GL_TEXTURE
  814. #ifndef GL_BUFFER
  815. # define GL_BUFFER 0x82E0
  816. #endif // GL_BUFFER
  817. #ifndef GL_COMMAND_BARRIER_BIT
  818. # define GL_COMMAND_BARRIER_BIT 0x00000040
  819. #endif // GL_COMMAND_BARRIER_BIT
  820. #ifndef GL_FIRST_VERTEX_CONVENTION
  821. # define GL_FIRST_VERTEX_CONVENTION 0x8E4D
  822. #endif // GL_FIRST_VERTEX_CONVENTION
  823. #ifndef GL_PARAMETER_BUFFER_ARB
  824. # define GL_PARAMETER_BUFFER_ARB 0x80EE
  825. #endif // GL_PARAMETER_BUFFER_ARB
  826. // _KHR or _ARB...
  827. #define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242
  828. #define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH 0x8243
  829. #define GL_DEBUG_CALLBACK_FUNCTION 0x8244
  830. #define GL_DEBUG_CALLBACK_USER_PARAM 0x8245
  831. #define GL_DEBUG_SOURCE_API 0x8246
  832. #define GL_DEBUG_SOURCE_WINDOW_SYSTEM 0x8247
  833. #define GL_DEBUG_SOURCE_SHADER_COMPILER 0x8248
  834. #define GL_DEBUG_SOURCE_THIRD_PARTY 0x8249
  835. #define GL_DEBUG_SOURCE_APPLICATION 0x824A
  836. #define GL_DEBUG_SOURCE_OTHER 0x824B
  837. #define GL_DEBUG_TYPE_ERROR 0x824C
  838. #define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR 0x824D
  839. #define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR 0x824E
  840. #define GL_DEBUG_TYPE_PORTABILITY 0x824F
  841. #define GL_DEBUG_TYPE_PERFORMANCE 0x8250
  842. #define GL_DEBUG_TYPE_OTHER 0x8251
  843. #define GL_DEBUG_TYPE_MARKER 0x8268
  844. #define GL_DEBUG_TYPE_PUSH_GROUP 0x8269
  845. #define GL_DEBUG_TYPE_POP_GROUP 0x826A
  846. #define GL_DEBUG_SEVERITY_NOTIFICATION 0x826B
  847. #define GL_MAX_DEBUG_GROUP_STACK_DEPTH 0x826C
  848. #define GL_DEBUG_GROUP_STACK_DEPTH 0x826D
  849. #define GL_MAX_LABEL_LENGTH 0x82E8
  850. #define GL_MAX_DEBUG_MESSAGE_LENGTH 0x9143
  851. #define GL_MAX_DEBUG_LOGGED_MESSAGES 0x9144
  852. #define GL_DEBUG_LOGGED_MESSAGES 0x9145
  853. #define GL_DEBUG_SEVERITY_HIGH 0x9146
  854. #define GL_DEBUG_SEVERITY_MEDIUM 0x9147
  855. #define GL_DEBUG_SEVERITY_LOW 0x9148
  856. #ifndef GL_DEPTH_CLAMP
  857. # define GL_DEPTH_CLAMP 0x864F
  858. #endif // GL_DEPTH_CLAMP
  859. #ifndef GL_TEXTURE_BORDER_COLOR
  860. # define GL_TEXTURE_BORDER_COLOR 0x1004
  861. #endif // GL_TEXTURE_BORDER_COLOR
  862. #ifndef GL_CLAMP_TO_BORDER
  863. # define GL_CLAMP_TO_BORDER 0x812D
  864. #endif // GL_CLAMP_TO_BORDER
  865. #ifndef GL_TEXTURE_2D_ARRAY
  866. # define GL_TEXTURE_2D_ARRAY 0x8C1A
  867. #endif // GL_TEXTURE_2D_ARRAY
  868. #ifndef GL_TEXTURE_2D_MULTISAMPLE_ARRAY
  869. # define GL_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9102
  870. #endif // GL_TEXTURE_2D_MULTISAMPLE_ARRAY
  871. #ifndef GL_TEXTURE_CUBE_MAP_ARRAY
  872. # define GL_TEXTURE_CUBE_MAP_ARRAY 0x9009
  873. #endif // GL_TEXTURE_CUBE_MAP_ARRAY
  874. #ifndef GL_TEXTURE_CUBE_MAP_SEAMLESS
  875. # define GL_TEXTURE_CUBE_MAP_SEAMLESS 0x884F
  876. #endif // GL_TEXTURE_CUBE_MAP_SEAMLESS
  877. #ifndef GL_TEXTURE_2D_MULTISAMPLE
  878. # define GL_TEXTURE_2D_MULTISAMPLE 0x9100
  879. #endif // GL_TEXTURE_2D_MULTISAMPLE
  880. #ifndef GL_DRAW_INDIRECT_BUFFER
  881. # define GL_DRAW_INDIRECT_BUFFER 0x8F3F
  882. #endif // GL_DRAW_INDIRECT_BUFFER
  883. #ifndef GL_DISPATCH_INDIRECT_BUFFER
  884. # define GL_DISPATCH_INDIRECT_BUFFER 0x90EE
  885. #endif // GL_DISPATCH_INDIRECT_BUFFER
  886. #ifndef GL_MAX_NAME_LENGTH
  887. # define GL_MAX_NAME_LENGTH 0x92F6
  888. #endif // GL_MAX_NAME_LENGTH
  889. #ifndef GL_DEBUG_SEVERITY_NOTIFICATION
  890. # define GL_DEBUG_SEVERITY_NOTIFICATION 0x826b
  891. #endif // GL_DEBUG_SEVERITY_NOTIFICATION
  892. #ifndef GL_LINE
  893. # define GL_LINE 0x1B01
  894. #endif // GL_LINE
  895. #ifndef GL_FILL
  896. # define GL_FILL 0x1B02
  897. #endif // GL_FILL
  898. #ifndef GL_MULTISAMPLE
  899. # define GL_MULTISAMPLE 0x809D
  900. #endif // GL_MULTISAMPLE
  901. #ifndef GL_LINE_SMOOTH
  902. # define GL_LINE_SMOOTH 0x0B20
  903. #endif // GL_LINE_SMOOTH
  904. #ifndef GL_TEXTURE_LOD_BIAS
  905. # define GL_TEXTURE_LOD_BIAS 0x8501
  906. #endif // GL_TEXTURE_LOD_BIAS
  907. #if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
  908. # include "glcontext_glx.h"
  909. #elif BX_PLATFORM_OSX
  910. # include "glcontext_nsgl.h"
  911. #elif BX_PLATFORM_IOS
  912. # include "glcontext_eagl.h"
  913. #endif // BX_PLATFORM_
  914. #if BGFX_USE_WGL
  915. # include "glcontext_wgl.h"
  916. #endif // BGFX_USE_WGL
  917. #ifndef GL_APIENTRY
  918. # define GL_APIENTRY APIENTRY
  919. #endif // GL_APIENTRY
  920. #ifndef GL_APIENTRYP
  921. # define GL_APIENTRYP GL_APIENTRY*
  922. #endif // GL_APIENTRYP
  923. #if !BGFX_CONFIG_RENDERER_OPENGL
  924. # define glClearDepth glClearDepthf
  925. #endif // !BGFX_CONFIG_RENDERER_OPENGL
  926. namespace bgfx
  927. {
  928. class UniformBuffer;
  929. } // namespace bgfx
  930. namespace bgfx { namespace gl
  931. {
  932. void dumpExtensions(const char* _extensions);
  933. void lazyEnableVertexAttribArray(GLuint index);
  934. void lazyDisableVertexAttribArray(GLuint index);
  935. const char* glEnumName(GLenum _enum);
  936. #define _GL_CHECK(_check, _call) \
  937. BX_MACRO_BLOCK_BEGIN \
  938. /*BX_TRACE(#_call);*/ \
  939. _call; \
  940. GLenum gl_err = glGetError(); \
  941. _check(0 == gl_err, #_call "; GL error 0x%x: %s", gl_err, glEnumName(gl_err) ); \
  942. BX_UNUSED(gl_err); \
  943. BX_MACRO_BLOCK_END
  944. #define IGNORE_GL_ERROR_CHECK(...) BX_NOOP()
  945. #if BGFX_CONFIG_DEBUG
  946. # define GL_CHECK(_call) _GL_CHECK(BX_ASSERT, _call)
  947. # define GL_CHECK_I(_call) _GL_CHECK(IGNORE_GL_ERROR_CHECK, _call)
  948. #else
  949. # define GL_CHECK(_call) _call
  950. # define GL_CHECK_I(_call) _call
  951. #endif // BGFX_CONFIG_DEBUG
  952. #define GL_IMPORT_TYPEDEFS 1
  953. #define GL_IMPORT(_optional, _proto, _func, _import) extern _proto _func
  954. #include "glimports.h"
  955. class UniformStateCache
  956. {
  957. public:
  958. struct f4 { float val[ 4]; bool operator ==(const f4 &rhs) { const uint64_t *a = (const uint64_t *)this; const uint64_t *b = (const uint64_t *)&rhs; return a[0] == b[0] && a[1] == b[1]; }};
  959. struct f3x3 { float val[ 9]; bool operator ==(const f3x3 &rhs) { const uint64_t *a = (const uint64_t *)this; const uint64_t *b = (const uint64_t *)&rhs; return a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3] && ((const uint32_t*)a)[8] == ((const uint32_t*)b)[8]; }};
  960. struct f4x4 { float val[16]; bool operator ==(const f4x4 &rhs) { const uint64_t *a = (const uint64_t *)this; const uint64_t *b = (const uint64_t *)&rhs; return a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3] && a[4] == b[4] && a[5] == b[5] && a[6] == b[6] && a[7] == b[7]; }};
  961. typedef stl::unordered_map<uint64_t, int> IMap;
  962. typedef stl::unordered_map<uint64_t, f4> F4Map;
  963. typedef stl::unordered_map<uint64_t, f3x3> F3x3Map;
  964. typedef stl::unordered_map<uint64_t, f4x4> F4x4Map;
  965. UniformStateCache()
  966. : m_currentProgram(0)
  967. {
  968. }
  969. // Inserts the new value into the uniform cache, and returns true
  970. // if the old value was different than the new one.
  971. template<typename T>
  972. bool updateUniformCache(uint32_t loc, const T &value)
  973. {
  974. if (BX_ENABLED(BGFX_GL_CONFIG_UNIFORM_CACHE) )
  975. {
  976. // Uniform state cache for various types.
  977. stl::unordered_map<uint64_t, T>& uniformCacheMap = getUniformCache<T>();
  978. uint64_t key = (uint64_t(m_currentProgram) << 32) | loc;
  979. auto iter = uniformCacheMap.find(key);
  980. // Not found in the cache? Add it.
  981. if (iter == uniformCacheMap.end())
  982. {
  983. uniformCacheMap[key] = value;
  984. return true;
  985. }
  986. // Value in the cache was the same as new state? Skip reuploading this state.
  987. if (iter->second == value)
  988. {
  989. return false;
  990. }
  991. iter->second = value;
  992. }
  993. return true;
  994. }
  995. void saveCurrentProgram(GLuint program)
  996. {
  997. if (BX_ENABLED(BGFX_GL_CONFIG_UNIFORM_CACHE) )
  998. {
  999. m_currentProgram = program;
  1000. }
  1001. }
  1002. private:
  1003. GLuint m_currentProgram;
  1004. IMap m_uniformiCacheMap;
  1005. F4Map m_uniformf4CacheMap;
  1006. F3x3Map m_uniformf3x3CacheMap;
  1007. F4x4Map m_uniformf4x4CacheMap;
  1008. template<typename T>
  1009. stl::unordered_map<uint64_t, T>& getUniformCache();
  1010. };
  1011. template<>
  1012. inline UniformStateCache::IMap& UniformStateCache::getUniformCache() { return m_uniformiCacheMap; }
  1013. template<>
  1014. inline UniformStateCache::F4Map& UniformStateCache::getUniformCache() { return m_uniformf4CacheMap; }
  1015. template<>
  1016. inline UniformStateCache::F3x3Map& UniformStateCache::getUniformCache() { return m_uniformf3x3CacheMap; }
  1017. template<>
  1018. inline UniformStateCache::F4x4Map& UniformStateCache::getUniformCache() { return m_uniformf4x4CacheMap; }
  1019. class SamplerStateCache
  1020. {
  1021. public:
  1022. GLuint add(uint32_t _hash)
  1023. {
  1024. invalidate(_hash);
  1025. GLuint samplerId;
  1026. GL_CHECK(glGenSamplers(1, &samplerId) );
  1027. m_hashMap.insert(stl::make_pair(_hash, samplerId) );
  1028. return samplerId;
  1029. }
  1030. GLuint find(uint32_t _hash)
  1031. {
  1032. HashMap::iterator it = m_hashMap.find(_hash);
  1033. if (it != m_hashMap.end() )
  1034. {
  1035. return it->second;
  1036. }
  1037. return UINT32_MAX;
  1038. }
  1039. void invalidate(uint32_t _hash)
  1040. {
  1041. HashMap::iterator it = m_hashMap.find(_hash);
  1042. if (it != m_hashMap.end() )
  1043. {
  1044. GL_CHECK(glDeleteSamplers(1, &it->second) );
  1045. m_hashMap.erase(it);
  1046. }
  1047. }
  1048. void invalidate()
  1049. {
  1050. for (HashMap::iterator it = m_hashMap.begin(), itEnd = m_hashMap.end(); it != itEnd; ++it)
  1051. {
  1052. GL_CHECK(glDeleteSamplers(1, &it->second) );
  1053. }
  1054. m_hashMap.clear();
  1055. }
  1056. uint32_t getCount() const
  1057. {
  1058. return uint32_t(m_hashMap.size() );
  1059. }
  1060. private:
  1061. typedef stl::unordered_map<uint32_t, GLuint> HashMap;
  1062. HashMap m_hashMap;
  1063. };
  1064. struct IndexBufferGL
  1065. {
  1066. void create(uint32_t _size, void* _data, uint16_t _flags)
  1067. {
  1068. m_size = _size;
  1069. m_flags = _flags;
  1070. GL_CHECK(glGenBuffers(1, &m_id) );
  1071. BX_ASSERT(0 != m_id, "Failed to generate buffer id.");
  1072. GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_id) );
  1073. GL_CHECK(glBufferData(GL_ELEMENT_ARRAY_BUFFER
  1074. , _size
  1075. , _data
  1076. , (NULL==_data) ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW
  1077. ) );
  1078. GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) );
  1079. }
  1080. void update(uint32_t _offset, uint32_t _size, void* _data, bool _discard = false)
  1081. {
  1082. BX_ASSERT(0 != m_id, "Updating invalid index buffer.");
  1083. if (_discard)
  1084. {
  1085. // orphan buffer...
  1086. destroy();
  1087. create(m_size, NULL, m_flags);
  1088. }
  1089. GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_id) );
  1090. GL_CHECK(glBufferSubData(GL_ELEMENT_ARRAY_BUFFER
  1091. , _offset
  1092. , _size
  1093. , _data
  1094. ) );
  1095. GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) );
  1096. }
  1097. void destroy();
  1098. GLuint m_id;
  1099. uint32_t m_size;
  1100. uint16_t m_flags;
  1101. };
  1102. struct VertexBufferGL
  1103. {
  1104. void create(uint32_t _size, void* _data, VertexLayoutHandle _layoutHandle, uint16_t _flags)
  1105. {
  1106. m_size = _size;
  1107. m_layoutHandle = _layoutHandle;
  1108. const bool drawIndirect = 0 != (_flags & BGFX_BUFFER_DRAW_INDIRECT);
  1109. m_target = drawIndirect ? GL_DRAW_INDIRECT_BUFFER : GL_ARRAY_BUFFER;
  1110. GL_CHECK(glGenBuffers(1, &m_id) );
  1111. BX_ASSERT(0 != m_id, "Failed to generate buffer id.");
  1112. GL_CHECK(glBindBuffer(m_target, m_id) );
  1113. GL_CHECK(glBufferData(m_target
  1114. , _size
  1115. , _data
  1116. , (NULL==_data) ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW
  1117. ) );
  1118. GL_CHECK(glBindBuffer(m_target, 0) );
  1119. }
  1120. void update(uint32_t _offset, uint32_t _size, void* _data, bool _discard = false)
  1121. {
  1122. BX_ASSERT(0 != m_id, "Updating invalid vertex buffer.");
  1123. if (_discard)
  1124. {
  1125. // orphan buffer...
  1126. destroy();
  1127. create(m_size, NULL, m_layoutHandle, 0);
  1128. }
  1129. GL_CHECK(glBindBuffer(m_target, m_id) );
  1130. GL_CHECK(glBufferSubData(m_target
  1131. , _offset
  1132. , _size
  1133. , _data
  1134. ) );
  1135. GL_CHECK(glBindBuffer(m_target, 0) );
  1136. }
  1137. void destroy();
  1138. GLuint m_id;
  1139. GLenum m_target;
  1140. uint32_t m_size;
  1141. VertexLayoutHandle m_layoutHandle;
  1142. };
  1143. struct TextureGL
  1144. {
  1145. TextureGL()
  1146. : m_id(0)
  1147. , m_rbo(0)
  1148. , m_target(GL_TEXTURE_2D)
  1149. , m_fmt(GL_ZERO)
  1150. , m_type(GL_ZERO)
  1151. , m_flags(0)
  1152. , m_currentSamplerHash(UINT32_MAX)
  1153. , m_numMips(0)
  1154. {
  1155. }
  1156. bool init(GLenum _target, uint32_t _width, uint32_t _height, uint32_t _depth, uint8_t _numMips, uint64_t _flags);
  1157. void create(const Memory* _mem, uint64_t _flags, uint8_t _skip);
  1158. void destroy();
  1159. void overrideInternal(uintptr_t _ptr);
  1160. void update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem);
  1161. void setSamplerState(uint32_t _flags, const float _rgba[4]);
  1162. void commit(uint32_t _stage, uint32_t _flags, const float _palette[][4]);
  1163. void resolve(uint8_t _resolve) const;
  1164. bool isCubeMap() const
  1165. {
  1166. return 0
  1167. || GL_TEXTURE_CUBE_MAP == m_target
  1168. || GL_TEXTURE_CUBE_MAP_ARRAY == m_target
  1169. ;
  1170. }
  1171. GLuint m_id;
  1172. GLuint m_rbo;
  1173. GLenum m_target;
  1174. GLenum m_fmt;
  1175. GLenum m_type;
  1176. uint64_t m_flags;
  1177. uint32_t m_currentSamplerHash;
  1178. uint32_t m_width;
  1179. uint32_t m_height;
  1180. uint32_t m_depth;
  1181. uint32_t m_numLayers;
  1182. uint8_t m_numMips;
  1183. uint8_t m_requestedFormat;
  1184. uint8_t m_textureFormat;
  1185. };
  1186. struct ShaderGL
  1187. {
  1188. ShaderGL()
  1189. : m_id(0)
  1190. , m_type(0)
  1191. , m_hash(0)
  1192. {
  1193. }
  1194. void create(const Memory* _mem);
  1195. void destroy();
  1196. GLuint m_id;
  1197. GLenum m_type;
  1198. uint32_t m_hash;
  1199. };
  1200. struct FrameBufferGL
  1201. {
  1202. FrameBufferGL()
  1203. : m_swapChain(NULL)
  1204. , m_denseIdx(UINT16_MAX)
  1205. , m_num(0)
  1206. , m_needPresent(false)
  1207. {
  1208. bx::memSet(m_fbo, 0, sizeof(m_fbo) );
  1209. }
  1210. void create(uint8_t _num, const Attachment* _attachment);
  1211. void create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat);
  1212. void postReset();
  1213. uint16_t destroy();
  1214. void resolve();
  1215. void discard(uint16_t _flags);
  1216. SwapChainGL* m_swapChain;
  1217. GLuint m_fbo[2];
  1218. uint32_t m_width;
  1219. uint32_t m_height;
  1220. uint16_t m_denseIdx;
  1221. uint8_t m_num;
  1222. uint8_t m_numTh;
  1223. bool m_needPresent;
  1224. Attachment m_attachment[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS];
  1225. };
  1226. struct ProgramGL
  1227. {
  1228. ProgramGL()
  1229. : m_id(0)
  1230. , m_constantBuffer(NULL)
  1231. , m_numPredefined(0)
  1232. {
  1233. m_instanceData[0] = -1;
  1234. }
  1235. void create(const ShaderGL& _vsh, const ShaderGL& _fsh);
  1236. void destroy();
  1237. void init();
  1238. void bindAttributesBegin();
  1239. void bindAttributes(const VertexLayout& _layout, uint32_t _baseVertex = 0);
  1240. void bindInstanceData(uint32_t _stride, uint32_t _baseVertex = 0) const;
  1241. void bindAttributesEnd();
  1242. void unbindInstanceData() const;
  1243. void unbindAttributes();
  1244. GLuint m_id;
  1245. uint8_t m_unboundUsedAttrib[Attrib::Count]; // For tracking unbound used attributes between begin()/end().
  1246. uint8_t m_usedCount;
  1247. uint8_t m_used[Attrib::Count]; // Dense.
  1248. GLint m_attributes[Attrib::Count]; // Sparse.
  1249. GLint m_instanceData[BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT+1];
  1250. uint16_t m_instanceOffset[BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT];
  1251. GLint m_sampler[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
  1252. uint8_t m_numSamplers;
  1253. UniformBuffer* m_constantBuffer;
  1254. PredefinedUniform m_predefined[PredefinedUniform::Count];
  1255. uint8_t m_numPredefined;
  1256. };
  1257. struct TimerQueryGL
  1258. {
  1259. TimerQueryGL()
  1260. : m_control(BX_COUNTOF(m_query) )
  1261. {
  1262. }
  1263. void create()
  1264. {
  1265. for (uint32_t ii = 0; ii < BX_COUNTOF(m_query); ++ii)
  1266. {
  1267. Query& query = m_query[ii];
  1268. query.m_ready = false;
  1269. query.m_frameNum = 0;
  1270. GL_CHECK(glGenQueries(1, &query.m_begin) );
  1271. GL_CHECK(glGenQueries(1, &query.m_end) );
  1272. }
  1273. for (uint32_t ii = 0; ii < BX_COUNTOF(m_result); ++ii)
  1274. {
  1275. Result& result = m_result[ii];
  1276. result.reset();
  1277. }
  1278. }
  1279. void destroy()
  1280. {
  1281. for (uint32_t ii = 0; ii < BX_COUNTOF(m_query); ++ii)
  1282. {
  1283. Query& query = m_query[ii];
  1284. GL_CHECK(glDeleteQueries(1, &query.m_begin) );
  1285. GL_CHECK(glDeleteQueries(1, &query.m_end) );
  1286. }
  1287. }
  1288. uint32_t begin(uint32_t _resultIdx, uint32_t _frameNum)
  1289. {
  1290. while (0 == m_control.reserve(1) )
  1291. {
  1292. update();
  1293. }
  1294. Result& result = m_result[_resultIdx];
  1295. ++result.m_pending;
  1296. const uint32_t idx = m_control.m_current;
  1297. Query& query = m_query[idx];
  1298. query.m_resultIdx = _resultIdx;
  1299. query.m_frameNum = _frameNum;
  1300. query.m_ready = false;
  1301. GL_CHECK(glQueryCounter(query.m_begin
  1302. , GL_TIMESTAMP
  1303. ) );
  1304. m_control.commit(1);
  1305. return idx;
  1306. }
  1307. void end(uint32_t _idx)
  1308. {
  1309. Query& query = m_query[_idx];
  1310. query.m_ready = true;
  1311. GL_CHECK(glQueryCounter(query.m_end
  1312. , GL_TIMESTAMP
  1313. ) );
  1314. while (update() )
  1315. {
  1316. }
  1317. }
  1318. bool update()
  1319. {
  1320. if (0 != m_control.available() )
  1321. {
  1322. Query& query = m_query[m_control.m_read];
  1323. if (!query.m_ready)
  1324. {
  1325. return false;
  1326. }
  1327. GLint available;
  1328. GL_CHECK(glGetQueryObjectiv(query.m_end
  1329. , GL_QUERY_RESULT_AVAILABLE
  1330. , &available
  1331. ) );
  1332. if (available)
  1333. {
  1334. m_control.consume(1);
  1335. Result& result = m_result[query.m_resultIdx];
  1336. --result.m_pending;
  1337. result.m_frameNum = query.m_frameNum;
  1338. GL_CHECK(glGetQueryObjectui64v(query.m_begin
  1339. , GL_QUERY_RESULT
  1340. , &result.m_begin
  1341. ) );
  1342. GL_CHECK(glGetQueryObjectui64v(query.m_end
  1343. , GL_QUERY_RESULT
  1344. , &result.m_end
  1345. ) );
  1346. return true;
  1347. }
  1348. }
  1349. return false;
  1350. }
  1351. struct Result
  1352. {
  1353. void reset()
  1354. {
  1355. m_begin = 0;
  1356. m_end = 0;
  1357. m_pending = 0;
  1358. m_frameNum = 0;
  1359. }
  1360. uint64_t m_begin;
  1361. uint64_t m_end;
  1362. uint32_t m_pending;
  1363. uint32_t m_frameNum;
  1364. };
  1365. struct Query
  1366. {
  1367. GLuint m_begin;
  1368. GLuint m_end;
  1369. uint32_t m_resultIdx;
  1370. uint32_t m_frameNum;
  1371. bool m_ready;
  1372. };
  1373. Result m_result[BGFX_CONFIG_MAX_VIEWS+1];
  1374. Query m_query[BGFX_CONFIG_MAX_VIEWS*4];
  1375. bx::RingBufferControl m_control;
  1376. };
  1377. struct OcclusionQueryGL
  1378. {
  1379. OcclusionQueryGL()
  1380. : m_control(BX_COUNTOF(m_query) )
  1381. {
  1382. }
  1383. void create();
  1384. void destroy();
  1385. void begin(Frame* _render, OcclusionQueryHandle _handle);
  1386. void end();
  1387. void resolve(Frame* _render, bool _wait = false);
  1388. void invalidate(OcclusionQueryHandle _handle);
  1389. struct Query
  1390. {
  1391. GLuint m_id;
  1392. OcclusionQueryHandle m_handle;
  1393. };
  1394. Query m_query[BGFX_CONFIG_MAX_OCCLUSION_QUERIES];
  1395. bx::RingBufferControl m_control;
  1396. };
  1397. } /* namespace gl */ } // namespace bgfx
  1398. #endif // BGFX_RENDERER_GL_H_HEADER_GUARD