File size: 1,453 Bytes
985c397 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | // SPDX-License-Identifier: LGPL-2.1-or-later
#include "MillPathLine.h"
#include "OpenGlWrapper.h"
#include "GlUtils.h"
#include "Shader.h"
namespace MillSim
{
MillPathLine::MillPathLine()
{
mVao = mVbo = 0;
}
void MillPathLine::GenerateModel()
{
mNumVerts = MillPathPointsBuffer.size();
void* vbuffer = MillPathPointsBuffer.data();
// vertex array
glGenVertexArrays(1, &mVao);
glBindVertexArray(mVao);
// vertex buffer
glGenBuffers(1, &mVbo);
glBindBuffer(GL_ARRAY_BUFFER, mVbo);
glBufferData(GL_ARRAY_BUFFER, mNumVerts * sizeof(MillPathPosition), vbuffer, GL_STATIC_DRAW);
// vertex attribs
glEnableVertexAttribArray(0);
glVertexAttribPointer(
0,
3,
GL_FLOAT,
GL_FALSE,
sizeof(MillPathPosition),
(void*)offsetof(MillPathPosition, X)
);
glEnableVertexAttribArray(1);
glVertexAttribIPointer(
1,
1,
GL_INT,
sizeof(MillPathPosition),
(void*)offsetof(MillPathPosition, SegmentId)
);
// unbind and free
glBindVertexArray(0);
MillPathPointsBuffer.clear();
}
void MillPathLine::Clear()
{
MillPathPointsBuffer.clear();
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
GLDELETE_BUFFER(mVbo);
GLDELETE_VERTEXARRAY(mVao);
}
void MillPathLine::Render()
{
glBindVertexArray(mVao);
glDrawArrays(GL_LINE_STRIP, 0, mNumVerts);
}
} // namespace MillSim
|