]> git.sesse.net Git - nageru/blobdiff - mixer.cpp
Add a wrapper to make fences refcounted, as we will soon be needing to split them...
[nageru] / mixer.cpp
index 4d7c19d35b30962334d61a0a6df9ab83cdf3664a..05b32871d3f528cc1e767c842713467fe4b0e687 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
 #include "context.h"
 #include "bmusb.h"
 #include "pbo_frame_allocator.h"
+#include "ref_counted_gl_sync.h"
 
 using namespace movit;
 using namespace std;
 using namespace std::placeholders;
 
-// shared between all EGL contexts
-EGLDisplay egl_display;
-EGLSurface egl_surface;
-EGLConfig ecfg;
-EGLint ctxattr[] = {
-       EGL_CONTEXT_CLIENT_VERSION, 2,
-       EGL_CONTEXT_MAJOR_VERSION_KHR, 3,
-       EGL_CONTEXT_MINOR_VERSION_KHR, 1,
-       //EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR,
-       EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT,
-       EGL_NONE
-};
-
-EGLConfig pbuffer_ecfg;
 
 std::mutex bmusb_mutex;  // protects <cards>
 
@@ -219,7 +206,7 @@ void mixer_thread_func(QSurface *surface, QSurface *surface2, QSurface *surface3
                exit(1);
        }
 
-       CHECK(init_movit("/usr/share/movit", MOVIT_DEBUG_ON));
+       CHECK(init_movit(MOVIT_SHADER_DIR, MOVIT_DEBUG_OFF));
        check_error();
 
        EffectChain chain(WIDTH, HEIGHT);
@@ -450,42 +437,40 @@ void mixer_thread_func(QSurface *surface, QSurface *surface2, QSurface *surface3
                glBindFramebuffer(GL_FRAMEBUFFER, cbcr_fbo);
                glViewport(0, 0, WIDTH/2, HEIGHT/2);
                check_error();
-               GLsync fence;
-               {
-                       glUseProgram(cbcr_program_num);
-                       check_error();
 
-                       glActiveTexture(GL_TEXTURE0);
-                       check_error();
-                       glBindTexture(GL_TEXTURE_2D, chroma_tex);
-                       check_error();
-                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-                       check_error();
-                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-                       check_error();
-                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-                       check_error();
+               glUseProgram(cbcr_program_num);
+               check_error();
 
-                       float chroma_offset_0[] = { -0.5f / WIDTH, 0.0f };
-                       set_uniform_vec2(cbcr_program_num, "foo", "chroma_offset_0", chroma_offset_0);
+               glActiveTexture(GL_TEXTURE0);
+               check_error();
+               glBindTexture(GL_TEXTURE_2D, chroma_tex);
+               check_error();
+               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+               check_error();
+               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+               check_error();
+               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+               check_error();
 
-                       GLuint position_vbo = fill_vertex_attribute(cbcr_program_num, "position", 2, GL_FLOAT, sizeof(vertices), vertices);
-                       GLuint texcoord_vbo = fill_vertex_attribute(cbcr_program_num, "texcoord", 2, GL_FLOAT, sizeof(vertices), vertices);  // Same as vertices.
+               float chroma_offset_0[] = { -0.5f / WIDTH, 0.0f };
+               set_uniform_vec2(cbcr_program_num, "foo", "chroma_offset_0", chroma_offset_0);
 
-                       glDrawArrays(GL_TRIANGLES, 0, 3);
-                       check_error();
+               GLuint position_vbo = fill_vertex_attribute(cbcr_program_num, "position", 2, GL_FLOAT, sizeof(vertices), vertices);
+               GLuint texcoord_vbo = fill_vertex_attribute(cbcr_program_num, "texcoord", 2, GL_FLOAT, sizeof(vertices), vertices);  // Same as vertices.
 
-                       cleanup_vertex_attribute(cbcr_program_num, "position", position_vbo);
-                       cleanup_vertex_attribute(cbcr_program_num, "texcoord", texcoord_vbo);
+               glDrawArrays(GL_TRIANGLES, 0, 3);
+               check_error();
 
-                       glUseProgram(0);
-                       check_error();
+               cleanup_vertex_attribute(cbcr_program_num, "position", position_vbo);
+               cleanup_vertex_attribute(cbcr_program_num, "texcoord", texcoord_vbo);
 
-                       fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, /*flags=*/0);              
-                       check_error();
+               glUseProgram(0);
+               check_error();
 
-                       resource_pool->release_fbo(cbcr_fbo);
-               }
+               RefCountedGLsync fence(GL_SYNC_GPU_COMMANDS_COMPLETE, /*flags=*/0);
+               check_error();
+
+               resource_pool->release_fbo(cbcr_fbo);
 
                h264_encoder.end_frame(fence, input_frames_to_release);