PeriDyno 1.0.0
Loading...
Searching...
No Matches
GLVisualModule.cpp
Go to the documentation of this file.
1#include "GLVisualModule.h"
2
3#include "glad/glad.h"
4
5namespace dyno
6{
9 {
10 this->setName("GLVisualModule");
11
12 this->varMetallic()->setRange(0, 1);
13 this->varRoughness()->setRange(0, 1);
14 this->varAlpha()->setRange(0, 1);
15
16 this->varBaseColor()->setObjectName("Color");
17 }
18
20 {
21 if (isGLInitialized) {
22 printf("Warning: %s not released!\n", getName().c_str());
23 }
24 }
25
27 {
28 printf("Warning: %s::updateImpl is not implemented!\n", getName().c_str());
29 }
30
32 {
33 updateMutex.lock();
34 }
35
37 {
38 updateMutex.unlock();
39 this->changed = clock::now();
40 }
41
43 {
44 //If any input field is empty, return false;
45 for (auto f_in : fields_input)
46 {
47 if (!f_in->isOptional() && f_in->isEmpty())
48 {
49 return false;
50 }
51 }
52
53 return true;
54 }
55
57 {
58 this->varBaseColor()->setValue(color);
59 }
60
62 {
63 this->varMetallic()->setValue(m);
64 }
65
67 {
68 this->varRoughness()->setValue(r);
69 }
70
71 void GLVisualModule::setAlpha(float alpha)
72 {
73 this->varAlpha()->setValue(alpha);
74 }
75
77 {
78 // we need to copy the alpha since it doesn't provide const interface...
79 auto alpha = this->var_Alpha;
80 return alpha.getValue() < 1.f;
81 }
82
84 {
85 if (!this->validateInputs())
86 return;
87
88 if (!this->isVisible())
89 return;
90
91 if (!isGLInitialized)
93
94 // if failed to initialize...
95 if (!isGLInitialized)
96 throw std::runtime_error("Cannot initialize " + getName());
97
98 // check update
99 if (changed > updated) {
100 updateMutex.lock();
101 updateGL();
102 updated = clock::now();
103 updateMutex.unlock();
104 }
105
106 // draw
107 this->paintGL(rparams);
108 }
109
111 {
112 if (isGLInitialized)
113 {
114 this->releaseGL();
115 isGLInitialized = false;
116 }
117 }
118
119}
120
121
virtual bool initializeGL()=0
void setColor(const Color &color)
virtual void updateImpl() override
void draw(const RenderParams &rparams)
void setAlpha(float alpha)
virtual bool isTransparent() const
bool validateInputs() override final
void setRoughness(float roughness)
virtual void paintGL(const RenderParams &rparams)=0
virtual void postprocess() override final
virtual void preprocess() override final
virtual void releaseGL()=0
clock::time_point updated
void setMetallic(float metallic)
virtual void updateGL()=0
clock::time_point changed
void setName(std::string name)
Definition Module.cpp:187
std::string getName() override
Definition Module.cpp:198
std::vector< FBase * > fields_input
Definition OBase.h:209
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25