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;
}
typedef std::vector<GLushort> Indices;
Indices _quadIndices[6];
typedef std::vector<GLushort> IndicesGLushort;
IndicesGLushort _quadIndicesGLushort[4];
typedef std::vector<GLuint> IndicesGLuint;
IndicesGLuint _quadIndicesGLuint[4];
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 numIndices = numQuads * 6;
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.
unsigned int numExistingQuads = indices.size()/6;
unsigned int numRequiredQuads = endOfIndices/6;
indices.reserve(endOfIndices);
for(unsigned int i=numExistingQuads; i<numRequiredQuads; ++i)
IndicesGLushort& indices = _quadIndicesGLushort[array];
if (endOfIndices >= indices.size())
{
unsigned int base = i*4 + array;
indices.push_back(base);
indices.push_back(base+1);
indices.push_back(base+3);
// 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);
indices.push_back(base+1);
indices.push_back(base+2);
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;
// 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;
glDrawElementsInstanced(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, &(indices[offsetFirst]), primCount);
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_INT, &(indices[offsetFirst]), primCount);
}
}
void State::ModeStack::print(std::ostream& fout) const