4848#include " IECore/TypeTraits.h"
4949
5050#include " boost/algorithm/string/predicate.hpp"
51+ #include " boost/container/flat_map.hpp"
5152#include " boost/format.hpp"
5253#include " boost/tokenizer.hpp"
5354
@@ -665,7 +666,8 @@ class Shader::Setup::MemberData : public IECore::RefCounted
665666 };
666667
667668 ConstShaderPtr shader;
668- vector<ValuePtr> values;
669+ boost::container::flat_map<GLint, ValuePtr> vertexValues;
670+ boost::container::flat_map<GLint, ValuePtr> uniformValues;
669671 bool hasCsValue;
670672
671673};
@@ -718,7 +720,7 @@ void Shader::Setup::addUniformParameter( const std::string &name, ConstTexturePt
718720 return ;
719721 }
720722
721- m_memberData->values . push_back ( new MemberData::TextureValue ( p->location , p->textureUnit , targetType, value ) );
723+ m_memberData->uniformValues [ p-> location ] = new MemberData::TextureValue ( p->location , p->textureUnit , targetType, value );
722724}
723725
724726template <typename Container>
@@ -790,7 +792,7 @@ void Shader::Setup::addUniformParameter( const std::string &name, IECore::ConstD
790792 case GL_INT_VEC3 :
791793 dimensions = 3 ;
792794 }
793- m_memberData->values . push_back ( new MemberData::UniformIntegerValue ( m_memberData->shader ->program (), p->location , dimensions, p->size , integers ) );
795+ m_memberData->uniformValues [ p-> location ] = new MemberData::UniformIntegerValue ( m_memberData->shader ->program (), p->location , dimensions, p->size , integers );
794796 }
795797 }
796798 else if ( p->type == GL_FLOAT || p->type == GL_FLOAT_VEC2 || p->type == GL_FLOAT_VEC3 || p->type == GL_FLOAT_VEC4 )
@@ -823,7 +825,7 @@ void Shader::Setup::addUniformParameter( const std::string &name, IECore::ConstD
823825 dimensions = 4 ;
824826 break ;
825827 }
826- m_memberData->values . push_back ( new MemberData::UniformFloatValue ( m_memberData->shader ->program (), p->location , dimensions, p->size , floats ) );
828+ m_memberData->uniformValues [ p-> location ] = new MemberData::UniformFloatValue ( m_memberData->shader ->program (), p->location , dimensions, p->size , floats );
827829 }
828830
829831 if ( name == " Cs" )
@@ -855,7 +857,7 @@ void Shader::Setup::addUniformParameter( const std::string &name, IECore::ConstD
855857 return ;
856858 }
857859
858- m_memberData->values . push_back ( new MemberData::UniformMatrixValue ( m_memberData->shader ->program (), p->location , dimensions0, dimensions1, p->size , floats ) );
860+ m_memberData->uniformValues [ p-> location ] = new MemberData::UniformMatrixValue ( m_memberData->shader ->program (), p->location , dimensions0, dimensions1, p->size , floats );
859861 }
860862 else
861863 {
@@ -908,7 +910,7 @@ void Shader::Setup::addVertexAttribute( const std::string &name, IECore::ConstDa
908910 CachedConverterPtr converter = CachedConverter::defaultCachedConverter ();
909911 ConstBufferPtr buffer = IECore::runTimeCast<const Buffer>( converter->convert ( value.get () ) );
910912
911- m_memberData->values . push_back ( new MemberData::VertexValue ( p->location , dataGLType, size, buffer, divisor ) );
913+ m_memberData->vertexValues [ p-> location ] = new MemberData::VertexValue ( p->location , dataGLType, size, buffer, divisor );
912914}
913915
914916bool Shader::Setup::hasCsValue () const
@@ -922,12 +924,14 @@ Shader::Setup::ScopedBinding::ScopedBinding( const Setup &setup )
922924 glGetIntegerv ( GL_CURRENT_PROGRAM, &m_previousProgram );
923925 glUseProgram ( m_setup.shader ()->m_implementation ->m_program );
924926
925- const vector<MemberData::ValuePtr> &values = m_setup.m_memberData ->values ;
926- for ( vector<MemberData::ValuePtr>::const_iterator it = values.begin (), eIt = values.end (); it != eIt; it++ )
927+ for ( const auto &keyValue : m_setup.m_memberData ->uniformValues )
927928 {
928- (*it)->bind ();
929+ keyValue.second ->bind ();
930+ }
931+ for ( const auto &keyValue : m_setup.m_memberData ->vertexValues )
932+ {
933+ keyValue.second ->bind ();
929934 }
930-
931935
932936 if ( Selector *currentSelector = Selector::currentSelector () )
933937 {
@@ -940,10 +944,13 @@ Shader::Setup::ScopedBinding::ScopedBinding( const Setup &setup )
940944
941945Shader::Setup::ScopedBinding::~ScopedBinding ()
942946{
943- const vector<MemberData::ValuePtr> &values = m_setup.m_memberData ->values ;
944- for ( vector<MemberData::ValuePtr>::const_iterator it = values.begin (), eIt = values.end (); it != eIt; it++ )
947+ for ( const auto &keyValue : m_setup.m_memberData ->uniformValues )
948+ {
949+ keyValue.second ->unbind ();
950+ }
951+ for ( const auto &keyValue : m_setup.m_memberData ->vertexValues )
945952 {
946- (*it) ->unbind ();
953+ keyValue. second ->unbind ();
947954 }
948955
949956 glUseProgram ( m_previousProgram );
0 commit comments