12a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson/*-------------------------------------------------------------------------
22a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson * drawElements Quality Program OpenGL ES 3.1 Module
32a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson * -------------------------------------------------
42a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson *
52a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson * Copyright 2017 The Android Open Source Project
62a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson *
72a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson * Licensed under the Apache License, Version 2.0 (the "License");
82a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson * you may not use this file except in compliance with the License.
92a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson * You may obtain a copy of the License at
102a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson *
112a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson *      http://www.apache.org/licenses/LICENSE-2.0
122a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson *
132a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson * Unless required by applicable law or agreed to in writing, software
142a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson * distributed under the License is distributed on an "AS IS" BASIS,
152a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
162a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson * See the License for the specific language governing permissions and
172a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson * limitations under the License.
182a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson *
192a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson *//*!
202a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson * \file
212a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson * \brief EXT Shader Framebuffer Fetch Tests.
222a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson *//*--------------------------------------------------------------------*/
232a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
242a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson#include "es31fShaderFramebufferFetchTests.hpp"
252a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson#include "es31fFboTestUtil.hpp"
262a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
272a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson#include "tcuTestLog.hpp"
282a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson#include "tcuSurface.hpp"
292a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson#include "tcuTextureUtil.hpp"
302a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson#include "tcuImageCompare.hpp"
312a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson#include "tcuVectorUtil.hpp"
322a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
332a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson#include "gluShaderProgram.hpp"
342a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson#include "gluPixelTransfer.hpp"
352a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson#include "gluTextureUtil.hpp"
362a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson#include "gluContextInfo.hpp"
372a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson#include "gluObjectWrapper.hpp"
382a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
392a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson#include "glwFunctions.hpp"
402a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson#include "glwEnums.hpp"
412a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
422a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson#include "deStringUtil.hpp"
432a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
442a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson#include <vector>
452a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
462a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonnamespace deqp
472a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
482a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonnamespace gles31
492a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
502a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonnamespace Functional
512a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
522a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonnamespace
532a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
542a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
552a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonusing std::vector;
562a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonusing std::string;
572a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonusing tcu::TestLog;
582a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
592a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonusing namespace glw;
602a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonusing namespace FboTestUtil;
612a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
622a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonstatic void checkExtensionSupport (Context& context, const char* extName)
632a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
642a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	if (!context.getContextInfo().isExtensionSupported(extName))
652a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		throw tcu::NotSupportedError(string(extName) + " not supported");
662a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
672a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
682a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonstatic void checkFramebufferFetchSupport (Context& context)
692a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
702a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	checkExtensionSupport(context, "GL_EXT_shader_framebuffer_fetch");
712a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
722a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
732a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonstatic bool isRequiredFormat (deUint32 format, glu::RenderContext& renderContext)
742a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
752a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const bool isES32 = glu::contextSupports(renderContext.getType(), glu::ApiType::es(3, 2));
762a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	switch (format)
772a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	{
782a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		// Color-renderable formats
792a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RGBA32I:
802a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RGBA32UI:
812a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RGBA16I:
822a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RGBA16UI:
832a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RGBA8:
842a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RGBA8I:
852a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RGBA8UI:
862a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_SRGB8_ALPHA8:
872a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RGB10_A2:
882a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RGB10_A2UI:
892a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RGBA4:
902a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RGB5_A1:
912a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RGB8:
922a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RGB565:
932a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RG32I:
942a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RG32UI:
952a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RG16I:
962a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RG16UI:
972a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RG8:
982a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RG8I:
992a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RG8UI:
1002a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_R32I:
1012a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_R32UI:
1022a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_R16I:
1032a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_R16UI:
1042a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_R8:
1052a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_R8I:
1062a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_R8UI:
1072a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			return true;
1082a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
1092a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		// Float format
1102a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RGBA32F:
1112a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RGB32F:
1122a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_R11F_G11F_B10F:
1132a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RG32F:
1142a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_R32F:
1152a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			return isES32;
1162a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
1172a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		default:
1182a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			return false;
1192a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	}
1202a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
1212a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
1222a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsontcu::TextureFormat getReadPixelFormat (const tcu::TextureFormat& format)
1232a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
1242a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	switch (tcu::getTextureChannelClass(format.type))
1252a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	{
1262a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1272a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			return tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNSIGNED_INT32);
1282a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
1292a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1302a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			return tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::SIGNED_INT32);
1312a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
1322a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1332a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1342a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			return tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8);
1352a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
1362a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1372a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			return tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::FLOAT);
1382a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
1392a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		default:
1402a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			DE_ASSERT(false);
1412a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			return tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8);
1422a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	}
1432a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
1442a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
1452a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsontcu::Vec4 getFixedPointFormatThreshold (const tcu::TextureFormat& sourceFormat, const tcu::TextureFormat& readPixelsFormat)
1462a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
1472a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	DE_ASSERT(tcu::getTextureChannelClass(sourceFormat.type) != tcu::TEXTURECHANNELCLASS_FLOATING_POINT);
1482a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	DE_ASSERT(tcu::getTextureChannelClass(readPixelsFormat.type) != tcu::TEXTURECHANNELCLASS_FLOATING_POINT);
1492a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
1502a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	DE_ASSERT(tcu::getTextureChannelClass(sourceFormat.type) != tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER);
1512a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	DE_ASSERT(tcu::getTextureChannelClass(readPixelsFormat.type) != tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER);
1522a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
1532a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	DE_ASSERT(tcu::getTextureChannelClass(sourceFormat.type) != tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER);
1542a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	DE_ASSERT(tcu::getTextureChannelClass(readPixelsFormat.type) != tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER);
1552a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
1562a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const tcu::IVec4	srcBits		= tcu::getTextureFormatBitDepth(sourceFormat);
1572a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const tcu::IVec4	readBits	= tcu::getTextureFormatBitDepth(readPixelsFormat);
1582a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
1592a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return tcu::Vec4(3.0f) / ((tcu::Vector<deUint64, 4>(1) << (tcu::min(srcBits, readBits).cast<deUint64>())) - tcu::Vector<deUint64, 4>(1)).cast<float>();
1602a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
1612a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
1622a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsontcu::UVec4 getFloatULPThreshold (const tcu::TextureFormat& sourceFormat, const tcu::TextureFormat& readPixelsFormat)
1632a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
1642a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const tcu::IVec4	srcMantissaBits		= tcu::getTextureFormatMantissaBitDepth(sourceFormat);
1652a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const tcu::IVec4	readMantissaBits	= tcu::getTextureFormatMantissaBitDepth(readPixelsFormat);
1662a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::IVec4			ULPDiff(0);
1672a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
1682a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	for (int i = 0; i < 4; i++)
1692a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		if (readMantissaBits[i] >= srcMantissaBits[i])
1702a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			ULPDiff[i] = readMantissaBits[i] - srcMantissaBits[i];
1712a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
1722a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return tcu::UVec4(4) * (tcu::UVec4(1) << (ULPDiff.cast<deUint32>()));
1732a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
1742a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
1752a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonstatic bool isAnyExtensionSupported (Context& context, const std::vector<std::string>& requiredExts)
1762a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
1772a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	for (std::vector<std::string>::const_iterator iter = requiredExts.begin(); iter != requiredExts.end(); iter++)
1782a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	{
1792a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		const std::string& extension = *iter;
1802a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
1812a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		if (context.getContextInfo().isExtensionSupported(extension.c_str()))
1822a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			return true;
1832a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	}
1842a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
1852a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return false;
1862a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
1872a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
1882a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonstatic std::string getColorOutputType(tcu::TextureFormat format)
1892a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
1902a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	switch (tcu::getTextureChannelClass(format.type))
1912a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	{
1922a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:		return "uvec4";
1932a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:		return "ivec4";
1942a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1952a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1962a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:		return "vec4";
1972a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		default:
1982a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			DE_FATAL("Unsupported TEXTURECHANNELCLASS");
1992a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			return "";
2002a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	}
2012a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
2022a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
2032a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonstatic std::vector<std::string> getEnablingExtensions (deUint32 format, glu::RenderContext& renderContext)
2042a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
2052a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const bool					isES32 = glu::contextSupports(renderContext.getType(), glu::ApiType::es(3, 2));
2062a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	std::vector<std::string>	out;
2072a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
2082a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	DE_ASSERT(!isRequiredFormat(format, renderContext));
2092a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
2102a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	switch (format)
2112a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	{
2122a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RGB16F:
2132a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			out.push_back("GL_EXT_color_buffer_half_float");
2142a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			break;
2152a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
2162a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RGBA16F:
2172a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RG16F:
2182a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_R16F:
2192a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			out.push_back("GL_EXT_color_buffer_half_float");
2202a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
2212a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RGBA32F:
2222a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RGB32F:
2232a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_R11F_G11F_B10F:
2242a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_RG32F:
2252a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case GL_R32F:
2262a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			if (!isES32)
2272a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson				out.push_back("GL_EXT_color_buffer_float");
2282a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			break;
2292a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
2302a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		default:
2312a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			break;
2322a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	}
2332a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
2342a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return out;
2352a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
2362a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
2372a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonvoid checkFormatSupport (Context& context, deUint32 sizedFormat)
2382a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
2392a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const bool						isCoreFormat	= isRequiredFormat(sizedFormat, context.getRenderContext());
2402a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const std::vector<std::string>	requiredExts	= (!isCoreFormat) ? getEnablingExtensions(sizedFormat, context.getRenderContext()) : std::vector<std::string>();
2412a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
2422a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	// Check that we don't try to use invalid formats.
2432a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	DE_ASSERT(isCoreFormat || !requiredExts.empty());
2442a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
2452a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	if (!requiredExts.empty() && !isAnyExtensionSupported(context, requiredExts))
2462a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		throw tcu::NotSupportedError("Format not supported");
2472a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
2482a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
2492a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsontcu::Vec4 scaleColorValue (tcu::TextureFormat format, const tcu::Vec4& color)
2502a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
2512a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const tcu::TextureFormatInfo	fmtInfo			= tcu::getTextureFormatInfo(format);
2522a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const tcu::Vec4					cScale			= fmtInfo.valueMax-fmtInfo.valueMin;
2532a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const tcu::Vec4					cBias			= fmtInfo.valueMin;
2542a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
2552a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return tcu::RGBA(color).toVec() * cScale + cBias;
2562a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
2572a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
2582a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// Base class for framebuffer fetch test cases
2592a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
2602a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonclass FramebufferFetchTestCase : public TestCase
2612a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
2622a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonpublic:
2632a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson									FramebufferFetchTestCase		(Context& context, const char* name, const char* desc, deUint32 format);
2642a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson									~FramebufferFetchTestCase		(void);
2652a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
2662a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	void							init							(void);
2672a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	void							deinit							(void);
2682a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
2692a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonprotected:
2702a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	string							genPassThroughVertSource		(void);
2712a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	virtual glu::ProgramSources		genShaderSources				(void);
2722a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
2732a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	void							genFramebufferWithTexture		(const tcu::Vec4& color);
2742a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	void							genAttachementTexture			(const tcu::Vec4& color);
2752a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	void							genUniformColor					(const tcu::Vec4& color);
2762a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
2772a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	void							render							(void);
2782a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	void							verifyRenderbuffer				(TestLog& log, const tcu::TextureFormat& format, const tcu::TextureLevel& reference, const tcu::TextureLevel& result);
2792a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
2802a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const glw::Functions&			m_gl;
2812a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const deUint32					m_format;
2822a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
2832a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	glu::ShaderProgram*				m_program;
2842a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	GLuint							m_framebuffer;
2852a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	GLuint							m_texColorBuffer;
2862a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
2872a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureFormat				m_texFmt;
2882a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	glu::TransferFormat				m_transferFmt;
2892a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	bool							m_isFilterable;
2902a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
2912a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	enum
2922a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	{
2932a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		VIEWPORT_WIDTH	= 64,
2942a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		VIEWPORT_HEIGHT = 64,
2952a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	};
2962a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson};
2972a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
2982a609fb223ff773c6da74ce9b1e1891d55b5252eJohn RichardsonFramebufferFetchTestCase::FramebufferFetchTestCase (Context& context, const char* name, const char* desc, deUint32 format)
2992a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	: TestCase (context, name, desc)
3002a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	, m_gl					(m_context.getRenderContext().getFunctions())
3012a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	, m_format				(format)
3022a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	, m_program				(DE_NULL)
3032a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	, m_framebuffer			(0)
3042a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	, m_texColorBuffer		(0)
3052a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	, m_texFmt				(glu::mapGLInternalFormat(m_format))
3062a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	, m_transferFmt			(glu::getTransferFormat(m_texFmt))
3072a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	, m_isFilterable		(glu::isGLInternalColorFormatFilterable(m_format))
3082a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
3092a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
3102a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
3112a609fb223ff773c6da74ce9b1e1891d55b5252eJohn RichardsonFramebufferFetchTestCase::~FramebufferFetchTestCase (void)
3122a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
3132a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	FramebufferFetchTestCase::deinit();
3142a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
3152a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
3162a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonvoid FramebufferFetchTestCase::init (void)
3172a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
3182a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	checkFramebufferFetchSupport (m_context);
3192a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	checkFormatSupport(m_context, m_format);
3202a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
3212a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	DE_ASSERT(!m_program);
3222a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_program = new glu::ShaderProgram(m_context.getRenderContext(), genShaderSources());
3232a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
3242a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_testCtx.getLog() << *m_program;
3252a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
3262a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	if (!m_program->isOk())
3272a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	{
3282a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		delete m_program;
3292a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		m_program = DE_NULL;
3302a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		TCU_FAIL("Failed to compile shader program");
3312a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	}
3322a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
3332a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.useProgram(m_program->getProgram());
3342a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
3352a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
3362a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonvoid FramebufferFetchTestCase::deinit (void)
3372a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
3382a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	delete m_program;
3392a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_program = DE_NULL;
3402a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
3412a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	if (m_framebuffer)
3422a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	{
3432a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		m_gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
3442a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		m_gl.deleteFramebuffers(1, &m_framebuffer);
3452a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		m_framebuffer = 0;
3462a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	}
3472a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
3482a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	if (m_texColorBuffer)
3492a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	{
3502a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		m_gl.deleteTextures(1, &m_texColorBuffer);
3512a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		m_texColorBuffer = 0;
3522a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	}
3532a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
3542a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
3552a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonstring FramebufferFetchTestCase::genPassThroughVertSource (void)
3562a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
3572a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	std::ostringstream vertShaderSource;
3582a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
3592a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	vertShaderSource	<< "#version 310 es\n"
3602a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "in highp vec4 a_position;\n"
3612a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "\n"
3622a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "void main (void)\n"
3632a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "{\n"
3642a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "	gl_Position = a_position;\n"
3652a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "}\n";
3662a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
3672a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return vertShaderSource.str();
3682a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
3692a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
3702a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonglu::ProgramSources FramebufferFetchTestCase::genShaderSources (void)
3712a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
3722a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const string		vecType	= getColorOutputType(m_texFmt);
3732a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	std::ostringstream	fragShaderSource;
3742a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
3752a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	fragShaderSource	<< "#version 310 es\n"
3762a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "#extension GL_EXT_shader_framebuffer_fetch : require\n"
3772a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "layout(location = 0) inout highp " << vecType << " o_color;\n"
3782a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "uniform highp " << vecType << " u_color;\n"
3792a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "\n"
3802a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "void main (void)\n"
3812a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "{\n"
3822a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "	o_color += u_color;\n"
3832a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "}\n";
3842a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
3852a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return glu::makeVtxFragSources(genPassThroughVertSource(), fragShaderSource.str());
3862a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
3872a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
3882a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonvoid FramebufferFetchTestCase::genFramebufferWithTexture (const tcu::Vec4& color)
3892a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
3902a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.genFramebuffers(1, &m_framebuffer);
3912a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.bindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
3922a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
3932a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	genAttachementTexture(color);
3942a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	GLU_EXPECT_NO_ERROR(m_gl.getError(), "genAttachementTexture()");
3952a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
3962a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texColorBuffer, 0);
3972a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	TCU_CHECK(m_gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
3982a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
3992a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
4002a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonvoid FramebufferFetchTestCase::genAttachementTexture (const tcu::Vec4& color)
4012a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
4023bb47b5c5782556bd8fafd6bf4964eb25bd916e9John Richardson	tcu::TextureLevel			data					(glu::mapGLTransferFormat(m_transferFmt.format, m_transferFmt.dataType), VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 1);
4033bb47b5c5782556bd8fafd6bf4964eb25bd916e9John Richardson	tcu::TextureChannelClass	textureChannelClass =	tcu::getTextureChannelClass(m_texFmt.type);
4042a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
4052a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.genTextures(1, &m_texColorBuffer);
4062a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.bindTexture(GL_TEXTURE_2D, m_texColorBuffer);
4072a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
4082a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.texParameteri(GL_TEXTURE_2D,	GL_TEXTURE_WRAP_S,		GL_CLAMP_TO_EDGE);
4092a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.texParameteri(GL_TEXTURE_2D,	GL_TEXTURE_WRAP_T,		GL_CLAMP_TO_EDGE);
4102a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.texParameteri(GL_TEXTURE_2D,	GL_TEXTURE_WRAP_R,		GL_CLAMP_TO_EDGE);
4112a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.texParameteri(GL_TEXTURE_2D,	GL_TEXTURE_MIN_FILTER,	m_isFilterable ? GL_LINEAR : GL_NEAREST);
4122a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.texParameteri(GL_TEXTURE_2D,	GL_TEXTURE_MAG_FILTER,	m_isFilterable ? GL_LINEAR : GL_NEAREST);
4132a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
4143bb47b5c5782556bd8fafd6bf4964eb25bd916e9John Richardson	if (textureChannelClass == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER)
4153bb47b5c5782556bd8fafd6bf4964eb25bd916e9John Richardson		tcu::clear(data.getAccess(), color.asUint());
4163bb47b5c5782556bd8fafd6bf4964eb25bd916e9John Richardson	else if (textureChannelClass == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER)
4173bb47b5c5782556bd8fafd6bf4964eb25bd916e9John Richardson		tcu::clear(data.getAccess(), color.asInt());
4183bb47b5c5782556bd8fafd6bf4964eb25bd916e9John Richardson	else
4193bb47b5c5782556bd8fafd6bf4964eb25bd916e9John Richardson		tcu::clear(data.getAccess(), color);
4202a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
4212a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.texImage2D(GL_TEXTURE_2D, 0, m_format, VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 0, m_transferFmt.format, m_transferFmt.dataType, data.getAccess().getDataPtr());
4222a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.bindTexture(GL_TEXTURE_2D, 0);
4232a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
4242a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
4252a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonvoid FramebufferFetchTestCase::verifyRenderbuffer (TestLog&	log, const tcu::TextureFormat& format, const tcu::TextureLevel&	reference, const tcu::TextureLevel&	result)
4262a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
4272a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
4282a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
4292a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	switch (tcu::getTextureChannelClass(format.type))
4302a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	{
4312a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
4322a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		{
4332a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			const string		name		= "Renderbuffer";
4342a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			const string		desc		= "Compare renderbuffer (floating_point)";
4352a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			const tcu::UVec4	threshold	= getFloatULPThreshold(format, result.getFormat());
4362a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
4372a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			if (!tcu::floatUlpThresholdCompare(log, name.c_str(), desc.c_str(), reference, result, threshold, tcu::COMPARE_LOG_RESULT))
4382a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
4392a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
4402a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			break;
4412a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		}
4422a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
4432a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
4442a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
4452a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		{
4462a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			const string		name		= "Renderbuffer";
4472a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			const string		desc		= "Compare renderbuffer (integer)";
4482a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			const tcu::UVec4	threshold	(1, 1, 1, 1);
4492a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
4502a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			if (!tcu::intThresholdCompare(log, name.c_str(), desc.c_str(), reference, result, threshold, tcu::COMPARE_LOG_RESULT))
4512a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
4522a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
4532a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			break;
4542a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		}
4552a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
4562a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
4572a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
4582a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		{
4592a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			const string		name		= "Renderbuffer";
4602a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			const string		desc		= "Compare renderbuffer (fixed point)";
4612a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			const tcu::Vec4		threshold	= getFixedPointFormatThreshold(format, result.getFormat());
4622a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
4632a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			if (!tcu::floatThresholdCompare(log, name.c_str(), desc.c_str(), reference, result, threshold, tcu::COMPARE_LOG_RESULT))
4642a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
4652a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
4662a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			break;
4672a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		}
4682a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
4692a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		default:
4702a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		{
4712a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			DE_ASSERT(DE_FALSE);
4722a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
4732a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		}
4742a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	}
4752a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
4762a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
4772a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonvoid FramebufferFetchTestCase::genUniformColor (const tcu::Vec4& color)
4782a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
4792a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const GLuint colorLocation	= m_gl.getUniformLocation(m_program->getProgram(), "u_color");
4802a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
4812a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	switch (tcu::getTextureChannelClass(m_texFmt.type))
4822a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	{
4832a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
4842a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		{
4852a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			m_gl.uniform4uiv(colorLocation, 1, color.asUint().getPtr());
4862a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			break;
4872a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		}
4882a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
4892a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
4902a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		{
4912a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			m_gl.uniform4iv(colorLocation, 1, color.asInt().getPtr());
4922a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			break;
4932a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		}
4942a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
4952a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
4962a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
4972a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		{
4982a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			m_gl.uniform4fv(colorLocation, 1, color.asFloat().getPtr());
4992a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			break;
5002a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		}
5012a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		default:
5022a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			DE_ASSERT(DE_FALSE);
5032a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	}
5042a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
5052a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	GLU_EXPECT_NO_ERROR(m_gl.getError(), "genUniformColor()");
5062a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
5072a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
5082a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonvoid FramebufferFetchTestCase::render (void)
5092a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
5102a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const GLfloat coords[] =
5112a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	{
5122a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		-1.0f, -1.0f,
5132a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		+1.0f, -1.0f,
5142a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		+1.0f, +1.0f,
5152a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		-1.0f, +1.0f,
5162a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	};
5172a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
5182a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const GLushort indices[] =
5192a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	{
5202a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		0, 1, 2, 2, 3, 0,
5212a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	};
5222a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
5232a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const GLuint	coordLocation	= m_gl.getAttribLocation(m_program->getProgram(), "a_position");
5242a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
5252a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.viewport(0, 0, VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
5262a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
5272a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	glu::Buffer coordinatesBuffer(m_context.getRenderContext());
5282a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	glu::Buffer elementsBuffer(m_context.getRenderContext());
5292a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
5302a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.bindBuffer(GL_ARRAY_BUFFER, *coordinatesBuffer);
5312a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.bufferData(GL_ARRAY_BUFFER, (GLsizeiptr)sizeof(coords), coords, GL_STATIC_DRAW);
5322a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.enableVertexAttribArray(coordLocation);
5332a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.vertexAttribPointer(coordLocation, 2, GL_FLOAT, GL_FALSE, 0, DE_NULL);
5342a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
5352a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, *elementsBuffer);
5362a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)sizeof(indices), &indices[0], GL_STATIC_DRAW);
5372a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
5382a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, DE_NULL);
5392a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	GLU_EXPECT_NO_ERROR(m_gl.getError(), "render()");
5402a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
5412a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
5422a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// Test description:
5432a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Attach texture containing solid color to framebuffer.
5442a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Draw full quad covering the entire viewport.
5452a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Sum framebuffer read color with passed in uniform color.
5462a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Compare resulting surface with reference.
5472a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
5482a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonclass TextureFormatTestCase : public FramebufferFetchTestCase
5492a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
5502a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonpublic:
5512a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						TextureFormatTestCase		(Context& context, const char* name, const char* desc, deUint32 format);
5522a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						~TextureFormatTestCase		(void) {};
5532a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
5542a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	IterateResult		iterate						(void);
5552a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
5562a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonprivate:
5572a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	genReferenceTexture			(const tcu::Vec4& fbColor, const tcu::Vec4& uniformColor);
5582a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson};
5592a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
5602a609fb223ff773c6da74ce9b1e1891d55b5252eJohn RichardsonTextureFormatTestCase::TextureFormatTestCase (Context& context, const char* name, const char* desc, deUint32 format)
5612a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	: FramebufferFetchTestCase(context, name, desc, format)
5622a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
5632a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
5642a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
5652a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsontcu::TextureLevel TextureFormatTestCase::genReferenceTexture (const tcu::Vec4& fbColor, const tcu::Vec4& uniformColor)
5662a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
5673bb47b5c5782556bd8fafd6bf4964eb25bd916e9John Richardson	tcu::TextureLevel			reference			(glu::mapGLTransferFormat(m_transferFmt.format, m_transferFmt.dataType), VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 1);
5683bb47b5c5782556bd8fafd6bf4964eb25bd916e9John Richardson	tcu::TextureChannelClass	textureChannelClass = tcu::getTextureChannelClass(m_texFmt.type);
5693bb47b5c5782556bd8fafd6bf4964eb25bd916e9John Richardson
5703bb47b5c5782556bd8fafd6bf4964eb25bd916e9John Richardson	if (textureChannelClass == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER)
571c76765be1fe96c67ff20b73779e4dc5eea101c87james.glanville	{
5723bb47b5c5782556bd8fafd6bf4964eb25bd916e9John Richardson		tcu::clear(reference.getAccess(), fbColor.asUint() + uniformColor.asUint());
573c76765be1fe96c67ff20b73779e4dc5eea101c87james.glanville	}
5743bb47b5c5782556bd8fafd6bf4964eb25bd916e9John Richardson	else if (textureChannelClass == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER)
575c76765be1fe96c67ff20b73779e4dc5eea101c87james.glanville	{
5763bb47b5c5782556bd8fafd6bf4964eb25bd916e9John Richardson		tcu::clear(reference.getAccess(), fbColor.asInt() + uniformColor.asInt());
577c76765be1fe96c67ff20b73779e4dc5eea101c87james.glanville	}
5783bb47b5c5782556bd8fafd6bf4964eb25bd916e9John Richardson	else
579c76765be1fe96c67ff20b73779e4dc5eea101c87james.glanville	{
580c76765be1fe96c67ff20b73779e4dc5eea101c87james.glanville		if (tcu::isSRGB(m_texFmt))
581c76765be1fe96c67ff20b73779e4dc5eea101c87james.glanville		{
582c76765be1fe96c67ff20b73779e4dc5eea101c87james.glanville			const tcu::Vec4	fragmentColor = tcu::sRGBToLinear(fbColor) + uniformColor;
583c76765be1fe96c67ff20b73779e4dc5eea101c87james.glanville			tcu::clear(reference.getAccess(), tcu::linearToSRGB(fragmentColor));
584c76765be1fe96c67ff20b73779e4dc5eea101c87james.glanville		}
585c76765be1fe96c67ff20b73779e4dc5eea101c87james.glanville		else
586c76765be1fe96c67ff20b73779e4dc5eea101c87james.glanville		{
587c76765be1fe96c67ff20b73779e4dc5eea101c87james.glanville			tcu::clear(reference.getAccess(), fbColor + uniformColor);
588c76765be1fe96c67ff20b73779e4dc5eea101c87james.glanville		}
589c76765be1fe96c67ff20b73779e4dc5eea101c87james.glanville	}
5902a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
5912a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return reference;
5922a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
5932a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
5942a609fb223ff773c6da74ce9b1e1891d55b5252eJohn RichardsonTextureFormatTestCase::IterateResult TextureFormatTestCase::iterate (void)
5952a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
5962a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const tcu::Vec4		uniformColor	= scaleColorValue(m_texFmt, tcu::Vec4(0.1f, 0.1f, 0.1f, 1.0f));
5972a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const tcu::Vec4		fbColor			= scaleColorValue(m_texFmt, tcu::Vec4(0.5f, 0.0f, 0.0f, 1.0f));
5982a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
5992a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	reference		= genReferenceTexture(fbColor, uniformColor);
6002a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	result			(getReadPixelFormat(m_texFmt), VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
6012a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
6022a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	genFramebufferWithTexture(fbColor);
6032a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	genUniformColor(uniformColor);
6042a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	render();
6052a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
6062a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	glu::readPixels(m_context.getRenderContext(), 0, 0, result.getAccess());
6072a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	verifyRenderbuffer(m_testCtx.getLog(), m_texFmt, reference, result);
6082a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
6092a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return STOP;
6102a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
6112a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
6122a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// Test description:
6132a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Attach multiple textures containing solid colors to framebuffer.
6142a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Draw full quad covering the entire viewport.
6152a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - For each render target sum framebuffer read color with passed in uniform color.
6162a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Compare resulting surfaces with references.
6172a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
6182a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonclass MultipleRenderTargetsTestCase : public FramebufferFetchTestCase
6192a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
6202a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonpublic:
6212a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						MultipleRenderTargetsTestCase		(Context& context, const char* name, const char* desc, deUint32 format);
6222a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						~MultipleRenderTargetsTestCase		(void);
6232a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
6242a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	IterateResult		iterate								(void);
6252a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	void				deinit								(void);
6262a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
6272a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonprivate:
6282a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	void				genFramebufferWithTextures			(const vector<tcu::Vec4>& colors);
6293bb47b5c5782556bd8fafd6bf4964eb25bd916e9John Richardson	void				genAttachmentTextures				(const vector<tcu::Vec4>& colors);
6302a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	genReferenceTexture					(const tcu::Vec4& fbColor, const tcu::Vec4& uniformColor);
6312a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	glu::ProgramSources genShaderSources					(void);
6322a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
6332a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	enum
6342a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	{
6352a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		MAX_COLOR_BUFFERS = 4
6362a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	};
6372a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
6382a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	GLuint				m_texColorBuffers					[MAX_COLOR_BUFFERS];
6392a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	GLenum				m_colorBuffers						[MAX_COLOR_BUFFERS];
6402a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson};
6412a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
6422a609fb223ff773c6da74ce9b1e1891d55b5252eJohn RichardsonMultipleRenderTargetsTestCase::MultipleRenderTargetsTestCase (Context& context, const char* name, const char* desc, deUint32 format)
6432a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	: FramebufferFetchTestCase(context, name, desc, format)
6442a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	, m_texColorBuffers ()
6452a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
6462a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_colorBuffers[0] = GL_COLOR_ATTACHMENT0;
6472a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_colorBuffers[1] = GL_COLOR_ATTACHMENT1;
6482a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_colorBuffers[2] = GL_COLOR_ATTACHMENT2;
6492a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_colorBuffers[3] = GL_COLOR_ATTACHMENT3;
6502a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
6512a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
6522a609fb223ff773c6da74ce9b1e1891d55b5252eJohn RichardsonMultipleRenderTargetsTestCase::~MultipleRenderTargetsTestCase (void)
6532a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
6542a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	MultipleRenderTargetsTestCase::deinit();
6552a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
6562a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
6572a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonvoid MultipleRenderTargetsTestCase::deinit (void)
6582a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
6592a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	// Clean up texture data
6602a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	for (int i = 0; i < DE_LENGTH_OF_ARRAY(m_texColorBuffers); ++i)
6612a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	{
6622a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		if (m_texColorBuffers[i])
6632a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			m_context.getRenderContext().getFunctions().deleteTextures(1, &m_texColorBuffers[i]);
6642a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	}
6652a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
6662a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	FramebufferFetchTestCase::deinit();
6672a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
6682a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
6692a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonvoid MultipleRenderTargetsTestCase::genFramebufferWithTextures (const vector<tcu::Vec4>& colors)
6702a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
6712a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.genFramebuffers(1, &m_framebuffer);
6722a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.bindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
6732a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
6743bb47b5c5782556bd8fafd6bf4964eb25bd916e9John Richardson	genAttachmentTextures(colors);
6752a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
6762a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	for (int i = 0; i < DE_LENGTH_OF_ARRAY(m_texColorBuffers); ++i)
6772a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		m_gl.framebufferTexture2D(GL_FRAMEBUFFER, m_colorBuffers[i], GL_TEXTURE_2D, m_texColorBuffers[i], 0);
6782a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
6792a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	TCU_CHECK(m_gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
6802a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
6812a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.drawBuffers((glw::GLsizei)MAX_COLOR_BUFFERS, &m_colorBuffers[0]);
6822a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	GLU_EXPECT_NO_ERROR(m_gl.getError(), "genFramebufferWithTextures()");
6832a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
6842a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
6853bb47b5c5782556bd8fafd6bf4964eb25bd916e9John Richardsonvoid MultipleRenderTargetsTestCase::genAttachmentTextures (const vector<tcu::Vec4>& colors)
6862a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
6872a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	data	(glu::mapGLTransferFormat(m_transferFmt.format, m_transferFmt.dataType), VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 1);
6882a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
6892a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.genTextures(MAX_COLOR_BUFFERS, m_texColorBuffers);
6902a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
6912a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	for (int i = 0; i < DE_LENGTH_OF_ARRAY(m_texColorBuffers); ++i)
6922a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	{
6932a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		m_gl.bindTexture(GL_TEXTURE_2D, m_texColorBuffers[i]);
6942a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
6952a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		m_gl.texParameteri(GL_TEXTURE_2D,	GL_TEXTURE_WRAP_S,		GL_CLAMP_TO_EDGE);
6962a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		m_gl.texParameteri(GL_TEXTURE_2D,	GL_TEXTURE_WRAP_T,		GL_CLAMP_TO_EDGE);
6972a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		m_gl.texParameteri(GL_TEXTURE_2D,	GL_TEXTURE_WRAP_R,		GL_CLAMP_TO_EDGE);
6982a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		m_gl.texParameteri(GL_TEXTURE_2D,	GL_TEXTURE_MIN_FILTER,	m_isFilterable ? GL_LINEAR : GL_NEAREST);
6992a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		m_gl.texParameteri(GL_TEXTURE_2D,	GL_TEXTURE_MAG_FILTER,	m_isFilterable ? GL_LINEAR : GL_NEAREST);
7002a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
7012a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		clear(data.getAccess(), colors[i]);
7022a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		m_gl.texImage2D(GL_TEXTURE_2D, 0, m_format, VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 0, m_transferFmt.format, m_transferFmt.dataType, data.getAccess().getDataPtr());
7032a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	}
7042a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
7052a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.bindTexture(GL_TEXTURE_2D, 0);
7063bb47b5c5782556bd8fafd6bf4964eb25bd916e9John Richardson	GLU_EXPECT_NO_ERROR(m_gl.getError(), "genAttachmentTextures()");
7072a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
7082a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
7092a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsontcu::TextureLevel MultipleRenderTargetsTestCase::genReferenceTexture (const tcu::Vec4& fbColor, const tcu::Vec4& uniformColor)
7102a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
7112a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	reference	(glu::mapGLTransferFormat(m_transferFmt.format, m_transferFmt.dataType), VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 1);
7122a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::clear(reference.getAccess(), fbColor + uniformColor);
7132a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
7142a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return reference;
7152a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
7162a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
7172a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonglu::ProgramSources MultipleRenderTargetsTestCase::genShaderSources (void)
7182a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
7192a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const string		vecType	= getColorOutputType(m_texFmt);
7202a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	std::ostringstream	fragShaderSource;
7212a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
7222a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	fragShaderSource	<< "#version 310 es\n"
7232a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "#extension GL_EXT_shader_framebuffer_fetch : require\n"
7242a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "layout(location = 0) inout highp " << vecType << " o_color0;\n"
7252a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "layout(location = 1) inout highp " << vecType << " o_color1;\n"
7262a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "layout(location = 2) inout highp " << vecType << " o_color2;\n"
7272a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "layout(location = 3) inout highp " << vecType << " o_color3;\n"
7282a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "uniform highp " << vecType << " u_color;\n"
7292a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "\n"
7302a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "void main (void)\n"
7312a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "{\n"
7322a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "	o_color0 += u_color;\n"
7332a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "	o_color1 += u_color;\n"
7342a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "	o_color2 += u_color;\n"
7352a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "	o_color3 += u_color;\n"
7362a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "}\n";
7372a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
7382a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return glu::makeVtxFragSources(genPassThroughVertSource(), fragShaderSource.str());
7392a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
7402a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
7412a609fb223ff773c6da74ce9b1e1891d55b5252eJohn RichardsonMultipleRenderTargetsTestCase::IterateResult MultipleRenderTargetsTestCase::iterate (void)
7422a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
7432a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const tcu::Vec4		uniformColor	= scaleColorValue(m_texFmt, tcu::Vec4(0.1f, 0.1f, 0.1f, 1.0f));
7442a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	result			(getReadPixelFormat(m_texFmt), VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
7452a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
7462a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	vector<tcu::Vec4> colors;
7472a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	colors.push_back(scaleColorValue(m_texFmt, tcu::Vec4(0.9f, 0.0f, 0.0f, 1.0f)));
7482a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	colors.push_back(scaleColorValue(m_texFmt, tcu::Vec4(0.0f, 0.9f, 0.0f, 1.0f)));
7492a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	colors.push_back(scaleColorValue(m_texFmt, tcu::Vec4(0.0f, 0.0f, 0.9f, 1.0f)));
7502a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	colors.push_back(scaleColorValue(m_texFmt, tcu::Vec4(0.0f, 0.9f, 0.9f, 1.0f)));
7512a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
7522a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	genFramebufferWithTextures(colors);
7532a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	genUniformColor(uniformColor);
7542a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	render();
7552a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
7562a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	for (int i = 0; i < DE_LENGTH_OF_ARRAY(m_colorBuffers); ++i)
7572a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	{
7582a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		tcu::TextureLevel	reference		= genReferenceTexture(colors[i], uniformColor);
7592a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
7602a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		m_gl.readBuffer(m_colorBuffers[i]);
7612a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		glu::readPixels(m_context.getRenderContext(), 0, 0, result.getAccess());
7622a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		verifyRenderbuffer(m_testCtx.getLog(), m_texFmt, reference, result);
7632a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	}
7642a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
7652a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return STOP;
7662a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
7672a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
7682a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// Test description:
7692a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Same as TextureFormatTestCase except uses built-in fragment output of ES 2.0
7702a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
7712a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonclass LastFragDataTestCase : public FramebufferFetchTestCase
7722a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
7732a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonpublic:
7742a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						LastFragDataTestCase			(Context& context, const char* name, const char* desc, deUint32 format);
7752a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						~LastFragDataTestCase			(void) {};
7762a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
7772a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	IterateResult		iterate							(void);
7782a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
7792a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonprivate:
7802a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	glu::ProgramSources genShaderSources				(void);
7812a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	genReferenceTexture				(const tcu::Vec4& fbColor, const tcu::Vec4& uniformColor);
7822a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson};
7832a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
7842a609fb223ff773c6da74ce9b1e1891d55b5252eJohn RichardsonLastFragDataTestCase::LastFragDataTestCase (Context& context, const char* name, const char* desc, deUint32 format)
7852a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	: FramebufferFetchTestCase(context, name, desc, format)
7862a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
7872a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
7882a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
7892a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonglu::ProgramSources LastFragDataTestCase::genShaderSources (void)
7902a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
7912a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const string		vecType	= getColorOutputType(m_texFmt);
7922a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	std::ostringstream	vertShaderSource;
7932a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	std::ostringstream	fragShaderSource;
7942a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
7952a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	vertShaderSource	<< "#version 100\n"
7962a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "attribute vec4 a_position;\n"
7972a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "\n"
7982a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "void main (void)\n"
7992a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "{\n"
8002a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "	gl_Position = a_position;\n"
8012a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "}\n";
8022a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8032a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	fragShaderSource	<< "#version 100\n"
8042a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "#extension GL_EXT_shader_framebuffer_fetch : require\n"
8052a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "uniform highp " << vecType << " u_color;\n"
8062a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "\n"
8072a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "void main (void)\n"
8082a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "{\n"
8092a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "	gl_FragColor = u_color + gl_LastFragData[0];\n"
8102a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "}\n";
8112a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8122a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return glu::makeVtxFragSources(vertShaderSource.str(), fragShaderSource.str());
8132a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
8142a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8152a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsontcu::TextureLevel LastFragDataTestCase::genReferenceTexture (const tcu::Vec4& fbColor, const tcu::Vec4& uniformColor)
8162a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
8172a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	reference	(glu::mapGLTransferFormat(m_transferFmt.format, m_transferFmt.dataType), VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 1);
8182a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::clear(reference.getAccess(), fbColor + uniformColor);
8192a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8202a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return reference;
8212a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
8222a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8232a609fb223ff773c6da74ce9b1e1891d55b5252eJohn RichardsonLastFragDataTestCase::IterateResult LastFragDataTestCase::iterate (void)
8242a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
8252a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const tcu::Vec4		uniformColor	= scaleColorValue(m_texFmt, tcu::Vec4(0.1f, 0.1f, 0.1f, 1.0f));
8262a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const tcu::Vec4		fbColor			= scaleColorValue(m_texFmt, tcu::Vec4(0.5f, 0.0f, 0.0f, 1.0f));
8272a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8282a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	reference		= genReferenceTexture(fbColor, uniformColor);
8292a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	result			(getReadPixelFormat(m_texFmt), VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
8302a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8312a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	genFramebufferWithTexture(fbColor);
8322a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	genUniformColor(uniformColor);
8332a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	render();
8342a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8352a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	glu::readPixels(m_context.getRenderContext(), 0, 0, result.getAccess());
8362a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	verifyRenderbuffer(m_testCtx.getLog(), m_texFmt, reference, result);
8372a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8382a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return STOP;
8392a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
8402a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8412a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// Test description:
8422a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Attach texture containing solid color to framebuffer.
8432a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Create one 2D texture for sampler with a grid pattern
8442a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Draw full screen quad covering the entire viewport.
8452a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Sum color values taken from framebuffer texture and sampled texture
8462a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Compare resulting surface with reference.
8472a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8482a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonclass TexelFetchTestCase : public FramebufferFetchTestCase
8492a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
8502a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonpublic:
8512a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						TexelFetchTestCase		(Context& context, const char* name, const char* desc, deUint32 format);
8522a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						~TexelFetchTestCase		(void) {}
8532a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8542a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	IterateResult		iterate					(void);
8552a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8562a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonprivate:
8572a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	glu::ProgramSources genShaderSources		(void);
8582a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	genReferenceTexture		(const tcu::Vec4& colorEven, const tcu::Vec4& colorOdd, const tcu::Vec4& fbColor);
8592a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	void				genSamplerTexture		(const tcu::Vec4& colorEven, const tcu::Vec4& colorOdd);
8602a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8612a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	GLuint				m_samplerTexture;
8622a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson};
8632a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8642a609fb223ff773c6da74ce9b1e1891d55b5252eJohn RichardsonTexelFetchTestCase::TexelFetchTestCase (Context& context, const char* name, const char* desc, deUint32 format)
8652a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	: FramebufferFetchTestCase(context, name, desc, format)
8662a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	, m_samplerTexture(0)
8672a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
8682a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
8692a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8702a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonvoid TexelFetchTestCase::genSamplerTexture (const tcu::Vec4& colorEven, const tcu::Vec4& colorOdd)
8712a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
8722a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	data	(glu::mapGLTransferFormat(m_transferFmt.format, m_transferFmt.dataType), VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 1);
8732a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8742a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.activeTexture(GL_TEXTURE1);
8752a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8762a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.genTextures(1, &m_samplerTexture);
8772a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.bindTexture(GL_TEXTURE_2D, m_texColorBuffer);
8782a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
8792a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
8802a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8812a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::fillWithGrid(data.getAccess(), 8, colorEven, colorOdd);
8822a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8832a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.texImage2D(GL_TEXTURE_2D, 0, m_format, VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 0, m_transferFmt.format, m_transferFmt.dataType, data.getAccess().getDataPtr());
8842a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.bindTexture(GL_TEXTURE_2D, 0);
8852a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8862a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const GLuint samplerLocation = m_gl.getUniformLocation(m_program->getProgram(), "u_sampler");
8872a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.uniform1i(samplerLocation, 1);
8882a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8892a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	GLU_EXPECT_NO_ERROR(m_gl.getError(), "genSamplerTexture()");
8902a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
8912a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8922a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonglu::ProgramSources TexelFetchTestCase::genShaderSources (void)
8932a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
8942a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const string		vecType	= getColorOutputType(m_texFmt);
8952a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	std::ostringstream	fragShaderSource;
8962a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
8972a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	fragShaderSource	<< "#version 310 es\n"
8982a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "#extension GL_EXT_shader_framebuffer_fetch : require\n"
8992a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "layout(location = 0) inout highp " << vecType << " o_color;\n"
9002a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "\n"
9012a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "uniform sampler2D u_sampler;\n"
9022a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "void main (void)\n"
9032a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "{\n"
9042a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "	o_color += texelFetch(u_sampler, ivec2(gl_FragCoord), 0);\n"
9052a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "}\n";
9062a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
9072a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return glu::makeVtxFragSources(genPassThroughVertSource(), fragShaderSource.str());
9082a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
9092a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
9102a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsontcu::TextureLevel TexelFetchTestCase::genReferenceTexture (const tcu::Vec4& colorEven, const tcu::Vec4& colorOdd, const tcu::Vec4& fbColor)
9112a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
9122a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	reference	(glu::mapGLTransferFormat(m_transferFmt.format, m_transferFmt.dataType), VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 1);
9132a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::fillWithGrid(reference.getAccess(), 8, colorEven + fbColor, colorOdd + fbColor);
9142a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
9152a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return reference;
9162a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
9172a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
9182a609fb223ff773c6da74ce9b1e1891d55b5252eJohn RichardsonTexelFetchTestCase::IterateResult TexelFetchTestCase::iterate (void)
9192a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
9202a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const tcu::Vec4		fbColor			= scaleColorValue(m_texFmt, tcu::Vec4(0.5f, 0.0f, 0.5f, 1.0f));
9212a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const tcu::Vec4		colorEven		= scaleColorValue(m_texFmt, tcu::Vec4(0.5f, 0.5f, 0.0f, 1.0f));
9222a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const tcu::Vec4		colorOdd		= scaleColorValue(m_texFmt, tcu::Vec4(0.5f, 0.0f, 0.5f, 1.0f));
9232a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
9242a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	genSamplerTexture(colorEven, colorOdd);
9252a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	reference		= genReferenceTexture(colorEven, colorOdd, fbColor);
9262a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	result			(getReadPixelFormat(m_texFmt), VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
9272a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
9282a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	genFramebufferWithTexture(fbColor);
9292a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	render();
9302a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
9312a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	glu::readPixels(m_context.getRenderContext(), 0, 0, result.getAccess());
9322a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	verifyRenderbuffer(m_testCtx.getLog(), m_texFmt, reference, result);
9332a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
9342a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	// cleanup
9352a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.deleteTextures(1, &m_samplerTexture);
9362a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
9372a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return STOP;
9382a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
9392a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
9402a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// Test description:
9412a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Attach texture containing solid color to framebuffer.
9422a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Draw full screen quad covering the entire viewport.
9432a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Multiple assignments are made to the output color for fragments on the right vertical half of the screen.
9442a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - A single assignment is made to the output color for fragments on the left vertical centre of the screen.
9452a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Values are calculated using the sum of the passed in uniform color and the previous framebuffer color.
9462a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Compare resulting surface with reference.
9472a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
9482a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonclass MultipleAssignmentTestCase : public FramebufferFetchTestCase
9492a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
9502a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonpublic:
9512a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						MultipleAssignmentTestCase		(Context& context, const char* name, const char* desc, deUint32 format);
9522a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						~MultipleAssignmentTestCase		(void) {}
9532a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
9542a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	IterateResult		iterate							(void);
9552a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
9562a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonprivate:
9572a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	glu::ProgramSources genShaderSources				(void);
9582a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	genReferenceTexture				(const tcu::Vec4& fbColor, const tcu::Vec4& uniformColor);
9592a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson};
9602a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
9612a609fb223ff773c6da74ce9b1e1891d55b5252eJohn RichardsonMultipleAssignmentTestCase::MultipleAssignmentTestCase (Context& context, const char* name, const char* desc, deUint32 format)
9622a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	: FramebufferFetchTestCase(context, name, desc, format)
9632a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
9642a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
9652a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
9662a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonglu::ProgramSources MultipleAssignmentTestCase::genShaderSources (void)
9672a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
9682a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const string		vecType = getColorOutputType(m_texFmt);
9692a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	std::ostringstream	vertShaderSource;
9702a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	std::ostringstream	fragShaderSource;
9712a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
9722a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	vertShaderSource	<< "#version 310 es\n"
9732a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "in highp vec4 a_position;\n"
9742a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "out highp vec4 v_position;\n"
9752a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "\n"
9762a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "void main (void)\n"
9772a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "{\n"
9782a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "	gl_Position = a_position;\n"
9792a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "	v_position  = gl_Position;\n"
9802a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "}\n";
9812a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
9822a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	fragShaderSource	<< "#version 310 es\n"
9832a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "#extension GL_EXT_shader_framebuffer_fetch : require\n"
9842a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "in highp vec4 v_position;\n"
9852a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "layout(location = 0) inout highp " << vecType << " o_color;\n"
9862a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "uniform highp " << vecType << " u_color;\n"
9872a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "\n"
9882a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "void main (void)\n"
9892a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "{\n"
9902a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "	if (v_position.x > 0.0f)\n"
9912a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "		o_color += u_color;\n"
9922a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "\n"
9932a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "	o_color += u_color;\n"
9942a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "}\n";
9952a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
9962a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return glu::makeVtxFragSources(vertShaderSource.str(), fragShaderSource.str());
9972a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
9982a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
9992a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsontcu::TextureLevel MultipleAssignmentTestCase::genReferenceTexture (const tcu::Vec4& fbColor, const tcu::Vec4& uniformColor)
10002a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
10012a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	reference	(glu::mapGLTransferFormat(m_transferFmt.format, m_transferFmt.dataType), VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 1);
10022a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
10032a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	int	width	= reference.getAccess().getWidth();
10042a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	int	height	= reference.getAccess().getHeight();
10052a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	int	left	= width /2;
10062a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	int	top		= height/2;
10072a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
10082a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::Vec4 compositeColor(uniformColor * 2.0f);
10092a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
10102a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::clear(getSubregion(reference.getAccess(), left,		0,		0, width-left,	top,		1),	fbColor + compositeColor);
10112a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::clear(getSubregion(reference.getAccess(), 0,			top,	0, left,		height-top,	1), fbColor + uniformColor);
10122a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::clear(getSubregion(reference.getAccess(), left,		top,	0, width-left,	height-top, 1), fbColor + compositeColor);
10132a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::clear(getSubregion(reference.getAccess(), 0,			0,		0, left,		top,		1),	fbColor + uniformColor);
10142a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
10152a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return reference;
10162a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
10172a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
10182a609fb223ff773c6da74ce9b1e1891d55b5252eJohn RichardsonMultipleAssignmentTestCase::IterateResult MultipleAssignmentTestCase::iterate (void)
10192a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
10202a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const tcu::Vec4		fbColor			= scaleColorValue(m_texFmt, tcu::Vec4(0.5f, 0.0f, 0.0f, 1.0f));
10212a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const tcu::Vec4		uniformColor	= scaleColorValue(m_texFmt, tcu::Vec4(0.25f, 0.0f, 0.0f, 1.0f));
10222a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
10232a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	reference		= genReferenceTexture(fbColor, uniformColor);
10242a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	result			(getReadPixelFormat(m_texFmt), VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
10252a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
10262a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	genFramebufferWithTexture(fbColor);
10272a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	genUniformColor(uniformColor);
10282a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	render();
10292a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
10302a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	glu::readPixels(m_context.getRenderContext(), 0, 0, result.getAccess());
10312a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	verifyRenderbuffer(m_testCtx.getLog(), m_texFmt, reference, result);
10322a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
10332a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return STOP;
10342a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
10352a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
10362a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// Test description:
10372a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Attach texture containing grid pattern to framebuffer.
10382a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Using framebuffer reads discard odd squares in the grid.
10392a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - The even squares framebuffer color is added to the passed in uniform color.
10402a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
10412a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonclass FragmentDiscardTestCase : public FramebufferFetchTestCase
10422a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
10432a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonpublic:
10442a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						FragmentDiscardTestCase		(Context& context, const char* name, const char* desc, deUint32 format);
10452a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						~FragmentDiscardTestCase	(void) {}
10462a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
10472a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	IterateResult		iterate						(void);
10482a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
10492a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonprivate:
10502a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	glu::ProgramSources genShaderSources			(void);
10512a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	void				genFramebufferWithGrid		(const tcu::Vec4& fbColorEven, const tcu::Vec4& fbColorOdd);
10522a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	genReferenceTexture			(const tcu::Vec4& fbColorEven, const tcu::Vec4& fbColorOdd);
10532a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson};
10542a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
10552a609fb223ff773c6da74ce9b1e1891d55b5252eJohn RichardsonFragmentDiscardTestCase::FragmentDiscardTestCase (Context& context, const char* name, const char* desc, deUint32 format)
10562a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	: FramebufferFetchTestCase(context, name, desc, format)
10572a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
10582a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
10592a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
10602a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonglu::ProgramSources FragmentDiscardTestCase::genShaderSources (void)
10612a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
10622a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const string		vecType	= getColorOutputType(m_texFmt);
10632a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	std::ostringstream	fragShaderSource;
10642a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
10652a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	fragShaderSource	<< "#version 310 es\n"
10662a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "#extension GL_EXT_shader_framebuffer_fetch : require\n"
10672a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "layout(location = 0) inout highp " << vecType << " o_color;\n"
10682a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "uniform highp " << vecType << " u_color;\n"
10692a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "\n"
10702a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "void main (void)\n"
10712a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "{\n"
10722a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "	const highp float threshold = 0.0005f;\n"
10732a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "	bool valuesEqual = all(lessThan(abs(o_color - u_color), vec4(threshold)));\n\n"
10742a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "	if (valuesEqual)\n"
10752a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "		o_color += u_color;\n"
10762a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "	else\n"
10772a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "		discard;\n"
10782a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						<< "}\n";
10792a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
10802a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return glu::makeVtxFragSources(genPassThroughVertSource(), fragShaderSource.str());
10812a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
10822a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
10832a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonvoid FragmentDiscardTestCase::genFramebufferWithGrid (const tcu::Vec4& fbColorEven, const tcu::Vec4& fbColorOdd)
10842a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
10852a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel data	(glu::mapGLTransferFormat(m_transferFmt.format, m_transferFmt.dataType), VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 1);
10862a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
10872a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.genFramebuffers(1, &m_framebuffer);
10882a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.bindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
10892a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
10902a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.genTextures(1, &m_texColorBuffer);
10912a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.bindTexture(GL_TEXTURE_2D, m_texColorBuffer);
10922a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
10932a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::fillWithGrid(data.getAccess(), 8, fbColorEven, fbColorOdd);
10942a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
10952a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.texImage2D(GL_TEXTURE_2D, 0, m_format, VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 0, m_transferFmt.format, m_transferFmt.dataType, data.getAccess().getDataPtr());
10962a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.bindTexture(GL_TEXTURE_2D, 0);
10972a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
10982a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texColorBuffer, 0);
10992a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	TCU_CHECK(m_gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
11002a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
11012a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
11022a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsontcu::TextureLevel FragmentDiscardTestCase::genReferenceTexture (const tcu::Vec4& fbColorEven, const tcu::Vec4& fbColorOdd)
11032a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
11042a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	reference	(glu::mapGLTransferFormat(m_transferFmt.format, m_transferFmt.dataType), VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 1);
11052a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::fillWithGrid(reference.getAccess(), 8, fbColorEven + fbColorEven, fbColorOdd);
11062a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
11072a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return reference;
11082a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
11092a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
11102a609fb223ff773c6da74ce9b1e1891d55b5252eJohn RichardsonFragmentDiscardTestCase::IterateResult FragmentDiscardTestCase::iterate (void)
11112a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
11122a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const tcu::Vec4		fbColorEven		= scaleColorValue(m_texFmt, tcu::Vec4(0.5f, 0.0f, 1.0f, 1.0f));
11132a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const tcu::Vec4		fbColorOdd		= scaleColorValue(m_texFmt, tcu::Vec4(0.0f, 1.0f, 1.0f, 1.0f));
11142a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
11152a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	reference		= genReferenceTexture(fbColorEven, fbColorOdd);
11162a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	result			(getReadPixelFormat(m_texFmt), VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
11172a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	genFramebufferWithGrid(fbColorEven, fbColorOdd);
11182a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
11192a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	genUniformColor(fbColorEven);
11202a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	render();
11212a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
11222a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	glu::readPixels(m_context.getRenderContext(), 0, 0, result.getAccess());
11232a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	verifyRenderbuffer(m_testCtx.getLog(), m_texFmt, reference, result);
11242a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
11252a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return STOP;
11262a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
11272a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
11282a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// Test description:
11292a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Create 2D texture array containing three mipmaps.
11302a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Each mipmap level is assigned a different color.
11312a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Attach single mipmap level to framebuffer and draw full screen quad.
11322a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Sum framebuffer read color with passed in uniform color.
11332a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Compare resulting surface with reference.
11342a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Repeat for subsequent mipmap levels.
11352a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
11362a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonclass TextureLevelTestCase : public FramebufferFetchTestCase
11372a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
11382a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonpublic:
11392a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						TextureLevelTestCase			(Context& context, const char* name, const char* desc, deUint32 format);
11402a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						~TextureLevelTestCase			(void) {}
11412a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
11422a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	IterateResult		iterate							(void);
11432a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
11442a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonprivate:
11452a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	void				create2DTextureArrayMipMaps		(const vector<tcu::Vec4>& colors);
11462a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	genReferenceTexture				(int level, const vector<tcu::Vec4>& colors, const tcu::Vec4& uniformColor);
1147be0d165a5d941f87320f8eb27558e037d92dcae6Mika Isojärvi	void				genReferenceMipmap				(const tcu::Vec4& color, tcu::TextureLevel& reference);
11482a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson};
11492a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
11502a609fb223ff773c6da74ce9b1e1891d55b5252eJohn RichardsonTextureLevelTestCase::TextureLevelTestCase (Context& context, const char* name, const char* desc, deUint32 format)
11512a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	: FramebufferFetchTestCase(context, name, desc, format)
11522a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
11532a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
11542a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
11552a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonvoid TextureLevelTestCase::create2DTextureArrayMipMaps (const vector<tcu::Vec4>& colors)
11562a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
11572a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	int						numLevels	= (int)colors.size();
11582a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel		levelData	(glu::mapGLTransferFormat(m_transferFmt.format, m_transferFmt.dataType));
11592a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
11602a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.genTextures(1, &m_texColorBuffer);
11612a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.bindTexture(GL_TEXTURE_2D_ARRAY, m_texColorBuffer);
11622a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
11632a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.texImage3D(GL_TEXTURE_2D_ARRAY, 0, m_format, VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 1, 0, m_transferFmt.format, m_transferFmt.dataType, DE_NULL);
11642a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.generateMipmap(GL_TEXTURE_2D_ARRAY);
11652a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
11662a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	for (int level = 0; level < numLevels; level++)
11672a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	{
11682a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		int		levelW		= de::max(1, VIEWPORT_WIDTH		>> level);
11692a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		int		levelH		= de::max(1, VIEWPORT_HEIGHT	>> level);
11702a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
11712a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		levelData.setSize(levelW, levelH, 1);
11722a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
11732a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		clear(levelData.getAccess(), colors[level]);
11742a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		m_gl.texImage3D(GL_TEXTURE_2D_ARRAY, level, m_format, levelW, levelH, 1, 0, m_transferFmt.format, m_transferFmt.dataType, levelData.getAccess().getDataPtr());
11752a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	}
11762a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
11772a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.bindTexture(GL_TEXTURE_2D_ARRAY, 0);
11782a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	GLU_EXPECT_NO_ERROR(m_gl.getError(), "create2DTextureArrayMipMaps()");
11792a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
11802a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
11812a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsontcu::TextureLevel TextureLevelTestCase::genReferenceTexture (int level, const vector<tcu::Vec4>& colors, const tcu::Vec4& uniformColor)
11822a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
1183be0d165a5d941f87320f8eb27558e037d92dcae6Mika Isojärvi	tcu::TextureLevel	reference	(glu::mapGLTransferFormat(m_transferFmt.format, m_transferFmt.dataType), VIEWPORT_WIDTH >> level, VIEWPORT_HEIGHT >> level, 1);
11842a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
1185be0d165a5d941f87320f8eb27558e037d92dcae6Mika Isojärvi	genReferenceMipmap(colors[level] + uniformColor, reference);
11862a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
11872a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return reference;
11882a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
11892a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
1190be0d165a5d941f87320f8eb27558e037d92dcae6Mika Isojärvivoid TextureLevelTestCase::genReferenceMipmap (const tcu::Vec4& color, tcu::TextureLevel& reference)
11912a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
1192be0d165a5d941f87320f8eb27558e037d92dcae6Mika Isojärvi	const int	width	= reference.getAccess().getWidth();
1193be0d165a5d941f87320f8eb27558e037d92dcae6Mika Isojärvi	const int	height	= reference.getAccess().getHeight();
1194be0d165a5d941f87320f8eb27558e037d92dcae6Mika Isojärvi	const int	left	= width  / 2;
1195be0d165a5d941f87320f8eb27558e037d92dcae6Mika Isojärvi	const int	top		= height / 2;
11962a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
11972a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	clear(getSubregion(reference.getAccess(), left,		0,		0, width-left,	top,		1),	color);
11982a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	clear(getSubregion(reference.getAccess(), 0,		top,	0, left,		height-top,	1), color);
11992a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	clear(getSubregion(reference.getAccess(), left,		top,	0, width-left,	height-top, 1), color);
12002a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	clear(getSubregion(reference.getAccess(), 0,		0,		0, left,		top,		1),	color);
12012a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
12022a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
12032a609fb223ff773c6da74ce9b1e1891d55b5252eJohn RichardsonTextureLevelTestCase::IterateResult TextureLevelTestCase::iterate (void)
12042a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
12052a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const tcu::Vec4		uniformColor	= scaleColorValue(m_texFmt, tcu::Vec4(0.1f, 0.0f, 0.0f, 1.0f));
12062a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	vector<tcu::Vec4>	levelColors;
12072a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
12082a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	levelColors.push_back(scaleColorValue(m_texFmt, tcu::Vec4(0.4f, 0.0f, 0.0f, 1.0f)));
12092a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	levelColors.push_back(scaleColorValue(m_texFmt, tcu::Vec4(0.2f, 0.0f, 0.0f, 1.0f)));
12102a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	levelColors.push_back(scaleColorValue(m_texFmt, tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f)));
12112a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
12122a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.genFramebuffers(1, &m_framebuffer);
12132a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.bindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
12142a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
12152a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	create2DTextureArrayMipMaps(levelColors);
12162a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
12172a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	// attach successive mipmap layers to framebuffer and render
12182a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	for (int level = 0; level < (int)levelColors.size(); ++level)
12192a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	{
12202a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		std::ostringstream name, desc;
12212a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		name << "Level "		<< level;
12222a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		desc << "Mipmap level " << level;
12232a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
1224be0d165a5d941f87320f8eb27558e037d92dcae6Mika Isojärvi		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), name.str(), desc.str());
1225be0d165a5d941f87320f8eb27558e037d92dcae6Mika Isojärvi		tcu::TextureLevel			result			(getReadPixelFormat(m_texFmt), VIEWPORT_WIDTH >> level, VIEWPORT_HEIGHT >> level);
12262a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		tcu::TextureLevel			reference		= genReferenceTexture(level, levelColors, uniformColor);
12272a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
1228f2cb65300c43dbd333e587544f560e15ab980c62james.glanville		m_gl.framebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_texColorBuffer, level, 0);
12292a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
12302a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		genUniformColor(uniformColor);
12312a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		render();
12322a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
12332a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		glu::readPixels(m_context.getRenderContext(), 0, 0, result.getAccess());
12342a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		verifyRenderbuffer(m_testCtx.getLog(), m_texFmt, reference, result);
12352a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
12362a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		if (m_testCtx.getTestResult() != QP_TEST_RESULT_PASS)
12372a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			return STOP;
12382a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	}
12392a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
12402a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return STOP;
12412a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
12422a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
12432a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonclass TextureLayerTestCase : public FramebufferFetchTestCase
12442a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
12452a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonpublic:
12462a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						TextureLayerTestCase		(Context& context, const char* name, const char* desc, deUint32 format);
12472a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson						~TextureLayerTestCase		(void) {}
12482a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
12492a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	IterateResult		iterate						(void);
12502a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
12512a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonprivate:
12522a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	void				create2DTextureArrayLayers	(const vector<tcu::Vec4>&  colors);
12532a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	genReferenceTexture			(int layer, const vector<tcu::Vec4>& colors, const tcu::Vec4& uniformColor);
12542a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson};
12552a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
12562a609fb223ff773c6da74ce9b1e1891d55b5252eJohn RichardsonTextureLayerTestCase::TextureLayerTestCase (Context& context, const char* name, const char* desc, deUint32 format)
12572a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	: FramebufferFetchTestCase(context, name, desc, format)
12582a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
12592a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
12602a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
12612a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonvoid TextureLayerTestCase::create2DTextureArrayLayers (const vector<tcu::Vec4>& colors)
12622a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
12632a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	int						numLayers	= (int)colors.size();
12642a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel		layerData	(glu::mapGLTransferFormat(m_transferFmt.format, m_transferFmt.dataType));
12652a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
12662a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.genTextures(1, &m_texColorBuffer);
12672a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.bindTexture(GL_TEXTURE_2D_ARRAY, m_texColorBuffer);
12682a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.texStorage3D(GL_TEXTURE_2D_ARRAY, 1, m_format, VIEWPORT_WIDTH, VIEWPORT_HEIGHT, numLayers);
12692a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.bindImageTexture(0, m_texColorBuffer, 0, GL_FALSE, 0, GL_READ_ONLY, m_format);
12702a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
12712a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	layerData.setSize(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, numLayers);
12722a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
12732a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	for (int layer = 0; layer < numLayers; layer++)
12742a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	{
12752a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		clear(layerData.getAccess(), colors[layer]);
12762a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		m_gl.texSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, layer, VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 1, m_transferFmt.format, m_transferFmt.dataType, layerData.getAccess().getDataPtr());
12772a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	}
12782a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
12792a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.bindTexture(GL_TEXTURE_2D_ARRAY, 0);
12802a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	GLU_EXPECT_NO_ERROR(m_gl.getError(), "create2DTextureArrayLayers()");
12812a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
12822a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
12832a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsontcu::TextureLevel TextureLayerTestCase::genReferenceTexture (int layer, const vector<tcu::Vec4>& colors, const tcu::Vec4& uniformColor)
12842a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
12852a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	reference	(glu::mapGLTransferFormat(m_transferFmt.format, m_transferFmt.dataType), VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 1);
12862a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	clear(reference.getAccess(), colors[layer] + uniformColor);
12872a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
12882a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return reference;
12892a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
12902a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
12912a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// Test description
12922a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Create 2D texture array containing three layers.
12932a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Each layer is assigned a different color.
12942a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Attach single layer to framebuffer and draw full screen quad.
12952a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Sum framebuffer read color with passed in uniform color.
12962a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Compare resulting surface with reference.
12972a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson// - Repeat for subsequent texture layers.
12982a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
12992a609fb223ff773c6da74ce9b1e1891d55b5252eJohn RichardsonTextureLayerTestCase::IterateResult TextureLayerTestCase::iterate (void)
13002a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
13012a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	const tcu::Vec4		uniformColor	= scaleColorValue(m_texFmt, tcu::Vec4(0.1f, 0.1f, 0.1f, 1.0f));
13022a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TextureLevel	result			(getReadPixelFormat(m_texFmt), VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
13032a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	vector<tcu::Vec4>	layerColors;
13042a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
13052a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	layerColors.push_back(scaleColorValue(m_texFmt, tcu::Vec4(0.4f, 0.0f, 0.0f, 1.0f)));
13062a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	layerColors.push_back(scaleColorValue(m_texFmt, tcu::Vec4(0.2f, 0.0f, 0.0f, 1.0f)));
13072a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	layerColors.push_back(scaleColorValue(m_texFmt, tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f)));
13082a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
13092a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.genFramebuffers(1, &m_framebuffer);
13102a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	m_gl.bindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
13112a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
13122a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	create2DTextureArrayLayers(layerColors);
13132a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
13142a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	for (int layer = 0; layer < (int)layerColors.size(); ++layer)
13152a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	{
13162a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		std::ostringstream name, desc;
13172a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		name << "Layer " << layer;
13182a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		desc << "Layer " << layer;
13192a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
13202a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		const tcu::ScopedLogSection section		(m_testCtx.getLog(), name.str(), desc.str());
13212a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		tcu::TextureLevel			reference	= genReferenceTexture(layer, layerColors, uniformColor);
13222a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
13232a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		m_gl.framebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_texColorBuffer, 0, layer);
13242a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
13252a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		genUniformColor(uniformColor);
13262a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		render();
13272a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
13282a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		glu::readPixels(m_context.getRenderContext(), 0, 0, result.getAccess());
13292a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		verifyRenderbuffer(m_testCtx.getLog(), m_texFmt, reference, result);
13302a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
13312a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		if (m_testCtx.getTestResult() != QP_TEST_RESULT_PASS)
13322a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			return STOP;
13332a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	}
13342a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
13352a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	return STOP;
13362a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
13372a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
13382a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson} // Anonymous
13392a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
13402a609fb223ff773c6da74ce9b1e1891d55b5252eJohn RichardsonShaderFramebufferFetchTests::ShaderFramebufferFetchTests (Context& context)
13412a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	: TestCaseGroup (context, "framebuffer_fetch", "GL_EXT_shader_framebuffer_fetch tests")
13422a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
13432a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
13442a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
13452a609fb223ff773c6da74ce9b1e1891d55b5252eJohn RichardsonShaderFramebufferFetchTests::~ShaderFramebufferFetchTests (void)
13462a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
13472a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
13482a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
13492a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardsonvoid ShaderFramebufferFetchTests::init (void)
13502a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson{
13512a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TestCaseGroup* const basicTestGroup				= new tcu::TestCaseGroup(m_testCtx, "basic",				"Basic framebuffer shader fetch tests");
13522a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	tcu::TestCaseGroup* const framebufferFormatTestGroup	= new tcu::TestCaseGroup(m_testCtx, "framebuffer_format",	"Texture render target formats tests");
13532a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
13542a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	// basic
13552a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	{
13562a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		basicTestGroup->addChild(new TexelFetchTestCase				(m_context,		"texel_fetch",					"Framebuffer fetches in conjunction with shader texel fetches",			GL_RGBA8));
13572a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		basicTestGroup->addChild(new LastFragDataTestCase			(m_context,		"last_frag_data",				"Framebuffer fetches with built-in fragment output of ES 2.0",			GL_RGBA8));
13582a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		basicTestGroup->addChild(new FragmentDiscardTestCase		(m_context,		"fragment_discard",				"Framebuffer fetches in combination with fragment discards",			GL_RGBA8));
13592a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		basicTestGroup->addChild(new MultipleAssignmentTestCase		(m_context,		"multiple_assignment",			"Multiple assignments to fragment color inout",							GL_RGBA8));
13602a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		basicTestGroup->addChild(new MultipleRenderTargetsTestCase	(m_context,		"multiple_render_targets",		"Framebuffer fetches used in combination with multiple render targets",	GL_RGBA8));
13612a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		basicTestGroup->addChild(new TextureLevelTestCase			(m_context,		"framebuffer_texture_level",	"Framebuffer fetches with individual texture render target mipmaps",	GL_RGBA8));
13622a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		basicTestGroup->addChild(new TextureLayerTestCase			(m_context,		"framebuffer_texture_layer",	"Framebuffer fetches with individual texture render target layers",		GL_RGBA8));
13632a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	}
13642a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
13652a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	// framebuffer formats
13662a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	{
13672a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		static const deUint32 colorFormats[] =
13682a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		{
13692a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			// RGBA formats
13702a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_RGBA32I,
13712a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_RGBA32UI,
13722a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_RGBA16I,
13732a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_RGBA16UI,
13742a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_RGBA8,
13752a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_RGBA8I,
13762a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_RGBA8UI,
13772a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_SRGB8_ALPHA8,
13782a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_RGB10_A2,
13792a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_RGB10_A2UI, GL_RGBA4, GL_RGB5_A1,
13802a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
13812a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			// RGB formats
13822a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_RGB8,
13832a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_RGB565,
13842a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
13852a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			// RG formats
13862a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_RG32I,
13872a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_RG32UI,
13882a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_RG16I,
13892a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_RG16UI,
13902a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_RG8,
13912a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_RG8I,
13922a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_RG8UI,
13932a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
13942a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			// R formats
13952a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_R32I,
13962a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_R32UI,
13972a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_R16I,
13982a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_R16UI,
13992a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_R8,
14002a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_R8I,
14012a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_R8UI,
14022a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
14032a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			// GL_EXT_color_buffer_float
14042a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_RGBA32F,
14052a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_RGBA16F,
14062a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_R11F_G11F_B10F,
14072a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_RG32F,
14082a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_RG16F,
14092a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_R32F,
14102a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_R16F,
14112a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
14122a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			// GL_EXT_color_buffer_half_float
14132a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			GL_RGB16F
14142a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		};
14152a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
14162a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson		for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(colorFormats); ndx++)
14172a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson			framebufferFormatTestGroup->addChild(new TextureFormatTestCase(m_context, getFormatName(colorFormats[ndx]), "Framebuffer fetches from texture attachments with varying formats", colorFormats[ndx]));
14182a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	}
14192a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
14202a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	addChild(basicTestGroup);
14212a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson	addChild(framebufferFormatTestGroup);
14222a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson}
14232a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson
14242a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson} // Functional
14252a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson} // gles31
14262a609fb223ff773c6da74ce9b1e1891d55b5252eJohn Richardson} // deqp
1427