1 #ifndef _GLCSHADERRENDERCASE_HPP
2 #define _GLCSHADERRENDERCASE_HPP
3 /*-------------------------------------------------------------------------
4 * OpenGL Conformance Test Suite
5 * -----------------------------
7 * Copyright (c) 2016 Google Inc.
8 * Copyright (c) 2016 The Khronos Group Inc.
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
14 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 * \brief Shader execute test.
25 */ /*-------------------------------------------------------------------*/
27 #include "glcTestCase.hpp"
28 #include "gluContextInfo.hpp"
29 #include "gluRenderContext.hpp"
30 #include "gluShaderProgram.hpp"
31 #include "tcuDefs.hpp"
32 #include "tcuMatrix.hpp"
33 #include "tcuSurface.hpp"
34 #include "tcuTexture.hpp"
35 #include "tcuVector.hpp"
57 LineStream(int indent = 0)
65 const char* str(void) const
67 m_string = m_stream.str();
68 return m_string.c_str();
70 LineStream& operator<<(const char* line)
72 for (int i = 0; i < m_indent; i++)
76 m_stream << line << "\n";
82 std::ostringstream m_stream;
83 mutable std::string m_string;
104 TextureBinding(const glu::Texture2D* tex2D, const tcu::Sampler& sampler);
105 TextureBinding(const glu::TextureCube* texCube, const tcu::Sampler& sampler);
106 TextureBinding(const glu::Texture2DArray* tex2DArray, const tcu::Sampler& sampler);
107 TextureBinding(const glu::Texture3D* tex3D, const tcu::Sampler& sampler);
108 TextureBinding(void);
110 void setSampler(const tcu::Sampler& sampler);
111 void setTexture(const glu::Texture2D* tex2D);
112 void setTexture(const glu::TextureCube* texCube);
113 void setTexture(const glu::Texture2DArray* tex2DArray);
114 void setTexture(const glu::Texture3D* tex3D);
116 Type getType(void) const
120 const tcu::Sampler& getSampler(void) const
124 const glu::Texture2D* get2D(void) const
126 DE_ASSERT(getType() == TYPE_2D);
127 return m_binding.tex2D;
129 const glu::TextureCube* getCube(void) const
131 DE_ASSERT(getType() == TYPE_CUBE_MAP);
132 return m_binding.texCube;
134 const glu::Texture2DArray* get2DArray(void) const
136 DE_ASSERT(getType() == TYPE_2D_ARRAY);
137 return m_binding.tex2DArray;
139 const glu::Texture3D* get3D(void) const
141 DE_ASSERT(getType() == TYPE_3D);
142 return m_binding.tex3D;
147 tcu::Sampler m_sampler;
149 const glu::Texture2D* tex2D;
150 const glu::TextureCube* texCube;
151 const glu::Texture2DArray* tex2DArray;
152 const glu::Texture3D* tex3D;
156 // ShaderEvalContext.
158 class ShaderEvalContext
164 MAX_USER_ATTRIBS = 4,
170 tcu::Sampler sampler;
171 const tcu::Texture2D* tex2D;
172 const tcu::TextureCube* texCube;
173 const tcu::Texture2DArray* tex2DArray;
174 const tcu::Texture3D* tex3D;
176 inline ShaderSampler(void) : tex2D(DE_NULL), texCube(DE_NULL), tex2DArray(DE_NULL), tex3D(DE_NULL)
181 ShaderEvalContext(const QuadGrid& quadGrid);
182 ~ShaderEvalContext(void);
184 void reset(float sx, float sy);
188 tcu::Vec4 unitCoords;
189 tcu::Vec4 constCoords;
191 tcu::Vec4 in[MAX_USER_ATTRIBS];
192 ShaderSampler textures[MAX_TEXTURES];
199 inline void discard(void)
203 tcu::Vec4 texture2D(int unitNdx, const tcu::Vec2& coords);
206 const QuadGrid& quadGrid;
211 typedef void (*ShaderEvalFunc)(ShaderEvalContext& c);
213 inline void evalCoordsPassthroughX(ShaderEvalContext& c)
215 c.color.x() = c.coords.x();
217 inline void evalCoordsPassthroughXY(ShaderEvalContext& c)
219 c.color.xy() = c.coords.swizzle(0, 1);
221 inline void evalCoordsPassthroughXYZ(ShaderEvalContext& c)
223 c.color.xyz() = c.coords.swizzle(0, 1, 2);
225 inline void evalCoordsPassthrough(ShaderEvalContext& c)
229 inline void evalCoordsSwizzleWZYX(ShaderEvalContext& c)
231 c.color = c.coords.swizzle(3, 2, 1, 0);
235 // Either inherit a class with overridden evaluate() or just pass in an evalFunc.
237 class ShaderEvaluator
240 ShaderEvaluator(void);
241 ShaderEvaluator(ShaderEvalFunc evalFunc);
242 virtual ~ShaderEvaluator(void);
244 virtual void evaluate(ShaderEvalContext& ctx);
247 ShaderEvaluator(const ShaderEvaluator&); // not allowed!
248 ShaderEvaluator& operator=(const ShaderEvaluator&); // not allowed!
250 ShaderEvalFunc m_evalFunc;
255 class ShaderRenderCase : public tcu::TestCase
258 ShaderRenderCase(tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo,
259 const char* name, const char* description, bool isVertexCase, ShaderEvalFunc evalFunc);
260 ShaderRenderCase(tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo,
261 const char* name, const char* description, bool isVertexCase, ShaderEvaluator& evaluator);
262 virtual ~ShaderRenderCase(void);
267 IterateResult iterate(void);
270 virtual void setup(deUint32 programID);
271 virtual void setupUniforms(deUint32 programID, const tcu::Vec4& constCoords);
273 tcu::IVec2 getViewportSize(void) const;
276 ShaderRenderCase(const ShaderRenderCase&); // not allowed!
277 ShaderRenderCase& operator=(const ShaderRenderCase&); // not allowed!
279 void setupDefaultInputs(int programID);
281 void render(tcu::Surface& result, int programID, const QuadGrid& quadGrid);
282 void computeVertexReference(tcu::Surface& result, const QuadGrid& quadGrid);
283 void computeFragmentReference(tcu::Surface& result, const QuadGrid& quadGrid);
284 bool compareImages(const tcu::Surface& resImage, const tcu::Surface& refImage, float errorThreshold);
287 glu::RenderContext& m_renderCtx;
288 const glu::ContextInfo& m_ctxInfo;
291 ShaderEvaluator m_defaultEvaluator;
292 ShaderEvaluator& m_evaluator;
293 std::string m_vertShaderSource;
294 std::string m_fragShaderSource;
295 tcu::Vec4 m_clearColor;
297 std::vector<tcu::Mat4> m_userAttribTransforms;
298 std::vector<TextureBinding> m_textures;
300 glu::ShaderProgram* m_program;
304 // \todo [2012-04-10 pyry] Move these to separate utility?
306 const char* getIntUniformName(int number);
307 const char* getFloatUniformName(int number);
308 const char* getFloatFractionUniformName(int number);
310 void setupDefaultUniforms(const glu::RenderContext& context, deUint32 programID);
314 #endif // _GLCSHADERRENDERCASE_HPP