MCPcopy Create free account
hub / github.com/arrayfire/forge / main

Function main

examples/opencl/surface.cpp:101–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99}
100
101int main(void)
102{
103 try {
104
105 /*
106 * First Forge call should be a window creation call
107 * so that necessary OpenGL context is created for any
108 * other forge::* object to be created successfully
109 */
110 forge::Window wnd(1024, 768, "3d Surface Demo");
111 wnd.makeCurrent();
112
113 forge::Chart chart(FG_CHART_3D);
114 chart.setAxesLimits(-10.f, 10.f, -10.f, 10.f, -0.5f, 1.f);
115 chart.setAxesTitles("x-axis", "y-axis", "z-axis");
116
117 forge::Surface surf = chart.surface(XSIZE, YSIZE, forge::f32);
118 surf.setColor(FG_YELLOW);
119
120 /*
121 * Helper function to create a CLGL interop context.
122 * This function checks for if the extension is available
123 * and creates the context on the appropriate device.
124 * Note: context and queue are defined in cl_helpers.h
125 */
126 context = createCLGLContext(wnd);
127 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
128 queue = CommandQueue(context, device);
129
130 cl::Buffer devOut(context, CL_MEM_READ_WRITE, sizeof(float) * XSIZE * YSIZE * 3);
131
132 kernel(devOut, queue, device);
133
134 GfxHandle* handle;
135 createGLBuffer(&handle, surf.vertices(), FORGE_VERTEX_BUFFER);
136 /* copy your data into the pixel buffer object exposed by
137 * forge::Surface class and then proceed to rendering.
138 * To help the users with copying the data from compute
139 * memory to display memory, Forge provides copy headers
140 * along with the library to help with this task
141 */
142 copyToGLBuffer(handle, (ComputeResourceHandle)devOut(), surf.verticesSize());
143
144 do {
145 wnd.draw(chart);
146 } while(!wnd.close());
147
148 releaseGLBuffer(handle);
149 }catch (forge::Error err) {
150 std::cout << err.what() << "(" << err.err() << ")" << std::endl;
151 } catch (cl::Error err) {
152 std::cout << err.what() << "(" << err.err() << ")" << std::endl;
153 }
154
155 return 0;
156}

Callers

nothing calls this directly

Calls 14

createCLGLContextFunction · 0.85
createGLBufferFunction · 0.85
copyToGLBufferFunction · 0.85
releaseGLBufferFunction · 0.85
surfaceMethod · 0.80
kernelFunction · 0.70
makeCurrentMethod · 0.45
setAxesLimitsMethod · 0.45
setAxesTitlesMethod · 0.45
setColorMethod · 0.45
verticesMethod · 0.45
verticesSizeMethod · 0.45

Tested by

no test coverage detected