diff --git a/modules/v4d/include/opencv2/v4d/detail/framebuffercontext.hpp b/modules/v4d/include/opencv2/v4d/detail/framebuffercontext.hpp index d30087131..3f7d2f31b 100644 --- a/modules/v4d/include/opencv2/v4d/detail/framebuffercontext.hpp +++ b/modules/v4d/include/opencv2/v4d/detail/framebuffercontext.hpp @@ -115,7 +115,7 @@ class CV_EXPORTS FrameBufferContext { int index_; void* currentSyncObject_ = 0; - bool firstSync_ = true; + static bool firstSync_; public: /*! * Acquires and releases the framebuffer from and to OpenGL. diff --git a/modules/v4d/include/opencv2/v4d/util.hpp b/modules/v4d/include/opencv2/v4d/util.hpp index 407ab72ad..78fa00e1d 100644 --- a/modules/v4d/include/opencv2/v4d/util.hpp +++ b/modules/v4d/include/opencv2/v4d/util.hpp @@ -85,11 +85,7 @@ void run_sync_on_main(std::function fn) { sync_run = true; #ifdef __EMSCRIPTEN__ - typedef void* function_t( void* ) ; - function_t* ptr_fun = fn.target() ; - //Check that the function object wrapped something callable - CV_Assert( ptr_fun != nullptr ); - emscripten_sync_run_in_main_runtime_thread(EM_FUNC_SIG_V, ptr_fun); + emscripten_sync_run_in_main_runtime_thread(EM_FUNC_SIG_V, cv::v4d::detail::get_fn_ptr(fn)); #else fn(); #endif diff --git a/modules/v4d/include/opencv2/v4d/v4d.hpp b/modules/v4d/include/opencv2/v4d/v4d.hpp index e305ad29a..99f7029f0 100644 --- a/modules/v4d/include/opencv2/v4d/v4d.hpp +++ b/modules/v4d/include/opencv2/v4d/v4d.hpp @@ -271,11 +271,8 @@ public: * This function main purpose is to abstract the run loop for portability reasons. * @param fn A functor that will be called repeatetly until the application terminates or the functor returns false */ - CV_EXPORTS void run(std::function)> fn -#ifndef __EMSCRIPTEN__ - , size_t workers = 0 -#endif - ); + + CV_EXPORTS void run(std::function)> fn, size_t workers = 0); /*! * Called to feed an image directly to the framebuffer */ diff --git a/modules/v4d/samples/cube-demo.cpp b/modules/v4d/samples/cube-demo.cpp index 78585227f..a95ef2915 100644 --- a/modules/v4d/samples/cube-demo.cpp +++ b/modules/v4d/samples/cube-demo.cpp @@ -26,12 +26,12 @@ using std::cerr; using std::endl; /* OpenGL constants and variables */ -static thread_local const unsigned int triangles = 12; -static thread_local const unsigned int vertices_index = 0; -static thread_local const unsigned int colors_index = 1; -static thread_local unsigned int shader_program; -static thread_local unsigned int vao; -static thread_local unsigned int uniform_transform; +static const unsigned int triangles = 12; +static const unsigned int vertices_index = 0; +static const unsigned int colors_index = 1; +static unsigned int shader_program; +static unsigned int vao; +static unsigned int uniform_transform; cv::Ptr global_v4d; //Simple transform & pass-through shaders @@ -198,9 +198,9 @@ static void render_scene() { #ifndef __EMSCRIPTEN__ //applies a glow effect to an image static void glow_effect(const cv::UMat& src, cv::UMat& dst, const int ksize) { - static thread_local cv::UMat resize; - static thread_local cv::UMat blur; - static thread_local cv::UMat dst16; + cv::UMat resize; + cv::UMat blur; + cv::UMat dst16; cv::bitwise_not(src, dst); diff --git a/modules/v4d/src/detail/framebuffercontext.cpp b/modules/v4d/src/detail/framebuffercontext.cpp index d9f82ca12..f81ee5da1 100644 --- a/modules/v4d/src/detail/framebuffercontext.cpp +++ b/modules/v4d/src/detail/framebuffercontext.cpp @@ -19,12 +19,14 @@ namespace cv { namespace v4d { + namespace detail { static void glfw_error_callback(int error, const char* description) { fprintf(stderr, "GLFW Error: (%d) %s\n", error, description); } +bool FrameBufferContext::firstSync_ = true; int frameBufferContextCnt = 0; @@ -700,7 +702,7 @@ void FrameBufferContext::begin(GLenum framebufferTarget) { void FrameBufferContext::end() { this->makeCurrent(); GL_CHECK(glFlush()); - // this->fence(); +// this->fence(); } void FrameBufferContext::download(cv::UMat& m) { diff --git a/modules/v4d/src/util.cpp b/modules/v4d/src/util.cpp index 931cdfcc8..2b4cafdbb 100644 --- a/modules/v4d/src/util.cpp +++ b/modules/v4d/src/util.cpp @@ -482,7 +482,7 @@ public: ); ); GL_CHECK(glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0)); - cv::Size fbSz = window_->framebufferSize(); + cv::Size fbSz = window_->fbSize(); window_->fbCtx().blitFrameBufferToFrameBuffer(cv::Rect(0, 0, width_, height_), cv::Size(width_, height_), window_->fbCtx().getFramebufferID(), true, true); return true; diff --git a/modules/v4d/src/v4d.cpp b/modules/v4d/src/v4d.cpp index a9265fa93..8a946d6d6 100644 --- a/modules/v4d/src/v4d.cpp +++ b/modules/v4d/src/v4d.cpp @@ -193,12 +193,7 @@ static void do_frame(void* void_fn_ptr) { static bool first_run = true; -void V4D::run(std::function)> fn -#ifndef __EMSCRIPTEN__ - , size_t workers -#endif - ) { -#ifndef __EMSCRIPTEN__ +void V4D::run(std::function)> fn, size_t workers) { numWorkers_ = workers; std::vector threads; { @@ -246,7 +241,6 @@ void V4D::run(std::function)> fn } } } -#endif this->makeCurrent(); #ifndef __EMSCRIPTEN__ @@ -271,10 +265,8 @@ void V4D::run(std::function)> fn if(this->isMain()) { thread_pool_.finish(); -#ifndef __EMSCRIPTEN__ for(auto& t : threads) t->join(); -#endif } }