citra/src/video_core/renderer_opengl/renderer_opengl.h

140 lines
4.7 KiB
C++
Raw Normal View History

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
#include <array>
#include <glad/glad.h>
#include "common/common_types.h"
#include "common/math_util.h"
#include "core/hw/gpu.h"
#include "video_core/renderer_base.h"
#include "video_core/renderer_opengl/frame_dumper_opengl.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
namespace Layout {
struct FramebufferLayout;
}
namespace Frontend {
struct Frame {
u32 width{}; /// Width of the frame (to detect resize)
u32 height{}; /// Height of the frame
bool color_reloaded = false; /// Texture attachment was recreated (ie: resized)
OpenGL::OGLRenderbuffer color{}; /// Buffer shared between the render/present FBO
OpenGL::OGLFramebuffer render{}; /// FBO created on the render thread
OpenGL::OGLFramebuffer present{}; /// FBO created on the present thread
GLsync render_fence{}; /// Fence created on the render thread
GLsync present_fence{}; /// Fence created on the presentation thread
};
} // namespace Frontend
namespace OpenGL {
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;
Common::Rectangle<float> display_texcoords;
2016-04-17 00:57:57 +02:00
TextureInfo texture;
};
struct PresentationTexture {
u32 width = 0;
u32 height = 0;
OGLTexture texture;
};
class RendererOpenGL : public RendererBase {
2014-04-06 22:55:39 +02:00
public:
explicit RendererOpenGL(Frontend::EmuWindow& window);
~RendererOpenGL() override;
2014-04-06 22:55:39 +02:00
/// Initialize the renderer
2019-09-08 00:11:09 +02:00
VideoCore::ResultStatus Init() override;
2014-04-06 22:55:39 +02:00
/// Shutdown the renderer
void ShutDown() override;
2014-04-06 22:55:39 +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 TryPresent(int timeout_ms) override;
/// 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:
void InitOpenGLObjects();
void ReloadSampler();
void ReloadShader();
void PrepareRendertarget();
void RenderScreenshot();
void RenderToMailbox(const Layout::FramebufferLayout& layout,
std::unique_ptr<Frontend::TextureMailbox>& mailbox, bool flipped);
2015-05-19 06:21:33 +02:00
void ConfigureFramebufferTexture(TextureInfo& texture,
const GPU::Regs::FramebufferConfig& framebuffer);
void DrawScreens(const Layout::FramebufferLayout& layout, bool flipped);
2016-04-17 00:57:57 +02:00
void DrawSingleScreenRotated(const ScreenInfo& screen_info, float x, float y, float w, float h);
void DrawSingleScreen(const ScreenInfo& screen_info, float x, float y, float w, float h);
void DrawSingleScreenStereoRotated(const ScreenInfo& screen_info_l,
const ScreenInfo& screen_info_r, float x, float y, float w,
float h);
void DrawSingleScreenStereo(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,
ScreenInfo& screen_info, bool right_eye);
// Fills active OpenGL texture with the given RGB color.
void LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, const TextureInfo& texture);
2014-04-06 22:55:39 +02:00
2015-05-19 06:21:33 +02:00
OpenGLState state;
// OpenGL object IDs
2016-04-17 00:57:57 +02:00
OGLVertexArray vertex_array;
OGLBuffer vertex_buffer;
OGLProgram shader;
OGLFramebuffer screenshot_framebuffer;
OGLSampler filter_sampler;
/// Display information for top and bottom screens respectively
std::array<ScreenInfo, 3> screen_infos;
// Shader uniform location indices
GLuint uniform_modelview_matrix;
GLuint uniform_color_texture;
GLuint uniform_color_texture_r;
// Shader uniform for Dolphin compatibility
GLuint uniform_i_resolution;
GLuint uniform_o_resolution;
GLuint uniform_layer;
// Shader attribute input indices
GLuint attrib_position;
GLuint attrib_tex_coord;
FrameDumperOpenGL frame_dumper;
};
} // namespace OpenGL