Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Mesa
piglit
Commits
a0710e2a
Commit
a0710e2a
authored
Jul 12, 2008
by
Nicolai Hähnle
Browse files
New test: general/linestipple
parent
0aaf624a
Changes
3
Hide whitespace changes
Inline
Side-by-side
tests/all.tests
View file @
a0710e2a
...
...
@@ -55,6 +55,7 @@ mesa = Group()
mesa
[
'crossbar'
]
=
PlainExecTest
([
testBinDir
+
'crossbar'
,
'-auto'
])
general
=
Group
()
general
[
'linestipple'
]
=
PlainExecTest
([
testBinDir
+
'linestipple'
,
'-auto'
])
general
[
'texgen'
]
=
PlainExecTest
([
testBinDir
+
'texgen'
,
'-auto'
])
shaders
=
Group
()
...
...
tests/general/CMakeLists.txt
View file @
a0710e2a
...
...
@@ -18,4 +18,5 @@ link_libraries (
piglitutil
)
add_executable
(
linestipple linestipple.c
)
add_executable
(
texgen texgen.c
)
tests/general/linestipple.c
0 → 100644
View file @
a0710e2a
/*
* 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 basic line stippling functionality.
*/
#include
<assert.h>
#include
<string.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<math.h>
#include
<GL/glut.h>
#include
"piglit-util.h"
static
int
Width
=
128
,
Height
=
128
;
static
int
Automatic
=
0
;
static
int
CurrentTest
=
0
;
static
void
probe_pixel
(
int
x
,
int
y
,
const
float
*
expected
)
{
if
(
!
piglit_probe_pixel_rgb
(
x
,
y
,
expected
))
{
if
(
Automatic
)
piglit_report_result
(
PIGLIT_FAILURE
);
}
}
struct
vertex
{
GLuint
x
;
GLuint
y
;
};
struct
stipple_line
{
GLint
factor
;
GLuint
pattern
;
GLfloat
color
[
3
];
GLuint
primitive
;
GLuint
nvertices
;
struct
vertex
*
vertices
;
};
static
const
int
basex
=
10
;
static
const
int
basey
=
10
;
static
float
background
[
3
]
=
{
0
,
0
,
0
};
/**
* @note Only horizontal and vertical lines supported right now.
*/
static
GLuint
probe_line
(
const
struct
stipple_line
*
line
,
const
struct
vertex
*
v1
,
const
struct
vertex
*
v2
,
GLuint
fragment
)
{
int
x
=
v1
->
x
;
int
y
=
v1
->
y
;
int
length
,
dx
=
0
,
dy
=
0
;
if
(
v2
->
x
!=
v1
->
x
)
{
if
(
v2
->
x
>
v1
->
x
)
dx
=
1
;
else
dx
=
-
1
;
length
=
(
v2
->
x
-
v1
->
x
)
*
dx
;
}
else
{
if
(
v2
->
y
>
v1
->
y
)
dy
=
1
;
else
dy
=
-
1
;
length
=
(
v2
->
y
-
v1
->
y
)
*
dy
;
}
while
(
length
)
{
GLuint
s
=
(
fragment
/
line
->
factor
)
&
15
;
if
(
line
->
pattern
&
(
1
<<
s
))
probe_pixel
(
basex
+
x
,
basey
+
y
,
line
->
color
);
else
probe_pixel
(
basex
+
x
,
basey
+
y
,
background
);
length
--
;
fragment
++
;
x
+=
dx
;
y
+=
dy
;
}
return
fragment
;
}
static
void
test_line
(
const
struct
stipple_line
*
line
)
{
GLuint
i
;
glLineStipple
(
line
->
factor
,
line
->
pattern
);
glColor3f
(
line
->
color
[
0
],
line
->
color
[
1
],
line
->
color
[
2
]);
glBegin
(
line
->
primitive
);
for
(
i
=
0
;
i
<
line
->
nvertices
;
++
i
)
glVertex2f
(
line
->
vertices
[
i
].
x
+
0
.
5
,
line
->
vertices
[
i
].
y
+
0
.
5
);
glEnd
();
glReadBuffer
(
GL_BACK
);
if
(
line
->
primitive
==
GL_LINES
)
{
for
(
i
=
0
;
i
+
1
<
line
->
nvertices
;
i
+=
2
)
probe_line
(
line
,
&
line
->
vertices
[
i
],
&
line
->
vertices
[
i
+
1
],
0
);
}
else
{
GLuint
fragment
=
0
;
for
(
i
=
0
;
i
+
1
<
line
->
nvertices
;
++
i
)
fragment
=
probe_line
(
line
,
&
line
->
vertices
[
i
],
&
line
->
vertices
[
i
+
1
],
fragment
);
if
(
line
->
primitive
==
GL_LINE_LOOP
)
probe_line
(
line
,
&
line
->
vertices
[
i
],
&
line
->
vertices
[
0
],
fragment
);
}
}
static
struct
vertex
BaselineVertices
[]
=
{
{
0
,
0
},
{
24
,
0
}
};
static
struct
vertex
RestartVertices
[]
=
{
{
0
,
2
},
{
24
,
2
},
{
0
,
4
},
{
24
,
4
}
};
static
struct
vertex
LinestripVertices
[]
=
{
{
0
,
6
},
{
24
,
6
},
{
24
,
30
}
};
static
struct
vertex
LineloopVertices
[]
=
{
{
26
,
0
},
{
46
,
0
},
{
46
,
20
},
{
26
,
20
}
};
static
struct
vertex
Factor2Vertices
[]
=
{
{
0
,
32
},
{
32
,
32
},
{
32
,
33
},
{
0
,
33
}
};
static
struct
vertex
Factor3Vertices
[]
=
{
{
0
,
35
},
{
63
,
35
},
{
63
,
36
},
{
0
,
36
}
};
static
struct
stipple_line
Lines
[]
=
{
{
/* Baseline */
1
,
0xffff
,
{
1
.
0
,
1
.
0
,
1
.
0
},
GL_LINES
,
2
,
BaselineVertices
},
{
/* Restarting lines within a single Begin/End block */
1
,
0x00ff
,
{
1
.
0
,
0
.
0
,
0
.
0
},
GL_LINES
,
4
,
RestartVertices
},
{
/* Line strip */
1
,
0x0f8f
,
{
1
.
0
,
1
.
0
,
0
.
0
},
GL_LINE_STRIP
,
3
,
LinestripVertices
},
{
/* Line loop */
1
,
0x8cef
,
{
0
.
0
,
1
.
0
,
0
.
0
},
GL_LINE_LOOP
,
4
,
LineloopVertices
},
{
/* Factor 2x */
2
,
0x838f
,
{
0
.
0
,
0
.
0
,
1
.
0
},
GL_LINE_LOOP
,
4
,
Factor2Vertices
},
{
/* Factor 3x */
3
,
0xf731
,
{
0
.
0
,
1
.
0
,
1
.
0
},
GL_LINE_LOOP
,
4
,
Factor3Vertices
}
};
static
void
test
()
{
int
i
;
glClearColor
(
0
.
0
,
0
.
0
,
0
.
0
,
1
.
0
);
glClear
(
GL_COLOR_BUFFER_BIT
);
glEnable
(
GL_LINE_STIPPLE
);
glPushMatrix
();
glTranslatef
(
basex
,
basey
,
0
.
0
);
for
(
i
=
0
;
i
<
sizeof
(
Lines
)
/
sizeof
(
Lines
[
0
]);
++
i
)
test_line
(
&
Lines
[
i
]);
glPopMatrix
();
glutSwapBuffers
();
}
static
void
Redisplay
(
void
)
{
test
();
if
(
Automatic
)
piglit_report_result
(
PIGLIT_SUCCESS
);
}
static
void
Reshape
(
int
width
,
int
height
)
{
Width
=
width
;
Height
=
height
;
glViewport
(
0
,
0
,
width
,
height
);
glMatrixMode
(
GL_PROJECTION
);
glLoadIdentity
();
glOrtho
(
0
.
0
,
width
,
0
.
0
,
height
,
-
1
.
0
,
1
.
0
);
glMatrixMode
(
GL_MODELVIEW
);
glLoadIdentity
();
}
static
void
Init
(
void
)
{
Reshape
(
Width
,
Height
);
}
static
void
Key
(
unsigned
char
key
,
int
x
,
int
y
)
{
(
void
)
x
;
(
void
)
y
;
switch
(
key
)
{
case
27
:
exit
(
0
);
break
;
}
glutPostRedisplay
();
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
i
;
glutInit
(
&
argc
,
argv
);
if
(
argc
==
2
&&
!
strcmp
(
argv
[
1
],
"-auto"
))
Automatic
=
1
;
glutInitWindowPosition
(
0
,
0
);
glutInitWindowSize
(
Width
,
Height
);
glutInitDisplayMode
(
GLUT_RGB
|
GLUT_DOUBLE
);
glutCreateWindow
(
argv
[
0
]);
glutReshapeFunc
(
Reshape
);
glutDisplayFunc
(
Redisplay
);
if
(
!
Automatic
)
glutKeyboardFunc
(
Key
);
Init
();
glutMainLoop
();
return
0
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment