2019-09-12 02:53:04 +00:00
|
|
|
#pragma once
|
2019-11-03 05:22:37 +00:00
|
|
|
#include "common/gl/program.h"
|
|
|
|
#include "common/gl/stream_buffer.h"
|
|
|
|
#include "common/gl/texture.h"
|
2019-09-12 02:53:04 +00:00
|
|
|
#include "glad.h"
|
2019-09-12 14:18:13 +00:00
|
|
|
#include "gpu_hw.h"
|
2019-09-12 02:53:04 +00:00
|
|
|
#include <array>
|
2019-09-12 14:18:13 +00:00
|
|
|
#include <memory>
|
2019-09-13 16:07:31 +00:00
|
|
|
#include <tuple>
|
2019-09-12 02:53:04 +00:00
|
|
|
|
|
|
|
class GPU_HW_OpenGL : public GPU_HW
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GPU_HW_OpenGL();
|
|
|
|
~GPU_HW_OpenGL() override;
|
|
|
|
|
2019-11-03 14:39:48 +00:00
|
|
|
bool Initialize(HostDisplay* host_display, System* system, DMA* dma, InterruptController* interrupt_controller,
|
|
|
|
Timers* timers) override;
|
2019-09-12 02:53:04 +00:00
|
|
|
void Reset() override;
|
2019-10-04 12:10:43 +00:00
|
|
|
|
|
|
|
void ResetGraphicsAPIState() override;
|
|
|
|
void RestoreGraphicsAPIState() override;
|
2019-11-01 14:31:25 +00:00
|
|
|
void UpdateSettings() override;
|
2019-10-04 12:10:43 +00:00
|
|
|
|
2019-09-12 02:53:04 +00:00
|
|
|
protected:
|
2019-09-13 16:07:31 +00:00
|
|
|
void UpdateDisplay() override;
|
2019-11-14 07:16:59 +00:00
|
|
|
void ReadVRAM(u32 x, u32 y, u32 width, u32 height) override;
|
2019-11-02 15:05:37 +00:00
|
|
|
void FillVRAM(u32 x, u32 y, u32 width, u32 height, u32 color) override;
|
2019-09-12 15:10:08 +00:00
|
|
|
void UpdateVRAM(u32 x, u32 y, u32 width, u32 height, const void* data) override;
|
2019-09-17 14:58:30 +00:00
|
|
|
void CopyVRAM(u32 src_x, u32 src_y, u32 dst_x, u32 dst_y, u32 width, u32 height) override;
|
2019-09-12 15:10:08 +00:00
|
|
|
void FlushRender() override;
|
2019-11-02 12:21:56 +00:00
|
|
|
void MapBatchVertexPointer(u32 required_vertices) override;
|
2019-11-05 12:34:27 +00:00
|
|
|
void UpdateVRAMReadTexture() override;
|
2019-09-12 02:53:04 +00:00
|
|
|
|
|
|
|
private:
|
2019-09-26 04:03:32 +00:00
|
|
|
struct GLStats
|
|
|
|
{
|
|
|
|
u32 num_batches;
|
|
|
|
u32 num_vertices;
|
2019-11-01 12:06:19 +00:00
|
|
|
u32 num_vram_reads;
|
|
|
|
u32 num_vram_writes;
|
|
|
|
u32 num_vram_read_texture_updates;
|
2019-11-03 03:15:17 +00:00
|
|
|
u32 num_uniform_buffer_updates;
|
2019-09-26 04:03:32 +00:00
|
|
|
};
|
|
|
|
|
2019-09-13 16:07:31 +00:00
|
|
|
std::tuple<s32, s32> ConvertToFramebufferCoordinates(s32 x, s32 y);
|
|
|
|
|
2019-11-05 15:33:09 +00:00
|
|
|
void SetCapabilities(HostDisplay* host_display);
|
2019-12-10 14:01:29 +00:00
|
|
|
bool CreateFramebuffer();
|
2019-09-12 02:53:04 +00:00
|
|
|
void ClearFramebuffer();
|
|
|
|
|
2019-12-10 14:01:29 +00:00
|
|
|
bool CreateVertexBuffer();
|
|
|
|
bool CreateUniformBuffer();
|
|
|
|
bool CreateTextureBuffer();
|
2019-09-12 02:53:04 +00:00
|
|
|
|
2019-09-12 14:18:13 +00:00
|
|
|
bool CompilePrograms();
|
2019-11-03 03:36:54 +00:00
|
|
|
void SetDrawState(BatchRenderMode render_mode);
|
2019-11-05 09:19:49 +00:00
|
|
|
void SetScissorFromDrawingArea();
|
2019-11-03 03:15:17 +00:00
|
|
|
void UploadUniformBlock(const void* data, u32 data_size);
|
2019-09-12 14:18:13 +00:00
|
|
|
|
2019-10-03 06:46:13 +00:00
|
|
|
// downsample texture - used for readbacks at >1xIR.
|
2019-12-10 14:01:29 +00:00
|
|
|
GL::Texture m_vram_texture;
|
|
|
|
GL::Texture m_vram_read_texture;
|
|
|
|
GL::Texture m_vram_encoding_texture;
|
|
|
|
GL::Texture m_display_texture;
|
2019-10-03 06:46:13 +00:00
|
|
|
|
2019-11-02 12:21:56 +00:00
|
|
|
std::unique_ptr<GL::StreamBuffer> m_vertex_stream_buffer;
|
2019-09-12 02:53:04 +00:00
|
|
|
GLuint m_vao_id = 0;
|
2019-09-13 16:07:31 +00:00
|
|
|
GLuint m_attributeless_vao_id = 0;
|
2019-09-12 02:53:04 +00:00
|
|
|
|
2019-11-03 03:15:17 +00:00
|
|
|
std::unique_ptr<GL::StreamBuffer> m_uniform_stream_buffer;
|
|
|
|
|
2019-11-02 12:31:15 +00:00
|
|
|
std::unique_ptr<GL::StreamBuffer> m_texture_stream_buffer;
|
2019-11-02 13:43:20 +00:00
|
|
|
GLuint m_texture_buffer_r16ui_texture = 0;
|
2019-11-02 12:31:15 +00:00
|
|
|
|
2019-11-01 12:47:32 +00:00
|
|
|
std::array<std::array<std::array<GL::Program, 2>, 9>, 4> m_render_programs; // [render_mode][texture_mode][dithering]
|
|
|
|
std::array<std::array<GL::Program, 2>, 2> m_display_programs; // [depth_24][interlaced]
|
2019-11-14 06:58:27 +00:00
|
|
|
GL::Program m_vram_read_program;
|
2019-11-02 13:43:20 +00:00
|
|
|
GL::Program m_vram_write_program;
|
2019-11-05 15:33:09 +00:00
|
|
|
|
|
|
|
u32 m_uniform_buffer_alignment = 1;
|
|
|
|
u32 m_max_texture_buffer_size = 0;
|
|
|
|
|
|
|
|
bool m_is_gles = false;
|
|
|
|
bool m_supports_texture_buffer = false;
|
2019-09-12 02:53:04 +00:00
|
|
|
};
|