Skip to content
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

Merged
merged 1 commit into from
Jul 12, 2018

Conversation

tribal-tec
Copy link
Contributor

  • 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

else
property->setData(newProperty.getData());
property->_data = newProperty._data;
Copy link

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

const Type type;

template <typename T>
Type getType();
Copy link

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??

{
auto property = findProperty(name);
if (property)
return property->type;
Copy link

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);
Copy link

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

Copy link
Contributor Author

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 :)

PropertyMap::Property::Type getType();

Property *findProperty(const std::string &name)
Property *findProperty(const std::string &name) const
Copy link

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.

}

/** @return the type of the given property name. */
Property::Type getPropertyType(const std::string &name)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

}

private:
std::string _type;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename _type -> _currentType?

/**
* Maps generic properties to user-defined types and tracks the current type
* for querying, setting and updating its properties.
*/
Copy link

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,
Copy link

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);
Copy link

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:

  1. The code is longer
  2. Addressing by string is error-prone
  3. 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?
  4. 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.

Copy link
Contributor Author

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.

Copy link

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.

Copy link

@rdumusc rdumusc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@tribal-tec tribal-tec force-pushed the renderer branch 2 times, most recently from 38871dc to 26659d7 Compare July 12, 2018 08:35
* 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
@tribal-tec tribal-tec merged commit f5a1184 into BlueBrain:master Jul 12, 2018
@tribal-tec tribal-tec deleted the renderer branch July 12, 2018 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants