1 #include "vogleditor_statetreeprogramitem.h"
2 #include "vogleditor_statetreeshaderitem.h"
4 //=============================================================================
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),
10 bool val = (state.*func)();
14 bool vogleditor_stateTreeProgramBoolItem::hasChanged() const
16 if (m_pDiffBaseState == NULL)
19 return (m_pState->*m_pFunc)() != (m_pDiffBaseState->*m_pFunc)();
22 QString vogleditor_stateTreeProgramBoolItem::getDiffedValue() const
24 if (m_pDiffBaseState == NULL)
27 bool value = (m_pDiffBaseState->*m_pFunc)();
28 return getValueFromBools(&value, 1);
31 //=============================================================================
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),
37 uint val = (state.*func)();
41 bool vogleditor_stateTreeProgramUIntItem::hasChanged() const
43 if (m_pDiffBaseState == NULL)
46 return (m_pState->*m_pFunc)() != (m_pDiffBaseState->*m_pFunc)();
49 QString vogleditor_stateTreeProgramUIntItem::getDiffedValue() const
51 if (m_pDiffBaseState == NULL)
54 uint value = (m_pDiffBaseState->*m_pFunc)();
55 return getValueFromUints(&value, 1);
58 //=============================================================================
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),
64 GLenum val = (state.*func)();
65 setValue(enum_to_string(val));
68 bool vogleditor_stateTreeProgramEnumItem::hasChanged() const
70 if (m_pDiffBaseState == NULL)
73 return (m_pState->*m_pFunc)() != (m_pDiffBaseState->*m_pFunc)();
76 QString vogleditor_stateTreeProgramEnumItem::getDiffedValue() const
78 if (m_pDiffBaseState == NULL)
81 int value = (m_pDiffBaseState->*m_pFunc)();
82 return getValueFromEnums(&value, 1);
85 //=============================================================================
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),
91 uint val = (state.*func)().size();
96 vogleditor_stateTreeProgramItem* pProgramItem = static_cast<vogleditor_stateTreeProgramItem*>(this->parent());
97 pProgramItem->add_diffable_child(new vogleditor_stateTreeProgramStringItem("Info Log", func, this->parent(), state));
101 bool vogleditor_stateTreeProgramLogItem::hasChanged() const
103 if (m_pDiffBaseState == NULL)
106 return (m_pState->*m_pFunc)() != (m_pDiffBaseState->*m_pFunc)();
109 QString vogleditor_stateTreeProgramLogItem::getDiffedValue() const
111 if (m_pDiffBaseState == NULL)
114 uint value = (m_pDiffBaseState->*m_pFunc)().size();
115 return getValueFromUints(&value, 1);
118 //=============================================================================
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),
124 m_value = (state.*func)();
125 setValue(m_value.c_str());
128 bool vogleditor_stateTreeProgramStringItem::hasChanged() const
130 if (m_pDiffBaseState == NULL)
136 return (m_pState->*m_pFunc)() != (m_pDiffBaseState->*m_pFunc)();
140 QString vogleditor_stateTreeProgramStringItem::getDiffedValue() const
142 if (m_pDiffBaseState == NULL)
145 vogl::dynamic_string value = (m_pDiffBaseState->*m_pFunc)();
146 return QString(value.c_str());
149 //=============================================================================
151 vogleditor_stateTreeProgramAttribItem::vogleditor_stateTreeProgramAttribItem(QString name, vogleditor_stateTreeItem* parent, const vogl_program_attrib_state& state)
152 : vogleditor_stateTreeItem(name, "", parent),
154 m_pDiffBaseState(NULL)
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()));
160 bool vogleditor_stateTreeProgramAttribItem::hasChanged() const
162 if (m_pDiffBaseState == NULL)
168 return (m_pDiffBaseState->find(*m_pState) == cInvalidIndex);
172 QString vogleditor_stateTreeProgramAttribItem::getDiffedValue() const
174 if (m_pDiffBaseState == NULL)
177 return "non-existent";
180 //=============================================================================
182 vogleditor_stateTreeProgramUniformItem::vogleditor_stateTreeProgramUniformItem(QString name, vogleditor_stateTreeItem* parent, const vogl_program_uniform_state& state)
183 : vogleditor_stateTreeItem(name, "", parent),
185 m_pDiffBaseState(NULL)
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()));
191 bool vogleditor_stateTreeProgramUniformItem::hasChanged() const
193 if (m_pDiffBaseState == NULL)
199 return (m_pDiffBaseState->find(*m_pState) == cInvalidIndex);
203 QString vogleditor_stateTreeProgramUniformItem::getDiffedValue() const
205 if (m_pDiffBaseState == NULL)
208 return "non-existent";
211 //=============================================================================
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),
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)
225 this->appendChild(new vogleditor_stateTreeProgramUIntItem("GL_ACTIVE_UNIFORM_BLOCKS", &vogl_program_state::get_num_active_uniform_blocks, this, state));
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)
234 this->appendChild(new vogleditor_stateTreeItem("Program Binary", "TODO: open in a new tab", this));
238 this->appendChild(new vogleditor_stateTreeProgramLogItem("GL_INFO_LOG_LENGTH", &vogl_program_state::get_info_log, this, state));
241 const vogl_unique_ptr<vogl_program_state> &linked_program = m_pState->get_link_time_snapshot();
242 if (linked_program.get())
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);
248 for (uint i = 0; i < num_attached_shaders; i++)
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));
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++)
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));
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++)
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);
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++)
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);
295 void vogleditor_stateTreeProgramItem::add_diffable_child(vogleditor_stateTreeProgramDiffableItem* pItem)
297 m_diffableItems.push_back(pItem);