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


C++ OpenCLProgram::SetInput方法代码示例

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


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

示例1: main

int main()
{
    if(OpenCLRuntime::Initialize() != SICKL_SUCCESS)
    {
        printf("Could not OpenCL Context\n");
        return -1;
    }

    Mandelbrot mbrot;
    
    mbrot.Parse();
  
    mbrot.GetRoot().Print();
    
    OpenCLProgram program;
    OpenCLCompiler::Build(mbrot, program);

#if 0

	// init GLEW/GLUT and other gl setup
    if(!OpenGLRuntime::Initialize())
    {
        printf("Could not create OpenGL Context\n");
        return -1;
    }

	OpenGLCompiler comp;

	Mandelbrot mbrot;
	mbrot.Parse();
	/// Prints the AST generated from the Mandelbrot source

	mbrot.GetRoot().Print();

	/// Compile our OpenGL program
	OpenGLProgram* program = comp.Build(mbrot);

	/// Print the generated GLSL source
	printf("%s\n", program->GetSource().c_str());

	
	const uint32_t width = 350 * 5;
	const uint32_t height = 200 * 5;
	const uint32_t colors = mbrot.max_iterations;

	/// Generate the color table (a nice gold)
	float* color_map_data = new float[3 * colors];
	for(uint32_t i = 0; i < colors; i++)
	{
		float x = i/(float)colors;
		color_map_data[3 * i + 0] = 191.0f / 255.0f * (1.0f - x);
		color_map_data[3 * i + 1] = 125.0f / 255.0f * (1.0f - x);
		color_map_data[3 * i + 2] = 37.0f / 255.0f * (1.0f - x);
	}

	/// put it int a 1d buffer
	OpenGLBuffer1D color_map(colors, ReturnType::Float3, color_map_data);

	/// our output buffer
	OpenGLBuffer2D result(width, height, ReturnType::Float3, nullptr);
	OpenGLBuffer2D copy(width, height, ReturnType::Float3, nullptr);

	/// initialize our program
	program->Initialize(width, height);

	/// get our binding locations for each of the program input and outputs
	input_t min_loc = program->GetInputHandle("min");
	input_t max_loc = program->GetInputHandle("max");
	input_t color_map_loc = program->GetInputHandle("color_map");

	output_t output_loc = program->GetOutputHandle("output");

	/// sets min values
	program->SetInput(min_loc, -2.5f, -1.0f);
	/// sets max values
	program->SetInput(max_loc, 1.0f, 1.0f);
	/// set the scaler
	program->SetInput(color_map_loc, color_map);

	/// sets the render location
	program->BindOutput(output_loc, result);

	/// Runs the program
	program->Run();

    /// We can copy our data to the second buffer
    copy.SetData(result);

    float* result_buffer = nullptr;
    /// We can either read result back from the texture
    copy.GetData(result_buffer);

	/// Or from the framebuffer (which is faster on nvidia hardware at least)
    program->GetOutput(output_loc, result_buffer);

	/// Finally, dump the image to a Bitmap to view
	BMP image;
	image.SetSize(width, height);

	for(uint32_t i = 0; i < height; i++)
//.........这里部分代码省略.........
开发者ID:hal2001,项目名称:sickl,代码行数:101,代码来源:Main.cpp


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