It's time to do the voxel traversal. Going to need to come up with a linear algorithm that doesn't take forever

master
MitchellHansen 8 years ago
parent 6c368183e9
commit 91e9de347e

@ -13,12 +13,13 @@
#include <unordered_map> #include <unordered_map>
#include <bitset> #include <bitset>
#include <cstring> #include <cstring>
#include <queue>
#define _USE_MATH_DEFINES #define _USE_MATH_DEFINES
#include <math.h> #include <math.h>
#define CHUNK_DIM 32 #define CHUNK_DIM 32
#define OCT_DIM 64 #define OCT_DIM 8
struct XYZHasher { struct XYZHasher {
std::size_t operator()(const sf::Vector3i& k) const { std::size_t operator()(const sf::Vector3i& k) const {
@ -35,7 +36,7 @@ public:
// initialize the first stack block // initialize the first stack block
stack.push_back(new uint64_t[0x8000]); stack.push_back(new uint64_t[0x8000]);
for (int i = 0; i < 0x8000; i++) { for (int i = 0; i < 0x8000; i++) {
stack.back() = 0; stack.back()[i] = 0;
} }
}; };
@ -69,6 +70,25 @@ public:
return stack_pos; return stack_pos;
}; };
// This might need to be a recursive function. But it needs to be easily ported to
// OpenCL C. Might spend some time thinking about how to do this in a linear algorithm
bool get_voxel(sf::Vector2i position) {
std::queue<uint64_t> parent_stack;
uint64_t head = stack.front()[stack_pos];
parent_stack.push(head);
uint64_t index = cp_to_index(head);
return true;
}
void print_block(int block_pos) { void print_block(int block_pos) {
std::stringstream sss; std::stringstream sss;
for (int i = 0; i < (int)pow(2, 15); i++) { for (int i = 0; i < (int)pow(2, 15); i++) {
@ -78,8 +98,13 @@ public:
DumpLog(&sss, "raw_data.txt"); DumpLog(&sss, "raw_data.txt");
} }
private:
uint64_t cp_to_index(uint64_t descriptor) {
return descriptor >> 64 - 15;
};
uint64_t is_leaf(uint64_t descriptor, )
}; };

@ -176,7 +176,7 @@ void Map::generate_octree() {
a.print_block(0); a.print_block(0);
a.get_voxel(sf::Vector2i(0, 0));
} }
void Map::load_unload(sf::Vector3i world_position) { void Map::load_unload(sf::Vector3i world_position) {

@ -91,7 +91,7 @@ int main() {
_map.generate_octree(); _map.generate_octree();
// ============================= // =============================
return 0;
/*GL_Testing t; /*GL_Testing t;
t.compile_shader("../shaders/passthrough.frag", GL_Testing::Shader_Type::FRAGMENT); t.compile_shader("../shaders/passthrough.frag", GL_Testing::Shader_Type::FRAGMENT);

@ -109,8 +109,7 @@ void Hardware_Caster::create_texture_atlas(sf::Texture *t, sf::Vector2i tile_dim
create_buffer("tile_dim", sizeof(sf::Vector2i), &tile_dim); create_buffer("tile_dim", sizeof(sf::Vector2i), &tile_dim);
} }
void Hardware_Caster::compute() void Hardware_Caster::compute() {
{
// correlating work size with texture size? good, bad? // correlating work size with texture size? good, bad?
run_kernel("raycaster", viewport_texture.getSize().x * viewport_texture.getSize().y); run_kernel("raycaster", viewport_texture.getSize().x * viewport_texture.getSize().y);
} }
@ -196,20 +195,6 @@ void Hardware_Caster::create_viewport(int width, int height, float v_fov, float
} }
//void Hardware_Caster::assign_lights(std::vector<LightController> *lights) {
//
// //this->lights = ;
//
// std::cout << sizeof(LightController);
// std::cout << sizeof(float);
// light_count = static_cast<int>(lights->size());
//
// //create_buffer("lights", sizeof(float) * 10 * light_count, this->lights->data(), CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR);
//
// create_buffer("light_count", sizeof(int), &light_count);
//
//}
void Hardware_Caster::assign_lights(std::vector<PackedData> *data) { void Hardware_Caster::assign_lights(std::vector<PackedData> *data) {
// Get a pointer to the packed light data // Get a pointer to the packed light data

Loading…
Cancel
Save