Moved many KRPipeline public members to private.
Added KRPipeline::hasUniform to avoid accessing private members directly in KRMaterial. Added KRPipeline::setUniform overload, for setting an array of Matrix4's.
This commit is contained in:
@@ -357,7 +357,7 @@ void KRMaterial::bind(const KRNode::RenderInfo& ri, ModelFormat modelFormat, __u
|
|||||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_RIM_POWER, rim_power);
|
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_RIM_POWER, rim_power);
|
||||||
|
|
||||||
// Bind bones
|
// Bind bones
|
||||||
if(pShader->m_pushConstants[0].offset[KRPipeline::KRENGINE_UNIFORM_BONE_TRANSFORMS] != -1) {
|
if(pShader->hasUniform(KRPipeline::KRENGINE_UNIFORM_BONE_TRANSFORMS)) {
|
||||||
float bone_mats[256 * 16];
|
float bone_mats[256 * 16];
|
||||||
float *bone_mat_component = bone_mats;
|
float *bone_mat_component = bone_mats;
|
||||||
for(int bone_index=0; bone_index < bones.size(); bone_index++) {
|
for(int bone_index=0; bone_index < bones.size(); bone_index++) {
|
||||||
@@ -384,8 +384,8 @@ void KRMaterial::bind(const KRNode::RenderInfo& ri, ModelFormat modelFormat, __u
|
|||||||
*bone_mat_component++ = t[i];
|
*bone_mat_component++ = t[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(pShader->m_pushConstants[0].offset[KRPipeline::KRENGINE_UNIFORM_BONE_TRANSFORMS] != -1) {
|
if(pShader->hasUniform(KRPipeline::KRENGINE_UNIFORM_BONE_TRANSFORMS)) {
|
||||||
glUniformMatrix4fv(pShader->m_pushConstants[0].offset[KRPipeline::KRENGINE_UNIFORM_BONE_TRANSFORMS], (GLsizei)bones.size(), GL_FALSE, bone_mats);
|
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_BONE_TRANSFORMS, (Matrix4*)bone_mats, bones.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -115,8 +115,10 @@ KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const PipelineInf
|
|||||||
, m_pushConstantBuffer(nullptr)
|
, m_pushConstantBuffer(nullptr)
|
||||||
, m_pushConstantBufferSize(0)
|
, m_pushConstantBufferSize(0)
|
||||||
{
|
{
|
||||||
memset(m_pushConstants[0].size, 0, KRENGINE_NUM_UNIFORMS);
|
for (int i = 0; i < static_cast<int>(ShaderStages::shaderStageCount); i++) {
|
||||||
memset(m_pushConstants[0].offset, 0, KRENGINE_NUM_UNIFORMS * sizeof(int));
|
memset(m_pushConstants[i].size, 0, KRENGINE_NUM_UNIFORMS);
|
||||||
|
memset(m_pushConstants[i].offset, 0, KRENGINE_NUM_UNIFORMS * sizeof(int));
|
||||||
|
}
|
||||||
|
|
||||||
m_pipelineLayout = nullptr;
|
m_pipelineLayout = nullptr;
|
||||||
m_graphicsPipeline = nullptr;
|
m_graphicsPipeline = nullptr;
|
||||||
@@ -481,6 +483,16 @@ void KRPipeline::setUniform(int location, float value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool KRPipeline::hasUniform(int location) const
|
||||||
|
{
|
||||||
|
for (int i = 0; i < static_cast<int>(ShaderStages::shaderStageCount); i++) {
|
||||||
|
if (m_pushConstants[i].size) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void KRPipeline::setUniform(int location, int value)
|
void KRPipeline::setUniform(int location, int value)
|
||||||
{
|
{
|
||||||
if (m_pushConstants[0].size[location] == sizeof(value)) {
|
if (m_pushConstants[0].size[location] == sizeof(value)) {
|
||||||
@@ -520,6 +532,12 @@ void KRPipeline::setUniform(int location, const Matrix4 &value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KRPipeline::setUniform(int location, const Matrix4* value, const size_t count)
|
||||||
|
{
|
||||||
|
// TODO - Vulkan refactoring
|
||||||
|
// GLDEBUG(glUniformMatrix4fv(pShader->m_pushConstants[0].offset[KRPipeline::KRENGINE_UNIFORM_BONE_TRANSFORMS], (GLsizei)bones.size(), GL_FALSE, bone_mats));
|
||||||
|
}
|
||||||
|
|
||||||
bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera &camera, const KRViewport &viewport, const Matrix4 &matModel, const std::vector<KRPointLight *> *point_lights, const std::vector<KRDirectionalLight *> *directional_lights, const std::vector<KRSpotLight *> *spot_lights, const KRNode::RenderPass &renderPass)
|
bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera &camera, const KRViewport &viewport, const Matrix4 &matModel, const std::vector<KRPointLight *> *point_lights, const std::vector<KRDirectionalLight *> *directional_lights, const std::vector<KRSpotLight *> *spot_lights, const KRNode::RenderPass &renderPass)
|
||||||
{
|
{
|
||||||
setUniform(KRENGINE_UNIFORM_ABSOLUTE_TIME, getContext().getAbsoluteTime());
|
setUniform(KRENGINE_UNIFORM_ABSOLUTE_TIME, getContext().getAbsoluteTime());
|
||||||
|
|||||||
@@ -293,7 +293,19 @@ public:
|
|||||||
shaderStageCount
|
shaderStageCount
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *KRENGINE_UNIFORM_NAMES[];
|
bool hasUniform(int location) const;
|
||||||
|
void setUniform(int location, float value);
|
||||||
|
void setUniform(int location, int value);
|
||||||
|
void setUniform(int location, const Vector2 &value);
|
||||||
|
void setUniform(int location, const Vector3 &value);
|
||||||
|
void setUniform(int location, const Vector4 &value);
|
||||||
|
void setUniform(int location, const Matrix4 &value);
|
||||||
|
void setUniform(int location, const Matrix4* value, const size_t count);
|
||||||
|
|
||||||
|
VkPipeline& getPipeline();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const char* KRENGINE_UNIFORM_NAMES[];
|
||||||
|
|
||||||
struct PushConstantStageInfo
|
struct PushConstantStageInfo
|
||||||
{
|
{
|
||||||
@@ -304,19 +316,9 @@ public:
|
|||||||
|
|
||||||
uint8_t* m_pushConstantBuffer;
|
uint8_t* m_pushConstantBuffer;
|
||||||
int m_pushConstantBufferSize;
|
int m_pushConstantBufferSize;
|
||||||
|
|
||||||
char m_szKey[256];
|
|
||||||
|
|
||||||
void setUniform(int location, float value);
|
|
||||||
void setUniform(int location, int value);
|
|
||||||
void setUniform(int location, const Vector2 &value);
|
|
||||||
void setUniform(int location, const Vector3 &value);
|
|
||||||
void setUniform(int location, const Vector4 &value);
|
|
||||||
void setUniform(int location, const Matrix4 &value);
|
|
||||||
|
|
||||||
VkPipeline& getPipeline();
|
char m_szKey[256];
|
||||||
|
|
||||||
private:
|
|
||||||
VkPipelineLayout m_pipelineLayout;
|
VkPipelineLayout m_pipelineLayout;
|
||||||
VkPipeline m_graphicsPipeline;
|
VkPipeline m_graphicsPipeline;
|
||||||
VkPipelineLayout m_pushConstantsLayout;
|
VkPipelineLayout m_pushConstantsLayout;
|
||||||
|
|||||||
Reference in New Issue
Block a user