Ejemplo n.º 1
0
static gboolean
gst_gl_alpha_gl_start (GstGLBaseFilter * base_filter)
{
  GstGLAlpha *alpha = GST_GL_ALPHA (base_filter);

  if (!_create_shader (alpha))
    return FALSE;

  return GST_GL_BASE_FILTER_CLASS (parent_class)->gl_start (base_filter);
}
Ejemplo n.º 2
0
static GLuint _shader_init(const char *vs_path, const char *fs_path) {
    GLuint vertex_shader, fragment_shader;

    vertex_shader = _create_shader(GL_VERTEX_SHADER, vs_path);
    fragment_shader = _create_shader(GL_FRAGMENT_SHADER, fs_path);

    GLuint shader_program = glCreateProgram();

    glAttachShader(shader_program, vertex_shader);
    glAttachShader(shader_program, fragment_shader);

    glLinkProgram(shader_program);

    GLint status;
    glGetProgramiv(shader_program, GL_LINK_STATUS, &status);

    if (status == GL_FALSE) {
        puts("Shader linker failure!");

        GLint infoLogLength;
        glGetProgramiv(shader_program, GL_INFO_LOG_LENGTH, &infoLogLength);

        GLchar strInfoLog[infoLogLength];
        glGetProgramInfoLog(shader_program, infoLogLength, NULL, strInfoLog);

        printf("\nGLSL error: %s", strInfoLog);
        return -1;
    } else {
        printf("Shader program linked: %d\n", shader_program);
    }

    glDetachShader(shader_program, vertex_shader);
    glDetachShader(shader_program, fragment_shader);

    return shader_program;
}
Ejemplo n.º 3
0
static gboolean
gst_gl_alpha_filter_texture (GstGLFilter * filter, GstGLMemory * in_tex,
    GstGLMemory * out_tex)
{
  GstGLAlpha *alpha = GST_GL_ALPHA (filter);
  GstGLShader *shader;

  if (!alpha->alpha_shader)
    _create_shader (alpha);

  GST_OBJECT_LOCK (alpha);
  if (alpha->method == ALPHA_METHOD_SET) {
    shader = alpha->alpha_shader;
    gst_gl_shader_use (shader);
    gst_gl_shader_set_uniform_1f (shader, "alpha", alpha->alpha);
  } else {
    shader = alpha->chroma_key_shader;
    gst_gl_shader_use (shader);

    gst_gl_shader_set_uniform_1f (shader, "cb", alpha->cb);
    gst_gl_shader_set_uniform_1f (shader, "cr", alpha->cr);
    gst_gl_shader_set_uniform_1f (shader, "kg", alpha->kg);
    gst_gl_shader_set_uniform_1f (shader, "accept_angle_tg",
        alpha->accept_angle_tg);
    gst_gl_shader_set_uniform_1f (shader, "accept_angle_ctg",
        alpha->accept_angle_ctg);
    gst_gl_shader_set_uniform_1f (shader, "one_over_kc", alpha->one_over_kc);
    gst_gl_shader_set_uniform_1f (shader, "kfgy_scale", alpha->kfgy_scale);
    gst_gl_shader_set_uniform_1f (shader, "noise_level2", alpha->noise_level2);
    gst_gl_shader_set_uniform_1f (shader, "smin",
        0.5 - alpha->black_sensitivity / 255.0);
    gst_gl_shader_set_uniform_1f (shader, "smax",
        0.5 + alpha->white_sensitivity / 255.0);
  }
  GST_OBJECT_UNLOCK (alpha);

  gst_gl_filter_render_to_target_with_shader (filter, in_tex, out_tex, shader);

  return TRUE;
}