1 | // Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). |
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 "graphicshelpergl3_3_p.h" |
5 | |
6 | #if !QT_CONFIG(opengles2) |
7 | #include <QOpenGLFunctions_3_3_Core> |
8 | #include <private/attachmentpack_p.h> |
9 | #include <logging_p.h> |
10 | #include <qgraphicsutils_p.h> |
11 | |
12 | # ifndef QT_OPENGL_3_2 |
13 | # define GL_PATCH_VERTICES 36466 |
14 | # define GL_ACTIVE_RESOURCES 0x92F5 |
15 | # define GL_ACTIVE_UNIFORM_BLOCKS 0x8A36 |
16 | # define GL_BUFFER_BINDING 0x9302 |
17 | # define GL_BUFFER_DATA_SIZE 0x9303 |
18 | # define GL_NUM_ACTIVE_VARIABLES 0x9304 |
19 | # define GL_SHADER_STORAGE_BLOCK 0x92E6 |
20 | # define GL_UNIFORM 0x92E1 |
21 | # define GL_UNIFORM_BLOCK 0x92E2 |
22 | # define GL_UNIFORM_BLOCK_INDEX 0x8A3A |
23 | # define GL_UNIFORM_OFFSET 0x8A3B |
24 | # define GL_UNIFORM_ARRAY_STRIDE 0x8A3C |
25 | # define GL_UNIFORM_MATRIX_STRIDE 0x8A3D |
26 | # define GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS 0x8A42 |
27 | # define GL_UNIFORM_BLOCK_BINDING 0x8A3F |
28 | # define GL_UNIFORM_BLOCK_DATA_SIZE 0x8A40 |
29 | # endif |
30 | |
31 | QT_BEGIN_NAMESPACE |
32 | |
33 | namespace Qt3DRender { |
34 | namespace Render { |
35 | namespace OpenGL { |
36 | |
37 | GraphicsHelperGL3_3::GraphicsHelperGL3_3() |
38 | : m_funcs(nullptr) |
39 | { |
40 | } |
41 | |
42 | GraphicsHelperGL3_3::~GraphicsHelperGL3_3() |
43 | { |
44 | } |
45 | |
46 | void GraphicsHelperGL3_3::initializeHelper(QOpenGLContext *context, |
47 | QAbstractOpenGLFunctions *functions) |
48 | { |
49 | Q_UNUSED(context); |
50 | m_funcs = static_cast<QOpenGLFunctions_3_3_Core*>(functions); |
51 | const bool ok = m_funcs->initializeOpenGLFunctions(); |
52 | Q_ASSERT(ok); |
53 | Q_UNUSED(ok); |
54 | } |
55 | |
56 | void GraphicsHelperGL3_3::drawElementsInstancedBaseVertexBaseInstance(GLenum primitiveType, |
57 | GLsizei primitiveCount, |
58 | GLint indexType, |
59 | void *indices, |
60 | GLsizei instances, |
61 | GLint baseVertex, |
62 | GLint baseInstance) |
63 | { |
64 | if (baseInstance != 0) |
65 | qWarning() << "glDrawElementsInstancedBaseVertexBaseInstance is not supported with OpenGL 3.3" ; |
66 | |
67 | // glDrawElements OpenGL 3.1 or greater |
68 | m_funcs->glDrawElementsInstancedBaseVertex(mode: primitiveType, |
69 | count: primitiveCount, |
70 | type: indexType, |
71 | indices, |
72 | instancecount: instances, |
73 | basevertex: baseVertex); |
74 | } |
75 | |
76 | void GraphicsHelperGL3_3::drawArraysInstanced(GLenum primitiveType, |
77 | GLint first, |
78 | GLsizei count, |
79 | GLsizei instances) |
80 | { |
81 | // glDrawArraysInstanced OpenGL 3.1 or greater |
82 | m_funcs->glDrawArraysInstanced(mode: primitiveType, |
83 | first, |
84 | count, |
85 | instancecount: instances); |
86 | } |
87 | |
88 | void GraphicsHelperGL3_3::drawArraysInstancedBaseInstance(GLenum primitiveType, GLint first, GLsizei count, GLsizei instances, GLsizei baseInstance) |
89 | { |
90 | if (baseInstance != 0) |
91 | qWarning() << "glDrawArraysInstancedBaseInstance is not supported with OpenGL 3" ; |
92 | m_funcs->glDrawArraysInstanced(mode: primitiveType, |
93 | first, |
94 | count, |
95 | instancecount: instances); |
96 | } |
97 | |
98 | void GraphicsHelperGL3_3::drawElements(GLenum primitiveType, |
99 | GLsizei primitiveCount, |
100 | GLint indexType, |
101 | void *indices, |
102 | GLint baseVertex) |
103 | { |
104 | m_funcs->glDrawElementsBaseVertex(mode: primitiveType, |
105 | count: primitiveCount, |
106 | type: indexType, |
107 | indices, |
108 | basevertex: baseVertex); |
109 | } |
110 | |
111 | void GraphicsHelperGL3_3::drawElementsIndirect(GLenum, GLenum, void *) |
112 | { |
113 | qWarning() << "Indirect Drawing is not supported with OpenGL 3" ; |
114 | } |
115 | |
116 | void GraphicsHelperGL3_3::drawArrays(GLenum primitiveType, |
117 | GLint first, |
118 | GLsizei count) |
119 | { |
120 | m_funcs->glDrawArrays(mode: primitiveType, |
121 | first, |
122 | count); |
123 | } |
124 | |
125 | void GraphicsHelperGL3_3::drawArraysIndirect(GLenum , void *) |
126 | { |
127 | qWarning() << "Indirect Drawing is not supported with OpenGL 3" ; |
128 | } |
129 | |
130 | void GraphicsHelperGL3_3::setVerticesPerPatch(GLint verticesPerPatch) |
131 | { |
132 | Q_UNUSED(verticesPerPatch); |
133 | qWarning() << "Tessellation not supported" ; |
134 | } |
135 | |
136 | void GraphicsHelperGL3_3::useProgram(GLuint programId) |
137 | { |
138 | m_funcs->glUseProgram(program: programId); |
139 | } |
140 | |
141 | std::vector<ShaderUniform> GraphicsHelperGL3_3::programUniformsAndLocations(GLuint programId) |
142 | { |
143 | std::vector<ShaderUniform> uniforms; |
144 | |
145 | GLint nbrActiveUniforms = 0; |
146 | m_funcs->glGetProgramiv(program: programId, GL_ACTIVE_UNIFORMS, params: &nbrActiveUniforms); |
147 | uniforms.reserve(n: nbrActiveUniforms); |
148 | char uniformName[256]; |
149 | for (GLint i = 0; i < nbrActiveUniforms; i++) { |
150 | ShaderUniform uniform; |
151 | GLsizei uniformNameLength = 0; |
152 | // Size is 1 for scalar and more for struct or arrays |
153 | // Type is the GL Type |
154 | m_funcs->glGetActiveUniform(program: programId, index: i, bufSize: sizeof(uniformName) - 1, length: &uniformNameLength, |
155 | size: &uniform.m_size, type: &uniform.m_type, name: uniformName); |
156 | uniformName[sizeof(uniformName) - 1] = '\0'; |
157 | uniform.m_location = m_funcs->glGetUniformLocation(program: programId, name: uniformName); |
158 | uniform.m_name = QString::fromUtf8(utf8: uniformName, size: uniformNameLength); |
159 | // Work around for uniform array names that aren't returned with [0] by some drivers |
160 | if (uniform.m_size > 1 && !uniform.m_name.endsWith(s: QLatin1String("[0]" ))) |
161 | uniform.m_name.append(s: QLatin1String("[0]" )); |
162 | m_funcs->glGetActiveUniformsiv(program: programId, uniformCount: 1, uniformIndices: (GLuint*)&i, GL_UNIFORM_BLOCK_INDEX, params: &uniform.m_blockIndex); |
163 | m_funcs->glGetActiveUniformsiv(program: programId, uniformCount: 1, uniformIndices: (GLuint*)&i, GL_UNIFORM_OFFSET, params: &uniform.m_offset); |
164 | m_funcs->glGetActiveUniformsiv(program: programId, uniformCount: 1, uniformIndices: (GLuint*)&i, GL_UNIFORM_ARRAY_STRIDE, params: &uniform.m_arrayStride); |
165 | m_funcs->glGetActiveUniformsiv(program: programId, uniformCount: 1, uniformIndices: (GLuint*)&i, GL_UNIFORM_MATRIX_STRIDE, params: &uniform.m_matrixStride); |
166 | uniform.m_rawByteSize = uniformByteSize(description: uniform); |
167 | uniforms.push_back(x: uniform); |
168 | qCDebug(Rendering) << uniform.m_name << "size" << uniform.m_size |
169 | << " offset" << uniform.m_offset |
170 | << " rawSize" << uniform.m_rawByteSize; |
171 | } |
172 | |
173 | return uniforms; |
174 | } |
175 | |
176 | std::vector<ShaderAttribute> GraphicsHelperGL3_3::programAttributesAndLocations(GLuint programId) |
177 | { |
178 | std::vector<ShaderAttribute> attributes; |
179 | GLint nbrActiveAttributes = 0; |
180 | m_funcs->glGetProgramiv(program: programId, GL_ACTIVE_ATTRIBUTES, params: &nbrActiveAttributes); |
181 | attributes.reserve(n: nbrActiveAttributes); |
182 | char attributeName[256]; |
183 | for (GLint i = 0; i < nbrActiveAttributes; i++) { |
184 | ShaderAttribute attribute; |
185 | GLsizei attributeNameLength = 0; |
186 | // Size is 1 for scalar and more for struct or arrays |
187 | // Type is the GL Type |
188 | m_funcs->glGetActiveAttrib(program: programId, index: i, bufSize: sizeof(attributeName) - 1, length: &attributeNameLength, |
189 | size: &attribute.m_size, type: &attribute.m_type, name: attributeName); |
190 | attributeName[sizeof(attributeName) - 1] = '\0'; |
191 | attribute.m_location = m_funcs->glGetAttribLocation(program: programId, name: attributeName); |
192 | attribute.m_name = QString::fromUtf8(utf8: attributeName, size: attributeNameLength); |
193 | attributes.push_back(x: attribute); |
194 | } |
195 | return attributes; |
196 | } |
197 | |
198 | std::vector<ShaderUniformBlock> GraphicsHelperGL3_3::programUniformBlocks(GLuint programId) |
199 | { |
200 | std::vector<ShaderUniformBlock> blocks; |
201 | GLint nbrActiveUniformsBlocks = 0; |
202 | m_funcs->glGetProgramiv(program: programId, GL_ACTIVE_UNIFORM_BLOCKS, params: &nbrActiveUniformsBlocks); |
203 | blocks.reserve(n: nbrActiveUniformsBlocks); |
204 | for (GLint i = 0; i < nbrActiveUniformsBlocks; i++) { |
205 | QByteArray uniformBlockName(256, '\0'); |
206 | GLsizei length = 0; |
207 | ShaderUniformBlock uniformBlock; |
208 | m_funcs->glGetActiveUniformBlockName(program: programId, uniformBlockIndex: i, bufSize: 256, length: &length, uniformBlockName: uniformBlockName.data()); |
209 | uniformBlock.m_name = QString::fromUtf8(ba: uniformBlockName.left(len: length)); |
210 | uniformBlock.m_index = i; |
211 | m_funcs->glGetActiveUniformBlockiv(program: programId, uniformBlockIndex: i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, params: &uniformBlock.m_activeUniformsCount); |
212 | m_funcs->glGetActiveUniformBlockiv(program: programId, uniformBlockIndex: i, GL_UNIFORM_BLOCK_BINDING, params: &uniformBlock.m_binding); |
213 | m_funcs->glGetActiveUniformBlockiv(program: programId, uniformBlockIndex: i, GL_UNIFORM_BLOCK_DATA_SIZE, params: &uniformBlock.m_size); |
214 | blocks.push_back(x: uniformBlock); |
215 | } |
216 | return blocks; |
217 | } |
218 | |
219 | std::vector<ShaderStorageBlock> GraphicsHelperGL3_3::programShaderStorageBlocks(GLuint programId) |
220 | { |
221 | Q_UNUSED(programId); |
222 | qWarning() << "SSBO are not supported by OpenGL 3.3 (since OpenGL 4.3)" ; |
223 | return {}; |
224 | } |
225 | |
226 | void GraphicsHelperGL3_3::vertexAttribDivisor(GLuint index, GLuint divisor) |
227 | { |
228 | m_funcs->glVertexAttribDivisor(index, divisor); |
229 | } |
230 | |
231 | void GraphicsHelperGL3_3::vertexAttributePointer(GLenum shaderDataType, |
232 | GLuint index, |
233 | GLint size, |
234 | GLenum type, |
235 | GLboolean normalized, |
236 | GLsizei stride, |
237 | const GLvoid *pointer) |
238 | { |
239 | switch (shaderDataType) { |
240 | case GL_FLOAT: |
241 | case GL_FLOAT_VEC2: |
242 | case GL_FLOAT_VEC3: |
243 | case GL_FLOAT_VEC4: |
244 | case GL_FLOAT_MAT2: |
245 | case GL_FLOAT_MAT2x3: |
246 | case GL_FLOAT_MAT2x4: |
247 | case GL_FLOAT_MAT3: |
248 | case GL_FLOAT_MAT3x2: |
249 | case GL_FLOAT_MAT3x4: |
250 | case GL_FLOAT_MAT4x2: |
251 | case GL_FLOAT_MAT4x3: |
252 | case GL_FLOAT_MAT4: |
253 | m_funcs->glVertexAttribPointer(index, size, type, normalized, stride, pointer); |
254 | break; |
255 | |
256 | case GL_INT: |
257 | case GL_INT_VEC2: |
258 | case GL_INT_VEC3: |
259 | case GL_INT_VEC4: |
260 | case GL_UNSIGNED_INT: |
261 | case GL_UNSIGNED_INT_VEC2: |
262 | case GL_UNSIGNED_INT_VEC3: |
263 | case GL_UNSIGNED_INT_VEC4: |
264 | m_funcs->glVertexAttribIPointer(index, size, type, stride, pointer); |
265 | break; |
266 | |
267 | default: |
268 | qCWarning(Rendering) << "vertexAttribPointer: Unhandled type" ; |
269 | } |
270 | } |
271 | |
272 | void GraphicsHelperGL3_3::readBuffer(GLenum mode) |
273 | { |
274 | m_funcs->glReadBuffer(mode); |
275 | } |
276 | |
277 | void GraphicsHelperGL3_3::drawBuffer(GLenum mode) |
278 | { |
279 | m_funcs->glDrawBuffer(mode); |
280 | } |
281 | |
282 | void *GraphicsHelperGL3_3::fenceSync() |
283 | { |
284 | return m_funcs->glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, flags: 0); |
285 | } |
286 | |
287 | void GraphicsHelperGL3_3::clientWaitSync(void *sync, GLuint64 nanoSecTimeout) |
288 | { |
289 | m_funcs->glClientWaitSync(sync: static_cast<GLsync>(sync), GL_SYNC_FLUSH_COMMANDS_BIT, timeout: nanoSecTimeout); |
290 | } |
291 | |
292 | void GraphicsHelperGL3_3::waitSync(void *sync) |
293 | { |
294 | m_funcs->glWaitSync(sync: static_cast<GLsync>(sync), flags: 0, GL_TIMEOUT_IGNORED); |
295 | } |
296 | |
297 | bool GraphicsHelperGL3_3::wasSyncSignaled(void *sync) |
298 | { |
299 | GLint v; |
300 | m_funcs->glGetSynciv(sync: static_cast<GLsync>(sync), |
301 | GL_SYNC_STATUS, |
302 | bufSize: sizeof(v), |
303 | length: nullptr, |
304 | values: &v); |
305 | return v == GL_SIGNALED; |
306 | } |
307 | |
308 | void GraphicsHelperGL3_3::deleteSync(void *sync) |
309 | { |
310 | m_funcs->glDeleteSync(sync: static_cast<GLsync>(sync)); |
311 | } |
312 | |
313 | void GraphicsHelperGL3_3::rasterMode(GLenum faceMode, GLenum rasterMode) |
314 | { |
315 | m_funcs->glPolygonMode(face: faceMode, mode: rasterMode); |
316 | } |
317 | |
318 | void GraphicsHelperGL3_3::blendEquation(GLenum mode) |
319 | { |
320 | m_funcs->glBlendEquation(mode); |
321 | } |
322 | |
323 | void GraphicsHelperGL3_3::blendFunci(GLuint buf, GLenum sfactor, GLenum dfactor) |
324 | { |
325 | Q_UNUSED(buf); |
326 | Q_UNUSED(sfactor); |
327 | Q_UNUSED(dfactor); |
328 | |
329 | qWarning() << "glBlendFunci() not supported by OpenGL 3.3 (since OpenGL 4.0)" ; |
330 | } |
331 | |
332 | void GraphicsHelperGL3_3::blendFuncSeparatei(GLuint buf, GLenum sRGB, GLenum dRGB, GLenum sAlpha, GLenum dAlpha) |
333 | { |
334 | Q_UNUSED(buf); |
335 | Q_UNUSED(sRGB); |
336 | Q_UNUSED(dRGB); |
337 | Q_UNUSED(sAlpha); |
338 | Q_UNUSED(dAlpha); |
339 | |
340 | qWarning() << "glBlendFuncSeparatei() not supported by OpenGL 3.3 (since OpenGL 4.0)" ; |
341 | } |
342 | |
343 | void GraphicsHelperGL3_3::alphaTest(GLenum, GLenum) |
344 | { |
345 | qCWarning(Rendering) << "AlphaTest not available with OpenGL 3.2 core" ; |
346 | } |
347 | |
348 | void GraphicsHelperGL3_3::depthTest(GLenum mode) |
349 | { |
350 | m_funcs->glEnable(GL_DEPTH_TEST); |
351 | m_funcs->glDepthFunc(func: mode); |
352 | } |
353 | |
354 | void GraphicsHelperGL3_3::depthMask(GLenum mode) |
355 | { |
356 | m_funcs->glDepthMask(flag: mode); |
357 | } |
358 | |
359 | void GraphicsHelperGL3_3::depthRange(GLdouble nearValue, GLdouble farValue) |
360 | { |
361 | m_funcs->glDepthRange(nearVal: nearValue, farVal: farValue); |
362 | } |
363 | |
364 | void GraphicsHelperGL3_3::frontFace(GLenum mode) |
365 | { |
366 | m_funcs->glFrontFace(mode); |
367 | |
368 | } |
369 | |
370 | void GraphicsHelperGL3_3::setMSAAEnabled(bool enabled) |
371 | { |
372 | enabled ? m_funcs->glEnable(GL_MULTISAMPLE) |
373 | : m_funcs->glDisable(GL_MULTISAMPLE); |
374 | } |
375 | |
376 | void GraphicsHelperGL3_3::setAlphaCoverageEnabled(bool enabled) |
377 | { |
378 | enabled ? m_funcs->glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE) |
379 | : m_funcs->glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); |
380 | } |
381 | |
382 | GLuint GraphicsHelperGL3_3::createFrameBufferObject() |
383 | { |
384 | GLuint id; |
385 | m_funcs->glGenFramebuffers(n: 1, framebuffers: &id); |
386 | return id; |
387 | } |
388 | |
389 | void GraphicsHelperGL3_3::releaseFrameBufferObject(GLuint frameBufferId) |
390 | { |
391 | m_funcs->glDeleteFramebuffers(n: 1, framebuffers: &frameBufferId); |
392 | } |
393 | |
394 | void GraphicsHelperGL3_3::bindFrameBufferObject(GLuint frameBufferId, FBOBindMode mode) |
395 | { |
396 | switch (mode) { |
397 | case FBODraw: |
398 | m_funcs->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer: frameBufferId); |
399 | return; |
400 | case FBORead: |
401 | m_funcs->glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer: frameBufferId); |
402 | return; |
403 | case FBOReadAndDraw: |
404 | default: |
405 | m_funcs->glBindFramebuffer(GL_FRAMEBUFFER, framebuffer: frameBufferId); |
406 | return; |
407 | } |
408 | } |
409 | |
410 | GLuint GraphicsHelperGL3_3::boundFrameBufferObject() |
411 | { |
412 | GLint id = 0; |
413 | m_funcs->glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, params: &id); |
414 | return id; |
415 | } |
416 | |
417 | bool GraphicsHelperGL3_3::checkFrameBufferComplete() |
418 | { |
419 | return (m_funcs->glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE); |
420 | } |
421 | |
422 | bool GraphicsHelperGL3_3::frameBufferNeedsRenderBuffer(const Attachment &attachment) |
423 | { |
424 | Q_UNUSED(attachment); |
425 | return false; |
426 | } |
427 | |
428 | void GraphicsHelperGL3_3::bindFrameBufferAttachment(QOpenGLTexture *texture, const Attachment &attachment) |
429 | { |
430 | GLenum attr = GL_DEPTH_STENCIL_ATTACHMENT; |
431 | |
432 | if (attachment.m_point <= QRenderTargetOutput::Color15) |
433 | attr = GL_COLOR_ATTACHMENT0 + attachment.m_point; |
434 | else if (attachment.m_point == QRenderTargetOutput::Depth) |
435 | attr = GL_DEPTH_ATTACHMENT; |
436 | else if (attachment.m_point == QRenderTargetOutput::Stencil) |
437 | attr = GL_STENCIL_ATTACHMENT; |
438 | |
439 | texture->bind(); |
440 | QOpenGLTexture::Target target = texture->target(); |
441 | if (target == QOpenGLTexture::Target1DArray || target == QOpenGLTexture::Target2DArray || |
442 | target == QOpenGLTexture::Target2DMultisampleArray || target == QOpenGLTexture::Target3D) |
443 | m_funcs->glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, attachment: attr, texture: texture->textureId(), level: attachment.m_mipLevel, layer: attachment.m_layer); |
444 | else if (target == QOpenGLTexture::TargetCubeMapArray && attachment.m_face != QAbstractTexture::AllFaces) |
445 | m_funcs->glFramebufferTextureLayer( GL_DRAW_FRAMEBUFFER, attachment: attr, texture: texture->textureId(), level: attachment.m_mipLevel, layer: attachment.m_layer * 6 + (attachment.m_face - QAbstractTexture::CubeMapPositiveX)); |
446 | else if (target == QOpenGLTexture::TargetCubeMap && attachment.m_face != QAbstractTexture::AllFaces) |
447 | m_funcs->glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment: attr, textarget: attachment.m_face, texture: texture->textureId(), level: attachment.m_mipLevel); |
448 | else |
449 | m_funcs->glFramebufferTexture(GL_DRAW_FRAMEBUFFER, attachment: attr, texture: texture->textureId(), level: attachment.m_mipLevel); |
450 | texture->release(); |
451 | } |
452 | |
453 | void GraphicsHelperGL3_3::bindFrameBufferAttachment(RenderBuffer *renderBuffer, const Attachment &attachment) |
454 | { |
455 | Q_UNUSED(renderBuffer); |
456 | Q_UNUSED(attachment); |
457 | Q_UNREACHABLE(); |
458 | } |
459 | |
460 | bool GraphicsHelperGL3_3::supportsFeature(GraphicsHelperInterface::Feature feature) const |
461 | { |
462 | switch (feature) { |
463 | case MRT: |
464 | case UniformBufferObject: |
465 | case PrimitiveRestart: |
466 | case RenderBufferDimensionRetrieval: |
467 | case TextureDimensionRetrieval: |
468 | case BindableFragmentOutputs: |
469 | case BlitFramebuffer: |
470 | case Fences: |
471 | return true; |
472 | default: |
473 | return false; |
474 | } |
475 | } |
476 | |
477 | void GraphicsHelperGL3_3::drawBuffers(GLsizei n, const int *bufs) |
478 | { |
479 | // Use QVarLengthArray here |
480 | QVarLengthArray<GLenum, 16> drawBufs(n); |
481 | |
482 | for (int i = 0; i < n; i++) |
483 | drawBufs[i] = GL_COLOR_ATTACHMENT0 + bufs[i]; |
484 | m_funcs->glDrawBuffers(n, bufs: drawBufs.constData()); |
485 | } |
486 | |
487 | void GraphicsHelperGL3_3::bindFragDataLocation(GLuint shader, const QHash<QString, int> &outputs) |
488 | { |
489 | for (auto it = outputs.begin(), end = outputs.end(); it != end; ++it) |
490 | m_funcs->glBindFragDataLocation(program: shader, color: it.value(), name: it.key().toStdString().c_str()); |
491 | } |
492 | |
493 | void GraphicsHelperGL3_3::bindUniformBlock(GLuint programId, GLuint uniformBlockIndex, GLuint uniformBlockBinding) |
494 | { |
495 | m_funcs->glUniformBlockBinding(program: programId, uniformBlockIndex, uniformBlockBinding); |
496 | } |
497 | |
498 | void GraphicsHelperGL3_3::bindShaderStorageBlock(GLuint programId, GLuint shaderStorageBlockIndex, GLuint shaderStorageBlockBinding) |
499 | { |
500 | Q_UNUSED(programId); |
501 | Q_UNUSED(shaderStorageBlockIndex); |
502 | Q_UNUSED(shaderStorageBlockBinding); |
503 | qWarning() << "SSBO are not supported by OpenGL 3.3 (since OpenGL 4.3)" ; |
504 | } |
505 | |
506 | void GraphicsHelperGL3_3::bindImageTexture(GLuint imageUnit, GLuint texture, |
507 | GLint mipLevel, GLboolean layered, |
508 | GLint layer, GLenum access, GLenum format) |
509 | { |
510 | Q_UNUSED(imageUnit); |
511 | Q_UNUSED(texture); |
512 | Q_UNUSED(mipLevel); |
513 | Q_UNUSED(layered); |
514 | Q_UNUSED(layer); |
515 | Q_UNUSED(access); |
516 | Q_UNUSED(format); |
517 | qWarning() << "Shader Images are not supported by OpenGL 3.3 (since OpenGL 4.2)" ; |
518 | } |
519 | |
520 | void GraphicsHelperGL3_3::bindBufferBase(GLenum target, GLuint index, GLuint buffer) |
521 | { |
522 | m_funcs->glBindBufferBase(target, index, buffer); |
523 | } |
524 | |
525 | void GraphicsHelperGL3_3::buildUniformBuffer(const QVariant &v, const ShaderUniform &description, QByteArray &buffer) |
526 | { |
527 | char *bufferData = buffer.data(); |
528 | |
529 | switch (description.m_type) { |
530 | |
531 | case GL_FLOAT: { |
532 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 1); |
533 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 1); |
534 | break; |
535 | } |
536 | |
537 | case GL_FLOAT_VEC2: { |
538 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 2); |
539 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 2); |
540 | break; |
541 | } |
542 | |
543 | case GL_FLOAT_VEC3: { |
544 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 3); |
545 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 3); |
546 | break; |
547 | } |
548 | |
549 | case GL_FLOAT_VEC4: { |
550 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 4); |
551 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 4); |
552 | break; |
553 | } |
554 | |
555 | case GL_FLOAT_MAT2: { |
556 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 4); |
557 | QGraphicsUtils::fillDataMatrixArray(buffer: bufferData, data, description, cols: 2, rows: 2); |
558 | break; |
559 | } |
560 | |
561 | case GL_FLOAT_MAT2x3: { |
562 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 6); |
563 | QGraphicsUtils::fillDataMatrixArray(buffer: bufferData, data, description, cols: 2, rows: 3); |
564 | break; |
565 | } |
566 | |
567 | case GL_FLOAT_MAT2x4: { |
568 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 8); |
569 | QGraphicsUtils::fillDataMatrixArray(buffer: bufferData, data, description, cols: 2, rows: 4); |
570 | break; |
571 | } |
572 | |
573 | case GL_FLOAT_MAT3: { |
574 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 9); |
575 | QGraphicsUtils::fillDataMatrixArray(buffer: bufferData, data, description, cols: 3, rows: 3); |
576 | break; |
577 | } |
578 | |
579 | case GL_FLOAT_MAT3x2: { |
580 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 6); |
581 | QGraphicsUtils::fillDataMatrixArray(buffer: bufferData, data, description, cols: 3, rows: 2); |
582 | break; |
583 | } |
584 | |
585 | case GL_FLOAT_MAT3x4: { |
586 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 12); |
587 | QGraphicsUtils::fillDataMatrixArray(buffer: bufferData, data, description, cols: 3, rows: 4); |
588 | break; |
589 | } |
590 | |
591 | case GL_FLOAT_MAT4: { |
592 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 16); |
593 | QGraphicsUtils::fillDataMatrixArray(buffer: bufferData, data, description, cols: 4, rows: 4); |
594 | break; |
595 | } |
596 | |
597 | case GL_FLOAT_MAT4x2: { |
598 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 8); |
599 | QGraphicsUtils::fillDataMatrixArray(buffer: bufferData, data, description, cols: 4, rows: 2); |
600 | break; |
601 | } |
602 | |
603 | case GL_FLOAT_MAT4x3: { |
604 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 12); |
605 | QGraphicsUtils::fillDataMatrixArray(buffer: bufferData, data, description, cols: 4, rows: 3); |
606 | break; |
607 | } |
608 | |
609 | case GL_INT: { |
610 | const GLint *data = QGraphicsUtils::valueArrayFromVariant<GLint>(v, count: description.m_size, tupleSize: 1); |
611 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 1); |
612 | break; |
613 | } |
614 | |
615 | case GL_INT_VEC2: { |
616 | const GLint *data = QGraphicsUtils::valueArrayFromVariant<GLint>(v, count: description.m_size, tupleSize: 2); |
617 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 2); |
618 | break; |
619 | } |
620 | |
621 | case GL_INT_VEC3: { |
622 | const GLint *data = QGraphicsUtils::valueArrayFromVariant<GLint>(v, count: description.m_size, tupleSize: 3); |
623 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 3); |
624 | break; |
625 | } |
626 | |
627 | case GL_INT_VEC4: { |
628 | const GLint *data = QGraphicsUtils::valueArrayFromVariant<GLint>(v, count: description.m_size, tupleSize: 4); |
629 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 4); |
630 | break; |
631 | } |
632 | |
633 | case GL_UNSIGNED_INT: { |
634 | const GLuint *data = QGraphicsUtils::valueArrayFromVariant<GLuint>(v, count: description.m_size, tupleSize: 1); |
635 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 1); |
636 | break; |
637 | } |
638 | |
639 | case GL_UNSIGNED_INT_VEC2: { |
640 | const GLuint *data = QGraphicsUtils::valueArrayFromVariant<GLuint>(v, count: description.m_size, tupleSize: 2); |
641 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 2); |
642 | break; |
643 | } |
644 | |
645 | case GL_UNSIGNED_INT_VEC3: { |
646 | const GLuint *data = QGraphicsUtils::valueArrayFromVariant<GLuint>(v, count: description.m_size, tupleSize: 3); |
647 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 3); |
648 | break; |
649 | } |
650 | |
651 | case GL_UNSIGNED_INT_VEC4: { |
652 | const GLuint *data = QGraphicsUtils::valueArrayFromVariant<GLuint>(v, count: description.m_size, tupleSize: 4); |
653 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 4); |
654 | break; |
655 | } |
656 | |
657 | case GL_BOOL: { |
658 | const GLboolean *data = QGraphicsUtils::valueArrayFromVariant<GLboolean>(v, count: description.m_size, tupleSize: 1); |
659 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 1); |
660 | break; |
661 | } |
662 | |
663 | case GL_BOOL_VEC2: { |
664 | const GLboolean *data = QGraphicsUtils::valueArrayFromVariant<GLboolean>(v, count: description.m_size, tupleSize: 2); |
665 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 2); |
666 | break; |
667 | } |
668 | |
669 | case GL_BOOL_VEC3: { |
670 | const GLboolean *data = QGraphicsUtils::valueArrayFromVariant<GLboolean>(v, count: description.m_size, tupleSize: 3); |
671 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 3); |
672 | break; |
673 | } |
674 | |
675 | case GL_BOOL_VEC4: { |
676 | const GLboolean *data = QGraphicsUtils::valueArrayFromVariant<GLboolean>(v, count: description.m_size, tupleSize: 4); |
677 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 4); |
678 | break; |
679 | } |
680 | |
681 | case GL_SAMPLER_1D: |
682 | case GL_SAMPLER_2D: |
683 | case GL_SAMPLER_3D: |
684 | case GL_SAMPLER_CUBE: |
685 | case GL_SAMPLER_BUFFER: |
686 | case GL_SAMPLER_2D_RECT: |
687 | case GL_INT_SAMPLER_1D: |
688 | case GL_INT_SAMPLER_2D: |
689 | case GL_INT_SAMPLER_3D: |
690 | case GL_INT_SAMPLER_CUBE: |
691 | case GL_INT_SAMPLER_BUFFER: |
692 | case GL_INT_SAMPLER_2D_RECT: |
693 | case GL_UNSIGNED_INT_SAMPLER_1D: |
694 | case GL_UNSIGNED_INT_SAMPLER_2D: |
695 | case GL_UNSIGNED_INT_SAMPLER_3D: |
696 | case GL_UNSIGNED_INT_SAMPLER_CUBE: |
697 | case GL_UNSIGNED_INT_SAMPLER_BUFFER: |
698 | case GL_UNSIGNED_INT_SAMPLER_2D_RECT: |
699 | case GL_SAMPLER_1D_SHADOW: |
700 | case GL_SAMPLER_2D_SHADOW: |
701 | case GL_SAMPLER_CUBE_SHADOW: |
702 | case GL_SAMPLER_1D_ARRAY: |
703 | case GL_SAMPLER_2D_ARRAY: |
704 | case GL_INT_SAMPLER_1D_ARRAY: |
705 | case GL_INT_SAMPLER_2D_ARRAY: |
706 | case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY: |
707 | case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: |
708 | case GL_SAMPLER_1D_ARRAY_SHADOW: |
709 | case GL_SAMPLER_2D_ARRAY_SHADOW: |
710 | case GL_SAMPLER_2D_RECT_SHADOW: |
711 | case GL_SAMPLER_2D_MULTISAMPLE: |
712 | case GL_INT_SAMPLER_2D_MULTISAMPLE: |
713 | case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: |
714 | case GL_SAMPLER_2D_MULTISAMPLE_ARRAY: |
715 | case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: |
716 | case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: { |
717 | Q_ASSERT(description.m_size == 1); |
718 | int value = v.toInt(); |
719 | QGraphicsUtils::fillDataArray<GLint>(buffer: bufferData, data: &value, description, tupleSize: 1); |
720 | break; |
721 | } |
722 | |
723 | default: |
724 | qWarning() << Q_FUNC_INFO << "unsupported uniform type:" << description.m_type << "for " << description.m_name; |
725 | break; |
726 | } |
727 | } |
728 | |
729 | uint GraphicsHelperGL3_3::uniformByteSize(const ShaderUniform &description) |
730 | { |
731 | uint rawByteSize = 0; |
732 | int arrayStride = qMax(a: description.m_arrayStride, b: 0); |
733 | int matrixStride = qMax(a: description.m_matrixStride, b: 0); |
734 | |
735 | switch (description.m_type) { |
736 | |
737 | case GL_FLOAT_VEC2: |
738 | case GL_INT_VEC2: |
739 | case GL_UNSIGNED_INT_VEC2: |
740 | rawByteSize = 8; |
741 | break; |
742 | |
743 | case GL_FLOAT_VEC3: |
744 | case GL_INT_VEC3: |
745 | case GL_UNSIGNED_INT_VEC3: |
746 | rawByteSize = 12; |
747 | break; |
748 | |
749 | case GL_FLOAT_VEC4: |
750 | case GL_INT_VEC4: |
751 | case GL_UNSIGNED_INT_VEC4: |
752 | rawByteSize = 16; |
753 | break; |
754 | |
755 | case GL_FLOAT_MAT2: |
756 | rawByteSize = matrixStride ? 2 * matrixStride : 16; |
757 | break; |
758 | |
759 | case GL_FLOAT_MAT2x4: |
760 | rawByteSize = matrixStride ? 2 * matrixStride : 32; |
761 | break; |
762 | |
763 | case GL_FLOAT_MAT4x2: |
764 | rawByteSize = matrixStride ? 4 * matrixStride : 32; |
765 | break; |
766 | |
767 | case GL_FLOAT_MAT3: |
768 | rawByteSize = matrixStride ? 3 * matrixStride : 36; |
769 | break; |
770 | |
771 | case GL_FLOAT_MAT2x3: |
772 | rawByteSize = matrixStride ? 2 * matrixStride : 24; |
773 | break; |
774 | |
775 | case GL_FLOAT_MAT3x2: |
776 | rawByteSize = matrixStride ? 3 * matrixStride : 24; |
777 | break; |
778 | |
779 | case GL_FLOAT_MAT4: |
780 | rawByteSize = matrixStride ? 4 * matrixStride : 64; |
781 | break; |
782 | |
783 | case GL_FLOAT_MAT4x3: |
784 | rawByteSize = matrixStride ? 4 * matrixStride : 48; |
785 | break; |
786 | |
787 | case GL_FLOAT_MAT3x4: |
788 | rawByteSize = matrixStride ? 3 * matrixStride : 48; |
789 | break; |
790 | |
791 | case GL_BOOL: |
792 | rawByteSize = 1; |
793 | break; |
794 | |
795 | case GL_BOOL_VEC2: |
796 | rawByteSize = 2; |
797 | break; |
798 | |
799 | case GL_BOOL_VEC3: |
800 | rawByteSize = 3; |
801 | break; |
802 | |
803 | case GL_BOOL_VEC4: |
804 | rawByteSize = 4; |
805 | break; |
806 | |
807 | case GL_INT: |
808 | case GL_FLOAT: |
809 | case GL_UNSIGNED_INT: |
810 | case GL_SAMPLER_1D: |
811 | case GL_SAMPLER_2D: |
812 | case GL_SAMPLER_3D: |
813 | case GL_SAMPLER_CUBE: |
814 | case GL_SAMPLER_BUFFER: |
815 | case GL_SAMPLER_2D_RECT: |
816 | case GL_INT_SAMPLER_1D: |
817 | case GL_INT_SAMPLER_2D: |
818 | case GL_INT_SAMPLER_3D: |
819 | case GL_INT_SAMPLER_CUBE: |
820 | case GL_INT_SAMPLER_BUFFER: |
821 | case GL_INT_SAMPLER_2D_RECT: |
822 | case GL_UNSIGNED_INT_SAMPLER_1D: |
823 | case GL_UNSIGNED_INT_SAMPLER_2D: |
824 | case GL_UNSIGNED_INT_SAMPLER_3D: |
825 | case GL_UNSIGNED_INT_SAMPLER_CUBE: |
826 | case GL_UNSIGNED_INT_SAMPLER_BUFFER: |
827 | case GL_UNSIGNED_INT_SAMPLER_2D_RECT: |
828 | case GL_SAMPLER_1D_SHADOW: |
829 | case GL_SAMPLER_2D_SHADOW: |
830 | case GL_SAMPLER_CUBE_SHADOW: |
831 | case GL_SAMPLER_1D_ARRAY: |
832 | case GL_SAMPLER_2D_ARRAY: |
833 | case GL_INT_SAMPLER_1D_ARRAY: |
834 | case GL_INT_SAMPLER_2D_ARRAY: |
835 | case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY: |
836 | case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: |
837 | case GL_SAMPLER_1D_ARRAY_SHADOW: |
838 | case GL_SAMPLER_2D_ARRAY_SHADOW: |
839 | case GL_SAMPLER_2D_RECT_SHADOW: |
840 | case GL_SAMPLER_2D_MULTISAMPLE: |
841 | case GL_INT_SAMPLER_2D_MULTISAMPLE: |
842 | case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: |
843 | case GL_SAMPLER_2D_MULTISAMPLE_ARRAY: |
844 | case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: |
845 | case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: |
846 | rawByteSize = 4; |
847 | break; |
848 | } |
849 | |
850 | return arrayStride ? rawByteSize * arrayStride : rawByteSize; |
851 | } |
852 | |
853 | void GraphicsHelperGL3_3::enableClipPlane(int clipPlane) |
854 | { |
855 | m_funcs->glEnable(GL_CLIP_DISTANCE0 + clipPlane); |
856 | } |
857 | |
858 | void GraphicsHelperGL3_3::disableClipPlane(int clipPlane) |
859 | { |
860 | m_funcs->glDisable(GL_CLIP_DISTANCE0 + clipPlane); |
861 | } |
862 | |
863 | void GraphicsHelperGL3_3::setClipPlane(int clipPlane, const QVector3D &normal, float distance) |
864 | { |
865 | // deprecated |
866 | Q_UNUSED(clipPlane); |
867 | Q_UNUSED(normal); |
868 | Q_UNUSED(distance); |
869 | } |
870 | |
871 | GLint GraphicsHelperGL3_3::maxClipPlaneCount() |
872 | { |
873 | GLint max = 0; |
874 | m_funcs->glGetIntegerv(GL_MAX_CLIP_DISTANCES, params: &max); |
875 | return max; |
876 | } |
877 | |
878 | void GraphicsHelperGL3_3::memoryBarrier(QMemoryBarrier::Operations barriers) |
879 | { |
880 | Q_UNUSED(barriers); |
881 | qWarning() << "memory barrier is not supported by OpenGL 3.3 (since 4.3)" ; |
882 | } |
883 | |
884 | void GraphicsHelperGL3_3::enablePrimitiveRestart(int primitiveRestartIndex) |
885 | { |
886 | m_funcs->glPrimitiveRestartIndex(index: primitiveRestartIndex); |
887 | m_funcs->glEnable(GL_PRIMITIVE_RESTART); |
888 | } |
889 | |
890 | void GraphicsHelperGL3_3::enableVertexAttributeArray(int location) |
891 | { |
892 | m_funcs->glEnableVertexAttribArray(index: location); |
893 | } |
894 | |
895 | void GraphicsHelperGL3_3::disablePrimitiveRestart() |
896 | { |
897 | m_funcs->glDisable(GL_PRIMITIVE_RESTART); |
898 | } |
899 | |
900 | void GraphicsHelperGL3_3::clearBufferf(GLint drawbuffer, const QVector4D &values) |
901 | { |
902 | GLfloat vec[4] = {values[0], values[1], values[2], values[3]}; |
903 | m_funcs->glClearBufferfv(GL_COLOR, drawbuffer, value: vec); |
904 | } |
905 | |
906 | void GraphicsHelperGL3_3::pointSize(bool programmable, GLfloat value) |
907 | { |
908 | if (programmable) { |
909 | m_funcs->glEnable(GL_PROGRAM_POINT_SIZE); |
910 | } else { |
911 | m_funcs->glDisable(GL_PROGRAM_POINT_SIZE); |
912 | m_funcs->glPointSize(size: value); |
913 | } |
914 | } |
915 | |
916 | void GraphicsHelperGL3_3::enablei(GLenum cap, GLuint index) |
917 | { |
918 | m_funcs->glEnablei(target: cap, index); |
919 | } |
920 | |
921 | void GraphicsHelperGL3_3::disablei(GLenum cap, GLuint index) |
922 | { |
923 | m_funcs->glDisablei(target: cap, index); |
924 | } |
925 | |
926 | void GraphicsHelperGL3_3::setSeamlessCubemap(bool enable) |
927 | { |
928 | if (enable) |
929 | m_funcs->glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); |
930 | else |
931 | m_funcs->glDisable(GL_TEXTURE_CUBE_MAP_SEAMLESS); |
932 | } |
933 | |
934 | QSize GraphicsHelperGL3_3::getRenderBufferDimensions(GLuint renderBufferId) |
935 | { |
936 | GLint width = 0; |
937 | GLint height = 0; |
938 | |
939 | m_funcs->glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer: renderBufferId); |
940 | m_funcs->glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, params: &width); |
941 | m_funcs->glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, params: &height); |
942 | m_funcs->glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer: 0); |
943 | |
944 | return QSize(width, height); |
945 | } |
946 | |
947 | QSize GraphicsHelperGL3_3::getTextureDimensions(GLuint textureId, GLenum target, uint level) |
948 | { |
949 | GLint width = 0; |
950 | GLint height = 0; |
951 | |
952 | m_funcs->glBindTexture(target, texture: textureId); |
953 | m_funcs->glGetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, params: &width); |
954 | m_funcs->glGetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, params: &height); |
955 | m_funcs->glBindTexture(target, texture: 0); |
956 | |
957 | return QSize(width, height); |
958 | } |
959 | |
960 | void GraphicsHelperGL3_3::dispatchCompute(GLuint wx, GLuint wy, GLuint wz) |
961 | { |
962 | Q_UNUSED(wx); |
963 | Q_UNUSED(wy); |
964 | Q_UNUSED(wz); |
965 | qWarning() << "Compute Shaders are not supported by OpenGL 3.3 (since OpenGL 4.3)" ; |
966 | } |
967 | |
968 | char *GraphicsHelperGL3_3::mapBuffer(GLenum target, GLsizeiptr size) |
969 | { |
970 | return static_cast<char*>(m_funcs->glMapBufferRange(target, offset: 0, length: size, GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)); |
971 | } |
972 | |
973 | GLboolean GraphicsHelperGL3_3::unmapBuffer(GLenum target) |
974 | { |
975 | return m_funcs->glUnmapBuffer(target); |
976 | } |
977 | |
978 | void GraphicsHelperGL3_3::glUniform1fv(GLint location, GLsizei count, const GLfloat *values) |
979 | { |
980 | m_funcs->glUniform1fv(location, count, value: values); |
981 | } |
982 | |
983 | void GraphicsHelperGL3_3::glUniform2fv(GLint location, GLsizei count, const GLfloat *values) |
984 | { |
985 | m_funcs->glUniform2fv(location, count, value: values); |
986 | } |
987 | |
988 | void GraphicsHelperGL3_3::glUniform3fv(GLint location, GLsizei count, const GLfloat *values) |
989 | { |
990 | m_funcs->glUniform3fv(location, count, value: values); |
991 | } |
992 | |
993 | void GraphicsHelperGL3_3::glUniform4fv(GLint location, GLsizei count, const GLfloat *values) |
994 | { |
995 | m_funcs->glUniform4fv(location, count, value: values); |
996 | } |
997 | |
998 | void GraphicsHelperGL3_3::glUniform1iv(GLint location, GLsizei count, const GLint *values) |
999 | { |
1000 | m_funcs->glUniform1iv(location, count, value: values); |
1001 | } |
1002 | |
1003 | void GraphicsHelperGL3_3::glUniform2iv(GLint location, GLsizei count, const GLint *values) |
1004 | { |
1005 | m_funcs->glUniform2iv(location, count, value: values); |
1006 | } |
1007 | |
1008 | void GraphicsHelperGL3_3::glUniform3iv(GLint location, GLsizei count, const GLint *values) |
1009 | { |
1010 | m_funcs->glUniform3iv(location, count, value: values); |
1011 | } |
1012 | |
1013 | void GraphicsHelperGL3_3::glUniform4iv(GLint location, GLsizei count, const GLint *values) |
1014 | { |
1015 | m_funcs->glUniform4iv(location, count, value: values); |
1016 | } |
1017 | |
1018 | void GraphicsHelperGL3_3::glUniform1uiv(GLint location, GLsizei count, const GLuint *values) |
1019 | { |
1020 | m_funcs->glUniform1uiv(location, count, value: values); |
1021 | } |
1022 | |
1023 | void GraphicsHelperGL3_3::glUniform2uiv(GLint location, GLsizei count, const GLuint *values) |
1024 | { |
1025 | m_funcs->glUniform2uiv(location, count, value: values); |
1026 | } |
1027 | |
1028 | void GraphicsHelperGL3_3::glUniform3uiv(GLint location, GLsizei count, const GLuint *values) |
1029 | { |
1030 | m_funcs->glUniform3uiv(location, count, value: values); |
1031 | } |
1032 | |
1033 | void GraphicsHelperGL3_3::glUniform4uiv(GLint location, GLsizei count, const GLuint *values) |
1034 | { |
1035 | m_funcs->glUniform4uiv(location, count, value: values); |
1036 | } |
1037 | |
1038 | void GraphicsHelperGL3_3::glUniformMatrix2fv(GLint location, GLsizei count, const GLfloat *values) |
1039 | { |
1040 | m_funcs->glUniformMatrix2fv(location, count, transpose: false, value: values); |
1041 | } |
1042 | |
1043 | void GraphicsHelperGL3_3::glUniformMatrix3fv(GLint location, GLsizei count, const GLfloat *values) |
1044 | { |
1045 | m_funcs->glUniformMatrix3fv(location, count, transpose: false, value: values); |
1046 | } |
1047 | |
1048 | void GraphicsHelperGL3_3::glUniformMatrix4fv(GLint location, GLsizei count, const GLfloat *values) |
1049 | { |
1050 | m_funcs->glUniformMatrix4fv(location, count, transpose: false, value: values); |
1051 | } |
1052 | |
1053 | void GraphicsHelperGL3_3::glUniformMatrix2x3fv(GLint location, GLsizei count, const GLfloat *values) |
1054 | { |
1055 | m_funcs->glUniformMatrix2x3fv(location, count, transpose: false, value: values); |
1056 | } |
1057 | |
1058 | void GraphicsHelperGL3_3::glUniformMatrix3x2fv(GLint location, GLsizei count, const GLfloat *values) |
1059 | { |
1060 | m_funcs->glUniformMatrix3x2fv(location, count, transpose: false, value: values); |
1061 | } |
1062 | |
1063 | void GraphicsHelperGL3_3::glUniformMatrix2x4fv(GLint location, GLsizei count, const GLfloat *values) |
1064 | { |
1065 | m_funcs->glUniformMatrix2x4fv(location, count, transpose: false, value: values); |
1066 | } |
1067 | |
1068 | void GraphicsHelperGL3_3::glUniformMatrix4x2fv(GLint location, GLsizei count, const GLfloat *values) |
1069 | { |
1070 | m_funcs->glUniformMatrix4x2fv(location, count, transpose: false, value: values); |
1071 | } |
1072 | |
1073 | void GraphicsHelperGL3_3::glUniformMatrix3x4fv(GLint location, GLsizei count, const GLfloat *values) |
1074 | { |
1075 | m_funcs->glUniformMatrix3x4fv(location, count, transpose: false, value: values); |
1076 | } |
1077 | |
1078 | void GraphicsHelperGL3_3::glUniformMatrix4x3fv(GLint location, GLsizei count, const GLfloat *values) |
1079 | { |
1080 | m_funcs->glUniformMatrix4x3fv(location, count, transpose: false, value: values); |
1081 | } |
1082 | |
1083 | UniformType GraphicsHelperGL3_3::uniformTypeFromGLType(GLenum type) |
1084 | { |
1085 | switch (type) { |
1086 | case GL_FLOAT: |
1087 | return UniformType::Float; |
1088 | case GL_FLOAT_VEC2: |
1089 | return UniformType::Vec2; |
1090 | case GL_FLOAT_VEC3: |
1091 | return UniformType::Vec3; |
1092 | case GL_FLOAT_VEC4: |
1093 | return UniformType::Vec4; |
1094 | case GL_FLOAT_MAT2: |
1095 | return UniformType::Mat2; |
1096 | case GL_FLOAT_MAT3: |
1097 | return UniformType::Mat3; |
1098 | case GL_FLOAT_MAT4: |
1099 | return UniformType::Mat4; |
1100 | case GL_FLOAT_MAT2x3: |
1101 | return UniformType::Mat2x3; |
1102 | case GL_FLOAT_MAT3x2: |
1103 | return UniformType::Mat3x2; |
1104 | case GL_FLOAT_MAT2x4: |
1105 | return UniformType::Mat2x4; |
1106 | case GL_FLOAT_MAT4x2: |
1107 | return UniformType::Mat4x2; |
1108 | case GL_FLOAT_MAT3x4: |
1109 | return UniformType::Mat3x4; |
1110 | case GL_FLOAT_MAT4x3: |
1111 | return UniformType::Mat4x3; |
1112 | case GL_INT: |
1113 | return UniformType::Int; |
1114 | case GL_INT_VEC2: |
1115 | return UniformType::IVec2; |
1116 | case GL_INT_VEC3: |
1117 | return UniformType::IVec3; |
1118 | case GL_INT_VEC4: |
1119 | return UniformType::IVec4; |
1120 | case GL_UNSIGNED_INT: |
1121 | return UniformType::UInt; |
1122 | case GL_UNSIGNED_INT_VEC2: |
1123 | return UniformType::UIVec2; |
1124 | case GL_UNSIGNED_INT_VEC3: |
1125 | return UniformType::UIVec3; |
1126 | case GL_UNSIGNED_INT_VEC4: |
1127 | return UniformType::UIVec4; |
1128 | case GL_BOOL: |
1129 | return UniformType::Bool; |
1130 | case GL_BOOL_VEC2: |
1131 | return UniformType::BVec2; |
1132 | case GL_BOOL_VEC3: |
1133 | return UniformType::BVec3; |
1134 | case GL_BOOL_VEC4: |
1135 | return UniformType::BVec4; |
1136 | |
1137 | case GL_SAMPLER_BUFFER: |
1138 | case GL_SAMPLER_1D: |
1139 | case GL_SAMPLER_1D_SHADOW: |
1140 | case GL_SAMPLER_1D_ARRAY: |
1141 | case GL_SAMPLER_2D: |
1142 | case GL_SAMPLER_2D_RECT: |
1143 | case GL_SAMPLER_2D_SHADOW: |
1144 | case GL_SAMPLER_2D_RECT_SHADOW: |
1145 | case GL_SAMPLER_CUBE: |
1146 | case GL_SAMPLER_CUBE_SHADOW: |
1147 | case GL_SAMPLER_2D_ARRAY: |
1148 | case GL_SAMPLER_2D_ARRAY_SHADOW: |
1149 | case GL_SAMPLER_2D_MULTISAMPLE: |
1150 | case GL_SAMPLER_2D_MULTISAMPLE_ARRAY: |
1151 | case GL_SAMPLER_3D: |
1152 | case GL_INT_SAMPLER_BUFFER: |
1153 | case GL_INT_SAMPLER_1D: |
1154 | case GL_INT_SAMPLER_2D: |
1155 | case GL_INT_SAMPLER_3D: |
1156 | case GL_INT_SAMPLER_CUBE: |
1157 | case GL_INT_SAMPLER_1D_ARRAY: |
1158 | case GL_INT_SAMPLER_2D_ARRAY: |
1159 | case GL_INT_SAMPLER_2D_MULTISAMPLE: |
1160 | case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: |
1161 | case GL_UNSIGNED_INT_SAMPLER_BUFFER: |
1162 | case GL_UNSIGNED_INT_SAMPLER_1D: |
1163 | case GL_UNSIGNED_INT_SAMPLER_2D: |
1164 | case GL_UNSIGNED_INT_SAMPLER_3D: |
1165 | case GL_UNSIGNED_INT_SAMPLER_CUBE: |
1166 | case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY: |
1167 | case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: |
1168 | case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: |
1169 | case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: |
1170 | return UniformType::Sampler; |
1171 | default: |
1172 | Q_UNREACHABLE_RETURN(UniformType::Float); |
1173 | } |
1174 | } |
1175 | |
1176 | void GraphicsHelperGL3_3::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter) |
1177 | { |
1178 | m_funcs->glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
1179 | } |
1180 | |
1181 | } // namespace OpenGL |
1182 | } // namespace Render |
1183 | } // namespace Qt3DRender |
1184 | |
1185 | QT_END_NAMESPACE |
1186 | |
1187 | #endif // !QT_OPENGL_ES_2 |
1188 | |