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

This commit is contained in:
2019-12-06 13:47:45 +00:00
parent c5bbf5ef8f
commit 6c409d0e12
14 changed files with 167 additions and 125 deletions

View File

@@ -191,7 +191,7 @@ QVector<float> Framebuffer::grabF(int index) const {
}
void Framebuffer::blit(int index_from, GLuint fb_to, int index_to, QRect from, QRect to, GLbitfield mask, GLenum filter) {
void Framebuffer::blit(int index_from, GLuint fb_to, int index_to, QRect from, QRect to, GLbitfield mask, GLenum filter) const {
if (index_from < 0 || index_from >= colors.size()) return;
GLenum e = GL_COLOR_ATTACHMENT0 + index_to;
f->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb_to);

View File

@@ -24,6 +24,7 @@
class Framebuffer
{
friend class FramebufferMipmap;
public:
Framebuffer(QOpenGLExtraFunctions * f_, int colorAttachments = 1, bool withDepth = true, GLenum colorFormat = GL_RGBA8, GLenum _target = GL_TEXTURE_2D);
Framebuffer(QOpenGLExtraFunctions * f_, QVector<GLenum> colors_, bool withDepth = true, GLenum _target = GL_TEXTURE_2D);
@@ -47,7 +48,7 @@ public:
QVector<uint> getPoints() const;
QImage getImage() const;
int queriedPoints() const {return pbo_queried;}
void blit(int index_from, GLuint fb_to, int index_to, QRect from, QRect to, GLbitfield mask = GL_COLOR_BUFFER_BIT, GLenum filter = GL_NEAREST);
void blit(int index_from, GLuint fb_to, int index_to, QRect from, QRect to, GLbitfield mask = GL_COLOR_BUFFER_BIT, GLenum filter = GL_NEAREST) const;
void resize(int width, int height, bool force = false);
void bind();

View File

@@ -0,0 +1,50 @@
/*
QGLView
Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QOpenGLExtraFunctions>
#include "glframebuffer_mipmap.h"
#include <QTime>
FramebufferMipmap::FramebufferMipmap(const Framebuffer & fb, int index_from_, int levels): src_fb(fb) {
index_from = index_from_;
for (int i = 0; i < levels; ++i)
fbo << new Framebuffer(fb.f, 1, false, fb.color_formats[index_from]);
}
FramebufferMipmap::~FramebufferMipmap() {
}
void FramebufferMipmap::resize() {
QSize sz = src_fb.size();
for (int i = 0; i < fbo.size(); ++i) {
sz /= 2;
fbo[i]->resize(sz.width(), sz.height());
}
}
void FramebufferMipmap::create() {
if (fbo.isEmpty()) return;
src_fb.blit(index_from, fbo[0]->id(), 0, src_fb.rect(), fbo[0]->rect(), GL_COLOR_BUFFER_BIT, GL_LINEAR);
for (int i = 0; i < fbo.size() - 1; ++i)
fbo[i]->blit(0, fbo[i + 1]->id(), 0, fbo[i]->rect(), fbo[i + 1]->rect(), GL_COLOR_BUFFER_BIT, GL_LINEAR);
}

View File

@@ -0,0 +1,49 @@
/*
QGLView
Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GLFRAMEBUFFER_MIPMAP_H
#define GLFRAMEBUFFER_MIPMAP_H
#include "glframebuffer.h"
class FramebufferMipmap
{
public:
FramebufferMipmap(const Framebuffer & fb, int index_from_, int levels = 2);
virtual ~FramebufferMipmap();
int levelsCount() const {return fbo.size();}
int lastLevel() const {return fbo.size() - 1;}
Framebuffer & plane(int level) {return *fbo[level];}
int width (int level) const {return fbo[level]->wid;}
int height(int level) const {return fbo[level]->hei;}
QSize size(int level) const {return fbo[level]->size();}
QRect rect(int level) const {return fbo[level]->rect();}
void resize();
void create();
private:
int index_from;
const Framebuffer & src_fb;
QVector<Framebuffer*> fbo;
};
#endif // GLFRAMEBUFFER_MIPMAP_H

View File

@@ -174,6 +174,8 @@ class Map;
class Material;
class TextureManager;
class Texture2DArray;
class Framebuffer;
class FramebufferMipmap;
class Mesh;
class Scene;
class RendererBase;