diff --git a/library/phx/core/component.hpp b/library/phx/core/component.hpp index 67261e88dd0cc248a1074b8f228b70cbd71bbd16..e80fdc571ef93fb294bd122e5ca414d4a37d79dc 100644 --- a/library/phx/core/component.hpp +++ b/library/phx/core/component.hpp @@ -45,10 +45,10 @@ class PHOENIX_EXPORT Component : public Loggable { protected: Component() = default; - Component(const Component&) = default; + Component(const Component&) = delete; Component(Component&&) = default; - Component& operator=(const Component&) = default; + Component& operator=(const Component&) = delete; Component& operator=(Component&&) = default; private: diff --git a/library/phx/input/openvr_controller_system.cpp b/library/phx/input/openvr_controller_system.cpp index e30451dced18cc2bcedfe56c8c3a5c02efbc7bc7..aa92e57998c97dfd0d9a6180c660d2a2ac6a67e2 100644 --- a/library/phx/input/openvr_controller_system.cpp +++ b/library/phx/input/openvr_controller_system.cpp @@ -29,6 +29,7 @@ #include "phx/core/logger.hpp" #include "phx/display/display_system_openvr.hpp" #include "phx/input/openvr_controller_behavior.hpp" +#include "phx/rendering/components/resource_component.hpp" #include "phx/rendering/components/transform.hpp" #include "phx/resources/loaders/openvr_resource_loader.hpp" #include "phx/resources/resource_manager.hpp" @@ -84,9 +85,9 @@ Entity* OpenVRControllerSystem::AddControllerEntity( phx::Scene* scene, ResourcePointer<Mesh> mesh, ResourcePointer<Material> material, OpenVRControllerBehavior::Side side) { Entity* controller = scene->CreateEntity(); - controller->AddComponent<ResourcePointer<Mesh>>(mesh); + controller->AddComponent<ResourceComponent<Mesh>>(mesh); controller->AddComponent<Transform>(); - controller->AddComponent<ResourcePointer<Material>>(material); + controller->AddComponent<ResourceComponent<Material>>(material); controller->AddComponent<OpenVRControllerBehavior>()->SetSide(side); return controller; diff --git a/library/phx/rendering/components/resource_component.cpp b/library/phx/rendering/components/resource_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..507c1974795be55a4fd7c7f64e3b20e1ad656710 --- /dev/null +++ b/library/phx/rendering/components/resource_component.cpp @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// 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/resource_component.hpp" + +#include <string> + +namespace phx { + + +} // namespace phx diff --git a/library/phx/rendering/components/resource_component.hpp b/library/phx/rendering/components/resource_component.hpp new file mode 100644 index 0000000000000000000000000000000000000000..30671dc1579be7fb52f06d7d834adabb52c2ef91 --- /dev/null +++ b/library/phx/rendering/components/resource_component.hpp @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +// 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_RESOURCE_COMPONENT_HPP_ +#define LIBRARY_PHX_RENDERING_COMPONENTS_RESOURCE_COMPONENT_HPP_ + +#include <string> + +#include "phx/core/component.hpp" +#include "phx/export.hpp" +#include "phx/resources/resource_pointer.hpp" + +namespace phx { + +template <class ResourceType> +class PHOENIX_EXPORT ResourceComponent final : public Component { + public: + std::string ToString() const override { return "Resource Pointer Component"; } + + ResourcePointer<ResourceType> GetResourcePointer() { + return resource_pointer_; + } + + void SetResourcePointer(ResourcePointer<ResourceType> pointer) { + resource_pointer_ = pointer; + } + + protected: + friend Entity; + ResourceComponent() = default; + explicit ResourceComponent(ResourcePointer<ResourceType> pointer) + : resource_pointer_(pointer) {} + ResourceComponent(const ResourceComponent&) = delete; + ResourceComponent(ResourceComponent&&) = default; + + ResourceComponent& operator=(const ResourceComponent&) = delete; + ResourceComponent& operator=(ResourceComponent&&) = default; + + private: + ResourcePointer<ResourceType> resource_pointer_; +}; + +} // namespace phx + +#endif // LIBRARY_PHX_RENDERING_COMPONENTS_RESOURCE_COMPONENT_HPP_ diff --git a/library/phx/rendering/rendering_system.cpp b/library/phx/rendering/rendering_system.cpp index fd4bb1cba43ed14cad2c10fa456a38a4952a2210..c10e4201b099320773443875e9c7496c68381612 100644 --- a/library/phx/rendering/rendering_system.cpp +++ b/library/phx/rendering/rendering_system.cpp @@ -32,6 +32,7 @@ #include "phx/core/scene.hpp" #include "phx/core/system.hpp" #include "phx/rendering/components/light.hpp" +#include "phx/rendering/components/resource_component.hpp" #include "phx/rendering/components/transform.hpp" #include "phx/resources/resource_pointer.hpp" #include "phx/resources/types/material.hpp" @@ -74,12 +75,14 @@ void RenderingSystem::Update(const FrameTimer::TimeInfo&) { auto light = entity->GetFirstComponent<Light>(); auto transform = entity->GetFirstComponent<Transform>(); const auto material = - entity->GetFirstComponent<ResourcePointer<Material>>(); - const auto mesh = entity->GetFirstComponent<ResourcePointer<Mesh>>(); + entity->GetFirstComponent<ResourceComponent<Material>>(); + const auto mesh = entity->GetFirstComponent<ResourceComponent<Mesh>>(); if (transform != nullptr) { if (mesh != nullptr) { rendering_instances.push_back( - {mesh->Get(), (material != nullptr ? material->Get() : nullptr), + {mesh->GetResourcePointer().Get(), + (material != nullptr ? material->GetResourcePointer().Get() + : nullptr), transform}); } else if (light != nullptr) { light_transform_pairs.push_back( diff --git a/library/phx/resources/loaders/scene_loader.cpp b/library/phx/resources/loaders/scene_loader.cpp index d8757f07c2fe2b3a9bea0530996cd8afed1ca2bc..0e353229fd657f573346676b28647cc8a851b7a9 100644 --- a/library/phx/resources/loaders/scene_loader.cpp +++ b/library/phx/resources/loaders/scene_loader.cpp @@ -24,6 +24,7 @@ #include <string> +#include "phx/rendering/components/resource_component.hpp" #include "phx/rendering/components/transform.hpp" #include "phx/resources/resource_pointer.hpp" #include "phx/resources/resource_utils.hpp" @@ -47,10 +48,10 @@ bool SceneLoader::InsertModelIntoScene(const std::string& file_name, for (auto mesh : model->GetMeshes()) { auto entity = scene->CreateEntity(); entity->AddComponent<Transform>()->SetParent(root_transform); - entity->AddComponent<ResourcePointer<Mesh>>(mesh); + entity->AddComponent<ResourceComponent<Mesh>>(mesh); ResourcePointer<Material> material = model->GetMaterialForMesh(mesh); if (material != nullptr) { - entity->AddComponent<ResourcePointer<Material>>(material); + entity->AddComponent<ResourceComponent<Material>>(material); } } diff --git a/library/phx/resources/resource_pointer.hpp b/library/phx/resources/resource_pointer.hpp index 02c595041c8eb1bce3c7ebca7f90113ebdc82c61..123f9a569612142f22d55caa82b2260a5c0a4f34 100644 --- a/library/phx/resources/resource_pointer.hpp +++ b/library/phx/resources/resource_pointer.hpp @@ -25,14 +25,13 @@ #include <cstddef> -#include "phx/core/component.hpp" #include "phx/export.hpp" #include "phx/resources/resource_proxy.hpp" namespace phx { template <class ResourceType> -class PHOENIX_EXPORT ResourcePointer : public Component { +class PHOENIX_EXPORT ResourcePointer { public: ResourcePointer() : proxy_(nullptr) {} explicit ResourcePointer(std::nullptr_t) : proxy_(nullptr) {} diff --git a/tests/src/integration_test_model_rendering.cpp b/tests/src/integration_test_model_rendering.cpp index f8ebd5fbb0750a27b3ae487a505fd26b0de7e9d1..28450005f92e25bed56e9fcc8590f5788a347eb3 100644 --- a/tests/src/integration_test_model_rendering.cpp +++ b/tests/src/integration_test_model_rendering.cpp @@ -32,6 +32,7 @@ #include "phx/display/display_system_window.hpp" #include "phx/display/window.hpp" #include "phx/rendering/backend/opengl_image_buffer_data.hpp" +#include "phx/rendering/components/resource_component.hpp" #include "phx/rendering/rendering_system.hpp" #include "phx/resources/loaders/assimp_model_loader.hpp" #include "phx/resources/resource_manager.hpp" @@ -57,11 +58,11 @@ phx::Entity* LoadBunny(glm::vec3 pos, float angleDeg, auto bunny_mesh = phx::ResourceUtils::LoadResourceFromFile<phx::Mesh>( "models/bunny.obj", {{"mesh_index", 0}}); - bunny->AddComponent<phx::ResourcePointer<phx::Mesh>>(bunny_mesh); + bunny->AddComponent<phx::ResourceComponent<phx::Mesh>>(bunny_mesh); auto bunny_material = phx::ResourceUtils::LoadResourceFromFile<phx::Material>( "models/bunny.obj", {{"material_name", material_name}}); - bunny->AddComponent<phx::ResourcePointer<phx::Material>>(bunny_material); + bunny->AddComponent<phx::ResourceComponent<phx::Material>>(bunny_material); phx::Transform* bunny_transform = bunny->AddComponent<phx::Transform>(); bunny_transform->SetLocalTranslation(pos); diff --git a/tests/src/integration_test_opengl_buffer_data_download.cpp b/tests/src/integration_test_opengl_buffer_data_download.cpp index 9e809577ddc4f3514e65429fbf7b9bc417adc5b6..dee66eac99e3ef1b7a9692360b7fd6eb3cf2340a 100644 --- a/tests/src/integration_test_opengl_buffer_data_download.cpp +++ b/tests/src/integration_test_opengl_buffer_data_download.cpp @@ -34,6 +34,7 @@ #include "phx/core/scene.hpp" #include "phx/display/window.hpp" #include "phx/rendering/backend/opengl_image_buffer_data.hpp" +#include "phx/rendering/components/resource_component.hpp" #include "phx/rendering/rendering_system.hpp" #include "phx/resources/resource_manager.hpp" #include "phx/resources/resource_pointer.hpp" @@ -98,7 +99,7 @@ class SceneSetupSimple { {{"TYPE", "custommaterial"}}); material.Load(); - triangle->AddComponent<phx::ResourcePointer<phx::Material>>(material); + triangle->AddComponent<phx::ResourceComponent<phx::Material>>(material); std::vector<glm::vec3> vertices = { {-4.0f, -3.0f, -0.05f}, {4.0f, -3.0f, -0.05f}, {4.0f, 3.0f, -0.05f}}; @@ -114,7 +115,7 @@ class SceneSetupSimple { {{"TYPE", "staticmesh"}}); mesh.Load(); - triangle->AddComponent<phx::ResourcePointer<phx::Mesh>>(mesh); + triangle->AddComponent<phx::ResourceComponent<phx::Mesh>>(mesh); phx::Entity* main_light = scene->CreateEntity(); main_light->AddComponent<phx::Transform>(); diff --git a/tests/src/integration_test_rendering.cpp b/tests/src/integration_test_rendering.cpp index 1783f13ee169356df7f9a67cccafba16edd08e3b..dcb7a9b076e9a1be13dd752dfd430cc8294a9869 100644 --- a/tests/src/integration_test_rendering.cpp +++ b/tests/src/integration_test_rendering.cpp @@ -33,6 +33,7 @@ #include "phx/display/display_system_window.hpp" #include "phx/display/window.hpp" #include "phx/rendering/backend/opengl_image_buffer_data.hpp" +#include "phx/rendering/components/resource_component.hpp" #include "phx/rendering/rendering_system.hpp" #include "phx/resources/resource_manager.hpp" #include "phx/resources/types/mesh.hpp" @@ -88,7 +89,7 @@ void CreateTestTriangleComponent(phx::Entity* triangle) { {{"TYPE", "staticmesh"}}); mesh.Load(); - triangle->AddComponent<phx::ResourcePointer<phx::Mesh>>(mesh); + triangle->AddComponent<phx::ResourceComponent<phx::Mesh>>(mesh); } SUPPRESS_WARNINGS_END @@ -116,7 +117,7 @@ SCENARIO("We can render a simple triangle", "[phx][phx::Rendering]") { material.Load(); triangle->AddComponent<phx::Transform>(); - triangle->AddComponent<phx::ResourcePointer<phx::Material>>(material); + triangle->AddComponent<phx::ResourceComponent<phx::Material>>(material); WHEN("We render the scene") { rendering_system->Update(phx::FrameTimer::TimeInfo{}); diff --git a/tests/src/test_openvr_controller_system.cpp b/tests/src/test_openvr_controller_system.cpp index 0e2a039c24cc67ed07094272656ee4c2bc7fc43f..5a8d237a384ffaf72e1687bb3b59c1ed939d7299 100644 --- a/tests/src/test_openvr_controller_system.cpp +++ b/tests/src/test_openvr_controller_system.cpp @@ -37,6 +37,7 @@ SUPPRESS_WARNINGS_END #include "phx/display/display_system_openvr.hpp" #include "phx/input/openvr_controller_behavior.hpp" #include "phx/input/openvr_controller_system.hpp" +#include "phx/rendering/components/resource_component.hpp" #include "phx/rendering/rendering_system.hpp" #include "mocks/opengl_mock.hpp" @@ -102,12 +103,10 @@ SCENARIO( for (auto entity : controller_entities) { REQUIRE( - entity->GetFirstComponent<phx::ResourcePointer<phx::Mesh>>() != - nullptr); - REQUIRE( - entity - ->GetFirstComponent<phx::ResourcePointer<phx::Material>>() != + entity->GetFirstComponent<phx::ResourceComponent<phx::Mesh>>() != nullptr); + REQUIRE(entity->GetFirstComponent< + phx::ResourceComponent<phx::Material>>() != nullptr); } auto side0 = controller_entities[0] diff --git a/tests/src/test_resource_pointer.cpp b/tests/src/test_resource_pointer.cpp index f5b8ae607f56bee6239c570fe0804ff86f114d54..fd924b1f732d0de930c72fd3fc4193c7c921a1a2 100644 --- a/tests/src/test_resource_pointer.cpp +++ b/tests/src/test_resource_pointer.cpp @@ -23,6 +23,7 @@ #include "catch/catch.hpp" #include "phx/core/entity.hpp" +#include "phx/rendering/components/resource_component.hpp" #include "phx/resources/resource_manager.hpp" #include "phx/resources/resource_pointer.hpp" #include "phx/resources/resource_utils.hpp" @@ -98,14 +99,15 @@ SCENARIO("ResourcePointers can be used as components directly") { auto mesh_resource_pointer = resource_pointer->GetMeshes()[0]; phx::Entity entity; WHEN("We add the mesh_resource_pointer as resource component") { - entity.AddComponent<phx::ResourcePointer<phx::Mesh>>( + entity.AddComponent<phx::ResourceComponent<phx::Mesh>>( mesh_resource_pointer); THEN( "the resouce pointer itself is the resource and can be obtained as " "usual") { auto resource_component = - entity.GetFirstComponent<phx::ResourcePointer<phx::Mesh>>(); - REQUIRE(resource_component->Get() == mesh_resource_pointer.Get()); + entity.GetFirstComponent<phx::ResourceComponent<phx::Mesh>>(); + REQUIRE(resource_component->GetResourcePointer().Get() == + mesh_resource_pointer.Get()); } } } diff --git a/tests/src/test_scene_loader.cpp b/tests/src/test_scene_loader.cpp index ee851ad9072e3a924a0eb0ec9e1d63457dacaaff..807a22be5f1cad2e088943c480b48e5b4631411f 100644 --- a/tests/src/test_scene_loader.cpp +++ b/tests/src/test_scene_loader.cpp @@ -26,6 +26,7 @@ #include "phx/core/entity.hpp" #include "phx/core/scene.hpp" +#include "phx/rendering/components/resource_component.hpp" #include "phx/rendering/components/transform.hpp" #include "phx/resources/loaders/scene_loader.hpp" #include "phx/resources/resource_pointer.hpp" @@ -57,7 +58,7 @@ SCENARIO("The scene loader can load a model", "[phx][phx::SceneLoader]") { nameCounter++; } if (currentEntity - ->GetFirstComponent<phx::ResourcePointer<phx::Mesh>>() != + ->GetFirstComponent<phx::ResourceComponent<phx::Mesh>>() != nullptr) { auto parentEntity = currentEntity->GetFirstComponent<phx::Transform>()