1 /*-------------------------------------------------------------------------
2 * OpenGL Conformance Test Suite
3 * -----------------------------
4 *
5 * Copyright (c) 2016 The Khronos Group Inc.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 */ /*!
20 * \file gl4cShaderDrawParametersTests.cpp
21 * \brief Conformance tests for the GL_ARB_shader_draw_parameters functionality.
22 */ /*-------------------------------------------------------------------*/
23
24 #include "gl4cShaderDrawParametersTests.hpp"
25 #include "gluContextInfo.hpp"
26 #include "gluDefs.hpp"
27 #include "gluDrawUtil.hpp"
28 #include "gluShaderProgram.hpp"
29 #include "glwEnums.hpp"
30 #include "glwFunctions.hpp"
31 #include "tcuRenderTarget.hpp"
32 #include "tcuStringTemplate.hpp"
33 #include "tcuTestLog.hpp"
34
35 using namespace glw;
36 using namespace glu;
37
38 namespace gl4cts
39 {
40
41 const char* sdp_compute_extensionCheck = "#version 450 core\n"
42 "\n"
43 "#extension GL_ARB_shader_draw_parameters : require\n"
44 "\n"
45 "#ifndef GL_ARB_shader_draw_parameters\n"
46 " #error GL_ARB_shader_draw_parameters not defined\n"
47 "#else\n"
48 " #if (GL_ARB_shader_draw_parameters != 1)\n"
49 " #error GL_ARB_shader_draw_parameters wrong value\n"
50 " #endif\n"
51 "#endif // GL_ARB_shader_draw_parameters\n"
52 "\n"
53 "layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
54 "\n"
55 "void main()\n"
56 "{\n"
57 "}\n";
58
59 static const char* sdp_vertShader = "${VERSION}\n"
60 "\n"
61 "${DRAW_PARAMETERS_EXTENSION}\n"
62 "\n"
63 "in vec3 vertex;\n"
64 "out vec3 color;\n"
65 "\n"
66 "void main()\n"
67 "{\n"
68 " float hOffset = float(${GL_BASE_VERTEX}) / 5.0;\n"
69 " float vOffset = float(${GL_BASE_INSTANCE}) / 5.0;\n"
70 " color = vec3(0.0);\n"
71 " if (${GL_DRAW_ID} % 3 == 0) color.r = 1;\n"
72 " else if (${GL_DRAW_ID} % 3 == 1) color.g = 1;\n"
73 " else if (${GL_DRAW_ID} % 3 == 2) color.b = 1;\n"
74 " gl_Position = vec4(vertex + vec3(hOffset, vOffset, 0), 1);\n"
75 "}\n";
76
77 static const char* sdp_fragShader = "${VERSION}\n"
78 "\n"
79 "${DRAW_PARAMETERS_EXTENSION}\n"
80 "\n"
81 "in vec3 color;\n"
82 "out vec4 fragColor;\n"
83 "\n"
84 "void main()\n"
85 "{\n"
86 " fragColor = vec4(color, 1.0);\n"
87 "}\n";
88
89 /** Constructor.
90 *
91 * @param context Rendering context
92 */
ShaderDrawParametersExtensionTestCase(deqp::Context & context)93 ShaderDrawParametersExtensionTestCase::ShaderDrawParametersExtensionTestCase(deqp::Context& context)
94 : TestCase(context, "ShaderDrawParametersExtension",
95 "Verifies if GL_ARB_shader_draw_parameters extension is available for GLSL")
96 {
97 /* Left blank intentionally */
98 }
99
100 /** Executes test iteration.
101 *
102 * @return Returns STOP when test has finished executing, CONTINUE if more iterations are needed.
103 */
iterate()104 tcu::TestNode::IterateResult ShaderDrawParametersExtensionTestCase::iterate()
105 {
106 if (!m_context.getContextInfo().isExtensionSupported("GL_ARB_shader_draw_parameters"))
107 {
108 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
109 return STOP;
110 }
111
112 const Functions& gl = m_context.getRenderContext().getFunctions();
113
114 std::string shader = sdp_compute_extensionCheck;
115
116 ProgramSources sources;
117 sources << ComputeSource(shader);
118 ShaderProgram program(gl, sources);
119
120 if (!program.isOk())
121 {
122 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
123 m_testCtx.getLog() << tcu::TestLog::Message << "Checking shader preprocessor directives failed. Source:\n"
124 << shader.c_str() << "InfoLog:\n"
125 << program.getShaderInfo(SHADERTYPE_COMPUTE).infoLog << "\n"
126 << tcu::TestLog::EndMessage;
127 return STOP;
128 }
129
130 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
131 return STOP;
132 }
133
134 /** Constructor.
135 *
136 * @param context Rendering context
137 * @param name Test case name
138 * @param description Test case description
139 */
ShaderDrawParametersTestBase(deqp::Context & context,const char * name,const char * description)140 ShaderDrawParametersTestBase::ShaderDrawParametersTestBase(deqp::Context& context, const char* name,
141 const char* description)
142 : TestCase(context, name, description)
143 , m_vao(0)
144 , m_arrayBuffer(0)
145 , m_elementBuffer(0)
146 , m_drawIndirectBuffer(0)
147 , m_parameterBuffer(0)
148 {
149 /* Left blank intentionally */
150 }
151
152 /** Stub init method */
init()153 void ShaderDrawParametersTestBase::init()
154 {
155 glu::ContextType contextType = m_context.getRenderContext().getType();
156 if (!glu::contextSupports(contextType, glu::ApiType::core(4, 6)) &&
157 !m_context.getContextInfo().isExtensionSupported("GL_ARB_shader_draw_parameters"))
158 {
159 TCU_THROW(NotSupportedError, "shader_draw_parameters functionality not supported");
160 }
161
162 initChild();
163
164 const Functions& gl = m_context.getRenderContext().getFunctions();
165
166 const GLfloat vertices[] = {
167 -1.0f, -1.0f, 0.0f, -1.0f, -0.8f, 0.0f, -0.9f, -1.0f, 0.0f,
168 -0.9f, -0.8f, 0.0f, -0.8f, -1.0f, 0.0f, -0.8f, -0.8f, 0.0f,
169 };
170
171 const GLushort elements[] = { 0, 1, 2, 3, 4, 5 };
172
173 // Generate vertex array object
174 gl.genVertexArrays(1, &m_vao);
175 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays");
176
177 gl.bindVertexArray(m_vao);
178 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray");
179
180 // Setup vertex array buffer
181 gl.genBuffers(1, &m_arrayBuffer);
182 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers");
183
184 gl.bindBuffer(GL_ARRAY_BUFFER, m_arrayBuffer);
185 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer");
186
187 gl.bufferData(GL_ARRAY_BUFFER, 24 * sizeof(GLfloat), vertices, GL_STATIC_DRAW);
188 GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData");
189
190 // Setup element array buffer
191 gl.genBuffers(1, &m_elementBuffer);
192 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers");
193
194 gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_elementBuffer);
195 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer");
196
197 gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, 6 * sizeof(GLushort), elements, GL_STATIC_DRAW);
198 GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData");
199 }
200
201 /** Stub deinit method */
deinit()202 void ShaderDrawParametersTestBase::deinit()
203 {
204 const Functions& gl = m_context.getRenderContext().getFunctions();
205
206 if (m_vao)
207 gl.deleteVertexArrays(1, &m_vao);
208 if (m_arrayBuffer)
209 gl.deleteBuffers(1, &m_arrayBuffer);
210 if (m_elementBuffer)
211 gl.deleteBuffers(1, &m_elementBuffer);
212
213 deinitChild();
214 }
215
216 /** Executes test iteration.
217 *
218 * @return Returns STOP when test has finished executing, CONTINUE if more iterations are needed.
219 */
iterate()220 tcu::TestNode::IterateResult ShaderDrawParametersTestBase::iterate()
221 {
222 if (draw() && verify())
223 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
224 else
225 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
226
227 return STOP;
228 }
229
230 /** Draws scene using specific case parameters.
231 *
232 * @return Returns true if no error occurred, false otherwise.
233 */
draw()234 bool ShaderDrawParametersTestBase::draw()
235 {
236 const Functions& gl = m_context.getRenderContext().getFunctions();
237 glu::ContextType contextType = m_context.getRenderContext().getType();
238 std::map<std::string, std::string> specializationMap;
239
240 if (glu::contextSupports(contextType, glu::ApiType::core(4, 6)))
241 {
242 specializationMap["VERSION"] = "#version 460";
243 specializationMap["DRAW_PARAMETERS_EXTENSION"] = "";
244 specializationMap["GL_BASE_VERTEX"] = "gl_BaseVertex";
245 specializationMap["GL_BASE_INSTANCE"] = "gl_BaseInstance";
246 specializationMap["GL_DRAW_ID"] = "gl_DrawID";
247 }
248 else
249 {
250 specializationMap["VERSION"] = "#version 450";
251 specializationMap["DRAW_PARAMETERS_EXTENSION"] = "#extension GL_ARB_shader_draw_parameters : enable";
252 specializationMap["GL_BASE_VERTEX"] = "gl_BaseVertexARB";
253 specializationMap["GL_BASE_INSTANCE"] = "gl_BaseInstanceARB";
254 specializationMap["GL_DRAW_ID"] = "gl_DrawIDARB";
255 }
256
257 std::string vs = tcu::StringTemplate(sdp_vertShader).specialize(specializationMap);
258 std::string fs = tcu::StringTemplate(sdp_fragShader).specialize(specializationMap);
259
260 ProgramSources sources = makeVtxFragSources(vs, fs);
261 ShaderProgram program(gl, sources);
262
263 if (!program.isOk())
264 {
265 m_testCtx.getLog() << tcu::TestLog::Message << "Shader build failed.\n"
266 << "Vertex: " << program.getShaderInfo(SHADERTYPE_VERTEX).infoLog << "\n"
267 << "Fragment: " << program.getShaderInfo(SHADERTYPE_FRAGMENT).infoLog << "\n"
268 << "Program: " << program.getProgramInfo().infoLog << tcu::TestLog::EndMessage;
269 return false;
270 }
271
272 gl.useProgram(program.getProgram());
273 GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram");
274
275 gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
276 gl.clear(GL_COLOR_BUFFER_BIT);
277
278 gl.enable(GL_BLEND);
279 gl.blendFunc(GL_ONE, GL_ONE);
280
281 gl.enableVertexAttribArray(0);
282 GLU_EXPECT_NO_ERROR(gl.getError(), "glEnableVertexAttribArray");
283 gl.vertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
284 GLU_EXPECT_NO_ERROR(gl.getError(), "glVertexAttribPointer");
285
286 drawCommand();
287
288 gl.disableVertexAttribArray(0);
289 GLU_EXPECT_NO_ERROR(gl.getError(), "glDisableVertexAttribArray");
290
291 gl.disable(GL_BLEND);
292
293 return true;
294 }
295
296 /** Verifies if drawing result is as expected.
297 *
298 * @return Returns true if verifying process has been successfully completed, false otherwise.
299 */
verify()300 bool ShaderDrawParametersTestBase::verify()
301 {
302 const Functions& gl = m_context.getRenderContext().getFunctions();
303 const tcu::RenderTarget& rt = m_context.getRenderContext().getRenderTarget();
304
305 const int width = rt.getWidth();
306 const int height = rt.getHeight();
307
308 std::vector<GLubyte> pixels;
309 pixels.resize(width * height * 3);
310
311 gl.pixelStorei(GL_PACK_ALIGNMENT, 1);
312 gl.readPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
313 gl.pixelStorei(GL_PACK_ALIGNMENT, 4);
314
315 std::vector<ResultPoint>::iterator it;
316 for (it = m_resultPoints.begin(); it != m_resultPoints.end(); ++it)
317 {
318 int x = (int)(((it->x + 1.0f) / 2) * width);
319 int y = (int)(((it->y + 1.0f) / 2) * height);
320 int red = (int)(it->red * 255);
321 int green = (int)(it->green * 255);
322 int blue = (int)(it->blue * 255);
323
324 if (pixels[(x + y * width) * 3 + 0] != red || pixels[(x + y * width) * 3 + 1] != green ||
325 pixels[(x + y * width) * 3 + 2] != blue)
326 {
327 m_testCtx.getLog() << tcu::TestLog::Message << "Verification failed (" << x << "/" << y << ")\n"
328 << "Expected point: (" << red << "," << green << "," << blue << ")\n"
329 << "Result point: (" << (int)pixels[(x + y * width) * 3 + 0] << ","
330 << (int)pixels[(x + y * width) * 3 + 1] << "," << (int)pixels[(x + y * width) * 3 + 2]
331 << ")\n"
332 << tcu::TestLog::EndMessage;
333 return false;
334 }
335 }
336
337 return true;
338 }
339
340 /** Child case initialization method.
341 */
initChild()342 void ShaderDrawParametersTestBase::initChild()
343 {
344 /* Do nothing */
345 }
346
347 /** Child case deinitialization method.
348 */
deinitChild()349 void ShaderDrawParametersTestBase::deinitChild()
350 {
351 /* Do nothing */
352 }
353
354 /** Child case drawing command invocation.
355 */
drawCommand()356 void ShaderDrawParametersTestBase::drawCommand()
357 {
358 /* Do nothing */
359 }
360
361 /* ShaderDrawArraysParametersTestCase */
362
initChild()363 void ShaderDrawArraysParametersTestCase::initChild()
364 {
365 // Set expected result vector [x, y, red, green, blue]
366 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 0.0f, 0.0f, 0.0f));
367 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
368 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
369 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 0.0f, 0.0f, 0.0f));
370 }
371
deinitChild()372 void ShaderDrawArraysParametersTestCase::deinitChild()
373 {
374 /* Do nothing */
375 }
376
drawCommand()377 void ShaderDrawArraysParametersTestCase::drawCommand()
378 {
379 const Functions& gl = m_context.getRenderContext().getFunctions();
380
381 gl.drawArrays(GL_TRIANGLE_STRIP, 1, 4);
382 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays");
383 }
384
385 /* ---------------------------------- */
386
387 /* ShaderDrawElementsParametersTestCase */
388
initChild()389 void ShaderDrawElementsParametersTestCase::initChild()
390 {
391 // Set expected result vector [x, y, red, green, blue]
392 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 0.0f, 0.0f, 0.0f));
393 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 0.0f, 0.0f, 0.0f));
394 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
395 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
396 }
397
deinitChild()398 void ShaderDrawElementsParametersTestCase::deinitChild()
399 {
400 /* Do nothing */
401 }
402
drawCommand()403 void ShaderDrawElementsParametersTestCase::drawCommand()
404 {
405 const Functions& gl = m_context.getRenderContext().getFunctions();
406
407 gl.drawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, (GLvoid*)(2 * sizeof(GLushort)));
408 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawElements");
409 }
410
411 /* ---------------------------------- */
412
413 /* ShaderDrawArraysIndirectParametersTestCase */
414
initChild()415 void ShaderDrawArraysIndirectParametersTestCase::initChild()
416 {
417 const Functions& gl = m_context.getRenderContext().getFunctions();
418
419 // Set expected result vector [x, y, red, green, blue]
420 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
421 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
422 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
423 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 0.0f, 0.0f, 0.0f));
424
425 const SDPDrawArraysIndirectCommand indirect[] = {
426 { 5, 1, 0, 0 },
427 };
428
429 // Setup indirect command buffer
430 gl.genBuffers(1, &m_drawIndirectBuffer);
431 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers");
432
433 gl.bindBuffer(GL_DRAW_INDIRECT_BUFFER, m_drawIndirectBuffer);
434 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer");
435
436 gl.bufferData(GL_DRAW_INDIRECT_BUFFER, 1 * sizeof(SDPDrawArraysIndirectCommand), indirect, GL_STATIC_DRAW);
437 GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData");
438 }
439
deinitChild()440 void ShaderDrawArraysIndirectParametersTestCase::deinitChild()
441 {
442 const Functions& gl = m_context.getRenderContext().getFunctions();
443
444 if (m_drawIndirectBuffer)
445 gl.deleteBuffers(1, &m_drawIndirectBuffer);
446 }
447
drawCommand()448 void ShaderDrawArraysIndirectParametersTestCase::drawCommand()
449 {
450 const Functions& gl = m_context.getRenderContext().getFunctions();
451
452 gl.drawArraysIndirect(GL_TRIANGLE_STRIP, (GLvoid*)0);
453 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArraysIndirect");
454 }
455
456 /* ---------------------------------- */
457
458 /* ShaderDrawElementsIndirectParametersTestCase */
459
initChild()460 void ShaderDrawElementsIndirectParametersTestCase::initChild()
461 {
462 const Functions& gl = m_context.getRenderContext().getFunctions();
463
464 // Set expected result vector [x, y, red, green, blue]
465 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 0.0f, 0.0f, 0.0f));
466 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
467 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
468 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
469
470 const SDPDrawElementsIndirectCommand indirect[] = {
471 { 5, 1, 1, 0, 0 },
472 };
473
474 // Setup indirect command buffer
475 gl.genBuffers(1, &m_drawIndirectBuffer);
476 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers");
477
478 gl.bindBuffer(GL_DRAW_INDIRECT_BUFFER, m_drawIndirectBuffer);
479 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer");
480
481 gl.bufferData(GL_DRAW_INDIRECT_BUFFER, 1 * sizeof(SDPDrawElementsIndirectCommand), indirect, GL_STATIC_DRAW);
482 GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData");
483 }
484
deinitChild()485 void ShaderDrawElementsIndirectParametersTestCase::deinitChild()
486 {
487 const Functions& gl = m_context.getRenderContext().getFunctions();
488
489 if (m_drawIndirectBuffer)
490 gl.deleteBuffers(1, &m_drawIndirectBuffer);
491 }
492
drawCommand()493 void ShaderDrawElementsIndirectParametersTestCase::drawCommand()
494 {
495 const Functions& gl = m_context.getRenderContext().getFunctions();
496
497 gl.drawElementsIndirect(GL_TRIANGLE_STRIP, GL_UNSIGNED_SHORT, (GLvoid*)0);
498 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawElementsIndirect");
499 }
500
501 /* ---------------------------------- */
502
503 /* ShaderDrawArraysInstancedParametersTestCase */
504
initChild()505 void ShaderDrawArraysInstancedParametersTestCase::initChild()
506 {
507 // Set expected result vector [x, y, red, green, blue]
508 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 0.0f, 0.0f, 0.0f));
509 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 0.0f, 0.0f, 0.0f));
510 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
511 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
512 }
513
deinitChild()514 void ShaderDrawArraysInstancedParametersTestCase::deinitChild()
515 {
516 /* Do nothing */
517 }
518
drawCommand()519 void ShaderDrawArraysInstancedParametersTestCase::drawCommand()
520 {
521 const Functions& gl = m_context.getRenderContext().getFunctions();
522
523 gl.drawArraysInstanced(GL_TRIANGLE_STRIP, 2, 4, 2);
524 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArraysInstanced");
525 }
526
527 /* ---------------------------------- */
528
529 /* ShaderDrawElementsInstancedParametersTestCase */
530
initChild()531 void ShaderDrawElementsInstancedParametersTestCase::initChild()
532 {
533 // Set expected result vector [x, y, red, green, blue]
534 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
535 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
536 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
537 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
538 }
539
deinitChild()540 void ShaderDrawElementsInstancedParametersTestCase::deinitChild()
541 {
542 /* Do nothing */
543 }
544
drawCommand()545 void ShaderDrawElementsInstancedParametersTestCase::drawCommand()
546 {
547 const Functions& gl = m_context.getRenderContext().getFunctions();
548
549 gl.drawElementsInstanced(GL_TRIANGLE_STRIP, 6, GL_UNSIGNED_SHORT, (GLvoid*)0, 3);
550 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawElementsInstanced");
551 }
552
553 /* ---------------------------------- */
554
555 /* ShaderMultiDrawArraysParametersTestCase */
556
initChild()557 void ShaderMultiDrawArraysParametersTestCase::initChild()
558 {
559 // Set expected result vector [x, y, red, green, blue]
560 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
561 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 1.0f, 1.0f, 0.0f));
562 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 0.0f, 1.0f, 0.0f));
563 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 0.0f, 0.0f, 0.0f));
564 }
565
deinitChild()566 void ShaderMultiDrawArraysParametersTestCase::deinitChild()
567 {
568 /* Do nothing */
569 }
570
drawCommand()571 void ShaderMultiDrawArraysParametersTestCase::drawCommand()
572 {
573 const Functions& gl = m_context.getRenderContext().getFunctions();
574
575 const GLint dFirst[] = { 0, 1 };
576 const GLsizei dCount[] = { 4, 4 };
577
578 gl.multiDrawArrays(GL_TRIANGLE_STRIP, dFirst, dCount, 2);
579 GLU_EXPECT_NO_ERROR(gl.getError(), "glMultiDrawArrays");
580 }
581
582 /* ---------------------------------- */
583
584 /* ShaderMultiDrawElementsParametersTestCase */
585
initChild()586 void ShaderMultiDrawElementsParametersTestCase::initChild()
587 {
588 // Set expected result vector [x, y, red, green, blue]
589 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 0.0f, 0.0f, 0.0f));
590 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 1.0f, 1.0f, 0.0f));
591 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 1.0f, 1.0f, 0.0f));
592 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
593 }
594
deinitChild()595 void ShaderMultiDrawElementsParametersTestCase::deinitChild()
596 {
597 /* Do nothing */
598 }
599
drawCommand()600 void ShaderMultiDrawElementsParametersTestCase::drawCommand()
601 {
602 const Functions& gl = m_context.getRenderContext().getFunctions();
603
604 const GLsizei dCount[] = { 5, 4 };
605 const GLvoid* dIndices[] = { (GLvoid*)(1 * sizeof(GLushort)), (GLvoid*)(1 * sizeof(GLushort)) };
606
607 gl.multiDrawElements(GL_TRIANGLE_STRIP, dCount, GL_UNSIGNED_SHORT, dIndices, 2);
608 GLU_EXPECT_NO_ERROR(gl.getError(), "glMultiDrawElements");
609 }
610
611 /* ---------------------------------- */
612
613 /* ShaderMultiDrawArraysIndirectParametersTestCase */
614
initChild()615 void ShaderMultiDrawArraysIndirectParametersTestCase::initChild()
616 {
617 const Functions& gl = m_context.getRenderContext().getFunctions();
618
619 // Set expected result vector [x, y, red, green, blue]
620 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 0.0f, 1.0f, 0.0f));
621 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 1.0f, 1.0f, 0.0f));
622 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
623 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
624 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -0.8f + 0.05f, 0.0f, 0.0f, 1.0f));
625 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -0.8f + 0.15f, 0.0f, 0.0f, 0.0f));
626 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -0.8f + 0.05f, 0.0f, 0.0f, 0.0f));
627 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -0.8f + 0.15f, 0.0f, 0.0f, 0.0f));
628
629 const SDPDrawArraysIndirectCommand indirect[] = {
630 { 5, 1, 1, 0 }, { 4, 1, 0, 0 }, { 3, 1, 0, 1 },
631 };
632
633 // Setup indirect command buffer
634 gl.genBuffers(1, &m_drawIndirectBuffer);
635 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers");
636
637 gl.bindBuffer(GL_DRAW_INDIRECT_BUFFER, m_drawIndirectBuffer);
638 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer");
639
640 gl.bufferData(GL_DRAW_INDIRECT_BUFFER, 3 * sizeof(SDPDrawArraysIndirectCommand), indirect, GL_STATIC_DRAW);
641 GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData");
642 }
643
deinitChild()644 void ShaderMultiDrawArraysIndirectParametersTestCase::deinitChild()
645 {
646 const Functions& gl = m_context.getRenderContext().getFunctions();
647
648 if (m_drawIndirectBuffer)
649 gl.deleteBuffers(1, &m_drawIndirectBuffer);
650 }
651
drawCommand()652 void ShaderMultiDrawArraysIndirectParametersTestCase::drawCommand()
653 {
654 const Functions& gl = m_context.getRenderContext().getFunctions();
655
656 gl.multiDrawArraysIndirect(GL_TRIANGLE_STRIP, (GLvoid*)0, 3, sizeof(SDPDrawArraysIndirectCommand));
657 GLU_EXPECT_NO_ERROR(gl.getError(), "glMultiDrawArraysIndirect");
658 }
659
660 /* ---------------------------------- */
661
662 /* ShaderMultiDrawElementsIndirectParametersTestCase */
663
initChild()664 void ShaderMultiDrawElementsIndirectParametersTestCase::initChild()
665 {
666 const Functions& gl = m_context.getRenderContext().getFunctions();
667
668 // Set expected result vector [x, y, red, green, blue]
669 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
670 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
671 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 0.0f, 0.0f, 0.0f));
672 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 0.0f, 0.0f, 0.0f));
673 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -0.8f + 0.05f, 0.0f, 0.0f, 0.0f));
674 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -0.8f + 0.15f, 0.0f, 0.0f, 0.0f));
675 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -0.8f + 0.05f, 0.0f, 0.0f, 0.0f));
676 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -0.8f + 0.15f, 0.0f, 1.0f, 0.0f));
677 m_resultPoints.push_back(ResultPoint(-0.8f + 0.05f, -1.0f + 0.05f, 0.0f, 0.0f, 0.0f));
678 m_resultPoints.push_back(ResultPoint(-0.8f + 0.05f, -1.0f + 0.15f, 0.0f, 0.0f, 1.0f));
679 m_resultPoints.push_back(ResultPoint(-0.8f + 0.15f, -1.0f + 0.05f, 0.0f, 0.0f, 0.0f));
680 m_resultPoints.push_back(ResultPoint(-0.8f + 0.15f, -1.0f + 0.15f, 0.0f, 0.0f, 0.0f));
681
682 const SDPDrawElementsIndirectCommand indirect[] = {
683 { 4, 1, 0, 0, 0 }, { 3, 1, 3, 0, 1 }, { 3, 1, 0, 1, 0 },
684 };
685
686 // Setup indirect command buffer
687 gl.genBuffers(1, &m_drawIndirectBuffer);
688 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers");
689
690 gl.bindBuffer(GL_DRAW_INDIRECT_BUFFER, m_drawIndirectBuffer);
691 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer");
692
693 gl.bufferData(GL_DRAW_INDIRECT_BUFFER, 3 * sizeof(SDPDrawElementsIndirectCommand), indirect, GL_STATIC_DRAW);
694 GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData");
695 }
696
deinitChild()697 void ShaderMultiDrawElementsIndirectParametersTestCase::deinitChild()
698 {
699 const Functions& gl = m_context.getRenderContext().getFunctions();
700
701 if (m_drawIndirectBuffer)
702 gl.deleteBuffers(1, &m_drawIndirectBuffer);
703 }
704
drawCommand()705 void ShaderMultiDrawElementsIndirectParametersTestCase::drawCommand()
706 {
707 const Functions& gl = m_context.getRenderContext().getFunctions();
708
709 gl.multiDrawElementsIndirect(GL_TRIANGLE_STRIP, GL_UNSIGNED_SHORT, (GLvoid*)0, 3,
710 sizeof(SDPDrawElementsIndirectCommand));
711 GLU_EXPECT_NO_ERROR(gl.getError(), "glMultiDrawElementsIndirect");
712 }
713
714 /* ---------------------------------- */
715
716 /* ShaderMultiDrawArraysIndirectCountParametersTestCase */
717
initChild()718 void ShaderMultiDrawArraysIndirectCountParametersTestCase::initChild()
719 {
720 glu::ContextType contextType = m_context.getRenderContext().getType();
721 if (!glu::contextSupports(contextType, glu::ApiType::core(4, 6)) &&
722 !m_context.getContextInfo().isExtensionSupported("GL_ARB_indirect_parameters"))
723 {
724 TCU_THROW(NotSupportedError, "indirect_parameters functionality not supported");
725 }
726
727 const Functions& gl = m_context.getRenderContext().getFunctions();
728
729 // Set expected result vector [x, y, red, green, blue]
730 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 0.0f, 0.0f, 0.0f));
731 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
732 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
733 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
734 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -0.8f + 0.05f, 0.0f, 1.0f, 0.0f));
735 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -0.8f + 0.15f, 0.0f, 1.0f, 0.0f));
736 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -0.8f + 0.05f, 0.0f, 1.0f, 0.0f));
737 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -0.8f + 0.15f, 0.0f, 1.0f, 0.0f));
738 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -0.6f + 0.05f, 0.0f, 0.0f, 0.0f));
739 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -0.6f + 0.15f, 0.0f, 0.0f, 0.0f));
740 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -0.6f + 0.05f, 0.0f, 0.0f, 1.0f));
741 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -0.6f + 0.15f, 0.0f, 0.0f, 1.0f));
742
743 const SDPDrawArraysIndirectCommand indirect[] = {
744 { 5, 1, 1, 0 }, { 6, 1, 0, 1 }, { 4, 1, 2, 2 },
745 };
746
747 const GLushort parameters[] = { 1, 1, 1 };
748
749 // Setup indirect command buffer
750 gl.genBuffers(1, &m_drawIndirectBuffer);
751 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers");
752
753 gl.bindBuffer(GL_DRAW_INDIRECT_BUFFER, m_drawIndirectBuffer);
754 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer");
755
756 gl.bufferData(GL_DRAW_INDIRECT_BUFFER, 4 * sizeof(SDPDrawArraysIndirectCommand), indirect, GL_STATIC_DRAW);
757 GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData");
758
759 // Setup indirect command buffer
760 gl.genBuffers(1, &m_parameterBuffer);
761 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers");
762
763 gl.bindBuffer(GL_PARAMETER_BUFFER_ARB, m_parameterBuffer);
764 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer");
765
766 gl.bufferData(GL_PARAMETER_BUFFER_ARB, 3 * sizeof(GLushort), parameters, GL_STATIC_DRAW);
767 GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData");
768 }
769
deinitChild()770 void ShaderMultiDrawArraysIndirectCountParametersTestCase::deinitChild()
771 {
772 const Functions& gl = m_context.getRenderContext().getFunctions();
773
774 if (m_drawIndirectBuffer)
775 gl.deleteBuffers(1, &m_drawIndirectBuffer);
776 if (m_parameterBuffer)
777 gl.deleteBuffers(1, &m_parameterBuffer);
778 }
779
drawCommand()780 void ShaderMultiDrawArraysIndirectCountParametersTestCase::drawCommand()
781 {
782 const Functions& gl = m_context.getRenderContext().getFunctions();
783
784 gl.multiDrawArraysIndirectCount(GL_TRIANGLE_STRIP, 0, 0, 3, sizeof(SDPDrawArraysIndirectCommand));
785 GLU_EXPECT_NO_ERROR(gl.getError(), "glMultiDrawArraysIndirect");
786 }
787
788 /* ---------------------------------- */
789
790 /* ShaderMultiDrawElementsIndirectCountParametersTestCase */
791
initChild()792 void ShaderMultiDrawElementsIndirectCountParametersTestCase::initChild()
793 {
794 glu::ContextType contextType = m_context.getRenderContext().getType();
795 if (!glu::contextSupports(contextType, glu::ApiType::core(4, 6)) &&
796 !m_context.getContextInfo().isExtensionSupported("GL_ARB_indirect_parameters"))
797 {
798 TCU_THROW(NotSupportedError, "indirect_parameters functionality not supported");
799 }
800
801 const Functions& gl = m_context.getRenderContext().getFunctions();
802
803 // Set expected result vector [x, y, red, green, blue]
804 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
805 m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 0.0f, 0.0f, 0.0f));
806 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 0.0f, 0.0f, 0.0f));
807 m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 0.0f, 0.0f, 0.0f));
808 m_resultPoints.push_back(ResultPoint(-0.8f + 0.05f, -0.8f + 0.05f, 0.0f, 0.0f, 0.0f));
809 m_resultPoints.push_back(ResultPoint(-0.8f + 0.05f, -0.8f + 0.15f, 0.0f, 1.0f, 1.0f));
810 m_resultPoints.push_back(ResultPoint(-0.8f + 0.15f, -0.8f + 0.05f, 0.0f, 0.0f, 1.0f));
811 m_resultPoints.push_back(ResultPoint(-0.8f + 0.15f, -0.8f + 0.15f, 0.0f, 0.0f, 0.0f));
812
813 const SDPDrawElementsIndirectCommand indirect[] = {
814 { 3, 1, 0, 0, 0 }, { 3, 1, 0, 1, 1 }, { 4, 1, 0, 1, 1 },
815 };
816
817 const GLushort parameters[] = { 1, 1, 1 };
818
819 // Setup indirect command buffer
820 gl.genBuffers(1, &m_drawIndirectBuffer);
821 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers");
822
823 gl.bindBuffer(GL_DRAW_INDIRECT_BUFFER, m_drawIndirectBuffer);
824 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer");
825
826 gl.bufferData(GL_DRAW_INDIRECT_BUFFER, 3 * sizeof(SDPDrawElementsIndirectCommand), indirect, GL_STATIC_DRAW);
827 GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData");
828
829 // Setup indirect command buffer
830 gl.genBuffers(1, &m_parameterBuffer);
831 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers");
832
833 gl.bindBuffer(GL_PARAMETER_BUFFER_ARB, m_parameterBuffer);
834 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer");
835
836 gl.bufferData(GL_PARAMETER_BUFFER_ARB, 3 * sizeof(GLushort), parameters, GL_STATIC_DRAW);
837 GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData");
838 }
839
deinitChild()840 void ShaderMultiDrawElementsIndirectCountParametersTestCase::deinitChild()
841 {
842 const Functions& gl = m_context.getRenderContext().getFunctions();
843
844 if (m_drawIndirectBuffer)
845 gl.deleteBuffers(1, &m_drawIndirectBuffer);
846 if (m_parameterBuffer)
847 gl.deleteBuffers(1, &m_parameterBuffer);
848 }
849
drawCommand()850 void ShaderMultiDrawElementsIndirectCountParametersTestCase::drawCommand()
851 {
852 const Functions& gl = m_context.getRenderContext().getFunctions();
853
854 gl.multiDrawElementsIndirectCount(GL_TRIANGLE_STRIP, GL_UNSIGNED_SHORT, 0, 0, 3,
855 sizeof(SDPDrawElementsIndirectCommand));
856 GLU_EXPECT_NO_ERROR(gl.getError(), "glMultiDrawElementsIndirect");
857 }
858
859 /* ---------------------------------- */
860
861 /** Constructor.
862 *
863 * @param context Rendering context.
864 */
ShaderDrawParametersTests(deqp::Context & context)865 ShaderDrawParametersTests::ShaderDrawParametersTests(deqp::Context& context)
866 : TestCaseGroup(context, "shader_draw_parameters_tests",
867 "Verify conformance of GL_ARB_shader_draw_parameters implementation")
868 {
869 }
870
871 /** Initializes the test group contents. */
init()872 void ShaderDrawParametersTests::init()
873 {
874 addChild(new ShaderDrawParametersExtensionTestCase(m_context));
875 addChild(new ShaderDrawArraysParametersTestCase(m_context));
876 addChild(new ShaderDrawElementsParametersTestCase(m_context));
877 addChild(new ShaderDrawArraysIndirectParametersTestCase(m_context));
878 addChild(new ShaderDrawElementsIndirectParametersTestCase(m_context));
879 addChild(new ShaderDrawArraysInstancedParametersTestCase(m_context));
880 addChild(new ShaderDrawElementsInstancedParametersTestCase(m_context));
881 addChild(new ShaderMultiDrawArraysParametersTestCase(m_context));
882 addChild(new ShaderMultiDrawElementsParametersTestCase(m_context));
883 addChild(new ShaderMultiDrawArraysIndirectParametersTestCase(m_context));
884 addChild(new ShaderMultiDrawElementsIndirectParametersTestCase(m_context));
885 addChild(new ShaderMultiDrawArraysIndirectCountParametersTestCase(m_context));
886 addChild(new ShaderMultiDrawElementsIndirectCountParametersTestCase(m_context));
887 }
888
889 } /* gl4cts namespace */
890