Commit 5562ee1d authored by nadro's avatar nadro

- Optimized 2D materials rendering.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4417 dfc29bdd-3216-0410-991c-e03cc46cb475
parent cc6f569b
...@@ -3406,10 +3406,6 @@ void COpenGLDriver::enableMaterial2D(bool enable) ...@@ -3406,10 +3406,6 @@ void COpenGLDriver::enableMaterial2D(bool enable)
//! sets the needed renderstates //! sets the needed renderstates
void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel) void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel)
{ {
bool BindedTexture = false;
BridgeCalls->setActiveTexture(GL_TEXTURE0_ARB);
if (CurrentRenderMode != ERM_2D || Transformation3DChanged) if (CurrentRenderMode != ERM_2D || Transformation3DChanged)
{ {
// unset last 3d material // unset last 3d material
...@@ -3439,8 +3435,7 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh ...@@ -3439,8 +3435,7 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh
} }
if (!OverrideMaterial2DEnabled) if (!OverrideMaterial2DEnabled)
{ {
setBasicRenderStates(InitMaterial2D, LastMaterial, true); setBasicRenderStates(InitMaterial2D, LastMaterial, true, true);
BindedTexture = true;
LastMaterial = InitMaterial2D; LastMaterial = InitMaterial2D;
} }
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
...@@ -3453,8 +3448,7 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh ...@@ -3453,8 +3448,7 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh
if (OverrideMaterial2DEnabled) if (OverrideMaterial2DEnabled)
{ {
OverrideMaterial2D.Lighting=false; OverrideMaterial2D.Lighting=false;
setBasicRenderStates(OverrideMaterial2D, LastMaterial, false); setBasicRenderStates(OverrideMaterial2D, LastMaterial, false, true);
BindedTexture = true;
LastMaterial = OverrideMaterial2D; LastMaterial = OverrideMaterial2D;
} }
...@@ -3475,38 +3469,11 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh ...@@ -3475,38 +3469,11 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh
if (texture) if (texture)
{ {
if(!BindedTexture && CurrentTexture[0]) if (OverrideMaterial2DEnabled)
BridgeCalls->setTexture(0, true); setTextureRenderStates(OverrideMaterial2D, false, true);
else
if (!OverrideMaterial2DEnabled && CurrentTexture[0]) setTextureRenderStates(InitMaterial2D, false, true);
{
const COpenGLTexture* tmpTexture = static_cast<const COpenGLTexture*>(CurrentTexture[0]);
if (tmpTexture->getStatesCache().IsCached && !tmpTexture->getStatesCache().BilinearFilter &&
!tmpTexture->getStatesCache().TrilinearFilter && !tmpTexture->getStatesCache().MipMapStatus)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
tmpTexture->getStatesCache().BilinearFilter = false;
tmpTexture->getStatesCache().TrilinearFilter = false;
tmpTexture->getStatesCache().MipMapStatus = false;
}
if(!tmpTexture->getStatesCache().IsCached || ETC_REPEAT != tmpTexture->getStatesCache().WrapU)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
tmpTexture->getStatesCache().WrapU = ETC_REPEAT;
}
if(!tmpTexture->getStatesCache().IsCached || GL_REPEAT != tmpTexture->getStatesCache().WrapV)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
tmpTexture->getStatesCache().WrapV = ETC_REPEAT;
}
tmpTexture->getStatesCache().IsCached = true;
}
Material.setTexture(0, const_cast<video::ITexture*>(CurrentTexture[0])); Material.setTexture(0, const_cast<video::ITexture*>(CurrentTexture[0]));
setTransform(ETS_TEXTURE_0, core::IdentityMatrix); setTransform(ETS_TEXTURE_0, core::IdentityMatrix);
// Due to the transformation change, the previous line would call a reset each frame // Due to the transformation change, the previous line would call a reset each frame
......
...@@ -360,6 +360,10 @@ void COpenGLTexture::uploadTexture(bool newTexture, void* mipmapData, u32 level) ...@@ -360,6 +360,10 @@ void COpenGLTexture::uploadTexture(bool newTexture, void* mipmapData, u32 level)
// enable bilinear mipmap filter // enable bilinear mipmap filter
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
StatesCache.BilinearFilter = true;
StatesCache.TrilinearFilter = false;
StatesCache.MipMapStatus = true;
} }
else else
#else #else
...@@ -370,6 +374,10 @@ void COpenGLTexture::uploadTexture(bool newTexture, void* mipmapData, u32 level) ...@@ -370,6 +374,10 @@ void COpenGLTexture::uploadTexture(bool newTexture, void* mipmapData, u32 level)
// enable bilinear filter without mipmaps // enable bilinear filter without mipmaps
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
StatesCache.BilinearFilter = true;
StatesCache.TrilinearFilter = false;
StatesCache.MipMapStatus = false;
} }
} }
...@@ -710,6 +718,15 @@ COpenGLFBOTexture::COpenGLFBOTexture(const core::dimension2d<u32>& size, ...@@ -710,6 +718,15 @@ COpenGLFBOTexture::COpenGLFBOTexture(const core::dimension2d<u32>& size,
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, FilteringType); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, FilteringType);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
if(FilteringType == GL_NEAREST)
StatesCache.BilinearFilter = false;
else
StatesCache.BilinearFilter = true;
StatesCache.WrapU = ETC_CLAMP_TO_EDGE;
StatesCache.WrapV = ETC_CLAMP_TO_EDGE;
glTexImage2D(GL_TEXTURE_2D, 0, InternalFormat, ImageSize.Width, glTexImage2D(GL_TEXTURE_2D, 0, InternalFormat, ImageSize.Width,
ImageSize.Height, 0, PixelFormat, PixelType, 0); ImageSize.Height, 0, PixelFormat, PixelType, 0);
#ifdef _DEBUG #ifdef _DEBUG
......
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