GlImageSink Callback Issue

Matthew Waters ystreet00 at gmail.com
Mon Aug 2 02:40:50 UTC 2021


Take a look at

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>.

I can notice a couple of things wrong:
1. Vertex glBufferData call is taking the address of an array that 
should not be taken.
2. No retrieval of the vertex attribute locations (GPU driver decides these)
3. You may not be creating the VAO in the correct thread? VAO's are not 
OpenGL shareable resource across OpenGL contexts.

Cheers
-Matt

On 2/8/21 5:47 am, Edward Anon via gstreamer-devel wrote:
> 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.
>
> 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.
>
> ```
> gboolean drawCallback (GstElement * gl_sink, GstGLContext *context, GstSample * sample, gpointer data) {
>    assert(gl_sink); assert(context); assert(sample); assert(not data); GstVideoFrame v_frame; GstVideoInfo v_info; GstBuffer *buf = gst_sample_get_buffer (sample); GstCaps *caps = gst_sample_get_caps (sample); gst_video_info_from_caps (&v_info, caps); if (!gst_video_frame_map (&v_frame, &v_info, buf, (GstMapFlags) (GST_MAP_READ |GST_MAP_GL))) {
>        g_warning ("Failed to map the video buffer"); return TRUE; }
>
>    GLuint texture_id = *(guint *) v_frame.data[0]; Texture t; t.from(texture_id, Texture::TextureType::COLOUR); t.render(); return true; }
> ```
>
> 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```.
>
> The render code is as follows:
> ```
> if (texture_type !=UNINITIALISED) {
>    switch (texture_type) {
>    case COLOUR:
>      colour_shader.use(); break;
> // other texture type setup
> default:
>      throw std::runtime_error("Unsupported texture type"); }
>
>    glBindVertexArray(quadVAO); glDisable(GL_DEPTH_TEST); glBindTexture(GL_TEXTURE_2D, opengl_texture); glDrawArrays(GL_TRIANGLES, 0, 6); glBindTexture(GL_TEXTURE_2D, 0); glEnable(GL_DEPTH_TEST); }
> ```
> Shaders, VAO and VBO set up as follows:
> ```
>      glGenVertexArrays(1, &quadVAO); glBindVertexArray(quadVAO); glGenBuffers(1, &quadVBO); glBindBuffer(GL_ARRAY_BUFFER, quadVBO); glBindVertexArray(quadVAO); glBindBuffer(GL_ARRAY_BUFFER, quadVBO); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 *sizeof(float), (void *)nullptr); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 *sizeof(float), (void *)(2 *sizeof(float)));constexpr float quadVertices[] = {
>          // positions // texCoords 1.0f, -1.0f, 0, 1, // top left 1.0f, 1.0f, 0, 0, // bottom left -1.0f, 1.0f, 1, 0, // bottom right 1.0f, -1.0f, 0, 1, // top left -1.0f, 1.0f, 1, 0, // bottom right -1.0f, -1.0f, 1, 1 // top right }; glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), &quadVertices, GL_STATIC_DRAW); glBindVertexArray(0); colour_shader = Shader(shaderRoot+ "quadFromTexture.vs", shaderRoot+ "colourTexture.fs");
> // setup other shaders
> ```
>
> What am I doing wrong?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20210802/f98c562d/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 495 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20210802/f98c562d/attachment.sig>


More information about the gstreamer-devel mailing list