|
Packit |
0652a1 |
/*
|
|
Packit |
0652a1 |
* GStreamer
|
|
Packit |
0652a1 |
* Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
|
|
Packit |
0652a1 |
*
|
|
Packit |
0652a1 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
0652a1 |
* modify it under the terms of the GNU Library General Public
|
|
Packit |
0652a1 |
* License as published by the Free Software Foundation; either
|
|
Packit |
0652a1 |
* version 2 of the License, or (at your option) any later version.
|
|
Packit |
0652a1 |
*
|
|
Packit |
0652a1 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
0652a1 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
0652a1 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
0652a1 |
* Library General Public License for more details.
|
|
Packit |
0652a1 |
*
|
|
Packit |
0652a1 |
* You should have received a copy of the GNU Library General Public
|
|
Packit |
0652a1 |
* License along with this library; if not, write to the
|
|
Packit |
0652a1 |
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
Packit |
0652a1 |
* Boston, MA 02110-1301, USA.
|
|
Packit |
0652a1 |
*/
|
|
Packit |
0652a1 |
|
|
Packit |
0652a1 |
#ifdef HAVE_CONFIG_H
|
|
Packit |
0652a1 |
#include "config.h"
|
|
Packit |
0652a1 |
#endif
|
|
Packit |
0652a1 |
|
|
Packit |
0652a1 |
#include "gstglshaderstrings.h"
|
|
Packit |
0652a1 |
|
|
Packit |
0652a1 |
#define MEDIUMP_PRECISION \
|
|
Packit |
0652a1 |
"#ifdef GL_ES\n" \
|
|
Packit |
0652a1 |
"precision mediump float;\n" \
|
|
Packit |
0652a1 |
"#endif\n"
|
|
Packit |
0652a1 |
|
|
Packit |
0652a1 |
#define HIGHP_PRECISION \
|
|
Packit |
0652a1 |
"#ifdef GL_ES\n" \
|
|
Packit |
0652a1 |
"precision highp float;\n" \
|
|
Packit |
0652a1 |
"#endif\n"
|
|
Packit |
0652a1 |
|
|
Packit |
0652a1 |
/* *INDENT-OFF* */
|
|
Packit |
0652a1 |
const gchar *gst_gl_shader_string_fragment_mediump_precision =
|
|
Packit |
0652a1 |
MEDIUMP_PRECISION;
|
|
Packit |
0652a1 |
|
|
Packit |
0652a1 |
const gchar *gst_gl_shader_string_fragment_highp_precision =
|
|
Packit |
0652a1 |
HIGHP_PRECISION;
|
|
Packit |
0652a1 |
|
|
Packit |
0652a1 |
const gchar *gst_gl_shader_string_vertex_default =
|
|
Packit |
0652a1 |
"attribute vec4 a_position;\n"
|
|
Packit |
0652a1 |
"attribute vec2 a_texcoord;\n"
|
|
Packit |
0652a1 |
"varying vec2 v_texcoord;\n"
|
|
Packit |
0652a1 |
"void main()\n"
|
|
Packit |
0652a1 |
"{\n"
|
|
Packit |
0652a1 |
" gl_Position = a_position;\n"
|
|
Packit |
0652a1 |
" v_texcoord = a_texcoord;\n"
|
|
Packit |
0652a1 |
"}\n";
|
|
Packit |
0652a1 |
|
|
Packit |
0652a1 |
const gchar *gst_gl_shader_string_vertex_mat4_texture_transform =
|
|
Packit |
0652a1 |
"uniform mat4 u_transformation;\n"
|
|
Packit |
0652a1 |
"attribute vec4 a_position;\n"
|
|
Packit |
0652a1 |
"attribute vec2 a_texcoord;\n"
|
|
Packit |
0652a1 |
"varying vec2 v_texcoord;\n"
|
|
Packit |
0652a1 |
"void main()\n"
|
|
Packit |
0652a1 |
"{\n"
|
|
Packit |
0652a1 |
" gl_Position = a_position;\n"
|
|
Packit |
0652a1 |
" v_texcoord = (u_transformation * vec4(a_texcoord, 0, 1)).xy;\n"
|
|
Packit |
0652a1 |
"}\n";
|
|
Packit |
0652a1 |
|
|
Packit |
0652a1 |
const gchar *gst_gl_shader_string_vertex_mat4_vertex_transform =
|
|
Packit |
0652a1 |
"uniform mat4 u_transformation;\n"
|
|
Packit |
0652a1 |
"attribute vec4 a_position;\n"
|
|
Packit |
0652a1 |
"attribute vec2 a_texcoord;\n"
|
|
Packit |
0652a1 |
"varying vec2 v_texcoord;\n"
|
|
Packit |
0652a1 |
"void main()\n"
|
|
Packit |
0652a1 |
"{\n"
|
|
Packit |
0652a1 |
" gl_Position = u_transformation * a_position;\n"
|
|
Packit |
0652a1 |
" v_texcoord = a_texcoord;\n"
|
|
Packit |
0652a1 |
"}\n";
|
|
Packit |
0652a1 |
|
|
Packit |
0652a1 |
#define DEFAULT_FRAGMENT_BODY \
|
|
Packit |
0652a1 |
"varying vec2 v_texcoord;\n" \
|
|
Packit |
0652a1 |
"uniform sampler2D tex;\n" \
|
|
Packit |
0652a1 |
"void main()\n" \
|
|
Packit |
0652a1 |
"{\n" \
|
|
Packit |
0652a1 |
" gl_FragColor = texture2D(tex, v_texcoord);\n" \
|
|
Packit |
0652a1 |
"}"
|
|
Packit |
0652a1 |
const gchar *gst_gl_shader_string_fragment_default =
|
|
Packit |
0652a1 |
MEDIUMP_PRECISION
|
|
Packit |
0652a1 |
DEFAULT_FRAGMENT_BODY;
|
|
Packit |
0652a1 |
|
|
Packit |
0652a1 |
#define EXTERNAL_FRAGMENT_HEADER \
|
|
Packit |
0652a1 |
"#extension GL_OES_EGL_image_external : require\n"
|
|
Packit |
0652a1 |
|
|
Packit |
0652a1 |
#define EXTERNAL_FRAGMENT_BODY \
|
|
Packit |
0652a1 |
"varying vec2 v_texcoord;\n" \
|
|
Packit |
0652a1 |
"uniform samplerExternalOES tex;\n" \
|
|
Packit |
0652a1 |
"void main()\n" \
|
|
Packit |
0652a1 |
"{\n" \
|
|
Packit |
0652a1 |
" gl_FragColor = texture2D(tex, v_texcoord);\n" \
|
|
Packit |
0652a1 |
"}"
|
|
Packit |
0652a1 |
const gchar *gst_gl_shader_string_fragment_external_oes_default =
|
|
Packit |
0652a1 |
EXTERNAL_FRAGMENT_HEADER
|
|
Packit |
0652a1 |
MEDIUMP_PRECISION
|
|
Packit |
0652a1 |
EXTERNAL_FRAGMENT_BODY;
|
|
Packit |
0652a1 |
/* *INDENT-ON* */
|
|
Packit |
0652a1 |
|
|
Packit |
0652a1 |
/**
|
|
Packit |
0652a1 |
* gst_gl_shader_string_get_highest_precision:
|
|
Packit |
0652a1 |
* @context: a #GstGLContext
|
|
Packit |
0652a1 |
* @version: a #GstGLSLVersion
|
|
Packit |
0652a1 |
* @profile: a #GstGLSLProfile
|
|
Packit |
0652a1 |
*
|
|
Packit |
0652a1 |
* Generates a shader string that defines the precision of float types in
|
|
Packit |
0652a1 |
* GLSL shaders. This is particularly needed for fragment shaders in a
|
|
Packit |
0652a1 |
* GLSL ES context where there is no default precision specified.
|
|
Packit |
0652a1 |
*
|
|
Packit |
0652a1 |
* Practically, this will return the string 'precision mediump float'
|
|
Packit |
0652a1 |
* or 'precision highp float' depending on if high precision floats are
|
|
Packit |
0652a1 |
* determined to be supported.
|
|
Packit |
0652a1 |
*
|
|
Packit |
0652a1 |
* Returns: a shader string defining the precision of float types based on
|
|
Packit |
0652a1 |
* @context, @version and @profile
|
|
Packit |
0652a1 |
*
|
|
Packit |
0652a1 |
* Since: 1.16
|
|
Packit |
0652a1 |
*/
|
|
Packit |
0652a1 |
const gchar *
|
|
Packit |
0652a1 |
gst_gl_shader_string_get_highest_precision (GstGLContext * context,
|
|
Packit |
0652a1 |
GstGLSLVersion version, GstGLSLProfile profile)
|
|
Packit |
0652a1 |
{
|
|
Packit |
0652a1 |
if (gst_gl_context_supports_precision (context, version, profile)) {
|
|
Packit |
0652a1 |
if (gst_gl_context_supports_precision_highp (context, version, profile))
|
|
Packit |
0652a1 |
return gst_gl_shader_string_fragment_highp_precision;
|
|
Packit |
0652a1 |
else
|
|
Packit |
0652a1 |
return gst_gl_shader_string_fragment_mediump_precision;
|
|
Packit |
0652a1 |
}
|
|
Packit |
0652a1 |
return "";
|
|
Packit |
0652a1 |
}
|
|
Packit |
0652a1 |
|
|
Packit |
0652a1 |
/**
|
|
Packit |
0652a1 |
* gst_gl_shader_string_fragment_get_default:
|
|
Packit |
0652a1 |
* @context: a #GstGLContext
|
|
Packit |
0652a1 |
* @version: a #GstGLSLVersion
|
|
Packit |
0652a1 |
* @profile: a #GstGLSLProfile
|
|
Packit |
0652a1 |
*
|
|
Packit |
0652a1 |
* Returns: a passthrough shader string for copying an input texture to
|
|
Packit |
0652a1 |
* the output
|
|
Packit |
0652a1 |
*
|
|
Packit |
0652a1 |
* Since: 1.16
|
|
Packit |
0652a1 |
*/
|
|
Packit |
0652a1 |
gchar *
|
|
Packit |
0652a1 |
gst_gl_shader_string_fragment_get_default (GstGLContext * context,
|
|
Packit |
0652a1 |
GstGLSLVersion version, GstGLSLProfile profile)
|
|
Packit |
0652a1 |
{
|
|
Packit |
0652a1 |
const gchar *precision =
|
|
Packit |
0652a1 |
gst_gl_shader_string_get_highest_precision (context, version, profile);
|
|
Packit |
0652a1 |
|
|
Packit |
0652a1 |
return g_strdup_printf ("%s%s", precision, DEFAULT_FRAGMENT_BODY);
|
|
Packit |
0652a1 |
}
|
|
Packit |
0652a1 |
|
|
Packit |
0652a1 |
/**
|
|
Packit |
0652a1 |
* gst_gl_shader_string_fragment_external_oes_get_default:
|
|
Packit |
0652a1 |
* @context: a #GstGLContext
|
|
Packit |
0652a1 |
* @version: a #GstGLSLVersion
|
|
Packit |
0652a1 |
* @profile: a #GstGLSLProfile
|
|
Packit |
0652a1 |
*
|
|
Packit |
0652a1 |
* Returns: a passthrough shader string for copying an input external-oes
|
|
Packit |
0652a1 |
* texture to the output
|
|
Packit |
0652a1 |
*
|
|
Packit |
0652a1 |
* Since: 1.16
|
|
Packit |
0652a1 |
*/
|
|
Packit |
0652a1 |
gchar *
|
|
Packit |
0652a1 |
gst_gl_shader_string_fragment_external_oes_get_default (GstGLContext * context,
|
|
Packit |
0652a1 |
GstGLSLVersion version, GstGLSLProfile profile)
|
|
Packit |
0652a1 |
{
|
|
Packit |
0652a1 |
const gchar *precision =
|
|
Packit |
0652a1 |
gst_gl_shader_string_get_highest_precision (context, version, profile);
|
|
Packit |
0652a1 |
|
|
Packit |
0652a1 |
return g_strdup_printf ("%s%s%s", EXTERNAL_FRAGMENT_HEADER, precision,
|
|
Packit |
0652a1 |
EXTERNAL_FRAGMENT_BODY);
|
|
Packit |
0652a1 |
}
|