]> git.vomp.tv Git - vompclient.git/commitdiff
Reorganizing Shader, Creatinng GLShader framework
authorMarten Richter <marten.richter@freenet.de>
Sat, 9 Jun 2012 10:12:05 +0000 (12:12 +0200)
committerMarten Richter <marten.richter@freenet.de>
Sat, 9 Jun 2012 10:12:05 +0000 (12:12 +0200)
13 files changed:
GNUmakefile
glosdshader.cc [new file with mode: 0755]
glosdshader.h [new file with mode: 0755]
glshader.cc [new file with mode: 0755]
glshader.h [new file with mode: 0755]
glyuv400shader.cc [new file with mode: 0755]
glyuv400shader.h [new file with mode: 0755]
osdopengl.cc
osdopengl.h
shaders/frame__frag_shader.h [deleted file]
shaders/generic__vertex_shader.h [deleted file]
shaders/osd__frag_shader.h [deleted file]
videovpeogl.cc

index a6bcb2611fd876b2402feb02b87ecb63d083cc21..680bc08191ea110ff14446b6c0d6774aa6d7e9e6 100755 (executable)
@@ -57,7 +57,7 @@ $(info Raspberry pi flags)
 LDFLAGS = -Wall\r
 LIBS = -L/opt/vc/lib -lpthread -lrt -lEGL -lGLESv2 -lopenmaxil -lbcm_host   -lavcodec -lavformat -lavutil\r
 \r
-OBJECTS += main.o threadp.o osdopengl.o surfaceopengl.o ledraspberry.o mtdraspberry.o videovpeogl.o audiovpe.o wjpegsimple.o remotelinux.o\r
+OBJECTS += main.o threadp.o osdopengl.o surfaceopengl.o ledraspberry.o mtdraspberry.o videovpeogl.o audiovpe.o wjpegsimple.o remotelinux.o glshader.o glosdshader.o glyuv400shader.o\r
 LIBS+= -ljpeg\r
 CROSSLIBS =\r
 INCLUDES = -DVOMP_PLATTFORM_RASPBERRY   -I/opt/vc/include \r
