diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/include/ITexture.h Irrlicht_starsonata/include/ITexture.h --- irrlicht-svn-ss/trunk/include/ITexture.h 2007-07-26 02:11:22.000000000 +0200 +++ Irrlicht_starsonata/include/ITexture.h 2008-05-07 18:18:52.000000000 +0200 @@ -62,6 +62,11 @@ enum E_TEXTURE_CREATION_FLAG //! Discard any alpha layer and use non-alpha color format. ETCF_NO_ALPHA_CHANNEL = 0x00000020, + // Starsonata, Micha + //! When textures are not power of two they will usually be scaled. + //! When this flag is set the textures will instead be padded up to the power of two sizes. + ETCF_PAD_NPOT = 0x00000040, + //! This flag is never used, it only forces the compiler to //! compile these enumeration values to 32 bit. ETCF_FORCE_32_BIT_DO_NOT_USE = 0x7fffffff @@ -163,6 +167,10 @@ public: //! Returns name of texture (in most cases this is the filename) const core::stringc& getName() { return Name; } + // starsonata, micha + //! returns if the texture was padded to get power of two sizes + virtual bool hasPaddingForPOT() const { return false; } + protected: core::stringc Name; diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/source/Irrlicht/CD3D8Texture.cpp Irrlicht_starsonata/source/Irrlicht/CD3D8Texture.cpp --- irrlicht-svn-ss/trunk/source/Irrlicht/CD3D8Texture.cpp 2007-07-26 02:11:08.000000000 +0200 +++ Irrlicht_starsonata/source/Irrlicht/CD3D8Texture.cpp 2008-05-08 01:04:46.000000000 +0200 @@ -35,6 +35,7 @@ CD3D8Texture::CD3D8Texture(CD3D8Driver* : ITexture(name), Image(0), Texture(0), RTTSurface(0), Driver(driver), TextureSize(size), ImageSize(size), Pitch(0), HasMipMaps(false), IsRenderTarget(true) + , HasPaddingForPOT(false) { #ifdef _DEBUG setDebugName("CD3D8Texture"); @@ -54,6 +55,7 @@ CD3D8Texture::CD3D8Texture(IImage* image : ITexture(name), Image(image), Texture(0), RTTSurface(0), Driver(driver), TextureSize(0,0), ImageSize(0,0), Pitch(0), HasMipMaps(false), IsRenderTarget(false) +, HasPaddingForPOT(false) { #ifdef _DEBUG setDebugName("CD3D8Texture"); @@ -120,6 +122,7 @@ bool CD3D8Texture::createTexture(u32 fla core::dimension2d optSize; ImageSize = Image->getDimension(); + // disable this to test how NPOT behaviour works on cards which don't support it if (Driver->queryFeature(EVDF_TEXTURE_NPOT)) optSize=ImageSize; else @@ -208,7 +211,19 @@ bool CD3D8Texture::copyTexture() } Pitch = rect.Pitch; + + if ( (TextureSize.Width != Image->getDimension().Width + || TextureSize.Height != Image->getDimension().Height) + && Driver->getTextureCreationFlag(ETCF_PAD_NPOT) ) + { + Image->copyTo(rect.pBits, TextureSize.Width, TextureSize.Height, ColorFormat, Pitch); + HasPaddingForPOT = true; + } + else + { + HasPaddingForPOT = false; Image->copyToScaling(rect.pBits, TextureSize.Width, TextureSize.Height, ColorFormat, Pitch); + } hr = Texture->UnlockRect(0); if (FAILED(hr)) diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/source/Irrlicht/CD3D8Texture.h Irrlicht_starsonata/source/Irrlicht/CD3D8Texture.h --- irrlicht-svn-ss/trunk/source/Irrlicht/CD3D8Texture.h 2007-07-26 02:11:08.000000000 +0200 +++ Irrlicht_starsonata/source/Irrlicht/CD3D8Texture.h 2008-05-07 05:13:52.000000000 +0200 @@ -73,6 +73,10 @@ public: //! Returns pointer to the render target surface IDirect3DSurface8* getRenderTargetSurface(); + // starsonata, micha + //! returns if the texture was padded to get power of two sizes + virtual bool hasPaddingForPOT() const { return HasPaddingForPOT; } + private: void createRenderTarget(); @@ -108,6 +112,7 @@ private: ECOLOR_FORMAT ColorFormat; bool HasMipMaps; bool IsRenderTarget; + bool HasPaddingForPOT; }; diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/source/Irrlicht/CD3D9Texture.cpp Irrlicht_starsonata/source/Irrlicht/CD3D9Texture.cpp --- irrlicht-svn-ss/trunk/source/Irrlicht/CD3D9Texture.cpp 2007-07-26 02:11:08.000000000 +0200 +++ Irrlicht_starsonata/source/Irrlicht/CD3D9Texture.cpp 2008-05-08 01:06:28.000000000 +0200 @@ -34,6 +34,7 @@ CD3D9Texture::CD3D9Texture(CD3D9Driver* : ITexture(name), Image(0), Texture(0), RTTSurface(0), Driver(driver), TextureSize(size), ImageSize(size), Pitch(0), HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(true) + , HasPaddingForPOT(false) { #ifdef _DEBUG setDebugName("CD3D9Texture"); @@ -53,6 +54,7 @@ CD3D9Texture::CD3D9Texture(IImage* image : ITexture(name), Image(image), Texture(0), RTTSurface(0), Driver(driver), TextureSize(0,0), ImageSize(0,0), Pitch(0), HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(false) +, HasPaddingForPOT(false) { #ifdef _DEBUG setDebugName("CD3D9Texture"); @@ -265,6 +267,7 @@ bool CD3D9Texture::createTexture(u32 fla core::dimension2d optSize; ImageSize = Image->getDimension(); + // disable this to test how NPOT behaviour works on cards which don't support it if (Driver->queryFeature(EVDF_TEXTURE_NPOT)) optSize=ImageSize; else @@ -410,7 +413,20 @@ bool CD3D9Texture::copyTexture() } Pitch = rect.Pitch; + + + if ( (TextureSize.Width != Image->getDimension().Width + || TextureSize.Height != Image->getDimension().Height) + && Driver->getTextureCreationFlag(ETCF_PAD_NPOT) ) + { + Image->copyTo(rect.pBits, TextureSize.Width, TextureSize.Height, ColorFormat, Pitch); + HasPaddingForPOT = true; + } + else + { + HasPaddingForPOT = false; Image->copyToScaling(rect.pBits, TextureSize.Width, TextureSize.Height, ColorFormat, Pitch); + } hr = Texture->UnlockRect(0); if (FAILED(hr)) diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/source/Irrlicht/CD3D9Texture.h Irrlicht_starsonata/source/Irrlicht/CD3D9Texture.h --- irrlicht-svn-ss/trunk/source/Irrlicht/CD3D9Texture.h 2007-07-26 02:11:08.000000000 +0200 +++ Irrlicht_starsonata/source/Irrlicht/CD3D9Texture.h 2008-05-07 05:14:00.000000000 +0200 @@ -72,6 +72,10 @@ public: //! Returns pointer to the render target surface IDirect3DSurface9* getRenderTargetSurface(); + // starsonata, micha + //! returns if the texture was padded to get power of two sizes + virtual bool hasPaddingForPOT() const { return HasPaddingForPOT; } + private: void createRenderTarget(); @@ -115,6 +119,7 @@ private: bool HasMipMaps; bool HardwareMipMaps; bool IsRenderTarget; + bool HasPaddingForPOT; }; diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/source/Irrlicht/COpenGLTexture.cpp Irrlicht_starsonata/source/Irrlicht/COpenGLTexture.cpp --- irrlicht-svn-ss/trunk/source/Irrlicht/COpenGLTexture.cpp 2007-07-26 02:11:08.000000000 +0200 +++ Irrlicht_starsonata/source/Irrlicht/COpenGLTexture.cpp 2008-05-07 05:05:56.000000000 +0200 @@ -28,6 +28,7 @@ COpenGLTexture::COpenGLTexture(IImage* i : ITexture(name), Driver(driver), Image(0), TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_BGRA_EXT), PixelType(GL_UNSIGNED_BYTE), HasMipMaps(true), + AutomaticMipmapUpdate(false), HasPaddingForPOT(false), ColorFrameBuffer(0), DepthRenderBuffer(0), StencilRenderBuffer(0), Locks(0) { #ifdef _DEBUG @@ -52,6 +53,7 @@ COpenGLTexture::COpenGLTexture(const cor : ITexture(name), ImageSize(size), Driver(driver), Image(0), TextureName(0), InternalFormat(GL_RGB8), PixelFormat(GL_RGBA), PixelType(GL_UNSIGNED_BYTE), HasMipMaps(false), + AutomaticMipmapUpdate(false), HasPaddingForPOT(false), ColorFrameBuffer(0), DepthRenderBuffer(0), StencilRenderBuffer(0), Locks(0) { #ifdef _DEBUG @@ -224,6 +226,7 @@ void COpenGLTexture::getImageData(IImage } core::dimension2d nImageSize; + // disable this to test how NPOT behaviour works on cards which don't support it if (Driver && Driver->queryFeature(EVDF_TEXTURE_NPOT)) nImageSize=ImageSize; else @@ -232,9 +235,17 @@ void COpenGLTexture::getImageData(IImage nImageSize.Height = getTextureSizeFromSurfaceSize(ImageSize.Height); } + HasPaddingForPOT = false; ECOLOR_FORMAT destFormat = getBestColorFormat(image->getColorFormat()); if (ImageSize==nImageSize) Image = new CImage(destFormat, image); + else if ( Driver->getTextureCreationFlag(ETCF_PAD_NPOT) ) + { + Image = new CImage(destFormat, nImageSize); + // copy data, padding will be left empty + image->copyTo(Image); + HasPaddingForPOT = true; + } else { Image = new CImage(destFormat, nImageSize); diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/source/Irrlicht/COpenGLTexture.h Irrlicht_starsonata/source/Irrlicht/COpenGLTexture.h --- irrlicht-svn-ss/trunk/source/Irrlicht/COpenGLTexture.h 2007-07-26 02:11:08.000000000 +0200 +++ Irrlicht_starsonata/source/Irrlicht/COpenGLTexture.h 2008-05-07 04:12:54.000000000 +0200 @@ -97,6 +97,10 @@ public: //! Unbind FrameBufferObject (valid only if isFrameBufferObject() returns true). void unbindFrameBufferObject(); + // starsonata, micha + //! returns if the texture was padded to get power of two sizes + virtual bool hasPaddingForPOT() const { return HasPaddingForPOT; } + private: //! get the desired color format based on texture creation flags and the input format. @@ -122,6 +126,7 @@ private: GLenum PixelType; bool HasMipMaps; bool AutomaticMipmapUpdate; + bool HasPaddingForPOT; GLuint ColorFrameBuffer; // for FBO path GLuint DepthRenderBuffer; // for FBO path