mirror of https://github.com/axmolengine/axmol.git
Fixup
OpenGL: read screen pixels only works: AFTER_DRAW and BEFORE_END_FRAME
This commit is contained in:
parent
c542037e7c
commit
b956637c74
|
@ -88,23 +88,18 @@ void captureScreen(std::function<void(RefPtr<Image>)> imageCallback)
|
||||||
auto renderer = director->getRenderer();
|
auto renderer = director->getRenderer();
|
||||||
auto eventDispatcher = director->getEventDispatcher();
|
auto eventDispatcher = director->getEventDispatcher();
|
||||||
|
|
||||||
s_captureScreenCommand.init((std::numeric_limits<float>::max)());
|
|
||||||
s_captureScreenCommand.func = [=]{
|
|
||||||
renderer->readPixels(nullptr, [=](const backend::PixelBufferDescriptor& pbd) {
|
|
||||||
if(pbd) {
|
|
||||||
auto image = utils::makeInstance<Image>(&Image::initWithRawData, pbd._data.getBytes(), pbd._data.getSize(), pbd._width, pbd._height, 8, false);
|
|
||||||
imageCallback(image);
|
|
||||||
}
|
|
||||||
else imageCallback(nullptr);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
s_captureScreenListener = eventDispatcher->addCustomEventListener(Director::EVENT_AFTER_DRAW, [=](EventCustom* /*event*/) {
|
s_captureScreenListener = eventDispatcher->addCustomEventListener(Director::EVENT_AFTER_DRAW, [=](EventCustom* /*event*/) {
|
||||||
eventDispatcher->removeEventListener(s_captureScreenListener);
|
eventDispatcher->removeEventListener(s_captureScreenListener);
|
||||||
s_captureScreenListener = nullptr;
|
s_captureScreenListener = nullptr;
|
||||||
|
|
||||||
renderer->addCommand(&s_captureScreenCommand);
|
// !!!GL: AFTER_DRAW and BEFORE_END_FRAME
|
||||||
renderer->render();
|
renderer->readPixels(nullptr, [=](const backend::PixelBufferDescriptor& pbd) {
|
||||||
|
if (pbd) {
|
||||||
|
auto image = utils::makeInstance<Image>(&Image::initWithRawData, pbd._data.getBytes(), pbd._data.getSize(), pbd._width, pbd._height, 8, false);
|
||||||
|
imageCallback(image);
|
||||||
|
}
|
||||||
|
else imageCallback(nullptr);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue