quick save before the main.cpp refactor

master
MitchellHansen 7 years ago
parent 0b42481020
commit 8c193acd40

@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.1)
set_property(GLOBAL PROPERTY USE_FOLDERS ON) set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Set the project name # Set the project name
set(PNAME Game) set(PNAME VoxelRaycaster)
project(${PNAME}) project(${PNAME})
# Set up variables, and find SFML # Set up variables, and find SFML

@ -0,0 +1,60 @@
#pragma once
#ifdef linux
#include <CL/cl.h>
#include <CL/opencl.h>
#elif defined _WIN32
// Good lord, windows.h overwrote the std::min() max() definitions
#define NOMINMAX
#include <windows.h>
// As if hardware is ever going to move away from 1.2
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
#include <CL/cl.h>
#include <CL/opencl.h>
#elif defined TARGET_OS_MAC
#include <OpenGL/gl.h>
#include <OpenGL/OpenGL.h>
#include <OpenCL/opencl.h>
#include <OpenCL/cl_gl_ext.h>
#include <OpenCL/cl_ext.h>
#endif
#include "util.hpp"
#include <iostream>
#include <chrono>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include "map/Old_Map.h"
#include "CLCaster.h"
#include "Vector4.hpp"
#include "Camera.h"
#include "Input.h"
#include "Pub_Sub.h"
#include "LightController.h"
#include "LightHandle.h"
#include "imgui/imgui-SFML.h"
#include "imgui/imgui.h"
#include "map/Map.h"
// Srsly people who macro error codes are the devil
#undef ERROR
#include "Logger.h"
class Application {
public:
const int WINDOW_X = 1536;
const int WINDOW_Y = 1024;
const int MAP_X = 256;
const int MAP_Y = 256;
const int MAP_Z = 256;
private:
static float elap_time();
};

