1 #ifndef _ESEXTCTEXTUREBUFFERACTIVEUNIFORMVALIDATION_HPP
2 #define _ESEXTCTEXTUREBUFFERACTIVEUNIFORMVALIDATION_HPP
3 /*-------------------------------------------------------------------------
4  * OpenGL Conformance Test Suite
5  * -----------------------------
6  *
7  * Copyright (c) 2014-2016 The Khronos Group Inc.
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
24  */ /*-------------------------------------------------------------------*/
25 
26 /*!
27  * \file  esextcTextureBufferActiveUniformValidation.hpp
28  * \brief Texture Buffer -  Active Uniform Value Validation (Test 8)
29  */ /*-------------------------------------------------------------------*/
30 
31 #include "../esextcTestCaseBase.hpp"
32 #include <map>
33 
34 namespace glcts
35 {
36 
37 /** Implementation of (Test 8) from CTS_EXT_texture_buffer. Description follows
38  *
39  *   Check whether glGetActiveUniform, glGetActiveUniformsiv and
40  *   glGetProgramResourceiv functions return correct information about active
41  *   uniform variables of the type:
42  *
43  *   SAMPLER_BUFFER_EXT
44  *   INT_SAMPLER_BUFFER_EXT
45  *   UNSIGNED_INT_SAMPLER_BUFFER_EXT
46  *   IMAGE_BUFFER_EXT
47  *   INT_IMAGE_BUFFER_EXT
48  *   UNSIGNED_INT_IMAGE_BUFFER_EXT
49  *
50  *   Category: API.
51  *
52  *   Write a fragment shader that defines the following uniform variables:
53  *
54  *   uniform highp samplerBuffer   sampler_buffer;
55  *   uniform highp isamplerBuffer  isampler_buffer;
56  *   uniform highp usamplerBuffer  usampler_buffer;
57  *
58  *   Make sure each of the uniform variables will be considered active.
59  *   A uniform variable is considered active if it is determined during the link
60  *   operation that it may be accessed during program execution. The easiest way
61  *   to make sure the above variables are active is to call texelFetch on each
62  *   texture sampler and imageLoad on each image sampler and use the returned
63  *   values to determine the output color.
64  *
65  *   Pair the fragment shader with a boilerplate vertex shader.
66  *
67  *   Compile vertex and fragment shader, attach them to a program object and link
68  *   the program object.
69  *
70  *   Get the number of active uniforms in the program object by calling
71  *   glGetProgramiv with the value GL_ACTIVE_UNIFORMS and store the result in
72  *   n_active_uniforms variable.
73  *
74  *   For index values ranging from zero to n_active_uniforms - 1 get the information
75  *   about the uniform variable by calling glGetActiveUniform.
76  *
77  *   This phase of the test passes if among the returned information
78  *   about active uniforms for the specified program object we can identify:
79  *
80  *   Name:               Type:
81  *
82  *   "sampler_buffer"    SAMPLER_BUFFER_EXT
83  *   "isampler_buffer"   INT_SAMPLER_BUFFER_EXT
84  *   "usampler_buffer"   UNSIGNED_INT_SAMPLER_BUFFER_EXT
85  *
86  *   Store which index corresponds to which variable type.
87  *
88  *   Create an array holding uniform variables' indices ranging from
89  *   zero to n_active_uniforms - 1.
90  *
91  *   Call
92  *
93  *   glGetActiveUniformsiv( po_id, n_active_uniforms, indices_array,
94  *       GL_UNIFORM_TYPE, types_array );
95  *
96  *   This phase of the test passes if the resulting types array holds for each
97  *   index value in indices_array the same uniform type as returned previously by
98  *   glGetActiveUniform called for this index.
99  *
100  *   For index values ranging from zero to n_active_uniforms - 1
101  *   get the type information about the uniform variable by calling
102  *   glGetProgramResourceiv with GL_UNIFORM program interface and GL_TYPE property.
103  *
104  *   This phase of the test passes if for each index value the returned type is
105  *   equal to the one previously returned by glGetActiveUniform.
106  *
107  *   Repeat the test for a compute shader that defines the following uniform
108  *   variables:
109  *
110  *   uniform highp   imageBuffer     image_buffer;
111  *   uniform highp   iimageBuffer    iimage_buffer;
112  *   uniform highp   uimageBuffer    uimage_buffer;
113  *
114  *   The corresponding types for the above uniform variables are:
115  *
116  *   IMAGE_BUFFER_EXT
117  *   INT_IMAGE_BUFFER_EXT
118  *   UNSIGNED_INT_IMAGE_BUFFER_EXT
119  *
120  */
121 
122 /* Helper Sctructure storing texture confituration parameters */
123 class TextureParameters
124 {
125 public:
126 	TextureParameters();
127 	TextureParameters(glw::GLuint textureBufferSize, glw::GLenum textureFormat, glw::GLenum textureUniformType,
128 					  const char* uniformName);
129 
get_texture_buffer_size() const130 	glw::GLuint get_texture_buffer_size() const
131 	{
132 		return m_texture_buffer_size;
133 	}
134 
get_texture_format() const135 	glw::GLenum get_texture_format() const
136 	{
137 		return m_texture_format;
138 	}
139 
get_texture_uniform_type() const140 	glw::GLenum get_texture_uniform_type() const
141 	{
142 		return m_texture_uniform_type;
143 	}
144 
get_uniform_name() const145 	std::string get_uniform_name() const
146 	{
147 		return m_uniform_name;
148 	}
149 
150 private:
151 	glw::GLenum m_texture_buffer_size;
152 	glw::GLenum m_texture_format;
153 	glw::GLenum m_texture_uniform_type;
154 	std::string m_uniform_name;
155 };
156 
157 /* Base Class */
158 class TextureBufferActiveUniformValidation : public TestCaseBase
159 {
160 public:
161 	/* Public methods */
162 	TextureBufferActiveUniformValidation(Context& context, const ExtParameters& extParams, const char* name,
163 										 const char* description);
164 
~TextureBufferActiveUniformValidation()165 	virtual ~TextureBufferActiveUniformValidation()
166 	{
167 	}
168 
169 	virtual void		  deinit(void);
170 	virtual IterateResult iterate(void);
171 
172 protected:
173 	/* Protected methods */
174 	void addTextureParam(glw::GLenum uniformType, glw::GLenum format, glw::GLuint size, const char* name,
175 						 std::vector<TextureParameters>* params);
176 
177 	/* Protected variables */
178 	glw::GLuint m_po_id;
179 
180 	static const glw::GLuint m_param_value_size;
181 
182 private:
183 	/* Private methods */
184 	virtual void configureParams(std::vector<TextureParameters>* params) = 0;
185 	virtual void configureProgram(std::vector<TextureParameters>* params, glw::GLuint* texIds) = 0;
186 	virtual void createProgram(void) = 0;
187 
188 	virtual void initTest(void);
189 	const char* getUniformTypeName(glw::GLenum uniformType);
190 	const TextureParameters* getParamsForType(glw::GLenum uniformType) const;
191 
192 	/* Variables for general usage */
193 	glw::GLuint*				   m_tbo_ids;
194 	glw::GLuint*				   m_tbo_tex_ids;
195 	std::vector<TextureParameters> m_texture_params;
196 };
197 
198 /* Vertex/Fragment Shader (Case 1)*/
199 class TextureBufferActiveUniformValidationVSFS : public TextureBufferActiveUniformValidation
200 {
201 public:
202 	/* Public methods */
203 	TextureBufferActiveUniformValidationVSFS(Context& context, const ExtParameters& extParams, const char* name,
204 											 const char* description);
205 
~TextureBufferActiveUniformValidationVSFS()206 	virtual ~TextureBufferActiveUniformValidationVSFS()
207 	{
208 	}
209 
210 	virtual void deinit(void);
211 
212 private:
213 	/* Private methods */
214 	virtual void configureParams(std::vector<TextureParameters>* params);
215 	virtual void configureProgram(std::vector<TextureParameters>* params, glw::GLuint* texIds);
216 	virtual void createProgram(void);
217 
218 	const char* getFragmentShaderCode(void) const;
219 	const char* getVertexShaderCode(void) const;
220 
221 	/* Variables for general usage */
222 	glw::GLuint m_fs_id;
223 	glw::GLuint m_vs_id;
224 };
225 
226 /* Compute Shader (Case 2)*/
227 class TextureBufferActiveUniformValidationCS : public TextureBufferActiveUniformValidation
228 {
229 public:
230 	/* Public methods */
231 	TextureBufferActiveUniformValidationCS(Context& context, const ExtParameters& extParams, const char* name,
232 										   const char* description);
233 
~TextureBufferActiveUniformValidationCS()234 	virtual ~TextureBufferActiveUniformValidationCS()
235 	{
236 	}
237 
238 	virtual void deinit(void);
239 
240 private:
241 	/* Private methods */
242 	virtual void configureParams(std::vector<TextureParameters>* params);
243 	virtual void configureProgram(std::vector<TextureParameters>* params, glw::GLuint* texIds);
244 	virtual void createProgram(void);
245 
246 	const char* getComputeShaderCode(void) const;
247 
248 	/* Variables for general usage */
249 	glw::GLuint m_cs_id;
250 };
251 
252 } // namespace glcts
253 
254 #endif // _ESEXTCTEXTUREBUFFERACTIVEUNIFORMVALIDATION_HPP
255