little edit to get rid of some cl boilerplate

master
MitchellHansen 8 years ago
parent e13280bb07
commit fe0fbc04e1

@ -27,12 +27,28 @@ public:
fps_average += (delta_time - fps_average) / frame_count; fps_average += (delta_time - fps_average) / frame_count;
} }
void flip_units() {
if (milliseconds)
milliseconds = false;
else
milliseconds = true;
}
void draw(sf::RenderWindow *r){ void draw(sf::RenderWindow *r){
t.setString(std::to_string(fps_average));
std::string out;
if (milliseconds)
out = std::to_string(fps_average);
else
out = std::to_string(floor(1 / fps_average));
t.setString(out);
r->draw(t); r->draw(t);
} }
private: private:
bool milliseconds = false;
sf::Font f; sf::Font f;
sf::Text t; sf::Text t;
int frame_count = 0; int frame_count = 0;

@ -278,6 +278,10 @@ int CL_Wrapper::run_kernel(std::string kernel_name, const int work_size){
cl_kernel kernel = kernel_map.at(kernel_name); cl_kernel kernel = kernel_map.at(kernel_name);
error = clEnqueueAcquireGLObjects(getCommandQueue(), 1, &buffer_map.at("image_buffer"), 0, 0, 0);
if (assert(error, "clEnqueueAcquireGLObjects"))
return -1;
//error = clEnqueueTask(command_queue, kernel, 0, NULL, NULL); //error = clEnqueueTask(command_queue, kernel, 0, NULL, NULL);
error = clEnqueueNDRangeKernel( error = clEnqueueNDRangeKernel(
command_queue, kernel, command_queue, kernel,
@ -287,6 +291,13 @@ int CL_Wrapper::run_kernel(std::string kernel_name, const int work_size){
if (assert(error, "clEnqueueNDRangeKernel")) if (assert(error, "clEnqueueNDRangeKernel"))
return -1; return -1;
// What if errors out and gl objects are never released?
error = clEnqueueReleaseGLObjects(getCommandQueue(), 1, &buffer_map.at("image_buffer"), 0, NULL, NULL);
if (assert(error, "clEnqueueReleaseGLObjects"))
return -1;
return 1; return 1;
} }

@ -311,21 +311,10 @@ int main() {
// ==== FPS LOCKED ==== // ==== FPS LOCKED ====
camera.update(delta_time); camera.update(delta_time);
// Run the raycast // Run the raycast
error = clEnqueueAcquireGLObjects(c.getCommandQueue(), 1, &image_buff, 0, 0, 0);
if (c.assert(error, "clEnqueueAcquireGLObjects"))
return -1;
c.run_kernel("min_kern", WORK_SIZE); c.run_kernel("min_kern", WORK_SIZE);
clFinish(c.getCommandQueue()); clFinish(c.getCommandQueue());
error = clEnqueueReleaseGLObjects(c.getCommandQueue(), 1, &image_buff, 0, NULL, NULL);
if (c.assert(error, "clEnqueueReleaseGLObjects"))
return -1;
// ==== RENDER ==== // ==== RENDER ====
window.clear(sf::Color::Black); window.clear(sf::Color::Black);
@ -343,8 +332,6 @@ int main() {
cam_text_mov_y.draw(&window); cam_text_mov_y.draw(&window);
cam_text_mov_z.draw(&window); cam_text_mov_z.draw(&window);
//cam_text_z.draw(&window);
window.display(); window.display();
} }

Loading…
Cancel
Save