diff --git a/src/Engine/Operator/AttributeHandle.h b/src/Engine/Operator/AttributeHandle.h index 9f17c7e..4e78224 100644 --- a/src/Engine/Operator/AttributeHandle.h +++ b/src/Engine/Operator/AttributeHandle.h @@ -53,13 +53,19 @@ public: // TODO:make this private (primitive friend classes only) data_->push_back(value); } - T getValue(uint pos) + + std::vector getData() const + { + return *data_; + } + + T getValue(uint pos) const { // TODO:protect against invalid positions // TODO: cast types return data_->at(pos); } - std::string getName() + std::string getName() const { return name_; } diff --git a/src/Engine/Operator/Geometry.cpp b/src/Engine/Operator/Geometry.cpp index 6739fd1..5246ee7 100644 --- a/src/Engine/Operator/Geometry.cpp +++ b/src/Engine/Operator/Geometry.cpp @@ -8,17 +8,24 @@ using namespace enzo; geo::Geometry::Geometry() { - + addVector3Attribute(ga::AttrOwner::POINT, "P"); } ga::AttributeHandle geo::Geometry::addIntAttribute(ga::AttributeOwner owner, std::string name) { auto newAttribute = std::make_shared(name, ga::AttrType::intT); - getOwnerVector(owner).push_back(newAttribute); + getAttributeStore(owner).push_back(newAttribute); return ga::AttributeHandle(newAttribute); } -std::vector>& geo::Geometry::getOwnerVector(ga::AttributeOwner& owner) +ga::AttributeHandle geo::Geometry::addVector3Attribute(ga::AttributeOwner owner, std::string name) +{ + auto newAttribute = std::make_shared(name, ga::AttrType::vectorT); + getAttributeStore(owner).push_back(newAttribute); + return ga::AttributeHandle(newAttribute); +} + +std::vector>& geo::Geometry::getAttributeStore(ga::AttributeOwner& owner) { switch(owner) { @@ -42,7 +49,7 @@ std::vector>& geo::Geometry::getOwnerVector(ga::A std::shared_ptr geo::Geometry::getAttribByName(ga::AttributeOwner owner, std::string name) { - auto& vector = getOwnerVector(owner); + auto& vector = getAttributeStore(owner); for(auto it=vector.begin(); it!=vector.end(); ++it) { if((*it)->getName()==name) diff --git a/src/Engine/Operator/Geometry.h b/src/Engine/Operator/Geometry.h index 0c979a2..332865f 100644 --- a/src/Engine/Operator/Geometry.h +++ b/src/Engine/Operator/Geometry.h @@ -10,10 +10,11 @@ class Geometry public: Geometry(); ga::AttributeHandle addIntAttribute(ga::AttributeOwner owner, std::string name); + ga::AttributeHandle addVector3Attribute(ga::AttributeOwner owner, std::string name); std::shared_ptr getAttribByName(ga::AttributeOwner owner, std::string name); private: using attribVector = std::vector>; - attribVector& getOwnerVector(ga::AttributeOwner& owner); + attribVector& getAttributeStore(ga::AttributeOwner& owner); attribVector pointAttributes_; attribVector vertexAttributes_; attribVector primitiveAttributes_; diff --git a/src/gui/viewport/GLMesh.cpp b/src/gui/viewport/GLMesh.cpp index 50b98d4..59bca08 100644 --- a/src/gui/viewport/GLMesh.cpp +++ b/src/gui/viewport/GLMesh.cpp @@ -15,6 +15,17 @@ void GLMesh::init() initBuffers(); + vertexPosData = { + -0.5f, -0.5f, 0.0f, + 0.5f, -0.5f, 0.0f, + 0.0f, 0.5f, 0.0f, + 0.5f, 0.5f, 0.0f + }; + + // store data in the buffer + glBufferData(GL_ARRAY_BUFFER, vertexPosData.size()*sizeof(GLfloat), vertexPosData.data(), GL_STATIC_DRAW); + + // unbind vertex array glBindVertexArray(0); } @@ -22,12 +33,6 @@ void GLMesh::init() void GLMesh::initBuffers() { - vertexPosData = { - -0.5f, -0.5f, 0.0f, - 0.5f, -0.5f, 0.0f, - 0.0f, 0.5f, 0.0f, - 0.5f, 0.5f, 0.0f - }; indexData = { @@ -38,8 +43,6 @@ void GLMesh::initBuffers() glGenBuffers(1, &vertexBuffer); // set purpose glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); - // store data in the buffer - glBufferData(GL_ARRAY_BUFFER, vertexPosData.size()*sizeof(GLfloat), vertexPosData.data(), GL_STATIC_DRAW); // gives the shader a way to read buffer data glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), (void*)0); @@ -52,6 +55,20 @@ void GLMesh::initBuffers() } +void GLMesh::setPosBuffer(std::vector data) +{ + vertexPosData.clear(); + for(auto vector : data) + { + vertexPosData.push_back(vector.x()); + vertexPosData.push_back(vector.y()); + vertexPosData.push_back(vector.z()); + } + + glBufferData(GL_ARRAY_BUFFER, vertexPosData.size()*sizeof(GLfloat), vertexPosData.data(), GL_STATIC_DRAW); +} + + void GLMesh::bind() { glBindVertexArray(vao); diff --git a/src/gui/viewport/GLMesh.h b/src/gui/viewport/GLMesh.h index 3eeae88..a0f585b 100644 --- a/src/gui/viewport/GLMesh.h +++ b/src/gui/viewport/GLMesh.h @@ -1,4 +1,5 @@ #pragma once +#include "Engine/Types.h" #include #include @@ -16,6 +17,7 @@ public: void init(); void initBuffers(); + void setPosBuffer(std::vector data); void bind(); void unbind(); void draw(); diff --git a/src/gui/viewport/ViewportGLWidget.cpp b/src/gui/viewport/ViewportGLWidget.cpp index a40c0f5..f745727 100644 --- a/src/gui/viewport/ViewportGLWidget.cpp +++ b/src/gui/viewport/ViewportGLWidget.cpp @@ -1,4 +1,6 @@ #include "gui/viewport/ViewportGLWidget.h" +#include "Engine/Operator/AttributeHandle.h" +#include "Engine/Types.h" #include "gui/viewport/GLMesh.h" #include #include @@ -141,7 +143,25 @@ void ViewportGLWidget::paintGL() std::unique_ptr ViewportGLWidget::meshFromGeo(std::unique_ptr& geometry) { + using namespace enzo; + auto mesh = std::make_unique(); + + std::shared_ptr PAttr = geometry->getAttribByName(ga::AttrOwner::POINT, "P"); + ga::AttributeHandleVector3 PAttrHandle = ga::AttributeHandleVector3(PAttr); + PAttrHandle.addValue(bt::Vector3(-0.5f, -0.5f, 0.0f)); + PAttrHandle.addValue(bt::Vector3(0.5f, -0.5f, 0.0f)); + PAttrHandle.addValue(bt::Vector3(0.0f, 0.5f, 0.0f)); + PAttrHandle.addValue(bt::Vector3(0.5f, 0.5f, 0.0f)); + + mesh->setPosBuffer(PAttrHandle.getData()); + // mesh->setPosBuffer(std::vector{ + // bt::Vector3(-0.5f, -0.5f, 0.0f), + // bt::Vector3(0.5f, -0.5f, 0.0f), + // bt::Vector3(0.0f, 0.5f, 0.0f), + // bt::Vector3(0.5f, 0.5f, 0.0f), + // }); + return mesh; }