Merge branch 'NDK' into NDK-ShadowMapping

Former-commit-id: b07de3853987ffc91946b307208c0ec26eda280a
This commit is contained in:
Lynix 2015-08-17 14:26:42 +02:00
commit 2b48917176
17 changed files with 280 additions and 21 deletions

View File

@ -34,20 +34,20 @@ namespace Ndk
EntityHandle CreateHandle();
BaseComponent& GetComponent(ComponentIndex index);
inline BaseComponent& GetComponent(ComponentIndex index);
template<typename ComponentType> ComponentType& GetComponent();
const NzBitset<>& GetComponentBits() const;
EntityId GetId() const;
const NzBitset<>& GetSystemBits() const;
World* GetWorld() const;
inline const NzBitset<>& GetComponentBits() const;
inline EntityId GetId() const;
inline const NzBitset<>& GetSystemBits() const;
inline World* GetWorld() const;
bool HasComponent(ComponentIndex index) const;
inline bool HasComponent(ComponentIndex index) const;
template<typename ComponentType> bool HasComponent() const;
void Kill();
void Invalidate();
bool IsValid() const;
inline bool IsValid() const;
void RemoveAllComponents();
void RemoveComponent(ComponentIndex index);
@ -62,10 +62,10 @@ namespace Ndk
void Create();
void Destroy();
void RegisterHandle(EntityHandle* handle);
void RegisterSystem(SystemIndex index);
void UnregisterHandle(EntityHandle* handle);
void UnregisterSystem(SystemIndex index);
inline void RegisterHandle(EntityHandle* handle);
inline void RegisterSystem(SystemIndex index);
inline void UnregisterHandle(EntityHandle* handle);
inline void UnregisterSystem(SystemIndex index);
std::vector<std::unique_ptr<BaseComponent>> m_components;
std::vector<EntityHandle*> m_handles;

View File

@ -0,0 +1,62 @@
// 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_BILLBOARD_HPP
#define NAZARA_BILLBOARD_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/InstancedRenderable.hpp>
#include <Nazara/Graphics/Material.hpp>
class NzBillboard;
using NzBillboardConstRef = NzObjectRef<const NzBillboard>;
using NzBillboardLibrary = NzObjectLibrary<NzBillboard>;
using NzBillboardRef = NzObjectRef<NzBillboard>;
class NAZARA_GRAPHICS_API NzBillboard : public NzInstancedRenderable
{
public:
inline NzBillboard();
inline NzBillboard(NzMaterialRef material);
inline NzBillboard(NzTexture* texture);
inline NzBillboard(const NzBillboard& billboard);
~NzBillboard() = default;
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
inline const NzColor& GetColor() const;
inline const NzMaterialRef& GetMaterial() const;
inline float GetRotation() const;
inline const NzVector2f& GetSize() const;
inline void SetColor(const NzColor& color);
inline void SetDefaultMaterial();
inline void SetMaterial(NzMaterialRef material, bool resizeBillboard = true);
inline void SetRotation(float rotation);
inline void SetSize(const NzVector2f& size);
inline void SetSize(float sizeX, float sizeY);
inline void SetTexture(NzTextureRef texture, bool resizeBillboard = true);
inline NzBillboard& operator=(const NzBillboard& billboard);
template<typename... Args> static NzBillboardRef New(Args&&... args);
private:
void MakeBoundingVolume() const override;
NzColor m_color;
NzMaterialRef m_material;
NzVector2f m_sinCos;
NzVector2f m_size;
float m_rotation;
static NzBillboardLibrary::LibraryMap s_library;
};
#include <Nazara/Graphics/Billboard.inl>
#endif // NAZARA_BILLBOARD_HPP

View File

