Skip to content

Commit

Permalink
Merge pull request #152 from kmkolasinski/switch_to_core_profile
Browse files Browse the repository at this point in the history
Switch to core profile
  • Loading branch information
kmkolasinski committed Sep 10, 2019
2 parents d401b92 + 876b60c commit 61a574d
Show file tree
Hide file tree
Showing 14 changed files with 444 additions and 680 deletions.
105 changes: 68 additions & 37 deletions Sources/CommonObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
}
}
Expand Down Expand Up @@ -435,7 +439,6 @@ class FBOImageProporties{
static int currentMaterialIndeks;



FBOImageProporties(){
bSkipProcessing = false;
properties = NULL;
Expand Down Expand Up @@ -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){
Expand All @@ -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;
}

};


Expand Down
54 changes: 27 additions & 27 deletions Sources/Sources.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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.1
Expand All @@ -14,7 +14,6 @@ VERSION_FULL = 5.1.0
DEFINES += VERSION_STRING=\\\"$$VERSION_STRING\\\"

QTN=utils/QtnProperty
#include($$QTN/Common.pri)
include($$QTN/PEG.pri)


Expand All @@ -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
Expand Down Expand Up @@ -71,7 +71,7 @@ HEADERS = glwidget.h \
glwidgetbase.h \
formmaterialindicesmanager.h \
dialogshortcuts.h \
allaboutdialog.h \
allaboutdialog.h \
formimagebase.h \
dockwidget3dsettings.h \
gpuinfo.h \
Expand All @@ -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

Expand All @@ -112,26 +112,26 @@ 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


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
Expand Down Expand Up @@ -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") {
Expand All @@ -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")
}
Loading

0 comments on commit 61a574d

Please sign in to comment.