当前位置: 首页>>代码示例>>C++>>正文


C++ ProgramObject::set_uniform_block方法代码示例

本文整理汇总了C++中ProgramObject::set_uniform_block方法的典型用法代码示例。如果您正苦于以下问题:C++ ProgramObject::set_uniform_block方法的具体用法?C++ ProgramObject::set_uniform_block怎么用?C++ ProgramObject::set_uniform_block使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProgramObject的用法示例。


在下文中一共展示了ProgramObject::set_uniform_block方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: start

int App::start(const std::vector<std::string> &args)
{
	OpenGLWindowDescription description;
	description.set_title("UniformBlock Shader");
	//description.set_version(3, 1, false);
	description.set_size(Size(1024, 768), true);

	DisplayWindow window(description);
	InputDevice keyboard = window.get_ic().get_keyboard();
	GraphicContext gc = window.get_gc();

	Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up);

	Slot slot_window_close = window.sig_window_close().connect(this, &App::window_close);

	// Load and link shaders
	ProgramObject shader = ProgramObject::load(gc, "Resources/vertex_shader.glsl", "Resources/fragment_shader.glsl");
	shader.bind_attribute_location(0, "Position");
	if (!shader.link())
		throw Exception("Unable to link shader program: Error:" + shader.get_info_log());

	int block_size = shader.get_uniform_block_size("TestBlock");
	const int num_blocks = 16;
	ProgramUniformBlock block(gc, block_size * num_blocks);

	std::vector<float> data_to_upload;
	data_to_upload.resize((num_blocks * block_size) / sizeof(float) );

	float test_colour = 1.0f;
	for (int cnt=0; cnt<num_blocks; cnt++)
	{

		int offset = cnt * block_size / sizeof(float) ;
		data_to_upload[offset + 0] = test_colour;
		data_to_upload[offset + 1] = 0.5f;
		data_to_upload[offset + 2] = 1.0f;
		test_colour -= 0.05f;
	}

	block.upload_data(0, &data_to_upload[0], block_size * num_blocks);

	quit = false;

	Font font(gc, "tahoma", 32);

	clan::ubyte64 startTime = System::get_time();



		//// Test code
		//GLuint uniform_index = -1;
		//const char *names[] = {"src_color"};

		//glGetUniformIndices(handle, 1, names, &uniform_index);
		//if (uniform_index >=0)
		//{
		//		GLint offset;
		//		GLint singleSize;
		//		GLint uniform_type;
		//		glGetActiveUniformsiv(handle, 1, &uniform_index, GL_UNIFORM_TYPE, &uniform_type);
		//		glGetActiveUniformsiv(handle, 1, &uniform_index, GL_UNIFORM_OFFSET, &offset);
		//		glGetActiveUniformsiv(handle, 1, &uniform_index, GL_UNIFORM_SIZE, &singleSize);
		//		if ((uniform_type != GL_FLOAT_VEC3) || (offset !=0) || (singleSize != 1))
		//		{
		//			throw Exception("well it seems it does not work");
		//		}
		//}


	while (!quit)
	{
		gc.clear(Colorf(0.1f, 0.1f, 0.2f));
		OpenGL::check_error();


		for (int test_run_y=0; test_run_y < 16; test_run_y++)
		{
			shader.set_uniform_block("TestBlock", block, test_run_y*block_size);
			for (int test_run_x=0; test_run_x < 16; test_run_x++)
			{
				Vec2f positions[3];
				float size = 32.0f;
				positions[0].x = test_run_x * size;
				positions[0].y = test_run_y * size + size;
				positions[1].x = test_run_x * size + size;
				positions[1].y = test_run_y * size + size;
				positions[2].x = test_run_x * size + size;
				positions[2].y = test_run_y * size;

				PrimitivesArray prim_array(gc);
				prim_array.set_attributes(0, positions);
				gc.set_program_object(shader, cl_program_matrix_modelview_projection);
				gc.draw_primitives(cl_triangles, 3, prim_array);
				gc.reset_program_object();
			}
		}
		font.draw_text(gc, 32, 200, "Hello World");
		window.flip(1);

		KeepAlive::process();
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


注:本文中的ProgramObject::set_uniform_block方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。