Merge branch 'master' into vulkan

Former-commit-id: 5e11ffb71a4deddeaa44a1b1e93aeea97525bd9c
This commit is contained in:
Lynix
2016-05-14 13:58:06 +02:00
107 changed files with 3433 additions and 1558 deletions

View File

@@ -1,4 +1,4 @@
// This file was automatically generated on 03 Feb 2016 at 00:06:56
// This file was automatically generated on 09 May 2016 at 17:07:09
/*
Nazara Engine - Core module
@@ -51,6 +51,7 @@
#include <Nazara/Core/FileLogger.hpp>
#include <Nazara/Core/Functor.hpp>
#include <Nazara/Core/GuillotineBinPack.hpp>
#include <Nazara/Core/HandledObject.hpp>
#include <Nazara/Core/HardwareInfo.hpp>
#include <Nazara/Core/Initializer.hpp>
#include <Nazara/Core/LockGuard.hpp>
@@ -61,6 +62,7 @@
#include <Nazara/Core/MemoryStream.hpp>
#include <Nazara/Core/MemoryView.hpp>
#include <Nazara/Core/Mutex.hpp>
#include <Nazara/Core/ObjectHandle.hpp>
#include <Nazara/Core/ObjectLibrary.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/OffsetOf.hpp>
@@ -72,8 +74,10 @@
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/ResourceManager.hpp>
#include <Nazara/Core/ResourceParameters.hpp>
#include <Nazara/Core/ResourceSaver.hpp>
#include <Nazara/Core/Semaphore.hpp>
#include <Nazara/Core/Serialization.hpp>
#include <Nazara/Core/SerializationContext.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Core/SparsePtr.hpp>
#include <Nazara/Core/StdLogger.hpp>

View File

@@ -9,7 +9,7 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Enums.hpp>
#include <Nazara/Core/Serialization.hpp>
#include <Nazara/Core/SerializationContext.hpp>
#include <functional>
#include <tuple>
#include <type_traits>

View File

@@ -209,14 +209,8 @@ namespace Nz
template<typename T>
std::enable_if_t<std::is_arithmetic<T>::value, bool> Serialize(SerializationContext& context, T value)
{
// Flush bits if a writing is in progress
if (context.currentBitPos != 8)
{
context.currentBitPos = 8;
if (!Serialize<UInt8>(context, context.currentByte))
NazaraWarning("Failed to flush bits");
}
// Flush bits in case a writing is in progress
context.FlushBits();
if (context.endianness != Endianness_Unknown && context.endianness != GetPlatformEndianness())
SwapBytes(&value, sizeof(T));
@@ -269,8 +263,7 @@ namespace Nz
{
NazaraAssert(value, "Invalid data pointer");
// Reset bit position
context.currentBitPos = 8;
context.ResetBitPosition();
if (context.stream->Read(value, sizeof(T)) == sizeof(T))
{

View File

@@ -31,7 +31,7 @@ namespace Nz
Bitset(const char* bits, unsigned int bitCount);
Bitset(const Bitset& bitset) = default;
explicit Bitset(const String& bits);
template<typename T> explicit Bitset(T value);
template<typename T> Bitset(T value);
Bitset(Bitset&& bitset) noexcept = default;
~Bitset() noexcept = default;

View File

@@ -120,19 +120,16 @@ namespace Nz
{
if (sizeof(T) <= sizeof(Block))
{
m_bitCount = CountBits(value);
m_bitCount = std::numeric_limits<T>::digits;
m_blocks.push_back(value);
}
else
{
// Note: I was kinda tired when I wrote this, there's probably a much easier method than checking bits to write bits
unsigned int bitPos = 0;
for (T bit = 1; bit < std::numeric_limits<T>::digits; bit <<= 1)
for (unsigned int bitPos = 0; bitPos < std::numeric_limits<T>::digits; bitPos++)
{
if (value & bit)
if (value & (T(1U) << bitPos))
UnboundedSet(bitPos, true);
bitPos++;
}
}
}
@@ -838,7 +835,7 @@ namespace Nz
Block block = m_blocks[i];
// Compute the position of LSB in the block (and adjustement of the position)
// Compute the position of LSB in the block (and adjustment of the position)
return IntegralLog2Pot(block & -block) + i*bitsPerBlock;
}

View File

@@ -9,7 +9,7 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/ByteArray.hpp>
#include <Nazara/Core/Serialization.hpp>
#include <Nazara/Core/SerializationContext.hpp>
#include <Nazara/Core/Stream.hpp>
#include <memory>

View File

@@ -25,6 +25,8 @@ namespace Nz
inline Color(const Color& color) = default;
inline ~Color() = default;
inline bool IsOpaque() const;
inline String ToString() const;
inline Color operator+(const Color& angles) const;

View File

@@ -72,6 +72,15 @@ namespace Nz
{
}
/*!
* \brief Return true is the color has no degree of transparency
* \return true if the color has an alpha value of 255
*/
inline bool Color::IsOpaque() const
{
return a == 255;
}
/*!
* \brief Converts this to string
* \return String representation of the object "Color(r, g, b[, a])"

View File

@@ -93,6 +93,7 @@ namespace Nz
enum ParameterType
{
ParameterType_Boolean,
ParameterType_Color,
ParameterType_Float,
ParameterType_Integer,
ParameterType_None,

View File

@@ -36,7 +36,8 @@ namespace Nz
private:
void RegisterHandle(ObjectHandle<T>* handle);
void UnregisterHandle(ObjectHandle<T>* handle);
void UnregisterHandle(ObjectHandle<T>* handle) noexcept;
void UpdateHandle(ObjectHandle<T>* oldHandle, ObjectHandle<T>* newHandle) noexcept;
std::vector<ObjectHandle<T>*> m_handles;
};

View File

@@ -71,14 +71,24 @@ namespace Nz
}
template<typename T>
void HandledObject<T>::UnregisterHandle(ObjectHandle<T>* handle)
void HandledObject<T>::UnregisterHandle(ObjectHandle<T>* handle) noexcept
{
///DOC: Un handle ne doit être libéré qu'une fois, et doit faire partie de la liste, sous peine de crash
auto it = std::find(m_handles.begin(), m_handles.end(), handle);
NazaraAssert(it != m_handles.end(), "Handle not registred");
NazaraAssert(it != m_handles.end(), "Handle not registered");
// On échange cet élément avec le dernier, et on diminue la taille du vector de 1
// Swap and pop idiom, more efficient than vector::erase
std::swap(*it, m_handles.back());
m_handles.pop_back();
}
template<typename T>
void HandledObject<T>::UpdateHandle(ObjectHandle<T>* oldHandle, ObjectHandle<T>* newHandle) noexcept
{
auto it = std::find(m_handles.begin(), m_handles.end(), oldHandle);
NazaraAssert(it != m_handles.end(), "Handle not registered");
// Simply update the handle
*it = newHandle;
}
}

View File

@@ -23,6 +23,7 @@ namespace Nz
ObjectHandle();
explicit ObjectHandle(T* object);
ObjectHandle(const ObjectHandle& handle);
ObjectHandle(ObjectHandle&& handle) noexcept;
~ObjectHandle();
T* GetObject() const;
@@ -31,6 +32,7 @@ namespace Nz
void Reset(T* object = nullptr);
void Reset(const ObjectHandle& handle);
void Reset(ObjectHandle&& handle) noexcept;
ObjectHandle& Swap(ObjectHandle& handle);
@@ -42,6 +44,7 @@ namespace Nz
ObjectHandle& operator=(T* object);
ObjectHandle& operator=(const ObjectHandle& handle);
ObjectHandle& operator=(ObjectHandle&& handle) noexcept;
static const ObjectHandle InvalidHandle;

View File

@@ -24,11 +24,18 @@ namespace Nz
template<typename T>
ObjectHandle<T>::ObjectHandle(const ObjectHandle<T>& handle) :
ObjectHandle()
ObjectHandle()
{
Reset(handle);
}
template<typename T>
ObjectHandle<T>::ObjectHandle(ObjectHandle<T>&& handle) noexcept :
ObjectHandle()
{
Reset(std::move(handle));
}
template<typename T>
ObjectHandle<T>::~ObjectHandle()
{
@@ -66,6 +73,20 @@ namespace Nz
Reset(handle.GetObject());
}
template<typename T>
void ObjectHandle<T>::Reset(ObjectHandle<T>&& handle) noexcept
{
if (m_object)
m_object->UnregisterHandle(this);
if (T* object = handle.GetObject())
{
m_object = handle.m_object;
handle.m_object = nullptr;
object->UpdateHandle(&handle, this);
}
}
template<typename T>
ObjectHandle<T>& ObjectHandle<T>::Swap(ObjectHandle<T>& handle)
{
@@ -138,6 +159,14 @@ namespace Nz
return *this;
}
template<typename T>
ObjectHandle<T>& ObjectHandle<T>::operator=(ObjectHandle<T>&& handle) noexcept
{
Reset(std::move(handle));
return *this;
}
template<typename T>
void ObjectHandle<T>::OnObjectDestroyed()
{

View File

@@ -17,8 +17,6 @@ namespace Nz
template<typename T>
class ObjectRef
{
static_assert(std::is_base_of<RefCounted, T>::value, "ObjectRef shall only be used with RefCounted-derived type");
public:
ObjectRef();
ObjectRef(T* object);

View File

@@ -8,6 +8,7 @@
#define NAZARA_PARAMETERLIST_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/String.hpp>
#include <atomic>
#include <unordered_map>
@@ -27,6 +28,7 @@ namespace Nz
void Clear();
bool GetBooleanParameter(const String& name, bool* value) const;
bool GetColorParameter(const String& name, Color* value) const;
bool GetFloatParameter(const String& name, float* value) const;
bool GetIntegerParameter(const String& name, int* value) const;
bool GetParameterType(const String& name, ParameterType* type) const;
@@ -39,13 +41,14 @@ namespace Nz
void RemoveParameter(const String& name);
void SetParameter(const String& name);
void SetParameter(const String& name, const Color& value);
void SetParameter(const String& name, const String& value);
void SetParameter(const String& name, const char* value);
void SetParameter(const String& name, void* value);
void SetParameter(const String& name, void* value, Destructor destructor);
void SetParameter(const String& name, bool value);
void SetParameter(const String& name, float value);
void SetParameter(const String& name, int value);
void SetParameter(const String& name, void* value);
void SetParameter(const String& name, void* value, Destructor destructor);
ParameterList& operator=(const ParameterList& list);
ParameterList& operator=(ParameterList&&) = default;
@@ -79,6 +82,7 @@ namespace Nz
float floatVal;
int intVal;
void* ptrVal;
Color colorVal;
String stringVal;
UserdataValue* userdataVal;
};

View File

@@ -8,6 +8,7 @@
#define NAZARA_SERIALIZATION_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Endianness.hpp>
#include <functional>
#include <tuple>
@@ -17,13 +18,18 @@ namespace Nz
{
class Stream;
struct SerializationContext
struct NAZARA_CORE_API SerializationContext
{
Stream* stream;
Endianness endianness = Endianness_BigEndian; //< Default to Big Endian encoding
UInt8 currentBitPos = 8; //< 8 means no bit is currently wrote
UInt8 currentByte; //< Undefined value, will be initialized at the first bit write
void FlushBits();
inline void ResetBitPosition();
};
}
#include <Nazara/Core/SerializationContext.inl>
#endif // NAZARA_SERIALIZATION_HPP

View File

@@ -0,0 +1,24 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/SerializationContext.hpp>
#include <Nazara/Core/Debug.hpp>
namespace Nz
{
/*!
* \brief Reset the current bit cursor
* \remark This function only reset the cursor position, it doesn't do any writing
if you wish to write all bits and reset bit position, call FlushBits
\see FlushBits
*/
inline void SerializationContext::ResetBitPosition()
{
currentBitPos = 8;
}
}
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -9,7 +9,7 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Endianness.hpp>
#include <Nazara/Core/Serialization.hpp>
#include <Nazara/Core/SerializationContext.hpp>
#include <atomic>
#include <iosfwd>
#include <memory>

View File

@@ -62,7 +62,9 @@ namespace Nz
struct DirectionalLight
{
Color color;
Matrix4f transformMatrix;
Vector3f direction;
Texture* shadowMap;
float ambientFactor;
float diffuseFactor;
};
@@ -71,6 +73,7 @@ namespace Nz
{
Color color;
Vector3f position;
Texture* shadowMap;
float ambientFactor;
float attenuation;
float diffuseFactor;
@@ -81,8 +84,10 @@ namespace Nz
struct SpotLight
{
Color color;
Matrix4f transformMatrix;
Vector3f direction;
Vector3f position;
Texture* shadowMap;
float ambientFactor;
float attenuation;
float diffuseFactor;

View File

@@ -0,0 +1,53 @@
// 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
#pragma once
#ifndef NAZARA_DEPTHRENDERQUEUE_HPP
#define NAZARA_DEPTHRENDERQUEUE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Graphics/AbstractRenderQueue.hpp>
#include <Nazara/Graphics/ForwardRenderQueue.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Utility/IndexBuffer.hpp>
#include <Nazara/Utility/VertexBuffer.hpp>
#include <map>
#include <tuple>
namespace Nz
{
class NAZARA_GRAPHICS_API DepthRenderQueue : public ForwardRenderQueue
{
public:
DepthRenderQueue();
~DepthRenderQueue() = default;
void AddBillboard(int renderOrder, const Material* material, const Vector3f& position, const Vector2f& size, const Vector2f& sinCos = Vector2f(0.f, 1.f), const Color& color = Color::White) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) override;
void AddDirectionalLight(const DirectionalLight& light) override;
void AddMesh(int renderOrder, const Material* material, const MeshData& meshData, const Boxf& meshAABB, const Matrix4f& transformMatrix) override;
void AddPointLight(const PointLight& light) override;
void AddSpotLight(const SpotLight& light) override;
void AddSprites(int renderOrder, const Material* material, const VertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount, const Texture* overlay = nullptr) override;
private:
inline bool IsMaterialSuitable(const Material* material) const;
MaterialRef m_baseMaterial;
};
}
#include <Nazara/Graphics/DepthRenderQueue.inl>
#endif // NAZARA_DEPTHRENDERQUEUE_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 <Nazara/Graphics/Debug.hpp>
namespace Nz
{
bool DepthRenderQueue::IsMaterialSuitable(const Material* material) const
{
NazaraAssert(material, "Invalid material");
return material->HasDepthMaterial() || (material->IsEnabled(RendererParameter_DepthBuffer) && material->IsEnabled(RendererParameter_DepthWrite) && material->IsShadowCastingEnabled());
}
}
#include <Nazara/Graphics/DebugOff.hpp>

View File

@@ -0,0 +1,79 @@
// 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
#pragma once
#ifndef NAZARA_DEPTHRENDERTECHNIQUE_HPP
#define NAZARA_DEPTHRENDERTECHNIQUE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/AbstractRenderTechnique.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/DepthRenderQueue.hpp>
#include <Nazara/Graphics/Light.hpp>
#include <Nazara/Renderer/Shader.hpp>
#include <Nazara/Utility/IndexBuffer.hpp>
#include <Nazara/Utility/VertexBuffer.hpp>
namespace Nz
{
class NAZARA_GRAPHICS_API DepthRenderTechnique : public AbstractRenderTechnique
{
public:
DepthRenderTechnique();
~DepthRenderTechnique() = default;
void Clear(const SceneData& sceneData) const override;
bool Draw(const SceneData& sceneData) const override;
AbstractRenderQueue* GetRenderQueue() override;
RenderTechniqueType GetType() const override;
static bool Initialize();
static void Uninitialize();
private:
struct ShaderUniforms;
void DrawBasicSprites(const SceneData& sceneData, ForwardRenderQueue::Layer& layer) const;
void DrawBillboards(const SceneData& sceneData, ForwardRenderQueue::Layer& layer) const;
void DrawOpaqueModels(const SceneData& sceneData, ForwardRenderQueue::Layer& layer) const;
const ShaderUniforms* GetShaderUniforms(const Shader* shader) const;
void OnShaderInvalidated(const Shader* shader) const;
struct LightIndex
{
LightType type;
float score;
unsigned int index;
};
struct ShaderUniforms
{
NazaraSlot(Shader, OnShaderUniformInvalidated, shaderUniformInvalidatedSlot);
NazaraSlot(Shader, OnShaderRelease, shaderReleaseSlot);
// Autre uniformes
int eyePosition;
int sceneAmbient;
int textureOverlay;
};
mutable std::unordered_map<const Shader*, ShaderUniforms> m_shaderUniforms;
Buffer m_vertexBuffer;
mutable DepthRenderQueue m_renderQueue;
VertexBuffer m_billboardPointBuffer;
VertexBuffer m_spriteBuffer;
static IndexBuffer s_quadIndexBuffer;
static VertexBuffer s_quadVertexBuffer;
static VertexDeclaration s_billboardInstanceDeclaration;
static VertexDeclaration s_billboardVertexDeclaration;
};
}
#include <Nazara/Graphics/dEPTHRenderTechnique.inl>
#endif // NAZARA_DEPTHRENDERTECHNIQUE_HPP

View File

@@ -0,0 +1,3 @@
// 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

View File

@@ -108,6 +108,7 @@ namespace Nz
RenderTechniqueType_AdvancedForward, // AdvancedForwardRenderTechnique
RenderTechniqueType_BasicForward, // BasicForwardRenderTechnique
RenderTechniqueType_DeferredShading, // DeferredRenderTechnique
RenderTechniqueType_Depth, // DepthRenderTechnique
RenderTechniqueType_LightPrePass, // LightPrePassRenderTechnique
RenderTechniqueType_User,

View File

@@ -36,7 +36,7 @@ namespace Nz
static bool Initialize();
static void Uninitialize();
private:
protected:
struct ShaderUniforms;
void ChooseLights(const Spheref& object, bool includeDirectionalLights = true) const;
@@ -46,7 +46,7 @@ namespace Nz
void DrawTransparentModels(const SceneData& sceneData, ForwardRenderQueue::Layer& layer) const;
const ShaderUniforms* GetShaderUniforms(const Shader* shader) const;
void OnShaderInvalidated(const Shader* shader) const;
void SendLightUniforms(const Shader* shader, const LightUniforms& uniforms, unsigned int index, unsigned int uniformOffset) const;
void SendLightUniforms(const Shader* shader, const LightUniforms& uniforms, unsigned int index, unsigned int uniformOffset, UInt8 availableTextureUnit) const;
static float ComputeDirectionalLightScore(const Spheref& object, const AbstractRenderQueue::DirectionalLight& light);
static float ComputePointLightScore(const Spheref& object, const AbstractRenderQueue::PointLight& light);
@@ -89,6 +89,7 @@ namespace Nz
unsigned int m_maxLightPassPerObject;
static IndexBuffer s_quadIndexBuffer;
static TextureSampler s_shadowSampler;
static VertexBuffer s_quadVertexBuffer;
static VertexDeclaration s_billboardInstanceDeclaration;
static VertexDeclaration s_billboardVertexDeclaration;

View File

@@ -2,10 +2,16 @@
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Renderer/Renderer.hpp>
namespace Nz
{
inline void ForwardRenderTechnique::SendLightUniforms(const Shader* shader, const LightUniforms& uniforms, unsigned int index, unsigned int uniformOffset) const
inline void ForwardRenderTechnique::SendLightUniforms(const Shader* shader, const LightUniforms& uniforms, unsigned int index, unsigned int uniformOffset, UInt8 availableTextureUnit) const
{
// If anyone got a better idea..
int dummyCubemap = Renderer::GetMaxTextureUnits() - 1;
int dummyTexture = Renderer::GetMaxTextureUnits() - 2;
if (index < m_lights.size())
{
const LightIndex& lightIndex = m_lights[index];
@@ -21,6 +27,20 @@ namespace Nz
shader->SendColor(uniforms.locations.color + uniformOffset, light.color);
shader->SendVector(uniforms.locations.factors + uniformOffset, Vector2f(light.ambientFactor, light.diffuseFactor));
shader->SendVector(uniforms.locations.parameters1 + uniformOffset, Vector4f(light.direction));
shader->SendBoolean(uniforms.locations.shadowMapping + uniformOffset, light.shadowMap != nullptr);
if (light.shadowMap)
{
Renderer::SetTexture(availableTextureUnit, light.shadowMap);
Renderer::SetTextureSampler(availableTextureUnit, s_shadowSampler);
shader->SendMatrix(uniforms.locations.lightViewProjMatrix + index, light.transformMatrix);
shader->SendInteger(uniforms.locations.directionalSpotLightShadowMap + index, availableTextureUnit);
}
else
shader->SendInteger(uniforms.locations.directionalSpotLightShadowMap + index, dummyTexture);
shader->SendInteger(uniforms.locations.pointLightShadowMap + index, dummyCubemap);
break;
}
@@ -32,6 +52,19 @@ namespace Nz
shader->SendVector(uniforms.locations.factors + uniformOffset, Vector2f(light.ambientFactor, light.diffuseFactor));
shader->SendVector(uniforms.locations.parameters1 + uniformOffset, Vector4f(light.position, light.attenuation));
shader->SendVector(uniforms.locations.parameters2 + uniformOffset, Vector4f(0.f, 0.f, 0.f, light.invRadius));
shader->SendBoolean(uniforms.locations.shadowMapping + uniformOffset, light.shadowMap != nullptr);
if (light.shadowMap)
{
Renderer::SetTexture(availableTextureUnit, light.shadowMap);
Renderer::SetTextureSampler(availableTextureUnit, s_shadowSampler);
shader->SendInteger(uniforms.locations.pointLightShadowMap + index, availableTextureUnit);
}
else
shader->SendInteger(uniforms.locations.pointLightShadowMap + index, dummyCubemap);
shader->SendInteger(uniforms.locations.directionalSpotLightShadowMap + index, dummyTexture);
break;
}
@@ -44,12 +77,31 @@ namespace Nz
shader->SendVector(uniforms.locations.parameters1 + uniformOffset, Vector4f(light.position, light.attenuation));
shader->SendVector(uniforms.locations.parameters2 + uniformOffset, Vector4f(light.direction, light.invRadius));
shader->SendVector(uniforms.locations.parameters3 + uniformOffset, Vector2f(light.innerAngleCosine, light.outerAngleCosine));
shader->SendBoolean(uniforms.locations.shadowMapping + uniformOffset, light.shadowMap != nullptr);
if (light.shadowMap)
{
Renderer::SetTexture(availableTextureUnit, light.shadowMap);
Renderer::SetTextureSampler(availableTextureUnit, s_shadowSampler);
shader->SendMatrix(uniforms.locations.lightViewProjMatrix + index, light.transformMatrix);
shader->SendInteger(uniforms.locations.directionalSpotLightShadowMap + index, availableTextureUnit);
}
else
shader->SendInteger(uniforms.locations.directionalSpotLightShadowMap + index, dummyTexture);
shader->SendInteger(uniforms.locations.pointLightShadowMap + index, dummyCubemap);
break;
}
}
}
else
{
shader->SendInteger(uniforms.locations.type + uniformOffset, -1); //< Disable the light in the shader
shader->SendInteger(uniforms.locations.directionalSpotLightShadowMap + index, dummyTexture);
shader->SendInteger(uniforms.locations.pointLightShadowMap + index, dummyCubemap);
}
}
inline float ForwardRenderTechnique::ComputeDirectionalLightScore(const Spheref& object, const AbstractRenderQueue::DirectionalLight& light)
@@ -78,7 +130,7 @@ namespace Nz
NazaraUnused(object);
NazaraUnused(light);
// Directional light are always suitables
// Directional light are always suitable
return true;
}

View File

@@ -11,6 +11,8 @@
#include <Nazara/Core/Color.hpp>
#include <Nazara/Graphics/Enums.hpp>
#include <Nazara/Graphics/Renderable.hpp>
#include <Nazara/Renderer/RenderTexture.hpp>
#include <Nazara/Renderer/Texture.hpp>
namespace Nz
{
@@ -21,7 +23,8 @@ namespace Nz
{
public:
Light(LightType type = LightType_Point);
Light(const Light& light) = default;
inline Light(const Light& light);
Light(Light&& light) = default;
~Light() = default;
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix) const override;
@@ -31,37 +34,56 @@ namespace Nz
bool Cull(const Frustumf& frustum, const Matrix4f& transformMatrix) const override;
float GetAmbientFactor() const;
float GetAttenuation() const;
Color GetColor() const;
float GetDiffuseFactor() const;
float GetInnerAngle() const;
float GetInnerAngleCosine() const;
float GetInvRadius() const;
LightType GetLightType() const;
float GetOuterAngle() const;
float GetOuterAngleCosine() const;
float GetOuterAngleTangent() const;
float GetRadius() const;
inline void EnableShadowCasting(bool castShadows);
void SetAmbientFactor(float factor);
void SetAttenuation(float attenuation);
void SetColor(const Color& color);
void SetDiffuseFactor(float factor);
void SetInnerAngle(float innerAngle);
void SetLightType(LightType type);
void SetOuterAngle(float outerAngle);
void SetRadius(float radius);
inline void EnsureShadowMapUpdate() const;
inline float GetAmbientFactor() const;
inline float GetAttenuation() const;
inline Color GetColor() const;
inline float GetDiffuseFactor() const;
inline float GetInnerAngle() const;
inline float GetInnerAngleCosine() const;
inline float GetInvRadius() const;
inline LightType GetLightType() const;
inline float GetOuterAngle() const;
inline float GetOuterAngleCosine() const;
inline float GetOuterAngleTangent() const;
inline float GetRadius() const;
inline TextureRef GetShadowMap() const;
inline PixelFormatType GetShadowMapFormat() const;
inline const Vector2ui& GetShadowMapSize() const;
inline bool IsShadowCastingEnabled() const;
inline void SetAmbientFactor(float factor);
inline void SetAttenuation(float attenuation);
inline void SetColor(const Color& color);
inline void SetDiffuseFactor(float factor);
inline void SetInnerAngle(float innerAngle);
inline void SetLightType(LightType type);
inline void SetOuterAngle(float outerAngle);
inline void SetRadius(float radius);
inline void SetShadowMapFormat(PixelFormatType shadowFormat);
inline void SetShadowMapSize(const Vector2ui& size);
void UpdateBoundingVolume(const Matrix4f& transformMatrix) override;
Light& operator=(const Light& light) = default;
Light& operator=(const Light& light);
Light& operator=(Light&& light) = default;
private:
void MakeBoundingVolume() const override;
inline void InvalidateShadowMap();
void UpdateShadowMap() const;
LightType m_type;
Color m_color;
LightType m_type;
PixelFormatType m_shadowMapFormat;
Vector2ui m_shadowMapSize;
mutable TextureRef m_shadowMap;
bool m_shadowCastingEnabled;
mutable bool m_shadowMapUpdated;
float m_ambientFactor;
float m_attenuation;
float m_diffuseFactor;
@@ -80,10 +102,14 @@ namespace Nz
{
int type;
int color;
int directionalSpotLightShadowMap;
int factors;
int lightViewProjMatrix;
int parameters1;
int parameters2;
int parameters3;
int pointLightShadowMap;
int shadowMapping;
};
bool ubo;

View File

@@ -7,6 +7,42 @@
namespace Nz
{
inline Light::Light(const Light& light) :
Renderable(light),
m_type(light.m_type),
m_shadowMapFormat(light.m_shadowMapFormat),
m_color(light.m_color),
m_shadowMapSize(light.m_shadowMapSize),
m_shadowCastingEnabled(light.m_shadowCastingEnabled),
m_shadowMapUpdated(false),
m_ambientFactor(light.m_ambientFactor),
m_attenuation(light.m_attenuation),
m_diffuseFactor(light.m_diffuseFactor),
m_innerAngle(light.m_innerAngle),
m_innerAngleCosine(light.m_innerAngleCosine),
m_invRadius(light.m_invRadius),
m_outerAngle(light.m_outerAngle),
m_outerAngleCosine(light.m_outerAngleCosine),
m_outerAngleTangent(light.m_outerAngleTangent),
m_radius(light.m_radius)
{
}
inline void Light::EnableShadowCasting(bool castShadows)
{
if (m_shadowCastingEnabled != castShadows)
{
m_shadowCastingEnabled = castShadows;
m_shadowMapUpdated = false;
}
}
inline void Light::EnsureShadowMapUpdate() const
{
if (!m_shadowMapUpdated)
UpdateShadowMap();
}
inline float Light::GetAmbientFactor() const
{
return m_ambientFactor;
@@ -67,6 +103,28 @@ namespace Nz
return m_radius;
}
inline TextureRef Light::GetShadowMap() const
{
EnsureShadowMapUpdate();
return m_shadowMap;
}
inline PixelFormatType Light::GetShadowMapFormat() const
{
return m_shadowMapFormat;
}
inline const Vector2ui& Light::GetShadowMapSize() const
{
return m_shadowMapSize;
}
inline bool Light::IsShadowCastingEnabled() const
{
return m_shadowCastingEnabled;
}
inline void Light::SetAmbientFactor(float factor)
{
m_ambientFactor = factor;
@@ -96,6 +154,8 @@ namespace Nz
inline void Light::SetLightType(LightType type)
{
m_type = type;
InvalidateShadowMap();
}
inline void Light::SetOuterAngle(float outerAngle)
@@ -115,6 +175,53 @@ namespace Nz
InvalidateBoundingVolume();
}
inline void Light::SetShadowMapFormat(PixelFormatType shadowFormat)
{
NazaraAssert(PixelFormat::GetType(shadowFormat) == PixelFormatTypeType_Depth, "Shadow format type is not a depth format");
m_shadowMapFormat = shadowFormat;
InvalidateShadowMap();
}
inline void Light::SetShadowMapSize(const Vector2ui& size)
{
NazaraAssert(size.x > 0 && size.y > 0, "Shadow map size must have a positive size");
m_shadowMapSize = size;
InvalidateShadowMap();
}
inline Light& Light::operator=(const Light& light)
{
Renderable::operator=(light);
m_ambientFactor = light.m_ambientFactor;
m_attenuation = light.m_attenuation;
m_color = light.m_color;
m_diffuseFactor = light.m_diffuseFactor;
m_innerAngle = light.m_innerAngle;
m_innerAngleCosine = light.m_innerAngleCosine;
m_invRadius = light.m_invRadius;
m_outerAngle = light.m_outerAngle;
m_outerAngleCosine = light.m_outerAngleCosine;
m_outerAngleTangent = light.m_outerAngleTangent;
m_radius = light.m_radius;
m_shadowCastingEnabled = light.m_shadowCastingEnabled;
m_shadowMapFormat = light.m_shadowMapFormat;
m_shadowMapSize = light.m_shadowMapSize;
m_type = light.m_type;
InvalidateShadowMap();
return *this;
}
inline void Light::InvalidateShadowMap()
{
m_shadowMapUpdated = false;
}
}
#include <Nazara/Renderer/DebugOff.hpp>

View File

@@ -24,6 +24,7 @@
#include <Nazara/Renderer/Texture.hpp>
#include <Nazara/Renderer/TextureSampler.hpp>
#include <Nazara/Renderer/UberShader.hpp>
#include <Nazara/Utility/MaterialData.hpp>
namespace Nz
{
@@ -56,90 +57,99 @@ namespace Nz
friend class Graphics;
public:
Material();
Material(const Material& material);
~Material();
inline Material();
inline Material(const Material& material);
inline ~Material();
const Shader* Apply(UInt32 shaderFlags = 0, UInt8 textureUnit = 0, UInt8* lastUsedUnit = nullptr) const;
void Enable(RendererParameter renderParameter, bool enable);
void EnableAlphaTest(bool alphaTest);
void EnableDepthSorting(bool depthSorting);
void EnableLighting(bool lighting);
void EnableTransform(bool transform);
void BuildFromParameters(const ParameterList& matData, const MaterialParams& matParams = MaterialParams());
Texture* GetAlphaMap() const;
float GetAlphaThreshold() const;
Color GetAmbientColor() const;
RendererComparison GetDepthFunc() const;
Color GetDiffuseColor() const;
Texture* GetDiffuseMap() const;
TextureSampler& GetDiffuseSampler();
const TextureSampler& GetDiffuseSampler() const;
BlendFunc GetDstBlend() const;
Texture* GetEmissiveMap() const;
FaceSide GetFaceCulling() const;
FaceFilling GetFaceFilling() const;
Texture* GetHeightMap() const;
Texture* GetNormalMap() const;
const RenderStates& GetRenderStates() const;
const UberShader* GetShader() const;
const UberShaderInstance* GetShaderInstance(UInt32 flags = ShaderFlags_None) const;
float GetShininess() const;
Color GetSpecularColor() const;
Texture* GetSpecularMap() const;
TextureSampler& GetSpecularSampler();
const TextureSampler& GetSpecularSampler() const;
BlendFunc GetSrcBlend() const;
inline void Enable(RendererParameter renderParameter, bool enable);
inline void EnableAlphaTest(bool alphaTest);
inline void EnableDepthSorting(bool depthSorting);
inline void EnableLighting(bool lighting);
inline void EnableShadowCasting(bool castShadows);
inline void EnableShadowReceive(bool receiveShadows);
inline void EnableTransform(bool transform);
bool HasAlphaMap() const;
bool HasDiffuseMap() const;
bool HasEmissiveMap() const;
bool HasHeightMap() const;
bool HasNormalMap() const;
bool HasSpecularMap() const;
inline const TextureRef& GetAlphaMap() const;
inline float GetAlphaThreshold() const;
inline Color GetAmbientColor() const;
inline RendererComparison GetDepthFunc() const;
inline const MaterialRef& GetDepthMaterial() const;
inline Color GetDiffuseColor() const;
inline const TextureRef& GetDiffuseMap() const;
inline TextureSampler& GetDiffuseSampler();
inline const TextureSampler& GetDiffuseSampler() const;
inline BlendFunc GetDstBlend() const;
inline const TextureRef& GetEmissiveMap() const;
inline FaceSide GetFaceCulling() const;
inline FaceFilling GetFaceFilling() const;
inline const TextureRef& GetHeightMap() const;
inline const TextureRef& GetNormalMap() const;
inline const RenderStates& GetRenderStates() const;
inline const UberShader* GetShader() const;
inline const UberShaderInstance* GetShaderInstance(UInt32 flags = ShaderFlags_None) const;
inline float GetShininess() const;
inline Color GetSpecularColor() const;
inline const TextureRef& GetSpecularMap() const;
inline TextureSampler& GetSpecularSampler();
inline const TextureSampler& GetSpecularSampler() const;
inline BlendFunc GetSrcBlend() const;
bool IsAlphaTestEnabled() const;
bool IsDepthSortingEnabled() const;
bool IsEnabled(RendererParameter renderParameter) const;
bool IsLightingEnabled() const;
bool IsTransformEnabled() const;
inline bool HasAlphaMap() const;
inline bool HasDepthMaterial() const;
inline bool HasDiffuseMap() const;
inline bool HasEmissiveMap() const;
inline bool HasHeightMap() const;
inline bool HasNormalMap() const;
inline bool HasSpecularMap() const;
bool LoadFromFile(const String& filePath, const MaterialParams& params = MaterialParams());
bool LoadFromMemory(const void* data, std::size_t size, const MaterialParams& params = MaterialParams());
bool LoadFromStream(Stream& stream, const MaterialParams& params = MaterialParams());
inline bool IsAlphaTestEnabled() const;
inline bool IsDepthSortingEnabled() const;
inline bool IsEnabled(RendererParameter renderParameter) const;
inline bool IsLightingEnabled() const;
inline bool IsShadowCastingEnabled() const;
inline bool IsShadowReceiveEnabled() const;
inline bool IsTransformEnabled() const;
inline bool LoadFromFile(const String& filePath, const MaterialParams& params = MaterialParams());
inline bool LoadFromMemory(const void* data, std::size_t size, const MaterialParams& params = MaterialParams());
inline bool LoadFromStream(Stream& stream, const MaterialParams& params = MaterialParams());
void Reset();
bool SetAlphaMap(const String& textureName);
void SetAlphaMap(TextureRef alphaMap);
void SetAlphaThreshold(float alphaThreshold);
void SetAmbientColor(const Color& ambient);
void SetDepthFunc(RendererComparison depthFunc);
void SetDiffuseColor(const Color& diffuse);
bool SetDiffuseMap(const String& textureName);
void SetDiffuseMap(TextureRef diffuseMap);
void SetDiffuseSampler(const TextureSampler& sampler);
void SetDstBlend(BlendFunc func);
bool SetEmissiveMap(const String& textureName);
void SetEmissiveMap(TextureRef textureName);
void SetFaceCulling(FaceSide faceSide);
void SetFaceFilling(FaceFilling filling);
bool SetHeightMap(const String& textureName);
void SetHeightMap(TextureRef textureName);
bool SetNormalMap(const String& textureName);
void SetNormalMap(TextureRef textureName);
void SetRenderStates(const RenderStates& states);
void SetShader(UberShaderConstRef uberShader);
bool SetShader(const String& uberShaderName);
void SetShininess(float shininess);
void SetSpecularColor(const Color& specular);
bool SetSpecularMap(const String& textureName);
void SetSpecularMap(TextureRef specularMap);
void SetSpecularSampler(const TextureSampler& sampler);
void SetSrcBlend(BlendFunc func);
inline bool SetAlphaMap(const String& textureName);
inline void SetAlphaMap(TextureRef alphaMap);
inline void SetAlphaThreshold(float alphaThreshold);
inline void SetAmbientColor(const Color& ambient);
inline void SetDepthFunc(RendererComparison depthFunc);
inline void SetDepthMaterial(MaterialRef depthMaterial);
inline void SetDiffuseColor(const Color& diffuse);
inline bool SetDiffuseMap(const String& textureName);
inline void SetDiffuseMap(TextureRef diffuseMap);
inline void SetDiffuseSampler(const TextureSampler& sampler);
inline void SetDstBlend(BlendFunc func);
inline bool SetEmissiveMap(const String& textureName);
inline void SetEmissiveMap(TextureRef textureName);
inline void SetFaceCulling(FaceSide faceSide);
inline void SetFaceFilling(FaceFilling filling);
inline bool SetHeightMap(const String& textureName);
inline void SetHeightMap(TextureRef textureName);
inline bool SetNormalMap(const String& textureName);
inline void SetNormalMap(TextureRef textureName);
inline void SetRenderStates(const RenderStates& states);
inline void SetShader(UberShaderConstRef uberShader);
inline bool SetShader(const String& uberShaderName);
inline void SetShininess(float shininess);
inline void SetSpecularColor(const Color& specular);
inline bool SetSpecularMap(const String& textureName);
inline void SetSpecularMap(TextureRef specularMap);
inline void SetSpecularSampler(const TextureSampler& sampler);
inline void SetSrcBlend(BlendFunc func);
Material& operator=(const Material& material);
inline Material& operator=(const Material& material);
static MaterialRef GetDefault();
template<typename... Args> static MaterialRef New(Args&&... args);
@@ -158,7 +168,7 @@ namespace Nz
void Copy(const Material& material);
void GenerateShader(UInt32 flags) const;
void InvalidateShaders();
inline void InvalidateShaders();
static bool Initialize();
static void Uninitialize();
@@ -166,6 +176,7 @@ namespace Nz
Color m_ambientColor;
Color m_diffuseColor;
Color m_specularColor;
MaterialRef m_depthMaterial; //< Materialception
RenderStates m_states;
TextureSampler m_diffuseSampler;
TextureSampler m_specularSampler;
@@ -180,6 +191,8 @@ namespace Nz
bool m_alphaTestEnabled;
bool m_depthSortingEnabled;
bool m_lightingEnabled;
bool m_shadowCastingEnabled;
bool m_shadowReceiveEnabled;
bool m_transformEnabled;
float m_alphaThreshold;
float m_shininess;

View File

@@ -7,6 +7,513 @@
namespace Nz
{
inline Material::Material()
{
Reset();
}
inline Material::Material(const Material& material) :
RefCounted(),
Resource(material)
{
Copy(material);
}
inline Material::~Material()
{
OnMaterialRelease(this);
}
inline void Material::Enable(RendererParameter renderParameter, bool enable)
{
NazaraAssert(renderParameter <= RendererParameter_Max, "Renderer parameter out of enum");
m_states.parameters[renderParameter] = enable;
}
inline void Material::EnableAlphaTest(bool alphaTest)
{
m_alphaTestEnabled = alphaTest;
InvalidateShaders();
}
inline void Material::EnableDepthSorting(bool depthSorting)
{
// Has no influence on shaders
m_depthSortingEnabled = depthSorting;
}
inline void Material::EnableLighting(bool lighting)
{
m_lightingEnabled = lighting;
InvalidateShaders();
}
inline void Material::EnableShadowCasting(bool castShadows)
{
// Has no influence on shaders
m_shadowCastingEnabled = castShadows;
}
inline void Material::EnableShadowReceive(bool receiveShadows)
{
m_shadowReceiveEnabled = receiveShadows;
InvalidateShaders();
}
inline void Material::EnableTransform(bool transform)
{
m_transformEnabled = transform;
InvalidateShaders();
}
inline const TextureRef& Material::GetAlphaMap() const
{
return m_alphaMap;
}
inline float Material::GetAlphaThreshold() const
{
return m_alphaThreshold;
}
inline Color Material::GetAmbientColor() const
{
return m_ambientColor;
}
inline RendererComparison Material::GetDepthFunc() const
{
return m_states.depthFunc;
}
inline const MaterialRef& Material::GetDepthMaterial() const
{
return m_depthMaterial;
}
inline Color Material::GetDiffuseColor() const
{
return m_diffuseColor;
}
inline TextureSampler& Material::GetDiffuseSampler()
{
return m_diffuseSampler;
}
inline const TextureSampler& Material::GetDiffuseSampler() const
{
return m_diffuseSampler;
}
const TextureRef& Material::GetDiffuseMap() const
{
return m_diffuseMap;
}
inline BlendFunc Material::GetDstBlend() const
{
return m_states.dstBlend;
}
inline const TextureRef& Material::GetEmissiveMap() const
{
return m_emissiveMap;
}
inline FaceSide Material::GetFaceCulling() const
{
return m_states.faceCulling;
}
inline FaceFilling Material::GetFaceFilling() const
{
return m_states.faceFilling;
}
inline const TextureRef& Material::GetHeightMap() const
{
return m_heightMap;
}
inline const TextureRef& Material::GetNormalMap() const
{
return m_normalMap;
}
inline const RenderStates& Material::GetRenderStates() const
{
return m_states;
}
inline const UberShader* Material::GetShader() const
{
return m_uberShader;
}
inline const UberShaderInstance* Material::GetShaderInstance(UInt32 flags) const
{
const ShaderInstance& instance = m_shaders[flags];
if (!instance.uberInstance)
GenerateShader(flags);
return instance.uberInstance;
}
inline float Material::GetShininess() const
{
return m_shininess;
}
inline Color Material::GetSpecularColor() const
{
return m_specularColor;
}
inline const TextureRef& Material::GetSpecularMap() const
{
return m_specularMap;
}
inline TextureSampler& Material::GetSpecularSampler()
{
return m_specularSampler;
}
inline const TextureSampler& Material::GetSpecularSampler() const
{
return m_specularSampler;
}
inline BlendFunc Material::GetSrcBlend() const
{
return m_states.srcBlend;
}
inline bool Material::HasAlphaMap() const
{
return m_alphaMap.IsValid();
}
inline bool Material::HasDepthMaterial() const
{
return m_depthMaterial.IsValid();
}
inline bool Material::HasDiffuseMap() const
{
return m_diffuseMap.IsValid();
}
inline bool Material::HasEmissiveMap() const
{
return m_emissiveMap.IsValid();
}
inline bool Material::HasHeightMap() const
{
return m_heightMap.IsValid();
}
inline bool Material::HasNormalMap() const
{
return m_normalMap.IsValid();
}
inline bool Material::HasSpecularMap() const
{
return m_specularMap.IsValid();
}
inline bool Material::IsAlphaTestEnabled() const
{
return m_alphaTestEnabled;
}
inline bool Material::IsDepthSortingEnabled() const
{
return m_depthSortingEnabled;
}
inline bool Material::IsEnabled(RendererParameter parameter) const
{
NazaraAssert(parameter <= RendererParameter_Max, "Renderer parameter out of enum");
return m_states.parameters[parameter];
}
inline bool Material::IsLightingEnabled() const
{
return m_lightingEnabled;
}
inline bool Material::IsShadowCastingEnabled() const
{
return m_shadowCastingEnabled;
}
inline bool Material::IsShadowReceiveEnabled() const
{
return m_shadowReceiveEnabled;
}
inline bool Material::IsTransformEnabled() const
{
return m_transformEnabled;
}
inline bool Material::LoadFromFile(const String& filePath, const MaterialParams& params)
{
return MaterialLoader::LoadFromFile(this, filePath, params);
}
inline bool Material::LoadFromMemory(const void* data, std::size_t size, const MaterialParams& params)
{
return MaterialLoader::LoadFromMemory(this, data, size, params);
}
inline bool Material::LoadFromStream(Stream& stream, const MaterialParams& params)
{
return MaterialLoader::LoadFromStream(this, stream, params);
}
inline bool Material::SetAlphaMap(const String& textureName)
{
TextureRef texture = TextureLibrary::Query(textureName);
if (!texture)
{
texture = TextureManager::Get(textureName);
if (!texture)
return false;
}
SetAlphaMap(std::move(texture));
return true;
}
inline void Material::SetAlphaMap(TextureRef alphaMap)
{
m_alphaMap = std::move(alphaMap);
InvalidateShaders();
}
inline void Material::SetAlphaThreshold(float alphaThreshold)
{
m_alphaThreshold = alphaThreshold;
}
inline void Material::SetAmbientColor(const Color& ambient)
{
m_ambientColor = ambient;
}
inline void Material::SetDepthFunc(RendererComparison depthFunc)
{
m_states.depthFunc = depthFunc;
}
inline void Material::SetDepthMaterial(MaterialRef depthMaterial)
{
m_depthMaterial = std::move(depthMaterial);
}
inline void Material::SetDiffuseColor(const Color& diffuse)
{
m_diffuseColor = diffuse;
}
inline bool Material::SetDiffuseMap(const String& textureName)
{
TextureRef texture = TextureLibrary::Query(textureName);
if (!texture)
{
texture = TextureManager::Get(textureName);
if (!texture)
return false;
}
SetDiffuseMap(std::move(texture));
return true;
}
inline void Material::SetDiffuseMap(TextureRef diffuseMap)
{
m_diffuseMap = std::move(diffuseMap);
InvalidateShaders();
}
inline void Material::SetDiffuseSampler(const TextureSampler& sampler)
{
m_diffuseSampler = sampler;
}
inline void Material::SetDstBlend(BlendFunc func)
{
m_states.dstBlend = func;
}
inline bool Material::SetEmissiveMap(const String& textureName)
{
TextureRef texture = TextureLibrary::Query(textureName);
if (!texture)
{
texture = TextureManager::Get(textureName);
if (!texture)
return false;
}
SetEmissiveMap(std::move(texture));
return true;
}
inline void Material::SetEmissiveMap(TextureRef emissiveMap)
{
m_emissiveMap = std::move(emissiveMap);
InvalidateShaders();
}
inline void Material::SetFaceCulling(FaceSide faceSide)
{
m_states.faceCulling = faceSide;
}
inline void Material::SetFaceFilling(FaceFilling filling)
{
m_states.faceFilling = filling;
}
inline bool Material::SetHeightMap(const String& textureName)
{
TextureRef texture = TextureLibrary::Query(textureName);
if (!texture)
{
texture = TextureManager::Get(textureName);
if (!texture)
return false;
}
SetHeightMap(std::move(texture));
return true;
}
inline void Material::SetHeightMap(TextureRef heightMap)
{
m_heightMap = std::move(heightMap);
InvalidateShaders();
}
inline bool Material::SetNormalMap(const String& textureName)
{
TextureRef texture = TextureLibrary::Query(textureName);
if (!texture)
{
texture = TextureManager::Get(textureName);
if (!texture)
return false;
}
SetNormalMap(std::move(texture));
return true;
}
inline void Material::SetNormalMap(TextureRef normalMap)
{
m_normalMap = std::move(normalMap);
InvalidateShaders();
}
inline void Material::SetRenderStates(const RenderStates& states)
{
m_states = states;
}
inline void Material::SetShader(UberShaderConstRef uberShader)
{
m_uberShader = std::move(uberShader);
InvalidateShaders();
}
inline bool Material::SetShader(const String& uberShaderName)
{
UberShaderConstRef uberShader = UberShaderLibrary::Get(uberShaderName);
if (!uberShader)
return false;
SetShader(std::move(uberShader));
return true;
}
inline void Material::SetShininess(float shininess)
{
m_shininess = shininess;
}
inline void Material::SetSpecularColor(const Color& specular)
{
m_specularColor = specular;
}
inline bool Material::SetSpecularMap(const String& textureName)
{
TextureRef texture = TextureLibrary::Query(textureName);
if (!texture)
{
texture = TextureManager::Get(textureName);
if (!texture)
return false;
}
SetSpecularMap(std::move(texture));
return true;
}
inline void Material::SetSpecularMap(TextureRef specularMap)
{
m_specularMap = std::move(specularMap);
InvalidateShaders();
}
inline void Material::SetSpecularSampler(const TextureSampler& sampler)
{
m_specularSampler = sampler;
}
inline void Material::SetSrcBlend(BlendFunc func)
{
m_states.srcBlend = func;
}
inline Material& Material::operator=(const Material& material)
{
Resource::operator=(material);
Copy(material);
return *this;
}
inline MaterialRef Material::GetDefault()
{
return s_defaultMaterial;
}
inline void Material::InvalidateShaders()
{
for (ShaderInstance& instance : m_shaders)
instance.uberInstance = nullptr;
}
template<typename... Args>
MaterialRef Material::New(Args&&... args)
{

View File

@@ -77,7 +77,7 @@ namespace Nz
mutable std::vector<VertexStruct_XY_Color_UV> m_localVertices;
Color m_color;
MaterialRef m_material;
Rectui m_localBounds;
Recti m_localBounds;
mutable bool m_verticesUpdated;
float m_scale;

View File

@@ -132,7 +132,7 @@ namespace Nz
}
/*!
* \brief Returns the distance from the center of the sphere to the point
* \brief Returns the distance from the sphere to the point (is negative when the point is inside the sphere)
* \return Distance to the point
*
* \param X X position of the point
@@ -145,12 +145,11 @@ namespace Nz
template<typename T>
T Sphere<T>::Distance(T X, T Y, T Z) const
{
Vector3<T> distance(X-x, Y-y, Z-z);
return distance.GetLength();
return Distance({X, Y, Z});
}
/*!
* \brief Returns the distance from the center of the sphere to the point
* \brief Returns the distance from the sphere to the point (is negative when the point is inside the sphere)
* \return Distance to the point
*
* \param point Position of the point
@@ -161,7 +160,7 @@ namespace Nz
template<typename T>
T Sphere<T>::Distance(const Vector3<T>& point) const
{
return Distance(point.x, point.y, point.z);
return Vector3f::Distance(point, GetPosition()) - radius;
}
/*!
@@ -305,7 +304,7 @@ namespace Nz
template<typename T>
bool Sphere<T>::Intersect(const Sphere& sphere) const
{
return SquaredDistance(sphere.x, sphere.y, sphere.z) - radius * radius <= sphere.radius * sphere.radius;
return SquaredDistance(sphere.x, sphere.y, sphere.z) <= sphere.radius * sphere.radius;
}
/*!
@@ -460,7 +459,7 @@ namespace Nz
}
/*!
* \brief Returns the squared distance from the center of the sphere to the point
* \brief Returns the squared distance from the sphere to the point (can be negative if the point is inside the sphere)
* \return Squared distance to the point
*
* \param X X position of the point
@@ -469,27 +468,24 @@ namespace Nz
*
* \see Distance
*/
template<typename T>
T Sphere<T>::SquaredDistance(T X, T Y, T Z) const
{
Vector3<T> distance(X - x, Y - y, Z - z);
return distance.GetSquaredLength();
return SquaredDistance({X, Y, Z});
}
/*!
* \brief Returns the squared distance from the center of the sphere to the point
* \brief Returns the squared distance from the sphere to the point (can be negative if the point is inside the sphere)
* \return Squared distance to the point
*
* \param point Position of the point
*
* \see Distance
*/
template<typename T>
T Sphere<T>::SquaredDistance(const Vector3<T>& point) const
{
return SquaredDistance(point.x, point.y, point.z);
return Vector3f::Distance(point, GetPosition()) - radius * radius;
}
/*!

View File

@@ -105,12 +105,15 @@ namespace Nz
static Vector3 Backward();
static Vector3 CrossProduct(const Vector3& vec1, const Vector3& vec2);
static T DotProduct(const Vector3& vec1, const Vector3& vec2);
static T Distance(const Vector3& vec1, const Vector3& vec2);
static float Distancef(const Vector3& vec1, const Vector3& vec2);
static Vector3 Down();
static Vector3 Forward();
static Vector3 Left();
static Vector3 Lerp(const Vector3& from, const Vector3& to, T interpolation);
static Vector3 Normalize(const Vector3& vec);
static Vector3 Right();
static T SquaredDistance(const Vector3& vec1, const Vector3& vec2);
static Vector3 Unit();
static Vector3 UnitX();
static Vector3 UnitY();

View File

@@ -1011,6 +1011,40 @@ namespace Nz
return vector;
}
/*!
* \brief Measure the distance between two points
* Shorthand for vec1.Distance(vec2)
*
* param vec1 the first point
* param vec2 the second point
*
* \return The distance between the two vectors
*
* \see SquaredDistance
*/
template<typename T>
T Vector3<T>::Distance(const Vector3& vec1, const Vector3& vec2)
{
return vec1.Distance(vec2);
}
/*!
* \brief Measure the distance between two points as a float
* Shorthand for vec1.Distancef(vec2)
*
* param vec1 the first point
* param vec2 the second point
*
* \return The distance between the two vectors as a float
*
* \see SquaredDistancef
*/
template<typename T>
float Vector3<T>::Distancef(const Vector3& vec1, const Vector3& vec2)
{
return vec1.Distancef(vec2);
}
/*!
* \brief Shorthand for the vector (0, -1, 0)
* \return A vector with components (0, -1, 0)
@@ -1110,6 +1144,21 @@ namespace Nz
return vector;
}
/*!
* \brief Calculates the squared distance between two vectors
* \return The metric distance between two vectors with the squared euclidean norm
*
* \param vec1 The first point to measure the distance with
* \param vec2 The second point to measure the distance with
*
* \see Distance
*/
template<typename T>
T Vector3<T>::SquaredDistance(const Vector3& vec1, const Vector3& vec2)
{
return vec1.SquaredDistance(vec2);
}
/*!
* \brief Shorthand for the vector (1, 1, 1)
* \return A vector with components (1, 1, 1)

View File

@@ -19,40 +19,6 @@ namespace Nz
AttachmentPoint_Max = AttachmentPoint_Stencil
};
enum BlendFunc
{
BlendFunc_DestAlpha,
BlendFunc_DestColor,
BlendFunc_SrcAlpha,
BlendFunc_SrcColor,
BlendFunc_InvDestAlpha,
BlendFunc_InvDestColor,
BlendFunc_InvSrcAlpha,
BlendFunc_InvSrcColor,
BlendFunc_One,
BlendFunc_Zero,
BlendFunc_Max = BlendFunc_Zero
};
enum FaceFilling
{
FaceFilling_Fill,
FaceFilling_Line,
FaceFilling_Point,
FaceFilling_Max = FaceFilling_Point
};
enum FaceSide
{
FaceSide_Back,
FaceSide_Front,
FaceSide_FrontAndBack,
FaceSide_Max = FaceSide_FrontAndBack
};
enum GpuQueryCondition
{
GpuQueryCondition_Region_NoWait,
@@ -124,59 +90,6 @@ namespace Nz
RendererBuffer_Max = RendererBuffer_Stencil*2-1
};
enum RendererComparison
{
RendererComparison_Always,
RendererComparison_Equal,
RendererComparison_Greater,
RendererComparison_GreaterOrEqual,
RendererComparison_Less,
RendererComparison_LessOrEqual,
RendererComparison_Never,
RendererComparison_NotEqual,
RendererComparison_Max = RendererComparison_NotEqual
};
enum RendererParameter
{
RendererParameter_Blend,
RendererParameter_ColorWrite,
RendererParameter_DepthBuffer,
RendererParameter_DepthWrite,
RendererParameter_FaceCulling,
RendererParameter_ScissorTest,
RendererParameter_StencilTest,
RendererParameter_Max = RendererParameter_StencilTest
};
enum SamplerFilter
{
SamplerFilter_Unknown = -1,
SamplerFilter_Bilinear,
SamplerFilter_Nearest,
SamplerFilter_Trilinear,
SamplerFilter_Default,
SamplerFilter_Max = SamplerFilter_Default
};
enum SamplerWrap
{
SamplerWrap_Unknown = -1,
SamplerWrap_Clamp,
SamplerWrap_MirroredRepeat,
SamplerWrap_Repeat,
SamplerWrap_Default,
SamplerWrap_Max = SamplerWrap_Repeat
};
enum ShaderUniform
{
ShaderUniform_InvProjMatrix,
@@ -205,20 +118,6 @@ namespace Nz
ShaderStageType_Max = ShaderStageType_Vertex
};
enum StencilOperation
{
StencilOperation_Decrement,
StencilOperation_DecrementNoClamp,
StencilOperation_Increment,
StencilOperation_IncrementNoClamp,
StencilOperation_Invert,
StencilOperation_Keep,
StencilOperation_Replace,
StencilOperation_Zero,
StencilOperation_Max = StencilOperation_Zero
};
}
#endif // NAZARA_ENUMS_RENDERER_HPP

View File

@@ -319,6 +319,7 @@ NAZARA_RENDERER_API extern PFNGLUNIFORMMATRIX4DVPROC glUniformMatrix4dv;
NAZARA_RENDERER_API extern PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv;
NAZARA_RENDERER_API extern PFNGLUNMAPBUFFERPROC glUnmapBuffer;
NAZARA_RENDERER_API extern PFNGLUSEPROGRAMPROC glUseProgram;
NAZARA_RENDERER_API extern PFNGLVALIDATEPROGRAMPROC glValidateProgram;
NAZARA_RENDERER_API extern PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f;
NAZARA_RENDERER_API extern PFNGLVERTEXATTRIBDIVISORPROC glVertexAttribDivisor;
NAZARA_RENDERER_API extern PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer;

View File

@@ -7,7 +7,7 @@
#ifndef NAZARA_RENDERSTATES_HPP
#define NAZARA_RENDERSTATES_HPP
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Utility/Enums.hpp>
namespace Nz
{

View File

@@ -98,6 +98,8 @@ namespace Nz
void SendVectorArray(int location, const Vector4f* vectors, unsigned int count) const;
void SendVectorArray(int location, const Vector4i* vectors, unsigned int count) const;
bool Validate() const;
// Fonctions OpenGL
unsigned int GetOpenGLID() const;

View File

@@ -9,7 +9,7 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Utility/Enums.hpp>
namespace Nz
{

View File

@@ -26,7 +26,7 @@ namespace Nz
AbstractTextDrawer() = default;
virtual ~AbstractTextDrawer();
virtual const Rectui& GetBounds() const = 0;
virtual const Recti& GetBounds() const = 0;
virtual Font* GetFont(unsigned int index) const = 0;
virtual unsigned int GetFontCount() const = 0;
virtual const Glyph& GetGlyph(unsigned int index) const = 0;

View File

@@ -17,6 +17,22 @@ namespace Nz
AnimationType_Max = AnimationType_Static
};
enum BlendFunc
{
BlendFunc_DestAlpha,
BlendFunc_DestColor,
BlendFunc_SrcAlpha,
BlendFunc_SrcColor,
BlendFunc_InvDestAlpha,
BlendFunc_InvDestColor,
BlendFunc_InvSrcAlpha,
BlendFunc_InvSrcColor,
BlendFunc_One,
BlendFunc_Zero,
BlendFunc_Max = BlendFunc_Zero
};
enum BufferAccess
{
BufferAccess_DiscardAndWrite,
@@ -87,6 +103,24 @@ namespace Nz
DataStorage_Max = DataStorage_Software*2-1
};
enum FaceFilling
{
FaceFilling_Fill,
FaceFilling_Line,
FaceFilling_Point,
FaceFilling_Max = FaceFilling_Point
};
enum FaceSide
{
FaceSide_Back,
FaceSide_Front,
FaceSide_FrontAndBack,
FaceSide_Max = FaceSide_FrontAndBack
};
enum ImageType
{
ImageType_1D,
@@ -211,6 +245,73 @@ namespace Nz
PrimitiveMode_Max = PrimitiveMode_TriangleFan
};
enum RendererComparison
{
RendererComparison_Always,
RendererComparison_Equal,
RendererComparison_Greater,
RendererComparison_GreaterOrEqual,
RendererComparison_Less,
RendererComparison_LessOrEqual,
RendererComparison_Never,
RendererComparison_NotEqual,
RendererComparison_Max = RendererComparison_NotEqual
};
enum RendererParameter
{
RendererParameter_Blend,
RendererParameter_ColorWrite,
RendererParameter_DepthBuffer,
RendererParameter_DepthWrite,
RendererParameter_FaceCulling,
RendererParameter_ScissorTest,
RendererParameter_StencilTest,
RendererParameter_Max = RendererParameter_StencilTest
};
enum SamplerFilter
{
SamplerFilter_Unknown = -1,
SamplerFilter_Bilinear,
SamplerFilter_Nearest,
SamplerFilter_Trilinear,
SamplerFilter_Default,
SamplerFilter_Max = SamplerFilter_Default
};
enum SamplerWrap
{
SamplerWrap_Unknown = -1,
SamplerWrap_Clamp,
SamplerWrap_MirroredRepeat,
SamplerWrap_Repeat,
SamplerWrap_Default,
SamplerWrap_Max = SamplerWrap_Repeat
};
enum StencilOperation
{
StencilOperation_Decrement,
StencilOperation_DecrementNoClamp,
StencilOperation_Increment,
StencilOperation_IncrementNoClamp,
StencilOperation_Invert,
StencilOperation_Keep,
StencilOperation_Replace,
StencilOperation_Zero,
StencilOperation_Max = StencilOperation_Zero
};
enum TextAlign
{
TextAlign_Left,

View File

@@ -0,0 +1,20 @@
// 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>
namespace Nz
{
template<typename... Args>
ImageRef Image::New(Args&&... args)
{
std::unique_ptr<Image> object(new Image(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -0,0 +1,65 @@
// 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
#pragma once
#ifndef NAZARA_MATERIALDATA_HPP
#define NAZARA_MATERIALDATA_HPP
namespace Nz
{
struct MaterialData
{
static constexpr const char* AlphaTest = "MatAlphaTest";
static constexpr const char* AlphaTexturePath = "MatAlphaTexturePath";
static constexpr const char* AlphaThreshold = "MatAlphaThreshold";
static constexpr const char* AmbientColor = "MatAmbientColor";
static constexpr const char* BackFaceStencilCompare = "MatBackFaceStencilCompare";
static constexpr const char* BackFaceStencilFail = "MatBackFaceStencilFail";
static constexpr const char* BackFaceStencilMask = "MatBackFaceStencilMask";
static constexpr const char* BackFaceStencilPass = "MatBackFaceStencilPass";
static constexpr const char* BackFaceStencilReference = "MatBackFaceStencilReference";
static constexpr const char* BackFaceStencilZFail = "MatBackFaceStencilZFail";
static constexpr const char* Blending = "MatBlending";
static constexpr const char* CustomDefined = "MatCustomDefined";
static constexpr const char* ColorWrite = "MatColorWrite";
static constexpr const char* DepthBuffer = "MatDepthBuffer";
static constexpr const char* DepthFunc = "MatDepthfunc";
static constexpr const char* DepthSorting = "MatDepthSorting";
static constexpr const char* DepthWrite = "MatDepthWrite";
static constexpr const char* DiffuseAnisotropyLevel = "MatDiffuseAnisotropyLevel";
static constexpr const char* DiffuseColor = "MatDiffuseColor";
static constexpr const char* DiffuseFilter = "MatDiffuseFilter";
static constexpr const char* DiffuseTexturePath = "MatDiffuseTexturePath";
static constexpr const char* DiffuseWrap = "MatDiffuseWrap";
static constexpr const char* DstBlend = "MatDstBlend";
static constexpr const char* EmissiveTexturePath = "MatEmissiveTexturePath";
static constexpr const char* FaceCulling = "MatFaceCulling";
static constexpr const char* FaceFilling = "MatFaceFilling";
static constexpr const char* FilePath = "MatFilePath";
static constexpr const char* HeightTexturePath = "MatHeightTexturePath";
static constexpr const char* Lighting = "MatLighting";
static constexpr const char* LineWidth = "MatLineWidth";
static constexpr const char* NormalTexturePath = "MatNormalTexturePath";
static constexpr const char* PointSize = "MatPointSize";
static constexpr const char* ScissorTest = "MatScissorTest";
static constexpr const char* Shininess = "MatShininess";
static constexpr const char* SpecularAnisotropyLevel = "MatSpecularAnisotropyLevel";
static constexpr const char* SpecularColor = "MatSpecularColor";
static constexpr const char* SpecularFilter = "MatSpecularFilter";
static constexpr const char* SpecularTexturePath = "MatSpecularTexturePath";
static constexpr const char* SpecularWrap = "MatSpecularWrap";
static constexpr const char* SrcBlend = "MatSrcBlend";
static constexpr const char* StencilCompare = "MatStencilCompare";
static constexpr const char* StencilFail = "MatStencilFail";
static constexpr const char* StencilMask = "MatStencilMask";
static constexpr const char* StencilPass = "MatStencilPass";
static constexpr const char* StencilReference = "MatStencilReference";
static constexpr const char* StencilTest = "MatStencilTest";
static constexpr const char* StencilZFail = "MatStencilZFail";
static constexpr const char* Transform = "MatTransform";
};
}
#endif // NAZARA_MATERIALDATA_HPP

View File

@@ -93,7 +93,8 @@ namespace Nz
String GetAnimation() const;
AnimationType GetAnimationType() const;
unsigned int GetJointCount() const;
String GetMaterial(unsigned int index) const;
ParameterList& GetMaterialData(unsigned int index);
const ParameterList& GetMaterialData(unsigned int index) const;
unsigned int GetMaterialCount() const;
Skeleton* GetSkeleton();
const Skeleton* GetSkeleton() const;
@@ -124,8 +125,8 @@ namespace Nz
void RemoveSubMesh(unsigned int index);
void SetAnimation(const String& animationPath);
void SetMaterial(unsigned int matIndex, const String& materialPath);
void SetMaterialCount(unsigned int matCount);
void SetMaterialData(unsigned int matIndex, ParameterList data);
void Transform(const Matrix4f& matrix);

View File

@@ -28,7 +28,7 @@ namespace Nz
void Clear();
const Rectui& GetBounds() const override;
const Recti& GetBounds() const override;
unsigned int GetCharacterSize() const;
const Color& GetColor() const;
Font* GetFont() const;
@@ -71,7 +71,7 @@ namespace Nz
Color m_color;
FontRef m_font;
mutable Rectf m_workingBounds;
mutable Rectui m_bounds;
mutable Recti m_bounds;
String m_text;
mutable UInt32 m_previousCharacter;
UInt32 m_style;