2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:29:41 +00:00
|
|
|
// 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
|
2013-10-29 05:23:17 +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
|
|
|
|
2013-03-07 18:11:50 +00:00
|
|
|
#include <algorithm>
|
2014-02-17 10:18:15 +00:00
|
|
|
#include <cstdarg>
|
2015-12-21 02:49:49 +00:00
|
|
|
#include <memory>
|
2014-02-17 10:18:15 +00:00
|
|
|
|
|
|
|
#include "Common/Atomic.h"
|
|
|
|
#include "Common/CommonPaths.h"
|
2014-11-15 20:46:40 +00:00
|
|
|
#include "Common/FileSearch.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/Thread.h"
|
2015-09-18 16:40:00 +00:00
|
|
|
#include "Common/GL/GLInterfaceBase.h"
|
|
|
|
#include "Common/GL/GLUtil.h"
|
2014-06-05 23:29:54 +00:00
|
|
|
#include "Common/Logging/LogManager.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
|
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/Host.h"
|
|
|
|
|
2014-11-13 22:26:49 +00:00
|
|
|
#include "VideoBackends/OGL/BoundingBox.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoBackends/OGL/FramebufferManager.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"
|
2014-12-14 20:23:13 +00:00
|
|
|
#include "VideoCommon/GeometryShaderManager.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#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/VertexLoaderManager.h"
|
|
|
|
#include "VideoCommon/VertexShaderManager.h"
|
|
|
|
#include "VideoCommon/VideoConfig.h"
|
|
|
|
#include "VideoCommon/VideoState.h"
|
|
|
|
|
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
|
|
|
|
2015-09-18 17:40:46 +00:00
|
|
|
// Draw messages on top of the screen
|
|
|
|
unsigned int VideoBackend::PeekMessages()
|
|
|
|
{
|
|
|
|
return GLInterface->PeekMessages();
|
|
|
|
}
|
|
|
|
|
2014-03-11 05:55:00 +00:00
|
|
|
std::string VideoBackend::GetName() const
|
2013-05-01 13:51:43 +00:00
|
|
|
{
|
|
|
|
return "OGL";
|
|
|
|
}
|
|
|
|
|
2014-03-11 05:55:00 +00:00
|
|
|
std::string VideoBackend::GetDisplayName() const
|
2009-07-02 17:11:27 +00:00
|
|
|
{
|
2014-02-03 15:59:23 +00:00
|
|
|
if (GLInterface != nullptr && GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3)
|
2014-01-18 04:11:59 +00:00
|
|
|
return "OpenGLES";
|
|
|
|
else
|
|
|
|
return "OpenGL";
|
2009-09-09 19:52:45 +00:00
|
|
|
}
|
2009-02-22 04:24:53 +00:00
|
|
|
|
2014-11-15 20:46:40 +00:00
|
|
|
static std::vector<std::string> GetShaders(const std::string &sub_dir = "")
|
2010-11-15 09:54:07 +00:00
|
|
|
{
|
2015-09-22 00:01:08 +00:00
|
|
|
std::vector<std::string> paths = DoFileSearch({".glsl"}, {
|
2015-01-03 00:33:30 +00:00
|
|
|
File::GetUserPath(D_SHADERS_IDX) + sub_dir,
|
2014-11-15 20:46:40 +00:00
|
|
|
File::GetSysDirectory() + SHADERS_DIR DIR_SEP + sub_dir
|
|
|
|
});
|
|
|
|
std::vector<std::string> result;
|
|
|
|
for (std::string path : paths)
|
2015-09-27 17:26:10 +00:00
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
SplitPath(path, nullptr, &name, nullptr);
|
|
|
|
result.push_back(name);
|
|
|
|
}
|
2014-11-15 20:46:40 +00:00
|
|
|
return result;
|
2010-11-15 09:54:07 +00:00
|
|
|
}
|
|
|
|
|
2014-07-08 12:29:26 +00:00
|
|
|
static 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;
|
2014-07-19 18:18:03 +00:00
|
|
|
g_Config.backend_info.bSupportsExclusiveFullscreen = false;
|
2013-10-14 13:16:42 +00:00
|
|
|
g_Config.backend_info.bSupportsOversizedViewports = true;
|
2014-12-16 23:26:03 +00:00
|
|
|
g_Config.backend_info.bSupportsGeometryShaders = true;
|
2014-11-13 23:24:53 +00:00
|
|
|
g_Config.backend_info.bSupports3DVision = false;
|
2015-01-03 00:33:30 +00:00
|
|
|
g_Config.backend_info.bSupportsPostProcessing = true;
|
2015-09-01 05:17:24 +00:00
|
|
|
g_Config.backend_info.bSupportsSSAA = true;
|
2010-11-22 22:17:35 +00:00
|
|
|
|
2014-04-12 07:17:36 +00:00
|
|
|
g_Config.backend_info.Adapters.clear();
|
|
|
|
|
2015-09-15 01:49:48 +00:00
|
|
|
// aamodes - 1 is to stay consistent with D3D (means no AA)
|
2015-10-10 14:47:58 +00:00
|
|
|
g_Config.backend_info.AAModes = { 1, 2, 4, 8 };
|
2010-11-22 22:17:35 +00:00
|
|
|
|
|
|
|
// pp shaders
|
2014-11-15 20:46:40 +00:00
|
|
|
g_Config.backend_info.PPShaders = GetShaders("");
|
|
|
|
g_Config.backend_info.AnaglyphShaders = GetShaders(ANAGLYPH_DIR DIR_SEP);
|
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)
|
|
|
|
{
|
2014-12-20 18:13:34 +00:00
|
|
|
if (!s_BackendInitialized)
|
|
|
|
InitBackendInfo();
|
2015-12-22 23:35:19 +00:00
|
|
|
Host_ShowVideoConfig(_hParent, GetDisplayName(), "gfx_opengl");
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2013-06-19 07:17:33 +00:00
|
|
|
|
2014-08-06 04:44:21 +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
|
|
|
|
2015-12-22 23:35:19 +00:00
|
|
|
g_Config.Load(File::GetUserPath(D_CONFIG_IDX) + "gfx_opengl.ini");
|
2013-09-23 06:39:14 +00:00
|
|
|
g_Config.GameIniLoad();
|
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();
|
2014-01-18 04:11:59 +00:00
|
|
|
GLInterface->SetMode(GLInterfaceMode::MODE_DETECT);
|
2013-06-19 07:17:33 +00:00
|
|
|
if (!GLInterface->Create(window_handle))
|
|
|
|
return false;
|
|
|
|
|
2013-10-29 05:23:17 +00:00
|
|
|
// Do our OSD callbacks
|
2013-06-19 07:17:33 +00:00
|
|
|
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
|
|
|
|
2015-12-21 02:49:49 +00:00
|
|
|
g_renderer = std::make_unique<Renderer>();
|
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();
|
2015-12-21 02:49:49 +00:00
|
|
|
g_vertex_manager = std::make_unique<VertexManager>();
|
2015-02-21 22:58:53 +00:00
|
|
|
g_perf_query = GetPerfQuery();
|
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();
|
2014-12-14 20:23:13 +00:00
|
|
|
GeometryShaderManager::Init();
|
2011-12-09 23:30:05 +00:00
|
|
|
ProgramShaderCache::Init();
|
2015-12-21 02:49:49 +00:00
|
|
|
g_texture_cache = std::make_unique<TextureCache>();
|
|
|
|
g_sampler_cache = std::make_unique<SamplerCache>();
|
2013-01-25 19:39:19 +00:00
|
|
|
Renderer::Init();
|
2010-09-30 16:11:31 +00:00
|
|
|
VertexLoaderManager::Init();
|
2011-01-31 01:28:32 +00:00
|
|
|
TextureConverter::Init();
|
2014-11-13 22:26:49 +00:00
|
|
|
BoundingBox::Init();
|
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
|
|
|
|
2013-10-29 05:23:17 +00:00
|
|
|
// Do our OSD callbacks
|
2013-04-13 05:48:53 +00:00
|
|
|
OSD::DoCallbacks(OSD::OSD_SHUTDOWN);
|
|
|
|
|
2013-02-26 15:42:32 +00:00
|
|
|
GLInterface->Shutdown();
|
2015-12-21 02:49:49 +00:00
|
|
|
GLInterface.reset();
|
2013-02-26 15:42:32 +00:00
|
|
|
}
|
2010-09-30 15:24:34 +00:00
|
|
|
|
2014-08-15 18:09:53 +00:00
|
|
|
void VideoBackend::Video_Cleanup()
|
|
|
|
{
|
2015-12-21 02:49:49 +00:00
|
|
|
if (!g_renderer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Fifo_Shutdown();
|
|
|
|
|
|
|
|
// The following calls are NOT Thread Safe
|
|
|
|
// And need to be called from the video thread
|
|
|
|
Renderer::Shutdown();
|
|
|
|
BoundingBox::Shutdown();
|
|
|
|
TextureConverter::Shutdown();
|
|
|
|
VertexLoaderManager::Shutdown();
|
|
|
|
g_sampler_cache.reset();
|
|
|
|
g_texture_cache.reset();
|
|
|
|
ProgramShaderCache::Shutdown();
|
|
|
|
VertexShaderManager::Shutdown();
|
|
|
|
PixelShaderManager::Shutdown();
|
|
|
|
GeometryShaderManager::Shutdown();
|
|
|
|
|
|
|
|
g_perf_query.reset();
|
|
|
|
g_vertex_manager.reset();
|
|
|
|
|
|
|
|
OpcodeDecoder_Shutdown();
|
|
|
|
g_renderer.reset();
|
|
|
|
GLInterface->ClearCurrent();
|
2010-09-30 15:24:34 +00:00
|
|
|
}
|
2011-01-31 01:28:32 +00:00
|
|
|
|
|
|
|
}
|