Exemplo n.º 1
0
/** Draws the meshes to the buffer */
void SV_GMeshInfoView::DrawMeshes()
{
	D3D11GraphicsEngine* g = (D3D11GraphicsEngine *)Engine::GraphicsEngine;

	g->SetupVS_ExMeshDrawCall();
	g->SetupVS_ExConstantBuffer();
	g->SetupVS_ExPerInstanceConstantBuffer();

	VisualTesselationSettings* ts = NULL;
	if(VisualInfo)
		ts = &VisualInfo->TesselationInfo;

	// Draw each texture
	for(auto it = Meshes.begin(); it != Meshes.end(); it++)
	{
		// Set up tesselation if wanted
		if(ts && !(*it).second->IndicesPNAEN.empty() && ts->buffer.VT_TesselationFactor > 0.0f)
		{
			g->Setup_PNAEN(D3D11GraphicsEngine::PNAEN_Default);
			ts->Constantbuffer->BindToDomainShader(1);
			ts->Constantbuffer->BindToHullShader(1);

			

			if((*it).first->CacheIn(-1) == zRES_CACHED_IN)
			{
				MyDirectDrawSurface7* surface = (*it).first->GetSurface();
				ID3D11ShaderResourceView* srv = surface->GetNormalmap() ? ((D3D11Texture *)surface->GetNormalmap())->GetShaderResourceView() : NULL;

				// Draw
				(*it).first->Bind(0);
				g->DrawVertexBufferIndexed( (*it).second->MeshVertexBuffer,
											(*it).second->MeshIndexBufferPNAEN,
											(*it).second->IndicesPNAEN.size() );
			}
		}else if(VisualInfo)
		{
			g->GetContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
			g->GetContext()->DSSetShader(NULL, NULL, NULL);
			g->GetContext()->HSSetShader(NULL, NULL, NULL);
			g->SetActiveHDShader("");
			g->SetActiveVertexShader("VS_Ex");

			if((*it).first && (*it).first->CacheIn(-1) == zRES_CACHED_IN)
			{
				// Draw
				(*it).first->Bind(0);
				g->DrawVertexBufferIndexed( (*it).second->MeshVertexBuffer,
											(*it).second->MeshIndexBuffer,
											(*it).second->Indices.size() );
			}
		}


		
	}

	
}
Exemplo n.º 2
0
/** Updates the view */
void SV_GMeshInfoView::UpdateView()
{
	if(IsHidden())
		return;

	D3D11GraphicsEngine* g = (D3D11GraphicsEngine *)Engine::GraphicsEngine;

	D3DXMatrixPerspectiveFovLH(&ObjectProjMatrix, (float)D3DXToRadian(FOV), GetSize().height / GetSize().width, 0.01f, 10000.0f);
	D3DXMatrixTranspose(&ObjectProjMatrix, &ObjectProjMatrix);

	g->SetDefaultStates();
	Engine::GAPI->GetRendererState()->RasterizerState.CullMode = GothicRasterizerStateInfo::CM_CULL_NONE;
	Engine::GAPI->GetRendererState()->RasterizerState.SetDirty();

	D3DXMATRIX oldProj = Engine::GAPI->GetProjTransform();

	// Set transforms
	Engine::GAPI->SetWorldTransform(ObjectWorldMatrix);
	Engine::GAPI->SetViewTransform(ObjectViewMatrix);
	Engine::GAPI->SetProjTransform(ObjectProjMatrix);

	// Set Viewport
	D3D11_VIEWPORT oldVP; 
	UINT numVP = 1;
	g->GetContext()->RSGetViewports(&numVP, &oldVP);

	D3D11_VIEWPORT vp;
	vp.TopLeftX = 0;
	vp.TopLeftY = 0;
	vp.Width = GetSize().width;
	vp.Height = GetSize().height;
	vp.MinDepth = 0.0f;
	vp.MaxDepth = 1.0f;

	g->GetContext()->RSSetViewports(1, &vp);

	// Clear
	g->GetContext()->ClearRenderTargetView(RT->GetRenderTargetView(), (float *)&D3DXVECTOR4(0,0,0,0));
	g->GetContext()->ClearDepthStencilView(DS->GetDepthStencilView(), D3D11_CLEAR_DEPTH, 1.0f, 0); 

	// Bind RTV
	g->GetContext()->OMSetRenderTargets(1, RT->GetRenderTargetViewPtr(), DS->GetDepthStencilView());

	// Setup shaders
	g->SetActiveVertexShader("VS_Ex");
	g->SetActivePixelShader("PS_DiffuseAlphaTest");

	switch(RenderMode)
	{
	case RM_Lit:
		g->SetActivePixelShader("PS_Preview_TexturedLit");
		DrawMeshes();
		break;

	case RM_Textured:
		g->SetActivePixelShader("PS_Preview_Textured");
		DrawMeshes();
		break;

	case RM_TexturedWireFrame:
		g->SetActivePixelShader("PS_Preview_Textured");
		DrawMeshes();
		// No break here, render wireframe right after

	case RM_Wireframe:
		g->SetActivePixelShader("PS_Preview_White");
		Engine::GAPI->GetRendererState()->RasterizerState.Wireframe = true;
		Engine::GAPI->GetRendererState()->RasterizerState.SetDirty();
		DrawMeshes();
		Engine::GAPI->GetRendererState()->RasterizerState.Wireframe = false;
		Engine::GAPI->GetRendererState()->RasterizerState.SetDirty();
		break;
	}
	// Reset viewport
	g->GetContext()->RSSetViewports(1, &oldVP);
	Engine::GAPI->SetProjTransform(oldProj);

	// Update panel
	Panel->SetD3D11TextureAsImage(RT->GetTexture(), INT2(RT->GetSizeX(), RT->GetSizeY()));
}