Added attribute to irrlicht's driver to enable automatic resize

of images that are too big. This is then used to automatically
resize any textures (except fonts, background screen) to be
automatically resized to 512x512 if they are bigger.
This commit is contained in:
hiker 2015-03-26 11:28:22 +11:00
parent 366b5aadb5
commit 27dec2fbf8
12 changed files with 65 additions and 16 deletions

View File

@ -501,11 +501,11 @@ public:
//! Gets an attribute as dimension2d
//! \param attributeName: Name of the attribute to get.
//! \return Returns value of the attribute previously set by setAttribute()
virtual core::dimension2d<u32> getAttributeAsDimension2d(const c8* attributeName) = 0;
virtual core::dimension2d<u32> getAttributeAsDimension2d(const c8* attributeName) const = 0;
//! Gets an attribute as dimension2d
//! \param index: Index value, must be between 0 and getAttributeCount()-1.
virtual core::dimension2d<u32> getAttributeAsDimension2d(s32 index) = 0;
virtual core::dimension2d<u32> getAttributeAsDimension2d(s32 index) const = 0;
//! Sets an attribute as dimension2d
virtual void setAttribute(s32 index, core::dimension2d<u32> v) = 0;

View File

@ -324,6 +324,8 @@ namespace video
AntiAlias (int) Number of Samples the driver uses for each pixel. 0 and 1 means anti aliasing is off, typical values are 2,4,8,16,32
*/
virtual const io::IAttributes& getDriverAttributes() const=0;
//! Non-const version (with a different name to avoid involuntary mistakes). */
virtual io::IAttributes& getNonConstDriverAttributes() = 0;
//! Check if the driver was recently reset.
/** For d3d devices you will need to recreate the RTTs if the

View File

@ -429,7 +429,7 @@ void CAttributes::setAttribute(const c8* attributeName, core::dimension2d<u32> v
//! Gets an attribute as dimension2d
//! \param attributeName: Name of the attribute to get.
//! \return Returns value of the attribute previously set by setAttribute()
core::dimension2d<u32> CAttributes::getAttributeAsDimension2d(const c8* attributeName)
core::dimension2d<u32> CAttributes::getAttributeAsDimension2d(const c8* attributeName) const
{
IAttribute* att = getAttributeP(attributeName);
if (att)
@ -737,7 +737,7 @@ core::rect<s32> CAttributes::getAttributeAsRect(s32 index)
//! Gets an attribute as dimension2d
//! \param index: Index value, must be between 0 and getAttributeCount()-1.
core::dimension2d<u32> CAttributes::getAttributeAsDimension2d(s32 index)
core::dimension2d<u32> CAttributes::getAttributeAsDimension2d(s32 index) const
{
if ((u32)index < Attributes.size())
return Attributes[index]->getDimension2d();

View File

@ -465,11 +465,11 @@ public:
//! Gets an attribute as dimension2d
//! \param attributeName: Name of the attribute to get.
//! \return Returns value of the attribute previously set by setAttribute()
virtual core::dimension2d<u32> getAttributeAsDimension2d(const c8* attributeName);
virtual core::dimension2d<u32> getAttributeAsDimension2d(const c8* attributeName) const;
//! Gets an attribute as dimension2d
//! \param index: Index value, must be between 0 and getAttributeCount()-1.
virtual core::dimension2d<u32> getAttributeAsDimension2d(s32 index);
virtual core::dimension2d<u32> getAttributeAsDimension2d(s32 index) const;
//! Sets an attribute as dimension2d
virtual void setAttribute(s32 index, core::dimension2d<u32> v);

View File

@ -298,6 +298,11 @@ const io::IAttributes& CNullDriver::getDriverAttributes() const
return *DriverAttributes;
}
//! Get attributes of the actual video driver
io::IAttributes& CNullDriver::getNonConstDriverAttributes()
{
return *DriverAttributes;
}
//! sets transformation
void CNullDriver::setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat)

View File

@ -64,6 +64,9 @@ namespace video
//! Get attributes of the actual video driver
const io::IAttributes& getDriverAttributes() const;
//! Non-const version (with a different name to avoid involuntary mistakes). */
virtual io::IAttributes& getNonConstDriverAttributes();
//! sets transformation
virtual void setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat);

View File

@ -11,6 +11,8 @@
#include "COpenGLDriver.h"
#include "os.h"
#include "CColorConverter.h"
#include "IAttributes.h"
#include "IrrlichtDevice.h"
#include "irrString.h"
@ -314,7 +316,17 @@ void COpenGLTexture::getImageValues(IImage* image)
ImageSize.Width = (u32)(Driver->MaxTextureSize*ratio);
}
TextureSize=ImageSize.getOptimalSize(!Driver->queryFeature(EVDF_TEXTURE_NPOT));
const core::dimension2du max_size = Driver->getDriverAttributes()
.getAttributeAsDimension2d("MAX_TEXTURE_SIZE");
if (max_size.Width> 0 && TextureSize.Width > max_size.Width)
{
TextureSize.Width = max_size.Width;
}
if (max_size.Height> 0 && TextureSize.Height > max_size.Height)
{
TextureSize.Height = max_size.Height;
}
ColorFormat = getBestColorFormat(image->getColorFormat());
}

View File

@ -206,7 +206,7 @@ void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect
tex_width, tex_height,
tex_center_pos_x, tex_center_pos_y;
getSize(texture->getOriginalSize().Width, texture->getOriginalSize().Height, texture->isRenderTarget(),
getSize(texture->getSize().Width, texture->getSize().Height, texture->isRenderTarget(),
destRect, sourceRect, width, height, center_pos_x, center_pos_y,
tex_width, tex_height, tex_center_pos_x, tex_center_pos_y);

View File

@ -592,10 +592,23 @@ void IrrDriver::initDevice()
m_pointer_shown = true;
} // initDevice
// ----------------------------------------------------------------------------
void IrrDriver::setMaxTextureSize()
{
if( (UserConfigParams::m_high_definition_textures & 0x01) == 0)
{
io::IAttributes &att = m_video_driver->getNonConstDriverAttributes();
att.setAttribute("MAX_TEXTURE_SIZE", core::dimension2du(512, 512));
}
} // setMaxTextureSize
// ----------------------------------------------------------------------------
void IrrDriver::cleanSunInterposer()
{
delete m_sun_interposer;
}
} // cleanSunInterposer
// ----------------------------------------------------------------------------
void IrrDriver::createSunInterposer()
{
scene::IMesh * sphere = m_scene_manager->getGeometryCreator()->createSphereMesh(1, 16, 16);

View File

@ -36,7 +36,6 @@
#include <SColor.h>
#include "IrrlichtDevice.h"
#include "ISkinnedMesh.h"
//#include "graphics/rtts.hpp"
#include "graphics/shaders.hpp"
#include "graphics/wind.hpp"
#include "io/file_manager.hpp"
@ -354,6 +353,7 @@ public:
~IrrDriver();
void initDevice();
void reset();
void setMaxTextureSize();
void getOpenGLData(std::string *vendor, std::string *renderer,
std::string *version);

View File

@ -4,16 +4,17 @@
#include "guiengine/scalable_font.hpp"
#include <IGUIEnvironment.h>
#include <IXMLReader.h>
#include <IReadFile.h>
#include <IVideoDriver.h>
#include <IGUISpriteBank.h>
#include "graphics/2dutils.hpp"
#include "guiengine/engine.hpp"
#include "io/file_manager.hpp"
#include "utils/translation.hpp"
#include "graphics/2dutils.hpp"
#include <IAttributes.h>
#include <IGUIEnvironment.h>
#include <IGUISpriteBank.h>
#include <IReadFile.h>
#include <IVideoDriver.h>
#include <IXMLReader.h>
namespace irr
{
@ -732,7 +733,16 @@ void ScalableFont::lazyLoadTexture(int texID)
// load texture
assert(m_texture_files[texID].m_file_name.size() > 0);
// Font textures can not be resized (besides the impact on quality in
// this case, the indices in the xml files would become wrong).
core::dimension2du old_max_size = Driver->getDriverAttributes()
.getAttributeAsDimension2d("MAX_TEXTURE_SIZE");
Driver->getNonConstDriverAttributes().setAttribute("MAX_TEXTURE_SIZE",
core::dimension2du(0, 0));
SpriteBank->setTexture(texID, Driver->getTexture( m_texture_files[texID].m_file_name ));
Driver->getNonConstDriverAttributes().setAttribute("MAX_TEXTURE_SIZE", old_max_size);
// set previous mip-map+filter state
//Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, mipmap);

View File

@ -1128,6 +1128,10 @@ void initRest()
powerup_manager = new PowerupManager ();
attachment_manager = new AttachmentManager ();
highscore_manager = new HighscoreManager ();
// The maximum texture size can not be set earlier, since
// e.g. the background image needs to be loaded in high res.
irr_driver->setMaxTextureSize();
KartPropertiesManager::addKartSearchDir(
file_manager->getAddonsFile("karts/"));
track_manager->addTrackSearchDir(