git-svn-id: svn://db.shs.com.ru/libs@661 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2019-12-06 22:26:37 +00:00
parent 816c87d101
commit 1c73e79c65
11 changed files with 295 additions and 104 deletions

View File

@@ -93,9 +93,7 @@ void Framebuffer::resize(int width, int height, bool force) {
}
f->glBindFramebuffer(GL_FRAMEBUFFER, 0);
if (pbo.isInit()) {
pbo.bind(f);
pbo.resize(f, width*height*4);
pbo.release(f);
enablePixelBuffer();
}
is_changed = false;
}
@@ -119,7 +117,7 @@ void Framebuffer::queryPoint(int index, QPoint p) {
}
void Framebuffer::queryPoints(int index, QRect rect_) {
void Framebuffer::queryPoints(int index, QRect rect_, GLenum pixel_format) {
pbo_queried = 0;
if (index < 0 || index >= colors.size()) return;
rect_ &= rect();
@@ -127,7 +125,7 @@ void Framebuffer::queryPoints(int index, QRect rect_) {
f->glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
f->glReadBuffer(GL_COLOR_ATTACHMENT0 + index);
pbo.bind(f);
f->glReadPixels(rect_.x(), height() - rect_.bottom(), rect_.width(), rect_.height(), GL_RGBA, GL_UNSIGNED_BYTE, 0);
f->glReadPixels(rect_.x(), height() - rect_.bottom(), rect_.width(), rect_.height(), GL_RGBA, pixel_format, 0);
pbo_queried = rect_.width() * rect_.height();
pbo.release(f);
}
@@ -151,7 +149,7 @@ uint Framebuffer::getPoint() const {
}
QVector<uint> Framebuffer::getPoints() const {
QVector<uint> Framebuffer::getPointsByte() const {
QVector<uint> ret;
if (!pbo.isInit() || (pbo_queried == 0)) return ret;
ret.resize(pbo_queried);
@@ -165,6 +163,20 @@ QVector<uint> Framebuffer::getPoints() const {
}
QVector<QVector4D> Framebuffer::getPointsFloat() const {
QVector<QVector4D> ret;
if (!pbo.isInit() || (pbo_queried == 0)) return ret;
ret.resize(pbo_queried);
pbo.bind(f);
void * map = pbo.map(f, GL_MAP_READ_BIT, pbo_queried * sizeof(QVector4D));
if (map)
memcpy(ret.data(), map, pbo_queried * sizeof(QVector4D));
pbo.unmap(f);
pbo.release(f);
return ret;
}
QImage Framebuffer::getImage() const {
QImage ret;
if (!pbo.isInit() || (pbo_queried == 0)) return ret;
@@ -258,6 +270,9 @@ void Framebuffer::unsetWriteBuffers() {
void Framebuffer::enablePixelBuffer() {
pbo.init(f);
pbo.bind(f);
pbo.resize(f, width()*height()*4*4);
pbo.release(f);
}