Merge pull request #1678 from shun-iwasawa/fix_plastic_on_subsheet
Fix Plastic Mesh on SubXsheet for OSX
This commit is contained in:
commit
edc4d810b8
2 changed files with 68 additions and 4 deletions
|
@ -191,8 +191,10 @@ DrawableTextureDataP texture_utils::getTextureData(const TXsheet *xsh,
|
|||
xsh->getPlacement(xsh->getStageObjectTree()->getCurrentCameraId(), frame);
|
||||
bbox = (cameraAff.inv() * bbox).enlarge(1.0);
|
||||
|
||||
// Render the xsheet on the specified bbox
|
||||
|
||||
// Render the xsheet on the specified bbox
|
||||
#ifdef MACOSX
|
||||
xsh->getScene()->renderFrame(tex, frame, xsh, bbox, TAffine());
|
||||
#else
|
||||
// The call below will change context (I know, it's a shame :( )
|
||||
TGlContext currentContext = tglGetCurrentContext();
|
||||
{
|
||||
|
@ -200,6 +202,7 @@ DrawableTextureDataP texture_utils::getTextureData(const TXsheet *xsh,
|
|||
xsh->getScene()->renderFrame(tex, frame, xsh, bbox, TAffine());
|
||||
tglMakeCurrent(currentContext);
|
||||
}
|
||||
#endif
|
||||
|
||||
TRop::depremultiply(tex); // Stored textures are rendered nonpremultiplied
|
||||
|
||||
|
|
|
@ -49,6 +49,13 @@
|
|||
TOfflineGL *currentOfflineGL = 0;
|
||||
|
||||
#include <QProgressDialog>
|
||||
|
||||
#ifdef MACOSX
|
||||
#include <QSurfaceFormat>
|
||||
#include <QOffscreenSurface>
|
||||
#include <QOpenGLContext>
|
||||
#include <QOpenGLFramebufferObject>
|
||||
#endif
|
||||
//=============================================================================
|
||||
// Utility functions
|
||||
//=============================================================================
|
||||
|
@ -764,6 +771,7 @@ 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.
|
||||
|
||||
void ToonzScene::renderFrame(const TRaster32P &ras, int row, const TXsheet *xsh,
|
||||
const TRectD &placedRect,
|
||||
const TAffine &worldToPlacedAff) const {
|
||||
|
@ -782,11 +790,42 @@ void ToonzScene::renderFrame(const TRaster32P &ras, int row, const TXsheet *xsh,
|
|||
|
||||
TRect clipRect(ras->getBounds());
|
||||
|
||||
// fix for plastic tool applied to subxsheet
|
||||
#ifdef MACOSX
|
||||
QSurfaceFormat format;
|
||||
format.setProfile(QSurfaceFormat::CompatibilityProfile);
|
||||
|
||||
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();
|
||||
#else
|
||||
TOfflineGL ogl(ras->getSize());
|
||||
currentOfflineGL = &ogl;
|
||||
|
||||
ogl.makeCurrent();
|
||||
#endif
|
||||
{
|
||||
#ifdef MACOSX
|
||||
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();
|
||||
#endif
|
||||
glTranslated(0.5 * ras->getLx(), 0.5 * ras->getLy(), 0.0);
|
||||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
@ -802,12 +841,34 @@ void ToonzScene::renderFrame(const TRaster32P &ras, int row, const TXsheet *xsh,
|
|||
|
||||
painter.flushRasterImages();
|
||||
glFlush();
|
||||
#ifdef MACOSX
|
||||
QImage img =
|
||||
fb->toImage().scaled(QSize(ras->getLx(), ras->getLy()),
|
||||
Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
|
||||
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);
|
||||
#else
|
||||
TRop::over(ras, ogl.getRaster());
|
||||
#endif
|
||||
}
|
||||
ogl.doneCurrent();
|
||||
#ifdef MACOSX
|
||||
glMatrixMode(GL_MODELVIEW), glPopMatrix();
|
||||
glMatrixMode(GL_PROJECTION), glPopMatrix();
|
||||
|
||||
glPopAttrib();
|
||||
#else
|
||||
ogl.doneCurrent();
|
||||
currentOfflineGL = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue