Debian Codegraph @

Source/Core/VideoBackends/OGL/OGLMain.cpp

raw symbols SCIP
1 // Copyright 2008 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 // OpenGL Backend Documentation
5 /*
6
7 1.1 Display settings
8
9 Internal and fullscreen resolution: Since the only internal resolutions allowed
10 are also fullscreen resolution allowed by the system there is only need for one
11 resolution setting that applies to both the internal resolution and the
12 fullscreen resolution. - Apparently no, someone else doesn't agree
13
14 Todo: Make the internal resolution option apply instantly, currently only the
15 native and 2x option applies instantly. To do this we need to be able to change
16 the reinitialize FramebufferManager:Init() while a game is running.
17
18 1.2 Screenshots
19
20
21 The screenshots should be taken from the internal representation of the picture
22 regardless of what the current window size is. Since AA and wireframe is
23 applied together with the picture resizing this rule is not currently applied
24 to AA or wireframe pictures, they are instead taken from whatever the window
25 size is.
26
27 Todo: Render AA and wireframe to a separate picture used for the screenshot in
28 addition to the one for display.
29
30 1.3 AA
31
32 Make AA apply instantly during gameplay if possible
33
34 */
35
36 #include "VideoBackends/OGL/VideoBackend.h"
37
38 #include <memory>
39 #include <string>
40 #include <vector>
41
42 #include "Common/Common.h"
43 #include "Common/GL/GLContext.h"
44 #include "Common/GL/GLUtil.h"
45 #include "Common/MsgHandler.h"
46
47 #include "Core/Config/GraphicsSettings.h"
48
49 #include "VideoBackends/OGL/OGLBoundingBox.h"
50 #include "VideoBackends/OGL/OGLConfig.h"
51 #include "VideoBackends/OGL/OGLGfx.h"
52 #include "VideoBackends/OGL/OGLPerfQuery.h"
53 #include "VideoBackends/OGL/OGLVertexManager.h"
54 #include "VideoBackends/OGL/ProgramShaderCache.h"
55 #include "VideoBackends/OGL/SamplerCache.h"
56
57 #include "VideoCommon/TextureCacheBase.h"
58 #include "VideoCommon/VideoCommon.h"
59 #include "VideoCommon/VideoConfig.h"
60
61 namespace OGL
62 {
63 std::string VideoBackend::GetConfigName() const
64 {
65 return CONFIG_NAME;
66 }
67
68 std::string VideoBackend::GetDisplayName() const
69 {
70 if (g_ogl_config.bIsES)
71 return _trans("OpenGL ES");
72 else
73 return _trans("OpenGL");
74 }
75
76 void VideoBackend::InitBackendInfo(const WindowSystemInfo& wsi)
77 {
78 std::unique_ptr<GLContext> temp_gl_context =
79 GLContext::Create(wsi, g_Config.stereo_mode == StereoMode::QuadBuffer, true,
80 Config::Get(Config::GFX_PREFER_GLES));
81
82 if (!temp_gl_context)
83 return;
84
85 FillBackendInfo(temp_gl_context.get());
86 }
87
88 bool VideoBackend::InitializeGLExtensions(GLContext* context)
89 {
90 // Init extension support.
91 if (!GLExtensions::Init(context))
92 {
93 // OpenGL 2.0 is required for all shader based drawings. There is no way to get this by
94 // extensions
95 PanicAlertFmtT("GPU: OGL ERROR: Does your video card support OpenGL 2.0?");
96 return false;
97 }
98
99 if (GLExtensions::Version() < 300)
100 {
101 // integer vertex attributes require a gl3 only function
102 PanicAlertFmtT("GPU: OGL ERROR: Need OpenGL version 3.\n"
103 "GPU: Does your video card support OpenGL 3?");
104 return false;
105 }
106
107 return true;
108 }
109
110 bool VideoBackend::FillBackendInfo(GLContext* context)
111 {
112 if (!InitializeGLExtensions(context))
113 return false;
114
115 g_backend_info.api_type = APIType::OpenGL;
116 g_backend_info.MaxTextureSize = 16384;
117 g_backend_info.bUsesLowerLeftOrigin = true;
118 g_backend_info.bSupportsExclusiveFullscreen = false;
119 g_backend_info.bSupportsGeometryShaders = true;
120 g_backend_info.bSupportsComputeShaders = false;
121 g_backend_info.bSupports3DVision = false;
122 g_backend_info.bSupportsPostProcessing = true;
123 g_backend_info.bSupportsSSAA = true;
124 g_backend_info.bSupportsReversedDepthRange = true;
125 g_backend_info.bSupportsLogicOp = true;
126 g_backend_info.bSupportsMultithreading = false;
127 g_backend_info.bSupportsCopyToVram = true;
128 g_backend_info.bSupportsLargePoints = true;
129 g_backend_info.bSupportsDepthReadback = true;
130 g_backend_info.bSupportsPartialDepthCopies = true;
131 g_backend_info.bSupportsShaderBinaries = false;
132 g_backend_info.bSupportsPipelineCacheData = false;
133 g_backend_info.bSupportsLodBiasInSampler = true;
134 g_backend_info.bSupportsPartialMultisampleResolve = true;
135 // Unnecessary since OGL doesn't use pipelines
136 g_backend_info.bSupportsDynamicVertexLoader = false;
137
138 // TODO: There is a bug here, if texel buffers or SSBOs/atomics are not supported the graphics
139 // options will show the option when it is not supported. The only way around this would be
140 // creating a context when calling this function to determine what is available.
141 g_backend_info.bSupportsGPUTextureDecoding = true;
142 g_backend_info.bSupportsBBox = true;
143
144 // Overwritten in OGLConfig.cpp later
145 g_backend_info.bSupportsDualSourceBlend = true;
146 g_backend_info.bSupportsPrimitiveRestart = true;
147 g_backend_info.bSupportsPaletteConversion = true;
148 g_backend_info.bSupportsClipControl = true;
149 g_backend_info.bSupportsDepthClamp = true;
150 g_backend_info.bSupportsST3CTextures = false;
151 g_backend_info.bSupportsBPTCTextures = false;
152 g_backend_info.bSupportsCoarseDerivatives = false;
153 g_backend_info.bSupportsTextureQueryLevels = false;
154 g_backend_info.bSupportsSettingObjectNames = false;
155
156 g_backend_info.bUsesExplictQuadBuffering = true;
157
158 g_backend_info.Adapters.clear();
159
160 // aamodes - 1 is to stay consistent with D3D (means no AA)
161 g_backend_info.AAModes = {1, 2, 4, 8};
162
163 // check for the max vertex attributes
164 GLint numvertexattribs = 0;
165 glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &numvertexattribs);
166 if (numvertexattribs < 16)
167 {
168 PanicAlertFmtT("GPU: OGL ERROR: Number of attributes {0} not enough.\n"
169 "GPU: Does your video card support OpenGL 2.x?",
170 numvertexattribs);
171 return false;
172 }
173
174 // check the max texture width and height
175 GLint max_texture_size = 0;
176 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
177 g_backend_info.MaxTextureSize = static_cast<u32>(max_texture_size);
178 if (max_texture_size < 1024)
179 {
180 PanicAlertFmtT("GL_MAX_TEXTURE_SIZE is {0} - must be at least 1024.", max_texture_size);
181 return false;
182 }
183
184 if (!PopulateConfig(context))
185 {
186 // Not all needed extensions are supported, so we have to stop here.
187 // Else some of the next calls might crash.
188 return false;
189 }
190
191 // TODO: Move the remaining fields from the Renderer constructor here.
192 return true;
193 }
194
195 bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
196 {
197 std::unique_ptr<GLContext> main_gl_context =
198 GLContext::Create(wsi, g_Config.stereo_mode == StereoMode::QuadBuffer, true,
199 Config::Get(Config::GFX_PREFER_GLES));
200 if (!main_gl_context)
201 return false;
202
203 if (!FillBackendInfo(main_gl_context.get()))
204 return false;
205
206 auto gfx = std::make_unique<OGLGfx>(std::move(main_gl_context), wsi.render_surface_scale);
207 ProgramShaderCache::Init();
208 g_sampler_cache = std::make_unique<SamplerCache>();
209
210 auto vertex_manager = std::make_unique<VertexManager>();
211 auto perf_query = GetPerfQuery(gfx->IsGLES());
212 auto bounding_box = std::make_unique<OGLBoundingBox>();
213
214 return InitializeShared(std::move(gfx), std::move(vertex_manager), std::move(perf_query),
215 std::move(bounding_box));
216 }
217
218 void VideoBackend::Shutdown()
219 {
220 ShutdownShared();
221
222 ProgramShaderCache::Shutdown();
223 g_sampler_cache.reset();
224 }
225 } // namespace OGL