Commit a875820f authored by Anakin's avatar Anakin
Browse files

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),
parent ea07ead9
......@@ -73,10 +73,6 @@ private:
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;
};
......@@ -48,9 +48,6 @@ private:
// ==============================
// data
std::vector<GLfloat> vfVertices;
std::vector<GLfloat> vfUV;
std::uint32_t ui32MeshSize;
std::vector<Modl*> vModels;
// transformation ===============
......
#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()
{
//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.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)
{
......@@ -542,12 +546,8 @@ void Object::readVertex(Modl* dataDestination, std::streampos position)
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 + 1]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&dataDestination->vertex[i + 2]), sizeof(float));
}
}
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];
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 + 1]), sizeof(float));
}
}
/////////////////////////////////////////////////////////////////////////
// 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
{
return vModls;
......
......@@ -6,9 +6,10 @@
#include <glm\gtc\matrix_transform.hpp>
#include "shader.hpp"
#include "import.h"
#include "Texture.h"
#include <iostream>
#define VERTEX_SHADER "Shader/VertexTextureShader.mv2shdr"
#define FRAGMENT_SHADER "Shader/FragmentTextureShader.mv2shdr"
//#define TEXTURE_NAME "Textures/texture32R.tga"
......@@ -31,6 +32,17 @@ OpenGLController::~OpenGLController()
glDeleteTextures(1, &gluiSamplerID);
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
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()
......@@ -266,38 +299,11 @@ void OpenGLController::updateScene()
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
std::list<std::string> listTextures;
try
{
Object obj(path);
vModels = obj.getModels();
//vfVertices = obj.getVertex();
//vfUV = obj.getUV();
//listTextures = obj.getTexture();
//ui32MeshSize = obj.getSize();
}
catch (std::invalid_argument e)
{
......
......@@ -108,6 +108,7 @@ TextureTGA::TextureTGA(const char * filePath)
TextureTGA::~TextureTGA()
{
vui8Pixels.clear();
}
std::vector<std::uint8_t> TextureTGA::getData() const
......
#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
}
);
}
......@@ -11,7 +11,7 @@ using namespace std;
#include "shader.hpp"
GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path){
GLuint LoadShaders(const char * vertex_file_path, const char * fragment_file_path){
// Create the shaders
GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
......
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