Skip to content

Commit

Permalink
[render] Canvas static asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
alemuntoni committed Dec 26, 2024
1 parent 48f435d commit 29f9c62
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 13 deletions.
7 changes: 7 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ option(VCLIB_CORE_BUILD_TESTS
option(VCLIB_EXTERNAL_BUILD_TESTS
"If true, the tests of VCLib-external will be built." ON)

option(VCLIB_RENDER_BUILD_TESTS
"If true, the tests of VCLib-render will be built." ON)

set(CMAKE_COMPILE_WARNING_AS_ERROR ${VCLIB_COMPILE_WARNINGS_AS_ERRORS})

### Catch2
Expand All @@ -47,6 +50,10 @@ if (VCLIB_BUILD_MODULE_EXTERNAL AND VCLIB_EXTERNAL_BUILD_TESTS)
add_subdirectory(external)
endif()

if (VCLIB_BUILD_MODULE_RENDER AND VCLIB_RENDER_BUILD_TESTS)
add_subdirectory(render)
endif()

# if (VCLIB_BUILD_MODULE_PROCESSING)
# add_subdirectory(processing)
# endif()
Expand Down
40 changes: 40 additions & 0 deletions tests/render/000-static-asserts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#*****************************************************************************
#* VCLib *
#* Visual Computing Library *
#* *
#* Copyright(C) 2021-2024 *
#* 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(TEST_NAME 000-static-asserts)
project(vclib-test-${TEST_NAME})

set(HEADERS
canvas.h
)

set(SOURCES
main.cpp
)

vclib_add_test(
${TEST_NAME}
VCLIB_MODULE render
SOURCES ${HEADERS} ${SOURCES}
${HEADER_ONLY_OPTION})
66 changes: 66 additions & 0 deletions tests/render/000-static-asserts/canvas.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*****************************************************************************
* VCLib *
* Visual Computing Library *
* *
* Copyright(C) 2021-2024 *
* 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 CANVAS_H
#define CANVAS_H

#include <vclib/render/canvas.h>
#include <vclib/render/renderer.h>

#ifdef VCLIB_WITH_QT
#include <vclib/qt/widget_manager.h>
#elif VCLIB_WITH_GLFW
#include <vclib/glfw/window_manager.h>
#endif

#ifdef VCLIB_WITH_QT
template<typename DR>
using WM = vcl::qt::WidgetManager<DR>;
#elif VCLIB_WITH_GLFW
template<typename DR>
using WM = vcl::glfw::WindowManager<DR>;
#endif

void canvasStaticAsserts()
{
using namespace vcl;

using RendererType = Renderer<WM, Canvas>;

static_assert(
CanvasConcept<Canvas<RendererType>>,
"Canvas does not satisfy the CanvasConcept");
static_assert(
CanvasConcept<const Canvas<RendererType>>,
"const Canvas does not satisfy the CanvasConcept");
static_assert(
CanvasConcept<Canvas<RendererType>&>,
"Canvas& does not satisfy the CanvasConcept");
static_assert(
CanvasConcept<const Canvas<RendererType>&>,
"const Canvas& does not satisfy the CanvasConcept");
static_assert(
CanvasConcept<Canvas<RendererType>&&>,
"Canvas&& does not satisfy the CanvasConcept");
}

#endif // CANVAS_H
30 changes: 30 additions & 0 deletions tests/render/000-static-asserts/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*****************************************************************************
* VCLib *
* Visual Computing Library *
* *
* Copyright(C) 2021-2024 *
* 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 "canvas.h"

int main()
{
canvasStaticAsserts();

return 0;
}
31 changes: 31 additions & 0 deletions tests/render/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#*****************************************************************************
#* VCLib *
#* Visual Computing Library *
#* *
#* Copyright(C) 2021-2024 *
#* 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)
project(vclib-render-tests)

set(CMAKE_COMPILE_WARNING_AS_ERROR ${VCLIB_COMPILE_WARNINGS_AS_ERRORS})

if (TARGET vclib-3rd-qt OR TARGET vclib-3rd-glfw)
add_subdirectory(000-static-asserts)
endif()

2 changes: 2 additions & 0 deletions vclib/external/3rdparty/vcg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ if (VCLIB_USES_VCG)
vclib-3rd-vcg
PROPERTIES
VCG_INCLUDE_DIRS ${VCG_INCLUDE_DIRS})
target_compile_definitions(vclib-3rd-vcg INTERFACE
VCLIB_WITH_VCG)

