ketmar opengl change, part 1

This commit is contained in:
Adam D. Ruppe 2017-07-03 19:20:10 -04:00
parent b68d4ff2a3
commit 6a995b9800
1 changed files with 49 additions and 15 deletions

View File

@ -798,6 +798,21 @@ unittest {
} }
} }
version(without_opengl) {
enum SdpyIsUsingIVGLBinds = false;
} else /*version(Posix)*/ {
static if (__traits(compiles, (){import iv.glbinds;})) {
enum SdpyIsUsingIVGLBinds = true;
public import iv.glbinds;
//pragma(msg, "SDPY: using iv.glbinds");
} else {
enum SdpyIsUsingIVGLBinds = false;
}
//} else {
// enum SdpyIsUsingIVGLBinds = false;
}
version(Windows) { version(Windows) {
import core.sys.windows.windows; import core.sys.windows.windows;
static import gdi = core.sys.windows.wingdi; static import gdi = core.sys.windows.wingdi;
@ -1649,6 +1664,7 @@ class SimpleWindow : CapableOfHandlingNativeEvent, CapableOfBeingDrawnUpon {
if(glXMakeCurrent(display, impl.window, impl.glc) == 0) if(glXMakeCurrent(display, impl.window, impl.glc) == 0)
throw new Exception("glXMakeCurrent"); throw new Exception("glXMakeCurrent");
} else version(Windows) { } else version(Windows) {
static if (SdpyIsUsingIVGLBinds) import iv.glbinds; // override druntime windows imports
if (!wglMakeCurrent(ghDC, ghRC)) if (!wglMakeCurrent(ghDC, ghRC))
throw new Exception("wglMakeCurrent"); // let windows users suffer too throw new Exception("wglMakeCurrent"); // let windows users suffer too
} }
@ -1661,6 +1677,7 @@ class SimpleWindow : CapableOfHandlingNativeEvent, CapableOfBeingDrawnUpon {
version(X11) { version(X11) {
return (glXMakeCurrent(display, impl.window, impl.glc) != 0); return (glXMakeCurrent(display, impl.window, impl.glc) != 0);
} else version(Windows) { } else version(Windows) {
static if (SdpyIsUsingIVGLBinds) import iv.glbinds; // override druntime windows imports
return wglMakeCurrent(ghDC, ghRC) ? true : false; return wglMakeCurrent(ghDC, ghRC) ? true : false;
} }
} }
@ -1672,6 +1689,7 @@ class SimpleWindow : CapableOfHandlingNativeEvent, CapableOfBeingDrawnUpon {
version(X11) { version(X11) {
return (glXMakeCurrent(display, 0, null) != 0); return (glXMakeCurrent(display, 0, null) != 0);
} else version(Windows) { } else version(Windows) {
static if (SdpyIsUsingIVGLBinds) import iv.glbinds; // override druntime windows imports
return wglMakeCurrent(ghDC, null) ? true : false; return wglMakeCurrent(ghDC, null) ? true : false;
} }
} }
@ -3603,11 +3621,15 @@ version(without_opengl) {
} }
version(X11) { version(X11) {
static if (!SdpyIsUsingIVGLBinds) {
pragma(lib, "GL"); pragma(lib, "GL");
pragma(lib, "GLU"); pragma(lib, "GLU");
}
} else version(Windows) { } else version(Windows) {
static if (!SdpyIsUsingIVGLBinds) {
pragma(lib, "opengl32"); pragma(lib, "opengl32");
pragma(lib, "glu32"); pragma(lib, "glu32");
}
} else } else
static assert(0, "OpenGL not supported on your system yet. Try -version=X11 if you have X Windows available, or -version=without_opengl to go without."); static assert(0, "OpenGL not supported on your system yet. Try -version=X11 if you have X Windows available, or -version=without_opengl to go without.");
} }
@ -6090,6 +6112,8 @@ version(Windows) {
version(without_opengl) {} version(without_opengl) {}
else { else {
if(opengl == OpenGlOptions.yes) { if(opengl == OpenGlOptions.yes) {
static if (SdpyIsUsingIVGLBinds) {if (glbindGetProcAddress("glHint") is null) assert(0, "GL: error loading OpenGL"); } // loads all necessary functions
static if (SdpyIsUsingIVGLBinds) import iv.glbinds; // override druntime windows imports
ghDC = hdc; ghDC = hdc;
PIXELFORMATDESCRIPTOR pfd; PIXELFORMATDESCRIPTOR pfd;
@ -7639,6 +7663,7 @@ version(X11) {
GLXFBConfig fbconf = null; GLXFBConfig fbconf = null;
XVisualInfo* vi = null; XVisualInfo* vi = null;
bool useLegacy = false; bool useLegacy = false;
static if (SdpyIsUsingIVGLBinds) {if (glbindGetProcAddress("glHint") is null) assert(0, "GL: error loading OpenGL"); } // loads all necessary functions
if (sdpyOpenGLContextVersion != 0 && glXCreateContextAttribsARB_present()) { if (sdpyOpenGLContextVersion != 0 && glXCreateContextAttribsARB_present()) {
int[23] visualAttribs = [ int[23] visualAttribs = [
GLX_X_RENDERABLE , 1/*True*/, GLX_X_RENDERABLE , 1/*True*/,
@ -7671,12 +7696,12 @@ version(X11) {
fbconf = fbc[bestidx]; fbconf = fbc[bestidx];
// Be sure to free the FBConfig list allocated by glXChooseFBConfig() // Be sure to free the FBConfig list allocated by glXChooseFBConfig()
XFree(fbc); XFree(fbc);
vi = glXGetVisualFromFBConfig(display, fbconf); vi = cast(XVisualInfo*)glXGetVisualFromFBConfig(display, fbconf);
} }
} }
if (vi is null || useLegacy) { if (vi is null || useLegacy) {
static immutable GLint[5] attrs = [ GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None ]; static immutable GLint[5] attrs = [ GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None ];
vi = glXChooseVisual(display, 0, attrs.ptr); vi = cast(XVisualInfo*)glXChooseVisual(cast(void*)display, 0, attrs.ptr);
useLegacy = true; useLegacy = true;
} }
if (vi is null) throw new Exception("no open gl visual found"); if (vi is null) throw new Exception("no open gl visual found");
@ -9942,6 +9967,8 @@ version(without_opengl) {}
else { else {
extern(C) nothrow @nogc { extern(C) nothrow @nogc {
/+
enum GLX_USE_GL= 1; /* support GLX rendering */ enum GLX_USE_GL= 1; /* support GLX rendering */
enum GLX_BUFFER_SIZE= 2; /* depth of the color buffer */ enum GLX_BUFFER_SIZE= 2; /* depth of the color buffer */
enum GLX_LEVEL= 3; /* level in plane stacking */ enum GLX_LEVEL= 3; /* level in plane stacking */
@ -9961,14 +9988,14 @@ enum GLX_ACCUM_BLUE_SIZE= 16; /* number of blue accum bits */
enum GLX_ACCUM_ALPHA_SIZE= 17; /* number of alpha accum bits */ enum GLX_ACCUM_ALPHA_SIZE= 17; /* number of alpha accum bits */
//XVisualInfo* glXChooseVisual(Display *dpy, int screen, in int *attrib_list);
XVisualInfo* glXChooseVisual(Display *dpy, int screen, in int *attrib_list);
enum GL_TRUE = 1; enum GL_TRUE = 1;
enum GL_FALSE = 0; enum GL_FALSE = 0;
alias int GLint; alias int GLint;
+/
alias XID GLXContextID; alias XID GLXContextID;
alias XID GLXPixmap; alias XID GLXPixmap;
@ -9978,6 +10005,7 @@ alias XID GLXWindow;
alias XID GLXFBConfigID; alias XID GLXFBConfigID;
alias void* GLXContext; alias void* GLXContext;
/+
XVisualInfo* glXChooseVisual(Display *dpy, int screen, XVisualInfo* glXChooseVisual(Display *dpy, int screen,
int *attrib_list); int *attrib_list);
@ -10017,7 +10045,7 @@ alias void* GLXContext;
void glXWaitGL(); void glXWaitGL();
void glXWaitX(); void glXWaitX();
+/
struct XVisualInfo { struct XVisualInfo {
@ -11032,9 +11060,10 @@ version(OSXCocoa) {
version(without_opengl) {} else version(without_opengl) {} else
extern(System) nothrow @nogc { extern(System) nothrow @nogc {
enum uint GL_VERSION = 0x1F02; //enum uint GL_VERSION = 0x1F02;
const(char)* glGetString (/*GLenum*/uint); //const(char)* glGetString (/*GLenum*/uint);
version(X11) { version(X11) {
static if (!SdpyIsUsingIVGLBinds) {
struct __GLXFBConfigRec {} struct __GLXFBConfigRec {}
alias GLXFBConfig = __GLXFBConfigRec*; alias GLXFBConfig = __GLXFBConfigRec*;
@ -11058,7 +11087,8 @@ extern(System) nothrow @nogc {
char* glXQueryExtensionsString (Display*, int); char* glXQueryExtensionsString (Display*, int);
void* glXGetProcAddress (const(char)*); void* glXGetProcAddress (const(char)*);
alias glGetProcAddress = glXGetProcAddress; alias glbindGetProcAddress = glXGetProcAddress;
}
// GLX_EXT_swap_control // GLX_EXT_swap_control
alias glXSwapIntervalEXT = void function (Display* dpy, /*GLXDrawable*/Drawable drawable, int interval); alias glXSwapIntervalEXT = void function (Display* dpy, /*GLXDrawable*/Drawable drawable, int interval);
@ -11074,7 +11104,7 @@ extern(System) nothrow @nogc {
public bool glXCreateContextAttribsARB_present () { public bool glXCreateContextAttribsARB_present () {
if (glXCreateContextAttribsARBFn is cast(void*)1) { if (glXCreateContextAttribsARBFn is cast(void*)1) {
// get it // get it
glXCreateContextAttribsARBFn = cast(void*)glGetProcAddress("glXCreateContextAttribsARB"); glXCreateContextAttribsARBFn = cast(void*)glbindGetProcAddress("glXCreateContextAttribsARB");
//{ import core.stdc.stdio; printf("checking glXCreateContextAttribsARB: %shere\n", (glXCreateContextAttribsARBFn !is null ? "".ptr : "not ".ptr)); } //{ import core.stdc.stdio; printf("checking glXCreateContextAttribsARB: %shere\n", (glXCreateContextAttribsARBFn !is null ? "".ptr : "not ".ptr)); }
} }
return (glXCreateContextAttribsARBFn !is null); return (glXCreateContextAttribsARBFn !is null);
@ -11099,11 +11129,12 @@ extern(System) nothrow @nogc {
_glx_swapInterval_fn(dpy, drawable, (wait ? 1 : 0)); _glx_swapInterval_fn(dpy, drawable, (wait ? 1 : 0));
} }
} else version(Windows) { } else version(Windows) {
static if (!SdpyIsUsingIVGLBinds) {
enum GL_TRUE = 1; enum GL_TRUE = 1;
enum GL_FALSE = 0; enum GL_FALSE = 0;
alias int GLint; alias int GLint;
public void* glGetProcAddress (const(char)* name) { public void* glbindGetProcAddress (const(char)* name) {
void* res = wglGetProcAddress(name); void* res = wglGetProcAddress(name);
if (res is null) { if (res is null) {
//{ import core.stdc.stdio; printf("GL: '%s' not found (0)\n", name); } //{ import core.stdc.stdio; printf("GL: '%s' not found (0)\n", name); }
@ -11117,6 +11148,7 @@ extern(System) nothrow @nogc {
} }
//{ import core.stdc.stdio; printf(" GL: '%s' is 0x%08x\n", name, cast(uint)res); } //{ import core.stdc.stdio; printf(" GL: '%s' is 0x%08x\n", name, cast(uint)res); }
return res; return res;
}
} }
enum WGL_CONTEXT_MAJOR_VERSION_ARB = 0x2091; enum WGL_CONTEXT_MAJOR_VERSION_ARB = 0x2091;
@ -11136,11 +11168,12 @@ extern(System) nothrow @nogc {
void wglInitOtherFunctions () { void wglInitOtherFunctions () {
if (wglCreateContextAttribsARB is null) { if (wglCreateContextAttribsARB is null) {
wglCreateContextAttribsARB = cast(wglCreateContextAttribsARB_fna)glGetProcAddress("wglCreateContextAttribsARB"); wglCreateContextAttribsARB = cast(wglCreateContextAttribsARB_fna)glbindGetProcAddress("wglCreateContextAttribsARB");
} }
} }
} }
static if (!SdpyIsUsingIVGLBinds) {
void glGetIntegerv(int, void*); void glGetIntegerv(int, void*);
void glMatrixMode(int); void glMatrixMode(int);
void glPushMatrix(); void glPushMatrix();
@ -11271,6 +11304,7 @@ extern(System) nothrow @nogc {
enum int GL_QUADS = 7; enum int GL_QUADS = 7;
enum int GL_QUAD_STRIP = 8; enum int GL_QUAD_STRIP = 8;
enum int GL_POLYGON = 9; enum int GL_POLYGON = 9;
}
} }
version(linux) { version(linux) {