1 2 // Copyright 2018 - 2021 Michael D. Parker 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 7 module bindbc.opengl.bind.arb.core_30; 8 9 import bindbc.loader; 10 import bindbc.opengl.config, 11 bindbc.opengl.context; 12 import bindbc.opengl.bind.types; 13 14 static if(glSupport >= GLSupport.gl30) { 15 enum has30 = true; 16 } 17 else enum has30 = false; 18 19 // ARB_depth_buffer_float 20 version(GL_ARB) enum useARBDepthBufferFloat = true; 21 else version(GL_ARB_depth_buffer_float) enum useARBDepthBufferFloat = true; 22 else enum useARBDepthBufferFloat = has30; 23 24 static if(useARBDepthBufferFloat) { 25 private bool _hasARBDepthBufferFloat; 26 @nogc nothrow bool hasARBDepthBufferFloat() { return _hasARBDepthBufferFloat; } 27 28 enum : uint { 29 GL_DEPTH_COMPONENT32F = 0x8CAC, 30 GL_DEPTH32F_STENCIL8 = 0x8CAD, 31 GL_FLOAT_32_UNSIGNED_INT_24_8_REV = 0x8DAD, 32 } 33 } 34 else enum hasARBDepthBufferFloat = false; 35 36 // ARB_half_float_vertex 37 version(GL_ARB) enum useARBHalfFloatVertex = true; 38 else version(GL_ARB_half_float_vertex) enum useARBHalfFloatVertex = true; 39 else enum useARBHalfFloatVertex = has30; 40 static if(useARBHalfFloatVertex) { 41 private bool _hasARBHalfFloatVertex; 42 @nogc nothrow bool hasARBHalfFloatVertex() { return _hasARBHalfFloatVertex; } 43 44 enum uint GL_HALF_FLOAT = 0x140B; 45 } 46 else enum hasARBHalfFloatVertex = false; 47 48 // ARB_texture_compression_rgtc 49 version(GL_ARB) enum useARBTextureCompressionRGTC = true; 50 else version(GL_ARB_texture_compression_rgtc) enum useARBTextureCompressionRGTC = true; 51 else enum useARBTextureCompressionRGTC = has30; 52 53 static if(useARBTextureCompressionRGTC) { 54 private bool _hasARBTextureCompressionRGTC; 55 @nogc nothrow bool hasARBTextureCompressionRGTC() { return _hasARBTextureCompressionRGTC; } 56 57 enum : uint { 58 GL_COMPRESSED_RED_RGTC1 = 0x8DBB, 59 GL_COMPRESSED_SIGNED_RED_RGTC1 = 0x8DBC, 60 GL_COMPRESSED_RG_RGTC2 = 0x8DBD, 61 GL_COMPRESSED_SIGNED_RG_RGTC2 = 0x8DBE, 62 } 63 } 64 else enum hasARBTextureCompressionRGTC = false; 65 66 // ARB_texture_rg 67 version(GL_ARB) enum useARBTextureRG = true; 68 else version(GL_ARB_texture_rg) enum useARBTextureRG = true; 69 else enum useARBTextureRG = has30; 70 71 static if(useARBTextureRG) { 72 private bool _hasARBTextureRG; 73 @nogc nothrow bool hasARBTextureRG() { return _hasARBTextureRG; } 74 75 enum : uint { 76 GL_RG = 0x8227, 77 GL_RG_INTEGER = 0x8228, 78 GL_R8 = 0x8229, 79 GL_R16 = 0x822A, 80 GL_RG8 = 0x822B, 81 GL_RG16 = 0x822C, 82 GL_R16F = 0x822D, 83 GL_R32F = 0x822E, 84 GL_RG16F = 0x822F, 85 GL_RG32F = 0x8230, 86 GL_R8I = 0x8231, 87 GL_R8UI = 0x8232, 88 GL_R16I = 0x8233, 89 GL_R16UI = 0x8234, 90 GL_R32I = 0x8235, 91 GL_R32UI = 0x8236, 92 GL_RG8I = 0x8237, 93 GL_RG8UI = 0x8238, 94 GL_RG16I = 0x8239, 95 GL_RG16UI = 0x823A, 96 GL_RG32I = 0x823B, 97 GL_RG32UI = 0x823C, 98 } 99 } 100 else enum hasARBTextureRG = false; 101 102 // ARB_framebuffer_object 103 version(GL_ARB) enum useARBFramebufferObject = true; 104 else version(GL_ARB_framebuffer_object) enum useARBFramebufferObject = true; 105 else enum useARBFramebufferObject = has30; 106 107 static if(useARBFramebufferObject) { 108 private bool _hasARBFramebufferObject; 109 @nogc nothrow bool hasARBFramebufferObject() { return _hasARBFramebufferObject; } 110 111 enum : uint { 112 GL_INVALID_FRAMEBUFFER_OPERATION = 0x0506, 113 GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING = 0x8210, 114 GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE = 0x8211, 115 GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE = 0x8212, 116 GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE = 0x8213, 117 GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE = 0x8214, 118 GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE = 0x8215, 119 GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE = 0x8216, 120 GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE = 0x8217, 121 GL_FRAMEBUFFER_DEFAULT = 0x8218, 122 GL_FRAMEBUFFER_UNDEFINED = 0x8219, 123 GL_DEPTH_STENCIL_ATTACHMENT = 0x821A, 124 GL_MAX_RENDERBUFFER_SIZE = 0x84E8, 125 GL_DEPTH_STENCIL = 0x84F9, 126 GL_UNSIGNED_INT_24_8 = 0x84FA, 127 GL_DEPTH24_STENCIL8 = 0x88F0, 128 GL_TEXTURE_STENCIL_SIZE = 0x88F1, 129 GL_TEXTURE_RED_TYPE = 0x8C10, 130 GL_TEXTURE_GREEN_TYPE = 0x8C11, 131 GL_TEXTURE_BLUE_TYPE = 0x8C12, 132 GL_TEXTURE_ALPHA_TYPE = 0x8C13, 133 GL_TEXTURE_DEPTH_TYPE = 0x8C16, 134 GL_UNSIGNED_NORMALIZED = 0x8C17, 135 GL_FRAMEBUFFER_BINDING = 0x8CA6, 136 GL_DRAW_FRAMEBUFFER_BINDING = GL_FRAMEBUFFER_BINDING, 137 GL_RENDERBUFFER_BINDING = 0x8CA7, 138 GL_READ_FRAMEBUFFER = 0x8CA8, 139 GL_DRAW_FRAMEBUFFER = 0x8CA9, 140 GL_READ_FRAMEBUFFER_BINDING = 0x8CAA, 141 GL_RENDERBUFFER_SAMPLES = 0x8CAB, 142 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE = 0x8CD0, 143 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME = 0x8CD1, 144 GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL = 0x8CD2, 145 GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE = 0x8CD3, 146 GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER = 0x8CD4, 147 GL_FRAMEBUFFER_COMPLETE = 0x8CD5, 148 GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT = 0x8CD6, 149 GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = 0x8CD7, 150 GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER = 0x8CDB, 151 GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER = 0x8CDC, 152 GL_FRAMEBUFFER_UNSUPPORTED = 0x8CDD, 153 GL_MAX_COLOR_ATTACHMENTS = 0x8CDF, 154 GL_COLOR_ATTACHMENT0 = 0x8CE0, 155 GL_COLOR_ATTACHMENT1 = 0x8CE1, 156 GL_COLOR_ATTACHMENT2 = 0x8CE2, 157 GL_COLOR_ATTACHMENT3 = 0x8CE3, 158 GL_COLOR_ATTACHMENT4 = 0x8CE4, 159 GL_COLOR_ATTACHMENT5 = 0x8CE5, 160 GL_COLOR_ATTACHMENT6 = 0x8CE6, 161 GL_COLOR_ATTACHMENT7 = 0x8CE7, 162 GL_COLOR_ATTACHMENT8 = 0x8CE8, 163 GL_COLOR_ATTACHMENT9 = 0x8CE9, 164 GL_COLOR_ATTACHMENT10 = 0x8CEA, 165 GL_COLOR_ATTACHMENT11 = 0x8CEB, 166 GL_COLOR_ATTACHMENT12 = 0x8CEC, 167 GL_COLOR_ATTACHMENT13 = 0x8CED, 168 GL_COLOR_ATTACHMENT14 = 0x8CEE, 169 GL_COLOR_ATTACHMENT15 = 0x8CEF, 170 GL_DEPTH_ATTACHMENT = 0x8D00, 171 GL_STENCIL_ATTACHMENT = 0x8D20, 172 GL_FRAMEBUFFER = 0x8D40, 173 GL_RENDERBUFFER = 0x8D41, 174 GL_RENDERBUFFER_WIDTH = 0x8D42, 175 GL_RENDERBUFFER_HEIGHT = 0x8D43, 176 GL_RENDERBUFFER_INTERNAL_FORMAT = 0x8D44, 177 GL_STENCIL_INDEX1 = 0x8D46, 178 GL_STENCIL_INDEX4 = 0x8D47, 179 GL_STENCIL_INDEX8 = 0x8D48, 180 GL_STENCIL_INDEX16 = 0x8D49, 181 GL_RENDERBUFFER_RED_SIZE = 0x8D50, 182 GL_RENDERBUFFER_GREEN_SIZE = 0x8D51, 183 GL_RENDERBUFFER_BLUE_SIZE = 0x8D52, 184 GL_RENDERBUFFER_ALPHA_SIZE = 0x8D53, 185 GL_RENDERBUFFER_DEPTH_SIZE = 0x8D54, 186 GL_RENDERBUFFER_STENCIL_SIZE = 0x8D55, 187 GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE = 0x8D56, 188 GL_MAX_SAMPLES = 0x8D57, 189 } 190 191 extern(System) @nogc nothrow { 192 alias pglIsRenderbuffer = GLboolean function(GLuint); 193 alias pglBindRenderbuffer = void function(GLenum, GLuint); 194 alias pglDeleteRenderbuffers = void function(GLsizei, const(GLuint)*); 195 alias pglGenRenderbuffers = void function(GLsizei, GLuint*); 196 alias pglRenderbufferStorage = void function(GLenum, GLenum, GLsizei, GLsizei); 197 alias pglGetRenderbufferParameteriv = void function(GLenum, GLenum, GLint*); 198 alias pglIsFramebuffer = GLboolean function(GLuint); 199 alias pglBindFramebuffer = void function(GLenum, GLuint); 200 alias pglDeleteFramebuffers = void function(GLsizei, const(GLuint)*); 201 alias pglGenFramebuffers = void function(GLsizei, GLuint*); 202 alias pglCheckFramebufferStatus = GLenum function(GLenum); 203 alias pglFramebufferTexture1D = void function(GLenum, GLenum, GLenum, GLuint, GLint); 204 alias pglFramebufferTexture2D = void function(GLenum, GLenum, GLenum, GLuint, GLint); 205 alias pglFramebufferTexture3D = void function(GLenum, GLenum, GLenum, GLuint, GLint, GLint); 206 alias pglFramebufferRenderbuffer = void function(GLenum, GLenum, GLenum, GLuint); 207 alias pglGetFramebufferAttachmentParameteriv = void function(GLenum, GLenum, GLenum, GLint*); 208 alias pglGenerateMipmap = void function(GLenum); 209 alias pglBlitFramebuffer = void function(GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLbitfield, GLenum); 210 alias pglRenderbufferStorageMultisample = void function(GLenum, GLsizei, GLenum, GLsizei, GLsizei); 211 alias pglFramebufferTextureLayer = void function(GLenum, GLenum, GLuint, GLint, GLint); 212 } 213 214 __gshared { 215 pglIsRenderbuffer glIsRenderbuffer; 216 pglBindRenderbuffer glBindRenderbuffer; 217 pglDeleteRenderbuffers glDeleteRenderbuffers; 218 pglGenRenderbuffers glGenRenderbuffers; 219 pglRenderbufferStorage glRenderbufferStorage; 220 pglGetRenderbufferParameteriv glGetRenderbufferParameteriv; 221 pglIsFramebuffer glIsFramebuffer; 222 pglBindFramebuffer glBindFramebuffer; 223 pglDeleteFramebuffers glDeleteFramebuffers; 224 pglGenFramebuffers glGenFramebuffers; 225 pglCheckFramebufferStatus glCheckFramebufferStatus; 226 pglFramebufferTexture1D glFramebufferTexture1D; 227 pglFramebufferTexture2D glFramebufferTexture2D; 228 pglFramebufferTexture3D glFramebufferTexture3D; 229 pglFramebufferRenderbuffer glFramebufferRenderbuffer; 230 pglGetFramebufferAttachmentParameteriv glGetFramebufferAttachmentParameteriv; 231 pglGenerateMipmap glGenerateMipmap; 232 pglBlitFramebuffer glBlitFramebuffer; 233 pglRenderbufferStorageMultisample glRenderbufferStorageMultisample; 234 pglFramebufferTextureLayer glFramebufferTextureLayer; 235 } 236 237 private @nogc nothrow 238 bool loadARBFramebufferObject(SharedLib lib, GLSupport contextVersion) 239 { 240 lib.bindGLSymbol(cast(void**)&glIsRenderbuffer, "glIsRenderbuffer"); 241 lib.bindGLSymbol(cast(void**)&glBindRenderbuffer, "glBindRenderbuffer"); 242 lib.bindGLSymbol(cast(void**)&glDeleteRenderbuffers, "glDeleteRenderbuffers"); 243 lib.bindGLSymbol(cast(void**)&glGenRenderbuffers, "glGenRenderbuffers"); 244 lib.bindGLSymbol(cast(void**)&glRenderbufferStorage, "glRenderbufferStorage"); 245 lib.bindGLSymbol(cast(void**)&glGetRenderbufferParameteriv, "glGetRenderbufferParameteriv"); 246 lib.bindGLSymbol(cast(void**)&glIsFramebuffer, "glIsFramebuffer"); 247 lib.bindGLSymbol(cast(void**)&glBindFramebuffer, "glBindFramebuffer"); 248 lib.bindGLSymbol(cast(void**)&glDeleteFramebuffers, "glDeleteFramebuffers"); 249 lib.bindGLSymbol(cast(void**)&glGenFramebuffers, "glGenFramebuffers"); 250 lib.bindGLSymbol(cast(void**)&glCheckFramebufferStatus, "glCheckFramebufferStatus"); 251 lib.bindGLSymbol(cast(void**)&glFramebufferTexture1D, "glFramebufferTexture1D"); 252 lib.bindGLSymbol(cast(void**)&glFramebufferTexture2D, "glFramebufferTexture2D"); 253 lib.bindGLSymbol(cast(void**)&glFramebufferTexture3D, "glFramebufferTexture3D"); 254 lib.bindGLSymbol(cast(void**)&glFramebufferRenderbuffer, "glFramebufferRenderbuffer"); 255 lib.bindGLSymbol(cast(void**)&glGetFramebufferAttachmentParameteriv, "glGetFramebufferAttachmentParameteriv"); 256 lib.bindGLSymbol(cast(void**)&glGenerateMipmap, "glGenerateMipmap"); 257 lib.bindGLSymbol(cast(void**)&glBlitFramebuffer, "glBlitFramebuffer"); 258 lib.bindGLSymbol(cast(void**)&glRenderbufferStorageMultisample, "glRenderbufferStorageMultisample"); 259 lib.bindGLSymbol(cast(void**)&glFramebufferTextureLayer, "glFramebufferTextureLayer"); 260 return resetErrorCountGL(); 261 } 262 } 263 else enum hasARBFramebufferObject = false; 264 265 // ARB_map_buffer_range 266 version(GL_ARB) enum useARBMapBufferRange = true; 267 else version(GL_ARB_map_buffer_range) enum useARBMapBufferRange = true; 268 else enum useARBMapBufferRange = has30; 269 270 static if(useARBMapBufferRange) { 271 private bool _hasARBMapBufferRange; 272 @nogc nothrow bool hasARBMapBufferRange() { return _hasARBMapBufferRange; } 273 274 enum : uint { 275 GL_MAP_READ_BIT = 0x0001, 276 GL_MAP_WRITE_BIT = 0x0002, 277 GL_MAP_INVALIDATE_RANGE_BIT = 0x0004, 278 GL_MAP_INVALIDATE_BUFFER_BIT = 0x0008, 279 GL_MAP_FLUSH_EXPLICIT_BIT = 0x0010, 280 GL_MAP_UNSYNCHRONIZED_BIT = 0x0020, 281 } 282 283 extern(System) @nogc nothrow { 284 alias pglMapBufferRange = GLvoid* function(GLenum, GLintptr, GLsizeiptr, GLbitfield); 285 alias pglFlushMappedBufferRange = void function(GLenum, GLintptr, GLsizeiptr); 286 } 287 288 __gshared { 289 pglMapBufferRange glMapBufferRange; 290 pglFlushMappedBufferRange glFlushMappedBufferRange; 291 } 292 293 private @nogc nothrow 294 bool loadARBMapBufferRange(SharedLib lib, GLSupport contextVersion) 295 { 296 lib.bindGLSymbol(cast(void**)&glMapBufferRange, "glMapBufferRange"); 297 lib.bindGLSymbol(cast(void**)&glFlushMappedBufferRange, "glFlushMappedBufferRange"); 298 return resetErrorCountGL(); 299 } 300 } 301 else enum hasARBMapBufferRange = false; 302 303 // ARB_vertex_array_object 304 version(GL_ARB) enum useARBVertexArrayObject = true; 305 else version(GL_ARB_vertex_array_object) enum useARBVertexArrayObject = true; 306 else enum useARBVertexArrayObject = has30; 307 308 static if(useARBVertexArrayObject) { 309 private bool _hasARBVertexArrayObject; 310 @nogc nothrow bool hasARBVertexArrayObject() { return _hasARBVertexArrayObject; } 311 312 enum uint GL_VERTEX_ARRAY_BINDING = 0x85B5; 313 314 extern(System) @nogc nothrow { 315 alias pglBindVertexArray = void function(GLuint); 316 alias pglDeleteVertexArrays = void function(GLsizei, const(GLuint)*); 317 alias pglGenVertexArrays = void function(GLsizei, GLuint*); 318 alias pglIsVertexArray = GLboolean function(GLuint); 319 } 320 321 __gshared { 322 pglBindVertexArray glBindVertexArray; 323 pglDeleteVertexArrays glDeleteVertexArrays; 324 pglGenVertexArrays glGenVertexArrays; 325 pglIsVertexArray glIsVertexArray; 326 } 327 328 private @nogc nothrow 329 bool loadARBVertexArrayObject(SharedLib lib, GLSupport contextVersion) 330 { 331 lib.bindGLSymbol(cast(void**)&glBindVertexArray, "glBindVertexArray"); 332 lib.bindGLSymbol(cast(void**)&glDeleteVertexArrays, "glDeleteVertexArrays"); 333 lib.bindGLSymbol(cast(void**)&glGenVertexArrays, "glGenVertexArrays"); 334 lib.bindGLSymbol(cast(void**)&glIsVertexArray, "glIsVertexArray"); 335 return resetErrorCountGL(); 336 } 337 } 338 else enum hasARBVertexArrayObject = false; 339 340 package(bindbc.opengl) @nogc nothrow 341 bool loadARB30(SharedLib lib, GLSupport contextVersion) 342 { 343 static if(has30) { 344 if(contextVersion >= GLSupport.gl30) { 345 _hasARBDepthBufferFloat = true; 346 _hasARBHalfFloatVertex = true; 347 _hasARBTextureCompressionRGTC = true; 348 _hasARBTextureRG = true; 349 350 bool ret = true; 351 ret = _hasARBFramebufferObject = lib.loadARBFramebufferObject(contextVersion); 352 ret = _hasARBMapBufferRange = lib.loadARBMapBufferRange(contextVersion); 353 ret = _hasARBVertexArrayObject = lib.loadARBVertexArrayObject(contextVersion); 354 return ret; 355 } 356 } 357 358 static if(useARBDepthBufferFloat) _hasARBDepthBufferFloat = 359 hasExtension(contextVersion, "GL_ARB_depth_buffer_float"); 360 361 static if(useARBHalfFloatVertex) _hasARBHalfFloatVertex = 362 hasExtension(contextVersion, "GL_ARB_half_float_vertex"); 363 364 static if(useARBTextureCompressionRGTC) _hasARBTextureCompressionRGTC = 365 hasExtension(contextVersion, "GL_ARB_texture_compression_rgtc"); 366 367 static if(useARBTextureRG) _hasARBTextureRG= 368 hasExtension(contextVersion, "GL_ARB_texture_rg"); 369 370 static if(useARBFramebufferObject) _hasARBFramebufferObject = 371 hasExtension(contextVersion, "GL_ARB_framebuffer_object") && 372 lib.loadARBFramebufferObject(contextVersion); 373 374 static if(useARBMapBufferRange) _hasARBMapBufferRange = 375 hasExtension(contextVersion, "GL_ARB_map_buffer_range") && 376 lib.loadARBMapBufferRange(contextVersion); 377 378 static if(useARBVertexArrayObject) _hasARBVertexArrayObject = 379 hasExtension(contextVersion, "GL_ARB_vertex_array_object") && 380 lib.loadARBVertexArrayObject(contextVersion); 381 382 return true; 383 }