From 8ca65c220a6d821151fb4234ebf022545f426b9d Mon Sep 17 00:00:00 2001 From: kmkolasinski Date: Sun, 29 Jul 2018 20:57:09 +0200 Subject: [PATCH 1/2] Initial commit with potential fix which makes AB Core compatible --- Sources/CommonObjects.h | 105 +++++--- Sources/Sources.pro | 54 ++-- Sources/dockwidget3dsettings.ui | 4 +- Sources/glimageeditor.cpp | 120 +++++---- Sources/glimageeditor.h | 9 +- Sources/glwidget.cpp | 314 +++++++++++------------ Sources/main.cpp | 6 + Sources/mainwindow.cpp | 9 +- Sources/resources/shaders/filters.frag | 20 +- Sources/resources/shaders/plane.vert | 78 ------ Sources/resources/shaders/plane_330.vert | 78 ------ Sources/utils/Mesh.cpp | 166 ++++-------- Sources/utils/Mesh.hpp | 1 + Sources/utils/qglbuffers.cpp | 159 +++++------- unixBuildScript.sh | 36 ++- 15 files changed, 470 insertions(+), 689 deletions(-) diff --git a/Sources/CommonObjects.h b/Sources/CommonObjects.h index 7cc69f1..4a8eefd 100644 --- a/Sources/CommonObjects.h +++ b/Sources/CommonObjects.h @@ -313,27 +313,31 @@ class Display3DSettings{ class FBOImages { public: static void create(QGLFramebufferObject *&fbo,int width,int height,GLuint internal_format = TEXTURE_FORMAT){ - if(fbo) - { + + if(fbo) + { fbo->release(); delete fbo; } + QGLFramebufferObjectFormat format; format.setInternalTextureFormat(internal_format); format.setTextureTarget(GL_TEXTURE_2D); format.setMipmap(true); - fbo = new QGLFramebufferObject(width,height,format); - glBindTexture(GL_TEXTURE_2D, fbo->texture()); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + fbo = new QGLFramebufferObject(width, height, format); + + GLCHK(glBindTexture(GL_TEXTURE_2D, fbo->texture())); + GLCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)); + GLCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)); + if(FBOImages::bUseLinearInterpolation){ - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + GLCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); + GLCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); }else{ - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + GLCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)); + GLCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)); } float aniso = 0.0; glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &aniso); @@ -349,11 +353,11 @@ class FBOImages { GLCHK(FBOImages::create(src ,ref->width(),ref->height(),internal_format)); } } - static void resize(QGLFramebufferObject *&src,int width, int height,GLuint internal_format = TEXTURE_FORMAT){ + static void resize(QGLFramebufferObject *&src,int width, int height,GLuint internal_format = TEXTURE_FORMAT){ if(!src){ GLCHK(FBOImages::create(src ,width,height,internal_format)); - }else if( width == src->width() && - height == src->height() ){}else{ + }else if( width == src->width() && height == src->height() ){ + }else{ GLCHK(FBOImages::create(src ,width,height,internal_format)); } } @@ -435,7 +439,6 @@ class FBOImageProporties{ static int currentMaterialIndeks; - FBOImageProporties(){ bSkipProcessing = false; properties = NULL; @@ -464,36 +467,32 @@ class FBOImageProporties{ void init(QImage& image){ qDebug() << Q_FUNC_INFO; - glWidget_ptr->makeCurrent(); - if(glIsTexture(scr_tex_id)) glWidget_ptr->deleteTexture(scr_tex_id); - scr_tex_id = glWidget_ptr->bindTexture(image,GL_TEXTURE_2D); + if(!glWidget_ptr->isValid()){ + qDebug() << "Incorrect Widget pointer. Cannot initialize textures."; + } + + GLCHK(glWidget_ptr->makeCurrent()); + if(glIsTexture(scr_tex_id)) + GLCHK(glWidget_ptr->deleteTexture(scr_tex_id)); + + scr_tex_id = bindImageAsTexture(image); + GLCHK(glBindTexture(GL_TEXTURE_2D, 0)); + scr_tex_width = image.width(); scr_tex_height = image.height(); - bFirstDraw = true; + bFirstDraw = true; + qDebug() << "Bind image texture with id: " << scr_tex_id << " w =" << scr_tex_width << " h = " << scr_tex_height; - /* - switch(imageType){ - case(HEIGHT_TEXTURE): - case(OCCLUSION_TEXTURE): - GLCHK(FBOImages::create(fbo ,image.width(),image.height(),GL_R16F)); - break; - default: - GLCHK(FBOImages::create(fbo ,image.width(),image.height())); - break; - } - */ GLuint internal_format = TEXTURE_FORMAT; if(imageType == HEIGHT_TEXTURE) internal_format = TEXTURE_3DRENDER_FORMAT; - GLCHK(FBOImages::create(fbo , image.width(), image.height(),internal_format)); - + GLCHK(FBOImages::create(fbo , image.width(), image.height(), internal_format)); } void updateSrcTexId(QGLFramebufferObject* in_ref_fbo){ glWidget_ptr->makeCurrent(); if(glIsTexture(scr_tex_id)) glWidget_ptr->deleteTexture(scr_tex_id); QImage image = in_ref_fbo->toImage(); - scr_tex_id = glWidget_ptr->bindTexture(image,GL_TEXTURE_2D); - + scr_tex_id = bindImageAsTexture(image); } void resizeFBO(int width, int height){ @@ -519,18 +518,50 @@ class FBOImageProporties{ qDebug() << Q_FUNC_INFO; glWidget_ptr->makeCurrent(); - if(glIsTexture(normalMixerInputTexId)) glWidget_ptr->deleteTexture(normalMixerInputTexId); - if(glIsTexture(scr_tex_id)) GLCHK(glWidget_ptr->deleteTexture(scr_tex_id)); + if(glIsTexture(normalMixerInputTexId)) + GLCHK(glWidget_ptr->deleteTexture(normalMixerInputTexId)); + if(glIsTexture(scr_tex_id)) + GLCHK(glWidget_ptr->deleteTexture(scr_tex_id)); + normalMixerInputTexId = 0; scr_tex_id = 0; - glWidget_ptr = NULL; - //qDebug() << "p=" << properties; + glWidget_ptr = NULL; if(properties != NULL ) delete properties; if(fbo != NULL ) delete fbo; properties = NULL; fbo = NULL; } } + + static int bindImageAsTexture(QImage image){ + + if (image.isNull()) { + qDebug() << "bindTexture::Cannot create texture for empty image."; + return NULL; + } + image = image.convertToFormat(QImage::Format_ARGB32); +// QTransform flip_transform; +// flip_transform.rotate(180); +// flip_transform.transposed(); +// image = image.transformed(flip_transform); + image = image.mirrored(); + + GLuint texture_id; // get id of new texture + GLCHK(glGenTextures(1, &texture_id)); + GLCHK(glBindTexture(GL_TEXTURE_2D, texture_id)); + + GLCHK(glTexImage2D( + GL_TEXTURE_2D, 0, + GL_RGBA, image.width(), image.height(), 0, + GL_BGRA, GL_UNSIGNED_BYTE, image.bits()) + ); + + GLCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); + GLCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); + GLCHK(glBindTexture(GL_TEXTURE_2D, 0)); + return texture_id; + } + }; diff --git a/Sources/Sources.pro b/Sources/Sources.pro index 61a3edc..8745af4 100644 --- a/Sources/Sources.pro +++ b/Sources/Sources.pro @@ -5,7 +5,7 @@ CONFIG += c++11 QT += opengl gui widgets isEmpty(TOP_DIR) { - ERROR("Run build process from the top directory") + ERROR("Run build process from the top directory") } VERSION_STRING = 5.0 @@ -14,7 +14,6 @@ VERSION_FULL = 5.0.0 DEFINES += VERSION_STRING=\\\"$$VERSION_STRING\\\" QTN=utils/QtnProperty -#include($$QTN/Common.pri) include($$QTN/PEG.pri) @@ -28,12 +27,13 @@ PEG_SOURCES += properties/Filter3DDOF.pef \ gl330: DEFINES += USE_OPENGL_330 -debug: DBG = -dgb +CONFIG(debug, debug|release): DBG = -dgb GL = -gl4 gl330: GL = -gl3 -win32{ # For windows - msvc: LIBS += Opengl32.lib +# Windows settings +win32{ + msvc: LIBS += Opengl32.lib } SPEC=$$[QMAKE_SPEC]$$DBG$$GL @@ -71,7 +71,7 @@ HEADERS = glwidget.h \ glwidgetbase.h \ formmaterialindicesmanager.h \ dialogshortcuts.h \ - allaboutdialog.h \ + allaboutdialog.h \ formimagebase.h \ dockwidget3dsettings.h \ gpuinfo.h \ @@ -80,13 +80,13 @@ HEADERS = glwidget.h \ properties/PropertyABColor.h \ properties/PropertyDelegateABColor.h \ properties/Dialog3DGeneralSettings.h \ - utils/DebugMetricsMonitor.h \ + utils/DebugMetricsMonitor.h \ utils/Mesh.hpp \ utils/qglbuffers.h \ utils/tinyobj/tiny_obj_loader.h \ utils/glslshaderparser.h \ utils/glslparsedshadercontainer.h \ - utils/contextinfo/contextwidget.h \ + utils/contextinfo/contextwidget.h \ utils/contextinfo/renderwindow.h \ formimagebatch.h @@ -112,13 +112,13 @@ SOURCES = glwidget.cpp \ dockwidget3dsettings.cpp \ gpuinfo.cpp \ properties/Dialog3DGeneralSettings.cpp \ - utils/DebugMetricsMonitor.cpp \ + utils/DebugMetricsMonitor.cpp \ utils/glslshaderparser.cpp \ utils/glslparsedshadercontainer.cpp \ properties/propertydelegateabfloatslider.cpp \ properties/PropertyABColor.cpp \ properties/PropertyDelegateABColor.cpp \ - utils/contextinfo/contextwidget.cpp \ + utils/contextinfo/contextwidget.cpp \ utils/contextinfo/renderwindow.cpp \ formimagebatch.cpp @@ -126,12 +126,12 @@ SOURCES = glwidget.cpp \ RESOURCES += content.qrc exists("runtime.qrc") { - # build runtime archive - runtimeTarget.target = runtime.rcc - runtimeTarget.depends = $$PWD/runtime.qrc - runtimeTarget.commands = $$[QT_INSTALL_PREFIX]/bin/rcc -binary $$PWD/runtime.qrc -o $$OUT_PWD/runtime.rcc - QMAKE_EXTRA_TARGETS += runtimeTarget - PRE_TARGETDEPS += runtime.rcc + # build runtime archive + runtimeTarget.target = runtime.rcc + runtimeTarget.depends = $$PWD/runtime.qrc + runtimeTarget.commands = $$[QT_INSTALL_PREFIX]/bin/rcc -binary $$PWD/runtime.qrc -o $$OUT_PWD/runtime.rcc + QMAKE_EXTRA_TARGETS += runtimeTarget + PRE_TARGETDEPS += runtime.rcc } RC_FILE = resources/icon.rc @@ -170,9 +170,9 @@ config.files += $$TOP_DIR/Bin/Configs $$TOP_DIR/Bin/Core INSTALLS += config exists("utils/qtcopydialog/qtcopydialog.pri") { - message("*** Adding 'copydialog' module.") - DEFINES += HAVE_RTCOPY - include("utils/qtcopydialog/qtcopydialog.pri") + message("*** Adding 'copydialog' module.") + DEFINES += HAVE_RTCOPY + include("utils/qtcopydialog/qtcopydialog.pri") } exists("utils/QtnProperty/QtnProperty.pri") { @@ -184,15 +184,15 @@ exists("utils/QtnProperty/QtnProperty.pri") { } exists("utils/quazip/quazip.pri") { - message("*** Adding 'quazip' module.") - DEFINES += HAVE_QUAZIP - CONFIG += quazip_include_zip quazip_include_unzip - include("utils/quazip/quazip.pri") + message("*** Adding 'quazip' module.") + DEFINES += HAVE_QUAZIP + CONFIG += quazip_include_zip quazip_include_unzip + include("utils/quazip/quazip.pri") } exists("utils/fervor/Fervor.pri") { - message("*** Adding 'fervor' module.") - DEFINES += HAVE_FERVOR - FV_APP_VERSION = $$VERSION_FULL - include("utils/fervor/Fervor.pri") + message("*** Adding 'fervor' module.") + DEFINES += HAVE_FERVOR + FV_APP_VERSION = $$VERSION_FULL + include("utils/fervor/Fervor.pri") } diff --git a/Sources/dockwidget3dsettings.ui b/Sources/dockwidget3dsettings.ui index 17aeed6..e63a970 100644 --- a/Sources/dockwidget3dsettings.ui +++ b/Sources/dockwidget3dsettings.ui @@ -10,7 +10,7 @@ 0 0 515 - 248 + 250 @@ -28,7 +28,7 @@ 524287 - 2000 + 250 diff --git a/Sources/glimageeditor.cpp b/Sources/glimageeditor.cpp index 60e309b..f855724 100644 --- a/Sources/glimageeditor.cpp +++ b/Sources/glimageeditor.cpp @@ -109,7 +109,8 @@ void GLImage::cleanup() delete renderFBO; - glDeleteBuffers(sizeof(vbos)/sizeof(GLuint), &vbos[0]); + GLCHK(glDeleteBuffers(sizeof(vbos)/sizeof(GLuint), &vbos[0])); + GLCHK(glDeleteVertexArrays(1, &screen_vao)); doneCurrent(); } @@ -312,7 +313,6 @@ void GLImage::initializeGL() auxFBO2BMLevels[i] = NULL; } paintFBO = NULL; - emit readyGL(); } @@ -342,11 +342,13 @@ void GLImage::paintGL() GLCHK( glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ); GLCHK( glDisable(GL_CULL_FACE) ); GLCHK( glDisable(GL_DEPTH_TEST) ); + + GLCHK(glBindVertexArray(screen_vao)); // positions - glBindBuffer(GL_ARRAY_BUFFER, vbos[0]); - glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,sizeof(float)*3,(void*)0); + GLCHK(glBindBuffer(GL_ARRAY_BUFFER, vbos[0])); + GLCHK(glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,sizeof(float)*3,(void*)0)); // indices - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbos[2]); + GLCHK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbos[2])); QGLFramebufferObject* activeFBO = paintFBO; @@ -354,7 +356,7 @@ void GLImage::paintGL() program = filter_programs["mode_normal_filter"]; program->bind(); #else - GLCHK( glUniformSubroutinesuiv( GL_FRAGMENT_SHADER, 1, &subroutines["mode_normal_filter"]) ); + GLCHK(glUniformSubroutinesuiv( GL_FRAGMENT_SHADER, 1, &subroutines["mode_normal_filter"])); #endif // Displaying new image @@ -373,8 +375,10 @@ void GLImage::paintGL() GLCHK( program->setUniformValue("ModelViewMatrix", m) ); GLCHK( program->setUniformValue("material_id", int(-1)) ); GLCHK( glDrawElements(GL_TRIANGLES, 3*2, GL_UNSIGNED_INT, 0) ); - GLCHK( program->setUniformValue("quad_draw_mode", int(0)) ); + GLCHK( program->setUniformValue("quad_draw_mode", int(0)) ); + GLCHK(glBindVertexArray(0)); } + glBindFramebuffer(GL_FRAMEBUFFER, 0); } @@ -382,7 +386,7 @@ void GLImage::paintGL() void GLImage::render(){ - + glBindFramebuffer(GL_FRAMEBUFFER, 0); if (!activeImage) return; if ( activeImage->fbo){ // since grunge map can be different we need to calculate ratio each time fboRatio = float(activeImage->fbo->width())/activeImage->fbo->height(); @@ -396,8 +400,7 @@ void GLImage::render(){ GLCHK( glDisable(GL_CULL_FACE) ); GLCHK( glDisable(GL_DEPTH_TEST) ); - - + GLCHK(glBindVertexArray(screen_vao)); // positions glBindBuffer(GL_ARRAY_BUFFER, vbos[0]); @@ -405,8 +408,7 @@ void GLImage::render(){ // indices glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbos[2]); - QGLFramebufferObject* activeFBO = activeImage->fbo; - + QGLFramebufferObject* activeFBO = activeImage->fbo; bool bTransformUVs = true; // images which depend on others will not be affected by UV changes again @@ -440,20 +442,19 @@ void GLImage::render(){ break; } - // create or resize when image was changed FBOImages::resize(auxFBO1,activeFBO->width(),activeFBO->height()); FBOImages::resize(auxFBO2,activeFBO->width(),activeFBO->height()); FBOImages::resize(auxFBO3,activeFBO->width(),activeFBO->height()); FBOImages::resize(auxFBO4,activeFBO->width(),activeFBO->height()); - // allocate aditional FBOs when conversion from BaseMap is enabled + // allocate additional FBOs when conversion from BaseMap is enabled if(activeImage->imageType == DIFFUSE_TEXTURE && activeImage->bConversionBaseMap){ for(int i = 0; i < 3 ; i++){ FBOImages::resize(auxFBO0BMLevels[i],activeFBO->width()/pow(2,i+1),activeFBO->height()/pow(2,i+1)); FBOImages::resize(auxFBO1BMLevels[i],activeFBO->width()/pow(2,i+1),activeFBO->height()/pow(2,i+1)); FBOImages::resize(auxFBO2BMLevels[i],activeFBO->width()/pow(2,i+1),activeFBO->height()/pow(2,i+1)); } - }else{// other wise "delete" unnecessary FBOs (I know that this is stupid...) + }else{// other wise "delete" unnecessary FBOs (I know this is stupid...) int small_w_h = 1; for(int i = 0; i < 3 ; i++){ FBOImages::resize(auxFBO0BMLevels[i],small_w_h,small_w_h); @@ -462,14 +463,12 @@ void GLImage::render(){ } } - GLCHK( program->bind() ); - GLCHK( program->setUniformValue("gui_image_type", activeImage->imageType) ); - openGL330ForceTexType = activeImage->imageType; + GLCHK( program->setUniformValue("gui_image_type", activeImage->imageType) ); GLCHK( program->setUniformValue("gui_depth", float(1.0)) ); GLCHK( program->setUniformValue("gui_mode_dgaussian", 1) ); GLCHK( program->setUniformValue("material_id", int(activeImage->currentMaterialIndeks) ) ); - + openGL330ForceTexType = activeImage->imageType; if(activeImage->bFirstDraw){ @@ -488,8 +487,6 @@ void GLImage::render(){ GLCHK( program->setUniformValue("material_id", int(MATERIALS_DISABLED) ) ); } - - GLCHK( glActiveTexture(GL_TEXTURE10) ); GLCHK( glBindTexture(GL_TEXTURE_2D, targetImageMaterial->scr_tex_id) ); GLCHK( glActiveTexture(GL_TEXTURE0) ); @@ -498,7 +495,6 @@ void GLImage::render(){ copyTex2FBO(activeImage->scr_tex_id,activeImage->fbo); // } - // in some cases the output image will be taken from other sources switch(activeImage->imageType){ // ---------------------------------------------------- @@ -524,9 +520,7 @@ void GLImage::render(){ openGL330ForceTexType = HEIGHT_TEXTURE;// used for GL3.30 version GLCHK( program->setUniformValue("gui_image_type", HEIGHT_TEXTURE) ); - copyTex2FBO(targetImageHeight->scr_tex_id,activeFBO); - applyAllUVsTransforms(activeFBO); copyFBO(activeFBO,auxFBO1); @@ -538,8 +532,6 @@ void GLImage::render(){ copyTex2FBO(targetImageHeight->scr_tex_id,activeFBO); } - - break; case(INPUT_FROM_HEIGHT_OUTPUT): applyHeightToNormal(targetImageHeight->fbo,activeFBO); @@ -678,12 +670,7 @@ void GLImage::render(){ break;}// end of case Roughness case(GRUNGE_TEXTURE):{ applyGrungeWarpNormalFilter(activeFBO,auxFBO2); - - //if(activeImage->grungeSeed != 0){ - applyGrungeRandomizationFilter(auxFBO2,activeFBO); - //}else - // copyTex2FBO(auxFBO2->texture(),activeFBO); - + applyGrungeRandomizationFilter(auxFBO2,activeFBO); break; }// end of case Grunge default:break; @@ -710,13 +697,9 @@ void GLImage::render(){ applyAllUVsTransforms(activeFBO); } - - // skip all processing and when mouse is dragged if(!bSkipStandardProcessing){ - - // begin standart pipe-line (for each image) applyInvertComponentsFilter(activeFBO,auxFBO1); copyFBO(auxFBO1,activeFBO); @@ -969,6 +952,8 @@ void GLImage::render(){ GLCHK(applyNormalFilter(activeFBO,renderFBO)); } emit rendered(); + GLCHK(glBindVertexArray(0)); + GLCHK(glBindFramebuffer(GL_FRAMEBUFFER, 0)); } void GLImage::showEvent(QShowEvent* event){ @@ -1009,10 +994,13 @@ void GLImage::resetView(){ // setting the image in the center xTranslation = orthographicProjWidth /2; yTranslation = orthographicProjHeight/2; + + glBindFramebuffer(GL_FRAMEBUFFER, 0); } void GLImage::resizeGL(int width, int height) { + qDebug() << "Resizing GL image to (" << width << ", " << height << ")"; windowRatio = float(width)/height; if (isValid()) { GLCHK( glViewport(0, 0, width, height) ); @@ -2807,39 +2795,49 @@ void GLImage::makeScreenQuad() iter++; }} - glGenBuffers(3, &vbos[0]); - glBindBuffer(GL_ARRAY_BUFFER, vbos[0]); - glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float)*3, vertices.constData(), GL_STATIC_DRAW); - glEnableVertexAttribArray(0); - glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,sizeof(float)*3,(void*)0); - - glBindBuffer(GL_ARRAY_BUFFER, vbos[1]); - glBufferData(GL_ARRAY_BUFFER, texCoords.size() * sizeof(float)*2, texCoords.constData(), GL_STATIC_DRAW); - glEnableVertexAttribArray(1); - glVertexAttribPointer(1,2,GL_FLOAT,GL_FALSE,sizeof(float)*2,(void*)0); + GLCHK(glGenVertexArrays(1, &screen_vao)); + GLCHK(glBindVertexArray(screen_vao)); + // Filling buffers with data: + GLCHK(glGenBuffers(3, &vbos[0])); + qDebug() << "Buffers ids:" << vbos[0] << ", " << vbos[1] << ", " << vbos[2]; + GLCHK(glBindBuffer(GL_ARRAY_BUFFER, vbos[0])); + GLCHK(glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float)*3, vertices.constData(), GL_STATIC_DRAW)); + GLCHK(glEnableVertexAttribArray(0)); + GLCHK(glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,sizeof(float)*3,(void*)0)); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbos[2]); + GLCHK(glBindBuffer(GL_ARRAY_BUFFER, vbos[1])); + GLCHK(glBufferData(GL_ARRAY_BUFFER, texCoords.size() * sizeof(float)*2, texCoords.constData(), GL_STATIC_DRAW)); + GLCHK(glEnableVertexAttribArray(1)); + GLCHK(glVertexAttribPointer(1,2,GL_FLOAT,GL_FALSE,sizeof(float)*2,(void*)0)); + GLCHK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbos[2])); int no_triangles = 2*(size - 1)*(size - 1); QVector indices(no_triangles*3); iter = 0; for(int i = 0 ; i < size -1 ; i++){ - for(int j = 0 ; j < size -1 ; j++){ - GLuint i1 = i + j*size; - GLuint i2 = i + (j+1)*size; - GLuint i3 = i+1 + j*size; - GLuint i4 = i+1 + (j+1)*size; - indices[iter++] = (i1); - indices[iter++] = (i3); - indices[iter++] = (i2); - indices[iter++] = (i2); - indices[iter++] = (i3); - indices[iter++] = (i4); - } - } - GLCHK( glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * no_triangles * 3 , indices.constData(), GL_STATIC_DRAW) ); + for(int j = 0 ; j < size -1 ; j++){ + GLuint i1 = i + j*size; + GLuint i2 = i + (j+1)*size; + GLuint i3 = i+1 + j*size; + GLuint i4 = i+1 + (j+1)*size; + indices[iter++] = (i1); + indices[iter++] = (i3); + indices[iter++] = (i2); + indices[iter++] = (i2); + indices[iter++] = (i3); + indices[iter++] = (i4); + } + } + GLCHK(glBufferData( + GL_ELEMENT_ARRAY_BUFFER, + sizeof(GLuint) * no_triangles * 3 , + indices.constData(), + GL_STATIC_DRAW + )); + + GLCHK(glBindVertexArray(0)); } diff --git a/Sources/glimageeditor.h b/Sources/glimageeditor.h index b59f1ca..cbd251b 100644 --- a/Sources/glimageeditor.h +++ b/Sources/glimageeditor.h @@ -55,8 +55,8 @@ #include #define OPENGL_FUNCTIONS QOpenGLFunctions_3_3_Core #else - #include - #define OPENGL_FUNCTIONS QOpenGLFunctions_4_0_Core + #include + #define OPENGL_FUNCTIONS QOpenGLFunctions_4_1_Core #endif #define BasicProp activeImage->properties->Basic @@ -296,10 +296,11 @@ public slots: QGLFramebufferObject* renderFBO; // Used for rendering to it std::map subroutines; - std::map filter_programs; // all filters in one array - + std::map filter_programs; // all filters in one array GLuint vbos[3]; ConversionType conversionType; + + GLuint screen_vao; bool bShadowRender; bool bSkipProcessing; // draw quad but skip all the processing step (using during mouse interaction) float windowRatio; // window width-height ratio diff --git a/Sources/glwidget.cpp b/Sources/glwidget.cpp index 2f149ce..9b2c0ea 100644 --- a/Sources/glwidget.cpp +++ b/Sources/glwidget.cpp @@ -104,8 +104,6 @@ void GLWidget::cleanup() deleteTexture(lensDirtTexture); deleteTexture(lensStarTexture); - - delete line_program; delete skybox_program; delete env_program; @@ -124,13 +122,14 @@ QSize GLWidget::minimumSizeHint() const { return QSize(100, 100); } + + QSize GLWidget::sizeHint() const { return QSize(500, 400); } - void GLWidget::setCameraMouseSensitivity(int value){ camera.setMouseSensitivity(value); } @@ -183,9 +182,6 @@ void GLWidget::toggleMetallicView(bool enable){ void GLWidget::initializeGL() { - - - initializeOpenGLFunctions(); glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); makeCurrent(); @@ -274,8 +270,6 @@ void GLWidget::initializeGL() delete pfshader; - - GLCHK(currentShader->program->bind()); currentShader->program->setUniformValue("texDiffuse" , 0); currentShader->program->setUniformValue("texNormal" , 1); @@ -299,7 +293,7 @@ void GLWidget::initializeGL() // lines shader qDebug() << "Compiling lines program..."; - preambule = QString("#version 330 core\n")+ + preambule = QString("#version 330 core\n")+ "layout(line_strip, max_vertices = 3) out;\n" ; gshader->compileSourceCode(preambule+shaderCode); if (!gshader->log().isEmpty()) qDebug() << gshader->log(); @@ -341,9 +335,6 @@ void GLWidget::initializeGL() if(teshader != NULL) delete teshader; if(gshader != NULL) delete gshader; - - - // loading sky box shader qDebug() << "Loading skybox shader (vertex shader)"; vshader = new QOpenGLShader(QOpenGLShader::Vertex, this); @@ -412,7 +403,6 @@ void GLWidget::initializeGL() if (!vshader->log().isEmpty()) qDebug() << vshader->log(); else qDebug() << "done"; - qDebug() << "Loading post-processing shaders (fragment shader)"; @@ -464,15 +454,13 @@ void GLWidget::initializeGL() if(vshader != NULL) delete vshader; - GLCHK( lensFlareColorsTexture = bindTexture(QImage(":/resources/textures/lenscolor.png"),GL_TEXTURE_2D) ); + GLCHK( lensFlareColorsTexture = FBOImageProporties::bindImageAsTexture(QImage(":/resources/textures/lenscolor.png"))); qDebug() << "Loading lensColors texture: (id=" << lensFlareColorsTexture << ")"; - GLCHK( lensDirtTexture = bindTexture(QImage(":/resources/textures/lensdirt.png"),GL_TEXTURE_2D) ); + GLCHK( lensDirtTexture = FBOImageProporties::bindImageAsTexture(QImage(":/resources/textures/lensdirt.png"))); qDebug() << "Loading lensDirt texture: (id=" << lensDirtTexture << ")"; - GLCHK( lensStarTexture = bindTexture(QImage(":/resources/textures/lensstar.png"),GL_TEXTURE_2D) ); + GLCHK( lensStarTexture = FBOImageProporties::bindImageAsTexture(QImage(":/resources/textures/lensstar.png"))); qDebug() << "Loading lensDirt texture: (id=" << lensStarTexture << ")"; - - camera.position.setZ( -0 ); camera.toggleFreeCamera(false); newCamera.toggleFreeCamera(false); @@ -491,13 +479,13 @@ void GLWidget::initializeGL() resizeFBOs(); emit readyGL(); + glBindFramebuffer(GL_FRAMEBUFFER, 0); } void GLWidget::paintGL() { - - glReadBuffer(GL_BACK); + glReadBuffer(GL_BACK); // --------------------------------------------------------- // Drawing env // --------------------------------------------------------- @@ -511,8 +499,6 @@ void GLWidget::paintGL() cameraInterpolation += 0.01; } - - // setting the camera viewpoint viewMatrix = camera.updateCamera(); @@ -523,20 +509,19 @@ void GLWidget::paintGL() projectionMatrix.perspective(zoom,ratio,0.1,350.0); - - // set to which FBO result will be drawn - GLuint attachments[4] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 , GL_COLOR_ATTACHMENT3 }; - glDrawBuffers(4, attachments); - GLCHK( glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ); - - GLCHK( glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ); + GLuint attachments[4] = { + GL_COLOR_ATTACHMENT0, + GL_COLOR_ATTACHMENT1, + GL_COLOR_ATTACHMENT2 , + GL_COLOR_ATTACHMENT3 + }; + glDrawBuffers(4, attachments); + GLCHK( glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); // --------------------------------------------------------- // Drawing skybox // --------------------------------------------------------- - - skybox_program->bind(); objectMatrix.setToIdentity(); @@ -548,9 +533,7 @@ void GLWidget::paintGL() NormalMatrix = modelViewMatrix.normalMatrix(); - glDisable(GL_DEPTH_TEST); // disable depth - GLCHK( skybox_program->setUniformValue("ModelViewMatrix" , modelViewMatrix) ); GLCHK( skybox_program->setUniformValue("NormalMatrix" , NormalMatrix) ); GLCHK( skybox_program->setUniformValue("ModelMatrix" , objectMatrix) ); @@ -559,12 +542,13 @@ void GLWidget::paintGL() GLCHK( m_env_map->bind()); GLCHK( skybox_mesh->drawMesh(true) ); - // --------------------------------------------------------- // Drawing model // --------------------------------------------------------- - QOpenGLShaderProgram* program_ptrs[2] = {currentShader->program,line_program}; - + QOpenGLShaderProgram* program_ptrs[2] = { + currentShader->program, + line_program + }; GLCHK( glEnable(GL_CULL_FACE) ); GLCHK( glEnable(GL_DEPTH_TEST) ); @@ -574,117 +558,110 @@ void GLWidget::paintGL() for(int pindex = 0 ; pindex < 2 ; pindex ++){ - QOpenGLShaderProgram* program_ptr = program_ptrs[pindex]; - GLCHK( program_ptr->bind() ); + QOpenGLShaderProgram* program_ptr = program_ptrs[pindex]; + GLCHK( program_ptr->bind() ); - // Update uniforms from parsed file. - if(pindex == 0){ - Dialog3DGeneralSettings::setUniforms(); - } - - - GLCHK( program_ptr->setUniformValue("ProjectionMatrix", projectionMatrix) ); - - objectMatrix.setToIdentity(); - if( fboIdPtrs[0] != NULL){ - float fboRatio = float((*(fboIdPtrs[0]))->width())/(*(fboIdPtrs[0]))->height(); - objectMatrix.scale(fboRatio,1,fboRatio); - } - if(mesh->isLoaded()){ - - objectMatrix.scale(0.5/mesh->radius); - objectMatrix.translate(-mesh->centre_of_mass); - } - modelViewMatrix = viewMatrix*objectMatrix; - NormalMatrix = modelViewMatrix.normalMatrix(); - float mesh_scale = 0.5/mesh->radius; - - GLCHK( program_ptr->setUniformValue("ModelViewMatrix" , modelViewMatrix) ); - GLCHK( program_ptr->setUniformValue("NormalMatrix" , NormalMatrix) ); - GLCHK( program_ptr->setUniformValue("ModelMatrix" , objectMatrix) ); - GLCHK( program_ptr->setUniformValue("meshScale" , mesh_scale) ); - - GLCHK( program_ptr->setUniformValue("lightPos" , lightPosition) ); - - GLCHK( program_ptr->setUniformValue("lightDirection" , lightDirection.direction) ); - - GLCHK( program_ptr->setUniformValue("cameraPos" , camera.get_position()) ); - GLCHK( program_ptr->setUniformValue("gui_depthScale" , display3Dparameters.depthScale) ); - GLCHK( program_ptr->setUniformValue("gui_uvScale" , display3Dparameters.uvScale) ); - GLCHK( program_ptr->setUniformValue("gui_uvScaleOffset" , display3Dparameters.uvOffset) ); - GLCHK( program_ptr->setUniformValue("gui_bSpecular" , bToggleSpecularView) ); - if(FBOImageProporties::bConversionBaseMap){ - GLCHK( program_ptr->setUniformValue("gui_bDiffuse" , false) ); - }else{ - GLCHK( program_ptr->setUniformValue("gui_bDiffuse" , bToggleDiffuseView) ); - } + // Update uniforms from parsed file. + if(pindex == 0){ + Dialog3DGeneralSettings::setUniforms(); + } - GLCHK( program_ptr->setUniformValue("gui_bOcclusion" , bToggleOcclusionView) ); - GLCHK( program_ptr->setUniformValue("gui_bHeight" , bToggleHeightView) ); - GLCHK( program_ptr->setUniformValue("gui_bNormal" , bToggleNormalView) ); - GLCHK( program_ptr->setUniformValue("gui_bRoughness" , bToggleRoughnessView) ); - GLCHK( program_ptr->setUniformValue("gui_bMetallic" , bToggleMetallicView) ); - GLCHK( program_ptr->setUniformValue("gui_shading_type" , display3Dparameters.shadingType) ); - GLCHK( program_ptr->setUniformValue("gui_shading_model" , display3Dparameters.shadingModel) ); - GLCHK( program_ptr->setUniformValue("gui_SpecularIntensity" , display3Dparameters.specularIntensity) ); - GLCHK( program_ptr->setUniformValue("gui_DiffuseIntensity" , display3Dparameters.diffuseIntensity) ); - GLCHK( program_ptr->setUniformValue("gui_LightPower" , display3Dparameters.lightPower) ); - GLCHK( program_ptr->setUniformValue("gui_LightRadius" , display3Dparameters.lightRadius) ); - - // number of mipmaps - GLCHK( program_ptr->setUniformValue("num_mipmaps" , m_env_map->numMipmaps ) ); - // 3D settings - GLCHK( program_ptr->setUniformValue("gui_bUseCullFace" , display3Dparameters.bUseCullFace) ); - GLCHK( program_ptr->setUniformValue("gui_bUseSimplePBR" , display3Dparameters.bUseSimplePBR) ); - GLCHK( program_ptr->setUniformValue("gui_noTessSub" , display3Dparameters.noTessSubdivision) ); - GLCHK( program_ptr->setUniformValue("gui_noPBRRays" , display3Dparameters.noPBRRays) ); - - if(display3Dparameters.bShowTriangleEdges && pindex == 0){ - glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); - glEnable( GL_POLYGON_OFFSET_FILL ); - glPolygonOffset( 1.0f, 1.0f ); - GLCHK( program_ptr->setUniformValue("gui_bShowTriangleEdges", true) ); - GLCHK( program_ptr->setUniformValue("gui_bMaterialsPreviewEnabled" , true) ); - }else{ - if(display3Dparameters.bShowTriangleEdges){ - glDisable( GL_POLYGON_OFFSET_FILL ); - glEnable( GL_POLYGON_OFFSET_LINE ); - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - glPolygonOffset( -2.0f, -2.0f ); - glLineWidth(1.0f); + GLCHK( program_ptr->setUniformValue("ProjectionMatrix", projectionMatrix) ); + objectMatrix.setToIdentity(); + if( fboIdPtrs[0] != NULL){ + float fboRatio = float((*(fboIdPtrs[0]))->width())/(*(fboIdPtrs[0]))->height(); + objectMatrix.scale(fboRatio,1,fboRatio); + } + if(mesh->isLoaded()){ + objectMatrix.scale(0.5/mesh->radius); + objectMatrix.translate(-mesh->centre_of_mass); + } + modelViewMatrix = viewMatrix*objectMatrix; + NormalMatrix = modelViewMatrix.normalMatrix(); + float mesh_scale = 0.5/mesh->radius; + + GLCHK( program_ptr->setUniformValue("ModelViewMatrix" , modelViewMatrix) ); + GLCHK( program_ptr->setUniformValue("NormalMatrix" , NormalMatrix) ); + GLCHK( program_ptr->setUniformValue("ModelMatrix" , objectMatrix) ); + GLCHK( program_ptr->setUniformValue("meshScale" , mesh_scale) ); + GLCHK( program_ptr->setUniformValue("lightPos" , lightPosition) ); + GLCHK( program_ptr->setUniformValue("lightDirection" , lightDirection.direction)); + GLCHK( program_ptr->setUniformValue("cameraPos" , camera.get_position()) ); + GLCHK( program_ptr->setUniformValue("gui_depthScale" , display3Dparameters.depthScale) ); + GLCHK( program_ptr->setUniformValue("gui_uvScale" , display3Dparameters.uvScale) ); + GLCHK( program_ptr->setUniformValue("gui_uvScaleOffset" , display3Dparameters.uvOffset) ); + GLCHK( program_ptr->setUniformValue("gui_bSpecular" , bToggleSpecularView) ); + + if(FBOImageProporties::bConversionBaseMap){ + GLCHK( program_ptr->setUniformValue("gui_bDiffuse" , false) ); + }else{ + GLCHK( program_ptr->setUniformValue("gui_bDiffuse" , bToggleDiffuseView) ); } - GLCHK( program_ptr->setUniformValue("gui_bShowTriangleEdges", display3Dparameters.bShowTriangleEdges) ); - - // Material preview: M key : when triangles are disabled - if(!display3Dparameters.bShowTriangleEdges) - GLCHK( program_ptr->setUniformValue("gui_bMaterialsPreviewEnabled" , bool(keyPressed == KEY_SHOW_MATERIALS)) ); - } + GLCHK( program_ptr->setUniformValue("gui_bOcclusion" , bToggleOcclusionView) ); + GLCHK( program_ptr->setUniformValue("gui_bHeight" , bToggleHeightView) ); + GLCHK( program_ptr->setUniformValue("gui_bNormal" , bToggleNormalView) ); + GLCHK( program_ptr->setUniformValue("gui_bRoughness" , bToggleRoughnessView) ); + GLCHK( program_ptr->setUniformValue("gui_bMetallic" , bToggleMetallicView) ); + GLCHK( program_ptr->setUniformValue("gui_shading_type" , display3Dparameters.shadingType) ); + GLCHK( program_ptr->setUniformValue("gui_shading_model" , display3Dparameters.shadingModel) ); + GLCHK( program_ptr->setUniformValue("gui_SpecularIntensity" , display3Dparameters.specularIntensity) ); + GLCHK( program_ptr->setUniformValue("gui_DiffuseIntensity" , display3Dparameters.diffuseIntensity) ); + GLCHK( program_ptr->setUniformValue("gui_LightPower" , display3Dparameters.lightPower) ); + GLCHK( program_ptr->setUniformValue("gui_LightRadius" , display3Dparameters.lightRadius) ); + + // number of mipmaps + GLCHK( program_ptr->setUniformValue("num_mipmaps" , m_env_map->numMipmaps ) ); + // 3D settings + GLCHK( program_ptr->setUniformValue("gui_bUseCullFace" , display3Dparameters.bUseCullFace) ); + GLCHK( program_ptr->setUniformValue("gui_bUseSimplePBR" , display3Dparameters.bUseSimplePBR) ); + GLCHK( program_ptr->setUniformValue("gui_noTessSub" , display3Dparameters.noTessSubdivision) ); + GLCHK( program_ptr->setUniformValue("gui_noPBRRays" , display3Dparameters.noPBRRays) ); + + if(display3Dparameters.bShowTriangleEdges && pindex == 0){ + glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); + glEnable( GL_POLYGON_OFFSET_FILL ); + glPolygonOffset( 1.0f, 1.0f ); + GLCHK( program_ptr->setUniformValue("gui_bShowTriangleEdges", true) ); + GLCHK( program_ptr->setUniformValue("gui_bMaterialsPreviewEnabled" , true) ); + }else{ + if(display3Dparameters.bShowTriangleEdges){ + glDisable( GL_POLYGON_OFFSET_FILL ); + glEnable( GL_POLYGON_OFFSET_LINE ); + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + glPolygonOffset( -2.0f, -2.0f ); + glLineWidth(1.0f); + } + + GLCHK( program_ptr->setUniformValue("gui_bShowTriangleEdges", display3Dparameters.bShowTriangleEdges) ); + // Material preview: M key : when triangles are disabled + if(!display3Dparameters.bShowTriangleEdges) + GLCHK( program_ptr->setUniformValue("gui_bMaterialsPreviewEnabled" , bool(keyPressed == KEY_SHOW_MATERIALS)) ); + } + if( fboIdPtrs[0] != NULL){ + int tindeks = 0; - if( fboIdPtrs[0] != NULL){ + for(tindeks = 0 ; tindeks <= MATERIAL_TEXTURE ; tindeks++){ // skip grunge texture (not used in 3D view) + GLCHK( glActiveTexture(GL_TEXTURE0+tindeks) ); + GLCHK( glBindTexture(GL_TEXTURE_2D, (*(fboIdPtrs[tindeks]))->texture()) ); + } - int tindeks = 0; + GLCHK( glActiveTexture(GL_TEXTURE0 + tindeks ) ); + GLCHK(m_prefiltered_env_map->bind()); - for(tindeks = 0 ; tindeks <= MATERIAL_TEXTURE ; tindeks++){ // skip grunge texture (not used in 3D view) - GLCHK( glActiveTexture(GL_TEXTURE0+tindeks) ); - GLCHK( glBindTexture(GL_TEXTURE_2D, (*(fboIdPtrs[tindeks]))->texture()) ); + tindeks++; + GLCHK( glActiveTexture(GL_TEXTURE0 + tindeks) ); + GLCHK( m_env_map->bind()); + GLCHK( mesh->drawMesh() ); + // set default active texture + glActiveTexture(GL_TEXTURE0); } - GLCHK( glActiveTexture(GL_TEXTURE0 + tindeks ) ); - GLCHK(m_prefiltered_env_map->bind()); - - tindeks++; - GLCHK( glActiveTexture(GL_TEXTURE0 + tindeks) ); - GLCHK( m_env_map->bind()); - GLCHK( mesh->drawMesh() ); - // set default active texture - glActiveTexture(GL_TEXTURE0); - } + if(!display3Dparameters.bShowTriangleEdges) break; - if(!display3Dparameters.bShowTriangleEdges) break; }// end of loop over triangles glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDisable( GL_POLYGON_OFFSET_LINE ); @@ -696,14 +673,10 @@ void GLWidget::paintGL() // set to which FBO result will be drawn GLuint attachments2[1] = { GL_COLOR_ATTACHMENT0 }; glDrawBuffers(1, attachments2); - - colorFBO->bindDefault(); GLCHK( glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ); - - // do post processing if materials are not shown if( keyPressed != KEY_SHOW_MATERIALS ){ @@ -733,20 +706,15 @@ void GLWidget::paintGL() if(display3Dparameters.bLensFlares){ applyLensFlaresFilter(colorFBO->fbo->texture(),outputFBO->fbo); } - applyToneFilter(colorFBO->fbo->texture(),outputFBO->fbo); - - applyNormalFilter(outputFBO->fbo->texture()); }else{ // end of if SHOW MATERIALS TEXTURE DISABLED GLCHK( applyNormalFilter(colorFBO->fbo->texture())); } - GLCHK( filter_program->release() ); - emit renderGL(); - + glBindFramebuffer(GL_FRAMEBUFFER, 0); } void GLWidget::bakeEnviromentalMaps(){ @@ -757,16 +725,15 @@ void GLWidget::bakeEnviromentalMaps(){ // --------------------------------------------------------- env_program->bind(); m_prefiltered_env_map->bindFBO(); - glViewport(0,0,512,512); + glViewport(0, 0, 512, 512); objectMatrix.setToIdentity(); objectMatrix.scale(1.0); - objectMatrix.rotate(90.0,1,0,0); + objectMatrix.rotate(90.0, 1, 0, 0); modelViewMatrix = viewMatrix * objectMatrix; NormalMatrix = modelViewMatrix.normalMatrix(); - GLCHK( env_program->setUniformValue("ModelViewMatrix" , modelViewMatrix) ); GLCHK( env_program->setUniformValue("NormalMatrix" , NormalMatrix) ); GLCHK( env_program->setUniformValue("ModelMatrix" , objectMatrix) ); @@ -776,17 +743,23 @@ void GLWidget::bakeEnviromentalMaps(){ GLCHK( m_env_map->bind()); GLCHK( env_mesh->drawMesh(true) ); - glBindFramebuffer (GL_FRAMEBUFFER, 0); - + glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(0, 0, width(), height()) ; + env_program->release(); } void GLWidget::resizeGL(int width, int height) { + qDebug() << "Resizing GLWidget image to (" << width << ", " << height << ")"; ratio = float(width)/height; + deleteFBOs(); resizeFBOs(); - - GLCHK( glViewport(0, 0, width, height) ); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + // SHITFIX => bake enviromental maps again, this will slow down GUI when + // resizing windows, but helps to prevent some bug in rendering + // when window size has been changed. + bDiffuseMapBaked = false; + GLCHK( glViewport(0, 0, width, height)); } void GLWidget::mousePressEvent(QMouseEvent *event) @@ -1032,11 +1005,15 @@ void GLWidget::chooseMeshFile(const QString &fileName){ void GLWidget::chooseSkyBox(QString cubeMapName,bool bFirstTime){ QStringList list; makeCurrent(); - list << QString(RESOURCE_BASE) + "Core/2D/skyboxes/" + cubeMapName + "/posx.jpg" << QString(RESOURCE_BASE) + "Core/2D/skyboxes/" + cubeMapName + "/negx.jpg" << QString(RESOURCE_BASE) + "Core/2D/skyboxes/" + cubeMapName + "/posy.jpg" - << QString(RESOURCE_BASE) + "Core/2D/skyboxes/" + cubeMapName + "/negy.jpg" << QString(RESOURCE_BASE) + "Core/2D/skyboxes/" + cubeMapName + "/posz.jpg" << QString(RESOURCE_BASE) + "Core/2D/skyboxes/" + cubeMapName + "/negz.jpg"; + list << QString(RESOURCE_BASE) + "Core/2D/skyboxes/" + cubeMapName + "/posx.jpg" + << QString(RESOURCE_BASE) + "Core/2D/skyboxes/" + cubeMapName + "/negx.jpg" + << QString(RESOURCE_BASE) + "Core/2D/skyboxes/" + cubeMapName + "/posy.jpg" + << QString(RESOURCE_BASE) + "Core/2D/skyboxes/" + cubeMapName + "/negy.jpg" + << QString(RESOURCE_BASE) + "Core/2D/skyboxes/" + cubeMapName + "/posz.jpg" + << QString(RESOURCE_BASE) + "Core/2D/skyboxes/" + cubeMapName + "/negz.jpg"; qDebug() << "Reading new cube map:" << list; - bDiffuseMapBaked = false; + bDiffuseMapBaked = false; if(m_env_map != NULL) delete m_env_map; m_env_map = new GLTextureCube(list); @@ -1190,12 +1167,25 @@ void GLWidget::deleteFBOs(){ delete colorFBO; delete outputFBO; delete auxFBO; + // reset pointers + colorFBO = NULL; + outputFBO = NULL; + auxFBO = NULL; for(int i = 0; i < 4 ; i++){ - if(glowInputColor[i] != NULL) delete glowInputColor[i]; - if(glowOutputColor[i] != NULL) delete glowOutputColor[i]; + if(glowInputColor[i] != NULL){ + delete glowInputColor[i]; + glowInputColor[i] = NULL; + } + if(glowOutputColor[i] != NULL){ + delete glowOutputColor[i]; + glowOutputColor[i] = NULL; + } } for(int i = 0; i < 10 ; i++){ - if(toneMipmaps[i] != NULL) delete toneMipmaps[i]; + if(toneMipmaps[i] != NULL){ + delete toneMipmaps[i]; + toneMipmaps[i] = NULL; + } } } @@ -1208,10 +1198,7 @@ void GLWidget::applyNormalFilter(GLuint input_tex){ GLCHK( filter_program->setUniformValue("quad_pos" , QVector2D(0.0,0.0)) ); GLCHK( glActiveTexture(GL_TEXTURE0) ); GLCHK( glBindTexture(GL_TEXTURE_2D, input_tex) ); - GLCHK( quad_mesh->drawMesh(true) ); - - } void GLWidget::copyTexToFBO(GLuint input_tex,QGLFramebufferObject* dst){ @@ -1229,12 +1216,11 @@ void GLWidget::copyTexToFBO(GLuint input_tex,QGLFramebufferObject* dst){ } + void GLWidget::applyGaussFilter( GLuint input_tex, QGLFramebufferObject* auxFBO, QGLFramebufferObject* outputFBO, float radius){ - - filter_program = post_processing_programs["GAUSSIAN_BLUR_FILTER"]; filter_program->bind(); @@ -1496,9 +1482,7 @@ void GLWidget::applyLensFlaresFilter(GLuint input_tex,QGLFramebufferObject* outp QMatrix4x4 uLensStarMatrix = scaleBias2 * rotation * scaleBias1; - // Third step -- blend images (orginal,halos,dirt texture, and star texture) - - + // Third step -- blend images (orginal,halos,dirt texture, and star texture) outputFBO->bind(); GLCHK( glViewport(0,0,outputFBO->width(),outputFBO->height()) ); GLCHK( filter_program->setUniformValue("quad_scale", QVector2D(1.0,1.0)) ); diff --git a/Sources/main.cpp b/Sources/main.cpp index 7395a3f..108f4d0 100644 --- a/Sources/main.cpp +++ b/Sources/main.cpp @@ -95,6 +95,9 @@ void customMessageHandler(QtMsgType type, const QMessageLogContext &context, con case QtWarningMsg: txt += QString("{Warning} \t %1").arg(msg); break; + case QtInfoMsg: + txt += QString("{Info} \t %1").arg(msg); + break; case QtCriticalMsg: txt += QString("{Critical} \t %1").arg(msg); break; @@ -284,6 +287,9 @@ int main(int argc, char *argv[]) format.setVersion( GL_MAJOR, GL_MINOR ); #endif + glFormat.setProfile( QGLFormat::CoreProfile ); // Requires >=Qt-4.8.0 + glFormat.setSampleBuffers( true ); + QGLFormat::setDefaultFormat(glFormat); QSurfaceFormat::setDefaultFormat(format); diff --git a/Sources/mainwindow.cpp b/Sources/mainwindow.cpp index d7573ce..4fa14a4 100644 --- a/Sources/mainwindow.cpp +++ b/Sources/mainwindow.cpp @@ -44,9 +44,12 @@ MainWindow::MainWindow(QWidget *parent) : glWidget = new GLWidget(this,glImage); } + #define INIT_PROGRESS(p,m) \ emit initProgress(p); \ - emit initMessage(m); + emit initMessage(m); \ + qApp->processEvents() + void MainWindow::initializeApp() { @@ -1526,12 +1529,12 @@ void MainWindow::updateSliders(){ FBOImageProporties::bSeamlessTranslationsFirst = ui->checkBoxUVTranslationsFirst->isChecked(); - // choosing the proper mirror mode + // choosing the propper mirror mode if(ui->radioButtonMirrorModeXY->isChecked()) FBOImageProporties::seamlessMirroModeType = 0; if(ui->radioButtonMirrorModeX ->isChecked()) FBOImageProporties::seamlessMirroModeType = 1; if(ui->radioButtonMirrorModeY ->isChecked()) FBOImageProporties::seamlessMirroModeType = 2; - // choosing the proper simple mode direction + // choosing the propper simple mode direction if(ui->radioButtonSeamlessSimpleDirXY->isChecked()) FBOImageProporties::seamlessSimpleModeDirection = 0; if(ui->radioButtonSeamlessSimpleDirX ->isChecked()) FBOImageProporties::seamlessSimpleModeDirection = 1; if(ui->radioButtonSeamlessSimpleDirY ->isChecked()) FBOImageProporties::seamlessSimpleModeDirection = 2; diff --git a/Sources/resources/shaders/filters.frag b/Sources/resources/shaders/filters.frag index 191a993..33206b0 100644 --- a/Sources/resources/shaders/filters.frag +++ b/Sources/resources/shaders/filters.frag @@ -1063,8 +1063,8 @@ vec4 ffilter(){ const vec2 size = vec2(1.0,0.0); const ivec3 off = ivec3(-1,0,1); - const ivec2 dx = ivec2(1,0); - const ivec2 dy = ivec2(0,1); + #define dx ivec2(1, 0) + #define dy ivec2(0, 1) vec2 tex_coord = v2QuadCoords.st; highp float R0 = texture(layerA, tex_coord).x; @@ -1082,22 +1082,6 @@ vec4 ffilter(){ dRy = normalize(vec3(-size.yx,gui_hn_conversion_depth*(Ry-R0))); bump = bump + normalize( cross(dRx,dRy) ); -// // (-dx,dy) -// Rx = textureOffset(layerA, tex_coord, -dx).x; -// Ry = textureOffset(layerA, tex_coord, dy).x; -// dRx = normalize(vec3(-size.xy,gui_hn_conversion_depth*(Rx-R0))); -// dRy = normalize(vec3( size.yx,gui_hn_conversion_depth*(Ry-R0))); -// bump = bump - normalize( cross(dRx,dRy) ); - -// // (dx,-dy) -// Rx = textureOffset(layerA, tex_coord, dx).x; -// Ry = textureOffset(layerA, tex_coord, -dy).x; -// dRx = normalize(vec3( size.xy,gui_hn_conversion_depth*(Rx-R0))); -// dRy = normalize(vec3(-size.yx,gui_hn_conversion_depth*(Ry-R0))); -// bump = bump - normalize( cross(dRx,dRy) ); - - - bump = normalize(bump); return vec4(clamp(bump*0.5 + 0.5,vec3(0),vec3(1)),1); } diff --git a/Sources/resources/shaders/plane.vert b/Sources/resources/shaders/plane.vert index 51e4fc5..baa6ea4 100644 --- a/Sources/resources/shaders/plane.vert +++ b/Sources/resources/shaders/plane.vert @@ -32,81 +32,3 @@ void main() vSmoothedNormal = smoothedNormalIn; vTexcoord = vec3(texcoordIn.st,0)*gui_uvScale + vec3(gui_uvScaleOffset,0); } - - -/* -uniform mat4 ModelViewMatrix; -uniform mat4 ProjectionMatrix; -uniform mat3 NormalMatrix; -uniform float meshScale; -uniform float gui_depthScale; -uniform float gui_uvScale; -uniform vec4 cameraPos; -uniform vec4 lightPos; -uniform bool gui_bHeight; -uniform int gui_shading_type; - - -out vec3 texcoord; -out vec3 ESVertexPosition; -out vec3 ESVertexNormal; -out vec3 ESVertexTangent; -out vec3 ESVertexBitangent; - -const int no_lights = 2; -out vec3 TSLightPosition[no_lights]; -out vec3 TSViewDirection[no_lights]; -out vec3 TSHalfVector; - -void bump_mapping(vec3 eyeLightDir[2],vec3 eyeVertexDir[2],vec3 halfVector){ - - - vec3 fvVertexNormal = ESVertexNormal; - vec3 fvBiVertexNormal = ESVertexBitangent; - vec3 fvTangent = ESVertexTangent; - - // Tangent space calculation of two lights - for(int lightIndeks = 0; lightIndeks < 2 ; lightIndeks++){ - TSViewDirection[lightIndeks].x = dot( fvTangent , eyeVertexDir[lightIndeks] ); - TSViewDirection[lightIndeks].y = dot( fvBiVertexNormal , eyeVertexDir[lightIndeks] ); - TSViewDirection[lightIndeks].z = dot( fvVertexNormal , eyeVertexDir[lightIndeks] ); - - TSLightPosition[lightIndeks].x = dot( fvTangent , eyeLightDir[lightIndeks] ); - TSLightPosition[lightIndeks].y = dot( fvBiVertexNormal , eyeLightDir[lightIndeks] ); - TSLightPosition[lightIndeks].z = dot( fvVertexNormal , eyeLightDir[lightIndeks] ); - } - - TSHalfVector.x = dot( fvTangent , halfVector ); - TSHalfVector.y = dot( fvBiVertexNormal , halfVector ); - TSHalfVector.z = dot( fvVertexNormal , halfVector ); - -} - - - -void main() -{ - - - texcoord = texcoordIn; - ESVertexNormal = NormalMatrix * normalIn; - ESVertexTangent = NormalMatrix * tangentIn; - ESVertexBitangent = NormalMatrix * bitangentIn; - vec4 eyeVec = ModelViewMatrix * vec4(positionIn,1); - ESVertexPosition = eyeVec.xyz; - - vec3 eyeLightVectors[2]; - eyeLightVectors[0] = normalize(cameraPos.xyz-eyeVec.xyz); - eyeLightVectors[1] = normalize(lightPos.xyz-eyeVec.xyz); - - vec3 eyeViewVectors[2]; - eyeViewVectors[0] = -normalize(eyeVec.xyz); - eyeViewVectors[1] = -normalize(eyeVec.xyz); - - vec4 lightV = vec4(0,0,5,0); - bump_mapping(eyeLightVectors,eyeViewVectors,normalize(lightV.xyz+eyeVec.xyz)); - gl_Position = ProjectionMatrix * eyeVec; - - -} -*/ diff --git a/Sources/resources/shaders/plane_330.vert b/Sources/resources/shaders/plane_330.vert index 90684d4..3ae831f 100644 --- a/Sources/resources/shaders/plane_330.vert +++ b/Sources/resources/shaders/plane_330.vert @@ -32,81 +32,3 @@ void main() teSmoothedNormal = smoothedNormalIn; teTexcoord = vec3(texcoordIn.st,0)*gui_uvScale + vec3(gui_uvScaleOffset,0); } - - -/* -uniform mat4 ModelViewMatrix; -uniform mat4 ProjectionMatrix; -uniform mat3 NormalMatrix; -uniform float meshScale; -uniform float gui_depthScale; -uniform float gui_uvScale; -uniform vec4 cameraPos; -uniform vec4 lightPos; -uniform bool gui_bHeight; -uniform int gui_shading_type; - - -out vec3 texcoord; -out vec3 ESVertexPosition; -out vec3 ESVertexNormal; -out vec3 ESVertexTangent; -out vec3 ESVertexBitangent; - -const int no_lights = 2; -out vec3 TSLightPosition[no_lights]; -out vec3 TSViewDirection[no_lights]; -out vec3 TSHalfVector; - -void bump_mapping(vec3 eyeLightDir[2],vec3 eyeVertexDir[2],vec3 halfVector){ - - - vec3 fvVertexNormal = ESVertexNormal; - vec3 fvBiVertexNormal = ESVertexBitangent; - vec3 fvTangent = ESVertexTangent; - - // Tangent space calculation of two lights - for(int lightIndeks = 0; lightIndeks < 2 ; lightIndeks++){ - TSViewDirection[lightIndeks].x = dot( fvTangent , eyeVertexDir[lightIndeks] ); - TSViewDirection[lightIndeks].y = dot( fvBiVertexNormal , eyeVertexDir[lightIndeks] ); - TSViewDirection[lightIndeks].z = dot( fvVertexNormal , eyeVertexDir[lightIndeks] ); - - TSLightPosition[lightIndeks].x = dot( fvTangent , eyeLightDir[lightIndeks] ); - TSLightPosition[lightIndeks].y = dot( fvBiVertexNormal , eyeLightDir[lightIndeks] ); - TSLightPosition[lightIndeks].z = dot( fvVertexNormal , eyeLightDir[lightIndeks] ); - } - - TSHalfVector.x = dot( fvTangent , halfVector ); - TSHalfVector.y = dot( fvBiVertexNormal , halfVector ); - TSHalfVector.z = dot( fvVertexNormal , halfVector ); - -} - - - -void main() -{ - - - texcoord = texcoordIn; - ESVertexNormal = NormalMatrix * normalIn; - ESVertexTangent = NormalMatrix * tangentIn; - ESVertexBitangent = NormalMatrix * bitangentIn; - vec4 eyeVec = ModelViewMatrix * vec4(positionIn,1); - ESVertexPosition = eyeVec.xyz; - - vec3 eyeLightVectors[2]; - eyeLightVectors[0] = normalize(cameraPos.xyz-eyeVec.xyz); - eyeLightVectors[1] = normalize(lightPos.xyz-eyeVec.xyz); - - vec3 eyeViewVectors[2]; - eyeViewVectors[0] = -normalize(eyeVec.xyz); - eyeViewVectors[1] = -normalize(eyeVec.xyz); - - vec4 lightV = vec4(0,0,5,0); - bump_mapping(eyeLightVectors,eyeViewVectors,normalize(lightV.xyz+eyeVec.xyz)); - gl_Position = ProjectionMatrix * eyeVec; - - -} -*/ diff --git a/Sources/utils/Mesh.cpp b/Sources/utils/Mesh.cpp index bdad4c4..c33855e 100644 --- a/Sources/utils/Mesh.cpp +++ b/Sources/utils/Mesh.cpp @@ -111,8 +111,6 @@ Mesh::Mesh(QString dir, QString name):mesh_path(name){ if(dist > radius) radius = dist; } - //qDebug() << "mesh radius=" << radius; - //qDebug() << "mesh center=" << centre_of_mass; calculateTangents(); @@ -165,103 +163,34 @@ Mesh::Mesh(QString dir, QString name):mesh_path(name){ } } - - delete[] verlet; - - bLoaded = true; initializeMesh(); } -/* -bool Mesh::hasCommonEdge(int i, int j){ - int ta = i/3; // triangle A ID - int tb = j/3; // triangle B ID - if( i > j ) return false; - if(ta > tb) return false; - if( ta == tb ) return false; - - int la = i - 3*ta; // local indeks in triangle A - int lb = j - 3*tb; - - - - for(int li = 0; li < 3 ; li++ ){ - if( li != la){ - - for(int lj = 0; lj < 3 ; lj++){ - if( lj != lb ){ - - // check if two points are same - if( (gl_vertices[3*ta+li] - gl_vertices[3*tb+lj]).length()/radius < 1.0E-5 ){ - // if yes both triangles has common edge - qDebug() << "i =" << i << "\tj =" << j; - qDebug() << "ta=" << ta << "\ttb=" << tb; - qDebug() << "la=" << la << "\tlb=" << lb ; - qDebug() << "ia=" << 3*ta+li << "\tjb=" << 3*tb+lj << endl; - if(no_shared_edges[j] > 1 || no_shared_edges[i] > 1 ){ - qDebug() << "i =" << i << "\tj =" << j; - qDebug() << "ia=" << 3*ta+li << "\tjb=" << 3*tb+lj << endl; - } - - if(no_shared_edges[i] == 0){ - no_shared_edges[i]++; - gl_shared_uvs[i].setX(gl_texcoords[j].x()); - gl_shared_uvs[i].setY(gl_texcoords[j].y()); - }else if(no_shared_edges[i] == 1){ - no_shared_edges[i]++; - gl_shared_uvs[i].setZ(gl_texcoords[j].x()); - gl_shared_uvs[i].setW(gl_texcoords[j].y()); - } - if(no_shared_edges[j] == 0){ - no_shared_edges[j]++; - gl_shared_uvs[j].setX(gl_texcoords[i].x()); - gl_shared_uvs[j].setY(gl_texcoords[i].y()); - }else if(no_shared_edges[j] == 1){ - no_shared_edges[j]++; - gl_shared_uvs[j].setZ(gl_texcoords[i].x()); - gl_shared_uvs[j].setW(gl_texcoords[i].y()); - } - - - return true; - - - - // return true; - } - } - } - }// end of if li - }// end of for li - //qDebug() << "" ; - return false; -} -*/ void Mesh::drawMesh(bool bUseArrays ){ if(bLoaded == false) return; - glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[0]); - glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0); - - glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[1]); - glVertexAttribPointer(1,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0); + GLCHK(glBindVertexArray(mesh_vao)); - glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[2]); - glVertexAttribPointer(2,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0); + GLCHK(glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[0])); + GLCHK(glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0)); - glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[3]); - glVertexAttribPointer(3,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0); + GLCHK(glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[1])); + GLCHK(glVertexAttribPointer(1,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0)); - glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[4]); - glVertexAttribPointer(4,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0); + GLCHK(glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[2])); + GLCHK(glVertexAttribPointer(2,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0)); - glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[5]); - glVertexAttribPointer(5,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0); + GLCHK(glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[3])); + GLCHK(glVertexAttribPointer(3,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0)); + GLCHK(glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[4])); + GLCHK(glVertexAttribPointer(4,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0)); + GLCHK(glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[5])); + GLCHK(glVertexAttribPointer(5,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0)); if(bUseArrays){ GLCHK(glDrawArrays(GL_TRIANGLES, 0, gl_vertices.size())); @@ -273,58 +202,56 @@ void Mesh::drawMesh(bool bUseArrays ){ glPatchParameteri(GL_PATCH_VERTICES, 3); // tell OpenGL that every patch has 16 verts GLCHK(glDrawArrays(GL_PATCHES, 0, gl_vertices.size())); // draw a bunch of patches #endif - } - + } + GLCHK(glBindVertexArray(0)); } void Mesh::initializeMesh(){ - //static bool bOneTime = true; - //if(!bOneTime) return; - //bOneTime = false; - if(bLoaded == false){ cerr << Q_FUNC_INFO << " Cannot initialize mesh because is NULL."; cerr.flush(); return; } - initializeOpenGLFunctions(); - glGenBuffers(6, &mesh_vbos[0]); - - glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[0]); - glBufferData(GL_ARRAY_BUFFER, gl_vertices.size() * sizeof(QVector3D), gl_vertices.constData(), GL_STATIC_DRAW); - glEnableVertexAttribArray(0); - glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0); + GLCHK(initializeOpenGLFunctions()); + GLCHK(glGenVertexArrays(1, &mesh_vao)); + GLCHK(glBindVertexArray(mesh_vao)); - glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[1]); - glBufferData(GL_ARRAY_BUFFER, gl_texcoords.size() * sizeof(QVector3D), gl_texcoords.constData(), GL_STATIC_DRAW); - glEnableVertexAttribArray(1); - glVertexAttribPointer(1,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0); + GLCHK(glGenBuffers(6, &mesh_vbos[0])); - glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[2]); - glBufferData(GL_ARRAY_BUFFER, gl_normals.size() * sizeof(QVector3D), gl_normals.constData(), GL_STATIC_DRAW); - glEnableVertexAttribArray(2); - glVertexAttribPointer(2,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0); + GLCHK(glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[0])); + GLCHK(glBufferData(GL_ARRAY_BUFFER, gl_vertices.size() * sizeof(QVector3D), gl_vertices.constData(), GL_STATIC_DRAW)); + GLCHK(glEnableVertexAttribArray(0)); + GLCHK(glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0)); - glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[3]); - glBufferData(GL_ARRAY_BUFFER, gl_tangents.size() * sizeof(QVector3D), gl_tangents.constData(), GL_STATIC_DRAW); - glEnableVertexAttribArray(3); - glVertexAttribPointer(3,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0); + GLCHK(glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[1])); + GLCHK(glBufferData(GL_ARRAY_BUFFER, gl_texcoords.size() * sizeof(QVector3D), gl_texcoords.constData(), GL_STATIC_DRAW)); + GLCHK(glEnableVertexAttribArray(1)); + GLCHK(glVertexAttribPointer(1,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0)); - glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[4]); - glBufferData(GL_ARRAY_BUFFER, gl_bitangents.size() * sizeof(QVector3D), gl_bitangents.constData(), GL_STATIC_DRAW); - glEnableVertexAttribArray(4); - glVertexAttribPointer(4,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0); + GLCHK(glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[2])); + GLCHK(glBufferData(GL_ARRAY_BUFFER, gl_normals.size() * sizeof(QVector3D), gl_normals.constData(), GL_STATIC_DRAW)); + GLCHK(glEnableVertexAttribArray(2)); + GLCHK(glVertexAttribPointer(2,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0)); - glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[5]); - glBufferData(GL_ARRAY_BUFFER, gl_smoothed_normals.size() * sizeof(QVector3D), gl_smoothed_normals.constData(), GL_STATIC_DRAW); - glEnableVertexAttribArray(5); - glVertexAttribPointer(5,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0); + GLCHK(glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[3])); + GLCHK(glBufferData(GL_ARRAY_BUFFER, gl_tangents.size() * sizeof(QVector3D), gl_tangents.constData(), GL_STATIC_DRAW)); + GLCHK(glEnableVertexAttribArray(3)); + GLCHK(glVertexAttribPointer(3,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0)); + GLCHK(glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[4])); + GLCHK(glBufferData(GL_ARRAY_BUFFER, gl_bitangents.size() * sizeof(QVector3D), gl_bitangents.constData(), GL_STATIC_DRAW)); + GLCHK(glEnableVertexAttribArray(4)); + GLCHK(glVertexAttribPointer(4,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0)); + GLCHK(glBindBuffer(GL_ARRAY_BUFFER, mesh_vbos[5])); + GLCHK(glBufferData(GL_ARRAY_BUFFER, gl_smoothed_normals.size() * sizeof(QVector3D), gl_smoothed_normals.constData(), GL_STATIC_DRAW)); + GLCHK(glEnableVertexAttribArray(5)); + GLCHK(glVertexAttribPointer(5,3,GL_FLOAT,GL_FALSE,sizeof(QVector3D),(void*)0)); + GLCHK(glBindVertexArray(0)); } @@ -419,5 +346,8 @@ Mesh::~Mesh() { gl_bitangents.clear(); gl_smoothed_normals.clear(); - if(bLoaded) GLCHK(glDeleteBuffers(6 , mesh_vbos )); + if(bLoaded){ + GLCHK(glDeleteBuffers(6 , mesh_vbos)); + GLCHK(glDeleteVertexArrays(1, &mesh_vao)); + }; } diff --git a/Sources/utils/Mesh.hpp b/Sources/utils/Mesh.hpp index dbcb137..727ece7 100644 --- a/Sources/utils/Mesh.hpp +++ b/Sources/utils/Mesh.hpp @@ -66,6 +66,7 @@ class Mesh : public OPENGL_FUNCTIONS { QString mesh_path; + GLuint mesh_vao; bool bLoaded; diff --git a/Sources/utils/qglbuffers.cpp b/Sources/utils/qglbuffers.cpp index 8ee37f7..e9f6e83 100644 --- a/Sources/utils/qglbuffers.cpp +++ b/Sources/utils/qglbuffers.cpp @@ -67,17 +67,17 @@ GLTexture::~GLTexture() GLTexture2D::GLTexture2D(int width, int height) { - glBindTexture(GL_TEXTURE_2D, m_texture); - glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, - GL_BGRA, GL_UNSIGNED_BYTE, 0); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + GLCHK(glBindTexture(GL_TEXTURE_2D, m_texture)); + GLCHK(glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, + GL_BGRA, GL_UNSIGNED_BYTE, 0)); + + GLCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)); + GLCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)); + GLCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); + GLCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); //glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); - glBindTexture(GL_TEXTURE_2D, 0); + GLCHK(glBindTexture(GL_TEXTURE_2D, 0)); } @@ -186,35 +186,35 @@ void GLTexture3D::unbind() GLTextureCube::GLTextureCube(int size) { - glBindTexture(GL_TEXTURE_CUBE_MAP, m_texture); - + GLCHK(glBindTexture(GL_TEXTURE_2D, 0)); + GLCHK(glBindTexture(GL_TEXTURE_CUBE_MAP, m_texture)); + qDebug() << "m_texture:" << m_texture; for (int i = 0; i < 6; ++i) - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 4, size, size, 0, - GL_BGRA, GL_UNSIGNED_BYTE, 0); - - 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); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - //glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - //glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_GENERATE_MIPMAP, GL_TRUE); - //glGenerateMipmap(GL_TEXTURE_CUBE_MAP); - glBindTexture(GL_TEXTURE_CUBE_MAP, 0); + GLCHK(glTexImage2D( + GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGBA, size, size, 0, + GL_BGRA, GL_UNSIGNED_BYTE, 0) + ); + + GLCHK(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); + GLCHK(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); + GLCHK(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE)); + GLCHK(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); + GLCHK(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); + GLCHK(glBindTexture(GL_TEXTURE_CUBE_MAP, 0)); // from http://stackoverflow.com/questions/462721/rendering-to-cube-map // framebuffer object - glGenFramebuffers (1, &fbo); - glBindFramebuffer (GL_FRAMEBUFFER, fbo); - glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_texture, 0); - glDrawBuffer (GL_COLOR_ATTACHMENT0); // important! + GLCHK(glGenFramebuffers (1, &fbo)); + GLCHK(glBindFramebuffer (GL_FRAMEBUFFER, fbo)); + GLCHK(glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_texture, 0)); + GLCHK(glDrawBuffer (GL_COLOR_ATTACHMENT0)); // important! GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if(status != GL_FRAMEBUFFER_COMPLETE){ - glDeleteFramebuffers(1, &fbo); + GLCHK(glDeleteFramebuffers(1, &fbo)); fbo = 0; } - glBindFramebuffer(GL_FRAMEBUFFER,0); + GLCHK(glBindFramebuffer(GL_FRAMEBUFFER,0)); } GLTextureCube::GLTextureCube(const QStringList& fileNames, int size) @@ -241,8 +241,11 @@ GLTextureCube::GLTextureCube(const QStringList& fileNames, int size) // Works on x86, so probably works on all little-endian systems. // Does it work on big-endian systems? - GLCHK(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + index, 0, 4, image.width(), image.height(), 0, - GL_BGRA, GL_UNSIGNED_BYTE, image.bits()) ); + GLCHK(glTexImage2D( + GL_TEXTURE_CUBE_MAP_POSITIVE_X + index, 0, + GL_RGBA, image.width(), image.height(), 0, + GL_BGRA, GL_UNSIGNED_BYTE, image.bits() + )); if (++index == 6) break; @@ -250,21 +253,20 @@ GLTextureCube::GLTextureCube(const QStringList& fileNames, int size) // Clear remaining faces. while (index < 6) { - GLCHK(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + index, 0, 4, size, size, 0, - GL_BGRA, GL_UNSIGNED_BYTE, 0)); + GLCHK(glTexImage2D( + GL_TEXTURE_CUBE_MAP_POSITIVE_X + index, 0, GL_RGBA, + size, size, 0, GL_BGRA, GL_UNSIGNED_BYTE, 0 + )); ++index; } GLCHK(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); GLCHK(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); GLCHK(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE)); - GLCHK(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); - //glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + GLCHK(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); GLCHK(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)); - GLCHK(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_GENERATE_MIPMAP, GL_TRUE)); GLCHK(glGenerateMipmap(GL_TEXTURE_CUBE_MAP)); - // get number of mip maps if ( (numMipmaps = textureCalcLevels(GL_TEXTURE_CUBE_MAP_POSITIVE_X)) == -1 ) { int max_level; @@ -279,28 +281,28 @@ GLTextureCube::GLTextureCube(const QStringList& fileNames, int size) void GLTextureCube::load(int size, int face, QRgb *data) { - glBindTexture(GL_TEXTURE_CUBE_MAP, m_texture); - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, 4, size, size, 0, - GL_BGRA, GL_UNSIGNED_BYTE, data); - glBindTexture(GL_TEXTURE_CUBE_MAP, 0); + GLCHK(glBindTexture(GL_TEXTURE_CUBE_MAP, m_texture)); + GLCHK(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, 4, size, size, 0, + GL_BGRA, GL_UNSIGNED_BYTE, data)); + GLCHK(glBindTexture(GL_TEXTURE_CUBE_MAP, 0)); } void GLTextureCube::bind() { - glBindTexture(GL_TEXTURE_CUBE_MAP, m_texture); - glEnable(GL_TEXTURE_CUBE_MAP); + GLCHK(glBindTexture(GL_TEXTURE_CUBE_MAP, m_texture)); +// GLCHK(glEnable(GL_TEXTURE_CUBE_MAP)); } void GLTextureCube::bindFBO(){ - glBindFramebuffer (GL_FRAMEBUFFER, fbo); - glDrawBuffer (GL_COLOR_ATTACHMENT0); // important! + GLCHK(glBindFramebuffer (GL_FRAMEBUFFER, fbo)); + GLCHK(glDrawBuffer (GL_COLOR_ATTACHMENT0)); // important! } void GLTextureCube::unbind() { - glBindTexture(GL_TEXTURE_CUBE_MAP, 0); - glDisable(GL_TEXTURE_CUBE_MAP); + GLCHK(glBindTexture(GL_TEXTURE_CUBE_MAP, 0)); + GLCHK(glDisable(GL_TEXTURE_CUBE_MAP)); } int GLTextureCube::textureCalcLevels(GLenum target) @@ -330,24 +332,7 @@ GLFrameBufferObject::GLFrameBufferObject(int width, int height) , m_height(height) , m_failed(false) { - initializeOpenGLFunctions(); - -/* - - glGenTextures(1, &depth_texture); - glBindTexture(GL_TEXTURE_2D, depth_texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); - //NULL means reserve texture memory, but texels are undefined - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); - glBindTexture(GL_TEXTURE_2D, 0); - */ - + GLCHK(initializeOpenGLFunctions()); fbo = NULL; attachments.clear(); @@ -356,22 +341,23 @@ GLFrameBufferObject::GLFrameBufferObject(int width, int height) format.setTextureTarget(GL_TEXTURE_2D); format.setMipmap(true); format.setAttachment(QGLFramebufferObject::Depth); - fbo = new QGLFramebufferObject(width,height,format); - glBindTexture(GL_TEXTURE_2D, fbo->texture()); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + fbo = new QGLFramebufferObject(width, height, format); + + GLCHK(glBindTexture(GL_TEXTURE_2D, fbo->texture())); + GLCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT)); + GLCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT)); + GLCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); + GLCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); GLCHK(glBindTexture(GL_TEXTURE_2D, 0)); - glBindFramebuffer(GL_FRAMEBUFFER, 0); + GLCHK(glBindFramebuffer(GL_FRAMEBUFFER, 0)); } GLFrameBufferObject::~GLFrameBufferObject() { fbo->release(); for(unsigned int i = 0;i< attachments.size();i++){ - glDeleteTextures(1,&attachments[i]); + GLCHK(glDeleteTextures(1,&attachments[i])); } attachments.erase(attachments.begin(),attachments.end()); @@ -382,37 +368,33 @@ GLFrameBufferObject::~GLFrameBufferObject() bool GLFrameBufferObject::isComplete() { - // GLBUFFERS_ASSERT_OPENGL("GLFrameBufferObject::isComplete", glCheckFramebufferStatusEXT, return false) - return GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER); } void GLFrameBufferObject::bind(){ - fbo->bind(); + GLCHK(fbo->bind()); } void GLFrameBufferObject::bindDefault(){ - fbo->bindDefault(); + GLCHK(fbo->bindDefault()); } bool GLFrameBufferObject::addTexture(GLenum COLOR_ATTACHMENTn){ - GLuint tex[1]; GLCHK(glGenTextures(1, &tex[0])); - glBindTexture(GL_TEXTURE_2D, tex[0]); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); - - glTexImage2D(GL_TEXTURE_2D, 0, TEXTURE_3DRENDER_FORMAT, fbo->width(), fbo->height(), 0,GL_RGB, GL_UNSIGNED_BYTE, 0); - glBindTexture(GL_TEXTURE_2D, 0); + GLCHK(glBindTexture(GL_TEXTURE_2D, tex[0])); + GLCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); + GLCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); + GLCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT)); + GLCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT)); + GLCHK(glTexImage2D(GL_TEXTURE_2D, 0, TEXTURE_3DRENDER_FORMAT, fbo->width(), fbo->height(), 0,GL_RGB, GL_UNSIGNED_BYTE, 0)); + GLCHK(glBindTexture(GL_TEXTURE_2D, 0)); if(!glIsTexture(tex[0])){ qDebug() << "Error: Cannot create additional texture. Process stopped." << endl; return false; } GLCHK(fbo->bind()); - glFramebufferTexture2D(GL_FRAMEBUFFER, COLOR_ATTACHMENTn,GL_TEXTURE_2D, tex[0], 0); + GLCHK(glFramebufferTexture2D(GL_FRAMEBUFFER, COLOR_ATTACHMENTn,GL_TEXTURE_2D, tex[0], 0)); GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if(status != GL_FRAMEBUFFER_COMPLETE){ @@ -421,8 +403,7 @@ bool GLFrameBufferObject::addTexture(GLenum COLOR_ATTACHMENTn){ return false; } // switch back to window-system-provided framebuffer - glBindFramebuffer(GL_FRAMEBUFFER, 0); - + GLCHK(glBindFramebuffer(GL_FRAMEBUFFER, 0)); attachments.push_back(tex[0]); return true; } diff --git a/unixBuildScript.sh b/unixBuildScript.sh index b4f41d9..904b58a 100755 --- a/unixBuildScript.sh +++ b/unixBuildScript.sh @@ -1,16 +1,27 @@ #!/bin/bash - # Add your QT path here by setting MY_QT_PATH variable # MY_QT_PATH=/YOUR_PATH_HERE/Qt/5.X/gcc_64/bin/ MY_QT_PATH= + +if [[ "$OSTYPE" == "darwin"* ]]; then + MY_QT_PATH=/Developer/Qt/5.6 + if [ ! -e "$MY_QT_PATH" ]; then + MY_QT_PATH=~/Qt/5.6 + fi +else + MY_QT_PATH=/opt/Qt5.7.0/5.7/gcc_64/bin/ +fi + wget="wget" tool="gcc_64" +peg="bin-linux" exe="" if [[ "$OSTYPE" == "darwin"* ]]; then wget="curl -L -o master.zip" tool="clang_64" + peg="bin-osx" exe=".app" fi @@ -27,20 +38,27 @@ if [ ! -e "$MY_QT_PATH" ]; then fi if [ "$(ls -A Sources/utils/QtnProperty)" ]; then - echo "QtnProperty module is already initialized. No action is performed." + echo "*** QtnProperty module is already initialized. No action is performed." else - echo "Initializing QtnProperty module" + echo "*** Initializing QtnProperty module" # Copy QtnProperty directly from the repository - cd Sources/utils/QtnProperty + pushd Sources/utils/QtnProperty $wget https://github.com/kmkolasinski/QtnProperty/archive/master.zip unzip master.zip rm master.zip mv QtnProperty-master/* . rm -r QtnProperty-master - cd ../../../ + popd fi -qmake \ - && make \ - && echo "*** Copying binary from `cat workdir/current` ..." \ - && cp -vr workdir/`cat workdir/current`/bin/AwesomeBump$exe ./Bin +if Sources/utils/QtnProperty/$peg/QtnPEG > /dev/null ; then + qmake \ + && make \ + && echo "*** Copying binary from `cat workdir/current` ..." \ + && cp -vr workdir/`cat workdir/current`/bin/AwesomeBump$exe ./Bin +else + echo " --------------------------------------" + echo " Error: QtnPEG failed to run." + echo " --------------------------------------" + echo "Try to rebuild the QtnPEG binary from Sources/utils/QtnProperty directory." +fi From 349c869bdf4cc2da965188ec329166e80dd2fcb7 Mon Sep 17 00:00:00 2001 From: kkol Date: Tue, 10 Sep 2019 16:24:49 +0200 Subject: [PATCH 2/2] Small change in the build script --- unixBuildScript.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unixBuildScript.sh b/unixBuildScript.sh index 92c0e29..1a80fb2 100755 --- a/unixBuildScript.sh +++ b/unixBuildScript.sh @@ -3,7 +3,7 @@ # Add your QT path here by setting MY_QT_PATH variable # MY_QT_PATH=/YOUR_PATH_HERE/Qt/5.X/gcc_64/bin/ MY_QT_PATH=/opt/Qt5.9.0/5.9/gcc_64/bin/ -BUILD_WITH_OPENGL_330_SUPPORT="no" +BUILD_WITH_OPENGL_330_SUPPORT=$1 MAKE_NUM_THREADS='-j 8' wget="wget"