mirror of
https://github.com/edubart/otclient.git
synced 2025-06-07 19:34:29 +02:00
Add graphics context
This commit is contained in:
parent
fb8552d142
commit
a989ceb10c
@ -350,6 +350,8 @@ if(FRAMEWORK_GRAPHICS)
|
||||
set(framework_SOURCES ${framework_SOURCES}
|
||||
${CMAKE_CURRENT_LIST_DIR}/graphics/dx/painterdx9.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/graphics/dx/painterdx9.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/graphics/dx/graphicscontextdx9.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/graphics/dx/graphicscontextdx9.h
|
||||
)
|
||||
endif()
|
||||
|
||||
@ -372,11 +374,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
|
||||
)
|
||||
else()
|
||||
set(framework_SOURCES ${framework_SOURCES}
|
||||
${CMAKE_CURRENT_LIST_DIR}/graphics/ogl/graphicscontextglx.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/graphics/ogl/graphicscontextglx.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/platform/x11window.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/platform/x11window.h
|
||||
)
|
||||
@ -402,6 +408,8 @@ if(FRAMEWORK_GRAPHICS)
|
||||
${CMAKE_CURRENT_LIST_DIR}/graphics/glutil.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/graphics/graphics.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/graphics/graphics.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/graphics/graphicscontext.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/graphics/graphicscontext.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/graphics/hardwarebuffer.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/graphics/hardwarebuffer.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/graphics/image.cpp
|
||||
|
@ -34,6 +34,7 @@ class BitmapFont;
|
||||
class CachedText;
|
||||
class FrameBuffer;
|
||||
class FrameBufferManager;
|
||||
class GraphicsContext;
|
||||
class Shader;
|
||||
class ShaderProgram;
|
||||
class PainterShaderProgram;
|
||||
@ -51,6 +52,7 @@ typedef stdext::shared_object_ptr<AnimatedTexture> AnimatedTexturePtr;
|
||||
typedef stdext::shared_object_ptr<BitmapFont> BitmapFontPtr;
|
||||
typedef stdext::shared_object_ptr<CachedText> CachedTextPtr;
|
||||
typedef stdext::shared_object_ptr<FrameBuffer> FrameBufferPtr;
|
||||
typedef stdext::shared_object_ptr<GraphicsContext> GraphicsContextPtr;
|
||||
typedef stdext::shared_object_ptr<Shader> ShaderPtr;
|
||||
typedef stdext::shared_object_ptr<ShaderProgram> ShaderProgramPtr;
|
||||
typedef stdext::shared_object_ptr<PainterShaderProgram> PainterShaderProgramPtr;
|
||||
|
@ -184,14 +184,14 @@ bool Graphics::isPainterEngineAvailable(Graphics::PainterEngine painterEngine)
|
||||
|
||||
bool Graphics::selectPainterEngine(PainterEngine painterEngine)
|
||||
{
|
||||
// TODO: remove this
|
||||
painterEngine = Painter_OpenGL2;
|
||||
|
||||
Painter *painter = nullptr;
|
||||
Painter *fallbackPainter = nullptr;
|
||||
PainterEngine fallbackPainterEngine = Painter_Any;
|
||||
|
||||
#ifdef PAINTER_DX9
|
||||
// use this to force directx if its enabled (avoid changes in options module, etc, will be removed)
|
||||
painterEngine = Painter_DirectX9;
|
||||
|
||||
// always prefer DirectX9 on Windows
|
||||
if(g_painterDX9) {
|
||||
if(!painter && (painterEngine == Painter_DirectX9 || painterEngine == Painter_Any)) {
|
||||
@ -238,6 +238,7 @@ bool Graphics::selectPainterEngine(PainterEngine painterEngine)
|
||||
if(g_painter)
|
||||
g_painter->unbind();
|
||||
painter->bind();
|
||||
g_window.setGraphicsContext(painter->getGraphicsContext());
|
||||
g_painter = painter;
|
||||
}
|
||||
|
||||
|
28
src/framework/graphics/graphicscontext.cpp
Normal file
28
src/framework/graphics/graphicscontext.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2013 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "graphicscontext.h"
|
||||
|
||||
GraphicsContext::GraphicsContext(const std::string& name)
|
||||
{
|
||||
m_name = name;
|
||||
}
|
59
src/framework/graphics/graphicscontext.h
Normal file
59
src/framework/graphics/graphicscontext.h
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2013 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef GRAPHICSCONTEXT_H
|
||||
#define GRAPHICSCONTEXT_H
|
||||
|
||||
#include "declarations.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
typedef HWND WindowType;
|
||||
#else
|
||||
typedef Window WindowType;
|
||||
#endif
|
||||
|
||||
class GraphicsContext
|
||||
{
|
||||
public:
|
||||
GraphicsContext(const std::string& name);
|
||||
virtual ~GraphicsContext() {}
|
||||
|
||||
std::string getName() { return m_name; }
|
||||
|
||||
virtual void create(WindowType window) = 0;
|
||||
virtual void destroy(WindowType window) = 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 setVerticalSync(bool enable) = 0;
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
127
src/framework/graphics/ogl/graphicscontextegl.cpp
Normal file
127
src/framework/graphics/ogl/graphicscontextegl.cpp
Normal file
@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2013 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "graphicscontextegl.h"
|
||||
|
||||
GraphicsContextEGL::GraphicsContextEGL() :
|
||||
GraphicsContext("EGL")
|
||||
{
|
||||
m_eglConfig = 0;
|
||||
m_eglContext = 0;
|
||||
m_eglDisplay = 0;
|
||||
m_eglSurface = 0;
|
||||
}
|
||||
|
||||
void GraphicsContextEGL::create()
|
||||
{
|
||||
m_eglDisplay = eglGetDisplay(m_deviceContext);
|
||||
if(m_eglDisplay == EGL_NO_DISPLAY)
|
||||
g_logger.fatal("EGL not supported");
|
||||
|
||||
if(!eglInitialize(m_eglDisplay, NULL, NULL))
|
||||
g_logger.fatal("Unable to initialize EGL");
|
||||
|
||||
static int configList[] = {
|
||||
#if OPENGL_ES==2
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
||||
#else
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
|
||||
#endif
|
||||
EGL_RED_SIZE, 4,
|
||||
EGL_GREEN_SIZE, 4,
|
||||
EGL_BLUE_SIZE, 4,
|
||||
EGL_ALPHA_SIZE, 4,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
EGLint numConfig;
|
||||
|
||||
if(!eglGetConfigs(m_eglDisplay, NULL, 0, &numConfig))
|
||||
g_logger.fatal("No valid GL configurations");
|
||||
|
||||
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");
|
||||
|
||||
EGLint contextAtrrList[] = {
|
||||
#if OPENGL_ES==2
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
#else
|
||||
EGL_CONTEXT_CLIENT_VERSION, 1,
|
||||
#endif
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
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()));
|
||||
|
||||
m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, EGL_NO_CONTEXT, contextAtrrList);
|
||||
if(m_eglContext == EGL_NO_CONTEXT )
|
||||
g_logger.fatal(stdext::format("Unable to create EGL context: %s", eglGetError()));
|
||||
}
|
||||
|
||||
void GraphicsContextEGL::destroy()
|
||||
{
|
||||
if(m_eglDisplay) {
|
||||
if(m_eglContext) {
|
||||
eglDestroyContext(m_eglDisplay, m_eglContext);
|
||||
m_eglContext = 0;
|
||||
}
|
||||
if(m_eglSurface) {
|
||||
eglDestroySurface(m_eglDisplay, m_eglSurface);
|
||||
m_eglSurface = 0;
|
||||
}
|
||||
eglTerminate(m_eglDisplay);
|
||||
m_eglDisplay = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsContextEGL::restore()
|
||||
{
|
||||
if(!eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext))
|
||||
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()
|
||||
{
|
||||
eglSwapBuffers(m_eglDisplay, m_eglSurface);
|
||||
}
|
||||
|
||||
void GraphicsContextEGL::setVerticalSync(bool enable)
|
||||
{
|
||||
eglSwapInterval(m_eglDisplay, enable ? 1 : 0);
|
||||
}
|
52
src/framework/graphics/ogl/graphicscontextegl.h
Normal file
52
src/framework/graphics/ogl/graphicscontextegl.h
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2013 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef GRAPHICSCONTEXTEGL_H
|
||||
#define GRAPHICSCONTEXTEGL_H
|
||||
|
||||
#include <framework/graphics/graphicscontext.h>
|
||||
#include <EGL/egl.h>
|
||||
|
||||
class GraphicsContextEGL : public GraphicsContext
|
||||
{
|
||||
public:
|
||||
GraphicsContextEGL();
|
||||
|
||||
void create();
|
||||
void destroy();
|
||||
void restore();
|
||||
|
||||
bool isExtensionSupported(const char *ext);
|
||||
void *getExtensionProcAddress(const char *ext);
|
||||
|
||||
void swapBuffers();
|
||||
|
||||
void setVerticalSync(bool enable);
|
||||
|
||||
private:
|
||||
EGLConfig m_eglConfig;
|
||||
EGLContext m_eglContext;
|
||||
EGLDisplay m_eglDisplay;
|
||||
EGLSurface m_eglSurface;
|
||||
};
|
||||
|
||||
#endif
|
80
src/framework/graphics/ogl/graphicscontextglx.cpp
Normal file
80
src/framework/graphics/ogl/graphicscontextglx.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2013 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "graphicscontextglx.h"
|
||||
|
||||
GraphicsContextGLX::GraphicsContextGLX() :
|
||||
GraphicsContext("GLX")
|
||||
{
|
||||
m_fbConfig = 0;
|
||||
m_glxContext = 0;
|
||||
}
|
||||
|
||||
void GraphicsContextGLX::create()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GraphicsContextGLX::destroy()
|
||||
{
|
||||
if(m_glxContext) {
|
||||
glXMakeCurrent(m_display, None, NULL);
|
||||
glXDestroyContext(m_display, m_glxContext);
|
||||
m_glxContext = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsContextGLX::restore()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool GraphicsContextGLX::isExtensionSupported(const char *ext)
|
||||
{
|
||||
const char *exts = glXQueryExtensionsString(m_display, m_screen);
|
||||
if(strstr(exts, ext))
|
||||
return true;
|
||||
}
|
||||
|
||||
void *GraphicsContextGLX::getExtensionProcAddress(const char *ext)
|
||||
{
|
||||
return (void *)glXGetProcAddressARB((const GLubyte*)ext);
|
||||
}
|
||||
|
||||
void GraphicsContextGLX::swapBuffers()
|
||||
{
|
||||
glXSwapBuffers(m_display, m_window);
|
||||
}
|
||||
|
||||
void GraphicsContextGLX::setVerticalSync(bool enable)
|
||||
{
|
||||
typedef GLint (*glSwapIntervalProc)(GLint);
|
||||
glSwapIntervalProc glSwapInterval = NULL;
|
||||
|
||||
if(isExtensionSupported("GLX_MESA_swap_control"))
|
||||
glSwapInterval = (glSwapIntervalProc)getExtensionProcAddress("glXSwapIntervalMESA");
|
||||
else if(isExtensionSupported("GLX_SGI_swap_control"))
|
||||
glSwapInterval = (glSwapIntervalProc)getExtensionProcAddress("glXSwapIntervalSGI");
|
||||
|
||||
if(glSwapInterval)
|
||||
glSwapInterval(enable ? 1 : 0);
|
||||
}
|
50
src/framework/graphics/ogl/graphicscontextglx.h
Normal file
50
src/framework/graphics/ogl/graphicscontextglx.h
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2013 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef GRAPHICSCONTEXTGLX_H
|
||||
#define GRAPHICSCONTEXTGLX_H
|
||||
|
||||
#include <framework/graphics/graphicscontext.h>
|
||||
#include <GL/glx.h>
|
||||
|
||||
class GraphicsContextGLX : public GraphicsContext
|
||||
{
|
||||
public:
|
||||
GraphicsContextGLX();
|
||||
|
||||
void create();
|
||||
void destroy();
|
||||
void restore();
|
||||
|
||||
bool isExtensionSupported(const char *ext);
|
||||
void *getExtensionProcAddress(const char *ext);
|
||||
|
||||
void swapBuffers();
|
||||
|
||||
void setVerticalSync(bool enable);
|
||||
|
||||
private:
|
||||
GLXContext m_glxContext;
|
||||
GLXFBConfig *m_fbConfig;
|
||||
};
|
||||
|
||||
#endif
|
125
src/framework/graphics/ogl/graphicscontextwgl.cpp
Normal file
125
src/framework/graphics/ogl/graphicscontextwgl.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2013 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "graphicscontextwgl.h"
|
||||
|
||||
GraphicsContextWGL::GraphicsContextWGL() :
|
||||
GraphicsContext("WGL")
|
||||
{
|
||||
m_deviceContext = 0;
|
||||
m_wglContext = 0;
|
||||
}
|
||||
|
||||
void GraphicsContextWGL::create(WindowType window)
|
||||
{
|
||||
m_deviceContext = GetDC(window);
|
||||
if(!m_deviceContext)
|
||||
g_logger.fatal("GetDC failed");
|
||||
|
||||
uint pixelFormat;
|
||||
static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR),
|
||||
1,
|
||||
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
|
||||
PFD_TYPE_RGBA,
|
||||
32, // Select Our Color Depth
|
||||
8, 0, 8, 0, 8, 0, // Color Bits Ignored
|
||||
8, // Alpha Buffer Bits
|
||||
0, // Shift Bit Ignored
|
||||
0, // No Accumulation Buffer
|
||||
0, 0, 0, 0, // Accumulation Bits Ignored
|
||||
0, // Z-Buffer (Depth Buffer)
|
||||
0, // No Stencil Buffer
|
||||
0, // No Auxiliary Buffer
|
||||
PFD_MAIN_PLANE, // Main Drawing Layer
|
||||
0, // Reserved
|
||||
0, 0, 0 }; // Layer Masks Ignored
|
||||
|
||||
pixelFormat = ChoosePixelFormat(m_deviceContext, &pfd);
|
||||
if(!pixelFormat)
|
||||
g_logger.fatal("Could not find a suitable pixel format");
|
||||
|
||||
if(!SetPixelFormat(m_deviceContext, pixelFormat, &pfd))
|
||||
g_logger.fatal("Could not set the pixel format");
|
||||
|
||||
if(!(m_wglContext = wglCreateContext(m_deviceContext)))
|
||||
g_logger.fatal("Unable to create GL context");
|
||||
}
|
||||
|
||||
void GraphicsContextWGL::destroy(WindowType window)
|
||||
{
|
||||
if(m_wglContext) {
|
||||
if(!wglMakeCurrent(NULL, NULL))
|
||||
g_logger.error("Release of dc and rc failed.");
|
||||
if(!wglDeleteContext(m_wglContext))
|
||||
g_logger.error("Release rendering context failed.");
|
||||
m_wglContext = NULL;
|
||||
}
|
||||
|
||||
if(m_deviceContext) {
|
||||
if(!ReleaseDC(window, m_deviceContext))
|
||||
g_logger.error("Release device context failed.");
|
||||
m_deviceContext = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsContextWGL::restore()
|
||||
{
|
||||
if(!wglMakeCurrent(m_deviceContext, m_wglContext))
|
||||
g_logger.fatal("Unable to make current WGL context");
|
||||
}
|
||||
|
||||
bool GraphicsContextWGL::isExtensionSupported(const char *ext)
|
||||
{
|
||||
typedef const char* (WINAPI * wglGetExtensionsStringProc)();
|
||||
wglGetExtensionsStringProc wglGetExtensionsString = (wglGetExtensionsStringProc)getExtensionProcAddress("wglGetExtensionsStringEXT");
|
||||
if(!wglGetExtensionsString)
|
||||
return false;
|
||||
|
||||
const char *exts = wglGetExtensionsString();
|
||||
if(exts && strstr(exts, ext))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void *GraphicsContextWGL::getExtensionProcAddress(const char *ext)
|
||||
{
|
||||
return (void*)wglGetProcAddress(ext);
|
||||
}
|
||||
|
||||
void GraphicsContextWGL::swapBuffers()
|
||||
{
|
||||
SwapBuffers(m_deviceContext);
|
||||
}
|
||||
|
||||
void GraphicsContextWGL::setVerticalSync(bool enable)
|
||||
{
|
||||
if(!isExtensionSupported("WGL_EXT_swap_control"))
|
||||
return;
|
||||
|
||||
typedef BOOL (WINAPI * wglSwapIntervalProc)(int);
|
||||
wglSwapIntervalProc wglSwapInterval = (wglSwapIntervalProc)getExtensionProcAddress("wglSwapIntervalEXT");
|
||||
if(!wglSwapInterval)
|
||||
return;
|
||||
|
||||
wglSwapInterval(enable ? 1 : 0);
|
||||
}
|
50
src/framework/graphics/ogl/graphicscontextwgl.h
Normal file
50
src/framework/graphics/ogl/graphicscontextwgl.h
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2013 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef GRAPHICSCONTEXTWGL_H
|
||||
#define GRAPHICSCONTEXTWGL_H
|
||||
|
||||
#include <framework/graphics/graphicscontext.h>
|
||||
#include <windows.h>
|
||||
|
||||
class GraphicsContextWGL : public GraphicsContext
|
||||
{
|
||||
public:
|
||||
GraphicsContextWGL();
|
||||
|
||||
void create(WindowType window);
|
||||
void destroy(WindowType window);
|
||||
void restore();
|
||||
|
||||
bool isExtensionSupported(const char *ext);
|
||||
void *getExtensionProcAddress(const char *ext);
|
||||
|
||||
void swapBuffers();
|
||||
|
||||
void setVerticalSync(bool enable);
|
||||
|
||||
private:
|
||||
HDC m_deviceContext;
|
||||
HGLRC m_wglContext;
|
||||
};
|
||||
|
||||
#endif
|
@ -24,8 +24,24 @@
|
||||
#include <framework/graphics/graphics.h>
|
||||
#include <framework/platform/platformwindow.h>
|
||||
|
||||
#ifdef OPENGL_ES
|
||||
#include <framework/graphics/ogl/graphicscontextegl.h>
|
||||
#elif WIN32
|
||||
#include <framework/graphics/ogl/graphicscontextwgl.h>
|
||||
#else
|
||||
#include <framework/graphics/ogl/graphicscontextglx.h>
|
||||
#endif
|
||||
|
||||
PainterOGL::PainterOGL()
|
||||
{
|
||||
#ifdef OPENGL_ES
|
||||
m_graphicsContext = GraphicsContextPtr(new GraphicsContextEGL);
|
||||
#elif WIN32
|
||||
m_graphicsContext = GraphicsContextPtr(new GraphicsContextWGL);
|
||||
#else
|
||||
m_graphicsContext = GraphicsContextPtr(new GraphicsContextGLX);
|
||||
#endif
|
||||
|
||||
m_glTextureId = 0;
|
||||
m_oldStateIndex = 0;
|
||||
m_color = Color::white;
|
||||
@ -35,6 +51,7 @@ PainterOGL::PainterOGL()
|
||||
m_shaderProgram = nullptr;
|
||||
m_texture = nullptr;
|
||||
m_alphaWriting = false;
|
||||
|
||||
setResolution(g_window.getSize());
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include <framework/graphics/declarations.h>
|
||||
#include <framework/graphics/coordsbuffer.h>
|
||||
#include <framework/graphics/graphicscontext.h>
|
||||
#include <framework/graphics/paintershaderprogram.h>
|
||||
#include <framework/graphics/texture.h>
|
||||
|
||||
@ -95,6 +96,7 @@ public:
|
||||
float getOpacity() { return m_opacity; }
|
||||
Rect getClipRect() { return m_clipRect; }
|
||||
CompositionMode getCompositionMode() { return m_compositionMode; }
|
||||
GraphicsContextPtr getGraphicsContext() { return m_graphicsContext; }
|
||||
|
||||
virtual void setCompositionMode(CompositionMode compositionMode) = 0;
|
||||
|
||||
@ -116,6 +118,7 @@ protected:
|
||||
Size m_resolution;
|
||||
float m_opacity;
|
||||
Rect m_clipRect;
|
||||
GraphicsContextPtr m_graphicsContext;
|
||||
};
|
||||
|
||||
extern Painter *g_painter;
|
||||
|
@ -63,6 +63,20 @@ int PlatformWindow::loadMouseCursor(const std::string& file, const Point& hotSpo
|
||||
return internalLoadMouseCursor(image, hotSpot);
|
||||
}
|
||||
|
||||
void PlatformWindow::setGraphicsContext(const GraphicsContextPtr& graphicsContext)
|
||||
{
|
||||
// TODO
|
||||
//if(m_graphicsContext && m_graphicsContext->getName() == graphicsContext->getName())
|
||||
//return;
|
||||
|
||||
if(m_graphicsContext)
|
||||
internalDestroyContext();
|
||||
|
||||
m_graphicsContext = graphicsContext;
|
||||
internalCreateContext();
|
||||
internalRestoreContext();
|
||||
}
|
||||
|
||||
void PlatformWindow::updateUnmaximizedCoords()
|
||||
{
|
||||
if(!isMaximized() && !isFullscreen()) {
|
||||
|
@ -27,12 +27,13 @@
|
||||
#include <framework/core/inputevent.h>
|
||||
#include <framework/core/timer.h>
|
||||
#include <framework/graphics/declarations.h>
|
||||
#include <framework/graphics/graphicscontext.h>
|
||||
|
||||
//@bindsingleton g_window
|
||||
class PlatformWindow
|
||||
{
|
||||
enum {
|
||||
KEY_PRESS_REPEAT_INTERVAL = 30,
|
||||
KEY_PRESS_REPEAT_INTERVAL = 30
|
||||
};
|
||||
|
||||
typedef std::function<void(const Size&)> OnResizeCallback;
|
||||
@ -63,6 +64,7 @@ public:
|
||||
virtual void setVerticalSync(bool enable) = 0;
|
||||
virtual void setIcon(const std::string& iconFile) = 0;
|
||||
virtual void setClipboardText(const std::string& text) = 0;
|
||||
void setGraphicsContext(const GraphicsContextPtr& graphicsContext);
|
||||
|
||||
virtual Size getDisplaySize() = 0;
|
||||
virtual std::string getClipboardText() = 0;
|
||||
@ -95,6 +97,9 @@ public:
|
||||
void setOnInputEvent(const OnInputEventCallback& onInputEvent) { m_onInputEvent = onInputEvent; }
|
||||
|
||||
protected:
|
||||
virtual void internalCreateContext() = 0;
|
||||
virtual void internalDestroyContext() = 0;
|
||||
virtual void internalRestoreContext() = 0;
|
||||
virtual int internalLoadMouseCursor(const ImagePtr& image, const Point& hotSpot) = 0;
|
||||
|
||||
void updateUnmaximizedCoords();
|
||||
@ -127,6 +132,8 @@ protected:
|
||||
std::function<void()> m_onClose;
|
||||
OnResizeCallback m_onResize;
|
||||
OnInputEventCallback m_onInputEvent;
|
||||
|
||||
GraphicsContextPtr m_graphicsContext;
|
||||
};
|
||||
|
||||
extern PlatformWindow& g_window;
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <framework/graphics/image.h>
|
||||
#include <framework/core/application.h>
|
||||
#include <framework/core/resourcemanager.h>
|
||||
#include <framework/graphics/ogl/graphicscontextwgl.h>
|
||||
|
||||
#define HSB_BIT_SET(p, n) (p[(n)/8] |= (128 >>((n)%8)))
|
||||
|
||||
@ -31,20 +32,11 @@ WIN32Window::WIN32Window()
|
||||
{
|
||||
m_window = 0;
|
||||
m_instance = 0;
|
||||
m_deviceContext = 0;
|
||||
m_cursor = 0;
|
||||
m_minimumSize = Size(600,480);
|
||||
m_size = Size(600,480);
|
||||
m_hidden = true;
|
||||
|
||||
#ifdef OPENGL_ES
|
||||
m_eglConfig = 0;
|
||||
m_eglContext = 0;
|
||||
m_eglDisplay = 0;
|
||||
m_eglSurface = 0;
|
||||
#else
|
||||
m_wglContext = 0;
|
||||
#endif
|
||||
m_graphicsContext = GraphicsContextPtr(new GraphicsContextWGL);
|
||||
|
||||
m_keyMap[VK_ESCAPE] = Fw::KeyEscape;
|
||||
m_keyMap[VK_TAB] = Fw::KeyTab;
|
||||
@ -201,30 +193,9 @@ WIN32Window::WIN32Window()
|
||||
void WIN32Window::init()
|
||||
{
|
||||
m_instance = GetModuleHandle(NULL);
|
||||
|
||||
#ifdef DIRECTX
|
||||
m_d3d = Direct3DCreate9(D3D_SDK_VERSION); // create the Direct3D interface
|
||||
|
||||
D3DPRESENT_PARAMETERS d3dpp; // create a struct to hold various device information
|
||||
|
||||
ZeroMemory(&d3dpp, sizeof(d3dpp)); // clear out the struct for use
|
||||
d3dpp.Windowed = TRUE; // program windowed, not fullscreen
|
||||
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // discard old frames
|
||||
d3dpp.hDeviceWindow = m_window; // set the window to be used by Direct3D
|
||||
|
||||
// create a device class using this information and information from the d3dpp stuct
|
||||
m_d3d->CreateDevice(D3DADAPTER_DEFAULT,
|
||||
D3DDEVTYPE_HAL,
|
||||
m_window,
|
||||
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
|
||||
&d3dpp,
|
||||
&m_d3ddev);
|
||||
|
||||
#endif
|
||||
|
||||
internalCreateWindow();
|
||||
internalCreateGLContext();
|
||||
internalRestoreGLContext();
|
||||
internalCreateContext();
|
||||
internalRestoreContext();
|
||||
}
|
||||
|
||||
void WIN32Window::terminate()
|
||||
@ -239,13 +210,7 @@ void WIN32Window::terminate()
|
||||
DestroyCursor(cursor);
|
||||
m_cursors.clear();
|
||||
|
||||
internalDestroyGLContext();
|
||||
|
||||
if(m_deviceContext) {
|
||||
if(!ReleaseDC(m_window, m_deviceContext))
|
||||
g_logger.error("Release device context failed.");
|
||||
m_deviceContext = NULL;
|
||||
}
|
||||
internalDestroyContext();
|
||||
|
||||
if(m_window) {
|
||||
if(!DestroyWindow(m_window))
|
||||
@ -310,158 +275,32 @@ void WIN32Window::internalCreateWindow()
|
||||
g_logger.fatal("Unable to create window");
|
||||
|
||||
ShowWindow(m_window, SW_HIDE);
|
||||
|
||||
m_deviceContext = GetDC(m_window);
|
||||
if(!m_deviceContext)
|
||||
g_logger.fatal("GetDC failed");
|
||||
}
|
||||
|
||||
void WIN32Window::internalCreateGLContext()
|
||||
void WIN32Window::internalCreateContext()
|
||||
{
|
||||
#ifdef OPENGL_ES
|
||||
m_eglDisplay = eglGetDisplay(m_deviceContext);
|
||||
if(m_eglDisplay == EGL_NO_DISPLAY)
|
||||
g_logger.fatal("EGL not supported");
|
||||
|
||||
if(!eglInitialize(m_eglDisplay, NULL, NULL))
|
||||
g_logger.fatal("Unable to initialize EGL");
|
||||
|
||||
static int configList[] = {
|
||||
#if OPENGL_ES==2
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
||||
#else
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
|
||||
#endif
|
||||
EGL_RED_SIZE, 4,
|
||||
EGL_GREEN_SIZE, 4,
|
||||
EGL_BLUE_SIZE, 4,
|
||||
EGL_ALPHA_SIZE, 4,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
EGLint numConfig;
|
||||
|
||||
if(!eglGetConfigs(m_eglDisplay, NULL, 0, &numConfig))
|
||||
g_logger.fatal("No valid GL configurations");
|
||||
|
||||
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");
|
||||
|
||||
EGLint contextAtrrList[] = {
|
||||
#if OPENGL_ES==2
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
#else
|
||||
EGL_CONTEXT_CLIENT_VERSION, 1,
|
||||
#endif
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
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()));
|
||||
|
||||
m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, EGL_NO_CONTEXT, contextAtrrList);
|
||||
if(m_eglContext == EGL_NO_CONTEXT )
|
||||
g_logger.fatal(stdext::format("Unable to create EGL context: %s", eglGetError()));
|
||||
|
||||
#else
|
||||
uint pixelFormat;
|
||||
static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR),
|
||||
1,
|
||||
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
|
||||
PFD_TYPE_RGBA,
|
||||
32, // Select Our Color Depth
|
||||
8, 0, 8, 0, 8, 0, // Color Bits Ignored
|
||||
8, // Alpha Buffer Bits
|
||||
0, // Shift Bit Ignored
|
||||
0, // No Accumulation Buffer
|
||||
0, 0, 0, 0, // Accumulation Bits Ignored
|
||||
0, // Z-Buffer (Depth Buffer)
|
||||
0, // No Stencil Buffer
|
||||
0, // No Auxiliary Buffer
|
||||
PFD_MAIN_PLANE, // Main Drawing Layer
|
||||
0, // Reserved
|
||||
0, 0, 0 }; // Layer Masks Ignored
|
||||
|
||||
pixelFormat = ChoosePixelFormat(m_deviceContext, &pfd);
|
||||
if(!pixelFormat)
|
||||
g_logger.fatal("Could not find a suitable pixel format");
|
||||
|
||||
if(!SetPixelFormat(m_deviceContext, pixelFormat, &pfd))
|
||||
g_logger.fatal("Could not set the pixel format");
|
||||
|
||||
if(!(m_wglContext = wglCreateContext(m_deviceContext)))
|
||||
g_logger.fatal("Unable to create GL context");
|
||||
#endif
|
||||
dump << m_graphicsContext->getName().c_str();
|
||||
m_graphicsContext->create(m_window);
|
||||
}
|
||||
|
||||
void WIN32Window::internalDestroyGLContext()
|
||||
void WIN32Window::internalDestroyContext()
|
||||
{
|
||||
#ifdef OPENGL_ES
|
||||
if(m_eglDisplay) {
|
||||
if(m_eglContext) {
|
||||
eglDestroyContext(m_eglDisplay, m_eglContext);
|
||||
m_eglContext = 0;
|
||||
}
|
||||
if(m_eglSurface) {
|
||||
eglDestroySurface(m_eglDisplay, m_eglSurface);
|
||||
m_eglSurface = 0;
|
||||
}
|
||||
eglTerminate(m_eglDisplay);
|
||||
m_eglDisplay = 0;
|
||||
}
|
||||
#else
|
||||
if(m_wglContext) {
|
||||
if(!wglMakeCurrent(NULL, NULL))
|
||||
g_logger.error("Release of dc and rc failed.");
|
||||
if(!wglDeleteContext(m_wglContext))
|
||||
g_logger.error("Release rendering context failed.");
|
||||
m_wglContext = NULL;
|
||||
}
|
||||
#endif
|
||||
m_graphicsContext->destroy(m_window);
|
||||
}
|
||||
|
||||
void WIN32Window::internalRestoreGLContext()
|
||||
void WIN32Window::internalRestoreContext()
|
||||
{
|
||||
#ifdef OPENGL_ES
|
||||
if(!eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext))
|
||||
g_logger.fatal("Unable to make current EGL context");
|
||||
#else
|
||||
if(!wglMakeCurrent(m_deviceContext, m_wglContext))
|
||||
g_logger.fatal("Unable to make current WGL context");
|
||||
#endif
|
||||
m_graphicsContext->restore();
|
||||
}
|
||||
|
||||
bool WIN32Window::isExtensionSupported(const char *ext)
|
||||
{
|
||||
#ifdef OPENGL_ES
|
||||
//TODO
|
||||
return false;
|
||||
#else
|
||||
typedef const char* (WINAPI * wglGetExtensionsStringProc)();
|
||||
wglGetExtensionsStringProc wglGetExtensionsString = (wglGetExtensionsStringProc)getExtensionProcAddress("wglGetExtensionsStringEXT");
|
||||
if(!wglGetExtensionsString)
|
||||
return false;
|
||||
|
||||
const char *exts = wglGetExtensionsString();
|
||||
if(exts && strstr(exts, ext))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
#endif
|
||||
return m_graphicsContext->isExtensionSupported(ext);
|
||||
}
|
||||
|
||||
void *WIN32Window::getExtensionProcAddress(const char *ext)
|
||||
{
|
||||
#ifdef OPENGL_ES
|
||||
//TODO
|
||||
return NULL;
|
||||
#else
|
||||
return (void*)wglGetProcAddress(ext);
|
||||
#endif
|
||||
return m_graphicsContext->getExtensionProcAddress(ext);
|
||||
}
|
||||
|
||||
void WIN32Window::move(const Point& pos)
|
||||
@ -737,8 +576,8 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
|
||||
break;
|
||||
}
|
||||
|
||||
if(m_visible && m_deviceContext)
|
||||
internalRestoreGLContext();
|
||||
if(m_visible)
|
||||
internalRestoreContext();
|
||||
|
||||
Size size = Size(LOWORD(lParam), HIWORD(lParam));
|
||||
size.setWidth(std::max(std::min(size.width(), 7680), 32));
|
||||
@ -760,11 +599,7 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
|
||||
|
||||
void WIN32Window::swapBuffers()
|
||||
{
|
||||
#ifdef OPENGL_ES
|
||||
eglSwapBuffers(m_eglDisplay, m_eglSurface);
|
||||
#else
|
||||
SwapBuffers(m_deviceContext);
|
||||
#endif
|
||||
m_graphicsContext->swapBuffers();
|
||||
}
|
||||
|
||||
void WIN32Window::showMouse()
|
||||
@ -860,19 +695,7 @@ void WIN32Window::setFullscreen(bool fullscreen)
|
||||
|
||||
void WIN32Window::setVerticalSync(bool enable)
|
||||
{
|
||||
#ifdef OPENGL_ES
|
||||
eglSwapInterval(m_eglDisplay, enable ? 1 : 0);
|
||||
#else
|
||||
if(!isExtensionSupported("WGL_EXT_swap_control"))
|
||||
return;
|
||||
|
||||
typedef BOOL (WINAPI * wglSwapIntervalProc)(int);
|
||||
wglSwapIntervalProc wglSwapInterval = (wglSwapIntervalProc)getExtensionProcAddress("wglSwapIntervalEXT");
|
||||
if(!wglSwapInterval)
|
||||
return;
|
||||
|
||||
wglSwapInterval(enable ? 1 : 0);
|
||||
#endif
|
||||
m_graphicsContext->setVerticalSync(enable);
|
||||
}
|
||||
|
||||
void WIN32Window::setIcon(const std::string& file)
|
||||
@ -965,11 +788,7 @@ std::string WIN32Window::getClipboardText()
|
||||
|
||||
std::string WIN32Window::getPlatformType()
|
||||
{
|
||||
#ifndef OPENGL_ES
|
||||
return "WIN32-WGL";
|
||||
#else
|
||||
return "WIN32-EGL";
|
||||
#endif
|
||||
return stdext::format("WIN32-%s", m_graphicsContext->getName());
|
||||
}
|
||||
|
||||
Rect WIN32Window::getClientRect()
|
||||
|
@ -24,25 +24,16 @@
|
||||
#define WIN32WINDOW_H
|
||||
|
||||
#include "platformwindow.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#ifdef OPENGL_ES
|
||||
#include <EGL/egl.h>
|
||||
#endif
|
||||
|
||||
#ifdef DIRECTX
|
||||
#include <d3d9.h>
|
||||
#endif
|
||||
|
||||
struct WindowProcProxy;
|
||||
|
||||
class WIN32Window : public PlatformWindow
|
||||
{
|
||||
void internalCreateWindow();
|
||||
void internalCreateGLContext();
|
||||
void internalDestroyGLContext();
|
||||
void internalRestoreGLContext();
|
||||
void internalCreateContext();
|
||||
void internalDestroyContext();
|
||||
void internalRestoreContext();
|
||||
|
||||
void *getExtensionProcAddress(const char *ext);
|
||||
bool isExtensionSupported(const char *ext);
|
||||
@ -94,24 +85,9 @@ private:
|
||||
std::vector<HCURSOR> m_cursors;
|
||||
HWND m_window;
|
||||
HINSTANCE m_instance;
|
||||
HDC m_deviceContext;
|
||||
HCURSOR m_cursor;
|
||||
HCURSOR m_defaultCursor;
|
||||
bool m_hidden;
|
||||
|
||||
#ifdef DIRECTX
|
||||
LPDIRECT3D9 m_d3d; // the pointer to our Direct3D interface
|
||||
LPDIRECT3DDEVICE9 m_d3ddev; // the pointer to the device class
|
||||
#endif
|
||||
|
||||
#ifdef OPENGL_ES
|
||||
EGLConfig m_eglConfig;
|
||||
EGLContext m_eglContext;
|
||||
EGLDisplay m_eglDisplay;
|
||||
EGLSurface m_eglSurface;
|
||||
#else
|
||||
HGLRC m_wglContext;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -43,16 +43,6 @@ X11Window::X11Window()
|
||||
m_minimumSize = Size(600,480);
|
||||
m_size = Size(600,480);
|
||||
|
||||
#ifdef OPENGL_ES
|
||||
m_eglConfig = 0;
|
||||
m_eglContext = 0;
|
||||
m_eglDisplay = 0;
|
||||
m_eglSurface = 0;
|
||||
#else
|
||||
m_fbConfig = 0;
|
||||
m_glxContext = 0;
|
||||
#endif
|
||||
|
||||
m_keyMap[XK_Escape] = Fw::KeyEscape;
|
||||
m_keyMap[XK_Tab] = Fw::KeyTab;
|
||||
m_keyMap[XK_Return] = Fw::KeyEnter;
|
||||
@ -460,26 +450,7 @@ void X11Window::internalCreateGLContext()
|
||||
|
||||
void X11Window::internalDestroyGLContext()
|
||||
{
|
||||
#ifdef OPENGL_ES
|
||||
if(m_eglDisplay) {
|
||||
if(m_eglContext) {
|
||||
eglDestroyContext(m_eglDisplay, m_eglContext);
|
||||
m_eglContext = 0;
|
||||
}
|
||||
if(m_eglSurface) {
|
||||
eglDestroySurface(m_eglDisplay, m_eglSurface);
|
||||
m_eglSurface = 0;
|
||||
}
|
||||
eglTerminate(m_eglDisplay);
|
||||
m_eglDisplay = 0;
|
||||
}
|
||||
#else
|
||||
if(m_glxContext) {
|
||||
glXMakeCurrent(m_display, None, NULL);
|
||||
glXDestroyContext(m_display, m_glxContext);
|
||||
m_glxContext = 0;
|
||||
}
|
||||
#endif
|
||||
m_graphicsContext->destroy();
|
||||
}
|
||||
|
||||
void X11Window::internalConnectGLContext()
|
||||
@ -498,25 +469,12 @@ void X11Window::internalConnectGLContext()
|
||||
|
||||
void *X11Window::getExtensionProcAddress(const char *ext)
|
||||
{
|
||||
#ifdef OPENGL_ES
|
||||
//TODO
|
||||
return NULL;
|
||||
#else
|
||||
return (void *)glXGetProcAddressARB((const GLubyte*)ext);
|
||||
#endif
|
||||
return m_graphicsContext->getExtensionProcAddress(ext);
|
||||
}
|
||||
|
||||
bool X11Window::isExtensionSupported(const char *ext)
|
||||
{
|
||||
#ifdef OPENGL_ES
|
||||
//TODO
|
||||
return false;
|
||||
#else
|
||||
const char *exts = glXQueryExtensionsString(m_display, m_screen);
|
||||
if(strstr(exts, ext))
|
||||
return true;
|
||||
#endif
|
||||
return false;
|
||||
return m_graphicsContext->isExtensionSupported(ext);
|
||||
}
|
||||
|
||||
void X11Window::move(const Point& pos)
|
||||
@ -838,11 +796,7 @@ void X11Window::poll()
|
||||
|
||||
void X11Window::swapBuffers()
|
||||
{
|
||||
#ifdef OPENGL_ES
|
||||
eglSwapBuffers(m_eglDisplay, m_eglSurface);
|
||||
#else
|
||||
glXSwapBuffers(m_display, m_window);
|
||||
#endif
|
||||
m_graphicsContext->swapBuffers();
|
||||
}
|
||||
|
||||
void X11Window::showMouse()
|
||||
@ -966,20 +920,7 @@ void X11Window::setFullscreen(bool fullscreen)
|
||||
|
||||
void X11Window::setVerticalSync(bool enable)
|
||||
{
|
||||
#ifdef OPENGL_ES
|
||||
//TODO
|
||||
#else
|
||||
typedef GLint (*glSwapIntervalProc)(GLint);
|
||||
glSwapIntervalProc glSwapInterval = NULL;
|
||||
|
||||
if(isExtensionSupported("GLX_MESA_swap_control"))
|
||||
glSwapInterval = (glSwapIntervalProc)getExtensionProcAddress("glXSwapIntervalMESA");
|
||||
else if(isExtensionSupported("GLX_SGI_swap_control"))
|
||||
glSwapInterval = (glSwapIntervalProc)getExtensionProcAddress("glXSwapIntervalSGI");
|
||||
|
||||
if(glSwapInterval)
|
||||
glSwapInterval(enable ? 1 : 0);
|
||||
#endif
|
||||
m_graphicsContext->setVerticalSync(enable);
|
||||
}
|
||||
|
||||
void X11Window::setIcon(const std::string& file)
|
||||
@ -1067,9 +1008,5 @@ std::string X11Window::getClipboardText()
|
||||
|
||||
std::string X11Window::getPlatformType()
|
||||
{
|
||||
#ifndef OPENGL_ES
|
||||
return "X11-GLX";
|
||||
#else
|
||||
return "X11-EGL";
|
||||
#endif
|
||||
return stdext::format("X11-%s", m_graphicsContext->getName());
|
||||
}
|
||||
|
@ -29,11 +29,7 @@
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xatom.h>
|
||||
|
||||
#ifdef OPENGL_ES
|
||||
#include <EGL/egl.h>
|
||||
#else
|
||||
#include <GL/glx.h>
|
||||
#endif
|
||||
typedef Window WindowType;
|
||||
|
||||
class X11Window : public PlatformWindow
|
||||
{
|
||||
@ -97,16 +93,6 @@ private:
|
||||
int m_screen;
|
||||
Atom m_wmDelete;
|
||||
std::string m_clipboardText;
|
||||
|
||||
#ifndef OPENGL_ES
|
||||
GLXContext m_glxContext;
|
||||
GLXFBConfig *m_fbConfig;
|
||||
#else
|
||||
EGLConfig m_eglConfig;
|
||||
EGLContext m_eglContext;
|
||||
EGLDisplay m_eglDisplay;
|
||||
EGLSurface m_eglSurface;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user