AZDO for new texture format
This commit is contained in:
parent
e049cb2bd6
commit
46be4948b2
@ -195,6 +195,9 @@ public:
|
||||
//! return open gl texture name
|
||||
virtual u32 getOpenGLTextureName() const = 0;
|
||||
|
||||
virtual u64 getHandle() = 0;
|
||||
|
||||
virtual void unloadHandle() {}
|
||||
protected:
|
||||
|
||||
//! Helper function, helps to get the desired texture creation format from the flags.
|
||||
|
@ -745,6 +745,7 @@ namespace video
|
||||
virtual ECOLOR_FORMAT getColorFormat() const { return video::ECF_A1R5G5B5; };
|
||||
virtual u32 getPitch() const { return 0; }
|
||||
virtual u32 getOpenGLTextureName() const { return 0; }
|
||||
virtual u64 getHandle() { return 0; }
|
||||
virtual void regenerateMipMapLevels(void* mipmapData=0) {};
|
||||
core::dimension2d<u32> size;
|
||||
};
|
||||
|
@ -83,6 +83,8 @@ public:
|
||||
//! return open gl texture name
|
||||
virtual u32 getOpenGLTextureName() const;
|
||||
|
||||
virtual u64 getHandle() { return 0; }
|
||||
|
||||
//! return whether this texture has mipmaps
|
||||
virtual bool hasMipMaps() const;
|
||||
|
||||
|
@ -80,6 +80,8 @@ public:
|
||||
//! return open gl texture name
|
||||
virtual u32 getOpenGLTextureName() const;
|
||||
|
||||
virtual u64 getHandle() { return 0; }
|
||||
|
||||
//! return whether this texture has mipmaps
|
||||
virtual bool hasMipMaps() const;
|
||||
|
||||
|
@ -23,10 +23,8 @@
|
||||
#include "graphics/central_settings.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/material_manager.hpp"
|
||||
#include "graphics/materials.hpp"
|
||||
#include "graphics/shaders.hpp"
|
||||
#include "graphics/stk_tex_manager.hpp"
|
||||
#include "graphics/texture_manager.hpp"
|
||||
|
||||
#include <ISceneManager.h>
|
||||
#include <IMaterialRenderer.h>
|
||||
@ -397,14 +395,7 @@ static void setTexture(GLMesh &mesh, unsigned i, bool is_srgb,
|
||||
{
|
||||
if (!mesh.TextureHandles[i])
|
||||
{
|
||||
mesh.TextureHandles[i] = glGetTextureSamplerHandleARB(
|
||||
mesh.textures[i]->getOpenGLTextureName(),
|
||||
ObjectPass1Shader::getInstance()->m_sampler_ids[0]);
|
||||
}
|
||||
if (!glIsTextureHandleResidentARB(mesh.TextureHandles[i]))
|
||||
{
|
||||
glMakeTextureHandleResidentARB(mesh.TextureHandles[i]);
|
||||
insertTextureHandle(mesh.TextureHandles[i]);
|
||||
mesh.TextureHandles[i] = mesh.textures[i]->getHandle();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -486,14 +477,7 @@ void initTexturesTransparent(GLMesh &mesh)
|
||||
{
|
||||
if (!mesh.TextureHandles[0])
|
||||
{
|
||||
mesh.TextureHandles[0] = glGetTextureSamplerHandleARB(
|
||||
mesh.textures[0]->getOpenGLTextureName(),
|
||||
ObjectPass1Shader::getInstance()->m_sampler_ids[0]);
|
||||
}
|
||||
if (!glIsTextureHandleResidentARB(mesh.TextureHandles[0]))
|
||||
{
|
||||
glMakeTextureHandleResidentARB(mesh.TextureHandles[0]);
|
||||
insertTextureHandle(mesh.TextureHandles[0]);
|
||||
mesh.TextureHandles[0] = mesh.textures[0]->getHandle();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "graphics/render_info.hpp"
|
||||
#include "graphics/rtts.hpp"
|
||||
#include "graphics/shaders.hpp"
|
||||
#include "graphics/texture_manager.hpp"
|
||||
#include "graphics/vao_manager.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
#include "modes/world.hpp"
|
||||
@ -360,15 +359,7 @@ void STKMeshSceneNode::render()
|
||||
{
|
||||
if (!mesh.TextureHandles[0])
|
||||
{
|
||||
mesh.TextureHandles[0] =
|
||||
glGetTextureSamplerHandleARB(mesh.textures[0]->getOpenGLTextureName(),
|
||||
ObjectPass1Shader
|
||||
::getInstance()->m_sampler_ids[0]);
|
||||
}
|
||||
if (!glIsTextureHandleResidentARB(mesh.TextureHandles[0]))
|
||||
{
|
||||
glMakeTextureHandleResidentARB(mesh.TextureHandles[0]);
|
||||
insertTextureHandle(mesh.TextureHandles[0]);
|
||||
mesh.TextureHandles[0] = mesh.textures[0]->getHandle();
|
||||
}
|
||||
ObjectPass1Shader::getInstance()->setTextureHandles(mesh.TextureHandles[0]);
|
||||
}
|
||||
@ -420,34 +411,13 @@ void STKMeshSceneNode::render()
|
||||
ObjectPass2Shader::getInstance()->m_sampler_ids[2]);
|
||||
|
||||
if (!mesh.TextureHandles[0])
|
||||
mesh.TextureHandles[0] =
|
||||
glGetTextureSamplerHandleARB(mesh.textures[0]->getOpenGLTextureName(),
|
||||
ObjectPass1Shader::getInstance()->m_sampler_ids[0]);
|
||||
if (!glIsTextureHandleResidentARB(mesh.TextureHandles[0]))
|
||||
{
|
||||
glMakeTextureHandleResidentARB(mesh.TextureHandles[0]);
|
||||
insertTextureHandle(mesh.TextureHandles[0]);
|
||||
}
|
||||
mesh.TextureHandles[0] = mesh.textures[0]->getHandle();
|
||||
|
||||
if (!mesh.TextureHandles[1])
|
||||
mesh.TextureHandles[1] =
|
||||
glGetTextureSamplerHandleARB(mesh.textures[1]->getOpenGLTextureName(),
|
||||
ObjectPass1Shader::getInstance()->m_sampler_ids[0]);
|
||||
if (!glIsTextureHandleResidentARB(mesh.TextureHandles[1]))
|
||||
{
|
||||
glMakeTextureHandleResidentARB(mesh.TextureHandles[1]);
|
||||
insertTextureHandle(mesh.TextureHandles[1]);
|
||||
}
|
||||
mesh.TextureHandles[1] = mesh.textures[1]->getHandle();
|
||||
|
||||
if (!mesh.TextureHandles[2])
|
||||
mesh.TextureHandles[2] =
|
||||
glGetTextureSamplerHandleARB(mesh.textures[2]->getOpenGLTextureName(),
|
||||
ObjectPass1Shader::getInstance()->m_sampler_ids[0]);
|
||||
if (!glIsTextureHandleResidentARB(mesh.TextureHandles[2]))
|
||||
{
|
||||
glMakeTextureHandleResidentARB(mesh.TextureHandles[2]);
|
||||
insertTextureHandle(mesh.TextureHandles[2]);
|
||||
}
|
||||
mesh.TextureHandles[2] = mesh.textures[2]->getHandle();
|
||||
|
||||
ObjectPass2Shader::getInstance()
|
||||
->setTextureHandles(DiffuseHandle, SpecularHandle, SSAOHandle,
|
||||
@ -532,14 +502,7 @@ void STKMeshSceneNode::render()
|
||||
if (CVS->isAZDOEnabled())
|
||||
{
|
||||
if (!mesh.TextureHandles[0])
|
||||
mesh.TextureHandles[0] =
|
||||
glGetTextureSamplerHandleARB(mesh.textures[0]->getOpenGLTextureName(),
|
||||
ObjectPass1Shader::getInstance()->m_sampler_ids[0]);
|
||||
if (!glIsTextureHandleResidentARB(mesh.TextureHandles[0]))
|
||||
{
|
||||
glMakeTextureHandleResidentARB(mesh.TextureHandles[0]);
|
||||
insertTextureHandle(mesh.TextureHandles[0]);
|
||||
}
|
||||
mesh.TextureHandles[0] = mesh.textures[0]->getHandle();
|
||||
Shaders::TransparentFogShader::getInstance()
|
||||
->setTextureHandles(mesh.TextureHandles[0]);
|
||||
}
|
||||
@ -574,14 +537,7 @@ void STKMeshSceneNode::render()
|
||||
if (CVS->isAZDOEnabled())
|
||||
{
|
||||
if (!mesh.TextureHandles[0])
|
||||
mesh.TextureHandles[0] =
|
||||
glGetTextureSamplerHandleARB(mesh.textures[0]->getOpenGLTextureName(),
|
||||
ObjectPass1Shader::getInstance()->m_sampler_ids[0]);
|
||||
if (!glIsTextureHandleResidentARB(mesh.TextureHandles[0]))
|
||||
{
|
||||
glMakeTextureHandleResidentARB(mesh.TextureHandles[0]);
|
||||
insertTextureHandle(mesh.TextureHandles[0]);
|
||||
}
|
||||
mesh.TextureHandles[0] = mesh.textures[0]->getHandle();
|
||||
Shaders::TransparentShader::getInstance()->setTextureHandles(mesh.TextureHandles[0]);
|
||||
}
|
||||
else
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
#include "graphics/stk_tex_manager.hpp"
|
||||
#include "graphics/central_settings.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/materials.hpp"
|
||||
#include "graphics/stk_texture.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
@ -222,3 +222,19 @@ core::stringw STKTexManager::reloadTexture(const irr::core::stringw& name)
|
||||
#endif // !SERVER_ONLY
|
||||
return result + "reloaded.";
|
||||
} // reloadTexture
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void STKTexManager::reset()
|
||||
{
|
||||
#if !(defined(SERVER_ONLY) || defined(USE_GLES2))
|
||||
if (!CVS->isAZDOEnabled()) return;
|
||||
for (auto p : m_all_textures)
|
||||
{
|
||||
if (p.second == NULL)
|
||||
continue;
|
||||
p.second->unloadHandle();
|
||||
}
|
||||
// Driver seems to crash if texture handles are not cleared...
|
||||
ObjectPass1Shader::getInstance()->recreateTrilinearSampler(0);
|
||||
#endif
|
||||
} // reset
|
||||
|
@ -67,6 +67,8 @@ public:
|
||||
int dumpTextureUsage();
|
||||
// ------------------------------------------------------------------------
|
||||
irr::core::stringw reloadTexture(const irr::core::stringw& name);
|
||||
// ------------------------------------------------------------------------
|
||||
void reset();
|
||||
|
||||
}; // STKTexManager
|
||||
|
||||
|
@ -15,12 +15,13 @@
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/stk_texture.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/central_settings.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/material.hpp"
|
||||
#include "graphics/material_manager.hpp"
|
||||
#include "graphics/materials.hpp"
|
||||
#include "modes/profile_world.hpp"
|
||||
#include "utils/log.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
@ -73,6 +74,7 @@ STKTexture::STKTexture(uint8_t* data, const std::string& name, size_t size,
|
||||
STKTexture::~STKTexture()
|
||||
{
|
||||
#ifndef SERVER_ONLY
|
||||
unloadHandle();
|
||||
if (m_texture_name != 0)
|
||||
{
|
||||
glDeleteTextures(1, &m_texture_name);
|
||||
@ -433,9 +435,9 @@ bool STKTexture::loadCompressedTexture(const std::string& file_name)
|
||||
* file name. This function should only be used for textures sent to
|
||||
* glTexImage2D with a compressed internal format as argument.<br>
|
||||
* \note The following format is used to save the compressed texture:<br>
|
||||
* <internal-format><w><h><orig_w><orig_h><size><data> <br>
|
||||
* The first six elements are integers and the last one is stored
|
||||
* on \c size bytes.
|
||||
* <version><internal-format><w><h><orig_w><orig_h><size><data> <br>
|
||||
* The first element is the version of cache, next six elements are
|
||||
* integers and the last one is stored on \c size bytes.
|
||||
* \see loadCompressedTexture
|
||||
*/
|
||||
void STKTexture::saveCompressedTexture(const std::string& compressed_tex)
|
||||
@ -502,3 +504,34 @@ void* STKTexture::lock(video::E_TEXTURE_LOCK_MODE mode, u32 mipmap_level)
|
||||
#endif // !SERVER_ONLY
|
||||
return NULL;
|
||||
} // lock
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
u64 STKTexture::getHandle()
|
||||
{
|
||||
#if !(defined(SERVER_ONLY) || defined(USE_GLES2))
|
||||
assert(CVS->isAZDOEnabled());
|
||||
if (m_texture_handle != 0) return m_texture_handle;
|
||||
|
||||
m_texture_handle =
|
||||
glGetTextureSamplerHandleARB( m_texture_name,
|
||||
ObjectPass1Shader::getInstance()->m_sampler_ids[0]);
|
||||
|
||||
if (!glIsTextureHandleResidentARB(m_texture_handle))
|
||||
glMakeTextureHandleResidentARB(m_texture_handle);
|
||||
|
||||
return m_texture_handle;
|
||||
#endif
|
||||
} // getHandle
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void STKTexture::unloadHandle()
|
||||
{
|
||||
#if !(defined(SERVER_ONLY) || defined(USE_GLES2))
|
||||
if (CVS->isAZDOEnabled())
|
||||
{
|
||||
if (m_texture_handle == 0) return;
|
||||
glMakeTextureHandleNonResidentARB(m_texture_handle);
|
||||
m_texture_handle = 0;
|
||||
}
|
||||
#endif
|
||||
} // unloadHandle
|
||||
|
@ -102,7 +102,9 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
virtual u32 getOpenGLTextureName() const { return m_texture_name; }
|
||||
// ------------------------------------------------------------------------
|
||||
uint64_t getTextureHandle() const { return m_texture_handle; }
|
||||
virtual u64 getHandle();
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void unloadHandle();
|
||||
// ------------------------------------------------------------------------
|
||||
bool isSrgb() const { return m_srgb; }
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -1,24 +0,0 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2014-2015 SuperTuxKart-Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
#ifndef HEADER_TEXTURE_MANAGER_HPP
|
||||
#define HEADER_TEXTURE_MANAGER_HPP
|
||||
|
||||
static void insertTextureHandle(uint64_t handle){}
|
||||
|
||||
#endif
|
@ -406,6 +406,7 @@ void Track::cleanup()
|
||||
irr_driver->clearLights();
|
||||
irr_driver->clearForcedBloom();
|
||||
irr_driver->clearBackgroundNodes();
|
||||
STKTexManager::getInstance()->reset();
|
||||
|
||||
if(UserConfigParams::logMemory())
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user