1 #ifndef _ES31FFBOTESTUTIL_HPP
2 #define _ES31FFBOTESTUTIL_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program OpenGL ES 3.1 Module
5  * -------------------------------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief FBO test utilities.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "tcuDefs.hpp"
27 #include "sglrContext.hpp"
28 #include "gluShaderUtil.hpp"
29 #include "tcuTexture.hpp"
30 #include "tcuMatrix.hpp"
31 #include "tcuRenderTarget.hpp"
32 
33 #include <vector>
34 
35 namespace deqp
36 {
37 namespace gles31
38 {
39 namespace Functional
40 {
41 namespace FboTestUtil
42 {
43 
44 // \todo [2012-04-29 pyry] Clean up and name as SglrUtil
45 
46 // Helper class for constructing DataType vectors.
47 struct DataTypes
48 {
49 	std::vector<glu::DataType> vec;
operator <<deqp::gles31::Functional::FboTestUtil::DataTypes50 	DataTypes& operator<< (glu::DataType type) { vec.push_back(type); return *this; }
51 };
52 
53 // Shaders.
54 
55 class Texture2DShader : public sglr::ShaderProgram
56 {
57 public:
58 					Texture2DShader			(const DataTypes& samplerTypes, glu::DataType outputType, const tcu::Vec4& outScale = tcu::Vec4(1.0f), const tcu::Vec4& outBias = tcu::Vec4(0.0f));
~Texture2DShader(void)59 					~Texture2DShader		(void) {}
60 
61 	void			setUnit					(int samplerNdx, int unitNdx);
62 	void			setTexScaleBias			(int samplerNdx, const tcu::Vec4& scale, const tcu::Vec4& bias);
63 	void			setOutScaleBias			(const tcu::Vec4& scale, const tcu::Vec4& bias);
64 
65 	void			setUniforms				(sglr::Context& context, deUint32 program) const;
66 
67 	void			shadeVertices			(const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const;
68 	void			shadeFragments			(rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const;
69 
70 private:
71 	struct Input
72 	{
73 		int			unitNdx;
74 		tcu::Vec4	scale;
75 		tcu::Vec4	bias;
76 	};
77 
78 	std::vector<Input>	m_inputs;
79 	tcu::Vec4			m_outScale;
80 	tcu::Vec4			m_outBias;
81 
82 	const glu::DataType	m_outputType;
83 };
84 
85 class TextureCubeArrayShader : public sglr::ShaderProgram
86 {
87 public:
88 						TextureCubeArrayShader	(glu::DataType samplerType, glu::DataType outputType);
~TextureCubeArrayShader(void)89 						~TextureCubeArrayShader	(void) {}
90 
91 	void				setLayer				(int layer);
92 	void				setFace					(tcu::CubeFace face);
93 	void				setTexScaleBias			(const tcu::Vec4& scale, const tcu::Vec4& bias);
94 
95 	void				setUniforms				(sglr::Context& context, deUint32 program) const;
96 
97 	void				shadeVertices			(const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const;
98 	void				shadeFragments			(rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const;
99 
100 private:
101 	tcu::Vec4			m_texScale;
102 	tcu::Vec4			m_texBias;
103 	int					m_layer;
104 	tcu::Mat3			m_coordMat;
105 
106 	const glu::DataType	m_outputType;
107 };
108 
109 // Framebuffer incomplete exception.
110 class FboIncompleteException : public tcu::TestError
111 {
112 public:
113 						FboIncompleteException		(deUint32 reason, const char* file, int line);
~FboIncompleteException(void)114 	virtual				~FboIncompleteException		(void) throw() {}
115 
getReason(void) const116 	deUint32			getReason					(void) const { return m_reason; }
117 
118 private:
119 	deUint32			m_reason;
120 };
121 
122 // Utility functions
123 
124 glu::DataType			getFragmentOutputType				(const tcu::TextureFormat& format);
125 tcu::TextureFormat		getFramebufferReadFormat			(const tcu::TextureFormat& format);
126 
127 const char*				getFormatName						(deUint32 format);
128 
129 void					clearColorBuffer					(sglr::Context& ctx, const tcu::TextureFormat& format, const tcu::Vec4& value);
130 void					readPixels							(sglr::Context& ctx, tcu::Surface& dst, int x, int y, int width, int height, const tcu::TextureFormat& format, const tcu::Vec4& scale, const tcu::Vec4& bias);
131 
132 tcu::RGBA				getFormatThreshold					(const tcu::TextureFormat& format);
133 tcu::RGBA				getFormatThreshold					(const deUint32 glFormat);
134 
135 } // FboTestUtil
136 } // Functional
137 } // gles31
138 } // deqp
139 
140 #endif // _ES31FFBOTESTUTIL_HPP
141