Skip to content

Commit c5953c0

Browse files
committed
viewer: replace GLEW with GLAD
1 parent 8dc7418 commit c5953c0

File tree

10 files changed

+27
-65
lines changed

10 files changed

+27
-65
lines changed

CMakeLists.txt

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,27 @@
33
########################################################################
44
#
55
# Project-wide settings
6-
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
6+
CMAKE_MINIMUM_REQUIRED(VERSION 3.18)
77
IF(POLICY CMP0011)
8+
# Included scripts do automatic cmake_policy() PUSH and POP.
89
CMAKE_POLICY(SET CMP0011 NEW)
910
ENDIF()
10-
IF(POLICY CMP0072)
11-
CMAKE_POLICY(SET CMP0072 NEW)
12-
ENDIF()
1311
IF(POLICY CMP0074)
12+
# find_package() uses <PackageName>_ROOT variables.
1413
CMAKE_POLICY(SET CMP0074 NEW)
1514
ENDIF()
1615
IF(POLICY CMP0104)
16+
# Initialize CMAKE_CUDA_ARCHITECTURES when CMAKE_CUDA_COMPILER_ID is NVIDIA. Raise an error if CUDA_ARCHITECTURES is empty.
1717
CMAKE_POLICY(SET CMP0104 NEW)
1818
ENDIF()
1919
IF(POLICY CMP0146)
20-
CMAKE_POLICY(SET CMP0146 OLD) # not required, but forced by OpenCV old support for CUDA
20+
# Use CMake's first-class CUDA language support instead of FindCUDA().
21+
# note: not required, but forced by OpenCV old support for CUDA
22+
CMAKE_POLICY(SET CMP0146 OLD)
23+
ENDIF()
24+
IF(POLICY CMP0167)
25+
# The FindBoost module is removed.
26+
CMAKE_POLICY(SET CMP0167 NEW)
2127
ENDIF()
2228

2329
# List configuration options
@@ -100,17 +106,6 @@ if(OpenMVS_USE_OPENMP)
100106
endif()
101107
endif()
102108

103-
if(OpenMVS_USE_OPENGL)
104-
FIND_PACKAGE(OpenGL)
105-
if(OPENGL_FOUND)
106-
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
107-
ADD_DEFINITIONS(${OpenGL_DEFINITIONS})
108-
SET(_USE_OPENGL TRUE)
109-
else()
110-
MESSAGE("-- Can't find OpenGL. Continuing without it.")
111-
endif()
112-
endif()
113-
114109
if(OpenMVS_USE_CUDA)
115110
INCLUDE(CheckLanguage)
116111
CHECK_LANGUAGE(CUDA)
@@ -208,10 +203,6 @@ if(Boost_FOUND)
208203
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
209204
ADD_DEFINITIONS(${Boost_DEFINITIONS})
210205
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
211-
if(NOT MSVC AND DEFINED CMAKE_TOOLCHAIN_FILE)
212-
# work around this missing library link in vcpkg
213-
LIST(APPEND Boost_LIBRARIES zstd)
214-
endif()
215206
SET(_USE_BOOST TRUE)
216207
if(OpenMVS_USE_PYTHON AND Boost_${Boost_EXTRA_COMPONENTS}_FOUND)
217208
SET(_USE_BOOST_PYTHON TRUE)

apps/Viewer/CMakeLists.txt

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
1-
if((NOT OpenMVS_USE_OPENGL) OR (NOT _USE_OPENGL))
2-
RETURN()
3-
endif()
4-
51
if(NOT VIEWER_NAME)
62
set(VIEWER_NAME "Viewer")
73
endif()
84

95
# Find required packages
10-
FIND_PACKAGE(GLEW QUIET)
11-
if(GLEW_FOUND)
12-
INCLUDE_DIRECTORIES(${GLEW_INCLUDE_DIRS})
13-
ADD_DEFINITIONS(${GLEW_DEFINITIONS})
14-
MESSAGE(STATUS "GLEW ${GLEW_VERSION} found (include: ${GLEW_INCLUDE_DIRS})")
6+
FIND_PACKAGE(glad QUIET)
7+
if(glad_FOUND)
8+
MESSAGE(STATUS "GLAD ${glad_VERSION} found")
159
else()
16-
MESSAGE("-- Can't find GLEW. Continuing without it.")
10+
MESSAGE("-- Can't find GLAD. Continuing without it.")
1711
RETURN()
1812
endif()
1913
FIND_PACKAGE(glfw3 QUIET)
2014
if(glfw3_FOUND)
21-
INCLUDE_DIRECTORIES(${glfw3_INCLUDE_DIRS})
22-
ADD_DEFINITIONS(${glfw3_DEFINITIONS})
23-
MESSAGE(STATUS "GLFW3 ${glfw3_VERSION} found (include: ${glfw3_INCLUDE_DIRS})")
15+
MESSAGE(STATUS "GLFW3 ${glfw3_VERSION} found")
2416
else()
2517
MESSAGE("-- Can't find GLFW3. Continuing without it.")
2618
RETURN()
@@ -35,7 +27,7 @@ else()
3527
endif()
3628
FILE(GLOB LIBRARY_FILES_H "*.h" "*.inl")
3729

38-
cxx_executable_with_flags(${VIEWER_NAME} "Apps" "${cxx_default}" "MVS;${OPENGL_LIBRARIES};${GLEW_LIBRARY};${GLFW_STATIC_LIBRARIES};GLEW::GLEW;${glfw3_LIBRARY};${GLFW3_LIBRARY};glfw;${OpenMVS_EXTRA_LIBS}" ${LIBRARY_FILES_C} ${LIBRARY_FILES_H})
30+
cxx_executable_with_flags(${VIEWER_NAME} "Apps" "${cxx_default}" "MVS;glad::glad;${GLFW_STATIC_LIBRARIES};${glfw3_LIBRARY};${GLFW3_LIBRARY};glfw;${OpenMVS_EXTRA_LIBS}" ${LIBRARY_FILES_C} ${LIBRARY_FILES_H})
3931

4032
# Manually set Common.h as the precompiled header
4133
IF(CMAKE_VERSION VERSION_GREATER_EQUAL 3.16.0)

apps/Viewer/Common.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,12 @@
3535

3636
// I N C L U D E S /////////////////////////////////////////////////
3737

38-
#include <GL/glew.h>
3938
#include "../../libs/MVS/Common.h"
4039
#include "../../libs/MVS/Scene.h"
4140

42-
#if defined(_MSC_VER)
43-
#include <gl/GLU.h>
44-
#elif defined(__APPLE__)
45-
#include <OpenGL/glu.h>
46-
#else
47-
#include <GL/glu.h>
48-
#endif
41+
#define GLAD_GL_IMPLEMENTATION
42+
#include <glad/glad.h>
43+
#define GLFW_INCLUDE_NONE
4944
#include <GLFW/glfw3.h>
5045

5146

