GlImageSink Callback Issue

Edward Anon blakat360 at gmail.com
Sun Aug 1 19:47:24 UTC 2021


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/20210801/69eefa3e/attachment-0001.htm>


More information about the gstreamer-devel mailing list