diff --git a/plugins/zzogl-pg/opengl/ZZGl.h b/plugins/zzogl-pg/opengl/ZZGl.h index cbd16204aa..86061b5e02 100644 --- a/plugins/zzogl-pg/opengl/ZZGl.h +++ b/plugins/zzogl-pg/opengl/ZZGl.h @@ -151,8 +151,14 @@ extern PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC glGetFramebufferAttachmen extern PFNGLGENERATEMIPMAPEXTPROC glGenerateMipmapEXT; extern PFNGLDRAWBUFFERSPROC glDrawBuffers; +#ifdef GLSL4_API +#include "ZZoglShaders.h" +#endif static __forceinline void DrawTriangleArray() { +#ifdef GLSL4_API + ZZshSetupShader(); +#endif glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); GL_REPORT_ERRORD(); } diff --git a/plugins/zzogl-pg/opengl/ZZoglCreate.cpp b/plugins/zzogl-pg/opengl/ZZoglCreate.cpp index f659cdf76c..51c721ebef 100644 --- a/plugins/zzogl-pg/opengl/ZZoglCreate.cpp +++ b/plugins/zzogl-pg/opengl/ZZoglCreate.cpp @@ -836,7 +836,9 @@ void ZZDestroy() vb_buffer_allocated = false; // mark the buffer unallocated } +#ifdef GLSL4_API delete vertex_array; +#endif g_nCurVBOIndex = 0; diff --git a/plugins/zzogl-pg/opengl/ZZoglFlush.cpp b/plugins/zzogl-pg/opengl/ZZoglFlush.cpp index b5f0aff08e..1e53535865 100644 --- a/plugins/zzogl-pg/opengl/ZZoglFlush.cpp +++ b/plugins/zzogl-pg/opengl/ZZoglFlush.cpp @@ -89,6 +89,9 @@ int icurctx = -1; void Draw(const VB& curvb) { +#ifdef GLSL4_API + ZZshSetupShader(); +#endif glDrawArrays(primtype[curvb.curprim.prim], 0, curvb.nCount); } @@ -851,8 +854,14 @@ inline void FlushSetTexture(VB& curvb, FRAGMENTSHADER* pfragment, CRenderTarget* if( curvb.ptexClamp[1] != 0 ) ZZshGLSetTextureParameter(pfragment->prog, pfragment->sBitwiseANDY, curvb.ptexClamp[1], "Clamp 1"); + // FIXME condition is a bit strange for GLSL +#ifdef GLSL4_API + if( s_ptexCurSet[context] != 0) + ZZshGLSetTextureParameter(pfragment->prog, pfragment->sMemory, s_ptexCurSet[context], "Clamp memory"); +#else if( pfragment->sMemory != NULL && s_ptexCurSet[context] != 0) ZZshGLSetTextureParameter(pfragment->prog, pfragment->sMemory, s_ptexCurSet[context], "Clamp memory"); +#endif } // Reset program and texture variables; diff --git a/plugins/zzogl-pg/opengl/ZZoglShaders.h b/plugins/zzogl-pg/opengl/ZZoglShaders.h index af26555020..b2d8a3fd74 100644 --- a/plugins/zzogl-pg/opengl/ZZoglShaders.h +++ b/plugins/zzogl-pg/opengl/ZZoglShaders.h @@ -404,7 +404,6 @@ struct FRAGMENTSHADER ZZshShaderLink prog; // it link to FRAGMENTSHADER structure, for compability between GLSL and CG ZZshProgram program; - ZZshShaderType ShaderType; // Not every PS and VS are used together, only compatible ones. uint context; FragmentUniform uniform_buffer[ZZSH_CTX_ALL]; @@ -576,7 +575,6 @@ struct VERTEXSHADER ZZshShaderLink prog; ZZshProgram program; - ZZshShaderType ShaderType; uint context; ZZshParameter sBitBltPos, sBitBltTex, fBitBltTrans; // vertex shader constants @@ -729,6 +727,7 @@ extern GSVertexBufferStateOGL *vertex_array; extern void init_shader(); extern void PutParametersInProgram(VERTEXSHADER* vs, FRAGMENTSHADER* ps); extern void init_shader(); +extern void ZZshSetupShader(); #endif diff --git a/plugins/zzogl-pg/opengl/ZZoglShadersGLSL4.cpp b/plugins/zzogl-pg/opengl/ZZoglShadersGLSL4.cpp index 00f44852f1..25cf3cf1d9 100644 --- a/plugins/zzogl-pg/opengl/ZZoglShadersGLSL4.cpp +++ b/plugins/zzogl-pg/opengl/ZZoglShadersGLSL4.cpp @@ -71,6 +71,8 @@ #define NUMBER_OF_SAMPLERS 11 #define MAX_SHADER_NAME_SIZE 25 #define DEFINE_STRING_SIZE 256 + +// #define ENABLE_MARKER // Fire some marker for opengl Debugger (apitrace, gdebugger) //------------------ Constants // Used in a logarithmic Z-test, as (1-o(1))/log(MAX_U32). @@ -109,7 +111,6 @@ const char* ShaderCallerName = ""; const char* ShaderHandleName = ""; const char* ShaderNames[MAX_ACTIVE_SHADERS] = {""}; -ZZshShaderType ShaderTypes[MAX_ACTIVE_SHADERS] = {ZZ_SH_NONE}; ZZshProgram CompiledPrograms[MAX_ACTIVE_SHADERS][MAX_ACTIVE_SHADERS] = {{0}}; @@ -239,11 +240,23 @@ void ZZshGLEnableProfile() { // The same function for texture, also to cgGLEnable void ZZshGLSetTextureParameter(ZZshParameter param, GLuint texobj, const char* name) { +#ifdef ENABLE_MARKER + char* debug = new char[100]; + sprintf(debug, "CS: texture %d, param %d", texobj, param); + if (GLEW_GREMEDY_string_marker) glStringMarkerGREMEDY(0, debug); +#endif + g_cs.set_texture(param, texobj); } void ZZshGLSetTextureParameter(ZZshShaderLink prog, ZZshParameter param, GLuint texobj, const char* name) { FRAGMENTSHADER* shader = (FRAGMENTSHADER*)prog.link; +#ifdef ENABLE_MARKER + char* debug = new char[100]; + sprintf(debug, "FS(%d):texture %d, param %d", shader->program, texobj, param); + if (GLEW_GREMEDY_string_marker) glStringMarkerGREMEDY(0, debug); +#endif + shader->set_texture(param, texobj); } @@ -258,10 +271,20 @@ void ZZshSetParameter4fv(ZZshShaderLink& prog, ZZshParameter param, const float* VERTEXSHADER* shader = (VERTEXSHADER*)prog.link; shader->ZZshSetParameter4fv(param, v); } +#ifdef ENABLE_MARKER + char* debug = new char[100]; + sprintf(debug, "prog: uniform (%s) (%f)", name, *v); + if (GLEW_GREMEDY_string_marker) glStringMarkerGREMEDY(0, debug); +#endif } void ZZshSetParameter4fv(ZZshParameter param, const float* v, const char* name) { g_cs.ZZshSetParameter4fv(param, v); +#ifdef ENABLE_MARKER + char* debug = new char[100]; + sprintf(debug, "CS: uniform (%s) (%f)", name, *v); + if (GLEW_GREMEDY_string_marker) glStringMarkerGREMEDY(0, debug); +#endif } // The same stuff, but also with retry of param, name should be USED name of param for prog. @@ -288,15 +311,6 @@ void ZZshDefaultOneColor( FRAGMENTSHADER& ptr ) { const GLchar * EmptyVertex = "void main(void) {gl_Position = ftransform();}"; const GLchar * EmptyFragment = "void main(void) {gl_FragColor = gl_Color;}"; -ZZshShaderType ZZshGetShaderType(const char* name) { - if (strncmp(name, "TextureFog", 10) == 0) return ZZ_SH_TEXTURE_FOG; - if (strncmp(name, "Texture", 7) == 0) return ZZ_SH_TEXTURE; - if (strncmp(name, "RegularFog", 10) == 0) return ZZ_SH_REGULAR_FOG; - if (strncmp(name, "Regular", 7) == 0) return ZZ_SH_REGULAR; - if (strncmp(name, "Zero", 4) == 0) return ZZ_SH_ZERO; - return ZZ_SH_CRTC; -} - inline bool GetCompilationLog(ZZshProgram program) { #if defined(DEVBUILD) || defined(_DEBUG) GLint log_length = 0; @@ -362,7 +376,6 @@ inline bool CompileShader(ZZshProgram& program, const char* DefineString, const return false; } - ShaderTypes[program] = ZZshGetShaderType(name); ShaderNames[program] = name; GL_REPORT_ERRORD(); @@ -374,9 +387,6 @@ inline bool CompileShader(ZZshProgram& program, const char* DefineString, const inline bool LoadShaderFromFile(ZZshProgram& program, const char* DefineString, const char* name, GLenum ShaderType, bool empty = false) { // Linux specific, as I presume - // Emit annotation for apitrace - // if (GLEW_GREMEDY_string_marker) glStringMarkerGREMEDY(0, DefineString); - if (!CompileShader(program, DefineString, name, ShaderType, empty)) { ZZLog::Error_Log("Failed to compile shader for %s: ", name); return false; @@ -403,47 +413,24 @@ static void PutParametersAndRun(VERTEXSHADER* vs, FRAGMENTSHADER* ps) { GL_REPORT_ERRORD(); } -inline bool ZZshCheckShaderCompatibility(VERTEXSHADER* vs, FRAGMENTSHADER* ps) { - if (vs->ShaderType == ZZ_SH_ZERO) return true; // ZeroPS is compatible with everything +void ZZshSetupShader() { + VERTEXSHADER* vs = (VERTEXSHADER*)g_vsprog.link; + FRAGMENTSHADER* ps = (FRAGMENTSHADER*)g_psprog.link; - return (vs->ShaderType == ps->ShaderType); + if (vs == NULL || ps == NULL) return; + + PutParametersAndRun(vs, ps); } static void ZZshSetShader(VERTEXSHADER* vs, FRAGMENTSHADER* ps) { - if (vs == NULL || ps == NULL) { - // if (vs == NULL) fprintf(stderr, "VS is null !!! \n"); - // if (ps == NULL) fprintf(stderr, "PS is null !!! \n"); - return; - } + if (vs == NULL || ps == NULL) return; - // FIXME all Shader are compatible now - // I keep for the moment to avoid useless running of the program - if (!ZZshCheckShaderCompatibility(vs, ps)) { // We don't need to link uncompatible shaders - return; - } + FRAGMENTSHADER* debug = ps; - - int vss = (vs!=NULL)?vs->program:0; - int pss = (ps!=NULL)?ps->program:0; - - if (vss !=0 && pss != 0) { - FRAGMENTSHADER* debug = ps; - - glUseProgramStages(s_pipeline, GL_VERTEX_SHADER_BIT, vs->program); - glUseProgramStages(s_pipeline, GL_FRAGMENT_SHADER_BIT, ps->program); - PutParametersAndRun(vs, ps); - // // FIXME DEBUG PS SHADER - // if (ps->ShaderType == ZZ_SH_TEXTURE) { - // glUseProgramStages(s_pipeline, GL_FRAGMENT_SHADER_BIT, ppsDebug2.program); - - // PutParametersAndRun(vs, &ppsDebug2); - - // } else { - // glUseProgramStages(s_pipeline, GL_FRAGMENT_SHADER_BIT, ps->program); - // PutParametersAndRun(vs, ps); - // } - GL_REPORT_ERRORD(); - } + glUseProgramStages(s_pipeline, GL_VERTEX_SHADER_BIT, vs->program); + glUseProgramStages(s_pipeline, GL_FRAGMENT_SHADER_BIT, ps->program); + //PutParametersAndRun(vs, ps); + GL_REPORT_ERRORD(); } void ZZshSetVertexShader(ZZshShaderLink prog) { @@ -496,6 +483,13 @@ void PutParametersInProgram(VERTEXSHADER* vs, FRAGMENTSHADER* ps) { fragment_buffer->upload((void*)&ps->uniform_buffer[ps->context]); g_cs.enable_texture(); + +#ifdef ENABLE_MARKER + char* debug = new char[100]; + sprintf(debug, "FS(%d): enable texture", ps->program); + if (GLEW_GREMEDY_string_marker) glStringMarkerGREMEDY(0, debug); +#endif + ps->enable_texture(); } @@ -504,7 +498,6 @@ static void SetupFragmentProgramParameters(FRAGMENTSHADER* pf, int context, int // uniform parameters pf->prog.link = (void*)pf; // Setting autolink pf->prog.isFragment = true; // Setting autolink - pf->ShaderType = ShaderTypes[pf->program]; pf->context = context; @@ -514,7 +507,6 @@ void SetupVertexProgramParameters(VERTEXSHADER* pf, int context) { pf->prog.link = (void*)pf; // Setting autolink pf->prog.isFragment = false; // Setting autolink - pf->ShaderType = ShaderTypes[pf->program]; pf->context = context; }