diff --git a/examples/render/06-test-texcoords/CMakeLists.txt b/examples/render/06-test-texcoords/CMakeLists.txt new file mode 100644 index 000000000..87cd054b8 --- /dev/null +++ b/examples/render/06-test-texcoords/CMakeLists.txt @@ -0,0 +1,37 @@ +#***************************************************************************** +#* VCLib * +#* Visual Computing Library * +#* * +#* Copyright(C) 2021-2025 * +#* Visual Computing Lab * +#* ISTI - Italian National Research Council * +#* * +#* All rights reserved. * +#* * +#* This program is free software; you can redistribute it and/or modify * +#* it under the terms of the Mozilla Public License Version 2.0 as published * +#* by the Mozilla Foundation; either version 2 of the License, or * +#* (at your option) any later version. * +#* * +#* This program is distributed in the hope that it will be useful, * +#* but WITHOUT ANY WARRANTY; without even the implied warranty of * +#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +#* Mozilla Public License Version 2.0 * +#* (https://www.mozilla.org/en-US/MPL/2.0/) for more details. * +#****************************************************************************/ + +cmake_minimum_required(VERSION 3.24) + +set(EXAMPLE_NAME 06-test-texcoords) +project(vclib-render-example-${EXAMPLE_NAME}) + +### Build settings +set(CMAKE_CXX_STANDARD 20) + +set(SOURCES + main.cpp) + +# will create a target called 'vclib-render-example-${EXAMPLE_NAME}' +vclib_add_example(${EXAMPLE_NAME} + VCLIB_MODULE render + SOURCES ${SOURCES}) diff --git a/examples/render/06-test-texcoords/main.cpp b/examples/render/06-test-texcoords/main.cpp new file mode 100644 index 000000000..9b4a37266 --- /dev/null +++ b/examples/render/06-test-texcoords/main.cpp @@ -0,0 +1,67 @@ +/***************************************************************************** + * VCLib * + * Visual Computing Library * + * * + * Copyright(C) 2021-2025 * + * Visual Computing Lab * + * ISTI - Italian National Research Council * + * * + * All rights reserved. * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the Mozilla Public License Version 2.0 as published * + * by the Mozilla Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * Mozilla Public License Version 2.0 * + * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. * + ****************************************************************************/ + +#include +#include + +#include + +#include + +int main(int argc, char** argv) +{ +#if VCLIB_RENDER_EXAMPLES_WITH_QT + QApplication application(argc, argv); +#endif + + auto viewer = defaultViewer(); + + const bool TEXCOORDS_PER_VERTEX = false; + + if (TEXCOORDS_PER_VERTEX) { + vcl::DrawableMesh drawable = + getDrawableMesh("VertTextureDouble.ply"); + auto mrs = drawable.renderSettings(); + mrs.setSurfaceShadingFlat(); + mrs.setSurfaceColorPerVertexTexcoords(); + drawable.setRenderSettings(mrs); + showMeshesOnViewer(argc, argv, viewer, drawable); + } + else { + vcl::DrawableMesh drawable = + getDrawableMesh("TextureDouble.ply"); + auto mrs = drawable.renderSettings(); + mrs.setSurfaceShadingFlat(); + mrs.setSurfaceColorPerWedgeTexcoords(); + drawable.setRenderSettings(mrs); + showMeshesOnViewer(argc, argv, viewer, drawable); + } + +#if VCLIB_RENDER_EXAMPLES_WITH_QT + viewer.showMaximized(); + return application.exec(); +#else + (void) argc; // unused + (void) argv; + return 0; +#endif +} diff --git a/examples/render/CMakeLists.txt b/examples/render/CMakeLists.txt index d0e710970..b20312646 100644 --- a/examples/render/CMakeLists.txt +++ b/examples/render/CMakeLists.txt @@ -56,6 +56,8 @@ endif() add_subdirectory(999-misc) if (CAN_BUILD_VCLIB_EXAMPLES) + add_subdirectory(06-test-texcoords) + # the following examples are the same of the ones in the core module, # but they add a viewer at the end in order to visualize the results add_subdirectory(9015-mesh-io-stl) diff --git a/examples/render/common/default_viewer.h b/examples/render/common/default_viewer.h index 1a420fddd..34c4cc784 100644 --- a/examples/render/common/default_viewer.h +++ b/examples/render/common/default_viewer.h @@ -24,6 +24,7 @@ #define VCLIB_RENDER_EXAMPLES_COMMON_DEFAULT_VIEWER_H #include +#include #if VCLIB_RENDER_EXAMPLES_WITH_QT #include @@ -37,23 +38,37 @@ #include #endif -template -int showMeshesOnDefaultViewer(int argc, char** argv, const MeshTypes&... meshes) +template +void pushMeshOnVector( + std::shared_ptr& vector, + const MeshType& mesh) { -#if VCLIB_RENDER_EXAMPLES_WITH_QT - QApplication application(argc, argv); -#endif + if constexpr (vcl::DrawableObjectConcept) + vector->pushBack(mesh); + else + vector->pushBack(vcl::DrawableMesh(mesh)); +} +auto defaultViewer() +{ #ifdef VCLIB_RENDER_EXAMPLES_WITH_QT - vcl::qt::MeshViewer viewer; + return vcl::qt::MeshViewer(); #elif VCLIB_RENDER_EXAMPLES_WITH_GLFW - vcl::glfw::ViewerWindow viewer; + return vcl::glfw::ViewerWindow ; #endif +} +template +void showMeshesOnViewer( + int argc, + char** argv, + auto& viewer, + const MeshTypes&... meshes) +{ std::shared_ptr vector = std::make_shared(); - (vector->pushBack(vcl::DrawableMesh(meshes)), ...); + (pushMeshOnVector(vector, meshes), ...); viewer.setDrawableObjectVector(vector); @@ -62,6 +77,22 @@ int showMeshesOnDefaultViewer(int argc, char** argv, const MeshTypes&... meshes) #endif viewer.show(); +} + +template +int showMeshesOnDefaultViewer(int argc, char** argv, const MeshTypes&... meshes) +{ +#if VCLIB_RENDER_EXAMPLES_WITH_QT + QApplication application(argc, argv); +#endif + +#ifdef VCLIB_RENDER_EXAMPLES_WITH_QT + vcl::qt::MeshViewer viewer; +#elif VCLIB_RENDER_EXAMPLES_WITH_GLFW + vcl::glfw::ViewerWindow viewer; +#endif + + showMeshesOnViewer(argc, argv, viewer, meshes...); #if VCLIB_RENDER_EXAMPLES_WITH_QT viewer.showMaximized(); diff --git a/tests/render/000-static-asserts/CMakeLists.txt b/tests/render/000-static-asserts/CMakeLists.txt index 6ed05f85b..3520e6ae6 100644 --- a/tests/render/000-static-asserts/CMakeLists.txt +++ b/tests/render/000-static-asserts/CMakeLists.txt @@ -26,6 +26,7 @@ set(TEST_NAME 000-static-asserts) project(vclib-test-${TEST_NAME}) set(HEADERS + drawable_object.h canvas.h drawers.h render_app.h diff --git a/tests/render/000-static-asserts/drawable_object.h b/tests/render/000-static-asserts/drawable_object.h new file mode 100644 index 000000000..acda9f463 --- /dev/null +++ b/tests/render/000-static-asserts/drawable_object.h @@ -0,0 +1,51 @@ +/***************************************************************************** + * VCLib * + * Visual Computing Library * + * * + * Copyright(C) 2021-2025 * + * Visual Computing Lab * + * ISTI - Italian National Research Council * + * * + * All rights reserved. * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the Mozilla Public License Version 2.0 as published * + * by the Mozilla Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * Mozilla Public License Version 2.0 * + * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. * + ****************************************************************************/ + +#ifndef DRAWABLE_OBJECT_H +#define DRAWABLE_OBJECT_H + +#include +#include +#include + +void drawableObjectStaticAsserts() +{ + using namespace vcl; + + static_assert( + DrawableObjectConcept>, + "DrawableMesh does not satisfy the DrawableObjectConcept"); + static_assert( + DrawableObjectConcept>, + "const DrawableMesh does not satisfy the DrawableObjectConcept"); + static_assert( + DrawableObjectConcept&>, + "DrawableMesh& does not satisfy the DrawableObjectConcept"); + static_assert( + DrawableObjectConcept&>, + "const DrawableMesh& does not satisfy the DrawableObjectConcept"); + static_assert( + DrawableObjectConcept&&>, + "DrawableMesh&& does not satisfy the DrawableObjectConcept"); +} + +#endif // DRAWABLE_OBJECT_H diff --git a/tests/render/000-static-asserts/main.cpp b/tests/render/000-static-asserts/main.cpp index 39402511f..28cb1dd17 100644 --- a/tests/render/000-static-asserts/main.cpp +++ b/tests/render/000-static-asserts/main.cpp @@ -21,6 +21,7 @@ ****************************************************************************/ #include "canvas.h" +#include "drawable_object.h" #include "drawers.h" #include "render_app.h" #include "window_manager.h" @@ -28,6 +29,7 @@ int main() { canvasStaticAsserts(); + drawableObjectStaticAsserts(); drawersStaticAsserts(); renderAppStaticAsserts(); windowManagerStaticAsserts(); diff --git a/vclib/render/include/vclib/bgfx/drawable/drawable_mesh.h b/vclib/render/include/vclib/bgfx/drawable/drawable_mesh.h index fbd77baa3..d810a5718 100644 --- a/vclib/render/include/vclib/bgfx/drawable/drawable_mesh.h +++ b/vclib/render/include/vclib/bgfx/drawable/drawable_mesh.h @@ -47,6 +47,8 @@ class DrawableMeshBGFX : public AbstractDrawableMesh, public MeshType mutable MeshRenderSettingsUniforms mMeshRenderSettingsUniforms; public: + using AbstractDrawableMesh::name; + DrawableMeshBGFX() = default; DrawableMeshBGFX(const MeshType& mesh) : diff --git a/vclib/render/include/vclib/render/concepts/drawable_object.h b/vclib/render/include/vclib/render/concepts/drawable_object.h new file mode 100644 index 000000000..f2de09ce9 --- /dev/null +++ b/vclib/render/include/vclib/render/concepts/drawable_object.h @@ -0,0 +1,50 @@ +/***************************************************************************** + * VCLib * + * Visual Computing Library * + * * + * Copyright(C) 2021-2025 * + * Visual Computing Lab * + * ISTI - Italian National Research Council * + * * + * All rights reserved. * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the Mozilla Public License Version 2.0 as published * + * by the Mozilla Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * Mozilla Public License Version 2.0 * + * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. * + ****************************************************************************/ + +#ifndef VCL_RENDER_CONCEPTS_DRAWABLE_OBJECT_H +#define VCL_RENDER_CONCEPTS_DRAWABLE_OBJECT_H + +#include + +namespace vcl { + +template +concept DrawableObjectConcept = requires (T&& obj, uint u) { + { obj.draw(u) } -> std::same_as; + { obj.boundingBox() } -> Box3Concept; + obj.clone(); + { obj.isVisible() } -> std::same_as; + { obj.name() } -> std::convertible_to; + { obj.info() } -> std::convertible_to; + + // non const requirements + requires IsConst || requires { + { obj.init() } -> std::same_as; + { obj.setVisibility(bool()) } -> std::same_as; + { obj.name() } -> std::same_as; + { obj.info() } -> std::same_as; + }; +}; + +} // namespace vcl + +#endif // VCL_RENDER_CONCEPTS_DRAWABLE_OBJECT_H