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
|
|
|
|
|
2014-11-13 19:33:29 +01:00
|
|
|
#include <array>
|
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-08-28 20:21:54 +02:00
|
|
|
#include "core/hw/gpu.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
|
|
|
|
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-11-17 08:29:10 +01:00
|
|
|
namespace OpenGL {
|
2014-08-28 20:21:54 +02:00
|
|
|
|
2016-04-17 00:57:57 +02:00
|
|
|
/// Structure used for storing information about the textures for each 3DS screen
|
|
|
|
struct TextureInfo {
|
|
|
|
OGLTexture resource;
|
|
|
|
GLsizei width;
|
|
|
|
GLsizei height;
|
|
|
|
GPU::Regs::PixelFormat format;
|
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Structure used for storing information about the display target for each 3DS screen
|
|
|
|
struct ScreenInfo {
|
|
|
|
GLuint display_texture;
|
2019-02-27 04:47:49 +01:00
|
|
|
Common::Rectangle<float> display_texcoords;
|
2016-04-17 00:57:57 +02:00
|
|
|
TextureInfo texture;
|
|
|
|
};
|
|
|
|
|
2019-09-17 04:37:43 +02:00
|
|
|
struct PresentationTexture {
|
|
|
|
u32 width = 0;
|
|
|
|
u32 height = 0;
|
|
|
|
OGLTexture texture;
|
|
|
|
};
|
|
|
|
|
2014-08-28 10:51:57 +02:00
|
|
|
class RendererOpenGL : public RendererBase {
|
2014-04-06 22:55:39 +02:00
|
|
|
public:
|
2018-08-12 02:20:19 +02:00
|
|
|
explicit RendererOpenGL(Frontend::EmuWindow& window);
|
2014-08-28 10:51:57 +02:00
|
|
|
~RendererOpenGL() override;
|
2014-04-06 22:55:39 +02:00
|
|
|
|
|
|
|
/// Initialize the renderer
|
2018-07-20 17:20:57 +02:00
|
|
|
Core::System::ResultStatus Init() override;
|
2014-04-06 22:55:39 +02:00
|
|
|
|
|
|
|
/// Shutdown the renderer
|
2014-10-26 05:56:13 +01:00
|
|
|
void ShutDown() override;
|
2014-04-06 22:55:39 +02:00
|
|
|
|
2019-09-17 04:37:43 +02:00
|
|
|
/// Finalizes rendering the guest frame
|
|
|
|
void SwapBuffers() override;
|
|
|
|
|
|
|
|
/// Draws the latest frame from texture mailbox to the currently bound draw framebuffer in this
|
|
|
|
/// context
|
|
|
|
void Present() override;
|
|
|
|
|
2019-01-26 15:34:55 +01:00
|
|
|
/// Prepares for video dumping (e.g. create necessary buffers, etc)
|
|
|
|
void PrepareVideoDumping() override;
|
|
|
|
|
|
|
|
/// Cleans up after video dumping is ended
|
|
|
|
void CleanupVideoDumping() override;
|
|
|
|
|
2014-04-06 22:55:39 +02:00
|
|
|
private:
|
2014-08-28 11:34:47 +02:00
|
|
|
void InitOpenGLObjects();
|
2019-08-09 20:00:47 +02:00
|
|
|
void ReloadSampler();
|
|
|
|
void ReloadShader();
|
2015-05-19 06:21:33 +02:00
|
|
|
void ConfigureFramebufferTexture(TextureInfo& texture,
|
|
|
|
const GPU::Regs::FramebufferConfig& framebuffer);
|
2018-08-31 08:16:16 +02:00
|
|
|
void DrawScreens(const Layout::FramebufferLayout& layout);
|
2016-04-17 00:57:57 +02:00
|
|
|
void DrawSingleScreenRotated(const ScreenInfo& screen_info, float x, float y, float w, float h);
|
2019-08-09 20:00:47 +02:00
|
|
|
void DrawSingleScreenAnaglyphRotated(const ScreenInfo& screen_info_l,
|
|
|
|
const ScreenInfo& screen_info_r, float x, float y, float w,
|
|
|
|
float h);
|
2014-04-06 22:55:39 +02:00
|
|
|
void UpdateFramerate();
|
|
|
|
|
2016-04-17 00:57:57 +02:00
|
|
|
// Loads framebuffer from emulated memory into the display information structure
|
|
|
|
void LoadFBToScreenInfo(const GPU::Regs::FramebufferConfig& framebuffer,
|
2018-04-06 15:25:13 +02:00
|
|
|
ScreenInfo& screen_info, bool right_eye);
|
2014-10-13 07:40:26 +02:00
|
|
|
// Fills active OpenGL texture with the given RGB color.
|
2016-09-18 02:38:01 +02:00
|
|
|
void LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, const TextureInfo& texture);
|
2014-04-06 22:55:39 +02:00
|
|
|
|
2019-01-26 15:34:55 +01:00
|
|
|
void InitVideoDumpingGLObjects();
|
|
|
|
void ReleaseVideoDumpingGLObjects();
|
|
|
|
|
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
|
|
|
OGLVertexArray vertex_array;
|
|
|
|
OGLBuffer vertex_buffer;
|
2018-04-09 23:26:09 +02:00
|
|
|
OGLProgram shader;
|
2018-08-31 08:16:16 +02:00
|
|
|
OGLFramebuffer screenshot_framebuffer;
|
2019-08-09 20:00:47 +02:00
|
|
|
OGLSampler filter_sampler;
|
2016-09-19 03:01:46 +02:00
|
|
|
|
|
|
|
/// Display information for top and bottom screens respectively
|
2018-04-06 15:25:13 +02:00
|
|
|
std::array<ScreenInfo, 3> screen_infos;
|
2016-09-19 03:01:46 +02:00
|
|
|
|
2014-08-28 20:21:54 +02:00
|
|
|
// Shader uniform location indices
|
|
|
|
GLuint uniform_modelview_matrix;
|
|
|
|
GLuint uniform_color_texture;
|
2019-08-09 20:00:47 +02:00
|
|
|
GLuint uniform_color_texture_r;
|
|
|
|
|
|
|
|
// Shader uniform for Dolphin compatibility
|
|
|
|
GLuint uniform_i_resolution;
|
|
|
|
GLuint uniform_o_resolution;
|
|
|
|
GLuint uniform_layer;
|
2016-09-19 03:01:46 +02:00
|
|
|
|
2014-08-28 10:37:07 +02:00
|
|
|
// Shader attribute input indices
|
|
|
|
GLuint attrib_position;
|
2014-08-28 20:21:54 +02:00
|
|
|
GLuint attrib_tex_coord;
|
2019-01-26 15:34:55 +01:00
|
|
|
|
|
|
|
// Frame dumping
|
|
|
|
OGLFramebuffer frame_dumping_framebuffer;
|
|
|
|
GLuint frame_dumping_renderbuffer;
|
|
|
|
|
|
|
|
// Whether prepare/cleanup video dumping has been requested.
|
|
|
|
// They will be executed on next frame.
|
|
|
|
std::atomic_bool prepare_video_dumping = false;
|
|
|
|
std::atomic_bool cleanup_video_dumping = false;
|
|
|
|
|
|
|
|
// PBOs used to dump frames faster
|
|
|
|
std::array<OGLBuffer, 2> frame_dumping_pbos;
|
|
|
|
GLuint current_pbo = 1;
|
|
|
|
GLuint next_pbo = 0;
|
2019-09-17 04:37:43 +02:00
|
|
|
|
|
|
|
// Textures used for presentation
|
|
|
|
OGLFramebuffer draw_framebuffer;
|
|
|
|
OGLFramebuffer presentation_framebuffer;
|
|
|
|
std::array<PresentationTexture, 3> presentation_textures{};
|
2014-07-11 19:40:34 +02:00
|
|
|
};
|
2018-11-17 08:29:10 +01:00
|
|
|
|
|
|
|
} // namespace OpenGL
|