Пример #1
0
void
_mesa_fetch_texel_2d_f_srgba_dxt5(const struct gl_texture_image *texImage,
                                  GLint i, GLint j, GLint k, GLfloat *texel)
{
   /* just sample as GLchan and convert to float here */
   GLchan rgba[4];
   fetch_texel_2d_rgba_dxt5(texImage, i, j, k, rgba);
   texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]);
   texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]);
   texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]);
   texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
}
Пример #2
0
void
_mesa_fetch_texel_srgba_dxt3(const struct swrast_texture_image *texImage,
                             GLint i, GLint j, GLint k, GLfloat *texel)
{
   /* just sample as GLubyte and convert to float here */
   GLubyte rgba[4];
   fetch_texel_2d_rgba_dxt3(texImage, i, j, k, rgba);
   texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]);
   texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]);
   texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]);
   texel[ACOMP] = UBYTE_TO_FLOAT(rgba[ACOMP]);
}
Пример #3
0
static GLboolean
srgb_tex_test(int srgb_format)
{
	GLboolean pass = GL_TRUE;
	float green[] = {0, 0.3, 0.0, 0};
	float expected_green[4];
	float expected_srgb_green[4];
	GLuint tex;
	GLboolean have_decode;

	have_decode = piglit_is_extension_supported("GL_EXT_texture_sRGB_decode");

	glGenTextures(1, &tex);

	glBindTexture(GL_TEXTURE_2D, tex);

	fill_level(0, green);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
			GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
			GL_NEAREST);

	glClearColor(0.0, 0.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);
	glEnable(GL_TEXTURE_2D);
	piglit_draw_rect_tex(0, 0, 20, 20, 0, 0, 1, 1);

	if (have_decode) {
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SRGB_DECODE_EXT,
				GL_SKIP_DECODE_EXT);

		piglit_draw_rect_tex(20, 0, 20, 20, 0, 0, 1, 1);

		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SRGB_DECODE_EXT,
				GL_DECODE_EXT);

		piglit_draw_rect_tex(40, 0, 20, 20, 0, 0, 1, 1);
	}

	memcpy(expected_green, green, sizeof(float) * 4);
	memcpy(expected_srgb_green, green, sizeof(float) * 4);
	expected_srgb_green[1] = nonlinear_to_linear(255.0*green[1]);

	if (!piglit_probe_rect_rgb(0, 0, 20, 20, expected_srgb_green))
		pass = GL_FALSE;

	if (have_decode) {

		if (!piglit_probe_rect_rgb(20, 0, 20, 20, expected_green))
			pass = GL_FALSE;

		if (!piglit_probe_rect_rgb(40, 0, 20, 20, expected_srgb_green))
			pass = GL_FALSE;
	}


	glDeleteTextures(1, &tex);
	piglit_present_results();

	return pass;
}
Пример #4
0
bool
TextureSRGBTest::testTextureFormat(GLenum intFormat, GLint components,
				   GLEAN::Environment &env)
{
	const GLubyte *image = randomArray(128 * 128 * 4, intFormat);
	GLfloat readback[128 * 128 * 4];
        int i;
	GLint redBits, alphaBits;

	glGetIntegerv(GL_RED_BITS, &redBits);
	glGetIntegerv(GL_ALPHA_BITS, &alphaBits);
	const float tolerance = 1.0 / ((1 << (redBits - 1)) - 1);

	// setup matrices
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glViewport(0, 0, windowSize, windowSize);

	// setup texture
	glTexImage2D(GL_TEXTURE_2D, 0, intFormat, 128, 128, 0,
		     GL_RGBA, GL_UNSIGNED_BYTE, image);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	glEnable(GL_TEXTURE_2D);

	glDisable(GL_DITHER);

	glDrawBuffer(GL_FRONT);
	glReadBuffer(GL_FRONT);

	// draw test polygon
	glBegin(GL_POLYGON);
	glTexCoord2f(0, 0);  glVertex2f(-1, -1);
	glTexCoord2f(1, 0);  glVertex2f( 1, -1);
	glTexCoord2f(1, 1);  glVertex2f( 1,  1);
	glTexCoord2f(0, 1);  glVertex2f(-1,  1);
	glEnd();

	glReadPixels(0, 0, windowSize, windowSize,
		     GL_RGBA, GL_FLOAT, readback);

	// compare rendered results to expected values
	for (i = 0; i < 128 * 128; i++) {
		const GLfloat *actual = readback + i * 4;
		GLfloat expected[4];

		expected[0] = nonlinear_to_linear(image[i * 4 + 0]);
		expected[1] = nonlinear_to_linear(image[i * 4 + 1]);
		expected[2] = nonlinear_to_linear(image[i * 4 + 2]);
		expected[3] = image[i * 4 + 3] / 255.0;

		if (components <= 2) {
			if (fabs(actual[0] - expected[0]) > tolerance) {
				env.log << '\n'
					<< name
					<< " failed for internalFormat "
					<< intFormat
					<< "\n";
				env.log << "Expected luminance "
					<< expected[0]
					<< " found "
					<< actual[0]
					<< "\n";
				delete [] image;
				return GL_FALSE;
			}

		}
		else {
			assert(components == 3 || components == 4);
			if (fabs(actual[0] - expected[0]) > tolerance ||
			    fabs(actual[1] - expected[1]) > tolerance ||
			    fabs(actual[2] - expected[2]) > tolerance) {
				env.log << '\n'
					<< name
					<< " failed for internalFormat "
					<< intFormat
					<< "\n";
				env.log << "Expected color "
					<< expected[0]
					<< ", "
					<< expected[1]
					<< ", "
					<< expected[2]
					<< " found "
					<< actual[0]
					<< ", "
					<< actual[1]
					<< ", "
					<< actual[2]
					<< "\n";
				delete [] image;
				return GL_FALSE;
			}
		}

		if (alphaBits >= redBits
		    && components == 4
		    && fabs(actual[3] - expected[3]) > tolerance) {
			env.log << '\n'
				<< name
				<< " failed for internalFormat "
				<< intFormat
				<< "\n";
			env.log << "Expected alpha "
				<< expected[3]
				<< " found "
				<< actual[3]
				<< "\n";
			delete [] image;
			return GL_FALSE;
		}
	}

	delete [] image;
	return GL_TRUE;
}