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

This commit is contained in:
2015-11-20 21:19:36 +00:00
parent cabaead1c6
commit 104a7f99ad
48 changed files with 1973 additions and 1273 deletions

View File

@@ -23,7 +23,9 @@ QGLView::QGLView(QWidget * parent): QGraphicsView(parent), fbo_selection(3) {
setFrameShape(QFrame::NoFrame);
setViewportUpdateMode(FullViewportUpdate);
setCacheMode(CacheNone);
setViewport(new QGLWidget(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer | QGL::Rgba | QGL::AlphaChannel | QGL::DirectRendering | QGL::SampleBuffers)));
QGLFormat f(QGL::DoubleBuffer | QGL::DepthBuffer | QGL::Rgba | QGL::AlphaChannel | QGL::DirectRendering | QGL::SampleBuffers);
f.setSwapInterval(0);
setViewport(new QGLWidget(f));
setMouseTracking(true);
setFocusPolicy(Qt::WheelFocus);
setScene(new QGraphicsScene());
@@ -51,7 +53,7 @@ QGLView::QGLView(QWidget * parent): QGraphicsView(parent), fbo_selection(3) {
selectionHaloFill_ = 0.5;
shadow_map_size = dynamic_cubemap_size = 512;
//lmode = Simple;
shader_select = shader_halo = shader_rope = 0;
shader_select = shader_halo = 0;
cur_luminance = 1.;
accom_time = 32.;
accom_max_speed = 0.1;
@@ -74,7 +76,7 @@ QGLView::QGLView(QWidget * parent): QGraphicsView(parent), fbo_selection(3) {
QGLView::~QGLView() {
if (shader_select != 0) delete shader_select;
if (shader_halo != 0) delete shader_halo;
if (shader_rope != 0) delete shader_rope;
//if (shader_rope != 0) delete shader_rope;
}
@@ -112,7 +114,7 @@ void QGLView::drawBackground(QPainter * painter, const QRectF & rect) {
f = false;
paintGL();
painter_->endNativePainting();
glDisable(GL_DEPTH_TEST);
glDisableDepth();
glDisable(GL_BLEND);
glDisable(GL_CULL_FACE);
glReleaseTextures();
@@ -131,7 +133,7 @@ void QGLView::initializeGL() {
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
//glEnable(GL_TEXTURE_2D);
//glEnable(GL_TEXTURE_CUBE_MAP);
glEnable(GL_DEPTH_TEST);
glEnableDepth();
glEnable(GL_CULL_FACE);
glEnableClientState(GL_VERTEX_ARRAY);
@@ -168,7 +170,7 @@ void QGLView::initializeGL() {
shader_select = new QGLShaderProgram(context());
shader_halo = new QGLShaderProgram(context());
shader_rope = new QGLShaderProgram(context());
//shader_rope = new QGLShaderProgram(context());
reloadThisShaders();
is_init = true;
@@ -192,16 +194,17 @@ void QGLView::initializeGL() {
void QGLView::paintGL() {
//QMutexLocker ml_v(&v_mutex);
glEnable(GL_CULL_FACE);
//glDisble(GL_CULL_FACE);
//glDisable(GL_CULL_FACE);
camera_.apply(aspect);
start_rp.proj_matrix = getGLMatrix(GL_PROJECTION_MATRIX);
start_rp.view_matrix = getGLMatrix(GL_MODELVIEW_MATRIX);
//objects_.buildTransform();
/// Selection detect
//glClearFramebuffer(QColor(100, 0, 0, 0));
if (mouseSelect_) {
glReleaseTextures();
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glDepthMask(GL_TRUE);
glEnableDepth();
glDisable(GL_TEXTURE_1D);
glDisable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_CUBE_MAP);
@@ -248,8 +251,7 @@ void QGLView::paintGL() {
renderHalo(sel_obj, ids.key(sel_obj), selectionHaloColor_, selectionHaloFill_);
}
fbo_selection.release();
glEnable(GL_DEPTH_TEST);
glEnable(GL_RESCALE_NORMAL);
glEnableDepth();
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
@@ -277,7 +279,7 @@ void QGLView::paintGL() {
glEnable(GL_BLEND);
glDisable(GL_TEXTURE_CUBE_MAP);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glDisableDepth();
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
if (selectionHalo_) {
glBindTexture(GL_TEXTURE_2D, fbo_selection.colorTexture(2));
@@ -372,7 +374,17 @@ void QGLView::renderSelection() {
ids.clear();
if (shaders_supported) sh_id_loc = shader_select->uniformLocation("id");
//qDebug() << sh_id_loc;
start_rp.view_matrix = getGLMatrix(GL_MODELVIEW_MATRIX);
glPushMatrix();
renderSingleSelection(objects_);
glPopMatrix();
}
void QGLView::renderShadow() {
glPushMatrix();
renderSingleShadow(objects_);
glPopMatrix();
}
@@ -382,32 +394,27 @@ void QGLView::renderSingleSelection(GLObjectBase & o) {
o.loadTextures();
}
if (!o.visible_ || !o.select_) return;
glPushMatrix();
if (o.pos_.x() != 0. || o.pos_.y() != 0. || o.pos_.z() != 0.) qglTranslate(o.pos_);
if (o.raw_matrix) {
qglMultMatrix(o.mat_);
} else {
if (o.angles_.z() != 0.) glRotated(o.angles_.z(), 0., 0., 1.);
if (o.angles_.y() != 0.) glRotated(o.angles_.y(), 0., 1., 0.);
if (o.angles_.x() != 0.) glRotated(o.angles_.x(), 1., 0., 0.);
if (o.scale_.x() != 1. || o.scale_.y() != 1. || o.scale_.z() != 1.) qglScale(o.scale_);
}
QMatrix4x4 curview = start_rp.view_matrix * o.itransform_;
ids.insert(cid, &o);
if (shaders_supported) 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 glColor4f(float((cid >> 24) & 0xFF) / 255.f,
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));
} else {
setGLMatrix(curview);
glColor4f(float((cid >> 24) & 0xFF) / 255.f,
float((cid >> 16) & 0xFF) / 255.f,
float((cid >> 8) & 0xFF) / 255.f,
float(cid & 0xFF) / 255.f);
}
//qDebug() << o.name() << "assign to" << sh_id_loc << cid;
//glColor4f(float((cid >> 24) & 0xFF) / 255.f, float((cid >> 16) & 0xFF) / 255.f, float((cid >> 8) & 0xFF) / 255.f, float(cid & 0xFF) / 255.f);
++cid;
o.draw(true);
o.draw(0, true);
foreach (GLObjectBase * i, o.children_)
renderSingleSelection(*i);
glPopMatrix();
}
@@ -417,19 +424,13 @@ void QGLView::renderSingleShadow(GLObjectBase & o) {
o.loadTextures();
}
if (!o.visible_) return;
glPushMatrix();
if (o.pos_.x() != 0. || o.pos_.y() != 0. || o.pos_.z() != 0.) qglTranslate(o.pos_);
if (o.angles_.z() != 0.) glRotated(o.angles_.z(), 0., 0., 1.);
if (o.angles_.y() != 0.) glRotated(o.angles_.y(), 0., 1., 0.);
if (o.angles_.x() != 0.) glRotated(o.angles_.x(), 1., 0., 0.);
if (o.scale_.x() != 1. || o.scale_.y() != 1. || o.scale_.z() != 1.) qglScale(o.scale_);
setGLMatrix(start_rp.view_matrix * o.itransform_);
glPolygonMode(GL_FRONT_AND_BACK, o.render_mode != GLObjectBase::View ? o.render_mode : (rmode != GLObjectBase::View ? rmode : GL_FILL));
glLineWidth(o.line_width > 0. ? o.line_width : lineWidth_);
glPointSize(o.line_width > 0. ? o.line_width : lineWidth_);
o.draw(true);
o.draw(0, true);
foreach (GLObjectBase * i, o.children_)
renderSingleSelection(*i);
glPopMatrix();
}