diff --git a/Application/CMakeLists.txt b/Application/CMakeLists.txt index 930489d1816b6e775c440c0f2e51e11d240115eb..6bf4daa45628d7f82312d3ed571e3962e8988571 100644 --- a/Application/CMakeLists.txt +++ b/Application/CMakeLists.txt @@ -84,6 +84,19 @@ else() set(BUILD_SHARED_LIBS OFF) endif() +if(TREX_BUILD_GLFW OR UNIX) + if(WIN32) + find_package(OpenGL REQUIRED) + message(STATUS "OpenGL library ${OPENGL_LIBRARY}") + elseif(UNIX AND NOT APPLE) + find_package(OpenGL REQUIRED) + SET(OPENGL_LIBRARY OpenGL::GL) + message(STATUS "OpenGL library ${OPENGL_LIBRARY}") + else() + find_library(OPENGL_LIBRARY OpenGL) + endif() +endif() + if(APPLE) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-undefined,error -framework IOKit -framework CoreFoundation -framework CoreGraphics -framework CoreVideo -framework OpenCL -framework Cocoa -framework AppKit -framework AVKit -framework AVFoundation -framework CoreMedia -framework QuartzCore -framework Accelerate") @@ -368,6 +381,7 @@ if(CMN_USE_OPENGL2) else() set(GLAD_PROFILE "core") set(GLAD_API "gl=4.1") + add_definitions(-DCMN_USE_OPENGL2=false) endif() ExternalProject_Add(gladex PREFIX gladex @@ -396,9 +410,8 @@ file(GLOB imgui_sources ${imgui_path}/*.cpp ${imgui_path}/*.h ${imgui_path}/examples/imgui_impl_glfw*.cpp ${imgui_path}/examples/imgui_impl_glfw*.h ) -if(CMN_USE_OPENGL2) - set(imgui_sources ${imgui_sources} ${imgui_path}/examples/imgui_impl_opengl2.cpp ${imgui_path}/examples/imgui_impl_opengl2.h) -else() +set(imgui_sources ${imgui_sources} ${imgui_path}/examples/imgui_impl_opengl2.cpp ${imgui_path}/examples/imgui_impl_opengl2.h) +if(NOT CMN_USE_OPENGL2) set(imgui_sources ${imgui_sources} ${imgui_path}/examples/imgui_impl_opengl3.cpp ${imgui_path}/examples/imgui_impl_opengl3.h) endif() @@ -950,19 +963,6 @@ foreach(dir ${dirs}) message(STATUS "dir='${dir}'") endforeach() -if(TREX_BUILD_GLFW OR UNIX) - if(WIN32) - find_package(OpenGL REQUIRED) - message(STATUS "OpenGL library ${OPENGL_LIBRARY}") - elseif(UNIX AND NOT APPLE) - find_package(OpenGL REQUIRED) - SET(OPENGL_LIBRARY OpenGL::GL) - message(STATUS "OpenGL library ${OPENGL_LIBRARY}") - else() - find_library(OPENGL_LIBRARY OpenGL) - endif() -endif() - add_subdirectory(src) diff --git a/Application/src/commons/common/gui/GLImpl.cpp b/Application/src/commons/common/gui/GLImpl.cpp index d8f616bc92c8b253a64f823ba9f68b2ee191fa4f..c5b88a4f63e7be7abcb0aa886cc129bdde38a1bd 100644 --- a/Application/src/commons/common/gui/GLImpl.cpp +++ b/Application/src/commons/common/gui/GLImpl.cpp @@ -4,13 +4,11 @@ #include <imgui/imgui.h> #include <imgui/examples/imgui_impl_glfw.h> -#ifdef CMN_USE_OPENGL2 #include <imgui/examples/imgui_impl_opengl2.h> using ImTextureID_t = ImGui_OpenGL2_TextureID; -#else + #include <imgui/examples/imgui_impl_opengl3.h> -using ImTextureID_t = ImGui_OpenGL3_TextureID; -#endif +//using ImTextureID_t = ImGui_OpenGL3_TextureID; #if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) #include <GL/gl3w.h> // Initialize with gl3wInit() @@ -22,9 +20,26 @@ using ImTextureID_t = ImGui_OpenGL3_TextureID; #include IMGUI_IMPL_OPENGL_LOADER_CUSTOM #endif -#ifndef CMN_USE_OPENGL2 -#define GLFW_INCLUDE_GL3 /* don't drag in legacy GL headers. */ +#ifndef GL_VERSION_3_2 +#define OPENGL3_CONDITION (false) +#else +#define OPENGL3_CONDITION (!CMN_USE_OPENGL2 && ((GLVersion.major == 3 && GLVersion.minor >= 2) || (GLVersion.major > 3))) +#endif + +#ifndef GL_PIXEL_PACK_BUFFER +#define GL_PIXEL_PACK_BUFFER 0 +#endif +#ifndef GL_RG +#define GL_RG 0 +#endif +#ifndef GL_RG8 +#define GL_RG8 0 #endif +#ifndef GL_TEXTURE_SWIZZLE_RGBA +#define GL_TEXTURE_SWIZZLE_RGBA 0 +#endif + +//#define GLFW_INCLUDE_GL3 /* don't drag in legacy GL headers. */ #define GLFW_NO_GLU /* don't drag in the old GLU lib - unless you must. */ #include <GLFW/glfw3.h> @@ -62,11 +77,10 @@ void GLImpl::init() { } void GLImpl::post_init() { -#ifdef CMN_USE_OPENGL2 - ImGui_ImplOpenGL2_NewFrame(); -#else - ImGui_ImplOpenGL3_NewFrame(); // load the font texture before anything else is done in the program -#endif + if OPENGL3_CONDITION { + ImGui_ImplOpenGL3_NewFrame(); + } else + ImGui_ImplOpenGL2_NewFrame(); } void GLImpl::set_icons(const std::vector<file::Path>& icons) { @@ -100,26 +114,24 @@ void GLImpl::set_icons(const std::vector<file::Path>& icons) { void GLImpl::create_window(int width, int height) { #if __APPLE__ -#ifdef CMN_USE_OPENGL2 - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); -#else // GL 3.2 + GLSL 150 const char* glsl_version = "#version 150"; - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); + +#if !CMN_USE_OPENGL2 + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac -#endif + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac #else -#ifdef CMN_USE_OPENGL2 - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); +#endif + #else // GL 3.0 + GLSL 130 const char* glsl_version = "#version 130"; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); -#endif glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // 3.0+ only @@ -147,16 +159,21 @@ void GLImpl::create_window(int width, int height) { U_EXCEPTION("Failed to initialize OpenGL loader!"); } + if OPENGL3_CONDITION + Debug("Using OpenGL3.2 (seems supported, %s).", glGetString(GL_VERSION)); + else + Debug("Using OpenGL2.0 (%s)", glGetString(GL_VERSION)); + IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; ImGui_ImplGlfw_InitForOpenGL(window, true); -#ifdef CMN_USE_OPENGL2 - ImGui_ImplOpenGL2_Init(); -#else - ImGui_ImplOpenGL3_Init(glsl_version); -#endif + + if OPENGL3_CONDITION + ImGui_ImplOpenGL3_Init(glsl_version); + else + ImGui_ImplOpenGL2_Init(); } GLFWwindow* GLImpl::window_handle() { @@ -180,11 +197,10 @@ LoopStatus GLImpl::update_loop() { _texture_updates.clear(); } -#ifdef CMN_USE_OPENGL2 - ImGui_ImplOpenGL2_NewFrame(); -#else - ImGui_ImplOpenGL3_NewFrame(); -#endif + if OPENGL3_CONDITION + ImGui_ImplOpenGL3_NewFrame(); + else + ImGui_ImplOpenGL2_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); @@ -202,18 +218,17 @@ LoopStatus GLImpl::update_loop() { glClearColor(_clear_color.r / 255.f, _clear_color.g / 255.f, _clear_color.b / 255.f, _clear_color.a / 255.f); glClear(GL_COLOR_BUFFER_BIT); -#ifdef CMN_USE_OPENGL2 - ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData()); -#else - ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); -#endif + if OPENGL3_CONDITION { + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + } else { + ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData()); + } if(_frame_capture_enabled) update_pbo(); -#ifdef CMN_USE_OPENGL2 - glfwMakeContextCurrent(window); -#endif + if(!OPENGL3_CONDITION) + glfwMakeContextCurrent(window); glfwSwapBuffers(window); ++draw_calls; @@ -232,55 +247,55 @@ LoopStatus GLImpl::update_loop() { void GLImpl::init_pbo(uint width, uint height) { if(!pboImage || pboImage->cols != width || pboImage->rows != height) { -#ifndef CMN_USE_OPENGL2 - if(pboImage) { - glDeleteBuffers(2, pboIds); - } - - pboImage = std::make_shared<Image>(height, width, 4); - pboOutput = std::make_shared<Image>(height, width, 4); - - glGenBuffers(2, pboIds); - auto nbytes = width * height * 4; - for(int i=0; i<2; ++i) { - glBindBuffer(GL_PIXEL_PACK_BUFFER, pboIds[i]); - glBufferData(GL_PIXEL_PACK_BUFFER, nbytes, NULL, GL_STREAM_READ); + if OPENGL3_CONDITION { + if(pboImage) { + glDeleteBuffers(2, pboIds); + } + + pboImage = std::make_shared<Image>(height, width, 4); + pboOutput = std::make_shared<Image>(height, width, 4); + + glGenBuffers(2, pboIds); + auto nbytes = width * height * 4; + for(int i=0; i<2; ++i) { + glBindBuffer(GL_PIXEL_PACK_BUFFER, pboIds[i]); + glBufferData(GL_PIXEL_PACK_BUFFER, nbytes, NULL, GL_STREAM_READ); + } + glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); } - glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); -#endif } } void GLImpl::update_pbo() { -#ifndef CMN_USE_OPENGL2 - // "index" is used to read pixels from framebuffer to a PBO - // "nextIndex" is used to update pixels in the other PBO - index = (index + 1) % 2; - nextIndex = (index + 1) % 2; - - // set the target framebuffer to read - glReadBuffer(GL_BACK); - - // read pixels from framebuffer to PBO - // glReadPixels() should return immediately. - glBindBuffer(GL_PIXEL_PACK_BUFFER, pboIds[index]); - glReadPixels(0, 0, pboImage->cols, pboImage->rows, GL_BGRA, GL_UNSIGNED_BYTE, 0); - - // map the PBO to process its data by CPU - glBindBuffer(GL_PIXEL_PACK_BUFFER, pboIds[nextIndex]); - GLubyte* ptr = (GLubyte*)glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY); - if(ptr) - { - memcpy(pboImage->data(), ptr, pboImage->size()); - glUnmapBuffer(GL_PIXEL_PACK_BUFFER); - - // flip vertically - cv::flip(pboImage->get(), pboOutput->get(), 0); - } + if OPENGL3_CONDITION { + // "index" is used to read pixels from framebuffer to a PBO + // "nextIndex" is used to update pixels in the other PBO + index = (index + 1) % 2; + nextIndex = (index + 1) % 2; + + // set the target framebuffer to read + glReadBuffer(GL_BACK); + + // read pixels from framebuffer to PBO + // glReadPixels() should return immediately. + glBindBuffer(GL_PIXEL_PACK_BUFFER, pboIds[index]); + glReadPixels(0, 0, pboImage->cols, pboImage->rows, GL_BGRA, GL_UNSIGNED_BYTE, 0); + + // map the PBO to process its data by CPU + glBindBuffer(GL_PIXEL_PACK_BUFFER, pboIds[nextIndex]); + GLubyte* ptr = (GLubyte*)glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY); + if(ptr) + { + memcpy(pboImage->data(), ptr, pboImage->size()); + glUnmapBuffer(GL_PIXEL_PACK_BUFFER); + + // flip vertically + cv::flip(pboImage->get(), pboOutput->get(), 0); + } - // back to conventional pixel operation - glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); -#endif + // back to conventional pixel operation + glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); + } } void GLImpl::loop(CrossPlatform::custom_function_t custom_loop) { @@ -300,11 +315,11 @@ GLImpl::~GLImpl() { glDeleteBuffers(2, pboIds); // Cleanup -#ifdef CMN_USE_OPENGL2 - ImGui_ImplOpenGL2_Shutdown(); -#else - ImGui_ImplOpenGL3_Shutdown(); -#endif + if OPENGL3_CONDITION + ImGui_ImplOpenGL3_Shutdown(); + else + ImGui_ImplOpenGL2_Shutdown(); + ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); @@ -348,30 +363,37 @@ TexturePtr GLImpl::texture(const Image * ptr) { glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glPixelStorei(GL_UNPACK_ALIGNMENT, ptr->dims != 4 ? ptr->dims : 0); -#ifdef CMN_USE_OPENGL2 - auto output_type = GL_RGBA, input_type = GL_RGBA; - if(ptr->dims == 1) { - output_type = GL_LUMINANCE; - input_type = GL_LUMINANCE; - } - if(ptr->dims == 2) { - output_type = GL_LUMINANCE_ALPHA; - input_type = GL_LUMINANCE_ALPHA; - } -#else +#if !CMN_USE_OPENGL2 +#define GL_LUMINANCE 0x1909 +#define GL_LUMINANCE_ALPHA 0x190A +#endif + auto output_type = GL_RGBA8, input_type = GL_RGBA; - if(ptr->dims == 1) { - output_type = GL_RED; - input_type = GL_RED; - } - if(ptr->dims == 2) { - output_type = GL_RG8; - input_type = GL_RG; + if OPENGL3_CONDITION { + if(ptr->dims == 1) { + output_type = GL_RED; + input_type = GL_RED; + } + if(ptr->dims == 2) { + output_type = GL_RG8; + input_type = GL_RG; + + GLint swizzleMask[] = {GL_RED, GL_ZERO, GL_ZERO, GL_GREEN}; + glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); + } + + } else { + output_type = GL_RGBA; - GLint swizzleMask[] = {GL_RED, GL_ZERO, GL_ZERO, GL_GREEN}; - glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); + if(ptr->dims == 1) { + output_type = GL_LUMINANCE; + input_type = GL_LUMINANCE; + } + if(ptr->dims == 2) { + output_type = GL_LUMINANCE_ALPHA; + input_type = GL_LUMINANCE_ALPHA; + } } -#endif auto width = next_pow2(ptr->cols), height = next_pow2(ptr->rows); auto capacity = size_t(ptr->dims) * size_t(width) * size_t(height); @@ -441,23 +463,23 @@ void GLImpl::update_texture(PlatformTexture& id_, const Image *ptr) { glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glPixelStorei(GL_UNPACK_ALIGNMENT, ptr->dims != 4 ? ptr->dims : 0); -#ifdef CMN_USE_OPENGL2 auto input_type = GL_RGBA; - if(ptr->dims == 1) { - input_type = GL_LUMINANCE; - } - if(ptr->dims == 2) { - input_type = GL_LUMINANCE_ALPHA; - } -#else - auto input_type = GL_RGBA; - if(ptr->dims == 1) { - input_type = GL_RED; - } - if(ptr->dims == 2) { - input_type = GL_RG; + if OPENGL3_CONDITION { + if(ptr->dims == 1) { + input_type = GL_RED; + } + if(ptr->dims == 2) { + input_type = GL_RG; + } + + } else { + if(ptr->dims == 1) { + input_type = GL_LUMINANCE; + } + if(ptr->dims == 2) { + input_type = GL_LUMINANCE_ALPHA; + } } -#endif auto capacity = size_t(ptr->dims) * size_t(id_.width) * size_t(id_.height); if (empty.size() < capacity) diff --git a/Application/src/grabber/tgrabs.cpp b/Application/src/grabber/tgrabs.cpp index 8fe4edbe351b80474e1532c8007a89b4c6df0da1..dcefa7573bd12c2e69a7f20ac8ff156461f44a56 100644 --- a/Application/src/grabber/tgrabs.cpp +++ b/Application/src/grabber/tgrabs.cpp @@ -74,11 +74,11 @@ int main(int argc, char** argv) { } #if __APPLE__ - ss << "open '"; + ss << ""; #endif ss << target_path; #if __APPLE__ - ss << "TGrabs.app' --args"; + ss << "TGrabs.app/Contents/MacOS/TGrabs"; #else U_EXCEPTION("Only Apple is supported."); #endif diff --git a/Application/src/tracker/trex.cpp b/Application/src/tracker/trex.cpp index c8e2e1f9617488cda9f8a9fc67c498792400217d..ce22e73c1b89557809a2eebc8e707856329013d2 100644 --- a/Application/src/tracker/trex.cpp +++ b/Application/src/tracker/trex.cpp @@ -72,11 +72,11 @@ int main(int argc, char** argv) { } #if __APPLE__ - ss << "open '"; + ss << ""; #endif ss << target_path; #if __APPLE__ - ss << "TRex.app' --args"; + ss << "TRex.app/Contents/MacOS/TRex"; #else U_EXCEPTION("Only apple supported."); #endif diff --git a/conda/build.sh b/conda/build.sh index 3cc76526bb35c4f587d035e01b7ee0cd083555db..2a0a1de74dabaaccd4c67d76ff0bf52a6f822dc8 100755 --- a/conda/build.sh +++ b/conda/build.sh @@ -11,6 +11,7 @@ if [ "$(uname)" == "Linux" ]; then # Fix up CMake for using conda's sysroot # See https://docs.conda.io/projects/conda-build/en/latest/resources/compiler-tools.html?highlight=cmake#an-aside-on-cmake-and-sysroots CMAKE_PLATFORM_FLAGS+=("-DCMAKE_TOOLCHAIN_FILE=${RECIPE_DIR}/conda_sysroot.cmake") + BUILD_GLFW="ON" else echo "CONDA_BUILD_SYSROOT=$CONDA_BUILD_SYSROOT. forcing it." export CONDA_BUILD_SYSROOT="/opt/MacOSX10.9.sdk" @@ -34,6 +35,7 @@ PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig;${BUILD_PREFIX}/${HOST}/sysroot/usr/lib -DTREX_BUILD_ZIP=ON \ -DTREX_CONDA_PACKAGE_INSTALL=ON \ -DTREX_DONT_USE_PCH=ON \ + -DCMN_USE_OPENGL2=OFF \ -DTREX_WITH_TESTS=OFF \ -DCMAKE_PREFIX_PATH=$PREFIX \ -DCMAKE_INSTALL_RPATH_USE_LINK_PATH:BOOL=TRUE \ diff --git a/conda/meta.yaml b/conda/meta.yaml index 7da31899ccef9ea0a1d095bd00dd7508fd82390a..48a9d3d0d09bac20cda4390270bcc36237d34f93 100644 --- a/conda/meta.yaml +++ b/conda/meta.yaml @@ -1,10 +1,11 @@ package: name: trex - version: "1.0" + version: "1.0.1" source: git_url: https://github.com/mooch443/trex.git git_depth: 1 + git_rev: 6fd5efeb4733c7ad2f83fdae0b86fb3f4aef1894 build: number: 4 @@ -32,11 +33,15 @@ requirements: - pkg-config # [not win] - jom # [win] - make # [unix] - - python [win] - - python =3.6 [not win] + - python # [win] + - python =3.6 # [not win] - {{ compiler('c') }} - {{ compiler('cxx') }} - cmake >=3.14 + - xorg-libxcursor # [linux] + - xorg-libx11 # [linux] + - xorg-libxrandr # [linux] + - xorg-libxinerama # [linux] - {{ cdt('mesa-libgl-devel') }} # [linux] - {{ cdt('mesa-dri-drivers') }} # [linux] - {{ cdt('libselinux') }} # [linux] @@ -64,24 +69,22 @@ requirements: host: - pthread-stubs # [linux] - - ffmpeg [win] - - python [win] - - ffmpeg ==4.0 [not win] - - python =3.6 [not win] - - glfw [linux] - - nomkl [osx] + - ffmpeg # [win] + - python # [win] + - ffmpeg ==4.0 # [not win] + - python =3.6 # [not win] + - nomkl # [osx] run: - - tensorflow-gpu ==1.13.* [not osx] - - tensorflow ==1.13.* [osx] + - tensorflow-gpu ==1.13.* # [not osx] + - tensorflow ==1.13.* # [osx] - keras - - ffmpeg [win] - - python [win] - - ffmpeg ==4.0 [not win] - - python =3.6 [not win] - - glfw [linux] - - nomkl [osx] - - xorg-libx11 [linux] + - ffmpeg # [win] + - python # [win] + - ffmpeg ==4.0 # [not win] + - python =3.6 # [not win] + - nomkl # [osx] + - xorg-libx11 # [linux] about: home: https://trex.run