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

This commit is contained in:
2018-10-16 09:01:00 +00:00
parent 2a4302712f
commit 83b27e0ff7
2 changed files with 34 additions and 16 deletions

View File

@@ -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;