Пример #1
0
bool	Pipeline :: setActiveProgram ( Program * program )
{
	if ( id == 0 || program == NULL || !program -> isOk () )
		return false;
		
	glActiveShaderProgram ( id, program -> getProgram () );
	
	return true;
}
Пример #2
0
GLUSboolean update(GLUSfloat time)
{
    glClear(GL_COLOR_BUFFER_BIT);

    // Setting up functions for the red triangle.
    glActiveShaderProgram(g_programPipeline.pipeline, g_vertexProgram.program);
    glUniformSubroutinesuiv(GL_VERTEX_SHADER, 1, &g_getOffsetRedSubIndex);
    glActiveShaderProgram(g_programPipeline.pipeline, g_fragmentProgram.program);
    glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, &g_getColorRedSubIndex);

    glDrawArrays(GL_TRIANGLES, 0, 3);

    //

    // Setting up functions for the green triangle.
    glActiveShaderProgram(g_programPipeline.pipeline, g_vertexProgram.program);
    glUniformSubroutinesuiv(GL_VERTEX_SHADER, 1, &g_getOffsetGreenSubIndex);
    glActiveShaderProgram(g_programPipeline.pipeline, g_fragmentProgram.program);
    glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, &g_getColorGreenSubIndex);

    glDrawArrays(GL_TRIANGLES, 0, 3);

    //

    // Setting up functions for the blue triangle.
    glActiveShaderProgram(g_programPipeline.pipeline, g_vertexProgram.program);
    glUniformSubroutinesuiv(GL_VERTEX_SHADER, 1, &g_getOffsetBlueSubIndex);
    glActiveShaderProgram(g_programPipeline.pipeline, g_fragmentProgram.program);
    glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, &g_getColorBlueSubIndex);

    glDrawArrays(GL_TRIANGLES, 0, 3);

    return GLUS_TRUE;
}
void
piglit_init(int argc, char **argv)
{
	bool pass = true;
	GLuint pipe;
	GLuint vs_prog;
	GLuint active_prog;
	GLuint unlinked_prog;
	GLuint shader;
	unsigned glsl_version;
	char *source;

	piglit_require_extension("GL_ARB_separate_shader_objects");

	glsl_version = pick_a_glsl_version();

	glGenProgramPipelines(1, &pipe);
	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	glBindProgramPipeline(pipe);

	(void)!asprintf(&source, vs_code_template, glsl_version);
	vs_prog = glCreateShaderProgramv(GL_VERTEX_SHADER, 1,
					 (const GLchar *const *) &source);
	piglit_link_check_status(vs_prog);

	/* First, make a valid program active.
	 */
	glActiveShaderProgram(pipe, vs_prog);
	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	/* Next, try to make an invalid program active and verify that the
	 * correct error is generated.  Also make sure the old program is
	 * still active.
	 *
	 * Section 7.4 (Program Pipeline Objects) under ActiveShaderProgram of
	 * the OpenGL 4.4 spec says:
	 *
	 *     "An INVALID_VALUE error is generated if program is not zero and
	 *     is not the name of either a program or shader object."
	 */
	glActiveShaderProgram(pipe, ~vs_prog);
	pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;

	glGetProgramPipelineiv(pipe, GL_ACTIVE_PROGRAM, (GLint *) &active_prog);
	if (active_prog != vs_prog) {
		printf("glActiveShaderProgram with an invalid program name "
		       "changed the active program state.\n");
		pass = false;
	} else {
		glActiveShaderProgram(pipe, vs_prog);
	}

	/* Try the same thing with a valid shader object (that is not part of
	 * a linked program).  Verify that the correct error is generated, and
	 * make sure the old program is still active.
	 *
	 * Section 7.4 (Program Pipeline Objects) under ActiveShaderProgram of
	 * the OpenGL 4.4 spec says:
	 *
	 *     "An INVALID_OPERATION error is generated if program is the name
	 *     of a shader object."
	 */
	shader = piglit_compile_shader_text(GL_VERTEX_SHADER, source);
	glActiveShaderProgram(pipe, shader);
	pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;

	glGetProgramPipelineiv(pipe, GL_ACTIVE_PROGRAM, (GLint *) &active_prog);
	if (active_prog != vs_prog) {
		printf("glActiveShaderProgram with a shader object "
		       "changed the active program state.\n");
		pass = false;
	} else {
		glActiveShaderProgram(pipe, vs_prog);
	}

	/* Finally, try the same thing with a valid program that is not
	 * linked.  Verify that the correct error is generated, and make sure
	 * the old program is still active.
	 *
	 * Section 7.4 (Program Pipeline Objects) under ActiveShaderProgram of
	 * the OpenGL 4.4 spec says:
	 *
	 *     "An INVALID_OPERATION error is generated if program is not zero
	 *     and has not been linked, or was last linked unsuccessfully."
	 */
	unlinked_prog = glCreateShaderProgramv(GL_VERTEX_SHADER, 1,
					       (const GLchar *const *) &invalid_code);

	glActiveShaderProgram(pipe, unlinked_prog);
	pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;

	glGetProgramPipelineiv(pipe, GL_ACTIVE_PROGRAM, (GLint *) &active_prog);
	if (active_prog != vs_prog) {
		printf("glActiveShaderProgram with an unlinked program "
		       "changed the active program state.\n");
		pass = false;
	} else {
		glActiveShaderProgram(pipe, vs_prog);
	}


	free(source);
	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}
