what about addin a IImageManipulator? this will be used for filling with colors, scaling, copying etc. (the mesh manipulator is already present).
Anyway for compressed textures there 's no need for a IImage counterpart. Just need to implement that in the IVideoDrivers methods wich just load textures:
Methods for loading from a KTX file
Code: Select all
//! Get access to a named texture.
/** Loads the texture from disk if it is not
already loaded and generates mipmap levels if desired.
Texture loading can be influenced using the
setTextureCreationFlag() method. The texture can be in several
imageformats, such as BMP, JPG, TGA, PCX, PNG, and PSD.
It can load also KTX files.
\param filename Filename of the texture to be loaded.
\return Pointer to the texture, or 0 if the texture
could not be loaded. This pointer should not be dropped. See
IReferenceCounted::drop() for more information. */
virtual ITexture* getTexture(const io::path& filename) = 0;
//! Get access to a named texture.
/** Loads the texture from disk if it is not
already loaded and generates mipmap levels if desired.
Texture loading can be influenced using the
setTextureCreationFlag() method. The texture can be in several
imageformats, such as BMP, JPG, TGA, PCX, PNG, and PSD.
Also KTX textures can be loaded.
\param file Pointer to an already opened file.
\return Pointer to the texture, or 0 if the texture
could not be loaded. This pointer should not be dropped. See
IReferenceCounted::drop() for more information. */
virtual ITexture* getTexture(io::IReadFile* file) =0;
I can also improve those methods
Code: Select all
//! Creates an empty texture of specified size.
/** \param size: Size of the texture.
\param name A name for the texture. Later calls to
getTexture() with this name will return this texture
\param format Desired color format of the texture. Please note
that the driver may choose to create the texture in another
color format. If you specify a compressed internal format
your texture can be used as compressed texture
and edited as any other texture.
\return Pointer to the newly created texture. This pointer
should not be dropped. See IReferenceCounted::drop() for more
information. */
virtual ITexture* addTexture(const core::dimension2d<u32>& size,
const io::path& name, ECOLOR_FORMAT format = ECF_A8R8G8B8) = 0;
//! Creates a software image from a part of a texture.
/**
\param texture Texture to copy to the new image in part.
the texture can also be compressed. In that case you obtain uncompressed data.
\param pos Position of rectangle to copy.
\param size Extents of rectangle to copy.
\return The created image.
If you no longer need the image, you should call IImage::drop().
See IReferenceCounted::drop() for more information. */
virtual IImage* createImage(ITexture* texture,
const core::position2d<s32>& pos,
const core::dimension2d<u32>& size) =0;
that would need internally a CCompressedProxyTexture. It will be easy for me making that. The proxy texture just keep in RAM a copy of an ITexture in a uncompressed format (the color format of the image is directly implied by wich compression is choosen since DXT1 only accept R8G8B8 and DXT and DXT 5 only R8G8B8A8.
So if the user specify DXT1 compression it will gain control over a ITexture that the user can freely modify by calling "lock()" as aR8G8B8 texture. When the user calls "unlock" the new data is sent to GPU for compression.
Then putting that ITexture into a material layer will automatically use the last compressed data found in the GPU by default a black (or other noticeable color) texture is used if user did'nt specify anything with a lock call().
this way even when user try to lock a compressed image it is deconpressed and a Proxy texture is created. This is much less invasive API change and need just to add few new color formats (DXT). I already have Idea on how to implement that if you give me white paper and wich parts of Irrlicht needs to be edited (really just few methods + 2 extra classes used only internally)
maybe IImage can be added with few methods. but no IImage with Compressed formats can be created (so no need to change pre-existing methods).
Code: Select all
static bool isCompressedColorFormat() //just a superfluos detail
{
swich(colorformat)
{
case DXT1: case DXT3: case DXT5: return true;
}
return false;
}
what about that? it seems nice to me.
Since i'm working with streaming for my terrain manager I can also add the chance to stream a texture by updating only parts of it and its mipmap levels (and not only with KTX textures if you like. Almost same difficulty for me. (but probably not really needed for now).
In conclusion:
1)KTX files support in the methods wich can returns a texture specifin only a source KTX file => internally a CKhronosTexture is created
2)Methods wich returns an empty texture => internally creates a CCompressedProxyImage already linked with a CKhronosTexture. Data is sent from Proxy to KhronosTexture
3)Users can require to lock a CKhronosTexture => in that case a CCompressedProxyImage is created. Data is de-compressed only once. After that the users have only to specify new data with (lock) and those data will be sended immediatly to GPU in compressed form when calling (unlock).
Issues. Still need a way to remove CCompressedProxyImage by detaching it from the CKhronosTexture (for savin RAM memory).. probably can be done just specifying the correct LOCK MODE. as parameter in lock method. Can't remove that automatically because in case 3) many de-compression/re-compression can reduce image quality.. Probably better to add a new LOCK MODE (FREE_RAM) wich only effect is to destroy the ProxyTexture. So that users can still use all other lock modes without warry about them.
If it seems ok to you I'll start implementing the CCompressedProxyTexture.
After I get all working I'll take a deeper look into GL extension handler to see If I can remove glew dependences easily. :*