2011-11-16 22:17:37 +00:00
|
|
|
/*
|
2016-04-24 08:53:12 +00:00
|
|
|
* Copyright (C) 2011-2016 Gregory hainaut
|
2011-11-16 22:17:37 +00:00
|
|
|
* 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"
|
2016-10-04 17:23:27 +00:00
|
|
|
#include "GSState.h"
|
2011-11-16 22:17:37 +00:00
|
|
|
#include "GSDeviceOGL.h"
|
2013-08-05 20:25:25 +00:00
|
|
|
#include "GLState.h"
|
2016-06-10 20:01:48 +00:00
|
|
|
#include "GSUtil.h"
|
2014-11-09 14:27:24 +00:00
|
|
|
#include <fstream>
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2013-07-07 16:13:11 +00:00
|
|
|
#include "res/glsl_source.h"
|
2013-05-18 09:17:30 +00:00
|
|
|
|
2012-01-04 23:19:17 +00:00
|
|
|
//#define ONLY_LINES
|
2011-12-29 14:24:26 +00:00
|
|
|
|
2015-05-01 18:04:23 +00:00
|
|
|
// TODO port those value into PerfMon API
|
2014-03-24 14:03:02 +00:00
|
|
|
#ifdef ENABLE_OGL_DEBUG_MEM_BW
|
2015-04-25 12:18:21 +00:00
|
|
|
uint64 g_real_texture_upload_byte = 0;
|
|
|
|
uint64 g_vertex_upload_byte = 0;
|
|
|
|
uint64 g_uniform_upload_byte = 0;
|
2014-03-24 14:03:02 +00:00
|
|
|
#endif
|
2011-12-29 14:24:26 +00:00
|
|
|
|
2013-04-19 19:16:26 +00:00
|
|
|
static const uint32 g_merge_cb_index = 10;
|
|
|
|
static const uint32 g_interlace_cb_index = 11;
|
2014-11-09 14:27:24 +00:00
|
|
|
static const uint32 g_fx_cb_index = 14;
|
2015-06-29 17:17:46 +00:00
|
|
|
static const uint32 g_convert_index = 15;
|
2016-04-24 08:53:12 +00:00
|
|
|
static const uint32 g_vs_cb_index = 20;
|
|
|
|
static const uint32 g_ps_cb_index = 21;
|
|
|
|
static const uint32 g_gs_cb_index = 22;
|
2011-12-29 14:24:26 +00:00
|
|
|
|
2016-06-10 20:01:48 +00:00
|
|
|
bool GSDeviceOGL::m_debug_gl_call = false;
|
|
|
|
int GSDeviceOGL::m_shader_inst = 0;
|
|
|
|
int GSDeviceOGL::m_shader_reg = 0;
|
2015-05-17 12:43:56 +00:00
|
|
|
FILE* GSDeviceOGL::m_debug_gl_file = NULL;
|
2015-05-07 21:20:01 +00:00
|
|
|
|
2011-11-16 22:17:37 +00:00
|
|
|
GSDeviceOGL::GSDeviceOGL()
|
2015-09-11 10:19:49 +00:00
|
|
|
: m_msaa(0)
|
2016-06-24 16:41:55 +00:00
|
|
|
, m_force_texture_clear(0)
|
2015-09-11 10:19:49 +00:00
|
|
|
, m_window(NULL)
|
|
|
|
, m_fbo(0)
|
|
|
|
, m_fbo_read(0)
|
|
|
|
, m_va(NULL)
|
|
|
|
, m_apitrace(0)
|
|
|
|
, m_palette_ss(0)
|
|
|
|
, m_vs_cb(NULL)
|
|
|
|
, m_ps_cb(NULL)
|
|
|
|
, m_shader(NULL)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2012-01-08 21:59:42 +00:00
|
|
|
memset(&m_merge_obj, 0, sizeof(m_merge_obj));
|
2011-11-21 22:36:03 +00:00
|
|
|
memset(&m_interlace, 0, sizeof(m_interlace));
|
|
|
|
memset(&m_convert, 0, sizeof(m_convert));
|
2014-11-09 14:27:24 +00:00
|
|
|
memset(&m_fxaa, 0, sizeof(m_fxaa));
|
|
|
|
memset(&m_shaderfx, 0, sizeof(m_shaderfx));
|
2011-11-21 22:36:03 +00:00
|
|
|
memset(&m_date, 0, sizeof(m_date));
|
2015-09-11 10:19:49 +00:00
|
|
|
memset(&m_shadeboost, 0, sizeof(m_shadeboost));
|
|
|
|
memset(&m_om_dss, 0, sizeof(m_om_dss));
|
2016-06-26 13:27:57 +00:00
|
|
|
memset(&m_profiler, 0 , sizeof(m_profiler));
|
2013-08-05 20:25:25 +00:00
|
|
|
GLState::Clear();
|
2012-01-31 17:08:05 +00:00
|
|
|
|
2016-09-30 18:04:24 +00:00
|
|
|
m_mipmap = theApp.GetConfigI("mipmap");
|
|
|
|
|
2012-01-31 17:08:05 +00:00
|
|
|
// Reset the debug file
|
2013-01-16 18:25:53 +00:00
|
|
|
#ifdef ENABLE_OGL_DEBUG
|
2015-05-17 12:43:56 +00:00
|
|
|
m_debug_gl_file = fopen("GSdx_opengl_debug.txt","w");
|
2012-05-11 20:52:50 +00:00
|
|
|
#endif
|
2015-05-07 21:20:01 +00:00
|
|
|
|
2016-05-24 19:52:06 +00:00
|
|
|
m_debug_gl_call = theApp.GetConfigB("debug_opengl");
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
2011-11-21 22:36:03 +00:00
|
|
|
GSDeviceOGL::~GSDeviceOGL()
|
|
|
|
{
|
2015-05-17 12:43:56 +00:00
|
|
|
if (m_debug_gl_file) {
|
|
|
|
fclose(m_debug_gl_file);
|
|
|
|
m_debug_gl_file = NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-06 10:08:52 +00:00
|
|
|
// If the create function wasn't called nothing to do.
|
|
|
|
if (m_shader == NULL)
|
|
|
|
return;
|
|
|
|
|
2015-05-15 13:12:49 +00:00
|
|
|
GL_PUSH("GSDeviceOGL destructor");
|
|
|
|
|
2011-12-15 18:27:58 +00:00
|
|
|
// Clean vertex buffer state
|
2016-04-24 09:08:14 +00:00
|
|
|
delete m_va;
|
2011-12-15 18:27:58 +00:00
|
|
|
|
2012-01-08 21:59:42 +00:00
|
|
|
// Clean m_merge_obj
|
2016-04-24 09:08:14 +00:00
|
|
|
delete m_merge_obj.cb;
|
2013-07-06 10:08:52 +00:00
|
|
|
|
2011-11-26 11:46:51 +00:00
|
|
|
// Clean m_interlace
|
2016-04-24 09:08:14 +00:00
|
|
|
delete m_interlace.cb;
|
2011-11-26 11:46:51 +00:00
|
|
|
|
|
|
|
// Clean m_convert
|
|
|
|
delete m_convert.dss;
|
2015-06-05 21:26:03 +00:00
|
|
|
delete m_convert.dss_write;
|
2015-06-29 17:17:46 +00:00
|
|
|
delete m_convert.cb;
|
2011-11-26 11:46:51 +00:00
|
|
|
|
2013-06-14 21:22:44 +00:00
|
|
|
// Clean m_fxaa
|
|
|
|
delete m_fxaa.cb;
|
|
|
|
|
2014-11-09 14:27:24 +00:00
|
|
|
// Clean m_shaderfx
|
|
|
|
delete m_shaderfx.cb;
|
|
|
|
|
2011-11-26 11:46:51 +00:00
|
|
|
// Clean m_date
|
|
|
|
delete m_date.dss;
|
|
|
|
|
|
|
|
// Clean various opengl allocation
|
2015-10-17 15:05:15 +00:00
|
|
|
glDeleteFramebuffers(1, &m_fbo);
|
|
|
|
glDeleteFramebuffers(1, &m_fbo_read);
|
2011-12-21 19:08:31 +00:00
|
|
|
|
|
|
|
// Delete HW FX
|
|
|
|
delete m_vs_cb;
|
|
|
|
delete m_ps_cb;
|
2015-10-17 15:05:15 +00:00
|
|
|
glDeleteSamplers(1, &m_palette_ss);
|
2013-06-30 11:18:46 +00:00
|
|
|
|
|
|
|
m_ps.clear();
|
2013-05-17 20:14:10 +00:00
|
|
|
|
2015-10-17 15:05:15 +00:00
|
|
|
glDeleteSamplers(countof(m_ps_ss), m_ps_ss);
|
2013-06-26 20:09:07 +00:00
|
|
|
|
2015-07-25 08:14:53 +00:00
|
|
|
for (uint32 key = 0; key < countof(m_om_dss); key++) delete m_om_dss[key];
|
2013-06-30 11:18:46 +00:00
|
|
|
|
2013-08-03 08:29:01 +00:00
|
|
|
PboPool::Destroy();
|
|
|
|
|
2013-07-07 16:13:11 +00:00
|
|
|
// Must be done after the destruction of all shader/program objects
|
|
|
|
delete m_shader;
|
|
|
|
m_shader = NULL;
|
2016-07-20 08:00:00 +00:00
|
|
|
|
|
|
|
// Purge any pending message to reduce noise in Valgrind (potential memory leak
|
|
|
|
// in Mesa driver that doesn't free internal buffer when the context is destroyed)
|
|
|
|
CheckDebugLog();
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2016-06-26 13:27:57 +00:00
|
|
|
void GSDeviceOGL::GenerateProfilerData()
|
|
|
|
{
|
2016-07-03 13:54:58 +00:00
|
|
|
if (m_profiler.last_query < 3) {
|
|
|
|
glDeleteQueries(1 << 16, m_profiler.timer_query);
|
|
|
|
return;
|
|
|
|
}
|
2016-06-26 13:27:57 +00:00
|
|
|
|
|
|
|
// Wait latest quey to get valid result
|
|
|
|
GLuint available = 0;
|
|
|
|
while (!available) {
|
|
|
|
glGetQueryObjectuiv(m_profiler.timer(), GL_QUERY_RESULT_AVAILABLE, &available);
|
|
|
|
}
|
|
|
|
|
2016-06-26 16:27:50 +00:00
|
|
|
GLuint64 time_start;
|
|
|
|
GLuint64 time_end;
|
2016-06-26 15:53:22 +00:00
|
|
|
std::vector<double> times;
|
|
|
|
double ms = 0.000001;
|
2016-06-26 13:27:57 +00:00
|
|
|
|
2016-07-03 13:54:58 +00:00
|
|
|
int replay = theApp.GetConfigI("linux_replay");
|
|
|
|
int first_query = replay > 1 ? m_profiler.last_query / replay : 0;
|
2016-06-26 13:27:57 +00:00
|
|
|
|
2016-06-26 15:53:22 +00:00
|
|
|
glGetQueryObjectui64v(m_profiler.timer_query[first_query], GL_QUERY_RESULT, &time_start);
|
|
|
|
for (uint32 q = first_query + 1; q < m_profiler.last_query; q++) {
|
2016-06-26 13:27:57 +00:00
|
|
|
glGetQueryObjectui64v(m_profiler.timer_query[q], GL_QUERY_RESULT, &time_end);
|
|
|
|
uint64 t = time_end - time_start;
|
2016-06-26 15:53:22 +00:00
|
|
|
times.push_back((double)t * ms);
|
2016-06-26 13:27:57 +00:00
|
|
|
|
|
|
|
time_start = time_end;
|
|
|
|
}
|
|
|
|
|
2016-07-09 08:03:21 +00:00
|
|
|
// Latest value is often silly, just drop it
|
|
|
|
times.pop_back();
|
|
|
|
|
2016-06-26 13:27:57 +00:00
|
|
|
glDeleteQueries(1 << 16, m_profiler.timer_query);
|
|
|
|
|
2016-06-26 15:53:22 +00:00
|
|
|
double frames = times.size();
|
|
|
|
double mean = 0.0;
|
|
|
|
double sd = 0.0;
|
|
|
|
|
|
|
|
auto minmax_time = std::minmax_element(times.begin(), times.end());
|
|
|
|
|
|
|
|
for (auto t : times) mean += t;
|
|
|
|
mean = mean / frames;
|
|
|
|
|
|
|
|
for (auto t : times) sd += pow(t-mean, 2);
|
|
|
|
sd = sqrt(sd / frames);
|
2016-06-26 13:27:57 +00:00
|
|
|
|
2016-09-05 18:25:55 +00:00
|
|
|
uint32 time_repartition[16] = {0};
|
|
|
|
for (auto t : times) {
|
|
|
|
uint32 slot = (uint32)(t/2.0);
|
|
|
|
if (slot >= countof(time_repartition)) {
|
|
|
|
slot = countof(time_repartition) - 1;
|
|
|
|
}
|
|
|
|
time_repartition[slot]++;
|
|
|
|
}
|
|
|
|
|
2016-06-26 15:53:22 +00:00
|
|
|
fprintf(stderr, "\nPerformance Profile for %.0f frames:\n", frames);
|
|
|
|
fprintf(stderr, "Min %4.2f ms\t(%4.2f fps)\n", *minmax_time.first, 1000.0 / *minmax_time.first);
|
|
|
|
fprintf(stderr, "Mean %4.2f ms\t(%4.2f fps)\n", mean, 1000.0 / mean);
|
|
|
|
fprintf(stderr, "Max %4.2f ms\t(%4.2f fps)\n", *minmax_time.second, 1000.0 / *minmax_time.second);
|
2016-06-26 16:27:50 +00:00
|
|
|
fprintf(stderr, "SD %4.2f ms\n", sd);
|
2016-06-26 15:53:22 +00:00
|
|
|
fprintf(stderr, "\n");
|
2016-09-05 18:25:55 +00:00
|
|
|
fprintf(stderr, "Frame Repartition\n");
|
|
|
|
for (uint32 i = 0; i < countof(time_repartition); i ++) {
|
|
|
|
fprintf(stderr, "%3u ms => %3u ms\t%4u\n", 2 * i, 2 * (i+1), time_repartition[i]);
|
|
|
|
}
|
2016-07-08 19:47:53 +00:00
|
|
|
|
|
|
|
FILE* csv = fopen("GSdx_profile.csv", "w");
|
|
|
|
if (csv) {
|
|
|
|
for (size_t i = 0; i < times.size(); i++) {
|
2016-08-13 10:40:30 +00:00
|
|
|
fprintf(csv, "%zu,%lf\n", i, times[i]);
|
2016-07-08 19:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(csv);
|
|
|
|
}
|
2016-06-26 13:27:57 +00:00
|
|
|
}
|
|
|
|
|
2015-05-16 17:28:22 +00:00
|
|
|
GSTexture* GSDeviceOGL::CreateSurface(int type, int w, int h, bool msaa, int fmt)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2015-05-08 13:51:46 +00:00
|
|
|
GL_PUSH("Create surface");
|
|
|
|
|
2011-11-16 22:17:37 +00:00
|
|
|
// A wrapper to call GSTextureOGL, with the different kind of parameter
|
2011-11-21 22:36:03 +00:00
|
|
|
GSTextureOGL* t = NULL;
|
2016-09-30 18:04:24 +00:00
|
|
|
t = new GSTextureOGL(type, w, h, fmt, m_fbo_read, m_mipmap > 1);
|
2016-05-05 16:01:44 +00:00
|
|
|
if (t == NULL) {
|
|
|
|
throw GSDXErrorOOM();
|
|
|
|
}
|
2011-11-21 22:36:03 +00:00
|
|
|
|
2015-05-01 18:04:23 +00:00
|
|
|
// NOTE: I'm not sure RenderTarget always need to be cleared. It could be costly for big upscale.
|
2016-06-24 16:41:55 +00:00
|
|
|
// FIXME: it will be more logical to do it in FetchSurface. This code is only called at first creation
|
|
|
|
// of the texture. However we could reuse a deleted texture.
|
|
|
|
if (m_force_texture_clear == 0) {
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case GSTexture::RenderTarget:
|
|
|
|
ClearRenderTarget(t, 0);
|
|
|
|
break;
|
|
|
|
case GSTexture::DepthStencil:
|
2016-07-27 21:22:46 +00:00
|
|
|
ClearDepth(t);
|
2016-06-24 16:41:55 +00:00
|
|
|
// No need to clear the stencil now.
|
|
|
|
break;
|
|
|
|
}
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
2015-05-08 13:51:46 +00:00
|
|
|
|
2011-11-21 22:36:03 +00:00
|
|
|
return t;
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GSTexture* GSDeviceOGL::FetchSurface(int type, int w, int h, bool msaa, int format)
|
|
|
|
{
|
2016-06-24 16:41:55 +00:00
|
|
|
GSTexture* t = GSDevice::FetchSurface(type, w, h, false, format);
|
|
|
|
|
|
|
|
|
|
|
|
if (m_force_texture_clear) {
|
|
|
|
GSVector4 red(1.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case GSTexture::RenderTarget:
|
|
|
|
ClearRenderTarget(t, 0);
|
|
|
|
break;
|
|
|
|
case GSTexture::DepthStencil:
|
2016-07-27 21:22:46 +00:00
|
|
|
ClearDepth(t);
|
2016-06-24 16:41:55 +00:00
|
|
|
// No need to clear the stencil now.
|
|
|
|
break;
|
|
|
|
case GSTexture::Texture:
|
|
|
|
if (m_force_texture_clear > 1)
|
|
|
|
static_cast<GSTextureOGL*>(t)->Clear((void*)&red);
|
|
|
|
else if (m_force_texture_clear)
|
|
|
|
static_cast<GSTextureOGL*>(t)->Clear(NULL);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return t;
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GSDeviceOGL::Create(GSWnd* wnd)
|
|
|
|
{
|
2011-11-21 22:36:03 +00:00
|
|
|
if (m_window == NULL) {
|
2014-09-30 20:04:42 +00:00
|
|
|
if (!GLLoader::check_gl_version(3, 3)) return false;
|
2011-12-21 23:09:36 +00:00
|
|
|
|
2013-01-14 09:15:39 +00:00
|
|
|
if (!GLLoader::check_gl_supported_extension()) return false;
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
|
|
|
|
2011-12-08 16:39:14 +00:00
|
|
|
m_window = wnd;
|
2011-11-26 11:46:51 +00:00
|
|
|
|
2014-09-27 16:57:17 +00:00
|
|
|
// ****************************************************************
|
|
|
|
// Debug helper
|
|
|
|
// ****************************************************************
|
|
|
|
#ifdef ENABLE_OGL_DEBUG
|
2016-05-24 19:52:06 +00:00
|
|
|
if (theApp.GetConfigB("debug_opengl")) {
|
2016-04-19 21:03:42 +00:00
|
|
|
glDebugMessageCallback((GLDEBUGPROC)DebugOutputToFile, NULL);
|
|
|
|
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
|
|
|
|
|
|
|
|
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, true);
|
|
|
|
// Useless info message on Nvidia driver
|
|
|
|
GLuint ids[] = {0x20004};
|
|
|
|
glDebugMessageControl(GL_DEBUG_SOURCE_API_ARB, GL_DEBUG_TYPE_OTHER_ARB, GL_DONT_CARE, countof(ids), ids, false);
|
2015-05-07 21:20:01 +00:00
|
|
|
}
|
2014-09-27 16:57:17 +00:00
|
|
|
#endif
|
|
|
|
|
2016-06-24 16:41:55 +00:00
|
|
|
m_force_texture_clear = theApp.GetConfigI("force_texture_clear");
|
|
|
|
|
2015-10-24 12:05:00 +00:00
|
|
|
// WARNING it must be done after the control setup (at least on MESA)
|
|
|
|
GL_PUSH("GSDeviceOGL::Create");
|
|
|
|
|
2011-11-21 22:36:03 +00:00
|
|
|
// ****************************************************************
|
|
|
|
// Various object
|
|
|
|
// ****************************************************************
|
2016-05-05 15:42:22 +00:00
|
|
|
{
|
|
|
|
GL_PUSH("GSDeviceOGL::Various");
|
2015-10-24 12:09:21 +00:00
|
|
|
|
2016-05-24 19:52:06 +00:00
|
|
|
m_shader = new GSShaderOGL(theApp.GetConfigB("debug_glsl_shader"));
|
2011-11-21 22:36:03 +00:00
|
|
|
|
2016-05-05 15:42:22 +00:00
|
|
|
glGenFramebuffers(1, &m_fbo);
|
|
|
|
// Always write to the first buffer
|
|
|
|
OMSetFBO(m_fbo);
|
|
|
|
GLenum target[1] = {GL_COLOR_ATTACHMENT0};
|
|
|
|
glDrawBuffers(1, target);
|
|
|
|
OMSetFBO(0);
|
2011-12-10 19:19:44 +00:00
|
|
|
|
2016-05-05 15:42:22 +00:00
|
|
|
glGenFramebuffers(1, &m_fbo_read);
|
|
|
|
// Always read from the first buffer
|
|
|
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo_read);
|
|
|
|
glReadBuffer(GL_COLOR_ATTACHMENT0);
|
|
|
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
2016-06-26 13:27:57 +00:00
|
|
|
|
|
|
|
// Some timers to help profiling
|
|
|
|
if (GLLoader::in_replayer) {
|
|
|
|
glCreateQueries(GL_TIMESTAMP, 1 << 16, m_profiler.timer_query);
|
|
|
|
}
|
2016-05-05 15:42:22 +00:00
|
|
|
}
|
2015-10-24 12:09:21 +00:00
|
|
|
|
2011-11-21 22:36:03 +00:00
|
|
|
// ****************************************************************
|
2011-12-15 18:27:58 +00:00
|
|
|
// Vertex buffer state
|
2011-11-21 22:36:03 +00:00
|
|
|
// ****************************************************************
|
|
|
|
{
|
2016-05-05 15:42:22 +00:00
|
|
|
GL_PUSH("GSDeviceOGL::Vertex Buffer");
|
|
|
|
|
2016-08-21 13:22:09 +00:00
|
|
|
static_assert(sizeof(GSVertexPT1) == sizeof(GSVertex), "wrong GSVertex size");
|
2016-05-05 15:42:22 +00:00
|
|
|
GSInputLayoutOGL il_convert[] =
|
|
|
|
{
|
|
|
|
{2 , GL_FLOAT , GL_FALSE , sizeof(GSVertexPT1) , (const GLvoid*)(0) } ,
|
|
|
|
{2 , GL_FLOAT , GL_FALSE , sizeof(GSVertexPT1) , (const GLvoid*)(16) } ,
|
|
|
|
{4 , GL_UNSIGNED_BYTE , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(8) } ,
|
|
|
|
{1 , GL_FLOAT , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(12) } ,
|
|
|
|
{2 , GL_UNSIGNED_SHORT , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(16) } ,
|
|
|
|
{1 , GL_UNSIGNED_INT , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(20) } ,
|
|
|
|
{2 , GL_UNSIGNED_SHORT , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(24) } ,
|
|
|
|
{4 , GL_UNSIGNED_BYTE , GL_TRUE , sizeof(GSVertex) , (const GLvoid*)(28) } , // Only 1 byte is useful but hardware unit only support 4B
|
|
|
|
};
|
|
|
|
m_va = new GSVertexBufferStateOGL(il_convert, countof(il_convert));
|
|
|
|
}
|
2011-11-21 22:36:03 +00:00
|
|
|
|
2013-08-17 08:57:52 +00:00
|
|
|
// ****************************************************************
|
|
|
|
// Pre Generate the different sampler object
|
|
|
|
// ****************************************************************
|
2016-05-05 15:42:22 +00:00
|
|
|
{
|
|
|
|
GL_PUSH("GSDeviceOGL::Sampler");
|
2015-10-24 12:09:21 +00:00
|
|
|
|
2016-05-05 15:42:22 +00:00
|
|
|
for (uint32 key = 0; key < countof(m_ps_ss); key++) {
|
|
|
|
m_ps_ss[key] = CreateSampler(PSSamplerSelector(key));
|
|
|
|
}
|
2015-07-25 08:14:53 +00:00
|
|
|
}
|
2013-08-02 16:38:12 +00:00
|
|
|
|
2011-12-15 18:27:58 +00:00
|
|
|
// ****************************************************************
|
|
|
|
// convert
|
|
|
|
// ****************************************************************
|
2016-05-05 15:42:22 +00:00
|
|
|
GLuint vs = 0;
|
2016-04-10 15:28:05 +00:00
|
|
|
GLuint ps = 0;
|
2016-05-05 15:42:22 +00:00
|
|
|
{
|
|
|
|
GL_PUSH("GSDeviceOGL::Convert");
|
2016-04-10 15:28:05 +00:00
|
|
|
|
2016-06-07 18:30:56 +00:00
|
|
|
m_convert.cb = new GSUniformBufferOGL("Misc UBO", g_convert_index, sizeof(MiscConstantBuffer));
|
2016-05-05 15:42:22 +00:00
|
|
|
// Upload once and forget about it
|
2016-05-29 08:03:26 +00:00
|
|
|
m_misc_cb_cache.ScalingFactor = GSVector4i(theApp.GetConfigI("upscale_multiplier"));
|
|
|
|
m_convert.cb->cache_upload(&m_misc_cb_cache);
|
2011-11-21 22:36:03 +00:00
|
|
|
|
2016-05-05 15:42:22 +00:00
|
|
|
vs = m_shader->Compile("convert.glsl", "vs_main", GL_VERTEX_SHADER, convert_glsl);
|
2013-08-17 08:57:52 +00:00
|
|
|
|
2016-05-05 15:42:22 +00:00
|
|
|
m_convert.vs = vs;
|
|
|
|
for(size_t i = 0; i < countof(m_convert.ps); i++) {
|
|
|
|
ps = m_shader->Compile("convert.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, convert_glsl);
|
2016-06-07 18:30:56 +00:00
|
|
|
string pretty_name = "Convert pipe " + to_string(i);
|
|
|
|
m_convert.ps[i] = m_shader->LinkPipeline(pretty_name, vs, 0, ps);
|
2016-05-05 15:42:22 +00:00
|
|
|
}
|
2011-11-21 22:36:03 +00:00
|
|
|
|
2016-05-05 15:42:22 +00:00
|
|
|
PSSamplerSelector point;
|
|
|
|
m_convert.pt = GetSamplerID(point);
|
2011-11-26 11:46:51 +00:00
|
|
|
|
2016-05-05 15:42:22 +00:00
|
|
|
PSSamplerSelector bilinear;
|
|
|
|
bilinear.ltf = true;
|
|
|
|
m_convert.ln = GetSamplerID(bilinear);
|
|
|
|
|
|
|
|
m_convert.dss = new GSDepthStencilOGL();
|
|
|
|
m_convert.dss_write = new GSDepthStencilOGL();
|
|
|
|
m_convert.dss_write->EnableDepth();
|
|
|
|
m_convert.dss_write->SetDepth(GL_ALWAYS, true);
|
|
|
|
}
|
2015-10-24 12:09:21 +00:00
|
|
|
|
2011-11-21 22:36:03 +00:00
|
|
|
// ****************************************************************
|
|
|
|
// merge
|
|
|
|
// ****************************************************************
|
2016-05-05 15:42:22 +00:00
|
|
|
{
|
|
|
|
GL_PUSH("GSDeviceOGL::Merge");
|
2015-10-24 12:09:21 +00:00
|
|
|
|
2016-06-07 18:30:56 +00:00
|
|
|
m_merge_obj.cb = new GSUniformBufferOGL("Merge UBO", g_merge_cb_index, sizeof(MergeConstantBuffer));
|
2011-11-21 22:36:03 +00:00
|
|
|
|
2016-05-05 15:42:22 +00:00
|
|
|
for(size_t i = 0; i < countof(m_merge_obj.ps); i++) {
|
|
|
|
ps = m_shader->Compile("merge.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, merge_glsl);
|
2016-06-07 18:30:56 +00:00
|
|
|
string pretty_name = "Merge pipe " + to_string(i);
|
|
|
|
m_merge_obj.ps[i] = m_shader->LinkPipeline(pretty_name, vs, 0, ps);
|
2016-05-05 15:42:22 +00:00
|
|
|
}
|
2016-04-10 15:28:05 +00:00
|
|
|
}
|
2011-11-21 22:36:03 +00:00
|
|
|
|
|
|
|
// ****************************************************************
|
|
|
|
// interlace
|
|
|
|
// ****************************************************************
|
2016-05-05 15:42:22 +00:00
|
|
|
{
|
|
|
|
GL_PUSH("GSDeviceOGL::Interlace");
|
2015-10-24 12:09:21 +00:00
|
|
|
|
2016-06-07 18:30:56 +00:00
|
|
|
m_interlace.cb = new GSUniformBufferOGL("Interlace UBO", g_interlace_cb_index, sizeof(InterlaceConstantBuffer));
|
2011-11-21 22:36:03 +00:00
|
|
|
|
2016-05-05 15:42:22 +00:00
|
|
|
for(size_t i = 0; i < countof(m_interlace.ps); i++) {
|
|
|
|
ps = m_shader->Compile("interlace.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, interlace_glsl);
|
2016-06-07 18:30:56 +00:00
|
|
|
string pretty_name = "Interlace pipe " + to_string(i);
|
|
|
|
m_interlace.ps[i] = m_shader->LinkPipeline(pretty_name, vs, 0, ps);
|
2016-05-05 15:42:22 +00:00
|
|
|
}
|
2016-04-10 15:28:05 +00:00
|
|
|
}
|
2015-10-24 12:09:21 +00:00
|
|
|
|
2012-04-26 21:42:16 +00:00
|
|
|
// ****************************************************************
|
|
|
|
// Shade boost
|
|
|
|
// ****************************************************************
|
2016-05-05 15:42:22 +00:00
|
|
|
{
|
|
|
|
GL_PUSH("GSDeviceOGL::Shadeboost");
|
2012-04-26 21:42:16 +00:00
|
|
|
|
2016-05-24 19:52:06 +00:00
|
|
|
int ShadeBoost_Contrast = theApp.GetConfigI("ShadeBoost_Contrast");
|
|
|
|
int ShadeBoost_Brightness = theApp.GetConfigI("ShadeBoost_Brightness");
|
|
|
|
int ShadeBoost_Saturation = theApp.GetConfigI("ShadeBoost_Saturation");
|
2016-05-05 15:42:22 +00:00
|
|
|
std::string shade_macro = format("#define SB_SATURATION %d.0\n", ShadeBoost_Saturation)
|
|
|
|
+ format("#define SB_BRIGHTNESS %d.0\n", ShadeBoost_Brightness)
|
|
|
|
+ format("#define SB_CONTRAST %d.0\n", ShadeBoost_Contrast);
|
2011-11-21 22:36:03 +00:00
|
|
|
|
2016-05-05 15:42:22 +00:00
|
|
|
ps = m_shader->Compile("shadeboost.glsl", "ps_main", GL_FRAGMENT_SHADER, shadeboost_glsl, shade_macro);
|
2016-06-07 18:30:56 +00:00
|
|
|
m_shadeboost.ps = m_shader->LinkPipeline("ShadeBoost pipe", vs, 0, ps);
|
2016-05-05 15:42:22 +00:00
|
|
|
}
|
2015-10-24 12:09:21 +00:00
|
|
|
|
2011-11-21 22:36:03 +00:00
|
|
|
// ****************************************************************
|
|
|
|
// rasterization configuration
|
|
|
|
// ****************************************************************
|
2016-05-05 15:42:22 +00:00
|
|
|
{
|
|
|
|
GL_PUSH("GSDeviceOGL::Rasterization");
|
2015-10-24 12:09:21 +00:00
|
|
|
|
2012-01-04 23:19:17 +00:00
|
|
|
#ifdef ONLY_LINES
|
2016-05-05 15:42:22 +00:00
|
|
|
glLineWidth(5.0);
|
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
2015-05-01 18:04:23 +00:00
|
|
|
#else
|
2016-05-05 15:42:22 +00:00
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
2012-01-04 23:19:17 +00:00
|
|
|
#endif
|
2016-05-05 15:42:22 +00:00
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
glDisable(GL_MULTISAMPLE);
|
|
|
|
glDisable(GL_DITHER); // Honestly I don't know!
|
|
|
|
}
|
2015-10-24 12:09:21 +00:00
|
|
|
|
2011-12-21 19:08:31 +00:00
|
|
|
// ****************************************************************
|
2013-06-14 11:34:44 +00:00
|
|
|
// DATE
|
2011-12-21 19:08:31 +00:00
|
|
|
// ****************************************************************
|
2016-05-05 15:42:22 +00:00
|
|
|
{
|
|
|
|
GL_PUSH("GSDeviceOGL::Date");
|
2011-12-21 19:08:31 +00:00
|
|
|
|
2016-05-05 15:42:22 +00:00
|
|
|
m_date.dss = new GSDepthStencilOGL();
|
|
|
|
m_date.dss->EnableStencil();
|
|
|
|
m_date.dss->SetStencil(GL_ALWAYS, GL_REPLACE);
|
|
|
|
}
|
2016-04-11 10:20:07 +00:00
|
|
|
|
2014-09-27 17:39:17 +00:00
|
|
|
// ****************************************************************
|
|
|
|
// Use DX coordinate convention
|
|
|
|
// ****************************************************************
|
|
|
|
|
|
|
|
// VS gl_position.z => [-1,-1]
|
|
|
|
// FS depth => [0, 1]
|
|
|
|
// because of -1 we loose lot of precision for small GS value
|
|
|
|
// This extension allow FS depth to range from -1 to 1. So
|
|
|
|
// gl_position.z could range from [0, 1]
|
2016-04-07 19:57:54 +00:00
|
|
|
// Change depth convention
|
|
|
|
glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE);
|
2014-09-27 17:39:17 +00:00
|
|
|
|
2011-12-21 19:08:31 +00:00
|
|
|
// ****************************************************************
|
|
|
|
// HW renderer shader
|
|
|
|
// ****************************************************************
|
|
|
|
CreateTextureFX();
|
2011-11-26 11:46:51 +00:00
|
|
|
|
2013-08-03 08:29:01 +00:00
|
|
|
// ****************************************************************
|
|
|
|
// Pbo Pool allocation
|
|
|
|
// ****************************************************************
|
2016-05-05 15:42:22 +00:00
|
|
|
{
|
|
|
|
GL_PUSH("GSDeviceOGL::PBO");
|
2013-08-03 08:29:01 +00:00
|
|
|
|
2016-05-05 15:42:22 +00:00
|
|
|
// Mesa seems to use it to compute the row length. In our case, we are
|
|
|
|
// tightly packed so don't bother with this parameter and set it to the
|
|
|
|
// minimum alignment (1 byte)
|
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
2015-05-15 13:12:49 +00:00
|
|
|
|
2016-05-05 15:42:22 +00:00
|
|
|
PboPool::Init();
|
|
|
|
}
|
2015-10-24 12:09:21 +00:00
|
|
|
|
2016-07-07 20:02:10 +00:00
|
|
|
// ****************************************************************
|
|
|
|
// Get Available Memory
|
|
|
|
// ****************************************************************
|
|
|
|
GLint vram[4] = {0};
|
2016-07-08 19:53:42 +00:00
|
|
|
if (GLLoader::fglrx_buggy_driver) {
|
2016-07-09 09:43:28 +00:00
|
|
|
// Full vram, remove a small margin for others buffer
|
2016-07-07 20:02:10 +00:00
|
|
|
glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, vram);
|
2016-07-08 19:53:42 +00:00
|
|
|
} else if (GLLoader::found_GL_NVX_gpu_memory_info) {
|
2016-07-09 09:43:28 +00:00
|
|
|
// GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX <= give full memory
|
|
|
|
// Available vram
|
2016-07-08 19:53:42 +00:00
|
|
|
glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, vram);
|
2016-07-07 20:02:10 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stdout, "No extenstion supported to get available memory. Use default value !\n");
|
|
|
|
}
|
|
|
|
|
2016-07-10 08:23:23 +00:00
|
|
|
// When VRAM is at least 2GB, we set the limit to the default i.e. 3.8 GB
|
|
|
|
// When VRAM is below 2GB, we add a factor 2 because RAM can be used. Potentially
|
|
|
|
// low VRAM gpu can go higher but perf will be bad anyway.
|
|
|
|
if (vram[0] > 0 && vram[0] < 1800000)
|
|
|
|
GLState::available_vram = (int64)(vram[0]) * 1024ul * 2ul;
|
2016-07-07 20:02:10 +00:00
|
|
|
|
2016-07-10 08:23:23 +00:00
|
|
|
fprintf(stdout, "Available VRAM/RAM:%lldMB for textures\n", GLState::available_vram >> 20u);
|
2016-07-07 20:02:10 +00:00
|
|
|
|
2011-11-26 11:46:51 +00:00
|
|
|
// ****************************************************************
|
|
|
|
// Finish window setup and backbuffer
|
|
|
|
// ****************************************************************
|
|
|
|
if(!GSDevice::Create(wnd))
|
|
|
|
return false;
|
|
|
|
|
2011-11-21 22:36:03 +00:00
|
|
|
GSVector4i rect = wnd->GetClientRect();
|
|
|
|
Reset(rect.z, rect.w);
|
|
|
|
|
2015-05-07 16:32:58 +00:00
|
|
|
// Basic to ensure structures are correctly packed
|
2016-08-21 13:22:09 +00:00
|
|
|
static_assert(sizeof(VSSelector) == 4, "Wrong VSSelector size");
|
|
|
|
static_assert(sizeof(PSSelector) == 8, "Wrong PSSelector size");
|
|
|
|
static_assert(sizeof(PSSamplerSelector) == 4, "Wrong PSSamplerSelector size");
|
|
|
|
static_assert(sizeof(OMDepthStencilSelector) == 4, "Wrong OMDepthStencilSelector size");
|
|
|
|
static_assert(sizeof(OMColorMaskSelector) == 4, "Wrong OMColorMaskSelector size");
|
2015-05-07 16:32:58 +00:00
|
|
|
|
2011-12-21 19:08:31 +00:00
|
|
|
return true;
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
2016-04-24 08:53:12 +00:00
|
|
|
void GSDeviceOGL::CreateTextureFX()
|
|
|
|
{
|
2016-05-05 15:42:22 +00:00
|
|
|
GL_PUSH("GSDeviceOGL::CreateTextureFX");
|
|
|
|
|
2016-06-07 18:30:56 +00:00
|
|
|
m_vs_cb = new GSUniformBufferOGL("HW VS UBO", g_vs_cb_index, sizeof(VSConstantBuffer));
|
|
|
|
m_ps_cb = new GSUniformBufferOGL("HW PS UBO", g_ps_cb_index, sizeof(PSConstantBuffer));
|
2016-04-24 08:53:12 +00:00
|
|
|
|
|
|
|
// warning 1 sampler by image unit. So you cannot reuse m_ps_ss...
|
|
|
|
m_palette_ss = CreateSampler(false, false, false);
|
|
|
|
glBindSampler(1, m_palette_ss);
|
|
|
|
|
2016-06-01 07:14:06 +00:00
|
|
|
// Pre compile the (remaining) Geometry & Vertex Shader
|
2016-08-21 16:34:03 +00:00
|
|
|
// One-Hot encoding
|
|
|
|
memset(m_gs, 0, sizeof(m_gs));
|
|
|
|
m_gs[1] = CompileGS(GSSelector(1));
|
|
|
|
m_gs[2] = CompileGS(GSSelector(2));
|
|
|
|
m_gs[4] = CompileGS(GSSelector(4));
|
2016-04-24 08:53:12 +00:00
|
|
|
|
2016-06-01 07:14:06 +00:00
|
|
|
m_vs[0] = CompileVS(VSSelector(0));
|
2016-04-24 08:53:12 +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);
|
|
|
|
for (uint32 key = 0; key < countof(m_om_dss); key++) {
|
|
|
|
m_om_dss[key] = CreateDepthStencil(OMDepthStencilSelector(key));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Help to debug FS in apitrace
|
|
|
|
m_apitrace = CompilePS(PSSelector());
|
|
|
|
}
|
|
|
|
|
2011-11-16 22:17:37 +00:00
|
|
|
bool GSDeviceOGL::Reset(int w, int h)
|
|
|
|
{
|
2011-11-21 22:36:03 +00:00
|
|
|
if(!GSDevice::Reset(w, h))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Opengl allocate the backbuffer with the window. The render is done in the backbuffer when
|
2011-11-26 11:46:51 +00:00
|
|
|
// there isn't any FBO. Only a dummy texture is created to easily detect when the rendering is done
|
2011-11-21 22:36:03 +00:00
|
|
|
// in the backbuffer
|
2016-09-30 18:04:24 +00:00
|
|
|
m_backbuffer = new GSTextureOGL(GSTextureOGL::Backbuffer, w, h, 0, m_fbo_read, false);
|
2011-11-21 22:36:03 +00:00
|
|
|
|
|
|
|
return true;
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
void GSDeviceOGL::SetVSync(bool enable)
|
|
|
|
{
|
|
|
|
m_wnd->SetVSync(enable);
|
|
|
|
}
|
|
|
|
|
2011-11-21 22:36:03 +00:00
|
|
|
void GSDeviceOGL::Flip()
|
|
|
|
{
|
2013-01-16 18:25:53 +00:00
|
|
|
#ifdef ENABLE_OGL_DEBUG
|
2011-11-26 11:46:51 +00:00
|
|
|
CheckDebugLog();
|
2012-05-11 20:52:50 +00:00
|
|
|
#endif
|
2012-03-30 19:02:37 +00:00
|
|
|
|
2011-12-07 22:05:46 +00:00
|
|
|
m_wnd->Flip();
|
2016-06-26 13:27:57 +00:00
|
|
|
|
|
|
|
if (GLLoader::in_replayer) {
|
|
|
|
glQueryCounter(m_profiler.timer(), GL_TIMESTAMP);
|
|
|
|
m_profiler.last_query++;
|
|
|
|
}
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
|
|
|
|
2013-04-19 19:16:26 +00:00
|
|
|
void GSDeviceOGL::BeforeDraw()
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2013-04-19 19:16:26 +00:00
|
|
|
}
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2013-04-19 19:16:26 +00:00
|
|
|
void GSDeviceOGL::AfterDraw()
|
|
|
|
{
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
|
|
|
|
2013-04-19 19:16:26 +00:00
|
|
|
void GSDeviceOGL::DrawPrimitive()
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2013-04-19 19:16:26 +00:00
|
|
|
BeforeDraw();
|
2014-10-02 07:33:41 +00:00
|
|
|
m_va->DrawPrimitive();
|
2013-04-19 19:16:26 +00:00
|
|
|
AfterDraw();
|
|
|
|
}
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2015-08-01 11:33:30 +00:00
|
|
|
void GSDeviceOGL::DrawPrimitive(int offset, int count)
|
|
|
|
{
|
|
|
|
BeforeDraw();
|
|
|
|
m_va->DrawPrimitive(offset, count);
|
|
|
|
AfterDraw();
|
|
|
|
}
|
|
|
|
|
2013-04-19 19:16:26 +00:00
|
|
|
void GSDeviceOGL::DrawIndexedPrimitive()
|
|
|
|
{
|
|
|
|
BeforeDraw();
|
2014-10-02 07:33:41 +00:00
|
|
|
m_va->DrawIndexedPrimitive();
|
2013-04-19 19:16:26 +00:00
|
|
|
AfterDraw();
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
|
|
|
|
2012-02-11 10:22:02 +00:00
|
|
|
void GSDeviceOGL::DrawIndexedPrimitive(int offset, int count)
|
|
|
|
{
|
2015-05-25 15:31:27 +00:00
|
|
|
//ASSERT(offset + count <= (int)m_index.count);
|
2012-02-11 10:22:02 +00:00
|
|
|
|
2013-04-19 19:16:26 +00:00
|
|
|
BeforeDraw();
|
2014-10-02 07:33:41 +00:00
|
|
|
m_va->DrawIndexedPrimitive(offset, count);
|
2013-04-19 19:16:26 +00:00
|
|
|
AfterDraw();
|
2012-02-11 10:22:02 +00:00
|
|
|
}
|
|
|
|
|
2011-11-21 22:36:03 +00:00
|
|
|
void GSDeviceOGL::ClearRenderTarget(GSTexture* t, const GSVector4& c)
|
|
|
|
{
|
2015-08-04 17:26:17 +00:00
|
|
|
if (!t) return;
|
|
|
|
|
2015-05-12 16:18:04 +00:00
|
|
|
GSTextureOGL* T = static_cast<GSTextureOGL*>(t);
|
2015-05-15 13:24:43 +00:00
|
|
|
if (T->HasBeenCleaned() && !T->IsBackbuffer())
|
2015-05-12 16:18:04 +00:00
|
|
|
return;
|
|
|
|
|
2016-05-16 14:49:18 +00:00
|
|
|
// Performance note: potentially T->Clear() could be used. Main purpose of
|
|
|
|
// Clear() is to avoid the framebuffer setup cost. However, in this context,
|
|
|
|
// the texture 't' will be set as the render target of the framebuffer and
|
|
|
|
// therefore will require a framebuffer setup.
|
|
|
|
|
|
|
|
// So using the old/standard path is faster/better albeit verbose.
|
2016-05-16 08:38:47 +00:00
|
|
|
|
2015-05-16 17:28:22 +00:00
|
|
|
GL_PUSH("Clear RT %d", T->GetID());
|
2015-05-06 16:52:51 +00:00
|
|
|
|
2015-05-01 18:04:23 +00:00
|
|
|
// TODO: check size of scissor before toggling it
|
2015-04-24 16:15:58 +00:00
|
|
|
glDisable(GL_SCISSOR_TEST);
|
2015-05-15 10:52:03 +00:00
|
|
|
|
|
|
|
uint32 old_color_mask = GLState::wrgba;
|
|
|
|
OMSetColorMaskState();
|
|
|
|
|
2015-05-12 16:18:04 +00:00
|
|
|
if (T->IsBackbuffer()) {
|
2015-04-24 16:15:58 +00:00
|
|
|
OMSetFBO(0);
|
|
|
|
|
|
|
|
// glDrawBuffer(GL_BACK); // this is the default when there is no FB
|
|
|
|
// 0 will select the first drawbuffer ie GL_BACK
|
2015-10-17 15:05:15 +00:00
|
|
|
glClearBufferfv(GL_COLOR, 0, c.v);
|
2011-12-07 22:05:46 +00:00
|
|
|
} else {
|
2015-04-24 16:15:58 +00:00
|
|
|
OMSetFBO(m_fbo);
|
2015-05-12 16:18:04 +00:00
|
|
|
OMAttachRt(T);
|
2015-04-24 16:15:58 +00:00
|
|
|
|
2015-10-17 15:05:15 +00:00
|
|
|
glClearBufferfv(GL_COLOR, 0, c.v);
|
2015-05-15 13:24:43 +00:00
|
|
|
|
2011-12-07 22:05:46 +00:00
|
|
|
}
|
2015-05-15 10:52:03 +00:00
|
|
|
|
|
|
|
OMSetColorMaskState(OMColorMaskSelector(old_color_mask));
|
|
|
|
|
2015-04-24 16:15:58 +00:00
|
|
|
glEnable(GL_SCISSOR_TEST);
|
2015-05-06 16:52:51 +00:00
|
|
|
|
2015-05-15 13:24:43 +00:00
|
|
|
T->WasCleaned();
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2011-11-21 22:36:03 +00:00
|
|
|
void GSDeviceOGL::ClearRenderTarget(GSTexture* t, uint32 c)
|
|
|
|
{
|
2015-08-04 17:26:17 +00:00
|
|
|
if (!t) return;
|
|
|
|
|
2011-11-21 22:36:03 +00:00
|
|
|
GSVector4 color = GSVector4::rgba32(c) * (1.0f / 255);
|
2011-12-07 22:05:46 +00:00
|
|
|
ClearRenderTarget(t, color);
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
|
|
|
|
2015-05-02 14:53:34 +00:00
|
|
|
void GSDeviceOGL::ClearRenderTarget_i(GSTexture* t, int32 c)
|
2013-07-28 14:40:43 +00:00
|
|
|
{
|
2016-05-15 13:54:29 +00:00
|
|
|
// Hopefully AMD mesa will support this extension soon
|
|
|
|
ASSERT(!GLLoader::found_GL_ARB_clear_texture);
|
|
|
|
|
2015-08-04 17:26:17 +00:00
|
|
|
if (!t) return;
|
|
|
|
|
2015-05-12 16:18:04 +00:00
|
|
|
GSTextureOGL* T = static_cast<GSTextureOGL*>(t);
|
|
|
|
|
2015-05-16 17:28:22 +00:00
|
|
|
GL_PUSH("Clear RTi %d", T->GetID());
|
2015-05-06 16:52:51 +00:00
|
|
|
|
2015-05-15 10:52:03 +00:00
|
|
|
uint32 old_color_mask = GLState::wrgba;
|
|
|
|
OMSetColorMaskState();
|
|
|
|
|
2015-04-24 16:32:08 +00:00
|
|
|
// Keep SCISSOR_TEST enabled on purpose to reduce the size
|
|
|
|
// of clean in DATE (impact big upscaling)
|
2015-05-02 14:53:34 +00:00
|
|
|
int32 col[4] = {c, c, c, c};
|
2013-07-28 14:40:43 +00:00
|
|
|
|
2015-04-24 16:15:58 +00:00
|
|
|
OMSetFBO(m_fbo);
|
2015-05-12 16:18:04 +00:00
|
|
|
OMAttachRt(T);
|
2013-07-28 14:40:43 +00:00
|
|
|
|
2015-07-03 18:26:56 +00:00
|
|
|
// Blending is not supported when you render to an Integer texture
|
2015-07-31 18:28:54 +00:00
|
|
|
if (GLState::blend) {
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
2015-07-03 18:26:56 +00:00
|
|
|
|
2015-10-17 15:05:15 +00:00
|
|
|
glClearBufferiv(GL_COLOR, 0, col);
|
2015-05-06 16:52:51 +00:00
|
|
|
|
2015-05-15 10:52:03 +00:00
|
|
|
OMSetColorMaskState(OMColorMaskSelector(old_color_mask));
|
|
|
|
|
2015-07-31 18:28:54 +00:00
|
|
|
if (GLState::blend) {
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
}
|
2013-07-28 14:40:43 +00:00
|
|
|
}
|
|
|
|
|
2016-07-27 21:22:46 +00:00
|
|
|
void GSDeviceOGL::ClearDepth(GSTexture* t)
|
2011-11-21 22:36:03 +00:00
|
|
|
{
|
2015-08-04 17:26:17 +00:00
|
|
|
if (!t) return;
|
|
|
|
|
2015-05-12 16:18:04 +00:00
|
|
|
GSTextureOGL* T = static_cast<GSTextureOGL*>(t);
|
|
|
|
|
2015-05-16 17:28:22 +00:00
|
|
|
GL_PUSH("Clear Depth %d", T->GetID());
|
2015-05-06 16:52:51 +00:00
|
|
|
|
2016-06-27 16:03:35 +00:00
|
|
|
if (0 && GLLoader::found_GL_ARB_clear_texture) {
|
|
|
|
// I don't know what the driver does but it creates
|
|
|
|
// some slowdowns on Harry Potter PS
|
|
|
|
// Maybe it triggers some texture relocations, or maybe
|
|
|
|
// it clears also the stencil value (2 times slower)
|
|
|
|
//
|
|
|
|
// Let's disable this code for the moment.
|
|
|
|
|
2016-05-15 12:57:37 +00:00
|
|
|
// Don't bother with Depth_Stencil insanity
|
|
|
|
T->Clear(NULL);
|
2012-08-08 17:49:23 +00:00
|
|
|
} else {
|
2016-05-15 12:57:37 +00:00
|
|
|
OMSetFBO(m_fbo);
|
|
|
|
// RT must be detached, if RT is too small, depth won't be fully cleared
|
|
|
|
// AT tolenico 2 map clip bug
|
|
|
|
OMAttachRt(NULL);
|
|
|
|
OMAttachDs(T);
|
|
|
|
|
|
|
|
// TODO: check size of scissor before toggling it
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
2016-07-27 21:22:46 +00:00
|
|
|
float c = 0.0f;
|
2016-05-15 12:57:37 +00:00
|
|
|
if (GLState::depth_mask) {
|
|
|
|
glClearBufferfv(GL_DEPTH, 0, &c);
|
|
|
|
} else {
|
|
|
|
glDepthMask(true);
|
|
|
|
glClearBufferfv(GL_DEPTH, 0, &c);
|
|
|
|
glDepthMask(false);
|
|
|
|
}
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
2012-08-08 17:49:23 +00:00
|
|
|
}
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::ClearStencil(GSTexture* t, uint8 c)
|
|
|
|
{
|
2015-08-04 17:26:17 +00:00
|
|
|
if (!t) return;
|
|
|
|
|
2015-05-12 16:18:04 +00:00
|
|
|
GSTextureOGL* T = static_cast<GSTextureOGL*>(t);
|
|
|
|
|
2015-05-16 17:28:22 +00:00
|
|
|
GL_PUSH("Clear Stencil %d", T->GetID());
|
2015-05-06 16:52:51 +00:00
|
|
|
|
2015-05-01 18:04:23 +00:00
|
|
|
// Keep SCISSOR_TEST enabled on purpose to reduce the size
|
|
|
|
// of clean in DATE (impact big upscaling)
|
2015-04-24 16:15:58 +00:00
|
|
|
OMSetFBO(m_fbo);
|
2015-05-12 16:18:04 +00:00
|
|
|
OMAttachDs(T);
|
2015-04-24 16:15:58 +00:00
|
|
|
GLint color = c;
|
2013-06-01 09:29:57 +00:00
|
|
|
|
2015-10-17 15:05:15 +00:00
|
|
|
glClearBufferiv(GL_STENCIL, 0, &color);
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
|
|
|
|
2013-08-17 08:57:52 +00:00
|
|
|
GLuint GSDeviceOGL::CreateSampler(PSSamplerSelector sel)
|
|
|
|
{
|
2015-10-17 12:39:26 +00:00
|
|
|
return CreateSampler(sel.ltf, sel.tau, sel.tav, sel.aniso);
|
2013-08-17 08:57:52 +00:00
|
|
|
}
|
|
|
|
|
2015-10-17 12:39:26 +00:00
|
|
|
GLuint GSDeviceOGL::CreateSampler(bool bilinear, bool tau, bool tav, bool aniso)
|
2013-06-09 16:41:58 +00:00
|
|
|
{
|
2015-05-07 22:16:31 +00:00
|
|
|
GL_PUSH("Create Sampler");
|
|
|
|
|
2013-06-26 20:09:07 +00:00
|
|
|
GLuint sampler;
|
2016-04-07 20:55:56 +00:00
|
|
|
glCreateSamplers(1, &sampler);
|
2013-06-09 16:41:58 +00:00
|
|
|
if (bilinear) {
|
2015-10-17 15:05:15 +00:00
|
|
|
glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
2013-06-09 16:41:58 +00:00
|
|
|
} else {
|
2015-10-17 15:05:15 +00:00
|
|
|
glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
2013-06-09 16:41:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tau)
|
2015-10-17 15:05:15 +00:00
|
|
|
glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
2013-06-09 16:41:58 +00:00
|
|
|
else
|
2015-10-17 15:05:15 +00:00
|
|
|
glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
2013-06-09 16:41:58 +00:00
|
|
|
if (tav)
|
2015-10-17 15:05:15 +00:00
|
|
|
glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
2013-06-09 16:41:58 +00:00
|
|
|
else
|
2015-10-17 15:05:15 +00:00
|
|
|
glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2013-06-09 16:41:58 +00:00
|
|
|
|
2015-10-17 15:05:15 +00:00
|
|
|
glSamplerParameteri(sampler, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
2013-06-09 16:41:58 +00:00
|
|
|
|
2015-10-17 15:05:15 +00:00
|
|
|
glSamplerParameterf(sampler, GL_TEXTURE_MIN_LOD, 0);
|
|
|
|
glSamplerParameterf(sampler, GL_TEXTURE_MAX_LOD, 6);
|
2013-06-09 16:41:58 +00:00
|
|
|
|
2016-05-24 19:52:06 +00:00
|
|
|
int anisotropy = theApp.GetConfigI("MaxAnisotropy");
|
2015-10-17 12:39:26 +00:00
|
|
|
if (GLLoader::found_GL_EXT_texture_filter_anisotropic && anisotropy && aniso)
|
2015-10-17 15:05:15 +00:00
|
|
|
glSamplerParameterf(sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)anisotropy);
|
2013-06-26 20:09:07 +00:00
|
|
|
|
|
|
|
return sampler;
|
2013-06-09 16:41:58 +00:00
|
|
|
}
|
|
|
|
|
2016-04-24 08:53:12 +00:00
|
|
|
GLuint GSDeviceOGL::GetSamplerID(PSSamplerSelector ssel)
|
|
|
|
{
|
|
|
|
return m_ps_ss[ssel];
|
|
|
|
}
|
|
|
|
|
|
|
|
GSDepthStencilOGL* GSDeviceOGL::CreateDepthStencil(OMDepthStencilSelector dssel)
|
|
|
|
{
|
|
|
|
GSDepthStencilOGL* dss = new GSDepthStencilOGL();
|
|
|
|
|
|
|
|
if (dssel.date)
|
|
|
|
{
|
|
|
|
dss->EnableStencil();
|
2016-05-15 15:22:58 +00:00
|
|
|
if (dssel.date_one)
|
|
|
|
dss->SetStencil(GL_EQUAL, GL_ZERO);
|
|
|
|
else
|
|
|
|
dss->SetStencil(GL_EQUAL, GL_KEEP);
|
2016-04-24 08:53:12 +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);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dss;
|
|
|
|
}
|
|
|
|
|
2016-05-15 13:54:29 +00:00
|
|
|
void GSDeviceOGL::InitPrimDateTexture(GSTexture* rt, const GSVector4i& area)
|
2013-07-28 14:40:43 +00:00
|
|
|
{
|
2015-04-24 18:13:38 +00:00
|
|
|
const GSVector2i& rtsize = rt->GetSize();
|
|
|
|
|
2013-07-28 14:40:43 +00:00
|
|
|
// Create a texture to avoid the useless clean@0
|
|
|
|
if (m_date.t == NULL)
|
2015-04-24 18:13:38 +00:00
|
|
|
m_date.t = CreateTexture(rtsize.x, rtsize.y, GL_R32I);
|
2013-07-28 14:40:43 +00:00
|
|
|
|
2015-05-02 14:53:34 +00:00
|
|
|
// Clean with the max signed value
|
2016-05-15 13:54:29 +00:00
|
|
|
int max_int = 0x7FFFFFFF;
|
|
|
|
if (GLLoader::found_GL_ARB_clear_texture) {
|
|
|
|
static_cast<GSTextureOGL*>(m_date.t)->Clear(&max_int, area);
|
|
|
|
} else {
|
|
|
|
ClearRenderTarget_i(m_date.t, max_int);
|
|
|
|
}
|
2013-07-28 14:40:43 +00:00
|
|
|
|
2016-04-04 21:08:46 +00:00
|
|
|
glBindImageTexture(2, static_cast<GSTextureOGL*>(m_date.t)->GetID(), 0, false, 0, GL_READ_WRITE, GL_R32I);
|
2015-10-16 19:03:08 +00:00
|
|
|
#ifdef ENABLE_OGL_DEBUG
|
|
|
|
// Help to see the texture in apitrace
|
|
|
|
PSSetShaderResource(2, m_date.t);
|
|
|
|
#endif
|
2013-07-28 14:40:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::RecycleDateTexture()
|
|
|
|
{
|
|
|
|
if (m_date.t) {
|
2016-10-04 17:23:27 +00:00
|
|
|
//static_cast<GSTextureOGL*>(m_date.t)->Save(format("/tmp/date_adv_%04ld.csv", GSState::s_n));
|
2013-07-28 14:40:43 +00:00
|
|
|
|
|
|
|
Recycle(m_date.t);
|
|
|
|
m_date.t = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-02 16:38:12 +00:00
|
|
|
void GSDeviceOGL::Barrier(GLbitfield b)
|
|
|
|
{
|
2015-10-17 15:05:15 +00:00
|
|
|
glMemoryBarrier(b);
|
2013-08-02 16:38:12 +00:00
|
|
|
}
|
|
|
|
|
2013-08-10 19:43:59 +00:00
|
|
|
/* Note: must be here because tfx_glsl is static */
|
2016-04-07 19:57:54 +00:00
|
|
|
GLuint GSDeviceOGL::CompileVS(VSSelector sel)
|
2013-07-07 16:13:11 +00:00
|
|
|
{
|
2016-06-01 18:58:10 +00:00
|
|
|
if (GLLoader::buggy_sso_dual_src)
|
|
|
|
return m_shader->CompileShader("tfx_vgs.glsl", "vs_main", GL_VERTEX_SHADER, tfx_vgs_glsl, "");
|
|
|
|
else
|
|
|
|
return m_shader->Compile("tfx_vgs.glsl", "vs_main", GL_VERTEX_SHADER, tfx_vgs_glsl, "");
|
2013-07-07 16:13:11 +00:00
|
|
|
}
|
|
|
|
|
2013-08-10 19:43:59 +00:00
|
|
|
/* Note: must be here because tfx_glsl is static */
|
2015-07-10 21:59:14 +00:00
|
|
|
GLuint GSDeviceOGL::CompileGS(GSSelector sel)
|
2013-07-07 16:13:11 +00:00
|
|
|
{
|
2016-08-21 16:34:03 +00:00
|
|
|
std::string macro = format("#define GS_POINT %d\n", sel.point)
|
|
|
|
+ format("#define GS_LINE %d\n", sel.line);
|
2015-07-10 21:59:14 +00:00
|
|
|
|
2016-06-01 18:58:10 +00:00
|
|
|
if (GLLoader::buggy_sso_dual_src)
|
|
|
|
return m_shader->CompileShader("tfx_vgs.glsl", "gs_main", GL_GEOMETRY_SHADER, tfx_vgs_glsl, macro);
|
|
|
|
else
|
|
|
|
return m_shader->Compile("tfx_vgs.glsl", "gs_main", GL_GEOMETRY_SHADER, tfx_vgs_glsl, macro);
|
2013-07-07 16:13:11 +00:00
|
|
|
}
|
|
|
|
|
2013-08-10 19:43:59 +00:00
|
|
|
/* Note: must be here because tfx_glsl is static */
|
2013-07-07 16:13:11 +00:00
|
|
|
GLuint GSDeviceOGL::CompilePS(PSSelector sel)
|
|
|
|
{
|
|
|
|
std::string macro = format("#define PS_FST %d\n", sel.fst)
|
|
|
|
+ format("#define PS_WMS %d\n", sel.wms)
|
|
|
|
+ format("#define PS_WMT %d\n", sel.wmt)
|
2015-08-08 11:34:55 +00:00
|
|
|
+ format("#define PS_TEX_FMT %d\n", sel.tex_fmt)
|
2015-05-26 12:59:07 +00:00
|
|
|
+ format("#define PS_DFMT %d\n", sel.dfmt)
|
2016-04-23 10:06:10 +00:00
|
|
|
+ format("#define PS_DEPTH_FMT %d\n", sel.depth_fmt)
|
2016-04-28 20:15:28 +00:00
|
|
|
+ format("#define PS_CHANNEL_FETCH %d\n", sel.channel)
|
2016-05-06 17:57:42 +00:00
|
|
|
+ format("#define PS_URBAN_CHAOS_HLE %d\n", sel.urban_chaos_hle)
|
|
|
|
+ format("#define PS_TALES_OF_ABYSS_HLE %d\n", sel.tales_of_abyss_hle)
|
2016-09-08 21:26:38 +00:00
|
|
|
+ format("#define PS_TEX_IS_FB %d\n", sel.tex_is_fb)
|
2013-07-07 16:13:11 +00:00
|
|
|
+ format("#define PS_AEM %d\n", sel.aem)
|
|
|
|
+ format("#define PS_TFX %d\n", sel.tfx)
|
|
|
|
+ format("#define PS_TCC %d\n", sel.tcc)
|
|
|
|
+ format("#define PS_ATST %d\n", sel.atst)
|
|
|
|
+ format("#define PS_FOG %d\n", sel.fog)
|
|
|
|
+ format("#define PS_CLR1 %d\n", sel.clr1)
|
|
|
|
+ format("#define PS_FBA %d\n", sel.fba)
|
|
|
|
+ format("#define PS_LTF %d\n", sel.ltf)
|
|
|
|
+ format("#define PS_COLCLIP %d\n", sel.colclip)
|
|
|
|
+ format("#define PS_DATE %d\n", sel.date)
|
|
|
|
+ format("#define PS_TCOFFSETHACK %d\n", sel.tcoffsethack)
|
2015-05-06 06:38:17 +00:00
|
|
|
//+ format("#define PS_POINT_SAMPLER %d\n", sel.point_sampler)
|
2015-07-13 13:19:33 +00:00
|
|
|
+ format("#define PS_BLEND_A %d\n", sel.blend_a)
|
|
|
|
+ format("#define PS_BLEND_B %d\n", sel.blend_b)
|
|
|
|
+ format("#define PS_BLEND_C %d\n", sel.blend_c)
|
|
|
|
+ format("#define PS_BLEND_D %d\n", sel.blend_d)
|
2013-08-14 10:18:38 +00:00
|
|
|
+ format("#define PS_IIP %d\n", sel.iip)
|
2015-06-06 11:56:08 +00:00
|
|
|
+ format("#define PS_SHUFFLE %d\n", sel.shuffle)
|
|
|
|
+ format("#define PS_READ_BA %d\n", sel.read_ba)
|
2015-08-04 18:08:33 +00:00
|
|
|
+ format("#define PS_WRITE_RG %d\n", sel.write_rg)
|
2015-06-21 06:47:45 +00:00
|
|
|
+ format("#define PS_FBMASK %d\n", sel.fbmask)
|
2015-07-30 20:05:08 +00:00
|
|
|
+ format("#define PS_HDR %d\n", sel.hdr)
|
2015-08-07 10:06:45 +00:00
|
|
|
+ format("#define PS_PABE %d\n", sel.pabe);
|
2016-06-01 18:58:10 +00:00
|
|
|
;
|
2013-07-07 16:13:11 +00:00
|
|
|
|
2016-06-01 18:58:10 +00:00
|
|
|
if (GLLoader::buggy_sso_dual_src)
|
|
|
|
return m_shader->CompileShader("tfx.glsl", "ps_main", GL_FRAGMENT_SHADER, tfx_fs_all_glsl, macro);
|
|
|
|
else
|
|
|
|
return m_shader->Compile("tfx.glsl", "ps_main", GL_FRAGMENT_SHADER, tfx_fs_all_glsl, macro);
|
2013-07-07 16:13:11 +00:00
|
|
|
}
|
|
|
|
|
2016-06-10 20:01:48 +00:00
|
|
|
void GSDeviceOGL::SelfShaderTestRun(const string& dir, const string& file, const PSSelector& sel, int& nb_shader)
|
|
|
|
{
|
|
|
|
#ifdef __unix__
|
|
|
|
string out = "/tmp/GSdx_Shader/";
|
|
|
|
GSmkdir(out.c_str());
|
|
|
|
|
|
|
|
out += dir + "/";
|
|
|
|
GSmkdir(out.c_str());
|
|
|
|
|
|
|
|
out += file;
|
|
|
|
#else
|
|
|
|
string out = file;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
// Nouveau actually
|
|
|
|
if (GLLoader::mesa_amd_buggy_driver) {
|
|
|
|
if (freopen(out.c_str(), "w", stderr) == NULL)
|
|
|
|
fprintf(stderr, "Failed to redirect stderr\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
GLuint p = CompilePS(sel);
|
|
|
|
nb_shader++;
|
|
|
|
m_shader_inst += m_shader->DumpAsm(out, p);
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
// Nouveau actually
|
|
|
|
if (GLLoader::mesa_amd_buggy_driver) {
|
|
|
|
if (freopen("/dev/tty", "w", stderr) == NULL)
|
|
|
|
fprintf(stderr, "Failed to restore stderr\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::SelfShaderTestPrint(const string& test, int& nb_shader)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%-25s\t\t%d shaders:\t%d instructions (M %4.2f)\t%d registers (M %4.2f)\n",
|
|
|
|
test.c_str(), nb_shader,
|
|
|
|
m_shader_inst, (float)m_shader_inst/(float)nb_shader,
|
|
|
|
m_shader_reg, (float)m_shader_reg/(float)nb_shader);
|
|
|
|
|
|
|
|
m_shader_inst = 0;
|
|
|
|
m_shader_reg = 0;
|
|
|
|
nb_shader = 0;
|
|
|
|
}
|
|
|
|
|
2015-07-15 06:59:16 +00:00
|
|
|
void GSDeviceOGL::SelfShaderTest()
|
|
|
|
{
|
2016-06-10 20:01:48 +00:00
|
|
|
string out = "";
|
2015-07-15 06:59:16 +00:00
|
|
|
|
2016-06-10 20:01:48 +00:00
|
|
|
#ifdef __unix__
|
|
|
|
setenv("NV50_PROG_DEBUG", "1", 1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
string test;
|
|
|
|
m_shader_inst = 0;
|
|
|
|
m_shader_reg = 0;
|
2015-07-15 06:59:16 +00:00
|
|
|
int nb_shader = 0;
|
2016-06-10 20:01:48 +00:00
|
|
|
|
|
|
|
test = "SW_Blending";
|
2015-07-30 20:11:32 +00:00
|
|
|
for (int colclip = 0; colclip < 2; colclip++) {
|
2015-07-15 06:59:16 +00:00
|
|
|
for (int fmt = 0; fmt < 3; fmt++) {
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
PSSelector sel;
|
|
|
|
sel.tfx = 4;
|
|
|
|
|
|
|
|
int ib = (i + 1) % 3;
|
|
|
|
sel.blend_a = i;
|
|
|
|
sel.blend_b = ib;;
|
|
|
|
sel.blend_c = i;
|
|
|
|
sel.blend_d = i;
|
|
|
|
sel.colclip = colclip;
|
|
|
|
sel.dfmt = fmt;
|
|
|
|
|
|
|
|
std::string file = format("Shader_Blend_%d_%d_%d_%d__Cclip_%d__Dfmt_%d.glsl.asm",
|
|
|
|
i, ib, i, i, colclip, fmt);
|
2016-06-10 20:01:48 +00:00
|
|
|
SelfShaderTestRun(test, file, sel, nb_shader);
|
2015-07-15 06:59:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-10 20:01:48 +00:00
|
|
|
SelfShaderTestPrint(test, nb_shader);
|
2015-07-15 06:59:16 +00:00
|
|
|
|
2016-06-10 20:01:48 +00:00
|
|
|
test = "Alpha_Test";
|
2016-06-11 08:33:17 +00:00
|
|
|
for (int atst = 0; atst < 5; atst++) {
|
2015-07-15 06:59:16 +00:00
|
|
|
PSSelector sel;
|
|
|
|
sel.tfx = 4;
|
|
|
|
|
|
|
|
sel.atst = atst;
|
|
|
|
std::string file = format("Shader_Atst_%d.glsl.asm", atst);
|
2016-06-10 20:01:48 +00:00
|
|
|
SelfShaderTestRun(test, file, sel, nb_shader);
|
2015-07-15 06:59:16 +00:00
|
|
|
}
|
2016-06-10 20:01:48 +00:00
|
|
|
SelfShaderTestPrint(test, nb_shader);
|
2015-07-15 06:59:16 +00:00
|
|
|
|
2016-06-10 20:01:48 +00:00
|
|
|
test = "Fbmask__Fog__Shuffle__Read_ba";
|
2015-07-15 06:59:16 +00:00
|
|
|
for (int read_ba = 0; read_ba < 2; read_ba++) {
|
|
|
|
PSSelector sel;
|
|
|
|
sel.tfx = 4;
|
|
|
|
|
|
|
|
sel.fog = 1;
|
|
|
|
sel.fbmask = 1;
|
|
|
|
sel.shuffle = 1;
|
|
|
|
sel.read_ba = read_ba;
|
|
|
|
|
|
|
|
std::string file = format("Shader_Fog__Fbmask__Shuffle__Read_ba_%d.glsl.asm", read_ba);
|
2016-06-10 20:01:48 +00:00
|
|
|
SelfShaderTestRun(test, file, sel, nb_shader);
|
2015-07-15 06:59:16 +00:00
|
|
|
}
|
2016-06-10 20:01:48 +00:00
|
|
|
SelfShaderTestPrint(test, nb_shader);
|
2015-07-15 06:59:16 +00:00
|
|
|
|
2016-06-10 20:01:48 +00:00
|
|
|
test = "Date";
|
2015-07-15 06:59:16 +00:00
|
|
|
for (int date = 1; date < 7; date++) {
|
|
|
|
PSSelector sel;
|
|
|
|
sel.tfx = 4;
|
|
|
|
|
|
|
|
sel.date = date;
|
|
|
|
std::string file = format("Shader_Date_%d.glsl.asm", date);
|
2016-06-10 20:01:48 +00:00
|
|
|
SelfShaderTestRun(test, file, sel, nb_shader);
|
2015-07-15 06:59:16 +00:00
|
|
|
}
|
2016-06-10 20:01:48 +00:00
|
|
|
SelfShaderTestPrint(test, nb_shader);
|
2015-07-15 06:59:16 +00:00
|
|
|
|
2016-06-10 20:01:48 +00:00
|
|
|
test = "FBA";
|
2015-07-15 06:59:16 +00:00
|
|
|
for (int fmt = 0; fmt < 3; fmt++) {
|
|
|
|
PSSelector sel;
|
|
|
|
sel.tfx = 4;
|
|
|
|
|
|
|
|
sel.fba = 1;
|
|
|
|
sel.dfmt = fmt;
|
|
|
|
sel.clr1 = 1;
|
|
|
|
std::string file = format("Shader_Fba__Clr1__Dfmt_%d.glsl.asm", fmt);
|
2016-06-10 20:01:48 +00:00
|
|
|
SelfShaderTestRun(test, file, sel, nb_shader);
|
2015-07-15 06:59:16 +00:00
|
|
|
}
|
2016-06-10 20:01:48 +00:00
|
|
|
SelfShaderTestPrint(test, nb_shader);
|
2015-07-15 06:59:16 +00:00
|
|
|
|
2016-06-10 20:01:48 +00:00
|
|
|
test = "Fst__Tc__IIP";
|
2015-07-15 06:59:16 +00:00
|
|
|
{
|
|
|
|
PSSelector sel;
|
|
|
|
sel.tfx = 1;
|
|
|
|
|
|
|
|
sel.fst = 0;
|
|
|
|
sel.iip = 1;
|
|
|
|
sel.tcoffsethack = 1;
|
|
|
|
|
|
|
|
std::string file = format("Shader_Fst__TC__Iip.glsl.asm");
|
2016-06-10 20:01:48 +00:00
|
|
|
SelfShaderTestRun(test, file, sel, nb_shader);
|
2015-07-15 06:59:16 +00:00
|
|
|
}
|
2016-06-10 20:01:48 +00:00
|
|
|
SelfShaderTestPrint(test, nb_shader);
|
2015-07-15 06:59:16 +00:00
|
|
|
|
2016-06-10 20:01:48 +00:00
|
|
|
test = "Tfx__Tcc";
|
2016-04-28 20:15:28 +00:00
|
|
|
for (int channel = 0; channel < 5; channel++) {
|
|
|
|
for (int tfx = 0; tfx < 5; tfx++) {
|
|
|
|
for (int tcc = 0; tcc < 2; tcc++) {
|
|
|
|
PSSelector sel;
|
|
|
|
sel.fst = 1;
|
|
|
|
|
|
|
|
sel.channel = channel;
|
|
|
|
sel.tfx = tfx;
|
|
|
|
sel.tcc = tcc;
|
|
|
|
std::string file = format("Shader_Tfx_%d__Tcc_%d__Channel_%d.glsl.asm", tfx, tcc, channel);
|
2016-06-10 20:01:48 +00:00
|
|
|
SelfShaderTestRun(test, file, sel, nb_shader);
|
2016-04-28 20:15:28 +00:00
|
|
|
}
|
2015-07-15 06:59:16 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-10 20:01:48 +00:00
|
|
|
SelfShaderTestPrint(test, nb_shader);
|
2015-07-15 06:59:16 +00:00
|
|
|
|
2016-06-10 20:01:48 +00:00
|
|
|
test = "Texture_Sampling";
|
2016-04-28 20:15:28 +00:00
|
|
|
for (int depth = 0; depth < 4; depth++) {
|
|
|
|
for (int fmt = 0; fmt < 16; fmt++) {
|
|
|
|
if ((fmt & 3) == 3) continue;
|
|
|
|
|
|
|
|
for (int ltf = 0; ltf < 2; ltf++) {
|
|
|
|
for (int aem = 0; aem < 2; aem++) {
|
|
|
|
for (int wms = 1; wms < 4; wms++) {
|
|
|
|
for (int wmt = 1; wmt < 4; wmt++) {
|
|
|
|
PSSelector sel;
|
|
|
|
sel.tfx = 1;
|
|
|
|
sel.tcc = 1;
|
|
|
|
sel.fst = 1;
|
|
|
|
|
|
|
|
sel.depth_fmt = depth;
|
|
|
|
sel.ltf = ltf;
|
|
|
|
sel.aem = aem;
|
|
|
|
sel.tex_fmt = fmt;
|
|
|
|
sel.wms = wms;
|
|
|
|
sel.wmt = wmt;
|
|
|
|
std::string file = format("Shader_Ltf_%d__Aem_%d__TFmt_%d__Wms_%d__Wmt_%d__DepthFmt_%d.glsl.asm",
|
|
|
|
ltf, aem, fmt, wms, wmt, depth);
|
2016-06-10 20:01:48 +00:00
|
|
|
SelfShaderTestRun(test, file, sel, nb_shader);
|
2016-04-28 20:15:28 +00:00
|
|
|
}
|
2015-07-15 06:59:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-10 20:01:48 +00:00
|
|
|
SelfShaderTestPrint(test, nb_shader);
|
2015-07-15 06:59:16 +00:00
|
|
|
}
|
|
|
|
|
2011-11-21 22:36:03 +00:00
|
|
|
GSTexture* GSDeviceOGL::CreateRenderTarget(int w, int h, bool msaa, int format)
|
|
|
|
{
|
|
|
|
return GSDevice::CreateRenderTarget(w, h, msaa, format ? format : GL_RGBA8);
|
|
|
|
}
|
|
|
|
|
|
|
|
GSTexture* GSDeviceOGL::CreateDepthStencil(int w, int h, bool msaa, int format)
|
|
|
|
{
|
|
|
|
return GSDevice::CreateDepthStencil(w, h, msaa, format ? format : GL_DEPTH32F_STENCIL8);
|
|
|
|
}
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2011-11-21 22:36:03 +00:00
|
|
|
GSTexture* GSDeviceOGL::CreateTexture(int w, int h, int format)
|
|
|
|
{
|
|
|
|
return GSDevice::CreateTexture(w, h, format ? format : GL_RGBA8);
|
|
|
|
}
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2011-11-21 22:36:03 +00:00
|
|
|
GSTexture* GSDeviceOGL::CreateOffscreen(int w, int h, int format)
|
|
|
|
{
|
|
|
|
return GSDevice::CreateOffscreen(w, h, format ? format : GL_RGBA8);
|
|
|
|
}
|
2011-11-16 22:17:37 +00:00
|
|
|
|
|
|
|
// blit a texture into an offscreen buffer
|
2015-05-19 10:42:14 +00:00
|
|
|
GSTexture* GSDeviceOGL::CopyOffscreen(GSTexture* src, const GSVector4& sRect, int w, int h, int format, int ps_shader)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2015-05-19 10:42:14 +00:00
|
|
|
if (format == 0)
|
|
|
|
format = GL_RGBA8;
|
|
|
|
|
2013-07-19 19:25:50 +00:00
|
|
|
ASSERT(src);
|
2015-05-20 06:07:40 +00:00
|
|
|
ASSERT(format == GL_RGBA8 || format == GL_R16UI || format == GL_R32UI);
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2013-07-19 19:25:50 +00:00
|
|
|
GSTexture* dst = CreateOffscreen(w, h, format);
|
2015-05-19 10:42:14 +00:00
|
|
|
|
2015-05-15 18:49:25 +00:00
|
|
|
GSVector4 dRect(0, 0, w, h);
|
2012-03-05 20:16:26 +00:00
|
|
|
|
2015-05-19 10:42:14 +00:00
|
|
|
StretchRect(src, sRect, dst, dRect, m_convert.ps[ps_shader]);
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2012-03-05 20:16:26 +00:00
|
|
|
return dst;
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
2015-07-23 07:29:32 +00:00
|
|
|
// Copy a sub part of texture (same as below but force a conversion)
|
2015-07-24 20:06:35 +00:00
|
|
|
void GSDeviceOGL::CopyRectConv(GSTexture* sTex, GSTexture* dTex, const GSVector4i& r, bool at_origin)
|
2015-07-23 07:29:32 +00:00
|
|
|
{
|
2015-10-21 17:58:31 +00:00
|
|
|
ASSERT(sTex && dTex);
|
|
|
|
if (!(sTex && dTex))
|
|
|
|
return;
|
|
|
|
|
2016-04-04 21:08:46 +00:00
|
|
|
const GLuint& sid = static_cast<GSTextureOGL*>(sTex)->GetID();
|
|
|
|
const GLuint& did = static_cast<GSTextureOGL*>(dTex)->GetID();
|
2015-07-23 07:29:32 +00:00
|
|
|
|
|
|
|
GL_PUSH(format("CopyRectConv from %d to %d", sid, did).c_str());
|
|
|
|
|
2015-10-17 15:05:15 +00:00
|
|
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo_read);
|
2015-07-23 07:29:32 +00:00
|
|
|
|
2015-10-17 15:05:15 +00:00
|
|
|
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, sid, 0);
|
2015-07-24 20:06:35 +00:00
|
|
|
if (at_origin)
|
2015-10-17 15:05:15 +00:00
|
|
|
glCopyTextureSubImage2D(did, GL_TEX_LEVEL_0, 0, 0, r.x, r.y, r.width(), r.height());
|
2015-07-24 20:06:35 +00:00
|
|
|
else
|
2015-10-17 15:05:15 +00:00
|
|
|
glCopyTextureSubImage2D(did, GL_TEX_LEVEL_0, r.x, r.y, r.x, r.y, r.width(), r.height());
|
2015-07-23 07:29:32 +00:00
|
|
|
|
2015-10-17 15:05:15 +00:00
|
|
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
2015-07-23 07:29:32 +00:00
|
|
|
}
|
|
|
|
|
2011-11-16 22:17:37 +00:00
|
|
|
// Copy a sub part of a texture into another
|
2015-05-15 18:45:31 +00:00
|
|
|
void GSDeviceOGL::CopyRect(GSTexture* sTex, GSTexture* dTex, const GSVector4i& r)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2015-05-15 18:45:31 +00:00
|
|
|
ASSERT(sTex && dTex);
|
2015-10-21 17:58:31 +00:00
|
|
|
if (!(sTex && dTex))
|
|
|
|
return;
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2016-04-04 21:08:46 +00:00
|
|
|
const GLuint& sid = static_cast<GSTextureOGL*>(sTex)->GetID();
|
|
|
|
const GLuint& did = static_cast<GSTextureOGL*>(dTex)->GetID();
|
2015-05-07 23:01:01 +00:00
|
|
|
|
2015-05-16 17:28:22 +00:00
|
|
|
GL_PUSH("CopyRect from %d to %d", sid, did);
|
2015-05-06 16:52:51 +00:00
|
|
|
|
2016-10-08 15:53:32 +00:00
|
|
|
#ifdef ENABLE_OGL_DEBUG
|
|
|
|
PSSetShaderResource(6, sTex);
|
|
|
|
#endif
|
|
|
|
|
2016-04-19 16:58:25 +00:00
|
|
|
glCopyImageSubData( sid, GL_TEXTURE_2D,
|
|
|
|
0, r.x, r.y, 0,
|
|
|
|
did, GL_TEXTURE_2D,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
r.width(), r.height(), 1);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
2015-05-15 18:49:25 +00:00
|
|
|
void GSDeviceOGL::StretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture* dTex, const GSVector4& dRect, int shader, bool linear)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2015-05-15 18:49:25 +00:00
|
|
|
StretchRect(sTex, sRect, dTex, dRect, m_convert.ps[shader], linear);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
2011-11-21 22:36:03 +00:00
|
|
|
|
2015-05-15 18:49:25 +00:00
|
|
|
void GSDeviceOGL::StretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture* dTex, const GSVector4& dRect, GLuint ps, bool linear)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2015-07-31 18:28:54 +00:00
|
|
|
StretchRect(sTex, sRect, dTex, dRect, ps, m_NO_BLEND, linear);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
2015-07-31 18:28:54 +00:00
|
|
|
void GSDeviceOGL::StretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture* dTex, const GSVector4& dRect, GLuint ps, int bs, bool linear)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2015-05-15 18:45:31 +00:00
|
|
|
if(!sTex || !dTex)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
|
|
|
ASSERT(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-08 14:36:23 +00:00
|
|
|
bool draw_in_depth = (ps == m_convert.ps[ShaderConvert_RGBA8_TO_FLOAT32] || ps == m_convert.ps[ShaderConvert_RGBA8_TO_FLOAT24] ||
|
|
|
|
ps == m_convert.ps[ShaderConvert_RGBA8_TO_FLOAT16] || ps == m_convert.ps[ShaderConvert_RGB5A1_TO_FLOAT16]);
|
2015-06-05 21:26:03 +00:00
|
|
|
|
2015-05-29 16:12:08 +00:00
|
|
|
// Performance optimization. It might be faster to use a framebuffer blit for standard case
|
|
|
|
// instead to emulate it with shader
|
|
|
|
// see https://www.opengl.org/wiki/Framebuffer#Blitting
|
|
|
|
|
2015-05-16 17:28:22 +00:00
|
|
|
GL_PUSH("StretchRect from %d to %d", sTex->GetID(), dTex->GetID());
|
2015-05-06 16:52:51 +00:00
|
|
|
|
2011-12-10 19:19:44 +00:00
|
|
|
// ************************************
|
|
|
|
// Init
|
|
|
|
// ************************************
|
|
|
|
|
2011-11-16 22:17:37 +00:00
|
|
|
BeginScene();
|
|
|
|
|
2015-05-15 18:43:57 +00:00
|
|
|
GSVector2i ds = dTex->GetSize();
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2016-04-10 15:28:05 +00:00
|
|
|
m_shader->BindPipeline(ps);
|
2013-08-10 19:43:59 +00:00
|
|
|
|
2011-12-10 19:19:44 +00:00
|
|
|
// ************************************
|
2011-11-16 22:17:37 +00:00
|
|
|
// om
|
2011-12-10 19:19:44 +00:00
|
|
|
// ************************************
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2015-06-05 21:26:03 +00:00
|
|
|
if (draw_in_depth)
|
2015-08-01 09:35:21 +00:00
|
|
|
OMSetDepthStencilState(m_convert.dss_write);
|
2015-06-05 21:26:03 +00:00
|
|
|
else
|
2015-08-01 09:35:21 +00:00
|
|
|
OMSetDepthStencilState(m_convert.dss);
|
2015-06-05 21:26:03 +00:00
|
|
|
|
|
|
|
if (draw_in_depth)
|
|
|
|
OMSetRenderTargets(NULL, dTex);
|
|
|
|
else
|
|
|
|
OMSetRenderTargets(dTex, NULL);
|
2015-07-31 18:28:54 +00:00
|
|
|
|
2016-04-14 10:00:58 +00:00
|
|
|
OMSetBlendState((uint8)bs);
|
2015-05-05 08:26:01 +00:00
|
|
|
OMSetColorMaskState();
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2011-12-10 19:19:44 +00:00
|
|
|
// ************************************
|
2011-11-16 22:17:37 +00:00
|
|
|
// ia
|
2011-12-10 19:19:44 +00:00
|
|
|
// ************************************
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2011-12-11 19:09:08 +00:00
|
|
|
|
2013-06-11 11:14:26 +00:00
|
|
|
// Original code from DX
|
2015-05-15 18:49:25 +00:00
|
|
|
float left = dRect.x * 2 / ds.x - 1.0f;
|
|
|
|
float right = dRect.z * 2 / ds.x - 1.0f;
|
2013-06-11 11:14:26 +00:00
|
|
|
#if 0
|
2015-05-15 18:49:25 +00:00
|
|
|
float top = 1.0f - dRect.y * 2 / ds.y;
|
|
|
|
float bottom = 1.0f - dRect.w * 2 / ds.y;
|
2013-06-11 11:14:26 +00:00
|
|
|
#else
|
|
|
|
// Opengl get some issues with the coordinate
|
|
|
|
// I flip top/bottom to fix scaling of the internal resolution
|
2015-05-15 18:49:25 +00:00
|
|
|
float top = -1.0f + dRect.y * 2 / ds.y;
|
|
|
|
float bottom = -1.0f + dRect.w * 2 / ds.y;
|
2013-06-11 11:14:26 +00:00
|
|
|
#endif
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2011-12-11 19:09:08 +00:00
|
|
|
// Flip y axis only when we render in the backbuffer
|
|
|
|
// By default everything is render in the wrong order (ie dx).
|
|
|
|
// 1/ consistency between several pass rendering (interlace)
|
|
|
|
// 2/ in case some GSdx code expect thing in dx order.
|
|
|
|
// Only flipping the backbuffer is transparent (I hope)...
|
2015-05-15 18:47:14 +00:00
|
|
|
GSVector4 flip_sr = sRect;
|
2015-05-15 18:43:57 +00:00
|
|
|
if (static_cast<GSTextureOGL*>(dTex)->IsBackbuffer()) {
|
2015-05-15 18:47:14 +00:00
|
|
|
flip_sr.y = sRect.w;
|
|
|
|
flip_sr.w = sRect.y;
|
2011-12-11 19:09:08 +00:00
|
|
|
}
|
|
|
|
|
2014-10-01 19:46:20 +00:00
|
|
|
GSVertexPT1 vertices[] =
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2014-10-01 19:46:20 +00:00
|
|
|
{GSVector4(left , top , 0.0f, 0.0f) , GSVector2(flip_sr.x , flip_sr.y)} ,
|
|
|
|
{GSVector4(right , top , 0.0f, 0.0f) , GSVector2(flip_sr.z , flip_sr.y)} ,
|
|
|
|
{GSVector4(left , bottom, 0.0f, 0.0f) , GSVector2(flip_sr.x , flip_sr.w)} ,
|
|
|
|
{GSVector4(right , bottom, 0.0f, 0.0f) , GSVector2(flip_sr.z , flip_sr.w)} ,
|
2011-11-16 22:17:37 +00:00
|
|
|
};
|
|
|
|
|
2011-12-15 18:27:58 +00:00
|
|
|
IASetVertexBuffer(vertices, 4);
|
|
|
|
IASetPrimitiveTopology(GL_TRIANGLE_STRIP);
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2011-12-10 19:19:44 +00:00
|
|
|
// ************************************
|
2013-08-10 19:43:59 +00:00
|
|
|
// Texture
|
2011-12-10 19:19:44 +00:00
|
|
|
// ************************************
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2015-08-07 12:46:57 +00:00
|
|
|
PSSetShaderResource(0, sTex);
|
|
|
|
PSSetSamplerState(linear ? m_convert.ln : m_convert.pt);
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2011-12-10 19:19:44 +00:00
|
|
|
// ************************************
|
|
|
|
// Draw
|
|
|
|
// ************************************
|
2011-12-15 18:27:58 +00:00
|
|
|
DrawPrimitive();
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2011-12-10 19:19:44 +00:00
|
|
|
// ************************************
|
|
|
|
// End
|
|
|
|
// ************************************
|
2011-11-16 22:17:37 +00:00
|
|
|
|
|
|
|
EndScene();
|
|
|
|
}
|
|
|
|
|
2015-05-15 18:49:25 +00:00
|
|
|
void GSDeviceOGL::DoMerge(GSTexture* sTex[2], GSVector4* sRect, GSTexture* dTex, GSVector4* dRect, bool slbg, bool mmod, const GSVector4& c)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2015-05-06 16:52:51 +00:00
|
|
|
GL_PUSH("DoMerge");
|
|
|
|
|
2015-05-15 10:52:03 +00:00
|
|
|
OMSetColorMaskState();
|
|
|
|
|
2015-05-15 18:43:57 +00:00
|
|
|
ClearRenderTarget(dTex, c);
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2015-05-15 18:45:31 +00:00
|
|
|
if(sTex[1] && !slbg)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2015-05-15 18:49:25 +00:00
|
|
|
StretchRect(sTex[1], sRect[1], dTex, dRect[1], m_merge_obj.ps[0]);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
2015-05-15 18:45:31 +00:00
|
|
|
if(sTex[0])
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2016-05-28 17:13:35 +00:00
|
|
|
m_merge_obj.cb->cache_upload(&c.v);
|
2011-12-11 19:09:08 +00:00
|
|
|
|
2015-07-31 18:28:54 +00:00
|
|
|
StretchRect(sTex[0], sRect[0], dTex, dRect[0], m_merge_obj.ps[mmod ? 1 : 0], m_MERGE_BLEND);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-15 18:45:31 +00:00
|
|
|
void GSDeviceOGL::DoInterlace(GSTexture* sTex, GSTexture* dTex, int shader, bool linear, float yoffset)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2015-05-06 16:52:51 +00:00
|
|
|
GL_PUSH("DoInterlace");
|
|
|
|
|
2015-05-15 10:52:03 +00:00
|
|
|
OMSetColorMaskState();
|
|
|
|
|
2015-05-15 18:43:57 +00:00
|
|
|
GSVector4 s = GSVector4(dTex->GetSize());
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2015-05-15 18:47:14 +00:00
|
|
|
GSVector4 sRect(0, 0, 1, 1);
|
2015-05-15 18:49:25 +00:00
|
|
|
GSVector4 dRect(0.0f, yoffset, s.x, s.y + yoffset);
|
2011-11-16 22:17:37 +00:00
|
|
|
|
|
|
|
InterlaceConstantBuffer cb;
|
|
|
|
|
|
|
|
cb.ZrH = GSVector2(0, 1.0f / s.y);
|
|
|
|
cb.hH = s.y / 2;
|
|
|
|
|
2016-05-28 17:13:35 +00:00
|
|
|
m_interlace.cb->cache_upload(&cb);
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2015-05-15 18:49:25 +00:00
|
|
|
StretchRect(sTex, sRect, dTex, dRect, m_interlace.ps[shader], linear);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
2015-05-15 18:45:31 +00:00
|
|
|
void GSDeviceOGL::DoFXAA(GSTexture* sTex, GSTexture* dTex)
|
2013-06-14 21:22:44 +00:00
|
|
|
{
|
2014-11-09 14:27:24 +00:00
|
|
|
// Lazy compile
|
|
|
|
if (!m_fxaa.ps) {
|
2015-05-01 18:04:23 +00:00
|
|
|
if (!GLLoader::found_GL_ARB_gpu_shader5) { // GL4.0 extension
|
2014-11-09 16:23:17 +00:00
|
|
|
return;
|
2014-11-09 14:27:24 +00:00
|
|
|
}
|
2015-05-01 18:04:23 +00:00
|
|
|
|
|
|
|
std::string fxaa_macro = "#define FXAA_GLSL_130 1\n";
|
|
|
|
fxaa_macro += "#extension GL_ARB_gpu_shader5 : enable\n";
|
2016-04-10 15:28:05 +00:00
|
|
|
GLuint ps = m_shader->Compile("fxaa.fx", "ps_main", GL_FRAGMENT_SHADER, fxaa_fx, fxaa_macro);
|
2016-06-07 18:30:56 +00:00
|
|
|
m_fxaa.ps = m_shader->LinkPipeline("FXAA pipe", m_convert.vs, 0, ps);
|
2014-11-09 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
2015-05-06 16:52:51 +00:00
|
|
|
GL_PUSH("DoFxaa");
|
|
|
|
|
2015-05-15 10:52:03 +00:00
|
|
|
OMSetColorMaskState();
|
|
|
|
|
2015-05-15 18:43:57 +00:00
|
|
|
GSVector2i s = dTex->GetSize();
|
2013-06-14 21:22:44 +00:00
|
|
|
|
2015-05-15 18:47:14 +00:00
|
|
|
GSVector4 sRect(0, 0, 1, 1);
|
2015-05-15 18:49:25 +00:00
|
|
|
GSVector4 dRect(0, 0, s.x, s.y);
|
2013-06-14 21:22:44 +00:00
|
|
|
|
2015-05-15 18:49:25 +00:00
|
|
|
StretchRect(sTex, sRect, dTex, dRect, m_fxaa.ps, true);
|
2013-06-14 21:22:44 +00:00
|
|
|
}
|
|
|
|
|
2015-05-15 18:45:31 +00:00
|
|
|
void GSDeviceOGL::DoExternalFX(GSTexture* sTex, GSTexture* dTex)
|
2014-11-09 14:27:24 +00:00
|
|
|
{
|
|
|
|
// Lazy compile
|
|
|
|
if (!m_shaderfx.ps) {
|
2015-05-01 18:04:23 +00:00
|
|
|
if (!GLLoader::found_GL_ARB_gpu_shader5) { // GL4.0 extension
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-24 19:52:06 +00:00
|
|
|
std::string config_name(theApp.GetConfigS("shaderfx_conf"));
|
2015-05-18 08:56:32 +00:00
|
|
|
std::ifstream fconfig(config_name);
|
2014-11-09 14:27:24 +00:00
|
|
|
std::stringstream config;
|
|
|
|
if (fconfig.good())
|
|
|
|
config << fconfig.rdbuf();
|
2015-05-18 08:56:32 +00:00
|
|
|
else
|
|
|
|
fprintf(stderr, "Warning failed to load '%s'. External Shader might be wrongly configured\n", config_name.c_str());
|
2014-11-09 14:27:24 +00:00
|
|
|
|
2016-05-24 19:52:06 +00:00
|
|
|
std::string shader_name(theApp.GetConfigS("shaderfx_glsl"));
|
2015-05-18 08:56:32 +00:00
|
|
|
std::ifstream fshader(shader_name);
|
2014-11-09 14:27:24 +00:00
|
|
|
std::stringstream shader;
|
2015-05-18 08:56:32 +00:00
|
|
|
if (!fshader.good()) {
|
|
|
|
fprintf(stderr, "Error failed to load '%s'. External Shader will be disabled !\n", shader_name.c_str());
|
2014-11-09 14:27:24 +00:00
|
|
|
return;
|
2015-05-18 08:56:32 +00:00
|
|
|
}
|
2014-11-09 14:27:24 +00:00
|
|
|
shader << fshader.rdbuf();
|
|
|
|
|
|
|
|
|
2016-06-07 18:30:56 +00:00
|
|
|
m_shaderfx.cb = new GSUniformBufferOGL("eFX UBO", g_fx_cb_index, sizeof(ExternalFXConstantBuffer));
|
2016-04-10 15:28:05 +00:00
|
|
|
GLuint ps = m_shader->Compile("Extra", "ps_main", GL_FRAGMENT_SHADER, shader.str().c_str(), config.str());
|
2016-06-07 18:30:56 +00:00
|
|
|
m_shaderfx.ps = m_shader->LinkPipeline("eFX pipie", m_convert.vs, 0, ps);
|
2014-11-09 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
2015-05-06 16:52:51 +00:00
|
|
|
GL_PUSH("DoExternalFX");
|
|
|
|
|
2015-05-15 10:52:03 +00:00
|
|
|
OMSetColorMaskState();
|
|
|
|
|
2015-05-15 18:43:57 +00:00
|
|
|
GSVector2i s = dTex->GetSize();
|
2014-11-09 14:27:24 +00:00
|
|
|
|
2015-05-15 18:47:14 +00:00
|
|
|
GSVector4 sRect(0, 0, 1, 1);
|
2015-05-15 18:49:25 +00:00
|
|
|
GSVector4 dRect(0, 0, s.x, s.y);
|
2014-11-09 14:27:24 +00:00
|
|
|
|
|
|
|
ExternalFXConstantBuffer cb;
|
|
|
|
|
2016-04-14 10:00:58 +00:00
|
|
|
cb.xyFrame = GSVector2((float)s.x, (float)s.y);
|
2014-11-09 14:27:24 +00:00
|
|
|
cb.rcpFrame = GSVector4(1.0f / s.x, 1.0f / s.y, 0.0f, 0.0f);
|
|
|
|
cb.rcpFrameOpt = GSVector4::zero();
|
|
|
|
|
2016-05-28 17:13:35 +00:00
|
|
|
m_shaderfx.cb->cache_upload(&cb);
|
2014-11-09 14:27:24 +00:00
|
|
|
|
2015-05-15 18:49:25 +00:00
|
|
|
StretchRect(sTex, sRect, dTex, dRect, m_shaderfx.ps, true);
|
2014-11-09 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
2015-05-15 18:45:31 +00:00
|
|
|
void GSDeviceOGL::DoShadeBoost(GSTexture* sTex, GSTexture* dTex)
|
2012-04-26 21:42:16 +00:00
|
|
|
{
|
2015-05-06 16:52:51 +00:00
|
|
|
GL_PUSH("DoShadeBoost");
|
|
|
|
|
2015-05-15 10:52:03 +00:00
|
|
|
OMSetColorMaskState();
|
|
|
|
|
2015-05-15 18:43:57 +00:00
|
|
|
GSVector2i s = dTex->GetSize();
|
2012-04-26 21:42:16 +00:00
|
|
|
|
2015-05-15 18:47:14 +00:00
|
|
|
GSVector4 sRect(0, 0, 1, 1);
|
2015-05-15 18:49:25 +00:00
|
|
|
GSVector4 dRect(0, 0, s.x, s.y);
|
2012-04-26 21:42:16 +00:00
|
|
|
|
2015-05-15 18:49:25 +00:00
|
|
|
StretchRect(sTex, sRect, dTex, dRect, m_shadeboost.ps, true);
|
2012-04-26 21:42:16 +00:00
|
|
|
}
|
|
|
|
|
2014-10-01 19:46:20 +00:00
|
|
|
void GSDeviceOGL::SetupDATE(GSTexture* rt, GSTexture* ds, const GSVertexPT1* vertices, bool datm)
|
2011-12-19 21:03:23 +00:00
|
|
|
{
|
2015-05-06 16:52:51 +00:00
|
|
|
GL_PUSH("DATE First Pass");
|
|
|
|
|
2013-06-14 11:34:44 +00:00
|
|
|
// sfex3 (after the capcom logo), vf4 (first menu fading in), ffxii shadows, rumble roses shadows, persona4 shadows
|
2011-12-19 21:03:23 +00:00
|
|
|
|
2013-06-14 11:34:44 +00:00
|
|
|
BeginScene();
|
2011-12-19 21:03:23 +00:00
|
|
|
|
2013-06-14 11:34:44 +00:00
|
|
|
ClearStencil(ds, 0);
|
2011-12-19 21:03:23 +00:00
|
|
|
|
2016-04-10 15:28:05 +00:00
|
|
|
m_shader->BindPipeline(m_convert.ps[datm ? ShaderConvert_DATM_1 : ShaderConvert_DATM_0]);
|
2013-08-10 19:43:59 +00:00
|
|
|
|
2013-06-14 11:34:44 +00:00
|
|
|
// om
|
2011-12-19 21:03:23 +00:00
|
|
|
|
2015-08-01 09:35:21 +00:00
|
|
|
OMSetDepthStencilState(m_date.dss);
|
2015-07-31 18:28:54 +00:00
|
|
|
if (GLState::blend) {
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
2015-06-05 20:37:34 +00:00
|
|
|
OMSetRenderTargets(NULL, ds, &GLState::scissor);
|
2011-12-19 21:03:23 +00:00
|
|
|
|
2013-06-14 11:34:44 +00:00
|
|
|
// ia
|
2011-12-19 21:03:23 +00:00
|
|
|
|
2013-06-14 11:34:44 +00:00
|
|
|
IASetVertexBuffer(vertices, 4);
|
|
|
|
IASetPrimitiveTopology(GL_TRIANGLE_STRIP);
|
2011-12-19 21:03:23 +00:00
|
|
|
|
|
|
|
|
2013-08-10 19:43:59 +00:00
|
|
|
// Texture
|
2011-12-19 21:03:23 +00:00
|
|
|
|
2015-08-07 12:46:57 +00:00
|
|
|
PSSetShaderResource(0, rt);
|
|
|
|
PSSetSamplerState(m_convert.pt);
|
2011-12-19 21:03:23 +00:00
|
|
|
|
2014-09-30 20:12:56 +00:00
|
|
|
DrawPrimitive();
|
2011-12-19 21:03:23 +00:00
|
|
|
|
2015-07-31 18:28:54 +00:00
|
|
|
if (GLState::blend) {
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
}
|
|
|
|
|
2013-06-14 11:34:44 +00:00
|
|
|
EndScene();
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-15 18:27:58 +00:00
|
|
|
void GSDeviceOGL::EndScene()
|
2011-12-10 19:19:44 +00:00
|
|
|
{
|
2014-10-02 07:33:41 +00:00
|
|
|
m_va->EndScene();
|
2011-12-10 19:19:44 +00:00
|
|
|
}
|
|
|
|
|
2011-12-15 18:27:58 +00:00
|
|
|
void GSDeviceOGL::IASetVertexBuffer(const void* vertices, size_t count)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2014-10-02 07:33:41 +00:00
|
|
|
m_va->UploadVB(vertices, count);
|
2012-01-15 17:25:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::IASetIndexBuffer(const void* index, size_t count)
|
|
|
|
{
|
2014-10-02 07:33:41 +00:00
|
|
|
m_va->UploadIB(index, count);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::IASetPrimitiveTopology(GLenum topology)
|
|
|
|
{
|
2014-10-02 07:33:41 +00:00
|
|
|
m_va->SetTopology(topology);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
2015-05-21 07:48:15 +00:00
|
|
|
void GSDeviceOGL::PSSetShaderResource(int i, GSTexture* sr)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2015-07-24 18:00:25 +00:00
|
|
|
ASSERT(i < (int)countof(GLState::tex_unit));
|
2015-08-13 07:57:24 +00:00
|
|
|
// Note: Nvidia debgger doesn't support the id 0 (ie the NULL texture)
|
|
|
|
if (sr) {
|
2016-04-04 21:08:46 +00:00
|
|
|
GLuint id = static_cast<GSTextureOGL*>(sr)->GetID();
|
2015-08-13 07:57:24 +00:00
|
|
|
if (GLState::tex_unit[i] != id) {
|
|
|
|
GLState::tex_unit[i] = id;
|
2015-10-17 15:05:15 +00:00
|
|
|
glBindTextureUnit(i, id);
|
2015-08-13 07:57:24 +00:00
|
|
|
}
|
2013-08-02 16:38:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-24 17:34:17 +00:00
|
|
|
void GSDeviceOGL::PSSetShaderResources(GSTexture* sr0, GSTexture* sr1)
|
2013-08-02 16:38:12 +00:00
|
|
|
{
|
2015-04-24 17:34:17 +00:00
|
|
|
PSSetShaderResource(0, sr0);
|
|
|
|
PSSetShaderResource(1, sr1);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
2013-08-02 16:38:12 +00:00
|
|
|
void GSDeviceOGL::PSSetSamplerState(GLuint ss)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2013-08-05 20:25:25 +00:00
|
|
|
if (GLState::ps_ss != ss) {
|
|
|
|
GLState::ps_ss = ss;
|
2015-10-17 15:05:15 +00:00
|
|
|
glBindSampler(0, ss);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-12 16:18:04 +00:00
|
|
|
void GSDeviceOGL::OMAttachRt(GSTextureOGL* rt)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2015-05-12 16:18:04 +00:00
|
|
|
GLuint id;
|
|
|
|
if (rt) {
|
|
|
|
rt->WasAttached();
|
|
|
|
id = rt->GetID();
|
|
|
|
} else {
|
|
|
|
id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GLState::rt != id) {
|
|
|
|
GLState::rt = id;
|
2015-10-17 15:05:15 +00:00
|
|
|
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, id, 0);
|
2013-06-01 09:29:57 +00:00
|
|
|
}
|
2013-07-19 19:25:50 +00:00
|
|
|
}
|
|
|
|
|
2015-05-12 16:18:04 +00:00
|
|
|
void GSDeviceOGL::OMAttachDs(GSTextureOGL* ds)
|
2013-07-19 19:25:50 +00:00
|
|
|
{
|
2015-05-12 16:18:04 +00:00
|
|
|
GLuint id;
|
|
|
|
if (ds) {
|
|
|
|
ds->WasAttached();
|
|
|
|
id = ds->GetID();
|
|
|
|
} else {
|
|
|
|
id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GLState::ds != id) {
|
|
|
|
GLState::ds = id;
|
2015-10-17 15:05:15 +00:00
|
|
|
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, id, 0);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-19 19:25:50 +00:00
|
|
|
void GSDeviceOGL::OMSetFBO(GLuint fbo)
|
2011-12-08 11:17:59 +00:00
|
|
|
{
|
2013-08-05 20:25:25 +00:00
|
|
|
if (GLState::fbo != fbo) {
|
|
|
|
GLState::fbo = fbo;
|
2016-04-07 20:56:31 +00:00
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
|
2011-12-08 11:17:59 +00:00
|
|
|
}
|
2013-07-19 19:25:50 +00:00
|
|
|
}
|
2012-03-30 19:02:37 +00:00
|
|
|
|
2015-08-01 09:35:21 +00:00
|
|
|
void GSDeviceOGL::OMSetDepthStencilState(GSDepthStencilOGL* dss)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2015-07-31 18:28:54 +00:00
|
|
|
dss->SetupDepth();
|
|
|
|
dss->SetupStencil();
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 08:26:01 +00:00
|
|
|
void GSDeviceOGL::OMSetColorMaskState(OMColorMaskSelector sel)
|
|
|
|
{
|
|
|
|
if (sel.wrgba != GLState::wrgba) {
|
|
|
|
GLState::wrgba = sel.wrgba;
|
|
|
|
|
2015-10-17 15:05:15 +00:00
|
|
|
glColorMaski(0, sel.wr, sel.wg, sel.wb, sel.wa);
|
2015-05-05 08:26:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-11 11:01:42 +00:00
|
|
|
void GSDeviceOGL::OMSetBlendState(uint8 blend_index, uint8 blend_factor, bool is_blend_constant, bool accumulation_blend)
|
2015-07-31 17:42:01 +00:00
|
|
|
{
|
|
|
|
if (blend_index) {
|
|
|
|
if (!GLState::blend) {
|
|
|
|
GLState::blend = true;
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_blend_constant && GLState::bf != blend_factor) {
|
|
|
|
GLState::bf = blend_factor;
|
2015-08-07 10:13:50 +00:00
|
|
|
float bf = (float)blend_factor / 128.0f;
|
2015-10-18 09:16:54 +00:00
|
|
|
gl_BlendColor(bf, bf, bf, bf);
|
2015-07-31 17:42:01 +00:00
|
|
|
}
|
|
|
|
|
2016-06-11 11:01:42 +00:00
|
|
|
OGLBlend b = m_blendMapOGL[blend_index];
|
|
|
|
if (accumulation_blend) {
|
|
|
|
b.src = GL_ONE;
|
|
|
|
b.dst = GL_ONE;
|
|
|
|
}
|
2015-08-07 17:43:42 +00:00
|
|
|
|
|
|
|
if (GLState::eq_RGB != b.op) {
|
|
|
|
GLState::eq_RGB = b.op;
|
2016-05-14 15:15:30 +00:00
|
|
|
glBlendEquationSeparateiARB(0, b.op, GL_FUNC_ADD);
|
2015-07-31 17:42:01 +00:00
|
|
|
}
|
|
|
|
|
2015-08-07 17:43:42 +00:00
|
|
|
if (GLState::f_sRGB != b.src || GLState::f_dRGB != b.dst) {
|
|
|
|
GLState::f_sRGB = b.src;
|
|
|
|
GLState::f_dRGB = b.dst;
|
2016-06-01 18:59:39 +00:00
|
|
|
glBlendFuncSeparateiARB(0, b.src, b.dst, GL_ONE, GL_ZERO);
|
2015-07-31 17:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (GLState::blend) {
|
|
|
|
GLState::blend = false;
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-16 22:17:37 +00:00
|
|
|
void GSDeviceOGL::OMSetRenderTargets(GSTexture* rt, GSTexture* ds, const GSVector4i* scissor)
|
|
|
|
{
|
2015-05-12 16:18:04 +00:00
|
|
|
GSTextureOGL* RT = static_cast<GSTextureOGL*>(rt);
|
|
|
|
GSTextureOGL* DS = static_cast<GSTextureOGL*>(ds);
|
|
|
|
|
|
|
|
if (rt == NULL || !RT->IsBackbuffer()) {
|
2014-09-07 15:22:23 +00:00
|
|
|
OMSetFBO(m_fbo);
|
2013-06-14 11:34:44 +00:00
|
|
|
if (rt) {
|
2015-05-12 16:18:04 +00:00
|
|
|
OMAttachRt(RT);
|
2011-12-29 14:24:26 +00:00
|
|
|
} else {
|
2015-05-12 16:18:04 +00:00
|
|
|
OMAttachRt();
|
2011-12-29 14:24:26 +00:00
|
|
|
}
|
|
|
|
|
2013-06-14 11:34:44 +00:00
|
|
|
// Note: it must be done after OMSetFBO
|
|
|
|
if (ds)
|
2015-05-12 16:18:04 +00:00
|
|
|
OMAttachDs(DS);
|
2014-09-07 15:22:23 +00:00
|
|
|
else
|
2015-05-12 16:18:04 +00:00
|
|
|
OMAttachDs();
|
2013-06-14 11:34:44 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// Render in the backbuffer
|
|
|
|
OMSetFBO(0);
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2013-06-14 11:34:44 +00:00
|
|
|
|
2015-10-17 17:17:44 +00:00
|
|
|
GSVector2i size = rt ? rt->GetSize() : ds ? ds->GetSize() : GLState::viewport;
|
2013-08-05 20:25:25 +00:00
|
|
|
if(GLState::viewport != size)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2013-08-05 20:25:25 +00:00
|
|
|
GLState::viewport = size;
|
2015-08-07 12:04:54 +00:00
|
|
|
// FIXME ViewportIndexedf or ViewportIndexedfv (GL4.1)
|
2016-06-29 17:42:05 +00:00
|
|
|
glViewportIndexedf(0, 0, 0, GLfloat(size.x), GLfloat(size.y));
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
2013-06-14 11:34:44 +00:00
|
|
|
GSVector4i r = scissor ? *scissor : GSVector4i(size).zwxy();
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2013-08-05 20:25:25 +00:00
|
|
|
if(!GLState::scissor.eq(r))
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2013-08-05 20:25:25 +00:00
|
|
|
GLState::scissor = r;
|
2015-08-07 12:04:54 +00:00
|
|
|
// FIXME ScissorIndexedv (GL4.1)
|
2016-05-14 15:18:16 +00:00
|
|
|
glScissorIndexed(0, r.x, r.y, r.width(), r.height());
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
|
|
|
|
2016-04-24 08:53:12 +00:00
|
|
|
void GSDeviceOGL::SetupCB(const VSConstantBuffer* vs_cb, const PSConstantBuffer* ps_cb)
|
|
|
|
{
|
|
|
|
GL_PUSH("UBO");
|
|
|
|
if(m_vs_cb_cache.Update(vs_cb)) {
|
|
|
|
m_vs_cb->upload(vs_cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(m_ps_cb_cache.Update(ps_cb)) {
|
|
|
|
m_ps_cb->upload(ps_cb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-29 08:03:26 +00:00
|
|
|
void GSDeviceOGL::SetupCBMisc(const GSVector4i& channel)
|
|
|
|
{
|
|
|
|
m_misc_cb_cache.ChannelShuffle = channel;
|
|
|
|
m_convert.cb->cache_upload(&m_misc_cb_cache);
|
|
|
|
}
|
|
|
|
|
2016-04-24 08:53:12 +00:00
|
|
|
void GSDeviceOGL::SetupPipeline(const VSSelector& vsel, const GSSelector& gsel, const PSSelector& psel)
|
|
|
|
{
|
|
|
|
GLuint ps;
|
|
|
|
auto i = m_ps.find(psel);
|
|
|
|
|
|
|
|
if (i == m_ps.end()) {
|
|
|
|
ps = CompilePS(psel);
|
|
|
|
m_ps[psel] = ps;
|
|
|
|
} else {
|
|
|
|
ps = i->second;
|
|
|
|
}
|
|
|
|
|
2016-06-10 18:44:35 +00:00
|
|
|
{
|
|
|
|
#if defined(_DEBUG) && 0
|
|
|
|
// Toggling Shader is bad for the perf. Let's trace parameter that often toggle to detect
|
|
|
|
// potential uber shader possibilities.
|
|
|
|
static PSSelector old_psel;
|
|
|
|
static GLuint old_ps = 0;
|
|
|
|
std::string msg("");
|
|
|
|
#define CHECK_STATE(p) if (psel.p != old_psel.p) msg.append(" ").append(#p);
|
|
|
|
|
|
|
|
if (old_ps != ps) {
|
|
|
|
|
|
|
|
CHECK_STATE(tex_fmt);
|
|
|
|
CHECK_STATE(dfmt);
|
|
|
|
CHECK_STATE(depth_fmt);
|
|
|
|
CHECK_STATE(aem);
|
|
|
|
CHECK_STATE(fba);
|
|
|
|
CHECK_STATE(fog);
|
|
|
|
CHECK_STATE(iip);
|
|
|
|
CHECK_STATE(date);
|
|
|
|
CHECK_STATE(atst);
|
|
|
|
CHECK_STATE(fst);
|
|
|
|
CHECK_STATE(tfx);
|
|
|
|
CHECK_STATE(tcc);
|
|
|
|
CHECK_STATE(wms);
|
|
|
|
CHECK_STATE(wmt);
|
|
|
|
CHECK_STATE(ltf);
|
|
|
|
CHECK_STATE(shuffle);
|
|
|
|
CHECK_STATE(read_ba);
|
|
|
|
CHECK_STATE(write_rg);
|
|
|
|
CHECK_STATE(fbmask);
|
|
|
|
CHECK_STATE(blend_a);
|
|
|
|
CHECK_STATE(blend_b);
|
|
|
|
CHECK_STATE(blend_c);
|
|
|
|
CHECK_STATE(blend_d);
|
|
|
|
CHECK_STATE(clr1);
|
|
|
|
CHECK_STATE(pabe);
|
|
|
|
CHECK_STATE(hdr);
|
|
|
|
CHECK_STATE(colclip);
|
|
|
|
// CHECK_STATE(channel);
|
|
|
|
// CHECK_STATE(tcoffsethack);
|
|
|
|
// CHECK_STATE(urban_chaos_hle);
|
|
|
|
// CHECK_STATE(tales_of_abyss_hle);
|
|
|
|
GL_PERF("New PS :%s", msg.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
old_psel.key = psel.key;
|
|
|
|
old_ps = ps;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-06-01 18:58:10 +00:00
|
|
|
if (GLLoader::buggy_sso_dual_src)
|
|
|
|
m_shader->BindProgram(m_vs[vsel], m_gs[gsel], ps);
|
|
|
|
else
|
|
|
|
m_shader->BindPipeline(m_vs[vsel], m_gs[gsel], ps);
|
2016-04-24 08:53:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::SetupSampler(PSSamplerSelector ssel)
|
|
|
|
{
|
|
|
|
PSSetSamplerState(m_ps_ss[ssel]);
|
|
|
|
}
|
|
|
|
|
|
|
|
GLuint GSDeviceOGL::GetPaletteSamplerID()
|
|
|
|
{
|
|
|
|
return m_palette_ss;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::SetupOM(OMDepthStencilSelector dssel)
|
|
|
|
{
|
|
|
|
OMSetDepthStencilState(m_om_dss[dssel]);
|
|
|
|
}
|
|
|
|
|
2011-11-26 11:46:51 +00:00
|
|
|
void GSDeviceOGL::CheckDebugLog()
|
|
|
|
{
|
2015-05-07 21:20:01 +00:00
|
|
|
if (!m_debug_gl_call) return;
|
2015-05-07 21:06:43 +00:00
|
|
|
|
|
|
|
unsigned int count = 16; // max. num. of messages that will be read from the log
|
|
|
|
int bufsize = 2048;
|
|
|
|
unsigned int sources[16] = {};
|
|
|
|
unsigned int types[16] = {};
|
|
|
|
unsigned int ids[16] = {};
|
|
|
|
unsigned int severities[16] = {};
|
|
|
|
int lengths[16] = {};
|
|
|
|
char* messageLog = new char[bufsize];
|
|
|
|
|
2015-10-17 15:05:15 +00:00
|
|
|
unsigned int retVal = glGetDebugMessageLogARB(count, bufsize, sources, types, ids, severities, lengths, messageLog);
|
2015-05-07 21:06:43 +00:00
|
|
|
|
|
|
|
if(retVal > 0)
|
|
|
|
{
|
|
|
|
unsigned int pos = 0;
|
|
|
|
for(unsigned int i=0; i<retVal; i++)
|
|
|
|
{
|
|
|
|
DebugOutputToFile(sources[i], types[i], ids[i], severities[i], lengths[i], &messageLog[pos], NULL);
|
|
|
|
pos += lengths[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] messageLog;
|
2011-11-26 11:46:51 +00:00
|
|
|
}
|
|
|
|
|
2014-09-27 16:57:17 +00:00
|
|
|
// Note: used as a callback of DebugMessageCallback. Don't change the signature
|
|
|
|
void GSDeviceOGL::DebugOutputToFile(GLenum gl_source, GLenum gl_type, GLuint id, GLenum gl_severity, GLsizei gl_length, const GLchar *gl_message, const void* userParam)
|
2011-11-26 11:46:51 +00:00
|
|
|
{
|
2016-01-07 20:48:06 +00:00
|
|
|
std::string message(gl_message, gl_length >= 0 ? gl_length : strlen(gl_message));
|
2014-09-27 16:57:17 +00:00
|
|
|
std::string type, severity, source;
|
2012-02-11 10:22:02 +00:00
|
|
|
static int sev_counter = 0;
|
2014-09-27 16:57:17 +00:00
|
|
|
switch(gl_type) {
|
|
|
|
case GL_DEBUG_TYPE_ERROR_ARB : type = "Error"; break;
|
|
|
|
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB : type = "Deprecated bhv"; break;
|
|
|
|
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB : type = "Undefined bhv"; break;
|
|
|
|
case GL_DEBUG_TYPE_PORTABILITY_ARB : type = "Portability"; break;
|
|
|
|
case GL_DEBUG_TYPE_PERFORMANCE_ARB : type = "Perf"; break;
|
2016-04-20 07:52:46 +00:00
|
|
|
case GL_DEBUG_TYPE_OTHER_ARB : type = "Oth"; break;
|
2015-05-06 16:52:51 +00:00
|
|
|
case GL_DEBUG_TYPE_PUSH_GROUP : return; // Don't print message injected by myself
|
|
|
|
case GL_DEBUG_TYPE_POP_GROUP : return; // Don't print message injected by myself
|
2014-09-27 16:57:17 +00:00
|
|
|
default : type = "TTT"; break;
|
|
|
|
}
|
|
|
|
switch(gl_severity) {
|
|
|
|
case GL_DEBUG_SEVERITY_HIGH_ARB : severity = "High"; sev_counter++; break;
|
|
|
|
case GL_DEBUG_SEVERITY_MEDIUM_ARB : severity = "Mid"; break;
|
|
|
|
case GL_DEBUG_SEVERITY_LOW_ARB : severity = "Low"; break;
|
2016-10-04 17:01:27 +00:00
|
|
|
default : if (id == 0xFEAD)
|
|
|
|
severity = "Cache";
|
|
|
|
else if (id == 0xB0B0)
|
|
|
|
severity = "REG";
|
|
|
|
break;
|
2014-09-27 16:57:17 +00:00
|
|
|
}
|
|
|
|
switch(gl_source) {
|
|
|
|
case GL_DEBUG_SOURCE_API_ARB : source = "API"; break;
|
|
|
|
case GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB : source = "WINDOW"; break;
|
|
|
|
case GL_DEBUG_SOURCE_SHADER_COMPILER_ARB : source = "COMPILER"; break;
|
|
|
|
case GL_DEBUG_SOURCE_THIRD_PARTY_ARB : source = "3rdparty"; break;
|
|
|
|
case GL_DEBUG_SOURCE_APPLICATION_ARB : source = "Application"; break;
|
|
|
|
case GL_DEBUG_SOURCE_OTHER_ARB : source = "Others"; break;
|
|
|
|
default : source = "???"; break;
|
2012-02-11 10:22:02 +00:00
|
|
|
}
|
2011-12-08 11:17:59 +00:00
|
|
|
|
2016-06-10 20:01:48 +00:00
|
|
|
#ifdef _DEBUG
|
2015-05-15 13:12:49 +00:00
|
|
|
// Don't spam noisy information on the terminal
|
2015-07-10 19:30:42 +00:00
|
|
|
if (gl_severity != GL_DEBUG_SEVERITY_NOTIFICATION) {
|
2016-10-04 17:23:27 +00:00
|
|
|
fprintf(stderr,"T:%s\tID:%d\tS:%s\t=> %s\n", type.c_str(), GSState::s_n, severity.c_str(), message.c_str());
|
2015-05-15 13:12:49 +00:00
|
|
|
}
|
2016-06-10 20:01:48 +00:00
|
|
|
#else
|
|
|
|
// Print nouveau shader compiler info
|
2016-10-04 17:23:27 +00:00
|
|
|
if (GSState::s_n == 0) {
|
2016-06-10 20:01:48 +00:00
|
|
|
int t, local, gpr, inst, byte;
|
|
|
|
int status = sscanf(message.c_str(), "type: %d, local: %d, gpr: %d, inst: %d, bytes: %d",
|
|
|
|
&t, &local, &gpr, &inst, &byte);
|
|
|
|
if (status == 5) {
|
|
|
|
m_shader_inst += inst;
|
|
|
|
m_shader_reg += gpr;
|
|
|
|
fprintf(stderr,"T:%s\t\tS:%s\t=> %s\n", type.c_str(), severity.c_str(), message.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2011-12-08 11:17:59 +00:00
|
|
|
|
2015-05-17 12:43:56 +00:00
|
|
|
if (m_debug_gl_file)
|
2016-10-04 17:23:27 +00:00
|
|
|
fprintf(m_debug_gl_file,"T:%s\tID:%d\tS:%s\t=> %s\n", type.c_str(), GSState::s_n, severity.c_str(), message.c_str());
|
2015-05-17 12:43:56 +00:00
|
|
|
|
2015-09-28 07:41:30 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
if (sev_counter >= 5) {
|
|
|
|
// Close the file to flush the content on disk before exiting.
|
|
|
|
if (m_debug_gl_file) {
|
|
|
|
fclose(m_debug_gl_file);
|
|
|
|
m_debug_gl_file = NULL;
|
|
|
|
}
|
|
|
|
ASSERT(0);
|
|
|
|
}
|
|
|
|
#endif
|
2011-11-26 11:46:51 +00:00
|
|
|
}
|
2011-12-19 21:03:23 +00:00
|
|
|
|
|
|
|
// (A - B) * C + D
|
|
|
|
// A: Cs/Cd/0
|
|
|
|
// B: Cs/Cd/0
|
|
|
|
// C: As/Ad/FIX
|
|
|
|
// D: Cs/Cd/0
|
|
|
|
|
|
|
|
// bogus: 0100, 0110, 0120, 0200, 0210, 0220, 1001, 1011, 1021
|
|
|
|
// tricky: 1201, 1211, 1221
|
|
|
|
|
|
|
|
// Source.rgb = float3(1, 1, 1);
|
|
|
|
// 1201 Cd*(1 + As) => Source * Dest color + Dest * Source alpha
|
|
|
|
// 1211 Cd*(1 + Ad) => Source * Dest color + Dest * Dest alpha
|
|
|
|
// 1221 Cd*(1 + F) => Source * Dest color + Dest * Factor
|
|
|
|
|
2015-07-31 07:09:44 +00:00
|
|
|
// Special blending method table:
|
|
|
|
// # (tricky) => 1 * Cd + Cd * F => Use (Cd, F) as factor of color (1, Cd)
|
|
|
|
// * (bogus) => C * (1 + F ) + ... => factor is always bigger than 1 (except above case)
|
|
|
|
// ? => Cs * F + Cd => do the multiplication in shader and addition in blending unit. It is an optimization
|
|
|
|
|
2011-12-19 21:03:23 +00:00
|
|
|
// Copy Dx blend table and convert it to ogl
|
|
|
|
#define D3DBLENDOP_ADD GL_FUNC_ADD
|
|
|
|
#define D3DBLENDOP_SUBTRACT GL_FUNC_SUBTRACT
|
|
|
|
#define D3DBLENDOP_REVSUBTRACT GL_FUNC_REVERSE_SUBTRACT
|
|
|
|
|
|
|
|
#define D3DBLEND_ONE GL_ONE
|
|
|
|
#define D3DBLEND_ZERO GL_ZERO
|
|
|
|
#define D3DBLEND_INVDESTALPHA GL_ONE_MINUS_DST_ALPHA
|
|
|
|
#define D3DBLEND_DESTALPHA GL_DST_ALPHA
|
|
|
|
#define D3DBLEND_DESTCOLOR GL_DST_COLOR
|
|
|
|
#define D3DBLEND_BLENDFACTOR GL_CONSTANT_COLOR
|
|
|
|
#define D3DBLEND_INVBLENDFACTOR GL_ONE_MINUS_CONSTANT_COLOR
|
2012-01-03 16:12:34 +00:00
|
|
|
|
2012-05-11 19:39:32 +00:00
|
|
|
#define D3DBLEND_SRCALPHA GL_SRC1_ALPHA
|
|
|
|
#define D3DBLEND_INVSRCALPHA GL_ONE_MINUS_SRC1_ALPHA
|
2014-09-07 15:22:23 +00:00
|
|
|
|
2015-07-31 18:28:54 +00:00
|
|
|
const int GSDeviceOGL::m_NO_BLEND = 0;
|
|
|
|
const int GSDeviceOGL::m_MERGE_BLEND = 3*3*3*3;
|
2015-07-31 07:09:44 +00:00
|
|
|
|
2015-08-07 17:43:42 +00:00
|
|
|
const GSDeviceOGL::OGLBlend GSDeviceOGL::m_blendMapOGL[3*3*3*3 + 1] =
|
2011-12-19 21:03:23 +00:00
|
|
|
{
|
2015-07-31 07:09:44 +00:00
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_ADD , D3DBLEND_ONE , D3DBLEND_ZERO} , // 0000: (Cs - Cs)*As + Cs ==> Cs
|
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_ONE} , // 0001: (Cs - Cs)*As + Cd ==> Cd
|
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_ZERO} , // 0002: (Cs - Cs)*As + 0 ==> 0
|
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_ADD , D3DBLEND_ONE , D3DBLEND_ZERO} , // 0010: (Cs - Cs)*Ad + Cs ==> Cs
|
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_ONE} , // 0011: (Cs - Cs)*Ad + Cd ==> Cd
|
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_ZERO} , // 0012: (Cs - Cs)*Ad + 0 ==> 0
|
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_ADD , D3DBLEND_ONE , D3DBLEND_ZERO} , // 0020: (Cs - Cs)*F + Cs ==> Cs
|
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_ONE} , // 0021: (Cs - Cs)*F + Cd ==> Cd
|
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_ZERO} , // 0022: (Cs - Cs)*F + 0 ==> 0
|
2015-07-31 07:24:10 +00:00
|
|
|
{ BLEND_A_MAX , D3DBLENDOP_SUBTRACT , D3DBLEND_ONE , D3DBLEND_SRCALPHA} , //*0100: (Cs - Cd)*As + Cs ==> Cs*(As + 1) - Cd*As
|
2015-07-31 07:09:44 +00:00
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_SRCALPHA , D3DBLEND_INVSRCALPHA} , // 0101: (Cs - Cd)*As + Cd ==> Cs*As + Cd*(1 - As)
|
|
|
|
{ 0 , D3DBLENDOP_SUBTRACT , D3DBLEND_SRCALPHA , D3DBLEND_SRCALPHA} , // 0102: (Cs - Cd)*As + 0 ==> Cs*As - Cd*As
|
2015-07-31 07:24:10 +00:00
|
|
|
{ BLEND_A_MAX , D3DBLENDOP_SUBTRACT , D3DBLEND_ONE , D3DBLEND_DESTALPHA} , //*0110: (Cs - Cd)*Ad + Cs ==> Cs*(Ad + 1) - Cd*Ad
|
2015-07-31 07:09:44 +00:00
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_DESTALPHA , D3DBLEND_INVDESTALPHA} , // 0111: (Cs - Cd)*Ad + Cd ==> Cs*Ad + Cd*(1 - Ad)
|
|
|
|
{ 0 , D3DBLENDOP_SUBTRACT , D3DBLEND_DESTALPHA , D3DBLEND_DESTALPHA} , // 0112: (Cs - Cd)*Ad + 0 ==> Cs*Ad - Cd*Ad
|
2015-07-31 07:24:10 +00:00
|
|
|
{ BLEND_A_MAX , D3DBLENDOP_SUBTRACT , D3DBLEND_ONE , D3DBLEND_BLENDFACTOR} , //*0120: (Cs - Cd)*F + Cs ==> Cs*(F + 1) - Cd*F
|
2015-07-31 07:09:44 +00:00
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_BLENDFACTOR , D3DBLEND_INVBLENDFACTOR} , // 0121: (Cs - Cd)*F + Cd ==> Cs*F + Cd*(1 - F)
|
|
|
|
{ 0 , D3DBLENDOP_SUBTRACT , D3DBLEND_BLENDFACTOR , D3DBLEND_BLENDFACTOR} , // 0122: (Cs - Cd)*F + 0 ==> Cs*F - Cd*F
|
2015-07-31 07:24:10 +00:00
|
|
|
{ BLEND_NO_BAR | BLEND_A_MAX , D3DBLENDOP_ADD , D3DBLEND_ONE , D3DBLEND_ZERO} , //*0200: (Cs - 0)*As + Cs ==> Cs*(As + 1)
|
2016-06-11 11:01:42 +00:00
|
|
|
{ BLEND_ACCU , D3DBLENDOP_ADD , D3DBLEND_SRCALPHA , D3DBLEND_ONE} , //?0201: (Cs - 0)*As + Cd ==> Cs*As + Cd
|
2015-07-31 07:09:44 +00:00
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_ADD , D3DBLEND_SRCALPHA , D3DBLEND_ZERO} , // 0202: (Cs - 0)*As + 0 ==> Cs*As
|
2015-07-31 07:24:10 +00:00
|
|
|
{ BLEND_A_MAX , D3DBLENDOP_ADD , D3DBLEND_ONE , D3DBLEND_ZERO} , //*0210: (Cs - 0)*Ad + Cs ==> Cs*(Ad + 1)
|
2015-07-31 07:09:44 +00:00
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_DESTALPHA , D3DBLEND_ONE} , // 0211: (Cs - 0)*Ad + Cd ==> Cs*Ad + Cd
|
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_DESTALPHA , D3DBLEND_ZERO} , // 0212: (Cs - 0)*Ad + 0 ==> Cs*Ad
|
2015-07-31 07:24:10 +00:00
|
|
|
{ BLEND_NO_BAR | BLEND_A_MAX , D3DBLENDOP_ADD , D3DBLEND_ONE , D3DBLEND_ZERO} , //*0220: (Cs - 0)*F + Cs ==> Cs*(F + 1)
|
2016-06-11 11:01:42 +00:00
|
|
|
{ BLEND_ACCU , D3DBLENDOP_ADD , D3DBLEND_BLENDFACTOR , D3DBLEND_ONE} , //?0221: (Cs - 0)*F + Cd ==> Cs*F + Cd
|
2015-07-31 07:09:44 +00:00
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_ADD , D3DBLEND_BLENDFACTOR , D3DBLEND_ZERO} , // 0222: (Cs - 0)*F + 0 ==> Cs*F
|
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_INVSRCALPHA , D3DBLEND_SRCALPHA} , // 1000: (Cd - Cs)*As + Cs ==> Cd*As + Cs*(1 - As)
|
2015-07-31 07:24:10 +00:00
|
|
|
{ BLEND_A_MAX , D3DBLENDOP_REVSUBTRACT , D3DBLEND_SRCALPHA , D3DBLEND_ONE} , //*1001: (Cd - Cs)*As + Cd ==> Cd*(As + 1) - Cs*As
|
2015-07-31 07:09:44 +00:00
|
|
|
{ 0 , D3DBLENDOP_REVSUBTRACT , D3DBLEND_SRCALPHA , D3DBLEND_SRCALPHA} , // 1002: (Cd - Cs)*As + 0 ==> Cd*As - Cs*As
|
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_INVDESTALPHA , D3DBLEND_DESTALPHA} , // 1010: (Cd - Cs)*Ad + Cs ==> Cd*Ad + Cs*(1 - Ad)
|
2015-07-31 07:24:10 +00:00
|
|
|
{ BLEND_A_MAX , D3DBLENDOP_REVSUBTRACT , D3DBLEND_DESTALPHA , D3DBLEND_ONE} , //*1011: (Cd - Cs)*Ad + Cd ==> Cd*(Ad + 1) - Cs*Ad
|
2015-07-31 07:09:44 +00:00
|
|
|
{ 0 , D3DBLENDOP_REVSUBTRACT , D3DBLEND_DESTALPHA , D3DBLEND_DESTALPHA} , // 1012: (Cd - Cs)*Ad + 0 ==> Cd*Ad - Cs*Ad
|
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_INVBLENDFACTOR , D3DBLEND_BLENDFACTOR} , // 1020: (Cd - Cs)*F + Cs ==> Cd*F + Cs*(1 - F)
|
2015-07-31 07:24:10 +00:00
|
|
|
{ BLEND_A_MAX , D3DBLENDOP_REVSUBTRACT , D3DBLEND_BLENDFACTOR , D3DBLEND_ONE} , //*1021: (Cd - Cs)*F + Cd ==> Cd*(F + 1) - Cs*F
|
2015-07-31 07:09:44 +00:00
|
|
|
{ 0 , D3DBLENDOP_REVSUBTRACT , D3DBLEND_BLENDFACTOR , D3DBLEND_BLENDFACTOR} , // 1022: (Cd - Cs)*F + 0 ==> Cd*F - Cs*F
|
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_ADD , D3DBLEND_ONE , D3DBLEND_ZERO} , // 1100: (Cd - Cd)*As + Cs ==> Cs
|
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_ONE} , // 1101: (Cd - Cd)*As + Cd ==> Cd
|
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_ZERO} , // 1102: (Cd - Cd)*As + 0 ==> 0
|
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_ADD , D3DBLEND_ONE , D3DBLEND_ZERO} , // 1110: (Cd - Cd)*Ad + Cs ==> Cs
|
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_ONE} , // 1111: (Cd - Cd)*Ad + Cd ==> Cd
|
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_ZERO} , // 1112: (Cd - Cd)*Ad + 0 ==> 0
|
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_ADD , D3DBLEND_ONE , D3DBLEND_ZERO} , // 1120: (Cd - Cd)*F + Cs ==> Cs
|
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_ONE} , // 1121: (Cd - Cd)*F + Cd ==> Cd
|
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_ZERO} , // 1122: (Cd - Cd)*F + 0 ==> 0
|
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_ONE , D3DBLEND_SRCALPHA} , // 1200: (Cd - 0)*As + Cs ==> Cs + Cd*As
|
|
|
|
{ BLEND_C_CLR , D3DBLENDOP_ADD , D3DBLEND_DESTCOLOR , D3DBLEND_SRCALPHA} , //#1201: (Cd - 0)*As + Cd ==> Cd*(1 + As) // ffxii main menu background
|
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_SRCALPHA} , // 1202: (Cd - 0)*As + 0 ==> Cd*As
|
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_ONE , D3DBLEND_DESTALPHA} , // 1210: (Cd - 0)*Ad + Cs ==> Cs + Cd*Ad
|
|
|
|
{ BLEND_C_CLR , D3DBLENDOP_ADD , D3DBLEND_DESTCOLOR , D3DBLEND_DESTALPHA} , //#1211: (Cd - 0)*Ad + Cd ==> Cd*(1 + Ad)
|
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_DESTALPHA} , // 1212: (Cd - 0)*Ad + 0 ==> Cd*Ad
|
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_ONE , D3DBLEND_BLENDFACTOR} , // 1220: (Cd - 0)*F + Cs ==> Cs + Cd*F
|
|
|
|
{ BLEND_C_CLR , D3DBLENDOP_ADD , D3DBLEND_DESTCOLOR , D3DBLEND_BLENDFACTOR} , //#1221: (Cd - 0)*F + Cd ==> Cd*(1 + F)
|
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_BLENDFACTOR} , // 1222: (Cd - 0)*F + 0 ==> Cd*F
|
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_ADD , D3DBLEND_INVSRCALPHA , D3DBLEND_ZERO} , // 2000: (0 - Cs)*As + Cs ==> Cs*(1 - As)
|
2016-07-29 17:46:36 +00:00
|
|
|
{ BLEND_ACCU , D3DBLENDOP_REVSUBTRACT , D3DBLEND_SRCALPHA , D3DBLEND_ONE} , // 2001: (0 - Cs)*As + Cd ==> Cd - Cs*As
|
2015-07-31 07:09:44 +00:00
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_REVSUBTRACT , D3DBLEND_SRCALPHA , D3DBLEND_ZERO} , // 2002: (0 - Cs)*As + 0 ==> 0 - Cs*As
|
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_INVDESTALPHA , D3DBLEND_ZERO} , // 2010: (0 - Cs)*Ad + Cs ==> Cs*(1 - Ad)
|
|
|
|
{ 0 , D3DBLENDOP_REVSUBTRACT , D3DBLEND_DESTALPHA , D3DBLEND_ONE} , // 2011: (0 - Cs)*Ad + Cd ==> Cd - Cs*Ad
|
|
|
|
{ 0 , D3DBLENDOP_REVSUBTRACT , D3DBLEND_DESTALPHA , D3DBLEND_ZERO} , // 2012: (0 - Cs)*Ad + 0 ==> 0 - Cs*Ad
|
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_ADD , D3DBLEND_INVBLENDFACTOR , D3DBLEND_ZERO} , // 2020: (0 - Cs)*F + Cs ==> Cs*(1 - F)
|
2016-07-29 17:46:36 +00:00
|
|
|
{ BLEND_ACCU , D3DBLENDOP_REVSUBTRACT , D3DBLEND_BLENDFACTOR , D3DBLEND_ONE} , // 2021: (0 - Cs)*F + Cd ==> Cd - Cs*F
|
2015-07-31 07:09:44 +00:00
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_REVSUBTRACT , D3DBLEND_BLENDFACTOR , D3DBLEND_ZERO} , // 2022: (0 - Cs)*F + 0 ==> 0 - Cs*F
|
|
|
|
{ 0 , D3DBLENDOP_SUBTRACT , D3DBLEND_ONE , D3DBLEND_SRCALPHA} , // 2100: (0 - Cd)*As + Cs ==> Cs - Cd*As
|
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_INVSRCALPHA} , // 2101: (0 - Cd)*As + Cd ==> Cd*(1 - As)
|
|
|
|
{ 0 , D3DBLENDOP_SUBTRACT , D3DBLEND_ZERO , D3DBLEND_SRCALPHA} , // 2102: (0 - Cd)*As + 0 ==> 0 - Cd*As
|
|
|
|
{ 0 , D3DBLENDOP_SUBTRACT , D3DBLEND_ONE , D3DBLEND_DESTALPHA} , // 2110: (0 - Cd)*Ad + Cs ==> Cs - Cd*Ad
|
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_INVDESTALPHA} , // 2111: (0 - Cd)*Ad + Cd ==> Cd*(1 - Ad)
|
|
|
|
{ 0 , D3DBLENDOP_SUBTRACT , D3DBLEND_ONE , D3DBLEND_DESTALPHA} , // 2112: (0 - Cd)*Ad + 0 ==> 0 - Cd*Ad
|
|
|
|
{ 0 , D3DBLENDOP_SUBTRACT , D3DBLEND_ONE , D3DBLEND_BLENDFACTOR} , // 2120: (0 - Cd)*F + Cs ==> Cs - Cd*F
|
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_INVBLENDFACTOR} , // 2121: (0 - Cd)*F + Cd ==> Cd*(1 - F)
|
|
|
|
{ 0 , D3DBLENDOP_SUBTRACT , D3DBLEND_ONE , D3DBLEND_BLENDFACTOR} , // 2122: (0 - Cd)*F + 0 ==> 0 - Cd*F
|
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_ADD , D3DBLEND_ONE , D3DBLEND_ZERO} , // 2200: (0 - 0)*As + Cs ==> Cs
|
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_ONE} , // 2201: (0 - 0)*As + Cd ==> Cd
|
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_ZERO} , // 2202: (0 - 0)*As + 0 ==> 0
|
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_ADD , D3DBLEND_ONE , D3DBLEND_ZERO} , // 2210: (0 - 0)*Ad + Cs ==> Cs
|
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_ONE} , // 2211: (0 - 0)*Ad + Cd ==> Cd
|
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_ZERO} , // 2212: (0 - 0)*Ad + 0 ==> 0
|
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_ADD , D3DBLEND_ONE , D3DBLEND_ZERO} , // 2220: (0 - 0)*F + Cs ==> Cs
|
|
|
|
{ 0 , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_ONE} , // 2221: (0 - 0)*F + Cd ==> Cd
|
|
|
|
{ BLEND_NO_BAR , D3DBLENDOP_ADD , D3DBLEND_ZERO , D3DBLEND_ZERO} , // 2222: (0 - 0)*F + 0 ==> 0
|
2015-07-31 18:28:54 +00:00
|
|
|
{ 0 , D3DBLENDOP_ADD , GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA} , // extra for merge operation
|
2011-12-19 21:03:23 +00:00
|
|
|
};
|