Visual Computing Library
Loading...
Searching...
No Matches
mesh_render_settings_uniforms.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_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
34{
35 // mDrawPack[0] -> draw mode0
36 // mDrawPack[1] -> draw mode1
37 // mDrawPack[2] -> unused
38 // mDrawPack[3] -> unused
39 float mDrawPack[4] = {0.0, 0.0, 0.0, 0.0};
40
41 // mWidthPack[0] -> point width
42 // mWidthPack[1] -> wireframe width
43 // mWidthPack[2] -> edge width
44 // mWidthPack[3] -> unused
45 float mWidthPack[4] = {0.0, 0.0, 0.0, 0.0};
46
47 // mColorPack[0] -> point user color
48 // mColorPack[1] -> surface user color
49 // mColorPack[2] -> wireframe user color
50 // mColorPack[3] -> edge user color
51 float mColorPack[4] = {0.0, 0.0, 0.0, 0.0};
52
53 Uniform mDrawModeUniform =
54 Uniform("u_mrsDrawPack", bgfx::UniformType::Vec4);
55
56 Uniform mWidthUniform = Uniform("u_mrsWidthPack", bgfx::UniformType::Vec4);
57
58 Uniform mColorUniform = Uniform("u_mrsColorPack", bgfx::UniformType::Vec4);
59
60public:
62
63 void updateSettings(const vcl::MeshRenderSettings& settings)
64 {
65 auto mri = settings.drawMode();
66 uint d0 = mri.points().underlying();
67 d0 |= mri.surface().underlying() << 16;
68 uint d1 = mri.wireframe().underlying();
69 d1 |= mri.edges().underlying() << 16;
70
71 mDrawPack[0] = Uniform::uintBitsToFloat(d0);
72 mDrawPack[1] = Uniform::uintBitsToFloat(d1);
73
74 mWidthPack[0] = settings.pointWidth();
75 mWidthPack[1] = settings.wireframeWidth();
76 mWidthPack[2] = settings.edgesWidth();
77
78 mColorPack[0] =
79 Uniform::uintBitsToFloat(settings.pointUserColor().abgr());
80 mColorPack[1] =
81 Uniform::uintBitsToFloat(settings.surfaceUserColor().abgr());
82 mColorPack[2] =
83 Uniform::uintBitsToFloat(settings.wireframeUserColor().abgr());
84 mColorPack[3] =
85 Uniform::uintBitsToFloat(settings.edgesUserColor().abgr());
86 }
87
88 void bind() const
89 {
90 mDrawModeUniform.bind(mDrawPack);
91 mWidthUniform.bind(mWidthPack);
92 mColorUniform.bind(mColorPack);
93 }
94};
95
96} // namespace vcl
97
98#endif // VCL_BGFX_DRAWABLE_UNIFORMS_MESH_RENDER_SETTINGS_UNIFORMS_H
Definition mesh_render_settings_uniforms.h:34
The MeshRenderSettings class allows an easy management of render settings of a Mesh....
Definition mesh_render_settings.h:71
MeshRenderInfo drawMode() const
Returns the current draw mode as a MeshRenderInfo object.
Definition mesh_render_settings.h:116
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
The Uniform class wraps a bgfx::UniformHandle and provides a simple interface to set the uniform data...
Definition uniform.h:43