From 6464fceece23e11471bad3eac0ebcf9b15fd7dec Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Sat, 24 Feb 2018 21:29:17 -0800 Subject: [PATCH] Added enabling and disabling of the octree from the settings buffer --- include/CLCaster.h | 5 +++-- kernels/ray_caster_kernel.cl | 28 ++++++++++++++-------------- src/Application.cpp | 4 ++++ src/CLCaster.cpp | 25 +++++++++++++++++++++++++ src/Input.cpp | 1 + 5 files changed, 47 insertions(+), 16 deletions(-) diff --git a/include/CLCaster.h b/include/CLCaster.h index 3469337..a876f16 100644 --- a/include/CLCaster.h +++ b/include/CLCaster.h @@ -104,7 +104,7 @@ public: */ CLCaster(); - virtual ~CLCaster(); + ~CLCaster(); // Queries hardware, creates the command queue and context, and compiles kernel bool init(); @@ -116,7 +116,7 @@ public: // Light controllers own the copy of the PackedData array. // We receive a pointer to the array and USE_HOST_POINTER to map the memory to the GPU - bool assign_lights(std::vector *data) ; + bool assign_lights(std::vector *data); // TODO: Double maps?? // We take a ptr to the map and create the map, and map_dimensions buffer for the GPU @@ -157,6 +157,7 @@ public: bool create_settings_buffer(); bool release_settings_buffer(); bool add_to_settings_buffer(std::string setting_name, std::string define_accessor_name, int64_t *value); + bool overwrite_setting(std::string settings_name, int64_t *value); bool remove_from_settings_buffer(std::string setting_name); // ================================== DEBUG ======================================= diff --git a/kernels/ray_caster_kernel.cl b/kernels/ray_caster_kernel.cl index a7a3a31..701e9ef 100644 --- a/kernels/ray_caster_kernel.cl +++ b/kernels/ray_caster_kernel.cl @@ -132,7 +132,7 @@ bool get_oct_vox( ts.parent_stack[ts.scale] = ts.current_descriptor; // Set our initial dimension and the position at the corner of the oct to keep track of our position - int dimension = OCTDIM; + int dimension = setting(OCTDIM); ts.oct_pos = zeroed_int3; // While we are not at the required resolution @@ -331,19 +331,19 @@ __kernel void raycaster( // If we hit a voxel - if (voxel.x < (*map_dim).x && voxel.y < (*map_dim).x && voxel.z < (*map_dim).x){ - // if (get_oct_vox( - // voxel, - // octree_descriptor_buffer, - // octree_attachment_lookup_buffer, - // octree_attachment_buffer, - // settings_buffer - // )){ - // voxel_data = 5; - // } else { - // voxel_data = 0; - // } - // } else { + if (setting(OCTENABLED) == 1 && voxel.x < (*map_dim).x && voxel.y < (*map_dim).x && voxel.z < (*map_dim).x){ + if (get_oct_vox( + voxel, + octree_descriptor_buffer, + octree_attachment_lookup_buffer, + octree_attachment_buffer, + settings_buffer + )){ + voxel_data = 5; + } else { + voxel_data = 0; + } + } else { voxel_data = map[voxel.x + (*map_dim).x * (voxel.y + (*map_dim).z * (voxel.z))]; } diff --git a/src/Application.cpp b/src/Application.cpp index 758137a..57c40a5 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -35,6 +35,10 @@ bool Application::init_clcaster() { raycaster->add_to_settings_buffer("octree_dimensions", "OCTDIM", (int64_t*)&MAP_X); + // TODO: ALLOW RVALUES FOR SETTINGS BUFFER + int64_t oct_enabled = 0; + raycaster->add_to_settings_buffer("using_octree", "OCTENABLED", &oct_enabled); + map = std::make_shared(MAP_X); // TODO: Implement this diff --git a/src/CLCaster.cpp b/src/CLCaster.cpp index 39ef2e4..bba2c42 100644 --- a/src/CLCaster.cpp +++ b/src/CLCaster.cpp @@ -1219,11 +1219,36 @@ bool CLCaster::remove_from_settings_buffer(std::string setting_name) { } bool CLCaster::release_settings_buffer() { + if (!release_buffer("settings_buffer")) return false; return true; } +bool CLCaster::overwrite_setting(std::string settings_name, int64_t *value) { + + bool success = true; + + if (settings_buffer == nullptr){ + + Logger::log("Trying to push settings to an uninitialized settings buffer", Logger::LogLevel::ERROR, __LINE__, __FILE__); + success = false; + + } else { + + if (settings_buffer_indices.count(settings_name)) { + + unsigned int postion = settings_buffer_indices[settings_name]; + settings_buffer[postion] = *value; + } else { + + Logger::log("No setting matching [" + settings_name +"]", Logger::LogLevel::ERROR, __LINE__, __FILE__); + success = false; + } + } + return success; +} + CLCaster::device::device(cl_device_id device_id, cl_platform_id platform_id) { diff --git a/src/Input.cpp b/src/Input.cpp index 5f79ec6..c59b3bd 100644 --- a/src/Input.cpp +++ b/src/Input.cpp @@ -55,6 +55,7 @@ void Input::handle_held_keys() { vr::MouseButtonReleased *e = static_cast(event.get()); held_mouse_buttons.erase(std::remove(held_mouse_buttons.begin(), held_mouse_buttons.end(), e->button), held_mouse_buttons.end()); } + } // Generate Held events for each of the held buttons and keys