]> git.cworth.org Git - vogl/blob - src/vogleditor/vogleditor_statetreeprogramitem.cpp
Initial vogl checkin
[vogl] / src / vogleditor / vogleditor_statetreeprogramitem.cpp
1 #include "vogleditor_statetreeprogramitem.h"
2 #include "vogleditor_statetreeshaderitem.h"
3
4 //=============================================================================
5
6 vogleditor_stateTreeProgramBoolItem::vogleditor_stateTreeProgramBoolItem(QString name, bool (vogl_program_state::* func)(void) const, vogleditor_stateTreeItem* parent, const vogl_program_state& state)
7     : vogleditor_stateTreeProgramDiffableItem(name, "", parent, state),
8       m_pFunc(func)
9 {
10     bool val = (state.*func)();
11     setValue(val);
12 }
13
14 bool vogleditor_stateTreeProgramBoolItem::hasChanged() const
15 {
16     if (m_pDiffBaseState == NULL)
17         return false;
18     else
19         return (m_pState->*m_pFunc)() != (m_pDiffBaseState->*m_pFunc)();
20 }
21
22 QString vogleditor_stateTreeProgramBoolItem::getDiffedValue() const
23 {
24     if (m_pDiffBaseState == NULL)
25         return "";
26
27     bool value = (m_pDiffBaseState->*m_pFunc)();
28     return getValueFromBools(&value, 1);
29 }
30
31 //=============================================================================
32
33 vogleditor_stateTreeProgramUIntItem::vogleditor_stateTreeProgramUIntItem(QString name, uint (vogl_program_state::* func)(void) const, vogleditor_stateTreeItem* parent, const vogl_program_state& state)
34     : vogleditor_stateTreeProgramDiffableItem(name, "", parent, state),
35       m_pFunc(func)
36 {
37     uint val = (state.*func)();
38     setValue(val);
39 }
40
41 bool vogleditor_stateTreeProgramUIntItem::hasChanged() const
42 {
43     if (m_pDiffBaseState == NULL)
44         return false;
45     else
46         return (m_pState->*m_pFunc)() != (m_pDiffBaseState->*m_pFunc)();
47 }
48
49 QString vogleditor_stateTreeProgramUIntItem::getDiffedValue() const
50 {
51     if (m_pDiffBaseState == NULL)
52         return "";
53
54     uint value = (m_pDiffBaseState->*m_pFunc)();
55     return getValueFromUints(&value, 1);
56 }
57
58 //=============================================================================
59
60 vogleditor_stateTreeProgramEnumItem::vogleditor_stateTreeProgramEnumItem(QString name, GLenum (vogl_program_state::* func)(void) const, vogleditor_stateTreeItem* parent, const vogl_program_state& state)
61     : vogleditor_stateTreeProgramDiffableItem(name, "", parent, state),
62       m_pFunc(func)
63 {
64     GLenum val = (state.*func)();
65     setValue(enum_to_string(val));
66 }
67
68 bool vogleditor_stateTreeProgramEnumItem::hasChanged() const
69 {
70     if (m_pDiffBaseState == NULL)
71         return false;
72     else
73         return (m_pState->*m_pFunc)() != (m_pDiffBaseState->*m_pFunc)();
74 }
75
76 QString vogleditor_stateTreeProgramEnumItem::getDiffedValue() const
77 {
78     if (m_pDiffBaseState == NULL)
79         return "";
80
81     int value = (m_pDiffBaseState->*m_pFunc)();
82     return getValueFromEnums(&value, 1);
83 }
84
85 //=============================================================================
86
87 vogleditor_stateTreeProgramLogItem::vogleditor_stateTreeProgramLogItem(QString name, const vogl::dynamic_string& (vogl_program_state::* func)(void) const, vogleditor_stateTreeItem* parent, const vogl_program_state& state)
88     : vogleditor_stateTreeProgramDiffableItem(name, "", parent, state),
89       m_pFunc(func)
90 {
91     uint val = (state.*func)().size();
92     setValue(val);
93
94     if (val > 0)
95     {
96         vogleditor_stateTreeProgramItem* pProgramItem = static_cast<vogleditor_stateTreeProgramItem*>(this->parent());
97         pProgramItem->add_diffable_child(new vogleditor_stateTreeProgramStringItem("Info Log", func, this->parent(), state));
98     }
99 }
100
101 bool vogleditor_stateTreeProgramLogItem::hasChanged() const
102 {
103     if (m_pDiffBaseState == NULL)
104         return false;
105     else
106         return (m_pState->*m_pFunc)() != (m_pDiffBaseState->*m_pFunc)();
107 }
108
109 QString vogleditor_stateTreeProgramLogItem::getDiffedValue() const
110 {
111     if (m_pDiffBaseState == NULL)
112         return "";
113
114     uint value = (m_pDiffBaseState->*m_pFunc)().size();
115     return getValueFromUints(&value, 1);
116 }
117
118 //=============================================================================
119
120 vogleditor_stateTreeProgramStringItem::vogleditor_stateTreeProgramStringItem(QString name, const vogl::dynamic_string& (vogl_program_state::* func)(void) const, vogleditor_stateTreeItem* parent, const vogl_program_state& state)
121     : vogleditor_stateTreeProgramDiffableItem(name, "", parent, state),
122       m_pFunc(func)
123 {
124     m_value = (state.*func)();
125     setValue(m_value.c_str());
126 }
127
128 bool vogleditor_stateTreeProgramStringItem::hasChanged() const
129 {
130     if (m_pDiffBaseState == NULL)
131     {
132         return false;
133     }
134     else
135     {
136         return (m_pState->*m_pFunc)() != (m_pDiffBaseState->*m_pFunc)();
137     }
138 }
139
140 QString vogleditor_stateTreeProgramStringItem::getDiffedValue() const
141 {
142     if (m_pDiffBaseState == NULL)
143         return "";
144
145     vogl::dynamic_string value = (m_pDiffBaseState->*m_pFunc)();
146     return QString(value.c_str());
147 }
148
149 //=============================================================================
150
151 vogleditor_stateTreeProgramAttribItem::vogleditor_stateTreeProgramAttribItem(QString name, vogleditor_stateTreeItem* parent, const vogl_program_attrib_state& state)
152     : vogleditor_stateTreeItem(name, "", parent),
153       m_pState(&state),
154       m_pDiffBaseState(NULL)
155 {
156     QString tmp;
157     setValue(tmp.sprintf("Loc: %d, Size: %d, Type: %s", state.m_bound_location, state.m_size, enum_to_string(state.m_type).toStdString().c_str()));
158 }
159
160 bool vogleditor_stateTreeProgramAttribItem::hasChanged() const
161 {
162     if (m_pDiffBaseState == NULL)
163     {
164         return false;
165     }
166     else
167     {
168         return (m_pDiffBaseState->find(*m_pState) == cInvalidIndex);
169     }
170 }
171
172 QString vogleditor_stateTreeProgramAttribItem::getDiffedValue() const
173 {
174     if (m_pDiffBaseState == NULL)
175         return "";
176
177     return "non-existent";
178 }
179
180 //=============================================================================
181
182 vogleditor_stateTreeProgramUniformItem::vogleditor_stateTreeProgramUniformItem(QString name, vogleditor_stateTreeItem* parent, const vogl_program_uniform_state& state)
183     : vogleditor_stateTreeItem(name, "", parent),
184       m_pState(&state),
185       m_pDiffBaseState(NULL)
186 {
187     QString tmp;
188     setValue(tmp.sprintf("Loc: %d, Size: %d, Type: %s", state.m_base_location, state.m_size, enum_to_string(state.m_type).toStdString().c_str()));
189 }
190
191 bool vogleditor_stateTreeProgramUniformItem::hasChanged() const
192 {
193     if (m_pDiffBaseState == NULL)
194     {
195         return false;
196     }
197     else
198     {
199         return (m_pDiffBaseState->find(*m_pState) == cInvalidIndex);
200     }
201 }
202
203 QString vogleditor_stateTreeProgramUniformItem::getDiffedValue() const
204 {
205     if (m_pDiffBaseState == NULL)
206         return "";
207
208     return "non-existent";
209 }
210
211 //=============================================================================
212
213 vogleditor_stateTreeProgramItem::vogleditor_stateTreeProgramItem(QString name, QString value, vogleditor_stateTreeItem* parentNode, vogl_program_state& state, const vogl_context_info& info)
214    : vogleditor_stateTreeItem(name, value, parentNode),
215      m_pState(&state)
216 {
217    QString tmp;
218
219    // basic info
220    this->appendChild(new vogleditor_stateTreeProgramBoolItem("GL_LINK_STATUS", &vogl_program_state::get_link_status, this, state));
221    this->appendChild(new vogleditor_stateTreeProgramBoolItem("GL_DELETE_STATUS", &vogl_program_state::get_marked_for_deletion, this, state));
222    this->appendChild(new vogleditor_stateTreeProgramBoolItem("GL_VALIDATE_STATUS", &vogl_program_state::get_verify_status, this, state));
223    if (info.get_version() >= VOGL_GL_VERSION_3_1)
224    {
225       this->appendChild(new vogleditor_stateTreeProgramUIntItem("GL_ACTIVE_UNIFORM_BLOCKS", &vogl_program_state::get_num_active_uniform_blocks, this, state));
226    }
227
228    // program binary
229    this->appendChild(new vogleditor_stateTreeItem("GL_PROGRAM_BINARY_RETRIEVABLE_HINT", "TODO", this));
230    this->appendChild(new vogleditor_stateTreeProgramUIntItem("GL_PROGRAM_BINARY_LENGTH", &vogl_program_state::get_program_binary_size, this, state));
231    this->appendChild(new vogleditor_stateTreeProgramEnumItem("GL_PROGRAM_BINARY_FORMAT", &vogl_program_state::get_program_binary_format, this, state));
232    if (m_pState->get_program_binary().size() > 0)
233    {
234       this->appendChild(new vogleditor_stateTreeItem("Program Binary", "TODO: open in a new tab", this));
235    }
236
237    // info log
238    this->appendChild(new vogleditor_stateTreeProgramLogItem("GL_INFO_LOG_LENGTH", &vogl_program_state::get_info_log, this, state));
239
240    // linked shaders
241    const vogl_unique_ptr<vogl_program_state> &linked_program = m_pState->get_link_time_snapshot();
242    if (linked_program.get())
243    {
244       uint num_attached_shaders = linked_program->get_shaders().size();
245       vogleditor_stateTreeItem* pLinkedShadersNode = new vogleditor_stateTreeItem("Linked Shaders", tmp.sprintf("[%u]", num_attached_shaders), this);
246       this->appendChild(pLinkedShadersNode);
247
248       for (uint i = 0; i < num_attached_shaders; i++)
249       {
250          vogl_shader_state& shader = const_cast<vogl_shader_state&>(linked_program->get_shaders()[i]);
251          GLuint64 shaderId = shader.get_snapshot_handle();
252          pLinkedShadersNode->appendChild(new vogleditor_stateTreeShaderItem(tmp.sprintf("%" PRIu64, shaderId), enum_to_string(shader.get_shader_type()), pLinkedShadersNode, shader));
253       }
254    }
255
256     // attached shaders
257     uint num_attached_shaders = m_pState->get_shaders().size();
258     vogleditor_stateTreeItem* pAttachedShadersNode = new vogleditor_stateTreeItem("GL_ATTACHED_SHADERS", tmp.sprintf("[%u]", num_attached_shaders), this);
259     this->appendChild(pAttachedShadersNode);
260     for (uint i = 0; i < num_attached_shaders; i++)
261     {
262         vogl_shader_state& shader = const_cast<vogl_shader_state&>(m_pState->get_shaders()[i]);
263         GLuint64 shaderId = shader.get_snapshot_handle();
264         pAttachedShadersNode->appendChild(new vogleditor_stateTreeShaderItem(tmp.sprintf("%" PRIu64, shaderId), enum_to_string(shader.get_shader_type()), pAttachedShadersNode, shader));
265     }
266
267    // active attribs
268    vogleditor_stateTreeItem* pAttribsNode = new vogleditor_stateTreeItem("GL_ACTIVE_ATTRIBUTES", tmp.sprintf("[%u]", m_pState->get_num_active_attribs()), this);
269    this->appendChild(pAttribsNode);
270    uint num_active_attributes = m_pState->get_attrib_state_vec().size();
271    for (uint i = 0; i < num_active_attributes; i++)
272    {
273       const vogl_program_attrib_state& attrib = m_pState->get_attrib_state_vec()[i];
274       vogleditor_stateTreeProgramAttribItem* pItem = new vogleditor_stateTreeProgramAttribItem(tmp.sprintf("%s", attrib.m_name.get_ptr()), pAttribsNode, attrib);
275       m_attribItems.push_back(pItem);
276       pAttribsNode->appendChild(pItem);
277    }
278
279    // uniforms
280    vogleditor_stateTreeItem* pUniformsNode = new vogleditor_stateTreeItem("GL_ACTIVE_UNIFORMS", tmp.sprintf("[%u]", m_pState->get_num_active_uniforms()), this);
281    this->appendChild(pUniformsNode);
282    uint num_uniforms = m_pState->get_uniform_state_vec().size();
283    for (uint i = 0; i < num_uniforms; i++)
284    {
285       const vogl_program_uniform_state& uniform = m_pState->get_uniform_state_vec()[i];
286 //      pUniformsNode->appendChild(new vogleditor_stateTreeItem(QString(uniform.m_name.get_ptr()), tmp.sprintf("Loc: %d, Size: %d, Type: %s", uniform.m_base_location, uniform.m_size, enum_to_string(uniform.m_type).toStdString().c_str()), pUniformsNode));
287       vogleditor_stateTreeProgramUniformItem* pItem = new vogleditor_stateTreeProgramUniformItem(QString(uniform.m_name.get_ptr()), pUniformsNode, uniform);
288       m_uniformItems.push_back(pItem);
289       pUniformsNode->appendChild(pItem);
290    }
291
292    // uniform blocks
293 }
294
295 void vogleditor_stateTreeProgramItem::add_diffable_child(vogleditor_stateTreeProgramDiffableItem* pItem)
296 {
297     m_diffableItems.push_back(pItem);
298     appendChild(pItem);
299 }