Window's subsystem is now initialized by NzUtility
Optimized Image
This commit is contained in:
parent
f55cf96713
commit
7659fdf460
|
|
@ -24,10 +24,12 @@
|
||||||
#include <Nazara/Core/ThreadCondition.hpp>
|
#include <Nazara/Core/ThreadCondition.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
class NzUtility;
|
||||||
class NzWindowImpl;
|
class NzWindowImpl;
|
||||||
|
|
||||||
class NAZARA_API NzWindow : NzNonCopyable
|
class NAZARA_API NzWindow : NzNonCopyable
|
||||||
{
|
{
|
||||||
|
friend class NzUtility;
|
||||||
friend class NzWindowImpl;
|
friend class NzWindowImpl;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -99,6 +101,9 @@ class NAZARA_API NzWindow : NzNonCopyable
|
||||||
private:
|
private:
|
||||||
void PushEvent(const NzEvent& event);
|
void PushEvent(const NzEvent& event);
|
||||||
|
|
||||||
|
static bool Initialize();
|
||||||
|
static void Uninitialize();
|
||||||
|
|
||||||
std::queue<NzEvent> m_events;
|
std::queue<NzEvent> m_events;
|
||||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||||
NzMutex m_eventMutex;
|
NzMutex m_eventMutex;
|
||||||
|
|
|
||||||
|
|
@ -298,7 +298,7 @@ bool NzImage::Update(const nzUInt8* pixels)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsCubemap())
|
if (m_sharedImage->type == nzImageType_Cubemap)
|
||||||
{
|
{
|
||||||
NazaraError("Update is not designed for cubemaps, use UpdateFace instead");
|
NazaraError("Update is not designed for cubemaps, use UpdateFace instead");
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -327,7 +327,7 @@ bool NzImage::Update(const nzUInt8* pixels, const NzRectui& rect)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsCubemap())
|
if (m_sharedImage->type == nzImageType_Cubemap)
|
||||||
{
|
{
|
||||||
NazaraError("Update is not designed for cubemaps, use UpdateFace instead");
|
NazaraError("Update is not designed for cubemaps, use UpdateFace instead");
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -380,7 +380,7 @@ bool NzImage::UpdateFace(nzCubemapFace face, const nzUInt8* pixels)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsCubemap())
|
if (m_sharedImage->type != nzImageType_Cubemap)
|
||||||
{
|
{
|
||||||
NazaraError("Update is only designed for cubemaps, use Update instead");
|
NazaraError("Update is only designed for cubemaps, use Update instead");
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -410,7 +410,7 @@ bool NzImage::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRect
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsCubemap())
|
if (m_sharedImage->type != nzImageType_Cubemap)
|
||||||
{
|
{
|
||||||
NazaraError("Update is only designed for cubemaps, use Update instead");
|
NazaraError("Update is only designed for cubemaps, use Update instead");
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -14,22 +14,22 @@ namespace
|
||||||
{
|
{
|
||||||
inline nzUInt8 c4to8(nzUInt8 c)
|
inline nzUInt8 c4to8(nzUInt8 c)
|
||||||
{
|
{
|
||||||
return c * 255.f/15.f;
|
return c * (255.f/15.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline nzUInt8 c5to8(nzUInt8 c)
|
inline nzUInt8 c5to8(nzUInt8 c)
|
||||||
{
|
{
|
||||||
return c * 255.f/31.f;
|
return c * (255.f/31.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline nzUInt8 c8to4(nzUInt8 c)
|
inline nzUInt8 c8to4(nzUInt8 c)
|
||||||
{
|
{
|
||||||
return c * 15.f/255.f;
|
return c * (15.f/255.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline nzUInt8 c8to5(nzUInt8 c)
|
inline nzUInt8 c8to5(nzUInt8 c)
|
||||||
{
|
{
|
||||||
return c * 31.f/255.f;
|
return c * (31.f/255.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<nzPixelFormat from, nzPixelFormat to>
|
template<nzPixelFormat from, nzPixelFormat to>
|
||||||
|
|
@ -215,7 +215,7 @@ namespace
|
||||||
*ptr++ = (static_cast<nzUInt16>(c8to5(start[2])) << 11) |
|
*ptr++ = (static_cast<nzUInt16>(c8to5(start[2])) << 11) |
|
||||||
(static_cast<nzUInt16>(c8to5(start[1])) << 6) |
|
(static_cast<nzUInt16>(c8to5(start[1])) << 6) |
|
||||||
(static_cast<nzUInt16>(c8to5(start[0])) << 1) |
|
(static_cast<nzUInt16>(c8to5(start[0])) << 1) |
|
||||||
((start[3] == 0xFF) ? 1 : 0);
|
((start[3] == 0xFF) ? 1 : 0);
|
||||||
|
|
||||||
start += 4;
|
start += 4;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#include <Nazara/Utility/Loaders/PCX.hpp>
|
#include <Nazara/Utility/Loaders/PCX.hpp>
|
||||||
#include <Nazara/Utility/Loaders/STB.hpp>
|
#include <Nazara/Utility/Loaders/STB.hpp>
|
||||||
#include <Nazara/Utility/PixelFormat.hpp>
|
#include <Nazara/Utility/PixelFormat.hpp>
|
||||||
|
#include <Nazara/Utility/Window.hpp>
|
||||||
#include <Nazara/Utility/Debug.hpp>
|
#include <Nazara/Utility/Debug.hpp>
|
||||||
|
|
||||||
NzUtility::NzUtility()
|
NzUtility::NzUtility()
|
||||||
|
|
@ -36,6 +37,14 @@ bool NzUtility::Initialize()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!NzWindow::Initialize())
|
||||||
|
{
|
||||||
|
NazaraError("Failed to initialize window's system");
|
||||||
|
NzPixelFormat::Uninitialize();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Loaders spécialisés
|
// Loaders spécialisés
|
||||||
NzLoaders_PCX_Register(); // Loader de fichiers .PCX (1, 4, 8, 24)
|
NzLoaders_PCX_Register(); // Loader de fichiers .PCX (1, 4, 8, 24)
|
||||||
|
|
||||||
|
|
@ -60,6 +69,8 @@ void NzUtility::Uninitialize()
|
||||||
NzLoaders_STB_Unregister();
|
NzLoaders_STB_Unregister();
|
||||||
NzLoaders_PCX_Unregister();
|
NzLoaders_PCX_Unregister();
|
||||||
|
|
||||||
|
NzWindow::Uninitialize();
|
||||||
|
|
||||||
NzPixelFormat::Uninitialize();
|
NzPixelFormat::Uninitialize();
|
||||||
|
|
||||||
s_initialized = false;
|
s_initialized = false;
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ namespace
|
||||||
{
|
{
|
||||||
const wchar_t* className = L"Nazara Window";
|
const wchar_t* className = L"Nazara Window";
|
||||||
NzWindowImpl* fullscreenWindow = nullptr;
|
NzWindowImpl* fullscreenWindow = nullptr;
|
||||||
unsigned int windowCount = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NzWindowImpl::NzWindowImpl(NzWindow* parent) :
|
NzWindowImpl::NzWindowImpl(NzWindow* parent) :
|
||||||
|
|
@ -62,19 +61,10 @@ void NzWindowImpl::Close()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
SetEventListener(false);
|
SetEventListener(false);
|
||||||
|
|
||||||
if (--windowCount == 0)
|
|
||||||
Uninitialize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 style)
|
bool NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 style)
|
||||||
{
|
{
|
||||||
if (windowCount++ == 0 && !Initialize())
|
|
||||||
{
|
|
||||||
NazaraError("Unable to initialize window implementation");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fullscreen = (style & NzWindow::Fullscreen) != 0;
|
bool fullscreen = (style & NzWindow::Fullscreen) != 0;
|
||||||
DWORD win32Style, win32StyleEx;
|
DWORD win32Style, win32StyleEx;
|
||||||
unsigned int x, y;
|
unsigned int x, y;
|
||||||
|
|
@ -165,15 +155,7 @@ bool NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 styl
|
||||||
m_eventListener = true;
|
m_eventListener = true;
|
||||||
m_ownsWindow = true;
|
m_ownsWindow = true;
|
||||||
|
|
||||||
if (m_handle != nullptr)
|
return m_handle != nullptr;
|
||||||
return true;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (--windowCount == 0)
|
|
||||||
Uninitialize();
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzWindowImpl::Create(NzWindowHandle handle)
|
bool NzWindowImpl::Create(NzWindowHandle handle)
|
||||||
|
|
@ -776,6 +758,30 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NzWindowImpl::Initialize()
|
||||||
|
{
|
||||||
|
// Nous devons faire un type Unicode pour que la fenêtre le soit également
|
||||||
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms633574(v=vs.85).aspx
|
||||||
|
WNDCLASSW windowClass;
|
||||||
|
windowClass.cbClsExtra = 0;
|
||||||
|
windowClass.cbWndExtra = 0;
|
||||||
|
windowClass.hbrBackground = nullptr;
|
||||||
|
windowClass.hCursor = nullptr; // Le curseur est définit dynamiquement
|
||||||
|
windowClass.hIcon = nullptr; // L'icône est définie dynamiquement
|
||||||
|
windowClass.hInstance = GetModuleHandle(nullptr);
|
||||||
|
windowClass.lpfnWndProc = MessageHandler;
|
||||||
|
windowClass.lpszClassName = className;
|
||||||
|
windowClass.lpszMenuName = nullptr;
|
||||||
|
windowClass.style = CS_DBLCLKS; // Gestion du double-clic
|
||||||
|
|
||||||
|
return RegisterClassW(&windowClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NzWindowImpl::Uninitialize()
|
||||||
|
{
|
||||||
|
UnregisterClassW(className, GetModuleHandle(nullptr));
|
||||||
|
}
|
||||||
|
|
||||||
LRESULT CALLBACK NzWindowImpl::MessageHandler(HWND window, UINT message, WPARAM wParam, LPARAM lParam)
|
LRESULT CALLBACK NzWindowImpl::MessageHandler(HWND window, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
NzWindowImpl* me;
|
NzWindowImpl* me;
|
||||||
|
|
@ -798,25 +804,6 @@ LRESULT CALLBACK NzWindowImpl::MessageHandler(HWND window, UINT message, WPARAM
|
||||||
return DefWindowProcW(window, message, wParam, lParam);
|
return DefWindowProcW(window, message, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzWindowImpl::Initialize()
|
|
||||||
{
|
|
||||||
// Nous devons faire un type Unicode pour que la fenêtre le soit également
|
|
||||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms633574(v=vs.85).aspx
|
|
||||||
WNDCLASSW windowClass;
|
|
||||||
windowClass.cbClsExtra = 0;
|
|
||||||
windowClass.cbWndExtra = 0;
|
|
||||||
windowClass.hbrBackground = nullptr;
|
|
||||||
windowClass.hCursor = nullptr; // Le curseur est définit dynamiquement
|
|
||||||
windowClass.hIcon = nullptr; // L'icône est définie dynamiquement
|
|
||||||
windowClass.hInstance = GetModuleHandle(nullptr);
|
|
||||||
windowClass.lpfnWndProc = MessageHandler;
|
|
||||||
windowClass.lpszClassName = className;
|
|
||||||
windowClass.lpszMenuName = nullptr;
|
|
||||||
windowClass.style = CS_DBLCLKS; // Gestion du double-clic
|
|
||||||
|
|
||||||
return RegisterClassW(&windowClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
NzKeyboard::Key NzWindowImpl::ConvertVirtualKey(WPARAM key, LPARAM flags)
|
NzKeyboard::Key NzWindowImpl::ConvertVirtualKey(WPARAM key, LPARAM flags)
|
||||||
{
|
{
|
||||||
switch (key)
|
switch (key)
|
||||||
|
|
@ -949,11 +936,6 @@ NzKeyboard::Key NzWindowImpl::ConvertVirtualKey(WPARAM key, LPARAM flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzWindowImpl::Uninitialize()
|
|
||||||
{
|
|
||||||
UnregisterClassW(className, GetModuleHandle(nullptr));
|
|
||||||
}
|
|
||||||
|
|
||||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||||
void NzWindowImpl::WindowThread(HWND* handle, DWORD styleEx, const wchar_t* title, DWORD style, unsigned int x, unsigned int y, unsigned int width, unsigned int height, NzWindowImpl* window, NzMutex* mutex, NzThreadCondition* condition)
|
void NzWindowImpl::WindowThread(HWND* handle, DWORD styleEx, const wchar_t* title, DWORD style, unsigned int x, unsigned int y, unsigned int width, unsigned int height, NzWindowImpl* window, NzMutex* mutex, NzThreadCondition* condition)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ class NzMutex;
|
||||||
class NzThread;
|
class NzThread;
|
||||||
class NzThreadCondition;
|
class NzThreadCondition;
|
||||||
#endif
|
#endif
|
||||||
|
class NzWindow;
|
||||||
|
|
||||||
#undef IsMinimized // Conflit avec la méthode du même nom
|
#undef IsMinimized // Conflit avec la méthode du même nom
|
||||||
|
|
||||||
|
|
@ -67,13 +68,14 @@ class NzWindowImpl : NzNonCopyable
|
||||||
void ShowMouseCursor(bool show);
|
void ShowMouseCursor(bool show);
|
||||||
void StayOnTop(bool stayOnTop);
|
void StayOnTop(bool stayOnTop);
|
||||||
|
|
||||||
|
static bool Initialize();
|
||||||
|
static void Uninitialize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool HandleMessage(HWND window, UINT message, WPARAM wParam, LPARAM lParam);
|
bool HandleMessage(HWND window, UINT message, WPARAM wParam, LPARAM lParam);
|
||||||
|
|
||||||
static bool Initialize();
|
|
||||||
static LRESULT CALLBACK MessageHandler(HWND window, UINT message, WPARAM wParam, LPARAM lParam);
|
static LRESULT CALLBACK MessageHandler(HWND window, UINT message, WPARAM wParam, LPARAM lParam);
|
||||||
static NzKeyboard::Key ConvertVirtualKey(WPARAM key, LPARAM flags);
|
static NzKeyboard::Key ConvertVirtualKey(WPARAM key, LPARAM flags);
|
||||||
static void Uninitialize();
|
|
||||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||||
static void WindowThread(HWND* handle, DWORD styleEx, const wchar_t* title, DWORD style, unsigned int x, unsigned int y, unsigned int width, unsigned int height, NzWindowImpl* window, NzMutex* mutex, NzThreadCondition* condition);
|
static void WindowThread(HWND* handle, DWORD styleEx, const wchar_t* title, DWORD style, unsigned int x, unsigned int y, unsigned int width, unsigned int height, NzWindowImpl* window, NzMutex* mutex, NzThreadCondition* condition);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -473,3 +473,13 @@ void NzWindow::PushEvent(const NzEvent& event)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NzWindow::Initialize()
|
||||||
|
{
|
||||||
|
return NzWindowImpl::Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NzWindow::Uninitialize()
|
||||||
|
{
|
||||||
|
NzWindowImpl::Uninitialize();
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue