Whoops, forgot to save the files, same commit as before

master
MitchellHansen 8 years ago
parent 51093beaca
commit 45627e6a85

@ -43,6 +43,8 @@ public:
int create_command_queue();
int check_cl_khr_gl_sharing();
int compile_kernel(std::string kernel_source, bool is_path, std::string kernel_name);
int create_buffer(std::string buffer_name, cl_uint size, void* data);
@ -60,11 +62,14 @@ public:
cl_kernel getKernel(std::string kernel_name);
cl_command_queue getCommandQueue();
bool was_init_valid();
private:
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;

@ -2,23 +2,32 @@
#include <SFML/System/Vector3.hpp>
#include <SFML/System/Vector2.hpp>
#include <Map.h>
#include "Old_map.h"
// What about a parent, child relationship between the raycaster and it's two
// different modes? Raycaster -> ClCaster, SoftwareCaster
class Camera;
class RayCaster {
public:
RayCaster(Map *map,
sf::Vector3<int> map_dimensions,
sf::Vector2<int> viewport_resolution);
RayCaster();
~RayCaster();
void setFOV(float fov);
void setResolution(sf::Vector2<int> resolution);
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 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;
sf::Color* CastRays(sf::Vector3<float> camera_direction, sf::Vector3<float> camera_position);
void moveCamera(sf::Vector2f v);
private:
sf::Vector3<int> map_dimensions;
Map *map;
Old_Map *map;
// The XY resolution of the viewport
sf::Vector2<int> resolution;

@ -1 +1,20 @@
#include "Renderer.h"
Renderer::Renderer() {
cl = new CL_Wrapper();
if (!cl->was_init_valid()) {
delete cl;
rc = new RayCaster();
}
}
void Renderer::register_camera(Camera *camera)
{
}
void Renderer::draw()
{
}

@ -4,6 +4,8 @@
#include "SFML/Graphics.hpp"
#include "CL_Wrapper.h"
#include "Camera.h"
#include "Old_map.h"
#include "RayCaster.h"
// Renderer needs to handle the distinction between a few difference circumstances.
// A.) The machine supports OpenCL and cl_khr_gl_sharing
@ -18,6 +20,9 @@
// intent of leaving it specialized to only the raycaster. Any further OpenCL
// work can use its own class
// Perhaps in the future there will be a container "scene" which will
// hold the current map, camera, and light objects. The renderer will
// then be passed that scene which it will then use to render with
class Renderer {
@ -26,9 +31,11 @@ public:
// The renderer needs all of the things that are required
// by CL in order to render the screen
void register_camera(Camera camera);
void register_camera(Camera* camera);
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 draw();
sf::RenderWindow* get_window();
@ -36,10 +43,19 @@ public:
private:
CL_Wrapper *cl;
RayCaster *rc;
bool sharing_supported = false;
sf::Uint8 *drawing_surface;
bool cl_supported = false;
sf::Uint8 *drawing_surface;
sf::RenderWindow* window;
std::vector<light> lights;
Old_Map* map;
Camera* camera;
sf::Uint8 *view_matrix;
};

@ -4,10 +4,17 @@
#include <math.h>
#include <fstream>
#include <sstream>
#include "Vector4.hpp"
const double PI = 3.141592653589793238463;
const float PI_F = 3.14159265358979f;
struct Light {
sf::Vector4f rgbi;
sf::Vector3f position;
sf::Vector3f direction_cartesian;
};
struct fps_counter {
public:
fps_counter(){

@ -2,15 +2,28 @@
CL_Wrapper::CL_Wrapper() {
acquire_platform_and_device();
// Check to see if acquiring the platform failed out
// This also catches when there are general errors,
// falling back to the known good software renderer
if (acquire_platform_and_device() == -1) {
std::cout << "Falling back to the software renderer" << std::endl;
return;
}
if (cl_khr_gl_sharing_fallback){
create_cl_context();
} else {
create_shared_context();
}
cl_supported = true;
// update cl_khr_gl_sharing_fallback's value
check_cl_khr_gl_sharing();
create_command_queue();
// Whether or not we can share GL contexts with our CL kernels
// Enables on-GPU editing and rendering of the screen buffer
if (cl_khr_gl_sharing_fallback){
create_cl_context();
} else {
create_shared_context();
}
create_command_queue();
}
@ -43,6 +56,13 @@ int CL_Wrapper::acquire_platform_and_device(){
cl_uint deviceIdCount = 0;
error = clGetDeviceIDs(plt_buf[i], CL_DEVICE_TYPE_ALL, 0, nullptr, &deviceIdCount);
// Check to see if we even have opencl on this machine
if (deviceIdCount == 0) {
cl_supported = false;
std::cout << "OpenCL does not appear to be supported on this machine" << std::endl;
return -1;
}
// Get the device ids
std::vector<cl_device_id> deviceIds(deviceIdCount);
error = clGetDeviceIDs(plt_buf[i], CL_DEVICE_TYPE_ALL, deviceIdCount, deviceIds.data(), NULL);
@ -100,18 +120,6 @@ int CL_Wrapper::acquire_platform_and_device(){
platform_id = current_best_device.platform;
device_id = current_best_device.id;
// Test for sharing
size_t ext_str_size = 1024;
char *ext_str = new char[ext_str_size];
clGetDeviceInfo(device_id, CL_DEVICE_EXTENSIONS, ext_str_size, ext_str, &ext_str_size);
if (std::string(ext_str).find("cl_khr_gl_sharing") == std::string::npos){
std::cout << "No support for the cl_khr_gl_sharing extension";
cl_khr_gl_sharing_fallback = true;
}
delete ext_str;
return 1;
};
@ -134,7 +142,7 @@ int CL_Wrapper::create_cl_context() {
if (assert(error, "clCreateContext"))
return -1;
return 0;
return 1;
}
@ -188,7 +196,7 @@ int CL_Wrapper::create_shared_context() {
if (assert(error, "clCreateContext"))
return -1;
return 0;
return 1;
}
int CL_Wrapper::create_command_queue(){
@ -200,7 +208,7 @@ int CL_Wrapper::create_command_queue(){
if (assert(error, "clCreateCommandQueue"))
return -1;
return 0;
return 1;
}
else {
std::cout << "Failed creating the command queue, context or device_id not initialized";
@ -208,6 +216,21 @@ int CL_Wrapper::create_command_queue(){
}
}
int CL_Wrapper::check_cl_khr_gl_sharing() {
// Test for sharing
size_t ext_str_size = 1024;
char *ext_str = new char[ext_str_size];
clGetDeviceInfo(device_id, CL_DEVICE_EXTENSIONS, ext_str_size, ext_str, &ext_str_size);
if (std::string(ext_str).find("cl_khr_gl_sharing") == std::string::npos) {
std::cout << "No support for the cl_khr_gl_sharing extension";
cl_khr_gl_sharing_fallback = true;
}
delete ext_str;
}
int CL_Wrapper::compile_kernel(std::string kernel_source, bool is_path, std::string kernel_name) {
const char* source;
@ -354,6 +377,10 @@ cl_context CL_Wrapper::getContext(){ return context; };
cl_kernel CL_Wrapper::getKernel(std::string kernel_name ){ return kernel_map.at(kernel_name); };
cl_command_queue CL_Wrapper::getCommandQueue(){ return command_queue; };
bool CL_Wrapper::was_init_valid() {
return cl_supported;
}
bool CL_Wrapper::assert(int error_code, std::string function_name){
// Just gonna do a little jump table here, just error codes so who cares

@ -2,12 +2,12 @@
#include <util.hpp>
#include <Ray.h>
RayCaster::RayCaster() {
}
RayCaster::RayCaster(
Map *map,
sf::Vector3<int> map_dimensions,
sf::Vector2<int> viewport_resolution ) {
void RayCaster::assign_map(Old_Map* map) {
this->map = map;
}
// Override values
//this.map_dimensions = new Vector3<int> (50, 50, 50);
//this.resolution = new Vector2<int> (200, 200);

Loading…
Cancel
Save