Linux build working again, removed the GL_Testing stuff, I'm going to move to Vulkan eventually. Got voxel search working mostly with the new octree changes. Issue with mirroring of voxel data currently

master
MitchellHansen 8 years ago
parent 04842dd597
commit 5e9401cd27

@ -3,6 +3,7 @@
#include <SFML/System/Vector2.hpp> #include <SFML/System/Vector2.hpp>
#include "util.hpp" #include "util.hpp"
#include "Pub_Sub.h" #include "Pub_Sub.h"
#include <cmath>
class Camera : public VrEventSubscriber{ class Camera : public VrEventSubscriber{
public: public:

@ -1,43 +0,0 @@
#pragma once
#include <string>
#include <util.hpp>
#include <cstring>
#ifdef _WIN32
#define GLEW_STATIC
#include <GL/glew.h>
#elif defined TARGET_OS_MAC
#include <OpenGL/gl.h>
#endif
class GL_Testing
{
public:
GL_Testing();
~GL_Testing(){};
enum Shader_Type {VERTEX, FRAGMENT};
void compile_shader(std::string file_path, Shader_Type t);
void create_program();
void create_buffers();
void transform();
void rotate(double delta);
void draw();
private:
GLuint VBO; //raw points
GLuint EBO; //link triangles
GLuint VAO;
GLuint vertex_shader;
GLuint fragment_shader;
GLuint shader_program;
GLfloat *matrix;
double counter = 0;
};

@ -25,11 +25,10 @@ public:
Map(uint32_t dimensions); Map(uint32_t dimensions);
void setVoxel(sf::Vector3i position, int val); void setVoxel(sf::Vector3i position, int val);
bool getVoxelFromOctree(sf::Vector3i position); bool getVoxelFromOctree(sf::Vector3i position);
bool getVoxel(sf::Vector3i pos); bool getVoxel(sf::Vector3i pos);
Octree octree;
Octree octree;
bool test(); bool test();
@ -40,8 +39,6 @@ private:
std::stringstream output_stream; std::stringstream output_stream;
// ========================= // =========================
void generate_octree(unsigned int dimensions);
char* voxel_data; char* voxel_data;
}; };

@ -24,7 +24,6 @@ public:
static const int buffer_size = 100000; static const int buffer_size = 100000;
Octree(); Octree();
~Octree() {}; ~Octree() {};
@ -56,10 +55,12 @@ public:
// With a position and the head of the stack. Traverse down the voxel hierarchy to find // With a position and the head of the stack. Traverse down the voxel hierarchy to find
// the IDX and stack position of the highest resolution (maybe set resolution?) oct // the IDX and stack position of the highest resolution (maybe set resolution?) oct
bool get_voxel(sf::Vector3i position); bool GetVoxel(sf::Vector3i position);
void print_block(int block_pos); void print_block(int block_pos);
bool Validate(char* data, sf::Vector3i dimensions);
private: private:
std::tuple<uint64_t, uint64_t> GenerationRecursion( std::tuple<uint64_t, uint64_t> GenerationRecursion(

@ -85,7 +85,7 @@ struct device_info {
cl_uint cl_device_preferred_vector_width_double; cl_uint cl_device_preferred_vector_width_double;
char cl_device_profile[256]; char cl_device_profile[256];
size_t cl_device_profiling_timer_resolution; size_t cl_device_profiling_timer_resolution;
cl_device_type cl_device_type; cl_device_type device_type;
char cl_device_vendor[128]; char cl_device_vendor[128];
cl_uint cl_device_vendor_id; cl_uint cl_device_vendor_id;
char cl_device_version[128]; char cl_device_version[128];

@ -7,7 +7,7 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <imgui/imgui.h> #include <imgui/imgui.h>
#include <cmath>
const double PI = 3.141592653589793238463; const double PI = 3.141592653589793238463;
const float PI_F = 3.14159265358979f; const float PI_F = 3.14159265358979f;

@ -1,199 +0,0 @@
#include "GL_Testing.h"
GL_Testing::GL_Testing() {
GLfloat tmp[] = {
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, static_cast<float>(cos(1.0f)), static_cast<float>(sin(1.0f)), 0.0f,
0.0f, static_cast<float>(-sin(1.0f)), static_cast<float>(cos(1.0f)), 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
};
matrix = new GLfloat[16];
memcpy(matrix, tmp, sizeof(GLfloat) * 16);
#ifdef linux
GLint err = glewInit();
#elif _WIN32
GLint err = glewInit();
#elif TARGET_OS_MAC
GLint err = 0;
#endif
if (err) {
std::cout << "error initializing glew" << std::endl;
}
}
void GL_Testing::compile_shader(std::string file_path, Shader_Type t) {
// Load in the source and cstring it
const char* source;
std::string tmp;
tmp = read_file(file_path);
source = tmp.c_str();
GLint success;
GLchar log[512];
if (t == Shader_Type::VERTEX) {
vertex_shader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertex_shader, 1, &source, NULL);
glCompileShader(vertex_shader);
glGetShaderiv(vertex_shader, GL_COMPILE_STATUS, &success);
if (!success) {
glGetShaderInfoLog(vertex_shader, 512, NULL, log);
std::cout << "Vertex shader failed compilation: " << log << std::endl;
}
} else if (t == Shader_Type::FRAGMENT) {
fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragment_shader, 1, &source, NULL);
glCompileShader(fragment_shader);
glGetShaderiv(fragment_shader, GL_COMPILE_STATUS, &success);
if (!success) {
glGetShaderInfoLog(fragment_shader, 512, NULL, log);
std::cout << "Vertex shader failed compilation: " << log << std::endl;
}
}
}
void GL_Testing::create_program() {
GLint success;
GLchar log[512];
shader_program = glCreateProgram();
glAttachShader(shader_program, vertex_shader);
glAttachShader(shader_program, fragment_shader);
glLinkProgram(shader_program);
glGetProgramiv(shader_program, GL_LINK_STATUS, &success);
if (!success) {
glGetProgramInfoLog(shader_program, 512, NULL, log);
std::cout << "Failed to link shaders into program: " << log << std::endl;
}
glDeleteShader(vertex_shader);
glDeleteShader(fragment_shader);
}
void GL_Testing::create_buffers() {
GLfloat vertices[] = {
0.5f, 0.5f, 0.0f, // Top Right
0.5f, -0.5f, 0.0f, // Bottom Right
-0.5f, -0.5f, 0.0f, // Bottom Left
-0.5f, 0.5f, 0.0f // Top Left
};
GLuint indices[] = { // Note that we start from 0!
0, 1, 3 // First Triangle
// Second Triangle
};
#ifdef linux
glGenVertexArrays(1, &VAO);
#elif defined _WIN32
glGenVertexArrays(1, &VAO);
#elif defined TARGET_OS_MAC
glGenVertexArraysAPPLE(1, &VAO);
#endif
glGenBuffers(1, &VBO);
glGenBuffers(1, &EBO);
// Bind the Vertex Array Object first, then bind and set vertex buffer(s) and attribute pointer(s).
#ifdef linux
glBindVertexArray(VAO);
#elif defined _WIN32
glBindVertexArray(VAO);
#elif defined TARGET_OS_MAC
glBindVertexArrayAPPLE(VAO);
#endif
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
#ifdef linux
glbindvertexarray(0);
#elif defined _win32
glbindvertexarray(0);
#elif defined target_os_mac
glbindvertexarrayapple(0);
#endif
}
void GL_Testing::transform()
{
GLuint transformLoc = glGetUniformLocation(shader_program, "transform");
glUseProgram(shader_program);
glUniformMatrix4fv(transformLoc, 1, GL_FALSE, matrix);
}
void GL_Testing::rotate(double delta) {
counter += delta;
GLfloat tmp[] = {
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, static_cast<float>(cos(counter)), static_cast<float>(sin(counter)), 0.0f,
0.0f, static_cast<float>(-sin(counter)), static_cast<float>(cos(counter)), 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
};
memcpy(matrix, tmp, sizeof(GLfloat) * 16);
}
void GL_Testing::draw() {
glUseProgram(shader_program);
#ifdef linux
glBindVertexArray(VAO);
#elif defined _WIN32
glBindVertexArray(VAO);
#elif defined TARGET_OS_MAC
glBindVertexArrayAPPLE(VAO);
#endif
//glDrawArrays(GL_TRIANGLES, 0, 6);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0);
#ifdef linux
glbindVertexArray(0);
#elif defined _win32
glbindVertexArray(0);
#elif defined target_os_mac
glbindVertexArrayAPPLE(0);
#endif
}
//

@ -1,6 +1,6 @@
 
// This has to be up here or else glew will complain // This has to be up here or else glew will complain
#include "GL_Testing.h" //#include "GL_Testing.h"
#ifdef linux #ifdef linux
#include <CL/cl.h> #include <CL/cl.h>
@ -16,8 +16,8 @@
#elif defined TARGET_OS_MAC #elif defined TARGET_OS_MAC
#include <OpenGL/gl.h> #include <OpenGL/gl.h>
# include <OpenGL/OpenGL.h> #include <OpenGL/OpenGL.h>
# include <OpenCL/opencl.h> #include <OpenCL/opencl.h>
#include <OpenCL/cl_gl_ext.h> #include <OpenCL/cl_gl_ext.h>
#include <OpenCL/cl_ext.h> #include <OpenCL/cl_ext.h>
#endif #endif
@ -65,31 +65,14 @@ float elap_time(){
sf::Sprite window_sprite; sf::Sprite window_sprite;
sf::Texture window_texture; sf::Texture window_texture;
// Y: -1.57 is straight up
// Y: 1.57 is straight down
// TODO: // TODO:
// - Texture axis sign flipping issue
// - Diffuse fog hard cut off
// - Infinite light distance, no inverse square
// - Inconsistent lighting constants. GUI manipulation // - Inconsistent lighting constants. GUI manipulation
// - Far pointers, attachment lookup and aux buffer, contour lookup & masking // Ancilary settings buffer and memory controller
// - Attachment lookup and aux buffer, contour lookup & masking
int main() { int main() {
// Keep at this at the top of main. I think it has to do with it and
// sf::RenderWindow stepping on each others feet
#ifdef linux
glewInit();
#elif defined _WIN32
//glewInit();
#elif defined TARGET_OS_MAC
// Do nothing, extension wrangling handled by macOS
#endif
// ============================= // =============================
Map _map(32); Map _map(32);
//_map.test(); //_map.test();
@ -113,7 +96,6 @@ int main() {
abort(); abort();
} }
// Create and generate the old 3d array style map // Create and generate the old 3d array style map
Old_Map* map = new Old_Map(sf::Vector3i(MAP_X, MAP_Y, MAP_Z)); Old_Map* map = new Old_Map(sf::Vector3i(MAP_X, MAP_Y, MAP_Z));
map->generate_terrain(); map->generate_terrain();

@ -5,31 +5,34 @@ Map::Map(uint32_t dimensions) {
srand(time(nullptr)); srand(time(nullptr));
voxel_data = new char[dimensions * dimensions * dimensions]; voxel_data = new char[dimensions * dimensions * dimensions]();
for (uint64_t i = 0; i < dimensions * dimensions * dimensions; i++) { for (uint64_t i = 0; i < dimensions * dimensions * dimensions; i++) {
if (rand() % 25 < 2)
voxel_data[i] = 1;
else
voxel_data[i] = 0;
}
generate_octree(dimensions); voxel_data[i] = 1;
} }
// for (uint64_t i = 0; i < dimensions * dimensions * dimensions; i++) {
// if (rand() % 25 < 2)
// voxel_data[i] = 1;
// else
// voxel_data[i] = 0;
// }
void Map::generate_octree(unsigned int dimensions) { setVoxel(sf::Vector3i(1, 1, 1), 0);
octree.Generate(voxel_data, sf::Vector3i(dimensions, dimensions, dimensions)); octree.Generate(voxel_data, sf::Vector3i(dimensions, dimensions, dimensions));
octree.Validate(voxel_data, sf::Vector3i(dimensions, dimensions, dimensions));
} }
void Map::setVoxel(sf::Vector3i world_position, int val) { void Map::setVoxel(sf::Vector3i pos, int val) {
voxel_data[pos.x + OCT_DIM * (pos.y + OCT_DIM * pos.z)] = val;
} }
bool Map::getVoxelFromOctree(sf::Vector3i position) bool Map::getVoxelFromOctree(sf::Vector3i position)
{ {
return octree.get_voxel(position); return 0;
} }
bool Map::getVoxel(sf::Vector3i pos){ bool Map::getVoxel(sf::Vector3i pos){

@ -22,17 +22,12 @@ void Octree::Generate(char* data, sf::Vector3i dimensions) {
output_stream << " " << OCT_DIM << " " << counter++ << std::endl; output_stream << " " << OCT_DIM << " " << counter++ << std::endl;
// ============================== // ==============================
// ============= TEMP!!! =================== std::get<0>(root_node) |= 1;
if (stack_pos - 1 > stack_pos) {
global_pos -= stack_pos;
stack_pos = 0x8000;
}
else {
stack_pos -= 1;
}
memcpy(&descriptor_buffer[descriptor_buffer_position], &std::get<0>(root_node), sizeof(uint64_t)); memcpy(&descriptor_buffer[descriptor_buffer_position], &std::get<0>(root_node), sizeof(uint64_t));
descriptor_buffer_position--;
root_index = descriptor_buffer_position;
descriptor_buffer_position--;
// ======================================== // ========================================
@ -48,13 +43,15 @@ void Octree::Generate(char* data, sf::Vector3i dimensions) {
} }
bool Octree::get_voxel(sf::Vector3i position) { bool Octree::GetVoxel(sf::Vector3i position) {
// Struct that holds the state necessary to continue the traversal from the found voxel // Struct that holds the state necessary to continue the traversal from the found voxel
oct_state state; oct_state state;
// push the root node to the parent stack // push the root node to the parent stack
uint64_t head = descriptor_buffer[root_index]; uint64_t current_index = root_index;
uint64_t head = descriptor_buffer[current_index];
// PrettyPrintUINT64(head);
state.parent_stack[state.parent_stack_position] = head; state.parent_stack[state.parent_stack_position] = head;
// Set our initial dimension and the position at the corner of the oct to keep track of our position // Set our initial dimension and the position at the corner of the oct to keep track of our position
@ -98,6 +95,7 @@ bool Octree::get_voxel(sf::Vector3i position) {
mask_index += 2; mask_index += 2;
// What is up with the binary operator on this one? TODO
state.idx_stack[state.scale] ^= idx_set_y_mask; state.idx_stack[state.scale] ^= idx_set_y_mask;
} }
@ -131,7 +129,8 @@ bool Octree::get_voxel(sf::Vector3i position) {
// access the element at which head points to and then add the specified number of indices // access the element at which head points to and then add the specified number of indices
// to get to the correct child descriptor // to get to the correct child descriptor
head = descriptor_buffer[(head & child_pointer_mask) + count]; current_index = current_index + (head & child_pointer_mask) + count;
head = descriptor_buffer[current_index];
// Increment the parent stack position and put the new oct node as the parent // Increment the parent stack position and put the new oct node as the parent
state.parent_stack_position++; state.parent_stack_position++;
@ -313,7 +312,35 @@ std::tuple<uint64_t, uint64_t> Octree::GenerationRecursion(char* data, sf::Vecto
} }
char Octree::get1DIndexedVoxel(char* data, sf::Vector3i dimensions, sf::Vector3i position) { char Octree::get1DIndexedVoxel(char* data, sf::Vector3i dimensions, sf::Vector3i position) {
return data[position.x + OCT_DIM * (position.y + OCT_DIM * position.z)]; return data[position.x + dimensions.x * (position.y + dimensions.y * position.z)];
} }
bool Octree::Validate(char* data, sf::Vector3i dimensions){
// std::cout << (int)get1DIndexedVoxel(data, dimensions, sf::Vector3i(16, 16, 16)) << std::endl;
// std::cout << (int)GetVoxel(sf::Vector3i(16, 16, 16)) << std::endl;
std::cout << "Validating map..." << std::endl;
for (int x = 0; x < OCT_DIM; x++) {
for (int y = 0; y < OCT_DIM; y++) {
for (int z = 0; z < OCT_DIM; z++) {
sf::Vector3i pos(x, y, z);
char arr_val = get1DIndexedVoxel(data, dimensions, pos);
char oct_val = GetVoxel(pos);
if (arr_val != oct_val) {
std::cout << "X: " << pos.x << " Y: " << pos.y << " Z: " << pos.z << " ";
std::cout << (int)arr_val << " : " << (int)oct_val << std::endl;
}
}
}
}
std::cout << "Done" << std::endl;
}

@ -478,7 +478,7 @@ int Hardware_Caster::query_hardware() {
clGetDeviceInfo(id, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, sizeof(cl_uint), &d.cl_device_preferred_vector_width_double, NULL); clGetDeviceInfo(id, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, sizeof(cl_uint), &d.cl_device_preferred_vector_width_double, NULL);
clGetDeviceInfo(id, CL_DEVICE_PROFILE, sizeof(char) * 256, &d.cl_device_profile, NULL); clGetDeviceInfo(id, CL_DEVICE_PROFILE, sizeof(char) * 256, &d.cl_device_profile, NULL);
clGetDeviceInfo(id, CL_DEVICE_PROFILING_TIMER_RESOLUTION, sizeof(size_t), &d.cl_device_profiling_timer_resolution, NULL); clGetDeviceInfo(id, CL_DEVICE_PROFILING_TIMER_RESOLUTION, sizeof(size_t), &d.cl_device_profiling_timer_resolution, NULL);
clGetDeviceInfo(id, CL_DEVICE_TYPE, sizeof(cl_device_type), &d.cl_device_type, NULL); clGetDeviceInfo(id, CL_DEVICE_TYPE, sizeof(cl_device_type), &d.device_type, NULL);
clGetDeviceInfo(id, CL_DEVICE_VENDOR, sizeof(char)*128, &d.cl_device_vendor, NULL); clGetDeviceInfo(id, CL_DEVICE_VENDOR, sizeof(char)*128, &d.cl_device_vendor, NULL);
clGetDeviceInfo(id, CL_DEVICE_VENDOR_ID, sizeof(cl_uint), &d.cl_device_vendor_id, NULL); clGetDeviceInfo(id, CL_DEVICE_VENDOR_ID, sizeof(cl_uint), &d.cl_device_vendor_id, NULL);
clGetDeviceInfo(id, CL_DEVICE_VERSION, sizeof(char)*128, &d.cl_device_version, NULL); clGetDeviceInfo(id, CL_DEVICE_VERSION, sizeof(char)*128, &d.cl_device_version, NULL);

Loading…
Cancel
Save