This repository has been archived on 2024-03-22. You can view files and clone it, but cannot push or open issues or pull requests.
DX11Starter/Sky.cpp
2022-04-03 18:18:42 -04:00

51 lines
1.5 KiB
C++

#include "Sky.h"
Sky::Sky(
std::shared_ptr<Mesh> _mesh,
std::shared_ptr<SimpleVertexShader> _vertexShader,
std::shared_ptr<SimplePixelShader> _pixelShader,
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> _cubemap,
Microsoft::WRL::ComPtr<ID3D11SamplerState> _sampler,
Microsoft::WRL::ComPtr<ID3D11Device> _device)
{
mesh = _mesh;
cubemap = _cubemap;
sampler = _sampler;
vertexShader = _vertexShader;
pixelShader = _pixelShader;
D3D11_RASTERIZER_DESC rDesc = {};
rDesc.FillMode = D3D11_FILL_SOLID;
rDesc.CullMode = D3D11_CULL_FRONT;
_device->CreateRasterizerState(&rDesc, rasterizerState.GetAddressOf());
D3D11_DEPTH_STENCIL_DESC dDesc = {};
dDesc.DepthEnable = true;
dDesc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
_device->CreateDepthStencilState(&dDesc, depthState.GetAddressOf());
}
Sky::~Sky()
{
}
void Sky::Draw(Microsoft::WRL::ComPtr<ID3D11DeviceContext> _context, std::shared_ptr<Camera> _camera)
{
_context->RSSetState(rasterizerState.Get());
_context->OMSetDepthStencilState(depthState.Get(), 0);
vertexShader->SetMatrix4x4("view", _camera->GetViewMatrix());
vertexShader->SetMatrix4x4("projection", _camera->GetProjectionMatrix());
vertexShader->CopyAllBufferData();
vertexShader->SetShader();
pixelShader->SetShaderResourceView("SkyTexture", cubemap.Get());
pixelShader->SetSamplerState("Sampler", sampler.Get());
pixelShader->CopyAllBufferData();
pixelShader->SetShader();
mesh->Draw();
_context->RSSetState(0);
_context->OMSetDepthStencilState(0, 0);
}