context reinit support
This commit is contained in:
@@ -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_);
|
||||
|
||||
@@ -31,6 +31,7 @@ public:
|
||||
|
||||
void init (QOpenGLExtraFunctions * f);
|
||||
void destroy (QOpenGLExtraFunctions * f);
|
||||
void reinit();
|
||||
|
||||
void bind (QOpenGLExtraFunctions * f);
|
||||
void release (QOpenGLExtraFunctions * f);
|
||||
|
||||
@@ -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 (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();
|
||||
}
|
||||
|
||||
@@ -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);}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ public:
|
||||
|
||||
void resize();
|
||||
void create();
|
||||
void reinit();
|
||||
|
||||
private:
|
||||
int index_from;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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!";
|
||||
|
||||
@@ -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_);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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_);
|
||||
|
||||
@@ -31,6 +31,7 @@ public:
|
||||
|
||||
void init (QOpenGLExtraFunctions * f);
|
||||
void destroy (QOpenGLExtraFunctions * f);
|
||||
void reinit();
|
||||
|
||||
void bind (QOpenGLExtraFunctions * f);
|
||||
void release (QOpenGLExtraFunctions * f);
|
||||
|
||||
15
glscene.cpp
15
glscene.cpp
@@ -101,7 +101,20 @@ void Scene::clear() {
|
||||
geometries.clear();
|
||||
materials.clear();
|
||||
emit __destroyed();
|
||||
emit treeChanged();}
|
||||
emit treeChanged();
|
||||
}
|
||||
|
||||
|
||||
void Scene::reinitAll() {
|
||||
for (auto * i: geometries)
|
||||
i->reinit();
|
||||
for (auto * i: td_geometries)
|
||||
i->reinit();
|
||||
setTreeChanged();
|
||||
mat_changed = lights_changed = true;
|
||||
need_reload_materials = true;
|
||||
tree_struct_changed = true;
|
||||
}
|
||||
|
||||
|
||||
void Scene::objectsCountInternal(int * cnt, ObjectBase * where) {
|
||||
|
||||
@@ -60,6 +60,7 @@ public:
|
||||
void addScene(const Scene * s);
|
||||
void assignFrom(const Scene * s);
|
||||
void clear();
|
||||
void reinitAll();
|
||||
|
||||
int objectsCount(bool all = false);
|
||||
ObjectBaseList objects(bool all = false);
|
||||
|
||||
@@ -14,8 +14,8 @@ OpenGLWindow::OpenGLWindow(QWindow *parent) : QWindow(parent) {
|
||||
format.setRenderableType(QSurfaceFormat::OpenGLES);
|
||||
#else
|
||||
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
|
||||
format.setVersion(2, 0);
|
||||
format.setProfile(QSurfaceFormat::NoProfile);
|
||||
format.setVersion(4, 0);
|
||||
format.setProfile(QSurfaceFormat::CoreProfile);
|
||||
}
|
||||
#endif
|
||||
format.setDepthBufferSize(24);
|
||||
|
||||
@@ -158,10 +158,10 @@ void QGLView::render() {
|
||||
renderer_.mouse_pos = mapFromGlobal(QCursor::pos());
|
||||
renderer_.renderScene();
|
||||
emit glEndPaint();
|
||||
fps_tm += time.elapsed();
|
||||
time.restart();
|
||||
fps_tm = time.elapsed();
|
||||
fps_cnt++;
|
||||
if (fps_tm < 1000.) return;
|
||||
time.restart();
|
||||
fps_ = fps_cnt / fps_tm * 1000.;
|
||||
fps_tm = 0.;
|
||||
fps_cnt = 0;
|
||||
@@ -183,8 +183,10 @@ void QGLView::initialize() {
|
||||
glCullFace(GL_BACK);
|
||||
renderer_.reloadShaders();
|
||||
renderer_.init(width(), height());
|
||||
scene_->reinitAll();
|
||||
is_init = true;
|
||||
need_init_ = false;
|
||||
prev_size = QSize();
|
||||
emit glInitializeDone();
|
||||
}
|
||||
|
||||
|
||||
@@ -80,8 +80,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>934</width>
|
||||
<height>737</height>
|
||||
<width>907</width>
|
||||
<height>943</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_9">
|
||||
@@ -628,6 +628,9 @@
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_2">
|
||||
<property name="text">
|
||||
@@ -748,7 +751,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1107</width>
|
||||
<height>24</height>
|
||||
<height>30</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
@@ -796,7 +799,7 @@
|
||||
</widget>
|
||||
<action name="actionExit">
|
||||
<property name="icon">
|
||||
<iconset resource="../../qad/application/qad_application.qrc">
|
||||
<iconset resource="../qglview.qrc">
|
||||
<normaloff>:/icons/application-exit.png</normaloff>:/icons/application-exit.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
@@ -817,7 +820,7 @@
|
||||
</action>
|
||||
<action name="actionOpen">
|
||||
<property name="icon">
|
||||
<iconset resource="../../qad/application/qad_application.qrc">
|
||||
<iconset resource="../../qad/libs/blockview/qad_blockview.qrc">
|
||||
<normaloff>:/icons/document-open.png</normaloff>:/icons/document-open.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
@@ -829,7 +832,7 @@
|
||||
</action>
|
||||
<action name="actionSave">
|
||||
<property name="icon">
|
||||
<iconset resource="../../qad/application/qad_application.qrc">
|
||||
<iconset resource="../../qad/libs/widgets/qad_widgets.qrc">
|
||||
<normaloff>:/icons/document-save-all.png</normaloff>:/icons/document-save-all.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
@@ -841,7 +844,7 @@
|
||||
</action>
|
||||
<action name="actionReset">
|
||||
<property name="icon">
|
||||
<iconset resource="../../qad/application/qad_application.qrc">
|
||||
<iconset resource="../../qad/libs/widgets/qad_widgets.qrc">
|
||||
<normaloff>:/icons/document-new.png</normaloff>:/icons/document-new.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
@@ -853,7 +856,7 @@
|
||||
</action>
|
||||
<action name="actionSaveSelected">
|
||||
<property name="icon">
|
||||
<iconset resource="../../qad/utils/qad_utils.qrc">
|
||||
<iconset resource="../../qad/libs/blockview/qad_blockview.qrc">
|
||||
<normaloff>:/icons/document-save.png</normaloff>:/icons/document-save.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
@@ -970,8 +973,8 @@
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../../qad/utils/qad_utils.qrc"/>
|
||||
<include location="../../qad/application/qad_application.qrc"/>
|
||||
<include location="../../qad/libs/blockview/qad_blockview.qrc"/>
|
||||
<include location="../../qad/libs/widgets/qad_widgets.qrc"/>
|
||||
<include location="../qglview.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
|
||||
18
renderer.cpp
18
renderer.cpp
@@ -53,8 +53,6 @@ Renderer::Renderer(QGLView * view_): RendererBase(view_),
|
||||
shader_files[srFinalPass ] = "ds_final.glsl";
|
||||
shader_files[srTonemapPass ] = "ds_tonemap.glsl";
|
||||
|
||||
shader_fxaa = 0;
|
||||
gamma_ = 1.;
|
||||
edit_mode = need_init_shaders = true;
|
||||
camera_light_mode = QGLView::clmAuto;
|
||||
}
|
||||
@@ -69,6 +67,14 @@ Renderer::~Renderer() {
|
||||
|
||||
|
||||
void Renderer::init(int width, int height) {
|
||||
fbo_ds.reinit();
|
||||
fbo_out.reinit();
|
||||
quad->reinit();
|
||||
buffer_materials.reinit();
|
||||
buffer_lights.reinit();
|
||||
buffer_lights_pos.reinit();
|
||||
textures_maps.reinit();
|
||||
textures_empty.reinit();
|
||||
resize(width, height);
|
||||
rend_mat.init(width, height);
|
||||
rend_service.init(width, height);
|
||||
@@ -77,6 +83,7 @@ void Renderer::init(int width, int height) {
|
||||
initQuad(quad);
|
||||
initTextureArrays();
|
||||
initCoeffTextures();
|
||||
markReloadTextures();
|
||||
tex_env.init();
|
||||
need_init_shaders = true;
|
||||
}
|
||||
@@ -94,6 +101,12 @@ void Renderer::resize(int width, int height) {
|
||||
|
||||
void Renderer::reloadShaders() {
|
||||
QMapIterator<ShaderRole, QString> it(shader_files);
|
||||
qDeleteAll(shaders.values());
|
||||
shaders.clear();
|
||||
if (shader_fxaa) delete shader_fxaa;
|
||||
shader_fxaa = nullptr;
|
||||
if (tone_proc.shader_sum) delete tone_proc.shader_sum;
|
||||
tone_proc.shader_sum = nullptr;
|
||||
QString dir = ":shaders/";
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
@@ -343,6 +356,7 @@ void Renderer::renderScene() {
|
||||
renderQuad(prog, quad);
|
||||
} else
|
||||
fbo_out.blit(obrSum, fbo_out.id(), obrTonemap, fbo_out.rect(), fbo_out.rect());
|
||||
//glClearFramebuffer(Qt::red, false);
|
||||
fbo_out.release();
|
||||
|
||||
/// apply hovers and selection frame
|
||||
|
||||
@@ -100,14 +100,14 @@ protected:
|
||||
void releaseShader();
|
||||
|
||||
private:
|
||||
float gamma_;
|
||||
float gamma_ = 1.f;
|
||||
int camera_light_mode;
|
||||
bool edit_mode, need_init_shaders, need_render_sum;
|
||||
Framebuffer fbo_ds, fbo_out;
|
||||
QMap<ShaderRole, QString> shader_files;
|
||||
QMap<ShaderRole, QStringList> shader_defines;
|
||||
QMap<ShaderRole, QOpenGLShaderProgram*> shaders;
|
||||
QOpenGLShaderProgram * shader_fxaa;
|
||||
QOpenGLShaderProgram * shader_fxaa = nullptr;
|
||||
|
||||
RendererMaterial rend_mat;
|
||||
RendererService rend_service;
|
||||
|
||||
@@ -49,6 +49,8 @@ RendererMaterial::~RendererMaterial() {
|
||||
|
||||
|
||||
void RendererMaterial::init(int width, int height) {
|
||||
fbo_mat_thumb.reinit();
|
||||
mat_sphere->reinit();
|
||||
resize(width, height);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,8 @@ RendererSelection::~RendererSelection() {
|
||||
|
||||
|
||||
void RendererSelection::init(int width, int height) {
|
||||
fbo_selection.reinit();
|
||||
sel_frame->reinit();
|
||||
resize(width, height);
|
||||
}
|
||||
|
||||
|
||||
@@ -142,6 +142,23 @@ RendererService::~RendererService() {
|
||||
|
||||
|
||||
void RendererService::init(int width, int height) {
|
||||
box_mesh ->reinit();
|
||||
box_mesh_f ->reinit();
|
||||
omni_mesh ->reinit();
|
||||
omni_mesh_f ->reinit();
|
||||
cone_mesh ->reinit();
|
||||
cone_mesh_f ->reinit();
|
||||
camera_mesh ->reinit();
|
||||
camera_mesh_f ->reinit();
|
||||
line_spot_f ->reinit();
|
||||
line_camera_f ->reinit();
|
||||
axis_mesh ->reinit();
|
||||
handle_move_mesh ->reinit();
|
||||
handle_ms_2_mesh ->reinit();
|
||||
handle_rotate_mesh ->reinit();
|
||||
handle_scale_mesh ->reinit();
|
||||
handle_scale_3_mesh->reinit();
|
||||
axis_mesh ->reinit();
|
||||
fillXYZObjects();
|
||||
axis_mesh->loadObjects(r->view, cur_objects);
|
||||
resize(width, height);
|
||||
|
||||
@@ -48,6 +48,9 @@ TonemappingProc::~TonemappingProc() {
|
||||
|
||||
|
||||
void TonemappingProc::init() {
|
||||
buffer_vbo.reinit();
|
||||
fbo_1x1.reinit();
|
||||
fbomm.reinit();
|
||||
QOpenGLExtraFunctions * f = r->view;
|
||||
buffer_vbo.init(f);
|
||||
f->glGenVertexArrays(1, &vbo_vao);
|
||||
|
||||
Reference in New Issue
Block a user