Esempio n. 1
0
enum piglit_result
piglit_display(void)
{
	GLuint vs, fs;
	bool pass = true;
	GLuint prog;
	float green[] = {0.0, 1.0, 0.0, 0.0};
	GLint status;

	/* Initial buffer clear. */
	glClearColor(1.0, 0.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);

	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source);
	fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_source);
	prog = piglit_link_simple_program(vs, fs);

	if (!vs || !fs || !prog)
		piglit_report_result(PIGLIT_FAIL);

	piglit_DeleteShader(vs);
	piglit_DeleteShader(fs);
	piglit_UseProgram(prog);
	piglit_DeleteProgram(prog);

	/* Try to blow out the refcount */
	piglit_DeleteProgram(prog);
	piglit_DeleteProgram(prog);
	piglit_DeleteProgram(prog);

	/* Sanity check: deleting didn't already unbind our shader program. */
	piglit_draw_rect(-1, -1, 2, 2);
	pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
				      green) && pass;

	/* The program should still report being deleted. */
	piglit_GetProgramiv(prog, GL_DELETE_STATUS, &status);
	if (!piglit_check_gl_error(0))
		piglit_report_result(PIGLIT_FAIL);
	if (status != GL_TRUE) {
		fprintf(stderr,
			"GL_DELETE_STATUS after a clear reported non-true %d\n",
			status);
		pass = false;
	}

	/* Now, disable the program and it should be finally deleted. */
	piglit_UseProgram(0);

	piglit_GetProgramiv(prog, GL_DELETE_STATUS, &status);
	pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;

	piglit_present_results();

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Esempio n. 2
0
void piglit_init(int argc, char **argv)
{
	GLuint vs;
	GLint maxcomps, maxattrs;
	unsigned i;

	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);

	/* Check the driver. */
	if (piglit_get_gl_version() < 15) {
		fprintf(stderr, "OpenGL 1.5 required.\n");
		piglit_report_result(PIGLIT_SKIP);
	}
	piglit_require_GLSL();
	piglit_require_transform_feedback();

	glGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS_EXT, &maxattrs);
	if (maxattrs < 4) {
		fprintf(stderr, "Not enough separate attribs supported by transform feedback.\n");
		piglit_report_result(PIGLIT_SKIP);
	}
	glGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_EXT, &maxcomps);
	if (maxcomps < 4) {
		fprintf(stderr, "Not enough separate components supported by transform feedback.\n");
		piglit_report_result(PIGLIT_SKIP);
	}

	/* Create shaders. */
	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vstext);
	prog = piglit_CreateProgram();
	piglit_AttachShader(prog, vs);
	piglit_TransformFeedbackVaryings(prog, sizeof(varyings)/sizeof(varyings[0]),
					 varyings, GL_SEPARATE_ATTRIBS_EXT);
	piglit_LinkProgram(prog);
	if (!piglit_link_check_status(prog)) {
		piglit_DeleteProgram(prog);
		piglit_report_result(PIGLIT_FAIL);
	}

	/* Set up the transform feedback buffer. */
	glGenBuffers(4, buf);
	for (i = 0; i < 4; i++) {
		unsigned j;
		float *ptr;
		glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, buf[i]);
		glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER_EXT,
			     NUM_OUT_VERTICES*4*sizeof(float), NULL, GL_STREAM_READ);
		ptr = glMapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, GL_WRITE_ONLY);
		for (j = 0; j < NUM_OUT_VERTICES*4; j++) {
			ptr[j] = 0.123456;
		}
		glUnmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT);
		piglit_BindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, i, buf[i]);
	}

	assert(glGetError() == 0);

	glClearColor(0.2, 0.2, 0.2, 1.0);
	glEnableClientState(GL_VERTEX_ARRAY);
}
Esempio n. 3
0
void
piglit_init(int argc, char **argv)
{
	GLuint vs;
	int num_varyings;

	piglit_require_GLSL();
	piglit_require_transform_feedback();

	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vstext);
	for (num_varyings = 1; num_varyings <= 2; ++num_varyings) {
		GLuint prog = piglit_CreateProgram();
		piglit_AttachShader(prog, vs);
		piglit_BindAttribLocation(prog, 0, "vertex_num");
		piglit_TransformFeedbackVaryings(prog, num_varyings, varyings,
						 GL_INTERLEAVED_ATTRIBS);
		piglit_LinkProgram(prog);
		if (!piglit_link_check_status(prog)) {
			piglit_DeleteProgram(prog);
			piglit_report_result(PIGLIT_FAIL);
		}
		progs[num_varyings - 1] = prog;
	}

	glGenBuffers(1, &xfb_buf);
	glGenQueries(1, &query_prims_generated);
	glGenQueries(1, &query_prims_written);
}
Esempio n. 4
0
/**
 * Test drawing with GLSL shaders and no vertex arrays.
 * Use a vertex shader with a hard-coded vertex position.
 */
static GLboolean
test_glsl_no_arrays(void)
{
   static const char *noVertexVertShaderText =
      "varying vec4 colorVar; \n"
      "void main() \n"
      "{ \n"
      "   colorVar = vec4(1.0, 1.0, 0.0, 1.0); \n"
      "   gl_Position = vec4(0.0, 0.0, 0.0, 1.0); \n"
      "} \n";

   static const char *fragShaderText =
      "varying vec4 colorVar; \n"
      "void main() \n"
      "{ \n"
      "   gl_FragColor = colorVar; \n"
      "} \n";

   static const GLfloat expected[4] = {1.0, 1.0, 0.0, 1.0};
   GLboolean p, pass = GL_TRUE;
   GLuint vertShader, fragShader, program;

   vertShader = piglit_compile_shader_text(GL_VERTEX_SHADER,
                                           noVertexVertShaderText);
   fragShader = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fragShaderText);
   program = piglit_link_simple_program(vertShader, fragShader);

   piglit_UseProgram(program);

   glClear(GL_COLOR_BUFFER_BIT);
   glPointSize(3.0);
   glDrawArrays(GL_POINTS, 0, 1);
   glPointSize(1.0);

   p = piglit_probe_pixel_rgba(piglit_width/2, piglit_height/2, expected);
   glutSwapBuffers();
   if (!p) {
      printf("%s: failed when drawing with GLSL and no vertex arrays\n",
             TestName);
      pass = GL_FALSE;
   }

   piglit_DeleteShader(vertShader);
   piglit_DeleteProgram(program);

   return pass;
}
Esempio n. 5
0
static void
initialize_shader_and_xfb()
{
	GLuint prog, vs;
	const char *varying = "tf";

	piglit_require_gl_version(30);
	piglit_require_GLSL_version(130);
	piglit_require_transform_feedback();
	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vstext);
	prog = piglit_CreateProgram();
	piglit_AttachShader(prog, vs);
	piglit_TransformFeedbackVaryings(prog, 1, &varying,
					 GL_INTERLEAVED_ATTRIBS);
	piglit_LinkProgram(prog);
	if (!piglit_link_check_status(prog)) {
		piglit_DeleteProgram(prog);
		piglit_report_result(PIGLIT_FAIL);
	}
	piglit_UseProgram(prog);
}
Esempio n. 6
0
/** Test drawing with GLSL shaders */
static GLboolean
test_glsl_arrays(void)
{
   static const char *vertShaderText =
      "attribute vec4 color, pos; \n"
      "varying vec4 colorVar; \n"
      "void main() \n"
      "{ \n"
      "   colorVar = color; \n"
      "   gl_Position = gl_ModelViewProjectionMatrix * pos; \n"
      "} \n";

   static const char *fragShaderText =
      "varying vec4 colorVar; \n"
      "void main() \n"
      "{ \n"
      "   gl_FragColor = colorVar; \n"
      "} \n";

   static const GLfloat expected[4] = {0.5, 0.0, 0.5, 1.0};
   GLuint buf;
   GLboolean p, pass = GL_TRUE;
   GLint posAttrib, colorAttrib;
   GLuint vertShader, fragShader, program;

   buf = setup_vbo();
   glBindBufferARB(GL_ARRAY_BUFFER_ARB, buf);

   vertShader = piglit_compile_shader_text(GL_VERTEX_SHADER, vertShaderText);
   fragShader = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fragShaderText);
   program = piglit_link_simple_program(vertShader, fragShader);

   piglit_UseProgram(program);

   /*
    * Draw with compiler-assigned attribute locations
    */
   {
      posAttrib = piglit_GetAttribLocation(program, "pos");
      colorAttrib = piglit_GetAttribLocation(program, "color");

      if (0)
         printf("%s: GLSL posAttrib = %d  colorAttrib = %d\n",
                TestName, posAttrib, colorAttrib);

      glVertexAttribPointerARB(posAttrib, 2, GL_FLOAT, GL_FALSE,
                               2 * sizeof(GLfloat), (void *) 0);
      glVertexAttribPointerARB(colorAttrib, 3, GL_FLOAT, GL_FALSE,
                               3 * sizeof(GLfloat),
                               (void *) (8 * sizeof(GLfloat)));
      glEnableVertexAttribArrayARB(posAttrib);
      glEnableVertexAttribArrayARB(colorAttrib);

      glClear(GL_COLOR_BUFFER_BIT);
      glDrawArrays(GL_QUADS, 0, 4);

      p = piglit_probe_pixel_rgba(piglit_width/2, piglit_height/2, expected);
      glutSwapBuffers();
      if (!p) {
         printf("%s: failed when drawing with ", TestName);
         printf("compiler-assigned attribute locations\n");
         pass = GL_FALSE;
      }

      glDisableVertexAttribArrayARB(posAttrib);
      glDisableVertexAttribArrayARB(colorAttrib);
   }

   /*
    * Draw with user-defined attribute bindings, not using 0.
    */
   {
      posAttrib = 5;
      colorAttrib = 7;

      piglit_BindAttribLocation(program, posAttrib, "pos");
      piglit_BindAttribLocation(program, colorAttrib, "color");

      piglit_LinkProgram(program);

      glVertexAttribPointerARB(posAttrib, 2, GL_FLOAT, GL_FALSE,
                               2 * sizeof(GLfloat), (void *) 0);
      glVertexAttribPointerARB(colorAttrib, 3, GL_FLOAT, GL_FALSE,
                               3 * sizeof(GLfloat),
                               (void *) (8 * sizeof(GLfloat)));
      glEnableVertexAttribArrayARB(posAttrib);
      glEnableVertexAttribArrayARB(colorAttrib);

      glClear(GL_COLOR_BUFFER_BIT);
      glDrawArrays(GL_QUADS, 0, 4);

      p = piglit_probe_pixel_rgba(piglit_width/2, piglit_height/2, expected);
      glutSwapBuffers();
      if (!p) {
         printf("%s: failed when drawing with ", TestName);
         printf("user-assigned attribute locations\n");
         pass = GL_FALSE;
      }

      glDisableVertexAttribArrayARB(posAttrib);
      glDisableVertexAttribArrayARB(colorAttrib);
   }

   piglit_DeleteShader(vertShader);
   piglit_DeleteProgram(program);
   glDeleteBuffersARB(1, &buf);

   return pass;
}
Esempio n. 7
0
void piglit_init(int argc, char **argv)
{
	GLuint vs;
	unsigned i;
	float data[BUF_FLOATS];

	for (i = 0; i < BUF_FLOATS; i++) {
		data[i] = DEFAULT_VALUE;
	}

	/* Parse params. */
	for (i = 1; i < argc; i++) {
		if (!strcmp(argv[i], "discard")) {
			discard = GL_TRUE;
		} else if (!strcmp(argv[i], "offset")) {
			/* BindBufferOffset only exists in the EXT specification */
			piglit_require_extension("GL_EXT_transform_feedback");
			offset = OFFSET;
		} else if (!strcmp(argv[i], "range")) {
			offset = OFFSET;
			range = MAX_RANGE-7;
		} else if (!strcmp(argv[i], "render")) {
			test = RENDER;
		} else if (!strcmp(argv[i], "primgen")) {
			test = PRIMGEN;
		} else if (!strcmp(argv[i], "primwritten")) {
			test = PRIMWRITTEN;
		}
	}

	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);

	/* Check the driver. */
	if (piglit_get_gl_version() < 15) {
		fprintf(stderr, "OpenGL 1.5 required.\n");
		piglit_report_result(PIGLIT_SKIP);
	}
	piglit_require_GLSL();
	piglit_require_transform_feedback();

	/* Create shaders. */
	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vstext);
	prog = piglit_CreateProgram();
	piglit_AttachShader(prog, vs);
	piglit_TransformFeedbackVaryings(prog, 1, varyings, GL_INTERLEAVED_ATTRIBS_EXT);
	piglit_LinkProgram(prog);
	if (!piglit_link_check_status(prog)) {
		piglit_DeleteProgram(prog);
		piglit_report_result(PIGLIT_FAIL);
	}

	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vspassthrough);
	prog_passthrough = piglit_CreateProgram();
	piglit_AttachShader(prog_passthrough, vs);
	piglit_TransformFeedbackVaryings(prog_passthrough, 1, varyings, GL_INTERLEAVED_ATTRIBS_EXT);
	piglit_LinkProgram(prog_passthrough);
	if (!piglit_link_check_status(prog_passthrough)) {
		piglit_DeleteProgram(prog_passthrough);
		piglit_report_result(PIGLIT_FAIL);
	}

	/* Set up the transform feedback buffer. */
	glGenBuffers(1, &buf);
	glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, buf);
	glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER_EXT,
		     BUF_FLOATS*sizeof(float), data, GL_STREAM_READ);

	assert(glGetError() == 0);

	if (range) {
		puts("Testing BindBufferRange.");
		piglit_BindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER_EXT,
				     0, buf, offset*sizeof(float), range*sizeof(float));
	} else if (offset) {
		puts("Testing BindBufferOffset.");
		glBindBufferOffsetEXT(GL_TRANSFORM_FEEDBACK_BUFFER_EXT,
				      0, buf, offset*sizeof(float));
	} else {
		puts("Testing BindBufferBase.");
		piglit_BindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, 0, buf);
	}

	if (!range) {
		range = MAX_RANGE;
	} else {
		range = MAX_RANGE/2; /* just one primitive is going to be written */
	}

	assert(glGetError() == 0);

	glClearColor(0.2, 0.2, 0.2, 1.0);
	glEnableClientState(GL_VERTEX_ARRAY);
}