@@ -153,6 +153,8 @@ const Shader::Setup *flatConstantShaderSetup( State *state, bool forIDRender )
153153 return shaderSetup.get ();
154154}
155155
156+ const std::string g_P ( " P" );
157+
156158} // namespace
157159
158160// ////////////////////////////////////////////////////////////////////////
@@ -380,6 +382,28 @@ void Primitive::addVertexAttribute( const std::string &name, IECore::ConstDataPt
380382 m_vertexAttributes[name] = data->copy ();
381383}
382384
385+ ConstBufferPtr Primitive::getVertexBuffer ( const std::string &name ) const
386+ {
387+ const AttributeMap::const_iterator it = m_vertexAttributes.find ( name );
388+ return ( it != m_vertexAttributes.end () )
389+ ? IECore::runTimeCast< const Buffer >( CachedConverter::defaultCachedConverter ()->convert ( it->second .get () ) )
390+ : ConstBufferPtr ();
391+ }
392+
393+ size_t Primitive::getVertexCount () const
394+ {
395+ // NOTE : It would perhaps be better if the vertex count was stored as a member variable, then we could
396+ // check the size of each registered vertex attribute as it is added. Derived classes would need
397+ // to set this value perhaps as an argument to the constructor. However that would break ABI so for
398+ // now determine the vertex count by inspecting the size of the "P" attribute which ALL primitives
399+ // should have registered.
400+
401+ const AttributeMap::const_iterator it = m_vertexAttributes.find ( g_P );
402+ return ( ( it != m_vertexAttributes.end () ) && ( IECore::runTimeCast< const IECore::V3fVectorData >( it->second ) ) )
403+ ? static_cast < size_t >( IECore::assertedStaticCast< const IECore::V3fVectorData >( it->second )->readable ().size () )
404+ : static_cast < size_t >( 0 );
405+ }
406+
383407bool Primitive::depthSortRequested ( const State * state ) const
384408{
385409 return state->get <Primitive::TransparencySort>()->value () &&
0 commit comments