+ return _glMultiDrawArraysIndirect_count(indirect, 1, 0);
+}
+
+typedef struct {
+ GLuint count;
+ GLuint primCount;
+ GLuint firstIndex;
+ GLuint baseVertex;
+ GLuint baseInstance;
+} DrawElementsIndirectCommand;
+
+static inline GLuint
+_glMultiDrawElementsIndirect_count(GLenum type, const GLvoid *indirect, GLsizei drawcount, GLsizei stride) {
+ const DrawElementsIndirectCommand *cmd;
+ GLvoid *temp = 0;
+
+ if (drawcount <= 0) {
+ return 0;
+ }
+
+ if (stride == 0) {
+ stride = sizeof *cmd;
+ }
+
+ GLint draw_indirect_buffer = _glGetInteger(GL_DRAW_INDIRECT_BUFFER_BINDING);
+ if (draw_indirect_buffer) {
+ // Read commands from indirect buffer object
+ GLintptr offset = (GLintptr)indirect;
+ GLsizeiptr size = sizeof *cmd + (drawcount - 1) * stride;
+ GLvoid *temp = malloc(size);
+ if (!temp) {
+ return 0;
+ }
+ memset(temp, 0, size);
+ _glGetBufferSubData(GL_DRAW_INDIRECT_BUFFER, offset, size, temp);
+ indirect = temp;
+ } else {
+ if (!indirect) {
+ return 0;
+ }
+ }
+
+ cmd = (const DrawElementsIndirectCommand *)indirect;
+
+ GLuint count = 0;
+ for (GLsizei i = 0; i < drawcount; ++i) {
+ cmd = (const DrawElementsIndirectCommand *)((const GLbyte *)indirect + i * stride);
+
+ GLuint count_i = _glDrawElementsInstancedBaseVertexBaseInstance_count(
+ cmd->count,
+ type,
+ (GLvoid *)(uintptr_t)(cmd->firstIndex * _gl_type_size(type)),
+ cmd->primCount,
+ cmd->baseVertex,
+ cmd->baseInstance
+ );
+
+ count = std::max(count, count_i);
+ }
+
+ if (draw_indirect_buffer) {
+ free(temp);
+ }
+
+ return count;