示例#1
0
GpuWaves::~GpuWaves()
{
	ReleaseCOM(mWavesPrevSolSRV);
	ReleaseCOM(mWavesCurrSolSRV);
	ReleaseCOM(mWavesNextSolSRV);

	ReleaseCOM(mWavesPrevSolUAV);
	ReleaseCOM(mWavesCurrSolUAV);
	ReleaseCOM(mWavesNextSolUAV);
}
示例#2
0
SolarSysDemo::~SolarSysDemo()
{
	delete mGfxStats;
	
	ReleaseCOM(mFX);
	ReleaseCOM(mSphere);
	ReleaseCOM(mSunTex);
	ReleaseCOM(mPlanet1Tex);
	ReleaseCOM(mPlanet2Tex);
	ReleaseCOM(mPlanet3Tex);
	ReleaseCOM(mMoonTex);

	DestroyAllVertexDeclarations();
}
示例#3
0
void Scene::BuildFX()
{
	DWORD shaderFlags = D3D10_SHADER_ENABLE_STRICTNESS;
#if defined (DEBUG) || (_DEBUG)
	shaderFlags |= D3D10_SHADER_SKIP_OPTIMIZATION;
#endif 

	ID3D10Blob* compilationErrors = 0;

	HRESULT hr = 0;
	hr =  D3DX10CreateEffectFromFile(L"tex.fx",			// The name of the effects file to compile
									 0,						// pDefines
									 0,						// pInlcude
									 "fx_4_0",				// The version of the shader we are using
									 shaderFlags,			// Specify how the shader code will be complied
									 0,						// FXflags
									 m_Direct3DDevice,		// A pointer to the direct device
									 0,						// pEffectPool
									 0,						// pPump
									 &m_FX,					// Returns a pointer to the created object
									 &compilationErrors,	// Returns a pointer to a string containing the comiplation errors
									 0						// pttResult, used with pPump
									 );

	if( FAILED(hr) )
	{
		if( compilationErrors )
		{
			// Print out any errors
			MessageBoxA( 0, (char*)compilationErrors->GetBufferPointer(), 0, 0);
			ReleaseCOM(compilationErrors);
		}
		DXTrace(__FILE__, (DWORD)__LINE__, hr, L"D3DX10CreateEffectFromFile", true);
	}

	// Set the technique to color tech
	m_Tech = m_FX->GetTechniqueByName("ColorTech");

	// Setup variable pointers to the designated name in effect files
	m_fxWVPVar = m_FX->GetVariableByName("gWVP")->AsMatrix();	// Set the effect file WVP matrix to 
	m_fxDiffuseMapVar = m_FX->GetVariableByName("gDiffuseMap")->AsShaderResource();
	m_FxSpecMapVar = m_FX->GetVariableByName("gSpecMap")->AsShaderResource();
	m_FxEyePosVar = m_FX->GetVariableByName("gEyePosW");
	m_FxLightVar = m_FX->GetVariableByName("gLight");
	m_FxTexMatVar = m_FX->GetVariableByName("gTexMat")->AsMatrix();
	m_FxBoxWorldVar = m_FX->GetVariableByName("gBoxWorld")->AsMatrix();
}
示例#4
0
void DumpMesh::DumpVertices()
{
	const D3D10_INPUT_ELEMENT_DESC *pDesc;
	UINT declCount = NULL;

	m_pMesh->GetVertexDescription(&pDesc, &declCount);

	m_Dumpfile << "---------IALayout-----------"  << std::endl;
	for (size_t i=0; i<declCount; i++)
	{
		m_Dumpfile.width(10);
		m_Dumpfile
			<< pDesc[i].SemanticName << "\t" 
			<< pDesc[i].Format << "\t"
			<< pDesc[i].AlignedByteOffset << "\t"
			<< pDesc[i].InputSlotClass << "\t"
			<< std::endl;
	}

	// Hard code the position type, should be consistances with the 
	// IALayout declaration

	ID3DX10MeshBuffer *vb = NULL;
	m_pMesh->GetVertexBuffer(0, &vb);

	VERTEX *vertices = NULL;
	SIZE_T vbufferSize;

	vb->Map( (void**)&vertices, &vbufferSize );

	m_Position.reserve(m_pMesh->GetVertexBufferCount());
	////m_Dumpfile << "---------Vertices-----------"  << std::endl;
	for (size_t i=0; i<m_pMesh->GetVertexCount(); i++)
	{
		//m_Dumpfile.width(10);
		//m_Dumpfile 
		//	<< vertices[i].position.x << "\t"
		//	<< vertices[i].position.y << "\t"
		//	<< vertices[i].position.z << "\t" 
		//	<< std::endl;
		m_Position.push_back(vertices[i].position);
	}

	vb->Unmap();
	ReleaseCOM(vb);

}
示例#5
0
void Ssao::ReleaseTextureViews()
{
	ReleaseCOM(mNormalDepthRTV);
	ReleaseCOM(mNormalDepthSRV);

	ReleaseCOM(mAmbientRTV0);
	ReleaseCOM(mAmbientSRV0);

	ReleaseCOM(mAmbientRTV1);
	ReleaseCOM(mAmbientSRV1);
}
示例#6
0
TerrainClient::~TerrainClient()
{
	for(UINT i = 0; i < mSubGrids.size(); ++i)
		ReleaseCOM(mSubGrids[i].mesh);

	ReleaseCOM(mFX);
	ReleaseCOM(mTex0);
	ReleaseCOM(mTex1);
	ReleaseCOM(mTex2);
	ReleaseCOM(mBlendMap);
}
D3D::~D3D()
{
	ReleaseCOM(m_device);
	ReleaseCOM(m_deviceContext);
	ReleaseCOM(m_renderTargetView);
	ReleaseCOM(m_swapChain);
	ReleaseCOM(m_depthStencilView);
	ReleaseCOM(m_depthStencilBuffer);

	m_enumAdapters.Release();
}
示例#8
0
Terrain::~Terrain()
{
	for(UINT i = 0; i < mSubGridMeshes.size(); ++i)
		ReleaseCOM(mSubGridMeshes[i]);

	ReleaseCOM(mFX);
	ReleaseCOM(mTex0);
	ReleaseCOM(mTex1);
	ReleaseCOM(mTex2);
	ReleaseCOM(mBlendMap);
}
示例#9
0
文件: Mesh.cpp 项目: flosmn/MeshPRT
HRESULT Mesh::AdjustMeshDecl()
{
  HRESULT hr;
  
  LPD3DXMESH pInMesh = mMesh;
  LPD3DXMESH pOutMesh = NULL;

  D3DVERTEXELEMENT9 vertDecl[ MAX_FVF_DECL_SIZE ] =
  {
  {0,  0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
  {0,  12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
  {0,  24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},

	// exact SH-coefficients
  {0, 32, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0},
	{0, 48, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 1},
  {0, 64, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 2},
  {0, 80, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 3},
  {0, 96, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 4},
  {0, 112, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 5},
  {0, 128, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 6},
	{0, 144, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 7},
	{0, 160, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 8},
	  
	{0, 176, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 2},
	{0, 188, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 3},
	D3DDECL_END()
  };
  
  hr = pInMesh->CloneMesh( pInMesh->GetOptions(), vertDecl, mDevice, &pOutMesh );
  PD( hr, L"clone mesh" );
  if( FAILED(hr) ) return hr;

  if( !DoesMeshHaveUsage( D3DDECLUSAGE_NORMAL ) )
  {
    hr = D3DXComputeNormals( pOutMesh, NULL );
    PD( hr, L"compute normals" );
    if( FAILED(hr) ) return hr;
  }

  ReleaseCOM( pInMesh )

  mMesh = pOutMesh;

  return D3D_OK;
}
示例#10
0
ShadowMap::ShadowMap( ID3D11Device* device, UINT width, UINT height )
    : mWidth( width ), mHeight( height ), mDepthMapSRV( 0 ), mDepthMapDSV( 0 )
{
    mViewport.TopLeftX = 0.0f;
    mViewport.TopLeftY = 0.0f;
    mViewport.Width = static_cast<float>( width );
    mViewport.Height = static_cast<float>( height );
    mViewport.MinDepth = 0.0f;
    mViewport.MaxDepth = 1.0f;

    // Use typeless format because the DSV is going to interpret
    // the bits as DXGI_FORMAT_D24_UNORM_S8_UINT, whereas the SRV is going to interpret
    // the bits as DXGI_FORMAT_R24_UNORM_X8_TYPELESS.
    D3D11_TEXTURE2D_DESC texDesc;
    texDesc.Width = mWidth;
    texDesc.Height = mHeight;
    texDesc.MipLevels = 1;
    texDesc.ArraySize = 1;
    texDesc.Format = DXGI_FORMAT_R24G8_TYPELESS;
    texDesc.SampleDesc.Count = 1;
    texDesc.SampleDesc.Quality = 0;
    texDesc.Usage = D3D11_USAGE_DEFAULT;
    texDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE;
    texDesc.CPUAccessFlags = 0;
    texDesc.MiscFlags = 0;

    ID3D11Texture2D* depthMap = 0;
    HR( device->CreateTexture2D( &texDesc, 0, &depthMap ) );

    D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
    dsvDesc.Flags = 0;
    dsvDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
    dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
    dsvDesc.Texture2D.MipSlice = 0;
    HR( device->CreateDepthStencilView( depthMap, &dsvDesc, &mDepthMapDSV ) );

    D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
    srvDesc.Format = DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
    srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
    srvDesc.Texture2D.MipLevels = texDesc.MipLevels;
    srvDesc.Texture2D.MostDetailedMip = 0;
    HR( device->CreateShaderResourceView( depthMap, &srvDesc, &mDepthMapSRV ) );

    // View saves a reference to the texture so we can release our reference.
    ReleaseCOM( depthMap );
}
示例#11
0
	ShadowMap::ShadowMap(ID3D11Device* device, UINT Width, UINT Height)
		: m_Width(Width), 
		m_Height(Height),
		m_DepthMapDSV(nullptr),
		m_DepthMapSRV(nullptr)
	{
		m_Viewport.TopLeftX = 0.0f;
		m_Viewport.TopLeftY = 0.0f;
		m_Viewport.Width = static_cast<FLOAT>(m_Width);
		m_Viewport.Height = static_cast<FLOAT>(m_Height);
		m_Viewport.MinDepth = 0.0f;
		m_Viewport.MaxDepth = 1.0f;
		
		D3D11_TEXTURE2D_DESC td;
		td.Width = m_Width;
		td.Height = m_Height;
		td.MipLevels = 1;
		td.ArraySize = 1;
		td.Format = DXGI_FORMAT_R24G8_TYPELESS;
		td.SampleDesc.Count = 1;
		td.SampleDesc.Quality = 0;
		td.Usage = D3D11_USAGE_DEFAULT;
		td.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE;
		td.CPUAccessFlags = 0;
		td.MiscFlags = 0;

		ID3D11Texture2D* DepthMap = nullptr;
		HR(device->CreateTexture2D(&td, 0, &DepthMap));

		D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
		dsvDesc.Flags = 0;
		dsvDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
		dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
		dsvDesc.Texture2D.MipSlice = 0;
		HR(device->CreateDepthStencilView(DepthMap, &dsvDesc, &m_DepthMapDSV));

		D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
		srvDesc.Format = DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
		srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
		srvDesc.Texture2D.MipLevels = td.MipLevels;
		srvDesc.Texture2D.MostDetailedMip = 0;
		HR(device->CreateShaderResourceView(DepthMap, &srvDesc, &m_DepthMapSRV));

		ReleaseCOM(DepthMap);
	}
示例#12
0
/**
	Dependent on having your depth buffer set
**/
void D3D::CreateDepthStencilView()
{
	D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;

	ReleaseCOM(m_depthStencilView);
	
	//Check if we have a depth stencil buffer
	if(!m_depthStencilBuffer) return;

	//Initialize depth stencil view
	ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc));
	depthStencilViewDesc.Format				= DXGI_FORMAT_D24_UNORM_S8_UINT;
	depthStencilViewDesc.ViewDimension		= D3D11_DSV_DIMENSION_TEXTURE2D;
	depthStencilViewDesc.Texture2D.MipSlice = 0;

	HR(m_device->CreateDepthStencilView(m_depthStencilBuffer, &depthStencilViewDesc, &m_depthStencilView));

}
示例#13
0
ShadowMap::ShadowMap(ID3D11Device *device, UINT width, UINT height)
:mWidth(width), mHeight(height), mDepthDSV(0), mDepthSRV(0), mEnable4xMsaa(0), m4xMsaaQuality(0)
{
	m_matViewport.TopLeftX = 0.0f;
	m_matViewport.TopLeftY = 0.0f;
	m_matViewport.Width = static_cast<float>(width);
	m_matViewport.Height = static_cast<float>(height);
	m_matViewport.MinDepth = 0.0f;
	m_matViewport.MaxDepth = 1.0f;

	D3D11_TEXTURE2D_DESC texDesc;
	texDesc.Width = mWidth;
	texDesc.Height = mHeight;
	texDesc.MipLevels = 1;
	texDesc.ArraySize = 1;
	texDesc.Format = DXGI_FORMAT_R24G8_TYPELESS;

	texDesc.SampleDesc.Count = 1;
	texDesc.SampleDesc.Quality = 0;

	texDesc.Usage = D3D11_USAGE_DEFAULT;
	texDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE;
	texDesc.CPUAccessFlags = 0;
	texDesc.MiscFlags = 0;

	ID3D11Texture2D * depthMap = 0;
	HR(device->CreateTexture2D(&texDesc, 0, &depthMap));

	D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
	dsvDesc.Flags = 0;
	dsvDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
	dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
	dsvDesc.Texture2D.MipSlice = 0;
	HR(device->CreateDepthStencilView(depthMap, &dsvDesc, &mDepthDSV));

	D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
	srvDesc.Format = DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
	srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
	srvDesc.Texture2D.MipLevels = texDesc.MipLevels;
	srvDesc.Texture2D.MostDetailedMip = 0;
	HR(device->CreateShaderResourceView(depthMap, &srvDesc, &mDepthSRV));

	ReleaseCOM(depthMap);
}
	void D3D9PixelBuffer::bind( uint32 face, uint32 mip, IDirect3DCubeTexture9* texTarget )
	{
		unbind();
		mMipIndex = mip;
		mCubeTarget = texTarget;
		switch(face)
		{
		case 0:
			mFaceIndex = D3DCUBEMAP_FACE_POSITIVE_X;
			break;
		case 1:
			mFaceIndex = D3DCUBEMAP_FACE_NEGATIVE_X;
			break;
		case 2:
			mFaceIndex = D3DCUBEMAP_FACE_POSITIVE_Y;
			break;
		case 3:
			mFaceIndex = D3DCUBEMAP_FACE_NEGATIVE_Y;
			break;
		case 4:
			mFaceIndex = D3DCUBEMAP_FACE_POSITIVE_Z;
			break;
		case 5:
			mFaceIndex = D3DCUBEMAP_FACE_NEGATIVE_Z;
			break;
		}
		IDirect3DSurface9* suf = NULL;
		if (FAILED(texTarget->GetCubeMapSurface(mFaceIndex,mip,&suf)))
		{
			unbind();
			return;
		}
		D3DSURFACE_DESC desc;
		suf->GetDesc(&desc);
		mWidth	= desc.Width;
		mHeight	= desc.Height;
		mDepth	= 1;
		mFormat	= D3D9Translator::getPixelFormat(desc.Format);
		mRowPitch = mWidth * DPixelFormatTool::getFormatBytes(mFormat);
		mSlicePitch = mHeight * mRowPitch;
		mByteSize	= mSlicePitch;
		ReleaseCOM(suf);
	}
void MeshGeometry::SetVertices(ID3D11Device* device,
	const Vertex::NormalTexVertex* verts,
	UINT count)
{
	ReleaseCOM(mVB);

	D3D11_BUFFER_DESC vbd;
	vbd.Usage = D3D11_USAGE_IMMUTABLE;
	vbd.ByteWidth = sizeof(Vertex::NormalTexVertex) * count;
	vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	vbd.CPUAccessFlags = 0;
	vbd.MiscFlags = 0;
	vbd.StructureByteStride = 0;

	D3D11_SUBRESOURCE_DATA vinitData;
	vinitData.pSysMem = verts;

	HR(device->CreateBuffer(&vbd, &vinitData, &mVB));
}
示例#16
0
Projekt::~Projekt()
{
	SafeDelete(mGenericModel);

	//SafeDelete(mSkinnedModel);

	SafeDelete(mPlayerModel);

	SafeDelete(mSky);

	SafeDelete(mShadowMap);

	ReleaseCOM(WireFrameRS);

	Effects::DestroyAll();
	InputLayouts::DestroyAll();

	delete GameSettings::Instance();
}
示例#17
0
D3DApp::~D3DApp()
{
	ReleaseCOM(mRenderTargetView);
	ReleaseCOM(mDepthStencilView);
	ReleaseCOM(mSwapChain);
	ReleaseCOM(mDepthStencilBuffer);

	// Restore all default settings.
	if( md3dImmediateContext )
		md3dImmediateContext->ClearState();

	ReleaseCOM(md3dImmediateContext);
	ReleaseCOM(md3dDevice);
}
示例#18
0
D3DApp::~D3DApp() {
	ReleaseCOM(m_renderTargetView);
	ReleaseCOM(m_depthStencilView);
	ReleaseCOM(m_swapChain);
	ReleaseCOM(m_depthStencilBuffer);

	if (m_d3dImmediateContext)
		m_d3dImmediateContext->ClearState();

	ReleaseCOM(m_d3dImmediateContext);
	ReleaseCOM(m_d3dDevice);

	UnregisterClass(L"DirectXApplication", application);
}
MirrorApp::~MirrorApp()
{
	md3dImmediateContext->ClearState();
	ReleaseCOM(mRoomVB);
	ReleaseCOM(mSkullVB);
	ReleaseCOM(mSkullIB);
	ReleaseCOM(mFloorDiffuseMapSRV);
	ReleaseCOM(mWallDiffuseMapSRV);
	ReleaseCOM(mMirrorDiffuseMapSRV);
 
	Effects::DestroyAll();
	InputLayouts::DestroyAll();
	RenderStates::DestroyAll();
}
示例#20
0
cInitDirect3D::~cInitDirect3D()
{
	ReleaseCOM(m_pRenderTargetView);
	ReleaseCOM(m_pDepthStencilView);
	ReleaseCOM(m_pSwapChain);
	ReleaseCOM(m_pDepthStencilBuffer);

	// Restore all default settings.
	if (m_pDeviceContext)
		m_pDeviceContext->ClearState();

	ReleaseCOM(m_pDeviceContext);
	ReleaseCOM(m_pD3dDevice);
}
void RenderContext::FinishRender()
{
#if defined(USE_IMMEDIATE_CONTEXT)

#else
    #if defined(XCGRAPHICS_DX12)
        //Cmdlist Close can happen here when in multiple render context.
        ValidateResult(m_deviceContext->Close());
    #elif defined(XCGRAPHICS_DX11)
        ID3DCommandList* commandList;
        m_deviceContext->FinishCommandList(false, &commandList);

        //Execute on main device context
        m_graphicsSystem->GetDeviceContext()->ExecuteCommandList(commandList, true);
        ReleaseCOM(commandList);

        m_shaderContainer->ClearShaderAndRenderStates(*m_deviceContext);
    #endif
#endif
}
示例#22
0
文件: Mesh.cpp 项目: flosmn/MeshPRT
HRESULT Mesh::LoadMesh(ID3DXMesh* mesh){
  HRESULT hr;

  CleanUpMesh();

  D3DVERTEXELEMENT9 decl[MAX_FVF_DECL_SIZE];
  hr = mesh->GetDeclaration(decl);
  hr = mesh->CloneMesh( mesh->GetOptions(), decl, mDevice, &mMesh );
  PD(hr, L"clone mesh");

  ReleaseCOM(mesh)

  SetDirectory( L"models/" );
  SetName( L"meshlab" );

  PD( AdjustMeshDecl(), L"adjust mesh delaration" );
  PD( AttribSortMesh(), L"attribute sort mesh" );

  return D3D_OK;
}
SuperSolarSystemApp::~SuperSolarSystemApp( )
{
	mD3dImmediateContext->ClearState( );

	SafeDelete( mSpace );
	ReleaseCOM( mLightTexVB );
	ReleaseCOM( mLightTexIB );
	ReleaseCOM( mColorIB );
	ReleaseCOM( mColorVB );
	ReleaseCOM( mDynamicCubeMapDSV );
	ReleaseCOM( mDynamicCubeMapSRV );

	for ( int i = 0; i < 6; ++i )
		ReleaseCOM( mDynamicCubeMapRTV[i] );

	for ( int i = 0; i < STARNUMBER; i++ )
		ReleaseCOM( mDiffuseMapSRV[i] );

	Effects::DestroyAll( );
	InputLayouts::DestroyAll( );
	RenderStates::DestroyAll( );
}
示例#24
0
D3DApp::~D3DApp()
{
	ReleaseCOM(mRenderTargetView);
	ReleaseCOM(mDepthStencilView);
	ReleaseCOM(mSwapChain);
	ReleaseCOM(mDepthStencilBuffer);

	if (mImmediateContext)
	{
		mImmediateContext->ClearState();
	}

	ReleaseCOM(mImmediateContext);
	ReleaseCOM(mDevice);
}
示例#25
0
void World::drawToMinimap(RenderTarget* renderTarget)
{
	// Save the current render target to restore it later.
	LPDIRECT3DSURFACE9 backBuffer;
	gd3dDevice->GetRenderTarget(0, &backBuffer);
	gd3dDevice->SetRenderTarget(0, renderTarget->getSurface());

	HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, 0xffffff00, 1.0f, 0xffff));

	// Set the cameras position to bird view.
	D3DXVECTOR3 position = gCamera->getPosition();
	float yaw = gCamera->getYaw();
	float pitch = gCamera->getPitch();

	gCamera->setPosition(position + D3DXVECTOR3(0, 5000, 0));
	gCamera->setPitch(-D3DX_PI/2);
	gCamera->rotate();
	gCamera->updateView();

	// Draw the terrain.
	mTerrain->draw();

	// Draw all the enemies with a red box and the player with a green.
	for(int i = 0; i < mObjectList.size(); i++) {
		if(!mObjectList[i]->getAlive() || mObjectList[i]->getType() == PARTICLE_SYSTEM || mObjectList[i]->getType() == SPAWNER)
			continue;

		// Draw minimap icon.
		gGraphics->drawBoundingBox(mObjectList[i]->getMinimapTexture(), mObjectList[i]->getPosition() + D3DXVECTOR3(0, 1500, 0), Dimensions(200, 1, 200), WHITE, 1.0f);
	}

	// Restore the camera.
	gCamera->setPosition(position);
	gCamera->setYaw(yaw);
	gCamera->setPitch(pitch);
	gCamera->rotate();

	// Change back to the backbuffer.
	gd3dDevice->SetRenderTarget(0, backBuffer);
	ReleaseCOM(backBuffer);
}
	void D3D9PixelBuffer::bind( uint32 mip, IDirect3DVolumeTexture9* texTarget )
	{
		unbind();
		mMipIndex = mip;
		m3DTarget = texTarget;
		IDirect3DVolume9* vol = NULL;
		if (FAILED(texTarget->GetVolumeLevel(mip, &vol)))
		{
			unbind();
			return;
		}
		D3DVOLUME_DESC desc;
		vol->GetDesc(&desc);
		mWidth	= desc.Width;
		mHeight	= desc.Height;
		mDepth	= desc.Depth;
		mFormat	= D3D9Translator::getPixelFormat(desc.Format);
		mRowPitch = mWidth * DPixelFormatTool::getFormatBytes(mFormat);
		mSlicePitch = mHeight * mRowPitch;
		mByteSize	= mSlicePitch * mDepth;
		ReleaseCOM(vol);
	}
