Odd dynamic splatting problem

nod

19-06-2008 04:48:44

Hey all, I just want to start out by saying ETM is awesome.

I've been trying to implement a dynamic splatting system, and it mostly works. I've hooked up wxWidgets for my GUI system, and have buttons to load textures into certain slots to be used for splatting. I edited ETTerrain.material to use dynamically managed textures and the associated .cg files.

The buttons in the wxWidgets window are bitmap buttons that draw the texture loaded with the button. I then pump the raw image data to my texture manager to load into the dynamic textures referenced in the material file.

My problem is that this:
1. Click the bitmap button, pick a texture to load.
2. The texture is loaded onto the button, I transfer the raw image data to be loaded into the material.
3. Nothing shows up on my terrain.
4. Click the bitmap button again, pick another texture.
5. The new texture is loaded onto the button and the PREVIOUS texture is now showing up on my terrain.

Its always the previously loaded texture that is being splatted onto my terrain. Do I need to release some resource before redefining a texture? Heres the relevant parts of my code:


// In my wxWidgets texture dialog

// load the image
wxImage *baseImage = new wxImage( mImagePaths[texturePos] );

// resize the image to the specified terrain texture size if we need to
if( baseImage->GetWidth() != g_textureWidth )
baseImage->Rescale( g_textureWidth, g_textureHeight );

// throw the raw pixel data over to the texture manager so we update the terrain textures
cTextureManager::getInstance()->updateTexture( baseImage->GetData(), texturePos );

// theres other code that updates the button texture, but that is all functional and not relevent here



// In my texture manager class:

// --------------- header file:
std::vector<Ogre::TexturePtr, std::allocator<Ogre::TexturePtr>> mTerrainTextures;

// --------------- constructor
// create the terrain textures
mTerrainTextures.reserve(numImages);


// getTextureName() returns "Texture" + an integer appended onto the end, this naming convention matches the dynamically managed textures in my material file
for( i = 0; i < numImages; i++ )
{
mTerrainTextures.push_back( Ogre::TextureManager::getSingleton().createManual( getTextureName(i),
"ET",
Ogre::TEX_TYPE_2D,
g_textureWidth,
g_textureHeight,
1,
Ogre::PF_BYTE_RGB ) );
}

// -------------- and the updateTexture function
void cTextureManager::updateTexture( unsigned char *data, int textureNumber )
{
Ogre::Image tempImage;
Ogre::DataStreamPtr texStream(new Ogre::MemoryDataStream( (void*)data, g_textureWidth * g_textureHeight * 3 ) );

tempImage.loadRawData( texStream, g_textureWidth, g_textureHeight, Ogre::PF_BYTE_RGB );

mTerrainTextures[textureNumber]->getBuffer(0, 0)->blitFromMemory( tempImage.getPixelBox(0, 0) );

}



// my material file

material ETTerrainMaterial
{
technique
{
// primary splatting technique, requires PS 2.0
// has issues with OpenGL rendering, though...
pass
{
// splatting pass

lighting off

vertex_program_ref ET/Programs/VSLodMorph2
{
}

fragment_program_ref ET/Programs/PSSplat2
{
}

texture_unit
{
texture ETSplatting0
}

// splatting textures
texture_unit
{
texture Texture0
}
texture_unit
{
texture Texture1
}
texture_unit
{
texture Texture2
}
texture_unit
{
texture Texture3
}
}

pass
{
// lightmap texture pass

scene_blend modulate

vertex_program_ref ET/Programs/VSLodMorph2
{
}

fragment_program_ref ET/Programs/PSLighting
{
}

texture_unit
{
texture ETLightmap
}

}
}


I think I'm just missing some unload/reload mechanism when reloading the splatting image. I've tried putting in some loops in the updateTexture() function to check if there is some kind of delay before the splatting texture gets updated, but no dice. Ive also tried that in my dialog code.

Anyone have any ideas?