2011-12-21 19:08:31 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011-2011 Gregory hainaut
|
|
|
|
* Copyright (C) 2007-2009 Gabest
|
|
|
|
*
|
|
|
|
* This Program 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, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This Program 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 GNU Make; see the file COPYING. If not, write to
|
2012-09-09 18:16:11 +00:00
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
|
2011-12-21 19:08:31 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "GSDeviceOGL.h"
|
|
|
|
#include "GSTables.h"
|
|
|
|
|
2013-04-19 19:16:26 +00:00
|
|
|
static const uint32 g_vs_cb_index = 20;
|
|
|
|
static const uint32 g_ps_cb_index = 21;
|
2015-04-19 16:22:20 +00:00
|
|
|
static const uint32 g_gs_cb_index = 22;
|
2013-04-19 19:16:26 +00:00
|
|
|
|
2011-12-21 19:08:31 +00:00
|
|
|
void GSDeviceOGL::CreateTextureFX()
|
|
|
|
{
|
2013-04-19 19:16:26 +00:00
|
|
|
m_vs_cb = new GSUniformBufferOGL(g_vs_cb_index, sizeof(VSConstantBuffer));
|
|
|
|
m_ps_cb = new GSUniformBufferOGL(g_ps_cb_index, sizeof(PSConstantBuffer));
|
2011-12-21 19:08:31 +00:00
|
|
|
|
2013-08-17 08:57:52 +00:00
|
|
|
// warning 1 sampler by image unit. So you cannot reuse m_ps_ss...
|
2013-06-26 20:09:07 +00:00
|
|
|
m_palette_ss = CreateSampler(false, false, false);
|
2015-10-17 15:05:15 +00:00
|
|
|
glBindSampler(1, m_palette_ss);
|
2011-12-21 19:08:31 +00:00
|
|
|
|
2013-06-09 16:41:58 +00:00
|
|
|
// Pre compile all Geometry & Vertex Shader
|
|
|
|
// It might cost a seconds at startup but it would reduce benchmark pollution
|
2015-10-24 12:09:21 +00:00
|
|
|
GL_PUSH("Compile GS");
|
|
|
|
|
2015-07-25 08:14:53 +00:00
|
|
|
for (uint32 key = 0; key < countof(m_gs); key++) {
|
2015-07-10 21:59:14 +00:00
|
|
|
GSSelector sel(key);
|
|
|
|
if (sel.point == sel.sprite)
|
|
|
|
m_gs[key] = 0;
|
|
|
|
else
|
|
|
|
m_gs[key] = CompileGS(GSSelector(key));
|
|
|
|
}
|
2013-06-26 20:09:07 +00:00
|
|
|
|
2015-10-24 12:09:21 +00:00
|
|
|
GL_POP();
|
|
|
|
|
|
|
|
GL_PUSH("Compile VS");
|
|
|
|
|
2015-07-25 08:14:53 +00:00
|
|
|
for (uint32 key = 0; key < countof(m_vs); key++) {
|
2015-04-19 16:01:42 +00:00
|
|
|
// wildhack is only useful if both TME and FST are enabled.
|
|
|
|
VSSelector sel(key);
|
|
|
|
if (sel.wildhack && (!sel.tme || !sel.fst))
|
|
|
|
m_vs[key] = 0;
|
|
|
|
else
|
2015-07-03 19:29:49 +00:00
|
|
|
m_vs[key] = CompileVS(sel, !GLLoader::found_GL_ARB_clip_control);
|
2015-04-19 16:01:42 +00:00
|
|
|
}
|
2013-06-26 20:09:07 +00:00
|
|
|
|
2015-10-24 12:09:21 +00:00
|
|
|
GL_POP();
|
|
|
|
|
2015-04-30 17:37:03 +00:00
|
|
|
// Enable all bits for stencil operations. Technically 1 bit is
|
|
|
|
// enough but buffer is polluted with noise. Clear will be limited
|
|
|
|
// to the mask.
|
|
|
|
glStencilMask(0xFF);
|
2015-07-25 08:14:53 +00:00
|
|
|
for (uint32 key = 0; key < countof(m_om_dss); key++) {
|
2013-06-26 20:09:07 +00:00
|
|
|
m_om_dss[key] = CreateDepthStencil(OMDepthStencilSelector(key));
|
2015-07-25 08:14:53 +00:00
|
|
|
}
|
2013-08-28 08:44:16 +00:00
|
|
|
|
|
|
|
// Help to debug FS in apitrace
|
|
|
|
m_apitrace = CompilePS(PSSelector());
|
2013-06-26 20:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GSDepthStencilOGL* GSDeviceOGL::CreateDepthStencil(OMDepthStencilSelector dssel)
|
|
|
|
{
|
|
|
|
GSDepthStencilOGL* dss = new GSDepthStencilOGL();
|
|
|
|
|
|
|
|
if (dssel.date)
|
|
|
|
{
|
|
|
|
dss->EnableStencil();
|
2015-07-25 08:14:53 +00:00
|
|
|
dss->SetStencil(GL_EQUAL, GL_KEEP);
|
2013-06-09 16:41:58 +00:00
|
|
|
}
|
2013-06-26 20:09:07 +00:00
|
|
|
|
|
|
|
if(dssel.ztst != ZTST_ALWAYS || dssel.zwe)
|
|
|
|
{
|
|
|
|
static const GLenum ztst[] =
|
|
|
|
{
|
|
|
|
GL_NEVER,
|
|
|
|
GL_ALWAYS,
|
|
|
|
GL_GEQUAL,
|
|
|
|
GL_GREATER
|
|
|
|
};
|
|
|
|
dss->EnableDepth();
|
|
|
|
dss->SetDepth(ztst[dssel.ztst], dssel.zwe);
|
2013-06-09 16:41:58 +00:00
|
|
|
}
|
2013-06-26 20:09:07 +00:00
|
|
|
|
|
|
|
return dss;
|
2011-12-21 19:08:31 +00:00
|
|
|
}
|
|
|
|
|
2015-05-06 06:44:27 +00:00
|
|
|
void GSDeviceOGL::SetupCB(const VSConstantBuffer* vs_cb, const PSConstantBuffer* ps_cb)
|
2013-06-26 20:09:07 +00:00
|
|
|
{
|
2015-08-03 06:46:25 +00:00
|
|
|
GL_PUSH("UBO");
|
2013-08-10 19:43:59 +00:00
|
|
|
if(m_vs_cb_cache.Update(vs_cb)) {
|
|
|
|
m_vs_cb->upload(vs_cb);
|
|
|
|
}
|
2013-06-26 20:09:07 +00:00
|
|
|
|
2013-08-10 19:43:59 +00:00
|
|
|
if(m_ps_cb_cache.Update(ps_cb)) {
|
|
|
|
m_ps_cb->upload(ps_cb);
|
2011-12-21 19:08:31 +00:00
|
|
|
}
|
2015-08-03 06:46:25 +00:00
|
|
|
GL_POP();
|
2013-08-10 19:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::SetupVS(VSSelector sel)
|
|
|
|
{
|
2015-07-17 16:16:35 +00:00
|
|
|
m_shader->VS(m_vs[sel]);
|
2011-12-21 19:08:31 +00:00
|
|
|
}
|
|
|
|
|
2015-07-10 21:59:14 +00:00
|
|
|
void GSDeviceOGL::SetupGS(GSSelector sel)
|
2011-12-21 19:08:31 +00:00
|
|
|
{
|
2015-07-10 21:59:14 +00:00
|
|
|
m_shader->GS(m_gs[sel]);
|
2011-12-21 19:08:31 +00:00
|
|
|
}
|
|
|
|
|
2013-08-10 19:43:59 +00:00
|
|
|
void GSDeviceOGL::SetupPS(PSSelector sel)
|
2011-12-21 19:08:31 +00:00
|
|
|
{
|
|
|
|
// *************************************************************
|
|
|
|
// Static
|
|
|
|
// *************************************************************
|
|
|
|
GLuint ps;
|
|
|
|
auto i = m_ps.find(sel);
|
|
|
|
|
2013-06-26 20:09:07 +00:00
|
|
|
if (i == m_ps.end()) {
|
|
|
|
ps = CompilePS(sel);
|
2011-12-21 19:08:31 +00:00
|
|
|
m_ps[sel] = ps;
|
|
|
|
} else {
|
|
|
|
ps = i->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
// *************************************************************
|
|
|
|
// Dynamic
|
|
|
|
// *************************************************************
|
2015-07-17 16:16:35 +00:00
|
|
|
m_shader->PS(ps);
|
2013-07-19 19:25:50 +00:00
|
|
|
}
|
2011-12-21 19:08:31 +00:00
|
|
|
|
2013-08-17 08:57:52 +00:00
|
|
|
void GSDeviceOGL::SetupSampler(PSSamplerSelector ssel)
|
2013-07-19 19:25:50 +00:00
|
|
|
{
|
2013-08-02 16:38:12 +00:00
|
|
|
PSSetSamplerState(m_ps_ss[ssel]);
|
2011-12-21 19:08:31 +00:00
|
|
|
}
|
|
|
|
|
2013-08-17 08:57:52 +00:00
|
|
|
GLuint GSDeviceOGL::GetSamplerID(PSSamplerSelector ssel)
|
|
|
|
{
|
|
|
|
return m_ps_ss[ssel];
|
|
|
|
}
|
|
|
|
|
|
|
|
GLuint GSDeviceOGL::GetPaletteSamplerID()
|
|
|
|
{
|
|
|
|
return m_palette_ss;
|
|
|
|
}
|
|
|
|
|
2015-07-31 18:28:54 +00:00
|
|
|
void GSDeviceOGL::SetupOM(OMDepthStencilSelector dssel)
|
2011-12-21 19:08:31 +00:00
|
|
|
{
|
2015-08-01 09:35:21 +00:00
|
|
|
OMSetDepthStencilState(m_om_dss[dssel]);
|
2011-12-21 19:08:31 +00:00
|
|
|
}
|