Loading...
Searching...
No Matches
GLCaptureUpload.hpp
Go to the documentation of this file.
1#pragma once
2
24
25#include <QtGui/private/qrhigles2_p.h>
26
27#include <QOpenGLContext>
28#include <QOpenGLExtraFunctions>
29
30#include <cstdint>
31
32// GL_BGRA is desktop-GL only. On an OpenGL ES build -- which is what Tegra and
33// most embedded targets use -- the same token is GL_BGRA_EXT, from
34// GL_EXT_texture_format_BGRA8888. Without this the whole gfx plugin fails to
35// compile for GLES rather than merely lacking the BGRA fast path.
36#if !defined(GL_BGRA) && defined(GL_BGRA_EXT)
37#define GL_BGRA GL_BGRA_EXT
38#endif
39
40namespace score::gfx::interop
41{
42
54 QOpenGLContext& glctx, QRhiTexture& outTex, const void* src,
55 bool bgra) noexcept
56{
57 if(!src)
58 return;
59 const auto nt = outTex.nativeTexture();
60 if(!nt.object)
61 return;
62 auto* f = glctx.extraFunctions();
63 if(!f)
64 return;
65
66 const auto sz = outTex.pixelSize();
67 const GLenum fmt = bgra ? GL_BGRA : GL_RGBA;
68 f->glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
69 f->glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
70 f->glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
71 f->glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
72 f->glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
73 f->glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(nt.object));
74 f->glTexSubImage2D(
75 GL_TEXTURE_2D, 0, 0, 0, sz.width(), sz.height(), fmt, GL_UNSIGNED_BYTE,
76 src);
77 f->glBindTexture(GL_TEXTURE_2D, 0);
78}
79
91 QOpenGLContext& glctx, QRhiTexture& outTex, std::uint32_t srcGlBuffer,
92 bool bgra) noexcept
93{
94 if(!srcGlBuffer)
95 return;
96 const auto nt = outTex.nativeTexture();
97 if(!nt.object)
98 return;
99 auto* f = glctx.extraFunctions();
100 if(!f)
101 return;
102
103 const auto sz = outTex.pixelSize();
104 const GLenum fmt = bgra ? GL_BGRA : GL_RGBA;
105 // The storage buffer can be bound to GL_PIXEL_UNPACK_BUFFER even though it
106 // was allocated for GL_SHADER_STORAGE_BUFFER: both are server-side memory;
107 // the binding target picks the usage, not the storage type.
108 f->glBindBuffer(GL_PIXEL_UNPACK_BUFFER, srcGlBuffer);
109 f->glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(nt.object));
110 f->glTexSubImage2D(
111 GL_TEXTURE_2D, 0, 0, 0, sz.width(), sz.height(), fmt, GL_UNSIGNED_BYTE,
112 nullptr);
113 f->glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
114 f->glBindTexture(GL_TEXTURE_2D, 0);
115}
116
117} // namespace score::gfx::interop
Backend-neutral plumbing shared by GPU-direct video CAPTURE strategies (no graphics-API headers).
void uploadClientToGLTexture(QOpenGLContext &glctx, QRhiTexture &outTex, const void *src, bool bgra) noexcept
Upload one captured frame from client memory into a QRhi GL texture.
Definition GLCaptureUpload.hpp:53
void uploadGLBufferToGLTexture(QOpenGLContext &glctx, QRhiTexture &outTex, std::uint32_t srcGlBuffer, bool bgra) noexcept
Upload one captured frame from a GL buffer (bound as PIXEL_UNPACK_BUFFER) into a QRhi GL texture.
Definition GLCaptureUpload.hpp:90