| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <memory> |
| 7 |
#include <string> |
| 8 |
#include <string_view> |
| 9 |
#include <vector> |
| 10 |
|
| 11 |
#include "Common/GL/GLExtensions/GLExtensions.h" |
| 12 |
|
| 13 |
#include "VideoCommon/AbstractFramebuffer.h" |
| 14 |
#include "VideoCommon/AbstractStagingTexture.h" |
| 15 |
#include "VideoCommon/AbstractTexture.h" |
| 16 |
|
| 17 |
namespace OGL |
| 18 |
{ |
| 19 |
class OGLTexture final : public AbstractTexture |
| 20 |
{ |
| 21 |
public: |
| 22 |
explicit OGLTexture(const TextureConfig& tex_config, std::string_view name); |
| 23 |
~OGLTexture() override; |
| 24 |
|
| 25 |
void CopyRectangleFromTexture(const AbstractTexture* src, |
| 26 |
const MathUtil::Rectangle<int>& src_rect, u32 src_layer, |
| 27 |
u32 src_level, const MathUtil::Rectangle<int>& dst_rect, |
| 28 |
u32 dst_layer, u32 dst_level) override; |
| 29 |
void ResolveFromTexture(const AbstractTexture* src, const MathUtil::Rectangle<int>& rect, |
| 30 |
u32 layer, u32 level) override; |
| 31 |
void Load(u32 level, u32 width, u32 height, u32 row_length, const u8* buffer, size_t buffer_size, |
| 32 |
u32 layer) override; |
| 33 |
|
| 34 |
GLuint GetGLTextureId() const { return m_texId; } |
| 35 |
GLenum GetGLTarget() const |
| 36 |
{ |
| 37 |
if (m_config.type == AbstractTextureType::Texture_2DArray) |
| 38 |
{ |
| 39 |
if (m_config.IsMultisampled()) |
| 40 |
return GL_TEXTURE_2D_MULTISAMPLE_ARRAY; |
| 41 |
else |
| 42 |
return GL_TEXTURE_2D_ARRAY; |
| 43 |
} |
| 44 |
else if (m_config.type == AbstractTextureType::Texture_2D) |
| 45 |
{ |
| 46 |
if (m_config.IsMultisampled()) |
| 47 |
return GL_TEXTURE_2D_MULTISAMPLE; |
| 48 |
else |
| 49 |
return GL_TEXTURE_2D; |
| 50 |
} |
| 51 |
else if (m_config.type == AbstractTextureType::Texture_CubeMap) |
| 52 |
{ |
| 53 |
return GL_TEXTURE_CUBE_MAP; |
| 54 |
} |
| 55 |
|
| 56 |
return GL_TEXTURE_2D_ARRAY; |
| 57 |
} |
| 58 |
static GLenum GetGLInternalFormatForTextureFormat(AbstractTextureFormat format, bool storage); |
| 59 |
GLenum GetGLFormatForImageTexture() const; |
| 60 |
|
| 61 |
private: |
| 62 |
void BlitFramebuffer(OGLTexture* srcentry, const MathUtil::Rectangle<int>& src_rect, |
| 63 |
u32 src_layer, u32 src_level, const MathUtil::Rectangle<int>& dst_rect, |
| 64 |
u32 dst_layer, u32 dst_level); |
| 65 |
|
| 66 |
GLuint m_texId; |
| 67 |
std::string m_name; |
| 68 |
}; |
| 69 |
|
| 70 |
class OGLStagingTexture final : public AbstractStagingTexture |
| 71 |
{ |
| 72 |
public: |
| 73 |
OGLStagingTexture() = delete; |
| 74 |
~OGLStagingTexture() override; |
| 75 |
|
| 76 |
void CopyFromTexture(const AbstractTexture* src, const MathUtil::Rectangle<int>& src_rect, |
| 77 |
u32 src_layer, u32 src_level, |
| 78 |
const MathUtil::Rectangle<int>& dst_rect) override; |
| 79 |
void CopyToTexture(const MathUtil::Rectangle<int>& src_rect, AbstractTexture* dst, |
| 80 |
const MathUtil::Rectangle<int>& dst_rect, u32 dst_layer, |
| 81 |
u32 dst_level) override; |
| 82 |
|
| 83 |
bool Map() override; |
| 84 |
void Unmap() override; |
| 85 |
void Flush() override; |
| 86 |
|
| 87 |
static std::unique_ptr<OGLStagingTexture> Create(StagingTextureType type, |
| 88 |
const TextureConfig& config); |
| 89 |
|
| 90 |
private: |
| 91 |
OGLStagingTexture(StagingTextureType type, const TextureConfig& config, GLenum target, |
| 92 |
GLuint buffer_name, size_t buffer_size, char* map_ptr, size_t map_stride); |
| 93 |
|
| 94 |
private: |
| 95 |
GLenum m_target; |
| 96 |
GLuint m_buffer_name; |
| 97 |
size_t m_buffer_size; |
| 98 |
GLsync m_fence = nullptr; |
| 99 |
}; |
| 100 |
|
| 101 |
class OGLFramebuffer final : public AbstractFramebuffer |
| 102 |
{ |
| 103 |
public: |
| 104 |
OGLFramebuffer(AbstractTexture* color_attachment, AbstractTexture* depth_attachment, |
| 105 |
std::vector<AbstractTexture*> additional_color_attachments, |
| 106 |
AbstractTextureFormat color_format, AbstractTextureFormat depth_format, u32 width, |
| 107 |
u32 height, u32 layers, u32 samples, GLuint fbo); |
| 108 |
~OGLFramebuffer() override; |
| 109 |
|
| 110 |
static std::unique_ptr<OGLFramebuffer> |
| 111 |
Create(OGLTexture* color_attachment, OGLTexture* depth_attachment, |
| 112 |
std::vector<AbstractTexture*> additional_color_attachments); |
| 113 |
|
| 114 |
GLuint GetFBO() const { return m_fbo; } |
| 115 |
|
| 116 |
|
| 117 |
void UpdateDimensions(u32 width, u32 height); |
| 118 |
|
| 119 |
protected: |
| 120 |
GLuint m_fbo; |
| 121 |
}; |
| 122 |
|
| 123 |
} |