conworlds

diff src/texture.cc @ 13:283cdfa7dda2

added a crapload of code from goat3dgfx
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 24 Aug 2014 09:41:24 +0300
parents bd8202d6d28d
children
line diff
     1.1 --- a/src/texture.cc	Sat Aug 23 12:03:29 2014 +0300
     1.2 +++ b/src/texture.cc	Sun Aug 24 09:41:24 2014 +0300
     1.3 @@ -64,18 +64,16 @@
     1.4  	return img;
     1.5  }
     1.6  
     1.7 +unsigned int Texture::get_type() const
     1.8 +{
     1.9 +	return type;
    1.10 +}
    1.11 +
    1.12  unsigned int Texture::get_texture_id() const
    1.13  {
    1.14  	return tex;
    1.15  }
    1.16  
    1.17 -void Texture::bind(int tunit) const
    1.18 -{
    1.19 -	glActiveTextureARB(GL_TEXTURE0_ARB + tunit);
    1.20 -	glBindTexture(type, tex);
    1.21 -	glActiveTextureARB(GL_TEXTURE0_ARB);
    1.22 -}
    1.23 -
    1.24  bool Texture::load(const char *fname)
    1.25  {
    1.26  	Image image;
    1.27 @@ -86,6 +84,26 @@
    1.28  	return true;
    1.29  }
    1.30  
    1.31 +void bind_texture(const Texture *tex, int tunit)
    1.32 +{
    1.33 +	static unsigned int cur_tex_type[8] = {
    1.34 +		GL_TEXTURE_2D, GL_TEXTURE_2D, GL_TEXTURE_2D, GL_TEXTURE_2D,
    1.35 +		GL_TEXTURE_2D, GL_TEXTURE_2D, GL_TEXTURE_2D, GL_TEXTURE_2D
    1.36 +	};
    1.37 +
    1.38 +	glActiveTextureARB(GL_TEXTURE0_ARB + tunit);
    1.39 +	if(tex) {
    1.40 +		glBindTexture(tex->get_type(), tex->get_texture_id());
    1.41 +		glEnable(tex->get_type());
    1.42 +	} else {
    1.43 +		glDisable(cur_tex_type[tunit]);
    1.44 +	}
    1.45 +	glActiveTextureARB(GL_TEXTURE0_ARB);
    1.46 +
    1.47 +	cur_tex_type[tunit] = tex->get_type();
    1.48 +}
    1.49 +
    1.50 +
    1.51  unsigned int next_pow2(unsigned int x)
    1.52  {
    1.53  	x -= 1;