Пример #1
0
void Grid::init_buffer(ID3D11Device *pD3D11Device, ID3D11DeviceContext *pD3D11DeviceContext)
{
	HRESULT hr;
	auto dir = d3d::TextureMgr::getInstance()->getDir() + "heightmap01.bmp";

	load_heightMap( dir.c_str() );

	d3d::Geometry geom;
	d3d::Geometry::MeshData gridMesh;
	geom.CreateGrid(160.0, 160.0, m_TerrainWidth, m_TerrainHeight, gridMesh);

	m_VertexCount = gridMesh.VertexData.size();
	for (int i = 0; i != m_VertexCount; ++i)
		gridMesh.VertexData[i].Pos.y = m_HightmapData[i].y / 10.0f;

	calc_normal(gridMesh);

	/////////////////////////////Vertex Buffer//////////////////////////////
	m_VertexCount = gridMesh.VertexData.size();
	D3D11_BUFFER_DESC gridVBDesc;
	gridVBDesc.Usage               = D3D11_USAGE_IMMUTABLE;
	gridVBDesc.ByteWidth           = sizeof(Vertex) * m_VertexCount;
	gridVBDesc.BindFlags           = D3D11_BIND_VERTEX_BUFFER;
	gridVBDesc.CPUAccessFlags      = 0;
	gridVBDesc.MiscFlags           = 0;
	gridVBDesc.StructureByteStride = 0;

	D3D11_SUBRESOURCE_DATA gridVBO;
	gridVBO.pSysMem = &gridMesh.VertexData[0];
	hr = pD3D11Device->CreateBuffer(&gridVBDesc, &gridVBO, &m_pGridVB);
	DebugHR(hr);

	/////////////////////////////Index Buffer//////////////////////////////

	m_IndexCount =  gridMesh.IndexData.size();
	D3D11_BUFFER_DESC gridIBDesc;
	gridIBDesc.Usage               = D3D11_USAGE_IMMUTABLE;
	gridIBDesc.ByteWidth           = sizeof(UINT) * m_IndexCount;
	gridIBDesc.BindFlags           = D3D11_BIND_INDEX_BUFFER;
	gridIBDesc.CPUAccessFlags      = 0;
	gridIBDesc.MiscFlags           = 0;
	gridIBDesc.StructureByteStride = 0;

	D3D11_SUBRESOURCE_DATA girdIBO;
	girdIBO.pSysMem = &gridMesh.IndexData[0];
	hr = pD3D11Device->CreateBuffer(&gridIBDesc, &girdIBO, &m_pGridIB);
	DebugHR(hr);

	////////////////////////////////Const Buffer//////////////////////////////////////

	D3D11_BUFFER_DESC mvpDesc;	
	ZeroMemory(&mvpDesc, sizeof(D3D11_BUFFER_DESC));
	mvpDesc.Usage          = D3D11_USAGE_DEFAULT;
	mvpDesc.ByteWidth      = sizeof(d3d::MatrixBuffer);
	mvpDesc.BindFlags      = D3D11_BIND_CONSTANT_BUFFER;
	mvpDesc.CPUAccessFlags = 0;
	mvpDesc.MiscFlags      = 0;
	hr = pD3D11Device->CreateBuffer(&mvpDesc, NULL, &m_pMVPBuffer);
	DebugHR(hr);
}
Пример #2
0
	void D3DBitmap::init_texture(ID3D11Device *pD3D11Device, WCHAR *texFile)
	{
		HRESULT hr;
		hr = CreateDDSTextureFromFile(pD3D11Device, texFile, NULL, &m_pTextureSRV, NULL);
		DebugHR(hr);
	
		// Create a texture sampler state description.
		D3D11_SAMPLER_DESC samplerDesc;
		samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
		samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
		samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
		samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
		samplerDesc.MipLODBias = 0.0f;
		samplerDesc.MaxAnisotropy = 1;
		samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
		samplerDesc.BorderColor[0] = 0;
		samplerDesc.BorderColor[1] = 0;
		samplerDesc.BorderColor[2] = 0;
		samplerDesc.BorderColor[3] = 0;
		samplerDesc.MinLOD = 0;
		samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
	
		// Create the texture sampler state.
		hr = pD3D11Device->CreateSamplerState(&samplerDesc, &m_pTexSamplerState);
		DebugHR(hr);
	
	}
Пример #3
0
void OutputPin::Send(unsigned char *data[DSHOW_MAX_PLANES],
		size_t linesize[DSHOW_MAX_PLANES],
		long long timestampStart, long long timestampEnd)
{
	ComQIPtr<IMemInputPin> memInput(connectedPin);
	REFERENCE_TIME startTime = timestampStart;
	REFERENCE_TIME endTime = timestampEnd;
	ComPtr<IMediaSample> sample;
	HRESULT hr;
	BYTE *ptr;

	if (!memInput || !allocator)
		return;

	hr = allocator->GetBuffer(&sample, &startTime, &endTime, 0);
	if (FAILED(hr))
		return;

	if (FAILED(sample->SetActualDataLength((long)bufSize)))
		return;
	if (FAILED(sample->SetDiscontinuity(false)))
		return;
	if (FAILED(sample->SetMediaTime(&startTime, &endTime)))
		return;
	if (FAILED(sample->SetPreroll(false)))
		return;
	if (FAILED(sample->SetTime(&startTime, &endTime)))
		return;
	if (FAILED(sample->GetPointer(&ptr)))
		return;

	size_t total = 0;
	for (size_t i = 0; i < DSHOW_MAX_PLANES; i++) {
		if (!linesize[i])
			break;

		memcpy(ptr + total, data[i], linesize[i]);
		total += linesize[i];
	}

	hr = memInput->Receive(sample);
	if (FAILED(hr)) {
		DebugHR(L"test", hr);
	}
}
Пример #4
0
	void D3DBitmap::init_buffer(ID3D11Device *pD3D11Device, ID3D11DeviceContext *pD3D11DeviceContext)
	{
		HRESULT hr;
	
		m_VertexCount = 6;
		m_IndexCount = 6;
	
		std::vector<Vertex> VertexData(6);
		std::vector<UINT> IndexData(6);
	
		for (int i = 0; i != m_IndexCount; ++i)
		{
			IndexData[i] = i;
		}
		// Calculate the screen coordinates of the left side of the D3DBitmap.
		float left = (float)((m_sw / 2) * -1) + (float)m_posX;
	
		// Calculate the screen coordinates of the right side of the D3DBitmap.
		float  right = left + (float)m_width;
	
		// Calculate the screen coordinates of the top of the D3DBitmap.
		float  top = (float)(m_sh / 2) - (float)m_posY;
	
		// Calculate the screen coordinates of the bottom of the D3DBitmap.
		float  bottom = top - (float)m_height;
	
		// First triangle.
		VertexData[0].Pos = XMFLOAT3(left, top, 0.0f);  // Top left.
		VertexData[0].Tex = XMFLOAT2(0.0f, 0.0f);
	
		VertexData[1].Pos = XMFLOAT3(right, bottom, 0.0f);  // Bottom right.
		VertexData[1].Tex = XMFLOAT2(1.0f, 1.0f);
	
		VertexData[2].Pos = XMFLOAT3(left, bottom, 0.0f);  // Bottom left.
		VertexData[2].Tex = XMFLOAT2(0.0f, 1.0f);
	
		// Second triangle.
		VertexData[3].Pos = XMFLOAT3(left, top, 0.0f);  // Bottom left.
		VertexData[3].Tex = XMFLOAT2(0.0f, 0.0f);
	
		VertexData[4].Pos = XMFLOAT3(right, top, 0.0f); // Top right.
		VertexData[4].Tex = XMFLOAT2(0.0f, 1.0f);
	
		VertexData[5].Pos = XMFLOAT3(right, bottom, 0.0f);  // Bottom right.
		VertexData[5].Tex = XMFLOAT2(1.0f, 1.0f);
	
		///////////////////////////Index Buffer ////////////////////////////////
	
		// Set up the description of the static vertex buffer.
		D3D11_BUFFER_DESC VertexBufferDesc;
		VertexBufferDesc.Usage               = D3D11_USAGE_DEFAULT;
		VertexBufferDesc.ByteWidth           = sizeof(Vertex) * m_VertexCount;
		VertexBufferDesc.BindFlags           = D3D11_BIND_VERTEX_BUFFER;
		VertexBufferDesc.CPUAccessFlags      = 0;
		VertexBufferDesc.MiscFlags           = 0;
		VertexBufferDesc.StructureByteStride = 0;
	
		// Give the subresource structure a pointer to the vertex data.
		D3D11_SUBRESOURCE_DATA VBO;
		VBO.pSysMem          = &VertexData[0];
		VBO.SysMemPitch      = 0;
		VBO.SysMemSlicePitch = 0;
	
		// Now create the vertex buffer.
		hr = pD3D11Device->CreateBuffer(&VertexBufferDesc, &VBO, &m_pVertexBuffer);
		DebugHR(hr);
	
		/////////////////////////////////Index Buffer ///////////////////////////////////////
	
		// Set up the description of the static index buffer.
		D3D11_BUFFER_DESC IndexBufferDesc;
		IndexBufferDesc.Usage               = D3D11_USAGE_DEFAULT;
		IndexBufferDesc.ByteWidth           = sizeof(UINT) * m_IndexCount;
		IndexBufferDesc.BindFlags           = D3D11_BIND_INDEX_BUFFER;
		IndexBufferDesc.CPUAccessFlags      = 0;
		IndexBufferDesc.MiscFlags           = 0;
		IndexBufferDesc.StructureByteStride = 0;
	
		// Give the subresource structure a pointer to the index data.
		D3D11_SUBRESOURCE_DATA IBO;
		IBO.pSysMem          = &IndexData[0];
		IBO.SysMemPitch      = 0;
		IBO.SysMemSlicePitch = 0;
	
		hr = pD3D11Device->CreateBuffer(&IndexBufferDesc, &IBO, &m_pIndexBuffer);
		DebugHR(hr);
	
		////////////////////////////////MVP Buffer//////////////////////////////////////
	
		D3D11_BUFFER_DESC mvpBufferDesc;
		ZeroMemory(&mvpBufferDesc, sizeof(D3D11_BUFFER_DESC));
		mvpBufferDesc.Usage          = D3D11_USAGE_DEFAULT;
		mvpBufferDesc.ByteWidth      = sizeof(d3d::MatrixBuffer);
		mvpBufferDesc.BindFlags      = D3D11_BIND_CONSTANT_BUFFER;
		mvpBufferDesc.CPUAccessFlags = 0;
		mvpBufferDesc.MiscFlags      = 0;
		hr = pD3D11Device->CreateBuffer(&mvpBufferDesc, NULL, &m_pMVPBuffer);
		DebugHR(hr);
	
	}
