Merge pull request #191 from tomosu/fix_vector_thumbnail_and_crash_in_preview
fix vector preview problems
This commit is contained in:
commit
3c27c43f43
2 changed files with 55 additions and 62 deletions
|
@ -98,7 +98,6 @@ QtOfflineGL::QtOfflineGL(TDimension rasterSize, std::shared_ptr<TOfflineGL::Imp>
|
||||||
|
|
||||||
QtOfflineGL::~QtOfflineGL()
|
QtOfflineGL::~QtOfflineGL()
|
||||||
{
|
{
|
||||||
delete m_context;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
@ -7,15 +7,17 @@
|
||||||
#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();
|
||||||
|
@ -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();
|
||||||
|
|
Loading…
Reference in a new issue