diff options
author | Rainer Hochecker <fernetmenta@online.de> | 2017-09-27 14:35:53 +0200 |
---|---|---|
committer | Rainer Hochecker <fernetmenta@online.de> | 2017-10-05 18:06:31 +0200 |
commit | d7f825e3861629a55a66111a8ac5f4519f835c1f (patch) | |
tree | a5147dbcbeb9faf61eaf36d0f321d0aa7947db90 | |
parent | e889fa1382babbac37380ea1b65859c603f86bde (diff) |
OpenGL: migrate to 3.2, WIP
23 files changed, 853 insertions, 21 deletions
diff --git a/system/shaders/GL/1.5/gl_convolution-4x4.glsl b/system/shaders/GL/1.5/gl_convolution-4x4.glsl new file mode 100644 index 0000000000..cf2a0f5378 --- /dev/null +++ b/system/shaders/GL/1.5/gl_convolution-4x4.glsl @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2010-2013 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +uniform sampler2D img; +uniform vec2 stepxy; +uniform float m_stretch; +varying vec2 m_cord; + +#if (USE1DTEXTURE) + uniform sampler1D kernelTex; +#else + uniform sampler2D kernelTex; +#endif + +//nvidia's half is a 16 bit float and can bring some speed improvements +//without affecting quality +#ifndef __GLSL_CG_DATA_TYPES + #define half float + #define half3 vec3 + #define half4 vec4 +#endif + +half4 weight(float pos) +{ +#if (HAS_FLOAT_TEXTURE) + #if (USE1DTEXTURE) + return texture1D(kernelTex, pos); + #else + return texture2D(kernelTex, vec2(pos, 0.5)); + #endif +#else + #if (USE1DTEXTURE) + return texture1D(kernelTex, pos) * 2.0 - 1.0; + #else + return texture2D(kernelTex, vec2(pos, 0.5)) * 2.0 - 1.0; + #endif +#endif +} + +vec2 stretch(vec2 pos) +{ +#if (XBMC_STRETCH) + // our transform should map [0..1] to itself, with f(0) = 0, f(1) = 1, f(0.5) = 0.5, and f'(0.5) = b. + // a simple curve to do this is g(x) = b(x-0.5) + (1-b)2^(n-1)(x-0.5)^n + 0.5 + // where the power preserves sign. n = 2 is the simplest non-linear case (required when b != 1) + float x = pos.x - 0.5; + return vec2(mix(x * abs(x) * 2.0, x, m_stretch) + 0.5, pos.y); +#else + return pos; +#endif +} + +half3 pixel(float xpos, float ypos) +{ + return texture2D(img, vec2(xpos, ypos)).rgb; +} + +half3 line (float ypos, vec4 xpos, half4 linetaps) +{ + return + pixel(xpos.r, ypos) * linetaps.r + + pixel(xpos.g, ypos) * linetaps.g + + pixel(xpos.b, ypos) * linetaps.b + + pixel(xpos.a, ypos) * linetaps.a; +} + +vec4 process() +{ + vec4 rgb; + vec2 pos = stretch(m_cord) + stepxy * 0.5; + vec2 f = fract(pos / stepxy); + + half4 linetaps = weight(1.0 - f.x); + half4 columntaps = weight(1.0 - f.y); + + //make sure all taps added together is exactly 1.0, otherwise some (very small) distortion can occur + linetaps /= linetaps.r + linetaps.g + linetaps.b + linetaps.a; + columntaps /= columntaps.r + columntaps.g + columntaps.b + columntaps.a; + + vec2 xystart = (-1.5 - f) * stepxy + pos; + vec4 xpos = vec4(xystart.x, xystart.x + stepxy.x, xystart.x + stepxy.x * 2.0, xystart.x + stepxy.x * 3.0); + + rgb.rgb = + line(xystart.y , xpos, linetaps) * columntaps.r + + line(xystart.y + stepxy.y , xpos, linetaps) * columntaps.g + + line(xystart.y + stepxy.y * 2.0, xpos, linetaps) * columntaps.b + + line(xystart.y + stepxy.y * 3.0, xpos, linetaps) * columntaps.a; + +#ifdef GL_ES + rgb.a = m_alpha; +#else + rgb.a = gl_Color.a; +#endif + + return rgb; +} diff --git a/system/shaders/GL/1.5/gl_convolution-6x6.glsl b/system/shaders/GL/1.5/gl_convolution-6x6.glsl new file mode 100644 index 0000000000..c4f51fd431 --- /dev/null +++ b/system/shaders/GL/1.5/gl_convolution-6x6.glsl @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2010-2013 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +uniform sampler2D img; +uniform vec2 stepxy; +uniform float m_stretch; +varying vec2 m_cord; + +#if (USE1DTEXTURE) + uniform sampler1D kernelTex; +#else + uniform sampler2D kernelTex; +#endif + +//nvidia's half is a 16 bit float and can bring some speed improvements +//without affecting quality +#ifndef __GLSL_CG_DATA_TYPES + #define half float + #define half3 vec3 + #define half4 vec4 +#endif + +half3 weight(float pos) +{ +#if (HAS_FLOAT_TEXTURE) + #if (USE1DTEXTURE) + return texture1D(kernelTex, pos).rgb; + #else + return texture2D(kernelTex, vec2(pos, 0.5)).rgb; + #endif +#else + #if (USE1DTEXTURE) + return texture1D(kernelTex, pos).rgb * 2.0 - 1.0; + #else + return texture2D(kernelTex, vec2(pos, 0.5)).rgb * 2.0 - 1.0; + #endif +#endif +} + +vec2 stretch(vec2 pos) +{ +#if (XBMC_STRETCH) + // our transform should map [0..1] to itself, with f(0) = 0, f(1) = 1, f(0.5) = 0.5, and f'(0.5) = b. + // a simple curve to do this is g(x) = b(x-0.5) + (1-b)2^(n-1)(x-0.5)^n + 0.5 + // where the power preserves sign. n = 2 is the simplest non-linear case (required when b != 1) + float x = pos.x - 0.5; + return vec2(mix(x * abs(x) * 2.0, x, m_stretch) + 0.5, pos.y); +#else + return pos; +#endif +} + +half3 pixel(float xpos, float ypos) +{ + return texture2D(img, vec2(xpos, ypos)).rgb; +} + +half3 line (float ypos, vec3 xpos1, vec3 xpos2, half3 linetaps1, half3 linetaps2) +{ + return + pixel(xpos1.r, ypos) * linetaps1.r + + pixel(xpos1.g, ypos) * linetaps2.r + + pixel(xpos1.b, ypos) * linetaps1.g + + pixel(xpos2.r, ypos) * linetaps2.g + + pixel(xpos2.g, ypos) * linetaps1.b + + pixel(xpos2.b, ypos) * linetaps2.b; +} + +vec4 process() +{ + vec4 rgb; + vec2 pos = stretch(m_cord) + stepxy * 0.5; + vec2 f = fract(pos / stepxy); + + half3 linetaps1 = weight((1.0 - f.x) / 2.0); + half3 linetaps2 = weight((1.0 - f.x) / 2.0 + 0.5); + half3 columntaps1 = weight((1.0 - f.y) / 2.0); + half3 columntaps2 = weight((1.0 - f.y) / 2.0 + 0.5); + + //make sure all taps added together is exactly 1.0, otherwise some (very small) distortion can occur + half sum = linetaps1.r + linetaps1.g + linetaps1.b + linetaps2.r + linetaps2.g + linetaps2.b; + linetaps1 /= sum; + linetaps2 /= sum; + sum = columntaps1.r + columntaps1.g + columntaps1.b + columntaps2.r + columntaps2.g + columntaps2.b; + columntaps1 /= sum; + columntaps2 /= sum; + + vec2 xystart = (-2.5 - f) * stepxy + pos; + vec3 xpos1 = vec3(xystart.x, xystart.x + stepxy.x, xystart.x + stepxy.x * 2.0); + vec3 xpos2 = vec3(xystart.x + stepxy.x * 3.0, xystart.x + stepxy.x * 4.0, xystart.x + stepxy.x * 5.0); + + rgb.rgb = + line(xystart.y , xpos1, xpos2, linetaps1, linetaps2) * columntaps1.r + + line(xystart.y + stepxy.y , xpos1, xpos2, linetaps1, linetaps2) * columntaps2.r + + line(xystart.y + stepxy.y * 2.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.g + + line(xystart.y + stepxy.y * 3.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.g + + line(xystart.y + stepxy.y * 4.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.b + + line(xystart.y + stepxy.y * 5.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.b; + +#ifdef GL_ES + rgb.a = m_alpha; +#else + rgb.a = gl_Color.a; +#endif + + return rgb; +} diff --git a/system/shaders/GL/1.5/gl_output.glsl b/system/shaders/GL/1.5/gl_output.glsl new file mode 100644 index 0000000000..d3294a8bb5 --- /dev/null +++ b/system/shaders/GL/1.5/gl_output.glsl @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2010-2017 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + + +#if defined(XBMC_DITHER) +uniform sampler2D m_dither; +uniform float m_ditherquant; +uniform vec2 m_dithersize; +#endif +#if defined(KODI_3DLUT) +uniform float m_CLUTsize; +uniform sampler3D m_CLUT; +#endif + +void main() +{ + vec4 rgb = process(); + +#if defined(KODI_3DLUT) + // FIXME: can this be optimized? + rgb = texture3D(m_CLUT, (rgb.rgb*(m_CLUTsize-1.0) + 0.5) / m_CLUTsize); +#endif + +#if defined(XBMC_FULLRANGE) +#if __VERSION__ <= 120 + rgb = (rgb-(16.0/255.0)) * 255.0/219.0; +#else + rgb = clamp((rgb-(16.0/255.0)) * 255.0/219.0, 0, 1); +#endif +#endif + +#if defined(XBMC_DITHER) + vec2 ditherpos = gl_FragCoord.xy / m_dithersize; + // ditherval is multiplied by 65536/(dither_size^2) to make it [0,1[ + // FIXME: scale dither values before uploading? + float ditherval = texture2D(m_dither, ditherpos).r * 16.0; + rgb = floor(rgb * m_ditherquant + ditherval) / m_ditherquant; +#endif + + gl_FragColor = rgb; +} diff --git a/system/shaders/GL/1.5/gl_shader_frag_default.glsl b/system/shaders/GL/1.5/gl_shader_frag_default.glsl new file mode 100644 index 0000000000..b5abea273e --- /dev/null +++ b/system/shaders/GL/1.5/gl_shader_frag_default.glsl @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2010-2013 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#version 130 + +uniform vec4 m_unicol; +out vec4 fragColor; + +// SM_DEFAULT shader +void main () +{ + fragColor = m_unicol; +} diff --git a/system/shaders/GL/1.5/gl_shader_frag_fonts.glsl b/system/shaders/GL/1.5/gl_shader_frag_fonts.glsl new file mode 100644 index 0000000000..c1b977030a --- /dev/null +++ b/system/shaders/GL/1.5/gl_shader_frag_fonts.glsl @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2010-2013 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#version 130 + +uniform sampler2D m_samp0; +in vec4 m_cord0; +in vec4 m_colour; +out vec4 fragColor; + +// SM_FONTS shader +void main () +{ + fragColor.r = m_colour.r; + fragColor.g = m_colour.g; + fragColor.b = m_colour.b; + fragColor.a = m_colour.a * texture2D(m_samp0, m_cord0.xy).a; +} diff --git a/system/shaders/GL/1.5/gl_shader_frag_multi.glsl b/system/shaders/GL/1.5/gl_shader_frag_multi.glsl new file mode 100644 index 0000000000..fddffebf9d --- /dev/null +++ b/system/shaders/GL/1.5/gl_shader_frag_multi.glsl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2010-2013 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#version 130 + +uniform sampler2D m_samp0; +uniform sampler2D m_samp1; +in vec4 m_cord0; +in vec4 m_cord1; +out vec4 fragColor; + +// SM_MULTI shader +void main () +{ + fragColor.rgba = (texture2D(m_samp0, m_cord0.xy) * texture2D(m_samp1, m_cord1.xy)).rgba; +} diff --git a/system/shaders/GL/1.5/gl_shader_frag_multi_blendcolor.glsl b/system/shaders/GL/1.5/gl_shader_frag_multi_blendcolor.glsl new file mode 100644 index 0000000000..5fc7c0f328 --- /dev/null +++ b/system/shaders/GL/1.5/gl_shader_frag_multi_blendcolor.glsl @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2010-2013 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#version 130 + +uniform sampler2D m_samp0; +uniform sampler2D m_samp1; +uniform vec4 m_unicol; +in vec4 m_cord0; +in vec4 m_cord1; +out vec4 fragColor; + +// SM_MULTI shader +void main () +{ + fragColor.rgba = m_unicol * texture2D(m_samp0, m_cord0.xy) * texture2D(m_samp1, m_cord1.xy); +} diff --git a/system/shaders/GL/1.5/gl_shader_frag_texture.glsl b/system/shaders/GL/1.5/gl_shader_frag_texture.glsl new file mode 100644 index 0000000000..249beeff07 --- /dev/null +++ b/system/shaders/GL/1.5/gl_shader_frag_texture.glsl @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2010-2013 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#version 130 + +uniform sampler2D m_samp0; +uniform vec4 m_unicol; +in vec4 m_cord0; +out vec4 fragColor; + +// SM_TEXTURE shader +void main () +{ + fragColor.rgba = vec4(texture2D(m_samp0, m_cord0.xy).rgba * m_unicol); +} diff --git a/system/shaders/GL/1.5/gl_shader_frag_texture_noblend.glsl b/system/shaders/GL/1.5/gl_shader_frag_texture_noblend.glsl new file mode 100644 index 0000000000..2a716843e4 --- /dev/null +++ b/system/shaders/GL/1.5/gl_shader_frag_texture_noblend.glsl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2010-2013 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#version 130 + +uniform sampler2D m_samp0; +in vec4 m_cord0; +out vec4 fragColor; + +// SM_TEXTURE_NOBLEND shader +void main () +{ + fragColor.rgba = vec4(texture2D(m_samp0, m_cord0.xy).rgba); +} diff --git a/system/shaders/GL/1.5/gl_shader_vert.glsl b/system/shaders/GL/1.5/gl_shader_vert.glsl new file mode 100644 index 0000000000..8bd7fc228f --- /dev/null +++ b/system/shaders/GL/1.5/gl_shader_vert.glsl @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2010-2013 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#version 130 + +in vec4 m_attrpos; +in vec4 m_attrcol; +in vec4 m_attrcord0; +in vec4 m_attrcord1; +out vec4 m_cord0; +out vec4 m_cord1; +out vec4 m_colour; +uniform mat4 m_proj; +uniform mat4 m_model; + +void main () +{ + mat4 mvp = m_proj * m_model; + gl_Position = mvp * m_attrpos; + m_colour = m_attrcol; + m_cord0 = m_attrcord0; + m_cord1 = m_attrcord1; +} diff --git a/system/shaders/GL/1.5/gl_shader_vert_default.glsl b/system/shaders/GL/1.5/gl_shader_vert_default.glsl new file mode 100644 index 0000000000..aaf01b75e1 --- /dev/null +++ b/system/shaders/GL/1.5/gl_shader_vert_default.glsl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2010-2013 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#version 130 + +in vec4 m_attrpos; +uniform mat4 m_proj; +uniform mat4 m_model; + +void main () +{ + mat4 mvp = m_proj * m_model; + gl_Position = mvp * m_attrpos; +} diff --git a/system/shaders/GL/1.5/gl_streatch.glsl b/system/shaders/GL/1.5/gl_streatch.glsl new file mode 100644 index 0000000000..dc42318d50 --- /dev/null +++ b/system/shaders/GL/1.5/gl_streatch.glsl @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2010-2013 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#version 120 + +uniform sampler2D img; +uniform float m_stretch; +varying vec2 m_cord; + +vec2 stretch(vec2 pos) +{ + // our transform should map [0..1] to itself, with f(0) = 0, f(1) = 1, f(0.5) = 0.5, and f'(0.5) = b. + // a simple curve to do this is g(x) = b(x-0.5) + (1-b)2^(n-1)(x-0.5)^n + 0.5 + // where the power preserves sign. n = 2 is the simplest non-linear case (required when b != 1) + float x = pos.x - 0.5; + return vec2(mix(x * abs(x) * 2.0, x, m_stretch) + 0.5, pos.y); +} + +void main() +{ + gl_FragColor.rgb = texture2D(img, stretch(m_cord)).rgb; + gl_FragColor.a = gl_Color.a; +} diff --git a/system/shaders/GL/1.5/gl_videofilter_frag.glsl b/system/shaders/GL/1.5/gl_videofilter_frag.glsl new file mode 100644 index 0000000000..ff7af3b678 --- /dev/null +++ b/system/shaders/GL/1.5/gl_videofilter_frag.glsl @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2010-2013 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#version 120 + +uniform sampler2D img; +varying vec2 m_cord; + +void main() +{ + gl_FragColor.rgb = texture2D(img, m_cord).rgb; + gl_FragColor.a = gl_Color.a; +} diff --git a/system/shaders/GL/1.5/gl_videofilter_vertex.glsl b/system/shaders/GL/1.5/gl_videofilter_vertex.glsl new file mode 100644 index 0000000000..aa124b5350 --- /dev/null +++ b/system/shaders/GL/1.5/gl_videofilter_vertex.glsl @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2010-2013 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#version 120 + +attribute vec4 m_attrpos; +attribute vec2 m_attrcord; +varying vec2 m_cord; +uniform mat4 m_proj; +uniform mat4 m_model; + +void main () +{ + mat4 mvp = m_proj * m_model; + gl_Position = mvp * m_attrpos; + m_cord = m_attrcord; +} diff --git a/system/shaders/GL/1.5/gl_yuv2rgb_basic.glsl b/system/shaders/GL/1.5/gl_yuv2rgb_basic.glsl new file mode 100644 index 0000000000..268d8c6682 --- /dev/null +++ b/system/shaders/GL/1.5/gl_yuv2rgb_basic.glsl @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2010-2013 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#if(XBMC_texture_rectangle) +# extension GL_ARB_texture_rectangle : enable +# define texture2D texture2DRect +# define sampler2D sampler2DRect +#endif + +uniform sampler2D m_sampY; +uniform sampler2D m_sampU; +uniform sampler2D m_sampV; +varying vec2 m_cordY; +varying vec2 m_cordU; +varying vec2 m_cordV; +uniform vec2 m_step; +uniform mat4 m_yuvmat; +uniform float m_stretch; + +vec2 stretch(vec2 pos) +{ +#if (XBMC_STRETCH) + // our transform should map [0..1] to itself, with f(0) = 0, f(1) = 1, f(0.5) = 0.5, and f'(0.5) = b. + // a simple curve to do this is g(x) = b(x-0.5) + (1-b)2^(n-1)(x-0.5)^n + 0.5 + // where the power preserves sign. n = 2 is the simplest non-linear case (required when b != 1) + #if(XBMC_texture_rectangle) + float x = (pos.x * m_step.x) - 0.5; + return vec2((mix(2.0 * x * abs(x), x, m_stretch) + 0.5) / m_step.x, pos.y); + #else + float x = pos.x - 0.5; + return vec2(mix(2.0 * x * abs(x), x, m_stretch) + 0.5, pos.y); + #endif +#else + return pos; +#endif +} + +vec4 process() +{ + vec4 rgb; +#if defined(XBMC_YV12) || defined(XBMC_NV12) + + vec4 yuv; + yuv.rgba = vec4( texture2D(m_sampY, stretch(m_cordY)).r + , texture2D(m_sampU, stretch(m_cordU)).g + , texture2D(m_sampV, stretch(m_cordV)).a + , 1.0 ); + + rgb = m_yuvmat * yuv; + rgb.a = gl_Color.a; + +#elif defined(XBMC_NV12_RRG) + + vec4 yuv; + yuv.rgba = vec4( texture2D(m_sampY, stretch(m_cordY)).r + , texture2D(m_sampU, stretch(m_cordU)).r + , texture2D(m_sampV, stretch(m_cordV)).g + , 1.0 ); + + rgb = m_yuvmat * yuv; + rgb.a = gl_Color.a; + +#elif defined(XBMC_YUY2) || defined(XBMC_UYVY) + +#if(XBMC_texture_rectangle) + vec2 stepxy = vec2(1.0, 1.0); + vec2 pos = stretch(m_cordY); + pos = vec2(pos.x - 0.25, pos.y); + vec2 f = fract(pos); +#else + vec2 stepxy = m_step; + vec2 pos = stretch(m_cordY); + pos = vec2(pos.x - stepxy.x * 0.25, pos.y); + vec2 f = fract(pos / stepxy); +#endif + + //y axis will be correctly interpolated by opengl + //x axis will not, so we grab two pixels at the center of two columns and interpolate ourselves + vec4 c1 = texture2D(m_sampY, vec2(pos.x + (0.5 - f.x) * stepxy.x, pos.y)); + vec4 c2 = texture2D(m_sampY, vec2(pos.x + (1.5 - f.x) * stepxy.x, pos.y)); + + /* each pixel has two Y subpixels and one UV subpixel + YUV Y YUV + check if we're left or right of the middle Y subpixel and interpolate accordingly*/ +#ifdef XBMC_YUY2 //BGRA = YUYV + float leftY = mix(c1.b, c1.r, f.x * 2.0); + float rightY = mix(c1.r, c2.b, f.x * 2.0 - 1.0); + vec2 outUV = mix(c1.ga, c2.ga, f.x); +#else //BGRA = UYVY + float leftY = mix(c1.g, c1.a, f.x * 2.0); + float rightY = mix(c1.a, c2.g, f.x * 2.0 - 1.0); + vec2 outUV = mix(c1.br, c2.br, f.x); +#endif //XBMC_YUY2 + + float outY = mix(leftY, rightY, step(0.5, f.x)); + + vec4 yuv = vec4(outY, outUV, 1.0); + rgb = m_yuvmat * yuv; + + rgb.a = gl_Color.a; + +#endif + + return rgb; +} diff --git a/system/shaders/GL/1.5/gl_yuv2rgb_vertex.glsl b/system/shaders/GL/1.5/gl_yuv2rgb_vertex.glsl new file mode 100644 index 0000000000..cdf3c56a71 --- /dev/null +++ b/system/shaders/GL/1.5/gl_yuv2rgb_vertex.glsl @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2010-2013 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +attribute vec4 m_attrpos; +attribute vec2 m_attrcordY; +attribute vec2 m_attrcordU; +attribute vec2 m_attrcordV; +varying vec2 m_cordY; +varying vec2 m_cordU; +varying vec2 m_cordV; +uniform mat4 m_proj; +uniform mat4 m_model; + +void main () +{ + mat4 mvp = m_proj * m_model; + gl_Position = mvp * m_attrpos; + m_cordY = m_attrcordY; + m_cordU = m_attrcordU; + m_cordV = m_attrcordV; +} diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGL.cpp b/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGL.cpp index 6a95b3c5dd..8831f59d0b 100644 --- a/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGL.cpp +++ b/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGL.cpp @@ -1301,7 +1301,6 @@ void CLinuxRendererGL::RenderToFBO(int index, int field, bool weave /*= false*/) void CLinuxRendererGL::RenderFromFBO() { - glEnable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE0); VerifyGLState(); diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGLES.cpp b/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGLES.cpp index 5df3993267..e3428d2ba8 100644 --- a/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGLES.cpp +++ b/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGLES.cpp @@ -1001,7 +1001,6 @@ void CLinuxRendererGLES::RenderToFBO(int index, int field, bool weave /*= false* void CLinuxRendererGLES::RenderFromFBO() { - glEnable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_fbo.fbo.Texture()); VerifyGLState(); diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRendererGL.cpp b/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRendererGL.cpp index 7af35811fb..7c4a060d82 100644 --- a/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRendererGL.cpp +++ b/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRendererGL.cpp @@ -183,7 +183,6 @@ COverlayTextureGL::COverlayTextureGL(CDVDOverlayImage* o) } glGenTextures(1, &m_texture); - glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); @@ -246,7 +245,6 @@ COverlayTextureGL::COverlayTextureGL(CDVDOverlaySpu* o) } glGenTextures(1, &m_texture); - glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); @@ -292,7 +290,6 @@ COverlayGlyphGL::COverlayGlyphGL(ASS_Image* images, int width, int height) return; glGenTextures(1, &m_texture); - glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_texture); LoadTexture(GL_TEXTURE_2D @@ -371,7 +368,6 @@ void COverlayGlyphGL::Render(SRenderState& state) if ((m_texture == 0) || (m_count == 0)) return; - glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, m_texture); @@ -452,7 +448,6 @@ COverlayTextureGL::~COverlayTextureGL() void COverlayTextureGL::Render(SRenderState& state) { - glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, m_texture); diff --git a/xbmc/guilib/GUITextureGL.cpp b/xbmc/guilib/GUITextureGL.cpp index 33ddac6345..ed4ce7c430 100644 --- a/xbmc/guilib/GUITextureGL.cpp +++ b/xbmc/guilib/GUITextureGL.cpp @@ -26,6 +26,8 @@ #include "guilib/Geometry.h" #include "windowing/WindowingFactory.h" +#define BUFFER_OFFSET(i) ((char *)NULL + (i)) + CGUITextureGL::CGUITextureGL(float posX, float posY, float width, float height, const CTextureInfo &texture) : CGUITextureBase(posX, posY, width, height, texture) { @@ -104,6 +106,13 @@ void CGUITextureGL::End() GLint tex1Loc = g_Windowing.ShaderGetCoord1(); GLint uniColLoc = g_Windowing.ShaderGetUniCol(); + GLuint VertexVBO; + GLuint IndexVBO; + + glGenBuffers(1, &VertexVBO); + glBindBuffer(GL_ARRAY_BUFFER, VertexVBO); + glBufferData(GL_ARRAY_BUFFER, sizeof(PackedVertex)*m_packedVertices.size(), &m_packedVertices[0], GL_STATIC_DRAW); + if (uniColLoc >= 0) { glUniform4f(uniColLoc,(m_col[0] / 255.0f), (m_col[1] / 255.0f), (m_col[2] / 255.0f), (m_col[3] / 255.0f)); @@ -111,22 +120,31 @@ void CGUITextureGL::End() if (m_diffuse.size()) { - glVertexAttribPointer(tex1Loc, 2, GL_FLOAT, 0, sizeof(PackedVertex), (char*)&m_packedVertices[0] + offsetof(PackedVertex, u2)); + glVertexAttribPointer(tex1Loc, 2, GL_FLOAT, 0, sizeof(PackedVertex), BUFFER_OFFSET(offsetof(PackedVertex, u2))); glEnableVertexAttribArray(tex1Loc); } - glVertexAttribPointer(posLoc, 3, GL_FLOAT, 0, sizeof(PackedVertex), (char*)&m_packedVertices[0] + offsetof(PackedVertex, x)); + glVertexAttribPointer(posLoc, 3, GL_FLOAT, 0, sizeof(PackedVertex), BUFFER_OFFSET(offsetof(PackedVertex, x))); glEnableVertexAttribArray(posLoc); - glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, sizeof(PackedVertex), (char*)&m_packedVertices[0] + offsetof(PackedVertex, u1)); + glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, sizeof(PackedVertex), BUFFER_OFFSET(offsetof(PackedVertex, u1))); glEnableVertexAttribArray(tex0Loc); - glDrawElements(GL_TRIANGLE_STRIP, m_packedVertices.size(), GL_UNSIGNED_SHORT, m_idx.data()); + glGenBuffers(1, &IndexVBO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexVBO); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(ushort)*m_idx.size(), m_idx.data(), GL_STATIC_DRAW); + + glDrawElements(GL_TRIANGLES, m_packedVertices.size()*6 / 4, GL_UNSIGNED_SHORT, 0); if (m_diffuse.size()) glDisableVertexAttribArray(tex1Loc); glDisableVertexAttribArray(posLoc); glDisableVertexAttribArray(tex0Loc); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glDeleteBuffers(1, &VertexVBO); + glDeleteBuffers(1, &IndexVBO); } if (m_diffuse.size()) @@ -216,13 +234,15 @@ void CGUITextureGL::Draw(float *x, float *y, float *z, const CRect &texture, con m_packedVertices.push_back(vertices[i]); } - if (m_packedVertices.size() > m_idx.size()) + if ((m_packedVertices.size() / 4) > (m_idx.size() / 6)) { size_t i = m_packedVertices.size() - 4; m_idx.push_back(i+0); m_idx.push_back(i+1); - m_idx.push_back(i+3); m_idx.push_back(i+2); + m_idx.push_back(i+2); + m_idx.push_back(i+3); + m_idx.push_back(i+0); } } diff --git a/xbmc/guilib/TextureGL.cpp b/xbmc/guilib/TextureGL.cpp index 05ccdbbf22..d35ffe8c7f 100644 --- a/xbmc/guilib/TextureGL.cpp +++ b/xbmc/guilib/TextureGL.cpp @@ -215,9 +215,6 @@ void CGLTexture::BindToUnit(unsigned int unit) { glActiveTexture(GL_TEXTURE0 + unit); glBindTexture(GL_TEXTURE_2D, m_texture); -#ifndef HAS_GLES - glEnable(GL_TEXTURE_2D); -#endif } #endif // HAS_GL diff --git a/xbmc/rendering/gl/GUIWindowTestPatternGL.cpp b/xbmc/rendering/gl/GUIWindowTestPatternGL.cpp index fbfddb42fe..c5572d37ef 100644 --- a/xbmc/rendering/gl/GUIWindowTestPatternGL.cpp +++ b/xbmc/rendering/gl/GUIWindowTestPatternGL.cpp @@ -196,7 +196,7 @@ void CGUIWindowTestPatternGL::BeginRender() void CGUIWindowTestPatternGL::EndRender() { - glEnable(GL_TEXTURE_2D); + } #endif diff --git a/xbmc/rendering/gl/RenderSystemGL.cpp b/xbmc/rendering/gl/RenderSystemGL.cpp index 6e2eeda529..2635188bb5 100644 --- a/xbmc/rendering/gl/RenderSystemGL.cpp +++ b/xbmc/rendering/gl/RenderSystemGL.cpp @@ -194,7 +194,6 @@ bool CRenderSystemGL::ResetRenderSystem(int width, int height) CRect rect( 0, 0, width, height ); SetViewPort( rect ); - glEnable(GL_TEXTURE_2D); glEnable(GL_SCISSOR_TEST); glMatrixProject.Clear(); @@ -362,7 +361,6 @@ void CRenderSystemGL::ApplyStateBlock() glMatrixTexture.PopLoad(); glActiveTextureARB(GL_TEXTURE0_ARB); - glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glEnable(GL_BLEND); glEnable(GL_SCISSOR_TEST); @@ -457,7 +455,7 @@ void CRenderSystemGL::CalculateMaxTexturesize() // max out at 2^(8+8) for (int i = 0 ; i<8 ; i++) { - glTexImage2D(GL_PROXY_TEXTURE_2D, 0, 4, width, width, 0, GL_BGRA, + glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGBA, width, width, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); @@ -615,7 +613,6 @@ void CRenderSystemGL::SetStereoMode(RENDER_STEREO_MODE mode, RENDER_STEREO_VIEW CRenderSystemBase::SetStereoMode(mode, view); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - glDisable(GL_POLYGON_STIPPLE); glDrawBuffer(GL_BACK); if(m_stereoMode == RENDER_STEREO_MODE_ANAGLYPH_RED_CYAN) |