diff --git a/Conway_OpenCL/Conway.hpp b/Conway_OpenCL/Conway.hpp index 0146f07..172fd93 100644 --- a/Conway_OpenCL/Conway.hpp +++ b/Conway_OpenCL/Conway.hpp @@ -335,28 +335,31 @@ int main(int argc, char* argv[]) // ===================================== Loop ================================================================== - + int i = 0; while (!glfwWindowShouldClose(gl_window)) { - glClearColor(0.2f, 0.3f, 0.3f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); + //glClearColor(0.2f, 0.3f, 0.3f, 1.0f); + //glClear(GL_COLOR_BUFFER_BIT); // ======================================= OpenCL Shtuff =================================================== // Work size, for each y line size_t global_work_size[1] = { WORKER_SIZE }; - //status = clEnqueueAcquireGLObjects(commandQueue, 1, &frontReadBuffer, 0, 0, 0); - //status = clEnqueueAcquireGLObjects(commandQueue, 1, &frontWriteBuffer, 0, 0, 0); - + glFinish(); + status = clEnqueueAcquireGLObjects(commandQueue, 1, &frontWriteBuffer, 0, 0, 0); + status = clEnqueueNDRangeKernel(commandQueue, compute_kernel, 1, NULL, global_work_size, NULL, 0, NULL, NULL); - clFinish(commandQueue); - status = clEnqueueNDRangeKernel(commandQueue, align_kernel, 1, NULL, global_work_size, NULL, 0, NULL, NULL); - //status = clEnqueueReleaseGLObjects(commandQueue, 1, &frontReadBuffer, 0, NULL, NULL); - //status = clEnqueueReleaseGLObjects(commandQueue, 1, &frontWriteBuffer, 0, NULL, NULL); + //clEnqueueBarrier(commandQueue); + + //status = clEnqueueNDRangeKernel(commandQueue, align_kernel, 1, NULL, global_work_size, NULL, 0, NULL, NULL); + + status = clEnqueueReleaseGLObjects(commandQueue, 1, &frontWriteBuffer, 0, NULL, NULL); + + //clEnqueueBarrier(commandQueue); + - clFinish(commandQueue); // ======================================= Rendering Shtuff ================================================= @@ -372,7 +375,7 @@ int main(int argc, char* argv[]) glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); glBindVertexArray(0); - glFinish(); + // Render glfwSwapBuffers(gl_window); diff --git a/Conway_OpenCL/conway_align.cl b/Conway_OpenCL/conway_align.cl index 7faab6d..90160b2 100644 --- a/Conway_OpenCL/conway_align.cl +++ b/Conway_OpenCL/conway_align.cl @@ -1,4 +1,4 @@ -__kernel void conway_align(__read_only image2d_t front_image, __global char* back_image, __global int* num_workers, __global int* grid_width, __global int *grid_height) +__kernel void conway_align(__read_only image2d_t front_image, __global unsigned char* back_image, __global int* num_workers, __global int* grid_width, __global int *grid_height) { const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST; @@ -15,9 +15,13 @@ __kernel void conway_align(__read_only image2d_t front_image, __global char* bac int4 pixel; pixel = read_imagei(front_image, sampler, pixelcoord); - char q = pixel.w / 255; + if (pixel.w > 200){ + back_image[i] = 0; + } + else + back_image[i] = 0; - back_image[i] = pixel.w / 255; + } } \ No newline at end of file diff --git a/Conway_OpenCL/conway_compute.cl b/Conway_OpenCL/conway_compute.cl index d1bf5d6..adf0aff 100644 --- a/Conway_OpenCL/conway_compute.cl +++ b/Conway_OpenCL/conway_compute.cl @@ -1,8 +1,8 @@ -__kernel void conway_compute(__write_only image2d_t front_image, __global char* back_image, __global int* num_workers, __global int* grid_width, __global int *grid_height) +__kernel void conway_compute(__write_only image2d_t front_image, __global unsigned char* back_image, __global int* num_workers, __global int* grid_width, __global int *grid_height) { - float4 black = (float4)(0.49, 0.68, 0.81, 1.0); - float4 white = (float4)(1.0, 1.00, 1.0, 0.5); + float4 black = (float4)(1.0, 0.0, 0.0, 1.0); + float4 white = (float4)(0.0, 0.0, 1.0, 0.0); // Caclulate the start and end range that this worker will be calculating int data_length = *grid_width * *grid_height; @@ -16,6 +16,8 @@ __kernel void conway_compute(__write_only image2d_t front_image, __global char* for (int i = start_range; i < end_range; i++){ + unsigned char im = back_image[i]; + int2 pixelcoord = (int2) (i % *grid_width, i / *grid_height); // add all 8 blocks to neghbors @@ -49,12 +51,12 @@ __kernel void conway_compute(__write_only image2d_t front_image, __global char* //write_imagef(front_image, pixelcoord, black); - if (neighbors == 3 || (neighbors == 2 && back_image[i] == 1) || back_image[i] < 0){ - write_imagef(front_image, pixelcoord, white); + if (neighbors == 3 || (neighbors == 2 && back_image[i] == 1) || (i % 10) == 1){ + write_imagef(front_image, pixelcoord, black); } else{ - write_imagef(front_image, pixelcoord, black); + write_imagef(front_image, pixelcoord, white); } } } \ No newline at end of file