emscripten adaptions

pull/3471/head
kallaballa 2 years ago
parent b47b11536c
commit ff8ceea99d
  1. 2
      modules/v4d/include/opencv2/v4d/detail/framebuffercontext.hpp
  2. 6
      modules/v4d/include/opencv2/v4d/util.hpp
  3. 7
      modules/v4d/include/opencv2/v4d/v4d.hpp
  4. 18
      modules/v4d/samples/cube-demo.cpp
  5. 4
      modules/v4d/src/detail/framebuffercontext.cpp
  6. 2
      modules/v4d/src/util.cpp
  7. 10
      modules/v4d/src/v4d.cpp

@ -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.

@ -85,11 +85,7 @@ void run_sync_on_main(std::function<void()> fn) {
sync_run = true;
#ifdef __EMSCRIPTEN__
typedef void* function_t( void* ) ;
function_t* ptr_fun = fn.target<function_t>() ;
//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<Tid>(fn));
#else
fn();
#endif

@ -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<bool(cv::Ptr<V4D>)> fn
#ifndef __EMSCRIPTEN__
, size_t workers = 0
#endif
);
CV_EXPORTS void run(std::function<bool(cv::Ptr<V4D>)> fn, size_t workers = 0);
/*!
* Called to feed an image directly to the framebuffer
*/

@ -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<cv::v4d::V4D> 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);

@ -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) {

@ -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;

@ -193,12 +193,7 @@ static void do_frame(void* void_fn_ptr) {
static bool first_run = true;
void V4D::run(std::function<bool(cv::Ptr<V4D>)> fn
#ifndef __EMSCRIPTEN__
, size_t workers
#endif
) {
#ifndef __EMSCRIPTEN__
void V4D::run(std::function<bool(cv::Ptr<V4D>)> fn, size_t workers) {
numWorkers_ = workers;
std::vector<std::thread*> threads;
{
@ -246,7 +241,6 @@ void V4D::run(std::function<bool(cv::Ptr<V4D>)> fn
}
}
}
#endif
this->makeCurrent();
#ifndef __EMSCRIPTEN__
@ -271,10 +265,8 @@ void V4D::run(std::function<bool(cv::Ptr<V4D>)> fn
if(this->isMain()) {
thread_pool_.finish();
#ifndef __EMSCRIPTEN__
for(auto& t : threads)
t->join();
#endif
}
}

Loading…
Cancel
Save