From 515c0767a95921f01ccd918afcf74101cc92306b Mon Sep 17 00:00:00 2001 From: MitchellHansen Date: Fri, 1 Jan 2016 21:21:39 -0800 Subject: [PATCH] Alright, I think thats the best performance I'm gonna get by tweaking the loop. Gonna move the rendering shtuff over to the kernel code --- Conway_OpenCL/HelloWorld.cpp | 39 +++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/Conway_OpenCL/HelloWorld.cpp b/Conway_OpenCL/HelloWorld.cpp index 16a4c74..fb1f68e 100644 --- a/Conway_OpenCL/HelloWorld.cpp +++ b/Conway_OpenCL/HelloWorld.cpp @@ -147,7 +147,7 @@ int main(int argc, char* argv[]) // Setup the rng std::mt19937 rng(time(NULL)); - std::uniform_int_distribution rgen(0, 20); // 25% chance + std::uniform_int_distribution rgen(0, 12); // 25% chance // Init the grid char* grid = new char[GRID_WIDTH * GRID_HEIGHT* 2]; @@ -190,6 +190,17 @@ int main(int argc, char* argv[]) status = clSetKernelArg(kernel, 3, sizeof(cl_mem), (void *)&gridHeightBuffer); sf::Uint8* pixel_array = new sf::Uint8[WINDOW_X * WINDOW_Y * 4]; + + for (int i = 0; i < GRID_WIDTH * GRID_HEIGHT * 2; i += 2) { + + int p = i / 2; + + pixel_array[p * 4] = 49; // R? + pixel_array[p * 4 + 1] = 68; // G? + pixel_array[p * 4 + 2] = 72; // B? + pixel_array[p * 4 + 3] = 255; // A? + } + sf::Texture texture; texture.create(WINDOW_X, WINDOW_Y); sf::Sprite sprite(texture); @@ -233,21 +244,25 @@ int main(int argc, char* argv[]) for (int i = 0; i < GRID_WIDTH * GRID_HEIGHT * 2; i += 2) { - grid[i] = grid[i + 1]; - if (grid[i] == 1) { + + int p = i / 2; + + if (grid[i + 1] == 1) { - pixel_array[(i/ 2) * 4] = 255; // R? - pixel_array[(i / 2) * 4 + 1] = 255; // G? - pixel_array[(i / 2) * 4 + 2] = 255; // B? - pixel_array[(i / 2) * 4 + 3] = 255; // A? + pixel_array[p * 4] = 255; // R? + pixel_array[p * 4 + 1] = 255; // G? + pixel_array[p * 4 + 2] = 255; // B? + pixel_array[p * 4 + 3] = 255; // A? } - else { - pixel_array[(i / 2) * 4] = 49; // R? - pixel_array[(i / 2) * 4 + 1] = 68; // G? - pixel_array[(i / 2) * 4 + 2] = 72; // B? - pixel_array[(i / 2) * 4 + 3] = 255; // A? + else if (grid[i] == 1){ + pixel_array[p * 4] = 49; // R? + pixel_array[p * 4 + 1] = 68; // G? + pixel_array[p * 4 + 2] = 72; // B? + pixel_array[p * 4 + 3] = 255; // A? } + + grid[i] = grid[i + 1]; } texture.update(pixel_array);