bloboland

diff src/texture.cc @ 3:a39c301cdcce

terrain raytracing pretty much done
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 16 Dec 2012 14:24:16 +0200
parents cfe68befb7cc
children 9021a906c5d3
line diff
     1.1 --- a/src/texture.cc	Sun Dec 16 00:37:35 2012 +0200
     1.2 +++ b/src/texture.cc	Sun Dec 16 14:24:16 2012 +0200
     1.3 @@ -3,9 +3,9 @@
     1.4  
     1.5  void bind_texture(const Texture *tex, int texunit)
     1.6  {
     1.7 -	static const Texture *curr_tex[8];
     1.8 +	static const Texture *cur_tex[8];
     1.9  
    1.10 -	if(tex == curr_tex[texunit]) {
    1.11 +	if(tex == cur_tex[texunit]) {
    1.12  		return;
    1.13  	}
    1.14  
    1.15 @@ -14,11 +14,11 @@
    1.16  		glEnable(tex->type);
    1.17  		glBindTexture(tex->type, tex->tex);
    1.18  	} else {
    1.19 -		glDisable(tex->type);
    1.20 +		glDisable(cur_tex[texunit]->type);
    1.21  	}
    1.22  	glActiveTexture(GL_TEXTURE0);
    1.23  
    1.24 -	curr_tex[texunit] = tex;
    1.25 +	cur_tex[texunit] = tex;
    1.26  }
    1.27  
    1.28  
    1.29 @@ -61,6 +61,12 @@
    1.30  	size[1] = ysz;
    1.31  }
    1.32  
    1.33 +void Texture2D::update(float *data)
    1.34 +{
    1.35 +	glBindTexture(type, tex);
    1.36 +	glTexSubImage2D(type, 0, 0, 0, size[0], size[1], GL_RGBA, GL_FLOAT, data);
    1.37 +}
    1.38 +
    1.39  Texture3D::Texture3D()
    1.40  {
    1.41  	type = GL_TEXTURE_3D;
    1.42 @@ -68,6 +74,9 @@
    1.43  	glBindTexture(type, tex);
    1.44  	glTexParameteri(type, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    1.45  	glTexParameteri(type, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    1.46 +	glTexParameteri(type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    1.47 +	glTexParameteri(type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    1.48 +	glTexParameteri(type, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
    1.49  }
    1.50  
    1.51  void Texture3D::create(int xsz, int ysz, int zsz, float *data)
    1.52 @@ -79,3 +88,9 @@
    1.53  	size[1] = ysz;
    1.54  	size[2] = zsz;
    1.55  }
    1.56 +
    1.57 +void Texture3D::update(float *data)
    1.58 +{
    1.59 +	glBindTexture(type, tex);
    1.60 +	glTexSubImage3D(type, 0, 0, 0, 0, size[0], size[1], size[2], GL_RGBA, GL_FLOAT, data);
    1.61 +}