void RenderTexture::BuildTexture(void)
{
    D3D10_TEXTURE2D_DESC  texDesc;
    D3D10_RENDER_TARGET_VIEW_DESC renderTargetViewDesc;
	D3D10_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc;
    memset(&texDesc, 0 , sizeof(texDesc));

    texDesc.Width     = m_width;
	texDesc.Height    = m_height;
	texDesc.MipLevels = 0;
	texDesc.ArraySize = 1;
	texDesc.Format    = m_format;
	texDesc.SampleDesc.Count   = 1;  
	texDesc.SampleDesc.Quality = 0;  
	texDesc.Usage          = D3D10_USAGE_DEFAULT;
	texDesc.BindFlags      = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
	texDesc.CPUAccessFlags = 0; 
	texDesc.MiscFlags      = D3D10_RESOURCE_MISC_GENERATE_MIPS;

    HR(m_device->CreateTexture2D(&texDesc, 0, &m_tex));


    renderTargetViewDesc.Format = texDesc.Format;
    renderTargetViewDesc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
    renderTargetViewDesc.Texture2D.MipSlice = 0;

	
	HR(m_device->CreateRenderTargetView(m_tex, &renderTargetViewDesc, &m_rtv));
    
    shaderResourceViewDesc.Format = texDesc.Format;
    shaderResourceViewDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
    shaderResourceViewDesc .Texture2D.MostDetailedMip = 0;
    shaderResourceViewDesc .Texture2D.MipLevels =1;
	
    HR(m_device->CreateShaderResourceView(m_tex,&shaderResourceViewDesc , &m_srv));

	// View saves a reference to the texture so we can release our reference.
	ReleaseCOM(m_tex);
}
示例#28
0
void Ssao::BuildRandomVectorTexture()
{
	D3D11_TEXTURE2D_DESC texDesc;
	texDesc.Width = 256;
	texDesc.Height = 256;
	texDesc.MipLevels = 1;
	texDesc.ArraySize = 1;
	texDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	texDesc.SampleDesc.Count = 1;
	texDesc.SampleDesc.Quality = 0;
	texDesc.Usage = D3D11_USAGE_IMMUTABLE;
	texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
	texDesc.CPUAccessFlags = 0;
	texDesc.MiscFlags = 0;
	
	D3D11_SUBRESOURCE_DATA initData = {0};
	initData.SysMemPitch = 256*sizeof(XMCOLOR);

	XMCOLOR color[256*256];
	for(int i = 0; i < 256; ++i)
	{
		for(int j = 0; j < 256; ++j)
		{
			XMFLOAT3 v(MathHelper::RandF(), MathHelper::RandF(), MathHelper::RandF());

			color[i*256+j] = XMCOLOR(v.x, v.y, v.z, 0.0f);
		}
	}

	initData.pSysMem = color;
	
	ID3D11Texture2D* tex = 0;
	HR(md3dDevice->CreateTexture2D(&texDesc, &initData, &tex));
	
	HR(md3dDevice->CreateShaderResourceView(tex, 0, &mRandomVectorSRV));
	
	// view saves a reference.
	ReleaseCOM(tex);
}
示例#29
0
void D3D::CreateDepthStencilBuffer(int screenWidth, int screenHeight)
{
	D3D11_TEXTURE2D_DESC depthBufferDesc;

	ReleaseCOM(m_depthStencilBuffer);

	//Initialize depth stencil buffer
	ZeroMemory(&depthBufferDesc, sizeof(depthBufferDesc));
	depthBufferDesc.Width				= screenWidth;
	depthBufferDesc.Height				= screenHeight;
	depthBufferDesc.MipLevels			= 1;
	depthBufferDesc.ArraySize			= 1;
	depthBufferDesc.Format				= DXGI_FORMAT_D24_UNORM_S8_UINT;
	depthBufferDesc.SampleDesc.Count	= 1;
	depthBufferDesc.SampleDesc.Quality	= 0;
	depthBufferDesc.Usage				= D3D11_USAGE_DEFAULT;
	depthBufferDesc.BindFlags			= D3D11_BIND_DEPTH_STENCIL;
	depthBufferDesc.CPUAccessFlags		= 0;
	depthBufferDesc.MiscFlags			= 0;

	HR(m_device->CreateTexture2D(&depthBufferDesc, 0, &m_depthStencilBuffer));
}
void DrawMorphMesh(D3DXMESHCONTAINER_EX *SourceMesh,
                   D3DXMESHCONTAINER_EX *TargetMesh,
                   float Scalar)
{
  // Get the world, view, and projection matrices
  D3DXMATRIX matWorld, matView, matProj;
  g_pD3DDevice->GetTransform(D3DTS_WORLD, &matWorld);
  g_pD3DDevice->GetTransform(D3DTS_VIEW, &matView);
  g_pD3DDevice->GetTransform(D3DTS_PROJECTION, &matProj);

  // Get the world*view*proj matrix and set it
  D3DXMATRIX matWVP;
  matWVP = matWorld * matView * matProj;
  D3DXMatrixTranspose(&matWVP, &matWVP);
  g_pD3DDevice->SetVertexShaderConstantF(0, (float*)&matWVP, 4);

  // Set the scalar value to use
  g_pD3DDevice->SetVertexShaderConstantF(4, (float*)&D3DXVECTOR4(1.0f-Scalar, Scalar, 0.0f, 0.0f), 1);

  // Set the light direction (convert from model space to view space)
  D3DXMATRIX matInvWorld;
  D3DXMatrixInverse(&matInvWorld, NULL, &matWorld);
  D3DXVECTOR3 vecLight = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
  D3DXVec3TransformCoord(&vecLight, &vecLight, &matInvWorld);
  g_pD3DDevice->SetVertexShaderConstantF(5, (float*)&D3DXVECTOR4(vecLight.x, vecLight.y, vecLight.z, 0.0f), 1);

  // Set the 2nd stream source
  IDirect3DVertexBuffer9 *pVB = NULL;
  TargetMesh->MeshData.pMesh->GetVertexBuffer(&pVB);
  g_pD3DDevice->SetStreamSource(1, pVB, 0, D3DXGetFVFVertexSize(TargetMesh->MeshData.pMesh->GetFVF()));

  // Draw the mesh in the vertex shader
  DrawMesh(SourceMesh, g_VS, g_Decl);

  // Clear the 2nd stream source and free the vertex buffer interface
  g_pD3DDevice->SetStreamSource(1, NULL, 0, 0);
  ReleaseCOM(pVB);
}