@ -0,0 +1,141 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Graphics/Debug.hpp>
inline NzBillboard::NzBillboard()
{
SetColor(NzColor::White);
SetDefaultMaterial();
SetRotation(0.f);
SetSize(64.f, 64.f);
}
inline NzBillboard::NzBillboard(NzMaterialRef material)
{
SetColor(NzColor::White);
SetMaterial(std::move(material), true);
SetRotation(0.f);
SetSize(64.f, 64.f);
}
inline NzBillboard::NzBillboard(NzTexture* texture)
{
SetColor(NzColor::White);
SetRotation(0.f);
SetSize(64.f, 64.f);
SetTexture(texture, true);
}
inline NzBillboard::NzBillboard(const NzBillboard& billboard) :
NzInstancedRenderable(billboard),
m_color(billboard.m_color),
m_material(billboard.m_material),
m_rotation(billboard.m_rotation),
m_sinCos(billboard.m_sinCos),
m_size(billboard.m_size)
{
}
inline const NzColor& NzBillboard::GetColor() const
{
return m_color;
}
inline const NzMaterialRef& NzBillboard::GetMaterial() const
{
return m_material;
}
inline float NzBillboard::GetRotation() const
{
return m_rotation;
}
inline const NzVector2f& NzBillboard::GetSize() const
{
return m_size;
}
inline void NzBillboard::SetColor(const NzColor& color)
{
m_color = color;
}
inline void NzBillboard::SetDefaultMaterial()
{
NzMaterialRef material = NzMaterial::New();
material->Enable(nzRendererParameter_FaceCulling, true);
material->EnableLighting(false);
SetMaterial(std::move(material));
}
inline void NzBillboard::SetMaterial(NzMaterialRef material, bool resizeBillboard)
{
m_material = std::move(material);
if (m_material && resizeBillboard)
{
NzTexture* diffuseMap = m_material->GetDiffuseMap();
if (diffuseMap && diffuseMap->IsValid())
SetSize(NzVector2f(NzVector2ui(diffuseMap->GetSize())));
}
}
inline void NzBillboard::SetRotation(float rotation)
{
m_rotation = rotation;
m_sinCos.Set(std::sin(m_rotation), std::cos(m_rotation));
}
inline void NzBillboard::SetSize(const NzVector2f& size)
{
m_size = size;
// On invalide la bounding box
InvalidateBoundingVolume();
}
inline void NzBillboard::SetSize(float sizeX, float sizeY)
{
SetSize(NzVector2f(sizeX, sizeY));
}
inline void NzBillboard::SetTexture(NzTextureRef texture, bool resizeBillboard)
{
if (!m_material)
SetDefaultMaterial();
else if (m_material->GetReferenceCount() > 1)
m_material = NzMaterial::New(*m_material); // Copie
if (resizeBillboard && texture && texture->IsValid())
SetSize(NzVector2f(NzVector2ui(texture->GetSize())));
m_material->SetDiffuseMap(std::move(texture));
}
inline NzBillboard& NzBillboard::operator=(const NzBillboard& billboard)
{
NzInstancedRenderable::operator=(billboard);
m_color = billboard.m_color;
m_material = billboard.m_material;
m_size = billboard.m_size;
InvalidateBoundingVolume();
return *this;
}
template<typename... Args>
NzBillboardRef NzBillboard::New(Args&&... args)
{
std::unique_ptr<NzBillboard> object(new NzBillboard(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Graphics/DebugOff.hpp>

View File

@ -10,8 +10,8 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Graphics/Material.hpp>
#include <Nazara/Graphics/InstancedRenderable.hpp>
#include <Nazara/Graphics/Material.hpp>
#include <Nazara/Utility/Mesh.hpp>
struct NAZARA_GRAPHICS_API NzModelParameters
@ -34,7 +34,6 @@ using NzModelRef = NzObjectRef<NzModel>;
class NAZARA_GRAPHICS_API NzModel : public NzInstancedRenderable, public NzResource
{
friend NzModelLoader;
friend class NzScene;
public:
NzModel();

View File

@ -72,7 +72,7 @@ inline void NzSprite::SetDefaultMaterial()
material->Enable(nzRendererParameter_FaceCulling, false);
material->EnableLighting(false);
SetMaterial(material);
SetMaterial(std::move(material));
}
inline void NzSprite::SetMaterial(NzMaterialRef material, bool resizeSprite)

View File

@ -113,7 +113,7 @@ class NAZARA_UTILITY_API NzFont : public NzRefCounted, public NzResource, NzNonC
};
NazaraSignal(OnFontAtlasChanged, const NzFont*); //< Args: me
NazaraSignal(OnFontAtlasLayerChanged, const NzFont*); //< Args: me
NazaraSignal(OnFontAtlasLayerChanged, const NzFont*, NzAbstractImage*, NzAbstractImage*); //< Args: me, old layer, new layer
NazaraSignal(OnFontDestroy, const NzFont*); //< Args: me
NazaraSignal(OnFontGlyphCacheCleared, const NzFont*); //< Args: me
NazaraSignal(OnFontKerningCacheCleared, const NzFont*); //< Args: me

View File

@ -43,6 +43,7 @@ class NAZARA_UTILITY_API NzSimpleTextDrawer : public NzAbstractTextDrawer
static NzSimpleTextDrawer Draw(NzFont* font, const NzString& str, unsigned int characterSize, nzUInt32 style = nzTextStyle_Regular, const NzColor& color = NzColor::White);
private:
void OnFontAtlasLayerChanged(const NzFont* font, NzAbstractImage* oldLayer, NzAbstractImage* newLayer);
void OnFontInvalidated(const NzFont* font);
void OnFontRelease(const NzFont* object);
void UpdateGlyphs() const;

View File

@ -0,0 +1,28 @@
// 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/Billboard.hpp>
#include <Nazara/Graphics/AbstractRenderQueue.hpp>
#include <Nazara/Graphics/AbstractViewer.hpp>
#include <Nazara/Math/Algorithm.hpp>
#include <cstring>
#include <memory>
#include <Nazara/Graphics/Debug.hpp>
void NzBillboard::AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const InstanceData& instanceData) const
{
if (!m_material)
return;
renderQueue->AddBillboard(m_material, instanceData.transformMatrix.GetTranslation(), m_size, m_sinCos, m_color);
}
void NzBillboard::MakeBoundingVolume() const
{
constexpr float sqrt2 = float(M_SQRT2);
m_boundingVolume.Set(NzVector3f(0.f), sqrt2*m_size.x*NzVector3f::Right() + sqrt2*m_size.y*NzVector3f::Down());
}
NzBillboardLibrary::LibraryMap NzBillboard::s_library;

View File

@ -388,6 +388,9 @@ void NzForwardRenderTechnique::DrawBillboards(const NzSceneData& sceneData) cons
// Les uniformes sont conservées au sein d'un programme, inutile de les renvoyer tant qu'il ne change pas
if (shader != lastShader)
{
// Index des uniformes dans le shader
shaderUniforms = GetShaderUniforms(shader);
// Couleur ambiante de la scène
shader->SendColor(shaderUniforms->sceneAmbient, sceneData.ambientColor);
// Position de la caméra

View File

@ -69,6 +69,7 @@ void main()
gl_Position = ViewProjMatrix * vec4(vertexPos, 1.0);
texCoords = VertexTexCoord;
#endif
texCoords.y = 1.0 - texCoords.y;
#else
#if FLAG_INSTANCING
#if TRANSFORM

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -78,6 +78,7 @@ void main()
gl_Position = ViewProjMatrix * vec4(vertexPos, 1.0);
texCoords = VertexTexCoord;
#endif
texCoords.y = 1.0 - texCoords.y;
#else
#if FLAG_INSTANCING
#if TRANSFORM

File diff suppressed because one or more lines are too long

View File

@ -48,3 +48,5 @@ void NzSprite::UpdateData(InstanceData* instanceData) const
*posPtr++ = instanceData->transformMatrix.Transform(m_size.x*NzVector3f::Right() + m_size.y*NzVector3f::Down());
*texCoordPtr++ = m_textureCoords.GetCorner(nzRectCorner_RightBottom);
}
NzSpriteLibrary::LibraryMap NzSprite::s_library;

View File

@ -454,7 +454,7 @@ void NzFont::OnAtlasLayerChange(const NzAbstractAtlas* atlas, NzAbstractImage* o
#endif
// Pour faciliter le travail des ressources qui nous écoutent
OnFontAtlasLayerChanged(this);
OnFontAtlasLayerChanged(this, oldLayer, newLayer);
}
void NzFont::OnAtlasRelease(const NzAbstractAtlas* atlas)

View File

@ -115,9 +115,9 @@ void NzSimpleTextDrawer::SetFont(NzFont* font)
if (m_font)
{
m_atlasChangedSlot.Connect(m_font->OnFontAtlasChanged, this, &NzSimpleTextDrawer::OnFontInvalidated);
m_atlasLayerChangedSlot.Connect(m_font->OnFontAtlasLayerChanged, this, &NzSimpleTextDrawer::OnFontInvalidated);
m_atlasLayerChangedSlot.Connect(m_font->OnFontAtlasLayerChanged, this, &NzSimpleTextDrawer::OnFontAtlasLayerChanged);
m_fontReleaseSlot.Connect(m_font->OnFontRelease, this, &NzSimpleTextDrawer::OnFontRelease);
m_glyphCacheClearedSlot.Connect(m_font->OnFontAtlasChanged, this, &NzSimpleTextDrawer::OnFontInvalidated);
m_glyphCacheClearedSlot.Connect(m_font->OnFontGlyphCacheCleared, this, &NzSimpleTextDrawer::OnFontInvalidated);
}
else
{
@ -168,6 +168,27 @@ NzSimpleTextDrawer NzSimpleTextDrawer::Draw(NzFont* font, const NzString& str, u
return drawer;
}
void NzSimpleTextDrawer::OnFontAtlasLayerChanged(const NzFont* font, NzAbstractImage* oldLayer, NzAbstractImage* newLayer)
{
NazaraUnused(font);
#ifdef NAZARA_DEBUG
if (m_font != font)
{
NazaraInternalError("Not listening to " + NzString::Pointer(font));
return;
}
#endif
// Update atlas layer pointer
// Note: This can happend while updating
for (Glyph& glyph : m_glyphs)
{
if (glyph.atlas == oldLayer)
glyph.atlas = newLayer;
}
}
void NzSimpleTextDrawer::OnFontInvalidated(const NzFont* font)
{
NazaraUnused(font);