| 1 | // Copyright (C) 2020 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 "shaderparameterpack_p.h" |
| 5 | |
| 6 | #include <submissioncontext_p.h> |
| 7 | #include <Qt3DRender/private/texture_p.h> |
| 8 | |
| 9 | #include <Qt3DCore/private/vector_helper_p.h> |
| 10 | |
| 11 | #include <QOpenGLShaderProgram> |
| 12 | #include <QDebug> |
| 13 | #include <QColor> |
| 14 | #include <QQuaternion> |
| 15 | #include <Qt3DRender/private/renderlogging_p.h> |
| 16 | |
| 17 | QT_BEGIN_NAMESPACE |
| 18 | |
| 19 | namespace Qt3DRender { |
| 20 | namespace Render { |
| 21 | namespace Rhi { |
| 22 | |
| 23 | ShaderParameterPack::~ShaderParameterPack() |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | void ShaderParameterPack::reserve(int uniformCount) |
| 28 | { |
| 29 | m_uniforms.reserve(count: uniformCount); |
| 30 | m_submissionUniformIndices.reserve(n: uniformCount); |
| 31 | } |
| 32 | |
| 33 | void ShaderParameterPack::setUniform(const int glslNameId, const UniformValue &val) |
| 34 | { |
| 35 | m_uniforms.insert(key: glslNameId, value: val); |
| 36 | } |
| 37 | |
| 38 | void ShaderParameterPack::setTexture(const int glslNameId, int uniformArrayIndex, Qt3DCore::QNodeId texId) |
| 39 | { |
| 40 | for (size_t t = 0; t < m_textures.size(); ++t) { |
| 41 | if (m_textures[t].glslNameId != glslNameId || m_textures[t].uniformArrayIndex != uniformArrayIndex) |
| 42 | continue; |
| 43 | |
| 44 | m_textures[t].nodeId = texId; |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | m_textures.push_back(x: NamedResource(glslNameId, texId, uniformArrayIndex, NamedResource::Texture)); |
| 49 | } |
| 50 | |
| 51 | void ShaderParameterPack::setImage(const int glslNameId, int uniformArrayIndex, Qt3DCore::QNodeId id) |
| 52 | { |
| 53 | for (size_t i=0, m = m_images.size(); i < m; ++i) { |
| 54 | if (m_images[i].glslNameId != glslNameId || m_images[i].uniformArrayIndex != uniformArrayIndex) |
| 55 | continue; |
| 56 | |
| 57 | m_images[i].nodeId = id; |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | m_images.push_back(x: NamedResource(glslNameId, id, uniformArrayIndex, NamedResource::Image)); |
| 62 | } |
| 63 | |
| 64 | // Contains Uniform Block Index and QNodeId of the ShaderData (UBO) |
| 65 | void ShaderParameterPack::setUniformBuffer(BlockToUBO blockToUBO) |
| 66 | { |
| 67 | m_uniformBuffers.push_back(x: std::move(blockToUBO)); |
| 68 | } |
| 69 | |
| 70 | void ShaderParameterPack::setShaderStorageBuffer(BlockToSSBO blockToSSBO) |
| 71 | { |
| 72 | m_shaderStorageBuffers.push_back(x: std::move(blockToSSBO)); |
| 73 | } |
| 74 | |
| 75 | void ShaderParameterPack::setShaderDataForUBO(ShaderDataForUBO shaderDataForUBO) |
| 76 | { |
| 77 | if (!Qt3DCore::contains(destination: m_shaderDatasForUBOs, element: shaderDataForUBO)) |
| 78 | m_shaderDatasForUBOs.push_back(x: std::move(shaderDataForUBO)); |
| 79 | } |
| 80 | |
| 81 | void ShaderParameterPack::setSubmissionUniformIndex(const int uniformIdx) |
| 82 | { |
| 83 | m_submissionUniformIndices.push_back(x: uniformIdx); |
| 84 | } |
| 85 | |
| 86 | bool operator==(const ShaderDataForUBO &a, const ShaderDataForUBO &b) |
| 87 | { |
| 88 | return a.m_bindingIndex == b.m_bindingIndex && a.m_shaderDataID == b.m_shaderDataID; |
| 89 | } |
| 90 | |
| 91 | } // namespace Rhi |
| 92 | } // namespace Render |
| 93 | } // namespace Qt3DRender |
| 94 | |
| 95 | QT_END_NAMESPACE |
| 96 | |