/tests/spec/gl-3.0/api/bindfragdata-nonexistent-variable.c

https://github.com/nobled/piglit · C · 162 lines · 98 code · 25 blank · 39 comment · 18 complexity · a80e0566f70b94e92a7edc22cea9f151 MD5 · raw file

  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 bindfragdata-nonexistent-variable.c
  24. * Test the behavior of glBindFragDataLocation on a non-existent variable
  25. *
  26. * \author Ian Romanick
  27. */
  28. #include "piglit-util.h"
  29. int piglit_width = 100, piglit_height = 100;
  30. int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
  31. static const char *vs_text =
  32. "#version 130\n"
  33. "in vec4 vertex;\n"
  34. "void main() { gl_Position = vertex; }\n"
  35. ;
  36. static const char *fs_text =
  37. "#version 130\n"
  38. "out vec4 v;\n"
  39. "void main() {\n"
  40. " v = vec4(0.0);\n"
  41. "}\n"
  42. ;
  43. enum piglit_result
  44. piglit_display(void)
  45. {
  46. return PIGLIT_FAIL;
  47. }
  48. void piglit_init(int argc, char **argv)
  49. {
  50. GLint max_draw_buffers;
  51. GLuint prog;
  52. GLuint vs;
  53. GLuint fs;
  54. GLint loc;
  55. piglit_require_gl_version(30);
  56. /* This test needs some number of draw buffers, so make sure the
  57. * implementation isn't broken. This enables the test to generate a
  58. * useful failure message.
  59. */
  60. glGetIntegerv(GL_MAX_DRAW_BUFFERS, &max_draw_buffers);
  61. if (max_draw_buffers < 8) {
  62. fprintf(stderr,
  63. "OpenGL 3.0 requires GL_MAX_DRAW_BUFFERS >= 8. "
  64. "Only got %d!\n",
  65. max_draw_buffers);
  66. piglit_report_result(PIGLIT_FAIL);
  67. }
  68. prog = glCreateProgram();
  69. vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_text);
  70. fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_text);
  71. if (!piglit_check_gl_error(GL_NO_ERROR))
  72. piglit_report_result(PIGLIT_FAIL);
  73. /* First, verify that the program will link without making any
  74. * location assignments through the API.
  75. */
  76. printf("Basic test...\n");
  77. glAttachShader(prog, vs);
  78. glAttachShader(prog, fs);
  79. glLinkProgram(prog);
  80. if (!piglit_check_gl_error(GL_NO_ERROR))
  81. piglit_report_result(PIGLIT_FAIL);
  82. if (!piglit_link_check_status(prog)) {
  83. piglit_report_result(PIGLIT_FAIL);
  84. }
  85. /* Page 237 (page 253 of the PDF) of the OpenGL 3.0 spec says:
  86. *
  87. * "Assigned bindings for variables that do not exist are
  88. * ignored."
  89. */
  90. printf("Binding `unicorn' to a non-conflicting location...\n");
  91. glBindFragDataLocation(prog, 0, "v");
  92. if (!piglit_check_gl_error(GL_NO_ERROR))
  93. piglit_report_result(PIGLIT_FAIL);
  94. glBindFragDataLocation(prog, 1, "unicorn");
  95. if (!piglit_check_gl_error(GL_NO_ERROR))
  96. piglit_report_result(PIGLIT_FAIL);
  97. glLinkProgram(prog);
  98. if (!piglit_check_gl_error(GL_NO_ERROR))
  99. piglit_report_result(PIGLIT_FAIL);
  100. if (!piglit_link_check_status(prog)) {
  101. fprintf(stderr,
  102. "Linking failed when it should have been "
  103. "successful.\n");
  104. piglit_report_result(PIGLIT_FAIL);
  105. }
  106. loc = glGetFragDataLocation(prog, "unicorn");
  107. if (!piglit_check_gl_error(GL_NO_ERROR))
  108. piglit_report_result(PIGLIT_FAIL);
  109. if (loc != -1) {
  110. fprintf(stderr, "Expected location = -1, got %d\n", loc);
  111. piglit_report_result(PIGLIT_FAIL);
  112. }
  113. printf("Binding `unicorn' to a conflicting location...\n");
  114. glBindFragDataLocation(prog, 0, "v");
  115. if (!piglit_check_gl_error(GL_NO_ERROR))
  116. piglit_report_result(PIGLIT_FAIL);
  117. glBindFragDataLocation(prog, 0, "unicorn");
  118. if (!piglit_check_gl_error(GL_NO_ERROR))
  119. piglit_report_result(PIGLIT_FAIL);
  120. glLinkProgram(prog);
  121. if (!piglit_check_gl_error(GL_NO_ERROR))
  122. piglit_report_result(PIGLIT_FAIL);
  123. if (!piglit_link_check_status(prog)) {
  124. fprintf(stderr,
  125. "Linking failed when it should have been "
  126. "successful.\n");
  127. piglit_report_result(PIGLIT_FAIL);
  128. }
  129. loc = glGetFragDataLocation(prog, "unicorn");
  130. if (!piglit_check_gl_error(GL_NO_ERROR))
  131. piglit_report_result(PIGLIT_FAIL);
  132. if (loc != -1) {
  133. fprintf(stderr, "Expected location = -1, got %d\n", loc);
  134. piglit_report_result(PIGLIT_FAIL);
  135. }
  136. piglit_report_result(PIGLIT_PASS);
  137. }