1 #include "vogleditor_qframebufferexplorer.h"
2 #include "ui_vogleditor_qframebufferexplorer.h"
4 #include "vogleditor_qtextureexplorer.h"
6 #include "vogl_gl_object.h"
7 #include "vogl_gl_state_snapshot.h"
8 #include "vogl_fbo_state.h"
13 vogl_framebuffer_state* pFBOState;
14 vogl_default_framebuffer_state* pDefaultFBState;
15 } vogl_framebuffer_container;
17 Q_DECLARE_METATYPE(vogl_framebuffer_container);
19 vogleditor_QFramebufferExplorer::vogleditor_QFramebufferExplorer(QWidget *parent) :
21 ui(new Ui::vogleditor_QFramebufferExplorer),
22 m_pDefaultFramebufferState(NULL)
26 m_colorExplorerLayout = new QVBoxLayout();
27 m_depthExplorerLayout = new QVBoxLayout();
28 m_stencilExplorerLayout = new QVBoxLayout();
30 ui->colorBufferGroupBox->setLayout(m_colorExplorerLayout);
32 m_depthExplorer = new vogleditor_QTextureExplorer(ui->depthBufferGroupBox);
33 m_depthExplorerLayout->addWidget(m_depthExplorer);
34 ui->depthBufferGroupBox->setLayout(m_depthExplorerLayout);
36 m_stencilExplorer = new vogleditor_QTextureExplorer(ui->stencilBufferGroupBox);
37 m_stencilExplorerLayout->addWidget(m_stencilExplorer);
38 ui->stencilBufferGroupBox->setLayout(m_stencilExplorerLayout);
40 connect(ui->framebufferObjectListbox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectedFramebufferIndexChanged(int)));
43 vogleditor_QFramebufferExplorer::~vogleditor_QFramebufferExplorer()
48 delete m_colorExplorerLayout;
49 delete m_depthExplorerLayout;
50 delete m_stencilExplorerLayout;
52 delete m_depthExplorer;
53 m_depthExplorer = NULL;
55 delete m_stencilExplorer;
56 m_stencilExplorer = NULL;
59 void vogleditor_QFramebufferExplorer::clear()
62 m_sharing_contexts.clear();
63 ui->framebufferObjectListbox->clear();
68 void vogleditor_QFramebufferExplorer::clearViewers()
70 m_depthExplorer->clear();
71 m_stencilExplorer->clear();
73 for (vogleditor_QTextureExplorer** iter = m_viewers.begin(); iter != m_viewers.end(); iter++)
75 m_colorExplorerLayout->takeAt(0);
84 uint vogleditor_QFramebufferExplorer::set_framebuffer_objects(vogl_context_snapshot* pContext, vogl::vector<vogl_context_snapshot*> sharingContexts, vogl_default_framebuffer_state* pDefaultFramebufferState)
88 m_sharing_contexts = sharingContexts;
90 uint framebufferCount = 0;
92 framebufferCount += set_default_framebuffer(pDefaultFramebufferState);
94 // framebuffers are not shared state objects, but they can reference shared objects,
95 // so only add the framebuffers from the main context
96 vogl_gl_object_state_ptr_vec framebufferObjects;
97 pContext->get_all_objects_of_category(cGLSTFramebuffer, framebufferObjects);
98 framebufferCount += add_framebuffer_objects(sharingContexts, framebufferObjects);
100 return framebufferCount;
103 uint vogleditor_QFramebufferExplorer::set_default_framebuffer(vogl_default_framebuffer_state* pDefaultFramebufferState)
106 if (pDefaultFramebufferState != NULL)
108 m_pDefaultFramebufferState = pDefaultFramebufferState;
110 // add default framebuffer
111 vogl_framebuffer_container defaultContainer;
112 defaultContainer.index = 0;
113 defaultContainer.pFBOState = NULL;
114 defaultContainer.pDefaultFBState = m_pDefaultFramebufferState;
115 ui->framebufferObjectListbox->addItem("Framebuffer 0 - (default framebuffer)", QVariant::fromValue(defaultContainer));
121 uint vogleditor_QFramebufferExplorer::add_framebuffer_objects(vogl::vector<vogl_context_snapshot*> sharingContexts, vogl_gl_object_state_ptr_vec objects)
123 m_objects.append(objects);
125 // add framebuffer objects
127 for (vogl_gl_object_state_ptr_vec::iterator iter = objects.begin(); iter != objects.end(); iter++)
129 vogl_framebuffer_state* pState = static_cast<vogl_framebuffer_state*>(*iter);
131 if (pState->get_attachments().size() > 0)
133 unsigned int width = 0;
134 unsigned int height = 0;
135 const vogl_framebuffer_attachment* pAttachment = &(pState->get_attachments().begin()->second);
136 if (pAttachment->get_type() == GL_TEXTURE)
138 for (uint c = 0; c < sharingContexts.size(); c++)
140 vogl_texture_state* pTexState = this->get_texture_attachment(*(sharingContexts[c]), pAttachment->get_handle());
141 if (pTexState != NULL)
143 width = pTexState->get_texture().get_width();
144 height = pTexState->get_texture().get_height();
149 else if (pAttachment->get_type() == GL_RENDERBUFFER)
151 for (uint c = 0; c < sharingContexts.size(); c++)
153 vogl_renderbuffer_state* pRbState = this->get_renderbuffer_attachment(*(sharingContexts[c]), pAttachment->get_handle());
154 if (pRbState != NULL)
156 width = pRbState->get_texture().get_texture().get_width();
157 height = pRbState->get_texture().get_texture().get_height();
163 valueStr = valueStr.sprintf("Framebuffer %" PRIu64 " - (%u x %u) %d attachments", pState->get_snapshot_handle(), width, height, pState->get_attachments().size());
167 valueStr = valueStr.sprintf("Framebuffer %" PRIu64 " - %d attachments", pState->get_snapshot_handle(), pState->get_attachments().size());
170 vogl_framebuffer_container container;
171 container.index = ui->framebufferObjectListbox->count();
172 container.pFBOState = pState;
173 container.pDefaultFBState = NULL;
175 ui->framebufferObjectListbox->addItem(valueStr, QVariant::fromValue(container));
178 return objects.size();
181 bool vogleditor_QFramebufferExplorer::set_active_framebuffer(unsigned long long framebufferHandle)
183 bool bDisplayedFramebuffer = false;
185 if (framebufferHandle == 0)
187 ui->framebufferObjectListbox->setCurrentIndex(0);
188 bDisplayedFramebuffer = true;
192 for (int index = 0; index < ui->framebufferObjectListbox->count(); index++)
194 vogl_framebuffer_container container = ui->framebufferObjectListbox->itemData(index).value<vogl_framebuffer_container>();
195 vogl_framebuffer_state* pState = container.pFBOState;
196 if (pState != NULL && pState->get_snapshot_handle() == framebufferHandle)
198 ui->framebufferObjectListbox->setCurrentIndex(index);
199 bDisplayedFramebuffer = true;
204 return bDisplayedFramebuffer;
207 void vogleditor_QFramebufferExplorer::selectedFramebufferIndexChanged(int index)
211 if (index < 0 || index >= ui->framebufferObjectListbox->count())
216 vogl_gl_object_state_ptr_vec colorVec;
217 vogl_gl_object_state_ptr_vec depthVec;
218 vogl_gl_object_state_ptr_vec stencilVec;
220 #define ADD_COLOR_BUFFER_VIEWER vogleditor_QTextureExplorer* pViewer = new vogleditor_QTextureExplorer(ui->colorBufferGroupBox); m_colorExplorerLayout->addWidget(pViewer); m_viewers.push_back(pViewer);
222 vogl_framebuffer_container container = ui->framebufferObjectListbox->itemData(index).value<vogl_framebuffer_container>();
225 vogl_default_framebuffer_state* pDefaultState = container.pDefaultFBState;
227 vogl_texture_state& rFrontLeft = pDefaultState->get_texture(cDefFramebufferFrontLeft);
228 vogl_texture_state& rBackLeft = pDefaultState->get_texture(cDefFramebufferBackLeft);
229 vogl_texture_state& rFrontRight = pDefaultState->get_texture(cDefFramebufferFrontRight);
230 vogl_texture_state& rBackRight = pDefaultState->get_texture(cDefFramebufferBackRight);
231 vogl_texture_state& rDepthStencil = pDefaultState->get_texture(cDefFramebufferDepthStencil);
233 if (rFrontLeft.is_valid())
235 colorVec.push_back(&rFrontLeft);
236 ADD_COLOR_BUFFER_VIEWER
237 pViewer->add_texture_object(rFrontLeft, "GL_FRONT_LEFT");
239 if (rBackLeft.is_valid())
241 colorVec.push_back(&rBackLeft);
242 ADD_COLOR_BUFFER_VIEWER
243 pViewer->add_texture_object(rBackLeft, "GL_BACK_LEFT");
245 if (rFrontRight.is_valid())
247 colorVec.push_back(&rFrontRight);
248 ADD_COLOR_BUFFER_VIEWER
249 pViewer->add_texture_object(rFrontRight, "GL_FRONT_RIGHT");
251 if (rBackRight.is_valid())
253 colorVec.push_back(&rBackRight);
254 ADD_COLOR_BUFFER_VIEWER
255 pViewer->add_texture_object(rBackRight, "GL_BACK_RIGHT");
258 if (rDepthStencil.is_valid()) { depthVec.push_back(&rDepthStencil); m_depthExplorer->add_texture_object(rDepthStencil, "GL_DEPTH"); }
259 if (rDepthStencil.is_valid()) { stencilVec.push_back(&rDepthStencil); m_stencilExplorer->add_texture_object(rDepthStencil, "GL_STENCIL"); }
263 vogl_framebuffer_state* pState = container.pFBOState;
266 const vogl_framebuffer_state::GLenum_to_attachment_map& rAttachments = pState->get_attachments();
267 for (vogl_framebuffer_state::GLenum_to_attachment_map::const_iterator iter = rAttachments.begin(); iter != rAttachments.end(); iter++)
269 const vogl_framebuffer_attachment* pAttachment = &(iter->second);
270 if (pAttachment->get_type() == GL_TEXTURE)
272 for (uint c = 0; c < m_sharing_contexts.size(); c++)
274 vogl_texture_state* pTexState = this->get_texture_attachment(*(m_sharing_contexts[c]), pAttachment->get_handle());
275 if (pTexState != NULL)
277 if (iter->first == GL_DEPTH_ATTACHMENT ||
278 iter->first == GL_DEPTH)
280 depthVec.push_back(pTexState);
282 else if (iter->first == GL_STENCIL_ATTACHMENT ||
283 iter->first == GL_STENCIL)
285 stencilVec.push_back(pTexState);
289 colorVec.push_back(pTexState);
291 ADD_COLOR_BUFFER_VIEWER
297 else if (pAttachment->get_type() == GL_RENDERBUFFER)
299 for (uint c = 0; c < m_sharing_contexts.size(); c++)
301 vogl_renderbuffer_state* pRbState = this->get_renderbuffer_attachment(*(m_sharing_contexts[c]), pAttachment->get_handle());
302 if (pRbState != NULL)
304 if (iter->first == GL_DEPTH_ATTACHMENT ||
305 iter->first == GL_DEPTH)
307 depthVec.push_back(pRbState);
309 else if (iter->first == GL_STENCIL_ATTACHMENT ||
310 iter->first == GL_STENCIL)
312 stencilVec.push_back(pRbState);
316 colorVec.push_back(pRbState);
318 ADD_COLOR_BUFFER_VIEWER
326 VOGL_ASSERT(!"Unhandled framebuffer attachment type");
332 #undef ADD_COLOR_BUFFER_VIEWER
334 if (colorVec.size() == 0)
336 ui->colorBufferGroupBox->setMinimumHeight(50);
340 uint totalHeight = 0;
341 uint viewerIndex = 0;
342 for (vogleditor_QTextureExplorer** iter = m_viewers.begin(); iter != m_viewers.end(); iter++)
344 (*iter)->set_zoom_factor(0.2);
346 // use index which was passed in as parameter
349 (*iter)->set_texture_objects(colorVec);
350 (*iter)->set_active_texture(colorVec[viewerIndex]->get_snapshot_handle());
353 // for better visibility, adjust height based on combined preferred heights
354 totalHeight += (*iter)->get_preferred_height();
355 (*iter)->setFixedHeight((*iter)->get_preferred_height());
358 connect(*iter, SIGNAL(zoomFactorChanged(double)), this, SLOT(slot_zoomFactorChanged(double)));
362 if (depthVec.size() == 0)
364 m_depthExplorer->setVisible(false);
365 ui->depthBufferGroupBox->setMinimumHeight(50);
369 m_depthExplorer->setVisible(true);
370 m_depthExplorer->set_zoom_factor(0.2);
371 // use index which was passed in as parameter
374 m_depthExplorer->set_texture_objects(depthVec);
375 m_depthExplorer->set_active_texture(depthVec[0]->get_snapshot_handle());
377 connect(m_depthExplorer, SIGNAL(zoomFactorChanged(double)), this, SLOT(slot_zoomFactorChanged(double)));
378 m_depthExplorer->setMinimumHeight(m_depthExplorer->get_preferred_height());
381 if (stencilVec.size() == 0)
383 m_stencilExplorer->setVisible(false);
384 ui->stencilBufferGroupBox->setMinimumHeight(50);
388 m_stencilExplorer->setVisible(true);
389 m_stencilExplorer->set_zoom_factor(0.2);
390 // use index which was passed in as parameter
393 m_stencilExplorer->set_texture_objects(stencilVec);
394 m_stencilExplorer->set_active_texture(stencilVec[0]->get_snapshot_handle());
396 connect(m_stencilExplorer, SIGNAL(zoomFactorChanged(double)), this, SLOT(slot_zoomFactorChanged(double)));
397 m_stencilExplorer->setMinimumHeight(m_stencilExplorer->get_preferred_height());
401 vogl_texture_state* vogleditor_QFramebufferExplorer::get_texture_attachment(vogl_context_snapshot& context, unsigned int handle)
403 vogl_gl_object_state_ptr_vec textureVec;
404 context.get_all_objects_of_category(cGLSTTexture, textureVec);
406 vogl_texture_state* pTexState = NULL;
407 for (vogl_gl_object_state_ptr_vec::iterator texIter = textureVec.begin(); texIter != textureVec.end(); texIter++)
409 if ((*texIter)->get_snapshot_handle() == handle)
411 pTexState = static_cast<vogl_texture_state*>(*texIter);
419 vogl_renderbuffer_state* vogleditor_QFramebufferExplorer::get_renderbuffer_attachment(vogl_context_snapshot& context, unsigned int handle)
421 vogl_gl_object_state_ptr_vec renderbufferVec;
422 context.get_all_objects_of_category(cGLSTRenderbuffer, renderbufferVec);
424 vogl_renderbuffer_state* pRenderbufferState = NULL;
425 for (vogl_gl_object_state_ptr_vec::iterator texIter = renderbufferVec.begin(); texIter != renderbufferVec.end(); texIter++)
427 if ((*texIter)->get_snapshot_handle() == handle)
429 pRenderbufferState = static_cast<vogl_renderbuffer_state*>(*texIter);
434 return pRenderbufferState;
437 void vogleditor_QFramebufferExplorer::slot_zoomFactorChanged(double zoomFactor)
439 VOGL_NOTE_UNUSED(zoomFactor);
441 uint totalHeight = 0;
442 for (vogleditor_QTextureExplorer** iter = m_viewers.begin(); iter != m_viewers.end(); iter++)
444 // for better visibility, adjust height based on combined preferred heights
445 totalHeight += (*iter)->get_preferred_height();
446 (*iter)->setFixedHeight((*iter)->get_preferred_height());
449 m_depthExplorer->setMinimumHeight(m_depthExplorer->get_preferred_height());
450 m_stencilExplorer->setMinimumHeight(m_stencilExplorer->get_preferred_height());