mirror of https://github.com/AxioDL/boo.git
Ensure OGL 3.3 context is created
This commit is contained in:
parent
577ed6dfbf
commit
bb2ca27ab7
|
@ -3947,11 +3947,13 @@ static GLboolean _glewInit_GL_VERSION_3_2 (GLEW_CONTEXT_ARG_DEF_INIT)
|
||||||
|
|
||||||
#ifdef GL_VERSION_3_3
|
#ifdef GL_VERSION_3_3
|
||||||
|
|
||||||
|
static GLboolean _glewInit_GL_ARB_vertex_array_object (GLEW_CONTEXT_ARG_DEF_INIT);
|
||||||
static GLboolean _glewInit_GL_VERSION_3_3 (GLEW_CONTEXT_ARG_DEF_INIT)
|
static GLboolean _glewInit_GL_VERSION_3_3 (GLEW_CONTEXT_ARG_DEF_INIT)
|
||||||
{
|
{
|
||||||
GLboolean r = GL_FALSE;
|
GLboolean r = GL_FALSE;
|
||||||
|
|
||||||
r = ((glVertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISORPROC)glewGetProcAddress((const GLubyte*)"glVertexAttribDivisor")) == NULL) || r;
|
r = ((glVertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISORPROC)glewGetProcAddress((const GLubyte*)"glVertexAttribDivisor")) == NULL) || r;
|
||||||
|
_glewInit_GL_ARB_vertex_array_object();
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,17 @@
|
||||||
|
|
||||||
#include <LogVisor/LogVisor.hpp>
|
#include <LogVisor/LogVisor.hpp>
|
||||||
|
|
||||||
|
typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
|
||||||
|
glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
|
||||||
|
static const int ContextAttribs[] =
|
||||||
|
{
|
||||||
|
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
|
||||||
|
GLX_CONTEXT_MINOR_VERSION_ARB, 3,
|
||||||
|
//GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
|
||||||
|
//GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
namespace boo
|
namespace boo
|
||||||
{
|
{
|
||||||
static LogVisor::LogModule Log("boo::WindowXCB");
|
static LogVisor::LogModule Log("boo::WindowXCB");
|
||||||
|
@ -115,7 +126,7 @@ struct XCBAtoms
|
||||||
Atom m_netwmStateFullscreen = 0;
|
Atom m_netwmStateFullscreen = 0;
|
||||||
Atom m_netwmStateAdd = 0;
|
Atom m_netwmStateAdd = 0;
|
||||||
Atom m_netwmStateRemove = 0;
|
Atom m_netwmStateRemove = 0;
|
||||||
//xcb_key_symbols_t* m_keySyms = NULL;
|
Atom m_motifWmHints = 0;
|
||||||
XCBAtoms(Display* disp)
|
XCBAtoms(Display* disp)
|
||||||
{
|
{
|
||||||
m_wmProtocols = XInternAtom(disp, "WM_PROTOCOLS", True);
|
m_wmProtocols = XInternAtom(disp, "WM_PROTOCOLS", True);
|
||||||
|
@ -124,19 +135,19 @@ struct XCBAtoms
|
||||||
m_netwmStateFullscreen = XInternAtom(disp, "_NET_WM_STATE_FULLSCREEN", False);
|
m_netwmStateFullscreen = XInternAtom(disp, "_NET_WM_STATE_FULLSCREEN", False);
|
||||||
m_netwmStateAdd = XInternAtom(disp, "_NET_WM_STATE_ADD", False);
|
m_netwmStateAdd = XInternAtom(disp, "_NET_WM_STATE_ADD", False);
|
||||||
m_netwmStateRemove = XInternAtom(disp, "_NET_WM_STATE_REMOVE", False);
|
m_netwmStateRemove = XInternAtom(disp, "_NET_WM_STATE_REMOVE", False);
|
||||||
//m_keySyms = xcb_key_symbols_alloc(conn);
|
m_motifWmHints = XInternAtom(disp, "_MOTIF_WM_HINTS", True);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static XCBAtoms* S_ATOMS = NULL;
|
static XCBAtoms* S_ATOMS = NULL;
|
||||||
|
|
||||||
static void genFrameDefault(Screen* screen, int* xOut, int* yOut, int* wOut, int* hOut)
|
static void genFrameDefault(Screen* screen, int& xOut, int& yOut, int& wOut, int& hOut)
|
||||||
{
|
{
|
||||||
float width = screen->width * 2.0 / 3.0;
|
float width = screen->width * 2.0 / 3.0;
|
||||||
float height = screen->height * 2.0 / 3.0;
|
float height = screen->height * 2.0 / 3.0;
|
||||||
*xOut = (screen->width - width) / 2.0;
|
xOut = (screen->width - width) / 2.0;
|
||||||
*yOut = (screen->height - height) / 2.0;
|
yOut = (screen->height - height) / 2.0;
|
||||||
*wOut = width;
|
wOut = width;
|
||||||
*hOut = height;
|
hOut = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct GraphicsContextXCB : IGraphicsContext
|
struct GraphicsContextXCB : IGraphicsContext
|
||||||
|
@ -264,7 +275,9 @@ public:
|
||||||
|
|
||||||
void initializeContext()
|
void initializeContext()
|
||||||
{
|
{
|
||||||
m_glxCtx = glXCreateNewContext(m_xDisp, m_fbconfig, GLX_RGBA_TYPE, m_lastCtx, True);
|
glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)
|
||||||
|
glXGetProcAddressARB((const GLubyte*)"glXCreateContextAttribsARB");
|
||||||
|
m_glxCtx = glXCreateContextAttribsARB(m_xDisp, m_fbconfig, m_lastCtx, True, ContextAttribs);
|
||||||
if (!m_glxCtx)
|
if (!m_glxCtx)
|
||||||
Log.report(LogVisor::FatalError, "unable to make new GLX context");
|
Log.report(LogVisor::FatalError, "unable to make new GLX context");
|
||||||
m_glxWindow = glXCreateWindow(m_xDisp, m_fbconfig, m_parentWindow->getPlatformHandle(), nullptr);
|
m_glxWindow = glXCreateWindow(m_xDisp, m_fbconfig, m_parentWindow->getPlatformHandle(), nullptr);
|
||||||
|
@ -273,7 +286,7 @@ public:
|
||||||
_XCBUpdateLastGlxCtx(m_glxCtx);
|
_XCBUpdateLastGlxCtx(m_glxCtx);
|
||||||
|
|
||||||
/* Make additional shared context for vsync timing */
|
/* Make additional shared context for vsync timing */
|
||||||
m_timerCtx = glXCreateNewContext(m_xDisp, m_fbconfig, GLX_RGBA_TYPE, m_glxCtx, True);
|
m_timerCtx = glXCreateContextAttribsARB(m_xDisp, m_fbconfig, m_glxCtx, True, ContextAttribs);
|
||||||
if (!m_timerCtx)
|
if (!m_timerCtx)
|
||||||
Log.report(LogVisor::FatalError, "unable to make new timer GLX context");
|
Log.report(LogVisor::FatalError, "unable to make new timer GLX context");
|
||||||
}
|
}
|
||||||
|
@ -284,10 +297,34 @@ public:
|
||||||
Log.report(LogVisor::FatalError, "unable to make GLX context current");
|
Log.report(LogVisor::FatalError, "unable to make GLX context current");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef void (*DEBUGPROC)(GLenum source,
|
||||||
|
GLenum type,
|
||||||
|
GLuint id,
|
||||||
|
GLenum severity,
|
||||||
|
GLsizei length,
|
||||||
|
const GLchar* message,
|
||||||
|
void* userParam);
|
||||||
|
|
||||||
|
static void DebugCb(GLenum source,
|
||||||
|
GLenum type,
|
||||||
|
GLuint id,
|
||||||
|
GLenum severity,
|
||||||
|
GLsizei length,
|
||||||
|
const GLchar* message,
|
||||||
|
void* userParam)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s\n", message);
|
||||||
|
}
|
||||||
|
typedef void(*glDebugMessageCallbackPROC)(DEBUGPROC callback, void* userParam);
|
||||||
|
|
||||||
void postInit()
|
void postInit()
|
||||||
{
|
{
|
||||||
GLXExtensionCheck();
|
GLXExtensionCheck();
|
||||||
GLXEnableVSync(m_xDisp, m_glxWindow);
|
GLXEnableVSync(m_xDisp, m_glxWindow);
|
||||||
|
|
||||||
|
glDebugMessageCallbackPROC glDebugMessageCb = (glDebugMessageCallbackPROC)
|
||||||
|
glXGetProcAddressARB((const GLubyte*)"glDebugMessageCallback");
|
||||||
|
glDebugMessageCb(DebugCb, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
IGraphicsCommandQueue* getCommandQueue()
|
IGraphicsCommandQueue* getCommandQueue()
|
||||||
|
@ -308,7 +345,7 @@ public:
|
||||||
{
|
{
|
||||||
if (!m_loadCtx)
|
if (!m_loadCtx)
|
||||||
{
|
{
|
||||||
m_loadCtx = glXCreateNewContext(m_xDisp, m_fbconfig, GLX_RGBA_TYPE, m_glxCtx, True);
|
m_loadCtx = glXCreateContextAttribsARB(m_xDisp, m_fbconfig, m_glxCtx, True, ContextAttribs);
|
||||||
if (!m_loadCtx)
|
if (!m_loadCtx)
|
||||||
Log.report(LogVisor::FatalError, "unable to make load GLX context");
|
Log.report(LogVisor::FatalError, "unable to make load GLX context");
|
||||||
if (!glXMakeContextCurrent(m_xDisp, m_glxWindow, m_glxWindow, m_loadCtx))
|
if (!glXMakeContextCurrent(m_xDisp, m_glxWindow, m_glxWindow, m_loadCtx))
|
||||||
|
@ -394,7 +431,7 @@ public:
|
||||||
|
|
||||||
/* Create window */
|
/* Create window */
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
genFrameDefault(screen, &x, &y, &w, &h);
|
genFrameDefault(screen, x, y, w, h);
|
||||||
XSetWindowAttributes swa;
|
XSetWindowAttributes swa;
|
||||||
swa.colormap = m_colormapId;
|
swa.colormap = m_colormapId;
|
||||||
swa.border_pixmap = None;
|
swa.border_pixmap = None;
|
||||||
|
@ -470,9 +507,13 @@ public:
|
||||||
|
|
||||||
std::string getTitle()
|
std::string getTitle()
|
||||||
{
|
{
|
||||||
|
unsigned long nitems;
|
||||||
|
Atom actualType;
|
||||||
|
int actualFormat;
|
||||||
|
unsigned long bytes;
|
||||||
unsigned char* string = nullptr;
|
unsigned char* string = nullptr;
|
||||||
if (XGetWindowProperty(m_xDisp, m_windowId, XA_WM_NAME, 0, 65536, False,
|
if (XGetWindowProperty(m_xDisp, m_windowId, XA_WM_NAME, 0, ~0l, False,
|
||||||
XA_STRING, nullptr, nullptr, nullptr, nullptr, &string))
|
XA_STRING, &actualType, &actualFormat, &nitems, &bytes, &string) == Success)
|
||||||
{
|
{
|
||||||
std::string retval((const char*)string);
|
std::string retval((const char*)string);
|
||||||
XFree(string);
|
XFree(string);
|
||||||
|
@ -492,17 +533,29 @@ public:
|
||||||
{
|
{
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
Screen* screen = DefaultScreenOfDisplay(m_xDisp);
|
Screen* screen = DefaultScreenOfDisplay(m_xDisp);
|
||||||
genFrameDefault(screen, &x, &y, &w, &h);
|
genFrameDefault(screen, x, y, w, h);
|
||||||
XWindowChanges values = {(int)x, (int)y, (int)w, (int)h};
|
XWindowChanges values = {(int)x, (int)y, (int)w, (int)h};
|
||||||
XConfigureWindow(m_xDisp, m_windowId, CWX|CWY|CWWidth|CWHeight, &values);
|
XConfigureWindow(m_xDisp, m_windowId, CWX|CWY|CWWidth|CWHeight, &values);
|
||||||
}
|
}
|
||||||
|
|
||||||
void getWindowFrame(float& xOut, float& yOut, float& wOut, float& hOut) const
|
void getWindowFrame(float& xOut, float& yOut, float& wOut, float& hOut) const
|
||||||
{
|
{
|
||||||
xOut = m_wx;
|
XWindowAttributes attrs;
|
||||||
yOut = m_wy;
|
XGetWindowAttributes(m_xDisp, m_windowId, &attrs);
|
||||||
wOut = m_ww;
|
xOut = attrs.x;
|
||||||
hOut = m_wh;
|
yOut = attrs.y;
|
||||||
|
wOut = attrs.width;
|
||||||
|
hOut = attrs.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
void getWindowFrame(int& xOut, int& yOut, int& wOut, int& hOut) const
|
||||||
|
{
|
||||||
|
XWindowAttributes attrs;
|
||||||
|
XGetWindowAttributes(m_xDisp, m_windowId, &attrs);
|
||||||
|
xOut = attrs.x;
|
||||||
|
yOut = attrs.y;
|
||||||
|
wOut = attrs.width;
|
||||||
|
hOut = attrs.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setWindowFrame(float x, float y, float w, float h)
|
void setWindowFrame(float x, float y, float w, float h)
|
||||||
|
@ -511,13 +564,24 @@ public:
|
||||||
XConfigureWindow(m_xDisp, m_windowId, CWX|CWY|CWWidth|CWHeight, &values);
|
XConfigureWindow(m_xDisp, m_windowId, CWX|CWY|CWWidth|CWHeight, &values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setWindowFrame(int x, int y, int w, int h)
|
||||||
|
{
|
||||||
|
XWindowChanges values = {x, y, w, h};
|
||||||
|
XConfigureWindow(m_xDisp, m_windowId, CWX|CWY|CWWidth|CWHeight, &values);
|
||||||
|
}
|
||||||
|
|
||||||
float getVirtualPixelFactor() const
|
float getVirtualPixelFactor() const
|
||||||
{
|
{
|
||||||
return m_pixelFactor;
|
return m_pixelFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool m_inFs = false;
|
||||||
|
int m_origFrame[4];
|
||||||
|
uint32_t m_decoBits;
|
||||||
|
|
||||||
bool isFullscreen() const
|
bool isFullscreen() const
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
unsigned long nitems;
|
unsigned long nitems;
|
||||||
Atom actualType;
|
Atom actualType;
|
||||||
int actualFormat;
|
int actualFormat;
|
||||||
|
@ -539,10 +603,22 @@ public:
|
||||||
return fullscreen;
|
return fullscreen;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
#endif
|
||||||
|
return m_inFs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct FSHints
|
||||||
|
{
|
||||||
|
uint32_t flags;
|
||||||
|
uint32_t functions;
|
||||||
|
uint32_t decorations;
|
||||||
|
int32_t inputMode;
|
||||||
|
uint32_t status;
|
||||||
|
};
|
||||||
|
|
||||||
void setFullscreen(bool fs)
|
void setFullscreen(bool fs)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
XEvent fsEvent;
|
XEvent fsEvent;
|
||||||
fsEvent.type = ClientMessage;
|
fsEvent.type = ClientMessage;
|
||||||
fsEvent.xclient.window = m_windowId;
|
fsEvent.xclient.window = m_windowId;
|
||||||
|
@ -553,6 +629,54 @@ public:
|
||||||
fsEvent.xclient.data.l[2] = 0;
|
fsEvent.xclient.data.l[2] = 0;
|
||||||
XSendEvent(m_xDisp, m_windowId, False,
|
XSendEvent(m_xDisp, m_windowId, False,
|
||||||
StructureNotifyMask | SubstructureRedirectMask, (XEvent*)&fsEvent);
|
StructureNotifyMask | SubstructureRedirectMask, (XEvent*)&fsEvent);
|
||||||
|
#endif
|
||||||
|
if (!m_inFs)
|
||||||
|
{
|
||||||
|
if (!fs)
|
||||||
|
return;
|
||||||
|
|
||||||
|
XSetWindowAttributes attrs = {};
|
||||||
|
attrs.override_redirect = True;
|
||||||
|
//XChangeWindowAttributes(m_xDisp, m_windowId, CWOverrideRedirect, &attrs);
|
||||||
|
|
||||||
|
FSHints hints = {};
|
||||||
|
hints.flags = 2;
|
||||||
|
hints.decorations = 1;
|
||||||
|
XChangeProperty(m_xDisp, m_windowId, S_ATOMS->m_motifWmHints, S_ATOMS->m_motifWmHints, 32,
|
||||||
|
PropModeReplace, (unsigned char*)&hints, 5);
|
||||||
|
|
||||||
|
getWindowFrame(m_origFrame[0], m_origFrame[1], m_origFrame[2], m_origFrame[3]);
|
||||||
|
Screen* screen = DefaultScreenOfDisplay(m_xDisp);
|
||||||
|
if (m_origFrame[2] < 1 || m_origFrame[3] < 1)
|
||||||
|
genFrameDefault(screen, m_origFrame[0], m_origFrame[1], m_origFrame[2], m_origFrame[3]);
|
||||||
|
fprintf(stderr, "= %d %d %d %d\n", m_origFrame[0], m_origFrame[1], m_origFrame[2], m_origFrame[3]);
|
||||||
|
fprintf(stderr, "%d %d %d %d\n", 0, 0, screen->width, screen->height);
|
||||||
|
setWindowFrame(0, 0, screen->width, screen->height);
|
||||||
|
|
||||||
|
m_inFs = true;
|
||||||
|
fprintf(stderr, "FULLSCREEN\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (fs)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fprintf(stderr, "%d %d %d %d\n", m_origFrame[0], m_origFrame[1], m_origFrame[2], m_origFrame[3]);
|
||||||
|
setWindowFrame(m_origFrame[0], m_origFrame[1], m_origFrame[2], m_origFrame[3]);
|
||||||
|
|
||||||
|
XSetWindowAttributes attrs = {};
|
||||||
|
attrs.override_redirect = False;
|
||||||
|
//XChangeWindowAttributes(m_xDisp, m_windowId, CWOverrideRedirect, &attrs);
|
||||||
|
|
||||||
|
FSHints hints = {};
|
||||||
|
hints.flags = 2;
|
||||||
|
hints.decorations = 1;
|
||||||
|
XChangeProperty(m_xDisp, m_windowId, S_ATOMS->m_motifWmHints, S_ATOMS->m_motifWmHints, 32,
|
||||||
|
PropModeReplace, (unsigned char*)&hints, 5);
|
||||||
|
|
||||||
|
m_inFs = false;
|
||||||
|
fprintf(stderr, "WINDOWED\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void waitForRetrace()
|
void waitForRetrace()
|
||||||
|
|
|
@ -228,7 +228,7 @@ struct TestApplicationCallback : IApplicationCallback
|
||||||
|
|
||||||
/* Make shader pipeline */
|
/* Make shader pipeline */
|
||||||
static const char* VS =
|
static const char* VS =
|
||||||
"#version 300 es\n"
|
"#version 330\n"
|
||||||
"layout(location=0) in vec3 in_pos;\n"
|
"layout(location=0) in vec3 in_pos;\n"
|
||||||
"layout(location=1) in vec2 in_uv;\n"
|
"layout(location=1) in vec2 in_uv;\n"
|
||||||
"out vec2 out_uv;\n"
|
"out vec2 out_uv;\n"
|
||||||
|
@ -239,7 +239,7 @@ struct TestApplicationCallback : IApplicationCallback
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
static const char* FS =
|
static const char* FS =
|
||||||
"#version 300 es\n"
|
"#version 330\n"
|
||||||
"precision highp float;\n"
|
"precision highp float;\n"
|
||||||
"uniform sampler2D tex;\n"
|
"uniform sampler2D tex;\n"
|
||||||
"layout(location=0) out vec4 out_frag;\n"
|
"layout(location=0) out vec4 out_frag;\n"
|
||||||
|
@ -278,7 +278,7 @@ struct TestApplicationCallback : IApplicationCallback
|
||||||
mainWindow = app->newWindow(_S("YAY!"));
|
mainWindow = app->newWindow(_S("YAY!"));
|
||||||
mainWindow->setCallback(&windowCallback);
|
mainWindow->setCallback(&windowCallback);
|
||||||
mainWindow->showWindow();
|
mainWindow->showWindow();
|
||||||
mainWindow->setFullscreen(true);
|
//mainWindow->setFullscreen(true);
|
||||||
devFinder.startScanning();
|
devFinder.startScanning();
|
||||||
|
|
||||||
IGraphicsCommandQueue* gfxQ = mainWindow->getCommandQueue();
|
IGraphicsCommandQueue* gfxQ = mainWindow->getCommandQueue();
|
||||||
|
@ -301,12 +301,13 @@ struct TestApplicationCallback : IApplicationCallback
|
||||||
gfxQ->present();
|
gfxQ->present();
|
||||||
gfxQ->execute();
|
gfxQ->execute();
|
||||||
|
|
||||||
fprintf(stderr, "%zu\n", frameIdx++);
|
//fprintf(stderr, "%zu\n", frameIdx++);
|
||||||
|
++frameIdx;
|
||||||
|
|
||||||
if ((frameIdx - lastCheck) > 100)
|
if ((frameIdx - lastCheck) > 100)
|
||||||
{
|
{
|
||||||
lastCheck = frameIdx;
|
lastCheck = frameIdx;
|
||||||
mainWindow->setFullscreen(!mainWindow->isFullscreen());
|
//mainWindow->setFullscreen(!mainWindow->isFullscreen());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue