GL: generate shaders C array from plain shader source file using xxd

parent e25eb668
...@@ -13,9 +13,9 @@ EXTRA_DIST= winsnd2.c winsnd.c winvideo.c \ ...@@ -13,9 +13,9 @@ EXTRA_DIST= winsnd2.c winsnd.c winvideo.c \
winvideods.c wincevideods.c dxfilter.h dxfilter.cpp \ winvideods.c wincevideods.c dxfilter.h dxfilter.cpp \
msfileplayer_win.c msfilerec_win.c winsndds.cpp nowebcamCIF.jpg winsnd3.c vfw-missing.h \ msfileplayer_win.c msfilerec_win.c winsndds.cpp nowebcamCIF.jpg winsnd3.c vfw-missing.h \
winvideo2.c msjava.c $(ANDROID_SRC_FILES) \ winvideo2.c msjava.c $(ANDROID_SRC_FILES) \
$(GITVERSION_FILE) $(GITVERSION_FILE) yuv2rgb.fs yuv2rgb.vs
BUILT_SOURCES=alldescs.h $(GITVERSION_FILE) BUILT_SOURCES=alldescs.h $(GITVERSION_FILE) yuv2rgb.fs.h yuv2rgb.vs.h
CLEANFILES=alldescs.h filterdescs.txt $(GITVERSION_FILE) CLEANFILES=alldescs.h filterdescs.txt $(GITVERSION_FILE)
...@@ -66,6 +66,8 @@ libmediastreamer_la_SOURCES= mscommon.c $(GITVERSION_FILE) \ ...@@ -66,6 +66,8 @@ libmediastreamer_la_SOURCES= mscommon.c $(GITVERSION_FILE) \
#dummy c++ file to force libtool to use c++ linking (because of msdscap-mingw.cc) #dummy c++ file to force libtool to use c++ linking (because of msdscap-mingw.cc)
nodist_EXTRA_libmediastreamer_la_SOURCES = dummy.cxx nodist_EXTRA_libmediastreamer_la_SOURCES = dummy.cxx
nodist_libmediastreamer_la_SOURCES = yuv2rgb.fs.h yuv2rgb.fs.h
libmediastreamer_la_SOURCES+=audiostream.c libmediastreamer_la_SOURCES+=audiostream.c
...@@ -158,7 +160,6 @@ if BUILD_FFMPEG ...@@ -158,7 +160,6 @@ if BUILD_FFMPEG
libmediastreamer_la_SOURCES+= videoenc.c \ libmediastreamer_la_SOURCES+= videoenc.c \
videodec.c \ videodec.c \
swscale.h ffmpeg-priv.h \ swscale.h ffmpeg-priv.h \
h264dec.c \
jpegwriter.c jpegwriter.c
endif endif
...@@ -170,6 +171,10 @@ if BUILD_X11_XV ...@@ -170,6 +171,10 @@ if BUILD_X11_XV
libmediastreamer_la_SOURCES+=x11video.c libmediastreamer_la_SOURCES+=x11video.c
endif endif
if BUILD_X11_GL
libmediastreamer_la_SOURCES+=x11video.c opengles_display.c shaders.c
endif
libmediastreamer_la_SOURCES+= rfc2429.h \ libmediastreamer_la_SOURCES+= rfc2429.h \
pixconv.c \ pixconv.c \
sizeconv.c \ sizeconv.c \
...@@ -280,6 +285,12 @@ make_gitversion_h: ...@@ -280,6 +285,12 @@ make_gitversion_h:
$(GITVERSION_FILE): make_gitversion_h $(GITVERSION_FILE): make_gitversion_h
yuv2rgb.fs.h: yuv2rgb.fs
xxd -i yuv2rgb.fs | sed s/}\;/,0x00}\;/ > yuv2rgb.fs.h
yuv2rgb.vs.h: yuv2rgb.vs
xxd -i yuv2rgb.vs | sed s/}\;/,0x00}\;/ > yuv2rgb.vs.h
......
...@@ -32,7 +32,7 @@ GLint compileShader(GLuint *shader, GLenum type, const char *sources) ...@@ -32,7 +32,7 @@ GLint compileShader(GLuint *shader, GLenum type, const char *sources)
{ {
char *log = (char *)malloc(logLength); char *log = (char *)malloc(logLength);
glGetShaderInfoLog(*shader, logLength, &logLength, log); glGetShaderInfoLog(*shader, logLength, &logLength, log);
ms_debug("Shader compile log:\n%s", log); ms_message("Shader compile log:\n%s", log);
free(log); free(log);
} }
...@@ -59,7 +59,7 @@ GLint linkProgram(GLuint prog) ...@@ -59,7 +59,7 @@ GLint linkProgram(GLuint prog)
{ {
char *log = (char *)malloc(logLength); char *log = (char *)malloc(logLength);
glGetProgramInfoLog(prog, logLength, &logLength, log); glGetProgramInfoLog(prog, logLength, &logLength, log);
ms_debug("Program link log:\n%s", log); ms_message("Program link log:\n%s", log);
free(log); free(log);
} }
......
#ifdef __arm__
precision mediump float;
#endif
uniform sampler2D t_texture_y;
uniform sampler2D t_texture_u;
uniform sampler2D t_texture_v;
varying vec2 uvVarying;
void main()
{
float y,u,v,r,g,b, gradx, grady;
y = texture2D(t_texture_y, uvVarying).r;
u = texture2D(t_texture_u, uvVarying).r;
v = texture2D(t_texture_v, uvVarying).r;
y = 1.16438355 * (y - 0.0625);
u = u - 0.5;
v = v - 0.5;
r = clamp(y + 1.596 * v, 0.0, 1.0);
g = clamp(y - 0.391 * u - 0.813 * v, 0.0, 1.0);
b = clamp(y + 2.018 * u, 0.0, 1.0);
gl_FragColor = vec4(r,g,b,1.0);
}
#if TARGET_OS_IPHONE || defined(ANDROID)
#define PRECISION_DECL "precision mediump float;\n"
#else
#define PRECISION_DECL ""
#endif
#define YUV2RGB_FRAGMENT_SHADER PRECISION_DECL \
"uniform sampler2D t_texture_y;\n" \
"uniform sampler2D t_texture_u;\n" \
"uniform sampler2D t_texture_v;\n" \
"varying vec2 uvVarying;\n" \
"void main()\n" \
"{\n" \
"float y,u,v,r,g,b;\n" \
"const float c1 = float(255.0/219.0);\n" \
"const float c2 = float(16.0/256.0);\n" \
"const float c3 = float(1.0/2.0);\n" \
"const float c4 = float(1596.0/1000.0);\n" \
"const float c5 = float(391.0/1000.0);\n" \
"const float c6 = float(813.0/1000.0);\n" \
"const float c7 = float(2018.0/1000.0);\n" \
"y = texture2D(t_texture_y, uvVarying).r;\n" \
"u = texture2D(t_texture_u, uvVarying).r;\n" \
"v = texture2D(t_texture_v, uvVarying).r;\n" \
"\n" \
"y = c1 * (y - c2);\n" \
"u = u - c3;\n" \
"v = v - c3;\n" \
"\n" \
"r = clamp(y + c4 * v, 0.0, 1.0);\n" \
"g = clamp(y - c5 * u - c6 * v, 0.0, 1.0);\n" \
"b = clamp(y + c7 * u, 0.0, 1.0);\n" \
"\n" \
"gl_FragColor = vec4(r,g,b,1.0);\n" \
"}\n"
attribute vec4 position;
attribute vec2 uv;
uniform mat4 matrix;
varying vec2 uvVarying;
void main()
{
gl_Position = matrix * position;
uvVarying = uv;
}
#define YUV2RGB_VERTEX_SHADER "attribute vec4 position;\n" \
"attribute vec2 uv;\n" \
"uniform mat4 matrix;\n" \
"varying vec2 uvVarying;\n" \
"\n" \
"void main()\n" \
"{\n" \
" gl_Position = matrix * position;\n" \
" uvVarying = uv;\n" \
"}\n"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment