Merge branch 'master' into Particle-Update

Former-commit-id: a015cefb77bfb41617e94368ac58f5cfe12266fe
This commit is contained in:
Lynix 2014-08-18 19:11:43 +02:00
commit f3baf9f9df
16 changed files with 273 additions and 155 deletions

View File

@ -62,6 +62,12 @@ class NAZARA_API NzTexture : public NzResource, NzNonCopyable
bool LoadFromMemory(const void* data, std::size_t size, const NzImageParams& params = NzImageParams(), bool generateMipmaps = true); bool LoadFromMemory(const void* data, std::size_t size, const NzImageParams& params = NzImageParams(), bool generateMipmaps = true);
bool LoadFromStream(NzInputStream& stream, const NzImageParams& params = NzImageParams(), bool generateMipmaps = true); bool LoadFromStream(NzInputStream& stream, const NzImageParams& params = NzImageParams(), bool generateMipmaps = true);
// LoadArray
bool LoadArrayFromFile(const NzString& filePath, const NzImageParams& imageParams = NzImageParams(), bool generateMipmaps = true, const NzVector2ui& atlasSize = NzVector2ui(2, 2));
bool LoadArrayFromImage(const NzImage& image, bool generateMipmaps = true, const NzVector2ui& atlasSize = NzVector2ui(2, 2));
bool LoadArrayFromMemory(const void* data, std::size_t size, const NzImageParams& imageParams = NzImageParams(), bool generateMipmaps = true, const NzVector2ui& atlasSize = NzVector2ui(2, 2));
bool LoadArrayFromStream(NzInputStream& stream, const NzImageParams& imageParams = NzImageParams(), bool generateMipmaps = true, const NzVector2ui& atlasSize = NzVector2ui(2, 2));
// LoadCubemap // LoadCubemap
bool LoadCubemapFromFile(const NzString& filePath, const NzImageParams& imageParams = NzImageParams(), bool generateMipmaps = true, const NzCubemapParams& cubemapParams = NzCubemapParams()); bool LoadCubemapFromFile(const NzString& filePath, const NzImageParams& imageParams = NzImageParams(), bool generateMipmaps = true, const NzCubemapParams& cubemapParams = NzCubemapParams());
bool LoadCubemapFromImage(const NzImage& image, bool generateMipmaps = true, const NzCubemapParams& params = NzCubemapParams()); bool LoadCubemapFromImage(const NzImage& image, bool generateMipmaps = true, const NzCubemapParams& params = NzCubemapParams());

View File

