ShaderAttrib: add set_shader_inputs() for C++ users

Closes #521
This commit is contained in:
Brian Lach 2019-01-08 18:49:13 -05:00 committed by rdb
parent 80bb5c09fe
commit 95f3e30d37
2 changed files with 25 additions and 0 deletions

View File

@ -224,6 +224,29 @@ set_shader_input(ShaderInput &&input) const {
return return_new(result);
}
/**
* Returns a new ShaderAttrib with the given shader inputs set. This is a
* more efficient way to set multiple shader inputs than calling
* set_shader_input multiple times.
*/
CPT(RenderAttrib) ShaderAttrib::
set_shader_inputs(const pvector<ShaderInput> &inputs) const {
ShaderAttrib *result = new ShaderAttrib(*this);
size_t num_inputs = inputs.size();
for (size_t i = 0; i < num_inputs; i++) {
const ShaderInput &input = inputs[i];
Inputs::iterator itr = result->_inputs.find(input.get_name());
if (itr == result->_inputs.end()) {
result->_inputs.insert(Inputs::value_type(input.get_name(), input));
} else {
itr->second = input;
}
}
return return_new(result);
}
/**
* Sets the geometry instance count. Do not confuse this with instanceTo,
* which is used for animation instancing, and has nothing to do with this. A

View File

@ -92,6 +92,8 @@ public:
INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, double n1=0, double n2=0, double n3=0, double n4=1,
int priority=0) const;
CPT(RenderAttrib) set_shader_inputs(const pvector<ShaderInput> &inputs) const;
PUBLISHED:
EXTENSION(CPT(RenderAttrib) set_shader_input(CPT_InternalName, PyObject *, int priority=0) const);
EXTENSION(CPT(RenderAttrib) set_shader_inputs(PyObject *args, PyObject *kwargs) const);