git-svn-id: svn://db.shs.com.ru/libs@536 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -23,8 +23,8 @@
|
||||
|
||||
class Camera;
|
||||
|
||||
extern QMatrix4x4 globCameraMatrix;
|
||||
extern Camera * currentCamera;
|
||||
//extern QMatrix4x4 globCameraMatrix;
|
||||
//extern Camera * currentCamera;
|
||||
|
||||
class Camera: public GLObjectBase
|
||||
{
|
||||
|
||||
@@ -42,9 +42,7 @@ GLFramebuffer::~GLFramebuffer() {
|
||||
|
||||
void GLFramebuffer::resize(int width, int height, bool force) {
|
||||
if ((wid == width) && (hei == height) && !force) return;
|
||||
#if QT_VERSION >= 0x050600
|
||||
initializeOpenGLFunctions();
|
||||
#endif
|
||||
wid = width;
|
||||
hei = height;
|
||||
deleteGLFramebuffer(fbo);
|
||||
@@ -91,9 +89,7 @@ QImage GLFramebuffer::grab() const {
|
||||
void GLFramebuffer::bind() {
|
||||
if (is_changed) resize(wid, hei);
|
||||
if (fbo == 0) return;
|
||||
#if QT_VERSION >= 0x050600
|
||||
initializeOpenGLFunctions();
|
||||
#endif
|
||||
glFlush();
|
||||
glGetIntegerv(GL_VIEWPORT, prev_view);
|
||||
//glClearError();
|
||||
|
||||
@@ -21,10 +21,7 @@
|
||||
|
||||
#include "gltypes.h"
|
||||
|
||||
class GLFramebuffer
|
||||
#if QT_VERSION >= 0x050600
|
||||
: protected QOpenGLExtraFunctions
|
||||
#endif
|
||||
class GLFramebuffer : protected QOpenGLExtraFunctions
|
||||
{
|
||||
public:
|
||||
GLFramebuffer(int colorAttachments = 1, bool withDepth = true, GLenum colorFormat = GL_RGBA8, GLenum target = GL_TEXTURE_2D);
|
||||
|
||||
@@ -226,7 +226,7 @@ Material::Material(): map_reflection(512) {
|
||||
}
|
||||
|
||||
|
||||
void Material::apply(__GLShaderProgram__ * prog) {
|
||||
void Material::apply(QOpenGLShaderProgram * prog) {
|
||||
if (prog) {
|
||||
setUniformMaterial(prog, *this);
|
||||
} else {
|
||||
|
||||
@@ -92,7 +92,7 @@ protected:
|
||||
|
||||
};
|
||||
|
||||
extern GLTextureManager * currentGLTextureManager;
|
||||
//extern GLTextureManager * currentGLTextureManager;
|
||||
|
||||
struct Map {
|
||||
Map() {bitmap_id = 0; color_amount = 1.f; color_offset = 0.f; animation_frame_rate = -1.f;}
|
||||
@@ -107,7 +107,7 @@ struct Map {
|
||||
|
||||
struct Material {
|
||||
Material();
|
||||
void apply(__GLShaderProgram__ * prog);
|
||||
void apply(QOpenGLShaderProgram * prog);
|
||||
void loadTextures(GLTextureManagerBase * tm = 0);
|
||||
QString name;
|
||||
QColor color_diffuse;
|
||||
|
||||
@@ -90,7 +90,7 @@ GLObjectBase * GLObjectBase::clone(bool withChildren) {
|
||||
return o;
|
||||
}
|
||||
|
||||
void GLObjectBase::draw(__GLShaderProgram__ * prog, bool simplest) {
|
||||
void GLObjectBase::draw(QOpenGLShaderProgram * prog, bool simplest) {
|
||||
vbo.draw(geom_prim, prog, simplest);
|
||||
/*if (!d_vertices.isEmpty()) {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
@@ -332,7 +332,7 @@ GLObjectBase * Light::clone(bool withChildren) {
|
||||
}
|
||||
|
||||
|
||||
void Light::draw(__GLShaderProgram__ * prog, bool simplest) {
|
||||
void Light::draw(QOpenGLShaderProgram * prog, bool simplest) {
|
||||
bool l = glIsEnabled(GL_LIGHTING);
|
||||
glDisable(GL_LIGHTING);
|
||||
glPointSize(8.);
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
void setName(const QString & name) {name_ = name;}
|
||||
//virtual GLuint hList() {return list;}
|
||||
virtual void init() {calculateBoundingBox(); vbo.init(); vbo.rebuffer(); /*material_.reflection.create();*/ /*qDebug() << "init" << vbo.buffer_;*/ is_init = true;}
|
||||
virtual void draw(__GLShaderProgram__ * prog, bool simplest = false);
|
||||
virtual void draw(QOpenGLShaderProgram * prog, bool simplest = false);
|
||||
virtual void update() {}
|
||||
bool isInit() const {return is_init;}
|
||||
bool isTexturesLoaded() const {return is_tex_loaded;}
|
||||
@@ -192,7 +192,7 @@ public:
|
||||
|
||||
protected:
|
||||
void addChildren(QList<GLObjectBase * > & list, GLObjectBase * where);
|
||||
void loadTextures(bool with_children = false) {material_.loadTextures((GLTextureManagerBase * )currentGLTextureManager); if (with_children) foreach (GLObjectBase * i, children_) i->loadTextures(); is_tex_loaded = true; checkPass();}
|
||||
void loadTextures(bool with_children = false) {material_.loadTextures(view_->textureManager()); if (with_children) foreach (GLObjectBase * i, children_) i->loadTextures(); is_tex_loaded = true; checkPass();}
|
||||
//void deleteTextures() {foreach (GLuint i, textures) currentQGLView->deleteTexture(i); textures.clear();}
|
||||
void buildTransform();
|
||||
void initInternal() {init(); loadTextures(); foreach (GLObjectBase * i, children_) i->initInternal();}
|
||||
@@ -236,7 +236,7 @@ public:
|
||||
Light(const QVector3D & p, const QColor & c = Qt::white, GLdouble i = 1.);
|
||||
virtual GLObjectBase * clone(bool withChildren = true);
|
||||
virtual void init() {shadow_map.resize(512, 512); is_init = true;}
|
||||
virtual void draw(__GLShaderProgram__ * prog, bool simplest = false);
|
||||
virtual void draw(QOpenGLShaderProgram * prog, bool simplest = false);
|
||||
|
||||
QVector3D direction, dir0, dir1;
|
||||
GLdouble angle_start;
|
||||
|
||||
@@ -108,7 +108,7 @@ void GLParticlesSystem::update() {
|
||||
}
|
||||
|
||||
|
||||
void GLParticlesSystem::draw(__GLShaderProgram__ * prog, bool) {
|
||||
void GLParticlesSystem::draw(QOpenGLShaderProgram * prog, bool) {
|
||||
if (particles.isEmpty()) return;
|
||||
if (view_ == 0) return;
|
||||
QGLCI
|
||||
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
};
|
||||
|
||||
void update();
|
||||
void draw(__GLShaderProgram__ * prog, bool);
|
||||
void draw(QOpenGLShaderProgram * prog, bool);
|
||||
|
||||
float birthRate() const {return birthRate_;}
|
||||
float lifeDuration() const {return lifeDuration_;}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include "glprimitives.h"
|
||||
|
||||
|
||||
void GLPrimitivePoint::draw(__GLShaderProgram__ * prog, bool simplest) {
|
||||
void GLPrimitivePoint::draw(QOpenGLShaderProgram * prog, bool simplest) {
|
||||
glPointSize(sz);
|
||||
glColor3f(material_.color_diffuse.redF(), material_.color_diffuse.greenF(), material_.color_diffuse.blueF());
|
||||
glBegin(GL_POINTS);
|
||||
@@ -29,7 +29,7 @@ void GLPrimitivePoint::draw(__GLShaderProgram__ * prog, bool simplest) {
|
||||
|
||||
|
||||
|
||||
void GLPrimitiveLine::draw(__GLShaderProgram__ * prog, bool simplest) {
|
||||
void GLPrimitiveLine::draw(QOpenGLShaderProgram * prog, bool simplest) {
|
||||
glColor3f(material_.color_diffuse.redF(), material_.color_diffuse.greenF(), material_.color_diffuse.blueF());
|
||||
glBegin(GL_LINES);
|
||||
glVertex3d(p0.x(), p0.y(), p0.z());
|
||||
|
||||
@@ -26,7 +26,7 @@ class GLPrimitivePoint: public GLObjectBase
|
||||
{
|
||||
public:
|
||||
GLPrimitivePoint(double size = 1., QVector3D pos = QVector3D()) {sz = 8.;}
|
||||
virtual void draw(__GLShaderProgram__ * prog, bool simplest = false);
|
||||
virtual void draw(QOpenGLShaderProgram * prog, bool simplest = false);
|
||||
private:
|
||||
double sz;
|
||||
};
|
||||
@@ -38,7 +38,7 @@ class GLPrimitiveLine: public GLObjectBase
|
||||
{
|
||||
public:
|
||||
GLPrimitiveLine(QVector3D p0_ = QVector3D(), QVector3D p1_ = QVector3D()) {p0 = p0_; p1 = p1_;}
|
||||
virtual void draw(__GLShaderProgram__ * prog, bool simplest = false);
|
||||
virtual void draw(QOpenGLShaderProgram * prog, bool simplest = false);
|
||||
QVector3D point0() const {return p0;}
|
||||
QVector3D point1() const {return p1;}
|
||||
void setPoint0(const QVector3D & p) {p0 = p;}
|
||||
|
||||
@@ -77,7 +77,7 @@ void GLRendererBase::setupAmbientLight(const QColor & a, bool first_pass) {
|
||||
|
||||
|
||||
void GLRendererBase::setupShadersLights(int lights_count) {
|
||||
/*foreach (__GLShaderProgram__ * i, view.shaders_ppl) {
|
||||
/*foreach (QOpenGLShaderProgram * i, view.shaders_ppl) {
|
||||
i->bind();
|
||||
i->setUniformValue("lightsCount", lights_count);
|
||||
i->setUniformValue("acc_light", lights_count > 0);
|
||||
@@ -190,7 +190,7 @@ void GLRendererBase::renderSingleObject(GLObjectBase & o, RenderingParameters &
|
||||
Material & mat(o.material_);
|
||||
QMatrix4x4 curview = rpl.view_matrix * rpl.cam_offset_matrix * o.itransform_, prevview = rpl.prev_view_matrix * rpl.cam_offset_matrix * o.itransform_;
|
||||
setupTextures(o, rpl, false);
|
||||
mat.apply((__GLShaderProgram__*)rpl.shaders);
|
||||
mat.apply((QOpenGLShaderProgram*)rpl.shaders);
|
||||
glSetPolygonMode(o.render_mode != GLObjectBase::View ? o.render_mode : (view.rmode != GLObjectBase::View ? view.rmode : GL_FILL));
|
||||
glLineWidth(o.line_width > 0. ? o.line_width : view.lineWidth_);
|
||||
glPointSize(o.line_width > 0. ? o.line_width : view.lineWidth_);
|
||||
@@ -218,19 +218,19 @@ void GLRendererBase::renderSingleObject(GLObjectBase & o, RenderingParameters &
|
||||
}
|
||||
if (rpl.shaders) {
|
||||
//qDebug() << o.name() << curview << curview.determinant();
|
||||
setUniformMatrices((__GLShaderProgram__*)rpl.shaders, rpl.proj_matrix, curview, rpl.prev_proj_matrix, prevview);
|
||||
setUniformMatrices((QOpenGLShaderProgram*)rpl.shaders, rpl.proj_matrix, curview, rpl.prev_proj_matrix, prevview);
|
||||
} else {
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
setGLMatrix(curview);
|
||||
}
|
||||
o.draw((__GLShaderProgram__*)rpl.shaders);
|
||||
o.draw((QOpenGLShaderProgram*)rpl.shaders);
|
||||
}
|
||||
foreach (GLObjectBase * i, o.children_)
|
||||
renderSingleObject(*i, rpl);
|
||||
}
|
||||
|
||||
|
||||
void GLRendererBase::renderShadow(Light * l, __GLShaderProgram__ * prog, QMatrix4x4 mat) {
|
||||
void GLRendererBase::renderShadow(Light * l, QOpenGLShaderProgram * prog, QMatrix4x4 mat) {
|
||||
Camera cam;
|
||||
QVector3D wp = l->worldPos();
|
||||
cam.setPos(wp);
|
||||
@@ -270,7 +270,7 @@ void GLRendererBase::renderSingleShadow(GLObjectBase & o, RenderingParameters &
|
||||
if (!o.visible_) return;
|
||||
if (rpl.shaders) {
|
||||
//qDebug() << o.name() << curview << curview.determinant();
|
||||
setUniformMatrices((__GLShaderProgram__*)rpl.shaders, rpl.proj_matrix, rpl.view_matrix * rpl.cam_offset_matrix * o.itransform_);
|
||||
setUniformMatrices((QOpenGLShaderProgram*)rpl.shaders, rpl.proj_matrix, rpl.view_matrix * rpl.cam_offset_matrix * o.itransform_);
|
||||
} else {
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
setGLMatrix(rpl.view_matrix * rpl.cam_offset_matrix * o.itransform_);
|
||||
@@ -278,7 +278,7 @@ void GLRendererBase::renderSingleShadow(GLObjectBase & o, RenderingParameters &
|
||||
glPolygonMode(GL_FRONT_AND_BACK, o.render_mode != GLObjectBase::View ? o.render_mode : (view.rmode != GLObjectBase::View ? view.rmode : GL_FILL));
|
||||
glLineWidth(o.line_width > 0. ? o.line_width : view.lineWidth_);
|
||||
glPointSize(o.line_width > 0. ? o.line_width : view.lineWidth_);
|
||||
o.draw((__GLShaderProgram__*)rpl.shaders, true);
|
||||
o.draw((QOpenGLShaderProgram*)rpl.shaders, true);
|
||||
foreach (GLObjectBase * i, o.children_)
|
||||
renderSingleShadow(*i, rpl);
|
||||
}
|
||||
@@ -303,7 +303,7 @@ void GLRendererBase::RenderingParameters::prepare() {
|
||||
}
|
||||
|
||||
|
||||
void GLRendererBase::RenderingParameters::setUniform(__GLShaderProgram__ * prog) {
|
||||
void GLRendererBase::RenderingParameters::setUniform(QOpenGLShaderProgram * prog) {
|
||||
if (!prog) return;
|
||||
prog->setUniformValue("qgl_ModelViewMatrix", view_matrix);
|
||||
prog->setUniformValue("qgl_ProjectionMatrix", proj_matrix);
|
||||
|
||||
@@ -22,10 +22,7 @@
|
||||
#include "glcamera.h"
|
||||
#include "glshaders.h"
|
||||
|
||||
class GLRendererBase: public QObject
|
||||
#if QT_VERSION >= 0x050600
|
||||
, protected QOpenGLExtraFunctions
|
||||
#endif
|
||||
class GLRendererBase: public QObject , protected QOpenGLExtraFunctions
|
||||
{
|
||||
friend class QGLView;
|
||||
Q_OBJECT
|
||||
@@ -37,7 +34,7 @@ public:
|
||||
struct RenderingParameters {
|
||||
RenderingParameters();
|
||||
void prepare();
|
||||
void setUniform(__GLShaderProgram__ * prog);
|
||||
void setUniform(QOpenGLShaderProgram * prog);
|
||||
int pass;
|
||||
int light_pass;
|
||||
bool light;
|
||||
@@ -52,7 +49,7 @@ public:
|
||||
QMatrix4x4 viewproj_matrix, viewproj_matrix_i;
|
||||
QMatrix3x3 normal_matrix;
|
||||
QMatrix4x4 cam_offset_matrix;
|
||||
__GLShaderProgram__ * cur_shader;
|
||||
QOpenGLShaderProgram * cur_shader;
|
||||
};
|
||||
|
||||
RenderingParameters rp;
|
||||
@@ -71,7 +68,7 @@ protected:
|
||||
inline void applyFilteringParameters();
|
||||
void renderObjects(int pass, int light_pass, void * shaders = 0, bool textures = true, bool light = true, bool fog = true);
|
||||
void renderSingleObject(GLObjectBase & o, RenderingParameters & rpl);
|
||||
void renderShadow(Light * l, __GLShaderProgram__ * prog = 0, QMatrix4x4 mat = QMatrix4x4());
|
||||
void renderShadow(Light * l, QOpenGLShaderProgram * prog = 0, QMatrix4x4 mat = QMatrix4x4());
|
||||
void renderSingleShadow(GLObjectBase & o, RenderingParameters & rpl);
|
||||
|
||||
QGLView & view;
|
||||
|
||||
@@ -96,7 +96,7 @@ const char qgl_structs[] =
|
||||
"uniform QGLMaterial qgl_Material;\n";
|
||||
|
||||
|
||||
QString loadShaderFile(__GLShaderProgram__ * prog, __GLShader__::ShaderType type, const QString & file) {
|
||||
QString loadShaderFile(QOpenGLShaderProgram * prog, QOpenGLShader::ShaderType type, const QString & file) {
|
||||
QFile f(file);
|
||||
if (!f.open(QIODevice::ReadOnly)) return "";
|
||||
QString all = QString::fromUtf8(f.readAll());
|
||||
@@ -105,10 +105,10 @@ QString loadShaderFile(__GLShaderProgram__ * prog, __GLShader__::ShaderType type
|
||||
if (version.toInt() >= 150) {
|
||||
int ip = all.indexOf("\n", i);
|
||||
if (ip < 0) return all;
|
||||
if (type == __GLShader__::Vertex) {
|
||||
if (type == QOpenGLShader::Vertex) {
|
||||
all.insert(ip + 1, qgl_vertex_head);
|
||||
}
|
||||
if (type == __GLShader__::Fragment) {
|
||||
if (type == QOpenGLShader::Fragment) {
|
||||
all.insert(ip + 1, qgl_fragment_head);
|
||||
}
|
||||
all.insert(ip + 1, qgl_structs);
|
||||
@@ -120,27 +120,25 @@ QString loadShaderFile(__GLShaderProgram__ * prog, __GLShader__::ShaderType type
|
||||
}
|
||||
|
||||
|
||||
bool loadShaders(__GLShaderProgram__ * prog, const QString & name, const QString & dir) {
|
||||
bool loadShaders(QOpenGLShaderProgram * prog, const QString & name, const QString & dir) {
|
||||
prog->removeAllShaders();
|
||||
QDir d(dir);
|
||||
QFileInfoList sl;
|
||||
//qDebug() << "[QGLView] Shader \"" + name + "\" load shaders from" << d.absolutePath();
|
||||
#if QT_VERSION >= 0x040700
|
||||
sl = d.entryInfoList(QStringList(name + ".geom"), QDir::Files | QDir::NoDotAndDotDot);
|
||||
foreach (const QFileInfo & i, sl) {
|
||||
qDebug() << "[QGLView] Shader \"" + name + "\" add geometry shader:" << i.fileName();
|
||||
loadShaderFile(prog, __GLShader__::Geometry, i.absoluteFilePath());
|
||||
loadShaderFile(prog, QOpenGLShader::Geometry, i.absoluteFilePath());
|
||||
}
|
||||
#endif
|
||||
sl = d.entryInfoList(QStringList(name + ".vert"), QDir::Files | QDir::NoDotAndDotDot);
|
||||
foreach (const QFileInfo & i, sl) {
|
||||
//qDebug() << "[QGLView] Shader \"" + name + "\" add vertex shader:" << i.fileName();
|
||||
loadShaderFile(prog, __GLShader__::Vertex, i.absoluteFilePath());
|
||||
loadShaderFile(prog, QOpenGLShader::Vertex, i.absoluteFilePath());
|
||||
}
|
||||
sl = d.entryInfoList(QStringList(name + ".frag"), QDir::Files | QDir::NoDotAndDotDot);
|
||||
foreach (const QFileInfo & i, sl) {
|
||||
//qDebug() << "[QGLView] Shader \"" + name + "\" add fragment shader:" << i.fileName();
|
||||
loadShaderFile(prog, __GLShader__::Fragment, i.absoluteFilePath());
|
||||
loadShaderFile(prog, QOpenGLShader::Fragment, i.absoluteFilePath());
|
||||
}
|
||||
if (!prog->link()) {
|
||||
qDebug() << "[QGLView] Shader \"" + name + "\" link error: " + prog->log();
|
||||
@@ -150,7 +148,7 @@ bool loadShaders(__GLShaderProgram__ * prog, const QString & name, const QString
|
||||
}
|
||||
|
||||
|
||||
void setUniformMatrices(__GLShaderProgram__ * prog, QMatrix4x4 proj, QMatrix4x4 view, QMatrix4x4 prevproj, QMatrix4x4 prevview) {
|
||||
void setUniformMatrices(QOpenGLShaderProgram * prog, QMatrix4x4 proj, QMatrix4x4 view, QMatrix4x4 prevproj, QMatrix4x4 prevview) {
|
||||
if (!prog) return;
|
||||
if (!prog->isLinked()) return;
|
||||
QMatrix4x4 mvpm = proj * view;
|
||||
@@ -170,7 +168,7 @@ void setUniformMatrices(__GLShaderProgram__ * prog, QMatrix4x4 proj, QMatrix4x4
|
||||
}
|
||||
|
||||
|
||||
void setUniformMap(__GLShaderProgram__ * prog, QString map_name, const Map & map, int channel, int def_channel) {
|
||||
void setUniformMap(QOpenGLShaderProgram * 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);
|
||||
@@ -179,7 +177,7 @@ void setUniformMap(__GLShaderProgram__ * prog, QString map_name, const Map & map
|
||||
}
|
||||
|
||||
|
||||
void setUniformMaterial(__GLShaderProgram__ * prog, const Material & mat) {
|
||||
void setUniformMaterial(QOpenGLShaderProgram * prog, const Material & mat) {
|
||||
if (!prog) return;
|
||||
if (!prog->isLinked()) return;
|
||||
QGLCI
|
||||
@@ -206,7 +204,7 @@ void setUniformMaterial(__GLShaderProgram__ * prog, const Material & mat) {
|
||||
}
|
||||
|
||||
|
||||
void setUniformLights(__GLShaderProgram__ * prog, const QVector<Light*> & lights, const QMatrix4x4 & mat, int shadow_start) {
|
||||
void setUniformLights(QOpenGLShaderProgram * prog, const QVector<Light*> & lights, const QMatrix4x4 & mat, int shadow_start) {
|
||||
for (int i = 0; i < lights.size(); ++i)
|
||||
setUniformLight(prog, lights[i], QString("qgl_Light[%1]").arg(i), mat, shadow_start + i);
|
||||
}
|
||||
@@ -223,7 +221,7 @@ void setUniformLights(__GLShaderProgram__ * prog, const QVector<Light*> & lights
|
||||
" sampler2DShadow shadow;\n"
|
||||
" mat4 shadowMatrix;\n"
|
||||
*/
|
||||
void setUniformLight(__GLShaderProgram__ * prog, Light * light, QString ulightn, const QMatrix4x4 & mat, int shadow) {
|
||||
void setUniformLight(QOpenGLShaderProgram * prog, Light * light, QString ulightn, const QMatrix4x4 & mat, int shadow) {
|
||||
if (!prog) return;
|
||||
if (!prog->isLinked()) return;
|
||||
QMatrix4x4 m = mat * light->worldTransform();
|
||||
|
||||
@@ -25,12 +25,12 @@ class Map;
|
||||
class Material;
|
||||
class Light;
|
||||
|
||||
QString loadShaderFile(__GLShaderProgram__ * prog, __GLShader__::ShaderType type, const QString & file);
|
||||
bool loadShaders(__GLShaderProgram__ * prog, const QString & name, const QString & dir = QString());
|
||||
void setUniformMatrices(__GLShaderProgram__ * prog, QMatrix4x4 proj, QMatrix4x4 view, QMatrix4x4 prevproj = QMatrix4x4(), QMatrix4x4 prevview = QMatrix4x4());
|
||||
void setUniformMap(__GLShaderProgram__ * prog, const Map & map, int channel, int def_channel);
|
||||
void setUniformMaterial(__GLShaderProgram__ * prog, const Material & mat);
|
||||
void setUniformLights(__GLShaderProgram__ * prog, const QVector<Light*> & lights, const QMatrix4x4 & mat, int shadow_start);
|
||||
void setUniformLight(__GLShaderProgram__ * prog, Light * light, QString ulightn, const QMatrix4x4 & mat = QMatrix4x4(), int shadow = 0);
|
||||
QString loadShaderFile(QOpenGLShaderProgram * prog, QOpenGLShader::ShaderType type, const QString & file);
|
||||
bool loadShaders(QOpenGLShaderProgram * prog, const QString & name, const QString & dir = QString());
|
||||
void setUniformMatrices(QOpenGLShaderProgram * prog, QMatrix4x4 proj, QMatrix4x4 view, QMatrix4x4 prevproj = QMatrix4x4(), QMatrix4x4 prevview = QMatrix4x4());
|
||||
void setUniformMap(QOpenGLShaderProgram * prog, const Map & map, int channel, int def_channel);
|
||||
void setUniformMaterial(QOpenGLShaderProgram * prog, const Material & mat);
|
||||
void setUniformLights(QOpenGLShaderProgram * prog, const QVector<Light*> & lights, const QMatrix4x4 & mat, int shadow_start);
|
||||
void setUniformLight(QOpenGLShaderProgram * prog, Light * light, QString ulightn, const QMatrix4x4 & mat = QMatrix4x4(), int shadow = 0);
|
||||
|
||||
#endif // GLSHADERS_H
|
||||
|
||||
@@ -19,7 +19,9 @@
|
||||
#include "glcamera.h"
|
||||
#include "qglview.h"
|
||||
|
||||
__GLWidget__ * currentQGLView;
|
||||
#include <QPainter>
|
||||
|
||||
//__GLWidget__ * currentQGLView;
|
||||
QMutex globMutex;
|
||||
|
||||
|
||||
@@ -51,7 +53,7 @@ QString findFile(const QString & file, const QStringList & pathes) {
|
||||
}
|
||||
|
||||
|
||||
void glDrawQuad(__GLShaderProgram__ * prog, QVector4D * corner_dirs, GLfloat x, GLfloat y, GLfloat w, GLfloat h) {
|
||||
void glDrawQuad(QOpenGLShaderProgram * prog, QVector4D * corner_dirs, GLfloat x, GLfloat y, GLfloat w, GLfloat h) {
|
||||
QGLCI
|
||||
glResetAllTransforms();
|
||||
glSetPolygonMode(GL_FILL);
|
||||
@@ -72,12 +74,7 @@ void glDrawQuad(__GLShaderProgram__ * prog, QVector4D * corner_dirs, GLfloat x,
|
||||
QMatrix4x4 getGLMatrix(GLenum matrix) {
|
||||
GLdouble gm[16];
|
||||
glGetDoublev(matrix, gm);
|
||||
#if QT_VERSION < 0x050600
|
||||
qreal
|
||||
#else
|
||||
float
|
||||
#endif
|
||||
qm[16];
|
||||
float qm[16];
|
||||
for (int i = 0; i < 16; ++i)
|
||||
qm[i] = gm[i];
|
||||
return QMatrix4x4(qm).transposed();
|
||||
@@ -86,12 +83,7 @@ QMatrix4x4 getGLMatrix(GLenum matrix) {
|
||||
|
||||
void setGLMatrix(QMatrix4x4 matrix) {
|
||||
GLdouble gm[16];
|
||||
#if QT_VERSION < 0x050600
|
||||
qreal
|
||||
#else
|
||||
float
|
||||
#endif
|
||||
qm[16];
|
||||
float qm[16];
|
||||
matrix.transposed().copyDataTo(qm);
|
||||
for (int i = 0; i < 16; ++i)
|
||||
gm[i] = qm[i];
|
||||
@@ -101,12 +93,7 @@ void setGLMatrix(QMatrix4x4 matrix) {
|
||||
|
||||
void qglMultMatrix(const QMatrix4x4 & m) {
|
||||
GLdouble gm[16];
|
||||
#if QT_VERSION < 0x050600
|
||||
qreal
|
||||
#else
|
||||
float
|
||||
#endif
|
||||
qm[16];
|
||||
float qm[16];
|
||||
m.transposed().copyDataTo(qm);
|
||||
for (int i = 0; i < 16; ++i)
|
||||
gm[i] = qm[i];
|
||||
@@ -307,6 +294,11 @@ void QGLViewBase::setCamera(const Camera & camera) {
|
||||
}
|
||||
|
||||
|
||||
GLTextureManagerBase * QGLViewBase::textureManager() {
|
||||
return m_texture_manager;
|
||||
}
|
||||
|
||||
|
||||
Box3D::Box3D(const QVector<QVector3D> & points) {
|
||||
x = y = z = width = length = height = angle_z = angle_xy = angle_roll = 0.f;
|
||||
if (points.isEmpty()) return;
|
||||
|
||||
@@ -41,15 +41,9 @@
|
||||
# define CC_VC
|
||||
#endif
|
||||
|
||||
#if QT_VERSION < 0x050600
|
||||
# define GL_GLEXT_PROTOTYPES
|
||||
#endif
|
||||
|
||||
#include <QObject>
|
||||
#ifdef WINDOWS
|
||||
# if QT_VERSION < 0x050600
|
||||
# include "GLee.h"
|
||||
# endif
|
||||
#else
|
||||
#ifndef WINDOWS
|
||||
# ifdef MAC
|
||||
# include <OpenGL/gl.h>
|
||||
# include <OpenGL/glu.h>
|
||||
@@ -60,15 +54,12 @@
|
||||
# include <GL/glu.h>
|
||||
# endif
|
||||
#endif
|
||||
#if QT_VERSION < 0x050600
|
||||
# include <qgl.h>
|
||||
#else
|
||||
//# include "GLee.h"
|
||||
# include <QOpenGLExtraFunctions>
|
||||
#endif
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include <QOpenGLWidget>
|
||||
#include <QOpenGLShader>
|
||||
#include <QOpenGLShaderProgram>
|
||||
#include <cmath>
|
||||
#include <float.h>
|
||||
//#include <limits>
|
||||
#include <QMatrix4x4>
|
||||
#include <QDebug>
|
||||
#include <QDataStream>
|
||||
@@ -87,23 +78,7 @@
|
||||
# include <complex.h>
|
||||
#endif
|
||||
#include <iostream>
|
||||
#if QT_VERSION >= 0x050400
|
||||
# include <QOpenGLWidget>
|
||||
# include <QOpenGLShader>
|
||||
# include <QOpenGLShaderProgram>
|
||||
typedef QOpenGLWidget __GLWidget__;
|
||||
typedef QOpenGLContext __GLContext__;
|
||||
typedef QOpenGLShader __GLShader__;
|
||||
typedef QOpenGLShaderProgram __GLShaderProgram__;
|
||||
#else
|
||||
# include <QGLWidget>
|
||||
# include <QGLShader>
|
||||
# include <QGLShaderProgram>
|
||||
typedef QGLWidget __GLWidget__;
|
||||
typedef QGLContext __GLContext__;
|
||||
typedef QGLShader __GLShader__;
|
||||
typedef QGLShaderProgram __GLShaderProgram__;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef WINDOWS
|
||||
# define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
|
||||
@@ -169,8 +144,7 @@ QString findFile(const QString & file, const QStringList & pathes);
|
||||
inline QColor operator *(const QColor & c, double v) {return QColor(c.red() * v, c.green() * v, c.blue() * v, c.alpha() * v);}
|
||||
inline QColor operator /(const QColor & c, double v) {return QColor(c.red() / v, c.green() / v, c.blue() / v, c.alpha() / v);}
|
||||
|
||||
extern __GLWidget__ * currentQGLView;
|
||||
extern QMutex globMutex;
|
||||
//extern __GLWidget__ * currentQGLView;
|
||||
|
||||
inline void qglColor(const QColor & c) {glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF());}
|
||||
void qglMultMatrix(const QMatrix4x4 & m);
|
||||
@@ -184,11 +158,10 @@ inline void glSetCapEnabled(GLenum cap, bool on = true) {if (on) glEnable(cap);
|
||||
inline void glSetLightEnabled(bool on) {if (on) glEnable(GL_LIGHTING); else glDisable(GL_LIGHTING);}
|
||||
inline void glSetFogEnabled(bool on) {if (on) glEnable(GL_FOG); else glDisable(GL_FOG);}
|
||||
inline void glSetPolygonMode(GLenum mode) {glPolygonMode(GL_FRONT_AND_BACK, mode);}
|
||||
void glDrawQuad(__GLShaderProgram__ * prog = 0, QVector4D * corner_dirs = 0, GLfloat x = -1.f, GLfloat y = -1.f, GLfloat w = 2.f, GLfloat h = 2.f);
|
||||
void glDrawQuad(QOpenGLShaderProgram * prog = 0, QVector4D * corner_dirs = 0, GLfloat x = -1.f, GLfloat y = -1.f, GLfloat w = 2.f, GLfloat h = 2.f);
|
||||
QMatrix4x4 getGLMatrix(GLenum matrix);
|
||||
void setGLMatrix(QMatrix4x4 matrix);
|
||||
inline void deleteGLTexture(GLuint & tex) {if (tex != 0) glDeleteTextures(1, &tex); tex = 0;}
|
||||
#if QT_VERSION >= 0x050600
|
||||
# define QGLCI if (!QOpenGLContext::currentContext()) return; QOpenGLExtraFunctions gf(QOpenGLContext::currentContext());
|
||||
# define QGLC gf.
|
||||
inline void glActiveTextureChannel(int channel) {QGLCI gf.glActiveTexture(GL_TEXTURE0 + channel);}
|
||||
@@ -200,19 +173,6 @@ inline void deleteGLFramebuffer(GLuint & fbo) {QGLCI if (fbo != 0) gf.glDeleteFr
|
||||
inline void deleteGLRenderbuffer(GLuint & drbo) {QGLCI if (drbo != 0) gf.glDeleteRenderbuffers(1, &drbo); drbo = 0;}
|
||||
inline void deleteGLBuffer(GLuint & bo) {QGLCI if (bo != 0) gf.glDeleteBuffers(1, &bo); bo = 0;}
|
||||
inline void deleteGLVertexArray(GLuint & va) {QGLCI if (va != 0) gf.glDeleteVertexArrays(1, &va); va = 0;}
|
||||
#else
|
||||
# define QGLCI
|
||||
# define QGLC
|
||||
inline void glActiveTextureChannel(int channel) {glActiveTexture(GL_TEXTURE0 + channel); glClientActiveTexture(GL_TEXTURE0 + channel);}
|
||||
inline void glDisableTextures(int channels = 8) {for (int i = channels - 1; i >= 0; --i) {glActiveTextureChannel(i); glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_CUBE_MAP);}}
|
||||
inline void glReleaseTextures(int channels = 8) {for (int i = channels - 1; i >= 0; --i) {glActiveTextureChannel(i); glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_CUBE_MAP, 0);}}
|
||||
inline void glReleaseFramebuffer() {glBindFramebuffer(GL_FRAMEBUFFER, 0);}
|
||||
inline void glReleaseShaders() {glUseProgram(0);}
|
||||
inline void deleteGLFramebuffer(GLuint & fbo) {if (fbo != 0) glDeleteFramebuffers(1, &fbo); fbo = 0;}
|
||||
inline void deleteGLRenderbuffer(GLuint & drbo) {if (drbo != 0) glDeleteRenderbuffers(1, &drbo); drbo = 0;}
|
||||
inline void deleteGLBuffer(GLuint & bo) {if (bo != 0) glDeleteBuffers(1, &bo); bo = 0;}
|
||||
inline void deleteGLVertexArray(GLuint & va) {if (va != 0) glDeleteVertexArrays(1, &va); va = 0;}
|
||||
#endif
|
||||
void createGLTexture(GLuint & tex, int width, int height, const GLenum & format = GL_RGBA8, const GLenum & target = GL_TEXTURE_2D);
|
||||
void createGLTexture(GLuint & tex, const QImage & image, const GLenum & format = GL_RGBA8, const GLenum & target = GL_TEXTURE_2D);
|
||||
inline void qglTranslate(const QVector3D & v) {glTranslated(v.x(), v.y(), v.z());}
|
||||
@@ -367,6 +327,7 @@ class GLObjectBase;
|
||||
class QGLView;
|
||||
class Light;
|
||||
class Camera;
|
||||
class GLTextureManagerBase;
|
||||
|
||||
class QGLViewBase
|
||||
{
|
||||
@@ -376,9 +337,11 @@ public:
|
||||
Camera & camera();
|
||||
const Camera & camera() const;
|
||||
void setCamera(const Camera & camera);
|
||||
GLTextureManagerBase * textureManager();
|
||||
protected:
|
||||
virtual void collectLights() = 0;
|
||||
Camera * camera_;
|
||||
GLTextureManagerBase * m_texture_manager;
|
||||
};
|
||||
|
||||
#endif // GLTYPES_H
|
||||
|
||||
@@ -33,9 +33,7 @@ GLVBO::~GLVBO() {
|
||||
|
||||
|
||||
void GLVBO::init() {
|
||||
#if QT_VERSION >= 0x050600
|
||||
initializeOpenGLFunctions();
|
||||
#endif
|
||||
if (!isInit()) {
|
||||
//glGenVertexArrays(1, &va_);
|
||||
glGenBuffers(1, &buffer_);
|
||||
@@ -83,9 +81,7 @@ void GLVBO::calculateBinormals() {
|
||||
|
||||
|
||||
bool GLVBO::rebuffer(bool clear_) {
|
||||
#if QT_VERSION >= 0x050600
|
||||
initializeOpenGLFunctions();
|
||||
#endif
|
||||
QVector<GLfloat> data;
|
||||
//data.clear();
|
||||
calculateBinormals();
|
||||
@@ -120,7 +116,7 @@ bool GLVBO::rebuffer(bool clear_) {
|
||||
}
|
||||
|
||||
|
||||
void GLVBO::draw(GLenum type, __GLShaderProgram__ * prog, bool simplest) {
|
||||
void GLVBO::draw(GLenum type, QOpenGLShaderProgram * prog, bool simplest) {
|
||||
if (buffer_ == 0 || vert_count == 0) return;
|
||||
if (changed) rebuffer();
|
||||
//qDebug() << "draw" << vert_count;
|
||||
@@ -289,9 +285,8 @@ bool GLVBO::loadFromFile(const QString & filename) {
|
||||
}
|
||||
|
||||
|
||||
Box3D GLVBO::boundingBox(const QMatrix4x4 & mat) const {
|
||||
Box3D GLVBO::boundingBox() const {
|
||||
if (vertices_.size() < 3) return Box3D();
|
||||
bool mi = mat.isIdentity();
|
||||
int vcnt = vertices_.size() / 3;
|
||||
//qDebug() << "calculateBinormals" << vcnt << tcnt << vertices_.size() << texcoords_.size() << "...";
|
||||
GLfloat mix, miy, miz, max, may, maz;
|
||||
|
||||
@@ -22,10 +22,7 @@
|
||||
#include "gltypes.h"
|
||||
#include "chunkstream.h"
|
||||
|
||||
class GLVBO
|
||||
#if QT_VERSION >= 0x050600
|
||||
: protected QOpenGLExtraFunctions
|
||||
#endif
|
||||
class GLVBO : protected QOpenGLExtraFunctions
|
||||
{
|
||||
friend class GLObjectBase;
|
||||
friend QDataStream & operator <<(QDataStream & s, const GLVBO & m);
|
||||
@@ -39,7 +36,7 @@ public:
|
||||
void init();
|
||||
void destroy();
|
||||
bool rebuffer(bool clear_ = false);
|
||||
void draw(GLenum type, __GLShaderProgram__ * prog, bool simplest = false);
|
||||
void draw(GLenum type, QOpenGLShaderProgram * prog, bool simplest = false);
|
||||
void clear();
|
||||
|
||||
GLuint buffer() const {return buffer_;}
|
||||
@@ -58,7 +55,7 @@ public:
|
||||
bool saveToFile(const QString & filename);
|
||||
bool loadFromFile(const QString & filename);
|
||||
|
||||
Box3D boundingBox(const QMatrix4x4 & mat = QMatrix4x4()) const;
|
||||
Box3D boundingBox() const;
|
||||
|
||||
private:
|
||||
void calculateBinormals();
|
||||
|
||||
@@ -18,21 +18,22 @@
|
||||
|
||||
#include "qglview.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QKeyEvent>
|
||||
|
||||
QGLView::QGLView(QWidget * parent): QGraphicsView(parent), fbo_selection(3) {
|
||||
setFrameShape(QFrame::NoFrame);
|
||||
setViewportUpdateMode(FullViewportUpdate);
|
||||
setCacheMode(CacheNone);
|
||||
setMouseTracking(true);
|
||||
setFocusPolicy(Qt::WheelFocus);
|
||||
setScene(new QGraphicsScene());
|
||||
setInteractive(true);
|
||||
_w = 0;
|
||||
|
||||
QGLView::QGLView(): OpenGLWindow(), fbo_selection(3) {
|
||||
// setFrameShape(QFrame::NoFrame);
|
||||
// setViewportUpdateMode(FullViewportUpdate);
|
||||
// setCacheMode(CacheNone);
|
||||
// setMouseTracking(true);
|
||||
// setFocusPolicy(Qt::WheelFocus);
|
||||
// setScene(new QGraphicsScene());
|
||||
// setInteractive(true);
|
||||
timer = 0;
|
||||
need_init_ = is_first_draw = true;
|
||||
objects_.is_root = true;
|
||||
objects_.view_ = this;
|
||||
painter_ = 0;
|
||||
backColor_ = Qt::black;
|
||||
hoverHaloColor_ = QColor(195, 140, 255, 96);
|
||||
selectionHaloColor_ = QColor(175, 255, 140);
|
||||
@@ -45,17 +46,18 @@ QGLView::QGLView(QWidget * parent): QGraphicsView(parent), fbo_selection(3) {
|
||||
shaders_supported = selecting_ = customMouseMove_ = false;
|
||||
sel_button = Qt::LeftButton;
|
||||
sel_mod = Qt::NoModifier;
|
||||
renderer_ = 0;
|
||||
renderer_ = nullptr;
|
||||
fps_cnt = 0;
|
||||
fps_tm = fps_ = 0.;
|
||||
sel_obj = hov_obj = 0;
|
||||
sel_obj = hov_obj = nullptr;
|
||||
fogDensity_ = fogEnd_ = 1.;
|
||||
fogStart_ = 0.;
|
||||
fogMode_ = Exp;
|
||||
hoverHaloFill_ = 0.333;
|
||||
selectionHaloFill_ = 0.5;
|
||||
//lmode = Simple;
|
||||
shader_select = shader_halo = 0;
|
||||
shader_select = shader_halo = nullptr;
|
||||
m_texture_manager = new GLTextureManager();
|
||||
setFeature(qglMSAA, false);
|
||||
setFeature(qglFXAA, false);
|
||||
setFeature(qglLinearFiltering, true);
|
||||
@@ -84,11 +86,11 @@ QGLView::QGLView(QWidget * parent): QGraphicsView(parent), fbo_selection(3) {
|
||||
setFeature(qglDepthOfFieldFocus, 1.);
|
||||
setFeature(qglDepthOfFieldDiaphragm, 8.);
|
||||
mouse_first = mouseSelect_ = hoverHalo_ = selectionHalo_ = true;
|
||||
fogEnabled_ = is_init = grabMouse_ = mouseRotate_ = mouseThis_ = shaders_bind = changed_ = false;
|
||||
fogEnabled_ = is_init = grabMouse_ = mouseRotate_ = shaders_bind = changed_ = false;
|
||||
rmode = GLObjectBase::Fill;
|
||||
sel_mode = QGLView::SingleSelection;
|
||||
sel_pen = QPen(Qt::black, 1, Qt::DashLine);
|
||||
sel_brush = QBrush(QColor(170, 100, 255, 120));
|
||||
// sel_pen = QPen(Qt::black, 1, Qt::DashLine);
|
||||
// sel_brush = QBrush(QColor(170, 100, 255, 120));
|
||||
camera().setAim(QVector3D(0,0,5.5));
|
||||
camera().setPos(QVector3D(10, 5, 5.5));
|
||||
camera().setName("Camera");
|
||||
@@ -103,20 +105,27 @@ QGLView::~QGLView() {
|
||||
stop();
|
||||
if (shader_select) delete shader_select;
|
||||
if (shader_halo) delete shader_halo;
|
||||
currentQGLView = 0;
|
||||
currentGLTextureManager = 0;
|
||||
//if (shader_rope != 0) delete shader_rope;
|
||||
delete m_texture_manager;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::addObject(QWidget * o, Qt::WindowFlags f) {
|
||||
scene()->addWidget(o, f)->setCacheMode(QGraphicsItem::ItemCoordinateCache);
|
||||
/*QList<QGraphicsItem * > il = collectGraphicItems();
|
||||
foreach (QGraphicsItem * i, il) {
|
||||
QGraphicsProxyWidget * p = qgraphicsitem_cast<QGraphicsProxyWidget * >(i);
|
||||
if (p == 0) continue;
|
||||
p->setCacheMode(QGraphicsItem::ItemCoordinateCache);
|
||||
}*/
|
||||
void QGLView::stop() {
|
||||
if (timer) killTimer(timer);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::start(double freq) {
|
||||
timer = startTimer(freq <= 0. ? 0 : 1000. / freq);
|
||||
}
|
||||
|
||||
|
||||
GLRendererBase * QGLView::renderer() {
|
||||
return renderer_;
|
||||
}
|
||||
|
||||
void QGLView::setRenderer(GLRendererBase * r, GLRendererBase ** prev) {
|
||||
if (prev != nullptr) *prev = renderer_;
|
||||
renderer_ = r;
|
||||
}
|
||||
|
||||
|
||||
@@ -130,15 +139,13 @@ void QGLView::addObject(GLObjectBase * o) {
|
||||
emit objectAdded(i);
|
||||
}
|
||||
if (is_init) {
|
||||
globMutex.lock();
|
||||
o->init();
|
||||
globMutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QGLView::removeObject(GLObjectBase * o, bool inChildren) {
|
||||
o->setView(0);
|
||||
o->setView(nullptr);
|
||||
if (inChildren)
|
||||
removeObjectInternal(o, &objects_);
|
||||
else
|
||||
@@ -151,8 +158,8 @@ void QGLView::clearObjects(bool deleteAll) {
|
||||
removeObject(camera_);
|
||||
objects_.clearChildren(deleteAll);
|
||||
addObject(camera());
|
||||
selectObject(0);
|
||||
hov_obj = 0;
|
||||
selectObject(nullptr);
|
||||
hov_obj = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -164,95 +171,22 @@ void QGLView::selectObject(GLObjectBase * o) {
|
||||
}
|
||||
|
||||
|
||||
void QGLView::drawBackground(QPainter * painter, const QRectF & rect) {
|
||||
if (setupViewport()) {
|
||||
QGraphicsView::drawBackground(painter_, rect);
|
||||
return;
|
||||
}
|
||||
painter_ = painter;
|
||||
if (is_first_draw) {
|
||||
//connect(context(), SIGNAL(aboutToBeDestroyed()), this, SLOT(glCleanup()));
|
||||
//resizeGL(viewport()->width(), viewport()->height());
|
||||
initializeGL();
|
||||
}
|
||||
is_first_draw = false;
|
||||
painter_->beginNativePainting();
|
||||
paintGL();
|
||||
painter_->endNativePainting();
|
||||
glDisableDepth();
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glReleaseTextures();
|
||||
painter_ = 0;
|
||||
QGraphicsView::drawBackground(painter, rect);
|
||||
void QGLView::resizeEvent(QResizeEvent * e) {
|
||||
resizeGL(width(), height());
|
||||
/* QWindow::resizeEvent(e);*/
|
||||
}
|
||||
|
||||
void QGLView::timerEvent(QTimerEvent *) {
|
||||
renderNow();
|
||||
if (ktm_.elapsed() < QApplication::keyboardInputInterval()) return;
|
||||
Qt::KeyboardModifiers km = QApplication::keyboardModifiers();
|
||||
foreach (int i, keys_)
|
||||
emit keyEvent((Qt::Key)i, km);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::initializeGL() {
|
||||
//qDebug() << "init glview";
|
||||
//makeCurrent();
|
||||
#if QT_VERSION >= 0x050600
|
||||
initializeOpenGLFunctions();
|
||||
#endif
|
||||
currentQGLView = (__GLWidget__ * )viewport();
|
||||
currentGLTextureManager = &textures_manager;
|
||||
currentCamera = &camera();
|
||||
glEnable(GL_TEXTURE_MAX_ANISOTROPY_EXT);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glEnableDepth();
|
||||
glEnable(GL_CULL_FACE);
|
||||
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
|
||||
glActiveTextureChannel(3);
|
||||
glEnable(GL_TEXTURE_GEN_S);
|
||||
glEnable(GL_TEXTURE_GEN_T);
|
||||
glEnable(GL_TEXTURE_GEN_R);
|
||||
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
|
||||
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
|
||||
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
glActiveTextureChannel(0);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glCullFace(GL_BACK);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glColorMaterial(GL_FRONT, GL_DIFFUSE);
|
||||
|
||||
textures_manager.loadTextures();
|
||||
objects_.initInternal();
|
||||
checkCaps();
|
||||
|
||||
shader_select = new __GLShaderProgram__(context());
|
||||
shader_halo = new __GLShaderProgram__(context());
|
||||
//shader_rope = new __GLShaderProgram__(context());
|
||||
reloadThisShaders();
|
||||
is_init = true;
|
||||
resizeGL(viewport()->width(), viewport()->height());
|
||||
|
||||
//dynamic_cubemap.loadPathesFromDirectory("e");
|
||||
//dynamic_cubemap.load();
|
||||
/*dynamic_cubemap.loadFront("e/front.jpg");
|
||||
dynamic_cubemap.loadBack("e/back.jpg");
|
||||
dynamic_cubemap.loadLeft("e/left.jpg");
|
||||
dynamic_cubemap.loadRight("e/right.jpg");
|
||||
dynamic_cubemap.loadTop("e/top.jpg");
|
||||
dynamic_cubemap.loadBottom("e/bottom.jpg");*/
|
||||
//glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
|
||||
//GLuint t = 0;
|
||||
//createGLTexture(t, QImage("e/bottom.jpg"));
|
||||
//qDebug() << bindTexture(QImage("e/bottom.jpg"));
|
||||
|
||||
need_init_ = false;
|
||||
emit glInitializeDone();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::paintGL() {
|
||||
#if QT_VERSION >= 0x050600
|
||||
//initializeOpenGLFunctions();
|
||||
if (need_init_)
|
||||
initializeGL();
|
||||
#endif
|
||||
void QGLView::render() {
|
||||
QRect g_rect(QPoint(), size());
|
||||
emit glBeforePaint();
|
||||
//qDebug() << "paintGL";
|
||||
//QMutexLocker ml_v(&v_mutex);
|
||||
@@ -290,16 +224,16 @@ void QGLView::paintGL() {
|
||||
if (shaders_supported && shader_select->isLinked()) shader_select->release();
|
||||
uchar cgid[4] = {0, 0, 0, 0};
|
||||
uint iid = 0;
|
||||
GLObjectBase * so = 0;
|
||||
if (!rect().contains(lastPos)) {
|
||||
if (hov_obj != 0) {
|
||||
hov_obj = 0;
|
||||
emit hoverChanged(0, hov_obj);
|
||||
GLObjectBase * so = nullptr;
|
||||
if (!g_rect.contains(lastPos)) {
|
||||
if (hov_obj != nullptr) {
|
||||
hov_obj = nullptr;
|
||||
emit hoverChanged(nullptr, hov_obj);
|
||||
}
|
||||
} else {
|
||||
glReadPixels(lastPos.x(), viewport()->height() - lastPos.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, cgid);
|
||||
glReadPixels(lastPos.x(), height() - lastPos.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, cgid);
|
||||
iid = (cgid[0] << 24) | (cgid[1] << 16) | (cgid[2] << 8) | cgid[3];
|
||||
so = ids[iid];
|
||||
so = ids.value(iid, nullptr);
|
||||
//qDebug() <<cgid[0]<<cgid[1]<<cgid[2]<<cgid[3]<< iid;
|
||||
if (so != hov_obj) {
|
||||
emit hoverChanged(so, hov_obj);
|
||||
@@ -309,7 +243,7 @@ void QGLView::paintGL() {
|
||||
}
|
||||
if (selectionHalo_ && sel_obj) {
|
||||
fbo_selection.setWriteBuffer(2);
|
||||
renderHalo(sel_obj, ids.key(sel_obj), selectionHaloColor_, selectionHaloFill_);
|
||||
renderHalo(sel_obj, qHash((quint64)sel_obj), selectionHaloColor_, selectionHaloFill_);
|
||||
}
|
||||
if (hoverHalo_ && hov_obj) {
|
||||
fbo_selection.setWriteBuffer(1);
|
||||
@@ -327,18 +261,18 @@ void QGLView::paintGL() {
|
||||
cur_mvpm = start_rp.proj_matrix * start_rp.view_matrix * start_rp.cam_offset_matrix;
|
||||
//objects_.preparePos(camera());
|
||||
|
||||
static GLRendererBase * prev_rend = 0;
|
||||
static GLRendererBase * prev_rend = nullptr;
|
||||
glShadeModel(GL_SMOOTH);
|
||||
if (prev_rend != renderer_) {
|
||||
prev_rend = renderer_;
|
||||
if (renderer_ != 0) {
|
||||
renderer_->init(viewport()->width(), viewport()->height());
|
||||
renderer_->resize(viewport()->width(), viewport()->height());
|
||||
if (renderer_ != nullptr) {
|
||||
renderer_->init(width(), height());
|
||||
renderer_->resize(width(), height());
|
||||
renderer_->reloadShaders();
|
||||
}
|
||||
}
|
||||
emit glBeginPaint();
|
||||
if (renderer_ != 0) {
|
||||
if (renderer_ != nullptr) {
|
||||
renderer_->rp.prepare();
|
||||
renderer_->prepareScene();
|
||||
renderer_->renderScene();
|
||||
@@ -367,13 +301,6 @@ void QGLView::paintGL() {
|
||||
}
|
||||
}
|
||||
|
||||
if (selecting_ && painter_) {
|
||||
painter_->setPen(sel_pen);
|
||||
painter_->setBrush(sel_brush);
|
||||
painter_->drawRect(QRect(downPos, lastPos).normalized());
|
||||
qDebug() << QRect(downPos, lastPos).normalized();
|
||||
}
|
||||
|
||||
glReleaseShaders();
|
||||
glResetAllTransforms();
|
||||
glReleaseFramebuffer();
|
||||
@@ -419,12 +346,47 @@ void QGLView::paintGL() {
|
||||
fps_ = fps_cnt / fps_tm * 1000.;
|
||||
fps_tm = 0.;
|
||||
fps_cnt = 0;
|
||||
|
||||
//glResetAllTransforms();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::renderHalo(const GLObjectBase * obj, const int iid, const QColor & color, const double & fill) {
|
||||
void QGLView::initialize() {
|
||||
initializeOpenGLFunctions();
|
||||
glEnable(GL_TEXTURE_MAX_ANISOTROPY_EXT);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glEnableDepth();
|
||||
glEnable(GL_CULL_FACE);
|
||||
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
|
||||
glActiveTextureChannel(3);
|
||||
glEnable(GL_TEXTURE_GEN_S);
|
||||
glEnable(GL_TEXTURE_GEN_T);
|
||||
glEnable(GL_TEXTURE_GEN_R);
|
||||
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
|
||||
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
|
||||
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
glActiveTextureChannel(0);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glCullFace(GL_BACK);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glColorMaterial(GL_FRONT, GL_DIFFUSE);
|
||||
|
||||
textures_manager.loadTextures();
|
||||
objects_.initInternal();
|
||||
checkCaps();
|
||||
|
||||
shader_select = new QOpenGLShaderProgram(context());
|
||||
shader_halo = new QOpenGLShaderProgram(context());
|
||||
reloadThisShaders();
|
||||
is_init = true;
|
||||
resizeGL(width(), height());
|
||||
need_init_ = false;
|
||||
emit glInitializeDone();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::renderHalo(const GLObjectBase * obj, const uint iid, const QColor & color, const double & fill) {
|
||||
if (!shaders_supported) return;
|
||||
if (!shader_halo) return;
|
||||
if (!shader_halo->isLinked()) return;
|
||||
@@ -434,7 +396,7 @@ void QGLView::renderHalo(const GLObjectBase * obj, const int iid, const QColor &
|
||||
glActiveTextureChannel(0);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_selection.colorTexture());
|
||||
shader_halo->setUniformValue("t0", 0);
|
||||
shader_halo->setUniformValue("dt", QVector2D(1. / viewport()->width(), 1. / viewport()->height()));
|
||||
shader_halo->setUniformValue("dt", QVector2D(1. / width(), 1. / height()));
|
||||
shader_halo->setUniformValue("selected", QVector4D(float((iid >> 24) & 0xFF) / 255.f,
|
||||
float((iid >> 16) & 0xFF) / 255.f,
|
||||
float((iid >> 8) & 0xFF) / 255.f,
|
||||
@@ -454,7 +416,7 @@ void QGLView::renderHalo(const GLObjectBase * obj, const int iid, const QColor &
|
||||
|
||||
|
||||
void QGLView::renderSelection() {
|
||||
cid = 1;
|
||||
// cid = 1;
|
||||
ids.clear();
|
||||
if (shaders_supported) {
|
||||
if (shader_select) {
|
||||
@@ -480,28 +442,29 @@ void QGLView::renderSingleSelection(GLObjectBase & o) {
|
||||
}
|
||||
if (!o.visible_ || !o.select_) return;
|
||||
QMatrix4x4 curview = start_rp.view_matrix * start_rp.cam_offset_matrix * o.itransform_;
|
||||
ids.insert(cid, &o);
|
||||
uint id = qHash((quint64)&o);
|
||||
ids.insert(id, &o);
|
||||
if (shaders_supported){
|
||||
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));
|
||||
shader_select->setUniformValue(sh_id_loc, QVector4D(float((id >> 24) & 0xFF) / 255.f,
|
||||
float((id >> 16) & 0xFF) / 255.f,
|
||||
float((id >> 8) & 0xFF) / 255.f,
|
||||
float(id & 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);
|
||||
glColor4f(float((id >> 24) & 0xFF) / 255.f,
|
||||
float((id >> 16) & 0xFF) / 255.f,
|
||||
float((id >> 8) & 0xFF) / 255.f,
|
||||
float(id & 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(0, true);
|
||||
// ++cid;
|
||||
o.draw(nullptr, true);
|
||||
foreach (GLObjectBase * i, o.children_)
|
||||
renderSingleSelection(*i);
|
||||
}
|
||||
@@ -515,25 +478,8 @@ void QGLView::collectLights() {
|
||||
|
||||
void QGLView::objectDeleted(GLObjectBase * o) {
|
||||
//qDebug() << "del" << o;
|
||||
if (sel_obj == o) selectObject(0);
|
||||
if (hov_obj == o) hov_obj = 0;
|
||||
}
|
||||
|
||||
|
||||
QList<QGraphicsItem * > QGLView::collectGraphicItems() {
|
||||
QList<QGraphicsItem * > list = scene()->items();
|
||||
foreach (QGraphicsItem * i, list)
|
||||
collectGraphicItems(list, i);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::collectGraphicItems(QList<QGraphicsItem * > & list, QGraphicsItem * o) {
|
||||
QList<QGraphicsItem * > cl = o->childItems();
|
||||
foreach (QGraphicsItem * i, cl) {
|
||||
list << i;
|
||||
collectGraphicItems(list, i);
|
||||
}
|
||||
if (sel_obj == o) selectObject(nullptr);
|
||||
if (hov_obj == o) hov_obj = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -563,7 +509,7 @@ void QGLView::checkCaps() {
|
||||
//glGetIntegerv(GL_MAX_TEXTURE_UNITS, &max_texture_chanels);
|
||||
//qDebug() << max_texture_chanels;
|
||||
//qDebug() << max_texture_chanels;
|
||||
shaders_supported = __GLShaderProgram__::hasOpenGLShaderPrograms();
|
||||
shaders_supported = QOpenGLShaderProgram::hasOpenGLShaderPrograms();
|
||||
}
|
||||
|
||||
|
||||
@@ -605,10 +551,10 @@ void QGLView::resizeGL(int width, int height) {
|
||||
|
||||
|
||||
void QGLView::mouseReleaseEvent(QMouseEvent * e) {
|
||||
QGraphicsView::mouseReleaseEvent(e);
|
||||
// QGraphicsView::mouseReleaseEvent(e);
|
||||
//setCursor(QCursor(Qt::ArrowCursor));
|
||||
selecting_ = false;
|
||||
if (mouseThis_ && mouseSelect_ && e->button() == Qt::LeftButton) {
|
||||
if (mouseSelect_ && e->button() == Qt::LeftButton) {
|
||||
if ((lastPos - downPos).manhattanLength() < 8) {
|
||||
if (sel_obj != hov_obj)
|
||||
selectObject(hov_obj);
|
||||
@@ -619,14 +565,10 @@ void QGLView::mouseReleaseEvent(QMouseEvent * e) {
|
||||
|
||||
|
||||
void QGLView::mousePressEvent(QMouseEvent * e) {
|
||||
QGraphicsView::mousePressEvent(e);
|
||||
mouseThis_ = (scene()->itemAt(mapToScene(e->pos())
|
||||
#if QT_VERSION >= 0x050000
|
||||
, QTransform()
|
||||
#endif
|
||||
) == 0);
|
||||
// QGraphicsView::mousePressEvent(e);
|
||||
// mouseThis_ = (scene()->itemAt(mapToScene(e->pos()) , QTransform() ) == 0);
|
||||
selecting_ = false;
|
||||
if (!mouseThis_) return;
|
||||
if (!QRect(QPoint(), size()).contains(e->pos())) return;
|
||||
/// TODO select by rect
|
||||
//if (e->button() == sel_button && e->modifiers() == sel_mod)
|
||||
// selecting_ = true;
|
||||
@@ -638,16 +580,16 @@ void QGLView::mousePressEvent(QMouseEvent * e) {
|
||||
|
||||
|
||||
void QGLView::mouseMoveEvent(QMouseEvent * e) {
|
||||
//qDebug() << e->pos();
|
||||
QGraphicsView::mouseMoveEvent(e);
|
||||
// qDebug() << e->pos();
|
||||
// QGraphicsView::mouseMoveEvent(e);
|
||||
//lastPos = e->pos();
|
||||
if (selecting_) {
|
||||
|
||||
return;
|
||||
}
|
||||
if (!mouseThis_) return;
|
||||
//if (scene()->itemAt(mapToScene(e->pos())) != 0) return;
|
||||
///qDebug() << e->x() << e->y();
|
||||
QRect g_rect(QPoint(), size());
|
||||
if (mouseRotate_) {
|
||||
double dx = e->x() - lastPos.x();
|
||||
double dy = e->y() - lastPos.y();
|
||||
@@ -676,7 +618,7 @@ void QGLView::mouseMoveEvent(QMouseEvent * e) {
|
||||
lastPos = e->pos();
|
||||
if (grabMouse_) {
|
||||
//if (!isrunning) return;
|
||||
QCursor::setPos(mapToGlobal(rect().center()));
|
||||
QCursor::setPos(mapToGlobal(QRect(QPoint(), size()).center()));
|
||||
static bool mouse_sec = false;
|
||||
if (mouse_sec) {
|
||||
mouse_sec = false;
|
||||
@@ -688,7 +630,7 @@ void QGLView::mouseMoveEvent(QMouseEvent * e) {
|
||||
//qDebug() << "first" << e->pos();
|
||||
return;
|
||||
}
|
||||
lastPos = rect().center();
|
||||
lastPos = g_rect.center();
|
||||
int dx = e->x() - lastPos.x();
|
||||
int dy = e->y() - lastPos.y();
|
||||
emit glMouseMoveEvent(new QMouseEvent(QEvent::MouseMove, QPoint(dx, dy), e->button(), e->buttons(), e->modifiers()));
|
||||
@@ -699,12 +641,6 @@ void QGLView::mouseMoveEvent(QMouseEvent * e) {
|
||||
|
||||
|
||||
void QGLView::wheelEvent(QWheelEvent * e) {
|
||||
QGraphicsView::wheelEvent(e);
|
||||
if (scene()->itemAt(mapToScene(e->pos())
|
||||
#if QT_VERSION >= 0x050000
|
||||
, QTransform()
|
||||
#endif
|
||||
) != 0) return;
|
||||
if (mouseRotate_) {
|
||||
if (e->delta() > 0) camera().flyCloser(0.1); //camera().pos.setZ(camera().pos.z() - 0.1 * camera().pos.z());
|
||||
if (e->delta() < 0) camera().flyFarer(0.1); //camera().pos.setZ(camera().pos.z() + 0.1 * camera().pos.z());
|
||||
@@ -720,37 +656,19 @@ void QGLView::leaveEvent(QEvent * ) {
|
||||
}
|
||||
|
||||
|
||||
void QGLView::processKeys() {
|
||||
if (ktm_.elapsed() < QApplication::keyboardInputInterval()) return;
|
||||
Qt::KeyboardModifiers km = QApplication::keyboardModifiers();
|
||||
foreach (int i, keys_)
|
||||
emit keyEvent((Qt::Key)i, km);
|
||||
void QGLView::keyPressEvent(QKeyEvent * e) {
|
||||
emit glKeyPressEvent(e);
|
||||
if (e->key() > 0) keys_.insert(e->key());
|
||||
}
|
||||
|
||||
|
||||
bool QGLView::setupViewport() {
|
||||
if (_w) return false;
|
||||
#if QT_VERSION >= 0x050600
|
||||
_w = new __GLWidget__();
|
||||
QSurfaceFormat f = _w->format();
|
||||
f.setSamples(8);
|
||||
_w->setFormat(f);
|
||||
#else
|
||||
QGLFormat f(QGL::DoubleBuffer | QGL::DepthBuffer | QGL::Rgba | QGL::AlphaChannel | QGL::DirectRendering | QGL::SampleBuffers);
|
||||
f.setSwapInterval(1);
|
||||
_w = new __GLWidget__(f);
|
||||
#endif
|
||||
setViewport(_w);
|
||||
_w->setMouseTracking(true);
|
||||
return true;
|
||||
void QGLView::keyReleaseEvent(QKeyEvent * e) {
|
||||
emit glKeyReleaseEvent(e);
|
||||
keys_.remove(e->key());
|
||||
}
|
||||
|
||||
|
||||
void QGLView::glCleanup() {
|
||||
//qDebug() << "cleanup";
|
||||
/*disconnect(context(), SIGNAL(aboutToBeDestroyed()), this, SLOT(glCleanup()));
|
||||
is_first_draw = true;
|
||||
textures_manager = GLTextureManager();
|
||||
currentQGLView = 0;
|
||||
currentGLTextureManager = 0;*/
|
||||
void QGLView::focusOutEvent(QFocusEvent *)
|
||||
{keys_.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,27 +19,15 @@
|
||||
#ifndef QGLVIEW_H
|
||||
#define QGLVIEW_H
|
||||
|
||||
#include "openglwindow.h"
|
||||
#include "glframebuffer.h"
|
||||
#include <QGraphicsProxyWidget>
|
||||
#include <QGraphicsView>
|
||||
#include <QGLFramebufferObject>
|
||||
#include <QVector3D>
|
||||
#include <QTimer>
|
||||
#include <QTime>
|
||||
#include <QMouseEvent>
|
||||
#include <QDebug>
|
||||
#include <QMutex>
|
||||
#include <QThread>
|
||||
#include <QApplication>
|
||||
#include "glprimitives.h"
|
||||
#include "glparticles_system.h"
|
||||
#include "glrendererbase.h"
|
||||
#include <QTime>
|
||||
|
||||
|
||||
class QGLView: public QGraphicsView, public QGLViewBase
|
||||
#if QT_VERSION >= 0x050600
|
||||
, protected QOpenGLExtraFunctions
|
||||
#endif
|
||||
class QGLView: public OpenGLWindow, public QGLViewBase
|
||||
{
|
||||
friend class GLRendererBase;
|
||||
friend class GLObjectBase;
|
||||
@@ -67,15 +55,12 @@ class QGLView: public QGraphicsView, public QGLViewBase
|
||||
Q_PROPERTY (bool selectionHalo READ isSelectionHaloEnabled WRITE setSelectionHaloEnabled)
|
||||
Q_PROPERTY (QColor selectionHaloColor READ selectionHaloColor WRITE setSelectionHaloColor)
|
||||
Q_PROPERTY (double selectionHaloFillAlpha READ selectionHaloFillAlpha WRITE setSelectionHaloFillAlpha)
|
||||
//Q_PROPERTY (LightingMode lightingMode READ lightingMode WRITE setLightingMode)
|
||||
Q_PROPERTY (Qt::MouseButton selectionButton READ selectionButton WRITE setSelectionButton)
|
||||
Q_PROPERTY (Qt::KeyboardModifier selectionModifier READ selectionModifier WRITE setSelectionModifier)
|
||||
Q_PROPERTY (SelectionMode selectionMode READ selectionMode WRITE setSelectionMode)
|
||||
Q_PROPERTY (QPen selectionRectPen READ selectionRectPen WRITE setSelectionRectPen)
|
||||
Q_PROPERTY (QBrush selectionRectBrush READ selectionRectBrush WRITE setSelectionRectBrush)
|
||||
|
||||
public:
|
||||
QGLView(QWidget * parent = 0);
|
||||
QGLView();
|
||||
virtual ~QGLView();
|
||||
|
||||
enum FogMode {Linear = GL_LINEAR, Exp = GL_EXP, Exp2 = GL_EXP2};
|
||||
@@ -112,21 +97,12 @@ public:
|
||||
|
||||
Q_ENUMS (FogMode)
|
||||
Q_ENUMS (SelectionMode)
|
||||
//enum LightingMode {Simple, PerPixel, DeferredShading};
|
||||
//Q_ENUMS (LightingMode)
|
||||
|
||||
void stop() {if (timer) killTimer(timer);}
|
||||
void start(double freq = 40.) {timer = startTimer(freq <= 0. ? 0 : 1000. / freq);}
|
||||
void stop();
|
||||
void start(double freq = 40.);
|
||||
|
||||
GLRendererBase * renderer() {return renderer_;}
|
||||
void setRenderer(GLRendererBase * r, GLRendererBase ** prev = 0) {if (prev != 0) *prev = renderer_; renderer_ = r;}
|
||||
|
||||
#if QT_VERSION >= 0x050600
|
||||
__GLContext__ * context() {return ((__GLWidget__ * )viewport())->context();}
|
||||
#else
|
||||
const __GLContext__ * context() const {return ((const __GLWidget__ * )viewport())->context();}
|
||||
#endif
|
||||
void makeCurrent() {((__GLWidget__ * )viewport())->makeCurrent();}
|
||||
GLRendererBase * renderer();
|
||||
void setRenderer(GLRendererBase * r, GLRendererBase ** prev = nullptr);
|
||||
|
||||
QColor backColor() const {return backColor_;}
|
||||
double lineWidth() const {return lineWidth_;}
|
||||
@@ -142,7 +118,6 @@ public:
|
||||
double fogStart() const {return fogStart_;}
|
||||
double fogEnd() const {return fogEnd_;}
|
||||
FogMode fogMode() const {return fogMode_;}
|
||||
//LightingMode lightingMode() const {return lmode;}
|
||||
bool isFogEnabled() const {return fogEnabled_;}
|
||||
bool isLightEnabled() const {return lightEnabled_;}
|
||||
bool isGrabMouseEnabled() const {return grabMouse_;}
|
||||
@@ -163,7 +138,6 @@ public:
|
||||
int renderMode() const {return (int)rmode;}
|
||||
void setRenderMode(int mode) {rmode = (GLObjectBase::RenderMode)mode;}
|
||||
|
||||
void addObject(QGraphicsItem * o) {scene()->addItem(o);}
|
||||
void addObject(QWidget * o, Qt::WindowFlags f = Qt::Widget);
|
||||
void addObject(GLObjectBase * o);
|
||||
void addObject(GLObjectBase & o) {addObject(&o);}
|
||||
@@ -189,8 +163,6 @@ public:
|
||||
Light * light(int index) {return lights_[index];}
|
||||
Light * light(const QString & name) {foreach (Light * i, lights_) if (i->name_ == name) return i; return 0;}
|
||||
|
||||
QPen selectionRectPen() const {return sel_pen;}
|
||||
QBrush selectionRectBrush() const {return sel_brush;}
|
||||
SelectionMode selectionMode() const {return sel_mode;}
|
||||
Qt::MouseButton selectionButton() const {return sel_button;}
|
||||
Qt::KeyboardModifier selectionModifier() const {return sel_mod;}
|
||||
@@ -198,31 +170,28 @@ public:
|
||||
void setSelectionMode(SelectionMode v) {sel_mode = v;}
|
||||
void setSelectionButton(Qt::MouseButton v) {sel_button = v;}
|
||||
void setSelectionModifier(Qt::KeyboardModifier v) {sel_mod = v;}
|
||||
void setSelectionRectPen(const QPen & v) {sel_pen = v;}
|
||||
void setSelectionRectBrush(const QBrush & v) {sel_brush = v;}
|
||||
void selectObject(GLObjectBase * o);
|
||||
GLObjectBase * selectedObject() const {return sel_obj;}
|
||||
|
||||
GLdouble aspect, iaspect;
|
||||
QMatrix4x4 cur_mvpm;
|
||||
//__GLShaderProgram__ * shader_rope;
|
||||
|
||||
protected:
|
||||
virtual void drawBackground(QPainter * painter, const QRectF & rect);
|
||||
virtual void resizeEvent(QResizeEvent * e) {resizeGL(viewport()->width(), viewport()->height()); QGraphicsView::resizeEvent(e);}
|
||||
void render();
|
||||
void resizeEvent(QResizeEvent * e);
|
||||
|
||||
void timerEvent(QTimerEvent * ) {/*globMutex.lock();*/ processKeys(); viewport()->repaint(); /*globMutex.unlock();*/}
|
||||
void initializeGL();
|
||||
void paintGL();
|
||||
void timerEvent(QTimerEvent * );
|
||||
void initialize();
|
||||
void resizeGL(int width, int height);
|
||||
void mousePressEvent(QMouseEvent * e);
|
||||
void mouseMoveEvent(QMouseEvent * e);
|
||||
void mouseReleaseEvent(QMouseEvent * e);
|
||||
void wheelEvent(QWheelEvent * e);
|
||||
void leaveEvent(QEvent * );
|
||||
void keyPressEvent(QKeyEvent * e) {emit glKeyPressEvent(e); if (e->key() > 0) keys_.insert(e->key());}
|
||||
void keyReleaseEvent(QKeyEvent * e) {emit glKeyReleaseEvent(e); keys_.remove(e->key());}
|
||||
void focusOutEvent(QFocusEvent *) {keys_.clear();}
|
||||
|
||||
void keyPressEvent(QKeyEvent * e);
|
||||
void keyReleaseEvent(QKeyEvent * e);
|
||||
void focusOutEvent(QFocusEvent *);
|
||||
|
||||
void applyFog();
|
||||
void renderSelection();
|
||||
@@ -237,46 +206,38 @@ private:
|
||||
void removeObjectInternal(GLObjectBase * o, GLObjectBase * where);
|
||||
void renderSingleSelection(GLObjectBase & o);
|
||||
//void renderSingleShadow(GLObjectBase & o);
|
||||
void renderHalo(const GLObjectBase * obj, const int iid, const QColor & color, const double & fill);
|
||||
QList<QGraphicsItem * > collectGraphicItems();
|
||||
void collectGraphicItems(QList<QGraphicsItem * > & list, QGraphicsItem * o);
|
||||
void renderHalo(const GLObjectBase * obj, const uint iid, const QColor & color, const double & fill);
|
||||
void reloadThisShaders();
|
||||
void processKeys();
|
||||
bool setupViewport();
|
||||
|
||||
QPoint lastPos, downPos;
|
||||
QMutex v_mutex;
|
||||
GLTextureManager textures_manager;
|
||||
GLObjectBase objects_;
|
||||
QList<Light * > lights_;
|
||||
uint cid;
|
||||
QMap<uint, GLObjectBase * > ids;
|
||||
// uint cid;
|
||||
QHash<uint, GLObjectBase * > ids;
|
||||
QSet<int> keys_;
|
||||
FogMode fogMode_;
|
||||
QColor backColor_, fogColor_, ambientColor_, hoverHaloColor_, selectionHaloColor_;
|
||||
QPainter * painter_;
|
||||
QTime time, ktm_;
|
||||
QPen sel_pen;
|
||||
QBrush sel_brush;
|
||||
GLint max_anisotropic, max_texture_chanels;
|
||||
GLObjectBase::RenderMode rmode;
|
||||
//LightingMode lmode;
|
||||
GLObjectBase * sel_obj, * hov_obj;
|
||||
GLFramebuffer fbo_selection;
|
||||
__GLShaderProgram__ * shader_select, * shader_halo;
|
||||
QOpenGLShaderProgram * shader_select, * shader_halo;
|
||||
GLRendererBase * renderer_;
|
||||
SelectionMode sel_mode;
|
||||
Qt::MouseButton sel_button;
|
||||
Qt::KeyboardModifier sel_mod;
|
||||
GLRendererBase::RenderingParameters start_rp;
|
||||
QHash<int, QVariant> features_;
|
||||
__GLWidget__ * _w;
|
||||
double lineWidth_;
|
||||
double fogDensity_, fogStart_, fogEnd_, fps_, fps_tm, hoverHaloFill_, selectionHaloFill_, m_motionBlurFactor;
|
||||
int timer, fps_cnt, sh_id_loc;
|
||||
bool is_first_draw, is_init, fogEnabled_, lightEnabled_, grabMouse_, mouse_first, mouseRotate_, mouseSelect_, customMouseMove_;
|
||||
bool shaders_supported, changed_, cameraOrbit_, need_init_;
|
||||
bool hoverHalo_, selectionHalo_, mouseThis_, shaders_bind, selecting_;
|
||||
bool hoverHalo_, selectionHalo_, shaders_bind, selecting_;
|
||||
|
||||
public slots:
|
||||
void setBackColor(const QColor & arg) {backColor_ = arg;}
|
||||
@@ -303,11 +264,9 @@ public slots:
|
||||
void setSelectionHaloEnabled(const bool & arg) {selectionHalo_ = arg;}
|
||||
void setSelectionHaloColor(const QColor & arg) {selectionHaloColor_ = arg;}
|
||||
void setSelectionHaloFillAlpha(const double & arg) {selectionHaloFill_ = arg;}
|
||||
//void setLightingMode(const LightingMode & arg) {lmode = arg;}
|
||||
|
||||
void reloadShaders() {if (renderer_ != 0) renderer_->reloadShaders(); reloadThisShaders();}
|
||||
void deselect() {sel_obj = 0;}
|
||||
void glCleanup();
|
||||
|
||||
signals:
|
||||
void glBeforePaint();
|
||||
|
||||
@@ -23,9 +23,7 @@
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
QApplication a(argc, argv);
|
||||
#if QT_VERSION >= 0x050000
|
||||
a.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
|
||||
#endif
|
||||
QGLViewWindow w;
|
||||
w.show();
|
||||
QStringList al(a.arguments());
|
||||
|
||||
@@ -36,61 +36,61 @@ QGLViewWindow::QGLViewWindow(QWidget * parent): QMainWindow(parent), Ui::QGLView
|
||||
icon_light = QIcon(":/icons/type-light.png");
|
||||
|
||||
sel_obj = 0;
|
||||
view->camera().setAim(QVector3D());
|
||||
view->camera().setPos(QVector3D(2, 2, 2));
|
||||
view->setFrameShape(QFrame::NoFrame);
|
||||
view->setRenderer(new RendererSimple(view));
|
||||
view->setMouseRotateEnabled(true);
|
||||
view->setMouseSelectionEnabled(true);
|
||||
view->setSelectionHaloEnabled(true);
|
||||
view->setHoverHaloEnabled(true);
|
||||
view->setHoverHaloFillAlpha(0.);
|
||||
view->setSelectionHaloFillAlpha(0.);
|
||||
view->setBackColor(Qt::lightGray);
|
||||
view->setDepthStart(0.001);
|
||||
view->setDepthEnd(100000.);
|
||||
view->view()->camera().setAim(QVector3D());
|
||||
view->view()->camera().setPos(QVector3D(2, 2, 2));
|
||||
// view->setFrameShape(QFrame::NoFrame);
|
||||
view->view()->setRenderer(new RendererSimple(view->view()));
|
||||
view->view()->setMouseRotateEnabled(true);
|
||||
view->view()->setMouseSelectionEnabled(true);
|
||||
view->view()->setSelectionHaloEnabled(true);
|
||||
view->view()->setHoverHaloEnabled(true);
|
||||
view->view()->setHoverHaloFillAlpha(0.);
|
||||
view->view()->setSelectionHaloFillAlpha(0.);
|
||||
view->view()->setBackColor(Qt::lightGray);
|
||||
view->view()->setDepthStart(0.001);
|
||||
view->view()->setDepthEnd(100000.);
|
||||
|
||||
spinFOV->setValue(view->FOV());
|
||||
spinDepthStart->setValue(view->depthStart());
|
||||
spinDepthEnd->setValue(view->depthEnd());
|
||||
groupHoverHalo->setChecked(view->isHoverHaloEnabled());
|
||||
groupSelectionHalo->setChecked(view->isSelectionHaloEnabled());
|
||||
spinHoverHaloFill->setValue(view->hoverHaloFillAlpha());
|
||||
spinSelectionHaloFill->setValue(view->selectionHaloFillAlpha());
|
||||
colorHoverHalo->setColor(view->hoverHaloColor());
|
||||
colorSelectionHalo->setColor(view->selectionHaloColor());
|
||||
checkFXAA->setChecked(view->isFeatureEnabled(QGLView::qglFXAA));
|
||||
checkMSAA->setChecked(view->isFeatureEnabled(QGLView::qglMSAA));
|
||||
colorBack->setColor(view->backColor());
|
||||
colorAmbient->setColor(view->ambientColor());
|
||||
checkCameraOrbit->setChecked(view->isCameraOrbit());
|
||||
spinFOV->setValue(view->view()->FOV());
|
||||
spinDepthStart->setValue(view->view()->depthStart());
|
||||
spinDepthEnd->setValue(view->view()->depthEnd());
|
||||
groupHoverHalo->setChecked(view->view()->isHoverHaloEnabled());
|
||||
groupSelectionHalo->setChecked(view->view()->isSelectionHaloEnabled());
|
||||
spinHoverHaloFill->setValue(view->view()->hoverHaloFillAlpha());
|
||||
spinSelectionHaloFill->setValue(view->view()->selectionHaloFillAlpha());
|
||||
colorHoverHalo->setColor(view->view()->hoverHaloColor());
|
||||
colorSelectionHalo->setColor(view->view()->selectionHaloColor());
|
||||
checkFXAA->setChecked(view->view()->isFeatureEnabled(QGLView::qglFXAA));
|
||||
checkMSAA->setChecked(view->view()->isFeatureEnabled(QGLView::qglMSAA));
|
||||
colorBack->setColor(view->view()->backColor());
|
||||
colorAmbient->setColor(view->view()->ambientColor());
|
||||
checkCameraOrbit->setChecked(view->view()->isCameraOrbit());
|
||||
|
||||
groupShadows->setChecked(view->isFeatureEnabled(QGLView::qglShadowsEnabled));
|
||||
groupEyeAccomodation->setChecked(view->isFeatureEnabled(QGLView::qglEyeAccomodationEnabled));
|
||||
groupBloom->setChecked(view->isFeatureEnabled(QGLView::qglBloomEnabled));
|
||||
groupMotionBlur->setChecked(view->isFeatureEnabled(QGLView::qglMotionBlurEnabled));
|
||||
groupReflections->setChecked(view->isFeatureEnabled(QGLView::qglReflectionsEnabled));
|
||||
checkSoftShadows->setChecked(view->isFeatureEnabled(QGLView::qglShadowsSoftEnabled));
|
||||
groupSSAO->setChecked(view->isFeatureEnabled(QGLView::qglSSAOEnabled));
|
||||
spinAccom->setValue(view->feature(QGLView::qglEyeAccomodationTime).toDouble());
|
||||
spinAccomMS->setValue(view->feature(QGLView::qglEyeAccomodationMaxSpeed).toDouble());
|
||||
checkReflectionsBlur->setChecked(view->isFeatureEnabled(QGLView::qglReflectionsBlur));
|
||||
spinShadowmapSize->setValue(view->feature(QGLView::qglShadowsMapSize).toInt());
|
||||
spinMotionBlurFactor->setValue(view->feature(QGLView::qglMotionBlurFactor).toDouble());
|
||||
spinMotionBlurSteps->setValue(view->feature(QGLView::qglMotionBlurSteps).toInt());
|
||||
spinBloomFactor->setValue(view->feature(QGLView::qglBloomFactor).toDouble());
|
||||
spinBloomRadius->setValue(view->feature(QGLView::qglBloomRadius).toInt());
|
||||
spinBloomThreshold->setValue(view->feature(QGLView::qglBloomThreshold).toDouble());
|
||||
spinSSAORadius->setValue(view->feature(QGLView::qglSSAORadius).toInt());
|
||||
groupDOF->setChecked(view->isFeatureEnabled(QGLView::qglDepthOfFieldEnabled));
|
||||
checkDOFAutoFocus->setChecked(view->isFeatureEnabled(QGLView::qglDepthOfFieldAutoFocusEnabled));
|
||||
spinDOFFocus->setValue(view->feature(QGLView::qglDepthOfFieldFocus).toDouble());
|
||||
spinDOFDiaphragm->setValue(view->feature(QGLView::qglDepthOfFieldDiaphragm).toDouble());
|
||||
spinDOFSpeed->setValue(view->feature(QGLView::qglDepthOfFieldAutoFocusSpeed).toDouble());
|
||||
groupShadows->setChecked(view->view()->isFeatureEnabled(QGLView::qglShadowsEnabled));
|
||||
groupEyeAccomodation->setChecked(view->view()->isFeatureEnabled(QGLView::qglEyeAccomodationEnabled));
|
||||
groupBloom->setChecked(view->view()->isFeatureEnabled(QGLView::qglBloomEnabled));
|
||||
groupMotionBlur->setChecked(view->view()->isFeatureEnabled(QGLView::qglMotionBlurEnabled));
|
||||
groupReflections->setChecked(view->view()->isFeatureEnabled(QGLView::qglReflectionsEnabled));
|
||||
checkSoftShadows->setChecked(view->view()->isFeatureEnabled(QGLView::qglShadowsSoftEnabled));
|
||||
groupSSAO->setChecked(view->view()->isFeatureEnabled(QGLView::qglSSAOEnabled));
|
||||
spinAccom->setValue(view->view()->feature(QGLView::qglEyeAccomodationTime).toDouble());
|
||||
spinAccomMS->setValue(view->view()->feature(QGLView::qglEyeAccomodationMaxSpeed).toDouble());
|
||||
checkReflectionsBlur->setChecked(view->view()->isFeatureEnabled(QGLView::qglReflectionsBlur));
|
||||
spinShadowmapSize->setValue(view->view()->feature(QGLView::qglShadowsMapSize).toInt());
|
||||
spinMotionBlurFactor->setValue(view->view()->feature(QGLView::qglMotionBlurFactor).toDouble());
|
||||
spinMotionBlurSteps->setValue(view->view()->feature(QGLView::qglMotionBlurSteps).toInt());
|
||||
spinBloomFactor->setValue(view->view()->feature(QGLView::qglBloomFactor).toDouble());
|
||||
spinBloomRadius->setValue(view->view()->feature(QGLView::qglBloomRadius).toInt());
|
||||
spinBloomThreshold->setValue(view->view()->feature(QGLView::qglBloomThreshold).toDouble());
|
||||
spinSSAORadius->setValue(view->view()->feature(QGLView::qglSSAORadius).toInt());
|
||||
groupDOF->setChecked(view->view()->isFeatureEnabled(QGLView::qglDepthOfFieldEnabled));
|
||||
checkDOFAutoFocus->setChecked(view->view()->isFeatureEnabled(QGLView::qglDepthOfFieldAutoFocusEnabled));
|
||||
spinDOFFocus->setValue(view->view()->feature(QGLView::qglDepthOfFieldFocus).toDouble());
|
||||
spinDOFDiaphragm->setValue(view->view()->feature(QGLView::qglDepthOfFieldDiaphragm).toDouble());
|
||||
spinDOFSpeed->setValue(view->view()->feature(QGLView::qglDepthOfFieldAutoFocusSpeed).toDouble());
|
||||
|
||||
axis = new GLObjectBase();
|
||||
GLObjectBase * obj;
|
||||
double al = 1.;
|
||||
float al = 1.;
|
||||
obj = new GLPrimitiveLine(QVector3D(0, 0, -al), QVector3D(0, 0, al));
|
||||
obj->material().color_diffuse = Qt::darkBlue; obj->setAcceptLight(false);
|
||||
axis->addChild(obj);
|
||||
@@ -100,19 +100,20 @@ QGLViewWindow::QGLViewWindow(QWidget * parent): QMainWindow(parent), Ui::QGLView
|
||||
obj = new GLPrimitiveLine(QVector3D(0, -al, 0), QVector3D(0, al, 0));
|
||||
obj->material().color_diffuse = Qt::darkGreen; obj->setAcceptLight(false);
|
||||
axis->addChild(obj);
|
||||
view->addObject(axis);
|
||||
view->view()->addObject(axis);
|
||||
|
||||
cam_light = new Light();
|
||||
cam_light->intensity = 0.5;
|
||||
cam_light->setName("Camera_Light");
|
||||
view->camera().addChild(cam_light);
|
||||
view->start(-1);
|
||||
view->view()->camera().addChild(cam_light);
|
||||
view->view()->start(-1);
|
||||
startTimer(1000/60);
|
||||
|
||||
connect(view, SIGNAL(selectionChanged(GLObjectBase*,GLObjectBase*)), this, SLOT(selectionChanged(GLObjectBase*,GLObjectBase*)));
|
||||
connect(view->view(), SIGNAL(selectionChanged(GLObjectBase*,GLObjectBase*)), this, SLOT(selectionChanged(GLObjectBase*,GLObjectBase*)));
|
||||
connect(view->view(), SIGNAL(keyEvent(Qt::Key, Qt::KeyboardModifiers)), this, SLOT(view_keyEvent(Qt::Key, Qt::KeyboardModifiers)));
|
||||
connect(matEditor, SIGNAL(changed()), this, SLOT(materialChanged()));
|
||||
|
||||
//view->addObject(&partsys);
|
||||
//view->view()->addObject(&partsys);
|
||||
partsys.material().color_diffuse = Qt::red;
|
||||
treeProps->assignObject(&partsys);
|
||||
session.load();
|
||||
@@ -138,24 +139,8 @@ void QGLViewWindow::timerEvent(QTimerEvent * ) {
|
||||
//static double t = 0.;
|
||||
//cam_light->intensity = checkCameraLight->isChecked() ? 0.5 : 0.;
|
||||
cam_light->setVisible(checkCameraLight->isChecked());
|
||||
//((RendererSimple*)(view->renderer()))->mpos = view->mapFromGlobal(QCursor::pos());
|
||||
statusBar()->showMessage(QString("FPS: %1").arg(QString::number(view->currentFPS(), 'f', 2)));
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::on_view_glKeyPressEvent(QKeyEvent * e) {
|
||||
if (e->key() != Qt::Key_F11) return;
|
||||
if (view->windowState().testFlag(Qt::WindowFullScreen)) {
|
||||
centralwidget->layout()->addWidget(view);
|
||||
} else {
|
||||
view->setParent(0);
|
||||
view->showFullScreen();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::on_view_glInitializeDone() {
|
||||
|
||||
//((RendererSimple*)(view->view()->renderer()))->mpos = view->view()->mapFromGlobal(QCursor::pos());
|
||||
statusBar()->showMessage(QString("FPS: %1").arg(QString::number(view->view()->currentFPS(), 'f', 2)));
|
||||
}
|
||||
|
||||
|
||||
@@ -180,7 +165,7 @@ void QGLViewWindow::importFile(const QString & path) {
|
||||
return;
|
||||
}
|
||||
o->setName(fi.baseName());
|
||||
view->addObject(o);
|
||||
view->view()->addObject(o);
|
||||
objectsTreeChanged();
|
||||
}
|
||||
|
||||
@@ -233,18 +218,18 @@ void QGLViewWindow::materialChanged() {
|
||||
void QGLViewWindow::on_comboRenderer_currentIndexChanged(int val) {
|
||||
GLRendererBase * pr = 0;
|
||||
switch (val) {
|
||||
case 0: view->setRenderer(new RendererSimple(view), &pr); break;
|
||||
case 1: view->setRenderer(new RendererDeferredShading(view), &pr); break;
|
||||
//case 2: view->setRenderer(new RendererRT(view), &pr); break;
|
||||
case 0: view->view()->setRenderer(new RendererSimple(view->view()), &pr); break;
|
||||
case 1: view->view()->setRenderer(new RendererDeferredShading(view->view()), &pr); break;
|
||||
//case 2: view->view()->setRenderer(new RendererRT(view), &pr); break;
|
||||
}
|
||||
if (pr != 0) delete pr;
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::on_actionReset_triggered() {
|
||||
view->removeObject(axis, false);
|
||||
view->clearObjects(true);
|
||||
view->addObject(axis);
|
||||
view->view()->removeObject(axis, false);
|
||||
view->view()->clearObjects(true);
|
||||
view->view()->addObject(axis);
|
||||
objectsTreeChanged();
|
||||
}
|
||||
|
||||
@@ -269,11 +254,11 @@ void QGLViewWindow::on_actionSave_triggered() {
|
||||
if (f.right(4).toLower() != ".qgl")
|
||||
f += ".qgl";
|
||||
prev_path = f;
|
||||
view->removeObject(axis);
|
||||
view->view()->removeObject(axis);
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
saveToQGLFile(f, &(view->rootObject()));
|
||||
saveToQGLFile(f, &(view->view()->rootObject()));
|
||||
QApplication::restoreOverrideCursor();
|
||||
view->addObject(axis);
|
||||
view->view()->addObject(axis);
|
||||
}
|
||||
|
||||
|
||||
@@ -303,16 +288,16 @@ void QGLViewWindow::on_actionOpen_triggered() {
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::on_view_keyEvent(Qt::Key k, Qt::KeyboardModifiers m) {
|
||||
void QGLViewWindow::view_keyEvent(Qt::Key k, Qt::KeyboardModifiers m) {
|
||||
//qDebug() << k;
|
||||
double spd = 0.2;
|
||||
if (m.testFlag(Qt::ShiftModifier))
|
||||
spd = 0.5;
|
||||
switch (k) {
|
||||
case Qt::Key_W: view->camera().moveForward(spd); break;
|
||||
case Qt::Key_S: view->camera().moveBackward(spd); break;
|
||||
case Qt::Key_A: view->camera().moveLeft(spd); break;
|
||||
case Qt::Key_D: view->camera().moveRight(spd); break;
|
||||
case Qt::Key_W: view->view()->camera().moveForward(spd); break;
|
||||
case Qt::Key_S: view->view()->camera().moveBackward(spd); break;
|
||||
case Qt::Key_A: view->view()->camera().moveLeft(spd); break;
|
||||
case Qt::Key_D: view->view()->camera().moveRight(spd); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@@ -322,28 +307,28 @@ void QGLViewWindow::on_treeObjects_itemClicked(QTreeWidgetItem * ti, int col) {
|
||||
((GLObjectBase*)(ti->data(0, Qt::UserRole).toULongLong()))->select();
|
||||
//qDebug() << ((GLObjectBase*)(ti->data(0, Qt::UserRole).toULongLong()))->type();
|
||||
if (sel_obj->type() == GLObjectBase::glCamera)
|
||||
view->setCamera(*(Camera*)sel_obj);
|
||||
view->view()->setCamera(*(Camera*)sel_obj);
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::objectsTreeChanged() {
|
||||
treeObjects->clear();
|
||||
makeObjetTree(&(view->rootObject()), treeObjects->invisibleRootItem());
|
||||
makeObjetTree(&(view->view()->rootObject()), treeObjects->invisibleRootItem());
|
||||
treeObjects->expandAll();
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::on_pushButton_clicked() {
|
||||
//view->removeLight(view->lightsCount() - 1);
|
||||
//setWindowTitle(QString::number(view->lightsCount()));
|
||||
QVector3D wp = view->light(0)->worldPos();
|
||||
view->camera().setPos(wp);
|
||||
view->camera().setAim(wp + (view->light(0)->worldTransform() * QVector4D(view->light(0)->direction)).toVector3D()*100);
|
||||
//view->view()->removeLight(view->view()->lightsCount() - 1);
|
||||
//setWindowTitle(QString::number(view->view()->lightsCount()));
|
||||
QVector3D wp = view->view()->light(0)->worldPos();
|
||||
view->view()->camera().setPos(wp);
|
||||
view->view()->camera().setAim(wp + (view->view()->light(0)->worldTransform() * QVector4D(view->view()->light(0)->direction)).toVector3D()*100);
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::on_pushButton_3_clicked() {
|
||||
QList<GLObjectBase * > ol = view->objects(true);
|
||||
QList<GLObjectBase * > ol = view->view()->objects(true);
|
||||
qDebug() << ol.size();
|
||||
foreach (GLObjectBase * i, ol) {
|
||||
i->VBO().rebuffer();
|
||||
|
||||
@@ -38,6 +38,8 @@
|
||||
#include "session_manager.h"
|
||||
//#include "renderer_rt.h"
|
||||
#include "glparticles_system.h"
|
||||
#include "qglview.h"
|
||||
#include "ui_qglview_window.h"
|
||||
|
||||
|
||||
class QGLViewWindow: public QMainWindow, public Ui::QGLViewWindow
|
||||
@@ -70,45 +72,45 @@ private:
|
||||
GLParticlesSystem partsys;
|
||||
|
||||
private slots:
|
||||
void on_spinFOV_valueChanged(double val) {view->setFOV(val);}
|
||||
void on_spinDepthStart_valueChanged(double val) {view->setDepthStart(val);}
|
||||
void on_spinDepthEnd_valueChanged(double val) {view->setDepthEnd(val);}
|
||||
void on_spinFOV_valueChanged(double val) {view->view()->setFOV(val);}
|
||||
void on_spinDepthStart_valueChanged(double val) {view->view()->setDepthStart(val);}
|
||||
void on_spinDepthEnd_valueChanged(double val) {view->view()->setDepthEnd(val);}
|
||||
void on_comboRenderer_currentIndexChanged(int val);
|
||||
void on_comboViewRenderMode_currentIndexChanged(int val) {static int modes[] = {GL_POINT, GL_LINE, GL_FILL}; view->setRenderMode((GLObjectBase::RenderMode)modes[val]);}
|
||||
void on_groupHoverHalo_clicked(bool val) {view->setHoverHaloEnabled(val);}
|
||||
void on_groupSelectionHalo_clicked(bool val) {view->setSelectionHaloEnabled(val);}
|
||||
void on_spinHoverHaloFill_valueChanged(double val) {view->setHoverHaloFillAlpha(val);}
|
||||
void on_spinSelectionHaloFill_valueChanged(double val) {view->setSelectionHaloFillAlpha(val);}
|
||||
void on_colorHoverHalo_colorChanged(QColor color) {view->setHoverHaloColor(color);}
|
||||
void on_colorSelectionHalo_colorChanged(QColor color) {view->setSelectionHaloColor(color);}
|
||||
void on_checkFXAA_clicked(bool val) {view->setFeature(QGLView::qglFXAA, val);}
|
||||
void on_checkMSAA_clicked(bool val) {view->setFeature(QGLView::qglMSAA, val);}
|
||||
void on_colorBack_colorChanged(QColor color) {view->setBackColor(color);}
|
||||
void on_colorAmbient_colorChanged(QColor color) {view->setAmbientColor(color);}
|
||||
void on_checkCameraOrbit_clicked(bool val) {view->setCameraOrbit(val);}
|
||||
void on_comboViewRenderMode_currentIndexChanged(int val) {static int modes[] = {GL_POINT, GL_LINE, GL_FILL}; view->view()->setRenderMode((GLObjectBase::RenderMode)modes[val]);}
|
||||
void on_groupHoverHalo_clicked(bool val) {view->view()->setHoverHaloEnabled(val);}
|
||||
void on_groupSelectionHalo_clicked(bool val) {view->view()->setSelectionHaloEnabled(val);}
|
||||
void on_spinHoverHaloFill_valueChanged(double val) {view->view()->setHoverHaloFillAlpha(val);}
|
||||
void on_spinSelectionHaloFill_valueChanged(double val) {view->view()->setSelectionHaloFillAlpha(val);}
|
||||
void on_colorHoverHalo_colorChanged(QColor color) {view->view()->setHoverHaloColor(color);}
|
||||
void on_colorSelectionHalo_colorChanged(QColor color) {view->view()->setSelectionHaloColor(color);}
|
||||
void on_checkFXAA_clicked(bool val) {view->view()->setFeature(QGLView::qglFXAA, val);}
|
||||
void on_checkMSAA_clicked(bool val) {view->view()->setFeature(QGLView::qglMSAA, val);}
|
||||
void on_colorBack_colorChanged(QColor color) {view->view()->setBackColor(color);}
|
||||
void on_colorAmbient_colorChanged(QColor color) {view->view()->setAmbientColor(color);}
|
||||
void on_checkCameraOrbit_clicked(bool val) {view->view()->setCameraOrbit(val);}
|
||||
|
||||
void on_groupShadows_clicked(bool val) {view->setFeature(QGLView::qglShadowsEnabled, val);}
|
||||
void on_groupEyeAccomodation_clicked(bool val) {view->setFeature(QGLView::qglEyeAccomodationEnabled, val);}
|
||||
void on_groupBloom_clicked(bool val) {view->setFeature(QGLView::qglBloomEnabled, val);}
|
||||
void on_groupMotionBlur_clicked(bool val) {view->setFeature(QGLView::qglMotionBlurEnabled, val);}
|
||||
void on_groupReflections_clicked(bool val) {view->setFeature(QGLView::qglReflectionsEnabled, val);}
|
||||
void on_checkSoftShadows_clicked(bool val) {view->setFeature(QGLView::qglShadowsSoftEnabled, val);}
|
||||
void on_groupSSAO_clicked(bool val) {view->setFeature(QGLView::qglSSAOEnabled, val);}
|
||||
void on_groupDOF_clicked(bool val) {view->setFeature(QGLView::qglDepthOfFieldEnabled, val);}
|
||||
void on_checkDOFAutoFocus_clicked(bool val) {view->setFeature(QGLView::qglDepthOfFieldAutoFocusEnabled, val);}
|
||||
void on_spinDOFFocus_valueChanged(double val) {view->setFeature(QGLView::qglDepthOfFieldFocus, val);}
|
||||
void on_spinDOFDiaphragm_valueChanged(double val) {view->setFeature(QGLView::qglDepthOfFieldDiaphragm, val);}
|
||||
void on_spinDOFSpeed_valueChanged(double val) {view->setFeature(QGLView::qglDepthOfFieldAutoFocusSpeed, val);}
|
||||
void on_spinAccom_valueChanged(double val) {view->setFeature(QGLView::qglEyeAccomodationTime, val);}
|
||||
void on_spinAccomMS_valueChanged(double val) {view->setFeature(QGLView::qglEyeAccomodationMaxSpeed, val);}
|
||||
void on_checkReflectionsBlur_clicked(bool val) {view->setFeature(QGLView::qglReflectionsBlur, val);}
|
||||
void on_spinShadowmapSize_valueChanged(double val) {view->setFeature(QGLView::qglShadowsMapSize, val);}
|
||||
void on_spinMotionBlurFactor_valueChanged(double val) {view->setFeature(QGLView::qglMotionBlurFactor, val);}
|
||||
void on_spinMotionBlurSteps_valueChanged(int val) {view->setFeature(QGLView::qglMotionBlurSteps, val);}
|
||||
void on_spinBloomFactor_valueChanged(double val) {view->setFeature(QGLView::qglBloomFactor, val);}
|
||||
void on_spinBloomRadius_valueChanged(int val) {view->setFeature(QGLView::qglBloomRadius, val);}
|
||||
void on_spinBloomThreshold_valueChanged(double val) {view->setFeature(QGLView::qglBloomThreshold, val);}
|
||||
void on_spinSSAORadius_valueChanged(int val) {view->setFeature(QGLView::qglSSAORadius, val);}
|
||||
void on_groupShadows_clicked(bool val) {view->view()->setFeature(QGLView::qglShadowsEnabled, val);}
|
||||
void on_groupEyeAccomodation_clicked(bool val) {view->view()->setFeature(QGLView::qglEyeAccomodationEnabled, val);}
|
||||
void on_groupBloom_clicked(bool val) {view->view()->setFeature(QGLView::qglBloomEnabled, val);}
|
||||
void on_groupMotionBlur_clicked(bool val) {view->view()->setFeature(QGLView::qglMotionBlurEnabled, val);}
|
||||
void on_groupReflections_clicked(bool val) {view->view()->setFeature(QGLView::qglReflectionsEnabled, val);}
|
||||
void on_checkSoftShadows_clicked(bool val) {view->view()->setFeature(QGLView::qglShadowsSoftEnabled, val);}
|
||||
void on_groupSSAO_clicked(bool val) {view->view()->setFeature(QGLView::qglSSAOEnabled, val);}
|
||||
void on_groupDOF_clicked(bool val) {view->view()->setFeature(QGLView::qglDepthOfFieldEnabled, val);}
|
||||
void on_checkDOFAutoFocus_clicked(bool val) {view->view()->setFeature(QGLView::qglDepthOfFieldAutoFocusEnabled, val);}
|
||||
void on_spinDOFFocus_valueChanged(double val) {view->view()->setFeature(QGLView::qglDepthOfFieldFocus, val);}
|
||||
void on_spinDOFDiaphragm_valueChanged(double val) {view->view()->setFeature(QGLView::qglDepthOfFieldDiaphragm, val);}
|
||||
void on_spinDOFSpeed_valueChanged(double val) {view->view()->setFeature(QGLView::qglDepthOfFieldAutoFocusSpeed, val);}
|
||||
void on_spinAccom_valueChanged(double val) {view->view()->setFeature(QGLView::qglEyeAccomodationTime, val);}
|
||||
void on_spinAccomMS_valueChanged(double val) {view->view()->setFeature(QGLView::qglEyeAccomodationMaxSpeed, val);}
|
||||
void on_checkReflectionsBlur_clicked(bool val) {view->view()->setFeature(QGLView::qglReflectionsBlur, val);}
|
||||
void on_spinShadowmapSize_valueChanged(double val) {view->view()->setFeature(QGLView::qglShadowsMapSize, val);}
|
||||
void on_spinMotionBlurFactor_valueChanged(double val) {view->view()->setFeature(QGLView::qglMotionBlurFactor, val);}
|
||||
void on_spinMotionBlurSteps_valueChanged(int val) {view->view()->setFeature(QGLView::qglMotionBlurSteps, val);}
|
||||
void on_spinBloomFactor_valueChanged(double val) {view->view()->setFeature(QGLView::qglBloomFactor, val);}
|
||||
void on_spinBloomRadius_valueChanged(int val) {view->view()->setFeature(QGLView::qglBloomRadius, val);}
|
||||
void on_spinBloomThreshold_valueChanged(double val) {view->view()->setFeature(QGLView::qglBloomThreshold, val);}
|
||||
void on_spinSSAORadius_valueChanged(int val) {view->view()->setFeature(QGLView::qglSSAORadius, val);}
|
||||
|
||||
void on_actionExit_triggered() {close();}
|
||||
void on_actionReset_triggered();
|
||||
@@ -117,9 +119,7 @@ private slots:
|
||||
void on_actionSaveSelected_triggered();
|
||||
void on_actionOpen_triggered();
|
||||
|
||||
void on_view_glKeyPressEvent(QKeyEvent * e);
|
||||
void on_view_glInitializeDone();
|
||||
void on_view_keyEvent(Qt::Key k, Qt::KeyboardModifiers m);
|
||||
void view_keyEvent(Qt::Key k, Qt::KeyboardModifiers m);
|
||||
|
||||
void on_treeObjects_itemClicked(QTreeWidgetItem * ti, int col);
|
||||
|
||||
@@ -128,7 +128,7 @@ private slots:
|
||||
void selectionChanged(GLObjectBase * cur, GLObjectBase * prev);
|
||||
|
||||
void on_pushButton_clicked();
|
||||
void on_pushButton_2_clicked() {view->reloadShaders();}
|
||||
void on_pushButton_2_clicked() {view->view()->reloadShaders();}
|
||||
void on_pushButton_3_clicked();
|
||||
|
||||
public slots:
|
||||
|
||||
@@ -1015,7 +1015,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGLView" name="view" native="true">
|
||||
<widget class="GLWidget" name="view" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
@@ -1075,7 +1075,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1125</width>
|
||||
<height>24</height>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
@@ -1096,7 +1096,7 @@
|
||||
<widget class="QStatusBar" name="statusBar_"/>
|
||||
<action name="actionExit">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="../../qad/application/qad_application.qrc">
|
||||
<normaloff>:/icons/application-exit.png</normaloff>:/icons/application-exit.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
@@ -1105,7 +1105,7 @@
|
||||
</action>
|
||||
<action name="actionImport">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="../qglview.qrc">
|
||||
<normaloff>:/icons/document-import.png</normaloff>:/icons/document-import.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
@@ -1117,7 +1117,7 @@
|
||||
</action>
|
||||
<action name="actionOpen">
|
||||
<property name="icon">
|
||||
<iconset resource="../../../SM/src/SignalModelling/signalmodelling.qrc">
|
||||
<iconset resource="../../qad/application/qad_application.qrc">
|
||||
<normaloff>:/icons/document-open.png</normaloff>:/icons/document-open.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
@@ -1129,7 +1129,7 @@
|
||||
</action>
|
||||
<action name="actionSave">
|
||||
<property name="icon">
|
||||
<iconset resource="../../../SM/src/SignalModelling/signalmodelling.qrc">
|
||||
<iconset resource="../../qad/application/qad_application.qrc">
|
||||
<normaloff>:/icons/document-save-all.png</normaloff>:/icons/document-save-all.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
@@ -1141,7 +1141,7 @@
|
||||
</action>
|
||||
<action name="actionReset">
|
||||
<property name="icon">
|
||||
<iconset resource="../../../SM/src/SMBricks/SM_plugins/signal_process/icons.qrc">
|
||||
<iconset resource="../../qad/application/qad_application.qrc">
|
||||
<normaloff>:/icons/document-new.png</normaloff>:/icons/document-new.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
@@ -1153,7 +1153,7 @@
|
||||
</action>
|
||||
<action name="actionSaveSelected">
|
||||
<property name="icon">
|
||||
<iconset resource="../../../SM/src/SMBricks/SM_plugins/signal_process/icons.qrc">
|
||||
<iconset resource="../../piqt_utils/piconnedit/piconnedit.qrc">
|
||||
<normaloff>:/icons/document-save-.png</normaloff>:/icons/document-save-.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
@@ -1179,9 +1179,9 @@
|
||||
<header>colorbutton.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>QGLView</class>
|
||||
<class>GLWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header location="global">qglview.h</header>
|
||||
<header location="global">glwidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
@@ -1202,6 +1202,10 @@
|
||||
<header>propertyeditor.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<resources>
|
||||
<include location="../../qad/application/qad_application.qrc"/>
|
||||
<include location="../../piqt_utils/piconnedit/piconnedit.qrc"/>
|
||||
<include location="../qglview.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
@@ -59,7 +59,7 @@ fbo_g(5, true, GL_RGBA16F), fbo_out(3, false, GL_RGBA16F), fbo_hsmall(1, false,
|
||||
|
||||
RendererDeferredShading::~RendererDeferredShading() {
|
||||
for (int i = 0; i < shaders.size(); ++i) {
|
||||
__GLShaderProgram__ * p(*(shaders[i].second));
|
||||
QOpenGLShaderProgram * p(*(shaders[i].second));
|
||||
if (p) delete p;
|
||||
}
|
||||
delete df;
|
||||
@@ -88,15 +88,15 @@ void RendererDeferredShading::renderScene() {
|
||||
fbo_g.bind();
|
||||
int buffs[] = {0, 1, 2, 3, 4};
|
||||
fbo_g.setWriteBuffers(buffs, 5);
|
||||
if (white_image_id == 0 && currentGLTextureManager) {
|
||||
if (white_image_id == 0) {
|
||||
glActiveTextureChannel(6);
|
||||
white_image_id = ((GLTextureManagerBase*)currentGLTextureManager)->loadTexture(white_image, false);
|
||||
white_image_id = view.textureManager()->loadTexture(white_image, false);
|
||||
glBindTexture(GL_TEXTURE_2D, white_image_id);
|
||||
glActiveTextureChannel(0);
|
||||
}
|
||||
if (violent_image_id == 0 && currentGLTextureManager) {
|
||||
if (violent_image_id == 0) {
|
||||
glActiveTextureChannel(7);
|
||||
violent_image_id = ((GLTextureManagerBase*)currentGLTextureManager)->loadTexture(violent_image, false);
|
||||
violent_image_id = view.textureManager()->loadTexture(violent_image, false);
|
||||
glBindTexture(GL_TEXTURE_2D, violent_image_id);
|
||||
glActiveTextureChannel(0);
|
||||
}
|
||||
@@ -112,7 +112,7 @@ void RendererDeferredShading::renderScene() {
|
||||
shader_ds_0->setUniformValue("t2", 2);
|
||||
shader_ds_0->setUniformValue("t3", 3);
|
||||
shader_ds_0->setUniformValue("t4", 4);
|
||||
shader_ds_0->setUniformValue("dt", QVector2D(1. / view.viewport()->width(), 1. / view.viewport()->height()));
|
||||
shader_ds_0->setUniformValue("dt", QVector2D(1. / view.width(), 1. / view.height()));
|
||||
//qDebug() << rp.view_matrix << prev_view;
|
||||
//shader_ds_0->setUniformValue("qgl_ModelViewMatrix", rp.view_matrix);
|
||||
renderObjects(GLObjectBase::Solid, 0, shader_ds_0, true, false, false);
|
||||
@@ -170,7 +170,7 @@ void RendererDeferredShading::renderScene() {
|
||||
shader_ds_1->setUniformValue("mat_viewi", mviewi);
|
||||
shader_ds_1->setUniformValue("mat_viewproji", mviewproji);
|
||||
shader_ds_1->setUniformValue("shadow_on", view.isFeatureEnabled(QGLView::qglShadowsEnabled) ? 1 : 0);
|
||||
shader_ds_1->setUniformValue("dt", QVector2D(1. / view.viewport()->width(), 1. / view.viewport()->height()));
|
||||
shader_ds_1->setUniformValue("dt", QVector2D(1. / view.width(), 1. / view.height()));
|
||||
rp.setUniform(shader_ds_1);
|
||||
fbo_g.bindColorTextures();
|
||||
fbo_g.bindDepthTexture(5);
|
||||
@@ -507,7 +507,7 @@ void RendererDeferredShading::renderScene() {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
shader_fxaa->bind();
|
||||
shader_fxaa->setUniformValue("dt", QVector2D(1. / view.viewport()->width(), 1. / view.viewport()->height()));
|
||||
shader_fxaa->setUniformValue("dt", QVector2D(1. / view.width(), 1. / view.height()));
|
||||
} else {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
@@ -521,9 +521,7 @@ void RendererDeferredShading::renderScene() {
|
||||
|
||||
|
||||
void RendererDeferredShading::init(int width, int height) {
|
||||
#if QT_VERSION >= 0x050600
|
||||
initializeOpenGLFunctions();
|
||||
#endif
|
||||
resize(width, height);
|
||||
}
|
||||
|
||||
@@ -532,15 +530,15 @@ void RendererDeferredShading::resize(int width, int height) {
|
||||
fbo_g.resize(width, height);
|
||||
fbo_out.resize(width, height);
|
||||
fbo_hsmall.resize(width / 16, height / 16);
|
||||
view.setSceneRect(QRect(0, 0, width, height));
|
||||
// view.setSceneRect(QRect(0, 0, width, height));
|
||||
//df->move(-width / 2, -height / 2);
|
||||
}
|
||||
|
||||
|
||||
void RendererDeferredShading::reloadShaders() {
|
||||
for (int i = 0; i < shaders.size(); ++i) {
|
||||
__GLShaderProgram__ * p(*(shaders[i].second));
|
||||
if (!p) p = new __GLShaderProgram__(view.context());
|
||||
QOpenGLShaderProgram * p(*(shaders[i].second));
|
||||
if (!p) p = new QOpenGLShaderProgram(view.context());
|
||||
loadShaders(p, shaders[i].first, "shaders");
|
||||
*(shaders[i].second) = p;
|
||||
}
|
||||
|
||||
@@ -40,15 +40,15 @@ protected:
|
||||
void setupAmbientLight(const QColor & a, bool first_pass);
|
||||
|
||||
private:
|
||||
typedef QPair<QString, __GLShaderProgram__ **> ShaderPair;
|
||||
typedef QPair<QString, QOpenGLShaderProgram **> ShaderPair;
|
||||
|
||||
int cplc, lights_per_pass;
|
||||
double exposure_;
|
||||
GLFramebuffer fbo_g, fbo_out, fbo_hsmall;
|
||||
__GLShaderProgram__ * shader_fxaa, * shader_ds_0, * shader_ds_1, * shader_hdr, * shader_small;
|
||||
__GLShaderProgram__ * shader_bloom_0, * shader_bloom_1, * shader_motion_blur, * shader_fbo_add;
|
||||
__GLShaderProgram__ * shader_shadow, * shader_ssr, * shader_ssr_blur, * shader_ssr_merge;
|
||||
__GLShaderProgram__ * shader_ssao_blur, * shader_ssao_merge, * shader_dof;
|
||||
QOpenGLShaderProgram * shader_fxaa, * shader_ds_0, * shader_ds_1, * shader_hdr, * shader_small;
|
||||
QOpenGLShaderProgram * shader_bloom_0, * shader_bloom_1, * shader_motion_blur, * shader_fbo_add;
|
||||
QOpenGLShaderProgram * shader_shadow, * shader_ssr, * shader_ssr_blur, * shader_ssr_merge;
|
||||
QOpenGLShaderProgram * shader_ssao_blur, * shader_ssao_merge, * shader_dof;
|
||||
GLuint tnoise;
|
||||
QVector<ShaderPair> shaders;
|
||||
|
||||
|
||||
@@ -29,20 +29,18 @@ RendererSimple::RendererSimple(QGLView * view_): GLRendererBase(view_), fbo(2)
|
||||
|
||||
void RendererSimple::reloadShaders() {
|
||||
if (shader_fxaa == 0) {
|
||||
shader_fxaa = new __GLShaderProgram__(view.context());
|
||||
shader_fxaa = new QOpenGLShaderProgram(view.context());
|
||||
loadShaders(shader_fxaa, "FXAA", "shaders");
|
||||
}
|
||||
/*if (shader == 0) {
|
||||
shader = new __GLShaderProgram__(view.context()); /// WARNING
|
||||
shader = new QOpenGLShaderProgram(view.context()); /// WARNING
|
||||
loadShaders(shader, "test", "shaders"); /// WARNING
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
void RendererSimple::resizeFBO(int w, int h) {
|
||||
#if QT_VERSION >= 0x050600
|
||||
initializeOpenGLFunctions();
|
||||
#endif
|
||||
fbo.resize(w, h);
|
||||
fbo_c.resize(w, h); /// WARNING
|
||||
}
|
||||
@@ -120,7 +118,7 @@ void RendererSimple::renderScene() {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
shader_fxaa->bind();
|
||||
shader_fxaa->setUniformValue("dt", QVector2D(1. / view.viewport()->width(), 1. / view.viewport()->height()));
|
||||
shader_fxaa->setUniformValue("dt", QVector2D(1. / view.width(), 1. / view.height()));
|
||||
glDrawQuad();
|
||||
shader_fxaa->release();
|
||||
} else {
|
||||
|
||||
@@ -40,7 +40,7 @@ private:
|
||||
void resizeFBO(int w, int h);
|
||||
|
||||
GLFramebuffer fbo, fbo_c;
|
||||
__GLShaderProgram__ * shader_fxaa, * shader;
|
||||
QOpenGLShaderProgram * shader_fxaa, * shader;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user