diff --git a/glosdshader.cc b/glosdshader.cc
new file mode 100755 (executable)
index 0000000..8ef5eb0
--- /dev/null
@@ -0,0 +1,85 @@
+/*\r
+    Copyright 2012 Marten Richter\r
+\r
+    This file is part of VOMP.\r
+\r
+    VOMP is free software; you can redistribute it and/or modify\r
+    it under the terms of the GNU General Public License as published by\r
+    the Free Software Foundation; either version 2 of the License, or\r
+    (at your option) any later version.\r
+\r
+    VOMP is distributed in the hope that it will be useful,\r
+    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+    GNU General Public License for more details.\r
+\r
+    You should have received a copy of the GNU General Public License\r
+    along with VOMP; if not, write to the Free Software\r
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
+*/\r
+#include "glosdshader.h"\r
+\r
+const GLchar generic_vertex_shader[] =\r
+               "attribute vec4 vec_pos;\n"\r
+               "attribute vec2 tex_coord;\n"\r
+               "varying vec2 out_texCoord;\n"\r
+               "void main()\n"\r
+               "{\n"\r
+               " gl_Position=vec_pos;\n"\r
+               " out_texCoord=tex_coord;\n"\r
+               "}\n";\r
+\r
+const GLchar osd_frag_shader[] =\r
+               "precision mediump float;\n"\r
+               "uniform sampler2D texture;\n"\r
+               "varying vec2 out_texCoord;\n"\r
+               "void main()\n"\r
+               "{\n"\r
+               " gl_FragColor=texture2D(texture,out_texCoord);\n"\r
+               "}\n";\r
+\r
+GLOsdShader::GLOsdShader(): GLShader("GLOsdShader")\r
+{\r
+\r
+}\r
+\r
+GLOsdShader::~GLOsdShader()\r
+{\r
+       //parent does everything\r
+}\r
+\r
+int GLOsdShader::init()\r
+{\r
+       if (!initShaders(generic_vertex_shader,osd_frag_shader)) {\r
+               return 0;\r
+       }\r
+       osd_sampler_loc=glGetUniformLocation(shad_program,"texture");\r
+       return 1;\r
+\r
+}\r
+\r
+int GLOsdShader::deinit()\r
+{\r
+       return deinitShaders();\r
+}\r
+\r
+int GLOsdShader::PrepareRendering(GLuint osd_tex){ // This Function setups the rendering pipeline according to the shaders standards\r
+       glUseProgram(shad_program);\r
+\r
+       glActiveTexture(GL_TEXTURE0);\r
+       glBindTexture(GL_TEXTURE_2D,osd_tex);\r
+\r
+       glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);\r
+       glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);\r
+\r
+       glUniform1i(osd_sampler_loc,0);\r
+       return 1;\r
+\r
+}\r
+\r
+int GLOsdShader::BindAttributes()\r
+{\r
+       glBindAttribLocation(shad_program,0,"vec_pos");\r
+       glBindAttribLocation(shad_program,1,"tex_coord");\r
+       return 1;\r
+}\r
diff --git a/glosdshader.h b/glosdshader.h
new file mode 100755 (executable)
index 0000000..3a48ef3
--- /dev/null
@@ -0,0 +1,44 @@
+/*\r
+    Copyright 2012 Marten Richter\r
+\r
+    This file is part of VOMP.\r
+\r
+    VOMP is free software; you can redistribute it and/or modify\r
+    it under the terms of the GNU General Public License as published by\r
+    the Free Software Foundation; either version 2 of the License, or\r
+    (at your option) any later version.\r
+\r
+    VOMP is distributed in the hope that it will be useful,\r
+    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+    GNU General Public License for more details.\r
+\r
+    You should have received a copy of the GNU General Public License\r
+    along with VOMP; if not, write to the Free Software\r
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
+*/\r
+\r
+#ifndef GL_OSDSHADER_H\r
+#define GL_OSDSHADER_H\r
+\r
+#include "glshader.h"\r
+\r
+class GLOsdShader: public GLShader {\r
+public:\r
+       GLOsdShader();\r
+       virtual ~GLOsdShader();\r
+\r
+       int init();\r
+       int deinit();\r
+\r
+       int PrepareRendering(GLuint osd_tex); // This Function setups the rendering pipeline according to the shaders standards\r
+\r
+protected:\r
+       virtual int BindAttributes();\r
+\r
+       GLint osd_sampler_loc;\r
+\r
+};\r
+\r
+\r
+#endif\r
diff --git a/glshader.cc b/glshader.cc
new file mode 100755 (executable)
index 0000000..e84caa4
--- /dev/null
@@ -0,0 +1,105 @@
+/*\r
+    Copyright 2012 Marten Richter\r
+\r
+    This file is part of VOMP.\r
+\r
+    VOMP is free software; you can redistribute it and/or modify\r
+    it under the terms of the GNU General Public License as published by\r
+    the Free Software Foundation; either version 2 of the License, or\r
+    (at your option) any later version.\r
+\r
+    VOMP is distributed in the hope that it will be useful,\r
+    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+    GNU General Public License for more details.\r
+\r
+    You should have received a copy of the GNU General Public License\r
+    along with VOMP; if not, write to the Free Software\r
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
+*/\r
+#include "glshader.h"\r
+\r
+GLShader::GLShader(const char* name)\r
+{\r
+       initted=0;\r
+       objname=name;\r
+}\r
+\r
+GLShader::~GLShader()\r
+{\r
+       if (initted) {\r
+               deinitShaders();\r
+       }\r
+\r
+\r
+\r
+}\r
+\r
+int GLShader::initShaders(const char * vertex_shad,const char *fragment_shad)\r
+{\r
+         vertex_shader=CreateShader(vertex_shad, GL_VERTEX_SHADER);\r
+         frag_shader=CreateShader(fragment_shad, GL_FRAGMENT_SHADER);\r
+\r
+         // Create the program for osd rendering\r
+         shad_program=glCreateProgram();\r
+         if (shad_program==0) {\r
+                 Log::getInstance()->log("GLShader", Log::WARN, "%s: Creating glsl program failed!%d",objname,glGetError());\r
+             return 0;\r
+         }\r
+         glAttachShader(shad_program,vertex_shader);\r
+         glAttachShader(shad_program,frag_shader);\r
+         if (!BindAttributes()) {\r
+                 return 0;\r
+         }\r
+         glLinkProgram(shad_program);\r
+\r
+\r
+         GLint link_status;\r
+         glGetProgramiv(shad_program,GL_LINK_STATUS, &link_status);\r
+\r
+         if (!link_status) {\r
+                 char buffer[1024];\r
+                 glGetProgramInfoLog(shad_program,1024,NULL,buffer);\r
+                 Log::getInstance()->log("GLShader", Log::WARN, "%s: Compiling Programm failed!",objname);\r
+                 Log::getInstance()->log("GLShader", Log::WARN, "%s",buffer);\r
+                 glDeleteProgram(shad_program);\r
+                 return 0;\r
+         }\r
+\r
+}\r
+\r
+GLuint GLShader::CreateShader(const GLchar * source, GLenum type)\r
+{\r
+       GLuint ret_shad=0;\r
+\r
+       ret_shad=glCreateShader(type);\r
+       if (ret_shad==0 ) {\r
+               Log::getInstance()->log("GLShader", Log::WARN, "%s: Creating Shader failed! %d",objname, glGetError());\r
+               return 0;\r
+       }\r
+       glShaderSource(ret_shad,1,&source,NULL);\r
+       glCompileShader(ret_shad);\r
+       GLint comp_status;\r
+       glGetShaderiv(ret_shad,GL_COMPILE_STATUS, &comp_status);\r
+\r
+       if (!comp_status) {\r
+               char buffer[1024];\r
+               Log::getInstance()->log("GLShader", Log::WARN, "%s: Compiling Shader failed!",objname);\r
+               glGetShaderInfoLog(ret_shad,1024,NULL,buffer);\r
+               Log::getInstance()->log("GLShader", Log::WARN, "%s: %s",objname,buffer);\r
+               glDeleteShader(ret_shad);\r
+               return 0;\r
+       }\r
+       return ret_shad;\r
+}\r
+\r
+int GLShader::deinitShaders()\r
+{\r
+        if (frag_shader!=0) glDeleteShader(frag_shader);\r
+        frag_shader=0;\r
+        if (vertex_shader!=0) glDeleteShader(vertex_shader);\r
+        vertex_shader=0;\r
+        if (shad_program!=0) glDeleteProgram(shad_program);\r
+        shad_program=0;\r
+}\r
+\r
diff --git a/glshader.h b/glshader.h
new file mode 100755 (executable)
index 0000000..b349e4c
--- /dev/null
@@ -0,0 +1,55 @@
+/*\r
+    Copyright 2012 Marten Richter\r
+\r
+    This file is part of VOMP.\r
+\r
+    VOMP is free software; you can redistribute it and/or modify\r
+    it under the terms of the GNU General Public License as published by\r
+    the Free Software Foundation; either version 2 of the License, or\r
+    (at your option) any later version.\r
+\r
+    VOMP is distributed in the hope that it will be useful,\r
+    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+    GNU General Public License for more details.\r
+\r
+    You should have received a copy of the GNU General Public License\r
+    along with VOMP; if not, write to the Free Software\r
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
+*/\r
+\r
+#ifndef GL_SHADER_H\r
+#define GL_SHADER_H\r
+\r
+#include <GLES2/gl2.h>\r
+#include "log.h"\r
+\r
+class GLShader {\r
+public:\r
+       GLShader(const char* name);\r
+       virtual ~GLShader();\r
+\r
+       int initShaders(const GLchar  * vertex_shad,const GLchar  *fragment_shad);\r
+\r
+       int deinitShaders();\r
+\r
+\r
+\r
+protected:\r
+\r
+       GLuint CreateShader(const GLchar * source, GLenum type);\r
+\r
+       virtual int BindAttributes() {return 1;};\r
+\r
+       GLuint vertex_shader;\r
+       GLuint frag_shader;\r
+\r
+       GLuint shad_program;\r
+       int initted;\r
+       const char* objname;\r
+\r
+};\r
+\r
+\r
+\r
+#endif\r
diff --git a/glyuv400shader.cc b/glyuv400shader.cc
new file mode 100755 (executable)
index 0000000..976c7aa
--- /dev/null
@@ -0,0 +1,124 @@
+/*\r
+    Copyright 2012 Marten Richter\r
+\r
+    This file is part of VOMP.\r
+\r
+    VOMP is free software; you can redistribute it and/or modify\r
+    it under the terms of the GNU General Public License as published by\r
+    the Free Software Foundation; either version 2 of the License, or\r
+    (at your option) any later version.\r
+\r
+    VOMP is distributed in the hope that it will be useful,\r
+    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+    GNU General Public License for more details.\r
+\r
+    You should have received a copy of the GNU General Public License\r
+    along with VOMP; if not, write to the Free Software\r
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
+*/\r
+#include "glyuv400shader.h"\r
+\r
+const GLchar generic_vertex_shader[] =\r
+               "attribute vec4 vec_pos;\n"\r
+               "attribute vec2 tex_coord;\n"\r
+               "varying vec2 out_texCoord;\n"\r
+               "void main()\n"\r
+               "{\n"\r
+               " gl_Position=vec_pos;\n"\r
+               " out_texCoord=tex_coord;\n"\r
+               "}\n";\r
+\r
+const GLchar frame_frag_shader[] =\r
+               "precision mediump float;\n"\r
+               "uniform sampler2D textureU;\n"\r
+               "uniform sampler2D textureV;\n"\r
+               "uniform sampler2D textureY;\n"\r
+               "const float uv_corr=0.5;\n"\r
+               "const float y_corr=0.0625;\n"\r
+               "const mat3 yuvtransform= mat3( 1.164 ,0.0  ,1.596   ,\n"\r
+               "                               1.164 ,-0.391,-0.813   ,\n"\r
+               "                               1.164,2.018  , 0.0 );\n"\r
+//             "const mat3 yuvtransform= mat3( 1. ,1.  ,1.   ,\n"\r
+//             "                               0.0 ,-0.3960,2.029   ,\n"\r
+//             "                               1.140,-0.581  , 0.0 );\n"\r
+//             "const mat3 yuvtransform= mat3( 1. ,0  ,0.   ,\n"\r
+//             "                               0.0 ,1.,0.   ,\n"\r
+//             "                               0.,0.  , 1.0 );\n"\r
+//             "const mat3 yuvtransform= mat3( 1. ,1.  ,1.   ,\n"\r
+//             "                               0.0 ,-0.03960,0.2029   ,\n"\r
+//             "                               0.1140,-0.0581  , 0.0 );\n"\r
+               "varying vec2 out_texCoord;\n"\r
+               "void main()\n"\r
+               "{\n"\r
+               " vec3 help;\n"\r
+               "help.x=texture2D(textureY,out_texCoord).r-y_corr;\n"\r
+               "help.y=texture2D(textureU,out_texCoord).r-uv_corr;\n"\r
+               "help.z=texture2D(textureV,out_texCoord).r-uv_corr;\n" //-uv_corr;\n"\r
+               "  gl_FragColor.rgb=help*yuvtransform;\n"\r
+               " gl_FragColor.a=1.;\n"\r
+               "}\n";\r
+\r
+GLYuv400Shader::GLYuv400Shader(): GLShader("GLYuv400Shader")\r
+{\r
+\r
+}\r
+\r
+GLYuv400Shader::~GLYuv400Shader()\r
+{\r
+       //parent does everything\r
+}\r
+\r
+int GLYuv400Shader::init() {\r
+       if (!initShaders(generic_vertex_shader, frame_frag_shader)) {\r
+               return 0;\r
+       }\r
+       frame_sampler_locY = glGetUniformLocation(shad_program, "textureY");\r
+       // Log::getInstance()->log("OSD", Log::WARN, "uniform location %x %x",frame_sampler_locY,glGetError());\r
+       frame_sampler_locU = glGetUniformLocation(shad_program, "textureU");\r
+       //Log::getInstance()->log("OSD", Log::WARN, "uniform location %x %x",frame_sampler_locU,glGetError());\r
+       frame_sampler_locV = glGetUniformLocation(shad_program, "textureV");\r
+       return 1;\r
+\r
+}\r
+\r
+int GLYuv400Shader::deinit()\r
+{\r
+       return deinitShaders();\r
+}\r
+\r
+int GLYuv400Shader::PrepareRendering(GLuint y_tex, GLuint u_tex, GLuint v_tex) { // This Function setups the rendering pipeline according to the shaders standards\r
+       glUseProgram(shad_program);\r
+       //Log::getInstance()->log("OSD", Log::WARN, "mark1 glerror %x",glGetError());\r
+\r
+\r
+       //Log::getInstance()->log("OSD", Log::WARN, "mark2 glerror %x",glGetError());\r
+\r
+\r
+       glActiveTexture( GL_TEXTURE2);\r
+       glBindTexture(GL_TEXTURE_2D, v_tex);\r
+       glUniform1i(frame_sampler_locV, 2);\r
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);\r
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);\r
+\r
+       glActiveTexture( GL_TEXTURE1);\r
+       glBindTexture(GL_TEXTURE_2D, u_tex);\r
+       glUniform1i(frame_sampler_locU, 1);\r
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);\r
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);\r
+\r
+       glActiveTexture( GL_TEXTURE0);\r
+       glBindTexture(GL_TEXTURE_2D, y_tex);\r
+       glUniform1i(frame_sampler_locY, 0);\r
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);\r
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);\r
+       return 1;\r
+\r
+}\r
+\r
+int GLYuv400Shader::BindAttributes()\r
+{\r
+       glBindAttribLocation(shad_program,0,"vec_pos");\r
+       glBindAttribLocation(shad_program,1,"tex_coord");\r
+       return 1;\r
+}\r
diff --git a/glyuv400shader.h b/glyuv400shader.h
new file mode 100755 (executable)
index 0000000..9e78665
--- /dev/null
@@ -0,0 +1,46 @@
+/*\r
+    Copyright 2012 Marten Richter\r
+\r
+    This file is part of VOMP.\r
+\r
+    VOMP is free software; you can redistribute it and/or modify\r
+    it under the terms of the GNU General Public License as published by\r
+    the Free Software Foundation; either version 2 of the License, or\r
+    (at your option) any later version.\r
+\r
+    VOMP is distributed in the hope that it will be useful,\r
+    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+    GNU General Public License for more details.\r
+\r
+    You should have received a copy of the GNU General Public License\r
+    along with VOMP; if not, write to the Free Software\r
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
+*/\r
+\r
+#ifndef GL_YUV400SHADER_H\r
+#define GL_YUV400SHADER_H\r
+\r
+#include "glshader.h"\r
+\r
+class GLYuv400Shader: public GLShader {\r
+public:\r
+       GLYuv400Shader();\r
+       virtual ~GLYuv400Shader();\r
+\r
+       int init();\r
+       int deinit();\r
+\r
+       int PrepareRendering(GLuint y_tex,GLuint u_tex,GLuint v_tex); // This Function setups the rendering pipeline according to the shaders standards\r
+\r
+protected:\r
+       virtual int BindAttributes();\r
+\r
+       GLint frame_sampler_locY;\r
+       GLint frame_sampler_locU;\r
+       GLint frame_sampler_locV;\r
+\r
+};\r
+\r
+\r
+#endif\r
index fe19214debf7bb2a7964d3c3bced04d98b4d6914..17b46d34e9934ae60ffa1bf481a2716aa8ab4127 100755 (executable)
@@ -28,9 +28,6 @@
 #include "message.h"\r
 #include "command.h"\r
 \r
