From 854d736882516400a6f8ecb172aa0374275dfcf4 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 17 Feb 2018 17:49:36 +0100 Subject: [PATCH] pgraph: fix alignment error in 32-bit Windows with Eigen Fixes #251 --- panda/src/pgraph/nodePath.cxx | 22 +++++++++++++++++++++- panda/src/pgraph/nodePath.h | 3 ++- panda/src/pgraph/shaderAttrib.cxx | 17 ++++++++++++++++- panda/src/pgraph/shaderAttrib.h | 3 ++- 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/panda/src/pgraph/nodePath.cxx b/panda/src/pgraph/nodePath.cxx index c9ccfd7c90..71bbb3a561 100644 --- a/panda/src/pgraph/nodePath.cxx +++ b/panda/src/pgraph/nodePath.cxx @@ -3262,7 +3262,7 @@ get_shader() const { * */ void NodePath:: -set_shader_input(ShaderInput inp) { +set_shader_input(const ShaderInput &inp) { nassertv_always(!is_empty()); PandaNode *pnode = node(); @@ -3278,6 +3278,26 @@ set_shader_input(ShaderInput inp) { } } +/** + * + */ +void NodePath:: +set_shader_input(ShaderInput &&inp) { + nassertv_always(!is_empty()); + + PandaNode *pnode = node(); + const RenderAttrib *attrib = + pnode->get_attrib(ShaderAttrib::get_class_slot()); + if (attrib != nullptr) { + const ShaderAttrib *sa = (const ShaderAttrib *)attrib; + pnode->set_attrib(sa->set_shader_input(move(inp))); + } else { + // Create a new ShaderAttrib for this node. + CPT(ShaderAttrib) sa = DCAST(ShaderAttrib, ShaderAttrib::make()); + pnode->set_attrib(sa->set_shader_input(move(inp))); + } +} + /** * */ diff --git a/panda/src/pgraph/nodePath.h b/panda/src/pgraph/nodePath.h index 617aac46a5..c5a3902c32 100644 --- a/panda/src/pgraph/nodePath.h +++ b/panda/src/pgraph/nodePath.h @@ -629,7 +629,8 @@ PUBLISHED: void set_shader_auto(BitMask32 shader_switch, int priority=0); void clear_shader(); - void set_shader_input(ShaderInput input); + void set_shader_input(const ShaderInput &input); + void set_shader_input(ShaderInput &&input); INLINE void set_shader_input(CPT_InternalName id, Texture *tex, const SamplerState &sampler, int priority=0); INLINE void set_shader_input(CPT_InternalName id, Texture *tex, bool read, bool write, int z=-1, int n=0, int priority=0); diff --git a/panda/src/pgraph/shaderAttrib.cxx b/panda/src/pgraph/shaderAttrib.cxx index 711e886828..130d85c1b8 100644 --- a/panda/src/pgraph/shaderAttrib.cxx +++ b/panda/src/pgraph/shaderAttrib.cxx @@ -195,7 +195,22 @@ clear_flag(int flag) const { * */ CPT(RenderAttrib) ShaderAttrib:: -set_shader_input(ShaderInput input) const { +set_shader_input(const ShaderInput &input) const { + ShaderAttrib *result = new ShaderAttrib(*this); + Inputs::iterator i = result->_inputs.find(input.get_name()); + if (i == result->_inputs.end()) { + result->_inputs.insert(Inputs::value_type(input.get_name(), input)); + } else { + i->second = input; + } + return return_new(result); +} + +/** + * + */ +CPT(RenderAttrib) ShaderAttrib:: +set_shader_input(ShaderInput &&input) const { ShaderAttrib *result = new ShaderAttrib(*this); Inputs::iterator i = result->_inputs.find(input.get_name()); if (i == result->_inputs.end()) { diff --git a/panda/src/pgraph/shaderAttrib.h b/panda/src/pgraph/shaderAttrib.h index cb1eec37d9..02a3189233 100644 --- a/panda/src/pgraph/shaderAttrib.h +++ b/panda/src/pgraph/shaderAttrib.h @@ -71,7 +71,8 @@ PUBLISHED: CPT(RenderAttrib) clear_shader() const; // Shader Inputs - CPT(RenderAttrib) set_shader_input(ShaderInput input) const; + CPT(RenderAttrib) set_shader_input(const ShaderInput &input) const; + CPT(RenderAttrib) set_shader_input(ShaderInput &&input) const; public: INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, Texture *tex, int priority=0) const;