Exemple #1
0
enum piglit_result
piglit_display(void)
{
	GLint max_clip_planes, max_clip_distances, expected_value;
	GLint test_distances, test_in_vs;
	float green[] = { 0.0, 1.0, 0.0, 1.0 };
	GLint loc;

	enum piglit_result result = PIGLIT_PASS;
	glGetIntegerv(GL_MAX_CLIP_PLANES, &max_clip_planes);
	printf("GL_MAX_CLIP_PLANES = %d\n", max_clip_planes);
	glGetIntegerv(GL_MAX_CLIP_DISTANCES, &max_clip_distances);
	printf("GL_MAX_CLIP_DISTANCES = %d\n", max_clip_distances);
	if (max_clip_planes != max_clip_distances) {
		printf("GL_MAX_CLIP_PLANES != GL_MAX_CLIP_DISTANCES\n");
		piglit_report_result(PIGLIT_FAIL);
	}
	if (max_clip_distances < 8) {
		printf("GL_MAX_CLIP_DISTANCES < 8\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	expected_value = max_clip_distances;
	loc = piglit_GetUniformLocation(prog, "expected_value");
	piglit_Uniform1i(loc, expected_value);

	for (test_distances = 0; test_distances <= 1; ++test_distances) {
		loc = piglit_GetUniformLocation(prog, "test_distances");
		piglit_Uniform1i(loc, test_distances);
		for (test_in_vs = 0; test_in_vs <= 1; ++test_in_vs) {
			bool pass;
			loc = piglit_GetUniformLocation(prog, "test_in_vs");
			piglit_Uniform1i(loc, test_in_vs);
			piglit_draw_rect(-1, -1, 2, 2);
			pass = piglit_probe_rect_rgba(0, 0, piglit_width,
						      piglit_height, green);
			printf("Checking that gl_MaxClip%s == %d in %s: %s\n",
			       test_distances ? "Distances" : "Planes",
			       expected_value,
			       test_in_vs ? "VS" : "FS",
			       pass ? "pass" : "fail");
			if (!pass) {
				result = PIGLIT_FAIL;
			}
		}
	}

	return result;
}
void
piglit_init(int argc, char **argv)
{
	int vs, fs, prog;
	int tex_location;

	piglit_require_GLSL_version(130);

	glActiveTexture(GL_TEXTURE0);
	piglit_rgbw_texture(GL_RGBA, tex_size, tex_size / 2, true, false,
			    GL_UNSIGNED_NORMALIZED);

	piglit_ortho_projection(piglit_width, piglit_height, false);

	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vert);
	fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, frag);
	prog = piglit_link_simple_program(vs, fs);

	tex_location = piglit_GetUniformLocation(prog, "tex");
	lod_location = piglit_GetUniformLocation(prog, "lod");
	pos_location = piglit_GetUniformLocation(prog, "pos");

	piglit_UseProgram(prog);
	piglit_Uniform1i(tex_location, 0);
}
Exemple #3
0
void
piglit_init(int argc, char **argv)
{
	int prog;
	int tex_location;
	int i;
	enum shader_target test_stage = UNKNOWN;
	bool sampler_found = false;

	for (i = 1; i < argc; i++) {
		if (test_stage == UNKNOWN) {
			/* Maybe it's the shader stage? */
			if (strcmp(argv[i], "vs") == 0) {
				test_stage = VS;
				continue;
			} else if (strcmp(argv[i], "fs") == 0) {
				test_stage = FS;
				continue;
			}
		}

		if (strcmp(argv[i], "140") == 0) {
			shader_version = 140;
			continue;
		}

		/* Maybe it's the sampler type? */
		if (!sampler_found && (sampler_found = select_sampler(argv[i])))
			continue;

		fail_and_show_usage();
	}

	if (test_stage == UNKNOWN || !sampler_found)
		fail_and_show_usage();

	/* Not implemented yet */
	assert(sampler.target != GL_TEXTURE_CUBE_MAP_ARRAY);

	require_GL_features(test_stage);

	prog = generate_GLSL(test_stage);
	if (!prog)
		piglit_report_result(PIGLIT_FAIL);

	tex_location = piglit_GetUniformLocation(prog, "tex");
	lod_location = piglit_GetUniformLocation(prog, "lod");
	vertex_location = piglit_GetAttribLocation(prog, "vertex");
	piglit_UseProgram(prog);
	piglit_Uniform1i(tex_location, 0);

	/* Create textures and set miplevel info */
	set_base_size();
	compute_miplevel_info();
	generate_texture();
}
enum piglit_result
piglit_display(void)
{
	int l, q;
	bool pass = true;
	float red[4]   = {1.0, 0.0, 0.0, 1.0};
	float blue[4]  = {0.0, 0.0, 1.0, 1.0};
	float black[4] = {0.0, 0.0, 0.0, 1.0};

	glClearColor(0.5, 0.5, 0.5, 1.0);
	glClear(GL_COLOR_BUFFER_BIT);

	for (l = 0; (tex_size >> l) > 0; l++) {
		const int width = tex_size >> l;
		const int height = max(width / 2, 1);
		const int y = 10 + 20 * l;

		piglit_Uniform1i(lod_location, l);

		/* Draw 4 squares with a color sample for each quad */
		for (q = 0; q < 4; q++) {
			const int tex_x = (q / 2) * ((width / 2));
			const int tex_y = (q % 2) * ((height / 2));
			float *c = black;
			const int x = 10+20*q;

			/* fancy stuff - we should see red and blue
			   due to the offset for 3 levels, 
			   otherwise we get lots of black border color */
			if (l < 3) {
				if (q == 2) c = red;
				else if (q == 3) c = blue;
			} else if (l == 3)
				if (q == 2) c = blue;

			piglit_Uniform2i(pos_location, tex_x, tex_y);
			piglit_draw_rect(x, y, 10, 10);

			if (width > 2) /* below 1 wide no test */
				pass &= piglit_probe_rect_rgba(x, y, 10, 10, c);
		}
	}

	glutSwapBuffers();

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Exemple #5
0
enum piglit_result
piglit_display()
{
	bool pass = true;
	int i, l;
	const int size = sampler_size();
	static const float verts[] = {
		-1, -1,
		-1,  1,
		 1,  1,
		 1, -1,
	};

	glClearColor(0.5, 0.5, 0.5, 1.0);
	glClear(GL_COLOR_BUFFER_BIT);

	glVertexAttribPointer(vertex_location, 2, GL_FLOAT, GL_FALSE, 0, verts);
	glEnableVertexAttribArray(vertex_location);

	/* Draw consecutive squares for each mipmap level */
	for (l = 0; l < miplevels; l++) {
		const int x = 10 + l * 20;
		float expected_color[4] = {0, 0, 0, 0};
		expected_color[0] = 0.01 * level_size[l][0];
		if (sampler.target == GL_TEXTURE_1D_ARRAY) {
			expected_color[1] = 0.01 * level_size[l][2];
		} else {
			for (i = 1; i < size; i++)
				expected_color[i] = 0.01 * level_size[l][i];
		}
		expected_color[3] = 1.0;

		piglit_Uniform1i(lod_location, l);
		glViewport(x, 10, 10, 10);
		glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

		pass &= piglit_probe_rect_rgba(x, 10, 10, 10, expected_color);
	}

	glDisableVertexAttribArray(vertex_location);

	piglit_present_results();

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
static void
create_frag_shader(void)
{
   /* This shader samples the currently bound depth texture, then compares
    * that value to the current fragment Z value to produce a shade of red
    * indicating error/difference.
    *
    * E.g:  gl_FragColor = scale * abs(texture.Z - fragment.Z);
    *
    * Note that we have to be pretty careful with converting gl_FragCoord
    * into a 2D texture coordinate.  There's a -0.5 bias and scale factor.
    */
   static const char *text_2d =
      "uniform sampler2D zTex; \n"
      "uniform float sizeScale; \n"
      "uniform float errorScale; \n"
      "void main() \n"
      "{ \n"
      "   vec2 coord = (gl_FragCoord.xy - vec2(0.5)) / sizeScale; \n"
      "   vec4 z = texture2D(zTex, coord); \n"
      "   float diff = errorScale * abs(z.r - gl_FragCoord.z); \n"
      "   //gl_FragColor = vec4(gl_FragCoord.z, 0, 0, 0); \n"
      "   //gl_FragColor = z; \n"
      "   gl_FragColor = vec4(diff, 0, 0, 0); \n"
      "   gl_FragDepth = gl_FragCoord.z; \n"
      "} \n";
   static const char *text_rect =
      "#extension GL_ARB_texture_rectangle: require \n"
      "uniform sampler2DRect zTex; \n"
      "uniform float sizeScale; \n"
      "uniform float errorScale; \n"
      "void main() \n"
      "{ \n"
      "   vec2 coord = gl_FragCoord.xy; \n"
      "   vec4 z = texture2DRect(zTex, coord); \n"
      "   float diff = errorScale * abs(z.r - gl_FragCoord.z); \n"
      "   //gl_FragColor = vec4(gl_FragCoord.z, 0, 0, 0); \n"
      "   //gl_FragColor = z; \n"
      "   gl_FragColor = vec4(diff, 0, 0, 0); \n"
      "   gl_FragDepth = gl_FragCoord.z; \n"
      "} \n";
   GLuint fs;
   GLint zTex, errorScale, sizeScale;

   if (TexTarget == GL_TEXTURE_2D)
      fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, text_2d);
   else
      fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, text_rect);

   assert(fs);

   ShaderProg = piglit_link_simple_program(0, fs);
   assert(ShaderProg);

   piglit_UseProgram(ShaderProg);

   zTex = piglit_GetUniformLocation(ShaderProg, "zTex");
   piglit_Uniform1i(zTex, 0);  /* unit 0 */

   errorScale = piglit_GetUniformLocation(ShaderProg, "errorScale");
   piglit_Uniform1f(errorScale, ErrorScale);

   sizeScale = piglit_GetUniformLocation(ShaderProg, "sizeScale");
   piglit_Uniform1f(sizeScale, (float) (SIZE - 1));

   piglit_UseProgram(0);
}