本文整理汇总了C++中OpenCLProgram::GetOutput方法的典型用法代码示例。如果您正苦于以下问题:C++ OpenCLProgram::GetOutput方法的具体用法?C++ OpenCLProgram::GetOutput怎么用?C++ OpenCLProgram::GetOutput使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenCLProgram
的用法示例。
在下文中一共展示了OpenCLProgram::GetOutput方法的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++)
//.........这里部分代码省略.........