當前位置: 首頁>>代碼示例>>C++>>正文


C++ AAsset_getLength函數代碼示例

本文整理匯總了C++中AAsset_getLength函數的典型用法代碼示例。如果您正苦於以下問題:C++ AAsset_getLength函數的具體用法?C++ AAsset_getLength怎麽用?C++ AAsset_getLength使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了AAsset_getLength函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的AAsset_getLength函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。