static gboolean
gst_gl_mosaic_init_shader (GstGLMixer * mixer, GstCaps * outcaps)
{
  GstGLMosaic *mosaic = GST_GL_MOSAIC (mixer);

  g_clear_object (&mosaic->shader);
  //blocking call, wait the opengl thread has compiled the shader
  return gst_gl_context_gen_shader (GST_GL_BASE_MIXER (mixer)->context,
      mosaic_v_src, mosaic_f_src, &mosaic->shader);
}
static void
gst_gl_mosaic_reset (GstGLMixer * mixer)
{
  GstGLMosaic *mosaic = GST_GL_MOSAIC (mixer);

  //blocking call, wait the opengl thread has destroyed the shader
  if (mosaic->shader)
    gst_object_unref (mosaic->shader);
  mosaic->shader = NULL;
}
Beispiel #3
0
static void
gst_gl_mosaic_reset (GstGLMixer * mixer)
{
  GstGLMosaic *mosaic = GST_GL_MOSAIC (mixer);

  mosaic->input_gl_buffers = NULL;

  //blocking call, wait the opengl thread has destroyed the shader
  gst_gl_display_del_shader (mixer->display, mosaic->shader);
}
Beispiel #4
0
static gboolean
gst_gl_mosaic_init_shader (GstGLMixer * mixer, GstCaps * outcaps)
{
  GstGLMosaic *mosaic = GST_GL_MOSAIC (mixer);

  //blocking call, wait the opengl thread has compiled the shader
  gst_gl_display_gen_shader (mixer->display, mosaic_v_src, mosaic_f_src,
      &mosaic->shader);

  return TRUE;
}
static gboolean
gst_gl_mosaic_process_textures (GstGLMixer * mix, GstGLMemory * out_tex)
{
  GstGLMosaic *mosaic = GST_GL_MOSAIC (mix);
  GstGLContext *context = GST_GL_BASE_MIXER (mix)->context;

  mosaic->out_tex = out_tex;

  gst_gl_context_thread_add (context, (GstGLContextThreadFunc) _mosaic_render,
      mosaic);

  return TRUE;
}
Beispiel #6
0
static gboolean
gst_gl_mosaic_proc (GstGLMixer * mix, GPtrArray * buffers, GstBuffer * outbuf)
{
  GstGLMosaic *mosaic = GST_GL_MOSAIC (mix);
  GstGLBuffer *gl_out_buffer = GST_GL_BUFFER (outbuf);

  mosaic->input_gl_buffers = buffers;

  //blocking call, use a FBO
  gst_gl_display_use_fbo_v2 (mix->display, mix->width, mix->height,
      mix->fbo, mix->depthbuffer, gl_out_buffer->texture,
      gst_gl_mosaic_callback, (gpointer) mosaic);

  return TRUE;
}
/* opengl scene, params: input texture (not the output mixer->texture) */
static gboolean
gst_gl_mosaic_callback (gpointer stuff)
{
  GstGLMosaic *mosaic = GST_GL_MOSAIC (stuff);
  GstGLMixer *mixer = GST_GL_MIXER (mosaic);
  GstGLFuncs *gl = GST_GL_BASE_MIXER (mixer)->context->gl_vtable;
  GList *walk;

  static GLfloat xrot = 0;
  static GLfloat yrot = 0;
  static GLfloat zrot = 0;

  GLint attr_position_loc = 0;
  GLint attr_texture_loc = 0;

  const GLfloat matrix[] = {
    0.5f, 0.0f, 0.0f, 0.0f,
    0.0f, 0.5f, 0.0f, 0.0f,
    0.0f, 0.0f, 0.5f, 0.0f,
    0.0f, 0.0f, 0.0f, 1.0f
  };
  const GLushort indices[] = {
    0, 1, 2,
    0, 2, 3
  };

  guint count = 0;

  gst_gl_context_clear_shader (GST_GL_BASE_MIXER (mixer)->context);
  gl->BindTexture (GL_TEXTURE_2D, 0);

  gl->Enable (GL_DEPTH_TEST);

  gl->ClearColor (0.0, 0.0, 0.0, 0.0);
  gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  gst_gl_shader_use (mosaic->shader);

  attr_position_loc =
      gst_gl_shader_get_attribute_location (mosaic->shader, "a_position");
  attr_texture_loc =
      gst_gl_shader_get_attribute_location (mosaic->shader, "a_texCoord");

  GST_OBJECT_LOCK (mosaic);
  walk = GST_ELEMENT (mosaic)->sinkpads;
  while (walk) {
    GstGLMixerPad *pad = walk->data;
    /* *INDENT-OFF* */
    gfloat v_vertices[] = {
      /* front face */
       1.0f, 1.0f,-1.0f, 1.0f, 0.0f,
       1.0f,-1.0f,-1.0f, 1.0f, 1.0f,
      -1.0f,-1.0f,-1.0f, 0.0f, 1.0f,
      -1.0f, 1.0f,-1.0f, 0.0f, 0.0f,
      /* right face */
       1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
       1.0f,-1.0f, 1.0f, 0.0f, 0.0f,
       1.0f,-1.0f,-1.0f, 0.0f, 1.0f,
       1.0f, 1.0f,-1.0f, 1.0f, 1.0f,
      /* left face */
      -1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
      -1.0f, 1.0f,-1.0f, 1.0f, 1.0f,
      -1.0f,-1.0f,-1.0f, 0.0f, 1.0f,
      -1.0f,-1.0f, 1.0f, 0.0f, 0.0f,
      /* top face */
       1.0f,-1.0f, 1.0f, 1.0f, 0.0f,
      -1.0f,-1.0f, 1.0f, 0.0f, 0.0f,
      -1.0f,-1.0f,-1.0f, 0.0f, 1.0f,
       1.0f,-1.0f,-1.0f, 1.0f, 1.0f,
      /* bottom face */
       1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
       1.0f, 1.0f,-1.0f, 1.0f, 1.0f,
      -1.0f, 1.0f,-1.0f, 0.0f, 1.0f,
      -1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
      /* back face */
       1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
      -1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
      -1.0f,-1.0f, 1.0f, 0.0f, 1.0f,
       1.0f,-1.0f, 1.0f, 1.0f, 1.0f
    };
    /* *INDENT-ON* */
    guint in_tex;
    guint width, height;

    in_tex = pad->current_texture;
    width = GST_VIDEO_INFO_WIDTH (&GST_VIDEO_AGGREGATOR_PAD (pad)->info);
    height = GST_VIDEO_INFO_HEIGHT (&GST_VIDEO_AGGREGATOR_PAD (pad)->info);

    if (!in_tex || width <= 0 || height <= 0) {
      GST_DEBUG ("skipping texture:%u pad:%p width:%u height %u",
          in_tex, pad, width, height);
      count++;
      walk = g_list_next (walk);
      continue;
    }

    GST_TRACE ("processing texture:%u dimensions:%ux%u", in_tex, width, height);

    gl->VertexAttribPointer (attr_position_loc, 3, GL_FLOAT,
        GL_FALSE, 5 * sizeof (GLfloat), &v_vertices[5 * 4 * count]);

    gl->VertexAttribPointer (attr_texture_loc, 2, GL_FLOAT,
        GL_FALSE, 5 * sizeof (GLfloat), &v_vertices[5 * 4 * count + 3]);

    gl->EnableVertexAttribArray (attr_position_loc);
    gl->EnableVertexAttribArray (attr_texture_loc);

    gl->ActiveTexture (GL_TEXTURE0);
    gl->BindTexture (GL_TEXTURE_2D, in_tex);
    gst_gl_shader_set_uniform_1i (mosaic->shader, "s_texture", 0);
    gst_gl_shader_set_uniform_1f (mosaic->shader, "xrot_degree", xrot);
    gst_gl_shader_set_uniform_1f (mosaic->shader, "yrot_degree", yrot);
    gst_gl_shader_set_uniform_1f (mosaic->shader, "zrot_degree", zrot);
    gst_gl_shader_set_uniform_matrix_4fv (mosaic->shader, "u_matrix", 1,
        GL_FALSE, matrix);

    gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);

    ++count;

    walk = g_list_next (walk);
  }
  GST_OBJECT_UNLOCK (mosaic);

  gl->DisableVertexAttribArray (attr_position_loc);
  gl->DisableVertexAttribArray (attr_texture_loc);

  gl->BindTexture (GL_TEXTURE_2D, 0);

  gl->Disable (GL_DEPTH_TEST);

  gst_gl_context_clear_shader (GST_GL_BASE_MIXER (mixer)->context);

  xrot += 0.6f;
  yrot += 0.4f;
  zrot += 0.8f;

  return TRUE;
}
Beispiel #8
0
//opengl scene, params: input texture (not the output mixer->texture)
static void
gst_gl_mosaic_callback (gpointer stuff)
{
  GstGLMosaic *mosaic = GST_GL_MOSAIC (stuff);

  static GLfloat xrot = 0;
  static GLfloat yrot = 0;
  static GLfloat zrot = 0;

  GLint attr_position_loc = 0;
  GLint attr_texture_loc = 0;

  const GLfloat matrix[] = {
    0.5f, 0.0f, 0.0f, 0.0f,
    0.0f, 0.5f, 0.0f, 0.0f,
    0.0f, 0.0f, 0.5f, 0.0f,
    0.0f, 0.0f, 0.0f, 1.0f
  };

  const GLushort indices[] = {
    0, 1, 2,
    0, 2, 3
  };

  guint count = 0;
  gboolean do_next = TRUE;

  gst_gl_shader_use (NULL);
  glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 0);
  glDisable (GL_TEXTURE_RECTANGLE_ARB);

  glEnable (GL_DEPTH_TEST);

  glClearColor (0.0, 0.0, 0.0, 0.0);
  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  gst_gl_shader_use (mosaic->shader);

  attr_position_loc =
      gst_gl_shader_get_attribute_location (mosaic->shader, "a_position");
  attr_texture_loc =
      gst_gl_shader_get_attribute_location (mosaic->shader, "a_texCoord");

  while (do_next && count < mosaic->input_gl_buffers->len && count < 6) {
    GstGLBuffer *gl_in_buffer =
        g_ptr_array_index (mosaic->input_gl_buffers, count);

    if (gl_in_buffer && gl_in_buffer->texture) {
      GLuint texture = gl_in_buffer->texture;
      GLfloat width = (GLfloat) gl_in_buffer->width;
      GLfloat height = (GLfloat) gl_in_buffer->height;

      const GLfloat v_vertices[] = {

        //front face
        1.0f, 1.0f, -1.0f,
        width, 0.0f,
        1.0f, -1.0f, -1.0f,
        width, height,
        -1.0f, -1.0f, -1.0f,
        0.0f, height,
        -1.0f, 1.0f, -1.0f,
        0.0f, 0.0f,
        //right face
        1.0f, 1.0f, 1.0f,
        width, 0.0f,
        1.0f, -1.0f, 1.0f,
        0.0f, 0.0f,
        1.0f, -1.0f, -1.0f,
        0.0f, height,
        1.0f, 1.0f, -1.0f,
        width, height,
        //left face
        -1.0f, 1.0f, 1.0f,
        width, 0.0f,
        -1.0f, 1.0f, -1.0f,
        width, height,
        -1.0f, -1.0f, -1.0f,
        0.0f, height,
        -1.0f, -1.0f, 1.0f,
        0.0f, 0.0f,
        //top face
        1.0f, -1.0f, 1.0f,
        width, 0.0f,
        -1.0f, -1.0f, 1.0f,
        0.0f, 0.0f,
        -1.0f, -1.0f, -1.0f,
        0.0f, height,
        1.0f, -1.0f, -1.0f,
        width, height,
        //bottom face
        1.0f, 1.0f, 1.0f,
        width, 0.0f,
        1.0f, 1.0f, -1.0f,
        width, height,
        -1.0f, 1.0f, -1.0f,
        0.0f, height,
        -1.0f, 1.0f, 1.0f,
        0.0f, 0.0f,
        //back face
        1.0f, 1.0f, 1.0f,
        width, 0.0f,
        -1.0f, 1.0f, 1.0f,
        0.0f, 0.0f,
        -1.0f, -1.0f, 1.0f,
        0.0f, height,
        1.0f, -1.0f, 1.0f,
        width, height
      };

      glVertexAttribPointerARB (attr_position_loc, 3, GL_FLOAT,
          GL_FALSE, 5 * sizeof (GLfloat), &v_vertices[5 * 4 * count]);

      glVertexAttribPointerARB (attr_texture_loc, 2, GL_FLOAT,
          GL_FALSE, 5 * sizeof (GLfloat), &v_vertices[5 * 4 * count + 3]);

      glEnableVertexAttribArrayARB (attr_position_loc);
      glEnableVertexAttribArrayARB (attr_texture_loc);

      glActiveTextureARB (GL_TEXTURE0_ARB);
      glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
      gst_gl_shader_set_uniform_1i (mosaic->shader, "s_texture", 0);
      gst_gl_shader_set_uniform_1f (mosaic->shader, "xrot_degree", xrot);
      gst_gl_shader_set_uniform_1f (mosaic->shader, "yrot_degree", yrot);
      gst_gl_shader_set_uniform_1f (mosaic->shader, "zrot_degree", zrot);
      gst_gl_shader_set_uniform_matrix_4fv (mosaic->shader, "u_matrix", 1,
          GL_FALSE, matrix);

      glDrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);

      ++count;
    } else {
      do_next = FALSE;
    }
  }

  glDisableVertexAttribArrayARB (attr_position_loc);
  glDisableVertexAttribArrayARB (attr_texture_loc);

  glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 0);

  glDisable (GL_DEPTH_TEST);

  gst_gl_shader_use (NULL);

  xrot += 0.6f;
  yrot += 0.4f;
  zrot += 0.8f;
}