mirror of
https://github.com/edubart/otclient.git
synced 2025-06-07 19:34:29 +02:00
More changes to context
This commit is contained in:
parent
a989ceb10c
commit
c3c951ebbb
@ -28,8 +28,11 @@
|
|||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
typedef HWND WindowType;
|
typedef HWND WindowType;
|
||||||
|
typedef HDC DisplayType;
|
||||||
#else
|
#else
|
||||||
|
#include <X11/Xlib.h>
|
||||||
typedef Window WindowType;
|
typedef Window WindowType;
|
||||||
|
typedef Display *DisplayType;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class GraphicsContext
|
class GraphicsContext
|
||||||
@ -40,19 +43,18 @@ public:
|
|||||||
|
|
||||||
std::string getName() { return m_name; }
|
std::string getName() { return m_name; }
|
||||||
|
|
||||||
virtual void create(WindowType window) = 0;
|
virtual void create(WindowType window, DisplayType display) = 0;
|
||||||
virtual void destroy(WindowType window) = 0;
|
virtual void destroy() = 0;
|
||||||
virtual void restore() = 0;
|
virtual void restore() = 0;
|
||||||
|
|
||||||
virtual bool isExtensionSupported(const char *ext) = 0;
|
|
||||||
virtual void *getExtensionProcAddress(const char *ext) = 0;
|
|
||||||
|
|
||||||
virtual void swapBuffers() = 0;
|
virtual void swapBuffers() = 0;
|
||||||
|
|
||||||
virtual void setVerticalSync(bool enable) = 0;
|
virtual void setVerticalSync(bool enable) = 0;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
|
WindowType m_window;
|
||||||
|
DisplayType m_display;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -31,9 +31,12 @@ GraphicsContextEGL::GraphicsContextEGL() :
|
|||||||
m_eglSurface = 0;
|
m_eglSurface = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsContextEGL::create()
|
void GraphicsContextEGL::create(WindowType window, DisplayType display)
|
||||||
{
|
{
|
||||||
m_eglDisplay = eglGetDisplay(m_deviceContext);
|
m_window = window;
|
||||||
|
m_display = display;
|
||||||
|
|
||||||
|
m_eglDisplay = eglGetDisplay(display);
|
||||||
if(m_eglDisplay == EGL_NO_DISPLAY)
|
if(m_eglDisplay == EGL_NO_DISPLAY)
|
||||||
g_logger.fatal("EGL not supported");
|
g_logger.fatal("EGL not supported");
|
||||||
|
|
||||||
@ -73,7 +76,7 @@ void GraphicsContextEGL::create()
|
|||||||
EGL_NONE
|
EGL_NONE
|
||||||
};
|
};
|
||||||
|
|
||||||
m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, m_window, NULL);
|
m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, window, NULL);
|
||||||
if(m_eglSurface == EGL_NO_SURFACE)
|
if(m_eglSurface == EGL_NO_SURFACE)
|
||||||
g_logger.fatal(stdext::format("Unable to create EGL surface: %s", eglGetError()));
|
g_logger.fatal(stdext::format("Unable to create EGL surface: %s", eglGetError()));
|
||||||
|
|
||||||
@ -104,18 +107,6 @@ void GraphicsContextEGL::restore()
|
|||||||
g_logger.fatal("Unable to make current EGL context");
|
g_logger.fatal("Unable to make current EGL context");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GraphicsContextEGL::isExtensionSupported(const char *ext)
|
|
||||||
{
|
|
||||||
//TODO
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *GraphicsContextEGL::getExtensionProcAddress(const char *ext)
|
|
||||||
{
|
|
||||||
//TODO
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsContextEGL::swapBuffers()
|
void GraphicsContextEGL::swapBuffers()
|
||||||
{
|
{
|
||||||
eglSwapBuffers(m_eglDisplay, m_eglSurface);
|
eglSwapBuffers(m_eglDisplay, m_eglSurface);
|
||||||
|
@ -31,13 +31,10 @@ class GraphicsContextEGL : public GraphicsContext
|
|||||||
public:
|
public:
|
||||||
GraphicsContextEGL();
|
GraphicsContextEGL();
|
||||||
|
|
||||||
void create();
|
void create(WindowType window, DisplayType display);
|
||||||
void destroy();
|
void destroy();
|
||||||
void restore();
|
void restore();
|
||||||
|
|
||||||
bool isExtensionSupported(const char *ext);
|
|
||||||
void *getExtensionProcAddress(const char *ext);
|
|
||||||
|
|
||||||
void swapBuffers();
|
void swapBuffers();
|
||||||
|
|
||||||
void setVerticalSync(bool enable);
|
void setVerticalSync(bool enable);
|
||||||
|
@ -29,9 +29,18 @@ GraphicsContextGLX::GraphicsContextGLX() :
|
|||||||
m_glxContext = 0;
|
m_glxContext = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsContextGLX::create()
|
void GraphicsContextGLX::create(WindowType window, DisplayType display)
|
||||||
{
|
{
|
||||||
|
m_window = window;
|
||||||
|
m_display = display;
|
||||||
|
|
||||||
|
m_glxContext = glXCreateContext(m_display, m_visual, NULL, True);
|
||||||
|
|
||||||
|
if(!m_glxContext)
|
||||||
|
g_logger.fatal("Unable to create GLX context");
|
||||||
|
|
||||||
|
if(!glXIsDirect(m_display, m_glxContext))
|
||||||
|
g_logger.warning("GL direct rendering is not possible");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsContextGLX::destroy()
|
void GraphicsContextGLX::destroy()
|
||||||
@ -45,14 +54,16 @@ void GraphicsContextGLX::destroy()
|
|||||||
|
|
||||||
void GraphicsContextGLX::restore()
|
void GraphicsContextGLX::restore()
|
||||||
{
|
{
|
||||||
|
if(!glXMakeCurrent(m_display, m_window, m_glxContext))
|
||||||
|
g_logger.fatal("Unable to set GLX context on X11 window");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GraphicsContextGLX::isExtensionSupported(const char *ext)
|
bool GraphicsContextGLX::isExtensionSupported(const char *ext)
|
||||||
{
|
{
|
||||||
const char *exts = glXQueryExtensionsString(m_display, m_screen);
|
const char *exts = glXQueryExtensionsString(m_display, DefaultScreen(m_display));
|
||||||
if(strstr(exts, ext))
|
if(strstr(exts, ext))
|
||||||
return true;
|
return true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *GraphicsContextGLX::getExtensionProcAddress(const char *ext)
|
void *GraphicsContextGLX::getExtensionProcAddress(const char *ext)
|
||||||
|
@ -31,7 +31,7 @@ class GraphicsContextGLX : public GraphicsContext
|
|||||||
public:
|
public:
|
||||||
GraphicsContextGLX();
|
GraphicsContextGLX();
|
||||||
|
|
||||||
void create();
|
void create(WindowType window, DisplayType display);
|
||||||
void destroy();
|
void destroy();
|
||||||
void restore();
|
void restore();
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "x11window.h"
|
#include "x11window.h"
|
||||||
#include <framework/core/resourcemanager.h>
|
#include <framework/core/resourcemanager.h>
|
||||||
#include <framework/graphics/image.h>
|
#include <framework/graphics/image.h>
|
||||||
|
#include <framework/graphics/ogl/graphicscontextglx.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#define LSB_BIT_SET(p, n) (p[(n)/8] |= (1 <<((n)%8)))
|
#define LSB_BIT_SET(p, n) (p[(n)/8] |= (1 <<((n)%8)))
|
||||||
@ -42,6 +43,7 @@ X11Window::X11Window()
|
|||||||
m_wmDelete = 0;
|
m_wmDelete = 0;
|
||||||
m_minimumSize = Size(600,480);
|
m_minimumSize = Size(600,480);
|
||||||
m_size = Size(600,480);
|
m_size = Size(600,480);
|
||||||
|
m_graphicsContext = GraphicsContextPtr(new GraphicsContextGLX);
|
||||||
|
|
||||||
m_keyMap[XK_Escape] = Fw::KeyEscape;
|
m_keyMap[XK_Escape] = Fw::KeyEscape;
|
||||||
m_keyMap[XK_Tab] = Fw::KeyTab;
|
m_keyMap[XK_Tab] = Fw::KeyTab;
|
||||||
@ -201,7 +203,7 @@ void X11Window::init()
|
|||||||
internalOpenDisplay();
|
internalOpenDisplay();
|
||||||
internalCheckGL();
|
internalCheckGL();
|
||||||
internalChooseGLVisual();
|
internalChooseGLVisual();
|
||||||
internalCreateGLContext();
|
internalCreateContext();
|
||||||
internalCreateWindow();
|
internalCreateWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,7 +233,7 @@ void X11Window::terminate()
|
|||||||
m_colormap = 0;
|
m_colormap = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
internalDestroyGLContext();
|
internalDestroyContext();
|
||||||
|
|
||||||
if(m_visual) {
|
if(m_visual) {
|
||||||
XFree(m_visual);
|
XFree(m_visual);
|
||||||
@ -319,7 +321,7 @@ void X11Window::internalCreateWindow()
|
|||||||
if(!internalSetupWindowInput())
|
if(!internalSetupWindowInput())
|
||||||
g_logger.warning("Input of special keys may be messed up, because window input initialization failed");
|
g_logger.warning("Input of special keys may be messed up, because window input initialization failed");
|
||||||
|
|
||||||
internalConnectGLContext();
|
internalRestoreContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool X11Window::internalSetupWindowInput()
|
bool X11Window::internalSetupWindowInput()
|
||||||
@ -422,59 +424,19 @@ void X11Window::internalChooseGLVisual()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void X11Window::internalCreateGLContext()
|
void X11Window::internalCreateContext()
|
||||||
{
|
{
|
||||||
#ifdef OPENGL_ES
|
m_graphicsContext->create(m_window, m_display);
|
||||||
EGLint attrList[] = {
|
|
||||||
#if OPENGL_ES==2
|
|
||||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
|
||||||
#else
|
|
||||||
EGL_CONTEXT_CLIENT_VERSION, 1,
|
|
||||||
#endif
|
|
||||||
EGL_NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, EGL_NO_CONTEXT, attrList);
|
|
||||||
if(m_eglContext == EGL_NO_CONTEXT )
|
|
||||||
g_logger.fatal(stdext::format("Unable to create EGL context: %s", eglGetError()));
|
|
||||||
#else
|
|
||||||
m_glxContext = glXCreateContext(m_display, m_visual, NULL, True);
|
|
||||||
|
|
||||||
if(!m_glxContext)
|
|
||||||
g_logger.fatal("Unable to create GLX context");
|
|
||||||
|
|
||||||
if(!glXIsDirect(m_display, m_glxContext))
|
|
||||||
g_logger.warning("GL direct rendering is not possible");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void X11Window::internalDestroyGLContext()
|
void X11Window::internalDestroyContext()
|
||||||
{
|
{
|
||||||
m_graphicsContext->destroy();
|
m_graphicsContext->destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void X11Window::internalConnectGLContext()
|
void X11Window::internalRestoreContext()
|
||||||
{
|
{
|
||||||
#ifdef OPENGL_ES
|
m_graphicsContext->restore();
|
||||||
m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, m_window, NULL);
|
|
||||||
if(m_eglSurface == EGL_NO_SURFACE)
|
|
||||||
g_logger.fatal(stdext::format("Unable to create EGL surface: %s", eglGetError()));
|
|
||||||
if(!eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext))
|
|
||||||
g_logger.fatal("Unable to connect EGL context into X11 window");
|
|
||||||
#else
|
|
||||||
if(!glXMakeCurrent(m_display, m_window, m_glxContext))
|
|
||||||
g_logger.fatal("Unable to set GLX context on X11 window");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void *X11Window::getExtensionProcAddress(const char *ext)
|
|
||||||
{
|
|
||||||
return m_graphicsContext->getExtensionProcAddress(ext);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool X11Window::isExtensionSupported(const char *ext)
|
|
||||||
{
|
|
||||||
return m_graphicsContext->isExtensionSupported(ext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void X11Window::move(const Point& pos)
|
void X11Window::move(const Point& pos)
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/Xatom.h>
|
#include <X11/Xatom.h>
|
||||||
|
#include <X11/Xutil.h>
|
||||||
|
|
||||||
typedef Window WindowType;
|
typedef Window WindowType;
|
||||||
|
|
||||||
@ -39,12 +40,9 @@ class X11Window : public PlatformWindow
|
|||||||
|
|
||||||
void internalCheckGL();
|
void internalCheckGL();
|
||||||
void internalChooseGLVisual();
|
void internalChooseGLVisual();
|
||||||
void internalCreateGLContext();
|
void internalCreateContext();
|
||||||
void internalDestroyGLContext();
|
void internalDestroyContext();
|
||||||
void internalConnectGLContext();
|
void internalRestoreContext();
|
||||||
|
|
||||||
void *getExtensionProcAddress(const char *ext);
|
|
||||||
bool isExtensionSupported(const char *ext);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
X11Window();
|
X11Window();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user