2011-11-16 22:17:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011-2011 Gregory hainaut
|
|
|
|
* Copyright (C) 2007-2009 Gabest
|
|
|
|
*
|
|
|
|
* This Program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This Program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Make; see the file COPYING. If not, write to
|
2012-09-09 18:16:11 +00:00
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
|
2011-11-16 22:17:37 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-01-10 13:13:59 +00:00
|
|
|
#include "stdafx.h"
|
2011-11-16 22:17:37 +00:00
|
|
|
#include "GSDeviceOGL.h"
|
|
|
|
|
2013-05-18 09:17:30 +00:00
|
|
|
#include "res/convert.h"
|
|
|
|
#include "res/interlace.h"
|
|
|
|
#include "res/merge.h"
|
|
|
|
#include "res/shadeboost.h"
|
|
|
|
|
2012-03-05 20:16:26 +00:00
|
|
|
// TODO performance cost to investigate
|
|
|
|
// Texture attachment/glDrawBuffer. For the moment it set every draw and potentially multiple time (first time in clear, second time in rendering)
|
|
|
|
// Attachment 1 is only used with the GL_16UI format
|
|
|
|
|
2012-01-12 07:29:31 +00:00
|
|
|
//#define LOUD_DEBUGGING
|
2012-01-04 23:19:17 +00:00
|
|
|
//#define PRINT_FRAME_NUMBER
|
|
|
|
//#define ONLY_LINES
|
2011-12-29 14:24:26 +00:00
|
|
|
|
|
|
|
static uint32 g_draw_count = 0;
|
2012-01-12 07:29:31 +00:00
|
|
|
static uint32 g_frame_count = 1;
|
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;
|
|
|
|
static const uint32 g_shadeboost_cb_index = 12;
|
|
|
|
static const uint32 g_fxaa_cb_index = 13;
|
2011-12-29 14:24:26 +00:00
|
|
|
|
2011-11-16 22:17:37 +00:00
|
|
|
GSDeviceOGL::GSDeviceOGL()
|
2011-11-21 22:36:03 +00:00
|
|
|
: m_free_window(false)
|
|
|
|
, m_window(NULL)
|
2011-12-11 19:09:08 +00:00
|
|
|
, m_pipeline(0)
|
2011-12-10 19:19:44 +00:00
|
|
|
, m_fbo(0)
|
2012-01-08 21:59:42 +00:00
|
|
|
, m_fbo_read(0)
|
2011-12-15 18:27:58 +00:00
|
|
|
, m_vb_sr(NULL)
|
2011-11-21 22:36:03 +00:00
|
|
|
, m_srv_changed(false)
|
|
|
|
, m_ss_changed(false)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2012-04-26 21:42:16 +00:00
|
|
|
m_msaa = !!theApp.GetConfig("UserHacks", 0) ? theApp.GetConfig("UserHacks_MSAA", 0) : 0;
|
2011-12-07 22:05:46 +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));
|
|
|
|
memset(&m_date, 0, sizeof(m_date));
|
|
|
|
memset(&m_state, 0, sizeof(m_state));
|
2012-01-31 17:08:05 +00:00
|
|
|
|
|
|
|
// Reset the debug file
|
2013-01-16 18:25:53 +00:00
|
|
|
#ifdef ENABLE_OGL_DEBUG
|
2012-01-31 17:08:05 +00:00
|
|
|
FILE* f = fopen("Debug.txt","w");
|
|
|
|
fclose(f);
|
2012-05-11 20:52:50 +00:00
|
|
|
#endif
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
2011-11-21 22:36:03 +00:00
|
|
|
GSDeviceOGL::~GSDeviceOGL()
|
|
|
|
{
|
2011-12-15 18:27:58 +00:00
|
|
|
// Clean vertex buffer state
|
|
|
|
delete (m_vb_sr);
|
|
|
|
|
2012-01-08 21:59:42 +00:00
|
|
|
// Clean m_merge_obj
|
2013-01-10 13:13:59 +00:00
|
|
|
for (uint32 i = 0; i < 2; i++)
|
2013-05-19 12:42:55 +00:00
|
|
|
if (GLLoader::found_GL_ARB_separate_shader_objects)
|
|
|
|
gl_DeleteProgram(m_merge_obj.ps[i]);
|
|
|
|
else
|
|
|
|
gl_DeleteShader(m_merge_obj.ps[i]);
|
2012-01-08 21:59:42 +00:00
|
|
|
delete (m_merge_obj.cb);
|
|
|
|
delete (m_merge_obj.bs);
|
2011-11-26 11:46:51 +00:00
|
|
|
|
|
|
|
// Clean m_interlace
|
2013-01-10 13:13:59 +00:00
|
|
|
for (uint32 i = 0; i < 2; i++)
|
2013-05-19 12:42:55 +00:00
|
|
|
if (GLLoader::found_GL_ARB_separate_shader_objects)
|
|
|
|
gl_DeleteProgram(m_interlace.ps[i]);
|
|
|
|
else
|
|
|
|
gl_DeleteShader(m_interlace.ps[i]);
|
2011-11-26 11:46:51 +00:00
|
|
|
delete (m_interlace.cb);
|
|
|
|
|
|
|
|
// Clean m_convert
|
2013-05-19 12:42:55 +00:00
|
|
|
if (GLLoader::found_GL_ARB_separate_shader_objects) {
|
|
|
|
gl_DeleteProgram(m_convert.vs);
|
|
|
|
for (uint32 i = 0; i < 2; i++)
|
|
|
|
gl_DeleteProgram(m_convert.ps[i]);
|
|
|
|
} else {
|
|
|
|
gl_DeleteShader(m_convert.vs);
|
|
|
|
for (uint i = 0; i < 2; i++)
|
|
|
|
gl_DeleteShader(m_convert.ps[i]);
|
|
|
|
}
|
2013-05-19 09:19:20 +00:00
|
|
|
gl_DeleteSamplers(1, &m_convert.ln);
|
|
|
|
gl_DeleteSamplers(1, &m_convert.pt);
|
2011-11-26 11:46:51 +00:00
|
|
|
delete m_convert.dss;
|
|
|
|
delete m_convert.bs;
|
|
|
|
|
|
|
|
// Clean m_date
|
|
|
|
delete m_date.dss;
|
|
|
|
delete m_date.bs;
|
|
|
|
|
|
|
|
// Clean various opengl allocation
|
2013-05-19 12:42:55 +00:00
|
|
|
if (GLLoader::found_GL_ARB_separate_shader_objects)
|
|
|
|
gl_DeleteProgramPipelines(1, &m_pipeline);
|
2013-05-19 09:19:20 +00:00
|
|
|
gl_DeleteFramebuffers(1, &m_fbo);
|
|
|
|
gl_DeleteFramebuffers(1, &m_fbo_read);
|
2011-12-21 19:08:31 +00:00
|
|
|
|
|
|
|
// Delete HW FX
|
|
|
|
delete m_vs_cb;
|
|
|
|
delete m_ps_cb;
|
2013-05-19 09:19:20 +00:00
|
|
|
gl_DeleteSamplers(1, &m_rt_ss);
|
2011-12-21 19:08:31 +00:00
|
|
|
delete m_vb;
|
|
|
|
|
2013-05-19 12:42:55 +00:00
|
|
|
if (GLLoader::found_GL_ARB_separate_shader_objects) {
|
|
|
|
for (auto it = m_vs.begin(); it != m_vs.end() ; it++) gl_DeleteProgram(it->second);
|
|
|
|
for (auto it = m_gs.begin(); it != m_gs.end() ; it++) gl_DeleteProgram(it->second);
|
|
|
|
for (auto it = m_ps.begin(); it != m_ps.end() ; it++) gl_DeleteProgram(it->second);
|
|
|
|
} else {
|
|
|
|
for (auto it = m_vs.begin(); it != m_vs.end() ; it++) gl_DeleteShader(it->second);
|
|
|
|
for (auto it = m_gs.begin(); it != m_gs.end() ; it++) gl_DeleteShader(it->second);
|
|
|
|
for (auto it = m_ps.begin(); it != m_ps.end() ; it++) gl_DeleteShader(it->second);
|
|
|
|
|
|
|
|
for (auto it = m_single_prog.begin(); it != m_single_prog.end() ; it++) gl_DeleteProgram(it->second);
|
|
|
|
m_single_prog.clear();
|
|
|
|
}
|
2013-05-17 20:14:10 +00:00
|
|
|
|
2013-05-19 09:19:20 +00:00
|
|
|
for (auto it = m_ps_ss.begin(); it != m_ps_ss.end() ; it++) gl_DeleteSamplers(1, &it->second);
|
2011-12-21 19:08:31 +00:00
|
|
|
m_vs.clear();
|
|
|
|
m_gs.clear();
|
|
|
|
m_ps.clear();
|
|
|
|
m_ps_ss.clear();
|
|
|
|
m_om_dss.clear();
|
|
|
|
m_om_bs.clear();
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
2011-11-16 22:17:37 +00:00
|
|
|
|
|
|
|
GSTexture* GSDeviceOGL::CreateSurface(int type, int w, int h, bool msaa, int format)
|
|
|
|
{
|
|
|
|
// A wrapper to call GSTextureOGL, with the different kind of parameter
|
2011-11-21 22:36:03 +00:00
|
|
|
GSTextureOGL* t = NULL;
|
2012-01-08 21:59:42 +00:00
|
|
|
t = new GSTextureOGL(type, w, h, msaa, format, m_fbo_read);
|
2011-11-21 22:36:03 +00:00
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case GSTexture::RenderTarget:
|
|
|
|
ClearRenderTarget(t, 0);
|
|
|
|
break;
|
|
|
|
case GSTexture::DepthStencil:
|
|
|
|
ClearDepth(t, 0);
|
|
|
|
//FIXME might be need to clear the stencil too
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return t;
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GSTexture* GSDeviceOGL::FetchSurface(int type, int w, int h, bool msaa, int format)
|
|
|
|
{
|
|
|
|
// FIXME: keep DX code. Do not know how work msaa but not important for the moment
|
2011-11-21 22:36:03 +00:00
|
|
|
// Current config give only 0 or 1
|
2011-11-16 22:17:37 +00:00
|
|
|
#if 0
|
|
|
|
if(m_msaa < 2) {
|
|
|
|
msaa = false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
msaa = false;
|
|
|
|
|
|
|
|
return GSDevice::FetchSurface(type, w, h, msaa, format);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GSDeviceOGL::Create(GSWnd* wnd)
|
|
|
|
{
|
2011-11-21 22:36:03 +00:00
|
|
|
if (m_window == NULL) {
|
2013-01-14 09:15:39 +00:00
|
|
|
GLLoader::init_gl_function();
|
2011-12-21 23:09:36 +00:00
|
|
|
|
2013-01-14 09:15:39 +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-11-26 11:46:51 +00:00
|
|
|
// FIXME disable it when code is ready
|
2012-10-29 21:35:47 +00:00
|
|
|
// glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
|
2011-12-08 16:39:14 +00:00
|
|
|
|
|
|
|
m_window = wnd;
|
2011-11-26 11:46:51 +00:00
|
|
|
|
2011-11-21 22:36:03 +00:00
|
|
|
// ****************************************************************
|
|
|
|
// Various object
|
|
|
|
// ****************************************************************
|
2013-05-19 12:42:55 +00:00
|
|
|
if (GLLoader::found_GL_ARB_separate_shader_objects) {
|
|
|
|
gl_GenProgramPipelines(1, &m_pipeline);
|
|
|
|
gl_BindProgramPipeline(m_pipeline);
|
|
|
|
}
|
2011-11-21 22:36:03 +00:00
|
|
|
|
2013-05-19 09:19:20 +00:00
|
|
|
gl_GenFramebuffers(1, &m_fbo);
|
|
|
|
gl_GenFramebuffers(1, &m_fbo_read);
|
2011-12-10 19:19:44 +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
|
|
|
// ****************************************************************
|
2011-12-31 14:38:58 +00:00
|
|
|
GSInputLayoutOGL il_convert[2] =
|
2011-11-21 22:36:03 +00:00
|
|
|
{
|
2011-12-19 21:03:23 +00:00
|
|
|
{0, 4, GL_FLOAT, GL_FALSE, sizeof(GSVertexPT1), (const GLvoid*)offsetof(struct GSVertexPT1, p) },
|
|
|
|
{1, 2, GL_FLOAT, GL_FALSE, sizeof(GSVertexPT1), (const GLvoid*)offsetof(struct GSVertexPT1, t) },
|
2011-11-21 22:36:03 +00:00
|
|
|
};
|
2011-12-31 14:38:58 +00:00
|
|
|
m_vb_sr = new GSVertexBufferStateOGL(sizeof(GSVertexPT1), il_convert, countof(il_convert));
|
2011-11-21 22:36:03 +00:00
|
|
|
|
2011-12-15 18:27:58 +00:00
|
|
|
// ****************************************************************
|
|
|
|
// convert
|
|
|
|
// ****************************************************************
|
2013-05-18 09:17:30 +00:00
|
|
|
CompileShaderFromSource("convert.glsl", "vs_main", GL_VERTEX_SHADER, &m_convert.vs, convert_glsl);
|
|
|
|
CompileShaderFromSource("convert.glsl", "gs_main", GL_GEOMETRY_SHADER, &m_convert.gs, convert_glsl);
|
2013-01-10 13:13:59 +00:00
|
|
|
for(uint32 i = 0; i < countof(m_convert.ps); i++)
|
2013-05-18 09:17:30 +00:00
|
|
|
CompileShaderFromSource("convert.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, &m_convert.ps[i], convert_glsl);
|
2011-11-21 22:36:03 +00:00
|
|
|
|
|
|
|
// Note the following object are initialized to 0 so disabled.
|
|
|
|
// Note: maybe enable blend with a factor of 1
|
|
|
|
// m_convert.dss, m_convert.bs
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
memset(&dsd, 0, sizeof(dsd));
|
|
|
|
|
|
|
|
dsd.DepthEnable = false;
|
|
|
|
dsd.StencilEnable = false;
|
|
|
|
|
|
|
|
hr = m_dev->CreateDepthStencilState(&dsd, &m_convert.dss);
|
|
|
|
|
|
|
|
memset(&bsd, 0, sizeof(bsd));
|
|
|
|
|
|
|
|
bsd.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
|
|
|
|
|
|
|
|
hr = m_dev->CreateBlendState(&bsd, &m_convert.bs);
|
|
|
|
#endif
|
2013-05-19 09:19:20 +00:00
|
|
|
gl_GenSamplers(1, &m_convert.ln);
|
|
|
|
gl_SamplerParameteri(m_convert.ln, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
gl_SamplerParameteri(m_convert.ln, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
gl_SamplerParameteri(m_convert.ln, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
|
|
|
gl_SamplerParameteri(m_convert.ln, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
gl_SamplerParameteri(m_convert.ln, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2011-11-21 22:36:03 +00:00
|
|
|
// FIXME which value for GL_TEXTURE_MIN_LOD
|
2013-05-19 09:19:20 +00:00
|
|
|
gl_SamplerParameterf(m_convert.ln, GL_TEXTURE_MAX_LOD, FLT_MAX);
|
2011-11-21 22:36:03 +00:00
|
|
|
// FIXME: seems there is 2 possibility in opengl
|
|
|
|
// DX: sd.ComparisonFunc = D3D11_COMPARISON_NEVER;
|
2013-05-19 09:19:20 +00:00
|
|
|
// gl_SamplerParameteri(m_convert.ln, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
|
|
|
gl_SamplerParameteri(m_convert.ln, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
|
|
|
gl_SamplerParameteri(m_convert.ln, GL_TEXTURE_COMPARE_FUNC, GL_NEVER);
|
2011-12-19 21:03:23 +00:00
|
|
|
// FIXME: need ogl extension sd.MaxAnisotropy = 16;
|
2011-11-21 22:36:03 +00:00
|
|
|
|
|
|
|
|
2013-05-19 09:19:20 +00:00
|
|
|
gl_GenSamplers(1, &m_convert.pt);
|
|
|
|
gl_SamplerParameteri(m_convert.pt, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
gl_SamplerParameteri(m_convert.pt, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
gl_SamplerParameteri(m_convert.pt, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
|
|
|
gl_SamplerParameteri(m_convert.pt, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
gl_SamplerParameteri(m_convert.pt, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2011-11-21 22:36:03 +00:00
|
|
|
// FIXME which value for GL_TEXTURE_MIN_LOD
|
2013-05-19 09:19:20 +00:00
|
|
|
gl_SamplerParameterf(m_convert.pt, GL_TEXTURE_MAX_LOD, FLT_MAX);
|
2011-11-21 22:36:03 +00:00
|
|
|
// FIXME: seems there is 2 possibility in opengl
|
|
|
|
// DX: sd.ComparisonFunc = D3D11_COMPARISON_NEVER;
|
2013-05-19 09:19:20 +00:00
|
|
|
// gl_SamplerParameteri(m_convert.pt, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
|
|
|
gl_SamplerParameteri(m_convert.pt, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
|
|
|
gl_SamplerParameteri(m_convert.pt, GL_TEXTURE_COMPARE_FUNC, GL_NEVER);
|
2011-12-19 21:03:23 +00:00
|
|
|
// FIXME: need ogl extension sd.MaxAnisotropy = 16;
|
2011-11-21 22:36:03 +00:00
|
|
|
|
2011-11-26 11:46:51 +00:00
|
|
|
m_convert.dss = new GSDepthStencilOGL();
|
|
|
|
m_convert.bs = new GSBlendStateOGL();
|
|
|
|
|
2011-11-21 22:36:03 +00:00
|
|
|
// ****************************************************************
|
|
|
|
// merge
|
|
|
|
// ****************************************************************
|
2013-04-19 19:16:26 +00:00
|
|
|
m_merge_obj.cb = new GSUniformBufferOGL(g_merge_cb_index, sizeof(MergeConstantBuffer));
|
2011-11-21 22:36:03 +00:00
|
|
|
|
2013-01-10 13:13:59 +00:00
|
|
|
for(uint32 i = 0; i < countof(m_merge_obj.ps); i++)
|
2013-05-18 09:17:30 +00:00
|
|
|
CompileShaderFromSource("merge.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, &m_merge_obj.ps[i], merge_glsl);
|
2011-11-21 22:36:03 +00:00
|
|
|
|
2012-01-08 21:59:42 +00:00
|
|
|
m_merge_obj.bs = new GSBlendStateOGL();
|
|
|
|
m_merge_obj.bs->EnableBlend();
|
|
|
|
m_merge_obj.bs->SetRGB(GL_FUNC_ADD, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2011-11-21 22:36:03 +00:00
|
|
|
|
|
|
|
// ****************************************************************
|
|
|
|
// interlace
|
|
|
|
// ****************************************************************
|
2013-04-19 19:16:26 +00:00
|
|
|
m_interlace.cb = new GSUniformBufferOGL(g_interlace_cb_index, sizeof(InterlaceConstantBuffer));
|
2011-11-21 22:36:03 +00:00
|
|
|
|
2013-01-10 13:13:59 +00:00
|
|
|
for(uint32 i = 0; i < countof(m_interlace.ps); i++)
|
2013-05-18 09:17:30 +00:00
|
|
|
CompileShaderFromSource("interlace.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, &m_interlace.ps[i], interlace_glsl);
|
2012-04-26 21:42:16 +00:00
|
|
|
// ****************************************************************
|
|
|
|
// Shade boost
|
|
|
|
// ****************************************************************
|
2013-04-19 19:16:26 +00:00
|
|
|
m_shadeboost.cb = new GSUniformBufferOGL(g_shadeboost_cb_index, sizeof(ShadeBoostConstantBuffer));
|
2012-04-26 21:42:16 +00:00
|
|
|
|
|
|
|
int ShadeBoost_Contrast = theApp.GetConfig("ShadeBoost_Contrast", 50);
|
|
|
|
int ShadeBoost_Brightness = theApp.GetConfig("ShadeBoost_Brightness", 50);
|
|
|
|
int ShadeBoost_Saturation = theApp.GetConfig("ShadeBoost_Saturation", 50);
|
|
|
|
std::string macro = format("#define SB_SATURATION %d\n", ShadeBoost_Saturation)
|
|
|
|
+ format("#define SB_BRIGHTNESS %d\n", ShadeBoost_Brightness)
|
|
|
|
+ format("#define SB_CONTRAST %d\n", ShadeBoost_Contrast);
|
|
|
|
|
2013-05-18 09:17:30 +00:00
|
|
|
CompileShaderFromSource("shadeboost.glsl", "ps_main", GL_FRAGMENT_SHADER, &m_shadeboost.ps, shadeboost_glsl, macro);
|
2011-11-21 22:36:03 +00:00
|
|
|
|
|
|
|
// ****************************************************************
|
|
|
|
// rasterization configuration
|
|
|
|
// ****************************************************************
|
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
// FIXME enable it when multisample code will be here
|
|
|
|
// DX: rd.MultisampleEnable = true;
|
|
|
|
glDisable(GL_MULTISAMPLE);
|
2012-01-04 23:19:17 +00:00
|
|
|
#ifdef ONLY_LINES
|
|
|
|
glLineWidth(5.0);
|
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
|
|
|
#endif
|
2011-11-21 22:36:03 +00:00
|
|
|
// Hum I don't know for those options but let's hope there are not activated
|
|
|
|
#if 0
|
|
|
|
rd.FrontCounterClockwise = false;
|
|
|
|
rd.DepthBias = false;
|
|
|
|
rd.DepthBiasClamp = 0;
|
|
|
|
rd.SlopeScaledDepthBias = 0;
|
|
|
|
rd.DepthClipEnable = false; // ???
|
|
|
|
rd.AntialiasedLineEnable = false;
|
|
|
|
#endif
|
|
|
|
|
2011-12-21 19:08:31 +00:00
|
|
|
// TODO Later
|
|
|
|
// ****************************************************************
|
|
|
|
// fxaa (bonus)
|
|
|
|
// ****************************************************************
|
|
|
|
// FIXME need to define FXAA_GLSL_130 for the shader
|
|
|
|
// FIXME need to manually set the index...
|
|
|
|
// FIXME need dofxaa interface too
|
2013-04-19 19:16:26 +00:00
|
|
|
// m_fxaa.cb = new GSUniformBufferOGL(g_fxaa_cb_index, sizeof(FXAAConstantBuffer));
|
2013-05-18 09:17:30 +00:00
|
|
|
//CompileShaderFromSource("fxaa.fx", format("ps_main", i), GL_FRAGMENT_SHADER, &m_fxaa.ps, fxaa_glsl);
|
2011-12-21 19:08:31 +00:00
|
|
|
|
|
|
|
// ****************************************************************
|
|
|
|
// date
|
|
|
|
// ****************************************************************
|
|
|
|
|
|
|
|
m_date.dss = new GSDepthStencilOGL();
|
2012-01-03 13:11:40 +00:00
|
|
|
m_date.dss->EnableStencil();
|
|
|
|
m_date.dss->SetStencil(GL_ALWAYS, GL_REPLACE);
|
2011-12-21 19:08:31 +00:00
|
|
|
//memset(&dsd, 0, sizeof(dsd));
|
|
|
|
|
|
|
|
//dsd.DepthEnable = false;
|
|
|
|
//dsd.StencilEnable = true;
|
|
|
|
//dsd.StencilReadMask = 1;
|
|
|
|
//dsd.StencilWriteMask = 1;
|
|
|
|
|
|
|
|
//dsd.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
|
|
|
|
//dsd.FrontFace.StencilPassOp = D3D11_STENCIL_OP_REPLACE;
|
|
|
|
//dsd.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
|
|
|
|
//dsd.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
|
|
|
|
|
|
|
|
//m_dev->CreateDepthStencilState(&dsd, &m_date.dss);
|
|
|
|
|
|
|
|
// FIXME are the blend state really empty
|
|
|
|
m_date.bs = new GSBlendStateOGL();
|
|
|
|
//D3D11_BLEND_DESC blend;
|
|
|
|
|
|
|
|
//memset(&blend, 0, sizeof(blend));
|
|
|
|
|
|
|
|
//m_dev->CreateBlendState(&blend, &m_date.bs);
|
|
|
|
|
|
|
|
// ****************************************************************
|
|
|
|
// HW renderer shader
|
|
|
|
// ****************************************************************
|
|
|
|
CreateTextureFX();
|
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);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
HRESULT hr = E_FAIL;
|
|
|
|
|
|
|
|
DXGI_SWAP_CHAIN_DESC scd;
|
|
|
|
D3D11_BUFFER_DESC bd;
|
|
|
|
D3D11_SAMPLER_DESC sd;
|
|
|
|
D3D11_DEPTH_STENCIL_DESC dsd;
|
|
|
|
D3D11_RASTERIZER_DESC rd;
|
|
|
|
D3D11_BLEND_DESC bsd;
|
|
|
|
|
|
|
|
memset(&scd, 0, sizeof(scd));
|
|
|
|
|
|
|
|
scd.BufferCount = 2;
|
|
|
|
scd.BufferDesc.Width = 1;
|
|
|
|
scd.BufferDesc.Height = 1;
|
|
|
|
scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
|
|
//scd.BufferDesc.RefreshRate.Numerator = 60;
|
|
|
|
//scd.BufferDesc.RefreshRate.Denominator = 1;
|
|
|
|
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
|
|
|
scd.OutputWindow = (HWND)m_wnd->GetHandle();
|
|
|
|
scd.SampleDesc.Count = 1;
|
|
|
|
scd.SampleDesc.Quality = 0;
|
|
|
|
|
|
|
|
// Always start in Windowed mode. According to MS, DXGI just "prefers" this, and it's more or less
|
|
|
|
// required if we want to add support for dual displays later on. The fullscreen/exclusive flip
|
|
|
|
// will be issued after all other initializations are complete.
|
|
|
|
|
|
|
|
scd.Windowed = TRUE;
|
|
|
|
|
|
|
|
// NOTE : D3D11_CREATE_DEVICE_SINGLETHREADED
|
|
|
|
// This flag is safe as long as the DXGI's internal message pump is disabled or is on the
|
|
|
|
// same thread as the GS window (which the emulator makes sure of, if it utilizes a
|
|
|
|
// multithreaded GS). Setting the flag is a nice and easy 5% speedup on GS-intensive scenes.
|
|
|
|
|
|
|
|
uint32 flags = D3D11_CREATE_DEVICE_SINGLETHREADED;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
flags |= D3D11_CREATE_DEVICE_DEBUG;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
D3D_FEATURE_LEVEL level;
|
|
|
|
|
|
|
|
const D3D_FEATURE_LEVEL levels[] =
|
|
|
|
{
|
|
|
|
D3D_FEATURE_LEVEL_11_0,
|
|
|
|
D3D_FEATURE_LEVEL_10_1,
|
|
|
|
D3D_FEATURE_LEVEL_10_0,
|
|
|
|
};
|
|
|
|
|
|
|
|
hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, levels, countof(levels), D3D11_SDK_VERSION, &scd, &m_swapchain, &m_dev, &level, &m_ctx);
|
|
|
|
// hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, flags, NULL, 0, D3D11_SDK_VERSION, &scd, &m_swapchain, &m_dev, &level, &m_ctx);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ****************************************************************
|
|
|
|
// The check of capability is done when context is created on openGL
|
|
|
|
// For the moment don't bother with extension, I just ask the most recent openGL version
|
|
|
|
// ****************************************************************
|
|
|
|
#if 0
|
|
|
|
if(FAILED(hr)) return false;
|
|
|
|
|
|
|
|
if(!SetFeatureLevel(level, true))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS options;
|
|
|
|
|
|
|
|
hr = m_dev->CheckFeatureSupport(D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &options, sizeof(D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS));
|
|
|
|
|
|
|
|
// msaa
|
|
|
|
|
|
|
|
for(uint32 i = 2; i <= D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; i++)
|
|
|
|
{
|
|
|
|
uint32 quality[2] = {0, 0};
|
|
|
|
|
|
|
|
if(SUCCEEDED(m_dev->CheckMultisampleQualityLevels(DXGI_FORMAT_R8G8B8A8_UNORM, i, &quality[0])) && quality[0] > 0
|
|
|
|
&& SUCCEEDED(m_dev->CheckMultisampleQualityLevels(DXGI_FORMAT_D32_FLOAT_S8X24_UINT, i, &quality[1])) && quality[1] > 0)
|
|
|
|
{
|
|
|
|
m_msaa_desc.Count = i;
|
|
|
|
m_msaa_desc.Quality = std::min<uint32>(quality[0] - 1, quality[1] - 1);
|
|
|
|
|
|
|
|
if(i >= m_msaa) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(m_msaa_desc.Count == 1)
|
|
|
|
{
|
|
|
|
m_msaa = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-12-21 19:08:31 +00:00
|
|
|
return true;
|
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;
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
// 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
|
2012-01-08 21:59:42 +00:00
|
|
|
m_backbuffer = new GSTextureOGL(GSTextureOGL::Backbuffer, w, h, false, 0, m_fbo_read);
|
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()
|
|
|
|
{
|
2011-11-26 11:46:51 +00:00
|
|
|
// FIXME: disable it when code is working
|
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();
|
2012-03-30 19:02:37 +00:00
|
|
|
|
2012-01-04 23:19:17 +00:00
|
|
|
#ifdef PRINT_FRAME_NUMBER
|
|
|
|
fprintf(stderr, "Draw %d (Frame %d)\n", g_draw_count, g_frame_count);
|
|
|
|
#endif
|
2013-05-18 16:09:09 +00:00
|
|
|
#if defined(ENABLE_OGL_DEBUG) || defined(PRINT_FRAME_NUMBER)
|
2013-05-18 09:17:30 +00:00
|
|
|
g_frame_count++;
|
2011-12-29 14:24:26 +00:00
|
|
|
#endif
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
|
|
|
|
2012-03-30 19:02:37 +00:00
|
|
|
void GSDeviceOGL::DebugBB()
|
|
|
|
{
|
|
|
|
bool dump_me = false;
|
|
|
|
uint32 start = theApp.GetConfig("debug_ogl_dump", 0);
|
|
|
|
uint32 length = theApp.GetConfig("debug_ogl_dump_length", 5);
|
|
|
|
if ( (start != 0 && g_frame_count >= start && g_frame_count < (start + length)) ) dump_me = true;
|
|
|
|
|
|
|
|
if (!dump_me) return;
|
|
|
|
|
|
|
|
GLuint fbo_old = m_state.fbo;
|
|
|
|
OMSetFBO(m_fbo);
|
|
|
|
|
|
|
|
GSVector2i size = m_backbuffer->GetSize();
|
|
|
|
GSTexture* rt = CreateRenderTarget(size.x, size.y, false);
|
|
|
|
|
|
|
|
static_cast<GSTextureOGL*>(rt)->Attach(GL_COLOR_ATTACHMENT0);
|
|
|
|
|
2013-05-19 09:19:20 +00:00
|
|
|
gl_BlitFramebuffer(0, 0, size.x, size.y,
|
2012-03-30 19:02:37 +00:00
|
|
|
0, 0, size.x, size.y,
|
|
|
|
GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
|
|
|
|
|
|
|
rt->Save(format("/tmp/out_f%d__d%d__bb.bmp", g_frame_count, g_draw_count));
|
|
|
|
|
|
|
|
delete rt;
|
|
|
|
OMSetFBO(fbo_old);
|
|
|
|
}
|
|
|
|
|
2012-01-15 17:25:49 +00:00
|
|
|
void GSDeviceOGL::DebugInput()
|
2011-11-21 22:36:03 +00:00
|
|
|
{
|
2011-12-30 13:55:33 +00:00
|
|
|
bool dump_me = false;
|
2012-01-12 07:29:31 +00:00
|
|
|
uint32 start = theApp.GetConfig("debug_ogl_dump", 0);
|
|
|
|
uint32 length = theApp.GetConfig("debug_ogl_dump_length", 5);
|
|
|
|
if ( (start != 0 && g_frame_count >= start && g_frame_count < (start + length)) ) dump_me = true;
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2012-03-30 19:02:37 +00:00
|
|
|
if (!dump_me) return;
|
|
|
|
|
|
|
|
for (auto i = 0 ; i < 3 ; i++) {
|
|
|
|
if (m_state.ps_srv[i] != NULL) {
|
|
|
|
m_state.ps_srv[i]->Save(format("/tmp/in_f%d__d%d__%d.bmp", g_frame_count, g_draw_count, i));
|
2011-12-29 14:24:26 +00:00
|
|
|
}
|
2011-12-30 13:55:33 +00:00
|
|
|
}
|
2012-03-30 19:02:37 +00:00
|
|
|
//if (m_state.rtv != NULL) m_state.rtv->Save(format("/tmp/target_f%d__d%d__tex.bmp", g_frame_count, g_draw_count));
|
|
|
|
//if (m_state.dsv != NULL) m_state.dsv->Save(format("/tmp/ds_in_%d.bmp", g_draw_count));
|
|
|
|
|
|
|
|
fprintf(stderr, "Draw %d (Frame %d)\n", g_draw_count, g_frame_count);
|
|
|
|
fprintf(stderr, "vs: %d ; gs: %d ; ps: %d\n", m_state.vs, m_state.gs, m_state.ps);
|
|
|
|
m_state.vb->debug();
|
|
|
|
m_state.bs->debug();
|
|
|
|
m_state.dss->debug();
|
2012-01-15 17:25:49 +00:00
|
|
|
}
|
2011-12-30 13:55:33 +00:00
|
|
|
|
2012-01-15 17:25:49 +00:00
|
|
|
void GSDeviceOGL::DebugOutput()
|
|
|
|
{
|
2012-03-05 20:16:26 +00:00
|
|
|
CheckDebugLog();
|
|
|
|
|
2012-01-15 17:25:49 +00:00
|
|
|
bool dump_me = false;
|
|
|
|
uint32 start = theApp.GetConfig("debug_ogl_dump", 0);
|
|
|
|
uint32 length = theApp.GetConfig("debug_ogl_dump_length", 5);
|
|
|
|
if ( (start != 0 && g_frame_count >= start && g_frame_count < (start + length)) ) dump_me = true;
|
2011-12-30 13:55:33 +00:00
|
|
|
|
2012-03-30 19:02:37 +00:00
|
|
|
if (!dump_me) return;
|
2011-12-29 14:24:26 +00:00
|
|
|
|
2012-03-30 19:02:37 +00:00
|
|
|
if (m_state.rtv == m_backbuffer) {
|
|
|
|
m_state.rtv->Save(format("/tmp/out_f%d__d%d__back.bmp", g_frame_count, g_draw_count));
|
|
|
|
} else {
|
|
|
|
if (m_state.rtv != NULL) m_state.rtv->Save(format("/tmp/out_f%d__d%d__tex.bmp", g_frame_count, g_draw_count));
|
2011-12-29 14:24:26 +00:00
|
|
|
}
|
2012-08-08 17:49:23 +00:00
|
|
|
if (m_state.dsv != NULL) m_state.dsv->Save(format("/tmp/ds_out_%d.bmp", g_draw_count));
|
2012-03-30 19:02:37 +00:00
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
//DebugBB();
|
2012-01-15 17:25:49 +00:00
|
|
|
}
|
2011-12-29 14:24:26 +00:00
|
|
|
|
2013-04-19 19:16:26 +00:00
|
|
|
static void set_uniform_buffer_binding(GLuint prog, GLchar* name, GLuint binding) {
|
|
|
|
GLuint index;
|
2013-05-19 12:42:55 +00:00
|
|
|
index = gl_GetUniformBlockIndex(prog, name);
|
2013-04-19 19:16:26 +00:00
|
|
|
if (index != GL_INVALID_INDEX) {
|
2013-05-19 12:42:55 +00:00
|
|
|
gl_UniformBlockBinding(prog, index, binding);
|
2013-04-19 19:16:26 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2013-05-17 18:28:51 +00:00
|
|
|
GLuint GSDeviceOGL::link_prog()
|
|
|
|
{
|
2013-05-19 09:19:20 +00:00
|
|
|
GLuint single_prog = gl_CreateProgram();
|
|
|
|
if (m_state.vs) gl_AttachShader(single_prog, m_state.vs);
|
|
|
|
if (m_state.ps) gl_AttachShader(single_prog, m_state.ps);
|
|
|
|
if (m_state.gs) gl_AttachShader(single_prog, m_state.gs);
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2013-05-19 09:19:20 +00:00
|
|
|
gl_LinkProgram(single_prog);
|
2013-05-17 18:28:51 +00:00
|
|
|
|
|
|
|
GLint status;
|
2013-05-19 09:19:20 +00:00
|
|
|
gl_GetProgramiv(single_prog, GL_LINK_STATUS, &status);
|
2013-05-17 18:28:51 +00:00
|
|
|
if (!status) {
|
|
|
|
GLint log_length = 0;
|
2013-05-19 09:19:20 +00:00
|
|
|
gl_GetProgramiv(single_prog, GL_INFO_LOG_LENGTH, &log_length);
|
2013-05-17 18:28:51 +00:00
|
|
|
if (log_length > 0) {
|
|
|
|
char* log = new char[log_length];
|
2013-05-19 09:19:20 +00:00
|
|
|
gl_GetProgramInfoLog(single_prog, log_length, NULL, log);
|
2013-05-17 18:28:51 +00:00
|
|
|
fprintf(stderr, "%s", log);
|
|
|
|
delete[] log;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
2013-05-17 20:14:10 +00:00
|
|
|
#if 0
|
2013-05-19 09:19:20 +00:00
|
|
|
if (m_state.vs) gl_DetachShader(single_prog, m_state.vs);
|
|
|
|
if (m_state.ps) gl_DetachShader(single_prog, m_state.ps);
|
|
|
|
if (m_state.gs) gl_DetachShader(single_prog, m_state.gs);
|
2012-01-15 17:25:49 +00:00
|
|
|
#endif
|
2013-05-17 18:28:51 +00:00
|
|
|
|
|
|
|
return single_prog;
|
2012-01-15 17:25:49 +00:00
|
|
|
}
|
|
|
|
|
2013-04-19 19:16:26 +00:00
|
|
|
void GSDeviceOGL::BeforeDraw()
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2013-01-16 18:25:53 +00:00
|
|
|
#ifdef ENABLE_OGL_DEBUG
|
2012-01-15 17:25:49 +00:00
|
|
|
DebugInput();
|
|
|
|
#endif
|
|
|
|
|
2013-05-19 12:42:55 +00:00
|
|
|
if (!GLLoader::found_GL_ARB_separate_shader_objects) {
|
|
|
|
// Note: shader are integer lookup pointer. They start from 1 and incr
|
|
|
|
// every time you create a new shader OR a new program.
|
|
|
|
uint64 sel = (uint64)m_state.vs << 40 | (uint64)m_state.gs << 20 | m_state.ps;
|
|
|
|
auto single_prog = m_single_prog.find(sel);
|
|
|
|
if (single_prog == m_single_prog.end()) {
|
|
|
|
m_single_prog[sel] = link_prog();
|
|
|
|
single_prog = m_single_prog.find(sel);
|
|
|
|
}
|
2013-05-17 18:28:51 +00:00
|
|
|
|
2013-05-19 12:42:55 +00:00
|
|
|
gl_UseProgram(single_prog->second);
|
|
|
|
}
|
2013-05-17 18:28:51 +00:00
|
|
|
|
2013-05-19 12:42:55 +00:00
|
|
|
if (!GLLoader::found_GL_ARB_shading_language_420pack) {
|
|
|
|
set_uniform_buffer_binding(m_state.vs, "cb20", 20);
|
|
|
|
set_uniform_buffer_binding(m_state.ps, "cb21", 21);
|
2013-04-19 19:16:26 +00:00
|
|
|
|
2013-05-19 12:42:55 +00:00
|
|
|
set_uniform_buffer_binding(m_state.ps, "cb10", 10);
|
|
|
|
set_uniform_buffer_binding(m_state.ps, "cb11", 11);
|
|
|
|
set_uniform_buffer_binding(m_state.ps, "cb12", 12);
|
|
|
|
set_uniform_buffer_binding(m_state.ps, "cb13", 13);
|
|
|
|
}
|
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()
|
|
|
|
{
|
2013-01-16 18:25:53 +00:00
|
|
|
#ifdef ENABLE_OGL_DEBUG
|
2012-01-15 17:25:49 +00:00
|
|
|
DebugOutput();
|
2013-05-18 09:17:30 +00:00
|
|
|
#endif
|
2013-05-18 16:09:09 +00:00
|
|
|
#if defined(ENABLE_OGL_DEBUG) || defined(PRINT_FRAME_NUMBER)
|
2011-12-29 14:24:26 +00:00
|
|
|
g_draw_count++;
|
|
|
|
#endif
|
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();
|
|
|
|
m_state.vb->DrawPrimitive();
|
|
|
|
AfterDraw();
|
|
|
|
}
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2013-04-19 19:16:26 +00:00
|
|
|
void GSDeviceOGL::DrawIndexedPrimitive()
|
|
|
|
{
|
|
|
|
BeforeDraw();
|
2012-01-15 17:25:49 +00:00
|
|
|
m_state.vb->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)
|
|
|
|
{
|
|
|
|
ASSERT(offset + count <= m_index.count);
|
|
|
|
|
2013-04-19 19:16:26 +00:00
|
|
|
BeforeDraw();
|
2012-02-11 10:22:02 +00:00
|
|
|
m_state.vb->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)
|
|
|
|
{
|
2011-12-30 13:55:33 +00:00
|
|
|
GLuint fbo_old = m_state.fbo;
|
2011-12-21 23:09:36 +00:00
|
|
|
if (static_cast<GSTextureOGL*>(t)->IsBackbuffer()) {
|
2011-12-08 11:17:59 +00:00
|
|
|
// FIXME I really not sure
|
|
|
|
OMSetFBO(0);
|
2013-05-19 09:19:20 +00:00
|
|
|
//gl_ClearBufferfv(GL_COLOR, GL_LEFT, c.v);
|
|
|
|
gl_ClearBufferfv(GL_COLOR, 0, c.v);
|
2011-12-21 19:08:31 +00:00
|
|
|
// code for the old interface
|
|
|
|
// glClearColor(c.x, c.y, c.z, c.w);
|
|
|
|
// glClear(GL_COLOR_BUFFER_BIT);
|
2011-12-07 22:05:46 +00:00
|
|
|
} else {
|
2012-02-11 10:22:02 +00:00
|
|
|
// FIXME1 I need to clarify this FBO attachment stuff
|
2011-12-07 22:05:46 +00:00
|
|
|
// I would like to avoid FBO for a basic clean operation
|
2011-12-08 11:17:59 +00:00
|
|
|
OMSetFBO(m_fbo);
|
2011-12-21 23:09:36 +00:00
|
|
|
static_cast<GSTextureOGL*>(t)->Attach(GL_COLOR_ATTACHMENT0);
|
2013-05-19 09:19:20 +00:00
|
|
|
gl_ClearBufferfv(GL_COLOR, 0, c.v);
|
2011-12-07 22:05:46 +00:00
|
|
|
}
|
2011-12-30 13:55:33 +00:00
|
|
|
OMSetFBO(fbo_old);
|
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)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::ClearDepth(GSTexture* t, float c)
|
|
|
|
{
|
2011-12-30 13:55:33 +00:00
|
|
|
GLuint fbo_old = m_state.fbo;
|
2011-12-23 12:32:40 +00:00
|
|
|
// FIXME I need to clarify this FBO attachment stuff
|
|
|
|
// I would like to avoid FBO for a basic clean operation
|
|
|
|
OMSetFBO(m_fbo);
|
|
|
|
static_cast<GSTextureOGL*>(t)->Attach(GL_DEPTH_STENCIL_ATTACHMENT);
|
|
|
|
// FIXME can you clean depth and stencil separately
|
2012-08-08 17:49:23 +00:00
|
|
|
// XXX: glClear* depends on the scissor test!!! Disable it because the viewport
|
|
|
|
// could be smaller than the texture and we really want to clean all pixels.
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
if (m_state.dss != NULL && m_state.dss->IsMaskEnable()) {
|
2013-05-19 09:19:20 +00:00
|
|
|
gl_ClearBufferfv(GL_DEPTH, 0, &c);
|
2012-08-08 17:49:23 +00:00
|
|
|
} else {
|
|
|
|
glDepthMask(true);
|
2013-05-19 09:19:20 +00:00
|
|
|
gl_ClearBufferfv(GL_DEPTH, 0, &c);
|
2012-08-08 17:49:23 +00:00
|
|
|
glDepthMask(false);
|
|
|
|
}
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
2011-12-30 13:55:33 +00:00
|
|
|
OMSetFBO(fbo_old);
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::ClearStencil(GSTexture* t, uint8 c)
|
|
|
|
{
|
2011-12-30 13:55:33 +00:00
|
|
|
GLuint fbo_old = m_state.fbo;
|
2011-12-23 12:32:40 +00:00
|
|
|
// FIXME I need to clarify this FBO attachment stuff
|
|
|
|
// I would like to avoid FBO for a basic clean operation
|
|
|
|
OMSetFBO(m_fbo);
|
|
|
|
static_cast<GSTextureOGL*>(t)->Attach(GL_DEPTH_STENCIL_ATTACHMENT);
|
2011-11-21 22:36:03 +00:00
|
|
|
GLint color = c;
|
2011-12-23 12:32:40 +00:00
|
|
|
// FIXME can you clean depth and stencil separately
|
2013-05-19 09:19:20 +00:00
|
|
|
gl_ClearBufferiv(GL_STENCIL, 0, &color);
|
2011-12-30 13:55:33 +00:00
|
|
|
OMSetFBO(fbo_old);
|
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
|
|
|
|
GSTexture* GSDeviceOGL::CopyOffscreen(GSTexture* src, const GSVector4& sr, int w, int h, int format)
|
|
|
|
{
|
|
|
|
GSTexture* dst = NULL;
|
|
|
|
|
2011-12-23 12:32:40 +00:00
|
|
|
if(format == 0) format = GL_RGBA8;
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2011-12-23 12:32:40 +00:00
|
|
|
if(format != GL_RGBA8 && format != GL_R16UI)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
|
|
|
ASSERT(0);
|
|
|
|
|
2013-04-19 19:16:26 +00:00
|
|
|
return NULL;
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
2012-03-05 20:16:26 +00:00
|
|
|
// FIXME: It is possible to bypass completely offscreen-buffer on opengl but it needs some re-thinking of the code.
|
|
|
|
// For the moment mimic dx11
|
2011-12-23 12:32:40 +00:00
|
|
|
GSTexture* rt = CreateRenderTarget(w, h, false, format);
|
|
|
|
if(rt)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
|
|
|
GSVector4 dr(0, 0, w, h);
|
|
|
|
|
|
|
|
if(GSTexture* src2 = src->IsMSAA() ? Resolve(src) : src)
|
|
|
|
{
|
2011-12-23 12:32:40 +00:00
|
|
|
StretchRect(src2, sr, rt, dr, m_convert.ps[format == GL_R16UI ? 1 : 0]);
|
2011-11-16 22:17:37 +00:00
|
|
|
|
|
|
|
if(src2 != src) Recycle(src2);
|
|
|
|
}
|
|
|
|
|
2012-03-05 20:16:26 +00:00
|
|
|
|
|
|
|
GSVector4i dor(0, 0, w, h);
|
2011-11-16 22:17:37 +00:00
|
|
|
dst = CreateOffscreen(w, h, format);
|
|
|
|
|
2012-03-05 20:16:26 +00:00
|
|
|
if (dst) CopyRect(rt, dst, dor);
|
|
|
|
#if 0
|
2011-11-16 22:17:37 +00:00
|
|
|
if(dst)
|
|
|
|
{
|
|
|
|
m_ctx->CopyResource(*(GSTexture11*)dst, *(GSTexture11*)rt);
|
|
|
|
}
|
2011-12-23 12:32:40 +00:00
|
|
|
#endif
|
2011-11-16 22:17:37 +00:00
|
|
|
|
|
|
|
Recycle(rt);
|
|
|
|
}
|
|
|
|
|
2012-03-05 20:16:26 +00:00
|
|
|
return dst;
|
|
|
|
//return rt;
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Copy a sub part of a texture into another
|
|
|
|
// Several question to answer did texture have same size?
|
|
|
|
// From a sub-part to the same sub-part
|
|
|
|
// From a sub-part to a full texture
|
|
|
|
void GSDeviceOGL::CopyRect(GSTexture* st, GSTexture* dt, const GSVector4i& r)
|
|
|
|
{
|
|
|
|
if(!st || !dt)
|
|
|
|
{
|
|
|
|
ASSERT(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-28 10:14:42 +00:00
|
|
|
// FIXME: the extension was integrated in opengl 4.3 (now we need driver that support OGL4.3)
|
2011-12-23 12:32:40 +00:00
|
|
|
// FIXME check those function work as expected
|
2012-01-31 17:08:05 +00:00
|
|
|
// void CopyImageSubDataNV(
|
2013-01-10 13:13:59 +00:00
|
|
|
// uint32 srcName, enum srcTarget, int srcLevel, int srcX, int srcY, int srcZ,
|
|
|
|
// uint32 dstName, enum dstTarget, int dstLevel, int dstX, int dstY, int dstZ,
|
2012-01-31 17:08:05 +00:00
|
|
|
// sizei width, sizei height, sizei depth);
|
2013-05-19 09:19:20 +00:00
|
|
|
gl_CopyImageSubDataNV( static_cast<GSTextureOGL*>(st)->GetID(), static_cast<GSTextureOGL*>(st)->GetTarget(),
|
2012-01-31 17:08:05 +00:00
|
|
|
0, r.x, r.y, 0,
|
2012-03-05 20:16:26 +00:00
|
|
|
static_cast<GSTextureOGL*>(dt)->GetID(), static_cast<GSTextureOGL*>(dt)->GetTarget(),
|
2012-01-31 17:08:05 +00:00
|
|
|
0, r.x, r.y, 0,
|
|
|
|
r.width(), r.height(), 1);
|
|
|
|
|
2011-11-21 22:36:03 +00:00
|
|
|
#if 0
|
2011-11-16 22:17:37 +00:00
|
|
|
D3D11_BOX box = {r.left, r.top, 0, r.right, r.bottom, 1};
|
|
|
|
m_ctx->CopySubresourceRegion(*(GSTexture11*)dt, 0, 0, 0, 0, *(GSTexture11*)st, 0, &box);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, const GSVector4& dr, int shader, bool linear)
|
|
|
|
{
|
2011-12-11 19:11:01 +00:00
|
|
|
StretchRect(st, sr, dt, dr, m_convert.ps[shader], linear);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
2011-11-21 22:36:03 +00:00
|
|
|
|
2011-12-11 19:11:01 +00:00
|
|
|
void GSDeviceOGL::StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, const GSVector4& dr, GLuint ps, bool linear)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2011-12-11 19:11:01 +00:00
|
|
|
StretchRect(st, sr, dt, dr, ps, m_convert.bs, linear);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-11 19:11:01 +00:00
|
|
|
void GSDeviceOGL::StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, const GSVector4& dr, GLuint ps, GSBlendStateOGL* bs, bool linear)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2011-12-07 22:05:46 +00:00
|
|
|
|
2011-11-16 22:17:37 +00:00
|
|
|
if(!st || !dt)
|
|
|
|
{
|
|
|
|
ASSERT(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-10 19:19:44 +00:00
|
|
|
// ************************************
|
|
|
|
// Init
|
|
|
|
// ************************************
|
|
|
|
|
2011-11-16 22:17:37 +00:00
|
|
|
BeginScene();
|
|
|
|
|
|
|
|
GSVector2i ds = dt->GetSize();
|
|
|
|
|
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
|
|
|
|
|
|
|
OMSetDepthStencilState(m_convert.dss, 0);
|
|
|
|
OMSetBlendState(bs, 0);
|
|
|
|
OMSetRenderTargets(dt, NULL);
|
|
|
|
|
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
|
|
|
|
2011-11-16 22:17:37 +00:00
|
|
|
float left = dr.x * 2 / ds.x - 1.0f;
|
|
|
|
float top = 1.0f - dr.y * 2 / ds.y;
|
|
|
|
float right = dr.z * 2 / ds.x - 1.0f;
|
|
|
|
float bottom = 1.0f - dr.w * 2 / ds.y;
|
|
|
|
|
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)...
|
|
|
|
GSVector4 flip_sr = sr;
|
2011-12-21 23:09:36 +00:00
|
|
|
if (static_cast<GSTextureOGL*>(dt)->IsBackbuffer()) {
|
2011-12-11 19:09:08 +00:00
|
|
|
flip_sr.y = 1.0f - sr.y;
|
|
|
|
flip_sr.w = 1.0f - sr.w;
|
|
|
|
}
|
|
|
|
|
2011-12-07 22:05:46 +00:00
|
|
|
GSVertexPT1 vertices[] =
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2011-12-11 19:09:08 +00:00
|
|
|
{GSVector4(left, bottom, 0.5f, 1.0f), GSVector2(flip_sr.x, flip_sr.y)},
|
|
|
|
{GSVector4(right, bottom, 0.5f, 1.0f), GSVector2(flip_sr.z, flip_sr.y)},
|
|
|
|
{GSVector4(left, top, 0.5f, 1.0f), GSVector2(flip_sr.x, flip_sr.w)},
|
|
|
|
{GSVector4(right, top, 0.5f, 1.0f), GSVector2(flip_sr.z, flip_sr.w)},
|
2011-11-16 22:17:37 +00:00
|
|
|
};
|
2012-01-31 17:08:05 +00:00
|
|
|
//fprintf(stderr, "A:%fx%f B:%fx%f\n", left, top, bottom, right);
|
|
|
|
//fprintf(stderr, "SR: %f %f %f %f\n", sr.x, sr.y, sr.z, sr.w);
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2011-12-15 18:27:58 +00:00
|
|
|
IASetVertexState(m_vb_sr);
|
|
|
|
IASetVertexBuffer(vertices, 4);
|
|
|
|
IASetPrimitiveTopology(GL_TRIANGLE_STRIP);
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2011-12-10 19:19:44 +00:00
|
|
|
// ************************************
|
2011-11-16 22:17:37 +00:00
|
|
|
// vs
|
2011-12-10 19:19:44 +00:00
|
|
|
// ************************************
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2011-12-11 19:11:01 +00:00
|
|
|
VSSetShader(m_convert.vs);
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2011-12-10 19:19:44 +00:00
|
|
|
// ************************************
|
2011-11-16 22:17:37 +00:00
|
|
|
// gs
|
2011-12-10 19:19:44 +00:00
|
|
|
// ************************************
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2011-11-30 21:42:41 +00:00
|
|
|
GSSetShader(0);
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2011-12-10 19:19:44 +00:00
|
|
|
// ************************************
|
2011-11-16 22:17:37 +00:00
|
|
|
// ps
|
2011-12-10 19:19:44 +00:00
|
|
|
// ************************************
|
2011-11-16 22:17:37 +00:00
|
|
|
|
|
|
|
PSSetShaderResources(st, NULL);
|
2011-11-30 21:42:41 +00:00
|
|
|
PSSetSamplerState(linear ? m_convert.ln : m_convert.pt, 0);
|
2011-12-11 19:11:01 +00:00
|
|
|
PSSetShader(ps);
|
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();
|
|
|
|
|
|
|
|
PSSetShaderResources(NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::DoMerge(GSTexture* st[2], GSVector4* sr, GSTexture* dt, GSVector4* dr, bool slbg, bool mmod, const GSVector4& c)
|
|
|
|
{
|
|
|
|
ClearRenderTarget(dt, c);
|
|
|
|
|
|
|
|
if(st[1] && !slbg)
|
|
|
|
{
|
2012-01-08 21:59:42 +00:00
|
|
|
StretchRect(st[1], sr[1], dt, dr[1], m_merge_obj.ps[0]);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(st[0])
|
|
|
|
{
|
2012-01-08 21:59:42 +00:00
|
|
|
SetUniformBuffer(m_merge_obj.cb);
|
|
|
|
m_merge_obj.cb->upload(&c.v);
|
2011-12-11 19:09:08 +00:00
|
|
|
|
2012-01-08 21:59:42 +00:00
|
|
|
StretchRect(st[0], sr[0], dt, dr[0], m_merge_obj.ps[mmod ? 1 : 0], m_merge_obj.bs);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::DoInterlace(GSTexture* st, GSTexture* dt, int shader, bool linear, float yoffset)
|
|
|
|
{
|
|
|
|
GSVector4 s = GSVector4(dt->GetSize());
|
|
|
|
|
|
|
|
GSVector4 sr(0, 0, 1, 1);
|
|
|
|
GSVector4 dr(0.0f, yoffset, s.x, s.y + yoffset);
|
|
|
|
|
|
|
|
InterlaceConstantBuffer cb;
|
|
|
|
|
|
|
|
cb.ZrH = GSVector2(0, 1.0f / s.y);
|
|
|
|
cb.hH = s.y / 2;
|
|
|
|
|
2011-12-19 21:03:23 +00:00
|
|
|
SetUniformBuffer(m_interlace.cb);
|
|
|
|
m_interlace.cb->upload(&cb);
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2011-12-11 19:11:01 +00:00
|
|
|
StretchRect(st, sr, dt, dr, m_interlace.ps[shader], linear);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
2012-04-26 21:42:16 +00:00
|
|
|
void GSDeviceOGL::DoShadeBoost(GSTexture* st, GSTexture* dt)
|
|
|
|
{
|
|
|
|
GSVector2i s = dt->GetSize();
|
|
|
|
|
|
|
|
GSVector4 sr(0, 0, 1, 1);
|
|
|
|
GSVector4 dr(0, 0, s.x, s.y);
|
|
|
|
|
|
|
|
ShadeBoostConstantBuffer cb;
|
|
|
|
|
|
|
|
cb.rcpFrame = GSVector4(1.0f / s.x, 1.0f / s.y, 0.0f, 0.0f);
|
|
|
|
cb.rcpFrameOpt = GSVector4::zero();
|
|
|
|
|
|
|
|
SetUniformBuffer(m_shadeboost.cb);
|
|
|
|
m_shadeboost.cb->upload(&cb);
|
|
|
|
|
|
|
|
StretchRect(st, sr, dt, dr, m_shadeboost.ps, m_shadeboost.cb);
|
|
|
|
}
|
|
|
|
|
2011-12-19 21:03:23 +00:00
|
|
|
void GSDeviceOGL::SetupDATE(GSTexture* rt, GSTexture* ds, const GSVertexPT1* vertices, bool datm)
|
|
|
|
{
|
|
|
|
const GSVector2i& size = rt->GetSize();
|
|
|
|
|
|
|
|
if(GSTexture* t = CreateRenderTarget(size.x, size.y, rt->IsMSAA()))
|
|
|
|
{
|
|
|
|
// sfex3 (after the capcom logo), vf4 (first menu fading in), ffxii shadows, rumble roses shadows, persona4 shadows
|
|
|
|
|
|
|
|
BeginScene();
|
|
|
|
|
|
|
|
ClearStencil(ds, 0);
|
|
|
|
|
|
|
|
// om
|
|
|
|
|
|
|
|
OMSetDepthStencilState(m_date.dss, 1);
|
|
|
|
OMSetBlendState(m_date.bs, 0);
|
|
|
|
OMSetRenderTargets(t, ds);
|
|
|
|
|
|
|
|
// ia
|
|
|
|
|
|
|
|
IASetVertexState(m_vb_sr);
|
|
|
|
IASetVertexBuffer(vertices, 4);
|
|
|
|
IASetPrimitiveTopology(GL_TRIANGLE_STRIP);
|
|
|
|
|
|
|
|
// vs
|
|
|
|
|
|
|
|
VSSetShader(m_convert.vs);
|
|
|
|
|
|
|
|
// gs
|
|
|
|
|
2011-12-23 12:32:40 +00:00
|
|
|
GSSetShader(0);
|
2011-12-19 21:03:23 +00:00
|
|
|
|
|
|
|
// ps
|
|
|
|
|
|
|
|
GSTexture* rt2 = rt->IsMSAA() ? Resolve(rt) : rt;
|
|
|
|
|
|
|
|
PSSetShaderResources(rt2, NULL);
|
|
|
|
PSSetSamplerState(m_convert.pt, 0);
|
|
|
|
PSSetShader(m_convert.ps[datm ? 2 : 3]);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
DrawPrimitive();
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
EndScene();
|
|
|
|
|
|
|
|
Recycle(t);
|
|
|
|
|
|
|
|
if(rt2 != rt) Recycle(rt2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-16 22:17:37 +00:00
|
|
|
// copy a multisample texture to a non-texture multisample. On opengl you need 2 FBO with different level of
|
|
|
|
// sample and then do a blit. Headach expected to for the moment just drop MSAA...
|
|
|
|
GSTexture* GSDeviceOGL::Resolve(GSTexture* t)
|
|
|
|
{
|
|
|
|
ASSERT(t != NULL && t->IsMSAA());
|
2011-11-21 22:36:03 +00:00
|
|
|
#if 0
|
2011-11-16 22:17:37 +00:00
|
|
|
|
|
|
|
if(GSTexture* dst = CreateRenderTarget(t->GetWidth(), t->GetHeight(), false, t->GetFormat()))
|
|
|
|
{
|
|
|
|
dst->SetScale(t->GetScale());
|
|
|
|
|
|
|
|
m_ctx->ResolveSubresource(*(GSTexture11*)dst, 0, *(GSTexture11*)t, 0, (DXGI_FORMAT)t->GetFormat());
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-12-15 18:27:58 +00:00
|
|
|
void GSDeviceOGL::EndScene()
|
2011-12-10 19:19:44 +00:00
|
|
|
{
|
2012-01-15 17:25:49 +00:00
|
|
|
m_state.vb->EndScene();
|
2011-12-10 19:19:44 +00:00
|
|
|
}
|
|
|
|
|
2011-12-19 21:03:23 +00:00
|
|
|
void GSDeviceOGL::SetUniformBuffer(GSUniformBufferOGL* cb)
|
|
|
|
{
|
|
|
|
if (m_state.cb != cb) {
|
|
|
|
m_state.cb = cb;
|
|
|
|
cb->bind();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-03 16:12:34 +00:00
|
|
|
void GSDeviceOGL::IASetVertexState(GSVertexBufferStateOGL* vb)
|
2011-12-10 19:19:44 +00:00
|
|
|
{
|
2012-02-11 10:22:02 +00:00
|
|
|
if (vb == NULL) vb = m_vb;
|
|
|
|
|
2012-01-03 16:12:34 +00:00
|
|
|
if (m_state.vb != vb) {
|
|
|
|
m_state.vb = vb;
|
|
|
|
vb->bind();
|
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
|
|
|
{
|
2012-01-15 17:25:49 +00:00
|
|
|
m_state.vb->UploadVB(vertices, count);
|
|
|
|
}
|
|
|
|
|
2012-02-11 10:22:02 +00:00
|
|
|
bool GSDeviceOGL::IAMapVertexBuffer(void** vertex, size_t stride, size_t count)
|
|
|
|
{
|
|
|
|
return m_state.vb->MapVB(vertex, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::IAUnmapVertexBuffer()
|
|
|
|
{
|
|
|
|
m_state.vb->UnmapVB();
|
|
|
|
}
|
|
|
|
|
2012-01-15 17:25:49 +00:00
|
|
|
void GSDeviceOGL::IASetIndexBuffer(const void* index, size_t count)
|
|
|
|
{
|
|
|
|
m_state.vb->UploadIB(index, count);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::IASetPrimitiveTopology(GLenum topology)
|
|
|
|
{
|
2012-01-03 16:12:34 +00:00
|
|
|
m_state.vb->SetTopology(topology);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-11 19:11:01 +00:00
|
|
|
void GSDeviceOGL::VSSetShader(GLuint vs)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
|
|
|
if(m_state.vs != vs)
|
|
|
|
{
|
|
|
|
m_state.vs = vs;
|
2013-05-19 12:42:55 +00:00
|
|
|
if (GLLoader::found_GL_ARB_separate_shader_objects)
|
|
|
|
gl_UseProgramStages(m_pipeline, GL_VERTEX_SHADER_BIT, vs);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::GSSetShader(GLuint gs)
|
|
|
|
{
|
|
|
|
if(m_state.gs != gs)
|
|
|
|
{
|
|
|
|
m_state.gs = gs;
|
2013-05-19 12:42:55 +00:00
|
|
|
if (GLLoader::found_GL_ARB_separate_shader_objects)
|
|
|
|
gl_UseProgramStages(m_pipeline, GL_GEOMETRY_SHADER_BIT, gs);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::PSSetShaderResources(GSTexture* sr0, GSTexture* sr1)
|
|
|
|
{
|
|
|
|
PSSetShaderResource(0, sr0);
|
|
|
|
PSSetShaderResource(1, sr1);
|
2012-01-31 17:08:05 +00:00
|
|
|
//PSSetShaderResource(2, NULL);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::PSSetShaderResource(int i, GSTexture* sr)
|
|
|
|
{
|
2011-12-29 14:24:26 +00:00
|
|
|
GSTextureOGL* srv = static_cast<GSTextureOGL*>(sr);
|
2011-11-16 22:17:37 +00:00
|
|
|
|
|
|
|
if(m_state.ps_srv[i] != srv)
|
|
|
|
{
|
|
|
|
m_state.ps_srv[i] = srv;
|
|
|
|
|
|
|
|
m_srv_changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::PSSetSamplerState(GLuint ss0, GLuint ss1, GLuint ss2)
|
|
|
|
{
|
2012-01-31 17:08:05 +00:00
|
|
|
if(m_state.ps_ss[0] != ss0 || m_state.ps_ss[1] != ss1)
|
|
|
|
//if(m_state.ps_ss[0] != ss0 || m_state.ps_ss[1] != ss1 || m_state.ps_ss[2] != ss2)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
|
|
|
m_state.ps_ss[0] = ss0;
|
|
|
|
m_state.ps_ss[1] = ss1;
|
2012-01-31 17:08:05 +00:00
|
|
|
//m_state.ps_ss[2] = ss2;
|
2011-11-16 22:17:37 +00:00
|
|
|
|
|
|
|
m_ss_changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-11 19:11:01 +00:00
|
|
|
void GSDeviceOGL::PSSetShader(GLuint ps)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
|
|
|
if(m_state.ps != ps)
|
|
|
|
{
|
|
|
|
m_state.ps = ps;
|
2013-05-19 12:42:55 +00:00
|
|
|
if (GLLoader::found_GL_ARB_separate_shader_objects)
|
|
|
|
gl_UseProgramStages(m_pipeline, GL_FRAGMENT_SHADER_BIT, ps);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sampler and texture must be set at the same time
|
|
|
|
// 1/ select the texture unit
|
2013-05-19 09:19:20 +00:00
|
|
|
// gl_ActiveTexture(GL_TEXTURE0 + 1);
|
2011-11-16 22:17:37 +00:00
|
|
|
// 2/ bind the texture
|
|
|
|
// glBindTexture(GL_TEXTURE_2D , brickTexture);
|
|
|
|
// 3/ sets the texture sampler in GLSL (could be useless with layout stuff)
|
2013-05-19 09:19:20 +00:00
|
|
|
// gl_Uniform1i(brickSamplerId , 1);
|
2011-11-16 22:17:37 +00:00
|
|
|
// 4/ set the sampler state
|
2013-05-19 09:19:20 +00:00
|
|
|
// gl_BindSampler(1 , sampler);
|
2011-11-21 22:36:03 +00:00
|
|
|
if (m_srv_changed || m_ss_changed) {
|
2013-01-10 13:13:59 +00:00
|
|
|
for (uint32 i=0 ; i < 1; i++) {
|
2011-11-30 21:42:41 +00:00
|
|
|
if (m_state.ps_srv[i] != NULL) {
|
|
|
|
m_state.ps_srv[i]->EnableUnit(i);
|
2013-05-19 09:19:20 +00:00
|
|
|
gl_BindSampler(i, m_state.ps_ss[i]);
|
2011-11-30 21:42:41 +00:00
|
|
|
}
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
2012-03-30 19:02:37 +00:00
|
|
|
void GSDeviceOGL::OMSetFBO(GLuint fbo, GLenum buffer)
|
2011-12-08 11:17:59 +00:00
|
|
|
{
|
|
|
|
if (m_state.fbo != fbo) {
|
|
|
|
m_state.fbo = fbo;
|
2013-05-19 09:19:20 +00:00
|
|
|
gl_BindFramebuffer(GL_FRAMEBUFFER, fbo);
|
2012-02-11 10:22:02 +00:00
|
|
|
// FIXME DEBUG
|
2013-05-19 09:19:20 +00:00
|
|
|
//if (fbo) fprintf(stderr, "FB status %x\n", gl_CheckFramebufferStatus(GL_FRAMEBUFFER));
|
2011-12-08 11:17:59 +00:00
|
|
|
}
|
2012-03-30 19:02:37 +00:00
|
|
|
|
|
|
|
if (m_state.draw != buffer) {
|
|
|
|
m_state.draw = buffer;
|
|
|
|
glDrawBuffer(buffer);
|
|
|
|
}
|
|
|
|
|
2011-12-08 11:17:59 +00:00
|
|
|
}
|
|
|
|
|
2011-11-16 22:17:37 +00:00
|
|
|
void GSDeviceOGL::OMSetDepthStencilState(GSDepthStencilOGL* dss, uint8 sref)
|
|
|
|
{
|
2012-01-03 13:11:40 +00:00
|
|
|
if(m_state.dss != dss) {
|
2011-11-16 22:17:37 +00:00
|
|
|
m_state.dss = dss;
|
|
|
|
m_state.sref = sref;
|
|
|
|
|
2012-01-03 13:11:40 +00:00
|
|
|
dss->SetupDepth();
|
|
|
|
dss->SetupStencil(sref);
|
|
|
|
|
|
|
|
} else if (m_state.sref != sref) {
|
|
|
|
m_state.sref = sref;
|
|
|
|
|
|
|
|
dss->SetupStencil(sref);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::OMSetBlendState(GSBlendStateOGL* bs, float bf)
|
|
|
|
{
|
2012-01-03 13:11:40 +00:00
|
|
|
if( m_state.bs != bs || (m_state.bf != bf && bs->HasConstantFactor()) )
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
|
|
|
m_state.bs = bs;
|
|
|
|
m_state.bf = bf;
|
|
|
|
|
2012-01-03 13:11:40 +00:00
|
|
|
bs->SetupBlend(bf);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::OMSetRenderTargets(GSTexture* rt, GSTexture* ds, const GSVector4i* scissor)
|
|
|
|
{
|
2011-11-21 22:36:03 +00:00
|
|
|
// Hum, need to separate 2 case, Render target fbo and render target backbuffer
|
|
|
|
// Or maybe blit final result to the backbuffer
|
2011-12-29 14:24:26 +00:00
|
|
|
m_state.rtv = static_cast<GSTextureOGL*>(rt);
|
|
|
|
m_state.dsv = static_cast<GSTextureOGL*>(ds);
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2011-12-21 23:09:36 +00:00
|
|
|
if (static_cast<GSTextureOGL*>(rt)->IsBackbuffer()) {
|
2013-01-12 23:41:31 +00:00
|
|
|
ASSERT(ds == NULL); // no depth-stencil without FBO
|
2012-03-30 19:02:37 +00:00
|
|
|
|
2011-12-08 11:17:59 +00:00
|
|
|
OMSetFBO(0);
|
2011-11-21 22:36:03 +00:00
|
|
|
|
|
|
|
} else {
|
2013-01-12 23:41:31 +00:00
|
|
|
ASSERT(rt != NULL); // a render target must exists
|
2011-12-29 14:24:26 +00:00
|
|
|
|
|
|
|
// FIXME DEBUG special case for GL_R16UI
|
|
|
|
if (rt->GetFormat() == GL_R16UI) {
|
2012-03-30 19:02:37 +00:00
|
|
|
OMSetFBO(m_fbo, GL_COLOR_ATTACHMENT1);
|
2011-12-29 14:24:26 +00:00
|
|
|
static_cast<GSTextureOGL*>(rt)->Attach(GL_COLOR_ATTACHMENT1);
|
|
|
|
} else {
|
2012-03-30 19:02:37 +00:00
|
|
|
OMSetFBO(m_fbo, GL_COLOR_ATTACHMENT0);
|
2011-12-29 14:24:26 +00:00
|
|
|
static_cast<GSTextureOGL*>(rt)->Attach(GL_COLOR_ATTACHMENT0);
|
|
|
|
}
|
|
|
|
|
2011-12-21 23:09:36 +00:00
|
|
|
if (ds != NULL)
|
|
|
|
static_cast<GSTextureOGL*>(ds)->Attach(GL_DEPTH_STENCIL_ATTACHMENT);
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
2011-11-16 22:17:37 +00:00
|
|
|
|
|
|
|
if(m_state.viewport != rt->GetSize())
|
|
|
|
{
|
|
|
|
m_state.viewport = rt->GetSize();
|
2011-11-21 22:36:03 +00:00
|
|
|
glViewport(0, 0, rt->GetWidth(), rt->GetHeight());
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GSVector4i r = scissor ? *scissor : GSVector4i(rt->GetSize()).zwxy();
|
|
|
|
|
|
|
|
if(!m_state.scissor.eq(r))
|
|
|
|
{
|
|
|
|
m_state.scissor = r;
|
2011-12-07 22:05:46 +00:00
|
|
|
glScissor( r.x, r.y, r.width(), r.height() );
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
|
|
|
|
2013-05-18 09:17:30 +00:00
|
|
|
void GSDeviceOGL::CompileShaderFromSource(const std::string& glsl_file, const std::string& entry, GLenum type, GLuint* program, const char* glsl_h_code, const std::string& macro_sel)
|
2011-11-21 22:36:03 +00:00
|
|
|
{
|
2011-11-30 21:42:41 +00:00
|
|
|
// *****************************************************
|
|
|
|
// Build a header string
|
|
|
|
// *****************************************************
|
|
|
|
// First select the version (must be the first line so we need to generate it
|
2013-05-19 12:42:55 +00:00
|
|
|
std::string version = "#version 330\n";
|
|
|
|
if (GLLoader::found_GL_ARB_shading_language_420pack) {
|
|
|
|
version += "#extension GL_ARB_shading_language_420pack: require\n";
|
|
|
|
} else {
|
|
|
|
version += "#define DISABLE_GL42\n";
|
|
|
|
}
|
|
|
|
if (GLLoader::found_GL_ARB_separate_shader_objects) {
|
|
|
|
version += "#extension GL_ARB_separate_shader_objects : require\n";
|
|
|
|
}
|
2011-11-30 21:42:41 +00:00
|
|
|
|
|
|
|
// Allow to puts several shader in 1 files
|
2011-11-21 22:36:03 +00:00
|
|
|
std::string shader_type;
|
|
|
|
switch (type) {
|
|
|
|
case GL_VERTEX_SHADER:
|
|
|
|
shader_type = "#define VERTEX_SHADER 1\n";
|
2011-11-30 21:42:41 +00:00
|
|
|
break;
|
2011-11-21 22:36:03 +00:00
|
|
|
case GL_GEOMETRY_SHADER:
|
|
|
|
shader_type = "#define GEOMETRY_SHADER 1\n";
|
2011-11-30 21:42:41 +00:00
|
|
|
break;
|
2011-11-21 22:36:03 +00:00
|
|
|
case GL_FRAGMENT_SHADER:
|
|
|
|
shader_type = "#define FRAGMENT_SHADER 1\n";
|
2011-11-30 21:42:41 +00:00
|
|
|
break;
|
2013-01-12 23:41:31 +00:00
|
|
|
default: ASSERT(0);
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
|
|
|
|
2011-11-30 21:42:41 +00:00
|
|
|
// Select the entry point ie the main function
|
2011-11-21 22:36:03 +00:00
|
|
|
std::string entry_main = format("#define %s main\n", entry.c_str());
|
|
|
|
|
2011-12-23 12:32:40 +00:00
|
|
|
std::string header = version + shader_type + entry_main + macro_sel;
|
2011-11-30 21:42:41 +00:00
|
|
|
|
|
|
|
// *****************************************************
|
2011-11-21 22:36:03 +00:00
|
|
|
// Read the source file
|
2011-11-30 21:42:41 +00:00
|
|
|
// *****************************************************
|
2011-11-21 22:36:03 +00:00
|
|
|
std::string source;
|
|
|
|
std::string line;
|
|
|
|
// Each linux distributions have his rules for path so we give them the possibility to
|
|
|
|
// change it with compilation flags. -- Gregory
|
2012-05-07 16:29:06 +00:00
|
|
|
#ifdef GLSL_SHADER_DIR_COMPILATION
|
|
|
|
#define xGLSL_SHADER_DIR_str(s) GLSL_SHADER_DIR_str(s)
|
|
|
|
#define GLSL_SHADER_DIR_str(s) #s
|
|
|
|
const std::string shader_file = string(xGLSL_SHADER_DIR_str(GLSL_SHADER_DIR_COMPILATION)) + '/' + glsl_file;
|
2011-11-21 22:36:03 +00:00
|
|
|
#else
|
|
|
|
const std::string shader_file = string("plugins/") + glsl_file;
|
2011-11-16 22:17:37 +00:00
|
|
|
#endif
|
2011-11-21 22:36:03 +00:00
|
|
|
std::ifstream myfile(shader_file.c_str());
|
2013-05-18 09:17:30 +00:00
|
|
|
bool failed_to_open_glsl = true;
|
2011-11-21 22:36:03 +00:00
|
|
|
if (myfile.is_open()) {
|
|
|
|
while ( myfile.good() )
|
|
|
|
{
|
|
|
|
getline (myfile,line);
|
|
|
|
source += line;
|
|
|
|
source += '\n';
|
|
|
|
}
|
|
|
|
myfile.close();
|
2013-05-18 09:17:30 +00:00
|
|
|
failed_to_open_glsl = false;
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-30 21:42:41 +00:00
|
|
|
// Note it is better to separate header and source file to have the good line number
|
|
|
|
// in the glsl compiler report
|
|
|
|
const char** sources_array = (const char**)malloc(2*sizeof(char*));
|
2013-05-18 09:17:30 +00:00
|
|
|
|
2011-11-30 21:42:41 +00:00
|
|
|
char* header_str = (char*)malloc(header.size() + 1);
|
|
|
|
sources_array[0] = header_str;
|
|
|
|
header.copy(header_str, header.size(), 0);
|
|
|
|
header_str[header.size()] = '\0';
|
2011-11-21 22:36:03 +00:00
|
|
|
|
2013-05-18 09:17:30 +00:00
|
|
|
char* source_str = (char*)malloc(source.size() + 1);
|
|
|
|
if (failed_to_open_glsl) {
|
|
|
|
sources_array[1] = glsl_h_code;
|
|
|
|
} else {
|
|
|
|
sources_array[1] = source_str;
|
|
|
|
source.copy(source_str, source.size(), 0);
|
|
|
|
source_str[source.size()] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-19 12:42:55 +00:00
|
|
|
if (GLLoader::found_GL_ARB_separate_shader_objects) {
|
|
|
|
#if 0
|
|
|
|
// Could be useful one day
|
|
|
|
const GLchar* ShaderSource[1];
|
|
|
|
ShaderSource[0] = header.append(source).c_str();
|
|
|
|
*program = gl_CreateShaderProgramv(type, 1, &ShaderSource[0]);
|
|
|
|
#else
|
|
|
|
*program = gl_CreateShaderProgramv(type, 2, sources_array);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
*program = gl_CreateShader(type);
|
|
|
|
gl_ShaderSource(*program, 2, sources_array, NULL);
|
|
|
|
gl_CompileShader(*program);
|
|
|
|
}
|
2012-05-11 19:39:32 +00:00
|
|
|
|
2011-11-30 21:42:41 +00:00
|
|
|
free(source_str);
|
|
|
|
free(header_str);
|
|
|
|
free(sources_array);
|
|
|
|
|
2012-01-12 07:29:31 +00:00
|
|
|
if (theApp.GetConfig("debug_ogl_shader", 1) == 1) {
|
|
|
|
// Print a nice debug log
|
2013-02-03 15:46:42 +00:00
|
|
|
fprintf(stderr, "%s (entry %s, prog %d) :", glsl_file.c_str(), entry.c_str(), *program);
|
|
|
|
fprintf(stderr, "\n%s", macro_sel.c_str());
|
|
|
|
|
2012-01-12 07:29:31 +00:00
|
|
|
GLint log_length = 0;
|
2013-05-19 12:42:55 +00:00
|
|
|
if (GLLoader::found_GL_ARB_separate_shader_objects)
|
|
|
|
gl_GetProgramiv(*program, GL_INFO_LOG_LENGTH, &log_length);
|
|
|
|
else
|
|
|
|
gl_GetShaderiv(*program, GL_INFO_LOG_LENGTH, &log_length);
|
|
|
|
|
2013-02-03 15:46:42 +00:00
|
|
|
if (log_length > 0) {
|
2013-05-17 16:55:55 +00:00
|
|
|
char* log = new char[log_length];
|
2013-05-19 12:42:55 +00:00
|
|
|
if (GLLoader::found_GL_ARB_separate_shader_objects)
|
|
|
|
gl_GetProgramInfoLog(*program, log_length, NULL, log);
|
|
|
|
else
|
|
|
|
gl_GetShaderInfoLog(*program, log_length, NULL, log);
|
|
|
|
|
2013-02-03 15:46:42 +00:00
|
|
|
fprintf(stderr, "%s", log);
|
2013-05-17 16:55:55 +00:00
|
|
|
delete[] log;
|
2013-02-03 15:46:42 +00:00
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
2012-01-12 07:29:31 +00:00
|
|
|
}
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
2011-11-26 11:46:51 +00:00
|
|
|
|
|
|
|
void GSDeviceOGL::CheckDebugLog()
|
|
|
|
{
|
|
|
|
unsigned int count = 64; // max. num. of messages that will be read from the log
|
|
|
|
int bufsize = 2048;
|
|
|
|
unsigned int* sources = new unsigned int[count];
|
|
|
|
unsigned int* types = new unsigned int[count];
|
|
|
|
unsigned int* ids = new unsigned int[count];
|
|
|
|
unsigned int* severities = new unsigned int[count];
|
|
|
|
int* lengths = new int[count];
|
|
|
|
char* messageLog = new char[bufsize];
|
|
|
|
|
2013-05-19 09:19:20 +00:00
|
|
|
unsigned int retVal = gl_GetDebugMessageLogARB(count, bufsize, sources, types, ids, severities, lengths, messageLog);
|
2011-11-26 11:46:51 +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],
|
|
|
|
&messageLog[pos]);
|
|
|
|
pos += lengths[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete [] sources;
|
|
|
|
delete [] types;
|
|
|
|
delete [] ids;
|
|
|
|
delete [] severities;
|
|
|
|
delete [] lengths;
|
|
|
|
delete [] messageLog;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::DebugOutputToFile(unsigned int source, unsigned int type, unsigned int id, unsigned int severity, const char* message)
|
|
|
|
{
|
2011-12-08 11:17:59 +00:00
|
|
|
char debType[20], debSev[5];
|
2012-02-11 10:22:02 +00:00
|
|
|
static int sev_counter = 0;
|
2011-12-08 11:17:59 +00:00
|
|
|
|
|
|
|
if(type == GL_DEBUG_TYPE_ERROR_ARB)
|
|
|
|
strcpy(debType, "Error");
|
|
|
|
else if(type == GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB)
|
|
|
|
strcpy(debType, "Deprecated behavior");
|
|
|
|
else if(type == GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB)
|
|
|
|
strcpy(debType, "Undefined behavior");
|
|
|
|
else if(type == GL_DEBUG_TYPE_PORTABILITY_ARB)
|
|
|
|
strcpy(debType, "Portability");
|
|
|
|
else if(type == GL_DEBUG_TYPE_PERFORMANCE_ARB)
|
|
|
|
strcpy(debType, "Performance");
|
|
|
|
else if(type == GL_DEBUG_TYPE_OTHER_ARB)
|
|
|
|
strcpy(debType, "Other");
|
|
|
|
else
|
2011-12-10 11:56:34 +00:00
|
|
|
strcpy(debType, "UNKNOWN");
|
2011-12-08 11:17:59 +00:00
|
|
|
|
2012-02-11 10:22:02 +00:00
|
|
|
if(severity == GL_DEBUG_SEVERITY_HIGH_ARB) {
|
2011-12-08 11:17:59 +00:00
|
|
|
strcpy(debSev, "High");
|
2012-02-11 10:22:02 +00:00
|
|
|
sev_counter++;
|
|
|
|
}
|
2011-12-08 11:17:59 +00:00
|
|
|
else if(severity == GL_DEBUG_SEVERITY_MEDIUM_ARB)
|
|
|
|
strcpy(debSev, "Med");
|
|
|
|
else if(severity == GL_DEBUG_SEVERITY_LOW_ARB)
|
|
|
|
strcpy(debSev, "Low");
|
|
|
|
|
2011-12-10 11:56:34 +00:00
|
|
|
#ifdef LOUD_DEBUGGING
|
2012-02-11 10:22:02 +00:00
|
|
|
fprintf(stderr,"Type:%s\tID:%d\tSeverity:%s\tMessage:%s\n", debType, g_draw_count, debSev,message);
|
2011-12-10 11:56:34 +00:00
|
|
|
#endif
|
2011-12-08 11:17:59 +00:00
|
|
|
|
|
|
|
FILE* f = fopen("Debug.txt","a");
|
2011-11-26 11:46:51 +00:00
|
|
|
if(f)
|
|
|
|
{
|
2012-02-11 10:22:02 +00:00
|
|
|
fprintf(f,"Type:%s\tID:%d\tSeverity:%s\tMessage:%s\n", debType, g_draw_count, debSev,message);
|
2011-11-26 11:46:51 +00:00
|
|
|
fclose(f);
|
|
|
|
}
|
2012-02-11 10:22:02 +00:00
|
|
|
//if (sev_counter > 2) assert(0);
|
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
|
|
|
|
|
|
|
|
// 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
|
2011-12-19 21:03:23 +00:00
|
|
|
|
|
|
|
const GSDeviceOGL::D3D9Blend GSDeviceOGL::m_blendMapD3D9[3*3*3*3] =
|
|
|
|
{
|
|
|
|
{0, 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
|
|
|
|
{0, D3DBLENDOP_ADD, D3DBLEND_ZERO, D3DBLEND_ZERO}, // 0002: (Cs - Cs)*As + 0 ==> 0
|
|
|
|
{0, 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
|
|
|
|
{0, D3DBLENDOP_ADD, D3DBLEND_ZERO, D3DBLEND_ZERO}, // 0012: (Cs - Cs)*Ad + 0 ==> 0
|
|
|
|
{0, 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
|
|
|
|
{0, D3DBLENDOP_ADD, D3DBLEND_ZERO, D3DBLEND_ZERO}, // 0022: (Cs - Cs)*F + 0 ==> 0
|
|
|
|
{1, D3DBLENDOP_SUBTRACT, D3DBLEND_SRCALPHA, D3DBLEND_SRCALPHA}, //*0100: (Cs - Cd)*As + Cs ==> Cs*(As + 1) - Cd*As
|
|
|
|
{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
|
|
|
|
{1, D3DBLENDOP_SUBTRACT, D3DBLEND_DESTALPHA, D3DBLEND_DESTALPHA}, //*0110: (Cs - Cd)*Ad + Cs ==> Cs*(Ad + 1) - Cd*Ad
|
|
|
|
{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
|
|
|
|
{1, D3DBLENDOP_SUBTRACT, D3DBLEND_BLENDFACTOR, D3DBLEND_BLENDFACTOR}, //*0120: (Cs - Cd)*F + Cs ==> Cs*(F + 1) - Cd*F
|
|
|
|
{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
|
|
|
|
{1, D3DBLENDOP_ADD, D3DBLEND_SRCALPHA, D3DBLEND_ZERO}, //*0200: (Cs - 0)*As + Cs ==> Cs*(As + 1)
|
|
|
|
{0, D3DBLENDOP_ADD, D3DBLEND_SRCALPHA, D3DBLEND_ONE}, // 0201: (Cs - 0)*As + Cd ==> Cs*As + Cd
|
|
|
|
{0, D3DBLENDOP_ADD, D3DBLEND_SRCALPHA, D3DBLEND_ZERO}, // 0202: (Cs - 0)*As + 0 ==> Cs*As
|
|
|
|
{1, D3DBLENDOP_ADD, D3DBLEND_DESTALPHA, D3DBLEND_ZERO}, //*0210: (Cs - 0)*Ad + Cs ==> Cs*(Ad + 1)
|
|
|
|
{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
|
|
|
|
{1, D3DBLENDOP_ADD, D3DBLEND_BLENDFACTOR, D3DBLEND_ZERO}, //*0220: (Cs - 0)*F + Cs ==> Cs*(F + 1)
|
|
|
|
{0, D3DBLENDOP_ADD, D3DBLEND_BLENDFACTOR, D3DBLEND_ONE}, // 0221: (Cs - 0)*F + Cd ==> Cs*F + Cd
|
|
|
|
{0, 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)
|
|
|
|
{1, D3DBLENDOP_REVSUBTRACT, D3DBLEND_SRCALPHA, D3DBLEND_SRCALPHA}, //*1001: (Cd - Cs)*As + Cd ==> Cd*(As + 1) - Cs*As
|
|
|
|
{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)
|
|
|
|
{1, D3DBLENDOP_REVSUBTRACT, D3DBLEND_DESTALPHA, D3DBLEND_DESTALPHA}, //*1011: (Cd - Cs)*Ad + Cd ==> Cd*(Ad + 1) - Cs*Ad
|
|
|
|
{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)
|
|
|
|
{1, D3DBLENDOP_REVSUBTRACT, D3DBLEND_BLENDFACTOR, D3DBLEND_BLENDFACTOR},//*1021: (Cd - Cs)*F + Cd ==> Cd*(F + 1) - Cs*F
|
|
|
|
{0, D3DBLENDOP_REVSUBTRACT, D3DBLEND_BLENDFACTOR, D3DBLEND_BLENDFACTOR},// 1022: (Cd - Cs)*F + 0 ==> Cd*F - Cs*F
|
|
|
|
{0, 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
|
|
|
|
{0, D3DBLENDOP_ADD, D3DBLEND_ZERO, D3DBLEND_ZERO}, // 1102: (Cd - Cd)*As + 0 ==> 0
|
|
|
|
{0, 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
|
|
|
|
{0, D3DBLENDOP_ADD, D3DBLEND_ZERO, D3DBLEND_ZERO}, // 1112: (Cd - Cd)*Ad + 0 ==> 0
|
|
|
|
{0, 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
|
|
|
|
{0, 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
|
|
|
|
{2, D3DBLENDOP_ADD, D3DBLEND_DESTCOLOR, D3DBLEND_SRCALPHA}, //#1201: (Cd - 0)*As + Cd ==> Cd*(1 + As) // ffxii main menu background glow effect
|
|
|
|
{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
|
|
|
|
{2, 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
|
|
|
|
{2, 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
|
|
|
|
{0, D3DBLENDOP_ADD, D3DBLEND_INVSRCALPHA, D3DBLEND_ZERO}, // 2000: (0 - Cs)*As + Cs ==> Cs*(1 - As)
|
|
|
|
{0, D3DBLENDOP_REVSUBTRACT, D3DBLEND_SRCALPHA, D3DBLEND_ONE}, // 2001: (0 - Cs)*As + Cd ==> Cd - Cs*As
|
|
|
|
{0, 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
|
|
|
|
{0, D3DBLENDOP_ADD, D3DBLEND_INVBLENDFACTOR, D3DBLEND_ZERO}, // 2020: (0 - Cs)*F + Cs ==> Cs*(1 - F)
|
|
|
|
{0, D3DBLENDOP_REVSUBTRACT, D3DBLEND_BLENDFACTOR, D3DBLEND_ONE}, // 2021: (0 - Cs)*F + Cd ==> Cd - Cs*F
|
|
|
|
{0, 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
|
|
|
|
{0, 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
|
|
|
|
{0, D3DBLENDOP_ADD, D3DBLEND_ZERO, D3DBLEND_ZERO}, // 2202: (0 - 0)*As + 0 ==> 0
|
|
|
|
{0, 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
|
|
|
|
{0, D3DBLENDOP_ADD, D3DBLEND_ZERO, D3DBLEND_ZERO}, // 2212: (0 - 0)*Ad + 0 ==> 0
|
|
|
|
{0, 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
|
|
|
|
{0, D3DBLENDOP_ADD, D3DBLEND_ZERO, D3DBLEND_ZERO}, // 2222: (0 - 0)*F + 0 ==> 0
|
|
|
|
};
|