#pragma once #include "filter_compute.hpp" namespace gli{ namespace detail { template inline void generate_mipmaps_1d ( texture_type & Texture, fetch_func Fetch, write_func Write, typename texture_type::size_type BaseLayer, typename texture_type::size_type MaxLayer, typename texture_type::size_type BaseFace, typename texture_type::size_type MaxFace, typename texture_type::size_type BaseLevel, typename texture_type::size_type MaxLevel, filter Min ) { typedef typename detail::interpolate::type interpolate_type; typedef typename texture_type::extent_type extent_type; typedef typename texture_type::size_type size_type; typedef typename extent_type::value_type component_type; typedef typename detail::filterBase::filterFunc filter_func; filter_func const Filter = detail::get_filter(FILTER_NEAREST, Min, false); GLI_ASSERT(Filter); for(size_type Layer = BaseLayer; Layer <= MaxLayer; ++Layer) for(size_type Face = BaseFace; Face <= MaxFace; ++Face) for(size_type Level = BaseLevel; Level < MaxLevel; ++Level) { extent_type const& ExtentDst = Texture.extent(Level + 1); normalized_type const& Scale = normalized_type(1) / normalized_type(max(ExtentDst - extent_type(1), extent_type(1))); for(component_type i = 0; i < ExtentDst.x; ++i) { normalized_type const& SamplePosition(normalized_type(static_cast(i)) * Scale); texel_type const& Texel = Filter(Texture, Fetch, SamplePosition, Layer, Face, static_cast(Level), texel_type(0)); Write(Texture, extent_type(i), Layer, Face, Level + 1, Texel); } } } template inline void generate_mipmaps_2d ( texture_type & Texture, fetch_func Fetch, write_func Write, typename texture_type::size_type BaseLayer, typename texture_type::size_type MaxLayer, typename texture_type::size_type BaseFace, typename texture_type::size_type MaxFace, typename texture_type::size_type BaseLevel, typename texture_type::size_type MaxLevel, filter Min ) { typedef typename detail::interpolate::type interpolate_type; typedef typename texture_type::extent_type extent_type; typedef typename texture_type::size_type size_type; typedef typename extent_type::value_type component_type; typedef typename detail::filterBase::filterFunc filter_func; filter_func const Filter = detail::get_filter(FILTER_NEAREST, Min, false); GLI_ASSERT(Filter); for(size_type Layer = BaseLayer; Layer <= MaxLayer; ++Layer) for(size_type Face = BaseFace; Face <= MaxFace; ++Face) for(size_type Level = BaseLevel; Level < MaxLevel; ++Level) { extent_type const& ExtentDst = Texture.extent(Level + 1); normalized_type const& Scale = normalized_type(1) / normalized_type(max(ExtentDst - extent_type(1), extent_type(1))); for(component_type j = 0; j < ExtentDst.y; ++j) for(component_type i = 0; i < ExtentDst.x; ++i) { normalized_type const& SamplePosition(normalized_type(i, j) * Scale); texel_type const& Texel = Filter(Texture, Fetch, SamplePosition, Layer, Face, static_cast(Level), texel_type(0)); Write(Texture, extent_type(i, j), Layer, Face, Level + 1, Texel); } } } template inline void generate_mipmaps_3d ( texture_type & Texture, fetch_func Fetch, write_func Write, typename texture_type::size_type BaseLayer, typename texture_type::size_type MaxLayer, typename texture_type::size_type BaseFace, typename texture_type::size_type MaxFace, typename texture_type::size_type BaseLevel, typename texture_type::size_type MaxLevel, filter Min ) { typedef typename detail::interpolate::type interpolate_type; typedef typename texture_type::extent_type extent_type; typedef typename texture_type::size_type size_type; typedef typename extent_type::value_type component_type; typedef typename detail::filterBase::filterFunc filter_func; filter_func const Filter = detail::get_filter(FILTER_NEAREST, Min, false); GLI_ASSERT(Filter); for(size_type Layer = BaseLayer; Layer <= MaxLayer; ++Layer) for(size_type Face = BaseFace; Face <= MaxFace; ++Face) for(size_type Level = BaseLevel; Level < MaxLevel; ++Level) { extent_type const& ExtentDst = Texture.extent(Level + 1); normalized_type const& Scale = normalized_type(1) / normalized_type(max(ExtentDst - extent_type(1), extent_type(1))); for(component_type k = 0; k < ExtentDst.z; ++k) for(component_type j = 0; j < ExtentDst.y; ++j) for(component_type i = 0; i < ExtentDst.x; ++i) { normalized_type const& SamplePosition(normalized_type(i, j, k) * Scale); texel_type const& Texel = Filter(Texture, Fetch, SamplePosition, Layer, Face, static_cast(Level), texel_type(0)); Write(Texture, extent_type(i, j, k), Layer, Face, Level + 1, Texel); } } } }//namespace detail }//namespace gli