├── .gitignore ├── LICENSE ├── bin ├── bld_tiles │ └── buildingTile00.osm.bin ├── buildings_test.bat ├── cubes_test.bat ├── cubes_test_notex.bat ├── dctest64.exe ├── dctest64.exe.orig ├── fonts │ ├── arial_14.fnt │ ├── arial_14_0.tga │ ├── lucida_console_13.fnt │ └── lucida_console_13_0.tga ├── grass_test.bat ├── grass_test_cull.bat ├── perf_test.bat ├── shaders │ ├── block_f.glsl │ ├── block_v.glsl │ ├── buildings_f.glsl │ ├── buildings_g.glsl │ ├── buildings_v.glsl │ ├── buildings_v_n.glsl │ ├── canvas_f.glsl │ ├── canvas_v.glsl │ ├── fs.glsl │ ├── gs.glsl │ ├── heightgen_c.glsl │ ├── mipgen_c.glsl │ ├── proc_f.glsl │ ├── proc_g.glsl │ ├── proc_inst_v.glsl │ ├── proc_tess_tcs.glsl │ ├── proc_tess_tes.glsl │ ├── proc_tess_v.glsl │ ├── proc_v.glsl │ ├── showtime_f.glsl │ ├── showtime_v.glsl │ ├── texgen_c.glsl │ ├── tile_f.glsl │ ├── tile_v.glsl │ └── vs.glsl ├── sign.bat └── tex │ └── grass_blade_d.tga ├── ext └── gl │ ├── glew.h │ ├── glext.h │ ├── wglew.h │ └── wglext.h ├── get_comm.bat ├── get_glm.bat ├── get_glm.sh ├── lib ├── debug │ ├── glew32.lib │ └── glew64.lib └── release │ ├── glew32.lib │ └── glew64.lib ├── prj └── vs2010 │ ├── async_vbo_transfers_Scenario2.vcxproj │ ├── async_vbo_transfers_Scenario2.vcxproj.filters │ └── draw_call_perf.sln ├── readme.md └── src ├── app_bw.cpp ├── app_bw.h ├── app_scenario1.cpp ├── app_scenario1.h ├── app_scenario3.cpp ├── app_scenario3.h ├── app_scenario4.cpp ├── app_scenario4.h ├── base ├── app.cpp ├── app.h ├── base.cpp ├── base.h ├── base_win.cpp ├── bmf.h ├── canvas.cpp ├── canvas.h ├── event.cpp ├── event.h ├── font.cpp ├── font.h ├── frame_context.cpp ├── frame_context.h ├── hptimer.h ├── hptimer_win.cpp ├── mutex.cpp ├── mutex.h ├── pixelfmt.cpp ├── pixelfmt.h ├── tga_utils.h ├── thread.h ├── thread_win.cpp ├── types.h └── utils.h ├── benchmark.cpp ├── benchmark.h ├── cube_gen.cpp ├── cube_gen.h ├── gen_tex.cpp ├── gen_tex.h ├── main.cpp ├── obj_writer.cpp ├── obj_writer.h ├── pci_c.h ├── renderer.cpp ├── renderer.h ├── scene.cpp ├── scene.h ├── scene_buildings.cpp ├── scene_buildings.h ├── scene_grass.cpp ├── scene_grass.h └── scene_i.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | 30 | obj/ 31 | ext/comm 32 | ext/ogl-math 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Laco Hrabcak 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /bin/bld_tiles/buildingTile00.osm.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hrabcak/draw_call_perf/602c578825ce18c0676611056d2361cc161ce635/bin/bld_tiles/buildingTile00.osm.bin -------------------------------------------------------------------------------- /bin/buildings_test.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | del /Q buildings_test.csv 3 | 4 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 1 5 | if %errorlevel% neq 0 exit /b %errorlevel% 6 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 2 7 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 4 8 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 8 9 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 16 10 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 32 11 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 64 12 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 128 13 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 256 14 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 512 15 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 1024 16 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 2048 17 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 4096 18 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 8192 19 | 20 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 1 --buildings-nocull 21 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 2 --buildings-nocull 22 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 4 --buildings-nocull 23 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 8 --buildings-nocull 24 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 16 --buildings-nocull 25 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 32 --buildings-nocull 26 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 64 --buildings-nocull 27 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 128 --buildings-nocull 28 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 256 --buildings-nocull 29 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 512 --buildings-nocull 30 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 1024 --buildings-nocull 31 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 2048 --buildings-nocull 32 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 4096 --buildings-nocull 33 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 8192 --buildings-nocull 34 | 35 | if %errorlevel% neq 0 exit /b %errorlevel% 36 | 37 | dctest64.exe --send-buildings-data -------------------------------------------------------------------------------- /bin/cubes_test_notex.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | del /Q cubes_test.csv 3 | 4 | dctest64.exe --test2 --mesh-size 1 --tex-mode0 --tex-size64 --nocull 5 | dctest64.exe --test2 --mesh-size 2 --tex-mode0 --tex-size64 --nocull 6 | dctest64.exe --test2 --mesh-size 3 --tex-mode0 --tex-size64 --nocull 7 | dctest64.exe --test2 --mesh-size 4 --tex-mode0 --tex-size64 --nocull 8 | dctest64.exe --test2 --mesh-size 5 --tex-mode0 --tex-size64 --nocull 9 | dctest64.exe --test2 --mesh-size 6 --tex-mode0 --tex-size64 --nocull 10 | dctest64.exe --test2 --mesh-size 7 --tex-mode0 --tex-size64 --nocull 11 | dctest64.exe --test2 --mesh-size 8 --tex-mode0 --tex-size64 --nocull 12 | dctest64.exe --test2 --mesh-size 9 --tex-mode0 --tex-size64 --nocull 13 | dctest64.exe --test2 --mesh-size 10 --tex-mode0 --tex-size64 --nocull 14 | dctest64.exe --test2 --mesh-size 11 --tex-mode0 --tex-size64 --nocull 15 | dctest64.exe --test2 --mesh-size 12 --tex-mode0 --tex-size64 --nocull 16 | dctest64.exe --test2 --mesh-size 13 --tex-mode0 --tex-size64 --nocull 17 | dctest64.exe --test2 --mesh-size 14 --tex-mode0 --tex-size64 --nocull 18 | dctest64.exe --test2 --mesh-size 15 --tex-mode0 --tex-size64 --nocull 19 | 20 | dctest64.exe --test2 --mesh-size 1 --tex-mode0 --tex-size64 21 | dctest64.exe --test2 --mesh-size 2 --tex-mode0 --tex-size64 22 | dctest64.exe --test2 --mesh-size 3 --tex-mode0 --tex-size64 23 | dctest64.exe --test2 --mesh-size 4 --tex-mode0 --tex-size64 24 | dctest64.exe --test2 --mesh-size 5 --tex-mode0 --tex-size64 25 | dctest64.exe --test2 --mesh-size 6 --tex-mode0 --tex-size64 26 | dctest64.exe --test2 --mesh-size 7 --tex-mode0 --tex-size64 27 | dctest64.exe --test2 --mesh-size 8 --tex-mode0 --tex-size64 28 | dctest64.exe --test2 --mesh-size 9 --tex-mode0 --tex-size64 29 | dctest64.exe --test2 --mesh-size 10 --tex-mode0 --tex-size64 30 | dctest64.exe --test2 --mesh-size 11 --tex-mode0 --tex-size64 31 | dctest64.exe --test2 --mesh-size 12 --tex-mode0 --tex-size64 32 | dctest64.exe --test2 --mesh-size 13 --tex-mode0 --tex-size64 33 | dctest64.exe --test2 --mesh-size 14 --tex-mode0 --tex-size64 34 | dctest64.exe --test2 --mesh-size 15 --tex-mode0 --tex-size64 35 | 36 | -------------------------------------------------------------------------------- /bin/dctest64.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hrabcak/draw_call_perf/602c578825ce18c0676611056d2361cc161ce635/bin/dctest64.exe -------------------------------------------------------------------------------- /bin/dctest64.exe.orig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hrabcak/draw_call_perf/602c578825ce18c0676611056d2361cc161ce635/bin/dctest64.exe.orig -------------------------------------------------------------------------------- /bin/fonts/arial_14.fnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hrabcak/draw_call_perf/602c578825ce18c0676611056d2361cc161ce635/bin/fonts/arial_14.fnt -------------------------------------------------------------------------------- /bin/fonts/arial_14_0.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hrabcak/draw_call_perf/602c578825ce18c0676611056d2361cc161ce635/bin/fonts/arial_14_0.tga -------------------------------------------------------------------------------- /bin/fonts/lucida_console_13.fnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hrabcak/draw_call_perf/602c578825ce18c0676611056d2361cc161ce635/bin/fonts/lucida_console_13.fnt -------------------------------------------------------------------------------- /bin/fonts/lucida_console_13_0.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hrabcak/draw_call_perf/602c578825ce18c0676611056d2361cc161ce635/bin/fonts/lucida_console_13_0.tga -------------------------------------------------------------------------------- /bin/grass_test.bat: -------------------------------------------------------------------------------- 1 | @echo OFF 2 | del /Q grass_test.csv 3 | 4 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 65536 --pure_color 5 | if %errorlevel% neq 0 exit /b %errorlevel% 6 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 16384 --pure_color 7 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 4096 --pure_color 8 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 1024 --pure_color 9 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 256 --pure_color 10 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 64 --pure_color 11 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 16 --pure_color 12 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 4 --pure_color 13 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 1 --pure_color 14 | if %errorlevel% neq 0 exit /b %errorlevel% 15 | 16 | 17 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 65536 --pure_color --use_idx_buf 18 | if %errorlevel% neq 0 exit /b %errorlevel% 19 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 16384 --pure_color --use_idx_buf 20 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 4096 --pure_color --use_idx_buf 21 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 1024 --pure_color --use_idx_buf 22 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 256 --pure_color --use_idx_buf 23 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 64 --pure_color --use_idx_buf 24 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 16 --pure_color --use_idx_buf 25 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 4 --pure_color --use_idx_buf 26 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 1 --pure_color --use_idx_buf 27 | if %errorlevel% neq 0 exit /b %errorlevel% 28 | 29 | 30 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 65536 --pure_color --use_idx_buf --use_triangles 31 | if %errorlevel% neq 0 exit /b %errorlevel% 32 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 16384 --pure_color --use_idx_buf --use_triangles 33 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 4096 --pure_color --use_idx_buf --use_triangles 34 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 1024 --pure_color --use_idx_buf --use_triangles 35 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 256 --pure_color --use_idx_buf --use_triangles 36 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 64 --pure_color --use_idx_buf --use_triangles 37 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 16 --pure_color --use_idx_buf --use_triangles 38 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 4 --pure_color --use_idx_buf --use_triangles 39 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 1 --pure_color --use_idx_buf --use_triangles 40 | 41 | if %errorlevel% neq 0 exit /b %errorlevel% 42 | 43 | dctest64.exe --send-grass-data 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /bin/grass_test_cull.bat: -------------------------------------------------------------------------------- 1 | @echo OFF 2 | del /Q grass_test.csv 3 | 4 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 65536 --pure_color --grass_cull 5 | if %errorlevel% neq 0 exit /b %errorlevel% 6 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 16384 --pure_color --grass_cull 7 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 4096 --pure_color --grass_cull 8 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 1024 --pure_color --grass_cull 9 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 256 --pure_color --grass_cull 10 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 64 --pure_color --grass_cull 11 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 16 --pure_color --grass_cull 12 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 4 --pure_color --grass_cull 13 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 1 --pure_color --grass_cull 14 | if %errorlevel% neq 0 exit /b %errorlevel% 15 | 16 | 17 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 65536 --pure_color --use_idx_buf --grass_cull 18 | if %errorlevel% neq 0 exit /b %errorlevel% 19 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 16384 --pure_color --use_idx_buf --grass_cull 20 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 4096 --pure_color --use_idx_buf --grass_cull 21 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 1024 --pure_color --use_idx_buf --grass_cull 22 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 256 --pure_color --use_idx_buf --grass_cull 23 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 64 --pure_color --use_idx_buf --grass_cull 24 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 16 --pure_color --use_idx_buf --grass_cull 25 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 4 --pure_color --use_idx_buf --grass_cull 26 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 1 --pure_color --use_idx_buf --grass_cull 27 | if %errorlevel% neq 0 exit /b %errorlevel% 28 | 29 | 30 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 65536 --pure_color --use_idx_buf --use_triangles --grass_cull 31 | if %errorlevel% neq 0 exit /b %errorlevel% 32 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 16384 --pure_color --use_idx_buf --use_triangles --grass_cull 33 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 4096 --pure_color --use_idx_buf --use_triangles --grass_cull 34 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 1024 --pure_color --use_idx_buf --use_triangles --grass_cull 35 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 256 --pure_color --use_idx_buf --use_triangles --grass_cull 36 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 64 --pure_color --use_idx_buf --use_triangles --grass_cull 37 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 16 --pure_color --use_idx_buf --use_triangles --grass_cull 38 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 4 --pure_color --use_idx_buf --use_triangles --grass_cull 39 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 1 --pure_color --use_idx_buf --use_triangles --grass_cull 40 | 41 | if %errorlevel% neq 0 exit /b %errorlevel% 42 | 43 | dctest64.exe --send-grass-data 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /bin/perf_test.bat: -------------------------------------------------------------------------------- 1 | @echo OFF 2 | del /Q grass_test.csv 3 | 4 | 5 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 65536 --pure_color 6 | if %errorlevel% neq 0 exit /b %errorlevel% 7 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 16384 --pure_color 8 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 4096 --pure_color 9 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 1024 --pure_color 10 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 256 --pure_color 11 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 64 --pure_color 12 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 16 --pure_color 13 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 4 --pure_color 14 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 1 --pure_color 15 | if %errorlevel% neq 0 exit /b %errorlevel% 16 | 17 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 65536 --pure_color --use_idx_buf 18 | if %errorlevel% neq 0 exit /b %errorlevel% 19 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 16384 --pure_color --use_idx_buf 20 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 4096 --pure_color --use_idx_buf 21 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 1024 --pure_color --use_idx_buf 22 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 256 --pure_color --use_idx_buf 23 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 64 --pure_color --use_idx_buf 24 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 16 --pure_color --use_idx_buf 25 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 4 --pure_color --use_idx_buf 26 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 1 --pure_color --use_idx_buf 27 | if %errorlevel% neq 0 exit /b %errorlevel% 28 | 29 | 30 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 65536 --pure_color --use_idx_buf --use_triangles 31 | if %errorlevel% neq 0 exit /b %errorlevel% 32 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 16384 --pure_color --use_idx_buf --use_triangles 33 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 4096 --pure_color --use_idx_buf --use_triangles 34 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 1024 --pure_color --use_idx_buf --use_triangles 35 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 256 --pure_color --use_idx_buf --use_triangles 36 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 64 --pure_color --use_idx_buf --use_triangles 37 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 16 --pure_color --use_idx_buf --use_triangles 38 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 4 --pure_color --use_idx_buf --use_triangles 39 | dctest64.exe --test1 --procedural-scene --proc_scene_mode 0 --vs_variable_blades_per_dc --blades_per_dc 1 --pure_color --use_idx_buf --use_triangles 40 | 41 | if %errorlevel% neq 0 exit /b %errorlevel% 42 | 43 | dctest64.exe --send-grass-data 44 | 45 | del /Q buildings_test.csv 46 | 47 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 1 48 | if %errorlevel% neq 0 exit /b %errorlevel% 49 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 2 50 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 4 51 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 8 52 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 16 53 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 32 54 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 64 55 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 128 56 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 256 57 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 512 58 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 1024 59 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 2048 60 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 4096 61 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 8192 62 | 63 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 1 --buildings-nocull 64 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 2 --buildings-nocull 65 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 4 --buildings-nocull 66 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 8 --buildings-nocull 67 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 16 --buildings-nocull 68 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 32 --buildings-nocull 69 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 64 --buildings-nocull 70 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 128 --buildings-nocull 71 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 256 --buildings-nocull 72 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 512 --buildings-nocull 73 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 1024 --buildings-nocull 74 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 2048 --buildings-nocull 75 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 4096 --buildings-nocull 76 | dctest64.exe --test0 --buildings-scene --blocks_per_tile 8192 --buildings-nocull 77 | 78 | if %errorlevel% neq 0 exit /b %errorlevel% 79 | 80 | dctest64.exe --send-buildings-data -------------------------------------------------------------------------------- /bin/shaders/block_f.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | precision highp float; 24 | precision highp int; 25 | 26 | in vec3 color; 27 | in vec2 uv; 28 | in vec3 wpos; 29 | 30 | #if defined(USE_NAIVE_TEX) 31 | uniform sampler2D mat_tex; 32 | #elif defined(USE_ARRAY_TEX) 33 | uniform sampler2DArray mat_tex; 34 | in flat float tex_slice; 35 | #elif defined(USE_BINDLESS_TEX) 36 | #extension GL_ARB_bindless_texture : enable 37 | in flat uvec2 tex_handle; 38 | #endif 39 | 40 | out vec4 _retval; 41 | 42 | void main() 43 | { 44 | vec4 tex_color; 45 | 46 | #if defined(USE_NAIVE_TEX) 47 | tex_color = texture(mat_tex, uv, 0); 48 | #elif defined(USE_ARRAY_TEX) 49 | tex_color = texture(mat_tex, vec3(uv, tex_slice), 0); 50 | #elif defined(USE_BINDLESS_TEX) 51 | tex_color = texture(sampler2D(tex_handle), uv, 0); 52 | #else 53 | tex_color = vec4(vec3(0.5), 0); 54 | #endif 55 | 56 | const vec3 sun_color = vec3(1.0f, 0.9725f, 0.9490f); 57 | 58 | vec3 nor = normalize(cross(dFdx(wpos), dFdy(wpos))); 59 | float fog = clamp(exp2(-0.01 * (1.0 / gl_FragCoord.w)), 0.0, 1.0); 60 | float LdN = clamp(dot(nor, normalize(vec3(-1, 1, -0.5))), 0, 1); 61 | //tex_color.rgb = tex_color.rgb * LdN * sun_color + tex_color.rgb * 0.15; 62 | tex_color.rgb = 63 | tex_color.rgb * LdN * sun_color + tex_color.rgb * 0.15 64 | + tex_color.a * vec3(254, 239,100) * (1.0 / 255.0); 65 | 66 | //if (tex_color.a == 0.0) discard; 67 | 68 | _retval = vec4(tex_color.rgb * fog + vec3(1.0f * (1-fog)),0.9); 69 | } 70 | -------------------------------------------------------------------------------- /bin/shaders/block_v.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | precision highp float; 24 | precision highp int; 25 | 26 | #extension GL_ARB_explicit_attrib_location : enable 27 | 28 | #define PI 3.14159265358979323846 29 | #define TWO_PI 6.28318530717958647692 30 | #define SQRT_2 1.414213562 31 | 32 | // IN 33 | struct context_data 34 | { 35 | mat4 _mvp; 36 | int _mesh_size; 37 | int _tex_freq; 38 | }; 39 | 40 | layout(std140) uniform context 41 | { 42 | context_data _ctx; 43 | }; 44 | 45 | #ifdef USE_BASE_VERTEX_DRAW 46 | uniform isamplerBuffer tb_draw_data; 47 | uniform int basevert; 48 | #else 49 | layout(location = 13) in ivec4 index_start; 50 | #endif 51 | 52 | uniform samplerBuffer tb_blocks; 53 | 54 | #ifdef USE_TB_FOR_VERTEX_DATA 55 | uniform isamplerBuffer tb_pos; 56 | uniform isamplerBuffer tb_nor_uv; 57 | #else 58 | layout(location = 0) in ivec2 in_pos; // NOT IMPLEMENTED YET 59 | layout(location = 1) in ivec2 in_nor_uv; 60 | #endif 61 | 62 | ivec2 get_vertex_pos_data(int vertex_id) 63 | { 64 | #ifdef USE_TB_FOR_VERTEX_DATA 65 | return texelFetch(tb_pos, vertex_id).xy; 66 | #else 67 | return in_pos; 68 | #endif 69 | } 70 | 71 | ivec2 get_norm_uv_data(int vertex_id) 72 | { 73 | #ifdef USE_TB_FOR_VERTEX_DATA 74 | return texelFetch(tb_nor_uv, vertex_id).xy; 75 | #else 76 | return in_nor_uv; 77 | #endif 78 | } 79 | 80 | #if defined(USE_BINDLESS_TEX) 81 | uniform usamplerBuffer tb_tex_handles; 82 | out flat uvec2 tex_handle; 83 | #elif defined(USE_ARRAY_TEX) 84 | out flat float tex_slice; 85 | #endif 86 | 87 | //OUT 88 | out vec3 color; 89 | out vec2 uv; 90 | out vec3 wpos; 91 | 92 | vec3 unpack_position(ivec2 pack_pos, float coef) 93 | { 94 | return vec3( 95 | pack_pos.x >> 11, 96 | ((pack_pos.x << 21) >> 11) | (pack_pos.y >> 21), 97 | (pack_pos.y << 11) >> 11) 98 | * coef; 99 | } 100 | 101 | vec3 unpack_norm(ivec2 pack_norm, float coef){ 102 | vec3 result = vec3(pack_norm.x >> 16, (pack_norm.x << 16) >> 16, 0.0); 103 | float lenght2 = dot(result.xy,result.xy); 104 | result.z = (pack_norm.y & 0x1)!=0?-1.0:1.0; 105 | return vec3(0.0,0.0,0.0);//result * coef; 106 | } 107 | 108 | vec2 unpack_uv(ivec2 pack_uv,float coef){ 109 | return vec2(pack_uv.y >> 17, (pack_uv.y << 15) >> 17) * coef; 110 | } 111 | 112 | void main() 113 | { 114 | int vertex_id = gl_VertexID; 115 | int index = vertex_id >> 12; 116 | 117 | #ifdef USE_BASE_VERTEX_DRAW 118 | #ifdef USE_BASE_VERTEX_DRAW_WA 119 | index = basevert; 120 | #endif 121 | ivec4 index_start = texelFetch(tb_draw_data, index); 122 | #endif 123 | 124 | vertex_id &= 0xfff; 125 | int idx = index_start.x * 4; 126 | mat4 tm = mat4( 127 | texelFetch(tb_blocks, idx), 128 | texelFetch(tb_blocks, idx + 1), 129 | texelFetch(tb_blocks, idx + 2), 130 | texelFetch(tb_blocks, idx + 3)); 131 | 132 | int inst_id = index_start.z; 133 | int vtx_index = index_start.y + vertex_id; 134 | ivec2 tmp0 = get_vertex_pos_data(vtx_index); 135 | vec3 pos = unpack_position(tmp0.xy, 1.0 / 1048575.0); 136 | 137 | tmp0 = get_norm_uv_data(vtx_index); 138 | uv = clamp(unpack_uv(tmp0.xy,1.0 / 16383.0),0.0,1.0); 139 | 140 | inst_id = _ctx._tex_freq == -1 ? 0 : inst_id >> _ctx._tex_freq; 141 | 142 | #if defined(USE_BINDLESS_TEX) 143 | tex_handle = texelFetch(tb_tex_handles, inst_id).xy; 144 | #elif defined(USE_ARRAY_TEX) 145 | tex_slice = inst_id & 0x7ff; 146 | #endif 147 | 148 | wpos = (tm * vec4(pos, 1)).xyz; 149 | gl_Position = _ctx._mvp * vec4(wpos,1); 150 | color = pos * 0.5 + 0.5; 151 | } 152 | -------------------------------------------------------------------------------- /bin/shaders/buildings_f.glsl: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | precision highp int; 3 | 4 | in OUT { 5 | vec3 wpos; 6 | } inp; 7 | 8 | out vec4 _retval; 9 | 10 | void main() 11 | { 12 | vec3 norm = normalize(cross(dFdx(inp.wpos), dFdy(inp.wpos))); 13 | float d = clamp(dot(norm, normalize(vec3(1, 1, 0))), 0, 1); 14 | _retval = vec4(norm,0.0); 15 | } 16 | -------------------------------------------------------------------------------- /bin/shaders/buildings_g.glsl: -------------------------------------------------------------------------------- 1 | #version 330 2 | precision highp float; 3 | precision highp int; 4 | 5 | //////////////////////////////////////////////////////////////////////////////// 6 | in OUT { 7 | vec3 wpos; 8 | vec4 opos; 9 | } inp[3]; 10 | 11 | out OUT2{ 12 | vec3 wpos; 13 | } o; 14 | 15 | layout(triangles) in; 16 | layout(triangle_strip, max_vertices = 3) out; 17 | 18 | void main() 19 | { 20 | if ((inp[2].opos.x - inp[0].opos.x) * (inp[0].opos.y - inp[1].opos.y) >= (inp[2].opos.y - inp[0].opos.y) * (inp[0].opos.x - inp[1].opos.x)) { 21 | 22 | for (int i = 0; i < 3; i++) { 23 | o.wpos = inp[i].wpos; 24 | gl_Position = inp[i].opos; 25 | EmitVertex(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /bin/shaders/buildings_v.glsl: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | precision highp int; 3 | 4 | uniform samplerBuffer tb_vertices; 5 | uniform usamplerBuffer tb_flags; 6 | uniform mat4 mvp; 7 | 8 | out OUT { 9 | vec3 wpos; 10 | } o; 11 | 12 | void main() 13 | { 14 | int index = (gl_InstanceID << 2) + (gl_VertexID & 3); 15 | vec2 xy = texelFetch(tb_vertices, index).xy; 16 | uint flags = texelFetch(tb_flags, gl_InstanceID).x; 17 | o.wpos = vec3(xy.x, float((gl_VertexID > 3) ? flags >> 4u: 0u) , -xy.y); 18 | vec4 opos = mvp * vec4(o.wpos, 1); 19 | 20 | opos.z = log2(max(1e-6, 1.0 + opos.w)) / log(1000000 + 1.0) - 1.0; 21 | opos.z *= opos.w; 22 | gl_Position = opos; 23 | } 24 | -------------------------------------------------------------------------------- /bin/shaders/buildings_v_n.glsl: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | precision highp int; 3 | 4 | uniform isamplerBuffer tb_blocks; 5 | uniform ivec2 tile_offset; 6 | uniform mat4 mvp; 7 | uniform uint total_count; 8 | 9 | out OUT{ 10 | vec3 wpos; 11 | } o; 12 | 13 | /* 14 | Buiding packing 15 | base_point - relative to tile 16 | - 16bits per component 17 | ohter 3 points - relative to base point 18 | - 13 bits per components 19 | 20 | ivec4{ 21 | upper bits -> lower bits 22 | x - base_point.x(16 bits), base_point.y(16 bits) 23 | y - p1.x(13 bits), p1.y(13 bits),p2.x(6 bit)sa 24 | z - p2.x(7 bits), p2.y(13 bits), p3.x(12 bits) 25 | w - p3.x(1 bit),p3.y(13 bits), falgs (18 bits) 26 | } 27 | 28 | */ 29 | 30 | vec2 unpack_ivec4_to_p1(ivec4 packed_block){ 31 | vec2 result; 32 | const float scale16 = 2500.0f / 32767.0f; 33 | 34 | result.x = (packed_block.x >> 16) * scale16; 35 | result.y = ((packed_block.x << 16) >> 16) * scale16; 36 | 37 | return result; 38 | } 39 | 40 | vec2 unpack_ivec4_to_p2(ivec4 packed_block){ 41 | vec2 result; 42 | const float scale13 = 312.5f / 4095.0f; 43 | 44 | result.x = (packed_block.y >> 19) * scale13; 45 | result.y = ((packed_block.y << 13) >> 19) * scale13; 46 | 47 | return result; 48 | } 49 | 50 | vec2 unpack_ivec4_to_p3(ivec4 packed_block){ 51 | vec2 result; 52 | const float scale13 = 312.5f / 4095.0f; 53 | 54 | result.x = (((packed_block.y << 26) >> 19) | ((packed_block.z >> 25) & 0x7f)) * scale13; 55 | result.y = ((packed_block.z << 7) >> 19) * scale13; 56 | 57 | return result; 58 | } 59 | 60 | vec2 unpack_ivec4_to_p4(ivec4 packed_block){ 61 | vec2 result; 62 | const float scale13 = 312.5f / 4095.0f; 63 | 64 | result.x = (((packed_block.z << 20) >> 19) | ((packed_block.w >> 31) & 0x1))* scale13; 65 | result.y = ((packed_block.w << 1) >> 19)* scale13; 66 | 67 | 68 | return result; 69 | } 70 | 71 | uint unpack_ivec4_to_flags(ivec4 packed_block){ 72 | return uint(packed_block.w & 0xff); 73 | } 74 | 75 | void main() 76 | { 77 | const float t_width = 2500.0f; 78 | int vtxID = gl_VertexID & 7; 79 | int index = gl_InstanceID * BLOCKS_PER_IDC + (gl_VertexID >> 3); 80 | 81 | if(index >= total_count){ 82 | gl_Position = vec4(0.0, 0.0, 0.0, 0.0); 83 | return; 84 | } 85 | 86 | ivec4 block = texelFetch(tb_blocks, index); 87 | 88 | vec2 xy; 89 | uint flags = unpack_ivec4_to_flags(block); 90 | 91 | vec2 base_point = unpack_ivec4_to_p1(block) + vec2(tile_offset) * t_width; // base point of buidling 92 | 93 | if ((vtxID & 3) == 0){ 94 | xy = base_point; 95 | } 96 | else if((vtxID & 3) == 1){ 97 | xy = base_point + unpack_ivec4_to_p2(block); 98 | } 99 | else if((vtxID & 3) == 2){ 100 | xy = base_point + unpack_ivec4_to_p3(block); 101 | } 102 | else if((vtxID & 3) == 3){ 103 | xy = base_point + unpack_ivec4_to_p4(block); 104 | } 105 | 106 | o.wpos = vec3(xy.x, (vtxID > 3) ? (float(flags) * 2.9) * 0.5 : 0.0, -xy.y); 107 | vec4 opos = mvp * vec4(o.wpos, 1); 108 | 109 | opos.z = log2(max(1e-6, 1.0 + opos.w)) / log(1000000 + 1.0) - 1.0; 110 | opos.z *= opos.w; 111 | gl_Position = opos; 112 | } 113 | -------------------------------------------------------------------------------- /bin/shaders/canvas_f.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #version 430 24 | 25 | precision highp float; 26 | precision highp int; 27 | 28 | layout(binding = 5) uniform sampler2D tex_font; 29 | uniform vec4 clip; 30 | 31 | in vec2 uv; 32 | in vec4 color; 33 | flat in int color_only; 34 | 35 | out vec4 _retval; 36 | 37 | void main() 38 | { 39 | vec4 col; 40 | 41 | if(color_only != 1) 42 | col = textureLod(tex_font, uv / vec2(textureSize(tex_font, 0)), 0); 43 | else 44 | col = vec4(1); 45 | 46 | if(col.a == 0.0f 47 | || gl_FragCoord.x < clip.x 48 | || gl_FragCoord.x > clip.z 49 | || gl_FragCoord.y < clip.y 50 | || gl_FragCoord.y > clip.w) 51 | discard; 52 | 53 | _retval = col * color; 54 | } 55 | -------------------------------------------------------------------------------- /bin/shaders/canvas_v.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #version 430 24 | precision highp float; 25 | precision highp int; 26 | 27 | layout(binding = 4) uniform samplerBuffer tb_elements; 28 | uniform vec2 screen_size; //< 1.0 / screen_size 29 | uniform int start_index; 30 | 31 | out vec2 uv; 32 | out vec4 color; 33 | flat out int color_only; 34 | 35 | void main() 36 | { 37 | int index = start_index + gl_InstanceID * 3; 38 | 39 | vec4 pos = texelFetch(tb_elements, index) * vec4(screen_size, screen_size); 40 | vec4 texpos = texelFetch(tb_elements, index + 1); 41 | color = texelFetch(tb_elements, index + 2); 42 | 43 | vec2 local_pos = vec2(gl_VertexID & 1, (gl_VertexID & 2) >> 1); 44 | 45 | uv.xy = texpos.xy + local_pos * texpos.zw; 46 | pos.xy += local_pos * pos.zw; 47 | gl_Position = vec4(pos.xy * 2.0 - 1.0, 0, 1); 48 | 49 | color_only = texpos.z==0 ? 1 : 0; 50 | } 51 | -------------------------------------------------------------------------------- /bin/shaders/fs.glsl: -------------------------------------------------------------------------------- 1 | #version 330 2 | precision highp float; 3 | precision highp int; 4 | 5 | layout(location=0) out vec3 _retval; 6 | 7 | uniform sampler2D tex; 8 | 9 | void main() 10 | { 11 | ivec2 uv=ivec2(gl_FragCoord); 12 | _retval=texelFetch(tex,uv,0).xyz; 13 | } 14 | -------------------------------------------------------------------------------- /bin/shaders/gs.glsl: -------------------------------------------------------------------------------- 1 | #version 330 2 | precision highp float; 3 | precision highp int; 4 | 5 | //comment out here and in vs.glsl to get the second problem 6 | //#define BUG_2 7 | 8 | //////////////////////////////////////////////////////////////////////////////// 9 | in _struct_TreeBilboNode { 10 | vec4 pos; 11 | vec4 norm_h; 12 | vec3 bilvec; 13 | #ifdef BUG_2 14 | vec4 attenuation; 15 | vec4 light; 16 | #endif 17 | } p[1]; 18 | 19 | out _struct_TreeBilboVertex { 20 | vec2 coord; 21 | flat out int jj; 22 | } v; 23 | 24 | uniform mat4 modelViewProj_6; 25 | uniform float invfarplanecoef_6; 26 | layout(points) in; 27 | layout(triangle_strip, max_vertices = 4) out; 28 | 29 | void main() 30 | { 31 | if(p[0].pos.w != 0) 32 | { 33 | vec3 bilvec = 4.5 * (1 + 0.5*p[0].norm_h.w) * p[0].bilvec; 34 | vec3 height = 30 * (1 + 0.5*p[0].norm_h.w) * p[0].norm_h.xyz; 35 | 36 | vec3 tpos; 37 | tpos = p[0].pos.xyz + bilvec; 38 | gl_Position = modelViewProj_6 * vec4(tpos, 1); 39 | v.coord = vec2(1,1); 40 | v.jj=1; 41 | EmitVertex(); 42 | 43 | tpos = p[0].pos.xyz + bilvec + height; 44 | gl_Position = modelViewProj_6 * vec4(tpos, 1); 45 | v.coord = vec2(1,0); 46 | v.jj=1; 47 | EmitVertex(); 48 | 49 | tpos = p[0].pos.xyz - bilvec; 50 | gl_Position = modelViewProj_6 * vec4(tpos, 1); 51 | v.coord = vec2(0,1); 52 | v.jj=1; 53 | EmitVertex(); 54 | 55 | tpos = p[0].pos.xyz - bilvec + height; 56 | gl_Position = modelViewProj_6 * vec4(tpos, 1); 57 | v.coord = vec2(0,0); 58 | v.jj=1; 59 | EmitVertex(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /bin/shaders/heightgen_c.glsl: -------------------------------------------------------------------------------- 1 | layout(binding = 0, r32ui) uniform writeonly uimage2D dst; 2 | 3 | layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in; 4 | 5 | uniform ivec2 pos; 6 | 7 | vec4 random_2d_perm(ivec2 coord) 8 | { 9 | const ivec4 D = ivec4(1, 17, -43, 71); 10 | int xp = coord.x; 11 | int yp = coord.y; 12 | 13 | const ivec4 K = ivec4(2047483673, 1951307951, 1815206923, 1664526161); 14 | 15 | ivec4 p = (K * xp + D) * xp; 16 | p = (p & 0xffff) + yp; 17 | p = (K*p + D)*p; 18 | p = (p & 0xffff) - 0x8000; 19 | 20 | return vec4(p) * float(1.0 / 0x8000); 21 | } 22 | 23 | float random_1d_perm1(int coord) 24 | { 25 | const int D = 1; 26 | int xp = coord; 27 | 28 | const int K = 2047483673; 29 | 30 | int p = (K * xp + D) * xp; 31 | p = (p & 0xffff) - 0x8000;//p - 16807*(p/16807); 32 | 33 | return float(p) * float(1.0 / 0x8000); 34 | } 35 | 36 | void main() 37 | { 38 | ivec2 seed = pos*BLOCKSPERROW + ivec2(gl_GlobalInvocationID.xy); 39 | vec4 rnd = random_2d_perm(seed); 40 | 41 | 42 | imageStore( 43 | dst, 44 | ivec2(gl_GlobalInvocationID.xy), 45 | uvec4(((0.35 + rnd.x * 0.25) * 0xffff))); 46 | //ivec4(0)); 47 | } 48 | -------------------------------------------------------------------------------- /bin/shaders/mipgen_c.glsl: -------------------------------------------------------------------------------- 1 | layout(binding = 0, rgba8) uniform readonly image2DArray src; 2 | layout(binding = 1, rgba8) uniform writeonly image2DArray dst; 3 | 4 | layout(local_size_x = GROUP_SIZE, local_size_y = GROUP_SIZE, local_size_z = GROUP_DEPTH) in; 5 | 6 | void main() 7 | { 8 | ivec3 pos = ivec3(gl_GlobalInvocationID.xy << 1, gl_GlobalInvocationID.z); 9 | vec4 c0 = imageLoad(src, pos); 10 | vec4 c1 = imageLoad(src, pos + ivec3(1,0,0)); 11 | vec4 c2 = imageLoad(src, pos + ivec3(1, 1, 0)); 12 | vec4 c3 = imageLoad(src, pos + ivec3(0, 1, 0)); 13 | 14 | imageStore( 15 | dst, 16 | ivec3(gl_GlobalInvocationID.xyz), 17 | (c0 + c1 + c2 + c3) * 0.25); 18 | } 19 | -------------------------------------------------------------------------------- /bin/shaders/proc_f.glsl: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | precision highp int; 3 | 4 | #ifdef USE_TEXTURE 5 | uniform sampler2D grass_tex; 6 | #endif 7 | 8 | in Color{ 9 | #ifdef USE_TEXTURE 10 | vec2 uv; 11 | #else 12 | #ifdef IP_1F 13 | float color; 14 | #elif defined(IP_2F) 15 | vec2 color; 16 | #elif defined(IP_3F) 17 | vec3 color; 18 | #elif defined(IP_4F) 19 | vec4 color; 20 | #else 21 | vec3 color; 22 | #endif 23 | #endif 24 | }color_in; 25 | 26 | out vec4 _retval; 27 | 28 | in vec3 norm; 29 | 30 | 31 | void main(){ 32 | #ifdef USE_TEXTURE 33 | vec3 col_grass = vec3(texture(grass_tex,color_in.uv)); 34 | 35 | #ifdef PURE_COLOR 36 | _retval = vec4(col_grass,1.0); 37 | #else 38 | const vec3 sun_color = vec3(1.0f, 0.9725f, 0.9490f); 39 | float LdN = clamp(dot(norm, normalize(vec3(-1, 1, -0.5))), 0, 1); 40 | _retval = vec4(col_grass *0.15 + LdN * col_grass * sun_color,1.0); 41 | #endif 42 | 43 | #else 44 | 45 | #ifdef PURE_COLOR 46 | #ifdef IP_1F 47 | _retval = vec4(color_in.color, 0.5, 0.5, 0.5); 48 | #elif defined(IP_2F) 49 | _retval = vec4(color_in.color, 0.5, 0.5); 50 | #elif defined(IP_3F) 51 | _retval = vec4(color_in.color,0.5); 52 | #elif defined(IP_4F) 53 | _retval = color_in.color; 54 | #else 55 | _retval = vec4(0,0.8,0,0.5); 56 | #endif 57 | #else 58 | const vec3 sun_color = vec3(1.0f, 0.9725f, 0.9490f); 59 | float LdN = clamp(dot(norm, normalize(vec3(-1, 1, -0.5))), 0, 1); 60 | //_retval = color_in.color *0.15 + LdN * color_in.color * sun_color; 61 | 62 | _retval = vec4(color_in.color * 0.15 + LdN * color_in.color * sun_color,0.9); 63 | #endif 64 | 65 | #endif 66 | } -------------------------------------------------------------------------------- /bin/shaders/proc_g.glsl: -------------------------------------------------------------------------------- 1 | layout(points) in; 2 | #ifdef USE_END_PRIMITIVE 3 | 4 | layout(triangle_strip, max_vertices = VERTS_PER_GEOM_RUN ) out; 5 | 6 | vec4 random_2d_perm(ivec2 coord) 7 | { 8 | const ivec4 D = ivec4(1, 17, -43, 71); 9 | int xp = coord.x; 10 | int yp = coord.y; 11 | 12 | const ivec4 K = ivec4(2047483673, 1951307951, 1815206923, 1664526161); 13 | 14 | ivec4 p = (K * xp + D) * xp; 15 | p = (p & 0xffff) + yp; 16 | p = (K*p + D)*p; 17 | p = (p & 0xffff) - 0x8000; 18 | 19 | return vec4(p) * float(1.0 / 0x8000); 20 | } 21 | 22 | uniform vec2 tile_pos; 23 | 24 | #else 25 | layout(triangle_strip, max_vertices = 7) out; 26 | #endif 27 | 28 | #define PI_HALF 1.57079632679489661923 29 | #define TRICOUNT 20 30 | #define RADIUS 0.02 31 | #define PI 3.14159265358979323846 32 | #define TWO_PI 6.28318530717958647692 33 | #define SQRT_2 1.414213562 34 | 35 | #define BLADE_WIDTH 0.02 36 | #define BLADE_HEIGHT 0.1 37 | 38 | // IN 39 | struct context_data 40 | { 41 | mat4 _mvp; 42 | int _mesh_size; 43 | int _tex_freq; 44 | }; 45 | 46 | layout(std140) uniform context 47 | { 48 | context_data _ctx; 49 | }; 50 | 51 | in Color{ 52 | #ifdef USE_TEXTURE 53 | vec2 uv; 54 | #else 55 | #ifdef IP_1F 56 | float color; 57 | #elif defined(IP_2F) 58 | vec2 color; 59 | #elif defined(IP_3F) 60 | vec3 color; 61 | #elif defined(IP_4F) 62 | vec4 color; 63 | #else 64 | vec3 color; 65 | #endif 66 | #endif 67 | }color_in[]; 68 | 69 | out Color{ 70 | #ifdef USE_TEXTURE 71 | vec2 uv; 72 | #else 73 | #ifdef IP_1F 74 | float color; 75 | #elif defined(IP_2F) 76 | vec2 color; 77 | #elif defined(IP_3F) 78 | vec3 color; 79 | #elif defined(IP_4F) 80 | vec4 color; 81 | #else 82 | vec3 color; 83 | #endif 84 | #endif 85 | }color_out; 86 | 87 | in vec3 blade_tangent[]; 88 | 89 | in float grass_h[]; 90 | 91 | out vec3 norm; 92 | 93 | uniform sampler2D height_map; 94 | 95 | void main(){ 96 | const float hcf = 1.0 / 3.0; 97 | 98 | const vec3 up = vec3(0.0, 1.0, 0.0); 99 | 100 | const vec4 blade_up_displace = vec4(up * grass_h[0], 0.0) / 3.0; 101 | 102 | #ifndef USE_TEXTURE 103 | color_out.color = color_in[0].color; 104 | #endif 105 | #ifdef USE_END_PRIMITIVE 106 | const float block_width = TILEWIDTH / float(BLOCKSPERROW); 107 | const float half_block_width = 0.5*block_width; 108 | 109 | const float bpt_inverse = 1.0/BLADESPERTUFT; 110 | 111 | vec4 block_pos_r = gl_in[0].gl_Position; 112 | 113 | for(int blade_id = int(block_pos_r.z * BLADES_PER_GEOM_RUN); blade_id < int((block_pos_r.z + 1) * BLADES_PER_GEOM_RUN); blade_id++){ 114 | //for(int blade_id = 0; blade_id < 8; blade_id++){ 115 | vec2 block_pos = tile_pos*TILEWIDTH + vec2(block_pos_r.x * block_width, block_pos_r.y * block_width) + half_block_width; 116 | 117 | vec4 rnd = random_2d_perm(ivec2(block_pos * blade_id * BLOCKSPERROW)); 118 | 119 | vec4 base_position = vec4(block_pos.x + rnd.x*half_block_width, 0.0, block_pos.y+ rnd.y*half_block_width, 1.0); 120 | 121 | vec3 bx_dis = vec3( cos(TWO_PI*bpt_inverse*blade_id - PI_HALF), 0.0 , sin(TWO_PI*bpt_inverse*blade_id- PI_HALF)) * BLADE_WIDTH; 122 | 123 | vec3 bend = normalize(cross(up, bx_dis)); 124 | 125 | for (int i = 0; i < 7; i++){ 126 | #if defined(IP_1F) || defined(IP_2F) || defined(IP_3F) || defined(IP_4F) 127 | color_out.color = color_in[0].color * (i/7.0); 128 | #endif 129 | 130 | float k = (i >> 1) * hcf; 131 | 132 | vec3 bend_displace = bend*(1 - exp2(-1))*k*k*grass_h[0]; 133 | 134 | norm = normalize(cross(blade_up_displace.xyz + bend_displace, bx_dis)); 135 | 136 | gl_Position = _ctx._mvp * (base_position + vec4(bx_dis * (1.0 - k*k) * ((i & 1) - 0.5) + bend_displace, 0.0)); 137 | 138 | 139 | #ifdef USE_TEXTURE 140 | color_out.uv = vec2(0.5 + ((i & 1) - 0.5)* (1.0 - k*k), k); 141 | #endif 142 | 143 | EmitVertex(); 144 | 145 | if ((i & 1) == 1 && i > 0){ 146 | base_position += blade_up_displace; 147 | } 148 | } 149 | 150 | EndPrimitive(); 151 | } 152 | 153 | #else 154 | vec4 base_position = gl_in[0].gl_Position; 155 | 156 | vec3 bx_dis = blade_tangent[0] * BLADE_WIDTH; 157 | 158 | vec3 bend = normalize(cross(up, blade_tangent[0])); 159 | 160 | for (int i = 0; i < 7; i++){ 161 | #if defined(IP_1F) || defined(IP_2F) || defined(IP_3F) || defined(IP_4F) 162 | color_out.color = color_in[0].color * (i/7.0); 163 | #endif 164 | float k = (i >> 1) * hcf; 165 | 166 | vec3 bend_displace = bend*(1 - exp2(-1))*k*k*grass_h[0]; 167 | 168 | norm = normalize(cross(blade_up_displace.xyz + bend_displace, bx_dis)); 169 | 170 | gl_Position = _ctx._mvp * (base_position + vec4(bx_dis * (1.0 - k*k) * ((i & 1) - 0.5) + bend_displace, 0.0)); 171 | 172 | 173 | #ifdef USE_TEXTURE 174 | color_out.uv = vec2(0.5 + ((i & 1) - 0.5)* (1.0 - k*k), k); 175 | #endif 176 | 177 | EmitVertex(); 178 | 179 | if ((i & 1) == 1 && i > 0){ 180 | base_position += blade_up_displace; 181 | } 182 | } 183 | 184 | #endif 185 | } -------------------------------------------------------------------------------- /bin/shaders/proc_inst_v.glsl: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | precision highp int; 3 | 4 | #define PI_HALF 1.57079632679489661923 5 | #define PI 3.14159265358979323846 6 | #define TWO_PI 6.28318530717958647692 7 | #define SQRT_2 1.414213562 8 | 9 | 10 | #define BLADE_WIDTH 0.02 11 | #define BLADE_HEIGHT 0.1 12 | 13 | 14 | // IN 15 | struct context_data 16 | { 17 | mat4 _mvp; 18 | int _mesh_size; 19 | int _tex_freq; 20 | }; 21 | 22 | layout(std140) uniform context 23 | { 24 | context_data _ctx; 25 | }; 26 | 27 | uniform vec2 tile_pos; 28 | 29 | uniform usampler2D height_map; 30 | 31 | 32 | out Color{ 33 | #ifdef USE_TEXTURE 34 | vec2 uv; 35 | #else 36 | #ifdef IP_1F 37 | float color; 38 | #elif defined(IP_2F) 39 | vec2 color; 40 | #elif defined(IP_3F) 41 | vec3 color; 42 | #elif defined(IP_4F) 43 | vec4 color; 44 | #else 45 | vec3 color; 46 | #endif 47 | #endif 48 | }color_out; 49 | 50 | out vec3 norm; 51 | 52 | vec4 random_2d_perm(ivec2 coord) 53 | { 54 | const ivec4 D = ivec4(1, 17, -43, 71); 55 | int xp = coord.x; 56 | int yp = coord.y; 57 | 58 | const ivec4 K = ivec4(2047483673, 1951307951, 1815206923, 1664526161); 59 | 60 | ivec4 p = (K * xp + D) * xp; 61 | p = (p & 0xffff) + yp; 62 | p = (K*p + D)*p; 63 | p = (p & 0xffff) - 0x8000; 64 | 65 | return vec4(p) * float(1.0 / 0x8000); 66 | } 67 | 68 | 69 | #ifdef VARIABLE_BLADES_PER_INSTANCE 70 | 71 | void get_blade_data_variable_blades_per_dc(out int blade_vtx_id, out int blade_instance_id, out ivec2 tuft_pos_r){ 72 | const int bpr_log2 = int(log2(BLOCKSPERROW)); 73 | int global_blade_id = -1; 74 | 75 | #ifdef USE_IDX_BUF 76 | blade_vtx_id = gl_VertexID % VERT_PER_BLADE; 77 | global_blade_id = gl_InstanceID * BLADES_PER_INSTANCE + (gl_VertexID / VERT_PER_BLADE); 78 | #else 79 | if(BLADES_PER_INSTANCE==1){ 80 | blade_vtx_id = gl_VertexID; 81 | global_blade_id = gl_InstanceID; 82 | 83 | }else { 84 | blade_vtx_id = gl_VertexID % (VERT_PER_BLADE + 2); 85 | blade_vtx_id = (blade_vtx_id == 0) ? 0 : blade_vtx_id - 1; 86 | blade_vtx_id = (blade_vtx_id == VERT_PER_BLADE) ? VERT_PER_BLADE - 1 : blade_vtx_id; 87 | 88 | global_blade_id = gl_InstanceID * BLADES_PER_INSTANCE + (gl_VertexID / (VERT_PER_BLADE + 2)); 89 | } 90 | #endif 91 | 92 | #ifdef RND_BLADE_ID 93 | global_blade_id = ((global_blade_id & 1) << 15 ) | 94 | ((global_blade_id & 2) << 13 ) | 95 | ((global_blade_id & 4) << 11 ) | 96 | ((global_blade_id & 8) << 9 ) | 97 | ((global_blade_id & 16) << 7 ) | 98 | ((global_blade_id & 32) << 5 ) | 99 | ((global_blade_id & 64) << 3 ) | 100 | ((global_blade_id & 128) << 1 ) | 101 | ((global_blade_id & 0xff00) >> 8 ); 102 | #endif 103 | 104 | blade_instance_id = global_blade_id & 15; 105 | 106 | tuft_pos_r.x = (global_blade_id >> 4) & 63; 107 | tuft_pos_r.y = global_blade_id >> 10; 108 | 109 | } 110 | 111 | #endif 112 | 113 | void main(){ 114 | const float hcf = 1.0 / (VERT_PER_BLADE >> 1); 115 | const vec3 up = vec3(0.0, 1.0, 0.0); 116 | const float block_width = TILEWIDTH / float(BLOCKSPERROW); 117 | const int bpr_log2 = int(log2(BLOCKSPERROW)); 118 | const float half_block_width = 0.5*block_width; 119 | 120 | #ifdef USE_IDX_BUF 121 | const int verts_per_block = VERT_PER_BLADE*BLADESPERTUFT; 122 | #else 123 | const int verts_per_block = (VERT_PER_BLADE + 2)*BLADESPERTUFT; 124 | #endif 125 | 126 | int block_part = gl_VertexID % verts_per_block; 127 | int instance_part = (gl_VertexID - block_part) / verts_per_block; 128 | 129 | 130 | #ifdef VARIABLE_BLADES_PER_INSTANCE 131 | int vertex_id = -1; 132 | int instance_id = -1; 133 | ivec2 block_pos_r; 134 | 135 | get_blade_data_variable_blades_per_dc(vertex_id,instance_id,block_pos_r); 136 | 137 | #elif defined(ONE_BATCH) 138 | #ifndef USE_TRIANGLES 139 | #ifdef USE_IDX_BUF 140 | int vertex_id = block_part % (VERT_PER_BLADE ); 141 | int instance_id = block_part / VERT_PER_BLADE; 142 | #else 143 | int vertex_id = block_part % (VERT_PER_BLADE + 2); 144 | vertex_id = (vertex_id == 0) ? 0 : vertex_id - 1; 145 | vertex_id = (vertex_id == VERT_PER_BLADE) ? VERT_PER_BLADE - 1 : vertex_id; 146 | int instance_id = block_part / (VERT_PER_BLADE + 2); 147 | #endif 148 | ivec2 block_pos_r = ivec2(instance_part & (BLOCKSPERROW - 1), (instance_part >> bpr_log2)); 149 | #else 150 | int vertex_id = gl_VertexID & 7; 151 | int instance_id = (gl_VertexID >> 4) & 15; 152 | ivec2 block_pos_r = ivec2((gl_VertexID >> 14) & 0x3f, (gl_VertexID >> 8) & 0x3f); 153 | #endif 154 | #else 155 | 156 | 157 | const int subdc_per_row = int(sqrt(DC_COUNT)); 158 | const int subdc_per_row_log2 = int(log2(subdc_per_row)); 159 | 160 | const int blocks_per_dc = BLOCKSPERROW / subdc_per_row; 161 | const int blocks_per_dc_log2 = int(log2(blocks_per_dc)); 162 | 163 | ivec2 subdc_origin = ivec2((gl_InstanceID & (subdc_per_row - 1)), (gl_InstanceID >> subdc_per_row_log2)) * blocks_per_dc; 164 | #ifndef USE_TRIANGLES 165 | #ifdef USE_IDX_BUF 166 | int vertex_id = block_part % (VERT_PER_BLADE ); 167 | int instance_id = block_part / VERT_PER_BLADE; 168 | #else 169 | int vertex_id = block_part % (VERT_PER_BLADE + 2); 170 | vertex_id = (vertex_id == 0) ? 0 : vertex_id - 1; 171 | vertex_id = (vertex_id == VERT_PER_BLADE) ? VERT_PER_BLADE-1 : vertex_id; 172 | int instance_id = block_part / (VERT_PER_BLADE + 2); 173 | #endif 174 | ivec2 block_pos_r = subdc_origin + ivec2(instance_part & (blocks_per_dc - 1), (instance_part >> blocks_per_dc_log2)); 175 | #else 176 | int vertex_id = gl_VertexID & 7; 177 | int instance_id = (gl_VertexID >> 4) & 15; 178 | ivec2 block_pos_r = subdc_origin + ivec2((gl_VertexID >> 14) & 0x3f, (gl_VertexID >> 8) & 0x3f); 179 | #endif 180 | 181 | #endif 182 | uvec4 height = texelFetch(height_map, block_pos_r,0); 183 | 184 | float grass_h = float(height.x) / float(0xffff); 185 | 186 | vec2 block_pos = tile_pos*TILEWIDTH + vec2(block_pos_r.x * block_width, block_pos_r.y * block_width) + half_block_width; 187 | vec4 rnd = random_2d_perm(ivec2(block_pos * instance_id * BLOCKSPERROW)); 188 | 189 | vec4 blade_pos = vec4(block_pos.x + rnd.x*half_block_width, 0.0, block_pos.y + rnd.y*half_block_width, 1.0); 190 | 191 | float tan_angle = (TWO_PI / float(BLADESPERTUFT)) * instance_id - PI_HALF; 192 | 193 | vec3 blade_tangent = vec3(cos(tan_angle), 0.0, sin(tan_angle)); 194 | 195 | vec3 bx_dis = blade_tangent * BLADE_WIDTH; 196 | 197 | vec4 blade_up_displace = vec4(up * grass_h, 0.0); 198 | 199 | float k = (vertex_id >> 1) * hcf; 200 | 201 | #ifdef WITHOUT_BENDING 202 | vec3 bend = cross(up, blade_tangent); 203 | 204 | vec3 bend_displace = 0.5*bend*k*k*BLADE_HEIGHT; 205 | 206 | norm = normalize(cross(blade_up_displace.xyz + bend_displace, bx_dis)); 207 | 208 | gl_Position = _ctx._mvp * (turf_pos + vec4(bx_dis * (1.0 - k*k) * ((vertex_id & 1) - 0.5) + vec3(0,0,0), 0.0) + (blade_up_displace * k)); 209 | #else 210 | vec3 bend = cross(up, blade_tangent); 211 | 212 | vec3 bend_displace = 0.5*bend*k*k*grass_h; 213 | 214 | norm = normalize(cross(blade_up_displace.xyz * hcf + bend_displace, bx_dis)); 215 | 216 | gl_Position = _ctx._mvp * (blade_pos + vec4(bx_dis * (1.0 - k*k) * ((vertex_id & 1) - 0.5) + bend_displace, 0.0) + (blade_up_displace * k)); 217 | 218 | #endif 219 | 220 | #ifdef USE_TEXTURE 221 | color_out.uv = vec2(0.5 + (0.5*((vertex_id & 1) - 0.5)* (1.0 - k*k)), k); 222 | #else 223 | rnd = random_2d_perm(ivec2(gl_VertexID))*0.5 + 0.5; 224 | #ifdef IP_1F 225 | color_out.color = rnd.x; 226 | #elif defined(IP_2F) 227 | color_out.color = rnd.xy; 228 | #elif defined(IP_3F) 229 | color_out.color = rnd.xyz; 230 | #elif defined(IP_4F) 231 | color_out.color = rnd; 232 | #else 233 | color_out.color = vec3(0.0, 0.29215, 0.0); 234 | #endif 235 | #endif 236 | } -------------------------------------------------------------------------------- /bin/shaders/proc_tess_tcs.glsl: -------------------------------------------------------------------------------- 1 | layout(vertices = 4) out; 2 | 3 | in vec3 norm_cs_in[]; 4 | out vec3 norm_es_in[]; 5 | 6 | in Color{ 7 | #ifdef USE_TEXTURE 8 | vec2 uv; 9 | #else 10 | vec3 color; 11 | #endif 12 | }color_in[]; 13 | 14 | out Color{ 15 | #ifdef USE_TEXTURE 16 | vec2 uv; 17 | #else 18 | vec3 color; 19 | #endif 20 | }color_out[]; 21 | 22 | in vec3 vert_cs_in[]; 23 | out vec3 vert_es_in[]; 24 | 25 | 26 | void main(){ 27 | norm_es_in[gl_InvocationID] = norm_cs_in[gl_InvocationID]; 28 | #ifdef USE_TEXTURE 29 | color_out[gl_InvocationID].uv = color_in[gl_InvocationID].uv; 30 | #else 31 | color_out[gl_InvocationID].color = color_in[gl_InvocationID].color; 32 | #endif 33 | 34 | vert_es_in[gl_InvocationID] = vert_cs_in[gl_InvocationID]; 35 | 36 | if (gl_InvocationID == 0){ 37 | gl_TessLevelOuter[0] = 3; 38 | gl_TessLevelOuter[1] = 1; 39 | gl_TessLevelOuter[2] = 3; 40 | gl_TessLevelOuter[3] = 1; 41 | 42 | gl_TessLevelInner[0] = 0; 43 | gl_TessLevelInner[1] = 3; 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /bin/shaders/proc_tess_tes.glsl: -------------------------------------------------------------------------------- 1 | layout(quads, equal_spacing, ccw) in; 2 | 3 | struct context_data 4 | { 5 | mat4 _mvp; 6 | int _mesh_size; 7 | int _tex_freq; 8 | }; 9 | 10 | layout(std140) uniform context 11 | { 12 | context_data _ctx; 13 | }; 14 | 15 | in vec3 norm_es_in[]; 16 | out vec3 norm; 17 | 18 | in Color{ 19 | #ifdef USE_TEXTURE 20 | vec2 uv; 21 | #else 22 | vec3 color; 23 | #endif 24 | }color_in[]; 25 | 26 | out Color{ 27 | #ifdef USE_TEXTURE 28 | vec2 uv; 29 | #else 30 | vec3 color; 31 | #endif 32 | }color_out; 33 | 34 | in vec3 vert_es_in[]; 35 | 36 | vec2 interpolate2D(vec2 v0, vec2 v1, vec2 v2) 37 | { 38 | return vec2(gl_TessCoord.x) * v0 + vec2(gl_TessCoord.y) * v1 + vec2(gl_TessCoord.z) * v2; 39 | } 40 | 41 | vec3 interpolate3D(vec3 v0, vec3 v1, vec3 v2) 42 | { 43 | return vec3(gl_TessCoord.x) * v0 + vec3(gl_TessCoord.y) * v1 + vec3(gl_TessCoord.z) * v2; 44 | } 45 | 46 | void main(){ 47 | gl_Position = _ctx._mvp * vec4(mix(mix(vert_es_in[0], vert_es_in[1],gl_TessCoord.x), 48 | mix(vert_es_in[2], vert_es_in[3], gl_TessCoord.x),gl_TessCoord.y),1.0); 49 | #ifdef USE_TEXTURE 50 | color_out.uv = interpolate2D(color_in[0].uv, color_in[1].uv, color_in[2].uv); 51 | #else 52 | color_out.color = color_in[0].color; 53 | #endif 54 | 55 | norm = interpolate3D(norm_es_in[0], norm_es_in[1], norm_es_in[2]); 56 | } -------------------------------------------------------------------------------- /bin/shaders/proc_tess_v.glsl: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | precision highp int; 3 | 4 | #define PI_HALF 1.57079632679489661923 5 | #define PI 3.14159265358979323846 6 | #define TWO_PI 6.28318530717958647692 7 | #define SQRT_2 1.414213562 8 | 9 | #define BLADE_WIDTH 0.03 10 | #define BLADE_HEIGHT 0.1 11 | 12 | uniform vec2 tile_pos; 13 | 14 | uniform usampler2D height_map; 15 | 16 | out Color{ 17 | #ifdef USE_TEXTURE 18 | vec2 uv; 19 | #else 20 | vec3 color; 21 | #endif 22 | }color_out; 23 | 24 | out vec3 norm_cs_in; 25 | out vec3 vert_cs_in; 26 | 27 | 28 | vec4 random_2d_perm(ivec2 coord) 29 | { 30 | const ivec4 D = ivec4(1, 17, -43, 71); 31 | int xp = coord.x; 32 | int yp = coord.y; 33 | 34 | const ivec4 K = ivec4(2047483673, 1951307951, 1815206923, 1664526161); 35 | 36 | ivec4 p = (K * xp + D) * xp; 37 | p = (p & 0xffff) + yp; 38 | p = (K*p + D)*p; 39 | p = (p & 0xffff) - 0x8000; 40 | 41 | return vec4(p) * float(1.0 / 0x8000); 42 | } 43 | 44 | void main(){ 45 | const vec3 up = vec3(0.0, 1.0, 0.0); 46 | const float block_width = TILEWIDTH / float(BLOCKSPERROW); 47 | const int bpr_log2 = int(log2(BLOCKSPERROW)); 48 | const float half_block_width = 0.5*block_width; 49 | 50 | const int instance_id = gl_VertexID / 4; 51 | int vert_id = gl_VertexID % 4; 52 | vert_id = (vert_id == 3) ? 2 : vert_id; 53 | const int block_pos_part = gl_InstanceID; 54 | 55 | ivec2 block_pos_r = ivec2(block_pos_part & (BLOCKSPERROW - 1), (block_pos_part >> bpr_log2)); 56 | 57 | uvec4 height = texelFetch(height_map, block_pos_r, 0); 58 | 59 | const float grass_h = float(height.x) / float(0xffff); 60 | 61 | vec2 block_pos = tile_pos*TILEWIDTH + vec2(block_pos_r.x * block_width, block_pos_r.y * block_width) + half_block_width; 62 | vec4 rnd = random_2d_perm(ivec2(block_pos * instance_id * BLOCKSPERROW)); 63 | 64 | vec4 turf_pos = vec4(block_pos.x + rnd.x*half_block_width, 0.0, block_pos.y + rnd.y*half_block_width, 1.0); 65 | 66 | const float tan_angle = 0;//(TWO_PI / float(BLADESPERTUFT)) * instance_id - PI_HALF; 67 | 68 | vec3 blade_tangent = vec3(cos(tan_angle), 0.0, sin(tan_angle)); 69 | 70 | vec3 bx_dis = blade_tangent * BLADE_WIDTH; 71 | 72 | vec4 blade_up_displace = vec4(up * grass_h, 0.0); 73 | 74 | float k = float(vert_id >> 1); 75 | 76 | norm_cs_in = normalize(cross(blade_up_displace.xyz, bx_dis)); 77 | 78 | vert_cs_in = ((turf_pos + vec4(bx_dis * ((vert_id & 1) - 0.5) + vec3(0, 0, 0), 0.0) + (blade_up_displace * k))).xyz; 79 | 80 | 81 | #ifdef USE_TEXTURE 82 | color_out.uv = vec2(0.5 + (0.5*((vert_id & 1) - 0.5)* (1.0 - k)), k); 83 | #else 84 | color_out.color = vec3(0.0, 0.29215, 0.0); 85 | #endif 86 | } -------------------------------------------------------------------------------- /bin/shaders/proc_v.glsl: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | precision highp int; 3 | 4 | #define PI_HALF 1.57079632679489661923 5 | #define PI 3.14159265358979323846 6 | #define TWO_PI 6.28318530717958647692 7 | #define SQRT_2 1.414213562 8 | 9 | // IN 10 | struct context_data 11 | { 12 | mat4 _mvp; 13 | int _mesh_size; 14 | int _tex_freq; 15 | }; 16 | 17 | layout(std140) uniform context 18 | { 19 | context_data _ctx; 20 | }; 21 | 22 | uniform vec2 tile_pos; 23 | 24 | uniform usampler2D height_map; 25 | 26 | out Color{ 27 | #ifdef USE_TEXTURE 28 | vec2 uv; 29 | #else 30 | #ifdef IP_1F 31 | float color; 32 | #elif defined(IP_2F) 33 | vec2 color; 34 | #elif defined(IP_3F) 35 | vec3 color; 36 | #elif defined(IP_4F) 37 | vec4 color; 38 | #else 39 | vec3 color; 40 | #endif 41 | #endif 42 | }color_out; 43 | 44 | out vec3 blade_tangent; 45 | 46 | out float grass_h; 47 | 48 | vec4 random_2d_perm(ivec2 coord) 49 | { 50 | const ivec4 D = ivec4(1, 17, -43, 71); 51 | int xp = coord.x; 52 | int yp = coord.y; 53 | 54 | const ivec4 K = ivec4(2047483673, 1951307951, 1815206923, 1664526161); 55 | 56 | ivec4 p = (K * xp + D) * xp; 57 | p = (p & 0xffff) + yp; 58 | p = (K*p + D)*p; 59 | p = (p & 0xffff) - 0x8000; 60 | 61 | return vec4(p) * float(1.0 / 0x8000); 62 | } 63 | 64 | void main() 65 | { 66 | #ifdef USE_END_PRIMITIVE 67 | #ifdef ONE_BATCH 68 | const int bpr_log2 = int(log2(BLOCKSPERROW)); 69 | const int blades_per_dc = BLADESPERTUFT / BLADES_PER_GEOM_RUN; 70 | const int bpdc_log2 = int(log2(blades_per_dc)); 71 | ivec2 block_pos_r = ivec2((gl_VertexID >> (bpdc_log2)) & (BLOCKSPERROW - 1), gl_VertexID >> (bpdc_log2 + bpr_log2)); 72 | uvec4 height = texelFetch(height_map, block_pos_r, 0); 73 | grass_h = float(height.x) / float(0xffff); 74 | gl_Position = vec4(block_pos_r, gl_VertexID & (blades_per_dc - 1), 1.0); 75 | 76 | vec4 rnd = random_2d_perm(ivec2(block_pos_r * height.x * BLOCKSPERROW)); 77 | #else 78 | const int bpr_log2 = int(log2(BLOCKSPERROW)); 79 | ivec2 block_pos_r = ivec2(gl_VertexID & (BLOCKSPERROW - 1), gl_VertexID >> (bpr_log2)); 80 | uvec4 height = texelFetch(height_map, block_pos_r, 0); 81 | grass_h = float(height.x) / float(0xffff); 82 | gl_Position = vec4(block_pos_r, gl_InstanceID, 1.0); 83 | 84 | vec4 rnd = random_2d_perm(ivec2(block_pos_r * height.x * BLOCKSPERROW)); 85 | 86 | #endif 87 | #else 88 | const float block_width = TILEWIDTH / float(BLOCKSPERROW); 89 | const float half_block_width = 0.5*block_width; 90 | int inst_part = gl_VertexID % BLADESPERTUFT; 91 | int block_part = (gl_VertexID - inst_part) / BLADESPERTUFT; 92 | 93 | #ifdef ONE_BATCH 94 | const int bpr_log2 = int(log2(BLOCKSPERROW)); 95 | ivec2 block_pos_r = ivec2(block_part & (BLOCKSPERROW -1), block_part >> bpr_log2); 96 | #else 97 | const int subdc_per_row = int(sqrt(DC_COUNT)); 98 | const int subdc_per_row_log2 = int(log2(subdc_per_row)); 99 | 100 | const int blocks_per_dc = BLOCKSPERROW / subdc_per_row; 101 | const int blocks_per_dc_log2 = int(log2(blocks_per_dc)); 102 | 103 | ivec2 subdc_origin = ivec2((gl_InstanceID & (subdc_per_row - 1)), (gl_InstanceID >> subdc_per_row_log2)) * blocks_per_dc; 104 | 105 | ivec2 block_pos_r = subdc_origin + ivec2(block_part & (blocks_per_dc - 1), (block_part >> blocks_per_dc_log2)); 106 | #endif 107 | 108 | vec2 block_pos = tile_pos*TILEWIDTH + vec2(block_pos_r.x * block_width, block_pos_r.y * block_width) + half_block_width; 109 | vec4 rnd = random_2d_perm(ivec2(block_pos * inst_part * BLOCKSPERROW)); 110 | 111 | vec4 turf_pos = vec4(block_pos.x + rnd.x*half_block_width, 0.0, block_pos.y+ rnd.y*half_block_width, 1.0); 112 | 113 | const float rad_per_blade = (TWO_PI / float(BLADESPERTUFT)); 114 | const float tan_angle = rad_per_blade * inst_part - PI_HALF; 115 | 116 | blade_tangent = vec3(cos(tan_angle), 0.0, sin(tan_angle)); 117 | 118 | uvec4 height = texelFetch(height_map, block_pos_r, 0); 119 | 120 | grass_h = float(height.x) / float(0xffff); 121 | 122 | gl_Position = turf_pos; 123 | #endif 124 | 125 | #ifndef USE_TEXTURE 126 | 127 | #ifdef IP_1F 128 | color_out.color = rnd.x; 129 | #elif defined(IP_2F) 130 | color_out.color = rnd.xy; 131 | #elif defined(IP_3F) 132 | color_out.color = rnd.xyz; 133 | #elif defined(IP_4F) 134 | color_out.color = rnd; 135 | #else 136 | color_out.color = vec3(0.0, 0.29215, 0.0); 137 | #endif 138 | #endif 139 | } -------------------------------------------------------------------------------- /bin/shaders/showtime_f.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #version 140 24 | //#version 330 25 | precision highp float; 26 | precision highp int; 27 | 28 | uniform sampler2D tex; 29 | out vec4 _retval; 30 | 31 | in vec2 uv; 32 | 33 | void main() 34 | { 35 | _retval = texture(tex, uv) * vec4(0.8,0.8,1,1); 36 | } 37 | -------------------------------------------------------------------------------- /bin/shaders/showtime_v.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | //#version 330 24 | #version 140 25 | precision highp float; 26 | precision highp int; 27 | 28 | uniform mat4 mvp; 29 | uniform vec2 size; 30 | 31 | out vec2 uv; 32 | 33 | #define PI 3.14159265358979323846 34 | #define TWO_PI 6.28318530717958647692 35 | #define SQRT_2 1.414213562 36 | 37 | void main() 38 | { 39 | gl_Position = mvp * vec4( 40 | ((gl_VertexID & 1) * 2.0 - 1.0) * size.x, 41 | ((gl_VertexID & 2) - 1.0) * size.y, 42 | 0, 1); 43 | 44 | uv = vec2(gl_VertexID & 1, (gl_VertexID & 2) >> 1); 45 | } 46 | -------------------------------------------------------------------------------- /bin/shaders/texgen_c.glsl: -------------------------------------------------------------------------------- 1 | layout(binding = 0, rgba8) uniform writeonly image2DArray dst; 2 | 3 | layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in; 4 | 5 | vec4 random_2d_perm(ivec2 coord) 6 | { 7 | const ivec4 D = ivec4(1, 17, -43, 71); 8 | int xp = coord.x; 9 | int yp = coord.y; 10 | 11 | const ivec4 K = ivec4(2047483673, 1951307951, 1815206923, 1664526161); 12 | 13 | ivec4 p = (K * xp + D) * xp; 14 | p = (p & 0xffff) + yp; 15 | p = (K*p + D)*p; 16 | p = (p & 0xffff) - 0x8000; 17 | 18 | return vec4(p) * float(1.0 / 0x8000); 19 | } 20 | 21 | float random_1d_perm1(int coord) 22 | { 23 | const int D = 1; 24 | int xp = coord; 25 | 26 | const int K = 2047483673; 27 | 28 | int p = (K * xp + D) * xp; 29 | p = (p & 0xffff) - 0x8000;//p - 16807*(p/16807); 30 | 31 | return float(p) * float(1.0 / 0x8000); 32 | } 33 | 34 | void main() 35 | { 36 | const vec4 c0[] = { 37 | vec4(0.6462, 0.7648, 0.8421, 1), 38 | vec4(0.1538, 0.1538, 0.1538, 0) * 0.5, 39 | vec4(0.3101, 0.2069, 0.1137, 0) 40 | }; 41 | 42 | ivec2 seed = ivec2(gl_GlobalInvocationID.x >> 2, gl_GlobalInvocationID.y >> 1) 43 | + int(gl_GlobalInvocationID.z * 128); 44 | 45 | vec4 rnd = random_2d_perm(seed); 46 | int irnd = min(int(abs(rnd.w) * 16), 2); 47 | 48 | float rnd2 = random_1d_perm1(int(gl_GlobalInvocationID.z)); 49 | 50 | if (gl_GlobalInvocationID.x == 0 && gl_GlobalInvocationID.x == 0) 51 | irnd = 2; 52 | 53 | vec4 color = c0[irnd]; 54 | 55 | 56 | color.rgb += vec3(rnd2 * 0.1); 57 | color.r += abs(rnd2 * 0.05); 58 | 59 | imageStore( 60 | dst, 61 | ivec3(gl_GlobalInvocationID.xyz), 62 | color); 63 | } 64 | -------------------------------------------------------------------------------- /bin/shaders/tile_f.glsl: -------------------------------------------------------------------------------- 1 | in vec3 color; 2 | 3 | out vec4 _retval; 4 | 5 | 6 | void main() { 7 | _retval = vec4(color,1.0); 8 | } -------------------------------------------------------------------------------- /bin/shaders/tile_v.glsl: -------------------------------------------------------------------------------- 1 | // IN 2 | struct context_data 3 | { 4 | mat4 _mvp; 5 | int _mesh_size; 6 | int _tex_freq; 7 | }; 8 | 9 | layout(std140) uniform context 10 | { 11 | context_data _ctx; 12 | }; 13 | 14 | uniform vec2 tile_pos; 15 | 16 | out vec3 color; 17 | 18 | void main(){ 19 | int vert_ord = gl_VertexID; 20 | 21 | if (vert_ord == 5){ 22 | vert_ord = 1; 23 | } 24 | else if (vert_ord == 4){ 25 | vert_ord = 3; 26 | } 27 | else if (vert_ord == 3){ 28 | vert_ord = 0; 29 | } 30 | 31 | vec4 base_vert = vec4(tile_pos.x * TILEWIDTH, -0.001, tile_pos.y * TILEWIDTH, 1.0); 32 | 33 | if (vert_ord == 0){ 34 | gl_Position = _ctx._mvp * base_vert; 35 | } 36 | else if (vert_ord == 1){ 37 | gl_Position = _ctx._mvp * (base_vert + vec4(TILEWIDTH, 0.0, TILEWIDTH, 0.0)); 38 | } 39 | else if (vert_ord == 2){ 40 | gl_Position = _ctx._mvp * (base_vert + vec4(TILEWIDTH, 0.0, 0.0, 0.0)); 41 | } 42 | else if (vert_ord == 3){ 43 | gl_Position = _ctx._mvp * (base_vert + vec4(0.0, 0.0, TILEWIDTH, 0.0)); 44 | } 45 | 46 | if (int(tile_pos.x + tile_pos.y) % 2 == 0){ 47 | color = vec3(0.5, 0.25, 0.0); 48 | } 49 | else{ 50 | color = vec3(0.317647, 0.156862, 0.0); 51 | } 52 | } -------------------------------------------------------------------------------- /bin/shaders/vs.glsl: -------------------------------------------------------------------------------- 1 | #version 330 2 | precision highp float; 3 | precision highp int; 4 | 5 | void main() 6 | { 7 | gl_Position=vec4(vec2(gl_VertexID&1,(gl_VertexID&2)>>1)*2-1,0,1) * 0.2; 8 | } 9 | -------------------------------------------------------------------------------- /bin/sign.bat: -------------------------------------------------------------------------------- 1 | signtool.exe sign /t http://timestamp.comodoca.com/authenticode /v dctest64.exe -------------------------------------------------------------------------------- /bin/tex/grass_blade_d.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hrabcak/draw_call_perf/602c578825ce18c0676611056d2361cc161ce635/bin/tex/grass_blade_d.tga -------------------------------------------------------------------------------- /get_comm.bat: -------------------------------------------------------------------------------- 1 | svn co https://coid.googlecode.com/svn/trunk/src/coid/comm ext/comm -------------------------------------------------------------------------------- /get_glm.bat: -------------------------------------------------------------------------------- 1 | git clone https://github.com/g-truc/glm ./ext/ogl-math 2 | cd ext/ogl-math 3 | git checkout 0.9.8.0 4 | -------------------------------------------------------------------------------- /get_glm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | git clone git://ogl-math.git.sourceforge.net/gitroot/ogl-math/ogl-math ./ext/ogl-math 3 | cd ./ext/ogl-math 4 | git checkout 0.9.2.6 5 | -------------------------------------------------------------------------------- /lib/debug/glew32.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hrabcak/draw_call_perf/602c578825ce18c0676611056d2361cc161ce635/lib/debug/glew32.lib -------------------------------------------------------------------------------- /lib/debug/glew64.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hrabcak/draw_call_perf/602c578825ce18c0676611056d2361cc161ce635/lib/debug/glew64.lib -------------------------------------------------------------------------------- /lib/release/glew32.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hrabcak/draw_call_perf/602c578825ce18c0676611056d2361cc161ce635/lib/release/glew32.lib -------------------------------------------------------------------------------- /lib/release/glew64.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hrabcak/draw_call_perf/602c578825ce18c0676611056d2361cc161ce635/lib/release/glew64.lib -------------------------------------------------------------------------------- /prj/vs2010/async_vbo_transfers_Scenario2.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | src\base 6 | 7 | 8 | src\base 9 | 10 | 11 | src\base 12 | 13 | 14 | src\base 15 | 16 | 17 | src\base 18 | 19 | 20 | src\base 21 | 22 | 23 | src\base 24 | 25 | 26 | src\base 27 | 28 | 29 | src 30 | 31 | 32 | src\base 33 | 34 | 35 | src\base 36 | 37 | 38 | src 39 | 40 | 41 | src\base 42 | 43 | 44 | src\base 45 | 46 | 47 | src 48 | 49 | 50 | src\base 51 | 52 | 53 | src 54 | 55 | 56 | src 57 | 58 | 59 | src 60 | 61 | 62 | src 63 | 64 | 65 | src 66 | 67 | 68 | src\base 69 | 70 | 71 | src 72 | 73 | 74 | 75 | 76 | src\base 77 | 78 | 79 | src\base 80 | 81 | 82 | src\base 83 | 84 | 85 | src\base 86 | 87 | 88 | src\base 89 | 90 | 91 | src\base 92 | 93 | 94 | src\base 95 | 96 | 97 | src 98 | 99 | 100 | src 101 | 102 | 103 | src\base 104 | 105 | 106 | src 107 | 108 | 109 | src\base 110 | 111 | 112 | src\base 113 | 114 | 115 | src\base 116 | 117 | 118 | src 119 | 120 | 121 | src 122 | 123 | 124 | src 125 | 126 | 127 | src 128 | 129 | 130 | src 131 | 132 | 133 | src 134 | 135 | 136 | 137 | 138 | {9d8036ab-81dc-47b9-b39e-b1cc792996ff} 139 | 140 | 141 | {3467cc65-ba88-43d7-9e7e-dd06c3e71377} 142 | 143 | 144 | {3501ad11-c39d-4354-a218-a6e71ed8960c} 145 | 146 | 147 | 148 | 149 | src\shaders 150 | 151 | 152 | src\shaders 153 | 154 | 155 | src\shaders 156 | 157 | 158 | src\shaders 159 | 160 | 161 | src\shaders 162 | 163 | 164 | src\shaders 165 | 166 | 167 | src\shaders 168 | 169 | 170 | src\shaders 171 | 172 | 173 | src\shaders 174 | 175 | 176 | src\shaders 177 | 178 | 179 | src\shaders 180 | 181 | 182 | src\shaders 183 | 184 | 185 | src\shaders 186 | 187 | 188 | src\shaders 189 | 190 | 191 | src\shaders 192 | 193 | 194 | src\shaders 195 | 196 | 197 | src\shaders 198 | 199 | 200 | src\shaders 201 | 202 | 203 | src\shaders 204 | 205 | 206 | src\shaders 207 | 208 | 209 | src 210 | 211 | 212 | src\shaders 213 | 214 | 215 | src\shaders 216 | 217 | 218 | src\shaders 219 | 220 | 221 | src\shaders 222 | 223 | 224 | src\shaders 225 | 226 | 227 | -------------------------------------------------------------------------------- /prj/vs2010/draw_call_perf.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "async_vbo_transfers_Scenario2", "async_vbo_transfers_Scenario2.vcxproj", "{04EE60D8-DC4E-4EBB-A257-4562123AE516}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Debug|x64 = Debug|x64 12 | Debug-clang|Win32 = Debug-clang|Win32 13 | Debug-clang|x64 = Debug-clang|x64 14 | Release|Win32 = Release|Win32 15 | Release|x64 = Release|x64 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {04EE60D8-DC4E-4EBB-A257-4562123AE516}.Debug|Win32.ActiveCfg = Debug|Win32 19 | {04EE60D8-DC4E-4EBB-A257-4562123AE516}.Debug|Win32.Build.0 = Debug|Win32 20 | {04EE60D8-DC4E-4EBB-A257-4562123AE516}.Debug|x64.ActiveCfg = Debug|x64 21 | {04EE60D8-DC4E-4EBB-A257-4562123AE516}.Debug|x64.Build.0 = Debug|x64 22 | {04EE60D8-DC4E-4EBB-A257-4562123AE516}.Debug-clang|Win32.ActiveCfg = Debug|Win32 23 | {04EE60D8-DC4E-4EBB-A257-4562123AE516}.Debug-clang|Win32.Build.0 = Debug|Win32 24 | {04EE60D8-DC4E-4EBB-A257-4562123AE516}.Debug-clang|x64.ActiveCfg = Debug|Win32 25 | {04EE60D8-DC4E-4EBB-A257-4562123AE516}.Release|Win32.ActiveCfg = Release|Win32 26 | {04EE60D8-DC4E-4EBB-A257-4562123AE516}.Release|Win32.Build.0 = Release|Win32 27 | {04EE60D8-DC4E-4EBB-A257-4562123AE516}.Release|x64.ActiveCfg = Release|x64 28 | {04EE60D8-DC4E-4EBB-A257-4562123AE516}.Release|x64.Build.0 = Release|x64 29 | EndGlobalSection 30 | GlobalSection(SolutionProperties) = preSolution 31 | HideSolutionNode = FALSE 32 | EndGlobalSection 33 | EndGlobal 34 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | If you want to compile async_vbo_transfers examples by yourself you will need GLM math library. 2 | 3 | For those users which have instaled GIT there are prepared scripts get_glm.sh/get_glm.bat that download GLM repository into ./etx/ogl-math folder. 4 | 5 | GLM git url: 6 | git://ogl-math.git.sourceforge.net/gitroot/ogl-math/ogl-math 7 | 8 | Otherwise you have to download GLM library by yourself from here 9 | http://glm.g-truc.net/ and unpack it to ./ext/ogl-math folder. 10 | 11 | All examples were prepared with GLM version 0.9.2.6. 12 | 13 | ### Test modes 14 | 15 | #### Test 0: Draw naive 16 | 17 | Call pair of glVertexAttribI4i and glDrawElements per draw call. glVertexAttrib is there to provide drawcall data. (instance_id, material_id, vertex offset etc.) 18 | 19 | for(int i = 0; i < nmeshes; ++i, ++dc) { 20 | glVertexAttribI3i( 21 | 13, 22 | ctx->_scene_data_offset + offset, // instance id 23 | dc->_first_vertex, // vertex offset (used if vertex data are pulled from texture buffer) 24 | i, // materia id / texture id 25 | 0); 26 | glDrawElements( 27 | GL_TRIANGLES, 28 | dc->_nelements, 29 | GL_UNSIGNED_SHORT, 30 | (void*)dc->_first_index); 31 | } 32 | 33 | 34 | #### Test 1: Draw with base instance 35 | 36 | Call one glDrawElementsInstancedBaseInstance (TB) or glDrawElementsInstancedBaseVertexBaseInstance (VBO) per draw call 37 | depends on the mode. Mesh data are provides from buffer as int4 38 | 39 | // init array with mesh data 40 | glBindBuffer(GL_ARRAY_BUFFER, _drawid_vbo); 41 | glVertexAttribIPointer(13, 4, GL_INT, 0, (GLvoid*)0); 42 | glVertexAttribDivisor(13, 1); 43 | glBindBuffer(GL_ARRAY_BUFFER, 0); 44 | 45 | // 46 | for(int i = 0; i < nmeshes; ++i, ++dc) { 47 | glDrawElementsInstancedBaseInstance( 48 | GL_TRIANGLES, 49 | dc->_nelements, 50 | GL_UNSIGNED_SHORT, 51 | (void*)dc->_first_index, 52 | 1, 53 | i); 54 | } 55 | 56 | #### Test 2: Multi draw indirect 57 | 58 | Whole scene is draw with one function call. Mesh data are provided from buffer as int4 per instance. 59 | 60 | glMultiDrawElementsIndirect( 61 | GL_TRIANGLES, 62 | GL_UNSIGNED_SHORT, 63 | (void*)ctx->_scene_data_offset, 64 | num_instances, 65 | 0); 66 | 67 | #### Test 3: Instancing 68 | 69 | In this test whole scene is draw with one function call. This test is not fair because it's using slightly different data. In texture buffer mode it's using unique data per isntance like other test but in VBO mode it's repeating the same instance for whole scene. Purpose of this test is to show fastest possible way but with limits. 70 | 71 | glDrawElementsInstanced( 72 | GL_TRIANGLES, 73 | _dc_data[0]._nelements, 74 | GL_UNSIGNED_SHORT, 75 | 0, 76 | nblocks); 77 | 78 | 79 | ### Texture modes 80 | 81 | #### Texture mode 0: None 82 | No textures 83 | 84 | #### Texture mode 1: Naive 85 | glBindMultiTextureEXT is call per draw call. 86 | 87 | #### Texture mode 2: Texture Array 88 | All textures are in multiple texture arrays. 89 | 90 | #### Texture mode 3: Bindless 91 | In this mode 64bit texture handles are stored in texture buffer and fetched in vertex shader by texture_id and pass to fragment shader. 92 | 93 | ## Command line switches: 94 | 95 | --debug-ctx Enable debug contex and GL_ARB_debug_output 96 | --debug-ctx-sync Same as --debug-ctx but enable GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB 97 | 98 | --test0 - glVertexAttribI3i + glDrawElements 99 | --test1 - glDrawElementsBaseInstance 100 | --test2 - glMultiDrawIndirect (default) 101 | --test3 - glMultiDrawElementsIndirect 102 | 103 | --tex-mode0 - No textures 104 | --tex-mode1 - Classis texture binding with glBindMultiTextureEXT 105 | --tex-mode2 - Texture arrays with max possible slices (default) 106 | --tex-mode3 - Bindless texturing handles are stored in texture buffer 107 | 108 | --tex-size32 - Texture 32x32 BGRA8 109 | --tex-size64 - Texture 64x64 BGRA8 (default) 110 | --tex-size128 - Texture 128x128 BGRA8 111 | 112 | --mesh-size0 - Meshes with 12 faces 113 | --mesh-size1 - Meshes with ~48 faces 114 | --mesh-size2 - Meshes with ~108 faces (default) 115 | --mesh-size3 - Meshes with ~192 faces 116 | --mesh-size4 - Meshes with ~300 faces 117 | 118 | --tex-freq0 - One texture for all meshes 119 | --tex-freq1 - One unique texture for each mesh (default) 120 | --tex-freq2 - One unique texture for two meshes 121 | --tex-freq3 - One unique texture for four meshes 122 | 123 | --one-mesh - Use one geometry for all meshes 124 | --use-vbo - Use classic buffer for vertex data instead of texture buffer 125 | --dont-rnd-cubes - Turn off cube randomization (better utilization of post-transform cache) 126 | --use_nor_uv - Will use additional vertex data normal and uv compressed to 8 bytes (16bytes vertex data) 127 | 128 | -------------------------------------------------------------------------------- /src/app_bw.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include "app_bw.h" 24 | 25 | #include "base/base.h" 26 | #include "base/frame_context.h" 27 | #include "base/canvas.h" 28 | 29 | #include 30 | 31 | GLuint buffer_src = 0; 32 | GLuint buffer_dst = 0; 33 | GLuint buffer_dst2 = 0; 34 | GLuint texture = 0; 35 | GLuint queries[5] = { 0, }; 36 | 37 | const base::pixelfmt pf = base::PF_RGBA8; 38 | const int texture_size = 4096; 39 | const base::pfd *pfdesc = base::get_pfd(pf); 40 | const int buffer_size = 41 | !pfdesc->_compressed ? 42 | texture_size * texture_size * pfdesc->_size 43 | : (texture_size >> 2) * pfdesc->_size * (texture_size >> 2); 44 | const int buffer_size_mb = buffer_size / 0x100000; 45 | 46 | const int target = GL_PIXEL_UNPACK_BUFFER; 47 | 48 | char *ptr_data = new char[buffer_size]; 49 | 50 | #define GL_EXTERNAL_VIRTUAL_MEMORY_AMD 37216 51 | 52 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 53 | 54 | app_bw::app_bw() 55 | : app() 56 | , _transfer(TransferCPUtoGPU) 57 | , _method(MethodMapBufferRange) 58 | , _use_copy(false) 59 | {} 60 | 61 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 62 | 63 | app_bw::~app_bw() {} 64 | 65 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 66 | 67 | void app_bw::start(const bool) 68 | { 69 | _frame_context.reset(new base::frame_context()); 70 | _frame_context->create_buffers(); 71 | 72 | // set projection matrix 73 | app::create_perspective_matrix(_frame_context.get()); 74 | 75 | base::canvas::load_and_init_shaders(SRC_LOCATION); 76 | 77 | // init test stuff 78 | memset(ptr_data, 0x44, buffer_size); 79 | 80 | glGenQueries(5, queries); 81 | 82 | glGenBuffers(1, &buffer_src); 83 | glBindBuffer(target, buffer_src); 84 | glBufferData(target, buffer_size, 0, GL_STREAM_DRAW); 85 | 86 | glGenBuffers(1, &buffer_dst); 87 | glBindBuffer(target, buffer_dst); 88 | glBufferData(target, buffer_size, 0, GL_STATIC_DRAW); 89 | 90 | glGenBuffers(1, &buffer_dst2); 91 | glBindBuffer(target, buffer_dst2); 92 | glBufferData(target, buffer_size, 0, GL_STATIC_DRAW); 93 | 94 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); 95 | texture = create_texture(texture_size, texture_size, pf, 0); 96 | 97 | glFinish(); 98 | } 99 | 100 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 101 | 102 | void app_bw::test_buffer_bandwidth(const bool log_to_screen) 103 | { 104 | _timer.start(); 105 | 106 | // CREATE DATA IN BUFFER_SRC 107 | 108 | glBindBuffer(GL_COPY_READ_BUFFER, buffer_src); 109 | 110 | glQueryCounter(queries[0], GL_TIMESTAMP); 111 | 112 | if(_method == MethodMapBufferRange) { 113 | char *ptr = (char*)glMapBufferRange( 114 | GL_COPY_READ_BUFFER, 115 | 0, 116 | buffer_size, 117 | GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT); 118 | memset(ptr, 0x44, buffer_size); 119 | glUnmapBuffer(GL_COPY_READ_BUFFER); 120 | } 121 | else if(_method == MethodMapBuffer) { 122 | char *ptr = (char*)glMapBuffer(GL_COPY_READ_BUFFER, GL_WRITE_ONLY); 123 | memset(ptr, 0x44, buffer_size); 124 | glUnmapBuffer(GL_COPY_READ_BUFFER); 125 | } 126 | else if(_method == MethodBufferData) { 127 | glBufferSubData(GL_COPY_READ_BUFFER, 0, buffer_size, ptr_data); 128 | } 129 | else 130 | throw base::exception() << "Unknown method!\n"; 131 | 132 | // IF GPU-GPU COPY DATA TO BUFFER_DST 133 | 134 | glQueryCounter(queries[1], GL_TIMESTAMP); 135 | 136 | if(_transfer == TransferGPUtoGPU) { 137 | glBindBuffer(GL_COPY_WRITE_BUFFER, buffer_dst); 138 | glCopyBufferSubData( 139 | GL_COPY_READ_BUFFER, 140 | GL_COPY_WRITE_BUFFER, 141 | 0, 142 | 0, 143 | buffer_size); 144 | 145 | glQueryCounter(queries[2], GL_TIMESTAMP); 146 | 147 | glBindBuffer(GL_COPY_READ_BUFFER, buffer_dst); 148 | glBindBuffer(GL_COPY_WRITE_BUFFER, buffer_dst2); 149 | glCopyBufferSubData( 150 | GL_COPY_READ_BUFFER, 151 | GL_COPY_WRITE_BUFFER, 152 | 0, 153 | 0, 154 | buffer_size); 155 | 156 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer_dst); 157 | } 158 | else if(_transfer == TransferCPUtoGPU) { 159 | glQueryCounter(queries[2], GL_TIMESTAMP); 160 | 161 | glBindBuffer(GL_COPY_WRITE_BUFFER, buffer_dst); 162 | glCopyBufferSubData( 163 | GL_COPY_READ_BUFFER, 164 | GL_COPY_WRITE_BUFFER, 165 | 0, 166 | 0, 167 | buffer_size); 168 | 169 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer_src); 170 | } 171 | else 172 | throw base::exception() << "Unknown transfer mode!\n"; 173 | 174 | glQueryCounter(queries[3], GL_TIMESTAMP); 175 | 176 | glBindTexture(GL_TEXTURE_2D, texture); 177 | if(!pfdesc->_compressed) { 178 | glTexSubImage2D( 179 | GL_TEXTURE_2D, 180 | 0, 181 | 0, 0, 182 | texture_size, 183 | texture_size, 184 | get_pfd(pf)->_format, 185 | get_pfd(pf)->_type, 186 | 0); 187 | } 188 | else { 189 | glCompressedTexSubImage2D( 190 | GL_TEXTURE_2D, 191 | 0, 192 | 0, 193 | 0, 194 | texture_size, 195 | texture_size, 196 | pfdesc->_internal, 197 | buffer_size, 198 | 0); 199 | } 200 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); 201 | glQueryCounter(queries[4], GL_TIMESTAMP); 202 | 203 | __int64 result[5]; 204 | 205 | const double cpu_time = _timer.elapsed_time(); 206 | 207 | glGetQueryObjecti64v(queries[4], GL_QUERY_RESULT, result + 4); 208 | glGetQueryObjecti64v(queries[3], GL_QUERY_RESULT, result + 3); 209 | glGetQueryObjecti64v(queries[2], GL_QUERY_RESULT, result + 2); 210 | glGetQueryObjecti64v(queries[1], GL_QUERY_RESULT, result + 1); 211 | glGetQueryObjecti64v(queries[0], GL_QUERY_RESULT, result); 212 | 213 | if(log_to_screen) { 214 | double time; 215 | 216 | if(_use_copy) 217 | time = double(result[3] - result[2]) * (1.0 / 1000000000.0); 218 | else 219 | time = double(result[1] - result[0]) * (1.0 / 1000000000.0); 220 | 221 | printf( 222 | "buffer transfer time for %dMB: %.3f ms, bandwidth: %.3f MB/s CPU time: %.3f\n", 223 | buffer_size_mb, 224 | 1000.0 * time, 225 | double(buffer_size) / double(0x100000) / time, 226 | cpu_time); 227 | 228 | time = double(result[4] - result[3]) * (1.0 / 1000000000.0); 229 | printf( 230 | "texture update time for %dMB %s: %.3f ms, bandwidth: %.3f MB/s\n", 231 | buffer_size_mb, 232 | base::get_pfd(pf)->_txt, 233 | 1000.0 * time, 234 | double(buffer_size) / double(0x100000) / time); 235 | } 236 | } 237 | 238 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 239 | 240 | void app_bw::draw_frame() 241 | { 242 | static int c = 0; 243 | 244 | test_buffer_bandwidth(true); 245 | 246 | if(c++ > 2) 247 | throw base::exception("The End...\n\n"); 248 | } 249 | 250 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 251 | -------------------------------------------------------------------------------- /src/app_bw.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __ASYNC_VBO_TRANSFERS_APP_BW_H__ 24 | #define __ASYNC_VBO_TRANSFERS_APP_BW_H__ 25 | 26 | #include "base/app.h" 27 | 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | enum Transfer { 35 | TransferGPUtoGPU, 36 | TransferCPUtoGPU, 37 | }; 38 | 39 | enum Method { 40 | MethodMapBufferRange, 41 | MethodMapBuffer, 42 | MethodBufferData, 43 | }; 44 | 45 | class app_bw 46 | : public base::app 47 | { 48 | protected: 49 | std::auto_ptr _frame_context; 50 | 51 | public: 52 | Transfer _transfer; 53 | Method _method; 54 | bool _use_copy; 55 | 56 | app_bw(); 57 | virtual ~app_bw(); 58 | 59 | virtual const char* get_app_name() const { return "scenario 1"; } 60 | 61 | virtual void start(const bool); 62 | virtual void draw_frame(); 63 | 64 | void test_buffer_bandwidth(const bool log_to_screen); 65 | 66 | private: 67 | app_bw(const app_bw&); 68 | void operator =(const app_bw&); 69 | }; 70 | 71 | #endif // __ASYNC_VBO_TRANSFERS_APP_BW_H__ 72 | -------------------------------------------------------------------------------- /src/app_scenario1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include "app_scenario1.h" 24 | 25 | #include "base/base.h" 26 | #include "base/frame_context.h" 27 | #include "base/canvas.h" 28 | #include "scene.h" 29 | 30 | #include 31 | 32 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 33 | 34 | app_scenario1::app_scenario1() : app() {} 35 | 36 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 37 | 38 | app_scenario1::~app_scenario1() {} 39 | 40 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 41 | 42 | void app_scenario1::start(const bool) 43 | { 44 | app::start(); 45 | 46 | create_frame_context_pool(false); 47 | 48 | // set projection matrix 49 | app::load_and_init_shaders(SRC_LOCATION); 50 | 51 | base::canvas::load_and_init_shaders(SRC_LOCATION); 52 | scene::load_and_init_shaders(SRC_LOCATION); 53 | 54 | _scene.reset(new scene()); 55 | scene::create_test_scene(_scene.get()); 56 | 57 | init_screen_capture(); 58 | } 59 | 60 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 61 | 62 | void app_scenario1::draw_frame() 63 | { 64 | base::frame_context *ctx = pop_frame_context_from_pool(); 65 | 66 | static bool first=true; 67 | 68 | if(!ctx->check_fence()) 69 | printf("fence incomplete!\n"); 70 | 71 | //printf("scene buffer handle: %.2u, ptr %p\n", ctx->_scene_vbo, ctx->_scene_data_ptr); 72 | 73 | app::begin_frame(ctx); 74 | 75 | app::create_perspective_matrix(ctx); 76 | app::update_camera(ctx); 77 | 78 | //app::prepare_showtime(ctx); 79 | process_captured_screen(); 80 | 81 | ctx->map_scene(); 82 | 83 | static char* cached_scene_data_ptr; 84 | static int cached_scene_data_ptr_size; 85 | 86 | //memset(ctx->_scene_data_ptr, 0, ctx->_scene_data_ptr_size); 87 | _scene->frustum_check(ctx); 88 | _scene->upload_blocks_to_gpu(SRC_LOCATION, ctx); 89 | 90 | /*static int counter = 100; 91 | if(counter-- < 0) 92 | memset(ctx->_scene_data_ptr, 0, ctx->_scene_data_ptr_size);*/ 93 | 94 | ctx->flush_scene_data(); 95 | 96 | /*_frame_context->map_scene(); 97 | _scene->frustum_check(_frame_context.get()); 98 | _scene->upload_blocks_to_gpu(SRC_LOCATION, _frame_context.get()); 99 | _frame_context->flush_scene_data();*/ 100 | 101 | scene::render_blocks(ctx); 102 | //app::render_showtime(ctx); 103 | 104 | ctx->map_canvas(); 105 | app::end_frame(ctx); 106 | ctx->flush_canvas_data(); 107 | 108 | capture_screen(); 109 | 110 | ctx->put_fence(); 111 | 112 | push_frame_context_to_pool(ctx); 113 | } 114 | 115 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 116 | -------------------------------------------------------------------------------- /src/app_scenario1.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __ASYNC_VBO_TRANSFERS_APP_SCENARIO1_H__ 24 | #define __ASYNC_VBO_TRANSFERS_APP_SCENARIO1_H__ 25 | 26 | #include "base/app.h" 27 | 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | class app_scenario1 34 | : public base::app 35 | { 36 | protected: 37 | //std::auto_ptr _frame_context; 38 | std::auto_ptr _scene; 39 | 40 | public: 41 | app_scenario1(); 42 | virtual ~app_scenario1(); 43 | 44 | virtual int get_wnd_width() const { return 1280; } 45 | virtual int get_wnd_height() const { return 720; } 46 | 47 | virtual const char* get_app_name() const { return "scenario 1"; } 48 | 49 | virtual void start(const bool); 50 | virtual void draw_frame(); 51 | 52 | private: 53 | app_scenario1(const app_scenario1&); 54 | void operator =(const app_scenario1&); 55 | }; 56 | 57 | #endif // __ASYNC_VBO_TRANSFERS_APP_SCENARIO1_H__ 58 | -------------------------------------------------------------------------------- /src/app_scenario3.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include "app_scenario3.h" 24 | 25 | #include "base/base.h" 26 | #include "base/frame_context.h" 27 | #include "scene.h" 28 | #include "renderer.h" 29 | 30 | #include 31 | 32 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 33 | 34 | app_scenario3::app_scenario3() : app() {} 35 | 36 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 37 | 38 | app_scenario3::~app_scenario3() {} 39 | 40 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 41 | 42 | base::pixelfmt fmt = base::PF_BGRA8; 43 | GLuint buf; 44 | int texsize = 1024; 45 | int bufsize = texsize * texsize * base::get_pfd(fmt)->_size; 46 | int counter = 0; 47 | GLuint tex; 48 | 49 | void app_scenario3::start(const bool) 50 | { 51 | _renderer.reset(new renderer(this, true)); 52 | _renderer->start(SRC_LOCATION); 53 | 54 | base::make_current_shared_context(); 55 | 56 | app::start(true); 57 | 58 | _scene.reset(new scene()); 59 | scene::create_test_scene(_scene.get()); 60 | 61 | //init_screen_capture(); 62 | 63 | { 64 | glGenBuffers(1, &buf); 65 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf); 66 | glBufferData(GL_PIXEL_UNPACK_BUFFER, bufsize, 0, GL_STREAM_DRAW); 67 | 68 | tex = base::create_texture(texsize,texsize,fmt,0); 69 | } 70 | } 71 | 72 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 73 | 74 | void app_scenario3::renderer_side_start() 75 | { 76 | app::renderer_side_start(); 77 | } 78 | 79 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 80 | 81 | void app_scenario3::stop() 82 | { 83 | _renderer->stop(SRC_LOCATION); 84 | app::stop(); 85 | } 86 | 87 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 88 | 89 | void app_scenario3::draw_frame() 90 | { 91 | base::frame_context *ctx = 0; 92 | 93 | // wait for renderer 94 | while((ctx = _renderer->pop_frame_context_from_pool()) == 0) base::sleep_ms(0); 95 | 96 | //process_captured_screen(); 97 | 98 | assert(ctx != 0); 99 | 100 | app::begin_frame(ctx, true); 101 | 102 | app::create_perspective_matrix(ctx); 103 | app::update_camera(ctx); 104 | 105 | ctx->map_scene(); 106 | 107 | static int first_time = base::frame_context::POOL_SIZE; 108 | static char* cached_scene_data_ptr; 109 | static int cached_scene_data_ptr_size; 110 | if(first_time) { 111 | _scene->frustum_check(ctx); 112 | _scene->upload_blocks_to_gpu(SRC_LOCATION, ctx); 113 | /*first_time--; 114 | cached_scene_data_ptr_size = ctx->_scene_data_ptr_size; 115 | cached_scene_data_ptr = new char[cached_scene_data_ptr_size]; 116 | memcpy(cached_scene_data_ptr, ctx->_scene_data_ptr, cached_scene_data_ptr_size);*/ 117 | } 118 | else { 119 | memcpy(ctx->_scene_data_ptr, cached_scene_data_ptr, cached_scene_data_ptr_size); 120 | } 121 | 122 | ctx->flush_scene_data(); 123 | 124 | ctx->map_canvas(); 125 | app::end_frame(ctx, true); 126 | ctx->flush_canvas_data(); 127 | 128 | _renderer->push_frame_context(ctx); 129 | 130 | if(counter++ > 3) { 131 | glPixelStorei(GL_UNPACK_ALIGNMENT, 4); 132 | 133 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf); 134 | //void * data = glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY); 135 | void * data = glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, bufsize, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT); 136 | memset(data, 0xab, bufsize); 137 | glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); 138 | 139 | glBindTexture(GL_TEXTURE_2D, tex); 140 | glTexSubImage2D( 141 | GL_TEXTURE_2D, 0, 0, 0, texsize, texsize, 142 | base::get_pfd(fmt)->_format, base::get_pfd(fmt)->_type, 0); 143 | 144 | counter = 0; 145 | } 146 | } 147 | 148 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 149 | -------------------------------------------------------------------------------- /src/app_scenario3.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __ASYNC_VBO_TRANSFERS_APP_SCENARIO2_H__ 24 | #define __ASYNC_VBO_TRANSFERS_APP_SCENARIO2_H__ 25 | 26 | #include "base/app.h" 27 | #include "base/thread.h" 28 | 29 | #include 30 | #include 31 | 32 | #include 33 | 34 | class renderer; 35 | 36 | class app_scenario3 37 | : public base::app 38 | { 39 | protected: 40 | std::auto_ptr _scene; 41 | 42 | std::auto_ptr _renderer; 43 | 44 | public: 45 | app_scenario3(); 46 | virtual ~app_scenario3(); 47 | 48 | virtual const char* get_app_name() const { return "scenario 3"; } 49 | 50 | virtual void start(const bool); 51 | virtual void renderer_side_start(); 52 | 53 | virtual void stop(); 54 | 55 | virtual void draw_frame(); 56 | 57 | private: 58 | app_scenario3(const app_scenario3&); 59 | void operator =(const app_scenario3&); 60 | }; 61 | 62 | #endif // __ASYNC_VBO_TRANSFERS_APP_SCENARIO2_H__ 63 | -------------------------------------------------------------------------------- /src/app_scenario4.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include "app_scenario4.h" 24 | 25 | #include "base/base.h" 26 | #include "base/frame_context.h" 27 | #include "base/canvas.h" 28 | #include "scene.h" 29 | #include "renderer.h" 30 | 31 | #include 32 | 33 | 34 | 35 | //std::auto_ptr _frame_context; 36 | 37 | copy_thread::copy_thread (app_scenario4 *a): 38 | _app(a), 39 | _shutdown(false) 40 | { 41 | } 42 | copy_thread::~copy_thread(){ 43 | 44 | } 45 | void copy_thread::start(const base::source_location &loc){ 46 | thread::start(loc); 47 | } 48 | void copy_thread::run(){ 49 | while(1){ 50 | //_app->_mutex.lock(); 51 | _app->_scene->frustum_check(_app->_thread_frame_context.get()); 52 | //_app->_mutex.unlock(); 53 | //_app->_event.wait(); 54 | _app->_event.signal(); 55 | _app->_event.wait(); 56 | } 57 | 58 | } 59 | void copy_thread::stop(const base::source_location &loc){ 60 | _shutdown = true; 61 | // todo : add sync here 62 | thread::stop(loc); 63 | } 64 | 65 | 66 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 67 | 68 | app_scenario4::app_scenario4() : app() {} 69 | 70 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 71 | 72 | app_scenario4::~app_scenario4() {} 73 | 74 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 75 | 76 | void app_scenario4::start(const bool) 77 | { 78 | _copy_thread.reset(new copy_thread(this)); 79 | 80 | app::start(); 81 | 82 | _frame_context.reset(new base::frame_context()); 83 | _frame_context->create_buffers(); 84 | _thread_frame_context.reset(new base::frame_context()); 85 | _thread_frame_context->_scene_tb = _frame_context->_scene_tb; 86 | 87 | // set projection matrix 88 | app::create_perspective_matrix(_frame_context.get()); 89 | 90 | base::canvas::load_and_init_shaders(SRC_LOCATION); 91 | scene::load_and_init_shaders(SRC_LOCATION); 92 | 93 | _scene.reset(new scene()); 94 | scene::create_test_scene(_scene.get()); 95 | 96 | glGenBuffers(1, &tmp_buffer); 97 | 98 | _copy_thread->start(SRC_LOCATION); 99 | 100 | } 101 | // 102 | ////-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 103 | // 104 | void app_scenario4::renderer_side_start() 105 | { 106 | app::renderer_side_start(); 107 | } 108 | 109 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 110 | 111 | void app_scenario4::stop() 112 | { 113 | _copy_thread->stop(SRC_LOCATION); 114 | app::stop(); 115 | } 116 | 117 | 118 | 119 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 120 | 121 | void app_scenario4::draw_frame() 122 | { 123 | 124 | 125 | 126 | app::begin_frame(_frame_context.get()); 127 | app::update_camera(_frame_context.get()); 128 | _thread_frame_context->_mvp = _frame_context->_mvp; 129 | //app::update_camera(_thread_frame_context.get()); 130 | 131 | //process_captured_screen(); 132 | 133 | _frame_context->map_canvas(); 134 | //_frame_context->map_scene(); 135 | 136 | //_scene->frustum_check(_frame_context.get()); 137 | 138 | 139 | glBindBuffer(GL_TEXTURE_BUFFER, tmp_buffer); 140 | glBufferData(GL_TEXTURE_BUFFER, scene::MAX_BLOCK_COUNT * sizeof(glm::mat4) * /*POOL_SIZE*/1, NULL, GL_STREAM_DRAW); 141 | // this may return a WriteCombined mapping! 142 | _event.wait(); 143 | _frame_context->_scene_data_ptr = (glm::mat4*)glMapBuffer(GL_TEXTURE_BUFFER, GL_WRITE_ONLY); 144 | // fill ptr 145 | //_mutex.lock(); 146 | for (int i=0; i<4; i++) 147 | _frame_context->_num_visible_blocks[i] = _thread_frame_context->_num_visible_blocks[i]; 148 | _event.signal(); 149 | 150 | _scene->upload_blocks_to_gpu(SRC_LOCATION, _frame_context.get()); 151 | glUnmapBuffer(GL_TEXTURE_BUFFER); 152 | //_mutex.unlock();_event.signal(); 153 | 154 | glBindBuffer(GL_COPY_WRITE_BUFFER, _frame_context->_scene_vbo); 155 | // this copy ideally requires no CPU work on the data itself. 156 | glCopyBufferSubData(GL_TEXTURE_BUFFER, GL_COPY_WRITE_BUFFER, 0, 0, scene::MAX_BLOCK_COUNT * sizeof(glm::mat4) * /*POOL_SIZE*/1); 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | //_frame_context->flush_scene_data(); 165 | _frame_context->flush_canvas_data(); 166 | 167 | scene::render_blocks(_frame_context.get()); 168 | 169 | app::end_frame(_frame_context.get()); 170 | 171 | //capture_screen(); 172 | 173 | } 174 | 175 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 176 | -------------------------------------------------------------------------------- /src/app_scenario4.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __ASYNC_VBO_TRANSFERS_app_scenario4_H__ 24 | #define __ASYNC_VBO_TRANSFERS_app_scenario4_H__ 25 | 26 | #include "base/app.h" 27 | #include "base/thread.h" 28 | #include "base/event.h" 29 | #include "base/mutex.h" 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | 36 | class app_scenario4; 37 | //class renderer; 38 | class copy_thread : public base::thread{ 39 | 40 | app_scenario4 *_app; 41 | public: 42 | //std::auto_ptr _frame_context; 43 | bool _shutdown ; 44 | 45 | copy_thread (app_scenario4 *a); 46 | virtual ~copy_thread(); 47 | 48 | virtual void start(const base::source_location &loc); 49 | 50 | virtual void run(); 51 | 52 | virtual void stop(const base::source_location &loc); 53 | 54 | void frustum_cull(base::frame_context *ctx); 55 | 56 | }; 57 | 58 | class app_scenario4 59 | : public base::app 60 | { 61 | public://todo 62 | std::auto_ptr _scene; 63 | std::auto_ptr _frame_context; 64 | std::auto_ptr _thread_frame_context; 65 | 66 | std::auto_ptr _copy_thread; 67 | 68 | GLuint tmp_buffer; 69 | base::thread_event _event; 70 | base::mutex _mutex; 71 | 72 | public: 73 | app_scenario4(); 74 | virtual ~app_scenario4(); 75 | 76 | virtual const char* get_app_name() const { return "scenario 4"; } 77 | 78 | virtual void start(const bool); 79 | virtual void renderer_side_start(); 80 | 81 | virtual void stop(); 82 | 83 | virtual void draw_frame(); 84 | 85 | private: 86 | app_scenario4(const app_scenario4&); 87 | void operator =(const app_scenario4&); 88 | }; 89 | 90 | #endif // __ASYNC_VBO_TRANSFERS_APP_SCENARIO4_H__ 91 | -------------------------------------------------------------------------------- /src/base/app.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include "app.h" 24 | 25 | #include "base.h" 26 | #include "font.h" 27 | #include "canvas.h" 28 | 29 | #include "frame_context.h" 30 | 31 | #include 32 | #include 33 | 34 | base::app* base::app::_app = 0; 35 | 36 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 37 | 38 | base::app::app() 39 | : _velocity_boost(false) 40 | , _position(0.0, 10.3, 0.0) 41 | , _frame_number(0) 42 | , _fovy(45.f) 43 | , _aspect(float(get_wnd_width()) / float(get_wnd_height())) 44 | , _benchmark_mode(cfg().test != -1) 45 | 46 | , _shutdown(false) 47 | , _shutdown_code(base::ecOK) 48 | { 49 | assert(_app == 0); 50 | _app = this; 51 | 52 | // init mouse stuff 53 | base::set_mouse_pos(glm::ivec2(200)); 54 | _last_mouse_pos = base::get_mouse_pos(); 55 | _mouse_pos = glm::ivec2(180, 0); 56 | 57 | if (base::cfg().sceneType == base::config::stGrass){ 58 | _position = glm::vec3(0.0, 1.8, 0.0); 59 | } 60 | else if (base::cfg().sceneType == base::config::stBuildings){ 61 | _mouse_pos = glm::vec2(45.4f, 0.4f); 62 | _position = glm::vec3(-987.37, 26.44, 981.66); 63 | } 64 | } 65 | 66 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 67 | 68 | base::app::~app() {} 69 | 70 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 71 | 72 | void base::app::start() 73 | { 74 | _canvas.reset(new base::canvas()); 75 | _canvas->set_pos(10, 400); 76 | _canvas->set_size(1280, 260); 77 | } 78 | 79 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 80 | 81 | void base::app::gpu_init() 82 | { 83 | canvas::load_and_init_shaders(SRC_LOCATION); 84 | 85 | _fnt_mono.reset(new base::font()); 86 | _fnt_mono->load(SRC_LOCATION,"fonts/lucida_console_13.fnt"); 87 | } 88 | 89 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 90 | 91 | void base::app::begin_frame() 92 | { 93 | if(_active && !_benchmark_mode) { 94 | _mouse_pos += glm::vec2(base::get_mouse_pos() - _last_mouse_pos) * 0.2f; 95 | base::set_mouse_pos(glm::ivec2(200)); 96 | } 97 | } 98 | 99 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 100 | 101 | void base::app::create_perspective_matrix(frame_context * const fc) 102 | { 103 | fc->_mprj = glm::perspective( 104 | _fovy, 105 | _aspect, 106 | 0.01f, 107 | 500.0f); 108 | } 109 | 110 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 111 | 112 | void base::app::update_camera(frame_context * const fc) 113 | { 114 | fc->_view = glm::rotate( 115 | glm::rotate( 116 | glm::mat4(1), 117 | glm::radians(-_mouse_pos.x), 118 | glm::vec3(0,1,0)), 119 | glm::radians (- _mouse_pos.y), glm::vec3(1, 0, 0)); 120 | 121 | _position += glm::mat3(fc->_view) * _velocity * (_velocity_boost ? 5.0f : 1.0f); 122 | 123 | fc->_view[3] = glm::vec4(_position, 1); 124 | fc->_mvp = fc->_mprj * glm::inverse(fc->_view); 125 | fc->_imvp = glm::inverse(fc->_mvp); 126 | 127 | fc->_fovy = _fovy; 128 | fc->_aspect = _aspect; 129 | } 130 | 131 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 132 | 133 | void base::app::stop() 134 | { 135 | _canvas.reset(0); 136 | _fnt_mono.reset(0); 137 | } 138 | 139 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 140 | 141 | void base::app::mouse_move(const int, const int) {} 142 | 143 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 144 | 145 | void base::app::key(const int key,const bool down) 146 | { 147 | const float speed = 0.05f; 148 | 149 | if(key == 0x57 || key == 0x26) _velocity.z += down ? -speed : speed; 150 | if(key == 0x53 || key == 0x28) _velocity.z += down ? speed : -speed; 151 | 152 | if(key == 0x41 || key == 0x25) _velocity.x += down ? -speed : speed; 153 | if(key == 0x44 || key == 0x27) _velocity.x += down ? speed : -speed; 154 | 155 | if(key == 0x52) _velocity.y += down ? speed : -speed; 156 | if(key == 0x46) _velocity.y += down ? -speed : speed; 157 | 158 | if(key == 0x10) _velocity_boost = down; 159 | } 160 | 161 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 162 | 163 | void base::app::activated(const bool state) 164 | { 165 | _active=state; 166 | if(state) 167 | base::set_mouse_pos(glm::ivec2(200)); 168 | } 169 | 170 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 171 | 172 | void base::app::create_frame_context_pool() 173 | { 174 | for(int i = 0; i < base::frame_context::POOL_SIZE; ++i) { 175 | base::frame_context *ctx = new base::frame_context(); 176 | ctx->create_buffers(); 177 | _pool.push_front(ctx); 178 | } 179 | } 180 | 181 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 182 | 183 | 184 | 185 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 186 | -------------------------------------------------------------------------------- /src/base/app.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __ASYNC_VBO_TRANSFERS_APP_H__ 24 | #define __ASYNC_VBO_TRANSFERS_APP_H__ 25 | 26 | #include "hptimer.h" 27 | #include "pixelfmt.h" 28 | 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | 37 | class scene; 38 | 39 | namespace base { 40 | 41 | class canvas; 42 | class font; 43 | struct frame_context; 44 | class source_location; 45 | enum exit_code_type; 46 | 47 | class app 48 | { 49 | public: 50 | app(); 51 | virtual ~app(); 52 | 53 | virtual void start(); 54 | virtual void gpu_init(); 55 | void begin_frame(); 56 | virtual void draw_frame() = 0; 57 | virtual void gpu_draw_frame(base::frame_context * const ctx) = 0; 58 | virtual void stop(); 59 | 60 | virtual void set_benchmark_mode(bool mode) = 0; 61 | 62 | // desired client area size / OpenGL frame buffer size 63 | virtual int get_wnd_width() const { return 1280; } 64 | virtual int get_wnd_height() const { return 720; } 65 | 66 | virtual const char* get_app_name() const = 0; 67 | virtual const char* get_wnd_name() const = 0; 68 | virtual const char* get_wnd_cls() const = 0; 69 | 70 | virtual const char * get_test_name() const = 0; 71 | 72 | static app* get() { assert(_app); return _app; } 73 | 74 | virtual void mouse_move(const int x, const int y); 75 | 76 | virtual void key(const int key,const bool down); 77 | 78 | virtual void activated(const bool state); 79 | 80 | void create_perspective_matrix(frame_context * const fc); 81 | void update_camera(frame_context * const fc); 82 | 83 | /// it is called in base::run_app_win... 84 | void inc_frame_number() { ++_frame_number; } 85 | 86 | base::frame_context* pop_frame_context_from_pool() { 87 | if(!_pool.empty()) { 88 | base::frame_context *ctx = _pool.back(); 89 | _pool.pop_back(); 90 | return ctx; 91 | } 92 | else 93 | return 0; 94 | } 95 | 96 | void push_frame_context_to_pool(frame_context *ctx) { 97 | _pool.push_front(ctx); 98 | } 99 | 100 | void create_frame_context_pool(); 101 | 102 | float get_fovy() const { return _fovy; } 103 | float get_aspect() const { return _aspect; } 104 | 105 | virtual void on_shutdown() = 0; 106 | void shutdown() { _shutdown = true; on_shutdown(); } 107 | void shutdown(base::exit_code_type exit_code) { _shutdown_code = exit_code; shutdown(); } 108 | 109 | bool is_shutdown() const { return _shutdown; } 110 | 111 | protected: 112 | static app *_app; 113 | 114 | bool _benchmark_mode; 115 | 116 | std::auto_ptr _fnt_mono; 117 | std::auto_ptr _canvas; 118 | 119 | glm::ivec2 _last_mouse_pos; 120 | glm::vec2 _mouse_pos; 121 | 122 | glm::vec3 _velocity; 123 | glm::vec3 _position; 124 | 125 | int _frame_number; 126 | 127 | bool _velocity_boost : 1; 128 | bool _active : 1; 129 | 130 | bool _shutdown; 131 | base::exit_code_type _shutdown_code; 132 | 133 | /// frame context pool 134 | std::list _pool; 135 | 136 | float _fovy; 137 | float _aspect; 138 | 139 | private: 140 | app(const app&); 141 | void operator =(const app&); 142 | }; 143 | 144 | } // end of namespace base 145 | 146 | #endif // __ASYNC_VBO_TRANSFERS_APP_H__ 147 | -------------------------------------------------------------------------------- /src/base/bmf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __ASYNC_VBO_TRANSFERS_BMF_H__ 24 | #define __ASYNC_VBO_TRANSFERS_BMF_H__ 25 | 26 | /* 27 | Font renderer is using Angel Code Bitmap Font Generator binary file format 28 | http://www.angelcode.com/products/bmfont/ 29 | */ 30 | 31 | namespace base { 32 | 33 | #pragma pack(push, 1) 34 | 35 | /// 36 | struct BMFInfo 37 | { 38 | char pID[3]; 39 | char ucVersion; 40 | }; 41 | 42 | /// 43 | struct InfoBlock 44 | { 45 | int blockSize; 46 | unsigned short fontSize; 47 | unsigned char reserved:4; 48 | unsigned char bold:1; 49 | unsigned char italic:1; 50 | unsigned char unicode:1; 51 | unsigned char smooth:1; 52 | unsigned char charSet; 53 | unsigned short stretchH; 54 | unsigned char aa; 55 | unsigned char paddingUp; 56 | unsigned char paddingRight; 57 | unsigned char paddingDown; 58 | unsigned char paddingLeft; 59 | unsigned char spacingHoriz; 60 | unsigned char spacingVert; 61 | unsigned char outline; // Added with version 2 62 | char fontName[1]; 63 | }; 64 | 65 | /// 66 | struct CommonBlock 67 | { 68 | int blockSize; 69 | unsigned short lineHeight; 70 | unsigned short base; 71 | unsigned short scaleW; 72 | unsigned short scaleH; 73 | unsigned short pages; 74 | unsigned char packed:1; 75 | unsigned char reserved:7; 76 | unsigned char alphaChnl; 77 | unsigned char redChnl; 78 | unsigned char greenChnl; 79 | unsigned char blueChnl; 80 | }; 81 | 82 | /// 83 | struct PagesBlock 84 | { 85 | int blockSize; 86 | char pageNames[1]; 87 | }; 88 | 89 | /// 90 | struct CharInfo 91 | { 92 | unsigned int id; 93 | unsigned short x; 94 | unsigned short y; 95 | unsigned short width; 96 | unsigned short height; 97 | short xoffset; 98 | short yoffset; 99 | short xadvance; 100 | unsigned char page; 101 | unsigned char chnl; 102 | }; 103 | 104 | /// 105 | struct CharsBlock 106 | { 107 | int blockSize; 108 | CharInfo chars[1]; 109 | }; 110 | 111 | /// 112 | struct kerningPair 113 | { 114 | unsigned int first; 115 | unsigned int second; 116 | short amount; 117 | }; 118 | 119 | /// 120 | struct KerningPairsBlock 121 | { 122 | int blockSize; 123 | kerningPair kerningPairs[1]; 124 | }; 125 | 126 | #pragma pack(pop) 127 | 128 | } // end of namspace base 129 | 130 | #endif // __ASYNC_VBO_TRANSFERS_BMF_H__ 131 | -------------------------------------------------------------------------------- /src/base/canvas.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include "canvas.h" 24 | #include "font.h" 25 | #include "bmf.h" 26 | #include "base.h" 27 | #include "app.h" 28 | #include "frame_context.h" 29 | 30 | #include 31 | 32 | GLuint base::canvas::_prg = 0; 33 | GLint base::canvas::_prg_tex_fnt = -1; 34 | GLint base::canvas::_prg_tb_elements = -1; 35 | GLint base::canvas::_prg_screen_size = -1; 36 | GLint base::canvas::_prg_clip = -1; 37 | GLint base::canvas::_prg_start_index = -1; 38 | 39 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 40 | 41 | base::canvas::canvas() 42 | : _pos(0) 43 | , _size(app::get()->get_wnd_width(),app::get()->get_wnd_height()) 44 | {} 45 | 46 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 47 | 48 | base::canvas::~canvas() {} 49 | 50 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 51 | 52 | void base::canvas::load_and_init_shaders(const base::source_location &loc) 53 | { 54 | assert(_prg == 0); 55 | 56 | std::string cfg; 57 | 58 | _prg=base::create_program( 59 | base::create_and_compile_shader( 60 | SRC_LOCATION, 61 | cfg, 62 | "shaders/canvas_v.glsl", 63 | GL_VERTEX_SHADER), 64 | 0, 65 | base::create_and_compile_shader( 66 | SRC_LOCATION, 67 | cfg, 68 | "shaders/canvas_f.glsl", 69 | GL_FRAGMENT_SHADER)); 70 | base::link_program(loc, _prg); 71 | 72 | _prg_tb_elements= get_uniform_location(loc, _prg, "tb_elements"); 73 | _prg_tex_fnt = get_uniform_location(loc, _prg, "tex_font"); 74 | _prg_screen_size = get_uniform_location(loc, _prg, "screen_size"); 75 | _prg_clip = get_uniform_location(loc, _prg, "clip"); 76 | _prg_start_index = get_uniform_location(loc, _prg, "start_index"); 77 | } 78 | 79 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 80 | 81 | void base::canvas::draw_text( 82 | base::frame_context * const ctx, 83 | const glm::vec2 &position, 84 | const char * const text, 85 | const glm::vec4 &color, 86 | const font *fnt) 87 | { 88 | assert( 89 | fnt->_infoBlock != 0 90 | && text != nullptr 91 | && fnt!=0); 92 | assert(ctx->_elements != 0 && ctx->_elements_begin != 0); 93 | 94 | glm::vec4* const batch_elements = ctx->_elements; 95 | 96 | // get font height and init screen position 97 | const float line_height = fnt->_commonBlock->lineHeight; 98 | glm::vec2 pos = position + _pos; 99 | 100 | const font::char_map_t &chars=fnt->_chars; 101 | 102 | const char *e = text + strlen(text); 103 | for(const char *i = text; i != e; ++i) { 104 | const unsigned int char_id = *i; 105 | 106 | // new line 107 | if(*i == 0x0a) { 108 | pos=glm::vec2(position.x + _pos.x, pos.y + line_height); 109 | continue; 110 | } 111 | 112 | // find 113 | font::char_map_t::const_iterator it = chars.find(char_id); 114 | if(it == chars.end()) 115 | it = chars.find(0x20); 116 | 117 | assert(it != chars.end()); 118 | 119 | const CharInfo *char_info=it->second; 120 | 121 | // space 122 | if(*i == 0x20) { 123 | pos.x += char_info->xadvance; 124 | continue; 125 | } 126 | 127 | assert(ctx->_elements - ctx->_elements_begin < MAX_ELEMENTS_COUNT * 3); 128 | 129 | // add element to VBO 130 | 131 | // position and size in screen space 132 | glm::vec4 elem_pos = glm::vec4( 133 | pos+glm::vec2( 134 | char_info->xoffset, 135 | line_height - char_info->yoffset - char_info->height), 136 | glm::vec2(char_info->width, char_info->height)); 137 | 138 | // check if the element is in canvas space 139 | if( elem_pos.x <= _pos.x + _size.x 140 | && elem_pos.x + elem_pos.z >= _pos.x 141 | && elem_pos.y + elem_pos.w <= _pos.y + _size.y 142 | && elem_pos.y >= _pos.y ) { 143 | 144 | *ctx->_elements++ = elem_pos; 145 | 146 | // position and size in font texture space 147 | *ctx->_elements++ = glm::vec4( 148 | glm::vec2(char_info->x, char_info->y + char_info->height), 149 | glm::vec2(char_info->width, -char_info->height)); 150 | 151 | // color 152 | *ctx->_elements++ = color; 153 | } 154 | 155 | // adjust position on screen 156 | pos.x += char_info->xadvance; 157 | } 158 | 159 | // create or update batch 160 | base::batches_t::iterator last = ctx->_batches.empty() 161 | ? ctx->_batches.end() 162 | : ctx->_batches.end() - 1; 163 | if (ctx->_batches.empty() || (last->tex != fnt->_tex && last->tex != 0)) { 164 | ctx->_batches.push_back( 165 | base::batch( 166 | _pos, 167 | _size, 168 | int(batch_elements - ctx->_elements_begin), // start index 169 | int(ctx->_elements - batch_elements) / 3, // number of elements in batch 170 | fnt->_tex)); 171 | } 172 | else { 173 | last->count += int(ctx->_elements - batch_elements) / 3; 174 | last->tex = fnt->_tex; 175 | } 176 | } 177 | 178 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 179 | 180 | void base::canvas::fill_rect( 181 | base::frame_context *ctx, 182 | const glm::vec2 &pos, 183 | const glm::vec2 &size, 184 | const glm::vec4 &color) 185 | { 186 | assert(ctx->_elements != 0 && ctx->_elements_begin != 0); 187 | 188 | const glm::vec4 * const ebegin = ctx->_elements; 189 | 190 | *ctx->_elements++ = glm::vec4(_pos + pos,size); 191 | *ctx->_elements++ = glm::vec4(0); 192 | *ctx->_elements++ = color; 193 | 194 | // create or update batch 195 | if(ctx->_batches.empty()) 196 | ctx->_batches.push_back(base::batch( 197 | _pos, _size, int(ebegin - ctx->_elements_begin), 1, 0)); 198 | else 199 | ++(ctx->_batches.end() - 1)->count; 200 | } 201 | 202 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 203 | 204 | void base::canvas::render(base::frame_context * const ctx) 205 | { 206 | if(!ctx->_batches.empty()) { 207 | glUseProgram(_prg); 208 | 209 | // bind canvas elements texture buffer 210 | glUniform1i(_prg_tb_elements, 4); 211 | glBindMultiTextureEXT(GL_TEXTURE4, GL_TEXTURE_BUFFER, ctx->_canvas_tb); 212 | 213 | const glm::vec2 screen_size( 214 | app::get()->get_wnd_width(), 215 | app::get()->get_wnd_height()); 216 | 217 | // set screen size 218 | glUniform2fv(_prg_screen_size, 1, glm::value_ptr(1.0f / screen_size)); 219 | glUniform1i(_prg_tex_fnt, 5); 220 | 221 | glDisable(GL_DEPTH_TEST); 222 | 223 | // draw canvas batches 224 | base::batches_t::const_iterator e = ctx->_batches.end(); 225 | for(base::batches_t::const_iterator i = ctx->_batches.begin(); i != e; ++i) { 226 | // set canvas clip region 227 | glUniform4fv(_prg_clip, 1, glm::value_ptr(glm::vec4(i->pos, i->pos + i->size))); 228 | glUniform1i(_prg_start_index, i->index); 229 | 230 | glBindMultiTextureEXT(GL_TEXTURE5, GL_TEXTURE_2D, i->tex); 231 | glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, i->count); 232 | } 233 | 234 | ctx->_batches.clear(); 235 | ctx->_elements = ctx->_elements_begin; 236 | } 237 | } 238 | 239 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 240 | -------------------------------------------------------------------------------- /src/base/canvas.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __ASYNC_VBO_TRANSFERS_CANVAS_H__ 24 | #define __ASYNC_VBO_TRANSFERS_CANVAS_H__ 25 | 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | namespace glm { 34 | typedef lowp_ivec2 svec2; //< short vec2 35 | } 36 | 37 | namespace base { 38 | 39 | class source_location; 40 | class font; 41 | struct frame_context; 42 | 43 | class canvas 44 | { 45 | public: 46 | static const unsigned int MAX_ELEMENTS_COUNT=8192; 47 | static const unsigned int ELEMENTS_VBO_SIZE=MAX_ELEMENTS_COUNT*4*sizeof(glm::vec4); 48 | static const unsigned int ELEMENTS_VBO_SIZE2=MAX_ELEMENTS_COUNT*4; 49 | 50 | canvas(); 51 | 52 | ~canvas(); 53 | 54 | void draw_text( 55 | base::frame_context * const ctx, 56 | const glm::vec2 &position, 57 | const char * const text, 58 | const glm::vec4 &color, 59 | const font *fnt); 60 | 61 | void fill_rect( 62 | base::frame_context * const ctx, 63 | const glm::vec2 &pos, 64 | const glm::vec2 &size, 65 | const glm::vec4 &color); 66 | 67 | 68 | static void render(base::frame_context * const ctx); 69 | 70 | void set_pos(const float x,const float y) { _pos=glm::vec2(x,y); } 71 | void set_size(const float w,const float h) { _size=glm::vec2(w,h); } 72 | 73 | static void load_and_init_shaders(const base::source_location &loc); 74 | 75 | protected: 76 | static GLuint _prg; 77 | static GLint _prg_tex_fnt; 78 | static GLint _prg_tb_elements; 79 | static GLint _prg_screen_size; 80 | static GLint _prg_clip; 81 | static GLint _prg_start_index; 82 | 83 | /// canvas position and size on screen 84 | glm::vec2 _pos; 85 | glm::vec2 _size; 86 | 87 | private: 88 | canvas(const canvas&); 89 | void operator=(const canvas&); 90 | }; 91 | 92 | } // end of namespace base 93 | 94 | #endif // __ASYNC_VBO_TRANSFERS_CANVAS_H__ 95 | -------------------------------------------------------------------------------- /src/base/event.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include "event.h" 24 | 25 | #include 26 | 27 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 28 | 29 | base::thread_event::thread_event() 30 | : _handle(CreateEvent(0, FALSE, FALSE, 0)) 31 | {} 32 | 33 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 34 | 35 | base::thread_event::~thread_event() 36 | { 37 | if(_handle != INVALID_HANDLE_VALUE) 38 | CloseHandle((HANDLE)_handle); 39 | } 40 | 41 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 42 | 43 | bool base::thread_event::wait(const unsigned int time) 44 | { 45 | return WAIT_OBJECT_0 == WaitForSingleObject((HANDLE)_handle, time); 46 | } 47 | 48 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 49 | 50 | bool base::thread_event::try_wait() 51 | { 52 | return WAIT_OBJECT_0 == WaitForSingleObject((HANDLE)_handle, 0); 53 | } 54 | 55 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 56 | 57 | void base::thread_event::signal() 58 | { 59 | SetEvent( (HANDLE)_handle ); 60 | } 61 | 62 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 63 | -------------------------------------------------------------------------------- /src/base/event.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __ASYNC_VBO_TRANSFERS_BASE_THREAD_EVENT_H__ 24 | #define __ASYNC_VBO_TRANSFERS_BASE_THREAD_EVENT_H__ 25 | 26 | #include "base.h" 27 | 28 | namespace base { 29 | 30 | struct thread_event 31 | { 32 | protected: 33 | void* _handle; 34 | 35 | public: 36 | explicit thread_event(); 37 | ~thread_event(); 38 | 39 | bool wait(const unsigned int time = -1); 40 | bool try_wait(); 41 | void signal(); 42 | }; 43 | 44 | } // end of namespace base 45 | 46 | #endif // __ASYNC_VBO_TRANSFERS_BASE_THREAD_EVENT_H__ 47 | -------------------------------------------------------------------------------- /src/base/font.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include "font.h" 24 | #include "base.h" 25 | #include "bmf.h" 26 | 27 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 28 | 29 | base::font::font() {} 30 | 31 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 32 | 33 | base::font::~font() {} 34 | 35 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 36 | 37 | void base::font::load(const base::source_location &loc, const char *filename) 38 | { 39 | base::read_file(loc,filename,_data); 40 | 41 | const unsigned char* buf=&_data[0]; 42 | _BMFInfo=reinterpret_cast(buf); 43 | 44 | if(_BMFInfo->pID[0] != 'B' 45 | || _BMFInfo->pID[1] != 'M' 46 | || _BMFInfo->pID[2] != 'F' 47 | || _BMFInfo->ucVersion != 3) 48 | throw base::exception(loc.to_str()) 49 | << "This is not a BMF file or it's a wrong version \"" << filename << "\"!"; 50 | 51 | const unsigned char* block_id=buf+sizeof(BMFInfo); 52 | const unsigned char* const end=buf+_data.size(); 53 | 54 | while(block_id(block_id); 59 | block_id += _infoBlock->blockSize; 60 | break; 61 | case 2: 62 | ++block_id; 63 | _commonBlock = reinterpret_cast(block_id); 64 | block_id += _commonBlock->blockSize; 65 | break; 66 | case 3: 67 | ++block_id; 68 | _pagesBlock = reinterpret_cast(block_id); 69 | block_id += _pagesBlock->blockSize; 70 | break; 71 | case 4: 72 | ++block_id; 73 | _charsBlock = reinterpret_cast(block_id); 74 | block_id += _charsBlock->blockSize; 75 | break; 76 | case 5: 77 | ++block_id; 78 | _kerningPairsBlock = reinterpret_cast(block_id); 79 | block_id += _kerningPairsBlock->blockSize; 80 | break; 81 | default: 82 | throw base::exception(loc.to_str()) 83 | << "Unknown BMF block inf font \"" << filename << "\"!"; 84 | } 85 | 86 | if (_BMFInfo->ucVersion == 3) 87 | block_id += 4; 88 | } 89 | 90 | const CharInfo *e = _charsBlock->chars + (_charsBlock->blockSize - 4) / sizeof(CharInfo); 91 | 92 | for(const CharInfo *i = _charsBlock->chars; i !=e; ++i) 93 | _chars.insert(std::pair(i->id, i)); 94 | 95 | // load font texture page, we are supporting only one txture page! 96 | std::string texture_page( 97 | _pagesBlock->pageNames, 98 | _pagesBlock->pageNames + _pagesBlock->blockSize); 99 | 100 | texture_page="fonts/"+texture_page; 101 | 102 | _tex=base::create_texture_from_file(loc, texture_page.c_str(), true); 103 | } 104 | 105 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 106 | -------------------------------------------------------------------------------- /src/base/font.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __ASYNC_VBO_TRANSFERS_FONT_H__ 24 | #define __ASYNC_VBO_TRANSFERS_FONT_H__ 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | namespace base { 33 | 34 | class source_location; 35 | class canvas; 36 | 37 | struct BMFInfo; 38 | struct InfoBlock; 39 | struct CommonBlock; 40 | struct PagesBlock; 41 | struct CharInfo; 42 | struct CharsBlock; 43 | struct KerningPairsBlock; 44 | 45 | class font 46 | { 47 | friend canvas; 48 | 49 | public: 50 | font(); 51 | ~font(); 52 | 53 | void load( 54 | const source_location &loc, 55 | const char *filename); 56 | 57 | protected: 58 | std::vector _data; 59 | const BMFInfo* _BMFInfo; 60 | const InfoBlock* _infoBlock; 61 | const CommonBlock* _commonBlock; 62 | const PagesBlock* _pagesBlock; 63 | const CharsBlock* _charsBlock; 64 | const KerningPairsBlock* _kerningPairsBlock; 65 | 66 | typedef std::map char_map_t; 67 | char_map_t _chars; 68 | GLuint _tex; 69 | 70 | private: 71 | font(const font&); 72 | void operator=(const font&); 73 | }; 74 | 75 | } // end of namspace base 76 | 77 | #endif // __ASYNC_VBO_TRANSFERS_FONT_H__ 78 | -------------------------------------------------------------------------------- /src/base/frame_context.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include "frame_context.h" 24 | #include "base/base.h" 25 | #include "base/pixelfmt.h" 26 | 27 | #include "canvas.h" 28 | #include "../scene.h" 29 | 30 | #include 31 | 32 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 33 | 34 | const int base::frame_context::POOL_SIZE = 4; 35 | 36 | bool __buffers_created = false; 37 | GLuint __scene_buffer = 0; 38 | GLuint __canvas_buffer = 0; 39 | GLuint __scene_tb = 0; 40 | GLuint __elem_buffer = 0; 41 | GLuint __vert_buffer = 0; 42 | GLuint __ctx_buffer = 0; 43 | GLuint __drawid_buffer = 0; 44 | GLuint __drawid_tb = 0; 45 | GLuint __cmd_buffer = 0; 46 | base::cmd * __cmd_data_ptr = 0; 47 | base::dc_gpu_data * __drawid_data_ptr = 0; 48 | base::block_data * __scene_data_ptr = 0; 49 | base::ctx_data * __ctx_data_ptr = 0; 50 | 51 | unsigned ctx_counter = 0; 52 | 53 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 54 | 55 | base::frame_context::frame_context() 56 | : _scene_data_ptr(0) 57 | , _scene_data_ptr_size(0) 58 | , _elements(0) 59 | , _elements_begin(0) 60 | , _fence(0) 61 | 62 | , _time(0) 63 | {} 64 | 65 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 66 | 67 | void base::frame_context::create_buffers() 68 | { 69 | first = true; 70 | 71 | _ctx_id = ctx_counter++; 72 | 73 | if (!__buffers_created) { 74 | glGenBuffers(1, &__drawid_buffer); 75 | _drawid_vbo = __drawid_buffer; 76 | glGenBuffers(1, &__cmd_buffer); 77 | _cmd_vbo = __cmd_buffer; 78 | 79 | _ctx_vbo = __ctx_buffer = create_buffer(1 * POOL_SIZE, &__ctx_data_ptr); 80 | _ctx_data_ptr = __ctx_data_ptr; 81 | 82 | _scene_vbo = __scene_buffer = create_buffer( 83 | scene::MAX_BLOCK_COUNT * POOL_SIZE, 84 | &__scene_data_ptr); 85 | _scene_data_ptr = __scene_data_ptr; 86 | _scene_data_offset = 0; 87 | 88 | _drawid_vbo = __drawid_buffer = create_buffer( 89 | scene::MAX_BLOCK_COUNT * POOL_SIZE, 90 | &__drawid_data_ptr); 91 | _drawid_data_ptr = __drawid_data_ptr; 92 | _drawid_data_offset = 0; 93 | 94 | // bind drawid buffer to 13 95 | glBindBuffer(GL_ARRAY_BUFFER, _drawid_vbo); 96 | glVertexAttribIPointer(13, 4, GL_INT, 0, (GLvoid*)0); 97 | glVertexAttribDivisor(13, 1); 98 | glBindBuffer(GL_ARRAY_BUFFER, 0); 99 | 100 | //create texture buffer for DC data (BaseVertex hack) 101 | glGenTextures(1, &__drawid_tb); 102 | glBindTexture(GL_TEXTURE_BUFFER, __drawid_tb); 103 | glTexBuffer( 104 | GL_TEXTURE_BUFFER, 105 | base::get_pfd(base::PF_RGBA32I)->_internal, 106 | _drawid_vbo); 107 | glBindTexture(GL_TEXTURE_BUFFER, 0); 108 | _drawid_tb = __drawid_tb; 109 | 110 | // create COMMAND buffer for multi draw indirect 111 | { 112 | const int size = scene::MAX_BLOCK_COUNT * sizeof(base::cmd) * 4; 113 | unsigned flags = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT; 114 | 115 | glBindBuffer(GL_ARRAY_BUFFER, __cmd_buffer); 116 | glBufferStorage(GL_ARRAY_BUFFER, size, 0, flags); 117 | _cmd_data_ptr = __cmd_data_ptr = 118 | reinterpret_cast(glMapBufferRange(GL_ARRAY_BUFFER, 0, size, flags)); 119 | glBindBuffer(GL_ARRAY_BUFFER, 0); 120 | } 121 | 122 | // scene buffer 123 | glGenTextures(1, &__scene_tb); 124 | _scene_tb = __scene_tb; 125 | glBindTexture(GL_TEXTURE_BUFFER, _scene_tb); 126 | glTexBuffer( 127 | GL_TEXTURE_BUFFER, 128 | base::get_pfd(base::PF_RGBA32F)->_internal, 129 | _scene_vbo); 130 | glBindTexture(GL_TEXTURE_BUFFER, 0); 131 | 132 | __buffers_created = true; 133 | } 134 | else { 135 | _scene_vbo = __scene_buffer; 136 | _scene_tb = __scene_tb; 137 | _drawid_vbo = __drawid_buffer; 138 | _drawid_tb = __drawid_tb; 139 | _cmd_vbo = __cmd_buffer; 140 | 141 | _scene_data_offset = scene::MAX_BLOCK_COUNT * _ctx_id; 142 | _scene_data_ptr = __scene_data_ptr + _scene_data_offset; 143 | 144 | _cmd_data_ptr = __cmd_data_ptr + scene::MAX_BLOCK_COUNT * _ctx_id; 145 | 146 | _ctx_vbo = __ctx_buffer; 147 | _ctx_data_ptr = __ctx_data_ptr + _ctx_id; 148 | 149 | _drawid_data_ptr = __drawid_data_ptr; 150 | _drawid_data_offset = scene::MAX_BLOCK_COUNT * _ctx_id; 151 | } 152 | 153 | // create canvas buffer 154 | glGenBuffers(1, &_canvas_vbo); 155 | _canvas_vbo = base::create_buffer( 156 | base::canvas::ELEMENTS_VBO_SIZE, 157 | &_elements, 158 | 0); 159 | _elements_begin = _elements; 160 | 161 | // canvas buffer TB 162 | glGenTextures(1, &_canvas_tb); 163 | glBindTexture(GL_TEXTURE_BUFFER, _canvas_tb); 164 | glTexBuffer( 165 | GL_TEXTURE_BUFFER, 166 | base::get_pfd(base::PF_RGBA32F)->_internal, 167 | _canvas_vbo); 168 | glBindTexture(GL_TEXTURE_BUFFER, 0); 169 | 170 | glGenQueries(sizeof(_time_queries) / sizeof(*_time_queries), _time_queries); 171 | } 172 | 173 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 174 | 175 | void base::frame_context::put_fence() 176 | { 177 | if(_fence) glDeleteSync(_fence); 178 | 179 | _fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); 180 | } 181 | 182 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 183 | 184 | bool base::frame_context::check_fence() 185 | { 186 | if(_fence==0) return true; 187 | 188 | GLenum res = glClientWaitSync(_fence, 0, 500000); 189 | 190 | // AMD returns GL_CONDITION_SATISFIED only BUG? 191 | return res == GL_ALREADY_SIGNALED || res == GL_CONDITION_SATISFIED; 192 | } 193 | 194 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 195 | -------------------------------------------------------------------------------- /src/base/frame_context.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __ASYNC_VBO_TRANSFERS_FRAME_CONTEXT_H__ 24 | #define __ASYNC_VBO_TRANSFERS_FRAME_CONTEXT_H__ 25 | 26 | #include "types.h" 27 | #include "base.h" 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | namespace base { 34 | 35 | struct cmd 36 | { 37 | unsigned _count; 38 | unsigned _instanceCount; 39 | unsigned _firstIndex; 40 | unsigned _baseVertex; 41 | unsigned _baseInstance; 42 | 43 | cmd( 44 | const unsigned count, 45 | const unsigned instanceCount, 46 | const unsigned firstIndex, 47 | const unsigned baseVertex, 48 | const unsigned baseInstance) 49 | : _count(count) 50 | , _instanceCount(instanceCount) 51 | , _firstIndex(firstIndex) 52 | , _baseVertex(baseVertex) 53 | , _baseInstance(baseInstance) 54 | {} 55 | }; 56 | 57 | struct ctx_data 58 | { 59 | glm::mat4 _mvp; 60 | int _mesh_size; 61 | int _tex_freq; 62 | char _res[256 - 64 - 4 - 4]; 63 | }; 64 | 65 | struct block_data 66 | { 67 | glm::mat4 _tm; 68 | }; 69 | 70 | /// batch represents group of canvas elements using same texture/font 71 | struct batch { 72 | glm::vec2 pos; 73 | glm::vec2 size; 74 | int index; 75 | int count; 76 | unsigned tex; 77 | 78 | batch( 79 | const glm::vec2 &pos, 80 | const glm::vec2 &size, 81 | const int index, 82 | const int count, 83 | const int tex) 84 | : pos(pos) 85 | , size(size) 86 | , index(index) 87 | , count(count) 88 | , tex(tex) 89 | {} 90 | }; 91 | 92 | typedef std::vector batches_t; 93 | 94 | // draw call gpu data 95 | struct dc_gpu_data 96 | { 97 | const glm::uint _inst_data_index; 98 | const glm::uint _first_vertex; 99 | const glm::uint _inst_id; 100 | const glm::uint _res; 101 | 102 | dc_gpu_data( 103 | const glm::uint inst_data_index, 104 | const glm::uint first_vertex, 105 | const glm::uint inst_id) 106 | : _inst_data_index(inst_data_index) 107 | , _first_vertex(first_vertex) 108 | , _inst_id(inst_id) 109 | , _res(0) 110 | {} 111 | }; 112 | 113 | struct frame_context 114 | { 115 | static const int POOL_SIZE; 116 | 117 | frame_context(); 118 | 119 | glm::mat4 _mprj; 120 | glm::mat4 _view; 121 | glm::mat4 _mvp; 122 | glm::mat4 _imvp; 123 | 124 | unsigned _canvas_vbo; 125 | unsigned _canvas_tb; 126 | 127 | unsigned _ctx_vbo; 128 | unsigned _scene_vbo; 129 | unsigned _scene_tb; 130 | unsigned _ctx_id; 131 | unsigned _drawid_vbo; 132 | unsigned _drawid_tb; 133 | unsigned _cmd_vbo; 134 | 135 | base::cmd* _cmd_data_ptr; 136 | 137 | base::ctx_data* _ctx_data_ptr; 138 | dc_gpu_data * _drawid_data_ptr; 139 | unsigned _drawid_data_offset; 140 | 141 | base::block_data* _scene_data_ptr; 142 | unsigned _scene_data_ptr_size; 143 | unsigned _scene_data_offset; 144 | 145 | int _num_visible_blocks[4]; 146 | 147 | batches_t _batches; 148 | 149 | glm::vec4* _elements; 150 | glm::vec4* _elements_begin; 151 | 152 | glm::mat4 _showtime_mvp; 153 | unsigned _showtime_tex; 154 | 155 | GLuint _time_queries[2]; 156 | double _cpu_render_time; 157 | 158 | GLsync _fence; 159 | 160 | void create_buffers(); 161 | 162 | void put_fence(); 163 | bool check_fence(); 164 | 165 | bool first; 166 | 167 | float _fovy; 168 | float _aspect; 169 | 170 | base::stats_data _stats; 171 | __int64 _time; 172 | }; 173 | 174 | } // end of namespace base 175 | 176 | #endif // __ASYNC_VBO_TRANSFERS_FRAME_CONTEXT_H__ 177 | -------------------------------------------------------------------------------- /src/base/hptimer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __ENG3_HPTIMER_H__ 24 | #define __ENG3_HPTIMER_H__ 25 | 26 | namespace base { 27 | 28 | class hptimer 29 | { 30 | private: 31 | __int64 _freq; 32 | double _freqd; 33 | __int64 _start; 34 | 35 | public: 36 | 37 | hptimer(); 38 | 39 | void start(); 40 | 41 | double elapsed_time(); 42 | 43 | double restart(); 44 | 45 | __int64 time(); 46 | 47 | // per second ! 48 | __int64 freq() const { return _freq; } 49 | 50 | // per milisecond ! 51 | double freqd() const { return _freqd; } 52 | }; 53 | 54 | } // end of namespace base 55 | 56 | #endif //__ENG3_HPTIMER_H__ 57 | -------------------------------------------------------------------------------- /src/base/hptimer_win.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include "hptimer.h" 24 | 25 | #include 26 | 27 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 28 | 29 | base::hptimer::hptimer() 30 | : _freq(0) 31 | , _freqd(0.0) 32 | , _start() 33 | { 34 | LARGE_INTEGER freq; 35 | QueryPerformanceFrequency(&freq); 36 | 37 | _freq = freq.QuadPart; 38 | _freqd = 1000.0 / double(freq.QuadPart); 39 | } 40 | 41 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 42 | 43 | void base::hptimer::start() 44 | { 45 | QueryPerformanceCounter((LARGE_INTEGER*)&_start); 46 | } 47 | 48 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 49 | 50 | double base::hptimer::elapsed_time() 51 | { 52 | LARGE_INTEGER stop; 53 | 54 | QueryPerformanceCounter(&stop); 55 | 56 | return double(stop.QuadPart - _start) * _freqd; 57 | } 58 | 59 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 60 | 61 | double base::hptimer::restart() { 62 | LARGE_INTEGER stop; 63 | QueryPerformanceCounter(&stop); 64 | 65 | const double t = (stop.QuadPart - _start) * _freqd; 66 | 67 | _start = stop.QuadPart; 68 | 69 | return t; 70 | } 71 | 72 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 73 | 74 | __int64 base::hptimer::time() 75 | { 76 | LARGE_INTEGER t; 77 | 78 | QueryPerformanceCounter(&t); 79 | 80 | return t.QuadPart; 81 | } 82 | 83 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 84 | 85 | -------------------------------------------------------------------------------- /src/base/mutex.cpp: -------------------------------------------------------------------------------- 1 | #include "mutex.h" 2 | 3 | #include 4 | 5 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 6 | 7 | base::mutex::mutex() 8 | : _cs() 9 | { 10 | InitializeCriticalSectionAndSpinCount( 11 | reinterpret_cast(&_cs), 512); 12 | } 13 | 14 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 15 | 16 | base::mutex::~mutex() 17 | { 18 | DeleteCriticalSection(reinterpret_cast(&_cs)); 19 | } 20 | 21 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 22 | 23 | void base::mutex::lock() 24 | { 25 | EnterCriticalSection(reinterpret_cast(&_cs)); 26 | } 27 | 28 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 29 | 30 | void base::mutex::unlock() 31 | { 32 | LeaveCriticalSection(reinterpret_cast(&_cs)); 33 | } 34 | 35 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 36 | 37 | bool base::mutex::try_lock() 38 | { 39 | return 0 != TryEnterCriticalSection( 40 | reinterpret_cast(&_cs)); 41 | } 42 | 43 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 44 | -------------------------------------------------------------------------------- /src/base/mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __ASYNC_VBO_TRANSFERS_BASE_MUTEX_H__ 24 | #define __ASYNC_VBO_TRANSFERS_BASE_MUTEX_H__ 25 | 26 | namespace base { 27 | 28 | class mutex 29 | { 30 | public: 31 | struct critical_section 32 | { 33 | enum { CS_SIZE = 16*4, }; 34 | char _tmp[CS_SIZE]; 35 | }; 36 | 37 | mutex(); 38 | ~mutex(); 39 | 40 | void lock(); 41 | void unlock(); 42 | 43 | bool try_lock(); 44 | 45 | private: 46 | critical_section _cs; 47 | }; 48 | 49 | class mutex_guard 50 | { 51 | protected: 52 | 53 | mutex &_mx; 54 | 55 | public: 56 | explicit mutex_guard(mutex &mx) : _mx(mx) { _mx.lock(); } 57 | 58 | ~mutex_guard() { _mx.unlock(); } 59 | 60 | private: 61 | void operator = (const mutex_guard&); 62 | }; 63 | 64 | } // end of namspace base 65 | 66 | #endif // __ASYNC_VBO_TRANSFERS_BASE_MUTEX_H__ 67 | -------------------------------------------------------------------------------- /src/base/pixelfmt.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __ASYNC_VBO_TRANSFERS_BASE_PIXELFMT_H__ 24 | #define __ASYNC_VBO_TRANSFERS_BASE_PIXELFMT_H__ 25 | 26 | namespace base { 27 | 28 | enum pixelfmt { 29 | PF_UNKNOWN = 0, 30 | 31 | PF_R8, 32 | PF_RG8, 33 | PF_RGB8, 34 | PF_RGBA8, 35 | 36 | PF_R8I, 37 | PF_RG8I, 38 | PF_RGB8I, 39 | PF_RGBA8I, 40 | 41 | PF_R8UI, 42 | PF_RG8UI, 43 | PF_RGB8UI, 44 | PF_RGBA8UI, 45 | 46 | PF_R16, 47 | PF_RG16, 48 | PF_RGB16, 49 | PF_RGBA16, 50 | 51 | PF_R16I, 52 | PF_RG16I, 53 | PF_RGB16I, 54 | PF_RGBA16I, 55 | 56 | PF_R16UI, 57 | PF_RG16UI, 58 | PF_RGB16UI, 59 | PF_RGBA16UI, 60 | 61 | PF_R32I, 62 | PF_RG32I, 63 | PF_RGB32I, 64 | PF_RGBA32I, 65 | 66 | PF_R32UI, 67 | PF_RG32UI, 68 | PF_RGB32UI, 69 | PF_RGBA32UI, 70 | 71 | PF_BGR8, 72 | PF_BGRA8, 73 | 74 | PF_BGR8I, 75 | PF_BGRA8I, 76 | 77 | PF_BGR8UI, 78 | PF_BGRA8UI, 79 | 80 | PF_BGR16, 81 | PF_BGRA16, 82 | 83 | PF_BGR16I, 84 | PF_BGRA16I, 85 | 86 | PF_BGR16UI, 87 | PF_BGRA16UI, 88 | 89 | PF_BGR32I, 90 | PF_BGRA32I, 91 | 92 | PF_BGR32UI, 93 | PF_BGRA32UI, 94 | 95 | // FLOAT 96 | 97 | PF_R32F, 98 | PF_RG32F, 99 | PF_RGB32F, 100 | PF_RGBA32F, 101 | 102 | // HALF FLOAT with source 16F 103 | 104 | PF_R16F, 105 | PF_RG16F, 106 | PF_RGB16F, 107 | PF_RGBA16F, 108 | 109 | // HALF FLOAT with source 32F 110 | 111 | PF_R16F_FLOAT, 112 | PF_RG16F_FLOAT, 113 | PF_RGB16F_FLOAT, 114 | PF_RGBA16F_FLOAT, 115 | 116 | // DEPTH 117 | 118 | PF_DEPTH16, 119 | PF_DEPTH24, 120 | PF_DEPTH24_STENCIL8, 121 | PF_DEPTH32, 122 | PF_DEPTH32F, 123 | PF_DEPTH32F_S8, 124 | 125 | // COMPRESSED 126 | 127 | PF_DXT1, 128 | PF_DXT3, 129 | PF_DXT5, 130 | 131 | // SIGNED NORMALIZED 132 | 133 | PF_R8_SNORM, 134 | PF_RG8_SNORM, 135 | PF_RGB8_SNORM, 136 | PF_RGBA8_SNORM, 137 | 138 | PF_R16_SNORM, 139 | PF_RG16_SNORM, 140 | PF_RGB16_SNORM, 141 | PF_RGBA16_SNORM, 142 | 143 | PF_DXT1_SRGB, 144 | PF_DXT3_SRGB, 145 | PF_DXT5_SRGB, 146 | 147 | PF_RGBA8_SRGB, 148 | PF_BGRA8_SRGB, 149 | 150 | PF_RGB565, 151 | PF_R11_G11_B10F, 152 | 153 | PF_LAST, 154 | }; 155 | 156 | } // end of namespace base 157 | 158 | #endif // __ASYNC_VBO_TRANSFERS_BASE_PIXELFMT_H__ 159 | -------------------------------------------------------------------------------- /src/base/tga_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __ASYNC_VBO_TRANSFERS_BASE_TGA_UTILS_H__ 24 | #define __ASYNC_VBO_TRANSFERS_BASE_TGA_UTILS_H__ 25 | 26 | namespace base { 27 | 28 | #pragma pack(push,1) 29 | 30 | struct tga_header 31 | { 32 | char identsize; //< size of ID field that follows 18 byte header (0 usually) 33 | char colormaptype; //< type of colour map 0=none, 1=has palette 34 | char imagetype; //< type of image 0=none,1=indexed,2=rgb,3=grey,+8=rle packed 35 | 36 | short colormapstart; //< first colour map entry in palette 37 | short colormaplength; //< number of colours in palette 38 | char colormapbits; //< number of bits per palette entry 15,16,24,32 39 | 40 | short xstart; //< image x origin 41 | short ystart; //< image y origin 42 | short width; //< image width in pixels 43 | short height; //< image height in pixels 44 | char bits; //< image bits per pixel 8,16,24,32 45 | char descriptor; //< image descriptor bits (vh flip bits) 46 | 47 | tga_header( 48 | const short width, 49 | const short height, 50 | const char bits) 51 | : identsize(0) 52 | , colormaptype(0) 53 | , imagetype(2) 54 | , colormapstart(0) 55 | , colormaplength(0) 56 | , colormapbits(0) 57 | , xstart(0) 58 | , ystart(0) 59 | , width(width) 60 | , height(height) 61 | , bits(bits) 62 | , descriptor(0) 63 | {} 64 | }; 65 | 66 | #pragma pack(pop) 67 | 68 | } // end of namespace base 69 | 70 | #endif // __ASYNC_VBO_TRANSFERS_BASE_TGA_UTILS_H__ 71 | -------------------------------------------------------------------------------- /src/base/thread.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __ASYNC_VBO_TRANSFERS_BASE_THREAD_H__ 24 | #define __ASYNC_VBO_TRANSFERS_BASE_THREAD_H__ 25 | 26 | #include "base.h" 27 | 28 | namespace base { 29 | 30 | class thread 31 | { 32 | protected: 33 | 34 | void* _handle; 35 | 36 | public: 37 | 38 | thread(); 39 | 40 | virtual ~thread(); 41 | 42 | virtual void start(const base::source_location &loc); 43 | 44 | virtual void run() {} 45 | 46 | virtual void stop(const base::source_location &loc); 47 | 48 | static void* thread_fnc(void* data); 49 | 50 | bool wait_for_end(const unsigned int time = -1); 51 | 52 | void terminate(); 53 | }; 54 | 55 | } // end of namspace base 56 | 57 | #endif // __ASYNC_VBO_TRANSFERS_BASE_THREAD_H__ -------------------------------------------------------------------------------- /src/base/thread_win.cpp: -------------------------------------------------------------------------------- 1 | #include "thread.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 8 | 9 | extern bool test_mode; 10 | 11 | base::thread::thread() 12 | : _handle(0) 13 | {} 14 | 15 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 16 | 17 | base::thread::~thread() 18 | {} 19 | 20 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 21 | 22 | void base::thread::start(const base::source_location &loc) 23 | { 24 | _handle = CreateThread( 25 | 0, 26 | 0, 27 | (LPTHREAD_START_ROUTINE)thread::thread_fnc, 28 | this, 29 | 0, 30 | 0); 31 | 32 | if(_handle==0) { 33 | throw base::exception(loc.to_str()) 34 | << "thread::start failed! (err: " 35 | << GetLastError() 36 | << ")\n"; 37 | } 38 | } 39 | 40 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 41 | 42 | void base::thread::stop(const base::source_location &loc) 43 | { 44 | loc; 45 | } 46 | 47 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 48 | 49 | void* base::thread::thread_fnc(void* data) 50 | { 51 | try { 52 | reinterpret_cast(data)->run(); 53 | } 54 | catch(const base::exception &e) { 55 | std::cout << e.text(); 56 | if (!test_mode) 57 | { 58 | MessageBoxA(0, e.text().c_str(), "Error...", MB_APPLMODAL); 59 | } 60 | PostQuitMessage(-1); 61 | return (void*)-1; 62 | } 63 | PostQuitMessage(-1); 64 | 65 | return 0; 66 | } 67 | 68 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 69 | 70 | bool base::thread::wait_for_end(const unsigned int time /* = -1 */) 71 | { 72 | return WAIT_OBJECT_0 == WaitForSingleObject((HANDLE)_handle, time); 73 | } 74 | 75 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 76 | 77 | void base::thread::terminate() 78 | { 79 | TerminateThread((HANDLE)_handle, DWORD(-1)); 80 | } 81 | 82 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 83 | -------------------------------------------------------------------------------- /src/base/types.h: -------------------------------------------------------------------------------- 1 | #ifndef __ASYNC_VBO_TRANSFERS_TYPES_H__ 2 | #define __ASYNC_VBO_TRANSFERS_TYPES_H__ 3 | 4 | #include 5 | #include 6 | 7 | typedef unsigned short ushort; 8 | typedef unsigned char uchar; 9 | typedef unsigned int uint32; 10 | typedef unsigned char uint8; 11 | typedef unsigned __int64 uint64; 12 | typedef __int64 int64; 13 | 14 | //typedef glm::vec4 float4; 15 | //typedef glm::vec3 float3; 16 | //typedef glm::vec2 float2; 17 | // 18 | //typedef glm::ivec4 int4; 19 | //typedef glm::ivec3 int3; 20 | //typedef glm::ivec2 int2; 21 | // 22 | typedef glm::uvec4 uint4; 23 | typedef glm::uvec3 uint3; 24 | typedef glm::uvec2 uint2; 25 | // 26 | //typedef glm::u16vec4 ushort4; 27 | //typedef glm::u16vec3 ushort3; 28 | //typedef glm::u16vec2 ushort2; 29 | // 30 | //typedef glm::i16vec4 short4; 31 | //typedef glm::i16vec3 short3; 32 | //typedef glm::i16vec2 short2; 33 | // 34 | typedef glm::u8vec4 uchar4; 35 | typedef glm::u8vec3 uchar3; 36 | typedef glm::u8vec2 uchar2; 37 | // 38 | //typedef glm::i8vec4 char4; 39 | //typedef glm::i8vec3 char3; 40 | //typedef glm::i8vec2 char2; 41 | 42 | namespace gen{ 43 | 44 | struct vert{ 45 | glm::vec3 pos; 46 | glm::vec3 norm; 47 | glm::vec2 uv; 48 | }; 49 | 50 | struct vert_packed{ 51 | glm::ivec2 pos; 52 | glm::ivec4 norm; 53 | }; 54 | 55 | struct triangle_pair_vert_indices{ 56 | ushort t1_i1; 57 | ushort t1_i2; 58 | ushort t1_i3; 59 | ushort t2_i1; 60 | ushort t2_i2; 61 | ushort t2_i3; 62 | }; 63 | }; 64 | 65 | #endif -------------------------------------------------------------------------------- /src/base/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef __ASYNC_VBO_TRANSFERS_UTILS_H__ 2 | #define __ASYNC_VBO_TRANSFERS_UTILS_H__ 3 | 4 | #include 5 | #include 6 | 7 | namespace util{ 8 | 9 | static int rndFromInterval(int min, int max){ 10 | int result = rand(); 11 | result %= (max - min + 1); 12 | return result + min; 13 | } 14 | 15 | } 16 | 17 | #endif -------------------------------------------------------------------------------- /src/benchmark.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __ASYNC_VBO_TRANSFERS_APP_SCENARIO2_H__ 24 | #define __ASYNC_VBO_TRANSFERS_APP_SCENARIO2_H__ 25 | 26 | #define GRASS_TEST_FILE_NAME "grass_test.csv" 27 | #define CUBES_TEST_FILE_NAME "cubes_test.csv" 28 | #define BUILDINGS_TEST_FILE_NAME "buildings_test.csv" 29 | 30 | #include "base/app.h" 31 | #include "base/thread.h" 32 | 33 | #include 34 | #include 35 | 36 | #include 37 | 38 | class renderer; 39 | class scene_i; 40 | 41 | class benchmark 42 | : public base::app 43 | { 44 | protected: 45 | std::auto_ptr _scene; 46 | std::auto_ptr _renderer; 47 | std::vector _stats_str; 48 | base::stats_data _test_stats; 49 | 50 | public: 51 | benchmark(); 52 | virtual ~benchmark(); 53 | 54 | const char* get_app_name() const override { return "draw call benchmark"; } 55 | const char* get_wnd_name() const override { return get_app_name(); } 56 | const char* get_wnd_cls() const override { return "benchmark class"; } 57 | const char* get_test_name() const override; 58 | void on_shutdown() override; 59 | 60 | void set_benchmark_mode(bool mode) override { _benchmark_mode = mode; } 61 | 62 | void key(const int key, const bool down)override; 63 | 64 | void start() override; 65 | void gpu_init() override; 66 | 67 | void stop() override; 68 | 69 | void draw_frame() override; 70 | 71 | void gpu_draw_frame(base::frame_context * const ctx) override; 72 | 73 | bool write_test_data_csv( 74 | const char * file_name, 75 | const base::stats_data & stats, 76 | const float time, 77 | const int nframes, 78 | bool is_dummy = false); 79 | 80 | bool grass_write_test_data_csv( 81 | const char * file_name, 82 | const base::stats_data & stats, 83 | const float time, 84 | const int nframes, 85 | bool is_dummy = false); 86 | 87 | bool buildings_write_test_data_csv( 88 | const char * file_name, 89 | const base::stats_data & stats, 90 | const float time, 91 | const int nframes, 92 | bool is_dummy = false); 93 | private: 94 | benchmark(const benchmark&); 95 | void operator =(const benchmark&); 96 | const char * get_texturing_mode_str(int mode); 97 | void get_mesh_size_str(char * out_str, ushort nvert, ushort nelem); 98 | }; 99 | 100 | #endif // __ASYNC_VBO_TRANSFERS_APP_SCENARIO2_H__ 101 | -------------------------------------------------------------------------------- /src/cube_gen.h: -------------------------------------------------------------------------------- 1 | #ifndef __ASYNC_VBO_TRANSFERS_CUBE_GEN_H__ 2 | #define __ASYNC_VBO_TRANSFERS_CUBE_GEN_H__ 3 | 4 | #include "base/types.h" 5 | #include "base/base.h" 6 | 7 | struct voxel_info { 8 | uint32 vert_idx; 9 | uint32 mask; 10 | }; 11 | 12 | void get_face_and_vert_count_for_tess_level( 13 | uint32 tess_level, 14 | uint32 & element_count, 15 | uint32 & vert_count); 16 | 17 | void gen_cube_imp( 18 | ushort tess_level_x, 19 | ushort tess_level_y, 20 | ushort tess_level_z, 21 | float * pos_data, 22 | float * norm_uv_data, 23 | ushort * index_array, 24 | short * voxel_map, 25 | voxel_info * voxel_inf, 26 | uint32 & element_count, 27 | uint32 & vert_count, 28 | bool use_int, 29 | bool deform, 30 | bool multipass); 31 | 32 | template < class V > 33 | void gen_cube( 34 | ushort tess_level_x, 35 | ushort tess_level_y, 36 | ushort tess_level_z, 37 | V * const vert_data, 38 | V * const norm_uv_data, 39 | ushort * index_array, 40 | short * voxel_map, 41 | voxel_info * voxel_inf, 42 | uint32 & element_count, 43 | uint32 & vert_count, 44 | bool deform, 45 | bool multipass); 46 | 47 | template <> 48 | static void gen_cube( 49 | ushort tess_level_x, 50 | ushort tess_level_y, 51 | ushort tess_level_z, 52 | float * const vert_data, 53 | float * const norm_uv_data, 54 | ushort * index_array, 55 | short * voxel_map, 56 | voxel_info * voxel_inf, 57 | uint32 & element_count, 58 | uint32 & vert_count, 59 | bool deform, 60 | bool multipass) 61 | { 62 | gen_cube_imp( 63 | tess_level_x, 64 | tess_level_y, 65 | tess_level_z, 66 | vert_data, 67 | norm_uv_data, 68 | index_array, 69 | voxel_map, 70 | voxel_inf, 71 | element_count, 72 | vert_count, 73 | false, 74 | deform, 75 | multipass); 76 | } 77 | 78 | template<> 79 | static void gen_cube( 80 | ushort tess_level_x, 81 | ushort tess_level_y, 82 | ushort tess_level_z, 83 | glm::int2 * const vert_data, 84 | glm::int2 * const norm_uv_data, 85 | ushort * index_array, 86 | short * voxel_map, 87 | voxel_info * voxel_inf, 88 | uint32 & element_count, 89 | uint32 & vert_count, 90 | bool deform, 91 | bool multipass) 92 | { 93 | gen_cube_imp( 94 | tess_level_x, 95 | tess_level_y, 96 | tess_level_z, 97 | reinterpret_cast(vert_data), 98 | reinterpret_cast(norm_uv_data), 99 | index_array, 100 | voxel_map, 101 | voxel_inf, 102 | element_count, 103 | vert_count, 104 | true, 105 | deform, 106 | multipass); 107 | } 108 | 109 | void gen_cube_simple_imp( 110 | int faces_per_side, 111 | char * const vert_data, 112 | char * const norm_uv_data, 113 | ushort * index_array, 114 | bool use_int); 115 | 116 | template 117 | void gen_cube_simple( 118 | int faces_per_side, 119 | V * const pos_data, 120 | V * const norm_uv_data, 121 | ushort * index_array); 122 | 123 | template <> 124 | static void gen_cube_simple( 125 | int faces_per_side, 126 | float * const vert_data, 127 | float * const norm_uv_data, 128 | ushort * index_array) 129 | { 130 | gen_cube_simple_imp( 131 | faces_per_side, 132 | (char * const)vert_data, 133 | (char * const)norm_uv_data, 134 | index_array, 135 | false); 136 | } 137 | 138 | template <> 139 | static void gen_cube_simple( 140 | int faces_per_side, 141 | glm::int2 * const vert_data, 142 | glm::int2 * const norm_uv_data, 143 | ushort * index_array) 144 | { 145 | gen_cube_simple_imp( 146 | faces_per_side, 147 | (char * const)vert_data, 148 | (char * const)norm_uv_data, 149 | index_array, 150 | true); 151 | } 152 | 153 | static void get_face_and_vert_count( 154 | ushort faces_per_side, 155 | uint32 & element_count, 156 | uint32 & vert_count) 157 | { 158 | vert_count = 8 * (faces_per_side + 1 )+ 8 * faces_per_side + 2; 159 | element_count = 48 * faces_per_side; 160 | } 161 | 162 | 163 | class voxel_gen 164 | { 165 | protected: 166 | 167 | static const glm::uint SIZE_BITS = 2; 168 | static const glm::uint BITS_Y = 2; 169 | static const glm::uint BITS_Z = 4; 170 | static const glm::uint CUBE_SIZE = 1 << 2; 171 | static const glm::uint SIZE_MASK = CUBE_SIZE - 1; 172 | static const glm::uint NVOXELS = CUBE_SIZE * CUBE_SIZE * CUBE_SIZE; 173 | 174 | ushort _voxels[NVOXELS]; 175 | ushort _indices[24 * NVOXELS]; 176 | ushort _mask_idx[6 * NVOXELS]; 177 | 178 | ushort _nvertices; 179 | 180 | public: 181 | 182 | voxel_gen() 183 | : _nvertices(0) 184 | { 185 | auto i = _voxels; 186 | auto e = i + CUBE_SIZE * CUBE_SIZE * CUBE_SIZE; 187 | do { *i++ = 1; } while (i != e); 188 | } 189 | 190 | inline uchar idx(const char x, const char y, const char z) 191 | { 192 | return x | (y << BITS_Y) | (z << BITS_Z); 193 | } 194 | 195 | inline bool is_there(const char x, const char y, const char z) 196 | { 197 | if (x < 0 || y < 0 || z < 0 198 | || x > SIZE_MASK || y > SIZE_MASK || z > SIZE_MASK) 199 | return false; 200 | 201 | return _voxels[idx(x, y, z)] != 0; 202 | } 203 | 204 | void create_masks() 205 | { 206 | ushort i = 0; 207 | ushort e = NVOXELS; 208 | do { 209 | const uchar x = i & SIZE_MASK; 210 | const uchar y = (i >> BITS_Y) & SIZE_MASK; 211 | const uchar z = (i >> BITS_Z) & SIZE_MASK; 212 | 213 | if (_voxels[i] == 0) 214 | continue; 215 | // 216 | uchar mask = 0; 217 | mask |= uchar(is_there(x - 1, y, z)); 218 | mask |= uchar(is_there(x + 1, y, z)) << 1; 219 | mask |= uchar(is_there(x, y - 1, z)) << 2; 220 | mask |= uchar(is_there(x, y + 1, z)) << 3; 221 | mask |= uchar(is_there(x, y, z - 1)) << 4; 222 | mask |= uchar(is_there(x, y, z + 1)) << 5; 223 | 224 | _voxels[i] = mask; 225 | } while (++i != e); 226 | } 227 | 228 | void triangulate() 229 | { 230 | ushort i = 0; 231 | ushort e = NVOXELS; 232 | do { 233 | const uchar x = i & SIZE_MASK; 234 | const uchar y = (i >> BITS_Y) & SIZE_MASK; 235 | const uchar z = (i >> BITS_Z) & SIZE_MASK; 236 | 237 | const ushort voxel = _voxels[i]; 238 | 239 | if (voxel == 0) 240 | continue; 241 | 242 | for (uchar i = 0; i < 6; ++i) { 243 | const uchar mask = 1 << i; 244 | 245 | if (voxel & mask) { 246 | // gen neighbor voxel 247 | if ((i & 1) == 0) { 248 | 249 | } 250 | 251 | } 252 | } 253 | 254 | } while (++i != e); 255 | } 256 | }; 257 | 258 | #endif -------------------------------------------------------------------------------- /src/gen_tex.cpp: -------------------------------------------------------------------------------- 1 | #include "gen_tex.h" 2 | 3 | #include "base/base.h" 4 | 5 | #include 6 | 7 | #define COMP_LATTICE_PROBABILITY 0.05f 8 | 9 | 10 | base::rnd_int _gen_text_rnd_generator(9894); 11 | 12 | uint32 u8vec4_to_uint32(const glm::u8vec4 & color){ 13 | return uint32(color.x) | uint32(color.y << 8) | uint32(color.z << 16) | uint32(color.w << 24); 14 | } 15 | 16 | void gen_texture( 17 | glm::u8vec4 * const tex_data, 18 | const ushort dim, 19 | const ushort grid_dim, 20 | const unsigned seed, 21 | uint32 * const grid) 22 | { 23 | if (grid_dim <= 0){ 24 | return; 25 | } 26 | 27 | const int max = int(1 / COMP_LATTICE_PROBABILITY); 28 | 29 | const int lattice_dim = dim / grid_dim; 30 | 31 | int base_col_rand = base::rndFromInterval(_gen_text_rnd_generator, -50, 50); 32 | 33 | glm::u8vec4 base_color( 34 | 86 + base_col_rand, 35 | 116 + base_col_rand, 36 | 142 + base_col_rand + (base_col_rand & 0xf), 0); 37 | glm::u8vec4 complement_color1(100, 100, 100, 0); 38 | glm::u8vec4 complement_color2(234, 223, 205, 255); 39 | 40 | const uint32 bc = u8vec4_to_uint32(base_color); 41 | const uint32 cc1 = u8vec4_to_uint32(complement_color1); 42 | const uint32 cc2 = u8vec4_to_uint32(complement_color2); 43 | 44 | { 45 | uint32 * i = grid; 46 | uint32 * const e = i + grid_dim * grid_dim; 47 | do { *i++ = bc; } while (i != e); 48 | } 49 | 50 | for (int i = 0; i < grid_dim*grid_dim; i++){ 51 | int rnd = base::rndFromInterval(_gen_text_rnd_generator, 1, max); 52 | if (rnd == 1){ 53 | grid[i] = cc1; 54 | } 55 | else if (rnd == 3){ 56 | grid[i] = cc2; 57 | } 58 | } 59 | 60 | uint32 * row = grid + grid_dim * grid_dim; 61 | const int dim4 = dim * 4; 62 | 63 | for (ushort y = 0; y < dim; y += 4){ 64 | for (ushort x = 0; x < dim; x++){ 65 | row[x] = grid[(y / lattice_dim) * grid_dim + (x / lattice_dim)]; 66 | } 67 | 68 | memcpy(tex_data + y*dim, row, dim4); 69 | memcpy(tex_data + (y+1)*dim, row, dim4); 70 | memcpy(tex_data + (y+2)*dim, row, dim4); 71 | memcpy(tex_data + (y+3)*dim, row, dim4); 72 | } 73 | } 74 | 75 | ushort rgb888_to_rgb565(uint8 r, uint8 g, uint8 b) { 76 | return ((ushort(r) >> 3) << 11) | (((ushort(g) >> 2)) << 5) | ((ushort(b) >> 3)); 77 | } 78 | 79 | glm::ivec2 gen_dxt1_block(uint8 r, uint8 g, uint8 b, uint8 a) { 80 | ushort rgb565 = rgb888_to_rgb565(r, g, b); 81 | return glm::ivec2(rgb565 << 16 | rgb565, 0xaaaaaaaa); 82 | } -------------------------------------------------------------------------------- /src/gen_tex.h: -------------------------------------------------------------------------------- 1 | #ifndef __ASYNC_VBO_TRANSFERS_GEN_TEX_H__ 2 | #define __ASYNC_VBO_TRANSFERS_GEN_TEX_H__ 3 | #include "base/types.h" 4 | #include 5 | #include 6 | 7 | void gen_texture(glm::u8vec4 * tex_data, ushort dim, ushort grid_dim, unsigned seed, uint32 * const tmp); 8 | glm::ivec2 gen_dxt1_block(ushort r, ushort g, ushort b, ushort a); 9 | 10 | #endif -------------------------------------------------------------------------------- /src/obj_writer.cpp: -------------------------------------------------------------------------------- 1 | #include "obj_writer.h" 2 | 3 | 4 | obj_writer::obj_writer() 5 | { 6 | } 7 | 8 | 9 | obj_writer::~obj_writer() 10 | { 11 | if (_is_opened){ 12 | close(); 13 | } 14 | } 15 | 16 | bool obj_writer::open(const std::string & file_name) 17 | { 18 | _ofs.open(file_name); 19 | _is_opened = _ofs.is_open(); 20 | return _is_opened; 21 | } 22 | 23 | void obj_writer::close() 24 | { 25 | _ofs.close(); 26 | _is_opened = false; 27 | } 28 | 29 | void obj_writer::write_vertex(const glm::vec3 & vertex) 30 | { 31 | write_vertex(vertex.x, vertex.y, vertex.z); 32 | } 33 | 34 | void obj_writer::write_vertex(float x, float y, float z) 35 | { 36 | if (!_is_opened){ 37 | return; 38 | } 39 | 40 | _ofs << "v " << x << " " << y << " " << z << std::endl; 41 | } 42 | 43 | void obj_writer::write_normal(const glm::vec3 & normal) 44 | { 45 | write_normal(normal.x, normal.y, normal.z); 46 | } 47 | 48 | void obj_writer::write_normal(float x, float y, float z) 49 | { 50 | if (!_is_opened){ 51 | return; 52 | } 53 | 54 | _ofs << "vn " << x << " " << y << " " << z << std::endl; 55 | } 56 | 57 | void obj_writer::write_tex_coords(const glm::vec2 & uv) 58 | { 59 | write_tex_coords(uv.x, uv.y); 60 | } 61 | 62 | void obj_writer::write_tex_coords(float u, float v) 63 | { 64 | if (!_is_opened){ 65 | return; 66 | } 67 | 68 | _ofs << "vt " << u << " " << v << std::endl; 69 | } 70 | 71 | void obj_writer::write_face_idx_from_zero(int v1, int vn1, int vt1, 72 | int v2, int vn2, int vt2, 73 | int v3, int vn3, int vt3) 74 | { 75 | write_face(v1 + 1, vn1 + 1, vt1 + 1, 76 | v2 + 1, vn2 + 1, vt2 + 1, 77 | v3 + 1, vn3 + 1, vt3 + 1); 78 | } 79 | 80 | void obj_writer::write_face(int v1, int vn1, int vt1, 81 | int v2, int vn2, int vt2, 82 | int v3, int vn3, int vt3) 83 | { 84 | if (!_is_opened){ 85 | return; 86 | } 87 | 88 | _ofs << "f " << v1 << "/" << vn1 << "/" << vt1 << " " << 89 | v2 << "/" << vn2 << "/" << vt2 << " " << 90 | v3 << "/" << vn3 << "/" << vt3 << std::endl; 91 | } -------------------------------------------------------------------------------- /src/obj_writer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class obj_writer 8 | { 9 | public: 10 | obj_writer(); 11 | ~obj_writer(); 12 | 13 | bool open(const std::string & file_name); 14 | void close(); 15 | 16 | void write_vertex(const glm::vec3 & vertex); 17 | void write_vertex(float x, float y, float z); 18 | 19 | void write_normal(const glm::vec3 & normal); 20 | void write_normal(float x, float y, float z); 21 | 22 | void write_tex_coords(const glm::vec2 & uv); 23 | void write_tex_coords(float u, float v); 24 | 25 | void write_face_idx_from_zero(int v1, int vn1, int vt1, 26 | int v2, int vn2, int vt2, 27 | int v3, int vn3, int vt3); 28 | void write_face(int v1, int vn1, int vt1, 29 | int v2, int vn2, int vt2, 30 | int v3, int vn3, int vt3); 31 | 32 | private: 33 | bool _is_opened; 34 | std::ofstream _ofs; 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /src/pci_c.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hrabcak/draw_call_perf/602c578825ce18c0676611056d2361cc161ce635/src/pci_c.h -------------------------------------------------------------------------------- /src/renderer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include "renderer.h" 24 | #include "scene.h" 25 | #include "benchmark.h" 26 | 27 | #include "base/base.h" 28 | #include "base/canvas.h" 29 | #include "base/frame_context.h" 30 | #include "base/app.h" 31 | #include "base/hptimer.h" 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #include 38 | 39 | using namespace glm; 40 | 41 | extern bool test_mode; 42 | 43 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 44 | 45 | renderer::renderer(base::app * const a, const base::source_location &loc) 46 | : thread() 47 | , _event() 48 | , _queue() 49 | , _mx_queue() 50 | , _shutdown(false) 51 | , _app(a) 52 | , _vendor_id(0) 53 | , _device_id(0) 54 | , _rev_id(0) 55 | , _shutdown_code(base::ecOK) 56 | { 57 | thread::start(loc); 58 | 59 | if (!_event.wait(1000000)) 60 | throw base::exception(loc.to_str()) 61 | << "Renderer initialization failed!"; 62 | } 63 | 64 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 65 | 66 | renderer::~renderer() {} 67 | 68 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 69 | 70 | void renderer::run() 71 | { 72 | __try{ 73 | _run_wrapper(); 74 | } 75 | __except (EXCEPTION_EXECUTE_HANDLER){ 76 | _app->shutdown(base::ecDriverError); 77 | } 78 | } 79 | 80 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 81 | 82 | void renderer::_run_wrapper(){ 83 | try { 84 | base::init_opengl_win(); 85 | base::init_opengl_dbg_win(); 86 | 87 | base::get_display_ven_dev_id(_vendor_id, _device_id, _rev_id); 88 | 89 | if (_vendor_id == 0x1002/* || _vendor_id == 0x1022*/){ 90 | _graphic_card_name = base::ven_dev_id_to_ati_card_name(_vendor_id, _device_id); 91 | } 92 | else{ 93 | _graphic_card_name = (char*)glGetString(GL_RENDERER); 94 | } 95 | 96 | _graphic_card_vendor = (char*)glGetString(GL_VENDOR); 97 | 98 | _graphic_card_driver = (char*)glGetString(GL_VERSION); 99 | 100 | // create frame_context pool 101 | { 102 | base::mutex_guard g(_mx_queue); 103 | base::app::get()->create_frame_context_pool(); 104 | } 105 | 106 | _app->gpu_init(); 107 | 108 | _event.signal(); 109 | 110 | for (;;) { 111 | base::frame_context *ctx = 0; 112 | 113 | if (!_waiting.empty() && _waiting.front()->check_fence()) { 114 | base::mutex_guard g(_mx_queue); 115 | base::app::get()->push_frame_context_to_pool(_waiting.front()); 116 | 117 | _waiting.pop_front(); 118 | } 119 | 120 | { 121 | base::mutex_guard g(_mx_queue); 122 | if (!_queue.empty()) { 123 | ctx = _queue.back(); 124 | _queue.pop_back(); 125 | } 126 | } 127 | 128 | if (ctx == 0) { 129 | if (_shutdown) break; 130 | continue; 131 | } 132 | 133 | draw_frame(ctx); 134 | 135 | ctx->put_fence(); 136 | _waiting.push_back(ctx); 137 | 138 | if (_shutdown) 139 | break; 140 | } 141 | 142 | 143 | printf("Renderer thread ended...\n"); 144 | } 145 | catch (const base::exception &e) { 146 | if (!test_mode){ 147 | MessageBoxA(0, e.text().c_str(), "Error...", MB_APPLMODAL); 148 | } 149 | _shutdown = true; 150 | _shutdown_code = base::ecAppError; 151 | _event.signal(); 152 | } 153 | 154 | _app->shutdown(_shutdown_code); 155 | } 156 | 157 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 158 | 159 | void renderer::stop(const base::source_location &loc) 160 | { 161 | printf("Renderer is going down...\n"); 162 | 163 | _shutdown = true; 164 | _event.signal(); 165 | 166 | if(!wait_for_end(2000)) { 167 | printf("Terminating renderer thread!\n"); 168 | terminate(); 169 | } 170 | 171 | thread::stop(loc); 172 | } 173 | 174 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 175 | 176 | void renderer::draw_frame(base::frame_context * const ctx) 177 | { 178 | base::hptimer timer; 179 | 180 | glEnable(GL_FRAMEBUFFER_SRGB); 181 | glEnable(GL_CULL_FACE); 182 | glEnable(GL_DEPTH_TEST); 183 | glClearColor(1.0f, 1.f, 1.f, 1.0f); 184 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 185 | 186 | _app->gpu_draw_frame(ctx); 187 | 188 | base::swap_buffers(); 189 | 190 | base::stats_data & stats = base::stats(); 191 | 192 | __int64 result[2] = { 0, }; 193 | glGetQueryObjecti64v(ctx->_time_queries[0], GL_QUERY_RESULT, result); 194 | glGetQueryObjecti64v(ctx->_time_queries[1], GL_QUERY_RESULT, result + 1); 195 | const double coef_n2m = 1.0 / 1000000.0; 196 | const double gpu_time = double(result[1] - result[0]) * coef_n2m; 197 | 198 | ctx->_stats = stats; 199 | ctx->_stats._gpu_time = float(gpu_time); 200 | ctx->_stats._cpu_time = float(ctx->_cpu_render_time); 201 | ctx->_time = timer.time(); 202 | } 203 | 204 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 205 | 206 | base::frame_context* renderer::pop_frame_context_from_pool() { 207 | base::mutex_guard g(_mx_queue); 208 | return base::app::get()->pop_frame_context_from_pool(); 209 | } 210 | 211 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 212 | -------------------------------------------------------------------------------- /src/renderer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __ASYNC_VBO_TRANSFERS_RENDERER_H__ 24 | #define __ASYNC_VBO_TRANSFERS_RENDERER_H__ 25 | 26 | #include "base/base.h" 27 | #include "base/thread.h" 28 | #include "base/event.h" 29 | #include "base/mutex.h" 30 | 31 | #include 32 | 33 | namespace base { 34 | struct frame_context; 35 | class app; 36 | } 37 | 38 | class renderer 39 | : public base::thread 40 | { 41 | protected: 42 | base::thread_event _event; 43 | std::list _queue; 44 | std::list _waiting; 45 | base::mutex _mx_queue; 46 | bool _shutdown; 47 | base::exit_code_type _shutdown_code; 48 | base::app *_app; 49 | std::string _graphic_card_name; 50 | std::string _graphic_card_driver; 51 | std::string _graphic_card_vendor; 52 | ushort _vendor_id; 53 | ushort _device_id; 54 | ushort _rev_id; 55 | 56 | public: 57 | 58 | renderer(base::app * const a, const base::source_location &loc); 59 | virtual ~renderer(); 60 | 61 | virtual void run(); 62 | 63 | virtual void stop(const base::source_location &loc); 64 | 65 | void draw_frame(base::frame_context * const ctx); 66 | 67 | void push_frame_context(base::frame_context *ctx) { 68 | base::mutex_guard g(_mx_queue); 69 | _queue.push_front(ctx); 70 | _event.signal(); 71 | } 72 | 73 | base::frame_context* pop_frame_context_from_pool(); 74 | 75 | const char* get_gpu_str() const { return _graphic_card_name.c_str(); } 76 | const char* get_gpu_driver_str() const { return _graphic_card_driver.c_str(); } 77 | const char* get_gpu_vendor_str() const { return _graphic_card_vendor.c_str(); } 78 | ushort get_vendor_id(){ return _vendor_id; } 79 | ushort get_device_id(){ return _device_id; } 80 | ushort get_rev_id(){ return _rev_id; } 81 | 82 | bool is_alive() { return !_shutdown; }; 83 | 84 | protected: 85 | void _run_wrapper(); 86 | }; 87 | 88 | #endif // __ASYNC_VBO_TRANSFERS_RENDERER_H__ -------------------------------------------------------------------------------- /src/scene.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __ASYNC_VBO_TRANSFERS_SCENE_H__ 24 | #define __ASYNC_VBO_TRANSFERS_SCENE_H__ 25 | 26 | #include 27 | 28 | #include 29 | 30 | #include "base/types.h" 31 | 32 | #include "scene_i.h" 33 | 34 | namespace base { 35 | struct frame_context; 36 | class source_location; 37 | } 38 | 39 | class benchmark; 40 | 41 | class scene 42 | : public scene_i 43 | { 44 | public: 45 | static const int * get_vtx_tbl() { 46 | static const int vtx_tbl[] = { 24, 32, 40, 42, 48, 56, 54, 47 | 64, 62, 72, 66, 72, 76, 82, 48 | 80, 92, 90, 94, 100, 102, 104, 49 | 112, 114, 112, 118, 120, 122, 126, 50 | 132, 130, 136, 142, 144, 152, 154, 51 | 158, 160, 162, 166, 172, 170, 180, 52 | 182, 184, 192, 190, 192, 202, 208, 53 | 210, 214, 216, 224, 232, 236, 238, 54 | 240, 256, 262, 264, 266, 288, 292, 55 | 294, 320, 322, 352, 384 }; 56 | 57 | return &vtx_tbl[0]; 58 | } 59 | static const int * get_ele_tbl() { 60 | static const int ele_tbl[] = { 36, 60, 84, 96, 108, 132, 144, 61 | 156, 168, 180, 192, 204, 228, 240, 62 | 252, 276, 288, 312, 324, 336, 348, 63 | 372, 384, 396, 408, 420, 432, 456, 64 | 468, 480, 492, 528, 540, 564, 576, 65 | 600, 612, 624, 648, 660, 672, 708, 66 | 720, 732, 756, 768, 780, 816, 852, 67 | 864, 888, 900, 924, 972, 996, 1008, 68 | 1020, 1092, 1128, 1140, 1152, 1260, 1284, 69 | 1296, 1428, 1440, 1596, 1764 }; 70 | return &ele_tbl[0]; 71 | } 72 | static const int * get_sz_tbl(){ 73 | static const int sz_tbl[] = { 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 1, 1, 0, 0, 3, 74 | 0, 0, 4, 1, 1, 1, 0, 0, 5, 0, 1, 3, 0, 0, 6, 75 | 1, 1, 2, 0, 1, 4, 0, 2, 3, 0, 1, 5, 1, 2, 2, 76 | 0, 1, 6, 0, 3, 3, 1, 2, 3, 0, 2, 5, 1, 1, 5, 77 | 0, 3, 4, 0, 2, 6, 1, 1, 6, 2, 2, 3, 0, 3, 5, 78 | 0, 4, 4, 1, 2, 5, 1, 3, 4, 0, 3, 6, 2, 3, 3, 79 | 0, 4, 5, 1, 3, 5, 1, 4, 4, 0, 4, 6, 0, 5, 5, 80 | 1, 3, 6, 2, 2, 6, 1, 4, 5, 2, 3, 5, 0, 5, 6, 81 | 3, 3, 4, 1, 4, 6, 1, 5, 5, 2, 3, 6, 0, 6, 6, 82 | 3, 3, 5, 3, 4, 4, 1, 5, 6, 2, 4, 6, 2, 5, 5, 83 | 3, 4, 5, 4, 4, 4, 1, 6, 6, 2, 5, 6, 3, 4, 6, 84 | 3, 5, 5, 4, 4, 5, 2, 6, 6, 3, 5, 6, 4, 4, 6, 85 | 4, 5, 5, 3, 6, 6, 4, 5, 6, 5, 5, 5, 4, 6, 6, 86 | 5, 5, 6, 5, 6, 6, 6, 6, 6 }; 87 | 88 | return &sz_tbl[0]; 89 | } 90 | 91 | static const int MAX_BLOCK_COUNT = 0x10000; 92 | std::vector _test_names; 93 | 94 | scene(benchmark * const app); 95 | ~scene(); 96 | 97 | void init_gpu_stuff(const base::source_location &loc) override; 98 | void post_gpu_init() override; 99 | void update(base::frame_context * const ctx) override; 100 | void gpu_draw(base::frame_context * const ctx) override; 101 | 102 | const char* get_test_name(const int i) const override { return _test_names[i].c_str(); } 103 | 104 | public: 105 | 106 | void add_test_block(bool add_peaks); 107 | 108 | static bool send_test_data(); 109 | 110 | bool test_nvidia_bug(); 111 | 112 | protected: 113 | 114 | // heading is in degrees 115 | void add_block( 116 | const glm::vec3 &pos, 117 | const glm::vec3 &size, 118 | const float heading); 119 | 120 | void create_textures(const base::source_location &loc); 121 | void create_test_scene(); 122 | 123 | int get_perspective_block_bound(int row, float scale); 124 | 125 | int frustum_check(base::frame_context *fc); 126 | void create_frustum_planes(glm::vec4 *planes, const glm::mat4 &mvp); 127 | void load_and_init_shaders(const base::source_location &loc); 128 | void upload_blocks_to_gpu( 129 | const base::source_location &loc, 130 | base::frame_context *ctx); 131 | void bind_texture(int counter); 132 | 133 | protected: 134 | uint8 _var_cube_sizes_order[MAX_BLOCK_COUNT]; 135 | glm::ivec2 _cur_next_block; 136 | uint32 _cur_block; 137 | 138 | static const int NumTypes = 4; 139 | 140 | enum Flags { 141 | TypeMask = NumTypes-1, 142 | Visible = 0x04, 143 | }; 144 | 145 | std::vector _tms; //< transformation matrixes for blocks 146 | std::vector _bboxes; //< inverse transposed TM matrices 147 | std::vector _hws; //< half width for every block 148 | std::vector _flags; //< 149 | 150 | GLuint _prg; 151 | GLint _prg_tb_blocks; 152 | GLint _prg_ctx; 153 | GLint _prg_tb_pos; 154 | GLint _prg_tb_nor_uv; 155 | GLint _prg_tex; 156 | GLint _prg_tb_dc_data, _prg_basevert; 157 | 158 | GLuint _prg_tg; 159 | GLint _prg_tg_tex; 160 | 161 | GLuint _prg_mip; 162 | GLuint _prg_mip2; 163 | 164 | GLuint _tb_pos; 165 | GLuint _tb_nor_uv; 166 | GLuint _tb_tex_handles; 167 | 168 | GLuint _buffer_elem; 169 | GLuint _buffer_pos; 170 | GLuint _buffer_nor_uv; 171 | GLuint _buffer_tex_handles; 172 | 173 | std::vector _texs; 174 | std::vector _tex_handles; 175 | 176 | GLint _max_array_layers; 177 | 178 | glm::int2 * _vertices_base_ptr; 179 | glm::int2 * _norm_uv_base_ptr; 180 | ushort * _elements_base_ptr; 181 | 182 | struct dc_data 183 | { 184 | const glm::uint _nelements; 185 | const glm::uint _first_index; 186 | const glm::uint _nvertices; 187 | const glm::uint _first_vertex; 188 | 189 | dc_data( 190 | const glm::uint nelements, 191 | const glm::uint first_index, 192 | const glm::uint nvertices, 193 | const glm::uint first_vertex) 194 | : _nelements(nelements) 195 | , _first_index(first_index) 196 | , _nvertices(nvertices) 197 | , _first_vertex(first_vertex) 198 | {} 199 | }; 200 | 201 | std::vector _dc_data; 202 | 203 | enum BenchmarkMode 204 | { 205 | // no textures (depth prepass, shadow mapping) 206 | BenchNaive, 207 | BenchBaseInstance, 208 | BenchIndirect, 209 | BenchInstancing, 210 | BenchBaseVertex, 211 | }; 212 | 213 | enum TexturingMode 214 | { 215 | BenchTexNone, 216 | BenchTexNaive, // glBindTexture 217 | BenchTexArray, 218 | BenchTexBindless, 219 | BenchTexBindlessHandle, 220 | }; 221 | 222 | bool _use_vbo; 223 | bool _one_mesh; 224 | 225 | BenchmarkMode _bench_mode; 226 | TexturingMode _tex_mode; 227 | int _mesh_size_opt; 228 | int _mesh_size_x; 229 | int _mesh_size_y; 230 | int _mesh_size_z; 231 | int _tex_freq; 232 | 233 | benchmark * const _app; 234 | 235 | }; 236 | 237 | #endif // __ASYNC_VBO_TRANSFERS_SCENE_H__ 238 | -------------------------------------------------------------------------------- /src/scene_buildings.h: -------------------------------------------------------------------------------- 1 | #ifndef __SCENE_BUILDINGS_H__ 2 | #define __SCENE_BUILDINGS_H__ 3 | 4 | #include "base/types.h" 5 | #include "scene_i.h" 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace base { 12 | struct frame_context; 13 | class source_location; 14 | class app; 15 | } 16 | 17 | struct BuildingTileDCData{ 18 | glm::ivec2 _tile_pos; 19 | GLuint _blocks_vbo; 20 | GLuint _blocks_tb; 21 | uint32 _blocks_count; 22 | }; 23 | 24 | class scene_buildings: public scene_i 25 | { 26 | public: 27 | scene_buildings(); 28 | scene_buildings(base::app * app); 29 | ~scene_buildings(); 30 | 31 | virtual void init_gpu_stuff(const base::source_location &loc) override; 32 | virtual void post_gpu_init() override; 33 | virtual void update(base::frame_context * const ctx) override; 34 | virtual void gpu_draw(base::frame_context * const ctx) override; 35 | virtual const char* get_test_name(const int i) const override; 36 | 37 | void load_tile(glm::ivec2 pos); 38 | 39 | static bool send_test_data(); 40 | private: 41 | std::vector _tiles; 42 | unsigned _indices_vbo; 43 | unsigned _indices_tb; 44 | protected: 45 | base::app * _app; 46 | 47 | GLuint _prg; 48 | GLint _prg_tb_blocks; 49 | GLint _prg_tile_offset; 50 | GLint _prg_mvp; 51 | GLint _prg_total_count; 52 | }; 53 | 54 | #endif // __SCENE_BUILDINGS_H__ 55 | -------------------------------------------------------------------------------- /src/scene_grass.h: -------------------------------------------------------------------------------- 1 | #ifndef __ASYNC_VBO_TRANSFERS_SCENE_GRASS_H__ 2 | #define __ASYNC_VBO_TRANSFERS_SCENE_GRASS_H__ 3 | 4 | #include "scene_i.h" 5 | 6 | #include 7 | 8 | #include "base/types.h" 9 | 10 | #define MAX_GRASS_TILES 1024 11 | 12 | namespace base{ 13 | class app; 14 | } 15 | 16 | struct grass_data{ 17 | int _blades_per_tuft; 18 | int _blocks_per_row; 19 | float _tile_width; 20 | }; 21 | 22 | class scene_grass : 23 | public scene_i 24 | { 25 | protected: 26 | base::app * _app; 27 | 28 | GLuint _prg_grass; 29 | GLint _prg_grs_ctx; 30 | GLint _prg_grs_pos; 31 | GLint _prg_grs_tex; 32 | GLint _prg_grs_data; 33 | GLint _prg_grs_hmap; 34 | 35 | GLuint _prg_floor; 36 | GLint _prg_flr_ctx; 37 | GLint _prg_flr_pos; 38 | 39 | GLuint _prg_tg; 40 | GLint _prg_tg_tex; 41 | GLint _prg_tg_pos; 42 | 43 | GLuint _grass_tex; 44 | 45 | grass_data _grs_data; 46 | 47 | glm::vec2 _grass_tiles[MAX_GRASS_TILES]; 48 | GLuint _height_tex[MAX_GRASS_TILES]; 49 | 50 | GLuint _idx_buf_h; 51 | 52 | int * _idx_buf_i; 53 | ushort * _idx_buf_us; 54 | 55 | glm::vec3 _cam_pos; 56 | public: 57 | scene_grass(base::app * app); 58 | virtual ~scene_grass(); 59 | 60 | virtual void init_gpu_stuff(const base::source_location &loc) override; 61 | virtual void post_gpu_init() override; 62 | virtual void update(base::frame_context * const ctx) override; 63 | virtual void gpu_draw(base::frame_context * const ctx) override; 64 | virtual const char* get_test_name(const int i) const override; 65 | 66 | static bool send_test_data(); 67 | protected: 68 | void calculate_visible_tiles(int ntiles, float tile_size); 69 | void create_height_texs(); 70 | }; 71 | 72 | #endif 73 | 74 | -------------------------------------------------------------------------------- /src/scene_i.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 by Ladislav Hrabcak 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | #ifndef __DRAW_CALL_PERF_SCENE_I_H__ 25 | #define __DRAW_CALL_PERF_SCENE_I_H__ 26 | 27 | namespace base { 28 | class source_location; 29 | struct frame_context; 30 | } 31 | 32 | class scene_i 33 | { 34 | public: 35 | virtual void init_gpu_stuff(const base::source_location &loc) = 0; 36 | virtual void post_gpu_init() = 0; 37 | virtual void update(base::frame_context * const ctx) = 0; 38 | virtual void gpu_draw(base::frame_context * const ctx) = 0; 39 | virtual const char* get_test_name(const int i) const = 0; 40 | }; 41 | 42 | #endif // __DRAW_CALL_PERF_SCENE_I_H__ --------------------------------------------------------------------------------