ShaderColorGeometry::ShaderColorGeometry(GraphicContext &gc)
{
	ShaderObject vertex_shader(gc, shadertype_vertex, vertex);
	if(!vertex_shader.compile())
	{
		throw Exception(string_format("Unable to compile vertex shader object: %1", vertex_shader.get_info_log()));
	}

	ShaderObject geometry_shader(gc, shadertype_geometry, geometry);
	if(!geometry_shader.compile())
	{
		throw Exception(string_format("Unable to compile geometry shader object: %1", geometry_shader.get_info_log()));
	}

	if (!glProgramParameteri)
		throw Exception("Geomtry shader is not available");

	ShaderObject fragment_shader(gc, shadertype_fragment, fragment);
	if(!fragment_shader.compile())
	{
		throw Exception(string_format("Unable to compile fragment shader object: %1", fragment_shader.get_info_log()));
	}

	program_object = ProgramObject(gc);
	program_object.attach(vertex_shader);
	program_object.attach(geometry_shader);
	program_object.attach(fragment_shader);
	program_object.bind_attribute_location(0, "InPosition");
	program_object.bind_attribute_location(1, "InColor");
	program_object.bind_frag_data_location(0, "cl_FragColor");

	if (!program_object.link())
	{
		throw Exception(string_format("Unable to link program object: %1", program_object.get_info_log()));
	}
	
	program_object.set_uniform1i("Texture0", 0);

	gpu_uniforms = clan::UniformVector<ProgramUniforms>(gc, 1);


}
	GL1GraphicContextProvider::GL1GraphicContextProvider(OpenGLWindowProvider * render_window)
		: render_window(render_window),
		prim_arrays_set(false), num_set_tex_arrays(0),
		primitives_array_texture_set(false), primitives_array_texindex_set(false), scissor_enabled(false),
		framebuffer_bound(false)
	{
		check_opengl_version();
		max_texture_coords = get_max_texture_coords();
		// Limit the internal texture coords, to avoid situations where the opengl driver says there are unlimited texture coords
		if (max_texture_coords > 32)
			max_texture_coords = 32;
		// Hack, so the sprite render batcher does not exceed the allowed number of textures
		if (max_texture_coords < RenderBatchTriangle::max_textures)
		{
			if (max_texture_coords > 0)
			{
				RenderBatchTriangle::max_textures = max_texture_coords;
			}
			else
			{
				RenderBatchTriangle::max_textures = 1;
			}
		}

		selected_textures.resize(max_texture_coords);

		internal_program_provider = new GL1ProgramObjectProvider(this);	// <-- To be owned by "standard_program"
		internal_program = ProgramObject(internal_program_provider);

		// Enable point sprites for legacy opengl
		glEnable(GL_POINT_SPRITE);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();

		SharedGCData::add_provider(this);
	}
Exemple #3
0
Shader::Shader(GraphicContext &gc)
{
	ShaderLanguage shader_language = gc.get_shader_language();
	ShaderObject vertex_shader(gc, shadertype_vertex, shader_language==shader_glsl ? vertex_glsl : vertex_hlsl);
	if(!vertex_shader.compile())
	{
		std::string log = vertex_shader.get_info_log();
		throw Exception(string_format("Unable to compile vertex shader object: %1", log));
	}

	ShaderObject fragment_shader(gc, shadertype_fragment, shader_language==shader_glsl ? fragment_glsl : fragment_hlsl);
	if(!fragment_shader.compile())
	{
		std::string log = fragment_shader.get_info_log();
		throw Exception(string_format("Unable to compile fragment shader object: %1", log));
	}

	program_object = ProgramObject(gc);
	program_object.attach(vertex_shader);
	program_object.attach(fragment_shader);
	program_object.bind_attribute_location(0, "InPosition");
	program_object.bind_attribute_location(1, "InNormal");
	program_object.bind_attribute_location(2, "InMaterialAmbient");
	program_object.bind_frag_data_location(0, "cl_FragColor");
	if (!program_object.link())
	{
		throw Exception(string_format("Unable to link program object: %1", program_object.get_info_log()));
	}

	program_object.set_uniform_buffer_index("ProgramUniforms", 0);

	gpu_uniforms = clan::UniformVector<ProgramUniforms>(gc, 1);

	uniforms.LightAmbient = Vec4f(0.2f, 0.2f, 0.2f, 1.0f);
	uniforms.LightVector = Vec3f(0.0f, 0.0f, -1.0f);
	uniforms.LightDiffuse = Vec4f(0.7f, 0.7f, 0.7f, 1.0f);

}