MCPcopy Create free account
hub / github.com/ImageEngine/cortex / render

Method render

src/IECoreGL/Primitive.cpp:186–338  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

184}
185
186void Primitive::render( State *state ) const
187{
188 const Selector *currentSelector = Selector::currentSelector();
189 if( currentSelector && !state->get<Primitive::Selectable>()->value() )
190 {
191 // if we're not selectable then we don't need to do anything
192 return;
193 }
194
195 /// \todo Really we want to remove use of this deprecated push/pop functionality.
196 PushAttrib attributeBlock( GL_DEPTH_BUFFER_BIT | GL_POLYGON_BIT | GL_LINE_BIT | GL_POINT_BIT );
197
198 // if we're in GL_SELECT render mode then just render solid
199 // with a simple shader and early out.
200 if( currentSelector && currentSelector->mode() == Selector::GLSelect && state->get<DrawSolid>()->value() )
201 {
202 const Shader::Setup *uniformSetup = flatConstantShaderSetup( state, /* forIDRender = */ false );
203 Shader::Setup::ScopedBinding uniformBinding( *uniformSetup );
204 const Shader::Setup *primitiveSetup = shaderSetup( uniformSetup->shader(), state );
205 Shader::Setup::ScopedBinding primitiveBinding( *primitiveSetup );
206 render( state, Primitive::DrawSolid::staticTypeId() );
207 return;
208 }
209
210 // render the shaded primitive if requested
211 ///////////////////////////////////////////
212
213 if( state->get<Primitive::DrawSolid>()->value() )
214 {
215 glDepthMask( !depthSortRequested( state ) );
216 // the state itself will have a shader with some nice uniform parameter
217 // values. we are responsible for binding this setup. unless we're performing
218 // an id render for selection, in which case we're responsible for binding an
219 // id shader.
220 const Shader::Setup *uniformSetup = nullptr;
221 if( currentSelector && currentSelector->mode() == Selector::IDRender )
222 {
223 uniformSetup = flatConstantShaderSetup( state, /* forIDRender = */ true );
224 }
225 else
226 {
227 uniformSetup = state->get<ShaderStateComponent>()->shaderSetup();
228 }
229 Shader::Setup::ScopedBinding uniformBinding( *uniformSetup );
230 // we then bind our own setup on top, adding in the parameters
231 // stored on the primitive itself.
232 const Shader *shader = uniformSetup->shader();
233 const Shader::Setup *primitiveSetup = shaderSetup( shader, state );
234 Shader::Setup::ScopedBinding primitiveBinding( *primitiveSetup );
235 // inherit Cs from the state if it isn't provided by the shader or a primitive variable
236 if( !uniformSetup->hasCsValue() && !primitiveSetup->hasCsValue() )
237 {
238 if( const Shader::Parameter *csParameter = primitiveSetup->shader()->csParameter() )
239 {
240 glUniform3fv( csParameter->location, 1, state->get<Color>()->value().getValue() );
241 }
242 }
243 // then we defer to the derived class to perform the draw call.

Callers

nothing calls this directly

Calls 8

shaderSetupFunction · 0.85
shaderMethod · 0.80
hasCsValueMethod · 0.80
valueMethod · 0.45
modeMethod · 0.45
shaderSetupMethod · 0.45
csParameterMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected