Remove glew include in libopenrecorder

This commit is contained in:
Benau 2017-04-10 01:26:52 +08:00
parent c69ea65ac2
commit ab10f335e9
6 changed files with 90 additions and 22 deletions

View File

@ -623,6 +623,12 @@ void IrrDriver::initDevice()
"RecorderConfig is invalid, use the default one."); "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, ogrRegGeneralCallback(OGR_CBT_START_RECORDING,
[] (void* user_data) { MessageQueue::add [] (void* user_data) { MessageQueue::add
(MessageQueue::MT_GENERIC, _("Video recording started.")); }, NULL); (MessageQueue::MT_GENERIC, _("Video recording started.")); }, NULL);

View File

@ -8,11 +8,6 @@
#include "vpx_encoder.hpp" #include "vpx_encoder.hpp"
#include "wasapi_recorder.hpp" #include "wasapi_recorder.hpp"
extern "C"
{
#include <GL/glew.h>
}
const uint32_t E_GL_PIXEL_PACK_BUFFER = 0x88EB; const uint32_t E_GL_PIXEL_PACK_BUFFER = 0x88EB;
const uint32_t E_GL_STREAM_READ = 0x88E1; const uint32_t E_GL_STREAM_READ = 0x88E1;
const uint32_t E_GL_READ_ONLY = 0x88B8; const uint32_t E_GL_READ_ONLY = 0x88B8;
@ -30,14 +25,14 @@ CaptureLibrary::CaptureLibrary(RecorderConfig* rc)
m_decompress_handle = tjInitDecompress(); m_decompress_handle = tjInitDecompress();
if (m_recorder_cfg->m_triple_buffering > 0) if (m_recorder_cfg->m_triple_buffering > 0)
{ {
glGenBuffers(3, m_pbo); ogrGenBuffers(3, m_pbo);
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
glBindBuffer(GL_PIXEL_PACK_BUFFER, m_pbo[i]); ogrBindBuffer(E_GL_PIXEL_PACK_BUFFER, m_pbo[i]);
glBufferData(GL_PIXEL_PACK_BUFFER, m_recorder_cfg->m_width * ogrBufferData(E_GL_PIXEL_PACK_BUFFER, m_recorder_cfg->m_width *
m_recorder_cfg->m_height * 4, NULL, GL_STREAM_READ); 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); m_capture_thread = std::thread(CaptureLibrary::captureConversion, this);
} // CaptureLibrary } // CaptureLibrary
@ -52,7 +47,7 @@ CaptureLibrary::~CaptureLibrary()
tjDestroy(m_decompress_handle); tjDestroy(m_decompress_handle);
if (m_recorder_cfg->m_triple_buffering > 0) if (m_recorder_cfg->m_triple_buffering > 0)
{ {
glDeleteBuffers(3, m_pbo); ogrDeleteBuffers(3, m_pbo);
} }
} // ~CaptureLibrary } // ~CaptureLibrary
@ -176,15 +171,16 @@ void CaptureLibrary::capture()
if (use_pbo) if (use_pbo)
{ {
pbo_read = m_pbo_use % 3; pbo_read = m_pbo_use % 3;
glBindBuffer(GL_PIXEL_PACK_BUFFER, m_pbo[pbo_read]); ogrBindBuffer(E_GL_PIXEL_PACK_BUFFER, m_pbo[pbo_read]);
void* ptr = glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY); void* ptr = ogrMapBuffer(E_GL_PIXEL_PACK_BUFFER,
E_GL_READ_ONLY);
memcpy(fbi, ptr, size); memcpy(fbi, ptr, size);
glUnmapBuffer(GL_PIXEL_PACK_BUFFER); ogrUnmapBuffer(E_GL_PIXEL_PACK_BUFFER);
} }
else else
{ {
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, ogrReadPixels(0, 0, width, height, E_GL_RGBA,
fbi); E_GL_UNSIGNED_BYTE, fbi);
} }
addFrameBufferImage(fbi, frame_count); addFrameBufferImage(fbi, frame_count);
} }
@ -194,9 +190,9 @@ void CaptureLibrary::capture()
return; return;
assert(pbo_read == -1 || pbo_use == pbo_read); assert(pbo_read == -1 || pbo_use == pbo_read);
glBindBuffer(GL_PIXEL_PACK_BUFFER, m_pbo[pbo_use]); ogrBindBuffer(E_GL_PIXEL_PACK_BUFFER, m_pbo[pbo_use]);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, NULL); ogrReadPixels(0, 0, width, height, E_GL_RGBA, E_GL_UNSIGNED_BYTE, NULL);
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); ogrBindBuffer(E_GL_PIXEL_PACK_BUFFER, 0);
} // capture } // capture
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@ -20,8 +20,6 @@
#include "capture_library.hpp" #include "capture_library.hpp"
#include "recorder_private.hpp" #include "recorder_private.hpp"
#include <turbojpeg.h>
namespace Recorder namespace Recorder
{ {
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------

View File

@ -2,6 +2,8 @@
#ifndef HEADER_OPENGLRECORDER_H #ifndef HEADER_OPENGLRECORDER_H
#define HEADER_OPENGLRECORDER_H #define HEADER_OPENGLRECORDER_H
#include <stddef.h>
/** /**
* \mainpage libopenglrecorder * \mainpage libopenglrecorder
* *
@ -160,6 +162,16 @@ struct RecorderConfig
unsigned int m_record_jpg_quality; 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 #ifdef __cplusplus
extern "C" extern "C"
{ {
@ -214,6 +226,16 @@ void ogrRegIntCallback(CallBackType, IntCallback, void*);
* Return 1 if recording is happening in libopenglrecorder, 0 otherwise. * Return 1 if recording is happening in libopenglrecorder, 0 otherwise.
*/ */
int ogrCapturing(void); 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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -8,6 +8,14 @@
#include <memory> #include <memory>
#include <cstring> #include <cstring>
// ============================================================================
ogrFucReadPixels ogrReadPixels = NULL;
ogrFucGenBuffers ogrGenBuffers = NULL;
ogrFucBindBuffer ogrBindBuffer = NULL;
ogrFucBufferData ogrBufferData = NULL;
ogrFucDeleteBuffers ogrDeleteBuffers = NULL;
ogrFucMapBuffer ogrMapBuffer = NULL;
ogrFucUnmapBuffer ogrUnmapBuffer = NULL;
// ============================================================================ // ============================================================================
std::unique_ptr<RecorderConfig> g_recorder_config(nullptr); std::unique_ptr<RecorderConfig> g_recorder_config(nullptr);
// ============================================================================ // ============================================================================
@ -105,7 +113,8 @@ const std::string& getSavedName()
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void ogrPrepareCapture(void) 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) if (g_capture_library.get() == nullptr)
{ {
assert(g_recorder_config.get() != nullptr); assert(g_recorder_config.get() != nullptr);
@ -243,6 +252,35 @@ int ogrCapturing(void)
return g_capturing.load() ? 1 : 0; return g_capturing.load() ? 1 : 0;
} // ogrCapturing } // 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) void setCapturing(bool val)
{ {

View File

@ -6,6 +6,14 @@
#include <string> #include <string>
extern ogrFucReadPixels ogrReadPixels;
extern ogrFucGenBuffers ogrGenBuffers;
extern ogrFucBindBuffer ogrBindBuffer;
extern ogrFucBufferData ogrBufferData;
extern ogrFucDeleteBuffers ogrDeleteBuffers;
extern ogrFucMapBuffer ogrMapBuffer;
extern ogrFucUnmapBuffer ogrUnmapBuffer;
RecorderConfig* getConfig(); RecorderConfig* getConfig();
const std::string& getSavedName(); const std::string& getSavedName();
void setCapturing(bool val); void setCapturing(bool val);