Merge remote-tracking branch 'upstream/master'
Former-commit-id: 8fe411f0146d6cc64cf8d32cc4896f7f417f62a5
This commit is contained in:
@@ -37,7 +37,7 @@ namespace
|
||||
break;
|
||||
|
||||
case SEEK_END:
|
||||
stream->SetCursorPos(stream->GetSize()+offset);
|
||||
stream->SetCursorPos(stream->GetSize() + offset); // L'offset est négatif ici
|
||||
break;
|
||||
|
||||
case SEEK_SET:
|
||||
@@ -95,11 +95,18 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
// https://github.com/LaurentGomila/SFML/issues/271
|
||||
// http://www.mega-nerd.com/libsndfile/command.html#SFC_SET_SCALE_FLOAT_INT_READ
|
||||
///FIXME: Seulement le Vorbis ?
|
||||
if (infos.format & SF_FORMAT_VORBIS)
|
||||
sf_command(file, SFC_SET_SCALE_FLOAT_INT_READ, nullptr, SF_TRUE);
|
||||
|
||||
unsigned int sampleCount = infos.frames*infos.channels;
|
||||
nzInt16* samples = new nzInt16[sampleCount];
|
||||
if (sf_read_short(file, samples, sampleCount) != sampleCount)
|
||||
{
|
||||
NazaraError("Failed to read samples");
|
||||
|
||||
delete[] samples;
|
||||
sf_close(file);
|
||||
|
||||
@@ -109,6 +116,8 @@ namespace
|
||||
if (!soundBuffer->Create(format, infos.frames*infos.channels, infos.samplerate, samples))
|
||||
{
|
||||
NazaraError("Failed to create sound buffer");
|
||||
|
||||
delete[] samples;
|
||||
sf_close(file);
|
||||
|
||||
return false;
|
||||
@@ -123,13 +132,11 @@ namespace
|
||||
void NzLoaders_sndfile_Register()
|
||||
{
|
||||
NzSoundBufferLoader::RegisterLoader("aiff,au,avr,caf,flac,htk,ircam,mat4,mat5,mpc2k,nist,ogg,paf,pvf,raw,rf64,sd2,sds,svx,voc,w64,wav,wve",
|
||||
NzLoader_sndfile_Check,
|
||||
NzLoader_sndfile_Load);
|
||||
NzLoader_sndfile_Check, NzLoader_sndfile_Load);
|
||||
}
|
||||
|
||||
void NzLoaders_sndfile_Unregister()
|
||||
{
|
||||
NzSoundBufferLoader::UnregisterLoader("aiff,au,avr,caf,flac,htk,ircam,mat4,mat5,mpc2k,nist,ogg,paf,pvf,raw,rf64,sd2,sds,svx,voc,w64,wav,wve",
|
||||
NzLoader_sndfile_Check,
|
||||
NzLoader_sndfile_Load);
|
||||
NzLoader_sndfile_Check, NzLoader_sndfile_Load);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,14 @@
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
// C'est malheureux mais le spécificateur %z de (f)printf n'est pas supporté partout
|
||||
#ifdef NAZARA_COMPILER_MINGW
|
||||
#define SIZE_T_SPECIFIER "%u"
|
||||
#else
|
||||
#define SIZE_T_SPECIFIER "%zu" // Standard
|
||||
#endif
|
||||
// Le seul fichier n'ayant pas à inclure Debug.hpp
|
||||
|
||||
namespace
|
||||
{
|
||||
struct Block
|
||||
@@ -76,7 +84,7 @@ void* NzMemoryManager::Allocate(std::size_t size, bool multi, const char* file,
|
||||
{
|
||||
// Pas d'information de temps (Car nécessitant une allocation)
|
||||
FILE* log = std::fopen(MLTFileName, "a");
|
||||
std::fprintf(log, "Failed to allocate memory (%d bytes)\n", size);
|
||||
std::fprintf(log, "Failed to allocate memory (" SIZE_T_SPECIFIER " bytes)\n", size);
|
||||
std::fclose(log);
|
||||
|
||||
return nullptr; // Impossible d'envoyer une exception car cela allouerait de la mémoire avec new (boucle infinie)
|
||||
@@ -126,9 +134,9 @@ void NzMemoryManager::Free(void* pointer, bool multi)
|
||||
if (nextFreeFile)
|
||||
{
|
||||
if (multi)
|
||||
std::fprintf(log, "%s Warning: delete[] after new at %s:%d\n", time, nextFreeFile, nextFreeLine);
|
||||
std::fprintf(log, "%s Warning: delete[] after new at %s:%u\n", time, nextFreeFile, nextFreeLine);
|
||||
else
|
||||
std::fprintf(log, "%s Warning: delete after new[] at %s:%d\n", time, nextFreeFile, nextFreeLine);
|
||||
std::fprintf(log, "%s Warning: delete after new[] at %s:%u\n", time, nextFreeFile, nextFreeLine);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -224,24 +232,24 @@ void NzMemoryManager::Uninitialize()
|
||||
std::fprintf(log, "%s ==============================\n\n", time);
|
||||
std::fputs("Leak list:\n", log);
|
||||
|
||||
std::size_t totalSize = 0;
|
||||
Block* ptr = ptrList.next;
|
||||
unsigned int count = 0;
|
||||
unsigned int totalSize = 0;
|
||||
while (ptr != &ptrList)
|
||||
{
|
||||
count++;
|
||||
totalSize += ptr->size;
|
||||
if (ptr->file)
|
||||
std::fprintf(log, "-0x%p -> %d bytes allocated at %s:%d\n", reinterpret_cast<char*>(ptr)+sizeof(Block), ptr->size, ptr->file, ptr->line);
|
||||
std::fprintf(log, "-0x%p -> " SIZE_T_SPECIFIER " bytes allocated at %s:%u\n", reinterpret_cast<char*>(ptr)+sizeof(Block), ptr->size, ptr->file, ptr->line);
|
||||
else
|
||||
std::fprintf(log, "-0x%p -> %d bytes allocated at unknown position\n", reinterpret_cast<char*>(ptr)+sizeof(Block), ptr->size);
|
||||
std::fprintf(log, "-0x%p -> " SIZE_T_SPECIFIER " bytes allocated at unknown position\n", reinterpret_cast<char*>(ptr)+sizeof(Block), ptr->size);
|
||||
|
||||
void* pointer = ptr;
|
||||
ptr = ptr->next;
|
||||
std::free(pointer);
|
||||
}
|
||||
|
||||
std::fprintf(log, "\n%d blocks leaked (%d bytes)", count, totalSize);
|
||||
std::fprintf(log, "\n%u blocks leaked (" SIZE_T_SPECIFIER " bytes)", count, totalSize);
|
||||
}
|
||||
|
||||
std::free(time);
|
||||
|
||||
@@ -11,10 +11,6 @@ NzDirectoryImpl::NzDirectoryImpl(const NzDirectory* parent)
|
||||
NazaraUnused(parent);
|
||||
}
|
||||
|
||||
NzDirectoryImpl::~NzDirectoryImpl()
|
||||
{
|
||||
}
|
||||
|
||||
void NzDirectoryImpl::Close()
|
||||
{
|
||||
FindClose(m_handle);
|
||||
|
||||
@@ -18,7 +18,7 @@ class NzDirectoryImpl : NzNonCopyable
|
||||
{
|
||||
public:
|
||||
NzDirectoryImpl(const NzDirectory* parent);
|
||||
~NzDirectoryImpl();
|
||||
~NzDirectoryImpl() = default;
|
||||
|
||||
void Close();
|
||||
|
||||
|
||||
@@ -13,10 +13,6 @@ m_parent(parent)
|
||||
{
|
||||
}
|
||||
|
||||
NzDynLibImpl::~NzDynLibImpl()
|
||||
{
|
||||
}
|
||||
|
||||
NzDynLibFunc NzDynLibImpl::GetSymbol(const NzString& symbol) const
|
||||
{
|
||||
NzDynLibFunc sym = reinterpret_cast<NzDynLibFunc>(GetProcAddress(m_handle, symbol.GetConstBuffer()));
|
||||
|
||||
@@ -17,7 +17,7 @@ class NzDynLibImpl : NzNonCopyable
|
||||
{
|
||||
public:
|
||||
NzDynLibImpl(NzDynLib* m_parent);
|
||||
~NzDynLibImpl();
|
||||
~NzDynLibImpl() = default;
|
||||
|
||||
NzDynLibFunc GetSymbol(const NzString& symbol) const;
|
||||
bool Load(const NzString& libraryPath);
|
||||
|
||||
@@ -14,10 +14,6 @@ m_endOfFileUpdated(true)
|
||||
NazaraUnused(parent);
|
||||
}
|
||||
|
||||
NzFileImpl::~NzFileImpl()
|
||||
{
|
||||
}
|
||||
|
||||
void NzFileImpl::Close()
|
||||
{
|
||||
CloseHandle(m_handle);
|
||||
|
||||
@@ -20,7 +20,7 @@ class NzFileImpl : NzNonCopyable
|
||||
{
|
||||
public:
|
||||
NzFileImpl(const NzFile* parent);
|
||||
~NzFileImpl();
|
||||
~NzFileImpl() = default;
|
||||
|
||||
void Close();
|
||||
bool EndOfFile() const;
|
||||
|
||||
@@ -97,9 +97,9 @@ bool NzGLSLShader::Compile()
|
||||
if (length > 1)
|
||||
{
|
||||
m_log.Clear(true);
|
||||
m_log.Reserve(length+19-1); // La taille retournée est celle du buffer (Avec caractère de fin)
|
||||
m_log.Reserve(length+15-2); // La taille retournée est celle du buffer (Avec caractère de fin)
|
||||
m_log.Prepend("Linkage error: ");
|
||||
m_log.Resize(length+19-1); // Extension du buffer d'écriture pour ajouter le log
|
||||
m_log.Resize(length+15-2); // Extension du buffer d'écriture pour ajouter le log
|
||||
|
||||
glGetProgramInfoLog(m_program, length-1, nullptr, &m_log[19]);
|
||||
}
|
||||
@@ -264,9 +264,9 @@ bool NzGLSLShader::Load(nzShaderType type, const NzString& source)
|
||||
if (length > 1)
|
||||
{
|
||||
m_log.Clear(true);
|
||||
m_log.Reserve(length+19-1); // La taille retournée est celle du buffer (Avec caractère de fin)
|
||||
m_log.Reserve(length+19-2); // La taille retournée est celle du buffer (Avec caractère de fin)
|
||||
m_log.Prepend("Compilation error: ");
|
||||
m_log.Resize(length+19-1); // Extension du buffer d'écriture pour ajouter le log
|
||||
m_log.Resize(length+19-2); // Extension du buffer d'écriture pour ajouter le log
|
||||
|
||||
glGetShaderInfoLog(shader, length-1, nullptr, &m_log[19]);
|
||||
}
|
||||
|
||||
@@ -262,10 +262,11 @@ namespace NzOpenGL
|
||||
glGenTextures = reinterpret_cast<PFNGLGENTEXTURESPROC>(LoadEntry("glGenTextures"));
|
||||
glGetBufferParameteriv = reinterpret_cast<PFNGLGETBUFFERPARAMETERIVPROC>(LoadEntry("glGetBufferParameteriv"));
|
||||
glGetError = reinterpret_cast<PFNGLGETERRORPROC>(LoadEntry("glGetError"));
|
||||
glGetFloatv = reinterpret_cast<PFNGLGETFLOATVPROC>(LoadEntry("glGetFloatv"));
|
||||
glGetIntegerv = reinterpret_cast<PFNGLGETINTEGERVPROC>(LoadEntry("glGetIntegerv"));
|
||||
glGetQueryiv = reinterpret_cast<PFNGLGETQUERYIVPROC>(LoadEntry("glGetQueryiv"));
|
||||
glGetQueryObjectiv = reinterpret_cast<PFNGLGETQUERYOBJECTIVPROC>(LoadEntry("glGetQueryObjectiv"));
|
||||
glGetQueryObjectuiv = reinterpret_cast<PFNGLGETQUERYOBJECTUIVPROC>(LoadEntry("glGetQueryObjectuiv"));
|
||||
glGetIntegerv = reinterpret_cast<PFNGLGETINTEGERVPROC>(LoadEntry("glGetIntegerv"));
|
||||
glGetProgramiv = reinterpret_cast<PFNGLGETPROGRAMIVPROC>(LoadEntry("glGetProgramiv"));
|
||||
glGetProgramInfoLog = reinterpret_cast<PFNGLGETPROGRAMINFOLOGPROC>(LoadEntry("glGetProgramInfoLog"));
|
||||
glGetShaderInfoLog = reinterpret_cast<PFNGLGETSHADERINFOLOGPROC>(LoadEntry("glGetShaderInfoLog"));
|
||||
@@ -277,9 +278,11 @@ namespace NzOpenGL
|
||||
glGetTexParameterfv = reinterpret_cast<PFNGLGETTEXPARAMETERFVPROC>(LoadEntry("glGetTexParameterfv"));
|
||||
glGetTexParameteriv = reinterpret_cast<PFNGLGETTEXPARAMETERIVPROC>(LoadEntry("glGetTexParameteriv"));
|
||||
glGetUniformLocation = reinterpret_cast<PFNGLGETUNIFORMLOCATIONPROC>(LoadEntry("glGetUniformLocation"));
|
||||
glLineWidth = reinterpret_cast<PFNGLLINEWIDTHPROC>(LoadEntry("glLineWidth"));
|
||||
glLinkProgram = reinterpret_cast<PFNGLLINKPROGRAMPROC>(LoadEntry("glLinkProgram"));
|
||||
glMapBuffer = reinterpret_cast<PFNGLMAPBUFFERPROC>(LoadEntry("glMapBuffer"));
|
||||
glPixelStorei = reinterpret_cast<PFNGLPIXELSTOREIPROC>(LoadEntry("glPixelStorei"));
|
||||
glPointSize = reinterpret_cast<PFNGLPOINTSIZEPROC>(LoadEntry("glPointSize"));
|
||||
glPolygonMode = reinterpret_cast<PFNGLPOLYGONMODEPROC>(LoadEntry("glPolygonMode"));
|
||||
glReadPixels = reinterpret_cast<PFNGLREADPIXELSPROC>(LoadEntry("glReadPixels"));
|
||||
glScissor = reinterpret_cast<PFNGLSCISSORPROC>(LoadEntry("glScissor"));
|
||||
@@ -936,6 +939,7 @@ PFNGLGENVERTEXARRAYSPROC glGenVertexArrays = nullptr;
|
||||
PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv = nullptr;
|
||||
PFNGLGETDEBUGMESSAGELOGPROC glGetDebugMessageLog = nullptr;
|
||||
PFNGLGETERRORPROC glGetError = nullptr;
|
||||
PFNGLGETFLOATVPROC glGetFloatv = nullptr;
|
||||
PFNGLGETINTEGERVPROC glGetIntegerv = nullptr;
|
||||
PFNGLGETPROGRAMIVPROC glGetProgramiv = nullptr;
|
||||
PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog = nullptr;
|
||||
@@ -953,10 +957,12 @@ PFNGLGETTEXLEVELPARAMETERIVPROC glGetTexLevelParameteriv = nullptr;
|
||||
PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv = nullptr;
|
||||
PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv = nullptr;
|
||||
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = nullptr;
|
||||
PFNGLLINEWIDTHPROC glLineWidth = nullptr;
|
||||
PFNGLLINKPROGRAMPROC glLinkProgram = nullptr;
|
||||
PFNGLMAPBUFFERPROC glMapBuffer = nullptr;
|
||||
PFNGLMAPBUFFERRANGEPROC glMapBufferRange = nullptr;
|
||||
PFNGLPIXELSTOREIPROC glPixelStorei = nullptr;
|
||||
PFNGLPOINTSIZEPROC glPointSize = nullptr;
|
||||
PFNGLPOLYGONMODEPROC glPolygonMode = nullptr;
|
||||
PFNGLPROGRAMUNIFORM1DPROC glProgramUniform1d = nullptr;
|
||||
PFNGLPROGRAMUNIFORM1FPROC glProgramUniform1f = nullptr;
|
||||
|
||||
@@ -196,6 +196,14 @@ void NzRenderer::Enable(nzRendererParameter parameter, bool enable)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
float NzRenderer::GetLineWidth()
|
||||
{
|
||||
float lineWidth;
|
||||
glGetFloatv(GL_LINE_WIDTH, &lineWidth);
|
||||
|
||||
return lineWidth;
|
||||
}
|
||||
/*
|
||||
NzMatrix4f NzRenderer::GetMatrix(nzMatrixCombination combination)
|
||||
{
|
||||
@@ -250,6 +258,14 @@ unsigned int NzRenderer::GetMaxTextureUnits()
|
||||
return s_maxTextureUnit;
|
||||
}
|
||||
|
||||
float NzRenderer::GetPointSize()
|
||||
{
|
||||
float pointSize;
|
||||
glGetFloatv(GL_POINT_SIZE, &pointSize);
|
||||
|
||||
return pointSize;
|
||||
}
|
||||
|
||||
NzShader* NzRenderer::GetShader()
|
||||
{
|
||||
return s_shader;
|
||||
@@ -497,6 +513,19 @@ bool NzRenderer::SetIndexBuffer(const NzIndexBuffer* indexBuffer)
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzRenderer::SetLineWidth(float width)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (width <= 0.f)
|
||||
{
|
||||
NazaraError("Width must be over zero");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
glLineWidth(width);
|
||||
}
|
||||
|
||||
void NzRenderer::SetMatrix(nzMatrixType type, const NzMatrix4f& matrix)
|
||||
{
|
||||
s_matrix[type] = matrix;
|
||||
@@ -514,6 +543,19 @@ void NzRenderer::SetMatrix(nzMatrixType type, const NzMatrix4f& matrix)
|
||||
}
|
||||
}
|
||||
|
||||
void NzRenderer::SetPointSize(float size)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (size <= 0.f)
|
||||
{
|
||||
NazaraError("Size must be over zero");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
glPointSize(size);
|
||||
}
|
||||
|
||||
bool NzRenderer::SetShader(NzShader* shader)
|
||||
{
|
||||
if (s_shader == shader)
|
||||
@@ -550,6 +592,10 @@ bool NzRenderer::SetShader(NzShader* shader)
|
||||
s_matrixLocation[nzMatrixCombination_ViewProj] = shader->GetUniformLocation("ViewProjMatrix");
|
||||
s_matrixLocation[nzMatrixCombination_WorldView] = shader->GetUniformLocation("WorldViewMatrix");
|
||||
s_matrixLocation[nzMatrixCombination_WorldViewProj] = shader->GetUniformLocation("WorldViewProjMatrix");
|
||||
|
||||
///FIXME: Peut VRAIMENT être optimisé
|
||||
for (unsigned int i = 0; i < totalMatrixCount; ++i)
|
||||
s_matrixUpdated[i] = false;
|
||||
}
|
||||
|
||||
s_shader = shader;
|
||||
@@ -856,15 +902,15 @@ bool NzRenderer::EnsureStateUpdate()
|
||||
NzHardwareBuffer* vertexBufferImpl = static_cast<NzHardwareBuffer*>(s_vertexBuffer->GetBuffer()->GetImpl());
|
||||
vertexBufferImpl->Bind();
|
||||
|
||||
const nzUInt8* buffer = reinterpret_cast<const nzUInt8*>(s_vertexBuffer->GetPointer());
|
||||
|
||||
const nzUInt8* buffer = static_cast<const nzUInt8*>(s_vertexBuffer->GetPointer());
|
||||
unsigned int stride = s_vertexDeclaration->GetStride(nzElementStream_VertexData);
|
||||
for (unsigned int i = 0; i <= nzElementUsage_Max; ++i)
|
||||
{
|
||||
const NzVertexElement* element = s_vertexDeclaration->GetElement(nzElementStream_VertexData, static_cast<nzElementUsage>(i));
|
||||
|
||||
if (element)
|
||||
nzElementUsage usage = static_cast<nzElementUsage>(i);
|
||||
if (s_vertexDeclaration->HasElement(nzElementStream_VertexData, usage))
|
||||
{
|
||||
const NzVertexElement* element = s_vertexDeclaration->GetElement(nzElementStream_VertexData, usage);
|
||||
|
||||
glEnableVertexAttribArray(NzOpenGL::AttributeIndex[i]);
|
||||
glVertexAttribPointer(NzOpenGL::AttributeIndex[i],
|
||||
NzVertexDeclaration::GetElementCount(element->type),
|
||||
|
||||
@@ -214,6 +214,11 @@ bool NzShader::IsLoaded(nzShaderType type) const
|
||||
return m_impl->IsLoaded(type);
|
||||
}
|
||||
|
||||
bool NzShader::IsValid() const
|
||||
{
|
||||
return m_impl != nullptr;
|
||||
}
|
||||
|
||||
bool NzShader::Load(nzShaderType type, const NzString& source)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
|
||||
@@ -11,6 +11,12 @@ m_extend(nzExtend_Null)
|
||||
{
|
||||
}
|
||||
|
||||
NzAxisAlignedBox::NzAxisAlignedBox(const NzCubef& cube) :
|
||||
m_extend(nzExtend_Finite),
|
||||
m_cube(cube)
|
||||
{
|
||||
}
|
||||
|
||||
NzAxisAlignedBox::NzAxisAlignedBox(const NzVector3f& vec1, const NzVector3f& vec2) :
|
||||
m_extend(nzExtend_Finite),
|
||||
m_cube(vec1, vec2)
|
||||
@@ -37,7 +43,6 @@ void NzAxisAlignedBox::ExtendTo(const NzAxisAlignedBox& box)
|
||||
switch (m_extend)
|
||||
{
|
||||
case nzExtend_Finite:
|
||||
{
|
||||
switch (box.m_extend)
|
||||
{
|
||||
case nzExtend_Finite:
|
||||
@@ -50,18 +55,16 @@ void NzAxisAlignedBox::ExtendTo(const NzAxisAlignedBox& box)
|
||||
|
||||
case nzExtend_Null:
|
||||
break;
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case nzExtend_Infinite:
|
||||
// Rien à faire
|
||||
break;
|
||||
case nzExtend_Infinite:
|
||||
// Rien à faire
|
||||
break;
|
||||
|
||||
case nzExtend_Null:
|
||||
operator=(box);
|
||||
break;
|
||||
}
|
||||
case nzExtend_Null:
|
||||
operator=(box);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,6 +155,66 @@ NzString NzAxisAlignedBox::ToString() const
|
||||
return "NzAxisAlignedBox(ERROR)";
|
||||
}
|
||||
|
||||
NzAxisAlignedBox::operator NzString() const
|
||||
{
|
||||
return ToString();
|
||||
}
|
||||
|
||||
NzAxisAlignedBox NzAxisAlignedBox::Lerp(const NzAxisAlignedBox& from, const NzAxisAlignedBox& to, float interpolation)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (interpolation < 0.f || interpolation > 1.f)
|
||||
{
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + NzString::Number(interpolation) + ')');
|
||||
return Null;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (NzNumberEquals(interpolation, 0.f))
|
||||
return from;
|
||||
|
||||
if (NzNumberEquals(interpolation, 1.f))
|
||||
return to;
|
||||
|
||||
switch (to.m_extend)
|
||||
{
|
||||
case nzExtend_Finite:
|
||||
{
|
||||
switch (from.m_extend)
|
||||
{
|
||||
case nzExtend_Finite:
|
||||
return NzCubef::Lerp(from.m_cube, to.m_cube, interpolation);
|
||||
|
||||
case nzExtend_Infinite:
|
||||
return Infinite;
|
||||
|
||||
case nzExtend_Null:
|
||||
return from.m_cube * interpolation;
|
||||
}
|
||||
}
|
||||
|
||||
case nzExtend_Infinite:
|
||||
return Infinite; // Un petit peu d'infini est infini quand même ;)
|
||||
|
||||
case nzExtend_Null:
|
||||
{
|
||||
switch (from.m_extend)
|
||||
{
|
||||
case nzExtend_Finite:
|
||||
return from.m_cube * (1.f - interpolation);
|
||||
|
||||
case nzExtend_Infinite:
|
||||
return Infinite;
|
||||
|
||||
case nzExtend_Null:
|
||||
return Null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Null;
|
||||
}
|
||||
|
||||
const NzAxisAlignedBox NzAxisAlignedBox::Infinite(nzExtend_Infinite);
|
||||
const NzAxisAlignedBox NzAxisAlignedBox::Null(nzExtend_Null);
|
||||
|
||||
|
||||
@@ -105,7 +105,8 @@ bool NzImage::Convert(nzPixelFormat format)
|
||||
for (unsigned int i = 0; i < m_sharedImage->levelCount; ++i)
|
||||
{
|
||||
unsigned int pixelsPerFace = width*height;
|
||||
nzUInt8* ptr = new nzUInt8[pixelsPerFace*depth*NzPixelFormat::GetBytesPerPixel(format)];
|
||||
nzUInt8* face = new nzUInt8[pixelsPerFace*depth*NzPixelFormat::GetBytesPerPixel(format)];
|
||||
nzUInt8* ptr = face;
|
||||
nzUInt8* pixels = m_sharedImage->pixels[i];
|
||||
unsigned int srcStride = pixelsPerFace * NzPixelFormat::GetBytesPerPixel(m_sharedImage->format);
|
||||
unsigned int dstStride = pixelsPerFace * NzPixelFormat::GetBytesPerPixel(format);
|
||||
@@ -117,7 +118,7 @@ bool NzImage::Convert(nzPixelFormat format)
|
||||
NazaraError("Failed to convert image");
|
||||
|
||||
// Nettoyage de la mémoire
|
||||
delete[] ptr; // Permet une optimisation de boucle (GCC)
|
||||
delete[] face; // Permet une optimisation de boucle (GCC)
|
||||
for (unsigned int j = 0; j < i; ++j)
|
||||
delete[] levels[j];
|
||||
|
||||
@@ -130,7 +131,7 @@ bool NzImage::Convert(nzPixelFormat format)
|
||||
ptr += dstStride;
|
||||
}
|
||||
|
||||
levels[i] = ptr;
|
||||
levels[i] = face;
|
||||
|
||||
if (width > 1)
|
||||
width >>= 1;
|
||||
@@ -356,33 +357,39 @@ bool NzImage::Fill(const NzColor& color)
|
||||
}
|
||||
#endif
|
||||
|
||||
EnsureOwnership();
|
||||
|
||||
nzUInt8 bpp = NzPixelFormat::GetBytesPerPixel(m_sharedImage->format);
|
||||
nzUInt8* pixels = new nzUInt8[bpp];
|
||||
if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, pixels))
|
||||
nzUInt8* colorBuffer = new nzUInt8[bpp];
|
||||
if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, colorBuffer))
|
||||
{
|
||||
NazaraError("Failed to convert RGBA8 to " + NzPixelFormat::ToString(m_sharedImage->format));
|
||||
delete[] pixels;
|
||||
delete[] colorBuffer;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
nzUInt8** levels = new nzUInt8*[m_sharedImage->levelCount];
|
||||
|
||||
unsigned int width = m_sharedImage->width;
|
||||
unsigned int height = m_sharedImage->height;
|
||||
|
||||
// Les images 3D et cubemaps sont stockés de la même façon
|
||||
unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth;
|
||||
|
||||
for (unsigned int level = 0; level < m_sharedImage->levelCount; ++level)
|
||||
for (unsigned int i = 0; i < m_sharedImage->levelCount; ++i)
|
||||
{
|
||||
nzUInt8* ptr = &m_sharedImage->pixels[level][0];
|
||||
nzUInt8* end = &m_sharedImage->pixels[level][width*height*depth*bpp];
|
||||
unsigned int size = width*height*depth*bpp;
|
||||
nzUInt8* face = new nzUInt8[size];
|
||||
nzUInt8* ptr = face;
|
||||
nzUInt8* end = &ptr[size];
|
||||
|
||||
while (ptr < end)
|
||||
{
|
||||
std::memcpy(ptr, pixels, bpp);
|
||||
std::memcpy(ptr, colorBuffer, bpp);
|
||||
ptr += bpp;
|
||||
}
|
||||
|
||||
levels[i] = face;
|
||||
|
||||
if (width > 1U)
|
||||
width >>= 1;
|
||||
|
||||
@@ -393,7 +400,12 @@ bool NzImage::Fill(const NzColor& color)
|
||||
depth >>= 1;
|
||||
}
|
||||
|
||||
delete[] pixels;
|
||||
delete[] colorBuffer;
|
||||
|
||||
SharedImage* newImage = new SharedImage(1, m_sharedImage->type, m_sharedImage->format, m_sharedImage->levelCount, levels, m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth);
|
||||
|
||||
ReleaseImage();
|
||||
m_sharedImage = newImage;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -562,7 +574,6 @@ bool NzImage::FlipHorizontally()
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool NzImage::FlipVertically()
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
|
||||
@@ -14,6 +14,11 @@
|
||||
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
NzString NzKeyboard::GetKeyName(Key key)
|
||||
{
|
||||
return NzEventImpl::GetKeyName(key);
|
||||
}
|
||||
|
||||
bool NzKeyboard::IsKeyPressed(Key key)
|
||||
{
|
||||
return NzEventImpl::IsKeyPressed(key);
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace
|
||||
nzUInt8 padding[54];
|
||||
};
|
||||
|
||||
bool NzLoader_PCX_Check(NzInputStream& stream, const NzImageParams& parameters)
|
||||
bool Check(NzInputStream& stream, const NzImageParams& parameters)
|
||||
{
|
||||
NazaraUnused(parameters);
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace
|
||||
return manufacturer == 0x0a;
|
||||
}
|
||||
|
||||
bool NzLoader_PCX_Load(NzImage* image, NzInputStream& stream, const NzImageParams& parameters)
|
||||
bool Load(NzImage* image, NzInputStream& stream, const NzImageParams& parameters)
|
||||
{
|
||||
NazaraUnused(parameters);
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
#if defined(NAZARA_BIG_ENDIAN)
|
||||
#ifdef NAZARA_BIG_ENDIAN
|
||||
// Les fichiers PCX sont en little endian
|
||||
NzByteSwap(&header.xmin, sizeof(nzUInt16));
|
||||
NzByteSwap(&header.ymin, sizeof(nzUInt16));
|
||||
@@ -337,10 +337,10 @@ namespace
|
||||
|
||||
void NzLoaders_PCX_Register()
|
||||
{
|
||||
NzImageLoader::RegisterLoader("pcx", NzLoader_PCX_Check, NzLoader_PCX_Load);
|
||||
NzImageLoader::RegisterLoader("pcx", Check, Load);
|
||||
}
|
||||
|
||||
void NzLoaders_PCX_Unregister()
|
||||
{
|
||||
NzImageLoader::UnregisterLoader("pcx", NzLoader_PCX_Check, NzLoader_PCX_Load);
|
||||
NzImageLoader::UnregisterLoader("pcx", Check, Load);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace
|
||||
|
||||
static stbi_io_callbacks callbacks = {Read, Skip, Eof};
|
||||
|
||||
bool NzLoader_STB_Check(NzInputStream& stream, const NzImageParams& parameters)
|
||||
bool Check(NzInputStream& stream, const NzImageParams& parameters)
|
||||
{
|
||||
NazaraUnused(parameters);
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace
|
||||
return stbi_info_from_callbacks(&callbacks, &stream, &width, &height, &bpp);
|
||||
}
|
||||
|
||||
bool NzLoader_STB_Load(NzImage* image, NzInputStream& stream, const NzImageParams& parameters)
|
||||
bool Load(NzImage* image, NzInputStream& stream, const NzImageParams& parameters)
|
||||
{
|
||||
static const nzPixelFormat formats[4] =
|
||||
{
|
||||
@@ -117,10 +117,10 @@ namespace
|
||||
|
||||
void NzLoaders_STB_Register()
|
||||
{
|
||||
NzImageLoader::RegisterLoader("bmp,gif,hdr,jpg,jpeg,pic,png,psd,tga", NzLoader_STB_Check, NzLoader_STB_Load);
|
||||
NzImageLoader::RegisterLoader("bmp,gif,hdr,jpg,jpeg,pic,png,psd,tga", Check, Load);
|
||||
}
|
||||
|
||||
void NzLoaders_STB_Unregister()
|
||||
{
|
||||
NzImageLoader::UnregisterLoader("bmp,gif,hdr,jpg,jpeg,pic,png,psd,tga", NzLoader_STB_Check, NzLoader_STB_Load);
|
||||
NzImageLoader::UnregisterLoader("bmp,gif,hdr,jpg,jpeg,pic,png,psd,tga", Check, Load);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,9 @@ void NzSubMesh::Animate(unsigned int frameA, unsigned int frameB, float interpol
|
||||
NazaraError("Frame B is out of range (" + NzString::Number(frameB) + " >= " + NzString::Number(frameCount) + ')');
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (interpolation < 0.f || interpolation > 1.f)
|
||||
{
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + NzString::Number(interpolation) + ')');
|
||||
|
||||
@@ -244,7 +244,6 @@ const NzVertexElement* NzVertexDeclaration::GetElement(nzElementStream stream, n
|
||||
#endif
|
||||
|
||||
int elementPos = m_sharedImpl->elementPos[stream][usage];
|
||||
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (elementPos == -1)
|
||||
{
|
||||
@@ -253,27 +252,32 @@ const NzVertexElement* NzVertexDeclaration::GetElement(nzElementStream stream, n
|
||||
}
|
||||
#endif
|
||||
|
||||
elementPos += usageIndex;
|
||||
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (static_cast<unsigned int>(elementPos) >= m_sharedImpl->elements.size())
|
||||
if (usageIndex == 0) // Si l'usage index vaut zéro, alors nous sommes certains d'être sur le bon élément (Majorité des cas)
|
||||
return &m_sharedImpl->elements[elementPos];
|
||||
else
|
||||
{
|
||||
NazaraError("Element not found");
|
||||
return nullptr;
|
||||
elementPos += usageIndex;
|
||||
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (static_cast<unsigned int>(elementPos) >= m_sharedImpl->elements.size())
|
||||
{
|
||||
NazaraError("Element not found");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
NzVertexElement& element = m_sharedImpl->elements[elementPos];
|
||||
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (element.stream != stream || element.usage != usage || element.usageIndex != usageIndex)
|
||||
{
|
||||
NazaraError("Element not found");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return &element;
|
||||
}
|
||||
#endif
|
||||
|
||||
NzVertexElement& element = m_sharedImpl->elements[elementPos];
|
||||
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (element.stream != stream || element.usage != usage || element.usageIndex != usageIndex)
|
||||
{
|
||||
NazaraError("Element not found");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return &element;
|
||||
}
|
||||
|
||||
unsigned int NzVertexDeclaration::GetElementCount() const
|
||||
|
||||
@@ -8,37 +8,9 @@
|
||||
#include <windows.h>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
NzVector2i NzEventImpl::GetMousePosition()
|
||||
namespace
|
||||
{
|
||||
POINT pos;
|
||||
GetCursorPos(&pos);
|
||||
|
||||
return NzVector2i(pos.x, pos.y);
|
||||
}
|
||||
|
||||
NzVector2i NzEventImpl::GetMousePosition(const NzWindow& relativeTo)
|
||||
{
|
||||
HWND handle = reinterpret_cast<HWND>(relativeTo.GetHandle());
|
||||
if (handle)
|
||||
{
|
||||
POINT pos;
|
||||
GetCursorPos(&pos);
|
||||
ScreenToClient(handle, &pos);
|
||||
|
||||
return NzVector2i(pos.x, pos.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
NazaraError("Window's handle is invalid");
|
||||
|
||||
// Attention que (-1, -1) est une position tout à fait valide et ne doit pas être utilisée pour tester l'erreur
|
||||
return NzVector2i(-1, -1);
|
||||
}
|
||||
}
|
||||
|
||||
bool NzEventImpl::IsKeyPressed(NzKeyboard::Key key)
|
||||
{
|
||||
static int vKeys[NzKeyboard::Count] = {
|
||||
int vKeys[NzKeyboard::Count] = {
|
||||
// Lettres
|
||||
0x41, // Key::A
|
||||
0x42, // Key::B
|
||||
@@ -161,7 +133,7 @@ bool NzEventImpl::IsKeyPressed(NzKeyboard::Key key)
|
||||
VK_BROWSER_SEARCH, // Key::Browser_Search
|
||||
VK_BROWSER_STOP, // Key::Browser_Stop
|
||||
|
||||
// Touches de contr
|
||||
// Touches de contrôle
|
||||
VK_MEDIA_NEXT_TRACK, // Key::Media_Next,
|
||||
VK_MEDIA_PLAY_PAUSE, // Key::Media_PlayPause,
|
||||
VK_MEDIA_PREV_TRACK, // Key::Media_Previous,
|
||||
@@ -177,7 +149,86 @@ bool NzEventImpl::IsKeyPressed(NzKeyboard::Key key)
|
||||
VK_NUMLOCK, // Key::NumLock
|
||||
VK_SCROLL // Key::ScrollLock
|
||||
};
|
||||
}
|
||||
|
||||
NzString NzEventImpl::GetKeyName(NzKeyboard::Key key)
|
||||
{
|
||||
// http://www.ffuts.org/blog/mapvirtualkey-getkeynametext-and-a-story-of-how-to/
|
||||
int vk = vKeys[key];
|
||||
unsigned int code = MapVirtualKeyW(vk, 0) << 16;
|
||||
|
||||
///FIXME: Liste complète ?
|
||||
switch (vk)
|
||||
{
|
||||
case VK_ATTN:
|
||||
case VK_DOWN:
|
||||
case VK_DELETE:
|
||||
case VK_DIVIDE:
|
||||
case VK_END:
|
||||
case VK_HOME:
|
||||
case VK_INSERT:
|
||||
case VK_LEFT:
|
||||
case VK_LWIN:
|
||||
case VK_OEM_1:
|
||||
case VK_OEM_2:
|
||||
case VK_OEM_3:
|
||||
case VK_OEM_4:
|
||||
case VK_OEM_5:
|
||||
case VK_OEM_6:
|
||||
case VK_OEM_7:
|
||||
case VK_OEM_CLEAR:
|
||||
case VK_OEM_COMMA:
|
||||
case VK_OEM_MINUS:
|
||||
case VK_OEM_PERIOD:
|
||||
case VK_OEM_PLUS:
|
||||
case VK_PAUSE:
|
||||
case VK_NEXT:
|
||||
case VK_NUMLOCK:
|
||||
case VK_PRIOR:
|
||||
case VK_RIGHT:
|
||||
case VK_RWIN:
|
||||
case VK_UP:
|
||||
code |= 0x1000000; // 24ème bit pour l'extension
|
||||
break;
|
||||
}
|
||||
|
||||
wchar_t keyName[20]; // Je ne pense pas que ça dépassera 20 caractères
|
||||
if (!GetKeyNameTextW(code, &keyName[0], 20))
|
||||
return "Unknown";
|
||||
|
||||
return NzString::Unicode(keyName);
|
||||
}
|
||||
|
||||
NzVector2i NzEventImpl::GetMousePosition()
|
||||
{
|
||||
POINT pos;
|
||||
GetCursorPos(&pos);
|
||||
|
||||
return NzVector2i(pos.x, pos.y);
|
||||
}
|
||||
|
||||
NzVector2i NzEventImpl::GetMousePosition(const NzWindow& relativeTo)
|
||||
{
|
||||
HWND handle = reinterpret_cast<HWND>(relativeTo.GetHandle());
|
||||
if (handle)
|
||||
{
|
||||
POINT pos;
|
||||
GetCursorPos(&pos);
|
||||
ScreenToClient(handle, &pos);
|
||||
|
||||
return NzVector2i(pos.x, pos.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
NazaraError("Window's handle is invalid");
|
||||
|
||||
// Attention que (-1, -1) est une position tout à fait valide et ne doit pas être utilisée pour tester l'erreur
|
||||
return NzVector2i(-1, -1);
|
||||
}
|
||||
}
|
||||
|
||||
bool NzEventImpl::IsKeyPressed(NzKeyboard::Key key)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case NzKeyboard::CapsLock:
|
||||
|
||||
@@ -8,12 +8,14 @@
|
||||
#define NAZARA_INPUTIMPL_HPP
|
||||
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Utility/Keyboard.hpp>
|
||||
#include <Nazara/Utility/Mouse.hpp>
|
||||
|
||||
class NzEventImpl
|
||||
{
|
||||
public:
|
||||
static NzString GetKeyName(NzKeyboard::Key key);
|
||||
static NzVector2i GetMousePosition();
|
||||
static NzVector2i GetMousePosition(const NzWindow& relativeTo);
|
||||
static bool IsKeyPressed(NzKeyboard::Key key);
|
||||
|
||||
Reference in New Issue
Block a user