code format
This commit is contained in:
@@ -1,51 +1,54 @@
|
||||
/*
|
||||
QGL Framebuffer
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL Framebuffer
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include "glframebuffer.h"
|
||||
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include <QTime>
|
||||
|
||||
|
||||
Framebuffer::Framebuffer(QOpenGLExtraFunctions * f_, int colorAttachments_, bool withDepth, GLenum colorFormat_, GLenum _target)
|
||||
: f(f_), pbo(GL_PIXEL_PACK_BUFFER, GL_STREAM_DRAW) {
|
||||
: f(f_)
|
||||
, pbo(GL_PIXEL_PACK_BUFFER, GL_STREAM_DRAW) {
|
||||
is_depth = withDepth;
|
||||
target_ = _target;
|
||||
target_ = _target;
|
||||
color_formats.fill(colorFormat_, colorAttachments_);
|
||||
colors.fill(0, colorAttachments_);
|
||||
fbo = drbo = 0;
|
||||
tex_d = 0;
|
||||
wid = hei = 0;
|
||||
tex_d = 0;
|
||||
wid = hei = 0;
|
||||
pbo_queried = 0;
|
||||
is_changed = false;
|
||||
is_changed = false;
|
||||
}
|
||||
|
||||
|
||||
Framebuffer::Framebuffer(QOpenGLExtraFunctions * f_, QVector<GLenum> colors_, bool withDepth, GLenum _target)
|
||||
: f(f_), pbo(GL_PIXEL_PACK_BUFFER, GL_STREAM_DRAW) {
|
||||
is_depth = withDepth;
|
||||
target_ = _target;
|
||||
: f(f_)
|
||||
, pbo(GL_PIXEL_PACK_BUFFER, GL_STREAM_DRAW) {
|
||||
is_depth = withDepth;
|
||||
target_ = _target;
|
||||
color_formats = colors_;
|
||||
colors.fill(0, colors_.size());
|
||||
fbo = drbo = 0;
|
||||
tex_d = 0;
|
||||
wid = hei = 0;
|
||||
tex_d = 0;
|
||||
wid = hei = 0;
|
||||
pbo_queried = 0;
|
||||
is_changed = false;
|
||||
is_changed = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +70,7 @@ void Framebuffer::resize(int width, int height, bool force) {
|
||||
if (fbo > 0) deleteGLFramebuffer(fbo);
|
||||
f->glGenFramebuffers(1, &fbo);
|
||||
f->glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
//qDebug() << "resize" << f << wid << hei << fbo;
|
||||
// qDebug() << "resize" << f << wid << hei << fbo;
|
||||
for (int i = 0; i < colors.size(); ++i) {
|
||||
deleteGLTexture(f, colors[i]);
|
||||
createGLTexture(f, colors[i], width, height, color_formats[i], target_);
|
||||
@@ -103,10 +106,10 @@ void Framebuffer::resize(int width, int height, bool force) {
|
||||
void Framebuffer::reinit() {
|
||||
pbo.reinit();
|
||||
colors.fill(0);
|
||||
fbo = drbo = 0;
|
||||
tex_d = 0;
|
||||
fbo = drbo = 0;
|
||||
tex_d = 0;
|
||||
pbo_queried = 0;
|
||||
is_changed = true;
|
||||
is_changed = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -152,8 +155,7 @@ uint Framebuffer::getPoint() const {
|
||||
uint ret = 0;
|
||||
pbo.bind(f);
|
||||
void * map = pbo.map(f, GL_MAP_READ_BIT, sizeof(uint));
|
||||
if (map)
|
||||
memcpy(&ret, map, sizeof(uint));
|
||||
if (map) memcpy(&ret, map, sizeof(uint));
|
||||
pbo.unmap(f);
|
||||
pbo.release(f);
|
||||
return ret;
|
||||
@@ -166,8 +168,7 @@ QVector<uint> Framebuffer::getPointsByte() const {
|
||||
ret.resize(pbo_queried);
|
||||
pbo.bind(f);
|
||||
void * map = pbo.map(f, GL_MAP_READ_BIT, pbo_queried * sizeof(uint));
|
||||
if (map)
|
||||
memcpy(ret.data(), map, pbo_queried * sizeof(uint));
|
||||
if (map) memcpy(ret.data(), map, pbo_queried * sizeof(uint));
|
||||
pbo.unmap(f);
|
||||
pbo.release(f);
|
||||
return ret;
|
||||
@@ -180,8 +181,7 @@ QVector<QVector4D> Framebuffer::getPointsFloat() const {
|
||||
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));
|
||||
if (map) memcpy(ret.data(), map, pbo_queried * sizeof(QVector4D));
|
||||
pbo.unmap(f);
|
||||
pbo.release(f);
|
||||
return ret;
|
||||
@@ -191,12 +191,11 @@ QVector<QVector4D> Framebuffer::getPointsFloat() const {
|
||||
QImage Framebuffer::getImage() const {
|
||||
QImage ret;
|
||||
if (!pbo.isInit() || (pbo_queried == 0)) return ret;
|
||||
ret = QImage(size(), QImage::Format_RGBA8888);
|
||||
ret = QImage(size(), QImage::Format_RGBA8888);
|
||||
int bytes = width() * height() * 4;
|
||||
pbo.bind(f);
|
||||
void * map = pbo.map(f, GL_MAP_READ_BIT, bytes);
|
||||
if (map)
|
||||
memcpy(ret.bits(), map, bytes);
|
||||
if (map) memcpy(ret.bits(), map, bytes);
|
||||
pbo.unmap(f);
|
||||
pbo.release(f);
|
||||
return ret;
|
||||
@@ -277,7 +276,7 @@ void Framebuffer::unsetWriteBuffers() {
|
||||
void Framebuffer::enablePixelBuffer() {
|
||||
pbo.init(f);
|
||||
pbo.bind(f);
|
||||
pbo.resize(f, width()*height()*4*4);
|
||||
pbo.resize(f, width() * height() * 4 * 4);
|
||||
pbo.release(f);
|
||||
}
|
||||
|
||||
@@ -311,14 +310,12 @@ void Framebuffer::bindDepthTexture(int channel) {
|
||||
|
||||
|
||||
void Framebuffer::deleteGLRenderbuffer(GLuint & drbo) {
|
||||
if (drbo != 0)
|
||||
f->glDeleteRenderbuffers(1, &drbo);
|
||||
if (drbo != 0) f->glDeleteRenderbuffers(1, &drbo);
|
||||
drbo = 0;
|
||||
}
|
||||
|
||||
|
||||
void Framebuffer::deleteGLFramebuffer(GLuint & fbo) {
|
||||
if (fbo != 0)
|
||||
f->glDeleteFramebuffers(1, &fbo);
|
||||
if (fbo != 0) f->glDeleteFramebuffers(1, &fbo);
|
||||
fbo = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user