diff --git a/.gitignore b/.gitignore index 92e76fa18..5d64539e6 100644 --- a/.gitignore +++ b/.gitignore @@ -162,3 +162,5 @@ DocProject/Help/*.hhk DocProject/Help/*.hhp DocProject/Help/Html2 DocProject/Help/html + +build/gmake/ diff --git a/SDK/src/NDK/Lua/LuaBinding_Platform.cpp b/SDK/src/NDK/Lua/LuaBinding_Platform.cpp index 2a2b02e7e..ac16f6fb3 100644 --- a/SDK/src/NDK/Lua/LuaBinding_Platform.cpp +++ b/SDK/src/NDK/Lua/LuaBinding_Platform.cpp @@ -33,7 +33,7 @@ namespace Ndk keyboard.PushGlobalTable(state); { - static_assert(Nz::Keyboard::Count == 121, "Nz::Keyboard::Key has been updated but change was not reflected to Lua binding"); + static_assert(Nz::Keyboard::Count == 124, "Nz::Keyboard::Key has been updated but change was not reflected to Lua binding"); state.PushField("Undefined", Nz::Keyboard::Undefined); @@ -63,6 +63,7 @@ namespace Ndk state.PushField("Divide", Nz::Keyboard::Divide); state.PushField("Multiply", Nz::Keyboard::Multiply); state.PushField("Subtract", Nz::Keyboard::Subtract); + state.PushField("NumpadReturn", Nz::Keyboard::NumpadReturn); state.PushField("Backslash", Nz::Keyboard::Backslash); state.PushField("Backspace", Nz::Keyboard::Backspace); @@ -98,6 +99,8 @@ namespace Ndk state.PushField("Space", Nz::Keyboard::Space); state.PushField("Tab", Nz::Keyboard::Tab); state.PushField("Tilde", Nz::Keyboard::Tilde); + state.PushField("Menu", Nz::Keyboard::Menu); + state.PushField("ISOBackslash102", Nz::Keyboard::ISOBackslash102); state.PushField("Browser_Back", Nz::Keyboard::Browser_Back); state.PushField("Browser_Favorites", Nz::Keyboard::Browser_Favorites); state.PushField("Browser_Forward", Nz::Keyboard::Browser_Forward); diff --git a/build/config.lua b/build/config.lua index 571bf6dc9..a1f4546eb 100644 --- a/build/config.lua +++ b/build/config.lua @@ -24,3 +24,6 @@ ServerMode = false -- Builds modules as one united library (useless on POSIX systems) UniteModules = false + +-- Use SDL2 platform +PlatformSDL2 = true \ No newline at end of file diff --git a/build/scripts/common.lua b/build/scripts/common.lua index f5f50a9f8..a50fc5c27 100644 --- a/build/scripts/common.lua +++ b/build/scripts/common.lua @@ -387,6 +387,7 @@ function NazaraBuild:Initialize() if (f) then MODULE = {} self:SetupModuleTable(MODULE) + Config = self.Config f() @@ -529,6 +530,7 @@ function NazaraBuild:LoadConfig() AddBoolOption("PremakeProject", "premakeproject", "Add a PremakeProject as a shortcut to call Premake") AddBoolOption("ServerMode", "server", "Excludes client-only modules/tools/examples") AddBoolOption("UniteModules", "united", "Builds all the modules as one united library") + AddBoolOption("PlatformSDL2", "platform-sdl2", "Use SDL2 instead of native APIs") -- AdditionalCompilationOptions do diff --git a/build/scripts/modules/platform.lua b/build/scripts/modules/platform.lua index ad013c306..2768d1a28 100644 --- a/build/scripts/modules/platform.lua +++ b/build/scripts/modules/platform.lua @@ -7,27 +7,41 @@ MODULE.Libraries = { "NazaraUtility" } -MODULE.OsFiles.Windows = { - "../src/Nazara/Platform/Win32/**.hpp", - "../src/Nazara/Platform/Win32/**.cpp" -} +if Config.PlatformSDL2 then + table.insert(MODULE.Defines, "NAZARA_PLATFORM_SDL2") -MODULE.OsFiles.Posix = { - "../src/Nazara/Platform/X11/**.hpp", - "../src/Nazara/Platform/X11/**.cpp" -} + table.insert(MODULE.Files, "../src/Nazara/Platform/SDL2/**.hpp") + table.insert(MODULE.Files, "../src/Nazara/Platform/SDL2/**.cpp") -MODULE.OsLibraries.Windows = { - "gdi32" -} + table.insert(MODULE.Libraries, "SDL2") -MODULE.OsLibraries.Posix = { - "X11", - "xcb", - "xcb-cursor", - "xcb-ewmh", - "xcb-icccm", - "xcb-keysyms", - "xcb-randr" -} + MODULE.FilesExcluded = { + "../src/Nazara/Platform/Win32/**", + "../src/Nazara/Platform/X11/**" + } +else + MODULE.OsFiles.Windows = { + "../src/Nazara/Platform/Win32/**.hpp", + "../src/Nazara/Platform/Win32/**.cpp" + } + MODULE.OsFiles.Posix = { + "../src/Nazara/Platform/X11/**.hpp", + "../src/Nazara/Platform/X11/**.cpp" + } + + MODULE.OsLibraries.Windows = { + "gdi32" + } + + MODULE.OsLibraries.Posix = { + "X11", + "xcb", + "xcb-cursor", + "xcb-ewmh", + "xcb-icccm", + "xcb-keysyms", + "xcb-randr" + } + +end diff --git a/build/scripts/modules/renderer.lua b/build/scripts/modules/renderer.lua index 11b378d2b..800ca33b7 100644 --- a/build/scripts/modules/renderer.lua +++ b/build/scripts/modules/renderer.lua @@ -12,23 +12,35 @@ MODULE.Libraries = { "NazaraPlatform" } -MODULE.OsFiles.Windows = { - "../src/Nazara/Renderer/Win32/**.hpp", - "../src/Nazara/Renderer/Win32/**.cpp" -} +if Config.PlatformSDL2 then + table.insert(MODULE.Defines, "NAZARA_PLATFORM_SDL2") -MODULE.OsFiles.Posix = { - "../src/Nazara/Renderer/GLX/**.hpp", - "../src/Nazara/Renderer/GLX/**.cpp" -} + table.insert(MODULE.Files, "../src/Nazara/Renderer/SDL2/**.hpp") + table.insert(MODULE.Files, "../src/Nazara/Renderer/SDL2/**.cpp") -MODULE.OsLibraries.Windows = { - "gdi32", - "opengl32", - "winmm" -} + MODULE.FilesExcluded = { + "../src/Nazara/Renderer/Win32/**", + "../src/Nazara/Renderer/GLX/**.cpp" + } +else + MODULE.OsFiles.Windows = { + "../src/Nazara/Renderer/Win32/**.hpp", + "../src/Nazara/Renderer/Win32/**.cpp" + } -MODULE.OsLibraries.Posix = { - "GL", - "X11" -} + MODULE.OsFiles.Posix = { + "../src/Nazara/Renderer/GLX/**.hpp", + "../src/Nazara/Renderer/GLX/**.cpp" + } + + MODULE.OsLibraries.Windows = { + "gdi32", + "opengl32", + "winmm" + } + + MODULE.OsLibraries.Posix = { + "GL", + "X11" + } +end \ No newline at end of file diff --git a/examples/FirstScene/build.lua b/examples/FirstScene/build.lua index 612965b5a..aba72ac5b 100644 --- a/examples/FirstScene/build.lua +++ b/examples/FirstScene/build.lua @@ -9,3 +9,7 @@ EXAMPLE.Files = { EXAMPLE.Libraries = { "NazaraSDK" } + +if Config.PlatformSDL2 then + table.insert(EXAMPLE.Defines, "NAZARA_PLATFORM_SDL2") +end diff --git a/examples/HardwareInfo/build.lua b/examples/HardwareInfo/build.lua index 953cba7d9..c0917e765 100644 --- a/examples/HardwareInfo/build.lua +++ b/examples/HardwareInfo/build.lua @@ -16,3 +16,7 @@ EXAMPLE.Libraries = { "NazaraRenderer", "NazaraUtility" } + +if Config.PlatformSDL2 then + table.insert(EXAMPLE.Defines, "NAZARA_PLATFORM_SDL2") +end diff --git a/examples/MeshInfos/build.lua b/examples/MeshInfos/build.lua index 74616762e..462533740 100644 --- a/examples/MeshInfos/build.lua +++ b/examples/MeshInfos/build.lua @@ -12,3 +12,6 @@ EXAMPLE.Libraries = { "NazaraUtility" } +if Config.PlatformSDL2 then + table.insert(EXAMPLE.Defines, "NAZARA_PLATFORM_SDL2") +end diff --git a/examples/Particles/build.lua b/examples/Particles/build.lua index 2e1a37801..678a172d4 100644 --- a/examples/Particles/build.lua +++ b/examples/Particles/build.lua @@ -11,3 +11,7 @@ EXAMPLE.Files = { EXAMPLE.Libraries = { "NazaraSDK" } + +if Config.PlatformSDL2 then + table.insert(EXAMPLE.Defines, "NAZARA_PLATFORM_SDL2") +end diff --git a/examples/Tut00/build.lua b/examples/Tut00/build.lua index baf738d1d..bdb125ab1 100644 --- a/examples/Tut00/build.lua +++ b/examples/Tut00/build.lua @@ -20,3 +20,7 @@ EXAMPLE.Libraries = { "NazaraUtility", "NazaraSDK" } + +if Config.PlatformSDL2 then + table.insert(EXAMPLE.Defines, "NAZARA_PLATFORM_SDL2") +end diff --git a/examples/Tut01/build.lua b/examples/Tut01/build.lua index c195cbc1b..6084317f9 100644 --- a/examples/Tut01/build.lua +++ b/examples/Tut01/build.lua @@ -9,3 +9,7 @@ EXAMPLE.Files = { EXAMPLE.Libraries = { "NazaraSDK" } + +if Config.PlatformSDL2 then + table.insert(EXAMPLE.Defines, "NAZARA_PLATFORM_SDL2") +end diff --git a/examples/Tut02/build.lua b/examples/Tut02/build.lua index dbb8a8c9f..4ee3cd467 100644 --- a/examples/Tut02/build.lua +++ b/examples/Tut02/build.lua @@ -9,3 +9,7 @@ EXAMPLE.Files = { EXAMPLE.Libraries = { "NazaraSDK" } + +if Config.PlatformSDL2 then + table.insert(EXAMPLE.Defines, "NAZARA_PLATFORM_SDL2") +end diff --git a/include/Nazara/Platform/Keyboard.hpp b/include/Nazara/Platform/Keyboard.hpp index 24c5c4b4b..c3ec5ac19 100644 --- a/include/Nazara/Platform/Keyboard.hpp +++ b/include/Nazara/Platform/Keyboard.hpp @@ -78,6 +78,7 @@ namespace Nz Decimal, Divide, Multiply, + NumpadReturn, Numpad0, Numpad1, Numpad2, @@ -135,6 +136,8 @@ namespace Nz Space, Tab, Tilde, + Menu, + ISOBackslash102, // Navigator keys Browser_Back, diff --git a/include/Nazara/Platform/VideoMode.hpp b/include/Nazara/Platform/VideoMode.hpp index 663e5721b..55e30af50 100644 --- a/include/Nazara/Platform/VideoMode.hpp +++ b/include/Nazara/Platform/VideoMode.hpp @@ -32,12 +32,12 @@ namespace Nz static const std::vector& GetFullscreenModes(); }; - bool operator==(const VideoMode& left, const VideoMode& right); - bool operator!=(const VideoMode& left, const VideoMode& right); - bool operator<(const VideoMode& left, const VideoMode& right); - bool operator<=(const VideoMode& left, const VideoMode& right); - bool operator>(const VideoMode& left, const VideoMode& right); - bool operator>=(const VideoMode& left, const VideoMode& right); + bool NAZARA_PLATFORM_API operator==(const VideoMode& left, const VideoMode& right); + bool NAZARA_PLATFORM_API operator!=(const VideoMode& left, const VideoMode& right); + bool NAZARA_PLATFORM_API operator<(const VideoMode& left, const VideoMode& right); + bool NAZARA_PLATFORM_API operator<=(const VideoMode& left, const VideoMode& right); + bool NAZARA_PLATFORM_API operator>(const VideoMode& left, const VideoMode& right); + bool NAZARA_PLATFORM_API operator>=(const VideoMode& left, const VideoMode& right); } #endif // NAZARA_VIDEOMODE_HPP diff --git a/include/Nazara/Platform/WindowHandle.hpp b/include/Nazara/Platform/WindowHandle.hpp index 88274f3f9..b220151f7 100644 --- a/include/Nazara/Platform/WindowHandle.hpp +++ b/include/Nazara/Platform/WindowHandle.hpp @@ -8,13 +8,17 @@ #define NAZARA_WINDOWHANDLE_HPP #include -#if defined(NAZARA_PLATFORM_X11) +#if defined(NAZARA_PLATFORM_SDL2) +#elif defined(NAZARA_PLATFORM_X11) #include #endif namespace Nz { - #if defined(NAZARA_PLATFORM_WINDOWS) + #if defined(NAZARA_PLATFORM_SDL2) + // Real type is SDL_Window + using WindowHandle = void*; + #elif defined(NAZARA_PLATFORM_WINDOWS) // http://msdn.microsoft.com/en-us/library/aa383751(v=vs.85).aspx using WindowHandle = void*; #elif defined(NAZARA_PLATFORM_X11) diff --git a/include/Nazara/Prerequisites.hpp b/include/Nazara/Prerequisites.hpp index ddb2796fc..adbe4aa9c 100644 --- a/include/Nazara/Prerequisites.hpp +++ b/include/Nazara/Prerequisites.hpp @@ -117,16 +117,19 @@ #endif #elif defined(__linux__) || defined(__unix__) #define NAZARA_PLATFORM_LINUX - #define NAZARA_PLATFORM_GLX #define NAZARA_PLATFORM_POSIX - #define NAZARA_PLATFORM_X11 + + #ifndef NAZARA_PLATFORM_SDL2 + #define NAZARA_PLATFORM_GLX + #define NAZARA_PLATFORM_X11 + #endif #define NAZARA_EXPORT __attribute__((visibility ("default"))) #define NAZARA_IMPORT __attribute__((visibility ("default"))) /*#elif defined(__APPLE__) && defined(__MACH__) - #define NAZARA_CORE_API - #define NAZARA_PLATFORM_MACOSX - #define NAZARA_PLATFORM_POSIX*/ + #define NAZARA_CORE_API + #define NAZARA_PLATFORM_MACOSX + #define NAZARA_PLATFORM_POSIX*/ #else #error This operating system is not fully supported by the Nazara Engine diff --git a/include/Nazara/Renderer/OpenGL.hpp b/include/Nazara/Renderer/OpenGL.hpp index 77fe10ad3..35a851d00 100644 --- a/include/Nazara/Renderer/OpenGL.hpp +++ b/include/Nazara/Renderer/OpenGL.hpp @@ -6,12 +6,14 @@ #ifndef NAZARA_OPENGL_HPP #define NAZARA_OPENGL_HPP - +#ifndef NAZARA_RENDERER_OPENGL +#define NAZARA_RENDERER_OPENGL +#endif #ifdef NAZARA_RENDERER_OPENGL -#include #include #include +#include #include #include #include @@ -21,7 +23,9 @@ #include #include -#if defined(NAZARA_PLATFORM_WINDOWS) +#if defined(NAZARA_PLATFORM_SDL2) + #include +#elif defined(NAZARA_PLATFORM_WINDOWS) #include #elif defined(NAZARA_PLATFORM_GLX) namespace GLX @@ -129,223 +133,226 @@ namespace Nz static void Uninitialize(); - static GLenum Attachment[AttachmentPoint_Max+1]; - static GLenum BlendFunc[BlendFunc_Max+1]; - static GLenum BufferLock[BufferAccess_Max+1]; - static GLenum BufferLockRange[BufferAccess_Max+1]; - static GLenum BufferTarget[BufferType_Max+1]; - static GLenum BufferTargetBinding[BufferType_Max+1]; - static GLenum ComponentType[ComponentType_Max+1]; + static GLenum Attachment[AttachmentPoint_Max + 1]; + static GLenum BlendFunc[BlendFunc_Max + 1]; + static GLenum BufferLock[BufferAccess_Max + 1]; + static GLenum BufferLockRange[BufferAccess_Max + 1]; + static GLenum BufferTarget[BufferType_Max + 1]; + static GLenum BufferTargetBinding[BufferType_Max + 1]; + static GLenum ComponentType[ComponentType_Max + 1]; static GLenum CubemapFace[6]; // Un cube possède six faces et ça n'est pas près de changer - static GLenum FaceFilling[FaceFilling_Max+1]; - static GLenum FaceSide[FaceSide_Max+1]; - static GLenum PrimitiveMode[PrimitiveMode_Max+1]; - static GLenum QueryCondition[GpuQueryCondition_Max+1]; - static GLenum QueryMode[GpuQueryMode_Max+1]; - static GLenum RendererComparison[RendererComparison_Max+1]; - static GLenum RendererParameter[RendererParameter_Max+1]; - static GLenum SamplerWrapMode[SamplerWrap_Max+1]; - static GLenum ShaderStage[ShaderStageType_Max+1]; - static GLenum StencilOperation[StencilOperation_Max+1]; - static GLenum TextureTarget[ImageType_Max+1]; - static GLenum TextureTargetBinding[ImageType_Max+1]; - static GLenum TextureTargetProxy[ImageType_Max+1]; - static UInt8 VertexComponentIndex[VertexComponent_Max+1]; + static GLenum FaceFilling[FaceFilling_Max + 1]; + static GLenum FaceSide[FaceSide_Max + 1]; + static GLenum PrimitiveMode[PrimitiveMode_Max + 1]; + static GLenum QueryCondition[GpuQueryCondition_Max + 1]; + static GLenum QueryMode[GpuQueryMode_Max + 1]; + static GLenum RendererComparison[RendererComparison_Max + 1]; + static GLenum RendererParameter[RendererParameter_Max + 1]; + static GLenum SamplerWrapMode[SamplerWrap_Max + 1]; + static GLenum ShaderStage[ShaderStageType_Max + 1]; + static GLenum StencilOperation[StencilOperation_Max + 1]; + static GLenum TextureTarget[ImageType_Max + 1]; + static GLenum TextureTargetBinding[ImageType_Max + 1]; + static GLenum TextureTargetProxy[ImageType_Max + 1]; + static UInt8 VertexComponentIndex[VertexComponent_Max + 1]; private: static void OnContextChanged(const Context* newContext); static void OnContextDestruction(const Context* context); }; -NAZARA_RENDERER_API extern PFNGLACTIVETEXTUREPROC glActiveTexture; -NAZARA_RENDERER_API extern PFNGLATTACHSHADERPROC glAttachShader; -NAZARA_RENDERER_API extern PFNGLBEGINCONDITIONALRENDERPROC glBeginConditionalRender; -NAZARA_RENDERER_API extern PFNGLBEGINQUERYPROC glBeginQuery; -NAZARA_RENDERER_API extern PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation; -NAZARA_RENDERER_API extern PFNGLBINDBUFFERPROC glBindBuffer; -NAZARA_RENDERER_API extern PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer; -NAZARA_RENDERER_API extern PFNGLBINDFRAGDATALOCATIONPROC glBindFragDataLocation; -NAZARA_RENDERER_API extern PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer; -NAZARA_RENDERER_API extern PFNGLBINDSAMPLERPROC glBindSampler; -NAZARA_RENDERER_API extern PFNGLBINDTEXTUREPROC glBindTexture; -NAZARA_RENDERER_API extern PFNGLBINDVERTEXARRAYPROC glBindVertexArray; -NAZARA_RENDERER_API extern PFNGLBLENDFUNCPROC glBlendFunc; -NAZARA_RENDERER_API extern PFNGLBLENDFUNCSEPARATEPROC glBlendFuncSeparate; -NAZARA_RENDERER_API extern PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer; -NAZARA_RENDERER_API extern PFNGLBUFFERDATAPROC glBufferData; -NAZARA_RENDERER_API extern PFNGLBUFFERSUBDATAPROC glBufferSubData; -NAZARA_RENDERER_API extern PFNGLCLEARPROC glClear; -NAZARA_RENDERER_API extern PFNGLCLEARCOLORPROC glClearColor; -NAZARA_RENDERER_API extern PFNGLCLEARDEPTHPROC glClearDepth; -NAZARA_RENDERER_API extern PFNGLCLEARSTENCILPROC glClearStencil; -NAZARA_RENDERER_API extern PFNGLCREATEPROGRAMPROC glCreateProgram; -NAZARA_RENDERER_API extern PFNGLCREATESHADERPROC glCreateShader; -NAZARA_RENDERER_API extern PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus; -NAZARA_RENDERER_API extern PFNGLCOLORMASKPROC glColorMask; -NAZARA_RENDERER_API extern PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC glCompressedTexSubImage1D; -NAZARA_RENDERER_API extern PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC glCompressedTexSubImage2D; -NAZARA_RENDERER_API extern PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC glCompressedTexSubImage3D; -NAZARA_RENDERER_API extern PFNGLCULLFACEPROC glCullFace; -NAZARA_RENDERER_API extern PFNGLCOMPILESHADERPROC glCompileShader; -NAZARA_RENDERER_API extern PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D; -NAZARA_RENDERER_API extern PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback; -NAZARA_RENDERER_API extern PFNGLDEBUGMESSAGECONTROLPROC glDebugMessageControl; -NAZARA_RENDERER_API extern PFNGLDEBUGMESSAGEINSERTPROC glDebugMessageInsert; -NAZARA_RENDERER_API extern PFNGLDELETEBUFFERSPROC glDeleteBuffers; -NAZARA_RENDERER_API extern PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers; -NAZARA_RENDERER_API extern PFNGLDELETEPROGRAMPROC glDeleteProgram; -NAZARA_RENDERER_API extern PFNGLDELETEQUERIESPROC glDeleteQueries; -NAZARA_RENDERER_API extern PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers; -NAZARA_RENDERER_API extern PFNGLDELETESAMPLERSPROC glDeleteSamplers; -NAZARA_RENDERER_API extern PFNGLDELETESHADERPROC glDeleteShader; -NAZARA_RENDERER_API extern PFNGLDELETETEXTURESPROC glDeleteTextures; -NAZARA_RENDERER_API extern PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays; -NAZARA_RENDERER_API extern PFNGLDEPTHFUNCPROC glDepthFunc; -NAZARA_RENDERER_API extern PFNGLDEPTHMASKPROC glDepthMask; -NAZARA_RENDERER_API extern PFNGLDISABLEPROC glDisable; -NAZARA_RENDERER_API extern PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray; -NAZARA_RENDERER_API extern PFNGLDRAWARRAYSPROC glDrawArrays; -NAZARA_RENDERER_API extern PFNGLDRAWARRAYSINSTANCEDPROC glDrawArraysInstanced; -NAZARA_RENDERER_API extern PFNGLDRAWBUFFERPROC glDrawBuffer; -NAZARA_RENDERER_API extern PFNGLDRAWBUFFERSPROC glDrawBuffers; -NAZARA_RENDERER_API extern PFNGLDRAWELEMENTSPROC glDrawElements; -NAZARA_RENDERER_API extern PFNGLDRAWELEMENTSINSTANCEDPROC glDrawElementsInstanced; -NAZARA_RENDERER_API extern PFNGLDRAWTEXTURENVPROC glDrawTexture; -NAZARA_RENDERER_API extern PFNGLENABLEPROC glEnable; -NAZARA_RENDERER_API extern PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray; -NAZARA_RENDERER_API extern PFNGLENDCONDITIONALRENDERPROC glEndConditionalRender; -NAZARA_RENDERER_API extern PFNGLENDQUERYPROC glEndQuery; -NAZARA_RENDERER_API extern PFNGLFLUSHPROC glFlush; -NAZARA_RENDERER_API extern PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer; -NAZARA_RENDERER_API extern PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture; -NAZARA_RENDERER_API extern PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D; -NAZARA_RENDERER_API extern PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D; -NAZARA_RENDERER_API extern PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D; -NAZARA_RENDERER_API extern PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer; -NAZARA_RENDERER_API extern PFNGLGENERATEMIPMAPPROC glGenerateMipmap; -NAZARA_RENDERER_API extern PFNGLGENBUFFERSPROC glGenBuffers; -NAZARA_RENDERER_API extern PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers; -NAZARA_RENDERER_API extern PFNGLGENQUERIESPROC glGenQueries; -NAZARA_RENDERER_API extern PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers; -NAZARA_RENDERER_API extern PFNGLGENSAMPLERSPROC glGenSamplers; -NAZARA_RENDERER_API extern PFNGLGENTEXTURESPROC glGenTextures; -NAZARA_RENDERER_API extern PFNGLGENVERTEXARRAYSPROC glGenVertexArrays; -NAZARA_RENDERER_API extern PFNGLGETACTIVEUNIFORMPROC glGetActiveUniform; -NAZARA_RENDERER_API extern PFNGLGETBOOLEANVPROC glGetBooleanv; -NAZARA_RENDERER_API extern PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv; -NAZARA_RENDERER_API extern PFNGLGETDEBUGMESSAGELOGPROC glGetDebugMessageLog; -NAZARA_RENDERER_API extern PFNGLGETERRORPROC glGetError; -NAZARA_RENDERER_API extern PFNGLGETFLOATVPROC glGetFloatv; -NAZARA_RENDERER_API extern PFNGLGETINTEGERVPROC glGetIntegerv; -NAZARA_RENDERER_API extern PFNGLGETPROGRAMBINARYPROC glGetProgramBinary; -NAZARA_RENDERER_API extern PFNGLGETPROGRAMIVPROC glGetProgramiv; -NAZARA_RENDERER_API extern PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog; -NAZARA_RENDERER_API extern PFNGLGETQUERYIVPROC glGetQueryiv; -NAZARA_RENDERER_API extern PFNGLGETQUERYOBJECTIVPROC glGetQueryObjectiv; -NAZARA_RENDERER_API extern PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv; -NAZARA_RENDERER_API extern PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog; -NAZARA_RENDERER_API extern PFNGLGETSHADERIVPROC glGetShaderiv; -NAZARA_RENDERER_API extern PFNGLGETSHADERSOURCEPROC glGetShaderSource; -NAZARA_RENDERER_API extern PFNGLGETSTRINGPROC glGetString; -NAZARA_RENDERER_API extern PFNGLGETSTRINGIPROC glGetStringi; -NAZARA_RENDERER_API extern PFNGLGETTEXIMAGEPROC glGetTexImage; -NAZARA_RENDERER_API extern PFNGLGETTEXLEVELPARAMETERFVPROC glGetTexLevelParameterfv; -NAZARA_RENDERER_API extern PFNGLGETTEXLEVELPARAMETERIVPROC glGetTexLevelParameteriv; -NAZARA_RENDERER_API extern PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv; -NAZARA_RENDERER_API extern PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv; -NAZARA_RENDERER_API extern PFNGLGETUNIFORMFVPROC glGetUniformfv; -NAZARA_RENDERER_API extern PFNGLGETUNIFORMIVPROC glGetUniformiv; -NAZARA_RENDERER_API extern PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation; -NAZARA_RENDERER_API extern PFNGLINVALIDATEBUFFERDATAPROC glInvalidateBufferData; -NAZARA_RENDERER_API extern PFNGLISENABLEDPROC glIsEnabled; -NAZARA_RENDERER_API extern PFNGLLINEWIDTHPROC glLineWidth; -NAZARA_RENDERER_API extern PFNGLLINKPROGRAMPROC glLinkProgram; -NAZARA_RENDERER_API extern PFNGLMAPBUFFERPROC glMapBuffer; -NAZARA_RENDERER_API extern PFNGLMAPBUFFERRANGEPROC glMapBufferRange; -NAZARA_RENDERER_API extern PFNGLPIXELSTOREIPROC glPixelStorei; -NAZARA_RENDERER_API extern PFNGLPOINTSIZEPROC glPointSize; -NAZARA_RENDERER_API extern PFNGLPOLYGONMODEPROC glPolygonMode; -NAZARA_RENDERER_API extern PFNGLPROGRAMBINARYPROC glProgramBinary; -NAZARA_RENDERER_API extern PFNGLPROGRAMPARAMETERIPROC glProgramParameteri; -NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM1DPROC glProgramUniform1d; -NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM1FPROC glProgramUniform1f; -NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM1IPROC glProgramUniform1i; -NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM1DVPROC glProgramUniform1dv; -NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM1FVPROC glProgramUniform1fv; -NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM1IVPROC glProgramUniform1iv; -NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM2DVPROC glProgramUniform2dv; -NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM2FVPROC glProgramUniform2fv; -NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM2IVPROC glProgramUniform2iv; -NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM3DVPROC glProgramUniform3dv; -NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM3FVPROC glProgramUniform3fv; -NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM3IVPROC glProgramUniform3iv; -NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM4DVPROC glProgramUniform4dv; -NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM4FVPROC glProgramUniform4fv; -NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM4IVPROC glProgramUniform4iv; -NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORMMATRIX4DVPROC glProgramUniformMatrix4dv; -NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORMMATRIX4FVPROC glProgramUniformMatrix4fv; -NAZARA_RENDERER_API extern PFNGLREADPIXELSPROC glReadPixels; -NAZARA_RENDERER_API extern PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage; -NAZARA_RENDERER_API extern PFNGLSAMPLERPARAMETERFPROC glSamplerParameterf; -NAZARA_RENDERER_API extern PFNGLSAMPLERPARAMETERIPROC glSamplerParameteri; -NAZARA_RENDERER_API extern PFNGLSCISSORPROC glScissor; -NAZARA_RENDERER_API extern PFNGLSHADERSOURCEPROC glShaderSource; -NAZARA_RENDERER_API extern PFNGLSTENCILFUNCPROC glStencilFunc; -NAZARA_RENDERER_API extern PFNGLSTENCILFUNCSEPARATEPROC glStencilFuncSeparate; -NAZARA_RENDERER_API extern PFNGLSTENCILOPPROC glStencilOp; -NAZARA_RENDERER_API extern PFNGLSTENCILOPSEPARATEPROC glStencilOpSeparate; -NAZARA_RENDERER_API extern PFNGLTEXIMAGE1DPROC glTexImage1D; -NAZARA_RENDERER_API extern PFNGLTEXIMAGE2DPROC glTexImage2D; -NAZARA_RENDERER_API extern PFNGLTEXIMAGE3DPROC glTexImage3D; -NAZARA_RENDERER_API extern PFNGLTEXPARAMETERFPROC glTexParameterf; -NAZARA_RENDERER_API extern PFNGLTEXPARAMETERIPROC glTexParameteri; -NAZARA_RENDERER_API extern PFNGLTEXSTORAGE1DPROC glTexStorage1D; -NAZARA_RENDERER_API extern PFNGLTEXSTORAGE2DPROC glTexStorage2D; -NAZARA_RENDERER_API extern PFNGLTEXSTORAGE3DPROC glTexStorage3D; -NAZARA_RENDERER_API extern PFNGLTEXSUBIMAGE1DPROC glTexSubImage1D; -NAZARA_RENDERER_API extern PFNGLTEXSUBIMAGE2DPROC glTexSubImage2D; -NAZARA_RENDERER_API extern PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D; -NAZARA_RENDERER_API extern PFNGLUNIFORM1DPROC glUniform1d; -NAZARA_RENDERER_API extern PFNGLUNIFORM1FPROC glUniform1f; -NAZARA_RENDERER_API extern PFNGLUNIFORM1IPROC glUniform1i; -NAZARA_RENDERER_API extern PFNGLUNIFORM1DVPROC glUniform1dv; -NAZARA_RENDERER_API extern PFNGLUNIFORM1FVPROC glUniform1fv; -NAZARA_RENDERER_API extern PFNGLUNIFORM1IVPROC glUniform1iv; -NAZARA_RENDERER_API extern PFNGLUNIFORM2DVPROC glUniform2dv; -NAZARA_RENDERER_API extern PFNGLUNIFORM2FVPROC glUniform2fv; -NAZARA_RENDERER_API extern PFNGLUNIFORM2IVPROC glUniform2iv; -NAZARA_RENDERER_API extern PFNGLUNIFORM3DVPROC glUniform3dv; -NAZARA_RENDERER_API extern PFNGLUNIFORM3FVPROC glUniform3fv; -NAZARA_RENDERER_API extern PFNGLUNIFORM3IVPROC glUniform3iv; -NAZARA_RENDERER_API extern PFNGLUNIFORM4DVPROC glUniform4dv; -NAZARA_RENDERER_API extern PFNGLUNIFORM4FVPROC glUniform4fv; -NAZARA_RENDERER_API extern PFNGLUNIFORM4IVPROC glUniform4iv; -NAZARA_RENDERER_API extern PFNGLUNIFORMMATRIX4DVPROC glUniformMatrix4dv; -NAZARA_RENDERER_API extern PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv; -NAZARA_RENDERER_API extern PFNGLUNMAPBUFFERPROC glUnmapBuffer; -NAZARA_RENDERER_API extern PFNGLUSEPROGRAMPROC glUseProgram; -NAZARA_RENDERER_API extern PFNGLVALIDATEPROGRAMPROC glValidateProgram; -NAZARA_RENDERER_API extern PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f; -NAZARA_RENDERER_API extern PFNGLVERTEXATTRIBDIVISORPROC glVertexAttribDivisor; -NAZARA_RENDERER_API extern PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer; -NAZARA_RENDERER_API extern PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer; -NAZARA_RENDERER_API extern PFNGLVERTEXATTRIBLPOINTERPROC glVertexAttribLPointer; -NAZARA_RENDERER_API extern PFNGLVIEWPORTPROC glViewport; -#if defined(NAZARA_PLATFORM_WINDOWS) -NAZARA_RENDERER_API extern PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat; -NAZARA_RENDERER_API extern PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs; -NAZARA_RENDERER_API extern PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB; -NAZARA_RENDERER_API extern PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT; -NAZARA_RENDERER_API extern PFNWGLSWAPINTERVALEXTPROC wglSwapInterval; + NAZARA_RENDERER_API extern PFNGLACTIVETEXTUREPROC glActiveTexture; + NAZARA_RENDERER_API extern PFNGLATTACHSHADERPROC glAttachShader; + NAZARA_RENDERER_API extern PFNGLBEGINCONDITIONALRENDERPROC glBeginConditionalRender; + NAZARA_RENDERER_API extern PFNGLBEGINQUERYPROC glBeginQuery; + NAZARA_RENDERER_API extern PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation; + NAZARA_RENDERER_API extern PFNGLBINDBUFFERPROC glBindBuffer; + NAZARA_RENDERER_API extern PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer; + NAZARA_RENDERER_API extern PFNGLBINDFRAGDATALOCATIONPROC glBindFragDataLocation; + NAZARA_RENDERER_API extern PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer; + NAZARA_RENDERER_API extern PFNGLBINDSAMPLERPROC glBindSampler; + NAZARA_RENDERER_API extern PFNGLBINDTEXTUREPROC glBindTexture; + NAZARA_RENDERER_API extern PFNGLBINDVERTEXARRAYPROC glBindVertexArray; + NAZARA_RENDERER_API extern PFNGLBLENDFUNCPROC glBlendFunc; + NAZARA_RENDERER_API extern PFNGLBLENDFUNCSEPARATEPROC glBlendFuncSeparate; + NAZARA_RENDERER_API extern PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer; + NAZARA_RENDERER_API extern PFNGLBUFFERDATAPROC glBufferData; + NAZARA_RENDERER_API extern PFNGLBUFFERSUBDATAPROC glBufferSubData; + NAZARA_RENDERER_API extern PFNGLCLEARPROC glClear; + NAZARA_RENDERER_API extern PFNGLCLEARCOLORPROC glClearColor; + NAZARA_RENDERER_API extern PFNGLCLEARDEPTHPROC glClearDepth; + NAZARA_RENDERER_API extern PFNGLCLEARSTENCILPROC glClearStencil; + NAZARA_RENDERER_API extern PFNGLCREATEPROGRAMPROC glCreateProgram; + NAZARA_RENDERER_API extern PFNGLCREATESHADERPROC glCreateShader; + NAZARA_RENDERER_API extern PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus; + NAZARA_RENDERER_API extern PFNGLCOLORMASKPROC glColorMask; + NAZARA_RENDERER_API extern PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC glCompressedTexSubImage1D; + NAZARA_RENDERER_API extern PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC glCompressedTexSubImage2D; + NAZARA_RENDERER_API extern PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC glCompressedTexSubImage3D; + NAZARA_RENDERER_API extern PFNGLCULLFACEPROC glCullFace; + NAZARA_RENDERER_API extern PFNGLCOMPILESHADERPROC glCompileShader; + NAZARA_RENDERER_API extern PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D; + NAZARA_RENDERER_API extern PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback; + NAZARA_RENDERER_API extern PFNGLDEBUGMESSAGECONTROLPROC glDebugMessageControl; + NAZARA_RENDERER_API extern PFNGLDEBUGMESSAGEINSERTPROC glDebugMessageInsert; + NAZARA_RENDERER_API extern PFNGLDELETEBUFFERSPROC glDeleteBuffers; + NAZARA_RENDERER_API extern PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers; + NAZARA_RENDERER_API extern PFNGLDELETEPROGRAMPROC glDeleteProgram; + NAZARA_RENDERER_API extern PFNGLDELETEQUERIESPROC glDeleteQueries; + NAZARA_RENDERER_API extern PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers; + NAZARA_RENDERER_API extern PFNGLDELETESAMPLERSPROC glDeleteSamplers; + NAZARA_RENDERER_API extern PFNGLDELETESHADERPROC glDeleteShader; + NAZARA_RENDERER_API extern PFNGLDELETETEXTURESPROC glDeleteTextures; + NAZARA_RENDERER_API extern PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays; + NAZARA_RENDERER_API extern PFNGLDEPTHFUNCPROC glDepthFunc; + NAZARA_RENDERER_API extern PFNGLDEPTHMASKPROC glDepthMask; + NAZARA_RENDERER_API extern PFNGLDISABLEPROC glDisable; + NAZARA_RENDERER_API extern PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray; + NAZARA_RENDERER_API extern PFNGLDRAWARRAYSPROC glDrawArrays; + NAZARA_RENDERER_API extern PFNGLDRAWARRAYSINSTANCEDPROC glDrawArraysInstanced; + NAZARA_RENDERER_API extern PFNGLDRAWBUFFERPROC glDrawBuffer; + NAZARA_RENDERER_API extern PFNGLDRAWBUFFERSPROC glDrawBuffers; + NAZARA_RENDERER_API extern PFNGLDRAWELEMENTSPROC glDrawElements; + NAZARA_RENDERER_API extern PFNGLDRAWELEMENTSINSTANCEDPROC glDrawElementsInstanced; + NAZARA_RENDERER_API extern PFNGLDRAWTEXTURENVPROC glDrawTexture; + NAZARA_RENDERER_API extern PFNGLENABLEPROC glEnable; + NAZARA_RENDERER_API extern PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray; + NAZARA_RENDERER_API extern PFNGLENDCONDITIONALRENDERPROC glEndConditionalRender; + NAZARA_RENDERER_API extern PFNGLENDQUERYPROC glEndQuery; + NAZARA_RENDERER_API extern PFNGLFLUSHPROC glFlush; + NAZARA_RENDERER_API extern PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer; + NAZARA_RENDERER_API extern PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture; + NAZARA_RENDERER_API extern PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D; + NAZARA_RENDERER_API extern PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D; + NAZARA_RENDERER_API extern PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D; + NAZARA_RENDERER_API extern PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer; + NAZARA_RENDERER_API extern PFNGLGENERATEMIPMAPPROC glGenerateMipmap; + NAZARA_RENDERER_API extern PFNGLGENBUFFERSPROC glGenBuffers; + NAZARA_RENDERER_API extern PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers; + NAZARA_RENDERER_API extern PFNGLGENQUERIESPROC glGenQueries; + NAZARA_RENDERER_API extern PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers; + NAZARA_RENDERER_API extern PFNGLGENSAMPLERSPROC glGenSamplers; + NAZARA_RENDERER_API extern PFNGLGENTEXTURESPROC glGenTextures; + NAZARA_RENDERER_API extern PFNGLGENVERTEXARRAYSPROC glGenVertexArrays; + NAZARA_RENDERER_API extern PFNGLGETACTIVEUNIFORMPROC glGetActiveUniform; + NAZARA_RENDERER_API extern PFNGLGETBOOLEANVPROC glGetBooleanv; + NAZARA_RENDERER_API extern PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv; + NAZARA_RENDERER_API extern PFNGLGETDEBUGMESSAGELOGPROC glGetDebugMessageLog; + NAZARA_RENDERER_API extern PFNGLGETERRORPROC glGetError; + NAZARA_RENDERER_API extern PFNGLGETFLOATVPROC glGetFloatv; + NAZARA_RENDERER_API extern PFNGLGETINTEGERVPROC glGetIntegerv; + NAZARA_RENDERER_API extern PFNGLGETPROGRAMBINARYPROC glGetProgramBinary; + NAZARA_RENDERER_API extern PFNGLGETPROGRAMIVPROC glGetProgramiv; + NAZARA_RENDERER_API extern PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog; + NAZARA_RENDERER_API extern PFNGLGETQUERYIVPROC glGetQueryiv; + NAZARA_RENDERER_API extern PFNGLGETQUERYOBJECTIVPROC glGetQueryObjectiv; + NAZARA_RENDERER_API extern PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv; + NAZARA_RENDERER_API extern PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog; + NAZARA_RENDERER_API extern PFNGLGETSHADERIVPROC glGetShaderiv; + NAZARA_RENDERER_API extern PFNGLGETSHADERSOURCEPROC glGetShaderSource; + NAZARA_RENDERER_API extern PFNGLGETSTRINGPROC glGetString; + NAZARA_RENDERER_API extern PFNGLGETSTRINGIPROC glGetStringi; + NAZARA_RENDERER_API extern PFNGLGETTEXIMAGEPROC glGetTexImage; + NAZARA_RENDERER_API extern PFNGLGETTEXLEVELPARAMETERFVPROC glGetTexLevelParameterfv; + NAZARA_RENDERER_API extern PFNGLGETTEXLEVELPARAMETERIVPROC glGetTexLevelParameteriv; + NAZARA_RENDERER_API extern PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv; + NAZARA_RENDERER_API extern PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv; + NAZARA_RENDERER_API extern PFNGLGETUNIFORMFVPROC glGetUniformfv; + NAZARA_RENDERER_API extern PFNGLGETUNIFORMIVPROC glGetUniformiv; + NAZARA_RENDERER_API extern PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation; + NAZARA_RENDERER_API extern PFNGLINVALIDATEBUFFERDATAPROC glInvalidateBufferData; + NAZARA_RENDERER_API extern PFNGLISENABLEDPROC glIsEnabled; + NAZARA_RENDERER_API extern PFNGLLINEWIDTHPROC glLineWidth; + NAZARA_RENDERER_API extern PFNGLLINKPROGRAMPROC glLinkProgram; + NAZARA_RENDERER_API extern PFNGLMAPBUFFERPROC glMapBuffer; + NAZARA_RENDERER_API extern PFNGLMAPBUFFERRANGEPROC glMapBufferRange; + NAZARA_RENDERER_API extern PFNGLPIXELSTOREIPROC glPixelStorei; + NAZARA_RENDERER_API extern PFNGLPOINTSIZEPROC glPointSize; + NAZARA_RENDERER_API extern PFNGLPOLYGONMODEPROC glPolygonMode; + NAZARA_RENDERER_API extern PFNGLPROGRAMBINARYPROC glProgramBinary; + NAZARA_RENDERER_API extern PFNGLPROGRAMPARAMETERIPROC glProgramParameteri; + NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM1DPROC glProgramUniform1d; + NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM1FPROC glProgramUniform1f; + NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM1IPROC glProgramUniform1i; + NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM1DVPROC glProgramUniform1dv; + NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM1FVPROC glProgramUniform1fv; + NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM1IVPROC glProgramUniform1iv; + NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM2DVPROC glProgramUniform2dv; + NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM2FVPROC glProgramUniform2fv; + NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM2IVPROC glProgramUniform2iv; + NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM3DVPROC glProgramUniform3dv; + NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM3FVPROC glProgramUniform3fv; + NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM3IVPROC glProgramUniform3iv; + NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM4DVPROC glProgramUniform4dv; + NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM4FVPROC glProgramUniform4fv; + NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM4IVPROC glProgramUniform4iv; + NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORMMATRIX4DVPROC glProgramUniformMatrix4dv; + NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORMMATRIX4FVPROC glProgramUniformMatrix4fv; + NAZARA_RENDERER_API extern PFNGLREADPIXELSPROC glReadPixels; + NAZARA_RENDERER_API extern PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage; + NAZARA_RENDERER_API extern PFNGLSAMPLERPARAMETERFPROC glSamplerParameterf; + NAZARA_RENDERER_API extern PFNGLSAMPLERPARAMETERIPROC glSamplerParameteri; + NAZARA_RENDERER_API extern PFNGLSCISSORPROC glScissor; + NAZARA_RENDERER_API extern PFNGLSHADERSOURCEPROC glShaderSource; + NAZARA_RENDERER_API extern PFNGLSTENCILFUNCPROC glStencilFunc; + NAZARA_RENDERER_API extern PFNGLSTENCILFUNCSEPARATEPROC glStencilFuncSeparate; + NAZARA_RENDERER_API extern PFNGLSTENCILOPPROC glStencilOp; + NAZARA_RENDERER_API extern PFNGLSTENCILOPSEPARATEPROC glStencilOpSeparate; + NAZARA_RENDERER_API extern PFNGLTEXIMAGE1DPROC glTexImage1D; + NAZARA_RENDERER_API extern PFNGLTEXIMAGE2DPROC glTexImage2D; + NAZARA_RENDERER_API extern PFNGLTEXIMAGE3DPROC glTexImage3D; + NAZARA_RENDERER_API extern PFNGLTEXPARAMETERFPROC glTexParameterf; + NAZARA_RENDERER_API extern PFNGLTEXPARAMETERIPROC glTexParameteri; + NAZARA_RENDERER_API extern PFNGLTEXSTORAGE1DPROC glTexStorage1D; + NAZARA_RENDERER_API extern PFNGLTEXSTORAGE2DPROC glTexStorage2D; + NAZARA_RENDERER_API extern PFNGLTEXSTORAGE3DPROC glTexStorage3D; + NAZARA_RENDERER_API extern PFNGLTEXSUBIMAGE1DPROC glTexSubImage1D; + NAZARA_RENDERER_API extern PFNGLTEXSUBIMAGE2DPROC glTexSubImage2D; + NAZARA_RENDERER_API extern PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D; + NAZARA_RENDERER_API extern PFNGLUNIFORM1DPROC glUniform1d; + NAZARA_RENDERER_API extern PFNGLUNIFORM1FPROC glUniform1f; + NAZARA_RENDERER_API extern PFNGLUNIFORM1IPROC glUniform1i; + NAZARA_RENDERER_API extern PFNGLUNIFORM1DVPROC glUniform1dv; + NAZARA_RENDERER_API extern PFNGLUNIFORM1FVPROC glUniform1fv; + NAZARA_RENDERER_API extern PFNGLUNIFORM1IVPROC glUniform1iv; + NAZARA_RENDERER_API extern PFNGLUNIFORM2DVPROC glUniform2dv; + NAZARA_RENDERER_API extern PFNGLUNIFORM2FVPROC glUniform2fv; + NAZARA_RENDERER_API extern PFNGLUNIFORM2IVPROC glUniform2iv; + NAZARA_RENDERER_API extern PFNGLUNIFORM3DVPROC glUniform3dv; + NAZARA_RENDERER_API extern PFNGLUNIFORM3FVPROC glUniform3fv; + NAZARA_RENDERER_API extern PFNGLUNIFORM3IVPROC glUniform3iv; + NAZARA_RENDERER_API extern PFNGLUNIFORM4DVPROC glUniform4dv; + NAZARA_RENDERER_API extern PFNGLUNIFORM4FVPROC glUniform4fv; + NAZARA_RENDERER_API extern PFNGLUNIFORM4IVPROC glUniform4iv; + NAZARA_RENDERER_API extern PFNGLUNIFORMMATRIX4DVPROC glUniformMatrix4dv; + NAZARA_RENDERER_API extern PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv; + NAZARA_RENDERER_API extern PFNGLUNMAPBUFFERPROC glUnmapBuffer; + NAZARA_RENDERER_API extern PFNGLUSEPROGRAMPROC glUseProgram; + NAZARA_RENDERER_API extern PFNGLVALIDATEPROGRAMPROC glValidateProgram; + NAZARA_RENDERER_API extern PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f; + NAZARA_RENDERER_API extern PFNGLVERTEXATTRIBDIVISORPROC glVertexAttribDivisor; + NAZARA_RENDERER_API extern PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer; + NAZARA_RENDERER_API extern PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer; + NAZARA_RENDERER_API extern PFNGLVERTEXATTRIBLPOINTERPROC glVertexAttribLPointer; + NAZARA_RENDERER_API extern PFNGLVIEWPORTPROC glViewport; +#if defined(NAZARA_PLATFORM_SDL2) +#elif defined(NAZARA_PLATFORM_WINDOWS) + NAZARA_RENDERER_API extern PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat; + NAZARA_RENDERER_API extern PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs; + NAZARA_RENDERER_API extern PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB; + NAZARA_RENDERER_API extern PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT; + NAZARA_RENDERER_API extern PFNWGLSWAPINTERVALEXTPROC wglSwapInterval; #elif defined(NAZARA_PLATFORM_GLX) -NAZARA_RENDERER_API extern GLX::PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs; -NAZARA_RENDERER_API extern GLX::PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT; -NAZARA_RENDERER_API extern GLX::PFNGLXSWAPINTERVALMESAPROC NzglXSwapIntervalMESA; -NAZARA_RENDERER_API extern GLX::PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI; + NAZARA_RENDERER_API extern GLX::PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs; + NAZARA_RENDERER_API extern GLX::PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT; + NAZARA_RENDERER_API extern GLX::PFNGLXSWAPINTERVALMESAPROC NzglXSwapIntervalMESA; + NAZARA_RENDERER_API extern GLX::PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI; #endif } +#undef None + #endif // NAZARA_RENDERER_OPENGL #endif // NAZARA_OPENGL_HPP diff --git a/src/Nazara/Platform/Cursor.cpp b/src/Nazara/Platform/Cursor.cpp index 7d68a460b..a352d7f8c 100644 --- a/src/Nazara/Platform/Cursor.cpp +++ b/src/Nazara/Platform/Cursor.cpp @@ -4,7 +4,9 @@ #include -#if defined(NAZARA_PLATFORM_WINDOWS) +#if defined(NAZARA_PLATFORM_SDL2) + #include +#elif defined(NAZARA_PLATFORM_WINDOWS) #include #elif defined(NAZARA_PLATFORM_X11) #include diff --git a/src/Nazara/Platform/Icon.cpp b/src/Nazara/Platform/Icon.cpp index 010e9dfc2..86ce7559b 100644 --- a/src/Nazara/Platform/Icon.cpp +++ b/src/Nazara/Platform/Icon.cpp @@ -4,7 +4,9 @@ #include -#if defined(NAZARA_PLATFORM_WINDOWS) +#if defined(NAZARA_PLATFORM_SDL2) + #include +#elif defined(NAZARA_PLATFORM_WINDOWS) #include #elif defined(NAZARA_PLATFORM_X11) #include diff --git a/src/Nazara/Platform/Keyboard.cpp b/src/Nazara/Platform/Keyboard.cpp index be1341eb6..9fbf8fcdf 100644 --- a/src/Nazara/Platform/Keyboard.cpp +++ b/src/Nazara/Platform/Keyboard.cpp @@ -4,7 +4,9 @@ #include -#if defined(NAZARA_PLATFORM_WINDOWS) +#if defined(NAZARA_PLATFORM_SDL2) + #include +#elif defined(NAZARA_PLATFORM_WINDOWS) #include #elif defined(NAZARA_PLATFORM_X11) #include diff --git a/src/Nazara/Platform/Mouse.cpp b/src/Nazara/Platform/Mouse.cpp index 6d589697e..e9b55031a 100644 --- a/src/Nazara/Platform/Mouse.cpp +++ b/src/Nazara/Platform/Mouse.cpp @@ -5,7 +5,9 @@ #include #include -#if defined(NAZARA_PLATFORM_WINDOWS) +#if defined(NAZARA_PLATFORM_SDL2) + #include +#elif defined(NAZARA_PLATFORM_WINDOWS) #include #elif defined(NAZARA_PLATFORM_X11) #include diff --git a/src/Nazara/Platform/SDL2/CursorImpl.cpp b/src/Nazara/Platform/SDL2/CursorImpl.cpp new file mode 100644 index 000000000..c9497a2e8 --- /dev/null +++ b/src/Nazara/Platform/SDL2/CursorImpl.cpp @@ -0,0 +1,108 @@ +// Copyright (C) 2017 Jérôme Leclercq +// This file is part of the "Nazara Engine - Platform module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include + +namespace Nz +{ + bool CursorImpl::Create(const Image& cursor, int hotSpotX, int hotSpotY) + { + m_iconImage = cursor; + if (!m_iconImage.Convert(PixelFormatType_BGRA8)) + { + NazaraError("Failed to convert icon to BGRA8"); + return false; + } + + m_icon = SDL_CreateRGBSurfaceWithFormatFrom( + m_iconImage.GetPixels(), + m_iconImage.GetWidth(), + m_iconImage.GetHeight(), + 32, + 32 * m_iconImage.GetWidth(), + SDL_PIXELFORMAT_BGRA8888 + ); + + if (!m_icon) + { + NazaraError(SDL_GetError()); + + return false; + } + + m_cursor = SDL_CreateColorCursor(m_icon, hotSpotX, hotSpotY); + + if (!m_cursor) + { + NazaraError(SDL_GetError()); + + return false; + } + + return true; + } + + bool CursorImpl::Create(SystemCursor cursor) + { + if (cursor != SystemCursor_None) + m_cursor = SDL_CreateSystemCursor(s_systemCursorIds[cursor]); + else + m_cursor = nullptr; + + m_icon = nullptr; + + return true; + } + + void CursorImpl::Destroy() + { + if (m_icon) + SDL_FreeSurface(m_icon); + + if (m_cursor) + SDL_FreeCursor(m_cursor); + } + + SDL_Cursor* CursorImpl::GetCursor() + { + return m_cursor; + } + + bool CursorImpl::Initialize() + { + return true; + } + + void CursorImpl::Uninitialize() + { + } + + std::array CursorImpl::s_systemCursorIds = + { + SDL_SYSTEM_CURSOR_CROSSHAIR, // SystemCursor_Crosshair + SDL_SYSTEM_CURSOR_ARROW, // SystemCursor_Default + SDL_SYSTEM_CURSOR_HAND, // SystemCursor_Hand + SDL_SYSTEM_CURSOR_ARROW, // SystemCursor_Help + SDL_SYSTEM_CURSOR_SIZEALL, // SystemCursor_Move + SDL_NUM_SYSTEM_CURSORS, // SystemCursor_None + SDL_SYSTEM_CURSOR_HAND, // SystemCursor_Pointer + SDL_SYSTEM_CURSOR_WAITARROW, // SystemCursor_Progress + SDL_SYSTEM_CURSOR_SIZEWE, // SystemCursor_ResizeE + SDL_SYSTEM_CURSOR_SIZENS, // SystemCursor_ResizeN + SDL_SYSTEM_CURSOR_SIZENESW, // SystemCursor_ResizeNE + SDL_SYSTEM_CURSOR_SIZENWSE, // SystemCursor_ResizeNW + SDL_SYSTEM_CURSOR_SIZENS, // SystemCursor_ResizeS + SDL_SYSTEM_CURSOR_SIZENWSE, // SystemCursor_ResizeSE + SDL_SYSTEM_CURSOR_SIZENESW, // SystemCursor_ResizeSW + SDL_SYSTEM_CURSOR_SIZEWE, // SystemCursor_ResizeW + SDL_SYSTEM_CURSOR_IBEAM, // SystemCursor_Text + SDL_SYSTEM_CURSOR_WAIT // SystemCursor_Wait + }; + + static_assert(SystemCursor_Max + 1 == 18, "System cursor array is incomplete"); +} diff --git a/src/Nazara/Platform/SDL2/CursorImpl.hpp b/src/Nazara/Platform/SDL2/CursorImpl.hpp new file mode 100644 index 000000000..ae90ef7f4 --- /dev/null +++ b/src/Nazara/Platform/SDL2/CursorImpl.hpp @@ -0,0 +1,45 @@ +// Copyright (C) 2017 Jérôme Leclercq +// This file is part of the "Nazara Engine - Platform module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_CURSORIMPL_HPP +#define NAZARA_CURSORIMPL_HPP + +#include +#include +#include +#include + +#include + +namespace Nz +{ + class Image; + + class CursorImpl + { + friend class Cursor; + + public: + bool Create(const Image& image, int hotSpotX, int hotSpotY); + bool Create(SystemCursor cursor); + + void Destroy(); + + SDL_Cursor* GetCursor(); + + private: + static bool Initialize(); + static void Uninitialize(); + + SDL_Cursor* m_cursor = nullptr; + SDL_Surface* m_icon = nullptr; + Image m_iconImage; + + static std::array s_systemCursorIds; + }; +} + +#endif // NAZARA_CURSORIMPL_HPP diff --git a/src/Nazara/Platform/SDL2/IconImpl.cpp b/src/Nazara/Platform/SDL2/IconImpl.cpp new file mode 100644 index 000000000..b802b1176 --- /dev/null +++ b/src/Nazara/Platform/SDL2/IconImpl.cpp @@ -0,0 +1,49 @@ +// Copyright (C) 2017 Jérôme Leclercq +// This file is part of the "Nazara Engine - Platform module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include + +namespace Nz +{ + bool IconImpl::Create(const Image& icon) + { + m_iconImage = icon; + if (!m_iconImage.Convert(PixelFormatType_BGRA8)) + { + NazaraError("Failed to convert icon to BGRA8"); + return false; + } + + m_icon = SDL_CreateRGBSurfaceWithFormatFrom( + m_iconImage.GetPixels(), + m_iconImage.GetWidth(), + m_iconImage.GetHeight(), + 32, + 32 * m_iconImage.GetWidth(), + SDL_PIXELFORMAT_BGRA8888 + ); + + if (!m_icon) + { + NazaraError(SDL_GetError()); + return false; + } + + return true; + } + + void IconImpl::Destroy() + { + SDL_FreeSurface(m_icon); + m_iconImage.Destroy(); + } + + SDL_Surface* IconImpl::GetIcon() + { + return m_icon; + } +} diff --git a/src/Nazara/Platform/SDL2/IconImpl.hpp b/src/Nazara/Platform/SDL2/IconImpl.hpp new file mode 100644 index 000000000..891e6a547 --- /dev/null +++ b/src/Nazara/Platform/SDL2/IconImpl.hpp @@ -0,0 +1,33 @@ +// Copyright (C) 2017 Jérôme Leclercq +// This file is part of the "Nazara Engine - Platform module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_ICONIMPL_HPP +#define NAZARA_ICONIMPL_HPP + +#include +#include +#include + +namespace Nz +{ + class Image; + + class IconImpl + { + public: + bool Create(const Image& image); + void Destroy(); + + SDL_Surface* GetIcon(); + + private: + + SDL_Surface* m_icon = nullptr; + Image m_iconImage; + }; +} + +#endif // NAZARA_ICONIMPL_HPP diff --git a/src/Nazara/Platform/SDL2/InputImpl.cpp b/src/Nazara/Platform/SDL2/InputImpl.cpp new file mode 100644 index 000000000..671f79d22 --- /dev/null +++ b/src/Nazara/Platform/SDL2/InputImpl.cpp @@ -0,0 +1,234 @@ +// Copyright (C) 2017 Jérôme Leclercq +// This file is part of the "Nazara Engine - Platform module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include + +#include +#include + +namespace Nz +{ + namespace + { + SDL_Scancode nzKeyboardToSDLScanCode[Keyboard::Count] = { + // Lettres + SDL_SCANCODE_A, // Key::A + SDL_SCANCODE_B, // Key::B + SDL_SCANCODE_C, // Key::C + SDL_SCANCODE_D, // Key::D + SDL_SCANCODE_E, // Key::E + SDL_SCANCODE_F, // Key::F + SDL_SCANCODE_G, // Key::G + SDL_SCANCODE_H, // Key::H + SDL_SCANCODE_I, // Key::I + SDL_SCANCODE_J, // Key::J + SDL_SCANCODE_K, // Key::K + SDL_SCANCODE_L, // Key::L + SDL_SCANCODE_M, // Key::M + SDL_SCANCODE_N, // Key::N + SDL_SCANCODE_O, // Key::O + SDL_SCANCODE_P, // Key::P + SDL_SCANCODE_Q, // Key::Q + SDL_SCANCODE_R, // Key::R + SDL_SCANCODE_S, // Key::S + SDL_SCANCODE_T, // Key::T + SDL_SCANCODE_U, // Key::U + SDL_SCANCODE_V, // Key::V + SDL_SCANCODE_W, // Key::W + SDL_SCANCODE_X, // Key::X + SDL_SCANCODE_Y, // Key::Y + SDL_SCANCODE_Z, // Key::Z + + // Touches de fonction + SDL_SCANCODE_F1, // Key::F1 + SDL_SCANCODE_F2, // Key::F2 + SDL_SCANCODE_F3, // Key::F3 + SDL_SCANCODE_F4, // Key::F4 + SDL_SCANCODE_F5, // Key::F5 + SDL_SCANCODE_F6, // Key::F6 + SDL_SCANCODE_F7, // Key::F7 + SDL_SCANCODE_F8, // Key::F8 + SDL_SCANCODE_F9, // Key::F9 + SDL_SCANCODE_F10, // Key::F10 + SDL_SCANCODE_F11, // Key::F11 + SDL_SCANCODE_F12, // Key::F12 + SDL_SCANCODE_F13, // Key::F13 + SDL_SCANCODE_F14, // Key::F14 + SDL_SCANCODE_F15, // Key::F15 + + // Flèches directionnelles + SDL_SCANCODE_DOWN, // Key::Down + SDL_SCANCODE_LEFT, // Key::Left + SDL_SCANCODE_RIGHT, // Key::Right + SDL_SCANCODE_UP, // Key::Up + + // Pavé numérique + SDL_SCANCODE_KP_PLUS, // Key::Add + SDL_SCANCODE_KP_PERIOD, // Key::Decimal + SDL_SCANCODE_KP_DIVIDE, // Key::Divide + SDL_SCANCODE_KP_MULTIPLY, // Key::Multiply + SDL_SCANCODE_KP_ENTER, // Key::NumpadReturn + SDL_SCANCODE_KP_0, // Key::Numpad0 + SDL_SCANCODE_KP_1, // Key::Numpad1 + SDL_SCANCODE_KP_2, // Key::Numpad2 + SDL_SCANCODE_KP_3, // Key::Numpad3 + SDL_SCANCODE_KP_4, // Key::Numpad4 + SDL_SCANCODE_KP_5, // Key::Numpad5 + SDL_SCANCODE_KP_6, // Key::Numpad6 + SDL_SCANCODE_KP_7, // Key::Numpad7 + SDL_SCANCODE_KP_8, // Key::Numpad8 + SDL_SCANCODE_KP_9, // Key::Numpad9 + SDL_SCANCODE_KP_MINUS, // Key::Subtract + + + // Diverss + SDL_SCANCODE_BACKSLASH, // Key::Backslash + SDL_SCANCODE_BACKSPACE, // Key::Backspace + SDL_SCANCODE_CLEAR, // Key::Clear + SDL_SCANCODE_COMMA, // Key::Comma, + SDL_SCANCODE_MINUS, // Key::Dash + SDL_SCANCODE_DELETE, // Key::Delete + SDL_SCANCODE_END, // Key::End + SDL_SCANCODE_EQUALS, // Key::Equal + SDL_SCANCODE_ESCAPE, // Key::Escape + SDL_SCANCODE_HOME, // Key::Home + SDL_SCANCODE_INSERT, // Key::Insert + SDL_SCANCODE_LALT, // Key::LAlt + SDL_SCANCODE_LEFTBRACKET, // Key::LBracket + SDL_SCANCODE_LCTRL, // Key::LControl + SDL_SCANCODE_LSHIFT, // Key::LShift + SDL_SCANCODE_LGUI, // Key::LSystem + SDL_SCANCODE_0, // Key::Num0 + SDL_SCANCODE_1, // Key::Num1 + SDL_SCANCODE_2, // Key::Num2 + SDL_SCANCODE_3, // Key::Num3 + SDL_SCANCODE_4, // Key::Num4 + SDL_SCANCODE_5, // Key::Num5 + SDL_SCANCODE_6, // Key::Num6 + SDL_SCANCODE_7, // Key::Num7 + SDL_SCANCODE_8, // Key::Num8 + SDL_SCANCODE_9, // Key::Num9 + SDL_SCANCODE_PAGEDOWN, // Key::PageDown + SDL_SCANCODE_PAGEUP, // Key::PageUp + SDL_SCANCODE_PAUSE, // Key::Pause + SDL_SCANCODE_PERIOD, // Key::Period + SDL_SCANCODE_SYSREQ, // Key::Print + SDL_SCANCODE_PRINTSCREEN, // Key::PrintScreen + SDL_SCANCODE_APOSTROPHE, // Key::Quote + SDL_SCANCODE_RALT, // Key::RAlt + SDL_SCANCODE_RIGHTBRACKET, // Key::RBracket + SDL_SCANCODE_RCTRL, // Key::RControl + SDL_SCANCODE_RETURN, // Key::Return + SDL_SCANCODE_RSHIFT, // Key::RShift + SDL_SCANCODE_RGUI, // Key::RSystem + SDL_SCANCODE_SEMICOLON, // Key::Semicolon + SDL_SCANCODE_SLASH, // Key::Slash + SDL_SCANCODE_SPACE, // Key::Space + SDL_SCANCODE_TAB, // Key::Tab + SDL_SCANCODE_GRAVE, // Key::Tilde + SDL_SCANCODE_APPLICATION, // Key::Menu + SDL_SCANCODE_NONUSBACKSLASH,// Key::ISOBackslash102 + + // Touches navigateur + SDL_SCANCODE_AC_BACK, // Key::Browser_Back + SDL_SCANCODE_AC_BOOKMARKS, // Key::Browser_Favorites + SDL_SCANCODE_AC_FORWARD, // Key::Browser_Forward + SDL_SCANCODE_AC_HOME, // Key::Browser_Home + SDL_SCANCODE_AC_REFRESH, // Key::Browser_Refresh + SDL_SCANCODE_AC_SEARCH, // Key::Browser_Search + SDL_SCANCODE_AC_STOP, // Key::Browser_Stop + + // Touches de contrôle + SDL_SCANCODE_AUDIONEXT, // Key::Media_Next, + SDL_SCANCODE_AUDIOPLAY, // Key::Media_PlayPause, + SDL_SCANCODE_AUDIOPREV, // Key::Media_Previous, + SDL_SCANCODE_AUDIOSTOP, // Key::Media_Stop, + + // Touches de contrôle du volume + SDL_SCANCODE_VOLUMEDOWN, // Key::Volume_Down + SDL_SCANCODE_MUTE, // Key::Volume_Mute + SDL_SCANCODE_VOLUMEUP, // Key::Volume_Up + + // Touches à verrouillage + SDL_SCANCODE_CAPSLOCK, // Key::CapsLock + SDL_SCANCODE_NUMLOCKCLEAR, // Key::NumLock + SDL_SCANCODE_SCROLLLOCK // Key::ScrollLock + }; + } + + String EventImpl::GetKeyName(Keyboard::Key key) + { + auto scancode = nzKeyboardToSDLScanCode[key]; + + auto name = String::Unicode(SDL_GetKeyName(SDL_GetKeyFromScancode(scancode))); + + if (name == "") + name = "\"" + String::Unicode(SDL_GetScancodeName(scancode)) + "\""; + + return name == "\"\"" ? String::Unicode("Unknown") : name; + } + + Vector2i EventImpl::GetMousePosition() + { + Vector2i pos; + SDL_GetGlobalMouseState(&pos.x, &pos.y); + + return pos; + } + + Vector2i EventImpl::GetMousePosition(const Window& relativeTo) + { + auto handle = relativeTo.GetHandle(); + if (handle) + { + auto windowPos = relativeTo.GetPosition(); + auto mousePos = GetMousePosition(); + + return mousePos - windowPos; + } + else + { + NazaraError("Invalid window handle"); + + // Attention que (-1, -1) est une position tout à fait valide et ne doit pas servir de test + return Vector2i(-1, -1); + } + } + + bool EventImpl::IsKeyPressed(Keyboard::Key key) + { + return SDL_GetKeyboardState(nullptr)[nzKeyboardToSDLScanCode[key]]; + } + + bool EventImpl::IsMouseButtonPressed(Mouse::Button button) + { + static int vButtons[Mouse::Max + 1] = { + SDL_BUTTON_LMASK, // Button::Left + SDL_BUTTON_MMASK, // Button::Middle + SDL_BUTTON_RMASK, // Button::Right + SDL_BUTTON_X1MASK, // Button::XButton1 + SDL_BUTTON_X2MASK // Button::XButton2 + }; + + return (SDL_GetGlobalMouseState(nullptr, nullptr) & vButtons[button]) != 0; + } + + void EventImpl::SetMousePosition(int x, int y) + { + if (SDL_WarpMouseGlobal(x, y) != 0) + NazaraWarning(SDL_GetError()); + } + + void EventImpl::SetMousePosition(int x, int y, const Window& relativeTo) + { + auto handle = static_cast(relativeTo.GetHandle()); + if (handle) + SDL_WarpMouseInWindow(handle, x, y); + else + NazaraError("Invalid window handle"); + } +} diff --git a/src/Nazara/Platform/SDL2/InputImpl.hpp b/src/Nazara/Platform/SDL2/InputImpl.hpp new file mode 100644 index 000000000..09f7802ec --- /dev/null +++ b/src/Nazara/Platform/SDL2/InputImpl.hpp @@ -0,0 +1,30 @@ +// Copyright (C) 2017 Jérôme Leclercq +// This file is part of the "Nazara Engine - Platform module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_INPUTIMPL_HPP +#define NAZARA_INPUTIMPL_HPP + +#include +#include +#include +#include + +namespace Nz +{ + class EventImpl + { + public: + static String GetKeyName(Keyboard::Key key); + static Vector2i GetMousePosition(); + static Vector2i GetMousePosition(const Window& relativeTo); + static bool IsKeyPressed(Keyboard::Key key); + static bool IsMouseButtonPressed(Mouse::Button button); + static void SetMousePosition(int x, int y); + static void SetMousePosition(int x, int y, const Window& relativeTo); + }; +} + +#endif // NAZARA_INPUTIMPL_HPP diff --git a/src/Nazara/Platform/SDL2/VideoModeImpl.cpp b/src/Nazara/Platform/SDL2/VideoModeImpl.cpp new file mode 100644 index 000000000..a9661c572 --- /dev/null +++ b/src/Nazara/Platform/SDL2/VideoModeImpl.cpp @@ -0,0 +1,51 @@ +// Copyright (C) 2017 Jérôme Leclercq +// This file is part of the "Nazara Engine - Platform module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include + +namespace Nz +{ + VideoMode VideoModeImpl::GetDesktopMode() + { + SDL_DisplayMode mode; + if (SDL_GetDesktopDisplayMode(0, &mode) != 0) // handle multi screen ? + { + NazaraError(SDL_GetError()); + + return VideoMode(800, 600, static_cast(32)); // useless ? + } + + return VideoMode(mode.w, mode.h, SDL_BITSPERPIXEL(mode.format)); + } + + void VideoModeImpl::GetFullscreenModes(std::vector& modes) + { + SDL_DisplayMode mode; + + int numModes = SDL_GetNumDisplayModes(0); + if (numModes < 0) + { + NazaraError(SDL_GetError()); + + return; + } + + for (int i = 0; i < numModes; i++) + { + if (SDL_GetDisplayMode(0, i, &mode) != 0) // handle multi screen ? + + NazaraError(SDL_GetError()); + + VideoMode vMode(mode.w, mode.h, SDL_BITSPERPIXEL(mode.format)); + + if (std::find(modes.begin(), modes.end(), vMode) == modes.end()) + modes.push_back(vMode); + } + } +} diff --git a/src/Nazara/Platform/SDL2/VideoModeImpl.hpp b/src/Nazara/Platform/SDL2/VideoModeImpl.hpp new file mode 100644 index 000000000..39579b9a2 --- /dev/null +++ b/src/Nazara/Platform/SDL2/VideoModeImpl.hpp @@ -0,0 +1,22 @@ +// Copyright (C) 2017 Jérôme Leclercq +// This file is part of the "Nazara Engine - Platform module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_VIDEOMODEIMPL_HPP +#define NAZARA_VIDEOMODEIMPL_HPP + +#include + +namespace Nz +{ + class VideoModeImpl + { + public: + static VideoMode GetDesktopMode(); + static void GetFullscreenModes(std::vector& modes); + }; +} + +#endif // NNAZARA_VIDEOMODEIMPL_HPP diff --git a/src/Nazara/Platform/SDL2/WindowImpl.cpp b/src/Nazara/Platform/SDL2/WindowImpl.cpp new file mode 100644 index 000000000..f44ca8fe5 --- /dev/null +++ b/src/Nazara/Platform/SDL2/WindowImpl.cpp @@ -0,0 +1,695 @@ +// Copyright (C) 2017 Jérôme Leclercq +// This file is part of the "Nazara Engine - Platform module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +// Un grand merci à Laurent Gomila pour la SFML qui m'aura bien aidé à réaliser cette implémentation + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Nz +{ + namespace + { + WindowImpl* fullscreenWindow = nullptr; + + Mouse::Button SDLToNazaraButton(Uint8 sdlButton) + { + switch (sdlButton) + { + case SDL_BUTTON_LEFT: + return Mouse::Left; + case SDL_BUTTON_MIDDLE: + return Mouse::Middle; + case SDL_BUTTON_RIGHT: + return Mouse::Right; + case SDL_BUTTON_X1: + return Mouse::XButton1; + case SDL_BUTTON_X2: + return Mouse::XButton2; + default: + NazaraAssert(false, "Unkown mouse button"); + return Mouse::Left; + } + } + } + + WindowImpl::WindowImpl(Window* parent) : + m_cursor(nullptr), + m_handle(nullptr), + //m_callback(0), + m_style(0), + m_maxSize(-1), + m_minSize(-1), + m_parent(parent), + m_keyRepeat(true), + m_mouseInside(false), + m_smoothScrolling(false), + m_scrolling(0) + { + m_cursor = SDL_GetDefaultCursor(); + } + + bool WindowImpl::Create(const VideoMode& mode, const String& title, WindowStyleFlags style) + { + bool async = (style & WindowStyle_Threaded) != 0; + if (async) + { + NazaraError("SDL2 backend doesn't support asyn window for now"); + + return false; + } + + + bool fullscreen = (style & WindowStyle_Fullscreen) != 0; + + Uint32 winStyle = SDL_WINDOW_OPENGL; + + unsigned int x, y; + unsigned int width = mode.width; + unsigned int height = mode.height; + if (fullscreen) + winStyle |= SDL_WINDOW_FULLSCREEN; + + // Testé une seconde fois car sa valeur peut changer + if (fullscreen) + { + x = 0; + y = 0; + + fullscreenWindow = this; + } + else + { + if (!(style & WindowStyle_Titlebar)) + winStyle |= SDL_WINDOW_BORDERLESS; + + x = SDL_WINDOWPOS_CENTERED; + y = SDL_WINDOWPOS_CENTERED; + } + + if (style & WindowStyle_Resizable) + winStyle |= SDL_WINDOW_RESIZABLE; + if (style & WindowStyle_Max) + winStyle |= SDL_WINDOW_MAXIMIZED; + + m_eventListener = true; + m_ownsWindow = true; + m_sizemove = false; + m_style = style; + + m_handle = SDL_CreateWindow(title.GetConstBuffer(), x, y, width, height, winStyle); + + if (!m_handle) + { + NazaraError("Failed to create window: " + Error::GetLastSystemError()); + return false; + } + + PrepareWindow(fullscreen); + + SDL_AddEventWatch(HandleEvent, this); + + return true; + } + + bool WindowImpl::Create(WindowHandle handle) + { + m_handle = static_cast(handle); + + if (!m_handle || !SDL_GetWindowID(m_handle)) + { + NazaraError("Invalid handle"); + return false; + } + + m_eventListener = false; + m_ownsWindow = false; + m_sizemove = false; + + SDL_GetWindowPosition(m_handle, &m_position.x, &m_position.y); + + int width; + int height; + SDL_GetWindowSize(m_handle, &width, &height); + + m_size.Set(width, height); + + SDL_AddEventWatch(HandleEvent, this); + + return true; + } + + void WindowImpl::Destroy() + { + if (m_ownsWindow && m_handle) + SDL_DestroyWindow(m_handle); + else + SetEventListener(false); + + SDL_DelEventWatch(HandleEvent, this); + } + + void WindowImpl::EnableKeyRepeat(bool enable) + { + m_keyRepeat = enable; + } + + void WindowImpl::EnableSmoothScrolling(bool enable) + { + m_smoothScrolling = enable; + } + + WindowHandle WindowImpl::GetHandle() const + { + return m_handle; + } + + Vector2i WindowImpl::GetPosition() const + { + return m_position; + } + + Vector2ui WindowImpl::GetSize() const + { + return m_size; + } + + WindowStyleFlags WindowImpl::GetStyle() const + { + return m_style; + } + + String WindowImpl::GetTitle() const + { + return String::Unicode(SDL_GetWindowTitle(m_handle)); + } + + bool WindowImpl::HasFocus() const + { + return (SDL_GetWindowFlags(m_handle) & SDL_WINDOW_INPUT_FOCUS) != 0; + } + + void WindowImpl::IgnoreNextMouseEvent(int mouseX, int mouseY) + { + m_ignoreNextMouseMove = true; + // Petite astuce ... probablement foireuse dans certains cas :ahde: + m_mousePos.x = mouseX; + m_mousePos.y = mouseY; + } + + bool WindowImpl::IsMinimized() const + { + return (SDL_GetWindowFlags(m_handle) & SDL_WINDOW_MINIMIZED) != 0; + } + + bool WindowImpl::IsVisible() const + { + return (SDL_GetWindowFlags(m_handle) & SDL_WINDOW_SHOWN) != 0; + } + + void WindowImpl::RefreshCursor() + { + if (!m_cursor) + { + if (SDL_ShowCursor(SDL_DISABLE) < 0) + NazaraWarning(SDL_GetError()); + } + else + { + if (SDL_ShowCursor(SDL_ENABLE) < 0) + NazaraWarning(SDL_GetError()); + + SDL_SetCursor(m_cursor); + } + } + + void WindowImpl::ProcessEvents(bool block) + { + SDL_PumpEvents(); + + + /*if (m_ownsWindow) + { + if (block) + WaitMessage(); + + MSG message; + while (PeekMessageW(&message, nullptr, 0, 0, PM_REMOVE)) + { + TranslateMessage(&message); + DispatchMessageW(&message); + } + }*/ + } + + int SDLCALL WindowImpl::HandleEvent(void *userdata, SDL_Event* event) + { + try { + auto window = static_cast(userdata); + + WindowEvent evt; + evt.type = WindowEventType::WindowEventType_Max; + + switch (event->type) + { + case SDL_WINDOWEVENT: + if (SDL_GetWindowID(window->m_handle) != event->window.windowID) + return 0; + + switch (event->window.event) + { + case SDL_WINDOWEVENT_CLOSE: + evt.type = Nz::WindowEventType::WindowEventType_Quit; + break; + case SDL_WINDOWEVENT_RESIZED: + evt.type = Nz::WindowEventType::WindowEventType_Resized; + + evt.size.width = event->window.data1; + evt.size.height = event->window.data2; + + window->m_size.Set(event->window.data1, event->window.data2); + + break; + case SDL_WINDOWEVENT_MOVED: + evt.type = Nz::WindowEventType::WindowEventType_Moved; + + evt.position.x = event->window.data1; + evt.position.y = event->window.data2; + + window->m_position.Set(event->window.data1, event->window.data2); + + break; + case SDL_WINDOWEVENT_FOCUS_GAINED: + evt.type = Nz::WindowEventType::WindowEventType_GainedFocus; + + break; + case SDL_WINDOWEVENT_FOCUS_LOST: + evt.type = Nz::WindowEventType::WindowEventType_LostFocus; + + break; + case SDL_WINDOWEVENT_ENTER: + evt.type = Nz::WindowEventType::WindowEventType_MouseEntered; + + break; + case SDL_WINDOWEVENT_LEAVE: + evt.type = Nz::WindowEventType::WindowEventType_MouseLeft; + + break; + } + break; + + case SDL_MOUSEMOTION: + if (SDL_GetWindowID(window->m_handle) != event->motion.windowID) + return 0; + + if (window->m_ignoreNextMouseMove && event->motion.x == window->m_mousePos.x && event->motion.y == window->m_mousePos.y) + { + window->m_ignoreNextMouseMove = false; + + return 0; + } + + evt.type = Nz::WindowEventType::WindowEventType_MouseMoved; + + evt.mouseMove.x = event->motion.x; + evt.mouseMove.y = event->motion.y; + evt.mouseMove.deltaX = event->motion.xrel; + evt.mouseMove.deltaY = event->motion.yrel; + + break; + + case SDL_MOUSEBUTTONDOWN: + if (SDL_GetWindowID(window->m_handle) != event->button.windowID) + return 0; + + evt.mouseButton.button = SDLToNazaraButton(event->button.button); + evt.mouseButton.x = event->button.x; + evt.mouseButton.y = event->button.y; + + if (event->button.clicks % 2 == 0) + { + evt.type = Nz::WindowEventType::WindowEventType_MouseButtonDoubleClicked; + + window->m_parent->PushEvent(evt); + } + + evt.type = Nz::WindowEventType::WindowEventType_MouseButtonPressed; + + break; + + case SDL_MOUSEBUTTONUP: + if (SDL_GetWindowID(window->m_handle) != event->button.windowID) + return 0; + + evt.mouseButton.button = SDLToNazaraButton(event->button.button); + evt.mouseButton.x = event->button.x; + evt.mouseButton.y = event->button.y; + + evt.type = Nz::WindowEventType::WindowEventType_MouseButtonReleased; + + break; + + case SDL_MOUSEWHEEL: + if (SDL_GetWindowID(window->m_handle) != event->wheel.windowID) + return 0; + + evt.type = Nz::WindowEventType::WindowEventType_MouseWheelMoved; + + evt.mouseWheel.delta = event->wheel.y; + + break; + + case SDL_KEYDOWN: + if (SDL_GetWindowID(window->m_handle) != event->key.windowID) + return 0; + + evt.type = WindowEventType_KeyPressed; + + evt.key.code = SDLKeySymToNazaraKey(event->key.keysym); + evt.key.alt = (event->key.keysym.mod & KMOD_ALT) != 0; + evt.key.control = (event->key.keysym.mod & KMOD_CTRL) != 0; + evt.key.repeated = event->key.repeat != 0; + evt.key.shift = (event->key.keysym.mod & KMOD_SHIFT) != 0; + evt.key.system = (event->key.keysym.mod & KMOD_GUI) != 0; + + break; + + case SDL_KEYUP: + if (SDL_GetWindowID(window->m_handle) != event->key.windowID) + return 0; + + evt.type = WindowEventType_KeyReleased; + + evt.key.code = SDLKeySymToNazaraKey(event->key.keysym); + evt.key.alt = (event->key.keysym.mod & KMOD_ALT) != 0; + evt.key.control = (event->key.keysym.mod & KMOD_CTRL) != 0; + evt.key.repeated = event->key.repeat != 0; + evt.key.shift = (event->key.keysym.mod & KMOD_SHIFT) != 0; + evt.key.system = (event->key.keysym.mod & KMOD_GUI) != 0; + + break; + + case SDL_TEXTINPUT: + if (SDL_GetWindowID(window->m_handle) != event->text.windowID) + return 0; + + evt.type = WindowEventType_TextEntered; + + for (decltype(evt.text.character)codepoint : String::Unicode(event->text.text).GetUtf32String()) + { + evt.text.character = codepoint; + + window->m_parent->PushEvent(evt); + } + + // prevent post switch event + evt.type = WindowEventType::WindowEventType_Max; + + break; + } + + if (evt.type != WindowEventType::WindowEventType_Max) + window->m_parent->PushEvent(evt); + } + catch (std::exception e) + { + NazaraError(e.what()); + } + catch (...) // Don't let any exceptions go thru C calls + { + NazaraError("An unknown error happened"); + } + + return 0; + } + + void WindowImpl::SetCursor(const Cursor& cursor) + { + m_cursor = cursor.m_impl->GetCursor(); + + if (HasFocus()) + RefreshCursor(); + } + + void WindowImpl::SetEventListener(bool listener) + { + + } + + void WindowImpl::SetFocus() + { + SDL_RaiseWindow(m_handle); + } + + void WindowImpl::SetIcon(const Icon& icon) + { + SDL_SetWindowIcon(m_handle, icon.m_impl->GetIcon()); + } + + void WindowImpl::SetMaximumSize(int width, int height) + { + SDL_SetWindowMaximumSize(m_handle, width, height); + } + + void WindowImpl::SetMinimumSize(int width, int height) + { + SDL_SetWindowMinimumSize(m_handle, width, height); + } + + void WindowImpl::SetPosition(int x, int y) + { + SDL_SetWindowPosition(m_handle, x, y); + } + + void WindowImpl::SetSize(unsigned int width, unsigned int height) + { + m_size.Set(width, height); + SDL_SetWindowSize(m_handle, width, height); + } + + void WindowImpl::SetStayOnTop(bool stayOnTop) + { + NazaraDebug("Stay on top isn't supported by SDL2 backend for now"); + } + + void WindowImpl::SetTitle(const String& title) + { + SDL_SetWindowTitle(m_handle, title.GetConstBuffer()); + } + + void WindowImpl::SetVisible(bool visible) + { + visible ? SDL_ShowWindow(m_handle) : SDL_HideWindow(m_handle); + } + + void WindowImpl::PrepareWindow(bool fullscreen) + { + (void)fullscreen; // ignore param warning + + SDL_GetWindowPosition(m_handle, &m_position.x, &m_position.y); + + int width, height; + SDL_GetWindowSize(m_handle, &width, &height); + + m_size.Set(width, height); + } + + bool WindowImpl::Initialize() + { + if (SDL_Init(SDL_INIT_VIDEO) < 0) + { + NazaraError(SDL_GetError()); + return false; + } + if (SDL_GL_LoadLibrary(nullptr) < 0) + { + NazaraError(SDL_GetError()); + + SDL_Quit(); + return false; + } + + if (SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, true) < 0) + NazaraError("Couldn't set share OpenGL contexes"); + + return true; + } + + void WindowImpl::Uninitialize() + { + SDL_Quit(); + } + + Keyboard::Key WindowImpl::SDLKeySymToNazaraKey(SDL_Keysym& keysym) + { + auto key = keysym.scancode; + + switch (key) + { + case SDL_SCANCODE_LCTRL: return Keyboard::LControl; + case SDL_SCANCODE_RCTRL: return Keyboard::RControl; + case SDL_SCANCODE_LALT: return Keyboard::LAlt; + case SDL_SCANCODE_RALT: return Keyboard::RAlt; + case SDL_SCANCODE_LSHIFT: return Keyboard::LShift; + case SDL_SCANCODE_RSHIFT: return Keyboard::RShift; + + case SDL_SCANCODE_0: return Keyboard::Num0; + case SDL_SCANCODE_1: return Keyboard::Num1; + case SDL_SCANCODE_2: return Keyboard::Num2; + case SDL_SCANCODE_3: return Keyboard::Num3; + case SDL_SCANCODE_4: return Keyboard::Num4; + case SDL_SCANCODE_5: return Keyboard::Num5; + case SDL_SCANCODE_6: return Keyboard::Num6; + case SDL_SCANCODE_7: return Keyboard::Num7; + case SDL_SCANCODE_8: return Keyboard::Num8; + case SDL_SCANCODE_9: return Keyboard::Num9; + case SDL_SCANCODE_A: return Keyboard::A; + case SDL_SCANCODE_B: return Keyboard::B; + case SDL_SCANCODE_C: return Keyboard::C; + case SDL_SCANCODE_D: return Keyboard::D; + case SDL_SCANCODE_E: return Keyboard::E; + case SDL_SCANCODE_F: return Keyboard::F; + case SDL_SCANCODE_G: return Keyboard::G; + case SDL_SCANCODE_H: return Keyboard::H; + case SDL_SCANCODE_I: return Keyboard::I; + case SDL_SCANCODE_J: return Keyboard::J; + case SDL_SCANCODE_K: return Keyboard::K; + case SDL_SCANCODE_L: return Keyboard::L; + case SDL_SCANCODE_M: return Keyboard::M; + case SDL_SCANCODE_N: return Keyboard::N; + case SDL_SCANCODE_O: return Keyboard::O; + case SDL_SCANCODE_P: return Keyboard::P; + case SDL_SCANCODE_Q: return Keyboard::Q; + case SDL_SCANCODE_R: return Keyboard::R; + case SDL_SCANCODE_S: return Keyboard::S; + case SDL_SCANCODE_T: return Keyboard::T; + case SDL_SCANCODE_U: return Keyboard::U; + case SDL_SCANCODE_V: return Keyboard::V; + case SDL_SCANCODE_W: return Keyboard::W; + case SDL_SCANCODE_X: return Keyboard::X; + case SDL_SCANCODE_Y: return Keyboard::Y; + case SDL_SCANCODE_Z: return Keyboard::Z; + case SDL_SCANCODE_KP_PLUS: return Keyboard::Add; + case SDL_SCANCODE_BACKSPACE: return Keyboard::Backspace; + case SDL_SCANCODE_AC_BACK: return Keyboard::Browser_Back; + case SDL_SCANCODE_AC_BOOKMARKS: return Keyboard::Browser_Favorites; + case SDL_SCANCODE_AC_FORWARD: return Keyboard::Browser_Forward; + case SDL_SCANCODE_AC_HOME: return Keyboard::Browser_Home; + case SDL_SCANCODE_AC_REFRESH: return Keyboard::Browser_Refresh; + case SDL_SCANCODE_AC_SEARCH: return Keyboard::Browser_Search; + case SDL_SCANCODE_AC_STOP: return Keyboard::Browser_Stop; + case SDL_SCANCODE_CAPSLOCK: return Keyboard::CapsLock; + case SDL_SCANCODE_CLEAR: return Keyboard::Clear; + case SDL_SCANCODE_KP_PERIOD: return Keyboard::Decimal; + case SDL_SCANCODE_DELETE: return Keyboard::Delete; + case SDL_SCANCODE_KP_DIVIDE: return Keyboard::Divide; + case SDL_SCANCODE_DOWN: return Keyboard::Down; + case SDL_SCANCODE_END: return Keyboard::End; + case SDL_SCANCODE_ESCAPE: return Keyboard::Escape; + case SDL_SCANCODE_F1: return Keyboard::F1; + case SDL_SCANCODE_F2: return Keyboard::F2; + case SDL_SCANCODE_F3: return Keyboard::F3; + case SDL_SCANCODE_F4: return Keyboard::F4; + case SDL_SCANCODE_F5: return Keyboard::F5; + case SDL_SCANCODE_F6: return Keyboard::F6; + case SDL_SCANCODE_F7: return Keyboard::F7; + case SDL_SCANCODE_F8: return Keyboard::F8; + case SDL_SCANCODE_F9: return Keyboard::F9; + case SDL_SCANCODE_F10: return Keyboard::F10; + case SDL_SCANCODE_F11: return Keyboard::F11; + case SDL_SCANCODE_F12: return Keyboard::F12; + case SDL_SCANCODE_F13: return Keyboard::F13; + case SDL_SCANCODE_F14: return Keyboard::F14; + case SDL_SCANCODE_F15: return Keyboard::F15; + case SDL_SCANCODE_HOME: return Keyboard::Home; + case SDL_SCANCODE_INSERT: return Keyboard::Insert; + case SDL_SCANCODE_LEFT: return Keyboard::Left; + case SDL_SCANCODE_LGUI: return Keyboard::LSystem; + case SDL_SCANCODE_AUDIONEXT: return Keyboard::Media_Next; + case SDL_SCANCODE_AUDIOPLAY: return Keyboard::Media_Play; + case SDL_SCANCODE_AUDIOPREV: return Keyboard::Media_Previous; + case SDL_SCANCODE_AUDIOSTOP: return Keyboard::Media_Stop; + case SDL_SCANCODE_KP_MULTIPLY: return Keyboard::Multiply; + case SDL_SCANCODE_PAGEDOWN: return Keyboard::PageDown; + case SDL_SCANCODE_KP_0: return Keyboard::Numpad0; + case SDL_SCANCODE_KP_1: return Keyboard::Numpad1; + case SDL_SCANCODE_KP_2: return Keyboard::Numpad2; + case SDL_SCANCODE_KP_3: return Keyboard::Numpad3; + case SDL_SCANCODE_KP_4: return Keyboard::Numpad4; + case SDL_SCANCODE_KP_5: return Keyboard::Numpad5; + case SDL_SCANCODE_KP_6: return Keyboard::Numpad6; + case SDL_SCANCODE_KP_7: return Keyboard::Numpad7; + case SDL_SCANCODE_KP_8: return Keyboard::Numpad8; + case SDL_SCANCODE_KP_9: return Keyboard::Numpad9; + case SDL_SCANCODE_NUMLOCKCLEAR: return Keyboard::NumLock; + case SDL_SCANCODE_SEMICOLON: return Keyboard::Semicolon; + case SDL_SCANCODE_SLASH: return Keyboard::Slash; + case SDL_SCANCODE_GRAVE: return Keyboard::Tilde; + case SDL_SCANCODE_APPLICATION: return Keyboard::Menu; + case SDL_SCANCODE_NONUSBACKSLASH: return Keyboard::ISOBackslash102; + case SDL_SCANCODE_LEFTBRACKET: return Keyboard::LBracket; + case SDL_SCANCODE_BACKSLASH: return Keyboard::Backslash; + case SDL_SCANCODE_RIGHTBRACKET: return Keyboard::RBracket; + case SDL_SCANCODE_APOSTROPHE: return Keyboard::Quote; + case SDL_SCANCODE_COMMA: return Keyboard::Comma; + case SDL_SCANCODE_MINUS: return Keyboard::Dash; + case SDL_SCANCODE_PERIOD: return Keyboard::Period; + case SDL_SCANCODE_EQUALS: return Keyboard::Equal; + case SDL_SCANCODE_RIGHT: return Keyboard::Right; + case SDL_SCANCODE_PAGEUP: return Keyboard::PageUp; + case SDL_SCANCODE_PAUSE: return Keyboard::Pause; + case SDL_SCANCODE_SYSREQ: return Keyboard::Print; + case SDL_SCANCODE_SCROLLLOCK: return Keyboard::ScrollLock; + case SDL_SCANCODE_PRINTSCREEN: return Keyboard::PrintScreen; + case SDL_SCANCODE_KP_MINUS: return Keyboard::Subtract; + case SDL_SCANCODE_RETURN: return Keyboard::Return; + case SDL_SCANCODE_KP_ENTER: return Keyboard::NumpadReturn; + case SDL_SCANCODE_RGUI: return Keyboard::RSystem; + case SDL_SCANCODE_SPACE: return Keyboard::Space; + case SDL_SCANCODE_TAB: return Keyboard::Tab; + case SDL_SCANCODE_UP: return Keyboard::Up; + case SDL_SCANCODE_VOLUMEDOWN: return Keyboard::Volume_Down; + case SDL_SCANCODE_MUTE: return Keyboard::Volume_Mute; + case SDL_SCANCODE_AUDIOMUTE: return Keyboard::Volume_Mute; + case SDL_SCANCODE_VOLUMEUP: return Keyboard::Volume_Up; + + default: + return Keyboard::Undefined; + } + } + + // not implemented for now, wait for mainloop friendly input + //void WindowImpl::WindowThread(SDL_Window* handle, /*DWORD styleEx,*/ const String& title, /*DWORD style,*/ bool fullscreen, const Rectui& dimensions, WindowImpl* window, Mutex* mutex, ConditionVariable* condition) + //{ + // SDL_Window& winHandle = *handle; + /*winHandle = CreateWindowExW(styleEx, className, title.GetWideString().data(), style, dimensions.x, dimensions.y, dimensions.width, dimensions.height, nullptr, nullptr, GetModuleHandle(nullptr), window); + + if (winHandle) + window->PrepareWindow(fullscreen); + + mutex->Lock(); + condition->Signal(); + mutex->Unlock(); // mutex and condition may be destroyed after this line + + if (!winHandle) + return; + + while (window->m_threadActive) + window->ProcessEvents(true); + + DestroyWindow(winHandle);*/ + //} +} diff --git a/src/Nazara/Platform/SDL2/WindowImpl.hpp b/src/Nazara/Platform/SDL2/WindowImpl.hpp new file mode 100644 index 000000000..b983d2881 --- /dev/null +++ b/src/Nazara/Platform/SDL2/WindowImpl.hpp @@ -0,0 +1,113 @@ +// Copyright (C) 2017 Jérôme Leclercq +// This file is part of the "Nazara Engine - Platform module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +// Interface inspirée de la SFML par Laurent Gomila + +#pragma once + +#ifndef NAZARA_WINDOWIMPL_HPP +#define NAZARA_WINDOWIMPL_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Nz +{ + class ConditionVariable; + class Mutex; + class Window; + + class WindowImpl + { + public: + WindowImpl(Window* parent); + WindowImpl(const WindowImpl&) = delete; + WindowImpl(WindowImpl&&) = delete; ///TODO? + ~WindowImpl() = default; + + bool Create(const VideoMode& mode, const String& title, WindowStyleFlags style); + bool Create(WindowHandle handle); + + void Destroy(); + + void EnableKeyRepeat(bool enable); + void EnableSmoothScrolling(bool enable); + + WindowHandle GetHandle() const; + Vector2i GetPosition() const; + Vector2ui GetSize() const; + WindowStyleFlags GetStyle() const; + String GetTitle() const; + + bool HasFocus() const; + + void IgnoreNextMouseEvent(int mouseX, int mouseY); + + bool IsMinimized() const; + bool IsVisible() const; + + void RefreshCursor(); + + void ProcessEvents(bool block); + + void SetCursor(const Cursor& cursor); + void SetEventListener(bool listener); + void SetFocus(); + void SetIcon(const Icon& icon); + void SetMaximumSize(int width, int height); + void SetMinimumSize(int width, int height); + void SetPosition(int x, int y); + void SetSize(unsigned int width, unsigned int height); + void SetStayOnTop(bool stayOnTop); + void SetTitle(const String& title); + void SetVisible(bool visible); + + WindowImpl& operator=(const WindowImpl&) = delete; + WindowImpl& operator=(WindowImpl&&) = delete; ///TODO? + + static bool Initialize(); + static void Uninitialize(); + + private: + int static SDLCALL HandleEvent(void *userdata, SDL_Event * event); + + void PrepareWindow(bool fullscreen); + + static Keyboard::Key SDLKeySymToNazaraKey(SDL_Keysym& keysym); + //static void WindowThread(SDL_Window* handle, /*DWORD styleEx,*/ const String& title, /*DWORD style,*/ bool fullscreen, const Rectui& dimensions, WindowImpl* window, Mutex* mutex, ConditionVariable* condition); + + SDL_Cursor* m_cursor; + SDL_Window* m_handle; + WindowStyleFlags m_style; + Vector2i m_maxSize; + Vector2i m_minSize; + Vector2i m_mousePos; + Vector2i m_position; + Vector2ui m_size; + //Thread m_thread; + Window* m_parent; + bool m_eventListener; + bool m_ignoreNextMouseMove = false; + bool m_keyRepeat; + bool m_mouseInside; + bool m_ownsWindow; + bool m_sizemove; + bool m_smoothScrolling; + bool m_threadActive; + short m_scrolling; + }; +} + +#endif // NAZARA_WINDOWIMPL_HPP diff --git a/src/Nazara/Platform/VideoMode.cpp b/src/Nazara/Platform/VideoMode.cpp index 5cc78d981..1cd8b0990 100644 --- a/src/Nazara/Platform/VideoMode.cpp +++ b/src/Nazara/Platform/VideoMode.cpp @@ -6,7 +6,9 @@ #include #include -#if defined(NAZARA_PLATFORM_WINDOWS) +#if defined(NAZARA_PLATFORM_SDL2) + #include +#elif defined(NAZARA_PLATFORM_WINDOWS) #include #elif defined(NAZARA_PLATFORM_X11) #include diff --git a/src/Nazara/Platform/Win32/InputImpl.cpp b/src/Nazara/Platform/Win32/InputImpl.cpp index f44594fa4..0858ec7a0 100644 --- a/src/Nazara/Platform/Win32/InputImpl.cpp +++ b/src/Nazara/Platform/Win32/InputImpl.cpp @@ -2,11 +2,11 @@ // This file is part of the "Nazara Engine - Platform module" // For conditions of distribution and use, see copyright notice in Config.hpp -#include #include +#include +#include #include #include -#include namespace Nz { @@ -42,115 +42,118 @@ namespace Nz 0x5A, // Key::Z // Touches de fonction - VK_F1, // Key::F1 - VK_F2, // Key::F2 - VK_F3, // Key::F3 - VK_F4, // Key::F4 - VK_F5, // Key::F5 - VK_F6, // Key::F6 - VK_F7, // Key::F7 - VK_F8, // Key::F8 - VK_F9, // Key::F9 - VK_F10, // Key::F10 - VK_F11, // Key::F11 - VK_F12, // Key::F12 - VK_F13, // Key::F13 - VK_F14, // Key::F14 - VK_F15, // Key::F15 + VK_F1, // Key::F1 + VK_F2, // Key::F2 + VK_F3, // Key::F3 + VK_F4, // Key::F4 + VK_F5, // Key::F5 + VK_F6, // Key::F6 + VK_F7, // Key::F7 + VK_F8, // Key::F8 + VK_F9, // Key::F9 + VK_F10, // Key::F10 + VK_F11, // Key::F11 + VK_F12, // Key::F12 + VK_F13, // Key::F13 + VK_F14, // Key::F14 + VK_F15, // Key::F15 // Flèches directionnelles VK_DOWN, // Key::Down VK_LEFT, // Key::Left VK_RIGHT, // Key::Right - VK_UP, // Key::Up + VK_UP, // Key::Up // Pavé numérique - VK_ADD, // Key::Add + VK_ADD, // Key::Add VK_DECIMAL, // Key::Decimal - VK_DIVIDE, // Key::Divide + VK_DIVIDE, // Key::Divide VK_MULTIPLY, // Key::Multiply - VK_NUMPAD0, // Key::Numpad0 - VK_NUMPAD1, // Key::Numpad1 - VK_NUMPAD2, // Key::Numpad2 - VK_NUMPAD3, // Key::Numpad3 - VK_NUMPAD4, // Key::Numpad4 - VK_NUMPAD5, // Key::Numpad5 - VK_NUMPAD6, // Key::Numpad6 - VK_NUMPAD7, // Key::Numpad7 - VK_NUMPAD8, // Key::Numpad8 - VK_NUMPAD9, // Key::Numpad9 + VK_RETURN, // Key::Multiply + VK_NUMPAD0, // Key::Numpad0 + VK_NUMPAD1, // Key::Numpad1 + VK_NUMPAD2, // Key::Numpad2 + VK_NUMPAD3, // Key::Numpad3 + VK_NUMPAD4, // Key::Numpad4 + VK_NUMPAD5, // Key::Numpad5 + VK_NUMPAD6, // Key::Numpad6 + VK_NUMPAD7, // Key::Numpad7 + VK_NUMPAD8, // Key::Numpad8 + VK_NUMPAD9, // Key::Numpad9 VK_SUBTRACT, // Key::Subtract // Diverss - VK_OEM_5, // Key::Backslash - VK_BACK, // Key::Backspace - VK_CLEAR, // Key::Clear + VK_OEM_5, // Key::Backslash + VK_BACK, // Key::Backspace + VK_CLEAR, // Key::Clear VK_OEM_COMMA, // Key::Comma, VK_OEM_MINUS, // Key::Dash - VK_DELETE, // Key::Delete - VK_END, // Key::End + VK_DELETE, // Key::Delete + VK_END, // Key::End VK_OEM_PLUS, // Key::Equal - VK_ESCAPE, // Key::Escape - VK_HOME, // Key::Home - VK_INSERT, // Key::Insert - VK_LMENU, // Key::LAlt - VK_OEM_4, // Key::LBracket + VK_ESCAPE, // Key::Escape + VK_HOME, // Key::Home + VK_INSERT, // Key::Insert + VK_LMENU, // Key::LAlt + VK_OEM_4, // Key::LBracket VK_LCONTROL, // Key::LControl - VK_LSHIFT, // Key::LShift - VK_LWIN, // Key::LSystem - 0x30, // Key::Num0 - 0x31, // Key::Num1 - 0x32, // Key::Num2 - 0x33, // Key::Num3 - 0x34, // Key::Num4 - 0x35, // Key::Num5 - 0x36, // Key::Num6 - 0x37, // Key::Num7 - 0x38, // Key::Num8 - 0x39, // Key::Num9 - VK_NEXT, // Key::PageDown - VK_PRIOR, // Key::PageUp - VK_PAUSE, // Key::Pause + VK_LSHIFT, // Key::LShift + VK_LWIN, // Key::LSystem + 0x30, // Key::Num0 + 0x31, // Key::Num1 + 0x32, // Key::Num2 + 0x33, // Key::Num3 + 0x34, // Key::Num4 + 0x35, // Key::Num5 + 0x36, // Key::Num6 + 0x37, // Key::Num7 + 0x38, // Key::Num8 + 0x39, // Key::Num9 + VK_NEXT, // Key::PageDown + VK_PRIOR, // Key::PageUp + VK_PAUSE, // Key::Pause VK_OEM_PERIOD, // Key::Period - VK_PRINT, // Key::Print + VK_PRINT, // Key::Print VK_SNAPSHOT, // Key::PrintScreen - VK_OEM_7, // Key::Quote - VK_RMENU, // Key::RAlt - VK_OEM_6, // Key::RBracket + VK_OEM_7, // Key::Quote + VK_RMENU, // Key::RAlt + VK_OEM_6, // Key::RBracket VK_RCONTROL, // Key::RControl - VK_RETURN, // Key::Return - VK_RSHIFT, // Key::RShift - VK_RWIN, // Key::RSystem - VK_OEM_1, // Key::Semicolon - VK_OEM_2, // Key::Slash - VK_SPACE, // Key::Space - VK_TAB, // Key::Tab - VK_OEM_3, // Key::Tilde + VK_RETURN, // Key::Return + VK_RSHIFT, // Key::RShift + VK_RWIN, // Key::RSystem + VK_OEM_1, // Key::Semicolon + VK_OEM_2, // Key::Slash + VK_SPACE, // Key::Space + VK_TAB, // Key::Tab + VK_OEM_3, // Key::Tilde + VK_APPS, // Key::Menu + VK_OEM_102, // Key::ISOBackslash102 // Touches navigateur - VK_BROWSER_BACK, // Key::Browser_Back + VK_BROWSER_BACK, // Key::Browser_Back VK_BROWSER_FAVORITES, // Key::Browser_Favorites - VK_BROWSER_FORWARD, // Key::Browser_Forward - VK_BROWSER_HOME, // Key::Browser_Home - VK_BROWSER_REFRESH, // Key::Browser_Refresh - VK_BROWSER_SEARCH, // Key::Browser_Search - VK_BROWSER_STOP, // Key::Browser_Stop + VK_BROWSER_FORWARD, // Key::Browser_Forward + VK_BROWSER_HOME, // Key::Browser_Home + VK_BROWSER_REFRESH, // Key::Browser_Refresh + VK_BROWSER_SEARCH, // Key::Browser_Search + VK_BROWSER_STOP, // Key::Browser_Stop // Touches de contrôle VK_MEDIA_NEXT_TRACK, // Key::Media_Next, VK_MEDIA_PLAY_PAUSE, // Key::Media_PlayPause, VK_MEDIA_PREV_TRACK, // Key::Media_Previous, - VK_MEDIA_STOP, // Key::Media_Stop, + VK_MEDIA_STOP, // Key::Media_Stop, // Touches de contrôle du volume - VK_VOLUME_DOWN, // Key::Volume_Down - VK_VOLUME_MUTE, // Key::Volume_Mute - VK_VOLUME_UP, // Key::Volume_Up + VK_VOLUME_DOWN, // Key::Volume_Down + VK_VOLUME_MUTE, // Key::Volume_Mute + VK_VOLUME_UP, // Key::Volume_Up // Touches à verrouillage - VK_CAPITAL, // Key::CapsLock - VK_NUMLOCK, // Key::NumLock - VK_SCROLL // Key::ScrollLock + VK_CAPITAL, // Key::CapsLock + VK_NUMLOCK, // Key::NumLock + VK_SCROLL // Key::ScrollLock }; } @@ -192,6 +195,7 @@ namespace Nz case VK_RIGHT: case VK_RWIN: case VK_UP: + case VK_RETURN: // TODO check code |= 0x1000000; // 24ème bit pour l'extension break; } @@ -247,17 +251,16 @@ namespace Nz bool EventImpl::IsMouseButtonPressed(Mouse::Button button) { - static int vButtons[Mouse::Max+1] = { - VK_LBUTTON, // Button::Left - VK_MBUTTON, // Button::Middle - VK_RBUTTON, // Button::Right + static int vButtons[Mouse::Max + 1] = { + VK_LBUTTON, // Button::Left + VK_MBUTTON, // Button::Middle + VK_RBUTTON, // Button::Right VK_XBUTTON1, // Button::XButton1 - VK_XBUTTON2 // Button::XButton2 + VK_XBUTTON2 // Button::XButton2 }; // Gestion de l'inversement des boutons de la souris if (GetSystemMetrics(SM_SWAPBUTTON)) - { switch (button) { case Mouse::Left: @@ -271,7 +274,6 @@ namespace Nz default: break; } - } return (GetAsyncKeyState(vButtons[button]) & 0x8000) != 0; } @@ -292,5 +294,5 @@ namespace Nz } else NazaraError("Invalid window handle"); - } + } } diff --git a/src/Nazara/Platform/Win32/WindowImpl.cpp b/src/Nazara/Platform/Win32/WindowImpl.cpp index 1e5135168..ad381c8f8 100644 --- a/src/Nazara/Platform/Win32/WindowImpl.cpp +++ b/src/Nazara/Platform/Win32/WindowImpl.cpp @@ -4,21 +4,21 @@ // Un grand merci à Laurent Gomila pour la SFML qui m'aura bien aidé à réaliser cette implémentation -#include +#include +#include #include #include #include #include #include #include +#include #include #include #include +#include #include -#include -#include #include -#include #ifdef _WIN64 #define GCL_HCURSOR GCLP_HCURSOR @@ -41,17 +41,17 @@ namespace Nz } WindowImpl::WindowImpl(Window* parent) : - m_cursor(nullptr), - m_handle(nullptr), - m_callback(0), - m_style(0), - m_maxSize(-1), - m_minSize(-1), - m_parent(parent), - m_keyRepeat(true), - m_mouseInside(false), - m_smoothScrolling(false), - m_scrolling(0) + m_cursor(nullptr), + m_handle(nullptr), + m_callback(0), + m_style(0), + m_maxSize(-1), + m_minSize(-1), + m_parent(parent), + m_keyRepeat(true), + m_mouseInside(false), + m_smoothScrolling(false), + m_scrolling(0) { m_cursor = static_cast(LoadImage(nullptr, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED)); } @@ -71,8 +71,8 @@ namespace Nz win32Mode.dmBitsPerPel = mode.bitsPerPixel; win32Mode.dmPelsHeight = mode.height; win32Mode.dmPelsWidth = mode.width; - win32Mode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; - win32Mode.dmSize = sizeof(DEVMODE); + win32Mode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; + win32Mode.dmSize = sizeof(DEVMODE); if (ChangeDisplaySettings(&win32Mode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { @@ -114,11 +114,11 @@ namespace Nz RECT rect = {0, 0, static_cast(width), static_cast(height)}; AdjustWindowRect(&rect, win32Style, false); - width = rect.right-rect.left; - height = rect.bottom-rect.top; + width = rect.right - rect.left; + height = rect.bottom - rect.top; - x = (GetSystemMetrics(SM_CXSCREEN) - width)/2; - y = (GetSystemMetrics(SM_CYSCREEN) - height)/2; + x = (GetSystemMetrics(SM_CXSCREEN) - width) / 2; + y = (GetSystemMetrics(SM_CYSCREEN) - height) / 2; } m_callback = 0; @@ -175,7 +175,7 @@ namespace Nz GetWindowRect(m_handle, &windowRect); m_position.Set(windowRect.left, windowRect.top); - m_size.Set(clientRect.right-clientRect.left, clientRect.bottom-clientRect.top); + m_size.Set(clientRect.right - clientRect.left, clientRect.bottom - clientRect.top); return true; } @@ -194,11 +194,8 @@ namespace Nz m_thread.Join(); } } - else - { - if (m_handle) - DestroyWindow(m_handle); - } + else if (m_handle) + DestroyWindow(m_handle); } else SetEventListener(false); @@ -338,12 +335,12 @@ namespace Nz AdjustWindowRect(&rect, static_cast(GetWindowLongPtr(m_handle, GWL_STYLE)), false); if (width != -1) - m_maxSize.x = rect.right-rect.left; + m_maxSize.x = rect.right - rect.left; else m_maxSize.x = -1; if (height != -1) - m_maxSize.y = rect.bottom-rect.top; + m_maxSize.y = rect.bottom - rect.top; else m_maxSize.y = -1; } @@ -354,12 +351,12 @@ namespace Nz AdjustWindowRect(&rect, static_cast(GetWindowLongPtr(m_handle, GWL_STYLE)), false); if (width != -1) - m_minSize.x = rect.right-rect.left; + m_minSize.x = rect.right - rect.left; else m_minSize.x = -1; if (height != -1) - m_minSize.y = rect.bottom-rect.top; + m_minSize.y = rect.bottom - rect.top; else m_minSize.y = -1; } @@ -411,11 +408,11 @@ namespace Nz break; /*case WM_SETCURSOR: - // http://msdn.microsoft.com/en-us/library/windows/desktop/ms648382(v=vs.85).aspx - if (LOWORD(lParam) == HTCLIENT) - ::SetCursor(m_cursor); + // http://msdn.microsoft.com/en-us/library/windows/desktop/ms648382(v=vs.85).aspx + if (LOWORD(lParam) == HTCLIENT) + ::SetCursor(m_cursor); - break;*/ + break;*/ case WM_WINDOWPOSCHANGING: { @@ -438,7 +435,6 @@ namespace Nz } if (m_eventListener) - { switch (message) { case WM_CHAR: @@ -497,7 +493,7 @@ namespace Nz m_parent->PushEvent(event); } - Vector2ui size(clientRect.right-clientRect.left, clientRect.bottom-clientRect.top); + Vector2ui size(clientRect.right - clientRect.left, clientRect.bottom - clientRect.top); if (m_size != size) { m_size = size; @@ -712,7 +708,7 @@ namespace Nz { WindowEvent event; event.type = WindowEventType_MouseWheelMoved; - event.mouseWheel.delta = static_cast(GET_WHEEL_DELTA_WPARAM(wParam))/WHEEL_DELTA; + event.mouseWheel.delta = static_cast(GET_WHEEL_DELTA_WPARAM(wParam)) / WHEEL_DELTA; m_parent->PushEvent(event); } else @@ -722,7 +718,7 @@ namespace Nz { WindowEvent event; event.type = WindowEventType_MouseWheelMoved; - event.mouseWheel.delta = static_cast(m_scrolling/WHEEL_DELTA); + event.mouseWheel.delta = static_cast(m_scrolling / WHEEL_DELTA); m_parent->PushEvent(event); m_scrolling %= WHEEL_DELTA; @@ -813,7 +809,7 @@ namespace Nz RECT rect; GetClientRect(m_handle, &rect); - Vector2ui size(rect.right-rect.left, rect.bottom-rect.top); // On récupère uniquement la taille de la zone client + Vector2ui size(rect.right - rect.left, rect.bottom - rect.top); // On récupère uniquement la taille de la zone client if (m_size == size) break; @@ -903,7 +899,6 @@ namespace Nz default: break; } - } #if NAZARA_PLATFORM_WINDOWS_DISABLE_MENU_KEYS // http://msdn.microsoft.com/en-us/library/windows/desktop/ms646360(v=vs.85).aspx @@ -959,8 +954,9 @@ namespace Nz { switch (key) { - case VK_CONTROL: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::RControl : Keyboard::LControl; - case VK_MENU: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::RAlt : Keyboard::LAlt; + case VK_CONTROL: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::RControl : Keyboard::LControl; + case VK_MENU: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::RAlt : Keyboard::LAlt; + case VK_RETURN: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::NumpadReturn : Keyboard::Return; // TODO Check case VK_SHIFT: { static UINT scancode = MapVirtualKey(VK_SHIFT, MAPVK_VK_TO_VSC); @@ -1059,6 +1055,8 @@ namespace Nz case VK_OEM_1: return Keyboard::Semicolon; case VK_OEM_2: return Keyboard::Slash; case VK_OEM_3: return Keyboard::Tilde; + case VK_APPS: return Keyboard::Menu; + case VK_OEM_102: return Keyboard::ISOBackslash102; case VK_OEM_4: return Keyboard::LBracket; case VK_OEM_5: return Keyboard::Backslash; case VK_OEM_6: return Keyboard::RBracket; @@ -1074,7 +1072,6 @@ namespace Nz case VK_SCROLL: return Keyboard::ScrollLock; case VK_SNAPSHOT: return Keyboard::PrintScreen; case VK_SUBTRACT: return Keyboard::Subtract; - case VK_RETURN: return Keyboard::Return; case VK_RWIN: return Keyboard::RSystem; case VK_SPACE: return Keyboard::Space; case VK_TAB: return Keyboard::Tab; @@ -1137,10 +1134,8 @@ namespace Nz RECT rect; if (GetWindowRect(handle, &rect)) - { - if (static_cast(rect.right-rect.left) == mode.dmPelsWidth && static_cast(rect.bottom-rect.top) == mode.dmPelsHeight) + if (static_cast(rect.right - rect.left) == mode.dmPelsWidth && static_cast(rect.bottom - rect.top) == mode.dmPelsHeight) style |= WindowStyle_Fullscreen; - } return style; } diff --git a/src/Nazara/Platform/Window.cpp b/src/Nazara/Platform/Window.cpp index 9ce743ad4..47c93d290 100644 --- a/src/Nazara/Platform/Window.cpp +++ b/src/Nazara/Platform/Window.cpp @@ -9,7 +9,9 @@ #include #include -#if defined(NAZARA_PLATFORM_WINDOWS) +#if defined(NAZARA_PLATFORM_SDL2) + #include +#elif defined(NAZARA_PLATFORM_WINDOWS) #include #elif defined(NAZARA_PLATFORM_X11) #include diff --git a/src/Nazara/Platform/X11/InputImpl.cpp b/src/Nazara/Platform/X11/InputImpl.cpp index 152ba0337..5787e2d86 100644 --- a/src/Nazara/Platform/X11/InputImpl.cpp +++ b/src/Nazara/Platform/X11/InputImpl.cpp @@ -79,6 +79,7 @@ namespace Nz case Keyboard::Decimal: keysym = XK_KP_Decimal; break; case Keyboard::Divide: keysym = XK_KP_Divide; break; case Keyboard::Multiply: keysym = XK_KP_Multiply; break; + case Keyboard::NumpadReturn: keysym = XK_KP_Enter; break; case Keyboard::Numpad0: keysym = XK_KP_0; break; case Keyboard::Numpad1: keysym = XK_KP_1; break; case Keyboard::Numpad2: keysym = XK_KP_2; break; @@ -136,6 +137,8 @@ namespace Nz case Keyboard::Space: keysym = XK_space; break; case Keyboard::Tab: keysym = XK_Tab; break; case Keyboard::Tilde: keysym = XK_grave; break; + case Keyboard::Menu: keysym = XK_Menu; break; + case Keyboard::ISOBackslash102: keysym = XK_less; break; // Touches navigateur case Keyboard::Browser_Back: keysym = XF86XK_Back; break; diff --git a/src/Nazara/Platform/X11/WindowImpl.cpp b/src/Nazara/Platform/X11/WindowImpl.cpp index 0e8215e37..eda4453ea 100644 --- a/src/Nazara/Platform/X11/WindowImpl.cpp +++ b/src/Nazara/Platform/X11/WindowImpl.cpp @@ -4,10 +4,10 @@ // Un grand merci à Laurent Gomila pour la SFML qui m'aura bien aidé à réaliser cette implémentation -#include #include #include #include +#include #include #include #include @@ -15,14 +15,14 @@ #include #include #include +#include +#include #include #include #include -#include -#include /* - Things to do left: + Things to do left: Icon working sometimes (No idea) EnableKeyRepeat (Working but is it the right behaviour ?) @@ -35,7 +35,7 @@ SetStayOnTop (Equivalent for X11 ?) Opengl Context (glXCreateContextAttribs should be loaded like in window and the version for the context should be the one of NzContextParameters) -*/ + */ namespace Nz { @@ -44,21 +44,21 @@ namespace Nz Nz::WindowImpl* fullscreenWindow = nullptr; const uint32_t eventMask = XCB_EVENT_MASK_FOCUS_CHANGE | XCB_EVENT_MASK_BUTTON_PRESS | - XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_BUTTON_MOTION | - XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_KEY_PRESS | - XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_STRUCTURE_NOTIFY | - XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW; + XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_BUTTON_MOTION | + XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_KEY_PRESS | + XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_STRUCTURE_NOTIFY | + XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW; xcb_connection_t* connection = nullptr; } WindowImpl::WindowImpl(Window* parent) : - m_window(0), - m_style(0), - m_parent(parent), - m_smoothScrolling(false), - m_mousePos(0, 0), - m_keyRepeat(true) + m_window(0), + m_style(0), + m_parent(parent), + m_smoothScrolling(false), + m_mousePos(0, 0), + m_keyRepeat(true) { std::memset(&m_size_hints, 0, sizeof(m_size_hints)); } @@ -96,34 +96,34 @@ namespace Nz const uint32_t value_list[] = { fullscreen, eventMask, colormap }; CallOnExit onExit([&](){ - if (!X11::CheckCookie( - connection, - xcb_free_colormap( - connection, - colormap - )) - ) - NazaraError("Failed to free colormap"); - }); + if (!X11::CheckCookie( + connection, + xcb_free_colormap( + connection, + colormap + )) + ) + NazaraError("Failed to free colormap"); + }); // Create the window m_window = xcb_generate_id(connection); if (!X11::CheckCookie( - connection, - xcb_create_window_checked( connection, - XCB_COPY_FROM_PARENT, - m_window, - m_screen->root, - left, top, - width, height, - 0, - XCB_WINDOW_CLASS_INPUT_OUTPUT, - m_screen->root_visual, - XCB_CW_EVENT_MASK | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_COLORMAP, - value_list - ))) + xcb_create_window_checked( + connection, + XCB_COPY_FROM_PARENT, + m_window, + m_screen->root, + left, top, + width, height, + 0, + XCB_WINDOW_CLASS_INPUT_OUTPUT, + m_screen->root_visual, + XCB_CW_EVENT_MASK | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_COLORMAP, + value_list + ))) { NazaraError("Failed to create window"); return false; @@ -141,7 +141,7 @@ namespace Nz m_window), &m_size_hints, &error - ); + ); if (error) NazaraError("Failed to get size hints"); @@ -215,7 +215,7 @@ namespace Nz m_window), &m_size_hints, &error - ); + ); if (error) { @@ -237,13 +237,11 @@ namespace Nz if (m_ownsWindow) { if (m_style & WindowStyle_Threaded) - { if (m_thread.IsJoinable()) { m_threadActive = false; m_thread.Join(); } - } // Destroy the window if (m_window && m_ownsWindow) @@ -252,11 +250,11 @@ namespace Nz SetCursor(*Cursor::Get(SystemCursor_Default)); if (!X11::CheckCookie( - connection, - xcb_destroy_window( connection, - m_window - ))) + xcb_destroy_window( + connection, + m_window + ))) NazaraError("Failed to destroy window"); xcb_flush(connection); @@ -309,7 +307,7 @@ namespace Nz xcb_ewmh_get_utf8_strings_reply_t data; xcb_ewmh_get_wm_name_reply(ewmhConnection, - xcb_ewmh_get_wm_name(ewmhConnection, m_window), &data, &error); + xcb_ewmh_get_wm_name(ewmhConnection, m_window), &data, &error); if (error) NazaraError("Failed to get window's title"); @@ -331,17 +329,17 @@ namespace Nz ScopedXCB error(nullptr); ScopedXCB reply(xcb_get_input_focus_reply( - connection, - xcb_get_input_focus_unchecked( - connection - ), - &error - )); + connection, + xcb_get_input_focus_unchecked( + connection + ), + &error + )); if (error) NazaraError("Failed to check if window has focus"); - return (reply->focus == m_window); + return reply->focus == m_window; } void WindowImpl::IgnoreNextMouseEvent(int mouseX, int mouseY) @@ -360,7 +358,7 @@ namespace Nz xcb_ewmh_get_atoms_reply_t atomReply; if (xcb_ewmh_get_wm_state_reply(ewmhConnection, - xcb_ewmh_get_wm_state(ewmhConnection, m_window), &atomReply, &error) == 1) + xcb_ewmh_get_wm_state(ewmhConnection, m_window), &atomReply, &error) == 1) { for (unsigned int i = 0; i < atomReply.atoms_len; i++) if (atomReply.atoms[i] == ewmhConnection->_NET_WM_STATE_HIDDEN) @@ -436,14 +434,14 @@ namespace Nz const uint32_t value_list[] = { eventMask }; if (!X11::CheckCookie( - connection, - xcb_change_window_attributes( connection, - m_window, - XCB_CW_EVENT_MASK, - value_list - )) - ) + xcb_change_window_attributes( + connection, + m_window, + XCB_CW_EVENT_MASK, + value_list + )) + ) NazaraError("Failed to change event for listener"); m_eventListener = true; @@ -453,14 +451,14 @@ namespace Nz const uint32_t value_list[] = { XCB_EVENT_MASK_NO_EVENT }; if (!X11::CheckCookie( - connection, - xcb_change_window_attributes( connection, - m_window, - XCB_CW_EVENT_MASK, - value_list - )) - ) + xcb_change_window_attributes( + connection, + m_window, + XCB_CW_EVENT_MASK, + value_list + )) + ) NazaraError("Failed to change event for listener"); m_eventListener = false; @@ -471,27 +469,27 @@ namespace Nz void WindowImpl::SetFocus() { if (!X11::CheckCookie( - connection, - xcb_set_input_focus( connection, - XCB_INPUT_FOCUS_POINTER_ROOT, - m_window, - XCB_CURRENT_TIME - )) - ) + xcb_set_input_focus( + connection, + XCB_INPUT_FOCUS_POINTER_ROOT, + m_window, + XCB_CURRENT_TIME + )) + ) NazaraError("Failed to set input focus"); const uint32_t values[] = { XCB_STACK_MODE_ABOVE }; if (!X11::CheckCookie( - connection, - xcb_configure_window( connection, - m_window, - XCB_CONFIG_WINDOW_STACK_MODE, - values - )) - ) + xcb_configure_window( + connection, + m_window, + XCB_CONFIG_WINDOW_STACK_MODE, + values + )) + ) NazaraError("Failed to set focus"); } @@ -518,7 +516,7 @@ namespace Nz m_window), &hints, &error - ); + ); if (error) NazaraError("Failed to get wm hints"); @@ -527,13 +525,13 @@ namespace Nz xcb_icccm_wm_hints_set_icon_mask(&hints, mask_pixmap); if (!X11::CheckCookie( - connection, - xcb_icccm_set_wm_hints( connection, - m_window, - &hints - )) - ) + xcb_icccm_set_wm_hints( + connection, + m_window, + &hints + )) + ) NazaraError("Failed to set wm hints"); xcb_flush(connection); @@ -570,14 +568,14 @@ namespace Nz const uint32_t values[] = { static_cast(x), static_cast(y) }; if (!X11::CheckCookie( - connection, - xcb_configure_window( connection, - m_window, - XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, - values - )) - ) + xcb_configure_window( + connection, + m_window, + XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, + values + )) + ) NazaraError("Failed to set position"); xcb_flush(connection); @@ -591,14 +589,14 @@ namespace Nz const uint32_t values[] = { width, height }; if (!X11::CheckCookie( - connection, - xcb_configure_window( connection, - m_window, - XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, - values - )) - ) + xcb_configure_window( + connection, + m_window, + XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, + values + )) + ) NazaraError("Failed to set sizes"); xcb_flush(connection); @@ -615,14 +613,14 @@ namespace Nz onTop = ewmhConnection->_NET_WM_STATE_BELOW; if (!X11::CheckCookie( - connection, - xcb_ewmh_set_wm_state( - ewmhConnection, - m_window, - 1, - &onTop - )) - ) + connection, + xcb_ewmh_set_wm_state( + ewmhConnection, + m_window, + 1, + &onTop + )) + ) NazaraError("Failed to set stay on top"); xcb_flush(connection); @@ -633,14 +631,14 @@ namespace Nz ScopedXCBEWMHConnection ewmhConnection(connection); if (!X11::CheckCookie( - connection, - xcb_ewmh_set_wm_name( - ewmhConnection, - m_window, - title.GetSize(), - title.GetConstBuffer() - )) - ) + connection, + xcb_ewmh_set_wm_name( + ewmhConnection, + m_window, + title.GetSize(), + title.GetConstBuffer() + )) + ) NazaraError("Failed to set title"); xcb_flush(connection); @@ -651,25 +649,22 @@ namespace Nz if (visible) { if (!X11::CheckCookie( - connection, - xcb_map_window( connection, - m_window - )) - ) + xcb_map_window( + connection, + m_window + )) + ) NazaraError("Failed to change window visibility to visible"); } - else - { - if (!X11::CheckCookie( - connection, - xcb_unmap_window( - connection, - m_window - )) - ) - NazaraError("Failed to change window visibility to invisible"); - } + else if (!X11::CheckCookie( + connection, + xcb_unmap_window( + connection, + m_window + )) + ) + NazaraError("Failed to change window visibility to invisible"); xcb_flush(connection); } @@ -708,8 +703,8 @@ namespace Nz xcb_keysym_t k0, k1; CallOnExit onExit([&](){ - X11::XCBKeySymbolsFree(keysyms); - }); + X11::XCBKeySymbolsFree(keysyms); + }); // Based on documentation in https://cgit.freedesktop.org/xcb/util-keysyms/tree/keysyms/keysyms.c // Mode switch = ctlr and alt gr = XCB_MOD_MASK_5 @@ -736,41 +731,41 @@ namespace Nz k1 = k0; /* The numlock modifier is on and the second KeySym is a keypad KeySym - The numlock modifier is on and the second KeySym is a keypad KeySym. In - this case, if the Shift modifier is on, or if the Lock modifier is on - and is interpreted as ShiftLock, then the first KeySym is used, - otherwise the second KeySym is used. - */ + The numlock modifier is on and the second KeySym is a keypad KeySym. In + this case, if the Shift modifier is on, or if the Lock modifier is on + and is interpreted as ShiftLock, then the first KeySym is used, + otherwise the second KeySym is used. + */ if ((state & XCB_MOD_MASK_2) && xcb_is_keypad_key(k1)) { - if ((state & XCB_MOD_MASK_SHIFT) || (state & XCB_MOD_MASK_LOCK && (state & XCB_MOD_MASK_SHIFT))) + if ((state & XCB_MOD_MASK_SHIFT) || (state & XCB_MOD_MASK_LOCK && (state & XCB_MOD_MASK_SHIFT))) return k0; else return k1; } /* The Shift and Lock modifiers are both off. In this case, the first - KeySym is used.*/ + KeySym is used.*/ else if (!(state & XCB_MOD_MASK_SHIFT) && !(state & XCB_MOD_MASK_LOCK)) return k0; /* The Shift modifier is off, and the Lock modifier is on and is - interpreted as CapsLock. In this case, the first KeySym is used, but - if that KeySym is lowercase alphabetic, then the corresponding - uppercase KeySym is used instead. */ + interpreted as CapsLock. In this case, the first KeySym is used, but + if that KeySym is lowercase alphabetic, then the corresponding + uppercase KeySym is used instead. */ else if (!(state & XCB_MOD_MASK_SHIFT) && (state & XCB_MOD_MASK_LOCK && (state & XCB_MOD_MASK_SHIFT))) return k0; /* The Shift modifier is on, and the Lock modifier is on and is - interpreted as CapsLock. In this case, the second KeySym is used, but - if that KeySym is lowercase alphabetic, then the corresponding - uppercase KeySym is used instead.*/ + interpreted as CapsLock. In this case, the second KeySym is used, but + if that KeySym is lowercase alphabetic, then the corresponding + uppercase KeySym is used instead.*/ else if ((state & XCB_MOD_MASK_SHIFT) && (state & XCB_MOD_MASK_LOCK && (state & XCB_MOD_MASK_SHIFT))) return k1; /* The Shift modifier is on, or the Lock modifier is on and is - interpreted as ShiftLock, or both. In this case, the second KeySym is - used. */ + interpreted as ShiftLock, or both. In this case, the second KeySym is + used. */ else if ((state & XCB_MOD_MASK_SHIFT) || (state & XCB_MOD_MASK_LOCK && (state & XCB_MOD_MASK_SHIFT))) return k1; @@ -785,149 +780,151 @@ namespace Nz switch (key) { - // Lettres - case XK_A: return Keyboard::A; - case XK_B: return Keyboard::B; - case XK_C: return Keyboard::C; - case XK_D: return Keyboard::D; - case XK_E: return Keyboard::E; - case XK_F: return Keyboard::F; - case XK_G: return Keyboard::G; - case XK_H: return Keyboard::H; - case XK_I: return Keyboard::I; - case XK_J: return Keyboard::J; - case XK_K: return Keyboard::K; - case XK_L: return Keyboard::L; - case XK_M: return Keyboard::M; - case XK_N: return Keyboard::N; - case XK_O: return Keyboard::O; - case XK_P: return Keyboard::P; - case XK_Q: return Keyboard::Q; - case XK_R: return Keyboard::R; - case XK_S: return Keyboard::S; - case XK_T: return Keyboard::T; - case XK_U: return Keyboard::U; - case XK_V: return Keyboard::V; - case XK_W: return Keyboard::W; - case XK_X: return Keyboard::X; - case XK_Y: return Keyboard::Y; - case XK_Z: return Keyboard::Z; + // Lettres + case XK_A: return Keyboard::A; + case XK_B: return Keyboard::B; + case XK_C: return Keyboard::C; + case XK_D: return Keyboard::D; + case XK_E: return Keyboard::E; + case XK_F: return Keyboard::F; + case XK_G: return Keyboard::G; + case XK_H: return Keyboard::H; + case XK_I: return Keyboard::I; + case XK_J: return Keyboard::J; + case XK_K: return Keyboard::K; + case XK_L: return Keyboard::L; + case XK_M: return Keyboard::M; + case XK_N: return Keyboard::N; + case XK_O: return Keyboard::O; + case XK_P: return Keyboard::P; + case XK_Q: return Keyboard::Q; + case XK_R: return Keyboard::R; + case XK_S: return Keyboard::S; + case XK_T: return Keyboard::T; + case XK_U: return Keyboard::U; + case XK_V: return Keyboard::V; + case XK_W: return Keyboard::W; + case XK_X: return Keyboard::X; + case XK_Y: return Keyboard::Y; + case XK_Z: return Keyboard::Z; - // Touches de fonction - case XK_F1: return Keyboard::F1; - case XK_F2: return Keyboard::F2; - case XK_F3: return Keyboard::F3; - case XK_F4: return Keyboard::F4; - case XK_F5: return Keyboard::F5; - case XK_F6: return Keyboard::F6; - case XK_F7: return Keyboard::F7; - case XK_F8: return Keyboard::F8; - case XK_F9: return Keyboard::F9; - case XK_F10: return Keyboard::F10; - case XK_F11: return Keyboard::F11; - case XK_F12: return Keyboard::F12; - case XK_F13: return Keyboard::F13; - case XK_F14: return Keyboard::F14; - case XK_F15: return Keyboard::F15; + // Touches de fonction + case XK_F1: return Keyboard::F1; + case XK_F2: return Keyboard::F2; + case XK_F3: return Keyboard::F3; + case XK_F4: return Keyboard::F4; + case XK_F5: return Keyboard::F5; + case XK_F6: return Keyboard::F6; + case XK_F7: return Keyboard::F7; + case XK_F8: return Keyboard::F8; + case XK_F9: return Keyboard::F9; + case XK_F10: return Keyboard::F10; + case XK_F11: return Keyboard::F11; + case XK_F12: return Keyboard::F12; + case XK_F13: return Keyboard::F13; + case XK_F14: return Keyboard::F14; + case XK_F15: return Keyboard::F15; - // Flèches directionnelles - case XK_Down: return Keyboard::Down; - case XK_Left: return Keyboard::Left; - case XK_Right: return Keyboard::Right; - case XK_Up: return Keyboard::Up; + // Flèches directionnelles + case XK_Down: return Keyboard::Down; + case XK_Left: return Keyboard::Left; + case XK_Right: return Keyboard::Right; + case XK_Up: return Keyboard::Up; - // Pavé numérique - case XK_KP_Add: return Keyboard::Add; - case XK_KP_Decimal: return Keyboard::Decimal; - case XK_KP_Delete: return Keyboard::Decimal; - case XK_KP_Divide: return Keyboard::Divide; - case XK_KP_Multiply: return Keyboard::Multiply; - case XK_KP_Insert: return Keyboard::Numpad0; - case XK_KP_End: return Keyboard::Numpad1; - case XK_KP_Down: return Keyboard::Numpad2; - case XK_KP_Page_Down: return Keyboard::Numpad3; - case XK_KP_Left: return Keyboard::Numpad4; - case XK_KP_Begin: return Keyboard::Numpad5; - case XK_KP_Right: return Keyboard::Numpad6; - case XK_KP_Home: return Keyboard::Numpad7; - case XK_KP_Up: return Keyboard::Numpad8; - case XK_KP_Page_Up: return Keyboard::Numpad9; - case XK_KP_Enter: return Keyboard::Return; - case XK_KP_Subtract: return Keyboard::Subtract; + // Pavé numérique + case XK_KP_Add: return Keyboard::Add; + case XK_KP_Decimal: return Keyboard::Decimal; + case XK_KP_Delete: return Keyboard::Decimal; + case XK_KP_Divide: return Keyboard::Divide; + case XK_KP_Multiply: return Keyboard::Multiply; + case XK_KP_Insert: return Keyboard::Numpad0; + case XK_KP_End: return Keyboard::Numpad1; + case XK_KP_Down: return Keyboard::Numpad2; + case XK_KP_Page_Down: return Keyboard::Numpad3; + case XK_KP_Left: return Keyboard::Numpad4; + case XK_KP_Begin: return Keyboard::Numpad5; + case XK_KP_Right: return Keyboard::Numpad6; + case XK_KP_Home: return Keyboard::Numpad7; + case XK_KP_Up: return Keyboard::Numpad8; + case XK_KP_Page_Up: return Keyboard::Numpad9; + case XK_KP_Enter: return Keyboard::NumpadReturn; + case XK_KP_Subtract: return Keyboard::Subtract; - // Divers - case XK_backslash: return Keyboard::Backslash; - case XK_BackSpace: return Keyboard::Backspace; - case XK_Clear: return Keyboard::Clear; - case XK_comma: return Keyboard::Comma; - case XK_minus: return Keyboard::Dash; - case XK_Delete: return Keyboard::Delete; - case XK_End: return Keyboard::End; - case XK_equal: return Keyboard::Equal; - case XK_Escape: return Keyboard::Escape; - case XK_Home: return Keyboard::Home; - case XK_Insert: return Keyboard::Insert; - case XK_Alt_L: return Keyboard::LAlt; - case XK_bracketleft: return Keyboard::LBracket; - case XK_Control_L: return Keyboard::LControl; - case XK_Shift_L: return Keyboard::LShift; - case XK_Super_L: return Keyboard::LSystem; - case XK_0: return Keyboard::Num0; - case XK_1: return Keyboard::Num1; - case XK_2: return Keyboard::Num2; - case XK_3: return Keyboard::Num3; - case XK_4: return Keyboard::Num4; - case XK_5: return Keyboard::Num5; - case XK_6: return Keyboard::Num6; - case XK_7: return Keyboard::Num7; - case XK_8: return Keyboard::Num8; - case XK_9: return Keyboard::Num9; - case XK_Page_Down: return Keyboard::PageDown; - case XK_Page_Up: return Keyboard::PageUp; - case XK_Pause: return Keyboard::Pause; - case XK_period: return Keyboard::Period; - case XK_Print: return Keyboard::Print; - case XK_Sys_Req: return Keyboard::PrintScreen; - case XK_quotedbl: return Keyboard::Quote; - case XK_Alt_R: return Keyboard::RAlt; - case XK_bracketright: return Keyboard::RBracket; - case XK_Control_R: return Keyboard::RControl; - case XK_Return: return Keyboard::Return; - case XK_Shift_R: return Keyboard::RShift; - case XK_Super_R: return Keyboard::RSystem; - case XK_semicolon: return Keyboard::Semicolon; - case XK_slash: return Keyboard::Slash; - case XK_space: return Keyboard::Space; - case XK_Tab: return Keyboard::Tab; - case XK_grave: return Keyboard::Tilde; + // Divers + case XK_backslash: return Keyboard::Backslash; + case XK_BackSpace: return Keyboard::Backspace; + case XK_Clear: return Keyboard::Clear; + case XK_comma: return Keyboard::Comma; + case XK_minus: return Keyboard::Dash; + case XK_Delete: return Keyboard::Delete; + case XK_End: return Keyboard::End; + case XK_equal: return Keyboard::Equal; + case XK_Escape: return Keyboard::Escape; + case XK_Home: return Keyboard::Home; + case XK_Insert: return Keyboard::Insert; + case XK_Alt_L: return Keyboard::LAlt; + case XK_bracketleft: return Keyboard::LBracket; + case XK_Control_L: return Keyboard::LControl; + case XK_Shift_L: return Keyboard::LShift; + case XK_Super_L: return Keyboard::LSystem; + case XK_0: return Keyboard::Num0; + case XK_1: return Keyboard::Num1; + case XK_2: return Keyboard::Num2; + case XK_3: return Keyboard::Num3; + case XK_4: return Keyboard::Num4; + case XK_5: return Keyboard::Num5; + case XK_6: return Keyboard::Num6; + case XK_7: return Keyboard::Num7; + case XK_8: return Keyboard::Num8; + case XK_9: return Keyboard::Num9; + case XK_Page_Down: return Keyboard::PageDown; + case XK_Page_Up: return Keyboard::PageUp; + case XK_Pause: return Keyboard::Pause; + case XK_period: return Keyboard::Period; + case XK_Print: return Keyboard::Print; + case XK_Sys_Req: return Keyboard::PrintScreen; + case XK_quotedbl: return Keyboard::Quote; + case XK_Alt_R: return Keyboard::RAlt; + case XK_bracketright: return Keyboard::RBracket; + case XK_Control_R: return Keyboard::RControl; + case XK_Return: return Keyboard::Return; + case XK_Shift_R: return Keyboard::RShift; + case XK_Super_R: return Keyboard::RSystem; + case XK_semicolon: return Keyboard::Semicolon; + case XK_slash: return Keyboard::Slash; + case XK_space: return Keyboard::Space; + case XK_Tab: return Keyboard::Tab; + case XK_grave: return Keyboard::Tilde; + case XK_Menu: return Keyboard::Menu; + case XK_less: return Keyboard::ISOBackslash102; - // Touches navigateur - case XF86XK_Back: return Keyboard::Browser_Back; - case XF86XK_Favorites: return Keyboard::Browser_Favorites; - case XF86XK_Forward: return Keyboard::Browser_Forward; - case XF86XK_HomePage: return Keyboard::Browser_Home; - case XF86XK_Refresh: return Keyboard::Browser_Refresh; - case XF86XK_Search: return Keyboard::Browser_Search; - case XF86XK_Stop: return Keyboard::Browser_Stop; + // Touches navigateur + case XF86XK_Back: return Keyboard::Browser_Back; + case XF86XK_Favorites: return Keyboard::Browser_Favorites; + case XF86XK_Forward: return Keyboard::Browser_Forward; + case XF86XK_HomePage: return Keyboard::Browser_Home; + case XF86XK_Refresh: return Keyboard::Browser_Refresh; + case XF86XK_Search: return Keyboard::Browser_Search; + case XF86XK_Stop: return Keyboard::Browser_Stop; - // Touches de contrôle - case XF86XK_AudioNext: return Keyboard::Media_Next; - case XF86XK_AudioPlay: return Keyboard::Media_Play; - case XF86XK_AudioPrev: return Keyboard::Media_Previous; - case XF86XK_AudioStop: return Keyboard::Media_Stop; + // Touches de contrôle + case XF86XK_AudioNext: return Keyboard::Media_Next; + case XF86XK_AudioPlay: return Keyboard::Media_Play; + case XF86XK_AudioPrev: return Keyboard::Media_Previous; + case XF86XK_AudioStop: return Keyboard::Media_Stop; - // Touches de contrôle du volume - case XF86XK_AudioLowerVolume: return Keyboard::Volume_Down; - case XF86XK_AudioMute: return Keyboard::Volume_Mute; - case XF86XK_AudioRaiseVolume: return Keyboard::Volume_Up; + // Touches de contrôle du volume + case XF86XK_AudioLowerVolume: return Keyboard::Volume_Down; + case XF86XK_AudioMute: return Keyboard::Volume_Mute; + case XF86XK_AudioRaiseVolume: return Keyboard::Volume_Up; - // Touches à verrouillage - case XK_Caps_Lock: return Keyboard::CapsLock; - case XK_Num_Lock: return Keyboard::NumLock; - case XK_Scroll_Lock: return Keyboard::ScrollLock; + // Touches à verrouillage + case XK_Caps_Lock: return Keyboard::CapsLock; + case XK_Num_Lock: return Keyboard::NumLock; + case XK_Scroll_Lock: return Keyboard::ScrollLock; - default: - return Keyboard::Undefined; + default: + return Keyboard::Undefined; } } @@ -945,15 +942,15 @@ namespace Nz }; if (!X11::CheckCookie( - connection, - xcb_icccm_set_wm_protocols( connection, - m_window, - X11::GetAtom("WM_PROTOCOLS"), - sizeof(protocols), - protocols - )) - ) + xcb_icccm_set_wm_protocols( + connection, + m_window, + X11::GetAtom("WM_PROTOCOLS"), + sizeof(protocols), + protocols + )) + ) NazaraError("Failed to get atom for deleting a window"); // Flush the commands queue @@ -964,57 +961,57 @@ namespace Nz { switch (keysym) { - case XK_KP_Space: - return ' '; - case XK_BackSpace: - return '\b'; - case XK_Tab: - case XK_KP_Tab: - return '\t'; - case XK_Linefeed: - return '\n'; - case XK_Return: - return '\r'; - // Numpad - case XK_KP_Multiply: - return '*'; - case XK_KP_Add: - return '+'; - case XK_KP_Separator: - return ','; // In french, it's '.' - case XK_KP_Subtract: - return '-'; - case XK_KP_Decimal: - return '.'; // In french, it's ',' - case XK_KP_Divide: - return '/'; - case XK_KP_0: - return '0'; - case XK_KP_1: - return '1'; - case XK_KP_2: - return '2'; - case XK_KP_3: - return '3'; - case XK_KP_4: - return '4'; - case XK_KP_5: - return '5'; - case XK_KP_6: - return '6'; - case XK_KP_7: - return '7'; - case XK_KP_8: - return '8'; - case XK_KP_9: - return '9'; - case XK_KP_Enter: - return '\r'; - default: - if (xcb_is_modifier_key(keysym) == true) - return '\0'; - else - return keysym; + case XK_KP_Space: + return ' '; + case XK_BackSpace: + return '\b'; + case XK_Tab: + case XK_KP_Tab: + return '\t'; + case XK_Linefeed: + return '\n'; + case XK_Return: + return '\r'; + // Numpad + case XK_KP_Multiply: + return '*'; + case XK_KP_Add: + return '+'; + case XK_KP_Separator: + return ','; // In french, it's '.' + case XK_KP_Subtract: + return '-'; + case XK_KP_Decimal: + return '.'; // In french, it's ',' + case XK_KP_Divide: + return '/'; + case XK_KP_0: + return '0'; + case XK_KP_1: + return '1'; + case XK_KP_2: + return '2'; + case XK_KP_3: + return '3'; + case XK_KP_4: + return '4'; + case XK_KP_5: + return '5'; + case XK_KP_6: + return '6'; + case XK_KP_7: + return '7'; + case XK_KP_8: + return '8'; + case XK_KP_9: + return '9'; + case XK_KP_Enter: + return '\r'; + default: + if (xcb_is_modifier_key(keysym) == true) + return '\0'; + else + return keysym; } } @@ -1026,296 +1023,296 @@ namespace Nz // Convert the xcb event to a Event switch (windowEvent->response_type & ~0x80) { - // Destroy event - case XCB_DESTROY_NOTIFY: - { - // The window is about to be destroyed: we must cleanup resources - CleanUp(); - break; - } + // Destroy event + case XCB_DESTROY_NOTIFY: + { + // The window is about to be destroyed: we must cleanup resources + CleanUp(); + break; + } - // Gain focus event - case XCB_FOCUS_IN: - { - const uint32_t value_list[] = { eventMask }; - if (!X11::CheckCookie( + // Gain focus event + case XCB_FOCUS_IN: + { + const uint32_t value_list[] = { eventMask }; + if (!X11::CheckCookie( connection, xcb_change_window_attributes( connection, m_window, XCB_CW_EVENT_MASK, value_list - )) - ) - NazaraError("Failed to change event mask"); + )) + ) + NazaraError("Failed to change event mask"); - WindowEvent event; - event.type = Nz::WindowEventType_GainedFocus; - m_parent->PushEvent(event); + WindowEvent event; + event.type = Nz::WindowEventType_GainedFocus; + m_parent->PushEvent(event); - break; - } + break; + } - // Lost focus event - case XCB_FOCUS_OUT: - { - WindowEvent event; - event.type = Nz::WindowEventType_LostFocus; - m_parent->PushEvent(event); + // Lost focus event + case XCB_FOCUS_OUT: + { + WindowEvent event; + event.type = Nz::WindowEventType_LostFocus; + m_parent->PushEvent(event); - const uint32_t values[] = { XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_FOCUS_CHANGE }; - if (!X11::CheckCookie( + const uint32_t values[] = { XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_FOCUS_CHANGE }; + if (!X11::CheckCookie( connection, xcb_change_window_attributes( connection, m_window, XCB_CW_EVENT_MASK, values - )) - ) - NazaraError("Failed to change event mask"); - + )) + ) + NazaraError("Failed to change event mask"); + + break; + } + + // Resize event + case XCB_CONFIGURE_NOTIFY: + { + xcb_configure_notify_event_t* configureNotifyEvent = (xcb_configure_notify_event_t*)windowEvent; + // ConfigureNotify can be triggered for other reasons, check if the size has actually changed + if ((configureNotifyEvent->width != m_size_hints.width) || (configureNotifyEvent->height != m_size_hints.width)) + { + WindowEvent event; + event.type = Nz::WindowEventType_Resized; + event.size.width = configureNotifyEvent->width; + event.size.height = configureNotifyEvent->height; + m_parent->PushEvent(event); + + m_size_hints.width = configureNotifyEvent->width; + m_size_hints.height = configureNotifyEvent->height; + } + if ((configureNotifyEvent->x != m_size_hints.x) || (configureNotifyEvent->y != m_size_hints.y)) + { + WindowEvent event; + event.type = Nz::WindowEventType_Moved; + event.size.width = configureNotifyEvent->x; + event.size.height = configureNotifyEvent->y; + m_parent->PushEvent(event); + + m_size_hints.x = configureNotifyEvent->x; + m_size_hints.y = configureNotifyEvent->y; + } + break; + } + + // Close event + case XCB_CLIENT_MESSAGE: + { + xcb_client_message_event_t* clientMessageEvent = (xcb_client_message_event_t*)windowEvent; + + if (clientMessageEvent->type != X11::GetAtom("WM_PROTOCOLS")) break; + if (clientMessageEvent->data.data32[0] == X11::GetAtom("WM_DELETE_WINDOW")) + { + WindowEvent event; + event.type = Nz::WindowEventType_Quit; + m_parent->PushEvent(event); } - // Resize event - case XCB_CONFIGURE_NOTIFY: + break; + } + + // Key down event + case XCB_KEY_PRESS: + { + xcb_key_press_event_t* keyPressEvent = (xcb_key_press_event_t*)windowEvent; + + if (!m_keyRepeat && m_eventQueue.curr && m_eventQueue.next) { - xcb_configure_notify_event_t* configureNotifyEvent = (xcb_configure_notify_event_t*)windowEvent; - // ConfigureNotify can be triggered for other reasons, check if the size has actually changed - if ((configureNotifyEvent->width != m_size_hints.width) || (configureNotifyEvent->height != m_size_hints.width)) - { - WindowEvent event; - event.type = Nz::WindowEventType_Resized; - event.size.width = configureNotifyEvent->width; - event.size.height = configureNotifyEvent->height; - m_parent->PushEvent(event); + xcb_key_press_event_t* current = (xcb_key_release_event_t*)m_eventQueue.curr; + // keyPressEvent == next - m_size_hints.width = configureNotifyEvent->width; - m_size_hints.height = configureNotifyEvent->height; - } - if ((configureNotifyEvent->x != m_size_hints.x) || (configureNotifyEvent->y != m_size_hints.y)) - { - WindowEvent event; - event.type = Nz::WindowEventType_Moved; - event.size.width = configureNotifyEvent->x; - event.size.height = configureNotifyEvent->y; - m_parent->PushEvent(event); - - m_size_hints.x = configureNotifyEvent->x; - m_size_hints.y = configureNotifyEvent->y; - } - break; - } - - // Close event - case XCB_CLIENT_MESSAGE: - { - xcb_client_message_event_t* clientMessageEvent = (xcb_client_message_event_t*)windowEvent; - - if (clientMessageEvent->type != X11::GetAtom("WM_PROTOCOLS")) + if ((current->time == keyPressEvent->time) && (current->detail == keyPressEvent->detail)) break; - if (clientMessageEvent->data.data32[0] == X11::GetAtom("WM_DELETE_WINDOW")) - { - WindowEvent event; - event.type = Nz::WindowEventType_Quit; - m_parent->PushEvent(event); - } - - break; } - // Key down event - case XCB_KEY_PRESS: + auto keysym = ConvertKeyCodeToKeySym(keyPressEvent->detail, keyPressEvent->state); + + WindowEvent event; + event.type = Nz::WindowEventType_KeyPressed; + event.key.code = ConvertVirtualKey(keysym); + event.key.alt = keyPressEvent->state & XCB_MOD_MASK_1; + event.key.control = keyPressEvent->state & XCB_MOD_MASK_CONTROL; + event.key.shift = keyPressEvent->state & XCB_MOD_MASK_SHIFT; + event.key.system = keyPressEvent->state & XCB_MOD_MASK_4; + m_parent->PushEvent(event); + + char32_t codePoint = GetRepresentation(keysym); + + // if (std::isprint(codePoint)) Is not working ? + handle combining ? { - xcb_key_press_event_t* keyPressEvent = (xcb_key_press_event_t*)windowEvent; - - if (!m_keyRepeat && m_eventQueue.curr && m_eventQueue.next) - { - xcb_key_press_event_t* current = (xcb_key_release_event_t*)m_eventQueue.curr; - // keyPressEvent == next - - if ((current->time == keyPressEvent->time) && (current->detail == keyPressEvent->detail)) - break; - } - - auto keysym = ConvertKeyCodeToKeySym(keyPressEvent->detail, keyPressEvent->state); - - WindowEvent event; - event.type = Nz::WindowEventType_KeyPressed; - event.key.code = ConvertVirtualKey(keysym); - event.key.alt = keyPressEvent->state & XCB_MOD_MASK_1; - event.key.control = keyPressEvent->state & XCB_MOD_MASK_CONTROL; - event.key.shift = keyPressEvent->state & XCB_MOD_MASK_SHIFT; - event.key.system = keyPressEvent->state & XCB_MOD_MASK_4; + event.type = Nz::WindowEventType_TextEntered; + event.text.character = codePoint; + event.text.repeated = false; m_parent->PushEvent(event); - - char32_t codePoint = GetRepresentation(keysym); - - // if (std::isprint(codePoint)) Is not working ? + handle combining ? - { - event.type = Nz::WindowEventType_TextEntered; - event.text.character = codePoint; - event.text.repeated = false; - m_parent->PushEvent(event); - } - - break; } - // Key up event - case XCB_KEY_RELEASE: + break; + } + + // Key up event + case XCB_KEY_RELEASE: + { + xcb_key_release_event_t* keyReleaseEvent = (xcb_key_release_event_t*)windowEvent; + + if (!m_keyRepeat && m_eventQueue.curr && m_eventQueue.next) { - xcb_key_release_event_t* keyReleaseEvent = (xcb_key_release_event_t*)windowEvent; + // keyReleaseEvent == current + xcb_key_press_event_t* next = (xcb_key_press_event_t*)m_eventQueue.next; - if (!m_keyRepeat && m_eventQueue.curr && m_eventQueue.next) - { - // keyReleaseEvent == current - xcb_key_press_event_t* next = (xcb_key_press_event_t*)m_eventQueue.next; - - if ((keyReleaseEvent->time == next->time) && (keyReleaseEvent->detail == next->detail)) - break; - } - - auto keysym = ConvertKeyCodeToKeySym(keyReleaseEvent->detail, keyReleaseEvent->state); - - WindowEvent event; - event.type = Nz::WindowEventType_KeyReleased; - event.key.code = ConvertVirtualKey(keysym); - event.key.alt = keyReleaseEvent->state & XCB_MOD_MASK_1; - event.key.control = keyReleaseEvent->state & XCB_MOD_MASK_CONTROL; - event.key.shift = keyReleaseEvent->state & XCB_MOD_MASK_SHIFT; - event.key.system = keyReleaseEvent->state & XCB_MOD_MASK_4; - m_parent->PushEvent(event); - - break; + if ((keyReleaseEvent->time == next->time) && (keyReleaseEvent->detail == next->detail)) + break; } - // Mouse button pressed - case XCB_BUTTON_PRESS: + auto keysym = ConvertKeyCodeToKeySym(keyReleaseEvent->detail, keyReleaseEvent->state); + + WindowEvent event; + event.type = Nz::WindowEventType_KeyReleased; + event.key.code = ConvertVirtualKey(keysym); + event.key.alt = keyReleaseEvent->state & XCB_MOD_MASK_1; + event.key.control = keyReleaseEvent->state & XCB_MOD_MASK_CONTROL; + event.key.shift = keyReleaseEvent->state & XCB_MOD_MASK_SHIFT; + event.key.system = keyReleaseEvent->state & XCB_MOD_MASK_4; + m_parent->PushEvent(event); + + break; + } + + // Mouse button pressed + case XCB_BUTTON_PRESS: + { + xcb_button_press_event_t* buttonPressEvent = (xcb_button_press_event_t*)windowEvent; + + WindowEvent event; + event.type = Nz::WindowEventType_MouseButtonPressed; + event.mouseButton.x = buttonPressEvent->event_x; + event.mouseButton.y = buttonPressEvent->event_y; + + if (buttonPressEvent->detail == XCB_BUTTON_INDEX_1) + event.mouseButton.button = Mouse::Left; + else if (buttonPressEvent->detail == XCB_BUTTON_INDEX_2) + event.mouseButton.button = Mouse::Middle; + else if (buttonPressEvent->detail == XCB_BUTTON_INDEX_3) + event.mouseButton.button = Mouse::Right; + else if (buttonPressEvent->detail == XCB_BUTTON_INDEX_4) + event.mouseButton.button = Mouse::XButton1; + else if (buttonPressEvent->detail == XCB_BUTTON_INDEX_5) + event.mouseButton.button = Mouse::XButton2; + else + NazaraWarning("Mouse button not handled"); + + m_parent->PushEvent(event); + + break; + } + + // Mouse button released + case XCB_BUTTON_RELEASE: + { + xcb_button_release_event_t* buttonReleaseEvent = (xcb_button_release_event_t*)windowEvent; + + WindowEvent event; + + switch (buttonReleaseEvent->detail) { - xcb_button_press_event_t* buttonPressEvent = (xcb_button_press_event_t*)windowEvent; + case XCB_BUTTON_INDEX_4: + case XCB_BUTTON_INDEX_5: + { + event.type = Nz::WindowEventType_MouseWheelMoved; + event.mouseWheel.delta = (buttonReleaseEvent->detail == XCB_BUTTON_INDEX_4) ? 1 : -1; + break; + } + default: + { + event.type = Nz::WindowEventType_MouseButtonReleased; + event.mouseButton.x = buttonReleaseEvent->event_x; + event.mouseButton.y = buttonReleaseEvent->event_y; - WindowEvent event; - event.type = Nz::WindowEventType_MouseButtonPressed; - event.mouseButton.x = buttonPressEvent->event_x; - event.mouseButton.y = buttonPressEvent->event_y; - - if (buttonPressEvent->detail == XCB_BUTTON_INDEX_1) + if (buttonReleaseEvent->detail == XCB_BUTTON_INDEX_1) event.mouseButton.button = Mouse::Left; - else if (buttonPressEvent->detail == XCB_BUTTON_INDEX_2) + else if (buttonReleaseEvent->detail == XCB_BUTTON_INDEX_2) event.mouseButton.button = Mouse::Middle; - else if (buttonPressEvent->detail == XCB_BUTTON_INDEX_3) + else if (buttonReleaseEvent->detail == XCB_BUTTON_INDEX_3) event.mouseButton.button = Mouse::Right; - else if (buttonPressEvent->detail == XCB_BUTTON_INDEX_4) + else if (buttonReleaseEvent->detail == XCB_BUTTON_INDEX_4) event.mouseButton.button = Mouse::XButton1; - else if (buttonPressEvent->detail == XCB_BUTTON_INDEX_5) + else if (buttonReleaseEvent->detail == XCB_BUTTON_INDEX_5) event.mouseButton.button = Mouse::XButton2; else NazaraWarning("Mouse button not handled"); - - m_parent->PushEvent(event); - - break; + } } - // Mouse button released - case XCB_BUTTON_RELEASE: - { - xcb_button_release_event_t* buttonReleaseEvent = (xcb_button_release_event_t*)windowEvent; + m_parent->PushEvent(event); - WindowEvent event; + break; + } - switch (buttonReleaseEvent->detail) - { - case XCB_BUTTON_INDEX_4: - case XCB_BUTTON_INDEX_5: - { - event.type = Nz::WindowEventType_MouseWheelMoved; - event.mouseWheel.delta = (buttonReleaseEvent->detail == XCB_BUTTON_INDEX_4) ? 1 : -1; - break; - } - default: - { - event.type = Nz::WindowEventType_MouseButtonReleased; - event.mouseButton.x = buttonReleaseEvent->event_x; - event.mouseButton.y = buttonReleaseEvent->event_y; - - if (buttonReleaseEvent->detail == XCB_BUTTON_INDEX_1) - event.mouseButton.button = Mouse::Left; - else if (buttonReleaseEvent->detail == XCB_BUTTON_INDEX_2) - event.mouseButton.button = Mouse::Middle; - else if (buttonReleaseEvent->detail == XCB_BUTTON_INDEX_3) - event.mouseButton.button = Mouse::Right; - else if (buttonReleaseEvent->detail == XCB_BUTTON_INDEX_4) - event.mouseButton.button = Mouse::XButton1; - else if (buttonReleaseEvent->detail == XCB_BUTTON_INDEX_5) - event.mouseButton.button = Mouse::XButton2; - else - NazaraWarning("Mouse button not handled"); - } - } - - m_parent->PushEvent(event); + // Mouse moved + case XCB_MOTION_NOTIFY: + { + xcb_motion_notify_event_t* motionNotifyEvent = (xcb_motion_notify_event_t*)windowEvent; + // We use the sequence to determine whether the motion is linked to a Mouse::SetPosition + if (m_mousePos.x == motionNotifyEvent->event_x && m_mousePos.y == motionNotifyEvent->event_y) break; - } - // Mouse moved - case XCB_MOTION_NOTIFY: - { - xcb_motion_notify_event_t* motionNotifyEvent = (xcb_motion_notify_event_t*)windowEvent; + WindowEvent event; + event.type = Nz::WindowEventType_MouseMoved; + event.mouseMove.deltaX = motionNotifyEvent->event_x - m_mousePos.x; + event.mouseMove.deltaY = motionNotifyEvent->event_y - m_mousePos.y; + event.mouseMove.x = motionNotifyEvent->event_x; + event.mouseMove.y = motionNotifyEvent->event_y; - // We use the sequence to determine whether the motion is linked to a Mouse::SetPosition - if (m_mousePos.x == motionNotifyEvent->event_x && m_mousePos.y == motionNotifyEvent->event_y) - break; + m_mousePos.x = motionNotifyEvent->event_x; + m_mousePos.y = motionNotifyEvent->event_y; - WindowEvent event; - event.type = Nz::WindowEventType_MouseMoved; - event.mouseMove.deltaX = motionNotifyEvent->event_x - m_mousePos.x; - event.mouseMove.deltaY = motionNotifyEvent->event_y - m_mousePos.y; - event.mouseMove.x = motionNotifyEvent->event_x; - event.mouseMove.y = motionNotifyEvent->event_y; + m_parent->PushEvent(event); - m_mousePos.x = motionNotifyEvent->event_x; - m_mousePos.y = motionNotifyEvent->event_y; + break; + } - m_parent->PushEvent(event); + // Mouse entered + case XCB_ENTER_NOTIFY: + { + WindowEvent event; + event.type = Nz::WindowEventType_MouseEntered; + m_parent->PushEvent(event); - break; - } + break; + } - // Mouse entered - case XCB_ENTER_NOTIFY: - { - WindowEvent event; - event.type = Nz::WindowEventType_MouseEntered; - m_parent->PushEvent(event); + // Mouse left + case XCB_LEAVE_NOTIFY: + { + WindowEvent event; + event.type = Nz::WindowEventType_MouseLeft; + m_parent->PushEvent(event); - break; - } + break; + } - // Mouse left - case XCB_LEAVE_NOTIFY: - { - WindowEvent event; - event.type = Nz::WindowEventType_MouseLeft; - m_parent->PushEvent(event); + // Parent window changed + case XCB_REPARENT_NOTIFY: + { + // Catch reparent events to properly apply fullscreen on + // some "strange" window managers (like Awesome) which + // seem to make use of temporary parents during mapping + if (m_style & WindowStyle_Fullscreen) + SwitchToFullscreen(); - break; - } - - // Parent window changed - case XCB_REPARENT_NOTIFY: - { - // Catch reparent events to properly apply fullscreen on - // some "strange" window managers (like Awesome) which - // seem to make use of temporary parents during mapping - if (m_style & WindowStyle_Fullscreen) - SwitchToFullscreen(); - - break; - } + break; + } } } @@ -1328,18 +1325,18 @@ namespace Nz // Reset the video mode ScopedXCB setScreenConfig(xcb_randr_set_screen_config_reply( - connection, - xcb_randr_set_screen_config( - connection, - m_oldVideoMode.root, - XCB_CURRENT_TIME, - m_oldVideoMode.config_timestamp, - m_oldVideoMode.sizeID, - m_oldVideoMode.rotation, - m_oldVideoMode.rate - ), - &error - )); + connection, + xcb_randr_set_screen_config( + connection, + m_oldVideoMode.root, + XCB_CURRENT_TIME, + m_oldVideoMode.config_timestamp, + m_oldVideoMode.sizeID, + m_oldVideoMode.rotation, + m_oldVideoMode.rate + ), + &error + )); if (error) NazaraError("Failed to reset old screen configuration"); @@ -1355,15 +1352,15 @@ namespace Nz const char MOTIF_WM_HINTS[] = "_MOTIF_WM_HINTS"; ScopedXCB hintsAtomReply(xcb_intern_atom_reply( - connection, - xcb_intern_atom( - connection, - 0, - sizeof(MOTIF_WM_HINTS) - 1, - MOTIF_WM_HINTS - ), - &error - )); + connection, + xcb_intern_atom( + connection, + 0, + sizeof(MOTIF_WM_HINTS) - 1, + MOTIF_WM_HINTS + ), + &error + )); if (!error && hintsAtomReply) { @@ -1390,7 +1387,7 @@ namespace Nz uint32_t flags; uint32_t functions; uint32_t decorations; - int32_t inputMode; + int32_t inputMode; uint32_t state; }; @@ -1418,18 +1415,18 @@ namespace Nz } ScopedXCB propertyError(xcb_request_check( - connection, - xcb_change_property_checked( - connection, - XCB_PROP_MODE_REPLACE, - m_window, - hintsAtomReply->atom, - hintsAtomReply->atom, - 32, - 5, - &hints - ) - )); + connection, + xcb_change_property_checked( + connection, + XCB_PROP_MODE_REPLACE, + m_window, + hintsAtomReply->atom, + hintsAtomReply->atom, + 32, + 5, + &hints + ) + )); if (propertyError) NazaraError("xcb_change_property failed, could not set window hints"); @@ -1458,14 +1455,14 @@ namespace Nz // Load RandR and check its version ScopedXCB randrVersion(xcb_randr_query_version_reply( - connection, - xcb_randr_query_version( - connection, - 1, - 1 - ), - &error - )); + connection, + xcb_randr_query_version( + connection, + 1, + 1 + ), + &error + )); if (error) { @@ -1475,13 +1472,13 @@ namespace Nz // Get the current configuration ScopedXCB config(xcb_randr_get_screen_info_reply( - connection, - xcb_randr_get_screen_info( - connection, - m_screen->root - ), - &error - )); + connection, + xcb_randr_get_screen_info( + connection, + m_screen->root + ), + &error + )); if (error || !config) { @@ -1506,26 +1503,26 @@ namespace Nz for (int i = 0; i < config->nSizes; ++i) { if (config->rotation == XCB_RANDR_ROTATION_ROTATE_90 || - config->rotation == XCB_RANDR_ROTATION_ROTATE_270) + config->rotation == XCB_RANDR_ROTATION_ROTATE_270) std::swap(sizes[i].height, sizes[i].width); if ((sizes[i].width == static_cast(mode.width)) && - (sizes[i].height == static_cast(mode.height))) + (sizes[i].height == static_cast(mode.height))) { // Switch to fullscreen mode ScopedXCB setScreenConfig(xcb_randr_set_screen_config_reply( - connection, - xcb_randr_set_screen_config( - connection, - config->root, - XCB_CURRENT_TIME, - config->config_timestamp, - i, - config->rotation, - config->rate - ), - &error - )); + connection, + xcb_randr_set_screen_config( + connection, + config->root, + XCB_CURRENT_TIME, + config->config_timestamp, + i, + config->rotation, + config->rate + ), + &error + )); if (error) NazaraError("Failed to set new screen configuration"); @@ -1546,14 +1543,14 @@ namespace Nz ScopedXCBEWMHConnection ewmhConnection(connection); if (!X11::CheckCookie( - connection, - xcb_ewmh_set_wm_state( - ewmhConnection, - m_window, - 1, - &ewmhConnection->_NET_WM_STATE_FULLSCREEN - )) - ) + connection, + xcb_ewmh_set_wm_state( + ewmhConnection, + m_window, + 1, + &ewmhConnection->_NET_WM_STATE_FULLSCREEN + )) + ) NazaraError("Failed to switch to fullscreen"); } @@ -1572,7 +1569,7 @@ namespace Nz connection, m_window, &m_size_hints - )); + )); } void WindowImpl::WindowThread(WindowImpl* window, Mutex* mutex, ConditionVariable* condition) diff --git a/src/Nazara/Renderer/Context.cpp b/src/Nazara/Renderer/Context.cpp index 90a17122d..0efb6ec61 100644 --- a/src/Nazara/Renderer/Context.cpp +++ b/src/Nazara/Renderer/Context.cpp @@ -12,7 +12,10 @@ #include #include -#if defined(NAZARA_PLATFORM_WINDOWS) +#if defined(NAZARA_PLATFORM_SDL2) + #include + #define CALLBACK +#elif defined(NAZARA_PLATFORM_WINDOWS) #include #elif defined(NAZARA_PLATFORM_GLX) #include diff --git a/src/Nazara/Renderer/OpenGL.cpp b/src/Nazara/Renderer/OpenGL.cpp index 1c6ac00dd..aea268456 100644 --- a/src/Nazara/Renderer/OpenGL.cpp +++ b/src/Nazara/Renderer/OpenGL.cpp @@ -2,21 +2,23 @@ // This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp -#include #include #include #include #include +#include #include #include -#if defined(NAZARA_PLATFORM_GLX) +#if defined(NAZARA_PLATFORM_SDL2) +#include +#elif defined(NAZARA_PLATFORM_GLX) #include #endif // NAZARA_PLATFORM_GLX +#include #include #include #include #include -#include namespace Nz { @@ -28,7 +30,9 @@ namespace Nz OpenGLFunc LoadEntry(const char* name, bool launchException = true) { - #if defined(NAZARA_PLATFORM_WINDOWS) + #if defined(NAZARA_PLATFORM_SDL2) + OpenGLFunc entry = reinterpret_cast(SDL_GL_GetProcAddress(name)); + #elif defined(NAZARA_PLATFORM_WINDOWS) OpenGLFunc entry = reinterpret_cast(wglGetProcAddress(name)); if (!entry) // wglGetProcAddress ne fonctionne pas sur les fonctions OpenGL <= 1.1 entry = reinterpret_cast(GetProcAddress(openGLlibrary, name)); @@ -51,7 +55,16 @@ namespace Nz bool LoadLibrary() { - #ifdef NAZARA_PLATFORM_WINDOWS + #if defined(NAZARA_PLATFORM_SDL2) + if (SDL_GL_LoadLibrary(nullptr) != 0) + { + NazaraError(SDL_GetError()); + + return false; + } + return true; + + #elif defined(NAZARA_PLATFORM_WINDOWS) openGLlibrary = ::LoadLibraryA("opengl32.dll"); return openGLlibrary != nullptr; @@ -62,7 +75,9 @@ namespace Nz void UnloadLibrary() { - #ifdef NAZARA_PLATFORM_WINDOWS + #if defined(NAZARA_PLATFORM_SDL2) + SDL_GL_UnloadLibrary(); + #elif defined(NAZARA_PLATFORM_WINDOWS) FreeLibrary(openGLlibrary); #endif } @@ -75,7 +90,7 @@ namespace Nz struct ContextStates { - std::vector> garbage; // Les ressources à supprimer dès que possible + std::vector > garbage; // Les ressources à supprimer dès que possible GLuint buffersBinding[BufferType_Max + 1] = {0}; GLuint currentProgram = 0; GLuint samplers[32] = {0}; // 32 est pour l'instant la plus haute limite (GL_TEXTURE31) @@ -158,15 +173,13 @@ namespace Nz // Les fonctions de blend n'a aucun intérêt sans blending if (states.blending) - { if (currentRenderStates.dstBlend != states.dstBlend || - currentRenderStates.srcBlend != states.srcBlend) + currentRenderStates.srcBlend != states.srcBlend) { glBlendFunc(BlendFunc[states.srcBlend], BlendFunc[states.dstBlend]); currentRenderStates.dstBlend = states.dstBlend; currentRenderStates.srcBlend = states.srcBlend; } - } if (states.depthBuffer) { @@ -187,13 +200,11 @@ namespace Nz // Inutile de changer le mode de face culling s'il n'est pas actif if (states.faceCulling) - { if (currentRenderStates.cullingSide != states.cullingSide) { glCullFace(FaceSide[states.cullingSide]); currentRenderStates.cullingSide = states.cullingSide; } - } if (currentRenderStates.faceFilling != states.faceFilling) { @@ -205,8 +216,8 @@ namespace Nz if (states.stencilTest) { if (currentRenderStates.stencilCompare.back != states.stencilCompare.back || - currentRenderStates.stencilReference.back != states.stencilReference.back || - currentRenderStates.stencilWriteMask.back != states.stencilWriteMask.back) + currentRenderStates.stencilReference.back != states.stencilReference.back || + currentRenderStates.stencilWriteMask.back != states.stencilWriteMask.back) { glStencilFuncSeparate(GL_BACK, RendererComparison[states.stencilCompare.back], states.stencilReference.back, states.stencilWriteMask.back); currentRenderStates.stencilCompare.back = states.stencilCompare.back; @@ -215,8 +226,8 @@ namespace Nz } if (currentRenderStates.stencilDepthFail.back != states.stencilDepthFail.back || - currentRenderStates.stencilFail.back != states.stencilFail.back || - currentRenderStates.stencilPass.back != states.stencilPass.back) + currentRenderStates.stencilFail.back != states.stencilFail.back || + currentRenderStates.stencilPass.back != states.stencilPass.back) { glStencilOpSeparate(GL_BACK, StencilOperation[states.stencilFail.back], StencilOperation[states.stencilDepthFail.back], StencilOperation[states.stencilPass.back]); currentRenderStates.stencilDepthFail.back = states.stencilDepthFail.back; @@ -225,8 +236,8 @@ namespace Nz } if (currentRenderStates.stencilCompare.front != states.stencilCompare.front || - currentRenderStates.stencilReference.front != states.stencilReference.front || - currentRenderStates.stencilWriteMask.front != states.stencilWriteMask.front) + currentRenderStates.stencilReference.front != states.stencilReference.front || + currentRenderStates.stencilWriteMask.front != states.stencilWriteMask.front) { glStencilFuncSeparate(GL_FRONT, RendererComparison[states.stencilCompare.front], states.stencilReference.front, states.stencilWriteMask.front); currentRenderStates.stencilCompare.front = states.stencilCompare.front; @@ -235,8 +246,8 @@ namespace Nz } if (currentRenderStates.stencilDepthFail.front != states.stencilDepthFail.front || - currentRenderStates.stencilFail.front != states.stencilFail.front || - currentRenderStates.stencilPass.front != states.stencilPass.front) + currentRenderStates.stencilFail.front != states.stencilFail.front || + currentRenderStates.stencilPass.front != states.stencilPass.front) { glStencilOpSeparate(GL_FRONT, StencilOperation[states.stencilFail.front], StencilOperation[states.stencilDepthFail.front], StencilOperation[states.stencilPass.front]); currentRenderStates.stencilDepthFail.front = states.stencilDepthFail.front; @@ -731,7 +742,10 @@ namespace Nz if (s_initialized) return true; - #if defined(NAZARA_PLATFORM_GLX) + + #if defined(NAZARA_PLATFORM_SDL2) + + #elif defined(NAZARA_PLATFORM_GLX) Initializer display; if (!display) { @@ -758,17 +772,17 @@ namespace Nz parameters.shared = false; /* - Note: Même le contexte de chargement nécessite quelques fonctions de base pour correctement s'initialiser - Pour cette raison, deux contextes sont créés, le premier sert à récupérer les fonctions permetttant - de créer le second avec les bons paramètres. + Note: Même le contexte de chargement nécessite quelques fonctions de base pour correctement s'initialiser + Pour cette raison, deux contextes sont créés, le premier sert à récupérer les fonctions permetttant + de créer le second avec les bons paramètres. - Non sérieusement si vous avez une meilleure idée, contactez-moi - */ + Non sérieusement si vous avez une meilleure idée, contactez-moi + */ /****************************Chargement OpenGL****************************/ ///FIXME: I'm really thinking this is a mistake and GLX has no need to be initialized differently (Lynix) - #if defined(NAZARA_PLATFORM_LINUX) + #if defined(NAZARA_PLATFORM_LINUX) && not defined(NAZARA_PLATFORM_SDL2) glXCreateContextAttribs = reinterpret_cast(LoadEntry("glXCreateContextAttribsARB", false)); #endif @@ -779,7 +793,7 @@ namespace Nz return false; } - #if defined(NAZARA_PLATFORM_WINDOWS) + #if defined(NAZARA_PLATFORM_WINDOWS) && not defined(NAZARA_PLATFORM_SDL2) wglCreateContextAttribs = reinterpret_cast(LoadEntry("wglCreateContextAttribsARB", false)); wglChoosePixelFormat = reinterpret_cast(LoadEntry("wglChoosePixelFormatARB", false)); if (!wglChoosePixelFormat) @@ -1031,7 +1045,8 @@ namespace Nz glInvalidateBufferData = reinterpret_cast(LoadEntry("glInvalidateBufferData", false)); glVertexAttribLPointer = reinterpret_cast(LoadEntry("glVertexAttribLPointer", false)); - #if defined(NAZARA_PLATFORM_WINDOWS) + #if defined(NAZARA_PLATFORM_SDL2) + #elif defined(NAZARA_PLATFORM_WINDOWS) wglGetExtensionsStringARB = reinterpret_cast(LoadEntry("wglGetExtensionsStringARB", false)); wglGetExtensionsStringEXT = reinterpret_cast(LoadEntry("wglGetExtensionsStringEXT", false)); wglSwapInterval = reinterpret_cast(LoadEntry("wglSwapIntervalEXT", false)); @@ -1898,7 +1913,7 @@ namespace Nz GLenum OpenGL::BufferTarget[] = { GL_ELEMENT_ARRAY_BUFFER, // BufferType_Index, - GL_ARRAY_BUFFER, // BufferType_Vertex + GL_ARRAY_BUFFER, // BufferType_Vertex }; static_assert(BufferType_Max + 1 == 2, "Buffer target array is incomplete"); @@ -1906,7 +1921,7 @@ namespace Nz GLenum OpenGL::BufferTargetBinding[] = { GL_ELEMENT_ARRAY_BUFFER_BINDING, // BufferType_Index, - GL_ARRAY_BUFFER_BINDING, // BufferType_Vertex + GL_ARRAY_BUFFER_BINDING, // BufferType_Vertex }; static_assert(BufferType_Max + 1 == 2, "Buffer target binding array is incomplete"); @@ -2033,9 +2048,9 @@ namespace Nz GLenum OpenGL::ShaderStage[] = { - GL_FRAGMENT_SHADER, // ShaderStage_Fragment - GL_GEOMETRY_SHADER, // ShaderStage_Geometry - GL_VERTEX_SHADER // ShaderStage_Vertex + GL_FRAGMENT_SHADER, // ShaderStage_Fragment + GL_GEOMETRY_SHADER, // ShaderStage_Geometry + GL_VERTEX_SHADER // ShaderStage_Vertex }; static_assert(ShaderStageType_Max + 1 == 3, "Shader stage array is incomplete"); @@ -2112,192 +2127,193 @@ namespace Nz static_assert(VertexComponent_Max + 1 == 16, "Attribute index array is incomplete"); -PFNGLACTIVETEXTUREPROC glActiveTexture = nullptr; -PFNGLATTACHSHADERPROC glAttachShader = nullptr; -PFNGLBEGINCONDITIONALRENDERPROC glBeginConditionalRender = nullptr; -PFNGLBEGINQUERYPROC glBeginQuery = nullptr; -PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation = nullptr; -PFNGLBINDBUFFERPROC glBindBuffer = nullptr; -PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer = nullptr; -PFNGLBINDFRAGDATALOCATIONPROC glBindFragDataLocation = nullptr; -PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer = nullptr; -PFNGLBINDSAMPLERPROC glBindSampler = nullptr; -PFNGLBINDTEXTUREPROC glBindTexture = nullptr; -PFNGLBINDVERTEXARRAYPROC glBindVertexArray = nullptr; -PFNGLBLENDFUNCPROC glBlendFunc = nullptr; -PFNGLBLENDFUNCSEPARATEPROC glBlendFuncSeparate = nullptr; -PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer = nullptr; -PFNGLBUFFERDATAPROC glBufferData = nullptr; -PFNGLBUFFERSUBDATAPROC glBufferSubData = nullptr; -PFNGLCLEARPROC glClear = nullptr; -PFNGLCLEARCOLORPROC glClearColor = nullptr; -PFNGLCLEARDEPTHPROC glClearDepth = nullptr; -PFNGLCLEARSTENCILPROC glClearStencil = nullptr; -PFNGLCREATEPROGRAMPROC glCreateProgram = nullptr; -PFNGLCREATESHADERPROC glCreateShader = nullptr; -PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus = nullptr; -PFNGLCOLORMASKPROC glColorMask = nullptr; -PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC glCompressedTexSubImage1D = nullptr; -PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC glCompressedTexSubImage2D = nullptr; -PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC glCompressedTexSubImage3D = nullptr; -PFNGLCULLFACEPROC glCullFace = nullptr; -PFNGLCOMPILESHADERPROC glCompileShader = nullptr; -PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D = nullptr; -PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback = nullptr; -PFNGLDEBUGMESSAGECONTROLPROC glDebugMessageControl = nullptr; -PFNGLDEBUGMESSAGEINSERTPROC glDebugMessageInsert = nullptr; -PFNGLDELETEBUFFERSPROC glDeleteBuffers = nullptr; -PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers = nullptr; -PFNGLDELETEPROGRAMPROC glDeleteProgram = nullptr; -PFNGLDELETEQUERIESPROC glDeleteQueries = nullptr; -PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers = nullptr; -PFNGLDELETESAMPLERSPROC glDeleteSamplers = nullptr; -PFNGLDELETESHADERPROC glDeleteShader = nullptr; -PFNGLDELETETEXTURESPROC glDeleteTextures = nullptr; -PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays = nullptr; -PFNGLDEPTHFUNCPROC glDepthFunc = nullptr; -PFNGLDEPTHMASKPROC glDepthMask = nullptr; -PFNGLDISABLEPROC glDisable = nullptr; -PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray = nullptr; -PFNGLDRAWARRAYSPROC glDrawArrays = nullptr; -PFNGLDRAWARRAYSINSTANCEDPROC glDrawArraysInstanced = nullptr; -PFNGLDRAWBUFFERPROC glDrawBuffer = nullptr; -PFNGLDRAWBUFFERSPROC glDrawBuffers = nullptr; -PFNGLDRAWELEMENTSPROC glDrawElements = nullptr; -PFNGLDRAWELEMENTSINSTANCEDPROC glDrawElementsInstanced = nullptr; -PFNGLDRAWTEXTURENVPROC glDrawTexture = nullptr; -PFNGLENABLEPROC glEnable = nullptr; -PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray = nullptr; -PFNGLENDCONDITIONALRENDERPROC glEndConditionalRender = nullptr; -PFNGLENDQUERYPROC glEndQuery = nullptr; -PFNGLFLUSHPROC glFlush = nullptr; -PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer = nullptr; -PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture = nullptr; -PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D = nullptr; -PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D = nullptr; -PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D = nullptr; -PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer = nullptr; -PFNGLGENERATEMIPMAPPROC glGenerateMipmap = nullptr; -PFNGLGENBUFFERSPROC glGenBuffers = nullptr; -PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers = nullptr; -PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers = nullptr; -PFNGLGENQUERIESPROC glGenQueries = nullptr; -PFNGLGENSAMPLERSPROC glGenSamplers = nullptr; -PFNGLGENTEXTURESPROC glGenTextures = nullptr; -PFNGLGENVERTEXARRAYSPROC glGenVertexArrays = nullptr; -PFNGLGETACTIVEUNIFORMPROC glGetActiveUniform = nullptr; -PFNGLGETBOOLEANVPROC glGetBooleanv = nullptr; -PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv = nullptr; -PFNGLGETDEBUGMESSAGELOGPROC glGetDebugMessageLog = nullptr; -PFNGLGETERRORPROC glGetError = nullptr; -PFNGLGETFLOATVPROC glGetFloatv = nullptr; -PFNGLGETINTEGERVPROC glGetIntegerv = nullptr; -PFNGLGETPROGRAMBINARYPROC glGetProgramBinary = nullptr; -PFNGLGETPROGRAMIVPROC glGetProgramiv = nullptr; -PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog = nullptr; -PFNGLGETQUERYIVPROC glGetQueryiv = nullptr; -PFNGLGETQUERYOBJECTIVPROC glGetQueryObjectiv = nullptr; -PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv = nullptr; -PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog = nullptr; -PFNGLGETSHADERIVPROC glGetShaderiv = nullptr; -PFNGLGETSHADERSOURCEPROC glGetShaderSource = nullptr; -PFNGLGETSTRINGPROC glGetString = nullptr; -PFNGLGETSTRINGIPROC glGetStringi = nullptr; -PFNGLGETTEXIMAGEPROC glGetTexImage = nullptr; -PFNGLGETTEXLEVELPARAMETERFVPROC glGetTexLevelParameterfv = nullptr; -PFNGLGETTEXLEVELPARAMETERIVPROC glGetTexLevelParameteriv = nullptr; -PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv = nullptr; -PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv = nullptr; -PFNGLGETUNIFORMFVPROC glGetUniformfv = nullptr; -PFNGLGETUNIFORMIVPROC glGetUniformiv = nullptr; -PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = nullptr; -PFNGLINVALIDATEBUFFERDATAPROC glInvalidateBufferData = nullptr; -PFNGLISENABLEDPROC glIsEnabled = nullptr; -PFNGLLINEWIDTHPROC glLineWidth = nullptr; -PFNGLLINKPROGRAMPROC glLinkProgram = nullptr; -PFNGLMAPBUFFERPROC glMapBuffer = nullptr; -PFNGLMAPBUFFERRANGEPROC glMapBufferRange = nullptr; -PFNGLPIXELSTOREIPROC glPixelStorei = nullptr; -PFNGLPOINTSIZEPROC glPointSize = nullptr; -PFNGLPOLYGONMODEPROC glPolygonMode = nullptr; -PFNGLPROGRAMBINARYPROC glProgramBinary = nullptr; -PFNGLPROGRAMPARAMETERIPROC glProgramParameteri = nullptr; -PFNGLPROGRAMUNIFORM1DPROC glProgramUniform1d = nullptr; -PFNGLPROGRAMUNIFORM1FPROC glProgramUniform1f = nullptr; -PFNGLPROGRAMUNIFORM1IPROC glProgramUniform1i = nullptr; -PFNGLPROGRAMUNIFORM1DVPROC glProgramUniform1dv = nullptr; -PFNGLPROGRAMUNIFORM1FVPROC glProgramUniform1fv = nullptr; -PFNGLPROGRAMUNIFORM1IVPROC glProgramUniform1iv = nullptr; -PFNGLPROGRAMUNIFORM2DVPROC glProgramUniform2dv = nullptr; -PFNGLPROGRAMUNIFORM2FVPROC glProgramUniform2fv = nullptr; -PFNGLPROGRAMUNIFORM2IVPROC glProgramUniform2iv = nullptr; -PFNGLPROGRAMUNIFORM3DVPROC glProgramUniform3dv = nullptr; -PFNGLPROGRAMUNIFORM3FVPROC glProgramUniform3fv = nullptr; -PFNGLPROGRAMUNIFORM3IVPROC glProgramUniform3iv = nullptr; -PFNGLPROGRAMUNIFORM4DVPROC glProgramUniform4dv = nullptr; -PFNGLPROGRAMUNIFORM4FVPROC glProgramUniform4fv = nullptr; -PFNGLPROGRAMUNIFORM4IVPROC glProgramUniform4iv = nullptr; -PFNGLPROGRAMUNIFORMMATRIX4DVPROC glProgramUniformMatrix4dv = nullptr; -PFNGLPROGRAMUNIFORMMATRIX4FVPROC glProgramUniformMatrix4fv = nullptr; -PFNGLREADPIXELSPROC glReadPixels = nullptr; -PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage = nullptr; -PFNGLSAMPLERPARAMETERFPROC glSamplerParameterf = nullptr; -PFNGLSAMPLERPARAMETERIPROC glSamplerParameteri = nullptr; -PFNGLSCISSORPROC glScissor = nullptr; -PFNGLSHADERSOURCEPROC glShaderSource = nullptr; -PFNGLSTENCILFUNCPROC glStencilFunc = nullptr; -PFNGLSTENCILFUNCSEPARATEPROC glStencilFuncSeparate = nullptr; -PFNGLSTENCILOPPROC glStencilOp = nullptr; -PFNGLSTENCILOPSEPARATEPROC glStencilOpSeparate = nullptr; -PFNGLTEXIMAGE1DPROC glTexImage1D = nullptr; -PFNGLTEXIMAGE2DPROC glTexImage2D = nullptr; -PFNGLTEXIMAGE3DPROC glTexImage3D = nullptr; -PFNGLTEXPARAMETERFPROC glTexParameterf = nullptr; -PFNGLTEXPARAMETERIPROC glTexParameteri = nullptr; -PFNGLTEXSTORAGE1DPROC glTexStorage1D = nullptr; -PFNGLTEXSTORAGE2DPROC glTexStorage2D = nullptr; -PFNGLTEXSTORAGE3DPROC glTexStorage3D = nullptr; -PFNGLTEXSUBIMAGE1DPROC glTexSubImage1D = nullptr; -PFNGLTEXSUBIMAGE2DPROC glTexSubImage2D = nullptr; -PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D = nullptr; -PFNGLUNIFORM1DPROC glUniform1d = nullptr; -PFNGLUNIFORM1FPROC glUniform1f = nullptr; -PFNGLUNIFORM1IPROC glUniform1i = nullptr; -PFNGLUNIFORM1DVPROC glUniform1dv = nullptr; -PFNGLUNIFORM1FVPROC glUniform1fv = nullptr; -PFNGLUNIFORM1IVPROC glUniform1iv = nullptr; -PFNGLUNIFORM2DVPROC glUniform2dv = nullptr; -PFNGLUNIFORM2FVPROC glUniform2fv = nullptr; -PFNGLUNIFORM2IVPROC glUniform2iv = nullptr; -PFNGLUNIFORM3DVPROC glUniform3dv = nullptr; -PFNGLUNIFORM3FVPROC glUniform3fv = nullptr; -PFNGLUNIFORM3IVPROC glUniform3iv = nullptr; -PFNGLUNIFORM4DVPROC glUniform4dv = nullptr; -PFNGLUNIFORM4FVPROC glUniform4fv = nullptr; -PFNGLUNIFORM4IVPROC glUniform4iv = nullptr; -PFNGLUNIFORMMATRIX4DVPROC glUniformMatrix4dv = nullptr; -PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv = nullptr; -PFNGLUNMAPBUFFERPROC glUnmapBuffer = nullptr; -PFNGLUSEPROGRAMPROC glUseProgram = nullptr; -PFNGLVALIDATEPROGRAMPROC glValidateProgram = nullptr; -PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f = nullptr; -PFNGLVERTEXATTRIBDIVISORPROC glVertexAttribDivisor = nullptr; -PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer = nullptr; -PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer = nullptr; -PFNGLVERTEXATTRIBLPOINTERPROC glVertexAttribLPointer = nullptr; -PFNGLVIEWPORTPROC glViewport = nullptr; + PFNGLACTIVETEXTUREPROC glActiveTexture = nullptr; + PFNGLATTACHSHADERPROC glAttachShader = nullptr; + PFNGLBEGINCONDITIONALRENDERPROC glBeginConditionalRender = nullptr; + PFNGLBEGINQUERYPROC glBeginQuery = nullptr; + PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation = nullptr; + PFNGLBINDBUFFERPROC glBindBuffer = nullptr; + PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer = nullptr; + PFNGLBINDFRAGDATALOCATIONPROC glBindFragDataLocation = nullptr; + PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer = nullptr; + PFNGLBINDSAMPLERPROC glBindSampler = nullptr; + PFNGLBINDTEXTUREPROC glBindTexture = nullptr; + PFNGLBINDVERTEXARRAYPROC glBindVertexArray = nullptr; + PFNGLBLENDFUNCPROC glBlendFunc = nullptr; + PFNGLBLENDFUNCSEPARATEPROC glBlendFuncSeparate = nullptr; + PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer = nullptr; + PFNGLBUFFERDATAPROC glBufferData = nullptr; + PFNGLBUFFERSUBDATAPROC glBufferSubData = nullptr; + PFNGLCLEARPROC glClear = nullptr; + PFNGLCLEARCOLORPROC glClearColor = nullptr; + PFNGLCLEARDEPTHPROC glClearDepth = nullptr; + PFNGLCLEARSTENCILPROC glClearStencil = nullptr; + PFNGLCREATEPROGRAMPROC glCreateProgram = nullptr; + PFNGLCREATESHADERPROC glCreateShader = nullptr; + PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus = nullptr; + PFNGLCOLORMASKPROC glColorMask = nullptr; + PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC glCompressedTexSubImage1D = nullptr; + PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC glCompressedTexSubImage2D = nullptr; + PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC glCompressedTexSubImage3D = nullptr; + PFNGLCULLFACEPROC glCullFace = nullptr; + PFNGLCOMPILESHADERPROC glCompileShader = nullptr; + PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D = nullptr; + PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback = nullptr; + PFNGLDEBUGMESSAGECONTROLPROC glDebugMessageControl = nullptr; + PFNGLDEBUGMESSAGEINSERTPROC glDebugMessageInsert = nullptr; + PFNGLDELETEBUFFERSPROC glDeleteBuffers = nullptr; + PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers = nullptr; + PFNGLDELETEPROGRAMPROC glDeleteProgram = nullptr; + PFNGLDELETEQUERIESPROC glDeleteQueries = nullptr; + PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers = nullptr; + PFNGLDELETESAMPLERSPROC glDeleteSamplers = nullptr; + PFNGLDELETESHADERPROC glDeleteShader = nullptr; + PFNGLDELETETEXTURESPROC glDeleteTextures = nullptr; + PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays = nullptr; + PFNGLDEPTHFUNCPROC glDepthFunc = nullptr; + PFNGLDEPTHMASKPROC glDepthMask = nullptr; + PFNGLDISABLEPROC glDisable = nullptr; + PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray = nullptr; + PFNGLDRAWARRAYSPROC glDrawArrays = nullptr; + PFNGLDRAWARRAYSINSTANCEDPROC glDrawArraysInstanced = nullptr; + PFNGLDRAWBUFFERPROC glDrawBuffer = nullptr; + PFNGLDRAWBUFFERSPROC glDrawBuffers = nullptr; + PFNGLDRAWELEMENTSPROC glDrawElements = nullptr; + PFNGLDRAWELEMENTSINSTANCEDPROC glDrawElementsInstanced = nullptr; + PFNGLDRAWTEXTURENVPROC glDrawTexture = nullptr; + PFNGLENABLEPROC glEnable = nullptr; + PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray = nullptr; + PFNGLENDCONDITIONALRENDERPROC glEndConditionalRender = nullptr; + PFNGLENDQUERYPROC glEndQuery = nullptr; + PFNGLFLUSHPROC glFlush = nullptr; + PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer = nullptr; + PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture = nullptr; + PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D = nullptr; + PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D = nullptr; + PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D = nullptr; + PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer = nullptr; + PFNGLGENERATEMIPMAPPROC glGenerateMipmap = nullptr; + PFNGLGENBUFFERSPROC glGenBuffers = nullptr; + PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers = nullptr; + PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers = nullptr; + PFNGLGENQUERIESPROC glGenQueries = nullptr; + PFNGLGENSAMPLERSPROC glGenSamplers = nullptr; + PFNGLGENTEXTURESPROC glGenTextures = nullptr; + PFNGLGENVERTEXARRAYSPROC glGenVertexArrays = nullptr; + PFNGLGETACTIVEUNIFORMPROC glGetActiveUniform = nullptr; + PFNGLGETBOOLEANVPROC glGetBooleanv = nullptr; + PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv = nullptr; + PFNGLGETDEBUGMESSAGELOGPROC glGetDebugMessageLog = nullptr; + PFNGLGETERRORPROC glGetError = nullptr; + PFNGLGETFLOATVPROC glGetFloatv = nullptr; + PFNGLGETINTEGERVPROC glGetIntegerv = nullptr; + PFNGLGETPROGRAMBINARYPROC glGetProgramBinary = nullptr; + PFNGLGETPROGRAMIVPROC glGetProgramiv = nullptr; + PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog = nullptr; + PFNGLGETQUERYIVPROC glGetQueryiv = nullptr; + PFNGLGETQUERYOBJECTIVPROC glGetQueryObjectiv = nullptr; + PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv = nullptr; + PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog = nullptr; + PFNGLGETSHADERIVPROC glGetShaderiv = nullptr; + PFNGLGETSHADERSOURCEPROC glGetShaderSource = nullptr; + PFNGLGETSTRINGPROC glGetString = nullptr; + PFNGLGETSTRINGIPROC glGetStringi = nullptr; + PFNGLGETTEXIMAGEPROC glGetTexImage = nullptr; + PFNGLGETTEXLEVELPARAMETERFVPROC glGetTexLevelParameterfv = nullptr; + PFNGLGETTEXLEVELPARAMETERIVPROC glGetTexLevelParameteriv = nullptr; + PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv = nullptr; + PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv = nullptr; + PFNGLGETUNIFORMFVPROC glGetUniformfv = nullptr; + PFNGLGETUNIFORMIVPROC glGetUniformiv = nullptr; + PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = nullptr; + PFNGLINVALIDATEBUFFERDATAPROC glInvalidateBufferData = nullptr; + PFNGLISENABLEDPROC glIsEnabled = nullptr; + PFNGLLINEWIDTHPROC glLineWidth = nullptr; + PFNGLLINKPROGRAMPROC glLinkProgram = nullptr; + PFNGLMAPBUFFERPROC glMapBuffer = nullptr; + PFNGLMAPBUFFERRANGEPROC glMapBufferRange = nullptr; + PFNGLPIXELSTOREIPROC glPixelStorei = nullptr; + PFNGLPOINTSIZEPROC glPointSize = nullptr; + PFNGLPOLYGONMODEPROC glPolygonMode = nullptr; + PFNGLPROGRAMBINARYPROC glProgramBinary = nullptr; + PFNGLPROGRAMPARAMETERIPROC glProgramParameteri = nullptr; + PFNGLPROGRAMUNIFORM1DPROC glProgramUniform1d = nullptr; + PFNGLPROGRAMUNIFORM1FPROC glProgramUniform1f = nullptr; + PFNGLPROGRAMUNIFORM1IPROC glProgramUniform1i = nullptr; + PFNGLPROGRAMUNIFORM1DVPROC glProgramUniform1dv = nullptr; + PFNGLPROGRAMUNIFORM1FVPROC glProgramUniform1fv = nullptr; + PFNGLPROGRAMUNIFORM1IVPROC glProgramUniform1iv = nullptr; + PFNGLPROGRAMUNIFORM2DVPROC glProgramUniform2dv = nullptr; + PFNGLPROGRAMUNIFORM2FVPROC glProgramUniform2fv = nullptr; + PFNGLPROGRAMUNIFORM2IVPROC glProgramUniform2iv = nullptr; + PFNGLPROGRAMUNIFORM3DVPROC glProgramUniform3dv = nullptr; + PFNGLPROGRAMUNIFORM3FVPROC glProgramUniform3fv = nullptr; + PFNGLPROGRAMUNIFORM3IVPROC glProgramUniform3iv = nullptr; + PFNGLPROGRAMUNIFORM4DVPROC glProgramUniform4dv = nullptr; + PFNGLPROGRAMUNIFORM4FVPROC glProgramUniform4fv = nullptr; + PFNGLPROGRAMUNIFORM4IVPROC glProgramUniform4iv = nullptr; + PFNGLPROGRAMUNIFORMMATRIX4DVPROC glProgramUniformMatrix4dv = nullptr; + PFNGLPROGRAMUNIFORMMATRIX4FVPROC glProgramUniformMatrix4fv = nullptr; + PFNGLREADPIXELSPROC glReadPixels = nullptr; + PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage = nullptr; + PFNGLSAMPLERPARAMETERFPROC glSamplerParameterf = nullptr; + PFNGLSAMPLERPARAMETERIPROC glSamplerParameteri = nullptr; + PFNGLSCISSORPROC glScissor = nullptr; + PFNGLSHADERSOURCEPROC glShaderSource = nullptr; + PFNGLSTENCILFUNCPROC glStencilFunc = nullptr; + PFNGLSTENCILFUNCSEPARATEPROC glStencilFuncSeparate = nullptr; + PFNGLSTENCILOPPROC glStencilOp = nullptr; + PFNGLSTENCILOPSEPARATEPROC glStencilOpSeparate = nullptr; + PFNGLTEXIMAGE1DPROC glTexImage1D = nullptr; + PFNGLTEXIMAGE2DPROC glTexImage2D = nullptr; + PFNGLTEXIMAGE3DPROC glTexImage3D = nullptr; + PFNGLTEXPARAMETERFPROC glTexParameterf = nullptr; + PFNGLTEXPARAMETERIPROC glTexParameteri = nullptr; + PFNGLTEXSTORAGE1DPROC glTexStorage1D = nullptr; + PFNGLTEXSTORAGE2DPROC glTexStorage2D = nullptr; + PFNGLTEXSTORAGE3DPROC glTexStorage3D = nullptr; + PFNGLTEXSUBIMAGE1DPROC glTexSubImage1D = nullptr; + PFNGLTEXSUBIMAGE2DPROC glTexSubImage2D = nullptr; + PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D = nullptr; + PFNGLUNIFORM1DPROC glUniform1d = nullptr; + PFNGLUNIFORM1FPROC glUniform1f = nullptr; + PFNGLUNIFORM1IPROC glUniform1i = nullptr; + PFNGLUNIFORM1DVPROC glUniform1dv = nullptr; + PFNGLUNIFORM1FVPROC glUniform1fv = nullptr; + PFNGLUNIFORM1IVPROC glUniform1iv = nullptr; + PFNGLUNIFORM2DVPROC glUniform2dv = nullptr; + PFNGLUNIFORM2FVPROC glUniform2fv = nullptr; + PFNGLUNIFORM2IVPROC glUniform2iv = nullptr; + PFNGLUNIFORM3DVPROC glUniform3dv = nullptr; + PFNGLUNIFORM3FVPROC glUniform3fv = nullptr; + PFNGLUNIFORM3IVPROC glUniform3iv = nullptr; + PFNGLUNIFORM4DVPROC glUniform4dv = nullptr; + PFNGLUNIFORM4FVPROC glUniform4fv = nullptr; + PFNGLUNIFORM4IVPROC glUniform4iv = nullptr; + PFNGLUNIFORMMATRIX4DVPROC glUniformMatrix4dv = nullptr; + PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv = nullptr; + PFNGLUNMAPBUFFERPROC glUnmapBuffer = nullptr; + PFNGLUSEPROGRAMPROC glUseProgram = nullptr; + PFNGLVALIDATEPROGRAMPROC glValidateProgram = nullptr; + PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f = nullptr; + PFNGLVERTEXATTRIBDIVISORPROC glVertexAttribDivisor = nullptr; + PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer = nullptr; + PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer = nullptr; + PFNGLVERTEXATTRIBLPOINTERPROC glVertexAttribLPointer = nullptr; + PFNGLVIEWPORTPROC glViewport = nullptr; -#if defined(NAZARA_PLATFORM_WINDOWS) -PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat = nullptr; -PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = nullptr; -PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = nullptr; -PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT = nullptr; -PFNWGLSWAPINTERVALEXTPROC wglSwapInterval = nullptr; +#if defined(NAZARA_PLATFORM_SDL2) +#elif defined(NAZARA_PLATFORM_WINDOWS) + PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat = nullptr; + PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = nullptr; + PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = nullptr; + PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT = nullptr; + PFNWGLSWAPINTERVALEXTPROC wglSwapInterval = nullptr; #elif defined(NAZARA_PLATFORM_GLX) -GLX::PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs = nullptr; -GLX::PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT = nullptr; -GLX::PFNGLXSWAPINTERVALMESAPROC NzglXSwapIntervalMESA = nullptr; -GLX::PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI = nullptr; + GLX::PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs = nullptr; + GLX::PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT = nullptr; + GLX::PFNGLXSWAPINTERVALMESAPROC NzglXSwapIntervalMESA = nullptr; + GLX::PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI = nullptr; #endif } diff --git a/src/Nazara/Renderer/SDL2/ContextImpl.cpp b/src/Nazara/Renderer/SDL2/ContextImpl.cpp new file mode 100644 index 000000000..35ebda856 --- /dev/null +++ b/src/Nazara/Renderer/SDL2/ContextImpl.cpp @@ -0,0 +1,145 @@ +// Copyright (C) 2017 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +// Code inspiré de NeHe (Lesson1) et de la SFML par Laurent Gomila + +#include +#include +#include +#include +#include +#include +#include +#include +#include +namespace Nz +{ + ContextImpl::ContextImpl() + { + } + + bool ContextImpl::Activate() const + { + bool success = SDL_GL_MakeCurrent(m_window, m_context) == 0; + + if (!success) + NazaraError(SDL_GetError()); + else + lastActive = m_window; + + return success; + } + + bool ContextImpl::Create(ContextParameters& parameters) + { + if (parameters.window) + { + m_window = static_cast(parameters.window); + m_ownsWindow = false; + } + else + { + m_window = SDL_CreateWindow("STATIC", 0, 0, 1, 1, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN); + if (!m_window) + { + NazaraError("Failed to create window"); + return false; + } + + //SDL_HideWindow(m_window); + m_ownsWindow = true; + } + + // En cas d'exception, la ressource sera quand même libérée + CallOnExit onExit([this] () + { + Destroy(); + }); + + + bool valid = true; + + std::array, 13> attributes{ + std::pair + {SDL_GL_CONTEXT_PROFILE_MASK, parameters.compatibilityProfile ? SDL_GL_CONTEXT_PROFILE_COMPATIBILITY : SDL_GL_CONTEXT_PROFILE_CORE}, + {SDL_GL_CONTEXT_MAJOR_VERSION, parameters.majorVersion}, + {SDL_GL_CONTEXT_MINOR_VERSION, parameters.minorVersion}, + {SDL_GL_CONTEXT_FLAGS, parameters.debugMode ? SDL_GL_CONTEXT_DEBUG_FLAG : 0}, + {SDL_GL_SHARE_WITH_CURRENT_CONTEXT, true}, + {SDL_GL_RED_SIZE, (parameters.bitsPerPixel == 32) ? 8 : parameters.bitsPerPixel / 3}, // sad but I don't have a solution for now + {SDL_GL_GREEN_SIZE, (parameters.bitsPerPixel == 32) ? 8 : parameters.bitsPerPixel / 3}, + {SDL_GL_BLUE_SIZE, (parameters.bitsPerPixel == 32) ? 8 : parameters.bitsPerPixel / 3}, + {SDL_GL_ALPHA_SIZE, (parameters.bitsPerPixel == 32) ? 8 : 0}, + {SDL_GL_DEPTH_SIZE, parameters.depthBits}, + {SDL_GL_STENCIL_SIZE, parameters.stencilBits}, + //{SDL_GL_DOUBLEBUFFER, parameters.doubleBuffered}, // doesn't work if we dont close all windows + {SDL_GL_MULTISAMPLEBUFFERS, parameters.antialiasingLevel > 0 ? GL_TRUE : GL_FALSE}, + {SDL_GL_MULTISAMPLESAMPLES, parameters.antialiasingLevel} + }; + + for (const auto& attribute : attributes) { + valid &= SDL_GL_SetAttribute(attribute.first, attribute.second) == 0; + + if (!valid) { + NazaraWarning(SDL_GetError()); + break; + } + } + + if (!valid) + NazaraWarning("Could not find a format matching requirements, disabling antialiasing..."); + + int antialiasingLevel; + SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &antialiasingLevel); + + parameters.antialiasingLevel = static_cast(antialiasingLevel); + + + onExit.Reset(); + + m_context = SDL_GL_CreateContext(m_window); + + if (!m_context) { + NazaraError(SDL_GetError()); + + return false; + } + + return true; + } + + void ContextImpl::Destroy() + { + if (m_context) + { + SDL_GL_DeleteContext(m_context); + m_context = nullptr; + } + + if (m_ownsWindow) + { + SDL_DestroyWindow(m_window); + m_window = nullptr; + } + } + + void ContextImpl::EnableVerticalSync(bool enabled) + { + + if (SDL_GL_SetSwapInterval(enabled ? 1 : 0) != 0) + NazaraError("Vertical sync not supported"); + } + + void ContextImpl::SwapBuffers() + { + SDL_GL_SwapWindow(m_window); + } + + bool ContextImpl::Desactivate() + { + return SDL_GL_MakeCurrent(nullptr, nullptr) == 0; + } + + SDL_Window* ContextImpl::lastActive = nullptr; +} diff --git a/src/Nazara/Renderer/SDL2/ContextImpl.hpp b/src/Nazara/Renderer/SDL2/ContextImpl.hpp new file mode 100644 index 000000000..ae1f620a1 --- /dev/null +++ b/src/Nazara/Renderer/SDL2/ContextImpl.hpp @@ -0,0 +1,42 @@ +// Copyright (C) 2017 Jérôme Leclercq +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_CONTEXTIMPL_HPP +#define NAZARA_CONTEXTIMPL_HPP + +#include +#include +#include + +namespace Nz +{ + class ContextImpl + { + public: + ContextImpl(); + + bool Activate() const; + + bool Create(ContextParameters& parameters); + + void Destroy(); + + void EnableVerticalSync(bool enabled); + + void SwapBuffers(); + + static bool Desactivate(); + + private: + SDL_GLContext m_context; + SDL_Window* m_window; + bool m_ownsWindow; + + static SDL_Window* lastActive; + }; +} + +#endif // NAZARA_CONTEXTIMPL_HPP