diff --git a/core/rend/gl4/gl4.h b/core/rend/gl4/gl4.h index f3ca4d436..7abc1db20 100755 --- a/core/rend/gl4/gl4.h +++ b/core/rend/gl4/gl4.h @@ -45,11 +45,6 @@ struct gl4_ctx } modvol_shader; std::map shaders; - struct - { - GLuint program,scale; - GLuint extra_depth_scale; - } OSD_SHADER; struct { diff --git a/core/rend/gl4/gles.cpp b/core/rend/gl4/gles.cpp index 5911eb636..62fcee621 100644 --- a/core/rend/gl4/gles.cpp +++ b/core/rend/gl4/gles.cpp @@ -389,22 +389,6 @@ void main() \n\ \n\ }"; -static const char* OSD_Shader = -" \ -#version 140 \n\ -out vec4 FragColor; \n\ - \n\ -smooth in lowp vec4 vtx_base; \n\ - in mediump vec2 vtx_uv; \n\ -/* Vertex input*/ \n\ -uniform sampler2D tex; \n\ -void main() \n\ -{ \n\ - mediump vec2 uv = vtx_uv; \n\ - uv.y = 1.0 - uv.y; \n\ - FragColor = vtx_base * texture(tex, uv.st); \n\n\ -}"; - gl4_ctx gl4; struct gl4ShaderUniforms_t gl4ShaderUniforms; @@ -544,12 +528,6 @@ static bool gl_create_resources() gl4.modvol_shader.scale = glGetUniformLocation(gl4.modvol_shader.program, "scale"); gl4.modvol_shader.extra_depth_scale = glGetUniformLocation(gl4.modvol_shader.program, "extra_depth_scale"); - - gl4.OSD_SHADER.program=gl_CompileAndLink(vshader, OSD_Shader); - gl4.OSD_SHADER.scale=glGetUniformLocation(gl4.OSD_SHADER.program, "scale"); - gl4.OSD_SHADER.extra_depth_scale = glGetUniformLocation(gl4.OSD_SHADER.program, "extra_depth_scale"); - glUniform1i(glGetUniformLocation(gl4.OSD_SHADER.program, "tex"),0); //bind osd texture to slot 0 - gl_load_osd_resources(); gui_init(); @@ -738,12 +716,6 @@ static bool RenderFrame() glUniform1f(gl4.modvol_shader.extra_depth_scale, gl4ShaderUniforms.extra_depth_scale); - GLfloat td[4]={0.5,0,0,0}; - - glcache.UseProgram(gl4.OSD_SHADER.program); - glUniform4fv( gl4.OSD_SHADER.scale, 1, gl4ShaderUniforms.scale_coefs); - glUniform1f(gl4.OSD_SHADER.extra_depth_scale, 1.0f); - gl4ShaderUniforms.PT_ALPHA=(PT_ALPHA_REF&0xFF)/255.0f; GLuint output_fbo; @@ -982,7 +954,13 @@ struct gl4rend : Renderer void Present() { gl_swap(); } - void DrawOSD() { OSD_DRAW(gl4.OSD_SHADER.program); } + void DrawOSD() + { + glBindVertexArray(gl4.vbo.main_vao); + glBindBuffer(GL_ARRAY_BUFFER, gl4.vbo.geometry); glCheck(); + + OSD_DRAW(); + } virtual u32 GetTexture(TSP tsp, TCW tcw) { return gl_GetTexture(tsp, tcw); diff --git a/core/rend/gles/gles.cpp b/core/rend/gles/gles.cpp index e976af9f3..e64750e6c 100644 --- a/core/rend/gles/gles.cpp +++ b/core/rend/gles/gles.cpp @@ -360,6 +360,47 @@ void main() \n\ gl_FragColor=vec4(0.0, 0.0, 0.0, sp_ShaderColor); \n\ }"; +const char* OSD_VertexShader = +"\ +%s \n\ +#define TARGET_GL %s \n\ + \n\ +#define GLES2 0 \n\ +#define GLES3 1 \n\ +#define GL2 2 \n\ +#define GL3 3 \n\ + \n\ +#if TARGET_GL == GL2 \n\ +#define highp \n\ +#define lowp \n\ +#define mediump \n\ +#endif \n\ +#if TARGET_GL == GLES2 || TARGET_GL == GL2 \n\ +#define in attribute \n\ +#define out varying \n\ +#endif \n\ + \n\ +uniform highp vec4 scale; \n\ + \n\ +in highp vec4 in_pos; \n\ +in lowp vec4 in_base; \n\ +in mediump vec2 in_uv; \n\ + \n\ +out lowp vec4 vtx_base; \n\ +out mediump vec2 vtx_uv; \n\ + \n\ +void main() \n\ +{ \n\ + vtx_base = in_base; \n\ + vtx_uv = in_uv; \n\ + highp vec4 vpos = in_pos; \n\ + \n\ + vpos.w = 1.0; \n\ + vpos.z = vpos.w; \n\ + vpos.xy = vpos.xy * scale.xy - scale.zw; \n\ + gl_Position = vpos; \n\ +}"; + const char* OSD_Shader = "\ %s \n\ @@ -383,13 +424,7 @@ out highp vec4 FragColor; \n\ #define texture texture2D \n\ #endif \n\ \n\ -#if TARGET_GL == GL3 || TARGET_GL == GLES3 \n\ -#define INTERPOLATION smooth \n\ -#else \n\ -#define INTERPOLATION \n\ -#endif \n\ - \n\ -INTERPOLATION in lowp vec4 vtx_base; \n\ +in lowp vec4 vtx_base; \n\ in mediump vec2 vtx_uv; \n\ /* Vertex input*/ \n\ uniform sampler2D tex; \n\ @@ -820,7 +855,6 @@ extern void gl_term(); static void gles_term() { glDeleteProgram(gl.modvol_shader.program); - glDeleteProgram(gl.OSD_SHADER.program); glDeleteBuffers(1, &gl.vbo.geometry); gl.vbo.geometry = 0; glDeleteBuffers(1, &gl.vbo.modvols); @@ -1075,6 +1109,15 @@ GLuint osd_tex; void gl_load_osd_resources() { + char vshader[8192]; + char fshader[8192]; + + sprintf(vshader, OSD_VertexShader, gl.glsl_version_header, gl.gl_version); + sprintf(fshader, OSD_Shader, gl.glsl_version_header, gl.gl_version); + + gl.OSD_SHADER.program = gl_CompileAndLink(vshader, fshader); + gl.OSD_SHADER.scale = glGetUniformLocation(gl.OSD_SHADER.program, "scale"); + glUniform1i(glGetUniformLocation(gl.OSD_SHADER.program, "tex"), 0); //bind osd texture to slot 0 int w, h; if (osd_tex == 0) @@ -1083,6 +1126,8 @@ void gl_load_osd_resources() void gl_free_osd_resources() { + glDeleteProgram(gl.OSD_SHADER.program); + if (osd_tex != 0) { glcache.DeleteTextures(1, &osd_tex); osd_tex = 0; @@ -1181,15 +1226,6 @@ bool gl_create_resources() gl.modvol_shader.depth_scale = glGetUniformLocation(gl.modvol_shader.program, "depth_scale"); gl.modvol_shader.extra_depth_scale = glGetUniformLocation(gl.modvol_shader.program, "extra_depth_scale"); - sprintf(fshader, OSD_Shader, gl.glsl_version_header, gl.gl_version); - - gl.OSD_SHADER.program=gl_CompileAndLink(vshader, fshader); - printf("OSD: %d\n",gl.OSD_SHADER.program); - gl.OSD_SHADER.scale=glGetUniformLocation(gl.OSD_SHADER.program, "scale"); - gl.OSD_SHADER.depth_scale=glGetUniformLocation(gl.OSD_SHADER.program, "depth_scale"); - gl.OSD_SHADER.extra_depth_scale = glGetUniformLocation(gl.OSD_SHADER.program, "extra_depth_scale"); - glUniform1i(glGetUniformLocation(gl.OSD_SHADER.program, "tex"),0); //bind osd texture to slot 0 - //#define PRECOMPILE_SHADERS #ifdef PRECOMPILE_SHADERS for (u32 i=0;i= 3) + glBindVertexArray(gl.vbo.vao); + glBindBuffer(GL_ARRAY_BUFFER, gl.vbo.geometry); glCheck(); + glEnableVertexAttribArray(VERTEX_POS_ARRAY); + glVertexAttribPointer(VERTEX_POS_ARRAY, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex,x)); + + glEnableVertexAttribArray(VERTEX_COL_BASE_ARRAY); + glVertexAttribPointer(VERTEX_COL_BASE_ARRAY, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex), (void*)offsetof(Vertex,col)); + + glEnableVertexAttribArray(VERTEX_UV_ARRAY); + glVertexAttribPointer(VERTEX_UV_ARRAY, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex,u)); + + OSD_DRAW(); + } virtual u32 GetTexture(TSP tsp, TCW tcw) { return gl_GetTexture(tsp, tcw); diff --git a/core/rend/gles/gles.h b/core/rend/gles/gles.h index 67a223732..96d0da957 100755 --- a/core/rend/gles/gles.h +++ b/core/rend/gles/gles.h @@ -96,8 +96,8 @@ struct gl_ctx PipelineShader pogram_table[24576]; struct { - GLuint program,scale,depth_scale; - GLuint extra_depth_scale; + GLuint program; + GLuint scale; } OSD_SHADER; struct @@ -175,7 +175,7 @@ bool render_output_framebuffer(); void free_output_framebuffer(); void HideOSD(); -void OSD_DRAW(GLuint shader_program); +void OSD_DRAW(); int GetProgramID(u32 cp_AlphaTest, u32 pp_ClipTestMode, u32 pp_Texture, u32 pp_UseAlpha, u32 pp_IgnoreTexA, u32 pp_ShadInstr, u32 pp_Offset, u32 pp_FogCtrl, bool pp_Gouraud, bool pp_BumpMap, bool fog_clamping, bool trilinear);