summaryrefslogtreecommitdiff
path: root/modules/gles31/functional/es31fFboTestUtil.hpp
blob: 1e06a47ad041138c900e5f40f9d82e36dcc93dbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#ifndef _ES31FFBOTESTUTIL_HPP
#define _ES31FFBOTESTUTIL_HPP
/*-------------------------------------------------------------------------
 * drawElements Quality Program OpenGL ES 3.1 Module
 * -------------------------------------------------
 *
 * Copyright 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *//*!
 * \file
 * \brief FBO test utilities.
 *//*--------------------------------------------------------------------*/

#include "tcuDefs.hpp"
#include "sglrContext.hpp"
#include "gluShaderUtil.hpp"
#include "tcuTexture.hpp"
#include "tcuMatrix.hpp"
#include "tcuRenderTarget.hpp"

#include <vector>

namespace deqp
{
namespace gles31
{
namespace Functional
{
namespace FboTestUtil
{

// \todo [2012-04-29 pyry] Clean up and name as SglrUtil

// Helper class for constructing DataType vectors.
struct DataTypes
{
	std::vector<glu::DataType> vec;
	DataTypes& operator<< (glu::DataType type) { vec.push_back(type); return *this; }
};

// Shaders.

class Texture2DShader : public sglr::ShaderProgram
{
public:
					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) {}

	void			setUnit					(int samplerNdx, int unitNdx);
	void			setTexScaleBias			(int samplerNdx, const tcu::Vec4& scale, const tcu::Vec4& bias);
	void			setOutScaleBias			(const tcu::Vec4& scale, const tcu::Vec4& bias);

	void			setUniforms				(sglr::Context& context, deUint32 program) const;

	void			shadeVertices			(const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const;
	void			shadeFragments			(rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const;

private:
	struct Input
	{
		int			unitNdx;
		tcu::Vec4	scale;
		tcu::Vec4	bias;
	};

	std::vector<Input>	m_inputs;
	tcu::Vec4			m_outScale;
	tcu::Vec4			m_outBias;

	const glu::DataType	m_outputType;
};

class TextureCubeArrayShader : public sglr::ShaderProgram
{
public:
						TextureCubeArrayShader	(glu::DataType samplerType, glu::DataType outputType);
						~TextureCubeArrayShader	(void) {}

	void				setLayer				(int layer);
	void				setFace					(tcu::CubeFace face);
	void				setTexScaleBias			(const tcu::Vec4& scale, const tcu::Vec4& bias);

	void				setUniforms				(sglr::Context& context, deUint32 program) const;

	void				shadeVertices			(const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const;
	void				shadeFragments			(rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const;

private:
	tcu::Vec4			m_texScale;
	tcu::Vec4			m_texBias;
	int					m_layer;
	tcu::Mat3			m_coordMat;

	const glu::DataType	m_outputType;
};

// Framebuffer incomplete exception.
class FboIncompleteException : public tcu::TestError
{
public:
						FboIncompleteException		(deUint32 reason, const char* file, int line);
	virtual				~FboIncompleteException		(void) throw() {}

	deUint32			getReason					(void) const { return m_reason; }

private:
	deUint32			m_reason;
};

// Utility functions

glu::DataType			getFragmentOutputType				(const tcu::TextureFormat& format);
tcu::TextureFormat		getFramebufferReadFormat			(const tcu::TextureFormat& format);

const char*				getFormatName						(deUint32 format);

void					clearColorBuffer					(sglr::Context& ctx, const tcu::TextureFormat& format, const tcu::Vec4& value);
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);

tcu::RGBA				getFormatThreshold					(const tcu::TextureFormat& format);
tcu::RGBA				getFormatThreshold					(const deUint32 glFormat);

} // FboTestUtil
} // Functional
} // gles31
} // deqp

#endif // _ES31FFBOTESTUTIL_HPP