当前位置: 首页>>代码示例>>C++>>正文


C++ AAsset_getLength函数代码示例

本文整理汇总了C++中AAsset_getLength函数的典型用法代码示例。如果您正苦于以下问题:C++ AAsset_getLength函数的具体用法?C++ AAsset_getLength怎么用?C++ AAsset_getLength使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了AAsset_getLength函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: AAssetManager_open

Shader::Shader(AAssetManager* assetMgr){
	AAsset* asset;
	long sizeAsset;
	asset = AAssetManager_open(assetMgr, "Shaders/triangle.vert", AASSET_MODE_STREAMING);
	sizeAsset = AAsset_getLength(asset);
	gVertexShader = (char*) malloc (sizeof(char)*sizeAsset + 1);
	AAsset_read (asset,gVertexShader,sizeAsset);
	gVertexShader[sizeAsset] = 0;
	AAsset_close(asset);

	asset = AAssetManager_open(assetMgr, "Shaders/triangle.frag", AASSET_MODE_STREAMING);
	sizeAsset = AAsset_getLength(asset);
	gFragmentShader = (char*) malloc (sizeof(char)*sizeAsset + 1);
	AAsset_read (asset,gFragmentShader,sizeAsset);
	gFragmentShader[sizeAsset] = 0;
	AAsset_close(asset);

	asset = AAssetManager_open(assetMgr, "Shaders/line.vert", AASSET_MODE_STREAMING);
	sizeAsset = AAsset_getLength(asset);
	gLineVertexShader = (char*) malloc (sizeof(char)*sizeAsset + 1);
	AAsset_read (asset,gLineVertexShader,sizeAsset);
	gLineVertexShader[sizeAsset] = 0;
	LOGE("%s\n",gLineVertexShader);
	AAsset_close(asset);

	asset = AAssetManager_open(assetMgr, "Shaders/line.frag", AASSET_MODE_STREAMING);
	sizeAsset = AAsset_getLength(asset);
	gFragmentLineShader = (char*) malloc (sizeof(char)*sizeAsset + 1);
	AAsset_read (asset,gFragmentLineShader,sizeAsset);
	gFragmentLineShader[sizeAsset] = 0;
	LOGE("%s\n",gFragmentLineShader);
	AAsset_close(asset);
}
开发者ID:rakesh-malviya,项目名称:Android-Game-Engine-NDK,代码行数:33,代码来源:Shader.cpp


示例2: TRACE_LOG

/**
 * Get shader program according to type.
 */
GLuint ShaderProgramFactory::CreateShaderProgram(AAssetManager* assetManager, ShaderType type) {
    if (mShaderPrograms[type] != INVALID_PROGRAM) {
        // Already created.
        return mShaderPrograms[type];
    }

    TRACE_LOG("Create new ShaderProgram.");

    // Get vertex/fragment shader src file path.
    const char* vertexShaderSrcFile = getShaderSrcFileName(GL_VERTEX_SHADER, type);
    const char* fragmentShaderSrcFile = getShaderSrcFileName(GL_FRAGMENT_SHADER, type);

    if (vertexShaderSrcFile == NULL || fragmentShaderSrcFile == NULL) {
        LOGE("Unexpected ShaderType.");
        return INVALID_PROGRAM;
    }

    // Vertex.
    // Open assets.
    AAsset* vertexSrcAsset = AAssetManager_open(
                                 assetManager,
                                 vertexShaderSrcFile,
                                 AASSET_MODE_RANDOM);
    GLsizei vertSrcLen = AAsset_getLength(vertexSrcAsset);
    // Src codes.
    GLchar vertSrc[vertSrcLen + 1];
    // Read.
    AAsset_seek(vertexSrcAsset, 0, 0);
    AAsset_read(vertexSrcAsset, vertSrc, vertSrcLen);
    vertSrc[vertSrcLen] = NULL; // Terminal.
    // Close assets.
    AAsset_close(vertexSrcAsset);

    // Fragment.
    // Open assets.
    AAsset* fragmentSrcAsset = AAssetManager_open(
                                   assetManager,
                                   fragmentShaderSrcFile,
                                   AASSET_MODE_RANDOM);
    GLsizei fragSrcLen = AAsset_getLength(fragmentSrcAsset);
    // Src codes.
    GLchar fragSrc[fragSrcLen + 1];
    // Read.
    AAsset_seek(fragmentSrcAsset, 0, 0);
    AAsset_read(fragmentSrcAsset, fragSrc, fragSrcLen);
    fragSrc[fragSrcLen] = NULL; // Terminal.
    // Close assets.
    AAsset_close(fragmentSrcAsset);

    // Create program.
    mShaderPrograms[type] = createProgram(vertSrc, vertSrcLen + 1, fragSrc, fragSrcLen + 1);

    return mShaderPrograms[type];
}
开发者ID:talalbutt,项目名称:3-layered-hybrid-app-template,代码行数:57,代码来源:ShaderProgramFactory.cpp


示例3: AndroidGetAssetBytes

ByteArray AndroidGetAssetBytes(const char *inResource)
{
   AAsset *asset = AndroidGetAsset(inResource);
   
   if (asset)
   {
      long size = AAsset_getLength(asset);
      ByteArray result(size);
      AAsset_read(asset, result.Bytes(), size);
      AAsset_close(asset);
      return result;
   }
   
   return 0;
   
   /*JNIEnv *env = GetEnv();
   
   jclass cls = FindClass("org/haxe/nme/GameActivity");
   jmethodID mid = env->GetStaticMethodID(cls, "getResource", "(Ljava/lang/String;)[B");
   if (mid == 0)
      return 0;
   
   jstring str = env->NewStringUTF( inResource );
   jbyteArray bytes = (jbyteArray)env->CallStaticObjectMethod(cls, mid, str);
   env->DeleteLocalRef(str);
   if (bytes==0)
   {
      return 0;
   }
   
   jint len = env->GetArrayLength(bytes);
   ByteArray result(len);
   env->GetByteArrayRegion(bytes, (jint)0, (jint)len, (jbyte*)result.Bytes());
   return result;*/
}
开发者ID:madrazo,项目名称:openfl-native-p8,代码行数:35,代码来源:AndroidFrame.cpp


示例4: assert

shared_ptr<Scene> Scene::loadColladaFromAsset(
    shared_ptr<EngineContext> engineContext,
    const string &assetFile) {
    AAssetManager *assetManager = engineContext->getAssetManager();
    assert(assetManager != NULL);

    AAsset* asset = AAssetManager_open(assetManager,
        assetFile.c_str(), AASSET_MODE_BUFFER);

    if (!asset) {
        ALOGE("Failed to open asset: %s", assetFile.c_str());
        return nullptr;
    }

    off_t length = AAsset_getLength(asset);
    unique_ptr<char[]> buffer(new char[length]);
    size_t sz = AAsset_read(asset, buffer.get(), length);
    AAsset_close(asset);
    if (sz != length) {
        ALOGE("Partial read %d bytes", sz);
        return nullptr;
    }

    return loadColladaFromMemory(buffer.get(), length, assetFile);
}
开发者ID:jiayu1016,项目名称:dizzy,代码行数:25,代码来源:scene.cpp


示例5: test_assets

    void test_assets() {
        AAsset* a = AAssetManager_open( g_asset_mgr, "raw/test.jpg", AASSET_MODE_RANDOM );
        assert( a != 0 );
        
        off_t len = AAsset_getLength(a);
        
        const char *buf = (const char *)AAsset_getBuffer(a);
        LOGI( "asset: %p %d\n", a, len );
        
        for( size_t i = 0; i < len; ++i ) {
            LOGI( "x: %c\n", buf[i] );
        }
//         AAssetDir *dir = AAssetManager_openDir(g_asset_mgr, "assets" );
//         
//         while( true ) {
//             const char *name = AAssetDir_getNextFileName(dir);
//             
//             if( name == 0 ) {
//                 break;
//             }
//             
//             LOGI( "asset: %s\n", name );
//         }


    }
