diff --git a/FocusTerra/.vs/FocusTerra/v16/ipch/AutoPCH/2497ca4debdda90c/SLIM_BLOCKCHAIN_HANDLER.ipch b/FocusTerra/.vs/FocusTerra/v16/ipch/AutoPCH/2497ca4debdda90c/SLIM_BLOCKCHAIN_HANDLER.ipch index a44a8593536f443f8c1cc13d9e2df56e4ed9590a..d3b71a321b926a3ff86042ccafb98a1f2b03767b 100644 Binary files a/FocusTerra/.vs/FocusTerra/v16/ipch/AutoPCH/2497ca4debdda90c/SLIM_BLOCKCHAIN_HANDLER.ipch and b/FocusTerra/.vs/FocusTerra/v16/ipch/AutoPCH/2497ca4debdda90c/SLIM_BLOCKCHAIN_HANDLER.ipch differ diff --git a/FocusTerra/.vs/FocusTerra/v16/ipch/AutoPCH/cb00a5d01c33728d/MAIN_TESTING.ipch b/FocusTerra/.vs/FocusTerra/v16/ipch/AutoPCH/cb00a5d01c33728d/MAIN_TESTING.ipch index 2229fb54e4b833de0d27e740abee03431d5b644c..a50bdb3dc3fbafb0a9ac7d189fd2a8fe5b2aaf35 100644 Binary files a/FocusTerra/.vs/FocusTerra/v16/ipch/AutoPCH/cb00a5d01c33728d/MAIN_TESTING.ipch and b/FocusTerra/.vs/FocusTerra/v16/ipch/AutoPCH/cb00a5d01c33728d/MAIN_TESTING.ipch differ diff --git a/include/slim_blockchain_handler.hpp b/include/slim_blockchain_handler.hpp index 20beca217056fdaad8134ebb206a1d725df3be83..9e27bae1674e98d35f016280da3adf84090e9581 100644 --- a/include/slim_blockchain_handler.hpp +++ b/include/slim_blockchain_handler.hpp @@ -12,7 +12,7 @@ class SlimBlockchainHandler { public: /*Assumes all toolbox textures are initialized*/ - SlimBlockchainHandler(Toolbox& tb, MSTATE initial_mstate, std::string filename_ssh, std::string filename_fzp) + SlimBlockchainHandler(Toolbox& tb, MSTATE initial_mstate) : previous_mstate_(static_cast<int>(initial_mstate)), blockchain_(0), dragpairs_(0), @@ -53,10 +53,6 @@ public: glEnableVertexAttribArray(1); glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); - - /*Load structure textures*/ - load_damping_texture_(tb, filename_ssh, &texture_ssh_); - load_damping_texture_(tb, filename_fzp, &texture_fresnel_); } void update(Toolbox& tb); @@ -66,18 +62,10 @@ private: void clear_blocks_(); void update_blocks_(const Toolbox& tb, bool reload_all); bool in_wave_window_(const Toolbox&, const Pevent&) const; - //Patterns - void queue_singleslit_(Toolbox&); - void queue_doubleslit_(Toolbox&); - void queue_lattice_(Toolbox&); - void queue_waveguide_(Toolbox&); - void queue_ssh_(Toolbox&); - void queue_fresnel_(Toolbox&); //Vertex Calculation void xywhs_to_vertices_(const Toolbox& tb, const std::vector<bool>& duplicates, const std::vector<glm::ivec4>& xywhs, std::vector<float>& vertices) const; //Duplicate identification void find_dynamic_duplicates_(); - bool load_damping_texture_(const Toolbox& tb, const std::string filename, GLuint* texture_target); //Data int previous_mstate_ = static_cast<int>(MSTATE::PLACE); /*Keep track when mstate changes*/ @@ -91,15 +79,10 @@ private: GLuint fbo_wave_ = 0; GLuint fbo_dynamic_ = 0; GLuint fbo_static_ = 0; - /*Structure textures*/ - GLuint texture_ssh_ = 0; - GLuint texture_fresnel_ = 0; /*Drawlists*/ std::vector<glm::ivec4> drawlist_static_; std::vector<glm::ivec4> drawlist_dynamic_; std::vector<glm::ivec4> eraselist_dynamic_; std::vector<bool> drawlist_dynamic_duplicates_; std::vector<bool> eraselist_dynamic_duplicates_; - /*Texture queue and vbo data*/ - GLuint queued_texture_ = 0; }; \ No newline at end of file diff --git a/src/slim_blockchain_handler.cpp b/src/slim_blockchain_handler.cpp index 149aa8bfd785fedd2a55ffd76d86afa1097ab735..09a4de19b5584db8c1f7655253d1b722d6de4db1 100644 --- a/src/slim_blockchain_handler.cpp +++ b/src/slim_blockchain_handler.cpp @@ -25,41 +25,7 @@ void SlimBlockchainHandler::update(Toolbox& tb) { m.handled = true; skip_events = true; break; - case BLOCKCHAINMESSAGE::PATTERN_SINGLESLIT: - clear_blocks_(); - queue_singleslit_(tb); - m.handled = true; - skip_events = true; - break; - case BLOCKCHAINMESSAGE::PATTERN_DOUBLESLIT: - clear_blocks_(); - queue_doubleslit_(tb); - m.handled = true; - skip_events = true; - break; - case BLOCKCHAINMESSAGE::PATTERN_LATTICE: - clear_blocks_(); - queue_lattice_(tb); - m.handled = true; - skip_events = true; - break; - case BLOCKCHAINMESSAGE::PATTERN_WAVEGUIDE: - clear_blocks_(); - queue_waveguide_(tb); - m.handled = true; - skip_events = true; - break; - case BLOCKCHAINMESSAGE::PATTERN_SSH: - clear_blocks_(); - queue_ssh_(tb); - m.handled = true; - skip_events = true; - break; - case BLOCKCHAINMESSAGE::PATTERN_FRESNEL: - clear_blocks_(); - queue_fresnel_(tb); - m.handled = true; - skip_events = true; + default: break; } } @@ -144,7 +110,7 @@ void SlimBlockchainHandler::clear_blocks_() { void SlimBlockchainHandler::update_blocks_(const Toolbox& tb, bool reload_all) { find_dynamic_duplicates_(); - if (drawlist_dynamic_.size() != 0 || drawlist_static_.size() != 0 || eraselist_dynamic_.size() != 0 || queued_texture_ != 0) { + if (drawlist_dynamic_.size() != 0 || drawlist_static_.size() != 0 || eraselist_dynamic_.size() != 0) { glBindVertexArray(vao_); glBindBuffer(GL_ARRAY_BUFFER, vbo_); glViewport(0, 0, tb.texture_w, tb.texture_h); @@ -210,18 +176,7 @@ void SlimBlockchainHandler::update_blocks_(const Toolbox& tb, bool reload_all) { } drawlist_dynamic_.clear(); } - /*Draw textured structures*/ - if (queued_texture_ != 0) { - glBindFramebuffer(GL_FRAMEBUFFER, fbo_static_); - glBindTexture(GL_TEXTURE_2D, queued_texture_); - xywhs_to_vertices_(tb, { false }, { {0, 0, tb.texture_w, tb.texture_h} }, vertices); - if (vertices.size() != 0) { - glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), vertices.data(), GL_DYNAMIC_DRAW); - shader_drawblocks_.setFloat("color_multiplier", 1.f); - glDrawArrays(GL_TRIANGLES, 0, 6); - } - queued_texture_ = 0; - } + /*Drawing finished, reset OpenGL state*/ glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); @@ -241,76 +196,6 @@ bool SlimBlockchainHandler::in_wave_window_(const Toolbox& tb, const Pevent& pev return pev.fscoord_x < 1.f - tb.gui_pos; } -/*Structures*/ -/*Note that they don't go into the blockchain, they only exist in the static damping texture*/ -/*The correct wave texture for Blocks is tb.tex_wave_1*/ -void SlimBlockchainHandler::queue_singleslit_(Toolbox& tb) { - int block_width = 30; - int slit_height = 40; - int block_height = tb.texture_h / 2 - slit_height/2 - 1; - EfficientBlock b_top(block_width, block_height, tb.texture_w / 3, tb.texture_h / 2 + slit_height / 2); - EfficientBlock b_bottom(block_width, block_height, tb.texture_w / 3, 0); - drawlist_static_.push_back(b_top.xywh()); - drawlist_static_.push_back(b_bottom.xywh()); -} - -void SlimBlockchainHandler::queue_doubleslit_(Toolbox& tb) { - int block_width = 30; - int slit_height = 40; - int mid_block_height = 30; - int block_height = tb.texture_h / 2 - slit_height - mid_block_height / 2 - 1; - EfficientBlock b_top(block_width, block_height, tb.texture_w / 3, tb.texture_h / 2 + mid_block_height / 2 + slit_height); - EfficientBlock b_bottom(block_width, block_height, tb.texture_w / 3, 0); - EfficientBlock b_middle(block_width, mid_block_height, tb.texture_w / 3, tb.texture_h / 2 - mid_block_height / 2); - drawlist_static_.push_back(b_top.xywh()); - drawlist_static_.push_back(b_bottom.xywh()); - drawlist_static_.push_back(b_middle.xywh()); -} - -/*Lattice targets frequency of 5Hz*/ -void SlimBlockchainHandler::queue_lattice_(Toolbox& tb) { - int block_width = 10; - int block_height = 10; - int block_spacing = 30; - int lattice_width = tb.texture_w / 3; - int lattice_minx = tb.texture_w / 3 - lattice_width / 2; - for (float y = 0.f; y + block_height + block_spacing < tb.texture_h; y += block_spacing + block_height) { - for (float x = lattice_minx; x < lattice_minx + lattice_width; x += block_spacing + block_height) { - EfficientBlock new_block(block_width, block_height, x, y); - drawlist_static_.push_back(new_block.xywh()); - } - } -} - -/*Lattice targets frequency of 5Hz*/ -void SlimBlockchainHandler::queue_waveguide_(Toolbox& tb) { - int block_width = 10; - int block_height = 10; - int block_spacing = 30; - int lattice_width = tb.texture_w / 3; - int lattice_minx = tb.texture_w / 3 - lattice_width / 2; - for (float y = 0.f; y + block_height + block_spacing < tb.texture_h; y += block_spacing + block_height) { - if (y < tb.texture_h / 2 && y + block_spacing + block_height > tb.texture_h / 2) { - continue; - } - else if (y > tb.texture_h / 2 && y - block_spacing - block_height < tb.texture_h / 2) { - continue; - } - for (float x = lattice_minx; x < lattice_minx + lattice_width; x += block_spacing + block_height) { - EfficientBlock new_block(block_width, block_height, x, y); - drawlist_static_.push_back(new_block.xywh()); - } - } -} - -void SlimBlockchainHandler::queue_ssh_(Toolbox& tb) { - queued_texture_ = texture_ssh_; -} - -void SlimBlockchainHandler::queue_fresnel_(Toolbox& tb) { - queued_texture_ = texture_fresnel_; -} - void SlimBlockchainHandler::xywhs_to_vertices_(const Toolbox& tb, const std::vector<bool>& duplicates, const std::vector<glm::ivec4>& xywhs, std::vector<float>& vertices) const { float texwidth = tb.texture_w; float texheight = tb.texture_h; @@ -374,98 +259,4 @@ void SlimBlockchainHandler::find_dynamic_duplicates_() { } } } -} - -bool SlimBlockchainHandler::load_damping_texture_(const Toolbox& tb, const std::string filename, GLuint* texture_target) { - /*Load info about the texture from configuration file*/ - int screen_width, screen_height, texture_width, texture_height; - int texoffset_left, texoffset_right, texoffset_bottom, texoffset_top; - std::string config_filename = filename + ".conf"; - std::fstream cfg_file; - cfg_file.exceptions(std::ifstream::failbit | std::ifstream::badbit); - try { - cfg_file.open(config_filename); - cfg_file >> screen_width; - cfg_file >> screen_height; - cfg_file >> texture_width; - cfg_file >> texture_height; - cfg_file >> texoffset_left; - cfg_file >> texoffset_right; - cfg_file >> texoffset_bottom; - cfg_file >> texoffset_top; - cfg_file.close(); - } - catch (std::ifstream::failure e) { - std::cout << "Failed to open file " + config_filename << std::endl; - return false; - } - std::cout << "Loaded configuration from " + config_filename; - std::cout << "\n\tScreen Resolution: " << screen_width << "x" << screen_height; - std::cout << "\n\tTexture Resolution: " << texture_width << "x" << texture_height; - std::cout << "\n\tOffset Left: " << texoffset_left; - std::cout << "\n\tOffset Right: " << texoffset_right; - std::cout << "\n\tOffset Bottom: " << texoffset_bottom; - std::cout << "\n\tOffset Top: " << texoffset_top << std::endl; - - /*Check if configuration is compatible with toolbox settings*/ - if (tb.screen_h != screen_height || tb.screen_w != screen_width) { - std::cout << "Incompatible Toolbox Screen Resolution: " << tb.screen_w << "x" << tb.screen_h << std::endl; - return false; - } - else if (tb.texture_h != texture_height || tb.texture_w != texture_width) { - std::cout << "Incompatible Toolbox Texture Resolution: " << tb.texture_w << "x" << tb.texture_h << std::endl; - return false; - } - else if (tb.texoffset_left != texoffset_left || tb.texoffset_right != texoffset_right || tb.texoffset_bottom != texoffset_bottom || tb.texoffset_top != texoffset_top) { - std::cout << "Incompatible Offsets" << std::endl; - return false; - } - - /*Load texture data*/ - else { - std::cout << "Texture is compatible" << std::endl; - } - - std::cout << "Loading Texture" << std::endl; - - std::fstream dmp_file; - std::string damping_filename = filename + ".texture"; - std::vector<float> data_target; - data_target.reserve(4 * texture_width * texture_height); - dmp_file.exceptions(std::ifstream::failbit | std::ifstream::badbit); - try { - dmp_file.open(damping_filename); - - float value; - for (size_t i = 0; i < 4 * texture_width * texture_height; ++i) { - /*If the file is finished at this point, we're fucked*/ - if (dmp_file.peek() == EOF) { - std::cout << "Unexpected End Of Damping File Encountered" << std::endl; - data_target.clear(); - return false; - } - dmp_file >> value; - data_target.push_back(value); - } - - dmp_file.close(); - } - catch (std::ifstream::failure e) { - std::cout << "Failed to open file " + damping_filename << std::endl; - return false; - } - - /*Generate and upload texture*/ - glGenTextures(1, texture_target); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, *texture_target); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, texture_width, texture_height, 0, GL_RGBA, GL_FLOAT, data_target.data()); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glBindTexture(GL_TEXTURE_2D, 0); - - - return true; } \ No newline at end of file