简体   繁体   中英

OpenGL combination of draw calls

If I have a series of draw calls like this:

void glDrawElementsBaseVertex(GLenum mode = GL_TRIANGLES, GLsizei count = 1188, GLenum type = GL_UNSIGNED_INT, GLvoid* indices = 000354FC, GLint basevertex = 38051)
void glDrawElementsBaseVertex(GLenum mode = GL_TRIANGLES, GLsizei count = 786, GLenum type = GL_UNSIGNED_INT, GLvoid* indices = 0003678C, GLint basevertex = 38847)
void glDrawElementsBaseVertex(GLenum mode = GL_TRIANGLES, GLsizei count = 786, GLenum type = GL_UNSIGNED_INT, GLvoid* indices = 000373D4, GLint basevertex = 39373)
void glDrawElementsBaseVertex(GLenum mode = GL_TRIANGLES, GLsizei count = 786, GLenum type = GL_UNSIGNED_INT, GLvoid* indices = 0003801C, GLint basevertex = 39899)

is it possible it combine them into a single call? The base vertex is incremental by an amount equal to the previous count. The only problem is the index that start in a different position for each call. In my code I created a vector that holds all those starting positions, I record the base vertex of the first call and accumulate the counts. After I am done I call

glDrawElementsBaseVertex(GL_TRIANGLES,
                    numIdx,
                    GL_UNSIGNED_INT,
                    (idx[0]),
                    baseVc);

the problem is that the function is taking idx[0] (containing the indices of the first draw call) and keep incrementing it. What I would like it to do is to make it idx containi some indices from 000354FC to 000354FC + 1188(in hex) and, right after that, the indices from 0003678C to 0003678C + 786(in hex) and so on. What will happen then is that, instead of calling 4 times I call it once with count equal to 1188+786+786+786, base vertex 38051. Is this possible?

I used the glMultiDraw command like this:

vector<GLsizei> numIdx;
    vector<GLint> baseVc;
    vector<void*> idx;
    unsigned int drawCount = 0;
...
drawCount++;
        numIdx.push_back(m_Entries[i].NumIndices);
        baseVc.push_back(m_Entries[i].BaseVertex);
        idx.push_back((void*)(sizeof(unsigned int) * m_Entries[i].BaseIndex));
...
glMultiDrawElementsBaseVertex(GL_TRIANGLES,
                    &numIdx[0],
                    GL_UNSIGNED_INT,
                    &idx[0],
                    drawCount,
                    &baseVc[0]);

I used to draw like this

glDrawElementsBaseVertex(GL_TRIANGLES,
                    m_Entries[i].NumIndices,
                    GL_UNSIGNED_INT,
                    (void*)(sizeof(unsigned int) * m_Entries[i].BaseIndex),
                    m_Entries[i].BaseVertex);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM