fix plastic on subsheet

This commit is contained in:
shun-iwasawa 2017-12-12 20:27:21 +09:00
parent e2bc0c20a8
commit 0da010d9e2
2 changed files with 49 additions and 15 deletions

View file

@ -192,14 +192,7 @@ DrawableTextureDataP texture_utils::getTextureData(const TXsheet *xsh,
bbox = (cameraAff.inv() * bbox).enlarge(1.0);
// Render the xsheet on the specified bbox
// The call below will change context (I know, it's a shame :( )
TGlContext currentContext = tglGetCurrentContext();
{
tglDoneCurrent(currentContext);
xsh->getScene()->renderFrame(tex, frame, xsh, bbox, TAffine());
tglMakeCurrent(currentContext);
}
xsh->getScene()->renderFrame(tex, frame, xsh, bbox, TAffine());
TRop::depremultiply(tex); // Stored textures are rendered nonpremultiplied

View file

@ -763,6 +763,11 @@ void ToonzScene::renderFrame(const TRaster32P &ras, int row, const TXsheet *xsh,
//! placedRect,
//! with known world/placed reference change - and returns the result in a
//! 32-bit raster.
#include <QSurfaceFormat>
#include <QOffscreenSurface>
#include <QOpenGLContext>
#include <QOpenGLFramebufferObject>
void ToonzScene::renderFrame(const TRaster32P &ras, int row, const TXsheet *xsh,
const TRectD &placedRect,
const TAffine &worldToPlacedAff) const {
@ -781,11 +786,33 @@ void ToonzScene::renderFrame(const TRaster32P &ras, int row, const TXsheet *xsh,
TRect clipRect(ras->getBounds());
TOfflineGL ogl(ras->getSize());
currentOfflineGL = &ogl;
QSurfaceFormat format;
format.setProfile(QSurfaceFormat::CompatibilityProfile);
ogl.makeCurrent();
std::unique_ptr<QOffscreenSurface> surface(new QOffscreenSurface());
surface->setFormat(format);
// Enabling Qt::AA_ShareOpenGLContexts attribute in main()
surface->setScreen(QOpenGLContext::globalShareContext()->screen());
surface->create();
glPushAttrib(GL_ALL_ATTRIB_BITS);
glMatrixMode(GL_MODELVIEW), glPushMatrix();
glMatrixMode(GL_PROJECTION), glPushMatrix();
{
std::unique_ptr<QOpenGLFramebufferObject> fb(
new QOpenGLFramebufferObject(ras->getLx(), ras->getLy()));
fb->bind();
assert(glGetError() == GL_NO_ERROR);
glViewport(0, 0, ras->getLx(), ras->getLy());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, ras->getLx(), 0, ras->getLy());
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslated(0.5 * ras->getLx(), 0.5 * ras->getLy(), 0.0);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
@ -802,11 +829,25 @@ void ToonzScene::renderFrame(const TRaster32P &ras, int row, const TXsheet *xsh,
painter.flushRasterImages();
glFlush();
TRop::over(ras, ogl.getRaster());
}
ogl.doneCurrent();
QImage img =
fb->toImage().scaled(QSize(ras->getLx(), ras->getLy()),
Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
currentOfflineGL = 0;
int wrap = ras->getLx() * sizeof(TPixel32);
uchar *srcPix = img.bits();
uchar *dstPix = ras->getRawData() + wrap * (ras->getLy() - 1);
for (int y = 0; y < ras->getLy(); y++) {
memcpy(dstPix, srcPix, wrap);
dstPix -= wrap;
srcPix += wrap;
}
fb->release();
assert(glGetError() == GL_NO_ERROR);
}
glMatrixMode(GL_MODELVIEW), glPopMatrix();
glMatrixMode(GL_PROJECTION), glPopMatrix();
glPopAttrib();
}
//-----------------------------------------------------------------------------