-#include "shaders/generic__vertex_shader.h"\r
-#include "shaders/osd__frag_shader.h"\r
-#include "shaders/frame__frag_shader.h"\r
 \r
 #define  BACKBUFFER_WIDTH 1920\r
 #define  BACKBUFFER_HEIGHT 1080\r
@@ -50,10 +47,6 @@ OsdOpenGL::OsdOpenGL()
   lastrendertime=getTimeMS();\r
   display_height=0;\r
   display_width=0;\r
-  osd_shader=0;\r
-  gen_shader=0;\r
-  osd_program=0;\r
-  frame_program=0;\r
 \r
 #ifdef BENCHMARK_FPS\r
        last_benchmark_time=getTimeMS();\r
@@ -102,6 +95,7 @@ int OsdOpenGL::init(void* device)
 \r
    if (egl_display==EGL_NO_DISPLAY) {\r
           Log::getInstance()->log("OSD", Log::WARN, "Could not get egl display! %x",eglGetError());\r
+          glmutex.Unlock();\r
           return 0;\r
    }\r
 \r
@@ -109,6 +103,7 @@ int OsdOpenGL::init(void* device)
 \r
    if (eglInitialize(egl_display, NULL, NULL)==EGL_FALSE) {\r
           Log::getInstance()->log("OSD", Log::WARN, "Initialising display failed! %x",eglGetError());\r
+          glmutex.Unlock();\r
           return 0;\r
    }\r
 \r
