Skip to content

Commit b045666

Browse files
committed
Merge pull request #278 from davidsminor/sxStringArrayOptions
added support for string array options in SXRenderer
2 parents 3582375 + 5e3759e commit b045666

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

src/IECoreRI/SXRendererImplementation.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,17 @@ void IECoreRI::SXRendererImplementation::setOption( const std::string &name, IEC
166166
SxSetOption( m_stateStack.top().context.get(), name.c_str(), SxString, &s );
167167
break;
168168
}
169+
case StringVectorDataTypeId :
170+
{
171+
const std::vector<std::string>& strings = static_cast<const StringVectorData *>( value.get() )->readable();
172+
std::vector< const char* > s;
173+
for( size_t i=0; i < strings.size(); ++i )
174+
{
175+
s.push_back( strings[i].c_str() );
176+
}
177+
SxSetOption( m_stateStack.top().context.get(), name.c_str(), SxString, &(s[0]), s.size() );
178+
break;
179+
}
169180
default :
170181
msg( Msg::Warning, "IECoreRI::SXRendererImplementation::setOption", format( "Unsupport type \"%s\"." ) % value->typeName() );
171182
}

test/IECoreRI/SXRendererTest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,23 @@ def testUserOptions( self ):
900900

901901
s = r.shade( points )
902902
self.assertEqual( s["Ci"][0], IECore.Color3f( 1,1,1 ) )
903+
904+
def testStringArrayOptions( self ):
905+
906+
self.assertEqual( os.system( "shaderdl -Irsl -o test/IECoreRI/shaders/sxStringArrayOptionTest.sdl test/IECoreRI/shaders/sxStringArrayOptionTest.sl" ), 0 )
907+
908+
points = self.__rectanglePoints( IECore.Box2i( IECore.V2i( 0 ), IECore.V2i( 1 ) ) )
909+
910+
r = IECoreRI.SXRenderer()
911+
r.shader( "surface", "test/IECoreRI/shaders/sxStringArrayOptionTest.sdl", {} )
912+
913+
s = r.shade( points )
914+
self.assertEqual( s["Ci"][0], IECore.Color3f( 0,0,0 ) )
915+
916+
r.setOption( "user:stringArray", IECore.StringVectorData( ["this","should","work"] ) )
917+
918+
s = r.shade( points )
919+
self.assertEqual( s["Ci"][0], IECore.Color3f( 1,1,1 ) )
903920

904921

905922
def testCoordinateSystems( self ):
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
surface sxStringArrayOptionTest()
2+
{
3+
string stringArray[];
4+
option("user:stringArray", stringArray);
5+
6+
Ci = color(0);
7+
if( arraylength( stringArray ) == 3 )
8+
{
9+
if( stringArray[0] == "this" &&
10+
stringArray[1] == "should" &&
11+
stringArray[2] == "work" )
12+
{
13+
Ci = color(1);
14+
}
15+
}
16+
17+
18+
}

0 commit comments

Comments
 (0)