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

Function main

examples/opencl/stream.cpp:140–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

138}
139
140int main(void)
141{
142 try {
143 /*
144 * First Forge call should be a window creation call
145 * so that necessary OpenGL context is created for any
146 * other forge::* object to be created successfully
147 */
148 forge::Window wnd(DIMX, DIMY, "3D Vector Field Demo");
149 wnd.makeCurrent();
150
151 forge::Chart chart(FG_CHART_3D);
152 chart.setAxesLimits(MINIMUM-1.0f, MAXIMUM,
153 MINIMUM-1.0f, MAXIMUM,
154 MINIMUM-1.0f, MAXIMUM);
155 chart.setAxesTitles("x-axis", "y-axis", "z-axis");
156
157 int numElems = NELEMS*NELEMS*NELEMS;
158 forge::VectorField field = chart.vectorField(numElems, forge::f32);
159 field.setColor(0.f, 1.f, 0.f, 1.f);
160
161 /*
162 * Helper function to create a CLGL interop context.
163 * This function checks for if the extension is available
164 * and creates the context on the appropriate device.
165 * Note: context and queue are defined in cl_helpers.h
166 */
167 context = createCLGLContext(wnd);
168 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
169 queue = CommandQueue(context, device);
170
171 cl::Buffer points(context, CL_MEM_READ_WRITE, sizeof(float)*3*numElems);
172 cl::Buffer colors(context, CL_MEM_READ_WRITE, sizeof(float)*3*numElems);
173 cl::Buffer dirs(context, CL_MEM_READ_WRITE, sizeof(float)*3*numElems);
174
175 GfxHandle* handles[3];
176 createGLBuffer(&handles[0], field.vertices(), FORGE_VERTEX_BUFFER);
177 createGLBuffer(&handles[1], field.colors(), FORGE_VERTEX_BUFFER);
178 createGLBuffer(&handles[2], field.directions(), FORGE_VERTEX_BUFFER);
179
180 generatePoints(points, dirs, colors, queue, device);
181
182 copyToGLBuffer(handles[0], (ComputeResourceHandle)points(), field.verticesSize());
183 copyToGLBuffer(handles[1], (ComputeResourceHandle)colors(), field.colorsSize());
184 copyToGLBuffer(handles[2], (ComputeResourceHandle)dirs(), field.directionsSize());
185
186 do {
187 wnd.draw(chart);
188 } while(!wnd.close());
189
190 releaseGLBuffer(handles[0]);
191 releaseGLBuffer(handles[1]);
192 releaseGLBuffer(handles[2]);
193
194 } catch (forge::Error err) {
195 std::cout << err.what() << "(" << err.err() << ")" << std::endl;
196 } catch (cl::Error err) {
197 std::cout << err.what() << "(" << err.err() << ")" << std::endl;

Callers

nothing calls this directly

Calls 15

createCLGLContextFunction · 0.85
createGLBufferFunction · 0.85
copyToGLBufferFunction · 0.85
releaseGLBufferFunction · 0.85
vectorFieldMethod · 0.80
generatePointsFunction · 0.70
makeCurrentMethod · 0.45
setAxesLimitsMethod · 0.45
setAxesTitlesMethod · 0.45
setColorMethod · 0.45
verticesMethod · 0.45
colorsMethod · 0.45

Tested by

no test coverage detected