gsdx-ogl: LINUX-ONLY

* constant buffer are attached to contexts not programs. So do it only once!


git-svn-id: http://pcsx2.googlecode.com/svn/branches/gsdx-ogl@4988 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gregory.hainaut 2011-12-11 19:11:01 +00:00
parent fbb224837d
commit 4029cc5195
2 changed files with 17 additions and 29 deletions

View File

@ -267,6 +267,7 @@ bool GSDeviceOGL::Create(GSWnd* wnd)
glGenBuffers(1, &m_merge.cb->buffer); glGenBuffers(1, &m_merge.cb->buffer);
glBindBuffer(GL_UNIFORM_BUFFER, m_merge.cb->buffer); glBindBuffer(GL_UNIFORM_BUFFER, m_merge.cb->buffer);
glBufferData(GL_UNIFORM_BUFFER, m_merge.cb->byte_size, NULL, GL_DYNAMIC_DRAW); glBufferData(GL_UNIFORM_BUFFER, m_merge.cb->byte_size, NULL, GL_DYNAMIC_DRAW);
glBindBufferBase(GL_UNIFORM_BUFFER, m_merge.cb->index, m_merge.cb->buffer);
for(int i = 0; i < countof(m_merge.ps); i++) for(int i = 0; i < countof(m_merge.ps); i++)
CompileShaderFromSource("merge.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, &m_merge.ps[i]); CompileShaderFromSource("merge.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, &m_merge.ps[i]);
@ -287,6 +288,7 @@ bool GSDeviceOGL::Create(GSWnd* wnd)
glGenBuffers(1, &m_interlace.cb->buffer); glGenBuffers(1, &m_interlace.cb->buffer);
glBindBuffer(GL_UNIFORM_BUFFER, m_interlace.cb->buffer); glBindBuffer(GL_UNIFORM_BUFFER, m_interlace.cb->buffer);
glBufferData(GL_UNIFORM_BUFFER, m_interlace.cb->byte_size, NULL, GL_DYNAMIC_DRAW); glBufferData(GL_UNIFORM_BUFFER, m_interlace.cb->byte_size, NULL, GL_DYNAMIC_DRAW);
glBindBufferBase(GL_UNIFORM_BUFFER, m_interlace.cb->index, m_interlace.cb->buffer);
for(int i = 0; i < countof(m_interlace.ps); i++) for(int i = 0; i < countof(m_interlace.ps); i++)
CompileShaderFromSource("interlace.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, &m_interlace.ps[i]); CompileShaderFromSource("interlace.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, &m_interlace.ps[i]);
@ -652,15 +654,15 @@ void GSDeviceOGL::CopyRect(GSTexture* st, GSTexture* dt, const GSVector4i& r)
void GSDeviceOGL::StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, const GSVector4& dr, int shader, bool linear) void GSDeviceOGL::StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, const GSVector4& dr, int shader, bool linear)
{ {
StretchRect(st, sr, dt, dr, m_convert.ps[shader], NULL, linear); StretchRect(st, sr, dt, dr, m_convert.ps[shader], linear);
} }
void GSDeviceOGL::StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, const GSVector4& dr, GLuint ps, GSUniformBufferOGL* ps_cb, bool linear) void GSDeviceOGL::StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, const GSVector4& dr, GLuint ps, bool linear)
{ {
StretchRect(st, sr, dt, dr, ps, ps_cb, m_convert.bs, linear); StretchRect(st, sr, dt, dr, ps, m_convert.bs, linear);
} }
void GSDeviceOGL::StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, const GSVector4& dr, GLuint ps, GSUniformBufferOGL* ps_cb, GSBlendStateOGL* bs, bool linear) void GSDeviceOGL::StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, const GSVector4& dr, GLuint ps, GSBlendStateOGL* bs, bool linear)
{ {
if(!st || !dt) if(!st || !dt)
@ -727,7 +729,7 @@ void GSDeviceOGL::StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt,
// vs // vs
// ************************************ // ************************************
VSSetShader(m_convert.vs, NULL); VSSetShader(m_convert.vs);
// ************************************ // ************************************
// gs // gs
@ -741,7 +743,7 @@ void GSDeviceOGL::StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt,
PSSetShaderResources(st, NULL); PSSetShaderResources(st, NULL);
PSSetSamplerState(linear ? m_convert.ln : m_convert.pt, 0); PSSetSamplerState(linear ? m_convert.ln : m_convert.pt, 0);
PSSetShader(ps, ps_cb); PSSetShader(ps);
// ************************************ // ************************************
// Draw // Draw
@ -764,7 +766,7 @@ void GSDeviceOGL::DoMerge(GSTexture* st[2], GSVector4* sr, GSTexture* dt, GSVect
if(st[1] && !slbg) if(st[1] && !slbg)
{ {
StretchRect(st[1], sr[1], dt, dr[1], m_merge.ps[0], NULL, true); StretchRect(st[1], sr[1], dt, dr[1], m_merge.ps[0]);
} }
if(st[0]) if(st[0])
@ -775,7 +777,7 @@ void GSDeviceOGL::DoMerge(GSTexture* st[2], GSVector4* sr, GSTexture* dt, GSVect
} }
glBufferSubData(GL_UNIFORM_BUFFER, 0, m_merge.cb->byte_size, &c.v); glBufferSubData(GL_UNIFORM_BUFFER, 0, m_merge.cb->byte_size, &c.v);
StretchRect(st[0], sr[0], dt, dr[0], m_merge.ps[mmod ? 1 : 0], m_merge.cb, m_merge.bs, true); StretchRect(st[0], sr[0], dt, dr[0], m_merge.ps[mmod ? 1 : 0], m_merge.bs);
} }
} }
@ -797,7 +799,7 @@ void GSDeviceOGL::DoInterlace(GSTexture* st, GSTexture* dt, int shader, bool lin
} }
glBufferSubData(GL_UNIFORM_BUFFER, 0, m_interlace.cb->byte_size, &cb); glBufferSubData(GL_UNIFORM_BUFFER, 0, m_interlace.cb->byte_size, &cb);
StretchRect(st, sr, dt, dr, m_interlace.ps[shader], m_interlace.cb, linear); StretchRect(st, sr, dt, dr, m_interlace.ps[shader], linear);
} }
// copy a multisample texture to a non-texture multisample. On opengl you need 2 FBO with different level of // copy a multisample texture to a non-texture multisample. On opengl you need 2 FBO with different level of
@ -905,19 +907,13 @@ void GSDeviceOGL::IASetPrimitiveTopology(GLenum topology)
} }
} }
void GSDeviceOGL::VSSetShader(GLuint vs, GSUniformBufferOGL* vs_cb) void GSDeviceOGL::VSSetShader(GLuint vs)
{ {
if(m_state.vs != vs) if(m_state.vs != vs)
{ {
m_state.vs = vs; m_state.vs = vs;
glUseProgramStages(m_pipeline, GL_VERTEX_SHADER_BIT, vs); glUseProgramStages(m_pipeline, GL_VERTEX_SHADER_BIT, vs);
} }
if(m_state.vs_cb != vs_cb)
{
m_state.vs_cb = vs_cb;
glBindBufferBase(GL_UNIFORM_BUFFER, vs_cb->index, vs_cb->buffer);
}
} }
void GSDeviceOGL::GSSetShader(GLuint gs) void GSDeviceOGL::GSSetShader(GLuint gs)
@ -962,7 +958,7 @@ void GSDeviceOGL::PSSetSamplerState(GLuint ss0, GLuint ss1, GLuint ss2)
} }
} }
void GSDeviceOGL::PSSetShader(GLuint ps, GSUniformBufferOGL* ps_cb) void GSDeviceOGL::PSSetShader(GLuint ps)
{ {
if(m_state.ps != ps) if(m_state.ps != ps)
@ -1003,12 +999,6 @@ void GSDeviceOGL::PSSetShader(GLuint ps, GSUniformBufferOGL* ps_cb)
m_ss_changed = false; m_ss_changed = false;
} }
#endif #endif
if(m_state.ps_cb != ps_cb && ps_cb != NULL)
{
m_state.ps_cb = ps_cb;
glBindBufferBase(GL_UNIFORM_BUFFER, ps_cb->index, ps_cb->buffer);
}
} }
void GSDeviceOGL::OMSetFBO(GLuint fbo) void GSDeviceOGL::OMSetFBO(GLuint fbo)

View File

@ -175,13 +175,11 @@ class GSDeviceOGL : public GSDevice
GLenum topology; // (ie GL_TRIANGLES...) GLenum topology; // (ie GL_TRIANGLES...)
GLuint vs; // program GLuint vs; // program
GLuint cb; // uniform current buffer GLuint cb; // uniform current buffer
GSUniformBufferOGL* vs_cb; // uniform buffer
GLuint gs; // program GLuint gs; // program
// FIXME texture binding. Maybe not equivalent for the state but the best I could find. // FIXME texture binding. Maybe not equivalent for the state but the best I could find.
GSTextureOGL* ps_srv[3]; GSTextureOGL* ps_srv[3];
// ID3D11ShaderResourceView* ps_srv[3]; // ID3D11ShaderResourceView* ps_srv[3];
GLuint ps; // program GLuint ps; // program
GSUniformBufferOGL* ps_cb; // uniform buffer
GLuint ps_ss[3]; // sampler GLuint ps_ss[3]; // sampler
GSVector2i viewport; GSVector2i viewport;
GSVector4i scissor; GSVector4i scissor;
@ -266,8 +264,8 @@ class GSDeviceOGL : public GSDevice
void CopyRect(GSTexture* st, GSTexture* dt, const GSVector4i& r); void CopyRect(GSTexture* st, GSTexture* dt, const GSVector4i& r);
void StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, const GSVector4& dr, int shader = 0, bool linear = true); void StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, const GSVector4& dr, int shader = 0, bool linear = true);
void StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, const GSVector4& dr, GLuint ps, GSUniformBufferOGL* ps_cb, bool linear = true); void StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, const GSVector4& dr, GLuint ps, bool linear = true);
void StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, const GSVector4& dr, GLuint ps, GSUniformBufferOGL* ps_cb, GSBlendStateOGL* bs, bool linear = true); void StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, const GSVector4& dr, GLuint ps, GSBlendStateOGL* bs, bool linear = true);
GSTexture* Resolve(GSTexture* t); GSTexture* Resolve(GSTexture* t);
@ -279,13 +277,13 @@ class GSDeviceOGL : public GSDevice
void IASetVertexBufferBind(GLuint vb); void IASetVertexBufferBind(GLuint vb);
void IASetVertexArrray(GLuint va); void IASetVertexArrray(GLuint va);
void VSSetShader(GLuint vs, GSUniformBufferOGL* vs_cb); void VSSetShader(GLuint vs);
void GSSetShader(GLuint gs); void GSSetShader(GLuint gs);
void PSSetShaderResources(GSTexture* sr0, GSTexture* sr1); void PSSetShaderResources(GSTexture* sr0, GSTexture* sr1);
void PSSetShaderResource(int i, GSTexture* sr); void PSSetShaderResource(int i, GSTexture* sr);
void PSSetSamplerState(GLuint ss0, GLuint ss1, GLuint ss2 = 0); void PSSetSamplerState(GLuint ss0, GLuint ss1, GLuint ss2 = 0);
void PSSetShader(GLuint ps, GSUniformBufferOGL* ps_cb); void PSSetShader(GLuint ps);
void OMSetFBO(GLuint fbo); void OMSetFBO(GLuint fbo);
void OMSetDepthStencilState(GSDepthStencilOGL* dss, uint8 sref); void OMSetDepthStencilState(GSDepthStencilOGL* dss, uint8 sref);