[Aqsis-commits] SF.net SVN: aqsis: [1816] branches/texfiltering/aqsis/texturing/texlib
Brought to you by:
ltatkinson,
pgregory
From: <c4...@us...> - 2007-12-08 05:05:36
|
Revision: 1816 http://aqsis.svn.sourceforge.net/aqsis/?rev=1816&view=rev Author: c42f Date: 2007-12-07 21:05:38 -0800 (Fri, 07 Dec 2007) Log Message: ----------- * Refactor to add infrastructure for arbitrary texture sampling methods via the IqTextureSampler interface. This will allow immediate implementation of non-mipmapped backends, followed by mipmapping. It would be trivial to integrate new methods (like ripmaps) if we ever thought it was worthwhile. * Renamed CqMipmapLevels to CqLevelSamplerCache, since the sampler cache isn't limited to supporting mipmaps only. In principle it can also help support occlusion maps, environment maps etc. * Create a new sampler class, CqMipmapTextureSampler which will sample textures via mipmapping. * Add a way to get sensible default sampler options to the IqTextureSampler interface. * Renamed the workhorse sampler class, CqTextureSamplerImpl to CqTextureSampler. * Remove the name() method from several sampler classes because it didn't really fit into the design. Will eventually incorporate it outside these classes. Modified Paths: -------------- branches/texfiltering/aqsis/texturing/texlib/CMakeLists.txt branches/texfiltering/aqsis/texturing/texlib/itexturesampler.cpp branches/texfiltering/aqsis/texturing/texlib/itexturesampler.h branches/texfiltering/aqsis/texturing/texlib/samplequad.h branches/texfiltering/aqsis/texturing/texlib/texturemap2.cpp branches/texfiltering/aqsis/texturing/texlib/texturemap2.h branches/texfiltering/aqsis/texturing/texlib/texturesampler.h Added Paths: ----------- branches/texfiltering/aqsis/texturing/texlib/levelsamplercache.cpp branches/texfiltering/aqsis/texturing/texlib/levelsamplercache.h branches/texfiltering/aqsis/texturing/texlib/mipmaptexturesampler.cpp branches/texfiltering/aqsis/texturing/texlib/mipmaptexturesampler.h Removed Paths: ------------- branches/texfiltering/aqsis/texturing/texlib/mipmaplevels.cpp branches/texfiltering/aqsis/texturing/texlib/mipmaplevels.h Modified: branches/texfiltering/aqsis/texturing/texlib/CMakeLists.txt =================================================================== --- branches/texfiltering/aqsis/texturing/texlib/CMakeLists.txt 2007-12-02 14:16:41 UTC (rev 1815) +++ branches/texfiltering/aqsis/texturing/texlib/CMakeLists.txt 2007-12-08 05:05:38 UTC (rev 1816) @@ -19,8 +19,9 @@ itexinputfile.cpp itexoutputfile.cpp itexturesampler.cpp + levelsamplercache.cpp magicnumber.cpp - mipmaplevels.cpp + mipmaptexturesampler.cpp texfileheader.cpp tiffdirhandle.cpp tiffinputfile.cpp Modified: branches/texfiltering/aqsis/texturing/texlib/itexturesampler.cpp =================================================================== --- branches/texfiltering/aqsis/texturing/texlib/itexturesampler.cpp 2007-12-02 14:16:41 UTC (rev 1815) +++ branches/texfiltering/aqsis/texturing/texlib/itexturesampler.cpp 2007-12-08 05:05:38 UTC (rev 1816) @@ -34,7 +34,13 @@ { // \todo write a switch based on the pixel type in file. return boost::shared_ptr<IqTextureSampler>( - new CqTextureSamplerImpl<TqUchar>(boost::shared_ptr<CqTileArray<TqUchar> >())); + new CqTextureSampler<TqUchar>(boost::shared_ptr<CqTileArray<TqUchar> >())); } +const CqTextureSampleOptions& IqTextureSampler::defaultSampleOptions() const +{ + static const CqTextureSampleOptions defaultOptions; + return defaultOptions; +} + } // namespace Aqsis Modified: branches/texfiltering/aqsis/texturing/texlib/itexturesampler.h =================================================================== --- branches/texfiltering/aqsis/texturing/texlib/itexturesampler.h 2007-12-02 14:16:41 UTC (rev 1815) +++ branches/texfiltering/aqsis/texturing/texlib/itexturesampler.h 2007-12-08 05:05:38 UTC (rev 1816) @@ -40,8 +40,13 @@ namespace Aqsis { //------------------------------------------------------------------------------ -/** \brief A class which knows how to sample texture buffers. +/** \brief An interface for sampling texture buffers. * + * This intent of this interface is to provide texture sampling facilities + * independently of the sampling options. Classes which implement the + * interface should attempt to use the sampling method as specified by a + * CqTexutureSampleOptions, passed to the filter() interface function. + * */ class IqTextureSampler { @@ -55,6 +60,18 @@ virtual void filter(const SqSampleQuad& sampleQuad, const CqTextureSampleOptions& sampleOpts, TqFloat* outSamps) const = 0; + /** \brief Get the default sample options for this texture. + * + * The default implementation returns texture sample options + * initialized by the default CqTextureSampleOptions constructor. + * + * \return The default sample options - in the case that the texture + * originates from an underlying file, these should include options + * which were used when the texture was created (things like the + * texutre wrap mode). + */ + virtual const CqTextureSampleOptions& defaultSampleOptions() const; + /** \brief Create and return a IqTextureSampler derived class * * The returned class is a CqTextureSamplerImpl<T> where T is a type Copied: branches/texfiltering/aqsis/texturing/texlib/levelsamplercache.cpp (from rev 1813, branches/texfiltering/aqsis/texturing/texlib/mipmaplevels.cpp) =================================================================== --- branches/texfiltering/aqsis/texturing/texlib/levelsamplercache.cpp (rev 0) +++ branches/texfiltering/aqsis/texturing/texlib/levelsamplercache.cpp 2007-12-08 05:05:38 UTC (rev 1816) @@ -0,0 +1,59 @@ +// Aqsis +// Copyright (C) 1997 - 2007, Paul C. Gregory +// +// Contact: pgr...@aq... +// +// This library 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 2 of the License, or (at your option) any later version. +// +// This library 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 library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +/** \file + * + * \brief Implementation of a class which holds a collection of mipmap levels. + * + * \author Chris Foster [ chris42f (at) gmail (dot) com ] + */ + +#include "levelsamplercache.h" + +#include "itexturesampler.h" + +namespace Aqsis +{ + +//------------------------------------------------------------------------------ +// Implementation of CqLevelSamplerCache + +CqLevelSamplerCache::CqLevelSamplerCache( + const boost::shared_ptr<IqTiledTexInputFile>& file) + : m_defaultSampleOptions(), + m_levels(), + m_texFile(file) +{ + // \todo decide how many mipmap levels are needed. + m_levels.resize(1); + // \todo: Init default sampling opts from texture file +} + +const IqTextureSampler& CqLevelSamplerCache::level(TqInt levelNum) +{ + IqTextureSampler* sampler = m_levels.at(levelNum).get(); + if(!sampler) + { + m_levels[levelNum] = IqTextureSampler::create(m_texFile); + sampler = m_levels[levelNum].get(); + } + return *sampler; +} + +} // namespace Aqsis Copied: branches/texfiltering/aqsis/texturing/texlib/levelsamplercache.h (from rev 1813, branches/texfiltering/aqsis/texturing/texlib/mipmaplevels.h) =================================================================== --- branches/texfiltering/aqsis/texturing/texlib/levelsamplercache.h (rev 0) +++ branches/texfiltering/aqsis/texturing/texlib/levelsamplercache.h 2007-12-08 05:05:38 UTC (rev 1816) @@ -0,0 +1,116 @@ +// Aqsis +// Copyright (C) 1997 - 2007, Paul C. Gregory +// +// Contact: pgr...@aq... +// +// This library 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 2 of the License, or (at your option) any later version. +// +// This library 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 library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +/** \file + * + * \brief Declare a class for holding a collection of mipmap levels. + * + * \author Chris Foster [ chris42f (at) gmail (dot) com ] + */ + +#ifndef MIPMAPLEVELS_H_INCLUDED +#define MIPMAPLEVELS_H_INCLUDED + +#include "aqsis.h" + +#include <string> +#include <vector> + +#include <boost/shared_ptr.hpp> + +#include "texturesampleoptions.h" + +namespace Aqsis +{ + +class IqTextureSampler; +class IqTiledTexInputFile; + +//------------------------------------------------------------------------------ +/** \brief Cache for a set of associated texture samplers + * + * This class holds texture samplers for a set of associated 2D textures, such + * as mipmap levels. The class is independent of any of any details of the + * sampling procedure. + * + * Samplers for textures in the cache are constructed only on-demand. + * + * CqLevelSamplerCache is the class which will be held in the high-level + * texture cache (yes, caches within caches). + * + * In addition to holding a set of samplers, this class also caches the default + * sampling options, as determined from attributes of the texture file. When + * these aren't present, we attempt to choose sensible defaults. + */ +class CqLevelSamplerCache +{ + public: + /** \brief Construct the sampler cache from an open file. + * + * If the file pointer is null, this class is still constructed + * sucessfully. However, the number of levels is then set to one, and + * that level is a dummy texture consisting of a single pixel. This + * allows us to gracefully recover from missing files. + * + * \param file - read texture data from here. + */ + CqLevelSamplerCache(const boost::shared_ptr<IqTiledTexInputFile>& file); + /** \brief Get the texture sampler for a given level. + * + * \param levelNum - mipmap level to grab + */ + const IqTextureSampler& level(TqInt levelNum); + /** \brief Get the number of levels in this mipmap. + * + */ + inline TqInt numLevels() const; + /** \brief Get the default sample options associated with the texture file. + * + * \return The default sample options - these include options which + * were used when the texture was created (things like the texutre wrap + * mode). + */ + inline const CqTextureSampleOptions& defaultSampleOptions(); + private: + /// Default texture sampling options for the set of mipmap levels. + CqTextureSampleOptions m_defaultSampleOptions; + /** \brief List of samplers for mipmap levels. The pointers to these + * may be NULL since they are created only on demand. + */ + mutable std::vector<boost::shared_ptr<IqTextureSampler> > m_levels; + boost::shared_ptr<IqTiledTexInputFile> m_texFile; +}; + + +//============================================================================== +// Implementation details +//============================================================================== +inline TqInt CqLevelSamplerCache::numLevels() const +{ + return m_levels.size(); +} + +inline const CqTextureSampleOptions& CqLevelSamplerCache::defaultSampleOptions() +{ + return m_defaultSampleOptions; +} + +} // namespace Aqsis + +#endif // MIPMAPLEVELS_H_INCLUDED Deleted: branches/texfiltering/aqsis/texturing/texlib/mipmaplevels.cpp =================================================================== --- branches/texfiltering/aqsis/texturing/texlib/mipmaplevels.cpp 2007-12-02 14:16:41 UTC (rev 1815) +++ branches/texfiltering/aqsis/texturing/texlib/mipmaplevels.cpp 2007-12-08 05:05:38 UTC (rev 1816) @@ -1,60 +0,0 @@ -// Aqsis -// Copyright (C) 1997 - 2007, Paul C. Gregory -// -// Contact: pgr...@aq... -// -// This library 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 2 of the License, or (at your option) any later version. -// -// This library 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 library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -/** \file - * - * \brief Implementation of a class which holds a collection of mipmap levels. - * - * \author Chris Foster [ chris42f (at) gmail (dot) com ] - */ - -#include "mipmaplevels.h" - -#include "itexturesampler.h" - -namespace Aqsis -{ - -//------------------------------------------------------------------------------ -// Implementation of CqMipmapLevels - -CqMipmapLevels::CqMipmapLevels(const std::string& texName) - : m_texName(texName), - m_defaultSampleOptions(), - m_mipLevels() -{ - // \todo decide how many mipmap levels are needed. - m_mipLevels.resize(1); - // \todo: Init default sampling opts from texture file -} - -const IqTextureSampler& CqMipmapLevels::level(TqInt levelNum) -{ - assert(levelNum >= 0); - IqTextureSampler* sampler = m_mipLevels[levelNum].get(); - if(!sampler) - { - m_mipLevels[levelNum] = IqTextureSampler::create( - boost::shared_ptr<IqTiledTexInputFile>()); - sampler = m_mipLevels[levelNum].get(); - } - return *sampler; -} - -} // namespace Aqsis Deleted: branches/texfiltering/aqsis/texturing/texlib/mipmaplevels.h =================================================================== --- branches/texfiltering/aqsis/texturing/texlib/mipmaplevels.h 2007-12-02 14:16:41 UTC (rev 1815) +++ branches/texfiltering/aqsis/texturing/texlib/mipmaplevels.h 2007-12-08 05:05:38 UTC (rev 1816) @@ -1,129 +0,0 @@ -// Aqsis -// Copyright (C) 1997 - 2007, Paul C. Gregory -// -// Contact: pgr...@aq... -// -// This library 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 2 of the License, or (at your option) any later version. -// -// This library 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 library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -/** \file - * - * \brief Declare a class for holding a collection of mipmap levels. - * - * \author Chris Foster [ chris42f (at) gmail (dot) com ] - */ - -#ifndef MIPMAPLEVELS_H_INCLUDED -#define MIPMAPLEVELS_H_INCLUDED - -#include "aqsis.h" - -#include <string> -#include <vector> - -#include <boost/shared_ptr.hpp> - -#include "texturesampleoptions.h" - -namespace Aqsis -{ - -class IqTextureSampler; - -//------------------------------------------------------------------------------ -/** \brief A container for a set of texture mipmap levels. - * - * This class holds texture mipmap level data, in a way which is independent of - * the sampling options. This makes sense because our typical usage is for - * sampling options to change very often, while the underlying data is fixed. - * - * CqMipmapLevels is the class which will be held in the texture cache. - * - * In addition to holding mipmap levels, this class also caches the default - * sampling options, as determined from attributes of the underlying texture - * file. When these aren't present, we attempt to choose sensible defaults. - */ -class CqMipmapLevels -{ - public: - /** \brief Construct a set of mipmap levels from a file - * - * If the file named by texName doesn't exist, this class is still - * constructed sucessfully. However, the number of levels is then set - * to one, and that level is a dummy texture consisting of a single - * pixel. This allows us to gracefully recover from a missing file. - * - * \param texName - Name of the texture file to open. - * - * \todo: Consider whether this should really take a pointer to an open - * file inestead of a file name... - */ - CqMipmapLevels(const std::string& texName); - /** \brief Get the texture sampler for a given level. - * - * \param levelNum - mipmap level to grab - */ - const IqTextureSampler& level(TqInt levelNum); - /** \brief Get the number of levels in this mipmap. - * - */ - inline TqInt numLevels() const; - /** \brief Get the default sample options associated with the texture file. - * - * \return The default sample options - these include options which - * were used when the texture was created (things like the texutre wrap - * mode). - */ - inline const CqTextureSampleOptions& defaultSampleOptions(); - /** \brief Get the texture name - * - * This is the name of the associated texture file, (if the file - * doesn't exist, this is still the name which was passed to the - * constructor). - * - * \return The texture name - */ - inline const std::string& name() const; - private: - std::string m_texName; ///< Name of texture - /// Default texture sampling options for the set of mipmap levels. - CqTextureSampleOptions m_defaultSampleOptions; - /** \brief List of samplers for mipmap levels. The pointers to these - * may be NULL since they are created only on demand. - */ - mutable std::vector<boost::shared_ptr<IqTextureSampler> > m_mipLevels; -}; - - -//============================================================================== -// Implementation details -//============================================================================== -inline TqInt CqMipmapLevels::numLevels() const -{ - return m_mipLevels.size(); -} - -inline const CqTextureSampleOptions& CqMipmapLevels::defaultSampleOptions() -{ - return m_defaultSampleOptions; -} - -inline const std::string& CqMipmapLevels::name() const -{ - return m_texName; -} - -} // namespace Aqsis - -#endif // MIPMAPLEVELS_H_INCLUDED Added: branches/texfiltering/aqsis/texturing/texlib/mipmaptexturesampler.cpp =================================================================== --- branches/texfiltering/aqsis/texturing/texlib/mipmaptexturesampler.cpp (rev 0) +++ branches/texfiltering/aqsis/texturing/texlib/mipmaptexturesampler.cpp 2007-12-08 05:05:38 UTC (rev 1816) @@ -0,0 +1,49 @@ +// Aqsis +// Copyright (C) 1997 - 2007, Paul C. Gregory +// +// Contact: pgr...@aq... +// +// This library 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 2 of the License, or (at your option) any later version. +// +// This library 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 library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +/** \file + * + * \brief Multiresolution texture sampler implementation + * + * \author Chris Foster [ chris42f (at) gmail (dot) com ] + */ + +#include "mipmaptexturesampler.h" + +namespace Aqsis { + +CqMipmapTextureSampler::CqMipmapTextureSampler( + const boost::shared_ptr<CqLevelSamplerCache>& levels) + : m_levels(levels) +{ } + +void CqMipmapTextureSampler::filter(const SqSampleQuad& sampleQuad, + const CqTextureSampleOptions& sampleOpts, TqFloat* outSamps) const +{ + SqSampleQuad quad = sampleQuad; + sampleOpts.adjustSampleQuad(quad); + m_levels->level(0).filter(quad, sampleOpts, outSamps); +} + +const CqTextureSampleOptions& CqMipmapTextureSampler::defaultSampleOptions() const +{ + return m_levels->defaultSampleOptions(); +} + +} // namespace Aqsis Added: branches/texfiltering/aqsis/texturing/texlib/mipmaptexturesampler.h =================================================================== --- branches/texfiltering/aqsis/texturing/texlib/mipmaptexturesampler.h (rev 0) +++ branches/texfiltering/aqsis/texturing/texlib/mipmaptexturesampler.h 2007-12-08 05:05:38 UTC (rev 1816) @@ -0,0 +1,65 @@ +// Aqsis +// Copyright (C) 1997 - 2007, Paul C. Gregory +// +// Contact: pgr...@aq... +// +// This library 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 2 of the License, or (at your option) any later version. +// +// This library 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 library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +/** \file + * + * \brief Declare a multiresolution texture sampler + * + * \author Chris Foster [ chris42f (at) gmail (dot) com ] + */ + +#ifndef MIPMAPTEXTURESAMPLER_H_INCLUDED +#define MIPMAPTEXTURESAMPLER_H_INCLUDED + +#include "aqsis.h" + +#include <boost/shared_ptr.hpp> + +#include "itexturesampler.h" +#include "levelsamplercache.h" + +namespace Aqsis { + +/** \brief A mulitresolution (mipmapped) texture sampler class + * + * This class uses a set of power-of-two downsampled images (a typical + * mipmap) to make texture filtering efficient. When filtering, a mipmap level + * is chosen based on the extent of the filter quadrilateral. Here we make a + * choice which eliminates aliasing and blurring: we choose a mipmap level such + * that the thinnest direction of the sampling quad falls across more than one + * pixel. + * + * \todo: Investigate optimal mipmap level selection. + */ +class CqMipmapTextureSampler : public IqTextureSampler +{ + public: + CqMipmapTextureSampler(const boost::shared_ptr<CqLevelSamplerCache>& levels); + + // from IqTextureSampler + virtual void filter(const SqSampleQuad& sampleQuad, + const CqTextureSampleOptions& sampleOpts, TqFloat* outSamps) const; + virtual const CqTextureSampleOptions& defaultSampleOptions() const; + private: + boost::shared_ptr<CqLevelSamplerCache> m_levels; +}; + +} // namespace Aqsis + +#endif // MIPMAPTEXTURESAMPLER_H_INCLUDED Modified: branches/texfiltering/aqsis/texturing/texlib/samplequad.h =================================================================== --- branches/texfiltering/aqsis/texturing/texlib/samplequad.h 2007-12-02 14:16:41 UTC (rev 1815) +++ branches/texfiltering/aqsis/texturing/texlib/samplequad.h 2007-12-08 05:05:38 UTC (rev 1816) @@ -19,7 +19,7 @@ /** \file * - * \brief Declare a filtered texture mapping class + * \brief Sampling quadrilateral struct definition * * \author Chris Foster [ chris42f (at) gmail (dot) com ] */ Modified: branches/texfiltering/aqsis/texturing/texlib/texturemap2.cpp =================================================================== --- branches/texfiltering/aqsis/texturing/texlib/texturemap2.cpp 2007-12-02 14:16:41 UTC (rev 1815) +++ branches/texfiltering/aqsis/texturing/texlib/texturemap2.cpp 2007-12-08 05:05:38 UTC (rev 1816) @@ -29,11 +29,10 @@ #include "vector3d.h" #include "matrix.h" #include "itexturesampler.h" -#include "mipmaplevels.h" +#include "mipmaptexturesampler.h" #include "ishaderdata.h" /// \todo remove when removing the wrapper. #include "logging.h" -#include "smartptr.h" namespace Aqsis { @@ -41,11 +40,12 @@ //------------------------------------------------------------------------------ // Implementation of CqTextureMap2 -CqTextureMap2::CqTextureMap2(const boost::shared_ptr<CqMipmapLevels>& mipmapLevels) - : m_mipLevels(mipmapLevels), - m_sampleOptions(m_mipLevels->defaultSampleOptions()) +CqTextureMap2::CqTextureMap2(const boost::shared_ptr<IqTextureSampler>& sampler) + : m_sampler(sampler), + m_sampleOptions(sampler->defaultSampleOptions()) { - assert(m_mipLevels); + /// \todo Proper error handling if null... + assert(m_sampler); } TqInt CqTextureMap2::numSamples() const @@ -54,17 +54,10 @@ return 1; } -const std::string& CqTextureMap2::name() const -{ - return m_mipLevels->name(); -} - void CqTextureMap2::sampleMap(const SqSampleQuad& sampleQuad, TqFloat* outSamples) const { /// \todo Add timing statistics? - SqSampleQuad quad = sampleQuad; - m_sampleOptions.adjustSampleQuad(quad); - m_mipLevels->level(0).filter(quad, m_sampleOptions, outSamples); + m_sampler->filter(sampleQuad, m_sampleOptions, outSamples); } @@ -72,11 +65,18 @@ // Implementation of CqTextureMap2Wrapper CqTextureMap2Wrapper::CqTextureMap2Wrapper(const std::string& texName) - : m_texName(), - m_levels(texName), - m_realMap(boost::shared_ptr<CqMipmapLevels>(&m_levels, nullDeleter)) + : m_texName(texName), + m_realMap(newWrappedTexture()) { } +boost::shared_ptr<IqTextureSampler> CqTextureMap2Wrapper::newWrappedTexture() +{ + boost::shared_ptr<IqTiledTexInputFile> file; + boost::shared_ptr<CqLevelSamplerCache> levels(new CqLevelSamplerCache(file)); + boost::shared_ptr<IqTextureSampler> sampler(new CqMipmapTextureSampler(levels)); + return sampler; +} + void CqTextureMap2Wrapper::Open() { // \todo implementation Modified: branches/texfiltering/aqsis/texturing/texlib/texturemap2.h =================================================================== --- branches/texfiltering/aqsis/texturing/texlib/texturemap2.h 2007-12-02 14:16:41 UTC (rev 1815) +++ branches/texfiltering/aqsis/texturing/texlib/texturemap2.h 2007-12-08 05:05:38 UTC (rev 1816) @@ -38,13 +38,11 @@ #include "sstring.h" #include "texfileheader.h" -#include "mipmaplevels.h" /// \todo may be removed when removing wrapper class. - namespace Aqsis { class IqTextureSampler; -class CqMipmapLevels; +class CqLevelSamplerCache; //------------------------------------------------------------------------------ /* \brief A multi-resolution filtering texture sampler @@ -54,7 +52,7 @@ class CqTextureMap2 { public: - CqTextureMap2(const boost::shared_ptr<CqMipmapLevels>& mipmapLevels); + CqTextureMap2(const boost::shared_ptr<IqTextureSampler>& sampler); /** \brief Get the texture attributes of the underlying file. * * This function allows access to the texture file attributes such as @@ -66,7 +64,6 @@ virtual inline const CqTexFileHeader* attributes() const; /// \todo Decide if these two methods are actually needed. virtual TqInt numSamples() const; - virtual const std::string& name() const; /** \brief Sample the texture map. * @@ -85,7 +82,7 @@ virtual ~CqTextureMap2() {} private: - boost::shared_ptr<CqMipmapLevels> m_mipLevels; ///< Collection of mipmap levels + boost::shared_ptr<IqTextureSampler> m_sampler; ///< Underlying sampler to use. CqTextureSampleOptions m_sampleOptions; ///< sampler options }; @@ -127,8 +124,8 @@ virtual TqInt NumPages() const; private: + static boost::shared_ptr<IqTextureSampler> newWrappedTexture(); mutable CqString m_texName; - CqMipmapLevels m_levels; CqTextureMap2 m_realMap; }; @@ -188,8 +185,6 @@ inline const CqString& CqTextureMap2Wrapper::getName() const { - // \todo implementation - m_texName = m_realMap.name(); return m_texName; } Modified: branches/texfiltering/aqsis/texturing/texlib/texturesampler.h =================================================================== --- branches/texfiltering/aqsis/texturing/texlib/texturesampler.h 2007-12-02 14:16:41 UTC (rev 1815) +++ branches/texfiltering/aqsis/texturing/texlib/texturesampler.h 2007-12-08 05:05:38 UTC (rev 1816) @@ -48,10 +48,11 @@ /** \brief Implementation of texture buffer samplers */ template<typename T> -class CqTextureSamplerImpl : public IqTextureSampler +class CqTextureSampler : public IqTextureSampler { public: - CqTextureSamplerImpl(const boost::shared_ptr<CqTileArray<T> >& texData); + CqTextureSampler(const boost::shared_ptr<CqTileArray<T> >& texData); + // from IqTextureSampler virtual void filter(const SqSampleQuad& sampleQuad, const CqTextureSampleOptions& sampleOpts, TqFloat* outSamps) const; private: @@ -166,7 +167,7 @@ //============================================================================== template<typename T> -inline CqTextureSamplerImpl<T>::CqTextureSamplerImpl( +inline CqTextureSampler<T>::CqTextureSampler( const boost::shared_ptr<CqTileArray<T> >& texData) : m_texData(texData), m_sMult(511), @@ -176,7 +177,7 @@ { } template<typename T> -void CqTextureSamplerImpl<T>::filter(const SqSampleQuad& sampleQuad, const CqTextureSampleOptions& sampleOpts, TqFloat* outSamps) const +void CqTextureSampler<T>::filter(const SqSampleQuad& sampleQuad, const CqTextureSampleOptions& sampleOpts, TqFloat* outSamps) const { switch(sampleOpts.filterType()) { @@ -194,7 +195,7 @@ } template<typename T> -inline TqFloat CqTextureSamplerImpl<T>::wrapCoord(TqFloat pos, EqWrapMode mode) const +inline TqFloat CqTextureSampler<T>::wrapCoord(TqFloat pos, EqWrapMode mode) const { switch(mode) { @@ -214,7 +215,7 @@ } template<typename T> -inline CqVector2D CqTextureSamplerImpl<T>::texToRasterCoords( +inline CqVector2D CqTextureSampler<T>::texToRasterCoords( const CqVector2D& pos, EqWrapMode sMode, EqWrapMode tMode) const { return CqVector2D(m_sOffset + m_sMult*wrapCoord(pos.x(), sMode), @@ -222,7 +223,7 @@ } template<typename T> -void CqTextureSamplerImpl<T>::filterSimple( const SqSampleQuad& sQuad, +void CqTextureSampler<T>::filterSimple( const SqSampleQuad& sQuad, const CqTextureSampleOptions& sampleOpts, TqFloat* outSamps) const { sampleBilinear((sQuad.v1 + sQuad.v2 + sQuad.v3 + sQuad.v4)/4, @@ -258,7 +259,7 @@ /** Get the quadratic form matrix for an EWA filter. */ template<typename T> -inline SqMatrix2D CqTextureSamplerImpl<T>::getEWAQuadForm(const SqSampleQuad& sQuad, +inline SqMatrix2D CqTextureSampler<T>::getEWAQuadForm(const SqSampleQuad& sQuad, const CqTextureSampleOptions& sampleOpts) const { // Get Jacobian of the texture warp @@ -303,7 +304,7 @@ } template<typename T> -void CqTextureSamplerImpl<T>::filterEWA( const SqSampleQuad& sQuad, +void CqTextureSampler<T>::filterEWA( const SqSampleQuad& sQuad, const CqTextureSampleOptions& sampleOpts, TqFloat* outSamps) const { // Zero the samples @@ -360,7 +361,7 @@ } template<typename T> -inline void CqTextureSamplerImpl<T>::sampleBilinear(const CqVector2D& st, +inline void CqTextureSampler<T>::sampleBilinear(const CqVector2D& st, const CqTextureSampleOptions& sampleOpts, TqFloat* outSamps) const { CqVector2D stRaster = texToRasterCoords(st, @@ -385,7 +386,7 @@ } template<typename T> -void CqTextureSamplerImpl<T>::filterMC(const SqSampleQuad& sampleQuad, +void CqTextureSampler<T>::filterMC(const SqSampleQuad& sampleQuad, const CqTextureSampleOptions& sampleOpts, TqFloat* outSamps) const { std::vector<TqFloat> tempSamps(sampleOpts.numChannels(), 0); @@ -422,7 +423,7 @@ } template<typename T> -TqFloat CqTextureSamplerImpl<T>::dummyGridTex(TqInt s, TqInt t) const +TqFloat CqTextureSampler<T>::dummyGridTex(TqInt s, TqInt t) const { const TqInt gridSize = 8; const TqInt lineWidth = 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |