1e5c31af7Sopenharmony_ci#ifndef _GL3CCULLDISTANCETESTS_HPP
2e5c31af7Sopenharmony_ci#define _GL3CCULLDISTANCETESTS_HPP
3e5c31af7Sopenharmony_ci/*-------------------------------------------------------------------------
4e5c31af7Sopenharmony_ci * OpenGL Conformance Test Suite
5e5c31af7Sopenharmony_ci * -----------------------------
6e5c31af7Sopenharmony_ci *
7e5c31af7Sopenharmony_ci * Copyright (c) 2015-2016 The Khronos Group Inc.
8e5c31af7Sopenharmony_ci *
9e5c31af7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
10e5c31af7Sopenharmony_ci * you may not use this file except in compliance with the License.
11e5c31af7Sopenharmony_ci * You may obtain a copy of the License at
12e5c31af7Sopenharmony_ci *
13e5c31af7Sopenharmony_ci *      http://www.apache.org/licenses/LICENSE-2.0
14e5c31af7Sopenharmony_ci *
15e5c31af7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
16e5c31af7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
17e5c31af7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18e5c31af7Sopenharmony_ci * See the License for the specific language governing permissions and
19e5c31af7Sopenharmony_ci * limitations under the License.
20e5c31af7Sopenharmony_ci *
21e5c31af7Sopenharmony_ci */ /*!
22e5c31af7Sopenharmony_ci * \file
23e5c31af7Sopenharmony_ci * \brief
24e5c31af7Sopenharmony_ci */ /*-------------------------------------------------------------------*/
25e5c31af7Sopenharmony_ci
26e5c31af7Sopenharmony_ci/**
27e5c31af7Sopenharmony_ci */ /*!
28e5c31af7Sopenharmony_ci * \file  gl3cCullDistanceTests.hpp
29e5c31af7Sopenharmony_ci * \brief  Cull Distance Test Suite Interface
30e5c31af7Sopenharmony_ci */ /*-------------------------------------------------------------------*/
31e5c31af7Sopenharmony_ci
32e5c31af7Sopenharmony_ci#include "glcTestCase.hpp"
33e5c31af7Sopenharmony_ci#include "glwDefs.hpp"
34e5c31af7Sopenharmony_ci#include "tcuDefs.hpp"
35e5c31af7Sopenharmony_ci
36e5c31af7Sopenharmony_cinamespace glcts
37e5c31af7Sopenharmony_ci{
38e5c31af7Sopenharmony_cinamespace CullDistance
39e5c31af7Sopenharmony_ci{
40e5c31af7Sopenharmony_ci/** @brief Cull Distance Test utility class
41e5c31af7Sopenharmony_ci *
42e5c31af7Sopenharmony_ci *  This class contains utility static function members
43e5c31af7Sopenharmony_ci *  helpful to OpenGL shader template based construction
44e5c31af7Sopenharmony_ci *  and building process.
45e5c31af7Sopenharmony_ci */
46e5c31af7Sopenharmony_ciclass Utilities
47e5c31af7Sopenharmony_ci{
48e5c31af7Sopenharmony_cipublic:
49e5c31af7Sopenharmony_ci	/* Public static methods */
50e5c31af7Sopenharmony_ci	static void buildProgram(const glw::Functions& gl, tcu::TestContext& testCtx, const glw::GLchar* cs_body,
51e5c31af7Sopenharmony_ci							 const glw::GLchar* fs_body, const glw::GLchar* gs_body, const glw::GLchar* tc_body,
52e5c31af7Sopenharmony_ci							 const glw::GLchar* te_body, const glw::GLchar* vs_body, const glw::GLuint& n_tf_varyings,
53e5c31af7Sopenharmony_ci							 const glw::GLchar** tf_varyings, glw::GLuint* out_program);
54e5c31af7Sopenharmony_ci
55e5c31af7Sopenharmony_ci	static void replaceAll(std::string& str, const std::string& from, const std::string& to);
56e5c31af7Sopenharmony_ci
57e5c31af7Sopenharmony_ci	static std::string intToString(glw::GLint integer);
58e5c31af7Sopenharmony_ci};
59e5c31af7Sopenharmony_ci
60e5c31af7Sopenharmony_ci/** @brief Cull Distance API Coverage Test class
61e5c31af7Sopenharmony_ci *
62e5c31af7Sopenharmony_ci *  This class contains basic API coverage test,
63e5c31af7Sopenharmony_ci *  which check if the implementation provides
64e5c31af7Sopenharmony_ci *  basic cull distance structures:
65e5c31af7Sopenharmony_ci *
66e5c31af7Sopenharmony_ci *   * Checks that calling GetIntegerv with MAX_CULL_DISTANCES doesn't generate
67e5c31af7Sopenharmony_ci *    any errors and returns a value at least 8.
68e5c31af7Sopenharmony_ci *
69e5c31af7Sopenharmony_ci *   * Checks that calling GetIntegerv with MAX_COMBINED_CLIP_AND_CULL_DISTANCES
70e5c31af7Sopenharmony_ci *     doesn't generate any errors and returns a value at least 8.
71e5c31af7Sopenharmony_ci *
72e5c31af7Sopenharmony_ci *   * Checks that using the GLSL built-in constant gl_MaxCullDistance in any
73e5c31af7Sopenharmony_ci *     shader stage (including compute shader) compiles and links successfully
74e5c31af7Sopenharmony_ci *     and that the value of the built-in constant is at least 8.
75e5c31af7Sopenharmony_ci *
76e5c31af7Sopenharmony_ci *   * Checks that using the GLSL built-in constant gl_MaxCombinedClipAndCull-
77e5c31af7Sopenharmony_ci *     Distances in any shader stage (including compute shader) compiles and
78e5c31af7Sopenharmony_ci *     links successfully and that the value of the built-in constant is at
79e5c31af7Sopenharmony_ci *     least 8.
80e5c31af7Sopenharmony_ci */
81e5c31af7Sopenharmony_ciclass APICoverageTest : public deqp::TestCase
82e5c31af7Sopenharmony_ci{
83e5c31af7Sopenharmony_cipublic:
84e5c31af7Sopenharmony_ci	/* Public methods */
85e5c31af7Sopenharmony_ci	APICoverageTest(deqp::Context& context);
86e5c31af7Sopenharmony_ci
87e5c31af7Sopenharmony_ciprotected:
88e5c31af7Sopenharmony_ci	/* Protected methods */
89e5c31af7Sopenharmony_ci	void						 deinit();
90e5c31af7Sopenharmony_ci	tcu::TestNode::IterateResult iterate();
91e5c31af7Sopenharmony_ci
92e5c31af7Sopenharmony_ciprivate:
93e5c31af7Sopenharmony_ci	/* Private fields */
94e5c31af7Sopenharmony_ci	glw::GLuint m_bo_id;
95e5c31af7Sopenharmony_ci	glw::GLuint m_cs_id;
96e5c31af7Sopenharmony_ci	glw::GLuint m_cs_to_id;
97e5c31af7Sopenharmony_ci	glw::GLuint m_fbo_draw_id;
98e5c31af7Sopenharmony_ci	glw::GLuint m_fbo_draw_to_id;
99e5c31af7Sopenharmony_ci	glw::GLuint m_fbo_read_id;
100e5c31af7Sopenharmony_ci	glw::GLuint m_fs_id;
101e5c31af7Sopenharmony_ci	glw::GLuint m_gs_id;
102e5c31af7Sopenharmony_ci	glw::GLuint m_po_id;
103e5c31af7Sopenharmony_ci	glw::GLuint m_tc_id;
104e5c31af7Sopenharmony_ci	glw::GLuint m_te_id;
105e5c31af7Sopenharmony_ci	glw::GLuint m_vao_id;
106e5c31af7Sopenharmony_ci	glw::GLuint m_vs_id;
107e5c31af7Sopenharmony_ci};
108e5c31af7Sopenharmony_ci
109e5c31af7Sopenharmony_ci/** @brief Cull Distance Functional Test class
110e5c31af7Sopenharmony_ci *
111e5c31af7Sopenharmony_ci *  This class contains functional test cases,
112e5c31af7Sopenharmony_ci *  which check if the implementation works
113e5c31af7Sopenharmony_ci *  in specified way. For each functional test:
114e5c31af7Sopenharmony_ci *    * Use the basic outline to test the basic functionality of cull distances.
115e5c31af7Sopenharmony_ci *    * Use the basic outline but don't redeclare gl_ClipDistance with a size.
116e5c31af7Sopenharmony_ci *    * Use the basic outline but don't redeclare gl_CullDistance with a size.
117e5c31af7Sopenharmony_ci *    * Use the basic outline but don't redeclare either gl_ClipDistance or
118e5c31af7Sopenharmony_ci *      gl_CullDistance with a size.
119e5c31af7Sopenharmony_ci *    * Use the basic outline but use dynamic indexing when writing the elements
120e5c31af7Sopenharmony_ci *      of the gl_ClipDistance and gl_CullDistance arrays.
121e5c31af7Sopenharmony_ci *    * Use the basic outline but add a geometry shader to the program that
122e5c31af7Sopenharmony_ci *      simply passes through all written clip and cull distances.
123e5c31af7Sopenharmony_ci *    * Use the basic outline but add a tessellation control and tessellation
124e5c31af7Sopenharmony_ci *      evaluation shader to the program which simply pass through all written
125e5c31af7Sopenharmony_ci *      clip and cull distances.
126e5c31af7Sopenharmony_ci *    * Test that using #extension with GL_ARB_cull_distance allows using the
127e5c31af7Sopenharmony_ci *      feature even with an earlier version of GLSL. Also test that the
128e5c31af7Sopenharmony_ci *      extension name is available as preprocessor #define.
129e5c31af7Sopenharmony_ci *  a basic outline is used to check the implementation:
130e5c31af7Sopenharmony_ci *    * Enable disjunct cull distances using Enable with CLIP_DISTANCE<i>.
131e5c31af7Sopenharmony_ci *    * Use a program that has only a vertex shader and a fragment shader.
132e5c31af7Sopenharmony_ci *      The vertex shader should redeclare gl_ClipDistance with a size that
133e5c31af7Sopenharmony_ci *      fits all enabled cull distances. Also redeclare gl_CullDistance with a
134e5c31af7Sopenharmony_ci *      size. The sum of the two sizes should not be more than MAX_COMBINED_-
135e5c31af7Sopenharmony_ci *      CLIP_AND_CULL_DISTANCES. The fragment shader should output the cull
136e5c31af7Sopenharmony_ci *      distances written by the vertex shader by reading them from the built-in
137e5c31af7Sopenharmony_ci *      array gl_CullDistance.
138e5c31af7Sopenharmony_ci *    * Write different positive and negative values for all the enabled clip
139e5c31af7Sopenharmony_ci *      distances to gl_ClipDistance in the vertex shader. Also write different
140e5c31af7Sopenharmony_ci *      positive and negative values for all the elements of gl_CullDistance.
141e5c31af7Sopenharmony_ci *      Use constant indices when writing to gl_ClipDistance and gl_CullDistance.
142e5c31af7Sopenharmony_ci *    * Render point, line and triangle primitives. Expect primitives that for
143e5c31af7Sopenharmony_ci *      a given index <i> all of their vertices have a negative value set for
144e5c31af7Sopenharmony_ci *      gl_CullDistance[i] to be discarded. Otherwise, they should be clipped
145e5c31af7Sopenharmony_ci *      according to the enabled clip distances as without this extension.
146e5c31af7Sopenharmony_ci *      Check the output image to make sure that the color output for each
147e5c31af7Sopenharmony_ci *      fragment matches the expected interpolated values of the written cull
148e5c31af7Sopenharmony_ci *      distances.
149e5c31af7Sopenharmony_ci * */
150e5c31af7Sopenharmony_ciclass FunctionalTest : public deqp::TestCase
151e5c31af7Sopenharmony_ci{
152e5c31af7Sopenharmony_cipublic:
153e5c31af7Sopenharmony_ci	/* Public methods */
154e5c31af7Sopenharmony_ci	FunctionalTest(deqp::Context& context);
155e5c31af7Sopenharmony_ci
156e5c31af7Sopenharmony_ciprotected:
157e5c31af7Sopenharmony_ci	/* Protected methods */
158e5c31af7Sopenharmony_ci	void						 deinit();
159e5c31af7Sopenharmony_ci	tcu::TestNode::IterateResult iterate();
160e5c31af7Sopenharmony_ci
161e5c31af7Sopenharmony_ciprivate:
162e5c31af7Sopenharmony_ci	/* Private type definitions */
163e5c31af7Sopenharmony_ci	enum _primitive_mode
164e5c31af7Sopenharmony_ci	{
165e5c31af7Sopenharmony_ci		PRIMITIVE_MODE_LINES,
166e5c31af7Sopenharmony_ci		PRIMITIVE_MODE_POINTS,
167e5c31af7Sopenharmony_ci		PRIMITIVE_MODE_TRIANGLES,
168e5c31af7Sopenharmony_ci
169e5c31af7Sopenharmony_ci		PRIMITIVE_MODE_COUNT
170e5c31af7Sopenharmony_ci	};
171e5c31af7Sopenharmony_ci
172e5c31af7Sopenharmony_ci	/* Private methods */
173e5c31af7Sopenharmony_ci	void buildPO(glw::GLuint clipdistances_array_size, glw::GLuint culldistances_array_size, bool dynamic_index_writes,
174e5c31af7Sopenharmony_ci				 _primitive_mode primitive_mode, bool redeclare_clipdistances, bool redeclare_culldistances,
175e5c31af7Sopenharmony_ci				 bool use_core_functionality, bool use_gs, bool use_ts, bool fetch_culldistance_from_fs);
176e5c31af7Sopenharmony_ci
177e5c31af7Sopenharmony_ci	void configureVAO(glw::GLuint clipdistances_array_size, glw::GLuint culldistances_array_size,
178e5c31af7Sopenharmony_ci					  _primitive_mode primitive_mode);
179e5c31af7Sopenharmony_ci
180e5c31af7Sopenharmony_ci	void deinitPO();
181e5c31af7Sopenharmony_ci
182e5c31af7Sopenharmony_ci	void executeRenderTest(glw::GLuint clipdistances_array_size, glw::GLuint culldistances_array_size,
183e5c31af7Sopenharmony_ci						   _primitive_mode primitive_mode, bool use_tesselation, bool fetch_culldistance_from_fs);
184e5c31af7Sopenharmony_ci
185e5c31af7Sopenharmony_ci	glw::GLint readRedPixelValue(glw::GLint x, glw::GLint y);
186e5c31af7Sopenharmony_ci
187e5c31af7Sopenharmony_ci	void readTexturePixels();
188e5c31af7Sopenharmony_ci
189e5c31af7Sopenharmony_ci	/* Private fields */
190e5c31af7Sopenharmony_ci	std::vector<glw::GLfloat> m_bo_data;
191e5c31af7Sopenharmony_ci	glw::GLuint				  m_bo_id;
192e5c31af7Sopenharmony_ci	glw::GLuint				  m_fbo_id;
193e5c31af7Sopenharmony_ci	glw::GLuint				  m_po_id;
194e5c31af7Sopenharmony_ci	glw::GLsizei			  m_render_primitives;
195e5c31af7Sopenharmony_ci	glw::GLsizei			  m_render_vertices;
196e5c31af7Sopenharmony_ci	glw::GLint				  m_sub_grid_cell_size;
197e5c31af7Sopenharmony_ci	glw::GLuint				  m_to_id;
198e5c31af7Sopenharmony_ci	glw::GLuint				  m_vao_id;
199e5c31af7Sopenharmony_ci
200e5c31af7Sopenharmony_ci	const glw::GLuint		   m_to_height;
201e5c31af7Sopenharmony_ci	const glw::GLuint		   m_to_width;
202e5c31af7Sopenharmony_ci	static const glw::GLuint   m_to_pixel_data_cache_color_components = 4;
203e5c31af7Sopenharmony_ci	std::vector<glw::GLushort> m_to_pixel_data_cache;
204e5c31af7Sopenharmony_ci};
205e5c31af7Sopenharmony_ci
206e5c31af7Sopenharmony_ci/** @brief Cull Distance Negative Test class
207e5c31af7Sopenharmony_ci *
208e5c31af7Sopenharmony_ci *  This class contains negative test cases,
209e5c31af7Sopenharmony_ci *  which check if the implementation returns
210e5c31af7Sopenharmony_ci *  properly in case of unsupport state
211e5c31af7Sopenharmony_ci *  configuration. Following cases are checked:
212e5c31af7Sopenharmony_ci *    * Use the basic outline but redeclare gl_ClipDistance and gl_CullDistance
213e5c31af7Sopenharmony_ci *      with sizes whose sum is more than MAX_COMBINED_CLIP_AND_CULL_DISTANCES.
214e5c31af7Sopenharmony_ci *      Expect a compile-time or link-time error.
215e5c31af7Sopenharmony_ci *    * Use the basic outline but don't redeclare gl_ClipDistance and/or
216e5c31af7Sopenharmony_ci *      gl_CullDistance with a size and statically write values to such elements
217e5c31af7Sopenharmony_ci *      of gl_ClipDistance and gl_CullDistance that the sum of these element
218e5c31af7Sopenharmony_ci *      indices is greater than MAX_COMBINED_CLIP_AND_CULL_DISTANCES minus two
219e5c31af7Sopenharmony_ci *      (the "minus two" part is needed because the indices are zero-based).
220e5c31af7Sopenharmony_ci *      Expect a compile-time or link-time error.
221e5c31af7Sopenharmony_ci *    * Use the basic outline but don't redeclare gl_ClipDistance and/or
222e5c31af7Sopenharmony_ci *      gl_CullDistance with a size and use dynamic indexing when writing their
223e5c31af7Sopenharmony_ci *      elements. Expect a compile-time or link-time error.
224e5c31af7Sopenharmony_ci */
225e5c31af7Sopenharmony_ciclass NegativeTest : public deqp::TestCase
226e5c31af7Sopenharmony_ci{
227e5c31af7Sopenharmony_cipublic:
228e5c31af7Sopenharmony_ci	/* Public methods */
229e5c31af7Sopenharmony_ci	NegativeTest(deqp::Context& context);
230e5c31af7Sopenharmony_ci
231e5c31af7Sopenharmony_ciprotected:
232e5c31af7Sopenharmony_ci	/* Protected methods */
233e5c31af7Sopenharmony_ci	void						 deinit();
234e5c31af7Sopenharmony_ci	tcu::TestNode::IterateResult iterate();
235e5c31af7Sopenharmony_ci
236e5c31af7Sopenharmony_ciprivate:
237e5c31af7Sopenharmony_ci	/* Private methods */
238e5c31af7Sopenharmony_ci	std::string getTestDescription(glw::GLint n_test_iteration, bool should_redeclare_output_variables,
239e5c31af7Sopenharmony_ci								   bool use_dynamic_index_based_writes);
240e5c31af7Sopenharmony_ci
241e5c31af7Sopenharmony_ci	/* Private fields */
242e5c31af7Sopenharmony_ci	glw::GLuint  m_fs_id;
243e5c31af7Sopenharmony_ci	glw::GLuint  m_po_id;
244e5c31af7Sopenharmony_ci	glw::GLchar* m_temp_buffer;
245e5c31af7Sopenharmony_ci	glw::GLuint  m_vs_id;
246e5c31af7Sopenharmony_ci};
247e5c31af7Sopenharmony_ci
248e5c31af7Sopenharmony_ci/** @brief Grouping class for Cull Distance Tests */
249e5c31af7Sopenharmony_ciclass Tests : public deqp::TestCaseGroup
250e5c31af7Sopenharmony_ci{
251e5c31af7Sopenharmony_cipublic:
252e5c31af7Sopenharmony_ci	/* Public methods */
253e5c31af7Sopenharmony_ci	Tests(deqp::Context& context);
254e5c31af7Sopenharmony_ci
255e5c31af7Sopenharmony_ci	void init(void);
256e5c31af7Sopenharmony_ci
257e5c31af7Sopenharmony_ciprivate:
258e5c31af7Sopenharmony_ci	Tests(const CullDistance::Tests& other);
259e5c31af7Sopenharmony_ci	Tests& operator=(const CullDistance::Tests& other);
260e5c31af7Sopenharmony_ci};
261e5c31af7Sopenharmony_ci}
262e5c31af7Sopenharmony_ci/* CullDistance namespace */
263e5c31af7Sopenharmony_ci} /* glcts namespace */
264e5c31af7Sopenharmony_ci
265e5c31af7Sopenharmony_ci#endif // _GL3CCULLDISTANCETESTS_HPP
266