]> git.cworth.org Git - vogl/blob - src/vogleditor/vogleditor_statetreeshaderitem.cpp
Initial vogl checkin
[vogl] / src / vogleditor / vogleditor_statetreeshaderitem.cpp
1 #include "vogleditor_statetreeshaderitem.h"
2 #include "vogl_shader_state.h"
3
4
5 //=============================================================================
6
7 vogleditor_stateTreeShaderBoolItem::vogleditor_stateTreeShaderBoolItem(QString name, bool (vogl_shader_state::* func)(void) const, vogleditor_stateTreeItem* parent, const vogl_shader_state& state)
8     : vogleditor_stateTreeShaderDiffableItem(name, "", parent, state),
9       m_pFunc(func)
10 {
11     bool val = (state.*func)();
12     setValue(val? "GL_TRUE" : "GL_FALSE");
13 }
14
15 bool vogleditor_stateTreeShaderBoolItem::hasChanged() const
16 {
17     if (m_pDiffBaseState == NULL)
18         return false;
19     else
20         return (m_pState->*m_pFunc)() != (m_pDiffBaseState->*m_pFunc)();
21 }
22
23 QString vogleditor_stateTreeShaderBoolItem::getDiffedValue() const
24 {
25     if (m_pDiffBaseState == NULL)
26         return "";
27
28     bool value = (m_pDiffBaseState->*m_pFunc)();
29     return getValueFromBools(&value, 1);
30 }
31
32 //=============================================================================
33
34 vogleditor_stateTreeShaderLogItem::vogleditor_stateTreeShaderLogItem(QString name, const vogl::dynamic_string& (vogl_shader_state::* func)(void) const, vogleditor_stateTreeItem* parent, const vogl_shader_state& state)
35     : vogleditor_stateTreeShaderDiffableItem(name, "", parent, state),
36       m_pFunc(func)
37 {
38     uint val = (state.*func)().size();
39     setValue(val);
40
41     if (val > 0)
42     {
43         vogleditor_stateTreeShaderItem* pShaderItem = static_cast<vogleditor_stateTreeShaderItem*>(this->parent());
44         pShaderItem->add_diffable_child(new vogleditor_stateTreeShaderStringItem("Info Log", func, this->parent(), state));
45     }
46 }
47
48 bool vogleditor_stateTreeShaderLogItem::hasChanged() const
49 {
50     if (m_pDiffBaseState == NULL)
51         return false;
52     else
53         return (m_pState->*m_pFunc)() != (m_pDiffBaseState->*m_pFunc)();
54 }
55
56 QString vogleditor_stateTreeShaderLogItem::getDiffedValue() const
57 {
58     if (m_pDiffBaseState == NULL)
59         return "";
60
61     uint value = (m_pDiffBaseState->*m_pFunc)().size();
62     return getValueFromUints(&value, 1);
63 }
64
65 //=============================================================================
66 vogleditor_stateTreeShaderSourceLengthItem::vogleditor_stateTreeShaderSourceLengthItem(QString name, vogleditor_stateTreeItem* parent, const vogl_shader_state& state)
67     : vogleditor_stateTreeShaderDiffableItem(name, "", parent, state)
68 {
69     unsigned int length = state.get_source().size();
70     setValue(length);
71 }
72
73 bool vogleditor_stateTreeShaderSourceLengthItem::hasChanged() const
74 {
75     if (m_pDiffBaseState == NULL)
76     {
77         return false;
78     }
79     else
80     {
81         return m_pState->get_source().size() != m_pDiffBaseState->get_source().size();
82     }
83 }
84
85 QString vogleditor_stateTreeShaderSourceLengthItem::getDiffedValue() const
86 {
87     if (m_pDiffBaseState == NULL)
88         return "";
89
90     uint value = m_pDiffBaseState->get_source().size();
91     return getValueFromUints(&value, 1);
92 }
93
94 //=============================================================================
95
96 vogleditor_stateTreeShaderStringItem::vogleditor_stateTreeShaderStringItem(QString name, const vogl::dynamic_string& (vogl_shader_state::* func)(void) const, vogleditor_stateTreeItem* parent, const vogl_shader_state& state)
97     : vogleditor_stateTreeShaderDiffableItem(name, "", parent, state),
98       m_pFunc(func)
99 {
100     m_value = (state.*func)();
101     setValue(m_value.c_str());
102 }
103
104 bool vogleditor_stateTreeShaderStringItem::hasChanged() const
105 {
106     if (m_pDiffBaseState == NULL)
107     {
108         return false;
109     }
110     else
111     {
112         return (m_pState->*m_pFunc)() != (m_pDiffBaseState->*m_pFunc)();
113     }
114 }
115
116 QString vogleditor_stateTreeShaderStringItem::getDiffedValue() const
117 {
118     if (m_pDiffBaseState == NULL)
119         return "";
120
121     vogl::dynamic_string value = (m_pDiffBaseState->*m_pFunc)();
122     return QString(value.c_str());
123 }
124
125 //=============================================================================
126
127 vogleditor_stateTreeShaderItem::vogleditor_stateTreeShaderItem(QString name, QString value, vogleditor_stateTreeItem* parentNode, vogl_shader_state& state)
128    : vogleditor_stateTreeItem(name, value, parentNode),
129      m_pState(&state)
130 {
131    QString tmp;
132
133    { vogleditor_stateTreeShaderBoolItem* pItem = new vogleditor_stateTreeShaderBoolItem("GL_DELETE_STATUS", &vogl_shader_state::get_marked_for_deletion, this, state); m_diffableItems.push_back(pItem); this->appendChild(pItem); }
134    { vogleditor_stateTreeShaderBoolItem* pItem = new vogleditor_stateTreeShaderBoolItem("GL_COMPILE_STATUS", &vogl_shader_state::get_compile_status, this, state); m_diffableItems.push_back(pItem); this->appendChild(pItem); }
135
136    { vogleditor_stateTreeShaderLogItem* pItem = new vogleditor_stateTreeShaderLogItem("GL_INFO_LOG_LENGTH", &vogl_shader_state::get_info_log, this, state); m_diffableItems.push_back(pItem); this->appendChild(pItem); }
137
138    { vogleditor_stateTreeShaderSourceLengthItem* pItem = new vogleditor_stateTreeShaderSourceLengthItem("GL_SHADER_SOURCE_LENGTH", this, state); m_diffableItems.push_back(pItem); this->appendChild(pItem); }
139 }
140
141 void vogleditor_stateTreeShaderItem::add_diffable_child(vogleditor_stateTreeShaderDiffableItem* pItem)
142 {
143     m_diffableItems.push_back(pItem);
144     appendChild(pItem);
145 }