Merge branch 'ubo' into vulkan

This commit is contained in:
Lynix
2018-06-12 19:07:58 +02:00
64 changed files with 1041 additions and 430 deletions

View File

@@ -219,17 +219,17 @@ namespace Nz
*/
inline bool Serialize(SerializationContext& context, bool value, TypeTag<bool>)
{
if (context.currentBitPos == 8)
if (context.writeBitPos == 8)
{
context.currentBitPos = 0;
context.currentByte = 0;
context.writeBitPos = 0;
context.writeByte = 0;
}
if (value)
context.currentByte |= 1 << context.currentBitPos;
context.writeByte |= 1 << context.writeBitPos;
if (++context.currentBitPos >= 8)
return Serialize(context, context.currentByte, TypeTag<UInt8>());
if (++context.writeBitPos >= 8)
return Serialize(context, context.writeByte, TypeTag<UInt8>());
else
return true;
}
@@ -291,18 +291,18 @@ namespace Nz
*/
inline bool Unserialize(SerializationContext& context, bool* value, TypeTag<bool>)
{
if (context.currentBitPos == 8)
if (context.readBitPos == 8)
{
if (!Unserialize(context, &context.currentByte, TypeTag<UInt8>()))
if (!Unserialize(context, &context.readByte, TypeTag<UInt8>()))
return false;
context.currentBitPos = 0;
context.readBitPos = 0;
}
if (value)
*value = (context.currentByte & (1 << context.currentBitPos)) != 0;
*value = (context.readByte & (1 << context.readBitPos)) != 0;
context.currentBitPos++;
context.readBitPos++;
return true;
}
@@ -341,7 +341,7 @@ namespace Nz
{
NazaraAssert(value, "Invalid data pointer");
context.ResetBitPosition();
context.ResetReadBitPosition();
if (context.stream->Read(value, sizeof(T)) == sizeof(T))
{

View File

@@ -86,11 +86,11 @@ namespace Nz
if (!m_context.stream)
return true;
if (m_context.currentBitPos != 8)
if (m_context.writeBitPos != 8)
{
m_context.currentBitPos = 8; //< To prevent Serialize to flush bits itself
m_context.writeBitPos = 8; //< To prevent Serialize to flush bits itself
if (!Serialize(m_context, m_context.currentByte))
if (!Serialize(m_context, m_context.writeByte))
return false;
}

View File

@@ -73,12 +73,16 @@ namespace Nz
BitField m_value;
};
template<typename E> constexpr Flags<E> operator&(E lhs, Flags<E> rhs);
template<typename E> constexpr Flags<E> operator|(E lhs, Flags<E> rhs);
template<typename E> constexpr Flags<E> operator^(E lhs, Flags<E> rhs);
// Little hack to have them in both Nz and global scope
namespace FlagsOperators
{
template<typename E> constexpr std::enable_if_t<IsEnumFlag<E>::value, Flags<E>> operator~(E lhs);
template<typename E> constexpr std::enable_if_t<IsEnumFlag<E>::value, Flags<E>> operator|(E lhs, E rhs);
template<typename E> constexpr std::enable_if_t<IsEnumFlag<E>::value, Flags<E>> operator&(E lhs, E rhs);
template<typename E> constexpr std::enable_if_t<IsEnumFlag<E>::value, Flags<E>> operator|(E lhs, E rhs);
template<typename E> constexpr std::enable_if_t<IsEnumFlag<E>::value, Flags<E>> operator^(E lhs, E rhs);
}

View File

@@ -221,6 +221,51 @@ namespace Nz
return 1U << static_cast<BitField>(enumValue);
}
/*!
* \brief Compare flag states
* \return Compared flags
*
* This will returns a copy of the Flags object compared with the enum state.
*
* \param lhs Enum to compare with flags.
* \param rhs Flags object.
*/
template<typename E>
constexpr Flags<E> operator&(E lhs, Flags<E> rhs)
{
return rhs & lhs;
}
/*!
* \brief Combine flag states
* \return Combined flags
*
* This will returns a copy of the Flags object combined with the enum state.
*
* \param lhs Enum to combine with flags.
* \param rhs Flags object.
*/
template<typename E>
constexpr Flags<E> operator|(E lhs, Flags<E> rhs)
{
return rhs | lhs;
}
/*!
* \brief XOR flag states
* \return XORed flags
*
* This will returns a copy of the Flags object XORed with the enum state.
*
* \param lhs Enum to XOR with flags.
* \param rhs Flags object.
*/
template<typename E>
constexpr Flags<E> operator^(E lhs, Flags<E> rhs)
{
return rhs ^ lhs;
}
namespace FlagsOperators
{
@@ -238,21 +283,6 @@ namespace Nz
return ~Flags<E>(lhs);
}
/*!
* \brief Override binary OR operator on enum to turns into a Flags object.
* \return A Flags object with combined enum states.
*
* \param lhs First enumeration value to combine.
* \param rhs Second enumeration value to combine.
*
* Returns a Flags object with combined states from the two enumeration values.
*/
template<typename E>
constexpr std::enable_if_t<IsEnumFlag<E>::value, Flags<E>> operator|(E lhs, E rhs)
{
return Flags<E>(lhs) | rhs;
}
/*!
* \brief Override binary AND operator on enum to turns into a Flags object.
* \return A Flags object with compare enum states.
@@ -269,6 +299,21 @@ namespace Nz
return Flags<E>(lhs) & rhs;
}
/*!
* \brief Override binary OR operator on enum to turns into a Flags object.
* \return A Flags object with combined enum states.
*
* \param lhs First enumeration value to combine.
* \param rhs Second enumeration value to combine.
*
* Returns a Flags object with combined states from the two enumeration values.
*/
template<typename E>
constexpr std::enable_if_t<IsEnumFlag<E>::value, Flags<E>> operator|(E lhs, E rhs)
{
return Flags<E>(lhs) | rhs;
}
/*!
* \brief Override binary XOR operator on enum to turns into a Flags object.
* \return A Flags object with XORed enum states.

View File

@@ -20,11 +20,14 @@ namespace Nz
{
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
UInt8 readBitPos = 8; //< 8 means no bit is currently read
UInt8 readByte; //< Undefined value, will be initialized at the first bit read
UInt8 writeBitPos = 8; //< 8 means no bit is currently wrote
UInt8 writeByte; //< Undefined value, will be initialized at the first bit write
void FlushBits();
inline void ResetBitPosition();
inline void ResetReadBitPosition();
inline void ResetWriteBitPosition();
};
}

View File

@@ -7,16 +7,24 @@
namespace Nz
{
/*!
* \brief Reset the current bit cursor
* \brief Reset the current read bit cursor
*/
inline void SerializationContext::ResetReadBitPosition()
{
readBitPos = 8;
}
/*!
* \brief Reset the current read 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
if you wish to write all bits and reset bit position, call FlushBits
\see FlushBits
\see FlushBits
*/
inline void SerializationContext::ResetBitPosition()
inline void SerializationContext::ResetWriteBitPosition()
{
currentBitPos = 8;
writeBitPos = 8;
}
}

View File

@@ -40,6 +40,11 @@ namespace Nz
virtual float GetZFar() const = 0;
virtual float GetZNear() const = 0;
Nz::Vector3f Project(const Nz::Vector3f& worldPosition) const;
float ProjectDepth(float depth);
Nz::Vector3f Unproject(const Nz::Vector3f& screenPos) const;
AbstractViewer& operator=(const AbstractViewer&) = default;
AbstractViewer& operator=(AbstractViewer&&) noexcept = default;
};

View File

@@ -31,6 +31,8 @@ namespace Nz
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override;
std::unique_ptr<InstancedRenderable> Clone() const override;
inline const Color& GetColor() const;
inline float GetRotation() const;
inline const Vector2f& GetSize() const;

View File

@@ -39,6 +39,8 @@ namespace Nz
virtual void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const = 0;
virtual std::unique_ptr<InstancedRenderable> Clone() const = 0;
virtual bool Cull(const Frustumf& frustum, const InstanceData& instanceData) const;
inline void EnsureBoundingVolumeUpdated() const;
@@ -53,6 +55,8 @@ namespace Nz
virtual void InvalidateData(InstanceData* instanceData, UInt32 flags) const;
inline void SetMaterial(std::size_t matIndex, MaterialRef material);
inline void SetMaterial(std::size_t skinIndex, std::size_t matIndex, MaterialRef material);
inline void SetSkin(std::size_t skinIndex);
inline void SetSkinCount(std::size_t skinCount);
@@ -108,9 +112,6 @@ namespace Nz
inline void ResetMaterials(std::size_t matCount, std::size_t skinCount = 1);
inline void SetMaterial(std::size_t matIndex, MaterialRef material);
inline void SetMaterial(std::size_t skinIndex, std::size_t matIndex, MaterialRef material);
mutable BoundingVolumef m_boundingVolume;
private:

View File

@@ -110,6 +110,51 @@ namespace Nz
return m_skinCount;
}
/*!
* \brief Changes the material used at the specified index by another one
*
* This function changes the active material at the specified index, depending on the current active skin, to the one passed as parameter.
*
* \param matIndex Material index
* \param material New material, cannot be null
*
* \remark If you wish to reset the material to the default one, use the default material (see Material::GetDefault)
*
* \see SetMaterial
*/
inline void InstancedRenderable::SetMaterial(std::size_t matIndex, MaterialRef material)
{
SetMaterial(m_skin, matIndex, std::move(material));
}
/*!
* \brief Changes the material used at the specified index by another one, independently from the active skin.
*
* This function changes the active material at the specified index and for the specified skin index, to the one passed as parameter.
*
* \param skinIndex Skin index
* \param matIndex Material index
* \param material New material, cannot be null
*
* \remark If you wish to reset the material to the default one, use the default material (see Material::GetDefault)
*
* \see SetMaterial
*/
inline void InstancedRenderable::SetMaterial(std::size_t skinIndex, std::size_t matIndex, MaterialRef material)
{
NazaraAssert(skinIndex < m_skinCount, "Skin index out of bounds");
NazaraAssert(matIndex < m_materials.size(), "Material index out of bounds");
NazaraAssert(material.IsValid(), "Material must be valid");
MaterialRef& matEntry = m_materials[m_matCount * skinIndex + matIndex];
if (matEntry != material)
{
OnInstancedRenderableInvalidateMaterial(this, skinIndex, matIndex, material);
matEntry = std::move(material);
}
}
/*!
* \brief Changes the active skin
*
@@ -201,51 +246,6 @@ namespace Nz
m_skin = 0;
}
/*!
* \brief Changes the material used at the specified index by another one
*
* This function changes the active material at the specified index, depending on the current active skin, to the one passed as parameter.
*
* \param matIndex Material index
* \param material New material, cannot be null
*
* \remark If you wish to reset the material to the default one, use the default material (see Material::GetDefault)
*
* \see SetMaterial
*/
inline void InstancedRenderable::SetMaterial(std::size_t matIndex, MaterialRef material)
{
SetMaterial(m_skin, matIndex, std::move(material));
}
/*!
* \brief Changes the material used at the specified index by another one, independently from the active skin.
*
* This function changes the active material at the specified index and for the specified skin index, to the one passed as parameter.
*
* \param skinIndex Skin index
* \param matIndex Material index
* \param material New material, cannot be null
*
* \remark If you wish to reset the material to the default one, use the default material (see Material::GetDefault)
*
* \see SetMaterial
*/
inline void InstancedRenderable::SetMaterial(std::size_t skinIndex, std::size_t matIndex, MaterialRef material)
{
NazaraAssert(skinIndex < m_skinCount, "Skin index out of bounds");
NazaraAssert(matIndex < m_materials.size(), "Material index out of bounds");
NazaraAssert(material.IsValid(), "Material must be valid");
MaterialRef& matEntry = m_materials[m_matCount * skinIndex + matIndex];
if (matEntry != material)
{
OnInstancedRenderableInvalidateMaterial(this, skinIndex, matIndex, material);
matEntry = std::move(material);
}
}
/*!
* \brief Sets the current instanced renderable with the content of the other one
* \return A reference to this

View File

@@ -8,9 +8,11 @@
#define NAZARA_MODEL_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/ObjectLibrary.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/ResourceParameters.hpp>
#include <Nazara/Core/ResourceSaver.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Graphics/InstancedRenderable.hpp>
#include <Nazara/Graphics/Material.hpp>
@@ -32,22 +34,30 @@ namespace Nz
class Model;
using ModelConstRef = ObjectRef<const Model>;
using ModelLibrary = ObjectLibrary<Model>;
using ModelLoader = ResourceLoader<Model, ModelParameters>;
using ModelManager = ResourceManager<Model, ModelParameters>;
using ModelRef = ObjectRef<Model>;
using ModelSaver = ResourceSaver<Model, ModelParameters>;
class NAZARA_GRAPHICS_API Model : public InstancedRenderable, public Resource
{
friend ModelLibrary;
friend ModelLoader;
friend ModelManager;
friend ModelSaver;
public:
inline Model();
Model(const Model& model) = default;
Model(Model&& model) = default;
Model(const Model& model);
Model(Model&& model) = delete;
virtual ~Model();
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override;
inline void AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix, int renderOrder = 0, const Recti& scissorRect = Recti(-1, -1, -1, -1)) const;
std::unique_ptr<InstancedRenderable> Clone() const override;
using InstancedRenderable::GetMaterial;
const MaterialRef& GetMaterial(const String& subMeshName) const;
const MaterialRef& GetMaterial(std::size_t skinIndex, const String& subMeshName) const;
@@ -66,7 +76,7 @@ namespace Nz
virtual void SetMesh(Mesh* mesh);
Model& operator=(const Model& node) = default;
Model& operator=(Model&& node) = default;
Model& operator=(Model&& node) = delete;
template<typename... Args> static ModelRef New(Args&&... args);
@@ -75,7 +85,13 @@ namespace Nz
MeshRef m_mesh;
NazaraSlot(Mesh, OnMeshInvalidateAABB, m_meshAABBInvalidationSlot);
static ModelLibrary::LibraryMap s_library;
static ModelLoader::LoaderList s_loaders;
static ModelManager::ManagerMap s_managerMap;
static ModelManager::ManagerParams s_managerParameters;
static ModelSaver::SaverList s_savers;
};
}

View File

@@ -2,6 +2,7 @@
// 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/Model.hpp>
#include <memory>
#include <Nazara/Graphics/Debug.hpp>
@@ -10,11 +11,22 @@ namespace Nz
/*!
* \brief Constructs a Model object by default
*/
Model::Model()
inline Model::Model()
{
ResetMaterials(0);
}
/*!
* \brief Constructs a Model object by copying another
*
* \param model Model to copy
*/
inline Model::Model(const Model& model) :
InstancedRenderable(model)
{
SetMesh(model.m_mesh);
}
/*!
* \brief Adds this model to a render queue, using user-specified transform matrix and render order
*
@@ -25,8 +37,8 @@ namespace Nz
* \param renderOrder Specify the render queue layer to be used
* \param scissorRect The Scissor rect to uses for rendering
*/
void Model::AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix, int renderOrder, const Recti& scissorRect) const
{
inline void Model::AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix, int renderOrder, const Recti& scissorRect) const
{
InstanceData instanceData(Nz::Matrix4f::Identity());
instanceData.renderOrder = renderOrder;
instanceData.transformMatrix = transformMatrix;

View File

@@ -41,7 +41,7 @@ namespace Nz
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override;
void AdvanceAnimation(float elapsedTime);
SkeletalModel* Clone() const;
std::unique_ptr<InstancedRenderable> Clone() const override;
SkeletalModel* Create() const;
void EnableAnimation(bool animation);

View File

@@ -35,6 +35,8 @@ namespace Nz
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override;
std::unique_ptr<InstancedRenderable> Clone() const override;
inline const Color& GetColor() const;
inline const Color& GetCornerColor(RectCorner corner) const;
inline const Vector3f& GetOrigin() const;

View File

@@ -34,11 +34,14 @@ namespace Nz
inline void Clear();
std::unique_ptr<InstancedRenderable> Clone() const override;
inline const Color& GetColor() const;
inline float GetScale() const;
inline void SetColor(const Color& color);
inline void SetDefaultMaterial();
using InstancedRenderable::SetMaterial;
inline void SetMaterial(MaterialRef material);
inline void SetMaterial(std::size_t skinIndex, MaterialRef material);
inline void SetScale(float scale);

View File

@@ -14,6 +14,7 @@ namespace Nz
inline TextSprite::TextSprite() :
m_color(Color::White),
m_localBounds(Nz::Recti::Zero()),
m_scale(1.f)
{
ResetMaterials(1U);

View File

@@ -35,6 +35,8 @@ namespace Nz
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override;
std::unique_ptr<InstancedRenderable> Clone() const override;
inline void DisableTile(const Vector2ui& tilePos);
inline void DisableTiles();
inline void DisableTiles(const Vector2ui* tilesPos, std::size_t tileCount);

View File

@@ -31,7 +31,7 @@ namespace Nz
private:
LuaCoroutine(lua_State* internalState, int refIndex);
bool Run(int argCount, int resultCount) override;
bool Run(int argCount, int resultCount, int errHandler) override;
int m_ref;
};

View File

@@ -43,6 +43,8 @@ namespace Nz
bool Call(unsigned int argCount);
bool Call(unsigned int argCount, unsigned int resultCount);
bool CallWithHandler(unsigned int argCount, int errorHandler);
bool CallWithHandler(unsigned int argCount, unsigned int resultCount, int errorHandler);
template<typename T> T Check(int* index) const;
template<typename T> T Check(int* index, T defValue) const;
@@ -84,10 +86,10 @@ namespace Nz
void Error(const char* message) const;
void Error(const String& message) const;
bool Execute(const String& code);
bool ExecuteFromFile(const String& filePath);
bool ExecuteFromMemory(const void* data, std::size_t size);
bool ExecuteFromStream(Stream& stream);
bool Execute(const String& code, int errorHandler = 0);
bool ExecuteFromFile(const String& filePath, int errorHandler = 0);
bool ExecuteFromMemory(const void* data, std::size_t size, int errorHandler = 0);
bool ExecuteFromStream(Stream& stream, int errorHandler = 0);
int GetAbsIndex(int index) const;
LuaType GetField(const char* fieldName, int tableIndex = -1) const;
@@ -112,6 +114,11 @@ namespace Nz
bool IsOfType(int index, const String& tname) const;
bool IsValid(int index) const;
bool Load(const String& code);
bool LoadFromFile(const String& filePath);
bool LoadFromMemory(const void* data, std::size_t size);
bool LoadFromStream(Stream& stream);
long long Length(int index) const;
std::size_t LengthRaw(int index) const;
@@ -134,7 +141,6 @@ namespace Nz
template<typename R, typename... Args, typename... DefArgs> void PushFunction(R(*func)(Args...), DefArgs&&... defArgs) const;
template<typename T> void PushGlobal(const char* name, T&& arg);
template<typename T> void PushGlobal(const String& name, T&& arg);
template<typename T> void PushInstance(const char* tname, const T& instance) const;
template<typename T> void PushInstance(const char* tname, T&& instance) const;
template<typename T, typename... Args> void PushInstance(const char* tname, Args&&... args) const;
void PushInteger(long long value) const;
@@ -173,6 +179,8 @@ namespace Nz
void* ToUserdata(int index, const char* tname) const;
void* ToUserdata(int index, const String& tname) const;
void Traceback(const char* message = nullptr, int level = 0);
LuaState& operator=(const LuaState&) = default;
LuaState& operator=(LuaState&& instance) = default;
@@ -185,7 +193,7 @@ namespace Nz
template<typename T> std::enable_if_t<std::is_signed<T>::value, T> CheckBounds(int index, long long value) const;
template<typename T> std::enable_if_t<std::is_unsigned<T>::value, T> CheckBounds(int index, long long value) const;
virtual bool Run(int argCount, int resultCount);
virtual bool Run(int argCount, int resultCount, int errHandler);
static int ProxyFunc(lua_State* internalState);

View File

@@ -706,7 +706,7 @@ namespace Nz
template<typename T>
void LuaState::PushField(const char* name, T&& arg, int tableIndex) const
{
Push<T>(std::forward<T>(arg));
Push(std::forward<T>(arg));
SetField(name, tableIndex);
}
@@ -732,7 +732,7 @@ namespace Nz
template<typename T>
void LuaState::PushGlobal(const char* name, T&& arg)
{
Push<T>(std::forward<T>(arg));
Push(std::forward<T>(arg));
SetGlobal(name);
}
@@ -742,15 +742,6 @@ namespace Nz
PushGlobal(name.GetConstBuffer(), std::forward<T>(arg));
}
template<typename T>
void LuaState::PushInstance(const char* tname, const T& instance) const
{
T* userdata = static_cast<T*>(PushUserdata(sizeof(T)));
PlacementNew(userdata, instance);
SetMetatable(tname);
}
template<typename T>
void LuaState::PushInstance(const char* tname, T&& instance) const
{

View File

@@ -47,6 +47,7 @@ namespace Nz
void DisconnectNow(UInt32 data);
inline const IpAddress& GetAddress() const;
inline UInt32 GetLastReceiveTime() const;
inline UInt32 GetMtu() const;
inline UInt32 GetPacketThrottleAcceleration() const;
inline UInt32 GetPacketThrottleDeceleration() const;

View File

@@ -22,6 +22,11 @@ namespace Nz
return m_address;
}
inline UInt32 ENetPeer::GetLastReceiveTime() const
{
return m_lastReceiveTime;
}
inline UInt32 ENetPeer::GetMtu() const
{
return m_mtu;

View File

@@ -123,8 +123,8 @@ namespace Nz
float fraction;
};
NazaraSignal(OnPhysWorld2DPreStep, const PhysWorld2D* /*physWorld*/);
NazaraSignal(OnPhysWorld2DPostStep, const PhysWorld2D* /*physWorld*/);
NazaraSignal(OnPhysWorld2DPreStep, const PhysWorld2D* /*physWorld*/, float /*invStepCount*/);
NazaraSignal(OnPhysWorld2DPostStep, const PhysWorld2D* /*physWorld*/, float /*invStepCount*/);
private:
void InitCallbacks(cpCollisionHandler* handler, const Callback& callbacks);

View File

@@ -36,7 +36,7 @@ namespace Nz
static void DrawCone(const Vector3f& origin, const Quaternionf& rotation, float angle, float length);
static void DrawLine(const Vector3f& p1, const Vector3f& p2);
static void DrawPoints(const Vector3f* ptr, unsigned int pointCount);
static void DrawNormals(const StaticMesh* subMesh);
static void DrawNormals(const StaticMesh* subMesh, float normalLength = 0.01f);
static void DrawTangents(const StaticMesh* subMesh);
static void EnableDepthBuffer(bool depthBuffer);

View File

@@ -15,8 +15,23 @@
namespace Nz
{
<<<<<<< HEAD
class AbstractBuffer;
class Buffer;
=======
class Color;
class Context;
class GpuQuery;
class IndexBuffer;
class RenderTarget;
struct RenderStates;
class Shader;
class Texture;
class TextureSampler;
class UniformBuffer;
class VertexBuffer;
class VertexDeclaration;
>>>>>>> ubo
class NAZARA_RENDERER_API Renderer
{
@@ -24,7 +39,46 @@ namespace Nz
Renderer() = delete;
~Renderer() = delete;
<<<<<<< HEAD
static inline RendererImpl* GetRendererImpl();
=======
static void BeginCondition(const GpuQuery& query, GpuQueryCondition condition);
static void BindUniformBuffer(unsigned int bindingPoint, const UniformBuffer* uniformBuffer);
static void Clear(UInt32 flags = RendererBuffer_Color | RendererBuffer_Depth);
static void DrawFullscreenQuad();
static void DrawIndexedPrimitives(PrimitiveMode mode, unsigned int firstIndex, unsigned int indexCount);
static void DrawIndexedPrimitivesInstanced(unsigned int instanceCount, PrimitiveMode mode, unsigned int firstIndex, unsigned int indexCount);
static void DrawPrimitives(PrimitiveMode mode, unsigned int firstVertex, unsigned int vertexCount);
static void DrawPrimitivesInstanced(unsigned int instanceCount, PrimitiveMode mode, unsigned int firstVertex, unsigned int vertexCount);
static void Enable(RendererParameter parameter, bool enable);
static void EndCondition();
static void Flush();
static RendererComparison GetDepthFunc();
static VertexBuffer* GetInstanceBuffer();
static float GetLineWidth();
static Matrix4f GetMatrix(MatrixType type);
static UInt8 GetMaxAnisotropyLevel();
static unsigned int GetMaxColorAttachments();
static unsigned int GetMaxRenderTargets();
static unsigned int GetMaxTextureSize();
static unsigned int GetMaxTextureUnits();
static unsigned int GetMaxVertexAttribs();
static float GetPointSize();
static const RenderStates& GetRenderStates();
static Recti GetScissorRect();
static const Shader* GetShader();
static const RenderTarget* GetTarget();
static Recti GetViewport();
static bool HasCapability(RendererCap capability);
>>>>>>> ubo
static bool Initialize();

View File

@@ -49,8 +49,9 @@ namespace Nz
{
BufferType_Index,
BufferType_Vertex,
BufferType_Uniform,
BufferType_Max = BufferType_Vertex
BufferType_Max = BufferType_Uniform
};
enum BufferUsage

View File

@@ -38,7 +38,6 @@ namespace Nz
inline const BufferRef& GetBuffer() const;
inline UInt32 GetEndOffset() const;
inline UInt32 GetIndexCount() const;
inline DataStorage GetStorage() const;
inline UInt32 GetStride() const;
inline UInt32 GetStartOffset() const;

View File

@@ -22,11 +22,6 @@ namespace Nz
return m_indexCount;
}
inline DataStorage IndexBuffer::GetStorage() const
{
return DataStorage();
}
inline UInt32 IndexBuffer::GetStride() const
{
return static_cast<UInt32>((m_largeIndices) ? sizeof(UInt32) : sizeof(UInt16));

View File

@@ -20,8 +20,12 @@
#include <Nazara/Math/Box.hpp>
#include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Skeleton.hpp>
#include <Nazara/Utility/SubMesh.hpp>
#include <Nazara/Utility/VertexDeclaration.hpp>
#include <Nazara/Utility/VertexStruct.hpp>
#include <unordered_map>
#include <vector>
namespace Nz
{
@@ -56,7 +60,6 @@ namespace Nz
class Mesh;
struct Primitive;
class PrimitiveList;
class Skeleton;
class SubMesh;
using MeshVertex = VertexStruct_XYZ_Normal_UV_Tangent;
@@ -80,8 +83,10 @@ namespace Nz
friend class Utility;
public:
Mesh() = default;
~Mesh();
inline Mesh();
Mesh(const Mesh&) = delete;
Mesh(Mesh&&) = delete;
inline ~Mesh();
void AddSubMesh(SubMesh* subMesh);
void AddSubMesh(const String& identifier, SubMesh* subMesh);
@@ -141,14 +146,34 @@ namespace Nz
void Transform(const Matrix4f& matrix);
Mesh& operator=(const Mesh&) = delete;
Mesh& operator=(Mesh&&) = delete;
template<typename... Args> static MeshRef New(Args&&... args);
// Signals:
NazaraSignal(OnMeshDestroy, const Mesh* /*mesh*/);
NazaraSignal(OnMeshInvalidateAABB, const Mesh* /*mesh*/);
NazaraSignal(OnMeshRelease, const Mesh* /*mesh*/);
private:
MeshImpl* m_impl = nullptr;
struct SubMeshData
{
SubMeshRef subMesh;
NazaraSlot(SubMesh, OnSubMeshInvalidateAABB, onSubMeshInvalidated);
};
std::unordered_map<String, UInt32> m_subMeshMap;
std::vector<ParameterList> m_materialData;
std::vector<SubMeshData> m_subMeshes;
AnimationType m_animationType;
mutable Boxf m_aabb;
Skeleton m_skeleton; // Only used by skeletal meshes
String m_animationPath;
mutable bool m_aabbUpdated;
bool m_isValid;
UInt32 m_jointCount; // Only used by skeletal meshes
static bool Initialize();
static void Uninitialize();

View File

@@ -2,11 +2,25 @@
// 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/Mesh.hpp>
#include <memory>
#include <Nazara/Utility/Debug.hpp>
namespace Nz
{
Mesh::Mesh() :
m_materialData(1),
m_aabbUpdated(false)
{
}
Mesh::~Mesh()
{
OnMeshRelease(this);
Destroy();
}
template<typename... Args>
MeshRef Mesh::New(Args&&... args)
{

View File

@@ -24,9 +24,14 @@ namespace Nz
class NAZARA_UTILITY_API SkeletalMesh final : public SubMesh
{
public:
SkeletalMesh(VertexBuffer* vertexBuffer, const IndexBuffer* indexBuffer);
NAZARA_DEPRECATED("SkeletalMesh constructor taking a mesh is deprecated, submeshes no longer require to be part of a single mesh")
SkeletalMesh(const Mesh* parent);
~SkeletalMesh();
NAZARA_DEPRECATED("SkeletalMesh create/destroy functions are deprecated, please use constructor")
bool Create(VertexBuffer* vertexBuffer);
void Destroy();
@@ -51,8 +56,8 @@ namespace Nz
private:
Boxf m_aabb;
IndexBufferConstRef m_indexBuffer = nullptr;
VertexBufferRef m_vertexBuffer = nullptr;
IndexBufferConstRef m_indexBuffer;
VertexBufferRef m_vertexBuffer;
};
}

View File

@@ -21,11 +21,16 @@ namespace Nz
class NAZARA_UTILITY_API StaticMesh final : public SubMesh
{
public:
StaticMesh(VertexBuffer* vertexBuffer, const IndexBuffer* indexBuffer);
NAZARA_DEPRECATED("StaticMesh constructor taking a mesh is deprecated, submeshes no longer require to be part of a single mesh")
StaticMesh(const Mesh* parent);
~StaticMesh();
void Center();
NAZARA_DEPRECATED("StaticMesh create/destroy functions are deprecated, please use constructor")
bool Create(VertexBuffer* vertexBuffer);
void Destroy();
@@ -52,8 +57,8 @@ namespace Nz
private:
Boxf m_aabb;
IndexBufferConstRef m_indexBuffer = nullptr;
VertexBufferRef m_vertexBuffer = nullptr;
IndexBufferConstRef m_indexBuffer;
VertexBufferRef m_vertexBuffer;
};
}

View File

@@ -28,7 +28,13 @@ namespace Nz
friend Mesh;
public:
SubMesh();
NAZARA_DEPRECATED("Submesh constructor taking a mesh is deprecated, submeshes no longer require to be part of a single mesh")
SubMesh(const Mesh* parent);
SubMesh(const SubMesh&) = delete;
SubMesh(SubMesh&&) = delete;
virtual ~SubMesh();
void GenerateNormals();
@@ -39,7 +45,6 @@ namespace Nz
virtual AnimationType GetAnimationType() const = 0;
virtual const IndexBuffer* GetIndexBuffer() const = 0;
UInt32 GetMaterialIndex() const;
const Mesh* GetParent() const;
PrimitiveMode GetPrimitiveMode() const;
UInt32 GetTriangleCount() const;
virtual UInt32 GetVertexCount() const = 0;
@@ -49,12 +54,15 @@ namespace Nz
void SetMaterialIndex(UInt32 matIndex);
void SetPrimitiveMode(PrimitiveMode mode);
SubMesh& operator=(const SubMesh&) = delete;
SubMesh& operator=(SubMesh&&) = delete;
// Signals:
NazaraSignal(OnSubMeshInvalidateAABB, const SubMesh* /*subMesh*/);
NazaraSignal(OnSubMeshRelease, const SubMesh* /*subMesh*/);
protected:
PrimitiveMode m_primitiveMode;
const Mesh* m_parent;
UInt32 m_matIndex;
};
}

View File

@@ -0,0 +1,69 @@
// Copyright (C) 2017 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_UNIFORMBUFFER_HPP
#define NAZARA_UNIFORMBUFFER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Utility/Buffer.hpp>
namespace Nz
{
class UniformBuffer;
using UniformBufferConstRef = ObjectRef<const UniformBuffer>;
using UniformBufferRef = ObjectRef<UniformBuffer>;
class NAZARA_UTILITY_API UniformBuffer : public RefCounted
{
public:
UniformBuffer() = default;
UniformBuffer(BufferRef buffer);
UniformBuffer(BufferRef buffer, UInt32 offset, UInt32 size);
UniformBuffer(UInt32 length, DataStorage storage, BufferUsageFlags usage);
UniformBuffer(const UniformBuffer& uniformBuffer);
UniformBuffer(UniformBuffer&&) = delete;
~UniformBuffer();
bool Fill(const void* data, UInt32 offset, UInt32 size);
inline const BufferRef& GetBuffer() const;
inline UInt32 GetEndOffset() const;
inline UInt32 GetStartOffset() const;
inline bool IsValid() const;
void* Map(BufferAccess access, UInt32 offset = 0, UInt32 size = 0);
void* Map(BufferAccess access, UInt32 offset = 0, UInt32 size = 0) const;
void Reset();
void Reset(BufferRef buffer);
void Reset(BufferRef buffer, UInt32 offset, UInt32 size);
void Reset(UInt32 size, DataStorage storage, BufferUsageFlags usage);
void Reset(const UniformBuffer& uniformBuffer);
void Unmap() const;
UniformBuffer& operator=(const UniformBuffer& uniformBuffer);
UniformBuffer& operator=(UniformBuffer&&) = delete;
template<typename... Args> static UniformBufferRef New(Args&&... args);
// Signals:
NazaraSignal(OnUniformBufferRelease, const UniformBuffer* /*UniformBuffer*/);
private:
BufferRef m_buffer;
UInt32 m_endOffset;
UInt32 m_startOffset;
};
}
#include <Nazara/Utility/UniformBuffer.inl>
#endif // NAZARA_UNIFORMBUFFER_HPP

View File

@@ -0,0 +1,41 @@
// Copyright (C) 2017 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 <Nazara/Utility/UniformBuffer.hpp>
#include <memory>
#include <Nazara/Utility/Debug.hpp>
namespace Nz
{
inline const BufferRef& UniformBuffer::GetBuffer() const
{
return m_buffer;
}
inline UInt32 UniformBuffer::GetEndOffset() const
{
return m_endOffset;
}
inline UInt32 UniformBuffer::GetStartOffset() const
{
return m_startOffset;
}
inline bool UniformBuffer::IsValid() const
{
return m_buffer.IsValid();
}
template<typename... Args>
UniformBufferRef UniformBuffer::New(Args&&... args)
{
std::unique_ptr<UniformBuffer> object(new UniformBuffer(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
}
#include <Nazara/Utility/DebugOff.hpp>