diff --git a/src/wave_handler.cpp b/src/wave_handler.cpp index 4cdf85c3d8487181a77ffe0540c6a4aa8a9f941d..bb932f6bfe64dd78fdda0de19fba34641477ed3f 100644 --- a/src/wave_handler.cpp +++ b/src/wave_handler.cpp @@ -34,7 +34,7 @@ bool WaveHandler::initialize(const std::string damping_file, const std::string p { bool retBool = true; retBool &= initialize_2D_data_(); - retBool &= initialize_3D_data_(); + //retBool &= initialize_3D_data_(); retBool &= initialize_comp_data_(damping_file); retBool &= initialize_render_data_(palette_file); retBool &= initialize_shaders_(); @@ -168,31 +168,6 @@ bool WaveHandler::render() return true; } -/*DO NOT CALL*/ -bool WaveHandler::reset_wave() -{ - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, tex_comp_wave_0_); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, texwidth_, texheight_, 0, GL_RGBA, GL_FLOAT, tex_wave_data_.data()); - glBindTexture(GL_TEXTURE_2D, tex_comp_wave_1_); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, texwidth_, texheight_, 0, GL_RGBA, GL_FLOAT, tex_wave_data_.data()); - return true; -} - -/*DO NOT CALL*/ -bool WaveHandler::reset_damping() -{ - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, tex_comp_damp_); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, texwidth_, texheight_, 0, GL_RGBA, GL_FLOAT, tex_damp_data_.data()); - glBindTexture(GL_TEXTURE_2D, tex_comp_damp_static_); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, texwidth_, texheight_, 0, GL_RGBA, GL_FLOAT, tex_damp_data_.data()); - glBindTexture(GL_TEXTURE_2D, tex_comp_damp_dynamic_); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, texwidth_, texheight_, 0, GL_RGBA, GL_FLOAT, tex_damp_data_.data()); - glBindTexture(GL_TEXTURE_2D, 0); - return true; -} - GLuint WaveHandler::get_damping_tex() const { return tex_comp_damp_; @@ -315,29 +290,14 @@ bool WaveHandler::initialize_3D_data_() bool WaveHandler::initialize_comp_data_(const std::string damping_file) { /*If we can load damping externally, we do that. Else we generate it ourselves*/ + std::cout << "Loading baseline damping texture" << std::endl; if (!load_damping_(damping_file)) { - - //int tapered_pixels = 280; - //float delta_damping = 0.00005f; + std::cout << "Load failed, generating fallback" << std::endl; int tapered_pixels = 280; float delta_damping = 0.00005f; float high_damping = 0.985f; float low_damping = 0.999f; - //generate damping mask texture data - //std::vector<float> texDamp(4 * height_ * width_, 0.992f); - //tex_damp_data_ = std::vector<float>(4 * texheight_ * texwidth_, 0.992f); tex_damp_data_ = std::vector<float>(4 * texheight_ * texwidth_, high_damping); - /*Inconsistent use of uv_off_screen - unsigned offset = static_cast<int>(uv_off_screen_ * height_) * width_ * 4 + static_cast<int>(uv_off_screen_ * width_) * 4; - for (size_t i = 0; i < (1.f - 2.f * uv_off_screen_) * height_; ++i) { - for (size_t j = 0; j < (1.f - 2.f * uv_off_screen_) * width_; ++j) { - tex_damp_data_[offset + 4 * width_ * i + 4 * j] = 0.999f; - tex_damp_data_[offset + 4 * width_ * i + 4 * j + 1] = 0.f; - tex_damp_data_[offset + 4 * width_ * i + 4 * j + 2] = 0.f; - tex_damp_data_[offset + 4 * width_ * i + 4 * j + 3] = 0.f; - } - } - */ unsigned offset = texoffset_bottom_ * texwidth_ * 4 + texoffset_left_ * 4; for (size_t i = 0; i < height_; ++i) { for (size_t j = 0; j < width_; ++j) { @@ -347,52 +307,15 @@ bool WaveHandler::initialize_comp_data_(const std::string damping_file) tex_damp_data_[offset + 4 * texwidth_ * i + 4 * j + 3] = 0.f; } } - /*Tapering*/ - /* - int offscreen_pixels_x = static_cast<int>(uv_off_screen_ * width_); - int offscreen_pixels_y = static_cast<int>(uv_off_screen_ * height_); - int j_right = texwidth_ - offscreen_pixels_x; - int j_left = offscreen_pixels_x; - int i_bottom = offscreen_pixels_y; - int i_top = texheight_ - offscreen_pixels_y; - for (int ring_index = 0; ring_index < tapered_pixels; ring_index++) { - float value = 0.999f - static_cast<float>(ring_index) * delta_damping; - std::cout << "Value: " << value << std::endl; - //Bottom and Top - for (int j = j_left - ring_index; j < j_right + ring_index; ++j) { - tex_damp_data_[ij_to_tex(i_bottom - ring_index, j, texwidth_)] = value; - tex_damp_data_[ij_to_tex(i_top + ring_index, j, texwidth_)] = value; - } - //Left and Right - for (int i = i_bottom - ring_index; i < i_top + ring_index; ++i) { - tex_damp_data_[ij_to_tex(i, j_left - ring_index, texwidth_)] = value; - tex_damp_data_[ij_to_tex(i, j_right + ring_index, texwidth_)] = value; - } - } - */ } - else { +#ifndef NDEBUG std::cout << "Damping " + damping_file + " loaded" << std::endl; +#endif +#ifdef NDEBUG + std::cout << "Load successful" << std::endl; +#endif } - - /* - std::ofstream file("damp_data.txt"); - for (int i = 0; i < texheight_; ++i) { - for (int j = 0; j < texwidth_; ++j) { - file << tex_damp_data_[ij_to_tex(i, j, texwidth_)] << " "; - } - file << std::endl; - } - file.close(); - */ - /*Debugging: Look at a central slice through the texture*/ - /* - for (int j = 0; j < texwidth_; ++j) { - std::cout << j << " " << tex_damp_data_[ij_to_tex(texheight_ / 2, j, texwidth_)] << " " << tex_damp_data_[ij_to_tex(texheight_ / 2, j, texwidth_) + 1] << " " << tex_damp_data_[ij_to_tex(texheight_ / 2, j, texwidth_) + 2] << " " << tex_damp_data_[ij_to_tex(texheight_ / 2, j, texwidth_) + 3] << std::endl; - } - */ - //generate texture and upload to GPU glGenTextures(1, &tex_comp_damp_); glActiveTexture(GL_TEXTURE1); @@ -422,6 +345,9 @@ bool WaveHandler::initialize_comp_data_(const std::string damping_file) 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); + + + //generate wave data texture data int source_offset = 0; /*used to be 50*/ //std::vector<float> texData(4 * height_ * width_, 0.f); //rgba @@ -429,13 +355,7 @@ bool WaveHandler::initialize_comp_data_(const std::string damping_file) for (size_t i = 0; i < tex_wave_data_.size() / 4; ++i) { tex_wave_data_[4 * i + 3] = 1.f; //alpha } - - /* - int source_anchor = 4 * texoffset_bottom_ * texwidth_ + 4 * texoffset_left_ - source_offset*4; - for (int i = 0; i < height_; ++i) { //source is marked in blue - tex_wave_data_[source_anchor + 4 * i * texwidth_ + 2] = 1.f; - } - */ + //Wide source for (int i = 0; i < texheight_; ++i) { tex_wave_data_[4 * i * texwidth_ + 2] = 1.f; } @@ -489,6 +409,7 @@ bool WaveHandler::initialize_comp_data_(const std::string damping_file) bool WaveHandler::initialize_render_data_(const std::string palette_file) { /*load colour palette*/ + std::cout << "Loading palette" << std::endl; if (!load_palette_(palette_file)) { return false; } @@ -558,8 +479,9 @@ bool WaveHandler::initialize_shaders_() shdr_step_.setFloat("c2", 0.150428); shdr_step_.setInt("tex_wave", 0); shdr_step_.setInt("tex_damp", 1); - //set up 3d rendering shader + /* + //set up 3d rendering shader Shader render3dshader((shader_path_ + "render3d.vert").c_str(), (shader_path_ + "render3d.frag").c_str()); shdr_3d_ = render3dshader; shdr_3d_.use(); @@ -570,6 +492,9 @@ bool WaveHandler::initialize_shaders_() glm::mat4 trans_3d = glm::mat4(1.0f); trans_3d = glm::rotate(trans_3d, glm::radians(60.f), glm::vec3(-1.0f, 0.0f, 0.0f)); shdr_3d_.setMat4("trans", trans_3d); + */ + + /* //set up 3d debug rendering shader Shader render3ddebugshader((shader_path_ + "render3d.vert").c_str(), (shader_path_ + "render3d.frag").c_str()); shdr_3d_dbg_ = render3ddebugshader; @@ -582,6 +507,7 @@ bool WaveHandler::initialize_shaders_() trans_3d_dbg = glm::rotate(trans_3d_dbg, glm::radians(60.f), glm::vec3(-1.0f, 0.0f, 0.0f)); shdr_3d_.setMat4("trans", trans_3d_dbg); */ + //set up 2d rendering shader Shader render2dshader((shader_path_ + "render2d.vert").c_str(), (shader_path_ + "render2d.frag").c_str()); shdr_2d_ = render2dshader; @@ -589,10 +515,7 @@ bool WaveHandler::initialize_shaders_() shdr_2d_.setInt("tex_wave", 0); shdr_2d_.setInt("tex_damp", 1); shdr_2d_.setInt("tex_palette", 2); - /* - float uos = 0.; - shdr_2d_.setFloat("uv_offscreen", uos); - */ + //set up 2d debug rendering shader Shader render2ddebugshader((shader_path_ + "render2d.vert").c_str(), (shader_path_ + "render2d.frag").c_str()); shdr_2d_dbg_ = render2ddebugshader; @@ -600,6 +523,7 @@ bool WaveHandler::initialize_shaders_() shdr_2d_dbg_.setInt("tex_wave", 0); shdr_2d_dbg_.setInt("tex_damp", 1); shdr_2d_dbg_.setFloat("uv_offscreen", 0.f); + //set up damping combiner shader Shader dampingcombinershader((shader_path_ + "combine_damping.vert").c_str(), (shader_path_ + "combine_damping.frag").c_str()); shdr_damp_ = dampingcombinershader; @@ -675,6 +599,7 @@ bool WaveHandler::load_damping_(const std::string filename) { std::cout << "Failed to open file " + config_filename << std::endl; return false; } +#ifndef NDEBUG 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; @@ -682,7 +607,7 @@ bool WaveHandler::load_damping_(const std::string filename) { std::cout << "\n\tOffset Right: " << texoffset_right; std::cout << "\n\tOffset Bottom: " << texoffset_bottom; std::cout << "\n\tOffset Top: " << texoffset_top << std::endl; - +#endif /*Check if configuration is compatible with toolbox settings*/ if (height_ != screen_height || width_ != screen_width) { std::cout << "Incompatible Toolbox Screen Resolution: " << width_ << "x" << height_ << std::endl; @@ -696,12 +621,12 @@ bool WaveHandler::load_damping_(const std::string filename) { std::cout << "Incompatible Offsets" << std::endl; return false; } +#ifndef NDEBUG else { std::cout << "Texture is compatible" << std::endl; } - std::cout << "Loading Texture" << std::endl; - +#endif std::fstream dmp_file; std::string damping_filename = filename + ".texture"; dmp_file.exceptions(std::ifstream::failbit | std::ifstream::badbit);