Пример #1
0
//--------------------------------------------------------------------------
void VeFilePath::FindFileList(const VeChar8* pcDesc,
	VeVector<VeFixedString>& kOut) const noexcept
{
#	ifdef VE_PLATFORM_WIN
	VeChar8 acBuffer[VE_MAX_PATH_LEN];
	PATH_CAT(acBuffer, m_kPath, pcDesc);
	_finddata_t kData;
	VeSizeT stHandle = _findfirst(acBuffer, &kData);
	if (stHandle != VE_ELF)
	{
		do
		{
			if ((kData.attrib & 0xf0) == _A_ARCH)
			{
				kOut.push_back(kData.name);
			}
		} while (VE_SUCCEEDED(_findnext(stHandle, &kData)));
		VE_ASSERT_EQ(_findclose(stHandle), VE_S_OK);
	}
#	else
	const VeChar8* pcFile = VeStrrchr(pcDesc, '/');
	pcFile = pcFile ? (pcFile + 1) : pcDesc;
	DIR* pkDir(nullptr);
	if (pcFile == pcDesc)
	{
		pkDir = opendir(m_kPath.GetLength() ? m_kPath : ".");
	}
	else
	{
		VeChar8 acBuffer[VE_MAX_PATH_LEN];
		VeChar8* pcTemp = acBuffer;
		if (m_kPath.GetLength())
		{
			pcTemp += VeSprintf(acBuffer, "%s/", m_kPath.GetStr());
		}
		VeStrncpy(pcTemp, VE_MAX_PATH_LEN, pcDesc, pcFile - pcDesc - 1);
		pkDir = opendir(acBuffer);
	}
	if (pkDir)
	{
		struct dirent* pkEntry;
		while ((pkEntry = readdir(pkDir)))
		{
			if (pkEntry->d_type != DT_DIR)
			{
				if (VeWildNameMatch(pkEntry->d_name, pcFile))
				{
					kOut.push_back(pkEntry->d_name);
				}

			}
		}
		VE_ASSERT_EQ(closedir(pkDir), VE_S_OK);
	}

#	endif
}
Пример #2
0
//--------------------------------------------------------------------------
void VeAssetPath::FindFileList(const VeChar8* pcDesc,
	VeVector<VeFixedString>& kOut) const noexcept
{
	const VeChar8* pcFile = VeStrrchr(pcDesc, '/');
	pcFile = pcFile ? (pcFile + 1) : pcDesc;
	AAssetDir* pkDir(nullptr);
	if (pcFile == pcDesc)
	{
		pkDir = AAssetManager_openDir(s_pkAssetManager, m_kPath);
	}
	else
	{
		VeChar8 acBuffer[VE_MAX_PATH_LEN];
		VeChar8* pcTemp = acBuffer;
		if (m_kPath.GetLength())
		{
			pcTemp += VeSprintf(acBuffer, "%s/", m_kPath.GetStr());
		}
		VeStrncpy(pcTemp, VE_MAX_PATH_LEN, pcDesc, pcFile - pcDesc - 1);
		pkDir = AAssetManager_openDir(s_pkAssetManager, acBuffer);
	}
	if (pkDir)
	{
		const VeChar8* pcEntry;
		while ((pcEntry = AAssetDir_getNextFileName(pkDir)))
		{
			if (VeWildNameMatch(pcEntry, pcFile))
			{
				kOut.push_back(pcEntry);
			}
		}
		AAssetDir_close(pkDir);
	}
}
Пример #3
0
//--------------------------------------------------------------------------
void VeGraphicsTest::OnTouchCancelled(VeUInt32 u32Time, VeVector<VeInputMessage::TouchPointParam>& kParams)
{
    for(VeVector<VeInputMessage::TouchPointParam>::iterator it = kParams.Begin(); it != kParams.End(); ++it)
    {
        VeDebugOutput("OnTouchCancelled[time:%d,id:%d,x:%.0f,y:%.0f]", u32Time, it->id, it->x, it->y);
    }
}
Пример #4
0
void NativeOnEvent(const VeChar8* pcEvent, const VeVector< VePair<VeStringA,VeStringA> >& kValue)
{
	if(kValue.Empty())
	{
		NativeOnEvent(pcEvent);
		return;
	}
#	ifdef VE_DEBUG
	VeStringA kOutput("NativeOnEvent:");
	kOutput += pcEvent;
	for(VeUInt32 i(0); i < kValue.Size(); ++i)
	{
		const VePair<VeStringA,VeStringA>& kIter = kValue[i];
		kOutput += "(" + kIter.m_tFirst + "," + kIter.m_tSecond + ")";
	}
	VeDebugOutputString(kOutput);
#	endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
	JniMethodInfo t;
	if(JniHelper::getStaticMethodInfo(t,
		"cn/VenusIE/TexasPoker/TexasPokerActivity",
		"jni_OnEventValues",
		"(Ljava/lang/String;[Ljava/lang/String;)V"))
	{
		jstring strEvent = t.env->NewStringUTF(pcEvent);
		VeUInt32 u32Size = kValue.Size();
		jclass strClass = t.env->FindClass("java/lang/String");
		jobjectArray astrValues = t.env->NewObjectArray(u32Size << 1, strClass, 0);
		jstring type,value;
		for(VeUInt32 i(0); i < u32Size; ++i)
		{
			type = t.env->NewStringUTF(kValue[i].m_tFirst);
			value = t.env->NewStringUTF(kValue[i].m_tSecond);
			t.env->SetObjectArrayElement(astrValues, i * 2, type);
			t.env->SetObjectArrayElement(astrValues, i * 2 + 1, value);
		}
		t.env->CallStaticVoidMethod(t.classID, t.methodID, strEvent, astrValues);
		t.env->DeleteLocalRef(t.classID);
		t.env->DeleteLocalRef(astrValues);
	}
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
	CocoaHelper::OnEvent(pcEvent, kValue);
#endif
}
Пример #5
0
//--------------------------------------------------------------------------
void VeGraphicsTest::OnInit()
{
	VeTextTablePtr spTable = VeLoadTextTableSync("text.txt", "Scripts");

	m_spTestSound = VeLoadSimpleSoundSync("stereo.ogg", "Sound");

	VeLoadRenderFrameSync("test_frame.[frm]", "Scripts");
	VeVector<const VeChar8*> kUnitArray;
	kUnitArray.PushBack("test");
	g_pRenderFrameManager->Update("default", kUnitArray);

	VeLoadTextureAtlasSync("test-hd.xml", "Textures");

	//VeTextureResourcePtr spTex = VeLoadTextureSync("logo2.png", "Textures");

	VeSceneNode2DPtr spRoot = g_pSceneManager->GetRootNode2D();
	////spRoot->SetMulColor(1,1,1,0.5f);
	//spRoot->SetAddColor(0.3f, 0.0f, 0.0f);
	//VeSprite2DPtr spSprite = VE_NEW VeSprite2D("expression_1_01.png");
	//spRoot->AttachRenderable(spSprite);
	////spSprite->SetAnchor(0,0);
	////spRoot->SetRotate(VE_MATH_2_PI_F);
	////spRoot->SetScale(2.0f, 2.0f);
	//spRoot->SetPosition(200,200);
	////spSprite->SetColor(1.0f,1.0f,1.0,0.5f);

	////m_spAnimation = VE_NEW VeMorphManual2D(spRoot);

	////VeQuaternion kQuat;
	////kQuat.FromAngleAxis(1.0f, VeVector3D::UNIT_Y);
	////spRoot->SetRotate(1.0f);

	//

	//m_spNode = VE_NEW VeSceneNode2D;
	//spRoot->AttachChild(m_spNode);
	//m_spNode->SetPosition(80, 0);

	//VeSprite2DPtr spSprite2 = VE_NEW VeSprite2D("expression_1_02.png");
	//m_spNode->AttachRenderable(spSprite2);

	//VeSceneNode2DPtr spNode2 = VE_NEW VeSceneNode2D;
	//m_spNode->AttachChild(spNode2);
	//spNode2->SetPosition(80, 0);

	//VeSprite2DPtr spSprite3 = VE_NEW VeSprite2D("expression_1_03.png");
	//spNode2->AttachRenderable(spSprite3);

	//VeBoundingBox2D kBox(VeVector2D(-40,-40), VeVector2D(40,40));
	//VeSquareFramePtr spFrame = VE_NEW VeSquareFrame(kBox);
	//spNode2->AttachRenderable(spFrame);
	//spFrame = VE_NEW VeSquareFrame(kBox);
	//m_spNode->AttachRenderable(spFrame);
	//VeSquarePtr spSquare = VE_NEW VeSquare(kBox);
	//spRoot->AttachRenderable(spSquare);

	//m_spNodeText = VE_NEW VeSceneNode2D;
	//spRoot->AttachChild(m_spNodeText);
	//m_spNodeText->SetPosition(g_pRenderer->GetWidthF() * 0.5f, g_pRenderer->GetHeightF() * 0.5f);
	////pkNodeText->SetScale(2.0f);

	//VeFontPtr spTestFont = VeLoadFontSync("black.kfont", "Fonts");

	

	//m_spNodeText->RunAction(VeRepeatForever::Create(VeSequence::Create(VeScaleTo2D::Create(0.5f, 2.0f, 2.0f, VeTweenEasing::TYPE_QUAD_IN_OUT), VeScaleTo2D::Create(0.5f, 1.0f, 1.0f, VeTweenEasing::TYPE_QUAD_IN_OUT), NULL)));



	//m_spNodeText->SetScale(2.0f);
	//m_spNodeText->SetRotate(1.0f);

	//VeSingleCharPtr spText = VE_NEW VeSingleChar();
	//spText->SetChar(L'H', spTestFont);
	////spText->SetBias(-0.5f);
	//m_spNodeText->AttachRenderable(spText);

	/*VeSingleCharPtr spText2 = VE_NEW VeSingleChar();
	spText2->SetChar(L'b', spTestFont);
	spText2->SetBias(-0.5f);
	m_spNodeText->AttachRenderable(spText2);*/
	//VeSprite2DPtr spSprite5 = VE_NEW VeSprite2D("expression_1_02.png");
	//pkNodeText->AttachRenderable(spSprite5);

	//g_pLua->DoFileSync(VE_DIR("Lua/startup.lua"));

	//VeSizeT aaa = BaseClassBias<TestClass, TestBase1>();

	//VeInt32 a,b,c;
	//g_pLua->CallFunction("Test(ii)iii", 2, 3, &a,&b,&c);
	//g_pLua->CallFunction("Print(s)", "Test");

	//VeLuaCall(a, b, c, "Test", 2, 3);
	//VeLuaCall(a, b, c, "Test2");

	//VeLuaBind::MakeFuncFormat();
	//g_pLua->CallFunction("Print(s)", VeLuaBind::TypeToCName(VeLuaBind::MakeFuncFormat(&Test)));
	/*using namespace VeLuaBind;
	Module() [
		Def("TestCFunc", (VeInt32(*)(VeInt32))&TestCFunc),
			Def("TestCFunc", (VeInt32(*)(VeInt32,VeInt32))&TestCFunc)
	];
	VeLuaCall<void>("TestRun");
	VeInt32 i32Value = VeLuaCall<VeInt32>("TestCFunc", 4);
	VE_LOG_I("luabind debug", "Value %d", i32Value);
	i32Value = VeLuaCall<VeInt32>("TestCFunc", 3, 5);
	VE_LOG_I("luabind debug", "Value %d", i32Value);
	i32Value = VeLuaCall<VeInt32>("TestFunc", 3, 5);
	VE_LOG_I("luabind debug", "Value %d", i32Value);
	VE_ASSERT(g_pLua->GetTop() == 0);*/

	VeDragonBones::SetTexScale(2.0);
	VeLoadTextureAtlasSync("card_001.xml", "Textures");
	VeLoadTextureAtlasSync("card_002.xml", "Textures");
	VeLoadTextureAtlasSync("card_003.xml", "Textures");
	VeLoadTextureAtlasSync("card_Weapons_01.xml", "Textures");
	VeLoadTextureAtlasSync("card_Weapons_02.xml", "Textures");
	VeLoadTextureAtlasSync("eff_01.xml", "Textures");
	VeLoadTextureAtlasSync("eff_02.xml", "Textures");
	VeLoadDragonBonesSync("c04_001.xml", "Animation");
	//VeLoadDragonBonesSync("test.xml", "Animation");
	//VeLoadDragonBonesSync("ui_create_ani_1.xml", "Animation");

	VeDragonBonesEntityPtr spNode = VE_NEW VeDragonBonesEntity("c04_001.xml");

	spNode->SetZOrder(3.0f);
	spNode->SetPosition(g_pRenderer->GetWidthF() * 0.5f, g_pRenderer->GetHeightF() * 0.35f);
	g_pSceneManager->GetRootNode2D()->AttachChild(spNode);
	
	spNode->Play("lv4wait", 0.0f, 0.0f);

	/*VeSimpleTextPtr spText = VE_NEW VeSimpleText(spTestFont);
	spText->SetText("Hello World!");
	spText->SetLine(0, 0);
	spText->SetType(VeSimpleText::CENTER_CENTER, VeColor::WHITE, -0.5f, 0);
	spText->SetShadowType(VeColor(0,0,0,0.5f), 1.0f, VeVector2D(3.0f, 3.0f));
	
	spNode->GetBone("ui_create_title_0")->AttachChild(spText);*/

	

	
	//m_spNodeText->AttachChild(spText);

	//VeSimpleTextPtr spText2 = VE_NEW VeSimpleText(spTestFont);
	//spText2->SetText("Hello World!");
	//spText2->SetType(VeSimpleText::CENTER_CENTER, VeColor::WHITE, -0.5f, 0);
	//spText2->SetShadowType(VeColor(0,0,0,0.5f), 1.0f, VeVector2D(3.0f, 3.0f));
	//spText2->SetPosition(g_pRenderer->GetWidthF() * 0.5f, g_pRenderer->GetHeightF() * 0.5f);
	//m_spNodeText->AttachChild(spText2);

	//spNode->Play("Weapons_r", "01", 0.0f, 0.0f);
	//spNode->Play("Weapons_l", "01", 0.0f, 0.0f);
	//spNode->Play("eff_fly0", "stand", 0.0f, 0.0f);
	//spNode->Play("eff_fire0", "stand", 0.0f, 0.0f);

	//spNode->Play("eff_shield_0", "stand", 0.0f, 0.0f);

	//g_pClientManager->AddClient(VE_NEW VeClientBase("Test"));
	//g_pClientManager->Connect("Test", "127.0.0.1", 62001, "null", true);
}
Пример #6
0
//--------------------------------------------------------------------------
void VeRenderWindowD3D12::SetupCompositorList(const VeChar8** ppcList,
	VeSizeT stNum, VeUInt32 u32ThreadNum, const VeChar8* pcHint) noexcept
{
	VeRendererD3D12& kRenderer = *VeMemberCast(
		&VeRendererD3D12::m_kRenderWindowList, m_kNode.get_list());

	VeVector<VeRenderer::FrameTechnique*> kTechList;
	{		
		for (VeSizeT i(0); i < stNum; ++i)
		{
			auto it = kRenderer.m_kCompositorMap.find(ppcList[i]);
			if (it != kRenderer.m_kCompositorMap.end())
			{
				VeRenderer::FrameTechnique* pkTech = nullptr;
				if (pcHint)
				{
					VeFixedString kHint = pcHint;
					for (auto& tech : it->second->m_kTechniqueList)
					{
						if (tech.m_kName == kHint)
						{
							pkTech = &tech;
							break;
						}
					}
				}
				if (pkTech)
				{
					kTechList.push_back(pkTech);
				}
				else if(it->second->m_kTechniqueList.size())
				{
					kTechList.push_back(&(it->second->m_kTechniqueList.front()));
				}
			}
		}
	}

	{
		m_kResourceMap.clear();
		VeStringMap<VeFloat64> kValueMap;
		kValueMap["screen_w"] = (VeFloat64)GetWidth();
		kValueMap["screen_h"] = (VeFloat64)GetHeight();

		for (auto pTech : kTechList)
		{
			for (auto& res : pTech->m_kResourceList)
			{
				auto it = m_kResourceMap.find(res.m_kName);
				if (it == m_kResourceMap.end())
				{
					VeUInt32 w = (VeUInt32)ve_parser.CalculateExpression(
						kValueMap, res.m_kWidth, 0);
					VeUInt32 h = (VeUInt32)ve_parser.CalculateExpression(
						kValueMap, res.m_kHeight, 0);
					VeUInt16 d = (VeUInt16)ve_parser.CalculateExpression(
						kValueMap, res.m_kDepth, 0);
					VeUInt16 m = (VeUInt16)ve_parser.CalculateExpression(
						kValueMap, res.m_kMipLevels, 0);
					VeUInt16 c = (VeUInt16)ve_parser.CalculateExpression(
						kValueMap, res.m_kCount, 0);
					VeUInt16 q = (VeUInt16)ve_parser.CalculateExpression(
						kValueMap, res.m_kQuality, 0);
					VeUInt32 u32Use(0);
					if (res.m_kSRVList.size()) u32Use |= VeRenderTexture::USEAGE_SRV;
					if (res.m_kRTVList.size()) u32Use |= VeRenderTexture::USEAGE_RTV;
					if (res.m_kDSVList.size()) u32Use |= VeRenderTexture::USEAGE_DSV;

					VeRenderTextureD3D12* pkTexture = VE_NEW VeRenderTextureD3D12(
						res.m_eDimension, (VeRenderTexture::Useage)u32Use,
						res.m_eFormat, w, h, d, m, c, q);
					pkTexture->Init(kRenderer);
					if (res.m_kSRVList.size())
					{
						pkTexture->SetSRVNum((VeUInt32)res.m_kSRVList.size());
						for (VeUInt32 i(0); i < res.m_kSRVList.size(); ++i)
						{
							auto& srv = res.m_kSRVList[i];
							pkTexture->SetSRV(i, srv.m_eType, srv.m_eFormat,
								srv.m_u32Param0, srv.m_u32Param1);
						}
					}
					if (res.m_kRTVList.size())
					{
						pkTexture->SetRTVNum((VeUInt32)res.m_kRTVList.size());
						for (VeUInt32 i(0); i < res.m_kRTVList.size(); ++i)
						{
							auto& rtv = res.m_kRTVList[i];
							pkTexture->SetRTV(i, rtv.m_eType, rtv.m_eFormat,
								rtv.m_u32Param0, rtv.m_u32Param1);
						}
					}
					if (res.m_kDSVList.size())
					{
						pkTexture->SetDSVNum((VeUInt32)res.m_kDSVList.size());
						for (VeUInt32 i(0); i < res.m_kDSVList.size(); ++i)
						{
							auto& dsv = res.m_kDSVList[i];
							pkTexture->SetDSV(i, dsv.m_eType, dsv.m_eFormat,
								dsv.m_u32Param0, dsv.m_u32Param1);
						}
					}
					m_kResourceMap[res.m_kName] = pkTexture;
				}
			}
		}
	}
	
	VeVector<VeStringMap<TargetCache>> kTargets;

	kTargets.resize(kTechList.size());
	for (VeSizeT i(kTechList.size() - 1); i < kTechList.size(); --i)
	{
		VeRenderer::FrameTechnique& kTech = *kTechList[i];
		for (VeSizeT j(0); j < kTech.m_kTargetList.size(); ++j)
		{
			VeRenderer::FrameTarget& kTarget = kTech.m_kTargetList[j];
			RecordRenderTargetPtr spTarget;
			VeVector<ViewData> kRTVList;
			ViewData kDSV;
			if (kTarget.m_eType == VeRenderer::TARGET_OUTPUT)
			{
				if (i == (kTechList.size() - 1))
				{
					spTarget = VE_NEW RecordRenderTarget();
					for (VeSizeT k(0); k < VeRendererD3D12::FRAME_COUNT; ++k)
					{
						spTarget->m_akRTVList[k].push_back(m_akFrameCache[k].m_hHandle);
						spTarget->m_ahDSV[k].ptr = 0;
					}
					kRTVList.resize(kRTVList.size() + 1);
					kRTVList.back().m_u32Width = GetWidth();
					kRTVList.back().m_u32Height = GetHeight();
					kRTVList.back().m_u32Depth = 1;
					kRTVList.back().m_u32SubResource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
				}
				else
				{
					auto it = kTargets[i + 1].find(kTarget.m_kName);
					if (it != kTargets[i + 1].end() && it->second.m_pkConfig->m_eType == VeRenderer::TARGET_INPUT)
					{
						spTarget = it->second.m_spRecorder;
					}
				}
			}
			else
			{
				spTarget = VE_NEW RecordRenderTarget();
				for (auto& rtv : kTarget.m_kRTVList)
				{
					auto it = m_kResourceMap.find(rtv.m_kResName);
					if (it != m_kResourceMap.end())
					{
						if (rtv.m_u32Index < it->second->m_kRTVList.size())
						{
							auto& kView = it->second->m_kRTVList[rtv.m_u32Index];
							for (VeSizeT k(0); k < VeRendererD3D12::FRAME_COUNT; ++k)
							{
								spTarget->m_akRTVList[k].push_back(kView.m_hCPUHandle);
							}
							kRTVList.resize(kRTVList.size() + 1);
							kRTVList.back().m_pkResource = it->second->m_pkResource;
							kRTVList.back().m_u32Width = kView.m_u32Width;
							kRTVList.back().m_u32Height = kView.m_u32Height;
							kRTVList.back().m_u32Depth = kView.m_u32Depth;
							kRTVList.back().m_u32SubResource = kView.m_u32SubResource;
						}
					}
				}
				auto it = m_kResourceMap.find(kTarget.m_kDSV.m_kResName);
				if (it != m_kResourceMap.end())
				{
					if (kTarget.m_kDSV.m_u32Index < it->second->m_kDSVList.size())
					{
						auto& kView = it->second->m_kDSVList[kTarget.m_kDSV.m_u32Index];
						for (VeSizeT k(0); k < VeRendererD3D12::FRAME_COUNT; ++k)
						{
							spTarget->m_ahDSV[k] = kView.m_hCPUHandle;
						}						
						kDSV.m_pkResource = it->second->m_pkResource;
						kDSV.m_u32Width = kView.m_u32Width;
						kDSV.m_u32Height = kView.m_u32Height;
						kDSV.m_u32Depth = kView.m_u32Depth;
						kDSV.m_u32SubResource = kView.m_u32SubResource;
					}
				}
			}

			if (spTarget)
			{
				auto& tar = kTargets[i][kTarget.m_kName];
				VE_ASSERT(!tar.m_pkConfig);
				tar.m_pkConfig = &kTarget;
				tar.m_spRecorder = spTarget;
				tar.m_kRTVList = std::move(kRTVList);
				tar.m_kDSV = kDSV;
			}
		}
	}

	RecordBarrierMap kBarriers;
	kBarriers.resize(kTechList.size());
	
	BarrierPathCache kResPathCache;
	VeMap<ID3D12Resource*, VeMap<VeUInt32, D3D12_RESOURCE_STATES>> kClickCache;

	for (VeSizeT i(0); i < kTechList.size(); ++i)
	{
		auto& kMap = kTargets[i];
		VeRenderer::FrameTechnique& kTech = *kTechList[i];
		kBarriers[i].resize(kTech.m_kClickList.size());
		for (VeSizeT j(0); j < kTech.m_kClickList.size(); ++j)
		{			
			VeRenderer::FrameClick& kClick = kTech.m_kClickList[j];
			auto it = kMap.find(kClick.m_kTarget);
			if (it == kMap.end()) continue;
			auto& tar = it->second;
			kClickCache.clear();
			for (auto rtv : tar.m_kRTVList)
			{
				kClickCache[rtv.m_pkResource][rtv.m_u32SubResource] = D3D12_RESOURCE_STATE_RENDER_TARGET;
			}
			if(tar.m_kDSV.m_pkResource)
			{
				kClickCache[tar.m_kDSV.m_pkResource][tar.m_kDSV.m_u32SubResource] = D3D12_RESOURCE_STATE_DEPTH_WRITE;
			}
			for (auto& con : kClick.m_kContextList)
			{
				auto itRes = m_kResourceMap.find(con);
				if (itRes != m_kResourceMap.end())
				{					
					auto& cache = kClickCache[itRes->second->m_pkResource];
					cache.clear();
					cache[D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES] = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
				}
			}
			for (auto& cache : kClickCache)
			{
				for (auto& state : cache.second)
				{
					BarrierEvent(kBarriers, kResPathCache, i, j,
						cache.first, state.first, state.second);
				}
			}
		}
	}

	VeUInt32 u32GCLIndex(0);
	bool bScene = false;

	m_kRecorderList.resize(1);
	m_kRecorderList.back().m_u32CommandIndex = 0;
	m_kRecorderList.back().m_kTaskList.clear();

	m_kProcessList.resize(1);
	m_kProcessList.back().m_eType = TYPE_EXCUTE;
	m_kProcessList.back().m_u16Start = 0;
	m_kProcessList.back().m_u16Num = 1;

	m_kCameraList.clear();

	RectMap kRectMap;

	RecordRenderTargetPtr spCurrent;
	RecordViewportPtr spViewport;
	RecordScissorRectPtr spScissorRect;
	
	for (VeSizeT i(0); i < kTechList.size(); ++i)
	{
		VeRenderer::FrameTechnique& kTech = *kTechList[i];
		auto& kMap = kTargets[i];
		for (VeSizeT j(0); j < kTech.m_kClickList.size(); ++j)
		{
			VeRenderer::FrameClick& kClick = kTech.m_kClickList[j];
			auto it = kMap.find(kClick.m_kTarget);
			if(it == kMap.end()) continue;
			TargetCache& kCache = it->second;

			auto& bar = kBarriers[i][j];
			if(bar.first)
			{
				if (bScene)
				{
					if (m_kProcessList.back().m_eType == TYPE_EXCUTE)
					{
						m_kProcessList.back().m_u16Num += 1;
					}
					else
					{
						m_kProcessList.resize(m_kProcessList.size() + 1);
						m_kProcessList.back().m_eType = TYPE_EXCUTE;
						m_kProcessList.back().m_u16Start = u32GCLIndex + 1;
						m_kProcessList.back().m_u16Num = 1;
					}
					++u32GCLIndex;
					m_kRecorderList.resize(m_kRecorderList.size() + 1);
					m_kRecorderList.back().m_u32CommandIndex = u32GCLIndex;
					m_kRecorderList.back().m_kTaskList.clear();
					bScene = false;
				}
				m_kRecorderList.back().m_kTaskList.push_back(bar.first);
			}			
			for (VeSizeT k(0); k < kClick.m_kPassList.size(); ++k)
			{
				switch (kClick.m_kPassList[k]->m_eType)
				{
				case VeRenderer::PASS_CLEAR:
				{
					if (bScene)
					{
						if (m_kProcessList.back().m_eType == TYPE_EXCUTE)
						{
							m_kProcessList.back().m_u16Num += 1;
						}
						else
						{
							m_kProcessList.resize(m_kProcessList.size() + 1);
							m_kProcessList.back().m_eType = TYPE_EXCUTE;
							m_kProcessList.back().m_u16Start = u32GCLIndex + 1;
							m_kProcessList.back().m_u16Num = 1;
						}
						++u32GCLIndex;
						m_kRecorderList.resize(m_kRecorderList.size() + 1);
						m_kRecorderList.back().m_u32CommandIndex = u32GCLIndex;
						m_kRecorderList.back().m_kTaskList.clear();
						bScene = false;
					}
					VeRenderer::FrameClear& kClear = (VeRenderer::FrameClear&)*kClick.m_kPassList[k];
					if (VE_MASK_HAS_ANY(kClear.m_u32Flags, VeRenderer::CLEAR_COLOR)
						&& kClear.m_kColorArray.size())
					{
						VeSizeT stColorNum = kCache.m_spRecorder->m_akRTVList->size();
						for (VeSizeT l(0); l < stColorNum; ++l)
						{
							RecordClearRTV* pkTask = VE_NEW RecordClearRTV();
							for (VeSizeT m(0); m < VeRendererD3D12::FRAME_COUNT; ++m)
							{
								pkTask->m_ahHandle[m] = kCache.m_spRecorder->m_akRTVList[m][l];
							}
							if (l < kClear.m_kColorArray.size())
							{
								pkTask->m_kColor = kClear.m_kColorArray[l];
							}
							else
							{
								pkTask->m_kColor = kClear.m_kColorArray.back();
							}
							m_kRecorderList.back().m_kTaskList.push_back(pkTask);
						}
					}
					if (VE_MASK_HAS_ANY(kClear.m_u32Flags, VeRenderer::CLEAR_DEPTH)
						|| VE_MASK_HAS_ANY(kClear.m_u32Flags, VeRenderer::CLEAR_STENCIL))
					{
						if (kCache.m_spRecorder->m_ahDSV->ptr)
						{
							RecordClearDSV* pkTask = VE_NEW RecordClearDSV();
							pkTask->m_eFlags = VE_TMIN(D3D12_CLEAR_FLAGS);
							if (VE_MASK_HAS_ANY(kClear.m_u32Flags, VeRenderer::CLEAR_DEPTH))
							{
								pkTask->m_eFlags |= D3D12_CLEAR_FLAG_DEPTH;
							}
							if (VE_MASK_HAS_ANY(kClear.m_u32Flags, VeRenderer::CLEAR_STENCIL))
							{
								pkTask->m_eFlags |= D3D12_CLEAR_FLAG_STENCIL;
							}
							pkTask->m_f32Depth = kClear.m_f32Depth;
							pkTask->m_u8Stencil = kClear.m_u8Stencil;
							for (VeSizeT m(0); m < VeRendererD3D12::FRAME_COUNT; ++m)
							{
								pkTask->m_ahHandle[m] = kCache.m_spRecorder->m_ahDSV[m];
							}							
							m_kRecorderList.back().m_kTaskList.push_back(pkTask);
						}
					}
				}
				break;
				case VeRenderer::PASS_QUAD:
				{
					if (bScene)
					{
						if (m_kProcessList.back().m_eType == TYPE_EXCUTE)
						{
							m_kProcessList.back().m_u16Num += 1;
						}
						else
						{
							m_kProcessList.resize(m_kProcessList.size() + 1);
							m_kProcessList.back().m_eType = TYPE_EXCUTE;
							m_kProcessList.back().m_u16Start = u32GCLIndex + 1;
							m_kProcessList.back().m_u16Num = 1;
						}
						++u32GCLIndex;
						m_kRecorderList.resize(m_kRecorderList.size() + 1);
						m_kRecorderList.back().m_u32CommandIndex = u32GCLIndex;
						m_kRecorderList.back().m_kTaskList.clear();
						bScene = false;
					}
					if (spCurrent != kCache.m_spRecorder)
					{
						m_kRecorderList.back().m_kTaskList.push_back(kCache.m_spRecorder);
						spCurrent = kCache.m_spRecorder;
					}
					auto& rect = Get(kRectMap, GetResolution(kCache));
					if (spViewport != rect.first)
					{
						m_kRecorderList.back().m_kTaskList.push_back(rect.first);
						spViewport = rect.first;
					}
					if (spScissorRect != rect.second)
					{
						m_kRecorderList.back().m_kTaskList.push_back(rect.second);
						spScissorRect = rect.second;
					}
					VeRenderer::FrameQuad& kQuad = (VeRenderer::FrameQuad&)*kClick.m_kPassList[k];					
					ID3D12RootSignature* pkRootSignature = nullptr;
					ID3D12PipelineState* pkPipelineState = nullptr;
					auto itRoot = kRenderer.m_kRootSignatureMap.find(kQuad.m_kRootSignature);
					if(itRoot != kRenderer.m_kRootSignatureMap.end())
					{
						pkRootSignature = VeSmartPointerCast(VeRendererD3D12::RootSignatureD3D12,
							itRoot->second)->m_pkRootSignature;
					}
					auto itPSO = kRenderer.m_kPipelineStateMap.find(kQuad.m_kPipelineState);
					if (itPSO != kRenderer.m_kPipelineStateMap.end())
					{
						pkPipelineState = VeSmartPointerCast(VeRendererD3D12::PipelineStateD3D12,
							itPSO->second)->m_pkPipelineState;
					}
					if (pkRootSignature && pkPipelineState)
					{
						RecordRenderQuad* pkQuad = VE_NEW RecordRenderQuad();
						pkQuad->m_pkRootSignature = pkRootSignature;
						pkQuad->m_pkPipelineState = pkPipelineState;
						for (auto& itTab : kQuad.m_kTable)
						{
							bool bFinished = false;
							for (auto context : kClick.m_kContextList)
							{
								if (context == itTab.second)
								{
									auto itRTRes = m_kResourceMap.find(itTab.second);
									if (itRTRes != m_kResourceMap.end())
									{
										VeRenderTextureD3D12* pkTex = itRTRes->second;
										if (pkTex->m_kSRVList.size())
										{
											pkQuad->m_kTable.push_back(std::make_pair(itTab.first, pkTex->m_kSRVList.front().m_hGPUHandle));
											bFinished = true;
										}										
										break;
									}
								}
							}
							if(!bFinished)
							{
								auto itRes = kRenderer.m_kResourceMap.find(itTab.second);
								if (itRes != kRenderer.m_kResourceMap.end())
								{
									switch (itRes->second->GetDimension())
									{
									case VeRenderResource::DIMENSION_TEXTURE1D:
									case VeRenderResource::DIMENSION_TEXTURE2D:
									case VeRenderResource::DIMENSION_TEXTURE3D:
									{
										VeRenderTextureD3D12* pkTex = VeDynamicCast(VeRenderTextureD3D12, itRes->second.p());
										if (pkTex && pkTex->m_kSRVList.size())
										{
											pkQuad->m_kTable.push_back(std::make_pair(itTab.first, pkTex->m_kSRVList.front().m_hGPUHandle));
										}
									}
									break;
									default:
										break;
									}
								}
							}							
						}
						m_kRecorderList.back().m_kTaskList.push_back(pkQuad);
					}
				}
				break;
				case VeRenderer::PASS_SCENE:
				{
					VeRenderer::FrameScene& kScene = (VeRenderer::FrameScene&)*kClick.m_kPassList[k];
					if (!bScene)
					{
						spCurrent = nullptr;
						spViewport = nullptr;
						spScissorRect = nullptr;
						bScene = true;
					}
					m_kCameraList.resize(m_kCameraList.size() + 1);
					m_kCameraList.back().m_u32CameraMask = VE_MASK(kScene.m_u32Camera);
					m_kCameraList.back().m_kStageList.resize(kScene.m_u32Stage);
					for (auto& stage : m_kCameraList.back().m_kStageList)
					{
						stage = u32GCLIndex + 1;
						if (m_kProcessList.back().m_eType == TYPE_EXCUTE)
						{
							m_kProcessList.back().m_u16Num += u32ThreadNum;
						}
						else
						{
							m_kProcessList.resize(m_kProcessList.size() + 1);
							m_kProcessList.back().m_eType = TYPE_EXCUTE;
							m_kProcessList.back().m_u16Start = stage;
							m_kProcessList.back().m_u16Num = u32ThreadNum;
						}
						u32GCLIndex += u32ThreadNum;
					}		
				}
				break;
				default:
					break;
				}
			}		
			if (bar.second)
			{
				if (bScene)
				{
					if (m_kProcessList.back().m_eType == TYPE_EXCUTE)
					{
						m_kProcessList.back().m_u16Num += 1;
					}
					else
					{
						m_kProcessList.resize(m_kProcessList.size() + 1);
						m_kProcessList.back().m_eType = TYPE_EXCUTE;
						m_kProcessList.back().m_u16Start = u32GCLIndex + 1;
						m_kProcessList.back().m_u16Num = 1;
					}
					++u32GCLIndex;
					m_kRecorderList.resize(m_kRecorderList.size() + 1);
					m_kRecorderList.back().m_u32CommandIndex = u32GCLIndex;
					m_kRecorderList.back().m_kTaskList.clear();
					bScene = false;
				}
				m_kRecorderList.back().m_kTaskList.push_back(bar.second);
			}
		}
	}

	auto it = kResPathCache.find(nullptr);
	if (it != kResPathCache.end())
	{
		if (it->second.size())
		{
			D3D12_RESOURCE_STATES eResPresent = GetState(it->second.back(), D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES);
			RecordBarrier* pkBarrier = VE_NEW RecordBarrier();
			for (VeSizeT i(0); i < VeRendererD3D12::FRAME_COUNT; ++i)
			{
				pkBarrier->m_akBarrierList[i].resize(pkBarrier->m_akBarrierList[i].size() + 1);
				pkBarrier->m_akBarrierList[i].back().Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
				pkBarrier->m_akBarrierList[i].back().Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
				pkBarrier->m_akBarrierList[i].back().Transition.pResource = m_akFrameCache[i].m_pkBufferResource;
				pkBarrier->m_akBarrierList[i].back().Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
				pkBarrier->m_akBarrierList[i].back().Transition.StateBefore = eResPresent;
				pkBarrier->m_akBarrierList[i].back().Transition.StateAfter = D3D12_RESOURCE_STATE_PRESENT;
			}
			if (bScene)
			{
				if (m_kProcessList.back().m_eType == TYPE_EXCUTE)
				{
					m_kProcessList.back().m_u16Num += 1;
				}
				else
				{
					m_kProcessList.resize(m_kProcessList.size() + 1);
					m_kProcessList.back().m_eType = TYPE_EXCUTE;
					m_kProcessList.back().m_u16Start = u32GCLIndex + 1;
					m_kProcessList.back().m_u16Num = 1;
				}
				++u32GCLIndex;
				m_kRecorderList.resize(m_kRecorderList.size() + 1);
				m_kRecorderList.back().m_u32CommandIndex = u32GCLIndex;
				m_kRecorderList.back().m_kTaskList.clear();
				bScene = false;
			}
			m_kRecorderList.back().m_kTaskList.push_back(pkBarrier);
		}
	}

	m_u32ThreadNum = u32ThreadNum;
	ResizeDirectList(u32GCLIndex + 1);
}
Пример #7
0
void Compile(VeChar8* pcFileName, VeChar8* pcDstDir)
{
	VeChar8* pcFile = VeStrrchr(pcFileName, '/');
	VeSizeT stNum = pcFile - pcFileName;
	VeChar8 acBuffer[2048];
	VeMemcpy(acBuffer, pcFileName, stNum);
	acBuffer[stNum] = 0;
	++pcFile;
	VeFileDir kFile(acBuffer);
	VeChar8* pcContent;
	VeChar8* pcTemp = VeStrtok(pcDstDir, "/", &pcContent);
	VE_ASSERT(pcTemp && *pcTemp);
	VeFileDir kDstFile(pcTemp);
	pcTemp = VeStrtok(NULL, "/", &pcContent);
	while(pcTemp && *pcTemp)
	{
		kDstFile.Change(pcTemp);
		pcTemp = VeStrtok(NULL, "/", &pcContent);
	}
	

	VeBinaryIStreamPtr spStream = kFile.OpenSync(pcFile);
	VE_ASSERT(spStream);
	VeXMLDocument kDoc;
	(*spStream) >> kDoc;
	VE_ASSERT(!kDoc.Error());
	VeXMLElement* pkRoot = kDoc.RootElement();
	VeXMLElement* pkGroup = pkRoot->FirstChildElement("Group");
	while(pkGroup)
	{
		VeXMLElement* pkShader = pkGroup->FirstChildElement();
		while(pkShader)
		{
			const VeChar8* pcName = pkShader->Value();
			const VeChar8* pcSrc = pkShader->GetAttribute("src");
			const VeChar8* pcEntry = pkShader->GetAttribute("entry");
			VeStringA kFile(acBuffer);
			kFile += '/';
			kFile += pcSrc;
			VeVector<const VeChar8*> kProfileList;
			VeXMLElement* pkProfile = pkShader->FirstChildElement("Profile");
			while(pkProfile)
			{
				const VeChar8* pcProfile = pkProfile->GetAttribute("value");
				kProfileList.PushBack(pcProfile);
				pkProfile = pkProfile->NextSiblingElement("Profile");
			}
			VeVector<D3D_SHADER_MACRO> kMacroList;
			VeXMLElement* pkMacro = pkShader->FirstChildElement("Macro");
			while(pkMacro)
			{
				D3D_SHADER_MACRO kMac;
				kMac.Name = pkMacro->GetAttribute("name");
				kMac.Definition = pkMacro->GetAttribute("define");
				kMacroList.PushBack(kMac);
				pkMacro = pkMacro->NextSiblingElement("Macro");
			}
			D3D_SHADER_MACRO kLast = {NULL, NULL};
			kMacroList.PushBack(kLast);
			for(VeVector<const VeChar8*>::iterator it = kProfileList.Begin(); it != kProfileList.End(); ++it)
			{
				HRESULT hRes = S_OK;
				ID3DBlob* pkOut;
				ID3DBlob* pkErrorBlob;
				hRes = D3DX11CompileFromFile(kFile, kMacroList.Begin(), NULL, pcEntry, *it, 
					D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_OPTIMIZATION_LEVEL3 | D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR,
					0, NULL, &pkOut, &pkErrorBlob, NULL);
				if(VE_FAILED(hRes))
				{
					if(pkErrorBlob)
					{
						VE_LOG_EString("HLSLComplier", (VeChar8*)pkErrorBlob->GetBufferPointer());
					}
				}
				else
				{
					VeStringA kOutputName(pcName);
					kOutputName += '.';
					kOutputName += *it;
					VeMemoryOStreamPtr spOutputStream = VE_NEW VeMemoryOStream();
					spOutputStream->AddBlob(pkOut->GetBufferPointer(), pkOut->GetBufferSize());
					kDstFile.WriteAsync(kOutputName, spOutputStream, g_kWriteDelegate);
				}
				VE_SAFE_RELEASE(pkOut);
				VE_SAFE_RELEASE(pkErrorBlob);
			}
			pkShader = pkShader->NextSiblingElement();
		}
		pkGroup = pkGroup->NextSiblingElement("Group");
	}
}