1 //          Copyright Michael D. Parker 2018.
2 // Distributed under the Boost Software License, Version 1.0.
3 //    (See accompanying file LICENSE_1_0.txt or copy at
4 //          http://www.boost.org/LICENSE_1_0.txt)
5 
6 module bindbc.opengl.bind.arb.arb_01;
7 
8 import bindbc.loader;
9 import bindbc.opengl.config,
10        bindbc.opengl.context;
11 import bindbc.opengl.bind.types;
12 
13 // ARB_bindless_texture
14 version(GL_ARB) enum useARBBindlessTexture = true;
15 else version(GL_ARB_bindless_texture) enum useARBBindlessTexture = true;
16 else enum useARBBindlessTexture = false;
17 
18 static if(useARBBindlessTexture) {
19     private bool _hasARBBindlessTexture;
20     bool hasARBBindlessTexture() { return _hasARBBindlessTexture; }
21 
22     enum uint GL_UNSIGNED_INT64_ARB = 0x140F;
23 
24     extern(System) @nogc nothrow  {
25         alias pglGetTextureHandleARB = GLuint64 function(GLuint);
26         alias pglGetTextureSamplerHandleARB = GLuint64 function(GLuint,GLuint);
27         alias pglMakeTextureHandleResidentARB = void function(GLuint64);
28         alias pglMakeTextureHandleNonResidentARB = void function(GLuint64);
29         alias pglGetImageHandleARB = GLuint64 function(GLuint,GLint,GLboolean,GLint,GLenum);
30         alias pglMakeImageHandleResidentARB = void function(GLuint64,GLenum);
31         alias pglMakeImageHandleNonResidentARB = void function(GLuint64);
32         alias pglUniformHandleui64ARB = void function(GLint,GLuint64);
33         alias pglUniformHandleui64vARB = void function(GLint,GLsizei,const(GLuint64)*);
34         alias pglProgramUniformHandleui64ARB = void function(GLuint,GLint,GLuint64);
35         alias pglProgramUniformHandleui64vARB = void function(GLuint,GLint,GLsizei,const(GLuint64)*);
36         alias pglIsTextureHandleResidentARB = GLboolean function(GLuint64);
37         alias pglIsImageHandleResidentARB = GLboolean function(GLuint64);
38         alias pglVertexAttribL1ui64ARB = void function(GLuint,GLuint64);
39         alias pglVertexAttribL1ui64vARB = void function(GLuint,const(GLuint64)*);
40         alias pglGetVertexAttribLui64vARB = void function(GLuint,GLenum,GLuint64*);
41     }
42 
43     __gshared {
44         pglGetTextureHandleARB glGetTextureHandleARB;
45         pglGetTextureSamplerHandleARB glGetTextureSamplerHandleARB;
46         pglMakeTextureHandleResidentARB glMakeTextureHandleResidentARB;
47         pglMakeTextureHandleNonResidentARB glMakeTextureHandleNonResidentARB;
48         pglGetImageHandleARB glGetImageHandleARB;
49         pglMakeImageHandleResidentARB glMakeImageHandleResidentARB;
50         pglMakeImageHandleNonResidentARB glMakeImageHandleNonResidentARB;
51         pglUniformHandleui64ARB glUniformHandleui64ARB;
52         pglUniformHandleui64vARB glUniformHandleui64vARB;
53         pglProgramUniformHandleui64ARB glProgramUniformHandleui64ARB;
54         pglProgramUniformHandleui64vARB glProgramUniformHandleui64vARB;
55         pglIsTextureHandleResidentARB glIsTextureHandleResidentARB;
56         pglIsImageHandleResidentARB glIsImageHandleResidentARB;
57         pglVertexAttribL1ui64ARB glVertexAttribL1ui64ARB;
58         pglVertexAttribL1ui64vARB glVertexAttribL1ui64vARB;
59         pglGetVertexAttribLui64vARB glGetVertexAttribLui64vARB;
60     }
61 
62     private @nogc nothrow
63     bool loadARBBindlessTexture(SharedLib lib, GLSupport contextVersion)
64     {
65         lib.bindGLSymbol(cast(void**)&glGetTextureHandleARB, "glGetTextureHandleARB");
66         lib.bindGLSymbol(cast(void**)&glGetTextureSamplerHandleARB, "glGetTextureSamplerHandleARB");
67         lib.bindGLSymbol(cast(void**)&glMakeTextureHandleResidentARB, "glMakeTextureHandleResidentARB");
68         lib.bindGLSymbol(cast(void**)&glMakeTextureHandleNonResidentARB, "glMakeTextureHandleNonResidentARB");
69         lib.bindGLSymbol(cast(void**)&glGetImageHandleARB, "glGetImageHandleARB");
70         lib.bindGLSymbol(cast(void**)&glMakeImageHandleResidentARB, "glMakeImageHandleResidentARB");
71         lib.bindGLSymbol(cast(void**)&glMakeImageHandleNonResidentARB, "glMakeImageHandleNonResidentARB");
72         lib.bindGLSymbol(cast(void**)&glUniformHandleui64ARB, "glUniformHandleui64ARB");
73         lib.bindGLSymbol(cast(void**)&glUniformHandleui64vARB, "glUniformHandleui64vARB");
74         lib.bindGLSymbol(cast(void**)&glProgramUniformHandleui64ARB, "glProgramUniformHandleui64ARB");
75         lib.bindGLSymbol(cast(void**)&glProgramUniformHandleui64vARB, "glProgramUniformHandleui64vARB");
76         lib.bindGLSymbol(cast(void**)&glIsTextureHandleResidentARB, "glIsTextureHandleResidentARB");
77         lib.bindGLSymbol(cast(void**)&glIsImageHandleResidentARB, "glIsImageHandleResidentARB");
78         lib.bindGLSymbol(cast(void**)&glVertexAttribL1ui64ARB, "glVertexAttribL1ui64ARB");
79         lib.bindGLSymbol(cast(void**)&glVertexAttribL1ui64vARB, "glVertexAttribL1ui64vARB");
80         lib.bindGLSymbol(cast(void**)&glGetVertexAttribLui64vARB, "glGetVertexAttribLui64vARB");
81         return resetErrorCountGL();
82     }
83 }
84 else enum hasARBBindlessTexture = false;
85 
86 // ARB_cl_event
87 version(GL_ARB) enum useARBCLEvent = true;
88 else version(GL_ARB_cl_event) enum useARBCLEvent = true;
89 else enum useARBCLEvent = false;
90 
91 static if(useARBCLEvent) {
92     import bindbc.opengl.bind.arb.core_32 : GLsync;
93     private bool _hasARBCLEvent;
94     bool hasARBCLEvent() { return _hasARBCLEvent; }
95 
96     struct _cl_context;
97     struct _cl_event;
98 
99     enum : uint {
100         GL_SYNC_CL_EVENT_ARB              = 0x8240,
101         GL_SYNC_CL_EVENT_COMPLETE_ARB     = 0x8241,
102     }
103 
104     extern(System) @nogc nothrow alias  pglCreateSyncFromCLeventARB = GLsync function(_cl_context*, _cl_event*, GLbitfield);
105     __gshared pglCreateSyncFromCLeventARB glCreateSyncFromCLeventARB;
106 
107     private @nogc nothrow
108     bool loadARBCLEvent(SharedLib lib, GLSupport contextVersion)
109     {
110         lib.bindGLSymbol(cast(void**)&glCreateSyncFromCLeventARB, "glCreateSyncFromCLeventARB");
111         return resetErrorCountGL();
112     }
113 }
114 else enum hasARBCLEvent = false;
115 
116 // ARB_compute_variable_group_size
117 version(GL_ARB) enum useARBComputeVariableGroupSize = true;
118 else version(GL_ARB_compute_variable_group_size) enum useARBComputeVariableGroupSize = true;
119 else enum useARBComputeVariableGroupSize = false;
120 
121 static if(useARBComputeVariableGroupSize) {
122     private bool _hasARBComputeVariableGroupSize;
123     bool hasARBComputeVariableGroupSize() { return _hasARBComputeVariableGroupSize; }
124 
125     enum : uint {
126         GL_MAX_COMPUTE_VARIABLE_GROUP_INVOCATIONS_ARB   = 0x9344,
127         GL_MAX_COMPUTE_FIXED_GROUP_INVOCATIONS_ARB      = 0x90EB,
128         GL_MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB          = 0x9345,
129         GL_MAX_COMPUTE_FIXED_GROUP_SIZE_ARB             = 0x91BF,
130     }
131 
132     extern(System) @nogc nothrow alias  pglDispatchComputeGroupSizeARB = GLsync function(GLuint,GLuint,GLuint,GLuint,GLuint,GLuint);
133     __gshared pglDispatchComputeGroupSizeARB glDispatchComputeGroupSizeARB;
134 
135     private @nogc nothrow
136     bool loadARBComputeVariableGroupSize(SharedLib lib, GLSupport contextVersion)
137     {
138         lib.bindGLSymbol(cast(void**)&glDispatchComputeGroupSizeARB, "glDispatchComputeGroupSizeARB");
139         return resetErrorCountGL();
140     }
141 }
142 else enum hasARBComputeVariableGroupSize = false;
143 
144 // ARB_debug_output
145 version(GL_ARB) enum useARBDebugOutput = true;
146 else version(GL_ARB_debug_output) enum useARBDebugOutput = true;
147 else enum useARBDebugOutput = false;
148 
149 static if(useARBDebugOutput) {
150     private bool _hasARBDebugOutput;
151     bool hasARBDebugOutput() { return _hasARBDebugOutput; }
152 
153     enum : uint {
154         GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB   = 0x8242,
155         GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_ARB = 0x8243,
156         GL_DEBUG_CALLBACK_FUNCTION_ARB    = 0x8244,
157         GL_DEBUG_CALLBACK_USER_PARAM_ARB  = 0x8245,
158         GL_DEBUG_SOURCE_API_ARB           = 0x8246,
159         GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB = 0x8247,
160         GL_DEBUG_SOURCE_SHADER_COMPILER_ARB = 0x8248,
161         GL_DEBUG_SOURCE_THIRD_PARTY_ARB   = 0x8249,
162         GL_DEBUG_SOURCE_APPLICATION_ARB   = 0x824A,
163         GL_DEBUG_SOURCE_OTHER_ARB         = 0x824B,
164         GL_DEBUG_TYPE_ERROR_ARB           = 0x824C,
165         GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB = 0x824D,
166         GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB = 0x824E,
167         GL_DEBUG_TYPE_PORTABILITY_ARB     = 0x824F,
168         GL_DEBUG_TYPE_PERFORMANCE_ARB     = 0x8250,
169         GL_DEBUG_TYPE_OTHER_ARB           = 0x8251,
170         GL_MAX_DEBUG_MESSAGE_LENGTH_ARB   = 0x9143,
171         GL_MAX_DEBUG_LOGGED_MESSAGES_ARB  = 0x9144,
172         GL_DEBUG_LOGGED_MESSAGES_ARB      = 0x9145,
173         GL_DEBUG_SEVERITY_HIGH_ARB        = 0x9146,
174         GL_DEBUG_SEVERITY_MEDIUM_ARB      = 0x9147,
175         GL_DEBUG_SEVERITY_LOW_ARB         = 0x9148,
176     }
177 
178     extern(System) nothrow {
179         alias GLDEBUGPROCARB = void function(GLenum,GLenum,GLuint,GLenum,GLsizei,in GLchar*,GLvoid*);
180         alias GLDEBUGPROCAMD = void function(GLuint,GLenum,GLenum,GLsizei,in GLchar*,GLvoid*);
181     }
182 
183     extern(System) @nogc nothrow  {
184         alias pglDebugMessageControlARB = void function(GLenum,GLenum,GLenum,GLsizei,const(GLuint)*,GLboolean);
185         alias pglDebugMessageInsertARB = void function(GLenum,GLenum,GLuint,GLenum,GLsizei,const(GLchar)*);
186         alias pglGetDebugMessageLogARB = void function(GLuint,GLsizei,GLenum*,GLenum*,GLuint*,GLenum*,GLsizei*,GLchar*);
187         alias pglDebugMessageCallbackARB = void function(GLDEBUGPROCARB,const(GLvoid)*);
188     }
189 
190     __gshared {
191         pglDebugMessageControlARB glDebugMessageControlARB;
192         pglDebugMessageInsertARB glDebugMessageInsertARB;
193         pglDebugMessageCallbackARB glDebugMessageCallbackARB;
194         pglGetDebugMessageLogARB glGetDebugMessageLogARB;
195     }
196 
197     private @nogc nothrow
198     bool loadARBDebugOutput(SharedLib lib, GLSupport contextVersion)
199     {
200         lib.bindGLSymbol(cast(void**)&glDebugMessageControlARB, "glDebugMessageControlARB");
201         lib.bindGLSymbol(cast(void**)&glDebugMessageInsertARB, "glDebugMessageInsertARB");
202         lib.bindGLSymbol(cast(void**)&glDebugMessageCallbackARB, "glDebugMessageCallbackARB");
203         lib.bindGLSymbol(cast(void**)&glGetDebugMessageLogARB, "glGetDebugMessageLogARB");
204         return resetErrorCountGL();
205     }
206 }
207 else enum hasARBDebugOutput = false;
208 
209 package @nogc nothrow
210 void loadARB_01(SharedLib lib, GLSupport contextVersion)
211 {
212     static if(useARBBindlessTexture) _hasARBBindlessTexture =
213             hasExtension(contextVersion, "GL_ARB_bindless_texture") &&
214             lib.loadARBBindlessTexture(contextVersion);
215 
216     static if(useARBCLEvent) _hasARBCLEvent =
217             hasExtension(contextVersion, "GL_ARB_cl_event") &&
218             lib.loadARBCLEvent(contextVersion);
219 
220     static if(useARBComputeVariableGroupSize) _hasARBComputeVariableGroupSize =
221             hasExtension(contextVersion, "GL_ARB_compute_variable_group_size") &&
222             lib.loadARBComputeVariableGroupSize(contextVersion);
223 
224     static if(useARBDebugOutput) _hasARBDebugOutput =
225             hasExtension(contextVersion, "GL_ARB_debug_output") &&
226             lib.loadARBDebugOutput(contextVersion);
227 }