summaryrefslogtreecommitdiff
path: root/tests/bugs/tex1d-2dborder.c
blob: 881ab4709d9a85333ad05819ef68429415f33639 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
 * Copyright (c) The Piglit project 2008
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * on the rights to use, copy, modify, merge, publish, distribute, sub
 * license, and/or sell copies of the Software, and to permit persons to whom
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
 * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

/**
 * @file
 * Test whether 1D textures correctly ignore the T coordinate wrap mode.
 *
 * Since 1D textures are genuine one-dimensional objects, the T coordinate
 * shouldn't affect them at all. However, R300 simulates them as flat
 * 2D textures, which caused incorrect sampling of border colors.
 */

#include "piglit-util.h"
#include "piglit-framework.h"

int piglit_width = 256, piglit_height = 128;
int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;

static const GLfloat TextureColor[3] = { 1.0, 0.5, 0.0 };


static GLboolean test(GLenum wrapt, int cellx, int celly)
{
	int sx, sy;

	glPushMatrix();
	glTranslatef(cellx*0.25, celly*0.5, 0.0);
	glScalef(0.25, 0.5, 1.0);
	glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, wrapt);
	glBegin(GL_QUADS);
		glTexCoord2f(0, 0); glVertex2f(0, 0);
		glTexCoord2f(1, 0); glVertex2f(1, 0);
		glTexCoord2f(1, 1); glVertex2f(1, 1);
		glTexCoord2f(0, 1); glVertex2f(0, 1);
	glEnd();
	glPopMatrix();

	glReadBuffer(GL_BACK);

	/* Take more than one sample, just to be sure */
	for(sy = 0; sy < 4; ++sy) {
		for(sx = 0; sx < 4; ++sx) {
			int x = (cellx*5 + sx + 1)*piglit_width/20;
			int y = (celly*5 + sy + 1)*piglit_height/10;

			if (!piglit_probe_pixel_rgb(x, y, TextureColor)) {
				fprintf(stderr, "Fail in cell %i,%i (texwrap = 0x%x)\n", cellx, celly, wrapt);

				return GL_FALSE;
			}
		}
	}

	return GL_TRUE;
}

enum piglit_result
piglit_display(void)
{
	GLboolean pass = GL_TRUE;

	glClearColor(0.5, 0.5, 0.5, 1.0);
	glClear(GL_COLOR_BUFFER_BIT);

        /* Draw eight tiles, each with a different tex wrap mode.
         * They should all look the same.
         */
	pass &= test(GL_REPEAT, 0, 0);
	pass &= test(GL_CLAMP, 1, 0);
	pass &= test(GL_CLAMP_TO_EDGE, 2, 0);
	pass &= test(GL_CLAMP_TO_BORDER, 3, 0);
	pass &= test(GL_MIRRORED_REPEAT, 0, 1);
	if (piglit_is_extension_supported("GL_EXT_texture_mirror_clamp")) {
		pass &= test(GL_MIRROR_CLAMP_EXT, 1, 1);
		pass &= test(GL_MIRROR_CLAMP_TO_EDGE_EXT, 2, 1);
		pass &= test(GL_MIRROR_CLAMP_TO_BORDER_EXT, 3, 1);
	}

	glutSwapBuffers();

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}

void piglit_init(int argc, char **argv)
{
	(void) argc;
	(void) argv;

	glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, 1, 0, GL_RGB, GL_FLOAT, TextureColor);
	glEnable(GL_TEXTURE_1D);

	piglit_ortho_projection(1.0, 1.0, GL_FALSE);

	if (!piglit_automatic)
		printf("You should see a flat orange color\n");
}