diff --git a/plugins/GSdx/GSDeviceOGL.cpp b/plugins/GSdx/GSDeviceOGL.cpp index 168699c65b..64197f82ed 100644 --- a/plugins/GSdx/GSDeviceOGL.cpp +++ b/plugins/GSdx/GSDeviceOGL.cpp @@ -32,6 +32,10 @@ static uint32 g_draw_count = 0; static uint32 g_frame_count = 1; +static const uint32 g_merge_cb_index = 10; +static const uint32 g_interlace_cb_index = 11; +static const uint32 g_shadeboost_cb_index = 12; +static const uint32 g_fxaa_cb_index = 13; GSDeviceOGL::GSDeviceOGL() : m_free_window(false) @@ -287,7 +291,7 @@ bool GSDeviceOGL::Create(GSWnd* wnd) // **************************************************************** // merge // **************************************************************** - m_merge_obj.cb = new GSUniformBufferOGL(1, sizeof(MergeConstantBuffer)); + m_merge_obj.cb = new GSUniformBufferOGL(g_merge_cb_index, sizeof(MergeConstantBuffer)); for(uint i = 0; i < countof(m_merge_obj.ps); i++) CompileShaderFromSource("merge.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, &m_merge_obj.ps[i]); @@ -299,14 +303,14 @@ bool GSDeviceOGL::Create(GSWnd* wnd) // **************************************************************** // interlace // **************************************************************** - m_interlace.cb = new GSUniformBufferOGL(2, sizeof(InterlaceConstantBuffer)); + m_interlace.cb = new GSUniformBufferOGL(g_interlace_cb_index, sizeof(InterlaceConstantBuffer)); for(uint i = 0; i < countof(m_interlace.ps); i++) CompileShaderFromSource("interlace.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, &m_interlace.ps[i]); // **************************************************************** // Shade boost // **************************************************************** - m_shadeboost.cb = new GSUniformBufferOGL(6, sizeof(ShadeBoostConstantBuffer)); + m_shadeboost.cb = new GSUniformBufferOGL(g_shadeboost_cb_index, sizeof(ShadeBoostConstantBuffer)); int ShadeBoost_Contrast = theApp.GetConfig("ShadeBoost_Contrast", 50); int ShadeBoost_Brightness = theApp.GetConfig("ShadeBoost_Brightness", 50); @@ -347,7 +351,7 @@ bool GSDeviceOGL::Create(GSWnd* wnd) // FIXME need to define FXAA_GLSL_130 for the shader // FIXME need to manually set the index... // FIXME need dofxaa interface too - // m_fxaa.cb = new GSUniformBufferOGL(3, sizeof(FXAAConstantBuffer)); + // m_fxaa.cb = new GSUniformBufferOGL(g_fxaa_cb_index, sizeof(FXAAConstantBuffer)); //CompileShaderFromSource("fxaa.fx", format("ps_main", i), GL_FRAGMENT_SHADER, &m_fxaa.ps); // **************************************************************** @@ -597,47 +601,62 @@ void GSDeviceOGL::DebugOutput() //DebugBB(); } -void GSDeviceOGL::DrawPrimitive() +#ifdef DISABLE_GL42 +static void set_uniform_buffer_binding(GLuint prog, GLchar* name, GLuint binding) { + GLuint index; + index = glGetUniformBlockIndex(prog, name); + if (index != GL_INVALID_INDEX) { + glUniformBlockBinding(prog, index, binding); + } +} +#endif + +void GSDeviceOGL::BeforeDraw() { #ifdef OGL_DEBUG DebugInput(); #endif - m_state.vb->DrawPrimitive(); +#ifdef DISABLE_GL42 + set_uniform_buffer_binding(m_state.vs, "cb20", 20); + set_uniform_buffer_binding(m_state.ps, "cb21", 21); + set_uniform_buffer_binding(m_state.ps, "cb10", 10); + set_uniform_buffer_binding(m_state.ps, "cb11", 11); + set_uniform_buffer_binding(m_state.ps, "cb12", 12); + set_uniform_buffer_binding(m_state.ps, "cb13", 13); +#endif +} + +void GSDeviceOGL::AfterDraw() +{ #ifdef OGL_DEBUG DebugOutput(); g_draw_count++; #endif } +void GSDeviceOGL::DrawPrimitive() +{ + BeforeDraw(); + m_state.vb->DrawPrimitive(); + AfterDraw(); +} + void GSDeviceOGL::DrawIndexedPrimitive() { -#ifdef OGL_DEBUG - DebugInput(); -#endif - + BeforeDraw(); m_state.vb->DrawIndexedPrimitive(); - -#ifdef OGL_DEBUG - DebugOutput(); - g_draw_count++; -#endif + AfterDraw(); } void GSDeviceOGL::DrawIndexedPrimitive(int offset, int count) { ASSERT(offset + count <= m_index.count); -#ifdef OGL_DEBUG - DebugInput(); -#endif + BeforeDraw(); m_state.vb->DrawIndexedPrimitive(offset, count); - -#ifdef OGL_DEBUG - DebugOutput(); - g_draw_count++; -#endif + AfterDraw(); } void GSDeviceOGL::ClearRenderTarget(GSTexture* t, const GSVector4& c) @@ -733,7 +752,7 @@ GSTexture* GSDeviceOGL::CopyOffscreen(GSTexture* src, const GSVector4& sr, int w { ASSERT(0); - return false; + return NULL; } // FIXME: It is possible to bypass completely offscreen-buffer on opengl but it needs some re-thinking of the code. @@ -1283,7 +1302,11 @@ void GSDeviceOGL::CompileShaderFromSource(const std::string& glsl_file, const st // Build a header string // ***************************************************** // First select the version (must be the first line so we need to generate it +#ifdef DISABLE_GL42 + std::string version = "#version 330\n#extension GL_ARB_separate_shader_objects : require\n#define DISABLE_GL42\n"; +#else std::string version = "#version 330\n#extension GL_ARB_shading_language_420pack: require\n#extension GL_ARB_separate_shader_objects : require\n"; +#endif //std::string version = "#version 420\n"; // Allow to puts several shader in 1 files diff --git a/plugins/GSdx/GSDeviceOGL.h b/plugins/GSdx/GSDeviceOGL.h index 195e6697f2..697c9e6da0 100644 --- a/plugins/GSdx/GSDeviceOGL.h +++ b/plugins/GSdx/GSDeviceOGL.h @@ -599,6 +599,8 @@ class GSDeviceOGL : public GSDevice void DrawPrimitive(); void DrawIndexedPrimitive(); void DrawIndexedPrimitive(int offset, int count); + void BeforeDraw(); + void AfterDraw(); void ClearRenderTarget(GSTexture* t, const GSVector4& c); void ClearRenderTarget(GSTexture* t, uint32 c); diff --git a/plugins/GSdx/GSTextureFXOGL.cpp b/plugins/GSdx/GSTextureFXOGL.cpp index ab062688bd..80d4e4699c 100644 --- a/plugins/GSdx/GSTextureFXOGL.cpp +++ b/plugins/GSdx/GSTextureFXOGL.cpp @@ -23,10 +23,13 @@ #include "GSDeviceOGL.h" #include "GSTables.h" +static const uint32 g_vs_cb_index = 20; +static const uint32 g_ps_cb_index = 21; + void GSDeviceOGL::CreateTextureFX() { - m_vs_cb = new GSUniformBufferOGL(4, sizeof(VSConstantBuffer)); - m_ps_cb = new GSUniformBufferOGL(5, sizeof(PSConstantBuffer)); + m_vs_cb = new GSUniformBufferOGL(g_vs_cb_index, sizeof(VSConstantBuffer)); + m_ps_cb = new GSUniformBufferOGL(g_ps_cb_index, sizeof(PSConstantBuffer)); glGenSamplers(1, &m_rt_ss); // FIXME, seem to have no difference between sampler !!! diff --git a/plugins/GSdx/config.h b/plugins/GSdx/config.h index a11724fcb7..80c47392b9 100644 --- a/plugins/GSdx/config.h +++ b/plugins/GSdx/config.h @@ -35,3 +35,5 @@ //#define DISABLE_COLCLAMP //#define DISABLE_DATE + +//#define DISABLE_GL42 diff --git a/plugins/GSdx/res/interlace.glsl b/plugins/GSdx/res/interlace.glsl index 97e567fa1b..21b81af113 100644 --- a/plugins/GSdx/res/interlace.glsl +++ b/plugins/GSdx/res/interlace.glsl @@ -11,7 +11,11 @@ layout(location = 0) in vertex_basic PSin; layout(location = 0) out vec4 SV_Target0; -layout(std140, binding = 2) uniform cb0 +#ifdef DISABLE_GL42 +layout(std140) uniform cb11 +#else +layout(std140, binding = 11) uniform cb11 +#endif { vec2 ZrH; float hH; diff --git a/plugins/GSdx/res/merge.glsl b/plugins/GSdx/res/merge.glsl index e9a93bdc88..ed3ca36062 100644 --- a/plugins/GSdx/res/merge.glsl +++ b/plugins/GSdx/res/merge.glsl @@ -11,7 +11,11 @@ layout(location = 0) in vertex_basic PSin; layout(location = 0) out vec4 SV_Target0; -layout(std140, binding = 1) uniform cb0 +#ifdef DISABLE_GL42 +layout(std140) uniform cb10 +#else +layout(std140, binding = 10) uniform cb10 +#endif { vec4 BGColor; }; diff --git a/plugins/GSdx/res/shadeboost.glsl b/plugins/GSdx/res/shadeboost.glsl index c98222d80a..006329ae80 100644 --- a/plugins/GSdx/res/shadeboost.glsl +++ b/plugins/GSdx/res/shadeboost.glsl @@ -18,7 +18,11 @@ layout(location = 0) in vertex_basic PSin; layout(location = 0) out vec4 SV_Target0; -layout(std140, binding = 6) uniform cb0 +#ifdef DISABLE_GL42 +layout(std140) uniform cb12 +#else +layout(std140, binding = 12) uniform cb12 +#endif { vec4 BGColor; }; diff --git a/plugins/GSdx/res/tfx.glsl b/plugins/GSdx/res/tfx.glsl index 85c1cb732c..f25ba617a2 100644 --- a/plugins/GSdx/res/tfx.glsl +++ b/plugins/GSdx/res/tfx.glsl @@ -69,7 +69,11 @@ out gl_PerVertex { float gl_ClipDistance[]; }; -layout(std140, binding = 4) uniform cb0 +#ifdef DISABLE_GL42 +layout(std140) uniform cb20 +#else +layout(std140, binding = 20) uniform cb20 +#endif { vec4 VertexScale; vec4 VertexOffset; @@ -278,7 +282,11 @@ layout(binding = 0) uniform sampler2D TextureSampler; layout(binding = 1) uniform sampler2D PaletteSampler; layout(binding = 2) uniform sampler2D RTCopySampler; -layout(std140, binding = 5) uniform cb1 +#ifdef DISABLE_GL42 +layout(std140) uniform cb21 +#else +layout(std140, binding = 21) uniform cb21 +#endif { vec3 FogColor; float AREF;