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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
/*
* Copyright (c) 2010 VMware, Inc.
*
* 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 THE AUTHORS OR COYPRIGTH
* HOLDERS 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 drawing a textured triangle. This is to test a Mesa/Gallium
* LLVMpipe crash which only seems to happen when SSE4.1 is not used.
*/
#include "piglit-util-gl-common.h"
PIGLIT_GL_TEST_MAIN(
400 /*window_width*/,
400 /*window_height*/,
GLUT_RGB | GLUT_DOUBLE)
static void
make_texture(void)
{
GLubyte image[64][64][3];
int i, j, size;
for (i = 0; i < 64; i++) {
for (j = 0; j < 64; j++) {
image[i][j][0] = 255;
image[i][j][1] = 0;
image[i][j][2] = 0;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
i = 0;
size = 64;
while (size) {
glTexImage2D(GL_TEXTURE_2D, i, GL_RGB, size, size, 0,
GL_RGB, GL_UNSIGNED_BYTE, image);
size /= 2;
i++;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_LINEAR);
glEnable(GL_TEXTURE_2D);
}
enum piglit_result
piglit_display(void)
{
/*
* Simply draw a textured tri. The texture is solid red.
* The tri is clipped.
*/
static const GLfloat v[3][4] = {
{ 10.0, 10.0, 0.0, 1.0 },
{ 10.0, 1.0, 0.0, 1.0 },
{ 1.0, 1.0, 0.0, 1.0 },
};
static const GLfloat t[3][2] = {
{ 0, 0 },
{ 1, 0 },
{ 1, 1 }
};
static const GLfloat red[4] = { 1, 0, 0, 1 };
enum piglit_result result;
make_texture();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glTexCoord2fv(t[0]); glVertex4fv(v[0]);
glTexCoord2fv(t[1]); glVertex4fv(v[1]);
glTexCoord2fv(t[2]); glVertex4fv(v[2]);
glEnd();
if (piglit_probe_pixel_rgb(piglit_width-5, piglit_height-20, red))
result = PIGLIT_PASS;
else
result = PIGLIT_FAIL;
piglit_present_results();
return result;
}
static void
reshape(int width, int height)
{
piglit_width = width;
piglit_height = height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 50.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -25.0);
}
void
piglit_init(int argc, char **argv)
{
glutReshapeFunc(reshape);
reshape(piglit_width, piglit_height);
}
|