diff --git a/.travis.yml b/.travis.yml index f865ea88..982bf688 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,64 +9,41 @@ language: cpp notifications: email: false +sudo: required + +services: + - docker + matrix: include: - os: linux - sudo: required - services: docker - env: VER_SUFFIX='-4.8' CC_NAME=gcc CXX_NAME=g++ + env: CC_NAME=gcc-4.8 CXX_NAME=g++-4.8 - os: linux - sudo: required - services: docker - env: VER_SUFFIX='-5' CC_NAME=gcc CXX_NAME=g++ + env: CC_NAME=gcc-5 CXX_NAME=g++-5 - os: linux - sudo: required - services: docker - env: VER_SUFFIX='' CC_NAME=gcc CXX_NAME=g++ #gcc 7.3 + env: CC_NAME=gcc CXX_NAME=g++ #default gnu compilers from ubuntu - os: linux - sudo: required - services: docker - env: VER_SUFFIX='-3.9' CC_NAME=clang CXX_NAME=clang++ + env: CC_NAME=clang-3.9 CXX_NAME=clang++-3.9 - os: linux - sudo: required - services: docker - env: VER_SUFFIX='-4.0' CC_NAME=clang CXX_NAME=clang++ + env: CC_NAME=clang-4.0 CXX_NAME=clang++-4.0 - os: linux - sudo: required - services: docker - env: VER_SUFFIX='-5.0' CC_NAME=clang CXX_NAME=clang++ + env: CC_NAME=clang-5.0 CXX_NAME=clang++-5.0 - os: linux - sudo: required - services: docker - env: VER_SUFFIX='-6.0' CC_NAME=clang CXX_NAME=clang++ - - os: osx - osx_image: xcode9.3 + env: CC_NAME=clang-6.0 CXX_NAME=clang++-6.0 + #- os: osx + # osx_image: xcode9.3 before_install: - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker run -d --name ubuntu-test -v $(pwd):/travis ubuntu:latest tail -f /dev/null; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker run -d --name forge-pr -v $(pwd):/travis pradeepgarigipati/forge-ubuntu:bionic tail -f /dev/null; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker ps; fi install: - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker exec -t ubuntu-test bash -c "apt-get update && - apt-get install -y software-properties-common git python-minimal && - apt-get install -y build-essential cmake cmake-data libboost-thread-dev libboost-date-time-dev && - apt-get install -y libfontconfig1-dev libfreeimage-dev libfreetype6-dev && - apt-get install -y libglfw3-dev libglbinding-dev && - add-apt-repository -y ppa:ubuntu-toolchain-r/test && - apt-get update && - apt-get install -y $CC_NAME$VER_SUFFIX $CXX_NAME$VER_SUFFIX && - apt-get install -y opencl-headers && - apt-get install -y ocl-icd-opencl-dev && - cd /travis && - git clone --branch 0.9.7.6 https://github.com/g-truc/glm.git && - cd glm && cmake -DCMAKE_INSTALL_PREFIX=/travis/glm/package && make install;"; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install glfw glbinding fontconfig freeimage glm; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew upgrade boost; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew info cmake; fi +# - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install glfw glbinding fontconfig freeimage glm; fi +# - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew upgrade boost; fi +# - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew info cmake; fi script: - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker exec -t ubuntu-test bash -c "cd /travis; - export GLM_DIR=/travis/glm/package/lib/x86_64-linux-gnu/cmake/glm; - cmake -DCMAKE_C_COMPILER=$CC_NAME$VER_SUFFIX -DCMAKE_CXX_COMPILER=$CXX_NAME$VER_SUFFIX -Dglm_DIR=$GLM_DIR . && - make all"; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then cmake . -DCMAKE_INSTALL_PREFIX:PATH=`pwd`/package && make install; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker exec -t forge-pr bash -c "cd /travis; + CC=/usr/bin/$CC_NAME CXX=/usr/bin/$CXX_NAME cmake -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo . && + make -j2 install"; fi +# - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then cmake . -DCMAKE_INSTALL_PREFIX:PATH=`pwd`/package && make install; fi diff --git a/CMakeModules/FGInstallDirs.cmake b/CMakeModules/FGInstallDirs.cmake index d7148ed1..72cd6880 100644 --- a/CMakeModules/FGInstallDirs.cmake +++ b/CMakeModules/FGInstallDirs.cmake @@ -4,14 +4,20 @@ # NOTE: These paths are all relative to the project installation prefix. +include(GNUInstallDirs) + # Executables if(NOT DEFINED FG_INSTALL_BIN_DIR) - set(FG_INSTALL_BIN_DIR "bin" CACHE PATH "Installation path for executables") + set(FG_INSTALL_BIN_DIR "lib" CACHE PATH "Installation path for executables") endif() # Libraries if(NOT DEFINED FG_INSTALL_LIB_DIR) - set(FG_INSTALL_LIB_DIR "lib" CACHE PATH "Installation path for libraries") + if(WIN32) + set(FG_INSTALL_LIB_DIR "lib" CACHE PATH "Installation path for libraries") + else() + set(FG_INSTALL_LIB_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Installation path for libraries") + endif() endif() # Header files diff --git a/appveyor.yml b/appveyor.yml index 93fcec1d..9173ceba 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -65,14 +65,21 @@ image: environment: # 0-4 warning levels; 0 is no warnings MSBUILD_FLAGS: /maxcpucount - BOOST_ROOT: C:/Libraries/boost_1_65_1 + BOOST_ROOT: C:/Libraries/boost_1_67_0 matrix: - generator: "Visual Studio 14 2015 Win64" - generator: "Visual Studio 15 2017 Win64" install: - - ps: cd C:\Tools\vcpkg - - ps: vcpkg --triplet x64-windows install freeimage glbinding glfw3 glm opencl freetype + - ps: cd C:\ + - ps: if ( ! (Test-Path -Path "C:/vcpkg") ) { + git clone -q https://github.com/Microsoft/vcpkg.git; + cd .\vcpkg; + git checkout -q 4568b57ad7728f30c1e2badc9735c8990cd51265; + .\bootstrap-vcpkg.bat; + .\vcpkg integrate install; + vcpkg --triplet x64-windows install freeimage glbinding glfw3 glm opencl freetype + } # scripts that are called at very beginning, before repo cloning init: @@ -108,7 +115,8 @@ configuration: # - Release cache: - - C:\Tools\vcpkg\installed\ -> appveyor.yml + - C:/vcpkg/installed/ -> appveyor.yml + - C:/vcpkg/scripts/ -> appveyor.yml build: parallel: true # enable MSBuild parallel builds @@ -132,6 +140,6 @@ build_script: - cd %APPVEYOR_BUILD_FOLDER% - mkdir build - cd build - - cmake %APPVEYOR_BUILD_FOLDER% -G "%generator%" -DCMAKE_INSTALL_PREFIX=%APPVEYOR_BUILD_FOLDER%/build/package -DBOOST_ROOT="%BOOST_ROOT%" -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake -DFreeImage_ROOT="c:/tools/vcpkg/installed/x64-windows" + - cmake %APPVEYOR_BUILD_FOLDER% -G "%generator%" -DCMAKE_INSTALL_PREFIX=%APPVEYOR_BUILD_FOLDER%/build/package -DBOOST_ROOT="%BOOST_ROOT%" -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake -DFreeImage_ROOT="c:/vcpkg/installed/x64-windows" - cmake --build . --target ALL_BUILD --config %configuration% -- /nologo - cmake --build . --target INSTALL --config %configuration% -- /nologo diff --git a/src/backend/common/window.hpp b/src/backend/common/window.hpp index 55033c3e..1f492dec 100644 --- a/src/backend/common/window.hpp +++ b/src/backend/common/window.hpp @@ -92,7 +92,7 @@ class Window { } inline void makeCurrent() { - MakeContextCurrent(mWindow.get()); + mWindow->makeContextCurrent(); } inline void hide() { diff --git a/src/backend/opengl/CMakeLists.txt b/src/backend/opengl/CMakeLists.txt index 7bb954c1..1bfa44cd 100755 --- a/src/backend/opengl/CMakeLists.txt +++ b/src/backend/opengl/CMakeLists.txt @@ -37,8 +37,6 @@ target_sources(${BackendTarget} ${CMAKE_CURRENT_SOURCE_DIR}/colormap_impl.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common.hpp ${CMAKE_CURRENT_SOURCE_DIR}/common.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/err_opengl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/err_opengl.cpp ${CMAKE_CURRENT_SOURCE_DIR}/font_atlas_impl.hpp ${CMAKE_CURRENT_SOURCE_DIR}/font_atlas_impl.cpp ${CMAKE_CURRENT_SOURCE_DIR}/font_impl.hpp @@ -93,6 +91,7 @@ target_link_libraries(${BackendTarget} OpenGL::GL PRIVATE glbinding::glbinding + $<$>:glbinding::glbinding-aux> glm Freetype::Freetype Boost::boost @@ -145,7 +144,9 @@ if (WIN32) DESTINATION ${FG_INSTALL_BIN_DIR} COMPONENT dependencies) endif () - install(FILES $ + install(FILES + $ + $<$>:$> DESTINATION ${FG_INSTALL_BIN_DIR} COMPONENT dependencies) endif () diff --git a/src/backend/opengl/chart_impl.cpp b/src/backend/opengl/chart_impl.cpp index e1b10489..5fb163cb 100644 --- a/src/backend/opengl/chart_impl.cpp +++ b/src/backend/opengl/chart_impl.cpp @@ -10,7 +10,6 @@ #include #include -#include #include #include #include diff --git a/src/backend/opengl/common.cpp b/src/backend/opengl/common.cpp index 91ec4940..43f830dc 100644 --- a/src/backend/opengl/common.cpp +++ b/src/backend/opengl/common.cpp @@ -7,10 +7,14 @@ * http://arrayfire.com/licenses/BSD-3-Clause ********************************************************/ +#include #include #include #include +#ifndef NDEBUG +#include +#endif #include #include @@ -110,7 +114,15 @@ Shaders loadShaders(const char* pVertexShaderSrc, GLuint f, v; v = glCreateShader(GL_VERTEX_SHADER); + if (!v) { + std::cerr << "Vertex shader creation failed." << std::endl; + FG_COMPILE_LINK_ERROR(v, Shader); + } f = glCreateShader(GL_FRAGMENT_SHADER); + if (!f) { + std::cerr << "Fragment shader creation failed." << std::endl; + FG_COMPILE_LINK_ERROR(f, Shader); + } // load shaders & get length of each glShaderSource(v, 1, &pVertexShaderSrc, NULL); @@ -136,6 +148,10 @@ Shaders loadShaders(const char* pVertexShaderSrc, /* compile geometry shader if source provided */ if (pGeometryShaderSrc) { g = glCreateShader(GL_GEOMETRY_SHADER); + if (!g) { + std::cerr << "Geometry shader not compiled." << std::endl; + FG_COMPILE_LINK_ERROR(g, Shader); + } glShaderSource(g, 1, &pGeometryShaderSrc, NULL); glCompileShader(g); glGetShaderiv(g, GL_COMPILE_STATUS, &compiled); @@ -155,6 +171,23 @@ namespace forge namespace opengl { +void glErrorCheck(const char *pMsg, const char* pFile, int pLine) +{ +// Skipped in release mode +#ifndef NDEBUG + auto errorCheck = [](const char *pMsg, const char* pFile, int pLine) { + GLenum x = glGetError(); + if (x != GL_NO_ERROR) { + std::stringstream ss; + ss << "GL Error at: "<< pFile << ":"< #include #include -#pragma warning (push, 0) -#include +#include #include -#pragma warning (pop) #define GLM_FORCE_RADIANS #include @@ -156,6 +154,10 @@ namespace forge namespace opengl { +void glErrorCheck(const char *pMsg, const char* pFile, int pLine); + +#define CheckGL(msg) glErrorCheck(msg, __FILE__, __LINE__) + typedef unsigned int uint; typedef unsigned short ushort; typedef unsigned char uchar; diff --git a/src/backend/opengl/err_opengl.cpp b/src/backend/opengl/err_opengl.cpp deleted file mode 100644 index daee70e6..00000000 --- a/src/backend/opengl/err_opengl.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************* - * Copyright (c) 2015-2019, ArrayFire - * All rights reserved. - * - * This file is distributed under 3-clause BSD license. - * The complete license agreement can be obtained at: - * http://arrayfire.com/licenses/BSD-3-Clause - ********************************************************/ - -#include - -#include -#include - -#include -#include - -using namespace gl; - -namespace forge -{ -namespace opengl -{ - -void commonErrorCheck(const char *pMsg, const char* pFile, int pLine) -{ - GLenum x = glGetError(); - - if (x != GL_NO_ERROR) { - std::stringstream ss; - ss << "GL Error at: "<< pFile << ":"< - -namespace forge -{ -namespace opengl -{ - -void glErrorCheck(const char *pMsg, const char* pFile, int pLine); -void glForceErrorCheck(const char *pMsg, const char* pFile, int pLine); - -#define CheckGL(msg) glErrorCheck (msg, __FILE__, __LINE__) -#define ForceCheckGL(msg) glForceErrorCheck(msg, __FILE__, __LINE__) - -} -} diff --git a/src/backend/opengl/font_atlas_impl.cpp b/src/backend/opengl/font_atlas_impl.cpp index 40c3dd96..dbe933b1 100644 --- a/src/backend/opengl/font_atlas_impl.cpp +++ b/src/backend/opengl/font_atlas_impl.cpp @@ -53,7 +53,6 @@ #include #include -#include #include #include diff --git a/src/backend/opengl/font_impl.cpp b/src/backend/opengl/font_impl.cpp index d1ad8898..5040a5da 100644 --- a/src/backend/opengl/font_impl.cpp +++ b/src/backend/opengl/font_impl.cpp @@ -8,7 +8,6 @@ ********************************************************/ #include -#include #include #include #include diff --git a/src/backend/opengl/glfw/window.cpp b/src/backend/opengl/glfw/window.cpp index 5fb5a5da..d725b105 100644 --- a/src/backend/opengl/glfw/window.cpp +++ b/src/backend/opengl/glfw/window.cpp @@ -127,7 +127,8 @@ Widget::Widget() { } -Widget::Widget(int pWidth, int pHeight, const char* pTitle, const Widget* pWindow, const bool invisible) +Widget::Widget(int pWidth, int pHeight, const char* pTitle, + const std::unique_ptr &pWidget, const bool invisible) : mWindow(NULL), mClose(false), mLastXPos(0), mLastYPos(0), mButton(-1), mFramePBO(0) { auto wndErrCallback = [](int errCode, const char* pDescription) @@ -149,7 +150,7 @@ Widget::Widget(int pWidth, int pHeight, const char* pTitle, const Widget* pWindo glfwWindowHint(GLFW_SAMPLES, 4); mWindow = glfwCreateWindow(pWidth, pHeight, (pTitle!=nullptr ? pTitle : "Forge-Demo"), nullptr, - (pWindow!=nullptr ? pWindow->getNativeHandle(): nullptr)); + (pWidget ? pWidget->getNativeHandle(): nullptr)); if (!mWindow) { std::cerr<<"Error: Could not Create GLFW Window!\n"; @@ -220,6 +221,11 @@ long long Widget::getDisplayHandle() return opengl::getCurrentDisplayHandle(); } +glbinding::GetProcAddress Widget::getProcAddr() +{ + return glfwGetProcAddress; +} + void Widget::setTitle(const char* pTitle) { glfwSetWindowTitle(mWindow, (pTitle!=nullptr ? pTitle : "Forge-Demo")); diff --git a/src/backend/opengl/glfw/window.hpp b/src/backend/opengl/glfw/window.hpp index 389eaeb5..04e013f7 100644 --- a/src/backend/opengl/glfw/window.hpp +++ b/src/backend/opengl/glfw/window.hpp @@ -14,6 +14,8 @@ #include #include +#include + /* the short form wtk stands for * Windowing Tool Kit */ namespace forge @@ -60,7 +62,8 @@ class Widget { GLuint mFramePBO; /* Constructors and methods */ - Widget(int pWidth, int pHeight, const char* pTitle, const Widget* pWindow, const bool invisible); + Widget(int pWidth, int pHeight, const char* pTitle, + const std::unique_ptr &pWidget, const bool invisible); ~Widget(); @@ -72,6 +75,8 @@ class Widget { long long getDisplayHandle(); + glbinding::GetProcAddress getProcAddr(); + void setTitle(const char* pTitle); void setPos(int pX, int pY); diff --git a/src/backend/opengl/histogram_impl.cpp b/src/backend/opengl/histogram_impl.cpp index 9b640f16..d97f716c 100644 --- a/src/backend/opengl/histogram_impl.cpp +++ b/src/backend/opengl/histogram_impl.cpp @@ -8,7 +8,6 @@ ********************************************************/ #include -#include #include #include #include diff --git a/src/backend/opengl/image_impl.cpp b/src/backend/opengl/image_impl.cpp index cc631e5b..9c49058d 100644 --- a/src/backend/opengl/image_impl.cpp +++ b/src/backend/opengl/image_impl.cpp @@ -8,7 +8,6 @@ ********************************************************/ #include -#include #include #include #include diff --git a/src/backend/opengl/plot_impl.cpp b/src/backend/opengl/plot_impl.cpp index 464ad394..1414ff85 100644 --- a/src/backend/opengl/plot_impl.cpp +++ b/src/backend/opengl/plot_impl.cpp @@ -7,7 +7,6 @@ * http://arrayfire.com/licenses/BSD-3-Clause ********************************************************/ -#include #include #include #include diff --git a/src/backend/opengl/sdl/window.cpp b/src/backend/opengl/sdl/window.cpp index 8d1150d1..198fa178 100644 --- a/src/backend/opengl/sdl/window.cpp +++ b/src/backend/opengl/sdl/window.cpp @@ -124,7 +124,8 @@ Widget::Widget() { } -Widget::Widget(int pWidth, int pHeight, const char* pTitle, const Widget* pWindow, const bool invisible) +Widget::Widget(int pWidth, int pHeight, const char* pTitle, + const std::unique_ptr &pWidget, const bool invisible) : mWindow(nullptr), mClose(false), mLastXPos(0), mLastYPos(0), mButton(-1), mFramePBO(0) { SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); @@ -133,8 +134,8 @@ Widget::Widget(int pWidth, int pHeight, const char* pTitle, const Widget* pWindo SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); - if (pWindow != nullptr) { - pWindow->makeContextCurrent(); + if (pWidget) { + pWidget->makeContextCurrent(); SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); } else { //SDL_GL_MakeCurrent(NULL, NULL); @@ -169,8 +170,8 @@ Widget::~Widget() { glDeleteBuffers(1, &mFramePBO); - SDL_DestroyWindow(mWindow); SDL_GL_DeleteContext(mContext); + SDL_DestroyWindow(mWindow); } SDL_Window* Widget::getNativeHandle() const @@ -193,6 +194,16 @@ long long Widget::getDisplayHandle() return opengl::getCurrentDisplayHandle(); } +glbinding::GetProcAddress Widget::getProcAddr() +{ + using glbinding::GetProcAddress; + using glbinding::ProcAddress; + const GetProcAddress get_proc_address = [](const char *name) { + return reinterpret_cast(SDL_GL_GetProcAddress(name)); + }; + return get_proc_address; +} + void Widget::setTitle(const char* pTitle) { SDL_SetWindowTitle(mWindow, (pTitle!=nullptr ? pTitle : "Forge-Demo")); diff --git a/src/backend/opengl/sdl/window.hpp b/src/backend/opengl/sdl/window.hpp index d0a3412b..fd9d5710 100644 --- a/src/backend/opengl/sdl/window.hpp +++ b/src/backend/opengl/sdl/window.hpp @@ -13,6 +13,8 @@ #include #include +#include + /* the short form wtk stands for * Windowing Tool Kit */ namespace forge @@ -60,7 +62,8 @@ class Widget { uint mFramePBO; /* Constructors and methods */ - Widget(int pWidth, int pHeight, const char* pTitle, const Widget* pWindow, const bool invisible); + Widget(int pWidth, int pHeight, const char* pTitle, + const std::unique_ptr &pWidget, const bool invisible); ~Widget(); @@ -72,6 +75,8 @@ class Widget { long long getDisplayHandle(); + glbinding::GetProcAddress getProcAddr(); + bool getClose() const; void setTitle(const char* pTitle); diff --git a/src/backend/opengl/surface_impl.cpp b/src/backend/opengl/surface_impl.cpp index 8dff105f..a77d1009 100644 --- a/src/backend/opengl/surface_impl.cpp +++ b/src/backend/opengl/surface_impl.cpp @@ -8,7 +8,6 @@ ********************************************************/ #include -#include #include #include #include diff --git a/src/backend/opengl/update_buffer.cpp b/src/backend/opengl/update_buffer.cpp index bc6a3a1e..bddf4c34 100644 --- a/src/backend/opengl/update_buffer.cpp +++ b/src/backend/opengl/update_buffer.cpp @@ -9,7 +9,6 @@ #include #include -#include using namespace gl; diff --git a/src/backend/opengl/vector_field_impl.cpp b/src/backend/opengl/vector_field_impl.cpp index a93e63c9..3f34a492 100644 --- a/src/backend/opengl/vector_field_impl.cpp +++ b/src/backend/opengl/vector_field_impl.cpp @@ -7,7 +7,6 @@ * http://arrayfire.com/licenses/BSD-3-Clause ********************************************************/ -#include #include #include #include diff --git a/src/backend/opengl/window_impl.cpp b/src/backend/opengl/window_impl.cpp index 81e85210..718f83f3 100644 --- a/src/backend/opengl/window_impl.cpp +++ b/src/backend/opengl/window_impl.cpp @@ -11,7 +11,6 @@ // https://gist.github.com/SnopyDogy/a9a22497a893ec86aa3e #include -#include #include #include @@ -90,7 +89,7 @@ void initWtkIfNotDone() initCallCount++; - if (initCallCount==0) + if (initCallCount == 0) forge::wtk::initWindowToolkit(); } @@ -107,35 +106,30 @@ void destroyWtkIfDone() namespace opengl { -void MakeContextCurrent(const window_impl* pWindow) -{ - if (pWindow != NULL) { - pWindow->get()->makeContextCurrent(); - glbinding::Binding::useCurrentContext(); - } -} - window_impl::window_impl(int pWidth, int pHeight, const char* pTitle, std::weak_ptr pWindow, const bool invisible) : mID(getNextUniqueId()) { + using widget_ptr = std::unique_ptr; + initWtkIfNotDone(); if (auto observe = pWindow.lock()) { - mWindow = new wtk::Widget(pWidth, pHeight, pTitle, observe->get(), invisible); + mWidget = widget_ptr(new wtk::Widget(pWidth, pHeight, pTitle, + observe->get(), invisible)); } else { /* when windows are not sharing any context, just create * a dummy wtk::Widget object and pass it on */ - mWindow = new wtk::Widget(pWidth, pHeight, pTitle, nullptr, invisible); + mWidget = widget_ptr(new wtk::Widget(pWidth, pHeight, pTitle, + widget_ptr(), invisible)); } - /* Set context (before glewInit()) */ - MakeContextCurrent(this); - glbinding::Binding::useCurrentContext(); - glbinding::Binding::initialize(false); // lazy function pointer evaluation + mWidget->makeContextCurrent(); - mCxt = mWindow->getGLContextHandle(); - mDsp = mWindow->getDisplayHandle(); + glbinding::Binding::initialize(mWidget->getProcAddr(), false); + + mCxt = mWidget->getGLContextHandle(); + mDsp = mWidget->getDisplayHandle(); /* copy colormap shared pointer if * this window shares context with another window * */ @@ -145,15 +139,15 @@ window_impl::window_impl(int pWidth, int pHeight, const char* pTitle, mCMap = std::make_shared(); } - mWindow->resizePixelBuffers(); + mWidget->resizePixelBuffers(); /* set the colormap to default */ mColorMapUBO = mCMap->cmapUniformBufferId(FG_COLOR_MAP_DEFAULT); mUBOSize = mCMap->cmapLength(FG_COLOR_MAP_DEFAULT); glEnable(GL_MULTISAMPLE); - mWindow->resetViewMatrices(); - mWindow->resetOrientationMatrices(); + mWidget->resetViewMatrices(); + mWidget->resetOrientationMatrices(); /* setup default window font */ mFont = std::make_shared(); @@ -169,10 +163,15 @@ window_impl::window_impl(int pWidth, int pHeight, const char* pTitle, window_impl::~window_impl() { - delete mWindow; destroyWtkIfDone(); } +void window_impl::makeContextCurrent() +{ + mWidget->makeContextCurrent(); + glbinding::Binding::useCurrentContext(); +} + void window_impl::setFont(const std::shared_ptr& pFont) { mFont = pFont; @@ -180,17 +179,17 @@ void window_impl::setFont(const std::shared_ptr& pFont) void window_impl::setTitle(const char* pTitle) { - mWindow->setTitle(pTitle); + mWidget->setTitle(pTitle); } void window_impl::setPos(int pX, int pY) { - mWindow->setPos(pX, pY); + mWidget->setPos(pX, pY); } void window_impl::setSize(unsigned pW, unsigned pH) { - mWindow->setSize(pW, pH); + mWidget->setSize(pW, pH); } void window_impl::setColorMap(forge::ColorMap cmap) @@ -217,17 +216,17 @@ long long window_impl::display() const int window_impl::width() const { - return mWindow->mWidth; + return mWidget->mWidth; } int window_impl::height() const { - return mWindow->mHeight; + return mWidget->mHeight; } -const wtk::Widget* window_impl::get() const +const std::unique_ptr& window_impl::get() const { - return mWindow; + return mWidget; } const std::shared_ptr& window_impl::colorMapPtr() const @@ -237,28 +236,28 @@ const std::shared_ptr& window_impl::colorMapPtr() const void window_impl::hide() { - mWindow->hide(); + mWidget->hide(); } void window_impl::show() { - mWindow->show(); + mWidget->show(); } bool window_impl::close() { - return mWindow->close(); + return mWidget->close(); } void window_impl::draw(const std::shared_ptr& pRenderable) { CheckGL("Begin window_impl::draw"); - MakeContextCurrent(this); - mWindow->resetCloseFlag(); - glViewport(0, 0, mWindow->mWidth, mWindow->mHeight); + makeContextCurrent(); + mWidget->resetCloseFlag(); + glViewport(0, 0, mWidget->mWidth, mWidget->mHeight); - const glm::mat4& viewMatrix = mWindow->getViewMatrix(std::make_tuple(1, 1, 0)); - const glm::mat4& orientMatrix = mWindow->getOrientationMatrix(std::make_tuple(1, 1, 0)); + const glm::mat4& viewMatrix = mWidget->getViewMatrix(std::make_tuple(1, 1, 0)); + const glm::mat4& orientMatrix = mWidget->getOrientationMatrix(std::make_tuple(1, 1, 0)); // clear color and depth buffers glClearColor(WHITE[0], WHITE[1], WHITE[2], WHITE[3]); @@ -266,11 +265,11 @@ void window_impl::draw(const std::shared_ptr& pRenderable) // set colormap call is equivalent to noop for non-image renderables pRenderable->setColorMapUBOParams(mColorMapUBO, mUBOSize); - pRenderable->render(mID, 0, 0, mWindow->mWidth, mWindow->mHeight, + pRenderable->render(mID, 0, 0, mWidget->mWidth, mWidget->mHeight, viewMatrix, orientMatrix); - mWindow->swapBuffers(); - mWindow->pollEvents(); + mWidget->swapBuffers(); + mWidget->pollEvents(); CheckGL("End window_impl::draw"); } @@ -279,19 +278,19 @@ void window_impl::draw(const int pRows, const int pCols, const int pIndex, const char* pTitle) { CheckGL("Begin draw(rows, columns, index)"); - MakeContextCurrent(this); - mWindow->resetCloseFlag(); + makeContextCurrent(); + mWidget->resetCloseFlag(); - const int cellWidth = mWindow->mWidth/pCols; - const int cellHeight = mWindow->mHeight/pRows; + const int cellWidth = mWidget->mWidth/pCols; + const int cellHeight = mWidget->mHeight/pRows; int c = pIndex % pCols; int r = pIndex / pCols; int xOff = c * cellWidth; int yOff = (pRows-1-r) * cellHeight; - const glm::mat4& viewMatrix = mWindow->getViewMatrix(std::make_tuple(pRows, pCols, pIndex)); - const glm::mat4& orientMatrix = mWindow->getOrientationMatrix(std::make_tuple(pRows, pCols, pIndex)); + const glm::mat4& viewMatrix = mWidget->getViewMatrix(std::make_tuple(pRows, pCols, pIndex)); + const glm::mat4& orientMatrix = mWidget->getOrientationMatrix(std::make_tuple(pRows, pCols, pIndex)); /* following margins are tested out for various * aspect ratios and are working fine. DO NOT CHANGE. @@ -330,8 +329,8 @@ void window_impl::draw(const int pRows, const int pCols, const int pIndex, void window_impl::swapBuffers() { - mWindow->swapBuffers(); - mWindow->pollEvents(); + mWidget->swapBuffers(); + mWidget->pollEvents(); // clear color and depth buffers glClearColor(WHITE[0], WHITE[1], WHITE[2], WHITE[3]); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -360,8 +359,8 @@ void window_impl::saveFrameBuffer(const char* pFullPath) FG_ERROR("Supports only bmp and png as of now", FG_ERR_FREEIMAGE_SAVE_FAILED); } - uint w = mWindow->mWidth; - uint h = mWindow->mHeight; + uint w = mWidget->mWidth; + uint h = mWidget->mHeight; uint c = 4; uint d = c * 8; @@ -379,14 +378,14 @@ void window_impl::saveFrameBuffer(const char* pFullPath) * it was async call(which it should be unless vendor driver * is doing something fishy) and the transfer is over by now * */ - glBindBuffer(GL_PIXEL_PACK_BUFFER, mWindow->mFramePBO); + glBindBuffer(GL_PIXEL_PACK_BUFFER, mWidget->mFramePBO); uchar* src = (uchar*)glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY); if (src) { // copy data from mapped memory location - uint w = mWindow->mWidth; - uint h = mWindow->mHeight; + uint w = mWidget->mWidth; + uint h = mWidget->mHeight; uint i = 0; for (uint y = 0; y < h; ++y) { diff --git a/src/backend/opengl/window_impl.hpp b/src/backend/opengl/window_impl.hpp index b9adcd4b..3d8910e3 100644 --- a/src/backend/opengl/window_impl.hpp +++ b/src/backend/opengl/window_impl.hpp @@ -34,7 +34,7 @@ class window_impl { long long mCxt; long long mDsp; int mID; - wtk::Widget* mWindow; + std::unique_ptr mWidget; std::shared_ptr mFont; std::shared_ptr mCMap; @@ -48,6 +48,7 @@ class window_impl { ~window_impl(); + void makeContextCurrent(); void setFont(const std::shared_ptr& pFont); void setTitle(const char* pTitle); void setPos(int pX, int pY); @@ -59,7 +60,7 @@ class window_impl { long long display() const; int width() const; int height() const; - const wtk::Widget* get() const; + const std::unique_ptr& get() const; const std::shared_ptr& colorMapPtr() const; void hide(); @@ -77,7 +78,5 @@ class window_impl { void saveFrameBuffer(const char* pFullPath); }; -void MakeContextCurrent(const window_impl* pWindow); - } }