Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/effects/wave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ void BGWave::Init() {
WaveData.resize(WaveMaxCount);
WavePos.resize((size_t)BGWaveGridSize.x * (size_t)BGWaveGridSize.y);
Vertices.resize((size_t)BGWaveGridSize.x * (size_t)BGWaveGridSize.y);
Indices.resize(
((size_t)BGWaveGridSize.x * 2 + 1) * ((size_t)BGWaveGridSize.y - 1) - 1);
Indices.resize((BGWaveGridSize.x * 2 + 2) * (BGWaveGridSize.y - 1) - 2);

// triangle strips with primitive restart index
constexpr uint16_t primitiveRestart = 0xFFFF;
// triangle strips with degenerate triangles for restarting a row
size_t i = 0;
for (uint16_t y = 0; y < BGWaveGridSize.y - 1; y++) {
for (uint16_t x = 0; x < BGWaveGridSize.x; x++) {
Expand All @@ -32,7 +30,12 @@ void BGWave::Init() {
}

if (y != BGWaveGridSize.y - 2) {
Indices[i++] = primitiveRestart;
const uint16_t lastIndex =
(y + 1) * BGWaveGridSize.x + (BGWaveGridSize.x - 1);
const uint16_t nextIndex = (y + 1) * BGWaveGridSize.x;

Indices[i++] = lastIndex;
Indices[i++] = nextIndex;
}
}
}
Expand Down
12 changes: 2 additions & 10 deletions src/renderer/opengl/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,10 @@ void Renderer::InsertVertices(
const size_t indicesCount = indices.size();
IndexBuffer.resize(offset + indicesCount);

constexpr uint16_t restartIndex = 0xFFFF;
uint16_t maxIndex = 0;
for (size_t i = 0; i < indicesCount; ++i) {
if (indices[i] == restartIndex) {
IndexBuffer[i + offset] = restartIndex;
} else {
IndexBuffer[i + offset] = indices[i] + NextFreeIndex;
if (indices[i] > maxIndex) maxIndex = indices[i];
}
IndexBuffer[i + offset] = indices[i] + NextFreeIndex;
if (indices[i] > maxIndex) maxIndex = indices[i];
}

NextFreeIndex += maxIndex + 1;
Expand Down Expand Up @@ -972,13 +967,10 @@ void Renderer::Flush() {
default: // falls through
case TopologyMode::Triangles: {
mode = GL_TRIANGLES;
glDisable(GL_PRIMITIVE_RESTART);
break;
}
case TopologyMode::TriangleStrips: {
mode = GL_TRIANGLE_STRIP;
glPrimitiveRestartIndex(0xFFFF);
glEnable(GL_PRIMITIVE_RESTART);
break;
}
}
Expand Down
Loading