13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#ifndef _TCUTEXTUREUTIL_HPP
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define _TCUTEXTUREUTIL_HPP
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program Tester Core
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ----------------------------------------
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License");
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License.
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *      http://www.apache.org/licenses/LICENSE-2.0
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS,
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License.
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*!
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Texture utilities.
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuDefs.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTexture.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace tcu
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// PixelBufferAccess utilities.
333c827367444ee418f129b2c238299f49d3264554Jarkko PoyryPixelBufferAccess		getSubregion	(const PixelBufferAccess& access, int x, int y, int z, int width, int height, int depth);
343c827367444ee418f129b2c238299f49d3264554Jarkko PoyryConstPixelBufferAccess	getSubregion	(const ConstPixelBufferAccess& access, int x, int y, int z, int width, int height, int depth);
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
363c827367444ee418f129b2c238299f49d3264554Jarkko PoyryPixelBufferAccess		getSubregion	(const PixelBufferAccess& access, int x, int y, int width, int height);
373c827367444ee418f129b2c238299f49d3264554Jarkko PoyryConstPixelBufferAccess	getSubregion	(const ConstPixelBufferAccess& access, int x, int y, int width, int height);
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
393c827367444ee418f129b2c238299f49d3264554Jarkko PoyryPixelBufferAccess		flipYAccess		(const PixelBufferAccess& access);
403c827367444ee418f129b2c238299f49d3264554Jarkko PoyryConstPixelBufferAccess	flipYAccess		(const ConstPixelBufferAccess& access);
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// sRGB - linear conversion.
433c827367444ee418f129b2c238299f49d3264554Jarkko PoyryVec4					sRGBToLinear	(const Vec4& cs);
443c827367444ee418f129b2c238299f49d3264554Jarkko PoyryVec4					linearToSRGB	(const Vec4& cl);
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*!
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Color channel storage type
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum TextureChannelClass
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TEXTURECHANNELCLASS_SIGNED_FIXED_POINT = 0,
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT,
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TEXTURECHANNELCLASS_SIGNED_INTEGER,
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TEXTURECHANNELCLASS_UNSIGNED_INTEGER,
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TEXTURECHANNELCLASS_FLOATING_POINT,
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TEXTURECHANNELCLASS_LAST
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
603c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureChannelClass getTextureChannelClass (TextureFormat::ChannelType channelType);
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*!
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Standard parameters for texture format testing
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct TextureFormatInfo
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Vec4	valueMin;
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Vec4	valueMax;
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Vec4	lookupScale;
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Vec4	lookupBias;
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TextureFormatInfo (const Vec4& valueMin_, const Vec4& valueMax_, const Vec4& lookupScale_, const Vec4& lookupBias_)
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: valueMin		(valueMin_)
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, valueMax		(valueMax_)
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, lookupScale	(lookupScale_)
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, lookupBias	(lookupBias_)
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
81ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko PöyryTextureFormatInfo	getTextureFormatInfo				(const TextureFormat& format);
82ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko PöyryIVec4				getTextureFormatBitDepth			(const TextureFormat& format);
83ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko PöyryIVec4				getTextureFormatMantissaBitDepth	(const TextureFormat& format);
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Texture fill.
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid	clear							(const PixelBufferAccess& access, const Vec4& color);
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid	clear							(const PixelBufferAccess& access, const IVec4& color);
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid	clearDepth						(const PixelBufferAccess& access, float depth);
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid	clearStencil					(const PixelBufferAccess& access, int stencil);
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid	fillWithComponentGradients		(const PixelBufferAccess& access, const Vec4& minVal, const Vec4& maxVal);
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid	fillWithGrid					(const PixelBufferAccess& access, int cellSize, const Vec4& colorA, const Vec4& colorB);
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid	fillWithRepeatableGradient		(const PixelBufferAccess& access, const Vec4& colorA, const Vec4& colorB);
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid	fillWithMetaballs				(const PixelBufferAccess& access, int numMetaballs, deUint32 seed);
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid	fillWithRGBAQuads				(const PixelBufferAccess& access);
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid	copy							(const PixelBufferAccess& dst, const ConstPixelBufferAccess& src);
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid	scale							(const PixelBufferAccess& dst, const ConstPixelBufferAccess& src, Sampler::FilterMode filter);
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid	estimatePixelValueRange			(const ConstPixelBufferAccess& access, Vec4& minVal, Vec4& maxVal);
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid	computePixelScaleBias			(const ConstPixelBufferAccess& access, Vec4& scale, Vec4& bias);
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1028852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyryint		getCubeArrayFaceIndex			(CubeFace face);
1038852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! FP32->U8 with RTE rounding (extremely fast, always accurate).
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline deUint8 floatToU8 (float fv)
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	union { float fv; deUint32 uv; deInt32 iv; } v;
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	v.fv = fv;
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint32	e	= (deUint32)(126-(v.iv>>23));
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32		m	= v.uv;
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m &= 0x00ffffffu;
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m |= 0x00800000u;
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m  = (m << 8) - m;
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m  = 0x00800000u + (m >> e);
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (e > 8)
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m = e;
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return (deUint8)(m>>24);
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // tcu
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif // _TCUTEXTUREUTIL_HPP
127