It might be handy in some cases to have direct access to the texture data (in my case I wanted to plant some trees onto a terrain and needed the heightmap for that). So this might be good:
Code:
Index: Horde3D/Source/Horde3DEngine/egTextures.cpp
===================================================================
--- Horde3D/Source/Horde3DEngine/egTextures.cpp (Revision 46)
+++ Horde3D/Source/Horde3DEngine/egTextures.cpp (Arbeitskopie)
@@ -280,9 +280,20 @@
}
return false;
+}
+
+const void *Texture2DResource::getData( int param )
+{
+ if( param == TextureResParams::PixelData )
+ {
+ if( _texObject == 0 ) return false;
+
+ return downloadImageData();
+ }
+
+ return 0;
}
-
float *Texture2DResource::downloadImageData()
{
int width, height;
Index: Horde3D/Source/Horde3DEngine/egTextures.h
===================================================================
--- Horde3D/Source/Horde3DEngine/egTextures.h (Revision 46)
+++ Horde3D/Source/Horde3DEngine/egTextures.h (Arbeitskopie)
@@ -85,7 +85,8 @@
void initDefault();
void release();
bool load( const char *data, int size );
- bool updateData( int param, const void *data, int size );
+ bool updateData( int param, const void *data, int size );
+ const void *getData( int param );
float *downloadImageData();
int getParami( int param );
Index: Horde3D/Bindings/C++/Horde3D.h
===================================================================
--- Horde3D/Bindings/C++/Horde3D.h (Revision 46)
+++ Horde3D/Bindings/C++/Horde3D.h (Arbeitskopie)
@@ -1019,7 +1019,13 @@
format (uint, float, ..) of the pointer see the ResourceData description.
*Important Note: The pointer is const and allows only read access to the data. Do never try to modify the
- data of the pointer since that can corrupt the engine's internal states!*
+ data of the pointer since that can corrupt the engine's internal states!*
+
+ Notes on available ResourceData parameters:
+ - Texture2DResData::PixelData
+ Returns the image data of a Texture2D resource. Note that you have to free it manually in this case!
+ The returned pointer points to an array of float, where one pixel is represented by 4 floats in RGBA
+ format.
Parameters:
res - handle to the resource to be accessed
Well, I know this is quite hacky, but I actually didn't find a way which fitted better into the concept, storing the data with the texture would have caused much memory overhead again.
Also there are quite some EOL-changes in this diff, that's because Horde3D svn doesn't use svn:eol-style=native (can anybody fix this?), and I'm on Linux. Of course those changes get lost at the moment I type this text into the web browser :p
EDIT: Fixed broken diff. Never simply paste out of a terminal window -.-