KhronosGroup / KhronosGroup/SPIRV-Cross

GLSL: How to add extra offset gl_VertexIndex?

Open
#1,875 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
GLSL
Stars
2.5k
Forks
713
Avg merge
2d 18h
Merged PRs (30d)
16

Description

There is a workaround for "baseVertex" when opengl doesn't support glDrawElementsInstancedBaseVertex by adding an extra offset to the vertex buffer:

```
Buffer vertexBuffers[NUM_VERTEX_BUFFER_SLOTS];
int vertexBufferOffsets[NUM_VERTEX_BUFFER_SLOTS];
int vertexBufferStrides[NUM_VERTEX_BUFFER_SLOTS];

void SetVertexBuffer(int slot, Buffer buffer, int offset, int stride)
{
vertexBuffers[slot] = buffer;
vertexBufferOffsets[slot] = offset;
vertexBufferStrides[slot] = stride;
}
void DrawIndexed(..., int baseVertex)
{
PreDrawIndexed(baseVertex);
// ...
}

void PreDrawIndexed(baseVertex)
{
for (int slot = 0; slot < NUM_VERTEX_BUFFER_SLOTS; slot++)
{
Buffer buffer = vertexBuffers[slot];
int offset = vertexBufferOffsets[slot] + baseVertex * vertexBufferStrides[slot];
// bind vertex buffer with offset
}
}
```

How can I add my soft offset to gl_VertexIndex?

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue does not name a file, test, or entry point. First clarify whether it requests implementation or usage guidance, then locate the GLSL handling for gl_VertexIndex and define the expected offset behavior; done should be a decided approach with a reproducible validation case.

Written by the indexing model from the issue text.

Assessment

Domain
computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.