MCPcopy Create free account
hub / github.com/carbonengine/trinity / ConvertEffectConstant

Function ConvertEffectConstant

trinity/Shader/Tr2Effect.cpp:125–201  ·  view source on GitHub ↗

-------------------------------------------------------------------------------------- Description: Look at the constant and build an ITriEffectParameter out of it Arguments: constant - constant being analyzed constantValues - blob with the default value for the constant adder - callback function that's in charge of actually adding the newly created parameter --------------------------------------

Source from the content-addressed store, hash-verified

123// adder - callback function that's in charge of actually adding the newly created parameter
124// --------------------------------------------------------------------------------------
125void ConvertEffectConstant( const Tr2EffectConstant& constant,
126 const char* constantValues,
127 std::function<void( ITriEffectParameter* )> adder )
128{
129 if( constant.type != Tr2EffectConstant::FLOAT )
130 {
131 return;
132 }
133 if( constant.elements > 1 )
134 {
135 // create new paramater
136 OTriFloatArrayParameter* newFloatArray = new OTriFloatArrayParameter(); // Creates object with 1 lock
137 newFloatArray->m_name = BlueSharedString( constant.name );
138 // create an instance for each vector4
139 for( unsigned int e = 0; e < constant.elements; ++e )
140 {
141 TriVector4Ptr newVector4;
142 newVector4.CreateInstance();
143 newVector4->m_data = *reinterpret_cast<const Vector4*>( constantValues + constant.offset + e * sizeof( Vector4 ) );
144 newFloatArray->m_value.Insert( -1, newVector4 );
145 }
146 adder( newFloatArray );
147 newFloatArray->Unlock();
148 }
149 else if( constant.dimension == 16 )
150 {
151 if( strstr( constant.name.c_str(), "Reflection" ) )
152 {
153 OTriVariableParameter* p = new OTriVariableParameter();
154 p->m_name = BlueSharedString( constant.name );
155 p->m_variableName = BlueSharedString( "EnvMapTransform" );
156 p->Initialize();
157 adder( p );
158 p->Unlock(); // Remove the original lock created by 'new'.
159 }
160 else
161 {
162 OTr2Matrix4Parameter* p = new OTr2Matrix4Parameter();
163 p->m_name = BlueSharedString( constant.name );
164 p->m_value = *reinterpret_cast<const Matrix*>( constantValues + constant.offset );
165 adder( p );
166 p->Unlock();
167 }
168 }
169 else if( constant.dimension == 2 )
170 {
171 OTr2Vector2Parameter* newVector2 = new OTr2Vector2Parameter(); // Creates object with 1 lock
172 newVector2->m_name = BlueSharedString( constant.name );
173 newVector2->m_value = *reinterpret_cast<const Vector2*>( constantValues + constant.offset );
174 adder( newVector2 );
175 newVector2->Unlock();
176 }
177 else if( constant.dimension == 3 )
178 {
179 OTr2Vector3Parameter* newVector3 = new OTr2Vector3Parameter(); // Creates object with 1 lock
180 newVector3->m_name = BlueSharedString( constant.name );
181 newVector3->m_value = *reinterpret_cast<const Vector3*>( constantValues + constant.offset );
182 adder( newVector3 );

Callers 1

PopulateParametersMethod · 0.85

Calls 3

CreateInstanceMethod · 0.80
UnlockMethod · 0.45
InitializeMethod · 0.45

Tested by

no test coverage detected