开发者ID:sim82,项目名称:native_gl2,代码行数:26,代码来源:gl_code.cpp


示例6: Java_org_gearvrf_NativeImporter_readFileFromAssets

JNIEXPORT jlong JNICALL
Java_org_gearvrf_NativeImporter_readFileFromAssets(JNIEnv * env,
        jobject obj, jobject asset_manager, jstring filename) {
    const char* native_string = env->GetStringUTFChars(filename, 0);
    AAssetManager* mgr = AAssetManager_fromJava(env, asset_manager);
    AAsset* asset = AAssetManager_open(mgr, native_string, AASSET_MODE_UNKNOWN);
    if (NULL == asset) {
        LOGE("_ASSET_NOT_FOUND_");
        return JNI_FALSE;
    }
    long size = AAsset_getLength(asset);
    char* buffer = (char*) malloc(sizeof(char) * size);
    AAsset_read(asset, buffer, size);

    AssimpImporter* assimp_scene = Importer::readFileFromAssets(
            buffer, size);

    AAsset_close(asset);

    free(buffer);

    env->ReleaseStringUTFChars(filename, native_string);

    return reinterpret_cast<jlong>(assimp_scene);
}
开发者ID:Bonch90,项目名称:GearVRf,代码行数:25,代码来源:importer_jni.cpp


示例7: ReadFile

// Read the contents of the give file return the content and the file size.
// The calling function is responsible for free the memory allocated for Content.
void ReadFile( const char* pFileName, char** ppContent, unsigned int* pSize )
{  
    assert( g_pManager );
    
    // Open files
    AAsset* pFile = AAssetManager_open( g_pManager, pFileName, AASSET_MODE_UNKNOWN );

    if( pFile != NULL )
    {
        // Determine file size
        off_t fileSize = AAsset_getLength( pFile );
        // Read data
        char* pData = new char[fileSize];
        AAsset_read( pFile, pData, fileSize );
    
        // Allocate space for the file content
        *ppContent = new char[fileSize];
    
        // Copy the content
        memcpy( *ppContent, pData, fileSize );
        *pSize = fileSize;

        Log("File length %d",*pSize);
        delete pData;
        
        // Close the file
        AAsset_close( pFile );
    }
}
开发者ID:nazgee,项目名称:OpenGlExamples,代码行数:31,代码来源:file.cpp


示例8: SOIL_load_OGL_texture

void Renderer::LoadTexture(const string* filePath, TextureID* id)
{
#ifdef PLATFORM_WINDOWS

	string nPath = Renderer::GetInstance()->ASSET_PATH + *filePath;

	id->name = *filePath;
	id->id = SOIL_load_OGL_texture(nPath.c_str(), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID,
			SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB);

#else

	AAssetManager* mgr = System::GetInstance()->GetEngineData()->app->activity->assetManager;
	AAsset* textureAsset = AAssetManager_open(mgr, filePath->c_str(), AASSET_MODE_UNKNOWN);
	unsigned int length = AAsset_getLength(textureAsset);

	unsigned char * bitmap = new unsigned char[length];
	AAsset_read(textureAsset, (void*)bitmap, length);

	id->name = *filePath;
	id->id = SOIL_load_OGL_texture_from_memory(bitmap, length, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID,
		SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB);

	++length;

#endif

}
开发者ID:ACPLMaverick,项目名称:MAVNET,代码行数:28,代码来源:Renderer.cpp


示例9: strcpy