@ -91,6 +91,12 @@ class NAZARA_API NzImage : public NzResource
bool LoadFromMemory(const void* data, std::size_t size, const NzImageParams& params = NzImageParams()); bool LoadFromMemory(const void* data, std::size_t size, const NzImageParams& params = NzImageParams());
bool LoadFromStream(NzInputStream& stream, const NzImageParams& params = NzImageParams()); bool LoadFromStream(NzInputStream& stream, const NzImageParams& params = NzImageParams());
// LoadArray
bool LoadArrayFromFile(const NzString& filePath, const NzImageParams& imageParams = NzImageParams(), const NzVector2ui& atlasSize = NzVector2ui(2, 2));
bool LoadArrayFromImage(const NzImage& image, const NzVector2ui& atlasSize = NzVector2ui(2, 2));
bool LoadArrayFromMemory(const void* data, std::size_t size, const NzImageParams& imageParams = NzImageParams(), const NzVector2ui& atlasSize = NzVector2ui(2, 2));
bool LoadArrayFromStream(NzInputStream& stream, const NzImageParams& imageParams = NzImageParams(), const NzVector2ui& atlasSize = NzVector2ui(2, 2));
// LoadCubemap // LoadCubemap
bool LoadCubemapFromFile(const NzString& filePath, const NzImageParams& imageParams = NzImageParams(), const NzCubemapParams& cubemapParams = NzCubemapParams()); bool LoadCubemapFromFile(const NzString& filePath, const NzImageParams& imageParams = NzImageParams(), const NzCubemapParams& cubemapParams = NzCubemapParams());
bool LoadCubemapFromImage(const NzImage& image, const NzCubemapParams& params = NzCubemapParams()); bool LoadCubemapFromImage(const NzImage& image, const NzCubemapParams& params = NzCubemapParams());
@ -109,6 +115,7 @@ class NAZARA_API NzImage : public NzResource
static void Copy(nzUInt8* destination, const nzUInt8* source, nzUInt8 bpp, unsigned int width, unsigned int height, unsigned int depth = 1, unsigned int dstWidth = 0, unsigned int dstHeight = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0); static void Copy(nzUInt8* destination, const nzUInt8* source, nzUInt8 bpp, unsigned int width, unsigned int height, unsigned int depth = 1, unsigned int dstWidth = 0, unsigned int dstHeight = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0);
static nzUInt8 GetMaxLevel(unsigned int width, unsigned int height, unsigned int depth = 1); static nzUInt8 GetMaxLevel(unsigned int width, unsigned int height, unsigned int depth = 1);
static nzUInt8 GetMaxLevel(nzImageType type, unsigned int width, unsigned int height, unsigned int depth = 1);
struct SharedImage struct SharedImage
{ {

View File

@ -21,6 +21,7 @@ class NAZARA_API NzIndexBuffer : public NzResource
{ {
public: public:
NzIndexBuffer() = default; NzIndexBuffer() = default;
NzIndexBuffer(bool largeIndices, NzBuffer* buffer);
NzIndexBuffer(bool largeIndices, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset); NzIndexBuffer(bool largeIndices, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset);
NzIndexBuffer(bool largeIndices, unsigned int length, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static); NzIndexBuffer(bool largeIndices, unsigned int length, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
NzIndexBuffer(const NzIndexBuffer& indexBuffer); NzIndexBuffer(const NzIndexBuffer& indexBuffer);
@ -51,6 +52,7 @@ class NAZARA_API NzIndexBuffer : public NzResource
void Optimize(); void Optimize();
void Reset(); void Reset();
void Reset(bool largeIndices, NzBuffer* buffer);
void Reset(bool largeIndices, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset); void Reset(bool largeIndices, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset);
void Reset(bool largeIndices, unsigned int length, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static); void Reset(bool largeIndices, unsigned int length, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
void Reset(const NzIndexBuffer& indexBuffer); void Reset(const NzIndexBuffer& indexBuffer);

View File

@ -22,6 +22,7 @@ class NAZARA_API NzVertexBuffer : public NzResource
{ {
public: public:
NzVertexBuffer() = default; NzVertexBuffer() = default;
NzVertexBuffer(const NzVertexDeclaration* vertexDeclaration, NzBuffer* buffer);
NzVertexBuffer(const NzVertexDeclaration* vertexDeclaration, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset); NzVertexBuffer(const NzVertexDeclaration* vertexDeclaration, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset);
NzVertexBuffer(const NzVertexDeclaration* vertexDeclaration, unsigned int length, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static); NzVertexBuffer(const NzVertexDeclaration* vertexDeclaration, unsigned int length, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
NzVertexBuffer(const NzVertexBuffer& vertexBuffer); NzVertexBuffer(const NzVertexBuffer& vertexBuffer);
@ -47,6 +48,7 @@ class NAZARA_API NzVertexBuffer : public NzResource
void* MapRaw(nzBufferAccess access, unsigned int offset = 0, unsigned int size = 0) const; void* MapRaw(nzBufferAccess access, unsigned int offset = 0, unsigned int size = 0) const;
void Reset(); void Reset();
void Reset(const NzVertexDeclaration* vertexDeclaration, NzBuffer* buffer);
void Reset(const NzVertexDeclaration* vertexDeclaration, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset); void Reset(const NzVertexDeclaration* vertexDeclaration, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset);
void Reset(const NzVertexDeclaration* vertexDeclaration, unsigned int length, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static); void Reset(const NzVertexDeclaration* vertexDeclaration, unsigned int length, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
void Reset(const NzVertexBuffer& vertexBuffer); void Reset(const NzVertexBuffer& vertexBuffer);

View File

@ -396,7 +396,7 @@ void NzModel::SetSkinCount(unsigned int skinCount)
#if NAZARA_GRAPHICS_SAFE #if NAZARA_GRAPHICS_SAFE
if (skinCount == 0) if (skinCount == 0)
{ {
NazaraError("Skin count must be over 0"); NazaraError("Skin count must be over zero");
return; return;
} }
#endif #endif

View File

@ -661,7 +661,7 @@ bool NzDebugDrawer::Initialize()
// s_vertexBuffer // s_vertexBuffer
try try
{ {
NzErrorFlags flags(nzErrorFlag_ThrowException); NzErrorFlags flags(nzErrorFlag_ThrowException, true);
s_vertexBuffer.Reset(NzVertexDeclaration::Get(nzVertexLayout_XYZ), 65365, nzBufferStorage_Hardware, nzBufferUsage_Dynamic); s_vertexBuffer.Reset(NzVertexDeclaration::Get(nzVertexLayout_XYZ), 65365, nzBufferStorage_Hardware, nzBufferUsage_Dynamic);
} }
catch (const std::exception& e) catch (const std::exception& e)

View File

@ -4,6 +4,7 @@
#include <Nazara/Renderer/RenderWindow.hpp> #include <Nazara/Renderer/RenderWindow.hpp>
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Core/Thread.hpp> #include <Nazara/Core/Thread.hpp>
#include <Nazara/Renderer/Context.hpp> #include <Nazara/Renderer/Context.hpp>
#include <Nazara/Renderer/OpenGL.hpp> #include <Nazara/Renderer/OpenGL.hpp>
@ -12,30 +13,18 @@
#include <stdexcept> #include <stdexcept>
#include <Nazara/Renderer/Debug.hpp> #include <Nazara/Renderer/Debug.hpp>
///TODO: Améliorer les méthode CopyTo*
NzRenderWindow::NzRenderWindow(NzVideoMode mode, const NzString& title, nzUInt32 style, const NzContextParameters& parameters) NzRenderWindow::NzRenderWindow(NzVideoMode mode, const NzString& title, nzUInt32 style, const NzContextParameters& parameters)
{ {
NzErrorFlags flags(nzErrorFlag_ThrowException, true);
Create(mode, title, style, parameters); Create(mode, title, style, parameters);
#ifdef NAZARA_DEBUG
if (!m_impl)
{
NazaraError("Failed to create render window");
throw std::runtime_error("Constructor failed");
}
#endif
} }
NzRenderWindow::NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters) NzRenderWindow::NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters)
{ {
NzErrorFlags flags(nzErrorFlag_ThrowException, true);
Create(handle, parameters); Create(handle, parameters);
#ifdef NAZARA_DEBUG
if (!m_impl)
{
NazaraError("Failed to create render window");
throw std::runtime_error("Constructor failed");
}
#endif
} }
NzRenderWindow::~NzRenderWindow() NzRenderWindow::~NzRenderWindow()

View File

@ -375,7 +375,7 @@ void NzRenderer::DrawIndexedPrimitivesInstanced(unsigned int instanceCount, nzPr
if (instanceCount == 0) if (instanceCount == 0)
{ {
NazaraError("Instance count must be over 0"); NazaraError("Instance count must be over zero");
return; return;
} }
@ -470,7 +470,7 @@ void NzRenderer::DrawPrimitivesInstanced(unsigned int instanceCount, nzPrimitive
if (instanceCount == 0) if (instanceCount == 0)
{ {
NazaraError("Instance count must be over 0"); NazaraError("Instance count must be over zero");
return; return;
} }
@ -1786,6 +1786,8 @@ bool NzRenderer::EnsureStateUpdate()
unsigned int offset; unsigned int offset;
vertexDeclaration->GetComponent(static_cast<nzVertexComponent>(j), &enabled, &type, &offset); vertexDeclaration->GetComponent(static_cast<nzVertexComponent>(j), &enabled, &type, &offset);
if (enabled)
{
if (!IsComponentTypeSupported(type)) if (!IsComponentTypeSupported(type))
{ {
NazaraError("Invalid vertex declaration " + NzString::Pointer(vertexDeclaration) + ": Vertex component 0x" + NzString::Number(j, 16) + " (type: 0x" + NzString::Number(type, 16) + ") is not supported"); NazaraError("Invalid vertex declaration " + NzString::Pointer(vertexDeclaration) + ": Vertex component 0x" + NzString::Number(j, 16) + " (type: 0x" + NzString::Number(type, 16) + ") is not supported");
@ -1793,8 +1795,6 @@ bool NzRenderer::EnsureStateUpdate()
break; break;
} }
if (enabled)
{
glEnableVertexAttribArray(NzOpenGL::VertexComponentIndex[j]); glEnableVertexAttribArray(NzOpenGL::VertexComponentIndex[j]);
switch (type) switch (type)

View File

@ -11,6 +11,8 @@
#include <stdexcept> #include <stdexcept>
#include <Nazara/Renderer/Debug.hpp> #include <Nazara/Renderer/Debug.hpp>
///TODO: Virer les méthodes faisant référence aux faces et gérer ces dernières comme de simples niveaux de profondeurs (malgré OpenGL)
struct NzTextureImpl struct NzTextureImpl
{ {
GLuint id; GLuint id;
@ -659,124 +661,100 @@ bool NzTexture::LoadFromStream(NzInputStream& stream, const NzImageParams& param
return LoadFromImage(image, generateMipmaps); return LoadFromImage(image, generateMipmaps);
} }
bool NzTexture::LoadCubemapFromFile(const NzString& filePath, const NzImageParams& imageParams, bool generateMipmaps, const NzCubemapParams& cubemapParams) bool NzTexture::LoadArrayFromFile(const NzString& filePath, const NzImageParams& imageParams, bool generateMipmaps, const NzVector2ui& atlasSize)
{ {
NzImage image; NzImage cubemap;
if (!image.LoadFromFile(filePath, imageParams)) if (!cubemap.LoadArrayFromFile(filePath, imageParams, atlasSize))
{ {
NazaraError("Failed to load image"); NazaraError("Failed to load cubemap");
return false; return false;
} }
return LoadCubemapFromImage(image, generateMipmaps, cubemapParams); return LoadFromImage(cubemap, generateMipmaps);
}
bool NzTexture::LoadArrayFromImage(const NzImage& image, bool generateMipmaps, const NzVector2ui& atlasSize)
{
NzImage cubemap;
if (!cubemap.LoadArrayFromImage(image, atlasSize))
{
NazaraError("Failed to load cubemap");
return false;
}
return LoadFromImage(cubemap, generateMipmaps);
}
bool NzTexture::LoadArrayFromMemory(const void* data, std::size_t size, const NzImageParams& imageParams, bool generateMipmaps, const NzVector2ui& atlasSize)
{
NzImage cubemap;
if (!cubemap.LoadArrayFromMemory(data, size, imageParams, atlasSize))
{
NazaraError("Failed to load cubemap");
return false;
}
return LoadFromImage(cubemap, generateMipmaps);
}
bool NzTexture::LoadArrayFromStream(NzInputStream& stream, const NzImageParams& imageParams, bool generateMipmaps, const NzVector2ui& atlasSize)
{
NzImage cubemap;
if (!cubemap.LoadArrayFromStream(stream, imageParams, atlasSize))
{
NazaraError("Failed to load cubemap");
return false;
}
return LoadFromImage(cubemap, generateMipmaps);
}
bool NzTexture::LoadCubemapFromFile(const NzString& filePath, const NzImageParams& imageParams, bool generateMipmaps, const NzCubemapParams& cubemapParams)
{
NzImage cubemap;
if (!cubemap.LoadCubemapFromFile(filePath, imageParams, cubemapParams))
{
NazaraError("Failed to load cubemap");
return false;
}
return LoadFromImage(cubemap, generateMipmaps);
} }
bool NzTexture::LoadCubemapFromImage(const NzImage& image, bool generateMipmaps, const NzCubemapParams& params) bool NzTexture::LoadCubemapFromImage(const NzImage& image, bool generateMipmaps, const NzCubemapParams& params)
{ {
// Implémentation presque identique à celle de Image::LoadCubemapFromImage NzImage cubemap;
#if NAZARA_UTILITY_SAFE if (!cubemap.LoadCubemapFromImage(image, params))
if (!image.IsValid())
{ {
NazaraError("Image must be valid"); NazaraError("Failed to load cubemap");
return false;
}
#endif
unsigned int width = image.GetWidth();
unsigned int height = image.GetHeight();
unsigned int faceSize = (params.faceSize == 0) ? std::max(width, height)/4 : params.faceSize;
// Sans cette vérification, celles des rectangles pourrait réussir via un overflow
if (width < faceSize || height < faceSize)
{
NazaraError("Image is too small for this face size");
return false; return false;
} }
// Calcul et vérification des surfaces return LoadFromImage(cubemap, generateMipmaps);
unsigned limitX = width - faceSize;
unsigned limitY = height - faceSize;
NzVector2ui backPos = params.backPosition * faceSize;
if (backPos.x > limitX || backPos.y > limitY)
{
NazaraError("Back rectangle is out of image");
return false;
}
NzVector2ui downPos = params.downPosition * faceSize;
if (downPos.x > limitX || downPos.y > limitY)
{
NazaraError("Down rectangle is out of image");
return false;
}
NzVector2ui forwardPos = params.forwardPosition * faceSize;
if (forwardPos.x > limitX || forwardPos.y > limitY)
{
NazaraError("Forward rectangle is out of image");
return false;
}
NzVector2ui leftPos = params.leftPosition * faceSize;
if (leftPos.x > limitX || leftPos.y > limitY)
{
NazaraError("Left rectangle is out of image");
return false;
}
NzVector2ui rightPos = params.rightPosition * faceSize;
if (rightPos.x > limitX || rightPos.y > limitY)
{
NazaraError("Right rectangle is out of image");
return false;
}
NzVector2ui upPos = params.upPosition * faceSize;
if (upPos.x > limitX || upPos.y > limitY)
{
NazaraError("Up rectangle is out of image");
return false;
}
if (!Create(nzImageType_Cubemap, image.GetFormat(), faceSize, faceSize, 1, (generateMipmaps) ? 0xFF : 1))
{
NazaraError("Failed to create texture");
return false;
}
UpdateFace(nzCubemapFace_NegativeX, image.GetConstPixels(leftPos.x, leftPos.y), width, height);
UpdateFace(nzCubemapFace_NegativeY, image.GetConstPixels(downPos.x, downPos.y), width, height);
UpdateFace(nzCubemapFace_NegativeZ, image.GetConstPixels(backPos.x, backPos.y), width, height);
UpdateFace(nzCubemapFace_PositiveX, image.GetConstPixels(rightPos.x, rightPos.y), width, height);
UpdateFace(nzCubemapFace_PositiveY, image.GetConstPixels(upPos.x, upPos.y), width, height);
UpdateFace(nzCubemapFace_PositiveZ, image.GetConstPixels(forwardPos.x, forwardPos.y), width, height);
return true;
} }
bool NzTexture::LoadCubemapFromMemory(const void* data, std::size_t size, const NzImageParams& imageParams, bool generateMipmaps, const NzCubemapParams& cubemapParams) bool NzTexture::LoadCubemapFromMemory(const void* data, std::size_t size, const NzImageParams& imageParams, bool generateMipmaps, const NzCubemapParams& cubemapParams)
{ {
NzImage image; NzImage cubemap;
if (!image.LoadFromMemory(data, size, imageParams)) if (!cubemap.LoadCubemapFromMemory(data, size, imageParams, cubemapParams))
{ {
NazaraError("Failed to load image"); NazaraError("Failed to load cubemap");
return false; return false;
} }
return LoadCubemapFromImage(image, generateMipmaps, cubemapParams); return LoadFromImage(cubemap, generateMipmaps);
} }
bool NzTexture::LoadCubemapFromStream(NzInputStream& stream, const NzImageParams& imageParams, bool generateMipmaps, const NzCubemapParams& cubemapParams) bool NzTexture::LoadCubemapFromStream(NzInputStream& stream, const NzImageParams& imageParams, bool generateMipmaps, const NzCubemapParams& cubemapParams)
{ {
NzImage image; NzImage cubemap;
if (!image.LoadFromStream(stream, imageParams)) if (!cubemap.LoadCubemapFromStream(stream, imageParams, cubemapParams))
{ {
NazaraError("Failed to load image"); NazaraError("Failed to load cubemap");
return false; return false;
} }
return LoadCubemapFromImage(image, generateMipmaps, cubemapParams); return LoadFromImage(cubemap, generateMipmaps);
} }
bool NzTexture::LoadFaceFromFile(nzCubemapFace face, const NzString& filePath, const NzImageParams& params) bool NzTexture::LoadFaceFromFile(nzCubemapFace face, const NzString& filePath, const NzImageParams& params)
@ -809,7 +787,6 @@ bool NzTexture::LoadFaceFromFile(nzCubemapFace face, const NzString& filePath, c
} }
unsigned int faceSize = m_impl->width; unsigned int faceSize = m_impl->width;
if (image.GetWidth() != faceSize || image.GetHeight() != faceSize) if (image.GetWidth() != faceSize || image.GetHeight() != faceSize)
{ {
NazaraError("Image size must match texture face size"); NazaraError("Image size must match texture face size");
@ -849,7 +826,6 @@ bool NzTexture::LoadFaceFromMemory(nzCubemapFace face, const void* data, std::si
} }
unsigned int faceSize = m_impl->width; unsigned int faceSize = m_impl->width;
if (image.GetWidth() != faceSize || image.GetHeight() != faceSize) if (image.GetWidth() != faceSize || image.GetHeight() != faceSize)
{ {
NazaraError("Image size must match texture face size"); NazaraError("Image size must match texture face size");

View File

@ -48,7 +48,7 @@ bool NzAnimation::AddSequence(const NzSequence& sequence)
if (sequence.frameCount == 0) if (sequence.frameCount == 0)
{ {
NazaraError("Sequence frame count must be over 0"); NazaraError("Sequence frame count must be over zero");
return false; return false;
} }
#endif #endif

View File

@ -4,6 +4,7 @@
#include <Nazara/Utility/Buffer.hpp> #include <Nazara/Utility/Buffer.hpp>
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Utility/AbstractBuffer.hpp> #include <Nazara/Utility/AbstractBuffer.hpp>
#include <Nazara/Utility/BufferMapper.hpp> #include <Nazara/Utility/BufferMapper.hpp>
#include <Nazara/Utility/Config.hpp> #include <Nazara/Utility/Config.hpp>
@ -32,15 +33,8 @@ NzBuffer::NzBuffer(nzBufferType type, unsigned int size, nzBufferStorage storage
m_type(type), m_type(type),
m_impl(nullptr) m_impl(nullptr)
{ {
NzErrorFlags flags(nzErrorFlag_ThrowException, true);
Create(size, storage, usage); Create(size, storage, usage);
#ifdef NAZARA_DEBUG
if (!m_impl)
{
NazaraError("Failed to create buffer");
throw std::runtime_error("Constructor failed");
}
#endif
} }
NzBuffer::~NzBuffer() NzBuffer::~NzBuffer()

View File

@ -227,13 +227,13 @@ bool NzImage::Create(nzImageType type, nzPixelFormat format, unsigned int width,
case nzImageType_1D: case nzImageType_1D:
if (height > 1) if (height > 1)
{ {
NazaraError("1D textures must be 1 height"); NazaraError("1D textures must be 1 tall");
return false; return false;
} }
if (depth > 1) if (depth > 1)
{ {
NazaraError("1D textures must be 1 depth"); NazaraError("1D textures must be 1 deep");
return false; return false;
} }
break; break;
@ -242,7 +242,7 @@ bool NzImage::Create(nzImageType type, nzPixelFormat format, unsigned int width,
case nzImageType_2D: case nzImageType_2D:
if (depth > 1) if (depth > 1)
{ {
NazaraError("2D textures must be 1 depth"); NazaraError("2D textures must be 1 deep");
return false; return false;
} }
break; break;
@ -254,7 +254,7 @@ bool NzImage::Create(nzImageType type, nzPixelFormat format, unsigned int width,
case nzImageType_Cubemap: case nzImageType_Cubemap:
if (depth > 1) if (depth > 1)
{ {
NazaraError("Cubemaps must be 1 depth"); NazaraError("Cubemaps must be 1 deep");
return false; return false;
} }
@ -271,7 +271,7 @@ bool NzImage::Create(nzImageType type, nzPixelFormat format, unsigned int width,
} }
#endif #endif
levelCount = std::min(levelCount, GetMaxLevel(width, height, depth)); levelCount = std::min(levelCount, GetMaxLevel(type, width, height, depth));
nzUInt8** levels = new nzUInt8*[levelCount]; nzUInt8** levels = new nzUInt8*[levelCount];
@ -673,7 +673,7 @@ nzUInt8 NzImage::GetLevelCount() const
nzUInt8 NzImage::GetMaxLevel() const nzUInt8 NzImage::GetMaxLevel() const
{ {
return GetMaxLevel(m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth); return GetMaxLevel(m_sharedImage->type, m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth);
} }
NzColor NzImage::GetPixelColor(unsigned int x, unsigned int y, unsigned int z) const NzColor NzImage::GetPixelColor(unsigned int x, unsigned int y, unsigned int z) const
@ -863,6 +863,103 @@ bool NzImage::LoadFromStream(NzInputStream& stream, const NzImageParams& params)
return NzImageLoader::LoadFromStream(this, stream, params); return NzImageLoader::LoadFromStream(this, stream, params);
} }
// LoadArray
bool NzImage::LoadArrayFromFile(const NzString& filePath, const NzImageParams& imageParams, const NzVector2ui& atlasSize)
{
NzImage image;
if (!image.LoadFromFile(filePath, imageParams))
{
NazaraError("Failed to load image");
return false;
}
return LoadArrayFromImage(image, atlasSize);
}
bool NzImage::LoadArrayFromImage(const NzImage& image, const NzVector2ui& atlasSize)
{
#if NAZARA_UTILITY_SAFE
if (!image.IsValid())
{
NazaraError("Image must be valid");
return false;
}
if (atlasSize.x == 0)
{
NazaraError("Atlas width must be over zero");
return false;
}
if (atlasSize.y == 0)
{
NazaraError("Atlas height must be over zero");
return false;
}
#endif
nzImageType type = image.GetType();
#if NAZARA_UTILITY_SAFE
if (type != nzImageType_1D && type != nzImageType_2D)
{
NazaraError("Image type not handled (0x" + NzString::Number(type, 16) + ')');
return false;
}
#endif
NzVector2ui imageSize(image.GetWidth(), image.GetHeight());
if (imageSize.x % atlasSize.x != 0)
{
NazaraWarning("Image width is not divisible by atlas width (" + NzString::Number(imageSize.x) + " mod " + NzString::Number(atlasSize.x) + " != 0)");
}
if (imageSize.y % atlasSize.y != 0)
{
NazaraWarning("Image height is not divisible by atlas height (" + NzString::Number(imageSize.y) + " mod " + NzString::Number(atlasSize.y) + " != 0)");
}
NzVector2ui faceSize = imageSize/atlasSize;
// Selon le type de l'image de base, on va créer un array d'images 2D ou 1D
if (type == nzImageType_2D)
Create(nzImageType_2D_Array, image.GetFormat(), faceSize.x, faceSize.y);
else
Create(nzImageType_1D_Array, image.GetFormat(), faceSize.x, 1);
unsigned int layer = 0;
for (unsigned int i = 0; i < atlasSize.x; ++i)
for (unsigned int j = 0; j < atlasSize.y; ++j)
Copy(image, NzRectui(i*faceSize.x, j*faceSize.y, faceSize.x, faceSize.y), NzVector3ui(0, 0, layer++));
return true;
}
bool NzImage::LoadArrayFromMemory(const void* data, std::size_t size, const NzImageParams& imageParams, const NzVector2ui& atlasSize)
{
NzImage image;
if (!image.LoadFromMemory(data, size, imageParams))
{
NazaraError("Failed to load image");
return false;
}
return LoadArrayFromImage(image, atlasSize);
}
bool NzImage::LoadArrayFromStream(NzInputStream& stream, const NzImageParams& imageParams, const NzVector2ui& atlasSize)
{
NzImage image;
if (!image.LoadFromStream(stream, imageParams))
{
NazaraError("Failed to load image");
return false;
}
return LoadArrayFromImage(image, atlasSize);
}
bool NzImage::LoadCubemapFromFile(const NzString& filePath, const NzImageParams& imageParams, const NzCubemapParams& cubemapParams) bool NzImage::LoadCubemapFromFile(const NzString& filePath, const NzImageParams& imageParams, const NzCubemapParams& cubemapParams)
{ {
NzImage image; NzImage image;
@ -883,6 +980,13 @@ bool NzImage::LoadCubemapFromImage(const NzImage& image, const NzCubemapParams&
NazaraError("Image must be valid"); NazaraError("Image must be valid");
return false; return false;
} }
nzImageType type = image.GetType();
if (type != nzImageType_2D)
{
NazaraError("Image type not handled (0x" + NzString::Number(type, 16) + ')');
return false;
}
#endif #endif
unsigned int width = image.GetWidth(); unsigned int width = image.GetWidth();
@ -1003,7 +1107,7 @@ void NzImage::SetLevelCount(nzUInt8 levelCount)
} }
#endif #endif
levelCount = std::min(levelCount, GetMaxLevel(m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth)); levelCount = std::min(levelCount, GetMaxLevel());
if (m_sharedImage->levelCount == levelCount) if (m_sharedImage->levelCount == levelCount)
return; return;
@ -1287,6 +1391,29 @@ nzUInt8 NzImage::GetMaxLevel(unsigned int width, unsigned int height, unsigned i
return std::max(std::max(std::max(widthLevel, heightLevel), depthLevel), 1U); return std::max(std::max(std::max(widthLevel, heightLevel), depthLevel), 1U);
} }
nzUInt8 NzImage::GetMaxLevel(nzImageType type, unsigned int width, unsigned int height, unsigned int depth)
{
// Pour éviter que la profondeur ne soit comptée dans le calcul des niveaux
switch (type)
{
case nzImageType_1D:
case nzImageType_1D_Array:
return GetMaxLevel(width, 1U, 1U);
case nzImageType_2D:
case nzImageType_2D_Array:
case nzImageType_Cubemap:
return GetMaxLevel(width, height, 1U);
case nzImageType_3D:
return GetMaxLevel(width, height, depth);
}
NazaraError("Image type not handled (0x" + NzString::Number(type, 16) + ')');
return 0;
}
void NzImage::EnsureOwnership() void NzImage::EnsureOwnership()
{ {
if (m_sharedImage == &emptyImage) if (m_sharedImage == &emptyImage)

View File

@ -4,6 +4,7 @@
#include <Nazara/Utility/IndexBuffer.hpp> #include <Nazara/Utility/IndexBuffer.hpp>
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Utility/Algorithm.hpp> #include <Nazara/Utility/Algorithm.hpp>
#include <Nazara/Utility/Config.hpp> #include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/IndexIterator.hpp> #include <Nazara/Utility/IndexIterator.hpp>
@ -11,13 +12,21 @@
#include <stdexcept> #include <stdexcept>
#include <Nazara/Utility/Debug.hpp> #include <Nazara/Utility/Debug.hpp>
NzIndexBuffer::NzIndexBuffer(bool largeIndices, NzBuffer* buffer)
{
NzErrorFlags(nzErrorFlag_ThrowException, true);
Reset(largeIndices, buffer);
}
NzIndexBuffer::NzIndexBuffer(bool largeIndices, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset) NzIndexBuffer::NzIndexBuffer(bool largeIndices, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset)
{ {
NzErrorFlags(nzErrorFlag_ThrowException, true);
Reset(largeIndices, buffer, startOffset, endOffset); Reset(largeIndices, buffer, startOffset, endOffset);
} }
NzIndexBuffer::NzIndexBuffer(bool largeIndices, unsigned int length, nzBufferStorage storage, nzBufferUsage usage) NzIndexBuffer::NzIndexBuffer(bool largeIndices, unsigned int length, nzBufferStorage storage, nzBufferUsage usage)
{ {
NzErrorFlags(nzErrorFlag_ThrowException, true);
Reset(largeIndices, length, storage, usage); Reset(largeIndices, length, storage, usage);
} }
@ -168,6 +177,11 @@ void NzIndexBuffer::Reset()
m_buffer.Reset(); m_buffer.Reset();
} }
void NzIndexBuffer::Reset(bool largeIndices, NzBuffer* buffer)
{
Reset(largeIndices, buffer, 0, buffer->GetSize()-1);
}
void NzIndexBuffer::Reset(bool largeIndices, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset) void NzIndexBuffer::Reset(bool largeIndices, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset)
{ {
#if NAZARA_UTILITY_SAFE #if NAZARA_UTILITY_SAFE
@ -177,9 +191,9 @@ void NzIndexBuffer::Reset(bool largeIndices, NzBuffer* buffer, unsigned int star
return; return;
} }
if (endOffset > startOffset) if (startOffset > endOffset)
{ {
NazaraError("End offset cannot be over start offset"); NazaraError("Start offset cannot be over end offset");
return; return;
} }

View File

@ -32,7 +32,7 @@ bool NzSkeleton::Create(unsigned int jointCount)
#if NAZARA_UTILITY_SAFE #if NAZARA_UTILITY_SAFE
if (jointCount == 0) if (jointCount == 0)
{ {
NazaraError("Joint count must be over 0"); NazaraError("Joint count must be over zero");
return false; return false;
} }
#endif #endif

View File

@ -4,16 +4,25 @@
#include <Nazara/Utility/VertexBuffer.hpp> #include <Nazara/Utility/VertexBuffer.hpp>
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <stdexcept> #include <stdexcept>
#include <Nazara/Utility/Debug.hpp> #include <Nazara/Utility/Debug.hpp>
NzVertexBuffer::NzVertexBuffer(const NzVertexDeclaration* vertexDeclaration, NzBuffer* buffer)
{
NzErrorFlags(nzErrorFlag_ThrowException, true);
Reset(vertexDeclaration, buffer);
}
NzVertexBuffer::NzVertexBuffer(const NzVertexDeclaration* vertexDeclaration, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset) NzVertexBuffer::NzVertexBuffer(const NzVertexDeclaration* vertexDeclaration, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset)
{ {
NzErrorFlags(nzErrorFlag_ThrowException, true);
Reset(vertexDeclaration, buffer, startOffset, endOffset); Reset(vertexDeclaration, buffer, startOffset, endOffset);
} }
NzVertexBuffer::NzVertexBuffer(const NzVertexDeclaration* vertexDeclaration, unsigned int length, nzBufferStorage storage, nzBufferUsage usage) NzVertexBuffer::NzVertexBuffer(const NzVertexDeclaration* vertexDeclaration, unsigned int length, nzBufferStorage storage, nzBufferUsage usage)
{ {
NzErrorFlags(nzErrorFlag_ThrowException, true);
Reset(vertexDeclaration, length, storage, usage); Reset(vertexDeclaration, length, storage, usage);
} }
@ -180,6 +189,11 @@ void NzVertexBuffer::Reset()
m_vertexDeclaration.Reset(); m_vertexDeclaration.Reset();
} }
void NzVertexBuffer::Reset(const NzVertexDeclaration* vertexDeclaration, NzBuffer* buffer)
{
Reset(vertexDeclaration, buffer, 0, buffer->GetSize()-1);
}
void NzVertexBuffer::Reset(const NzVertexDeclaration* vertexDeclaration, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset) void NzVertexBuffer::Reset(const NzVertexDeclaration* vertexDeclaration, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset)
{ {
#if NAZARA_UTILITY_SAFE #if NAZARA_UTILITY_SAFE
@ -189,9 +203,9 @@ void NzVertexBuffer::Reset(const NzVertexDeclaration* vertexDeclaration, NzBuffe
return; return;
} }
if (endOffset > startOffset) if (startOffset > endOffset)
{ {
NazaraError("End offset cannot be over start offset"); NazaraError("Start offset cannot be over end offset");
return; return;
} }

View File

@ -4,6 +4,7 @@
#include <Nazara/Utility/Window.hpp> #include <Nazara/Utility/Window.hpp>
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Core/LockGuard.hpp> #include <Nazara/Core/LockGuard.hpp>
#include <Nazara/Utility/Cursor.hpp> #include <Nazara/Utility/Cursor.hpp>
#include <Nazara/Utility/Image.hpp> #include <Nazara/Utility/Image.hpp>
@ -45,15 +46,8 @@ m_waitForEvent(false)
m_impl(nullptr) m_impl(nullptr)
#endif #endif
{ {
NzErrorFlags flags(nzErrorFlag_ThrowException, true);
Create(mode, title, style); Create(mode, title, style);
#ifdef NAZARA_DEBUG
if (!m_impl)
{
NazaraError("Failed to create window");
throw std::runtime_error("Constructor failed");
}
#endif
} }
NzWindow::NzWindow(NzWindowHandle handle) : NzWindow::NzWindow(NzWindowHandle handle) :
@ -65,15 +59,8 @@ m_waitForEvent(false)
m_impl(nullptr) m_impl(nullptr)
#endif #endif
{ {
NzErrorFlags flags(nzErrorFlag_ThrowException, true);
Create(handle); Create(handle);
#ifdef NAZARA_DEBUG
if (!m_impl)
{
NazaraError("Failed to create window");
throw std::runtime_error("Constructor failed");
}
#endif
} }
NzWindow::~NzWindow() NzWindow::~NzWindow()