removed unused files,
removed unused functions, removed unused variables, reduced dynamic stack memory (there was too much allocated), moved some code around into better place, implemented destructor (there is still a std::_face_node left on the stack when the program is done),
This commit is contained in:
parent
ea07ead94f
commit
a875820f48
|
@ -73,10 +73,6 @@ private:
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::vector<GLfloat> getVertex() const;
|
|
||||||
std::vector<GLfloat> getUV() const;
|
|
||||||
std::uint32_t getSize() const;
|
|
||||||
std::list<std::string> getTexture() const;
|
|
||||||
std::vector<Modl*> getModels() const;
|
std::vector<Modl*> getModels() const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -48,9 +48,6 @@ private:
|
||||||
// ==============================
|
// ==============================
|
||||||
|
|
||||||
// data
|
// data
|
||||||
std::vector<GLfloat> vfVertices;
|
|
||||||
std::vector<GLfloat> vfUV;
|
|
||||||
std::uint32_t ui32MeshSize;
|
|
||||||
std::vector<Modl*> vModels;
|
std::vector<Modl*> vModels;
|
||||||
|
|
||||||
// transformation ===============
|
// transformation ===============
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
#pragma once
|
|
||||||
#include <vector>
|
|
||||||
#include <gl\glew.h>
|
|
||||||
|
|
||||||
extern std::vector<GLfloat> loadData();
|
|
||||||
|
|
||||||
extern std::vector<GLfloat> loadUV();
|
|
|
@ -61,7 +61,11 @@ Object::Object(const char* path)
|
||||||
|
|
||||||
Object::~Object()
|
Object::~Object()
|
||||||
{
|
{
|
||||||
//delete Chunk list;
|
// clear texture list
|
||||||
|
vTextures.clear();
|
||||||
|
|
||||||
|
// clear Model list (don't delete the elements)
|
||||||
|
vModls.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -464,7 +468,7 @@ void Object::analyseSegmChunks(Modl * dataDestination, std::list<ChunkHeader*>&
|
||||||
fsMesh.seekg((*it)->position);
|
fsMesh.seekg((*it)->position);
|
||||||
fsMesh.read(reinterpret_cast<char*>(&dataDestination->meshSize), sizeof(dataDestination->meshSize));
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->meshSize), sizeof(dataDestination->meshSize));
|
||||||
|
|
||||||
dataDestination->mesh = new std::uint32_t[dataDestination->meshSize * 3];
|
dataDestination->mesh = new std::uint32_t[dataDestination->meshSize];
|
||||||
|
|
||||||
for (unsigned int i = 0; i < dataDestination->meshSize; i += 3)
|
for (unsigned int i = 0; i < dataDestination->meshSize; i += 3)
|
||||||
{
|
{
|
||||||
|
@ -542,12 +546,8 @@ void Object::readVertex(Modl* dataDestination, std::streampos position)
|
||||||
|
|
||||||
dataDestination->vertex = new float[tempSize * 3];
|
dataDestination->vertex = new float[tempSize * 3];
|
||||||
|
|
||||||
for (unsigned int i = 0; i < tempSize * 3; i += 3)
|
for (unsigned int i = 0; i < tempSize * 3; i++)
|
||||||
{
|
|
||||||
fsMesh.read(reinterpret_cast<char*>(&dataDestination->vertex[i]), sizeof(float));
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->vertex[i]), sizeof(float));
|
||||||
fsMesh.read(reinterpret_cast<char*>(&dataDestination->vertex[i + 1]), sizeof(float));
|
|
||||||
fsMesh.read(reinterpret_cast<char*>(&dataDestination->vertex[i + 2]), sizeof(float));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Object::readUV(Modl* dataDestination, std::streampos position)
|
void Object::readUV(Modl* dataDestination, std::streampos position)
|
||||||
|
@ -558,92 +558,14 @@ void Object::readUV(Modl* dataDestination, std::streampos position)
|
||||||
|
|
||||||
dataDestination->uv = new float[tempSize * 2];
|
dataDestination->uv = new float[tempSize * 2];
|
||||||
|
|
||||||
for (unsigned int i = 0; i < tempSize * 2; i += 2)
|
for (unsigned int i = 0; i < tempSize * 2; i++)
|
||||||
{
|
|
||||||
fsMesh.read(reinterpret_cast<char*>(&dataDestination->uv[i]), sizeof(float));
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->uv[i]), sizeof(float));
|
||||||
fsMesh.read(reinterpret_cast<char*>(&dataDestination->uv[i + 1]), sizeof(float));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// public getter
|
// public getter
|
||||||
|
|
||||||
std::vector<GLfloat> Object::getVertex() const
|
|
||||||
{
|
|
||||||
std::vector<GLfloat> tempData;
|
|
||||||
|
|
||||||
for (std::vector<Modl*>::const_iterator it = vModls.begin(); it != vModls.end(); it++)
|
|
||||||
{
|
|
||||||
if ((*it)->renderFlags == 1)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < (*it)->meshSize; i++)
|
|
||||||
{
|
|
||||||
tempData.push_back((GLfloat)(*it)->vertex[(*it)->mesh[i] * 3]);
|
|
||||||
tempData.push_back((GLfloat)(*it)->vertex[(*it)->mesh[i] * 3 + 1]);
|
|
||||||
tempData.push_back((GLfloat)(*it)->vertex[(*it)->mesh[i] * 3 + 2]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return tempData;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<GLfloat> Object::getUV() const
|
|
||||||
{
|
|
||||||
std::vector<GLfloat> tempData;
|
|
||||||
|
|
||||||
for (std::vector<Modl*>::const_iterator it = vModls.begin(); it != vModls.end(); it++)
|
|
||||||
{
|
|
||||||
if ((*it)->renderFlags == 1)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if ((*it)->uv == NULL)
|
|
||||||
{
|
|
||||||
for (unsigned int i = 0; i < (*it)->meshSize; i++)
|
|
||||||
tempData.push_back(1.0);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (unsigned int i = 0; i < (*it)->meshSize; i++)
|
|
||||||
{
|
|
||||||
tempData.push_back((GLfloat)(*it)->uv[(*it)->mesh[i] * 2]);
|
|
||||||
tempData.push_back((GLfloat)(*it)->uv[(*it)->mesh[i] * 2 + 1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return tempData;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::uint32_t Object::getSize() const
|
|
||||||
{
|
|
||||||
std::uint32_t tempData(0);
|
|
||||||
|
|
||||||
for (std::vector<Modl*>::const_iterator it = vModls.begin(); it != vModls.end(); it++)
|
|
||||||
{
|
|
||||||
if ((*it)->renderFlags == 1)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
tempData += (*it)->meshSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
return tempData;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::list<std::string> Object::getTexture() const
|
|
||||||
{
|
|
||||||
std::list<std::string> tempData;
|
|
||||||
|
|
||||||
for (std::vector<Modl*>::const_iterator it = vModls.begin(); it != vModls.end(); it++)
|
|
||||||
{
|
|
||||||
if ((*it)->renderFlags == 1)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
tempData.push_back((*it)->texture);
|
|
||||||
}
|
|
||||||
|
|
||||||
return tempData;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<Modl*> Object::getModels() const
|
std::vector<Modl*> Object::getModels() const
|
||||||
{
|
{
|
||||||
return vModls;
|
return vModls;
|
||||||
|
|
|
@ -6,9 +6,10 @@
|
||||||
|
|
||||||
#include <glm\gtc\matrix_transform.hpp>
|
#include <glm\gtc\matrix_transform.hpp>
|
||||||
#include "shader.hpp"
|
#include "shader.hpp"
|
||||||
#include "import.h"
|
|
||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#define VERTEX_SHADER "Shader/VertexTextureShader.mv2shdr"
|
#define VERTEX_SHADER "Shader/VertexTextureShader.mv2shdr"
|
||||||
#define FRAGMENT_SHADER "Shader/FragmentTextureShader.mv2shdr"
|
#define FRAGMENT_SHADER "Shader/FragmentTextureShader.mv2shdr"
|
||||||
//#define TEXTURE_NAME "Textures/texture32R.tga"
|
//#define TEXTURE_NAME "Textures/texture32R.tga"
|
||||||
|
@ -31,6 +32,17 @@ OpenGLController::~OpenGLController()
|
||||||
|
|
||||||
glDeleteTextures(1, &gluiSamplerID);
|
glDeleteTextures(1, &gluiSamplerID);
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
||||||
|
while (!vModels.empty())
|
||||||
|
{
|
||||||
|
Modl* cursor = vModels.back();
|
||||||
|
vModels.pop_back();
|
||||||
|
|
||||||
|
delete cursor->uv;
|
||||||
|
delete cursor->mesh;
|
||||||
|
delete cursor->vertex;
|
||||||
|
delete cursor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -95,6 +107,27 @@ void OpenGLController::processInit()
|
||||||
|
|
||||||
// draw vertics only from one side
|
// draw vertics only from one side
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
|
|
||||||
|
// generate stuff
|
||||||
|
glGenVertexArrays(1, &gluiVertexArrayID);
|
||||||
|
glBindVertexArray(gluiVertexArrayID);
|
||||||
|
|
||||||
|
glGenBuffers(1, &gluiVertexBufferID);
|
||||||
|
glGenBuffers(1, &gluiUVBufferID);
|
||||||
|
|
||||||
|
// get the painter ready
|
||||||
|
try
|
||||||
|
{
|
||||||
|
gluiShaderPrgmID = LoadShaders(VERTEX_SHADER, FRAGMENT_SHADER);
|
||||||
|
}
|
||||||
|
catch (std::invalid_argument e)
|
||||||
|
{
|
||||||
|
MessageBox(NULL, e.what(), "MeshViewer 2.0 Error", MB_OK | MB_ICONERROR);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
gluiMatrixID = glGetUniformLocation(gluiShaderPrgmID, "MVP");
|
||||||
|
gluiSamplerID = glGetUniformLocation(gluiShaderPrgmID, "textureSampler");
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLController::startGLFW()
|
void OpenGLController::startGLFW()
|
||||||
|
@ -266,38 +299,11 @@ void OpenGLController::updateScene()
|
||||||
|
|
||||||
void OpenGLController::loadMsh(const char * path)
|
void OpenGLController::loadMsh(const char * path)
|
||||||
{
|
{
|
||||||
// generate stuff
|
|
||||||
glGenVertexArrays(1, &gluiVertexArrayID);
|
|
||||||
glBindVertexArray(gluiVertexArrayID);
|
|
||||||
|
|
||||||
glGenBuffers(1, &gluiVertexBufferID);
|
|
||||||
glGenBuffers(1, &gluiUVBufferID);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
gluiShaderPrgmID = LoadShaders(VERTEX_SHADER, FRAGMENT_SHADER);
|
|
||||||
}
|
|
||||||
catch (std::invalid_argument e)
|
|
||||||
{
|
|
||||||
MessageBox(NULL, e.what(), "MeshViewer 2.0 Error", MB_OK | MB_ICONERROR);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
gluiMatrixID = glGetUniformLocation(gluiShaderPrgmID, "MVP");
|
|
||||||
gluiSamplerID = glGetUniformLocation(gluiShaderPrgmID, "textureSampler");
|
|
||||||
|
|
||||||
// get data
|
// get data
|
||||||
std::list<std::string> listTextures;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object obj(path);
|
Object obj(path);
|
||||||
|
|
||||||
vModels = obj.getModels();
|
vModels = obj.getModels();
|
||||||
|
|
||||||
//vfVertices = obj.getVertex();
|
|
||||||
//vfUV = obj.getUV();
|
|
||||||
//listTextures = obj.getTexture();
|
|
||||||
//ui32MeshSize = obj.getSize();
|
|
||||||
}
|
}
|
||||||
catch (std::invalid_argument e)
|
catch (std::invalid_argument e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -108,6 +108,7 @@ TextureTGA::TextureTGA(const char * filePath)
|
||||||
|
|
||||||
TextureTGA::~TextureTGA()
|
TextureTGA::~TextureTGA()
|
||||||
{
|
{
|
||||||
|
vui8Pixels.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::uint8_t> TextureTGA::getData() const
|
std::vector<std::uint8_t> TextureTGA::getData() const
|
||||||
|
|
|
@ -1,92 +0,0 @@
|
||||||
#include <vector>
|
|
||||||
#include <fstream>
|
|
||||||
#include <Windows.h>
|
|
||||||
#include <gl\glew.h>
|
|
||||||
|
|
||||||
std::vector<GLfloat> loadData()
|
|
||||||
{
|
|
||||||
return std::vector<GLfloat>(
|
|
||||||
{
|
|
||||||
-1.0f, -1.0f, -1.0f, //H5
|
|
||||||
-1.0f, -1.0f, 1.0f, //H8
|
|
||||||
-1.0f, 1.0f, 1.0f, //H7
|
|
||||||
1.0f, 1.0f, -1.0f, //U2
|
|
||||||
-1.0f, -1.0f, -1.0f, //U5
|
|
||||||
-1.0f, 1.0f, -1.0f, //U6
|
|
||||||
1.0f, -1.0f, 1.0f, //L4
|
|
||||||
-1.0f, -1.0f, -1.0f, //L5
|
|
||||||
1.0f, -1.0f, -1.0f, //L1
|
|
||||||
1.0f, 1.0f, -1.0f, //U2
|
|
||||||
1.0f, -1.0f, -1.0f, //U1
|
|
||||||
-1.0f, -1.0f, -1.0f, //U5
|
|
||||||
-1.0f, -1.0f, -1.0f, //H5
|
|
||||||
-1.0f, 1.0f, 1.0f, //H7
|
|
||||||
-1.0f, 1.0f, -1.0f, //H6
|
|
||||||
1.0f, -1.0f, 1.0f, //L4
|
|
||||||
-1.0f, -1.0f, 1.0f, //L8
|
|
||||||
-1.0f, -1.0f, -1.0f, //L5
|
|
||||||
-1.0f, 1.0f, 1.0f, //O7
|
|
||||||
-1.0f, -1.0f, 1.0f, //O8
|
|
||||||
1.0f, -1.0f, 1.0f, //O4
|
|
||||||
1.0f, 1.0f, 1.0f, //V3
|
|
||||||
1.0f, -1.0f, -1.0f, //V1
|
|
||||||
1.0f, 1.0f, -1.0f, //V2
|
|
||||||
1.0f, -1.0f, -1.0f, //V1
|
|
||||||
1.0f, 1.0f, 1.0f, //V3
|
|
||||||
1.0f, -1.0f, 1.0f, //V4
|
|
||||||
1.0f, 1.0f, 1.0f, //R3
|
|
||||||
1.0f, 1.0f, -1.0f, //R2
|
|
||||||
-1.0f, 1.0f, -1.0f, //R6
|
|
||||||
1.0f, 1.0f, 1.0f, //R3
|
|
||||||
-1.0f, 1.0f, -1.0f, //R6
|
|
||||||
-1.0f, 1.0f, 1.0f, //R7
|
|
||||||
1.0f, 1.0f, 1.0f, //O3
|
|
||||||
-1.0f, 1.0f, 1.0f, //O7
|
|
||||||
1.0f, -1.0f, 1.0f //O4
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<GLfloat> loadUV()
|
|
||||||
{
|
|
||||||
return std::vector<float>(
|
|
||||||
{
|
|
||||||
0.0f, 0.0f,//587 Links
|
|
||||||
1.0f, 0.0f,
|
|
||||||
1.0f, 1.0f,
|
|
||||||
0.0f, 1.0f,//256 Hinten
|
|
||||||
1.0f, 0.0f,
|
|
||||||
1.0f, 1.0f,
|
|
||||||
1.0f, 1.0f,//451 Unten
|
|
||||||
0.0f, 0.0f,
|
|
||||||
1.0f, 0.0f,
|
|
||||||
0.0f, 1.0f,//215 Hinten
|
|
||||||
0.0f, 0.0f,
|
|
||||||
1.0f, 0.0f,
|
|
||||||
0.0f, 0.0f,//576 Links
|
|
||||||
1.0f, 1.0f,
|
|
||||||
0.0f, 1.0f,
|
|
||||||
1.0f, 1.0f,//485 Unten
|
|
||||||
0.0f, 1.0f,
|
|
||||||
0.0f, 0.0f,
|
|
||||||
0.0f, 1.0f,//784 Front
|
|
||||||
0.0f, 0.0f,
|
|
||||||
1.0f, 0.0f,
|
|
||||||
0.0f, 1.0f,//312 Rechts
|
|
||||||
1.0f, 0.0f,
|
|
||||||
1.0f, 1.0f,
|
|
||||||
1.0f, 0.0f,//134 Rechts
|
|
||||||
0.0f, 1.0f,
|
|
||||||
0.0f, 0.0f,
|
|
||||||
1.0f, 0.0f,//326 Oben
|
|
||||||
1.0f, 1.0f,
|
|
||||||
0.0f, 1.0f,
|
|
||||||
1.0f, 0.0f,//367 Oben
|
|
||||||
0.0f, 1.0f,
|
|
||||||
0.0f, 0.0f,
|
|
||||||
1.0f, 1.0f,//374 Front
|
|
||||||
0.0f, 1.0f,
|
|
||||||
1.0f, 0.0f
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
Loading…
Reference in New Issue