renderer_opengl.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <algorithm>
  5. #include <cstddef>
  6. #include <cstdlib>
  7. #include <cstring>
  8. #include <memory>
  9. #include <glad/glad.h>
  10. #include "common/assert.h"
  11. #include "common/logging/log.h"
  12. #include "common/microprofile.h"
  13. #include "common/telemetry.h"
  14. #include "core/core.h"
  15. #include "core/core_timing.h"
  16. #include "core/frontend/emu_window.h"
  17. #include "core/memory.h"
  18. #include "core/perf_stats.h"
  19. #include "core/settings.h"
  20. #include "core/telemetry_session.h"
  21. #include "video_core/host_shaders/opengl_present_frag.h"
  22. #include "video_core/host_shaders/opengl_present_vert.h"
  23. #include "video_core/morton.h"
  24. #include "video_core/renderer_opengl/gl_rasterizer.h"
  25. #include "video_core/renderer_opengl/gl_shader_manager.h"
  26. #include "video_core/renderer_opengl/renderer_opengl.h"
  27. namespace OpenGL {
  28. namespace {
  29. constexpr GLint PositionLocation = 0;
  30. constexpr GLint TexCoordLocation = 1;
  31. constexpr GLint ModelViewMatrixLocation = 0;
  32. struct ScreenRectVertex {
  33. constexpr ScreenRectVertex(u32 x, u32 y, GLfloat u, GLfloat v)
  34. : position{{static_cast<GLfloat>(x), static_cast<GLfloat>(y)}}, tex_coord{{u, v}} {}
  35. std::array<GLfloat, 2> position;
  36. std::array<GLfloat, 2> tex_coord;
  37. };
  38. /**
  39. * Defines a 1:1 pixel ortographic projection matrix with (0,0) on the top-left
  40. * corner and (width, height) on the lower-bottom.
  41. *
  42. * The projection part of the matrix is trivial, hence these operations are represented
  43. * by a 3x2 matrix.
  44. */
  45. std::array<GLfloat, 3 * 2> MakeOrthographicMatrix(float width, float height) {
  46. std::array<GLfloat, 3 * 2> matrix; // Laid out in column-major order
  47. // clang-format off
  48. matrix[0] = 2.f / width; matrix[2] = 0.f; matrix[4] = -1.f;
  49. matrix[1] = 0.f; matrix[3] = -2.f / height; matrix[5] = 1.f;
  50. // Last matrix row is implicitly assumed to be [0, 0, 1].
  51. // clang-format on
  52. return matrix;
  53. }
  54. const char* GetSource(GLenum source) {
  55. switch (source) {
  56. case GL_DEBUG_SOURCE_API:
  57. return "API";
  58. case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
  59. return "WINDOW_SYSTEM";
  60. case GL_DEBUG_SOURCE_SHADER_COMPILER:
  61. return "SHADER_COMPILER";
  62. case GL_DEBUG_SOURCE_THIRD_PARTY:
  63. return "THIRD_PARTY";
  64. case GL_DEBUG_SOURCE_APPLICATION:
  65. return "APPLICATION";
  66. case GL_DEBUG_SOURCE_OTHER:
  67. return "OTHER";
  68. default:
  69. UNREACHABLE();
  70. return "Unknown source";
  71. }
  72. }
  73. const char* GetType(GLenum type) {
  74. switch (type) {
  75. case GL_DEBUG_TYPE_ERROR:
  76. return "ERROR";
  77. case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
  78. return "DEPRECATED_BEHAVIOR";
  79. case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
  80. return "UNDEFINED_BEHAVIOR";
  81. case GL_DEBUG_TYPE_PORTABILITY:
  82. return "PORTABILITY";
  83. case GL_DEBUG_TYPE_PERFORMANCE:
  84. return "PERFORMANCE";
  85. case GL_DEBUG_TYPE_OTHER:
  86. return "OTHER";
  87. case GL_DEBUG_TYPE_MARKER:
  88. return "MARKER";
  89. default:
  90. UNREACHABLE();
  91. return "Unknown type";
  92. }
  93. }
  94. void APIENTRY DebugHandler(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length,
  95. const GLchar* message, const void* user_param) {
  96. const char format[] = "{} {} {}: {}";
  97. const char* const str_source = GetSource(source);
  98. const char* const str_type = GetType(type);
  99. switch (severity) {
  100. case GL_DEBUG_SEVERITY_HIGH:
  101. LOG_CRITICAL(Render_OpenGL, format, str_source, str_type, id, message);
  102. break;
  103. case GL_DEBUG_SEVERITY_MEDIUM:
  104. LOG_WARNING(Render_OpenGL, format, str_source, str_type, id, message);
  105. break;
  106. case GL_DEBUG_SEVERITY_NOTIFICATION:
  107. case GL_DEBUG_SEVERITY_LOW:
  108. LOG_DEBUG(Render_OpenGL, format, str_source, str_type, id, message);
  109. break;
  110. }
  111. }
  112. } // Anonymous namespace
  113. RendererOpenGL::RendererOpenGL(Core::TelemetrySession& telemetry_session_,
  114. Core::Frontend::EmuWindow& emu_window_,
  115. Core::Memory::Memory& cpu_memory_, Tegra::GPU& gpu_,
  116. std::unique_ptr<Core::Frontend::GraphicsContext> context_)
  117. : RendererBase{emu_window_, std::move(context_)}, telemetry_session{telemetry_session_},
  118. emu_window{emu_window_}, cpu_memory{cpu_memory_}, gpu{gpu_}, program_manager{device} {}
  119. RendererOpenGL::~RendererOpenGL() = default;
  120. void RendererOpenGL::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) {
  121. if (!framebuffer) {
  122. return;
  123. }
  124. PrepareRendertarget(framebuffer);
  125. RenderScreenshot();
  126. glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
  127. DrawScreen(emu_window.GetFramebufferLayout());
  128. ++m_current_frame;
  129. rasterizer->TickFrame();
  130. context->SwapBuffers();
  131. render_window.OnFrameDisplayed();
  132. }
  133. void RendererOpenGL::PrepareRendertarget(const Tegra::FramebufferConfig* framebuffer) {
  134. if (!framebuffer) {
  135. return;
  136. }
  137. // If framebuffer is provided, reload it from memory to a texture
  138. if (screen_info.texture.width != static_cast<GLsizei>(framebuffer->width) ||
  139. screen_info.texture.height != static_cast<GLsizei>(framebuffer->height) ||
  140. screen_info.texture.pixel_format != framebuffer->pixel_format ||
  141. gl_framebuffer_data.empty()) {
  142. // Reallocate texture if the framebuffer size has changed.
  143. // This is expected to not happen very often and hence should not be a
  144. // performance problem.
  145. ConfigureFramebufferTexture(screen_info.texture, *framebuffer);
  146. }
  147. // Load the framebuffer from memory, draw it to the screen, and swap buffers
  148. LoadFBToScreenInfo(*framebuffer);
  149. }
  150. void RendererOpenGL::LoadFBToScreenInfo(const Tegra::FramebufferConfig& framebuffer) {
  151. // Framebuffer orientation handling
  152. framebuffer_transform_flags = framebuffer.transform_flags;
  153. framebuffer_crop_rect = framebuffer.crop_rect;
  154. const VAddr framebuffer_addr{framebuffer.address + framebuffer.offset};
  155. if (rasterizer->AccelerateDisplay(framebuffer, framebuffer_addr, framebuffer.stride)) {
  156. return;
  157. }
  158. // Reset the screen info's display texture to its own permanent texture
  159. screen_info.display_texture = screen_info.texture.resource.handle;
  160. const auto pixel_format{
  161. VideoCore::Surface::PixelFormatFromGPUPixelFormat(framebuffer.pixel_format)};
  162. const u32 bytes_per_pixel{VideoCore::Surface::GetBytesPerPixel(pixel_format)};
  163. const u64 size_in_bytes{framebuffer.stride * framebuffer.height * bytes_per_pixel};
  164. u8* const host_ptr{cpu_memory.GetPointer(framebuffer_addr)};
  165. rasterizer->FlushRegion(ToCacheAddr(host_ptr), size_in_bytes);
  166. // TODO(Rodrigo): Read this from HLE
  167. constexpr u32 block_height_log2 = 4;
  168. VideoCore::MortonSwizzle(VideoCore::MortonSwizzleMode::MortonToLinear, pixel_format,
  169. framebuffer.stride, block_height_log2, framebuffer.height, 0, 1, 1,
  170. gl_framebuffer_data.data(), host_ptr);
  171. glPixelStorei(GL_UNPACK_ROW_LENGTH, static_cast<GLint>(framebuffer.stride));
  172. // Update existing texture
  173. // TODO: Test what happens on hardware when you change the framebuffer dimensions so that
  174. // they differ from the LCD resolution.
  175. // TODO: Applications could theoretically crash yuzu here by specifying too large
  176. // framebuffer sizes. We should make sure that this cannot happen.
  177. glTextureSubImage2D(screen_info.texture.resource.handle, 0, 0, 0, framebuffer.width,
  178. framebuffer.height, screen_info.texture.gl_format,
  179. screen_info.texture.gl_type, gl_framebuffer_data.data());
  180. glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
  181. }
  182. void RendererOpenGL::LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, u8 color_a,
  183. const TextureInfo& texture) {
  184. const u8 framebuffer_data[4] = {color_a, color_b, color_g, color_r};
  185. glClearTexImage(texture.resource.handle, 0, GL_RGBA, GL_UNSIGNED_BYTE, framebuffer_data);
  186. }
  187. void RendererOpenGL::InitOpenGLObjects() {
  188. glClearColor(Settings::values.bg_red.GetValue(), Settings::values.bg_green.GetValue(),
  189. Settings::values.bg_blue.GetValue(), 0.0f);
  190. // Create shader programs
  191. OGLShader vertex_shader;
  192. vertex_shader.Create(HostShaders::OPENGL_PRESENT_VERT, GL_VERTEX_SHADER);
  193. OGLShader fragment_shader;
  194. fragment_shader.Create(HostShaders::OPENGL_PRESENT_FRAG, GL_FRAGMENT_SHADER);
  195. vertex_program.Create(true, false, vertex_shader.handle);
  196. fragment_program.Create(true, false, fragment_shader.handle);
  197. pipeline.Create();
  198. glUseProgramStages(pipeline.handle, GL_VERTEX_SHADER_BIT, vertex_program.handle);
  199. glUseProgramStages(pipeline.handle, GL_FRAGMENT_SHADER_BIT, fragment_program.handle);
  200. // Generate VBO handle for drawing
  201. vertex_buffer.Create();
  202. // Attach vertex data to VAO
  203. glNamedBufferData(vertex_buffer.handle, sizeof(ScreenRectVertex) * 4, nullptr, GL_STREAM_DRAW);
  204. // Allocate textures for the screen
  205. screen_info.texture.resource.Create(GL_TEXTURE_2D);
  206. const GLuint texture = screen_info.texture.resource.handle;
  207. glTextureStorage2D(texture, 1, GL_RGBA8, 1, 1);
  208. screen_info.display_texture = screen_info.texture.resource.handle;
  209. // Clear screen to black
  210. LoadColorToActiveGLTexture(0, 0, 0, 0, screen_info.texture);
  211. // Enable unified vertex attributes and query vertex buffer address when the driver supports it
  212. if (device.HasVertexBufferUnifiedMemory()) {
  213. glEnableClientState(GL_VERTEX_ATTRIB_ARRAY_UNIFIED_NV);
  214. glMakeNamedBufferResidentNV(vertex_buffer.handle, GL_READ_ONLY);
  215. glGetNamedBufferParameterui64vNV(vertex_buffer.handle, GL_BUFFER_GPU_ADDRESS_NV,
  216. &vertex_buffer_address);
  217. }
  218. }
  219. void RendererOpenGL::AddTelemetryFields() {
  220. const char* const gl_version{reinterpret_cast<char const*>(glGetString(GL_VERSION))};
  221. const char* const gpu_vendor{reinterpret_cast<char const*>(glGetString(GL_VENDOR))};
  222. const char* const gpu_model{reinterpret_cast<char const*>(glGetString(GL_RENDERER))};
  223. LOG_INFO(Render_OpenGL, "GL_VERSION: {}", gl_version);
  224. LOG_INFO(Render_OpenGL, "GL_VENDOR: {}", gpu_vendor);
  225. LOG_INFO(Render_OpenGL, "GL_RENDERER: {}", gpu_model);
  226. constexpr auto user_system = Common::Telemetry::FieldType::UserSystem;
  227. telemetry_session.AddField(user_system, "GPU_Vendor", std::string(gpu_vendor));
  228. telemetry_session.AddField(user_system, "GPU_Model", std::string(gpu_model));
  229. telemetry_session.AddField(user_system, "GPU_OpenGL_Version", std::string(gl_version));
  230. }
  231. void RendererOpenGL::CreateRasterizer() {
  232. if (rasterizer) {
  233. return;
  234. }
  235. rasterizer = std::make_unique<RasterizerOpenGL>(emu_window, gpu, cpu_memory, device,
  236. screen_info, program_manager, state_tracker);
  237. }
  238. void RendererOpenGL::ConfigureFramebufferTexture(TextureInfo& texture,
  239. const Tegra::FramebufferConfig& framebuffer) {
  240. texture.width = framebuffer.width;
  241. texture.height = framebuffer.height;
  242. texture.pixel_format = framebuffer.pixel_format;
  243. const auto pixel_format{
  244. VideoCore::Surface::PixelFormatFromGPUPixelFormat(framebuffer.pixel_format)};
  245. const u32 bytes_per_pixel{VideoCore::Surface::GetBytesPerPixel(pixel_format)};
  246. gl_framebuffer_data.resize(texture.width * texture.height * bytes_per_pixel);
  247. GLint internal_format;
  248. switch (framebuffer.pixel_format) {
  249. case Tegra::FramebufferConfig::PixelFormat::A8B8G8R8_UNORM:
  250. internal_format = GL_RGBA8;
  251. texture.gl_format = GL_RGBA;
  252. texture.gl_type = GL_UNSIGNED_INT_8_8_8_8_REV;
  253. break;
  254. case Tegra::FramebufferConfig::PixelFormat::RGB565_UNORM:
  255. internal_format = GL_RGB565;
  256. texture.gl_format = GL_RGB;
  257. texture.gl_type = GL_UNSIGNED_SHORT_5_6_5;
  258. break;
  259. default:
  260. internal_format = GL_RGBA8;
  261. texture.gl_format = GL_RGBA;
  262. texture.gl_type = GL_UNSIGNED_INT_8_8_8_8_REV;
  263. UNIMPLEMENTED_MSG("Unknown framebuffer pixel format: {}",
  264. static_cast<u32>(framebuffer.pixel_format));
  265. }
  266. texture.resource.Release();
  267. texture.resource.Create(GL_TEXTURE_2D);
  268. glTextureStorage2D(texture.resource.handle, 1, internal_format, texture.width, texture.height);
  269. }
  270. void RendererOpenGL::DrawScreen(const Layout::FramebufferLayout& layout) {
  271. if (renderer_settings.set_background_color) {
  272. // Update background color before drawing
  273. glClearColor(Settings::values.bg_red.GetValue(), Settings::values.bg_green.GetValue(),
  274. Settings::values.bg_blue.GetValue(), 0.0f);
  275. }
  276. // Set projection matrix
  277. const std::array ortho_matrix =
  278. MakeOrthographicMatrix(static_cast<float>(layout.width), static_cast<float>(layout.height));
  279. glProgramUniformMatrix3x2fv(vertex_program.handle, ModelViewMatrixLocation, 1, GL_FALSE,
  280. std::data(ortho_matrix));
  281. const auto& texcoords = screen_info.display_texcoords;
  282. auto left = texcoords.left;
  283. auto right = texcoords.right;
  284. if (framebuffer_transform_flags != Tegra::FramebufferConfig::TransformFlags::Unset) {
  285. if (framebuffer_transform_flags == Tegra::FramebufferConfig::TransformFlags::FlipV) {
  286. // Flip the framebuffer vertically
  287. left = texcoords.right;
  288. right = texcoords.left;
  289. } else {
  290. // Other transformations are unsupported
  291. LOG_CRITICAL(Render_OpenGL, "Unsupported framebuffer_transform_flags={}",
  292. static_cast<u32>(framebuffer_transform_flags));
  293. UNIMPLEMENTED();
  294. }
  295. }
  296. ASSERT_MSG(framebuffer_crop_rect.top == 0, "Unimplemented");
  297. ASSERT_MSG(framebuffer_crop_rect.left == 0, "Unimplemented");
  298. // Scale the output by the crop width/height. This is commonly used with 1280x720 rendering
  299. // (e.g. handheld mode) on a 1920x1080 framebuffer.
  300. f32 scale_u = 1.f, scale_v = 1.f;
  301. if (framebuffer_crop_rect.GetWidth() > 0) {
  302. scale_u = static_cast<f32>(framebuffer_crop_rect.GetWidth()) /
  303. static_cast<f32>(screen_info.texture.width);
  304. }
  305. if (framebuffer_crop_rect.GetHeight() > 0) {
  306. scale_v = static_cast<f32>(framebuffer_crop_rect.GetHeight()) /
  307. static_cast<f32>(screen_info.texture.height);
  308. }
  309. const auto& screen = layout.screen;
  310. const std::array vertices = {
  311. ScreenRectVertex(screen.left, screen.top, texcoords.top * scale_u, left * scale_v),
  312. ScreenRectVertex(screen.right, screen.top, texcoords.bottom * scale_u, left * scale_v),
  313. ScreenRectVertex(screen.left, screen.bottom, texcoords.top * scale_u, right * scale_v),
  314. ScreenRectVertex(screen.right, screen.bottom, texcoords.bottom * scale_u, right * scale_v),
  315. };
  316. glNamedBufferSubData(vertex_buffer.handle, 0, sizeof(vertices), std::data(vertices));
  317. // TODO: Signal state tracker about these changes
  318. state_tracker.NotifyScreenDrawVertexArray();
  319. state_tracker.NotifyPolygonModes();
  320. state_tracker.NotifyViewport0();
  321. state_tracker.NotifyScissor0();
  322. state_tracker.NotifyColorMask0();
  323. state_tracker.NotifyBlend0();
  324. state_tracker.NotifyFramebuffer();
  325. state_tracker.NotifyFrontFace();
  326. state_tracker.NotifyCullTest();
  327. state_tracker.NotifyDepthTest();
  328. state_tracker.NotifyStencilTest();
  329. state_tracker.NotifyPolygonOffset();
  330. state_tracker.NotifyRasterizeEnable();
  331. state_tracker.NotifyFramebufferSRGB();
  332. state_tracker.NotifyLogicOp();
  333. state_tracker.NotifyClipControl();
  334. state_tracker.NotifyAlphaTest();
  335. program_manager.BindHostPipeline(pipeline.handle);
  336. glEnable(GL_CULL_FACE);
  337. if (screen_info.display_srgb) {
  338. glEnable(GL_FRAMEBUFFER_SRGB);
  339. } else {
  340. glDisable(GL_FRAMEBUFFER_SRGB);
  341. }
  342. glDisable(GL_COLOR_LOGIC_OP);
  343. glDisable(GL_DEPTH_TEST);
  344. glDisable(GL_STENCIL_TEST);
  345. glDisable(GL_POLYGON_OFFSET_FILL);
  346. glDisable(GL_RASTERIZER_DISCARD);
  347. glDisable(GL_ALPHA_TEST);
  348. glDisablei(GL_BLEND, 0);
  349. glDisablei(GL_SCISSOR_TEST, 0);
  350. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  351. glCullFace(GL_BACK);
  352. glFrontFace(GL_CW);
  353. glColorMaski(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
  354. glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE);
  355. glViewportIndexedf(0, 0.0f, 0.0f, static_cast<GLfloat>(layout.width),
  356. static_cast<GLfloat>(layout.height));
  357. glDepthRangeIndexed(0, 0.0, 0.0);
  358. glEnableVertexAttribArray(PositionLocation);
  359. glEnableVertexAttribArray(TexCoordLocation);
  360. glVertexAttribDivisor(PositionLocation, 0);
  361. glVertexAttribDivisor(TexCoordLocation, 0);
  362. glVertexAttribFormat(PositionLocation, 2, GL_FLOAT, GL_FALSE,
  363. offsetof(ScreenRectVertex, position));
  364. glVertexAttribFormat(TexCoordLocation, 2, GL_FLOAT, GL_FALSE,
  365. offsetof(ScreenRectVertex, tex_coord));
  366. glVertexAttribBinding(PositionLocation, 0);
  367. glVertexAttribBinding(TexCoordLocation, 0);
  368. if (device.HasVertexBufferUnifiedMemory()) {
  369. glBindVertexBuffer(0, 0, 0, sizeof(ScreenRectVertex));
  370. glBufferAddressRangeNV(GL_VERTEX_ATTRIB_ARRAY_ADDRESS_NV, 0, vertex_buffer_address,
  371. sizeof(vertices));
  372. } else {
  373. glBindVertexBuffer(0, vertex_buffer.handle, 0, sizeof(ScreenRectVertex));
  374. }
  375. glBindTextureUnit(0, screen_info.display_texture);
  376. glBindSampler(0, 0);
  377. glClear(GL_COLOR_BUFFER_BIT);
  378. glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  379. program_manager.RestoreGuestPipeline();
  380. }
  381. void RendererOpenGL::RenderScreenshot() {
  382. if (!renderer_settings.screenshot_requested) {
  383. return;
  384. }
  385. GLint old_read_fb;
  386. GLint old_draw_fb;
  387. glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &old_read_fb);
  388. glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &old_draw_fb);
  389. // Draw the current frame to the screenshot framebuffer
  390. screenshot_framebuffer.Create();
  391. glBindFramebuffer(GL_FRAMEBUFFER, screenshot_framebuffer.handle);
  392. const Layout::FramebufferLayout layout{renderer_settings.screenshot_framebuffer_layout};
  393. GLuint renderbuffer;
  394. glGenRenderbuffers(1, &renderbuffer);
  395. glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
  396. glRenderbufferStorage(GL_RENDERBUFFER, screen_info.display_srgb ? GL_SRGB8 : GL_RGB8,
  397. layout.width, layout.height);
  398. glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer);
  399. DrawScreen(layout);
  400. glReadPixels(0, 0, layout.width, layout.height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
  401. renderer_settings.screenshot_bits);
  402. screenshot_framebuffer.Release();
  403. glDeleteRenderbuffers(1, &renderbuffer);
  404. glBindFramebuffer(GL_READ_FRAMEBUFFER, old_read_fb);
  405. glBindFramebuffer(GL_DRAW_FRAMEBUFFER, old_draw_fb);
  406. renderer_settings.screenshot_complete_callback();
  407. renderer_settings.screenshot_requested = false;
  408. }
  409. bool RendererOpenGL::Init() {
  410. if (Settings::values.renderer_debug && GLAD_GL_KHR_debug) {
  411. glEnable(GL_DEBUG_OUTPUT);
  412. glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
  413. glDebugMessageCallback(DebugHandler, nullptr);
  414. }
  415. AddTelemetryFields();
  416. if (!GLAD_GL_VERSION_4_3) {
  417. return false;
  418. }
  419. InitOpenGLObjects();
  420. CreateRasterizer();
  421. return true;
  422. }
  423. void RendererOpenGL::ShutDown() {}
  424. } // namespace OpenGL