本文整理汇总了C++中DataSourceRef::getBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ DataSourceRef::getBuffer方法的具体用法?C++ DataSourceRef::getBuffer怎么用?C++ DataSourceRef::getBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataSourceRef
的用法示例。
在下文中一共展示了DataSourceRef::getBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setup
HRESULT Shader::setup(DataSourceRef dataSrc, const std::string& entryName)
{
if (dataSrc && dataSrc->getBuffer().getDataSize() > 0)
{
CComPtr<ID3DBlob> shaderBytecode;
HR( dx11::compileShader(dataSrc->getBuffer(), entryName, getProfileName(), &shaderBytecode) );
HR( doCreateShader(shaderBytecode, &mHandle) );
}
return hr;
}
示例2: mObj
//////////////////////////////////////////////////////////////////////////
// GlslProg
GlslProg::GlslProg( DataSourceRef vertexShader, DataSourceRef fragmentShader, DataSourceRef geometryShader )
: mObj( shared_ptr<Obj>( new Obj ) )
{
mObj->mHandle = glCreateProgram();
loadShader( vertexShader->getBuffer(), GL_VERTEX_SHADER_ARB );
if( fragmentShader )
loadShader( fragmentShader->getBuffer(), GL_FRAGMENT_SHADER_ARB );
if( geometryShader )
loadShader( geometryShader->getBuffer(), GL_GEOMETRY_SHADER_EXT );
link();
}
示例3: loadUrl
// Load JSON from URL
Value loadUrl(const string & url, bool isEscaped)
{
// Load URL
DataSourceRef dataSource = ci::loadUrl(Url(url, isEscaped));
// Read buffer
Buffer buffer;
try
{
buffer = dataSource->getBuffer();
}
catch (...)
{
Value value;
return value;
}
size_t dataSize = buffer.getDataSize();
shared_ptr<int_fast8_t> bufferStr(new int_fast8_t[dataSize + 1], checked_array_deleter<int_fast8_t>());
memcpy(bufferStr.get(), buffer.getData(), buffer.getDataSize());
bufferStr.get()[dataSize] = 0;
// Convert buffer to string, deserialize and return
return deserialize(string(reinterpret_cast<char *>(bufferStr.get())));
}
示例4: loadFromDataSource
void XmlTree::loadFromDataSource( DataSourceRef dataSource, XmlTree *result, const XmlTree::ParseOptions &parseOptions )
{
auto buf = dataSource->getBuffer();
size_t dataSize = buf->getSize();
unique_ptr<char[]> bufString( new char[dataSize+1] );
memcpy( bufString.get(), buf->getData(), buf->getSize() );
bufString.get()[dataSize] = 0;
rapidxml::xml_document<> doc; // character type defaults to char
if( parseOptions.getParseComments() )
doc.parse<rapidxml::parse_comment_nodes | rapidxml::parse_doctype_node>( bufString.get() );
else
doc.parse<rapidxml::parse_doctype_node>( bufString.get() );
parseItem( doc, NULL, result, parseOptions );
result->setNodeType( NODE_DOCUMENT ); // call this after parse - constructor replaces it
}
示例5: loadShader
void GeometryShaderApp::loadShader( const std::string &path )
{
// ATI/AMD drivers require layout qualifiers, where NVIDIA drivers specifically do not.
std::string header;
if( isNVIDIA() ) {
DataSourceRef headerFile = loadAsset("shaders/header_nvidia.txt");
header = std::string( (char*) headerFile->getBuffer().getData(), headerFile->getBuffer().getDataSize() );
}
else {
DataSourceRef headerFile = loadAsset("shaders/header_ati.txt");
header = std::string( (char*) headerFile->getBuffer().getData(), headerFile->getBuffer().getDataSize() );
}
// Load the geometry shader as a text file into memory and prepend the header
DataSourceRef geomFile = loadAsset(path);
std::string geom( (char*) geomFile->getBuffer().getData(), geomFile->getBuffer().getDataSize() );
geom = header + geom;
// Load vertex and fragments shaders as text files and compile the shader
try {
DataSourceRef vertFile = loadAsset("shaders/lines.vert");
std::string vert( (char*) vertFile->getBuffer().getData(), vertFile->getBuffer().getDataSize() );
DataSourceRef fragFile = loadAsset("shaders/lines.frag");
std::string frag( (char*) fragFile->getBuffer().getData(), fragFile->getBuffer().getDataSize() );
mShader = gl::GlslProg(
vert.c_str(), frag.c_str(), geom.c_str(),
GL_LINES_ADJACENCY_EXT, GL_TRIANGLE_STRIP, 7
);
}
catch( const std::exception &e ) {
console() << "Could not compile shader:" << e.what() << std::endl;
}
}
示例6: createFileQuartzRef
///////////////////////////////////////////////////////////////////////////////
// ImageSourceFileQuartz
ImageSourceFileQuartzRef ImageSourceFileQuartz::createFileQuartzRef( DataSourceRef dataSourceRef, ImageSource::Options options )
{
std::shared_ptr<CGImageSource> sourceRef;
std::shared_ptr<CGImage> imageRef;
::CFStringRef keys[1] = { kCGImageSourceShouldAllowFloat };
::CFBooleanRef values[1] = { kCFBooleanTrue };
const std::shared_ptr<__CFDictionary> optionsDict( (__CFDictionary*)CFDictionaryCreate( kCFAllocatorDefault, (const void **)&keys, (const void **)&values, 1, NULL, NULL ), cocoa::safeCfRelease );
if( dataSourceRef->isFilePath() ) {
::CFStringRef pathString = cocoa::createCfString( dataSourceRef->getFilePath().string() );
::CFURLRef urlRef = ::CFURLCreateWithFileSystemPath( kCFAllocatorDefault, pathString, kCFURLPOSIXPathStyle, false );
sourceRef = std::shared_ptr<CGImageSource>( ::CGImageSourceCreateWithURL( urlRef, optionsDict.get() ), cocoa::safeCfRelease );
::CFRelease( pathString );
::CFRelease( urlRef );
}
else if( dataSourceRef->isUrl() ) {
::CFURLRef urlRef = cocoa::createCfUrl( dataSourceRef->getUrl() );
if( ! urlRef )
throw ImageIoExceptionFailedLoad();
sourceRef = std::shared_ptr<CGImageSource>( ::CGImageSourceCreateWithURL( urlRef, optionsDict.get() ), cocoa::safeCfRelease );
::CFRelease( urlRef );
}
else { // last ditch, we'll use a dataref from the buffer
::CFDataRef dataRef = cocoa::createCfDataRef( dataSourceRef->getBuffer() );
if( ! dataRef )
throw ImageIoExceptionFailedLoad();
sourceRef = std::shared_ptr<CGImageSource>( ::CGImageSourceCreateWithData( dataRef, optionsDict.get() ), cocoa::safeCfRelease );
::CFRelease( dataRef );
}
if( sourceRef ) {
imageRef = std::shared_ptr<CGImage>( ::CGImageSourceCreateImageAtIndex( sourceRef.get(), options.getIndex(), optionsDict.get() ), CGImageRelease );
if( ! imageRef )
throw ImageIoExceptionFailedLoad();
}
else
throw ImageIoExceptionFailedLoad();
const std::shared_ptr<__CFDictionary> imageProperties( (__CFDictionary*)::CGImageSourceCopyProperties( sourceRef.get(), NULL ), ::CFRelease );
const std::shared_ptr<__CFDictionary> imageIndexProperties( (__CFDictionary*)::CGImageSourceCopyPropertiesAtIndex( sourceRef.get(), options.getIndex(), NULL ), ::CFRelease );
return ImageSourceFileQuartzRef( new ImageSourceFileQuartz( imageRef.get(), options, imageProperties, imageIndexProperties ) );
}
示例7: read
void XFont::read(InputSourceRef inputSource)
{
if (inputSource->isFile())
{
ifstream in(inputSource->getFilePath().c_str(), ifstream::binary);
readFromStream(in);
in.close();
}
else
{
DataSourceRef resource = inputSource->loadDataSource();
Buffer &buffer = resource->getBuffer();
ReadStreamBuffer tmp(buffer);
istream in(&tmp);
readFromStream(in);
}
}
示例8: createFileQuartzRef
///////////////////////////////////////////////////////////////////////////////
// ImageSourceFileQuartz
ImageSourceFileQuartzRef ImageSourceFileQuartz::createFileQuartzRef( DataSourceRef dataSourceRef )
{
::CGImageSourceRef sourceRef = NULL;
::CGImageRef imageRef = NULL;
::CFStringRef keys[1] = { kCGImageSourceShouldAllowFloat };
::CFBooleanRef values[1] = { kCFBooleanTrue };
::CFDictionaryRef optionsDict = ::CFDictionaryCreate( kCFAllocatorDefault, (const void **)&keys, (const void **)&values, 1, NULL, NULL );
if( dataSourceRef->isFilePath() ) {
::CFStringRef pathString = cocoa::createCfString( dataSourceRef->getFilePath() );
::CFURLRef urlRef = ::CFURLCreateWithFileSystemPath( kCFAllocatorDefault, pathString, kCFURLPOSIXPathStyle, false );
sourceRef = ::CGImageSourceCreateWithURL( urlRef, optionsDict );
::CFRelease( pathString );
::CFRelease( urlRef );
}
else if( dataSourceRef->isUrl() ) {
::CFURLRef urlRef = cocoa::createCfUrl( dataSourceRef->getUrl() );
if( ! urlRef )
throw ImageIoExceptionFailedLoad();
sourceRef = ::CGImageSourceCreateWithURL( urlRef, optionsDict );
::CFRelease( urlRef );
}
else { // last ditch, we'll use a dataref from the buffer
::CFDataRef dataRef = cocoa::createCfDataRef( dataSourceRef->getBuffer() );
if( ! dataRef )
throw ImageIoExceptionFailedLoad();
sourceRef = ::CGImageSourceCreateWithData( dataRef, optionsDict );
::CFRelease( dataRef );
}
if( sourceRef ) {
imageRef = ::CGImageSourceCreateImageAtIndex( sourceRef, 0, optionsDict );
::CFRelease( sourceRef );
if( ! imageRef )
throw ImageIoExceptionFailedLoad();
}
else
throw ImageIoExceptionFailedLoad();
return ImageSourceFileQuartzRef( new ImageSourceFileQuartz( imageRef ) );
}
示例9: in
FollowablePath::FollowablePath(InputSourceRef inputSource, int mode)
:
mode(mode)
{
if (inputSource->isFile())
{
ifstream in(inputSource->getFilePath().c_str(), ifstream::binary);
readFromStream(in);
in.close();
}
else
{
DataSourceRef resource = inputSource->loadDataSource();
Buffer &buffer = resource->getBuffer();
ReadStreamBuffer tmp(buffer);
istream in(&tmp);
readFromStream(in);
}
}
示例10: initFromDataSource
void MovieBase::initFromDataSource( DataSourceRef dataSourceRef, const std::string &mimeTypeHint )
{
startQuickTime();
if( dataSourceRef->isFilePath() ) { // try to use quicktime's native file handling if possible
getObj()->mMovie = openMovieFromPath( dataSourceRef->getFilePath() );
// no need to retain the data source
}
else if( dataSourceRef->isUrl() ) { // try to use quicktime's native Url handling if possible
// Create a loader for this Url and then wait on it
MovieLoader loader( dataSourceRef->getUrl() );
loader.waitForLoaded();
getObj()->mMovie = loader.transferMovieHandle();
// no need to retain the data source
}
else { // we'll need to load from memory; and we'll rer to the data source to make sure it doesn't go away before the movie does
Buffer buffer( dataSourceRef->getBuffer() );
getObj()->mMovie = openMovieFromMemory( buffer.getData(), buffer.getDataSize(), dataSourceRef->getFilePathHint(), mimeTypeHint );
getObj()->mDataSource = dataSourceRef; // retain a reference to the dataSource so that it doesn't go away before we do
}
init();
}
示例11: createIsolateAndSetup
Dart_Isolate DartTestApp::createIsolateAndSetup( const char* script_uri, const char* main, void* data, char** error )
{
DataSourceRef snapshot = loadResource( "snapshot_gen.bin" );
const uint8_t *snapshotData = (const uint8_t *)snapshot->getBuffer().getData();
LOG_V << "Creating isolate " << script_uri << ", " << main << endl;
Dart_Isolate isolate = Dart_CreateIsolate( script_uri, main, snapshotData, data, error );
if ( isolate == NULL ) {
LOG_E << "Couldn't create isolate: " << *error << endl;
return NULL;
}
LOG_V << "Entering scope" << endl;
Dart_EnterScope();
// Set up the library tag handler for this isolate.
LOG_V << "Setting up library tag handler" << endl;
Dart_Handle result = Dart_SetLibraryTagHandler( libraryTagHandler );
CHECK_RESULT( result );
Dart_ExitScope();
return isolate;
}
示例12: ImageIoExceptionFailedLoadTinyExr
ImageSourceFileTinyExr::ImageSourceFileTinyExr( DataSourceRef dataSource, ImageSource::Options /*options*/ )
{
mExrImage.reset( new EXRImage );
const char *error;
InitEXRImage( mExrImage.get() );
int status = 0;
if( dataSource->isFilePath() ) {
status = ParseMultiChannelEXRHeaderFromFile( mExrImage.get(), dataSource->getFilePath().string().c_str(), &error );
if( status != 0 )
throw ImageIoExceptionFailedLoadTinyExr( string( "Failed to parse OpenEXR header; Error message: " ) + error );
status = LoadMultiChannelEXRFromFile( mExrImage.get(), dataSource->getFilePath().string().c_str(), &error );
if( status != 0 )
throw ImageIoExceptionFailedLoadTinyExr( string( "Failed to parse OpenEXR file; Error message: " ) + error );
}
else {
BufferRef buffer = dataSource->getBuffer();
status = ParseMultiChannelEXRHeaderFromMemory( mExrImage.get(), (const unsigned char*)buffer->getData(), &error );
if( status != 0 )
throw ImageIoExceptionFailedLoadTinyExr( string( "Failed to parse OpenEXR header; Error message: " ) + error );
status = LoadMultiChannelEXRFromMemory( mExrImage.get(), (const unsigned char*)buffer->getData(), &error );
if( status != 0 )
throw ImageIoExceptionFailedLoadTinyExr( string( "Failed to parse OpenEXR file; Error message: " ) + error );
}
// verify that the channels are all the same size; currently we don't support variably sized channels
int pixelType = mExrImage->pixel_types[0];
for( int c = 1; c < mExrImage->num_channels; ++c ) {
if( pixelType != mExrImage->pixel_types[c] )
throw ImageIoExceptionFailedLoadTinyExr( "TinyExr: heterogneous channel data types not supported" );
}
switch( pixelType ) {
case TINYEXR_PIXELTYPE_HALF:
setDataType( ImageIo::FLOAT16 );
break;
case TINYEXR_PIXELTYPE_FLOAT:
setDataType( ImageIo::FLOAT32 );
break;
default:
throw ImageIoExceptionFailedLoadTinyExr( "TinyExr: Unknown data type" );
break;
}
setSize( mExrImage->width, mExrImage->height );
switch( mExrImage->num_channels ) {
case 3:
setColorModel( ImageIo::CM_RGB );
setChannelOrder( ImageIo::ChannelOrder::RGB );
break;
case 4:
setColorModel( ImageIo::CM_RGB );
setChannelOrder( ImageIo::ChannelOrder::RGBA );
break;
default:
throw ImageIoExceptionFailedLoadTinyExr( "TinyExr: Unsupported number of channels (" + to_string( mExrImage->num_channels ) + ")" );
}
}
示例13: mBuffer
AssimpLoader::AssimpLoader(DataSourceRef dataSource)
: mBuffer(dataSource->getBuffer())
{
string ext = getPathExtension(dataSource->getFilePath());
load(ext);
}
示例14: SourceFileWindowsMediaExceptionUnsupportedData
SourceFileWindowsMedia::SourceFileWindowsMedia( DataSourceRef dataSourceRef )
: Source()
{
mDataType = DATA_UNKNOWN;
mSampleRate = 0;
mChannelCount = 0;
mBitsPerSample = 0;
mBlockAlign = 0;
mIsPcm = FALSE;
mIsBigEndian = TRUE;
mIsInterleaved = FALSE;
/*if( dataSourceRef->isFilePath() ) {
//TODO: implement
} else if ( dataSourceRef->isFilePath() ) {
//TODO: implement WindowsMedia network functionallity
}else { //have to use buffer
//TODO: move current implementation into this
}*/
mBuffer = dataSourceRef->getBuffer();
::HRESULT hr;
msw::initializeCom();
//setup readers
IWMSyncReader * IWMReaderP = NULL;
hr = ::WMCreateSyncReader(0, 0, &IWMReaderP);
if( FAILED( hr ) ) {
throw SourceFileWindowsMediaExceptionUnsupportedData();
}
std::shared_ptr<IWMSyncReader> reader = msw::makeComShared<IWMSyncReader>( IWMReaderP );
//turn data into stream
uint32_t dataSize = getLength();
mMemHandle = std::shared_ptr<void>( ::GlobalAlloc( GMEM_MOVEABLE | GMEM_NODISCARD | GMEM_SHARE, dataSize ), GlobalFree );
LPVOID pMem = ::GlobalLock( mMemHandle.get() );
void * data = mBuffer.getData();
::CopyMemory( pMem, data, dataSize );
::GlobalUnlock( mMemHandle.get() );
::IStream* iStreamP;
hr = ::CreateStreamOnHGlobal( mMemHandle.get(), FALSE, &iStreamP );
if(FAILED(hr)) {
throw SourceFileWindowsMediaExceptionUnsupportedData();
}
std::shared_ptr<::IStream> pStream = msw::makeComShared<::IStream>( iStreamP );
hr = reader->OpenStream( pStream.get() );
if( FAILED(hr) ) {
throw SourceFileWindowsMediaExceptionUnsupportedData();
}
//ensure that there is only one stream in the file
DWORD nOutputCount;
hr = reader->GetOutputCount( &nOutputCount );
if( FAILED(hr) ) {
throw SourceFileWindowsMediaExceptionUnsupportedData();
}
//ensure this is audio only
if( nOutputCount != 1 ) {
throw SourceFileWindowsMediaExceptionUnsupportedData();
}
}
示例15: ImageIoExceptionFailedLoad
ImageSourceFileWic::ImageSourceFileWic( DataSourceRef dataSourceRef, ImageSource::Options options )
: ImageSource()
{
::HRESULT hr = S_OK;
// Initialize COM
msw::initializeCom();
// Create WIC factory
IWICImagingFactory *IWICFactoryP = NULL;
hr = ::CoCreateInstance( CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&IWICFactoryP) );
if( ! SUCCEEDED( hr ) )
throw ImageIoExceptionFailedLoad();
std::shared_ptr<IWICImagingFactory> IWICFactory = msw::makeComShared( IWICFactoryP );
// Create a decoder
IWICBitmapDecoder *decoderP = NULL;
if( dataSourceRef->isFilePath() ) {
hr = IWICFactory->CreateDecoderFromFilename(
toUtf16( dataSourceRef->getFilePath().string() ).c_str(), // Image to be decoded
NULL, // Do not prefer a particular vendor
GENERIC_READ, // Desired read access to the file
WICDecodeMetadataCacheOnDemand, // Cache metadata when needed
&decoderP // Pointer to the decoder
);
if( ! SUCCEEDED(hr) )
throw ImageIoExceptionFailedLoad();
}
else { // have to use a buffer
IWICStream *pIWICStream = NULL;
hr = IWICFactory->CreateStream( &pIWICStream );
if( ! SUCCEEDED(hr) )
throw ImageIoExceptionFailedLoad();
std::shared_ptr<IWICStream> stream = msw::makeComShared( pIWICStream );
Buffer buffer = dataSourceRef->getBuffer();
hr = stream->InitializeFromMemory( reinterpret_cast<BYTE*>( buffer.getData() ), buffer.getDataSize() );
if( ! SUCCEEDED(hr) )
throw ImageIoExceptionFailedLoad();
hr = IWICFactory->CreateDecoderFromStream( stream.get(), NULL, WICDecodeMetadataCacheOnDemand, &decoderP );
if( ! SUCCEEDED(hr) )
throw ImageIoExceptionFailedLoad();
}
std::shared_ptr<IWICBitmapDecoder> decoder = msw::makeComShared( decoderP );
// Retrieve the 'index' frame of the image from the decoder
IWICBitmapFrameDecode *frameP = NULL;
hr = decoder->GetFrame( options.getIndex(), &frameP );
if( ! SUCCEEDED(hr) )
throw ImageIoExceptionFailedLoad();
std::shared_ptr<IWICBitmapFrameDecode> frame = msw::makeComShared( frameP );
UINT width = 0, height = 0;
frame->GetSize( &width, &height );
mWidth = width; mHeight = height;
GUID pixelFormat = { 0 }, convertPixelFormat;
frame->GetPixelFormat( &pixelFormat );
bool requiresConversion = processFormat( pixelFormat, &convertPixelFormat );
mRowBytes = mWidth * ImageIo::dataTypeBytes( mDataType ) * channelOrderNumChannels( mChannelOrder );
mData = std::shared_ptr<uint8_t>( new uint8_t[mRowBytes * mHeight], boost::checked_array_delete<uint8_t> );
if( requiresConversion ) {
IWICFormatConverter *pIFormatConverter = NULL;
hr = IWICFactory->CreateFormatConverter( &pIFormatConverter );
if( ! SUCCEEDED( hr ) )
throw ImageIoExceptionFailedLoad();
std::shared_ptr<IWICFormatConverter> formatConverter = msw::makeComShared( pIFormatConverter );
hr = formatConverter->Initialize( frame.get(), convertPixelFormat, WICBitmapDitherTypeNone,
NULL, 0.f, WICBitmapPaletteTypeCustom );
if( ! SUCCEEDED( hr ) )
throw ImageIoExceptionFailedLoad();
hr = formatConverter->CopyPixels( NULL, (UINT)mRowBytes, mRowBytes * mHeight, mData.get() );
}
else
hr = frame->CopyPixels( NULL, (UINT)mRowBytes, mRowBytes * mHeight, mData.get() );
}