Skip to content

Commit

Permalink
[render] ImGui static Asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
alemuntoni committed Jan 9, 2025
1 parent 3f33977 commit a0b1f00
Show file tree
Hide file tree
Showing 2 changed files with 243 additions and 9 deletions.
249 changes: 240 additions & 9 deletions tests/render/000-static-asserts/drawers.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,47 @@

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

#include <vclib/render/drawers/plain_drawer.h>
#include <vclib/render/drawers/event_drawer.h>
#include <vclib/render/drawers/viewer_drawer.h>

#ifdef VCLIB_WITH_IMGUI
#include <vclib/imgui/imgui_drawer.h>
#endif

#ifdef VCLIB_RENDER_BACKEND_BGFX
#include <vclib/bgfx/drawers/text_drawer.h>
#endif

template<typename DR>
using BlockEventDrawer = vcl::EventDrawer<DR, true>;

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

void drawersStaticAsserts()
// generic static asserts for drawers that should work with any window manager
template<template<typename> typename WM>
void drawersStaticAssertsWM()
{
using namespace vcl;

using RendererTypePD = Renderer<WM, Canvas, PlainDrawer>;
using RendererTypeED = Renderer<WM, Canvas, EventDrawer>;
using RendererTypeVD = Renderer<WM, Canvas, ViewerDrawer>;
using RendererTypePD = Renderer<WM, Canvas, PlainDrawer>;
using RendererTypeED = Renderer<WM, Canvas, EventDrawer>;
using RendererTypeBED = Renderer<WM, Canvas, BlockEventDrawer>;
using RendererTypeVD = Renderer<WM, Canvas, ViewerDrawer>;

// PlainDrawer
static_assert(
DrawerConcept<PlainDrawer<RendererTypePD>>,
"PlainDrawer does not satisfy the DrawerConcept");
Expand Down Expand Up @@ -88,6 +101,7 @@ void drawersStaticAsserts()
!EventDrawerConcept<PlainDrawer<RendererTypePD>&&>,
"PlainDrawer&& does satisfy the EventDrawerConcept");

// EventDrawer
static_assert(
DrawerConcept<EventDrawer<RendererTypeED>>,
"EventDrawer does not satisfy the DrawerConcept");
Expand Down Expand Up @@ -120,6 +134,104 @@ void drawersStaticAsserts()
EventDrawerConcept<EventDrawer<RendererTypeED>&&>,
"EventDrawer&& does not satisfy the EventDrawerConcept");

static_assert(
CantBlockEventDrawerConcept<EventDrawer<RendererTypeED>>,
"EventDrawer does not satisfy the CantBlockEventDrawerConcept");
static_assert(
CantBlockEventDrawerConcept<const EventDrawer<RendererTypeED>>,
"const EventDrawer does not satisfy the CantBlockEventDrawerConcept");
static_assert(
CantBlockEventDrawerConcept<EventDrawer<RendererTypeED>&>,
"EventDrawer& does not satisfy the CantBlockEventDrawerConcept");
static_assert(
CantBlockEventDrawerConcept<const EventDrawer<RendererTypeED>&>,
"const EventDrawer& does not satisfy the CantBlockEventDrawerConcept");
static_assert(
CantBlockEventDrawerConcept<EventDrawer<RendererTypeED>&&>,
"EventDrawer&& does not satisfy the CantBlockEventDrawerConcept");

static_assert(
!CanBlockEventDrawerConcept<EventDrawer<RendererTypeED>>,
"EventDrawer does satisfy the CanBlockEventDrawerConcept");
static_assert(
!CanBlockEventDrawerConcept<const EventDrawer<RendererTypeED>>,
"const EventDrawer does satisfy the CanBlockEventDrawerConcept");
static_assert(
!CanBlockEventDrawerConcept<EventDrawer<RendererTypeED>&>,
"EventDrawer& does satisfy the CanBlockEventDrawerConcept");
static_assert(
!CanBlockEventDrawerConcept<const EventDrawer<RendererTypeED>&>,
"const EventDrawer& does satisfy the CanBlockEventDrawerConcept");
static_assert(
!CanBlockEventDrawerConcept<EventDrawer<RendererTypeED>&&>,
"EventDrawer&& does satisfy the CanBlockEventDrawerConcept");

// BlockEventDrawer
static_assert(
DrawerConcept<BlockEventDrawer<RendererTypeBED>>,
"BlockEventDrawer does not satisfy the DrawerConcept");
static_assert(
DrawerConcept<const BlockEventDrawer<RendererTypeBED>>,
"const BlockEventDrawer does not satisfy the DrawerConcept");
static_assert(
DrawerConcept<BlockEventDrawer<RendererTypeBED>&>,
"BlockEventDrawer& does not satisfy the DrawerConcept");
static_assert(
DrawerConcept<const BlockEventDrawer<RendererTypeBED>&>,
"const BlockEventDrawer& does not satisfy the DrawerConcept");
static_assert(
DrawerConcept<BlockEventDrawer<RendererTypeBED>&&>,
"BlockEventDrawer&& does not satisfy the DrawerConcept");

static_assert(
EventDrawerConcept<BlockEventDrawer<RendererTypeBED>>,
"BlockEventDrawer does not satisfy the EventDrawerConcept");
static_assert(
EventDrawerConcept<const BlockEventDrawer<RendererTypeBED>>,
"const BlockEventDrawer does not satisfy the EventDrawerConcept");
static_assert(
EventDrawerConcept<BlockEventDrawer<RendererTypeBED>&>,
"BlockEventDrawer& does not satisfy the EventDrawerConcept");
static_assert(
EventDrawerConcept<const BlockEventDrawer<RendererTypeBED>&>,
"const BlockEventDrawer& does not satisfy the EventDrawerConcept");
static_assert(
EventDrawerConcept<BlockEventDrawer<RendererTypeBED>&&>,
"BlockEventDrawer&& does not satisfy the EventDrawerConcept");

static_assert(
!CantBlockEventDrawerConcept<BlockEventDrawer<RendererTypeBED>>,
"BlockEventDrawer does satisfy the CantBlockEventDrawerConcept");
static_assert(
!CantBlockEventDrawerConcept<const BlockEventDrawer<RendererTypeBED>>,
"const BlockEventDrawer does satisfy the CantBlockEventDrawerConcept");
static_assert(
!CantBlockEventDrawerConcept<BlockEventDrawer<RendererTypeBED>&>,
"BlockEventDrawer& does satisfy the CantBlockEventDrawerConcept");
static_assert(
!CantBlockEventDrawerConcept<const BlockEventDrawer<RendererTypeBED>&>,
"const BlockEventDrawer& does satisfy the CantBlockEventDrawerConcept");
static_assert(
!CantBlockEventDrawerConcept<BlockEventDrawer<RendererTypeBED>&&>,
"BlockEventDrawer&& does satisfy the CantBlockEventDrawerConcept");

static_assert(
CanBlockEventDrawerConcept<BlockEventDrawer<RendererTypeBED>>,
"BlockEventDrawer does not satisfy the CanBlockEventDrawerConcept");
static_assert(
CanBlockEventDrawerConcept<const BlockEventDrawer<RendererTypeBED>>,
"const BlockEventDrawer does not satisfy the CanBlockEventDrawerConcept");
static_assert(
CanBlockEventDrawerConcept<BlockEventDrawer<RendererTypeBED>&>,
"BlockEventDrawer& does not satisfy the CanBlockEventDrawerConcept");
static_assert(
CanBlockEventDrawerConcept<const BlockEventDrawer<RendererTypeBED>&>,
"const BlockEventDrawer& does not satisfy the CanBlockEventDrawerConcept");
static_assert(
CanBlockEventDrawerConcept<BlockEventDrawer<RendererTypeBED>&&>,
"BlockEventDrawer&& does not satisfy the CanBlockEventDrawerConcept");

// ViewerDrawer
static_assert(
DrawerConcept<ViewerDrawer<RendererTypeVD>>,
"ViewerDrawer does not satisfy the DrawerConcept");
Expand Down Expand Up @@ -152,9 +264,42 @@ void drawersStaticAsserts()
EventDrawerConcept<ViewerDrawer<RendererTypeVD>&&>,
"ViewerDrawer&& does not satisfy the EventDrawerConcept");

static_assert(
CantBlockEventDrawerConcept<ViewerDrawer<RendererTypeVD>>,
"ViewerDrawer does not satisfy the CantBlockEventDrawerConcept");
static_assert(
CantBlockEventDrawerConcept<const ViewerDrawer<RendererTypeVD>>,
"const ViewerDrawer does not satisfy the CantBlockEventDrawerConcept");
static_assert(
CantBlockEventDrawerConcept<ViewerDrawer<RendererTypeVD>&>,
"ViewerDrawer& does not satisfy the CantBlockEventDrawerConcept");
static_assert(
CantBlockEventDrawerConcept<const ViewerDrawer<RendererTypeVD>&>,
"const ViewerDrawer& does not satisfy the CantBlockEventDrawerConcept");
static_assert(
CantBlockEventDrawerConcept<ViewerDrawer<RendererTypeVD>&&>,
"ViewerDrawer&& does not satisfy the CantBlockEventDrawerConcept");

static_assert(
!CanBlockEventDrawerConcept<ViewerDrawer<RendererTypeVD>>,
"ViewerDrawer does satisfy the CanBlockEventDrawerConcept");
static_assert(
!CanBlockEventDrawerConcept<const ViewerDrawer<RendererTypeVD>>,
"const ViewerDrawer does satisfy the CanBlockEventDrawerConcept");
static_assert(
!CanBlockEventDrawerConcept<ViewerDrawer<RendererTypeVD>&>,
"ViewerDrawer& does satisfy the CanBlockEventDrawerConcept");
static_assert(
!CanBlockEventDrawerConcept<const ViewerDrawer<RendererTypeVD>&>,
"const ViewerDrawer& does satisfy the CanBlockEventDrawerConcept");
static_assert(
!CanBlockEventDrawerConcept<ViewerDrawer<RendererTypeVD>&&>,
"ViewerDrawer&& does satisfy the CanBlockEventDrawerConcept");

#ifdef VCLIB_RENDER_BACKEND_BGFX
using RendererTypeTD = Renderer<WM, Canvas, TextDrawer>;
using RendererTypeTD = Renderer<WMQ, Canvas, TextDrawer>;

// TextDrawer
static_assert(
DrawerConcept<TextDrawer<RendererTypeTD>>,
"TextDrawer does not satisfy the DrawerConcept");
Expand Down Expand Up @@ -189,4 +334,90 @@ void drawersStaticAsserts()
#endif
}

void drawersStaticAsserts()
{
using namespace vcl;

// static asserts for each window manager
#ifdef VCLIB_WITH_QT
drawersStaticAssertsWM<WMQ>();
#endif

#if VCLIB_WITH_GLFW
drawersStaticAssertsWM<WMG>();
#endif

// static assers for drawers that work with specific window managers
#ifdef VCLIB_WITH_IMGUI
using namespace vcl::imgui;

using RendererTypeID = Renderer<WMG, Canvas, ImguiDrawer>;

// ImguiDrawer
static_assert(
DrawerConcept<ImguiDrawer<RendererTypeID>>,
"ImguiDrawer does not satisfy the DrawerConcept");
static_assert(
DrawerConcept<const ImguiDrawer<RendererTypeID>>,
"const ImguiDrawer does not satisfy the DrawerConcept");
static_assert(
DrawerConcept<ImguiDrawer<RendererTypeID>&>,
"ImguiDrawer& does not satisfy the DrawerConcept");
static_assert(
DrawerConcept<const ImguiDrawer<RendererTypeID>&>,
"const ImguiDrawer& does not satisfy the DrawerConcept");
static_assert(
DrawerConcept<ImguiDrawer<RendererTypeID>&&>,
"ImguiDrawer&& does not satisfy the DrawerConcept");

static_assert(
EventDrawerConcept<ImguiDrawer<RendererTypeID>>,
"ImguiDrawer does not satisfy the EventDrawerConcept");
static_assert(
EventDrawerConcept<const ImguiDrawer<RendererTypeID>>,
"const ImguiDrawer does not satisfy the EventDrawerConcept");
static_assert(
EventDrawerConcept<ImguiDrawer<RendererTypeID>&>,
"ImguiDrawer& does not satisfy the EventDrawerConcept");
static_assert(
EventDrawerConcept<const ImguiDrawer<RendererTypeID>&>,
"const ImguiDrawer& does not satisfy the EventDrawerConcept");
static_assert(
EventDrawerConcept<ImguiDrawer<RendererTypeID>&&>,
"ImguiDrawer&& does not satisfy the EventDrawerConcept");

static_assert(
CanBlockEventDrawerConcept<ImguiDrawer<RendererTypeID>>,
"ImguiDrawer does not satisfy the CanBlockEventDrawerConcept");
static_assert(
CanBlockEventDrawerConcept<const ImguiDrawer<RendererTypeID>>,
"const ImguiDrawer does not satisfy the CanBlockEventDrawerConcept");
static_assert(
CanBlockEventDrawerConcept<ImguiDrawer<RendererTypeID>&>,
"ImguiDrawer& does not satisfy the CanBlockEventDrawerConcept");
static_assert(
CanBlockEventDrawerConcept<const ImguiDrawer<RendererTypeID>&>,
"const ImguiDrawer& does not satisfy the CanBlockEventDrawerConcept");
static_assert(
CanBlockEventDrawerConcept<ImguiDrawer<RendererTypeID>&&>,
"ImguiDrawer&& does not satisfy the CanBlockEventDrawerConcept");

static_assert(
!CantBlockEventDrawerConcept<ImguiDrawer<RendererTypeID>>,
"ImguiDrawer does satisfy the CantBlockEventDrawerConcept");
static_assert(
!CantBlockEventDrawerConcept<const ImguiDrawer<RendererTypeID>>,
"const ImguiDrawer does satisfy the CantBlockEventDrawerConcept");
static_assert(
!CantBlockEventDrawerConcept<ImguiDrawer<RendererTypeID>&>,
"ImguiDrawer& does satisfy the CantBlockEventDrawerConcept");
static_assert(
!CantBlockEventDrawerConcept<const ImguiDrawer<RendererTypeID>&>,
"const ImguiDrawer& does satisfy the CantBlockEventDrawerConcept");
static_assert(
!CantBlockEventDrawerConcept<ImguiDrawer<RendererTypeID>&&>,
"ImguiDrawer&& does satisfy the CantBlockEventDrawerConcept");
#endif
}

#endif // DRAWERS_H
3 changes: 3 additions & 0 deletions vclib/render/3rdparty/imgui.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,7 @@ if (VCLIB_ALLOW_DOWNLOAD_IMGUI)
target_link_libraries(vclib-3rd-imgui INTERFACE imgui)

list(APPEND VCLIB_RENDER_3RDPARTY_LIBRARIES vclib-3rd-imgui)

target_compile_definitions(vclib-3rd-imgui INTERFACE
VCLIB_WITH_IMGUI)
endif()

0 comments on commit a0b1f00

Please sign in to comment.