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_31; 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.gl31) { 15 enum has31 = true; 16 } 17 else enum has31 = false; 18 19 // ARB_copy_buffer 20 version(GL_ARB) enum useARBCopyBuffer = true; 21 else version(GL_ARB_copy_buffer) enum useARBCopyBuffer = true; 22 else enum useARBCopyBuffer = has31; 23 24 static if(useARBCopyBuffer) { 25 private bool _hasARBCopyBuffer; 26 @nogc nothrow bool hasARBCopyBuffer() { return _hasARBCopyBuffer; } 27 28 enum : uint { 29 GL_COPY_READ_BUFFER = 0x8F36, 30 GL_COPY_WRITE_BUFFER = 0x8F37, 31 } 32 33 extern(System) @nogc nothrow { 34 alias pglCopyBufferSubData = void function(GLenum, GLenum, GLintptr, GLintptr, GLsizeiptr); 35 } 36 37 __gshared { 38 pglCopyBufferSubData glCopyBufferSubData; 39 } 40 41 private @nogc nothrow 42 bool loadARBCopyBuffer(SharedLib lib, GLSupport contextVersion) 43 { 44 lib.bindGLSymbol(cast(void**)&glCopyBufferSubData, "glCopyBufferSubData"); 45 return resetErrorCountGL(); 46 } 47 } 48 else enum hasARBCopyBuffer = false; 49 50 // ARB_uniform_buffer_object 51 version(GL_ARB) enum useARBUniformBufferObject = true; 52 else version(GL_ARB_uniform_buffer_object) enum useARBUniformBufferObject = true; 53 else enum useARBUniformBufferObject = has31; 54 55 static if(useARBUniformBufferObject) { 56 private bool _hasARBUniformBufferObject; 57 @nogc nothrow bool hasARBUniformBufferObject() { return _hasARBUniformBufferObject; } 58 59 enum : uint { 60 GL_UNIFORM_BUFFER = 0x8A11, 61 GL_UNIFORM_BUFFER_BINDING = 0x8A28, 62 GL_UNIFORM_BUFFER_START = 0x8A29, 63 GL_UNIFORM_BUFFER_SIZE = 0x8A2A, 64 GL_MAX_VERTEX_UNIFORM_BLOCKS = 0x8A2B, 65 GL_MAX_GEOMETRY_UNIFORM_BLOCKS = 0x8A2C, 66 GL_MAX_FRAGMENT_UNIFORM_BLOCKS = 0x8A2D, 67 GL_MAX_COMBINED_UNIFORM_BLOCKS = 0x8A2E, 68 GL_MAX_UNIFORM_BUFFER_BINDINGS = 0x8A2F, 69 GL_MAX_UNIFORM_BLOCK_SIZE = 0x8A30, 70 GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS = 0x8A31, 71 GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS = 0x8A32, 72 GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS = 0x8A33, 73 GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT = 0x8A34, 74 GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH = 0x8A35, 75 GL_ACTIVE_UNIFORM_BLOCKS = 0x8A36, 76 GL_UNIFORM_TYPE = 0x8A37, 77 GL_UNIFORM_SIZE = 0x8A38, 78 GL_UNIFORM_NAME_LENGTH = 0x8A39, 79 GL_UNIFORM_BLOCK_INDEX = 0x8A3A, 80 GL_UNIFORM_OFFSET = 0x8A3B, 81 GL_UNIFORM_ARRAY_STRIDE = 0x8A3C, 82 GL_UNIFORM_MATRIX_STRIDE = 0x8A3D, 83 GL_UNIFORM_IS_ROW_MAJOR = 0x8A3E, 84 GL_UNIFORM_BLOCK_BINDING = 0x8A3F, 85 GL_UNIFORM_BLOCK_DATA_SIZE = 0x8A40, 86 GL_UNIFORM_BLOCK_NAME_LENGTH = 0x8A41, 87 GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS = 0x8A42, 88 GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES = 0x8A43, 89 GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER = 0x8A44, 90 GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER = 0x8A45, 91 GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER = 0x8A46, 92 GL_INVALID_INDEX = 0xFFFFFFFFu, 93 } 94 95 extern(System) @nogc nothrow { 96 alias pglGetUniformIndices = void function(GLuint, GLsizei, const(GLchar*)*, GLuint*); 97 alias pglGetActiveUniformsiv = void function(GLuint, GLsizei, const(GLuint)*, GLenum, GLint*); 98 alias pglGetActiveUniformName = void function(GLuint, GLuint, GLsizei, GLsizei*, GLchar*); 99 alias pglGetUniformBlockIndex = GLuint function(GLuint, const(GLchar)*); 100 alias pglGetActiveUniformBlockiv = void function(GLuint, GLuint, GLenum, GLint*); 101 alias pglGetActiveUniformBlockName = void function(GLuint, GLuint, GLsizei, GLsizei*, GLchar*); 102 alias pglUniformBlockBinding = void function(GLuint, GLuint, GLuint); 103 } 104 105 __gshared { 106 pglGetUniformIndices glGetUniformIndices; 107 pglGetActiveUniformsiv glGetActiveUniformsiv; 108 pglGetActiveUniformName glGetActiveUniformName; 109 pglGetUniformBlockIndex glGetUniformBlockIndex; 110 pglGetActiveUniformBlockiv glGetActiveUniformBlockiv; 111 pglGetActiveUniformBlockName glGetActiveUniformBlockName; 112 pglUniformBlockBinding glUniformBlockBinding; 113 } 114 115 private @nogc nothrow 116 bool loadARBUniformBufferObject(SharedLib lib, GLSupport contextVersion) 117 { 118 lib.bindGLSymbol(cast(void**)&glGetUniformIndices, "glGetUniformIndices"); 119 lib.bindGLSymbol(cast(void**)&glGetActiveUniformsiv, "glGetActiveUniformsiv"); 120 lib.bindGLSymbol(cast(void**)&glGetActiveUniformName, "glGetActiveUniformName"); 121 lib.bindGLSymbol(cast(void**)&glGetUniformBlockIndex, "glGetUniformBlockIndex"); 122 lib.bindGLSymbol(cast(void**)&glGetActiveUniformBlockiv, "glGetActiveUniformBlockiv"); 123 lib.bindGLSymbol(cast(void**)&glGetActiveUniformBlockName, "glGetActiveUniformBlockName"); 124 lib.bindGLSymbol(cast(void**)&glUniformBlockBinding, "glUniformBlockBinding"); 125 return resetErrorCountGL(); 126 } 127 } 128 else enum hasARBUniformBufferObject = false; 129 130 package(bindbc.opengl) @nogc nothrow 131 bool loadARB31(SharedLib lib, GLSupport contextVersion) 132 { 133 static if(has31) { 134 if(contextVersion >= GLSupport.gl31) { 135 bool ret = true; 136 ret = _hasARBCopyBuffer = lib.loadARBCopyBuffer(contextVersion); 137 ret = _hasARBUniformBufferObject = lib.loadARBUniformBufferObject(contextVersion); 138 return ret; 139 } 140 } 141 142 static if(useARBCopyBuffer) _hasARBCopyBuffer = 143 hasExtension(contextVersion, "GL_ARB_copy_buffer") && 144 lib.loadARBCopyBuffer(contextVersion); 145 146 static if(useARBUniformBufferObject) _hasARBUniformBufferObject = 147 hasExtension(contextVersion, "GL_ARB_uniform_buffer_object") && 148 lib.loadARBUniformBufferObject(contextVersion); 149 150 return true; 151 }