2013-04-17 21:29:41 -06:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2009-06-06 07:36:33 -06:00
|
|
|
|
2009-06-15 00:39:26 -06:00
|
|
|
|
2011-02-13 19:18:03 -07:00
|
|
|
// OpenGL Backend Documentation
|
2013-10-28 23:23:17 -06:00
|
|
|
/*
|
2009-06-06 07:36:33 -06:00
|
|
|
|
|
|
|
1.1 Display settings
|
2009-06-15 00:39:26 -06:00
|
|
|
|
2009-09-09 13:52:45 -06:00
|
|
|
Internal and fullscreen resolution: Since the only internal resolutions allowed
|
|
|
|
are also fullscreen resolution allowed by the system there is only need for one
|
|
|
|
resolution setting that applies to both the internal resolution and the
|
|
|
|
fullscreen resolution. - Apparently no, someone else doesn't agree
|
2009-06-06 07:36:33 -06:00
|
|
|
|
2009-09-09 13:52:45 -06:00
|
|
|
Todo: Make the internal resolution option apply instantly, currently only the
|
|
|
|
native and 2x option applies instantly. To do this we need to be able to change
|
|
|
|
the reinitialize FramebufferManager:Init() while a game is running.
|
2009-06-06 07:36:33 -06:00
|
|
|
|
2009-06-07 05:51:53 -06:00
|
|
|
1.2 Screenshots
|
2009-06-15 00:39:26 -06:00
|
|
|
|
2009-06-07 05:51:53 -06:00
|
|
|
|
2009-09-09 13:52:45 -06:00
|
|
|
The screenshots should be taken from the internal representation of the picture
|
|
|
|
regardless of what the current window size is. Since AA and wireframe is
|
|
|
|
applied together with the picture resizing this rule is not currently applied
|
|
|
|
to AA or wireframe pictures, they are instead taken from whatever the window
|
|
|
|
size is.
|
2009-06-07 05:51:53 -06:00
|
|
|
|
2009-09-09 13:52:45 -06:00
|
|
|
Todo: Render AA and wireframe to a separate picture used for the screenshot in
|
|
|
|
addition to the one for display.
|
2009-06-07 05:51:53 -06:00
|
|
|
|
|
|
|
1.3 AA
|
2009-06-15 00:39:26 -06:00
|
|
|
|
2009-06-07 05:51:53 -06:00
|
|
|
Make AA apply instantly during gameplay if possible
|
|
|
|
|
2009-06-15 00:39:26 -06:00
|
|
|
*/
|
2009-06-06 07:36:33 -06:00
|
|
|
|
2013-03-07 11:11:50 -07:00
|
|
|
#include <algorithm>
|
2014-02-17 03:18:15 -07:00
|
|
|
#include <cstdarg>
|
|
|
|
|
|
|
|
#include "Common/Atomic.h"
|
|
|
|
#include "Common/CommonPaths.h"
|
|
|
|
#include "Common/Thread.h"
|
2014-06-05 17:29:54 -06:00
|
|
|
#include "Common/Logging/LogManager.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
|
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/Host.h"
|
|
|
|
|
|
|
|
#include "VideoBackends/OGL/FramebufferManager.h"
|
|
|
|
#include "VideoBackends/OGL/GLUtil.h"
|
|
|
|
#include "VideoBackends/OGL/PerfQuery.h"
|
|
|
|
#include "VideoBackends/OGL/PostProcessing.h"
|
|
|
|
#include "VideoBackends/OGL/ProgramShaderCache.h"
|
|
|
|
#include "VideoBackends/OGL/Render.h"
|
|
|
|
#include "VideoBackends/OGL/SamplerCache.h"
|
|
|
|
#include "VideoBackends/OGL/TextureCache.h"
|
|
|
|
#include "VideoBackends/OGL/TextureConverter.h"
|
|
|
|
#include "VideoBackends/OGL/VertexManager.h"
|
|
|
|
#include "VideoBackends/OGL/VideoBackend.h"
|
|
|
|
|
|
|
|
#include "VideoCommon/BPStructs.h"
|
|
|
|
#include "VideoCommon/CommandProcessor.h"
|
|
|
|
#include "VideoCommon/Fifo.h"
|
|
|
|
#include "VideoCommon/ImageWrite.h"
|
|
|
|
#include "VideoCommon/IndexGenerator.h"
|
|
|
|
#include "VideoCommon/LookUpTables.h"
|
|
|
|
#include "VideoCommon/MainBase.h"
|
|
|
|
#include "VideoCommon/OnScreenDisplay.h"
|
|
|
|
#include "VideoCommon/OpcodeDecoding.h"
|
|
|
|
#include "VideoCommon/PixelEngine.h"
|
|
|
|
#include "VideoCommon/PixelShaderManager.h"
|
|
|
|
#include "VideoCommon/VertexLoader.h"
|
|
|
|
#include "VideoCommon/VertexLoaderManager.h"
|
|
|
|
#include "VideoCommon/VertexShaderManager.h"
|
|
|
|
#include "VideoCommon/VideoConfig.h"
|
|
|
|
#include "VideoCommon/VideoState.h"
|
|
|
|
|
2009-01-11 06:37:13 -07:00
|
|
|
|
2008-12-07 22:25:12 -07:00
|
|
|
#ifdef _WIN32
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/IniFile.h"
|
2008-12-07 22:25:12 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "DolphinWX/VideoConfigDiag.h"
|
|
|
|
#include "DolphinWX/Debugger/DebuggerPanel.h"
|
2009-07-26 03:52:35 -06:00
|
|
|
#endif // HAVE_WX
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2011-01-30 18:28:32 -07:00
|
|
|
namespace OGL
|
2010-12-19 12:43:18 -07:00
|
|
|
{
|
2009-01-08 05:12:15 -07:00
|
|
|
|
2014-03-10 23:55:00 -06:00
|
|
|
std::string VideoBackend::GetName() const
|
2013-05-01 07:51:43 -06:00
|
|
|
{
|
|
|
|
return "OGL";
|
|
|
|
}
|
|
|
|
|
2014-03-10 23:55:00 -06:00
|
|
|
std::string VideoBackend::GetDisplayName() const
|
2009-07-02 11:11:27 -06:00
|
|
|
{
|
2014-02-03 08:59:23 -07:00
|
|
|
if (GLInterface != nullptr && GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3)
|
2014-01-17 21:11:59 -07:00
|
|
|
return "OpenGLES";
|
|
|
|
else
|
|
|
|
return "OpenGL";
|
2009-09-09 13:52:45 -06:00
|
|
|
}
|
2009-02-21 21:24:53 -07:00
|
|
|
|
2010-11-15 02:54:07 -07:00
|
|
|
void GetShaders(std::vector<std::string> &shaders)
|
|
|
|
{
|
2013-09-11 18:40:17 -06:00
|
|
|
std::set<std::string> already_found;
|
|
|
|
|
2011-12-11 03:08:18 -07:00
|
|
|
shaders.clear();
|
2013-09-11 18:40:17 -06:00
|
|
|
static const std::string directories[] = {
|
|
|
|
File::GetUserPath(D_SHADERS_IDX),
|
|
|
|
File::GetSysDirectory() + SHADERS_DIR DIR_SEP,
|
|
|
|
};
|
2013-10-28 23:09:01 -06:00
|
|
|
for (auto& directory : directories)
|
2011-12-11 03:08:18 -07:00
|
|
|
{
|
2013-10-28 23:09:01 -06:00
|
|
|
if (!File::IsDirectory(directory))
|
2013-09-11 18:40:17 -06:00
|
|
|
continue;
|
|
|
|
|
2011-12-11 03:14:02 -07:00
|
|
|
File::FSTEntry entry;
|
2013-10-28 23:09:01 -06:00
|
|
|
File::ScanDirectoryTree(directory, entry);
|
|
|
|
for (auto& file : entry.children)
|
2011-12-11 03:14:02 -07:00
|
|
|
{
|
2014-03-12 13:33:41 -06:00
|
|
|
std::string name = file.virtualName;
|
2013-09-11 18:40:17 -06:00
|
|
|
if (name.size() < 5)
|
|
|
|
continue;
|
|
|
|
if (strcasecmp(name.substr(name.size() - 5).c_str(), ".glsl"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
name = name.substr(0, name.size() - 5);
|
|
|
|
if (already_found.find(name) != already_found.end())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
already_found.insert(name);
|
|
|
|
shaders.push_back(name);
|
2011-12-11 03:14:02 -07:00
|
|
|
}
|
2011-12-11 03:08:18 -07:00
|
|
|
}
|
2013-09-11 18:40:17 -06:00
|
|
|
std::sort(shaders.begin(), shaders.end());
|
2010-11-15 02:54:07 -07:00
|
|
|
}
|
|
|
|
|
2010-11-22 15:17:35 -07:00
|
|
|
void InitBackendInfo()
|
2009-09-09 13:52:45 -06:00
|
|
|
{
|
2010-11-21 07:47:28 -07:00
|
|
|
g_Config.backend_info.APIType = API_OPENGL;
|
2013-01-14 15:43:51 -07:00
|
|
|
g_Config.backend_info.bUseRGBATextures = true;
|
2013-02-18 09:14:56 -07:00
|
|
|
g_Config.backend_info.bUseMinimalMipCount = false;
|
2010-11-24 10:13:12 -07:00
|
|
|
g_Config.backend_info.bSupports3DVision = false;
|
2013-07-22 04:02:16 -06:00
|
|
|
//g_Config.backend_info.bSupportsDualSourceBlend = true; // is gpu dependent and must be set in renderer
|
|
|
|
//g_Config.backend_info.bSupportsEarlyZ = true; // is gpu dependent and must be set in renderer
|
2013-10-14 07:16:42 -06:00
|
|
|
g_Config.backend_info.bSupportsOversizedViewports = true;
|
2010-11-22 15:17:35 -07:00
|
|
|
|
2014-04-12 01:17:36 -06:00
|
|
|
g_Config.backend_info.Adapters.clear();
|
|
|
|
|
2010-11-22 15:17:35 -07:00
|
|
|
// aamodes
|
2014-04-30 10:13:31 -06:00
|
|
|
const char* caamodes[] = {_trans("None"), "2x", "4x", "8x", "4x SSAA"};
|
2010-11-22 15:17:35 -07:00
|
|
|
g_Config.backend_info.AAModes.assign(caamodes, caamodes + sizeof(caamodes)/sizeof(*caamodes));
|
|
|
|
|
|
|
|
// pp shaders
|
|
|
|
GetShaders(g_Config.backend_info.PPShaders);
|
2011-05-31 14:16:59 -06:00
|
|
|
}
|
2010-11-22 15:17:35 -07:00
|
|
|
|
2011-05-31 14:16:59 -06:00
|
|
|
void VideoBackend::ShowConfig(void *_hParent)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
InitBackendInfo();
|
2011-03-21 13:57:31 -06:00
|
|
|
VideoConfigDiag diag((wxWindow*)_hParent, "OpenGL", "gfx_opengl");
|
2011-03-16 16:22:21 -06:00
|
|
|
diag.ShowModal();
|
2009-07-02 11:11:27 -06:00
|
|
|
#endif
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
2013-06-19 01:17:33 -06:00
|
|
|
|
2011-02-25 14:14:13 -07:00
|
|
|
bool VideoBackend::Initialize(void *&window_handle)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2012-01-02 03:20:22 -07:00
|
|
|
InitializeShared();
|
2010-11-22 15:17:35 -07:00
|
|
|
InitBackendInfo();
|
2013-06-19 01:17:33 -06:00
|
|
|
|
2010-02-24 23:12:35 -07:00
|
|
|
frameCount = 0;
|
2009-09-09 13:52:45 -06:00
|
|
|
|
2014-03-12 13:33:41 -06:00
|
|
|
g_Config.Load(File::GetUserPath(D_CONFIG_IDX) + "gfx_opengl.ini");
|
2013-09-23 00:39:14 -06:00
|
|
|
g_Config.GameIniLoad();
|
2009-08-01 12:31:25 -06:00
|
|
|
g_Config.UpdateProjectionHack();
|
2011-05-31 14:16:59 -06:00
|
|
|
g_Config.VerifyValidity();
|
2009-09-13 02:21:35 -06:00
|
|
|
UpdateActiveConfig();
|
2009-07-30 19:55:26 -06:00
|
|
|
|
2013-06-19 01:17:33 -06:00
|
|
|
InitInterface();
|
2014-01-17 21:11:59 -07:00
|
|
|
GLInterface->SetMode(GLInterfaceMode::MODE_DETECT);
|
2013-06-19 01:17:33 -06:00
|
|
|
if (!GLInterface->Create(window_handle))
|
|
|
|
return false;
|
|
|
|
|
2013-10-28 23:23:17 -06:00
|
|
|
// Do our OSD callbacks
|
2013-06-19 01:17:33 -06:00
|
|
|
OSD::DoCallbacks(OSD::OSD_INIT);
|
|
|
|
|
2011-02-13 19:18:03 -07:00
|
|
|
s_BackendInitialized = true;
|
2011-02-25 14:14:13 -07:00
|
|
|
|
2011-03-02 08:13:13 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is called after Initialize() from the Core
|
|
|
|
// Run from the graphics thread
|
|
|
|
void VideoBackend::Video_Prepare()
|
|
|
|
{
|
2012-12-17 13:54:20 -07:00
|
|
|
GLInterface->MakeCurrent();
|
2010-11-17 19:21:26 -07:00
|
|
|
|
2011-01-30 18:28:32 -07:00
|
|
|
g_renderer = new Renderer;
|
2010-09-30 09:24:34 -06:00
|
|
|
|
2011-02-02 10:09:39 -07:00
|
|
|
s_efbAccessRequested = false;
|
|
|
|
s_FifoShuttingDown = false;
|
|
|
|
s_swapRequested = false;
|
2010-09-30 09:24:34 -06:00
|
|
|
|
2010-09-30 10:11:31 -06:00
|
|
|
CommandProcessor::Init();
|
|
|
|
PixelEngine::Init();
|
|
|
|
|
2010-09-30 09:24:34 -06:00
|
|
|
BPInit();
|
2011-01-30 18:28:32 -07:00
|
|
|
g_vertex_manager = new VertexManager;
|
2012-06-17 05:58:29 -06:00
|
|
|
g_perf_query = new PerfQuery;
|
2010-09-30 10:11:31 -06:00
|
|
|
Fifo_Init(); // must be done before OpcodeDecoder_Init()
|
2010-09-30 09:24:34 -06:00
|
|
|
OpcodeDecoder_Init();
|
2013-04-08 11:39:43 -06:00
|
|
|
IndexGenerator::Init();
|
2010-09-30 09:24:34 -06:00
|
|
|
VertexShaderManager::Init();
|
|
|
|
PixelShaderManager::Init();
|
2011-12-09 16:30:05 -07:00
|
|
|
ProgramShaderCache::Init();
|
2013-03-07 09:00:11 -07:00
|
|
|
PostProcessing::Init();
|
2013-02-26 10:30:13 -07:00
|
|
|
g_texture_cache = new TextureCache();
|
|
|
|
g_sampler_cache = new SamplerCache();
|
2013-01-25 12:39:19 -07:00
|
|
|
Renderer::Init();
|
2010-09-30 10:11:31 -06:00
|
|
|
GL_REPORT_ERRORD();
|
|
|
|
VertexLoaderManager::Init();
|
2011-01-30 18:28:32 -07:00
|
|
|
TextureConverter::Init();
|
2010-09-30 09:24:34 -06:00
|
|
|
|
2011-02-13 19:18:03 -07:00
|
|
|
// Notify the core that the video backend is ready
|
2011-03-15 17:09:12 -06:00
|
|
|
Host_Message(WM_USER_CREATE);
|
2010-09-30 09:24:34 -06:00
|
|
|
}
|
|
|
|
|
2011-01-30 18:28:32 -07:00
|
|
|
void VideoBackend::Shutdown()
|
2010-09-30 09:24:34 -06:00
|
|
|
{
|
2011-02-13 19:18:03 -07:00
|
|
|
s_BackendInitialized = false;
|
2013-04-12 23:48:53 -06:00
|
|
|
|
2013-10-28 23:23:17 -06:00
|
|
|
// Do our OSD callbacks
|
2013-04-12 23:48:53 -06:00
|
|
|
OSD::DoCallbacks(OSD::OSD_SHUTDOWN);
|
|
|
|
|
2013-02-26 08:42:32 -07:00
|
|
|
GLInterface->Shutdown();
|
|
|
|
}
|
2010-09-30 09:24:34 -06:00
|
|
|
|
2013-02-26 08:42:32 -07:00
|
|
|
void VideoBackend::Video_Cleanup() {
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2011-03-02 08:13:13 -07:00
|
|
|
if (g_renderer)
|
|
|
|
{
|
|
|
|
s_efbAccessRequested = false;
|
|
|
|
s_FifoShuttingDown = false;
|
|
|
|
s_swapRequested = false;
|
|
|
|
Fifo_Shutdown();
|
|
|
|
|
|
|
|
// The following calls are NOT Thread Safe
|
|
|
|
// And need to be called from the video thread
|
2013-01-25 12:39:19 -07:00
|
|
|
Renderer::Shutdown();
|
2011-03-02 08:13:13 -07:00
|
|
|
TextureConverter::Shutdown();
|
|
|
|
VertexLoaderManager::Shutdown();
|
2013-02-26 10:30:13 -07:00
|
|
|
delete g_sampler_cache;
|
2014-03-09 14:14:26 -06:00
|
|
|
g_sampler_cache = nullptr;
|
2013-01-26 08:33:54 -07:00
|
|
|
delete g_texture_cache;
|
2014-03-09 14:14:26 -06:00
|
|
|
g_texture_cache = nullptr;
|
2013-03-07 09:00:11 -07:00
|
|
|
PostProcessing::Shutdown();
|
2011-12-09 16:30:05 -07:00
|
|
|
ProgramShaderCache::Shutdown();
|
2011-03-02 08:13:13 -07:00
|
|
|
VertexShaderManager::Shutdown();
|
|
|
|
PixelShaderManager::Shutdown();
|
2013-08-15 05:52:31 -06:00
|
|
|
delete g_perf_query;
|
2014-03-09 14:14:26 -06:00
|
|
|
g_perf_query = nullptr;
|
2011-03-02 08:13:13 -07:00
|
|
|
delete g_vertex_manager;
|
2014-03-09 14:14:26 -06:00
|
|
|
g_vertex_manager = nullptr;
|
2011-03-02 08:13:13 -07:00
|
|
|
OpcodeDecoder_Shutdown();
|
|
|
|
delete g_renderer;
|
2014-03-09 14:14:26 -06:00
|
|
|
g_renderer = nullptr;
|
2013-04-10 19:32:07 -06:00
|
|
|
GLInterface->ClearCurrent();
|
2011-03-02 08:13:13 -07:00
|
|
|
}
|
2010-09-30 09:24:34 -06:00
|
|
|
}
|
2011-01-30 18:28:32 -07:00
|
|
|
|
|
|
|
}
|