Merge remote-tracking branch 'origin/3D-Engine'
Former-commit-id: 1781615fc780accbe6c11d55fd896038d97ffec9
This commit is contained in:
29
include/Nazara/3D/3D.hpp
Normal file
29
include/Nazara/3D/3D.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - 3D Module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_3D_HPP
|
||||
#define NAZARA_3D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Initializer.hpp>
|
||||
|
||||
class Nz3D
|
||||
{
|
||||
public:
|
||||
Nz3D() = delete;
|
||||
~Nz3D() = delete;
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static bool IsInitialized();
|
||||
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
static unsigned int s_moduleReferenceCounter;
|
||||
};
|
||||
|
||||
#endif // NAZARA_3D_HPP
|
||||
38
include/Nazara/3D/Config.hpp
Normal file
38
include/Nazara/3D/Config.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
Nazara Engine - 3D module
|
||||
|
||||
Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CONFIG_3D_HPP
|
||||
#define NAZARA_CONFIG_3D_HPP
|
||||
|
||||
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
|
||||
|
||||
// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution)
|
||||
#define NAZARA_3D_MEMORYLEAKTRACKER 0
|
||||
|
||||
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
|
||||
#define NAZARA_3D_SAFE 1
|
||||
|
||||
#endif // NAZARA_CONFIG_3D_HPP
|
||||
11
include/Nazara/3D/Debug.hpp
Normal file
11
include/Nazara/3D/Debug.hpp
Normal file
@@ -0,0 +1,11 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - 3D Module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/3D/Config.hpp>
|
||||
#if NAZARA_3D_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
|
||||
#include <Nazara/Core/Debug/MemoryLeakTracker.hpp>
|
||||
|
||||
#define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete
|
||||
#define new new(__FILE__, __LINE__)
|
||||
#endif
|
||||
8
include/Nazara/3D/DebugOff.hpp
Normal file
8
include/Nazara/3D/DebugOff.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - 3D Module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#if NAZARA_3D_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
|
||||
#undef delete
|
||||
#undef new
|
||||
#endif
|
||||
@@ -50,7 +50,7 @@ class NAZARA_API NzResource
|
||||
void RemoveResourceListener(NzResourceListener* listener) const;
|
||||
void RemoveResourceReference() const;
|
||||
|
||||
void SetPersistent(bool persistent = true);
|
||||
void SetPersistent(bool persistent = true, bool checkReferenceCount = true);
|
||||
|
||||
protected:
|
||||
void NotifyCreated();
|
||||
|
||||
@@ -31,7 +31,7 @@ bool NzResourceLoader<Type, Parameters>::LoadFromFile(Type* resource, const NzSt
|
||||
NzFile file(path, NzFile::ReadOnly);
|
||||
if (!file.IsOpen())
|
||||
{
|
||||
NazaraError("Failed to open file");
|
||||
NazaraError("Failed to open \"" + path + '"');
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ bool NzResourceLoader<Type, Parameters>::LoadFromFile(Type* resource, const NzSt
|
||||
int cmp = NzString::Compare(loaderExt, ext);
|
||||
if (cmp == 0)
|
||||
{
|
||||
file.SetCursorPos(0);
|
||||
|
||||
if (!std::get<1>(*loader)(file, parameters))
|
||||
continue;
|
||||
|
||||
@@ -52,8 +54,6 @@ bool NzResourceLoader<Type, Parameters>::LoadFromFile(Type* resource, const NzSt
|
||||
return true;
|
||||
|
||||
NazaraWarning("Loader failed");
|
||||
|
||||
file.SetCursorPos(0);
|
||||
}
|
||||
else if (cmp < 0) // S'il est encore possible que l'extension se situe après
|
||||
continue;
|
||||
@@ -95,11 +95,13 @@ bool NzResourceLoader<Type, Parameters>::LoadFromStream(Type* resource, NzInputS
|
||||
nzUInt64 streamPos = stream.GetCursorPos();
|
||||
for (auto loader = Type::s_loaders.begin(); loader != Type::s_loaders.end(); ++loader)
|
||||
{
|
||||
stream.SetCursorPos(streamPos);
|
||||
|
||||
// Le loader supporte-t-il les données ?
|
||||
if (!std::get<1>(*loader)(stream, parameters))
|
||||
continue;
|
||||
|
||||
// On repositionne le stream au début
|
||||
// On repositionne le stream à son ancienne position
|
||||
stream.SetCursorPos(streamPos);
|
||||
|
||||
// Chargement de la ressource
|
||||
@@ -107,7 +109,6 @@ bool NzResourceLoader<Type, Parameters>::LoadFromStream(Type* resource, NzInputS
|
||||
return true;
|
||||
|
||||
NazaraWarning("Loader failed");
|
||||
stream.SetCursorPos(streamPos); // On repositionne au début
|
||||
}
|
||||
|
||||
NazaraError("Failed to load file: no loader");
|
||||
|
||||
@@ -590,9 +590,9 @@ NzMatrix4<T>& NzMatrix4<T>::MakeZero()
|
||||
|
||||
template<typename T>
|
||||
NzMatrix4<T>& NzMatrix4<T>::Set(T r11, T r12, T r13, T r14,
|
||||
T r21, T r22, T r23, T r24,
|
||||
T r31, T r32, T r33, T r34,
|
||||
T r41, T r42, T r43, T r44)
|
||||
T r21, T r22, T r23, T r24,
|
||||
T r31, T r32, T r33, T r34,
|
||||
T r41, T r42, T r43, T r44)
|
||||
{
|
||||
m11 = r11;
|
||||
m12 = r12;
|
||||
@@ -626,9 +626,7 @@ NzMatrix4<T>& NzMatrix4<T>::Set(const T matrix[16])
|
||||
template<typename T>
|
||||
NzMatrix4<T>& NzMatrix4<T>::Set(const NzMatrix4& matrix)
|
||||
{
|
||||
NazaraError("Check 1");
|
||||
std::memcpy(&m11, &matrix.m11, 16*sizeof(T));
|
||||
NazaraError("Check 2");
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
95
include/Nazara/Renderer/Material.hpp
Normal file
95
include/Nazara/Renderer/Material.hpp
Normal file
@@ -0,0 +1,95 @@
|
||||
// Copyright (C) 2012 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
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_MATERIAL_HPP
|
||||
#define NAZARA_MATERIAL_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
|
||||
struct NAZARA_API NzMaterialParams
|
||||
{
|
||||
bool loadDiffuseMap = true;
|
||||
bool loadSpecularMap = true;
|
||||
|
||||
bool IsValid() const;
|
||||
};
|
||||
|
||||
class NzMaterial;
|
||||
|
||||
using NzMaterialLoader = NzResourceLoader<NzMaterial, NzMaterialParams>;
|
||||
|
||||
class NAZARA_API NzMaterial : public NzResource
|
||||
{
|
||||
friend NzMaterialLoader;
|
||||
|
||||
public:
|
||||
NzMaterial();
|
||||
~NzMaterial();
|
||||
|
||||
void EnableAlphaBlending(bool alphaBlending);
|
||||
void EnableZTest(bool zTest);
|
||||
void EnableZWrite(bool zWrite);
|
||||
|
||||
NzColor GetAmbientColor() const;
|
||||
NzColor GetDiffuseColor() const;
|
||||
const NzTexture* GetDiffuseMap() const;
|
||||
nzBlendFunc GetDstAlpha() const;
|
||||
nzFaceCulling GetFaceCulling() const;
|
||||
nzFaceFilling GetFaceFilling() const;
|
||||
float GetShininess() const;
|
||||
NzColor GetSpecularColor() const;
|
||||
const NzTexture* GetSpecularMap() const;
|
||||
nzBlendFunc GetSrcAlpha() const;
|
||||
nzRendererComparison GetZTestCompare() const;
|
||||
|
||||
bool IsAlphaBlendingEnabled() const;
|
||||
bool IsZTestEnabled() const;
|
||||
bool IsZWriteEnabled() const;
|
||||
|
||||
bool LoadFromFile(const NzString& filePath, const NzMaterialParams& params = NzMaterialParams());
|
||||
bool LoadFromMemory(const void* data, std::size_t size, const NzMaterialParams& params = NzMaterialParams());
|
||||
bool LoadFromStream(NzInputStream& stream, const NzMaterialParams& params = NzMaterialParams());
|
||||
|
||||
void Reset();
|
||||
|
||||
void SetAmbientColor(const NzColor& ambient);
|
||||
void SetDiffuseColor(const NzColor& diffuse);
|
||||
void SetDiffuseMap(const NzTexture* map);
|
||||
void SetDstAlpha(nzBlendFunc func);
|
||||
void SetFaceCulling(nzFaceCulling culling);
|
||||
void SetFaceFilling(nzFaceFilling filling);
|
||||
void SetShininess(float shininess);
|
||||
void SetSpecularColor(const NzColor& specular);
|
||||
void SetSpecularMap(const NzTexture* map);
|
||||
void SetSrcAlpha(nzBlendFunc func);
|
||||
void SetZTestCompare(nzRendererComparison compareFunc);
|
||||
|
||||
static const NzMaterial* GetDefault();
|
||||
|
||||
private:
|
||||
nzBlendFunc m_dstAlpha;
|
||||
nzBlendFunc m_srcAlpha;
|
||||
nzFaceCulling m_faceCulling;
|
||||
nzFaceFilling m_faceFilling;
|
||||
nzRendererComparison m_zTestCompareFunc;
|
||||
NzColor m_ambientColor;
|
||||
NzColor m_diffuseColor;
|
||||
NzColor m_specularColor;
|
||||
const NzTexture* m_diffuseMap;
|
||||
const NzTexture* m_specularMap;
|
||||
bool m_alphaBlendingEnabled;
|
||||
bool m_zTestEnabled;
|
||||
bool m_zWriteEnabled;
|
||||
float m_shininess;
|
||||
|
||||
static NzMaterialLoader::LoaderList s_loaders;
|
||||
};
|
||||
|
||||
#endif // NAZARA_MATERIAL_HPP
|
||||
@@ -33,7 +33,7 @@ class NAZARA_API NzKeyframeMesh final : public NzSubMesh
|
||||
bool GetVertex(NzMeshVertex* dest, unsigned int frameIndex, unsigned int vertexIndex, bool queryUV = true) const;
|
||||
const NzVertexBuffer* GetVertexBuffer() const override;
|
||||
|
||||
void Interpolate(unsigned int frameA, unsigned int frameB, float interpolation) const;
|
||||
void Interpolate(const NzAnimation* animation, unsigned int frameA, unsigned int frameB, float interpolation) const;
|
||||
|
||||
bool IsAnimated() const override;
|
||||
bool IsValid();
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include <Nazara/Core/ResourceListener.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Utility/Animation.hpp>
|
||||
#include <Nazara/Utility/AxisAlignedBox.hpp>
|
||||
#include <Nazara/Utility/Skeleton.hpp>
|
||||
#include <Nazara/Utility/SubMesh.hpp>
|
||||
@@ -23,13 +22,13 @@ struct NAZARA_API NzMeshParams
|
||||
{
|
||||
NzMeshParams(); // Vérifie que le storage indiqué un peu plus bas est supporté
|
||||
|
||||
NzAnimationParams animation;
|
||||
nzBufferStorage storage = nzBufferStorage_Hardware;
|
||||
bool animated = true;
|
||||
|
||||
bool IsValid() const;
|
||||
};
|
||||
|
||||
class NzAnimation;
|
||||
class NzMesh;
|
||||
|
||||
typedef NzVertexStruct_XYZ_Normal_UV_Tangent NzMeshVertex;
|
||||
@@ -46,11 +45,10 @@ class NAZARA_API NzMesh : public NzResource, NzResourceListener
|
||||
NzMesh() = default;
|
||||
~NzMesh();
|
||||
|
||||
bool AddMaterial(const NzString& matPath, unsigned int* matIndex = nullptr);
|
||||
bool AddSubMesh(NzSubMesh* subMesh);
|
||||
bool AddSubMesh(const NzString& identifier, NzSubMesh* subMesh);
|
||||
|
||||
void Animate(unsigned int frameA, unsigned int frameB, float interpolation) const;
|
||||
void Animate(const NzAnimation* animation, unsigned int frameA, unsigned int frameB, float interpolation) const;
|
||||
|
||||
bool CreateKeyframe();
|
||||
bool CreateSkeletal(unsigned int jointCount);
|
||||
@@ -58,9 +56,8 @@ class NAZARA_API NzMesh : public NzResource, NzResourceListener
|
||||
void Destroy();
|
||||
|
||||
const NzAxisAlignedBox& GetAABB() const;
|
||||
const NzAnimation* GetAnimation() const;
|
||||
NzString GetAnimation() const;
|
||||
nzAnimationType GetAnimationType() const;
|
||||
unsigned int GetFrameCount() const;
|
||||
unsigned int GetJointCount() const;
|
||||
NzString GetMaterial(unsigned int index) const;
|
||||
unsigned int GetMaterialCount() const;
|
||||
@@ -74,8 +71,6 @@ class NAZARA_API NzMesh : public NzResource, NzResourceListener
|
||||
int GetSubMeshIndex(const NzString& identifier) const;
|
||||
unsigned int GetVertexCount() const;
|
||||
|
||||
bool HasAnimation() const;
|
||||
bool HasMaterial(unsigned int index) const;
|
||||
bool HasSubMesh(const NzString& identifier) const;
|
||||
bool HasSubMesh(unsigned int index = 0) const;
|
||||
|
||||
@@ -88,18 +83,18 @@ class NAZARA_API NzMesh : public NzResource, NzResourceListener
|
||||
bool LoadFromMemory(const void* data, std::size_t size, const NzMeshParams& params = NzMeshParams());
|
||||
bool LoadFromStream(NzInputStream& stream, const NzMeshParams& params = NzMeshParams());
|
||||
|
||||
void RemoveMaterial(unsigned int index);
|
||||
void RemoveSubMesh(const NzString& identifier);
|
||||
void RemoveSubMesh(unsigned int index);
|
||||
|
||||
bool SetAnimation(const NzAnimation* animation);
|
||||
void SetAnimation(const NzString& animationPath);
|
||||
void SetMaterial(unsigned int matIndex, const NzString& materialPath);
|
||||
void SetMaterialCount(unsigned int matCount);
|
||||
|
||||
void Skin(const NzSkeleton* skeleton) const;
|
||||
|
||||
static const NzVertexDeclaration* GetDeclaration();
|
||||
|
||||
private:
|
||||
void OnResourceCreated(const NzResource* resource, int index) override;
|
||||
void OnResourceReleased(const NzResource* resource, int index) override;
|
||||
|
||||
NzMeshImpl* m_impl = nullptr;
|
||||
|
||||
@@ -31,7 +31,7 @@ class NAZARA_API NzNode
|
||||
NzQuaternionf GetRotation() const;
|
||||
NzVector3f GetScale() const;
|
||||
NzVector3f GetTranslation() const;
|
||||
NzMatrix4f GetTransformMatrix() const;
|
||||
const NzMatrix4f& GetTransformMatrix() const;
|
||||
|
||||
NzNode& Interpolate(const NzNode& nodeA, const NzNode& nodeB, float interpolation);
|
||||
|
||||
|
||||
@@ -28,9 +28,9 @@ class NAZARA_API NzSubMesh : public NzResource
|
||||
virtual const NzAxisAlignedBox& GetAABB() const = 0;
|
||||
virtual nzAnimationType GetAnimationType() const = 0;
|
||||
virtual const NzIndexBuffer* GetIndexBuffer() const = 0;
|
||||
unsigned int GetMaterialIndex() const;
|
||||
const NzMesh* GetParent() const;
|
||||
nzPrimitiveType GetPrimitiveType() const;
|
||||
unsigned int GetSkinIndex() const;
|
||||
virtual const NzVertexBuffer* GetVertexBuffer() const = 0;
|
||||
virtual unsigned int GetVertexCount() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user