PDA

View Full Version : Replacing an existing texture with a new one



Benzino
08-18-2011, 06:06 AM
I am trying to load a new 3D texture, replacing an existing 3D texture used to draw a volume in a Cg shader. However, when the new volume (or 3d texture) is loaded, the old volume is still been drawn. I create the texture by doing the following:


glGenTextures(1, &volume_texture);
glBindTexture(GL_TEXTURE_3D, volume_texture);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);

glTexImage3D(GL_TEXTURE_3D, 0, GL_INTENSITY, WIDTH, HEIGHT, DEPTH, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, volumeData);

When I load a new texture, I do the following (where volumeData contains the new volume texture information):


glBindTexture(GL_TEXTURE_3D, volume_texture);

glTexImage3D(GL_TEXTURE_3D, 0, GL_INTENSITY, WIDTH, HEIGHT, DEPTH, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, volumeData);

I have tried glDeleteTextures to delete the existing texture before loading the new one, but it didn't make any difference.
The data for the texture is loaded in correctly, as after the texture is created, the same data is used to build an octree, which is built correctly as it represents the loaded volume.
For rendering, I pass the 3D texture to a Cg shader. This is done using the following call, every time the scene is drawn



SetTextureParam("volumeTex", volumeTexture, fragment_main, param3);

void SetTextureParam(char* par, GLuint tex, const CGprogram &program, CGparameter param)
{
param = cgGetNamedParameter(program, par);
cgGLSetTextureParameter(param, tex);
cgGLEnableTextureParameter(param);
}