diff --git a/FocusTerra/.vs/FocusTerra/v16/.suo b/FocusTerra/.vs/FocusTerra/v16/.suo index 78986f26e6cdffa3d45e6c8548ded1bb47e1926e..bf2cc93f51b1e7f6966fefa378e8dee747d4abb3 100644 Binary files a/FocusTerra/.vs/FocusTerra/v16/.suo and b/FocusTerra/.vs/FocusTerra/v16/.suo differ diff --git a/FocusTerra/.vs/FocusTerra/v16/ipch/AutoPCH/814970c2f16523d/WAVE_HANDLER.ipch b/FocusTerra/.vs/FocusTerra/v16/ipch/AutoPCH/814970c2f16523d/WAVE_HANDLER.ipch index 2723c38591f2a276c1b262dd442ba829108396c3..4bca3bdee0ad31702a9aff03824f55bc4147f753 100644 Binary files a/FocusTerra/.vs/FocusTerra/v16/ipch/AutoPCH/814970c2f16523d/WAVE_HANDLER.ipch and b/FocusTerra/.vs/FocusTerra/v16/ipch/AutoPCH/814970c2f16523d/WAVE_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 c1755b23938a6d838e02977f1612f29c18d916bb..329c76cb9400ff7b49d3f8629ced90766a411ef4 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/FocusTerra/FocusTerra/FocusTerra.vcxproj b/FocusTerra/FocusTerra/FocusTerra.vcxproj index cf0679666d0d55fe433ef13667316e1909649844..6dfb839c2625fd183c3ee4fd504d474bd578a07d 100644 --- a/FocusTerra/FocusTerra/FocusTerra.vcxproj +++ b/FocusTerra/FocusTerra/FocusTerra.vcxproj @@ -217,6 +217,7 @@ </ItemGroup> <ItemGroup> <None Include="..\..\build\Makefile" /> + <None Include="..\..\resource\damp_test.conf" /> <None Include="..\..\shaders\combine_damping.frag" /> <None Include="..\..\shaders\combine_damping.vert" /> <None Include="..\..\shaders\copy_red.frag" /> diff --git a/FocusTerra/FocusTerra/FocusTerra.vcxproj.filters b/FocusTerra/FocusTerra/FocusTerra.vcxproj.filters index 60011167ced4301ecb558917cc975b7fa8471afb..25f9adc5b48fe58c0512afaf889b054d5f6e0f14 100644 --- a/FocusTerra/FocusTerra/FocusTerra.vcxproj.filters +++ b/FocusTerra/FocusTerra/FocusTerra.vcxproj.filters @@ -220,6 +220,9 @@ <None Include="..\..\shaders\combine_damping.frag"> <Filter>Resource Files</Filter> </None> + <None Include="..\..\resource\damp_test.conf"> + <Filter>Resource Files</Filter> + </None> </ItemGroup> <ItemGroup> <Text Include="..\..\resource\classDesign.txt"> diff --git a/FocusTerra/FocusTerra/imgui.ini b/FocusTerra/FocusTerra/imgui.ini index e11fec52864c20c3a0f7a3ed605a8e874fa5cd06..58421a6444229a9f7b29f031ab6de838d8c6c182 100644 --- a/FocusTerra/FocusTerra/imgui.ini +++ b/FocusTerra/FocusTerra/imgui.ini @@ -6,7 +6,7 @@ Collapsed=0 [Window][Controller] Pos=2176,0 Size=384,1440 -Collapsed=1 +Collapsed=0 [Window][Developer] Pos=60,60 diff --git a/FocusTerra/FocusTerra/x64/Release/FocusTerra.iobj b/FocusTerra/FocusTerra/x64/Release/FocusTerra.iobj index 485caa7ed53c17f5dcc6a87d71d4741e29d09cde..e9baf0dbb54f188fbd31226eb5f7a1623ecd889b 100644 Binary files a/FocusTerra/FocusTerra/x64/Release/FocusTerra.iobj and b/FocusTerra/FocusTerra/x64/Release/FocusTerra.iobj differ diff --git a/FocusTerra/FocusTerra/x64/Release/FocusTerra.ipdb b/FocusTerra/FocusTerra/x64/Release/FocusTerra.ipdb index f4e69ae2c6d8860abdc5809a2d615e54a5153710..5fe716f9007a71c7b8f76109df71caeef34f1528 100644 Binary files a/FocusTerra/FocusTerra/x64/Release/FocusTerra.ipdb and b/FocusTerra/FocusTerra/x64/Release/FocusTerra.ipdb differ diff --git a/FocusTerra/FocusTerra/x64/Release/FocusTerra.log b/FocusTerra/FocusTerra/x64/Release/FocusTerra.log index cfc9725e0b57f5ead9a9b59d2ff8f93bebd250b7..ee7883800e98d9c8a0e58fe86092652f94a3942e 100644 --- a/FocusTerra/FocusTerra/x64/Release/FocusTerra.log +++ b/FocusTerra/FocusTerra/x64/Release/FocusTerra.log @@ -31,18 +31,14 @@ C:\Users\engel\VS_Projects\FocusTerra\framebuffer-testing\src\wave_handler.cpp(2 _Ty=GLuint ] C:\Users\engel\VS_Projects\FocusTerra\framebuffer-testing\src\wave_handler.cpp(273,37): warning C4267: '=': conversion from 'size_t' to 'GLuint', possible loss of data -C:\Users\engel\VS_Projects\FocusTerra\framebuffer-testing\src\wave_handler.cpp(316,19): warning C4244: 'initializing': conversion from 'float' to 'unsigned int', possible loss of data -C:\Users\engel\VS_Projects\FocusTerra\framebuffer-testing\src\wave_handler.cpp(455,35): warning C4305: 'argument': truncation from 'double' to 'float' -C:\Users\engel\VS_Projects\FocusTerra\framebuffer-testing\src\wave_handler.cpp(456,35): warning C4305: 'argument': truncation from 'double' to 'float' - main_testing.cpp -C:\Users\engel\VS_Projects\FocusTerra\framebuffer-testing\include\drawing_handler.hpp(26,21): warning C4305: 'initializing': truncation from 'double' to 'float' -C:\Users\engel\VS_Projects\FocusTerra\framebuffer-testing\src\main_testing.cpp(21,79): warning C4244: 'argument': conversion from 'double' to 'const int', possible loss of data -C:\Users\engel\VS_Projects\FocusTerra\framebuffer-testing\src\main_testing.cpp(21,34): warning C4244: 'argument': conversion from 'double' to 'const int', possible loss of data +C:\Users\engel\VS_Projects\FocusTerra\framebuffer-testing\src\wave_handler.cpp(318,21): warning C4244: 'initializing': conversion from 'float' to 'unsigned int', possible loss of data +C:\Users\engel\VS_Projects\FocusTerra\framebuffer-testing\src\wave_handler.cpp(461,35): warning C4305: 'argument': truncation from 'double' to 'float' +C:\Users\engel\VS_Projects\FocusTerra\framebuffer-testing\src\wave_handler.cpp(462,35): warning C4305: 'argument': truncation from 'double' to 'float' Generating code -C:\Users\engel\VS_Projects\FocusTerra\framebuffer-testing\src\wave_handler.cpp(445): warning C4715: 'WaveHandler::initialize_comp_data_': not all control paths return a value +C:\Users\engel\VS_Projects\FocusTerra\framebuffer-testing\src\wave_handler.cpp(509): warning C4715: 'WaveHandler::initialize_shaders_': not all control paths return a value C:\Users\engel\VS_Projects\FocusTerra\framebuffer-testing\src\main_testing.cpp(96): warning C4715: 'SDL_main': not all control paths return a value - 2 of 2024 functions (<0.1%) were compiled, the rest were copied from previous compilation. + 3 of 2032 functions ( 0.1%) were compiled, the rest were copied from previous compilation. 0 functions were new in current compilation - 14 functions had inline decision re-evaluated but remain unchanged + 13 functions had inline decision re-evaluated but remain unchanged Finished generating code FocusTerra.vcxproj -> C:\Users\engel\VS_Projects\FocusTerra\framebuffer-testing\FocusTerra\x64\Release\FocusTerra.exe diff --git a/FocusTerra/FocusTerra/x64/Release/FocusTerra.tlog/CL.command.1.tlog b/FocusTerra/FocusTerra/x64/Release/FocusTerra.tlog/CL.command.1.tlog index eae08909a5ff83a878c40b7295e21a0c2aed5234..4c9401f4d2351de43061665391c2d2c930bf46da 100644 Binary files a/FocusTerra/FocusTerra/x64/Release/FocusTerra.tlog/CL.command.1.tlog and b/FocusTerra/FocusTerra/x64/Release/FocusTerra.tlog/CL.command.1.tlog differ diff --git a/FocusTerra/FocusTerra/x64/Release/FocusTerra.tlog/CL.read.1.tlog b/FocusTerra/FocusTerra/x64/Release/FocusTerra.tlog/CL.read.1.tlog index 3c0c9b851807467d8a8d55322765427a42c56407..76fd5a316d1e323932c2deda01f95bccab2712ab 100644 Binary files a/FocusTerra/FocusTerra/x64/Release/FocusTerra.tlog/CL.read.1.tlog and b/FocusTerra/FocusTerra/x64/Release/FocusTerra.tlog/CL.read.1.tlog differ diff --git a/FocusTerra/FocusTerra/x64/Release/FocusTerra.tlog/CL.write.1.tlog b/FocusTerra/FocusTerra/x64/Release/FocusTerra.tlog/CL.write.1.tlog index 14c70b62034ad812162d43cb277d695c2923e484..352cfa9f8b498f7b3586aa65102c875a7995c8a7 100644 Binary files a/FocusTerra/FocusTerra/x64/Release/FocusTerra.tlog/CL.write.1.tlog and b/FocusTerra/FocusTerra/x64/Release/FocusTerra.tlog/CL.write.1.tlog differ diff --git a/FocusTerra/FocusTerra/x64/Release/gui_handler.obj b/FocusTerra/FocusTerra/x64/Release/gui_handler.obj index 263e570a230902c5b10f67ac755bd39099019433..8dbd80c7a2893829cd394dd3d9c6b160f4342923 100644 Binary files a/FocusTerra/FocusTerra/x64/Release/gui_handler.obj and b/FocusTerra/FocusTerra/x64/Release/gui_handler.obj differ diff --git a/FocusTerra/FocusTerra/x64/Release/main_testing.obj b/FocusTerra/FocusTerra/x64/Release/main_testing.obj index deae433e6f46e30df3cb3f48519f1f29fa7eff92..5fd5c6d29cebfbd426bf0c04c686e3a846260761 100644 Binary files a/FocusTerra/FocusTerra/x64/Release/main_testing.obj and b/FocusTerra/FocusTerra/x64/Release/main_testing.obj differ diff --git a/FocusTerra/FocusTerra/x64/Release/vc142.pdb b/FocusTerra/FocusTerra/x64/Release/vc142.pdb index 91138372cf452d8c7b60f58ce47ae14bc7a3d513..9b07b1a57ddad87853d680efafb166c092af005e 100644 Binary files a/FocusTerra/FocusTerra/x64/Release/vc142.pdb and b/FocusTerra/FocusTerra/x64/Release/vc142.pdb differ diff --git a/FocusTerra/FocusTerra/x64/Release/wave_handler.obj b/FocusTerra/FocusTerra/x64/Release/wave_handler.obj index 76feadbdd39df5af98b25b69f8075d16abf19fc1..e25e089ca11d03a9ba27bc675416c4a6196c6eee 100644 Binary files a/FocusTerra/FocusTerra/x64/Release/wave_handler.obj and b/FocusTerra/FocusTerra/x64/Release/wave_handler.obj differ diff --git a/FocusTerra/x64/Release/FocusTerra.exe b/FocusTerra/x64/Release/FocusTerra.exe index c6cbd5ffdf592e0a03205ce18af59f000b67788d..2bab968859f2e342bc9e99a80abc0adee38b278d 100644 Binary files a/FocusTerra/x64/Release/FocusTerra.exe and b/FocusTerra/x64/Release/FocusTerra.exe differ diff --git a/FocusTerra/x64/Release/FocusTerra.pdb b/FocusTerra/x64/Release/FocusTerra.pdb index ca88b36b45742d3a0f671bb4becea4547f1544af..d3e99f9decdab301dfcf2f069b00e925525c61b0 100644 Binary files a/FocusTerra/x64/Release/FocusTerra.pdb and b/FocusTerra/x64/Release/FocusTerra.pdb differ diff --git a/include/wave_handler.hpp b/include/wave_handler.hpp index db3d4e161291a487fed4d8c9a7f3cd24aa1ba401..6e0204f8c6c630868123898e194bd8553f2c0a35 100644 --- a/include/wave_handler.hpp +++ b/include/wave_handler.hpp @@ -14,7 +14,7 @@ public: WaveHandler(const WaveHandler&) = delete; /*Public Member Functions*/ - bool initialize(); + bool initialize(const std::string damping_file=""); //damping_file is the name of the damping that should be loaded, without file extension void update(Toolbox& tb); void prepare_step(); bool step(Toolbox& tb); @@ -31,8 +31,9 @@ private: /*Private Member Functions*/ bool initialize_2D_data_(); bool initialize_3D_data_(); - bool initialize_comp_data_(); + bool initialize_comp_data_(const std::string); bool initialize_shaders_(); + bool load_damping_(const std::string); /*Private Data Members*/ const int width_, height_; /*Window dimensions*/ diff --git a/resource/damp_smooth.conf b/resource/damp_smooth.conf new file mode 100644 index 0000000000000000000000000000000000000000..7648af27f4b46870bf73f8f86c5d1b9b5ef315c0 --- /dev/null +++ b/resource/damp_smooth.conf @@ -0,0 +1,5 @@ +2560 +1440 +3584 +2016 +0.2 diff --git a/resource/damp_smooth.texture b/resource/damp_smooth.texture new file mode 100644 index 0000000000000000000000000000000000000000..a3068e55d3ac43a0cc312976262a67aedf135534 Binary files /dev/null and b/resource/damp_smooth.texture differ diff --git a/resource/damp_test.conf b/resource/damp_test.conf new file mode 100644 index 0000000000000000000000000000000000000000..2a586e630e8dd46106315c1105014f196360226b --- /dev/null +++ b/resource/damp_test.conf @@ -0,0 +1,5 @@ +2560 +1440 +3584 +2015 +0.2 \ No newline at end of file diff --git a/shaders/render2d.frag b/shaders/render2d.frag index ad59b915043e750235d69541744149436ee3134c..3328b2082ae003865d25051a7f15922bf6e4b44d 100644 --- a/shaders/render2d.frag +++ b/shaders/render2d.frag @@ -14,8 +14,8 @@ void main(){ float damping = texture(tex_damp, textureCoordinates).r; //Debugging: top line //Running: bottom line - float damping_color = (1. - damping)*60; - //float damping_color = (1. - damping); + //float damping_color = (1. - damping)*60; + float damping_color = (1. - damping); FragColor = vec4((0.25*(1.+color.r)+0.25)*damping + damping_color*0.2, damping_color*0.2, damping_color*0.2, 1.); //FragColor = color; } \ No newline at end of file diff --git a/src/main_testing.cpp b/src/main_testing.cpp index da2e3288e244f175bb5c18d93c1d054d92b74b6c..d7a4c77d5568f9dc7e9f2dcd8397afe61e615af6 100644 --- a/src/main_testing.cpp +++ b/src/main_testing.cpp @@ -20,7 +20,7 @@ int main(int argc, char** argv) { Toolbox tb(WIDTH, HEIGHT, WIDTH * (1. + 2. * tex_offscreen_fraction), HEIGHT * (1. + 2. * tex_offscreen_fraction), tex_offscreen_x, tex_offscreen_y, tex_offscreen_fraction, "C:\\Users\\engel\\VS_Projects\\FocusTerra\\framebuffer-testing\\shaders\\"); WaveHandler waves(tb); - waves.initialize(); + waves.initialize("C:\\Users\\engel\\VS_Projects\\FocusTerra\\framebuffer-testing\\resource\\damp_smooth"); waves.transfer_damping_texture(tb); InputHandler ioHandler; GuiHandler guiHandler(0.15f); diff --git a/src/wave_handler.cpp b/src/wave_handler.cpp index a008bb763f150a6c1614ac95afb264385bfa6261..a28f8b0f61e3f8af70fa37f6fe3664a7ec647129 100644 --- a/src/wave_handler.cpp +++ b/src/wave_handler.cpp @@ -26,12 +26,12 @@ WaveHandler::WaveHandler(Toolbox& tb) } /*OpenGL must be loaded before this call (i.e. infra.init() must have executed)*/ -bool WaveHandler::initialize() +bool WaveHandler::initialize(const std::string damping_file) { bool retBool = true; retBool &= initialize_2D_data_(); retBool &= initialize_3D_data_(); - retBool &= initialize_comp_data_(); + retBool &= initialize_comp_data_(damping_file); retBool &= initialize_shaders_(); return retBool; } @@ -289,60 +289,64 @@ bool WaveHandler::initialize_3D_data_() return true; } -bool WaveHandler::initialize_comp_data_() +bool WaveHandler::initialize_comp_data_(const std::string damping_file) { - //int tapered_pixels = 280; - //float delta_damping = 0.00005f; - int tapered_pixels = 280; - float delta_damping = 0.00005f; - float high_damping = 0.985f; - float low_damping = 0.999f; - int source_offset = 50; - //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 = uv_off_screen_ * height_ * texwidth_ * 4 + static_cast<int>(uv_off_screen_ * width_) * 4; - for (size_t i = 0; i < height_; ++i) { - for (size_t j = 0; j < width_; ++j) { - tex_damp_data_[offset + 4 * texwidth_ * i + 4 * j] = low_damping; - tex_damp_data_[offset + 4 * texwidth_ * i + 4 * j + 1] = 0.f; - tex_damp_data_[offset + 4 * texwidth_ * i + 4 * j + 2] = 0.f; - tex_damp_data_[offset + 4 * texwidth_ * i + 4 * j + 3] = 0.f; + /*If we can load damping externally, we do that. Else we generate it ourselves*/ + if (!load_damping_(damping_file)) { + + //int tapered_pixels = 280; + //float delta_damping = 0.00005f; + 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; + } } - } - /*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; + */ + unsigned offset = uv_off_screen_ * height_ * texwidth_ * 4 + static_cast<int>(uv_off_screen_ * width_) * 4; + for (size_t i = 0; i < height_; ++i) { + for (size_t j = 0; j < width_; ++j) { + tex_damp_data_[offset + 4 * texwidth_ * i + 4 * j] = low_damping; + tex_damp_data_[offset + 4 * texwidth_ * i + 4 * j + 1] = 0.f; + tex_damp_data_[offset + 4 * texwidth_ * i + 4 * j + 2] = 0.f; + tex_damp_data_[offset + 4 * texwidth_ * i + 4 * j + 3] = 0.f; + } } - /*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; + /*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; + } } } + /* std::ofstream file("damp_data.txt"); for (int i = 0; i < texheight_; ++i) { for (int j = 0; j < texwidth_; ++j) { @@ -351,6 +355,7 @@ bool WaveHandler::initialize_comp_data_() 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; @@ -387,6 +392,7 @@ bool WaveHandler::initialize_comp_data_() 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 = 50; //std::vector<float> texData(4 * height_ * width_, 0.f); //rgba tex_wave_data_ = std::vector<float>(4 * texheight_ * texwidth_, 0.f); for (size_t i = 0; i < tex_wave_data_.size() / 4; ++i) { @@ -484,9 +490,9 @@ bool WaveHandler::initialize_shaders_() shdr_2d_.use(); shdr_2d_.setInt("tex_wave", 0); shdr_2d_.setInt("tex_damp", 1); - //shdr_2d_.setFloat("uv_offscreen", uv_off_screen_); - float uos = 0.; - shdr_2d_.setFloat("uv_offscreen", uos); + shdr_2d_.setFloat("uv_offscreen", uv_off_screen_); + //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; @@ -505,4 +511,73 @@ bool WaveHandler::initialize_shaders_() void WaveHandler::transfer_damping_texture(Toolbox& tb) const { tb.tex_damp_dynamic = tex_comp_damp_dynamic_; tb.tex_damp_static = tex_comp_damp_static_; +} + +bool WaveHandler::load_damping_(const std::string filename) { + /*Load info about the texture from configuration file*/ + int screen_width, screen_height, texture_width, texture_height; + float texture_fraction_off_screen; + 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 >> texture_fraction_off_screen; + 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\tOff Screen Fraction: " << texture_fraction_off_screen << std::endl; + + /*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; + return false; + } + if (texheight_ != texture_height || texwidth_ != texture_width) { + std::cout << "Incompatible Toolbox Texture Resolution: " << texwidth_ << "x" << texheight_ << std::endl; + return false; + } + if (uv_off_screen_ != texture_fraction_off_screen) { + std::cout << "Incompatible Toolbox Off-Screen Fraction: " << uv_off_screen_ << std::endl; + return 0; + } + + std::fstream dmp_file; + std::string damping_filename = filename + ".texture"; + dmp_file.exceptions(std::ifstream::failbit | std::ifstream::badbit); + try { + dmp_file.open(damping_filename); + + float value; + tex_damp_data_.clear(); + tex_damp_data_.reserve(4 * texture_width * texture_height); + 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; + tex_damp_data_.clear(); + return false; + } + dmp_file >> value; + tex_damp_data_.push_back(value); + } + + dmp_file.close(); + } + catch (std::ifstream::failure e) { + std::cout << "Failed to open file " + damping_filename << std::endl; + return false; + } + + return true; } \ No newline at end of file