From 83b27e0ff73f192c31dd70945dde85d89d2d7635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Tue, 16 Oct 2018 09:01:00 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/libs@446 a8b55f48-bf90-11e4-a774-851b48703e85 --- qglview/glshaders.cpp | 8 ++++++++ qglview/qglview.cpp | 42 ++++++++++++++++++++++++++---------------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/qglview/glshaders.cpp b/qglview/glshaders.cpp index 9aa1ff8..e27da1d 100644 --- a/qglview/glshaders.cpp +++ b/qglview/glshaders.cpp @@ -151,6 +151,8 @@ bool loadShaders(__GLShaderProgram__ * prog, const QString & name, const QString void setUniformMatrices(__GLShaderProgram__ * prog, QMatrix4x4 proj, QMatrix4x4 view, QMatrix4x4 prevproj, QMatrix4x4 prevview) { + if (!prog) return; + if (!prog->isLinked()) return; QMatrix4x4 mvpm = proj * view; QMatrix4x4 pmvpm = prevproj * prevview; QMatrix3x3 nm = view.normalMatrix(); @@ -169,6 +171,8 @@ void setUniformMatrices(__GLShaderProgram__ * prog, QMatrix4x4 proj, QMatrix4x4 void setUniformMap(__GLShaderProgram__ * prog, QString map_name, const Map & map, int channel, int def_channel) { + if (!prog) return; + if (!prog->isLinked()) return; prog->setUniformValue(("qgl_Material." + map_name + ".offset").toLatin1().constData(), map.color_offset); prog->setUniformValue(("qgl_Material." + map_name + ".amount").toLatin1().constData(), map.color_amount); prog->setUniformValue(("qgl_Material." + map_name + ".map").toLatin1().constData(), map.bitmap_id > 0 ? channel : def_channel); @@ -176,6 +180,8 @@ void setUniformMap(__GLShaderProgram__ * prog, QString map_name, const Map & map void setUniformMaterial(__GLShaderProgram__ * prog, const Material & mat) { + if (!prog) return; + if (!prog->isLinked()) return; QGLCI GLfloat mat_diffuse[4] = {1.0f, 1.0f, 1.0f, 1.0f}; mat_diffuse[0] = mat.color_diffuse.redF(); @@ -218,6 +224,8 @@ void setUniformLights(__GLShaderProgram__ * prog, const QVector & lights " mat4 shadowMatrix;\n" */ void setUniformLight(__GLShaderProgram__ * prog, Light * light, QString ulightn, const QMatrix4x4 & mat, int shadow) { + if (!prog) return; + if (!prog->isLinked()) return; QMatrix4x4 m = mat * light->worldTransform(); QVector4D pos(0, 0, 0, 1.), dir(light->direction);//, dir0(light->dir0), dir1(light->dir1); pos = m * pos; diff --git a/qglview/qglview.cpp b/qglview/qglview.cpp index a094d56..d6d5b53 100644 --- a/qglview/qglview.cpp +++ b/qglview/qglview.cpp @@ -101,8 +101,8 @@ QGLView::QGLView(QWidget * parent): QGraphicsView(parent), fbo_selection(3) { QGLView::~QGLView() { stop(); - if (shader_select != 0) delete shader_select; - if (shader_halo != 0) delete shader_halo; + if (shader_select) delete shader_select; + if (shader_halo) delete shader_halo; currentQGLView = 0; currentGLTextureManager = 0; //if (shader_rope != 0) delete shader_rope; @@ -170,21 +170,21 @@ void QGLView::drawBackground(QPainter * painter, const QRectF & rect) { return; } painter_ = painter; - painter_->beginNativePainting(); if (is_first_draw) { //connect(context(), SIGNAL(aboutToBeDestroyed()), this, SLOT(glCleanup())); - resizeGL(viewport()->width(), viewport()->height()); + //resizeGL(viewport()->width(), viewport()->height()); initializeGL(); } is_first_draw = false; + painter_->beginNativePainting(); paintGL(); painter_->endNativePainting(); glDisableDepth(); glDisable(GL_BLEND); glDisable(GL_CULL_FACE); glReleaseTextures(); - QGraphicsView::drawBackground(painter_, rect); painter_ = 0; + QGraphicsView::drawBackground(painter, rect); } @@ -285,9 +285,9 @@ void QGLView::paintGL() { fbo_selection.bind(); fbo_selection.setWriteBuffer(0); glClearFramebuffer(QColor(0, 0, 0, 0)); - if (shaders_supported) shader_select->bind(); + if (shaders_supported && shader_select->isLinked()) shader_select->bind(); renderSelection(); - if (shaders_supported) shader_select->release(); + if (shaders_supported && shader_select->isLinked()) shader_select->release(); uchar cgid[4] = {0, 0, 0, 0}; uint iid = 0; GLObjectBase * so = 0; @@ -426,6 +426,8 @@ void QGLView::paintGL() { void QGLView::renderHalo(const GLObjectBase * obj, const int iid, const QColor & color, const double & fill) { if (!shaders_supported) return; + if (!shader_halo) return; + if (!shader_halo->isLinked()) return; if (obj) { shader_halo->bind(); shader_halo->setUniformValue("qgl_ModelViewProjectionMatrix", QMatrix4x4()); @@ -455,9 +457,13 @@ void QGLView::renderSelection() { cid = 1; ids.clear(); if (shaders_supported) { - sh_id_loc = shader_select->uniformLocation("id"); - shader_select->setUniformValue("z_far", GLfloat(depthEnd())); - shader_select->setUniformValue("z_near", GLfloat(depthStart())); + if (shader_select) { + if (shader_select->isLinked()) { + sh_id_loc = shader_select->uniformLocation("id"); + shader_select->setUniformValue("z_far", GLfloat(depthEnd())); + shader_select->setUniformValue("z_near", GLfloat(depthStart())); + } + } } //qDebug() << sh_id_loc; start_rp.view_matrix = getGLMatrix(GL_MODELVIEW_MATRIX); @@ -476,11 +482,15 @@ void QGLView::renderSingleSelection(GLObjectBase & o) { QMatrix4x4 curview = start_rp.view_matrix * start_rp.cam_offset_matrix * o.itransform_; ids.insert(cid, &o); if (shaders_supported){ - setUniformMatrices(shader_select, start_rp.proj_matrix, curview); - shader_select->setUniformValue(sh_id_loc, QVector4D(float((cid >> 24) & 0xFF) / 255.f, - float((cid >> 16) & 0xFF) / 255.f, - float((cid >> 8) & 0xFF) / 255.f, - float(cid & 0xFF) / 255.f)); + if (shader_select) { + if (shader_select->isLinked()) { + setUniformMatrices(shader_select, start_rp.proj_matrix, curview); + shader_select->setUniformValue(sh_id_loc, QVector4D(float((cid >> 24) & 0xFF) / 255.f, + float((cid >> 16) & 0xFF) / 255.f, + float((cid >> 8) & 0xFF) / 255.f, + float(cid & 0xFF) / 255.f)); + } + } } else { setGLMatrix(curview); glColor4f(float((cid >> 24) & 0xFF) / 255.f, @@ -584,7 +594,7 @@ void QGLView::applyFog() { void QGLView::resizeGL(int width, int height) { if (!is_init) return; aspect = double(width) / double(height); - if (renderer_ != 0) renderer_->resize(width, height); + if (renderer_) renderer_->resize(width, height); //qDebug() << "resize" << width << height; fbo_selection.resize(width, height); mouse_first = true;