renderer_gl.h 42 KB

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