12 #ifndef hifi_gpu_41_GL41Backend_h
13 #define hifi_gpu_41_GL41Backend_h
15 #include <gl/Config.h>
17 #include <gpu/gl/GLBackend.h>
18 #include <gpu/gl/GLTexture.h>
20 #define GPU_CORE_41 410
21 #define GPU_CORE_43 430
23 #define GPU_INPUT_PROFILE GPU_CORE_41
25 namespace gpu {
namespace gl41 {
27 using namespace gpu::gl;
29 class GL41Backend :
public GLBackend {
30 using Parent = GLBackend;
35 static const GLint RESOURCE_TRANSFER_TEX_UNIT { 32 };
36 static const GLint RESOURCE_TRANSFER_EXTRA_TEX_UNIT { 33 };
37 static const GLint RESOURCE_BUFFER_TEXBUF_TEX_UNIT { 34 };
38 static const GLint RESOURCE_BUFFER_SLOT0_TEX_UNIT { 35 };
40 explicit GL41Backend(
bool syncCache) : Parent(syncCache) {}
41 GL41Backend() : Parent() {}
42 virtual ~GL41Backend() {
48 static const std::string GL41_VERSION;
49 const std::string& getVersion()
const override {
return GL41_VERSION; }
51 bool supportedTextureFormat(
const gpu::Element& format)
const override;
53 class GL41Texture :
public GLTexture {
54 using Parent = GLTexture;
55 friend class GL41Backend;
56 static GLuint allocate(
const Texture& texture);
58 GL41Texture(
const std::weak_ptr<GLBackend>& backend,
const Texture& texture);
59 void generateMips()
const override;
60 Size copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face,
const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize,
const void* sourcePointer)
const override;
61 void syncSampler(
const Sampler& sampler)
const override;
63 void withPreservedTexture(std::function<
void()> f)
const;
70 class GL41FixedAllocationTexture :
public GL41Texture {
71 using Parent = GL41Texture;
72 friend class GL41Backend;
75 GL41FixedAllocationTexture(
const std::weak_ptr<GLBackend>& backend,
const Texture& texture);
76 ~GL41FixedAllocationTexture();
79 Size size()
const override {
return _size; }
80 void allocateStorage()
const;
81 void syncSampler(
const Sampler& sampler)
const override;
82 const Size _size { 0 };
85 class GL41AttachmentTexture :
public GL41FixedAllocationTexture {
86 using Parent = GL41FixedAllocationTexture;
87 friend class GL41Backend;
89 GL41AttachmentTexture(
const std::weak_ptr<GLBackend>& backend,
const Texture& texture);
90 ~GL41AttachmentTexture();
93 class GL41StrictResourceTexture :
public GL41FixedAllocationTexture {
94 using Parent = GL41FixedAllocationTexture;
95 friend class GL41Backend;
97 GL41StrictResourceTexture(
const std::weak_ptr<GLBackend>& backend,
const Texture& texture);
98 ~GL41StrictResourceTexture();
101 class GL41VariableAllocationTexture :
public GL41Texture,
public GLVariableAllocationSupport {
102 using Parent = GL41Texture;
103 friend class GL41Backend;
104 using PromoteLambda = std::function<void()>;
108 GL41VariableAllocationTexture(
const std::weak_ptr<GLBackend>& backend,
const Texture& texture);
109 ~GL41VariableAllocationTexture();
111 void allocateStorage(uint16 allocatedMip);
112 void syncSampler(
const Sampler& sampler)
const override;
113 size_t promote()
override;
114 size_t demote()
override;
115 void populateTransferQueue(TransferQueue& pendingTransfers)
override;
117 Size copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face,
const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize,
const void* sourcePointer)
const override;
118 Size copyMipsFromTexture();
120 void copyTextureMipsInGPUMem(GLuint srcId, GLuint destId, uint16_t srcMipOffset, uint16_t destMipOffset, uint16_t populatedMips)
override;
122 Size size()
const override {
return _size; }
125 class GL41ResourceTexture :
public GL41VariableAllocationTexture {
126 using Parent = GL41VariableAllocationTexture;
127 friend class GL41Backend;
129 GL41ResourceTexture(
const std::weak_ptr<GLBackend>& backend,
const Texture& texture);
130 ~GL41ResourceTexture();
135 void draw(GLenum mode, uint32 numVertices, uint32 startVertex)
override;
137 GLuint getFramebufferID(
const FramebufferPointer& framebuffer)
override;
138 GLFramebuffer* syncGPUObject(
const Framebuffer& framebuffer)
override;
140 GLuint getBufferID(
const Buffer& buffer)
override;
141 GLuint getBufferIDUnsynced(
const Buffer& buffer)
override;
142 GLuint getResourceBufferID(
const Buffer& buffer);
143 GLBuffer* syncGPUObject(
const Buffer& buffer)
override;
145 GLTexture* syncGPUObject(
const TexturePointer& texture)
override;
147 GLuint getQueryID(
const QueryPointer& query)
override;
148 GLQuery* syncGPUObject(
const Query& query)
override;
151 void do_draw(
const Batch& batch,
size_t paramOffset)
override;
152 void do_drawIndexed(
const Batch& batch,
size_t paramOffset)
override;
153 void do_drawInstanced(
const Batch& batch,
size_t paramOffset)
override;
154 void do_drawIndexedInstanced(
const Batch& batch,
size_t paramOffset)
override;
155 void do_multiDrawIndirect(
const Batch& batch,
size_t paramOffset)
override;
156 void do_multiDrawIndexedIndirect(
const Batch& batch,
size_t paramOffset)
override;
159 void resetInputStage()
override;
160 void updateInput()
override;
163 void transferTransformState(
const Batch& batch)
const override;
164 void initTransform()
override;
165 void updateTransform(
const Batch& batch)
override;
168 bool bindResourceBuffer(uint32_t slot,
const BufferPointer& buffer)
override;
169 void releaseResourceBuffer(uint32_t slot)
override;
171 void do_copySavedViewProjectionTransformToBuffer(
const Batch& batch,
size_t paramOffset)
override;
174 void do_blit(
const Batch& batch,
size_t paramOffset)
override;
176 shader::Dialect getShaderDialect()
const override {
return shader::Dialect::glsl410; }
177 void postLinkProgram(ShaderObject& programObject,
const Shader& program)
const override;
182 Q_DECLARE_LOGGING_CATEGORY(gpugl41logging)