apps/Viewer/Scene.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,9 @@ bool Scene::Init(const cv::Size& size, LPCTSTR windowName, LPCTSTR fileName, LPC
186186
return false;
187187
if (!window.Init(size, windowName))
188188
return false;
189-
if (glewInit() != GLEW_OK)
189+
if (gladLoadGL() == 0)
190190
return false;
191+
VERBOSE("OpenGL: %s %s", glGetString(GL_RENDERER), glGetString(GL_VERSION));
191192
name = windowName;
192193
window.clbkOpenScene = DELEGATEBINDCLASS(Window::ClbkOpenScene, &Scene::Open, this);
193194

apps/Viewer/Window.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ Window::~Window()
6262
void Window::Release()
6363
{
6464
if (IsValid()) {
65-
#ifdef _USE_NUKLEAR
66-
nk_glfw3_shutdown();
67-
#endif
6865
glfwDestroyWindow(window);
6966
window = NULL;
7067
}
@@ -205,14 +202,6 @@ void Window::UpdateMousePosition(double xpos, double ypos)
205202
}
206203

207204

208-
void Window::GetFrame(Image8U3& image) const
209-
{
210-
image.create(GetSize());
211-
glReadPixels(0, 0, image.width(), image.height(), GL_BGR_EXT, GL_UNSIGNED_BYTE, image.ptr());
212-
cv::flip(image, image, 0);
213-
}
214-
215-
216205
cv::Size Window::GetSize() const
217206
{
218207
cv::Size _size;

apps/Viewer/Window.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ class Window
139139
void UpdateView(const Eigen::Matrix3d& R, const Eigen::Vector3d& t);
140140
void UpdateMousePosition(double xpos, double ypos);
141141

142-
void GetFrame(Image8U3&) const;
143-
144142
cv::Size GetSize() const;
145143
void Resize(const cv::Size&);
146144
static void Resize(GLFWwindow* window, int width, int height);

build/Templates/ConfigLocal.h.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@
3939
// TIFF codec
4040
#cmakedefine _USE_TIFF
4141

42-
// OpenGL support
43-
#cmakedefine _USE_OPENGL
44-
4542
// OpenCL support
4643
#cmakedefine _USE_OPENCL
4744
#cmakedefine _USE_OPENCL_STATIC

libs/MVS/DepthMap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ bool DepthData::Load(const String& fileName, unsigned flags)
266266
Camera camera;
267267
if (!ImportDepthDataRaw(fileName, imageFileName, IDs, imageSize, camera.K, camera.R, camera.C, dMin, dMax, depthMap, normalMap, confMap, viewsMap, flags))
268268
return false;
269-
ASSERT(!IsValid() || (IDs.size() == images.size() && IDs.front() == GetView().GetID()));
269+
ASSERT(!IDs.empty() && (!IsValid() || IDs.front() == GetView().GetID()));
270270
ASSERT(depthMap.size() == imageSize);
271271
ASSERT(depthMap.size() == size);
272272
return true;
@@ -1834,7 +1834,7 @@ bool MVS::ExportDepthDataRaw(const String& fileName, const String& imageFileName
18341834
Depth dMin, Depth dMax,
18351835
const DepthMap& depthMap, const NormalMap& normalMap, const ConfidenceMap& confMap, const ViewsMap& viewsMap)
18361836
{
1837-
ASSERT(IDs.size() > 1 && IDs.size() < 256);
1837+
ASSERT(!IDs.empty() && IDs.size() < 256);
18381838
ASSERT(!depthMap.empty());
18391839
ASSERT(confMap.empty() || depthMap.size() == confMap.size());
18401840
ASSERT(viewsMap.empty() || depthMap.size() == viewsMap.size());

libs/MVS/SceneReconstruct.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
#include <CGAL/Triangulation_cell_base_with_info_3.h>
3939
#include <CGAL/Spatial_sort_traits_adapter_3.h>
4040
#include <CGAL/AABB_tree.h>
41-
#include <CGAL/AABB_traits.h>
42-
#include <CGAL/AABB_triangle_primitive.h>
41+
#include <CGAL/AABB_traits_3.h>
42+
#include <CGAL/AABB_triangle_primitive_3.h>
4343
#include <CGAL/Polyhedron_3.h>
4444

4545
using namespace MVS;

vcpkg.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"default-features": false
1515
},
1616
"eigen3",
17-
"glew",
17+
"glad",
1818
"glfw3",
1919
"libpng",
2020
{
@@ -24,7 +24,6 @@
2424
"openexr"
2525
]
2626
},
27-
"opengl",
2827
"tiff",
2928
"vcglib",
3029
"zlib"

0 commit comments

Comments
 (0)