summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2017-08-04 16:12:16 +0100
committerSean Harmer <sean.harmer@kdab.com>2017-08-10 10:41:27 +0000
commite2e1a7986f92f76a2a2e79f911248de604af382f (patch)
tree46d18a7e9c6a574073742ba9aa76428624e854b6
parentc74ce04b4f3d25c21ccea6b836d30b4dbda2b6c0 (diff)
Extend standard uniforms to cover skinningPalette
This requires obtaining the skinning palette uniform from the entity. Up until now the standard uniforms only needed the entity's world transform. Now we need more, refactor the affected functions to pass in a pointer to the entity we are creating render commands for. Change-Id: Iba3c34159e798857682b9962266da1367ce9095c Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--src/render/backend/renderview.cpp52
-rw-r--r--src/render/backend/renderview_p.h21
-rw-r--r--src/render/backend/uniform_p.h2
-rw-r--r--src/render/geometry/armature_p.h1
-rw-r--r--src/render/graphicshelpers/graphicscontext.cpp60
-rw-r--r--src/render/graphicshelpers/graphicscontext_p.h10
6 files changed, 91 insertions, 55 deletions
diff --git a/src/render/backend/renderview.cpp b/src/render/backend/renderview.cpp
index 16e548062..8177f958b 100644
--- a/src/render/backend/renderview.cpp
+++ b/src/render/backend/renderview.cpp
@@ -133,6 +133,7 @@ RenderView::StandardUniformsNameToTypeHash RenderView::initializeStandardUniform
setters.insert(StringToInt::lookupId(QLatin1String("gamma")), Gamma);
setters.insert(StringToInt::lookupId(QLatin1String("time")), Time);
setters.insert(StringToInt::lookupId(QLatin1String("eyePosition")), EyePosition);
+ setters.insert(StringToInt::lookupId(QLatin1String("skinningPalette[0]")), SkinningPalette);
return setters;
}
@@ -153,7 +154,9 @@ static QMatrix4x4 getProjectionMatrix(const CameraLens *lens)
return lens ? lens->projection() : QMatrix4x4();
}
-UniformValue RenderView::standardUniformValue(RenderView::StandardUniform standardUniformType, const QMatrix4x4 &model) const
+UniformValue RenderView::standardUniformValue(RenderView::StandardUniform standardUniformType,
+ Entity *entity,
+ const QMatrix4x4 &model) const
{
switch (standardUniformType) {
case ModelMatrix:
@@ -205,6 +208,14 @@ UniformValue RenderView::standardUniformValue(RenderView::StandardUniform standa
return UniformValue(float(m_renderer->time() / 1000000000.0f));
case EyePosition:
return UniformValue(m_data.m_eyePos);
+ case SkinningPalette: {
+ const Armature *armature = entity->renderComponent<Armature>();
+ if (!armature) {
+ qCWarning(Jobs, "Requesting skinningPalette uniform but no armature set on entity");
+ return UniformValue();
+ }
+ return armature->skinningPaletteUniform();
+ }
default:
Q_UNREACHABLE();
return UniformValue();
@@ -372,15 +383,15 @@ QVector<RenderCommand *> RenderView::buildDrawRenderCommands(const QVector<Entit
QVector<RenderCommand *> commands;
commands.reserve(entities.size());
- for (Entity *node : entities) {
+ for (Entity *entity : entities) {
GeometryRenderer *geometryRenderer = nullptr;
- HGeometryRenderer geometryRendererHandle = node->componentHandle<GeometryRenderer, 16>();
+ HGeometryRenderer geometryRendererHandle = entity->componentHandle<GeometryRenderer, 16>();
// There is a geometry renderer with geometry
if ((geometryRenderer = m_manager->geometryRendererManager()->data(geometryRendererHandle)) != nullptr
&& geometryRenderer->isEnabled()
&& !geometryRenderer->geometryId().isNull()) {
- const Qt3DCore::QNodeId materialComponentId = node->componentUuid<Material>();
+ const Qt3DCore::QNodeId materialComponentId = entity->componentUuid<Material>();
const QVector<RenderPassParameterData> renderPassData = m_parameters.value(materialComponentId);
HGeometry geometryHandle = m_manager->lookupHandle<Geometry, GeometryManager, HGeometry>(geometryRenderer->geometryId());
Geometry *geometry = m_manager->data<Geometry, GeometryManager>(geometryHandle);
@@ -389,7 +400,7 @@ QVector<RenderCommand *> RenderView::buildDrawRenderCommands(const QVector<Entit
for (const RenderPassParameterData &passData : renderPassData) {
// Add the RenderPass Parameters
RenderCommand *command = new RenderCommand();
- command->m_depth = m_data.m_eyePos.distanceToPoint(node->worldBoundingVolume()->center());
+ command->m_depth = m_data.m_eyePos.distanceToPoint(entity->worldBoundingVolume()->center());
command->m_geometry = geometryHandle;
command->m_geometryRenderer = geometryRendererHandle;
// For RenderPass based states we use the globally set RenderState
@@ -414,7 +425,7 @@ QVector<RenderCommand *> RenderView::buildDrawRenderCommands(const QVector<Entit
// Copy vector so that we can sort it concurrently and we only want to sort the one for the current command
QVector<LightSource> lightSources = m_lightSources;
if (lightSources.size() > 1)
- std::sort(lightSources.begin(), lightSources.end(), LightSourceCompare(node));
+ std::sort(lightSources.begin(), lightSources.end(), LightSourceCompare(entity));
ParameterInfoList globalParameters = passData.parameterInfo;
// setShaderAndUniforms can initialize a localData
@@ -422,7 +433,7 @@ QVector<RenderCommand *> RenderView::buildDrawRenderCommands(const QVector<Entit
setShaderAndUniforms(command,
pass,
globalParameters,
- *(node->worldTransform()),
+ entity,
lightSources.mid(0, std::max(lightSources.size(), MAX_LIGHTS)),
m_environmentLight);
@@ -500,12 +511,12 @@ QVector<RenderCommand *> RenderView::buildComputeRenderCommands(const QVector<En
// material/effect/technique/parameters/filters/
QVector<RenderCommand *> commands;
commands.reserve(entities.size());
- for (Entity *node : entities) {
+ for (Entity *entity : entities) {
ComputeCommand *computeJob = nullptr;
- if ((computeJob = node->renderComponent<ComputeCommand>()) != nullptr
+ if ((computeJob = entity->renderComponent<ComputeCommand>()) != nullptr
&& computeJob->isEnabled()) {
- const Qt3DCore::QNodeId materialComponentId = node->componentUuid<Material>();
+ const Qt3DCore::QNodeId materialComponentId = entity->componentUuid<Material>();
const QVector<RenderPassParameterData> renderPassData = m_parameters.value(materialComponentId);
// 1 RenderCommand per RenderPass pass on an Entity with a Mesh
@@ -523,7 +534,7 @@ QVector<RenderCommand *> RenderView::buildComputeRenderCommands(const QVector<En
setShaderAndUniforms(command,
pass,
globalParameters,
- *(node->worldTransform()),
+ entity,
QVector<LightSource>(),
nullptr);
commands.append(command);
@@ -570,9 +581,13 @@ void RenderView::setUniformValue(ShaderParameterPack &uniformPack, int nameId, c
}
}
-void RenderView::setStandardUniformValue(ShaderParameterPack &uniformPack, int glslNameId, int nameId, const QMatrix4x4 &worldTransform) const
+void RenderView::setStandardUniformValue(ShaderParameterPack &uniformPack,
+ int glslNameId,
+ int nameId,
+ Entity *entity,
+ const QMatrix4x4 &worldTransform) const
{
- uniformPack.setUniform(glslNameId, standardUniformValue(ms_standardUniformSetters[nameId], worldTransform));
+ uniformPack.setUniform(glslNameId, standardUniformValue(ms_standardUniformSetters[nameId], entity, worldTransform));
}
void RenderView::setUniformBlockValue(ShaderParameterPack &uniformPack,
@@ -713,8 +728,12 @@ void RenderView::buildSortingKey(RenderCommand *command) const
}
}
-void RenderView::setShaderAndUniforms(RenderCommand *command, RenderPass *rPass, ParameterInfoList &parameters, const QMatrix4x4 &worldTransform,
- const QVector<LightSource> &activeLightSources, EnvironmentLight *environmentLight) const
+void RenderView::setShaderAndUniforms(RenderCommand *command,
+ RenderPass *rPass,
+ ParameterInfoList &parameters,
+ Entity *entity,
+ const QVector<LightSource> &activeLightSources,
+ EnvironmentLight *environmentLight) const
{
// The VAO Handle is set directly in the renderer thread so as to avoid having to use a mutex here
// Set shader, technique, and effect by basically doing :
@@ -757,9 +776,10 @@ void RenderView::setShaderAndUniforms(RenderCommand *command, RenderPass *rPass,
!shaderStorageBlockNamesIds.isEmpty() || !attributeNamesIds.isEmpty()) {
// Set default standard uniforms without bindings
+ QMatrix4x4 worldTransform = *(entity->worldTransform());
for (const int uniformNameId : uniformNamesIds) {
if (ms_standardUniformSetters.contains(uniformNameId))
- setStandardUniformValue(command->m_parameterPack, uniformNameId, uniformNameId, worldTransform);
+ setStandardUniformValue(command->m_parameterPack, uniformNameId, uniformNameId, entity, worldTransform);
}
// Set default attributes
diff --git a/src/render/backend/renderview_p.h b/src/render/backend/renderview_p.h
index 1f4a920c8..1674db0a5 100644
--- a/src/render/backend/renderview_p.h
+++ b/src/render/backend/renderview_p.h
@@ -261,8 +261,12 @@ public:
void setIsDownloadBuffersEnable(bool isDownloadBuffersEnable);
private:
- void setShaderAndUniforms(RenderCommand *command, RenderPass *pass, ParameterInfoList &parameters, const QMatrix4x4 &worldTransform,
- const QVector<LightSource> &activeLightSources, EnvironmentLight *environmentLight) const;
+ void setShaderAndUniforms(RenderCommand *command,
+ RenderPass *pass,
+ ParameterInfoList &parameters,
+ Entity *entity,
+ const QVector<LightSource> &activeLightSources,
+ EnvironmentLight *environmentLight) const;
mutable QThreadStorage<UniformBlockValueBuilder*> m_localData;
@@ -324,17 +328,24 @@ private:
Time,
Exposure,
Gamma,
- EyePosition
+ EyePosition,
+ SkinningPalette
};
typedef QHash<int, StandardUniform> StandardUniformsNameToTypeHash;
static StandardUniformsNameToTypeHash ms_standardUniformSetters;
static StandardUniformsNameToTypeHash initializeStandardUniformSetters();
- UniformValue standardUniformValue(StandardUniform standardUniformType, const QMatrix4x4 &model) const;
+ UniformValue standardUniformValue(StandardUniform standardUniformType,
+ Entity *entity,
+ const QMatrix4x4 &model) const;
void setUniformValue(ShaderParameterPack &uniformPack, int nameId, const UniformValue &value) const;
- void setStandardUniformValue(ShaderParameterPack &uniformPack, int glslNameId, int nameId, const QMatrix4x4 &worldTransform) const;
+ void setStandardUniformValue(ShaderParameterPack &uniformPack,
+ int glslNameId,
+ int nameId,
+ Entity *entity,
+ const QMatrix4x4 &worldTransform) const;
void setUniformBlockValue(ShaderParameterPack &uniformPack,
Shader *shader,
const ShaderUniformBlock &block,
diff --git a/src/render/backend/uniform_p.h b/src/render/backend/uniform_p.h
index eeb636dd5..e0d8fedeb 100644
--- a/src/render/backend/uniform_p.h
+++ b/src/render/backend/uniform_p.h
@@ -194,6 +194,8 @@ public:
static UniformValue fromVariant(const QVariant &variant);
+ int byteSize() const { return m_data.size() * sizeof(float); }
+
template<typename T>
const T *constData() const
{
diff --git a/src/render/geometry/armature_p.h b/src/render/geometry/armature_p.h
index 0a8c4ebb9..f0960d256 100644
--- a/src/render/geometry/armature_p.h
+++ b/src/render/geometry/armature_p.h
@@ -70,6 +70,7 @@ public:
// Called from jobs
UniformValue &skinningPaletteUniform() { return m_skinningPaletteUniform; }
+ const UniformValue &skinningPaletteUniform() const { return m_skinningPaletteUniform; }
private:
void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL;
diff --git a/src/render/graphicshelpers/graphicscontext.cpp b/src/render/graphicshelpers/graphicscontext.cpp
index 6473fee76..e480d0aa7 100644
--- a/src/render/graphicshelpers/graphicscontext.cpp
+++ b/src/render/graphicshelpers/graphicscontext.cpp
@@ -1301,100 +1301,100 @@ void GraphicsContext::applyUniform(const ShaderUniform &description, const Unifo
if (v.storedType() == Int) {
float value = float(*v.constData<int>());
UniformValue floatV(value);
- applyUniformHelper<UniformType::Float>(description.m_location, description.m_size, floatV);
+ applyUniformHelper<UniformType::Float>(description, floatV);
} else {
- applyUniformHelper<UniformType::Float>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::Float>(description, v);
}
break;
case UniformType::Vec2:
- applyUniformHelper<UniformType::Vec2>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::Vec2>(description, v);
break;
case UniformType::Vec3:
- applyUniformHelper<UniformType::Vec3>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::Vec3>(description, v);
break;
case UniformType::Vec4:
- applyUniformHelper<UniformType::Vec4>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::Vec4>(description, v);
break;
case UniformType::Double:
- applyUniformHelper<UniformType::Double>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::Double>(description, v);
break;
case UniformType::DVec2:
- applyUniformHelper<UniformType::DVec2>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::DVec2>(description, v);
break;
case UniformType::DVec3:
- applyUniformHelper<UniformType::DVec3>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::DVec3>(description, v);
break;
case UniformType::DVec4:
- applyUniformHelper<UniformType::DVec4>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::DVec4>(description, v);
break;
case UniformType::Sampler:
case UniformType::Int:
- applyUniformHelper<UniformType::Int>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::Int>(description, v);
break;
case UniformType::IVec2:
- applyUniformHelper<UniformType::IVec2>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::IVec2>(description, v);
break;
case UniformType::IVec3:
- applyUniformHelper<UniformType::IVec3>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::IVec3>(description, v);
break;
case UniformType::IVec4:
- applyUniformHelper<UniformType::IVec4>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::IVec4>(description, v);
break;
case UniformType::UInt:
- applyUniformHelper<UniformType::UInt>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::UInt>(description, v);
break;
case UniformType::UIVec2:
- applyUniformHelper<UniformType::UIVec2>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::UIVec2>(description, v);
break;
case UniformType::UIVec3:
- applyUniformHelper<UniformType::UIVec3>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::UIVec3>(description, v);
break;
case UniformType::UIVec4:
- applyUniformHelper<UniformType::UIVec4>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::UIVec4>(description, v);
break;
case UniformType::Bool:
- applyUniformHelper<UniformType::Bool>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::Bool>(description, v);
break;
case UniformType::BVec2:
- applyUniformHelper<UniformType::BVec2>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::BVec2>(description, v);
break;
case UniformType::BVec3:
- applyUniformHelper<UniformType::BVec3>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::BVec3>(description, v);
break;
case UniformType::BVec4:
- applyUniformHelper<UniformType::BVec4>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::BVec4>(description, v);
break;
case UniformType::Mat2:
- applyUniformHelper<UniformType::Mat2>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::Mat2>(description, v);
break;
case UniformType::Mat3:
- applyUniformHelper<UniformType::Mat3>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::Mat3>(description, v);
break;
case UniformType::Mat4:
- applyUniformHelper<UniformType::Mat4>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::Mat4>(description, v);
break;
case UniformType::Mat2x3:
- applyUniformHelper<UniformType::Mat2x3>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::Mat2x3>(description, v);
break;
case UniformType::Mat3x2:
- applyUniformHelper<UniformType::Mat3x2>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::Mat3x2>(description, v);
break;
case UniformType::Mat2x4:
- applyUniformHelper<UniformType::Mat2x4>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::Mat2x4>(description, v);
break;
case UniformType::Mat4x2:
- applyUniformHelper<UniformType::Mat4x2>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::Mat4x2>(description, v);
break;
case UniformType::Mat3x4:
- applyUniformHelper<UniformType::Mat3x4>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::Mat3x4>(description, v);
break;
case UniformType::Mat4x3:
- applyUniformHelper<UniformType::Mat4x3>(description.m_location, description.m_size, v);
+ applyUniformHelper<UniformType::Mat4x3>(description, v);
break;
default:
diff --git a/src/render/graphicshelpers/graphicscontext_p.h b/src/render/graphicshelpers/graphicscontext_p.h
index b89a42ec6..f1dc176f8 100644
--- a/src/render/graphicshelpers/graphicscontext_p.h
+++ b/src/render/graphicshelpers/graphicscontext_p.h
@@ -70,6 +70,7 @@
#include <Qt3DRender/private/qgraphicsapifilter_p.h>
#include <Qt3DRender/private/shadercache_p.h>
#include <Qt3DRender/private/uniform_p.h>
+#include <qmath.h>
QT_BEGIN_NAMESPACE
@@ -333,7 +334,7 @@ private:
void applyUniform(const ShaderUniform &description, const UniformValue &v);
template<UniformType>
- void applyUniformHelper(int, int, const UniformValue &) const
+ void applyUniformHelper(const ShaderUniform &, const UniformValue &) const
{
Q_ASSERT_X(false, Q_FUNC_INFO, "Uniform: Didn't provide specialized apply() implementation");
}
@@ -341,13 +342,14 @@ private:
#define QT3D_UNIFORM_TYPE_PROTO(UniformTypeEnum, BaseType, Func) \
template<> \
-void GraphicsContext::applyUniformHelper<UniformTypeEnum>(int location, int count, const UniformValue &value) const;
+void GraphicsContext::applyUniformHelper<UniformTypeEnum>(const ShaderUniform &description, const UniformValue &value) const;
#define QT3D_UNIFORM_TYPE_IMPL(UniformTypeEnum, BaseType, Func) \
template<> \
- void GraphicsContext::applyUniformHelper<UniformTypeEnum>(int location, int count, const UniformValue &value) const \
+ void GraphicsContext::applyUniformHelper<UniformTypeEnum>(const ShaderUniform &description, const UniformValue &value) const \
{ \
- m_glHelper->Func(location, count, value.constData<BaseType>()); \
+ const int count = qMin(description.m_size, int(value.byteSize() / description.m_rawByteSize)); \
+ m_glHelper->Func(description.m_location, count, value.constData<BaseType>()); \
}