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

Function main

examples/opencl/histogram.cpp:257–346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

255}
256
257int main(void)
258{
259 try {
260
261 /*
262 * First Forge call should be a window creation call
263 * so that necessary OpenGL context is created for any
264 * other forge::* object to be created successfully
265 */
266 forge::Window wnd(DIMX, DIMY, "Histogram Demo");
267 wnd.makeCurrent();
268
269 forge::Image img(IMGW, IMGH, FG_RGBA, forge::u8);
270
271 forge::Chart chart(FG_CHART_2D);
272
273 chart.setAxesLabelFormat("%3.1f", "%.2e");
274
275 /* set x axis limits to maximum and minimum values of data
276 * and y axis limits to range [0, number of pixels ideally]
277 * but practically total number of pixels as y range will skew
278 * the histogram graph vertically. Therefore setting it to
279 * 25% of total number of pixels */
280 chart.setAxesLimits(0, 1, 0, IMGW*IMGH/(float)(NBINS/4.0));
281
282 /*
283 * Create histogram object specifying number of bins
284 */
285 forge::Histogram hist = chart.histogram(NBINS, forge::s32);
286 /*
287 * Set histogram colors
288 */
289 hist.setColor(FG_YELLOW);
290
291 /*
292 * Helper function to create a CLGL interop context.
293 * This function checks for if the extension is available
294 * and creates the context on the appropriate device.
295 * Note: context and queue are defined in cl_helpers.h
296 */
297 context = createCLGLContext(wnd);
298 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
299 queue = CommandQueue(context, device);
300
301 cl::Buffer image(context, CL_MEM_READ_WRITE, IMG_SIZE);
302 cl::Buffer baseNoise(context, CL_MEM_READ_WRITE, IMG_SIZE);
303 cl::Buffer perlinNoise(context, CL_MEM_READ_WRITE, IMG_SIZE);
304 cl::Buffer histOut(context, CL_MEM_READ_WRITE, NBINS * sizeof(int));
305 cl::Buffer colors(context, CL_MEM_READ_WRITE, 3 * NBINS * sizeof(float));
306
307 GfxHandle* handles[3];
308
309 createGLBuffer(&handles[0], img.pixels(), FORGE_IMAGE_BUFFER);
310 createGLBuffer(&handles[1], hist.vertices(), FORGE_VERTEX_BUFFER);
311 createGLBuffer(&handles[2], hist.colors(), FORGE_VERTEX_BUFFER);
312
313 unsigned frame = 0;
314 do {

Callers

nothing calls this directly

Calls 15

createCLGLContextFunction · 0.85
createGLBufferFunction · 0.85
copyToGLBufferFunction · 0.85
releaseGLBufferFunction · 0.85
histogramMethod · 0.80
pixelsMethod · 0.80
kernelFunction · 0.70
makeCurrentMethod · 0.45
setAxesLabelFormatMethod · 0.45
setAxesLimitsMethod · 0.45
setColorMethod · 0.45
verticesMethod · 0.45

Tested by

no test coverage detected