GLES3 adaption

pull/3471/head
kallaballa 2 years ago
parent 52dbb39bbd
commit 40cc1e027b
  1. 29
      modules/v4d/CMakeLists.txt
  2. 18
      modules/v4d/include/opencv2/v4d/v4d.hpp
  3. 2
      modules/v4d/samples/cube-demo.cpp
  4. 16
      modules/v4d/src/detail/imguicontext.cpp
  5. 4
      modules/v4d/src/detail/nanovgcontext.cpp

@ -1,3 +1,5 @@
cmake_policy(SET CMP0079 NEW)
if(NOT EMSCRIPTEN)
find_package(glfw3 3 REQUIRED)
find_package(OpenCL REQUIRED)
@ -32,7 +34,7 @@ macro(add_binary_sample sample source)
#add_executable(${sample} ${source})
# ocv_target_include_modules(${sample} opencv_core opencv_imgproc opencv_videoio opencv_video opencv_imgcodecs opencv_v4d opencv_face opencv_tracking opencv_objdetect opencv_stitching opencv_optflow opencv_imgcodecs opencv_features2d opencv_dnn opencv_flann)
# ocv_target_link_libraries(${sample} LINK_PRIVATE opencv_core opencv_imgproc opencv_videoio opencv_video opencv_imgcodecs opencv_v4d opencv_face opencv_tracking opencv_objdetect opencv_stitching opencv_optflow opencv_imgcodecs opencv_features2d opencv_dnn opencv_flann bgfx-shared-libRelease)
ocv_target_link_libraries(${sample} glfw imgui_v4d opencv_v4d)
ocv_target_link_libraries(${sample} OpenGL::OpenGL glfw imgui_v4d opencv_v4d)
target_compile_features(${sample} PRIVATE cxx_std_20)
target_link_directories(${sample} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../../lib" "${CMAKE_CURRENT_SOURCE_DIR}/third/bgfx/.build/linux64_gcc/bin/")
target_include_directories(${sample} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include/opencv2/v4d/detail/" "${CMAKE_CURRENT_SOURCE_DIR}/third/imgui" "${CMAKE_CURRENT_SOURCE_DIR}/third/imgui/backends/" "${CMAKE_CURRENT_SOURCE_DIR}/third/nanovg/src/" "${CMAKE_CURRENT_SOURCE_DIR}/third/glad/include/")
@ -95,22 +97,34 @@ endif()
if (NOT (TARGET nanovg))
set(NANOVG_BUILD_EXAMPLES OFF)
set(NANOVG_BUILD_GL2 OFF)
set(NANOVG_BUILD_GL3 ON)
if(OPENCV_V4D_ENABLE_ES3)
set(NANOVG_BUILD_GL3 OFF)
set(NANOVG_BUILD_GLES3 ON)
else()
set(NANOVG_BUILD_GL3 ON)
set(NANOVG_BUILD_GLES3 OFF)
endif()
set(NANOVG_BUILD_GLES2 OFF)
set(NANOVG_BUILD_GLES3 OFF)
set(NANOVG_BUILD_OUI OFF)
set(NANOVG_BUILD_SVG OFF)
set(NANOVG_SHARED_LIBS ON)
set(NANOVG_STATIC_LIBS OFF)
set(NANOVG_USE_FREETYPE OFF)
set(NANOVG_USE_STB ON)
set(CMAKE_CXX_FLAGS "-Wno-error -DNANOVG_GL3")
set(CMAKE_C_FLAGS "-Wno-error -DNANOVG_GL3")
set(CMAKE_CXX_FLAGS "-Wno-error")
set(CMAKE_C_FLAGS "-Wno-error")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/third/nanovg/")
if(OPENCV_V4D_ENABLE_ES3)
target_compile_definitions(nanovg PUBLIC "NANOVG_GLES3")
target_link_libraries(nanovg OpenGL::GLES3)
else()
target_compile_definitions(nanovg PUBLIC "NANOVG_GL3")
target_link_libraries(nanovg OpenGL::OpenGL)
endif()
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/third/nanovg/src/")
target_compile_definitions(nanovg PUBLIC "NANOVG_GL3")
endif()
if (NOT (TARGET imgui_v4d))
file(GLOB imgui_sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/third/imgui/*.cpp")
file(GLOB imgui_backend_sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/third/imgui/backends/imgui_impl_opengl3*.cpp")
@ -119,7 +133,8 @@ if (NOT (TARGET imgui_v4d))
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/third/imgui/")
endif()
install(TARGETS imgui_v4d EXPORT )
cmake_policy(SET CMP0079 NEW)
ocv_add_module(v4d opencv_core opencv_imgproc opencv_videoio opencv_video)

@ -19,14 +19,28 @@
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; \
ImGui::StyleColorsDark(); \
ImGui_ImplGlfw_InitForOpenGL(v4d->getGLFWWindow(), install_hooks); \
ImGui_ImplOpenGL3_Init(); \
ImGui_ImplOpenGL3_Init("#version 330"); \
})
#else
# define V4D_INIT_PRIVATE(v4d, install_hooks) ({ \
FrameBufferContext::GLScope glScope(v4d->fbCtx(), GL_FRAMEBUFFER); \
IMGUI_CHECKVERSION(); \
ImGui::CreateContext(); \
ImGuiIO& io = ImGui::GetIO(); \
(void)io; \
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; \
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; \
ImGui::StyleColorsDark(); \
ImGui_ImplGlfw_InitForOpenGL(v4d->getGLFWWindow(), install_hooks); \
ImGui_ImplOpenGL3_Init("#version 300 es"); \
})
#endif
# define V4D_INIT_MAIN(w, h, title, offscreen, debug, samples) ({ \
cv::Ptr<cv::v4d::V4D> v4d = cv::v4d::V4D::make(cv::Size(w, h), cv::Size(), title, offscreen, debug, samples); \
V4D_INIT_PRIVATE(v4d, true); \
v4d; \
})
#endif
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#include <emscripten/threading.h>

@ -251,7 +251,7 @@ int main() {
#ifndef __EMSCRIPTEN__
//Creates a writer sink using the VP9 codec (which might be hardware accelerated)
Sink sink = makeWriterSink(OUTPUT_FILENAME, cv::VideoWriter::fourcc('H', '2', '6', '4'), FPS,
Sink sink = makeWriterSink(OUTPUT_FILENAME, cv::VideoWriter::fourcc('V', 'P', '9', '0'), FPS,
cv::Size(WIDTH, HEIGHT));
window->setSink(sink);
#endif

@ -5,14 +5,17 @@
#include "opencv2/v4d/v4d.hpp"
#include "opencv2/v4d/detail/imguicontext.hpp"
#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
#include <stdio.h>
#define GL_SILENCE_DEPRECATION
#if defined(OPENCV_V4D_USE_ES3) || defined(EMSCRIPTEN)
#include <GLES3/gl3.h>
# define IMGUI_IMPL_OPENGL_ES3
//# include <GLES3/gl3.h>
#endif
#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
#include <GLFW/glfw3.h>
namespace cv {
@ -28,7 +31,6 @@ ImGuiContext::ImGuiContext(FrameBufferContext& fbContext) :
#endif
}
void ImGuiContext::build(std::function<void(const cv::Size&)> fn) {
renderCallback_ = fn;
}
@ -46,7 +48,9 @@ void ImGuiContext::render() {
{
fbCtx().getV4D()->makeCurrent();
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0));
#if !defined(OPENCV_V4D_USE_ES3) && !defined(EMSCRIPTEN)
GL_CHECK(glDrawBuffer(GL_BACK));
#endif
GL_CHECK(glViewport(0, 0, fbCtx().getV4D()->size().width, fbCtx().getV4D()->size().height));
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();

@ -17,7 +17,11 @@ NanoVGContext::NanoVGContext(FrameBufferContext& fbContext) :
run_sync_on_main<13>([this]() {
{
FrameBufferContext::GLScope glScope(fbCtx(), GL_FRAMEBUFFER);
#if defined(OPENCV_V4D_USE_ES3)
context_ = nvgCreateGLES3(NVG_ANTIALIAS | NVG_STENCIL_STROKES | NVG_DEBUG);
#else
context_ = nvgCreateGL3(NVG_ANTIALIAS | NVG_STENCIL_STROKES | NVG_DEBUG);
#endif
if (!context_)
throw std::runtime_error("Could not initialize NanoVG!");
}

Loading…
Cancel
Save