Lots of work done moving the various raycasting implementations over to a

consolidated RayCaster class.
This commit is contained in:
MitchellHansen
2016-11-02 00:09:32 -07:00
parent 45627e6a85
commit 518cc757a3
9 changed files with 874 additions and 23 deletions

View File

@@ -22,11 +22,11 @@
#endif
struct device {
cl_device_id id;
cl_device_type type;
cl_uint clock_frequency;
char version[128];
cl_platform_id platform;
cl_device_id id;
cl_device_type type;
cl_uint clock_frequency;
char version[128];
cl_platform_id platform;
cl_uint comp_units;
};

104
include/Hardware_Caster.h Normal file
View File

@@ -0,0 +1,104 @@
#pragma once
#include <RayCaster.h>
#include <vector>
#include <iostream>
#include "util.hpp"
#include <map>
#include <string.h>
#ifdef linux
#include <CL/cl.h>
#include <CL/opencl.h>
#include <GL/glx.h>
#elif defined _WIN32
#include <CL/cl_gl.h>
#include <CL/cl.h>
#include <CL/opencl.h>
#include <GL/GL.h>
#include <windows.h>
#elif defined TARGET_OS_MAC
# include <OpenGL/OpenGL.h>
# include <OpenCL/opencl.h>
#endif
struct device {
cl_device_id id;
cl_device_type type;
cl_uint clock_frequency;
char version[128];
cl_platform_id platform;
cl_uint comp_units;
};
class Hardware_Caster : public RayCaster
{
public:
Hardware_Caster();
virtual ~Hardware_Caster();
int init();
// In interop mode, this will create a gl texture that we share
// Otherwise, it will create the pixel buffer and pass that in as an image, retreiving it each draw
// Both will create the view matrix, view res buffer
void create_viewport(int width, int height, float v_fov, float h_fov);
void assign_light(Light light);
void assign_map(Old_Map *map);
void assign_camera(Camera *camera);
// draw will abstract the gl sharing and software rendering
// methods of retrieving the screen buffer
void draw(sf::RenderWindow* window) = 0;
private:
int acquire_platform_and_device();
int create_shared_context();
int create_command_queue();
int check_cl_khr_gl_sharing();
int create_image_buffer(std::string buffer_name, cl_uint size, void* data);
int create_buffer(std::string buffer_name, cl_uint size, void* data);
int create_buffer(std::string buffer_name, cl_uint size, void* data, cl_mem_flags flags);
int store_buffer(cl_mem, std::string buffer_name);
int release_buffer(std::string buffer_name);
int compile_kernel(std::string kernel_source, bool is_path, std::string kernel_name);
int set_kernel_arg(std::string kernel_name, int index, std::string buffer_name);
int run_kernel(std::string kernel_name, const int work_size);
bool assert(int error_code, std::string function_name);
cl_device_id getDeviceID();
cl_platform_id getPlatformID();
cl_context getContext();
cl_kernel getKernel(std::string kernel_name);
cl_command_queue getCommandQueue();
bool was_init_valid();
int error = 0;
bool initialized = false;
bool cl_khr_gl_sharing_fallback = false;
bool cl_supported = false;
cl_platform_id platform_id;
cl_device_id device_id;
cl_context context;
cl_command_queue command_queue;
std::map<std::string, cl_kernel> kernel_map;
std::map<std::string, cl_mem> buffer_map;
};

View File

@@ -18,7 +18,6 @@ public:
Old_Map(sf::Vector3i dim);
~Old_Map();
void generate_from_data(char* dat, int len);
void generate_terrain();
sf::Vector3i getDimensions();

View File

@@ -3,30 +3,40 @@
#include <SFML/System/Vector2.hpp>
#include <Map.h>
#include "Old_map.h"
#include "Camera.h"
// What about a parent, child relationship between the raycaster and it's two
// different modes? Raycaster -> ClCaster, SoftwareCaster
class Camera;
class RayCaster {
public:
enum ERROR_CODES {
SHARING_NOT_SUPPORTED = 800,
OPENCL_NOT_SUPPORTED = 801,
OPENCL_ERROR = 802,
ERROR = 803
};
RayCaster();
~RayCaster();
virtual ~RayCaster();
virtual int init() = 0;
virtual void assign_map(Old_Map *map) = 0;
virtual void assign_camera(Camera *camera) = 0;
virtual void assign_viewport(int width, int height, float v_fov, float h_fov) = 0;
virtual void create_viewport(int width, int height, float v_fov, float h_fov) = 0;
virtual void assign_light(Light light) = 0;
// draw will abstract the gl sharing and software rendering
// methods of retrieving the screen buffer
virtual void draw(sf::RenderWindow* window) = 0;
private:
protected:
sf::Vector3<int> map_dimensions;
sf::Sprite viewport_sprite;
sf::Texture viewport_texture;
// A reference to the map
Old_Map *map;
// The XY resolution of the viewport
@@ -38,7 +48,6 @@ private:
// The direction of the camera in POLAR coordinates
sf::Vector3<float> camera_direction;
// Convert the polar coordinates to CARTESIAN
sf::Vector3<float> camera_direction_cartesian;

View File

@@ -9,12 +9,12 @@ Renderer::Renderer() {
}
}
void Renderer::register_camera(Camera *camera)
{
void Renderer::register_camera(Camera *camera) {
this->camera = camera;
}
void Renderer::draw() {
}
void Renderer::draw()
{
}

View File

@@ -35,7 +35,7 @@ public:
void register_map(Old_Map* map);
void register_lights();
void create_viewport(float v_fov, float h_fov, int height, int width);
void register_light(light l);
void register_light(Light l);
void draw();
sf::RenderWindow* get_window();
@@ -51,7 +51,7 @@ private:
sf::Uint8 *drawing_surface;
sf::RenderWindow* window;
std::vector<light> lights;
std::vector<Light> lights;
Old_Map* map;
Camera* camera;
sf::Uint8 *view_matrix;