Commit fface044 authored by nadro's avatar nadro

- Rewritten OpenGL textures cache.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5154 dfc29bdd-3216-0410-991c-e03cc46cb475
parent be22e335
--------------------------
Changes in 1.9 (not yet released)
- Fix problem with OpenGL textures cache.
- Add clear buffer flags and marked some methods used for clear buffers as deprecated.
- Fix: CGUIImage no longer scales wrong when working with textures which don't have the original image size.
- Fix CSoftwareTexture2 calculation for OriginalSize of ITexture. It was returning the changed texture size instead of the original one before.
......
This diff is collapsed.
......@@ -310,10 +310,6 @@ namespace video
//! Int interface for the above.
virtual bool setPixelShaderConstant(s32 index, const s32* ints, int count) _IRR_OVERRIDE_;
//! sets the current Texture
//! Returns whether setting was a success or not.
bool setActiveTexture(u32 stage, const video::ITexture* texture);
//! disables all textures beginning with the optional fromStage parameter. Otherwise all texture stages are disabled.
//! Returns whether disabling was successful or not.
bool disableTextures(u32 fromStage=0);
......@@ -481,71 +477,6 @@ namespace video
SMaterial Material, LastMaterial;
class STextureStageCache
{
const ITexture* CurrentTexture[MATERIAL_MAX_TEXTURES];
public:
STextureStageCache()
{
for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
{
CurrentTexture[i] = 0;
}
}
~STextureStageCache()
{
clear();
}
void set(u32 stage, const ITexture* tex)
{
if (stage<MATERIAL_MAX_TEXTURES)
{
const ITexture* oldTexture=CurrentTexture[stage];
if (tex)
tex->grab();
CurrentTexture[stage]=tex;
if (oldTexture)
oldTexture->drop();
}
}
const ITexture* operator[](int stage) const
{
if ((u32)stage<MATERIAL_MAX_TEXTURES)
return CurrentTexture[stage];
else
return 0;
}
void remove(ITexture* tex)
{
for (s32 i = MATERIAL_MAX_TEXTURES-1; i>= 0; --i)
{
if (CurrentTexture[i] == tex)
{
tex->drop();
CurrentTexture[i] = 0;
}
}
}
void clear()
{
// Drop all the CurrentTexture handles
for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
{
if (CurrentTexture[i])
{
CurrentTexture[i]->drop();
CurrentTexture[i] = 0;
}
}
}
};
STextureStageCache CurrentTexture;
struct SUserClipPlane
{
SUserClipPlane() : Enabled(false) {}
......@@ -604,11 +535,30 @@ namespace video
E_DEVICE_TYPE DeviceType;
};
//! This bridge between Irlicht pseudo OpenGL calls
//! and true OpenGL calls.
//! This is a bridge between Irlicht pseudo OpenGL calls and real OpenGL calls.
class COpenGLCallBridge
{
class STextureCache
{
public:
STextureCache(COpenGLCallBridge* cacheHandler, u32 textureCount);
~STextureCache();
const COpenGLTexture* operator[](int index) const;
bool set(u32 index, const ITexture* texture);
void remove(ITexture* texture);
void clear();
private:
COpenGLCallBridge* CacheHandler;
const COpenGLTexture* Texture[MATERIAL_MAX_TEXTURES];
u32 TextureCount;
};
public:
COpenGLCallBridge(COpenGLDriver* driver);
~COpenGLCallBridge();
......@@ -673,18 +623,18 @@ namespace video
// Texture calls.
void resetTexture(const ITexture* texture);
void setActiveTexture(GLenum texture);
void setClientActiveTexture(GLenum texture);
void setTexture(GLuint stage, bool fixedPipeline);
// Viewport calls.
void setViewport(GLint viewportX, GLint viewportY, GLsizei viewportWidth, GLsizei viewportHeight);
// Texture cache.
STextureCache TextureCache;
private:
COpenGLDriver* Driver;
......@@ -722,9 +672,6 @@ namespace video
GLenum ActiveTexture;
GLenum ClientActiveTexture;
const ITexture* Texture[MATERIAL_MAX_TEXTURES];
bool TextureFixedPipeline[MATERIAL_MAX_TEXTURES];
GLint ViewportX;
GLint ViewportY;
GLsizei ViewportWidth;
......
......@@ -108,6 +108,9 @@ COpenGLTexture::COpenGLTexture(const io::path& name, const core::dimension2d<u32
setDebugName("COpenGLTexture");
#endif
COpenGLCallBridge* bridgeCalls = Driver->getBridgeCalls();
const COpenGLTexture* prevTexture = bridgeCalls->TextureCache[0];
DriverType = EDT_OPENGL;
if (ECF_UNKNOWN == format)
......@@ -137,8 +140,7 @@ COpenGLTexture::COpenGLTexture(const io::path& name, const core::dimension2d<u32
glGenTextures(1, &TextureName);
Driver->setActiveTexture(0, this);
Driver->getBridgeCalls()->setTexture(0, true);
bridgeCalls->TextureCache.set(0, this);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, FilteringType);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
......@@ -154,20 +156,19 @@ COpenGLTexture::COpenGLTexture(const io::path& name, const core::dimension2d<u32
glTexImage2D(GL_TEXTURE_2D, 0, InternalFormat, OriginalSize.Width, OriginalSize.Height, 0, PixelFormat, PixelType, 0);
Driver->setActiveTexture(0, 0);
Driver->getBridgeCalls()->setTexture(0, true);
bridgeCalls->TextureCache.set(0, prevTexture);
}
//! destructor
COpenGLTexture::~COpenGLTexture()
{
Driver->getBridgeCalls()->TextureCache.remove(this);
if (TextureName)
glDeleteTextures(1, &TextureName);
if (Image)
Image->drop();
Driver->getBridgeCalls()->resetTexture(this);
}
......@@ -477,6 +478,9 @@ void COpenGLTexture::uploadTexture(bool newTexture, void* mipmapData, u32 level)
return;
}
COpenGLCallBridge* bridgeCalls = Driver->getBridgeCalls();
const COpenGLTexture* prevTexture = bridgeCalls->TextureCache[0];
// get correct opengl color data values
GLenum oldInternalFormat = InternalFormat;
GLint filtering;
......@@ -485,8 +489,7 @@ void COpenGLTexture::uploadTexture(bool newTexture, void* mipmapData, u32 level)
if (!newTexture)
InternalFormat=oldInternalFormat;
Driver->setActiveTexture(0, this);
Driver->getBridgeCalls()->setTexture(0, true);
bridgeCalls->TextureCache.set(0, this);
if (Driver->testGLError())
os::Printer::log("Could not bind Texture", ELL_ERROR);
......@@ -599,6 +602,8 @@ void COpenGLTexture::uploadTexture(bool newTexture, void* mipmapData, u32 level)
if (Driver->testGLError())
os::Printer::log("Could not glTexImage2D", ELL_ERROR);
bridgeCalls->TextureCache.set(0, prevTexture);
}
......
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