git-svn-id: svn://db.shs.com.ru/libs@446 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -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<Light*> & 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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user