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

Method endIDRender

src/IECoreGL/Selector.cpp:353–403  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

351 }
352
353 void endIDRender()
354 {
355 glUseProgram( m_prevProgram );
356 glViewport( m_prevViewport[0], m_prevViewport[1], m_prevViewport[2], m_prevViewport[3] );
357 m_frameBufferBinding.reset();
358
359 IECoreImage::ImagePrimitivePtr idsImage = m_frameBuffer->getColor( g_idBufferIndex )->imagePrimitive();
360 const IECore::UIntVectorData *idsData = static_cast<const IECore::UIntVectorData *>( idsImage->channels["Y"].get() );
361 const std::vector<unsigned int> ids = idsData->readable();
362
363 IECoreImage::ImagePrimitivePtr zImage;
364 std::string channelName;
365
366 if( !m_useCameraDepth )
367 {
368 zImage = m_frameBuffer->getDepth()->imagePrimitive();
369 channelName = "Z";
370 }
371 else
372 {
373 zImage = m_frameBuffer->getColor( g_cameraDepthBufferIndex )->imagePrimitive();
374 channelName = "R";
375 }
376
377 auto zData = static_cast<const IECore::FloatVectorData *>( zImage->channels[channelName].get() );
378 const std::vector<float> &z = zData->readable();
379
380 std::map<unsigned int, HitRecord> idRecords;
381 for( size_t i = 0, e = ids.size(); i < e; i++ )
382 {
383 if( ids[i] == 0 )
384 {
385 continue;
386 }
387 std::map<unsigned int, HitRecord>::iterator it = idRecords.find( ids[i] );
388 if( it == idRecords.end() )
389 {
390 HitRecord r( std::numeric_limits<float>::max(), std::numeric_limits<float>::lowest(), ids[i] );
391 it = idRecords.insert( std::pair<unsigned int, HitRecord>( ids[i], r ) ).first;
392 }
393 it->second.depthMin = std::min( it->second.depthMin, z[i] );
394 it->second.depthMax = std::max( it->second.depthMax, z[i] );
395 }
396
397 m_hits.clear();
398 m_hits.reserve( idRecords.size() );
399 for( std::map<unsigned int, HitRecord>::const_iterator it = idRecords.begin(), eIt = idRecords.end(); it != eIt; it++ )
400 {
401 m_hits.push_back( it->second );
402 }
403 }
404
405 void bindIDShader( const IECoreGL::Shader *shader )
406 {

Callers

nothing calls this directly

Calls 11

getColorMethod · 0.80
readableMethod · 0.80
getDepthMethod · 0.80
insertMethod · 0.80
imagePrimitiveMethod · 0.45
getMethod · 0.45
sizeMethod · 0.45
findMethod · 0.45
endMethod · 0.45
clearMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected