Debian Codegraph @

Source/Core/VideoBackends/OGL/OGLGfx.h

raw symbols SCIP
1 // Copyright 2023 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include "VideoCommon/AbstractGfx.h"
7 #include "VideoCommon/Constants.h"
8
9 class GLContext;
10
11 namespace OGL
12 {
13 class OGLFramebuffer;
14 class OGLTexture;
15
16 class OGLGfx final : public AbstractGfx
17 {
18 public:
19 OGLGfx(std::unique_ptr<GLContext> main_gl_context, float backbuffer_scale);
20 ~OGLGfx() override;
21
22 bool IsHeadless() const override;
23
24 std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config,
25 std::string_view name) override;
26 std::unique_ptr<AbstractStagingTexture>
27 CreateStagingTexture(StagingTextureType type, const TextureConfig& config) override;
28 std::unique_ptr<AbstractShader>
29 CreateShaderFromSource(ShaderStage stage, std::string_view source,
30 VideoCommon::ShaderIncluder* shader_includer,
31 std::string_view name) override;
32 std::unique_ptr<AbstractShader> CreateShaderFromBinary(ShaderStage stage, const void* data,
33 size_t length,
34 std::string_view name) override;
35 std::unique_ptr<NativeVertexFormat>
36 CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override;
37 std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config,
38 const void* cache_data = nullptr,
39 size_t cache_data_length = 0) override;
40 std::unique_ptr<AbstractFramebuffer>
41 CreateFramebuffer(AbstractTexture* color_attachment, AbstractTexture* depth_attachment,
42 std::vector<AbstractTexture*> additional_color_attachments) override;
43
44 void SetPipeline(const AbstractPipeline* pipeline) override;
45 void SetFramebuffer(AbstractFramebuffer* framebuffer) override;
46 void SetAndDiscardFramebuffer(AbstractFramebuffer* framebuffer) override;
47 void SetAndClearFramebuffer(AbstractFramebuffer* framebuffer, const ClearColor& color_value = {},
48 float depth_value = 0.0f) override;
49 void ClearRegion(const MathUtil::Rectangle<int>& target_rc, bool colorEnable, bool alphaEnable,
50 bool zEnable, u32 color, u32 z) override;
51 void SetScissorRect(const MathUtil::Rectangle<int>& rc) override;
52 void SetTexture(u32 index, const AbstractTexture* texture) override;
53 void SetSamplerState(u32 index, const SamplerState& state) override;
54 void SetComputeImageTexture(u32 index, AbstractTexture* texture, bool read, bool write) override;
55 void UnbindTexture(const AbstractTexture* texture) override;
56 void SetViewport(float x, float y, float width, float height, float near_depth,
57 float far_depth) override;
58 void Draw(u32 base_vertex, u32 num_vertices) override;
59 void DrawIndexed(u32 base_index, u32 num_indices, u32 base_vertex) override;
60 void DispatchComputeShader(const AbstractShader* shader, u32 groupsize_x, u32 groupsize_y,
61 u32 groupsize_z, u32 groups_x, u32 groups_y, u32 groups_z) override;
62 bool BindBackbuffer(const ClearColor& clear_color = {}) override;
63 void PresentBackbuffer() override;
64
65 void BeginUtilityDrawing() override;
66 void EndUtilityDrawing() override;
67
68 void Flush() override;
69 void WaitForGPUIdle() override;
70 void OnConfigChanged(u32 bits) override;
71
72 void SelectLeftBuffer() override;
73 void SelectRightBuffer() override;
74 void SelectMainBuffer() override;
75
76 std::unique_ptr<VideoCommon::AsyncShaderCompiler> CreateAsyncShaderCompiler() override;
77
78 // Only call methods from this on the GPU thread.
79 GLContext* GetMainGLContext() const { return m_main_gl_context.get(); }
80 bool IsGLES() const;
81
82 // Invalidates a cached texture binding. Required for texel buffers when they borrow the units.
83 void InvalidateTextureBinding(u32 index) { m_bound_textures[index] = nullptr; }
84
85 // The shared framebuffer exists for copying textures when extensions are not available. It is
86 // slower, but the only way to do these things otherwise.
87 u32 GetSharedReadFramebuffer() const { return m_shared_read_framebuffer; }
88 u32 GetSharedDrawFramebuffer() const { return m_shared_draw_framebuffer; }
89 void BindSharedReadFramebuffer();
90 void BindSharedDrawFramebuffer();
91
92 // Restores FBO binding after it's been changed.
93 void RestoreFramebufferBinding();
94
95 SurfaceInfo GetSurfaceInfo() const override;
96
97 private:
98 void CheckForSurfaceChange();
99 void CheckForSurfaceResize();
100
101 void ApplyRasterizationState(const RasterizationState state);
102 void ApplyDepthState(const DepthState state);
103 void ApplyBlendingState(const BlendingState state);
104
105 std::unique_ptr<GLContext> m_main_gl_context;
106 std::unique_ptr<OGLFramebuffer> m_system_framebuffer;
107 std::array<const OGLTexture*, VideoCommon::MAX_PIXEL_SHADER_SAMPLERS> m_bound_textures{};
108 std::array<const AbstractTexture*, VideoCommon::MAX_COMPUTE_SHADER_SAMPLERS>
109 m_bound_image_textures{};
110 AbstractTexture* m_bound_image_texture = nullptr;
111 RasterizationState m_current_rasterization_state;
112 DepthState m_current_depth_state;
113 BlendingState m_current_blend_state;
114 u32 m_shared_read_framebuffer = 0;
115 u32 m_shared_draw_framebuffer = 0;
116 float m_backbuffer_scale;
117 };
118
119 inline OGLGfx* GetOGLGfx()
120 {
121 return static_cast<OGLGfx*>(g_gfx.get());
122 }
123
124 } // namespace OGL