45 lines
1.1 KiB
C++
45 lines
1.1 KiB
C++
#include "render/IConstantMapping.h"
|
|||
|
|
|
||
|
|
IConstantMapping::IConstantMapping()
|
||
|
|
:lastSlotId(0)
|
||
|
|
{
|
||
|
|
}
|
||
|
|
IConstantMapping::~IConstantMapping()
|
||
|
|
{
|
||
|
|
}
|
||
|
|
uint32 IConstantMapping::GetAlignedSize()
|
||
|
|
{
|
||
|
|
return (lastSlotId + 1) * HLSL_CONSTANT_SIZE * (mapping.size() > 0 ? 1 : 0);
|
||
|
|
}
|
||
|
|
void IConstantMapping::InsertConstant(const String& name, uint32 numRows, uint32 numCols)
|
||
|
|
{
|
||
|
|
if(!numRows || !numCols) return;
|
||
|
|
|
||
|
|
if(numRows == 1)
|
||
|
|
{
|
||
|
|
//try to insert variable in @white spaces@
|
||
|
|
if(spaces.size() > 0)
|
||
|
|
{
|
||
|
|
for(ConstantCollectionItr it = spaces.begin(); it != spaces.end(); ++it)
|
||
|
|
{
|
||
|
|
if((*it).ColumnCount <= numCols) //found suitable white space! Fill it ^^
|
||
|
|
{
|
||
|
|
mapping.push_back(IConstantMappingData((*it).SlotID, (*it).SlotOffset, 1, numCols));
|
||
|
|
(*it).SlotOffset += numCols;
|
||
|
|
(*it).ColumnCount -= numCols;
|
||
|
|
if((*it).ColumnCount <= 0)
|
||
|
|
spaces.erase(it);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
mapping.push_back(IConstantMappingData(lastSlotId++, 0, 1, numCols));
|
||
|
|
if(numCols < 4)
|
||
|
|
spaces.push_back(IConstantMappingData(lastSlotId, numCols, 1, 4 - numCols));
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
mapping.push_back(IConstantMappingData(lastSlotId, 0, numRows, numCols));
|
||
|
|
lastSlotId+=numRows;
|
||
|
|
}
|
||
|
|
}
|