Skip to content

Commit

Permalink
[render] DrawableObjectConcept and test for vertex and wedge textures
Browse files Browse the repository at this point in the history
  • Loading branch information
alemuntoni committed Jan 24, 2025
1 parent 3da1ad1 commit 853efd7
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 8 deletions.
37 changes: 37 additions & 0 deletions examples/render/06-test-texcoords/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
67 changes: 67 additions & 0 deletions examples/render/06-test-texcoords/main.cpp
Original file line number Diff line number Diff line change
@@ -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 <default_viewer.h>
#include <get_drawable_mesh.h>

#include <vclib/qt/viewer_widget.h>

#include <QApplication>

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<vcl::TriMesh> drawable =
getDrawableMesh<vcl::TriMesh>("VertTextureDouble.ply");
auto mrs = drawable.renderSettings();
mrs.setSurfaceShadingFlat();
mrs.setSurfaceColorPerVertexTexcoords();
drawable.setRenderSettings(mrs);
showMeshesOnViewer(argc, argv, viewer, drawable);
}
else {
vcl::DrawableMesh<vcl::TriMesh> drawable =
getDrawableMesh<vcl::TriMesh>("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
}
2 changes: 2 additions & 0 deletions examples/render/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
47 changes: 39 additions & 8 deletions examples/render/common/default_viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define VCLIB_RENDER_EXAMPLES_COMMON_DEFAULT_VIEWER_H

#include <vclib/mesh/requirements.h>
#include <vclib/render/concepts/drawable_object.h>

#if VCLIB_RENDER_EXAMPLES_WITH_QT
#include <QApplication>
Expand All @@ -37,23 +38,37 @@
#include <vclib/render/drawable/drawable_mesh.h>
#endif

template<vcl::MeshConcept... MeshTypes>
int showMeshesOnDefaultViewer(int argc, char** argv, const MeshTypes&... meshes)
template<vcl::MeshConcept MeshType>
void pushMeshOnVector(
std::shared_ptr<vcl::DrawableObjectVector>& vector,
const MeshType& mesh)
{
#if VCLIB_RENDER_EXAMPLES_WITH_QT
QApplication application(argc, argv);
#endif
if constexpr (vcl::DrawableObjectConcept<MeshType>)
vector->pushBack(mesh);
else
vector->pushBack(vcl::DrawableMesh<MeshType>(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<vcl::MeshConcept... MeshTypes>
void showMeshesOnViewer(
int argc,
char** argv,
auto& viewer,
const MeshTypes&... meshes)
{
std::shared_ptr<vcl::DrawableObjectVector> vector =
std::make_shared<vcl::DrawableObjectVector>();

(vector->pushBack(vcl::DrawableMesh<MeshTypes>(meshes)), ...);
(pushMeshOnVector(vector, meshes), ...);

viewer.setDrawableObjectVector(vector);

Expand All @@ -62,6 +77,22 @@ int showMeshesOnDefaultViewer(int argc, char** argv, const MeshTypes&... meshes)
#endif

viewer.show();
}

template<vcl::MeshConcept... MeshTypes>
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();
Expand Down
1 change: 1 addition & 0 deletions tests/render/000-static-asserts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions tests/render/000-static-asserts/drawable_object.h
Original file line number Diff line number Diff line change
@@ -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 <vclib/meshes.h>
#include <vclib/render/concepts/drawable_object.h>
#include <vclib/render/drawable/drawable_mesh.h>

void drawableObjectStaticAsserts()
{
using namespace vcl;

static_assert(
DrawableObjectConcept<DrawableMesh<TriMesh>>,
"DrawableMesh does not satisfy the DrawableObjectConcept");
static_assert(
DrawableObjectConcept<const DrawableMesh<TriMesh>>,
"const DrawableMesh does not satisfy the DrawableObjectConcept");
static_assert(
DrawableObjectConcept<DrawableMesh<TriMesh>&>,
"DrawableMesh& does not satisfy the DrawableObjectConcept");
static_assert(
DrawableObjectConcept<const DrawableMesh<TriMesh>&>,
"const DrawableMesh& does not satisfy the DrawableObjectConcept");
static_assert(
DrawableObjectConcept<DrawableMesh<TriMesh>&&>,
"DrawableMesh&& does not satisfy the DrawableObjectConcept");
}

#endif // DRAWABLE_OBJECT_H
2 changes: 2 additions & 0 deletions tests/render/000-static-asserts/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
****************************************************************************/

#include "canvas.h"
#include "drawable_object.h"
#include "drawers.h"
#include "render_app.h"
#include "window_manager.h"

int main()
{
canvasStaticAsserts();
drawableObjectStaticAsserts();
drawersStaticAsserts();
renderAppStaticAsserts();
windowManagerStaticAsserts();
Expand Down
2 changes: 2 additions & 0 deletions vclib/render/include/vclib/bgfx/drawable/drawable_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class DrawableMeshBGFX : public AbstractDrawableMesh, public MeshType
mutable MeshRenderSettingsUniforms mMeshRenderSettingsUniforms;

public:
using AbstractDrawableMesh::name;

DrawableMeshBGFX() = default;

DrawableMeshBGFX(const MeshType& mesh) :
Expand Down
50 changes: 50 additions & 0 deletions vclib/render/include/vclib/render/concepts/drawable_object.h
Original file line number Diff line number Diff line change
@@ -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 <vclib/concepts.h>

namespace vcl {

template<typename T>
concept DrawableObjectConcept = requires (T&& obj, uint u) {
{ obj.draw(u) } -> std::same_as<void>;
{ obj.boundingBox() } -> Box3Concept;
obj.clone();
{ obj.isVisible() } -> std::same_as<bool>;
{ obj.name() } -> std::convertible_to<std::string>;
{ obj.info() } -> std::convertible_to<std::string>;

// non const requirements
requires IsConst<T> || requires {
{ obj.init() } -> std::same_as<void>;
{ obj.setVisibility(bool()) } -> std::same_as<void>;
{ obj.name() } -> std::same_as<std::string&>;
{ obj.info() } -> std::same_as<std::string&>;
};
};

} // namespace vcl

#endif // VCL_RENDER_CONCEPTS_DRAWABLE_OBJECT_H

0 comments on commit 853efd7

Please sign in to comment.