Exemple #1
0
/***********************************************************************************
 Function Name      : CreateSharedState
 Inputs             : gc, psShareContext
 Outputs            : -
 Returns            : Success
 Description        : Initialises the data shared between contexts.
************************************************************************************/
static IMG_BOOL CreateSharedState(GLES2Context *gc, GLES2Context *psShareContext)
{
	GLES2ContextSharedState *psSharedState;
	GLES2NameType aeNameType[GLES2_MAX_SHAREABLE_NAMETYPE] =
	{
		GLES2_NAMETYPE_TEXOBJ, 
		GLES2_NAMETYPE_PROGRAM, 
		GLES2_NAMETYPE_BUFOBJ,
		GLES2_NAMETYPE_RENDERBUFFER, 
		GLES2_NAMETYPE_FRAMEBUFFER
	};
	IMG_UINT32 i;

	/*
	 * Init shared structures unless we're sharing them
	 * with another context, in which they are already initialized.
	 */
	if(!gc->psSharedState) 
	{
		if(psShareContext)
		{
			/* Get the shared state from the other context */
			GLES_ASSERT(psShareContext->psSharedState);

			/* *** START CRITICAL SECTION *** */
			PVRSRVLockMutex(psShareContext->psSharedState->hPrimaryLock);

			gc->psSharedState = psShareContext->psSharedState;
			gc->psSharedState->ui32RefCount++;

			PVRSRVUnlockMutex(psShareContext->psSharedState->hPrimaryLock);
			/* *** END CRITICAL SECTION *** */
		}
		else
		{
			PVRSRV_ERROR eError;

			/* Create shared state */
			psSharedState = GLES2Calloc(gc, sizeof(GLES2ContextSharedState));

			if(!psSharedState)
			{
				return IMG_FALSE;
			}

			gc->psSharedState = psSharedState;

			psSharedState->ui32RefCount = 1;

			eError = PVRSRVCreateMutex(&psSharedState->hPrimaryLock);

			if (eError != PVRSRV_OK)
			{
				PVR_DPF((PVR_DBG_ERROR,"CreateSharedState: PVRSRVCreateMutex failed on hPrimaryLock (%d)", eError));

				GLES2Free(gc, psSharedState);

				return IMG_FALSE;
			}

			eError = PVRSRVCreateMutex(&psSharedState->hSecondaryLock);

			if (eError != PVRSRV_OK)
			{
				PVR_DPF((PVR_DBG_ERROR,"CreateSharedState: PVRSRVCreateMutex failed on hSecondaryLock (%d)", eError));

				eError = PVRSRVDestroyMutex(psSharedState->hPrimaryLock);

				if (eError != PVRSRV_OK)
				{
					PVR_DPF((PVR_DBG_ERROR, "CreateSharedState: PVRSRVDestroyMutex failed on hPrimaryLock (%d)", eError));
				}

				GLES2Free(gc, psSharedState);

				return IMG_FALSE;
			}

			eError = PVRSRVCreateMutex(&psSharedState->hTertiaryLock);

			if (eError != PVRSRV_OK)
			{
				PVR_DPF((PVR_DBG_ERROR,"CreateSharedState: PVRSRVCreateMutex failed on hTertiaryLock (%d)", eError));

				eError = PVRSRVDestroyMutex(psSharedState->hSecondaryLock);

				if (eError != PVRSRV_OK)
				{
					PVR_DPF((PVR_DBG_ERROR, "CreateSharedState: PVRSRVDestroyMutex failed on hSecondaryLock (%d)", eError));
				}

				eError = PVRSRVDestroyMutex(psSharedState->hPrimaryLock);

				if (eError != PVRSRV_OK)
				{
					PVR_DPF((PVR_DBG_ERROR, "CreateSharedState: PVRSRVDestroyMutex failed on hPrimaryLock (%d)", eError));
				}

				GLES2Free(gc, psSharedState);

				return IMG_FALSE;
			}

			eError = PVRSRVCreateMutex(&psSharedState->hFlushListLock);

			if (eError != PVRSRV_OK)
			{
				PVR_DPF((PVR_DBG_ERROR,"CreateSharedState: PVRSRVCreateMutex failed on hFlushListLock (%d)", eError));

				eError = PVRSRVDestroyMutex(psSharedState->hTertiaryLock);

				if (eError != PVRSRV_OK)
				{
					PVR_DPF((PVR_DBG_ERROR, "CreateSharedState: PVRSRVDestroyMutex failed on hTertiaryLock (%d)", eError));
				}

				eError = PVRSRVDestroyMutex(psSharedState->hSecondaryLock);

				if (eError != PVRSRV_OK)
				{
					PVR_DPF((PVR_DBG_ERROR, "CreateSharedState: PVRSRVDestroyMutex failed on hSecondaryLock (%d)", eError));
				}

				eError = PVRSRVDestroyMutex(psSharedState->hPrimaryLock);

				if (eError != PVRSRV_OK)
				{
					PVR_DPF((PVR_DBG_ERROR, "CreateSharedState: PVRSRVDestroyMutex failed on hPrimaryLock (%d)", eError));
				}

				GLES2Free(gc, psSharedState);

				return IMG_FALSE;
			}


			/* Initialize the texture manager.
			 * Make sure that gc->psSharedState points to the right place before calling this
			 */
			psSharedState->psTextureManager = CreateTextureManager(gc);

			if(!psSharedState->psTextureManager)
			{
				PVR_DPF((PVR_DBG_ERROR,"CreateSharedState: Couldn't initialise the texture manager"));

				FreeContextSharedState(gc);

				return IMG_FALSE;
			}

			/* Initialize the USSE code variant manager */
			if(!KRM_Initialize(&psSharedState->sUSEShaderVariantKRM, 
							    KRM_TYPE_3D,
							    IMG_TRUE,
							    psSharedState->hSecondaryLock, 
							    gc->ps3DDevData,
							    gc->psSysContext->sHWInfo.sMiscInfo.hOSGlobalEvent,
							    ReclaimUSEShaderVariantMemKRM, 
							    IMG_TRUE, 
							    DestroyUSECodeVariantGhostKRM))
			{
				PVR_DPF((PVR_DBG_ERROR,"CreateSharedState: Couldn't initialise the USSE code variant manager"));

				FreeContextSharedState(gc);

				return IMG_FALSE;
			}

			/* Initialize the TA kick buffer object manager */
			if(!KRM_Initialize(&psSharedState->sBufferObjectKRM,
								KRM_TYPE_TA, 
							    IMG_TRUE,
								psSharedState->hSecondaryLock, 
								gc->ps3DDevData,
								gc->psSysContext->sHWInfo.sMiscInfo.hOSGlobalEvent,
								ReclaimBufferObjectMemKRM, 
								IMG_TRUE, 
								DestroyBufferObjectGhostKRM))
			{
				PVR_DPF((PVR_DBG_ERROR,"CreateSharedState: Couldn't initialise the TA kick buffer object manager"));

				FreeContextSharedState(gc);

				return IMG_FALSE;
			}

			/* Initialize the code memory heaps */
			psSharedState->psUSEVertexCodeHeap = UCH_CodeHeapCreate(gc->ps3DDevData, 
																	UCH_USE_CODE_HEAP_TYPE, 
																	gc->psSysContext->hUSEVertexHeap,
																	psSharedState->hSecondaryLock);

			if(!psSharedState->psUSEVertexCodeHeap)
			{
				PVR_DPF((PVR_DBG_ERROR, "CreateSharedState: Failed to create USSE vertex code heap!\n"));

				FreeContextSharedState(gc);

				return IMG_FALSE;
			}

			psSharedState->psUSEFragmentCodeHeap = UCH_CodeHeapCreate(gc->ps3DDevData, 
																		UCH_USE_CODE_HEAP_TYPE, 
																		gc->psSysContext->hUSEFragmentHeap,
																		psSharedState->hSecondaryLock);

			if(!psSharedState->psUSEFragmentCodeHeap)
			{
				PVR_DPF((PVR_DBG_ERROR, "CreateSharedState: Failed to create USSE fragment code heap!\n"));

				FreeContextSharedState(gc);

				return IMG_FALSE;
			}

			psSharedState->psPDSFragmentCodeHeap = UCH_CodeHeapCreate(gc->ps3DDevData, 
																		UCH_PDS_CODE_HEAP_TYPE, 
																		gc->psSysContext->hPDSFragmentHeap,
																		psSharedState->hSecondaryLock);

			if(!psSharedState->psPDSFragmentCodeHeap)
			{
				PVR_DPF((PVR_DBG_ERROR, "CreateSharedState: Failed to create PDS fragment code heap!\n"));

				FreeContextSharedState(gc);

				return IMG_FALSE;
			}

			/* Initialize the shareable names arrays */
			for(i = 0; i < GLES2_MAX_SHAREABLE_NAMETYPE; ++i)
			{
				psSharedState->apsNamesArray[i] = CreateNamesArray(gc, aeNameType[i], psSharedState->hPrimaryLock);

				if(!psSharedState->apsNamesArray[i])
				{
					PVR_DPF((PVR_DBG_ERROR,"CreateSharedState: Couldn't create names array %d", i));

					FreeContextSharedState(gc);

					return IMG_FALSE;
				}
			}
		}
	}

	GLES_ASSERT(gc->psSharedState);

	return IMG_TRUE;
}
void RenderTest1()
{

	RenderParticleTest();

	/*
	SharedPtr<File> file = CreateFile();
	file->open( String("D:\\test.txt"), FILE_MODE_READ, FILE_TEXT);
	char buffer[1024];
	size_t size = file->read( 5, &buffer[0] );
	file->close();	
	*/

	SharedPtr<Foo111> foo = new Foo111;
	SharedPtr<Asset> asset;


	//asset->addListe
	asset = new TextureAsset("Content/tree_foliage.dds");
	asset->load();
	asset = new TextureAsset("Content/lizard_diff.dds");
	asset->load();
	//asset = new TextureAsset("Content/lizard_norm.dds");
	asset = new TextureAsset("Content/TerrainDiffuseArray.dds");
	asset->load();
	asset = new TextureAsset("Content/TerrainNormalArray.dds");

	//asset = new TextureAsset("Content/Terrain.dds");
	//asset = new TextureAsset("Content/Wood.dds");

	asset->addListener(foo);

	asset->load();

	asset->removeListener(foo);


	AssetName a1("DisciplesIII");
	SharedPtr<Skeleton> skeleton = CreateTestSkeleton();

	unsigned numBones = skeleton->getNumBones();

	TextureInfo info;
	gTextureManager = CreateTextureManager();
	SharedPtr<Texture> texture1 = gTextureManager->createTexture(info);
	SharedPtr<Texture> texture2 = gTextureManager->createTexture(AssetName("textures/fire.dds"));

	MaterialInfo materialInfo;
	SharedPtr<Material> material = GetMaterialManager()->createMaterial(materialInfo);

	material->setTexture(texture1, MATERIAL_TEXTURE_DEFFUSE);


	texture1 = NULL;
	texture2 = NULL;

	

	

	SharedPtr<Geometry> geometry = new Geometry;
	geometry->addItem(GeometryItem(3,0));
	geometry->addItem(GeometryItem(3,3));
	geometry->addItem(GeometryItem(3,6));

	geometry->addItem(GeometryItem(0,6,3,4,5));

	//geometry->set



	


	

	size_t s = sizeof(RenderProfile);
	Map map;
	for (int i = 0; i < 10000000; i++) {
		RenderProfile rf;
		rf.field = rand();
		rf.surface.skinning = 2;
		rf.postProcess.msaa = 4;
		rf.postProcess.dof = 2;
		//map.insert(Map::value_type(rf, NULL));
	}

	printf("Passed...\n");

	SharedPtr<Logger> logger = CreateLogger();
	logger->start("MyLog.log");
	logger->error("Render", "Hello!");	

	ShaderDefines  shaderDefines;
	shaderDefines.addDefine("USE_EMISSION_MAP");
	shaderDefines.addDefine("USE_DIFFUSE_MAP");
	shaderDefines.addDefine("USE_SPECULAR_MAP");
	shaderDefines.addDefine("USE_NORMAL_MAP");
	shaderDefines.addDefine("USE_DETAIL_MAP");
	shaderDefines.addDefine("USE_FOG");
	shaderDefines.addDefine("USE_3DC");
	shaderDefines.addDefine("NUM_SAMPLES",8);
	  
	String string = shaderDefines.getString();
	String defines = shaderDefines.getDefines();

	logger->info("Render", string);
	logger->info("Render", defines);

	logger->stop();




	SharedPtr<MemoryBuffer> mb = CreateMemoryBuffer(0xFFFF0000);
	if( mb ) {
			int* intPtr = (int*)mb->lock();
			intPtr[0] = 0xFFFF;
			intPtr[0] = 0xDEAD;
			mb->unlock();
	}
	mb=NULL;
	
	ResourceName texture3( "textures/particles/fire.dds");
	
	
	SharedPtr<RenderScene> rs = CreateRenderScene();
	SharedPtr<LightRenderSceneObject> sunLight = new LightRenderSceneObject;
	SharedPtr<ParticleSystemRenderSceneObject> particleSystemRenderSceneObject = new ParticleSystemRenderSceneObject;
	SharedPtr<TerrainRenderSceneObject> ts = new TerrainRenderSceneObject;
	SharedPtr<TextRenderSceneObject> textSceneObject = new TextRenderSceneObject;
	SharedPtr<MeshRenderSceneObject> meshSceneObject = new MeshRenderSceneObject;
	
	SharedPtr<LightRenderSceneObject> omniLights1 = new LightRenderSceneObject;
	SharedPtr<LightRenderSceneObject> omniLights2 = new LightRenderSceneObject;
	SharedPtr<LightRenderSceneObject> omniLights3 = new LightRenderSceneObject;


	//rs->
	SharedPtr<ParticleSystemManager> particleSystemManager = CreateParticleSystemManager();
	SharedPtr<ParticleSystem> particleSystem1 = particleSystemManager->createParticleSystem();
	SharedPtr<ParticleSystem> particleSystem2 = particleSystemManager->createParticleSystem();

	particleSystem1->addStream( new ParticleStream );
	particleSystem1->addStream( new ParticleStream );
		
	particleSystemRenderSceneObject->setParticleSystem(particleSystem1);

	particleSystem1 = NULL;
	particleSystem2 = NULL;


	rs->addLight(sunLight);

	LightInfo omniLightInfo;
	omniLightInfo.type = LIGHT_OMNI;
	omniLights1->setInfo(omniLightInfo);
	omniLights2->setInfo(omniLightInfo);
	omniLights3->setInfo(omniLightInfo);

	omniLights1->setColor(Color::RED, LIGHT_COLOR_DIFFUSE);

	rs->addLight(omniLights1);
	rs->addLight(omniLights2);
	rs->addLight(omniLights3);

	DynamicArray<SharedPtr<LightRenderSceneObject>> lights;
	rs->getLights(lights);


	rs->addMesh(meshSceneObject);
	//rs->addSceneObject(ps);
	//rs->addSceneObject(textSceneObject);

	textSceneObject->setText("Hello,world!");

	particleSystemRenderSceneObject->setTransform(Transform());


	rs->removeMesh(meshSceneObject);



	sunLight->setTransform(Transform());
	//light->


	rs->removeLight(omniLights1);
	rs->removeLight(omniLights2);
	rs->removeLight(omniLights3);

	rs->removeLight(sunLight);
	//rs->removeSceneObject(ps);


	 /*
	HardwareTexture* htexture = NULL;

	SharedPtr<TextureSurface> surface[10];
	for(unsigned mipLevel =0; mipLevel < 10; mipLevel++) {
		htexture->update(mipLevel, surface[mipLevel] );		
	}


	SharedPtr<TextureVolume> volume[10];
	for (unsigned mipLevel = 0; mipLevel < 10; mipLevel++) {
		//htexture->update(mipLevel, surface[mipLevel]);
		htexture->update(mipLevel, volume[mipLevel]);
	}
	*/


}