Commit c6f5e6d9 authored by nadro's avatar nadro

- Replaced ITexture::lock 'mipmapLevel' param by 'layer' param.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5279 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 9f88ed7d
......@@ -139,12 +139,11 @@ public:
only mode or read from in write only mode.
Support for this feature depends on the driver, so don't rely on the
texture being write-protected when locking with read-only, etc.
\param mipmapLevel Number of the mipmapLevel to lock. 0 is main texture.
Non-existing levels will silently fail and return 0.
\param layer It determines which cubemap face or texture array layer should be locked.
\return Returns a pointer to the pixel data. The format of the pixel can
be determined by using getColorFormat(). 0 is returned, if
the texture cannot be locked. */
virtual void* lock(E_TEXTURE_LOCK_MODE mode=ETLM_READ_WRITE, u32 mipmapLevel=0) = 0;
virtual void* lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 layer = 0) = 0;
//! Unlock function. Must be called after a lock() to the texture.
/** One should avoid to call unlock more than once before another lock.
......
......@@ -16,8 +16,8 @@ namespace video
{
CD3D9Texture::CD3D9Texture(const io::path& name, const core::array<IImage*>& image, E_TEXTURE_TYPE type, CD3D9Driver* driver)
: ITexture(name, type), Driver(driver), InternalFormat(D3DFMT_UNKNOWN), LockData(0), LockLevel(0), AutoGenerateMipMaps(false),
Device(0), Texture(0), CubeTexture(0), RTTSurface(0)
: ITexture(name, type), Driver(driver), InternalFormat(D3DFMT_UNKNOWN), LockReadOnly(false), LockData(0), LockLayer(0),
AutoGenerateMipMaps(false), Device(0), Texture(0), CubeTexture(0), RTTSurface(0)
{
#ifdef _DEBUG
setDebugName("CD3D9Texture");
......@@ -115,8 +115,8 @@ CD3D9Texture::CD3D9Texture(const io::path& name, const core::array<IImage*>& ima
}
CD3D9Texture::CD3D9Texture(CD3D9Driver* driver, const core::dimension2d<u32>& size, const io::path& name, const ECOLOR_FORMAT format)
: ITexture(name, ETT_2D), Driver(driver), InternalFormat(D3DFMT_UNKNOWN), LockData(0), LockLevel(0), AutoGenerateMipMaps(false),
Device(0), Texture(0), CubeTexture(0), RTTSurface(0)
: ITexture(name, ETT_2D), Driver(driver), InternalFormat(D3DFMT_UNKNOWN), LockReadOnly(false), LockData(0), LockLayer(0),
AutoGenerateMipMaps(false), Device(0), Texture(0), CubeTexture(0), RTTSurface(0)
{
#ifdef _DEBUG
setDebugName("CD3D9Texture");
......@@ -164,16 +164,16 @@ CD3D9Texture::~CD3D9Texture()
Device->Release();
}
void* CD3D9Texture::lock(E_TEXTURE_LOCK_MODE mode, u32 mipmapLevel)
void* CD3D9Texture::lock(E_TEXTURE_LOCK_MODE mode, u32 layer)
{
if (LockData)
return LockData;
if (IImage::isCompressedFormat(ColorFormat) || mipmapLevel > 0) // TO-DO
if (IImage::isCompressedFormat(ColorFormat))
return 0;
bool lockReadOnly = (mode == ETLM_READ_ONLY);
LockLevel = mipmapLevel;
LockReadOnly = (mode == ETLM_READ_ONLY);
LockLayer = layer;
HRESULT hr;
D3DLOCKED_RECT rect;
......@@ -182,12 +182,13 @@ void* CD3D9Texture::lock(E_TEXTURE_LOCK_MODE mode, u32 mipmapLevel)
{
if (Texture)
{
hr = Texture->LockRect(mipmapLevel, &rect, 0, lockReadOnly ? D3DLOCK_READONLY : 0);
hr = Texture->LockRect(0, &rect, 0, LockReadOnly ? D3DLOCK_READONLY : 0);
}
else if (CubeTexture)
{
// TO-DO -> hardcoded D3DCUBEMAP_FACE_POSITIVE_X.
hr = CubeTexture->LockRect(D3DCUBEMAP_FACE_POSITIVE_X, mipmapLevel, &rect, 0, lockReadOnly ? D3DLOCK_READONLY : 0);
_IRR_DEBUG_BREAK_IF(layer > 5)
hr = CubeTexture->LockRect(static_cast<_D3DCUBEMAP_FACES>(layer), 0, &rect, 0, LockReadOnly ? D3DLOCK_READONLY : 0);
}
if (FAILED(hr))
......@@ -212,7 +213,7 @@ void* CD3D9Texture::lock(E_TEXTURE_LOCK_MODE mode, u32 mipmapLevel)
}
IDirect3DSurface9 *surface = 0;
hr = Texture->GetSurfaceLevel(mipmapLevel, &surface);
hr = Texture->GetSurfaceLevel(0, &surface);
if (FAILED(hr))
{
os::Printer::log("Could not lock DIRECT3D9 Texture", "Could not get surface.", ELL_ERROR);
......@@ -225,7 +226,7 @@ void* CD3D9Texture::lock(E_TEXTURE_LOCK_MODE mode, u32 mipmapLevel)
os::Printer::log("Could not lock DIRECT3D9 Texture", "Data copy failed.", ELL_ERROR);
return 0;
}
hr = RTTSurface->LockRect(&rect, 0, lockReadOnly ? D3DLOCK_READONLY : 0);
hr = RTTSurface->LockRect(&rect, 0, LockReadOnly ? D3DLOCK_READONLY : 0);
if(FAILED(hr))
{
os::Printer::log("Could not lock DIRECT3D9 Texture", "LockRect failed.", ELL_ERROR);
......@@ -247,12 +248,11 @@ void CD3D9Texture::unlock()
{
if (Texture)
{
Texture->UnlockRect(LockLevel);
Texture->UnlockRect(0);
}
else if (CubeTexture)
{
// TO-DO -> hardcoded D3DCUBEMAP_FACE_POSITIVE_X.
CubeTexture->UnlockRect(D3DCUBEMAP_FACE_POSITIVE_X, LockLevel);
CubeTexture->UnlockRect(static_cast<_D3DCUBEMAP_FACES>(LockLayer), 0);
}
}
else if (RTTSurface)
......@@ -260,11 +260,12 @@ void CD3D9Texture::unlock()
RTTSurface->UnlockRect();
}
if (LockLevel == 0)
regenerateMipMapLevels(0);
if (!LockReadOnly)
regenerateMipMapLevels(0, LockLayer);
LockReadOnly = false;
LockData = 0;
LockLevel = 0;
LockLayer = 0;
}
void CD3D9Texture::regenerateMipMapLevels(void* data, u32 layer)
......@@ -456,13 +457,6 @@ void CD3D9Texture::uploadTexture(u32 layer, u32 level, void* data)
u32 width = Size.Width >> level;
u32 height = Size.Height >> level;
const D3DCUBEMAP_FACES cubeTextureType[6] =
{
D3DCUBEMAP_FACE_POSITIVE_X, D3DCUBEMAP_FACE_NEGATIVE_X,
D3DCUBEMAP_FACE_POSITIVE_Y, D3DCUBEMAP_FACE_NEGATIVE_Y,
D3DCUBEMAP_FACE_POSITIVE_Z, D3DCUBEMAP_FACE_NEGATIVE_Z
};
u32 dataSize = IImage::getDataSizeFromFormat(ColorFormat, width, height);
HRESULT hr = 0;
......@@ -475,8 +469,9 @@ void CD3D9Texture::uploadTexture(u32 layer, u32 level, void* data)
}
else if (CubeTexture)
{
const D3DCUBEMAP_FACES tmpCubeTextureType = cubeTextureType[(layer < 6) ? layer : 0];
hr = CubeTexture->LockRect(tmpCubeTextureType, level, &lockRectangle, 0, 0);
_IRR_DEBUG_BREAK_IF(layer > 5)
hr = CubeTexture->LockRect(static_cast<_D3DCUBEMAP_FACES>(layer), level, &lockRectangle, 0, 0);
}
if (FAILED(hr))
......@@ -493,8 +488,7 @@ void CD3D9Texture::uploadTexture(u32 layer, u32 level, void* data)
}
else if (CubeTexture)
{
const D3DCUBEMAP_FACES tmpCubeTextureType = cubeTextureType[(layer < 6) ? layer : 0];
hr = CubeTexture->UnlockRect(tmpCubeTextureType, level);
hr = CubeTexture->UnlockRect(static_cast<_D3DCUBEMAP_FACES>(layer), level);
}
if (FAILED(hr))
......
......@@ -32,7 +32,7 @@ public:
virtual ~CD3D9Texture();
virtual void* lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 mipmapLevel = 0) _IRR_OVERRIDE_;
virtual void* lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 layer = 0) _IRR_OVERRIDE_;
virtual void unlock() _IRR_OVERRIDE_;
......@@ -59,8 +59,9 @@ private:
D3DFORMAT InternalFormat;
bool LockReadOnly;
void* LockData;
u32 LockLevel;
u32 LockLayer;
bool AutoGenerateMipMaps;
......
......@@ -768,7 +768,7 @@ namespace video
{
SDummyTexture(const io::path& name, E_TEXTURE_TYPE type) : ITexture(name, type) {};
virtual void* lock(E_TEXTURE_LOCK_MODE mode=ETLM_READ_WRITE, u32 mipmapLevel=0) _IRR_OVERRIDE_ { return 0; }
virtual void* lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 layer = 0) _IRR_OVERRIDE_ { return 0; }
virtual void unlock()_IRR_OVERRIDE_ {}
virtual void regenerateMipMapLevels(void* data = 0, u32 layer = 0) _IRR_OVERRIDE_ {}
};
......
......@@ -46,7 +46,7 @@ public:
};
COpenGLCoreTexture(const io::path& name, const core::array<IImage*>& image, E_TEXTURE_TYPE type, TOpenGLDriver* driver) : ITexture(name, type), Driver(driver), TextureType(GL_TEXTURE_2D),
TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_RGBA), PixelType(GL_UNSIGNED_BYTE), Converter(0), LockReadOnly(false), LockImage(0), LockLevel(0),
TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_RGBA), PixelType(GL_UNSIGNED_BYTE), Converter(0), LockReadOnly(false), LockImage(0), LockLayer(0),
KeepImage(false), AutoGenerateMipMaps(false)
{
_IRR_DEBUG_BREAK_IF(image.size() == 0)
......@@ -134,7 +134,7 @@ public:
}
COpenGLCoreTexture(const io::path& name, const core::dimension2d<u32>& size, ECOLOR_FORMAT format, TOpenGLDriver* driver) : ITexture(name, ETT_2D), Driver(driver), TextureType(GL_TEXTURE_2D),
TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_RGBA), PixelType(GL_UNSIGNED_BYTE), Converter(0), LockReadOnly(false), LockImage(0), LockLevel(0), KeepImage(false),
TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_RGBA), PixelType(GL_UNSIGNED_BYTE), Converter(0), LockReadOnly(false), LockImage(0), LockLayer(0), KeepImage(false),
AutoGenerateMipMaps(false)
{
DriverType = Driver->getDriverType();
......@@ -189,7 +189,7 @@ public:
Image[i]->drop();
}
virtual void* lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 mipmapLevel = 0) _IRR_OVERRIDE_
virtual void* lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 layer = 0) _IRR_OVERRIDE_
{
if (LockImage)
return LockImage->getData();
......@@ -198,24 +198,25 @@ public:
return 0;
LockReadOnly |= (mode == ETLM_READ_ONLY);
LockLevel = mipmapLevel;
LockLayer = layer;
if (KeepImage && mipmapLevel == 0)
if (KeepImage)
{
LockImage = Image[0];
_IRR_DEBUG_BREAK_IF(LockLayer > Image.size())
LockImage = Image[LockLayer];
LockImage->grab();
}
else
{
const core::dimension2d<u32> lockImageSize(Size.Width >> mipmapLevel, Size.Height >> mipmapLevel);
LockImage = Driver->createImage(ColorFormat, lockImageSize);
LockImage = Driver->createImage(ColorFormat, Size);
if (LockImage && mode != ETLM_WRITE_ONLY)
{
IImage* tmpImage = Driver->createImage(ECF_A8R8G8B8, lockImageSize);
IImage* tmpImage = Driver->createImage(ECF_A8R8G8B8, Size);
#if 0 // This method doesn't work properly in some cases
glGetTexImage(GL_TEXTURE_2D, mipmapLevel, GL_RGBA, GL_UNSIGNED_BYTE, tmpImage->getData());
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmpImage->getData());
if (IsRenderTarget)
{
......@@ -238,7 +239,7 @@ public:
delete[] tmpBuffer;
}
#else
COpenGLCoreTexture* tmpTexture = new COpenGLCoreTexture("OGL_CORE_LOCK_TEXTURE", lockImageSize, ColorFormat, Driver);
COpenGLCoreTexture* tmpTexture = new COpenGLCoreTexture("OGL_CORE_LOCK_TEXTURE", Size, ColorFormat, Driver);
GLuint tmpFBO = 0;
Driver->irrGlGenFramebuffers(1, &tmpFBO);
......@@ -248,7 +249,7 @@ public:
GLsizei prevViewportWidth = 0;
GLsizei prevViewportHeight = 0;
Driver->getCacheHandler()->getViewport(prevViewportX, prevViewportY, prevViewportWidth, prevViewportHeight);
Driver->getCacheHandler()->setViewport(0, 0, lockImageSize.Width, lockImageSize.Height);
Driver->getCacheHandler()->setViewport(0, 0, Size.Width, Size.Height);
GLuint prevFBO = 0;
Driver->getCacheHandler()->getFBO(prevFBO);
......@@ -258,7 +259,7 @@ public:
Driver->draw2DImage(this, true);
glReadPixels(0, 0, lockImageSize.Width, lockImageSize.Height, GL_RGBA, GL_UNSIGNED_BYTE, tmpImage->getData());
glReadPixels(0, 0, Size.Width, Size.Height, GL_RGBA, GL_UNSIGNED_BYTE, tmpImage->getData());
Driver->getCacheHandler()->setFBO(prevFBO);
Driver->getCacheHandler()->setViewport(prevViewportX, prevViewportY, prevViewportWidth, prevViewportHeight);
......@@ -313,19 +314,18 @@ public:
const COpenGLCoreTexture* prevTexture = Driver->getCacheHandler()->getTextureCache().get(0);
Driver->getCacheHandler()->getTextureCache().set(0, this);
uploadTexture(false, 0, LockLevel, LockImage->getData());
uploadTexture(false, LockLayer, 0, LockImage->getData());
Driver->getCacheHandler()->getTextureCache().set(0, prevTexture);
if (LockLevel == 0)
regenerateMipMapLevels(0);
regenerateMipMapLevels(0, LockLayer);
}
LockImage->drop();
LockReadOnly = false;
LockImage = 0;
LockLevel = 0;
LockLayer = 0;
}
virtual void regenerateMipMapLevels(void* data = 0, u32 layer = 0) _IRR_OVERRIDE_
......@@ -481,14 +481,21 @@ protected:
u32 width = Size.Width >> level;
u32 height = Size.Height >> level;
const GLenum cubeTextureType[6] =
GLenum tmpTextureType = TextureType;
if (tmpTextureType == GL_TEXTURE_CUBE_MAP)
{
GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
};
_IRR_DEBUG_BREAK_IF(layer > 5)
GLenum tmpTextureType = (TextureType == GL_TEXTURE_CUBE_MAP) ? cubeTextureType[(layer < 6) ? layer : 0] : TextureType;
const GLenum cubeTextureType[6] =
{
GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
};
tmpTextureType = cubeTextureType[layer];
}
if (!IImage::isCompressedFormat(ColorFormat))
{
......@@ -552,7 +559,7 @@ protected:
bool LockReadOnly;
IImage* LockImage;
u32 LockLevel;
u32 LockLayer;
bool KeepImage;
core::array<IImage*> Image;
......
......@@ -76,7 +76,7 @@ CSoftwareTexture::~CSoftwareTexture()
//! lock function
void* CSoftwareTexture::lock(E_TEXTURE_LOCK_MODE mode, u32 mipmapLevel)
void* CSoftwareTexture::lock(E_TEXTURE_LOCK_MODE mode, u32 layer)
{
return Image->getData();
}
......
......@@ -30,7 +30,7 @@ public:
virtual ~CSoftwareTexture();
//! lock function
virtual void* lock(E_TEXTURE_LOCK_MODE mode=ETLM_READ_WRITE, u32 mipmapLevel=0) _IRR_OVERRIDE_;
virtual void* lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 layer = 0) _IRR_OVERRIDE_;
//! unlock function
virtual void unlock() _IRR_OVERRIDE_;
......
......@@ -38,11 +38,11 @@ public:
virtual ~CSoftwareTexture2();
//! lock function
virtual void* lock(E_TEXTURE_LOCK_MODE mode=ETLM_READ_WRITE, u32 mipmapLevel=0) _IRR_OVERRIDE_
virtual void* lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 layer = 0) _IRR_OVERRIDE_
{
if (Flags & GEN_MIPMAP)
{
MipMapLOD = mipmapLevel;
MipMapLOD = 0;
Size = MipMap[MipMapLOD]->getDimension();
Pitch = MipMap[MipMapLOD]->getPitch();
}
......
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