]> git.cworth.org Git - vogl/blob - src/vogleditor/vogleditor_statetreecontextitem.h
Initial vogl checkin
[vogl] / src / vogleditor / vogleditor_statetreecontextitem.h
1 #ifndef VOGLEDITOR_STATETREECONTEXTITEM_H
2 #define VOGLEDITOR_STATETREECONTEXTITEM_H
3
4 #include "vogleditor_statetreeitem.h"
5 #include "vogleditor_statetreearbprogramitem.h"
6 #include "vogleditor_statetreearbprogramenvitem.h"
7 #include "vogleditor_statetreebufferitem.h"
8 #include "vogleditor_statetreecontextinfoitem.h"
9 #include "vogleditor_statetreecontextgeneralitem.h"
10 #include "vogleditor_statetreeframebufferitem.h"
11 #include "vogleditor_statetreelightitem.h"
12 #include "vogleditor_statetreepolygonstippleitem.h"
13 #include "vogleditor_statetreeprogramitem.h"
14 #include "vogleditor_statetreequeryitem.h"
15 #include "vogleditor_statetreerenderbufferitem.h"
16 #include "vogleditor_statetreesampleritem.h"
17 #include "vogleditor_statetreeshaderitem.h"
18 #include "vogleditor_statetreesyncitem.h"
19 #include "vogleditor_statetreetexenvitem.h"
20 #include "vogleditor_statetreetextureitem.h"
21 #include "vogleditor_statetreematrixitem.h"
22 #include "vogleditor_statetreevertexarrayitem.h"
23
24 #include "vogl_gl_state_snapshot.h"
25 #include "vogl_sync_object.h"
26
27 class vogleditor_stateTreeContextAttributesItem : public vogleditor_stateTreeItem
28 {
29 public:
30     vogleditor_stateTreeContextAttributesItem(QString name, vogleditor_stateTreeItem* parent, const vogl_context_desc& desc)
31         : vogleditor_stateTreeItem(name, "", parent),
32           m_pState(&desc),
33           m_pDiffBaseState(NULL)
34     {
35         setValue(attribsToString(desc.get_attribs()));
36     }
37
38     virtual ~vogleditor_stateTreeContextAttributesItem() { m_pState = NULL; m_pDiffBaseState = NULL; }
39
40     void set_diff_base_state(const vogl_context_desc* pBaseState) { m_pDiffBaseState = pBaseState; }
41
42     virtual bool hasChanged() const
43     {
44         if (m_pDiffBaseState == NULL)
45         {
46             return false;
47         }
48
49         const vogl_context_attribs& attribs = m_pState->get_attribs();
50
51         for (uint i = 0; i < attribs.size(); i++)
52         {
53             if (i < m_pDiffBaseState->get_attribs().size())
54             {
55                 if (attribs[i] != m_pDiffBaseState->get_attribs()[i])
56                 {
57                     return true;
58                 }
59             }
60         }
61
62         return false;
63     }
64
65     virtual QString getDiffedValue() const
66     {
67         if (m_pDiffBaseState == NULL)
68         {
69             return "";
70         }
71
72         return attribsToString(m_pDiffBaseState->get_attribs());
73     }
74
75 private:
76     const vogl_context_desc* m_pState;
77     const vogl_context_desc* m_pDiffBaseState;
78
79     QString attribsToString(const vogl_context_attribs& attribs) const
80     {
81         QString attribStr;
82         static QString tmp;
83         for (uint i = 0; i < attribs.size(); i++)
84         {
85             if (i != 0)
86             {
87                 attribStr += ", ";
88             }
89
90             GLenum id = attribs[i];
91
92             // final value should always be 0, and should not be handled like the other attribs
93             if (id == 0)
94             {
95                 attribStr += "0";
96             }
97             else
98             {
99                 tmp = g_gl_enums.find_glx_name(id);
100                 if (tmp.isEmpty() || tmp.isNull())
101                 {
102                     tmp = tmp.sprintf("0x%x", id);
103                 }
104                 attribStr += tmp;
105             }
106
107             // check for a value to go with the above attrib
108             if (i + 1 < attribs.size())
109             {
110                i += 1;
111                attribStr += tmp.sprintf(" = 0x%x", attribs[i]);
112             }
113         }
114
115         if (attribStr.isEmpty())
116         {
117             attribStr = "0";
118         }
119         return attribStr;
120     }
121 };
122
123 class vogleditor_stateTreeContextCreationItem : public vogleditor_stateTreeItem
124 {
125 public:
126     vogleditor_stateTreeContextCreationItem(QString name, vogleditor_stateTreeItem* parent, const vogl_context_desc& desc)
127         : vogleditor_stateTreeItem(name, "", parent),
128           m_pState(&desc),
129           m_pDiffBaseState(NULL)
130     {
131         const gl_entrypoint_desc_t &creation_func_entrypoint_desc = g_vogl_entrypoint_descs[desc.get_creation_func()];
132
133         setValue(QString(creation_func_entrypoint_desc.m_pName));
134     }
135
136     virtual ~vogleditor_stateTreeContextCreationItem() { m_pState = NULL; m_pDiffBaseState = NULL; }
137
138     void set_diff_base_state(const vogl_context_desc* pBaseState) { m_pDiffBaseState = pBaseState; }
139
140     virtual bool hasChanged() const
141     {
142         if (m_pDiffBaseState == NULL)
143         {
144             return false;
145         }
146
147         return m_pState->get_creation_func() != m_pDiffBaseState->get_creation_func();
148     }
149
150     virtual QString getDiffedValue() const
151     {
152         if (m_pDiffBaseState == NULL)
153         {
154             return "";
155         }
156
157         const gl_entrypoint_desc_t &creation_func_entrypoint_desc = g_vogl_entrypoint_descs[m_pDiffBaseState->get_creation_func()];
158         return QString(creation_func_entrypoint_desc.m_pName);
159     }
160
161 private:
162     const vogl_context_desc* m_pState;
163     const vogl_context_desc* m_pDiffBaseState;
164 };
165
166
167 class vogleditor_stateTreeContextDirectItem : public vogleditor_stateTreeItem
168 {
169 public:
170     vogleditor_stateTreeContextDirectItem(QString name, vogleditor_stateTreeItem* parent, const vogl_context_desc& desc)
171         : vogleditor_stateTreeItem(name, "", parent),
172           m_pState(&desc),
173           m_pDiffBaseState(NULL)
174     {
175         setValue((bool)desc.get_direct());
176     }
177
178     virtual ~vogleditor_stateTreeContextDirectItem() { m_pState = NULL; m_pDiffBaseState = NULL; }
179
180     void set_diff_base_state(const vogl_context_desc* pBaseState) { m_pDiffBaseState = pBaseState; }
181
182     virtual bool hasChanged() const
183     {
184         if (m_pDiffBaseState == NULL)
185         {
186             return false;
187         }
188
189         return m_pState->get_direct() != m_pDiffBaseState->get_direct();
190     }
191
192     virtual QString getDiffedValue() const
193     {
194         if (m_pDiffBaseState == NULL)
195         {
196             return "";
197         }
198
199         bool value = m_pDiffBaseState->get_direct();
200         return getValueFromBools(&value, 1);
201     }
202
203 private:
204     const vogl_context_desc* m_pState;
205     const vogl_context_desc* m_pDiffBaseState;
206 };
207
208 class vogleditor_stateTreeContextSharedItem : public vogleditor_stateTreeItem
209 {
210 public:
211     vogleditor_stateTreeContextSharedItem(QString name, vogleditor_stateTreeItem* parent, const vogl_context_desc& desc)
212         : vogleditor_stateTreeItem(name, "", parent),
213           m_pState(&desc),
214           m_pDiffBaseState(NULL)
215     {
216         setValue((void*)desc.get_trace_share_context());
217     }
218
219     virtual ~vogleditor_stateTreeContextSharedItem() { m_pState = NULL; m_pDiffBaseState = NULL; }
220
221     void set_diff_base_state(const vogl_context_desc* pBaseState) { m_pDiffBaseState = pBaseState; }
222
223     virtual bool hasChanged() const
224     {
225         if (m_pDiffBaseState == NULL)
226         {
227             return false;
228         }
229
230         return m_pState->get_trace_share_context() != m_pDiffBaseState->get_trace_share_context();
231     }
232
233     virtual QString getDiffedValue() const
234     {
235         if (m_pDiffBaseState == NULL)
236         {
237             return "";
238         }
239
240         vogl_trace_ptr_value value = m_pDiffBaseState->get_trace_share_context();
241         return getValueFromPtrs((int*)&value, 1);
242     }
243
244 private:
245     const vogl_context_desc* m_pState;
246     const vogl_context_desc* m_pDiffBaseState;
247 };
248
249 class vogleditor_stateTreeContextMaterialItem : public vogleditor_stateTreeItem
250 {
251 public:
252     vogleditor_stateTreeContextMaterialItem(QString name, unsigned int face, vogleditor_stateTreeItem* parent, vogl_material_state& state)
253         : vogleditor_stateTreeItem(name, "", parent),
254           m_face(face),
255           m_pState(&state),
256           m_pDiffBaseState(NULL)
257     {
258         vogl_state_vector* pStateVec = state.get_state_vector(face);
259
260         int iVals[4] = {0,0,0,0};
261         float fVals[4] = {0,0,0,0};
262 #define GET_FLOAT(side, name, num) if (pStateVec->get<float>(name, 0, fVals, num)) { vogleditor_stateTreeStateVecFloatItem* pItem = new vogleditor_stateTreeStateVecFloatItem(#name, name, 0, *(pStateVec), fVals, num, false, this); m_diffableItems.push_back(pItem); this->appendChild(pItem); }
263 #define GET_INT(side, name, num) if (pStateVec->get<int>(name, 0, iVals, num)) { vogleditor_stateTreeStateVecIntItem* pItem = new vogleditor_stateTreeStateVecIntItem(#name, name, 0, *(pStateVec), iVals, num, false, this); m_diffableItems.push_back(pItem); this->appendChild(pItem); }
264         VOGL_ASSERT(pStateVec->size() == 6);
265         GET_FLOAT(face, GL_AMBIENT, 4);
266         GET_FLOAT(face, GL_DIFFUSE, 4);
267         GET_FLOAT(face, GL_SPECULAR, 4);
268         GET_FLOAT(face, GL_EMISSION, 4);
269         GET_FLOAT(face, GL_SHININESS, 1);
270         GET_INT(face, GL_COLOR_INDEXES, 3);
271 #undef GET_FLOAT
272 #undef GET_INT
273     }
274
275     virtual ~vogleditor_stateTreeContextMaterialItem() { m_pState = NULL; m_pDiffBaseState = NULL;}
276
277     void set_diff_base_state(const vogl_material_state* pBaseState)
278     {
279         m_pDiffBaseState = pBaseState;
280
281         for (vogleditor_stateTreeStateVecDiffableItem** iter = m_diffableItems.begin(); iter != m_diffableItems.end(); iter++)
282         {
283             (*iter)->set_diff_base_state(m_pDiffBaseState->get_state_vector(m_face));
284         }
285     }
286
287  private:
288     const unsigned int m_face;
289     const vogl_material_state* m_pState;
290     const vogl_material_state* m_pDiffBaseState;
291     vogl::vector<vogleditor_stateTreeStateVecDiffableItem*> m_diffableItems;
292 };
293
294
295 class vogleditor_stateTreeContextItem : public vogleditor_stateTreeItem
296 {
297 public:
298
299     vogleditor_stateTreeContextItem(QString name, QString value, vogleditor_stateTreeItem* parent, vogl_context_snapshot& contextState);
300
301     virtual ~vogleditor_stateTreeContextItem();
302
303     void set_diff_base_state(const vogl_context_snapshot* pBaseState);
304
305     vogl::vector<vogleditor_stateTreeProgramItem*> get_program_objects()
306     {
307         return m_programItems;
308     }
309
310 private:
311     vogl_context_snapshot* m_pState;
312     const vogl_context_snapshot* m_pDiffBaseState;
313     vogleditor_stateTreeContextAttributesItem* m_pAttributesItem;
314     vogleditor_stateTreeContextCreationItem* m_pCreationItem;
315     vogleditor_stateTreeContextDirectItem* m_pDirectItem;
316     vogleditor_stateTreeContextSharedItem* m_pSharedItem;
317     vogleditor_stateTreePolygonStippleItem* m_pPolygonStippleItem;
318     vogleditor_stateTreeTexEnvItem* m_pTexEnvItem;
319     vogl::vector<vogleditor_stateTreeContextInfoItem*> m_contextInfoItems;
320     vogl::vector<vogleditor_stateTreeContextGeneralItem*> m_generalStateItems;
321     vogl::vector<vogleditor_stateTreeStateVecDiffableItem*> m_diffableItems;
322     vogl::vector<vogleditor_stateTreeTextureItem*> m_textureItems;
323     vogl::vector<vogleditor_stateTreeSamplerItem*> m_samplerItems;
324     vogl::vector<vogleditor_stateTreeBufferItem*> m_bufferItems;
325     vogl::vector<vogleditor_stateTreeLightItem*> m_lightItems;
326     vogl::vector<vogleditor_stateTreeContextMaterialItem*> m_materialItems;
327     vogl::vector<vogleditor_stateTreeMatrixStackItem*> m_matrixStackItems;
328     vogl::vector<vogleditor_stateTreeQueryItem*> m_queryItems;
329     vogl::vector<vogleditor_stateTreeRenderbufferItem*> m_renderbufferItems;
330     vogl::vector<vogleditor_stateTreeVertexArrayItem*> m_vertexArrayItems;
331     vogl::vector<vogleditor_stateTreeFramebufferItem*> m_framebufferItems;
332     vogl::vector<vogleditor_stateTreeShaderItem*> m_shaderItems;
333     vogl::vector<vogleditor_stateTreeProgramItem*> m_programItems;
334     vogl::vector<vogleditor_stateTreeSyncItem*> m_syncItems;
335     vogl::vector<vogleditor_stateTreeArbProgramItem*> m_arbProgramItems;
336     vogl::vector<vogleditor_stateTreeArbProgramEnvItem*> m_arbProgramEnvItems;
337 };
338
339 #endif // VOGLEDITOR_STATETREECONTEXTITEM_H