feat: mesh from geo

This commit is contained in:
parker
2025-07-01 16:04:09 +01:00
parent c60b5dd2f5
commit 6463fe2a7f
5 changed files with 47 additions and 12 deletions

View File

@@ -40,6 +40,9 @@ qt_add_executable(${AppExec}
src/gui/network/FloatingEdgeGraphic.cpp src/gui/network/FloatingEdgeGraphic.cpp
src/gui/network/DisplayFlagButton.cpp src/gui/network/DisplayFlagButton.cpp
src/gui/network/NodeIconGraphic.cpp src/gui/network/NodeIconGraphic.cpp
src/Engine/Operator/Attribute.cpp
src/Engine/Operator/Geometry.cpp
) )
target_link_libraries(${AppExec} PRIVATE Qt6::Core Qt6::Widgets Qt6::SvgWidgets Qt6::OpenGLWidgets glm::glm) target_link_libraries(${AppExec} PRIVATE Qt6::Core Qt6::Widgets Qt6::SvgWidgets Qt6::OpenGLWidgets glm::glm)

View File

@@ -1,4 +1,5 @@
#include "gui/viewport/GLMesh.h" #include "gui/viewport/GLMesh.h"
#include <GL/gl.h>
#include <iostream> #include <iostream>
GLMesh::GLMesh() GLMesh::GLMesh()
@@ -21,23 +22,34 @@ void GLMesh::init()
void GLMesh::initBuffers() void GLMesh::initBuffers()
{ {
float vertices[] = { vertexPosData = {
-0.5f, -0.5f, 0.0f, -0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f,
0.0f, 0.5f, 0.0f 0.0f, 0.5f, 0.0f,
0.5f, 0.5f, 0.0f
};
indexData =
{
0, 1, 2, 1, 2, 3
}; };
// create buffer of vertices // create buffer of vertices
glGenBuffers(1, &vbo); glGenBuffers(1, &vertexBuffer);
// set purpose // set purpose
glBindBuffer(GL_ARRAY_BUFFER, vbo); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
// store data in the buffer // store data in the buffer
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, vertexPosData.size()*sizeof(GLfloat), vertexPosData.data(), GL_STATIC_DRAW);
// gives the shader a way to read // gives the shader a way to read buffer data
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), (void*)0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), (void*)0);
// disable vertex attrib array // disable vertex attrib array
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
glGenBuffers(1, &indexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexData.size()*sizeof(GLint), indexData.data(), GL_STATIC_DRAW);
} }
void GLMesh::bind() void GLMesh::bind()
@@ -53,5 +65,9 @@ void GLMesh::unbind()
void GLMesh::draw() void GLMesh::draw()
{ {
bind(); bind();
glDrawArrays(GL_TRIANGLES, 0, 3);
// wireframe
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
glDrawElements(GL_TRIANGLES, indexData.size(), GL_UNSIGNED_INT, 0);
} }

View File

@@ -1,4 +1,5 @@
#pragma once #pragma once
#include <GL/gl.h>
#include <QOpenGLFunctions_3_2_Core> #include <QOpenGLFunctions_3_2_Core>
class GLMesh class GLMesh
@@ -7,7 +8,11 @@ class GLMesh
public: public:
GLMesh(); GLMesh();
GLuint vao; GLuint vao;
GLuint vbo; GLuint vertexBuffer;
GLuint indexBuffer;
std::vector<GLfloat> vertexPosData;
std::vector<GLint> indexData;
void init(); void init();
void initBuffers(); void initBuffers();

View File

@@ -1,14 +1,15 @@
#include "gui/viewport/ViewportGLWidget.h" #include "gui/viewport/ViewportGLWidget.h" #include "gui/viewport/GLMesh.h"
#include "gui/viewport/GLMesh.h"
#include <glm/mat4x4.hpp> #include <glm/mat4x4.hpp>
#include <glm/ext/matrix_clip_space.hpp> #include <glm/ext/matrix_clip_space.hpp>
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp> #include <glm/gtc/type_ptr.hpp>
#include <memory> #include <memory>
#include <qtimer.h> #include <qtimer.h>
#include "Engine/Operator/Geometry.h"
void ViewportGLWidget::initializeGL() void ViewportGLWidget::initializeGL()
{ {
using namespace enzo;
initializeOpenGLFunctions(); initializeOpenGLFunctions();
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
@@ -16,13 +17,13 @@ void ViewportGLWidget::initializeGL()
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_MULTISAMPLE); glEnable(GL_MULTISAMPLE);
triangleMesh_ = std::make_unique<GLMesh>(); auto geo = std::make_unique<enzo::geo::Geometry>();
triangleMesh_ = meshFromGeo(geo);
gridMesh_ = std::make_unique<GLGrid>(); gridMesh_ = std::make_unique<GLGrid>();
QSurfaceFormat fmt = context()->format(); QSurfaceFormat fmt = context()->format();
std::cout << "format: " << (fmt.renderableType() == QSurfaceFormat::OpenGLES ? "GLES" : "Desktop") << "\n"; std::cout << "format: " << (fmt.renderableType() == QSurfaceFormat::OpenGLES ? "GLES" : "Desktop") << "\n";
std::cout << "format: " << (fmt.renderableType() == QSurfaceFormat::OpenGL ? "true" : "false") << "\n"; std::cout << "format: " << (fmt.renderableType() == QSurfaceFormat::OpenGL ? "true" : "false") << "\n";
std::cout << "hello\n";
// init loop // init loop
QTimer* loopTimer = new QTimer(this); QTimer* loopTimer = new QTimer(this);
@@ -136,3 +137,10 @@ void ViewportGLWidget::paintGL()
} }
std::unique_ptr<GLMesh> ViewportGLWidget::meshFromGeo(std::unique_ptr<enzo::geo::Geometry>& geometry)
{
auto mesh = std::make_unique<GLMesh>();
return mesh;
}

View File

@@ -6,6 +6,7 @@
#include "gui/viewport/GLCamera.h" #include "gui/viewport/GLCamera.h"
#include "gui/viewport/GLMesh.h" #include "gui/viewport/GLMesh.h"
#include "gui/viewport/GLGrid.h" #include "gui/viewport/GLGrid.h"
#include "Engine/Operator/Geometry.h"
class ViewportGLWidget : public QOpenGLWidget, protected QOpenGLFunctions_3_2_Core class ViewportGLWidget : public QOpenGLWidget, protected QOpenGLFunctions_3_2_Core
{ {
@@ -17,6 +18,8 @@ public:
std::unique_ptr<GLMesh> triangleMesh_ ; std::unique_ptr<GLMesh> triangleMesh_ ;
std::unique_ptr<GLGrid> gridMesh_ ; std::unique_ptr<GLGrid> gridMesh_ ;
std::unique_ptr<GLMesh> meshFromGeo(std::unique_ptr<enzo::geo::Geometry>& geometry);
protected: protected:
void initializeGL() override; void initializeGL() override;
void resizeGL(int w, int h) override; void resizeGL(int w, int h) override;