本文整理汇总了C++中Waves::TriangleCount方法的典型用法代码示例。如果您正苦于以下问题:C++ Waves::TriangleCount方法的具体用法?C++ Waves::TriangleCount怎么用?C++ Waves::TriangleCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Waves
的用法示例。
在下文中一共展示了Waves::TriangleCount方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BuildWaveGeometryBuffers
void BlendApp::BuildWaveGeometryBuffers()
{
// Create the vertex buffer. Note that we allocate space only, as
// we will be updating the data every time step of the simulation.
D3D11_BUFFER_DESC vbd;
vbd.Usage = D3D11_USAGE_DYNAMIC;
vbd.ByteWidth = sizeof(Vertex) * mWaves.VertexCount();
vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vbd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
vbd.MiscFlags = 0;
HR(md3dDevice->CreateBuffer(&vbd, 0, &mWavesVB));
// Create the index buffer. The index buffer is fixed, so we only
// need to create and set once.
std::vector<UINT> indices(3*mWaves.TriangleCount()); // 3 indices per face
// Iterate over each quad.
UINT m = mWaves.RowCount();
UINT n = mWaves.ColumnCount();
int k = 0;
for(UINT i = 0; i < m-1; ++i)
{
for(DWORD j = 0; j < n-1; ++j)
{
indices[k] = i*n+j;
indices[k+1] = i*n+j+1;
indices[k+2] = (i+1)*n+j;
indices[k+3] = (i+1)*n+j;
indices[k+4] = i*n+j+1;
indices[k+5] = (i+1)*n+j+1;
k += 6; // next quad
}
}
D3D11_BUFFER_DESC ibd;
ibd.Usage = D3D11_USAGE_IMMUTABLE;
ibd.ByteWidth = sizeof(UINT) * indices.size();
ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
ibd.CPUAccessFlags = 0;
ibd.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA iinitData;
iinitData.pSysMem = &indices[0];
HR(md3dDevice->CreateBuffer(&ibd, &iinitData, &mWavesIB));
}
示例2: BuildWavesBuffers
void LightDemo::BuildWavesBuffers()
{
// Create the vertex buffer. Note that we allocate space only, as
// we will be updating the data every time step of the simulation.
D3D11_BUFFER_DESC vbd;
vbd.Usage = D3D11_USAGE_DYNAMIC; //Dynamic instead of Immutable
vbd.ByteWidth = sizeof(Vertex) * m_waves.VertexCount();
vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vbd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; //Write access since it's dynamic
vbd.MiscFlags = 0;
//No data is passed because we will set it at each frame
HR(m_dxDevice->CreateBuffer(&vbd, 0, m_wavesVB.GetAddressOf()));
// Create the index buffer. The index buffer is fixed, so we only
// need to create and set once.
std::vector<uint32> indices(3*m_waves.TriangleCount()); // 3 indices per face
// Iterate over each quad.
uint32 m = m_waves.RowCount();
uint32 n = m_waves.ColumnCount();
int k = 0;
for(uint32 i = 0; i < m-1; ++i)
{
for(uint32 j = 0; j < n-1; ++j)
{
indices[k] = i*n+j;
indices[k+1] = i*n+j+1;
indices[k+2] = (i+1)*n+j;
indices[k+3] = (i+1)*n+j;
indices[k+4] = i*n+j+1;
indices[k+5] = (i+1)*n+j+1;
k += 6; // next quad
}
}
D3D11_BUFFER_DESC ibd;
ibd.Usage = D3D11_USAGE_IMMUTABLE;
ibd.ByteWidth = sizeof(uint32) * indices.size();
ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
ibd.CPUAccessFlags = 0;
ibd.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA iinitData;
iinitData.pSysMem = &indices[0];
HR(m_dxDevice->CreateBuffer(&ibd, &iinitData, m_wavesIB.GetAddressOf()));
}
示例3: DrawScene
void BlendApp::DrawScene()
{
md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::Silver));
md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);
md3dImmediateContext->IASetInputLayout(mInputLayout);
md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
float blendFactor[] = {0.0f, 0.0f, 0.0f, 0.0f};
UINT stride = sizeof(Vertex);
UINT offset = 0;
XMMATRIX view = XMLoadFloat4x4(&mView);
XMMATRIX proj = XMLoadFloat4x4(&mProj);
XMMATRIX viewProj = view*proj;
mConstStruct.gEyePosW = mEyePosW;
md3dImmediateContext->IASetVertexBuffers(0, 1, &mBoxVB, &stride, &offset);
md3dImmediateContext->IASetIndexBuffer(mBoxIB, DXGI_FORMAT_R32_UINT, 0);
// Set per object constants.
XMMATRIX world = XMLoadFloat4x4(&mBoxWorld);
XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world);
XMMATRIX worldViewProj = world*view*proj;
mConstStruct.gWorld = XMMatrixTranspose(world);
mConstStruct.gWorldInvTranspose = XMMatrixTranspose(worldInvTranspose);
mConstStruct.gWorldViewProj = XMMatrixTranspose(worldViewProj);
mConstStruct.gTexTransform = XMMatrixTranspose(XMMatrixIdentity());
md3dImmediateContext->UpdateSubresource(mConstBuffer, 0, NULL, &mConstStruct, 0, 0);
md3dImmediateContext->VSSetShader(mVertexShader, NULL, 0);
md3dImmediateContext->VSSetConstantBuffers(0, 1, &mConstBuffer);
md3dImmediateContext->PSSetShader(mPixelShader, NULL, 0);
md3dImmediateContext->PSSetConstantBuffers(0, 1, &mConstBuffer);
md3dImmediateContext->RSSetState(RenderStates::NoCullRS);
md3dImmediateContext->PSSetShaderResources(0, 1, &mBoxMapSRV);
md3dImmediateContext->DrawIndexed(36, 0, 0);
// Restore default render state.
md3dImmediateContext->RSSetState(0);
//
// Draw the hills.
//
md3dImmediateContext->IASetVertexBuffers(0, 1, &mLandVB, &stride, &offset);
md3dImmediateContext->IASetIndexBuffer(mLandIB, DXGI_FORMAT_R32_UINT, 0);
// Set per object constants.
world = XMLoadFloat4x4(&mLandWorld);
worldInvTranspose = MathHelper::InverseTranspose(world);
worldViewProj = world*view*proj;
mConstStruct.gWorld = XMMatrixTranspose(world);
mConstStruct.gWorldInvTranspose = XMMatrixTranspose(worldInvTranspose);
mConstStruct.gWorldViewProj = XMMatrixTranspose(worldViewProj);
mConstStruct.gTexTransform = XMMatrixTranspose(XMLoadFloat4x4(&mGrassTexTransform));
mConstStruct.gMaterial = mLandMat;
md3dImmediateContext->PSSetShaderResources(0, 1, &mGrassMapSRV);
md3dImmediateContext->UpdateSubresource(mConstBuffer, 0, NULL, &mConstStruct, 0, 0);
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 = world*view*proj;
mConstStruct.gWorld = XMMatrixTranspose(world);
mConstStruct.gWorldInvTranspose = XMMatrixTranspose(worldInvTranspose);
mConstStruct.gWorldViewProj = XMMatrixTranspose(worldViewProj);
mConstStruct.gTexTransform = XMMatrixTranspose(XMLoadFloat4x4(&mWaterTexTransform));
mConstStruct.gMaterial = mWavesMat;
md3dImmediateContext->PSSetShaderResources(0, 1, &mWavesMapSRV);
md3dImmediateContext->UpdateSubresource(mConstBuffer, 0, NULL, &mConstStruct, 0, 0);
md3dImmediateContext->OMSetBlendState(RenderStates::TransparentBS, blendFactor, 0xffffffff);
md3dImmediateContext->DrawIndexed(3 * mWaves.TriangleCount(), 0, 0);
// Restore default blend state
md3dImmediateContext->OMSetBlendState(0, blendFactor, 0xffffffff);
HR(mSwapChain->Present(0, 0));
}
示例4: DrawScene
void LightDemo::DrawScene()
{
m_dxImmediateContext->ClearRenderTargetView(m_renderTargetView.Get(), reinterpret_cast<const float*>(&oc::Colors::LightSteelBlue));
m_dxImmediateContext->ClearDepthStencilView(m_depthStencilView.Get(), D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);
m_dxImmediateContext->IASetInputLayout(m_inputLayout.Get());
m_dxImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
uint32 stride = sizeof(Vertex);
uint32 offset = 0;
// Set constants
XMMATRIX view = XMLoadFloat4x4(&m_view);
XMMATRIX proj = XMLoadFloat4x4(&m_proj);
XMMATRIX viewProj = view*proj;
// Set per frame constants.
m_fxDirLight->SetRawValue(&m_dirLight, 0, sizeof(m_dirLight));
m_fxPointLight->SetRawValue(&m_pointLight, 0, sizeof(m_pointLight));
m_fxSpotLight->SetRawValue(&m_spotLight, 0, sizeof(m_spotLight));
m_fxEyePosW->SetRawValue(&m_camPosition, 0, sizeof(m_camPosition));
D3DX11_TECHNIQUE_DESC techDesc;
m_tech->GetDesc(&techDesc);
for(uint32 p = 0; p < techDesc.Passes; ++p)
{
//Draw the land
m_dxImmediateContext->IASetVertexBuffers(0, 1, m_landVB.GetAddressOf(), &stride, &offset);
m_dxImmediateContext->IASetIndexBuffer(m_landIB.Get(), DXGI_FORMAT_R32_UINT, 0);
//Set per object constants
XMMATRIX world = XMLoadFloat4x4(&m_landWorld);
XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world);
XMMATRIX worldViewProj = world*viewProj;
m_fxWorld->SetMatrix(reinterpret_cast<float*>(&world));
m_fxWorldInvTranspose->SetMatrix(reinterpret_cast<float*>(&worldInvTranspose));
m_fxWorldViewProj->SetMatrix(reinterpret_cast<float*>(&worldViewProj));
m_fxMaterial->SetRawValue(&m_landMat, 0, sizeof(m_landMat));
m_tech->GetPassByIndex(p)->Apply(0, m_dxImmediateContext.Get());
m_dxImmediateContext->DrawIndexed(m_landIndexCount, 0, 0);
//Draw the wave
m_dxImmediateContext->IASetVertexBuffers(0, 1, m_wavesVB.GetAddressOf(), &stride, &offset);
m_dxImmediateContext->IASetIndexBuffer(m_wavesIB.Get(), DXGI_FORMAT_R32_UINT, 0);
world = XMLoadFloat4x4(&m_wavesWorld);
worldInvTranspose = MathHelper::InverseTranspose(world);
worldViewProj = world*viewProj;
m_fxWorld->SetMatrix(reinterpret_cast<float*>(&world));
m_fxWorldInvTranspose->SetMatrix(reinterpret_cast<float*>(&worldInvTranspose));
m_fxWorldViewProj->SetMatrix(reinterpret_cast<float*>(&worldViewProj));
m_fxMaterial->SetRawValue(&m_wavesMat, 0, sizeof(m_wavesMat));
m_tech->GetPassByIndex(p)->Apply(0, m_dxImmediateContext.Get());
m_dxImmediateContext->DrawIndexed(3*m_waves.TriangleCount(), 0, 0);
}
HR(m_swapChain->Present(0, 0));
}
示例5: DrawScene
//.........这里部分代码省略.........
Effects::BasicFX->SetFogColor(oc::Colors::Silver);
Effects::BasicFX->SetFogStart(25.0f);
Effects::BasicFX->SetFogRange(200.0f);
ID3DX11EffectTechnique* boxTech = nullptr;
ID3DX11EffectTechnique* landAndWavesTech = nullptr;
switch(m_renderOptions)
{
case RenderOptions::Lighting:
boxTech = Effects::BasicFX->Light3Tech;
landAndWavesTech = Effects::BasicFX->Light3Tech;
break;
case RenderOptions::Textures:
boxTech = Effects::BasicFX->Light3TexAlphaClipTech;
landAndWavesTech = Effects::BasicFX->Light3TexTech;
break;
case RenderOptions::TexturesAndFog:
boxTech = Effects::BasicFX->Light3TexAlphaClipFogTech;
landAndWavesTech = Effects::BasicFX->Light3TexFogTech;
break;
}
D3DX11_TECHNIQUE_DESC techDesc;
boxTech->GetDesc(&techDesc);
for(uint32 p = 0; p < techDesc.Passes; ++p)
{
//Draw the box with alpha clipping
m_dxImmediateContext->IASetVertexBuffers(0, 1, m_boxVB.GetAddressOf(), &stride, &offset);
m_dxImmediateContext->IASetIndexBuffer(m_boxIB.Get(), DXGI_FORMAT_R32_UINT, 0);
// Set per object constants.
XMMATRIX world = XMLoadFloat4x4(&m_boxWorld);
XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world);
XMMATRIX worldViewProj = world*view*proj;
Effects::BasicFX->SetWorld(world);
Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose);
Effects::BasicFX->SetWorldViewProj(worldViewProj);
Effects::BasicFX->SetTexTransform(XMMatrixIdentity());
Effects::BasicFX->SetMaterial(m_boxMat);
Effects::BasicFX->SetDiffuseMap(m_boxMapSRV.Get());
//Disable backface culling to render the crate properly (else the back of the crate won't be rendered)
m_dxImmediateContext->RSSetState(RenderStates::NoCullRS.Get());
boxTech->GetPassByIndex(p)->Apply(0, m_dxImmediateContext.Get());
m_dxImmediateContext->DrawIndexed(36, 0, 0);
// Restore default render state.
m_dxImmediateContext->RSSetState(0);
}
//Draw the hills and water with texture and fog (no alpha clipping needed)
landAndWavesTech->GetDesc(&techDesc);
for(uint32 p = 0; p < techDesc.Passes; ++p)
{
//Draw the land
m_dxImmediateContext->IASetVertexBuffers(0, 1, m_landVB.GetAddressOf(), &stride, &offset);
m_dxImmediateContext->IASetIndexBuffer(m_landIB.Get(), DXGI_FORMAT_R32_UINT, 0);
//Set per object constants
XMMATRIX world = XMLoadFloat4x4(&m_landWorld);
XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world);
XMMATRIX worldViewProj = world*viewProj;
Effects::BasicFX->SetWorld(world);
Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose);
Effects::BasicFX->SetWorldViewProj(worldViewProj);
Effects::BasicFX->SetTexTransform(XMLoadFloat4x4(&m_grassTexTransform));
Effects::BasicFX->SetMaterial(m_landMat);
Effects::BasicFX->SetDiffuseMap(m_grassMapSRV.Get());
landAndWavesTech->GetPassByIndex(p)->Apply(0, m_dxImmediateContext.Get());
m_dxImmediateContext->DrawIndexed(m_landIndexCount, 0, 0);
//Draw the wave
m_dxImmediateContext->IASetVertexBuffers(0, 1, m_wavesVB.GetAddressOf(), &stride, &offset);
m_dxImmediateContext->IASetIndexBuffer(m_wavesIB.Get(), DXGI_FORMAT_R32_UINT, 0);
world = XMLoadFloat4x4(&m_wavesWorld);
worldInvTranspose = MathHelper::InverseTranspose(world);
worldViewProj = world*viewProj;
Effects::BasicFX->SetWorld(world);
Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose);
Effects::BasicFX->SetWorldViewProj(worldViewProj);
Effects::BasicFX->SetTexTransform(XMLoadFloat4x4(&m_waterTexTransform));
Effects::BasicFX->SetMaterial(m_wavesMat);
Effects::BasicFX->SetDiffuseMap(m_wavesMapSRV.Get());
m_dxImmediateContext->OMSetBlendState(RenderStates::TransparentBS.Get(), blendFactor, 0xffffffff);
landAndWavesTech->GetPassByIndex(p)->Apply(0, m_dxImmediateContext.Get());
m_dxImmediateContext->DrawIndexed(3*m_waves.TriangleCount(), 0, 0);
// Restore default blend state
m_dxImmediateContext->OMSetBlendState(0, blendFactor, 0xffffffff);
}
HR(m_swapChain->Present(0, 0));
}
示例6: 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));
}