1 #ifndef _GLCSHADERLIBRARYCASE_HPP
2 #define _GLCSHADERLIBRARYCASE_HPP
3 /*-------------------------------------------------------------------------
4  * OpenGL Conformance Test Suite
5  * -----------------------------
6  *
7  * Copyright (c) 2016 Google Inc.
8  * Copyright (c) 2016 The Khronos Group Inc.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */ /*!
23  * \file
24  * \brief Shader test case.
25  */ /*-------------------------------------------------------------------*/
26 
27 #include "glcTestCase.hpp"
28 #include "gluDefs.hpp"
29 #include "gluRenderContext.hpp"
30 #include "gluShaderUtil.hpp"
31 #include "tcuSurface.hpp"
32 
33 #include <string>
34 #include <vector>
35 
36 namespace deqp
37 {
38 namespace sl
39 {
40 
41 // ShaderCase node.
42 
43 class ShaderCase : public tcu::TestCase
44 {
45 public:
46 	enum CaseType
47 	{
48 		CASETYPE_COMPLETE = 0,  //!< Has both shaders.
49 		CASETYPE_VERTEX_ONLY,   //!< Has only vertex shader.
50 		CASETYPE_FRAGMENT_ONLY, //!< Has only fragment shader.
51 
52 		CASETYPE_LAST
53 	};
54 
55 	enum ExpectResult
56 	{
57 		EXPECT_PASS = 0,
58 		EXPECT_COMPILE_FAIL,
59 		EXPECT_LINK_FAIL,
60 
61 		EXPECT_LAST
62 	};
63 
64 	struct Value
65 	{
66 		enum StorageType
67 		{
68 			STORAGE_UNIFORM,
69 			STORAGE_INPUT,
70 			STORAGE_OUTPUT,
71 
72 			STORAGE_LAST
73 		};
74 
75 		/* \todo [2010-03-31 petri] Replace with another vector to allow a) arrays, b) compact representation */
76 		union Element {
77 			float   float32;
78 			deInt32 int32;
79 			deInt32 bool32;
80 		};
81 
82 		StorageType			 storageType;
83 		std::string			 valueName;
84 		glu::DataType		 dataType;
85 		int					 arrayLength; // Number of elements in array (currently always 1).
86 		std::vector<Element> elements;	// Scalar values (length dataType.scalarSize * arrayLength).
87 	};
88 
89 	struct ValueBlock
90 	{
91 		int				   arrayLength; // Combined array length of each value (lengths must be same, or one).
92 		std::vector<Value> values;
ValueBlockdeqp::sl::ShaderCase::ValueBlock93 		ValueBlock(void)
94 		{
95 			arrayLength = 0;
96 		}
97 	};
98 
99 	// Methods.
100 	ShaderCase(tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* caseName, const char* description,
101 			   ExpectResult expectResult, const std::vector<ValueBlock>& valueBlocks, glu::GLSLVersion targetVersion,
102 			   const char* vertexSource, const char* fragmentSource);
103 
104 	virtual ~ShaderCase(void);
105 
getCaseType(void) const106 	CaseType getCaseType(void) const
107 	{
108 		return m_caseType;
109 	}
getValueBlocks(void) const110 	const std::vector<ValueBlock>& getValueBlocks(void) const
111 	{
112 		return m_valueBlocks;
113 	}
getVertexSource(void) const114 	const char* getVertexSource(void) const
115 	{
116 		return m_vertexSource.c_str();
117 	}
getFragmentSource(void) const118 	const char* getFragmentSource(void) const
119 	{
120 		return m_fragmentSource.c_str();
121 	}
122 
123 	bool		  execute(void);
124 	IterateResult iterate(void);
125 
126 private:
127 	ShaderCase(const ShaderCase&);			  // not allowed!
128 	ShaderCase& operator=(const ShaderCase&); // not allowed!
129 
130 	std::string genVertexShader(const ValueBlock& valueBlock);
131 	std::string genFragmentShader(const ValueBlock& valueBlock);
132 	std::string specializeVertexShader(const char* src, const ValueBlock& valueBlock);
133 	std::string specializeFragmentShader(const char* src, const ValueBlock& valueBlock);
134 
135 	void specializeShaders(const char* vertexSource, const char* fragmentSource, std::string& outVertexSource,
136 						   std::string& outFragmentSource, const ValueBlock& valueBlock);
137 
138 	void dumpValues(const ValueBlock& valueBlock, int arrayNdx);
139 
140 	bool checkPixels(tcu::Surface& surface, int minX, int maxX, int minY, int maxY);
141 
142 	// Member variables.
143 	glu::RenderContext&		m_renderCtx;
144 	CaseType				m_caseType;
145 	ExpectResult			m_expectResult;
146 	std::vector<ValueBlock> m_valueBlocks;
147 	glu::GLSLVersion		m_targetVersion;
148 	std::string				m_vertexSource;
149 	std::string				m_fragmentSource;
150 };
151 
152 } // sl
153 } // deqp
154 
155 #endif // _GLCSHADERLIBRARYCASE_HPP
156