@ -84,7 +84,7 @@ struct device_info {
struct PackedData; struct PackedData;
class Hardware_Caster { class CLCaster {
public: public:
@ -148,8 +148,8 @@ public:
* as rendering of the computed cast. * as rendering of the computed cast.
* *
*/ */
Hardware_Caster(); CLCaster();
virtual ~Hardware_Caster(); virtual ~CLCaster();
// Queries hardware, creates the command queue and context, and compiles kernel // Queries hardware, creates the command queue and context, and compiles kernel

@ -4,7 +4,7 @@
#include <numeric> #include <numeric>
#include "util.hpp" #include "util.hpp"
#include "Pub_Sub.h" #include "Pub_Sub.h"
#include "Hardware_Caster.h" #include "CLCaster.h"
#include "LightHandle.h" #include "LightHandle.h"
@ -48,12 +48,12 @@ struct PackedData {
}; };
class LightHandle; class LightHandle;
class Hardware_Caster; class CLCaster;
class LightController : public VrEventSubscriber { class LightController : public VrEventSubscriber {
public: public:
LightController(std::shared_ptr<Hardware_Caster> raycaster); LightController(std::shared_ptr<CLCaster> raycaster);
~LightController(); ~LightController();
// find a free light 'slot' and create // find a free light 'slot' and create

@ -0,0 +1,16 @@
#include "Application.h"
float Application::elap_time() {
static std::chrono::time_point<std::chrono::system_clock> start;
static bool started = false;
if (!started) {
start = std::chrono::system_clock::now();
started = true;
}
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_time = now - start;
return static_cast<float>(elapsed_time.count());
}

@ -1,10 +1,10 @@
#include "Hardware_Caster.h" #include "CLCaster.h"
Hardware_Caster::Hardware_Caster() {} CLCaster::CLCaster() {}
Hardware_Caster::~Hardware_Caster() {} CLCaster::~CLCaster() {}
bool Hardware_Caster::init() { bool CLCaster::init() {
Logger::log("Initializing the Hardware Caster", Logger::LogLevel::INFO); Logger::log("Initializing the Hardware Caster", Logger::LogLevel::INFO);
@ -68,7 +68,7 @@ bool Hardware_Caster::init() {
} }
bool Hardware_Caster::assign_map(std::shared_ptr<Old_Map> map) { bool CLCaster::assign_map(std::shared_ptr<Old_Map> map) {
this->map = map; this->map = map;
auto dimensions = map->getDimensions(); auto dimensions = map->getDimensions();
@ -82,7 +82,7 @@ bool Hardware_Caster::assign_map(std::shared_ptr<Old_Map> map) {
return true; return true;
} }
bool Hardware_Caster::release_map() { bool CLCaster::release_map() {
this->map = nullptr; this->map = nullptr;
@ -96,7 +96,7 @@ bool Hardware_Caster::release_map() {
} }
bool Hardware_Caster::assign_camera(std::shared_ptr<Camera> camera) { bool CLCaster::assign_camera(std::shared_ptr<Camera> camera) {
this->camera = camera; this->camera = camera;
@ -109,7 +109,7 @@ bool Hardware_Caster::assign_camera(std::shared_ptr<Camera> camera) {
return true; return true;
} }
bool Hardware_Caster::release_camera() { bool CLCaster::release_camera() {
this->camera = nullptr; this->camera = nullptr;
@ -122,7 +122,7 @@ bool Hardware_Caster::release_camera() {
return true; return true;
} }
bool Hardware_Caster::validate() { bool CLCaster::validate() {
Logger::log("Validating OpenCL kernel args", Logger::LogLevel::INFO); Logger::log("Validating OpenCL kernel args", Logger::LogLevel::INFO);
@ -163,7 +163,7 @@ bool Hardware_Caster::validate() {
} }
bool Hardware_Caster::create_texture_atlas(sf::Texture *t, sf::Vector2i tile_dim) { bool CLCaster::create_texture_atlas(sf::Texture *t, sf::Vector2i tile_dim) {
if (!create_image_buffer("texture_atlas", t->getSize().x * t->getSize().x * 4 * sizeof(float), t, CL_MEM_READ_ONLY)) if (!create_image_buffer("texture_atlas", t->getSize().x * t->getSize().x * 4 * sizeof(float), t, CL_MEM_READ_ONLY))
return false; return false;
@ -180,7 +180,7 @@ bool Hardware_Caster::create_texture_atlas(sf::Texture *t, sf::Vector2i tile_dim
return true; return true;
} }
bool Hardware_Caster::compute() { bool CLCaster::compute() {
// correlating work size with texture size? good, bad? // correlating work size with texture size? good, bad?
return run_kernel("raycaster", viewport_texture.getSize().x, viewport_texture.getSize().y); return run_kernel("raycaster", viewport_texture.getSize().x, viewport_texture.getSize().y);
@ -189,7 +189,7 @@ bool Hardware_Caster::compute() {
// There is a possibility that I would want to move this over to be all inside it's own // There is a possibility that I would want to move this over to be all inside it's own
// container to make it so it can be changed via CL_MEM_USE_HOST_PTR. But I doubt it // container to make it so it can be changed via CL_MEM_USE_HOST_PTR. But I doubt it
// would ever be called enough to warrent that // would ever be called enough to warrent that
bool Hardware_Caster::create_viewport(int width, int height, float v_fov, float h_fov) { bool CLCaster::create_viewport(int width, int height, float v_fov, float h_fov) {
// CL needs the screen resolution // CL needs the screen resolution
sf::Vector2i view_res(width, height); sf::Vector2i view_res(width, height);
@ -272,7 +272,7 @@ bool Hardware_Caster::create_viewport(int width, int height, float v_fov, float
} }
bool Hardware_Caster::assign_lights(std::vector<PackedData> *data) { bool CLCaster::assign_lights(std::vector<PackedData> *data) {
// Get a pointer to the packed light data // Get a pointer to the packed light data
this->lights = data; this->lights = data;
@ -290,11 +290,11 @@ bool Hardware_Caster::assign_lights(std::vector<PackedData> *data) {
return true; return true;
} }
void Hardware_Caster::draw(sf::RenderWindow* window) { void CLCaster::draw(sf::RenderWindow* window) {
window->draw(viewport_sprite); window->draw(viewport_sprite);
} }
bool Hardware_Caster::debug_quick_recompile() { bool CLCaster::debug_quick_recompile() {
if (!compile_kernel("../kernels/ray_caster_kernel.cl", true, "raycaster")) { if (!compile_kernel("../kernels/ray_caster_kernel.cl", true, "raycaster")) {
Logger::log("Failed to recompile kernel", Logger::LogLevel::WARN, __LINE__, __FILE__); Logger::log("Failed to recompile kernel", Logger::LogLevel::WARN, __LINE__, __FILE__);
@ -306,7 +306,7 @@ bool Hardware_Caster::debug_quick_recompile() {
} }
bool Hardware_Caster::aquire_hardware() { bool CLCaster::aquire_hardware() {
Logger::log("Acquiring OpenCL Hardware", Logger::LogLevel::INFO); Logger::log("Acquiring OpenCL Hardware", Logger::LogLevel::INFO);
@ -371,7 +371,7 @@ bool Hardware_Caster::aquire_hardware() {
return true; return true;
} }
void Hardware_Caster::save_config() { void CLCaster::save_config() {
Logger::log("Saving OpenCL hardware config", Logger::LogLevel::INFO); Logger::log("Saving OpenCL hardware config", Logger::LogLevel::INFO);
@ -384,7 +384,7 @@ void Hardware_Caster::save_config() {
output_file.close(); output_file.close();
} }
bool Hardware_Caster::load_config() { bool CLCaster::load_config() {
Logger::log("Loading hardware config", Logger::LogLevel::INFO); Logger::log("Loading hardware config", Logger::LogLevel::INFO);
@ -420,7 +420,7 @@ bool Hardware_Caster::load_config() {
return true; return true;
} }
bool Hardware_Caster::query_hardware() bool CLCaster::query_hardware()
{ {
Logger::log("Querying OpenCL hardware", Logger::LogLevel::INFO); Logger::log("Querying OpenCL hardware", Logger::LogLevel::INFO);
@ -531,7 +531,7 @@ bool Hardware_Caster::query_hardware()
return true; return true;
} }
bool Hardware_Caster::create_shared_context() bool CLCaster::create_shared_context()
{ {
// Hurray for standards! // Hurray for standards!
@ -589,7 +589,7 @@ bool Hardware_Caster::create_shared_context()
return true; return true;
} }
bool Hardware_Caster::create_command_queue() { bool CLCaster::create_command_queue() {
// If context and device_id have initialized // If context and device_id have initialized
if (context && device_id) { if (context && device_id) {
@ -610,7 +610,7 @@ bool Hardware_Caster::create_command_queue() {
return true; return true;
} }
bool Hardware_Caster::compile_kernel(std::string kernel_source, bool is_path, std::string kernel_name) { bool CLCaster::compile_kernel(std::string kernel_source, bool is_path, std::string kernel_name) {
Logger::log("Compiling OpenCL Kernel", Logger::LogLevel::INFO); Logger::log("Compiling OpenCL Kernel", Logger::LogLevel::INFO);
@ -677,7 +677,7 @@ bool Hardware_Caster::compile_kernel(std::string kernel_source, bool is_path, st
return true; return true;
} }
bool Hardware_Caster::set_kernel_arg( bool CLCaster::set_kernel_arg(
std::string kernel_name, std::string kernel_name,
int index, int index,
std::string buffer_name) { std::string buffer_name) {
@ -698,7 +698,7 @@ bool Hardware_Caster::set_kernel_arg(
} }
bool Hardware_Caster::create_image_buffer(std::string buffer_name, cl_uint size, sf::Texture* texture, cl_int access_type) { bool CLCaster::create_image_buffer(std::string buffer_name, cl_uint size, sf::Texture* texture, cl_int access_type) {
// I can imagine overwriting buffers will be common, so I think // I can imagine overwriting buffers will be common, so I think
// this is safe to overwrite / release old buffers quietly // this is safe to overwrite / release old buffers quietly
@ -723,7 +723,7 @@ bool Hardware_Caster::create_image_buffer(std::string buffer_name, cl_uint size,
return true; return true;
} }
bool Hardware_Caster::create_buffer(std::string buffer_name, cl_uint size, void* data, cl_mem_flags flags) { bool CLCaster::create_buffer(std::string buffer_name, cl_uint size, void* data, cl_mem_flags flags) {
// I can imagine overwriting buffers will be common, so I think // I can imagine overwriting buffers will be common, so I think
// this is safe to overwrite / release old buffers quietly // this is safe to overwrite / release old buffers quietly
@ -751,7 +751,7 @@ bool Hardware_Caster::create_buffer(std::string buffer_name, cl_uint size, void*
} }
bool Hardware_Caster::create_buffer(std::string buffer_name, cl_uint size, void* data) { bool CLCaster::create_buffer(std::string buffer_name, cl_uint size, void* data) {
// I can imagine overwriting buffers will be common, so I think // I can imagine overwriting buffers will be common, so I think
// this is safe to overwrite / release old buffers quietly // this is safe to overwrite / release old buffers quietly
@ -779,7 +779,7 @@ bool Hardware_Caster::create_buffer(std::string buffer_name, cl_uint size, void*
} }
bool Hardware_Caster::release_buffer(std::string buffer_name) { bool CLCaster::release_buffer(std::string buffer_name) {
if (buffer_map.count(buffer_name) > 0) { if (buffer_map.count(buffer_name) > 0) {
@ -802,7 +802,7 @@ bool Hardware_Caster::release_buffer(std::string buffer_name) {
} }
bool Hardware_Caster::store_buffer(cl_mem buffer, std::string buffer_name) { bool CLCaster::store_buffer(cl_mem buffer, std::string buffer_name) {
if (buffer_map.count(buffer_name) == 0) { if (buffer_map.count(buffer_name) == 0) {
buffer_map.emplace(std::make_pair(buffer_name, buffer)); buffer_map.emplace(std::make_pair(buffer_name, buffer));
@ -814,7 +814,7 @@ bool Hardware_Caster::store_buffer(cl_mem buffer, std::string buffer_name) {
} }
bool Hardware_Caster::run_kernel(std::string kernel_name, const int work_dim_x, const int work_dim_y) { bool CLCaster::run_kernel(std::string kernel_name, const int work_dim_x, const int work_dim_y) {
size_t global_work_size[2] = { static_cast<size_t>(work_dim_x), static_cast<size_t>(work_dim_y)}; size_t global_work_size[2] = { static_cast<size_t>(work_dim_x), static_cast<size_t>(work_dim_y)};
@ -857,7 +857,7 @@ bool Hardware_Caster::run_kernel(std::string kernel_name, const int work_dim_x,
return true; return true;
} }
void Hardware_Caster::print_kernel_arguments() void CLCaster::print_kernel_arguments()
{ {
compile_kernel("../kernels/print_arguments.cl", true, "printer"); compile_kernel("../kernels/print_arguments.cl", true, "printer");
set_kernel_arg("printer", 0, "map"); set_kernel_arg("printer", 0, "map");
@ -873,13 +873,13 @@ void Hardware_Caster::print_kernel_arguments()
run_kernel("printer", 1, 1); run_kernel("printer", 1, 1);
} }
cl_device_id Hardware_Caster::getDeviceID() { return device_id; }; cl_device_id CLCaster::getDeviceID() { return device_id; };
cl_platform_id Hardware_Caster::getPlatformID() { return platform_id; }; cl_platform_id CLCaster::getPlatformID() { return platform_id; };
cl_context Hardware_Caster::getContext() { return context; }; cl_context CLCaster::getContext() { return context; };
cl_kernel Hardware_Caster::getKernel(std::string kernel_name) { return kernel_map.at(kernel_name); }; cl_kernel CLCaster::getKernel(std::string kernel_name) { return kernel_map.at(kernel_name); };
cl_command_queue Hardware_Caster::getCommandQueue() { return command_queue; }; cl_command_queue CLCaster::getCommandQueue() { return command_queue; };
bool Hardware_Caster::cl_assert(int error_code) { bool CLCaster::cl_assert(int error_code) {
if (error_code == CL_SUCCESS || error_code == 1) if (error_code == CL_SUCCESS || error_code == 1)
return false; return false;
@ -888,7 +888,7 @@ bool Hardware_Caster::cl_assert(int error_code) {
} }
std::string Hardware_Caster::cl_err_lookup(int error_code) { std::string CLCaster::cl_err_lookup(int error_code) {
std::string err_msg = ""; std::string err_msg = "";
@ -1080,16 +1080,16 @@ std::string Hardware_Caster::cl_err_lookup(int error_code) {
case CL_PLATFORM_NOT_FOUND_KHR: case CL_PLATFORM_NOT_FOUND_KHR:
err_msg = "CL_PLATFORM_NOT_FOUND_KHR"; err_msg = "CL_PLATFORM_NOT_FOUND_KHR";
break; break;
case Hardware_Caster::SHARING_NOT_SUPPORTED: case CLCaster::SHARING_NOT_SUPPORTED:
err_msg = "SHARING_NOT_SUPPORTED"; err_msg = "SHARING_NOT_SUPPORTED";
break; break;
case Hardware_Caster::OPENCL_NOT_SUPPORTED: case CLCaster::OPENCL_NOT_SUPPORTED:
err_msg = "OPENCL_NOT_SUPPORTED"; err_msg = "OPENCL_NOT_SUPPORTED";
break; break;
case Hardware_Caster::OPENCL_ERROR: case CLCaster::OPENCL_ERROR:
err_msg = "OPENCL_ERROR"; err_msg = "OPENCL_ERROR";
break; break;
case Hardware_Caster::ERR: case CLCaster::ERR:
err_msg = "ERROR"; err_msg = "ERROR";
break; break;
default: default:
@ -1100,7 +1100,7 @@ std::string Hardware_Caster::cl_err_lookup(int error_code) {
} }
Hardware_Caster::device::device(cl_device_id device_id, cl_platform_id platform_id) { CLCaster::device::device(cl_device_id device_id, cl_platform_id platform_id) {
this->device_id = device_id; this->device_id = device_id;
this->platform_id = platform_id; this->platform_id = platform_id;
@ -1135,7 +1135,7 @@ Hardware_Caster::device::device(cl_device_id device_id, cl_platform_id platform_
} }
Hardware_Caster::device::device(const device& d) { CLCaster::device::device(const device& d) {
// member values, copy individually // member values, copy individually
device_id = d.device_id; device_id = d.device_id;
@ -1148,7 +1148,7 @@ Hardware_Caster::device::device(const device& d) {
} }
void Hardware_Caster::device::print(std::ostream& stream) const { void CLCaster::device::print(std::ostream& stream) const {
stream << "\n\tDevice ID : " << device_id << std::endl; stream << "\n\tDevice ID : " << device_id << std::endl;
stream << "\tDevice Name : " << data.device_name << std::endl; stream << "\tDevice Name : " << data.device_name << std::endl;
@ -1180,6 +1180,6 @@ void Hardware_Caster::device::print(std::ostream& stream) const {
} }
void Hardware_Caster::device::print_packed_data(std::ostream& stream) { void CLCaster::device::print_packed_data(std::ostream& stream) {
stream.write(reinterpret_cast<char*>(&data), sizeof(data)); stream.write(reinterpret_cast<char*>(&data), sizeof(data));
} }

@ -1,6 +1,6 @@
#include "LightController.h" #include "LightController.h"
LightController::LightController(std::shared_ptr<Hardware_Caster> raycaster) : packed_data_array(reserved_count), open_list(reserved_count) { LightController::LightController(std::shared_ptr<CLCaster> raycaster) : packed_data_array(reserved_count), open_list(reserved_count) {
// initialize the open list with numbers 1 -> open_list.size() // initialize the open list with numbers 1 -> open_list.size()
std::iota(open_list.begin(), open_list.end(), 0); std::iota(open_list.begin(), open_list.end(), 0);

@ -1,13 +1,9 @@
 #ifdef linux
// This has to be up here or else glew will complain
//#include "GL_Testing.h"
#ifdef linux
#include <CL/cl.h> #include <CL/cl.h>
#include <CL/opencl.h> #include <CL/opencl.h>
#elif defined _WIN32 #elif defined _WIN32
// Good lord, the C++ std overwrote windows.h min() max() definitions // Good lord, windows.h overwrote the std::min() max() definitions
#define NOMINMAX #define NOMINMAX
#include <windows.h> #include <windows.h>
@ -30,7 +26,7 @@
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include <SFML/Network.hpp> #include <SFML/Network.hpp>
#include "map/Old_Map.h" #include "map/Old_Map.h"
#include "Hardware_Caster.h" #include "CLCaster.h"
#include "Vector4.hpp" #include "Vector4.hpp"
#include "Camera.h" #include "Camera.h"
#include "Input.h" #include "Input.h"
@ -45,28 +41,15 @@
#undef ERROR #undef ERROR
#include "Logger.h" #include "Logger.h"
const int WINDOW_X = 1536; const int WINDOW_X = 1536;
const int WINDOW_Y = 1024; const int WINDOW_Y = 1024;
const int WORK_SIZE = WINDOW_X * WINDOW_Y;
const int MAP_X = 256; const int MAP_X = 256;
const int MAP_Y = 256; const int MAP_Y = 256;
const int MAP_Z = 256; const int MAP_Z = 256;
float elap_time(){ float elap_time(){
static std::chrono::time_point<std::chrono::system_clock> start;
static bool started = false;
if (!started){
start = std::chrono::system_clock::now();
started = true;
}
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_time = now - start;
return static_cast<float>(elapsed_time.count());
} }
sf::Sprite window_sprite; sf::Sprite window_sprite;
@ -98,7 +81,7 @@ int main() {
window.resetGLStates(); window.resetGLStates();
// Start up the raycaster // Start up the raycaster
std::shared_ptr<Hardware_Caster> raycaster(new Hardware_Caster()); std::shared_ptr<CLCaster> raycaster(new CLCaster());
if (!raycaster->init()) if (!raycaster->init())
abort(); abort();

Loading…
Cancel
Save