diff --git a/modules/v4d/CMakeLists.txt b/modules/v4d/CMakeLists.txt index 73e67258f..e35f7bf9b 100644 --- a/modules/v4d/CMakeLists.txt +++ b/modules/v4d/CMakeLists.txt @@ -12,9 +12,9 @@ if (${idx} LESS 0) message(STATUS "Module opencv_v4d disabled because it requires C++20") ocv_module_disable(v4d) endif() -set(CMAKE_CXX_FLAGS "${CMAKE_LD_FLAGS} -L../../lib") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L../../lib") -OCV_OPTION(OPENCV_V4D_ENABLE_ES3 "Enable OpenGL ES 3.0 backend for V4D" OFF +OCV_OPTION(OPENCV_V4D_ENABLE_ES2 "Enable OpenGL ES 2.0 backend for V4D" OFF VERIFY HAVE_OPENGL) find_package(Git QUIET) @@ -60,6 +60,15 @@ endif() set(NANOGUI_BUILD_SHARED ON) set(NANOGUI_BUILD_PYTHON OFF) +set(NANOGUI_BUILD_EXAMPLES OFF) + +if(OPENCV_V4D_ENABLE_ES2) + set(NANOGUI_BACKEND "GLES 2") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOPENCV_V4D_USE_ES2=1") +else() + set(NANOGUI_BACKEND "OpenGL") +endif() + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third/nanogui) add_library(nanovg "third/nanogui/ext/nanovg/src/nanovg.c") diff --git a/modules/v4d/include/opencv2/v4d/dialog.hpp b/modules/v4d/include/opencv2/v4d/dialog.hpp index f2e79b258..84423f2d8 100644 --- a/modules/v4d/include/opencv2/v4d/dialog.hpp +++ b/modules/v4d/include/opencv2/v4d/dialog.hpp @@ -6,7 +6,7 @@ #ifndef SRC_OPENCV_V4D_DIALOG_HPP_ #define SRC_OPENCV_V4D_DIALOG_HPP_ #ifdef __EMSCRIPTEN__ -#define OPENCV_V4D_USE_ES3 1 +#define OPENCV_V4D_USE_ES2 1 #endif #include diff --git a/modules/v4d/include/opencv2/v4d/nvg.hpp b/modules/v4d/include/opencv2/v4d/nvg.hpp index 045c1a220..398b1ec1a 100644 --- a/modules/v4d/include/opencv2/v4d/nvg.hpp +++ b/modules/v4d/include/opencv2/v4d/nvg.hpp @@ -7,14 +7,14 @@ #define SRC_OPENCV_V4D_NVG_HPP_ #include "v4d.hpp" -#ifndef OPENCV_V4D_USE_ES3 +#ifndef OPENCV_V4D_USE_ES2 # ifndef NANOGUI_USE_OPENGL # define NANOGUI_USE_OPENGL # endif #else # ifndef NANOGUI_USE_GLES # define NANOGUI_USE_GLES -# define NANOGUI_GLES_VERSION 3 +# define NANOGUI_GLES_VERSION 2 # endif #endif #include diff --git a/modules/v4d/include/opencv2/v4d/v4d.hpp b/modules/v4d/include/opencv2/v4d/v4d.hpp index 446782de2..dd305587f 100644 --- a/modules/v4d/include/opencv2/v4d/v4d.hpp +++ b/modules/v4d/include/opencv2/v4d/v4d.hpp @@ -21,12 +21,12 @@ #include "cxxpool.hpp" #ifdef __EMSCRIPTEN__ -#define OPENCV_V4D_USE_ES3 1 +#define OPENCV_V4D_USE_ES2 1 #include #endif #include -#ifndef OPENCV_V4D_USE_ES3 +#ifndef OPENCV_V4D_USE_ES2 #include #else #include diff --git a/modules/v4d/samples/shader/shader-demo.cpp b/modules/v4d/samples/shader/shader-demo.cpp index 92eb99dd0..4fce9b0fe 100644 --- a/modules/v4d/samples/shader/shader-demo.cpp +++ b/modules/v4d/samples/shader/shader-demo.cpp @@ -44,7 +44,7 @@ GLint zoom_hdl; /** shader and program handle **/ GLuint shader_program_hdl; -#ifndef OPENCV_V4D_USE_ES3 +#ifndef OPENCV_V4D_USE_ES2 //vertex array GLuint VAO; #endif @@ -71,7 +71,7 @@ unsigned int indices[] = void load_buffer_data(){ -#ifndef OPENCV_V4D_USE_ES3 +#ifndef OPENCV_V4D_USE_ES2 glGenVertexArrays(1, &VAO); glBindVertexArray(VAO); #endif @@ -89,7 +89,7 @@ void load_buffer_data(){ glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); -#ifndef OPENCV_V4D_USE_ES3 +#ifndef OPENCV_V4D_USE_ES2 glBindVertexArray(0); #endif } @@ -141,7 +141,7 @@ GLuint init_shader(const char* vShader, const char* fShader, const char* outputA glAttachShader( program, shader ); } -#ifndef OPENCV_V4D_USE_ES3 +#ifndef OPENCV_V4D_USE_ES2 /* Link output */ glBindFragDataLocation(program, 0, outputAttributeName); #endif @@ -170,7 +170,7 @@ GLuint init_shader(const char* vShader, const char* fShader, const char* outputA //mandelbrot shader code adapted from my own project: https://github.com/kallaballa/FractalDive#after void load_shader(){ -#ifndef OPENCV_V4D_USE_ES3 +#ifndef OPENCV_V4D_USE_ES2 const string shaderVersion = "330"; #else const string shaderVersion = "300 es"; @@ -293,7 +293,7 @@ void render_scene(const cv::Size& sz) { glUniform1f(zoom_hdl, zoom); } -#ifndef OPENCV_V4D_USE_ES3 +#ifndef OPENCV_V4D_USE_ES2 glBindVertexArray(VAO); #endif glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); diff --git a/modules/v4d/samples/tetra/tetra-demo.cpp b/modules/v4d/samples/tetra/tetra-demo.cpp index 8e6e43a3c..be9da493d 100644 --- a/modules/v4d/samples/tetra/tetra-demo.cpp +++ b/modules/v4d/samples/tetra/tetra-demo.cpp @@ -20,7 +20,7 @@ using std::endl; static cv::Ptr v4d = cv::viz::V4D::make(cv::Size(WIDTH, HEIGHT), cv::Size(WIDTH, HEIGHT), OFFSCREEN, "Tetra Demo"); void init_scene(const cv::Size& sz) { -#ifndef OPENCV_V4D_USE_ES3 +#ifndef OPENCV_V4D_USE_ES2 //Initialize the OpenGL scene glViewport(0, 0, sz.width, sz.height); glColor3f(1.0, 1.0, 1.0); @@ -41,7 +41,7 @@ void init_scene(const cv::Size& sz) { } void render_scene(const cv::Size& sz) { -#ifndef OPENCV_V4D_USE_ES3 +#ifndef OPENCV_V4D_USE_ES2 //Render a tetrahedron using immediate mode because the code is more concise for a demo glViewport(0, 0, sz.width, sz.height); glRotatef(1, 0, 1, 0); diff --git a/modules/v4d/samples/video/video-demo.cpp b/modules/v4d/samples/video/video-demo.cpp index 6da2c0d1b..83bbc2b95 100644 --- a/modules/v4d/samples/video/video-demo.cpp +++ b/modules/v4d/samples/video/video-demo.cpp @@ -21,7 +21,7 @@ using std::string; static cv::Ptr v4d = cv::viz::V4D::make(cv::Size(WIDTH, HEIGHT), cv::Size(WIDTH, HEIGHT), OFFSCREEN, "Video Demo"); void init_scene(const cv::Size& sz) { -#ifndef OPENCV_V4D_USE_ES3 +#ifndef OPENCV_V4D_USE_ES2 //Initialize the OpenGL scene glViewport(0, 0, sz.width, sz.height); glColor3f(1.0, 1.0, 1.0); @@ -42,7 +42,7 @@ void init_scene(const cv::Size& sz) { } void render_scene(const cv::Size& sz) { -#ifndef OPENCV_V4D_USE_ES3 +#ifndef OPENCV_V4D_USE_ES2 //Render a tetrahedron using immediate mode because the code is more concise for a demo glViewport(0, 0, sz.width, sz.height); glRotatef(1, 0, 1, 0); diff --git a/modules/v4d/src/detail/framebuffercontext.cpp b/modules/v4d/src/detail/framebuffercontext.cpp index d2c327c05..196181eae 100644 --- a/modules/v4d/src/detail/framebuffercontext.cpp +++ b/modules/v4d/src/detail/framebuffercontext.cpp @@ -8,7 +8,7 @@ #include "opencv2/v4d/util.hpp" #include "opencv2/v4d/v4d.hpp" -#ifndef OPENCV_V4D_USE_ES3 +#ifndef OPENCV_V4D_USE_ES2 #include #endif @@ -19,7 +19,7 @@ namespace detail { //FIXME use cv::ogl FrameBufferContext::FrameBufferContext(const cv::Size& frameBufferSize) : frameBufferSize_(frameBufferSize) { -#ifndef OPENCV_V4D_USE_ES3 +#ifndef OPENCV_V4D_USE_ES2 glewExperimental = true; glewInit(); try { diff --git a/modules/v4d/src/detail/framebuffercontext.hpp b/modules/v4d/src/detail/framebuffercontext.hpp index 6489227d3..9ef32ff30 100644 --- a/modules/v4d/src/detail/framebuffercontext.hpp +++ b/modules/v4d/src/detail/framebuffercontext.hpp @@ -13,10 +13,10 @@ # include # include #else -# define OPENCV_V4D_USE_ES3 1 +# define OPENCV_V4D_USE_ES2 1 #endif -#ifndef OPENCV_V4D_USE_ES3 +#ifndef OPENCV_V4D_USE_ES2 # include # define GLFW_INCLUDE_GLCOREARB #else diff --git a/modules/v4d/src/detail/nanovgcontext.cpp b/modules/v4d/src/detail/nanovgcontext.cpp index 70a9153f0..756e4542c 100644 --- a/modules/v4d/src/detail/nanovgcontext.cpp +++ b/modules/v4d/src/detail/nanovgcontext.cpp @@ -27,7 +27,7 @@ void NanoVGContext::render(std::function fn) { } void push() { -#ifndef OPENCV_V4D_USE_ES3 +#ifndef OPENCV_V4D_USE_ES2 GL_CHECK(glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS)); GL_CHECK(glPushAttrib(GL_ALL_ATTRIB_BITS)); GL_CHECK(glMatrixMode(GL_MODELVIEW)); @@ -40,7 +40,7 @@ void push() { } void pop() { -#ifndef OPENCV_V4D_USE_ES3 +#ifndef OPENCV_V4D_USE_ES2 GL_CHECK(glMatrixMode(GL_TEXTURE)); GL_CHECK(glPopMatrix()); GL_CHECK(glMatrixMode(GL_PROJECTION)); diff --git a/modules/v4d/src/detail/nanovgcontext.hpp b/modules/v4d/src/detail/nanovgcontext.hpp index 7084f0011..f57ba1c24 100644 --- a/modules/v4d/src/detail/nanovgcontext.hpp +++ b/modules/v4d/src/detail/nanovgcontext.hpp @@ -8,11 +8,11 @@ #include "framebuffercontext.hpp" #include -#ifndef OPENCV_V4D_USE_ES3 +#ifndef OPENCV_V4D_USE_ES2 #define NANOGUI_USE_OPENGL #else #define NANOGUI_USE_GLES -#define NANOGUI_GLES_VERSION 3 +#define NANOGUI_GLES_VERSION 2 #endif #include diff --git a/modules/v4d/src/dialog.cpp b/modules/v4d/src/dialog.cpp index a774c0742..29e4c35c5 100644 --- a/modules/v4d/src/dialog.cpp +++ b/modules/v4d/src/dialog.cpp @@ -5,7 +5,7 @@ #include "opencv2/v4d/dialog.hpp" #include -#ifndef OPENCV_V4D_USE_ES3 +#ifndef OPENCV_V4D_USE_ES2 # include # define GLFW_INCLUDE_GLCOREARB #else diff --git a/modules/v4d/src/v4d.cpp b/modules/v4d/src/v4d.cpp index 1481077f0..01810d4e2 100644 --- a/modules/v4d/src/v4d.cpp +++ b/modules/v4d/src/v4d.cpp @@ -124,7 +124,7 @@ bool V4D::initializeWindowing() { glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint (GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); -#elif defined(OPENCV_V4D_USE_ES3) +#elif defined(OPENCV_V4D_USE_ES2) glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);