11 #ifndef hifi_gpu_41_GL41Backend_h
12 #define hifi_gpu_41_GL41Backend_h
14 #include <gl/Config.h>
16 #include <gpu/gl/GLBackend.h>
17 #include <gpu/gl/GLTexture.h>
19 #define GPU_CORE_41 410
20 #define GPU_CORE_43 430
22 #define GPU_INPUT_PROFILE GPU_CORE_41
24 namespace gpu {
namespace gl41 {
26 using namespace gpu::gl;
28 class GL41Backend :
public GLBackend {
29 using Parent = GLBackend;
34 static const GLint RESOURCE_TRANSFER_TEX_UNIT { 32 };
35 static const GLint RESOURCE_TRANSFER_EXTRA_TEX_UNIT { 33 };
36 static const GLint RESOURCE_BUFFER_TEXBUF_TEX_UNIT { 34 };
37 static const GLint RESOURCE_BUFFER_SLOT0_TEX_UNIT { 35 };
39 explicit GL41Backend(
bool syncCache) : Parent(syncCache) {}
40 GL41Backend() : Parent() {}
41 virtual ~GL41Backend() {
47 static const std::string GL41_VERSION;
48 const std::string& getVersion()
const override {
return GL41_VERSION; }
50 bool supportedTextureFormat(
const gpu::Element& format)
override;
52 class GL41Texture :
public GLTexture {
53 using Parent = GLTexture;
54 friend class GL41Backend;
55 static GLuint allocate(
const Texture& texture);
57 GL41Texture(
const std::weak_ptr<GLBackend>& backend,
const Texture& texture);
58 void generateMips()
const override;
59 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;
60 void syncSampler()
const override;
62 void withPreservedTexture(std::function<
void()> f)
const;
69 class GL41FixedAllocationTexture :
public GL41Texture {
70 using Parent = GL41Texture;
71 friend class GL41Backend;
74 GL41FixedAllocationTexture(
const std::weak_ptr<GLBackend>& backend,
const Texture& texture);
75 ~GL41FixedAllocationTexture();
78 Size size()
const override {
return _size; }
79 void allocateStorage()
const;
80 void syncSampler()
const override;
81 const Size _size { 0 };
84 class GL41AttachmentTexture :
public GL41FixedAllocationTexture {
85 using Parent = GL41FixedAllocationTexture;
86 friend class GL41Backend;
88 GL41AttachmentTexture(
const std::weak_ptr<GLBackend>& backend,
const Texture& texture);
89 ~GL41AttachmentTexture();
92 class GL41StrictResourceTexture :
public GL41FixedAllocationTexture {
93 using Parent = GL41FixedAllocationTexture;
94 friend class GL41Backend;
96 GL41StrictResourceTexture(
const std::weak_ptr<GLBackend>& backend,
const Texture& texture);
97 ~GL41StrictResourceTexture();
100 class GL41VariableAllocationTexture :
public GL41Texture,
public GLVariableAllocationSupport {
101 using Parent = GL41Texture;
102 friend class GL41Backend;
103 using PromoteLambda = std::function<void()>;
107 GL41VariableAllocationTexture(
const std::weak_ptr<GLBackend>& backend,
const Texture& texture);
108 ~GL41VariableAllocationTexture();
110 void allocateStorage(uint16 allocatedMip);
111 void syncSampler()
const override;
112 size_t promote()
override;
113 size_t demote()
override;
114 void populateTransferQueue(TransferQueue& pendingTransfers)
override;
116 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;
117 Size copyMipsFromTexture();
119 void copyTextureMipsInGPUMem(GLuint srcId, GLuint destId, uint16_t srcMipOffset, uint16_t destMipOffset, uint16_t populatedMips)
override;
121 Size size()
const override {
return _size; }
124 class GL41ResourceTexture :
public GL41VariableAllocationTexture {
125 using Parent = GL41VariableAllocationTexture;
126 friend class GL41Backend;
128 GL41ResourceTexture(
const std::weak_ptr<GLBackend>& backend,
const Texture& texture);
129 ~GL41ResourceTexture();
134 void draw(GLenum mode, uint32 numVertices, uint32 startVertex)
override;
136 GLuint getFramebufferID(
const FramebufferPointer& framebuffer)
override;
137 GLFramebuffer* syncGPUObject(
const Framebuffer& framebuffer)
override;
139 GLuint getBufferID(
const Buffer& buffer)
override;
140 GLuint getBufferIDUnsynced(
const Buffer& buffer)
override;
141 GLuint getResourceBufferID(
const Buffer& buffer);
142 GLBuffer* syncGPUObject(
const Buffer& buffer)
override;
144 GLTexture* syncGPUObject(
const TexturePointer& texture)
override;
146 GLuint getQueryID(
const QueryPointer& query)
override;
147 GLQuery* syncGPUObject(
const Query& query)
override;
150 void do_draw(
const Batch& batch,
size_t paramOffset)
override;
151 void do_drawIndexed(
const Batch& batch,
size_t paramOffset)
override;
152 void do_drawInstanced(
const Batch& batch,
size_t paramOffset)
override;
153 void do_drawIndexedInstanced(
const Batch& batch,
size_t paramOffset)
override;
154 void do_multiDrawIndirect(
const Batch& batch,
size_t paramOffset)
override;
155 void do_multiDrawIndexedIndirect(
const Batch& batch,
size_t paramOffset)
override;
158 void resetInputStage()
override;
159 void updateInput()
override;
162 void transferTransformState(
const Batch& batch)
const override;
163 void initTransform()
override;
164 void updateTransform(
const Batch& batch)
override;
167 bool bindResourceBuffer(uint32_t slot,
const BufferPointer& buffer)
override;
168 void releaseResourceBuffer(uint32_t slot)
override;
171 void do_blit(
const Batch& batch,
size_t paramOffset)
override;
173 shader::Dialect getShaderDialect()
const override {
return shader::Dialect::glsl410; }
174 void postLinkProgram(ShaderObject& programObject,
const Shader& program)
const override;
179 Q_DECLARE_LOGGING_CATEGORY(gpugl41logging)