PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

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