Updated GLI version used in GLM tests
This commit is contained in:
184
test/external/gli/core/generate_mipmaps.inl
vendored
184
test/external/gli/core/generate_mipmaps.inl
vendored
@@ -1,69 +1,127 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Created : 2010-09-27
|
||||
// Updated : 2010-09-27
|
||||
// Licence : This source is under MIT License
|
||||
// File : gli/core/generate_mipmaps.inl
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
#include "../sampler1d.hpp"
|
||||
#include "../sampler1d_array.hpp"
|
||||
#include "../sampler2d.hpp"
|
||||
#include "../sampler2d_array.hpp"
|
||||
#include "../sampler3d.hpp"
|
||||
#include "../sampler_cube.hpp"
|
||||
#include "../sampler_cube_array.hpp"
|
||||
|
||||
namespace gli
|
||||
{
|
||||
/*
|
||||
inline texture2D generateMipmaps
|
||||
(
|
||||
texture2D const & Image,
|
||||
texture2D::level_type const & BaseLevel
|
||||
)
|
||||
inline texture1d generate_mipmaps(
|
||||
texture1d const& Texture,
|
||||
texture1d::size_type BaseLevel, texture1d::size_type MaxLevel,
|
||||
filter Minification)
|
||||
{
|
||||
assert(BaseLevel < Image.levels());
|
||||
texture2D::format_type Format = Image[BaseLevel].format();
|
||||
|
||||
assert(Format == R8U || Format == RG8U || Format == RGB8U || Format == RGBA8U);
|
||||
texture2D::level_type Levels = std::size_t(glm::log2(float(glm::compMax(Image[0].dimensions())))) + 1;
|
||||
|
||||
texture2D Result(Levels);
|
||||
for(texture2D::level_type Level = 0; Level <= BaseLevel; ++Level)
|
||||
Result[Level] = detail::duplicate(Image[Level]);
|
||||
|
||||
for(texture2D::level_type Level = BaseLevel; Level < Levels - 1; ++Level)
|
||||
{
|
||||
std::size_t BaseWidth = Result[Level + 0].dimensions().x;
|
||||
texture2D::value_type * DataSrc = Result[Level + 0].data();
|
||||
|
||||
texture2D::dimensions_type LevelDimensions = Result[Level + 0].dimensions() >> texture2D::dimensions_type(1);
|
||||
LevelDimensions = glm::max(LevelDimensions, texture2D::dimensions_type(1));
|
||||
texture2D::size_type Components = Result[Level + 0].components();
|
||||
|
||||
texture2D::data_type DataDst(glm::compMul(LevelDimensions) * Components);
|
||||
|
||||
for(std::size_t j = 0; j < LevelDimensions.y; ++j)
|
||||
for(std::size_t i = 0; i < LevelDimensions.x; ++i)
|
||||
for(std::size_t c = 0; c < Components; ++c)
|
||||
{
|
||||
std::size_t x = (i << 1);
|
||||
std::size_t y = (j << 1);
|
||||
|
||||
std::size_t Index00 = ((x + 0) + (y + 0) * BaseWidth) * Components + c;
|
||||
std::size_t Index01 = ((x + 0) + (y + 1) * BaseWidth) * Components + c;
|
||||
std::size_t Index11 = ((x + 1) + (y + 1) * BaseWidth) * Components + c;
|
||||
std::size_t Index10 = ((x + 1) + (y + 0) * BaseWidth) * Components + c;
|
||||
|
||||
glm::u32 Data00 = reinterpret_cast<texture2D::value_type*>(DataSrc)[Index00];
|
||||
glm::u32 Data01 = reinterpret_cast<texture2D::value_type*>(DataSrc)[Index01];
|
||||
glm::u32 Data11 = reinterpret_cast<texture2D::value_type*>(DataSrc)[Index11];
|
||||
glm::u32 Data10 = reinterpret_cast<texture2D::value_type*>(DataSrc)[Index10];
|
||||
|
||||
texture2D::value_type Result = (Data00 + Data01 + Data11 + Data10) >> 2;
|
||||
texture2D::value_type * Data = reinterpret_cast<texture2D::value_type*>(DataDst.data());
|
||||
|
||||
*(Data + ((i + j * LevelDimensions.x) * Components + c)) = Result;
|
||||
}
|
||||
|
||||
Result[Level + 1] = image2D(LevelDimensions, Format, DataDst);
|
||||
}
|
||||
|
||||
return Result;
|
||||
fsampler1D Sampler(Texture, WRAP_CLAMP_TO_EDGE);
|
||||
Sampler.generate_mipmaps(BaseLevel, MaxLevel, Minification);
|
||||
return Sampler();
|
||||
}
|
||||
|
||||
inline texture1d_array generate_mipmaps(
|
||||
texture1d_array const& Texture,
|
||||
texture1d_array::size_type BaseLayer, texture1d_array::size_type MaxLayer,
|
||||
texture1d_array::size_type BaseLevel, texture1d_array::size_type MaxLevel,
|
||||
filter Minification)
|
||||
{
|
||||
fsampler1DArray Sampler(Texture, WRAP_CLAMP_TO_EDGE);
|
||||
Sampler.generate_mipmaps(BaseLayer, MaxLayer, BaseLevel, MaxLevel, Minification);
|
||||
return Sampler();
|
||||
}
|
||||
|
||||
inline texture2d generate_mipmaps(
|
||||
texture2d const& Texture,
|
||||
texture2d::size_type BaseLevel, texture2d::size_type MaxLevel,
|
||||
filter Minification)
|
||||
{
|
||||
fsampler2D Sampler(Texture, WRAP_CLAMP_TO_EDGE);
|
||||
Sampler.generate_mipmaps(BaseLevel, MaxLevel, Minification);
|
||||
return Sampler();
|
||||
}
|
||||
|
||||
inline texture2d_array generate_mipmaps(
|
||||
texture2d_array const& Texture,
|
||||
texture2d_array::size_type BaseLayer, texture2d_array::size_type MaxLayer,
|
||||
texture2d_array::size_type BaseLevel, texture2d_array::size_type MaxLevel,
|
||||
filter Minification)
|
||||
{
|
||||
fsampler2DArray Sampler(Texture, WRAP_CLAMP_TO_EDGE);
|
||||
Sampler.generate_mipmaps(BaseLayer, MaxLayer, BaseLevel, MaxLevel, Minification);
|
||||
return Sampler();
|
||||
}
|
||||
|
||||
inline texture3d generate_mipmaps(
|
||||
texture3d const& Texture,
|
||||
texture3d::size_type BaseLevel, texture3d::size_type MaxLevel,
|
||||
filter Minification)
|
||||
{
|
||||
fsampler3D Sampler(Texture, WRAP_CLAMP_TO_EDGE);
|
||||
Sampler.generate_mipmaps(BaseLevel, MaxLevel, Minification);
|
||||
return Sampler();
|
||||
}
|
||||
|
||||
inline texture_cube generate_mipmaps(
|
||||
texture_cube const& Texture,
|
||||
texture_cube::size_type BaseFace, texture_cube::size_type MaxFace,
|
||||
texture_cube::size_type BaseLevel, texture_cube::size_type MaxLevel,
|
||||
filter Minification)
|
||||
{
|
||||
fsamplerCube Sampler(Texture, WRAP_CLAMP_TO_EDGE);
|
||||
Sampler.generate_mipmaps(BaseFace, MaxFace, BaseLevel, MaxLevel, Minification);
|
||||
return Sampler();
|
||||
}
|
||||
|
||||
inline texture_cube_array generate_mipmaps(
|
||||
texture_cube_array const& Texture,
|
||||
texture_cube_array::size_type BaseLayer, texture_cube_array::size_type MaxLayer,
|
||||
texture_cube_array::size_type BaseFace, texture_cube_array::size_type MaxFace,
|
||||
texture_cube_array::size_type BaseLevel, texture_cube_array::size_type MaxLevel,
|
||||
filter Minification)
|
||||
{
|
||||
fsamplerCubeArray Sampler(Texture, WRAP_CLAMP_TO_EDGE);
|
||||
Sampler.generate_mipmaps(BaseLayer, MaxLayer, BaseFace, MaxFace, BaseLevel, MaxLevel, Minification);
|
||||
return Sampler();
|
||||
}
|
||||
|
||||
template <>
|
||||
inline texture1d generate_mipmaps<texture1d>(texture1d const& Texture, filter Minification)
|
||||
{
|
||||
return generate_mipmaps(Texture, Texture.base_level(), Texture.max_level(), Minification);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline texture1d_array generate_mipmaps<texture1d_array>(texture1d_array const& Texture, filter Minification)
|
||||
{
|
||||
return generate_mipmaps(Texture, Texture.base_layer(), Texture.max_layer(), Texture.base_level(), Texture.max_level(), Minification);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline texture2d generate_mipmaps<texture2d>(texture2d const& Texture, filter Minification)
|
||||
{
|
||||
return generate_mipmaps(Texture, Texture.base_level(), Texture.max_level(), Minification);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline texture2d_array generate_mipmaps<texture2d_array>(texture2d_array const& Texture, filter Minification)
|
||||
{
|
||||
return generate_mipmaps(Texture, Texture.base_layer(), Texture.max_layer(), Texture.base_level(), Texture.max_level(), Minification);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline texture3d generate_mipmaps<texture3d>(texture3d const& Texture, filter Minification)
|
||||
{
|
||||
return generate_mipmaps(Texture, Texture.base_level(), Texture.max_level(), Minification);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline texture_cube generate_mipmaps<texture_cube>(texture_cube const& Texture, filter Minification)
|
||||
{
|
||||
return generate_mipmaps(Texture, Texture.base_face(), Texture.max_face(), Texture.base_level(), Texture.max_level(), Minification);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline texture_cube_array generate_mipmaps<texture_cube_array>(texture_cube_array const& Texture, filter Minification)
|
||||
{
|
||||
return generate_mipmaps(Texture, Texture.base_layer(), Texture.max_layer(), Texture.base_face(), Texture.max_face(), Texture.base_level(), Texture.max_level(), Minification);
|
||||
}
|
||||
*/
|
||||
}//namespace gli
|
||||
|
||||
Reference in New Issue
Block a user