Пример #5
0
		void Bitmap::init_buffer(ID3D11Device *pD3D11Device, ID3D11DeviceContext *pD3D11DeviceContext)
		{
			HRESULT hr;

			m_VertexCount = 6;
			m_IndexCount = 6;

			std::vector<Vertex> VertexData(6);
			std::vector<UINT> IndexData(6);

			for (int i = 0; i != m_IndexCount; ++i)
			{
				IndexData[i] = i;
			}
			// Calculate the screen coordinates of the left side of the bitmap.
			float left = (float)((m_sw / 2) * -1) + (float)m_posX;

			// Calculate the screen coordinates of the right side of the bitmap.
			float  right = left + (float)m_width;

			// Calculate the screen coordinates of the top of the bitmap.
			float  top = (float)(m_sh / 2) - (float)m_posY;

			// Calculate the screen coordinates of the bottom of the bitmap.
			float  bottom = top - (float)m_height;

			// First triangle.
			VertexData[0].Pos = XMFLOAT3(left, top, 0.0f);  // Top left.
			VertexData[0].Tex = XMFLOAT2(0.0f, 0.0f);

			VertexData[1].Pos = XMFLOAT3(right, bottom, 0.0f);  // Bottom right.
			VertexData[1].Tex = XMFLOAT2(1.0f, 1.0f);

			VertexData[2].Pos = XMFLOAT3(left, bottom, 0.0f);  // Bottom left.
			VertexData[2].Tex = XMFLOAT2(0.0f, 1.0f);

			// Second triangle.
			VertexData[3].Pos = XMFLOAT3(left, top, 0.0f);  // Bottom left.
			VertexData[3].Tex = XMFLOAT2(0.0f, 0.0f);

			VertexData[4].Pos = XMFLOAT3(right, top, 0.0f); // Top right.
			VertexData[4].Tex = XMFLOAT2(1.0f, 0.0f);

			VertexData[5].Pos = XMFLOAT3(right, bottom, 0.0f);  // Bottom right.
			VertexData[5].Tex = XMFLOAT2(1.0f, 1.0f);

			///////////////////////////Index Buffer ////////////////////////////////

			// Set up the description of the static vertex buffer.
			D3D11_BUFFER_DESC VertexBufferDesc;
			VertexBufferDesc.Usage               = D3D11_USAGE_DEFAULT;
			VertexBufferDesc.ByteWidth           = sizeof(Vertex) * m_VertexCount;
			VertexBufferDesc.BindFlags           = D3D11_BIND_VERTEX_BUFFER;
			VertexBufferDesc.CPUAccessFlags      = 0;
			VertexBufferDesc.MiscFlags           = 0;
			VertexBufferDesc.StructureByteStride = 0;

			// Give the subresource structure a pointer to the vertex data.
			D3D11_SUBRESOURCE_DATA VBO;
			VBO.pSysMem          = &VertexData[0];
			VBO.SysMemPitch      = 0;
			VBO.SysMemSlicePitch = 0;

			// Now create the vertex buffer.
			hr = pD3D11Device->CreateBuffer(&VertexBufferDesc, &VBO, &m_pVertexBuffer);
			DebugHR(hr);

			/////////////////////////////////Index Buffer ///////////////////////////////////////

			// Set up the description of the static index buffer.
			D3D11_BUFFER_DESC IndexBufferDesc;
			IndexBufferDesc.Usage               = D3D11_USAGE_DEFAULT;
			IndexBufferDesc.ByteWidth           = sizeof(UINT) * m_IndexCount;
			IndexBufferDesc.BindFlags           = D3D11_BIND_INDEX_BUFFER;
			IndexBufferDesc.CPUAccessFlags      = 0;
			IndexBufferDesc.MiscFlags           = 0;
			IndexBufferDesc.StructureByteStride = 0;

			// Give the subresource structure a pointer to the index data.
			D3D11_SUBRESOURCE_DATA IBO;
			IBO.pSysMem          = &IndexData[0];
			IBO.SysMemPitch      = 0;
			IBO.SysMemSlicePitch = 0;

			hr = pD3D11Device->CreateBuffer(&IndexBufferDesc, &IBO, &m_pIndexBuffer);
			DebugHR(hr);

			////////////////////////////////MVP Buffer//////////////////////////////////////

			D3D11_BUFFER_DESC mvpBufferDesc;
			ZeroMemory(&mvpBufferDesc, sizeof(D3D11_BUFFER_DESC));
			mvpBufferDesc.Usage          = D3D11_USAGE_DEFAULT;
			mvpBufferDesc.ByteWidth      = sizeof(d3d::MatrixBuffer);
			mvpBufferDesc.BindFlags      = D3D11_BIND_CONSTANT_BUFFER;
			mvpBufferDesc.CPUAccessFlags = 0;
			mvpBufferDesc.MiscFlags      = 0;
			hr = pD3D11Device->CreateBuffer(&mvpBufferDesc, NULL, &m_pMVPBuffer);
			DebugHR(hr);

			// Create a texture sampler state description.
			D3D11_SAMPLER_DESC samplerDesc;
			samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
			samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
			samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
			samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
			samplerDesc.MipLODBias = 0.0f;
			samplerDesc.MaxAnisotropy = 1;
			samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
			samplerDesc.BorderColor[0] = 0;
			samplerDesc.BorderColor[1] = 0;
			samplerDesc.BorderColor[2] = 0;
			samplerDesc.BorderColor[3] = 0;
			samplerDesc.MinLOD = 0;
			samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;

			// Create the texture sampler state.
			hr = pD3D11Device->CreateSamplerState(&samplerDesc, &m_pTexSamplerState);
			DebugHR(hr);
		}
