| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #include "Shader.h"
- #include "DXBuffer.h"
- using namespace Framework;
- // Contents of the Shader class
- // Constructor
- Shader::Shader()
- : ReferenceCounter()
- {
- type = UNBEKANNT;
- constBuffers = new RCArray<DXBuffer>();
- }
- // Destructor
- Shader::~Shader()
- {
- constBuffers->release();
- }
- // Deletes a constant buffer
- // index: the index of the buffer to be deleted. Buffer 0 cannot
- // be deleted while buffer 1 still exists, etc.
- bool Shader::removeConstBuffer(int index)
- {
- if (index < 0) return 0;
- bool ok = 1;
- constBuffers->set(0, index);
- return 1;
- }
- // Copies data into a constant buffer
- // zD3d11Context: The context object used for copying
- // data: A pointer to a byte array the size of the buffer
- // index: The index of the buffer
- // laen: The length of the data in bytes (-1 for the maximum size of the
- // buffer)
- bool Shader::fillConstBuffer(char* data, int index, int len)
- {
- if (index < 0 || index > constBuffers->getLastIndex()) return 0;
- DXBuffer* zB = constBuffers->z(index);
- if (!zB) return 0;
- if (len < 0) len = zB->getElementCount() * zB->getElementLength();
- zB->setData(data);
- zB->copyToGPU(len);
- return 1;
- }
- // Returns the length of a constant buffer
- // index: The index of the buffer
- int Shader::getConstBufferLaenge(int index) const
- {
- if (index < 0 || index > constBuffers->getLastIndex()) return 0;
- DXBuffer* zB = constBuffers->z(index);
- if (!zB) return 0;
- return zB->getElementCount() * zB->getElementLength();
- }
- // Returns the shader type
- ShaderType Shader::getType() const
- {
- return type;
- }
- //! Returns the index of the first uninitialized buffer
- int Shader::getFirstUninitializedBufferIndex() const
- {
- for (int index = 0; index < constBuffers->getEntryCount(); index++)
- {
- if (!constBuffers->has(index) || !constBuffers->z(index)) return index;
- }
- return constBuffers->getEntryCount();
- }
|