From cd5399459d3e3ea22a09a55ee0f170e633bfb2af Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 16 Jan 2015 16:28:38 +0100 Subject: [PATCH] Made Resource copying/moving impossible It is still possible to copy some Resource-based classes though Former-commit-id: bbb6066f736c210015ff9fdfded7d95eb9695359 --- include/Nazara/Core/Resource.hpp | 5 ++++ include/Nazara/Graphics/Material.hpp | 2 -- include/Nazara/Renderer/Texture.hpp | 3 -- include/Nazara/Utility/Image.hpp | 2 -- src/Nazara/Graphics/Material.cpp | 42 ---------------------------- src/Nazara/Renderer/Texture.cpp | 42 +++++++++------------------- src/Nazara/Utility/Image.cpp | 13 --------- 7 files changed, 18 insertions(+), 91 deletions(-) diff --git a/include/Nazara/Core/Resource.hpp b/include/Nazara/Core/Resource.hpp index adf0eace2..2bc392734 100644 --- a/include/Nazara/Core/Resource.hpp +++ b/include/Nazara/Core/Resource.hpp @@ -23,6 +23,8 @@ class NAZARA_API NzResource { public: NzResource(bool persistent = true); + NzResource(const NzResource& resource) = delete; + NzResource(NzResource&& resource) = delete; virtual ~NzResource(); void AddResourceListener(NzResourceListener* listener, int index = 0) const; @@ -37,6 +39,9 @@ class NAZARA_API NzResource bool SetPersistent(bool persistent = true, bool checkReferenceCount = false); + NzResource& operator=(const NzResource& resource) = delete; + NzResource& operator=(NzResource&& resource) = delete; + protected: void NotifyCreated(); void NotifyDestroy(); diff --git a/include/Nazara/Graphics/Material.hpp b/include/Nazara/Graphics/Material.hpp index a4192b0e3..ffe7f8217 100644 --- a/include/Nazara/Graphics/Material.hpp +++ b/include/Nazara/Graphics/Material.hpp @@ -46,7 +46,6 @@ class NAZARA_API NzMaterial : public NzResource public: NzMaterial(); NzMaterial(const NzMaterial& material); - NzMaterial(NzMaterial&& material); ~NzMaterial(); const NzShader* Apply(nzUInt32 shaderFlags = 0, nzUInt8 textureUnit = 0, nzUInt8* lastUsedUnit = nullptr) const; @@ -127,7 +126,6 @@ class NAZARA_API NzMaterial : public NzResource void SetSrcBlend(nzBlendFunc func); NzMaterial& operator=(const NzMaterial& material); - NzMaterial& operator=(NzMaterial&& material); static NzMaterial* GetDefault(); diff --git a/include/Nazara/Renderer/Texture.hpp b/include/Nazara/Renderer/Texture.hpp index 5c082cc2e..02a1a208f 100644 --- a/include/Nazara/Renderer/Texture.hpp +++ b/include/Nazara/Renderer/Texture.hpp @@ -31,7 +31,6 @@ class NAZARA_API NzTexture : public NzAbstractImage, public NzResource, NzNonCop NzTexture() = default; NzTexture(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth = 1, nzUInt8 levelCount = 1); explicit NzTexture(const NzImage& image); - NzTexture(NzTexture&& texture); ~NzTexture(); bool Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth = 1, nzUInt8 levelCount = 1); @@ -94,8 +93,6 @@ class NAZARA_API NzTexture : public NzAbstractImage, public NzResource, NzNonCop // Fonctions OpenGL unsigned int GetOpenGLID() const; - NzTexture& operator=(NzTexture&& texture); - static unsigned int GetValidSize(unsigned int size); static bool IsFormatSupported(nzPixelFormat format); static bool IsMipmappingSupported(); diff --git a/include/Nazara/Utility/Image.hpp b/include/Nazara/Utility/Image.hpp index d94177bbe..57c188822 100644 --- a/include/Nazara/Utility/Image.hpp +++ b/include/Nazara/Utility/Image.hpp @@ -46,7 +46,6 @@ class NAZARA_API NzImage : public NzAbstractImage, public NzResource NzImage(); NzImage(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth = 1, nzUInt8 levelCount = 1); NzImage(const NzImage& image); - NzImage(NzImage&& image) noexcept; NzImage(SharedImage* sharedImage); ~NzImage(); @@ -105,7 +104,6 @@ class NAZARA_API NzImage : public NzAbstractImage, public NzResource bool Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0); NzImage& operator=(const NzImage& image); - NzImage& operator=(NzImage&& image) noexcept; 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); diff --git a/src/Nazara/Graphics/Material.cpp b/src/Nazara/Graphics/Material.cpp index e674f8e96..8a6ca4357 100644 --- a/src/Nazara/Graphics/Material.cpp +++ b/src/Nazara/Graphics/Material.cpp @@ -34,11 +34,6 @@ NzResource() Copy(material); } -NzMaterial::NzMaterial(NzMaterial&& material) -{ - Move(material); -} - NzMaterial::~NzMaterial() { NotifyDestroy(); @@ -613,13 +608,6 @@ NzMaterial& NzMaterial::operator=(const NzMaterial& material) return *this; } -NzMaterial& NzMaterial::operator=(NzMaterial&& material) -{ - Move(material); - - return *this; -} - NzMaterial* NzMaterial::GetDefault() { return s_defaultMaterial; @@ -655,36 +643,6 @@ void NzMaterial::Copy(const NzMaterial& material) std::memcpy(&m_shaders[0], &material.m_shaders[0], (nzShaderFlags_Max+1)*sizeof(ShaderInstance)); } -void NzMaterial::Move(NzMaterial&& material) -{ - // Copie des états de base - m_alphaTestEnabled = material.m_alphaTestEnabled; - m_alphaThreshold = material.m_alphaThreshold; - m_ambientColor = material.m_ambientColor; - m_diffuseColor = material.m_diffuseColor; - m_diffuseSampler = material.m_diffuseSampler; - m_lightingEnabled = material.m_lightingEnabled; - m_shininess = material.m_shininess; - m_specularColor = material.m_specularColor; - m_specularSampler = material.m_specularSampler; - m_states = material.m_states; - m_transformEnabled = material.m_transformEnabled; - - // Vol des références de texture - m_alphaMap = std::move(material.m_alphaMap); - m_diffuseMap = std::move(material.m_diffuseMap); - m_emissiveMap = std::move(material.m_emissiveMap); - m_heightMap = std::move(material.m_heightMap); - m_normalMap = std::move(material.m_normalMap); - m_specularMap = std::move(material.m_specularMap); - - // Vol de la référence vers l'Über-Shader - m_uberShader = std::move(material.m_uberShader); - - // On copie les instances de shader par la même occasion - std::memcpy(&m_shaders[0], &material.m_shaders[0], (nzShaderFlags_Max+1)*sizeof(ShaderInstance)); -} - void NzMaterial::GenerateShader(nzUInt32 flags) const { NzParameterList list; diff --git a/src/Nazara/Renderer/Texture.cpp b/src/Nazara/Renderer/Texture.cpp index 80b580312..bee9c9ae8 100644 --- a/src/Nazara/Renderer/Texture.cpp +++ b/src/Nazara/Renderer/Texture.cpp @@ -60,12 +60,6 @@ NzTexture::NzTexture(const NzImage& image) LoadFromImage(image); } -NzTexture::NzTexture(NzTexture&& texture) : -m_impl(texture.m_impl) -{ - texture.m_impl = nullptr; -} - NzTexture::~NzTexture() { Destroy(); @@ -477,6 +471,19 @@ bool NzTexture::HasMipmaps() const return m_impl->levelCount > 1; } +void NzTexture::InvalidateMipmaps() +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraInternalError("Texture must be valid"); + return; + } + #endif + + m_impl->mipmapsUpdated = false; +} + bool NzTexture::IsValid() const { return m_impl != nullptr; @@ -1031,16 +1038,6 @@ unsigned int NzTexture::GetOpenGLID() const return m_impl->id; } -NzTexture& NzTexture::operator=(NzTexture&& texture) -{ - Destroy(); - - m_impl = texture.m_impl; - texture.m_impl = nullptr; - - return *this; -} - unsigned int NzTexture::GetValidSize(unsigned int size) { if (NzRenderer::HasCapability(nzRendererCap_TextureNPOT)) @@ -1277,16 +1274,3 @@ bool NzTexture::CreateTexture(bool proxy) return true; } - -void NzTexture::InvalidateMipmaps() -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraInternalError("Texture must be valid"); - return; - } - #endif - - m_impl->mipmapsUpdated = false; -} diff --git a/src/Nazara/Utility/Image.cpp b/src/Nazara/Utility/Image.cpp index 4cc9297d2..b25ccdfd4 100644 --- a/src/Nazara/Utility/Image.cpp +++ b/src/Nazara/Utility/Image.cpp @@ -57,12 +57,6 @@ m_sharedImage(image.m_sharedImage) m_sharedImage->refCount++; } -NzImage::NzImage(NzImage&& image) noexcept : -m_sharedImage(image.m_sharedImage) -{ - image.m_sharedImage = &emptyImage; -} - NzImage::NzImage(SharedImage* sharedImage) : m_sharedImage(sharedImage) { @@ -1283,13 +1277,6 @@ NzImage& NzImage::operator=(const NzImage& image) return *this; } -NzImage& NzImage::operator=(NzImage&& image) noexcept -{ - std::swap(m_sharedImage, image.m_sharedImage); - - return *this; -} - void NzImage::Copy(nzUInt8* destination, const nzUInt8* source, nzUInt8 bpp, unsigned int width, unsigned int height, unsigned int depth, unsigned int dstWidth, unsigned int dstHeight, unsigned int srcWidth, unsigned int srcHeight) { if (dstWidth == 0)