Shader.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "Shader.h"
  2. #include "DXBuffer.h"
  3. using namespace Framework;
  4. // Contents of the Shader class
  5. // Constructor
  6. Shader::Shader()
  7. : ReferenceCounter()
  8. {
  9. type = UNBEKANNT;
  10. constBuffers = new RCArray<DXBuffer>();
  11. }
  12. // Destructor
  13. Shader::~Shader()
  14. {
  15. constBuffers->release();
  16. }
  17. // Deletes a constant buffer
  18. // index: the index of the buffer to be deleted. Buffer 0 cannot
  19. // be deleted while buffer 1 still exists, etc.
  20. bool Shader::removeConstBuffer(int index)
  21. {
  22. if (index < 0) return 0;
  23. bool ok = 1;
  24. constBuffers->set(0, index);
  25. return 1;
  26. }
  27. // Copies data into a constant buffer
  28. // zD3d11Context: The context object used for copying
  29. // data: A pointer to a byte array the size of the buffer
  30. // index: The index of the buffer
  31. // laen: The length of the data in bytes (-1 for the maximum size of the
  32. // buffer)
  33. bool Shader::fillConstBuffer(char* data, int index, int len)
  34. {
  35. if (index < 0 || index > constBuffers->getLastIndex()) return 0;
  36. DXBuffer* zB = constBuffers->z(index);
  37. if (!zB) return 0;
  38. if (len < 0) len = zB->getElementCount() * zB->getElementLength();
  39. zB->setData(data);
  40. zB->copyToGPU(len);
  41. return 1;
  42. }
  43. // Returns the length of a constant buffer
  44. // index: The index of the buffer
  45. int Shader::getConstBufferLaenge(int index) const
  46. {
  47. if (index < 0 || index > constBuffers->getLastIndex()) return 0;
  48. DXBuffer* zB = constBuffers->z(index);
  49. if (!zB) return 0;
  50. return zB->getElementCount() * zB->getElementLength();
  51. }
  52. // Returns the shader type
  53. ShaderType Shader::getType() const
  54. {
  55. return type;
  56. }
  57. //! Returns the index of the first uninitialized buffer
  58. int Shader::getFirstUninitializedBufferIndex() const
  59. {
  60. for (int index = 0; index < constBuffers->getEntryCount(); index++)
  61. {
  62. if (!constBuffers->has(index) || !constBuffers->z(index)) return index;
  63. }
  64. return constBuffers->getEntryCount();
  65. }