| 196 | } |
| 197 | |
| 198 | const Shader::Setup *PointsPrimitive::shaderSetup( const Shader *shader, State *state ) const |
| 199 | { |
| 200 | Type type = effectiveType( state ); |
| 201 | if( type == Point ) |
| 202 | { |
| 203 | // rendering as gl points goes through the normal process |
| 204 | return Primitive::shaderSetup( shader, state ); |
| 205 | } |
| 206 | else |
| 207 | { |
| 208 | // for rendering as disks, quads or spheres, we build a custom setup which we use |
| 209 | // for instancing primitives onto our points. |
| 210 | for( MemberData::InstancingSetupVector::const_iterator it = m_memberData->instancingSetups.begin(), eIt = m_memberData->instancingSetups.end(); it != eIt; it++ ) |
| 211 | { |
| 212 | if( it->originalShader == shader && it->type == type ) |
| 213 | { |
| 214 | return it->shaderSetup.get(); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | ConstShaderPtr instancingShader = shader; |
| 219 | ShaderStateComponent *shaderStateComponent = state->get<ShaderStateComponent>(); |
| 220 | if( instancingShader->vertexSource() == "" ) |
| 221 | { |
| 222 | // if the current shader has specific vertex source, then we assume the user has provided |
| 223 | // a shader capable of performing the instancing, but if not then we substitute in our own |
| 224 | // instancing vertex shader. |
| 225 | ShaderLoader *shaderLoader = shaderStateComponent->shaderLoader(); |
| 226 | instancingShader = shaderLoader->create( instancingVertexSource(), "", shader->fragmentSource() ); |
| 227 | } |
| 228 | |
| 229 | Shader::SetupPtr instancingShaderSetup = new Shader::Setup( instancingShader ); |
| 230 | shaderStateComponent->addParametersToShaderSetup( instancingShaderSetup.get() ); |
| 231 | addPrimitiveVariablesToShaderSetup( instancingShaderSetup.get(), "vertex", 1 ); |
| 232 | |
| 233 | instancingShaderSetup->addUniformParameter( "useWidth", new BoolData( static_cast<bool>( m_memberData->widths ) ) ); |
| 234 | if( !m_memberData->constantWidth ) |
| 235 | { |
| 236 | instancingShaderSetup->addUniformParameter( "constantwidth", new FloatData( 1.0f ) ); |
| 237 | } |
| 238 | instancingShaderSetup->addUniformParameter( "useAspectRatio", new BoolData( static_cast<bool>( m_memberData->patchAspectRatio ) ) ); |
| 239 | instancingShaderSetup->addUniformParameter( "useRotation", new BoolData( static_cast<bool>( m_memberData->rotations ) ) ); |
| 240 | |
| 241 | switch( type ) |
| 242 | { |
| 243 | case Disk : |
| 244 | if( !m_memberData->diskPrimitive ) |
| 245 | { |
| 246 | m_memberData->diskPrimitive = new DiskPrimitive( 0.5f ); |
| 247 | } |
| 248 | m_memberData->diskPrimitive->addPrimitiveVariablesToShaderSetup( instancingShaderSetup.get(), "instance" ); |
| 249 | break; |
| 250 | case Sphere : |
| 251 | if( !m_memberData->spherePrimitive ) |
| 252 | { |
| 253 | m_memberData->spherePrimitive = new SpherePrimitive( 0.5f ); |
| 254 | } |
| 255 | m_memberData->spherePrimitive->addPrimitiveVariablesToShaderSetup( instancingShaderSetup.get(), "instance" ); |
nothing calls this directly
no test coverage detected