2023-01-26 17:21:09 -07:00
|
|
|
// Copyright 2023 Dolphin Emulator Project
|
2021-07-04 19:22:19 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2015-05-23 22:32:32 -06:00
|
|
|
|
2014-02-10 11:54:46 -07:00
|
|
|
#pragma once
|
2010-11-17 19:21:26 -07:00
|
|
|
|
2023-01-26 17:21:09 -07:00
|
|
|
#include "VideoCommon/AbstractGfx.h"
|
2023-02-09 23:28:06 -07:00
|
|
|
#include "VideoCommon/Constants.h"
|
2017-01-23 09:20:20 -07:00
|
|
|
|
2023-01-26 17:21:09 -07:00
|
|
|
class GLContext;
|
2021-06-09 05:42:21 -06:00
|
|
|
|
2010-11-17 19:21:26 -07:00
|
|
|
namespace OGL
|
|
|
|
{
|
2019-02-14 18:59:50 -07:00
|
|
|
class OGLFramebuffer;
|
|
|
|
class OGLTexture;
|
2011-08-21 22:15:02 -06:00
|
|
|
|
2023-01-26 17:21:09 -07:00
|
|
|
class OGLGfx final : public AbstractGfx
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
|
|
|
public:
|
2023-01-26 17:21:09 -07:00
|
|
|
OGLGfx(std::unique_ptr<GLContext> main_gl_context, float backbuffer_scale);
|
|
|
|
~OGLGfx();
|
2019-02-14 18:59:50 -07:00
|
|
|
|
2018-10-03 07:03:13 -06:00
|
|
|
bool IsHeadless() const override;
|
|
|
|
|
2021-08-27 23:30:05 -06:00
|
|
|
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config,
|
|
|
|
std::string_view name) override;
|
2017-10-21 08:49:40 -06:00
|
|
|
std::unique_ptr<AbstractStagingTexture>
|
|
|
|
CreateStagingTexture(StagingTextureType type, const TextureConfig& config) override;
|
2021-08-27 23:30:05 -06:00
|
|
|
std::unique_ptr<AbstractShader> CreateShaderFromSource(ShaderStage stage, std::string_view source,
|
|
|
|
std::string_view name) override;
|
2017-09-08 03:42:56 -06:00
|
|
|
std::unique_ptr<AbstractShader> CreateShaderFromBinary(ShaderStage stage, const void* data,
|
2021-08-27 23:30:05 -06:00
|
|
|
size_t length,
|
|
|
|
std::string_view name) override;
|
2019-02-14 18:59:50 -07:00
|
|
|
std::unique_ptr<NativeVertexFormat>
|
|
|
|
CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override;
|
2019-04-15 05:55:26 -06:00
|
|
|
std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config,
|
|
|
|
const void* cache_data = nullptr,
|
|
|
|
size_t cache_data_length = 0) override;
|
2018-01-21 03:22:45 -07:00
|
|
|
std::unique_ptr<AbstractFramebuffer>
|
2023-05-28 19:59:02 -06:00
|
|
|
CreateFramebuffer(AbstractTexture* color_attachment, AbstractTexture* depth_attachment,
|
|
|
|
std::vector<AbstractTexture*> additional_color_attachments) override;
|
2017-09-30 00:25:36 -06:00
|
|
|
|
2017-09-08 03:42:56 -06:00
|
|
|
void SetPipeline(const AbstractPipeline* pipeline) override;
|
2019-02-14 18:59:50 -07:00
|
|
|
void SetFramebuffer(AbstractFramebuffer* framebuffer) override;
|
|
|
|
void SetAndDiscardFramebuffer(AbstractFramebuffer* framebuffer) override;
|
|
|
|
void SetAndClearFramebuffer(AbstractFramebuffer* framebuffer, const ClearColor& color_value = {},
|
2018-01-21 03:22:45 -07:00
|
|
|
float depth_value = 0.0f) override;
|
2023-01-30 21:29:16 -07:00
|
|
|
void ClearRegion(const MathUtil::Rectangle<int>& target_rc, bool colorEnable, bool alphaEnable,
|
|
|
|
bool zEnable, u32 color, u32 z) override;
|
2018-01-21 05:12:32 -07:00
|
|
|
void SetScissorRect(const MathUtil::Rectangle<int>& rc) override;
|
2018-01-21 06:13:25 -07:00
|
|
|
void SetTexture(u32 index, const AbstractTexture* texture) override;
|
2017-09-09 02:30:15 -06:00
|
|
|
void SetSamplerState(u32 index, const SamplerState& state) override;
|
2023-06-10 11:35:36 -06:00
|
|
|
void SetComputeImageTexture(u32 index, AbstractTexture* texture, bool read, bool write) override;
|
2018-01-21 06:13:25 -07:00
|
|
|
void UnbindTexture(const AbstractTexture* texture) override;
|
2018-01-21 05:04:15 -07:00
|
|
|
void SetViewport(float x, float y, float width, float height, float near_depth,
|
|
|
|
float far_depth) override;
|
2018-11-27 00:16:53 -07:00
|
|
|
void Draw(u32 base_vertex, u32 num_vertices) override;
|
|
|
|
void DrawIndexed(u32 base_index, u32 num_indices, u32 base_vertex) override;
|
2022-06-01 03:58:13 -06:00
|
|
|
void DispatchComputeShader(const AbstractShader* shader, u32 groupsize_x, u32 groupsize_y,
|
|
|
|
u32 groupsize_z, u32 groups_x, u32 groups_y, u32 groups_z) override;
|
2024-09-30 17:29:38 -06:00
|
|
|
bool BindBackbuffer(const ClearColor& clear_color = {}) override;
|
2018-11-27 21:30:47 -07:00
|
|
|
void PresentBackbuffer() override;
|
2010-11-17 19:21:26 -07:00
|
|
|
|
2019-02-14 18:59:50 -07:00
|
|
|
void BeginUtilityDrawing() override;
|
|
|
|
void EndUtilityDrawing() override;
|
2010-11-17 19:21:26 -07:00
|
|
|
|
2019-01-08 03:28:59 -07:00
|
|
|
void Flush() override;
|
2019-02-14 18:59:50 -07:00
|
|
|
void WaitForGPUIdle() override;
|
2018-11-27 21:30:47 -07:00
|
|
|
void OnConfigChanged(u32 bits) override;
|
2010-11-17 19:21:26 -07:00
|
|
|
|
2023-01-26 17:21:09 -07:00
|
|
|
virtual void SelectLeftBuffer() override;
|
|
|
|
virtual void SelectRightBuffer() override;
|
|
|
|
virtual void SelectMainBuffer() override;
|
2010-11-17 19:21:26 -07:00
|
|
|
|
2018-02-25 00:56:09 -07:00
|
|
|
std::unique_ptr<VideoCommon::AsyncShaderCompiler> CreateAsyncShaderCompiler() override;
|
|
|
|
|
2018-10-03 07:03:26 -06:00
|
|
|
// Only call methods from this on the GPU thread.
|
|
|
|
GLContext* GetMainGLContext() const { return m_main_gl_context.get(); }
|
2023-01-26 17:21:09 -07:00
|
|
|
bool IsGLES() const;
|
2018-10-03 07:03:26 -06:00
|
|
|
|
2019-02-14 18:59:50 -07:00
|
|
|
// Invalidates a cached texture binding. Required for texel buffers when they borrow the units.
|
|
|
|
void InvalidateTextureBinding(u32 index) { m_bound_textures[index] = nullptr; }
|
2018-11-27 00:16:53 -07:00
|
|
|
|
2019-02-14 18:59:50 -07:00
|
|
|
// The shared framebuffer exists for copying textures when extensions are not available. It is
|
|
|
|
// slower, but the only way to do these things otherwise.
|
2023-01-26 17:21:09 -07:00
|
|
|
u32 GetSharedReadFramebuffer() const { return m_shared_read_framebuffer; }
|
|
|
|
u32 GetSharedDrawFramebuffer() const { return m_shared_draw_framebuffer; }
|
2019-02-14 18:59:50 -07:00
|
|
|
void BindSharedReadFramebuffer();
|
|
|
|
void BindSharedDrawFramebuffer();
|
2014-12-20 09:10:58 -07:00
|
|
|
|
2019-02-14 18:59:50 -07:00
|
|
|
// Restores FBO binding after it's been changed.
|
|
|
|
void RestoreFramebufferBinding();
|
|
|
|
|
2023-01-26 17:21:09 -07:00
|
|
|
SurfaceInfo GetSurfaceInfo() const override;
|
2023-01-25 23:06:39 -07:00
|
|
|
|
2019-02-14 18:59:50 -07:00
|
|
|
private:
|
2018-01-25 23:23:24 -07:00
|
|
|
void CheckForSurfaceChange();
|
|
|
|
void CheckForSurfaceResize();
|
|
|
|
|
2019-02-14 18:59:50 -07:00
|
|
|
void ApplyRasterizationState(const RasterizationState state);
|
|
|
|
void ApplyDepthState(const DepthState state);
|
|
|
|
void ApplyBlendingState(const BlendingState state);
|
2017-09-08 03:42:56 -06:00
|
|
|
|
2018-10-03 07:03:26 -06:00
|
|
|
std::unique_ptr<GLContext> m_main_gl_context;
|
2019-02-14 18:59:50 -07:00
|
|
|
std::unique_ptr<OGLFramebuffer> m_system_framebuffer;
|
2023-02-09 23:28:06 -07:00
|
|
|
std::array<const OGLTexture*, VideoCommon::MAX_PIXEL_SHADER_SAMPLERS> m_bound_textures{};
|
2023-06-10 11:35:36 -06:00
|
|
|
std::array<const AbstractTexture*, VideoCommon::MAX_COMPUTE_SHADER_SAMPLERS>
|
|
|
|
m_bound_image_textures{};
|
2019-02-14 18:59:50 -07:00
|
|
|
AbstractTexture* m_bound_image_texture = nullptr;
|
2019-01-19 06:54:35 -07:00
|
|
|
RasterizationState m_current_rasterization_state;
|
|
|
|
DepthState m_current_depth_state;
|
|
|
|
BlendingState m_current_blend_state;
|
2023-01-26 17:21:09 -07:00
|
|
|
u32 m_shared_read_framebuffer = 0;
|
|
|
|
u32 m_shared_draw_framebuffer = 0;
|
|
|
|
float m_backbuffer_scale;
|
2010-11-17 19:21:26 -07:00
|
|
|
};
|
2023-01-26 17:21:09 -07:00
|
|
|
|
|
|
|
inline OGLGfx* GetOGLGfx()
|
|
|
|
{
|
|
|
|
return static_cast<OGLGfx*>(g_gfx.get());
|
|
|
|
}
|
|
|
|
|
2018-10-03 07:03:26 -06:00
|
|
|
} // namespace OGL
|