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
4 changes: 4 additions & 0 deletions include/polyscope/render/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ class ShaderProgram {
virtual void setAttribute(std::string name, const std::vector<double>& data) = 0;
virtual void setAttribute(std::string name, const std::vector<int32_t>& data) = 0;
virtual void setAttribute(std::string name, const std::vector<uint32_t>& data) = 0;

virtual void setAttribute(std::string name, const std::vector<std::array<glm::vec3, 2>>& data) = 0;
virtual void setAttribute(std::string name, const std::vector<std::array<glm::vec3, 3>>& data) = 0;
virtual void setAttribute(std::string name, const std::vector<std::array<glm::vec3, 4>>& data) = 0;
// clang-format on


Expand Down
4 changes: 4 additions & 0 deletions include/polyscope/render/mock_opengl/mock_gl_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ class GLShaderProgram : public ShaderProgram {
void setAttribute(std::string name, const std::vector<double>& data) override;
void setAttribute(std::string name, const std::vector<int32_t>& data) override;
void setAttribute(std::string name, const std::vector<uint32_t>& data) override;

void setAttribute(std::string name, const std::vector<std::array<glm::vec3, 2>>& data) override;
void setAttribute(std::string name, const std::vector<std::array<glm::vec3, 3>>& data) override;
void setAttribute(std::string name, const std::vector<std::array<glm::vec3, 4>>& data) override;
// clang-format on

// Indices
Expand Down
4 changes: 4 additions & 0 deletions include/polyscope/render/opengl/gl_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ class GLShaderProgram : public ShaderProgram {
void setAttribute(std::string name, const std::vector<double>& data) override;
void setAttribute(std::string name, const std::vector<int32_t>& data) override;
void setAttribute(std::string name, const std::vector<uint32_t>& data) override;

void setAttribute(std::string name, const std::vector<std::array<glm::vec3, 2>>& data) override;
void setAttribute(std::string name, const std::vector<std::array<glm::vec3, 3>>& data) override;
void setAttribute(std::string name, const std::vector<std::array<glm::vec3, 4>>& data) override;
// clang-format on


Expand Down
6 changes: 1 addition & 5 deletions src/camera_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,7 @@ void CameraView::fillCameraWidgetGeometry(render::ShaderProgram* nodeProgram, re
std::array<glm::vec3, 3>{pickColor, pickColor, pickColor});


std::shared_ptr<render::AttributeBuffer> tripleColorsBuff =
render::engine->generateAttributeBuffer(RenderDataType::Vector3Float, 3);
tripleColorsBuff->setData(tripleColors);

pickFrameProgram->setAttribute("a_vertexColors", tripleColorsBuff);
pickFrameProgram->setAttribute("a_vertexColors", tripleColors);
pickFrameProgram->setAttribute("a_faceColor", faceColor);
if (wantsCullPosition()) {
pickFrameProgram->setAttribute("a_cullPos", cullPos);
Expand Down
45 changes: 45 additions & 0 deletions src/render/mock_opengl/mock_gl_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,51 @@ void GLShaderProgram::setAttribute(std::string name, const std::vector<uint32_t>
throw std::invalid_argument("Tried to set nonexistent attribute with name " + name);
}

void GLShaderProgram::setAttribute(std::string name, const std::vector<std::array<glm::vec3, 2>>& data) {

// pass-through to the buffer
for (GLShaderAttribute& a : attributes) {
if (a.name == name) {
if (a.arrayCount != 2) throw std::invalid_argument("Tried to set attribute " + name + " with wrong array count");
ensureBufferExists(a);
a.buff->setData(data);
return;
}
}

throw std::invalid_argument("Tried to set nonexistent attribute with name " + name);
}

void GLShaderProgram::setAttribute(std::string name, const std::vector<std::array<glm::vec3, 3>>& data) {

// pass-through to the buffer
for (GLShaderAttribute& a : attributes) {
if (a.name == name) {
if (a.arrayCount != 3) throw std::invalid_argument("Tried to set attribute " + name + " with wrong array count");
ensureBufferExists(a);
a.buff->setData(data);
return;
}
}

throw std::invalid_argument("Tried to set nonexistent attribute with name " + name);
}

void GLShaderProgram::setAttribute(std::string name, const std::vector<std::array<glm::vec3, 4>>& data) {

// pass-through to the buffer
for (GLShaderAttribute& a : attributes) {
if (a.name == name) {
if (a.arrayCount != 4) throw std::invalid_argument("Tried to set attribute " + name + " with wrong array count");
ensureBufferExists(a);
a.buff->setData(data);
return;
}
}

throw std::invalid_argument("Tried to set nonexistent attribute with name " + name);
}

bool GLShaderProgram::hasTexture(std::string name) {
for (GLShaderTexture& t : textures) {
if (t.name == name) {
Expand Down
48 changes: 48 additions & 0 deletions src/render/opengl/gl_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1751,6 +1751,54 @@ void GLShaderProgram::setAttribute(std::string name, const std::vector<uint32_t>
throw std::invalid_argument("Tried to set nonexistent attribute with name " + name);
}

void GLShaderProgram::setAttribute(std::string name, const std::vector<std::array<glm::vec3, 2>>& data) {
glBindVertexArray(vaoHandle);

// pass-through to the buffer
for (GLShaderAttribute& a : attributes) {
if (a.name == name && a.location != -1) {
if (a.arrayCount != 2) throw std::invalid_argument("Tried to set attribute " + name + " with wrong array count");
ensureBufferExists(a);
a.buff->setData(data);
return;
}
}

throw std::invalid_argument("Tried to set nonexistent attribute with name " + name);
}

void GLShaderProgram::setAttribute(std::string name, const std::vector<std::array<glm::vec3, 3>>& data) {
glBindVertexArray(vaoHandle);

// pass-through to the buffer
for (GLShaderAttribute& a : attributes) {
if (a.name == name && a.location != -1) {
if (a.arrayCount != 3) throw std::invalid_argument("Tried to set attribute " + name + " with wrong array count");
ensureBufferExists(a);
a.buff->setData(data);
return;
}
}

throw std::invalid_argument("Tried to set nonexistent attribute with name " + name);
}

void GLShaderProgram::setAttribute(std::string name, const std::vector<std::array<glm::vec3, 4>>& data) {
glBindVertexArray(vaoHandle);

// pass-through to the buffer
for (GLShaderAttribute& a : attributes) {
if (a.name == name && a.location != -1) {
if (a.arrayCount != 4) throw std::invalid_argument("Tried to set attribute " + name + " with wrong array count");
ensureBufferExists(a);
a.buff->setData(data);
return;
}
}

throw std::invalid_argument("Tried to set nonexistent attribute with name " + name);
}

bool GLShaderProgram::hasTexture(std::string name) {
for (GLShaderTexture& t : textures) {
if (t.name == name && t.location != -1) {
Expand Down
24 changes: 4 additions & 20 deletions src/surface_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,27 +1040,11 @@ void SurfaceMesh::setMeshPickAttributes(render::ShaderProgram& p) {

// == Store data in buffers

std::shared_ptr<render::AttributeBuffer> vertexColorsBuff =
render::engine->generateAttributeBuffer(RenderDataType::Vector3Float, 3);
vertexColorsBuff->setData(vertexColors);
pickProgram->setAttribute("a_vertexColors", vertexColorsBuff);

std::shared_ptr<render::AttributeBuffer> faceColorsBuff =
render::engine->generateAttributeBuffer(RenderDataType::Vector3Float);
faceColorsBuff->setData(faceColor);
pickProgram->setAttribute("a_faceColor", faceColorsBuff);

pickProgram->setAttribute("a_vertexColors", vertexColors);
pickProgram->setAttribute("a_faceColor", faceColor);
if (!usingSimplePick) {

std::shared_ptr<render::AttributeBuffer> halfedgeColorsBuff =
render::engine->generateAttributeBuffer(RenderDataType::Vector3Float, 3);
halfedgeColorsBuff->setData(halfedgeColors);
pickProgram->setAttribute("a_halfedgeColors", halfedgeColorsBuff);

std::shared_ptr<render::AttributeBuffer> cornerColorsBuff =
render::engine->generateAttributeBuffer(RenderDataType::Vector3Float, 3);
cornerColorsBuff->setData(cornerColors);
pickProgram->setAttribute("a_cornerColors", cornerColorsBuff);
pickProgram->setAttribute("a_halfedgeColors", halfedgeColors);
pickProgram->setAttribute("a_cornerColors", cornerColors);
}
}

Expand Down
7 changes: 1 addition & 6 deletions src/volume_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,12 +599,7 @@ void VolumeMesh::preparePick() {
}

// === Store data in buffers

std::shared_ptr<render::AttributeBuffer> vertexColorsBuff =
render::engine->generateAttributeBuffer(RenderDataType::Vector3Float, 3);
vertexColorsBuff->setData(vertexColors);

pickProgram->setAttribute("a_vertexColors", vertexColorsBuff);
pickProgram->setAttribute("a_vertexColors", vertexColors);
pickProgram->setAttribute("a_faceColor", faceColor);
}

Expand Down