Beispiel #1
0
bool 
TexgenTest::verifyCheckers(GLfloat* pixels, GLfloat* upperLeftColor, GLfloat* upperRightColor, std::string& failureInfo) const {
    
    // My loop   control variable, since gcc and MSVC do things differently.
    GLint samp;
    
    // It's a viewSize x viewSize pixel block; since we drew a sphere that doesn't quite touch the 
	// edges, we need to be careful not to sample from what should be background.
	// These pairs are hand-picked coordinates on the image that fall on the bottom-left quadrant
	// of the sphere.
	// XXX FIX ME: these sample coordinates assume that viewSize == 50.
    GLuint samples[6][2] = {{13,13}, {4,22}, {22,4}, {20,20}, {20,10}, {10,20}};
    
    // Run through those sample points in the bottom-left corner and make sure they're all the right color.
	for (samp=0; samp<6; samp++)
	{
        GLuint sampleOffset = (samples[samp][0] + (viewSize*samples[samp][1]))*3;
        if (!compareColors(upperRightColor, pixels + sampleOffset, failureInfo))
        {
            return false;
        }
	}
    
    // Run through those sample points in the bottom-right corner and make sure they're all the right color.
	// Note the "viewSize - samples[samp][0]" to flip it to the bottom-right quadrant.
	for (samp=0; samp<6; samp++)
	{
        GLuint sampleOffset = ((viewSize - samples[samp][0]) + (viewSize*samples[samp][1]))*3;
        if (!compareColors(upperLeftColor, pixels + sampleOffset, failureInfo))
        {
            return false;
        }
	}
    
    // Run through those sample points in the upper-right corner and make sure they're all the right color.
	for (samp=0; samp<6; samp++)
	{
        GLuint sampleOffset = ((viewSize - samples[samp][0]) + (viewSize*(viewSize - samples[samp][1])))*3;
        if (!compareColors(upperRightColor, pixels + sampleOffset, failureInfo))
        {
            return false;
        }
	}
    
    // Run through those sample points in the upper-left corner and make sure they're all the right color.
	for (samp=0; samp<6; samp++)
	{
        GLuint sampleOffset = (samples[samp][0] + (viewSize*(viewSize - samples[samp][1])))*3;
        if (!compareColors(upperLeftColor, pixels + sampleOffset, failureInfo))
        {
            return false;
        }
	}
    
	return true;
}
static float compareToNeighbor (const FuzzyCompareParams& params, de::Random& rnd, deUint32 pixel, const ConstPixelBufferAccess& surface, int x, int y)
{
	float minErr = +100.f;

	// (x, y) + (0, 0)
	minErr = deFloatMin(minErr, compareColors(pixel, readUnorm8<NumChannels>(surface, x, y), params.minErrThreshold));
	if (minErr == 0.0f)
		return minErr;

	// Area around (x, y)
	static const int s_coords[][2] =
	{
		{-1, -1},
		{ 0, -1},
		{+1, -1},
		{-1,  0},
		{+1,  0},
		{-1, +1},
		{ 0, +1},
		{+1, +1}
	};

	for (int d = 0; d < (int)DE_LENGTH_OF_ARRAY(s_coords); d++)
	{
		int dx = x + s_coords[d][0];
		int dy = y + s_coords[d][1];

		if (!deInBounds32(dx, 0, surface.getWidth()) || !deInBounds32(dy, 0, surface.getHeight()))
			continue;

		minErr = deFloatMin(minErr, compareColors(pixel, readUnorm8<NumChannels>(surface, dx, dy), params.minErrThreshold));
		if (minErr == 0.0f)
			return minErr;
	}

	// Random bilinear-interpolated samples around (x, y)
	for (int s = 0; s < 32; s++)
	{
		float dx = (float)x + rnd.getFloat()*2.0f - 0.5f;
		float dy = (float)y + rnd.getFloat()*2.0f - 0.5f;

		deUint32 sample = bilinearSample<NumChannels>(surface, dx, dy);

		minErr = deFloatMin(minErr, compareColors(pixel, sample, params.minErrThreshold));
		if (minErr == 0.0f)
			return minErr;
	}

	return minErr;
}