#include "Shader.h" #include "DXBuffer.h" using namespace Framework; // Contents of the Shader class // Constructor Shader::Shader() : ReferenceCounter() { type = UNBEKANNT; constBuffers = new RCArray(); } // 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 = (int)zB->getElementCount() * zB->getElementLength(); zB->setData(data, true); 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 (unsigned)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(); }