diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-02-18 05:20:39 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-02-23 20:57:58 +0300 |
commit | a963c7d48dade70474ec3b40bea5e99ebdbbc5d4 (patch) | |
tree | 7df66a8c09dec4f9bd1f9eb1f9d390339213c21d /intern/cycles/render/attribute.cpp | |
parent | 4448ed6c5e6d321c9f0822ca2d969f7e7041fe27 (diff) |
Code refactor: improve attribute handling for optional volume attributes.
A volume shader should be able to request attributes, and still be rendered
as homogeneous if no volume attributes are available for the object.
Diffstat (limited to 'intern/cycles/render/attribute.cpp')
-rw-r--r-- | intern/cycles/render/attribute.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/intern/cycles/render/attribute.cpp b/intern/cycles/render/attribute.cpp index f959b1fef8b..6816f8ca3f3 100644 --- a/intern/cycles/render/attribute.cpp +++ b/intern/cycles/render/attribute.cpp @@ -298,9 +298,13 @@ const char *Attribute::standard_name(AttributeStandard std) AttributeStandard Attribute::name_standard(const char *name) { - for(int std = ATTR_STD_NONE; std < ATTR_STD_NUM; std++) - if(strcmp(name, Attribute::standard_name((AttributeStandard)std)) == 0) - return (AttributeStandard)std; + if(name) { + for(int std = ATTR_STD_NONE; std < ATTR_STD_NUM; std++) { + if(strcmp(name, Attribute::standard_name((AttributeStandard)std)) == 0) { + return (AttributeStandard)std; + } + } + } return ATTR_STD_NONE; } @@ -615,9 +619,11 @@ bool AttributeRequestSet::modified(const AttributeRequestSet& other) void AttributeRequestSet::add(ustring name) { - foreach(AttributeRequest& req, requests) - if(req.name == name) + foreach(AttributeRequest& req, requests) { + if(req.name == name) { return; + } + } requests.push_back(AttributeRequest(name)); } @@ -641,6 +647,22 @@ void AttributeRequestSet::add(AttributeRequestSet& reqs) } } +void AttributeRequestSet::add_standard(ustring name) +{ + if(!name) { + return; + } + + AttributeStandard std = Attribute::name_standard(name.c_str()); + + if(std) { + add(std); + } + else { + add(name); + } +} + bool AttributeRequestSet::find(ustring name) { foreach(AttributeRequest& req, requests) |