1 #include "vogleditor_qprogramexplorer.h"
2 #include "ui_vogleditor_qprogramexplorer.h"
4 #include "vogl_gl_object.h"
5 #include "vogl_gl_state_snapshot.h"
6 #include "vogl_program_state.h"
8 Q_DECLARE_METATYPE(vogl_program_state*);
9 Q_DECLARE_METATYPE(vogl_shader_state*);
11 vogleditor_QProgramExplorer::vogleditor_QProgramExplorer(QWidget *parent) :
13 ui(new Ui::vogleditor_QProgramExplorer)
17 ui->saveShaderButton->setEnabled(false);
20 vogleditor_QProgramExplorer::~vogleditor_QProgramExplorer()
25 void vogleditor_QProgramExplorer::clear()
27 ui->programListBox->clear();
28 ui->shaderListBox->clear();
30 ui->shaderTextEdit->clear();
33 uint vogleditor_QProgramExplorer::set_program_objects(vogl::vector<vogl_context_snapshot*> sharingContexts)
37 uint programCount = 0;
38 for (uint c = 0; c < sharingContexts.size(); c++)
40 vogl_gl_object_state_ptr_vec programObjects;
41 sharingContexts[c]->get_all_objects_of_category(cGLSTProgram, programObjects);
43 programCount += add_program_objects(programObjects);
49 uint vogleditor_QProgramExplorer::add_program_objects(vogl_gl_object_state_ptr_vec objects)
51 m_objects.append(objects);
53 for (vogl_gl_object_state_ptr_vec::iterator iter = objects.begin(); iter != objects.end(); iter++)
55 if ((*iter)->get_type() == cGLSTProgram)
57 vogl_program_state* pState = static_cast<vogl_program_state*>(*iter);
60 valueStr = valueStr.sprintf("Program %" PRIu64, pState->get_snapshot_handle());
62 ui->programListBox->addItem(valueStr, QVariant::fromValue(pState));
66 VOGL_ASSERT(!"Unhandled object type in vogleditor_QProgramExplorer");
70 return objects.size();
73 bool vogleditor_QProgramExplorer::set_active_program(unsigned long long programHandle)
75 bool bActivated = false;
77 for (vogl_gl_object_state_ptr_vec::iterator iter = m_objects.begin(); iter != m_objects.end(); iter++)
79 vogl_program_state* pState = static_cast<vogl_program_state*>(*iter);
80 if (pState->get_snapshot_handle() == programHandle)
82 ui->programListBox->setCurrentIndex(index);
92 void vogleditor_QProgramExplorer::on_programListBox_currentIndexChanged(int index)
94 ui->shaderListBox->clear();
96 int count = ui->programListBox->count();
97 if (index >= 0 && index < count)
99 vogl_program_state* pObjState = ui->programListBox->itemData(index).value<vogl_program_state*>();
100 if (pObjState == NULL)
102 VOGL_ASSERT(!"NULL object type in vogleditor_QProgramExplorer");
106 vogl_shader_state_vec& attachedShaderVec = pObjState->get_shaders();
107 vogl_shader_state_vec& linkedShaderVec = pObjState->get_link_time_snapshot()->get_shaders();
110 for (vogl_shader_state_vec::iterator linkedIter = linkedShaderVec.begin(); linkedIter != linkedShaderVec.end(); linkedIter++)
112 vogl_shader_state* pShaderState = linkedIter;
113 valueStr = valueStr.sprintf("Linked Shader %" PRIu64 " - %s", pShaderState->get_snapshot_handle(), g_gl_enums.find_gl_name(pShaderState->get_shader_type()));
114 ui->shaderListBox->addItem(valueStr, QVariant::fromValue(pShaderState));
117 for (vogl_shader_state_vec::iterator attachedIter = attachedShaderVec.begin(); attachedIter != attachedShaderVec.end(); attachedIter++)
119 vogl_shader_state* pShaderState = attachedIter;
120 valueStr = valueStr.sprintf("Attached Shader %" PRIu64 " - %s", pShaderState->get_snapshot_handle(), g_gl_enums.find_gl_name(pShaderState->get_shader_type()));
121 ui->shaderListBox->addItem(valueStr, QVariant::fromValue(pShaderState));
126 void vogleditor_QProgramExplorer::on_shaderListBox_currentIndexChanged(int index)
128 ui->shaderTextEdit->clear();
130 int count = ui->shaderListBox->count();
131 if (index >= 0 && index < count)
133 vogl_shader_state* pObjState = ui->shaderListBox->itemData(index).value<vogl_shader_state*>();
134 if (pObjState == NULL)
136 VOGL_ASSERT(!"NULL shader object type in vogleditor_QProgramExplorer");
140 ui->shaderTextEdit->setText(pObjState->get_source().c_str());
144 ui->saveShaderButton->setEnabled(false);
147 void vogleditor_QProgramExplorer::on_shaderTextEdit_textChanged()
149 ui->saveShaderButton->setEnabled(true);
152 void vogleditor_QProgramExplorer::on_saveShaderButton_clicked()
154 int index = ui->shaderListBox->currentIndex();
155 if (index >= 0 && ui->shaderListBox->count() > 0)
157 vogl_shader_state* pObjState = ui->shaderListBox->itemData(index).value<vogl_shader_state*>();
158 if (pObjState == NULL)
160 VOGL_ASSERT(!"NULL shader object type in vogleditor_QProgramExplorer");
164 pObjState->set_source(ui->shaderTextEdit->toPlainText().toStdString().c_str());
166 ui->saveShaderButton->setEnabled(false);
168 vogl_program_state* pProgramState = ui->programListBox->itemData(index).value<vogl_program_state*>();
169 emit program_edited(pProgramState);