little edit to get rid of some cl boilerplate

master
MitchellHansen 8 years ago
parent e13280bb07
commit fe0fbc04e1

@ -10,33 +10,49 @@ const float PI_F = 3.14159265358979f;
struct fps_counter { struct fps_counter {
public: public:
fps_counter(){ fps_counter(){
if(!f.loadFromFile("../assets/fonts/Arial.ttf")){ if(!f.loadFromFile("../assets/fonts/Arial.ttf")){
std::cout << "couldn't find the fall back Arial font in ../assets/fonts/" << std::endl; std::cout << "couldn't find the fall back Arial font in ../assets/fonts/" << std::endl;
} else { } else {
t.setFont(f); t.setFont(f);
}
} }
}
void frame(double delta_time){ void frame(double delta_time){
if (frame_count == 100){ if (frame_count == 100){
frame_count = 0; frame_count = 0;
fps_average = 0; fps_average = 0;
}
frame_count++;
fps_average += (delta_time - fps_average) / frame_count;
} }
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));
r->draw(t); 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);
}
private: private:
sf::Font f; bool milliseconds = false;
sf::Text t; sf::Font f;
int frame_count = 0; sf::Text t;
double fps_average = 0; int frame_count = 0;
double fps_average = 0;
}; };
struct debug_text { struct debug_text {

@ -276,7 +276,11 @@ int CL_Wrapper::run_kernel(std::string kernel_name, const int work_size){
size_t global_work_size[1] = { static_cast<size_t>(work_size) }; size_t global_work_size[1] = { static_cast<size_t>(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(
@ -284,8 +288,15 @@ int CL_Wrapper::run_kernel(std::string kernel_name, const int work_size){
1, NULL, global_work_size, 1, NULL, global_work_size,
NULL, 0, NULL, NULL); NULL, 0, NULL, NULL);
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,20 +311,9 @@ 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 ====
@ -342,8 +331,6 @@ int main() {
cam_text_mov_x.draw(&window); cam_text_mov_x.draw(&window);
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