mirror of
https://github.com/edubart/otclient.git
synced 2025-06-07 19:34:29 +02:00
EGL and WGL working
This commit is contained in:
parent
96bbe20588
commit
ab9351196c
@ -380,11 +380,15 @@ if(FRAMEWORK_GRAPHICS)
|
||||
else()
|
||||
if(WIN32)
|
||||
set(framework_SOURCES ${framework_SOURCES}
|
||||
${CMAKE_CURRENT_LIST_DIR}/graphics/ogl/graphicscontextwgl.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/graphics/ogl/graphicscontextwgl.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/platform/win32window.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/platform/win32window.h
|
||||
)
|
||||
if(NOT OPENGLES)
|
||||
set(framework_SOURCES ${framework_SOURCES}
|
||||
${CMAKE_CURRENT_LIST_DIR}/graphics/ogl/graphicscontextwgl.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/graphics/ogl/graphicscontextwgl.h
|
||||
)
|
||||
endif()
|
||||
else()
|
||||
set(framework_SOURCES ${framework_SOURCES}
|
||||
${CMAKE_CURRENT_LIST_DIR}/platform/x11window.cpp
|
||||
|
@ -185,7 +185,9 @@ bool Graphics::isPainterEngineAvailable(Graphics::PainterEngine painterEngine)
|
||||
bool Graphics::selectPainterEngine(PainterEngine painterEngine)
|
||||
{
|
||||
// TODO: remove this
|
||||
painterEngine = Painter_OpenGL2;
|
||||
#ifdef DIRECTX
|
||||
painterEngine = Painter_DirectX9;
|
||||
#endif
|
||||
|
||||
Painter *painter = nullptr;
|
||||
Painter *fallbackPainter = nullptr;
|
||||
|
@ -21,7 +21,12 @@
|
||||
*/
|
||||
|
||||
#include "graphicscontextegl.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <framework/platform/win32window.h>
|
||||
#else
|
||||
#include <framework/platform/x11window.h>
|
||||
#endif
|
||||
|
||||
GraphicsContextEGL::GraphicsContextEGL() :
|
||||
GraphicsContext("EGL")
|
||||
@ -35,7 +40,7 @@ GraphicsContextEGL::GraphicsContextEGL() :
|
||||
void GraphicsContextEGL::create()
|
||||
{
|
||||
#ifdef WIN32
|
||||
// TODO
|
||||
HDC display = g_win32Window.getDisplay();
|
||||
#else
|
||||
Display *display = g_x11Window.getDisplay();
|
||||
#endif
|
||||
@ -62,22 +67,17 @@ void GraphicsContextEGL::create()
|
||||
|
||||
EGLint numConfig;
|
||||
|
||||
#ifdef WIN32
|
||||
if(!eglGetConfigs(m_eglDisplay, NULL, 0, &numConfig))
|
||||
g_logger.fatal("No valid GL configurations");
|
||||
#endif
|
||||
|
||||
if(!eglChooseConfig(m_eglDisplay, configList, &m_eglConfig, 1, &numConfig))
|
||||
g_logger.fatal("Failed to choose EGL config");
|
||||
|
||||
if(numConfig != 1)
|
||||
g_logger.warning("Didn't got the exact EGL config");
|
||||
|
||||
#ifndef WIN32
|
||||
EGLint vid;
|
||||
if(!eglGetConfigAttrib(m_eglDisplay, m_eglConfig, EGL_NATIVE_VISUAL_ID, &vid))
|
||||
g_logger.fatal("Unable to get visual EGL visual id");
|
||||
|
||||
#ifndef WIN32
|
||||
XVisualInfo visTemplate;
|
||||
int numVisuals;
|
||||
memset(&visTemplate, 0, sizeof(visTemplate));
|
||||
@ -99,6 +99,7 @@ void GraphicsContextEGL::create()
|
||||
};
|
||||
|
||||
#ifdef WIN32
|
||||
HWND window = g_win32Window.getWindow();
|
||||
m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, window, NULL);
|
||||
if(m_eglSurface == EGL_NO_SURFACE)
|
||||
g_logger.fatal(stdext::format("Unable to create EGL surface: %s", eglGetError()));
|
||||
|
@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "graphicscontextwgl.h"
|
||||
#include <framework/platform/win32window.h>
|
||||
|
||||
GraphicsContextWGL::GraphicsContextWGL() :
|
||||
GraphicsContext("WGL")
|
||||
@ -28,10 +29,9 @@ GraphicsContextWGL::GraphicsContextWGL() :
|
||||
m_wglContext = 0;
|
||||
}
|
||||
|
||||
void GraphicsContextWGL::create(WindowType window, DisplayType display)
|
||||
void GraphicsContextWGL::create()
|
||||
{
|
||||
m_window = window;
|
||||
m_display = display;
|
||||
HDC display = g_win32Window.getDisplay();
|
||||
|
||||
uint pixelFormat;
|
||||
static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR),
|
||||
@ -75,7 +75,7 @@ void GraphicsContextWGL::destroy()
|
||||
|
||||
void GraphicsContextWGL::restore()
|
||||
{
|
||||
if(!wglMakeCurrent(m_display, m_wglContext))
|
||||
if(!wglMakeCurrent(g_win32Window.getDisplay(), m_wglContext))
|
||||
g_logger.fatal("Unable to make current WGL context");
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ void *GraphicsContextWGL::getExtensionProcAddress(const char *ext)
|
||||
|
||||
void GraphicsContextWGL::swapBuffers()
|
||||
{
|
||||
SwapBuffers(m_display);
|
||||
SwapBuffers(g_win32Window.getDisplay());
|
||||
}
|
||||
|
||||
void GraphicsContextWGL::setVerticalSync(bool enable)
|
||||
|
@ -31,7 +31,7 @@ class GraphicsContextWGL : public GraphicsContext
|
||||
public:
|
||||
GraphicsContextWGL();
|
||||
|
||||
void create(WindowType window, DisplayType display);
|
||||
void create();
|
||||
void destroy();
|
||||
void restore();
|
||||
|
||||
|
@ -29,6 +29,7 @@ SDLWindow window;
|
||||
#ifdef WIN32
|
||||
#include "win32window.h"
|
||||
WIN32Window window;
|
||||
WIN32Window& g_win32Window = window;
|
||||
#else
|
||||
#include "x11window.h"
|
||||
#include <framework/core/clock.h>
|
||||
|
@ -24,7 +24,12 @@
|
||||
#include <framework/graphics/image.h>
|
||||
#include <framework/core/application.h>
|
||||
#include <framework/core/resourcemanager.h>
|
||||
|
||||
#ifndef OPENGL_ES
|
||||
#include <framework/graphics/ogl/graphicscontextwgl.h>
|
||||
#else
|
||||
#include <framework/graphics/ogl/graphicscontextegl.h>
|
||||
#endif
|
||||
|
||||
#define HSB_BIT_SET(p, n) (p[(n)/8] |= (128 >>((n)%8)))
|
||||
|
||||
@ -37,8 +42,12 @@ WIN32Window::WIN32Window()
|
||||
m_size = Size(600,480);
|
||||
m_hidden = true;
|
||||
m_deviceContext = 0;
|
||||
|
||||
#ifndef OPENGL_ES
|
||||
m_graphicsContext = GraphicsContextPtr(new GraphicsContextWGL);
|
||||
std::cout << "lal3: \"" << m_graphicsContext->getName().c_str() << "\" aa" << std::endl;
|
||||
#else
|
||||
m_graphicsContext = GraphicsContextPtr(new GraphicsContextEGL);
|
||||
#endif
|
||||
|
||||
m_keyMap[VK_ESCAPE] = Fw::KeyEscape;
|
||||
m_keyMap[VK_TAB] = Fw::KeyTab;
|
||||
@ -196,8 +205,8 @@ void WIN32Window::init()
|
||||
{
|
||||
m_instance = GetModuleHandle(NULL);
|
||||
internalCreateWindow();
|
||||
internalCreateContext();
|
||||
internalRestoreContext();
|
||||
m_graphicsContext->create();
|
||||
m_graphicsContext->restore();
|
||||
}
|
||||
|
||||
void WIN32Window::terminate()
|
||||
@ -212,7 +221,7 @@ void WIN32Window::terminate()
|
||||
DestroyCursor(cursor);
|
||||
m_cursors.clear();
|
||||
|
||||
internalDestroyContext();
|
||||
m_graphicsContext->destroy();
|
||||
|
||||
if(m_deviceContext) {
|
||||
if(!ReleaseDC(m_window, m_deviceContext))
|
||||
@ -289,22 +298,6 @@ void WIN32Window::internalCreateWindow()
|
||||
g_logger.fatal("GetDC failed");
|
||||
}
|
||||
|
||||
void WIN32Window::internalCreateContext()
|
||||
{
|
||||
dump << m_graphicsContext->getName().c_str();
|
||||
m_graphicsContext->create(m_window, m_deviceContext);
|
||||
}
|
||||
|
||||
void WIN32Window::internalDestroyContext()
|
||||
{
|
||||
m_graphicsContext->destroy();
|
||||
}
|
||||
|
||||
void WIN32Window::internalRestoreContext()
|
||||
{
|
||||
m_graphicsContext->restore();
|
||||
}
|
||||
|
||||
void WIN32Window::move(const Point& pos)
|
||||
{
|
||||
Rect clientRect(pos, getClientRect().size());
|
||||
@ -579,7 +572,7 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
|
||||
}
|
||||
|
||||
if(m_visible)
|
||||
internalRestoreContext();
|
||||
m_graphicsContext->restore();
|
||||
|
||||
Size size = Size(LOWORD(lParam), HIWORD(lParam));
|
||||
size.setWidth(std::max(std::min(size.width(), 7680), 32));
|
||||
|
@ -31,9 +31,6 @@ struct WindowProcProxy;
|
||||
class WIN32Window : public PlatformWindow
|
||||
{
|
||||
void internalCreateWindow();
|
||||
void internalCreateContext();
|
||||
void internalDestroyContext();
|
||||
void internalRestoreContext();
|
||||
|
||||
LRESULT windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
friend class WindowProcProxy;
|
||||
@ -70,6 +67,8 @@ public:
|
||||
Size getDisplaySize();
|
||||
std::string getClipboardText();
|
||||
std::string getPlatformType();
|
||||
HWND getWindow() { return m_window; }
|
||||
HDC getDisplay() { return m_deviceContext; }
|
||||
|
||||
protected:
|
||||
int internalLoadMouseCursor(const ImagePtr& image, const Point& hotSpot);
|
||||
@ -88,4 +87,6 @@ private:
|
||||
bool m_hidden;
|
||||
};
|
||||
|
||||
extern WIN32Window& g_win32Window;
|
||||
|
||||
#endif
|
||||
|
@ -23,10 +23,14 @@
|
||||
#include "x11window.h"
|
||||
#include <framework/core/resourcemanager.h>
|
||||
#include <framework/graphics/image.h>
|
||||
#include <framework/graphics/ogl/graphicscontextglx.h>
|
||||
#include <framework/graphics/ogl/graphicscontextegl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef OPENGL_ES
|
||||
#include <framework/graphics/ogl/graphicscontextglx.h>
|
||||
#else
|
||||
#include <framework/graphics/ogl/graphicscontextegl.h>
|
||||
#endif
|
||||
|
||||
#define LSB_BIT_SET(p, n) (p[(n)/8] |= (1 <<((n)%8)))
|
||||
|
||||
X11Window::X11Window()
|
||||
|
Loading…
x
Reference in New Issue
Block a user