Пример #6
0
void RenderSystem::init_device()
{

	////////////////////////Create buffer desc////////////////////////////
	DXGI_MODE_DESC bufferDesc;
	ZeroMemory(&bufferDesc, sizeof(DXGI_MODE_DESC));
	bufferDesc.Width                   = m_ScreenWidth;
	bufferDesc.Height                  = m_ScreenHeight;
	bufferDesc.RefreshRate.Numerator   = 60;
	bufferDesc.RefreshRate.Denominator = 1;
	bufferDesc.Format                  = DXGI_FORMAT_R8G8B8A8_UNORM;
	bufferDesc.ScanlineOrdering        = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
	bufferDesc.Scaling                 = DXGI_MODE_SCALING_UNSPECIFIED;

	//Create swapChain Desc
	DXGI_SWAP_CHAIN_DESC swapChainDesc;
	ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
	swapChainDesc.BufferDesc         = bufferDesc;
	swapChainDesc.SampleDesc.Count   = 1;
	swapChainDesc.SampleDesc.Quality = 0;
	swapChainDesc.BufferUsage        = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	swapChainDesc.BufferCount        = 1;
	swapChainDesc.OutputWindow       = GetHwnd();
	swapChainDesc.Windowed           = TRUE;
	swapChainDesc.SwapEffect         = DXGI_SWAP_EFFECT_DISCARD;


	/////////////////////Create RenderTargetView//////////////////////////////////////
	HRESULT hr;
	//Create the double buffer chain
	hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE,
		NULL, NULL, NULL, NULL, D3D11_SDK_VERSION,
		&swapChainDesc, &m_pSwapChain, &m_pD3D11Device,
		NULL, &m_pD3D11DeviceContext);
	DebugHR(hr);

	//Create back buffer, buffer also is a texture
	ID3D11Texture2D *pBackBuffer;
	hr = m_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&pBackBuffer);
	hr = m_pD3D11Device->CreateRenderTargetView(pBackBuffer, NULL, &m_pRenderTargetView);
	pBackBuffer->Release();
	DebugHR(hr);
	

	////////////////////////////Create The depth buffer///////////////////////////////////////////////
	D3D11_TEXTURE2D_DESC depthBufferDesc;
	ZeroMemory(&depthBufferDesc, sizeof(depthBufferDesc));
	depthBufferDesc.Width              = m_ScreenWidth;
	depthBufferDesc.Height             = m_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;
	// Create the texture for the depth buffer using the filled out description.
	hr = m_pD3D11Device->CreateTexture2D(&depthBufferDesc, NULL, &m_pDepthStencilBuffer);



	////////////////////Create DepthStencilView///////////////////////////////////////
	D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
	ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc));

	// Set up the depth stencil view description.
	depthStencilViewDesc.Format =  DXGI_FORMAT_D24_UNORM_S8_UINT;
	depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
	depthStencilViewDesc.Texture2D.MipSlice = 0;

	hr = m_pD3D11Device->CreateDepthStencilView(m_pDepthStencilBuffer, &depthStencilViewDesc, &m_pDepthStencilView);
	DebugHR(hr);



    //////////////Create the Depth Stencil State(Enable Depth test)//////////////////////
	D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
	ZeroMemory(&depthStencilDesc, sizeof(depthStencilDesc));

	// Set up the description of the stencil state.
	depthStencilDesc.DepthEnable      = true;
	depthStencilDesc.DepthWriteMask   = D3D11_DEPTH_WRITE_MASK_ALL;
	depthStencilDesc.DepthFunc        = D3D11_COMPARISON_LESS;
	depthStencilDesc.StencilEnable    = true;
	depthStencilDesc.StencilReadMask  = 0xFF;
	depthStencilDesc.StencilWriteMask = 0xFF;

	// Stencil operations if pixel is front-facing.
	depthStencilDesc.FrontFace.StencilFailOp      = D3D11_STENCIL_OP_KEEP;
	depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
	depthStencilDesc.FrontFace.StencilPassOp      = D3D11_STENCIL_OP_KEEP;
	depthStencilDesc.FrontFace.StencilFunc        = D3D11_COMPARISON_ALWAYS;

	// Stencil operations if pixel is back-facing.
	depthStencilDesc.BackFace.StencilFailOp      = D3D11_STENCIL_OP_KEEP;
	depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
	depthStencilDesc.BackFace.StencilPassOp      = D3D11_STENCIL_OP_KEEP;
	depthStencilDesc.BackFace.StencilFunc        = D3D11_COMPARISON_ALWAYS;

	// Create the depth stencil state.
	hr = m_pD3D11Device->CreateDepthStencilState(&depthStencilDesc, &m_pDepthStencilState);
	DebugHR(hr);


	//////////////Create the Depth Stencil Status(Disable Depth test)//////////////////////

	D3D11_DEPTH_STENCIL_DESC depthDisabledStencilDesc;
	ZeroMemory(&depthDisabledStencilDesc, sizeof(depthDisabledStencilDesc));
	// Now create a second depth stencil state which turns off the Z buffer for 2D rendering.  The only difference is 
	// that DepthEnable is set to false, all other parameters are the same as the other depth stencil state.
	depthDisabledStencilDesc.DepthEnable = false;
	depthDisabledStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
	depthDisabledStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
	depthDisabledStencilDesc.StencilEnable = true;
	depthDisabledStencilDesc.StencilReadMask = 0xFF;
	depthDisabledStencilDesc.StencilWriteMask = 0xFF;
	depthDisabledStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
	depthDisabledStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
	depthDisabledStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
	depthDisabledStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
	depthDisabledStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
	depthDisabledStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
	depthDisabledStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
	depthDisabledStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

	// Create the state using the device.
	hr = m_pD3D11Device->CreateDepthStencilState(&depthDisabledStencilDesc, &m_pDepthDisabledStencilState);
	DebugHR(hr);


