1 // BEGIN_COPYRIGHT -*- glean -*-
3 // Copyright (C) 1999 Allen Akin All Rights Reserved.
5 // Permission is hereby granted, free of charge, to any person
6 // obtaining a copy of this software and associated documentation
7 // files (the "Software"), to deal in the Software without
8 // restriction, including without limitation the rights to use,
9 // copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 // KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
21 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ALLEN AKIN BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 // AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 // DEALINGS IN THE SOFTWARE.
29 // tpointatten.h: Test GL_ARB_point_parameters extension.
30 // Brian Paul 6 October 2005
33 #include "tpointatten.h"
40 // Max tested point size
44 /* Clamp X to [MIN,MAX] */
45 #define CLAMP( X, MIN, MAX ) ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) )
48 static PFNGLPOINTPARAMETERFVARBPROC PointParameterfvARB
= NULL
;
49 static PFNGLPOINTPARAMETERFARBPROC PointParameterfARB
= NULL
;
53 PointAttenuationTest::setup(void)
55 PointParameterfvARB
= (PFNGLPOINTPARAMETERFVARBPROC
)
56 GLUtils::getProcAddress("glPointParameterfvARB");
57 assert(PointParameterfvARB
);
58 PointParameterfARB
= (PFNGLPOINTPARAMETERFARBPROC
)
59 GLUtils::getProcAddress("glPointParameterfARB");
60 assert(PointParameterfARB
);
62 glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE
, aliasedLimits
);
63 glGetFloatv(GL_SMOOTH_POINT_SIZE_RANGE
, smoothLimits
);
64 glMatrixMode(GL_PROJECTION
);
66 glOrtho(-10.0, 10.0, -10.0, 10.0, -10.0, 10.0);
67 glMatrixMode(GL_MODELVIEW
);
73 PointAttenuationTest::reportFailure(GLfloat initSize
,
74 const GLfloat attenuation
[3],
75 GLfloat min
, GLfloat max
,
76 GLfloat eyeZ
, GLboolean smooth
,
77 GLfloat expected
, GLfloat actual
) const
79 env
->log
<< "\tFAILURE:\n";
80 env
->log
<< "\tExpected size: " << expected
<< " Actual size: " << actual
<< "\n";
81 env
->log
<< "\tSize: " << initSize
<< "\n";
82 env
->log
<< "\tMin: " << min
<< " Max: " << max
<< "\n";
83 env
->log
<< "\tAttenuation: " << attenuation
[0] << " " << attenuation
[1] << " " << attenuation
[2] << "\n";
84 env
->log
<< "\tEye Z: " << eyeZ
<< "\n";
86 env
->log
<< "\tSmooth/antialiased\n";
88 env
->log
<< "\tAliased\n";
93 PointAttenuationTest::reportSuccess(int count
, GLboolean smooth
) const
95 env
->log
<< "PASS: " << count
;
97 env
->log
<< " aliased combinations tested.\n";
99 env
->log
<< " antialiased combinations tested.\n";
103 // Compute the expected point size given various point state
105 PointAttenuationTest::expectedSize(GLfloat initSize
,
106 const GLfloat attenuation
[3],
107 GLfloat min
, GLfloat max
,
108 GLfloat eyeZ
, GLboolean smooth
) const
110 const GLfloat dist
= fabs(eyeZ
);
111 const GLfloat atten
= sqrt(1.0 / (attenuation
[0] +
112 attenuation
[1] * dist
+
113 attenuation
[2] * dist
* dist
));
115 float size
= initSize
* atten
;
117 size
= CLAMP(size
, min
, max
);
120 size
= CLAMP(size
, smoothLimits
[0], smoothLimits
[1]);
122 size
= CLAMP(size
, aliasedLimits
[0], aliasedLimits
[1]);
127 // measure size of rendered point at yPos (in model coords)
129 PointAttenuationTest::measureSize(GLfloat yPos
) const
131 assert(yPos
>= -10.0);
132 assert(yPos
<= 10.0);
133 float yNdc
= (yPos
+ 10.0) / 20.0; // See glOrtho above
135 int y
= (int) (yNdc
* windowHeight
);
138 GLfloat image
[windowWidth
* 3];
139 // Read row of pixels and add up colors, which should be white
140 // or shades of gray if smoothing is enabled.
141 glReadPixels(x
, y
, w
, h
, GL_RGB
, GL_FLOAT
, image
);
143 for (int i
= 0; i
< w
; i
++) {
144 sum
+= (image
[i
*3+0] + image
[i
*3+1] + image
[i
*3+2]) / 3.0;
151 PointAttenuationTest::testPointRendering(GLboolean smooth
)
153 // epsilon is the allowed size difference in pixels between the
154 // expected and actual rendering.
155 const GLfloat epsilon
= smooth
? 1.5 : 1.0;
159 // Enable front buffer if you want to see the rendering
160 //glDrawBuffer(GL_FRONT);
161 //glReadBuffer(GL_FRONT);
164 glEnable(GL_POINT_SMOOTH
);
166 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
169 glDisable(GL_POINT_SMOOTH
);
173 for (int a
= 0; a
< 3; a
++) {
174 atten
[0] = pow(10.0, -a
);
175 for (int b
= -2; b
< 3; b
++) {
176 atten
[1] = (b
== -1) ? 0.0 : pow(10.0, -b
);
177 for (int c
= -2; c
< 3; c
++) {
178 atten
[2] = (c
== -1) ? 0.0 : pow(10.0, -c
);
179 PointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB
, atten
);
180 for (float min
= 1.0; min
< MAX_SIZE
; min
+= 5) {
181 PointParameterfARB(GL_POINT_SIZE_MIN_ARB
, min
);
182 for (float max
= min
; max
< MAX_SIZE
; max
+= 5) {
183 PointParameterfARB(GL_POINT_SIZE_MAX_ARB
, max
);
184 for (float size
= 1.0; size
< MAX_SIZE
; size
+= 4) {
187 // draw column of points
188 glClear(GL_COLOR_BUFFER_BIT
);
190 for (float z
= -6.0; z
<= 6.0; z
+= 1.0) {
195 // test the column of points
196 for (float z
= -6.0; z
<= 6.0; z
+= 1.0) {
199 = expectedSize(size
, atten
, min
, max
,
201 float actual
= measureSize(z
);
202 if (fabs(expected
- actual
) > epsilon
) {
203 reportFailure(size
, atten
, min
, max
,
215 reportSuccess(count
, smooth
);
220 PointAttenuationTest::runOne(BasicResult
&r
, Window
&w
)
222 (void) w
; // silence warning
230 r
.pass
= testPointRendering(GL_FALSE
);
232 r
.pass
= testPointRendering(GL_TRUE
);
237 PointAttenuationTest::logOne(BasicResult
&r
)
247 PointAttenuationTest::PointAttenuationTest(const char *testName
,
249 const char *extensions
,
250 const char *description
)
251 : BasicTest(testName
, filter
, extensions
, description
)
253 fWidth
= windowWidth
;
254 fHeight
= windowHeight
;
259 // The test object itself:
260 PointAttenuationTest
pointAttenuationTest("pointAtten", "window, rgb",
261 "GL_ARB_point_parameters",
262 "Test point size attenuation with the GL_ARB_point_parameters extension.\n");