-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathRenderAPI_OpenGLEAGL.h
More file actions
117 lines (98 loc) · 3.17 KB
/
RenderAPI_OpenGLEAGL.h
File metadata and controls
117 lines (98 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#ifndef RENDER_API_OPENGL_CGL_H
#define RENDER_API_OPENGL_CGL_H
#include "RenderAPI.h"
#include "PlatformBase.h"
#import <OpenGLES/EAGL.h>
#import <OpenGLES/ES2/gl.h>
#import <CoreVideo/CVMetalTextureCache.h>
#import <CoreVideo/CoreVideo.h>
#include <mutex>
#if defined(SHOW_WATERMARK)
#include "RenderAPI_OpenGLWatermark.h"
#endif
typedef struct libvlc_media_player_t libvlc_media_player_t;
struct RenderAPICoreVideoBuffer
{
CVPixelBufferRef cvpx = nil;
CVOpenGLESTextureRef texture = nil;
CVMetalTextureRef texture_metal = nil;
GLuint fbo = 0;
GLuint texture_name = 0;
~RenderAPICoreVideoBuffer()
{
if (texture)
CFRelease(texture);
if (cvpx)
CFRelease(cvpx);
if (texture_metal)
CFRelease(texture_metal);
}
RenderAPICoreVideoBuffer& operator=(RenderAPICoreVideoBuffer &&other)
{
// Release old resources before taking new ones
if (texture)
CFRelease(texture);
if (cvpx)
CFRelease(cvpx);
if (texture_metal)
CFRelease(texture_metal);
cvpx = other.cvpx;
other.cvpx = nil;
texture = other.texture;
other.texture = nil;
texture_metal = other.texture_metal;
other.texture_metal = nil;
fbo = other.fbo;
texture_name = other.texture_name;
return *this;
}
RenderAPICoreVideoBuffer(){}
RenderAPICoreVideoBuffer(RenderAPICoreVideoBuffer &&other)
{
*this = std::forward<RenderAPICoreVideoBuffer>(other);
}
};
class RenderAPI_OpenGLEAGL : public RenderAPI
{
public:
RenderAPI_OpenGLEAGL(UnityGfxRenderer apiType);
~RenderAPI_OpenGLEAGL() override {
if (_textureCache) {
CFRelease(_textureCache);
_textureCache = nil;
}
if (_textureCacheMetal) {
CFRelease(_textureCacheMetal);
_textureCacheMetal = nil;
}
}
void setVlcContext(libvlc_media_player_t *mp) override;
void ProcessDeviceEvent(UnityGfxDeviceEventType type, IUnityInterfaces* interfaces) override;
bool makeCurrent(bool current);
static void* get_proc_address(void* /*data*/, const char* current);
void swap(void* opaque);
static bool setup(void **opaque, const libvlc_video_setup_device_cfg_t *cfg, libvlc_video_setup_device_info_t *out);
static void cleanup(void* opaque);
static bool resize(void* opaque, const libvlc_video_render_cfg_t *cfg, libvlc_video_output_cfg_t *output);
void* getVideoFrame(unsigned width, unsigned height, bool* out_updated) override;
private:
void releaseFrameBufferResources();
RenderAPICoreVideoBuffer initBuffer(unsigned width, unsigned height);
CVOpenGLESTextureCacheRef _textureCache;
CVMetalTextureCacheRef _textureCacheMetal;
EAGLContext* m_context;
RenderAPICoreVideoBuffer buffers[3];
std::mutex text_lock;
unsigned width;
unsigned height;
GLuint fbo[3];
size_t idx_render = 0;
size_t idx_swap = 1;
size_t idx_display = 2;
bool updated;
#if defined(SHOW_WATERMARK)
OpenGLWatermark watermark;
#endif
libvlc_media_player_t *m_mp = nullptr;
};
#endif /* RENDER_API_OPENGL_CGL_H */