Merge pull request #191 from tomosu/fix_vector_thumbnail_and_crash_in_preview

fix vector preview problems
This commit is contained in:
Keisuke Ogaki 2016-04-19 18:51:28 +09:00
commit 3c27c43f43
2 changed files with 55 additions and 62 deletions

View file

@ -98,7 +98,6 @@ QtOfflineGL::QtOfflineGL(TDimension rasterSize, std::shared_ptr<TOfflineGL::Imp>
QtOfflineGL::~QtOfflineGL() QtOfflineGL::~QtOfflineGL()
{ {
delete m_context;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -107,22 +106,22 @@ void QtOfflineGL::createContext(TDimension rasterSize, std::shared_ptr<TOfflineG
{ {
// Imposto il formato dei Pixel (pixelFormat) // Imposto il formato dei Pixel (pixelFormat)
/* /*
32, // 32-bit color depth 32, // 32-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored 0, 0, 0, 0, 0, 0, // color bits ignored
8, // no alpha buffer 8, // no alpha buffer
0, // shift bit ignored 0, // shift bit ignored
0, // no accumulation buffer 0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored 0, 0, 0, 0, // accum bits ignored
32, // 32-bit z-buffer 32, // 32-bit z-buffer
32, // max stencil buffer 32, // max stencil buffer
0, // no auxiliary buffer 0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer PFD_MAIN_PLANE, // main layer
0, // reserved 0, // reserved
0, 0, 0 // layer masks ignored 0, 0, 0 // layer masks ignored
ATTENZIONE !! SU MAC IL FORMATO E' DIVERSO (casomai possiamo mettere un ifdef) ATTENZIONE !! SU MAC IL FORMATO E' DIVERSO (casomai possiamo mettere un ifdef)
SPECIFICHE MAC = depth_size 24, stencil_size 8, alpha_size 1 SPECIFICHE MAC = depth_size 24, stencil_size 8, alpha_size 1
*/ */
@ -155,36 +154,36 @@ void QtOfflineGL::createContext(TDimension rasterSize, std::shared_ptr<TOfflineG
fmt.setDirectRendering(false); fmt.setDirectRendering(false);
#endif #endif
#endif #endif
/* FIXME: ここでいう QPixmap は Level Strip のセルに相当する.
QPixmap GLContext bind
QLContext .
*/
printf("QPixmap(%d, %d)\n", rasterSize.lx, rasterSize.ly);
//QPixmap *m_pixmap = new QPixmap(rasterSize.lx, rasterSize.ly);
// Inizializzo un contesto openGL utilizzando una QPixmap QSurfaceFormat format;
format.setProfile(QSurfaceFormat::CompatibilityProfile);
m_context = new QOpenGLContext(); m_surface = std::make_shared<QOffscreenSurface>();
//m_context = new QGLContext(fmt); m_surface->setFormat(format);
m_surface = new QOffscreenSurface();
m_surface->setFormat(m_context->format());
//QSurfaceFormat sfmt = QGuiApplication::focusWindow()->format();
m_surface->create(); m_surface->create();
printf("create context:%p [thread:0x%x]\n", m_context, QThread::currentThreadId()); m_context = std::make_shared<QOpenGLContext>();
//m_context->setFormat(sfmt); m_context->setFormat(format);
m_context->create();
m_context->makeCurrent(m_surface.get());
QOpenGLFramebufferObjectFormat fbo_format;
m_fbo = std::make_shared<QOpenGLFramebufferObject>(rasterSize.lx, rasterSize.ly, fbo_format);
m_fbo->bind();
printf("create context:%p [thread:0x%x]\n", m_context.get(), QThread::currentThreadId());
// Creo il contesto OpenGL - assicurandomi che sia effettivamente creato // Creo il contesto OpenGL - assicurandomi che sia effettivamente creato
// NOTA: Se il contesto non viene creato, di solito basta ritentare qualche volta. // NOTA: Se il contesto non viene creato, di solito basta ritentare qualche volta.
bool ret = m_context->create();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void QtOfflineGL::makeCurrent() void QtOfflineGL::makeCurrent()
{ {
if (m_context) { if (m_context) {
m_context->makeCurrent(m_surface); m_context->moveToThread(QThread::currentThread());
m_context->makeCurrent(m_surface.get());
} }
// else // else
// m_oldContext = 0; // m_oldContext = 0;
@ -225,15 +224,7 @@ void QtOfflineGL::getRaster(TRaster32P raster)
int ly = raster->getLy(); int ly = raster->getLy();
raster->lock(); raster->lock();
glReadPixels(0, 0, lx, ly, raster->copy( TRaster32P(lx, ly, m_fbo->width(), (TPixelRGBM32 *)m_fbo->toImage(false).bits(), false) );
GL_RGBA /*GL_BGRA_EXT*/, GL_UNSIGNED_BYTE,
raster->getRawData());
#ifdef WIN32
swapRedBlueChannels(raster->getRawData(), lx * ly);
#elif MACOSX
rightRotateBits(raster->getRawData(), lx * ly);
#endif
raster->unlock(); raster->unlock();
} }
@ -260,7 +251,6 @@ QtOfflineGLPBuffer::QtOfflineGLPBuffer(TDimension rasterSize)
QtOfflineGLPBuffer::~QtOfflineGLPBuffer() QtOfflineGLPBuffer::~QtOfflineGLPBuffer()
{ {
delete m_context;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -269,22 +259,22 @@ void QtOfflineGLPBuffer::createContext(TDimension rasterSize)
{ {
// Imposto il formato dei Pixel (pixelFormat) // Imposto il formato dei Pixel (pixelFormat)
/* /*
32, // 32-bit color depth 32, // 32-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored 0, 0, 0, 0, 0, 0, // color bits ignored
8, // no alpha buffer 8, // no alpha buffer
0, // shift bit ignored 0, // shift bit ignored
0, // no accumulation buffer 0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored 0, 0, 0, 0, // accum bits ignored
32, // 32-bit z-buffer 32, // 32-bit z-buffer
32, // max stencil buffer 32, // max stencil buffer
0, // no auxiliary buffer 0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer PFD_MAIN_PLANE, // main layer
0, // reserved 0, // reserved
0, 0, 0 // layer masks ignored 0, 0, 0 // layer masks ignored
ATTENZIONE !! SU MAC IL FORMATO E' DIVERSO (casomai possiamo mettere un ifdef) ATTENZIONE !! SU MAC IL FORMATO E' DIVERSO (casomai possiamo mettere un ifdef)
SPECIFICHE MAC = depth_size 24, stencil_size 8, alpha_size 1 SPECIFICHE MAC = depth_size 24, stencil_size 8, alpha_size 1
*/ */
@ -321,15 +311,16 @@ void QtOfflineGLPBuffer::createContext(TDimension rasterSize)
while (pBufferSize < sizeMax) while (pBufferSize < sizeMax)
pBufferSize *= 2; pBufferSize *= 2;
m_context = new QGLPixelBuffer(QSize(pBufferSize, pBufferSize), fmt); m_context = std::make_shared<QGLPixelBuffer>(QSize(pBufferSize, pBufferSize), fmt);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void QtOfflineGLPBuffer::makeCurrent() void QtOfflineGLPBuffer::makeCurrent()
{ {
if (m_context) if (m_context){
m_context->makeCurrent(); m_context->makeCurrent();
}
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -7,17 +7,19 @@
#include <QGLFormat> #include <QGLFormat>
#include <QGLContext> #include <QGLContext>
#include <QGLPixelBuffer> #include <QGLPixelBuffer>
#include <QOpenGLFramebufferObject>
#include "tofflinegl.h" #include "tofflinegl.h"
class QtOfflineGL : public TOfflineGL::Imp class QtOfflineGL : public TOfflineGL::Imp
{ {
public: public:
QOpenGLContext *m_context; std::shared_ptr<QOpenGLContext> m_context;
QOpenGLContext *m_oldContext; std::shared_ptr<QOpenGLContext> m_oldContext;
QOffscreenSurface *m_surface; std::shared_ptr<QOffscreenSurface> m_surface;
std::shared_ptr<QOpenGLFramebufferObject> m_fbo;
QtOfflineGL(TDimension rasterSize, std::shared_ptr<TOfflineGL::Imp> shared); QtOfflineGL(TDimension rasterSize, std::shared_ptr<TOfflineGL::Imp> shared);
~QtOfflineGL(); ~QtOfflineGL();
void createContext(TDimension rasterSize, std::shared_ptr<TOfflineGL::Imp> shared); void createContext(TDimension rasterSize, std::shared_ptr<TOfflineGL::Imp> shared);
@ -35,7 +37,7 @@ public:
class QtOfflineGLPBuffer : public TOfflineGL::Imp class QtOfflineGLPBuffer : public TOfflineGL::Imp
{ {
public: public:
QGLPixelBuffer *m_context; std::shared_ptr<QGLPixelBuffer> m_context;
QtOfflineGLPBuffer(TDimension rasterSize); QtOfflineGLPBuffer(TDimension rasterSize);
~QtOfflineGLPBuffer(); ~QtOfflineGLPBuffer();