Visual Computing Library  devel
Loading...
Searching...
No Matches
viewer_drawer_bgfx.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_BGFX_DRAWERS_VIEWER_DRAWER_BGFX_H
24#define VCL_BGFX_DRAWERS_VIEWER_DRAWER_BGFX_H
25
26#include <vclib/render/drawers/abstract_viewer_drawer.h>
27
28#include <vclib/bgfx/context.h>
29#include <vclib/bgfx/drawable/uniforms/directional_light_uniforms.h>
30#include <vclib/bgfx/drawable/uniforms/mesh_render_settings_uniforms.h>
31
32namespace vcl {
33
34template<typename ViewProjEventDrawer>
35class ViewerDrawerBGFX : public AbstractViewerDrawer<ViewProjEventDrawer>
36{
38
39 DirectionalLightUniforms mDirectionalLightUniforms;
40
41 // flags
42 bool mStatsEnabled = false;
43
44public:
45 ViewerDrawerBGFX(uint width = 1024, uint height = 768) :
46 ParentViewer(width, height)
47 {
48 mDirectionalLightUniforms.updateLight(ParentViewer::light());
49 }
50
52 const std::shared_ptr<DrawableObjectVector>& v,
53 uint width = 1024,
54 uint height = 768) : ViewerDrawerBGFX(width, height)
55 {
56 ParentViewer::setDrawableObjectVector(v);
57 }
58
59 void onDrawContent(uint viewId) override
60 {
61 bgfx::setViewTransform(
62 viewId,
63 ParentViewer::viewMatrix().data(),
64 ParentViewer::projectionMatrix().data());
65
66 mDirectionalLightUniforms.updateLight(ParentViewer::light());
67 mDirectionalLightUniforms.bind();
68
69 ParentViewer::drawableObjectVector().draw(viewId);
70 }
71
72 void onDrawId(uint viewId) override
73 {
74 bgfx::setViewTransform(
75 viewId,
76 ParentViewer::viewMatrix().data(),
77 ParentViewer::projectionMatrix().data());
78
79 ParentViewer::drawableObjectVector().drawId(viewId, ParentViewer::id());
80 }
81
82 void onKeyPress(Key::Enum key, const KeyModifiers& modifiers) override
83 {
84 if (key == Key::F1) {
85 if (mStatsEnabled) {
86 mStatsEnabled = false;
87 bgfx::setDebug(BGFX_DEBUG_NONE);
88 }
89 else {
90 mStatsEnabled = true;
91 bgfx::setDebug(BGFX_DEBUG_STATS);
92 }
93 }
94 ParentViewer::onKeyPress(key, modifiers);
95 }
96
97 void onMouseDoubleClick(
98 MouseButton::Enum button,
99 double x,
100 double y,
101 const KeyModifiers& modifiers) override
102 {
103 ParentViewer::onMouseDoubleClick(button, x, y, modifiers);
104
105 if (button == MouseButton::LEFT) {
106 const bool homogeneousNDC =
107 Context::instance().capabilites().homogeneousDepth;
108
109 ParentViewer::readDepthRequest(x, y, homogeneousNDC);
110 }
111 }
112};
113
114} // namespace vcl
115
116#endif // VCL_BGFX_DRAWERS_VIEWER_DRAWER_BGFX_H
The AbstractViewerDrawer class is a base class for all viewer drawers implementations.
Definition abstract_viewer_drawer.h:46
A class representing a box in N-dimensional space.
Definition box.h:46
static Context & instance(void *windowHandle=nullptr, void *displayHandle=nullptr)
Return the context instance.
Definition context.cpp:371
The DirectionalLightUniforms class manages the uniforms which describe a directional light that can b...
Definition directional_light_uniforms.h:49
void updateLight(const vcl::DirectionalLight< S > &light)
updateLight
Definition directional_light_uniforms.h:66
Definition viewer_drawer_bgfx.h:36