diff --git a/renderdoc/driver/gl/gl_overlay.cpp b/renderdoc/driver/gl/gl_overlay.cpp index 8f5f4982d..6760a4822 100644 --- a/renderdoc/driver/gl/gl_overlay.cpp +++ b/renderdoc/driver/gl/gl_overlay.cpp @@ -373,26 +373,48 @@ ResourceId GLReplay::RenderOverlay(ResourceId texid, CompType typeHint, DebugOve const DrawcallDescription *draw = m_pDriver->GetDrawcall(eventId); - // readback the index buffer data - std::vector idxs; - uint32_t offset = draw->indexOffset * draw->indexByteWidth; - uint32_t length = 1; - drv.glGetNamedBufferParameterivEXT(idxbuf, eGL_BUFFER_SIZE, (GLint *)&length); - - idxs.resize(length); - drv.glGetBufferSubData(eGL_ELEMENT_ARRAY_BUFFER, offset, - RDCMIN(GLsizeiptr(length - offset), - GLsizeiptr(draw->numIndices) * GLsizeiptr(draw->indexByteWidth)), - &idxs[0]); - - // unbind the real index buffer - drv.glBindBuffer(eGL_ELEMENT_ARRAY_BUFFER, 0); - std::vector patchedIndices; - PatchLineStripIndexBuffer( - draw, draw->indexByteWidth == 1 ? (uint8_t *)idxs.data() : (uint8_t *)NULL, - draw->indexByteWidth == 2 ? (uint16_t *)idxs.data() : (uint16_t *)NULL, - draw->indexByteWidth == 4 ? (uint32_t *)idxs.data() : (uint32_t *)NULL, patchedIndices); + + // readback the index buffer data + if(idxbuf) + { + std::vector idxs; + uint32_t offset = draw->indexOffset * draw->indexByteWidth; + uint32_t length = 1; + drv.glGetNamedBufferParameterivEXT(idxbuf, eGL_BUFFER_SIZE, (GLint *)&length); + + idxs.resize(length); + drv.glGetBufferSubData( + eGL_ELEMENT_ARRAY_BUFFER, offset, + RDCMIN(GLsizeiptr(length - offset), + GLsizeiptr(draw->numIndices) * GLsizeiptr(draw->indexByteWidth)), + &idxs[0]); + + // unbind the real index buffer + drv.glBindBuffer(eGL_ELEMENT_ARRAY_BUFFER, 0); + + uint32_t expectedSize = draw->numIndices * draw->indexByteWidth; + + if(idxs.size() < expectedSize) + { + RDCERR("Index buffer is as large as expected"); + idxs.resize(expectedSize); + } + + PatchLineStripIndexBuffer( + draw, draw->indexByteWidth == 1 ? (uint8_t *)idxs.data() : (uint8_t *)NULL, + draw->indexByteWidth == 2 ? (uint16_t *)idxs.data() : (uint16_t *)NULL, + draw->indexByteWidth == 4 ? (uint32_t *)idxs.data() : (uint32_t *)NULL, patchedIndices); + } + else + { + // generate 'index' list + std::vector idxs; + idxs.resize(draw->numIndices); + for(uint32_t i = 0; i < draw->numIndices; i++) + idxs[i] = i; + PatchLineStripIndexBuffer(draw, NULL, NULL, idxs.data(), patchedIndices); + } GLboolean primRestart = drv.glIsEnabled(eGL_PRIMITIVE_RESTART_FIXED_INDEX); drv.glEnable(eGL_PRIMITIVE_RESTART_FIXED_INDEX);