1 #include "vogleditor_qprogramexplorer.h"
2 #include "ui_vogleditor_qprogramexplorer.h"
4 #include "vogl_gl_object.h"
5 #include "vogl_program_state.h"
7 Q_DECLARE_METATYPE(vogl_program_state*);
8 Q_DECLARE_METATYPE(vogl_shader_state*);
10 vogleditor_QProgramExplorer::vogleditor_QProgramExplorer(QWidget *parent) :
12 ui(new Ui::vogleditor_QProgramExplorer)
16 ui->saveShaderButton->setEnabled(false);
19 vogleditor_QProgramExplorer::~vogleditor_QProgramExplorer()
24 void vogleditor_QProgramExplorer::clear()
26 ui->programListBox->clear();
27 ui->shaderListBox->clear();
29 ui->shaderTextEdit->clear();
32 void vogleditor_QProgramExplorer::set_program_objects(vogl_gl_object_state_ptr_vec objects)
37 for (vogl_gl_object_state_ptr_vec::iterator iter = objects.begin(); iter != objects.end(); iter++)
39 if ((*iter)->get_type() == cGLSTProgram)
41 vogl_program_state* pState = static_cast<vogl_program_state*>(*iter);
44 valueStr = valueStr.sprintf("Program %" PRIu64, pState->get_snapshot_handle());
46 ui->programListBox->addItem(valueStr, QVariant::fromValue(pState));
50 VOGL_ASSERT(!"Unhandled object type in vogleditor_QProgramExplorer");
55 bool vogleditor_QProgramExplorer::set_active_program(unsigned long long programHandle)
57 bool bActivated = false;
59 for (vogl_gl_object_state_ptr_vec::iterator iter = m_objects.begin(); iter != m_objects.end(); iter++)
61 vogl_program_state* pState = static_cast<vogl_program_state*>(*iter);
62 if (pState->get_snapshot_handle() == programHandle)
64 ui->programListBox->setCurrentIndex(index);
74 void vogleditor_QProgramExplorer::on_programListBox_currentIndexChanged(int index)
76 ui->shaderListBox->clear();
78 int count = ui->programListBox->count();
79 if (index >= 0 && index < count)
81 vogl_program_state* pObjState = ui->programListBox->itemData(index).value<vogl_program_state*>();
82 if (pObjState == NULL)
84 VOGL_ASSERT(!"NULL object type in vogleditor_QProgramExplorer");
88 vogl_shader_state_vec& attachedShaderVec = pObjState->get_shaders();
89 vogl_shader_state_vec& linkedShaderVec = pObjState->get_link_time_snapshot()->get_shaders();
92 for (vogl_shader_state_vec::iterator linkedIter = linkedShaderVec.begin(); linkedIter != linkedShaderVec.end(); linkedIter++)
94 vogl_shader_state* pShaderState = linkedIter;
95 valueStr = valueStr.sprintf("Linked Shader %" PRIu64 " - %s", pShaderState->get_snapshot_handle(), g_gl_enums.find_gl_name(pShaderState->get_shader_type()));
96 ui->shaderListBox->addItem(valueStr, QVariant::fromValue(pShaderState));
99 for (vogl_shader_state_vec::iterator attachedIter = attachedShaderVec.begin(); attachedIter != attachedShaderVec.end(); attachedIter++)
101 vogl_shader_state* pShaderState = attachedIter;
102 valueStr = valueStr.sprintf("Attached Shader %" PRIu64 " - %s", pShaderState->get_snapshot_handle(), g_gl_enums.find_gl_name(pShaderState->get_shader_type()));
103 ui->shaderListBox->addItem(valueStr, QVariant::fromValue(pShaderState));
108 void vogleditor_QProgramExplorer::on_shaderListBox_currentIndexChanged(int index)
110 ui->shaderTextEdit->clear();
112 int count = ui->shaderListBox->count();
113 if (index >= 0 && index < count)
115 vogl_shader_state* pObjState = ui->shaderListBox->itemData(index).value<vogl_shader_state*>();
116 if (pObjState == NULL)
118 VOGL_ASSERT(!"NULL shader object type in vogleditor_QProgramExplorer");
122 ui->shaderTextEdit->setText(pObjState->get_source().c_str());
126 ui->saveShaderButton->setEnabled(false);
129 void vogleditor_QProgramExplorer::on_shaderTextEdit_textChanged()
131 ui->saveShaderButton->setEnabled(true);
134 void vogleditor_QProgramExplorer::on_saveShaderButton_clicked()
136 int index = ui->shaderListBox->currentIndex();
137 if (index >= 0 && ui->shaderListBox->count() > 0)
139 vogl_shader_state* pObjState = ui->shaderListBox->itemData(index).value<vogl_shader_state*>();
140 if (pObjState == NULL)
142 VOGL_ASSERT(!"NULL shader object type in vogleditor_QProgramExplorer");
146 pObjState->set_source(ui->shaderTextEdit->toPlainText().toStdString().c_str());
148 ui->saveShaderButton->setEnabled(false);
150 vogl_program_state* pProgramState = ui->programListBox->itemData(index).value<vogl_program_state*>();
151 emit program_edited(pProgramState);