<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
Take a look at<br>
<br>
<a moz-do-not-send="true"
href="https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/blob/master/gst-libs/gst/gl/gstglfilter.c#L1165">https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/blob/master/gst-libs/gst/gl/gstglfilter.c#L1165</a>.<br>
<br>
I can notice a couple of things wrong:<br>
1. Vertex glBufferData call is taking the address of an array that
should not be taken.<br>
2. No retrieval of the vertex attribute locations (GPU driver
decides these)<br>
3. You may not be creating the VAO in the correct thread? VAO's are
not OpenGL shareable resource across OpenGL contexts.<br>
<br>
Cheers<br>
-Matt<br>
<br>
<div class="moz-cite-prefix">On 2/8/21 5:47 am, Edward Anon via
gstreamer-devel wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAKQvMEtfqXGO7MTF8nM94cTvmEs3TbLYon15F5vyawtgYAc8XQ@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">
<div>My client takes a camera feed over RTP. I want to render an
overlay onto it using opengl. Hence, I want to use
GlImageSink in my application as it provides me with the next
frame already in a texture. I want to blit the already
rendered overlay onto the texture prior to rendering.<br>
<br>
</div>
<div>As a first step I am writing a simple draw callback which
should just render the texture to the screen. I am basing my
callback on the cube example in the gst-plugins-base source.</div>
<div><br>
</div>
<div>```</div>
<div>
<pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:"JetBrains Mono",monospace;font-size:9.8pt"><span style="color:rgb(185,188,209)">gboolean </span><span style="color:rgb(255,198,109)">drawCallback </span>(<span style="color:rgb(185,188,209)">GstElement </span>* gl_sink<span style="color:rgb(204,120,50)">, </span><span style="color:rgb(185,188,209)">GstGLContext </span>*context<span style="color:rgb(204,120,50)">, </span><span style="color:rgb(185,188,209)">GstSample </span>* sample<span style="color:rgb(204,120,50)">, </span><span style="color:rgb(185,188,209)">gpointer </span>data) {
<span style="color:rgb(144,139,37)">assert</span>(gl_sink)<span style="color:rgb(204,120,50)">; </span><span style="color:rgb(144,139,37)">assert</span>(context)<span style="color:rgb(204,120,50)">; </span><span style="color:rgb(144,139,37)">assert</span>(sample)<span style="color:rgb(204,120,50)">; </span><span style="color:rgb(144,139,37)">assert</span>(<span style="color:rgb(204,120,50)">not </span>data)<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)">
</span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(185,188,209)">GstVideoFrame </span>v_frame<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(185,188,209)">GstVideoInfo </span>v_info<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(185,188,209)">GstBuffer </span>*buf = gst_sample_get_buffer (sample)<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(185,188,209)">GstCaps </span>*caps = gst_sample_get_caps (sample)<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)">
</span><span style="color:rgb(204,120,50)"> </span>gst_video_info_from_caps (&v_info<span style="color:rgb(204,120,50)">, </span>caps)<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)">
</span><span style="color:rgb(204,120,50)"> if </span>(!gst_video_frame_map (&v_frame<span style="color:rgb(204,120,50)">, </span>&v_info<span style="color:rgb(204,120,50)">, </span>buf<span style="color:rgb(204,120,50)">, </span>(<span style="color:rgb(185,188,209)">GstMapFlags</span>) (<span style="color:rgb(152,118,170);font-style:italic">GST_MAP_READ </span>| <span style="color:rgb(144,139,37)">GST_MAP_GL</span>))) {
<span style="color:rgb(144,139,37)">g_warning </span>(<span style="color:rgb(106,135,89)">"Failed to map the video buffer"</span>)<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)"> return </span><span style="color:rgb(144,139,37)">TRUE</span><span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)"> </span>}
<span style="color:rgb(185,188,209)">GLuint </span>texture_id = *(<span style="color:rgb(185,188,209)">guint </span>*) v_frame.<span style="color:rgb(147,115,165)">data</span>[<span style="color:rgb(104,151,187)">0</span>]<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(181,182,227)">Texture </span>t<span style="color:rgb(204,120,50)">; </span>t.from(texture_id<span style="color:rgb(204,120,50)">, </span><span style="color:rgb(181,182,227)">Texture</span>::<span style="color:rgb(181,182,227)">TextureType</span>::<span style="color:rgb(152,118,170);font-style:italic">COLOUR</span>)<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)">
</span><span style="color:rgb(204,120,50)"> </span>t.render()<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)">
</span><span style="color:rgb(204,120,50)"> return true;
</span>}</pre>
```<br>
<br>
</div>
<div>However, I get the following error: ```gldebug
gstgldebug.c:306:_gst_gl_debug_callback:<glcontextglx0>
high: GL error from API id:1, GL_INVALID_OPERATION in
glDrawArrays```.<br>
<br>
</div>
<div>The render code is as follows:<br>
```<br>
<pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:"JetBrains Mono",monospace;font-size:9.8pt"><span style="color:rgb(204,120,50)">if </span>(texture_type != <span style="color:rgb(152,118,170);font-style:italic">UNINITIALISED</span>) {
<span style="color:rgb(204,120,50)">switch </span>(texture_type) {
<span style="color:rgb(204,120,50)">case </span><span style="color:rgb(152,118,170);font-style:italic">COLOUR</span>:
<span style="color:rgb(147,115,165)">colour_shader</span>.use()<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)"> break;
</span></pre>
<pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:"JetBrains Mono",monospace;font-size:9.8pt"><span style="color:rgb(204,120,50)">// other texture type setup
</span></pre>
<pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:"JetBrains Mono",monospace;font-size:9.8pt"><span style="color:rgb(204,120,50)"> default</span>:
<span style="color:rgb(204,120,50)">throw </span><span style="color:rgb(181,182,227)">std</span>::runtime_error(<span style="color:rgb(106,135,89)">"Unsupported texture type"</span>)<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)"> </span>}
<span style="color:rgb(144,139,37)">glBindVertexArray</span>(<span style="color:rgb(147,115,165)">quadVAO</span>)<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(144,139,37)">glDisable</span>(<span style="color:rgb(144,139,37)">GL_DEPTH_TEST</span>)<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(144,139,37)">glBindTexture</span>(<span style="color:rgb(144,139,37)">GL_TEXTURE_2D</span><span style="color:rgb(204,120,50)">, </span>opengl_texture)<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(144,139,37)">glDrawArrays</span>(<span style="color:rgb(144,139,37)">GL_TRIANGLES</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(104,151,187)">0</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(104,151,187)">6</span>)<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(144,139,37)">glBindTexture</span>(<span style="color:rgb(144,139,37)">GL_TEXTURE_2D</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(104,151,187)">0</span>)<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(144,139,37)">glEnable</span>(<span style="color:rgb(144,139,37)">GL_DEPTH_TEST</span>)<span style="color:rgb(204,120,50)">;
</span>}</pre>
```<br>
</div>
<div>Shaders, VAO and VBO set up as follows:<br>
```<br>
<pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:"JetBrains Mono",monospace;font-size:9.8pt"> <span style="color:rgb(144,139,37)">glGenVertexArrays</span>(<span style="color:rgb(104,151,187)">1</span><span style="color:rgb(204,120,50)">, </span>&<span style="color:rgb(147,115,165)">quadVAO</span>)<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(144,139,37)">glBindVertexArray</span>(<span style="color:rgb(147,115,165)">quadVAO</span>)<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)">
</span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(144,139,37)">glGenBuffers</span>(<span style="color:rgb(104,151,187)">1</span><span style="color:rgb(204,120,50)">, </span>&<span style="color:rgb(147,115,165)">quadVBO</span>)<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(144,139,37)">glBindBuffer</span>(<span style="color:rgb(144,139,37)">GL_ARRAY_BUFFER</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(147,115,165)">quadVBO</span>)<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)">
</span><span style="color:rgb(204,120,50)">
</span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(144,139,37)">glBindVertexArray</span>(<span style="color:rgb(147,115,165)">quadVAO</span>)<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(144,139,37)">glBindBuffer</span>(<span style="color:rgb(144,139,37)">GL_ARRAY_BUFFER</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(147,115,165)">quadVBO</span>)<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(144,139,37)">glEnableVertexAttribArray</span>(<span style="color:rgb(104,151,187)">0</span>)<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(144,139,37)">glVertexAttribPointer</span>(<span style="color:rgb(104,151,187)">0</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(104,151,187)">2</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(144,139,37)">GL_FLOAT</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(144,139,37)">GL_FALSE</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(104,151,187)">4 </span>* <span style="color:rgb(204,120,50)">sizeof</span>(<span style="color:rgb(204,120,50)">float</span>)<span style="color:rgb(204,120,50)">,
</span><span style="color:rgb(204,120,50)"> </span>(<span style="color:rgb(204,120,50)">void </span>*)<span style="color:rgb(204,120,50)">nullptr</span>)<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(144,139,37)">glEnableVertexAttribArray</span>(<span style="color:rgb(104,151,187)">1</span>)<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(144,139,37)">glVertexAttribPointer</span>(<span style="color:rgb(104,151,187)">1</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(104,151,187)">2</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(144,139,37)">GL_FLOAT</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(144,139,37)">GL_FALSE</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(104,151,187)">4 </span>* <span style="color:rgb(204,120,50)">sizeof</span>(<span style="color:rgb(204,120,50)">float</span>)<span style="color:rgb(204,120,50)">,
</span><span style="color:rgb(204,120,50)"> </span>(<span style="color:rgb(204,120,50)">void </span>*)(<span style="color:rgb(104,151,187)">2 </span>* <span style="color:rgb(204,120,50)">sizeof</span>(<span style="color:rgb(204,120,50)">float</span>)))<span style="color:rgb(204,120,50)">;</span><span style="color:rgb(128,128,128)">
</span><span style="color:rgb(128,128,128)">
</span><span style="color:rgb(128,128,128)"> </span><span style="color:rgb(204,120,50)">constexpr float </span>quadVertices[] = {
<span style="color:rgb(128,128,128)">// positions // texCoords
</span><span style="color:rgb(128,128,128)"> </span><span style="color:rgb(104,151,187)">1.0f</span><span style="color:rgb(204,120,50)">, </span>-<span style="color:rgb(104,151,187)">1.0f</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(104,151,187)">0</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(104,151,187)">1</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(128,128,128)">// top left
</span><span style="color:rgb(128,128,128)"> </span><span style="color:rgb(104,151,187)">1.0f</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(104,151,187)">1.0f</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(104,151,187)">0</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(104,151,187)">0</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(128,128,128)">// bottom left
</span><span style="color:rgb(128,128,128)"> </span>-<span style="color:rgb(104,151,187)">1.0f</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(104,151,187)">1.0f</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(104,151,187)">1</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(104,151,187)">0</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(128,128,128)">// bottom right
</span><span style="color:rgb(128,128,128)">
</span><span style="color:rgb(128,128,128)"> </span><span style="color:rgb(104,151,187)">1.0f</span><span style="color:rgb(204,120,50)">, </span>-<span style="color:rgb(104,151,187)">1.0f</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(104,151,187)">0</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(104,151,187)">1</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(128,128,128)">// top left
</span><span style="color:rgb(128,128,128)"> </span>-<span style="color:rgb(104,151,187)">1.0f</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(104,151,187)">1.0f</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(104,151,187)">1</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(104,151,187)">0</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(128,128,128)">// bottom right
</span><span style="color:rgb(128,128,128)"> </span>-<span style="color:rgb(104,151,187)">1.0f</span><span style="color:rgb(204,120,50)">, </span>-<span style="color:rgb(104,151,187)">1.0f</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(104,151,187)">1</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(104,151,187)">1 </span><span style="color:rgb(128,128,128)">// top right
</span><span style="color:rgb(128,128,128)"> </span>}<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)">
</span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(144,139,37)">glBufferData</span>(<span style="color:rgb(144,139,37)">GL_ARRAY_BUFFER</span><span style="color:rgb(204,120,50)">, sizeof</span>(quadVertices)<span style="color:rgb(204,120,50)">, </span>&quadVertices<span style="color:rgb(204,120,50)">,
</span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(144,139,37)">GL_STATIC_DRAW</span>)<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)">
</span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(144,139,37)">glBindVertexArray</span>(<span style="color:rgb(104,151,187)">0</span>)<span style="color:rgb(204,120,50)">;
</span><span style="color:rgb(204,120,50)">
</span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(147,115,165)">colour_shader </span>= Shader(shaderRoot <span style="color:rgb(95,140,138)">+ </span><span style="color:rgb(106,135,89)">"quadFromTexture.vs"</span><span style="color:rgb(204,120,50)">,
</span><span style="color:rgb(204,120,50)"> </span>shaderRoot <span style="color:rgb(95,140,138)">+ </span><span style="color:rgb(106,135,89)">"colourTexture.fs"</span>)<span style="color:rgb(204,120,50)">;
</span></pre>
<pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:"JetBrains Mono",monospace;font-size:9.8pt"><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(204,120,50)">// setup other shaders</span></pre>
```<br>
<br>
</div>
<div>What am I doing wrong?</div>
</div>
</blockquote>
<br>
</body>
</html>