add initial buildVBO()

This commit is contained in:
Josh Holtrop 2011-04-20 16:29:59 -04:00
parent 66d4bb50e4
commit 67ef0c4009
2 changed files with 19 additions and 0 deletions

View File

@ -1,4 +1,6 @@
#define GL_GLEXT_PROTOTYPES
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
@ -7,12 +9,15 @@
#include <string.h> /* strlen() */ #include <string.h> /* strlen() */
#include <stdlib.h> /* atoi */ #include <stdlib.h> /* atoi */
#include <GL/gl.h> #include <GL/gl.h>
#include <vector> #include <vector>
#include <string> #include <string>
#include <map> #include <map>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include "WFObj.h" #include "WFObj.h"
using namespace std; using namespace std;
#define WHITESPACE " \n\r\t\v" #define WHITESPACE " \n\r\t\v"
@ -103,6 +108,8 @@ WFObj::WFObj(loadfile_t lf, loadtexture_t lt)
{ {
m_loadfile = loadfile; m_loadfile = loadfile;
} }
if (m_valid)
glDeleteBuffers(1, &m_vbo);
m_valid = false; m_valid = false;
clear(); clear();
} }
@ -160,6 +167,9 @@ bool WFObj::load(const WFObj::Buffer &buff)
} }
updateAABB(); updateAABB();
buildVBO();
m_valid = true;
return true; return true;
} }
@ -430,6 +440,13 @@ bool WFObj::loadfile(const char *path, Buffer & buff)
return false; return false;
} }
void WFObj::buildVBO()
{
glGenBuffers(1, &m_vbo);
bool do_textures = m_loadtexture != NULL
&& m_vertices[VERTEX_TEXTURE].size() > 0;
}
bool WFObj::VertexRef::operator<(const VertexRef & other) bool WFObj::VertexRef::operator<(const VertexRef & other)
{ {
if (vertex != other.vertex) if (vertex != other.vertex)

View File

@ -99,6 +99,7 @@ protected:
static bool loadfile(const char *path, Buffer & buff); static bool loadfile(const char *path, Buffer & buff);
std::string getLine(const Buffer & buff, size_t idx, size_t *update_idx); std::string getLine(const Buffer & buff, size_t idx, size_t *update_idx);
void loadMaterial(const std::string & name); void loadMaterial(const std::string & name);
void buildVBO();
/* variables */ /* variables */
std::vector<Vertex> m_vertices[VERTEX_TYPES]; std::vector<Vertex> m_vertices[VERTEX_TYPES];
@ -110,6 +111,7 @@ protected:
loadtexture_t m_loadtexture; loadtexture_t m_loadtexture;
std::string m_current_material_name; std::string m_current_material_name;
bool m_valid; bool m_valid;
GLuint m_vbo;
}; };
#endif #endif