CubeRenderer.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #include "Direct3DBase.h"
  3. #include <d3d11.h>
  4. #include <mutex>
  5. struct ModelViewProjectionConstantBuffer
  6. {
  7. DirectX::XMFLOAT4X4 model;
  8. DirectX::XMFLOAT4X4 view;
  9. DirectX::XMFLOAT4X4 projection;
  10. };
  11. struct Vertex //Overloaded Vertex Structure
  12. {
  13. Vertex(){}
  14. Vertex(float x, float y, float z,
  15. float u, float v)
  16. : pos(x,y,z), texCoord(u, v){}
  17. DirectX::XMFLOAT3 pos;
  18. DirectX::XMFLOAT2 texCoord;
  19. };
  20. // This class renders a simple spinning cube.
  21. ref class CubeRenderer sealed : public Direct3DBase
  22. {
  23. public:
  24. CubeRenderer();
  25. // Direct3DBase methods.
  26. virtual void CreateDeviceResources() override;
  27. virtual void CreateWindowSizeDependentResources() override;
  28. virtual void Render() override;
  29. // Method for updating time-dependent objects.
  30. void Update(float timeTotal, float timeDelta);
  31. void CreateTextureFromByte(byte * buffer,int width,int height);
  32. private:
  33. void Render(Microsoft::WRL::ComPtr<ID3D11RenderTargetView> renderTargetView, Microsoft::WRL::ComPtr<ID3D11DepthStencilView> depthStencilView);
  34. bool m_loadingComplete;
  35. Microsoft::WRL::ComPtr<ID3D11InputLayout> m_inputLayout;
  36. Microsoft::WRL::ComPtr<ID3D11Buffer> m_vertexBuffer;
  37. Microsoft::WRL::ComPtr<ID3D11Buffer> m_indexBuffer;
  38. Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vertexShader;
  39. Microsoft::WRL::ComPtr<ID3D11PixelShader> m_pixelShader;
  40. Microsoft::WRL::ComPtr<ID3D11Buffer> m_constantBuffer;
  41. Microsoft::WRL::ComPtr<ID3D11Texture2D> m_texture;
  42. Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_SRV;
  43. Microsoft::WRL::ComPtr<ID3D11SamplerState> m_cubesTexSamplerState;
  44. uint32 m_indexCount;
  45. ModelViewProjectionConstantBuffer m_constantBufferData;
  46. std::mutex m_mutex;
  47. Microsoft::WRL::ComPtr<ID3D11BlendState> m_transparency;
  48. Microsoft::WRL::ComPtr<ID3D11RasterizerState> m_CCWcullMode;
  49. Microsoft::WRL::ComPtr<ID3D11RasterizerState> m_CWcullMode;
  50. };