From 73fa215b431e59576b4b37700302c7a2c27b3259 Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Sat, 9 Jun 2012 12:12:05 +0200 Subject: [PATCH] Reorganizing Shader, Creatinng GLShader framework --- GNUmakefile | 2 +- glosdshader.cc | 85 ++++++++++++ .../generic__vertex_shader.h => glosdshader.h | 35 +++-- glshader.cc | 105 ++++++++++++++ shaders/osd__frag_shader.h => glshader.h | 57 ++++---- glyuv400shader.cc | 124 +++++++++++++++++ glyuv400shader.h | 46 +++++++ osdopengl.cc | 129 +++++++----------- osdopengl.h | 12 +- shaders/frame__frag_shader.h | 63 --------- videovpeogl.cc | 3 +- 11 files changed, 476 insertions(+), 185 deletions(-) create mode 100755 glosdshader.cc rename shaders/generic__vertex_shader.h => glosdshader.h (64%) mode change 100644 => 100755 create mode 100755 glshader.cc rename shaders/osd__frag_shader.h => glshader.h (52%) create mode 100755 glyuv400shader.cc create mode 100755 glyuv400shader.h delete mode 100755 shaders/frame__frag_shader.h diff --git a/GNUmakefile b/GNUmakefile index a6bcb26..680bc08 100755 --- a/GNUmakefile +++ b/GNUmakefile @@ -57,7 +57,7 @@ $(info Raspberry pi flags) LDFLAGS = -Wall LIBS = -L/opt/vc/lib -lpthread -lrt -lEGL -lGLESv2 -lopenmaxil -lbcm_host -lavcodec -lavformat -lavutil -OBJECTS += main.o threadp.o osdopengl.o surfaceopengl.o ledraspberry.o mtdraspberry.o videovpeogl.o audiovpe.o wjpegsimple.o remotelinux.o +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 LIBS+= -ljpeg CROSSLIBS = INCLUDES = -DVOMP_PLATTFORM_RASPBERRY -I/opt/vc/include diff --git a/glosdshader.cc b/glosdshader.cc new file mode 100755 index 0000000..8ef5eb0 --- /dev/null +++ b/glosdshader.cc @@ -0,0 +1,85 @@ +/* + Copyright 2012 Marten Richter + + This file is part of VOMP. + + VOMP 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 of the License, or + (at your option) any later version. + + VOMP 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 VOMP; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +#include "glosdshader.h" + +const GLchar generic_vertex_shader[] = + "attribute vec4 vec_pos;\n" + "attribute vec2 tex_coord;\n" + "varying vec2 out_texCoord;\n" + "void main()\n" + "{\n" + " gl_Position=vec_pos;\n" + " out_texCoord=tex_coord;\n" + "}\n"; + +const GLchar osd_frag_shader[] = + "precision mediump float;\n" + "uniform sampler2D texture;\n" + "varying vec2 out_texCoord;\n" + "void main()\n" + "{\n" + " gl_FragColor=texture2D(texture,out_texCoord);\n" + "}\n"; + +GLOsdShader::GLOsdShader(): GLShader("GLOsdShader") +{ + +} + +GLOsdShader::~GLOsdShader() +{ + //parent does everything +} + +int GLOsdShader::init() +{ + if (!initShaders(generic_vertex_shader,osd_frag_shader)) { + return 0; + } + osd_sampler_loc=glGetUniformLocation(shad_program,"texture"); + return 1; + +} + +int GLOsdShader::deinit() +{ + return deinitShaders(); +} + +int GLOsdShader::PrepareRendering(GLuint osd_tex){ // This Function setups the rendering pipeline according to the shaders standards + glUseProgram(shad_program); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D,osd_tex); + + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + + glUniform1i(osd_sampler_loc,0); + return 1; + +} + +int GLOsdShader::BindAttributes() +{ + glBindAttribLocation(shad_program,0,"vec_pos"); + glBindAttribLocation(shad_program,1,"tex_coord"); + return 1; +} diff --git a/shaders/generic__vertex_shader.h b/glosdshader.h old mode 100644 new mode 100755 similarity index 64% rename from shaders/generic__vertex_shader.h rename to glosdshader.h index e5f1ac5..3a48ef3 --- a/shaders/generic__vertex_shader.h +++ b/glosdshader.h @@ -18,16 +18,27 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef OSD_GEN_SHADER_H -#define OSD_GEN_SHADER_H - -const GLchar generic_vertex_shader[] = - "attribute vec4 vec_pos;\n" - "attribute vec2 tex_coord;\n" - "varying vec2 out_texCoord;\n" - "void main()\n" - "{\n" - " gl_Position=vec_pos;\n" - " out_texCoord=tex_coord;\n" - "}\n"; +#ifndef GL_OSDSHADER_H +#define GL_OSDSHADER_H + +#include "glshader.h" + +class GLOsdShader: public GLShader { +public: + GLOsdShader(); + virtual ~GLOsdShader(); + + int init(); + int deinit(); + + int PrepareRendering(GLuint osd_tex); // This Function setups the rendering pipeline according to the shaders standards + +protected: + virtual int BindAttributes(); + + GLint osd_sampler_loc; + +}; + + #endif diff --git a/glshader.cc b/glshader.cc new file mode 100755 index 0000000..e84caa4 --- /dev/null +++ b/glshader.cc @@ -0,0 +1,105 @@ +/* + Copyright 2012 Marten Richter + + This file is part of VOMP. + + VOMP 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 of the License, or + (at your option) any later version. + + VOMP 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 VOMP; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +#include "glshader.h" + +GLShader::GLShader(const char* name) +{ + initted=0; + objname=name; +} + +GLShader::~GLShader() +{ + if (initted) { + deinitShaders(); + } + + + +} + +int GLShader::initShaders(const char * vertex_shad,const char *fragment_shad) +{ + vertex_shader=CreateShader(vertex_shad, GL_VERTEX_SHADER); + frag_shader=CreateShader(fragment_shad, GL_FRAGMENT_SHADER); + + // Create the program for osd rendering + shad_program=glCreateProgram(); + if (shad_program==0) { + Log::getInstance()->log("GLShader", Log::WARN, "%s: Creating glsl program failed!%d",objname,glGetError()); + return 0; + } + glAttachShader(shad_program,vertex_shader); + glAttachShader(shad_program,frag_shader); + if (!BindAttributes()) { + return 0; + } + glLinkProgram(shad_program); + + + GLint link_status; + glGetProgramiv(shad_program,GL_LINK_STATUS, &link_status); + + if (!link_status) { + char buffer[1024]; + glGetProgramInfoLog(shad_program,1024,NULL,buffer); + Log::getInstance()->log("GLShader", Log::WARN, "%s: Compiling Programm failed!",objname); + Log::getInstance()->log("GLShader", Log::WARN, "%s",buffer); + glDeleteProgram(shad_program); + return 0; + } + +} + +GLuint GLShader::CreateShader(const GLchar * source, GLenum type) +{ + GLuint ret_shad=0; + + ret_shad=glCreateShader(type); + if (ret_shad==0 ) { + Log::getInstance()->log("GLShader", Log::WARN, "%s: Creating Shader failed! %d",objname, glGetError()); + return 0; + } + glShaderSource(ret_shad,1,&source,NULL); + glCompileShader(ret_shad); + GLint comp_status; + glGetShaderiv(ret_shad,GL_COMPILE_STATUS, &comp_status); + + if (!comp_status) { + char buffer[1024]; + Log::getInstance()->log("GLShader", Log::WARN, "%s: Compiling Shader failed!",objname); + glGetShaderInfoLog(ret_shad,1024,NULL,buffer); + Log::getInstance()->log("GLShader", Log::WARN, "%s: %s",objname,buffer); + glDeleteShader(ret_shad); + return 0; + } + return ret_shad; +} + +int GLShader::deinitShaders() +{ + if (frag_shader!=0) glDeleteShader(frag_shader); + frag_shader=0; + if (vertex_shader!=0) glDeleteShader(vertex_shader); + vertex_shader=0; + if (shad_program!=0) glDeleteProgram(shad_program); + shad_program=0; +} + diff --git a/shaders/osd__frag_shader.h b/glshader.h similarity index 52% rename from shaders/osd__frag_shader.h rename to glshader.h index d7fb2b8..b349e4c 100755 --- a/shaders/osd__frag_shader.h +++ b/glshader.h @@ -18,27 +18,38 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef OSD_FRAG_SHADER_H -#define OSD_FRAG_SHADER_H - -const GLchar osd_frag_shader[] = - "precision mediump float;\n" - "uniform sampler2D texture;\n" - "varying vec2 out_texCoord;\n" - "void main()\n" - "{\n" - // " vec4 temp=vec4(0.3,0.4,0.5,0.5);\n" - // " temp.r=0.6;\n" - " gl_FragColor=texture2D(texture,out_texCoord);\n" - // " temp.r=temp2.r;\n" - // " temp.b=temp2.b;\n" - // "gl_FragColor=temp;\n" - "}\n"; +#ifndef GL_SHADER_H +#define GL_SHADER_H + +#include +#include "log.h" + +class GLShader { +public: + GLShader(const char* name); + virtual ~GLShader(); + + int initShaders(const GLchar * vertex_shad,const GLchar *fragment_shad); + + int deinitShaders(); + + + +protected: + + GLuint CreateShader(const GLchar * source, GLenum type); + + virtual int BindAttributes() {return 1;}; + + GLuint vertex_shader; + GLuint frag_shader; + + GLuint shad_program; + int initted; + const char* objname; + +}; + + + #endif -//"vec4 temp=vec4(0.3,0.4,0.5);\n" -// "temp.a=1.0f;\n" -// " gl_FragColor.r=texture2D(texture,out_texCoord.st).r;\n" -// " gl_FragColor.b=0.2f;\n" -// " gl_FragColor.g=0.2f;\n" -// "gl_FragColor.a=0.5f;\n" -//"gl_FragColor=vec4(0.3,0.4,0.5,0.5);\n" diff --git a/glyuv400shader.cc b/glyuv400shader.cc new file mode 100755 index 0000000..976c7aa --- /dev/null +++ b/glyuv400shader.cc @@ -0,0 +1,124 @@ +/* + Copyright 2012 Marten Richter + + This file is part of VOMP. + + VOMP 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 of the License, or + (at your option) any later version. + + VOMP 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 VOMP; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +#include "glyuv400shader.h" + +const GLchar generic_vertex_shader[] = + "attribute vec4 vec_pos;\n" + "attribute vec2 tex_coord;\n" + "varying vec2 out_texCoord;\n" + "void main()\n" + "{\n" + " gl_Position=vec_pos;\n" + " out_texCoord=tex_coord;\n" + "}\n"; + +const GLchar frame_frag_shader[] = + "precision mediump float;\n" + "uniform sampler2D textureU;\n" + "uniform sampler2D textureV;\n" + "uniform sampler2D textureY;\n" + "const float uv_corr=0.5;\n" + "const float y_corr=0.0625;\n" + "const mat3 yuvtransform= mat3( 1.164 ,0.0 ,1.596 ,\n" + " 1.164 ,-0.391,-0.813 ,\n" + " 1.164,2.018 , 0.0 );\n" +// "const mat3 yuvtransform= mat3( 1. ,1. ,1. ,\n" +// " 0.0 ,-0.3960,2.029 ,\n" +// " 1.140,-0.581 , 0.0 );\n" +// "const mat3 yuvtransform= mat3( 1. ,0 ,0. ,\n" +// " 0.0 ,1.,0. ,\n" +// " 0.,0. , 1.0 );\n" +// "const mat3 yuvtransform= mat3( 1. ,1. ,1. ,\n" +// " 0.0 ,-0.03960,0.2029 ,\n" +// " 0.1140,-0.0581 , 0.0 );\n" + "varying vec2 out_texCoord;\n" + "void main()\n" + "{\n" + " vec3 help;\n" + "help.x=texture2D(textureY,out_texCoord).r-y_corr;\n" + "help.y=texture2D(textureU,out_texCoord).r-uv_corr;\n" + "help.z=texture2D(textureV,out_texCoord).r-uv_corr;\n" //-uv_corr;\n" + " gl_FragColor.rgb=help*yuvtransform;\n" + " gl_FragColor.a=1.;\n" + "}\n"; + +GLYuv400Shader::GLYuv400Shader(): GLShader("GLYuv400Shader") +{ + +} + +GLYuv400Shader::~GLYuv400Shader() +{ + //parent does everything +} + +int GLYuv400Shader::init() { + if (!initShaders(generic_vertex_shader, frame_frag_shader)) { + return 0; + } + frame_sampler_locY = glGetUniformLocation(shad_program, "textureY"); + // Log::getInstance()->log("OSD", Log::WARN, "uniform location %x %x",frame_sampler_locY,glGetError()); + frame_sampler_locU = glGetUniformLocation(shad_program, "textureU"); + //Log::getInstance()->log("OSD", Log::WARN, "uniform location %x %x",frame_sampler_locU,glGetError()); + frame_sampler_locV = glGetUniformLocation(shad_program, "textureV"); + return 1; + +} + +int GLYuv400Shader::deinit() +{ + return deinitShaders(); +} + +int GLYuv400Shader::PrepareRendering(GLuint y_tex, GLuint u_tex, GLuint v_tex) { // This Function setups the rendering pipeline according to the shaders standards + glUseProgram(shad_program); + //Log::getInstance()->log("OSD", Log::WARN, "mark1 glerror %x",glGetError()); + + + //Log::getInstance()->log("OSD", Log::WARN, "mark2 glerror %x",glGetError()); + + + glActiveTexture( GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, v_tex); + glUniform1i(frame_sampler_locV, 2); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glActiveTexture( GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, u_tex); + glUniform1i(frame_sampler_locU, 1); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glActiveTexture( GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, y_tex); + glUniform1i(frame_sampler_locY, 0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + return 1; + +} + +int GLYuv400Shader::BindAttributes() +{ + glBindAttribLocation(shad_program,0,"vec_pos"); + glBindAttribLocation(shad_program,1,"tex_coord"); + return 1; +} diff --git a/glyuv400shader.h b/glyuv400shader.h new file mode 100755 index 0000000..9e78665 --- /dev/null +++ b/glyuv400shader.h @@ -0,0 +1,46 @@ +/* + Copyright 2012 Marten Richter + + This file is part of VOMP. + + VOMP 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 of the License, or + (at your option) any later version. + + VOMP 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 VOMP; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef GL_YUV400SHADER_H +#define GL_YUV400SHADER_H + +#include "glshader.h" + +class GLYuv400Shader: public GLShader { +public: + GLYuv400Shader(); + virtual ~GLYuv400Shader(); + + int init(); + int deinit(); + + int PrepareRendering(GLuint y_tex,GLuint u_tex,GLuint v_tex); // This Function setups the rendering pipeline according to the shaders standards + +protected: + virtual int BindAttributes(); + + GLint frame_sampler_locY; + GLint frame_sampler_locU; + GLint frame_sampler_locV; + +}; + + +#endif diff --git a/osdopengl.cc b/osdopengl.cc index fe19214..17b46d3 100755 --- a/osdopengl.cc +++ b/osdopengl.cc @@ -28,9 +28,6 @@ #include "message.h" #include "command.h" -#include "shaders/generic__vertex_shader.h" -#include "shaders/osd__frag_shader.h" -#include "shaders/frame__frag_shader.h" #define BACKBUFFER_WIDTH 1920 #define BACKBUFFER_HEIGHT 1080 @@ -50,10 +47,6 @@ OsdOpenGL::OsdOpenGL() lastrendertime=getTimeMS(); display_height=0; display_width=0; - osd_shader=0; - gen_shader=0; - osd_program=0; - frame_program=0; #ifdef BENCHMARK_FPS last_benchmark_time=getTimeMS(); @@ -102,6 +95,7 @@ int OsdOpenGL::init(void* device) if (egl_display==EGL_NO_DISPLAY) { Log::getInstance()->log("OSD", Log::WARN, "Could not get egl display! %x",eglGetError()); + glmutex.Unlock(); return 0; } @@ -109,6 +103,7 @@ int OsdOpenGL::init(void* device) if (eglInitialize(egl_display, NULL, NULL)==EGL_FALSE) { Log::getInstance()->log("OSD", Log::WARN, "Initialising display failed! %x",eglGetError()); + glmutex.Unlock(); return 0; } @@ -131,6 +126,7 @@ int OsdOpenGL::init(void* device) if (eglChooseConfig(egl_display, attributs, &egl_ourconfig, 1, &number)==EGL_FALSE) { Log::getInstance()->log("OSD", Log::WARN, "Choosing egl config failed! %d",eglGetError()); + glmutex.Unlock(); return 0; } @@ -142,6 +138,7 @@ int OsdOpenGL::init(void* device) egl_context=eglCreateContext(egl_display,egl_ourconfig,EGL_NO_CONTEXT,attr_context); if (egl_context==EGL_NO_CONTEXT) { Log::getInstance()->log("OSD", Log::WARN, "Creating egl context failed! %d",eglGetError()); + glmutex.Unlock(); return 0; } @@ -149,6 +146,7 @@ int OsdOpenGL::init(void* device) display_width=display_height=0; if (graphics_get_display_size(0, &display_width, &display_height)<0) { Log::getInstance()->log("OSD", Log::WARN, "Getting display size failed! (BCM API) "); + glmutex.Unlock(); return 0; } Log::getInstance()->log("OSD", Log::NOTICE, "Displaysize is %d x %d ",display_width, display_height); @@ -174,11 +172,13 @@ int OsdOpenGL::init(void* device) egl_surface = eglCreateWindowSurface(egl_display,egl_ourconfig, &nativewindow,NULL ); if (egl_surface==EGL_NO_SURFACE) { Log::getInstance()->log("OSD", Log::WARN, "Creating egl window surface failed!"); + glmutex.Unlock(); return 0; } if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context)== EGL_FALSE) { Log::getInstance()->log("OSD", Log::WARN, "Making egl Current failed"); + glmutex.Unlock(); return 0; } // Test stuff @@ -214,7 +214,18 @@ int OsdOpenGL::init(void* device) //Preparing the Shaders - gen_shader=CreateShader(generic_vertex_shader, GL_VERTEX_SHADER); + if (!osd_shader.init()) { + Log::getInstance()->log("OSD", Log::WARN, "Init Osd Shader failed"); + glmutex.Unlock(); + return 0; + } + if (!yuv400_shader.init()) { + Log::getInstance()->log("OSD", Log::WARN, "Init Yuv400 Shader failed"); + glmutex.Unlock(); + return 0; + } + + /* gen_shader=CreateShader(generic_vertex_shader, GL_VERTEX_SHADER); osd_shader=CreateShader(osd_frag_shader, GL_FRAGMENT_SHADER); // Create the program for osd rendering @@ -282,7 +293,7 @@ int OsdOpenGL::init(void* device) frame_sampler_locU=glGetUniformLocation(frame_program,"textureU"); //Log::getInstance()->log("OSD", Log::WARN, "uniform location %x %x",frame_sampler_locU,glGetError()); frame_sampler_locV=glGetUniformLocation(frame_program,"textureV"); - +*/ glClearColor(0.0f,0.0f,0.0f,1.f); @@ -301,30 +312,7 @@ int OsdOpenGL::init(void* device) } -GLuint OsdOpenGL::CreateShader(const GLchar * source, GLenum type) -{ - GLuint ret_shad=0; - ret_shad=glCreateShader(type); - if (ret_shad==0 ) { - Log::getInstance()->log("OSD", Log::WARN, "Creating Shader failed! %d",glGetError()); - return 0; - } - glShaderSource(ret_shad,1,&source,NULL); - glCompileShader(ret_shad); - GLint comp_status; - glGetShaderiv(ret_shad,GL_COMPILE_STATUS, &comp_status); - - if (!comp_status) { - char buffer[1024]; - Log::getInstance()->log("OSD", Log::WARN, "Compiling Shader failed!"); - glGetShaderInfoLog(ret_shad,1024,NULL,buffer); - Log::getInstance()->log("OSD", Log::WARN, "%s",buffer); - glDeleteShader(ret_shad); - return 0; - } - return ret_shad; -} void OsdOpenGL::InitVertexBuffer(float scalex,float scaley) @@ -389,9 +377,8 @@ int OsdOpenGL::shutdown() (((VideoVPEOGL*)Video::getInstance())->shutdownUsingOSDObjects()); - if (osd_shader!=0) glDeleteShader(osd_shader); - if (gen_shader!=0) glDeleteShader(gen_shader); - if (osd_program!=0) glDeleteProgram(osd_program); + osd_shader.deinit(); + yuv400_shader.deinit(); glClear(GL_COLOR_BUFFER_BIT); eglSwapBuffers(egl_display, egl_surface); @@ -578,16 +565,12 @@ void OsdOpenGL::InternalRendering(VPEOGLFrame* frame){ if (frame) { //Log::getInstance()->log("OSD", Log::WARN, "mark1 glerror %x",glGetError()); - glUseProgram(frame_program); + /* glUseProgram(frame_program); //Log::getInstance()->log("OSD", Log::WARN, "mark1 glerror %x",glGetError()); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), osdvertices); glEnableVertexAttribArray(0); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), &(osdvertices[0].u)); glEnableVertexAttribArray(1); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), osdvertices); - glEnableVertexAttribArray(0); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), &(osdvertices[0].u)); - glEnableVertexAttribArray(1); //Log::getInstance()->log("OSD", Log::WARN, "mark2 glerror %x",glGetError()); @@ -611,8 +594,16 @@ void OsdOpenGL::InternalRendering(VPEOGLFrame* frame){ glBindTexture(GL_TEXTURE_2D,frame->textures[0]); glUniform1i(frame_sampler_locY,0); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);*/ + + yuv400_shader.PrepareRendering(frame->textures[0],frame->textures[1],frame->textures[2]); + + + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), osdvertices); + glEnableVertexAttribArray(0); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), &(osdvertices[0].u)); + glEnableVertexAttribArray(1); //Log::getInstance()->log("OSD", Log::WARN, "mark8 glerror %x %x",glGetError(),osd_sampler_loc); @@ -620,12 +611,12 @@ void OsdOpenGL::InternalRendering(VPEOGLFrame* frame){ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - glEnable(GL_BLEND); - glBlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ZERO,GL_ONE); + } - glUseProgram(osd_program); + + /*glUseProgram(osd_program); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), osdvertices); glEnableVertexAttribArray(0); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), &(osdvertices[0].u)); @@ -638,53 +629,29 @@ void OsdOpenGL::InternalRendering(VPEOGLFrame* frame){ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); - glUniform1i(osd_sampler_loc,0); - - if (0) { //This is ok for ffmpeg rendering not OMX - glEnable(GL_BLEND); - glBlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ZERO,GL_ONE); + glUniform1i(osd_sampler_loc,0);*/ - } -/* glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), - (GLvoid*)(((char*)osdvertices)+3*sizeof(GLfloat))); - glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), - (GLvoid*)(((char*)osdvertices)+3*sizeof(GLfloat)+sizeof(OSDCOLOR)));*/ - //glDisable(GL_LIGHTING); - //glEnable(GL_TEXTURE_2D); - //glEnable(GL_BLEND); - //glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - //glDepthFunc(GL_ALWAYS); - //glDisable(GL_DEPTH_TEST); - //glDisable(GL_STENCIL_TEST); - //glDisable(GL_CULL_FACE); + osd_shader.PrepareRendering(((SurfaceOpenGL*)screen)->getTexture()); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), osdvertices); + glEnableVertexAttribArray(0); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), &(osdvertices[0].u)); + glEnableVertexAttribArray(1); -/* - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D,((SurfaceOpenGL*)screen)->getTexture()); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);*/ -// glUniform1i(mTextureUniformHandle, present); + if (frame!=NULL) { //This is ok for ffmpeg rendering not OMX + glEnable(GL_BLEND); + glBlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ZERO,GL_ONE); + } else { + glDisable(GL_BLEND); + } glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - //glDrawElements(GL_TRIANGLES, sizeof(osdindices)/sizeof(osdindices[0]), GL_UNSIGNED_BYTE, 0); - - - - -/* glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), 0); - glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), - (GLvoid*)(3*sizeof(GLfloat))); - glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), - (GLvoid*)(3*sizeof(GLfloat)+sizeof(OSDCOLOR)));*/ - - //glDisable(GL_BLEND); - //glDisable(GL_TEXTURE_2D); + //Show it to the user! eglSwapBuffers(egl_display, egl_surface); diff --git a/osdopengl.h b/osdopengl.h index 3bd5def..5b354e1 100755 --- a/osdopengl.h +++ b/osdopengl.h @@ -36,6 +36,9 @@ #include "mutex.h" #include "videovpeogl.h" +#include "glosdshader.h" +#include "glyuv400shader.h" + @@ -107,7 +110,7 @@ private: //Maybe move the following stuff to a generic opengl object also for boosting DCT etc. - GLuint CreateShader(const GLchar * source, GLenum type); + void threadMethod(); void threadPostStopCleanup(); @@ -123,7 +126,7 @@ private: GLubyte osdindices[6]; - GLuint osd_shader; +/* GLuint osd_shader; GLuint gen_shader; GLuint osd_program; @@ -135,7 +138,10 @@ private: GLint frame_sampler_locU; GLint frame_sampler_locV; - GLint osd_sampler_loc; + GLint osd_sampler_loc;*/ + GLOsdShader osd_shader; + GLYuv400Shader yuv400_shader; + diff --git a/shaders/frame__frag_shader.h b/shaders/frame__frag_shader.h deleted file mode 100755 index 4671f0e..0000000 --- a/shaders/frame__frag_shader.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - Copyright 2012 Marten Richter - - This file is part of VOMP. - - VOMP 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 of the License, or - (at your option) any later version. - - VOMP 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 VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#ifndef FRAME_FRAG_SHADER_H -#define FRAME_FRAG_SHADER_H - -const GLchar frame_frag_shader[] = - "precision mediump float;\n" - "uniform sampler2D textureU;\n" - "uniform sampler2D textureV;\n" - "uniform sampler2D textureY;\n" - "const float uv_corr=0.5;\n" - "const float y_corr=0.0625;\n" - "const mat3 yuvtransform= mat3( 1.164 ,0.0 ,1.596 ,\n" - " 1.164 ,-0.391,-0.813 ,\n" - " 1.164,2.018 , 0.0 );\n" -// "const mat3 yuvtransform= mat3( 1. ,1. ,1. ,\n" -// " 0.0 ,-0.3960,2.029 ,\n" -// " 1.140,-0.581 , 0.0 );\n" -// "const mat3 yuvtransform= mat3( 1. ,0 ,0. ,\n" -// " 0.0 ,1.,0. ,\n" -// " 0.,0. , 1.0 );\n" -// "const mat3 yuvtransform= mat3( 1. ,1. ,1. ,\n" -// " 0.0 ,-0.03960,0.2029 ,\n" -// " 0.1140,-0.0581 , 0.0 );\n" - "varying vec2 out_texCoord;\n" - "void main()\n" - "{\n" - // " vec3 inputcoloryuv=vec3(texture2D(textureY,out_texCoord).r-y_corr,0,0);\n" - //" texture2D(textureU,out_texCoord)-uv_corr," - //" texture2D(textureV,out_texCoord)-uv_corr);" - // " gl_FragColor.rgb=yuvtransform*inputcoloryuv;\n" - " vec3 help;\n" - "help.x=texture2D(textureY,out_texCoord).r-y_corr;\n" - "help.y=texture2D(textureU,out_texCoord).r-uv_corr;\n" - "help.z=texture2D(textureV,out_texCoord).r-uv_corr;\n" //-uv_corr;\n" - " gl_FragColor.rgb=help*yuvtransform;\n" - //" gl_FragColor.g=texture2D(textureU,out_texCoord).r;\n" - //" gl_FragColor.b=texture2D(textureV,out_texCoord).r;\n" - " gl_FragColor.a=1.;\n" -// " gl_FragColor=texture2D(texture,out_texCoord);\n" - //" vec4 temp=vec4(0.3,0.4,0.5,0.5);\n" - //"gl_FragColor=temp;\n" - "}\n"; -#endif - diff --git a/videovpeogl.cc b/videovpeogl.cc index 1a0b03f..c4ec0c5 100755 --- a/videovpeogl.cc +++ b/videovpeogl.cc @@ -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) { -- 2.39.2