PageRenderTime 24ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/blaztinn/piglit
C | 182 lines | 112 code | 27 blank | 43 comment | 25 complexity | 4cc99bd2f3004f75b58f500a5598ee6a 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-common.h"
  28. int piglit_width = 100, piglit_height = 100;
  29. int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
  30. static const char *vs_text =
  31. "#version 130\n"
  32. "in vec4 vertex;\n"
  33. "void main() { gl_Position = vertex; }\n"
  34. ;
  35. static const char *fs_text =
  36. "#version 130\n"
  37. "out vec4 v;\n"
  38. "out vec4 a[2];\n"
  39. "void main() {\n"
  40. " v = vec4(0.0);\n"
  41. " a[0] = vec4(1.0);\n"
  42. " a[1] = vec4(2.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. glAttachShader(prog, vs);
  74. glAttachShader(prog, fs);
  75. if (!piglit_check_gl_error(GL_NO_ERROR))
  76. piglit_report_result(PIGLIT_FAIL);
  77. /* Page 237 (page 253 of the PDF) of the OpenGL 3.0 spec says:
  78. *
  79. * "If program has not been successfully linked, the error INVALID
  80. * OPERATION is generated. If name is not a varying out variable,
  81. * or if an error occurs, -1 will be returned."
  82. */
  83. printf("Querying location before linking...\n");
  84. loc = glGetFragDataLocation(prog, "v");
  85. if (!piglit_check_gl_error(GL_INVALID_OPERATION))
  86. piglit_report_result(PIGLIT_FAIL);
  87. if (loc != -1) {
  88. fprintf(stderr, "Expected location = -1, got %d\n", loc);
  89. piglit_report_result(PIGLIT_FAIL);
  90. }
  91. glLinkProgram(prog);
  92. if (!piglit_check_gl_error(GL_NO_ERROR))
  93. piglit_report_result(PIGLIT_FAIL);
  94. if (!piglit_link_check_status(prog)) {
  95. piglit_report_result(PIGLIT_FAIL);
  96. }
  97. printf("Querying location of nonexistent variable...\n");
  98. loc = glGetFragDataLocation(prog, "waldo");
  99. if (!piglit_check_gl_error(GL_NO_ERROR))
  100. piglit_report_result(PIGLIT_FAIL);
  101. if (loc != -1) {
  102. fprintf(stderr, "Expected location = -1, got %d\n", loc);
  103. piglit_report_result(PIGLIT_FAIL);
  104. }
  105. /* Page 236 (page 252 of the PDF) of the OpenGL 3.0 spec says:
  106. *
  107. * "BindFragDataLocation has no effect until the program is
  108. * linked. In particular, it doesn’t modify the bindings of
  109. * varying out variables in a program that has already been
  110. * linked."
  111. */
  112. glBindFragDataLocation(prog, 0, "v");
  113. glBindFragDataLocation(prog, 1, "a");
  114. glLinkProgram(prog);
  115. if (!piglit_check_gl_error(GL_NO_ERROR))
  116. piglit_report_result(PIGLIT_FAIL);
  117. if (!piglit_link_check_status(prog)) {
  118. piglit_report_result(PIGLIT_FAIL);
  119. }
  120. printf("Querying locations after binding and linking...\n");
  121. loc = glGetFragDataLocation(prog, "v");
  122. if (!piglit_check_gl_error(GL_NO_ERROR))
  123. piglit_report_result(PIGLIT_FAIL);
  124. if (loc != 0) {
  125. fprintf(stderr, "Expected location = 0, got %d\n", loc);
  126. piglit_report_result(PIGLIT_FAIL);
  127. }
  128. loc = glGetFragDataLocation(prog, "a");
  129. if (!piglit_check_gl_error(GL_NO_ERROR))
  130. piglit_report_result(PIGLIT_FAIL);
  131. if (loc != 1) {
  132. fprintf(stderr, "Expected location = 1, got %d\n", loc);
  133. piglit_report_result(PIGLIT_FAIL);
  134. }
  135. printf("Querying locations after just binding...\n");
  136. glBindFragDataLocation(prog, 2, "v");
  137. glBindFragDataLocation(prog, 0, "a");
  138. if (!piglit_check_gl_error(GL_NO_ERROR))
  139. piglit_report_result(PIGLIT_FAIL);
  140. loc = glGetFragDataLocation(prog, "v");
  141. if (!piglit_check_gl_error(GL_NO_ERROR))
  142. piglit_report_result(PIGLIT_FAIL);
  143. if (loc != 0) {
  144. fprintf(stderr, "Expected location = 0, got %d\n", loc);
  145. piglit_report_result(PIGLIT_FAIL);
  146. }
  147. loc = glGetFragDataLocation(prog, "a");
  148. if (!piglit_check_gl_error(GL_NO_ERROR))
  149. piglit_report_result(PIGLIT_FAIL);
  150. if (loc != 1) {
  151. fprintf(stderr, "Expected location = 1, got %d\n", loc);
  152. piglit_report_result(PIGLIT_FAIL);
  153. }
  154. piglit_report_result(PIGLIT_PASS);
  155. }