Refactored mathematics module
Added AABBs Added code examples Added experimental support for texture arrays (1D/2D) Added initialisers (new way of initialising modules) Added global headers (Plus a global header generator script) Added pattern support for directory Added support for spinlocks critical section on Windows Added NzRenderWindow::SetFramerateLimit Core project now includes Mathematics files Fixed color implementation using double Fixed declaration needing renderer include Fixed MLT not clearing nextFree(File/Line) after Free Fixed move operators not being noexcept Fixed thread-safety (Now working correctly - If I'm lucky) Moved Resource to core New interface for modules New interface for the renderer Put some global functions to anonymous namespace Removed empty modules Renamed ThreadCondition to ConditionVariable Replaced redirect to cerr log option by duplicate to cout Setting mouse position relative to a window will make this window ignore the event Shaders sending methods no longer takes the uniform variable name (it's using ID instead) Using new OpenGL 4.3 header
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Audio/Config.hpp>
|
||||
#if NAZARA_AUDIO_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
|
||||
#include <Nazara/Core/Debug/MemoryLeakTracker.hpp>
|
||||
#include <new>
|
||||
|
||||
void* operator new(std::size_t size)
|
||||
{
|
||||
return NzMemoryManager::Allocate(size, false);
|
||||
}
|
||||
|
||||
void* operator new[](std::size_t size)
|
||||
{
|
||||
return NzMemoryManager::Allocate(size, true);
|
||||
}
|
||||
|
||||
void operator delete(void* pointer) noexcept
|
||||
{
|
||||
NzMemoryManager::Free(pointer, false);
|
||||
}
|
||||
|
||||
void operator delete[](void* pointer) noexcept
|
||||
{
|
||||
NzMemoryManager::Free(pointer, true);
|
||||
}
|
||||
#endif
|
||||
@@ -15,6 +15,24 @@
|
||||
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
nzUInt64 NzGetMicrosecondsLowPrecision()
|
||||
{
|
||||
return NzClockImplGetMilliseconds()*1000ULL;
|
||||
}
|
||||
|
||||
nzUInt64 NzGetMicrosecondsFirstRun()
|
||||
{
|
||||
if (NzClockImplInitializeHighPrecision())
|
||||
NzGetMicroseconds = NzClockImplGetMicroseconds;
|
||||
else
|
||||
NzGetMicroseconds = NzGetMicrosecondsLowPrecision;
|
||||
|
||||
return NzGetMicroseconds();
|
||||
}
|
||||
}
|
||||
|
||||
NzClock::NzClock() :
|
||||
m_elapsedTime(0),
|
||||
m_refTime(NzGetMicroseconds()),
|
||||
@@ -81,20 +99,5 @@ void NzClock::Unpause()
|
||||
NazaraWarning("Clock is not paused, ignoring...");
|
||||
}
|
||||
|
||||
nzUInt64 NzGetMicrosecondsLowPrecision()
|
||||
{
|
||||
return NzClockImplGetMilliseconds()*1000ULL;
|
||||
}
|
||||
|
||||
nzUInt64 NzGetMicrosecondsFirstRun()
|
||||
{
|
||||
if (NzClockImplInitializeHighPrecision())
|
||||
NzGetMicroseconds = NzClockImplGetMicroseconds;
|
||||
else
|
||||
NzGetMicroseconds = NzGetMicrosecondsLowPrecision;
|
||||
|
||||
return NzGetMicroseconds();
|
||||
}
|
||||
|
||||
NzClockFunction NzGetMicroseconds = NzGetMicrosecondsFirstRun;
|
||||
NzClockFunction NzGetMilliseconds = NzClockImplGetMilliseconds;
|
||||
|
||||
@@ -2,45 +2,45 @@
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/ThreadCondition.hpp>
|
||||
#include <Nazara/Core/ConditionVariable.hpp>
|
||||
#include <Nazara/Core/Mutex.hpp>
|
||||
|
||||
#if defined(NAZARA_PLATFORM_WINDOWS)
|
||||
#include <Nazara/Core/Win32/ThreadConditionImpl.hpp>
|
||||
#include <Nazara/Core/Win32/ConditionVariableImpl.hpp>
|
||||
#elif defined(NAZARA_PLATFORM_POSIX)
|
||||
#include <Nazara/Core/Posix/ThreadConditionImpl.hpp>
|
||||
#include <Nazara/Core/Posix/ConditionVariableImpl.hpp>
|
||||
#else
|
||||
#error Thread condition has no implementation
|
||||
#endif
|
||||
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
NzThreadCondition::NzThreadCondition()
|
||||
NzConditionVariable::NzConditionVariable()
|
||||
{
|
||||
m_impl = new NzThreadConditionImpl;
|
||||
m_impl = new NzConditionVariableImpl;
|
||||
}
|
||||
|
||||
NzThreadCondition::~NzThreadCondition()
|
||||
NzConditionVariable::~NzConditionVariable()
|
||||
{
|
||||
delete m_impl;
|
||||
}
|
||||
|
||||
void NzThreadCondition::Signal()
|
||||
void NzConditionVariable::Signal()
|
||||
{
|
||||
m_impl->Signal();
|
||||
}
|
||||
|
||||
void NzThreadCondition::SignalAll()
|
||||
void NzConditionVariable::SignalAll()
|
||||
{
|
||||
m_impl->SignalAll();
|
||||
}
|
||||
|
||||
void NzThreadCondition::Wait(NzMutex* mutex)
|
||||
void NzConditionVariable::Wait(NzMutex* mutex)
|
||||
{
|
||||
m_impl->Wait(mutex->m_impl);
|
||||
}
|
||||
|
||||
bool NzThreadCondition::Wait(NzMutex* mutex, nzUInt32 timeout)
|
||||
bool NzConditionVariable::Wait(NzMutex* mutex, nzUInt32 timeout)
|
||||
{
|
||||
return m_impl->Wait(mutex->m_impl, timeout);
|
||||
}
|
||||
39
src/Nazara/Core/Core.cpp
Normal file
39
src/Nazara/Core/Core.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2012 AUTHORS
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
bool NzCore::Initialize()
|
||||
{
|
||||
if (s_moduleReferenceCouter++ != 0)
|
||||
return true; // Déjà initialisé
|
||||
|
||||
// Initialisation du module
|
||||
// Le noyau de Nazara n'a pour l'instant aucun besoin d'initialisation, mais dans le futur il est très probable que ce soit le cas.
|
||||
// Donc en prévision, tous les modules initialisent le noyau
|
||||
|
||||
NazaraNotice("Initialized: Core");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzCore::IsInitialized()
|
||||
{
|
||||
return s_moduleReferenceCouter != 0;
|
||||
}
|
||||
|
||||
void NzCore::Uninitialize()
|
||||
{
|
||||
if (--s_moduleReferenceCouter != 0)
|
||||
return; // Encore utilisé
|
||||
|
||||
// Libération du module
|
||||
NazaraNotice("Uninitialized: Core");
|
||||
}
|
||||
|
||||
unsigned int NzCore::s_moduleReferenceCouter = 0;
|
||||
@@ -119,19 +119,16 @@ void NzMemoryManager::Free(void* pointer, bool multi)
|
||||
if (nextFreeFile)
|
||||
{
|
||||
if (multi)
|
||||
std::fprintf(log, "%s Warning: delete[] on new at %s:%d\n", time, nextFreeFile, nextFreeLine);
|
||||
std::fprintf(log, "%s Warning: delete[] after new at %s:%d\n", time, nextFreeFile, nextFreeLine);
|
||||
else
|
||||
std::fprintf(log, "%s Warning: delete on new[] at %s:%d\n", time, nextFreeFile, nextFreeLine);
|
||||
|
||||
nextFreeFile = nullptr;
|
||||
nextFreeLine = 0;
|
||||
std::fprintf(log, "%s Warning: delete after new[] at %s:%d\n", time, nextFreeFile, nextFreeLine);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (multi)
|
||||
std::fprintf(log, "%s Warning: delete[] on new at unknown position\n", time);
|
||||
std::fprintf(log, "%s Warning: delete[] after new at unknown position\n", time);
|
||||
else
|
||||
std::fprintf(log, "%s Warning: delete on new[] at unknown position\n", time);
|
||||
std::fprintf(log, "%s Warning: delete after new[] at unknown position\n", time);
|
||||
}
|
||||
|
||||
std::fclose(log);
|
||||
@@ -145,6 +142,9 @@ void NzMemoryManager::Free(void* pointer, bool multi)
|
||||
|
||||
std::free(ptr);
|
||||
|
||||
nextFreeFile = nullptr;
|
||||
nextFreeLine = 0;
|
||||
|
||||
#if defined(NAZARA_PLATFORM_WINDOWS)
|
||||
LeaveCriticalSection(&mutex);
|
||||
#elif defined(NAZARA_PLATFORM_POSIX)
|
||||
|
||||
@@ -25,14 +25,14 @@ namespace
|
||||
}
|
||||
|
||||
NzDirectory::NzDirectory() :
|
||||
m_impl(nullptr)
|
||||
m_pattern('*')
|
||||
{
|
||||
}
|
||||
|
||||
NzDirectory::NzDirectory(const NzString& dirPath) :
|
||||
m_impl(nullptr)
|
||||
m_dirPath(dirPath),
|
||||
m_pattern('*')
|
||||
{
|
||||
SetDirectory(dirPath);
|
||||
}
|
||||
|
||||
NzDirectory::~NzDirectory()
|
||||
@@ -42,18 +42,27 @@ NzDirectory::~NzDirectory()
|
||||
|
||||
void NzDirectory::Close()
|
||||
{
|
||||
NazaraLock(m_mutex);
|
||||
|
||||
if (m_impl)
|
||||
{
|
||||
m_impl->Close();
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
|
||||
NazaraMutexUnlock(m_mutex);
|
||||
}
|
||||
}
|
||||
|
||||
NzString NzDirectory::GetPattern() const
|
||||
{
|
||||
NazaraLock(m_mutex);
|
||||
|
||||
return m_pattern;
|
||||
}
|
||||
|
||||
NzString NzDirectory::GetResultName() const
|
||||
{
|
||||
NazaraLock(m_mutex);
|
||||
|
||||
#if NAZARA_CORE_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
@@ -67,6 +76,8 @@ NzString NzDirectory::GetResultName() const
|
||||
|
||||
NzString NzDirectory::GetResultPath() const
|
||||
{
|
||||
NazaraLock(m_mutex);
|
||||
|
||||
#if NAZARA_CORE_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
@@ -80,6 +91,8 @@ NzString NzDirectory::GetResultPath() const
|
||||
|
||||
nzUInt64 NzDirectory::GetResultSize() const
|
||||
{
|
||||
NazaraLock(m_mutex);
|
||||
|
||||
#if NAZARA_CORE_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
@@ -91,8 +104,17 @@ nzUInt64 NzDirectory::GetResultSize() const
|
||||
return m_impl->GetResultSize();
|
||||
}
|
||||
|
||||
bool NzDirectory::IsOpen() const
|
||||
{
|
||||
NazaraLock(m_mutex);
|
||||
|
||||
return m_impl != nullptr;
|
||||
}
|
||||
|
||||
bool NzDirectory::IsResultDirectory() const
|
||||
{
|
||||
NazaraLock(m_mutex);
|
||||
|
||||
#if NAZARA_CORE_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
@@ -106,6 +128,8 @@ bool NzDirectory::IsResultDirectory() const
|
||||
|
||||
bool NzDirectory::NextResult(bool skipDots)
|
||||
{
|
||||
NazaraLock(m_mutex);
|
||||
|
||||
#if NAZARA_CORE_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
@@ -114,41 +138,40 @@ bool NzDirectory::NextResult(bool skipDots)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (skipDots)
|
||||
NzString name;
|
||||
do
|
||||
{
|
||||
NzString name;
|
||||
do
|
||||
{
|
||||
if (!m_impl->NextResult())
|
||||
return false;
|
||||
if (!m_impl->NextResult())
|
||||
return false;
|
||||
|
||||
name = m_impl->GetResultName();
|
||||
}
|
||||
while (name == '.' || name == "..");
|
||||
name = m_impl->GetResultName();
|
||||
|
||||
return true;
|
||||
if (skipDots && (name == '.' || name == ".."))
|
||||
continue;
|
||||
|
||||
if (name.Match(m_pattern))
|
||||
break;
|
||||
}
|
||||
else
|
||||
return m_impl->NextResult();
|
||||
while (true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzDirectory::Open()
|
||||
{
|
||||
NazaraLock(m_mutex);
|
||||
|
||||
Close();
|
||||
|
||||
if (!Exists(m_dirPath))
|
||||
return false;
|
||||
|
||||
NazaraMutexLock(m_mutex);
|
||||
|
||||
m_impl = new NzDirectoryImpl(this);
|
||||
if (!m_impl->Open(m_dirPath))
|
||||
{
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
|
||||
NazaraMutexUnlock(m_mutex);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -157,11 +180,20 @@ bool NzDirectory::Open()
|
||||
|
||||
void NzDirectory::SetDirectory(const NzString& dirPath)
|
||||
{
|
||||
NazaraLock(m_mutex);
|
||||
|
||||
Close();
|
||||
|
||||
m_dirPath = NzFile::AbsolutePath(dirPath);
|
||||
}
|
||||
|
||||
void NzDirectory::SetPattern(const NzString& pattern)
|
||||
{
|
||||
NazaraLock(m_mutex);
|
||||
|
||||
m_pattern = pattern;
|
||||
}
|
||||
|
||||
bool NzDirectory::Copy(const NzString& sourcePath, const NzString& destPath)
|
||||
{
|
||||
if (sourcePath.IsEmpty() || destPath.IsEmpty())
|
||||
@@ -187,12 +219,12 @@ bool NzDirectory::Copy(const NzString& sourcePath, const NzString& destPath)
|
||||
{
|
||||
if (dir.IsResultDirectory())
|
||||
{
|
||||
if (!Copy(dir.GetResultPath(), dest + NAZARA_DIRECTORY_SEPARATOR + dir.GetResultName()))
|
||||
if (!Copy(dir.GetResultPath(), dest + NAZARA_DIRECTORY_SEPARATOR + dir.GetResultName()))
|
||||
return false;
|
||||
}
|
||||
else if (!NzFile::Copy(dir.GetResultPath(), dest + NAZARA_DIRECTORY_SEPARATOR + dir.GetResultName()))
|
||||
{
|
||||
NazaraError("Unable to copy \"" + dir.GetResultPath() + "\" to \"" + dest + NAZARA_DIRECTORY_SEPARATOR + dir.GetResultName() + '"');
|
||||
NazaraError("Failed to copy \"" + dir.GetResultPath() + "\" to \"" + dest + NAZARA_DIRECTORY_SEPARATOR + dir.GetResultName() + '"');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ NzString NzGetLastSystemError(unsigned int code)
|
||||
wchar_t* buffer = nullptr;
|
||||
|
||||
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
0,
|
||||
nullptr,
|
||||
code,
|
||||
0,
|
||||
reinterpret_cast<LPWSTR>(&buffer),
|
||||
|
||||
@@ -45,7 +45,7 @@ m_openMode(0)
|
||||
Open(openMode);
|
||||
}
|
||||
|
||||
NzFile::NzFile(NzFile&& file) :
|
||||
NzFile::NzFile(NzFile&& file) noexcept :
|
||||
m_endianness(file.m_endianness),
|
||||
m_filePath(std::move(file.m_filePath)),
|
||||
m_impl(file.m_impl),
|
||||
@@ -525,7 +525,7 @@ NzFile& NzFile::operator=(const NzString& filePath)
|
||||
return *this;
|
||||
}
|
||||
|
||||
NzFile& NzFile::operator=(NzFile&& file)
|
||||
NzFile& NzFile::operator=(NzFile&& file) noexcept
|
||||
{
|
||||
NazaraLock(m_mutex)
|
||||
|
||||
@@ -570,7 +570,7 @@ NzString NzFile::AbsolutePath(const NzString& filePath)
|
||||
NazaraError("Path unrecognized");
|
||||
return path;
|
||||
}
|
||||
#elif NAZARA_PLATEFORM_LINUX
|
||||
#elif defined(NAZARA_PLATEFORM_LINUX)
|
||||
base = '/';
|
||||
start = 0;
|
||||
#else
|
||||
@@ -718,7 +718,7 @@ bool NzFile::IsAbsolute(const NzString& path)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
#elif NAZARA_PLATEFORM_LINUX
|
||||
#elif defined(NAZARA_PLATEFORM_LINUX)
|
||||
return wpath.StartsWith('/');
|
||||
#else
|
||||
#error OS case not implemented
|
||||
@@ -752,7 +752,7 @@ NzString NzFile::NormalizeSeparators(const NzString& filePath)
|
||||
#elif defined(NAZARA_PLATFORM_LINUX)
|
||||
path.Replace('\\', '/');
|
||||
#else
|
||||
#error OS not handled
|
||||
#error OS case not implemented
|
||||
#endif
|
||||
|
||||
return path;
|
||||
@@ -793,4 +793,4 @@ bool NzFile::FillHash(NzHashImpl* hash) const
|
||||
}
|
||||
|
||||
return true;
|
||||
} // Fermeture auttomatique du fichier
|
||||
} // Fermeture automatique du fichier
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace
|
||||
* On little-endian machines, we can process properly aligned
|
||||
* data without copying it.
|
||||
*/
|
||||
if (!((data - reinterpret_cast<const nzUInt8*>(0)) & 3))
|
||||
if (!(data - static_cast<const nzUInt8*>(nullptr)) & 3)
|
||||
{
|
||||
/* data are properly aligned */
|
||||
X = reinterpret_cast<const nzUInt32*>(data);
|
||||
|
||||
@@ -315,119 +315,122 @@ void SHA1_Init(SHA_CTX* context)
|
||||
(b) = ROTL32(30, b); \
|
||||
j++;
|
||||
|
||||
void SHA1_Internal_Transform(SHA_CTX* context, const nzUInt32* data)
|
||||
namespace
|
||||
{
|
||||
nzUInt32 a, b, c, d, e;
|
||||
nzUInt32 T1, *W1;
|
||||
int j;
|
||||
void SHA1_Internal_Transform(SHA_CTX* context, const nzUInt32* data)
|
||||
{
|
||||
nzUInt32 a, b, c, d, e;
|
||||
nzUInt32 T1, *W1;
|
||||
int j;
|
||||
|
||||
W1 = reinterpret_cast<nzUInt32*>(context->s1.buffer);
|
||||
W1 = reinterpret_cast<nzUInt32*>(context->s1.buffer);
|
||||
|
||||
/* Initialize registers with the prev. intermediate value */
|
||||
a = context->s1.state[0];
|
||||
b = context->s1.state[1];
|
||||
c = context->s1.state[2];
|
||||
d = context->s1.state[3];
|
||||
e = context->s1.state[4];
|
||||
/* Initialize registers with the prev. intermediate value */
|
||||
a = context->s1.state[0];
|
||||
b = context->s1.state[1];
|
||||
c = context->s1.state[2];
|
||||
d = context->s1.state[3];
|
||||
e = context->s1.state[4];
|
||||
|
||||
j = 0;
|
||||
j = 0;
|
||||
|
||||
/* Rounds 0 to 15 unrolled: */
|
||||
ROUND1_0_TO_15(a,b,c,d,e);
|
||||
ROUND1_0_TO_15(e,a,b,c,d);
|
||||
ROUND1_0_TO_15(d,e,a,b,c);
|
||||
ROUND1_0_TO_15(c,d,e,a,b);
|
||||
ROUND1_0_TO_15(b,c,d,e,a);
|
||||
ROUND1_0_TO_15(a,b,c,d,e);
|
||||
ROUND1_0_TO_15(e,a,b,c,d);
|
||||
ROUND1_0_TO_15(d,e,a,b,c);
|
||||
ROUND1_0_TO_15(c,d,e,a,b);
|
||||
ROUND1_0_TO_15(b,c,d,e,a);
|
||||
ROUND1_0_TO_15(a,b,c,d,e);
|
||||
ROUND1_0_TO_15(e,a,b,c,d);
|
||||
ROUND1_0_TO_15(d,e,a,b,c);
|
||||
ROUND1_0_TO_15(c,d,e,a,b);
|
||||
ROUND1_0_TO_15(b,c,d,e,a);
|
||||
ROUND1_0_TO_15(a,b,c,d,e);
|
||||
/* Rounds 0 to 15 unrolled: */
|
||||
ROUND1_0_TO_15(a,b,c,d,e);
|
||||
ROUND1_0_TO_15(e,a,b,c,d);
|
||||
ROUND1_0_TO_15(d,e,a,b,c);
|
||||
ROUND1_0_TO_15(c,d,e,a,b);
|
||||
ROUND1_0_TO_15(b,c,d,e,a);
|
||||
ROUND1_0_TO_15(a,b,c,d,e);
|
||||
ROUND1_0_TO_15(e,a,b,c,d);
|
||||
ROUND1_0_TO_15(d,e,a,b,c);
|
||||
ROUND1_0_TO_15(c,d,e,a,b);
|
||||
ROUND1_0_TO_15(b,c,d,e,a);
|
||||
ROUND1_0_TO_15(a,b,c,d,e);
|
||||
ROUND1_0_TO_15(e,a,b,c,d);
|
||||
ROUND1_0_TO_15(d,e,a,b,c);
|
||||
ROUND1_0_TO_15(c,d,e,a,b);
|
||||
ROUND1_0_TO_15(b,c,d,e,a);
|
||||
ROUND1_0_TO_15(a,b,c,d,e);
|
||||
|
||||
/* Rounds 16 to 19 unrolled: */
|
||||
ROUND1_16_TO_19(e,a,b,c,d);
|
||||
ROUND1_16_TO_19(d,e,a,b,c);
|
||||
ROUND1_16_TO_19(c,d,e,a,b);
|
||||
ROUND1_16_TO_19(b,c,d,e,a);
|
||||
/* Rounds 16 to 19 unrolled: */
|
||||
ROUND1_16_TO_19(e,a,b,c,d);
|
||||
ROUND1_16_TO_19(d,e,a,b,c);
|
||||
ROUND1_16_TO_19(c,d,e,a,b);
|
||||
ROUND1_16_TO_19(b,c,d,e,a);
|
||||
|
||||
/* Rounds 20 to 39 unrolled: */
|
||||
ROUND1_20_TO_39(a,b,c,d,e);
|
||||
ROUND1_20_TO_39(e,a,b,c,d);
|
||||
ROUND1_20_TO_39(d,e,a,b,c);
|
||||
ROUND1_20_TO_39(c,d,e,a,b);
|
||||
ROUND1_20_TO_39(b,c,d,e,a);
|
||||
ROUND1_20_TO_39(a,b,c,d,e);
|
||||
ROUND1_20_TO_39(e,a,b,c,d);
|
||||
ROUND1_20_TO_39(d,e,a,b,c);
|
||||
ROUND1_20_TO_39(c,d,e,a,b);
|
||||
ROUND1_20_TO_39(b,c,d,e,a);
|
||||
ROUND1_20_TO_39(a,b,c,d,e);
|
||||
ROUND1_20_TO_39(e,a,b,c,d);
|
||||
ROUND1_20_TO_39(d,e,a,b,c);
|
||||
ROUND1_20_TO_39(c,d,e,a,b);
|
||||
ROUND1_20_TO_39(b,c,d,e,a);
|
||||
ROUND1_20_TO_39(a,b,c,d,e);
|
||||
ROUND1_20_TO_39(e,a,b,c,d);
|
||||
ROUND1_20_TO_39(d,e,a,b,c);
|
||||
ROUND1_20_TO_39(c,d,e,a,b);
|
||||
ROUND1_20_TO_39(b,c,d,e,a);
|
||||
/* Rounds 20 to 39 unrolled: */
|
||||
ROUND1_20_TO_39(a,b,c,d,e);
|
||||
ROUND1_20_TO_39(e,a,b,c,d);
|
||||
ROUND1_20_TO_39(d,e,a,b,c);
|
||||
ROUND1_20_TO_39(c,d,e,a,b);
|
||||
ROUND1_20_TO_39(b,c,d,e,a);
|
||||
ROUND1_20_TO_39(a,b,c,d,e);
|
||||
ROUND1_20_TO_39(e,a,b,c,d);
|
||||
ROUND1_20_TO_39(d,e,a,b,c);
|
||||
ROUND1_20_TO_39(c,d,e,a,b);
|
||||
ROUND1_20_TO_39(b,c,d,e,a);
|
||||
ROUND1_20_TO_39(a,b,c,d,e);
|
||||
ROUND1_20_TO_39(e,a,b,c,d);
|
||||
ROUND1_20_TO_39(d,e,a,b,c);
|
||||
ROUND1_20_TO_39(c,d,e,a,b);
|
||||
ROUND1_20_TO_39(b,c,d,e,a);
|
||||
ROUND1_20_TO_39(a,b,c,d,e);
|
||||
ROUND1_20_TO_39(e,a,b,c,d);
|
||||
ROUND1_20_TO_39(d,e,a,b,c);
|
||||
ROUND1_20_TO_39(c,d,e,a,b);
|
||||
ROUND1_20_TO_39(b,c,d,e,a);
|
||||
|
||||
/* Rounds 40 to 59 unrolled: */
|
||||
ROUND1_40_TO_59(a,b,c,d,e);
|
||||
ROUND1_40_TO_59(e,a,b,c,d);
|
||||
ROUND1_40_TO_59(d,e,a,b,c);
|
||||
ROUND1_40_TO_59(c,d,e,a,b);
|
||||
ROUND1_40_TO_59(b,c,d,e,a);
|
||||
ROUND1_40_TO_59(a,b,c,d,e);
|
||||
ROUND1_40_TO_59(e,a,b,c,d);
|
||||
ROUND1_40_TO_59(d,e,a,b,c);
|
||||
ROUND1_40_TO_59(c,d,e,a,b);
|
||||
ROUND1_40_TO_59(b,c,d,e,a);
|
||||
ROUND1_40_TO_59(a,b,c,d,e);
|
||||
ROUND1_40_TO_59(e,a,b,c,d);
|
||||
ROUND1_40_TO_59(d,e,a,b,c);
|
||||
ROUND1_40_TO_59(c,d,e,a,b);
|
||||
ROUND1_40_TO_59(b,c,d,e,a);
|
||||
ROUND1_40_TO_59(a,b,c,d,e);
|
||||
ROUND1_40_TO_59(e,a,b,c,d);
|
||||
ROUND1_40_TO_59(d,e,a,b,c);
|
||||
ROUND1_40_TO_59(c,d,e,a,b);
|
||||
ROUND1_40_TO_59(b,c,d,e,a);
|
||||
/* Rounds 40 to 59 unrolled: */
|
||||
ROUND1_40_TO_59(a,b,c,d,e);
|
||||
ROUND1_40_TO_59(e,a,b,c,d);
|
||||
ROUND1_40_TO_59(d,e,a,b,c);
|
||||
ROUND1_40_TO_59(c,d,e,a,b);
|
||||
ROUND1_40_TO_59(b,c,d,e,a);
|
||||
ROUND1_40_TO_59(a,b,c,d,e);
|
||||
ROUND1_40_TO_59(e,a,b,c,d);
|
||||
ROUND1_40_TO_59(d,e,a,b,c);
|
||||
ROUND1_40_TO_59(c,d,e,a,b);
|
||||
ROUND1_40_TO_59(b,c,d,e,a);
|
||||
ROUND1_40_TO_59(a,b,c,d,e);
|
||||
ROUND1_40_TO_59(e,a,b,c,d);
|
||||
ROUND1_40_TO_59(d,e,a,b,c);
|
||||
ROUND1_40_TO_59(c,d,e,a,b);
|
||||
ROUND1_40_TO_59(b,c,d,e,a);
|
||||
ROUND1_40_TO_59(a,b,c,d,e);
|
||||
ROUND1_40_TO_59(e,a,b,c,d);
|
||||
ROUND1_40_TO_59(d,e,a,b,c);
|
||||
ROUND1_40_TO_59(c,d,e,a,b);
|
||||
ROUND1_40_TO_59(b,c,d,e,a);
|
||||
|
||||
/* Rounds 60 to 79 unrolled: */
|
||||
ROUND1_60_TO_79(a,b,c,d,e);
|
||||
ROUND1_60_TO_79(e,a,b,c,d);
|
||||
ROUND1_60_TO_79(d,e,a,b,c);
|
||||
ROUND1_60_TO_79(c,d,e,a,b);
|
||||
ROUND1_60_TO_79(b,c,d,e,a);
|
||||
ROUND1_60_TO_79(a,b,c,d,e);
|
||||
ROUND1_60_TO_79(e,a,b,c,d);
|
||||
ROUND1_60_TO_79(d,e,a,b,c);
|
||||
ROUND1_60_TO_79(c,d,e,a,b);
|
||||
ROUND1_60_TO_79(b,c,d,e,a);
|
||||
ROUND1_60_TO_79(a,b,c,d,e);
|
||||
ROUND1_60_TO_79(e,a,b,c,d);
|
||||
ROUND1_60_TO_79(d,e,a,b,c);
|
||||
ROUND1_60_TO_79(c,d,e,a,b);
|
||||
ROUND1_60_TO_79(b,c,d,e,a);
|
||||
ROUND1_60_TO_79(a,b,c,d,e);
|
||||
ROUND1_60_TO_79(e,a,b,c,d);
|
||||
ROUND1_60_TO_79(d,e,a,b,c);
|
||||
ROUND1_60_TO_79(c,d,e,a,b);
|
||||
ROUND1_60_TO_79(b,c,d,e,a);
|
||||
/* Rounds 60 to 79 unrolled: */
|
||||
ROUND1_60_TO_79(a,b,c,d,e);
|
||||
ROUND1_60_TO_79(e,a,b,c,d);
|
||||
ROUND1_60_TO_79(d,e,a,b,c);
|
||||
ROUND1_60_TO_79(c,d,e,a,b);
|
||||
ROUND1_60_TO_79(b,c,d,e,a);
|
||||
ROUND1_60_TO_79(a,b,c,d,e);
|
||||
ROUND1_60_TO_79(e,a,b,c,d);
|
||||
ROUND1_60_TO_79(d,e,a,b,c);
|
||||
ROUND1_60_TO_79(c,d,e,a,b);
|
||||
ROUND1_60_TO_79(b,c,d,e,a);
|
||||
ROUND1_60_TO_79(a,b,c,d,e);
|
||||
ROUND1_60_TO_79(e,a,b,c,d);
|
||||
ROUND1_60_TO_79(d,e,a,b,c);
|
||||
ROUND1_60_TO_79(c,d,e,a,b);
|
||||
ROUND1_60_TO_79(b,c,d,e,a);
|
||||
ROUND1_60_TO_79(a,b,c,d,e);
|
||||
ROUND1_60_TO_79(e,a,b,c,d);
|
||||
ROUND1_60_TO_79(d,e,a,b,c);
|
||||
ROUND1_60_TO_79(c,d,e,a,b);
|
||||
ROUND1_60_TO_79(b,c,d,e,a);
|
||||
|
||||
/* Compute the current intermediate hash value */
|
||||
context->s1.state[0] += a;
|
||||
context->s1.state[1] += b;
|
||||
context->s1.state[2] += c;
|
||||
context->s1.state[3] += d;
|
||||
context->s1.state[4] += e;
|
||||
/* Compute the current intermediate hash value */
|
||||
context->s1.state[0] += a;
|
||||
context->s1.state[1] += b;
|
||||
context->s1.state[2] += c;
|
||||
context->s1.state[3] += d;
|
||||
context->s1.state[4] += e;
|
||||
}
|
||||
}
|
||||
|
||||
void SHA1_Update(SHA_CTX* context, const nzUInt8* data, std::size_t len)
|
||||
@@ -766,9 +769,12 @@ void SHA224_Init(SHA_CTX* context)
|
||||
SHA256_Internal_Init(context, sha224_initial_hash_value);
|
||||
}
|
||||
|
||||
void SHA224_Internal_Transform(SHA_CTX* context, const nzUInt32* data)
|
||||
namespace
|
||||
{
|
||||
SHA256_Internal_Transform(context, data);
|
||||
void SHA224_Internal_Transform(SHA_CTX* context, const nzUInt32* data)
|
||||
{
|
||||
SHA256_Internal_Transform(context, data);
|
||||
}
|
||||
}
|
||||
|
||||
void SHA224_Update(SHA_CTX* context, const nzUInt8 *data, std::size_t len)
|
||||
|
||||
@@ -42,7 +42,7 @@ m_digestLength(rhs.m_digestLength)
|
||||
m_digest = nullptr;
|
||||
}
|
||||
|
||||
NzHashDigest::NzHashDigest(NzHashDigest&& rhs) :
|
||||
NzHashDigest::NzHashDigest(NzHashDigest&& rhs) noexcept :
|
||||
m_hashName(std::move(rhs.m_hashName)),
|
||||
m_digest(rhs.m_digest),
|
||||
m_digestLength(rhs.m_digestLength)
|
||||
@@ -118,7 +118,7 @@ NzHashDigest& NzHashDigest::operator=(const NzHashDigest& rhs)
|
||||
return *this;
|
||||
}
|
||||
|
||||
NzHashDigest& NzHashDigest::operator=(NzHashDigest&& rhs)
|
||||
NzHashDigest& NzHashDigest::operator=(NzHashDigest&& rhs) noexcept
|
||||
{
|
||||
std::swap(m_hashName, rhs.m_hashName);
|
||||
std::swap(m_digest, rhs.m_digest);
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Basic.hpp>
|
||||
#include <ctime>
|
||||
#include <cstring>
|
||||
|
||||
#if NAZARA_CORE_REDIRECT_TO_CERR_ON_LOG_FAILURE
|
||||
#if NAZARA_CORE_DUPLICATE_TO_COUT
|
||||
#include <cstdio>
|
||||
#endif
|
||||
|
||||
@@ -17,7 +18,7 @@
|
||||
|
||||
namespace
|
||||
{
|
||||
NzString errorType[] = {
|
||||
const char* errorType[] = {
|
||||
"Assert failed: ", // nzErrorType_AssertFailed
|
||||
"Internal error: ", // nzErrorType_Internal
|
||||
"Error: ", // nzErrorType_Normal
|
||||
@@ -124,12 +125,11 @@ void NzLog::Write(const NzString& string)
|
||||
line += string;
|
||||
line += '\n';
|
||||
|
||||
#if NAZARA_CORE_REDIRECT_TO_CERR_ON_LOG_FAILURE
|
||||
if (!m_file->IsOpen() || !m_file->Write(line))
|
||||
std::fputs(line.GetBuffer(), stderr);
|
||||
#else
|
||||
if (m_file->IsOpen())
|
||||
m_file->Write(line);
|
||||
|
||||
#if NAZARA_CORE_DUPLICATE_TO_COUT
|
||||
std::fputs(line.GetConstBuffer(), stderr);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -137,7 +137,7 @@ void NzLog::Write(const NzString& string)
|
||||
void NzLog::WriteError(nzErrorType type, const NzString& error, unsigned int line, const NzString& file, const NzString& func)
|
||||
{
|
||||
NzString stream;
|
||||
stream.Reserve(errorType[type].GetSize() + error.GetSize() + 2 + file.GetSize() + 1 + NzGetNumberLength(line) +2 + func.GetSize() + 1);
|
||||
stream.Reserve(std::strlen(errorType[type]) + error.GetSize() + 2 + file.GetSize() + 1 + NzGetNumberLength(line) +2 + func.GetSize() + 1);
|
||||
stream += errorType[type];
|
||||
stream += error;
|
||||
stream += " (";
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Utility/Resource.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
NzResource::NzResource(bool persistent) :
|
||||
m_resourcePersistent(persistent),
|
||||
@@ -33,7 +33,7 @@ bool NzResource::IsPersistent() const
|
||||
|
||||
void NzResource::RemoveResourceReference() const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
#if NAZARA_CORE_SAFE
|
||||
if (m_resourceReferenceCount == 0)
|
||||
{
|
||||
NazaraError("Impossible to remove reference (Ref. counter is already 0)");
|
||||
@@ -142,7 +142,7 @@ m_sharedString(string.m_sharedString)
|
||||
}
|
||||
}
|
||||
|
||||
NzString::NzString(NzString&& string) :
|
||||
NzString::NzString(NzString&& string) noexcept :
|
||||
m_sharedString(string.m_sharedString)
|
||||
{
|
||||
string.m_sharedString = &emptyString;
|
||||
@@ -307,7 +307,6 @@ unsigned int NzString::Count(char character, int start, nzUInt32 flags) const
|
||||
{
|
||||
char character_lower = nzToLower(character);
|
||||
char character_upper = nzToUpper(character);
|
||||
unsigned int count = 0;
|
||||
do
|
||||
{
|
||||
if (*str == character_lower || *str == character_upper)
|
||||
@@ -807,14 +806,14 @@ unsigned int NzString::Find(const char* string, int start, nzUInt32 flags) const
|
||||
{
|
||||
if (NzUnicode::GetLowercase(*it) == c)
|
||||
{
|
||||
const char* pos = it.base();
|
||||
const char* ptrPos = it.base();
|
||||
++it;
|
||||
|
||||
utf8::unchecked::iterator<const char*> it2(t);
|
||||
while (true)
|
||||
{
|
||||
if (*it2 == '\0')
|
||||
return static_cast<unsigned int>(pos - m_sharedString->string);
|
||||
return static_cast<unsigned int>(ptrPos - m_sharedString->string);
|
||||
|
||||
if (*it == '\0')
|
||||
return npos;
|
||||
@@ -836,14 +835,14 @@ unsigned int NzString::Find(const char* string, int start, nzUInt32 flags) const
|
||||
{
|
||||
if (nzToLower(*str) == c)
|
||||
{
|
||||
char* pos = str;
|
||||
char* ptrPos = str;
|
||||
str++;
|
||||
|
||||
const char* ptr = &string[1];
|
||||
while (true)
|
||||
{
|
||||
if (*ptr == '\0')
|
||||
return static_cast<unsigned int>(pos - m_sharedString->string);
|
||||
return static_cast<unsigned int>(ptrPos - m_sharedString->string);
|
||||
|
||||
if (*str == '\0')
|
||||
return npos;
|
||||
@@ -897,14 +896,14 @@ unsigned int NzString::Find(const NzString& string, int start, nzUInt32 flags) c
|
||||
{
|
||||
if (NzUnicode::GetLowercase(*it) == c)
|
||||
{
|
||||
const char* pos = it.base();
|
||||
const char* ptrPos = it.base();
|
||||
++it;
|
||||
|
||||
utf8::unchecked::iterator<const char*> it2(t);
|
||||
while (true)
|
||||
{
|
||||
if (*it2 == '\0')
|
||||
return static_cast<unsigned int>(pos - m_sharedString->string);
|
||||
return static_cast<unsigned int>(ptrPos - m_sharedString->string);
|
||||
|
||||
if (*it == '\0')
|
||||
return npos;
|
||||
@@ -926,14 +925,14 @@ unsigned int NzString::Find(const NzString& string, int start, nzUInt32 flags) c
|
||||
{
|
||||
if (nzToLower(*str) == c)
|
||||
{
|
||||
char* pos = str;
|
||||
char* ptrPos = str;
|
||||
str++;
|
||||
|
||||
const char* ptr = &string.m_sharedString->string[1];
|
||||
while (true)
|
||||
{
|
||||
if (*ptr == '\0')
|
||||
return static_cast<unsigned int>(pos - m_sharedString->string);
|
||||
return static_cast<unsigned int>(ptrPos - m_sharedString->string);
|
||||
|
||||
if (*str == '\0')
|
||||
return npos;
|
||||
@@ -2296,7 +2295,7 @@ char16_t* NzString::GetUtf16Buffer(unsigned int* size) const
|
||||
catch (const utf8::exception& exception)
|
||||
{
|
||||
NazaraError("UTF-8 error : " + NzString(exception.what()));
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -2340,7 +2339,7 @@ char32_t* NzString::GetUtf32Buffer(unsigned int* size) const
|
||||
catch (const utf8::exception& exception)
|
||||
{
|
||||
NazaraError("UTF-8 error : " + NzString(exception.what()));
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -2387,7 +2386,7 @@ wchar_t* NzString::GetWideBuffer(unsigned int* size) const
|
||||
catch (const utf8::exception& exception)
|
||||
{
|
||||
NazaraError("UTF-8 error : " + NzString(exception.what()));
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -2621,7 +2620,7 @@ bool NzString::IsNull() const
|
||||
|
||||
bool NzString::IsNumber(nzUInt8 base, nzUInt32 flags) const
|
||||
{
|
||||
#if !NAZARA_UNSAFE
|
||||
#if NAZARA_CORE_SAFE
|
||||
if (base < 2 || base > 36)
|
||||
{
|
||||
NazaraError("Base must be between 2 and 36");
|
||||
@@ -2770,11 +2769,11 @@ unsigned int NzString::Replace(char oldCharacter, char newCharacter, int start,
|
||||
{
|
||||
if (!found)
|
||||
{
|
||||
unsigned int pos = ptr-m_sharedString->string;
|
||||
unsigned int offset = ptr-m_sharedString->string;
|
||||
|
||||
EnsureOwnership();
|
||||
|
||||
ptr = &m_sharedString->string[pos];
|
||||
ptr = &m_sharedString->string[offset];
|
||||
found = true;
|
||||
}
|
||||
|
||||
@@ -2790,11 +2789,11 @@ unsigned int NzString::Replace(char oldCharacter, char newCharacter, int start,
|
||||
{
|
||||
if (!found)
|
||||
{
|
||||
unsigned int pos = ptr-m_sharedString->string;
|
||||
unsigned int offset = ptr-m_sharedString->string;
|
||||
|
||||
EnsureOwnership();
|
||||
|
||||
ptr = &m_sharedString->string[pos];
|
||||
ptr = &m_sharedString->string[offset];
|
||||
found = true;
|
||||
}
|
||||
|
||||
@@ -2954,6 +2953,7 @@ unsigned int NzString::Replace(const NzString& oldString, const NzString& replac
|
||||
|
||||
unsigned int NzString::ReplaceAny(const char* oldCharacters, char replaceCharacter, int start, nzUInt32 flags)
|
||||
{
|
||||
///FIXME: Ne gère pas l'UTF-8
|
||||
if (!oldCharacters || !oldCharacters[0])
|
||||
return 0;
|
||||
|
||||
@@ -2982,11 +2982,11 @@ unsigned int NzString::ReplaceAny(const char* oldCharacters, char replaceCharact
|
||||
{
|
||||
if (!found)
|
||||
{
|
||||
unsigned int pos = ptr-m_sharedString->string;
|
||||
unsigned int offset = ptr-m_sharedString->string;
|
||||
|
||||
EnsureOwnership();
|
||||
|
||||
ptr = &m_sharedString->string[pos];
|
||||
ptr = &m_sharedString->string[offset];
|
||||
found = true;
|
||||
}
|
||||
|
||||
@@ -3006,11 +3006,11 @@ unsigned int NzString::ReplaceAny(const char* oldCharacters, char replaceCharact
|
||||
{
|
||||
if (!found)
|
||||
{
|
||||
unsigned int pos = ptr-m_sharedString->string;
|
||||
unsigned int offset = ptr-m_sharedString->string;
|
||||
|
||||
EnsureOwnership();
|
||||
|
||||
ptr = &m_sharedString->string[pos];
|
||||
ptr = &m_sharedString->string[offset];
|
||||
found = true;
|
||||
}
|
||||
|
||||
@@ -3203,7 +3203,10 @@ void NzString::Reserve(unsigned int bufferSize)
|
||||
NzString& NzString::Resize(int size, char character)
|
||||
{
|
||||
if (size == 0)
|
||||
{
|
||||
Clear(true);
|
||||
return *this;
|
||||
}
|
||||
|
||||
if (size < 0)
|
||||
size = std::max(static_cast<int>(m_sharedString->size + size), 0);
|
||||
@@ -3249,9 +3252,6 @@ NzString& NzString::Resize(int size, char character)
|
||||
|
||||
NzString NzString::Resized(int size, char character) const
|
||||
{
|
||||
if (size == 0)
|
||||
return NzString();
|
||||
|
||||
if (size < 0)
|
||||
size = m_sharedString->size + size;
|
||||
|
||||
@@ -3692,12 +3692,12 @@ NzString NzString::Substr(int startPos, int endPos) const
|
||||
return NzString();
|
||||
}
|
||||
|
||||
unsigned int end = std::min(static_cast<unsigned int>(endPos), m_sharedString->size-1);
|
||||
unsigned int minEnd = std::min(static_cast<unsigned int>(endPos), m_sharedString->size-1);
|
||||
|
||||
if (start > end || start >= m_sharedString->size)
|
||||
if (start > minEnd || start >= m_sharedString->size)
|
||||
return NzString();
|
||||
|
||||
unsigned int size = end-start+1;
|
||||
unsigned int size = minEnd-start+1;
|
||||
char* str = new char[size+1];
|
||||
std::memcpy(str, &m_sharedString->string[start], size*sizeof(char));
|
||||
str[size] = '\0';
|
||||
@@ -4232,7 +4232,7 @@ NzString& NzString::operator=(const NzString& string)
|
||||
return *this;
|
||||
}
|
||||
|
||||
NzString& NzString::operator=(NzString&& string)
|
||||
NzString& NzString::operator=(NzString&& string) noexcept
|
||||
{
|
||||
std::swap(m_sharedString, string.m_sharedString);
|
||||
|
||||
@@ -5107,7 +5107,6 @@ void NzString::ReleaseString()
|
||||
|
||||
if (freeSharedString)
|
||||
{
|
||||
NazaraMutexUnlock(m_sharedString->mutex);
|
||||
delete[] m_sharedString->string;
|
||||
delete m_sharedString;
|
||||
}
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
|
||||
// Source: http://www.cs.wustl.edu/~schmidt/win32-cv-1.html
|
||||
|
||||
#include <Nazara/Core/Win32/ThreadConditionImpl.hpp>
|
||||
#include <Nazara/Core/Win32/ConditionVariableImpl.hpp>
|
||||
#include <Nazara/Core/Win32/MutexImpl.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
NzThreadConditionImpl::NzThreadConditionImpl()
|
||||
NzConditionVariableImpl::NzConditionVariableImpl()
|
||||
{
|
||||
#ifdef NAZARA_PLATFORM_WINDOWSVISTA
|
||||
#if NAZARA_CORE_WINDOWS_VISTA
|
||||
InitializeConditionVariable(&m_cv);
|
||||
#else
|
||||
m_count = 0;
|
||||
@@ -20,16 +20,16 @@ NzThreadConditionImpl::NzThreadConditionImpl()
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef NAZARA_PLATFORM_WINDOWSVISTA
|
||||
NzThreadConditionImpl::~NzThreadConditionImpl()
|
||||
#if !NAZARA_CORE_WINDOWS_VISTA
|
||||
NzConditionVariableImpl::~NzConditionVariableImpl()
|
||||
{
|
||||
DeleteCriticalSection(&m_countLock);
|
||||
}
|
||||
#endif
|
||||
|
||||
void NzThreadConditionImpl::Signal()
|
||||
void NzConditionVariableImpl::Signal()
|
||||
{
|
||||
#ifdef NAZARA_PLATFORM_WINDOWSVISTA
|
||||
#if NAZARA_CORE_WINDOWS_VISTA
|
||||
WakeConditionVariable(&m_cv);
|
||||
#else
|
||||
// Avoid race conditions.
|
||||
@@ -42,9 +42,9 @@ void NzThreadConditionImpl::Signal()
|
||||
#endif
|
||||
}
|
||||
|
||||
void NzThreadConditionImpl::SignalAll()
|
||||
void NzConditionVariableImpl::SignalAll()
|
||||
{
|
||||
#ifdef NAZARA_PLATFORM_WINDOWSVISTA
|
||||
#if NAZARA_CORE_WINDOWS_VISTA
|
||||
WakeAllConditionVariable(&m_cv);
|
||||
#else
|
||||
// Avoid race conditions.
|
||||
@@ -57,14 +57,14 @@ void NzThreadConditionImpl::SignalAll()
|
||||
#endif
|
||||
}
|
||||
|
||||
void NzThreadConditionImpl::Wait(NzMutexImpl* mutex)
|
||||
void NzConditionVariableImpl::Wait(NzMutexImpl* mutex)
|
||||
{
|
||||
Wait(mutex, INFINITE);
|
||||
}
|
||||
|
||||
bool NzThreadConditionImpl::Wait(NzMutexImpl* mutex, nzUInt32 timeout)
|
||||
bool NzConditionVariableImpl::Wait(NzMutexImpl* mutex, nzUInt32 timeout)
|
||||
{
|
||||
#ifdef NAZARA_PLATFORM_WINDOWSVISTA
|
||||
#if NAZARA_CORE_WINDOWS_VISTA
|
||||
return SleepConditionVariableCS(&m_cv, mutex->m_criticalSection, timeout);
|
||||
#else
|
||||
// Avoid race conditions.
|
||||
@@ -6,22 +6,22 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_THREADCONDITIONIMPL_HPP
|
||||
#define NAZARA_THREADCONDITIONIMPL_HPP
|
||||
#ifndef NAZARA_CONDITIONVARIABLEIMPL_HPP
|
||||
#define NAZARA_CONDITIONVARIABLEIMPL_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <windows.h>
|
||||
|
||||
class NzMutexImpl;
|
||||
|
||||
class NzThreadConditionImpl
|
||||
class NzConditionVariableImpl
|
||||
{
|
||||
public:
|
||||
NzThreadConditionImpl();
|
||||
#ifdef NAZARA_PLATFORM_WINDOWSVISTA
|
||||
~NzThreadConditionImpl() = default;
|
||||
NzConditionVariableImpl();
|
||||
#if NAZARA_CORE_WINDOWS_VISTA
|
||||
~NzConditionVariableImpl() = default;
|
||||
#else
|
||||
~NzThreadConditionImpl();
|
||||
~NzConditionVariableImpl();
|
||||
#endif
|
||||
|
||||
void Signal();
|
||||
@@ -31,7 +31,7 @@ class NzThreadConditionImpl
|
||||
bool Wait(NzMutexImpl* mutex, nzUInt32 timeout);
|
||||
|
||||
private:
|
||||
#ifdef NAZARA_PLATFORM_WINDOWSVISTA
|
||||
#if NAZARA_CORE_WINDOWS_VISTA
|
||||
CONDITION_VARIABLE m_cv;
|
||||
#else
|
||||
enum
|
||||
@@ -48,4 +48,4 @@ class NzThreadConditionImpl
|
||||
|
||||
};
|
||||
|
||||
#endif // NAZARA_THREADCONDITIONIMPL_HPP
|
||||
#endif // NAZARA_CONDITIONVARIABLEIMPL_HPP
|
||||
@@ -117,7 +117,7 @@ std::size_t NzFileImpl::Read(void* buffer, std::size_t size)
|
||||
/// D'après les tests, ce n'est pas le cas, la taille lue est inférieure à la taille en argument, mais pas nulle
|
||||
/// Peut-être ais-je mal compris la documentation
|
||||
/// Le correctif (dans le cas où la doc serait vraie) est commenté en début de fonction et après ce commentaire
|
||||
/// Il est cependant plus lourd, et ne fonctionne pas selon les tests...
|
||||
/// Il est cependant plus lourd, et ne fonctionne pas avec le comportement observé de la fonction
|
||||
/*
|
||||
if (read == 0)
|
||||
{
|
||||
@@ -254,7 +254,7 @@ time_t NzFileImpl::GetCreationTime(const NzString& filePath)
|
||||
|
||||
CloseHandle(handle);
|
||||
|
||||
return FileTimeToTime(&creationTime);
|
||||
return NzFileTimeToTime(&creationTime);
|
||||
}
|
||||
|
||||
time_t NzFileImpl::GetLastAccessTime(const NzString& filePath)
|
||||
@@ -277,7 +277,7 @@ time_t NzFileImpl::GetLastAccessTime(const NzString& filePath)
|
||||
|
||||
CloseHandle(handle);
|
||||
|
||||
return FileTimeToTime(&accessTime);
|
||||
return NzFileTimeToTime(&accessTime);
|
||||
}
|
||||
|
||||
time_t NzFileImpl::GetLastWriteTime(const NzString& filePath)
|
||||
@@ -300,7 +300,7 @@ time_t NzFileImpl::GetLastWriteTime(const NzString& filePath)
|
||||
|
||||
CloseHandle(handle);
|
||||
|
||||
return FileTimeToTime(&writeTime);
|
||||
return NzFileTimeToTime(&writeTime);
|
||||
}
|
||||
|
||||
nzUInt64 NzFileImpl::GetSize(const NzString& filePath)
|
||||
|
||||
@@ -7,7 +7,11 @@
|
||||
|
||||
NzMutexImpl::NzMutexImpl()
|
||||
{
|
||||
#if NAZARA_CORE_WINDOWS_CS_SPINLOCKS > 0
|
||||
InitializeCriticalSectionAndSpinCount(&m_criticalSection, NAZARA_CORE_WINDOWS_CS_SPINLOCKS);
|
||||
#else
|
||||
InitializeCriticalSection(&m_criticalSection);
|
||||
#endif
|
||||
}
|
||||
|
||||
NzMutexImpl::~NzMutexImpl()
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
class NzThreadConditionImpl;
|
||||
class NzConditionVariableImpl;
|
||||
|
||||
class NzMutexImpl
|
||||
{
|
||||
friend class NzThreadConditionImpl;
|
||||
friend class NzConditionVariableImpl;
|
||||
|
||||
public:
|
||||
NzMutexImpl();
|
||||
|
||||
24
src/Nazara/Core/Win32/Time.cpp
Normal file
24
src/Nazara/Core/Win32/Time.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Win32/Time.hpp>
|
||||
|
||||
time_t NzFileTimeToTime(FILETIME* time)
|
||||
{
|
||||
SYSTEMTIME stUTC, stLocal;
|
||||
|
||||
FileTimeToSystemTime(time, &stUTC);
|
||||
SystemTimeToTzSpecificLocalTime(nullptr, &stUTC, &stLocal);
|
||||
|
||||
std::tm timeinfo;
|
||||
timeinfo.tm_sec = stLocal.wSecond;
|
||||
timeinfo.tm_min = stLocal.wMinute;
|
||||
timeinfo.tm_hour = stLocal.wHour;
|
||||
timeinfo.tm_mday = stLocal.wDay;
|
||||
timeinfo.tm_mon = stLocal.wMonth-1;
|
||||
timeinfo.tm_year = stLocal.wYear-1900;
|
||||
timeinfo.tm_isdst = -1;
|
||||
|
||||
return std::mktime(&timeinfo);
|
||||
}
|
||||
@@ -10,23 +10,6 @@
|
||||
#include <ctime>
|
||||
#include <windows.h>
|
||||
|
||||
time_t FileTimeToTime(FILETIME* time)
|
||||
{
|
||||
SYSTEMTIME stUTC, stLocal;
|
||||
|
||||
FileTimeToSystemTime(time, &stUTC);
|
||||
SystemTimeToTzSpecificLocalTime(nullptr, &stUTC, &stLocal);
|
||||
|
||||
std::tm timeinfo;
|
||||
timeinfo.tm_sec = stLocal.wSecond;
|
||||
timeinfo.tm_min = stLocal.wMinute;
|
||||
timeinfo.tm_hour = stLocal.wHour;
|
||||
timeinfo.tm_mday = stLocal.wDay;
|
||||
timeinfo.tm_mon = stLocal.wMonth-1;
|
||||
timeinfo.tm_year = stLocal.wYear-1900;
|
||||
timeinfo.tm_isdst = -1;
|
||||
|
||||
return std::mktime(&timeinfo);
|
||||
}
|
||||
time_t NzFileTimeToTime(FILETIME* time);
|
||||
|
||||
#endif // NAZARA_WINDOWS_TIME_HPP
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Network/Config.hpp>
|
||||
#if NAZARA_NETWORK_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
|
||||
#include <Nazara/Core/Debug/MemoryLeakTracker.hpp>
|
||||
#include <new>
|
||||
|
||||
void* operator new(std::size_t size)
|
||||
{
|
||||
return NzMemoryManager::Allocate(size, false);
|
||||
}
|
||||
|
||||
void* operator new[](std::size_t size)
|
||||
{
|
||||
return NzMemoryManager::Allocate(size, true);
|
||||
}
|
||||
|
||||
void operator delete(void* pointer) noexcept
|
||||
{
|
||||
NzMemoryManager::Free(pointer, false);
|
||||
}
|
||||
|
||||
void operator delete[](void* pointer) noexcept
|
||||
{
|
||||
NzMemoryManager::Free(pointer, true);
|
||||
}
|
||||
#endif
|
||||
@@ -3,57 +3,47 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Noise/Noise.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
NzNoise::NzNoise()
|
||||
{
|
||||
}
|
||||
|
||||
NzNoise::~NzNoise()
|
||||
{
|
||||
if (s_initialized)
|
||||
Uninitialize();
|
||||
}
|
||||
|
||||
bool NzNoise::Initialize()
|
||||
{
|
||||
#if NAZARA_NOISE_SAFE
|
||||
if (s_initialized)
|
||||
if (s_moduleReferenceCouter++ != 0)
|
||||
return true; // Déjà initialisé
|
||||
|
||||
// Initialisation des dépendances
|
||||
if (!NzCore::Initialize())
|
||||
{
|
||||
NazaraError("NzNoise already initialized");
|
||||
return true;
|
||||
NazaraError("Failed to initialize core module");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Initialisation du module
|
||||
|
||||
s_initialized = true;
|
||||
NazaraNotice("Initialized: Noise module");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzNoise::IsInitialized()
|
||||
{
|
||||
return s_moduleReferenceCouter != 0;
|
||||
}
|
||||
|
||||
void NzNoise::Uninitialize()
|
||||
{
|
||||
#if NAZARA_NOISE_SAFE
|
||||
if (!s_initialized)
|
||||
{
|
||||
NazaraError("NzNoise not initialized");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (--s_moduleReferenceCouter != 0)
|
||||
return; // Encore utilisé
|
||||
|
||||
// Libération du module
|
||||
|
||||
s_initialized = false;
|
||||
// Libération des dépendances
|
||||
NzCore::Uninitialize();
|
||||
|
||||
NazaraNotice("Uninitialized: Noise module");
|
||||
}
|
||||
|
||||
bool NzNoise::IsInitialized()
|
||||
{
|
||||
return s_initialized;
|
||||
}
|
||||
|
||||
bool NzNoise::s_initialized = false;
|
||||
|
||||
//#include <Nazara/Core/DebugOff.hpp> //A INCLURE ?
|
||||
unsigned int NzNoise::s_moduleReferenceCouter = 0;
|
||||
|
||||
@@ -63,11 +63,22 @@ bool NzGLSLShader::Bind()
|
||||
|
||||
glUseProgram(m_program);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::BindTextures()
|
||||
{
|
||||
for (auto it = m_textures.begin(); it != m_textures.end(); ++it)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0 + it->second.unit);
|
||||
if (!it->second.texture->Bind())
|
||||
NazaraWarning("Failed to bind texture");
|
||||
TextureSlot& slot = it->second;
|
||||
if (!slot.updated)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0 + slot.unit);
|
||||
if (!slot.texture->Bind())
|
||||
NazaraWarning("Failed to bind texture");
|
||||
|
||||
slot.updated = true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -78,6 +89,7 @@ bool NzGLSLShader::Compile()
|
||||
NzContext::EnsureContext();
|
||||
|
||||
m_idCache.clear();
|
||||
m_textures.clear();
|
||||
|
||||
glLinkProgram(m_program);
|
||||
|
||||
@@ -86,8 +98,8 @@ bool NzGLSLShader::Compile()
|
||||
|
||||
if (success == GL_TRUE)
|
||||
{
|
||||
static NzString success("Linkage successful");
|
||||
m_log = success;
|
||||
static NzString successStr("Linkage successful");
|
||||
m_log = successStr;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -131,7 +143,7 @@ bool NzGLSLShader::Create()
|
||||
glBindAttribLocation(m_program, attribIndex[nzElementUsage_Tangent], "Tangent");
|
||||
|
||||
NzString uniform = "TexCoord";
|
||||
unsigned int maxTexCoords = NazaraRenderer->GetMaxTextureUnits();
|
||||
unsigned int maxTexCoords = NzRenderer::GetMaxTextureUnits();
|
||||
for (unsigned int i = 0; i < maxTexCoords; ++i)
|
||||
{
|
||||
NzString uniformName = uniform + NzString::Number(i);
|
||||
@@ -148,6 +160,9 @@ void NzGLSLShader::Destroy()
|
||||
{
|
||||
NzContext::EnsureContext();
|
||||
|
||||
for (auto it = m_textures.begin(); it != m_textures.end(); ++it)
|
||||
it->second.texture->RemoveResourceReference();
|
||||
|
||||
for (GLuint shader : m_shaders)
|
||||
if (shader)
|
||||
glDeleteShader(shader);
|
||||
@@ -183,7 +198,7 @@ NzString NzGLSLShader::GetSourceCode(nzShaderType type) const
|
||||
return source;
|
||||
}
|
||||
|
||||
GLint NzGLSLShader::GetUniformLocation(const NzString& name) const
|
||||
int NzGLSLShader::GetUniformLocation(const NzString& name) const
|
||||
{
|
||||
std::map<NzString, GLint>::const_iterator it = m_idCache.find(name);
|
||||
GLint id;
|
||||
@@ -232,8 +247,8 @@ bool NzGLSLShader::Load(nzShaderType type, const NzString& source)
|
||||
glAttachShader(m_program, shader);
|
||||
m_shaders[type] = shader;
|
||||
|
||||
static NzString success("Compilation successful");
|
||||
m_log = success;
|
||||
static NzString successStr("Compilation successful");
|
||||
m_log = successStr;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -280,226 +295,247 @@ bool NzGLSLShader::Lock()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendBoolean(const NzString& name, bool value)
|
||||
bool NzGLSLShader::SendBoolean(int location, bool value)
|
||||
{
|
||||
if (glProgramUniform1i)
|
||||
glProgramUniform1i(m_program, GetUniformLocation(name), value);
|
||||
glProgramUniform1i(m_program, location, value);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform1i(GetUniformLocation(name), value);
|
||||
glUniform1i(location, value);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendDouble(const NzString& name, double value)
|
||||
bool NzGLSLShader::SendDouble(int location, double value)
|
||||
{
|
||||
if (glProgramUniform1d)
|
||||
glProgramUniform1d(m_program, GetUniformLocation(name), value);
|
||||
glProgramUniform1d(m_program, location, value);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform1d(GetUniformLocation(name), value);
|
||||
glUniform1d(location, value);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendFloat(const NzString& name, float value)
|
||||
bool NzGLSLShader::SendFloat(int location, float value)
|
||||
{
|
||||
if (glProgramUniform1f)
|
||||
glProgramUniform1f(m_program, GetUniformLocation(name), value);
|
||||
glProgramUniform1f(m_program, location, value);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform1f(GetUniformLocation(name), value);
|
||||
glUniform1f(location, value);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendInteger(const NzString& name, int value)
|
||||
bool NzGLSLShader::SendInteger(int location, int value)
|
||||
{
|
||||
if (glProgramUniform1i)
|
||||
glProgramUniform1i(m_program, GetUniformLocation(name), value);
|
||||
glProgramUniform1i(m_program, location, value);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform1i(GetUniformLocation(name), value);
|
||||
glUniform1i(location, value);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendMatrix(const NzString& name, const NzMatrix4d& matrix)
|
||||
bool NzGLSLShader::SendMatrix(int location, const NzMatrix4d& matrix)
|
||||
{
|
||||
if (glProgramUniformMatrix4dv)
|
||||
glProgramUniformMatrix4dv(m_program, GetUniformLocation(name), 1, GL_FALSE, matrix);
|
||||
glProgramUniformMatrix4dv(m_program, location, 1, GL_FALSE, matrix);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniformMatrix4dv(GetUniformLocation(name), 1, GL_FALSE, matrix);
|
||||
glUniformMatrix4dv(location, 1, GL_FALSE, matrix);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendMatrix(const NzString& name, const NzMatrix4f& matrix)
|
||||
bool NzGLSLShader::SendMatrix(int location, const NzMatrix4f& matrix)
|
||||
{
|
||||
if (glProgramUniformMatrix4fv)
|
||||
glProgramUniformMatrix4fv(m_program, GetUniformLocation(name), 1, GL_FALSE, matrix);
|
||||
glProgramUniformMatrix4fv(m_program, location, 1, GL_FALSE, matrix);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniformMatrix4fv(GetUniformLocation(name), 1, GL_FALSE, matrix);
|
||||
glUniformMatrix4fv(location, 1, GL_FALSE, matrix);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendVector(const NzString& name, const NzVector2d& vector)
|
||||
bool NzGLSLShader::SendTexture(int location, const NzTexture* texture)
|
||||
{
|
||||
if (glProgramUniform2dv)
|
||||
glProgramUniform2dv(m_program, GetUniformLocation(name), 1, vector);
|
||||
else
|
||||
auto it = m_textures.find(location);
|
||||
if (it != m_textures.end())
|
||||
{
|
||||
Lock();
|
||||
glUniform2dv(GetUniformLocation(name), 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendVector(const NzString& name, const NzVector2f& vector)
|
||||
{
|
||||
if (glProgramUniform2fv)
|
||||
glProgramUniform2fv(m_program, GetUniformLocation(name), 1, vector);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform2fv(GetUniformLocation(name), 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendVector(const NzString& name, const NzVector3d& vector)
|
||||
{
|
||||
if (glProgramUniform3dv)
|
||||
glProgramUniform3dv(m_program, GetUniformLocation(name), 1, vector);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform3dv(GetUniformLocation(name), 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendVector(const NzString& name, const NzVector3f& vector)
|
||||
{
|
||||
if (glProgramUniform3fv)
|
||||
glProgramUniform3fv(m_program, GetUniformLocation(name), 1, vector);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform3fv(GetUniformLocation(name), 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendVector(const NzString& name, const NzVector4d& vector)
|
||||
{
|
||||
if (glProgramUniform4dv)
|
||||
glProgramUniform4dv(m_program, GetUniformLocation(name), 1, vector);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform4dv(GetUniformLocation(name), 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendVector(const NzString& name, const NzVector4f& vector)
|
||||
{
|
||||
if (glProgramUniform4fv)
|
||||
glProgramUniform4fv(m_program, GetUniformLocation(name), 1, vector);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform4fv(GetUniformLocation(name), 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendTexture(const NzString& name, NzTexture* texture)
|
||||
{
|
||||
static const unsigned int maxUnits = NazaraRenderer->GetMaxTextureUnits();
|
||||
|
||||
unsigned int unitUsed = m_textures.size();
|
||||
if (unitUsed >= maxUnits)
|
||||
{
|
||||
NazaraError("Unable to use texture \"" + name + "\" for shader: all available texture units are used");
|
||||
return false;
|
||||
}
|
||||
|
||||
// À partir d'ici nous savons qu'il y a au moins un identifiant de texture libre
|
||||
GLint location = GetUniformLocation(name);
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Parameter name \"" + name + "\" not found in shader");
|
||||
return false;
|
||||
}
|
||||
|
||||
nzUInt8 unit;
|
||||
if (unitUsed == 0)
|
||||
// Pas d'unité utilisée, la tâche est simple
|
||||
unit = 0;
|
||||
else
|
||||
{
|
||||
auto it = m_textures.rbegin(); // Itérateur vers la fin de la map
|
||||
unit = it->second.unit;
|
||||
if (unit == maxUnits-1)
|
||||
// Slot déjà utilisé
|
||||
TextureSlot& slot = it->second;
|
||||
if (slot.texture != texture)
|
||||
{
|
||||
// Il y a une place libre, mais pas à la fin
|
||||
for (; it != m_textures.rend(); ++it)
|
||||
slot.texture->RemoveResourceReference();
|
||||
|
||||
if (texture)
|
||||
{
|
||||
if (unit - it->second.unit > 1) // Si l'espace entre les indices est supérieur à 1, alors il y a une place libre
|
||||
slot.texture = texture;
|
||||
slot.texture->AddResourceReference();
|
||||
|
||||
slot.updated = false;
|
||||
}
|
||||
else
|
||||
m_textures.erase(it); // On supprime le slot
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
static const unsigned int maxUnits = NzRenderer::GetMaxTextureUnits();
|
||||
|
||||
unsigned int unitUsed = m_textures.size();
|
||||
if (unitUsed >= maxUnits)
|
||||
{
|
||||
NazaraError("Unable to use texture for shader: all available texture units are used");
|
||||
return false;
|
||||
}
|
||||
|
||||
// À partir d'ici nous savons qu'il y a au moins un identifiant de texture libre
|
||||
nzUInt8 unit;
|
||||
if (unitUsed == 0)
|
||||
// Pas d'unité utilisée, la tâche est simple
|
||||
unit = 0;
|
||||
else
|
||||
{
|
||||
auto it2 = m_textures.rbegin(); // Itérateur vers la fin de la map
|
||||
unit = it2->second.unit;
|
||||
if (unit == maxUnits-1)
|
||||
{
|
||||
// Il y a une place libre, mais pas à la fin
|
||||
for (; it2 != m_textures.rend(); ++it2)
|
||||
{
|
||||
unit--;
|
||||
break;
|
||||
if (unit - it2->second.unit > 1) // Si l'espace entre les indices est supérieur à 1, alors il y a une place libre
|
||||
{
|
||||
unit--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
// Il y a une place libre à la fin
|
||||
unit++;
|
||||
}
|
||||
|
||||
TextureSlot slot;
|
||||
slot.unit = unit;
|
||||
slot.texture = texture;
|
||||
texture->AddResourceReference();
|
||||
|
||||
m_textures[location] = slot;
|
||||
|
||||
if (glProgramUniform1i)
|
||||
glProgramUniform1i(m_program, location, unit);
|
||||
else
|
||||
// Il y a une place libre à la fin
|
||||
unit++;
|
||||
{
|
||||
Lock();
|
||||
glUniform1i(location, unit);
|
||||
Unlock();
|
||||
}
|
||||
}
|
||||
|
||||
m_textures[location] = TextureSlot{unit, texture};
|
||||
return true;
|
||||
}
|
||||
|
||||
if (glProgramUniform1i)
|
||||
glProgramUniform1i(m_program, location, unit);
|
||||
bool NzGLSLShader::SendVector(int location, const NzVector2d& vector)
|
||||
{
|
||||
if (glProgramUniform2dv)
|
||||
glProgramUniform2dv(m_program, location, 1, vector);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform1i(location, unit);
|
||||
glUniform2dv(location, 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendVector(int location, const NzVector2f& vector)
|
||||
{
|
||||
if (glProgramUniform2fv)
|
||||
glProgramUniform2fv(m_program, location, 1, vector);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform2fv(location, 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendVector(int location, const NzVector3d& vector)
|
||||
{
|
||||
if (glProgramUniform3dv)
|
||||
glProgramUniform3dv(m_program, location, 1, vector);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform3dv(location, 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendVector(int location, const NzVector3f& vector)
|
||||
{
|
||||
if (glProgramUniform3fv)
|
||||
glProgramUniform3fv(m_program, location, 1, vector);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform3fv(location, 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendVector(int location, const NzVector4d& vector)
|
||||
{
|
||||
if (glProgramUniform4dv)
|
||||
glProgramUniform4dv(m_program, location, 1, vector);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform4dv(location, 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendVector(int location, const NzVector4f& vector)
|
||||
{
|
||||
if (glProgramUniform4fv)
|
||||
glProgramUniform4fv(m_program, location, 1, vector);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform4fv(location, 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,35 +20,36 @@ class NzGLSLShader : public NzShaderImpl
|
||||
~NzGLSLShader();
|
||||
|
||||
bool Bind();
|
||||
bool BindTextures();
|
||||
|
||||
bool Compile();
|
||||
bool Create();
|
||||
|
||||
bool Create();
|
||||
void Destroy();
|
||||
|
||||
NzString GetLog() const;
|
||||
nzShaderLanguage GetLanguage() const;
|
||||
NzString GetSourceCode(nzShaderType type) const;
|
||||
GLint GetUniformLocation(const NzString& name) const;
|
||||
int GetUniformLocation(const NzString& name) const;
|
||||
|
||||
bool IsLoaded(nzShaderType type) const;
|
||||
|
||||
bool Load(nzShaderType type, const NzString& source);
|
||||
bool Lock();
|
||||
|
||||
bool SendBoolean(const NzString& name, bool value);
|
||||
bool SendDouble(const NzString& name, double value);
|
||||
bool SendFloat(const NzString& name, float value);
|
||||
bool SendInteger(const NzString& name, int value);
|
||||
bool SendMatrix(const NzString& name, const NzMatrix4d& matrix);
|
||||
bool SendMatrix(const NzString& name, const NzMatrix4f& matrix);
|
||||
bool SendVector(const NzString& name, const NzVector2d& vector);
|
||||
bool SendVector(const NzString& name, const NzVector2f& vector);
|
||||
bool SendVector(const NzString& name, const NzVector3d& vector);
|
||||
bool SendVector(const NzString& name, const NzVector3f& vector);
|
||||
bool SendVector(const NzString& name, const NzVector4d& vector);
|
||||
bool SendVector(const NzString& name, const NzVector4f& vector);
|
||||
bool SendTexture(const NzString& name, NzTexture* texture);
|
||||
bool SendBoolean(int location, bool value);
|
||||
bool SendDouble(int location, double value);
|
||||
bool SendFloat(int location, float value);
|
||||
bool SendInteger(int location, int value);
|
||||
bool SendMatrix(int location, const NzMatrix4d& matrix);
|
||||
bool SendMatrix(int location, const NzMatrix4f& matrix);
|
||||
bool SendTexture(int location, const NzTexture* texture);
|
||||
bool SendVector(int location, const NzVector2d& vector);
|
||||
bool SendVector(int location, const NzVector2f& vector);
|
||||
bool SendVector(int location, const NzVector3d& vector);
|
||||
bool SendVector(int location, const NzVector3f& vector);
|
||||
bool SendVector(int location, const NzVector4d& vector);
|
||||
bool SendVector(int location, const NzVector4f& vector);
|
||||
|
||||
void Unbind();
|
||||
void Unlock();
|
||||
@@ -56,8 +57,9 @@ class NzGLSLShader : public NzShaderImpl
|
||||
private:
|
||||
struct TextureSlot
|
||||
{
|
||||
bool updated = false;
|
||||
nzUInt8 unit;
|
||||
NzTexture* texture;
|
||||
const NzTexture* texture;
|
||||
};
|
||||
|
||||
mutable std::map<NzString, GLint> m_idCache;
|
||||
|
||||
@@ -52,14 +52,14 @@ namespace
|
||||
|
||||
if (access == nzBufferAccess_DiscardAndWrite)
|
||||
{
|
||||
GLint bufferSize;
|
||||
glGetBufferParameteriv(bufferTargetBinding[type], GL_BUFFER_SIZE, &bufferSize);
|
||||
GLint bufSize;
|
||||
glGetBufferParameteriv(bufferTargetBinding[type], GL_BUFFER_SIZE, &bufSize);
|
||||
|
||||
GLint bufferUsage;
|
||||
glGetBufferParameteriv(bufferTargetBinding[type], GL_BUFFER_USAGE, &bufferUsage);
|
||||
GLint bufUsage;
|
||||
glGetBufferParameteriv(bufferTargetBinding[type], GL_BUFFER_USAGE, &bufUsage);
|
||||
|
||||
// On discard le buffer
|
||||
glBufferData(bufferTargetBinding[type], bufferSize, nullptr, bufferUsage);
|
||||
glBufferData(bufferTargetBinding[type], bufSize, nullptr, bufUsage);
|
||||
}
|
||||
|
||||
void* ptr = glMapBuffer(bufferTarget[type], bufferLock[access]);
|
||||
|
||||
@@ -98,5 +98,5 @@ bool NzOcclusionQuery::IsResultAvailable() const
|
||||
|
||||
bool NzOcclusionQuery::IsSupported()
|
||||
{
|
||||
return NazaraRenderer->HasCapability(nzRendererCap_OcclusionQuery);
|
||||
return NzRenderer::HasCapability(nzRendererCap_OcclusionQuery);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Renderer/Context.hpp>
|
||||
@@ -54,7 +58,7 @@ namespace
|
||||
}
|
||||
|
||||
std::set<NzString> openGLextensionSet;
|
||||
bool openGLextensions[NzOpenGL::Count] = {false};
|
||||
bool openGLextensions[NzOpenGL::Max+1] = {false};
|
||||
unsigned int openGLversion = 0;
|
||||
|
||||
bool LoadExtensionsString(const NzString& extensionString)
|
||||
@@ -129,7 +133,7 @@ bool NzOpenGL::Initialize()
|
||||
/*
|
||||
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.s
|
||||
de créer le second avec les bons paramètres.
|
||||
|
||||
Non sérieusement si quelqu'un a une meilleure idée qu'il me le dise
|
||||
*/
|
||||
@@ -157,7 +161,7 @@ bool NzOpenGL::Initialize()
|
||||
// Récupération de la version d'OpenGL
|
||||
// Ce code se base sur le fait que la carte graphique renverra un contexte de compatibilité avec la plus haute version supportée
|
||||
// Ce qui semble vrai au moins chez ATI/AMD et NVidia, mais si quelqu'un à une meilleure idée ...
|
||||
glGetString = reinterpret_cast<PFNGLGETSTRINGPROC>(LoadEntry("glGetString"));
|
||||
glGetString = reinterpret_cast<PFNGLGETSTRINGPROC>(LoadEntry("glGetString", false));
|
||||
if (!glGetString)
|
||||
{
|
||||
NazaraError("Unable to load OpenGL: failed to load glGetString");
|
||||
@@ -191,10 +195,17 @@ bool NzOpenGL::Initialize()
|
||||
}
|
||||
|
||||
openGLversion = major*100 + minor*10;
|
||||
if (openGLversion < 200)
|
||||
{
|
||||
NazaraError("OpenGL version is too low, please upgrade your drivers or your graphics card");
|
||||
Uninitialize();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
parameters.debugMode = true; // Certaines extensions n'apparaissent qu'avec un contexte de debug (e.g. ARB_debug_output)
|
||||
parameters.majorVersion = NzContextParameters::defaultMajorVersion = openGLversion/100;
|
||||
parameters.minorVersion = NzContextParameters::defaultMinorVersion = (openGLversion%100)/10;
|
||||
parameters.majorVersion = NzContextParameters::defaultMajorVersion = major;
|
||||
parameters.minorVersion = NzContextParameters::defaultMinorVersion = minor;
|
||||
|
||||
// Destruction implicite du premier contexte
|
||||
if (!loadContext.Create(parameters))
|
||||
@@ -331,7 +342,7 @@ bool NzOpenGL::Initialize()
|
||||
loaded = false;
|
||||
|
||||
if (!loaded)
|
||||
NazaraWarning("Failed to load windows' extension string");
|
||||
NazaraWarning("Failed to load wgl extension string");
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -403,7 +414,7 @@ bool NzOpenGL::Initialize()
|
||||
openGLextensions[NzOpenGL::PixelBufferObject] = (openGLversion >= 210 || IsSupported("GL_ARB_pixel_buffer_object"));
|
||||
|
||||
// SeparateShaderObjects
|
||||
if (openGLversion >= 400 || IsSupported("GL_ARB_gpu_shader_fp64"))
|
||||
if (openGLversion >= 400 || IsSupported("GL_ARB_separate_shader_objects"))
|
||||
{
|
||||
glProgramUniform1f = reinterpret_cast<PFNGLPROGRAMUNIFORM1FPROC>(LoadEntry("glProgramUniform1f"));
|
||||
glProgramUniform1i = reinterpret_cast<PFNGLPROGRAMUNIFORM1IPROC>(LoadEntry("glProgramUniform1i"));
|
||||
@@ -412,6 +423,7 @@ bool NzOpenGL::Initialize()
|
||||
glProgramUniform4fv = reinterpret_cast<PFNGLPROGRAMUNIFORM4FVPROC>(LoadEntry("glProgramUniform4fv"));
|
||||
glProgramUniformMatrix4fv = reinterpret_cast<PFNGLPROGRAMUNIFORMMATRIX4FVPROC>(LoadEntry("glProgramUniformMatrix4fv"));
|
||||
|
||||
// Si ARB_gpu_shader_fp64 est supporté, alors cette extension donne également accès aux fonctions utilisant des double
|
||||
if (openGLextensions[NzOpenGL::FP64])
|
||||
{
|
||||
glProgramUniform1d = reinterpret_cast<PFNGLPROGRAMUNIFORM1DPROC>(LoadEntry("glProgramUniform1d"));
|
||||
@@ -434,8 +446,7 @@ bool NzOpenGL::Initialize()
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
if (openGLversion >= 120)
|
||||
NazaraWarning("Failed to load core texture 3D (" + NzString(e.what()) + ")");
|
||||
NazaraWarning("Failed to load core texture 3D (" + NzString(e.what()) + ")");
|
||||
|
||||
if (IsSupported("GL_EXT_texture3D"))
|
||||
{
|
||||
@@ -449,13 +460,16 @@ bool NzOpenGL::Initialize()
|
||||
|
||||
openGLextensions[NzOpenGL::Texture3D] = true;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
catch (const std::exception& e2)
|
||||
{
|
||||
NazaraWarning("Failed to load EXT_texture3D: " + NzString(e.what()));
|
||||
NazaraWarning("Failed to load EXT_texture3D: " + NzString(e2.what()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TextureArray
|
||||
openGLextensions[NzOpenGL::TextureArray] = (openGLversion >= 300 || IsSupported("GL_EXT_texture_array"));
|
||||
|
||||
// TextureCompression_s3tc
|
||||
openGLextensions[NzOpenGL::TextureCompression_s3tc] = IsSupported("GL_EXT_texture_compression_s3tc");
|
||||
|
||||
|
||||
@@ -10,15 +10,15 @@ NzRenderTarget::~NzRenderTarget() = default;
|
||||
|
||||
bool NzRenderTarget::IsActive() const
|
||||
{
|
||||
return NazaraRenderer->GetTarget() == this;
|
||||
return NzRenderer::GetTarget() == this;
|
||||
}
|
||||
|
||||
bool NzRenderTarget::SetActive(bool active)
|
||||
{
|
||||
if (active)
|
||||
return NazaraRenderer->SetTarget(this);
|
||||
else if (NazaraRenderer->GetTarget() == this)
|
||||
return NazaraRenderer->SetTarget(nullptr);
|
||||
return NzRenderer::SetTarget(this);
|
||||
else if (NzRenderer::GetTarget() == this)
|
||||
return NzRenderer::SetTarget(nullptr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -5,18 +5,13 @@
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Renderer/RenderWindow.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Thread.hpp>
|
||||
#include <Nazara/Renderer/Context.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
NzRenderWindow::NzRenderWindow() :
|
||||
m_context(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
NzRenderWindow::NzRenderWindow(NzVideoMode mode, const NzString& title, nzUInt32 style, const NzContextParameters& parameters) :
|
||||
m_context(nullptr)
|
||||
NzRenderWindow::NzRenderWindow(NzVideoMode mode, const NzString& title, nzUInt32 style, const NzContextParameters& parameters)
|
||||
{
|
||||
Create(mode, title, style, parameters);
|
||||
|
||||
@@ -29,8 +24,7 @@ m_context(nullptr)
|
||||
#endif
|
||||
}
|
||||
|
||||
NzRenderWindow::NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters) :
|
||||
m_context(nullptr)
|
||||
NzRenderWindow::NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters)
|
||||
{
|
||||
Create(handle, parameters);
|
||||
|
||||
@@ -45,6 +39,8 @@ m_context(nullptr)
|
||||
|
||||
NzRenderWindow::~NzRenderWindow()
|
||||
{
|
||||
// Nécessaire si NzWindow::Destroy est appelé par son destructeur
|
||||
OnWindowDestroying();
|
||||
}
|
||||
|
||||
bool NzRenderWindow::CopyToImage(NzImage* image)
|
||||
@@ -136,6 +132,15 @@ bool NzRenderWindow::Create(NzWindowHandle handle, const NzContextParameters& pa
|
||||
|
||||
void NzRenderWindow::Display()
|
||||
{
|
||||
if (m_framerateLimit > 0)
|
||||
{
|
||||
int remainingTime = 1000/m_framerateLimit - m_clock.GetMilliseconds();
|
||||
if (remainingTime > 0)
|
||||
NzThread::Sleep(remainingTime);
|
||||
|
||||
m_clock.Restart();
|
||||
}
|
||||
|
||||
if (m_context && m_parameters.doubleBuffered)
|
||||
m_context->SwapBuffers();
|
||||
}
|
||||
@@ -218,6 +223,11 @@ bool NzRenderWindow::IsValid() const
|
||||
return m_impl != nullptr && m_context != nullptr;
|
||||
}
|
||||
|
||||
void NzRenderWindow::SetFramerateLimit(unsigned int limit)
|
||||
{
|
||||
m_framerateLimit = limit;
|
||||
}
|
||||
|
||||
bool NzRenderWindow::Activate()
|
||||
{
|
||||
if (m_context->SetActive(true))
|
||||
@@ -232,12 +242,16 @@ bool NzRenderWindow::Activate()
|
||||
}
|
||||
}
|
||||
|
||||
void NzRenderWindow::OnClose()
|
||||
void NzRenderWindow::OnWindowDestroying()
|
||||
{
|
||||
delete m_context;
|
||||
if (m_context)
|
||||
{
|
||||
delete m_context;
|
||||
m_context = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool NzRenderWindow::OnCreate()
|
||||
bool NzRenderWindow::OnWindowCreated()
|
||||
{
|
||||
m_parameters.doubleBuffered = true;
|
||||
m_parameters.window = GetHandle();
|
||||
@@ -258,5 +272,7 @@ bool NzRenderWindow::OnCreate()
|
||||
NazaraWarning("Failed to activate window");
|
||||
#endif
|
||||
|
||||
m_clock.Restart();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/Context.hpp>
|
||||
#include <Nazara/Renderer/HardwareBuffer.hpp>
|
||||
@@ -18,6 +19,7 @@
|
||||
#include <Nazara/Utility/VertexBuffer.hpp>
|
||||
#include <Nazara/Utility/VertexDeclaration.hpp>
|
||||
#include <stdexcept>
|
||||
#include <tuple>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace
|
||||
@@ -61,7 +63,6 @@ namespace
|
||||
GL_FILL // nzFaceFilling_Fill
|
||||
};
|
||||
|
||||
|
||||
const GLenum openglPrimitive[] =
|
||||
{
|
||||
GL_LINES, // nzPrimitiveType_LineList,
|
||||
@@ -131,28 +132,47 @@ namespace
|
||||
GL_ZERO // nzStencilOperation_Zero
|
||||
};
|
||||
|
||||
///FIXME: Solution temporaire pour plus de facilité
|
||||
enum nzMatrixCombination
|
||||
{
|
||||
nzMatrixCombination_ViewProj = nzMatrixType_Max+1,
|
||||
nzMatrixCombination_WorldView,
|
||||
nzMatrixCombination_WorldViewProj,
|
||||
|
||||
nzMatrixCombination_Max = nzMatrixCombination_WorldViewProj
|
||||
};
|
||||
|
||||
NzBufferImpl* HardwareBufferFunction(NzBuffer* parent, nzBufferType type)
|
||||
{
|
||||
return new NzHardwareBuffer(parent, type);
|
||||
}
|
||||
}
|
||||
|
||||
NzRenderer::NzRenderer()
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (s_instance)
|
||||
throw std::runtime_error("Renderer already instanced");
|
||||
#endif
|
||||
typedef std::tuple<const NzContext*, const NzIndexBuffer*, const NzVertexBuffer*, const NzVertexDeclaration*> VAO_Key;
|
||||
|
||||
s_instance = this;
|
||||
}
|
||||
constexpr unsigned int totalMatrixCount = nzMatrixCombination_Max+1;
|
||||
|
||||
NzRenderer::~NzRenderer()
|
||||
{
|
||||
if (s_initialized)
|
||||
Uninitialize();
|
||||
|
||||
s_instance = nullptr;
|
||||
std::map<VAO_Key, unsigned int> s_vaos;
|
||||
NzMatrix4f s_matrix[totalMatrixCount];
|
||||
int s_matrixLocation[totalMatrixCount];
|
||||
bool s_matrixUpdated[totalMatrixCount];
|
||||
nzRendererComparison s_stencilCompare;
|
||||
nzStencilOperation s_stencilFail;
|
||||
nzStencilOperation s_stencilPass;
|
||||
nzStencilOperation s_stencilZFail;
|
||||
nzUInt32 s_stencilMask;
|
||||
const NzIndexBuffer* s_indexBuffer;
|
||||
NzRenderTarget* s_target;
|
||||
NzShader* s_shader;
|
||||
const NzVertexBuffer* s_vertexBuffer;
|
||||
const NzVertexDeclaration* s_vertexDeclaration;
|
||||
bool s_vaoUpdated;
|
||||
bool s_capabilities[nzRendererCap_Max+1];
|
||||
bool s_stencilFuncUpdated;
|
||||
bool s_stencilOpUpdated;
|
||||
unsigned int s_maxAnisotropyLevel;
|
||||
unsigned int s_maxRenderTarget;
|
||||
unsigned int s_maxTextureUnit;
|
||||
unsigned int s_stencilReference;
|
||||
}
|
||||
|
||||
void NzRenderer::Clear(unsigned long flags)
|
||||
@@ -190,8 +210,10 @@ void NzRenderer::DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int f
|
||||
NazaraError("No active context");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!m_indexBuffer)
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!s_indexBuffer)
|
||||
{
|
||||
NazaraError("No index buffer");
|
||||
return;
|
||||
@@ -204,11 +226,11 @@ void NzRenderer::DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int f
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_indexBuffer->IsSequential())
|
||||
glDrawArrays(openglPrimitive[primitive], m_indexBuffer->GetStartIndex(), m_indexBuffer->GetIndexCount());
|
||||
if (s_indexBuffer->IsSequential())
|
||||
glDrawArrays(openglPrimitive[primitive], s_indexBuffer->GetStartIndex(), s_indexBuffer->GetIndexCount());
|
||||
else
|
||||
{
|
||||
nzUInt8 indexSize = m_indexBuffer->GetIndexSize();
|
||||
nzUInt8 indexSize = s_indexBuffer->GetIndexSize();
|
||||
|
||||
GLenum type;
|
||||
switch (indexSize)
|
||||
@@ -230,7 +252,7 @@ void NzRenderer::DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int f
|
||||
return;
|
||||
}
|
||||
|
||||
glDrawElements(openglPrimitive[primitive], indexCount, type, reinterpret_cast<const nzUInt8*>(m_indexBuffer->GetPointer()) + firstIndex*indexSize);
|
||||
glDrawElements(openglPrimitive[primitive], indexCount, type, reinterpret_cast<const nzUInt8*>(s_indexBuffer->GetPointer()) + firstIndex*indexSize);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,33 +304,70 @@ void NzRenderer::Enable(nzRendererParameter parameter, bool enable)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int NzRenderer::GetMaxAnisotropyLevel() const
|
||||
/*
|
||||
NzMatrix4f NzRenderer::GetMatrix(nzMatrixCombination combination)
|
||||
{
|
||||
return m_maxAnisotropyLevel;
|
||||
switch (combination)
|
||||
{
|
||||
case nzMatrixCombination_ViewProj:
|
||||
if (!s_matrixUpdated[nzMatrixCombination_ViewProj])
|
||||
{
|
||||
s_matrix[nzMatrixCombination_ViewProj] = s_matrix[nzMatrixType_View] * s_matrix[nzMatrixType_Projection];
|
||||
s_matrixUpdated[nzMatrixCombination_ViewProj] = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case nzMatrixCombination_WorldView:
|
||||
if (!s_matrixUpdated[nzMatrixCombination_WorldView])
|
||||
{
|
||||
s_matrix[nzMatrixCombination_WorldView] = NzMatrix4f::ConcatenateAffine(s_matrix[nzMatrixType_World], s_matrix[nzMatrixType_View]);
|
||||
s_matrixUpdated[nzMatrixCombination_WorldView] = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case nzMatrixCombination_WorldViewProj:
|
||||
if (!s_matrixUpdated[nzMatrixCombination_WorldViewProj])
|
||||
{
|
||||
s_matrix[nzMatrixCombination_WorldViewProj] = s_matrix[nzMatrixCombination_WorldView] * s_matrix[nzMatrixType_Projection];
|
||||
s_matrixUpdated[nzMatrixCombination_WorldViewProj] = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return m_matrix[combination];
|
||||
}
|
||||
*/
|
||||
NzMatrix4f NzRenderer::GetMatrix(nzMatrixType type)
|
||||
{
|
||||
return s_matrix[type];
|
||||
}
|
||||
|
||||
unsigned int NzRenderer::GetMaxRenderTargets() const
|
||||
unsigned int NzRenderer::GetMaxAnisotropyLevel()
|
||||
{
|
||||
return m_maxRenderTarget;
|
||||
return s_maxAnisotropyLevel;
|
||||
}
|
||||
|
||||
unsigned int NzRenderer::GetMaxTextureUnits() const
|
||||
unsigned int NzRenderer::GetMaxRenderTargets()
|
||||
{
|
||||
return m_maxTextureUnit;
|
||||
return s_maxRenderTarget;
|
||||
}
|
||||
|
||||
NzShader* NzRenderer::GetShader() const
|
||||
unsigned int NzRenderer::GetMaxTextureUnits()
|
||||
{
|
||||
return m_shader;
|
||||
return s_maxTextureUnit;
|
||||
}
|
||||
|
||||
NzRenderTarget* NzRenderer::GetTarget() const
|
||||
NzShader* NzRenderer::GetShader()
|
||||
{
|
||||
return m_target;
|
||||
return s_shader;
|
||||
}
|
||||
|
||||
NzRectui NzRenderer::GetViewport() const
|
||||
NzRenderTarget* NzRenderer::GetTarget()
|
||||
{
|
||||
return s_target;
|
||||
}
|
||||
|
||||
NzRectui NzRenderer::GetViewport()
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (NzContext::GetCurrent() == nullptr)
|
||||
@@ -324,103 +383,110 @@ NzRectui NzRenderer::GetViewport() const
|
||||
return NzRectui(params[0], params[1], params[2], params[3]);
|
||||
}
|
||||
|
||||
bool NzRenderer::HasCapability(nzRendererCap capability) const
|
||||
bool NzRenderer::HasCapability(nzRendererCap capability)
|
||||
{
|
||||
return m_capabilities[capability];
|
||||
return s_capabilities[capability];
|
||||
}
|
||||
|
||||
bool NzRenderer::Initialize()
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (s_initialized)
|
||||
if (s_moduleReferenceCouter++ != 0)
|
||||
return true; // Déjà initialisé
|
||||
|
||||
// Initialisation des dépendances
|
||||
if (!NzUtility::Initialize())
|
||||
{
|
||||
NazaraError("Renderer already initialized");
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Initialisation du module Utility
|
||||
if (!NzUtility::IsInitialized())
|
||||
{
|
||||
m_utilityModule = new NzUtility;
|
||||
m_utilityModule->Initialize();
|
||||
}
|
||||
else
|
||||
m_utilityModule = nullptr;
|
||||
|
||||
if (NzOpenGL::Initialize())
|
||||
{
|
||||
NzContext::EnsureContext();
|
||||
|
||||
m_indexBuffer = nullptr;
|
||||
m_shader = nullptr;
|
||||
m_stencilCompare = nzRendererComparison_Always;
|
||||
m_stencilFail = nzStencilOperation_Keep;
|
||||
m_stencilFuncUpdated = true;
|
||||
m_stencilMask = 0xFFFFFFFF;
|
||||
m_stencilOpUpdated = true;
|
||||
m_stencilPass = nzStencilOperation_Keep;
|
||||
m_stencilReference = 0;
|
||||
m_stencilZFail = nzStencilOperation_Keep;
|
||||
m_target = nullptr;
|
||||
m_vaoUpdated = false;
|
||||
m_vertexBuffer = nullptr;
|
||||
m_vertexDeclaration = nullptr;
|
||||
|
||||
// Récupération des capacités
|
||||
m_capabilities[nzRendererCap_AnisotropicFilter] = NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter);
|
||||
m_capabilities[nzRendererCap_FP64] = NzOpenGL::IsSupported(NzOpenGL::FP64);
|
||||
m_capabilities[nzRendererCap_HardwareBuffer] = true; // Natif depuis OpenGL 1.5
|
||||
m_capabilities[nzRendererCap_MultipleRenderTargets] = true; // Natif depuis OpenGL 2.0
|
||||
m_capabilities[nzRendererCap_OcclusionQuery] = true; // Natif depuis OpenGL 1.5
|
||||
m_capabilities[nzRendererCap_PixelBufferObject] = NzOpenGL::IsSupported(NzOpenGL::PixelBufferObject);
|
||||
m_capabilities[nzRendererCap_Texture3D] = NzOpenGL::IsSupported(NzOpenGL::Texture3D);
|
||||
m_capabilities[nzRendererCap_TextureCubemap] = true; // Natif depuis OpenGL 1.3
|
||||
m_capabilities[nzRendererCap_TextureMulti] = true; // Natif depuis OpenGL 1.3
|
||||
m_capabilities[nzRendererCap_TextureNPOT] = true; // Natif depuis OpenGL 2.0
|
||||
|
||||
if (m_capabilities[nzRendererCap_AnisotropicFilter])
|
||||
{
|
||||
GLint maxAnisotropy;
|
||||
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
|
||||
|
||||
m_maxAnisotropyLevel = static_cast<unsigned int>(maxAnisotropy);
|
||||
}
|
||||
else
|
||||
m_maxAnisotropyLevel = 1;
|
||||
|
||||
if (m_capabilities[nzRendererCap_MultipleRenderTargets])
|
||||
{
|
||||
GLint maxDrawBuffers;
|
||||
glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
|
||||
|
||||
m_maxRenderTarget = static_cast<unsigned int>(maxDrawBuffers);
|
||||
}
|
||||
else
|
||||
m_maxRenderTarget = 1;
|
||||
|
||||
if (m_capabilities[nzRendererCap_TextureMulti])
|
||||
{
|
||||
GLint maxTextureUnits;
|
||||
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
|
||||
|
||||
GLint maxVertexAttribs;
|
||||
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs);
|
||||
|
||||
// Impossible de binder plus de texcoords que d'attributes (en sachant qu'un certain nombre est déjà pris par les autres attributs)
|
||||
m_maxTextureUnit = static_cast<unsigned int>(std::min(maxTextureUnits, maxVertexAttribs-attribIndex[nzElementUsage_TexCoord]));
|
||||
}
|
||||
else
|
||||
m_maxTextureUnit = 1;
|
||||
|
||||
NzBuffer::SetBufferFunction(nzBufferStorage_Hardware, HardwareBufferFunction);
|
||||
|
||||
s_initialized = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
NazaraError("Failed to initialize utility module");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Initialisation du module
|
||||
if (!NzOpenGL::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize OpenGL");
|
||||
return false;
|
||||
}
|
||||
|
||||
NzContext::EnsureContext();
|
||||
|
||||
for (unsigned int i = 0; i < totalMatrixCount; ++i)
|
||||
{
|
||||
s_matrix[i].MakeIdentity();
|
||||
s_matrixLocation[i] = -1;
|
||||
s_matrixUpdated[i] = false;
|
||||
}
|
||||
|
||||
s_indexBuffer = nullptr;
|
||||
s_shader = nullptr;
|
||||
s_stencilCompare = nzRendererComparison_Always;
|
||||
s_stencilFail = nzStencilOperation_Keep;
|
||||
s_stencilFuncUpdated = true;
|
||||
s_stencilMask = 0xFFFFFFFF;
|
||||
s_stencilOpUpdated = true;
|
||||
s_stencilPass = nzStencilOperation_Keep;
|
||||
s_stencilReference = 0;
|
||||
s_stencilZFail = nzStencilOperation_Keep;
|
||||
s_target = nullptr;
|
||||
s_vaoUpdated = false;
|
||||
s_vertexBuffer = nullptr;
|
||||
s_vertexDeclaration = nullptr;
|
||||
|
||||
// Récupération des capacités
|
||||
s_capabilities[nzRendererCap_AnisotropicFilter] = NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter);
|
||||
s_capabilities[nzRendererCap_FP64] = NzOpenGL::IsSupported(NzOpenGL::FP64);
|
||||
s_capabilities[nzRendererCap_HardwareBuffer] = true; // Natif depuis OpenGL 1.5
|
||||
s_capabilities[nzRendererCap_MultipleRenderTargets] = true; // Natif depuis OpenGL 2.0
|
||||
s_capabilities[nzRendererCap_OcclusionQuery] = true; // Natif depuis OpenGL 1.5
|
||||
s_capabilities[nzRendererCap_PixelBufferObject] = NzOpenGL::IsSupported(NzOpenGL::PixelBufferObject);
|
||||
s_capabilities[nzRendererCap_Texture3D] = NzOpenGL::IsSupported(NzOpenGL::Texture3D);
|
||||
s_capabilities[nzRendererCap_TextureCubemap] = true; // Natif depuis OpenGL 1.3
|
||||
s_capabilities[nzRendererCap_TextureMulti] = true; // Natif depuis OpenGL 1.3
|
||||
s_capabilities[nzRendererCap_TextureNPOT] = true; // Natif depuis OpenGL 2.0
|
||||
|
||||
if (s_capabilities[nzRendererCap_AnisotropicFilter])
|
||||
{
|
||||
GLint maxAnisotropy;
|
||||
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
|
||||
|
||||
s_maxAnisotropyLevel = static_cast<unsigned int>(maxAnisotropy);
|
||||
}
|
||||
else
|
||||
s_maxAnisotropyLevel = 1;
|
||||
|
||||
if (s_capabilities[nzRendererCap_MultipleRenderTargets])
|
||||
{
|
||||
GLint maxDrawBuffers;
|
||||
glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
|
||||
|
||||
s_maxRenderTarget = static_cast<unsigned int>(maxDrawBuffers);
|
||||
}
|
||||
else
|
||||
s_maxRenderTarget = 1;
|
||||
|
||||
if (s_capabilities[nzRendererCap_TextureMulti])
|
||||
{
|
||||
GLint maxTextureUnits;
|
||||
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
|
||||
|
||||
GLint maxVertexAttribs;
|
||||
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs);
|
||||
|
||||
// Impossible de binder plus de texcoords que d'attributes (en sachant qu'un certain nombre est déjà pris par les autres attributs)
|
||||
s_maxTextureUnit = static_cast<unsigned int>(std::min(maxTextureUnits, maxVertexAttribs-attribIndex[nzElementUsage_TexCoord]));
|
||||
}
|
||||
else
|
||||
s_maxTextureUnit = 1;
|
||||
|
||||
NzBuffer::SetBufferFunction(nzBufferStorage_Hardware, HardwareBufferFunction);
|
||||
|
||||
NazaraNotice("Initialized: Renderer module");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzRenderer::IsInitialized()
|
||||
{
|
||||
return s_moduleReferenceCouter != 0;
|
||||
}
|
||||
|
||||
void NzRenderer::SetBlendFunc(nzBlendFunc src, nzBlendFunc dest)
|
||||
@@ -524,22 +590,43 @@ bool NzRenderer::SetIndexBuffer(const NzIndexBuffer* indexBuffer)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (indexBuffer != m_indexBuffer)
|
||||
if (s_indexBuffer != indexBuffer)
|
||||
{
|
||||
m_indexBuffer = indexBuffer;
|
||||
m_vaoUpdated = false;
|
||||
s_indexBuffer = indexBuffer;
|
||||
s_vaoUpdated = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzRenderer::SetMatrix(nzMatrixType type, const NzMatrix4f& matrix)
|
||||
{
|
||||
s_matrix[type] = matrix;
|
||||
|
||||
// Cas particulier, la matrice projection doit être inversée sur l'axe Y à cause des conventions d'OpenGL
|
||||
if (type == nzMatrixType_Projection)
|
||||
s_matrix[type] *= NzMatrix4f::Scale(NzVector3f(1.f, -1.f, 1.f));
|
||||
|
||||
// Invalidation des combinaisons
|
||||
switch (type)
|
||||
{
|
||||
case nzMatrixType_View:
|
||||
case nzMatrixType_World:
|
||||
s_matrixUpdated[nzMatrixCombination_WorldView] = false;
|
||||
case nzMatrixType_Projection:
|
||||
s_matrixUpdated[nzMatrixCombination_WorldViewProj] = false;
|
||||
s_matrixUpdated[nzMatrixCombination_ViewProj] = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool NzRenderer::SetShader(NzShader* shader)
|
||||
{
|
||||
if (shader == m_shader)
|
||||
if (s_shader == shader)
|
||||
return true;
|
||||
|
||||
if (m_shader)
|
||||
m_shader->m_impl->Unbind();
|
||||
if (s_shader)
|
||||
s_shader->m_impl->Unbind();
|
||||
|
||||
if (shader)
|
||||
{
|
||||
@@ -547,7 +634,7 @@ bool NzRenderer::SetShader(NzShader* shader)
|
||||
if (!shader->IsCompiled())
|
||||
{
|
||||
NazaraError("Shader is not compiled");
|
||||
m_shader = nullptr;
|
||||
shader = nullptr;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -556,78 +643,87 @@ bool NzRenderer::SetShader(NzShader* shader)
|
||||
if (!shader->m_impl->Bind())
|
||||
{
|
||||
NazaraError("Failed to bind shader");
|
||||
m_shader = nullptr;
|
||||
shader = nullptr;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Récupération des indices des variables uniformes (-1 si la variable n'existe pas)
|
||||
s_matrixLocation[nzMatrixType_Projection] = shader->GetUniformLocation("ProjMatrix");
|
||||
s_matrixLocation[nzMatrixType_View] = shader->GetUniformLocation("ViewMatrix");
|
||||
s_matrixLocation[nzMatrixType_World] = shader->GetUniformLocation("WorldMatrix");
|
||||
|
||||
s_matrixLocation[nzMatrixCombination_ViewProj] = shader->GetUniformLocation("ViewProjMatrix");
|
||||
s_matrixLocation[nzMatrixCombination_WorldView] = shader->GetUniformLocation("WorldViewMatrix");
|
||||
s_matrixLocation[nzMatrixCombination_WorldViewProj] = shader->GetUniformLocation("WorldViewProjMatrix");
|
||||
}
|
||||
|
||||
m_shader = shader;
|
||||
s_shader = shader;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzRenderer::SetStencilCompareFunction(nzRendererComparison compareFunc)
|
||||
{
|
||||
if (compareFunc != m_stencilCompare)
|
||||
if (compareFunc != s_stencilCompare)
|
||||
{
|
||||
m_stencilCompare = compareFunc;
|
||||
m_stencilFuncUpdated = false;
|
||||
s_stencilCompare = compareFunc;
|
||||
s_stencilFuncUpdated = false;
|
||||
}
|
||||
}
|
||||
|
||||
void NzRenderer::SetStencilFailOperation(nzStencilOperation failOperation)
|
||||
{
|
||||
if (failOperation != m_stencilFail)
|
||||
if (failOperation != s_stencilFail)
|
||||
{
|
||||
m_stencilFail = failOperation;
|
||||
m_stencilOpUpdated = false;
|
||||
s_stencilFail = failOperation;
|
||||
s_stencilOpUpdated = false;
|
||||
}
|
||||
}
|
||||
|
||||
void NzRenderer::SetStencilMask(nzUInt32 mask)
|
||||
{
|
||||
if (mask != m_stencilMask)
|
||||
if (mask != s_stencilMask)
|
||||
{
|
||||
m_stencilMask = mask;
|
||||
m_stencilFuncUpdated = false;
|
||||
s_stencilMask = mask;
|
||||
s_stencilFuncUpdated = false;
|
||||
}
|
||||
}
|
||||
|
||||
void NzRenderer::SetStencilPassOperation(nzStencilOperation passOperation)
|
||||
{
|
||||
if (passOperation != m_stencilPass)
|
||||
if (passOperation != s_stencilPass)
|
||||
{
|
||||
m_stencilPass = passOperation;
|
||||
m_stencilOpUpdated = false;
|
||||
s_stencilPass = passOperation;
|
||||
s_stencilOpUpdated = false;
|
||||
}
|
||||
}
|
||||
|
||||
void NzRenderer::SetStencilReferenceValue(unsigned int refValue)
|
||||
{
|
||||
if (refValue != m_stencilReference)
|
||||
if (refValue != s_stencilReference)
|
||||
{
|
||||
m_stencilReference = refValue;
|
||||
m_stencilFuncUpdated = false;
|
||||
s_stencilReference = refValue;
|
||||
s_stencilFuncUpdated = false;
|
||||
}
|
||||
}
|
||||
|
||||
void NzRenderer::SetStencilZFailOperation(nzStencilOperation zfailOperation)
|
||||
{
|
||||
if (zfailOperation != m_stencilZFail)
|
||||
if (zfailOperation != s_stencilZFail)
|
||||
{
|
||||
m_stencilZFail = zfailOperation;
|
||||
m_stencilOpUpdated = false;
|
||||
s_stencilZFail = zfailOperation;
|
||||
s_stencilOpUpdated = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool NzRenderer::SetTarget(NzRenderTarget* target)
|
||||
{
|
||||
if (target == m_target)
|
||||
if (s_target == target)
|
||||
return true;
|
||||
|
||||
if (m_target && !m_target->HasContext())
|
||||
m_target->Desactivate();
|
||||
if (s_target && !target->HasContext())
|
||||
s_target->Desactivate();
|
||||
|
||||
if (target)
|
||||
{
|
||||
@@ -640,17 +736,17 @@ bool NzRenderer::SetTarget(NzRenderTarget* target)
|
||||
#endif
|
||||
|
||||
if (target->Activate())
|
||||
m_target = target;
|
||||
s_target = target;
|
||||
else
|
||||
{
|
||||
NazaraError("Failed to activate target");
|
||||
m_target = nullptr;
|
||||
s_target = nullptr;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
m_target = nullptr;
|
||||
s_target = nullptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -665,10 +761,10 @@ bool NzRenderer::SetVertexBuffer(const NzVertexBuffer* vertexBuffer)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (m_vertexBuffer != vertexBuffer)
|
||||
if (s_vertexBuffer != vertexBuffer)
|
||||
{
|
||||
m_vertexBuffer = vertexBuffer;
|
||||
m_vaoUpdated = false;
|
||||
s_vertexBuffer = vertexBuffer;
|
||||
s_vaoUpdated = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -676,10 +772,10 @@ bool NzRenderer::SetVertexBuffer(const NzVertexBuffer* vertexBuffer)
|
||||
|
||||
bool NzRenderer::SetVertexDeclaration(const NzVertexDeclaration* vertexDeclaration)
|
||||
{
|
||||
if (m_vertexDeclaration != vertexDeclaration)
|
||||
if (s_vertexDeclaration != vertexDeclaration)
|
||||
{
|
||||
m_vertexDeclaration = vertexDeclaration;
|
||||
m_vaoUpdated = false;
|
||||
s_vertexDeclaration = vertexDeclaration;
|
||||
s_vaoUpdated = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -695,16 +791,16 @@ void NzRenderer::SetViewport(const NzRectui& viewport)
|
||||
}
|
||||
#endif
|
||||
|
||||
unsigned int height = m_target->GetHeight();
|
||||
unsigned int height = s_target->GetHeight();
|
||||
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_target)
|
||||
if (!s_target)
|
||||
{
|
||||
NazaraError("Renderer has no target");
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int width = m_target->GetWidth();
|
||||
unsigned int width = s_target->GetWidth();
|
||||
if (viewport.x+viewport.width > width || viewport.y+viewport.height > height)
|
||||
{
|
||||
NazaraError("Rectangle dimensions are out of bounds");
|
||||
@@ -718,20 +814,14 @@ void NzRenderer::SetViewport(const NzRectui& viewport)
|
||||
|
||||
void NzRenderer::Uninitialize()
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!s_initialized)
|
||||
{
|
||||
NazaraError("Renderer not initialized");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (--s_moduleReferenceCouter != 0)
|
||||
return; // Encore utilisé
|
||||
|
||||
// Libération du module
|
||||
NzContext::EnsureContext();
|
||||
|
||||
s_initialized = false;
|
||||
|
||||
// Libération des VAOs
|
||||
for (auto it = m_vaos.begin(); it != m_vaos.end(); ++it)
|
||||
for (auto it = s_vaos.begin(); it != s_vaos.end(); ++it)
|
||||
{
|
||||
GLuint vao = static_cast<GLuint>(it->second);
|
||||
glDeleteVertexArrays(1, &vao);
|
||||
@@ -739,26 +829,10 @@ void NzRenderer::Uninitialize()
|
||||
|
||||
NzOpenGL::Uninitialize();
|
||||
|
||||
if (m_utilityModule)
|
||||
{
|
||||
delete m_utilityModule;
|
||||
m_utilityModule = nullptr;
|
||||
}
|
||||
}
|
||||
NazaraNotice("Uninitialized: Renderer module");
|
||||
|
||||
NzRenderer* NzRenderer::Instance()
|
||||
{
|
||||
#if defined(NAZARA_DEBUG)
|
||||
if (!s_instance)
|
||||
NazaraError("Renderer not instanced");
|
||||
#endif
|
||||
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
bool NzRenderer::IsInitialized()
|
||||
{
|
||||
return s_initialized;
|
||||
// Libération des dépendances
|
||||
NzUtility::Uninitialize();
|
||||
}
|
||||
|
||||
bool NzRenderer::EnsureStateUpdate()
|
||||
@@ -771,28 +845,76 @@ bool NzRenderer::EnsureStateUpdate()
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!m_stencilFuncUpdated)
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!s_shader)
|
||||
{
|
||||
glStencilFunc(rendererComparison[m_stencilCompare], m_stencilReference, m_stencilMask);
|
||||
m_stencilFuncUpdated = true;
|
||||
NazaraError("No shader");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Il est plus rapide d'opérer sur l'implémentation du shader directement
|
||||
NzShaderImpl* shaderImpl = s_shader->m_impl;
|
||||
|
||||
if (!shaderImpl->BindTextures())
|
||||
NazaraWarning("Failed to bind textures");
|
||||
|
||||
for (unsigned int i = 0; i <= nzMatrixType_Max; ++i)
|
||||
{
|
||||
if (!s_matrixUpdated[i])
|
||||
{
|
||||
shaderImpl->SendMatrix(s_matrixLocation[i], s_matrix[i]);
|
||||
s_matrixUpdated[i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_stencilOpUpdated)
|
||||
// Cas spéciaux car il faut recalculer la matrice
|
||||
if (!s_matrixUpdated[nzMatrixCombination_ViewProj])
|
||||
{
|
||||
glStencilOp(stencilOperation[m_stencilFail], stencilOperation[m_stencilZFail], stencilOperation[m_stencilPass]);
|
||||
m_stencilOpUpdated = true;
|
||||
s_matrix[nzMatrixCombination_ViewProj] = s_matrix[nzMatrixType_View] * s_matrix[nzMatrixType_Projection];
|
||||
|
||||
shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_ViewProj], s_matrix[nzMatrixCombination_ViewProj]);
|
||||
s_matrixUpdated[nzMatrixCombination_ViewProj] = true;
|
||||
}
|
||||
|
||||
if (!m_vaoUpdated)
|
||||
if (!s_matrixUpdated[nzMatrixCombination_WorldView])
|
||||
{
|
||||
s_matrix[nzMatrixCombination_WorldView] = NzMatrix4f::ConcatenateAffine(s_matrix[nzMatrixType_World], s_matrix[nzMatrixType_View]);
|
||||
|
||||
shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_WorldView], s_matrix[nzMatrixCombination_WorldView]);
|
||||
s_matrixUpdated[nzMatrixCombination_WorldView] = true;
|
||||
}
|
||||
|
||||
if (!s_matrixUpdated[nzMatrixCombination_WorldViewProj])
|
||||
{
|
||||
s_matrix[nzMatrixCombination_WorldViewProj] = s_matrix[nzMatrixCombination_WorldView] * s_matrix[nzMatrixType_Projection];
|
||||
|
||||
shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_WorldViewProj], s_matrix[nzMatrixCombination_WorldViewProj]);
|
||||
s_matrixUpdated[nzMatrixCombination_WorldViewProj] = true;
|
||||
}
|
||||
|
||||
if (!s_stencilFuncUpdated)
|
||||
{
|
||||
glStencilFunc(rendererComparison[s_stencilCompare], s_stencilReference, s_stencilMask);
|
||||
s_stencilFuncUpdated = true;
|
||||
}
|
||||
|
||||
if (!s_stencilOpUpdated)
|
||||
{
|
||||
glStencilOp(stencilOperation[s_stencilFail], stencilOperation[s_stencilZFail], stencilOperation[s_stencilPass]);
|
||||
s_stencilOpUpdated = true;
|
||||
}
|
||||
|
||||
if (!s_vaoUpdated)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_vertexBuffer)
|
||||
if (!s_vertexBuffer)
|
||||
{
|
||||
NazaraError("No vertex buffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_vertexDeclaration)
|
||||
if (!s_vertexDeclaration)
|
||||
{
|
||||
NazaraError("No vertex declaration");
|
||||
return false;
|
||||
@@ -809,16 +931,16 @@ bool NzRenderer::EnsureStateUpdate()
|
||||
// On recherche si un VAO existe déjà avec notre configuration
|
||||
// Note: Les VAOs ne sont pas partagés entre les contextes, ces derniers font donc partie de notre configuration
|
||||
|
||||
auto key = std::make_tuple(NzContext::GetCurrent(), m_indexBuffer, m_vertexBuffer, m_vertexDeclaration);
|
||||
auto it = m_vaos.find(key);
|
||||
if (it == m_vaos.end())
|
||||
auto key = std::make_tuple(NzContext::GetCurrent(), s_indexBuffer, s_vertexBuffer, s_vertexDeclaration);
|
||||
auto it = s_vaos.find(key);
|
||||
if (it == s_vaos.end())
|
||||
{
|
||||
// On créé notre VAO
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
|
||||
// On l'ajoute à notre liste
|
||||
m_vaos.insert(std::make_pair(key, static_cast<unsigned int>(vao)));
|
||||
s_vaos.insert(std::make_pair(key, static_cast<unsigned int>(vao)));
|
||||
|
||||
// Et on indique qu'on veut le programmer
|
||||
update = true;
|
||||
@@ -836,15 +958,15 @@ bool NzRenderer::EnsureStateUpdate()
|
||||
|
||||
if (update)
|
||||
{
|
||||
NzHardwareBuffer* vertexBuffer = static_cast<NzHardwareBuffer*>(m_vertexBuffer->GetBuffer()->GetImpl());
|
||||
vertexBuffer->Bind();
|
||||
NzHardwareBuffer* vertexBufferImpl = static_cast<NzHardwareBuffer*>(s_vertexBuffer->GetBuffer()->GetImpl());
|
||||
vertexBufferImpl->Bind();
|
||||
|
||||
const nzUInt8* buffer = reinterpret_cast<const nzUInt8*>(m_vertexBuffer->GetPointer());
|
||||
const nzUInt8* buffer = reinterpret_cast<const nzUInt8*>(s_vertexBuffer->GetPointer());
|
||||
|
||||
unsigned int stride = m_vertexDeclaration->GetStride(nzElementStream_VertexData);
|
||||
unsigned int stride = s_vertexDeclaration->GetStride(nzElementStream_VertexData);
|
||||
for (unsigned int i = 0; i <= nzElementUsage_Max; ++i)
|
||||
{
|
||||
const NzVertexElement* element = m_vertexDeclaration->GetElement(nzElementStream_VertexData, static_cast<nzElementUsage>(i));
|
||||
const NzVertexElement* element = s_vertexDeclaration->GetElement(nzElementStream_VertexData, static_cast<nzElementUsage>(i));
|
||||
|
||||
if (element)
|
||||
{
|
||||
@@ -860,10 +982,10 @@ bool NzRenderer::EnsureStateUpdate()
|
||||
glDisableVertexAttribArray(attribIndex[i]);
|
||||
}
|
||||
|
||||
if (m_indexBuffer)
|
||||
if (s_indexBuffer)
|
||||
{
|
||||
NzHardwareBuffer* indexBuffer = static_cast<NzHardwareBuffer*>(m_indexBuffer->GetBuffer()->GetImpl());
|
||||
indexBuffer->Bind();
|
||||
NzHardwareBuffer* indexBufferImpl = static_cast<NzHardwareBuffer*>(s_indexBuffer->GetBuffer()->GetImpl());
|
||||
indexBufferImpl->Bind();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -877,11 +999,10 @@ bool NzRenderer::EnsureStateUpdate()
|
||||
glBindVertexArray(vao);
|
||||
}
|
||||
|
||||
m_vaoUpdated = true;
|
||||
s_vaoUpdated = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NzRenderer* NzRenderer::s_instance = nullptr;
|
||||
bool NzRenderer::s_initialized = false;
|
||||
unsigned int NzRenderer::s_moduleReferenceCouter = 0;
|
||||
|
||||
@@ -161,6 +161,32 @@ NzString NzShader::GetSourceCode(nzShaderType type) const
|
||||
return m_impl->GetSourceCode(type);
|
||||
}
|
||||
|
||||
int NzShader::GetUniformLocation(const NzString& name) const
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->GetUniformLocation(name);
|
||||
}
|
||||
|
||||
bool NzShader::HasUniform(const NzString& name) const
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->GetUniformLocation(name) != -1;
|
||||
}
|
||||
|
||||
bool NzShader::IsCompiled() const
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
@@ -282,7 +308,7 @@ bool NzShader::Lock()
|
||||
return m_impl->Lock();
|
||||
}
|
||||
|
||||
bool NzShader::SendBoolean(const NzString& name, bool value)
|
||||
bool NzShader::SendBoolean(int location, bool value)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
@@ -290,57 +316,43 @@ bool NzShader::SendBoolean(const NzString& name, bool value)
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendBoolean(name, value);
|
||||
return m_impl->SendBoolean(location, value);
|
||||
}
|
||||
|
||||
bool NzShader::SendDouble(const NzString& name, double value)
|
||||
bool NzShader::SendDouble(int location, double value)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!NazaraRenderer->HasCapability(nzRendererCap_FP64))
|
||||
if (!NzRenderer::HasCapability(nzRendererCap_FP64))
|
||||
{
|
||||
NazaraError("FP64 is not supported");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendDouble(name, value);
|
||||
}
|
||||
|
||||
bool NzShader::SendFloat(const NzString& name, float value)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendFloat(name, value);
|
||||
}
|
||||
|
||||
bool NzShader::SendInteger(const NzString& name, int value)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendInteger(name, value);
|
||||
return m_impl->SendDouble(location, value);
|
||||
}
|
||||
|
||||
bool NzShader::SendMatrix(const NzString& name, const NzMatrix4d& matrix)
|
||||
bool NzShader::SendFloat(int location, float value)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
@@ -349,30 +361,61 @@ bool NzShader::SendMatrix(const NzString& name, const NzMatrix4d& matrix)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!NazaraRenderer->HasCapability(nzRendererCap_FP64))
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendFloat(location, value);
|
||||
}
|
||||
|
||||
bool NzShader::SendInteger(int location, int value)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendInteger(location, value);
|
||||
}
|
||||
|
||||
bool NzShader::SendMatrix(int location, const NzMatrix4d& matrix)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!NzRenderer::HasCapability(nzRendererCap_FP64))
|
||||
{
|
||||
NazaraError("FP64 is not supported");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendMatrix(name, matrix);
|
||||
}
|
||||
|
||||
bool NzShader::SendMatrix(const NzString& name, const NzMatrix4f& matrix)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendMatrix(name, matrix);
|
||||
return m_impl->SendMatrix(location, matrix);
|
||||
}
|
||||
|
||||
bool NzShader::SendVector(const NzString& name, const NzVector2d& vector)
|
||||
bool NzShader::SendMatrix(int location, const NzMatrix4f& matrix)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
@@ -381,30 +424,61 @@ bool NzShader::SendVector(const NzString& name, const NzVector2d& vector)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!NazaraRenderer->HasCapability(nzRendererCap_FP64))
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendMatrix(location, matrix);
|
||||
}
|
||||
|
||||
bool NzShader::SendTexture(int location, const NzTexture* texture)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendTexture(location, texture);
|
||||
}
|
||||
|
||||
bool NzShader::SendVector(int location, const NzVector2d& vector)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!NzRenderer::HasCapability(nzRendererCap_FP64))
|
||||
{
|
||||
NazaraError("FP64 is not supported");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendVector(name, vector);
|
||||
}
|
||||
|
||||
bool NzShader::SendVector(const NzString& name, const NzVector2f& vector)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendVector(name, vector);
|
||||
return m_impl->SendVector(location, vector);
|
||||
}
|
||||
|
||||
bool NzShader::SendVector(const NzString& name, const NzVector3d& vector)
|
||||
bool NzShader::SendVector(int location, const NzVector2f& vector)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
@@ -413,30 +487,42 @@ bool NzShader::SendVector(const NzString& name, const NzVector3d& vector)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!NazaraRenderer->HasCapability(nzRendererCap_FP64))
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendVector(location, vector);
|
||||
}
|
||||
|
||||
bool NzShader::SendVector(int location, const NzVector3d& vector)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!NzRenderer::HasCapability(nzRendererCap_FP64))
|
||||
{
|
||||
NazaraError("FP64 is not supported");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendVector(name, vector);
|
||||
}
|
||||
|
||||
bool NzShader::SendVector(const NzString& name, const NzVector3f& vector)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendVector(name, vector);
|
||||
return m_impl->SendVector(location, vector);
|
||||
}
|
||||
|
||||
bool NzShader::SendVector(const NzString& name, const NzVector4d& vector)
|
||||
bool NzShader::SendVector(int location, const NzVector3f& vector)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
@@ -445,17 +531,42 @@ bool NzShader::SendVector(const NzString& name, const NzVector4d& vector)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!NazaraRenderer->HasCapability(nzRendererCap_FP64))
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendVector(location, vector);
|
||||
}
|
||||
|
||||
bool NzShader::SendVector(int location, const NzVector4d& vector)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!NzRenderer::HasCapability(nzRendererCap_FP64))
|
||||
{
|
||||
NazaraError("FP64 is not supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendVector(name, vector);
|
||||
return m_impl->SendVector(location, vector);
|
||||
}
|
||||
|
||||
bool NzShader::SendVector(const NzString& name, const NzVector4f& vector)
|
||||
bool NzShader::SendVector(int location, const NzVector4f& vector)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
@@ -463,22 +574,15 @@ bool NzShader::SendVector(const NzString& name, const NzVector4f& vector)
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendVector(name, vector);
|
||||
}
|
||||
|
||||
bool NzShader::SendTexture(const NzString& name, NzTexture* texture)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendTexture(name, texture);
|
||||
return m_impl->SendVector(location, vector);
|
||||
}
|
||||
|
||||
void NzShader::Unlock()
|
||||
|
||||
@@ -23,6 +23,7 @@ class NzShaderImpl
|
||||
virtual ~NzShaderImpl();
|
||||
|
||||
virtual bool Bind() = 0;
|
||||
virtual bool BindTextures() = 0;
|
||||
|
||||
virtual bool Compile() = 0;
|
||||
virtual bool Create() = 0;
|
||||
@@ -32,6 +33,7 @@ class NzShaderImpl
|
||||
virtual NzString GetLog() const = 0;
|
||||
virtual nzShaderLanguage GetLanguage() const = 0;
|
||||
virtual NzString GetSourceCode(nzShaderType type) const = 0;
|
||||
virtual int GetUniformLocation(const NzString& name) const = 0;
|
||||
|
||||
virtual bool IsLoaded(nzShaderType type) const = 0;
|
||||
|
||||
@@ -39,19 +41,19 @@ class NzShaderImpl
|
||||
|
||||
virtual bool Lock() = 0;
|
||||
|
||||
virtual bool SendBoolean(const NzString& name, bool value) = 0;
|
||||
virtual bool SendDouble(const NzString& name, double value) = 0;
|
||||
virtual bool SendFloat(const NzString& name, float value) = 0;
|
||||
virtual bool SendInteger(const NzString& name, int value) = 0;
|
||||
virtual bool SendMatrix(const NzString& name, const NzMatrix4d& matrix) = 0;
|
||||
virtual bool SendMatrix(const NzString& name, const NzMatrix4f& matrix) = 0;
|
||||
virtual bool SendVector(const NzString& name, const NzVector2d& vector) = 0;
|
||||
virtual bool SendVector(const NzString& name, const NzVector2f& vector) = 0;
|
||||
virtual bool SendVector(const NzString& name, const NzVector3d& vector) = 0;
|
||||
virtual bool SendVector(const NzString& name, const NzVector3f& vector) = 0;
|
||||
virtual bool SendVector(const NzString& name, const NzVector4d& vector) = 0;
|
||||
virtual bool SendVector(const NzString& name, const NzVector4f& vector) = 0;
|
||||
virtual bool SendTexture(const NzString& name, NzTexture* texture) = 0;
|
||||
virtual bool SendBoolean(int location, bool value) = 0;
|
||||
virtual bool SendDouble(int location, double value) = 0;
|
||||
virtual bool SendFloat(int location, float value) = 0;
|
||||
virtual bool SendInteger(int location, int value) = 0;
|
||||
virtual bool SendMatrix(int location, const NzMatrix4d& matrix) = 0;
|
||||
virtual bool SendMatrix(int location, const NzMatrix4f& matrix) = 0;
|
||||
virtual bool SendTexture(int location, const NzTexture* texture) = 0;
|
||||
virtual bool SendVector(int location, const NzVector2d& vector) = 0;
|
||||
virtual bool SendVector(int location, const NzVector2f& vector) = 0;
|
||||
virtual bool SendVector(int location, const NzVector3d& vector) = 0;
|
||||
virtual bool SendVector(int location, const NzVector3f& vector) = 0;
|
||||
virtual bool SendVector(int location, const NzVector4d& vector) = 0;
|
||||
virtual bool SendVector(int location, const NzVector4f& vector) = 0;
|
||||
|
||||
virtual void Unbind() = 0;
|
||||
virtual void Unlock() = 0;
|
||||
|
||||
@@ -39,18 +39,31 @@ namespace
|
||||
|
||||
GLenum openglTarget[] =
|
||||
{
|
||||
GL_TEXTURE_1D, // nzImageType_1D
|
||||
GL_TEXTURE_2D, // nzImageType_2D
|
||||
GL_TEXTURE_3D, // nzImageType_3D
|
||||
GL_TEXTURE_CUBE_MAP // nzImageType_Cubemap
|
||||
GL_TEXTURE_1D, // nzImageType_1D
|
||||
GL_TEXTURE_1D_ARRAY, // nzImageType_1D_Array
|
||||
GL_TEXTURE_2D, // nzImageType_2D
|
||||
GL_TEXTURE_2D_ARRAY, // nzImageType_2D_Array
|
||||
GL_TEXTURE_3D, // nzImageType_3D
|
||||
GL_TEXTURE_CUBE_MAP // nzImageType_Cubemap
|
||||
};
|
||||
|
||||
GLenum openglTargetBinding[] =
|
||||
{
|
||||
GL_TEXTURE_BINDING_1D, // nzImageType_1D
|
||||
GL_TEXTURE_BINDING_2D, // nzImageType_2D
|
||||
GL_TEXTURE_BINDING_3D, // nzImageType_3D
|
||||
GL_TEXTURE_BINDING_CUBE_MAP // nzImageType_Cubemap
|
||||
GL_TEXTURE_BINDING_1D, // nzImageType_1D
|
||||
GL_TEXTURE_BINDING_1D_ARRAY, // nzImageType_1D
|
||||
GL_TEXTURE_BINDING_2D, // nzImageType_2D
|
||||
GL_TEXTURE_BINDING_3D, // nzImageType_3D
|
||||
GL_TEXTURE_BINDING_CUBE_MAP // nzImageType_Cubemap
|
||||
};
|
||||
|
||||
GLenum openglTargetProxy[] =
|
||||
{
|
||||
GL_PROXY_TEXTURE_1D, // nzImageType_1D
|
||||
GL_PROXY_TEXTURE_1D_ARRAY, // nzImageType_1D_Array
|
||||
GL_PROXY_TEXTURE_2D, // nzImageType_2D
|
||||
GL_PROXY_TEXTURE_2D_ARRAY, // nzImageType_2D_Array
|
||||
GL_PROXY_TEXTURE_3D, // nzImageType_3D
|
||||
GL_PROXY_TEXTURE_CUBE_MAP // nzImageType_Cubemap
|
||||
};
|
||||
|
||||
struct OpenGLFormat
|
||||
@@ -142,16 +155,16 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
GLenum target;
|
||||
GLenum target = (proxy) ? openglTargetProxy[impl->type] : openglTarget[impl->type];
|
||||
GLint previous;
|
||||
glGetIntegerv(openglTargetBinding[impl->type], &previous);
|
||||
switch (impl->type)
|
||||
{
|
||||
case nzImageType_1D:
|
||||
{
|
||||
target = (proxy) ? GL_TEXTURE_1D : GL_PROXY_TEXTURE_1D;
|
||||
|
||||
/*if (glTexStorage1D)
|
||||
if (glTexStorage1D)
|
||||
glTexStorage1D(target, impl->levelCount, openGLFormat.internalFormat, impl->width);
|
||||
else*/
|
||||
else
|
||||
{
|
||||
unsigned int w = impl->width;
|
||||
for (nzUInt8 level = 0; level < impl->levelCount; ++level)
|
||||
@@ -164,13 +177,12 @@ namespace
|
||||
break;
|
||||
}
|
||||
|
||||
case nzImageType_1D_Array:
|
||||
case nzImageType_2D:
|
||||
{
|
||||
target = (proxy) ? GL_TEXTURE_2D : GL_PROXY_TEXTURE_2D;
|
||||
|
||||
/*if (glTexStorage2D)
|
||||
if (glTexStorage2D)
|
||||
glTexStorage2D(target, impl->levelCount, openGLFormat.internalFormat, impl->width, impl->height);
|
||||
else*/
|
||||
else
|
||||
{
|
||||
unsigned int w = impl->width;
|
||||
unsigned int h = impl->height;
|
||||
@@ -187,13 +199,12 @@ namespace
|
||||
break;
|
||||
}
|
||||
|
||||
case nzImageType_2D_Array:
|
||||
case nzImageType_3D:
|
||||
{
|
||||
target = (proxy) ? GL_TEXTURE_3D : GL_PROXY_TEXTURE_3D;
|
||||
|
||||
/*if (glTexStorage3D)
|
||||
if (glTexStorage3D)
|
||||
glTexStorage3D(target, impl->levelCount, openGLFormat.internalFormat, impl->width, impl->height, impl->depth);
|
||||
else*/
|
||||
else
|
||||
{
|
||||
unsigned int w = impl->width;
|
||||
unsigned int h = impl->height;
|
||||
@@ -216,11 +227,9 @@ namespace
|
||||
|
||||
case nzImageType_Cubemap:
|
||||
{
|
||||
target = (proxy) ? GL_TEXTURE_CUBE_MAP : GL_PROXY_TEXTURE_CUBE_MAP;
|
||||
|
||||
/*if (glTexStorage2D)
|
||||
if (glTexStorage2D)
|
||||
glTexStorage2D(target, impl->levelCount, openGLFormat.internalFormat, impl->width, impl->height);
|
||||
else*/
|
||||
else
|
||||
{
|
||||
unsigned int size = impl->width; // Les cubemaps ont une longueur et largeur identique
|
||||
for (nzUInt8 level = 0; level < impl->levelCount; ++level)
|
||||
@@ -234,15 +243,11 @@ namespace
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
NazaraInternalError("Image type not handled");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (proxy)
|
||||
{
|
||||
GLint internalFormat;
|
||||
GLint internalFormat = 0;
|
||||
glGetTexLevelParameteriv(target, 0, GL_TEXTURE_INTERNAL_FORMAT, &internalFormat);
|
||||
if (internalFormat == 0)
|
||||
return false;
|
||||
@@ -400,6 +405,7 @@ bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int widt
|
||||
}
|
||||
break;
|
||||
|
||||
case nzImageType_1D_Array:
|
||||
case nzImageType_2D:
|
||||
if (depth > 1)
|
||||
{
|
||||
@@ -408,6 +414,7 @@ bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int widt
|
||||
}
|
||||
break;
|
||||
|
||||
case nzImageType_2D_Array:
|
||||
case nzImageType_3D:
|
||||
break;
|
||||
|
||||
@@ -424,10 +431,6 @@ bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int widt
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
NazaraInternalError("Image type not handled");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -454,7 +457,7 @@ bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int widt
|
||||
LockTexture(impl);
|
||||
|
||||
// Vérification du support par la carte graphique
|
||||
if (!CreateTexture(impl, true))
|
||||
/*if (!CreateTexture(impl, true))
|
||||
{
|
||||
NazaraError("Texture's parameters not supported by driver");
|
||||
UnlockTexture(impl);
|
||||
@@ -462,7 +465,7 @@ bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int widt
|
||||
delete impl;
|
||||
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
|
||||
// Création de la texture
|
||||
if (!CreateTexture(impl, false))
|
||||
@@ -603,16 +606,13 @@ unsigned int NzTexture::GetAnisotropyLevel() const
|
||||
if (!IsValid())
|
||||
{
|
||||
NazaraError("Texture must be valid");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter))
|
||||
{
|
||||
NazaraError("Anisotropic filter not supported");
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter))
|
||||
return 1;
|
||||
|
||||
LockTexture(m_impl);
|
||||
|
||||
GLint anisotropyLevel;
|
||||
@@ -937,7 +937,7 @@ bool NzTexture::SetAnisotropyLevel(unsigned int anistropyLevel)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter))
|
||||
if (!NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter) && anistropyLevel > 1)
|
||||
{
|
||||
NazaraError("Anisotropic filter not supported");
|
||||
return false;
|
||||
@@ -1070,9 +1070,11 @@ bool NzTexture::SetWrapMode(nzTextureWrap wrap)
|
||||
case nzImageType_3D:
|
||||
glTexParameteri(target, GL_TEXTURE_WRAP_R, wrapMode);
|
||||
case nzImageType_2D:
|
||||
case nzImageType_2D_Array:
|
||||
case nzImageType_Cubemap:
|
||||
glTexParameteri(target, GL_TEXTURE_WRAP_T, wrapMode);
|
||||
case nzImageType_1D:
|
||||
case nzImageType_1D_Array:
|
||||
glTexParameteri(target, GL_TEXTURE_WRAP_S, wrapMode);
|
||||
break;
|
||||
|
||||
@@ -1180,7 +1182,7 @@ bool NzTexture::Update(const nzUInt8* pixels, nzUInt8 level)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (m_impl->type == nzImageType_3D)
|
||||
if (m_impl->type == nzImageType_3D || m_impl->type == nzImageType_2D_Array)
|
||||
return Update(pixels, NzCubeui(0, 0, 0, std::max(m_impl->width >> level, 1U), std::max(m_impl->height >> level, 1U), std::max(m_impl->depth >> level, 1U)), level);
|
||||
else
|
||||
return Update(pixels, NzRectui(0, 0, std::max(m_impl->width >> level, 1U), std::max(m_impl->height >> level, 1U)), 0, level);
|
||||
@@ -1268,16 +1270,19 @@ bool NzTexture::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int
|
||||
glTexSubImage1D(GL_TEXTURE_1D, level, rect.x, rect.width, format.dataFormat, format.dataType, mirrored.GetConstPixels());
|
||||
break;
|
||||
|
||||
case nzImageType_1D_Array:
|
||||
case nzImageType_2D:
|
||||
glTexSubImage2D(GL_TEXTURE_2D, level, rect.x, height-rect.height-rect.y, rect.width, rect.height, format.dataFormat, format.dataType, mirrored.GetConstPixels());
|
||||
glTexSubImage2D(openglTarget[m_impl->type], level, rect.x, height-rect.height-rect.y, rect.width, rect.height, format.dataFormat, format.dataType, mirrored.GetConstPixels());
|
||||
break;
|
||||
|
||||
case nzImageType_2D_Array:
|
||||
case nzImageType_3D:
|
||||
glTexSubImage3D(GL_TEXTURE_3D, level, rect.x, height-rect.height-rect.y, z, rect.width, rect.height, 1, format.dataFormat, format.dataType, mirrored.GetConstPixels());
|
||||
glTexSubImage3D(openglTarget[m_impl->type], level, rect.x, height-rect.height-rect.y, z, rect.width, rect.height, 1, format.dataFormat, format.dataType, mirrored.GetConstPixels());
|
||||
break;
|
||||
|
||||
default:
|
||||
NazaraInternalError("Image type not handled (0x" + NzString::Number(m_impl->type, 16) + ')');
|
||||
case nzImageType_Cubemap:
|
||||
NazaraError("Update used on a cubemap texture, please enable safe mode");
|
||||
break;
|
||||
}
|
||||
UnlockTexture(m_impl);
|
||||
|
||||
@@ -1363,16 +1368,19 @@ bool NzTexture::Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 leve
|
||||
glTexSubImage1D(GL_TEXTURE_1D, level, cube.x, cube.width, format.dataFormat, format.dataType, mirrored);
|
||||
break;
|
||||
|
||||
case nzImageType_1D_Array:
|
||||
case nzImageType_2D:
|
||||
glTexSubImage2D(GL_TEXTURE_2D, level, cube.x, height-cube.height-cube.y, cube.width, cube.height, format.dataFormat, format.dataType, mirrored);
|
||||
glTexSubImage2D(openglTarget[m_impl->type], level, cube.x, height-cube.height-cube.y, cube.width, cube.height, format.dataFormat, format.dataType, mirrored);
|
||||
break;
|
||||
|
||||
case nzImageType_2D_Array:
|
||||
case nzImageType_3D:
|
||||
glTexSubImage3D(GL_TEXTURE_3D, level, cube.x, height-cube.height-cube.y, cube.z, cube.width, cube.height, cube.depth, format.dataFormat, format.dataType, mirrored);
|
||||
glTexSubImage3D(openglTarget[m_impl->type], level, cube.x, height-cube.height-cube.y, cube.z, cube.width, cube.height, cube.depth, format.dataFormat, format.dataType, mirrored);
|
||||
break;
|
||||
|
||||
default:
|
||||
NazaraInternalError("Image type not handled (0x" + NzString::Number(m_impl->type, 16) + ')');
|
||||
case nzImageType_Cubemap:
|
||||
NazaraError("Update used on a cubemap texture, please enable safe mode");
|
||||
break;
|
||||
}
|
||||
UnlockTexture(m_impl);
|
||||
|
||||
@@ -1531,7 +1539,7 @@ void NzTexture::Unlock()
|
||||
|
||||
unsigned int NzTexture::GetValidSize(unsigned int size)
|
||||
{
|
||||
if (NazaraRenderer->HasCapability(nzRendererCap_TextureNPOT))
|
||||
if (NzRenderer::HasCapability(nzRendererCap_TextureNPOT))
|
||||
return size;
|
||||
else
|
||||
{
|
||||
@@ -1596,9 +1604,16 @@ bool NzTexture::IsTypeSupported(nzImageType type)
|
||||
case nzImageType_Cubemap:
|
||||
return true; // Tous supportés nativement dans OpenGL 2
|
||||
|
||||
default:
|
||||
return false;
|
||||
case nzImageType_1D_Array:
|
||||
case nzImageType_2D_Array:
|
||||
{
|
||||
static bool supported = NzOpenGL::IsSupported(NzOpenGL::TextureArray);
|
||||
return supported;
|
||||
}
|
||||
}
|
||||
|
||||
NazaraError("Image type not handled (0x" + NzString::Number(type, 16) + ')');
|
||||
return false;
|
||||
}
|
||||
|
||||
void NzTexture::SetTarget(bool isTarget)
|
||||
|
||||
162
src/Nazara/Utility/AxisAlignedBox.cpp
Normal file
162
src/Nazara/Utility/AxisAlignedBox.cpp
Normal file
@@ -0,0 +1,162 @@
|
||||
// Copyright (C) 2011 Jérôme Leclercq
|
||||
// This file is part of the "Ungine".
|
||||
// For conditions of distribution and use, see copyright notice in Core.h
|
||||
|
||||
#include <Nazara/Utility/AxisAlignedBox.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
NzAxisAlignedBox::NzAxisAlignedBox() :
|
||||
m_extend(nzExtend_Null)
|
||||
{
|
||||
}
|
||||
|
||||
NzAxisAlignedBox::NzAxisAlignedBox(const NzVector3f& vec1, const NzVector3f& vec2) :
|
||||
m_extend(nzExtend_Finite),
|
||||
m_cube(vec1, vec2)
|
||||
{
|
||||
}
|
||||
|
||||
NzAxisAlignedBox::NzAxisAlignedBox(nzExtend extend) :
|
||||
m_extend(extend)
|
||||
{
|
||||
}
|
||||
|
||||
bool NzAxisAlignedBox::Contains(const NzAxisAlignedBox& box)
|
||||
{
|
||||
if (m_extend == nzExtend_Null || box.m_extend == nzExtend_Null)
|
||||
return false;
|
||||
else if (m_extend == nzExtend_Infinite || box.m_extend == nzExtend_Infinite)
|
||||
return true;
|
||||
|
||||
return m_cube.Contains(box.m_cube);
|
||||
}
|
||||
|
||||
void NzAxisAlignedBox::ExtendTo(const NzAxisAlignedBox& box)
|
||||
{
|
||||
switch (m_extend)
|
||||
{
|
||||
case nzExtend_Finite:
|
||||
{
|
||||
switch (box.m_extend)
|
||||
{
|
||||
case nzExtend_Finite:
|
||||
m_cube.ExtendTo(box.m_cube);
|
||||
break;
|
||||
|
||||
case nzExtend_Infinite:
|
||||
SetInfinite();
|
||||
break;
|
||||
|
||||
case nzExtend_Null:
|
||||
break;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case nzExtend_Infinite:
|
||||
// Rien à faire
|
||||
break;
|
||||
|
||||
case nzExtend_Null:
|
||||
operator=(box);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NzAxisAlignedBox::ExtendTo(const NzVector3f& vector)
|
||||
{
|
||||
switch (m_extend)
|
||||
{
|
||||
case nzExtend_Finite:
|
||||
m_cube.ExtendTo(vector);
|
||||
break;
|
||||
|
||||
case nzExtend_Infinite:
|
||||
// Rien à faire
|
||||
break;
|
||||
|
||||
case nzExtend_Null:
|
||||
// Nous étendons l'AABB en la construisant de l'origine jusqu'au vecteur
|
||||
m_cube.x = 0.f;
|
||||
m_cube.y = 0.f;
|
||||
m_cube.z = 0.f;
|
||||
m_cube.width = std::fabs(vector.x);
|
||||
m_cube.height = std::fabs(vector.y);
|
||||
m_cube.depth = std::fabs(vector.z);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
nzExtend NzAxisAlignedBox::GetExtend() const
|
||||
{
|
||||
return m_extend;
|
||||
}
|
||||
|
||||
NzVector3f NzAxisAlignedBox::GetMaximum() const
|
||||
{
|
||||
return NzVector3f(m_cube.x+m_cube.width, m_cube.y+m_cube.height, m_cube.z+m_cube.depth);
|
||||
}
|
||||
|
||||
NzVector3f NzAxisAlignedBox::GetMinimum() const
|
||||
{
|
||||
return NzVector3f(m_cube.x, m_cube.y, m_cube.z);
|
||||
}
|
||||
|
||||
bool NzAxisAlignedBox::IsFinite() const
|
||||
{
|
||||
return m_extend == nzExtend_Finite;
|
||||
}
|
||||
|
||||
bool NzAxisAlignedBox::IsInfinite() const
|
||||
{
|
||||
return m_extend == nzExtend_Infinite;
|
||||
}
|
||||
|
||||
bool NzAxisAlignedBox::IsNull() const
|
||||
{
|
||||
return m_extend == nzExtend_Null;
|
||||
}
|
||||
|
||||
void NzAxisAlignedBox::SetInfinite()
|
||||
{
|
||||
m_extend = nzExtend_Infinite;
|
||||
}
|
||||
|
||||
void NzAxisAlignedBox::SetExtends(const NzVector3f& vec1, const NzVector3f& vec2)
|
||||
{
|
||||
m_extend = nzExtend_Finite;
|
||||
m_cube.Set(vec1, vec2);
|
||||
}
|
||||
|
||||
void NzAxisAlignedBox::SetNull()
|
||||
{
|
||||
m_extend = nzExtend_Null;
|
||||
}
|
||||
|
||||
NzString NzAxisAlignedBox::ToString() const
|
||||
{
|
||||
switch (m_extend)
|
||||
{
|
||||
case nzExtend_Finite:
|
||||
return "NzAxisAlignedBox(min=" + GetMinimum().ToString() + ", max=" + GetMaximum().ToString() + ')';
|
||||
|
||||
case nzExtend_Infinite:
|
||||
return "NzAxisAlignedBox(Infinite)";
|
||||
|
||||
case nzExtend_Null:
|
||||
return "NzAxisAlignedBox(Null)";
|
||||
}
|
||||
|
||||
return "NzAxisAlignedBox(ERROR)";
|
||||
}
|
||||
|
||||
const NzAxisAlignedBox NzAxisAlignedBox::Infinite(nzExtend_Infinite);
|
||||
const NzAxisAlignedBox NzAxisAlignedBox::Null(nzExtend_Null);
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const NzAxisAlignedBox& aabb)
|
||||
{
|
||||
out << aabb.ToString();
|
||||
return out;
|
||||
}
|
||||
@@ -290,9 +290,10 @@ bool NzBuffer::SetStorage(nzBufferStorage storage)
|
||||
|
||||
m_impl->Unmap();
|
||||
m_impl->Destroy();
|
||||
delete m_impl;
|
||||
|
||||
delete m_impl;
|
||||
m_impl = impl;
|
||||
|
||||
m_storage = storage;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace
|
||||
|
||||
inline nzUInt8* GetPixelPtr(nzUInt8* base, nzUInt8 bpp, unsigned int x, unsigned int y, unsigned int z, unsigned int width, unsigned int height)
|
||||
{
|
||||
return &base[(width*(height*z+y) + x) * bpp];
|
||||
return &base[(width*(height*z + y) + x)*bpp];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ m_sharedImage(image.m_sharedImage)
|
||||
}
|
||||
}
|
||||
|
||||
NzImage::NzImage(NzImage&& image) :
|
||||
NzImage::NzImage(NzImage&& image) noexcept :
|
||||
m_sharedImage(image.m_sharedImage)
|
||||
{
|
||||
image.m_sharedImage = &emptyImage;
|
||||
@@ -95,14 +95,15 @@ bool NzImage::Convert(nzPixelFormat format)
|
||||
unsigned int srcStride = pixelsPerFace * NzPixelFormat::GetBPP(m_sharedImage->format);
|
||||
unsigned int dstStride = pixelsPerFace * NzPixelFormat::GetBPP(format);
|
||||
|
||||
levels[i] = ptr;
|
||||
|
||||
for (unsigned int d = 0; d < depth; ++d)
|
||||
{
|
||||
if (!NzPixelFormat::Convert(m_sharedImage->format, format, pixels, &pixels[srcStride], ptr))
|
||||
{
|
||||
NazaraError("Failed to convert image");
|
||||
for (unsigned int j = 0; j <= i; ++j)
|
||||
|
||||
// Nettoyage de la mémoire
|
||||
delete[] ptr; // Permet une optimisation de boucle (GCC)
|
||||
for (unsigned int j = 0; j < i; ++j)
|
||||
delete[] levels[j];
|
||||
|
||||
delete[] levels;
|
||||
@@ -114,6 +115,8 @@ bool NzImage::Convert(nzPixelFormat format)
|
||||
ptr += dstStride;
|
||||
}
|
||||
|
||||
levels[i] = ptr;
|
||||
|
||||
if (width > 1)
|
||||
width >>= 1;
|
||||
|
||||
@@ -223,6 +226,7 @@ bool NzImage::Create(nzImageType type, nzPixelFormat format, unsigned int width,
|
||||
}
|
||||
break;
|
||||
|
||||
case nzImageType_1D_Array:
|
||||
case nzImageType_2D:
|
||||
if (depth > 1)
|
||||
{
|
||||
@@ -231,6 +235,7 @@ bool NzImage::Create(nzImageType type, nzPixelFormat format, unsigned int width,
|
||||
}
|
||||
break;
|
||||
|
||||
case nzImageType_2D_Array:
|
||||
case nzImageType_3D:
|
||||
break;
|
||||
|
||||
@@ -281,7 +286,10 @@ bool NzImage::Create(nzImageType type, nzPixelFormat format, unsigned int width,
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
NazaraError("Failed to allocate image's level " + NzString::Number(i) + " (" + NzString(e.what()) + ')');
|
||||
for (unsigned int j = 0; j <= i; ++j)
|
||||
|
||||
// Nettoyage
|
||||
delete[] levels[i]; // Permet une optimisation de boucle (GCC)
|
||||
for (unsigned int j = 0; j < i; ++j)
|
||||
delete[] levels[j];
|
||||
|
||||
delete[] levels;
|
||||
@@ -302,7 +310,7 @@ void NzImage::Destroy()
|
||||
|
||||
bool NzImage::Fill(const NzColor& color)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!IsValid())
|
||||
{
|
||||
NazaraError("Image must be valid");
|
||||
@@ -399,6 +407,7 @@ bool NzImage::Fill(const NzColor& color, const NzRectui& rect, unsigned int z)
|
||||
return false;
|
||||
}
|
||||
|
||||
///FIXME: L'algorithme a du mal avec un bpp non multiple de 2
|
||||
nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[0], bpp, rect.x, rect.y, z, m_sharedImage->width, m_sharedImage->height);
|
||||
unsigned int srcStride = rect.width * bpp;
|
||||
unsigned int dstStride = m_sharedImage->width * bpp;
|
||||
@@ -415,6 +424,8 @@ bool NzImage::Fill(const NzColor& color, const NzRectui& rect, unsigned int z)
|
||||
dstPixels += dstStride;
|
||||
}
|
||||
|
||||
delete[] pixels;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -452,6 +463,7 @@ bool NzImage::Fill(const NzColor& color, const NzCubeui& cube)
|
||||
return false;
|
||||
}
|
||||
|
||||
///FIXME: L'algorithme a du mal avec un bpp non multiple de 2
|
||||
nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[0], bpp, cube.x, cube.y, cube.z, m_sharedImage->width, m_sharedImage->height);
|
||||
unsigned int srcStride = cube.width * bpp;
|
||||
unsigned int dstStride = m_sharedImage->width * bpp;
|
||||
@@ -562,7 +574,7 @@ nzUInt8 NzImage::GetBPP() const
|
||||
return NzPixelFormat::GetBPP(m_sharedImage->format);
|
||||
}
|
||||
|
||||
const nzUInt8* NzImage::GetConstPixels(nzUInt8 level, unsigned int x, unsigned int y, unsigned int z) const
|
||||
const nzUInt8* NzImage::GetConstPixels(unsigned int x, unsigned int y, unsigned int z, nzUInt8 level) const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!IsValid())
|
||||
@@ -571,12 +583,6 @@ const nzUInt8* NzImage::GetConstPixels(nzUInt8 level, unsigned int x, unsigned i
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (level >= m_sharedImage->levelCount)
|
||||
{
|
||||
NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')');
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (x >= m_sharedImage->width)
|
||||
{
|
||||
NazaraError("X value exceeds width (" + NzString::Number(x) + " >= (" + NzString::Number(m_sharedImage->width) + ')');
|
||||
@@ -595,6 +601,12 @@ const nzUInt8* NzImage::GetConstPixels(nzUInt8 level, unsigned int x, unsigned i
|
||||
NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')');
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (level >= m_sharedImage->levelCount)
|
||||
{
|
||||
NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')');
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return GetPixelPtr(m_sharedImage->pixels[level], NzPixelFormat::GetBPP(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height);
|
||||
@@ -685,7 +697,7 @@ NzColor NzImage::GetPixelColor(unsigned int x, unsigned int y, unsigned int z) c
|
||||
return color;
|
||||
}
|
||||
|
||||
nzUInt8* NzImage::GetPixels(nzUInt8 level, unsigned int x, unsigned int y, unsigned int z)
|
||||
nzUInt8* NzImage::GetPixels(unsigned int x, unsigned int y, unsigned int z, nzUInt8 level)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!IsValid())
|
||||
@@ -694,12 +706,6 @@ nzUInt8* NzImage::GetPixels(nzUInt8 level, unsigned int x, unsigned int y, unsig
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (level >= m_sharedImage->levelCount)
|
||||
{
|
||||
NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')');
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (x >= m_sharedImage->width)
|
||||
{
|
||||
NazaraError("X value exceeds width (" + NzString::Number(x) + " >= (" + NzString::Number(m_sharedImage->width) + ')');
|
||||
@@ -718,6 +724,13 @@ nzUInt8* NzImage::GetPixels(nzUInt8 level, unsigned int x, unsigned int y, unsig
|
||||
NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')');
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
if (level >= m_sharedImage->levelCount)
|
||||
{
|
||||
NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')');
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
EnsureOwnership();
|
||||
@@ -1077,7 +1090,7 @@ NzImage& NzImage::operator=(const NzImage& image)
|
||||
return *this;
|
||||
}
|
||||
|
||||
NzImage& NzImage::operator=(NzImage&& image)
|
||||
NzImage& NzImage::operator=(NzImage&& image) noexcept
|
||||
{
|
||||
std::swap(m_sharedImage, image.m_sharedImage);
|
||||
|
||||
@@ -1086,11 +1099,11 @@ NzImage& NzImage::operator=(NzImage&& image)
|
||||
|
||||
nzUInt8 NzImage::GetMaxLevel(unsigned int width, unsigned int height, unsigned int depth)
|
||||
{
|
||||
static const float l2 = std::log(2);
|
||||
static const float l2 = std::log(2.f);
|
||||
|
||||
unsigned int widthLevel = std::log(width)/l2;
|
||||
unsigned int heightLevel = std::log(height)/l2;
|
||||
unsigned int depthLevel = std::log(depth)/l2;
|
||||
unsigned int widthLevel = std::log(static_cast<float>(width))/l2;
|
||||
unsigned int heightLevel = std::log(static_cast<float>(height))/l2;
|
||||
unsigned int depthLevel = std::log(static_cast<float>(depth))/l2;
|
||||
|
||||
return std::max(std::max(std::max(widthLevel, heightLevel), depthLevel), 1U);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace
|
||||
}
|
||||
|
||||
// Les fichiers MD2 sont en little endian
|
||||
#if NAZARA_BIG_ENDIAN
|
||||
#if defined(NAZARA_BIG_ENDIAN)
|
||||
NzByteSwap(&header.ident, sizeof(nzUInt32));
|
||||
#endif
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
#if NAZARA_BIG_ENDIAN
|
||||
#if defined(NAZARA_BIG_ENDIAN)
|
||||
NzByteSwap(&header.version, sizeof(nzUInt32));
|
||||
#endif
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
#if NAZARA_BIG_ENDIAN
|
||||
#if defined(NAZARA_BIG_ENDIAN)
|
||||
NzByteSwap(&header.skinwidth, sizeof(nzUInt32));
|
||||
NzByteSwap(&header.skinheight, sizeof(nzUInt32));
|
||||
NzByteSwap(&header.framesize, sizeof(nzUInt32));
|
||||
@@ -129,6 +129,7 @@ namespace
|
||||
NzAnimation* animation = new NzAnimation;
|
||||
if (animation->Create(nzAnimationType_Keyframe, endFrame-startFrame+1))
|
||||
{
|
||||
// Décodage des séquences
|
||||
NzString frameName;
|
||||
|
||||
NzSequence sequence;
|
||||
@@ -154,7 +155,7 @@ namespace
|
||||
stream.SetCursorPos(header.offset_frames + i*header.framesize + offsetof(md2_frame, name));
|
||||
stream.Read(name, 16*sizeof(char));
|
||||
|
||||
int pos = std::strlen(name)-1;
|
||||
pos = std::strlen(name)-1;
|
||||
for (unsigned int j = 0; j < 2; ++j)
|
||||
{
|
||||
if (!std::isdigit(name[pos]))
|
||||
@@ -217,7 +218,7 @@ namespace
|
||||
|
||||
const md2_header* header = reinterpret_cast<const md2_header*>(data);
|
||||
|
||||
#if NAZARA_BIG_ENDIAN
|
||||
#if defined(NAZARA_BIG_ENDIAN)
|
||||
nzUInt32 ident = header->ident;
|
||||
nzUInt32 version = header->version;
|
||||
|
||||
@@ -238,7 +239,7 @@ namespace
|
||||
if (stream.Read(&magic[0], 2*sizeof(nzUInt32)) != 2*sizeof(nzUInt32))
|
||||
return false;
|
||||
|
||||
#if NAZARA_BIG_ENDIAN
|
||||
#if defined(NAZARA_BIG_ENDIAN)
|
||||
NzByteSwap(&magic[0], sizeof(nzUInt32));
|
||||
NzByteSwap(&magic[1], sizeof(nzUInt32));
|
||||
#endif
|
||||
|
||||
@@ -41,7 +41,7 @@ bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const Nz
|
||||
stream.SetCursorPos(header.offset_st);
|
||||
stream.Read(&texCoords[0], header.num_st*sizeof(md2_texCoord));
|
||||
|
||||
#if NAZARA_BIG_ENDIAN
|
||||
#if defined(NAZARA_BIG_ENDIAN)
|
||||
for (unsigned int i = 0; i < header.num_st; ++i)
|
||||
{
|
||||
NzByteSwap(&texCoords[i].u, sizeof(nzInt16));
|
||||
@@ -52,7 +52,7 @@ bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const Nz
|
||||
stream.SetCursorPos(header.offset_tris);
|
||||
stream.Read(&triangles[0], header.num_tris*sizeof(md2_triangle));
|
||||
|
||||
#if NAZARA_BIG_ENDIAN
|
||||
#if defined(NAZARA_BIG_ENDIAN)
|
||||
for (unsigned int i = 0; i < header.num_tris; ++i)
|
||||
{
|
||||
NzByteSwap(&triangles[i].vertices[0], sizeof(nzUInt16));
|
||||
@@ -72,9 +72,7 @@ bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const Nz
|
||||
frame.vertices.resize(header.num_vertices);
|
||||
|
||||
// Pour que le modèle soit correctement aligné, on génère une matrice de rotation que nous appliquerons à chacune des vertices
|
||||
NzMatrix4f rotationMatrix = NzMatrix4f::Rotate(NzEulerAnglesf(-90.f, 0.f, -90.f));
|
||||
//NzMatrix4f rotationMatrix;
|
||||
//rotationMatrix.SetIdentity();
|
||||
NzMatrix4f rotationMatrix = NzMatrix4f::Rotate(NzEulerAnglesf(90.f, -90.f, 0.f));
|
||||
|
||||
unsigned int stride = s_declaration.GetStride(nzElementStream_VertexData);
|
||||
|
||||
@@ -86,7 +84,7 @@ bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const Nz
|
||||
stream.Read(&frame.name, 16*sizeof(char));
|
||||
stream.Read(&frame.vertices[0], header.num_vertices*sizeof(md2_vertex));
|
||||
|
||||
#if NAZARA_BIG_ENDIAN
|
||||
#if defined(NAZARA_BIG_ENDIAN)
|
||||
NzByteSwap(&frame.scale.x, sizeof(float));
|
||||
NzByteSwap(&frame.scale.y, sizeof(float));
|
||||
NzByteSwap(&frame.scale.z, sizeof(float));
|
||||
@@ -98,6 +96,8 @@ bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const Nz
|
||||
|
||||
m_frames[i].normal = new nzUInt8[m_vertexCount]; // Nous stockons l'indice de la normale plutôt que la normale (gain d'espace)
|
||||
m_frames[i].vertices = new NzVector3f[m_vertexCount];
|
||||
|
||||
NzVector3f max, min;
|
||||
for (unsigned int t = 0; t < header.num_tris; ++t)
|
||||
{
|
||||
for (unsigned int v = 0; v < 3; ++v)
|
||||
@@ -105,17 +105,19 @@ bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const Nz
|
||||
const md2_vertex& vert = frame.vertices[triangles[t].vertices[v]];
|
||||
|
||||
NzVector3f vertex = rotationMatrix * NzVector3f(vert.x * frame.scale.x + frame.translate.x, vert.y * frame.scale.y + frame.translate.y, vert.z * frame.scale.z + frame.translate.z);
|
||||
max.MakeCeil(vertex);
|
||||
min.MakeFloor(vertex);
|
||||
|
||||
m_frames[i].normal[t*3+v] = vert.n;
|
||||
m_frames[i].vertices[t*3+v] = vertex;
|
||||
}
|
||||
}
|
||||
|
||||
m_frames[i].aabb.SetExtends(min, max);
|
||||
}
|
||||
|
||||
nzBufferStorage storage = (NzBuffer::IsSupported(nzBufferStorage_Hardware) && !parameters.forceSoftware) ? nzBufferStorage_Hardware : nzBufferStorage_Software;
|
||||
|
||||
m_indexBuffer = nullptr; // Pas d'indexbuffer pour l'instant
|
||||
m_vertexBuffer = new NzVertexBuffer(m_vertexCount, (3+3+2)*sizeof(float), storage, nzBufferUsage_Dynamic);
|
||||
m_vertexBuffer = new NzVertexBuffer(m_vertexCount, (3+3+2)*sizeof(float), parameters.storage, nzBufferUsage_Dynamic);
|
||||
|
||||
nzUInt8* ptr = reinterpret_cast<nzUInt8*>(m_vertexBuffer->Map(nzBufferAccess_WriteOnly));
|
||||
if (!ptr)
|
||||
@@ -185,6 +187,11 @@ void NzMD2Mesh::Destroy()
|
||||
}
|
||||
}
|
||||
|
||||
const NzAxisAlignedBox& NzMD2Mesh::GetAABB() const
|
||||
{
|
||||
return m_aabb;
|
||||
}
|
||||
|
||||
nzAnimationType NzMD2Mesh::GetAnimationType() const
|
||||
{
|
||||
if (m_frameCount > 1)
|
||||
@@ -262,14 +269,19 @@ void NzMD2Mesh::AnimateImpl(unsigned int frameA, unsigned int frameB, float inte
|
||||
NzVector3f* position = reinterpret_cast<NzVector3f*>(ptr + positionOffset);
|
||||
NzVector3f* normal = reinterpret_cast<NzVector3f*>(ptr + normalOffset);
|
||||
|
||||
*position = fA->vertices[i] + interpolation * (fB->vertices[i] - fA->vertices[i]);
|
||||
*normal = md2Normals[fA->normal[i]] + interpolation * (md2Normals[fB->normal[i]] - md2Normals[fA->normal[i]]);
|
||||
*position = fA->vertices[i] + interpolation * (fB->vertices[i] - fA->vertices[i]);
|
||||
*normal = md2Normals[fA->normal[i]] + interpolation * (md2Normals[fB->normal[i]] - md2Normals[fA->normal[i]]);
|
||||
|
||||
ptr += stride;
|
||||
}
|
||||
|
||||
if (!m_vertexBuffer->Unmap())
|
||||
NazaraWarning("Failed to unmap vertex buffer, expect mesh corruption");
|
||||
|
||||
// Interpolation de l'AABB
|
||||
NzVector3f max1 = fA->aabb.GetMaximum();
|
||||
NzVector3f min1 = fA->aabb.GetMinimum();
|
||||
m_aabb.SetExtends(min1 + interpolation * (fB->aabb.GetMinimum() - min1), max1 + interpolation * (fB->aabb.GetMaximum() - max1));
|
||||
}
|
||||
|
||||
NzVertexDeclaration NzMD2Mesh::s_declaration;
|
||||
|
||||
@@ -27,6 +27,7 @@ class NAZARA_API NzMD2Mesh : public NzKeyframeMesh
|
||||
bool Create(const md2_header& header, NzInputStream& stream, const NzMeshParams& parameters);
|
||||
void Destroy();
|
||||
|
||||
const NzAxisAlignedBox& GetAABB() const;
|
||||
nzAnimationType GetAnimationType() const;
|
||||
unsigned int GetFrameCount() const;
|
||||
const NzIndexBuffer* GetIndexBuffer() const;
|
||||
@@ -44,14 +45,14 @@ class NAZARA_API NzMD2Mesh : public NzKeyframeMesh
|
||||
|
||||
struct Frame
|
||||
{
|
||||
//AxisAlignedBox aabb;
|
||||
NzAxisAlignedBox aabb;
|
||||
nzUInt8* normal;
|
||||
NzVector3f* tangents;
|
||||
NzVector3f* vertices;
|
||||
char name[16];
|
||||
};
|
||||
|
||||
//AxisAlignedBox m_aabb;
|
||||
NzAxisAlignedBox m_aabb;
|
||||
Frame* m_frames;
|
||||
NzIndexBuffer* m_indexBuffer;
|
||||
NzVertexBuffer* m_vertexBuffer;
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
#if NAZARA_BIG_ENDIAN
|
||||
#if defined(NAZARA_BIG_ENDIAN)
|
||||
// Les fichiers PCX sont en little endian
|
||||
NzByteSwap(&header.xmin, sizeof(nzUInt16));
|
||||
NzByteSwap(&header.ymin, sizeof(nzUInt16));
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <Nazara/Utility/Mesh.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Utility/Buffer.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <Nazara/Utility/SubMesh.hpp>
|
||||
#include <cstring>
|
||||
@@ -18,6 +19,12 @@ bool NzMeshParams::IsValid() const
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!NzBuffer::IsSupported(storage))
|
||||
{
|
||||
NazaraError("Storage not supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -27,6 +34,7 @@ struct NzMeshImpl
|
||||
std::deque<NzString> skins;
|
||||
std::vector<NzSubMesh*> subMeshes;
|
||||
nzAnimationType animationType;
|
||||
NzAxisAlignedBox aabb;
|
||||
const NzAnimation* animation = nullptr;
|
||||
};
|
||||
|
||||
@@ -76,6 +84,8 @@ nzUInt8 NzMesh::AddSubMesh(NzSubMesh* subMesh)
|
||||
#endif
|
||||
|
||||
subMesh->AddResourceReference();
|
||||
|
||||
m_impl->aabb.SetNull(); // On invalide l'AABB
|
||||
m_impl->subMeshes.push_back(subMesh);
|
||||
|
||||
return m_impl->subMeshes.size()-1;
|
||||
@@ -114,6 +124,7 @@ nzUInt8 NzMesh::AddSubMesh(const NzString& identifier, NzSubMesh* subMesh)
|
||||
|
||||
subMesh->AddResourceReference();
|
||||
|
||||
m_impl->aabb.SetNull(); // On invalide l'AABB
|
||||
m_impl->subMeshes.push_back(subMesh);
|
||||
m_impl->subMeshMap[identifier] = index;
|
||||
|
||||
@@ -157,6 +168,8 @@ void NzMesh::Animate(unsigned int frameA, unsigned int frameB, float interpolati
|
||||
|
||||
for (NzSubMesh* subMesh : m_impl->subMeshes)
|
||||
subMesh->AnimateImpl(frameA, frameB, interpolation);
|
||||
|
||||
m_impl->aabb.SetNull(); // On invalide l'AABB
|
||||
}
|
||||
|
||||
bool NzMesh::Create(nzAnimationType type)
|
||||
@@ -184,6 +197,25 @@ void NzMesh::Destroy()
|
||||
}
|
||||
}
|
||||
|
||||
const NzAxisAlignedBox& NzMesh::GetAABB() const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Mesh not created");
|
||||
return NzAxisAlignedBox::Null;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (m_impl->aabb.IsNull())
|
||||
{
|
||||
for (NzSubMesh* subMesh : m_impl->subMeshes)
|
||||
m_impl->aabb.ExtendTo(subMesh->GetAABB());
|
||||
}
|
||||
|
||||
return m_impl->aabb;
|
||||
}
|
||||
|
||||
const NzAnimation* NzMesh::GetAnimation() const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
@@ -373,6 +405,19 @@ unsigned int NzMesh::GetVertexCount() const
|
||||
return vertexCount;
|
||||
}
|
||||
|
||||
void NzMesh::InvalidateAABB() const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Mesh not created");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
m_impl->aabb.SetNull();
|
||||
}
|
||||
|
||||
bool NzMesh::HasAnimation() const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
@@ -505,6 +550,8 @@ void NzMesh::RemoveSubMesh(const NzString& identifier)
|
||||
std::advance(it2, index);
|
||||
|
||||
m_impl->subMeshes.erase(it2);
|
||||
|
||||
m_impl->aabb.SetNull(); // On invalide l'AABB
|
||||
}
|
||||
|
||||
void NzMesh::RemoveSubMesh(nzUInt8 index)
|
||||
@@ -527,6 +574,8 @@ void NzMesh::RemoveSubMesh(nzUInt8 index)
|
||||
std::advance(it, index);
|
||||
|
||||
m_impl->subMeshes.erase(it);
|
||||
|
||||
m_impl->aabb.SetNull(); // On invalide l'AABB
|
||||
}
|
||||
|
||||
bool NzMesh::SetAnimation(const NzAnimation* animation)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Utility/Mouse.hpp>
|
||||
#include <Nazara/Utility/Window.hpp>
|
||||
|
||||
#if defined(NAZARA_PLATFORM_WINDOWS)
|
||||
#include <Nazara/Utility/Win32/InputImpl.hpp>
|
||||
@@ -36,6 +37,9 @@ void NzMouse::SetPosition(const NzVector2i& position)
|
||||
|
||||
void NzMouse::SetPosition(const NzVector2i& position, const NzWindow& relativeTo)
|
||||
{
|
||||
if (position.x > 0 && position.y > 0)
|
||||
relativeTo.IgnoreNextMouseEvent(position.x, position.y);
|
||||
|
||||
NzEventImpl::SetMousePosition(position.x, position.y, relativeTo);
|
||||
}
|
||||
|
||||
@@ -46,5 +50,8 @@ void NzMouse::SetPosition(int x, int y)
|
||||
|
||||
void NzMouse::SetPosition(int x, int y, const NzWindow& relativeTo)
|
||||
{
|
||||
if (x > 0 && y > 0)
|
||||
relativeTo.IgnoreNextMouseEvent(x, y);
|
||||
|
||||
NzEventImpl::SetMousePosition(x, y, relativeTo);
|
||||
}
|
||||
|
||||
@@ -1320,5 +1320,5 @@ void NzPixelFormat::Uninitialize()
|
||||
s_flipFunctions[i].clear();
|
||||
}
|
||||
|
||||
NzPixelFormat::ConvertFunction NzPixelFormat::s_convertFunctions[nzPixelFormat_Max+1][nzPixelFormat_Max+1] = {{0}}; ///FIXME: Fonctionne correctement ?
|
||||
NzPixelFormat::ConvertFunction NzPixelFormat::s_convertFunctions[nzPixelFormat_Max+1][nzPixelFormat_Max+1] = {{nullptr}}; ///FIXME: Fonctionne correctement ?
|
||||
std::map<nzPixelFormat, NzPixelFormat::FlipFunction> NzPixelFormat::s_flipFunctions[nzPixelFlipping_Max+1];
|
||||
|
||||
@@ -12,17 +12,17 @@ NzSubMesh(parent)
|
||||
{
|
||||
}
|
||||
|
||||
NzStaticMesh::NzStaticMesh(const NzMesh* parent, const NzVertexBuffer* vertexBuffer, const NzVertexDeclaration* vertexDeclaration, const NzIndexBuffer* indexBuffer) :
|
||||
NzStaticMesh::NzStaticMesh(const NzMesh* parent, const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer) :
|
||||
NzSubMesh(parent)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (!Create(vertexBuffer, vertexDeclaration, indexBuffer))
|
||||
if (!Create(vertexDeclaration, vertexBuffer, indexBuffer))
|
||||
{
|
||||
NazaraError("Failed to create mesh");
|
||||
throw std::runtime_error("Constructor failed");
|
||||
}
|
||||
#else
|
||||
Create(vertexBuffer, vertexDeclaration, indexBuffer);
|
||||
Create(vertexDeclaration, vertexBuffer, indexBuffer);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -31,22 +31,22 @@ NzStaticMesh::~NzStaticMesh()
|
||||
Destroy();
|
||||
}
|
||||
|
||||
bool NzStaticMesh::Create(const NzVertexBuffer* vertexBuffer, const NzVertexDeclaration* vertexDeclaration, const NzIndexBuffer* indexBuffer)
|
||||
bool NzStaticMesh::Create(const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer)
|
||||
{
|
||||
Destroy();
|
||||
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!vertexBuffer)
|
||||
{
|
||||
NazaraError("Vertex buffer is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!vertexDeclaration)
|
||||
{
|
||||
NazaraError("Vertex declaration is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!vertexBuffer)
|
||||
{
|
||||
NazaraError("Vertex buffer is null");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (indexBuffer)
|
||||
@@ -66,6 +66,8 @@ bool NzStaticMesh::Create(const NzVertexBuffer* vertexBuffer, const NzVertexDecl
|
||||
|
||||
void NzStaticMesh::Destroy()
|
||||
{
|
||||
m_aabb.SetNull();
|
||||
|
||||
if (m_indexBuffer)
|
||||
{
|
||||
m_indexBuffer->RemoveResourceReference();
|
||||
@@ -85,6 +87,44 @@ void NzStaticMesh::Destroy()
|
||||
}
|
||||
}
|
||||
|
||||
bool NzStaticMesh::GenerateAABB()
|
||||
{
|
||||
if (!m_aabb.IsNull())
|
||||
return true;
|
||||
|
||||
const NzVertexElement* position = m_vertexDeclaration->GetElement(nzElementStream_VertexData, nzElementUsage_Position);
|
||||
if (position && position->type == nzElementType_Float3) // Si nous avons des positions du type Vec3
|
||||
{
|
||||
// On lock le buffer pour itérer sur toutes les positions et composer notre AABB
|
||||
nzUInt8* buffer = reinterpret_cast<nzUInt8*>(m_vertexBuffer->Map(nzBufferAccess_ReadOnly));
|
||||
if (!buffer)
|
||||
{
|
||||
NazaraWarning("Failed to lock vertex buffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
buffer += position->offset;
|
||||
unsigned int stride = m_vertexDeclaration->GetStride(nzElementStream_VertexData);
|
||||
unsigned int vertexCount = m_vertexBuffer->GetVertexCount();
|
||||
for (unsigned int i = 0; i < vertexCount; ++i)
|
||||
{
|
||||
m_aabb.ExtendTo(*reinterpret_cast<NzVector3f*>(buffer));
|
||||
|
||||
buffer += stride;
|
||||
}
|
||||
|
||||
if (!m_vertexBuffer->Unmap())
|
||||
NazaraWarning("Failed to unmap vertex buffer");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const NzAxisAlignedBox& NzStaticMesh::GetAABB() const
|
||||
{
|
||||
return m_aabb;
|
||||
}
|
||||
|
||||
nzAnimationType NzStaticMesh::GetAnimationType() const
|
||||
{
|
||||
return nzAnimationType_Static;
|
||||
@@ -125,6 +165,11 @@ bool NzStaticMesh::IsValid() const
|
||||
return m_vertexBuffer != nullptr && m_vertexDeclaration != nullptr;
|
||||
}
|
||||
|
||||
void NzStaticMesh::SetAABB(const NzAxisAlignedBox& aabb)
|
||||
{
|
||||
m_aabb = aabb;
|
||||
}
|
||||
|
||||
void NzStaticMesh::SetPrimitiveType(nzPrimitiveType primitiveType)
|
||||
{
|
||||
m_primitiveType = primitiveType;
|
||||
|
||||
@@ -14,7 +14,7 @@ NzSubMesh::NzSubMesh(const NzMesh* parent) :
|
||||
NzResource(false), // Un SubMesh n'est pas persistant par défaut
|
||||
m_parent(parent)
|
||||
{
|
||||
#if NAZARA_DEBUG
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (!m_parent)
|
||||
{
|
||||
NazaraError("Parent mesh is null");
|
||||
@@ -55,6 +55,8 @@ void NzSubMesh::Animate(unsigned int frameA, unsigned int frameB, float interpol
|
||||
#endif
|
||||
|
||||
AnimateImpl(frameA, frameB, interpolation);
|
||||
|
||||
m_parent->InvalidateAABB();
|
||||
}
|
||||
|
||||
const NzMesh* NzSubMesh::GetParent() const
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Utility/Utility.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Utility/Buffer.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <Nazara/Utility/Loaders/MD2.hpp>
|
||||
@@ -13,26 +15,19 @@
|
||||
#include <Nazara/Utility/Window.hpp>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
NzUtility::NzUtility()
|
||||
{
|
||||
}
|
||||
|
||||
NzUtility::~NzUtility()
|
||||
{
|
||||
if (s_initialized)
|
||||
Uninitialize();
|
||||
}
|
||||
|
||||
bool NzUtility::Initialize()
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (s_initialized)
|
||||
{
|
||||
NazaraError("Renderer already initialized");
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
if (s_moduleReferenceCouter++ != 0)
|
||||
return true; // Déjà initialisé
|
||||
|
||||
// Initialisation des dépendances
|
||||
if (!NzCore::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize core module");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Initialisation du module
|
||||
if (!NzBuffer::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize buffers");
|
||||
@@ -64,21 +59,22 @@ bool NzUtility::Initialize()
|
||||
// Image
|
||||
NzLoaders_STB_Register(); // Loader générique (STB)
|
||||
|
||||
s_initialized = true;
|
||||
NazaraNotice("Initialized: Utility module");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzUtility::IsInitialized()
|
||||
{
|
||||
return s_moduleReferenceCouter != 0;
|
||||
}
|
||||
|
||||
void NzUtility::Uninitialize()
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!s_initialized)
|
||||
{
|
||||
NazaraError("Utility not initialized");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (--s_moduleReferenceCouter != 0)
|
||||
return; // Encore utilisé
|
||||
|
||||
// Libération du module
|
||||
NzLoaders_MD2_Unregister();
|
||||
NzLoaders_PCX_Unregister();
|
||||
NzLoaders_STB_Unregister();
|
||||
@@ -87,12 +83,11 @@ void NzUtility::Uninitialize()
|
||||
NzPixelFormat::Uninitialize();
|
||||
NzBuffer::Uninitialize();
|
||||
|
||||
s_initialized = false;
|
||||
NazaraNotice("Uninitialized: Utility module");
|
||||
|
||||
// Libération des dépendances
|
||||
NzCore::Uninitialize();
|
||||
}
|
||||
|
||||
bool NzUtility::IsInitialized()
|
||||
{
|
||||
return s_initialized;
|
||||
}
|
||||
unsigned int NzUtility::s_moduleReferenceCouter = 0;
|
||||
|
||||
bool NzUtility::s_initialized = false;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
#if NAZARA_THREADSAFETY_VERTEXDECLARATION
|
||||
#if NAZARA_UTILITY_THREADSAFE && NAZARA_THREADSAFETY_VERTEXDECLARATION
|
||||
#include <Nazara/Core/ThreadSafety.hpp>
|
||||
#else
|
||||
#include <Nazara/Core/ThreadSafetyOff.hpp>
|
||||
@@ -22,15 +22,15 @@ namespace
|
||||
{
|
||||
const unsigned int size[] =
|
||||
{
|
||||
4, // nzElementType_Color
|
||||
8, // nzElementType_Double1
|
||||
16, // nzElementType_Double2
|
||||
24, // nzElementType_Double3
|
||||
32, // nzElementType_Double4
|
||||
4, // nzElementType_Float1
|
||||
8, // nzElementType_Float2
|
||||
12, // nzElementType_Float3
|
||||
16 // nzElementType_Float4
|
||||
sizeof(nzUInt32), // nzElementType_Color
|
||||
1*sizeof(double), // nzElementType_Double1
|
||||
2*sizeof(double), // nzElementType_Double2
|
||||
3*sizeof(double), // nzElementType_Double3
|
||||
4*sizeof(double), // nzElementType_Double4
|
||||
1*sizeof(float), // nzElementType_Float1
|
||||
2*sizeof(float), // nzElementType_Float2
|
||||
3*sizeof(float), // nzElementType_Float3
|
||||
4*sizeof(float) // nzElementType_Float4
|
||||
};
|
||||
|
||||
bool VertexElementCompare(const NzVertexElement& elementA, const NzVertexElement& elementB)
|
||||
@@ -57,7 +57,7 @@ struct NzVertexDeclarationImpl
|
||||
int streamPos[nzElementStream_Max+1];
|
||||
unsigned int stride[nzElementStream_Max+1] = {0};
|
||||
|
||||
unsigned short refCount;
|
||||
unsigned short refCount = 1;
|
||||
NazaraMutex(mutex)
|
||||
};
|
||||
|
||||
@@ -86,7 +86,7 @@ m_sharedImpl(declaration.m_sharedImpl)
|
||||
}
|
||||
}
|
||||
|
||||
NzVertexDeclaration::NzVertexDeclaration(NzVertexDeclaration&& declaration) :
|
||||
NzVertexDeclaration::NzVertexDeclaration(NzVertexDeclaration&& declaration) noexcept :
|
||||
m_sharedImpl(declaration.m_sharedImpl)
|
||||
{
|
||||
declaration.m_sharedImpl = nullptr;
|
||||
@@ -146,7 +146,7 @@ bool NzVertexDeclaration::Create(const NzVertexElement* elements, unsigned int e
|
||||
impl->stride[current.stream] += size[current.type];
|
||||
}
|
||||
|
||||
#if NAZARA_RENDERER_FORCE_DECLARATION_STRIDE_MULTIPLE_OF_32
|
||||
#if NAZARA_UTILITY_FORCE_DECLARATION_STRIDE_MULTIPLE_OF_32
|
||||
for (unsigned int& stride : impl->stride)
|
||||
stride = ((static_cast<int>(stride)-1)/32+1)*32;
|
||||
#endif
|
||||
@@ -335,7 +335,7 @@ NzVertexDeclaration& NzVertexDeclaration::operator=(const NzVertexDeclaration& d
|
||||
return *this;
|
||||
}
|
||||
|
||||
NzVertexDeclaration& NzVertexDeclaration::operator=(NzVertexDeclaration&& declaration)
|
||||
NzVertexDeclaration& NzVertexDeclaration::operator=(NzVertexDeclaration&& declaration) noexcept
|
||||
{
|
||||
Destroy();
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ bool NzEventImpl::IsKeyPressed(NzKeyboard::Key key)
|
||||
|
||||
bool NzEventImpl::IsMouseButtonPressed(NzMouse::Button button)
|
||||
{
|
||||
static int vButtons[NzMouse::Count] = {
|
||||
static int vButtons[NzMouse::Max+1] = {
|
||||
VK_LBUTTON, // Button::Left
|
||||
VK_MBUTTON, // Button::Middle
|
||||
VK_RBUTTON, // Button::Right
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
#define OEMRESOURCE
|
||||
|
||||
#include <Nazara/Utility/Win32/WindowImpl.hpp>
|
||||
#include <Nazara/Core/ConditionVariable.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Mutex.hpp>
|
||||
#include <Nazara/Core/Thread.hpp>
|
||||
#include <Nazara/Core/ThreadCondition.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <Nazara/Utility/Cursor.hpp>
|
||||
#include <Nazara/Utility/Image.hpp>
|
||||
@@ -53,28 +53,6 @@ m_scrolling(0)
|
||||
{
|
||||
}
|
||||
|
||||
void NzWindowImpl::Close()
|
||||
{
|
||||
if (m_ownsWindow)
|
||||
{
|
||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||
if (m_thread)
|
||||
{
|
||||
m_threadActive = false;
|
||||
PostMessageW(m_handle, WM_NULL, 0, 0); // Pour réveiller le thread
|
||||
|
||||
m_thread->Join();
|
||||
delete m_thread;
|
||||
}
|
||||
#else
|
||||
if (m_handle)
|
||||
DestroyWindow(m_handle);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
SetEventListener(false);
|
||||
}
|
||||
|
||||
bool NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 style)
|
||||
{
|
||||
bool fullscreen = (style & nzWindowStyle_Fullscreen) != 0;
|
||||
@@ -99,6 +77,7 @@ bool NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 styl
|
||||
}
|
||||
}
|
||||
|
||||
// Testé une seconde fois car sa valeur peut changer
|
||||
if (fullscreen)
|
||||
{
|
||||
x = 0;
|
||||
@@ -143,7 +122,7 @@ bool NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 styl
|
||||
|
||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||
NzMutex mutex;
|
||||
NzThreadCondition condition;
|
||||
NzConditionVariable condition;
|
||||
m_thread = new NzThread(WindowThread, &m_handle, win32StyleEx, wtitle, win32Style, x, y, width, height, this, &mutex, &condition);
|
||||
m_threadActive = true;
|
||||
|
||||
@@ -166,6 +145,9 @@ bool NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 styl
|
||||
|
||||
m_eventListener = true;
|
||||
m_ownsWindow = true;
|
||||
#if !NAZARA_UTILITY_THREADED_WINDOW
|
||||
m_sizemove = false;
|
||||
#endif
|
||||
|
||||
return m_handle != nullptr;
|
||||
}
|
||||
@@ -181,10 +163,35 @@ bool NzWindowImpl::Create(NzWindowHandle handle)
|
||||
m_handle = reinterpret_cast<HWND>(handle);
|
||||
m_eventListener = false;
|
||||
m_ownsWindow = false;
|
||||
#if !NAZARA_UTILITY_THREADED_WINDOW
|
||||
m_sizemove = false;
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzWindowImpl::Destroy()
|
||||
{
|
||||
if (m_ownsWindow)
|
||||
{
|
||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||
if (m_thread)
|
||||
{
|
||||
m_threadActive = false;
|
||||
PostMessageW(m_handle, WM_NULL, 0, 0); // Pour réveiller le thread
|
||||
|
||||
m_thread->Join();
|
||||
delete m_thread;
|
||||
}
|
||||
#else
|
||||
if (m_handle)
|
||||
DestroyWindow(m_handle);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
SetEventListener(false);
|
||||
}
|
||||
|
||||
void NzWindowImpl::EnableKeyRepeat(bool enable)
|
||||
{
|
||||
m_keyRepeat = enable;
|
||||
@@ -267,6 +274,13 @@ void NzWindowImpl::ProcessEvents(bool block)
|
||||
}
|
||||
}
|
||||
|
||||
void NzWindowImpl::IgnoreNextMouseEvent(int mouseX, int mouseY)
|
||||
{
|
||||
// Petite astuce ...
|
||||
m_mousePos.x = mouseX;
|
||||
m_mousePos.y = mouseY;
|
||||
}
|
||||
|
||||
bool NzWindowImpl::IsMinimized() const
|
||||
{
|
||||
return IsIconic(m_handle);
|
||||
@@ -317,12 +331,12 @@ void NzWindowImpl::SetCursor(nzWindowCursor cursor)
|
||||
|
||||
case nzWindowCursor_ResizeNW:
|
||||
case nzWindowCursor_ResizeSE:
|
||||
m_cursor = reinterpret_cast<HCURSOR>(LoadImage(nullptr, IDC_SIZENESW, IMAGE_CURSOR, 0, 0, LR_SHARED));
|
||||
m_cursor = reinterpret_cast<HCURSOR>(LoadImage(nullptr, IDC_SIZENWSE, IMAGE_CURSOR, 0, 0, LR_SHARED));
|
||||
break;
|
||||
|
||||
case nzWindowCursor_ResizeNE:
|
||||
case nzWindowCursor_ResizeSW:
|
||||
m_cursor = reinterpret_cast<HCURSOR>(LoadImage(nullptr, IDC_SIZENWSE, IMAGE_CURSOR, 0, 0, LR_SHARED));
|
||||
m_cursor = reinterpret_cast<HCURSOR>(LoadImage(nullptr, IDC_SIZENESW, IMAGE_CURSOR, 0, 0, LR_SHARED));
|
||||
break;
|
||||
|
||||
case nzWindowCursor_ResizeE:
|
||||
@@ -418,7 +432,7 @@ void NzWindowImpl::SetMinimumSize(int width, int height)
|
||||
|
||||
void NzWindowImpl::SetPosition(int x, int y)
|
||||
{
|
||||
SetWindowPos(m_handle, 0, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
|
||||
SetWindowPos(m_handle, nullptr, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
|
||||
}
|
||||
|
||||
void NzWindowImpl::SetSize(unsigned int width, unsigned int height)
|
||||
@@ -427,7 +441,15 @@ void NzWindowImpl::SetSize(unsigned int width, unsigned int height)
|
||||
RECT rect = {0, 0, static_cast<LONG>(width), static_cast<LONG>(height)};
|
||||
AdjustWindowRect(&rect, GetWindowLongPtr(m_handle, GWL_STYLE), false);
|
||||
|
||||
SetWindowPos(m_handle, 0, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE | SWP_NOZORDER);
|
||||
SetWindowPos(m_handle, nullptr, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE | SWP_NOZORDER);
|
||||
}
|
||||
|
||||
void NzWindowImpl::SetStayOnTop(bool stayOnTop)
|
||||
{
|
||||
if (stayOnTop)
|
||||
SetWindowPos(m_handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
|
||||
else
|
||||
SetWindowPos(m_handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
|
||||
}
|
||||
|
||||
void NzWindowImpl::SetTitle(const NzString& title)
|
||||
@@ -442,11 +464,6 @@ void NzWindowImpl::SetVisible(bool visible)
|
||||
ShowWindow(m_handle, (visible) ? SW_SHOW : SW_HIDE);
|
||||
}
|
||||
|
||||
void NzWindowImpl::StayOnTop(bool stayOnTop)
|
||||
{
|
||||
SetWindowPos(m_handle, (stayOnTop) ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
|
||||
}
|
||||
|
||||
bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
// Inutile de récupérer des évènements ne venant pas de notre fenêtre
|
||||
@@ -495,11 +512,13 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||
case WM_CHAR:
|
||||
{
|
||||
// http://msdn.microsoft.com/en-us/library/ms646267(VS.85).aspx
|
||||
if (m_keyRepeat || (HIWORD(lParam) & KF_REPEAT) == 0)
|
||||
bool repeated = ((HIWORD(lParam) & KF_REPEAT) != 0);
|
||||
if (m_keyRepeat || !repeated)
|
||||
{
|
||||
NzEvent event;
|
||||
event.type = NzEvent::TextEntered;
|
||||
event.text.character = static_cast<nzUInt32>(wParam);
|
||||
event.type = nzEventType_TextEntered;
|
||||
event.text.character = static_cast<char32_t>(wParam);
|
||||
event.text.repeated = repeated;
|
||||
m_parent->PushEvent(event);
|
||||
}
|
||||
|
||||
@@ -509,65 +528,64 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||
case WM_CLOSE:
|
||||
{
|
||||
NzEvent event;
|
||||
event.type = NzEvent::Quit;
|
||||
event.type = nzEventType_Quit;
|
||||
m_parent->PushEvent(event);
|
||||
|
||||
return true; // Afin que Windows ne ferme pas la fenêtre automatiquement
|
||||
}
|
||||
|
||||
case WM_LBUTTONDBLCLK:
|
||||
#if !NAZARA_UTILITY_THREADED_WINDOW
|
||||
case WM_ENTERSIZEMOVE:
|
||||
{
|
||||
// Cet évènement est généré à la place d'un WM_LBUTTONDOWN lors d'un double-clic.
|
||||
// Comme nous désirons quand même notifier chaque clic, nous envoyons les deux évènements.
|
||||
NzEvent event;
|
||||
event.mouseButton.button = NzMouse::Left;
|
||||
event.mouseButton.x = GET_X_LPARAM(lParam);
|
||||
event.mouseButton.y = GET_Y_LPARAM(lParam);
|
||||
|
||||
event.type = NzEvent::MouseButtonDoubleClicked;
|
||||
m_parent->PushEvent(event);
|
||||
|
||||
event.type = NzEvent::MouseButtonPressed;
|
||||
m_parent->PushEvent(event);
|
||||
|
||||
m_sizemove = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_LBUTTONDOWN:
|
||||
case WM_EXITSIZEMOVE:
|
||||
{
|
||||
NzEvent event;
|
||||
event.type = NzEvent::MouseButtonPressed;
|
||||
event.mouseButton.button = NzMouse::Left;
|
||||
event.mouseButton.x = GET_X_LPARAM(lParam);
|
||||
event.mouseButton.y = GET_Y_LPARAM(lParam);
|
||||
m_parent->PushEvent(event);
|
||||
m_sizemove = false;
|
||||
|
||||
break;
|
||||
// On vérifie ce qui a changé
|
||||
NzVector2i position = GetPosition();
|
||||
if (m_position != position)
|
||||
{
|
||||
m_position = position;
|
||||
|
||||
NzEvent event;
|
||||
event.type = nzEventType_Moved;
|
||||
event.position.x = position.x;
|
||||
event.position.y = position.y;
|
||||
m_parent->PushEvent(event);
|
||||
}
|
||||
|
||||
NzVector2ui size = GetSize();
|
||||
if (m_size != size)
|
||||
{
|
||||
m_size = size;
|
||||
|
||||
NzEvent event;
|
||||
event.type = nzEventType_Resized;
|
||||
event.size.width = size.x;
|
||||
event.size.height = size.y;
|
||||
m_parent->PushEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
case WM_LBUTTONUP:
|
||||
{
|
||||
NzEvent event;
|
||||
event.type = NzEvent::MouseButtonReleased;
|
||||
event.mouseButton.button = NzMouse::Left;
|
||||
event.mouseButton.x = GET_X_LPARAM(lParam);
|
||||
event.mouseButton.y = GET_Y_LPARAM(lParam);
|
||||
m_parent->PushEvent(event);
|
||||
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
case WM_KEYDOWN:
|
||||
case WM_SYSKEYDOWN:
|
||||
{
|
||||
// http://msdn.microsoft.com/en-us/library/ms646267(VS.85).aspx
|
||||
if (m_keyRepeat || (HIWORD(lParam) & KF_REPEAT) == 0)
|
||||
bool repeated = ((HIWORD(lParam) & KF_REPEAT) != 0);
|
||||
if (m_keyRepeat || !repeated)
|
||||
{
|
||||
NzEvent event;
|
||||
event.type = NzEvent::KeyPressed;
|
||||
event.type = nzEventType_KeyPressed;
|
||||
event.key.code = ConvertVirtualKey(wParam, lParam);
|
||||
event.key.alt = ((GetAsyncKeyState(VK_MENU) & 0x8000) != 0);
|
||||
event.key.control = ((GetAsyncKeyState(VK_CONTROL) & 0x8000) != 0);
|
||||
event.key.repeated = repeated;
|
||||
event.key.shift = ((GetAsyncKeyState(VK_SHIFT) & 0x8000) != 0);
|
||||
event.key.system = (((GetAsyncKeyState(VK_LWIN) & 0x8000) != 0) || ((GetAsyncKeyState(VK_RWIN) & 0x8000) != 0));
|
||||
m_parent->PushEvent(event);
|
||||
@@ -581,7 +599,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||
{
|
||||
// http://msdn.microsoft.com/en-us/library/ms646267(VS.85).aspx
|
||||
NzEvent event;
|
||||
event.type = NzEvent::KeyReleased;
|
||||
event.type = nzEventType_KeyReleased;
|
||||
event.key.code = ConvertVirtualKey(wParam, lParam);
|
||||
event.key.alt = ((GetAsyncKeyState(VK_MENU) & 0x8000) != 0);
|
||||
event.key.control = ((GetAsyncKeyState(VK_CONTROL) & 0x8000) != 0);
|
||||
@@ -595,7 +613,49 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||
case WM_KILLFOCUS:
|
||||
{
|
||||
NzEvent event;
|
||||
event.type = NzEvent::LostFocus;
|
||||
event.type = nzEventType_LostFocus;
|
||||
m_parent->PushEvent(event);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_LBUTTONDBLCLK:
|
||||
{
|
||||
// Cet évènement est généré à la place d'un WM_LBUTTONDOWN lors d'un double-clic.
|
||||
// Comme nous désirons quand même notifier chaque clic, nous envoyons les deux évènements.
|
||||
NzEvent event;
|
||||
event.mouseButton.button = NzMouse::Left;
|
||||
event.mouseButton.x = GET_X_LPARAM(lParam);
|
||||
event.mouseButton.y = GET_Y_LPARAM(lParam);
|
||||
|
||||
event.type = nzEventType_MouseButtonDoubleClicked;
|
||||
m_parent->PushEvent(event);
|
||||
|
||||
event.type = nzEventType_MouseButtonPressed;
|
||||
m_parent->PushEvent(event);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_LBUTTONDOWN:
|
||||
{
|
||||
NzEvent event;
|
||||
event.type = nzEventType_MouseButtonPressed;
|
||||
event.mouseButton.button = NzMouse::Left;
|
||||
event.mouseButton.x = GET_X_LPARAM(lParam);
|
||||
event.mouseButton.y = GET_Y_LPARAM(lParam);
|
||||
m_parent->PushEvent(event);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_LBUTTONUP:
|
||||
{
|
||||
NzEvent event;
|
||||
event.type = nzEventType_MouseButtonReleased;
|
||||
event.mouseButton.button = NzMouse::Left;
|
||||
event.mouseButton.x = GET_X_LPARAM(lParam);
|
||||
event.mouseButton.y = GET_Y_LPARAM(lParam);
|
||||
m_parent->PushEvent(event);
|
||||
|
||||
break;
|
||||
@@ -608,10 +668,10 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||
event.mouseButton.x = GET_X_LPARAM(lParam);
|
||||
event.mouseButton.y = GET_Y_LPARAM(lParam);
|
||||
|
||||
event.type = NzEvent::MouseButtonDoubleClicked;
|
||||
event.type = nzEventType_MouseButtonDoubleClicked;
|
||||
m_parent->PushEvent(event);
|
||||
|
||||
event.type = NzEvent::MouseButtonPressed;
|
||||
event.type = nzEventType_MouseButtonPressed;
|
||||
m_parent->PushEvent(event);
|
||||
|
||||
break;
|
||||
@@ -620,7 +680,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||
case WM_MBUTTONDOWN:
|
||||
{
|
||||
NzEvent event;
|
||||
event.type = NzEvent::MouseButtonPressed;
|
||||
event.type = nzEventType_MouseButtonPressed;
|
||||
event.mouseButton.button = NzMouse::Middle;
|
||||
event.mouseButton.x = GET_X_LPARAM(lParam);
|
||||
event.mouseButton.y = GET_Y_LPARAM(lParam);
|
||||
@@ -632,7 +692,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||
case WM_MBUTTONUP:
|
||||
{
|
||||
NzEvent event;
|
||||
event.type = NzEvent::MouseButtonReleased;
|
||||
event.type = nzEventType_MouseButtonReleased;
|
||||
event.mouseButton.button = NzMouse::Middle;
|
||||
event.mouseButton.x = GET_X_LPARAM(lParam);
|
||||
event.mouseButton.y = GET_Y_LPARAM(lParam);
|
||||
@@ -648,13 +708,16 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||
m_mouseInside = false;
|
||||
|
||||
NzEvent event;
|
||||
event.type = NzEvent::MouseLeft;
|
||||
event.type = nzEventType_MouseLeft;
|
||||
m_parent->PushEvent(event);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_MOUSEMOVE:
|
||||
{
|
||||
int currentX = GET_X_LPARAM(lParam);
|
||||
int currentY = GET_Y_LPARAM(lParam);
|
||||
|
||||
if (!m_mouseInside)
|
||||
{
|
||||
m_mouseInside = true;
|
||||
@@ -667,14 +730,37 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||
TrackMouseEvent(&mouseEvent);
|
||||
|
||||
NzEvent event;
|
||||
event.type = NzEvent::MouseEntered;
|
||||
event.type = nzEventType_MouseEntered;
|
||||
m_parent->PushEvent(event);
|
||||
|
||||
event.type = nzEventType_MouseMoved;
|
||||
|
||||
// Le delta sera 0
|
||||
event.mouseMove.deltaX = 0;
|
||||
event.mouseMove.deltaY = 0;
|
||||
|
||||
event.mouseMove.x = currentX;
|
||||
event.mouseMove.y = currentY;
|
||||
|
||||
m_mousePos.x = currentX;
|
||||
m_mousePos.y = currentY;
|
||||
|
||||
m_parent->PushEvent(event);
|
||||
break;
|
||||
}
|
||||
else if (m_mousePos.x == currentX && m_mousePos.y == currentY)
|
||||
break;
|
||||
|
||||
NzEvent event;
|
||||
event.type = NzEvent::MouseMoved;
|
||||
event.mouseMove.x = GET_X_LPARAM(lParam);
|
||||
event.mouseMove.y = GET_Y_LPARAM(lParam);
|
||||
event.type = nzEventType_MouseMoved;
|
||||
event.mouseMove.deltaX = currentX - m_mousePos.x;
|
||||
event.mouseMove.deltaY = currentY - m_mousePos.y;
|
||||
event.mouseMove.x = currentX;
|
||||
event.mouseMove.y = currentY;
|
||||
|
||||
m_mousePos.x = currentX;
|
||||
m_mousePos.y = currentY;
|
||||
|
||||
m_parent->PushEvent(event);
|
||||
break;
|
||||
}
|
||||
@@ -684,7 +770,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||
if (m_smoothScrolling)
|
||||
{
|
||||
NzEvent event;
|
||||
event.type = NzEvent::MouseWheelMoved;
|
||||
event.type = nzEventType_MouseWheelMoved;
|
||||
event.mouseWheel.delta = static_cast<float>(GET_WHEEL_DELTA_WPARAM(wParam))/WHEEL_DELTA;
|
||||
m_parent->PushEvent(event);
|
||||
}
|
||||
@@ -694,7 +780,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||
if (std::abs(m_scrolling) >= WHEEL_DELTA)
|
||||
{
|
||||
NzEvent event;
|
||||
event.type = NzEvent::MouseWheelMoved;
|
||||
event.type = nzEventType_MouseWheelMoved;
|
||||
event.mouseWheel.delta = m_scrolling/WHEEL_DELTA;
|
||||
m_parent->PushEvent(event);
|
||||
|
||||
@@ -709,7 +795,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||
NzVector2i position = GetPosition();
|
||||
|
||||
NzEvent event;
|
||||
event.type = NzEvent::Moved;
|
||||
event.type = nzEventType_Moved;
|
||||
event.position.x = position.x;
|
||||
event.position.y = position.y;
|
||||
m_parent->PushEvent(event);
|
||||
@@ -724,10 +810,10 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||
event.mouseButton.x = GET_X_LPARAM(lParam);
|
||||
event.mouseButton.y = GET_Y_LPARAM(lParam);
|
||||
|
||||
event.type = NzEvent::MouseButtonDoubleClicked;
|
||||
event.type = nzEventType_MouseButtonDoubleClicked;
|
||||
m_parent->PushEvent(event);
|
||||
|
||||
event.type = NzEvent::MouseButtonPressed;
|
||||
event.type = nzEventType_MouseButtonPressed;
|
||||
m_parent->PushEvent(event);
|
||||
|
||||
break;
|
||||
@@ -736,7 +822,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||
case WM_RBUTTONDOWN:
|
||||
{
|
||||
NzEvent event;
|
||||
event.type = NzEvent::MouseButtonPressed;
|
||||
event.type = nzEventType_MouseButtonPressed;
|
||||
event.mouseButton.button = NzMouse::Right;
|
||||
event.mouseButton.x = GET_X_LPARAM(lParam);
|
||||
event.mouseButton.y = GET_Y_LPARAM(lParam);
|
||||
@@ -748,7 +834,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||
case WM_RBUTTONUP:
|
||||
{
|
||||
NzEvent event;
|
||||
event.type = NzEvent::MouseButtonReleased;
|
||||
event.type = nzEventType_MouseButtonReleased;
|
||||
event.mouseButton.button = NzMouse::Right;
|
||||
event.mouseButton.x = GET_X_LPARAM(lParam);
|
||||
event.mouseButton.y = GET_Y_LPARAM(lParam);
|
||||
@@ -760,7 +846,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||
case WM_SETFOCUS:
|
||||
{
|
||||
NzEvent event;
|
||||
event.type = NzEvent::GainedFocus;
|
||||
event.type = nzEventType_GainedFocus;
|
||||
m_parent->PushEvent(event);
|
||||
|
||||
break;
|
||||
@@ -768,12 +854,22 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||
|
||||
case WM_SIZE:
|
||||
{
|
||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||
if (wParam != SIZE_MINIMIZED)
|
||||
#else
|
||||
if (!m_sizemove && wParam != SIZE_MINIMIZED)
|
||||
#endif
|
||||
{
|
||||
NzVector2ui size = GetSize(); // On récupère uniquement la taille de la zone client
|
||||
#if !NAZARA_UTILITY_THREADED_WINDOW
|
||||
if (m_size == size)
|
||||
break;
|
||||
|
||||
m_size = size;
|
||||
#endif
|
||||
|
||||
NzEvent event;
|
||||
event.type = NzEvent::Resized;
|
||||
event.type = nzEventType_Resized;
|
||||
event.size.width = size.x;
|
||||
event.size.height = size.y;
|
||||
m_parent->PushEvent(event);
|
||||
@@ -792,10 +888,10 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||
event.mouseButton.x = GET_X_LPARAM(lParam);
|
||||
event.mouseButton.y = GET_Y_LPARAM(lParam);
|
||||
|
||||
event.type = NzEvent::MouseButtonDoubleClicked;
|
||||
event.type = nzEventType_MouseButtonDoubleClicked;
|
||||
m_parent->PushEvent(event);
|
||||
|
||||
event.type = NzEvent::MouseButtonPressed;
|
||||
event.type = nzEventType_MouseButtonPressed;
|
||||
m_parent->PushEvent(event);
|
||||
|
||||
break;
|
||||
@@ -804,6 +900,8 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||
case WM_XBUTTONDOWN:
|
||||
{
|
||||
NzEvent event;
|
||||
event.type = nzEventType_MouseButtonPressed;
|
||||
|
||||
if (HIWORD(wParam) == XBUTTON1)
|
||||
event.mouseButton.button = NzMouse::XButton1;
|
||||
else
|
||||
@@ -819,6 +917,8 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||
case WM_XBUTTONUP:
|
||||
{
|
||||
NzEvent event;
|
||||
event.type = nzEventType_MouseButtonReleased;
|
||||
|
||||
if (HIWORD(wParam) == XBUTTON1)
|
||||
event.mouseButton.button = NzMouse::XButton1;
|
||||
else
|
||||
@@ -1018,7 +1118,7 @@ NzKeyboard::Key NzWindowImpl::ConvertVirtualKey(WPARAM key, LPARAM flags)
|
||||
}
|
||||
|
||||
#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, NzConditionVariable* condition)
|
||||
{
|
||||
*handle = CreateWindowExW(styleEx, className, title, style, x, y, width, height, nullptr, nullptr, GetModuleHandle(nullptr), window);
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
#include <windows.h>
|
||||
|
||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||
class NzConditionVariable;
|
||||
class NzMutex;
|
||||
class NzThread;
|
||||
class NzThreadCondition;
|
||||
#endif
|
||||
class NzWindow;
|
||||
|
||||
@@ -34,11 +34,11 @@ class NzWindowImpl : NzNonCopyable
|
||||
NzWindowImpl(NzWindow* parent);
|
||||
~NzWindowImpl() = default;
|
||||
|
||||
void Close();
|
||||
|
||||
bool Create(NzVideoMode mode, const NzString& title, nzUInt32 style);
|
||||
bool Create(NzWindowHandle handle);
|
||||
|
||||
void Destroy();
|
||||
|
||||
void EnableKeyRepeat(bool enable);
|
||||
void EnableSmoothScrolling(bool enable);
|
||||
|
||||
@@ -53,6 +53,8 @@ class NzWindowImpl : NzNonCopyable
|
||||
|
||||
void ProcessEvents(bool block);
|
||||
|
||||
void IgnoreNextMouseEvent(int mouseX, int mouseY);
|
||||
|
||||
bool IsMinimized() const;
|
||||
bool IsVisible() const;
|
||||
|
||||
@@ -65,11 +67,10 @@ class NzWindowImpl : NzNonCopyable
|
||||
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 NzString& title);
|
||||
void SetVisible(bool visible);
|
||||
|
||||
void StayOnTop(bool stayOnTop);
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
@@ -79,7 +80,7 @@ class NzWindowImpl : NzNonCopyable
|
||||
static LRESULT CALLBACK MessageHandler(HWND window, UINT message, WPARAM wParam, LPARAM lParam);
|
||||
static NzKeyboard::Key ConvertVirtualKey(WPARAM key, LPARAM flags);
|
||||
#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, NzConditionVariable* condition);
|
||||
#endif
|
||||
|
||||
HCURSOR m_cursor;
|
||||
@@ -87,7 +88,11 @@ class NzWindowImpl : NzNonCopyable
|
||||
LONG_PTR m_callback;
|
||||
NzVector2i m_maxSize;
|
||||
NzVector2i m_minSize;
|
||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||
NzVector2i m_mousePos;
|
||||
#if !NAZARA_UTILITY_THREADED_WINDOW
|
||||
NzVector2i m_position;
|
||||
NzVector2ui m_size;
|
||||
#else
|
||||
NzThread* m_thread;
|
||||
#endif
|
||||
NzWindow* m_parent;
|
||||
@@ -95,6 +100,9 @@ class NzWindowImpl : NzNonCopyable
|
||||
bool m_keyRepeat;
|
||||
bool m_mouseInside;
|
||||
bool m_ownsWindow;
|
||||
#if !NAZARA_UTILITY_THREADED_WINDOW
|
||||
bool m_sizemove;
|
||||
#endif
|
||||
bool m_smoothScrolling;
|
||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||
bool m_threadActive;
|
||||
|
||||
@@ -82,32 +82,18 @@ m_impl(nullptr)
|
||||
|
||||
NzWindow::~NzWindow()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
void NzWindow::Close()
|
||||
{
|
||||
if (m_impl)
|
||||
{
|
||||
OnClose();
|
||||
|
||||
m_impl->Close();
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
|
||||
if (fullscreenWindow == this)
|
||||
fullscreenWindow = nullptr;
|
||||
}
|
||||
Destroy();
|
||||
}
|
||||
|
||||
bool NzWindow::Create(NzVideoMode mode, const NzString& title, nzUInt32 style)
|
||||
{
|
||||
// Si la fenêtre est déjà ouverte, nous conservons sa position
|
||||
bool opened = IsOpen();
|
||||
NzVector2i position;
|
||||
if (opened)
|
||||
position = m_impl->GetPosition();
|
||||
|
||||
Close();
|
||||
Destroy();
|
||||
|
||||
// Inspiré du code de la SFML par Laurent Gomila
|
||||
if (style & nzWindowStyle_Fullscreen)
|
||||
@@ -143,7 +129,7 @@ bool NzWindow::Create(NzVideoMode mode, const NzString& title, nzUInt32 style)
|
||||
|
||||
m_ownsWindow = true;
|
||||
|
||||
if (!OnCreate())
|
||||
if (!OnWindowCreated())
|
||||
{
|
||||
NazaraError("Failed to initialize window extension");
|
||||
delete m_impl;
|
||||
@@ -152,6 +138,7 @@ bool NzWindow::Create(NzVideoMode mode, const NzString& title, nzUInt32 style)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Paramètres par défaut
|
||||
m_impl->EnableKeyRepeat(true);
|
||||
m_impl->EnableSmoothScrolling(false);
|
||||
m_impl->SetCursor(nzWindowCursor_Default);
|
||||
@@ -167,7 +154,7 @@ bool NzWindow::Create(NzVideoMode mode, const NzString& title, nzUInt32 style)
|
||||
|
||||
bool NzWindow::Create(NzWindowHandle handle)
|
||||
{
|
||||
Close();
|
||||
Destroy();
|
||||
|
||||
m_impl = new NzWindowImpl(this);
|
||||
if (!m_impl->Create(handle))
|
||||
@@ -181,7 +168,7 @@ bool NzWindow::Create(NzWindowHandle handle)
|
||||
|
||||
m_ownsWindow = false;
|
||||
|
||||
if (!OnCreate())
|
||||
if (!OnWindowCreated())
|
||||
{
|
||||
NazaraError("Failed to initialize window's derivate");
|
||||
delete m_impl;
|
||||
@@ -193,6 +180,21 @@ bool NzWindow::Create(NzWindowHandle handle)
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzWindow::Destroy()
|
||||
{
|
||||
if (m_impl)
|
||||
{
|
||||
OnWindowDestroying();
|
||||
|
||||
m_impl->Destroy();
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
|
||||
if (fullscreenWindow == this)
|
||||
fullscreenWindow = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void NzWindow::EnableKeyRepeat(bool enable)
|
||||
{
|
||||
if (m_impl)
|
||||
@@ -210,7 +212,7 @@ NzWindowHandle NzWindow::GetHandle() const
|
||||
if (m_impl)
|
||||
return m_impl->GetHandle();
|
||||
else
|
||||
return 0;
|
||||
return reinterpret_cast<NzWindowHandle>(0);
|
||||
}
|
||||
|
||||
unsigned int NzWindow::GetHeight() const
|
||||
@@ -420,6 +422,12 @@ void NzWindow::SetSize(unsigned int width, unsigned int height)
|
||||
m_impl->SetSize(width, height);
|
||||
}
|
||||
|
||||
void NzWindow::SetStayOnTop(bool stayOnTop)
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->SetStayOnTop(stayOnTop);
|
||||
}
|
||||
|
||||
void NzWindow::SetTitle(const NzString& title)
|
||||
{
|
||||
if (m_impl)
|
||||
@@ -432,12 +440,6 @@ void NzWindow::SetVisible(bool visible)
|
||||
m_impl->SetVisible(visible);
|
||||
}
|
||||
|
||||
void NzWindow::StayOnTop(bool stayOnTop)
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->StayOnTop(stayOnTop);
|
||||
}
|
||||
|
||||
bool NzWindow::WaitEvent(NzEvent* event)
|
||||
{
|
||||
if (!m_impl)
|
||||
@@ -481,15 +483,21 @@ bool NzWindow::WaitEvent(NzEvent* event)
|
||||
#endif
|
||||
}
|
||||
|
||||
void NzWindow::OnClose()
|
||||
void NzWindow::OnWindowDestroying()
|
||||
{
|
||||
}
|
||||
|
||||
bool NzWindow::OnCreate()
|
||||
bool NzWindow::OnWindowCreated()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzWindow::IgnoreNextMouseEvent(int mouseX, int mouseY) const
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->IgnoreNextMouseEvent(mouseX, mouseY);
|
||||
}
|
||||
|
||||
void NzWindow::PushEvent(const NzEvent& event)
|
||||
{
|
||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||
|
||||
Reference in New Issue
Block a user