CustomDX11API.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "CustomDX11API.h"
  2. #include <Shader.h>
  3. #include <DXBuffer.h>
  4. #include <d3d11.h>
  5. #include "CustomUIDX11PixelShader.h"
  6. #include "CustomUIDX11VertexShader.h"
  7. using namespace Framework;
  8. CustomDX11API::CustomDX11API()
  9. : DirectX11(),
  10. vertexShaderLightBufferIndex(-1)
  11. {}
  12. Framework::DX11VertexShader* CustomDX11API::initializeVertexShader(
  13. unsigned char* byteCode, int size)
  14. {
  15. D3D11_RASTERIZER_DESC rasterDesc;
  16. ZeroMemory(&rasterDesc, sizeof(rasterDesc));
  17. rasterDesc.AntialiasedLineEnable = false;
  18. rasterDesc.CullMode = D3D11_CULL_NONE;
  19. rasterDesc.DepthBiasClamp = 0.0f;
  20. rasterDesc.DepthClipEnable = true;
  21. rasterDesc.FillMode = D3D11_FILL_SOLID;
  22. rasterDesc.FrontCounterClockwise = false;
  23. rasterDesc.MultisampleEnable = false;
  24. rasterDesc.ScissorEnable = false;
  25. rasterDesc.SlopeScaledDepthBias = 0.0f;
  26. ID3D11Device* device;
  27. zContext()->GetDevice(&device);
  28. device->CreateRasterizerState(&rasterDesc, &noCull);
  29. DX11VertexShader* shader = DirectX11::initializeVertexShader(
  30. (unsigned char*)CustomUIDX11VertexShader,
  31. sizeof(CustomUIDX11VertexShader));
  32. vertexShaderLightBufferIndex = shader->getFirstUninitializedBufferIndex();
  33. shader->erstelleConstBuffer(20, vertexShaderLightBufferIndex);
  34. char buffer[8];
  35. *(int*)buffer = 0;
  36. *(float*)(buffer + 4) = 1.f;
  37. shader->füllConstBuffer(buffer, vertexShaderLightBufferIndex, 8);
  38. return shader;
  39. }
  40. Framework::DX11PixelShader* CustomDX11API::initializePixelShader(
  41. unsigned char* byteCode, int size)
  42. {
  43. DX11PixelShader* shader = DirectX11::initializePixelShader(
  44. (unsigned char*)CustomUIDX11PixelShader,
  45. sizeof(CustomUIDX11PixelShader));
  46. return shader;
  47. }
  48. void CustomDX11API::setVertexLightBuffer(Framework::DXBuffer* zBuffer)
  49. {
  50. DX11StructuredBuffer* buffer = dynamic_cast<DX11StructuredBuffer*>(zBuffer);
  51. if (buffer)
  52. {
  53. ID3D11ShaderResourceView* v[1];
  54. v[0] = *buffer;
  55. zContext()->VSSetShaderResources(0, 1, v);
  56. }
  57. }
  58. int CustomDX11API::getVertexShaderLightBufferIndex() const
  59. {
  60. return vertexShaderLightBufferIndex;
  61. }
  62. void CustomDX11API::setCullBack(bool cull)
  63. {
  64. zContext()->RSSetState(cull ? texturRS : noCull);
  65. }