Skip to content
Snippets Groups Projects
Commit d028d8cc authored by Philip Trettner's avatar Philip Trettner
Browse files

Fixed instance count calculation

parent 3a83cba5
No related branches found
No related tags found
No related merge requests found
...@@ -262,14 +262,22 @@ SharedArrayBuffer VertexArray::getAttributeBuffer(const std::string &name) const ...@@ -262,14 +262,22 @@ SharedArrayBuffer VertexArray::getAttributeBuffer(const std::string &name) const
int VertexArray::getInstanceCount() const int VertexArray::getInstanceCount() const
{ {
auto iCnt = 1; auto isInstanced = false;
auto iCnt = std::numeric_limits<int>::max();
for (auto const &a : mAttributes) for (auto const &a : mAttributes)
{ {
auto eCnt = a.buffer->getElementCount(); auto eCnt = a.buffer->getElementCount();
auto const &aa = a.buffer->getAttributes()[a.locationInBuffer]; 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 int VertexArray::getVertexCount() const
...@@ -287,6 +295,13 @@ void VertexArray::BoundVertexArray::attach(const SharedArrayBuffer &ab) ...@@ -287,6 +295,13 @@ void VertexArray::BoundVertexArray::attach(const SharedArrayBuffer &ab)
if (!isCurrent()) if (!isCurrent())
return; return;
if (!ab)
{
error() << "Trying to attach nullptr as ArrayBuffer";
assert(false);
return;
}
auto const &attrs = ab->getAttributes(); auto const &attrs = ab->getAttributes();
for (auto i = 0u; i < attrs.size(); ++i) for (auto i = 0u; i < attrs.size(); ++i)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment