Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1918cc89bf | ||
|
|
e999bf67b7 |
No files matched your search
@@ -99,14 +99,8 @@ static void checkGLErrorLine(const char * function, int line)
|
||||
|
||||
/****** WFObj functions ******/
|
||||
|
||||
WFObj::WFObj(loadfile_t lf, loadtexture_t lt)
|
||||
WFObj::WFObj()
|
||||
{
|
||||
m_loadfile = lf;
|
||||
m_loadtexture = lt;
|
||||
if (m_loadfile == NULL)
|
||||
{
|
||||
m_loadfile = loadfile;
|
||||
}
|
||||
if (m_valid)
|
||||
{
|
||||
glDeleteBuffers(1, &m_data_vbo);
|
||||
@@ -131,8 +125,15 @@ void WFObj::clear()
|
||||
m_current_material_name = "";
|
||||
}
|
||||
|
||||
bool WFObj::load(const char *fname)
|
||||
bool WFObj::load(const char *fname, loadfile_t lf, loadtexture_t lt)
|
||||
{
|
||||
m_loadfile = lf;
|
||||
m_loadtexture = lt;
|
||||
if (m_loadfile == NULL)
|
||||
{
|
||||
m_loadfile = loadfile;
|
||||
}
|
||||
|
||||
clear();
|
||||
|
||||
Buffer buff;
|
||||
@@ -419,9 +420,15 @@ void WFObj::loadMaterial(const std::string & name)
|
||||
{
|
||||
/* ignore these parameters */
|
||||
}
|
||||
else if (tokens[0] == "map_Kd")
|
||||
{
|
||||
m_materials[mat_name].texture = loadTexture(tokens[1]);
|
||||
if (m_materials[mat_name].texture != 0)
|
||||
m_materials[mat_name].flags |= Material::TEXTURE_BIT;
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "WFObj: error: unrecognized material directive: '"
|
||||
cerr << "WFObj: warning: unrecognized material directive: '"
|
||||
<< tokens[0] << "'" << endl;
|
||||
}
|
||||
}
|
||||
@@ -553,6 +560,17 @@ void WFObj::bindBuffers()
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_index_vbo);
|
||||
}
|
||||
|
||||
GLuint WFObj::loadTexture(const std::string & path)
|
||||
{
|
||||
if (m_loadtexture == NULL)
|
||||
return 0;
|
||||
if (m_textures.find(path) != m_textures.end())
|
||||
return m_textures[path];
|
||||
GLuint id = m_loadtexture(path.c_str());
|
||||
m_textures[path] = id;
|
||||
return id;
|
||||
}
|
||||
|
||||
bool WFObj::VertexRef::operator<(const VertexRef & other) const
|
||||
{
|
||||
if (vertex != other.vertex)
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
GLfloat ambient[4];
|
||||
GLfloat diffuse[4];
|
||||
GLfloat specular[4];
|
||||
std::string texture;
|
||||
GLuint texture;
|
||||
int flags;
|
||||
int first_vertex;
|
||||
int num_vertices;
|
||||
@@ -60,11 +60,11 @@ public:
|
||||
enum { VERTEX, VERTEX_TEXTURE, VERTEX_NORMAL, VERTEX_TYPES };
|
||||
|
||||
/* constructors */
|
||||
WFObj(loadfile_t lf = NULL, loadtexture_t lt = NULL);
|
||||
WFObj();
|
||||
~WFObj();
|
||||
|
||||
/* methods */
|
||||
bool load(const char *fname);
|
||||
bool load(const char *fname, loadfile_t lf = NULL, loadtexture_t lt = NULL);
|
||||
bool load(const Buffer &buff);
|
||||
const float * const getAABB() { return m_aabb; }
|
||||
size_t getStride() { return sizeof(GLfloat) * m_n_floats_per_vref; }
|
||||
@@ -115,6 +115,7 @@ protected:
|
||||
std::string getLine(const Buffer & buff, size_t idx, size_t *update_idx);
|
||||
void loadMaterial(const std::string & name);
|
||||
bool buildVBO();
|
||||
GLuint loadTexture(const std::string & path);
|
||||
|
||||
/* variables */
|
||||
std::vector<Vertex> m_vertices[VERTEX_TYPES];
|
||||
@@ -130,6 +131,7 @@ protected:
|
||||
bool m_do_textures;
|
||||
size_t m_n_floats_per_vref;
|
||||
size_t m_num_materials;
|
||||
std::map<std::string, GLuint> m_textures;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user