@@ -131,6 +126,7 @@ int OsdOpenGL::init(void* device)
 \r
    if (eglChooseConfig(egl_display, attributs, &egl_ourconfig, 1, &number)==EGL_FALSE) {\r
           Log::getInstance()->log("OSD", Log::WARN, "Choosing egl config failed! %d",eglGetError());\r
+          glmutex.Unlock();\r
           return 0;\r
    }\r
 \r
@@ -142,6 +138,7 @@ int OsdOpenGL::init(void* device)
    egl_context=eglCreateContext(egl_display,egl_ourconfig,EGL_NO_CONTEXT,attr_context);\r
    if (egl_context==EGL_NO_CONTEXT) {\r
           Log::getInstance()->log("OSD", Log::WARN, "Creating egl context failed! %d",eglGetError());\r
+          glmutex.Unlock();\r
           return 0;\r
    }\r
 \r
@@ -149,6 +146,7 @@ int OsdOpenGL::init(void* device)
    display_width=display_height=0;\r
    if (graphics_get_display_size(0, &display_width, &display_height)<0) {\r
           Log::getInstance()->log("OSD", Log::WARN, "Getting display size failed! (BCM API) ");\r
+          glmutex.Unlock();\r
           return 0;\r
    }\r
    Log::getInstance()->log("OSD", Log::NOTICE, "Displaysize is %d x %d ",display_width, display_height);\r
