Commit 1c1d13b3 by Philipp Adolf

Use shared_ptr for SubdivEntrys

parent 5493df80
...@@ -86,7 +86,8 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice ...@@ -86,7 +86,8 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice
this->f = f; this->f = f;
buffers.resize(1); buffers.resize(1);
buffers[0].init(f,Vertices,Indices); buffers[0].reset(new SubdivEntry);
buffers[0]->init(f,Vertices,Indices);
//calc AABB //calc AABB
for (int i = 0; i < Vertices.size(); ++i) { for (int i = 0; i < Vertices.size(); ++i) {
...@@ -102,8 +103,8 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice ...@@ -102,8 +103,8 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice
} }
void Mesh::MeshEntry::update(GLuint VB, QVector<Vertex>& Vertices, QVector<unsigned int>& Indices){ void Mesh::MeshEntry::update(GLuint VB, QVector<Vertex>& Vertices, QVector<unsigned int>& Indices){
buffers.resize(buffers.size()+1); SubdivEntry *entry = new SubdivEntry;
SubdivEntry *entry = &buffers[buffers.size()-1]; buffers.push_back(std::shared_ptr<SubdivEntry>(entry));
entry->init(f,VB,Vertices,Indices); entry->init(f,VB,Vertices,Indices);
} }
...@@ -461,11 +462,11 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision, ...@@ -461,11 +462,11 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision,
materials[MaterialIndex].texture.bind(f,GL_TEXTURE0); materials[MaterialIndex].texture.bind(f,GL_TEXTURE0);
} }
if(entries[index].buffers.size()<= subdivision){ if(entries[index].buffers.size() <= subdivision){
subdivision = entries[index].buffers.size()-1; subdivision = entries[index].buffers.size()-1;
} }
SubdivEntry *entry = &entries[index].buffers[subdivision]; std::shared_ptr<SubdivEntry> entry = entries[index].buffers[subdivision];
// Draw Vertex Array // Draw Vertex Array
f->glBindBuffer(GL_ARRAY_BUFFER, entry->VB_handle); f->glBindBuffer(GL_ARRAY_BUFFER, entry->VB_handle);
......
#ifndef MESH_H #ifndef MESH_H
#define MESH_H #define MESH_H
#include <memory>
#include <QtOpenGL> #include <QtOpenGL>
#include <QOpenGLFunctions_4_3_Core> #include <QOpenGLFunctions_4_3_Core>
#include <assimp/Importer.hpp> #include <assimp/Importer.hpp>
...@@ -89,7 +90,7 @@ public: ...@@ -89,7 +90,7 @@ public:
QString name; QString name;
QVector<SubdivEntry> buffers; QVector<std::shared_ptr<SubdivEntry>> buffers;
int materialIndex; int materialIndex;
......
#include <memory>
#include "subdivision.h" #include "subdivision.h"
Subdivision::Subdivision(QOpenGLFunctions_4_3_Core *f) Subdivision::Subdivision(QOpenGLFunctions_4_3_Core *f)
...@@ -63,7 +65,7 @@ void Subdivision::subdivide(Mesh *mesh, int level) { ...@@ -63,7 +65,7 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
if(level <= currentMax) if(level <= currentMax)
return; return;
Mesh::SubdivEntry* entry = &current_mesh->buffers[currentMax]; std::shared_ptr<Mesh::SubdivEntry> entry = current_mesh->buffers[currentMax];
input.vb_handle = entry->VB_handle; input.vb_handle = entry->VB_handle;
input.vertex_buffer = entry->vertices; input.vertex_buffer = entry->vertices;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment