Merge remote-tracking branch 'origin/NDK' into NDK-ShadowMapping
Conflicts: SDK/include/NDK/Systems/RenderSystem.hpp SDK/src/NDK/Systems/RenderSystem.cpp Former-commit-id: 0a72e838de272bff91f0b8c8a3637db94fdd7820
This commit is contained in:
commit
ea3fdaba26
|
|
@ -33,10 +33,15 @@ namespace Ndk
|
||||||
|
|
||||||
inline const std::vector<EntityHandle>& GetEntities() const;
|
inline const std::vector<EntityHandle>& GetEntities() const;
|
||||||
inline SystemIndex GetIndex() const;
|
inline SystemIndex GetIndex() const;
|
||||||
|
inline float GetUpdateRate() const;
|
||||||
inline World& GetWorld() const;
|
inline World& GetWorld() const;
|
||||||
|
|
||||||
inline bool HasEntity(const Entity* entity) const;
|
inline bool HasEntity(const Entity* entity) const;
|
||||||
|
|
||||||
|
inline void SetUpdateRate(float updatePerSecond);
|
||||||
|
|
||||||
|
inline void Update(float elapsedTime);
|
||||||
|
|
||||||
BaseSystem& operator=(const BaseSystem&) = delete;
|
BaseSystem& operator=(const BaseSystem&) = delete;
|
||||||
BaseSystem& operator=(BaseSystem&&) noexcept = default;
|
BaseSystem& operator=(BaseSystem&&) noexcept = default;
|
||||||
|
|
||||||
|
|
@ -55,6 +60,8 @@ namespace Ndk
|
||||||
template<typename ComponentType1, typename ComponentType2, typename... Rest> void RequiresAny();
|
template<typename ComponentType1, typename ComponentType2, typename... Rest> void RequiresAny();
|
||||||
inline void RequiresAnyComponent(ComponentIndex index);
|
inline void RequiresAnyComponent(ComponentIndex index);
|
||||||
|
|
||||||
|
virtual void OnUpdate(float elapsedTime) = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline void AddEntity(Entity* entity);
|
inline void AddEntity(Entity* entity);
|
||||||
|
|
||||||
|
|
@ -79,6 +86,8 @@ namespace Ndk
|
||||||
NzBitset<> m_requiredComponents;
|
NzBitset<> m_requiredComponents;
|
||||||
SystemIndex m_systemIndex;
|
SystemIndex m_systemIndex;
|
||||||
World* m_world;
|
World* m_world;
|
||||||
|
float m_updateCounter;
|
||||||
|
float m_updateRate;
|
||||||
|
|
||||||
static SystemIndex s_nextIndex;
|
static SystemIndex s_nextIndex;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,15 @@ namespace Ndk
|
||||||
inline BaseSystem::BaseSystem(SystemIndex systemId) :
|
inline BaseSystem::BaseSystem(SystemIndex systemId) :
|
||||||
m_systemIndex(systemId)
|
m_systemIndex(systemId)
|
||||||
{
|
{
|
||||||
|
SetUpdateRate(30);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline BaseSystem::BaseSystem(const BaseSystem& system) :
|
inline BaseSystem::BaseSystem(const BaseSystem& system) :
|
||||||
m_excludedComponents(system.m_excludedComponents),
|
m_excludedComponents(system.m_excludedComponents),
|
||||||
m_requiredComponents(system.m_requiredComponents),
|
m_requiredComponents(system.m_requiredComponents),
|
||||||
m_systemIndex(system.m_systemIndex)
|
m_systemIndex(system.m_systemIndex),
|
||||||
|
m_updateCounter(0.f),
|
||||||
|
m_updateRate(system.m_updateRate)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -29,6 +32,11 @@ namespace Ndk
|
||||||
return m_systemIndex;
|
return m_systemIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline float BaseSystem::GetUpdateRate() const
|
||||||
|
{
|
||||||
|
return 1.f / m_updateRate;
|
||||||
|
}
|
||||||
|
|
||||||
inline World& BaseSystem::GetWorld() const
|
inline World& BaseSystem::GetWorld() const
|
||||||
{
|
{
|
||||||
return *m_world;
|
return *m_world;
|
||||||
|
|
@ -42,6 +50,22 @@ namespace Ndk
|
||||||
return m_entityBits.UnboundedTest(entity->GetId());
|
return m_entityBits.UnboundedTest(entity->GetId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void BaseSystem::SetUpdateRate(float updatePerSecond)
|
||||||
|
{
|
||||||
|
m_updateCounter = 0.f;
|
||||||
|
m_updateRate = (updatePerSecond > 0.f) ? 1.f / updatePerSecond : 0.f; // 0.f means no limit
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void BaseSystem::Update(float elapsedTime)
|
||||||
|
{
|
||||||
|
m_updateCounter -= elapsedTime;
|
||||||
|
if (m_updateCounter < 0.f)
|
||||||
|
{
|
||||||
|
m_updateCounter += m_updateRate;
|
||||||
|
OnUpdate(elapsedTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template<typename ComponentType>
|
template<typename ComponentType>
|
||||||
void BaseSystem::Excludes()
|
void BaseSystem::Excludes()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,10 @@ namespace Ndk
|
||||||
ListenerSystem();
|
ListenerSystem();
|
||||||
~ListenerSystem() = default;
|
~ListenerSystem() = default;
|
||||||
|
|
||||||
void Update(float elapsedTime);
|
|
||||||
|
|
||||||
static SystemIndex systemIndex;
|
static SystemIndex systemIndex;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void OnUpdate(float elapsedTime) override;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,12 +23,11 @@ namespace Ndk
|
||||||
NzPhysWorld& GetWorld();
|
NzPhysWorld& GetWorld();
|
||||||
const NzPhysWorld& GetWorld() const;
|
const NzPhysWorld& GetWorld() const;
|
||||||
|
|
||||||
void Update(float elapsedTime);
|
|
||||||
|
|
||||||
static SystemIndex systemIndex;
|
static SystemIndex systemIndex;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void OnEntityValidation(Entity* entity, bool justAdded) override;
|
void OnEntityValidation(Entity* entity, bool justAdded) override;
|
||||||
|
void OnUpdate(float elapsedTime) override;
|
||||||
|
|
||||||
EntityList m_dynamicObjects;
|
EntityList m_dynamicObjects;
|
||||||
EntityList m_staticObjects;
|
EntityList m_staticObjects;
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,12 @@ namespace Ndk
|
||||||
inline RenderSystem(const RenderSystem& renderSystem);
|
inline RenderSystem(const RenderSystem& renderSystem);
|
||||||
~RenderSystem() = default;
|
~RenderSystem() = default;
|
||||||
|
|
||||||
void Update(float elapsedTime);
|
|
||||||
|
|
||||||
static SystemIndex systemIndex;
|
static SystemIndex systemIndex;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void OnEntityRemoved(Entity* entity) override;
|
void OnEntityRemoved(Entity* entity) override;
|
||||||
void OnEntityValidation(Entity* entity, bool justAdded) override;
|
void OnEntityValidation(Entity* entity, bool justAdded) override;
|
||||||
|
void OnUpdate(float elapsedTime) override;
|
||||||
void UpdateShadowMaps();
|
void UpdateShadowMaps();
|
||||||
|
|
||||||
EntityList m_cameras;
|
EntityList m_cameras;
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,10 @@ namespace Ndk
|
||||||
VelocitySystem();
|
VelocitySystem();
|
||||||
~VelocitySystem() = default;
|
~VelocitySystem() = default;
|
||||||
|
|
||||||
void Update(float elapsedTime);
|
|
||||||
|
|
||||||
static SystemIndex systemIndex;
|
static SystemIndex systemIndex;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void OnUpdate(float elapsedTime) override;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ namespace Ndk
|
||||||
template<typename SystemType> void RemoveSystem();
|
template<typename SystemType> void RemoveSystem();
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
|
inline void Update(float elapsedTime);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline void Invalidate();
|
inline void Invalidate();
|
||||||
|
|
|
||||||
|
|
@ -130,6 +130,15 @@ namespace Ndk
|
||||||
RemoveSystem(index);
|
RemoveSystem(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void World::Update(float elapsedTime)
|
||||||
|
{
|
||||||
|
Update(); //< Update entities
|
||||||
|
|
||||||
|
// And then update systems
|
||||||
|
for (auto& systemPtr : m_systems)
|
||||||
|
systemPtr->Update(elapsedTime);
|
||||||
|
}
|
||||||
|
|
||||||
inline void World::Invalidate()
|
inline void World::Invalidate()
|
||||||
{
|
{
|
||||||
m_dirtyEntities.Resize(m_entities.size(), false);
|
m_dirtyEntities.Resize(m_entities.size(), false);
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ namespace Ndk
|
||||||
Requires<ListenerComponent, NodeComponent>();
|
Requires<ListenerComponent, NodeComponent>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ListenerSystem::Update(float elapsedTime)
|
void ListenerSystem::OnUpdate(float elapsedTime)
|
||||||
{
|
{
|
||||||
NazaraUnused(elapsedTime);
|
NazaraUnused(elapsedTime);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,21 @@ namespace Ndk
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsSystem::Update(float elapsedTime)
|
void PhysicsSystem::OnEntityValidation(Entity* entity, bool justAdded)
|
||||||
|
{
|
||||||
|
// Si l'entité ne vient pas d'être ajoutée au système, il est possible qu'elle fasse partie du mauvais tableau
|
||||||
|
if (!justAdded)
|
||||||
|
{
|
||||||
|
// On prend le tableau inverse de celui dont l'entité devrait faire partie
|
||||||
|
auto& entities = (entity->HasComponent<PhysicsComponent>()) ? m_staticObjects : m_dynamicObjects;
|
||||||
|
entities.Remove(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& entities = (entity->HasComponent<PhysicsComponent>()) ? m_dynamicObjects : m_staticObjects;
|
||||||
|
entities.Insert(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhysicsSystem::OnUpdate(float elapsedTime)
|
||||||
{
|
{
|
||||||
m_world.Step(elapsedTime);
|
m_world.Step(elapsedTime);
|
||||||
|
|
||||||
|
|
@ -75,19 +89,5 @@ namespace Ndk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsSystem::OnEntityValidation(Entity* entity, bool justAdded)
|
|
||||||
{
|
|
||||||
// Si l'entité ne vient pas d'être ajoutée au système, il est possible qu'elle fasse partie du mauvais tableau
|
|
||||||
if (!justAdded)
|
|
||||||
{
|
|
||||||
// On prend le tableau inverse de celui dont l'entité devrait faire partie
|
|
||||||
auto& entities = (entity->HasComponent<PhysicsComponent>()) ? m_staticObjects : m_dynamicObjects;
|
|
||||||
entities.Remove(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& entities = (entity->HasComponent<PhysicsComponent>()) ? m_dynamicObjects : m_staticObjects;
|
|
||||||
entities.Insert(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
SystemIndex PhysicsSystem::systemIndex;
|
SystemIndex PhysicsSystem::systemIndex;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,69 @@ namespace Ndk
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderSystem::Update(float elapsedTime)
|
void RenderSystem::OnEntityRemoved(Entity* entity)
|
||||||
|
{
|
||||||
|
m_cameras.Remove(entity);
|
||||||
|
m_drawables.Remove(entity);
|
||||||
|
m_lights.Remove(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderSystem::OnEntityValidation(Entity* entity, bool justAdded)
|
||||||
|
{
|
||||||
|
if (entity->HasComponent<CameraComponent>() && entity->HasComponent<NodeComponent>())
|
||||||
|
{
|
||||||
|
m_cameras.Insert(entity);
|
||||||
|
std::sort(m_cameras.begin(), m_cameras.end(), [](const EntityHandle& handle1, const EntityHandle& handle2)
|
||||||
|
{
|
||||||
|
return handle1->GetComponent<CameraComponent>().GetLayer() < handle2->GetComponent<CameraComponent>().GetLayer();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_cameras.Remove(entity);
|
||||||
|
|
||||||
|
if (entity->HasComponent<GraphicsComponent>() && entity->HasComponent<NodeComponent>())
|
||||||
|
m_drawables.Insert(entity);
|
||||||
|
else
|
||||||
|
m_drawables.Remove(entity);
|
||||||
|
|
||||||
|
if (entity->HasComponent<LightComponent>() && entity->HasComponent<NodeComponent>())
|
||||||
|
m_lights.Insert(entity);
|
||||||
|
else
|
||||||
|
m_lights.Remove(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderSystem::OnEntityRemoved(Entity* entity)
|
||||||
|
{
|
||||||
|
m_cameras.Remove(entity);
|
||||||
|
m_drawables.Remove(entity);
|
||||||
|
m_lights.Remove(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderSystem::OnEntityValidation(Entity* entity, bool justAdded)
|
||||||
|
{
|
||||||
|
if (entity->HasComponent<CameraComponent>() && entity->HasComponent<NodeComponent>())
|
||||||
|
{
|
||||||
|
m_cameras.Insert(entity);
|
||||||
|
std::sort(m_cameras.begin(), m_cameras.end(), [](const EntityHandle& handle1, const EntityHandle& handle2)
|
||||||
|
{
|
||||||
|
return handle1->GetComponent<CameraComponent>().GetLayer() < handle2->GetComponent<CameraComponent>().GetLayer();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_cameras.Remove(entity);
|
||||||
|
|
||||||
|
if (entity->HasComponent<GraphicsComponent>() && entity->HasComponent<NodeComponent>())
|
||||||
|
m_drawables.Insert(entity);
|
||||||
|
else
|
||||||
|
m_drawables.Remove(entity);
|
||||||
|
|
||||||
|
if (entity->HasComponent<LightComponent>() && entity->HasComponent<NodeComponent>())
|
||||||
|
m_lights.Insert(entity);
|
||||||
|
else
|
||||||
|
m_lights.Remove(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderSystem::OnUpdate(float elapsedTime)
|
||||||
{
|
{
|
||||||
UpdateShadowMaps();
|
UpdateShadowMaps();
|
||||||
|
|
||||||
|
|
@ -56,37 +118,6 @@ namespace Ndk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderSystem::OnEntityRemoved(Entity* entity)
|
|
||||||
{
|
|
||||||
m_cameras.Remove(entity);
|
|
||||||
m_drawables.Remove(entity);
|
|
||||||
m_lights.Remove(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderSystem::OnEntityValidation(Entity* entity, bool justAdded)
|
|
||||||
{
|
|
||||||
if (entity->HasComponent<CameraComponent>() && entity->HasComponent<NodeComponent>())
|
|
||||||
{
|
|
||||||
m_cameras.Insert(entity);
|
|
||||||
std::sort(m_cameras.begin(), m_cameras.end(), [](const EntityHandle& handle1, const EntityHandle& handle2)
|
|
||||||
{
|
|
||||||
return handle1->GetComponent<CameraComponent>().GetLayer() < handle2->GetComponent<CameraComponent>().GetLayer();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
m_cameras.Remove(entity);
|
|
||||||
|
|
||||||
if (entity->HasComponent<GraphicsComponent>() && entity->HasComponent<NodeComponent>())
|
|
||||||
m_drawables.Insert(entity);
|
|
||||||
else
|
|
||||||
m_drawables.Remove(entity);
|
|
||||||
|
|
||||||
if (entity->HasComponent<LightComponent>() && entity->HasComponent<NodeComponent>())
|
|
||||||
m_lights.Insert(entity);
|
|
||||||
else
|
|
||||||
m_lights.Remove(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderSystem::UpdateShadowMaps()
|
void RenderSystem::UpdateShadowMaps()
|
||||||
{
|
{
|
||||||
if (!m_shadowRT.IsValid())
|
if (!m_shadowRT.IsValid())
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ namespace Ndk
|
||||||
Excludes<PhysicsComponent>();
|
Excludes<PhysicsComponent>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VelocitySystem::Update(float elapsedTime)
|
void VelocitySystem::OnUpdate(float elapsedTime)
|
||||||
{
|
{
|
||||||
for (const Ndk::EntityHandle& entity : GetEntities())
|
for (const Ndk::EntityHandle& entity : GetEntities())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,7 @@ function NazaraBuild:Execute()
|
||||||
return -- Alors l'utilisateur voulait probablement savoir comment utiliser le programme, on ne fait rien
|
return -- Alors l'utilisateur voulait probablement savoir comment utiliser le programme, on ne fait rien
|
||||||
end
|
end
|
||||||
|
|
||||||
if (self.Actions[_ACTION] ~= nil) then
|
if (self.Actions[_ACTION] == nil) then
|
||||||
self.Actions[_ACTION].Function()
|
|
||||||
else
|
|
||||||
if (#self.OrderedExtLibs > 0) then
|
if (#self.OrderedExtLibs > 0) then
|
||||||
solution("NazaraExtlibs")
|
solution("NazaraExtlibs")
|
||||||
platforms({"x32", "x64"})
|
platforms({"x32", "x64"})
|
||||||
|
|
@ -325,66 +323,66 @@ function NazaraBuild:Execute()
|
||||||
|
|
||||||
configuration({})
|
configuration({})
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
for k, exampleTable in ipairs(self.OrderedExamples) do
|
for k, exampleTable in ipairs(self.OrderedExamples) do
|
||||||
project("Demo" .. exampleTable.Name)
|
project("Demo" .. exampleTable.Name)
|
||||||
|
|
||||||
location(_ACTION .. "/examples")
|
location(_ACTION .. "/examples")
|
||||||
|
|
||||||
if (exampleTable.Console) then
|
if (exampleTable.Console) then
|
||||||
kind("ConsoleApp")
|
kind("ConsoleApp")
|
||||||
else
|
else
|
||||||
kind("Window")
|
kind("Window")
|
||||||
|
end
|
||||||
|
|
||||||
|
debugdir("../examples/bin")
|
||||||
|
includedirs({
|
||||||
|
"../include",
|
||||||
|
"../extlibs/include"
|
||||||
|
})
|
||||||
|
libdirs("../lib")
|
||||||
|
targetdir("../examples/bin")
|
||||||
|
|
||||||
|
files(exampleTable.Files)
|
||||||
|
excludes(exampleTable.FilesExclusion)
|
||||||
|
|
||||||
|
defines(exampleTable.Defines)
|
||||||
|
flags(exampleTable.Flags)
|
||||||
|
includedirs(exampleTable.Includes)
|
||||||
|
links(exampleTable.Libraries)
|
||||||
|
|
||||||
|
configuration("x32")
|
||||||
|
libdirs("../extlibs/lib/common/x86")
|
||||||
|
|
||||||
|
configuration("x64")
|
||||||
|
defines("NAZARA_PLATFORM_x64")
|
||||||
|
libdirs("../extlibs/lib/common/x64")
|
||||||
|
|
||||||
|
configuration({"codeblocks or codelite or gmake", "x32"})
|
||||||
|
libdirs("../lib/mingw/x86")
|
||||||
|
|
||||||
|
configuration({"codeblocks or codelite or gmake", "x64"})
|
||||||
|
libdirs("../lib/mingw/x64")
|
||||||
|
|
||||||
|
configuration({"vs*", "x32"})
|
||||||
|
libdirs("../lib/msvc/x86")
|
||||||
|
|
||||||
|
configuration({"vs*", "x64"})
|
||||||
|
libdirs("../lib/msvc/x64")
|
||||||
|
|
||||||
|
configuration({"xcode3 or xcode4", "x32"})
|
||||||
|
libdirs("../lib/xcode/x86")
|
||||||
|
|
||||||
|
configuration({"xcode3 or xcode4", "x64"})
|
||||||
|
libdirs("../lib/xcode/x64")
|
||||||
|
|
||||||
|
for k,v in pairs(exampleTable.ConfigurationLibraries) do
|
||||||
|
configuration(k)
|
||||||
|
links(v)
|
||||||
|
end
|
||||||
|
|
||||||
|
configuration({})
|
||||||
end
|
end
|
||||||
|
|
||||||
debugdir("../examples/bin")
|
|
||||||
includedirs({
|
|
||||||
"../include",
|
|
||||||
"../extlibs/include"
|
|
||||||
})
|
|
||||||
libdirs("../lib")
|
|
||||||
targetdir("../examples/bin")
|
|
||||||
|
|
||||||
files(exampleTable.Files)
|
|
||||||
excludes(exampleTable.FilesExclusion)
|
|
||||||
|
|
||||||
defines(exampleTable.Defines)
|
|
||||||
flags(exampleTable.Flags)
|
|
||||||
includedirs(exampleTable.Includes)
|
|
||||||
links(exampleTable.Libraries)
|
|
||||||
|
|
||||||
configuration("x32")
|
|
||||||
libdirs("../extlibs/lib/common/x86")
|
|
||||||
|
|
||||||
configuration("x64")
|
|
||||||
defines("NAZARA_PLATFORM_x64")
|
|
||||||
libdirs("../extlibs/lib/common/x64")
|
|
||||||
|
|
||||||
configuration({"codeblocks or codelite or gmake", "x32"})
|
|
||||||
libdirs("../lib/mingw/x86")
|
|
||||||
|
|
||||||
configuration({"codeblocks or codelite or gmake", "x64"})
|
|
||||||
libdirs("../lib/mingw/x64")
|
|
||||||
|
|
||||||
configuration({"vs*", "x32"})
|
|
||||||
libdirs("../lib/msvc/x86")
|
|
||||||
|
|
||||||
configuration({"vs*", "x64"})
|
|
||||||
libdirs("../lib/msvc/x64")
|
|
||||||
|
|
||||||
configuration({"xcode3 or xcode4", "x32"})
|
|
||||||
libdirs("../lib/xcode/x86")
|
|
||||||
|
|
||||||
configuration({"xcode3 or xcode4", "x64"})
|
|
||||||
libdirs("../lib/xcode/x64")
|
|
||||||
|
|
||||||
for k,v in pairs(exampleTable.ConfigurationLibraries) do
|
|
||||||
configuration(k)
|
|
||||||
links(v)
|
|
||||||
end
|
|
||||||
|
|
||||||
configuration({})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -590,7 +588,7 @@ function NazaraBuild:RegisterAction(actionTable)
|
||||||
{
|
{
|
||||||
trigger = lowerCaseName,
|
trigger = lowerCaseName,
|
||||||
description = actionTable.Description,
|
description = actionTable.Description,
|
||||||
execute = actionTable.Function
|
execute = function () actionTable:Function() end
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,16 @@ inline float NzLight::GetOuterAngle() const
|
||||||
return m_outerAngle;
|
return m_outerAngle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline float NzLight::GetOuterAngleCosine() const
|
||||||
|
{
|
||||||
|
return m_outerAngleCosine;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float NzLight::GetOuterAngleTangent() const
|
||||||
|
{
|
||||||
|
return m_outerAngleTangent;
|
||||||
|
}
|
||||||
|
|
||||||
inline float NzLight::GetRadius() const
|
inline float NzLight::GetRadius() const
|
||||||
{
|
{
|
||||||
return m_radius;
|
return m_radius;
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ struct NzRenderTextureImpl;
|
||||||
class NAZARA_RENDERER_API NzRenderTexture : public NzRenderTarget, NzNonCopyable
|
class NAZARA_RENDERER_API NzRenderTexture : public NzRenderTarget, NzNonCopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NzRenderTexture() = default;
|
inline NzRenderTexture();
|
||||||
~NzRenderTexture();
|
inline ~NzRenderTexture();
|
||||||
|
|
||||||
bool AttachBuffer(nzAttachmentPoint attachmentPoint, nzUInt8 index, NzRenderBuffer* buffer);
|
bool AttachBuffer(nzAttachmentPoint attachmentPoint, nzUInt8 index, NzRenderBuffer* buffer);
|
||||||
bool AttachBuffer(nzAttachmentPoint attachmentPoint, nzUInt8 index, nzPixelFormat format, unsigned int width, unsigned int height);
|
bool AttachBuffer(nzAttachmentPoint attachmentPoint, nzUInt8 index, nzPixelFormat format, unsigned int width, unsigned int height);
|
||||||
|
|
@ -38,18 +38,18 @@ class NAZARA_RENDERER_API NzRenderTexture : public NzRenderTarget, NzNonCopyable
|
||||||
|
|
||||||
void Detach(nzAttachmentPoint attachmentPoint, nzUInt8 index);
|
void Detach(nzAttachmentPoint attachmentPoint, nzUInt8 index);
|
||||||
|
|
||||||
unsigned int GetHeight() const;
|
unsigned int GetHeight() const override;
|
||||||
NzRenderTargetParameters GetParameters() const;
|
NzRenderTargetParameters GetParameters() const;
|
||||||
NzVector2ui GetSize() const;
|
NzVector2ui GetSize() const;
|
||||||
unsigned int GetWidth() const;
|
unsigned int GetWidth() const override;
|
||||||
|
|
||||||
bool IsComplete() const;
|
bool IsComplete() const;
|
||||||
bool IsRenderable() const;
|
bool IsRenderable() const;
|
||||||
bool IsValid() const;
|
inline bool IsValid() const;
|
||||||
|
|
||||||
bool Lock() const;
|
bool Lock() const;
|
||||||
|
|
||||||
void SetColorTarget(nzUInt8 target) const;
|
inline void SetColorTarget(nzUInt8 target) const;
|
||||||
void SetColorTargets(const nzUInt8* targets, unsigned int targetCount) const;
|
void SetColorTargets(const nzUInt8* targets, unsigned int targetCount) const;
|
||||||
void SetColorTargets(const std::initializer_list<nzUInt8>& targets) const;
|
void SetColorTargets(const std::initializer_list<nzUInt8>& targets) const;
|
||||||
|
|
||||||
|
|
@ -59,7 +59,7 @@ class NAZARA_RENDERER_API NzRenderTexture : public NzRenderTarget, NzNonCopyable
|
||||||
unsigned int GetOpenGLID() const;
|
unsigned int GetOpenGLID() const;
|
||||||
bool HasContext() const override;
|
bool HasContext() const override;
|
||||||
|
|
||||||
static void Blit(NzRenderTexture* src, NzRenderTexture* dst, nzUInt32 buffers = nzRendererBuffer_Color | nzRendererBuffer_Depth | nzRendererBuffer_Stencil, bool bilinearFilter = false);
|
static inline void Blit(NzRenderTexture* src, NzRenderTexture* dst, nzUInt32 buffers = nzRendererBuffer_Color | nzRendererBuffer_Depth | nzRendererBuffer_Stencil, bool bilinearFilter = false);
|
||||||
static void Blit(NzRenderTexture* src, NzRectui srcRect, NzRenderTexture* dst, NzRectui dstRect, nzUInt32 buffers = nzRendererBuffer_Color | nzRendererBuffer_Depth | nzRendererBuffer_Stencil, bool bilinearFilter = false);
|
static void Blit(NzRenderTexture* src, NzRectui srcRect, NzRenderTexture* dst, NzRectui dstRect, nzUInt32 buffers = nzRendererBuffer_Color | nzRendererBuffer_Depth | nzRendererBuffer_Stencil, bool bilinearFilter = false);
|
||||||
static bool IsSupported();
|
static bool IsSupported();
|
||||||
|
|
||||||
|
|
@ -69,6 +69,9 @@ class NAZARA_RENDERER_API NzRenderTexture : public NzRenderTarget, NzNonCopyable
|
||||||
void EnsureTargetUpdated() const override;
|
void EnsureTargetUpdated() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
inline void InvalidateDrawBuffers() const;
|
||||||
|
inline void InvalidateSize() const;
|
||||||
|
inline void InvalidateTargets() const;
|
||||||
void OnContextDestroy(const NzContext* context);
|
void OnContextDestroy(const NzContext* context);
|
||||||
void OnRenderBufferDestroy(const NzRenderBuffer* renderBuffer, unsigned int attachmentIndex);
|
void OnRenderBufferDestroy(const NzRenderBuffer* renderBuffer, unsigned int attachmentIndex);
|
||||||
void OnTextureDestroy(const NzTexture* texture, unsigned int attachmentIndex);
|
void OnTextureDestroy(const NzTexture* texture, unsigned int attachmentIndex);
|
||||||
|
|
@ -76,7 +79,13 @@ class NAZARA_RENDERER_API NzRenderTexture : public NzRenderTarget, NzNonCopyable
|
||||||
void UpdateSize() const;
|
void UpdateSize() const;
|
||||||
void UpdateTargets() const;
|
void UpdateTargets() const;
|
||||||
|
|
||||||
NzRenderTextureImpl* m_impl = nullptr;
|
NzRenderTextureImpl* m_impl;
|
||||||
|
mutable bool m_checked ;
|
||||||
|
mutable bool m_drawBuffersUpdated;
|
||||||
|
mutable bool m_sizeUpdated;
|
||||||
|
mutable bool m_targetsUpdated;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#include <Nazara/Renderer/RenderTexture.inl>
|
||||||
|
|
||||||
#endif // NAZARA_RENDERTEXTURE_HPP
|
#endif // NAZARA_RENDERTEXTURE_HPP
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Renderer module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#include <Nazara/Core/Error.hpp>
|
||||||
|
#include <cstring>
|
||||||
|
#include <Nazara/Renderer/Debug.hpp>
|
||||||
|
|
||||||
|
inline NzRenderTexture::NzRenderTexture() :
|
||||||
|
m_impl(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline NzRenderTexture::~NzRenderTexture()
|
||||||
|
{
|
||||||
|
Destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool NzRenderTexture::IsValid() const
|
||||||
|
{
|
||||||
|
return m_impl != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void NzRenderTexture::SetColorTarget(nzUInt8 target) const
|
||||||
|
{
|
||||||
|
SetColorTargets(&target, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void NzRenderTexture::Blit(NzRenderTexture* src, NzRenderTexture* dst, nzUInt32 buffers, bool bilinearFilter)
|
||||||
|
{
|
||||||
|
Blit(src, src->GetSize(), dst, dst->GetSize(), buffers, bilinearFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void NzRenderTexture::InvalidateDrawBuffers() const
|
||||||
|
{
|
||||||
|
m_drawBuffersUpdated = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void NzRenderTexture::InvalidateSize() const
|
||||||
|
{
|
||||||
|
m_sizeUpdated = false;
|
||||||
|
|
||||||
|
OnRenderTargetSizeChange(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void NzRenderTexture::InvalidateTargets() const
|
||||||
|
{
|
||||||
|
m_checked = false;
|
||||||
|
m_drawBuffersUpdated = false;
|
||||||
|
m_targetsUpdated = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Renderer/DebugOff.hpp>
|
||||||
|
|
@ -18,6 +18,9 @@
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
constexpr unsigned int s_allocatedId = 0xDEADB33FUL;
|
||||||
|
constexpr unsigned int s_freedId = 0x4B1DUL;
|
||||||
|
|
||||||
struct Block
|
struct Block
|
||||||
{
|
{
|
||||||
std::size_t size;
|
std::size_t size;
|
||||||
|
|
@ -31,7 +34,6 @@ namespace
|
||||||
|
|
||||||
bool s_allocationLogging = false;
|
bool s_allocationLogging = false;
|
||||||
bool s_initialized = false;
|
bool s_initialized = false;
|
||||||
const unsigned int s_magic = 0xDEADB33FUL;
|
|
||||||
const char* s_logFileName = "NazaraMemory.log";
|
const char* s_logFileName = "NazaraMemory.log";
|
||||||
thread_local const char* s_nextFreeFile = "(Internal error)";
|
thread_local const char* s_nextFreeFile = "(Internal error)";
|
||||||
thread_local unsigned int s_nextFreeLine = 0;
|
thread_local unsigned int s_nextFreeLine = 0;
|
||||||
|
|
@ -44,7 +46,7 @@ namespace
|
||||||
&s_list,
|
&s_list,
|
||||||
false,
|
false,
|
||||||
0,
|
0,
|
||||||
s_magic
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned int s_allocationCount = 0;
|
unsigned int s_allocationCount = 0;
|
||||||
|
|
@ -101,7 +103,7 @@ void* NzMemoryManager::Allocate(std::size_t size, bool multi, const char* file,
|
||||||
ptr->file = file;
|
ptr->file = file;
|
||||||
ptr->line = line;
|
ptr->line = line;
|
||||||
ptr->size = size;
|
ptr->size = size;
|
||||||
ptr->magic = s_magic;
|
ptr->magic = s_allocatedId;
|
||||||
|
|
||||||
ptr->prev = s_list.prev;
|
ptr->prev = s_list.prev;
|
||||||
ptr->next = &s_list;
|
ptr->next = &s_list;
|
||||||
|
|
@ -147,8 +149,22 @@ void NzMemoryManager::Free(void* pointer, bool multi)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Block* ptr = reinterpret_cast<Block*>(reinterpret_cast<nzUInt8*>(pointer) - sizeof(Block));
|
Block* ptr = reinterpret_cast<Block*>(reinterpret_cast<nzUInt8*>(pointer) - sizeof(Block));
|
||||||
if (ptr->magic != s_magic)
|
if (ptr->magic != s_allocatedId)
|
||||||
|
{
|
||||||
|
char timeStr[23];
|
||||||
|
TimeInfo(timeStr);
|
||||||
|
|
||||||
|
FILE* log = std::fopen(s_logFileName, "a");
|
||||||
|
|
||||||
|
const char* error = (ptr->magic == s_freedId) ? "double-delete" : "possible delete of dangling pointer";
|
||||||
|
if (s_nextFreeFile)
|
||||||
|
std::fprintf(log, "%s Warning: %s at %s:%u\n", timeStr, error, s_nextFreeFile, s_nextFreeLine);
|
||||||
|
else
|
||||||
|
std::fprintf(log, "%s Warning: %s at unknown position\n", timeStr, error);
|
||||||
|
|
||||||
|
std::fclose(log);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(NAZARA_PLATFORM_WINDOWS)
|
#if defined(NAZARA_PLATFORM_WINDOWS)
|
||||||
EnterCriticalSection(&s_mutex);
|
EnterCriticalSection(&s_mutex);
|
||||||
|
|
@ -167,12 +183,12 @@ void NzMemoryManager::Free(void* pointer, bool multi)
|
||||||
if (s_nextFreeFile)
|
if (s_nextFreeFile)
|
||||||
std::fprintf(log, "%s Warning: %s at %s:%u\n", timeStr, error, s_nextFreeFile, s_nextFreeLine);
|
std::fprintf(log, "%s Warning: %s at %s:%u\n", timeStr, error, s_nextFreeFile, s_nextFreeLine);
|
||||||
else
|
else
|
||||||
std::fprintf(log, "%s Warning: %s at unknown position\n", error, timeStr);
|
std::fprintf(log, "%s Warning: %s at unknown position\n", timeStr, error);
|
||||||
|
|
||||||
std::fclose(log);
|
std::fclose(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr->magic = 0; // Évitons des problèmes
|
ptr->magic = s_freedId;
|
||||||
ptr->prev->next = ptr->next;
|
ptr->prev->next = ptr->next;
|
||||||
ptr->next->prev = ptr->prev;
|
ptr->next->prev = ptr->prev;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,21 +63,12 @@ struct NzRenderTextureImpl
|
||||||
std::vector<nzUInt8> colorTargets;
|
std::vector<nzUInt8> colorTargets;
|
||||||
mutable std::vector<GLenum> drawBuffers;
|
mutable std::vector<GLenum> drawBuffers;
|
||||||
const NzContext* context;
|
const NzContext* context;
|
||||||
bool checked = false;
|
|
||||||
bool complete = false;
|
bool complete = false;
|
||||||
bool userDefinedTargets = false;
|
bool userDefinedTargets = false;
|
||||||
mutable bool drawBuffersUpdated = true;
|
|
||||||
mutable bool sizeUpdated = false;
|
|
||||||
mutable bool targetsUpdated = true;
|
|
||||||
unsigned int height;
|
unsigned int height;
|
||||||
unsigned int width;
|
unsigned int width;
|
||||||
};
|
};
|
||||||
|
|
||||||
NzRenderTexture::~NzRenderTexture()
|
|
||||||
{
|
|
||||||
Destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NzRenderTexture::AttachBuffer(nzAttachmentPoint attachmentPoint, nzUInt8 index, NzRenderBuffer* buffer)
|
bool NzRenderTexture::AttachBuffer(nzAttachmentPoint attachmentPoint, nzUInt8 index, NzRenderBuffer* buffer)
|
||||||
{
|
{
|
||||||
#if NAZARA_RENDERER_SAFE
|
#if NAZARA_RENDERER_SAFE
|
||||||
|
|
@ -160,15 +151,11 @@ bool NzRenderTexture::AttachBuffer(nzAttachmentPoint attachmentPoint, nzUInt8 in
|
||||||
attachment.height = buffer->GetHeight();
|
attachment.height = buffer->GetHeight();
|
||||||
attachment.width = buffer->GetWidth();
|
attachment.width = buffer->GetWidth();
|
||||||
|
|
||||||
m_impl->checked = false;
|
InvalidateSize();
|
||||||
m_impl->sizeUpdated = false;
|
InvalidateTargets();
|
||||||
|
|
||||||
if (attachmentPoint == nzAttachmentPoint_Color && !m_impl->userDefinedTargets)
|
if (attachmentPoint == nzAttachmentPoint_Color && !m_impl->userDefinedTargets)
|
||||||
{
|
|
||||||
m_impl->colorTargets.push_back(index);
|
m_impl->colorTargets.push_back(index);
|
||||||
m_impl->drawBuffersUpdated = false;
|
|
||||||
m_impl->targetsUpdated = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -301,15 +288,11 @@ bool NzRenderTexture::AttachTexture(nzAttachmentPoint attachmentPoint, nzUInt8 i
|
||||||
attachment.textureDestroySlot.Connect(texture->OnTextureDestroy, std::bind(&NzRenderTexture::OnTextureDestroy, this, std::placeholders::_1, attachIndex));
|
attachment.textureDestroySlot.Connect(texture->OnTextureDestroy, std::bind(&NzRenderTexture::OnTextureDestroy, this, std::placeholders::_1, attachIndex));
|
||||||
attachment.width = texture->GetWidth();
|
attachment.width = texture->GetWidth();
|
||||||
|
|
||||||
m_impl->checked = false;
|
InvalidateSize();
|
||||||
m_impl->sizeUpdated = false;
|
InvalidateTargets();
|
||||||
|
|
||||||
if (attachmentPoint == nzAttachmentPoint_Color && !m_impl->userDefinedTargets)
|
if (attachmentPoint == nzAttachmentPoint_Color && !m_impl->userDefinedTargets)
|
||||||
{
|
|
||||||
m_impl->colorTargets.push_back(index);
|
m_impl->colorTargets.push_back(index);
|
||||||
m_impl->drawBuffersUpdated = false;
|
|
||||||
m_impl->targetsUpdated = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -347,6 +330,11 @@ bool NzRenderTexture::Create(bool lock)
|
||||||
m_impl->context = NzContext::GetCurrent();
|
m_impl->context = NzContext::GetCurrent();
|
||||||
m_impl->contextDestroySlot.Connect(m_impl->context->OnContextDestroy, this, &NzRenderTexture::OnContextDestroy);
|
m_impl->contextDestroySlot.Connect(m_impl->context->OnContextDestroy, this, &NzRenderTexture::OnContextDestroy);
|
||||||
|
|
||||||
|
m_checked = false;
|
||||||
|
m_drawBuffersUpdated = true;
|
||||||
|
m_sizeUpdated = false;
|
||||||
|
m_targetsUpdated = true;
|
||||||
|
|
||||||
if (lock)
|
if (lock)
|
||||||
{
|
{
|
||||||
// En cas d'exception, la ressource sera quand même libérée
|
// En cas d'exception, la ressource sera quand même libérée
|
||||||
|
|
@ -436,30 +424,21 @@ void NzRenderTexture::Detach(nzAttachmentPoint attachmentPoint, nzUInt8 index)
|
||||||
attachement.textureDestroySlot.Disconnect();
|
attachement.textureDestroySlot.Disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_impl->sizeUpdated = false;
|
InvalidateSize();
|
||||||
|
|
||||||
if (attachement.attachmentPoint == nzAttachmentPoint_Color)
|
if (attachement.attachmentPoint == nzAttachmentPoint_Color)
|
||||||
{
|
InvalidateTargets();
|
||||||
m_impl->drawBuffersUpdated = false;
|
|
||||||
m_impl->targetsUpdated = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Unlock();
|
Unlock();
|
||||||
|
|
||||||
m_impl->checked = false;
|
m_checked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int NzRenderTexture::GetHeight() const
|
unsigned int NzRenderTexture::GetHeight() const
|
||||||
{
|
{
|
||||||
#if NAZARA_RENDERER_SAFE
|
NazaraAssert(m_impl, "Invalid render texture");
|
||||||
if (!m_impl)
|
|
||||||
{
|
|
||||||
NazaraError("Render texture not created");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!m_impl->sizeUpdated)
|
if (!m_sizeUpdated)
|
||||||
UpdateSize();
|
UpdateSize();
|
||||||
|
|
||||||
return m_impl->height;
|
return m_impl->height;
|
||||||
|
|
@ -467,13 +446,7 @@ unsigned int NzRenderTexture::GetHeight() const
|
||||||
|
|
||||||
NzRenderTargetParameters NzRenderTexture::GetParameters() const
|
NzRenderTargetParameters NzRenderTexture::GetParameters() const
|
||||||
{
|
{
|
||||||
#if NAZARA_RENDERER_SAFE
|
NazaraAssert(m_impl, "Invalid render texture");
|
||||||
if (!m_impl)
|
|
||||||
{
|
|
||||||
NazaraError("Render texture not created");
|
|
||||||
return NzRenderTargetParameters();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
///TODO
|
///TODO
|
||||||
return NzRenderTargetParameters();
|
return NzRenderTargetParameters();
|
||||||
|
|
@ -481,15 +454,9 @@ NzRenderTargetParameters NzRenderTexture::GetParameters() const
|
||||||
|
|
||||||
NzVector2ui NzRenderTexture::GetSize() const
|
NzVector2ui NzRenderTexture::GetSize() const
|
||||||
{
|
{
|
||||||
#if NAZARA_RENDERER_SAFE
|
NazaraAssert(m_impl, "Invalid render texture");
|
||||||
if (!m_impl)
|
|
||||||
{
|
|
||||||
NazaraError("Render texture not created");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!m_impl->sizeUpdated)
|
if (!m_sizeUpdated)
|
||||||
UpdateSize();
|
UpdateSize();
|
||||||
|
|
||||||
return NzVector2ui(m_impl->width, m_impl->height);
|
return NzVector2ui(m_impl->width, m_impl->height);
|
||||||
|
|
@ -497,15 +464,9 @@ NzVector2ui NzRenderTexture::GetSize() const
|
||||||
|
|
||||||
unsigned int NzRenderTexture::GetWidth() const
|
unsigned int NzRenderTexture::GetWidth() const
|
||||||
{
|
{
|
||||||
#if NAZARA_RENDERER_SAFE
|
NazaraAssert(m_impl, "Invalid render texture");
|
||||||
if (!m_impl)
|
|
||||||
{
|
|
||||||
NazaraError("Render texture not created");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!m_impl->sizeUpdated)
|
if (!m_sizeUpdated)
|
||||||
UpdateSize();
|
UpdateSize();
|
||||||
|
|
||||||
return m_impl->width;
|
return m_impl->width;
|
||||||
|
|
@ -513,15 +474,9 @@ unsigned int NzRenderTexture::GetWidth() const
|
||||||
|
|
||||||
bool NzRenderTexture::IsComplete() const
|
bool NzRenderTexture::IsComplete() const
|
||||||
{
|
{
|
||||||
#if NAZARA_RENDERER_SAFE
|
NazaraAssert(m_impl, "Invalid render texture");
|
||||||
if (!m_impl)
|
|
||||||
{
|
|
||||||
NazaraError("Render texture not created");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!m_impl->checked)
|
if (!m_checked)
|
||||||
{
|
{
|
||||||
if (!Lock())
|
if (!Lock())
|
||||||
{
|
{
|
||||||
|
|
@ -572,7 +527,7 @@ bool NzRenderTexture::IsComplete() const
|
||||||
NazaraInternalError("Unknown error");
|
NazaraInternalError("Unknown error");
|
||||||
}
|
}
|
||||||
|
|
||||||
m_impl->checked = true;
|
m_checked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_impl->complete;
|
return m_impl->complete;
|
||||||
|
|
@ -583,20 +538,11 @@ bool NzRenderTexture::IsRenderable() const
|
||||||
return IsComplete() && !m_impl->attachments.empty();
|
return IsComplete() && !m_impl->attachments.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzRenderTexture::IsValid() const
|
|
||||||
{
|
|
||||||
return m_impl != nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NzRenderTexture::Lock() const
|
bool NzRenderTexture::Lock() const
|
||||||
{
|
{
|
||||||
#if NAZARA_RENDERER_SAFE
|
NazaraAssert(m_impl, "Invalid render texture");
|
||||||
if (!m_impl)
|
|
||||||
{
|
|
||||||
NazaraError("Render texture not created");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#if NAZARA_RENDERER_SAFE
|
||||||
if (NzContext::GetCurrent() != m_impl->context)
|
if (NzContext::GetCurrent() != m_impl->context)
|
||||||
{
|
{
|
||||||
NazaraError("RenderTexture cannot be used with this context");
|
NazaraError("RenderTexture cannot be used with this context");
|
||||||
|
|
@ -618,20 +564,11 @@ bool NzRenderTexture::Lock() const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzRenderTexture::SetColorTarget(nzUInt8 target) const
|
|
||||||
{
|
|
||||||
SetColorTargets(&target, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void NzRenderTexture::SetColorTargets(const nzUInt8* targets, unsigned int targetCount) const
|
void NzRenderTexture::SetColorTargets(const nzUInt8* targets, unsigned int targetCount) const
|
||||||
{
|
{
|
||||||
#if NAZARA_RENDERER_SAFE
|
NazaraAssert(m_impl, "Invalid render texture");
|
||||||
if (!m_impl)
|
|
||||||
{
|
|
||||||
NazaraError("Render texture not created");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#if NAZARA_RENDERER_SAFE
|
||||||
for (unsigned int i = 0; i < targetCount; ++i)
|
for (unsigned int i = 0; i < targetCount; ++i)
|
||||||
{
|
{
|
||||||
unsigned int index = attachmentIndex[nzAttachmentPoint_Color] + targets[i];
|
unsigned int index = attachmentIndex[nzAttachmentPoint_Color] + targets[i];
|
||||||
|
|
@ -646,20 +583,15 @@ void NzRenderTexture::SetColorTargets(const nzUInt8* targets, unsigned int targe
|
||||||
m_impl->colorTargets.resize(targetCount);
|
m_impl->colorTargets.resize(targetCount);
|
||||||
std::memcpy(&m_impl->colorTargets[0], targets, targetCount*sizeof(nzUInt8));
|
std::memcpy(&m_impl->colorTargets[0], targets, targetCount*sizeof(nzUInt8));
|
||||||
|
|
||||||
m_impl->drawBuffersUpdated = false;
|
|
||||||
m_impl->targetsUpdated = false;
|
|
||||||
m_impl->userDefinedTargets = true;
|
m_impl->userDefinedTargets = true;
|
||||||
|
InvalidateDrawBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzRenderTexture::SetColorTargets(const std::initializer_list<nzUInt8>& targets) const
|
void NzRenderTexture::SetColorTargets(const std::initializer_list<nzUInt8>& targets) const
|
||||||
{
|
{
|
||||||
#if NAZARA_RENDERER_SAFE
|
NazaraAssert(m_impl, "Invalid render texture");
|
||||||
if (!m_impl)
|
|
||||||
{
|
|
||||||
NazaraError("Render texture not created");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#if NAZARA_RENDERER_SAFE
|
||||||
for (nzUInt8 target : targets)
|
for (nzUInt8 target : targets)
|
||||||
{
|
{
|
||||||
unsigned int index = attachmentIndex[nzAttachmentPoint_Color] + target;
|
unsigned int index = attachmentIndex[nzAttachmentPoint_Color] + target;
|
||||||
|
|
@ -677,20 +609,15 @@ void NzRenderTexture::SetColorTargets(const std::initializer_list<nzUInt8>& targ
|
||||||
for (nzUInt8 index : targets)
|
for (nzUInt8 index : targets)
|
||||||
*ptr++ = index;
|
*ptr++ = index;
|
||||||
|
|
||||||
m_impl->drawBuffersUpdated = false;
|
|
||||||
m_impl->targetsUpdated = false;
|
|
||||||
m_impl->userDefinedTargets = true;
|
m_impl->userDefinedTargets = true;
|
||||||
|
InvalidateDrawBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzRenderTexture::Unlock() const
|
void NzRenderTexture::Unlock() const
|
||||||
{
|
{
|
||||||
#if NAZARA_RENDERER_SAFE
|
NazaraAssert(m_impl, "Invalid render texture");
|
||||||
if (!m_impl)
|
|
||||||
{
|
|
||||||
NazaraError("Render texture not created");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#if NAZARA_RENDERER_SAFE
|
||||||
if (NzContext::GetCurrent() != m_impl->context)
|
if (NzContext::GetCurrent() != m_impl->context)
|
||||||
{
|
{
|
||||||
NazaraError("RenderTexture cannot be used with this context");
|
NazaraError("RenderTexture cannot be used with this context");
|
||||||
|
|
@ -710,13 +637,9 @@ void NzRenderTexture::Unlock() const
|
||||||
|
|
||||||
unsigned int NzRenderTexture::GetOpenGLID() const
|
unsigned int NzRenderTexture::GetOpenGLID() const
|
||||||
{
|
{
|
||||||
#if NAZARA_RENDERER_SAFE
|
NazaraAssert(m_impl, "Invalid render texture");
|
||||||
if (!m_impl)
|
|
||||||
{
|
|
||||||
NazaraError("Render texture not created");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#if NAZARA_RENDERER_SAFE
|
||||||
if (NzContext::GetCurrent() != m_impl->context)
|
if (NzContext::GetCurrent() != m_impl->context)
|
||||||
{
|
{
|
||||||
NazaraError("RenderTexture cannot be used with this context");
|
NazaraError("RenderTexture cannot be used with this context");
|
||||||
|
|
@ -737,46 +660,18 @@ bool NzRenderTexture::IsSupported()
|
||||||
return NzOpenGL::IsSupported(nzOpenGLExtension_FrameBufferObject);
|
return NzOpenGL::IsSupported(nzOpenGLExtension_FrameBufferObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzRenderTexture::Blit(NzRenderTexture* src, NzRenderTexture* dst, nzUInt32 buffers, bool bilinearFilter)
|
|
||||||
{
|
|
||||||
#if NAZARA_RENDERER_SAFE
|
|
||||||
if (!src)
|
|
||||||
{
|
|
||||||
NazaraError("Invalid source render texture");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!dst)
|
|
||||||
{
|
|
||||||
NazaraError("Invalid source render texture");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Blit(src, src->GetSize(), dst, dst->GetSize(), buffers, bilinearFilter);
|
|
||||||
}
|
|
||||||
|
|
||||||
void NzRenderTexture::Blit(NzRenderTexture* src, NzRectui srcRect, NzRenderTexture* dst, NzRectui dstRect, nzUInt32 buffers, bool bilinearFilter)
|
void NzRenderTexture::Blit(NzRenderTexture* src, NzRectui srcRect, NzRenderTexture* dst, NzRectui dstRect, nzUInt32 buffers, bool bilinearFilter)
|
||||||
{
|
{
|
||||||
#if NAZARA_RENDERER_SAFE
|
NazaraAssert(src && src->IsValid(), "Invalid source render texture");
|
||||||
if (!src || !src->IsValid())
|
NazaraAssert(dst && dst->IsValid(), "Invalid destination render texture");
|
||||||
{
|
|
||||||
NazaraError("Invalid source render texture");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#if NAZARA_RENDERER_SAFE
|
||||||
if (srcRect.x+srcRect.width > src->GetWidth() || srcRect.y+srcRect.height > src->GetHeight())
|
if (srcRect.x+srcRect.width > src->GetWidth() || srcRect.y+srcRect.height > src->GetHeight())
|
||||||
{
|
{
|
||||||
NazaraError("Source rectangle dimensions are out of bounds");
|
NazaraError("Source rectangle dimensions are out of bounds");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dst || !dst->IsValid())
|
|
||||||
{
|
|
||||||
NazaraError("Invalid source render texture");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dstRect.x+dstRect.width > dst->GetWidth() || dstRect.y+dstRect.height > dst->GetHeight())
|
if (dstRect.x+dstRect.width > dst->GetWidth() || dstRect.y+dstRect.height > dst->GetHeight())
|
||||||
{
|
{
|
||||||
NazaraError("Destination rectangle dimensions are out of bounds");
|
NazaraError("Destination rectangle dimensions are out of bounds");
|
||||||
|
|
@ -817,13 +712,9 @@ void NzRenderTexture::Blit(NzRenderTexture* src, NzRectui srcRect, NzRenderTextu
|
||||||
|
|
||||||
bool NzRenderTexture::Activate() const
|
bool NzRenderTexture::Activate() const
|
||||||
{
|
{
|
||||||
#if NAZARA_RENDERER_SAFE
|
NazaraAssert(m_impl, "Invalid render texture");
|
||||||
if (!m_impl)
|
|
||||||
{
|
|
||||||
NazaraError("Render texture not created");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#if NAZARA_RENDERER_SAFE
|
||||||
if (NzContext::GetCurrent() != m_impl->context)
|
if (NzContext::GetCurrent() != m_impl->context)
|
||||||
{
|
{
|
||||||
NazaraError("RenderTexture cannot be used with this context");
|
NazaraError("RenderTexture cannot be used with this context");
|
||||||
|
|
@ -833,20 +724,16 @@ bool NzRenderTexture::Activate() const
|
||||||
|
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_impl->fbo);
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_impl->fbo);
|
||||||
|
|
||||||
m_impl->drawBuffersUpdated = false;
|
m_drawBuffersUpdated = false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzRenderTexture::Desactivate() const
|
void NzRenderTexture::Desactivate() const
|
||||||
{
|
{
|
||||||
#if NAZARA_RENDERER_SAFE
|
NazaraAssert(m_impl, "Invalid render texture");
|
||||||
if (!m_impl)
|
|
||||||
{
|
|
||||||
NazaraError("Render texture not created");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#if NAZARA_RENDERER_SAFE
|
||||||
if (NzContext::GetCurrent() != m_impl->context)
|
if (NzContext::GetCurrent() != m_impl->context)
|
||||||
{
|
{
|
||||||
NazaraError("RenderTexture cannot be used with this context");
|
NazaraError("RenderTexture cannot be used with this context");
|
||||||
|
|
@ -861,7 +748,7 @@ void NzRenderTexture::Desactivate() const
|
||||||
|
|
||||||
void NzRenderTexture::EnsureTargetUpdated() const
|
void NzRenderTexture::EnsureTargetUpdated() const
|
||||||
{
|
{
|
||||||
if (!m_impl->drawBuffersUpdated)
|
if (!m_drawBuffersUpdated)
|
||||||
UpdateDrawBuffers();
|
UpdateDrawBuffers();
|
||||||
|
|
||||||
for (nzUInt8 index : m_impl->colorTargets)
|
for (nzUInt8 index : m_impl->colorTargets)
|
||||||
|
|
@ -900,8 +787,7 @@ void NzRenderTexture::OnRenderBufferDestroy(const NzRenderBuffer* renderBuffer,
|
||||||
attachment.isUsed = false;
|
attachment.isUsed = false;
|
||||||
attachment.renderBufferDestroySlot.Disconnect();
|
attachment.renderBufferDestroySlot.Disconnect();
|
||||||
|
|
||||||
m_impl->checked = false;
|
InvalidateTargets();
|
||||||
m_impl->targetsUpdated = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzRenderTexture::OnTextureDestroy(const NzTexture* texture, unsigned int attachmentIndex)
|
void NzRenderTexture::OnTextureDestroy(const NzTexture* texture, unsigned int attachmentIndex)
|
||||||
|
|
@ -911,23 +797,17 @@ void NzRenderTexture::OnTextureDestroy(const NzTexture* texture, unsigned int at
|
||||||
NazaraAssert(!m_impl->attachments[attachmentIndex].isBuffer, "Invalid attachment state");
|
NazaraAssert(!m_impl->attachments[attachmentIndex].isBuffer, "Invalid attachment state");
|
||||||
NazaraUnused(texture);
|
NazaraUnused(texture);
|
||||||
|
|
||||||
Attachment& attachment = m_impl->attachments[attachmentIndex];
|
InvalidateTargets();
|
||||||
attachment.isUsed = false;
|
|
||||||
attachment.texture = nullptr;
|
|
||||||
attachment.textureDestroySlot.Disconnect();
|
|
||||||
|
|
||||||
m_impl->checked = false;
|
|
||||||
m_impl->targetsUpdated = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzRenderTexture::UpdateDrawBuffers() const
|
void NzRenderTexture::UpdateDrawBuffers() const
|
||||||
{
|
{
|
||||||
if (!m_impl->targetsUpdated)
|
if (!m_targetsUpdated)
|
||||||
UpdateTargets();
|
UpdateTargets();
|
||||||
|
|
||||||
glDrawBuffers(m_impl->drawBuffers.size(), &m_impl->drawBuffers[0]);
|
glDrawBuffers(m_impl->drawBuffers.size(), &m_impl->drawBuffers[0]);
|
||||||
|
|
||||||
m_impl->drawBuffersUpdated = true;
|
m_drawBuffersUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzRenderTexture::UpdateSize() const
|
void NzRenderTexture::UpdateSize() const
|
||||||
|
|
@ -943,7 +823,7 @@ void NzRenderTexture::UpdateSize() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_impl->sizeUpdated = true;
|
m_sizeUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzRenderTexture::UpdateTargets() const
|
void NzRenderTexture::UpdateTargets() const
|
||||||
|
|
@ -961,5 +841,5 @@ void NzRenderTexture::UpdateTargets() const
|
||||||
*ptr++ = GL_COLOR_ATTACHMENT0 + index;
|
*ptr++ = GL_COLOR_ATTACHMENT0 + index;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_impl->targetsUpdated = true;
|
m_targetsUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue