diff options
Diffstat (limited to 'src/render/graphicshelpers/graphicscontext.cpp')
-rw-r--r-- | src/render/graphicshelpers/graphicscontext.cpp | 153 |
1 files changed, 143 insertions, 10 deletions
diff --git a/src/render/graphicshelpers/graphicscontext.cpp b/src/render/graphicshelpers/graphicscontext.cpp index acec8edf6..4c2d902f1 100644 --- a/src/render/graphicshelpers/graphicscontext.cpp +++ b/src/render/graphicshelpers/graphicscontext.cpp @@ -852,6 +852,11 @@ void GraphicsContext::alphaTest(GLenum mode1, GLenum mode2) m_glHelper->alphaTest(mode1, mode2); } +void GraphicsContext::bindFramebuffer(GLuint fbo) +{ + m_glHelper->bindFrameBufferObject(fbo); +} + void GraphicsContext::depthTest(GLenum mode) { m_glHelper->depthTest(mode); @@ -874,11 +879,6 @@ void GraphicsContext::bindFragOutputs(GLuint shader, const QHash<QString, int> & m_glHelper->bindFragDataLocation(shader, outputs); } -void GraphicsContext::bindUniform(const QVariant &v, const ShaderUniform &description) -{ - m_glHelper->bindUniform(v, description); -} - void GraphicsContext::bindUniformBlock(GLuint programId, GLuint uniformBlockIndex, GLuint uniformBlockBinding) { m_glHelper->bindUniformBlock(programId, uniformBlockIndex, uniformBlockBinding); @@ -1079,12 +1079,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; } } } @@ -1140,8 +1140,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]); } } @@ -1171,6 +1170,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) { @@ -1452,6 +1554,37 @@ QImage GraphicsContext::readFramebuffer(QSize size) return qt_gl_read_framebuffer(size, true, true); } +QT3D_UNIFORM_TYPE_IMPL(UniformType::Float, float, glUniform1fv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::Vec2, float, glUniform2fv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::Vec3, float, glUniform3fv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::Vec4, float, glUniform4fv) + +// OpenGL expects int* as values for booleans +QT3D_UNIFORM_TYPE_IMPL(UniformType::Bool, int, glUniform1iv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::BVec2, int, glUniform2iv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::BVec3, int, glUniform3iv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::BVec4, int, glUniform4iv) + +QT3D_UNIFORM_TYPE_IMPL(UniformType::Int, int, glUniform1iv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::IVec2, int, glUniform2iv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::IVec3, int, glUniform3iv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::IVec4, int, glUniform4iv) + +QT3D_UNIFORM_TYPE_IMPL(UniformType::UInt, uint, glUniform1uiv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::UIVec2, uint, glUniform2uiv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::UIVec3, uint, glUniform3uiv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::UIVec4, uint, glUniform4uiv) + +QT3D_UNIFORM_TYPE_IMPL(UniformType::Mat2, float, glUniformMatrix2fv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::Mat3, float, glUniformMatrix3fv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::Mat4, float, glUniformMatrix4fv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::Mat2x3, float, glUniformMatrix2x3fv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::Mat3x2, float, glUniformMatrix3x2fv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::Mat2x4, float, glUniformMatrix2x4fv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::Mat4x2, float, glUniformMatrix4x2fv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::Mat3x4, float, glUniformMatrix3x4fv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::Mat4x3, float, glUniformMatrix4x3fv) + } // namespace Render } // namespace Qt3DRender of namespace |