From 035c602e0afc659b344d685614ec7a2e334636b6 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 7 Jul 2011 22:01:36 +0000 Subject: Disable mipmapping on skybox textures, provide an OpenGL texture id for the cubemap. --- src/render/textures.cc | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'src/render/textures.cc') diff --git a/src/render/textures.cc b/src/render/textures.cc index ad1d8d1..687d245 100644 --- a/src/render/textures.cc +++ b/src/render/textures.cc @@ -20,6 +20,7 @@ namespace render std::map Textures::registry; GLuint Textures::textures[MAXTEXTURES]; +GLuint Textures::textures_cubemap_id; math::Vector2f Textures::texture_size[MAXTEXTURES]; std::string textures_cubemapname; @@ -32,6 +33,8 @@ void Textures::init() { con_print << "^BLoading textures..." << std::endl; + glGenTextures(1, &textures_cubemap_id); + if (registry.size()) { clear(); } else { @@ -83,6 +86,9 @@ void Textures::clear() registry.clear(); memset(textures, 0, sizeof(textures)); + // clear cubemap + glDeleteTextures(1, &textures_cubemap_id); + textures_cubemap_id = 0; textures_cubemapname.clear(); } @@ -127,7 +133,7 @@ void Textures::load_cubemap(const std::string & name) textures_cubemapname.assign(name); -const GLenum cube_map[6] = { + const GLenum cube_map[6] = { GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, @@ -147,6 +153,8 @@ const GLenum cube_map[6] = { }; + // load six skybox images and apply the necessary transformations + if (cube_texture[0]) { Image *image = cube_texture[0]; @@ -238,20 +246,17 @@ const GLenum cube_map[6] = { } } } + + glBindTexture(GL_TEXTURE_CUBE_MAP, textures_cubemap_id); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); - // 4 levels of mipmaps - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 4); - - if (r_mipmap->value()) { - // hardware generated mipmaps (requires OpenGL 1.4) - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_GENERATE_MIPMAP, GL_TRUE); - } + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 0); for (size_t i = 0; i < 6; i++) { if (cube_texture[i]) { @@ -264,18 +269,11 @@ const GLenum cube_map[6] = { } else { texture_format = GL_RGB; texture_internalformat = GL_RGB8; - } + } + glTexImage2D(cube_map[i], 0, + texture_internalformat, cube_texture[i]->width(), cube_texture[i]->height(), 0, + texture_format, GL_UNSIGNED_BYTE, cube_texture[i]->ptr()); - if (r_mipmap->value() <= 0) { - gluBuild2DMipmaps(cube_map[i], - texture_internalformat, cube_texture[i]->width(), cube_texture[i]->height(), - texture_format, GL_UNSIGNED_BYTE, cube_texture[i]->ptr()); - } else { - glTexImage2D(cube_map[i], 0, - texture_internalformat, cube_texture[i]->width(), cube_texture[i]->height(), 0, - texture_format, GL_UNSIGNED_BYTE, cube_texture[i]->ptr()); - } - delete cube_texture[i]; } } -- cgit v1.2.3