perf/pixel-rate: new pixel throughput microbenchmark
[piglit.git] / tests / shaders / sso-simple.c
blob89cac8eb829cf61d8f1b920e7bc0537b9b600ef7
1 /*
2 * Copyright © 2010 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 /**
25 * \file sso-simple.c
26 * Simple GL_EXT_separate_shader_objects rendering test
28 * \author Ian Romanick <ian.d.romanick@intel.com>
30 #include "piglit-util-gl.h"
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config.supports_gl_compat_version = 10;
36 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
38 PIGLIT_GL_TEST_CONFIG_END
40 static const char vs_text[] =
41 "void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; "
42 "gl_FrontColor = vec4(0.0, 1.0, 0.0, 1.0); }";
44 static const char good_fs_text[] =
45 "void main() { gl_FragColor = gl_Color; }";
47 /* It is important that this shader *not* use gl_Color.
49 static const char bad_fs_text[] =
50 "void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }";
52 static GLuint prog[3];
54 enum piglit_result
55 piglit_display(void)
57 static const float green[3] = { 0.0, 1.0, 0.0 };
58 static const float blue[3] = { 0.0, 0.0, 1.0 };
59 enum piglit_result result = PIGLIT_PASS;
60 float x = 10.0;
62 glClear(GL_COLOR_BUFFER_BIT);
63 glColor3fv(blue);
65 /* Bind the separately linked vertex shader and the separately linked
66 * fragment shader using the new interfaces. This should produce a
67 * green box.
69 glUseShaderProgramEXT(GL_VERTEX_SHADER, prog[0]);
70 glUseShaderProgramEXT(GL_FRAGMENT_SHADER, prog[1]);
71 piglit_draw_rect(x, 10, 10, 10);
72 if (!piglit_probe_pixel_rgb(x + 5, 15, green))
73 result = PIGLIT_FAIL;
75 x += 20.0;
77 /* Bind the vertex shader that is already linked with a fragment
78 * shader and the separately linked fragment shader using the new
79 * interfaces. This should produce a green box.
81 * If the linked optimized away the vertex shader writes to
82 * gl_FrontColor (because the fragment shader in prog[2] does not use
83 * it), this will produce incorrect results.
85 glUseProgram(prog[2]);
86 glUseShaderProgramEXT(GL_FRAGMENT_SHADER, prog[1]);
87 piglit_draw_rect(x, 10, 10, 10);
88 if (!piglit_probe_pixel_rgb(x + 5, 15, green))
89 result = PIGLIT_FAIL;
91 x += 20.0;
93 /* Unbind any program from the vertex shader stage so that fixed
94 * function is used. This should produce the same results as the
95 * vertex shader except that fixed-function outputs blue.
97 glUseShaderProgramEXT(GL_VERTEX_SHADER, 0);
98 piglit_draw_rect(x, 10, 10, 10);
99 if (!piglit_probe_pixel_rgb(x + 5, 15, blue))
100 result = PIGLIT_FAIL;
102 if (!piglit_automatic)
103 piglit_present_results();
105 return result;
108 void
109 piglit_init(int argc, char **argv)
111 GLuint vs;
112 GLuint fs;
114 piglit_require_gl_version(20);
116 piglit_require_extension("GL_EXT_separate_shader_objects");
118 glClearColor(0.3, 0.3, 0.3, 0.0);
120 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
122 vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_text);
123 fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, bad_fs_text);
125 prog[0] = piglit_link_simple_program(vs, 0);
126 prog[1] = glCreateShaderProgramEXT(GL_FRAGMENT_SHADER, good_fs_text);
127 prog[2] = piglit_link_simple_program(vs, fs);
129 glDeleteShader(vs);
130 glDeleteShader(fs);