-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce renderer-specific properties #459
Conversation
brayns/common/PropertyMap.h
Outdated
else | ||
property->setData(newProperty.getData()); | ||
property->_data = newProperty._data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use property->set() or call updateProperty() instead of playing with the internals? This is even unsafe and can cause the _data to no longer match its type
brayns/common/PropertyMap.h
Outdated
const Type type; | ||
|
||
template <typename T> | ||
Type getType(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this not redundant with the public Type type??
brayns/common/PropertyMap.h
Outdated
{ | ||
auto property = findProperty(name); | ||
if (property) | ||
return property->type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These type of statements can be rewritten as:
if (auto property = findProperty(name))
return property->type;
It improves scoping and is shorter to read
aoStrength -= 0.1f; | ||
if (aoStrength < 0.f) | ||
aoStrength = 0.f; | ||
renderer.updateProperty("aoWeight", aoStrength); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think string should be defined as constants in a single location
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strictly speaking, those actions should not be in the core, hence it becomes client code where those strings are either hardcoded or better, are taken from the schema. This is the case for the web clients. This change just tries to avoid breaking existing behavior. I can define a string constant here, but it's still wrong :)
brayns/common/PropertyMap.h
Outdated
PropertyMap::Property::Type getType(); | ||
|
||
Property *findProperty(const std::string &name) | ||
Property *findProperty(const std::string &name) const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the alignement of * and & is wrong in multiple places. Set DerivePointerBinding: false in .clang-format to prevent that.
brayns/common/PropertyMap.h
Outdated
} | ||
|
||
/** @return the type of the given property name. */ | ||
Property::Type getPropertyType(const std::string &name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
brayns/common/PropertyObject.h
Outdated
} | ||
|
||
private: | ||
std::string _type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename _type -> _currentType?
brayns/common/PropertyObject.h
Outdated
/** | ||
* Maps generic properties to user-defined types and tracks the current type | ||
* for querying, setting and updating its properties. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what "types" in this class refer to... The PropertyMap are collections of heterogeneous types, but it seems like it's used with a different meaning here. Can this be renamed / clarified?
} | ||
|
||
template <typename T, int S> | ||
void _addArrayPropertySchema(const std::shared_ptr<PropertyMap::Property> prop, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't just const PropertyMap::Property& prop be used here?
params.getRenderingParameters().setShadowIntensity(1.f); | ||
auto props = renderer.getPropertyMap(); | ||
props.updateProperty("shadows", 1.f); | ||
renderer.updateProperties(props); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't been part of the technical discussions, but this first usage example does not convince me that the change is an improvement:
- The code is longer
- Addressing by string is error-prone
- I'm not sure if type safety is guaranteed; I have the impression that props.updateProperty("shadows", "no_a_number"); would compile just fine, or am I wrong and that's the reason that I can see no test for that?
- It seem to me that internal properties of the Ospray shaders are being exposed directly throughout the application all the way to the web interface, completely breaking the encapsulation. If a shader in Ospray changes, all user code that relies on that magic string has to be fixed / recompiled / redeployed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the entire point: custom shaders have custom attributes, so they can and should no longer be hardcoded in the core. If the shader changes, it should be directly reflected on the client side (btw, the shader will not change really, but there will be new shaders from any plugin/module).
With the schema in place, having the properties for a specific shader being exposed is doable for the clients. Used here w/o any schema checks which tells the valid names and types, this looks wrong, agreed.
I addressed point 3, where the updated value must have the same type that the property was registered with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I see... if the shaders are moved to plugins then then PropertyMap is a way to provide reflexion for arbitrary C++ classes... in that case the string keys make sense. Then yes, make sure the intended usage is well tested:
PropertyMap is filled by plugin and only existing properties can be updated by clients in a type safe-manner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
38871dc
to
26659d7
Compare
* new web API: set-/get-renderer-params which returns the properties of the current renderer * hardcoded renderer types are gone, new renderers are identified by string * new PropertyObject base class of Renderer keeps properties per type * only one single renderer exists in Brayns, type switching happens on the OSPRay level only * resolved cyclic dependency scene <-> renderer
current renderer
OSPRay level only