Commit b9e6d2cb authored by Martin Schultz's avatar Martin Schultz

moved QtOpengl functionality to QtBaseViewer_qt

parent 60d919f3
......@@ -236,7 +236,7 @@ void glViewer::makeCurrent() {
#endif
// calling makeCurrent binds the default FBO when QOpenGLWidget is used
glWidget_->makeCurrent();
makeWidgetCurrent();
#if (QT_VERSION >= QT_VERSION_CHECK(5,4,4))
//restore the previously bound FBO, if it was not 0 as Qt Documentation says we shall not bind 0
......@@ -521,27 +521,6 @@ void glViewer::normalsMode(NormalsMode _mode)
//-----------------------------------------------------------------------------
void
glViewer::copyToImage( QImage& _image,
unsigned int _l, unsigned int _t,
unsigned int _w, unsigned int _h,
GLenum /* _buffer */ )
{
// makeCurrent();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 4))
_image = glWidget_->grabFramebuffer()
#else
_image = glWidget_->grabFrameBuffer(true)
#endif
.copy(_l, _t, _w, _h).convertToFormat(QImage::Format_RGB32);
}
//-----------------------------------------------------------------------------
void glViewer::updateGL()
{
if (!properties_.updateLocked() && isVisible() )
......@@ -2240,23 +2219,14 @@ void glViewer::snapshot(QImage& _image, int _width, int _height, bool _alpha, bo
aspect = (double)w / (double)h;
}
QFramebufferObjectFormat format;
format.setInternalTextureFormat(GL_RGBA);
format.setTextureTarget(GL_TEXTURE_2D);
// set the attachments as in the standard rendering
format.setAttachment(QFramebufferObject::CombinedDepthStencil);
// format.setAttachment(QFramebufferObject::CombinedDepthStencil);
// 16 samples per pixel as we want a nice snapshot. If this is not supported
// it will fall back to the maximal supported number of samples
format.setSamples(samples);
QFramebufferObject* fb = nullptr;
GLuint hnd;
QFramebufferObject fb(w,h,format);
if ( fb.isValid() ){
if ( createQFBO(fb,&hnd,w,h,&samples) ){
const GLuint prevFbo = ACG::GLState::getFramebufferDraw();
ACG::GLState::bindFramebuffer(GL_FRAMEBUFFER_EXT, fb.handle());
ACG::GLState::bindFramebuffer(GL_FRAMEBUFFER_EXT, hnd);
// Turn alpha on if demanded
ACG::Vec4f backColorBak;
......@@ -2275,7 +2245,7 @@ void glViewer::snapshot(QImage& _image, int _width, int _height, bool _alpha, bo
emit statusMessage(QString(tr("Could not find coordsys node, thus it will appear in the snapshot anyway.")));
}
}
backColorBak = properties()->backgroundColor();
newBack = ACG::Vec4f(backColorBak[0], backColorBak[1], backColorBak[2], (_alpha ? 0.0f : 1.0f));
......@@ -2298,18 +2268,19 @@ void glViewer::snapshot(QImage& _image, int _width, int _height, bool _alpha, bo
glDisable(GL_MULTISAMPLE);
//Qt FrameBuffer "toImage" function returns QImage::Format_ARGB32_Premultiplied. not desired
QFramebufferObjectFormat tempFormat;
tempFormat.setInternalTextureFormat(GL_RGBA);
tempFormat.setTextureTarget(GL_TEXTURE_2D);
QFramebufferObject temp(w,h, tempFormat);
if (format.samples() != 0)
QFramebufferObject* temp = nullptr;
GLuint tempHnd;
int testSamples = -1;
createQFBO(temp, &tempHnd, w, h, &testSamples);
if (testSamples != 0)
{
//cannot directly read from a multisampled framebuffer.
//create new one without sampling and read from it
QRect rect(QPoint(0, 0), QSize(w,h));
QFramebufferObject::blitFramebuffer(&temp, rect, &fb, rect);
ACG::GLState::bindFramebuffer(GL_FRAMEBUFFER_EXT, temp.handle());
//QFramebufferObject::blitFramebuffer(&temp, rect, &fb, rect);
blitQFBO(temp, rect, fb, rect);
ACG::GLState::bindFramebuffer(GL_FRAMEBUFFER_EXT, tempHnd);
}
//get the framebuffer data
......@@ -2334,9 +2305,12 @@ void glViewer::snapshot(QImage& _image, int _width, int _height, bool _alpha, bo
}
}
deleteQFBO(temp);
}
deleteQFBO(fb);
if(_width != 0 || _height != 0) {
// Reset viewport to former size
glstate_->viewport(left, bottom, bak_w, bak_h);
......
......@@ -92,6 +92,7 @@ class QSplitter;
class QImage;
class QSocketNotifier;
class QPropertyAnimation;
class QFramebufferObject;
struct PostProcessorInput;
......@@ -567,6 +568,14 @@ private:
void startGLDebugLogger();
void deleteGLDebugLogger();
// wrapper for glWidget make current
void makeWidgetCurrent();
// wrapper to create QFramebufferObject returns true if QFBO is valid if samples is -1 the default samples are retrieved
bool createQFBO(QOpenGLFramebufferObject* _ptr, GLuint* _handle, int _width, int _height, int* _samples);
void blitQFBO(QOpenGLFramebufferObject* _ptr1, const QRect& _size1, QOpenGLFramebufferObject* _ptr2, const QRect& _size2);
void deleteQFBO(QOpenGLFramebufferObject* _ptr);
//-------------------------------------------------------------- protected data
protected:
......
......@@ -73,6 +73,8 @@
#include <QOpenGLDebugLogger>
#endif
#include <QOpenGLWidget>
#include <QOpenGLFramebufferObject>
//== NAMESPACES ===============================================================
......@@ -134,6 +136,82 @@ void glViewer::processGLDebugMessage(const QOpenGLDebugMessage& msg)
#endif
//-----------------------------------------------------------------------------
void
glViewer::copyToImage( QImage& _image,
unsigned int _l, unsigned int _t,
unsigned int _w, unsigned int _h,
GLenum /* _buffer */ )
{
// makeCurrent();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 4))
_image = glWidget_->grabFramebuffer()
#else
_image = glWidget_->grabFrameBuffer(true)
#endif
.copy(_l, _t, _w, _h).convertToFormat(QImage::Format_RGB32);
}
//-----------------------------------------------------------------------------
void glViewer::makeWidgetCurrent()
{
glWidget_->makeCurrent();
}
//-----------------------------------------------------------------------------
bool glViewer::createQFBO(QOpenGLFramebufferObject* ptr, GLuint* _handle, int _width, int _height, int* _samples)
{
QFramebufferObjectFormat format;
format.setInternalTextureFormat(GL_RGBA);
format.setTextureTarget(GL_TEXTURE_2D);
if(*_samples > -1) //use -1 to indicate, that sample count is bit set
{
// set the attachments as in the standard rendering
format.setAttachment(QFramebufferObject::CombinedDepthStencil);
// 16 samples per pixel as we want a nice snapshot. If this is not supported
// it will fall back to the maximal supported number of samples
format.setSamples(*_samples);
std::cout<<"set samples"<<std::endl;
}
else //retrieve sample count otherwise
{
*_samples = format.samples();
std::cout<<"retrieved samples"<<std::endl;
}
QFramebufferObject* fb;
fb = new QFramebufferObject(_width, _height, format);
ptr = fb;
if(fb->isValid())
{
*_handle = fb->handle();
return true;
}
else
{
*_handle = 0;
return false;
}
}
//-----------------------------------------------------------------------------
void glViewer::blitQFBO(QOpenGLFramebufferObject* _ptr1, const QRect& _size1, QOpenGLFramebufferObject* _ptr2, const QRect& _size2)
{
QFramebufferObject::blitFramebuffer(_ptr1, _size1, _ptr2, _size2);
}
//-----------------------------------------------------------------------------
void glViewer::deleteQFBO(QOpenGLFramebufferObject* _ptr)
{
delete _ptr;
}
//=============================================================================
//=============================================================================
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment