From ab10f335e907766d2177d19936482012fa1b94fc Mon Sep 17 00:00:00 2001 From: Benau Date: Mon, 10 Apr 2017 01:26:52 +0800 Subject: [PATCH] Remove glew include in libopenrecorder --- src/graphics/irr_driver.cpp | 6 +++++ src/recorder/capture_library.cpp | 34 ++++++++++++-------------- src/recorder/mjpeg_writer.cpp | 2 -- src/recorder/openglrecorder.h | 22 +++++++++++++++++ src/recorder/recorder.cpp | 40 ++++++++++++++++++++++++++++++- src/recorder/recorder_private.hpp | 8 +++++++ 6 files changed, 90 insertions(+), 22 deletions(-) diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index 719cba17b..7aa1ef92d 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -623,6 +623,12 @@ void IrrDriver::initDevice() "RecorderConfig is invalid, use the default one."); } + ogrRegReadPixelsFunction((ogrFucReadPixels)glReadPixels); + ogrRegPBOFunctions((ogrFucGenBuffers)glGenBuffers, + (ogrFucBindBuffer)glBindBuffer, (ogrFucBufferData)glBufferData, + (ogrFucDeleteBuffers)glDeleteBuffers, (ogrFucMapBuffer)glMapBuffer, + (ogrFucUnmapBuffer)glUnmapBuffer); + ogrRegGeneralCallback(OGR_CBT_START_RECORDING, [] (void* user_data) { MessageQueue::add (MessageQueue::MT_GENERIC, _("Video recording started.")); }, NULL); diff --git a/src/recorder/capture_library.cpp b/src/recorder/capture_library.cpp index 5e9dbf85c..9666a3cb6 100644 --- a/src/recorder/capture_library.cpp +++ b/src/recorder/capture_library.cpp @@ -8,11 +8,6 @@ #include "vpx_encoder.hpp" #include "wasapi_recorder.hpp" -extern "C" -{ -#include -} - const uint32_t E_GL_PIXEL_PACK_BUFFER = 0x88EB; const uint32_t E_GL_STREAM_READ = 0x88E1; const uint32_t E_GL_READ_ONLY = 0x88B8; @@ -30,14 +25,14 @@ CaptureLibrary::CaptureLibrary(RecorderConfig* rc) m_decompress_handle = tjInitDecompress(); if (m_recorder_cfg->m_triple_buffering > 0) { - glGenBuffers(3, m_pbo); + ogrGenBuffers(3, m_pbo); for (int i = 0; i < 3; i++) { - glBindBuffer(GL_PIXEL_PACK_BUFFER, m_pbo[i]); - glBufferData(GL_PIXEL_PACK_BUFFER, m_recorder_cfg->m_width * - m_recorder_cfg->m_height * 4, NULL, GL_STREAM_READ); + ogrBindBuffer(E_GL_PIXEL_PACK_BUFFER, m_pbo[i]); + ogrBufferData(E_GL_PIXEL_PACK_BUFFER, m_recorder_cfg->m_width * + m_recorder_cfg->m_height * 4, NULL, E_GL_STREAM_READ); } - glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); + ogrBindBuffer(E_GL_PIXEL_PACK_BUFFER, 0); } m_capture_thread = std::thread(CaptureLibrary::captureConversion, this); } // CaptureLibrary @@ -52,7 +47,7 @@ CaptureLibrary::~CaptureLibrary() tjDestroy(m_decompress_handle); if (m_recorder_cfg->m_triple_buffering > 0) { - glDeleteBuffers(3, m_pbo); + ogrDeleteBuffers(3, m_pbo); } } // ~CaptureLibrary @@ -176,15 +171,16 @@ void CaptureLibrary::capture() if (use_pbo) { pbo_read = m_pbo_use % 3; - glBindBuffer(GL_PIXEL_PACK_BUFFER, m_pbo[pbo_read]); - void* ptr = glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY); + ogrBindBuffer(E_GL_PIXEL_PACK_BUFFER, m_pbo[pbo_read]); + void* ptr = ogrMapBuffer(E_GL_PIXEL_PACK_BUFFER, + E_GL_READ_ONLY); memcpy(fbi, ptr, size); - glUnmapBuffer(GL_PIXEL_PACK_BUFFER); + ogrUnmapBuffer(E_GL_PIXEL_PACK_BUFFER); } else { - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, - fbi); + ogrReadPixels(0, 0, width, height, E_GL_RGBA, + E_GL_UNSIGNED_BYTE, fbi); } addFrameBufferImage(fbi, frame_count); } @@ -194,9 +190,9 @@ void CaptureLibrary::capture() return; assert(pbo_read == -1 || pbo_use == pbo_read); - glBindBuffer(GL_PIXEL_PACK_BUFFER, m_pbo[pbo_use]); - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); + ogrBindBuffer(E_GL_PIXEL_PACK_BUFFER, m_pbo[pbo_use]); + ogrReadPixels(0, 0, width, height, E_GL_RGBA, E_GL_UNSIGNED_BYTE, NULL); + ogrBindBuffer(E_GL_PIXEL_PACK_BUFFER, 0); } // capture // ---------------------------------------------------------------------------- diff --git a/src/recorder/mjpeg_writer.cpp b/src/recorder/mjpeg_writer.cpp index 93c78afed..8de7dee5a 100644 --- a/src/recorder/mjpeg_writer.cpp +++ b/src/recorder/mjpeg_writer.cpp @@ -20,8 +20,6 @@ #include "capture_library.hpp" #include "recorder_private.hpp" -#include - namespace Recorder { // ------------------------------------------------------------------------ diff --git a/src/recorder/openglrecorder.h b/src/recorder/openglrecorder.h index 1ef089f7d..34c78d522 100644 --- a/src/recorder/openglrecorder.h +++ b/src/recorder/openglrecorder.h @@ -2,6 +2,8 @@ #ifndef HEADER_OPENGLRECORDER_H #define HEADER_OPENGLRECORDER_H +#include + /** * \mainpage libopenglrecorder * @@ -160,6 +162,16 @@ struct RecorderConfig unsigned int m_record_jpg_quality; }; +/* List of opengl function used by libopenglrecorder: */ +typedef void(*ogrFucReadPixels)(int, int, int, int, unsigned int, unsigned int, + void*); +typedef void(*ogrFucGenBuffers)(int, unsigned int*); +typedef void(*ogrFucBindBuffer)(unsigned int, unsigned int); +typedef void(*ogrFucBufferData)(unsigned int, ptrdiff_t, const void*, unsigned int); +typedef void(*ogrFucDeleteBuffers)(int, const unsigned int*); +typedef void*(*ogrFucMapBuffer)(unsigned int, unsigned int); +typedef void(*ogrFucUnmapBuffer)(unsigned int); + #ifdef __cplusplus extern "C" { @@ -214,6 +226,16 @@ void ogrRegIntCallback(CallBackType, IntCallback, void*); * Return 1 if recording is happening in libopenglrecorder, 0 otherwise. */ int ogrCapturing(void); +/** + * Set opengl function for read pixels (always required). + */ +void ogrRegReadPixelsFunction(ogrFucReadPixels); +/** + * Set opengl functions for using PBOs (required if triple buffering is used). + */ +void ogrRegPBOFunctions(ogrFucGenBuffers, ogrFucBindBuffer, ogrFucBufferData, + ogrFucDeleteBuffers, ogrFucMapBuffer, + ogrFucUnmapBuffer); #ifdef __cplusplus } #endif diff --git a/src/recorder/recorder.cpp b/src/recorder/recorder.cpp index 0543f0756..e09bbb3eb 100644 --- a/src/recorder/recorder.cpp +++ b/src/recorder/recorder.cpp @@ -8,6 +8,14 @@ #include #include +// ============================================================================ +ogrFucReadPixels ogrReadPixels = NULL; +ogrFucGenBuffers ogrGenBuffers = NULL; +ogrFucBindBuffer ogrBindBuffer = NULL; +ogrFucBufferData ogrBufferData = NULL; +ogrFucDeleteBuffers ogrDeleteBuffers = NULL; +ogrFucMapBuffer ogrMapBuffer = NULL; +ogrFucUnmapBuffer ogrUnmapBuffer = NULL; // ============================================================================ std::unique_ptr g_recorder_config(nullptr); // ============================================================================ @@ -105,7 +113,8 @@ const std::string& getSavedName() // ---------------------------------------------------------------------------- void ogrPrepareCapture(void) { - assert(g_recorder_config.get() != nullptr && !g_saved_name.empty()); + assert(g_recorder_config.get() != nullptr && !g_saved_name.empty() && + ogrReadPixels != NULL); if (g_capture_library.get() == nullptr) { assert(g_recorder_config.get() != nullptr); @@ -243,6 +252,35 @@ int ogrCapturing(void) return g_capturing.load() ? 1 : 0; } // ogrCapturing +// ---------------------------------------------------------------------------- +void ogrRegReadPixelsFunction(ogrFucReadPixels read_pixels) +{ + assert(read_pixels != NULL); + ogrReadPixels = read_pixels; +} // ogrRegReadPixelsFunction + +// ---------------------------------------------------------------------------- +void ogrRegPBOFunctions(ogrFucGenBuffers gen_buffers, + ogrFucBindBuffer bind_buffer, + ogrFucBufferData buffer_data, + ogrFucDeleteBuffers delete_buffers, + ogrFucMapBuffer map_buffer, + ogrFucUnmapBuffer unmap_buffer) +{ + assert(gen_buffers != NULL); + ogrGenBuffers = gen_buffers; + assert(bind_buffer != NULL); + ogrBindBuffer = bind_buffer; + assert(buffer_data != NULL); + ogrBufferData = buffer_data; + assert(delete_buffers != NULL); + ogrDeleteBuffers = delete_buffers; + assert(map_buffer != NULL); + ogrMapBuffer = map_buffer; + assert(unmap_buffer != NULL); + ogrUnmapBuffer = unmap_buffer; +} // ogrRegPBOFunctions + // ---------------------------------------------------------------------------- void setCapturing(bool val) { diff --git a/src/recorder/recorder_private.hpp b/src/recorder/recorder_private.hpp index df0e1515e..97cccd2a5 100644 --- a/src/recorder/recorder_private.hpp +++ b/src/recorder/recorder_private.hpp @@ -6,6 +6,14 @@ #include +extern ogrFucReadPixels ogrReadPixels; +extern ogrFucGenBuffers ogrGenBuffers; +extern ogrFucBindBuffer ogrBindBuffer; +extern ogrFucBufferData ogrBufferData; +extern ogrFucDeleteBuffers ogrDeleteBuffers; +extern ogrFucMapBuffer ogrMapBuffer; +extern ogrFucUnmapBuffer ogrUnmapBuffer; + RecorderConfig* getConfig(); const std::string& getSavedName(); void setCapturing(bool val);