2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2021-07-04 19:22:19 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2011-02-13 19:18:03 -07:00
|
|
|
// OpenGL Backend Documentation
|
2009-06-15 00:39:26 -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
|
|
|
|
2021-12-09 19:22:16 -07:00
|
|
|
#include "VideoBackends/OGL/VideoBackend.h"
|
|
|
|
|
2015-12-20 19:49:49 -07:00
|
|
|
#include <memory>
|
2016-01-02 13:01:12 -07:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2014-02-17 03:18:15 -07:00
|
|
|
|
2018-06-30 02:53:24 -06:00
|
|
|
#include "Common/Common.h"
|
2018-10-03 07:02:45 -06:00
|
|
|
#include "Common/GL/GLContext.h"
|
2015-09-18 10:40:00 -06:00
|
|
|
#include "Common/GL/GLUtil.h"
|
2017-03-09 07:01:23 -07:00
|
|
|
#include "Common/MsgHandler.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
|
2018-10-03 07:03:36 -06:00
|
|
|
#include "Core/Config/GraphicsSettings.h"
|
|
|
|
|
2020-09-15 06:00:24 -06:00
|
|
|
#include "VideoBackends/OGL/OGLPerfQuery.h"
|
|
|
|
#include "VideoBackends/OGL/OGLRender.h"
|
|
|
|
#include "VideoBackends/OGL/OGLVertexManager.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoBackends/OGL/ProgramShaderCache.h"
|
|
|
|
#include "VideoBackends/OGL/SamplerCache.h"
|
|
|
|
|
2019-02-14 18:59:50 -07:00
|
|
|
#include "VideoCommon/FramebufferManager.h"
|
|
|
|
#include "VideoCommon/TextureCacheBase.h"
|
2019-12-22 11:40:40 -07:00
|
|
|
#include "VideoCommon/VideoCommon.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoCommon/VideoConfig.h"
|
|
|
|
|
2011-01-30 18:28:32 -07:00
|
|
|
namespace OGL
|
2010-12-19 12:43:18 -07:00
|
|
|
{
|
2014-03-10 23:55:00 -06:00
|
|
|
std::string VideoBackend::GetName() const
|
2013-05-01 07:51:43 -06:00
|
|
|
{
|
2020-09-06 04:56:45 -06:00
|
|
|
return NAME;
|
2013-05-01 07:51:43 -06:00
|
|
|
}
|
|
|
|
|
2014-03-10 23:55:00 -06:00
|
|
|
std::string VideoBackend::GetDisplayName() const
|
2009-07-02 11:11:27 -06:00
|
|
|
{
|
2018-11-07 04:20:12 -07:00
|
|
|
if (g_ogl_config.bIsES)
|
2018-06-30 02:53:24 -06:00
|
|
|
return _trans("OpenGL ES");
|
2014-01-17 21:11:59 -07:00
|
|
|
else
|
2018-06-30 02:53:24 -06:00
|
|
|
return _trans("OpenGL");
|
2009-09-09 13:52:45 -06:00
|
|
|
}
|
2009-02-21 21:24:53 -07:00
|
|
|
|
2016-01-13 13:38:11 -07:00
|
|
|
void VideoBackend::InitBackendInfo()
|
2009-09-09 13:52:45 -06:00
|
|
|
{
|
2016-07-21 17:04:57 -06:00
|
|
|
g_Config.backend_info.api_type = APIType::OpenGL;
|
2017-03-09 07:01:23 -07:00
|
|
|
g_Config.backend_info.MaxTextureSize = 16384;
|
2019-02-14 18:59:50 -07:00
|
|
|
g_Config.backend_info.bUsesLowerLeftOrigin = true;
|
2014-07-19 12:18:03 -06:00
|
|
|
g_Config.backend_info.bSupportsExclusiveFullscreen = false;
|
2013-10-14 07:16:42 -06:00
|
|
|
g_Config.backend_info.bSupportsOversizedViewports = true;
|
2014-12-16 16:26:03 -07:00
|
|
|
g_Config.backend_info.bSupportsGeometryShaders = true;
|
2016-11-27 01:14:55 -07:00
|
|
|
g_Config.backend_info.bSupportsComputeShaders = false;
|
2014-11-13 16:24:53 -07:00
|
|
|
g_Config.backend_info.bSupports3DVision = false;
|
2015-01-02 17:33:30 -07:00
|
|
|
g_Config.backend_info.bSupportsPostProcessing = true;
|
2015-08-31 23:17:24 -06:00
|
|
|
g_Config.backend_info.bSupportsSSAA = true;
|
2016-08-21 09:47:24 -06:00
|
|
|
g_Config.backend_info.bSupportsReversedDepthRange = true;
|
2018-05-25 08:04:18 -06:00
|
|
|
g_Config.backend_info.bSupportsLogicOp = true;
|
2016-08-13 06:08:46 -06:00
|
|
|
g_Config.backend_info.bSupportsMultithreading = false;
|
2017-05-29 16:02:09 -06:00
|
|
|
g_Config.backend_info.bSupportsCopyToVram = true;
|
2019-02-14 18:59:50 -07:00
|
|
|
g_Config.backend_info.bSupportsLargePoints = true;
|
2020-05-24 00:11:10 -06:00
|
|
|
g_Config.backend_info.bSupportsDepthReadback = true;
|
2019-03-01 22:03:49 -07:00
|
|
|
g_Config.backend_info.bSupportsPartialDepthCopies = true;
|
2019-04-15 05:55:26 -06:00
|
|
|
g_Config.backend_info.bSupportsShaderBinaries = false;
|
|
|
|
g_Config.backend_info.bSupportsPipelineCacheData = false;
|
2016-11-27 01:15:00 -07:00
|
|
|
|
2019-03-29 06:38:17 -06:00
|
|
|
// TODO: There is a bug here, if texel buffers or SSBOs/atomics are not supported the graphics
|
|
|
|
// options will show the option when it is not supported. The only way around this would be
|
2016-11-27 01:15:00 -07:00
|
|
|
// creating a context when calling this function to determine what is available.
|
|
|
|
g_Config.backend_info.bSupportsGPUTextureDecoding = true;
|
2019-03-29 06:38:17 -06:00
|
|
|
g_Config.backend_info.bSupportsBBox = true;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2021-11-13 21:10:20 -07:00
|
|
|
// Overwritten in OGLRender.cpp later
|
2016-01-13 13:14:20 -07:00
|
|
|
g_Config.backend_info.bSupportsDualSourceBlend = true;
|
|
|
|
g_Config.backend_info.bSupportsPrimitiveRestart = true;
|
|
|
|
g_Config.backend_info.bSupportsPaletteConversion = true;
|
|
|
|
g_Config.backend_info.bSupportsClipControl = true;
|
2016-08-05 14:31:34 -06:00
|
|
|
g_Config.backend_info.bSupportsDepthClamp = true;
|
2017-04-16 03:30:11 -06:00
|
|
|
g_Config.backend_info.bSupportsST3CTextures = false;
|
2017-07-27 06:00:04 -06:00
|
|
|
g_Config.backend_info.bSupportsBPTCTextures = false;
|
2021-11-13 21:10:20 -07:00
|
|
|
g_Config.backend_info.bSupportsCoarseDerivatives = false;
|
2021-11-13 21:10:55 -07:00
|
|
|
g_Config.backend_info.bSupportsTextureQueryLevels = false;
|
2016-01-13 13:14:20 -07:00
|
|
|
|
2014-04-12 01:17:36 -06:00
|
|
|
g_Config.backend_info.Adapters.clear();
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-09-14 19:49:48 -06:00
|
|
|
// aamodes - 1 is to stay consistent with D3D (means no AA)
|
2015-10-10 08:47:58 -06:00
|
|
|
g_Config.backend_info.AAModes = {1, 2, 4, 8};
|
2011-05-31 14:16:59 -06:00
|
|
|
}
|
2010-11-22 15:17:35 -07:00
|
|
|
|
2018-10-03 07:03:26 -06:00
|
|
|
bool VideoBackend::InitializeGLExtensions(GLContext* context)
|
2017-03-09 07:01:23 -07:00
|
|
|
{
|
|
|
|
// Init extension support.
|
2018-10-03 07:03:26 -06:00
|
|
|
if (!GLExtensions::Init(context))
|
2017-03-09 07:01:23 -07:00
|
|
|
{
|
|
|
|
// OpenGL 2.0 is required for all shader based drawings. There is no way to get this by
|
|
|
|
// extensions
|
2020-12-02 11:17:27 -07:00
|
|
|
PanicAlertFmtT("GPU: OGL ERROR: Does your video card support OpenGL 2.0?");
|
2017-03-09 07:01:23 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GLExtensions::Version() < 300)
|
|
|
|
{
|
|
|
|
// integer vertex attributes require a gl3 only function
|
2020-12-02 11:17:27 -07:00
|
|
|
PanicAlertFmtT("GPU: OGL ERROR: Need OpenGL version 3.\n"
|
|
|
|
"GPU: Does your video card support OpenGL 3?");
|
2017-03-09 07:01:23 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VideoBackend::FillBackendInfo()
|
|
|
|
{
|
2019-03-09 06:31:40 -07:00
|
|
|
InitBackendInfo();
|
|
|
|
|
2017-03-09 07:01:23 -07:00
|
|
|
// check for the max vertex attributes
|
|
|
|
GLint numvertexattribs = 0;
|
|
|
|
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &numvertexattribs);
|
|
|
|
if (numvertexattribs < 16)
|
|
|
|
{
|
2020-12-02 11:17:27 -07:00
|
|
|
PanicAlertFmtT("GPU: OGL ERROR: Number of attributes {0} not enough.\n"
|
|
|
|
"GPU: Does your video card support OpenGL 2.x?",
|
|
|
|
numvertexattribs);
|
2017-03-09 07:01:23 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check the max texture width and height
|
|
|
|
GLint max_texture_size = 0;
|
|
|
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
|
|
|
|
g_Config.backend_info.MaxTextureSize = static_cast<u32>(max_texture_size);
|
|
|
|
if (max_texture_size < 1024)
|
|
|
|
{
|
2020-12-02 11:17:27 -07:00
|
|
|
PanicAlertFmtT("GL_MAX_TEXTURE_SIZE is {0} - must be at least 1024.", max_texture_size);
|
2017-03-09 07:01:23 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Move the remaining fields from the Renderer constructor here.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-03 07:03:22 -06:00
|
|
|
bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2018-10-03 07:03:26 -06:00
|
|
|
std::unique_ptr<GLContext> main_gl_context =
|
2019-03-09 06:31:40 -07:00
|
|
|
GLContext::Create(wsi, g_Config.stereo_mode == StereoMode::QuadBuffer, true, false,
|
2018-10-03 07:03:36 -06:00
|
|
|
Config::Get(Config::GFX_PREFER_GLES));
|
2018-10-03 07:03:26 -06:00
|
|
|
if (!main_gl_context)
|
2013-06-19 01:17:33 -06:00
|
|
|
return false;
|
|
|
|
|
2018-10-03 07:03:26 -06:00
|
|
|
if (!InitializeGLExtensions(main_gl_context.get()) || !FillBackendInfo())
|
2018-01-25 22:09:07 -07:00
|
|
|
return false;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2019-03-09 06:31:40 -07:00
|
|
|
InitializeShared();
|
2019-01-18 07:35:00 -07:00
|
|
|
g_renderer = std::make_unique<Renderer>(std::move(main_gl_context), wsi.render_surface_scale);
|
2019-02-14 18:59:50 -07:00
|
|
|
ProgramShaderCache::Init();
|
2015-12-20 19:49:49 -07:00
|
|
|
g_vertex_manager = std::make_unique<VertexManager>();
|
2019-02-14 18:59:50 -07:00
|
|
|
g_shader_cache = std::make_unique<VideoCommon::ShaderCache>();
|
|
|
|
g_framebuffer_manager = std::make_unique<FramebufferManager>();
|
2015-02-21 15:58:53 -07:00
|
|
|
g_perf_query = GetPerfQuery();
|
2019-02-14 18:59:50 -07:00
|
|
|
g_texture_cache = std::make_unique<TextureCacheBase>();
|
2015-12-20 19:49:49 -07:00
|
|
|
g_sampler_cache = std::make_unique<SamplerCache>();
|
2019-02-14 18:59:50 -07:00
|
|
|
|
|
|
|
if (!g_vertex_manager->Initialize() || !g_shader_cache->Initialize() ||
|
|
|
|
!g_renderer->Initialize() || !g_framebuffer_manager->Initialize() ||
|
|
|
|
!g_texture_cache->Initialize())
|
|
|
|
{
|
2020-12-02 11:17:27 -07:00
|
|
|
PanicAlertFmtT("Failed to initialize renderer classes");
|
2019-02-14 18:59:50 -07:00
|
|
|
Shutdown();
|
2018-02-09 03:52:25 -07:00
|
|
|
return false;
|
2019-02-14 18:59:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
g_shader_cache->InitializeShaderCache();
|
|
|
|
return true;
|
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
|
|
|
{
|
2018-02-24 08:15:35 -07:00
|
|
|
g_shader_cache->Shutdown();
|
2018-01-25 22:09:07 -07:00
|
|
|
g_renderer->Shutdown();
|
2015-12-20 19:49:49 -07:00
|
|
|
g_sampler_cache.reset();
|
|
|
|
g_texture_cache.reset();
|
|
|
|
g_perf_query.reset();
|
|
|
|
g_vertex_manager.reset();
|
2019-02-14 18:59:50 -07:00
|
|
|
g_framebuffer_manager.reset();
|
|
|
|
g_shader_cache.reset();
|
|
|
|
ProgramShaderCache::Shutdown();
|
2015-12-20 19:49:49 -07:00
|
|
|
g_renderer.reset();
|
2018-01-25 22:09:07 -07:00
|
|
|
ShutdownShared();
|
2010-09-30 09:24:34 -06:00
|
|
|
}
|
2018-10-03 07:02:45 -06:00
|
|
|
} // namespace OGL
|