void OSLOgg::load(char* filename) {

	strcpy(this->filename, filename);
//	LOGD("filename = %s, this->filename = %s",filename, this->filename);

	// if set Player Buffer, than load audio data to PCM buffer
	if(playerType == BUFFER){
		AAsset* f = openFile(filename);
		if (!f) {
				LOGE("no file %s",filename);
				throw "no file %s";
		}
		buf = 0;
		off_t length = AAsset_getLength(f);
		buf = (char*) malloc(length);
		if (buf) {
			if (AAsset_read(f,buf, length)) {

			} else {
				free(buf);
				AAsset_close(f);

				LOGE("smthng wrong with %s",filename);
				throw "smthng wrong while reading file";
	//			return;
			}
		}

//		LOGD("length = %d", length);
		this->buf =  (char *) ConvertOggToPCM(length, buf);
		if(f)
			AAsset_close(f);
	}
}
开发者ID:Suvitruf,项目名称:Android-ndk,代码行数:34,代码来源:OSLOgg.cpp


示例10: openFile

char* OSLSound::readWAVFull(AAssetManager *mgr, BasicWAVEHeader* header) {
    char* buffer = 0;
    AAsset * file = openFile(filename);
    if (!file) {
        LOGE("no file %s in readWAV",filename);
        return 0;
    }

    char extra[2];
    int res = AAsset_read (file,header,sizeof(BasicWAVEHeader));
    if(!strstr(header->data, "data")) {

        AAsset_read (file,extra,2);
        header->dataSize = AAsset_getLength(file) - sizeof(BasicWAVEHeader)-2;
    }
    if(res) {
        buffer = (char*)malloc(header->dataSize);
        if (buffer) {
            res = AAsset_read (file,buffer,header->dataSize);
            if(res) {
                AAsset_close(file);
                return buffer;
            }
            free(buffer);
        }
    }
    AAsset_close(file);
    return 0;
}
开发者ID:cibergod,项目名称:Pac-man-for-android-NDK,代码行数:29,代码来源:OSLSound.cpp


示例11: files

	FileInfoListPtr APKFileSystemArchive::findFileInfo(const String& pattern, bool recursive, bool dirs)
	{
		FileInfoListPtr files(new FileInfoList);
		std::map<String, std::vector< String > >::iterator iter = mFiles.find( mName );
		std::vector< String > fileList = iter->second;
		for( size_t i = 0; i < fileList.size(); i++ ) 
		{
			if(StringUtil::match(fileList[i], pattern)) 
			{
				AAsset* asset = AAssetManager_open(mAssetMgr, (mPathPreFix + fileList[i]).c_str(), AASSET_MODE_UNKNOWN);
				if(asset) {
					FileInfo info;
					info.archive = this;
					info.filename = fileList[i];
					info.path = mName;
					info.basename = fileList[i];
					info.compressedSize = AAsset_getLength(asset);
					info.uncompressedSize = info.compressedSize;
					files->push_back(info);
					AAsset_close(asset);
				}
			}
		}
		return files;
	}
开发者ID:Gerviba,项目名称:MuOnline,代码行数:25,代码来源:OgreAPKFileSystemArchive.cpp


示例12: asset

AssetFileCache::AssetFileCache ( AAsset* asset ) : asset ( asset )
{
    fileSize = AAsset_getLength ( asset );

    pageSize = 1024 * 1024;
    nbrPageData = 8;

    pos = 0;

    uint32_t totalPages = fileSize / pageSize;
    if ( fileSize % pageSize != 0 )
    {
        totalPages++;
    }

    this->totalPages = totalPages;

    if ( totalPages < nbrPageData )
    {
        nbrPageData = totalPages;
    }

    for ( int32_t n = 0; n < totalPages; n++ )
    {
        pages.push_back ( new Page() );
    }

    for ( int32_t n = 0; n < nbrPageData; n++ )
    {
        pageData.push_back ( new PageData ( pageSize ) );
    }

    LOGI ( "Created, asset = %p, fileSize = %d, totalPages = %d, nbrPageData = %d", asset, fileSize, totalPages, nbrPageData );
}
开发者ID:emileb,项目名称:MobileTouchControls,代码行数:34,代码来源:AssetFileCache.cpp


示例13: ReadAPKFile

	int ReadAPKFile(void ** data, const char * filename)
	{
		assert (gAssetManager != NULL);

		AAsset * pAsset = AAssetManager_open(gAssetManager, filename, AASSET_MODE_UNKNOWN);
		if (pAsset == NULL)
			return -1;

		size_t size = AAsset_getLength(pAsset);
		if (size > 0 && data != NULL)
		{
			unsigned char * pd = new unsigned char[size];
			int read_count = AAsset_read(pAsset, pd, size);
			if(read_count <= 0)
			{
				n_log("?: Read APK File '%s'.", filename);

				delete[] pd;
				pd = NULL;
				size = 0;
			}

			*data = pd;
		}

		AAsset_close(pAsset);
		
		return size;
	}
开发者ID:MSoft1115,项目名称:Rad3D,代码行数:29,代码来源:NDK_Utils.cpp


示例14: GetAsset

void GetAsset(char* path, GLchar *text, GLuint *length)
{
	AAsset* asset = AAssetManager_open(Manager, path, AASSET_MODE_STREAMING);
	*length = AAsset_getLength(asset);
	AAsset_read(asset, text, length);
	AAsset_close(asset);
}
开发者ID:jmoak3,项目名称:ImageViewer5000,代码行数:7,代码来源:Assets.c


示例15: androidRead

void androidRead(const char* pFileName, char** ppContent, unsigned int* pSize) {
	assert( gActivity->assetManager );

	AAsset* pFile = AAssetManager_open(gActivity->assetManager, pFileName,
	                                   AASSET_MODE_STREAMING);

	if (pFile != NULL) {

		off_t fileSize = AAsset_getLength(pFile);

		std::string path = androidGetPath(pFileName);
		char* pData = new char[fileSize];
		AAsset_read(pFile, pData, fileSize);

		*ppContent = new char[fileSize];

		memcpy(*ppContent, pData, fileSize);
		*pSize = fileSize;

		FLOG_DEBUG("File %s length %d", pFileName, *pSize);
		delete pData;

		AAsset_close(pFile);
	}
}
开发者ID:filipwasil,项目名称:fillwave,代码行数:25,代码来源:AndroidLoader.cpp


示例16: LOGD

const char* AndroidPlatformAdapter::loadAsset(const char* filename,
		size_t* size) {
	LOGD("loadAsset %s", filename);

	AAsset* asset = AAssetManager_open(m_AssetManager, filename, AASSET_MODE_UNKNOWN);
	if (NULL == asset) {
		LOGE("_ASSET_NOT_FOUND_ %s", filename);
		return 0;
	}
	size_t filesize = AAsset_getLength(asset);
	char* data;
	if(size) {
		*size = filesize;
		data = new char[filesize];
	} else {
		data = new char[filesize + 1];
	}

	AAsset_read (asset,data,filesize);
	AAsset_close(asset);

	if(!size) {
		data[filesize] = 0;
	}

	return data;
}
开发者ID:EthrosDemon,项目名称:p3d,代码行数:27,代码来源:AndroidPlatformAdapter.cpp


示例17: void

void LoaderAndroid::loadAsset(const char* filename, std::stringstream& stream) {

	//auto del = AAsset_close();
	std::unique_ptr<AAsset, void (*)(AAsset*)> asset(AAssetManager_open(assetManager, filename, AASSET_MODE_BUFFER), AAsset_close);
	//std::unique_ptr<AAsset> asset(AAssetManager_open(assetManager, filename, AASSET_MODE_BUFFER));
	//asset.get_deleter()

	//AAsset* asset = AAssetManager_open(assetManager, filename, AASSET_MODE_BUFFER);

	if(asset){
		//std::string content;
		//content.resize(AAsset_getLength( asset ));
		std::vector<char> buffer;
		buffer.resize(AAsset_getLength( asset.get() ));
		//AAsset_read(asset, (void *)content.data(), content.size()); // ToDo: ugly hack
		AAsset_read( asset.get(), (void *)buffer.data(), buffer.size());
		//stream << content;
		stream.write(buffer.data(), buffer.size());
	} else{
		LOG(WARNING) << "Asset %s not found";
	}

	// ToDo: I want to return a stringstream object, but gnu_std doesn't support move constructor for stringstreams



}
开发者ID:SOTR,项目名称:OpenGLTest,代码行数:27,代码来源:loaderandroid.cpp


示例18: getFullFilePath

veFileData* veFileAndroid::readFileToBuffer(const std::string &filePath) {
    if (!veFileAndroid::ASSET_MANAGER)
        return nullptr;
    std::string fullPath = getFullFilePath(filePath);
    if (!isFileExist(fullPath))
        return nullptr;
    auto fileIter = _fileDataCache.find(fullPath);
    if (fileIter != _fileDataCache.end())
        return fileIter->second;

    const char* str = fullPath.c_str() + strlen("assets/");
    AAsset* asset = AAssetManager_open(veFileAndroid::ASSET_MANAGER, str, AASSET_MODE_UNKNOWN);
    if (asset) {
        off_t fileSize = AAsset_getLength(asset);
        char *buffer = new char[fileSize + 1];
        buffer[fileSize] = '\0';
        int bytesread = AAsset_read(asset, (void*)buffer, fileSize);
        auto fileData = new veFileData();
        fileData->buffer = buffer;
        fileData->size = fileSize + 1;
        //veLog("filebuffer: %s, size: %d", buffer, fileSize);
        _fileDataCache[fullPath] = fileData;
        AAsset_close(asset);
        return fileData;
    }
    return nullptr;
}
开发者ID:songchengjiang,项目名称:VoidEngine,代码行数:27,代码来源:File-android.cpp


示例19: loadShader

	// Android shaders are stored as assets in the apk
	// So they need to be loaded via the asset manager
	VkShaderModule loadShader(AAssetManager* assetManager, const char *fileName, VkDevice device, VkShaderStageFlagBits stage)
	{
		// Load shader from compressed asset
		AAsset* asset = AAssetManager_open(assetManager, fileName, AASSET_MODE_STREAMING);
		assert(asset);
		size_t size = AAsset_getLength(asset);
		assert(size > 0);

		char *shaderCode = new char[size];
		AAsset_read(asset, shaderCode, size);
		AAsset_close(asset);

		VkShaderModule shaderModule;
		VkShaderModuleCreateInfo moduleCreateInfo;
		moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
		moduleCreateInfo.pNext = NULL;
		moduleCreateInfo.codeSize = size;
		moduleCreateInfo.pCode = (uint32_t*)shaderCode;
		moduleCreateInfo.flags = 0;

		VK_CHECK_RESULT(vkCreateShaderModule(device, &moduleCreateInfo, NULL, &shaderModule));

		delete[] shaderCode;

		return shaderModule;
	}
开发者ID:SaschaWillems,项目名称:VulkanSponza,代码行数:28,代码来源:vulkantools.cpp


示例20: files

	FileInfoListPtr APKFileSystemArchive::listFileInfo(bool recursive, bool dirs)
	{
		FileInfoListPtr files(new FileInfoList);

		AAssetDir* dir = AAssetManager_openDir(mAssetMgr, mName.c_str());
		const char* fileName = NULL;
		while((fileName = AAssetDir_getNextFileName(dir)) != NULL)
		{
			AAsset* asset = AAssetManager_open(mAssetMgr, (mPathPreFix + String(fileName)).c_str(), AASSET_MODE_UNKNOWN);
			if(asset)
			{
				FileInfo info;
				info.archive = this;
				info.filename = fileName;
				info.path = mName;
				info.basename = fileName;
				info.compressedSize = AAsset_getLength(asset);
				info.uncompressedSize = info.compressedSize;
				files->push_back(info);

				AAsset_close(asset);
			}

		}
		AAssetDir_close(dir);

		return files;
	}
开发者ID:dorgonman,项目名称:cocos2d-x-ogre,代码行数:28,代码来源:OgreAPKFileSystemArchive.cpp



注:本文中的AAsset_getLength函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。