Got the octree data to the GPU and it's traversing it, but it having some corruption issues. Endianness???

This commit is contained in:
MitchellHansen
2017-09-24 00:50:09 -07:00
parent ba11f9c081
commit ebce781eb3
12 changed files with 403 additions and 152 deletions

View File

@@ -3,7 +3,7 @@
#include "imgui/imgui-SFML.h"
Application::Application() {
srand(time(nullptr));
//srand(time(nullptr));
window = std::make_shared<sf::RenderWindow>(sf::VideoMode(WINDOW_X, WINDOW_Y), "SFML");
window->setMouseCursorVisible(false);
@@ -23,7 +23,7 @@ Application::~Application() {
bool Application::init_clcaster() {
Map _map(32);
//Map _map(32);
//return 0;
// Start up the raycaster
@@ -38,6 +38,10 @@ bool Application::init_clcaster() {
// Send the data to the GPU
raycaster->assign_map(map);
octree = std::make_shared<Map>(32);
raycaster->assign_octree(octree);
// Create a new camera with (starting position, direction)
camera = std::make_shared<Camera>(
sf::Vector3f(50, 50, 50),
@@ -90,6 +94,8 @@ bool Application::init_events() {
window_handler->subscribe_to_publisher(&input_handler, vr::Event::EventType::Closed);
window_handler->subscribe_to_publisher(&input_handler, vr::Event::EventType::KeyPressed);
//camera->subscribe_to_publisher(&input_handler, vr::Event::EventType::JoystickMoved);
return true;
}
@@ -234,6 +240,47 @@ bool Application::game_loop() {
ImGui::End();
ImGui::Begin("Controller debugger");
ImDrawList* draw_list = ImGui::GetWindowDrawList();
static ImVec4 col = ImVec4(1.0f, 0.0f, 1.0f, 1.0f);
const ImVec2 p = ImGui::GetCursorScreenPos();
const ImU32 col32 = ImColor(col);
std::vector<float> axis_values = {
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::X) / 2,
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::Y) / 2,
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::U) / 2,
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::R) / 2,
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::Z) / 2,
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::V) / 2
};
ImGui::Columns(3, "Axis's"); // 4-ways, with border
ImGui::Separator();
ImGui::Text("X Y"); ImGui::NextColumn();
ImGui::Text("U R"); ImGui::NextColumn();
ImGui::Text("Z V"); ImGui::NextColumn();
ImGui::Separator();
for (int i = 0; i < 3; i++) {
float offset = ImGui::GetColumnWidth(i);
draw_list->AddLine(ImVec2(p.x + 0 + offset * i, p.y + 50), ImVec2(p.x + 100 + offset * i, p.y + 50), col32, 1.0);
draw_list->AddLine(ImVec2(p.x + 50 + offset * i, p.y + 0), ImVec2(p.x + 50 + offset * i, p.y + 100), col32, 1.0);
draw_list->AddCircleFilled(ImVec2(p.x + axis_values[2 * i] + 50 + offset * i, p.y + axis_values[2 * i + 1] + 50), 6, col32, 32);
ImGui::Dummy(ImVec2(100, 100));
ImGui::NextColumn();
}
ImGui::End();
//ImGui::ShowTestWindow();
ImGui::Render();
// ImGUI messes up somthing in the SFML GL state, so we need a single draw call to right things

View File

@@ -49,7 +49,6 @@ bool CLCaster::init() {
Logger::log("Failed to create a OpenCL command queue", Logger::LogLevel::ERROR, __LINE__, __FILE__);
return false;
}
if (!compile_kernel("../kernels/ray_caster_kernel.cl", true, "raycaster")) {
Logger::log("Failed to compile the kernel", Logger::LogLevel::ERROR, __LINE__, __FILE__);
@@ -75,7 +74,6 @@ bool CLCaster::assign_map(std::shared_ptr<Old_Map> map) {
if (!create_buffer("map", sizeof(char) * dimensions.x * dimensions.y * dimensions.z, map->get_voxel_data()))
return false;
if (!create_buffer("map_dimensions", sizeof(int) * 3, &dimensions))
return false;
@@ -88,7 +86,6 @@ bool CLCaster::release_map() {
if (!release_buffer("map"))
return false;
if (!release_buffer("map_dimensions"))
return false;
@@ -96,13 +93,45 @@ bool CLCaster::release_map() {
}
bool CLCaster::assign_octree(std::shared_ptr<Map> octree) {
this->octree = octree;
if (!create_buffer("octree_descriptor_buffer", octree->octree.buffer_size, &octree->octree.descriptor_buffer))
return false;
if (!create_buffer("octree_attachment_lookup_buffer", octree->octree.buffer_size, &octree->octree.attachment_lookup))
return false;
if (!create_buffer("octree_attachment_buffer", octree->octree.buffer_size, &octree->octree.attachment_buffer))
return false;
if (!create_buffer("settings_buffer", sizeof(uint64_t), &octree->octree.root_index))
return false;
return true;
}
bool CLCaster::release_octree()
{
this->octree = nullptr;
if (!release_buffer("octree_descriptor_buffer"))
return false;
if (!release_buffer("octree_attachment_lookup_buffer"))
return false;
if (!release_buffer("octree_attachment_buffer"))
return false;
if (!release_buffer("settings_buffer"))
return false;
return true;
}
bool CLCaster::assign_camera(std::shared_ptr<Camera> camera) {
this->camera = camera;
if (!create_buffer("camera_direction", sizeof(float) * 4, (void*)camera->get_direction_pointer(), CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR))
return false;
if (!create_buffer("camera_position", sizeof(float) * 4, (void*)camera->get_position_pointer(), CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR))
return false;
@@ -115,7 +144,6 @@ bool CLCaster::release_camera() {
if (!release_buffer("camera_direction"))
return false;
if (!release_buffer("camera_position"))
return false;
@@ -154,10 +182,14 @@ bool CLCaster::validate() {
set_kernel_arg("raycaster", 6, "lights");
set_kernel_arg("raycaster", 7, "light_count");
set_kernel_arg("raycaster", 8, "image");
set_kernel_arg("raycaster", 9, "seed");
set_kernel_arg("raycaster", 10, "texture_atlas");
set_kernel_arg("raycaster", 11, "atlas_dim");
set_kernel_arg("raycaster", 12, "tile_dim");
//set_kernel_arg("raycaster", 9, "seed");
set_kernel_arg("raycaster", 9, "texture_atlas");
set_kernel_arg("raycaster", 10, "atlas_dim");
set_kernel_arg("raycaster", 11, "tile_dim");
set_kernel_arg("raycaster", 12, "octree_descriptor_buffer");
set_kernel_arg("raycaster", 13, "octree_attachment_lookup_buffer");
set_kernel_arg("raycaster", 14, "octree_attachment_buffer");
set_kernel_arg("raycaster", 15, "settings_buffer");
return true;
@@ -173,7 +205,6 @@ bool CLCaster::create_texture_atlas(sf::Texture *t, sf::Vector2i tile_dim) {
if (!create_buffer("atlas_dim", sizeof(sf::Vector2u) , &v))
return false;
if (!create_buffer("tile_dim", sizeof(sf::Vector2i), &tile_dim))
return false;
@@ -283,7 +314,6 @@ bool CLCaster::assign_lights(std::vector<PackedData> *data) {
if (!create_buffer("lights", packed_size * light_count, lights->data(), CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR))
return false;
if (!create_buffer("light_count", 8, &light_count))
return false;
@@ -1080,18 +1110,6 @@ std::string CLCaster::cl_err_lookup(int error_code) {
case CL_PLATFORM_NOT_FOUND_KHR:
err_msg = "CL_PLATFORM_NOT_FOUND_KHR";
break;
case CLCaster::SHARING_NOT_SUPPORTED:
err_msg = "SHARING_NOT_SUPPORTED";
break;
case CLCaster::OPENCL_NOT_SUPPORTED:
err_msg = "OPENCL_NOT_SUPPORTED";
break;
case CLCaster::OPENCL_ERROR:
err_msg = "OPENCL_ERROR";
break;
case CLCaster::ERR:
err_msg = "ERROR";
break;
default:
err_msg = "UNKNOWN_ERROR";
}

View File

@@ -167,23 +167,39 @@ void Camera::recieve_event(VrEventPublisher* publisher, std::unique_ptr<vr::Even
vr::JoystickMoved *joystick_event = static_cast<vr::JoystickMoved*>(event.get());
if (joystick_event->axis == sf::Joystick::Axis::X) {
movement.x -= joystick_event->position / 5;
//add_relative_impulse(Camera::DIRECTION::FORWARD, joystick_event->position);
if (joystick_event->position > 0)
add_relative_impulse(Camera::DIRECTION::RIGHT, joystick_event->position / 100);
else
add_relative_impulse(Camera::DIRECTION::LEFT, joystick_event->position / 100);
}
else if (joystick_event->axis == sf::Joystick::Axis::Y) {
movement.y += joystick_event->position / 5;
//add_relative_impulse(Camera::DIRECTION::RIGHT, joystick_event->position);
if (joystick_event->position > 0)
add_relative_impulse(Camera::DIRECTION::FORWARD, joystick_event->position / 100);
else
add_relative_impulse(Camera::DIRECTION::REARWARD, joystick_event->position / 100);
}
//else if (joystick_event->axis == sf::Joystick::Axis::Z) {
// add_relative_impulse(Camera::DIRECTION::DOWN, joystick_event->position);
//}
else if (joystick_event->axis == sf::Joystick::Axis::Z) {
if (joystick_event->position > 0)
add_relative_impulse(Camera::DIRECTION::DOWN, joystick_event->position / 100);
else
add_relative_impulse(Camera::DIRECTION::UP, joystick_event->position / 100);
}
else if (joystick_event->axis == sf::Joystick::Axis::U) {
slew_camera(sf::Vector2f(
deltas.y / 1200.0f,
deltas.x / 1200.0f
));
}
}
}
void Camera::look_at_center() {
direction = CartToNormalizedSphere(sf::Vector3f(75, 75, 75) - position);
direction = CartToNormalizedSphere(sf::Vector3f(60, 60, 35) - position);
}
sf::Vector2f* Camera::get_direction_pointer() {

View File

@@ -2,6 +2,7 @@
#include <iostream>
#include <memory>
#include "imgui/imgui-SFML.h"
#include "Logger.h"
Input::Input() :
@@ -22,9 +23,8 @@ void Input::consume_sf_events(sf::RenderWindow *window) {
sf::Event e;
while (window->pollEvent(e)) {
ImGui::SFML::ProcessEvent(e);
sf_event_queue.push_back(e);
ImGui::SFML::ProcessEvent(e);
}
transpose_sf_events(sf_event_queue);
@@ -121,6 +121,7 @@ void Input::dispatch_events() {
void Input::transpose_sf_events(std::list<sf::Event> sf_event_queue) {
for (auto sf_event: sf_event_queue) {
switch(sf_event.type) {

View File

@@ -70,16 +70,16 @@ void LightHandle::recieve_event(VrEventPublisher* publisher, std::unique_ptr<vr:
vr::JoystickMoved *joystick_event = static_cast<vr::JoystickMoved*>(event.get());
if (joystick_event->axis == sf::Joystick::Axis::X) {
movement.x = -joystick_event->position / 5;
movement.x = -joystick_event->position / 100;
//add_relative_impulse(Camera::DIRECTION::FORWARD, joystick_event->position);
}
else if (joystick_event->axis == sf::Joystick::Axis::Y) {
movement.y = joystick_event->position / 5;
movement.y = joystick_event->position / 100;
//add_relative_impulse(Camera::DIRECTION::RIGHT, joystick_event->position);
}
//else if (joystick_event->axis == sf::Joystick::Axis::Z) {
// add_relative_impulse(Camera::DIRECTION::DOWN, joystick_event->position);
//}
else if (joystick_event->axis == sf::Joystick::Axis::Z) {
movement.y = joystick_event->position / 100;
}
}
}

View File

@@ -12,7 +12,7 @@ Map::Map(uint32_t dimensions) {
// randomly set the voxel data for testing
for (uint64_t i = 0; i < dimensions * dimensions * dimensions; i++) {
if (rand() % 25 < 2)
if (i % 2 == 0)
voxel_data[i] = 1;
else
voxel_data[i] = 0;