1 /* 2 3 Boost Software License - Version 1.0 - August 17th, 2003 4 5 Permission is hereby granted, free of charge, to any person or organization 6 obtaining a copy of the software and accompanying documentation covered by 7 this license (the "Software") to use, reproduce, display, distribute, 8 execute, and transmit the Software, and to prepare derivative works of the 9 Software, and to permit third-parties to whom the Software is furnished to 10 do so, all subject to the following: 11 12 The copyright notices in the Software and this entire statement, including 13 the above license grant, this restriction and the following disclaimer, 14 must be included in all copies of the Software, in whole or in part, and 15 all derivative works of the Software, unless such copies or derivative 16 works are solely in the form of machine-executable object code generated by 17 a source language processor. 18 19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 22 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 23 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 DEALINGS IN THE SOFTWARE. 26 27 */ 28 module derelict.opengl.glx; 29 30 version (freebsd) 31 { 32 version = GLX; 33 } 34 35 else version (FreeBSD) 36 { 37 version = GLX; 38 } 39 40 else version (linux) 41 { 42 version = GLX; 43 } 44 45 version(GLX) 46 { 47 48 private 49 { 50 import derelict.opengl.gltypes; 51 import derelict.util.compat; 52 import derelict.util.loader; 53 import derelict.util.xtypes; 54 } 55 56 struct __GLXcontextRec {} 57 struct __GLXFBConfigRec {} 58 59 alias uint GLXContentID; 60 alias uint GLXPixmap; 61 alias uint GLXDrawable; 62 alias uint GLXPbuffer; 63 alias uint GLXWindow; 64 alias uint GLXFBConfigID; 65 66 alias __GLXcontextRec *GLXContext; // __GLXcontextRec type is opaque 67 alias __GLXFBConfigRec *GLXFBConfig; // __GLXFBConfigRec type is opaque 68 69 /* 70 * GLX Events 71 */ 72 73 struct GLXPbufferClobberEvent 74 { 75 int event_type; 76 int draw_type; 77 uint serial; 78 Bool send_event; 79 Display* display; 80 GLXDrawable drawable; 81 uint buffer_mask; 82 uint aux_buffer; 83 int x, y; 84 int width, height; 85 int count; 86 } 87 88 union GLXEvent 89 { 90 GLXPbufferClobberEvent glxpbufferclobber; 91 int[24] pad; 92 } 93 94 // Function pointer variables 95 96 extern (C) 97 { 98 alias XVisualInfo* function(Display*,int,int*) da_glXChooseVisual; 99 alias void function(Display*,GLXContext,GLXContext,uint) da_glXCopyContext; 100 alias GLXContext function(Display*,XVisualInfo*,GLXContext,Bool) da_glXCreateContext; 101 alias GLXPixmap function(Display*,XVisualInfo*,Pixmap) da_glXCreateGLXPixmap; 102 alias void function(Display*,GLXContext) da_glXDestroyContext; 103 alias void function(Display*,GLXPixmap) da_glXDestroyGLXPixmap; 104 alias int function(Display*,XVisualInfo*,int,int*) da_glXGetConfig; 105 alias GLXContext function() da_glXGetCurrentContext; 106 alias GLXDrawable function() da_glXGetCurrentDrawable; 107 alias Bool function(Display*,GLXContext) da_glXIsDirect; 108 alias Bool function(Display*,GLXDrawable,GLXContext) da_glXMakeCurrent; 109 alias Bool function(Display*,int*,int*) da_glXQueryExtension; 110 alias Bool function(Display*,int*,int*) da_glXQueryVersion; 111 alias void function(Display*,GLXDrawable) da_glXSwapBuffers; 112 alias void function(Font,int,int,int) da_glXUseXFont; 113 alias void function() da_glXWaitGL; 114 alias void function() da_glXWaitX; 115 alias char* function(Display*,int) da_glXGetClientString; 116 alias char* function(Display*,int,int) da_glXQueryServerString; 117 alias char* function(Display*,int) da_glXQueryExtensionsString; 118 119 /* GLX 1.3 */ 120 121 alias GLXFBConfig* function(Display*,int,int*) da_glXGetFBConfigs; 122 alias GLXFBConfig* function(Display*,int,int*,int*) da_glXChooseFBConfig; 123 alias int function(Display*,GLXFBConfig,int,int*) da_glXGetFBConfigAttrib; 124 alias XVisualInfo* function(Display*,GLXFBConfig) da_glXGetVisualFromFBConfig; 125 alias GLXWindow function(Display*,GLXFBConfig,Window,int*) da_glXCreateWindow; 126 alias void function(Display*,GLXWindow) da_glXDestroyWindow; 127 alias GLXPixmap function(Display*,GLXFBConfig,Pixmap,int*) da_glXCreatePixmap; 128 alias void function(Display*,GLXPixmap) da_glXDestroyPixmap; 129 alias GLXPbuffer function(Display*,GLXFBConfig,int*) da_glXCreatePbuffer; 130 alias void function(Display*,GLXPbuffer) da_glXDestroyPbuffer; 131 alias void function(Display*,GLXDrawable,int,uint*) da_glXQueryDrawable; 132 alias GLXContext function(Display*,GLXFBConfig,int,GLXContext,Bool) da_glXCreateNewContext; 133 alias Bool function(Display*,GLXDrawable,GLXDrawable,GLXContext) da_glXMakeContextCurrent; 134 alias GLXDrawable function() da_glXGetCurrentReadDrawable; 135 alias Display* function() da_glXGetCurrentDisplay; 136 alias int function(Display*,GLXContext,int,int*) da_glXQueryContext; 137 alias void function(Display*,GLXDrawable,uint) da_glXSelectEvent; 138 alias void function(Display*,GLXDrawable,uint*) da_glXGetSelectedEvent; 139 140 /* GLX 1.4+ */ 141 alias void* function(CCPTR) da_glXGetProcAddress; 142 143 144 } 145 146 /* GLX extensions -- legacy */ 147 148 /* 149 GLXContextID function(const GLXContext) 150 pfglXGetContextIDEXT; 151 GLXContext function(Display*,GLXContextID) 152 pfglXImportContextEXT; 153 void function(Display*,GLXContext) 154 pfglXFreeContextEXT; 155 int function(Display*,GLXContext,int,int*) 156 pfglXQueryContextInfoEXT; 157 Display* function() 158 pfglXGetCurrentDisplayEXT; 159 void function() function(const GLubyte*) 160 pfglXGetProcAddressARB; 161 */ 162 163 /+ 164 165 // All extensions are disabled in the current version 166 // until further testing is done and need is established. 167 168 void* function(GLsizei,GLfloat,GLfloat,GLfloat) 169 glXAllocateMemoryNV; 170 void function(GLvoid*) 171 glXFreeMemoryNV; 172 void* function(GLsizei,GLfloat,GLfloat,GLfloat) 173 PFNGLXALLOCATEMEMORYNVPROC; 174 void function(GLvoid*) 175 PFNGLXFREEMEMORYNVPROC; 176 177 /* Mesa specific? */ 178 179 // work in progress 180 181 /* GLX_ARB specific? */ 182 183 Bool function(Display*, GLXPbuffer,int) 184 glXBindTexImageARB; 185 Bool function(Display*, GLXPbuffer,int) 186 glXReleaseTexImageARB; 187 Bool function(Display*,GLXDrawable,int*) 188 glXDrawableAttribARB; 189 190 +/ 191 192 193 mixin(gsharedString!() ~ 194 " 195 da_glXChooseVisual glXChooseVisual; 196 da_glXCopyContext glXCopyContext; 197 da_glXCreateContext glXCreateContext; 198 da_glXCreateGLXPixmap glXCreateGLXPixmap; 199 da_glXDestroyContext glXDestroyContext; 200 da_glXDestroyGLXPixmap glXDestroyGLXPixmap; 201 da_glXGetConfig glXGetConfig; 202 da_glXGetCurrentContext glXGetCurrentContext; 203 da_glXGetCurrentDrawable glXGetCurrentDrawable; 204 da_glXIsDirect glXIsDirect; 205 da_glXMakeCurrent glXMakeCurrent; 206 da_glXQueryExtension glXQueryExtension; 207 da_glXQueryVersion glXQueryVersion; 208 da_glXSwapBuffers glXSwapBuffers; 209 da_glXUseXFont glXUseXFont; 210 da_glXWaitGL glXWaitGL; 211 da_glXWaitX glXWaitX; 212 da_glXGetClientString glXGetClientString; 213 da_glXQueryServerString glXQueryServerString; 214 da_glXQueryExtensionsString glXQueryExtensionsString; 215 216 /* GLX 1.3 */ 217 218 da_glXGetFBConfigs glXGetFBConfigs; 219 da_glXChooseFBConfig glXChooseFBConfig; 220 da_glXGetFBConfigAttrib glXGetFBConfigAttrib; 221 da_glXGetVisualFromFBConfig glXGetVisualFromFBConfig; 222 da_glXCreateWindow glXCreateWindow; 223 da_glXDestroyWindow glXDestroyWindow; 224 da_glXCreatePixmap glXCreatePixmap; 225 da_glXDestroyPixmap glXDestroyPixmap; 226 da_glXCreatePbuffer glXCreatePbuffer; 227 da_glXDestroyPbuffer glXDestroyPbuffer; 228 da_glXQueryDrawable glXQueryDrawable; 229 da_glXCreateNewContext glXCreateNewContext; 230 da_glXMakeContextCurrent glXMakeContextCurrent; 231 da_glXGetCurrentReadDrawable glXGetCurrentReadDrawable; 232 da_glXGetCurrentDisplay glXGetCurrentDisplay; 233 da_glXQueryContext glXQueryContext; 234 da_glXSelectEvent glXSelectEvent; 235 da_glXGetSelectedEvent glXGetSelectedEvent; 236 237 /* GLX 1.4+ */ 238 da_glXGetProcAddress glXGetProcAddress; 239 240 "); 241 242 package 243 { 244 void loadPlatformGL(void delegate(void**, string, bool doThrow = true) bindFunc) 245 { 246 bindFunc(cast(void**)&glXChooseVisual, "glXChooseVisual", false); 247 bindFunc(cast(void**)&glXCopyContext, "glXCopyContext", false); 248 bindFunc(cast(void**)&glXCreateContext, "glXCreateContext", false); 249 bindFunc(cast(void**)&glXCreateGLXPixmap, "glXCreateGLXPixmap", false); 250 bindFunc(cast(void**)&glXDestroyContext, "glXDestroyContext", false); 251 bindFunc(cast(void**)&glXDestroyGLXPixmap, "glXDestroyGLXPixmap", false); 252 bindFunc(cast(void**)&glXGetConfig, "glXGetConfig", false); 253 bindFunc(cast(void**)&glXGetCurrentContext, "glXGetCurrentContext", false); 254 bindFunc(cast(void**)&glXGetCurrentDrawable, "glXGetCurrentDrawable", false); 255 bindFunc(cast(void**)&glXIsDirect, "glXIsDirect", false); 256 bindFunc(cast(void**)&glXMakeCurrent, "glXMakeCurrent", false); 257 bindFunc(cast(void**)&glXQueryExtension, "glXQueryExtension", false); 258 bindFunc(cast(void**)&glXQueryVersion, "glXQueryVersion", false); 259 bindFunc(cast(void**)&glXSwapBuffers, "glXSwapBuffers", false); 260 bindFunc(cast(void**)&glXUseXFont, "glXUseXFont", false); 261 bindFunc(cast(void**)&glXWaitGL, "glXWaitGL", false); 262 bindFunc(cast(void**)&glXWaitX, "glXWaitX", false); 263 bindFunc(cast(void**)&glXGetClientString, "glXGetClientString", false); 264 bindFunc(cast(void**)&glXQueryServerString, "glXQueryServerString", false); 265 bindFunc(cast(void**)&glXQueryExtensionsString, "glXQueryExtensionsString", false); 266 267 bindFunc(cast(void**)&glXGetFBConfigs, "glXGetFBConfigs", false); 268 bindFunc(cast(void**)&glXChooseFBConfig, "glXChooseFBConfig", false); 269 bindFunc(cast(void**)&glXGetFBConfigAttrib, "glXGetFBConfigAttrib", false); 270 bindFunc(cast(void**)&glXGetVisualFromFBConfig, "glXGetVisualFromFBConfig", false); 271 bindFunc(cast(void**)&glXCreateWindow, "glXCreateWindow", false); 272 bindFunc(cast(void**)&glXDestroyWindow, "glXDestroyWindow", false); 273 bindFunc(cast(void**)&glXCreatePixmap, "glXCreatePixmap", false); 274 bindFunc(cast(void**)&glXDestroyPixmap, "glXDestroyPixmap", false); 275 bindFunc(cast(void**)&glXCreatePbuffer, "glXCreatePbuffer", false); 276 bindFunc(cast(void**)&glXDestroyPbuffer, "glXDestroyPbuffer", false); 277 bindFunc(cast(void**)&glXQueryDrawable, "glXQueryDrawable", false); 278 bindFunc(cast(void**)&glXCreateNewContext, "glXCreateNewContext", false); 279 bindFunc(cast(void**)&glXMakeContextCurrent, "glXMakeContextCurrent", false); 280 bindFunc(cast(void**)&glXGetCurrentReadDrawable, "glXGetCurrentReadDrawable", false); 281 bindFunc(cast(void**)&glXGetCurrentDisplay, "glXGetCurrentDisplay", false); 282 bindFunc(cast(void**)&glXQueryContext, "glXQueryContext", false); 283 bindFunc(cast(void**)&glXSelectEvent, "glXSelectEvent", false); 284 bindFunc(cast(void**)&glXGetSelectedEvent, "glXGetSelectedEvent", false); 285 286 bindFunc(cast(void**)&glXGetProcAddress, "glXGetProcAddressARB", false); 287 } 288 289 void* loadGLSymbol(string symName) 290 { 291 return glXGetProcAddress(toCString(symName)); 292 } 293 } 294 295 } // version(linux)