| 104 | } |
| 105 | |
| 106 | int main(void) |
| 107 | { |
| 108 | try { |
| 109 | |
| 110 | /* |
| 111 | * First Forge call should be a window creation call |
| 112 | * so that necessary OpenGL context is created for any |
| 113 | * other forge::* object to be created successfully |
| 114 | */ |
| 115 | forge::Window wnd(DIMX, DIMY, "Fractal Demo"); |
| 116 | wnd.makeCurrent(); |
| 117 | |
| 118 | /* Create an image object which creates the necessary |
| 119 | * textures and pixel buffer objects to hold the image |
| 120 | * */ |
| 121 | forge::Image img(DIMX, DIMY, FG_RGBA, forge::u8); |
| 122 | |
| 123 | /* |
| 124 | * Helper function to create a CLGL interop context. |
| 125 | * This function checks for if the extension is available |
| 126 | * and creates the context on the appropriate device. |
| 127 | * Note: context and queue are defined in cl_helpers.h |
| 128 | */ |
| 129 | context = createCLGLContext(wnd); |
| 130 | Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0]; |
| 131 | queue = CommandQueue(context, device); |
| 132 | |
| 133 | /* copy your data into the pixel buffer object exposed by |
| 134 | * forge::Image class and then proceed to rendering. |
| 135 | * To help the users with copying the data from compute |
| 136 | * memory to display memory, Forge provides copy headers |
| 137 | * along with the library to help with this task |
| 138 | */ |
| 139 | cl::Buffer devOut(context, CL_MEM_READ_WRITE, IMG_SIZE); |
| 140 | |
| 141 | kernel(devOut, queue); |
| 142 | |
| 143 | GfxHandle* handle = 0; |
| 144 | |
| 145 | // create GL-CPU interop buffer |
| 146 | createGLBuffer(&handle, img.pixels(), FORGE_IMAGE_BUFFER); |
| 147 | |
| 148 | // copy the data from compute buffer to graphics buffer |
| 149 | copyToGLBuffer(handle, (ComputeResourceHandle)devOut(), img.size()); |
| 150 | |
| 151 | do { |
| 152 | wnd.draw(img); |
| 153 | } while(!wnd.close()); |
| 154 | |
| 155 | // destroy GL-CPU Interop buffer |
| 156 | releaseGLBuffer(handle); |
| 157 | |
| 158 | }catch (forge::Error err) { |
| 159 | std::cout << err.what() << "(" << err.err() << ")" << std::endl; |
| 160 | } catch (cl::Error err) { |
| 161 | std::cout << err.what() << "(" << err.err() << ")" << std::endl; |
| 162 | } |
| 163 |
nothing calls this directly
no test coverage detected