2011-11-16 22:17:37 +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-11-16 22:17:37 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-01-10 13:13:59 +00:00
|
|
|
#include "stdafx.h"
|
2011-11-16 22:17:37 +00:00
|
|
|
#include "GSRendererOGL.h"
|
|
|
|
#include "GSRenderer.h"
|
|
|
|
|
|
|
|
|
|
|
|
GSRendererOGL::GSRendererOGL()
|
2012-02-11 10:22:02 +00:00
|
|
|
: GSRendererHW(new GSTextureCacheOGL(this))
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2011-12-19 21:03:23 +00:00
|
|
|
m_pixelcenter = GSVector2(-0.5f, -0.5f);
|
2013-02-23 15:35:56 +00:00
|
|
|
|
2015-05-23 13:10:04 +00:00
|
|
|
m_accurate_blend = theApp.GetConfig("accurate_blend", 1);
|
2015-05-08 08:40:43 +00:00
|
|
|
m_accurate_date = theApp.GetConfig("accurate_date", 0);
|
2015-05-19 22:51:37 +00:00
|
|
|
m_accurate_colclip = theApp.GetConfig("accurate_colclip", 0);
|
2015-05-08 08:40:43 +00:00
|
|
|
|
|
|
|
UserHacks_AlphaHack = theApp.GetConfig("UserHacks_AlphaHack", 0);
|
|
|
|
UserHacks_AlphaStencil = theApp.GetConfig("UserHacks_AlphaStencil", 0);
|
|
|
|
UserHacks_DateGL4 = theApp.GetConfig("UserHacks_DateGL4", 0);
|
|
|
|
UserHacks_TCOffset = theApp.GetConfig("UserHacks_TCOffset", 0);
|
|
|
|
UserHacks_TCO_x = (UserHacks_TCOffset & 0xFFFF) / -1000.0f;
|
|
|
|
UserHacks_TCO_y = ((UserHacks_TCOffset >> 16) & 0xFFFF) / -1000.0f;
|
|
|
|
|
|
|
|
if (!theApp.GetConfig("UserHacks", 0)) {
|
|
|
|
UserHacks_AlphaHack = false;
|
|
|
|
UserHacks_AlphaStencil = false;
|
|
|
|
UserHacks_DateGL4 = false;
|
|
|
|
UserHacks_TCOffset = 0;
|
|
|
|
UserHacks_TCO_x = 0;
|
|
|
|
UserHacks_TCO_y = 0;
|
|
|
|
}
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-19 21:03:23 +00:00
|
|
|
bool GSRendererOGL::CreateDevice(GSDevice* dev)
|
|
|
|
{
|
2015-05-19 22:51:37 +00:00
|
|
|
if (!GSRenderer::CreateDevice(dev))
|
2011-12-19 21:03:23 +00:00
|
|
|
return false;
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2011-12-19 21:03:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2013-05-27 16:53:38 +00:00
|
|
|
void GSRendererOGL::EmulateGS()
|
|
|
|
{
|
2013-08-14 10:18:38 +00:00
|
|
|
if (m_vt.m_primclass != GS_SPRITE_CLASS) return;
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
// each sprite converted to quad needs twice the space
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
while(m_vertex.tail * 2 > m_vertex.maxcount)
|
|
|
|
{
|
|
|
|
GrowVertexBuffer();
|
|
|
|
}
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
// assume vertices are tightly packed and sequentially indexed (it should be the case)
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2015-05-19 22:51:37 +00:00
|
|
|
if (m_vertex.next >= 2)
|
2013-08-14 10:18:38 +00:00
|
|
|
{
|
|
|
|
size_t count = m_vertex.next;
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
int i = (int)count * 2 - 4;
|
|
|
|
GSVertex* s = &m_vertex.buff[count - 2];
|
|
|
|
GSVertex* q = &m_vertex.buff[count * 2 - 4];
|
|
|
|
uint32* RESTRICT index = &m_index.buff[count * 3 - 6];
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
for(; i >= 0; i -= 4, s -= 2, q -= 4, index -= 6)
|
2013-05-27 16:53:38 +00:00
|
|
|
{
|
2013-08-14 10:18:38 +00:00
|
|
|
GSVertex v0 = s[0];
|
|
|
|
GSVertex v1 = s[1];
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
v0.RGBAQ = v1.RGBAQ;
|
|
|
|
v0.XYZ.Z = v1.XYZ.Z;
|
|
|
|
v0.FOG = v1.FOG;
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
q[0] = v0;
|
|
|
|
q[3] = v1;
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
// swap x, s, u
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
uint16 x = v0.XYZ.X;
|
|
|
|
v0.XYZ.X = v1.XYZ.X;
|
|
|
|
v1.XYZ.X = x;
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
float s = v0.ST.S;
|
|
|
|
v0.ST.S = v1.ST.S;
|
|
|
|
v1.ST.S = s;
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
uint16 u = v0.U;
|
|
|
|
v0.U = v1.U;
|
|
|
|
v1.U = u;
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
q[1] = v0;
|
|
|
|
q[2] = v1;
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
index[0] = i + 0;
|
|
|
|
index[1] = i + 1;
|
|
|
|
index[2] = i + 2;
|
|
|
|
index[3] = i + 1;
|
|
|
|
index[4] = i + 2;
|
|
|
|
index[5] = i + 3;
|
2013-05-27 16:53:38 +00:00
|
|
|
}
|
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
m_vertex.head = m_vertex.tail = m_vertex.next = count * 2;
|
|
|
|
m_index.tail = count * 3;
|
2013-05-27 16:53:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-11 10:22:02 +00:00
|
|
|
void GSRendererOGL::SetupIA()
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2012-02-11 10:22:02 +00:00
|
|
|
GSDeviceOGL* dev = (GSDeviceOGL*)m_dev;
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2013-05-27 16:53:38 +00:00
|
|
|
if (!GLLoader::found_geometry_shader)
|
|
|
|
EmulateGS();
|
|
|
|
|
2015-04-13 16:34:43 +00:00
|
|
|
dev->IASetVertexBuffer(m_vertex.buff, m_vertex.next);
|
2012-02-11 10:22:02 +00:00
|
|
|
dev->IASetIndexBuffer(m_index.buff, m_index.tail);
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2013-06-28 10:43:50 +00:00
|
|
|
GLenum t = 0;
|
2012-02-11 10:22:02 +00:00
|
|
|
|
|
|
|
switch(m_vt.m_primclass)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
|
|
|
case GS_POINT_CLASS:
|
2012-02-11 10:22:02 +00:00
|
|
|
t = GL_POINTS;
|
2012-01-15 17:25:49 +00:00
|
|
|
break;
|
|
|
|
case GS_LINE_CLASS:
|
2012-02-11 10:22:02 +00:00
|
|
|
t = GL_LINES;
|
2012-01-15 17:25:49 +00:00
|
|
|
break;
|
2013-05-27 16:53:38 +00:00
|
|
|
case GS_SPRITE_CLASS:
|
|
|
|
if (GLLoader::found_geometry_shader)
|
|
|
|
t = GL_LINES;
|
|
|
|
else
|
|
|
|
t = GL_TRIANGLES;
|
|
|
|
break;
|
2012-01-15 17:25:49 +00:00
|
|
|
case GS_TRIANGLE_CLASS:
|
2012-02-11 10:22:02 +00:00
|
|
|
t = GL_TRIANGLES;
|
2012-01-15 17:25:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
__assume(0);
|
|
|
|
}
|
|
|
|
|
2012-02-11 10:22:02 +00:00
|
|
|
dev->IASetPrimitiveTopology(t);
|
|
|
|
}
|
|
|
|
|
2015-04-24 18:53:59 +00:00
|
|
|
bool GSRendererOGL::PrimitiveOverlap()
|
|
|
|
{
|
|
|
|
if (m_vertex.next < 4)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (m_vt.m_primclass != GS_SPRITE_CLASS)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Check intersection of sprite primitive only
|
|
|
|
size_t count = m_vertex.next;
|
|
|
|
GSVertex* v = &m_vertex.buff[0];
|
|
|
|
|
|
|
|
for(size_t i = 0; i < count; i += 2) {
|
|
|
|
// Very bad code
|
|
|
|
GSVector4i vi(v[i].XYZ.X, v[i].XYZ.Y, v[i+1].XYZ.X, v[i+1].XYZ.Y);
|
|
|
|
for (size_t j = i+2; j < count; j += 2) {
|
|
|
|
GSVector4i vj(v[j].XYZ.X, v[j].XYZ.Y, v[j+1].XYZ.X, v[j+1].XYZ.Y);
|
|
|
|
GSVector4i inter = vi.rintersect(vj);
|
|
|
|
if (!inter.rempty()) {
|
|
|
|
//fprintf(stderr, "Overlap found between %d and %d (draw of %d vertices)\n", i, j, count);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//fprintf(stderr, "Yes, code can be optimized (draw of %d vertices)\n", count);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-05-09 13:01:39 +00:00
|
|
|
void GSRendererOGL::SendDraw(bool require_barrier)
|
|
|
|
{
|
|
|
|
GSDeviceOGL* dev = (GSDeviceOGL*)m_dev;
|
|
|
|
|
|
|
|
if (!require_barrier || !PrimitiveOverlap()) {
|
|
|
|
dev->DrawIndexedPrimitive();
|
|
|
|
} else {
|
|
|
|
ASSERT(m_vt.m_primclass != GS_POINT_CLASS);
|
|
|
|
ASSERT(m_vt.m_primclass != GS_LINE_CLASS);
|
|
|
|
ASSERT(GLLoader::found_geometry_shader);
|
|
|
|
|
2015-05-25 15:31:27 +00:00
|
|
|
// FIXME: Investigate: a dynamic check to pack as many primitives as possibles
|
|
|
|
// I'm nearly sure GSdx already have this kind of code (maybe we can adapt GSDirtyRect)
|
2015-05-09 13:01:39 +00:00
|
|
|
size_t nb_vertex = (m_vt.m_primclass == GS_TRIANGLE_CLASS) ? 3 : 2;
|
|
|
|
|
2015-05-25 15:31:27 +00:00
|
|
|
GL_PUSH("Split the draw");
|
|
|
|
|
2015-05-17 10:19:38 +00:00
|
|
|
GL_PERF("Split single draw in %d draw", m_index.tail/nb_vertex);
|
|
|
|
|
2015-05-09 13:01:39 +00:00
|
|
|
for (size_t p = 0; p < m_index.tail; p += nb_vertex) {
|
|
|
|
gl_TextureBarrier();
|
|
|
|
dev->DrawIndexedPrimitive(p, nb_vertex);
|
|
|
|
}
|
2015-05-25 15:31:27 +00:00
|
|
|
|
|
|
|
GL_POP();
|
2015-05-09 13:01:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-11 10:22:02 +00:00
|
|
|
void GSRendererOGL::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Source* tex)
|
|
|
|
{
|
2015-05-16 17:28:22 +00:00
|
|
|
GL_PUSH("GL Draw from %d in %d (Depth %d)",
|
2015-05-12 15:41:41 +00:00
|
|
|
tex && tex->m_texture ? tex->m_texture->GetID() : 0,
|
2015-05-16 17:28:22 +00:00
|
|
|
rt->GetID(), ds->GetID());
|
2015-05-11 09:19:00 +00:00
|
|
|
|
2012-01-15 17:25:49 +00:00
|
|
|
GSDrawingEnvironment& env = m_env;
|
|
|
|
GSDrawingContext* context = m_context;
|
|
|
|
|
|
|
|
const GSVector2i& rtsize = rt->GetSize();
|
|
|
|
const GSVector2& rtscale = rt->GetScale();
|
|
|
|
|
|
|
|
bool DATE = m_context->TEST.DATE && context->FRAME.PSM != PSM_PSMCT24;
|
2015-04-24 18:53:59 +00:00
|
|
|
bool DATE_GL42 = false;
|
|
|
|
bool DATE_GL45 = false;
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2015-05-09 13:01:39 +00:00
|
|
|
bool require_barrier = false; // For blend (and maybe in date in the future)
|
|
|
|
|
2012-01-15 17:25:49 +00:00
|
|
|
ASSERT(m_dev != NULL);
|
|
|
|
|
|
|
|
GSDeviceOGL* dev = (GSDeviceOGL*)m_dev;
|
2015-05-16 11:58:36 +00:00
|
|
|
dev->s_n = s_n;
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2015-04-19 16:22:20 +00:00
|
|
|
GSDeviceOGL::VSSelector vs_sel;
|
|
|
|
GSDeviceOGL::VSConstantBuffer vs_cb;
|
2014-02-08 11:05:26 +00:00
|
|
|
|
2015-04-19 16:22:20 +00:00
|
|
|
GSDeviceOGL::PSSelector ps_sel;
|
|
|
|
GSDeviceOGL::PSConstantBuffer ps_cb;
|
|
|
|
GSDeviceOGL::PSSamplerSelector ps_ssel;
|
2014-02-08 11:05:26 +00:00
|
|
|
|
|
|
|
GSDeviceOGL::OMBlendSelector om_bsel;
|
2015-05-05 08:26:01 +00:00
|
|
|
GSDeviceOGL::OMColorMaskSelector om_csel;
|
2015-04-19 16:22:20 +00:00
|
|
|
GSDeviceOGL::OMDepthStencilSelector om_dssel;
|
|
|
|
|
2015-05-26 12:59:07 +00:00
|
|
|
// Format of the output
|
|
|
|
ps_sel.dfmt = GSLocalMemory::m_psm[context->FRAME.PSM].fmt;
|
|
|
|
|
2015-05-26 13:36:48 +00:00
|
|
|
GIFRegALPHA ALPHA = context->ALPHA;
|
|
|
|
float afix = (float)context->ALPHA.FIX / 0x80;
|
|
|
|
|
2015-04-19 16:22:20 +00:00
|
|
|
// Blend
|
2014-02-08 11:05:26 +00:00
|
|
|
|
2015-05-19 22:51:37 +00:00
|
|
|
if (!IsOpaque())
|
2014-02-08 11:05:26 +00:00
|
|
|
{
|
|
|
|
om_bsel.abe = PRIM->ABE || PRIM->AA1 && m_vt.m_primclass == GS_LINE_CLASS;
|
|
|
|
|
2015-05-26 13:36:48 +00:00
|
|
|
om_bsel.a = ALPHA.A;
|
|
|
|
om_bsel.b = ALPHA.B;
|
|
|
|
om_bsel.c = ALPHA.C;
|
|
|
|
om_bsel.d = ALPHA.D;
|
2014-02-08 11:05:26 +00:00
|
|
|
|
2015-05-19 22:51:37 +00:00
|
|
|
if (env.PABE.PABE)
|
2014-02-08 11:05:26 +00:00
|
|
|
{
|
2015-05-19 22:51:37 +00:00
|
|
|
if (om_bsel.a == 0 && om_bsel.b == 1 && om_bsel.c == 0 && om_bsel.d == 1)
|
2014-02-08 11:05:26 +00:00
|
|
|
{
|
|
|
|
// this works because with PABE alpha blending is on when alpha >= 0x80, but since the pixel shader
|
|
|
|
// cannot output anything over 0x80 (== 1.0) blending with 0x80 or turning it off gives the same result
|
|
|
|
|
|
|
|
om_bsel.abe = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Breath of Fire Dragon Quarter triggers this in battles. Graphics are fine though.
|
|
|
|
//ASSERT(0);
|
2015-05-06 06:34:45 +00:00
|
|
|
#ifdef ENABLE_OGL_DEBUG
|
|
|
|
fprintf(stderr, "env PABE not supported\n");
|
2015-05-07 22:16:31 +00:00
|
|
|
GL_INS("!!! ENV PABE not supported !!!");
|
2015-05-06 06:34:45 +00:00
|
|
|
#endif
|
2014-02-08 11:05:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-05 08:26:01 +00:00
|
|
|
om_csel.wrgba = ~GSVector4i::load((int)context->FRAME.FBMSK).eq8(GSVector4i::xffffffff()).mask();
|
2015-05-26 14:16:36 +00:00
|
|
|
if (ps_sel.dfmt == 1) {
|
|
|
|
// 24 bits no alpha channel so use 1.0f fix factor as equivalent
|
|
|
|
ALPHA.C = 2;
|
|
|
|
afix = 1.0f;
|
|
|
|
// Disable writing of the alpha channel
|
|
|
|
om_csel.wa = 0;
|
|
|
|
}
|
2014-02-08 11:05:26 +00:00
|
|
|
|
2015-04-24 18:53:59 +00:00
|
|
|
if (DATE) {
|
2015-04-25 07:59:25 +00:00
|
|
|
if (GLLoader::found_GL_ARB_texture_barrier && !PrimitiveOverlap()) {
|
2015-04-24 18:53:59 +00:00
|
|
|
DATE_GL45 = true;
|
|
|
|
DATE = false;
|
2015-05-09 17:54:01 +00:00
|
|
|
} else if (m_accurate_date && !UserHacks_AlphaStencil &&
|
|
|
|
om_csel.wa && (!context->TEST.ATE || context->TEST.ATST == ATST_ALWAYS)) {
|
|
|
|
// texture barrier will split the draw call into n draw call. It is very efficient for
|
|
|
|
// few primitive draws. Otherwise it sucks.
|
|
|
|
if (GLLoader::found_GL_ARB_texture_barrier && (m_index.tail < 100)) {
|
|
|
|
require_barrier = true;
|
|
|
|
DATE_GL45 = true;
|
|
|
|
DATE = false;
|
|
|
|
} else {
|
|
|
|
DATE_GL42 = GLLoader::found_GL_ARB_shader_image_load_store;
|
|
|
|
}
|
2015-04-24 18:53:59 +00:00
|
|
|
}
|
2014-02-08 11:05:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DATE
|
|
|
|
|
2015-04-24 18:53:59 +00:00
|
|
|
if (DATE_GL45) {
|
|
|
|
gl_TextureBarrier();
|
|
|
|
dev->PSSetShaderResource(3, rt);
|
|
|
|
} else if (DATE) {
|
2015-04-24 16:32:08 +00:00
|
|
|
// TODO: do I need to clamp the value (if yes how? rintersect with rt?)
|
|
|
|
GSVector4 si = GSVector4(rtscale.x, rtscale.y);
|
2015-05-15 18:40:09 +00:00
|
|
|
GSVector4 off = GSVector4(-1.0f, 1.0f); // Round value
|
|
|
|
GSVector4 b = m_vt.m_min.p.xyxy(m_vt.m_max.p) + off.xxyy();
|
2015-04-24 16:32:08 +00:00
|
|
|
GSVector4i ri = GSVector4i(b * si.xyxy());
|
|
|
|
|
|
|
|
// Reduce the quantity of clean function
|
|
|
|
glScissor( ri.x, ri.y, ri.width(), ri.height() );
|
2015-04-30 22:59:49 +00:00
|
|
|
GLState::scissor = ri;
|
2015-04-24 16:32:08 +00:00
|
|
|
|
2015-04-24 18:13:38 +00:00
|
|
|
// Must be done here to avoid any GL state pertubation (clear function...)
|
|
|
|
// Create an r32ui image that will containt primitive ID
|
2015-04-24 18:53:59 +00:00
|
|
|
if (DATE_GL42) {
|
2015-04-24 18:13:38 +00:00
|
|
|
dev->InitPrimDateTexture(rt);
|
2015-04-24 18:53:59 +00:00
|
|
|
dev->PSSetShaderResource(3, rt);
|
2015-04-24 18:13:38 +00:00
|
|
|
} else {
|
2012-01-15 17:25:49 +00:00
|
|
|
GSVector4 s = GSVector4(rtscale.x / rtsize.x, rtscale.y / rtsize.y);
|
|
|
|
|
2015-05-15 18:40:09 +00:00
|
|
|
GSVector4 src = (b * s.xyxy()).sat(off.zzyy());
|
|
|
|
GSVector4 dst = src * 2.0f + off.xxxx();
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2014-10-01 19:46:20 +00:00
|
|
|
GSVertexPT1 vertices[] =
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2014-10-01 19:46:20 +00:00
|
|
|
{GSVector4(dst.x, dst.y, 0.0f, 0.0f), GSVector2(src.x, src.y)},
|
|
|
|
{GSVector4(dst.z, dst.y, 0.0f, 0.0f), GSVector2(src.z, src.y)},
|
|
|
|
{GSVector4(dst.x, dst.w, 0.0f, 0.0f), GSVector2(src.x, src.w)},
|
|
|
|
{GSVector4(dst.z, dst.w, 0.0f, 0.0f), GSVector2(src.z, src.w)},
|
2012-01-15 17:25:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
dev->SetupDATE(rt, ds, vertices, m_context->TEST.DATM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
dev->BeginScene();
|
|
|
|
|
|
|
|
// om
|
|
|
|
|
2015-05-19 22:51:37 +00:00
|
|
|
if (context->TEST.ZTE)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
|
|
|
om_dssel.ztst = context->TEST.ZTST;
|
|
|
|
om_dssel.zwe = !context->ZBUF.ZMSK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
om_dssel.ztst = ZTST_ALWAYS;
|
|
|
|
}
|
|
|
|
|
2015-04-19 16:22:20 +00:00
|
|
|
// vs
|
2012-01-15 17:25:49 +00:00
|
|
|
|
|
|
|
vs_sel.tme = PRIM->TME;
|
|
|
|
vs_sel.fst = PRIM->FST;
|
2015-04-13 16:34:43 +00:00
|
|
|
vs_sel.wildhack = (UserHacks_WildHack && !isPackedUV_HackFlag) ? 1 : 0;
|
2012-01-15 17:25:49 +00:00
|
|
|
|
|
|
|
// The real GS appears to do no masking based on the Z buffer format and writing larger Z values
|
|
|
|
// than the buffer supports seems to be an error condition on the real GS, causing it to crash.
|
|
|
|
// We are probably receiving bad coordinates from VU1 in these cases.
|
|
|
|
|
2015-05-19 22:51:37 +00:00
|
|
|
if (om_dssel.ztst >= ZTST_ALWAYS && om_dssel.zwe)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2015-05-19 22:51:37 +00:00
|
|
|
if (context->ZBUF.PSM == PSM_PSMZ24)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2015-05-19 22:51:37 +00:00
|
|
|
if (m_vt.m_max.p.z > 0xffffff)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2012-02-11 10:22:02 +00:00
|
|
|
ASSERT(m_vt.m_min.p.z > 0xffffff);
|
2012-01-15 17:25:49 +00:00
|
|
|
// Fixme :Following conditional fixes some dialog frame in Wild Arms 3, but may not be what was intended.
|
2012-02-11 10:22:02 +00:00
|
|
|
if (m_vt.m_min.p.z > 0xffffff)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2015-05-07 22:16:31 +00:00
|
|
|
GL_INS("Bad Z size on 24 bits buffers")
|
2012-01-15 17:25:49 +00:00
|
|
|
vs_sel.bppz = 1;
|
|
|
|
om_dssel.ztst = ZTST_ALWAYS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 22:51:37 +00:00
|
|
|
else if (context->ZBUF.PSM == PSM_PSMZ16 || context->ZBUF.PSM == PSM_PSMZ16S)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2015-05-19 22:51:37 +00:00
|
|
|
if (m_vt.m_max.p.z > 0xffff)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2012-02-11 10:22:02 +00:00
|
|
|
ASSERT(m_vt.m_min.p.z > 0xffff); // sfex capcom logo
|
2012-01-15 17:25:49 +00:00
|
|
|
// Fixme : Same as above, I guess.
|
2012-02-11 10:22:02 +00:00
|
|
|
if (m_vt.m_min.p.z > 0xffff)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2015-05-07 22:16:31 +00:00
|
|
|
GL_INS("Bad Z size on 16 bits buffers")
|
2012-01-15 17:25:49 +00:00
|
|
|
vs_sel.bppz = 2;
|
|
|
|
om_dssel.ztst = ZTST_ALWAYS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME Opengl support half pixel center (as dx10). Code could be easier!!!
|
|
|
|
float sx = 2.0f * rtscale.x / (rtsize.x << 4);
|
|
|
|
float sy = 2.0f * rtscale.y / (rtsize.y << 4);
|
|
|
|
float ox = (float)(int)context->XYOFFSET.OFX;
|
|
|
|
float oy = (float)(int)context->XYOFFSET.OFY;
|
2013-06-26 20:09:07 +00:00
|
|
|
float ox2 = -1.0f / rtsize.x;
|
|
|
|
float oy2 = -1.0f / rtsize.y;
|
2012-01-15 17:25:49 +00:00
|
|
|
|
|
|
|
//This hack subtracts around half a pixel from OFX and OFY. (Cannot do this directly,
|
|
|
|
//because DX10 and DX9 have a different pixel center.)
|
|
|
|
//
|
|
|
|
//The resulting shifted output aligns better with common blending / corona / blurring effects,
|
|
|
|
//but introduces a few bad pixels on the edges.
|
|
|
|
|
2015-05-19 22:51:37 +00:00
|
|
|
if (rt->LikelyOffset)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
|
|
|
ox2 *= rt->OffsetHack_modx;
|
|
|
|
oy2 *= rt->OffsetHack_mody;
|
|
|
|
}
|
|
|
|
|
2013-06-26 20:09:07 +00:00
|
|
|
// Note: DX does y *= -1.0
|
|
|
|
vs_cb.Vertex_Scale_Offset = GSVector4(sx, sy, ox * sx + ox2 + 1, oy * sy + oy2 + 1);
|
2012-01-15 17:25:49 +00:00
|
|
|
// END of FIXME
|
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
// GS_SPRITE_CLASS are already flat (either by CPU or the GS)
|
|
|
|
ps_sel.iip = (m_vt.m_primclass == GS_SPRITE_CLASS) ? 1 : PRIM->IIP;
|
|
|
|
|
2015-04-24 18:53:59 +00:00
|
|
|
if (DATE_GL45) {
|
|
|
|
ps_sel.date = 5 + context->TEST.DATM;
|
2015-05-19 22:51:37 +00:00
|
|
|
} else if (DATE) {
|
2015-04-24 18:53:59 +00:00
|
|
|
if (DATE_GL42)
|
2012-01-15 17:25:49 +00:00
|
|
|
ps_sel.date = 1 + context->TEST.DATM;
|
2015-04-21 22:36:34 +00:00
|
|
|
else
|
|
|
|
om_dssel.date = 1;
|
2012-01-15 17:25:49 +00:00
|
|
|
}
|
|
|
|
|
2015-05-19 22:51:37 +00:00
|
|
|
bool colclip_wrap = env.COLCLAMP.CLAMP == 0 && !tex && PRIM->PRIM != GS_POINTLIST && !m_accurate_colclip;
|
|
|
|
bool acc_colclip_wrap = env.COLCLAMP.CLAMP == 0 && m_accurate_colclip;
|
2015-05-26 13:36:48 +00:00
|
|
|
if (ALPHA.A == ALPHA.B) { // Optimize-away colclip
|
2015-05-20 07:36:01 +00:00
|
|
|
// No addition neither substraction so no risk of overflow the [0:255] range.
|
|
|
|
colclip_wrap = false;
|
|
|
|
acc_colclip_wrap = false;
|
2015-05-19 22:51:37 +00:00
|
|
|
#ifdef ENABLE_OGL_DEBUG
|
2015-05-20 07:36:01 +00:00
|
|
|
if (colclip_wrap || acc_colclip_wrap) {
|
2015-05-19 22:51:37 +00:00
|
|
|
const char *col[3] = {"Cs", "Cd", "0"};
|
2015-05-26 13:36:48 +00:00
|
|
|
GL_INS("COLCLIP: DISABLED: blending is a plain copy of %s", col[ALPHA.D]);
|
2015-05-17 11:00:28 +00:00
|
|
|
}
|
2015-05-20 07:36:01 +00:00
|
|
|
#endif
|
2012-01-15 17:25:49 +00:00
|
|
|
}
|
2015-05-19 22:51:37 +00:00
|
|
|
if (colclip_wrap) {
|
|
|
|
ps_sel.colclip = 1;
|
2015-05-26 13:36:48 +00:00
|
|
|
GL_INS("COLCLIP ENABLED (blending is %d/%d/%d/%d)", ALPHA.A, ALPHA.B, ALPHA.C, ALPHA.D);
|
2015-05-19 22:51:37 +00:00
|
|
|
} else if (acc_colclip_wrap) {
|
2015-05-26 13:36:48 +00:00
|
|
|
ps_sel.colclip = 3;
|
|
|
|
GL_INS("COLCLIP SW ENABLED (blending is %d/%d/%d/%d)", ALPHA.A, ALPHA.B, ALPHA.C, ALPHA.D);
|
|
|
|
} else if (env.COLCLAMP.CLAMP == 0 && (ALPHA.A != ALPHA.B)) {
|
|
|
|
GL_INS("COLCLIP NOT SUPPORTED (blending is %d/%d/%d/%d)", ALPHA.A, ALPHA.B, ALPHA.C, ALPHA.D);
|
2015-05-19 22:51:37 +00:00
|
|
|
}
|
2012-01-15 17:25:49 +00:00
|
|
|
|
|
|
|
ps_sel.fba = context->FBA.FBA;
|
|
|
|
ps_sel.aout = context->FRAME.PSM == PSM_PSMCT16 || context->FRAME.PSM == PSM_PSMCT16S || (context->FRAME.FBMSK & 0xff000000) == 0x7f000000 ? 1 : 0;
|
|
|
|
|
2015-05-19 22:51:37 +00:00
|
|
|
if (UserHacks_AlphaHack) ps_sel.aout = 1;
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2015-05-19 22:51:37 +00:00
|
|
|
if (PRIM->FGE)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
|
|
|
ps_sel.fog = 1;
|
|
|
|
|
|
|
|
ps_cb.FogColor_AREF = GSVector4::rgba32(env.FOGCOL.u32[0]) / 255;
|
|
|
|
}
|
|
|
|
|
2015-05-19 22:51:37 +00:00
|
|
|
if (context->TEST.ATE)
|
2012-01-15 17:25:49 +00:00
|
|
|
ps_sel.atst = context->TEST.ATST;
|
2012-08-15 10:14:13 +00:00
|
|
|
else
|
|
|
|
ps_sel.atst = ATST_ALWAYS;
|
|
|
|
|
|
|
|
if (context->TEST.ATE && context->TEST.ATST > 1)
|
|
|
|
ps_cb.FogColor_AREF.a = (float)context->TEST.AREF;
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2012-08-15 10:14:13 +00:00
|
|
|
// Destination alpha pseudo stencil hack: use a stencil operation combined with an alpha test
|
|
|
|
// to only draw pixels which would cause the destination alpha test to fail in the future once.
|
|
|
|
// Unfortunately this also means only drawing those pixels at all, which is why this is a hack.
|
|
|
|
// The interaction with FBA in D3D9 is probably less than ideal.
|
2015-05-05 08:26:01 +00:00
|
|
|
if (UserHacks_AlphaStencil && DATE && dev->HasStencil() && om_csel.wa && (!context->TEST.ATE || context->TEST.ATST == ATST_ALWAYS))
|
2012-08-15 10:14:13 +00:00
|
|
|
{
|
|
|
|
if (!context->FBA.FBA)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2012-08-15 10:14:13 +00:00
|
|
|
if (context->TEST.DATM == 0)
|
2013-07-13 11:39:45 +00:00
|
|
|
ps_sel.atst = ATST_GEQUAL; // >=
|
2012-08-15 10:14:13 +00:00
|
|
|
else
|
2013-07-13 11:39:45 +00:00
|
|
|
ps_sel.atst = ATST_LESS; // <
|
2012-08-15 10:14:13 +00:00
|
|
|
ps_cb.FogColor_AREF.a = (float)0x80;
|
2012-01-15 17:25:49 +00:00
|
|
|
}
|
2012-08-15 10:14:13 +00:00
|
|
|
if (!(context->FBA.FBA && context->TEST.DATM == 1))
|
|
|
|
om_dssel.alpha_stencil = 1;
|
2012-01-15 17:25:49 +00:00
|
|
|
}
|
|
|
|
|
2013-08-10 19:43:59 +00:00
|
|
|
// By default don't use texture
|
|
|
|
ps_sel.tfx = 4;
|
2015-05-08 08:57:21 +00:00
|
|
|
bool spritehack = false;
|
|
|
|
int atst = ps_sel.atst;
|
2013-08-10 19:43:59 +00:00
|
|
|
|
2015-05-19 22:51:37 +00:00
|
|
|
if (tex)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2012-06-13 10:43:04 +00:00
|
|
|
const GSLocalMemory::psm_t &psm = GSLocalMemory::m_psm[context->TEX0.PSM];
|
2012-08-15 10:14:13 +00:00
|
|
|
const GSLocalMemory::psm_t &cpsm = psm.pal > 0 ? GSLocalMemory::m_psm[context->TEX0.CPSM] : psm;
|
|
|
|
bool bilinear = m_filter == 2 ? m_vt.IsLinear() : m_filter != 0;
|
|
|
|
bool simple_sample = !tex->m_palette && cpsm.fmt == 0 && context->CLAMP.WMS < 3 && context->CLAMP.WMT < 3;
|
2015-04-03 18:09:02 +00:00
|
|
|
// Don't force extra filtering on sprite (it creates various upscaling issue)
|
2015-04-15 07:26:01 +00:00
|
|
|
bilinear &= !((m_vt.m_primclass == GS_SPRITE_CLASS) && m_userhacks_round_sprite_offset && !m_vt.IsLinear());
|
2012-06-13 10:43:04 +00:00
|
|
|
|
2012-01-15 17:25:49 +00:00
|
|
|
ps_sel.wms = context->CLAMP.WMS;
|
|
|
|
ps_sel.wmt = context->CLAMP.WMT;
|
2015-05-24 14:50:01 +00:00
|
|
|
if (tex->m_palette) {
|
2015-05-25 07:46:51 +00:00
|
|
|
// In standard mode palette is only used when alpha channel of the RT is
|
|
|
|
// reinterpreted as an index. Star Ocean 3 uses it to emulate a stencil buffer.
|
|
|
|
// It is a very bad idea to force bilinear filtering on it.
|
|
|
|
bilinear = false;
|
|
|
|
|
2015-05-24 14:50:01 +00:00
|
|
|
ps_sel.fmt = cpsm.fmt | 4;
|
2015-05-30 17:01:09 +00:00
|
|
|
ps_sel.ifmt = !tex->m_alpha_palette ? 0
|
|
|
|
: (context->TEX0.PSM == 0x1B) ? 3
|
2015-05-24 14:50:01 +00:00
|
|
|
: (context->TEX0.PSM == 0x24) ? 2
|
|
|
|
: (context->TEX0.PSM == 0x2C) ? 1
|
|
|
|
: 0;
|
2015-06-02 07:27:34 +00:00
|
|
|
//GL_INS("Use palette with format %d and index format %d", ps_sel.fmt, ps_sel.ifmt);
|
2015-05-24 14:50:01 +00:00
|
|
|
} else {
|
|
|
|
ps_sel.fmt = cpsm.fmt;
|
|
|
|
}
|
2012-01-15 17:25:49 +00:00
|
|
|
ps_sel.aem = env.TEXA.AEM;
|
|
|
|
ps_sel.tfx = context->TEX0.TFX;
|
|
|
|
ps_sel.tcc = context->TEX0.TCC;
|
2012-08-15 10:14:13 +00:00
|
|
|
ps_sel.ltf = bilinear && !simple_sample;
|
2015-05-08 08:57:21 +00:00
|
|
|
spritehack = tex->m_spritehack_t;
|
2013-08-10 19:43:59 +00:00
|
|
|
// FIXME the ati is currently disabled on the shader. I need to find a .gs to test that we got same
|
|
|
|
// bug on opengl
|
2013-10-24 20:54:27 +00:00
|
|
|
// FIXME for the moment disable it on subroutine (it will kill my perf for nothings)
|
2015-05-06 06:38:17 +00:00
|
|
|
//ps_sel.point_sampler = 0; // !(bilinear && simple_sample) && !GLLoader::found_GL_ARB_shader_subroutine;
|
2012-01-15 17:25:49 +00:00
|
|
|
|
|
|
|
int w = tex->m_texture->GetWidth();
|
|
|
|
int h = tex->m_texture->GetHeight();
|
|
|
|
|
|
|
|
int tw = (int)(1 << context->TEX0.TW);
|
|
|
|
int th = (int)(1 << context->TEX0.TH);
|
|
|
|
|
|
|
|
GSVector4 WH(tw, th, w, h);
|
|
|
|
|
2015-05-19 22:51:37 +00:00
|
|
|
if (PRIM->FST)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
|
|
|
vs_cb.TextureScale = GSVector4(1.0f / 16) / WH.xyxy();
|
|
|
|
ps_sel.fst = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ps_cb.WH = WH;
|
|
|
|
ps_cb.HalfTexel = GSVector4(-0.5f, 0.5f).xxyy() / WH.zwzw();
|
|
|
|
ps_cb.MskFix = GSVector4i(context->CLAMP.MINU, context->CLAMP.MINV, context->CLAMP.MAXU, context->CLAMP.MAXV);
|
|
|
|
|
2013-02-23 15:35:56 +00:00
|
|
|
// TC Offset Hack
|
|
|
|
ps_sel.tcoffsethack = !!UserHacks_TCOffset;
|
|
|
|
ps_cb.TC_OffsetHack = GSVector4(UserHacks_TCO_x, UserHacks_TCO_y).xyxy() / WH.xyxy();
|
|
|
|
|
2012-01-15 17:25:49 +00:00
|
|
|
GSVector4 clamp(ps_cb.MskFix);
|
|
|
|
GSVector4 ta(env.TEXA & GSVector4i::x000000ff());
|
|
|
|
|
|
|
|
ps_cb.MinMax = clamp / WH.xyxy();
|
|
|
|
ps_cb.MinF_TA = (clamp + 0.5f).xyxy(ta) / WH.xyxy(GSVector4(255, 255));
|
|
|
|
|
|
|
|
ps_ssel.tau = (context->CLAMP.WMS + 3) >> 1;
|
|
|
|
ps_ssel.tav = (context->CLAMP.WMT + 3) >> 1;
|
2012-08-15 10:14:13 +00:00
|
|
|
ps_ssel.ltf = bilinear && simple_sample;
|
2013-08-17 08:57:52 +00:00
|
|
|
|
|
|
|
// Setup Texture ressources
|
|
|
|
if (GLLoader::found_GL_ARB_bindless_texture) {
|
|
|
|
GLuint64 handle[2];
|
|
|
|
handle[0] = tex->m_texture ? static_cast<GSTextureOGL*>(tex->m_texture)->GetHandle(dev->GetSamplerID(ps_ssel)): 0;
|
|
|
|
handle[1] = tex->m_palette ? static_cast<GSTextureOGL*>(tex->m_palette)->GetHandle(dev->GetPaletteSamplerID()): 0;
|
|
|
|
|
|
|
|
dev->m_shader->PS_ressources(handle);
|
|
|
|
} else {
|
|
|
|
dev->SetupSampler(ps_ssel);
|
|
|
|
|
|
|
|
if (tex->m_palette) {
|
2015-04-24 17:34:17 +00:00
|
|
|
dev->PSSetShaderResources(tex->m_texture, tex->m_palette);
|
2013-08-17 08:57:52 +00:00
|
|
|
} else if (tex->m_texture) {
|
2015-04-24 17:34:17 +00:00
|
|
|
dev->PSSetShaderResource(0, tex->m_texture);
|
2013-08-17 08:57:52 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-08 08:57:21 +00:00
|
|
|
|
|
|
|
if (spritehack && (ps_sel.atst == 2)) {
|
|
|
|
ps_sel.atst = 1;
|
|
|
|
}
|
2015-05-23 10:23:05 +00:00
|
|
|
} else {
|
|
|
|
#ifdef ENABLE_OGL_DEBUG
|
|
|
|
// Unattach texture to avoid noise in debugger
|
|
|
|
dev->PSSetShaderResource(0, NULL);
|
2015-05-24 14:50:01 +00:00
|
|
|
dev->PSSetShaderResource(1, NULL);
|
2015-05-23 10:23:05 +00:00
|
|
|
#endif
|
2013-08-10 19:43:59 +00:00
|
|
|
}
|
|
|
|
|
2015-05-19 22:51:37 +00:00
|
|
|
// Compute the blending equation to detect special case
|
|
|
|
int blend_sel = ((om_bsel.a * 3 + om_bsel.b) * 3 + om_bsel.c) * 3 + om_bsel.d;
|
|
|
|
int bogus_blend = GSDeviceOGL::m_blendMapD3D9[blend_sel].bogus;
|
2015-06-03 07:56:07 +00:00
|
|
|
bool sw_blending = (m_accurate_blend && (bogus_blend & A_MAX)) || acc_colclip_wrap || (m_accurate_blend > 1);
|
2015-05-19 22:51:37 +00:00
|
|
|
|
2015-05-20 07:36:01 +00:00
|
|
|
if (sw_blending && om_bsel.abe) {
|
|
|
|
GL_INS("!!! SW blending effect used (0x%x from sel %d) !!!", bogus_blend, blend_sel);
|
2015-05-19 22:51:37 +00:00
|
|
|
|
|
|
|
// select a shader that support blending
|
|
|
|
ps_sel.blend = bogus_blend & 0xFF;
|
|
|
|
|
|
|
|
dev->PSSetShaderResource(3, rt);
|
|
|
|
|
|
|
|
// Require the fix alpha vlaue
|
2015-05-26 13:36:48 +00:00
|
|
|
if (ALPHA.C == 2) {
|
|
|
|
ps_cb.AlphaCoeff = GSVector4(afix);
|
2015-05-19 22:51:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// No need to flush for every primitive
|
|
|
|
require_barrier = !(bogus_blend & NO_BAR);
|
2015-05-20 07:36:01 +00:00
|
|
|
} else {
|
|
|
|
ps_sel.clr1 = om_bsel.IsCLR1();
|
2015-05-19 22:51:37 +00:00
|
|
|
}
|
|
|
|
|
2013-08-10 19:43:59 +00:00
|
|
|
// WARNING: setup of the program must be done first. So you can setup
|
|
|
|
// 1/ subroutine uniform
|
|
|
|
// 2/ bindless texture uniform
|
|
|
|
// 3/ others uniform?
|
|
|
|
dev->SetupVS(vs_sel);
|
2013-08-14 10:18:38 +00:00
|
|
|
dev->SetupGS(m_vt.m_primclass == GS_SPRITE_CLASS);
|
2013-08-10 19:43:59 +00:00
|
|
|
dev->SetupPS(ps_sel);
|
2013-07-19 19:25:50 +00:00
|
|
|
|
2012-01-15 17:25:49 +00:00
|
|
|
// rs
|
|
|
|
|
|
|
|
GSVector4i scissor = GSVector4i(GSVector4(rtscale).xyxy() * context->scissor.in).rintersect(GSVector4i(rtsize).zwxy());
|
|
|
|
|
2015-05-06 16:52:51 +00:00
|
|
|
GL_PUSH("IA");
|
2012-02-11 10:22:02 +00:00
|
|
|
SetupIA();
|
2015-05-06 16:52:51 +00:00
|
|
|
GL_POP();
|
2012-02-11 10:22:02 +00:00
|
|
|
|
2015-05-05 08:26:01 +00:00
|
|
|
dev->OMSetColorMaskState(om_csel);
|
2015-05-19 22:51:37 +00:00
|
|
|
dev->SetupOM(om_dssel, om_bsel, afix, sw_blending);
|
2015-05-09 13:02:13 +00:00
|
|
|
|
2015-05-06 06:44:27 +00:00
|
|
|
dev->SetupCB(&vs_cb, &ps_cb);
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2015-04-24 18:53:59 +00:00
|
|
|
if (DATE_GL42) {
|
2015-05-06 16:52:51 +00:00
|
|
|
GL_PUSH("Date GL42");
|
2015-05-19 22:12:52 +00:00
|
|
|
ASSERT((bogus_blend & A_MAX) == 0);
|
2015-05-06 06:34:45 +00:00
|
|
|
// It could be good idea to use stencil in the same time.
|
|
|
|
// Early stencil test will reduce the number of atomic-load operation
|
|
|
|
|
2013-08-28 08:44:16 +00:00
|
|
|
// Create an r32i image that will contain primitive ID
|
|
|
|
// Note: do it at the beginning because the clean will dirty the FBO state
|
2013-07-28 14:40:43 +00:00
|
|
|
//dev->InitPrimDateTexture(rtsize.x, rtsize.y);
|
|
|
|
|
2015-04-24 18:13:38 +00:00
|
|
|
// I don't know how much is it legal to mount rt as Texture/RT. No write is done.
|
|
|
|
// In doubt let's detach RT.
|
|
|
|
dev->OMSetRenderTargets(NULL, ds, &scissor);
|
|
|
|
|
2013-07-28 14:40:43 +00:00
|
|
|
// Don't write anything on the color buffer
|
|
|
|
dev->OMSetWriteBuffer(GL_NONE);
|
|
|
|
// Compute primitiveID max that pass the date test
|
2015-05-09 13:01:39 +00:00
|
|
|
SendDraw(false);
|
2013-07-28 14:40:43 +00:00
|
|
|
|
|
|
|
// Ask PS to discard shader above the primitiveID max
|
|
|
|
dev->OMSetWriteBuffer();
|
|
|
|
|
|
|
|
ps_sel.date = 3;
|
2013-08-10 19:43:59 +00:00
|
|
|
dev->SetupPS(ps_sel);
|
2013-07-28 14:40:43 +00:00
|
|
|
|
|
|
|
// Be sure that first pass is finished !
|
2014-02-08 11:05:26 +00:00
|
|
|
if (!UserHacks_DateGL4)
|
|
|
|
dev->Barrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
|
2015-05-06 16:52:51 +00:00
|
|
|
|
|
|
|
GL_POP();
|
2013-07-28 14:40:43 +00:00
|
|
|
}
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2015-04-24 18:13:38 +00:00
|
|
|
dev->OMSetRenderTargets(rt, ds, &scissor);
|
|
|
|
|
2015-05-19 22:51:37 +00:00
|
|
|
if (context->TEST.DoFirstPass())
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2015-05-09 13:01:39 +00:00
|
|
|
SendDraw(require_barrier);
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2015-05-17 11:00:28 +00:00
|
|
|
if (colclip_wrap)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2015-05-19 22:12:52 +00:00
|
|
|
ASSERT((bogus_blend & A_MAX) == 0);
|
2015-05-06 16:52:51 +00:00
|
|
|
GL_PUSH("COLCLIP");
|
2012-01-15 17:25:49 +00:00
|
|
|
GSDeviceOGL::OMBlendSelector om_bselneg(om_bsel);
|
|
|
|
GSDeviceOGL::PSSelector ps_selneg(ps_sel);
|
|
|
|
|
|
|
|
om_bselneg.negative = 1;
|
|
|
|
ps_selneg.colclip = 2;
|
|
|
|
|
|
|
|
dev->SetupOM(om_dssel, om_bselneg, afix);
|
2013-08-10 19:43:59 +00:00
|
|
|
dev->SetupPS(ps_selneg);
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2015-05-09 13:01:39 +00:00
|
|
|
SendDraw(false);
|
2012-08-15 10:14:13 +00:00
|
|
|
dev->SetupOM(om_dssel, om_bsel, afix);
|
2015-05-06 16:52:51 +00:00
|
|
|
GL_POP();
|
2012-01-15 17:25:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-19 22:51:37 +00:00
|
|
|
if (context->TEST.DoSecondPass())
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
|
|
|
ASSERT(!env.PABE.PABE);
|
|
|
|
|
|
|
|
static const uint32 iatst[] = {1, 0, 5, 6, 7, 2, 3, 4};
|
|
|
|
|
2015-05-08 08:57:21 +00:00
|
|
|
ps_sel.atst = iatst[atst];
|
|
|
|
if (spritehack && (ps_sel.atst == 2)) {
|
|
|
|
ps_sel.atst = 1;
|
|
|
|
}
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2013-08-10 19:43:59 +00:00
|
|
|
dev->SetupPS(ps_sel);
|
2012-01-15 17:25:49 +00:00
|
|
|
|
|
|
|
bool z = om_dssel.zwe;
|
2015-05-05 08:26:01 +00:00
|
|
|
bool r = om_csel.wr;
|
|
|
|
bool g = om_csel.wg;
|
|
|
|
bool b = om_csel.wb;
|
|
|
|
bool a = om_csel.wa;
|
2012-01-15 17:25:49 +00:00
|
|
|
|
|
|
|
switch(context->TEST.AFAIL)
|
|
|
|
{
|
2013-08-10 19:43:59 +00:00
|
|
|
case AFAIL_KEEP: z = r = g = b = a = false; break; // none
|
|
|
|
case AFAIL_FB_ONLY: z = false; break; // rgba
|
|
|
|
case AFAIL_ZB_ONLY: r = g = b = a = false; break; // z
|
|
|
|
case AFAIL_RGB_ONLY: z = a = false; break; // rgb
|
|
|
|
default: __assume(0);
|
2012-01-15 17:25:49 +00:00
|
|
|
}
|
|
|
|
|
2015-05-19 22:51:37 +00:00
|
|
|
if (z || r || g || b || a)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
|
|
|
om_dssel.zwe = z;
|
2015-05-05 08:26:01 +00:00
|
|
|
om_csel.wr = r;
|
|
|
|
om_csel.wg = g;
|
|
|
|
om_csel.wb = b;
|
|
|
|
om_csel.wa = a;
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2015-05-05 08:26:01 +00:00
|
|
|
dev->OMSetColorMaskState(om_csel);
|
2012-01-15 17:25:49 +00:00
|
|
|
dev->SetupOM(om_dssel, om_bsel, afix);
|
|
|
|
|
2015-05-09 13:01:39 +00:00
|
|
|
SendDraw(require_barrier);
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2015-05-17 11:00:28 +00:00
|
|
|
if (colclip_wrap)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2015-05-19 22:12:52 +00:00
|
|
|
ASSERT((bogus_blend & A_MAX) == 0);
|
2015-05-06 16:52:51 +00:00
|
|
|
GL_PUSH("COLCLIP");
|
2012-01-15 17:25:49 +00:00
|
|
|
GSDeviceOGL::OMBlendSelector om_bselneg(om_bsel);
|
|
|
|
GSDeviceOGL::PSSelector ps_selneg(ps_sel);
|
|
|
|
|
|
|
|
om_bselneg.negative = 1;
|
|
|
|
ps_selneg.colclip = 2;
|
|
|
|
|
|
|
|
dev->SetupOM(om_dssel, om_bselneg, afix);
|
2013-08-10 19:43:59 +00:00
|
|
|
dev->SetupPS(ps_selneg);
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2015-05-09 13:01:39 +00:00
|
|
|
SendDraw(false);
|
2015-05-06 16:52:51 +00:00
|
|
|
GL_POP();
|
2012-01-15 17:25:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-24 18:53:59 +00:00
|
|
|
if (DATE_GL42)
|
2013-07-28 14:40:43 +00:00
|
|
|
dev->RecycleDateTexture();
|
2012-01-15 17:25:49 +00:00
|
|
|
|
|
|
|
dev->EndScene();
|
|
|
|
|
2015-05-06 16:52:51 +00:00
|
|
|
GL_POP();
|
2012-01-15 17:25:49 +00:00
|
|
|
}
|