Added support osg::State::drawQuad(..) for number of vertices in quads to uint range rather than just ushort range.

This commit is contained in:
Robert Osfield 2011-06-14 15:48:27 +00:00
parent 5b3eed5dce
commit b6a15b2ef8
2 changed files with 59 additions and 27 deletions

View File

@ -512,8 +512,11 @@ class OSG_EXPORT State : public Referenced, public Observer
_currentPBO = 0; _currentPBO = 0;
} }
typedef std::vector<GLushort> Indices; typedef std::vector<GLushort> IndicesGLushort;
Indices _quadIndices[6]; IndicesGLushort _quadIndicesGLushort[4];
typedef std::vector<GLuint> IndicesGLuint;
IndicesGLuint _quadIndicesGLuint[4];
void drawQuads(GLint first, GLsizei count, GLsizei primCount=0); void drawQuads(GLint first, GLsizei count, GLsizei primCount=0);

View File

@ -1431,38 +1431,67 @@ void State::drawQuads(GLint first, GLsizei count, GLsizei primCount)
unsigned int numQuads = (count/4); unsigned int numQuads = (count/4);
unsigned int numIndices = numQuads * 6; unsigned int numIndices = numQuads * 6;
unsigned int endOfIndices = offsetFirst+numIndices; unsigned int endOfIndices = offsetFirst+numIndices;
Indices& indices = _quadIndices[array];
if (endOfIndices>65536)
{
OSG_NOTICE<<"Warning: State::drawQuads("<<first<<", "<<count<<") too large handle in remapping to ushort glDrawElements."<<std::endl;
endOfIndices = 65536;
}
if (endOfIndices >= indices.size()) if (endOfIndices<65536)
{ {
// we need to expand the _indexArray to be big enough to cope with all the quads required. IndicesGLushort& indices = _quadIndicesGLushort[array];
unsigned int numExistingQuads = indices.size()/6;
unsigned int numRequiredQuads = endOfIndices/6; if (endOfIndices >= indices.size())
indices.reserve(endOfIndices);
for(unsigned int i=numExistingQuads; i<numRequiredQuads; ++i)
{ {
unsigned int base = i*4 + array; // we need to expand the _indexArray to be big enough to cope with all the quads required.
indices.push_back(base); unsigned int numExistingQuads = indices.size()/6;
indices.push_back(base+1); unsigned int numRequiredQuads = endOfIndices/6;
indices.push_back(base+3); indices.reserve(endOfIndices);
for(unsigned int i=numExistingQuads; i<numRequiredQuads; ++i)
indices.push_back(base+1); {
indices.push_back(base+2); unsigned int base = i*4 + array;
indices.push_back(base+3); indices.push_back(base);
indices.push_back(base+1);
// OSG_NOTICE<<" adding quad indices ("<<base<<")"<<std::endl; indices.push_back(base+3);
indices.push_back(base+1);
indices.push_back(base+2);
indices.push_back(base+3);
// OSG_NOTICE<<" adding quad indices ("<<base<<")"<<std::endl;
}
} }
// if (array!=0) return;
// OSG_NOTICE<<" glDrawElements(GL_TRIANGLES, "<<numIndices<<", GL_UNSIGNED_SHORT, "<<&(indices[base])<<")"<<std::endl;
glDrawElementsInstanced(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, &(indices[offsetFirst]), primCount);
} }
else
{
IndicesGLuint& indices = _quadIndicesGLuint[array];
// if (array!=0) return; if (endOfIndices >= indices.size())
{
// we need to expand the _indexArray to be big enough to cope with all the quads required.
unsigned int numExistingQuads = indices.size()/6;
unsigned int numRequiredQuads = endOfIndices/6;
indices.reserve(endOfIndices);
for(unsigned int i=numExistingQuads; i<numRequiredQuads; ++i)
{
unsigned int base = i*4 + array;
indices.push_back(base);
indices.push_back(base+1);
indices.push_back(base+3);
// OSG_NOTICE<<" glDrawElements(GL_TRIANGLES, "<<numIndices<<", GL_UNSIGNED_SHORT, "<<&(indices[base])<<")"<<std::endl; indices.push_back(base+1);
glDrawElementsInstanced(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, &(indices[offsetFirst]), primCount); indices.push_back(base+2);
indices.push_back(base+3);
// OSG_NOTICE<<" adding quad indices ("<<base<<")"<<std::endl;
}
}
// if (array!=0) return;
// OSG_NOTICE<<" glDrawElements(GL_TRIANGLES, "<<numIndices<<", GL_UNSIGNED_SHORT, "<<&(indices[base])<<")"<<std::endl;
glDrawElementsInstanced(GL_TRIANGLES, numIndices, GL_UNSIGNED_INT, &(indices[offsetFirst]), primCount);
}
} }
void State::ModeStack::print(std::ostream& fout) const void State::ModeStack::print(std::ostream& fout) const