From 7ad19d72c501761570f13263884b05fceb8c4cd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Tue, 3 Oct 2017 12:20:32 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/libs@286 a8b55f48-bf90-11e4-a774-851b48703e85 --- qglview/CMakeLists.txt | 34 +-- qglview/glframebuffer.cpp | 6 + qglview/glframebuffer.h | 3 + qglview/glmaterial.cpp | 11 +- qglview/glmaterial.h | 2 +- qglview/globject.cpp | 4 +- qglview/globject.h | 6 +- qglview/globject_editor.cpp | 124 +++++----- qglview/globject_editor.h | 8 +- qglview/glparticles_system.cpp | 5 +- qglview/glparticles_system.h | 2 +- qglview/glprimitives.cpp | 4 +- qglview/glprimitives.h | 4 +- qglview/glrendererbase.cpp | 18 +- qglview/glrendererbase.h | 9 +- qglview/glshaders.cpp | 27 +- qglview/glshaders.h | 14 +- qglview/gltypes.cpp | 40 ++- qglview/gltypes.h | 69 ++++-- qglview/glvbo.cpp | 5 +- qglview/glvbo.h | 5 +- qglview/loader_3ds.h | 1 - qglview/loader_dae.h | 1 - qglview/loader_obj.h | 1 - qglview/main.cpp | 112 --------- qglview/make_install.sh | 5 - qglview/propertyeditor.cpp | 2 +- qglview/qglview.cpp | 36 ++- qglview/qglview.h | 17 +- .../{rope_system.h => qglview_test/main.cpp} | 40 ++- qglview/{ => qglview_test}/qglview_window.cpp | 2 +- qglview/{ => qglview_test}/qglview_window.h | 2 - qglview/{ => qglview_test}/qglview_window.ui | 0 qglview/renderer_deferred_shading.cpp | 9 +- qglview/renderer_deferred_shading.h | 10 +- qglview/renderer_simple.cpp | 7 +- qglview/renderer_simple.h | 2 +- qglview/rope_system.cpp | 66 ----- qglview/water_system.cpp | 230 ------------------ qglview/water_system.h | 89 ------- 40 files changed, 320 insertions(+), 712 deletions(-) delete mode 100644 qglview/main.cpp delete mode 100644 qglview/make_install.sh rename qglview/{rope_system.h => qglview_test/main.cpp} (60%) rename qglview/{ => qglview_test}/qglview_window.cpp (99%) rename qglview/{ => qglview_test}/qglview_window.h (99%) rename qglview/{ => qglview_test}/qglview_window.ui (100%) delete mode 100644 qglview/rope_system.cpp delete mode 100644 qglview/water_system.cpp delete mode 100644 qglview/water_system.h diff --git a/qglview/CMakeLists.txt b/qglview/CMakeLists.txt index 3bc9b83..1041028 100644 --- a/qglview/CMakeLists.txt +++ b/qglview/CMakeLists.txt @@ -17,8 +17,9 @@ endif() find_package(QAD REQUIRED) find_package(OpenGL REQUIRED) include_directories(${QAD_INCLUDES}) -file(GLOB SRC "*.h" "*.cpp" "*.ui" "*.qrc" "lang/*.ts") -find_qt(Qt4 Core Gui OpenGL Xml) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3") +find_qt(${QtVersions} Core Gui OpenGL Xml) +qt_sources(SRC) qt_wrap(${SRC} HDRS out_HDR CPPS out_CPP QMS out_QM) qt_add_library(${PROJECT_NAME} SHARED out_CPP) qt_target_link_libraries(${PROJECT_NAME} qad_utils qad_widgets ${OPENGL_LIBRARIES}) @@ -28,29 +29,32 @@ if (LIBPROJECT) else() if (LIB) if (WIN32) - set(CMAKE_INSTALL_PREFIX ${MINGW_DIR}) - install(FILES ${H} DESTINATION ${MINGW_INCLUDE}/qad) - install(TARGETS ${PROJECT_NAME} DESTINATION ${MINGW_LIB}) - install(TARGETS ${PROJECT_NAME} DESTINATION ${MINGW_BIN}) - get_filename_component(QTDIR ${QT_QMAKE_EXECUTABLE} PATH) - install(TARGETS ${PROJECT_NAME} DESTINATION ${QTDIR}) + qt_install(FILES ${H} DESTINATION ${MINGW_INCLUDE}/qad) + qt_install(TARGETS ${PROJECT_NAME} DESTINATION ${MINGW_LIB}) + qt_install(TARGETS ${PROJECT_NAME} DESTINATION ${MINGW_BIN}) + qt_install(TARGETS ${PROJECT_NAME} DESTINATION QtBin) else() if(APPLE) set(CMAKE_INSTALL_PREFIX /usr/local) else() set(CMAKE_INSTALL_PREFIX /usr) endif() - install(FILES ${H} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/qad) - install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) + qt_install(FILES ${H} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/qad) + qt_install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) endif() message(STATUS "Install ${PROJECT_NAME} to system \"${CMAKE_INSTALL_PREFIX}\"") else() - install(TARGETS ${PROJECT_NAME} DESTINATION bin) + qt_install(TARGETS ${PROJECT_NAME} DESTINATION bin) message(STATUS "Install ${PROJECT_NAME} to local \"bin\"") endif() endif() +foreach(_v ${_QT_VERSIONS_}) + set(MULTILIB_qglview_SUFFIX_Qt${_v} ${_v}) + set(MULTILIB_qglview_SUFFIX_Qt${_v} ${_v} PARENT_SCOPE) +endforeach() +list(APPEND QT_MULTILIB_LIST qglview) -qt4_wrap_cpp(CMOCS_TEST "qglview_window.h" OPTIONS -nw) -qt4_wrap_ui(CUIS_TEST "qglview_window.ui") -qt_add_executable(qglview_test "main.cpp" "qglview_window.cpp" ${CMOCS_TEST} ${CUIS_TEST} ${CRES}) -qt_target_link_libraries(qglview_test ${PROJECT_NAME} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY}) +qt_sources(test_SRC DIR "qglview_test") +qt_wrap(${test_SRC} CPPS test_CPP) +qt_add_executable(qglview_test test_CPP) +qt_target_link_libraries(qglview_test ${PROJECT_NAME}) diff --git a/qglview/glframebuffer.cpp b/qglview/glframebuffer.cpp index ba7bb74..ab6fc22 100644 --- a/qglview/glframebuffer.cpp +++ b/qglview/glframebuffer.cpp @@ -42,6 +42,9 @@ 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); @@ -88,6 +91,9 @@ 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(); diff --git a/qglview/glframebuffer.h b/qglview/glframebuffer.h index fa5a56c..3b9d0d0 100644 --- a/qglview/glframebuffer.h +++ b/qglview/glframebuffer.h @@ -22,6 +22,9 @@ #include "gltypes.h" class GLFramebuffer +#if QT_VERSION >= 0x050600 + : protected QOpenGLExtraFunctions +#endif { public: GLFramebuffer(int colorAttachments = 1, bool withDepth = true, GLenum colorFormat = GL_RGBA8, GLenum target = GL_TEXTURE_2D); diff --git a/qglview/glmaterial.cpp b/qglview/glmaterial.cpp index 367265e..891e999 100644 --- a/qglview/glmaterial.cpp +++ b/qglview/glmaterial.cpp @@ -93,7 +93,11 @@ GLuint GLTextureManagerBase::loadTexture(const QString & path, bool ownership, b QImage image(p); if (bump) convertToNormal(image); //qDebug() << p << image.width() << image.height() << image.format() << bump; - tid = currentQGLView->bindTexture(image, GL_TEXTURE_2D/*, GL_RGBA, QGLContext::MipmapBindOption*/); + ///tid = currentQGLView->bindTexture(image, GL_TEXTURE_2D/*, GL_RGBA, __GLContext__::MipmapBindOption*/); + //GLuint tid = 0; + GLuint _tid = tid; + createGLTexture(_tid, image);///currentQGLView->bindTexture(image, GL_TEXTURE_2D); + tid = _tid; if (tid == 0) { qDebug() << "[TextureManager] Can`t load" << p; return tid; @@ -108,7 +112,8 @@ GLuint GLTextureManagerBase::loadTexture(const QImage & im, bool ownership, bool if (im.isNull()) return 0; QImage image(im); if (bump) convertToNormal(image); - GLuint tid = currentQGLView->bindTexture(image, GL_TEXTURE_2D); + GLuint tid = 0; + createGLTexture(tid, im);///currentQGLView->bindTexture(image, GL_TEXTURE_2D); if (tid == 0) { qDebug() << "[TextureManager] Can`t load image"; return tid; @@ -190,7 +195,7 @@ Material::Material(): map_reflection(512) { } -void Material::apply(QGLShaderProgram * prog) { +void Material::apply(__GLShaderProgram__ * prog) { if (prog) { setUniformMaterial(prog, *this); } else { diff --git a/qglview/glmaterial.h b/qglview/glmaterial.h index cf2a119..0897b81 100644 --- a/qglview/glmaterial.h +++ b/qglview/glmaterial.h @@ -104,7 +104,7 @@ struct Map { struct Material { Material(); - void apply(QGLShaderProgram * prog); + void apply(__GLShaderProgram__ * prog); void loadTextures(GLTextureManagerBase * tm = 0); QString name; QColor color_diffuse; diff --git a/qglview/globject.cpp b/qglview/globject.cpp index f34f1cc..6e9a97c 100644 --- a/qglview/globject.cpp +++ b/qglview/globject.cpp @@ -79,7 +79,7 @@ GLObjectBase * GLObjectBase::clone(bool withChildren) { return o; } -void GLObjectBase::draw(QGLShaderProgram * prog, bool simplest) { +void GLObjectBase::draw(__GLShaderProgram__ * prog, bool simplest) { vbo.draw(geom_prim, prog, simplest); /*if (!d_vertices.isEmpty()) { glBindBuffer(GL_ARRAY_BUFFER, 0); @@ -272,7 +272,7 @@ GLObjectBase * Light::clone(bool withChildren) { } -void Light::draw(QGLShaderProgram * prog, bool simplest) { +void Light::draw(__GLShaderProgram__ * prog, bool simplest) { bool l = glIsEnabled(GL_LIGHTING); glDisable(GL_LIGHTING); glPointSize(8.); diff --git a/qglview/globject.h b/qglview/globject.h index 7693239..0600321 100644 --- a/qglview/globject.h +++ b/qglview/globject.h @@ -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(QGLShaderProgram * prog, bool simplest = false); + virtual void draw(__GLShaderProgram__ * prog, bool simplest = false); virtual void update() {} bool isInit() const {return is_init;} bool isTexturesLoaded() const {return is_tex_loaded;} @@ -185,7 +185,7 @@ public: protected: void addChildren(QList & 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 deleteTextures() {foreach (GLuint i, textures) currentQGLView->deleteTexture(i); textures.clear();} + //void deleteTextures() {foreach (GLuint i, textures) currentQGLView->deleteTexture(i); textures.clear();} void calculateBoundingBox(); void buildTransform(); void initInternal() {init(); loadTextures(); foreach (GLObjectBase * i, children_) i->initInternal();} @@ -228,7 +228,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(QGLShaderProgram * prog, bool simplest = false); + virtual void draw(__GLShaderProgram__ * prog, bool simplest = false); QVector3D direction, dir0, dir1; GLdouble angle_start; diff --git a/qglview/globject_editor.cpp b/qglview/globject_editor.cpp index 857fa83..a1d364c 100644 --- a/qglview/globject_editor.cpp +++ b/qglview/globject_editor.cpp @@ -17,14 +17,16 @@ */ #include "globject_editor.h" +#include "ui_globject_editor.h" GLObjectEditor::GLObjectEditor(QWidget * parent): QWidget(parent) { - setupUi(this); + ui = new Ui::GLObjectEditor(); + ui->setupUi(this); active = true; object = 0; rmodes << GLObjectBase::View << GLObjectBase::Point << GLObjectBase::Line << GLObjectBase::Fill; - groupLight->setEnabled(false); + ui->groupLight->setEnabled(false); } @@ -33,7 +35,7 @@ void GLObjectEditor::changeEvent(QEvent * e) { QWidget::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: - retranslateUi(this); + ui->retranslateUi(this); break; default: break; @@ -44,41 +46,41 @@ void GLObjectEditor::changeEvent(QEvent * e) { void GLObjectEditor::setObject(GLObjectBase * o) { object = o; if (object == 0) { - groupLight->setEnabled(false); + ui->groupLight->setEnabled(false); return; } active = false; - spinPosX->setValue(object->posX()); - spinPosY->setValue(object->posY()); - spinPosZ->setValue(object->posZ()); - spinRotationX->setValue(object->rotationX()); - spinRotationY->setValue(object->rotationY()); - spinRotationZ->setValue(object->rotationZ()); - spinScaleX->setValue(object->scaleX()); - spinScaleY->setValue(object->scaleY()); - spinScaleZ->setValue(object->scaleZ()); - spinLineWidth->setValue(object->lineWidth()); - checkVisible->setChecked(object->isVisible()); - checkAcceptLight->setChecked(object->isAcceptLight()); - checkAcceptFog->setChecked(object->isAcceptFog()); - checkCastShadows->setChecked(object->isCastShadows()); - checkReceiveShadows->setChecked(object->isReceiveShadows()); - comboRenderMode->setCurrentIndex(rmodes.indexOf(object->renderMode())); - groupLight->setEnabled(object->type() == GLObjectBase::glLight); + ui->spinPosX->setValue(object->posX()); + ui->spinPosY->setValue(object->posY()); + ui->spinPosZ->setValue(object->posZ()); + ui->spinRotationX->setValue(object->rotationX()); + ui->spinRotationY->setValue(object->rotationY()); + ui->spinRotationZ->setValue(object->rotationZ()); + ui->spinScaleX->setValue(object->scaleX()); + ui->spinScaleY->setValue(object->scaleY()); + ui->spinScaleZ->setValue(object->scaleZ()); + ui->spinLineWidth->setValue(object->lineWidth()); + ui->checkVisible->setChecked(object->isVisible()); + ui->checkAcceptLight->setChecked(object->isAcceptLight()); + ui->checkAcceptFog->setChecked(object->isAcceptFog()); + ui->checkCastShadows->setChecked(object->isCastShadows()); + ui->checkReceiveShadows->setChecked(object->isReceiveShadows()); + ui->comboRenderMode->setCurrentIndex(rmodes.indexOf(object->renderMode())); + ui->groupLight->setEnabled(object->type() == GLObjectBase::glLight); if (object->type() == GLObjectBase::glLight) { Light * l = globject_cast(object); //bool is_dir = l->light_type == Light::Directional, is_cone = l->light_type == Light::Cone; - buttonLightColor->setColor(l->color()); - comboLightType->setCurrentIndex(l->light_type); - spinLightIntensity->setValue(l->intensity); - spinLightDecayConst->setValue(l->decay_const); - spinLightDecayLinear->setValue(l->decay_linear); - spinLightDecayQuadratic->setValue(l->decay_quadratic); - spinLightAngleStart->setValue(l->angle_start); - spinLightAngleEnd->setValue(l->angle_end); - spinLightDirectionX->setValue(l->direction.x()); - spinLightDirectionY->setValue(l->direction.y()); - spinLightDirectionZ->setValue(l->direction.z()); + ui->buttonLightColor->setColor(l->color()); + ui->comboLightType->setCurrentIndex(l->light_type); + ui->spinLightIntensity->setValue(l->intensity); + ui->spinLightDecayConst->setValue(l->decay_const); + ui->spinLightDecayLinear->setValue(l->decay_linear); + ui->spinLightDecayQuadratic->setValue(l->decay_quadratic); + ui->spinLightAngleStart->setValue(l->angle_start); + ui->spinLightAngleEnd->setValue(l->angle_end); + ui->spinLightDirectionX->setValue(l->direction.x()); + ui->spinLightDirectionY->setValue(l->direction.y()); + ui->spinLightDirectionZ->setValue(l->direction.z()); } active = true; } @@ -86,46 +88,46 @@ void GLObjectEditor::setObject(GLObjectBase * o) { void GLObjectEditor::objectChanged() { if (!active || object == 0) return; - object->setPosX(spinPosX->value()); - object->setPosY(spinPosY->value()); - object->setPosZ(spinPosZ->value()); - object->setRotationX(spinRotationX->value()); - object->setRotationY(spinRotationY->value()); - object->setRotationZ(spinRotationZ->value()); - object->setScaleX(spinScaleX->value()); - object->setScaleY(spinScaleY->value()); - object->setScaleZ(spinScaleZ->value()); - object->setLineWidth(spinLineWidth->value()); - object->setVisible(checkVisible->isChecked()); - object->setAcceptLight(checkAcceptLight->isChecked()); - object->setAcceptFog(checkAcceptFog->isChecked()); - object->setCastShadows(checkCastShadows->isChecked()); - object->setReceiveShadows(checkReceiveShadows->isChecked()); - object->setRenderMode((GLObjectBase::RenderMode)rmodes[comboRenderMode->currentIndex()]); + object->setPosX(ui->spinPosX->value()); + object->setPosY(ui->spinPosY->value()); + object->setPosZ(ui->spinPosZ->value()); + object->setRotationX(ui->spinRotationX->value()); + object->setRotationY(ui->spinRotationY->value()); + object->setRotationZ(ui->spinRotationZ->value()); + object->setScaleX(ui->spinScaleX->value()); + object->setScaleY(ui->spinScaleY->value()); + object->setScaleZ(ui->spinScaleZ->value()); + object->setLineWidth(ui->spinLineWidth->value()); + object->setVisible(ui->checkVisible->isChecked()); + object->setAcceptLight(ui->checkAcceptLight->isChecked()); + object->setAcceptFog(ui->checkAcceptFog->isChecked()); + object->setCastShadows(ui->checkCastShadows->isChecked()); + object->setReceiveShadows(ui->checkReceiveShadows->isChecked()); + object->setRenderMode((GLObjectBase::RenderMode)rmodes[ui->comboRenderMode->currentIndex()]); if (object->type() == GLObjectBase::glLight) { Light * l = globject_cast(object); //bool is_dir = l->light_type == Light::Directional, is_cone = l->light_type == Light::Cone; - l->setColor(buttonLightColor->color()); - l->light_type = (Light::Type)comboLightType->currentIndex(); - l->intensity = spinLightIntensity->value(); - l->decay_const = spinLightDecayConst->value(); - l->decay_linear = spinLightDecayLinear->value(); - l->decay_quadratic = spinLightDecayQuadratic->value(); - l->angle_start = spinLightAngleStart->value(); - l->angle_end = spinLightAngleEnd->value(); - l->direction = QVector3D(spinLightDirectionX->value(), spinLightDirectionY->value(), spinLightDirectionZ->value()).normalized(); + l->setColor(ui->buttonLightColor->color()); + l->light_type = (Light::Type)ui->comboLightType->currentIndex(); + l->intensity = ui->spinLightIntensity->value(); + l->decay_const = ui->spinLightDecayConst->value(); + l->decay_linear = ui->spinLightDecayLinear->value(); + l->decay_quadratic = ui->spinLightDecayQuadratic->value(); + l->angle_start = ui->spinLightAngleStart->value(); + l->angle_end = ui->spinLightAngleEnd->value(); + l->direction = QVector3D(ui->spinLightDirectionX->value(), ui->spinLightDirectionY->value(), ui->spinLightDirectionZ->value()).normalized(); } emit changed(); } void GLObjectEditor::on_spinLightAngleStart_valueChanged(double v) { - if (spinLightAngleEnd->value() < v) - spinLightAngleEnd->setValue(v); + if (ui->spinLightAngleEnd->value() < v) + ui->spinLightAngleEnd->setValue(v); } void GLObjectEditor::on_spinLightAngleEnd_valueChanged(double v) { - if (spinLightAngleStart->value() > v) - spinLightAngleStart->setValue(v); + if (ui->spinLightAngleStart->value() > v) + ui->spinLightAngleStart->setValue(v); } diff --git a/qglview/globject_editor.h b/qglview/globject_editor.h index 3655b24..71345cd 100644 --- a/qglview/globject_editor.h +++ b/qglview/globject_editor.h @@ -19,10 +19,13 @@ #ifndef GLOBJECT_EDITOR_H #define GLOBJECT_EDITOR_H -#include "ui_globject_editor.h" #include "globject.h" -class GLObjectEditor: public QWidget, private Ui::GLObjectEditor +namespace Ui { + class GLObjectEditor; +}; + +class GLObjectEditor: public QWidget { Q_OBJECT public: @@ -33,6 +36,7 @@ public: protected: void changeEvent(QEvent * e); + Ui::GLObjectEditor * ui; bool active; GLObjectBase * object; QList rmodes; diff --git a/qglview/glparticles_system.cpp b/qglview/glparticles_system.cpp index 181e495..02f31e9 100644 --- a/qglview/glparticles_system.cpp +++ b/qglview/glparticles_system.cpp @@ -108,9 +108,10 @@ void GLParticlesSystem::update() { } -void GLParticlesSystem::draw(QGLShaderProgram * prog, bool) { +void GLParticlesSystem::draw(__GLShaderProgram__ * prog, bool) { if (particles.isEmpty()) return; if (view_ == 0) return; + QGLCI pass_ = GLObjectBase::Transparent; Camera & camera(view_->camera()); QVector3D apos = camera.pos(), dir = camera.direction(); @@ -186,7 +187,7 @@ void GLParticlesSystem::draw(QGLShaderProgram * prog, bool) { glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_COLOR_ARRAY); - glBindBuffer(GL_ARRAY_BUFFER, 0); + QGLC glBindBuffer(GL_ARRAY_BUFFER, 0); //glNormal3f(vn.x(), vn.y(), vn.z()); glNormal3f(0., 0., 1.); glDepthMask(false); diff --git a/qglview/glparticles_system.h b/qglview/glparticles_system.h index 9d4dfb0..b935b7d 100644 --- a/qglview/glparticles_system.h +++ b/qglview/glparticles_system.h @@ -69,7 +69,7 @@ public: }; void update(); - void draw(QGLShaderProgram * prog, bool); + void draw(__GLShaderProgram__ * prog, bool); float birthRate() const {return birthRate_;} float lifeDuration() const {return lifeDuration_;} diff --git a/qglview/glprimitives.cpp b/qglview/glprimitives.cpp index 056cdb2..c9ac6af 100644 --- a/qglview/glprimitives.cpp +++ b/qglview/glprimitives.cpp @@ -19,7 +19,7 @@ #include "glprimitives.h" -void GLPrimitivePoint::draw(QGLShaderProgram * prog, bool simplest) { +void GLPrimitivePoint::draw(__GLShaderProgram__ * 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(QGLShaderProgram * prog, bool simplest) { -void GLPrimitiveLine::draw(QGLShaderProgram * prog, bool simplest) { +void GLPrimitiveLine::draw(__GLShaderProgram__ * 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()); diff --git a/qglview/glprimitives.h b/qglview/glprimitives.h index c1a9d2d..575b783 100644 --- a/qglview/glprimitives.h +++ b/qglview/glprimitives.h @@ -26,7 +26,7 @@ class GLPrimitivePoint: public GLObjectBase { public: GLPrimitivePoint(double size = 1., QVector3D pos = QVector3D()) {sz = 8.;} - virtual void draw(QGLShaderProgram * prog, bool simplest = false); + virtual void draw(__GLShaderProgram__ * 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(QGLShaderProgram * prog, bool simplest = false); + virtual void draw(__GLShaderProgram__ * prog, bool simplest = false); QVector3D point0() const {return p0;} QVector3D point1() const {return p1;} void setPoint0(const QVector3D & p) {p0 = p;} diff --git a/qglview/glrendererbase.cpp b/qglview/glrendererbase.cpp index b78dafc..2b1ec35 100644 --- a/qglview/glrendererbase.cpp +++ b/qglview/glrendererbase.cpp @@ -77,7 +77,7 @@ void GLRendererBase::setupAmbientLight(const QColor & a, bool first_pass) { void GLRendererBase::setupShadersLights(int lights_count) { - /*foreach (QGLShaderProgram * i, view.shaders_ppl) { + /*foreach (__GLShaderProgram__ * 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((QGLShaderProgram*)rpl.shaders); + mat.apply((__GLShaderProgram__*)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_); @@ -211,26 +211,26 @@ void GLRendererBase::renderSingleObject(GLObjectBase & o, RenderingParameters & glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, bc); glGetFloatv(GL_MODELVIEW_MATRIX, gm); glMatrixMode(GL_TEXTURE); - glLoadTransposeMatrixf(gm); + ///glLoadTransposeMatrixf(gm); glScalef(-1., -1., -1.); glMatrixMode(GL_MODELVIEW); glActiveTextureChannel(0); } if (rpl.shaders) { //qDebug() << o.name() << curview << curview.determinant(); - setUniformMatrices((QGLShaderProgram*)rpl.shaders, rpl.proj_matrix, curview, rpl.prev_proj_matrix, prevview); + setUniformMatrices((__GLShaderProgram__*)rpl.shaders, rpl.proj_matrix, curview, rpl.prev_proj_matrix, prevview); } else { glMatrixMode(GL_MODELVIEW); setGLMatrix(curview); } - o.draw((QGLShaderProgram*)rpl.shaders); + o.draw((__GLShaderProgram__*)rpl.shaders); } foreach (GLObjectBase * i, o.children_) renderSingleObject(*i, rpl); } -void GLRendererBase::renderShadow(Light * l, QGLShaderProgram * prog, QMatrix4x4 mat) { +void GLRendererBase::renderShadow(Light * l, __GLShaderProgram__ * 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((QGLShaderProgram*)rpl.shaders, rpl.proj_matrix, rpl.view_matrix * rpl.cam_offset_matrix * o.itransform_); + setUniformMatrices((__GLShaderProgram__*)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((QGLShaderProgram*)rpl.shaders, true); + o.draw((__GLShaderProgram__*)rpl.shaders, true); foreach (GLObjectBase * i, o.children_) renderSingleShadow(*i, rpl); } @@ -297,7 +297,7 @@ void GLRendererBase::RenderingParameters::prepare() { } -void GLRendererBase::RenderingParameters::setUniform(QGLShaderProgram * prog) { +void GLRendererBase::RenderingParameters::setUniform(__GLShaderProgram__ * prog) { if (!prog) return; prog->setUniformValue("qgl_ModelViewMatrix", view_matrix); prog->setUniformValue("qgl_ProjectionMatrix", proj_matrix); diff --git a/qglview/glrendererbase.h b/qglview/glrendererbase.h index f6b79c8..859873d 100644 --- a/qglview/glrendererbase.h +++ b/qglview/glrendererbase.h @@ -23,6 +23,9 @@ #include "glshaders.h" class GLRendererBase: public QObject +#if QT_VERSION >= 0x050600 + , protected QOpenGLExtraFunctions +#endif { friend class QGLView; Q_OBJECT @@ -34,7 +37,7 @@ public: protected: struct RenderingParameters { void prepare(); - void setUniform(QGLShaderProgram * prog); + void setUniform(__GLShaderProgram__ * prog); int pass; int light_pass; bool light; @@ -49,7 +52,7 @@ protected: QMatrix4x4 viewproj_matrix, viewproj_matrix_i; QMatrix3x3 normal_matrix; QMatrix4x4 cam_offset_matrix; - QGLShaderProgram * cur_shader; + __GLShaderProgram__ * cur_shader; }; virtual void setupLight(const Light & l, int inpass_index, int gl_index); @@ -65,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, QGLShaderProgram * prog = 0, QMatrix4x4 mat = QMatrix4x4()); + void renderShadow(Light * l, __GLShaderProgram__ * prog = 0, QMatrix4x4 mat = QMatrix4x4()); void renderSingleShadow(GLObjectBase & o, RenderingParameters & rpl); RenderingParameters rp; diff --git a/qglview/glshaders.cpp b/qglview/glshaders.cpp index 0167cb9..8d52c4b 100644 --- a/qglview/glshaders.cpp +++ b/qglview/glshaders.cpp @@ -96,7 +96,7 @@ const char qgl_structs[] = "uniform QGLMaterial qgl_Material;\n"; -QString loadShaderFile(QGLShaderProgram * prog, QGLShader::ShaderType type, const QString & file) { +QString loadShaderFile(__GLShaderProgram__ * prog, __GLShader__::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(QGLShaderProgram * prog, QGLShader::ShaderType type, cons if (version.toInt() >= 150) { int ip = all.indexOf("\n", i); if (ip < 0) return all; - if (type == QGLShader::Vertex) { + if (type == __GLShader__::Vertex) { all.insert(ip + 1, qgl_vertex_head); } - if (type == QGLShader::Fragment) { + if (type == __GLShader__::Fragment) { all.insert(ip + 1, qgl_fragment_head); } all.insert(ip + 1, qgl_structs); @@ -120,7 +120,7 @@ QString loadShaderFile(QGLShaderProgram * prog, QGLShader::ShaderType type, cons } -bool loadShaders(QGLShaderProgram * prog, const QString & name, const QString & dir) { +bool loadShaders(__GLShaderProgram__ * prog, const QString & name, const QString & dir) { prog->removeAllShaders(); QDir d(dir); QFileInfoList sl; @@ -129,18 +129,18 @@ bool loadShaders(QGLShaderProgram * prog, const QString & name, const QString & 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, QGLShader::Geometry, i.absoluteFilePath()); + loadShaderFile(prog, __GLShader__::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, QGLShader::Vertex, i.absoluteFilePath()); + loadShaderFile(prog, __GLShader__::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, QGLShader::Fragment, i.absoluteFilePath()); + loadShaderFile(prog, __GLShader__::Fragment, i.absoluteFilePath()); } if (!prog->link()) { qDebug() << "[QGLView] Shader \"" + name + "\" link error: " + prog->log(); @@ -150,7 +150,7 @@ bool loadShaders(QGLShaderProgram * prog, const QString & name, const QString & } -void setUniformMatrices(QGLShaderProgram * prog, QMatrix4x4 proj, QMatrix4x4 view, QMatrix4x4 prevproj, QMatrix4x4 prevview) { +void setUniformMatrices(__GLShaderProgram__ * prog, QMatrix4x4 proj, QMatrix4x4 view, QMatrix4x4 prevproj, QMatrix4x4 prevview) { QMatrix4x4 mvpm = proj * view; QMatrix4x4 pmvpm = prevproj * prevview; QMatrix3x3 nm = view.normalMatrix(); @@ -167,20 +167,21 @@ void setUniformMatrices(QGLShaderProgram * prog, QMatrix4x4 proj, QMatrix4x4 vie } -void setUniformMap(QGLShaderProgram * prog, QString map_name, const Map & map, int channel, int def_channel) { +void setUniformMap(__GLShaderProgram__ * prog, QString map_name, const Map & map, int channel, int def_channel) { prog->setUniformValue(("qgl_Material." + map_name + ".offset").toLatin1().constData(), map.color_offset); prog->setUniformValue(("qgl_Material." + map_name + ".amount").toLatin1().constData(), map.color_amount); prog->setUniformValue(("qgl_Material." + map_name + ".map").toLatin1().constData(), map.bitmap_id > 0 ? channel : def_channel); } -void setUniformMaterial(QGLShaderProgram * prog, const Material & mat) { +void setUniformMaterial(__GLShaderProgram__ * prog, const Material & mat) { + QGLCI GLfloat mat_diffuse[4] = {1.0f, 1.0f, 1.0f, 1.0f}; mat_diffuse[0] = mat.color_diffuse.redF(); mat_diffuse[1] = mat.color_diffuse.greenF(); mat_diffuse[2] = mat.color_diffuse.blueF(); mat_diffuse[3] = mat.color_diffuse.alphaF() * (1.f - mat.transparency); - glVertexAttrib4f(prog->attributeLocation("qgl_Color"), mat_diffuse[0], mat_diffuse[1], mat_diffuse[2], mat_diffuse[3]); + QGLC glVertexAttrib4f(prog->attributeLocation("qgl_Color"), mat_diffuse[0], mat_diffuse[1], mat_diffuse[2], mat_diffuse[3]); prog->setUniformValue("qgl_Material.transparency", mat.transparency); prog->setUniformValue("qgl_Material.reflectivity", mat.reflectivity); prog->setUniformValue("qgl_Material.iof", mat.iof); @@ -198,7 +199,7 @@ void setUniformMaterial(QGLShaderProgram * prog, const Material & mat) { } -void setUniformLights(QGLShaderProgram * prog, const QVector & lights, const QMatrix4x4 & mat, int shadow_start) { +void setUniformLights(__GLShaderProgram__ * prog, const QVector & 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); } @@ -215,7 +216,7 @@ void setUniformLights(QGLShaderProgram * prog, const QVector & lights, c " sampler2DShadow shadow;\n" " mat4 shadowMatrix;\n" */ -void setUniformLight(QGLShaderProgram * prog, Light * light, QString ulightn, const QMatrix4x4 & mat, int shadow) { +void setUniformLight(__GLShaderProgram__ * prog, Light * light, QString ulightn, const QMatrix4x4 & mat, int shadow) { QMatrix4x4 m = mat * light->worldTransform(); QVector4D pos(0, 0, 0, 1.), dir(light->direction);//, dir0(light->dir0), dir1(light->dir1); pos = m * pos; diff --git a/qglview/glshaders.h b/qglview/glshaders.h index 4e7069c..02e04f5 100644 --- a/qglview/glshaders.h +++ b/qglview/glshaders.h @@ -25,12 +25,12 @@ class Map; class Material; class Light; -QString loadShaderFile(QGLShaderProgram * prog, QGLShader::ShaderType type, const QString & file); -bool loadShaders(QGLShaderProgram * prog, const QString & name, const QString & dir = QString()); -void setUniformMatrices(QGLShaderProgram * prog, QMatrix4x4 proj, QMatrix4x4 view, QMatrix4x4 prevproj = QMatrix4x4(), QMatrix4x4 prevview = QMatrix4x4()); -void setUniformMap(QGLShaderProgram * prog, const Map & map, int channel, int def_channel); -void setUniformMaterial(QGLShaderProgram * prog, const Material & mat); -void setUniformLights(QGLShaderProgram * prog, const QVector & lights, const QMatrix4x4 & mat, int shadow_start); -void setUniformLight(QGLShaderProgram * prog, Light * light, QString ulightn, const QMatrix4x4 & mat = QMatrix4x4(), int shadow = 0); +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 & lights, const QMatrix4x4 & mat, int shadow_start); +void setUniformLight(__GLShaderProgram__ * prog, Light * light, QString ulightn, const QMatrix4x4 & mat = QMatrix4x4(), int shadow = 0); #endif // GLSHADERS_H diff --git a/qglview/gltypes.cpp b/qglview/gltypes.cpp index b2d0ad6..825316c 100644 --- a/qglview/gltypes.cpp +++ b/qglview/gltypes.cpp @@ -19,7 +19,7 @@ #include "glcamera.h" #include "qglview.h" -QGLWidget * currentQGLView; +__GLWidget__ * currentQGLView; QMutex globMutex; @@ -51,7 +51,8 @@ QString findFile(const QString & file, const QStringList & pathes) { } -void glDrawQuad(QGLShaderProgram * prog, QVector4D * corner_dirs, GLfloat x, GLfloat y, GLfloat w, GLfloat h) { +void glDrawQuad(__GLShaderProgram__ * prog, QVector4D * corner_dirs, GLfloat x, GLfloat y, GLfloat w, GLfloat h) { + QGLCI glResetAllTransforms(); glSetPolygonMode(GL_FILL); int loc = prog ? prog->attributeLocation("qgl_Color") : 0, @@ -59,11 +60,11 @@ void glDrawQuad(QGLShaderProgram * prog, QVector4D * corner_dirs, GLfloat x, GLf loct = prog ? prog->attributeLocation("qgl_Texture") : 0, locc = prog ? prog->attributeLocation("view_corner") : 0; glBegin(GL_QUADS); - if (prog) glVertexAttrib3f(loc, 1.f, 1.f, 1.f); glColor3f(1.f, 1.f, 1.f); - if (prog) {if (corner_dirs) prog->setAttributeValue(locc, corner_dirs[0]); glVertexAttrib2f(loct, 0.f, 0.f); glVertexAttrib2f(locv, x, y);} glTexCoord2f(0.f, 0.f); glVertex2f(x, y); - if (prog) {if (corner_dirs) prog->setAttributeValue(locc, corner_dirs[1]); glVertexAttrib2f(loct, 1.f, 0.f); glVertexAttrib2f(locv, x + w, y);} glTexCoord2f(1.f, 0.f); glVertex2f(x + w, y); - if (prog) {if (corner_dirs) prog->setAttributeValue(locc, corner_dirs[2]); glVertexAttrib2f(loct, 1.f, 1.f); glVertexAttrib2f(locv, x + w, y + h);} glTexCoord2f(1.f, 1.f); glVertex2f(x + w, y + h); - if (prog) {if (corner_dirs) prog->setAttributeValue(locc, corner_dirs[3]); glVertexAttrib2f(loct, 0.f, 1.f); glVertexAttrib2f(locv, x, y + h);} glTexCoord2f(0.f, 1.f); glVertex2f(x, y + h); + if (prog) {QGLC glVertexAttrib3f(loc, 1.f, 1.f, 1.f);} glColor3f(1.f, 1.f, 1.f); + if (prog) {if (corner_dirs) prog->setAttributeValue(locc, corner_dirs[0]); QGLC glVertexAttrib2f(loct, 0.f, 0.f); QGLC glVertexAttrib2f(locv, x, y);} glTexCoord2f(0.f, 0.f); glVertex2f(x, y); + if (prog) {if (corner_dirs) prog->setAttributeValue(locc, corner_dirs[1]); QGLC glVertexAttrib2f(loct, 1.f, 0.f); QGLC glVertexAttrib2f(locv, x + w, y);} glTexCoord2f(1.f, 0.f); glVertex2f(x + w, y); + if (prog) {if (corner_dirs) prog->setAttributeValue(locc, corner_dirs[2]); QGLC glVertexAttrib2f(loct, 1.f, 1.f); QGLC glVertexAttrib2f(locv, x + w, y + h);} glTexCoord2f(1.f, 1.f); glVertex2f(x + w, y + h); + if (prog) {if (corner_dirs) prog->setAttributeValue(locc, corner_dirs[3]); QGLC glVertexAttrib2f(loct, 0.f, 1.f); QGLC glVertexAttrib2f(locv, x, y + h);} glTexCoord2f(0.f, 1.f); glVertex2f(x, y + h); glEnd(); } @@ -71,7 +72,12 @@ void glDrawQuad(QGLShaderProgram * prog, QVector4D * corner_dirs, GLfloat x, GLf QMatrix4x4 getGLMatrix(GLenum matrix) { GLdouble gm[16]; glGetDoublev(matrix, gm); - qreal qm[16]; +#if QT_VERSION < 0x050600 + qreal +#else + float +#endif + qm[16]; for (int i = 0; i < 16; ++i) qm[i] = gm[i]; return QMatrix4x4(qm).transposed(); @@ -80,7 +86,12 @@ QMatrix4x4 getGLMatrix(GLenum matrix) { void setGLMatrix(QMatrix4x4 matrix) { GLdouble gm[16]; - qreal qm[16]; +#if QT_VERSION < 0x050600 + qreal +#else + float +#endif + qm[16]; matrix.transposed().copyDataTo(qm); for (int i = 0; i < 16; ++i) gm[i] = qm[i]; @@ -90,7 +101,12 @@ void setGLMatrix(QMatrix4x4 matrix) { void qglMultMatrix(const QMatrix4x4 & m) { GLdouble gm[16]; - qreal qm[16]; +#if QT_VERSION < 0x050600 + qreal +#else + float +#endif + qm[16]; m.transposed().copyDataTo(qm); for (int i = 0; i < 16; ++i) gm[i] = qm[i]; @@ -127,7 +143,7 @@ void createGLTexture(GLuint & tex, const QImage & image, const GLenum & format, glGenTextures(1, &tex); glBindTexture(target, tex); } - QImage im = QGLWidget::convertToGLFormat(image); + QImage im = image;///__GLWidget__::convertToGLFormat(image); //const QImage & cim(im); //glClearError(); //glPixelStorei(GL_UNPACK_ALIGNMENT, 1); @@ -139,7 +155,7 @@ void createGLTexture(GLuint & tex, const QImage & image, const GLenum & format, glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(target, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); } - glTexImage2D(target, 0, format, im.width(), im.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, im.bits()); + glTexImage2D(target, 0, format, im.width(), im.height(), 0, GL_BGRA, GL_UNSIGNED_BYTE, im.bits()); //qDebug() << tex << im.width() << im.height() << im.bits() << glGetError(); } diff --git a/qglview/gltypes.h b/qglview/gltypes.h index 12e460b..1879ed9 100644 --- a/qglview/gltypes.h +++ b/qglview/gltypes.h @@ -41,9 +41,14 @@ # define CC_VC #endif -#define GL_GLEXT_PROTOTYPES +#if QT_VERSION < 0x050600 +# define GL_GLEXT_PROTOTYPES +#endif +#include #ifdef WINDOWS -# include "GLee.h" +# if QT_VERSION < 0x050600 +# include "GLee.h" +# endif #else # ifdef MAC # include @@ -55,12 +60,16 @@ # include # endif #endif -#include +#if QT_VERSION < 0x050600 +# include +#else +//# include "GLee.h" +# include +#endif #include #include //#include #include -#include #include #include #include @@ -70,7 +79,6 @@ #include #include #include -#include #ifndef QNX # include # include @@ -79,6 +87,23 @@ # include #endif #include +#if QT_VERSION >= 0x050400 +# include +# include +# include +typedef QOpenGLWidget __GLWidget__; +typedef QOpenGLContext __GLContext__; +typedef QOpenGLShader __GLShader__; +typedef QOpenGLShaderProgram __GLShaderProgram__; +#else +# include +# include +# include +typedef QGLWidget __GLWidget__; +typedef QGLContext __GLContext__; +typedef QGLShader __GLShader__; +typedef QGLShaderProgram __GLShaderProgram__; +#endif #ifdef WINDOWS # define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF @@ -140,31 +165,50 @@ 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; + inline void qglColor(const QColor & c) {glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF());} void qglMultMatrix(const QMatrix4x4 & m); void glEnableDepth(); void glDisableDepth(); -inline void glActiveTextureChannel(int channel) {glActiveTexture(GL_TEXTURE0 + channel); glClientActiveTexture(GL_TEXTURE0 + channel);} inline void glResetAllTransforms() {glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity();} inline void glClearError() {int c = 100; while (glGetError() != GL_NO_ERROR && --c > 0) glGetError();} inline void glClearAccumulation(const QColor & color = Qt::black) {glClearAccum(color.redF(), color.greenF(), color.blueF(), color.alphaF()); glClear(GL_ACCUM_BUFFER_BIT);} void glClearFramebuffer(const QColor & color = Qt::black, bool depth = true); -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 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 glReleaseShaders() {glUseProgram(0);} inline void glSetCapEnabled(GLenum cap, bool on = true) {if (on) glEnable(cap); else glDisable(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(QGLShaderProgram * prog = 0, QVector4D * corner_dirs = 0, GLfloat x = -1.f, GLfloat y = -1.f, GLfloat w = 2.f, GLfloat h = 2.f); +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); 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 QOpenGLExtraFunctions gf(QOpenGLContext::currentContext()); +# define QGLC gf. +inline void glActiveTextureChannel(int channel) {QGLCI gf.glActiveTexture(GL_TEXTURE0 + channel);} +inline void glDisableTextures(int channels = 8) {QGLCI 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) {QGLCI for (int i = channels - 1; i >= 0; --i) {glActiveTextureChannel(i); glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_CUBE_MAP, 0);}} +inline void glReleaseFramebuffer() {QGLCI gf.glBindFramebuffer(GL_FRAMEBUFFER, 0);} +inline void glReleaseShaders() {QGLCI gf.glUseProgram(0);} +inline void deleteGLFramebuffer(GLuint & fbo) {QGLCI if (fbo != 0) gf.glDeleteFramebuffers(1, &fbo); fbo = 0;} +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());} @@ -176,9 +220,6 @@ inline QImage rotateQImage180(const QImage & im) {return im.mirrored(true, true) //const double deg2rad = atan(1.) / 45.; //const double rad2deg = 45. / atan(1.); -extern QGLWidget * currentQGLView; -extern QMutex globMutex; - struct Box3D { GLfloat x; GLfloat y; diff --git a/qglview/glvbo.cpp b/qglview/glvbo.cpp index 1ce1e7a..0297d86 100644 --- a/qglview/glvbo.cpp +++ b/qglview/glvbo.cpp @@ -33,6 +33,9 @@ GLVBO::~GLVBO() { void GLVBO::init() { +#if QT_VERSION >= 0x050600 + initializeOpenGLFunctions(); +#endif if (!isIinit()) { //glGenVertexArrays(1, &va_); glGenBuffers(1, &buffer_); @@ -114,7 +117,7 @@ bool GLVBO::rebuffer(bool clear_) { } -void GLVBO::draw(GLenum type, QGLShaderProgram * prog, bool simplest) { +void GLVBO::draw(GLenum type, __GLShaderProgram__ * prog, bool simplest) { if (buffer_ == 0 || vert_count == 0) return; if (changed) rebuffer(); //qDebug() << "draw" << vert_count; diff --git a/qglview/glvbo.h b/qglview/glvbo.h index bcfd62c..3a97e90 100644 --- a/qglview/glvbo.h +++ b/qglview/glvbo.h @@ -23,6 +23,9 @@ #include "chunkstream.h" class GLVBO +#if QT_VERSION >= 0x050600 + : protected QOpenGLExtraFunctions +#endif { friend class GLObjectBase; friend QDataStream & operator <<(QDataStream & s, const GLVBO & m); @@ -36,7 +39,7 @@ public: void init(); void destroy(); bool rebuffer(bool clear_ = false); - void draw(GLenum type, QGLShaderProgram * prog, bool simplest = false); + void draw(GLenum type, __GLShaderProgram__ * prog, bool simplest = false); void clear(); GLuint buffer() const {return buffer_;} diff --git a/qglview/loader_3ds.h b/qglview/loader_3ds.h index 2020770..57bbcc5 100644 --- a/qglview/loader_3ds.h +++ b/qglview/loader_3ds.h @@ -21,7 +21,6 @@ #include "gltexture_manager.h" #include "globject.h" -#include #include #include diff --git a/qglview/loader_dae.h b/qglview/loader_dae.h index 9bc55bf..c271cdd 100644 --- a/qglview/loader_dae.h +++ b/qglview/loader_dae.h @@ -21,7 +21,6 @@ #include "gltexture_manager.h" #include "globject.h" -#include #include #include #include diff --git a/qglview/loader_obj.h b/qglview/loader_obj.h index a6ff3ca..b8d3f46 100644 --- a/qglview/loader_obj.h +++ b/qglview/loader_obj.h @@ -21,7 +21,6 @@ #include "gltexture_manager.h" #include "globject.h" -#include #include #include diff --git a/qglview/main.cpp b/qglview/main.cpp deleted file mode 100644 index 9bab139..0000000 --- a/qglview/main.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* - Stanley Designer - Copyright (C) 2017 Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include -#include -#include -#include -#include "qglview_window.h" -//#include -//#include - -/*void display () -{ - qDebug() << (const char*)glGetString(GLUT_VERSION); - qDebug() << (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION); - usleep(200000); -}*/ -template -struct garray { - garray(T * _i) {for (int i = 0; i < N; ++i) _c[i] = &(_i[i]);} - T * _c[N]; - garray & operator =(const garray & o) {for (int i = 0; i < N; ++i) *_c[i] = *(o._c[i]); return *this;}; - template - garray & operator =(const garray & o) {for (int i = 0; i < qMin(N, ON); ++i) *_c[i] = *(o._c[i]); return *this;}; -}; - -template -class gvec3 { -public: - gvec3(T def = T()) {x = y = z = def;} - union { - T xyz[3]; - struct {T x, y, z;}; - }; -private: - T _c[3]; - -}; - -template -QDebug operator<<(QDebug d, const gvec3 & c) { - d.nospace() << "(" << c.x << ", " << c.y << ", " << c.z << ")"; - return d.space(); -} - -typedef gvec3 vec3; -typedef gvec3 ivec3; - -int main(int argc, char ** argv) { - /*float f[3] = {0., 1., 2.}; - float f2[3] = {-1., -1., -1.}; - garray gar(f2); - qDebug() << f2[0] << f2[1] << f2[2]; - gar = garray((float[3]){f[2], f[1], f[0]}); - qDebug() << f2[0] << f2[1] << f2[2];*/ - /*vec3 v0, v1(20); - v0.y = 10; - qDebug() << v0 << v1;*/ - - /*glutInit ( &argc, argv ); - glutInitDisplayMode ( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ); - glutInitWindowSize ( 500, 500 ); - - // prepare context for 3.3 - glutInitContextVersion ( 3, 3 ); - glutInitContextFlags ( GLUT_FORWARD_COMPATIBLE | GLUT_DEBUG ); - glutInitContextProfile ( GLUT_CORE_PROFILE ); - glutCreateWindow ( "Geometry shader example - particles" ); - glutDisplayFunc ( display ); - glewInit (); - if ( !GLEW_VERSION_3_3 ) - { - printf ( "OpenGL 3.3 not supported.\n" ); - - return 1; - } - - glutMainLoop(); - */ - //return 0; - QApplication a(argc, argv); - /*QGLFormat f; - f.setVersion(3, 3); - f.setSampleBuffers(true); - f.setProfile(QGLFormat::CoreProfile); - QGLFormat::setDefaultFormat(f);*/ - //QApplication::setStyle(new QCleanlooksStyle()); - //QDir::setCurrent(a.applicationDirPath()); - //a.setWindowIcon(QIcon(":/icons/peri4_paint.png")); - QGLViewWindow w; - w.show(); - QStringList al(a.arguments()); - al.pop_front(); - foreach (QString s, al) - w.loadFile(s); - return a.exec(); -} diff --git a/qglview/make_install.sh b/qglview/make_install.sh deleted file mode 100644 index 9e65aa3..0000000 --- a/qglview/make_install.sh +++ /dev/null @@ -1,5 +0,0 @@ -#! /bin/bash -cmake . -make $@ -cp -vf *.h /usr/include/ -cp -vf lib*.so /usr/lib/ diff --git a/qglview/propertyeditor.cpp b/qglview/propertyeditor.cpp index 4923aa1..cce7e95 100644 --- a/qglview/propertyeditor.cpp +++ b/qglview/propertyeditor.cpp @@ -326,7 +326,7 @@ void PropertyEditor::itemChanged(QTreeWidgetItem * item, int column) { if (value.canConvert()) { value = value.value().second; } - object->setProperty(item->text(0).toAscii(), value); + object->setProperty(item->text(0).toLatin1(), value); } diff --git a/qglview/qglview.cpp b/qglview/qglview.cpp index c5043d7..0cc2669 100644 --- a/qglview/qglview.cpp +++ b/qglview/qglview.cpp @@ -23,9 +23,18 @@ QGLView::QGLView(QWidget * parent): QGraphicsView(parent), fbo_selection(3) { setFrameShape(QFrame::NoFrame); setViewportUpdateMode(FullViewportUpdate); setCacheMode(CacheNone); + __GLWidget__ * _w; +#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); - setViewport(new QGLWidget(f)); + _w = new __GLWidget__(f); +#endif + setViewport(_w); setMouseTracking(true); setFocusPolicy(Qt::WheelFocus); setScene(new QGraphicsScene()); @@ -156,7 +165,10 @@ void QGLView::drawBackground(QPainter * painter, const QRectF & rect) { void QGLView::initializeGL() { //qDebug() << "init glview"; makeCurrent(); - currentQGLView = (QGLWidget * )viewport(); +#if QT_VERSION >= 0x050600 + initializeOpenGLFunctions(); +#endif + currentQGLView = (__GLWidget__ * )viewport(); currentGLTextureManager = &textures_manager; currentCamera = &camera(); glEnable(GL_TEXTURE_MAX_ANISOTROPY_EXT); @@ -184,9 +196,9 @@ void QGLView::initializeGL() { objects_.initInternal(); checkCaps(); - shader_select = new QGLShaderProgram(context()); - shader_halo = new QGLShaderProgram(context()); - //shader_rope = new QGLShaderProgram(context()); + shader_select = new __GLShaderProgram__(context()); + shader_halo = new __GLShaderProgram__(context()); + //shader_rope = new __GLShaderProgram__(context()); reloadThisShaders(); is_init = true; resizeGL(viewport()->width(), viewport()->height()); @@ -483,7 +495,7 @@ void QGLView::checkCaps() { //glGetIntegerv(GL_MAX_TEXTURE_UNITS, &max_texture_chanels); //qDebug() << max_texture_chanels; //qDebug() << max_texture_chanels; - shaders_supported = QGLShaderProgram::hasOpenGLShaderPrograms(); + shaders_supported = __GLShaderProgram__::hasOpenGLShaderPrograms(); } @@ -540,7 +552,11 @@ void QGLView::mouseReleaseEvent(QMouseEvent * e) { void QGLView::mousePressEvent(QMouseEvent * e) { QGraphicsView::mousePressEvent(e); - mouseThis_ = (scene()->itemAt(mapToScene(e->pos())) == 0); + mouseThis_ = (scene()->itemAt(mapToScene(e->pos()) +#if QT_VERSION >= 0x050000 + , QTransform() +#endif + ) == 0); selecting_ = false; if (!mouseThis_) return; /// TODO select by rect @@ -616,7 +632,11 @@ void QGLView::mouseMoveEvent(QMouseEvent * e) { void QGLView::wheelEvent(QWheelEvent * e) { QGraphicsView::wheelEvent(e); - if (scene()->itemAt(mapToScene(e->pos())) != 0) return; + 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()); diff --git a/qglview/qglview.h b/qglview/qglview.h index ac65cc1..a26cba7 100644 --- a/qglview/qglview.h +++ b/qglview/qglview.h @@ -22,8 +22,6 @@ #include "glframebuffer.h" #include #include -#include -#include #include #include #include @@ -39,6 +37,9 @@ class QGLView: public QGraphicsView, public QGLViewBase +#if QT_VERSION >= 0x050600 + , protected QOpenGLExtraFunctions +#endif { friend class GLRendererBase; Q_OBJECT @@ -119,8 +120,12 @@ public: GLRendererBase * renderer() {return renderer_;} void setRenderer(GLRendererBase * r, GLRendererBase ** prev = 0) {if (prev != 0) *prev = renderer_; renderer_ = r;} - const QGLContext * context() const {return ((const QGLWidget * )viewport())->context();} - void makeCurrent() {((QGLWidget * )viewport())->makeCurrent();} +#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();} QColor backColor() const {return backColor_;} double lineWidth() const {return lineWidth_;} @@ -197,7 +202,7 @@ public: void selectObject(GLObjectBase * o); GLdouble aspect, iaspect; - //QGLShaderProgram * shader_rope; + //__GLShaderProgram__ * shader_rope; protected: virtual void drawBackground(QPainter * painter, const QRectF & rect); @@ -253,7 +258,7 @@ private: //LightingMode lmode; GLObjectBase * sel_obj, * hov_obj; GLFramebuffer fbo_selection; - QGLShaderProgram * shader_select, * shader_halo; + __GLShaderProgram__ * shader_select, * shader_halo; GLRendererBase * renderer_; SelectionMode sel_mode; Qt::MouseButton sel_button; diff --git a/qglview/rope_system.h b/qglview/qglview_test/main.cpp similarity index 60% rename from qglview/rope_system.h rename to qglview/qglview_test/main.cpp index 5465245..14440e6 100644 --- a/qglview/rope_system.h +++ b/qglview/qglview_test/main.cpp @@ -1,6 +1,6 @@ /* - Water system - Copyright (C) 2017 Ivan Pelipenko peri4ko@yandex.ru + Stanley Designer + Copyright (C) 2017 Ivan Pelipenko peri4ko@yandex.ru This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,26 +16,18 @@ along with this program. If not, see . */ -#ifndef ROPE_SYSTEM_H -#define ROPE_SYSTEM_H +#include +#include +#include +#include "qglview_window.h" -#include "globject.h" - -class RopeSystem: public GLObjectBase -{ -public: - RopeSystem(); - ~RopeSystem(); - - virtual void draw(QGLShaderProgram * prog, bool simplest = false); - virtual void init(); - virtual void update() {} - -protected: - GLuint tex[3]; - QVector pos; - GLFramebuffer fbo; - -}; - -#endif // ROPE_SYSTEM_H +int main(int argc, char ** argv) { + QApplication a(argc, argv); + QGLViewWindow w; + w.show(); + QStringList al(a.arguments()); + al.pop_front(); + foreach (QString s, al) + w.loadFile(s); + return a.exec(); +} diff --git a/qglview/qglview_window.cpp b/qglview/qglview_test/qglview_window.cpp similarity index 99% rename from qglview/qglview_window.cpp rename to qglview/qglview_test/qglview_window.cpp index d27c122..2e33cc7 100644 --- a/qglview/qglview_window.cpp +++ b/qglview/qglview_test/qglview_window.cpp @@ -37,7 +37,7 @@ QGLViewWindow::QGLViewWindow(QWidget * parent): QMainWindow(parent), Ui::QGLView view->camera().setAim(QVector3D()); view->camera().setPos(QVector3D(2, 2, 2)); view->setFrameShape(QFrame::NoFrame); - view->setRenderer(new RendererDeferredShading(view)); + view->setRenderer(new RendererSimple(view)); view->setMouseRotateEnabled(true); view->setMouseSelectionEnabled(true); view->setSelectionHaloEnabled(true); diff --git a/qglview/qglview_window.h b/qglview/qglview_test/qglview_window.h similarity index 99% rename from qglview/qglview_window.h rename to qglview/qglview_test/qglview_window.h index b5cbf4c..90d0721 100644 --- a/qglview/qglview_window.h +++ b/qglview/qglview_test/qglview_window.h @@ -37,8 +37,6 @@ #include "renderer_deferred_shading.h" //#include "renderer_rt.h" #include "glparticles_system.h" -#include "water_system.h" -#include "rope_system.h" class QGLViewWindow: public QMainWindow, public Ui::QGLViewWindow diff --git a/qglview/qglview_window.ui b/qglview/qglview_test/qglview_window.ui similarity index 100% rename from qglview/qglview_window.ui rename to qglview/qglview_test/qglview_window.ui diff --git a/qglview/renderer_deferred_shading.cpp b/qglview/renderer_deferred_shading.cpp index 4fe0389..d6a9496 100644 --- a/qglview/renderer_deferred_shading.cpp +++ b/qglview/renderer_deferred_shading.cpp @@ -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) { - QGLShaderProgram * p(*(shaders[i].second)); + __GLShaderProgram__ * p(*(shaders[i].second)); if (p) delete p; } delete df; @@ -521,6 +521,9 @@ void RendererDeferredShading::renderScene() { void RendererDeferredShading::init(int width, int height) { +#if QT_VERSION >= 0x050600 + initializeOpenGLFunctions(); +#endif resize(width, height); } @@ -536,8 +539,8 @@ void RendererDeferredShading::resize(int width, int height) { void RendererDeferredShading::reloadShaders() { for (int i = 0; i < shaders.size(); ++i) { - QGLShaderProgram * p(*(shaders[i].second)); - if (!p) p = new QGLShaderProgram(view.context()); + __GLShaderProgram__ * p(*(shaders[i].second)); + if (!p) p = new __GLShaderProgram__(view.context()); loadShaders(p, shaders[i].first, "shaders"); *(shaders[i].second) = p; } diff --git a/qglview/renderer_deferred_shading.h b/qglview/renderer_deferred_shading.h index c55fa83..9236af2 100644 --- a/qglview/renderer_deferred_shading.h +++ b/qglview/renderer_deferred_shading.h @@ -40,15 +40,15 @@ protected: void setupAmbientLight(const QColor & a, bool first_pass); private: - typedef QPair ShaderPair; + typedef QPair ShaderPair; int cplc, lights_per_pass; double exposure_; GLFramebuffer fbo_g, fbo_out, fbo_hsmall; - QGLShaderProgram * shader_fxaa, * shader_ds_0, * shader_ds_1, * shader_hdr, * shader_small; - QGLShaderProgram * shader_bloom_0, * shader_bloom_1, * shader_motion_blur, * shader_fbo_add; - QGLShaderProgram * shader_shadow, * shader_ssr, * shader_ssr_blur, * shader_ssr_merge; - QGLShaderProgram * shader_ssao_blur, * shader_ssao_merge, * shader_dof; + __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; GLuint tnoise; QVector shaders; diff --git a/qglview/renderer_simple.cpp b/qglview/renderer_simple.cpp index e39571a..8a05464 100644 --- a/qglview/renderer_simple.cpp +++ b/qglview/renderer_simple.cpp @@ -29,17 +29,20 @@ RendererSimple::RendererSimple(QGLView * view_): GLRendererBase(view_), fbo(2) void RendererSimple::reloadShaders() { if (shader_fxaa == 0) { - shader_fxaa = new QGLShaderProgram(view.context()); + shader_fxaa = new __GLShaderProgram__(view.context()); loadShaders(shader_fxaa, "FXAA", "shaders"); } /*if (shader == 0) { - shader = new QGLShaderProgram(view.context()); /// WARNING + shader = new __GLShaderProgram__(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 } diff --git a/qglview/renderer_simple.h b/qglview/renderer_simple.h index eda0c53..a45e73a 100644 --- a/qglview/renderer_simple.h +++ b/qglview/renderer_simple.h @@ -40,7 +40,7 @@ private: void resizeFBO(int w, int h); GLFramebuffer fbo , fbo_c; - QGLShaderProgram * shader_fxaa , * shader; + __GLShaderProgram__ * shader_fxaa , * shader; }; diff --git a/qglview/rope_system.cpp b/qglview/rope_system.cpp deleted file mode 100644 index 4cbb363..0000000 --- a/qglview/rope_system.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - QGLView - Copyright (C) 2017 Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "rope_system.h" -#include "qglview.h" - - -RopeSystem::RopeSystem(): GLObjectBase(), fbo(2, false, GL_RGBA16F, GL_TEXTURE_1D) { - tex[0] = tex[1] = tex[2] = 0; -} - - -RopeSystem::~RopeSystem() { -} - - -void RopeSystem::init() { - pos.clear(); - for (int i = 0; i < 1024; ++i) - pos << (i - 512) / 51.2f << 0.f << 20.f << 0.1f; - deleteGLTexture(tex[0]); - deleteGLTexture(tex[1]); - deleteGLTexture(tex[2]); - glGenTextures(3, tex); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_1D, tex[0]); - glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA16F, 1024, 0, GL_RGBA, GL_FLOAT, pos.constData()); - glBindTexture(GL_TEXTURE_1D, tex[1]); - glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA16F, 1024, 0, GL_RGBA, GL_FLOAT, pos.constData()); - glBindTexture(GL_TEXTURE_1D, tex[2]); - glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA16F, 1024, 0, GL_RGBA, GL_FLOAT, pos.constData()); -} - - -void RopeSystem::draw(QGLShaderProgram * prog, bool simplest) { - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_1D, tex[0]); - glGetTexImage(GL_TEXTURE_1D, 0, GL_RGBA, GL_FLOAT, pos.data()); - glColor3f(1.f, 1.f, 1.f); - glBegin(GL_LINE_STRIP); - int ind = 0; - for (int i = 0; i < 1024; ++i) { - ind = i * 4; - glVertex3f(pos[ind], pos[ind + 1], pos[ind + 2]); - } - glEnd(); - /*((QGLView * )view_)->shader_rope->bind(); - ((QGLView * )view_)->shader_rope->setUniformValue("t0", 0); - ((QGLView * )view_)->shader_rope->setUniformValue("dt", 1.f / 1024.f); - ((QGLView * )view_)->shader_rope->release();*/ -} diff --git a/qglview/water_system.cpp b/qglview/water_system.cpp deleted file mode 100644 index 5899e39..0000000 --- a/qglview/water_system.cpp +++ /dev/null @@ -1,230 +0,0 @@ -/* - QGLView - Copyright (C) 2017 Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "water_system.h" - - -WaterSystem::WaterSystem(): GLObjectBase() { - texture = 0; - near_offsets - << Vector3i(-1, 0, 0) - << Vector3i( 1, 0, 0) - << Vector3i(-1, -1, 0) - << Vector3i( 1, -1, 0) - << Vector3i( 0, -1, 0) - << Vector3i(-1, 1, 0) - << Vector3i( 1, 1, 0) - << Vector3i( 0, 1, 0) - << Vector3i(-1, 0, -1) - << Vector3i( 1, 0, -1) - << Vector3i( 0, 0, -1) - << Vector3i(-1, -1, -1) - << Vector3i( 1, -1, -1) - << Vector3i( 0, -1, -1) - << Vector3i(-1, 1, -1) - << Vector3i( 1, 1, -1) - << Vector3i( 0, 1, -1) - << Vector3i(-1, 0, 1) - << Vector3i( 1, 0, 1) - << Vector3i( 0, 0, 1) - << Vector3i(-1, -1, 1) - << Vector3i( 1, -1, 1) - << Vector3i( 0, -1, 1) - << Vector3i(-1, 1, 1) - << Vector3i( 1, 1, 1) - << Vector3i( 0, 1, 1); -} - - -WaterSystem::~WaterSystem() { - QList cv = big_chunks.values(); - foreach (BigChunk * i, cv) { - qDebug() << "delete" << i; - delete i; - } - cv.clear(); -} - - -void WaterSystem::update() { - QList cv = big_chunks.values(); - //qDebug() << "save states" << cv.size(); - foreach (BigChunk * i, cv) - i->saveState(); - Particle tp; - if (part_count < 5000) - for (int i = 0; i < 10; ++i) { - tp.pos = QVector3D(urand()*20+30, urand()*20+30, 30); - tp.speed = QVector3D(urand(1.), urand(1.), 0.); - newBigChunk(tp.bigChunkIndex())->newChunk(tp.chunkIndex())->particles << tp; - } - QList near_big; - QList near_; - QList * > near_parts; - Vector3i cind, nind; -#if QT_VERSION >= 0x040700 - near_big.reserve(27); - near_.reserve(27); - near_parts.reserve(27); -#endif - foreach (BigChunk * bc, cv) { - Vector3i bci = bc->index; - near_big.clear(); - near_big << bc; - foreach (const Vector3i & o, near_offsets) - near_big << big_chunks.value(bci + o); - near_big.removeAll(0); - for (int i = 0; i < BIG_CHUNK_SIZE; ++i) - for (int j = 0; j < BIG_CHUNK_SIZE; ++j) - for (int k = 0; k < BIG_CHUNK_SIZE; ++k) { - Chunk * cc = bc->chunks[i][j][k]; - if (cc == 0) continue; - near_.clear(); - //foreach (const Vector3i & o, near_offsets) - // near_ << big_chunks.value(bci + o); - near_ << cc; - near_.removeAll(0); - near_parts.clear(); - foreach (Chunk * ci, near_) - if (!ci->prev_particles.isEmpty()) - near_parts << &(ci->prev_particles); - QVector & parts(cc->particles); - //qDebug() << "chunk" << cc->index.toQVector3D() << "proc" << parts.size() << "particles"; - for (int p = 0; p < parts.size(); ++p) { - Particle & cp(parts[p]); - //Vector3i obi = cp.bigChunkIndex(), oi = cp.chunkIndex(); - if (cp.processed) continue; - cp.processed = true; - cind = cp.chunkIndex(); - cp.process(near_parts); - nind = cp.chunkIndex(); - if (nind == cind) continue; - newBigChunk(cp.bigChunkIndex())->newChunk(nind)->particles << cp; - parts.remove(p); - --p; - } - } - } -} - - -void WaterSystem::Particle::process(const QList * > & near_parts) { - accel += Vector3d(0., 0., -0.98 / 60.) / mass; - speed += accel; - pos += speed; - speed *= 0.95; - GLfloat sm = speed.length();//piMax(fabs(speed.x), fabs(speed.y), fabs(speed.z)); - if (sm > 0.2) - speed.normalize() *= 0.2; - if (pos.z - radius < 0.) { - pos.z = radius; - speed.z = -speed.z * 0.2; - speed *= 0.9; - accel.clear(); - } - GLfloat sdist, srad, ssrad; - Vector3d dpos; - //return; - /*int cnt = 0; - foreach (QVector * pl, near_parts) - cnt += pl->size(); - qDebug() << cnt;*/ - foreach (QVector * pl, near_parts) { - QVector & rpl(*pl); - for (int i = 0; i < rpl.size(); ++i) { - Particle & cp(rpl[i]); - srad = radius + cp.radius; - dpos = pos - cp.pos; - if (fabs(dpos.x) >= srad || fabs(dpos.y) >= srad || fabs(dpos.z) >= srad) continue; - ssrad = srad * srad; - sdist = dpos.lengthSquared(); - if (sdist >= ssrad) continue; - //continue; - sdist = sqrt(sdist); - ssrad = (srad - sdist) / 2; - dpos *= ssrad / sdist; - //pos += dpos; - //cp.pos -= dpos; - //qDebug() << "intersect" << sdist << (pos - cp.pos).length(); - speed -= speed.projectTo(dpos) * 2.; - cp.speed -= cp.speed.projectTo(dpos) * 2.; - speed *= 0.8; - cp.speed *= 0.8; - accel *= 0.8; - cp.accel *= 0.8; - } - } -} - - -void WaterSystem::draw(QGLShaderProgram * prog, bool simplest) { - //return; - pass_ = GLObjectBase::Transparent; - //qDebug() << "save states" << cv.size(); - glPointSize(20); - GLfloat pp[] = {1.f, 1.f, 0.f}; - //glEnable(GL_BLEND); - glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, pp); - //glDepthMask(GL_FALSE); - glNormal3f(0.f, 0.f, 1.f); - //glEnable(GL_POINT_SPRITE); - glDisable(GL_TEXTURE_2D); - glEnable(GL_VERTEX_ARRAY); - //glDisable(GL_BLEND); - //glDisable(GL_ALPHA_TEST); - glDisable(GL_NORMAL_ARRAY); - glDisable(GL_COLOR_ARRAY); - glDisable(GL_TEXTURE_COORD_ARRAY); - double ha = 1. / (big_chunks.size() + 1.), ch = 0.; - QVector v; - QList cv = big_chunks.values(); - part_count = 0; - foreach (BigChunk * bc, cv) { - for (int i = 0; i < BIG_CHUNK_SIZE; ++i) - for (int j = 0; j < BIG_CHUNK_SIZE; ++j) - for (int k = 0; k < BIG_CHUNK_SIZE; ++k) { - Chunk * cc = bc->chunks[i][j][k]; - if (cc == 0) continue; - const QVector & cp(cc->particles); - part_count += cp.size(); - v.clear(); - foreach (const Particle & p, cp) - v << p.pos.x << p.pos.y << p.pos.z; - qglColor(QColor::fromHsvF(ch, 1., 1.)); - glVertexPointer(3, GL_FLOAT, 0, v.constData()); - glDrawArrays(GL_POINTS, 0, v.size() / 3); - ch += ha; - while (ch > 1.) ch -= 1.; - } - } - qDebug() << "draw" << part_count << "water particles"; - //glDepthMask(GL_TRUE); - /*if (!d_vertices.isEmpty()) { - glBindBuffer(GL_ARRAY_BUFFER, 0); - glVertexPointer(3, GL_FLOAT, 0, d_vertices.constData()); - glTexCoordPointer(2, GL_FLOAT, 0, d_uvs.constData()); - //glColorPointer(4, GL_FLOAT, 0, d_colors.constData()); - glNormalPointer(GL_FLOAT, 0, d_normals.constData()); - glDrawArrays(geom_prim, 0, d_vertices.size() / 3);*/ - /*if (pass_ == Reflection) { - glActiveTexture(GL_TEXTURE1); - glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); - glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); - }*/ - //} -} diff --git a/qglview/water_system.h b/qglview/water_system.h deleted file mode 100644 index 2197393..0000000 --- a/qglview/water_system.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - Water system - Copyright (C) 2017 Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef WATER_SYSTEM_H -#define WATER_SYSTEM_H - -#include "globject.h" - -#define BIG_CHUNK_SIZE 4 -#define BIG_CHUNK_SIZEF 4.f -#define CHUNK_SIZE 8*8*8 - -class WaterSystem: public GLObjectBase -{ -public: - WaterSystem(); - ~WaterSystem(); - - virtual void draw(QGLShaderProgram * prog, bool simplest = false); - virtual void update(); - virtual void init() {createGLTexture(texture, QImage("./media-record.png")); material_.map_diffuse.bitmap_id = texture; is_init = true;} - -protected: - class Chunk; - class BigChunk; - struct Particle { - Particle() {mass = 1.; radius = 0.2;} - //Particle(const Particle & other) {pos = other.pos; speed = other.speed; accel = other.accel; mass = other.mass; radius = other.radius; processed = other.processed;} - - Vector3d pos; - Vector3d speed; - Vector3d accel; - float mass; - float radius; - bool processed; - - Vector3i chunkIndex() {return Vector3i(floor(pos.x / 8.), floor(pos.y / 8.), floor(pos.z / 8.));} - Vector3i bigChunkIndex() {Vector3i i(floor(pos.x / 8.), floor(pos.y / 8.), floor(pos.z / 8.)); return Vector3i(floor(i.p0 / BIG_CHUNK_SIZEF), floor(i.p1 / BIG_CHUNK_SIZEF), floor(i.p2 / BIG_CHUNK_SIZEF));} - void process(const QList * > & near_parts); - }; - class Chunk { - public: - Chunk() {particles.reserve(CHUNK_SIZE); prev_particles.reserve(CHUNK_SIZE);} - Vector3i bigIndex() {return Vector3i(floor(index.p0 / BIG_CHUNK_SIZEF), floor(index.p1 / BIG_CHUNK_SIZEF), floor(index.p2 / BIG_CHUNK_SIZEF));} - void saveState() {prev_particles = particles; for (int i = 0; i < particles.size(); ++i) particles[i].processed = false;} - Vector3i index; - QVector particles, prev_particles; - }; - class BigChunk { - public: - BigChunk() {for (int i = 0; i < BIG_CHUNK_SIZE; ++i) for (int j = 0; j < BIG_CHUNK_SIZE; ++j) for (int k = 0; k < BIG_CHUNK_SIZE; ++k) chunks[i][j][k] = 0;} - ~BigChunk() {for (int i = 0; i < BIG_CHUNK_SIZE; ++i) for (int j = 0; j < BIG_CHUNK_SIZE; ++j) for (int k = 0; k < BIG_CHUNK_SIZE; ++k) if (chunks[i][j][k] != 0) delete chunks[i][j][k];} - void saveState() {for (int i = 0; i < BIG_CHUNK_SIZE; ++i) for (int j = 0; j < BIG_CHUNK_SIZE; ++j) for (int k = 0; k < BIG_CHUNK_SIZE; ++k) if (chunks[i][j][k] != 0) chunks[i][j][k]->saveState();} - Chunk * newChunk(const Vector3i & i) { - int ii = i.p0 % BIG_CHUNK_SIZE, jj = i.p1 % BIG_CHUNK_SIZE, kk = i.p2 % BIG_CHUNK_SIZE; - if (ii < 0) ii += BIG_CHUNK_SIZE; - if (jj < 0) jj += BIG_CHUNK_SIZE; - if (kk < 0) kk += BIG_CHUNK_SIZE; - if (chunks[ii][jj][kk] == 0) {qDebug() << "insert" << ii << jj << kk; chunks[ii][jj][kk] = new Chunk();} - return chunks[ii][jj][kk];} - Vector3i index; - Chunk * chunks[BIG_CHUNK_SIZE][BIG_CHUNK_SIZE][BIG_CHUNK_SIZE]; - }; - - BigChunk * newBigChunk(const Vector3i & i) {BigChunk * tbc = big_chunks.value(i); if (tbc == 0) {qDebug() << "insert big" << i; tbc = new BigChunk(); big_chunks.insert(i, tbc);} return tbc;} - - QHash big_chunks; - QList near_offsets; - GLuint texture; - ullong part_count; - -}; - -#endif // WATER_SYSTEM_H