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

Function main

examples/opencl/plotting.cpp:78–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76}
77
78int main(void)
79{
80 try {
81
82 /*
83 * First Forge call should be a window creation call
84 * so that necessary OpenGL context is created for any
85 * other forge::* object to be created successfully
86 */
87 forge::Window wnd(DIMX, DIMY, "Plotting Demo");
88 wnd.makeCurrent();
89
90 forge::Chart chart(FG_CHART_2D);
91 chart.setAxesLimits(FRANGE_START, FRANGE_END, -1.0f, 1.0f);
92
93 /* Create several plot objects which creates the necessary
94 * vertex buffer objects to hold the different plot types
95 */
96 forge::Plot plt0 = chart.plot(DATA_SIZE, forge::f32); //create a default plot
97 forge::Plot plt1 = chart.plot(DATA_SIZE, forge::f32, FG_PLOT_LINE, FG_MARKER_NONE); //or specify a specific plot type
98 forge::Plot plt2 = chart.plot(DATA_SIZE, forge::f32, FG_PLOT_LINE, FG_MARKER_TRIANGLE); //last parameter specifies marker shape
99 forge::Plot plt3 = chart.plot(DATA_SIZE, forge::f32, FG_PLOT_SCATTER, FG_MARKER_CROSS);
100
101 /*
102 * Set plot colors
103 */
104 plt0.setColor(FG_RED);
105 plt1.setColor(FG_BLUE);
106 plt2.setColor(FG_YELLOW); //use a forge predefined color
107 plt3.setColor((forge::Color) 0x257973FF); //or any hex-valued color
108 /*
109 * Set plot legends
110 */
111 plt0.setLegend("Sine");
112 plt1.setLegend("Cosine");
113 plt2.setLegend("Tangent");
114 plt3.setLegend("Log base 10");
115
116 /*
117 * Helper function to create a CLGL interop context.
118 * This function checks for if the extension is available
119 * and creates the context on the appropriate device.
120 * Note: context and queue are defined in cl_helpers.h
121 */
122 context = createCLGLContext(wnd);
123 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
124 queue = CommandQueue(context, device);
125
126 cl::Buffer sinOut(context, CL_MEM_READ_WRITE, sizeof(float) * DATA_SIZE * 2);
127 cl::Buffer cosOut(context, CL_MEM_READ_WRITE, sizeof(float) * DATA_SIZE * 2);
128 cl::Buffer tanOut(context, CL_MEM_READ_WRITE, sizeof(float) * DATA_SIZE * 2);
129 cl::Buffer logOut(context, CL_MEM_READ_WRITE, sizeof(float) * DATA_SIZE * 2);
130 kernel(sinOut, queue, 0);
131 kernel(cosOut, queue, 1);
132 kernel(tanOut, queue, 2);
133 kernel(logOut, queue, 3);
134
135 GfxHandle* handles[4];

Callers

nothing calls this directly

Calls 14

createCLGLContextFunction · 0.85
createGLBufferFunction · 0.85
copyToGLBufferFunction · 0.85
releaseGLBufferFunction · 0.85
plotMethod · 0.80
kernelFunction · 0.70
makeCurrentMethod · 0.45
setAxesLimitsMethod · 0.45
setColorMethod · 0.45
setLegendMethod · 0.45
verticesMethod · 0.45
verticesSizeMethod · 0.45

Tested by

no test coverage detected