| 160 | } |
| 161 | |
| 162 | void MandelbrotWidget::paintGL() |
| 163 | { |
| 164 | using compute::dim; |
| 165 | |
| 166 | float w = width(); |
| 167 | float h = height(); |
| 168 | |
| 169 | glMatrixMode(GL_PROJECTION); |
| 170 | glLoadIdentity(); |
| 171 | glOrtho(0.0, w, 0.0, h, -1.0, 1.0); |
| 172 | glMatrixMode(GL_MODELVIEW); |
| 173 | glLoadIdentity(); |
| 174 | |
| 175 | // setup the mandelbrot kernel |
| 176 | compute::kernel kernel(program_, "mandelbrot"); |
| 177 | kernel.set_arg(0, cl_texture_); |
| 178 | |
| 179 | // acquire the opengl texture so it can be used in opencl |
| 180 | compute::opengl_enqueue_acquire_gl_objects(1, &cl_texture_.get(), queue_); |
| 181 | |
| 182 | // execute the mandelbrot kernel |
| 183 | queue_.enqueue_nd_range_kernel( |
| 184 | kernel, dim(0, 0), dim(width(), height()), dim(1, 1) |
| 185 | ); |
| 186 | |
| 187 | // release the opengl texture so it can be used by opengl |
| 188 | compute::opengl_enqueue_release_gl_objects(1, &cl_texture_.get(), queue_); |
| 189 | |
| 190 | // ensure opencl is finished before rendering in opengl |
| 191 | queue_.finish(); |
| 192 | |
| 193 | // draw a single quad with the mandelbrot image texture |
| 194 | glEnable(GL_TEXTURE_2D); |
| 195 | glBindTexture(GL_TEXTURE_2D, gl_texture_); |
| 196 | |
| 197 | glBegin(GL_QUADS); |
| 198 | glTexCoord2f(0, 0); glVertex2f(0, 0); |
| 199 | glTexCoord2f(0, 1); glVertex2f(0, h); |
| 200 | glTexCoord2f(1, 1); glVertex2f(w, h); |
| 201 | glTexCoord2f(1, 0); glVertex2f(w, 0); |
| 202 | glEnd(); |
| 203 | } |
| 204 | |
| 205 | void MandelbrotWidget::keyPressEvent(QKeyEvent* event) |
| 206 | { |
nothing calls this directly
no test coverage detected