//////////////////////////////Create the raster mode//////////////////////////////////////////
	D3D11_RASTERIZER_DESC rasterDesc;
	rasterDesc.AntialiasedLineEnable = false;
	rasterDesc.CullMode              = D3D11_CULL_BACK;
	rasterDesc.DepthBias             = 0;
	rasterDesc.DepthBiasClamp        = 0.0f;
	rasterDesc.DepthClipEnable       = true;
	rasterDesc.FillMode              = D3D11_FILL_WIREFRAME;
	rasterDesc.FrontCounterClockwise = false;
	rasterDesc.MultisampleEnable     = false;
	rasterDesc.ScissorEnable         = false;
	rasterDesc.SlopeScaledDepthBias  = 0.0f;
	// Create the rasterizer state from the description we just filled out.
	hr = m_pD3D11Device->CreateRasterizerState(&rasterDesc, &m_pRasterState);
	DebugHR(hr);

	/////////////////////////Video Card information////////////////////////////////////

	unsigned int numModes, i, numerator, denominator, stringLength;
	IDXGIFactory* factory;
	IDXGIAdapter* adapter;
	IDXGISurface *surface;
	DXGI_ADAPTER_DESC adapterDesc;

	// Create a DirectX graphics interface factory.
	CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
	// Use the factory to create an adapter for the primary graphics interface (video card).
	factory->EnumAdapters(0, &adapter);
	adapter->GetDesc(&adapterDesc);
	m_videoCardMemory = (int)(adapterDesc.DedicatedVideoMemory / 1024 / 1024);

	// Convert the name of the video card to a character array and store it.
	m_videoCardInfo = std::wstring(L"Video Card  :") + adapterDesc.Description;

}
Пример #7
0
	void LightShader::Init(ID3D11Device *pD3D11Device, ID3D11DeviceContext *pD3D11DeviceContext, HWND hWnd)
	{

		HRESULT hr;

		D3D11_INPUT_ELEMENT_DESC pInputLayoutDesc;
		std::vector<D3D11_INPUT_ELEMENT_DESC> vInputLayoutDesc;

		pInputLayoutDesc.SemanticName         = "POSITION";
		pInputLayoutDesc.SemanticIndex        = 0;
		pInputLayoutDesc.Format               = DXGI_FORMAT_R32G32B32_FLOAT;
		pInputLayoutDesc.InputSlot            = 0;
		pInputLayoutDesc.AlignedByteOffset    = 0;
		pInputLayoutDesc.InputSlotClass       = D3D11_INPUT_PER_VERTEX_DATA;
		pInputLayoutDesc.InstanceDataStepRate = 0;
		vInputLayoutDesc.push_back(pInputLayoutDesc);

		pInputLayoutDesc.SemanticName         = "TEXCOORD";
		pInputLayoutDesc.SemanticIndex        = 0;
		pInputLayoutDesc.Format               = DXGI_FORMAT_R32G32_FLOAT;
		pInputLayoutDesc.InputSlot            = 0;
		pInputLayoutDesc.AlignedByteOffset    = D3D11_APPEND_ALIGNED_ELEMENT;
		pInputLayoutDesc.InputSlotClass       = D3D11_INPUT_PER_VERTEX_DATA;
		pInputLayoutDesc.InstanceDataStepRate = 0;
		vInputLayoutDesc.push_back(pInputLayoutDesc);

		pInputLayoutDesc.SemanticName         = "NORMAL";
		pInputLayoutDesc.SemanticIndex        = 0;
		pInputLayoutDesc.Format               = DXGI_FORMAT_R32G32B32_FLOAT;
		pInputLayoutDesc.InputSlot            = 0;
		pInputLayoutDesc.AlignedByteOffset    = D3D11_APPEND_ALIGNED_ELEMENT;
		pInputLayoutDesc.InputSlotClass       = D3D11_INPUT_PER_VERTEX_DATA;
		pInputLayoutDesc.InstanceDataStepRate = 0;
		vInputLayoutDesc.push_back(pInputLayoutDesc);


		m_LightShader.init(pD3D11Device, vInputLayoutDesc);
		m_LightShader.attachVS(L"light.vsh", "LightVS", "vs_5_0");
		m_LightShader.attachPS(L"light.psh", "LightPS", "ps_5_0");
		m_LightShader.end();


		D3D11_BUFFER_DESC mvpBufferDesc;
		ZeroMemory(&mvpBufferDesc, sizeof(D3D11_BUFFER_DESC));
		mvpBufferDesc.Usage          = D3D11_USAGE_DEFAULT;
		mvpBufferDesc.ByteWidth      = sizeof(d3d::MatrixBuffer);
		mvpBufferDesc.BindFlags      = D3D11_BIND_CONSTANT_BUFFER;
		mvpBufferDesc.CPUAccessFlags = 0;
		mvpBufferDesc.MiscFlags      = 0;
		hr = pD3D11Device->CreateBuffer(&mvpBufferDesc, NULL, &m_pMVPBuffer);
		DebugHR(hr);

		///////////////////////////////////////Light buffer////////////////////////////////////////
		D3D11_BUFFER_DESC lightBufferDesc;
		ZeroMemory(&lightBufferDesc, sizeof(D3D11_BUFFER_DESC));
		lightBufferDesc.Usage          = D3D11_USAGE_DYNAMIC;
		lightBufferDesc.ByteWidth      = sizeof(LightBuffer);
		lightBufferDesc.BindFlags      = D3D11_BIND_CONSTANT_BUFFER;
		lightBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
		lightBufferDesc.MiscFlags      = 0;

		hr = pD3D11Device->CreateBuffer(&lightBufferDesc, NULL, &m_pLightBuffer);
		DebugHR(hr);

		D3D11_MAPPED_SUBRESOURCE mappedResource;
		// Lock the light constant buffer so it can be written to.
		hr = pD3D11DeviceContext->Map(m_pLightBuffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
		DebugHR(hr);

		// Get a pointer to the data in the constant buffer.
		LightBuffer *dataPtr2 = (LightBuffer*)mappedResource.pData;

		dataPtr2->ambientColor   = XMFLOAT4(0.75f, 0.75f, 0.75f, 1.0f);
		dataPtr2->diffuseColor   = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
		dataPtr2->lightDirection = XMFLOAT3(0.0f, -1.0f, 0.5f);

		pD3D11DeviceContext->Unmap(m_pLightBuffer.Get(), 0);


		//DebugHR(hr);

		// Create a texture sampler state description.
		D3D11_SAMPLER_DESC samplerDesc;
		samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
		samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
		samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
		samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
		samplerDesc.MipLODBias = 0.0f;
		samplerDesc.MaxAnisotropy = 1;
		samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
		samplerDesc.BorderColor[0] = 0;
		samplerDesc.BorderColor[1] = 0;
		samplerDesc.BorderColor[2] = 0;
		samplerDesc.BorderColor[3] = 0;
		samplerDesc.MinLOD = 0;
		samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;

		// Create the texture sampler state.
		hr = pD3D11Device->CreateSamplerState(&samplerDesc, &m_pTexSamplerState);
		//DebugHR(hr);

	}
Пример #8
0
	void Terrain::init_buffer(ID3D11Device *pD3D11Device, ID3D11DeviceContext *pD3D11DeviceContext)
	{
		HRESULT hr;
		auto dir = d3d::TextureMgr::getInstance()->getDir() + "heightmap01.bmp";

		load_heightMap(dir.c_str());

		d3d::Geometry geom;
		d3d::Geometry::MeshData TerrainMesh;
		geom.CreateGrid(160.0, 160.0, m_TerrainWidth, m_TerrainHeight, TerrainMesh);

		m_VertexCount = TerrainMesh.VertexData.size();
		for (int i = 0; i != m_VertexCount; ++i)
			TerrainMesh.VertexData[i].Pos.y = m_HightmapData[i].y / 10.0f;

		calc_normal(TerrainMesh);

		/////////////////////////////Vertex Buffer//////////////////////////////
		m_VertexCount = TerrainMesh.VertexData.size();
		D3D11_BUFFER_DESC TerrainVBDesc;
		TerrainVBDesc.Usage               = D3D11_USAGE_IMMUTABLE;
		TerrainVBDesc.ByteWidth           = sizeof(Vertex) * m_VertexCount;
		TerrainVBDesc.BindFlags           = D3D11_BIND_VERTEX_BUFFER;
		TerrainVBDesc.CPUAccessFlags      = 0;
		TerrainVBDesc.MiscFlags           = 0;
		TerrainVBDesc.StructureByteStride = 0;

		D3D11_SUBRESOURCE_DATA TerrainVBO;
		TerrainVBO.pSysMem = &TerrainMesh.VertexData[0];
		hr = pD3D11Device->CreateBuffer(&TerrainVBDesc, &TerrainVBO, &m_pTerrainVB);
		DebugHR(hr);

		/////////////////////////////Index Buffer//////////////////////////////

		m_IndexCount =  TerrainMesh.IndexData.size();
		D3D11_BUFFER_DESC TerrainIBDesc;
		TerrainIBDesc.Usage               = D3D11_USAGE_IMMUTABLE;
		TerrainIBDesc.ByteWidth           = sizeof(UINT) * m_IndexCount;
		TerrainIBDesc.BindFlags           = D3D11_BIND_INDEX_BUFFER;
		TerrainIBDesc.CPUAccessFlags      = 0;
		TerrainIBDesc.MiscFlags           = 0;
		TerrainIBDesc.StructureByteStride = 0;

		D3D11_SUBRESOURCE_DATA girdIBO;
		girdIBO.pSysMem = &TerrainMesh.IndexData[0];
		hr = pD3D11Device->CreateBuffer(&TerrainIBDesc, &girdIBO, &m_pTerrainIB);
		DebugHR(hr);

		////////////////////////////////Const Buffer//////////////////////////////////////

		D3D11_BUFFER_DESC mvpDesc;
		ZeroMemory(&mvpDesc, sizeof(D3D11_BUFFER_DESC));
		mvpDesc.Usage          = D3D11_USAGE_DEFAULT;
		mvpDesc.ByteWidth      = sizeof(d3d::MatrixBuffer);
		mvpDesc.BindFlags      = D3D11_BIND_CONSTANT_BUFFER;
		mvpDesc.CPUAccessFlags = 0;
		mvpDesc.MiscFlags      = 0;
		hr = pD3D11Device->CreateBuffer(&mvpDesc, NULL, &m_pMVPBuffer);
		DebugHR(hr);



		D3D11_BUFFER_DESC lightDesc;
		ZeroMemory(&mvpDesc, sizeof(D3D11_BUFFER_DESC));
		lightDesc.Usage          = D3D11_USAGE_IMMUTABLE;
		lightDesc.ByteWidth      = sizeof(LightBuffer);
		lightDesc.BindFlags      = D3D11_BIND_CONSTANT_BUFFER;
		lightDesc.CPUAccessFlags = 0;
		lightDesc.MiscFlags      = 0;

		cbLight.ambient  = XMFLOAT4(0.05f, 0.05f, 0.05f, 1.0f);
		cbLight.diffuse  = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
		cbLight.lightDir = XMFLOAT3(-0.5f, -1.0f, 0.0f);
		cbLight.pad      = 0.0f;

		D3D11_SUBRESOURCE_DATA lightVBO;
		lightVBO.pSysMem = &cbLight;
		hr = pD3D11Device->CreateBuffer(&lightDesc, &lightVBO, &m_pLightBuffer);
		DebugHR(hr);

	}