Introduced new State::drawQuads(..) convinience method to help out with mapping GL 1.x style calls to GLES2.0 compatible calls.
This commit is contained in:
parent
20a5820843
commit
4374ca23f9
@ -477,6 +477,10 @@ class OSG_EXPORT State : public Referenced, public Observer
|
||||
_currentPBO = 0;
|
||||
}
|
||||
|
||||
typedef std::vector<GLushort> Indices;
|
||||
Indices _quadIndices[6];
|
||||
|
||||
void drawQuads(GLint first, GLsizei count, GLsizei primCount=1);
|
||||
|
||||
inline void glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
|
||||
{
|
||||
|
@ -1343,3 +1343,47 @@ void State::updateModelViewAndProjectionMatrixUniforms()
|
||||
_normalMatrixUniform->set(normalMatrix);
|
||||
}
|
||||
}
|
||||
|
||||
void State::drawQuads(GLint first, GLsizei count, GLsizei primCount)
|
||||
{
|
||||
// osg::notify(osg::NOTICE)<<"State::drawQuads("<<first<<", "<<count<<")"<<std::endl;
|
||||
|
||||
unsigned int array = first % 4;
|
||||
unsigned int offsetFirst = ((first-array) / 4) * 6;
|
||||
unsigned int numQuads = (count/4);
|
||||
unsigned int numIndices = numQuads * 6;
|
||||
unsigned int endOfIndices = offsetFirst+numIndices;
|
||||
Indices& indices = _quadIndices[array];
|
||||
if (endOfIndices>65536)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Warning: State::drawQuads("<<first<<", "<<count<<") too large handle in remapping to ushort glDrawElements."<<std::endl;
|
||||
endOfIndices = 65536;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
indices.push_back(base+1);
|
||||
indices.push_back(base+2);
|
||||
indices.push_back(base+3);
|
||||
|
||||
// osg::notify(osg::NOTICE)<<" adding quad indices ("<<base<<")"<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// if (array!=0) return;
|
||||
|
||||
// osg::notify(osg::NOTICE)<<" glDrawElements(GL_TRIANGLES, "<<numIndices<<", GL_UNSIGNED_SHORT, "<<&(indices[base])<<")"<<std::endl;
|
||||
glDrawElementsInstanced(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, &(indices[offsetFirst]), primCount);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user