MCPcopy Create free account
hub / github.com/cinder/Cinder / initDataImageSourceWithPboImpl

Method initDataImageSourceWithPboImpl

src/cinder/gl/Texture.cpp:1309–1345  ·  view source on GitHub ↗

Called by initData( ImageSourceRef ) when the user has supplied an intermediate PBO via Format We map the PBO after resizing it if necessary, and then use that as a data store for the ImageTargetGlTexture

Source from the content-addressed store, hash-verified

1307// Called by initData( ImageSourceRef ) when the user has supplied an intermediate PBO via Format
1308// We map the PBO after resizing it if necessary, and then use that as a data store for the ImageTargetGlTexture
1309void Texture2d::initDataImageSourceWithPboImpl( const ImageSourceRef &imageSource, const Format & /*format*/, GLint dataFormat, GLint dataType, ImageIo::ChannelOrder channelOrder, bool isGray, const PboRef &pbo )
1310{
1311 auto ctx = gl::context();
1312
1313 ctx->pushBufferBinding( GL_PIXEL_UNPACK_BUFFER, pbo->getId() );
1314 // resize the PBO if necessary
1315 if( pbo->getSize() < imageSource->getRowBytes() * imageSource->getHeight() )
1316 pbo->bufferData( imageSource->getRowBytes() * imageSource->getHeight(), nullptr, GL_STREAM_DRAW );
1317 void *pboData = pbo->map( GL_WRITE_ONLY );
1318
1319 if( imageSource->getDataType() == ImageIo::UINT8 ) {
1320 auto target = ImageTargetGlTexture<uint8_t>::create( this, channelOrder, isGray, imageSource->hasAlpha(), pboData );
1321 imageSource->load( target );
1322 pbo->unmap();
1323 glTexImage2D( mTarget, 0, mInternalFormat, mActualSize.x, mActualSize.y, 0, dataFormat, dataType, nullptr );
1324 }
1325 else if( imageSource->getDataType() == ImageIo::UINT16 ) {
1326 auto target = ImageTargetGlTexture<uint16_t>::create( this, channelOrder, isGray, imageSource->hasAlpha(), pboData );
1327 imageSource->load( target );
1328 pbo->unmap();
1329 glTexImage2D( mTarget, 0, mInternalFormat, mActualSize.x, mActualSize.y, 0, dataFormat, dataType, nullptr );
1330 }
1331 else if( imageSource->getDataType() == ImageIo::FLOAT16 ) {
1332 auto target = ImageTargetGlTexture<half_float>::create( this, channelOrder, isGray, imageSource->hasAlpha(), pboData );
1333 imageSource->load( target );
1334 pbo->unmap();
1335 glTexImage2D( mTarget, 0, mInternalFormat, mActualSize.x, mActualSize.y, 0, dataFormat, dataType, nullptr );
1336 }
1337 else {
1338 auto target = ImageTargetGlTexture<float>::create( this, channelOrder, isGray, imageSource->hasAlpha(), pboData );
1339 imageSource->load( target );
1340 pbo->unmap();
1341 glTexImage2D( mTarget, 0, mInternalFormat, mActualSize.x, mActualSize.y, 0, dataFormat, dataType, nullptr );
1342 }
1343
1344 ctx->popBufferBinding( GL_PIXEL_UNPACK_BUFFER );
1345}
1346#endif
1347
1348// Called by initData( ImageSourceRef ) when the user has NOT supplied an intermediate PBO

Callers

nothing calls this directly

Calls 12

pushBufferBindingMethod · 0.80
bufferDataMethod · 0.80
popBufferBindingMethod · 0.80
contextFunction · 0.70
createFunction · 0.50
getSizeMethod · 0.45
getRowBytesMethod · 0.45
getHeightMethod · 0.45
mapMethod · 0.45
hasAlphaMethod · 0.45
loadMethod · 0.45
unmapMethod · 0.45

Tested by

no test coverage detected