es3fPixelBufferObjectTests.cpp revision 3c827367444ee418f129b2c238299f49d3264554
12b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata/*-------------------------------------------------------------------------
22b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * drawElements Quality Program OpenGL ES 3.0 Module
32b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * -------------------------------------------------
42b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata *
52b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * Copyright 2014 The Android Open Source Project
62b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata *
72b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * Licensed under the Apache License, Version 2.0 (the "License");
82b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * you may not use this file except in compliance with the License.
92b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * You may obtain a copy of the License at
102b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata *
112b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata *      http://www.apache.org/licenses/LICENSE-2.0
122b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata *
132b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * Unless required by applicable law or agreed to in writing, software
142b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * distributed under the License is distributed on an "AS IS" BASIS,
152b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
162b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * See the License for the specific language governing permissions and
172b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * limitations under the License.
182b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata *
192b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata *//*!
202b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * \file
212b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * \brief Pixel Buffer Object tests
222b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata *//*--------------------------------------------------------------------*/
23366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
24366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#include "es3fPixelBufferObjectTests.hpp"
25366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
268a568dd4ad368d37c059ec9c8da0e894417a27d9Petr Machata#include "tcuTexture.hpp"
278a568dd4ad368d37c059ec9c8da0e894417a27d9Petr Machata#include "tcuTextureUtil.hpp"
28d2c5dfdf0c746bb0d0365505577461f0058aedf9Andrey Zonov#include "tcuImageCompare.hpp"
29d2c5dfdf0c746bb0d0365505577461f0058aedf9Andrey Zonov#include "tcuTestLog.hpp"
30366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#include "tcuRenderTarget.hpp"
31366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
32366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#include "gluTextureUtil.hpp"
33366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#include "gluPixelTransfer.hpp"
34366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#include "gluShaderProgram.hpp"
35366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
36744f255ed0d676896dbe2f326b9c353c56438f0aPetr Machata#include "deRandom.hpp"
37a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata#include "deString.h"
386d8aa0bba1fb9473f6e92738975f6be73a6ac722Petr Machata
392b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata#include <string>
40366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#include <sstream>
41366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
42366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#include "glw.h"
43366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
44366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machatausing std::string;
45366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machatausing std::stringstream;
46366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
47366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machatanamespace deqp
48366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata{
49366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machatanamespace gles3
50366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata{
51366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machatanamespace Functional
52366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata{
53366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
54366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machatanamespace
55366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata{
56f6ec08afb96292fd3c802c1f633d8de249664c72Petr Machata
57f6ec08afb96292fd3c802c1f633d8de249664c72Petr Machataclass ReadPixelsTest : public TestCase
58f6ec08afb96292fd3c802c1f633d8de249664c72Petr Machata{
59f6ec08afb96292fd3c802c1f633d8de249664c72Petr Machatapublic:
60f6ec08afb96292fd3c802c1f633d8de249664c72Petr Machata	struct TestSpec
61366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	{
62366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata		enum FramebufferType
63366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata		{
64366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata			FRAMEBUFFERTYPE_NATIVE = 0,
65366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata			FRAMEBUFFERTYPE_RENDERBUFFER
66366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata		};
67366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
68366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata		string			name;
69f6ec08afb96292fd3c802c1f633d8de249664c72Petr Machata		string			description;
7094078ecce3a103c28457e6f90f1e5b0dacc61146Petr Machata
71f6ec08afb96292fd3c802c1f633d8de249664c72Petr Machata		bool			useColorClear;
72366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata		bool			renderTriangles;
73366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
74366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata		FramebufferType	framebufferType;
75366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata		GLenum			renderbufferFormat;
76366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	};
77366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
78366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata					ReadPixelsTest				(Context& context, const TestSpec& spec);
79366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata					~ReadPixelsTest				(void);
80366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
81fd43ef7bb48260aadd4d8335371f75015e680108Petr Machata	void			init						(void);
82366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	void			deinit						(void);
83366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
84366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	IterateResult	iterate						(void);
85366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
86366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machataprivate:
87366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	void						renderTriangle	(const tcu::Vec3& a, const tcu::Vec3& b, const tcu::Vec3& c);
88366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	void						clearColor		(float r, float g, float b, float a);
89366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
90ecb082f480f057dc166c9d62e8776c892caf5e11Petr Machata	de::Random					m_random;
91bac2da505ee174b7fb984b975c5938f88f0dbab2Petr Machata	tcu::TestLog&				m_log;
92ecb082f480f057dc166c9d62e8776c892caf5e11Petr Machata	glu::ShaderProgram*			m_program;
93366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
94366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	TestSpec::FramebufferType	m_framebuffeType;
95366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
96366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	GLenum						m_renderbufferFormat;
97366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	tcu::TextureChannelClass	m_texChannelClass;
98366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
99ba1664b062414481d0f37d06bb01a19874c8d481Petr Machata	bool						m_useColorClears;
100366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	bool						m_renderTriangles;
10176dd9290bd760f363a6f39db06020e61e3f7b345Petr Machata
10276dd9290bd760f363a6f39db06020e61e3f7b345Petr Machata	GLfloat						m_colorScale;
10376dd9290bd760f363a6f39db06020e61e3f7b345Petr Machata};
1042b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
105366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
106366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr MachataReadPixelsTest::ReadPixelsTest (Context& context, const TestSpec& spec)
107366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	: TestCase				(context, spec.name.c_str(), spec.description.c_str())
108366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	, m_random				(deStringHash(spec.name.c_str()))
109366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	, m_log					(m_testCtx.getLog())
110366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	, m_program				(NULL)
1114d4e1b853db0c97b7c7f023bc301e3c3eee58ce4Petr Machata	, m_framebuffeType		(spec.framebufferType)
1124d4e1b853db0c97b7c7f023bc301e3c3eee58ce4Petr Machata	, m_renderbufferFormat	(spec.renderbufferFormat)
1134d4e1b853db0c97b7c7f023bc301e3c3eee58ce4Petr Machata	, m_texChannelClass		(tcu::TEXTURECHANNELCLASS_LAST)
1144d4e1b853db0c97b7c7f023bc301e3c3eee58ce4Petr Machata	, m_useColorClears		(spec.useColorClear)
1154d4e1b853db0c97b7c7f023bc301e3c3eee58ce4Petr Machata	, m_renderTriangles		(spec.renderTriangles)
116366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	, m_colorScale			(1.0f)
1174d4e1b853db0c97b7c7f023bc301e3c3eee58ce4Petr Machata{
1184d4e1b853db0c97b7c7f023bc301e3c3eee58ce4Petr Machata
1194d4e1b853db0c97b7c7f023bc301e3c3eee58ce4Petr Machata	if (m_framebuffeType == TestSpec::FRAMEBUFFERTYPE_NATIVE)
120366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	{
121366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata		m_colorScale = 1.0f;
122366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	}
123366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	else if (m_framebuffeType == TestSpec::FRAMEBUFFERTYPE_RENDERBUFFER)
124366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	{
125366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata		m_texChannelClass = tcu::getTextureChannelClass(glu::mapGLInternalFormat(spec.renderbufferFormat).type);
126366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata		switch (m_texChannelClass)
127366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata		{
128366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata			case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
129366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata				m_colorScale = 1.0f;
130366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata				break;
131366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
132366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata			case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
133366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata				m_colorScale = 100.0f;
134366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata				break;
135366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
136366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata			case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
137366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata				m_colorScale = 100.0f;
138366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata				break;
139366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
140366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata			case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
141366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata				m_colorScale = 100.0f;
142366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata				break;
143366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
144366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata			default:
145744f255ed0d676896dbe2f326b9c353c56438f0aPetr Machata				DE_ASSERT(false);
1460f6e6d9861ce790cb8b7d07aca28a5878d705359Petr Machata		}
147744f255ed0d676896dbe2f326b9c353c56438f0aPetr Machata	}
148366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	else
149366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata		DE_ASSERT(false);
15075934ad3b30790f6a892069576d0790a351ef101Petr Machata}
15175934ad3b30790f6a892069576d0790a351ef101Petr Machata
15275934ad3b30790f6a892069576d0790a351ef101Petr MachataReadPixelsTest::~ReadPixelsTest (void)
1532b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata{
1543d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata}
1553d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata
1563d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machatavoid ReadPixelsTest::init (void)
1573d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata{
1583d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata	// Check extensions
1593d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata	if (m_framebuffeType == TestSpec::FRAMEBUFFERTYPE_RENDERBUFFER)
1603d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata	{
1613d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata		bool supported = false;
1623d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata
1633d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata		if (m_renderbufferFormat == GL_RGBA16F
1643d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata			|| m_renderbufferFormat == GL_RG16F)
1653d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata		{
1663d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata			std::istringstream extensions(std::string((const char*)glGetString(GL_EXTENSIONS)));
16775934ad3b30790f6a892069576d0790a351ef101Petr Machata			std::string extension;
168366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
169366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata			while (std::getline(extensions, extension, ' '))
1702b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata			{
1712b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata				if (extension=="GL_EXT_color_buffer_half_float")
1722b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata				{
1732b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata					supported = true;
1742b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata					break;
175a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata				}
176a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata				if (extension=="GL_EXT_color_buffer_float")
177a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata				{
17874132a447b18c588c698ecfb8cf4ad4b16360f2fPetr Machata					supported = true;
1792b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata					break;
1802b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata				}
181366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata			}
1822b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata		}
183a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata		else if (m_renderbufferFormat == GL_RGBA32F
184a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata				|| m_renderbufferFormat == GL_RG32F
18574132a447b18c588c698ecfb8cf4ad4b16360f2fPetr Machata				|| m_renderbufferFormat == GL_R11F_G11F_B10F)
1862b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata		{
1872b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata			std::istringstream extensions(std::string((const char*)glGetString(GL_EXTENSIONS)));
188366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata			std::string extension;
1892b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
190366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata			while (std::getline(extensions, extension, ' '))
191fd2641c0d27705c89d224e3205b1296110b6598cPetr Machata			{
192fd2641c0d27705c89d224e3205b1296110b6598cPetr Machata				if (extension=="GL_EXT_color_buffer_float")
193fd2641c0d27705c89d224e3205b1296110b6598cPetr Machata				{
194fd2641c0d27705c89d224e3205b1296110b6598cPetr Machata					supported = true;
195fd2641c0d27705c89d224e3205b1296110b6598cPetr Machata					break;
196366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata				}
197366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata			}
198366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata		}
1992b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata		else
2002b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata			supported = true;
2012b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
2022b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata		if (!supported)
2032b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata			throw tcu::NotSupportedError("Renderbuffer format not supported", "", __FILE__, __LINE__);
2042b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata	}
2052b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
206ef2fd27a347bbb0e7cca7fdee97422f6ae4d4bdaPetr Machata	std::string outtype = "";
207ef2fd27a347bbb0e7cca7fdee97422f6ae4d4bdaPetr Machata
208ef2fd27a347bbb0e7cca7fdee97422f6ae4d4bdaPetr Machata	if (m_framebuffeType == TestSpec::FRAMEBUFFERTYPE_NATIVE)
209ef2fd27a347bbb0e7cca7fdee97422f6ae4d4bdaPetr Machata		outtype = "vec4";
210ef2fd27a347bbb0e7cca7fdee97422f6ae4d4bdaPetr Machata	else if (m_framebuffeType == TestSpec::FRAMEBUFFERTYPE_RENDERBUFFER)
211ef2fd27a347bbb0e7cca7fdee97422f6ae4d4bdaPetr Machata	{
212ef2fd27a347bbb0e7cca7fdee97422f6ae4d4bdaPetr Machata		switch (m_texChannelClass)
213ef2fd27a347bbb0e7cca7fdee97422f6ae4d4bdaPetr Machata		{
214a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata			case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
215a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata				outtype = "vec4";
2162b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata				break;
2172b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
2182b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata			case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
2192b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata				outtype = "ivec4";
2202b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata				break;
2212b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
22252dbfb161efeab85bddc880966db2f7af9b9cf9aPetr Machata			case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
22352dbfb161efeab85bddc880966db2f7af9b9cf9aPetr Machata				outtype = "uvec4";
22452dbfb161efeab85bddc880966db2f7af9b9cf9aPetr Machata				break;
225f7fee43f72667f453bba5aaeea6b5490ece6792aPetr Machata
226f7fee43f72667f453bba5aaeea6b5490ece6792aPetr Machata			case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
227f7fee43f72667f453bba5aaeea6b5490ece6792aPetr Machata				outtype = "vec4";
2282b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata				break;
229a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata
230a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata			default:
231d3cc9889fdfe2e523e99ca5f664f8ae4b3936612Petr Machata				DE_ASSERT(false);
232d3cc9889fdfe2e523e99ca5f664f8ae4b3936612Petr Machata		}
233d3cc9889fdfe2e523e99ca5f664f8ae4b3936612Petr Machata	}
234d3cc9889fdfe2e523e99ca5f664f8ae4b3936612Petr Machata	else
235d3cc9889fdfe2e523e99ca5f664f8ae4b3936612Petr Machata		DE_ASSERT(false);
236d3cc9889fdfe2e523e99ca5f664f8ae4b3936612Petr Machata
237cc77b0e0e735d598f4bc746f8e79b6cd342bd606Edgar E. Iglesias
238cc77b0e0e735d598f4bc746f8e79b6cd342bd606Edgar E. Iglesias	const char* vertexShaderSource =
239cc77b0e0e735d598f4bc746f8e79b6cd342bd606Edgar E. Iglesias	"#version 300 es\n"
240cc77b0e0e735d598f4bc746f8e79b6cd342bd606Edgar E. Iglesias	"in mediump vec3 a_position;\n"
241cc77b0e0e735d598f4bc746f8e79b6cd342bd606Edgar E. Iglesias	"in mediump vec4 a_color;\n"
242165b566a50b2bd560af3bd9649e456915397066bPetr Machata	"uniform mediump float u_colorScale;\n"
243165b566a50b2bd560af3bd9649e456915397066bPetr Machata	"out mediump vec4 v_color;\n"
244165b566a50b2bd560af3bd9649e456915397066bPetr Machata	"void main(void)\n"
245165b566a50b2bd560af3bd9649e456915397066bPetr Machata	"{\n"
246165b566a50b2bd560af3bd9649e456915397066bPetr Machata	"\tgl_Position = vec4(a_position, 1.0);\n"
247165b566a50b2bd560af3bd9649e456915397066bPetr Machata	"\tv_color = u_colorScale * a_color;\n"
248165b566a50b2bd560af3bd9649e456915397066bPetr Machata	"}";
249165b566a50b2bd560af3bd9649e456915397066bPetr Machata
250366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	stringstream fragmentShaderSource;
251
252	fragmentShaderSource <<
253	"#version 300 es\n"
254	"in mediump vec4 v_color;\n";
255
256
257	fragmentShaderSource << "layout (location = 0) out mediump " << outtype << " o_color;\n"
258	"void main(void)\n"
259	"{\n"
260	"\to_color = " << outtype << "(v_color);\n"
261	"}";
262
263	m_program = new glu::ShaderProgram(m_context.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource.str()));
264
265	if (!m_program->isOk())
266	{
267		m_log << *m_program;
268		TCU_FAIL("Failed to compile shader");
269	}
270}
271
272void ReadPixelsTest::deinit (void)
273{
274	if (m_program)
275		delete m_program;
276	m_program = NULL;
277}
278
279void ReadPixelsTest::renderTriangle (const tcu::Vec3& a, const tcu::Vec3& b, const tcu::Vec3& c)
280{
281	float positions[3*3];
282
283	positions[0] = a.x();
284	positions[1] = a.y();
285	positions[2] = a.z();
286
287	positions[3] = b.x();
288	positions[4] = b.y();
289	positions[5] = b.z();
290
291	positions[6] = c.x();
292	positions[7] = c.y();
293	positions[8] = c.z();
294
295	float colors[] = {
296		1.0f, 0.0f, 0.0f, 1.0f,
297		0.0f, 1.0f, 0.0f, 1.0f,
298		0.0f, 0.0f, 1.0f, 1.0f
299	};
300
301	GLU_CHECK_CALL(glUseProgram(m_program->getProgram()));
302
303	GLuint coordLoc = (GLuint)-1;
304	GLuint colorLoc = (GLuint)-1;
305	GLuint colorScaleLoc = (GLuint)-1;
306
307	colorScaleLoc = glGetUniformLocation(m_program->getProgram(), "u_colorScale");
308	TCU_CHECK(colorScaleLoc != (GLuint)-1);
309
310	GLU_CHECK_CALL(glUniform1f(colorScaleLoc, m_colorScale));
311
312	coordLoc = glGetAttribLocation(m_program->getProgram(), "a_position");
313	TCU_CHECK(coordLoc != (GLuint)-1);
314
315	colorLoc = glGetAttribLocation(m_program->getProgram(), "a_color");
316	TCU_CHECK(colorLoc != (GLuint)-1);
317
318	GLU_CHECK_CALL(glEnableVertexAttribArray(colorLoc));
319	GLU_CHECK_CALL(glEnableVertexAttribArray(coordLoc));
320
321	GLU_CHECK_CALL(glVertexAttribPointer(coordLoc, 3, GL_FLOAT, GL_FALSE, 0, positions));
322	GLU_CHECK_CALL(glVertexAttribPointer(colorLoc, 4, GL_FLOAT, GL_FALSE, 0, colors));
323
324	GLU_CHECK_CALL(glDrawArrays(GL_TRIANGLES, 0, 3));
325
326	GLU_CHECK_CALL(glDisableVertexAttribArray(colorLoc));
327	GLU_CHECK_CALL(glDisableVertexAttribArray(coordLoc));
328
329}
330
331
332void ReadPixelsTest::clearColor (float r, float g, float b, float a)
333{
334	if (m_framebuffeType == TestSpec::FRAMEBUFFERTYPE_NATIVE)
335	{
336		GLU_CHECK_CALL(glClearColor(r, g, b, a));
337		GLU_CHECK_CALL(glClear(GL_COLOR_BUFFER_BIT));
338	}
339	else if (m_framebuffeType == TestSpec::FRAMEBUFFERTYPE_RENDERBUFFER)
340	{
341		switch (m_texChannelClass)
342		{
343			case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
344			{
345				GLU_CHECK_CALL(glClearColor(r, g, b, a));
346				GLU_CHECK_CALL(glClear(GL_COLOR_BUFFER_BIT));
347				break;
348			}
349
350			case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
351			{
352				GLint color[4] = { (GLint)r, (GLint)g, (GLint)b, (GLint)a };
353
354				GLU_CHECK_CALL(glClearBufferiv(GL_COLOR, 0, color));
355				break;
356			}
357
358			case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
359			{
360				GLuint color[4] = { (GLuint)r, (GLuint)g, (GLuint)b, (GLuint)a };
361
362				GLU_CHECK_CALL(glClearBufferuiv(GL_COLOR, 0, color));
363				break;
364			}
365
366			case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
367			{
368				GLfloat color[4] = { (GLfloat)r, (GLfloat)g, (GLfloat)b, (GLfloat)a };
369
370				GLU_CHECK_CALL(glClearBufferfv(GL_COLOR, 0, color));
371				break;
372			}
373
374			default:
375				DE_ASSERT(false);
376		}
377	}
378	else
379		DE_ASSERT(false);
380
381}
382
383TestCase::IterateResult ReadPixelsTest::iterate(void)
384{
385	int width				= m_context.getRenderTarget().getWidth();
386	int height				= m_context.getRenderTarget().getHeight();
387
388	GLuint framebuffer	= 0;
389	GLuint renderbuffer	= 0;
390
391	switch (m_framebuffeType)
392	{
393		case TestSpec::FRAMEBUFFERTYPE_NATIVE:
394			GLU_CHECK_CALL(glBindFramebuffer(GL_FRAMEBUFFER, framebuffer));
395			break;
396
397		case TestSpec::FRAMEBUFFERTYPE_RENDERBUFFER:
398		{
399			GLU_CHECK_CALL(glGenFramebuffers(1, &framebuffer));
400			GLU_CHECK_CALL(glGenRenderbuffers(1, &renderbuffer));
401
402			GLU_CHECK_CALL(glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer));
403			GLU_CHECK_CALL(glRenderbufferStorage(GL_RENDERBUFFER, m_renderbufferFormat, width, height));
404
405			GLU_CHECK_CALL(glBindFramebuffer(GL_FRAMEBUFFER, framebuffer));
406			GLU_CHECK_CALL(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer));
407
408			break;
409		}
410
411		default:
412			DE_ASSERT(false);
413	}
414
415	clearColor(m_colorScale * 0.4f, m_colorScale * 1.0f, m_colorScale * 0.5f, m_colorScale * 1.0f);
416
417	if (m_useColorClears)
418	{
419		const int maxClearCount	= 10;
420		const int minClearCount	= 6;
421		const int minClearSize	= 15;
422
423		int clearCount = m_random.getInt(minClearCount, maxClearCount);
424
425		for (int clearNdx = 0; clearNdx < clearCount; clearNdx++)
426		{
427			int clearX = m_random.getInt(0, width - minClearSize);
428			int clearY = m_random.getInt(0, height - minClearSize);
429
430			int clearWidth = m_random.getInt(minClearSize, width - clearX);
431			int clearHeight = m_random.getInt(minClearSize, height - clearY);
432
433			float clearRed		= m_colorScale * m_random.getFloat();
434			float clearGreen	= m_colorScale * m_random.getFloat();
435			float clearBlue		= m_colorScale * m_random.getFloat();
436			float clearAlpha	= m_colorScale * (0.5f + 0.5f * m_random.getFloat());
437
438			GLU_CHECK_CALL(glEnable(GL_SCISSOR_TEST));
439			GLU_CHECK_CALL(glScissor(clearX, clearY, clearWidth, clearHeight));
440
441			clearColor(clearRed, clearGreen, clearBlue, clearAlpha);
442		}
443
444		GLU_CHECK_CALL(glDisable(GL_SCISSOR_TEST));
445	}
446
447	if (m_renderTriangles)
448	{
449		const int minTriangleCount = 4;
450		const int maxTriangleCount = 10;
451
452		int triangleCount = m_random.getInt(minTriangleCount, maxTriangleCount);
453
454		for (int triangleNdx = 0; triangleNdx < triangleCount; triangleNdx++)
455		{
456			float x1 = 2.0f * m_random.getFloat() - 1.0f;
457			float y1 = 2.0f * m_random.getFloat() - 1.0f;
458			float z1 = 2.0f * m_random.getFloat() - 1.0f;
459
460			float x2 = 2.0f * m_random.getFloat() - 1.0f;
461			float y2 = 2.0f * m_random.getFloat() - 1.0f;
462			float z2 = 2.0f * m_random.getFloat() - 1.0f;
463
464			float x3 = 2.0f * m_random.getFloat() - 1.0f;
465			float y3 = 2.0f * m_random.getFloat() - 1.0f;
466			float z3 = 2.0f * m_random.getFloat() - 1.0f;
467
468			renderTriangle(tcu::Vec3(x1, y1, z1), tcu::Vec3(x2, y2, z2), tcu::Vec3(x3, y3, z3));
469		}
470	}
471
472	tcu::TextureFormat	readFormat;
473	GLenum				readPixelsFormat;
474	GLenum				readPixelsType;
475	bool				floatCompare;
476
477
478	if (m_framebuffeType == TestSpec::FRAMEBUFFERTYPE_NATIVE)
479	{
480		readFormat			= glu::mapGLTransferFormat(GL_RGBA, GL_UNSIGNED_BYTE);
481		readPixelsFormat	= GL_RGBA;
482		readPixelsType		= GL_UNSIGNED_BYTE;
483		floatCompare		= false;
484	}
485	else if (m_framebuffeType == TestSpec::FRAMEBUFFERTYPE_RENDERBUFFER)
486	{
487		switch (m_texChannelClass)
488		{
489			case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
490				readFormat			= glu::mapGLTransferFormat(GL_RGBA, GL_UNSIGNED_BYTE);
491				readPixelsFormat	= GL_RGBA;
492				readPixelsType		= GL_UNSIGNED_BYTE;
493				floatCompare		= true;
494				break;
495
496			case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
497				readFormat			= glu::mapGLTransferFormat(GL_RGBA_INTEGER, GL_INT);
498				readPixelsFormat	= GL_RGBA_INTEGER;
499				readPixelsType		= GL_INT;
500				floatCompare		= false;
501				break;
502
503			case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
504				readFormat			= glu::mapGLTransferFormat(GL_RGBA_INTEGER, GL_UNSIGNED_INT);
505				readPixelsFormat	= GL_RGBA_INTEGER;
506				readPixelsType		= GL_UNSIGNED_INT;
507				floatCompare		= false;
508				break;
509
510			case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
511				readFormat			= glu::mapGLTransferFormat(GL_RGBA, GL_FLOAT);
512				readPixelsFormat	= GL_RGBA;
513				readPixelsType		= GL_FLOAT;
514				floatCompare		= true;
515				break;
516
517			default:
518				DE_ASSERT(false);
519				// Silence warnings
520				readFormat			= glu::mapGLTransferFormat(GL_RGBA, GL_FLOAT);
521				readPixelsFormat	= GL_RGBA;
522				readPixelsType		= GL_FLOAT;
523				floatCompare		= true;
524		}
525	}
526	else
527	{
528		// Silence warnings
529		readFormat			= glu::mapGLTransferFormat(GL_RGBA, GL_FLOAT);
530		readPixelsFormat	= GL_RGBA;
531		readPixelsType		= GL_FLOAT;
532		floatCompare		= true;
533		DE_ASSERT(false);
534	}
535
536	tcu::Texture2D readRefrence(readFormat, width, height);
537	readRefrence.allocLevel(0);
538
539	GLuint pixelBuffer = (GLuint)-1;
540
541	GLU_CHECK_CALL(glGenBuffers(1, &pixelBuffer));
542	GLU_CHECK_CALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, pixelBuffer));
543	GLU_CHECK_CALL(glBufferData(GL_PIXEL_PACK_BUFFER, readRefrence.getLevel(0).getDataSize(), NULL, GL_STREAM_READ));
544
545	GLU_CHECK_CALL(glReadPixels(0, 0, width, height, readPixelsFormat, readPixelsType, 0));
546
547	const deUint8* bufferData = (const deUint8*)glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, readRefrence.getLevel(0).getDataSize(), GL_MAP_READ_BIT);
548	GLU_CHECK_MSG("glMapBufferRange() failed");
549
550	tcu::ConstPixelBufferAccess readResult(readFormat, width, height, 1, bufferData);
551
552	GLU_CHECK_CALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0));
553
554	GLU_CHECK_CALL(glReadPixels(0, 0, width, height, readPixelsFormat, readPixelsType, readRefrence.getLevel(0).getDataPtr()));
555
556	if (framebuffer)
557		GLU_CHECK_CALL(glDeleteFramebuffers(1, &framebuffer));
558
559	if (renderbuffer)
560		GLU_CHECK_CALL(glDeleteRenderbuffers(1, &renderbuffer));
561
562
563	bool isOk = false;
564
565	if (floatCompare)
566		isOk = tcu::floatThresholdCompare(m_log, "Result comparision", "Result of read pixels to memory compared with result of read pixels to buffer", readRefrence.getLevel(0), readResult, tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::COMPARE_LOG_RESULT);
567	else
568		isOk = tcu::intThresholdCompare(m_log, "Result comparision", "Result of read pixels to memory compared with result of read pixels to buffer", readRefrence.getLevel(0), readResult, tcu::UVec4(0, 0, 0, 0), tcu::COMPARE_LOG_RESULT);
569
570	GLU_CHECK_CALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, pixelBuffer));
571	GLU_CHECK_CALL(glUnmapBuffer(GL_PIXEL_PACK_BUFFER));
572	GLU_CHECK_CALL(glDeleteBuffers(1, &pixelBuffer));
573
574	if (isOk)
575	{
576		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
577		return STOP;
578	}
579	else
580	{
581		m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
582		return STOP;
583	}
584}
585
586} // anonymous
587
588PixelBufferObjectTests::PixelBufferObjectTests (Context& context)
589	: TestCaseGroup (context, "pbo", "Pixel buffer objects tests")
590{
591}
592
593PixelBufferObjectTests::~PixelBufferObjectTests (void)
594{
595}
596
597void PixelBufferObjectTests::init (void)
598{
599	TestCaseGroup* nativeFramebufferGroup = new TestCaseGroup(m_context, "native", "Tests with reading from native framebuffer");
600
601	ReadPixelsTest::TestSpec nativeFramebufferTests[] = {
602		{
603			"clears",
604			"Simple read pixels test with color clears",
605			true,
606			false,
607			ReadPixelsTest::TestSpec::FRAMEBUFFERTYPE_NATIVE,
608			GL_NONE
609		},
610		{
611			"triangles",
612			"Simple read pixels test rendering triangles",
613			false,
614			true,
615			ReadPixelsTest::TestSpec::FRAMEBUFFERTYPE_NATIVE,
616			GL_NONE
617		}
618	};
619
620	for (int testNdx = 0; testNdx < DE_LENGTH_OF_ARRAY(nativeFramebufferTests); testNdx++)
621	{
622		nativeFramebufferGroup->addChild(new ReadPixelsTest(m_context, nativeFramebufferTests[testNdx]));
623	}
624
625	addChild(nativeFramebufferGroup);
626
627	TestCaseGroup* renderbufferGroup = new TestCaseGroup(m_context, "renderbuffer", "Tests with reading from renderbuffer");
628
629	GLenum renderbufferFormats[] = {
630		GL_RGBA8,
631		GL_RGBA8I,
632		GL_RGBA8UI,
633		GL_RGBA16F,
634		GL_RGBA16I,
635		GL_RGBA16UI,
636		GL_RGBA32F,
637		GL_RGBA32I,
638		GL_RGBA32UI,
639
640		GL_SRGB8_ALPHA8,
641		GL_RGB10_A2,
642		GL_RGB10_A2UI,
643		GL_RGBA4,
644		GL_RGB5_A1,
645
646		GL_RGB8,
647		GL_RGB565,
648
649		GL_R11F_G11F_B10F,
650
651		GL_RG8,
652		GL_RG8I,
653		GL_RG8UI,
654		GL_RG16F,
655		GL_RG16I,
656		GL_RG16UI,
657		GL_RG32F,
658		GL_RG32I,
659		GL_RG32UI
660	};
661
662	const char* renderbufferFormatsStr[] = {
663		"rgba8",
664		"rgba8i",
665		"rgba8ui",
666		"rgba16f",
667		"rgba16i",
668		"rgba16ui",
669		"rgba32f",
670		"rgba32i",
671		"rgba32ui",
672
673		"srgb8_alpha8",
674		"rgb10_a2",
675		"rgb10_a2ui",
676		"rgba4",
677		"rgb5_a1",
678
679		"rgb8",
680		"rgb565",
681
682		"r11f_g11f_b10f",
683
684		"rg8",
685		"rg8i",
686		"rg8ui",
687		"rg16f",
688		"rg16i",
689		"rg16ui",
690		"rg32f",
691		"rg32i",
692		"rg32ui"
693	};
694
695	DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(renderbufferFormatsStr) == DE_LENGTH_OF_ARRAY(renderbufferFormats));
696
697	for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(renderbufferFormats); formatNdx++)
698	{
699		for (int trianglesClears = 0; trianglesClears < 2; trianglesClears++)
700		{
701			ReadPixelsTest::TestSpec testSpec;
702
703			testSpec.name					= string(renderbufferFormatsStr [formatNdx]) + "_" + (trianglesClears == 0 ? "triangles" : "clears"),
704			testSpec.description			= testSpec.name;
705			testSpec.useColorClear			= trianglesClears == 1,
706			testSpec.renderTriangles		= trianglesClears == 0,
707			testSpec.framebufferType		= ReadPixelsTest::TestSpec::FRAMEBUFFERTYPE_RENDERBUFFER,
708			testSpec.renderbufferFormat		= renderbufferFormats[formatNdx];
709
710			renderbufferGroup->addChild(new ReadPixelsTest(m_context, testSpec));
711		}
712	}
713
714	addChild(renderbufferGroup);
715}
716
717} // Functional
718} // gles3
719} // deqp
720