Visual Computing Library  devel
Loading...
Searching...
No Matches
mesh_render_settings_uniforms.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2026 *
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_DRAWABLE_UNIFORMS_MESH_RENDER_SETTINGS_UNIFORMS_H
24#define VCL_BGFX_DRAWABLE_UNIFORMS_MESH_RENDER_SETTINGS_UNIFORMS_H
25
26#include <vclib/bgfx/uniform.h>
27#include <vclib/render/drawable/mesh/mesh_render_settings.h>
28
29#include <bgfx/bgfx.h>
30
31namespace vcl {
32
41{
42 // sDrawPack[0] -> draw mode0
43 // sDrawPack[1] -> draw mode1
44 // sDrawPack[2] -> unused
45 // sDrawPack[3] -> unused
46 inline static std::array<float, 4> sDrawPack = {0.0, 0.0, 0.0, 0.0};
47
48 // sWidthPack[0] -> point width
49 // sWidthPack[1] -> wireframe width
50 // sWidthPack[2] -> edge width
51 // sWidthPack[3] -> unused
52 inline static std::array<float, 4> sWidthPack = {0.0, 0.0, 0.0, 0.0};
53
54 // sColorPack[0] -> point user color
55 // sColorPack[1] -> surface user color
56 // sColorPack[2] -> wireframe user color
57 // sColorPack[3] -> edge user color
58 inline static std::array<float, 4> sColorPack = {0.0, 0.0, 0.0, 0.0};
59
60 inline static Uniform sDrawModeUniform;
61 inline static Uniform sWidthUniform;
62 inline static Uniform sColorUniform;
63
64public:
66
67 static void set(const vcl::MeshRenderSettings& settings)
68 {
69 auto mri = settings.drawMode();
70 uint d0 = mri.points().underlying();
71 d0 |= mri.surface().underlying() << 16;
72 uint d1 = mri.wireframe().underlying();
73 d1 |= mri.edges().underlying() << 16;
74
75 sDrawPack[0] = std::bit_cast<float>(d0);
76 sDrawPack[1] = std::bit_cast<float>(d1);
77
78 sWidthPack[0] = settings.pointWidth();
79 sWidthPack[1] = settings.wireframeWidth();
80 sWidthPack[2] = settings.edgesWidth();
81
82 sColorPack[0] = std::bit_cast<float>(settings.pointUserColor().abgr());
83 sColorPack[1] =
84 std::bit_cast<float>(settings.surfaceUserColor().abgr());
85 sColorPack[2] =
86 std::bit_cast<float>(settings.wireframeUserColor().abgr());
87 sColorPack[3] = std::bit_cast<float>(settings.edgesUserColor().abgr());
88 }
89
90 static void bind()
91 {
92 // lazy initialization
93 // to avoid creating uniforms before bgfx is initialized
94 if (!sDrawModeUniform.isValid())
95 sDrawModeUniform =
96 Uniform("u_mrsDrawPack", bgfx::UniformType::Vec4);
97 if (!sWidthUniform.isValid())
98 sWidthUniform = Uniform("u_mrsWidthPack", bgfx::UniformType::Vec4);
99 if (!sColorUniform.isValid())
100 sColorUniform = Uniform("u_mrsColorPack", bgfx::UniformType::Vec4);
101 sDrawModeUniform.bind(sDrawPack.data());
102 sWidthUniform.bind(sWidthPack.data());
103 sColorUniform.bind(sColorPack.data());
104 }
105};
106
107} // namespace vcl
108
109#endif // VCL_BGFX_DRAWABLE_UNIFORMS_MESH_RENDER_SETTINGS_UNIFORMS_H
The MeshRenderSettingsUniforms class is responsible for managing the shader uniforms related to mesh ...
Definition mesh_render_settings_uniforms.h:41
The MeshRenderSettings class allows an easy management of render settings of a Mesh....
Definition mesh_render_settings.h:70
MeshRenderInfo drawMode() const
Returns the current draw mode as a MeshRenderInfo object.
Definition mesh_render_settings.h:115
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:41
The Uniform class wraps a bgfx::UniformHandle and provides a simple interface to set the uniform data...
Definition uniform.h:43
void bind(const void *data) const
Sets the uniform data for the current shader program.
Definition uniform.h:165
bool isValid() const
Checks if the Uniform is valid (i.e., if it has a valid bgfx::UniformHandle).
Definition uniform.h:129