The new rendering method now works on the full compat case.

Added a kernel to help test opencl data passing
renamed the kernels, buffers, etc.
This commit is contained in:
MitchellHansen
2016-11-04 03:28:23 -07:00
parent 5528e03c69
commit d1bd4ce667
13 changed files with 267 additions and 685 deletions

View File

@@ -1,138 +0,0 @@
#pragma once
#include <SFML/Graphics.hpp>
#include <list>
class Curses {
public:
struct Slot {
Slot(wchar_t unicode_value_,
sf::Color font_color_,
sf::Color backfill_color_) :
unicode_value(unicode_value_),
font_color(font_color_),
backfill_color(backfill_color_)
{};
wchar_t unicode_value;
sf::Color font_color;
sf::Color backfill_color;
};
struct Tile {
public:
Tile(sf::Vector2i position_) :
blank_standby(L'\u0020', sf::Color::Transparent, sf::Color::Black),
position(position_)
{ };
private:
Slot blank_standby;
int index = 0; // What index in the vector are we. Backbone for blinking and scrolling
int ratio_counter = 0; // Secondary counter to hold index positions for (ratio) length of time
int ratio_value = 0;
std::vector<Slot> slot_stack; // The icon that aligns with the index
sf::Vector2i position; // Position of the text, and backfill
public:
void set_ratio(int ratio_) {
ratio_value = ratio_;
}
sf::Vector2i getPosition() const {
return position;
}
void push_back(Slot s) {
slot_stack.push_back(s);
}
void clear_and_set(Slot s) {
slot_stack.clear();
slot_stack.push_back(s);
}
void clear() {
slot_stack.clear();
}
sf::Color current_font_color() {
if (slot_stack.size() > 0)
return slot_stack.at(index).font_color;
else
return blank_standby.font_color;
}
sf::Color current_backfill_color() {
if (slot_stack.size() > 0)
return slot_stack.at(index).backfill_color;
else
return blank_standby.backfill_color;
}
wchar_t current_unicode_value() {
if (slot_stack.size() > 0)
return slot_stack.at(index).unicode_value;
else
return blank_standby.unicode_value;
}
void inc_index() {
if (index >= slot_stack.size() - 1) {
index = 0;
}
else if (ratio_counter == ratio_value) {
ratio_counter = 0;
index++;
}
else
ratio_counter++;
}
};
Curses(sf::Vector2i tile_size_, sf::Vector2i grid_dimensions);
~Curses();
void Update(double delta_time_);
void Render();
void setTile(Tile tile_);
void setTiles(std::vector<Tile> tiles_); // Can be seperate, non-adjacent tiles
void Clear();
Tile* getTile(sf::Vector2i position_);
std::vector<Curses::Tile*> getTiles(sf::Vector2i start_, sf::Vector2i end_);
void ResizeTiles(sf::Vector2i size_);
void ResizeTileGrid(sf::Vector2i grid_dimensions_);
void setBlink(int ratio_, sf::Vector2i position_);
void setScroll(int ratio_, sf::Vector2i start_, sf::Vector2i end_);
void setScroll(int ratio_, sf::Vector2i start_, std::list<Slot> tiles_);
private:
sf::Vector2i grid_dimensions;
sf::Vector2i tile_pixel_dimensions;
sf::RenderWindow window;
std::vector<Tile> tiles;
sf::Font font;
int multi_to_linear(sf::Vector2i position_) const;
sf::Vector2i linear_to_multi(int position_) const;
void set_tile_ratio(int ratio_, sf::Vector2i tile_position_);
void append_slots(sf::Vector2i start_, std::list<Slot> values_);
};

View File

@@ -6,6 +6,7 @@
#include <map>
#include <string.h>
#ifdef linux
#include <CL/cl.h>
#include <CL/opencl.h>
@@ -15,8 +16,10 @@
#include <CL/cl_gl.h>
#include <CL/cl.h>
#include <CL/opencl.h>
#include <GL/GL.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>
@@ -47,12 +50,14 @@ public:
// 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_light(std::string light_id, Light light) override;
void assign_lights(std::vector<Light> lights) 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:
@@ -78,6 +83,8 @@ private:
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();
@@ -93,5 +100,6 @@ private:
std::map<std::string, cl_kernel> kernel_map;
std::map<std::string, cl_mem> buffer_map;
};

View File

@@ -24,10 +24,12 @@ public:
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_light(std::string light_id, Light light) = 0;
virtual void assign_lights(std::vector<Light> lights) = 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:
@@ -35,11 +37,11 @@ protected:
sf::Sprite viewport_sprite;
sf::Texture viewport_texture;
Old_Map * map;
Camera *camera;
std::map<std::string, Light> light_map;
sf::Uint8 *viewport_image;
sf::Vector4f *viewport_matrix;
Old_Map * map = nullptr;
Camera *camera = nullptr;
std::vector<Light> lights;
sf::Uint8 *viewport_image = nullptr;
sf::Vector4f *viewport_matrix = nullptr;
int error = 0;

View File

@@ -11,8 +11,13 @@ const float PI_F = 3.14159265358979f;
struct Light {
sf::Vector4f rgbi;
// I believe that Vector3's get padded to Vector4's. Give them a non-garbage value
sf::Vector3f position;
const float padding_1 = -1;
sf::Vector3f direction_cartesian;
const float padding_2 = -2;
};
struct fps_counter {
@@ -164,5 +169,6 @@ inline std::string read_file(std::string file_name){
std::stringstream buf;
buf << input_file.rdbuf();
input_file.close();
return buf.str();
}