Пример #4
0
void dd::ShaderProgram::Unbind()
{
	glActiveShaderProgram(0, 0);
}
Пример #5
0
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL41_nglActiveShaderProgram(JNIEnv *env, jclass clazz, jint pipeline, jint program, jlong function_pointer) {
	glActiveShaderProgramPROC glActiveShaderProgram = (glActiveShaderProgramPROC)((intptr_t)function_pointer);
	glActiveShaderProgram(pipeline, program);
}
bool testDrawArrays::initProgram()
{
	bool Validated(true);
	
	std::size_t ShaderIndex(0);
	switch(this->UniformUpdate)
	{
	case CONSTANT_UNIFORM:
	case PER_DRAW_UNIFORM_DSA:
	case REDUNDANT_UNIFORM_DSA:
	case PER_DRAW_UNIFORM_B2E:
	case REDUNDANT_UNIFORM_B2E:
		ShaderIndex = 1;
		break;
	case PER_DRAW_UNIFORM2_DSA:
	case REDUNDANT_UNIFORM2_DSA:
	case PER_DRAW_UNIFORM2_B2E:
	case REDUNDANT_UNIFORM2_B2E:
		ShaderIndex = 2;
		break;
	case NO_UNIFORM:
	default:
		ShaderIndex = 0;
		break;
	}

	glGenProgramPipelines(1, &this->PipelineName);

	compiler Compiler;
	GLuint VertShaderName = Compiler.create(GL_VERTEX_SHADER, getDataDirectory() + VERT_SHADER_SOURCE[ShaderIndex], "--version 420 --profile core");
	GLuint FragShaderName = Compiler.create(GL_FRAGMENT_SHADER, getDataDirectory() + FRAG_SHADER_SOURCE[ShaderIndex], "--version 420 --profile core");
	Validated = Validated && Compiler.check();

	this->ProgramName = glCreateProgram();
	glProgramParameteri(this->ProgramName, GL_PROGRAM_SEPARABLE, GL_TRUE);
	glAttachShader(this->ProgramName, VertShaderName);
	glAttachShader(this->ProgramName, FragShaderName);
	glLinkProgram(this->ProgramName);
	Validated = Validated && Compiler.checkProgram(this->ProgramName);

	UniformDiffuse0 = glGetUniformLocation(ProgramName, "Diffuse0");
	UniformDiffuse1 = glGetUniformLocation(ProgramName, "Diffuse1");

	if(Validated)
		glUseProgramStages(this->PipelineName, GL_VERTEX_SHADER_BIT | GL_FRAGMENT_SHADER_BIT, ProgramName);

	if(
		this->UniformUpdate == testDrawArrays::CONSTANT_UNIFORM ||
		this->UniformUpdate == testDrawArrays::PER_DRAW_UNIFORM_B2E ||
		this->UniformUpdate == testDrawArrays::REDUNDANT_UNIFORM_B2E ||
		this->UniformUpdate == testDrawArrays::PER_DRAW_UNIFORM2_B2E ||
		this->UniformUpdate == testDrawArrays::REDUNDANT_UNIFORM2_B2E)
		glActiveShaderProgram(this->PipelineName, this->ProgramName);

	if(this->UniformUpdate == testDrawArrays::CONSTANT_UNIFORM)
	{
		glProgramUniform4f(this->ProgramName, UniformDiffuse0, 1.0f, 0.5f, 0.0f, 1.0f);
		if(UniformDiffuse1 != -1)
			glProgramUniform4f(this->ProgramName, UniformDiffuse1, 0.0f, 0.5f, 1.0f, 1.0f);
	}

	return Validated;
}
void piglit_init(int argc, char **argv)
{
	GLuint prog;
	GLint s2_loc;
	GLint s3_loc;
	GLuint pipe;
	GLuint vao;
	GLuint bo;
	bool pass = true;

	piglit_require_extension("GL_ARB_separate_shader_objects");

	prog = glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1,
					 (const GLchar *const *) &fs_code);
	piglit_link_check_status(prog);

	s2_loc = glGetUniformLocation(prog, "s2");
	if (s2_loc == -1) {
		fprintf(stderr, "Failed to get uniform location for s2.\n");
		pass = false;
	}

	s3_loc = glGetUniformLocation(prog, "s3");
	if (s3_loc == -1) {
		fprintf(stderr, "Failed to get uniform location for s3.\n");
		pass = false;
	}

	glGenProgramPipelines(1, &pipe);
	glUseProgramStages(pipe,
			   GL_FRAGMENT_SHADER_BIT,
			   prog);
	glActiveShaderProgram(pipe, prog);
	glBindProgramPipeline(pipe);

	glGenVertexArrays(1, &vao);
	glBindVertexArray(vao);

	/* Configure a vertex array object and buffer object that will
	 * be used for drawing later.
	 */
	glGenBuffers(1, &bo);
	glBindBuffer(GL_ARRAY_BUFFER, bo);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vert), vert, GL_STATIC_DRAW);

	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	/* First, try an invalid configuration.
	 */
	glUniform1i(s2_loc, 1);
	glUniform1i(s3_loc, 1);
	if (piglit_program_pipeline_check_status_quiet(pipe)) {
		fprintf(stderr,
			"Pipeline was validated with conflicting "
			"sampler configuration.\n");
		pass = false;
	}

	/* Now try a valid configuration.
	 */
	glUniform1i(s2_loc, 1);
	glUniform1i(s3_loc, 2);
	if (!piglit_program_pipeline_check_status_quiet(pipe)) {
		fprintf(stderr,
			"Pipeline was not validated with non-conflicting "
			"sampler configuration.\n");
		pass = false;
	}

	/* Switch back to the invalid configuration.  Without first calling
	 * glValidateProgramPipeline, try to draw something.  Verify that
	 * GL_INVALID_OPERATION is generated.
	 */
	glUniform1i(s2_loc, 1);
	glUniform1i(s3_loc, 1);

	glDrawArrays(GL_POINTS, 0, 1);
	
	pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;

	/* Re-validate the program.
	 */
	if (piglit_program_pipeline_check_status_quiet(pipe)) {
		fprintf(stderr,
			"Pipeline was validated with conflicting "
			"sampler configuration (second attempt).\n");
		pass = false;
	}

	pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;

	/* Switch back to the valid configuration.  Without first calling
	 * glValidateProgramPipeline, try to draw something.  Verify that
	 * no error is generated.
	 */
	glUniform1i(s2_loc, 1);
	glUniform1i(s3_loc, 2);

	glDrawArrays(GL_POINTS, 0, 1);

	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	/* Clean up.
	 */
	glBindProgramPipeline(0);
	glDeleteProgram(prog);
	glDeleteProgramPipelines(1, &pipe);
	
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindVertexArray(0);

	glDeleteBuffers(1, &bo);
	glDeleteVertexArrays(1, &vao);

	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}
