Commit 53dbcf00 authored by hybrid's avatar hybrid

Prepare for release of the additional image stored in GL textures.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1737 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 120e8622
...@@ -22,33 +22,44 @@ namespace video ...@@ -22,33 +22,44 @@ namespace video
//! constructor for usual textures //! constructor for usual textures
COpenGLTexture::COpenGLTexture(IImage* origImage, const char* name, COpenGLDriver* driver) COpenGLTexture::COpenGLTexture(IImage* origImage, const char* name, COpenGLDriver* driver)
: ITexture(name), Driver(driver), Image(0), : ITexture(name), ColorFormat(ECF_A8R8G8B8), Driver(driver), Image(0),
TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_BGRA_EXT), TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_BGRA_EXT),
PixelType(GL_UNSIGNED_BYTE), PixelType(GL_UNSIGNED_BYTE),
IsRenderTarget(false), AutomaticMipmapUpdate(false), IsRenderTarget(false), AutomaticMipmapUpdate(false),
ReadOnlyLock(false) ReadOnlyLock(false), KeepImage(true)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("COpenGLTexture"); setDebugName("COpenGLTexture");
#endif #endif
HasMipMaps = Driver->getTextureCreationFlag(ETCF_CREATE_MIP_MAPS);
getImageData(origImage); getImageData(origImage);
HasMipMaps = Driver->getTextureCreationFlag(ETCF_CREATE_MIP_MAPS); glGenTextures(1, &TextureName);
if (Image)
if (ImageSize==TextureSize)
Image = new CImage(ColorFormat, origImage);
else
{ {
glGenTextures(1, &TextureName); Image = new CImage(ColorFormat, TextureSize);
copyTexture(); // scale texture
origImage->copyToScaling(Image);
}
copyTexture();
if (!KeepImage)
{
Image->drop();
Image=0;
} }
} }
//! constructor for basic setup (only for derived classes) //! constructor for basic setup (only for derived classes)
COpenGLTexture::COpenGLTexture(const char* name, COpenGLDriver* driver) COpenGLTexture::COpenGLTexture(const char* name, COpenGLDriver* driver)
: ITexture(name), Driver(driver), Image(0), : ITexture(name), ColorFormat(ECF_A8R8G8B8), Driver(driver), Image(0),
TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_BGRA_EXT), TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_BGRA_EXT),
PixelType(GL_UNSIGNED_BYTE), PixelType(GL_UNSIGNED_BYTE),
HasMipMaps(true), IsRenderTarget(false), AutomaticMipmapUpdate(false), HasMipMaps(true), IsRenderTarget(false), AutomaticMipmapUpdate(false),
ReadOnlyLock(false) ReadOnlyLock(false), KeepImage(true)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("COpenGLTexture"); setDebugName("COpenGLTexture");
...@@ -124,34 +135,22 @@ void COpenGLTexture::getImageData(IImage* image) ...@@ -124,34 +135,22 @@ void COpenGLTexture::getImageData(IImage* image)
return; return;
} }
const core::dimension2d<s32> nImageSize=ImageSize.getOptimalSize(!Driver->queryFeature(EVDF_TEXTURE_NPOT)); TextureSize=ImageSize.getOptimalSize(!Driver->queryFeature(EVDF_TEXTURE_NPOT));
ECOLOR_FORMAT destFormat = getBestColorFormat(image->getColorFormat()); ColorFormat = getBestColorFormat(image->getColorFormat());
if (ImageSize==nImageSize)
Image = new CImage(destFormat, image);
else
{
Image = new CImage(destFormat, nImageSize);
// scale texture
image->copyToScaling(Image);
}
} }
//! copies the the texture into an open gl texture. //! copies the the texture into an open gl texture.
void COpenGLTexture::copyTexture(bool newTexture) void COpenGLTexture::copyTexture(bool newTexture)
{ {
glBindTexture(GL_TEXTURE_2D, TextureName);
if (Driver->testGLError())
os::Printer::log("Could not bind Texture", ELL_ERROR);
if (!Image) if (!Image)
{ {
os::Printer::log("No image for OpenGL texture to upload", ELL_ERROR); os::Printer::log("No image for OpenGL texture to upload", ELL_ERROR);
return; return;
} }
switch (Image->getColorFormat()) switch (ColorFormat)
{ {
case ECF_A1R5G5B5: case ECF_A1R5G5B5:
InternalFormat=GL_RGBA; InternalFormat=GL_RGBA;
...@@ -179,6 +178,10 @@ void COpenGLTexture::copyTexture(bool newTexture) ...@@ -179,6 +178,10 @@ void COpenGLTexture::copyTexture(bool newTexture)
break; break;
} }
glBindTexture(GL_TEXTURE_2D, TextureName);
if (Driver->testGLError())
os::Printer::log("Could not bind Texture", ELL_ERROR);
if (newTexture) if (newTexture)
{ {
#ifndef DISABLE_MIPMAPPING #ifndef DISABLE_MIPMAPPING
...@@ -230,10 +233,14 @@ void* COpenGLTexture::lock(bool readOnly) ...@@ -230,10 +233,14 @@ void* COpenGLTexture::lock(bool readOnly)
{ {
ReadOnlyLock |= readOnly; ReadOnlyLock |= readOnly;
if (!Image) if (!Image || IsRenderTarget)
Image = new CImage(ECF_A8R8G8B8, ImageSize);
if (IsRenderTarget)
{ {
// prepare the data storage if necessary
if (!Image)
Image = new CImage(ECF_A8R8G8B8, ImageSize);
if (!Image)
return 0;
u8* pPixels = static_cast<u8*>(Image->lock()); u8* pPixels = static_cast<u8*>(Image->lock());
if (!pPixels) if (!pPixels)
{ {
...@@ -284,10 +291,17 @@ void* COpenGLTexture::lock(bool readOnly) ...@@ -284,10 +291,17 @@ void* COpenGLTexture::lock(bool readOnly)
//! unlock function //! unlock function
void COpenGLTexture::unlock() void COpenGLTexture::unlock()
{ {
if (!Image)
return;
Image->unlock(); Image->unlock();
if (!ReadOnlyLock) if (!ReadOnlyLock)
copyTexture(false); copyTexture(false);
ReadOnlyLock = false; ReadOnlyLock = false;
if (!KeepImage)
{
Image->drop();
Image=0;
}
} }
...@@ -301,10 +315,7 @@ const core::dimension2d<s32>& COpenGLTexture::getOriginalSize() const ...@@ -301,10 +315,7 @@ const core::dimension2d<s32>& COpenGLTexture::getOriginalSize() const
//! Returns size of the texture. //! Returns size of the texture.
const core::dimension2d<s32>& COpenGLTexture::getSize() const const core::dimension2d<s32>& COpenGLTexture::getSize() const
{ {
if (Image) return TextureSize;
return Image->getDimension();
else
return ImageSize;
} }
...@@ -318,10 +329,7 @@ E_DRIVER_TYPE COpenGLTexture::getDriverType() const ...@@ -318,10 +329,7 @@ E_DRIVER_TYPE COpenGLTexture::getDriverType() const
//! returns color format of texture //! returns color format of texture
ECOLOR_FORMAT COpenGLTexture::getColorFormat() const ECOLOR_FORMAT COpenGLTexture::getColorFormat() const
{ {
if (Image) return ColorFormat;
return Image->getColorFormat();
else
return ECF_A8R8G8B8;
} }
...@@ -354,7 +362,7 @@ bool COpenGLTexture::hasMipMaps() const ...@@ -354,7 +362,7 @@ bool COpenGLTexture::hasMipMaps() const
//! modifying the texture //! modifying the texture
void COpenGLTexture::regenerateMipMapLevels() void COpenGLTexture::regenerateMipMapLevels()
{ {
if (AutomaticMipmapUpdate || !HasMipMaps) if (AutomaticMipmapUpdate || !HasMipMaps || !Image)
return; return;
if ((Image->getDimension().Width==1) && (Image->getDimension().Height==1)) if ((Image->getDimension().Width==1) && (Image->getDimension().Height==1))
return; return;
...@@ -434,6 +442,7 @@ COpenGLFBOTexture::COpenGLFBOTexture(const core::dimension2d<s32>& size, ...@@ -434,6 +442,7 @@ COpenGLFBOTexture::COpenGLFBOTexture(const core::dimension2d<s32>& size,
#endif #endif
ImageSize = size; ImageSize = size;
TextureSize = size;
InternalFormat = GL_RGBA; InternalFormat = GL_RGBA;
PixelFormat = GL_RGBA; PixelFormat = GL_RGBA;
PixelType = GL_UNSIGNED_BYTE; PixelType = GL_UNSIGNED_BYTE;
...@@ -518,6 +527,7 @@ COpenGLFBODepthTexture::COpenGLFBODepthTexture( ...@@ -518,6 +527,7 @@ COpenGLFBODepthTexture::COpenGLFBODepthTexture(
#endif #endif
ImageSize = size; ImageSize = size;
TextureSize = size;
InternalFormat = GL_RGBA; InternalFormat = GL_RGBA;
PixelFormat = GL_RGBA; PixelFormat = GL_RGBA;
PixelType = GL_UNSIGNED_BYTE; PixelType = GL_UNSIGNED_BYTE;
......
...@@ -115,6 +115,9 @@ protected: ...@@ -115,6 +115,9 @@ protected:
void copyTexture(bool newTexture=true); void copyTexture(bool newTexture=true);
core::dimension2d<s32> ImageSize; core::dimension2d<s32> ImageSize;
core::dimension2d<s32> TextureSize;
ECOLOR_FORMAT ColorFormat;
s32 Pitch;
COpenGLDriver* Driver; COpenGLDriver* Driver;
IImage* Image; IImage* Image;
...@@ -127,6 +130,7 @@ protected: ...@@ -127,6 +130,7 @@ protected:
bool IsRenderTarget; bool IsRenderTarget;
bool AutomaticMipmapUpdate; bool AutomaticMipmapUpdate;
bool ReadOnlyLock; bool ReadOnlyLock;
bool KeepImage;
}; };
//! OpenGL FBO texture. //! OpenGL FBO texture.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment