diff --git a/demos/combustion_demo/src/combustion_demo.cpp b/demos/combustion_demo/src/combustion_demo.cpp index 909ccfd04f727bcdfc54c03d40341f7698f225f8..ab7bedcef95122ba366b7797bb0f60e947c649c9 100644 --- a/demos/combustion_demo/src/combustion_demo.cpp +++ b/demos/combustion_demo/src/combustion_demo.cpp @@ -37,6 +37,7 @@ #include "phx/input/input_system.hpp" #include "phx/rendering/auxiliary/splash_screen.hpp" #include "phx/rendering/components/mesh_handle.hpp" +#include "phx/rendering/components/mesh_render_settings.hpp" #include "phx/resources/loaders/assimp_model_loader.hpp" #include "phx/resources/loaders/scene_loader.hpp" #include "phx/setup.hpp" @@ -105,7 +106,9 @@ int main(int, char**) { auto boundingbox_mesh_handle = boundingbox_transform->GetChild(0) ->GetEntity() ->GetFirstComponent<phx::MeshHandle>(); - boundingbox_mesh_handle->SetWireframeMode(true); + auto render_settings = + model_boundingbox->AddComponent<phx::MeshRenderSettings>(); + render_settings->SetWireframeMode(true); std::array<glm::vec3, 2> bbox = boundingbox_mesh_handle->GetMesh()->GetBoundingBox(); diff --git a/library/phx/rendering/components/mesh_handle.cpp b/library/phx/rendering/components/mesh_handle.cpp index 14041b3414920d201f59526cee2f4cd310acb139..85fd32a7fcc2feea41f9f8f115e816a67c71fff3 100644 --- a/library/phx/rendering/components/mesh_handle.cpp +++ b/library/phx/rendering/components/mesh_handle.cpp @@ -32,10 +32,6 @@ void MeshHandle::SetMesh(ResourcePointer<Mesh> mesh) { mesh_ = mesh; } ResourcePointer<Mesh> MeshHandle::GetMesh() const { return mesh_; } -void MeshHandle::SetWireframeMode(bool enabled) { wireframe_mode_ = enabled; } - -bool MeshHandle::GetWireframeMode() const { return wireframe_mode_; } - std::string MeshHandle::ToString() const { if (mesh_ == nullptr) return GetName() + " (MeshHandle <empty>)"; diff --git a/library/phx/rendering/components/mesh_handle.hpp b/library/phx/rendering/components/mesh_handle.hpp index 52ba4594f6f92424ede2e80fc7881757ed1c5b42..9ad2de1e10c9dbfd2f82b9636795000f366c2181 100644 --- a/library/phx/rendering/components/mesh_handle.hpp +++ b/library/phx/rendering/components/mesh_handle.hpp @@ -25,10 +25,10 @@ #include <string> #include "phx/core/component.hpp" -#include "phx/resources/types/mesh.hpp" +#include "phx/export.hpp" #include "phx/resources/resource_pointer.hpp" +#include "phx/resources/types/mesh.hpp" #include "phx/utility/aspects/nameable.hpp" -#include "phx/export.hpp" namespace phx { /** @@ -41,9 +41,6 @@ class PHOENIX_EXPORT MeshHandle final : public Component, public Nameable { void SetMesh(ResourcePointer<Mesh> mesh); ResourcePointer<Mesh> GetMesh() const; - void SetWireframeMode(bool enabled); - bool GetWireframeMode() const; - std::string ToString() const override; protected: @@ -57,7 +54,6 @@ class PHOENIX_EXPORT MeshHandle final : public Component, public Nameable { private: ResourcePointer<Mesh> mesh_{nullptr}; - bool wireframe_mode_ = false; }; } // namespace phx diff --git a/library/phx/rendering/components/mesh_render_settings.cpp b/library/phx/rendering/components/mesh_render_settings.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0a2907d581bad4d411c712ed357092391673441c --- /dev/null +++ b/library/phx/rendering/components/mesh_render_settings.cpp @@ -0,0 +1,39 @@ +//------------------------------------------------------------------------------ +// Project Phoenix +// +// Copyright (c) 2017-2018 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualization Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the 3-Clause BSD License (the "License"); +// you may not use this file except in compliance with the License. +// See the file LICENSE for the full text. +// You may obtain a copy of the License at +// +// https://opensource.org/licenses/BSD-3-Clause +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#include "phx/rendering/components/mesh_render_settings.hpp" + +namespace phx { + +const MeshRenderSettings MeshRenderSettings::default_settings_; + +void MeshRenderSettings::SetWireframeMode(const bool enabled) { + wireframe_mode_ = enabled; +} + +bool MeshRenderSettings::GetWireframeMode() const { return wireframe_mode_; } + +const MeshRenderSettings* MeshRenderSettings::GetDefault() { + return &default_settings_; +} + +} // namespace phx diff --git a/library/phx/rendering/components/mesh_render_settings.hpp b/library/phx/rendering/components/mesh_render_settings.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b35f1710e2ba330fad793266883a2603bae5d593 --- /dev/null +++ b/library/phx/rendering/components/mesh_render_settings.hpp @@ -0,0 +1,48 @@ +//------------------------------------------------------------------------------ +// Project Phoenix +// +// Copyright (c) 2017-2018 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualization Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the 3-Clause BSD License (the "License"); +// you may not use this file except in compliance with the License. +// See the file LICENSE for the full text. +// You may obtain a copy of the License at +// +// https://opensource.org/licenses/BSD-3-Clause +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ +#ifndef LIBRARY_PHX_RENDERING_COMPONENTS_MESH_RENDER_SETTINGS_HPP_ +#define LIBRARY_PHX_RENDERING_COMPONENTS_MESH_RENDER_SETTINGS_HPP_ + +#include "phx/core/component.hpp" +#include "phx/export.hpp" + +namespace phx { +/** + * A component holding a simple pointer to a mesh + */ +class PHOENIX_EXPORT MeshRenderSettings final : public Component { + public: + virtual ~MeshRenderSettings() = default; + + void SetWireframeMode(bool enabled); + bool GetWireframeMode() const; + + static const MeshRenderSettings* GetDefault(); + + private: + bool wireframe_mode_ = false; + + static const MeshRenderSettings default_settings_; +}; +} // namespace phx + +#endif // LIBRARY_PHX_RENDERING_COMPONENTS_MESH_RENDER_SETTINGS_HPP_ diff --git a/library/phx/rendering/render_passes/geometry_pass.cpp b/library/phx/rendering/render_passes/geometry_pass.cpp index ca4eef6be568b55fbbaa72b8cffc8070f04d4460..434b0b0a6e91d04957279a1f8b31e21a1ee2bfdb 100644 --- a/library/phx/rendering/render_passes/geometry_pass.cpp +++ b/library/phx/rendering/render_passes/geometry_pass.cpp @@ -35,9 +35,9 @@ #include "phx/core/logger.hpp" #include "phx/rendering/components/transform.hpp" +#include "phx/resources/resource_utils.hpp" #include "phx/resources/types/mesh.hpp" #include "phx/resources/types/shader_source.hpp" -#include "phx/resources/resource_utils.hpp" namespace phx { @@ -223,9 +223,15 @@ void GeometryPass::Draw(const RenderingInstance& rendering_instance) { SetTransformShaderUniforms(model_matrix, view_matrix, projection_matrix); SetMaterialShaderUniforms(rendering_instance.material); + const MeshRenderSettings* render_settings = + rendering_instance.mesh_render_settings; + if (render_settings == nullptr) { + render_settings = MeshRenderSettings::GetDefault(); + } + glEnable(GL_DEPTH_TEST); glPolygonMode(GL_FRONT_AND_BACK, - rendering_instance.wireframe_mode ? GL_LINE : GL_FILL); + render_settings->GetWireframeMode() ? GL_LINE : GL_FILL); glDrawElements( GL_TRIANGLES, static_cast<GLsizei>(rendering_instance.mesh->GetIndices().size()), @@ -291,41 +297,32 @@ void GeometryPass::SetLightShaderUniforms() { } } -void GeometryPass::SetMaterialShaderUniforms(Material* material) { - glm::uvec4 texture_toggle(0, 0, 0, 0); - glm::vec3 ambient_color(1, 0, 0); - glm::vec3 diffuse_color(1, 0, 0); - glm::vec3 specular_color(1, 0, 0); - float shininess = 1.0f; - if (material != nullptr) { - ambient_color = material->GetAmbientColor(); - diffuse_color = material->GetDiffuseColor(); - specular_color = material->GetSpecularColor(); - - texture_toggle = - glm::uvec4(material->GetAmbientTexture() != nullptr ? 1u : 0u, - material->GetDiffuseTexture() != nullptr ? 1u : 0u, - material->GetSpecularTexture() != nullptr ? 1u : 0u, 0u); - if (material->GetAmbientTexture()) - shader_program_->set_uniform_handle( - shader_program_->uniform_location("material.ambient_tex"), - gl::texture_handle(*material->GetAmbientTexture())); - if (material->GetDiffuseTexture()) - shader_program_->set_uniform_handle( - shader_program_->uniform_location("material.diffuse_tex"), - gl::texture_handle(*material->GetDiffuseTexture())); - if (material->GetSpecularTexture()) - shader_program_->set_uniform_handle( - shader_program_->uniform_location("material.specular_tex"), - gl::texture_handle(*material->GetSpecularTexture())); - - shininess = material->GetShininess(); - } +void GeometryPass::SetMaterialShaderUniforms(const Material* material) { + if (material == nullptr) material = Material::GetDefault(); + + const glm::uvec4 texture_toggle = + glm::uvec4(material->GetAmbientTexture() != nullptr ? 1u : 0u, + material->GetDiffuseTexture() != nullptr ? 1u : 0u, + material->GetSpecularTexture() != nullptr ? 1u : 0u, 0u); + if (material->GetAmbientTexture()) + shader_program_->set_uniform_handle( + shader_program_->uniform_location("material.ambient_tex"), + gl::texture_handle(*material->GetAmbientTexture())); + if (material->GetDiffuseTexture()) + shader_program_->set_uniform_handle( + shader_program_->uniform_location("material.diffuse_tex"), + gl::texture_handle(*material->GetDiffuseTexture())); + if (material->GetSpecularTexture()) + shader_program_->set_uniform_handle( + shader_program_->uniform_location("material.specular_tex"), + gl::texture_handle(*material->GetSpecularTexture())); + shader_program_->SetUniform("material.texture_toggle", texture_toggle); - shader_program_->SetUniform("material.ambient", ambient_color); - shader_program_->SetUniform("material.diffuse", diffuse_color); - shader_program_->SetUniform("material.specular", specular_color); - shader_program_->SetUniform("material.shininess", shininess); + shader_program_->SetUniform("material.ambient", material->GetAmbientColor()); + shader_program_->SetUniform("material.diffuse", material->GetDiffuseColor()); + shader_program_->SetUniform("material.specular", + material->GetSpecularColor()); + shader_program_->SetUniform("material.shininess", material->GetShininess()); } bool GeometryPass::IsValid() const { diff --git a/library/phx/rendering/render_passes/geometry_pass.hpp b/library/phx/rendering/render_passes/geometry_pass.hpp index 0b2104f103ee0ffa9a0ce2afd147d89630c36862..a02733159fc998a2b8547c5565932bbf118e1203 100644 --- a/library/phx/rendering/render_passes/geometry_pass.hpp +++ b/library/phx/rendering/render_passes/geometry_pass.hpp @@ -41,6 +41,7 @@ SUPPRESS_WARNINGS_END #include "phx/rendering/backend/shader_program.hpp" #include "phx/rendering/components/light.hpp" #include "phx/rendering/components/material_handle.hpp" +#include "phx/rendering/components/mesh_render_settings.hpp" #include "phx/rendering/components/projection.hpp" #include "phx/rendering/components/transform.hpp" #include "phx/rendering/render_passes/render_pass.hpp" @@ -62,7 +63,7 @@ class PHOENIX_EXPORT GeometryPass : public RenderPass { Mesh* mesh = nullptr; Material* material = nullptr; Transform* transform = nullptr; - bool wireframe_mode = false; + MeshRenderSettings* mesh_render_settings = nullptr; }; struct RenderOffset { std::size_t vertex_offset; @@ -118,7 +119,7 @@ class PHOENIX_EXPORT GeometryPass : public RenderPass { const glm::mat4& view_matrix, const glm::mat4& projection_matrix); void SetLightShaderUniforms(); - void SetMaterialShaderUniforms(Material* material); + void SetMaterialShaderUniforms(const Material* material); std::unique_ptr<ShaderProgram> shader_program_; diff --git a/library/phx/rendering/rendering_system.cpp b/library/phx/rendering/rendering_system.cpp index bf4ea619bdfdc7660b2ddd95736d9c309a4061d8..78362871ef1b8b0e84f38fe4b3e414d0d0c86fe2 100644 --- a/library/phx/rendering/rendering_system.cpp +++ b/library/phx/rendering/rendering_system.cpp @@ -22,24 +22,20 @@ #include "phx/rendering/rendering_system.hpp" -#include <iostream> #include <memory> #include <string> -#include <tuple> #include <utility> #include <vector> #include "phx/core/engine.hpp" #include "phx/core/logger.hpp" -#include "phx/core/runtime_component.hpp" #include "phx/core/scene.hpp" #include "phx/core/system.hpp" #include "phx/rendering/components/light.hpp" #include "phx/rendering/components/material_handle.hpp" #include "phx/rendering/components/mesh_handle.hpp" -#include "phx/rendering/components/projection.hpp" +#include "phx/rendering/components/mesh_render_settings.hpp" #include "phx/rendering/components/transform.hpp" -#include "phx/resources/types/mesh.hpp" #include "gl/opengl.hpp" @@ -79,14 +75,15 @@ void RenderingSystem::Update(const FrameTimer::TimeInfo&) { auto light = entity->GetFirstComponent<Light>(); auto transform = entity->GetFirstComponent<Transform>(); auto material_handle = entity->GetFirstComponent<MaterialHandle>(); + Material* material = nullptr; + if (material_handle != nullptr) + material = material_handle->GetMaterial().Get(); + auto mesh_render_settings = entity->GetFirstComponent<MeshRenderSettings>(); + if (transform != nullptr) { if (mesh_handle != nullptr) { - Material* material = nullptr; - if (material_handle != nullptr) - material = material_handle->GetMaterial().Get(); rendering_instances.push_back({mesh_handle->GetMesh().Get(), material, - transform, - mesh_handle->GetWireframeMode()}); + transform, mesh_render_settings}); } else if (light != nullptr) { light_transform_pairs.push_back( std::pair<Light*, Transform*>(light, transform)); diff --git a/library/phx/rendering/rendering_system.hpp b/library/phx/rendering/rendering_system.hpp index e33def770c5e7d7c64b7c6bb0ae97e7f1460fe3f..e0fad0bd36fc21c77b715afca7502e6ad2f093c8 100644 --- a/library/phx/rendering/rendering_system.hpp +++ b/library/phx/rendering/rendering_system.hpp @@ -32,10 +32,10 @@ #include "phx/core/scene.hpp" #include "phx/core/system.hpp" #include "phx/display/display_system.hpp" +#include "phx/export.hpp" #include "phx/rendering/backend/render_target.hpp" -#include "phx/rendering/render_passes/geometry_pass.hpp" #include "phx/rendering/frame_graph.hpp" -#include "phx/export.hpp" +#include "phx/rendering/render_passes/geometry_pass.hpp" namespace phx { diff --git a/library/phx/resources/types/material.cpp b/library/phx/resources/types/material.cpp index f79e5d332942b63f933ddc00235cb201fe4e8d06..cf0b925a2b12089a464e9910b295ad9bf89fcf69 100644 --- a/library/phx/resources/types/material.cpp +++ b/library/phx/resources/types/material.cpp @@ -32,6 +32,7 @@ namespace phx { const char Material::UNNAMED[] = "UnnamedMaterial"; +const Material Material::default_material_; glm::vec3 Material::GetDiffuseColor() const { return diffuse_color_; } void Material::SetDiffuseColor(glm::vec3 color) { diffuse_color_ = color; } @@ -41,11 +42,10 @@ ResourcePointer<Image> Material::GetDiffuseImage() const { } void Material::SetDiffuseImage(ResourcePointer<Image> image) { diffuse_image_ = image; + SetTexture(diffuse_image_, &diffuse_texture_); } -gl::texture_2d* Material::GetDiffuseTexture() { - if (diffuse_image_ && !diffuse_texture_) - SetTexture(diffuse_image_, &diffuse_texture_); +gl::texture_2d* Material::GetDiffuseTexture() const { return diffuse_texture_.get(); } @@ -57,11 +57,10 @@ ResourcePointer<Image> Material::GetAmbientImage() const { } void Material::SetAmbientImage(ResourcePointer<Image> image) { ambient_image_ = image; + SetTexture(ambient_image_, &ambient_texture_); } -gl::texture_2d* Material::GetAmbientTexture() { - if (ambient_image_ && !ambient_texture_) - SetTexture(ambient_image_, &ambient_texture_); +gl::texture_2d* Material::GetAmbientTexture() const { return ambient_texture_.get(); } @@ -73,11 +72,10 @@ ResourcePointer<Image> Material::GetSpecularImage() const { } void Material::SetSpecularImage(ResourcePointer<Image> image) { specular_image_ = image; + SetTexture(specular_image_, &specular_texture_); } -gl::texture_2d* Material::GetSpecularTexture() { - if (specular_image_ && !specular_texture_) - SetTexture(specular_image_, &specular_texture_); +gl::texture_2d* Material::GetSpecularTexture() const { return specular_texture_.get(); } @@ -93,6 +91,8 @@ void Material::SetShininess(float shininess) { } } +const Material* Material::GetDefault() { return &default_material_; } + void Material::SetTexture(ResourcePointer<Image> image, std::shared_ptr<gl::texture_2d>* texture) { if (image == nullptr) return; diff --git a/library/phx/resources/types/material.hpp b/library/phx/resources/types/material.hpp index 557dbfc01397270ac47f926fec0be7a2d4f663ed..ae74ee21dba19043c2478ae9a31cc2237e009b3b 100644 --- a/library/phx/resources/types/material.hpp +++ b/library/phx/resources/types/material.hpp @@ -35,11 +35,11 @@ SUPPRESS_WARNINGS_BEGIN #include "glm/vec3.hpp" SUPPRESS_WARNINGS_END +#include "phx/export.hpp" #include "phx/resources/resource.hpp" #include "phx/resources/resource_pointer.hpp" #include "phx/resources/types/image.hpp" #include "phx/utility/aspects/nameable.hpp" -#include "phx/export.hpp" namespace phx { @@ -62,28 +62,27 @@ class PHOENIX_EXPORT Material : public Resource, public Nameable { ResourcePointer<Image> GetDiffuseImage() const; void SetDiffuseImage(ResourcePointer<Image> image); - - gl::texture_2d* GetDiffuseTexture(); + gl::texture_2d* GetDiffuseTexture() const; glm::vec3 GetAmbientColor() const; void SetAmbientColor(glm::vec3 color); ResourcePointer<Image> GetAmbientImage() const; void SetAmbientImage(ResourcePointer<Image> image); - - gl::texture_2d* GetAmbientTexture(); + gl::texture_2d* GetAmbientTexture() const; glm::vec3 GetSpecularColor() const; void SetSpecularColor(glm::vec3 color); ResourcePointer<Image> GetSpecularImage() const; void SetSpecularImage(ResourcePointer<Image> image); - - gl::texture_2d* GetSpecularTexture(); + gl::texture_2d* GetSpecularTexture() const; float GetShininess() const; void SetShininess(float shininess); + static const Material* GetDefault(); + private: void SetTexture(ResourcePointer<Image> image, std::shared_ptr<gl::texture_2d>* texture); @@ -97,7 +96,9 @@ class PHOENIX_EXPORT Material : public Resource, public Nameable { glm::vec3 ambient_color_ = glm::vec3(0, 0, 0); glm::vec3 diffuse_color_ = glm::vec3(1, 0, 0); glm::vec3 specular_color_ = glm::vec3(1, 1, 1); - float shininess_ = 1.0f; + float shininess_ = 64.0f; + + static const Material default_material_; }; } // namespace phx diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7e68360a7efe9d70afddbf46ca842808a3cb6af5..f63ed905d8e76ba508e35cf4c75092d0c56031d9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -173,67 +173,26 @@ add_test_cpplint(NAME "phoenix-tests--cpplint" # specified via AUTOREMOVE_MOCKED_TEST_SOURCE_FROM autoremove_mocked_test_source_from(${PHOENIX_TEST_SOURCES}) -add_mocked_test(test_clear_pass - LIBRARIES phoenix - MOCKS opengl_mock -) -add_mocked_test(test_input_system - LIBRARIES phoenix - MOCKS openvr_mock sdl_mock -) -add_mocked_test(test_geometry_pass - LIBRARIES phoenix test_utilities - MOCKS opengl_mock sdl_mock -) -add_mocked_test(test_rendering_system - LIBRARIES phoenix - MOCKS opengl_mock sdl_mock -) -add_mocked_test(test_shader - LIBRARIES phoenix - MOCKS opengl_mock -) -add_mocked_test(test_display_system - LIBRARIES phoenix - MOCKS sdl_mock -) -add_mocked_test(test_engine - LIBRARIES phoenix test_utilities - MOCKS opengl_mock openvr_mock sdl_mock -) -add_mocked_test(test_tracking_system - LIBRARIES phoenix test_utilities - MOCKS openvr_mock sdl_mock -) -add_mocked_test(test_openvr_controller_model_system - LIBRARIES phoenix - MOCKS opengl_mock openvr_mock sdl_mock -) -add_mocked_test(test_tracked_device - LIBRARIES phoenix - MOCKS openvr_mock -) -add_mocked_test(test_vr_controller - LIBRARIES phoenix test_utilities - MOCKS openvr_mock -) +add_mocked_test(test_clear_pass LIBRARIES phoenix MOCKS opengl_mock) +add_mocked_test(test_input_system LIBRARIES phoenix MOCKS openvr_mock sdl_mock) +add_mocked_test(test_geometry_pass LIBRARIES phoenix test_utilities MOCKS opengl_mock sdl_mock) +add_mocked_test(test_rendering_system LIBRARIES phoenix MOCKS opengl_mock sdl_mock) +add_mocked_test(test_shader LIBRARIES phoenix MOCKS opengl_mock) +add_mocked_test(test_display_system LIBRARIES phoenix MOCKS sdl_mock) +add_mocked_test(test_engine LIBRARIES phoenix test_utilities MOCKS opengl_mock openvr_mock sdl_mock) +add_mocked_test(test_tracking_system LIBRARIES phoenix test_utilities MOCKS openvr_mock sdl_mock) +add_mocked_test(test_openvr_controller_model_system LIBRARIES phoenix MOCKS opengl_mock openvr_mock sdl_mock) +add_mocked_test(test_tracked_device LIBRARIES phoenix MOCKS openvr_mock) +add_mocked_test(test_vr_controller LIBRARIES phoenix test_utilities MOCKS openvr_mock) +add_mocked_test(test_assimp_loader LIBRARIES phoenix test_utilities MOCKS opengl_mock) +add_mocked_test(test_model LIBRARIES phoenix MOCKS opengl_mock) +add_mocked_test(test_scene_loader LIBRARIES phoenix MOCKS opengl_mock) + +add_mocked_test(integration_test_model_rendering LIBRARIES phoenix test_utilities MOCKS openvr_mock) +add_mocked_test(integration_test_opengl_buffer_data_download LIBRARIES phoenix test_utilities MOCKS openvr_mock) +add_mocked_test(integration_test_rendering LIBRARIES phoenix test_utilities MOCKS openvr_mock) +add_mocked_test(integration_test_hmd LIBRARIES phoenix test_utilities MOCKS openvr_mock) -add_mocked_test(integration_test_model_rendering - LIBRARIES phoenix test_utilities - MOCKS openvr_mock -) -add_mocked_test(integration_test_opengl_buffer_data_download - LIBRARIES phoenix test_utilities - MOCKS openvr_mock -) -add_mocked_test(integration_test_rendering - LIBRARIES phoenix test_utilities - MOCKS openvr_mock -) -add_mocked_test(integration_test_hmd - LIBRARIES phoenix test_utilities - MOCKS openvr_mock -) get_unmocked_test_sources(PHOENIX_TEST_SOURCES) @@ -246,3 +205,4 @@ add_tests(NAME "phoenix-tests" LIBRARIES phoenix test_utilities PATH_TO_ADD ${PROJECT_BINARY_DIR}/library ) + diff --git a/tests/reference_images/model_loading_wireframe.png b/tests/reference_images/model_loading_wireframe.png new file mode 100644 index 0000000000000000000000000000000000000000..fba84750d93e4e9dda237e96dd0ab6004e07d5dd --- /dev/null +++ b/tests/reference_images/model_loading_wireframe.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:79ea2093c78aa11360295e2ee16ffa2f815ccd2e9f9e79ab5a06a29ef895564a +size 105684 diff --git a/tests/reference_images/triangle_without_material.png b/tests/reference_images/triangle_without_material.png index f93066742c9359d414787cbafdc31031d11f80eb..b5eb2e6a885ae9e371ef92880dfb74a9e9e0df68 100644 --- a/tests/reference_images/triangle_without_material.png +++ b/tests/reference_images/triangle_without_material.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cdf28b3e240057f66ad3e4323c1ffd5aa7200bd6708a1d8d0476ff9c5a6eae22 -size 3859 +oid sha256:dfcd770371589244e01ed9ac2a85fc9e113d4b96383901dcca61cb6a1038e060 +size 10984 diff --git a/tests/src/integration_test_model_rendering.cpp b/tests/src/integration_test_model_rendering.cpp index 729b5fc573b4f15c65d316a35ddfa63b460fc17c..39761c2ea606701292d9b3c2a9653c5fdc14f45b 100644 --- a/tests/src/integration_test_model_rendering.cpp +++ b/tests/src/integration_test_model_rendering.cpp @@ -27,18 +27,18 @@ #include "phx/suppress_warnings.hpp" -#include "phx/resources/loaders/assimp_model_loader.hpp" +#include "phx/core/frame_timer.hpp" +#include "phx/core/scene.hpp" #include "phx/display/display_system_window.hpp" #include "phx/display/window.hpp" -#include "phx/core/frame_timer.hpp" #include "phx/rendering/backend/opengl_image_buffer_data.hpp" #include "phx/rendering/components/mesh_handle.hpp" +#include "phx/rendering/components/mesh_render_settings.hpp" #include "phx/rendering/rendering_system.hpp" -#include "phx/resources/types/mesh.hpp" -#include "phx/resources/resource_declaration.hpp" +#include "phx/resources/loaders/assimp_model_loader.hpp" #include "phx/resources/resource_manager.hpp" #include "phx/resources/resource_utils.hpp" -#include "phx/core/scene.hpp" +#include "phx/resources/types/mesh.hpp" #include "phx/setup.hpp" #include "test_utilities/opengl_buffer_data_comparison.hpp" @@ -134,7 +134,7 @@ SCENARIO( "If no light and camera are give the model rendering takes default values", "[phx][phx::ModelLoading]") { ALLOW_CALL(openvr_mock.Get(), VR_IsHmdPresent()).RETURN(false); - GIVEN("A complete scene with two differently colored bunnies.") { + GIVEN("A complete scene with a bunny") { std::unique_ptr<phx::Engine> engine = phx::Setup::CreateDefaultEngine(); auto scene = engine->GetScene(); @@ -158,4 +158,34 @@ SCENARIO( } } +SCENARIO("We can render meshes as wireframe.", + "[phx][phx::MeshRenderSettings]") { + ALLOW_CALL(openvr_mock.Get(), VR_IsHmdPresent()).RETURN(false); + GIVEN("A complete scene with a bunny") { + std::unique_ptr<phx::Engine> engine = phx::Setup::CreateDefaultEngine(); + auto scene = engine->GetScene(); + + auto bunny = + LoadBunny(glm::vec3(0.0f, -0.1f, -0.3f), 0.0f, "bunny", scene.get()); + + auto rendering_system = engine->GetSystem<phx::RenderingSystem>(); + auto display_system = engine->GetSystem<phx::DisplaySystemWindow>(); + + WHEN("We set the rendering to be done in wireframe") { + auto render_settings = bunny->AddComponent<phx::MeshRenderSettings>(); + render_settings->SetWireframeMode(true); + THEN("the rendering matches our reference image") { + rendering_system->Update(phx::FrameTimer::TimeInfo{}); + display_system->Update(phx::FrameTimer::TimeInfo()); + phx::OpenGLImageBufferData<phx::OpenGLImageBufferDataType_RGB> buffer( + 1024, 768); + buffer.ReadColorPixels(true); + test_utilities::OpenGLBufferComparison:: + REQUIRE_REFERENCE_IMAGE_SIMILARITY( + buffer, "model_loading_wireframe.png", 1.0); + } + } + } +} + SUPPRESS_WARNINGS_END diff --git a/tests/src/integration_test_rendering.cpp b/tests/src/integration_test_rendering.cpp index 0d23dbd4216219d241ce3bc04aa5ebfd669e6d2d..dc65452c9256e81044b58ec3bb43507187e28de0 100644 --- a/tests/src/integration_test_rendering.cpp +++ b/tests/src/integration_test_rendering.cpp @@ -35,8 +35,8 @@ #include "phx/rendering/backend/opengl_image_buffer_data.hpp" #include "phx/rendering/components/mesh_handle.hpp" #include "phx/rendering/rendering_system.hpp" -#include "phx/resources/types/mesh.hpp" #include "phx/resources/resource_manager.hpp" +#include "phx/resources/types/mesh.hpp" #include "phx/setup.hpp" SUPPRESS_WARNINGS_BEGIN diff --git a/tests/src/test_assimp_loader.cpp b/tests/src/test_assimp_loader.cpp index 16626f0aa7b5c5dc8cf2f39d99cee75eea8f4fc9..9711390663d673f35d6679ec15e424b86642a565 100644 --- a/tests/src/test_assimp_loader.cpp +++ b/tests/src/test_assimp_loader.cpp @@ -26,14 +26,18 @@ #include "catch/catch.hpp" +#include "mocks/opengl_mock.hpp" + #include "phx/core/logger.hpp" -#include "phx/resources/types/mesh.hpp" #include "phx/resources/loaders/assimp_model_loader.hpp" #include "phx/resources/resource_utils.hpp" +#include "phx/resources/types/mesh.hpp" #include "phx/utility/aspects/nameable.hpp" #include "test_utilities/log_capture.hpp" +extern template struct trompeloeil::reporter<trompeloeil::specialized>; + class TestLogger { public: TestLogger() : log_capture_{std::make_shared<test_utilities::LogCapture>()} { @@ -49,6 +53,7 @@ class TestLogger { SCENARIO("The assimp loader loads models using the Assimp library.", "[phx][phx::AssimpLoader]") { + OPENGL_MOCK_ALLOW_ANY_CALL GIVEN("A plain loader") { phx::CreateDefaultLogger(); TestLogger test_logger; diff --git a/tests/src/test_material.cpp b/tests/src/test_material.cpp index 34f0552562a062641b060f9d222b54c5058fecda..843bd61e2fde6e39861566ecc0735b02ce29e633 100644 --- a/tests/src/test_material.cpp +++ b/tests/src/test_material.cpp @@ -42,7 +42,7 @@ SCENARIO("The material component keeps track of its attributes", REQUIRE(material.GetAmbientColor() == glm::vec3(0, 0, 0)); REQUIRE(material.GetSpecularColor() == glm::vec3(1, 1, 1)); REQUIRE(material.GetDiffuseColor() == glm::vec3(1, 0, 0)); - REQUIRE(material.GetShininess() == 1.0f); + REQUIRE(material.GetShininess() == 64.0f); } WHEN("we assign it to be some other material") { glm::vec3 blue(0, 0, 1), white(1, 1, 1), green(0, 1, 0); diff --git a/tests/src/test_model.cpp b/tests/src/test_model.cpp index 7098d7ca52f01c7dec6872d7a815ff80aee976b3..883d5e3b09fff45fb85c2f552b266b76073d4cdd 100644 --- a/tests/src/test_model.cpp +++ b/tests/src/test_model.cpp @@ -25,12 +25,18 @@ #include "catch/catch.hpp" #include "phx/resources/loaders/assimp_model_loader.hpp" -#include "phx/resources/types/model.hpp" #include "phx/resources/resource_manager.hpp" #include "phx/resources/resource_utils.hpp" +#include "phx/resources/types/model.hpp" + +#include "mocks/opengl_mock.hpp" +#include "trompeloeil.hpp" + +extern template struct trompeloeil::reporter<trompeloeil::specialized>; SCENARIO("A Model can be loaded that contains multiple meshes", "[phx][phx::Model]") { + OPENGL_MOCK_ALLOW_ANY_CALL GIVEN("A fresh resource manager...") { GIVEN("A file name of an .obj file...") { std::string model_file_name{"models/2MeshTest/2meshTest.obj"}; diff --git a/tests/src/test_scene_loader.cpp b/tests/src/test_scene_loader.cpp index 1e69d84c692c57071f22d50d69d4df46bfe838d0..fefb838b4ec2a5fc8a0fd742f22ce9d624b754b9 100644 --- a/tests/src/test_scene_loader.cpp +++ b/tests/src/test_scene_loader.cpp @@ -30,7 +30,13 @@ #include "phx/rendering/components/transform.hpp" #include "phx/resources/loaders/scene_loader.hpp" +#include "mocks/opengl_mock.hpp" +#include "trompeloeil.hpp" + +extern template struct trompeloeil::reporter<trompeloeil::specialized>; + SCENARIO("The scene loader can load a model", "[phx][phx::SceneLoader]") { + OPENGL_MOCK_ALLOW_ANY_CALL GIVEN("An empty scene") { phx::Scene scene; WHEN("We load a model into the scene") {