|
|
|
|
@ -20,7 +20,6 @@
|
|
|
|
|
|
|
|
|
|
render_object * allocateRenderObject(uint buffer_len, uint index_len = 0); |
|
|
|
|
void freeRenderObject(render_object* ro); |
|
|
|
|
bool initGLTexture(render_object* ro, util_image image); |
|
|
|
|
bool convertMeshInfo(meMeshInfo* mesh, render_object* ro, bool use_normals, bool use_texture); |
|
|
|
|
void sendIndexBufferToGL(gl_index_buffer* index_buffer, GLenum usage, GLenum target); |
|
|
|
|
|
|
|
|
|
@ -102,6 +101,21 @@ rgInitShaderProgram(rg_shader_program& sp, const char * vertex_code, const char
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool |
|
|
|
|
rgInitGLTexture(GLuint& tex_id, util_image image) |
|
|
|
|
{ |
|
|
|
|
glGenTextures(1, &tex_id); |
|
|
|
|
glBindTexture(GL_TEXTURE_2D, tex_id); |
|
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); |
|
|
|
|
GLenum pixel_format = (image.num_channels == 3) ? GL_RGB : GL_RGBA; |
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, pixel_format, image.w, image.h, 0, |
|
|
|
|
pixel_format, GL_UNSIGNED_BYTE, image.pixels); |
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
|
|
|
|
|
|
|
|
|
return (glGetError() == GL_NO_ERROR); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO: move Entity initialization to Entity.h/.cpp to fix circular dependancy
|
|
|
|
|
// then just call into convertMeshInfo directly
|
|
|
|
|
bool |
|
|
|
|
@ -139,7 +153,7 @@ rgInitEntity(Entity* e)
|
|
|
|
|
|
|
|
|
|
if (mesh->use_texture) { |
|
|
|
|
ro->use_texture = true; |
|
|
|
|
if (!initGLTexture(ro, mesh->diffuse_texture)) { |
|
|
|
|
if (!rgInitGLTexture(ro->tex_id, mesh->diffuse_texture)) { |
|
|
|
|
LOG(ERROR) << "Error initializing GL texture\n"; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
@ -312,6 +326,7 @@ freeRenderObject(render_object* ro)
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
glDeleteTextures(1, &ro->tex_id); |
|
|
|
|
utilSafeFree(ro->vertex_buffer.buffer); |
|
|
|
|
utilSafeFree(ro->normal_buffer.buffer); |
|
|
|
|
utilSafeFree(ro->color_buffer.buffer); |
|
|
|
|
@ -388,21 +403,6 @@ convertMeshInfo(meMeshInfo* mesh, render_object* ro, bool use_normals, bool use_
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool |
|
|
|
|
initGLTexture(render_object* ro, util_image image) |
|
|
|
|
{ |
|
|
|
|
glGenTextures(1, &ro->tex_id); |
|
|
|
|
glBindTexture(GL_TEXTURE_2D, ro->tex_id); |
|
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); |
|
|
|
|
GLenum pixel_format = (image.num_channels == 3) ? GL_RGB : GL_RGBA; |
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, pixel_format, image.w, image.h, 0, |
|
|
|
|
pixel_format, GL_UNSIGNED_BYTE, image.pixels); |
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
|
|
|
|
|
|
|
|
|
return (glGetError() == GL_NO_ERROR); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
sendIndexBufferToGL(gl_index_buffer* index_buffer, GLenum usage, GLenum target) |
|
|
|
|
{ |
|
|
|
|
|