context reinit support

This commit is contained in:
2022-10-13 08:57:27 +03:00
parent 3b0d1ea0e2
commit ce3df7d051
24 changed files with 136 additions and 24 deletions

View File

@@ -48,6 +48,12 @@ void Buffer::destroy(QOpenGLExtraFunctions * f) {
}
void Buffer::reinit() {
buffer_ = 0;
prev_size = 0;
}
void Buffer::bind(QOpenGLExtraFunctions * f) {
//qDebug() << "bind" << target_ << buffer_;
f->glBindBuffer(target_, buffer_);

View File

@@ -31,6 +31,7 @@ public:
void init (QOpenGLExtraFunctions * f);
void destroy (QOpenGLExtraFunctions * f);
void reinit();
void bind (QOpenGLExtraFunctions * f);
void release (QOpenGLExtraFunctions * f);

View File

@@ -50,7 +50,7 @@ Framebuffer::Framebuffer(QOpenGLExtraFunctions * f_, QVector<GLenum> colors_, bo
Framebuffer::~Framebuffer() {
deleteGLFramebuffer(fbo);
if (fbo > 0) deleteGLFramebuffer(fbo);
deleteGLRenderbuffer(drbo);
for (int i = 0; i < colors.size(); ++i)
deleteGLTexture(f, colors[i]);
@@ -59,12 +59,15 @@ Framebuffer::~Framebuffer() {
void Framebuffer::resize(int width, int height, bool force) {
if ((wid == width) && (hei == height) && !force) return;
if (fbo > 0) {
if ((wid == width) && (hei == height) && !force) return;
}
wid = width;
hei = height;
deleteGLFramebuffer(fbo);
if (fbo > 0) deleteGLFramebuffer(fbo);
f->glGenFramebuffers(1, &fbo);
f->glBindFramebuffer(GL_FRAMEBUFFER, 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_);
@@ -77,7 +80,7 @@ void Framebuffer::resize(int width, int height, bool force) {
}
if (is_depth) {
deleteGLTexture(f, tex_d);
deleteGLRenderbuffer(drbo);
if (drbo > 0) deleteGLRenderbuffer(drbo);
f->glGenRenderbuffers(1, &drbo);
f->glBindRenderbuffer(GL_RENDERBUFFER, drbo);
f->glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
@@ -97,6 +100,16 @@ void Framebuffer::resize(int width, int height, bool force) {
}
void Framebuffer::reinit() {
pbo.reinit();
colors.fill(0);
fbo = drbo = 0;
tex_d = 0;
pbo_queried = 0;
is_changed = true;
}
QImage Framebuffer::grab() const {
return QImage();
}

View File

@@ -52,6 +52,7 @@ public:
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 reinit();
void bind();
void release();
void setReadBuffer(int index) {glReadBuffer(GL_COLOR_ATTACHMENT0 + index);}

View File

@@ -48,3 +48,9 @@ void FramebufferMipmap::create() {
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);
}
void FramebufferMipmap::reinit() {
for (auto * f: fbo)
f->reinit();
}

View File

@@ -39,6 +39,7 @@ public:
void resize();
void create();
void reinit();
private:
int index_from;

View File

@@ -64,6 +64,16 @@ void Mesh::init(QOpenGLExtraFunctions * f) {
}
void Mesh::reinit() {
buffer_geom.reinit();
buffer_ind .reinit();
QMapIterator<int, VertexObject * > it(vao_map);
while (it.hasNext())
it.next().value()->reinit();
changed = true;
}
void Mesh::destroy(QOpenGLExtraFunctions * f) {
buffer_geom.destroy(f);
buffer_ind .destroy(f);

View File

@@ -37,6 +37,7 @@ public:
void destroy (QOpenGLExtraFunctions * f);
bool rebuffer(QOpenGLExtraFunctions * f);
void draw (QOpenGLExtraFunctions * f, int count, int type = 0);
void reinit();
void clear();
void loadObject (QOpenGLExtraFunctions * f, const QGLEngineShaders::Object & object, int type = 0);
void loadObjects (QOpenGLExtraFunctions * f, const QVector<QGLEngineShaders::Object> & objects, int type = 0);

View File

@@ -66,7 +66,6 @@ QString prepareDefines(const QStringList & defines) {
bool QGLEngineShaders::loadShadersMulti(QOpenGLShaderProgram *& prog, const QString & file, bool add_qgl, const QStringList & defines) {
if (!prog)
prog = new QOpenGLShaderProgram();
prog->removeAllShaders();
QFile f(file);
if (!f.open(QIODevice::ReadOnly)) {
qDebug() << "[QGLEngine] Shader" << file << "Error: can`t open file!";

View File

@@ -48,6 +48,12 @@ void Texture2DArray::destroy(QOpenGLExtraFunctions * f) {
}
void Texture2DArray::reinit() {
texture_ = 0;
layers_ = 0;
}
void Texture2DArray::bind(QOpenGLExtraFunctions * f, int channel) {
f->glActiveTexture(GL_TEXTURE0 + channel);
f->glBindTexture(target_, texture_);

View File

@@ -30,6 +30,7 @@ public:
void init (QOpenGLExtraFunctions * f);
void destroy (QOpenGLExtraFunctions * f);
void reinit();
void bind (QOpenGLExtraFunctions * f, int channel = 0);
void release (QOpenGLExtraFunctions * f);

View File

@@ -55,6 +55,15 @@ void VertexObject::destroy(QOpenGLExtraFunctions * f) {
}
void VertexObject::reinit() {
vao_ = 0;
buffer_obj.reinit();
buffer_sel.reinit();
buffers_binded = false;
objects_changed = selected_changed = true;
}
void VertexObject::bind(QOpenGLExtraFunctions * f) {
//qDebug() << "bind" << target_ << buffer_;
f->glBindVertexArray(vao_);

View File

@@ -31,6 +31,7 @@ public:
void init (QOpenGLExtraFunctions * f);
void destroy (QOpenGLExtraFunctions * f);
void reinit();
void bind (QOpenGLExtraFunctions * f);
void release (QOpenGLExtraFunctions * f);