Added a static New method to RefCounted-derived classes

Former-commit-id: efd9e68e050fb6cc7e0df7a7c222ca759c502dc5
This commit is contained in:
Lynix 2015-01-25 23:41:09 +01:00
parent 5f5be93992
commit 0db92e671d
59 changed files with 532 additions and 354 deletions

View File

@ -61,6 +61,7 @@ class NAZARA_API NzSoundBuffer : public NzRefCounted, public NzResource, NzNonCo
bool LoadFromStream(NzInputStream& stream, const NzSoundBufferParams& params = NzSoundBufferParams());
static bool IsFormatSupported(nzAudioFormat format);
template<typename... Args> static NzSoundBufferRef New(Args&&... args);
private:
unsigned int GetOpenALBuffer() const;
@ -70,4 +71,6 @@ class NAZARA_API NzSoundBuffer : public NzRefCounted, public NzResource, NzNonCo
static NzSoundBufferLoader::LoaderList s_loaders;
};
#include <Nazara/Audio/SoundBuffer.inl>
#endif // NAZARA_SOUNDBUFFER_HPP

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Audio module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Audio/Debug.hpp>
template<typename... Args>
NzSoundBufferRef NzSoundBuffer::New(Args&&... args)
{
std::unique_ptr<NzSoundBuffer> object(new NzSoundBuffer(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Audio/DebugOff.hpp>

View File

@ -23,6 +23,7 @@ class NzObjectRef
NzObjectRef(NzObjectRef&& ref) noexcept;
~NzObjectRef();
T* Get() const;
bool IsValid() const;
T* Release();
bool Reset(T* object = nullptr);

View File

@ -41,6 +41,12 @@ NzObjectRef<T>::~NzObjectRef()
m_object->RemoveReference();
}
template<typename T>
T* NzObjectRef<T>::Get() const
{
return m_object;
}
template<typename T>
bool NzObjectRef<T>::IsValid() const
{

View File

@ -134,6 +134,7 @@ class NAZARA_API NzMaterial : public NzRefCounted, public NzResource
NzMaterial& operator=(const NzMaterial& material);
static NzMaterial* GetDefault();
template<typename... Args> static NzMaterialRef New(Args&&... args);
private:
struct ShaderInstance
@ -172,8 +173,10 @@ class NAZARA_API NzMaterial : public NzRefCounted, public NzResource
float m_alphaThreshold;
float m_shininess;
static NzMaterial* s_defaultMaterial;
static NzMaterialRef s_defaultMaterial;
static NzMaterialLoader::LoaderList s_loaders;
};
#include <Nazara/Graphics/Material.inl>
#endif // NAZARA_MATERIAL_HPP

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Graphics/Debug.hpp>
template<typename... Args>
NzMaterialRef NzMaterial::New(Args&&... args)
{
std::unique_ptr<NzMaterial> object(new NzMaterial(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Graphics/DebugOff.hpp>

View File

@ -40,6 +40,7 @@ class NAZARA_API NzRenderBuffer : public NzRefCounted, NzNonCopyable
bool IsValid() const;
static bool IsSupported();
template<typename... Args> static NzRenderBufferRef New(Args&&... args);
private:
nzPixelFormat m_pixelFormat;
@ -48,4 +49,6 @@ class NAZARA_API NzRenderBuffer : public NzRefCounted, NzNonCopyable
unsigned int m_width;
};
#include <Nazara/Renderer/RenderBuffer.inl>
#endif // NAZARA_RENDERBUFFER_HPP

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Renderer/Debug.hpp>
template<typename... Args>
NzRenderBufferRef NzRenderBuffer::New(Args&&... args)
{
std::unique_ptr<NzRenderBuffer> object(new NzRenderBuffer(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Renderer/DebugOff.hpp>

View File

@ -97,6 +97,7 @@ class NAZARA_API NzShader : public NzRefCounted, NzNonCopyable
unsigned int GetOpenGLID() const;
static bool IsStageSupported(nzShaderStage stage);
template<typename... Args> static NzShaderRef New(Args&&... args);
private:
bool PostLinkage();
@ -107,4 +108,6 @@ class NAZARA_API NzShader : public NzRefCounted, NzNonCopyable
unsigned int m_program;
};
#include <Nazara/Renderer/Shader.inl>
#endif // NAZARA_SHADER_HPP

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Renderer/Debug.hpp>
template<typename... Args>
NzShaderRef NzShader::New(Args&&... args)
{
std::unique_ptr<NzShader> object(new NzShader(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Renderer/DebugOff.hpp>

View File

@ -101,6 +101,7 @@ class NAZARA_API NzTexture : public NzAbstractImage, public NzRefCounted, public
static bool IsFormatSupported(nzPixelFormat format);
static bool IsMipmappingSupported();
static bool IsTypeSupported(nzImageType type);
template<typename... Args> static NzTextureRef New(Args&&... args);
private:
bool CreateTexture(bool proxy);
@ -108,4 +109,6 @@ class NAZARA_API NzTexture : public NzAbstractImage, public NzRefCounted, public
NzTextureImpl* m_impl = nullptr;
};
#include <Nazara/Renderer/Texture.inl>
#endif // NAZARA_TEXTURE_HPP

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Renderer/Debug.hpp>
template<typename... Args>
NzTextureRef NzTexture::New(Args&&... args)
{
std::unique_ptr<NzTexture> object(new NzTexture(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Renderer/DebugOff.hpp>

View File

@ -9,12 +9,21 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Core/ObjectListenerWrapper.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Renderer/Shader.hpp>
#include <Nazara/Renderer/ShaderStage.hpp>
#include <Nazara/Renderer/UberShader.hpp>
#include <Nazara/Renderer/UberShaderInstancePreprocessor.hpp>
#include <unordered_map>
class NzUberShaderPreprocessor;
using NzUberShaderPreprocessorConstListener = NzObjectListenerWrapper<const NzUberShaderPreprocessor>;
using NzUberShaderPreprocessorConstRef = NzObjectRef<const NzUberShaderPreprocessor>;
using NzUberShaderPreprocessorListener = NzObjectListenerWrapper<NzUberShaderPreprocessor>;
using NzUberShaderPreprocessorRef = NzObjectRef<NzUberShaderPreprocessor>;
class NAZARA_API NzUberShaderPreprocessor : public NzUberShader
{
public:
@ -27,6 +36,7 @@ class NAZARA_API NzUberShaderPreprocessor : public NzUberShader
bool SetShaderFromFile(nzShaderStage stage, const NzString& filePath, const NzString& shaderFlags, const NzString& requiredFlags = NzString());
static bool IsSupported();
template<typename... Args> static NzUberShaderPreprocessorRef New(Args&&... args);
private:
struct Shader
@ -43,4 +53,6 @@ class NAZARA_API NzUberShaderPreprocessor : public NzUberShader
Shader m_shaders[nzShaderStage_Max+1];
};
#include <Nazara/Renderer/UberShaderPreprocessor.inl>
#endif // NAZARA_UBERSHADERPREPROCESSOR_HPP

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Renderer/Debug.hpp>
template<typename... Args>
NzUberShaderPreprocessorRef NzUberShaderPreprocessor::New(Args&&... args)
{
std::unique_ptr<NzUberShaderPreprocessor> object(new NzUberShaderPreprocessor(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Renderer/DebugOff.hpp>

View File

@ -80,10 +80,14 @@ class NAZARA_API NzAnimation : public NzRefCounted, public NzResource
void RemoveSequence(const NzString& sequenceName);
void RemoveSequence(unsigned int index);
template<typename... Args> static NzAnimationRef New(Args&&... args);
private:
NzAnimationImpl* m_impl = nullptr;
static NzAnimationLoader::LoaderList s_loaders;
};
#include <Nazara/Utility/Animation.inl>
#endif // NAZARA_ANIMATION_HPP

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Utility/Debug.hpp>
template<typename... Args>
NzAnimationRef NzAnimation::New(Args&&... args)
{
std::unique_ptr<NzAnimation> object(new NzAnimation(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@ -58,6 +58,7 @@ class NAZARA_API NzBuffer : public NzRefCounted, NzNonCopyable
void Unmap() const;
static bool IsStorageSupported(nzUInt32 storage);
template<typename... Args> static NzBufferRef New(Args&&... args);
static void SetBufferFactory(nzUInt32 storage, BufferFactory func);
private:
@ -73,4 +74,6 @@ class NAZARA_API NzBuffer : public NzRefCounted, NzNonCopyable
static BufferFactory s_bufferFactories[nzDataStorage_Max+1];
};
#include <Nazara/Utility/Buffer.inl>
#endif // NAZARA_BUFFER_HPP

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Utility/Debug.hpp>
template<typename... Args>
NzBufferRef NzBuffer::New(Args&&... args)
{
std::unique_ptr<NzBuffer> object(new NzBuffer(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@ -85,6 +85,8 @@ class NAZARA_API NzFont : public NzRefCounted, public NzResource, NzAbstractAtla
static bool Initialize();
template<typename... Args> static NzFontRef New(Args&&... args);
static void SetDefaultAtlas(const std::shared_ptr<NzAbstractAtlas>& atlas);
static void SetDefaultGlyphBorder(unsigned int borderSize);
static void SetDefaultMinimumStepSize(unsigned int minimumStepSize);
@ -138,10 +140,12 @@ class NAZARA_API NzFont : public NzRefCounted, public NzResource, NzAbstractAtla
unsigned int m_minimumStepSize;
static std::shared_ptr<NzAbstractAtlas> s_defaultAtlas;
static NzFont* s_defaultFont;
static NzFontRef s_defaultFont;
static NzFontLoader::LoaderList s_loaders;
static unsigned int s_defaultGlyphBorder;
static unsigned int s_defaultMinimumStepSize;
};
#include <Nazara/Utility/Font.inl>
#endif // NAZARA_FONT_HPP

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Utility/Debug.hpp>
template<typename... Args>
NzFontRef NzFont::New(Args&&... args)
{
std::unique_ptr<NzFont> object(new NzFont(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@ -112,6 +112,7 @@ class NAZARA_API NzImage : public NzAbstractImage, public NzRefCounted, public N
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(nzImageType type, unsigned int width, unsigned int height, unsigned int depth = 1);
template<typename... Args> static NzImageRef New(Args&&... args);
struct SharedImage
{
@ -149,4 +150,6 @@ class NAZARA_API NzImage : public NzAbstractImage, public NzRefCounted, public N
static NzImageLoader::LoaderList s_loaders;
};
#include <Nazara/Utility/Image.inl>
#endif // NAZARA_IMAGE_HPP

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Utility/Debug.hpp>
template<typename... Args>
NzImageRef NzImage::New(Args&&... args)
{
std::unique_ptr<NzImage> object(new NzImage(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@ -64,6 +64,8 @@ class NAZARA_API NzIndexBuffer : public NzRefCounted
NzIndexBuffer& operator=(const NzIndexBuffer& indexBuffer);
template<typename... Args> static NzIndexBufferRef New(Args&&... args);
private:
NzBufferRef m_buffer;
bool m_largeIndices;
@ -72,4 +74,6 @@ class NAZARA_API NzIndexBuffer : public NzRefCounted
unsigned int m_startOffset;
};
#include <Nazara/Utility/IndexBuffer.inl>
#endif // NAZARA_INDEXBUFFER_HPP

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Utility/Debug.hpp>
template<typename... Args>
NzIndexBufferRef NzIndexBuffer::New(Args&&... args)
{
std::unique_ptr<NzIndexBuffer> object(new NzIndexBuffer(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@ -123,10 +123,14 @@ class NAZARA_API NzMesh : public NzRefCounted, public NzResource
void Transform(const NzMatrix4f& matrix);
template<typename... Args> static NzMeshRef New(Args&&... args);
private:
NzMeshImpl* m_impl = nullptr;
static NzMeshLoader::LoaderList s_loaders;
};
#include <Nazara/Utility/Mesh.inl>
#endif // NAZARA_MESH_HPP

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Utility/Debug.hpp>
template<typename... Args>
NzMeshRef NzMesh::New(Args&&... args)
{
std::unique_ptr<NzMesh> object(new NzMesh(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@ -41,10 +41,14 @@ class NAZARA_API NzSkeletalMesh final : public NzSubMesh
void SetAABB(const NzBoxf& aabb);
void SetIndexBuffer(const NzIndexBuffer* indexBuffer);
template<typename... Args> static NzSkeletalMeshRef New(Args&&... args);
private:
NzBoxf m_aabb;
NzIndexBufferConstRef m_indexBuffer = nullptr;
NzVertexBufferRef m_vertexBuffer = nullptr;
};
#include <Nazara/Utility/SkeletalMesh.inl>
#endif // NAZARA_SKELETALMESH_HPP

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Utility/Debug.hpp>
template<typename... Args>
NzSkeletalMeshRef NzSkeletalMesh::New(Args&&... args)
{
std::unique_ptr<NzSkeletalMesh> object(new NzSkeletalMesh(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@ -53,6 +53,8 @@ class NAZARA_API NzSkeleton : public NzRefCounted
NzSkeleton& operator=(const NzSkeleton& skeleton);
template<typename... Args> static NzSkeletonRef New(Args&&... args);
private:
void InvalidateJoints();
void InvalidateJointMap();
@ -61,4 +63,6 @@ class NAZARA_API NzSkeleton : public NzRefCounted
NzSkeletonImpl* m_impl = nullptr;
};
#include <Nazara/Utility/Skeleton.inl>
#endif // NAZARA_SKELETON_HPP

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Utility/Debug.hpp>
template<typename... Args>
NzSkeletonRef NzSkeleton::New(Args&&... args)
{
std::unique_ptr<NzSkeleton> object(new NzSkeleton(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@ -45,10 +45,14 @@ class NAZARA_API NzStaticMesh final : public NzSubMesh
void SetAABB(const NzBoxf& aabb);
void SetIndexBuffer(const NzIndexBuffer* indexBuffer);
template<typename... Args> static NzStaticMeshRef New(Args&&... args);
private:
NzBoxf m_aabb;
NzIndexBufferConstRef m_indexBuffer = nullptr;
NzVertexBufferRef m_vertexBuffer = nullptr;
};
#include <Nazara/Utility/StaticMesh.inl>
#endif // NAZARA_STATICMESH_HPP

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Utility/Debug.hpp>
template<typename... Args>
NzStaticMeshRef NzStaticMesh::New(Args&&... args)
{
std::unique_ptr<NzStaticMesh> object(new NzStaticMesh(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@ -62,6 +62,8 @@ class NAZARA_API NzVertexBuffer : public NzRefCounted
NzVertexBuffer& operator=(const NzVertexBuffer& vertexBuffer);
template<typename... Args> static NzVertexBufferRef New(Args&&... args);
private:
NzBufferRef m_buffer;
NzVertexDeclarationConstRef m_vertexDeclaration;
@ -70,4 +72,6 @@ class NAZARA_API NzVertexBuffer : public NzRefCounted
unsigned int m_vertexCount;
};
#include <Nazara/Utility/VertexBuffer.inl>
#endif // NAZARA_VERTEXBUFFER_HPP

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Utility/Debug.hpp>
template<typename... Args>
NzVertexBufferRef NzVertexBuffer::New(Args&&... args)
{
std::unique_ptr<NzVertexBuffer> object(new NzVertexBuffer(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@ -41,6 +41,7 @@ class NAZARA_API NzVertexDeclaration : public NzRefCounted
static NzVertexDeclaration* Get(nzVertexLayout layout);
static bool IsTypeSupported(nzComponentType type);
template<typename... Args> static NzVertexDeclarationRef New(Args&&... args);
private:
static bool Initialize();
@ -67,4 +68,6 @@ class NAZARA_API NzVertexDeclaration : public NzRefCounted
static NzVertexDeclaration s_declarations[nzVertexLayout_Max+1];
};
#include <Nazara/Utility/VertexDeclaration.hpp>
#endif // NAZARA_VERTEXDECLARATION_HPP

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Utility/Debug.hpp>
template<typename... Args>
NzVertexDeclarationRef NzVertexDeclaration::New(Args&&... args)
{
std::unique_ptr<NzVertexDeclaration> object(new NzVertexDeclaration(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@ -2,8 +2,8 @@
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Utility/Debug.hpp>
#include <Nazara/Utility/VertexDeclaration.hpp>
#include <Nazara/Utility/Debug.hpp>
template <typename T>
NzSparsePtr<T> NzVertexMapper::GetComponentPtr(nzVertexComponent component)

View File

@ -84,52 +84,40 @@ bool NzSound::IsPlaying() const
bool NzSound::LoadFromFile(const NzString& filePath, const NzSoundBufferParams& params)
{
std::unique_ptr<NzSoundBuffer> buffer(new NzSoundBuffer);
buffer->SetPersistent(false);
NzSoundBufferRef buffer = NzSoundBuffer::New();
if (!buffer->LoadFromFile(filePath, params))
{
NazaraError("Failed to load buffer from file (" + filePath + ')');
return false;
}
SetBuffer(buffer.get());
buffer.release();
SetBuffer(buffer);
return true;
}
bool NzSound::LoadFromMemory(const void* data, std::size_t size, const NzSoundBufferParams& params)
{
std::unique_ptr<NzSoundBuffer> buffer(new NzSoundBuffer);
buffer->SetPersistent(false);
NzSoundBufferRef buffer = NzSoundBuffer::New();
if (!buffer->LoadFromMemory(data, size, params))
{
NazaraError("Failed to load buffer from memory (" + NzString::Pointer(data) + ')');
return false;
}
SetBuffer(buffer.get());
buffer.release();
SetBuffer(buffer);
return true;
}
bool NzSound::LoadFromStream(NzInputStream& stream, const NzSoundBufferParams& params)
{
std::unique_ptr<NzSoundBuffer> buffer(new NzSoundBuffer);
buffer->SetPersistent(false);
NzSoundBufferRef buffer = NzSoundBuffer::New();
if (!buffer->LoadFromStream(stream, params))
{
NazaraError("Failed to load buffer from stream");
return false;
}
SetBuffer(buffer.get());
buffer.release();
SetBuffer(buffer);
return true;
}

View File

@ -26,10 +26,7 @@ m_blurPassCount(5)
m_gaussianBlurShaderFilterLocation = m_gaussianBlurShader->GetUniformLocation("Filter");
for (unsigned int i = 0; i < 2; ++i)
{
m_bloomTextures[i] = new NzTexture;
m_bloomTextures[i]->SetPersistent(false);
}
m_bloomTextures[i] = NzTexture::New();
}
NzDeferredBloomPass::~NzDeferredBloomPass() = default;

View File

@ -14,7 +14,7 @@
namespace
{
// http://digitalerr0r.wordpress.com/2009/05/16/xna-shader-programming-tutorial-20-depth-of-field/
NzShader* BuildDepthOfFieldShader()
NzShaderRef BuildDepthOfFieldShader()
{
const char* fragmentSource =
"#version 140\n"
@ -63,9 +63,7 @@ namespace
"}\n";
///TODO: Remplacer ça par des ShaderNode
std::unique_ptr<NzShader> shader(new NzShader);
shader->SetPersistent(false);
NzShaderRef shader = NzShader::New();
if (!shader->Create())
{
NazaraError("Failed to load create shader");
@ -90,7 +88,7 @@ namespace
return nullptr;
}
return shader.release();
return shader;
}
}
@ -105,10 +103,7 @@ NzDeferredDOFPass::NzDeferredDOFPass()
m_gaussianBlurShaderFilterLocation = m_gaussianBlurShader->GetUniformLocation("Filter");
for (unsigned int i = 0; i < 2; ++i)
{
m_dofTextures[i] = new NzTexture;
m_dofTextures[i]->SetPersistent(false);
}
m_dofTextures[i] = NzTexture::New();
m_bilinearSampler.SetAnisotropyLevel(1);
m_bilinearSampler.SetFilterMode(nzSamplerFilter_Bilinear);

View File

@ -12,7 +12,7 @@
namespace
{
NzShader* BuildFogShader()
NzShaderRef BuildFogShader()
{
/*const nzUInt8 fragmentSource[] = {
#include <Nazara/Graphics/Resources/DeferredShading/Shaders/FXAA.frag.h>
@ -84,9 +84,7 @@ namespace
"}\n";
///TODO: Remplacer ça par des ShaderNode
std::unique_ptr<NzShader> shader(new NzShader);
shader->SetPersistent(false);
NzShaderRef shader = NzShader::New();
if (!shader->Create())
{
NazaraError("Failed to load create shader");
@ -114,7 +112,7 @@ namespace
shader->SendInteger(shader->GetUniformLocation("ColorTexture"), 0);
shader->SendInteger(shader->GetUniformLocation("GBuffer2"), 1);
return shader.release();
return shader;
}
}

View File

@ -45,13 +45,11 @@ m_lightMeshesDrawing(false)
m_pointSampler.SetFilterMode(nzSamplerFilter_Nearest);
m_pointSampler.SetWrapMode(nzSamplerWrap_Clamp);
m_cone = new NzMesh;
m_cone->SetPersistent(false);
m_cone = NzMesh::New();
m_cone->CreateStatic();
m_coneMesh = static_cast<NzStaticMesh*>(m_cone->BuildSubMesh(NzPrimitive::Cone(1.f, 1.f, 16, NzMatrix4f::Rotate(NzEulerAnglesf(90.f, 0.f, 0.f)))));
m_sphere = new NzMesh;
m_sphere->SetPersistent(false);
m_sphere = NzMesh::New();
m_sphere->CreateStatic();
m_sphereMesh = static_cast<NzStaticMesh*>(m_sphere->BuildSubMesh(NzPrimitive::IcoSphere(1.f, 1)));
}

View File

@ -79,13 +79,11 @@ namespace
static_assert(sizeof(RenderPassPriority)/sizeof(unsigned int) == nzRenderPassType_Max+1, "Render pass priority array is incomplete");
inline NzShader* RegisterDeferredShader(const NzString& name, const nzUInt8* fragmentSource, unsigned int fragmentSourceLength, const NzShaderStage& vertexStage, NzString* err)
inline NzShaderRef RegisterDeferredShader(const NzString& name, const nzUInt8* fragmentSource, unsigned int fragmentSourceLength, const NzShaderStage& vertexStage, NzString* err)
{
NzErrorFlags errFlags(nzErrorFlag_Silent | nzErrorFlag_ThrowExceptionDisabled);
std::unique_ptr<NzShader> shader(new NzShader);
shader->SetPersistent(false);
NzShaderRef shader = NzShader::New();
if (!shader->Create())
{
err->Set("Failed to create shader: " + NzError::GetLastError());
@ -106,8 +104,8 @@ namespace
return nullptr;
}
NzShaderLibrary::Register(name, shader.get());
return shader.release();
NzShaderLibrary::Register(name, shader);
return shader;
}
}
@ -115,20 +113,13 @@ NzDeferredRenderTechnique::NzDeferredRenderTechnique() :
m_renderQueue(static_cast<NzForwardRenderQueue*>(m_forwardTechnique.GetRenderQueue())),
m_GBufferSize(0U)
{
m_depthStencilBuffer = new NzRenderBuffer;
m_depthStencilBuffer->SetPersistent(false);
m_depthStencilBuffer = NzRenderBuffer::New();
for (unsigned int i = 0; i < 2; ++i)
{
m_workTextures[i] = new NzTexture;
m_workTextures[i]->SetPersistent(false);
}
m_workTextures[i] = NzTexture::New();
for (unsigned int i = 0; i < 3; ++i)
{
m_GBuffer[i] = new NzTexture;
m_GBuffer[i]->SetPersistent(false);
}
m_GBuffer[i] = NzTexture::New();
try
{

View File

@ -24,8 +24,7 @@ namespace
{
NazaraUnused(parameters);
std::unique_ptr<NzMesh> mesh(new NzMesh);
mesh->SetPersistent(false);
NzMeshRef mesh = NzMesh::New();
if (!mesh->LoadFromStream(stream, parameters.mesh))
{
NazaraError("Failed to load model mesh");
@ -38,12 +37,8 @@ namespace
return false;
}
// Nous ne pouvons plus avoir recours au smart pointeur à partir d'ici si nous voulons être exception-safe
NzMesh* meshPtr = mesh.get();
model->Reset();
model->SetMesh(meshPtr);
mesh.release();
model->SetMesh(mesh);
if (parameters.loadMaterials)
{
@ -51,17 +46,12 @@ namespace
for (unsigned int i = 0; i < matCount; ++i)
{
NzString mat = meshPtr->GetMaterial(i);
NzString mat = mesh->GetMaterial(i);
if (!mat.IsEmpty())
{
std::unique_ptr<NzMaterial> material(new NzMaterial);
material->SetPersistent(false);
NzMaterialRef material = NzMaterial::New();
if (material->LoadFromFile(mat, parameters.material))
{
model->SetMaterial(i, material.get());
material.release();
}
model->SetMaterial(i, material);
else
NazaraWarning("Failed to load material #" + NzString::Number(i));
}
@ -83,8 +73,7 @@ namespace
{
NazaraUnused(parameters);
std::unique_ptr<NzMesh> mesh(new NzMesh);
mesh->SetPersistent(false);
NzMeshRef mesh = NzMesh::New();
if (!mesh->LoadFromStream(stream, parameters.mesh))
{
NazaraError("Failed to load model mesh");
@ -97,13 +86,8 @@ namespace
return false;
}
// Nous ne pouvons plus avoir recours au smart pointeur à partir d'ici si nous voulons être exception-safe
NzMesh* meshPtr = mesh.get();
model->Reset();
model->SetMesh(meshPtr);
mesh.release();
model->SetMesh(mesh);
if (parameters.loadMaterials)
{
@ -111,17 +95,12 @@ namespace
for (unsigned int i = 0; i < matCount; ++i)
{
NzString mat = meshPtr->GetMaterial(i);
NzString mat = mesh->GetMaterial(i);
if (!mat.IsEmpty())
{
std::unique_ptr<NzMaterial> material(new NzMaterial);
material->SetPersistent(false);
NzMaterialRef material = NzMaterial::New();
if (material->LoadFromFile(mat, parameters.material))
{
model->SetMaterial(i, material.get());
material.release();
}
model->SetMaterial(i, material);
else
NazaraWarning("Failed to load material #" + NzString::Number(i));
}

View File

@ -41,8 +41,7 @@ namespace
return false;
}
std::unique_ptr<NzMesh> mesh(new NzMesh);
mesh->SetPersistent(false);
NzMeshRef mesh = NzMesh::New();
if (!mesh->CreateStatic()) // Ne devrait jamais échouer
{
NazaraInternalError("Failed to create mesh");
@ -100,14 +99,11 @@ namespace
}
// Création des buffers
std::unique_ptr<NzIndexBuffer> indexBuffer(new NzIndexBuffer(vertexCount > std::numeric_limits<nzUInt16>::max(), indices.size(), parameters.mesh.storage, nzBufferUsage_Static));
indexBuffer->SetPersistent(false);
std::unique_ptr<NzVertexBuffer> vertexBuffer(new NzVertexBuffer(NzVertexDeclaration::Get(nzVertexLayout_XYZ_Normal_UV_Tangent), vertexCount, parameters.mesh.storage, nzBufferUsage_Static));
vertexBuffer->SetPersistent(false);
NzIndexBufferRef indexBuffer = NzIndexBuffer::New(vertexCount > std::numeric_limits<nzUInt16>::max(), indices.size(), parameters.mesh.storage, nzBufferUsage_Static);
NzVertexBufferRef vertexBuffer = NzVertexBuffer::New(NzVertexDeclaration::Get(nzVertexLayout_XYZ_Normal_UV_Tangent), vertexCount, parameters.mesh.storage, nzBufferUsage_Static);
// Remplissage des indices
NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly);
NzIndexMapper indexMapper(indexBuffer, nzBufferAccess_WriteOnly);
for (unsigned int j = 0; j < indices.size(); ++j)
indexMapper.Set(j, indices[j]);
@ -116,7 +112,7 @@ namespace
// Remplissage des vertices
bool hasNormals = true;
bool hasTexCoords = true;
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly);
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer, nzBufferAccess_WriteOnly);
NzMeshVertex* meshVertices = static_cast<NzMeshVertex*>(vertexMapper.GetPointer());
for (auto& uvIt : vertices)
{
@ -152,21 +148,18 @@ namespace
vertexMapper.Unmap();
std::unique_ptr<NzStaticMesh> subMesh(new NzStaticMesh(mesh.get()));
if (!subMesh->Create(vertexBuffer.get()))
NzStaticMeshRef subMesh = NzStaticMesh::New(mesh);
if (!subMesh->Create(vertexBuffer))
{
NazaraError("Failed to create StaticMesh");
continue;
}
vertexBuffer.release();
if (parameters.mesh.optimizeIndexBuffers)
indexBuffer->Optimize();
subMesh->SetIndexBuffer(indexBuffer.get());
indexBuffer.release();
subMesh->GenerateAABB();
subMesh->SetIndexBuffer(indexBuffer);
subMesh->SetMaterialIndex(meshes[i].material);
subMesh->SetPrimitiveMode(nzPrimitiveMode_TriangleList);
@ -178,8 +171,7 @@ namespace
else
subMesh->GenerateNormals();
mesh->AddSubMesh(meshes[i].name + '_' + materials[meshes[i].material], subMesh.get());
subMesh.release();
mesh->AddSubMesh(meshes[i].name + '_' + materials[meshes[i].material], subMesh);
}
if (parameters.mesh.center)
@ -196,8 +188,7 @@ namespace
mesh->SetMaterialCount(parser.GetMaterialCount());
model->SetMesh(mesh.get());
mesh.release();
model->SetMesh(mesh);
// On charge les matériaux si demandé
NzString mtlLib = parser.GetMtlLib();
@ -209,7 +200,7 @@ namespace
NzMTLParser materialParser(file);
if (materialParser.Parse())
{
std::unordered_map<NzString, NzMaterial*> materialCache;
std::unordered_map<NzString, NzMaterialRef> materialCache;
NzString baseDir = file.GetDirectory();
for (unsigned int i = 0; i < meshCount; ++i)
{
@ -222,9 +213,7 @@ namespace
model->SetMaterial(meshes[i].material, it->second);
else
{
std::unique_ptr<NzMaterial> material(new NzMaterial);
material->SetPersistent(false);
NzMaterialRef material = NzMaterial::New();
material->SetShader(parameters.material.shaderName);
nzUInt8 alphaValue = static_cast<nzUInt8>(mtlMat->alpha*255.f);
@ -246,15 +235,11 @@ namespace
bool hasAlphaMap = false;;
if (parameters.material.loadAlphaMap && !mtlMat->alphaMap.IsEmpty())
{
std::unique_ptr<NzTexture> alphaMap(new NzTexture);
alphaMap->SetPersistent(false);
NzTextureRef alphaMap = NzTexture::New();
if (alphaMap->LoadFromFile(baseDir + mtlMat->alphaMap))
{
hasAlphaMap = true;
material->SetAlphaMap(alphaMap.get());
alphaMap.release();
material->SetAlphaMap(alphaMap);
}
else
NazaraWarning("Failed to load alpha map (" + mtlMat->alphaMap + ')');
@ -262,28 +247,18 @@ namespace
if (parameters.material.loadDiffuseMap && !mtlMat->diffuseMap.IsEmpty())
{
std::unique_ptr<NzTexture> diffuseMap(new NzTexture);
diffuseMap->SetPersistent(false);
NzTextureRef diffuseMap = NzTexture::New();
if (diffuseMap->LoadFromFile(baseDir + mtlMat->diffuseMap))
{
material->SetDiffuseMap(diffuseMap.get());
diffuseMap.release();
}
material->SetDiffuseMap(diffuseMap);
else
NazaraWarning("Failed to load diffuse map (" + mtlMat->diffuseMap + ')');
}
if (parameters.material.loadSpecularMap && !mtlMat->specularMap.IsEmpty())
{
std::unique_ptr<NzTexture> specularMap(new NzTexture);
specularMap->SetPersistent(false);
NzTextureRef specularMap = NzTexture::New();
if (specularMap->LoadFromFile(baseDir + mtlMat->specularMap))
{
material->SetSpecularMap(specularMap.get());
specularMap.release();
}
material->SetSpecularMap(specularMap);
else
NazaraWarning("Failed to load specular map (" + mtlMat->specularMap + ')');
}
@ -299,10 +274,9 @@ namespace
material->SetSrcBlend(nzBlendFunc_SrcAlpha);
}
materialCache[matName] = material.get();
materialCache[matName] = material;
model->SetMaterial(meshes[i].material, material.get());
material.release();
model->SetMaterial(meshes[i].material, material);
}
}
else

View File

@ -22,9 +22,7 @@ namespace
{
NazaraUnused(parameters);
std::unique_ptr<NzTexture> texture(new NzTexture);
texture->SetPersistent(false);
NzTextureRef texture = NzTexture::New();
if (!texture->LoadFromStream(stream))
{
NazaraError("Failed to load diffuse map");
@ -32,9 +30,7 @@ namespace
}
material->Reset();
material->SetDiffuseMap(texture.get());
texture.release();
material->SetDiffuseMap(texture);
material->SetShader(parameters.shaderName);
return true;

View File

@ -409,18 +409,14 @@ void NzMaterial::Reset()
bool NzMaterial::SetAlphaMap(const NzString& texturePath)
{
std::unique_ptr<NzTexture> texture(new NzTexture);
NzTextureRef texture = NzTexture::New();
if (!texture->LoadFromFile(texturePath))
{
NazaraError("Failed to load texture from \"" + texturePath + '"');
return false;
}
texture->SetPersistent(false);
SetAlphaMap(texture.get());
texture.release();
SetAlphaMap(texture);
return true;
}
@ -453,18 +449,14 @@ void NzMaterial::SetDiffuseColor(const NzColor& diffuse)
bool NzMaterial::SetDiffuseMap(const NzString& texturePath)
{
std::unique_ptr<NzTexture> texture(new NzTexture);
NzTextureRef texture = NzTexture::New();
if (!texture->LoadFromFile(texturePath))
{
NazaraError("Failed to load texture from \"" + texturePath + '"');
return false;
}
texture->SetPersistent(false);
SetDiffuseMap(texture.get());
texture.release();
SetDiffuseMap(texture);
return true;
}
@ -487,18 +479,14 @@ void NzMaterial::SetDstBlend(nzBlendFunc func)
bool NzMaterial::SetEmissiveMap(const NzString& texturePath)
{
std::unique_ptr<NzTexture> texture(new NzTexture);
NzTextureRef texture = NzTexture::New();
if (!texture->LoadFromFile(texturePath))
{
NazaraError("Failed to load texture from \"" + texturePath + '"');
return false;
}
texture->SetPersistent(false);
SetEmissiveMap(texture.get());
texture.release();
SetEmissiveMap(texture);
return true;
}
@ -521,18 +509,14 @@ void NzMaterial::SetFaceFilling(nzFaceFilling filling)
bool NzMaterial::SetHeightMap(const NzString& texturePath)
{
std::unique_ptr<NzTexture> texture(new NzTexture);
NzTextureRef texture = NzTexture::New();
if (!texture->LoadFromFile(texturePath))
{
NazaraError("Failed to load texture from \"" + texturePath + '"');
return false;
}
texture->SetPersistent(false);
SetHeightMap(texture.get());
texture.release();
SetHeightMap(texture);
return true;
}
@ -545,18 +529,14 @@ void NzMaterial::SetHeightMap(NzTexture* map)
bool NzMaterial::SetNormalMap(const NzString& texturePath)
{
std::unique_ptr<NzTexture> texture(new NzTexture);
NzTextureRef texture = NzTexture::New();
if (!texture->LoadFromFile(texturePath))
{
NazaraError("Failed to load texture from \"" + texturePath + '"');
return false;
}
texture->SetPersistent(false);
SetNormalMap(texture.get());
texture.release();
SetNormalMap(texture);
return true;
}
@ -601,18 +581,14 @@ void NzMaterial::SetSpecularColor(const NzColor& specular)
bool NzMaterial::SetSpecularMap(const NzString& texturePath)
{
std::unique_ptr<NzTexture> texture(new NzTexture);
NzTextureRef texture = NzTexture::New();
if (!texture->LoadFromFile(texturePath))
{
NazaraError("Failed to load texture from \"" + texturePath + '"');
return false;
}
texture->SetPersistent(false);
SetSpecularMap(texture.get());
texture.release();
SetSpecularMap(texture);
return true;
}
@ -734,8 +710,7 @@ bool NzMaterial::Initialize()
// Basic shader
{
std::unique_ptr<NzUberShaderPreprocessor> uberShader(new NzUberShaderPreprocessor);
uberShader->SetPersistent(false);
NzUberShaderPreprocessorRef uberShader = NzUberShaderPreprocessor::New();
NzString fragmentShader;
NzString vertexShader;
@ -753,14 +728,12 @@ bool NzMaterial::Initialize()
uberShader->SetShader(nzShaderStage_Fragment, fragmentShader, "FLAG_TEXTUREOVERLAY ALPHA_MAPPING ALPHA_TEST AUTO_TEXCOORDS DIFFUSE_MAPPING");
uberShader->SetShader(nzShaderStage_Vertex, vertexShader, "FLAG_BILLBOARD FLAG_INSTANCING FLAG_VERTEXCOLOR TEXTURE_MAPPING TRANSFORM UNIFORM_VERTEX_DEPTH");
NzUberShaderLibrary::Register("Basic", uberShader.get());
uberShader.release();
NzUberShaderLibrary::Register("Basic", uberShader);
}
// PhongLighting shader
{
std::unique_ptr<NzUberShaderPreprocessor> uberShader(new NzUberShaderPreprocessor);
uberShader->SetPersistent(false);
NzUberShaderPreprocessorRef uberShader = NzUberShaderPreprocessor::New();
NzString fragmentShader;
NzString vertexShader;
@ -794,13 +767,10 @@ bool NzMaterial::Initialize()
uberShader->SetShader(nzShaderStage_Fragment, fragmentShader, "FLAG_DEFERRED FLAG_TEXTUREOVERLAY ALPHA_MAPPING ALPHA_TEST AUTO_TEXCOORDS DIFFUSE_MAPPING EMISSIVE_MAPPING LIGHTING NORMAL_MAPPING PARALLAX_MAPPING SPECULAR_MAPPING");
uberShader->SetShader(nzShaderStage_Vertex, vertexShader, "FLAG_BILLBOARD FLAG_DEFERRED FLAG_INSTANCING FLAG_VERTEXCOLOR COMPUTE_TBNMATRIX LIGHTING PARALLAX_MAPPING TEXTURE_MAPPING TRANSFORM UNIFORM_VERTEX_DEPTH");
NzUberShaderLibrary::Register("PhongLighting", uberShader.get());
uberShader.release();
NzUberShaderLibrary::Register("PhongLighting", uberShader);
}
s_defaultMaterial = new NzMaterial;
s_defaultMaterial->SetPersistent(true);
s_defaultMaterial = NzMaterial::New();
s_defaultMaterial->Enable(nzRendererParameter_FaceCulling, false);
s_defaultMaterial->SetFaceFilling(nzFaceFilling_Line);
@ -809,12 +779,10 @@ bool NzMaterial::Initialize()
void NzMaterial::Uninitialize()
{
s_defaultMaterial.Reset();
NzUberShaderLibrary::Unregister("PhongLighting");
NzUberShaderLibrary::Unregister("Basic");
s_defaultMaterial->SetPersistent(false, true);
s_defaultMaterial = nullptr;
}
NzMaterial* NzMaterial::s_defaultMaterial = nullptr;
NzMaterialRef NzMaterial::s_defaultMaterial = nullptr;
NzMaterialLoader::LoaderList NzMaterial::s_loaders;

View File

@ -172,16 +172,14 @@ NzVertexBuffer* NzSkinningManager::GetBuffer(const NzSkeletalMesh* mesh, const N
MeshMap::iterator it2 = meshMap.find(mesh);
if (it2 == meshMap.end())
{
std::unique_ptr<NzVertexBuffer> vertexBuffer(new NzVertexBuffer);
vertexBuffer->SetPersistent(false);
vertexBuffer->Reset(NzVertexDeclaration::Get(nzVertexLayout_XYZ_Normal_UV_Tangent), mesh->GetVertexCount(), nzDataStorage_Hardware, nzBufferUsage_Dynamic);
NzVertexBufferRef vertexBuffer = NzVertexBuffer::New(NzVertexDeclaration::Get(nzVertexLayout_XYZ_Normal_UV_Tangent), mesh->GetVertexCount(), nzDataStorage_Hardware, nzBufferUsage_Dynamic);
BufferData data({vertexBuffer.get(), true});
BufferData data({vertexBuffer, true});
meshMap.insert(std::make_pair(mesh, std::make_pair(NzSkeletalMeshConstListener(&listener, ObjectType_SkeletalMesh, mesh), data)));
s_skinningQueue.push_back(SkinningData{mesh, skeleton, vertexBuffer.get()});
s_skinningQueue.push_back(SkinningData{mesh, skeleton, vertexBuffer});
buffer = vertexBuffer.release();
buffer = vertexBuffer;
}
else
{

View File

@ -96,14 +96,11 @@ void NzSprite::SetColor(const NzColor& color)
void NzSprite::SetDefaultMaterial()
{
std::unique_ptr<NzMaterial> material(new NzMaterial);
NzMaterialRef material = NzMaterial::New();
material->Enable(nzRendererParameter_FaceCulling, false);
material->EnableLighting(false);
SetMaterial(material.get());
material->SetPersistent(false);
material.release();
SetMaterial(material);
}
void NzSprite::SetMaterial(NzMaterial* material, bool resizeSprite)
@ -137,10 +134,7 @@ void NzSprite::SetTexture(NzTexture* texture, bool resizeSprite)
if (!m_material)
SetDefaultMaterial();
else if (m_material->GetReferenceCount() > 1)
{
m_material = new NzMaterial(*m_material);
m_material->SetPersistent(false);
}
m_material = NzMaterial::New(*m_material); // Copie
m_material->SetDiffuseMap(texture);
if (resizeSprite && texture && texture->IsValid())

View File

@ -108,7 +108,7 @@ void NzTextSprite::SetColor(const NzColor& color)
void NzTextSprite::SetDefaultMaterial()
{
std::unique_ptr<NzMaterial> material(new NzMaterial);
NzMaterialRef material = NzMaterial::New();
material->Enable(nzRendererParameter_Blend, true);
material->Enable(nzRendererParameter_DepthWrite, false);
material->Enable(nzRendererParameter_FaceCulling, false);
@ -116,10 +116,7 @@ void NzTextSprite::SetDefaultMaterial()
material->SetDstBlend(nzBlendFunc_InvSrcAlpha);
material->SetSrcBlend(nzBlendFunc_SrcAlpha);
SetMaterial(material.get());
material->SetPersistent(false);
material.release();
SetMaterial(material);
}
void NzTextSprite::SetMaterial(NzMaterial* material)

View File

@ -184,22 +184,19 @@ bool NzRenderTexture::AttachBuffer(nzAttachmentPoint attachmentPoint, nzUInt8 in
bool NzRenderTexture::AttachBuffer(nzAttachmentPoint attachmentPoint, nzUInt8 index, nzPixelFormat format, unsigned int width, unsigned int height)
{
std::unique_ptr<NzRenderBuffer> renderBuffer(new NzRenderBuffer);
renderBuffer->SetPersistent(false);
NzRenderBufferRef renderBuffer = NzRenderBuffer::New();
if (!renderBuffer->Create(format, width, height))
{
NazaraError("Failed to create RenderBuffer");
return false;
}
if (!AttachBuffer(attachmentPoint, index, renderBuffer.get()))
if (!AttachBuffer(attachmentPoint, index, renderBuffer))
{
NazaraError("Failed to attach buffer");
return false;
}
renderBuffer.release();
return true;
}

View File

@ -884,10 +884,8 @@ bool NzRenderer::Initialize()
}
// Création du shader de Debug
std::unique_ptr<NzShader> shader(new NzShader);
shader->SetPersistent(false);
if (!shader->Create())
NzShaderRef debugShader = NzShader::New();
if (!debugShader->Create())
{
NazaraError("Failed to create debug shader");
return false;
@ -912,26 +910,25 @@ bool NzRenderer::Initialize()
vertexShaderLength = sizeof(r_compatibilityVertexShader);
}
if (!shader->AttachStageFromSource(nzShaderStage_Fragment, fragmentShader, fragmentShaderLength))
if (!debugShader->AttachStageFromSource(nzShaderStage_Fragment, fragmentShader, fragmentShaderLength))
{
NazaraError("Failed to attach fragment stage");
return false;
}
if (!shader->AttachStageFromSource(nzShaderStage_Vertex, vertexShader, vertexShaderLength))
if (!debugShader->AttachStageFromSource(nzShaderStage_Vertex, vertexShader, vertexShaderLength))
{
NazaraError("Failed to attach vertex stage");
return false;
}
if (!shader->Link())
if (!debugShader->Link())
{
NazaraError("Failed to link shader");
return false;
}
NzShaderLibrary::Register("DebugSimple", shader.get());
shader.release();
NzShaderLibrary::Register("DebugSimple", debugShader);
onExit.Reset();

View File

@ -35,10 +35,9 @@ NzUberShaderInstance* NzUberShaderPreprocessor::Get(const NzParameterList& param
// Une exception sera lancée à la moindre erreur et celle-ci ne sera pas enregistrée dans le log (car traitée dans le bloc catch)
NzErrorFlags errFlags(nzErrorFlag_Silent | nzErrorFlag_ThrowException, true);
std::unique_ptr<NzShader> shader(new NzShader);
shader->SetPersistent(false);
NzShaderRef shader = NzShader::New();
shader->Create();
for (unsigned int i = 0; i <= nzShaderStage_Max; ++i)
{
const Shader& shaderStage = m_shaders[i];
@ -91,8 +90,7 @@ NzUberShaderInstance* NzUberShaderPreprocessor::Get(const NzParameterList& param
shader->Link();
// On construit l'instant
shaderIt = m_cache.emplace(flags, shader.get()).first;
shader.release();
shaderIt = m_cache.emplace(flags, shader.Get()).first;
}
catch (const std::exception& e)
{

View File

@ -340,16 +340,14 @@ NzFont* NzFont::GetDefault()
if (!s_defaultFont)
{
std::unique_ptr<NzFont> cabin(new NzFont);
cabin->SetPersistent(true);
NzFontRef cabin = NzFont::New();
if (!cabin->OpenFromMemory(r_cabinRegular, sizeof(r_cabinRegular)))
{
NazaraError("Failed to open default font");
return nullptr;
}
s_defaultFont = cabin.release();
s_defaultFont = cabin;
}
return s_defaultFont;
@ -400,13 +398,7 @@ void NzFont::SetDefaultMinimumStepSize(unsigned int minimumStepSize)
void NzFont::Uninitialize()
{
s_defaultAtlas.reset();
// On rend la police non-persistente et on demande la vérification du compteur (pouvant entraîner la libération de la ressource)
if (s_defaultFont)
{
s_defaultFont->SetPersistent(false, true);
s_defaultFont = nullptr;
}
s_defaultFont.Reset();
}
nzUInt64 NzFont::ComputeKey(unsigned int characterSize, nzUInt32 style) const
@ -582,7 +574,7 @@ const NzFont::Glyph& NzFont::PrecacheGlyph(GlyphMap& glyphMap, unsigned int char
}
std::shared_ptr<NzAbstractAtlas> NzFont::s_defaultAtlas;
NzFont* NzFont::s_defaultFont;
NzFontRef NzFont::s_defaultFont;
NzFontLoader::LoaderList NzFont::s_loaders;
unsigned int NzFont::s_defaultGlyphBorder;
unsigned int NzFont::s_defaultMinimumStepSize;

View File

@ -219,8 +219,7 @@ void NzIndexBuffer::Reset(bool largeIndices, unsigned int length, nzUInt32 stora
m_largeIndices = largeIndices;
m_startOffset = 0;
m_buffer = new NzBuffer(nzBufferType_Index, m_endOffset, storage, usage);
m_buffer->SetPersistent(false);
m_buffer = NzBuffer::New(nzBufferType_Index, m_endOffset, storage, usage);
}
void NzIndexBuffer::Reset(const NzIndexBuffer& indexBuffer)

View File

@ -102,8 +102,7 @@ namespace
/// Chargement des submesh
// Actuellement le loader ne charge qu'un submesh
std::unique_ptr<NzIndexBuffer> indexBuffer(new NzIndexBuffer(false, header.num_tris * 3, parameters.storage, nzBufferUsage_Static));
indexBuffer->SetPersistent(false);
NzIndexBufferRef indexBuffer = NzIndexBuffer::New(false, header.num_tris*3, parameters.storage, nzBufferUsage_Static);
/// Lecture des triangles
std::vector<MD2_Triangle> triangles(header.num_tris);
@ -111,7 +110,7 @@ namespace
stream.SetCursorPos(header.offset_tris);
stream.Read(&triangles[0], header.num_tris*sizeof(MD2_Triangle));
NzBufferMapper<NzIndexBuffer> indexMapper(indexBuffer.get(), nzBufferAccess_DiscardAndWrite);
NzBufferMapper<NzIndexBuffer> indexMapper(indexBuffer, nzBufferAccess_DiscardAndWrite);
nzUInt16* index = reinterpret_cast<nzUInt16*>(indexMapper.GetPointer());
for (unsigned int i = 0; i < header.num_tris; ++i)
@ -127,7 +126,7 @@ namespace
NzByteSwap(&triangles[i].texCoords[2], sizeof(nzUInt16));
#endif
// On respécifie le triangle dans le bon ordre
// On respécifie le triangle dans l'ordre attendu
*index++ = triangles[i].vertices[0];
*index++ = triangles[i].vertices[2];
*index++ = triangles[i].vertices[1];
@ -135,6 +134,9 @@ namespace
indexMapper.Unmap();
if (parameters.optimizeIndexBuffers)
indexBuffer->Optimize();
/// Lecture des coordonnées de texture
std::vector<MD2_TexCoord> texCoords(header.num_st);
@ -149,20 +151,14 @@ namespace
}
#endif
std::unique_ptr<NzVertexBuffer> vertexBuffer(new NzVertexBuffer(NzVertexDeclaration::Get(nzVertexLayout_XYZ_Normal_UV_Tangent), header.num_vertices, parameters.storage, nzBufferUsage_Static));
std::unique_ptr<NzStaticMesh> subMesh(new NzStaticMesh(mesh));
if (!subMesh->Create(vertexBuffer.get()))
NzVertexBufferRef vertexBuffer = NzVertexBuffer::New(NzVertexDeclaration::Get(nzVertexLayout_XYZ_Normal_UV_Tangent), header.num_vertices, parameters.storage, nzBufferUsage_Static);
NzStaticMeshRef subMesh = NzStaticMesh::New(mesh);
if (!subMesh->Create(vertexBuffer))
{
NazaraError("Failed to create SubMesh");
return false;
}
if (parameters.optimizeIndexBuffers)
indexBuffer->Optimize();
subMesh->SetIndexBuffer(indexBuffer.get());
indexBuffer.release();
/// Chargement des vertices
stream.SetCursorPos(header.offset_frames);
@ -189,7 +185,7 @@ namespace
scale *= s;
translate *= s;
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_DiscardAndWrite);
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer, nzBufferAccess_DiscardAndWrite);
NzMeshVertex* vertex = reinterpret_cast<NzMeshVertex*>(vertexMapper.GetPointer());
/// Chargement des coordonnées de texture
@ -224,17 +220,15 @@ namespace
vertexMapper.Unmap();
vertexBuffer->SetPersistent(false);
vertexBuffer.release();
subMesh->GenerateAABB();
subMesh->GenerateTangents();
subMesh->SetIndexBuffer(indexBuffer);
subMesh->SetMaterialIndex(0);
if (parameters.center)
subMesh->Center();
mesh->AddSubMesh(subMesh.release());
mesh->AddSubMesh(subMesh);
return true;
}

View File

@ -85,14 +85,11 @@ namespace
bool largeIndices = (vertexCount > std::numeric_limits<nzUInt16>::max());
std::unique_ptr<NzIndexBuffer> indexBuffer(new NzIndexBuffer(largeIndices, indexCount, parameters.storage));
indexBuffer->SetPersistent(false);
std::unique_ptr<NzVertexBuffer> vertexBuffer(new NzVertexBuffer(NzVertexDeclaration::Get(nzVertexLayout_XYZ_Normal_UV_Tangent_Skinning), vertexCount, parameters.storage, nzBufferUsage_Static));
vertexBuffer->SetPersistent(false);
NzIndexBufferRef indexBuffer = NzIndexBuffer::New(largeIndices, indexCount, parameters.storage);
NzVertexBufferRef vertexBuffer = NzVertexBuffer::New(NzVertexDeclaration::Get(nzVertexLayout_XYZ_Normal_UV_Tangent_Skinning), vertexCount, parameters.storage, nzBufferUsage_Static);
// Index buffer
NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_DiscardAndWrite);
NzIndexMapper indexMapper(indexBuffer, nzBufferAccess_DiscardAndWrite);
// Le format définit un set de triangles nous permettant de retrouver facilement les indices
// Cependant les sommets des triangles ne sont pas spécifiés dans le même ordre que ceux du moteur
@ -108,6 +105,9 @@ namespace
indexMapper.Unmap();
if (parameters.optimizeIndexBuffers)
indexBuffer->Optimize();
// Vertex buffer
struct Weight
{
@ -117,7 +117,7 @@ namespace
std::vector<Weight> tempWeights;
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly);
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer, nzBufferAccess_WriteOnly);
NzSkeletalMeshVertex* vertices = static_cast<NzSkeletalMeshVertex*>(vertexMapper.GetPointer());
for (const NzMD5MeshParser::Vertex& vertex : md5Mesh.vertices)
{
@ -188,22 +188,15 @@ namespace
mesh->SetMaterial(i, baseDir + md5Mesh.shader);
// Submesh
std::unique_ptr<NzSkeletalMesh> subMesh(new NzSkeletalMesh(mesh));
subMesh->Create(vertexBuffer.get());
vertexBuffer.release();
if (parameters.optimizeIndexBuffers)
indexBuffer->Optimize();
subMesh->SetIndexBuffer(indexBuffer.get());
indexBuffer.release();
NzSkeletalMeshRef subMesh = NzSkeletalMesh::New(mesh);
subMesh->Create(vertexBuffer);
subMesh->SetIndexBuffer(indexBuffer);
subMesh->GenerateNormalsAndTangents();
subMesh->SetMaterialIndex(i);
subMesh->SetPrimitiveMode(nzPrimitiveMode_TriangleList);
mesh->AddSubMesh(subMesh.get());
subMesh.release();
mesh->AddSubMesh(subMesh);
// Animation
// Il est peut-être éventuellement possible que la probabilité que l'animation ait le même nom soit non-nulle.
@ -234,10 +227,9 @@ namespace
// Index buffer
bool largeIndices = (vertexCount > std::numeric_limits<nzUInt16>::max());
std::unique_ptr<NzIndexBuffer> indexBuffer(new NzIndexBuffer(largeIndices, indexCount, parameters.storage));
indexBuffer->SetPersistent(false);
NzIndexBufferRef indexBuffer = NzIndexBuffer::New(largeIndices, indexCount, parameters.storage);
NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_DiscardAndWrite);
NzIndexMapper indexMapper(indexBuffer, nzBufferAccess_DiscardAndWrite);
NzIndexIterator index = indexMapper.begin();
for (const NzMD5MeshParser::Triangle& triangle : md5Mesh.triangles)
@ -250,8 +242,8 @@ namespace
indexMapper.Unmap();
// Vertex buffer
std::unique_ptr<NzVertexBuffer> vertexBuffer(new NzVertexBuffer(NzVertexDeclaration::Get(nzVertexLayout_XYZ_Normal_UV_Tangent), vertexCount, parameters.storage));
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly);
NzVertexBufferRef vertexBuffer = NzVertexBuffer::New(NzVertexDeclaration::Get(nzVertexLayout_XYZ_Normal_UV_Tangent), vertexCount, parameters.storage);
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer, nzBufferAccess_WriteOnly);
NzMeshVertex* vertex = reinterpret_cast<NzMeshVertex*>(vertexMapper.GetPointer());
for (const NzMD5MeshParser::Vertex& md5Vertex : md5Mesh.vertices)
@ -275,27 +267,21 @@ namespace
vertexMapper.Unmap();
// Submesh
std::unique_ptr<NzStaticMesh> subMesh(new NzStaticMesh(mesh));
subMesh->Create(vertexBuffer.get());
vertexBuffer->SetPersistent(false);
vertexBuffer.release();
NzStaticMeshRef subMesh = NzStaticMesh::New(mesh);
subMesh->Create(vertexBuffer);
if (parameters.optimizeIndexBuffers)
indexBuffer->Optimize();
subMesh->SetIndexBuffer(indexBuffer.get());
indexBuffer.release();
// Material
mesh->SetMaterial(i, baseDir + md5Mesh.shader);
subMesh->SetIndexBuffer(indexBuffer);
subMesh->GenerateAABB();
subMesh->GenerateNormalsAndTangents();
subMesh->SetMaterialIndex(i);
mesh->AddSubMesh(subMesh.get());
subMesh.release();
mesh->AddSubMesh(subMesh);
// Material
mesh->SetMaterial(i, baseDir + md5Mesh.shader);
}
if (parameters.center)

View File

@ -160,8 +160,8 @@ NzSubMesh* NzMesh::BuildSubMesh(const NzPrimitive& primitive, const NzMeshParams
#endif
NzBoxf aabb;
std::unique_ptr<NzIndexBuffer> indexBuffer;
std::unique_ptr<NzVertexBuffer> vertexBuffer;
NzIndexBufferRef indexBuffer;
NzVertexBufferRef vertexBuffer;
NzMatrix4f matrix(primitive.matrix);
matrix.ApplyScale(params.scale);
@ -176,14 +176,11 @@ NzSubMesh* NzMesh::BuildSubMesh(const NzPrimitive& primitive, const NzMeshParams
unsigned int vertexCount;
NzComputeBoxIndexVertexCount(primitive.box.subdivision, &indexCount, &vertexCount);
indexBuffer.reset(new NzIndexBuffer(vertexCount > std::numeric_limits<nzUInt16>::max(), indexCount, params.storage, nzBufferUsage_Static));
indexBuffer->SetPersistent(false);
indexBuffer = NzIndexBuffer::New(vertexCount > std::numeric_limits<nzUInt16>::max(), indexCount, params.storage, nzBufferUsage_Static);
vertexBuffer = NzVertexBuffer::New(declaration, vertexCount, params.storage, nzBufferUsage_Static);
vertexBuffer.reset(new NzVertexBuffer(declaration, vertexCount, params.storage, nzBufferUsage_Static));
vertexBuffer->SetPersistent(false);
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly);
NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly);
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer, nzBufferAccess_WriteOnly);
NzIndexMapper indexMapper(indexBuffer, nzBufferAccess_WriteOnly);
NzGenerateBox(primitive.box.lengths, primitive.box.subdivision, matrix, primitive.textureCoords, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), indexMapper.begin(), &aabb);
break;
@ -195,14 +192,11 @@ NzSubMesh* NzMesh::BuildSubMesh(const NzPrimitive& primitive, const NzMeshParams
unsigned int vertexCount;
NzComputeConeIndexVertexCount(primitive.cone.subdivision, &indexCount, &vertexCount);
indexBuffer.reset(new NzIndexBuffer(vertexCount > std::numeric_limits<nzUInt16>::max(), indexCount, params.storage, nzBufferUsage_Static));
indexBuffer->SetPersistent(false);
indexBuffer = NzIndexBuffer::New(vertexCount > std::numeric_limits<nzUInt16>::max(), indexCount, params.storage, nzBufferUsage_Static);
vertexBuffer = NzVertexBuffer::New(declaration, vertexCount, params.storage, nzBufferUsage_Static);
vertexBuffer.reset(new NzVertexBuffer(declaration, vertexCount, params.storage, nzBufferUsage_Static));
vertexBuffer->SetPersistent(false);
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly);
NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly);
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer, nzBufferAccess_WriteOnly);
NzIndexMapper indexMapper(indexBuffer, nzBufferAccess_WriteOnly);
NzGenerateCone(primitive.cone.length, primitive.cone.radius, primitive.cone.subdivision, matrix, primitive.textureCoords, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), indexMapper.begin(), &aabb);
break;
@ -214,14 +208,11 @@ NzSubMesh* NzMesh::BuildSubMesh(const NzPrimitive& primitive, const NzMeshParams
unsigned int vertexCount;
NzComputePlaneIndexVertexCount(primitive.plane.subdivision, &indexCount, &vertexCount);
indexBuffer.reset(new NzIndexBuffer(vertexCount > std::numeric_limits<nzUInt16>::max(), indexCount, params.storage, nzBufferUsage_Static));
indexBuffer->SetPersistent(false);
indexBuffer = NzIndexBuffer::New(vertexCount > std::numeric_limits<nzUInt16>::max(), indexCount, params.storage, nzBufferUsage_Static);
vertexBuffer = NzVertexBuffer::New(declaration, vertexCount, params.storage, nzBufferUsage_Static);
vertexBuffer.reset(new NzVertexBuffer(declaration, vertexCount, params.storage, nzBufferUsage_Static));
vertexBuffer->SetPersistent(false);
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly);
NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly);
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer, nzBufferAccess_WriteOnly);
NzIndexMapper indexMapper(indexBuffer, nzBufferAccess_WriteOnly);
NzGeneratePlane(primitive.plane.subdivision, primitive.plane.size, matrix, primitive.textureCoords, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), indexMapper.begin(), &aabb);
break;
@ -237,14 +228,11 @@ NzSubMesh* NzMesh::BuildSubMesh(const NzPrimitive& primitive, const NzMeshParams
unsigned int vertexCount;
NzComputeCubicSphereIndexVertexCount(primitive.sphere.cubic.subdivision, &indexCount, &vertexCount);
indexBuffer.reset(new NzIndexBuffer(vertexCount > std::numeric_limits<nzUInt16>::max(), indexCount, params.storage, nzBufferUsage_Static));
indexBuffer->SetPersistent(false);
indexBuffer = NzIndexBuffer::New(vertexCount > std::numeric_limits<nzUInt16>::max(), indexCount, params.storage, nzBufferUsage_Static);
vertexBuffer = NzVertexBuffer::New(declaration, vertexCount, params.storage, nzBufferUsage_Static);
vertexBuffer.reset(new NzVertexBuffer(declaration, vertexCount, params.storage, nzBufferUsage_Static));
vertexBuffer->SetPersistent(false);
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly);
NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly);
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer, nzBufferAccess_WriteOnly);
NzIndexMapper indexMapper(indexBuffer, nzBufferAccess_WriteOnly);
NzGenerateCubicSphere(primitive.sphere.size, primitive.sphere.cubic.subdivision, matrix, primitive.textureCoords, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), indexMapper.begin(), &aabb);
break;
@ -256,14 +244,11 @@ NzSubMesh* NzMesh::BuildSubMesh(const NzPrimitive& primitive, const NzMeshParams
unsigned int vertexCount;
NzComputeIcoSphereIndexVertexCount(primitive.sphere.ico.recursionLevel, &indexCount, &vertexCount);
indexBuffer.reset(new NzIndexBuffer(vertexCount > std::numeric_limits<nzUInt16>::max(), indexCount, params.storage, nzBufferUsage_Static));
indexBuffer->SetPersistent(false);
indexBuffer = NzIndexBuffer::New(vertexCount > std::numeric_limits<nzUInt16>::max(), indexCount, params.storage, nzBufferUsage_Static);
vertexBuffer = NzVertexBuffer::New(declaration, vertexCount, params.storage, nzBufferUsage_Static);
vertexBuffer.reset(new NzVertexBuffer(declaration, vertexCount, params.storage, nzBufferUsage_Static));
vertexBuffer->SetPersistent(false);
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly);
NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly);
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer, nzBufferAccess_WriteOnly);
NzIndexMapper indexMapper(indexBuffer, nzBufferAccess_WriteOnly);
NzGenerateIcoSphere(primitive.sphere.size, primitive.sphere.ico.recursionLevel, matrix, primitive.textureCoords, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), indexMapper.begin(), &aabb);
break;
@ -275,14 +260,11 @@ NzSubMesh* NzMesh::BuildSubMesh(const NzPrimitive& primitive, const NzMeshParams
unsigned int vertexCount;
NzComputeUvSphereIndexVertexCount(primitive.sphere.uv.sliceCount, primitive.sphere.uv.stackCount, &indexCount, &vertexCount);
indexBuffer.reset(new NzIndexBuffer(vertexCount > std::numeric_limits<nzUInt16>::max(), indexCount, params.storage, nzBufferUsage_Static));
indexBuffer->SetPersistent(false);
indexBuffer = NzIndexBuffer::New(vertexCount > std::numeric_limits<nzUInt16>::max(), indexCount, params.storage, nzBufferUsage_Static);
vertexBuffer = NzVertexBuffer::New(declaration, vertexCount, params.storage, nzBufferUsage_Static);
vertexBuffer.reset(new NzVertexBuffer(declaration, vertexCount, params.storage, nzBufferUsage_Static));
vertexBuffer->SetPersistent(false);
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly);
NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly);
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer, nzBufferAccess_WriteOnly);
NzIndexMapper indexMapper(indexBuffer, nzBufferAccess_WriteOnly);
NzGenerateUvSphere(primitive.sphere.size, primitive.sphere.uv.sliceCount, primitive.sphere.uv.stackCount, matrix, primitive.textureCoords, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), indexMapper.begin(), &aabb);
break;
@ -292,24 +274,21 @@ NzSubMesh* NzMesh::BuildSubMesh(const NzPrimitive& primitive, const NzMeshParams
}
}
std::unique_ptr<NzStaticMesh> subMesh(new NzStaticMesh(this));
if (!subMesh->Create(vertexBuffer.get()))
NzStaticMeshRef subMesh = NzStaticMesh::New(this);
if (!subMesh->Create(vertexBuffer))
{
NazaraError("Failed to create StaticMesh");
return nullptr;
}
vertexBuffer.release();
if (params.optimizeIndexBuffers)
indexBuffer->Optimize();
subMesh->SetIndexBuffer(indexBuffer.get());
indexBuffer.release();
subMesh->SetAABB(aabb);
AddSubMesh(subMesh.get());
subMesh->SetIndexBuffer(indexBuffer);
return subMesh.release();
AddSubMesh(subMesh);
return subMesh;
}
void NzMesh::BuildSubMeshes(const NzPrimitiveList& list, const NzMeshParams& params)

View File

@ -227,8 +227,7 @@ void NzVertexBuffer::Reset(const NzVertexDeclaration* vertexDeclaration, unsigne
m_startOffset = 0;
m_vertexCount = length;
m_buffer = new NzBuffer(nzBufferType_Vertex, m_endOffset, storage, usage);
m_buffer->SetPersistent(false);
m_buffer = NzBuffer::New(nzBufferType_Vertex, m_endOffset, storage, usage);
m_vertexDeclaration = vertexDeclaration;
}