2014-04-09 01:04:25 +02:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 06:38:14 +01:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-04-09 01:04:25 +02:00
|
|
|
// Refer to the license.txt file included.
|
2014-04-06 22:55:39 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-01-11 04:43:17 +01:00
|
|
|
#include <vector>
|
2015-08-30 08:37:42 +02:00
|
|
|
#include <glad/glad.h>
|
2016-04-30 17:34:51 +02:00
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "common/math_util.h"
|
2014-11-13 19:33:29 +01:00
|
|
|
#include "video_core/renderer_base.h"
|
2016-04-17 00:57:57 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
2015-05-19 06:21:33 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_state.h"
|
2014-04-06 22:55:39 +02:00
|
|
|
|
2019-01-15 20:28:42 +01:00
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
}
|
|
|
|
|
2018-08-12 02:20:19 +02:00
|
|
|
namespace Core::Frontend {
|
2014-08-28 20:21:54 +02:00
|
|
|
class EmuWindow;
|
2018-08-12 02:20:19 +02:00
|
|
|
}
|
2014-08-28 20:21:54 +02:00
|
|
|
|
2018-08-31 08:16:16 +02:00
|
|
|
namespace Layout {
|
2018-12-26 23:32:30 +01:00
|
|
|
struct FramebufferLayout;
|
2018-08-31 08:16:16 +02:00
|
|
|
}
|
|
|
|
|
2018-08-21 10:18:27 +02:00
|
|
|
namespace OpenGL {
|
|
|
|
|
2018-04-04 23:03:02 +02:00
|
|
|
/// Structure used for storing information about the textures for the Switch screen
|
2016-04-17 00:57:57 +02:00
|
|
|
struct TextureInfo {
|
|
|
|
OGLTexture resource;
|
|
|
|
GLsizei width;
|
|
|
|
GLsizei height;
|
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
2018-03-23 02:04:30 +01:00
|
|
|
Tegra::FramebufferConfig::PixelFormat pixel_format;
|
2016-04-17 00:57:57 +02:00
|
|
|
};
|
|
|
|
|
2018-04-04 23:03:02 +02:00
|
|
|
/// Structure used for storing information about the display target for the Switch screen
|
2016-04-17 00:57:57 +02:00
|
|
|
struct ScreenInfo {
|
2019-09-03 06:05:23 +02:00
|
|
|
GLuint display_texture{};
|
|
|
|
bool display_srgb{};
|
2019-02-27 04:47:49 +01:00
|
|
|
const Common::Rectangle<float> display_texcoords{0.0f, 0.0f, 1.0f, 1.0f};
|
2016-04-17 00:57:57 +02:00
|
|
|
TextureInfo texture;
|
|
|
|
};
|
|
|
|
|
2020-02-17 20:31:14 +01:00
|
|
|
struct PresentationTexture {
|
|
|
|
u32 width = 0;
|
|
|
|
u32 height = 0;
|
|
|
|
OGLTexture texture;
|
|
|
|
};
|
|
|
|
|
2020-02-27 00:28:50 +01:00
|
|
|
class FrameMailbox;
|
|
|
|
|
2019-08-21 06:55:25 +02:00
|
|
|
class RendererOpenGL final : public VideoCore::RendererBase {
|
2014-04-06 22:55:39 +02:00
|
|
|
public:
|
2019-04-06 22:59:56 +02:00
|
|
|
explicit RendererOpenGL(Core::Frontend::EmuWindow& emu_window, Core::System& system);
|
2014-08-28 10:51:57 +02:00
|
|
|
~RendererOpenGL() override;
|
2014-04-06 22:55:39 +02:00
|
|
|
|
2016-01-07 20:33:54 +01:00
|
|
|
bool Init() override;
|
2014-10-26 05:56:13 +01:00
|
|
|
void ShutDown() override;
|
2020-02-17 20:31:14 +01:00
|
|
|
void SwapBuffers(const Tegra::FramebufferConfig* framebuffer) override;
|
|
|
|
void TryPresent(int timeout_ms) override;
|
2014-04-06 22:55:39 +02:00
|
|
|
|
|
|
|
private:
|
2019-11-29 00:11:03 +01:00
|
|
|
/// Initializes the OpenGL state and creates persistent objects.
|
2014-08-28 11:34:47 +02:00
|
|
|
void InitOpenGLObjects();
|
2019-11-29 00:11:03 +01:00
|
|
|
|
2019-03-02 21:08:11 +01:00
|
|
|
void AddTelemetryFields();
|
2019-11-29 00:11:03 +01:00
|
|
|
|
2018-08-21 01:22:43 +02:00
|
|
|
void CreateRasterizer();
|
|
|
|
|
2018-03-23 02:04:30 +01:00
|
|
|
void ConfigureFramebufferTexture(TextureInfo& texture,
|
|
|
|
const Tegra::FramebufferConfig& framebuffer);
|
2019-11-29 00:11:03 +01:00
|
|
|
|
|
|
|
/// Draws the emulated screens to the emulator window.
|
2018-08-31 08:16:16 +02:00
|
|
|
void DrawScreen(const Layout::FramebufferLayout& layout);
|
2019-11-29 00:11:03 +01:00
|
|
|
|
2020-02-17 20:31:14 +01:00
|
|
|
void RenderScreenshot();
|
2018-08-31 08:16:16 +02:00
|
|
|
|
2019-11-29 00:11:03 +01:00
|
|
|
/// Loads framebuffer from emulated memory into the active OpenGL texture.
|
2018-08-21 01:34:02 +02:00
|
|
|
void LoadFBToScreenInfo(const Tegra::FramebufferConfig& framebuffer);
|
2019-11-29 00:11:03 +01:00
|
|
|
|
|
|
|
/// Fills active OpenGL texture with the given RGB color.Since the color is solid, the texture
|
|
|
|
/// can be 1x1 but will stretch across whatever it's rendered on.
|
2018-01-16 19:05:21 +01:00
|
|
|
void LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, u8 color_a,
|
|
|
|
const TextureInfo& texture);
|
2014-04-06 22:55:39 +02:00
|
|
|
|
2020-02-17 20:31:14 +01:00
|
|
|
void PrepareRendertarget(const Tegra::FramebufferConfig* framebuffer);
|
|
|
|
|
2019-04-06 22:59:56 +02:00
|
|
|
Core::Frontend::EmuWindow& emu_window;
|
2019-01-15 20:28:42 +01:00
|
|
|
Core::System& system;
|
|
|
|
|
2015-05-19 06:21:33 +02:00
|
|
|
OpenGLState state;
|
|
|
|
|
2014-08-28 20:21:54 +02:00
|
|
|
// OpenGL object IDs
|
2016-04-17 00:57:57 +02:00
|
|
|
OGLBuffer vertex_buffer;
|
2018-04-07 05:56:42 +02:00
|
|
|
OGLProgram shader;
|
2018-08-31 08:16:16 +02:00
|
|
|
OGLFramebuffer screenshot_framebuffer;
|
2016-09-19 03:01:46 +02:00
|
|
|
|
2018-01-11 04:43:17 +01:00
|
|
|
/// Display information for Switch screen
|
|
|
|
ScreenInfo screen_info;
|
|
|
|
|
|
|
|
/// OpenGL framebuffer data
|
|
|
|
std::vector<u8> gl_framebuffer_data;
|
2016-09-19 03:01:46 +02:00
|
|
|
|
2018-03-23 19:59:14 +01:00
|
|
|
/// Used for transforming the framebuffer orientation
|
|
|
|
Tegra::FramebufferConfig::TransformFlags framebuffer_transform_flags;
|
2019-02-27 04:47:49 +01:00
|
|
|
Common::Rectangle<int> framebuffer_crop_rect;
|
2020-02-17 20:31:14 +01:00
|
|
|
|
2020-02-27 00:28:50 +01:00
|
|
|
/// Frame presentation mailbox
|
|
|
|
std::unique_ptr<FrameMailbox> frame_mailbox;
|
2014-07-11 19:40:34 +02:00
|
|
|
};
|
2018-08-21 10:18:27 +02:00
|
|
|
|
|
|
|
} // namespace OpenGL
|