PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/spec/gl-3.0/api/getfragdatalocation.c

https://gitlab.com/mcepl/piglit
C | 186 lines | 114 code | 29 blank | 43 comment | 25 complexity | 1194c6fb2a33ede5c2724fe2ca2eb454 MD5 | raw file
Possible License(s): MIT
  1. /* Copyright © 2011 Intel Corporation
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a
  4. * copy of this software and associated documentation files (the "Software"),
  5. * to deal in the Software without restriction, including without limitation
  6. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  7. * and/or sell copies of the Software, and to permit persons to whom the
  8. * Software is furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice (including the next
  11. * paragraph) shall be included in all copies or substantial portions of the
  12. * Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. * IN THE SOFTWARE.
  21. */
  22. /**
  23. * \file getfragdatalocation.c
  24. *
  25. * \author Ian Romanick
  26. */
  27. #include "piglit-util-gl.h"
  28. PIGLIT_GL_TEST_CONFIG_BEGIN
  29. config.supports_gl_compat_version = 10;
  30. config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
  31. PIGLIT_GL_TEST_CONFIG_END
  32. static const char *vs_text =
  33. "#version 130\n"
  34. "in vec4 vertex;\n"
  35. "void main() { gl_Position = vertex; }\n"
  36. ;
  37. static const char *fs_text =
  38. "#version 130\n"
  39. "out vec4 v;\n"
  40. "out vec4 a[2];\n"
  41. "void main() {\n"
  42. " v = vec4(0.0);\n"
  43. " a[0] = vec4(1.0);\n"
  44. " a[1] = vec4(2.0);\n"
  45. "}\n"
  46. ;
  47. enum piglit_result
  48. piglit_display(void)
  49. {
  50. return PIGLIT_FAIL;
  51. }
  52. void piglit_init(int argc, char **argv)
  53. {
  54. GLint max_draw_buffers;
  55. GLuint prog;
  56. GLuint vs;
  57. GLuint fs;
  58. GLint loc;
  59. piglit_require_gl_version(30);
  60. /* This test needs some number of draw buffers, so make sure the
  61. * implementation isn't broken. This enables the test to generate a
  62. * useful failure message.
  63. */
  64. glGetIntegerv(GL_MAX_DRAW_BUFFERS, &max_draw_buffers);
  65. if (max_draw_buffers < 8) {
  66. fprintf(stderr,
  67. "OpenGL 3.0 requires GL_MAX_DRAW_BUFFERS >= 8. "
  68. "Only got %d!\n",
  69. max_draw_buffers);
  70. piglit_report_result(PIGLIT_FAIL);
  71. }
  72. prog = glCreateProgram();
  73. vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_text);
  74. fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_text);
  75. glAttachShader(prog, vs);
  76. glAttachShader(prog, fs);
  77. if (!piglit_check_gl_error(GL_NO_ERROR))
  78. piglit_report_result(PIGLIT_FAIL);
  79. /* Page 237 (page 253 of the PDF) of the OpenGL 3.0 spec says:
  80. *
  81. * "If program has not been successfully linked, the error INVALID
  82. * OPERATION is generated. If name is not a varying out variable,
  83. * or if an error occurs, -1 will be returned."
  84. */
  85. printf("Querying location before linking...\n");
  86. loc = glGetFragDataLocation(prog, "v");
  87. if (!piglit_check_gl_error(GL_INVALID_OPERATION))
  88. piglit_report_result(PIGLIT_FAIL);
  89. if (loc != -1) {
  90. fprintf(stderr, "Expected location = -1, got %d\n", loc);
  91. piglit_report_result(PIGLIT_FAIL);
  92. }
  93. glLinkProgram(prog);
  94. if (!piglit_check_gl_error(GL_NO_ERROR))
  95. piglit_report_result(PIGLIT_FAIL);
  96. if (!piglit_link_check_status(prog)) {
  97. piglit_report_result(PIGLIT_FAIL);
  98. }
  99. printf("Querying location of nonexistent variable...\n");
  100. loc = glGetFragDataLocation(prog, "waldo");
  101. if (!piglit_check_gl_error(GL_NO_ERROR))
  102. piglit_report_result(PIGLIT_FAIL);
  103. if (loc != -1) {
  104. fprintf(stderr, "Expected location = -1, got %d\n", loc);
  105. piglit_report_result(PIGLIT_FAIL);
  106. }
  107. /* Page 236 (page 252 of the PDF) of the OpenGL 3.0 spec says:
  108. *
  109. * "BindFragDataLocation has no effect until the program is
  110. * linked. In particular, it doesn’t modify the bindings of
  111. * varying out variables in a program that has already been
  112. * linked."
  113. */
  114. glBindFragDataLocation(prog, 0, "v");
  115. glBindFragDataLocation(prog, 1, "a");
  116. glLinkProgram(prog);
  117. if (!piglit_check_gl_error(GL_NO_ERROR))
  118. piglit_report_result(PIGLIT_FAIL);
  119. if (!piglit_link_check_status(prog)) {
  120. piglit_report_result(PIGLIT_FAIL);
  121. }
  122. printf("Querying locations after binding and linking...\n");
  123. loc = glGetFragDataLocation(prog, "v");
  124. if (!piglit_check_gl_error(GL_NO_ERROR))
  125. piglit_report_result(PIGLIT_FAIL);
  126. if (loc != 0) {
  127. fprintf(stderr, "Expected location = 0, got %d\n", loc);
  128. piglit_report_result(PIGLIT_FAIL);
  129. }
  130. loc = glGetFragDataLocation(prog, "a");
  131. if (!piglit_check_gl_error(GL_NO_ERROR))
  132. piglit_report_result(PIGLIT_FAIL);
  133. if (loc != 1) {
  134. fprintf(stderr, "Expected location = 1, got %d\n", loc);
  135. piglit_report_result(PIGLIT_FAIL);
  136. }
  137. printf("Querying locations after just binding...\n");
  138. glBindFragDataLocation(prog, 2, "v");
  139. glBindFragDataLocation(prog, 0, "a");
  140. if (!piglit_check_gl_error(GL_NO_ERROR))
  141. piglit_report_result(PIGLIT_FAIL);
  142. loc = glGetFragDataLocation(prog, "v");
  143. if (!piglit_check_gl_error(GL_NO_ERROR))
  144. piglit_report_result(PIGLIT_FAIL);
  145. if (loc != 0) {
  146. fprintf(stderr, "Expected location = 0, got %d\n", loc);
  147. piglit_report_result(PIGLIT_FAIL);
  148. }
  149. loc = glGetFragDataLocation(prog, "a");
  150. if (!piglit_check_gl_error(GL_NO_ERROR))
  151. piglit_report_result(PIGLIT_FAIL);
  152. if (loc != 1) {
  153. fprintf(stderr, "Expected location = 1, got %d\n", loc);
  154. piglit_report_result(PIGLIT_FAIL);
  155. }
  156. piglit_report_result(PIGLIT_PASS);
  157. }