@@ -174,11 +172,13 @@ int OsdOpenGL::init(void* device)
    egl_surface = eglCreateWindowSurface(egl_display,egl_ourconfig, &nativewindow,NULL );\r
    if (egl_surface==EGL_NO_SURFACE) {\r
           Log::getInstance()->log("OSD", Log::WARN, "Creating egl window surface failed!");\r
+          glmutex.Unlock();\r
           return 0;\r
    }\r
 \r
    if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context)== EGL_FALSE) {\r
           Log::getInstance()->log("OSD", Log::WARN, "Making egl Current failed");\r
+          glmutex.Unlock();\r
                   return 0;\r
    }\r
    // Test stuff\r
@@ -214,7 +214,18 @@ int OsdOpenGL::init(void* device)
 \r
   //Preparing the Shaders\r
 \r
-  gen_shader=CreateShader(generic_vertex_shader, GL_VERTEX_SHADER);\r
+  if (!osd_shader.init()) {\r
+         Log::getInstance()->log("OSD", Log::WARN, "Init Osd Shader failed");\r
+         glmutex.Unlock();\r
+         return 0;\r
+  }\r
+  if (!yuv400_shader.init()) {\r
+         Log::getInstance()->log("OSD", Log::WARN, "Init Yuv400 Shader failed");\r
+         glmutex.Unlock();\r
+         return 0;\r
+  }\r
+\r
+ /* gen_shader=CreateShader(generic_vertex_shader, GL_VERTEX_SHADER);\r
   osd_shader=CreateShader(osd_frag_shader, GL_FRAGMENT_SHADER);\r
 \r
   // Create the program for osd rendering\r
@@ -282,7 +293,7 @@ int OsdOpenGL::init(void* device)
   frame_sampler_locU=glGetUniformLocation(frame_program,"textureU");\r
   //Log::getInstance()->log("OSD", Log::WARN, "uniform location %x %x",frame_sampler_locU,glGetError());\r
    frame_sampler_locV=glGetUniformLocation(frame_program,"textureV");\r
-\r
+*/\r
 \r
 \r
   glClearColor(0.0f,0.0f,0.0f,1.f);\r
@@ -301,30 +312,7 @@ int OsdOpenGL::init(void* device)
 }\r
 \r
 \r
-GLuint OsdOpenGL::CreateShader(const GLchar * source, GLenum type)\r
-{\r
-       GLuint ret_shad=0;\r
 \r
-       ret_shad=glCreateShader(type);\r
-       if (ret_shad==0 ) {\r
-               Log::getInstance()->log("OSD", Log::WARN, "Creating Shader failed! %d",glGetError());\r
-               return 0;\r
-       }\r
-       glShaderSource(ret_shad,1,&source,NULL);\r
-       glCompileShader(ret_shad);\r
-       GLint comp_status;\r
-       glGetShaderiv(ret_shad,GL_COMPILE_STATUS, &comp_status);\r
-\r
-       if (!comp_status) {\r
-               char buffer[1024];\r
-               Log::getInstance()->log("OSD", Log::WARN, "Compiling Shader failed!");\r
-               glGetShaderInfoLog(ret_shad,1024,NULL,buffer);\r
-               Log::getInstance()->log("OSD", Log::WARN, "%s",buffer);\r
-               glDeleteShader(ret_shad);\r
-               return 0;\r
-       }\r
-       return ret_shad;\r
-}\r
 \r
        \r
 void OsdOpenGL::InitVertexBuffer(float  scalex,float scaley)\r
