[Piglit] [PATCH] ARB_point_parameters: port glean test pointatten to piglit

Timothy Arceri tarceri at itsqueeze.com
Wed Jun 28 23:33:10 UTC 2017


Ping. Any comments on  this?

If not I'll probably push this soon as its one of the bigger bottle 
necks in my piglit runs.

On 21/06/17 10:33, Timothy Arceri wrote:
> ---
>   tests/all.py                                       |   6 +-
>   tests/glean/CMakeLists.gl.txt                      |   1 -
>   tests/glean/tpointatten.cpp                        | 294 ---------------------
>   tests/glean/tpointatten.h                          |  78 ------
>   tests/llvmpipe.py                                  |   1 -
>   tests/spec/CMakeLists.txt                          |   1 +
>   tests/spec/arb_point_parameters/CMakeLists.gl.txt  |  13 +
>   tests/spec/arb_point_parameters/CMakeLists.txt     |   1 +
>   .../spec/arb_point_parameters/point-attenuation.c  | 232 ++++++++++++++++
>   9 files changed, 252 insertions(+), 375 deletions(-)
>   delete mode 100644 tests/glean/tpointatten.cpp
>   delete mode 100644 tests/glean/tpointatten.h
>   create mode 100644 tests/spec/arb_point_parameters/CMakeLists.gl.txt
>   create mode 100644 tests/spec/arb_point_parameters/CMakeLists.txt
>   create mode 100644 tests/spec/arb_point_parameters/point-attenuation.c
> 
> diff --git a/tests/all.py b/tests/all.py
> index f0a7c05..9e19e1f 100644
> --- a/tests/all.py
> +++ b/tests/all.py
> @@ -293,21 +293,20 @@ MSAA_SAMPLE_COUNTS = ['2', '4', '6', '8', '16', '32']
>   
>   with profile.test_list.group_manager(GleanTest, 'glean') as g:
>       g('basic')
>       g('api2')
>       g('makeCurrent')
>       g('bufferObject')
>       g('depthStencil')
>       g('fbo')
>       g('getString')
>       g('pixelFormats')
> -    g('pointAtten')
>       g('pointSprite')
>       # exactRGBA is not included intentionally, because it's too strict and
>       # the equivalent functionality is covered by other tests
>       g('shaderAPI')
>       g('texCombine')
>       g('texCube')
>       g('texEnv')
>       g('texgen')
>       g('texCombine4')
>       g('texture_srgb')
> @@ -2232,20 +2231,25 @@ with profile.test_list.group_manager(
>           grouptools.join('spec', 'ARB_occlusion_query')) as g:
>       g(['occlusion_query'])
>       g(['occlusion_query_conform'])
>       g(['occlusion_query_lifetime'])
>       g(['occlusion_query_meta_fragments'])
>       g(['occlusion_query_meta_no_fragments'])
>       g(['occlusion_query_meta_save'])
>       g(['occlusion_query_order'])
>       g(['gen_delete_while_active'])
>   
> +with profile.test_list.group_manager(
> +        PiglitGLTest,
> +        grouptools.join('spec', 'ARB_point_parameters')) as g:
> +    g(['arb_point_parameters-point-attenuation'])
> +
>   # Group ARB_separate_shader_objects
>   with profile.test_list.group_manager(
>           PiglitGLTest,
>           grouptools.join('spec', 'ARB_separate_shader_objects')) as g:
>       g(['arb_separate_shader_object-ActiveShaderProgram-invalid-program'],
>         'ActiveShaderProgram with invalid program')
>       g(['arb_separate_shader_object-GetProgramPipelineiv'],
>         'GetProgramPipelineiv')
>       g(['arb_separate_shader_object-dlist'], 'Display lists (Compat)')
>       g(['arb_separate_shader_object-IsProgramPipeline'],
> diff --git a/tests/glean/CMakeLists.gl.txt b/tests/glean/CMakeLists.gl.txt
> index 576cde1..9bbf324 100644
> --- a/tests/glean/CMakeLists.gl.txt
> +++ b/tests/glean/CMakeLists.gl.txt
> @@ -28,21 +28,20 @@ piglit_add_executable (glean
>   	rc.cpp
>   	tapi2.cpp
>   	tbasic.cpp
>   	tbinding.cpp
>   	test.cpp
>   	tfbo.cpp
>   	tfragprog1.cpp
>   	tglsl1.cpp
>   	tmultitest.cpp
>   	tpixelformats.cpp
> -	tpointatten.cpp
>   	tpointsprite.cpp
>   	tshaderapi.cpp
>   	ttexcombine.cpp
>   	ttexcombine4.cpp
>   	ttexcube.cpp
>   	ttexenv.cpp
>   	ttexgen.cpp
>   	ttexture_srgb.cpp
>   	ttexunits.cpp
>   	tvertarraybgra.cpp
> diff --git a/tests/glean/tpointatten.cpp b/tests/glean/tpointatten.cpp
> deleted file mode 100644
> index 49d9dac..0000000
> --- a/tests/glean/tpointatten.cpp
> +++ /dev/null
> @@ -1,294 +0,0 @@
> -// BEGIN_COPYRIGHT -*- glean -*-
> -//
> -// Copyright (C) 1999  Allen Akin   All Rights Reserved.
> -//
> -// 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 the rights to use,
> -// copy, modify, merge, publish, distribute, sublicense, 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 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 NONINFRINGEMENT.  IN NO EVENT SHALL ALLEN AKIN 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.
> -//
> -// END_COPYRIGHT
> -
> -// tpointatten.h:  Test GL_ARB_point_parameters extension.
> -// Brian Paul  6 October 2005
> -
> -
> -#include "tpointatten.h"
> -#include <cassert>
> -#include <cmath>
> -
> -
> -namespace GLEAN {
> -
> -// Max tested point size
> -#define MAX_SIZE 24.0
> -
> -
> -/* Clamp X to [MIN,MAX] */
> -#define CLAMP( X, MIN, MAX )  ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) )
> -
> -void
> -PointAttenuationTest::setup(void)
> -{
> -	glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, aliasedLimits);
> -	glGetFloatv(GL_SMOOTH_POINT_SIZE_RANGE, smoothLimits);
> -	glMatrixMode(GL_PROJECTION);
> -	glLoadIdentity();
> -	glOrtho(-10.0, 10.0, -10.0, 10.0, -10.0, 10.0);
> -	glMatrixMode(GL_MODELVIEW);
> -	glLoadIdentity();
> -}
> -
> -
> -void
> -PointAttenuationTest::reportFailure(GLfloat initSize,
> -				    const GLfloat attenuation[3],
> -				    GLfloat min, GLfloat max,
> -				    GLfloat eyeZ, GLboolean smooth,
> -				    GLfloat expected, GLfloat actual) const
> -{
> -	env->log << "\tFAILURE:\n";
> -	env->log << "\tExpected size: " << expected << "  Actual size: " << actual << "\n";
> -	env->log << "\tSize: " << initSize << "\n";
> -	env->log << "\tMin: " << min << "  Max: " << max << "\n";
> -	env->log << "\tAttenuation: " << attenuation[0] << " " << attenuation[1] << " " << attenuation[2] << "\n";
> -	env->log << "\tEye Z: " << eyeZ << "\n";
> -	if (smooth)
> -		env->log << "\tSmooth/antialiased\n";
> -	else
> -		env->log << "\tAliased\n";
> -}
> -
> -
> -void
> -PointAttenuationTest::reportSuccess(int count, GLboolean smooth) const
> -{
> -	env->log << "PASS: " << count;
> -	if (smooth)
> -		env->log << " aliased combinations tested.\n";
> -	else
> -		env->log << " antialiased combinations tested.\n";
> -}
> -
> -
> -// Compute the expected point size given various point state
> -GLfloat
> -PointAttenuationTest::expectedSize(GLfloat initSize,
> -				   const GLfloat attenuation[3],
> -				   GLfloat min, GLfloat max,
> -				   GLfloat eyeZ, GLboolean smooth) const
> -{
> -	const GLfloat dist = fabs(eyeZ);
> -	const GLfloat atten = sqrt(1.0 / (attenuation[0] +
> -					  attenuation[1] * dist +
> -					  attenuation[2] * dist * dist));
> -
> -	float size = initSize * atten;
> -
> -	size = CLAMP(size, min, max);
> -
> -	if (smooth)
> -		size = CLAMP(size, smoothLimits[0], smoothLimits[1]);
> -	else
> -		size = CLAMP(size, aliasedLimits[0], aliasedLimits[1]);
> -	return size;
> -}
> -
> -
> -// measure size of rendered point at yPos (in model coords)
> -GLfloat
> -PointAttenuationTest::measureSize(GLfloat yPos) const
> -{
> -	assert(yPos >= -10.0);
> -	assert(yPos <= 10.0);
> -	float yNdc = (yPos + 10.0) / 20.0;  // See glOrtho above
> -	int x = 0;
> -	int y = (int) (yNdc * windowHeight);
> -	int w = windowWidth;
> -	int h = 3;
> -	GLfloat image[3 * windowWidth * 3]; // three rows of RGB values
> -
> -	// Read three row of pixels and add up colors in each row.
> -	// Use the row with the greatest sum.  This helps gives us a bit
> -	// of leeway in vertical point positioning.
> -	// Colors should be white or shades of gray if smoothing is enabled.
> -	glReadPixels(x, y - 1, w, h, GL_RGB, GL_FLOAT, image);
> -
> -	float sum[3] = { 0.0, 0.0, 0.0 };
> -	for (int j = 0; j < 3; j++) {
> -		for (int i = 0; i < w; i++) {
> -			int k = j * 3 * w + i * 3;
> -			sum[j] += (image[k+0] + image[k+1] + image[k+2]) / 3.0;
> -		}
> -	}
> -
> -	// find max of the row sums
> -	if (sum[0] >= sum[1] && sum[0] >= sum[2])
> -		return sum[0];
> -	else if (sum[1] >= sum[0] && sum[1] >= sum[2])
> -		return sum[1];
> -	else
> -		return sum[2];
> -}
> -
> -
> -bool
> -PointAttenuationTest::testPointRendering(GLboolean smooth)
> -{
> -	// epsilon is the allowed size difference in pixels between the
> -	// expected and actual rendering.
> -	const GLfloat epsilon = (smooth ? 1.5 : 1.0) + 0.0;
> -	GLfloat atten[3];
> -	int count = 0;
> -	unsigned testNo, testStride;
> -
> -	// Enable front buffer if you want to see the rendering
> -	glDrawBuffer(GL_FRONT);
> -	glReadBuffer(GL_FRONT);
> -
> -	if (env->options.quick)
> -		testStride = 5;  // a prime number
> -	else
> -		testStride = 1;
> -	testNo = 0;
> -	printf("stride %u\n", testStride);
> -
> -	if (smooth) {
> -		glEnable(GL_POINT_SMOOTH);
> -		glEnable(GL_BLEND);
> -		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
> -	}
> -	else {
> -		glDisable(GL_POINT_SMOOTH);
> -		glDisable(GL_BLEND);
> -	}
> -
> -	for (int a = 0; a < 3; a++) {
> -		atten[0] = pow(10.0, -a);
> -		for (int b = -2; b < 3; b++) {
> -			atten[1] = (b == -1) ? 0.0 : pow(10.0, -b);
> -			for (int c = -2; c < 3; c++) {
> -				atten[2] = (c == -1) ? 0.0 : pow(10.0, -c);
> -				glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, atten);
> -				for (float min = 1.0; min < MAX_SIZE; min += 10) {
> -					glPointParameterfARB(GL_POINT_SIZE_MIN_ARB, min);
> -					for (float max = min; max < MAX_SIZE; max += 10) {
> -						glPointParameterfARB(GL_POINT_SIZE_MAX_ARB, max);
> -						for (float size = 1.0; size < MAX_SIZE; size += 8) {
> -							glPointSize(size);
> -
> -							testNo++;
> -							if (testNo % testStride != 0) {
> -								// skip this test
> -								continue;
> -							}
> -
> -							// draw column of points
> -							glClear(GL_COLOR_BUFFER_BIT);
> -							glBegin(GL_POINTS);
> -							for (float z = -6.0; z <= 6.0; z += 1.0) {
> -								glVertex3f(0, z, z);
> -							}
> -							glEnd();
> -
> -							// test the column of points
> -							for (float z = -6.0; z <= 6.0; z += 1.0) {
> -								count++;
> -								float expected
> -									= expectedSize(size, atten, min, max,
> -												   z, smooth);
> -								float actual = measureSize(z);
> -								if (fabs(expected - actual) > epsilon) {
> -									reportFailure(size, atten, min, max,
> -												  z, smooth,
> -												  expected, actual);
> -									return false;
> -								}
> -								else if(0){
> -									printf("pass z=%f exp=%f act=%f\n",
> -										   z, expected, actual);
> -								}
> -							}
> -						}
> -					}
> -				}
> -			}
> -		}
> -	}
> -	printf("Tested %u\n", testNo);
> -
> -	reportSuccess(count, smooth);
> -	return true;
> -}
> -
> -void
> -PointAttenuationTest::runOne(BasicResult &r, Window &w)
> -{
> -	(void) w;  // silence warning
> -	r.pass = true;
> -	errorCode = 0;
> -	errorPos = NULL;
> -
> -	setup();
> -
> -	if (r.pass)
> -		r.pass = testPointRendering(GL_FALSE);
> -	if (r.pass)
> -		r.pass = testPointRendering(GL_TRUE);
> -}
> -
> -
> -void
> -PointAttenuationTest::logOne(BasicResult &r)
> -{
> -	if (r.pass) {
> -		logPassFail(r);
> -		logConcise(r);
> -	}
> -}
> -
> -
> -// constructor
> -PointAttenuationTest::PointAttenuationTest(const char *testName,
> -					   const char *filter,
> -					   const char *extensions,
> -					   const char *description)
> -	: BasicTest(testName, filter, extensions, description)
> -{
> -	fWidth  = windowWidth;
> -	fHeight = windowHeight;
> -	errorCode = GL_NO_ERROR;
> -	errorPos = NULL;
> -	for (int i = 0; i < 2; i++) {
> -		aliasedLimits[i] = 0;
> -		smoothLimits[i] = 0;
> -	}
> -}
> -
> -
> -
> -// The test object itself:
> -PointAttenuationTest pointAttenuationTest("pointAtten", "window, rgb",
> -	"GL_ARB_point_parameters",
> -	"Test point size attenuation with the GL_ARB_point_parameters extension.\n");
> -
> -
> -
> -} // namespace GLEAN
> diff --git a/tests/glean/tpointatten.h b/tests/glean/tpointatten.h
> deleted file mode 100644
> index 4592202..0000000
> --- a/tests/glean/tpointatten.h
> +++ /dev/null
> @@ -1,78 +0,0 @@
> -// BEGIN_COPYRIGHT -*- glean -*-
> -//
> -// Copyright (C) 1999  Allen Akin   All Rights Reserved.
> -//
> -// 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 the rights to use,
> -// copy, modify, merge, publish, distribute, sublicense, 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 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 NONINFRINGEMENT.  IN NO EVENT SHALL ALLEN AKIN 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.
> -//
> -// END_COPYRIGHT
> -
> -// tpointatten.h:  Test GL_ARB_point_parameters extension.
> -// Brian Paul  6 October 2005
> -
> -#ifndef __tpointatten_h__
> -#define __tpointatten_h__
> -
> -#include "tbasic.h"
> -
> -namespace GLEAN {
> -
> -#define windowWidth 100
> -#define windowHeight 503   // yes, odd
> -
> -
> -class PointAttenuationTest: public BasicTest
> -{
> -public:
> -	PointAttenuationTest(const char *testName,
> -			     const char *filter,
> -			     const char *extensions,
> -			     const char *description);
> -
> -	virtual void runOne(BasicResult& r, Window& w);
> -	virtual void logOne(BasicResult& r);
> -
> -private:
> -	GLenum errorCode;
> -	const char *errorPos;
> -	GLfloat aliasedLimits[2];  // min/max
> -	GLfloat smoothLimits[2];   // min/max
> -
> -	void setup(void);
> -	bool testPointRendering(GLboolean smooth);
> -	void reportFailure(GLfloat initSize,
> -			   const GLfloat attenuation[3],
> -			   GLfloat min, GLfloat max,
> -			   GLfloat eyeZ, GLboolean smooth,
> -			   GLfloat expected, GLfloat actual) const;
> -	void reportSuccess(int count, GLboolean smooth) const;
> -	GLfloat expectedSize(GLfloat initSize,
> -			     const GLfloat attenuation[3],
> -			     GLfloat min, GLfloat max,
> -			     GLfloat eyeZ, GLboolean smooth) const;
> -	GLfloat measureSize(GLfloat yPos) const;
> -};
> -
> -} // namespace GLEAN
> -
> -#endif // __tpointatten_h__
> -
> diff --git a/tests/llvmpipe.py b/tests/llvmpipe.py
> index 0ebd88b..52168c4 100644
> --- a/tests/llvmpipe.py
> +++ b/tests/llvmpipe.py
> @@ -17,18 +17,17 @@ profile = _profile.copy()  # pylint: disable=invalid-name
>   
>   def remove(key):
>       try:
>           del profile.test_list[key]
>       except KeyError:
>           sys.stderr.write('warning: test %s does not exist\n' % key)
>           sys.stderr.flush()
>   
>   
>   # These take too long or too much memory
> -remove(join('glean', 'pointAtten'))
>   remove(join('glean', 'texCombine'))
>   remove(join('spec', '!OpenGL 1.0', 'gl-1.0-blend-func'))
>   remove(join('spec', '!OpenGL 1.1', 'streaming-texture-leak'))
>   remove(join('spec', '!OpenGL 1.1', 'max-texture-size'))
>   
>   if platform.system() != 'Windows':
>       remove(join('glx', 'glx-multithread-shader-compile'))
> diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
> index dbf0cf1..fea2561 100644
> --- a/tests/spec/CMakeLists.txt
> +++ b/tests/spec/CMakeLists.txt
> @@ -34,20 +34,21 @@ add_subdirectory (arb_gpu_shader5)
>   add_subdirectory (arb_gpu_shader_fp64)
>   add_subdirectory (arb_instanced_arrays)
>   add_subdirectory (arb_internalformat_query)
>   add_subdirectory (arb_internalformat_query2)
>   add_subdirectory (arb_invalidate_subdata)
>   add_subdirectory (arb_map_buffer_alignment)
>   add_subdirectory (arb_map_buffer_range)
>   add_subdirectory (arb_multisample)
>   add_subdirectory (arb_occlusion_query)
>   add_subdirectory (arb_occlusion_query2)
> +add_subdirectory (arb_point_parameters)
>   add_subdirectory (arb_provoking_vertex)
>   add_subdirectory (arb_robustness)
>   add_subdirectory (arb_sample_shading)
>   add_subdirectory (arb_sampler_objects)
>   add_subdirectory (arb_seamless_cube_map)
>   add_subdirectory (amd_seamless_cubemap_per_texture)
>   add_subdirectory (amd_vertex_shader_layer)
>   add_subdirectory (amd_vertex_shader_viewport_index)
>   add_subdirectory (arb_separate_shader_objects)
>   add_subdirectory (arb_shader_subroutine)
> diff --git a/tests/spec/arb_point_parameters/CMakeLists.gl.txt b/tests/spec/arb_point_parameters/CMakeLists.gl.txt
> new file mode 100644
> index 0000000..18b7300
> --- /dev/null
> +++ b/tests/spec/arb_point_parameters/CMakeLists.gl.txt
> @@ -0,0 +1,13 @@
> +include_directories(
> +	${GLEXT_INCLUDE_DIR}
> +	${OPENGL_INCLUDE_PATH}
> +	${piglit_SOURCE_DIR}/tests/util
> +)
> +
> +link_libraries (
> +	piglitutil_${piglit_target_api}
> +	${OPENGL_gl_LIBRARY}
> +)
> +
> +piglit_add_executable (arb_point_parameters-point-attenuation point-attenuation.c)
> +
> diff --git a/tests/spec/arb_point_parameters/CMakeLists.txt b/tests/spec/arb_point_parameters/CMakeLists.txt
> new file mode 100644
> index 0000000..144a306
> --- /dev/null
> +++ b/tests/spec/arb_point_parameters/CMakeLists.txt
> @@ -0,0 +1 @@
> +piglit_include_target_api()
> diff --git a/tests/spec/arb_point_parameters/point-attenuation.c b/tests/spec/arb_point_parameters/point-attenuation.c
> new file mode 100644
> index 0000000..ed77064
> --- /dev/null
> +++ b/tests/spec/arb_point_parameters/point-attenuation.c
> @@ -0,0 +1,232 @@
> +/* Copyright © 2005 Brian Paul
> + *
> + * 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
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * 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 NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS 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 point-attenuation.c
> + *
> + * Test GL_ARB_point_parameters extension.
> + */
> +
> +#include <math.h>
> +
> +#include "piglit-util-gl.h"
> +
> +#define windowWidth 100
> +#define windowHeight 503 /* yes, odd */
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +	config.supports_gl_compat_version = 10;
> +	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
> +	config.window_width = windowWidth;
> +	config.window_height = windowHeight;
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +/* Max tested point size */
> +#define MAX_SIZE 24.0
> +
> +/* Clamp X to [MIN,MAX] */
> +#define CLAMP( X, MIN, MAX )  ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) )
> +
> +GLfloat aliasedLimits[2];  /* min/max */
> +GLfloat smoothLimits[2];   /* min/max */
> +
> +static void
> +reportFailure(GLfloat initSize, const GLfloat attenuation[3],
> +			  GLfloat min, GLfloat max, GLfloat eyeZ,
> +			  GLfloat expected, GLfloat actual)
> +{
> +	fprintf(stderr, "Expected size: %f Actual size: %f\n", expected, actual);
> +	fprintf(stderr, "Size: %f\n", initSize);
> +	fprintf(stderr, "Min: %f Max %f\n", min, max);
> +	fprintf(stderr, "Attenuation %f %f %f\n", attenuation[0] , attenuation[1], attenuation[2]);
> +	fprintf(stderr, "Eye Z: %f\n", eyeZ);
> +}
> +
> +
> +/* Compute the expected point size given various point state */
> +static GLfloat
> +expectedSize(GLfloat initSize,
> +			 const GLfloat attenuation[3],
> +			 GLfloat min, GLfloat max,
> +			 GLfloat eyeZ, GLboolean smooth)
> +{
> +	const GLfloat dist = fabs(eyeZ);
> +	const GLfloat atten = sqrt(1.0 / (attenuation[0] +
> +					  attenuation[1] * dist +
> +					  attenuation[2] * dist * dist));
> +
> +	float size = initSize * atten;
> +
> +	size = CLAMP(size, min, max);
> +
> +	if (smooth)
> +		size = CLAMP(size, smoothLimits[0], smoothLimits[1]);
> +	else
> +		size = CLAMP(size, aliasedLimits[0], aliasedLimits[1]);
> +	return size;
> +}
> +
> +
> +/* measure size of rendered point at yPos (in model coords) */
> +static GLfloat
> +measureSize(GLfloat yPos)
> +{
> +	assert(yPos >= -10.0);
> +	assert(yPos <= 10.0);
> +	float yNdc = (yPos + 10.0) / 20.0;  /* See glOrtho above */
> +	int x = 0;
> +	int y = (int) (yNdc * windowHeight);
> +	int w = windowWidth;
> +	int h = 3;
> +	GLfloat image[3 * windowWidth * 3]; /* three rows of RGB values */
> +
> +	/* Read three row of pixels and add up colors in each row.
> +	 * Use the row with the greatest sum.  This helps gives us a bit
> +	 * of leeway in vertical point positioning.
> +	 * Colors should be white or shades of gray if smoothing is enabled.
> +     */
> +	glReadPixels(x, y - 1, w, h, GL_RGB, GL_FLOAT, image);
> +
> +	float sum[3] = { 0.0, 0.0, 0.0 };
> +	for (int j = 0; j < 3; j++) {
> +		for (int i = 0; i < w; i++) {
> +			int k = j * 3 * w + i * 3;
> +			sum[j] += (image[k+0] + image[k+1] + image[k+2]) / 3.0;
> +		}
> +	}
> +
> +	/* find max of the row sums */
> +	if (sum[0] >= sum[1] && sum[0] >= sum[2])
> +		return sum[0];
> +	else if (sum[1] >= sum[0] && sum[1] >= sum[2])
> +		return sum[1];
> +	else
> +		return sum[2];
> +}
> +
> +
> +static bool
> +testPointRendering(bool smooth)
> +{
> +	/* epsilon is the allowed size difference in pixels between the
> +	 * expected and actual rendering.
> +     */
> +	const GLfloat epsilon = (smooth ? 1.5 : 1.0) + 0.0;
> +	GLfloat atten[3];
> +
> +	if (smooth) {
> +		glEnable(GL_POINT_SMOOTH);
> +		glEnable(GL_BLEND);
> +		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
> +	}
> +	else {
> +		glDisable(GL_POINT_SMOOTH);
> +		glDisable(GL_BLEND);
> +	}
> +
> +	for (int a = 0; a < 3; a++) {
> +		atten[0] = pow(10.0, -a);
> +		for (int b = -2; b < 3; b++) {
> +			atten[1] = (b == -1) ? 0.0 : pow(10.0, -b);
> +			for (int c = -2; c < 3; c++) {
> +				atten[2] = (c == -1) ? 0.0 : pow(10.0, -c);
> +				glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, atten);
> +				for (float min = 1.0; min < MAX_SIZE; min += 10) {
> +					glPointParameterfARB(GL_POINT_SIZE_MIN_ARB, min);
> +					for (float max = min; max < MAX_SIZE; max += 10) {
> +						glPointParameterfARB(GL_POINT_SIZE_MAX_ARB, max);
> +						for (float size = 1.0; size < MAX_SIZE; size += 8) {
> +							glPointSize(size);
> +
> +							/* draw column of points */
> +							glClear(GL_COLOR_BUFFER_BIT);
> +							glBegin(GL_POINTS);
> +							for (float z = -6.0; z <= 6.0; z += 1.0) {
> +								glVertex3f(0, z, z);
> +							}
> +							glEnd();
> +
> +							/* test the column of points */
> +							for (float z = -6.0; z <= 6.0; z += 1.0) {
> +								float expected
> +									= expectedSize(size, atten, min, max,
> +												   z, smooth);
> +								float actual = measureSize(z);
> +								if (fabs(expected - actual) > epsilon) {
> +									reportFailure(size, atten, min, max,
> +												  z, expected, actual);
> +									return false;
> +								}
> +								else if(0){
> +									printf("pass z=%f exp=%f act=%f\n",
> +										   z, expected, actual);
> +								}
> +							}
> +						}
> +					}
> +				}
> +			}
> +		}
> +	}
> +
> +	if (!piglit_check_gl_error(0))
> +		return false;
> +
> +	return true;
> +}
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +	bool smooth = false;
> +	bool pass = testPointRendering(smooth);
> +	piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
> +			"Antialiased combinations");
> +
> +	smooth = true;
> +	bool pass2 = testPointRendering(smooth) && pass;
> +	piglit_report_subtest_result(pass2 ? PIGLIT_PASS : PIGLIT_FAIL,
> +			"Aliased combinations");
> +
> +	return pass && pass2 ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> +	piglit_require_extension("GL_ARB_point_parameters");
> +
> +	for (int i = 0; i < 2; i++) {
> +		aliasedLimits[i] = 0;
> +		smoothLimits[i] = 0;
> +	}
> +
> +	glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, aliasedLimits);
> +	glGetFloatv(GL_SMOOTH_POINT_SIZE_RANGE, smoothLimits);
> +	glMatrixMode(GL_PROJECTION);
> +	glLoadIdentity();
> +	glOrtho(-10.0, 10.0, -10.0, 10.0, -10.0, 10.0);
> +	glMatrixMode(GL_MODELVIEW);
> +	glLoadIdentity();
> +
> +	if (!piglit_check_gl_error(0))
> +		piglit_report_result(PIGLIT_FAIL);
> +}
> 


More information about the Piglit mailing list