1 | // Copyright (C) 2017 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "graphicshelperes3_2_p.h" |
5 | #include <QOpenGLExtraFunctions> |
6 | #include <Qt3DRender/qrendertargetoutput.h> |
7 | #include <private/attachmentpack_p.h> |
8 | |
9 | QT_BEGIN_NAMESPACE |
10 | |
11 | #ifndef GL_DRAW_FRAMEBUFFER |
12 | #define GL_DRAW_FRAMEBUFFER 0x8CA9 |
13 | #endif |
14 | |
15 | #ifndef GL_DEPTH_STENCIL_ATTACHMENT |
16 | #define GL_DEPTH_STENCIL_ATTACHMENT 0x821A |
17 | #endif |
18 | |
19 | #ifndef GL_PATCH_VERTICES |
20 | #define GL_PATCH_VERTICES 36466 |
21 | #endif |
22 | |
23 | #ifndef GL_IMAGE_BUFFER |
24 | #define GL_IMAGE_BUFFER 0x9051 |
25 | #endif |
26 | #ifndef GL_IMAGE_CUBE_MAP_ARRAY |
27 | #define GL_IMAGE_CUBE_MAP_ARRAY 0x9054 |
28 | #endif |
29 | #ifndef GL_INT_IMAGE_BUFFER |
30 | #define GL_INT_IMAGE_BUFFER 0x905C |
31 | #endif |
32 | #ifndef GL_INT_IMAGE_CUBE_MAP_ARRAY |
33 | #define GL_INT_IMAGE_CUBE_MAP_ARRAY 0x905F |
34 | #endif |
35 | #ifndef GL_UNSIGNED_INT_IMAGE_BUFFER |
36 | #define GL_UNSIGNED_INT_IMAGE_BUFFER 0x9067 |
37 | #endif |
38 | #ifndef GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY |
39 | #define GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY 0x906A |
40 | #endif |
41 | |
42 | namespace Qt3DRender { |
43 | namespace Render { |
44 | namespace OpenGL { |
45 | |
46 | GraphicsHelperES3_2::GraphicsHelperES3_2() |
47 | { |
48 | } |
49 | |
50 | GraphicsHelperES3_2::~GraphicsHelperES3_2() |
51 | { |
52 | } |
53 | |
54 | bool GraphicsHelperES3_2::supportsFeature(GraphicsHelperInterface::Feature feature) const |
55 | { |
56 | switch (feature) { |
57 | case GraphicsHelperInterface::Tessellation: |
58 | return true; |
59 | default: |
60 | break; |
61 | } |
62 | return GraphicsHelperES3_1::supportsFeature(feature); |
63 | } |
64 | |
65 | bool GraphicsHelperES3_2::frameBufferNeedsRenderBuffer(const Attachment &attachment) |
66 | { |
67 | Q_UNUSED(attachment); |
68 | // This is first ES version where we have glFramebufferTexture, so |
69 | // attaching a D24S8 texture to the combined depth-stencil attachment point |
70 | // should work. |
71 | return false; |
72 | } |
73 | |
74 | void GraphicsHelperES3_2::bindFrameBufferAttachment(QOpenGLTexture *texture, const Attachment &attachment) |
75 | { |
76 | GLenum attr = GL_COLOR_ATTACHMENT0; |
77 | |
78 | if (attachment.m_point <= QRenderTargetOutput::Color15) |
79 | attr = GL_COLOR_ATTACHMENT0 + attachment.m_point; |
80 | else if (attachment.m_point == QRenderTargetOutput::Depth) |
81 | attr = GL_DEPTH_ATTACHMENT; |
82 | else if (attachment.m_point == QRenderTargetOutput::Stencil) |
83 | attr = GL_STENCIL_ATTACHMENT; |
84 | else if (attachment.m_point == QRenderTargetOutput::DepthStencil) |
85 | attr = GL_DEPTH_STENCIL_ATTACHMENT; |
86 | else |
87 | qCritical() << "Unsupported FBO attachment OpenGL ES 3.2" ; |
88 | |
89 | const QOpenGLTexture::Target target = texture->target(); |
90 | |
91 | texture->bind(); |
92 | if (target == QOpenGLTexture::TargetCubeMap && attachment.m_face != QAbstractTexture::AllFaces) |
93 | m_funcs->glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment: attr, textarget: attachment.m_face, texture: texture->textureId(), level: attachment.m_mipLevel); |
94 | else |
95 | m_extraFuncs->glFramebufferTexture(GL_DRAW_FRAMEBUFFER, attachment: attr, texture: texture->textureId(), level: attachment.m_mipLevel); |
96 | texture->release(); |
97 | } |
98 | |
99 | void GraphicsHelperES3_2::setVerticesPerPatch(GLint verticesPerPatch) |
100 | { |
101 | m_extraFuncs->glPatchParameteri(GL_PATCH_VERTICES, value: verticesPerPatch); |
102 | } |
103 | |
104 | void GraphicsHelperES3_2::drawElementsInstancedBaseVertexBaseInstance(GLenum primitiveType, GLsizei primitiveCount, GLint indexType, void *indices, GLsizei instances, GLint baseVertex, GLint baseInstance) |
105 | { |
106 | if (baseInstance != 0) |
107 | qWarning() << "glDrawElementsInstancedBaseVertexBaseInstance is not supported with OpenGL ES 3.2" ; |
108 | |
109 | m_extraFuncs->glDrawElementsInstancedBaseVertex(mode: primitiveType, |
110 | count: primitiveCount, |
111 | type: indexType, |
112 | indices, |
113 | instancecount: instances, |
114 | basevertex: baseVertex); |
115 | } |
116 | |
117 | UniformType GraphicsHelperES3_2::uniformTypeFromGLType(GLenum glType) |
118 | { |
119 | switch (glType) { |
120 | case GL_IMAGE_BUFFER: |
121 | case GL_IMAGE_CUBE_MAP_ARRAY: |
122 | case GL_INT_IMAGE_BUFFER: |
123 | case GL_INT_IMAGE_CUBE_MAP_ARRAY: |
124 | case GL_UNSIGNED_INT_IMAGE_BUFFER: |
125 | case GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY: |
126 | return UniformType::Image; |
127 | |
128 | default: |
129 | return GraphicsHelperES3_1::uniformTypeFromGLType(glType); |
130 | } |
131 | } |
132 | |
133 | uint GraphicsHelperES3_2::uniformByteSize(const ShaderUniform &description) |
134 | { |
135 | uint rawByteSize = 0; |
136 | |
137 | switch (description.m_type) { |
138 | case GL_IMAGE_BUFFER: |
139 | case GL_IMAGE_CUBE_MAP_ARRAY: |
140 | case GL_INT_IMAGE_BUFFER: |
141 | case GL_INT_IMAGE_CUBE_MAP_ARRAY: |
142 | case GL_UNSIGNED_INT_IMAGE_BUFFER: |
143 | case GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY: |
144 | rawByteSize = 4; |
145 | break; |
146 | |
147 | default: |
148 | rawByteSize = GraphicsHelperES3_1::uniformByteSize(description); |
149 | break; |
150 | } |
151 | |
152 | return rawByteSize; |
153 | } |
154 | |
155 | } // namespace OpenGL |
156 | } // namespace Render |
157 | } // namespace Qt3DRender |
158 | |
159 | QT_END_NAMESPACE |
160 | |