list(APPEND VCLIB_EXTERNAL_3RDPARTY_LIBRARIES vclib-3rd-vcg)
endif()
11 changes: 7 additions & 4 deletions vclib/render/3rdparty/glfw.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ find_package(glfw3 3 QUIET)
if (VCLIB_ALLOW_SYSTEM_GLFW AND glfw3_FOUND)
message(STATUS "- GLFW - using system-provided library")

add_library(vclib-3rd-glfw INTERFACE)
target_link_libraries(vclib-3rd-glfw INTERFACE glfw)

list(APPEND VCLIB_RENDER_3RDPARTY_LIBRARIES vclib-3rd-glfw)
set(VCLIB_USES_GLFW TRUE)

elseif(VCLIB_ALLOW_DOWNLOAD_GLFW)
message(STATUS "- GLFW - using downloaded source")
Expand All @@ -49,11 +46,17 @@ elseif(VCLIB_ALLOW_DOWNLOAD_GLFW)

FetchContent_MakeAvailable(glfw3)

set(VCLIB_USES_GLFW TRUE)
endif()

if (VCLIB_USES_GLFW)
add_library(vclib-3rd-glfw INTERFACE)
target_link_libraries(vclib-3rd-glfw INTERFACE glfw)

list(APPEND VCLIB_RENDER_3RDPARTY_LIBRARIES vclib-3rd-glfw)

target_compile_definitions(vclib-3rd-glfw INTERFACE
VCLIB_WITH_GLFW)
else()
message(STATUS "- GLFW - not found, skipping")
endif()
2 changes: 1 addition & 1 deletion vclib/render/include/vclib/opengl2/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class CanvasOpenGL2

Point2<uint> size() const { return mSize; }

uint viewId() { return 0; }
uint viewId() const { return 0; }

/**
* @brief Automatically called by the DerivedRenderer when the window
Expand Down
19 changes: 11 additions & 8 deletions vclib/render/include/vclib/render/concepts/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,22 @@ concept CanvasConcept = requires (

typename RemoveRef<T>::CallbackReadBuffer;

T(vPtr, u, u);
T(vPtr, u, u, vPtr);
RemoveRef<T>(vPtr, u, u);
RemoveRef<T>(vPtr, u, u, vPtr);

{ obj.size() } -> Point2Concept;
{ obj.viewId() } -> std::convertible_to<uint>;

{ obj.onInit() } -> std::same_as<void>; // qt+opengl requires init
{ obj.onResize(u, u) } -> std::same_as<void>;
{ obj.onPaint() } -> std::same_as<void>;
// non const requirements
requires IsConst<T> || requires {
{ obj.onInit() } -> std::same_as<void>; // qt+opengl requires init
{ obj.onResize(u, u) } -> std::same_as<void>;
{ obj.onPaint() } -> std::same_as<void>;

{ obj.onReadDepth(p, cbrb) } -> std::same_as<bool>;
{ obj.onScreenshot(str) } -> std::same_as<bool>;
{ obj.onScreenshot(str, u, u) } -> std::same_as<bool>;
{ obj.onReadDepth(p, cbrb) } -> std::same_as<bool>;
{ obj.onScreenshot(str) } -> std::same_as<bool>;
{ obj.onScreenshot(str, u, u) } -> std::same_as<bool>;
};
};

} // namespace vcl
Expand Down

0 comments on commit 29f9c62

Please sign in to comment.