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

Function main

examples/opencl/field.cpp:103–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101}
102
103int main(void)
104{
105 try {
106 /*
107 * First Forge call should be a window creation call
108 * so that necessary OpenGL context is created for any
109 * other forge::* object to be created successfully
110 */
111 forge::Window wnd(DIMX, DIMY, "Vector Field Demo");
112 wnd.makeCurrent();
113
114 forge::Chart chart(FG_CHART_2D);
115 chart.setAxesLimits(MINIMUM-1.0f, MAXIMUM, MINIMUM-1.0f, MAXIMUM);
116 chart.setAxesTitles("x-axis", "y-axis");
117
118 forge::Plot divPoints = chart.plot(4, forge::u32, FG_PLOT_SCATTER, FG_MARKER_CIRCLE);
119 divPoints.setColor(0.9f, 0.9f, 0.0f, 1.f);
120 divPoints.setLegend("Convergence Points");
121 divPoints.setMarkerSize(24);
122
123 size_t npoints = (size_t)(NELEMS*NELEMS);
124
125 forge::VectorField field = chart.vectorField((unsigned)(npoints), forge::f32);
126 field.setColor(0.f, 0.6f, 0.3f, 1.f);
127
128 /*
129 * Helper function to create a CLGL interop context.
130 * This function checks for if the extension is available
131 * and creates the context on the appropriate device.
132 * Note: context and queue are defined in cl_helpers.h
133 */
134 context = createCLGLContext(wnd);
135 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
136 queue = CommandQueue(context, device);
137
138 GfxHandle* handles[3];
139
140 createGLBuffer(&handles[0], divPoints.vertices(), FORGE_VERTEX_BUFFER);
141 createGLBuffer(&handles[1], field.vertices(), FORGE_VERTEX_BUFFER);
142 createGLBuffer(&handles[2], field.directions(), FORGE_VERTEX_BUFFER);
143
144 cl::Buffer dpoints(context, CL_MEM_READ_WRITE, sizeof(unsigned)*8);
145 cl::Buffer points(context, CL_MEM_READ_WRITE, sizeof(float)*2*npoints);
146 cl::Buffer dirs(context, CL_MEM_READ_WRITE, sizeof(float)*2*npoints);
147
148 queue.enqueueWriteBuffer(dpoints, CL_TRUE, 0, sizeof(unsigned)*8, DPOINTS);
149 generatePoints(points, dirs, queue, device);
150
151 copyToGLBuffer(handles[0], (ComputeResourceHandle)dpoints(), divPoints.verticesSize());
152
153 copyToGLBuffer(handles[1], (ComputeResourceHandle)points(), field.verticesSize());
154 copyToGLBuffer(handles[2], (ComputeResourceHandle)dirs(), field.directionsSize());
155
156 do {
157 wnd.draw(chart);
158 } while(!wnd.close());
159
160 // destroy GL-CUDA interop buffers

Callers

nothing calls this directly

Calls 15

createCLGLContextFunction · 0.85
createGLBufferFunction · 0.85
copyToGLBufferFunction · 0.85
releaseGLBufferFunction · 0.85
plotMethod · 0.80
vectorFieldMethod · 0.80
generatePointsFunction · 0.70
makeCurrentMethod · 0.45
setAxesLimitsMethod · 0.45
setAxesTitlesMethod · 0.45
setColorMethod · 0.45
setLegendMethod · 0.45

Tested by

no test coverage detected