@@ -389,9 +377,8 @@ int OsdOpenGL::shutdown()
   (((VideoVPEOGL*)Video::getInstance())->shutdownUsingOSDObjects());\r
 \r
 \r
-  if (osd_shader!=0) glDeleteShader(osd_shader);\r
-  if (gen_shader!=0) glDeleteShader(gen_shader);\r
-  if (osd_program!=0) glDeleteProgram(osd_program);\r
+  osd_shader.deinit();\r
+  yuv400_shader.deinit();\r
 \r
   glClear(GL_COLOR_BUFFER_BIT);\r
   eglSwapBuffers(egl_display, egl_surface);\r
@@ -578,16 +565,12 @@ void OsdOpenGL::InternalRendering(VPEOGLFrame* frame){
 \r
        if (frame) {\r
                //Log::getInstance()->log("OSD", Log::WARN, "mark1 glerror %x",glGetError());\r
-               glUseProgram(frame_program);\r
+       /*      glUseProgram(frame_program);\r
                //Log::getInstance()->log("OSD", Log::WARN, "mark1 glerror %x",glGetError());\r
                glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), osdvertices);\r
                glEnableVertexAttribArray(0);\r
                glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), &(osdvertices[0].u));\r
                glEnableVertexAttribArray(1);\r
-               glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), osdvertices);\r
-               glEnableVertexAttribArray(0);\r
-               glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), &(osdvertices[0].u));\r
-               glEnableVertexAttribArray(1);\r
 \r
 \r
                //Log::getInstance()->log("OSD", Log::WARN, "mark2 glerror %x",glGetError());\r
@@ -611,8 +594,16 @@ void OsdOpenGL::InternalRendering(VPEOGLFrame* frame){
                glBindTexture(GL_TEXTURE_2D,frame->textures[0]);\r
                glUniform1i(frame_sampler_locY,0);\r
                glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);\r
-               glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);\r
+               glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);*/\r
+\r
+               yuv400_shader.PrepareRendering(frame->textures[0],frame->textures[1],frame->textures[2]);\r
+\r
+\r
 \r
+               glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), osdvertices);\r
+               glEnableVertexAttribArray(0);\r
+               glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), &(osdvertices[0].u));\r
+               glEnableVertexAttribArray(1);\r
 \r
 \r
                //Log::getInstance()->log("OSD", Log::WARN, "mark8 glerror %x %x",glGetError(),osd_sampler_loc);\r
@@ -620,12 +611,12 @@ void OsdOpenGL::InternalRendering(VPEOGLFrame* frame){
 \r
 \r
                glDrawArrays(GL_TRIANGLE_STRIP, 0,  4);\r
-               glEnable(GL_BLEND);\r
-               glBlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ZERO,GL_ONE);\r
+\r
 \r
        }\r
 \r
-       glUseProgram(osd_program);\r
+\r
+       /*glUseProgram(osd_program);\r
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), osdvertices);\r
        glEnableVertexAttribArray(0);\r
        glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), &(osdvertices[0].u));\r
@@ -638,53 +629,29 @@ void OsdOpenGL::InternalRendering(VPEOGLFrame* frame){
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);\r
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);\r
 \r
-       glUniform1i(osd_sampler_loc,0);\r
-\r
-       if (0) { //This is ok for ffmpeg rendering not OMX\r
-               glEnable(GL_BLEND);\r
-               glBlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ZERO,GL_ONE);\r
+       glUniform1i(osd_sampler_loc,0);*/\r
 \r
-       }\r
-/*     glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX),\r
-                       (GLvoid*)(((char*)osdvertices)+3*sizeof(GLfloat)));\r
-       glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX),\r
-                       (GLvoid*)(((char*)osdvertices)+3*sizeof(GLfloat)+sizeof(OSDCOLOR)));*/\r
-       //glDisable(GL_LIGHTING);\r
-       //glEnable(GL_TEXTURE_2D);\r
-       //glEnable(GL_BLEND);\r
-    //glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);\r
-    //glDepthFunc(GL_ALWAYS);\r
-    //glDisable(GL_DEPTH_TEST);\r
-    //glDisable(GL_STENCIL_TEST);\r
-    //glDisable(GL_CULL_FACE);\r
+       osd_shader.PrepareRendering(((SurfaceOpenGL*)screen)->getTexture());\r
 \r
+       glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), osdvertices);\r
+       glEnableVertexAttribArray(0);\r
+       glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), &(osdvertices[0].u));\r
+       glEnableVertexAttribArray(1);\r
 \r
 \r
-/*\r
-       glActiveTexture(GL_TEXTURE0);\r
-       glBindTexture(GL_TEXTURE_2D,((SurfaceOpenGL*)screen)->getTexture());\r
-       glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);\r
-       glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);*/\r
-//     glUniform1i(mTextureUniformHandle, present);\r
+       if (frame!=NULL) { //This is ok for ffmpeg rendering not OMX\r
+               glEnable(GL_BLEND);\r
+               glBlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ZERO,GL_ONE);\r
 \r
+       } else {\r
+               glDisable(GL_BLEND);\r
+       }\r
 \r
 \r
        glDrawArrays(GL_TRIANGLE_STRIP, 0,  4);\r
 \r
-       //glDrawElements(GL_TRIANGLES, sizeof(osdindices)/sizeof(osdindices[0]), GL_UNSIGNED_BYTE, 0);\r
-\r
-\r
-\r
-\r
-/*     glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), 0);\r
-       glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX),\r
-                               (GLvoid*)(3*sizeof(GLfloat)));\r
-       glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX),\r
-                       (GLvoid*)(3*sizeof(GLfloat)+sizeof(OSDCOLOR)));*/\r
-\r
-       //glDisable(GL_BLEND);\r
-       //glDisable(GL_TEXTURE_2D);\r
        \r
+\r
        //Show it to the user!\r
        eglSwapBuffers(egl_display, egl_surface);\r
 \r
index 3bd5defde8cbedb0360c6cf021a2516163251ccd..5b354e1d59af7529b6fb53ee0aba70f1d682d78e 100755 (executable)
@@ -36,6 +36,9 @@
 #include "mutex.h"\r
 #include "videovpeogl.h"\r
 \r
+#include "glosdshader.h"\r
+#include "glyuv400shader.h"\r
+\r
 \r
 \r
 \r
@@ -107,7 +110,7 @@ private:
 \r
        //Maybe move the following stuff to a generic opengl object also for boosting DCT etc.\r
 \r
-   GLuint CreateShader(const GLchar * source, GLenum type);\r
+\r
 \r
        void threadMethod();\r
     void threadPostStopCleanup();\r
@@ -123,7 +126,7 @@ private:
        GLubyte osdindices[6];\r
 \r
 \r
-       GLuint osd_shader;\r
+/*     GLuint osd_shader;\r
        GLuint gen_shader;\r
 \r
        GLuint osd_program;\r
@@ -135,7 +138,10 @@ private:
        GLint frame_sampler_locU;\r
        GLint frame_sampler_locV;\r
 \r
-       GLint osd_sampler_loc;\r
+       GLint osd_sampler_loc;*/\r
+       GLOsdShader osd_shader;\r
+       GLYuv400Shader yuv400_shader;\r
+\r
 \r
 \r
 \r
diff --git a/shaders/frame__frag_shader.h b/shaders/frame__frag_shader.h
deleted file mode 100755 (executable)
index 4671f0e..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*\r
-    Copyright 2012 Marten Richter\r
-\r
-    This file is part of VOMP.\r
-\r
-    VOMP is free software; you can redistribute it and/or modify\r
-    it under the terms of the GNU General Public License as published by\r
-    the Free Software Foundation; either version 2 of the License, or\r
-    (at your option) any later version.\r
-\r
-    VOMP is distributed in the hope that it will be useful,\r
-    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-    GNU General Public License for more details.\r
-\r
-    You should have received a copy of the GNU General Public License\r
-    along with VOMP; if not, write to the Free Software\r
-    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
-*/\r
-\r
-#ifndef FRAME_FRAG_SHADER_H\r
-#define FRAME_FRAG_SHADER_H\r
-\r
-const GLchar frame_frag_shader[] =\r
-               "precision mediump float;\n"\r
-               "uniform sampler2D textureU;\n"\r
-               "uniform sampler2D textureV;\n"\r
-               "uniform sampler2D textureY;\n"\r
-               "const float uv_corr=0.5;\n"\r
-               "const float y_corr=0.0625;\n"\r
-               "const mat3 yuvtransform= mat3( 1.164 ,0.0  ,1.596   ,\n"\r
-               "                               1.164 ,-0.391,-0.813   ,\n"\r
-               "                               1.164,2.018  , 0.0 );\n"\r
-//             "const mat3 yuvtransform= mat3( 1. ,1.  ,1.   ,\n"\r
-//             "                               0.0 ,-0.3960,2.029   ,\n"\r
-//             "                               1.140,-0.581  , 0.0 );\n"\r
-//             "const mat3 yuvtransform= mat3( 1. ,0  ,0.   ,\n"\r
-//             "                               0.0 ,1.,0.   ,\n"\r
-//             "                               0.,0.  , 1.0 );\n"\r
-//             "const mat3 yuvtransform= mat3( 1. ,1.  ,1.   ,\n"\r
-//             "                               0.0 ,-0.03960,0.2029   ,\n"\r
-//             "                               0.1140,-0.0581  , 0.0 );\n"\r
-               "varying vec2 out_texCoord;\n"\r
-               "void main()\n"\r
-               "{\n"\r
-       //      "  vec3 inputcoloryuv=vec3(texture2D(textureY,out_texCoord).r-y_corr,0,0);\n"\r
-               //"                                             texture2D(textureU,out_texCoord)-uv_corr,"\r
-               //"                                             texture2D(textureV,out_texCoord)-uv_corr);"\r
-       //      "  gl_FragColor.rgb=yuvtransform*inputcoloryuv;\n"\r
-               " vec3 help;\n"\r
-               "help.x=texture2D(textureY,out_texCoord).r-y_corr;\n"\r
-               "help.y=texture2D(textureU,out_texCoord).r-uv_corr;\n"\r
-               "help.z=texture2D(textureV,out_texCoord).r-uv_corr;\n" //-uv_corr;\n"\r
-               "  gl_FragColor.rgb=help*yuvtransform;\n"\r
-               //" gl_FragColor.g=texture2D(textureU,out_texCoord).r;\n"\r
-               //" gl_FragColor.b=texture2D(textureV,out_texCoord).r;\n"\r
-               " gl_FragColor.a=1.;\n"\r
-//             " gl_FragColor=texture2D(texture,out_texCoord);\n"\r
-               //" vec4 temp=vec4(0.3,0.4,0.5,0.5);\n"\r
-               //"gl_FragColor=temp;\n"\r
-               "}\n";\r
-#endif\r
-\r
diff --git a/shaders/generic__vertex_shader.h b/shaders/generic__vertex_shader.h
deleted file mode 100644 (file)
index e5f1ac5..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*\r
-    Copyright 2012 Marten Richter\r
-\r
-    This file is part of VOMP.\r
-\r
-    VOMP is free software; you can redistribute it and/or modify\r
-    it under the terms of the GNU General Public License as published by\r
-    the Free Software Foundation; either version 2 of the License, or\r
-    (at your option) any later version.\r
-\r
-    VOMP is distributed in the hope that it will be useful,\r
-    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-    GNU General Public License for more details.\r
-\r
-    You should have received a copy of the GNU General Public License\r
-    along with VOMP; if not, write to the Free Software\r
-    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
-*/\r
-\r
-#ifndef OSD_GEN_SHADER_H\r
-#define OSD_GEN_SHADER_H\r
-\r
-const GLchar generic_vertex_shader[] =\r
-               "attribute vec4 vec_pos;\n"\r
-               "attribute vec2 tex_coord;\n"\r
-               "varying vec2 out_texCoord;\n"\r
-               "void main()\n"\r
-               "{\n"\r
-               " gl_Position=vec_pos;\n"\r
-               " out_texCoord=tex_coord;\n"\r
-               "}\n";\r
-#endif\r
diff --git a/shaders/osd__frag_shader.h b/shaders/osd__frag_shader.h
deleted file mode 100755 (executable)
index d7fb2b8..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*\r
-    Copyright 2012 Marten Richter\r
-\r
-    This file is part of VOMP.\r
-\r
-    VOMP is free software; you can redistribute it and/or modify\r
-    it under the terms of the GNU General Public License as published by\r
-    the Free Software Foundation; either version 2 of the License, or\r
-    (at your option) any later version.\r
-\r
-    VOMP is distributed in the hope that it will be useful,\r
-    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-    GNU General Public License for more details.\r
-\r
-    You should have received a copy of the GNU General Public License\r
-    along with VOMP; if not, write to the Free Software\r
-    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
-*/\r
-\r
-#ifndef OSD_FRAG_SHADER_H\r
-#define OSD_FRAG_SHADER_H\r
-\r
-const GLchar osd_frag_shader[] =\r
-               "precision mediump float;\n"\r
-               "uniform sampler2D texture;\n"\r
-               "varying vec2 out_texCoord;\n"\r
-               "void main()\n"\r
-               "{\n"\r
-       //      " vec4 temp=vec4(0.3,0.4,0.5,0.5);\n"\r
-       //      " temp.r=0.6;\n"\r
-               " gl_FragColor=texture2D(texture,out_texCoord);\n"\r
-       //      " temp.r=temp2.r;\n"\r
-       //      " temp.b=temp2.b;\n"\r
-       //      "gl_FragColor=temp;\n"\r
-               "}\n";\r
-#endif\r
-//"vec4 temp=vec4(0.3,0.4,0.5);\n"\r
-//     "temp.a=1.0f;\n"\r
-//     " gl_FragColor.r=texture2D(texture,out_texCoord.st).r;\n"\r
-//     " gl_FragColor.b=0.2f;\n"\r
-//     " gl_FragColor.g=0.2f;\n"\r
-//     "gl_FragColor.a=0.5f;\n"\r
-//"gl_FragColor=vec4(0.3,0.4,0.5,0.5);\n"\r
index 1a0b03f3f553a02e5d962e5a9abd3824fc5d33d6..c4ec0c5d20d3fa5d0a4fe76ec3418da6a146f601 100755 (executable)
@@ -1404,7 +1404,6 @@ int VideoVPEOGL::DeAllocateCodecsFFMPEG()
        dec_frame_ff_all.clear();
        dec_frame_ff_mutex.Unlock();
        dec_frame_ff_decoding=NULL;
-
        while (ogl_frame_outside) {
                Log::getInstance()->log("Video", Log::NOTICE, "Wait for ogl frame from outside");
                MILLISLEEP(20);
@@ -1898,7 +1897,7 @@ UINT VideoVPEOGL::DeliverMediaPacketFFMPEG(MediaPacket packet,
                if ((num_frames%100)==0) {
                        float fps=1000./(float)(time_in_decoder);
                        fps*=((float)num_frames);
-                       Log::getInstance()->log("OSD", Log::NOTICE, "Current Pure Decoding FPS %g", fps);
+                       Log::getInstance()->log("Video", Log::NOTICE, "Current Pure Decoding FPS %g", fps);
                }
 #endif
                if (dec_bytes<0) {