2013-04-18 03:29:41 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-06-06 13:36:33 +00:00
|
|
|
|
2009-06-15 06:39:26 +00:00
|
|
|
|
2011-02-14 02:18:03 +00:00
|
|
|
// OpenGL Backend Documentation
|
2009-06-15 06:39:26 +00:00
|
|
|
/*
|
2009-06-06 13:36:33 +00:00
|
|
|
|
|
|
|
1.1 Display settings
|
2009-06-15 06:39:26 +00:00
|
|
|
|
2009-09-09 19:52:45 +00: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 13:36:33 +00:00
|
|
|
|
2009-09-09 19:52:45 +00: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 13:36:33 +00:00
|
|
|
|
2009-06-07 11:51:53 +00:00
|
|
|
1.2 Screenshots
|
2009-06-15 06:39:26 +00:00
|
|
|
|
2009-06-07 11:51:53 +00:00
|
|
|
|
2009-09-09 19:52:45 +00: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 11:51:53 +00:00
|
|
|
|
2009-09-09 19:52:45 +00:00
|
|
|
Todo: Render AA and wireframe to a separate picture used for the screenshot in
|
|
|
|
addition to the one for display.
|
2009-06-07 11:51:53 +00:00
|
|
|
|
|
|
|
1.3 AA
|
2009-06-15 06:39:26 +00:00
|
|
|
|
2009-06-07 11:51:53 +00:00
|
|
|
Make AA apply instantly during gameplay if possible
|
|
|
|
|
2009-06-15 06:39:26 +00:00
|
|
|
*/
|
2009-06-06 13:36:33 +00:00
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "Globals.h"
|
2009-07-13 05:38:34 +00:00
|
|
|
#include "Atomic.h"
|
2010-09-30 15:24:34 +00:00
|
|
|
#include "Thread.h"
|
|
|
|
#include "LogManager.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-01-11 13:37:13 +00:00
|
|
|
#include <cstdarg>
|
2013-03-07 18:11:50 +00:00
|
|
|
#include <algorithm>
|
2009-01-11 13:37:13 +00:00
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
#ifdef _WIN32
|
2010-12-19 19:43:18 +00:00
|
|
|
#include "EmuWindow.h"
|
2011-01-14 15:09:30 +00:00
|
|
|
#include "IniFile.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2010-11-15 09:54:07 +00:00
|
|
|
#include "VideoConfigDiag.h"
|
2011-02-13 06:06:32 +00:00
|
|
|
#include "Debugger/DebuggerPanel.h"
|
2009-07-26 09:52:35 +00:00
|
|
|
#endif // HAVE_WX
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2010-11-18 02:21:26 +00:00
|
|
|
#include "MainBase.h"
|
2009-09-13 09:23:30 +00:00
|
|
|
#include "VideoConfig.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "LookUpTables.h"
|
|
|
|
#include "ImageWrite.h"
|
|
|
|
#include "Render.h"
|
|
|
|
#include "GLUtil.h"
|
|
|
|
#include "Fifo.h"
|
|
|
|
#include "OpcodeDecoding.h"
|
2010-09-28 02:15:02 +00:00
|
|
|
#include "TextureCache.h"
|
2009-06-22 09:31:30 +00:00
|
|
|
#include "BPStructs.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "VertexLoader.h"
|
|
|
|
#include "VertexLoaderManager.h"
|
|
|
|
#include "VertexManager.h"
|
|
|
|
#include "PixelShaderManager.h"
|
|
|
|
#include "VertexShaderManager.h"
|
2011-12-09 23:30:05 +00:00
|
|
|
#include "ProgramShaderCache.h"
|
2009-10-10 21:19:39 +00:00
|
|
|
#include "CommandProcessor.h"
|
|
|
|
#include "PixelEngine.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "TextureConverter.h"
|
2009-06-08 19:42:25 +00:00
|
|
|
#include "PostProcessing.h"
|
2009-02-21 12:53:10 +00:00
|
|
|
#include "OnScreenDisplay.h"
|
2009-08-09 11:03:58 +00:00
|
|
|
#include "DLCache.h"
|
2010-11-18 02:21:26 +00:00
|
|
|
#include "FramebufferManager.h"
|
2011-01-31 01:28:32 +00:00
|
|
|
#include "Core.h"
|
2011-03-15 23:09:12 +00:00
|
|
|
#include "Host.h"
|
2013-02-26 17:30:13 +00:00
|
|
|
#include "SamplerCache.h"
|
2012-06-17 11:58:29 +00:00
|
|
|
#include "PerfQuery.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
#include "VideoState.h"
|
2013-04-08 17:39:43 +00:00
|
|
|
#include "IndexGenerator.h"
|
2011-01-31 01:28:32 +00:00
|
|
|
#include "VideoBackend.h"
|
|
|
|
#include "ConfigManager.h"
|
2008-12-14 23:52:01 +00:00
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
namespace OGL
|
2010-12-19 19:43:18 +00:00
|
|
|
{
|
2009-01-08 12:12:15 +00:00
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
std::string VideoBackend::GetName()
|
2013-05-01 13:51:43 +00:00
|
|
|
{
|
|
|
|
return "OGL";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string VideoBackend::GetDisplayName()
|
2009-07-02 17:11:27 +00:00
|
|
|
{
|
2011-01-31 01:28:32 +00:00
|
|
|
return "OpenGL";
|
2009-09-09 19:52:45 +00:00
|
|
|
}
|
2009-02-22 04:24:53 +00:00
|
|
|
|
2010-11-15 09:54:07 +00:00
|
|
|
void GetShaders(std::vector<std::string> &shaders)
|
|
|
|
{
|
2011-12-11 10:08:18 +00:00
|
|
|
shaders.clear();
|
|
|
|
if (File::IsDirectory(File::GetUserPath(D_SHADERS_IDX)))
|
|
|
|
{
|
2011-12-11 10:14:02 +00:00
|
|
|
File::FSTEntry entry;
|
|
|
|
File::ScanDirectoryTree(File::GetUserPath(D_SHADERS_IDX), entry);
|
|
|
|
for (u32 i = 0; i < entry.children.size(); i++)
|
|
|
|
{
|
|
|
|
std::string name = entry.children[i].virtualName.c_str();
|
2013-03-07 18:11:50 +00:00
|
|
|
if (!strcasecmp(name.substr(name.size() - 4).c_str(), ".txt")) {
|
2011-12-11 10:14:02 +00:00
|
|
|
name = name.substr(0, name.size() - 4);
|
2013-03-07 18:11:50 +00:00
|
|
|
shaders.push_back(name);
|
|
|
|
}
|
2011-12-11 10:14:02 +00:00
|
|
|
}
|
2013-03-07 18:11:50 +00:00
|
|
|
std::sort(shaders.begin(), shaders.end());
|
2011-12-11 10:08:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-11 10:14:02 +00:00
|
|
|
File::CreateDir(File::GetUserPath(D_SHADERS_IDX).c_str());
|
2011-12-11 10:08:18 +00:00
|
|
|
}
|
2010-11-15 09:54:07 +00:00
|
|
|
}
|
|
|
|
|
2010-11-22 22:17:35 +00:00
|
|
|
void InitBackendInfo()
|
2009-09-09 19:52:45 +00:00
|
|
|
{
|
2010-11-21 14:47:28 +00:00
|
|
|
g_Config.backend_info.APIType = API_OPENGL;
|
2013-01-14 22:43:51 +00:00
|
|
|
g_Config.backend_info.bUseRGBATextures = true;
|
2013-02-18 16:14:56 +00:00
|
|
|
g_Config.backend_info.bUseMinimalMipCount = false;
|
2010-11-24 17:13:12 +00:00
|
|
|
g_Config.backend_info.bSupports3DVision = false;
|
2013-03-05 17:35:30 +00:00
|
|
|
//g_Config.backend_info.bSupportsDualSourceBlend = true; // is gpu depenend and must be set in renderer
|
2010-12-27 21:56:20 +00:00
|
|
|
g_Config.backend_info.bSupportsFormatReinterpretation = false;
|
2011-01-09 14:13:24 +00:00
|
|
|
g_Config.backend_info.bSupportsPixelLighting = true;
|
2010-11-22 22:17:35 +00:00
|
|
|
|
|
|
|
// aamodes
|
2013-04-02 22:44:27 +00:00
|
|
|
const char* caamodes[] = {_trans("None"), "2x", "4x", "8x", "8x CSAA", "8xQ CSAA", "16x CSAA", "16xQ CSAA", "4x SSAA"};
|
2010-11-22 22:17:35 +00:00
|
|
|
g_Config.backend_info.AAModes.assign(caamodes, caamodes + sizeof(caamodes)/sizeof(*caamodes));
|
|
|
|
|
|
|
|
// pp shaders
|
|
|
|
GetShaders(g_Config.backend_info.PPShaders);
|
2011-05-31 20:16:59 +00:00
|
|
|
}
|
2010-11-22 22:17:35 +00:00
|
|
|
|
2011-05-31 20:16:59 +00:00
|
|
|
void VideoBackend::ShowConfig(void *_hParent)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
InitBackendInfo();
|
2011-03-21 19:57:31 +00:00
|
|
|
VideoConfigDiag diag((wxWindow*)_hParent, "OpenGL", "gfx_opengl");
|
2011-03-16 22:22:21 +00:00
|
|
|
diag.ShowModal();
|
2009-07-02 17:11:27 +00:00
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2013-06-19 07:17:33 +00:00
|
|
|
|
2011-02-25 21:14:13 +00:00
|
|
|
bool VideoBackend::Initialize(void *&window_handle)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2012-01-02 10:20:22 +00:00
|
|
|
InitializeShared();
|
2010-11-22 22:17:35 +00:00
|
|
|
InitBackendInfo();
|
2013-06-19 07:17:33 +00:00
|
|
|
|
2010-02-25 06:12:35 +00:00
|
|
|
frameCount = 0;
|
2009-09-09 19:52:45 +00:00
|
|
|
|
2011-04-25 20:06:45 +00:00
|
|
|
g_Config.Load((File::GetUserPath(D_CONFIG_IDX) + "gfx_opengl.ini").c_str());
|
|
|
|
g_Config.GameIniLoad(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strGameIni.c_str());
|
2009-08-01 18:31:25 +00:00
|
|
|
g_Config.UpdateProjectionHack();
|
2011-05-31 20:16:59 +00:00
|
|
|
g_Config.VerifyValidity();
|
2009-09-13 08:21:35 +00:00
|
|
|
UpdateActiveConfig();
|
2009-07-31 01:55:26 +00:00
|
|
|
|
2013-06-19 07:17:33 +00:00
|
|
|
InitInterface();
|
|
|
|
if (!GLInterface->Create(window_handle))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Do our OSD callbacks
|
|
|
|
OSD::DoCallbacks(OSD::OSD_INIT);
|
|
|
|
|
2011-02-14 02:18:03 +00:00
|
|
|
s_BackendInitialized = true;
|
2011-02-25 21:14:13 +00:00
|
|
|
|
2011-03-02 15:13:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is called after Initialize() from the Core
|
|
|
|
// Run from the graphics thread
|
|
|
|
void VideoBackend::Video_Prepare()
|
|
|
|
{
|
2012-12-17 20:54:20 +00:00
|
|
|
GLInterface->MakeCurrent();
|
2010-11-18 02:21:26 +00:00
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
g_renderer = new Renderer;
|
2010-09-30 15:24:34 +00:00
|
|
|
|
2011-02-02 17:09:39 +00:00
|
|
|
s_efbAccessRequested = false;
|
|
|
|
s_FifoShuttingDown = false;
|
|
|
|
s_swapRequested = false;
|
2010-09-30 15:24:34 +00:00
|
|
|
|
2010-09-30 16:11:31 +00:00
|
|
|
CommandProcessor::Init();
|
|
|
|
PixelEngine::Init();
|
|
|
|
|
2010-09-30 15:24:34 +00:00
|
|
|
BPInit();
|
2011-01-31 01:28:32 +00:00
|
|
|
g_vertex_manager = new VertexManager;
|
2012-06-17 11:58:29 +00:00
|
|
|
g_perf_query = new PerfQuery;
|
2010-09-30 16:11:31 +00:00
|
|
|
Fifo_Init(); // must be done before OpcodeDecoder_Init()
|
2010-09-30 15:24:34 +00:00
|
|
|
OpcodeDecoder_Init();
|
2013-04-08 17:39:43 +00:00
|
|
|
IndexGenerator::Init();
|
2010-09-30 15:24:34 +00:00
|
|
|
VertexShaderManager::Init();
|
|
|
|
PixelShaderManager::Init();
|
2011-12-09 23:30:05 +00:00
|
|
|
ProgramShaderCache::Init();
|
2013-03-07 16:00:11 +00:00
|
|
|
PostProcessing::Init();
|
2013-02-26 17:30:13 +00:00
|
|
|
g_texture_cache = new TextureCache();
|
|
|
|
g_sampler_cache = new SamplerCache();
|
2013-01-25 19:39:19 +00:00
|
|
|
Renderer::Init();
|
2010-09-30 16:11:31 +00:00
|
|
|
GL_REPORT_ERRORD();
|
|
|
|
VertexLoaderManager::Init();
|
2011-01-31 01:28:32 +00:00
|
|
|
TextureConverter::Init();
|
2013-02-26 19:49:00 +00:00
|
|
|
#ifndef _M_GENERIC
|
2010-09-30 15:24:34 +00:00
|
|
|
DLCache::Init();
|
2013-02-26 19:49:00 +00:00
|
|
|
#endif
|
2010-09-30 15:24:34 +00:00
|
|
|
|
2011-02-14 02:18:03 +00:00
|
|
|
// Notify the core that the video backend is ready
|
2011-03-15 23:09:12 +00:00
|
|
|
Host_Message(WM_USER_CREATE);
|
2010-09-30 15:24:34 +00:00
|
|
|
}
|
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
void VideoBackend::Shutdown()
|
2010-09-30 15:24:34 +00:00
|
|
|
{
|
2011-02-14 02:18:03 +00:00
|
|
|
s_BackendInitialized = false;
|
2013-04-13 05:48:53 +00:00
|
|
|
|
|
|
|
// Do our OSD callbacks
|
|
|
|
OSD::DoCallbacks(OSD::OSD_SHUTDOWN);
|
|
|
|
|
2013-02-26 15:42:32 +00:00
|
|
|
GLInterface->Shutdown();
|
|
|
|
}
|
2010-09-30 15:24:34 +00:00
|
|
|
|
2013-02-26 15:42:32 +00:00
|
|
|
void VideoBackend::Video_Cleanup() {
|
|
|
|
|
2011-03-02 15:13:13 +00:00
|
|
|
if (g_renderer)
|
|
|
|
{
|
|
|
|
s_efbAccessRequested = false;
|
|
|
|
s_FifoShuttingDown = false;
|
|
|
|
s_swapRequested = false;
|
2013-02-26 19:49:00 +00:00
|
|
|
#ifndef _M_GENERIC
|
2011-03-02 15:13:13 +00:00
|
|
|
DLCache::Shutdown();
|
2013-02-26 19:49:00 +00:00
|
|
|
#endif
|
2011-03-02 15:13:13 +00:00
|
|
|
Fifo_Shutdown();
|
|
|
|
|
|
|
|
// The following calls are NOT Thread Safe
|
|
|
|
// And need to be called from the video thread
|
2013-01-25 19:39:19 +00:00
|
|
|
Renderer::Shutdown();
|
2011-03-02 15:13:13 +00:00
|
|
|
TextureConverter::Shutdown();
|
|
|
|
VertexLoaderManager::Shutdown();
|
2013-02-26 17:30:13 +00:00
|
|
|
delete g_sampler_cache;
|
|
|
|
g_sampler_cache = NULL;
|
2013-01-26 15:33:54 +00:00
|
|
|
delete g_texture_cache;
|
|
|
|
g_texture_cache = NULL;
|
2013-03-07 16:00:11 +00:00
|
|
|
PostProcessing::Shutdown();
|
2011-12-09 23:30:05 +00:00
|
|
|
ProgramShaderCache::Shutdown();
|
2011-03-02 15:13:13 +00:00
|
|
|
VertexShaderManager::Shutdown();
|
|
|
|
PixelShaderManager::Shutdown();
|
|
|
|
delete g_vertex_manager;
|
2013-01-26 15:33:54 +00:00
|
|
|
g_vertex_manager = NULL;
|
2011-03-02 15:13:13 +00:00
|
|
|
OpcodeDecoder_Shutdown();
|
|
|
|
delete g_renderer;
|
|
|
|
g_renderer = NULL;
|
2013-04-11 01:32:07 +00:00
|
|
|
GLInterface->ClearCurrent();
|
2011-03-02 15:13:13 +00:00
|
|
|
}
|
2010-09-30 15:24:34 +00:00
|
|
|
}
|
2011-01-31 01:28:32 +00:00
|
|
|
|
|
|
|
}
|