From 823f2e78aa743f2cf629462b817635ef8f75ce95 Mon Sep 17 00:00:00 2001 From: MitchellHansen Date: Tue, 4 Apr 2017 06:12:41 -0700 Subject: [PATCH] Forgot to turn off the FPS limiting, wow this thing is speedy --- kernels/conways.cl | 24 +++++++++++++----------- src/main.cpp | 10 ++++++---- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/kernels/conways.cl b/kernels/conways.cl index 926a1f5..03ac74b 100644 --- a/kernels/conways.cl +++ b/kernels/conways.cl @@ -12,7 +12,7 @@ int pixel_to_index(int2 dimensions, int2 pixel) { __kernel void conways ( global int2* image_res, - __write_only image2d_t image, + __read_write image2d_t image, global char* first_node_buffer, global char* second_node_buffer, global char* buffer_flip @@ -29,8 +29,9 @@ __kernel void conways ( //if (pixel.x > 1800) // printf("%i, %i", pixel.x, pixel.y); - float4 dead = (float4)(.49, .68, .81, 1); - float4 alive = (float4)(.49, .68, .71, .3); + float4 dead = (float4)(.51, .49, .39, .9); + float4 alive = (float4)(.21, .43, .46, .6); + float4 flavor = (float4)(.21, .76, .83, .8); // add all 8 blocks to neghbors int neighbors = 0; @@ -80,11 +81,12 @@ __kernel void conways ( int base = pixel_to_index(*image_res, pixel); if (neighbors == 3 || (neighbors == 2 && first_node_buffer[base])){ - write_imagef(image, pixel, alive); - second_node_buffer[base] = 1; + write_imagef(image, pixel, alive); + second_node_buffer[base] = 1; } else { - write_imagef(image, pixel, dead); - second_node_buffer[base] = 0; + + write_imagef(image, pixel, mix(read_imagef(image, pixel), dead, 0.01f)); + second_node_buffer[base] = 0; } } else { @@ -131,11 +133,11 @@ __kernel void conways ( int base = pixel_to_index(*image_res, pixel); if (neighbors == 3 || (neighbors == 2 && second_node_buffer[base])){ - write_imagef(image, pixel, alive); - first_node_buffer[base] = 1; + write_imagef(image, pixel, alive); + first_node_buffer[base] = 1; } else { - write_imagef(image, pixel, dead); - first_node_buffer[base] = 0; + write_imagef(image, pixel, mix(read_imagef(image, pixel), flavor, 0.001f)); + first_node_buffer[base] = 0; } } } diff --git a/src/main.cpp b/src/main.cpp index 4cd5f7f..5edced9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,7 +27,10 @@ const int WINDOW_Y = 1080; void generate_nodes(sf::Uint8* nodes) { for (int i = 0; i < WINDOW_X * WINDOW_Y; i += 1) { - if (rand() % 10 > 8) + + sf::Vector2i pos(i % WINDOW_X, i / WINDOW_X); + + if ((pos.x % 5 == 0) || (pos.y % 8 == 0)) nodes[i] = 1; else nodes[i] = 0; @@ -38,7 +41,7 @@ void generate_nodes(sf::Uint8* nodes) { int main() { sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "conways-game-of-life-opencl"); - window.setFramerateLimit(60); + window.setFramerateLimit(300); float physic_step = 0.166f; float physic_time = 0.0f; @@ -54,7 +57,7 @@ int main() { } sf::Vector2i image_resolution(WINDOW_X, WINDOW_Y); - cl.create_image_buffer("viewport_image", image_resolution, sf::Vector2f(0, 0), CL_MEM_WRITE_ONLY); + cl.create_image_buffer("viewport_image", image_resolution, sf::Vector2f(0, 0), CL_MEM_READ_WRITE); cl.create_buffer("image_res", sizeof(sf::Vector2i), &image_resolution); sf::Uint8* nodes = new sf::Uint8[WINDOW_X * WINDOW_Y]; @@ -116,7 +119,6 @@ int main() { window.clear(sf::Color::White); cl.run_kernel("conways", image_resolution); - //cl.run_kernel("conways", sf::Vector2i(5, 5)); cl.draw(&window); if (buffer_flip == 1)