cl: Don't use device_infos if num_device_infos == 0
[piglit.git] / tests / shaders / fp-formats.c
blob1edcb3aff6d0f20dde287bd8305dc264dce50d75
1 /*
2 * Copyright © 2009 Intel Corporation
3 * Copyright © 2010 Red Hat, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
25 /**
26 * \file fp-formats.c
27 * Test fragment programs sampling from different texture formats.
28 * (currently just alpha-only textures)
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config.supports_gl_compat_version = 10;
37 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
39 PIGLIT_GL_TEST_CONFIG_END
41 /**
42 * Modulate the primary color with the alpha channel of the texture
44 static const char alpha_source[] =
45 "!!ARBfp1.0\n"
46 "TEMP texel0;\n"
47 "TEX texel0,fragment.texcoord[0],texture[0],2D;\n"
48 "MOV result.color, texel0.abgr;\n"
49 "END"
52 static GLint progs[1];
53 static GLuint textures[1];
55 enum piglit_result
56 piglit_display(void)
58 enum piglit_result result = PIGLIT_PASS;
60 const GLfloat expected[4] = { 0.5, 0.0, 0.0, 0.0 };
62 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, progs[0]);
64 glClear(GL_COLOR_BUFFER_BIT);
65 glEnable(GL_FRAGMENT_PROGRAM_ARB);
67 piglit_draw_rect(0, 0, piglit_width, piglit_height);
69 if (!piglit_probe_pixel_rgb(piglit_width / 2,
70 piglit_height / 2,
71 expected))
72 result = PIGLIT_FAIL;
74 piglit_present_results();
75 return result;
79 void
80 piglit_init(int argc, char **argv)
82 const GLfloat alpha_data[] = { 0.5 };
84 (void) argc;
85 (void) argv;
87 piglit_require_fragment_program();
88 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
90 progs[0] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB,
91 alpha_source);
93 glGenTextures(1, textures);
95 glActiveTexture(GL_TEXTURE0);
96 glBindTexture(GL_TEXTURE_2D, textures[0]);
97 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 1, 1, 0, GL_ALPHA, GL_FLOAT, alpha_data);
98 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
99 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
101 glClearColor(1.0, 1.0, 1.0, 1.0);