diff options
Diffstat (limited to 'src/render/graphicshelpers/graphicscontext.cpp')
-rw-r--r-- | src/render/graphicshelpers/graphicscontext.cpp | 112 |
1 files changed, 107 insertions, 5 deletions
diff --git a/src/render/graphicshelpers/graphicscontext.cpp b/src/render/graphicshelpers/graphicscontext.cpp index 021637c24..9731e7c5e 100644 --- a/src/render/graphicshelpers/graphicscontext.cpp +++ b/src/render/graphicshelpers/graphicscontext.cpp @@ -1084,12 +1084,12 @@ void GraphicsContext::setParameters(ShaderParameterPack ¶meterPack) for (int i = 0; i < parameterPack.textures().size(); ++i) { const ShaderParameterPack::NamedTexture &namedTex = parameterPack.textures().at(i); Texture *t = manager->lookupResource<Texture, TextureManager>(namedTex.texId); - // TO DO : Rework the way textures are loaded if (t != nullptr) { int texUnit = activateTexture(TextureScopeMaterial, t); if (uniformValues.contains(namedTex.glslNameId)) { - QUniformValue &texUniform = uniformValues[namedTex.glslNameId]; - texUniform.setTextureUnit(texUnit); + UniformValue &texUniform = uniformValues[namedTex.glslNameId]; + Q_ASSERT(texUniform.valueType() == UniformValue::TextureValue); + texUniform.data<UniformValue::Texture>()->textureId = texUnit; } } } @@ -1145,8 +1145,7 @@ void GraphicsContext::setParameters(ShaderParameterPack ¶meterPack) for (const ShaderUniform &uniform : activeUniforms) { // We can use [] as we are sure the the uniform wouldn't // be un activeUniforms if there wasn't a matching value - const QUniformValue &value = values[uniform.m_nameId]; - value.apply(this, uniform); + applyUniform(uniform, values[uniform.m_nameId]); } } @@ -1176,6 +1175,109 @@ void GraphicsContext::disableAttribute(const GraphicsContext::VAOVertexAttribute prog->disableAttributeArray(attr.location); } +void GraphicsContext::applyUniform(const ShaderUniform &description, const UniformValue &v) +{ + const UniformType type = m_glHelper->uniformTypeFromGLType(description.m_type); + + switch (type) { + case UniformType::Float: + applyUniformHelper<UniformType::Float>(description.m_location, v); + break; + case UniformType::Vec2: + applyUniformHelper<UniformType::Vec2>(description.m_location, v); + break; + case UniformType::Vec3: + applyUniformHelper<UniformType::Vec3>(description.m_location, v); + break; + case UniformType::Vec4: + applyUniformHelper<UniformType::Vec4>(description.m_location, v); + break; + + case UniformType::Double: + applyUniformHelper<UniformType::Double>(description.m_location, v); + break; + case UniformType::DVec2: + applyUniformHelper<UniformType::DVec2>(description.m_location, v); + break; + case UniformType::DVec3: + applyUniformHelper<UniformType::DVec3>(description.m_location, v); + break; + case UniformType::DVec4: + applyUniformHelper<UniformType::DVec4>(description.m_location, v); + break; + + case UniformType::Sampler: + case UniformType::Int: + applyUniformHelper<UniformType::Int>(description.m_location, v); + break; + case UniformType::IVec2: + applyUniformHelper<UniformType::IVec2>(description.m_location, v); + break; + case UniformType::IVec3: + applyUniformHelper<UniformType::IVec3>(description.m_location, v); + break; + case UniformType::IVec4: + applyUniformHelper<UniformType::IVec4>(description.m_location, v); + break; + + case UniformType::UInt: + applyUniformHelper<UniformType::Int>(description.m_location, v); + break; + case UniformType::UIVec2: + applyUniformHelper<UniformType::IVec2>(description.m_location, v); + break; + case UniformType::UIVec3: + applyUniformHelper<UniformType::IVec3>(description.m_location, v); + break; + case UniformType::UIVec4: + applyUniformHelper<UniformType::IVec4>(description.m_location, v); + break; + + case UniformType::Bool: + applyUniformHelper<UniformType::Bool>(description.m_location, v); + break; + case UniformType::BVec2: + applyUniformHelper<UniformType::BVec2>(description.m_location, v); + break; + case UniformType::BVec3: + applyUniformHelper<UniformType::BVec3>(description.m_location, v); + break; + case UniformType::BVec4: + applyUniformHelper<UniformType::BVec4>(description.m_location, v); + break; + + case UniformType::Mat2: + applyUniformHelper<UniformType::Mat2>(description.m_location, v); + break; + case UniformType::Mat3: + applyUniformHelper<UniformType::Mat3>(description.m_location, v); + break; + case UniformType::Mat4: + applyUniformHelper<UniformType::Mat4>(description.m_location, v); + break; + case UniformType::Mat2x3: + applyUniformHelper<UniformType::Mat2x3>(description.m_location, v); + break; + case UniformType::Mat3x2: + applyUniformHelper<UniformType::Mat3x2>(description.m_location, v); + break; + case UniformType::Mat2x4: + applyUniformHelper<UniformType::Mat2x4>(description.m_location, v); + break; + case UniformType::Mat4x2: + applyUniformHelper<UniformType::Mat4x2>(description.m_location, v); + case UniformType::Mat3x4: + applyUniformHelper<UniformType::Mat3x4>(description.m_location, v); + break; + case UniformType::Mat4x3: + applyUniformHelper<UniformType::Mat4x3>(description.m_location, v); + break; + + default: + break; + } +} + // Note: needs to be called while VAO is bound void GraphicsContext::specifyAttribute(const Attribute *attribute, Buffer *buffer, int location) { |