Commit d028d8cc authored by Philip Trettner's avatar Philip Trettner

Fixed instance count calculation

parent 3a83cba5
......@@ -262,14 +262,22 @@ SharedArrayBuffer VertexArray::getAttributeBuffer(const std::string &name) const
int VertexArray::getInstanceCount() const
{
auto iCnt = 1;
auto isInstanced = false;
auto iCnt = std::numeric_limits<int>::max();
for (auto const &a : mAttributes)
{
auto eCnt = a.buffer->getElementCount();
auto const &aa = a.buffer->getAttributes()[a.locationInBuffer];
iCnt = std::max(iCnt, (int)(aa.divisor * eCnt));
if (aa.divisor > 0)
{
isInstanced = true;
// in order to not sample out of bounds:
// at most divisor * |element| instances
iCnt = std::min(iCnt, (int)(aa.divisor * eCnt));
}
}
return iCnt;
return isInstanced ? iCnt : 1;
}
int VertexArray::getVertexCount() const
......@@ -287,6 +295,13 @@ void VertexArray::BoundVertexArray::attach(const SharedArrayBuffer &ab)
if (!isCurrent())
return;
if (!ab)
{
error() << "Trying to attach nullptr as ArrayBuffer";
assert(false);
return;
}
auto const &attrs = ab->getAttributes();
for (auto i = 0u; i < attrs.size(); ++i)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment