Exemplo n.º 1
0
	int test(gli::format Format, genType const & Black, genType const & Color, std::size_t Size, gli::filter Filter)
	{
		int Error = 0;

		gli::texture_cube Texture(Format, gli::texture_cube::extent_type(static_cast<gli::texture_cube::extent_type::value_type>(Size)));
		Texture.clear(Black);
		for(std::size_t Face = 0; Face < 6; ++Face)
			Texture[Face][0].clear(Color);

		for(std::size_t Face = 0; Face < 6; ++Face)
		{
			genType const LoadC = Texture.load<genType>(gli::texture_cube::extent_type(0), Face, Texture.max_level());
			if(Texture.levels() > 1)
				Error += LoadC == Black ? 0 : 1;

			gli::fsamplerCube SamplerA(gli::texture_cube(gli::duplicate(Texture)), gli::WRAP_CLAMP_TO_EDGE);
			SamplerA.generate_mipmaps(gli::FILTER_LINEAR);

			gli::texture_cube MipmapsA = SamplerA();
			genType const LoadA = MipmapsA.load<genType>(gli::texture_cube::extent_type(0), Face, MipmapsA.max_level());
			Error += LoadA == Color ? 0 : 1;
			if(Texture.levels() > 1)
				Error += LoadA != LoadC ? 0 : 1;

			// Mipmaps generation using the wrapper function
			gli::texture_cube MipmapsB = gli::generate_mipmaps(gli::texture_cube(gli::duplicate(Texture)), Filter);
			genType const LoadB = MipmapsB.load<genType>(gli::texture_cube::extent_type(0), Face, MipmapsB.max_level());
			Error += LoadB == Color ? 0 : 1;
			if(Texture.levels() > 1)
				Error += LoadB != LoadC ? 0 : 1;
		}

		return Error;
	}
	int test(gli::format Format, genType const & Black, genType const & Color, std::size_t Layers, std::size_t Size, gli::filter Filter)
	{
		int Error = 0;

		gli::texture1DArray Texture(Format, gli::texture1DArray::texelcoord_type(static_cast<gli::texture1DArray::texelcoord_type::value_type>(Size)), Layers);
		Texture.clear(Black);
		for(std::size_t Layer = 0; Layer < Layers; ++Layer)
			Texture[Layer][0].clear(Color);

		for(std::size_t Layer = 0; Layer < Layers; ++Layer)
		{
			genType const LoadC = Texture.load<genType>(gli::texture1DArray::texelcoord_type(0), Layer, Texture.max_level());
			if(Texture.levels() > 1)
				Error += LoadC == Black ? 0 : 1;

			gli::fsampler1DArray SamplerA(gli::texture1DArray(gli::copy(Texture)), gli::WRAP_CLAMP_TO_EDGE);
			SamplerA.generate_mipmaps(gli::FILTER_LINEAR);

			gli::texture1DArray MipmapsA = SamplerA();
			genType const LoadA = MipmapsA.load<genType>(gli::texture1DArray::texelcoord_type(0), Layer, MipmapsA.max_level());
			Error += LoadA == Color ? 0 : 1;
			if(Texture.levels() > 1)
				Error += LoadA != LoadC ? 0 : 1;

			// Mipmaps generation using the wrapper function
			gli::texture1DArray MipmapsB = gli::generate_mipmaps(gli::texture1DArray(gli::copy(Texture)), Filter);
			genType const LoadB = MipmapsB.load<genType>(gli::texture1DArray::texelcoord_type(0), Layer, MipmapsB.max_level());
			Error += LoadB == Color ? 0 : 1;
			if(Texture.levels() > 1)
				Error += LoadB != LoadC ? 0 : 1;
		}

		return Error;
	}
	int test()
	{
		int Error = 0;

		gli::texture2D Texture(gli::FORMAT_RGBA8_UNORM, gli::texture2D::dim_type(64));
		for(std::size_t j = 0, n = Texture.dimensions().y; j < n; ++j)
		for(std::size_t i = 0, m = Texture.dimensions().x; i < n; ++i)
			Texture.store<gli::u8vec4>(gli::dim2_t(i , j), 0, gli::u8vec4(i * 4, j * 4, 0, 255));

		gli::texture2D TextureView(gli::view(Texture, 0, 0));

		// Custom mipmaps generation using a sampler object
		gli::fsampler2D SamplerA(gli::texture2D(gli::copy(Texture)), gli::WRAP_CLAMP_TO_EDGE, gli::FILTER_LINEAR, gli::FILTER_LINEAR);
		SamplerA.generate_mipmaps();

		gli::texture2D MipmapsA = SamplerA();
		gli::texture2D MipmapViewA(gli::view(MipmapsA, 0, 0));

		Error += TextureView == MipmapViewA ? 0 : 1;

		// Mipmaps generation using the wrapper function
		gli::texture2D MipmapsB = gli::generate_mipmaps(gli::texture2D(gli::copy(Texture)));
		gli::texture2D MipmapViewB(gli::view(MipmapsB, 0, 0));

		Error += TextureView == MipmapViewB ? 0 : 1;

		// Compare custom mipmaps generation and wrapper mipmaps generation
		Error += MipmapViewA == MipmapViewB ? 0 : 1;
		Error += MipmapsA == MipmapsB ? 0 : 1;

		return Error;
	}
Exemplo n.º 4
0
	int test()
	{
		int Error(0);

		glm::vec4 const Orange(1.0f, 0.5f, 0.0f, 1.0f);
		glm::vec4 const Blue(0.0f, 0.5f, 1.0f, 1.0f);

		gli::texture2d Texture(gli::FORMAT_RGBA8_UNORM_PACK8, gli::texture2d::extent_type(32), 1);
		Texture.clear(glm::packUnorm4x8(Orange));

		gli::fsampler2D SamplerA(Texture, gli::WRAP_CLAMP_TO_BORDER, gli::FILTER_LINEAR, gli::FILTER_LINEAR, Blue);

		{
			std::array<gli::fsampler2D::normalized_type, 8> SampleCoord{
			{
				gli::fsampler2D::normalized_type( 0.5f, 0.5f),
				gli::fsampler2D::normalized_type( 0.1f, 0.1f),
				gli::fsampler2D::normalized_type( 0.5f, 0.1f),
				gli::fsampler2D::normalized_type( 0.1f, 0.5f),
				gli::fsampler2D::normalized_type( 0.5f, 0.9f),
				gli::fsampler2D::normalized_type( 0.9f, 0.9f),
				gli::fsampler2D::normalized_type( 0.9f, 0.5f),
				gli::fsampler2D::normalized_type( 0.1f, 0.9f)
			}};

			for(std::size_t i = 0, n = SampleCoord.size(); i < n; ++i)
			{
				gli::vec4 const Texel = SamplerA.texture_lod(SampleCoord[i], 0.0f);
				Error += glm::all(glm::epsilonEqual(Texel, Orange, 0.01f)) ? 0 : 1;
			}
		}
		{
			std::array<gli::fsampler2D::normalized_type, 8> SampleCoord{
			{
				gli::fsampler2D::normalized_type( 0.5f,-0.5f),
				gli::fsampler2D::normalized_type(-0.5f,-0.5f),
				gli::fsampler2D::normalized_type(-0.5f, 0.5f),
				gli::fsampler2D::normalized_type( 1.5f, 0.5f),
				gli::fsampler2D::normalized_type( 1.5f, 1.5f),
				gli::fsampler2D::normalized_type( 0.5f, 1.5f),
				gli::fsampler2D::normalized_type( 1.5f,-0.5f),
				gli::fsampler2D::normalized_type(-0.5f, 1.5f)
			}};

			for(std::size_t i = 0, n = SampleCoord.size(); i < n; ++i)
			{
				gli::vec4 const Texel = SamplerA.texture_lod(SampleCoord[i], 0.0f);
				Error += glm::all(glm::epsilonEqual(Texel, Blue, 0.01f)) ? 0 : 1;
			}
		}

		return Error;
	}