Documentation for module: Graphics
Former-commit-id: 1757c33318443aade1dc38e16d053240d7dc885c
This commit is contained in:
34
tests/Engine/Graphics/Billboard.cpp
Normal file
34
tests/Engine/Graphics/Billboard.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <Nazara/Graphics/Billboard.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
SCENARIO("Billboard", "[GRAPHICS][BILLBOARD]")
|
||||
{
|
||||
GIVEN("A default billboard")
|
||||
{
|
||||
Nz::Billboard billboard;
|
||||
|
||||
WHEN("We assign it to another")
|
||||
{
|
||||
Nz::MaterialRef materialRef = Nz::Material::New();
|
||||
materialRef->LoadFromFile("resources/Engine/Graphics/Nazara.png");
|
||||
Nz::Color materialColor = materialRef->GetDiffuseColor();
|
||||
Nz::BillboardRef otherBillboard = Nz::Billboard::New(materialRef);
|
||||
|
||||
billboard = *otherBillboard;
|
||||
|
||||
THEN("The old one has the same properties than the new one")
|
||||
{
|
||||
REQUIRE(billboard.GetColor() == materialColor);
|
||||
REQUIRE(billboard.GetMaterial().Get() == materialRef.Get());
|
||||
REQUIRE(billboard.GetRotation() == Approx(0.f));
|
||||
REQUIRE(billboard.GetSize() == Nz::Vector2f(64.f, 64.f)); // Default sizes
|
||||
}
|
||||
|
||||
THEN("We set it with our new material and ask for its real size")
|
||||
{
|
||||
billboard.SetMaterial(materialRef, true);
|
||||
REQUIRE(billboard.GetSize() == Nz::Vector2f(765.f, 212.f)); // Nazara.png sizes
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
20
tests/Engine/Graphics/ColorBackground.cpp
Normal file
20
tests/Engine/Graphics/ColorBackground.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <Nazara/Graphics/ColorBackground.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
SCENARIO("ColorBackground", "[GRAPHICS][COLORBACKGROUND]")
|
||||
{
|
||||
GIVEN("A default color background")
|
||||
{
|
||||
Nz::ColorBackground colorBackground;
|
||||
|
||||
WHEN("We assign it a color")
|
||||
{
|
||||
colorBackground.SetColor(Nz::Color::Red);
|
||||
|
||||
THEN("We can get it")
|
||||
{
|
||||
REQUIRE(colorBackground.GetColor() == Nz::Color::Red);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
29
tests/Engine/Graphics/DeferredRenderTechnique.cpp
Normal file
29
tests/Engine/Graphics/DeferredRenderTechnique.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <Nazara/Graphics/DeferredRenderTechnique.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
SCENARIO("DeferredRenderTechnique", "[GRAPHICS][DEFERREDRENDERTECHNIQUE]")
|
||||
{
|
||||
GIVEN("A default deferred render technique")
|
||||
{
|
||||
Nz::DeferredRenderTechnique deferredRenderTechnique;
|
||||
|
||||
WHEN("We can disable a pass")
|
||||
{
|
||||
REQUIRE(deferredRenderTechnique.IsPassEnabled(Nz::RenderPassType::RenderPassType_AA, 0));
|
||||
deferredRenderTechnique.EnablePass(Nz::RenderPassType::RenderPassType_AA, 0, false);
|
||||
|
||||
THEN("It is disabled")
|
||||
{
|
||||
REQUIRE(!deferredRenderTechnique.IsPassEnabled(Nz::RenderPassType::RenderPassType_AA, 0));
|
||||
}
|
||||
|
||||
AND_THEN("We reset it, it is disabled and not the same as the old one")
|
||||
{
|
||||
Nz::DeferredRenderPass* oldPass = deferredRenderTechnique.GetPass(Nz::RenderPassType::RenderPassType_AA, 0);
|
||||
deferredRenderTechnique.ResetPass(Nz::RenderPassType::RenderPassType_AA, 0);
|
||||
REQUIRE(!deferredRenderTechnique.IsPassEnabled(Nz::RenderPassType::RenderPassType_AA, 0));
|
||||
REQUIRE(deferredRenderTechnique.GetPass(Nz::RenderPassType::RenderPassType_AA, 0) != oldPass);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
tests/Engine/Graphics/Light.cpp
Normal file
31
tests/Engine/Graphics/Light.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <Nazara/Graphics/Light.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
SCENARIO("Light", "[GRAPHICS][LIGHT]")
|
||||
{
|
||||
GIVEN("Different light")
|
||||
{
|
||||
Nz::Light directionalLight(Nz::LightType_Directional);
|
||||
Nz::Light pointLight(Nz::LightType_Point);
|
||||
Nz::Light spotLight(Nz::LightType_Spot);
|
||||
|
||||
WHEN("We try to cull")
|
||||
{
|
||||
Nz::Frustumf frustum;
|
||||
frustum.Build(90.f, 16.f / 9.f, 1.f, 1000.f, Nz::Vector3f::Zero(), Nz::Vector3f::UnitX());
|
||||
Nz::Matrix4f Unit3InX = Nz::Matrix4f::Translate(Nz::Vector3f::UnitX() * 3.f);
|
||||
Nz::Matrix4f rotationTowardsY = Unit3InX * Nz::Matrix4f::Rotate(Nz::EulerAnglesf(Nz::FromDegrees(90.f), 0.f, 0.f).ToQuaternion());
|
||||
|
||||
THEN("These results are expected")
|
||||
{
|
||||
REQUIRE(directionalLight.Cull(frustum, Unit3InX));
|
||||
REQUIRE(pointLight.Cull(frustum, Unit3InX));
|
||||
REQUIRE(!spotLight.Cull(frustum, Unit3InX));
|
||||
|
||||
REQUIRE(directionalLight.Cull(frustum, rotationTowardsY));
|
||||
REQUIRE(pointLight.Cull(frustum, rotationTowardsY));
|
||||
REQUIRE(!spotLight.Cull(frustum, rotationTowardsY));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
24
tests/Engine/Graphics/Model.cpp
Normal file
24
tests/Engine/Graphics/Model.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <Nazara/Graphics/Model.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
SCENARIO("Model", "[GRAPHICS][MODEL]")
|
||||
{
|
||||
GIVEN("The standford dragon model")
|
||||
{
|
||||
WHEN("We get general informations")
|
||||
{
|
||||
THEN("These results are expected")
|
||||
{
|
||||
Nz::ModelRef model = Nz::Model::New();
|
||||
REQUIRE(model->LoadFromFile("resources/Engine/Graphics/dragon_recon/dragon_vrip_res4.obj"));
|
||||
|
||||
REQUIRE(model->GetMaterialCount() == 2);
|
||||
REQUIRE(model->GetSkin() == 0);
|
||||
REQUIRE(model->GetSkinCount() == 1);
|
||||
|
||||
Nz::Material* material = model->GetMaterial(0);
|
||||
REQUIRE(material->GetAmbientColor() == Nz::Color(128));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
29
tests/Engine/Graphics/ParticleDeclaration.cpp
Normal file
29
tests/Engine/Graphics/ParticleDeclaration.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <Nazara/Graphics/ParticleDeclaration.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
SCENARIO("ParticleDeclaration", "[GRAPHICS][PARTICLEDECLARATION]")
|
||||
{
|
||||
GIVEN("A particle declaration of a model")
|
||||
{
|
||||
Nz::ParticleDeclaration* particleDeclaration = Nz::ParticleDeclaration::Get(Nz::ParticleLayout_Model);
|
||||
|
||||
WHEN("We disable a component")
|
||||
{
|
||||
bool enabled;
|
||||
Nz::ComponentType type;
|
||||
unsigned int offset;
|
||||
particleDeclaration->GetComponent(Nz::ParticleComponent_Position, &enabled, &type, &offset);
|
||||
REQUIRE(enabled);
|
||||
unsigned int oldStride = particleDeclaration->GetStride();
|
||||
|
||||
particleDeclaration->DisableComponent(Nz::ParticleComponent_Position);
|
||||
REQUIRE(oldStride != particleDeclaration->GetStride());
|
||||
|
||||
THEN("We can enable it and the stride is back")
|
||||
{
|
||||
particleDeclaration->EnableComponent(Nz::ParticleComponent_Position, type, offset);
|
||||
REQUIRE(oldStride == particleDeclaration->GetStride());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
103
tests/Engine/Graphics/ParticleSystem.cpp
Normal file
103
tests/Engine/Graphics/ParticleSystem.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
#include <Nazara/Graphics/ParticleSystem.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
#include <Nazara/Core/SparsePtr.hpp>
|
||||
#include <Nazara/Graphics/ParticleMapper.hpp>
|
||||
|
||||
class TestParticleController : public Nz::ParticleController
|
||||
{
|
||||
public:
|
||||
// Be aware that the interval is [startId, endId] and NOT [startId, endId)
|
||||
void Apply(Nz::ParticleSystem& system, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime) override
|
||||
{
|
||||
Nz::SparsePtr<Nz::Vector3f> positionPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Position);
|
||||
Nz::SparsePtr<Nz::Vector3f> velocityPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Velocity);
|
||||
Nz::SparsePtr<float> lifePtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Life);
|
||||
|
||||
for (unsigned int i = startId; i <= endId; ++i)
|
||||
{
|
||||
Nz::Vector3f& particlePosition = positionPtr[i];
|
||||
Nz::Vector3f& particleVelocity = velocityPtr[i];
|
||||
float& particleLife = lifePtr[i];
|
||||
|
||||
particleLife -= elapsedTime;
|
||||
if (particleLife <= 0.f)
|
||||
system.KillParticle(i);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class TestParticleEmitter : public Nz::ParticleEmitter
|
||||
{
|
||||
public:
|
||||
~TestParticleEmitter() override = default;
|
||||
|
||||
void Emit(Nz::ParticleSystem& system, float elapsedTime) const override
|
||||
{
|
||||
system.GenerateParticles(GetEmissionCount());
|
||||
}
|
||||
|
||||
private:
|
||||
void SetupParticles(Nz::ParticleMapper& mapper, unsigned int count) const override
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class TestParticleGenerator : public Nz::ParticleGenerator
|
||||
{
|
||||
public:
|
||||
~TestParticleGenerator() override = default;
|
||||
|
||||
// Be aware that the interval is [startId, endId] and NOT [startId, endId)
|
||||
void Generate(Nz::ParticleSystem& system, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId) override
|
||||
{
|
||||
Nz::SparsePtr<Nz::Vector3f> positionPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Position);
|
||||
Nz::SparsePtr<Nz::Vector3f> velocityPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Velocity);
|
||||
Nz::SparsePtr<float> lifePtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Life);
|
||||
|
||||
for (unsigned int i = startId; i <= endId; ++i)
|
||||
{
|
||||
Nz::Vector3f& particlePosition = positionPtr[i];
|
||||
Nz::Vector3f& particleVelocity = velocityPtr[i];
|
||||
float& particleLife = lifePtr[i];
|
||||
|
||||
particlePosition = Nz::Vector3f::Zero();
|
||||
particleVelocity = Nz::Vector3f::UnitX();
|
||||
particleLife = 1.3f;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SCENARIO("ParticleSystem", "[GRAPHICS][PARTICLESYSTEM]")
|
||||
{
|
||||
GIVEN("A particle system of maximum 10 billboards with its generators")
|
||||
{
|
||||
// These need to be alive longer than the particle system
|
||||
TestParticleController particleController;
|
||||
TestParticleGenerator particleGenerator;
|
||||
Nz::ParticleSystem particleSystem(10, Nz::ParticleLayout_Billboard);
|
||||
|
||||
particleSystem.AddController(&particleController);
|
||||
TestParticleEmitter particleEmitter;
|
||||
particleEmitter.SetEmissionCount(10);
|
||||
particleSystem.AddEmitter(&particleEmitter);
|
||||
|
||||
particleSystem.AddGenerator(&particleGenerator);
|
||||
|
||||
WHEN("We update to generate 10 particles")
|
||||
{
|
||||
particleSystem.Update(1.f);
|
||||
|
||||
THEN("There must be 10 particles")
|
||||
{
|
||||
REQUIRE(particleSystem.GetParticleCount() == 10);
|
||||
}
|
||||
|
||||
AND_THEN("We update to make them die")
|
||||
{
|
||||
particleSystem.Update(2.f);
|
||||
REQUIRE(particleSystem.GetParticleCount() == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
47
tests/Engine/Graphics/RenderTechniques.cpp
Normal file
47
tests/Engine/Graphics/RenderTechniques.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <Nazara/Graphics/RenderTechniques.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
#include <Nazara/Graphics/AbstractRenderTechnique.hpp>
|
||||
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
|
||||
|
||||
SCENARIO("RenderTechniques", "[GRAPHICS][RENDERTECHNIQUES]")
|
||||
{
|
||||
GIVEN("Nothing")
|
||||
{
|
||||
WHEN("We try to get a technique")
|
||||
{
|
||||
THEN("We should get it")
|
||||
{
|
||||
std::unique_ptr<Nz::AbstractRenderTechnique> forwardByEnum(Nz::RenderTechniques::GetByEnum(Nz::RenderTechniqueType_BasicForward));
|
||||
REQUIRE(forwardByEnum->GetType() == Nz::RenderTechniqueType_BasicForward);
|
||||
|
||||
std::unique_ptr<Nz::AbstractRenderTechnique> forwardByIndex(Nz::RenderTechniques::GetByIndex(1));
|
||||
REQUIRE(forwardByIndex->GetType() == Nz::RenderTechniqueType_BasicForward);
|
||||
|
||||
std::unique_ptr<Nz::AbstractRenderTechnique> forwardByName(Nz::RenderTechniques::GetByName(Nz::RenderTechniques::ToString(Nz::RenderTechniqueType_BasicForward)));
|
||||
REQUIRE(forwardByName->GetType() == Nz::RenderTechniqueType_BasicForward);
|
||||
}
|
||||
|
||||
THEN("We can register a render technique")
|
||||
{
|
||||
unsigned int previousCount = Nz::RenderTechniques::GetCount();
|
||||
|
||||
Nz::RenderTechniques::Register("test", 23, []() -> Nz::AbstractRenderTechnique* {
|
||||
return new Nz::ForwardRenderTechnique;
|
||||
});
|
||||
|
||||
REQUIRE(previousCount < Nz::RenderTechniques::GetCount());
|
||||
|
||||
std::unique_ptr<Nz::AbstractRenderTechnique> forwardByRanking(Nz::RenderTechniques::GetByRanking(23));
|
||||
REQUIRE(forwardByRanking->GetType() == Nz::RenderTechniqueType_BasicForward);
|
||||
|
||||
std::unique_ptr<Nz::AbstractRenderTechnique> forwardByName(Nz::RenderTechniques::GetByName("test"));
|
||||
REQUIRE(forwardByName->GetType() == Nz::RenderTechniqueType_BasicForward);
|
||||
|
||||
Nz::RenderTechniques::Unregister("test");
|
||||
|
||||
REQUIRE(previousCount == Nz::RenderTechniques::GetCount());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
26
tests/Engine/Graphics/SkeletalModel.cpp
Normal file
26
tests/Engine/Graphics/SkeletalModel.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <Nazara/Graphics/SkeletalModel.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
SCENARIO("SkeletalModel", "[GRAPHICS][SKELETALMODEL]")
|
||||
{
|
||||
GIVEN("A default skeletal model")
|
||||
{
|
||||
Nz::SkeletalModel skeletalModel;
|
||||
Nz::AnimationRef animation = Nz::Animation::New();
|
||||
|
||||
WHEN("We can load the bob lamp")
|
||||
{
|
||||
REQUIRE(skeletalModel.LoadFromFile("resources/Engine/Graphics/Bob lamp/bob_lamp_update.md5mesh"));
|
||||
REQUIRE(animation->LoadFromFile("resources/Engine/Graphics/Bob lamp/bob_lamp_update.md5anim"));
|
||||
skeletalModel.SetAnimation(animation);
|
||||
|
||||
THEN("We can enable its animation")
|
||||
{
|
||||
REQUIRE(skeletalModel.HasAnimation());
|
||||
skeletalModel.EnableAnimation(true);
|
||||
skeletalModel.AdvanceAnimation(0.10f);
|
||||
REQUIRE(skeletalModel.IsAnimationEnabled());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
25
tests/Engine/Graphics/SkyboxBackground.cpp
Normal file
25
tests/Engine/Graphics/SkyboxBackground.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <Nazara/Graphics/SkyboxBackground.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
SCENARIO("SkyboxBackground", "[GRAPHICS][SKYBOXBACKGROUND]")
|
||||
{
|
||||
GIVEN("A skybox background with a loaded image")
|
||||
{
|
||||
Nz::TextureRef textureRef = Nz::Texture::New();
|
||||
textureRef->LoadCubemapFromFile("resources/Engine/Graphics/skybox.png");
|
||||
Nz::SkyboxBackgroundRef skyboxBackgroundRef = Nz::SkyboxBackground::New(textureRef);
|
||||
|
||||
WHEN("We assign it parameters")
|
||||
{
|
||||
skyboxBackgroundRef->SetMovementOffset(Nz::Vector3f::Unit());
|
||||
skyboxBackgroundRef->SetMovementScale(1.f);
|
||||
|
||||
THEN("We can get it")
|
||||
{
|
||||
REQUIRE(skyboxBackgroundRef->GetMovementOffset() == Nz::Vector3f::Unit());
|
||||
REQUIRE(skyboxBackgroundRef->GetMovementScale() == Approx(1.f));
|
||||
REQUIRE(skyboxBackgroundRef->GetTexture().Get() == textureRef.Get());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
20
tests/Engine/Graphics/TextureBackground.cpp
Normal file
20
tests/Engine/Graphics/TextureBackground.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <Nazara/Graphics/TextureBackground.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
SCENARIO("TextureBackground", "[GRAPHICS][TEXTUREBACKGROUND]")
|
||||
{
|
||||
GIVEN("A default texture background")
|
||||
{
|
||||
Nz::TextureRef textureRef = Nz::Texture::New();
|
||||
textureRef->LoadFromFile("resources/Engine/Graphics/skybox.png");
|
||||
Nz::TextureBackgroundRef textureBackgroundRef = Nz::TextureBackground::New(textureRef);
|
||||
|
||||
WHEN("We assign it parameters")
|
||||
{
|
||||
THEN("We can get it")
|
||||
{
|
||||
REQUIRE(textureBackgroundRef->GetTexture().Get() == textureRef.Get());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,14 +39,14 @@ SCENARIO("Sphere", "[MATH][SPHERE]")
|
||||
|
||||
WHEN("We ask for distance")
|
||||
{
|
||||
THEN("These results are expected")
|
||||
THEN("These results are expected because we don't take into account the border")
|
||||
{
|
||||
REQUIRE(firstCenterAndUnit.Distance(Nz::Vector3f::UnitX()) == Approx(1.f));
|
||||
REQUIRE(firstCenterAndUnit.SquaredDistance(Nz::Vector3f::UnitX()) == Approx(1.f));
|
||||
REQUIRE(firstCenterAndUnit.Distance(Nz::Vector3f::UnitX() * 2.f) == Approx(1.f));
|
||||
REQUIRE(firstCenterAndUnit.SquaredDistance(Nz::Vector3f::UnitX() * 2.f) == Approx(1.f));
|
||||
|
||||
Nz::Spheref tmp(Nz::Vector3f::UnitX(), 1.f);
|
||||
REQUIRE(tmp.Distance(Nz::Vector3f::UnitX() * 4.f) == Approx(3.f));
|
||||
REQUIRE(tmp.SquaredDistance(Nz::Vector3f::UnitX() * 4.f) == Approx(9.f));
|
||||
REQUIRE(tmp.Distance(Nz::Vector3f::UnitX() * 4.f) == Approx(2.f));
|
||||
REQUIRE(tmp.SquaredDistance(Nz::Vector3f::UnitX() * 4.f) == Approx(4.f));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ SCENARIO("Sphere", "[MATH][SPHERE]")
|
||||
THEN("Sphere must contain it and distance should be good")
|
||||
{
|
||||
CHECK(firstCenterAndUnit.Contains(point));
|
||||
REQUIRE(firstCenterAndUnit.Distance(point) == 2.f);
|
||||
REQUIRE(firstCenterAndUnit.Distance(point) == 1.f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user