Пример #8
0
void
piglit_init(int argc, char **argv)
{
	GLint vs, fs, gs, tcs, tes;
	GLint ver;
	GLuint pipe = 0;
	GLint param = 0;
	char *version = NULL;
	const char *shader_source[2];

	static const char vs_source[] =
		"#if __VERSION__ > 140\n"
		"/* At least some versions of AMD's closed-source driver\n"
		" * contain a bug that requires redeclaration of gl_PerVertex\n"
		" * interface block in core profile shaders.\n"
		" */\n"
		"out gl_PerVertex {\n"
		"    vec4 gl_Position;\n"
		"};\n"
		"\n"
		"in vec4 position;\n"
		"#else\n"
		"varying vec4 position;\n"
		"#endif\n"
		"\n"
		"void main()\n"
		"{\n"
		"    gl_Position = position;\n"
		"}\n";
	static const char fs_source[] =
		"void main()\n"
		"{\n"
		"    gl_FragColor = vec4(0.0, 1.0, 0.0, 0.0);\n"
		"}\n";
	static const char gs_source[] =
		"/* At least some versions of AMD's closed-source driver\n"
		" * contain a bug that requires redeclaration of gl_PerVertex\n"
		" * interface block in core profile shaders.\n"
		" */\n"
		"in gl_PerVertex {\n"
		"    vec4 gl_Position;\n"
		"    float gl_PointSize;\n"
		"    float gl_ClipDistance[];\n"
		"} gl_in[];\n"
		"\n"
		"out gl_PerVertex {\n"
		"    vec4 gl_Position;\n"
		"    float gl_PointSize;\n"
		"    float gl_ClipDistance[];\n"
		"};\n"
		"\n"
		"layout(triangles) in;\n"
		"layout(triangle_strip, max_vertices = 3) out;\n"
		"void main() {\n"
		"    for(int i = 0; i < gl_in.length(); i++) {\n"
		"        gl_Position = gl_in[i].gl_Position;\n"
		"        EmitVertex();\n"
		"    }\n"
		"    EndPrimitive();\n"
		"}\n";
	static const char tc_source[] =
		"/* At least some versions of AMD's closed-source driver\n"
		" * contain a bug that requires redeclaration of gl_PerVertex\n"
		" * interface block in core profile shaders.\n"
		" */\n"
		"in gl_PerVertex {\n"
		"    vec4 gl_Position;\n"
		"    float gl_PointSize;\n"
		"    float gl_ClipDistance[];\n"
		"} gl_in[];\n"
		"\n"
		"out gl_PerVertex {\n"
		"    vec4 gl_Position;\n"
		"    float gl_PointSize;\n"
		"    float gl_ClipDistance[];\n"
		"} gl_out[];\n"
		"\n"
		"layout(vertices = 3)  out;\n"
		"void main()\n"
		"{\n"
		"    gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;\n"
		"    gl_TessLevelOuter[0] = 1.0;\n"
		"    gl_TessLevelOuter[1] = 1.0;\n"
		"    gl_TessLevelOuter[2] = 1.0;\n"
		"    gl_TessLevelInner[0] = 1.0;\n"
		"    gl_TessLevelInner[1] = 1.0;\n"
		"}\n";
	static const char te_source[] =
		"/* At least some versions of AMD's closed-source driver\n"
		" * contain a bug that requires redeclaration of gl_PerVertex\n"
		" * interface block in core profile shaders.\n"
		" */\n"
		"in gl_PerVertex {\n"
		"    vec4 gl_Position;\n"
		"    float gl_PointSize;\n"
		"    float gl_ClipDistance[];\n"
		"} gl_in[];\n"
		"\n"
		"out gl_PerVertex {\n"
		"    vec4 gl_Position;\n"
		"    float gl_PointSize;\n"
		"    float gl_ClipDistance[];\n"
		"};\n"
		"\n"
		"layout(triangles, equal_spacing) in;\n"
		"\n"
		"void main()\n"
		"{\n"
		"    vec4 p0 = gl_in[0].gl_Position;\n"
		"    vec4 p1 = gl_in[1].gl_Position;\n"
		"    vec4 p2 = gl_in[2].gl_Position;\n"
		"\n"
		"    vec3 p = gl_TessCoord.xyz;\n"
		"\n"
		"    gl_Position = p0*p.x + p1*p.y + p2*p.z;\n"
		"}\n";
	const bool has_gs = piglit_get_gl_version() >= 32;
	const bool has_tess = piglit_get_gl_version() >= 40
		|| piglit_is_extension_supported("GL_ARB_tessellation_shader");

	piglit_require_extension("GL_ARB_separate_shader_objects");

	pass = true;

	if (piglit_get_gl_version() >= 43) {
		ver = 430;
	} else if (piglit_get_gl_version() >= 32) {
		ver = 150;
	} else {
		ver = 110;
	}

	asprintf(&version,
		 "#version %d\n"
		 "#extension GL_ARB_separate_shader_objects: enable\n\n",
		 ver);

	shader_source[0] = version;
	if (has_tess) {
		shader_source[1] = tc_source;
		tcs = glCreateShaderProgramv(GL_TESS_CONTROL_SHADER, 2,
					     shader_source);
		pass = piglit_link_check_status(tcs) && pass;

		shader_source[1] = te_source;
		tes = glCreateShaderProgramv(GL_TESS_EVALUATION_SHADER, 2,
					     shader_source);
		pass = piglit_link_check_status(tes) && pass;
	} else {
		tcs = 0;
		tes = 0;
	}

	if (has_gs) {
		shader_source[1] = gs_source;
		gs = glCreateShaderProgramv(GL_GEOMETRY_SHADER, 2,
					    shader_source);
		pass = piglit_link_check_status(gs) && pass;
	} else {
		gs = 0;
	}

	shader_source[1] = fs_source;
	fs = glCreateShaderProgramv(GL_FRAGMENT_SHADER, 2, shader_source);
	pass = piglit_link_check_status(fs) && pass;

	shader_source[1] = vs_source;
	vs = glCreateShaderProgramv(GL_VERTEX_SHADER, 2, shader_source);
	pass = piglit_link_check_status(vs) && pass;

	glGenProgramPipelines(1, &pipe);
	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	glActiveShaderProgram(pipe, fs);
	glGetProgramPipelineiv(pipe, GL_ACTIVE_PROGRAM, &param);
	if (param != fs) {
		fprintf(stderr, "Failed to get Active Program.\n");
		pass = false;
	}
	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	use_stage_and_check(pipe, vs, GL_VERTEX_SHADER, true);
	use_stage_and_check(pipe, fs, GL_FRAGMENT_SHADER, true);
	use_stage_and_check(pipe, gs, GL_GEOMETRY_SHADER, has_gs);
	use_stage_and_check(pipe, tes, GL_TESS_EVALUATION_SHADER, has_tess);
	use_stage_and_check(pipe, tcs, GL_TESS_CONTROL_SHADER, has_tess);

	glActiveShaderProgram(pipe, vs);
	glGetProgramPipelineiv(pipe, GL_ACTIVE_PROGRAM, &param);
	if (param != vs) {
		fprintf(stderr, "Failed to get Active Program.\n");
		pass = false;
	}
	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;


	glUseProgramStages(pipe, GL_ALL_SHADER_BITS, 0);
	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	check_stage(pipe, 0, GL_VERTEX_SHADER, true);
	check_stage(pipe, 0, GL_FRAGMENT_SHADER, true);
	check_stage(pipe, 0, GL_GEOMETRY_SHADER, has_gs);
	check_stage(pipe, 0, GL_TESS_EVALUATION_SHADER, has_tess);
	check_stage(pipe, 0, GL_TESS_CONTROL_SHADER, has_tess);

	free(version);

	piglit_present_results();
	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}