suyu/src/video_core/renderer_opengl/renderer_opengl.h

109 lines
3 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 <vector>
#include <glad/glad.h>
#include "common/common_types.h"
#include "common/math_util.h"
#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
namespace Core {
class System;
}
namespace Core::Frontend {
class EmuWindow;
}
namespace Layout {
struct FramebufferLayout;
}
namespace OpenGL {
/// 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;
Tegra::FramebufferConfig::PixelFormat pixel_format;
2016-04-17 00:57:57 +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 {
GLuint display_texture;
const Common::Rectangle<float> display_texcoords{0.0f, 0.0f, 1.0f, 1.0f};
2016-04-17 00:57:57 +02:00
TextureInfo texture;
};
class RendererOpenGL : public VideoCore::RendererBase {
2014-04-06 22:55:39 +02:00
public:
explicit RendererOpenGL(Core::Frontend::EmuWindow& window, Core::System& system);
~RendererOpenGL() override;
2014-04-06 22:55:39 +02:00
/// Swap buffers (render frame)
void SwapBuffers(
std::optional<std::reference_wrapper<const Tegra::FramebufferConfig>> framebuffer) override;
2014-04-06 22:55:39 +02:00
/// Initialize the renderer
bool Init() override;
2014-04-06 22:55:39 +02:00
/// Shutdown the renderer
void ShutDown() override;
2014-04-06 22:55:39 +02:00
private:
void InitOpenGLObjects();
void CreateRasterizer();
void ConfigureFramebufferTexture(TextureInfo& texture,
const Tegra::FramebufferConfig& framebuffer);
void DrawScreen(const Layout::FramebufferLayout& layout);
void DrawScreenTriangles(const ScreenInfo& screen_info, float x, float y, float w, float h);
2014-04-06 22:55:39 +02:00
void UpdateFramerate();
void CaptureScreenshot();
2016-04-17 00:57:57 +02:00
// Loads framebuffer from emulated memory into the display information structure
void LoadFBToScreenInfo(const Tegra::FramebufferConfig& framebuffer);
// Fills active OpenGL texture with the given RGBA color.
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
Core::System& system;
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;
/// Display information for Switch screen
ScreenInfo screen_info;
/// OpenGL framebuffer data
std::vector<u8> gl_framebuffer_data;
// Shader uniform location indices
GLuint uniform_modelview_matrix;
GLuint uniform_color_texture;
// Shader attribute input indices
GLuint attrib_position;
GLuint attrib_tex_coord;
/// Used for transforming the framebuffer orientation
Tegra::FramebufferConfig::TransformFlags framebuffer_transform_flags;
Common::Rectangle<int> framebuffer_crop_rect;
};
} // namespace OpenGL