├── .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