当前位置: 首页>>代码示例>>C++>>正文


C++ ConstantBuffer::Buffer方法代码示例

本文整理汇总了C++中ConstantBuffer::Buffer方法的典型用法代码示例。如果您正苦于以下问题:C++ ConstantBuffer::Buffer方法的具体用法?C++ ConstantBuffer::Buffer怎么用?C++ ConstantBuffer::Buffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConstantBuffer的用法示例。


在下文中一共展示了ConstantBuffer::Buffer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DrawScene

void HillsApp::DrawScene()
{
	md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::LightSteelBlue));
	md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);

	md3dImmediateContext->IASetInputLayout(mInputLayout);
    md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	md3dImmediateContext->PSSetShader(mPixelShader, NULL, 0);
	md3dImmediateContext->VSSetShader(mVertexShader, NULL, 0);
 
	UINT stride = sizeof(Vertex);
    UINT offset = 0;
    md3dImmediateContext->IASetVertexBuffers(0, 1, &mVB, &stride, &offset);
	md3dImmediateContext->IASetIndexBuffer(mIB, DXGI_FORMAT_R32_UINT, 0);

	// Set constants
	
	XMMATRIX view  = XMLoadFloat4x4(&mView);
	XMMATRIX proj  = XMLoadFloat4x4(&mProj);
	XMMATRIX world = XMLoadFloat4x4(&mGridWorld);
	XMMATRIX worldViewProj = XMMatrixTranspose(world*view*proj);


	cbPerObject mPerObjectCB;


	XMStoreFloat4x4(&mPerObjectCB.mWorldViewProj, worldViewProj);
	mObjectConstantBuffer.Data = mPerObjectCB;
	mObjectConstantBuffer.ApplyChanges(md3dImmediateContext);

	auto buffer = mObjectConstantBuffer.Buffer();
	md3dImmediateContext->VSSetConstantBuffers(0, 1, &buffer);

	// Set raster state
	md3dImmediateContext->RSSetState(mRasterState);

	// Draw
	md3dImmediateContext->DrawIndexed(mGridIndexCount, 0, 0);
	HR(mSwapChain->Present(0, 0));
}
开发者ID:neropsys,项目名称:D3D11CodeSet,代码行数:40,代码来源:HillsDemo.cpp

示例2: DrawScene

void LightingApp::DrawScene()
{
	md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::LightSteelBlue));
	md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);

	md3dImmediateContext->IASetInputLayout(mInputLayout);
	md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	md3dImmediateContext->PSSetShader(mPixelShader, NULL, 0);
	md3dImmediateContext->VSSetShader(mVertexShader, NULL, 0);

	UINT stride = sizeof(Vertex);
	UINT offset = 0;

	XMMATRIX view = XMLoadFloat4x4(&mView);
	XMMATRIX proj = XMLoadFloat4x4(&mProj);
	XMMATRIX viewProj = view*proj;

	// Set per frame constants.
	mFrameConstantBuffer.Data.mDirLight = mDirLight;
	mFrameConstantBuffer.Data.mPointLight = mPointLight;
	mFrameConstantBuffer.Data.mSpotLight = mSpotLight;
	mFrameConstantBuffer.Data.mEyePosW = mEyePosW;

	//
	// Draw the hills.
	//
	md3dImmediateContext->IASetVertexBuffers(0, 1, &mLandVB, &stride, &offset);
	md3dImmediateContext->IASetIndexBuffer(mLandIB, DXGI_FORMAT_R32_UINT, 0);

	// Set per object constants.
	XMMATRIX world = XMLoadFloat4x4(&mLandWorld);
	XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world);
	XMMATRIX worldViewProj = XMMatrixTranspose(world*view*proj);

	mObjectConstantBuffer.Data.mWorld = mLandWorld;
	XMStoreFloat4x4(&mObjectConstantBuffer.Data.mWorldInvTranspose, worldInvTranspose);
	XMStoreFloat4x4(&mObjectConstantBuffer.Data.mWorldViewProj, worldViewProj);
	mObjectConstantBuffer.Data.mMaterial = mLandMat;

	mObjectConstantBuffer.ApplyChanges(md3dImmediateContext);
	mFrameConstantBuffer.ApplyChanges(md3dImmediateContext);

	ID3D11Buffer* buffer[2] = { mObjectConstantBuffer.Buffer(), mFrameConstantBuffer.Buffer() };
	md3dImmediateContext->VSSetConstantBuffers(0, 1, &buffer[0]);
	md3dImmediateContext->PSSetConstantBuffers(0, 2, buffer);


	md3dImmediateContext->DrawIndexed(mLandIndexCount, 0, 0);

	//
	// Draw the waves.
	//
	md3dImmediateContext->IASetVertexBuffers(0, 1, &mWavesVB, &stride, &offset);
	md3dImmediateContext->IASetIndexBuffer(mWavesIB, DXGI_FORMAT_R32_UINT, 0);

	// Set per object constants.
	world = XMLoadFloat4x4(&mWavesWorld);
	worldInvTranspose = MathHelper::InverseTranspose(world);
	worldViewProj = XMMatrixTranspose(world*view*proj);

	mObjectConstantBuffer.Data.mWorld = mWavesWorld;
	XMStoreFloat4x4(&mObjectConstantBuffer.Data.mWorldInvTranspose, worldInvTranspose);
	XMStoreFloat4x4(&mObjectConstantBuffer.Data.mWorldViewProj, worldViewProj);
	mObjectConstantBuffer.Data.mMaterial = mWavesMat;

	mObjectConstantBuffer.ApplyChanges(md3dImmediateContext);
	mFrameConstantBuffer.ApplyChanges(md3dImmediateContext);

	md3dImmediateContext->VSSetConstantBuffers(0, 1, &buffer[0]);
	md3dImmediateContext->PSSetConstantBuffers(0, 2, buffer);

	md3dImmediateContext->DrawIndexed(3 * mWaves.TriangleCount(), 0, 0);


	HR(mSwapChain->Present(0, 0));
}
开发者ID:neropsys,项目名称:D3D11CodeSet,代码行数:76,代码来源:LightingDemo.cpp


注:本文中的ConstantBuffer::Buffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。