WORKING! Awesome! It now casts fully inside the gpu,

context is then switched to gl and then rendered via sfml.
It has no loop, no controls, and the aspect ratio is off,
but holy hell it works!
This commit is contained in:
2016-09-01 22:45:48 -07:00
parent c565d0facc
commit cf607382a9
5 changed files with 172 additions and 17 deletions

View File

@@ -230,10 +230,10 @@ int CL_Wrapper::store_buffer(cl_mem buffer, std::string buffer_name){
buffer_map.emplace(std::make_pair(buffer_name, buffer));
}
int CL_Wrapper::run_kernel(std::string kernel_name){
int CL_Wrapper::run_kernel(std::string kernel_name, const int work_size){
const int WORKER_SIZE = 10;
size_t global_work_size[1] = { WORKER_SIZE };
size_t global_work_size[1] = { static_cast<size_t>(work_size) };
cl_kernel kernel = kernel_map.at(kernel_name);

View File

@@ -29,8 +29,8 @@
#include "RayCaster.h"
#include "CL_Wrapper.h"
const int WINDOW_X = 150;
const int WINDOW_Y = 150;
const int WINDOW_X = 100;
const int WINDOW_Y = 100;
@@ -76,6 +76,8 @@ int main() {
sf::Vector3i map_dim(100, 100, 100);
Map* map = new Map(map_dim);
map->setVoxel(sf::Vector3i(77, 50, 85), 5);
cl_mem map_buff = clCreateBuffer(
c.getContext(), CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
sizeof(char) * map_dim.x * map_dim.y * map_dim.z, map->list, NULL
@@ -129,6 +131,9 @@ int main() {
}
}
int ind = 367;
printf("%i === %f, %f, %f\n", ind, view_matrix[ind * 4 + 0], view_matrix[ind * 4 + 1], view_matrix[ind * 4 + 2]);
cl_mem view_matrix_buff = clCreateBuffer(
c.getContext(), CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
sizeof(float) * 3 * view_res.x * view_res.y, view_matrix, NULL
@@ -142,7 +147,7 @@ int main() {
);
sf::Vector3f cam_pos(50, 50, 50);
sf::Vector3f cam_pos(55, 50, 50);
cl_mem cam_pos_buff = clCreateBuffer(
c.getContext(), CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
sizeof(float) * 4, &cam_pos, NULL
@@ -194,15 +199,18 @@ int main() {
c.set_kernel_arg("min_kern", 5, "cam_pos_buffer");
c.set_kernel_arg("min_kern", 6, "image_buffer");
const int size = 100 * 100;
c.run_kernel("min_kern", size);
c.run_kernel("min_kern");
clFinish(c.getCommandQueue());
error = clEnqueueReleaseGLObjects(c.getCommandQueue(), 1, &image_buff, 0, NULL, NULL);
if (c.assert(error, "clEnqueueReleaseGLObjects"))
return -1;
s.setTexture(t);
// The step size in milliseconds between calls to Update()
// Lets set it to 16.6 milliseonds (60FPS)
float step_size = 0.0166f;
@@ -224,9 +232,6 @@ int main() {
// State values
sf::Vector3f cam_vec(0, 0, 0);
RayCaster ray_caster(map, map_dim, view_res);