Whoops, forgot to remove the old stuff
This commit is contained in:
@@ -1,112 +0,0 @@
|
||||
#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>
|
||||
|
||||
// Note: windows.h must be included before Gl/GL.h
|
||||
#include <windows.h>
|
||||
#include <GL/GL.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() override;
|
||||
|
||||
// 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, retrieving 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) override;
|
||||
|
||||
void assign_lights(std::vector<char> *data) override;
|
||||
void assign_map(Old_Map *map) override;
|
||||
void assign_camera(Camera *camera) override;
|
||||
void validate() override;
|
||||
|
||||
// TODO: Hoist this to the base class
|
||||
void create_texture_atlas(sf::Texture *t, sf::Vector2i tile_dim);
|
||||
|
||||
|
||||
// draw will abstract the gl sharing and software rendering
|
||||
// methods of retrieving the screen buffer
|
||||
void compute() override;
|
||||
void draw(sf::RenderWindow* window) override;
|
||||
|
||||
|
||||
int debug_quick_recompile();
|
||||
void test_edit_viewport(int width, int height, float v_fov, float h_fov);
|
||||
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, sf::Texture* texture);
|
||||
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);
|
||||
|
||||
void print_kernel_arguments();
|
||||
|
||||
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();
|
||||
|
||||
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;
|
||||
|
||||
};
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
#pragma once
|
||||
#include <SFML/System/Vector3.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <Map.h>
|
||||
#include "Old_Map.h"
|
||||
#include "Camera.h"
|
||||
#include "LightController.h"
|
||||
|
||||
class RayCaster {
|
||||
public:
|
||||
|
||||
enum ERROR_CODES {
|
||||
SHARING_NOT_SUPPORTED = 800,
|
||||
OPENCL_NOT_SUPPORTED = 801,
|
||||
OPENCL_ERROR = 802,
|
||||
ERR = 803
|
||||
};
|
||||
|
||||
RayCaster();
|
||||
virtual ~RayCaster();
|
||||
|
||||
virtual int init() = 0;
|
||||
|
||||
virtual void assign_map(Old_Map *map) = 0;
|
||||
virtual void assign_camera(Camera *camera) = 0;
|
||||
virtual void create_viewport(int width, int height, float v_fov, float h_fov) = 0;
|
||||
virtual void assign_lights(std::vector<char> *data) = 0;
|
||||
virtual void validate() = 0;
|
||||
|
||||
// draw will abstract the gl sharing and software rendering
|
||||
// methods of retrieving the screen buffer
|
||||
virtual void compute() = 0;
|
||||
virtual void draw(sf::RenderWindow* window) = 0;
|
||||
|
||||
protected:
|
||||
|
||||
sf::Sprite viewport_sprite;
|
||||
sf::Texture viewport_texture;
|
||||
|
||||
Old_Map * map = nullptr;
|
||||
Camera *camera = nullptr;
|
||||
// std::vector<LightController::PackedData> *lights;
|
||||
std::vector<char> *lights;
|
||||
int light_count = 0;
|
||||
sf::Uint8 *viewport_image = nullptr;
|
||||
sf::Vector4f *viewport_matrix = nullptr;
|
||||
sf::Vector2i viewport_resolution;
|
||||
|
||||
int error = 0;
|
||||
|
||||
};
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#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) {
|
||||
this->camera = camera;
|
||||
}
|
||||
|
||||
void Renderer::draw() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
#ifndef GAME_RENDERER_H
|
||||
#define GAME_RENDERER_H
|
||||
|
||||
#include "SFML/Graphics.hpp"
|
||||
|
||||
#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
|
||||
// Everything is normal, rendering is handled on-gpu
|
||||
// B.) The machine support Opencl and NOT cl_khr_gl_sharing
|
||||
// For every frame we have to pull the screen buffer from the GPU's memory
|
||||
// C.) The machine does not support OpenCL
|
||||
// We must use the fallback software renderer
|
||||
|
||||
// Renderer will hold its own CL_Renderer class which contains all of the data
|
||||
// and functionality that the CL_Wrapper class currently does, but with the
|
||||
// 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 {
|
||||
|
||||
public:
|
||||
Renderer();
|
||||
|
||||
// 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_map(Old_Map* map);
|
||||
void register_lights();
|
||||
void create_viewport(float v_fov, float h_fov, int height, int width);
|
||||
void register_light(LightController l);
|
||||
|
||||
void draw();
|
||||
sf::RenderWindow* get_window();
|
||||
|
||||
private:
|
||||
|
||||
RayCaster *rc;
|
||||
|
||||
bool sharing_supported = false;
|
||||
bool cl_supported = false;
|
||||
|
||||
sf::Uint8 *drawing_surface;
|
||||
sf::RenderWindow* window;
|
||||
|
||||
std::vector<LightController> lights;
|
||||
Old_Map* map;
|
||||
Camera* camera;
|
||||
sf::Uint8 *view_matrix;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,35 +0,0 @@
|
||||
#include "RayCaster.h"
|
||||
#include <thread>
|
||||
|
||||
class Software_Caster : public RayCaster
|
||||
{
|
||||
public:
|
||||
Software_Caster();
|
||||
|
||||
virtual ~Software_Caster();
|
||||
|
||||
int init() override;
|
||||
|
||||
// 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, retrieving 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) override;
|
||||
|
||||
void assign_lights(std::vector<char> *data) override;
|
||||
void assign_map(Old_Map *map) override;
|
||||
void assign_camera(Camera *camera) override;
|
||||
void validate() override;
|
||||
|
||||
// draw will abstract the gl sharing and software rendering
|
||||
// methods of retrieving the screen buffer
|
||||
void compute() override;
|
||||
void draw(sf::RenderWindow* window) override;
|
||||
|
||||
private:
|
||||
|
||||
void cast_viewport();
|
||||
void cast_thread(int start_id, int end_id);
|
||||
void cast_ray(int id);
|
||||
void blit_pixel(sf::Color color, sf::Vector2i position, sf::Vector3i mask);
|
||||
sf::Color global_light(sf::Color in, sf::Vector3i mask);
|
||||
};
|
||||
Reference in New Issue
Block a user