├── .gitignore ├── .gitmodules ├── .ide.vim ├── .makebg.sh ├── LICENSE ├── Makefile ├── README.md ├── dependency ├── miniz │ └── miniz.c ├── stb │ └── stb_image.h └── tinydir │ ├── .gitignore │ ├── .travis.yml │ ├── COPYING │ ├── README.md │ ├── THANKS │ ├── samples │ ├── .gitignore │ ├── CMakeLists.txt │ ├── file_open_sample.c │ ├── interactive_sample.c │ ├── iterate_sample.c │ └── random_access_sample.c │ └── tinydir.h ├── res ├── Bricks_ao.dds ├── Bricks_n.dds ├── CmftStudio_iem.dds ├── CmftStudio_pmrem.dds ├── CmftStudio_skybox.dds ├── DroidSans.ttf ├── DroidSansMono.ttf ├── LoadingScreen.dds ├── Sphere.bin ├── Sphere.h ├── Stripes_s.dds ├── SunIcon.dds ├── SunIcon.xcf ├── cmftStudio_cover.jpg ├── cmftstudio_icon.ico ├── cmftstudio_icon.png ├── gen_res_headers.sh ├── icon │ ├── afxres.h │ ├── cmftStudio.aps │ ├── cmftStudio.rc │ ├── icon_small.ico │ └── resource.h └── makefile ├── runtime └── cmftstudio.conf ├── screenshots ├── cmftStudio_alpha1.jpg ├── cmftStudio_osx0.jpg ├── cmftStudio_osx1.jpg ├── cmftStudio_small.jpg ├── cmftStudio_spheres0.jpg ├── cmftStudio_spheres1.jpg ├── cmftStudio_win3.jpg ├── cmftStudio_win4.jpg └── cmftStudio_win5.jpg ├── scripts └── main.lua ├── src ├── assets.cpp ├── assets.h ├── assets_res.h ├── backgroundjobs.cpp ├── backgroundjobs.h ├── build │ ├── Makefile │ ├── cmftStudioApp.cpp │ ├── cmftStudioApp_static_resources.cpp │ └── gen_build_headers.sh ├── cmftstudio.cpp ├── common │ ├── allocator.cpp │ ├── allocator.h │ ├── appconfig.h │ ├── cmft.h │ ├── common.h │ ├── config.cpp │ ├── config.h │ ├── datastructures.h │ ├── globals.cpp │ ├── globals.h │ ├── imgui.h │ ├── memblock.h │ ├── miniz.h │ ├── stb_image.h │ ├── timer.cpp │ ├── timer.h │ ├── tinystl.h │ └── utils.h ├── context.cpp ├── context.h ├── context_res.h ├── eventstate.cpp ├── eventstate.h ├── geometry │ ├── geometry.cpp │ ├── geometry.h │ ├── loader_bgfxbin.h │ ├── loader_obj.h │ ├── loadermanager.cpp │ ├── loadermanager.h │ ├── loaders.h │ ├── objtobin.cpp │ └── objtobin.h ├── gui.cpp ├── gui.h ├── gui_res.h ├── guimanager.cpp ├── guimanager.h ├── inflatedeflate.cpp ├── inflatedeflate.h ├── mouse.h ├── project.cpp ├── project.h ├── renderpipeline.cpp ├── renderpipeline.h ├── res │ ├── brick_ao.h │ ├── brick_n.h │ ├── droidsans.h │ ├── droidsansmono.h │ ├── loading_screen.h │ ├── logo_iem.h │ ├── logo_pmrem.h │ ├── logo_skybox.h │ ├── sphere.h │ ├── sphereSurfaceTex.h │ ├── stripes_s.h │ └── sun_icon.h ├── settings.h ├── shaders │ ├── fs_blur.sc │ ├── fs_bright.sc │ ├── fs_color.sc │ ├── fs_cubemap_tonemap.sc │ ├── fs_equals.sc │ ├── fs_fxaa.sc │ ├── fs_image.sc │ ├── fs_image_re8.sc │ ├── fs_latlong.sc │ ├── fs_lum.sc │ ├── fs_lumavg.sc │ ├── fs_lumdownscale.sc │ ├── fs_mesh.sc │ ├── fs_mesh.shdr │ ├── fs_mesh_normal.sc │ ├── fs_mesh_normal_rgbe8.sc │ ├── fs_mesh_normal_rgbe8_trans.sc │ ├── fs_mesh_rgbe8.sc │ ├── fs_mesh_rgbe8_trans.sc │ ├── fs_overlay.sc │ ├── fs_skybox.sc │ ├── fs_skybox_trans.sc │ ├── fs_sun_icon.sc │ ├── fs_tex.sc │ ├── fs_tonemap.sc │ ├── fs_wireframe.sc │ ├── fxaa3_11.h │ ├── gen_headers.sh │ ├── headers │ │ ├── fs_blur.bin.h │ │ ├── fs_bright.bin.h │ │ ├── fs_color.bin.h │ │ ├── fs_cubemap_tonemap.bin.h │ │ ├── fs_equals.bin.h │ │ ├── fs_fxaa.bin.h │ │ ├── fs_image.bin.h │ │ ├── fs_image_re8.bin.h │ │ ├── fs_latlong.bin.h │ │ ├── fs_lum.bin.h │ │ ├── fs_lumavg.bin.h │ │ ├── fs_lumdownscale.bin.h │ │ ├── fs_mesh.bin.h │ │ ├── fs_mesh_normal.bin.h │ │ ├── fs_mesh_normal_rgbe8.bin.h │ │ ├── fs_mesh_normal_rgbe8_trans.bin.h │ │ ├── fs_mesh_rgbe8.bin.h │ │ ├── fs_mesh_rgbe8_trans.bin.h │ │ ├── fs_overlay.bin.h │ │ ├── fs_skybox.bin.h │ │ ├── fs_skybox_trans.bin.h │ │ ├── fs_sun_icon.bin.h │ │ ├── fs_tex.bin.h │ │ ├── fs_tonemap.bin.h │ │ ├── fs_wireframe.bin.h │ │ ├── shaders.h │ │ ├── vs_blur.bin.h │ │ ├── vs_material.bin.h │ │ ├── vs_material_normal.bin.h │ │ ├── vs_mesh.bin.h │ │ ├── vs_mesh_color.bin.h │ │ ├── vs_mesh_normal.bin.h │ │ ├── vs_mesh_tex.bin.h │ │ ├── vs_plain.bin.h │ │ ├── vs_skybox.bin.h │ │ ├── vs_texcoord.bin.h │ │ └── vs_tonemap.bin.h │ ├── makefile │ ├── makefile_headers │ ├── shader.shdr │ ├── tonemap.shdr │ ├── uniforms.shdr │ ├── utils.shdr │ ├── varying.def.sc │ ├── vs_blur.sc │ ├── vs_material.sc │ ├── vs_material_normal.sc │ ├── vs_mesh.sc │ ├── vs_mesh.shdr │ ├── vs_mesh_color.sc │ ├── vs_mesh_normal.sc │ ├── vs_mesh_tex.sc │ ├── vs_plain.sc │ ├── vs_skybox.sc │ ├── vs_texcoord.sc │ └── vs_tonemap.sc ├── staticres.cpp ├── staticres.h └── staticres_res.h └── tools ├── bin └── windows │ └── rawcompress.exe └── src └── rawcompress.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | _build/ 2 | _projects/ 3 | *.swp 4 | .svn/ 5 | .DS_Store 6 | .vim 7 | tags 8 | make.log 9 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "dependency/bx"] 2 | path = dependency/bx 3 | url = https://github.com/dariomanesku/bx 4 | [submodule "dependency/bgfx"] 5 | path = dependency/bgfx 6 | url = https://github.com/dariomanesku/bgfx 7 | [submodule "dependency/cmft"] 8 | path = dependency/cmft 9 | url = https://github.com/dariomanesku/cmft 10 | [submodule "dependency/dm"] 11 | path = dependency/dm 12 | url = https://github.com/dariomanesku/dm 13 | -------------------------------------------------------------------------------- /.ide.vim: -------------------------------------------------------------------------------- 1 | " 2 | " Copyright 2015 Dario Manesku. All rights reserved. 3 | " License: http://www.opensource.org/licenses/BSD-2-Clause 4 | " 5 | 6 | " Run vim as 'vim --servername VIM'. 7 | 8 | if has("unix") 9 | set makeprg=make 10 | 11 | let s:proj_root = expand(":p:h") 12 | let s:makebg_file = s:proj_root."/.makebg.sh" 13 | let s:log_file = s:proj_root."/make.log" 14 | 15 | let s:exec_action = "!../_build/linux64_gcc/bin/cmftStudioDebug" 16 | let s:gdb_action = "!gdb -x ".s:proj_root."/.gdbinit"." --args ../_build/linux64_gcc/bin/cmftStudioDebug" 17 | 18 | let s:make_action = "linux-debug64" 19 | 20 | function! SetDebug() 21 | let s:make_action = "linux-debug64" 22 | let s:exec_action = "!../_build/linux64_gcc/bin/cmftStudioDebug" 23 | endfunc 24 | command! -nargs=0 SetDebug :call SetDebug() 25 | 26 | function! SetRelease() 27 | let s:make_action = "linux-release64" 28 | let s:exec_action = "!../_build/linux64_gcc/bin/cmftStudioRelease" 29 | endfunc 30 | command! -nargs=0 SetRelease :call SetRelease() 31 | 32 | function! Build() 33 | let s:make_command = "make ".s:proj_root." ".s:make_action 34 | let s:build_action = "!".s:makebg_file." ".v:servername." \"".s:make_command."\" ".s:log_file 35 | let curr_dir = getcwd() 36 | exec 'cd' s:proj_root 37 | exec s:build_action 38 | exec 'cd' curr_dir 39 | endfunc 40 | 41 | function! Execute() 42 | let s:runtime_dir = s:proj_root."/runtime" 43 | let curr_dir = getcwd() 44 | exec 'cd' s:runtime_dir 45 | exec s:exec_action 46 | exec 'cd' curr_dir 47 | endfunc 48 | 49 | function! DebugGdb() 50 | let s:runtime_dir = s:proj_root."/runtime" 51 | let curr_dir = getcwd() 52 | exec 'cd' s:runtime_dir 53 | exec s:gdb_action 54 | exec 'cd' curr_dir 55 | endfunc 56 | 57 | nmap ,rr :call Build() 58 | nmap ,ee :call Execute() 59 | nmap ,gdb :call DebugGdb() 60 | 61 | endif 62 | -------------------------------------------------------------------------------- /.makebg.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2015 Dario Manesku. All rights reserved. 4 | # License: http://www.opensource.org/licenses/BSD-2-Clause 5 | # 6 | 7 | # Use as: .makebg.sh VIMSERVERNAME MAKEPRG LOGFILE TEMPFILE 8 | 9 | server="${1:-VIM}" 10 | makeprg="${2:-make}" 11 | logfile="${3:-make.log}" 12 | tempfile="${4:-.make.tmp}" 13 | 14 | { 15 | echo -n > $logfile 16 | echo '-----------------------------------------' >> "$tempfile" 17 | date >> "$tempfile" 18 | echo '-----------------------------------------' >> "$tempfile" 19 | 20 | # sed removes some words to prevent vim from misparsing a filename 21 | exec 3<> $tempfile 22 | $makeprg >&3 2>&1 23 | success=$? 24 | exec 3>&1 25 | sed -i 's/In file included from //' $tempfile 26 | 27 | cat "$logfile" >> "$tempfile" 28 | mv "$tempfile" "$logfile"; 29 | vim --servername "$server" --remote-send ":cgetfile $logfile" ; 30 | 31 | if [ $success -eq 0 ]; then 32 | vim --servername "$server" --remote-send ":redraw | :echo \"Build successful.\"" ; 33 | else 34 | vim --servername "$server" --remote-send ":redraw | :echo \"Build ERROR!\"" ; 35 | fi 36 | 37 | } & 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014-2015 Dario Manesku. All rights reserved. 2 | 3 | https://github.com/dariomanesku/cmftstudio 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR 16 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 17 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 18 | SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 20 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 23 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 24 | OF THE POSSIBILITY OF SUCH DAMAGE. 25 | 26 | https://github.com/dariomanesku/cmftstudio/blob/master/LICENSE 27 | -------------------------------------------------------------------------------- /dependency/tinydir/.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | 4 | # Libraries 5 | *.lib 6 | *.a 7 | 8 | # Shared objects (inc. Windows DLLs) 9 | *.dll 10 | *.so 11 | *.so.* 12 | *.dylib 13 | 14 | # Executables 15 | *.exe 16 | *.out 17 | *.app 18 | interactive_sample 19 | iterate_sample 20 | random_access_sample 21 | 22 | # CMake 23 | CMakeFiles/ 24 | CMakeCache.txt 25 | *.dir/ 26 | cmake_install.cmake 27 | 28 | # Visual Studio 29 | Debug/ 30 | Win32/ 31 | *.opensdf 32 | *.sdf 33 | *.suo 34 | *.vcxproj.user 35 | *.vcxproj 36 | *.vcxproj.filters 37 | *.sln 38 | -------------------------------------------------------------------------------- /dependency/tinydir/.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | compiler: 4 | - gcc 5 | - clang 6 | 7 | before_install: 8 | - sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y 9 | - sudo apt-get update -qq 10 | 11 | install: 12 | - if [ "$CC" = "gcc" ]; then sudo apt-get install -qq gcc-4.8; fi 13 | 14 | before_script: 15 | # force newer gcc version 16 | - if [ "$CC" = "gcc" ]; then export CC="gcc-4.8"; fi 17 | # show which tests failed 18 | - export CTEST_OUTPUT_ON_FAILURE=1 19 | # pull all sub modules recursively 20 | - git submodule update --init --recursive 21 | 22 | script: 23 | - cmake samples 24 | - make -j2 25 | -------------------------------------------------------------------------------- /dependency/tinydir/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Cong Xu 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 17 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 20 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /dependency/tinydir/README.md: -------------------------------------------------------------------------------- 1 | TinyDir 2 | ======= 3 | [![Build Status](https://travis-ci.org/cxong/tinydir.svg?branch=master)](https://travis-ci.org/cxong/tinydir)[![Project Stats](https://www.openhub.net/p/tinydir/widgets/project_thin_badge.gif)](https://www.openhub.net/p/tinydir) 4 | 5 | Lightweight, portable and easy to integrate C directory and file reader. TinyDir wraps dirent for POSIX and FindFirstFile for Windows. 6 | 7 | Example 8 | ======= 9 | 10 | There are two methods. Error checking omitted: 11 | 12 | ```C 13 | tinydir_dir dir; 14 | tinydir_open(&dir, "/path/to/dir"); 15 | 16 | while (dir.has_next) 17 | { 18 | tinydir_file file; 19 | tinydir_readfile(&dir, &file); 20 | 21 | printf("%s", file.name); 22 | if (file.is_dir) 23 | { 24 | printf("/"); 25 | } 26 | printf("\n"); 27 | 28 | tinydir_next(&dir); 29 | } 30 | 31 | tinydir_close(&dir); 32 | ``` 33 | 34 | ```C 35 | tinydir_dir dir; 36 | int i; 37 | tinydir_open_sorted(&dir, "/path/to/dir"); 38 | 39 | for (i = 0; i < dir.n_files; i++) 40 | { 41 | tinydir_file file; 42 | tinydir_readfile_n(&dir, &file, i); 43 | 44 | printf("%s", file.name); 45 | if (file.is_dir) 46 | { 47 | printf("/"); 48 | } 49 | printf("\n"); 50 | } 51 | 52 | tinydir_close(&dir); 53 | ``` 54 | 55 | See the `/samples` folder for more examples, including an interactive command-line directory navigator. 56 | 57 | Language 58 | ======== 59 | 60 | ANSI C, or C90. 61 | 62 | Platforms 63 | ========= 64 | 65 | POSIX and Windows supported. Open to the possibility of supporting other platforms. 66 | 67 | Links 68 | ===== 69 | Available Archlinux AUR package : https://aur.archlinux.org/packages/tinydir-git/ 70 | 71 | License 72 | ======= 73 | 74 | Simplified BSD. 75 | 76 | Known Limitations 77 | ================= 78 | 79 | - Not threadsafe 80 | - Limited path and filename sizes 81 | - No wide char support 82 | -------------------------------------------------------------------------------- /dependency/tinydir/THANKS: -------------------------------------------------------------------------------- 1 | Thanks to tinyxml2 for the example of an easy to use, lightweight library. -------------------------------------------------------------------------------- /dependency/tinydir/samples/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /dependency/tinydir/samples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6 FATAL_ERROR) 2 | cmake_policy(VERSION 2.6) 3 | 4 | project(tinydir C) 5 | 6 | INCLUDE_DIRECTORIES(..) 7 | 8 | ################################ 9 | # Add definitions 10 | 11 | if(MSVC) 12 | add_definitions(-W4 -WX) 13 | else() 14 | add_definitions(-fsigned-char -Wall -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Winline -Werror) 15 | endif() 16 | 17 | ################################ 18 | # Add targets 19 | add_executable(file_open_sample file_open_sample.c) 20 | add_executable(iterate_sample iterate_sample.c) 21 | add_executable(random_access_sample random_access_sample.c) 22 | add_executable(interactive_sample interactive_sample.c) 23 | -------------------------------------------------------------------------------- /dependency/tinydir/samples/file_open_sample.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | tinydir_file file; 7 | if (argc != 2) 8 | { 9 | fprintf(stderr, "Usage: test filename\n"); 10 | return 1; 11 | } 12 | if (tinydir_file_open(&file, argv[1]) == -1) 13 | { 14 | perror("Error opening file"); 15 | return 1; 16 | } 17 | printf("Path: %s\nName: %s\nExtension: %s\nIs dir? %s\nIs regular file? %s\n", 18 | file.path, file.name, file.extension, 19 | file.is_dir?"yes":"no", file.is_reg?"yes":"no"); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /dependency/tinydir/samples/interactive_sample.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) 5 | { 6 | tinydir_dir dir; 7 | if (tinydir_open_sorted(&dir, ".") == -1) 8 | { 9 | perror("Error opening file"); 10 | goto bail; 11 | } 12 | 13 | for (;;) 14 | { 15 | size_t i; 16 | char input[256]; 17 | for (i = 0; i < dir.n_files; i++) 18 | { 19 | tinydir_file file; 20 | if (tinydir_readfile_n(&dir, &file, i) == -1) 21 | { 22 | perror("Error getting file"); 23 | goto bail; 24 | } 25 | 26 | if (file.is_dir) 27 | { 28 | printf("[%zu] ", i); 29 | } 30 | printf("%s", file.name); 31 | if (file.is_dir) 32 | { 33 | printf("/"); 34 | } 35 | printf("\n"); 36 | } 37 | printf("?"); 38 | 39 | if (fgets(input, 256, stdin) == NULL) 40 | { 41 | break; 42 | } 43 | else 44 | { 45 | int choice = atoi(input); 46 | if (choice >= 0 && (size_t)choice < dir.n_files) 47 | { 48 | if (tinydir_open_subdir_n(&dir, choice) == -1) 49 | { 50 | perror("Error opening subdirectory"); 51 | goto bail; 52 | } 53 | } 54 | } 55 | } 56 | 57 | bail: 58 | tinydir_close(&dir); 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /dependency/tinydir/samples/iterate_sample.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) 5 | { 6 | tinydir_dir dir; 7 | if (tinydir_open(&dir, ".") == -1) 8 | { 9 | perror("Error opening file"); 10 | goto bail; 11 | } 12 | 13 | while (dir.has_next) 14 | { 15 | tinydir_file file; 16 | if (tinydir_readfile(&dir, &file) == -1) 17 | { 18 | perror("Error getting file"); 19 | goto bail; 20 | } 21 | 22 | printf("%s", file.name); 23 | if (file.is_dir) 24 | { 25 | printf("/"); 26 | } 27 | printf("\n"); 28 | 29 | tinydir_next(&dir); 30 | } 31 | 32 | bail: 33 | tinydir_close(&dir); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /dependency/tinydir/samples/random_access_sample.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) 5 | { 6 | tinydir_dir dir; 7 | size_t i; 8 | if (tinydir_open_sorted(&dir, ".") == -1) 9 | { 10 | perror("Error opening file"); 11 | goto bail; 12 | } 13 | 14 | for (i = 0; i < dir.n_files; i++) 15 | { 16 | tinydir_file file; 17 | if (tinydir_readfile_n(&dir, &file, i) == -1) 18 | { 19 | perror("Error getting file"); 20 | goto bail; 21 | } 22 | 23 | printf("%s", file.name); 24 | if (file.is_dir) 25 | { 26 | printf("/"); 27 | } 28 | printf("\n"); 29 | } 30 | 31 | bail: 32 | tinydir_close(&dir); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /res/Bricks_ao.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/res/Bricks_ao.dds -------------------------------------------------------------------------------- /res/Bricks_n.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/res/Bricks_n.dds -------------------------------------------------------------------------------- /res/CmftStudio_iem.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/res/CmftStudio_iem.dds -------------------------------------------------------------------------------- /res/CmftStudio_pmrem.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/res/CmftStudio_pmrem.dds -------------------------------------------------------------------------------- /res/CmftStudio_skybox.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/res/CmftStudio_skybox.dds -------------------------------------------------------------------------------- /res/DroidSans.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/res/DroidSans.ttf -------------------------------------------------------------------------------- /res/DroidSansMono.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/res/DroidSansMono.ttf -------------------------------------------------------------------------------- /res/LoadingScreen.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/res/LoadingScreen.dds -------------------------------------------------------------------------------- /res/Sphere.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/res/Sphere.bin -------------------------------------------------------------------------------- /res/Stripes_s.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/res/Stripes_s.dds -------------------------------------------------------------------------------- /res/SunIcon.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/res/SunIcon.dds -------------------------------------------------------------------------------- /res/SunIcon.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/res/SunIcon.xcf -------------------------------------------------------------------------------- /res/cmftStudio_cover.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/res/cmftStudio_cover.jpg -------------------------------------------------------------------------------- /res/cmftstudio_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/res/cmftstudio_icon.ico -------------------------------------------------------------------------------- /res/cmftstudio_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/res/cmftstudio_icon.png -------------------------------------------------------------------------------- /res/gen_res_headers.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2014-2015 Dario Manesku. All rights reserved. 4 | # License: http://www.opensource.org/licenses/BSD-2-Clause 5 | # 6 | 7 | if [ $(uname -o) == "Darwin" ]; then 8 | OS="darwin" 9 | elif [ $(uname -o) == "Linux" ]; then 10 | OS="linux" 11 | else 12 | OS="windows" 13 | fi 14 | 15 | BXDIR=../../bx 16 | BIN2C=$BXDIR/tools/bin/$OS/bin2c 17 | RAWCOMPRESS=../tools/bin/$OS/rawcompress 18 | TMPFN=".tmp_file_6029bf40ad3811e4ab270800200c9a66" 19 | OUTDIR=../src/res 20 | 21 | # $1 - input 22 | # $2 - output 23 | # $3 - name 24 | compressedToC() 25 | { 26 | echo Compressing $1 ... 27 | $($RAWCOMPRESS -i $1 -o $TMPFN) 28 | echo Creating $OUTDIR/$2 \($3\) ... 29 | $($BIN2C -f $TMPFN -o $OUTDIR/$2 -n $3) 30 | $(rm $TMPFN) 31 | echo Done. 32 | } 33 | 34 | # $1 - input 35 | # $2 - output 36 | # $3 - name 37 | rawToC() 38 | { 39 | echo Creating $OUTDIR/$2 \($3\) ... 40 | $($BIN2C -f $1 -o $OUTDIR/$2 -n $3) 41 | echo Done. 42 | } 43 | 44 | # Uncompressed: 45 | rawToC Sphere.bin sphere.h sc_sphereMesh 46 | 47 | # Cubemaps: 48 | compressedToC CmftStudio_skybox.dds logo_skybox.h sc_logoSkyboxCompressed 49 | compressedToC CmftStudio_pmrem.dds logo_pmrem.h sc_logoPmremCompressed 50 | compressedToC CmftStudio_iem.dds logo_iem.h sc_logoIemCompressed 51 | 52 | # Textures: 53 | compressedToC LoadingScreen.dds loading_screen.h sc_loadingScreenCompressed 54 | compressedToC SunIcon.dds sunicon.h sc_sunIconCompressed 55 | compressedToC Stripes_s.dds stripes_s.h sc_stripesSCompressed 56 | compressedToC Bricks_n.dds brick_n.h sc_brickNCompressed 57 | compressedToC Bricks_ao.dds brick_ao.h sc_brickAoCompressed 58 | 59 | # Fonts: 60 | compressedToC DroidSans.ttf droidsans.h sc_droidSansCompressed 61 | compressedToC DroidSansMono.ttf droidsansmono.h sc_droidSansMonoCompressed 62 | -------------------------------------------------------------------------------- /res/icon/afxres.h: -------------------------------------------------------------------------------- 1 | #ifndef _AFXRES_H 2 | #define _AFXRES_H 3 | #if __GNUC__ >= 3 4 | #pragma GCC system_header 5 | #endif 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #ifndef _WINDOWS_H 12 | #include 13 | #endif 14 | 15 | /* IDC_STATIC is documented in winuser.h, but not defined. */ 16 | #ifndef IDC_STATIC 17 | #define IDC_STATIC (-1) 18 | #endif 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | #endif 24 | -------------------------------------------------------------------------------- /res/icon/cmftStudio.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/res/icon/cmftStudio.aps -------------------------------------------------------------------------------- /res/icon/cmftStudio.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/res/icon/cmftStudio.rc -------------------------------------------------------------------------------- /res/icon/icon_small.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/res/icon/icon_small.ico -------------------------------------------------------------------------------- /res/icon/resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/res/icon/resource.h -------------------------------------------------------------------------------- /res/makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | # License: http://www.opensource.org/licenses/BSD-2-Clause 4 | # 5 | 6 | .PHONY: all 7 | all: 8 | @ gen_res_headers.sh 9 | 10 | -------------------------------------------------------------------------------- /runtime/cmftstudio.conf: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | # License: http://www.opensource.org/licenses/BSD-2-Clause 4 | # 5 | 6 | # Options: 7 | # Renderer = [dx9,directx9,dx11,directx11,ogl,opengl] # Windows only. 8 | # WindowSize = [width x height] # Window size at startup. 9 | # Memory = [1.0-7.0]GB # Recommended 2.0GB or more on a 64bit system. 10 | # StartupProject = ["path_to_csp_file"] # *.csp - cmftStudio project file. 11 | # DefaultLoadPath = ["path"] # Default load path. 12 | # DefaultSavePath = ["path"] # Default save path. 13 | 14 | Renderer = ogl 15 | WindowSize = 1920x1027 16 | Memory = 1.5GB 17 | StartupProject = "SampleProject0.csp" 18 | DefaultLoadPath = "." 19 | DefaultSavePath = "." 20 | -------------------------------------------------------------------------------- /screenshots/cmftStudio_alpha1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/screenshots/cmftStudio_alpha1.jpg -------------------------------------------------------------------------------- /screenshots/cmftStudio_osx0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/screenshots/cmftStudio_osx0.jpg -------------------------------------------------------------------------------- /screenshots/cmftStudio_osx1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/screenshots/cmftStudio_osx1.jpg -------------------------------------------------------------------------------- /screenshots/cmftStudio_small.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/screenshots/cmftStudio_small.jpg -------------------------------------------------------------------------------- /screenshots/cmftStudio_spheres0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/screenshots/cmftStudio_spheres0.jpg -------------------------------------------------------------------------------- /screenshots/cmftStudio_spheres1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/screenshots/cmftStudio_spheres1.jpg -------------------------------------------------------------------------------- /screenshots/cmftStudio_win3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/screenshots/cmftStudio_win3.jpg -------------------------------------------------------------------------------- /screenshots/cmftStudio_win4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/screenshots/cmftStudio_win4.jpg -------------------------------------------------------------------------------- /screenshots/cmftStudio_win5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/screenshots/cmftStudio_win5.jpg -------------------------------------------------------------------------------- /src/assets.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_ASSETS_H_HEADER_GUARD 7 | #define CMFTSTUDIO_ASSETS_H_HEADER_GUARD 8 | 9 | #include "context.h" 10 | 11 | struct Assets 12 | { 13 | struct Textures 14 | { 15 | enum Enum 16 | { 17 | #define TEX_DESC(_name, _path) _name, 18 | #include "assets_res.h" 19 | 20 | Count, 21 | Invalid = UINT16_MAX 22 | }; 23 | }; 24 | 25 | struct Materials 26 | { 27 | enum Enum 28 | { 29 | #define MAT_DESC(_name \ 30 | , _d00, _d01, _d02, _d03 \ 31 | , _d10, _d11, _d12, _d13 \ 32 | , _d20, _d21, _d22, _d23 \ 33 | , _d30, _d31, _d32, _d33 \ 34 | , _d40, _d41, _d42, _d43 \ 35 | , _d50, _d51, _d52, _d53 \ 36 | , _d60, _d61, _d62, _d63 \ 37 | , _d70, _d71, _d72, _d73 \ 38 | , _d80, _d81, _d82, _d83 \ 39 | , _d90, _d91, _d92, _d93 \ 40 | , _texAlbedo \ 41 | , _texNormal \ 42 | , _texSurface \ 43 | , _texReflectivity \ 44 | , _texAmbientOcclusion \ 45 | , _texEmissive \ 46 | ) \ 47 | _name , 48 | 49 | #include "assets_res.h" 50 | 51 | Count, 52 | Invalid = UINT16_MAX 53 | }; 54 | }; 55 | 56 | struct Meshes 57 | { 58 | enum Enum 59 | { 60 | #define MESH_DESC(_name, _path) _name, 61 | #include "assets_res.h" 62 | 63 | Count, 64 | Invalid = UINT16_MAX 65 | }; 66 | }; 67 | 68 | struct Environments 69 | { 70 | enum Enum 71 | { 72 | #define ENVMAP_DESC(_name, _skybox, _pmrem, _iem) _name, 73 | #include "assets_res.h" 74 | 75 | Count, 76 | }; 77 | }; 78 | 79 | struct MeshInstances 80 | { 81 | enum Enum 82 | { 83 | #define INST_DESC(_name, _mesh, _mat0, _mat1, _mat2, _scale, _posx, _posy, _posz, _rotx, _roty, _rotz) _name, 84 | #include "assets_res.h" 85 | 86 | Count, 87 | }; 88 | }; 89 | 90 | static void loadTextures(); 91 | static void loadMaterials(); 92 | static void loadMeshes(); 93 | static void loadEnvironments(); 94 | static void loadResources(); // Loads all at once. 95 | 96 | static cs::TextureHandle get(Textures::Enum _texture); 97 | static cs::MaterialHandle get(Materials::Enum _material); 98 | static cs::MeshHandle get(Meshes::Enum _mesh); 99 | static cs::EnvHandle get(Environments::Enum _env); 100 | 101 | static void getAll(cs::TextureList& _textures); 102 | static void getAll(cs::MaterialList& _materials); 103 | static void getAll(cs::MeshList& _meshes); 104 | static void getAll(cs::EnvList& _environments); 105 | 106 | static void getAll(cs::MeshInstanceList& _meshInstances); 107 | 108 | static void releaseTextures(); 109 | static void releaseMaterials(); 110 | static void releaseMeshes(); 111 | static void releaseEnvironments(); 112 | static void releaseResources(); // Release all at once. 113 | }; 114 | 115 | #endif // CMFTSTUDIO_ASSETS_H_HEADER_GUARD 116 | 117 | /* vim: set sw=4 ts=4 expandtab: */ 118 | -------------------------------------------------------------------------------- /src/backgroundjobs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_BACKGROUNDJOBS_H_HEADER_GUARD 7 | #define CMFTSTUDIO_BACKGROUNDJOBS_H_HEADER_GUARD 8 | 9 | #include "common/common.h" 10 | #include 11 | 12 | #include "guimanager.h" // imguiEnqueueStatusMessage() 13 | #include "context.h" // cs::*List, cs::MeshHandle 14 | #include "settings.h" // Settings 15 | #include // DM_PATH_LEN 16 | 17 | struct ThreadStatus 18 | { 19 | enum Enum 20 | { 21 | Idle = 0x00, 22 | Started = 0x01, 23 | Completed = 0x02, 24 | Halted = 0x04, 25 | 26 | ExitSuccess = 0x10, 27 | ExitFailure = 0x20, 28 | }; 29 | }; 30 | 31 | static inline bool threadStatus(ThreadStatus::Enum _state, uint8_t& _states) 32 | { 33 | if (_states & _state) 34 | { 35 | _states ^= _state; 36 | return true; 37 | } 38 | 39 | return false; 40 | } 41 | 42 | // Project save. 43 | //----- 44 | 45 | struct ProjectSaveThreadParams 46 | { 47 | void init() 48 | { 49 | m_stackAlloc = NULL; 50 | m_compressionLevel = 6; 51 | m_threadStatus = ThreadStatus::Idle; 52 | m_path[0] = '\0'; 53 | m_name[0] = '\0'; 54 | 55 | const uint32_t size = cs::MaterialList::sizeFor(CS_MAX_MATERIALS) 56 | + cs::EnvList::sizeFor(CS_MAX_ENVIRONMENTS) 57 | + cs::MeshInstanceList::sizeFor(CS_MAX_MESHINSTANCES); 58 | m_memBlock = DM_ALLOC(dm::staticAlloc, size); 59 | 60 | void* ptr = m_memBlock; 61 | ptr = m_materialList.init(CS_MAX_MATERIALS, ptr, dm::staticAlloc); 62 | ptr = m_envList.init(CS_MAX_ENVIRONMENTS, ptr, dm::staticAlloc); 63 | ptr = m_meshInstList.init(CS_MAX_MESHINSTANCES, ptr, dm::staticAlloc); 64 | } 65 | 66 | void releaseAll() 67 | { 68 | listRemoveReleaseAll(m_materialList); 69 | listRemoveReleaseAll(m_envList); 70 | listRemoveReleaseAll(m_meshInstList); 71 | } 72 | 73 | void destroy() 74 | { 75 | m_materialList.destroy(); 76 | m_envList.destroy(); 77 | m_meshInstList.destroy(); 78 | DM_FREE(dm::staticAlloc, m_memBlock); 79 | } 80 | 81 | Settings m_settings; 82 | dm::StackAllocatorI* m_stackAlloc; 83 | int32_t m_compressionLevel; 84 | uint8_t m_threadStatus; 85 | char m_path[DM_PATH_LEN]; 86 | char m_name[128]; 87 | void* m_memBlock; 88 | cs::MaterialList m_materialList; 89 | cs::EnvList m_envList; 90 | cs::MeshInstanceList m_meshInstList; 91 | }; 92 | 93 | int32_t projectSaveFunc(void* _projectSaveThreadParams); 94 | 95 | // Project load. 96 | //----- 97 | 98 | struct ProjectLoadThreadParams 99 | { 100 | void init() 101 | { 102 | m_stackAlloc = NULL; 103 | m_threadStatus = ThreadStatus::Idle; 104 | m_path[0] = '\0'; 105 | m_name[0] = '\0'; 106 | 107 | const uint32_t size = cs::TextureList::sizeFor(CS_MAX_TEXTURES) 108 | + cs::MaterialList::sizeFor(CS_MAX_MATERIALS) 109 | + cs::EnvList::sizeFor(CS_MAX_ENVIRONMENTS) 110 | + cs::MeshInstanceList::sizeFor(CS_MAX_MESHINSTANCES); 111 | m_memBlock = DM_ALLOC(dm::staticAlloc, size); 112 | 113 | void* ptr = m_memBlock; 114 | ptr = m_textureList.init(CS_MAX_TEXTURES, ptr, dm::staticAlloc); 115 | ptr = m_materialList.init(CS_MAX_MATERIALS, ptr, dm::staticAlloc); 116 | ptr = m_envList.init(CS_MAX_ENVIRONMENTS, ptr, dm::staticAlloc); 117 | ptr = m_meshInstList.init(CS_MAX_MESHINSTANCES, ptr, dm::staticAlloc); 118 | } 119 | 120 | void reset() 121 | { 122 | m_textureList.reset(); 123 | m_materialList.reset(); 124 | m_envList.reset(); 125 | m_meshInstList.removeAll(); 126 | } 127 | 128 | void destroy() 129 | { 130 | m_textureList.destroy(); 131 | m_materialList.destroy(); 132 | m_envList.destroy(); 133 | m_meshInstList.destroy(); 134 | DM_FREE(dm::staticAlloc, m_memBlock); 135 | } 136 | 137 | Settings m_settings; 138 | dm::StackAllocatorI* m_stackAlloc; 139 | uint8_t m_threadStatus; 140 | char m_path[DM_PATH_LEN]; 141 | char m_name[128]; 142 | void* m_memBlock; 143 | cs::TextureList m_textureList; 144 | cs::MaterialList m_materialList; 145 | cs::EnvList m_envList; 146 | cs::MeshInstanceList m_meshInstList; 147 | }; 148 | 149 | int32_t projectLoadFunc(void* _projectLoadThreadParams); 150 | 151 | // Mesh format conversion. 152 | //----- 153 | 154 | struct ModelLoadThreadParams 155 | { 156 | ModelLoadThreadParams() 157 | { 158 | m_mesh = cs::MeshHandle::invalid(); 159 | m_stackAlloc = NULL; 160 | m_threadStatus = ThreadStatus::Idle; 161 | m_filePath[0] = '\0'; 162 | m_fileName[0] = '\0'; 163 | } 164 | 165 | cs::MeshHandle m_mesh; 166 | dm::StackAllocatorI* m_stackAlloc; 167 | uint8_t m_threadStatus; 168 | char m_filePath[DM_PATH_LEN]; 169 | char m_fileName[128]; 170 | uint8_t m_userData[sizeof(int32_t)*64]; 171 | }; 172 | 173 | int32_t modelLoadFunc(void* _modelLoadThreadParameters); 174 | 175 | // Cmft filter. 176 | //----- 177 | 178 | namespace cmft { struct ImageSoftRef; } 179 | 180 | struct CmftFilterThreadParams 181 | { 182 | CmftFilterThreadParams() 183 | { 184 | m_threadStatus = ThreadStatus::Idle; 185 | m_srcSize = 256; 186 | m_dstSize = 256; 187 | m_inputGamma = 2.2f; 188 | m_outputGamma = 1.0f/2.2f; 189 | m_mipCount = 7; 190 | m_glossScale = 10; 191 | m_glossBias = 3; 192 | m_numCpuThreads = 4; 193 | m_filterType = cs::Environment::Pmrem; 194 | m_lightingModel = cmft::LightingModel::BlinnBrdf; 195 | m_edgeFixup = cmft::EdgeFixup::None; 196 | m_excludeBase = false; 197 | m_useOpenCL = true; 198 | m_envHandle = cs::EnvHandle::invalid(); 199 | } 200 | 201 | uint8_t m_threadStatus; 202 | uint32_t m_srcSize; 203 | uint32_t m_dstSize; 204 | float m_inputGamma; 205 | float m_outputGamma; 206 | uint8_t m_mipCount; 207 | uint8_t m_glossScale; 208 | uint8_t m_glossBias; 209 | uint8_t m_numCpuThreads; 210 | cs::Environment::Enum m_filterType; 211 | cmft::LightingModel::Enum m_lightingModel; 212 | cmft::EdgeFixup::Enum m_edgeFixup; 213 | bool m_excludeBase; 214 | bool m_useOpenCL; 215 | cmft::ImageSoftRef m_output; 216 | cmft::ImageSoftRef m_input; 217 | cs::EnvHandle m_envHandle; 218 | }; 219 | 220 | int32_t cmftFilterFunc(void* _cmftFilterThreadParams); 221 | 222 | #endif // CMFTSTUDIO_BACKGROUNDJOBS_H_HEADER_GUARD 223 | 224 | /* vim: set sw=4 ts=4 expandtab: */ 225 | -------------------------------------------------------------------------------- /src/build/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | # License: http://www.opensource.org/licenses/BSD-2-Clause 4 | # 5 | 6 | .PHONY: all 7 | all: 8 | @ bash gen_build_headers.sh 9 | -------------------------------------------------------------------------------- /src/build/cmftStudioApp.cpp: -------------------------------------------------------------------------------- 1 | #include "../assets.cpp" 2 | #include "../backgroundjobs.cpp" 3 | #include "../cmftstudio.cpp" 4 | #include "../context.cpp" 5 | #include "../eventstate.cpp" 6 | #include "../gui.cpp" 7 | #include "../guimanager.cpp" 8 | #include "../inflatedeflate.cpp" 9 | #include "../project.cpp" 10 | #include "../renderpipeline.cpp" 11 | #include "../geometry/geometry.cpp" 12 | #include "../geometry/loadermanager.cpp" 13 | #include "../geometry/objtobin.cpp" 14 | #include "../common/allocator.cpp" 15 | #include "../common/config.cpp" 16 | #include "../common/globals.cpp" 17 | #include "../common/timer.cpp" 18 | -------------------------------------------------------------------------------- /src/build/cmftStudioApp_static_resources.cpp: -------------------------------------------------------------------------------- 1 | #include "../staticres.cpp" 2 | -------------------------------------------------------------------------------- /src/build/gen_build_headers.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2014-2015 Dario Manesku. All rights reserved. 4 | # License: http://www.opensource.org/licenses/BSD-2-Clause 5 | # 6 | 7 | SRC=(../*.cpp ../geometry/*.cpp ../common/*.cpp) 8 | APP=cmftStudioApp.cpp 9 | RES=cmftStudioApp_static_resources.cpp 10 | 11 | echo "Generating '$APP' and '$RES'..." 12 | echo -n > $APP 13 | echo -n > $RES 14 | 15 | for file in ${SRC[*]}; do 16 | if [ $file == "../staticres.cpp" ]; then 17 | echo "#include \"$file\"" >> $RES 18 | else 19 | echo "#include \"$file\"" >> $APP 20 | fi 21 | done 22 | 23 | echo "Done." 24 | -------------------------------------------------------------------------------- /src/common/allocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_ALLOCATOR_H_HEADER_GUARD 7 | #define CMFTSTUDIO_ALLOCATOR_H_HEADER_GUARD 8 | 9 | #include 10 | 11 | namespace cs 12 | { 13 | extern bx::AllocatorI* delayedFree; // Used for memory that is referenced and passed to bgfx. 14 | extern bx::ReallocatorI* bgfxAlloc; // Bgfx allocator. 15 | void allocGc(); 16 | void allocDestroy(); 17 | } //namespace cs 18 | 19 | #endif // CMFTSTUDIO_ALLOCATOR_H_HEADER_GUARD 20 | 21 | /* vim: set sw=4 ts=4 expandtab: */ 22 | -------------------------------------------------------------------------------- /src/common/appconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_APPCONFIG_H_HEADER_GUARD 7 | #define CMFTSTUDIO_APPCONFIG_H_HEADER_GUARD 8 | 9 | // Check. 10 | //----- 11 | 12 | // Available options: 13 | // -DM_CHECK_CONFIG_NOOP 14 | // -DM_CHECK_CONFIG_PRINT 15 | // -DM_CHECK_CONFIG_DEBUG_BREAK 16 | #define DM_CHECK_CONFIG DM_CHECK_CONFIG_NOOP 17 | #include 18 | #define CS_CHECK DM_CHECK 19 | 20 | // Allocator. 21 | //----- 22 | 23 | #define DM_ALLOCATOR 1 // Using 0 here makes implementation fallback to C-runtime allocator functions. 24 | #define DM_NATURAL_ALIGNMENT 16 25 | 26 | #define DM_ALLOC_PRINT_STATS 0 27 | #define DM_ALLOC_PRINT_USAGE 0 28 | #define DM_ALLOC_PRINT_STATIC 0 29 | #define DM_ALLOC_PRINT_SMALL 0 30 | #define DM_ALLOC_PRINT_STACK 0 31 | #define DM_ALLOC_PRINT_HEAP 0 32 | #define DM_ALLOC_PRINT_EXT 0 33 | #define DM_ALLOC_PRINT_BGFX 0 34 | 35 | #define DM_ALLOC_PRINT_FILELINE 0 36 | 37 | // Allocator overrides. 38 | //----- 39 | 40 | #define CS_OVERRIDE_NEWDELETE 1 41 | #define CS_OVERRIDE_TINYSTL_ALLOCATOR 1 42 | #define CS_OVERRIDE_STBI_ALLOCATOR 1 43 | #define CS_OBJTOBIN_USES_TINYSTL 1 // 1 == tinystl, 0 == std containers. 44 | 45 | // Resources. 46 | //----- 47 | 48 | #define CS_MAX_LIGHTS 6 49 | #define CS_MAX_TEXTURES 128 50 | #define CS_MAX_MATERIALS 256 51 | #define CS_MAX_MESHES 16 52 | #define CS_MAX_ENVIRONMENTS 32 53 | #define CS_MAX_MESHINSTANCES 32 54 | 55 | #define CS_MAX_GEOMETRY_LOADERS 8 56 | 57 | // Shaders. 58 | //----- 59 | 60 | // Load shaders from: 61 | // 0 - local files 62 | // 1 - executable's data segment (headers are generated with '/src/shaders/makefile_headers') 63 | #define CS_LOAD_SHADERS_FROM_DATA_SEGMENT 1 64 | 65 | #endif // CMFTSTUDIO_APPCONFIG_H_HEADER_GUARD 66 | 67 | /* vim: set sw=4 ts=4 expandtab: */ 68 | -------------------------------------------------------------------------------- /src/common/cmft.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_CMFT_H_HEADER_GUARD 7 | #define CMFTSTUDIO_CMFT_H_HEADER_GUARD 8 | 9 | #include "allocator.h" 10 | 11 | // These must be defined before including cmft/allocator.h 12 | #define CMFT_STACK_PUSH() cs::allocStackPush() 13 | #define CMFT_STACK_POP() cs::allocStackPop() 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #endif // CMFTSTUDIO_CMFT_H_HEADER_GUARD 20 | 21 | /* vim: set sw=4 ts=4 expandtab: */ 22 | -------------------------------------------------------------------------------- /src/common/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_COMMON_H_HEADER_GUARD 7 | #define CMFTSTUDIO_COMMON_H_HEADER_GUARD 8 | 9 | #include "appconfig.h" 10 | #include "allocator.h" 11 | #include "globals.h" 12 | 13 | #endif // CMFTSTUDIO_COMMON_H_HEADER_GUARD 14 | 15 | /* vim: set sw=4 ts=4 expandtab: */ 16 | 17 | -------------------------------------------------------------------------------- /src/common/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_CONFIG_H_HEADER_GUARD 7 | #define CMFTSTUDIO_CONFIG_H_HEADER_GUARD 8 | 9 | #include // bgfx::RendererType 10 | #include // DM_GIGABYTES, DM_PATH_LEN 11 | 12 | struct Config 13 | { 14 | Config() 15 | { 16 | #if BX_ARCH_64BIT 17 | m_memorySize = DM_GIGABYTES(2); 18 | #else // Windows 32bit build cannot allocate 2GB. 19 | m_memorySize = DM_MEGABYTES(1536); 20 | #endif // BX_ARCH_64BIT 21 | m_width = 1920; 22 | m_height = 1027; 23 | m_renderer = bgfx::RendererType::Count; 24 | m_loaded = false; 25 | m_startupProject[0] = '\0'; 26 | m_defaultLoadPath[0] = '\0'; 27 | m_defaultSavePath[0] = '\0'; 28 | } 29 | 30 | uint64_t m_memorySize; 31 | uint32_t m_width; 32 | uint32_t m_height; 33 | bgfx::RendererType::Enum m_renderer; 34 | bool m_loaded; 35 | char m_startupProject[DM_PATH_LEN]; 36 | char m_defaultLoadPath[DM_PATH_LEN]; 37 | char m_defaultSavePath[DM_PATH_LEN]; 38 | }; 39 | 40 | void configWriteDefault(const char* _path); 41 | void configFromFile(Config& _config, const char* _path); 42 | void configFromDefaultPaths(Config& _config); 43 | void configFromCli(Config& _config, int _argc, const char* const* _argv); 44 | void printCliHelp(); 45 | 46 | extern Config g_config; 47 | 48 | #endif // CMFTSTUDIO_CONFIG_H_HEADER_GUARD 49 | 50 | /* vim: set sw=4 ts=4 expandtab: */ 51 | -------------------------------------------------------------------------------- /src/common/globals.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #include "globals.h" 7 | 8 | uint16_t g_versionMajor = 1; 9 | uint16_t g_versionMinor = 1; 10 | 11 | float g_texelHalf = 0.0f; 12 | bool g_originBottomLeft = false; 13 | uint32_t g_frameNum = 0; 14 | uint32_t g_width = 1920; 15 | uint32_t g_height = 1080; 16 | uint32_t g_guiWidth = 1920; 17 | uint32_t g_guiHeight = 1022; 18 | float g_widthf = 1920.0f; 19 | float g_heightf = 1080.0f; 20 | 21 | /* vim: set sw=4 ts=4 expandtab: */ 22 | -------------------------------------------------------------------------------- /src/common/globals.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_GLOBALS_H_HEADER_GUARD 7 | #define CMFTSTUDIO_GLOBALS_H_HEADER_GUARD 8 | 9 | #include 10 | 11 | extern uint16_t g_versionMajor; 12 | extern uint16_t g_versionMinor; 13 | 14 | extern float g_texelHalf; // 0.5f on DX9, 0.0f elsewhere. 15 | extern bool g_originBottomLeft; // false for DX9/DX11, true for OpenGL. 16 | extern uint32_t g_frameNum; 17 | extern uint32_t g_width; 18 | extern uint32_t g_height; 19 | extern uint32_t g_guiWidth; 20 | extern uint32_t g_guiHeight; 21 | extern float g_widthf; 22 | extern float g_heightf; 23 | 24 | #endif // CMFTSTUDIO_GLOBALS_H_HEADER_GUARD 25 | 26 | /* vim: set sw=4 ts=4 expandtab: */ 27 | -------------------------------------------------------------------------------- /src/common/imgui.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_IMGUI_H_HEADER_GUARD 7 | #define CMFTSTUDIO_IMGUI_H_HEADER_GUARD 8 | 9 | // These must be defined before including imgui.h 10 | #define IMGUI_SCROLL_AREA_R 0 11 | #define IMGUI_SCROLL_BAR_R 4 12 | #define IMGUI_BUTTON_R 4 13 | #define IMGUI_INPUT_R 4 14 | #include 15 | 16 | #endif // CMFTSTUDIO_IMGUI_H_HEADER_GUARD 17 | 18 | /* vim: set sw=4 ts=4 expandtab: */ 19 | -------------------------------------------------------------------------------- /src/common/memblock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_MEMBLOCK_H_HEADER_GUARD 7 | #define CMFTSTUDIO_MEMBLOCK_H_HEADER_GUARD 8 | 9 | #include 10 | #include "appconfig.h" 11 | #include 12 | #include 13 | #include //dm::max 14 | 15 | class DynamicMemoryBlock : public bx::MemoryBlockI 16 | { 17 | public: 18 | DynamicMemoryBlock(bx::ReallocatorI* _reallocator, uint32_t _initialSize) 19 | : m_reallocator(_reallocator) 20 | , m_data(NULL) 21 | , m_size(0) 22 | , m_initialSize(_initialSize) 23 | { 24 | } 25 | 26 | virtual ~DynamicMemoryBlock() 27 | { 28 | } 29 | 30 | virtual void* more(uint32_t _size = 0) BX_OVERRIDE 31 | { 32 | const uint32_t newSize = (0 == m_size) ? m_initialSize : m_size+_size*8; 33 | void* newData = BX_REALLOC(m_reallocator, m_data, newSize); 34 | if (NULL != newData) 35 | { 36 | m_data = newData; 37 | m_size = newSize; 38 | } 39 | 40 | return m_data; 41 | } 42 | 43 | virtual uint32_t getSize() BX_OVERRIDE 44 | { 45 | return m_size; 46 | } 47 | 48 | void* getData() const 49 | { 50 | return m_data; 51 | } 52 | 53 | 54 | public: 55 | bx::ReallocatorI* m_reallocator; 56 | private: 57 | DynamicMemoryBlock& operator=(const DynamicMemoryBlock& _rhs); 58 | void* m_data; 59 | uint32_t m_size; 60 | uint32_t m_initialSize; 61 | }; 62 | 63 | class DynamicMemoryBlockWriter : public bx::MemoryWriter 64 | { 65 | public: 66 | DynamicMemoryBlockWriter(bx::ReallocatorI* _reallocator, uint32_t _initialSize) 67 | : MemoryWriter(&m_dmb) 68 | , m_dmb(_reallocator, _initialSize) 69 | { 70 | m_begin = this->seek(); 71 | } 72 | 73 | virtual ~DynamicMemoryBlockWriter() 74 | { 75 | } 76 | 77 | void* getData() 78 | { 79 | return m_dmb.getData(); 80 | } 81 | 82 | void* getDataTrim() 83 | { 84 | void* data = this->getData(); 85 | uint32_t size = this->getDataSize(); 86 | 87 | return BX_REALLOC(m_dmb.m_reallocator, data, size); 88 | } 89 | 90 | void* getDataCopy(bx::AllocatorI* _allocator) 91 | { 92 | const void* data = this->getData(); 93 | const uint32_t size = this->getDataSize(); 94 | 95 | void* out = BX_ALLOC(_allocator, size); 96 | memcpy(out, data, size); 97 | 98 | return out; 99 | } 100 | 101 | uint32_t getDataSize() 102 | { 103 | const int64_t curr = this->seek(); 104 | const uint32_t diff = uint32_t(curr-m_begin); 105 | 106 | return diff; 107 | } 108 | 109 | uint32_t getAllocatedSize() 110 | { 111 | return (uint32_t)m_dmb.getSize(); 112 | } 113 | 114 | private: 115 | int64_t m_begin; 116 | DynamicMemoryBlock m_dmb; 117 | }; 118 | 119 | #endif // CMFTSTUDIO_MEMBLOCK_H_HEADER_GUARD 120 | 121 | /* vim: set sw=4 ts=4 expandtab: */ 122 | 123 | -------------------------------------------------------------------------------- /src/common/miniz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_MINIZ_H_HEADER_GUARD 7 | #define CMFTSTUDIO_MINIZ_H_HEADER_GUARD 8 | 9 | #include 10 | 11 | BX_PRAGMA_DIAGNOSTIC_PUSH_GCC() 12 | BX_PRAGMA_DIAGNOSTIC_IGNORED_GCC("-Wstrict-aliasing") 13 | #define MINIZ_NO_TIME 14 | #define MINIZ_NO_ARCHIVE_APIS 15 | #define MINIZ_NO_ARCHIVE_WRITING_APIS 16 | #include 17 | BX_PRAGMA_DIAGNOSTIC_POP_GCC() 18 | 19 | #endif // CMFTSTUDIO_MINIZ_H_HEADER_GUARD 20 | 21 | /* vim: set sw=4 ts=4 expandtab: */ 22 | 23 | -------------------------------------------------------------------------------- /src/common/stb_image.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_STB_IMAGE_H_HEADER_GUARD 7 | #define CMFTSTUDIO_STB_IMAGE_H_HEADER_GUARD 8 | 9 | #ifndef CS_OVERRIDE_STBI_ALLOCATOR 10 | # define CS_OVERRIDE_STBI_ALLOCATOR 0 11 | #endif //CS_OVERRIDE_STBI_ALLOCATOR 12 | 13 | #if CS_OVERRIDE_STBI_ALLOCATOR 14 | # undef STBI_MALLOC 15 | # undef STBI_REALLOC 16 | # undef STBI_FREE 17 | # define STBI_MALLOC(sz) BX_ALLOC(dm::mainAlloc,sz) 18 | # define STBI_REALLOC(p,sz) BX_REALLOC(dm::mainAlloc,p,sz) 19 | # define STBI_FREE(p) BX_FREE(dm::mainAlloc,p) 20 | #endif //CS_OVERRIDE_STBI_ALLOCATOR 21 | 22 | namespace stb 23 | { 24 | #include 25 | } 26 | 27 | #endif // CMFTSTUDIO_STB_IMAGE_HEADER_GUARD 28 | 29 | /* vim: set sw=4 ts=4 expandtab: */ 30 | -------------------------------------------------------------------------------- /src/common/timer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #include "common.h" 7 | #include "timer.h" 8 | #include 9 | 10 | struct Timer 11 | { 12 | Timer() 13 | { 14 | m_once = true; 15 | m_freq = double(bx::getHPFrequency()); 16 | m_toSec = 1.0/m_freq; 17 | m_toMs = 1000.0/m_freq; 18 | } 19 | 20 | void update() 21 | { 22 | if (m_once) 23 | { 24 | start(); 25 | m_once = false; 26 | } 27 | 28 | m_now = bx::getHPCounter(); 29 | m_frameTime = m_now-m_last; 30 | m_last = m_now; 31 | } 32 | 33 | double toSec(int64_t _tick) const 34 | { 35 | return double(_tick)*m_toSec; 36 | } 37 | 38 | double toMs(int64_t _tick) const 39 | { 40 | return double(_tick)*m_toMs; 41 | } 42 | 43 | int64_t currentTick() const 44 | { 45 | return bx::getHPCounter(); 46 | } 47 | 48 | double currentSec() const 49 | { 50 | return toSec(bx::getHPCounter()); 51 | } 52 | 53 | double currentMs() const 54 | { 55 | return toMs(bx::getHPCounter()); 56 | } 57 | 58 | int64_t deltaTick() const 59 | { 60 | return m_frameTime; 61 | } 62 | 63 | double deltaSec() const 64 | { 65 | return toSec(m_frameTime); 66 | } 67 | 68 | private: 69 | void start() 70 | { 71 | m_begin = bx::getHPCounter(); 72 | 73 | m_now = m_begin; 74 | m_last = m_begin; 75 | m_frameTime = 0; 76 | } 77 | 78 | bool m_once; 79 | 80 | int64_t m_begin; 81 | int64_t m_now; 82 | int64_t m_last; 83 | int64_t m_frameTime; 84 | 85 | double m_freq; 86 | double m_toSec; 87 | double m_toMs; 88 | }; 89 | static Timer s_timer; 90 | 91 | void timerUpdate() 92 | { 93 | s_timer.update(); 94 | } 95 | 96 | int64_t timerCurrentTick() 97 | { 98 | return s_timer.currentTick(); 99 | } 100 | 101 | double timerCurrentSec() 102 | { 103 | return s_timer.currentSec(); 104 | } 105 | 106 | double timerCurrentMs() 107 | { 108 | return s_timer.currentMs(); 109 | } 110 | 111 | int64_t timerDeltaTick() 112 | { 113 | return s_timer.deltaTick(); 114 | } 115 | 116 | double timerDeltaSec() 117 | { 118 | return s_timer.deltaSec(); 119 | } 120 | 121 | double timerToSec(int64_t _tick) 122 | { 123 | return s_timer.toSec(_tick); 124 | } 125 | 126 | double timerToMs(int64_t _tick) 127 | { 128 | return s_timer.toMs(_tick); 129 | } 130 | 131 | /* vim: set sw=4 ts=4 expandtab: */ 132 | -------------------------------------------------------------------------------- /src/common/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_TIMER_H_HEADER_GUARD 7 | #define CMFTSTUDIO_TIMER_H_HEADER_GUARD 8 | 9 | #include 10 | 11 | void timerUpdate(); 12 | int64_t timerCurrentTick(); 13 | double timerCurrentSec(); 14 | double timerCurrentMs(); 15 | int64_t timerDeltaTick(); 16 | double timerDeltaSec(); 17 | double timerToSec(int64_t _tick); 18 | double timerToMs(int64_t _tick); 19 | 20 | #endif // CMFTSTUDIO_TIMER_H_HEADER_GUARD 21 | 22 | /* vim: set sw=4 ts=4 expandtab: */ 23 | -------------------------------------------------------------------------------- /src/common/tinystl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_TINYSTL_H_HEADER_GUARD 7 | #define CMFTSTUDIO_TINYSTL_H_HEADER_GUARD 8 | 9 | namespace cs 10 | { 11 | struct TinyStlAllocator 12 | { 13 | static void* static_allocate(size_t _bytes); 14 | static void static_deallocate(void* _ptr, size_t /*_bytes*/); 15 | }; 16 | } //namespace cs 17 | 18 | #define TINYSTL_ALLOCATOR cs::TinyStlAllocator 19 | #include 20 | #include 21 | #include 22 | #include 23 | namespace stl = tinystl; 24 | 25 | #endif // CMFTSTUDIO_TINYSTL_H_HEADER_GUARD 26 | 27 | /* vim: set sw=4 ts=4 expandtab: */ 28 | -------------------------------------------------------------------------------- /src/common/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_UTILS_H_HEADER_GUARD 7 | #define CMFTSTUDIO_UTILS_H_HEADER_GUARD 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "timer.h" //timerCurrentSec() 15 | 16 | static inline float lerp(float _a, float _b, float _dt, float _d) 17 | { 18 | return _a + (_b-_a)*dm::min(_dt/_d, 1.0f); 19 | } 20 | 21 | static inline float gaussian(float _x, float _mean, float _stdDev) 22 | { 23 | const float stdDevSq = _stdDev*_stdDev; 24 | const float diff = _x - _mean; 25 | const float diffSq = diff*diff; 26 | 27 | const float exp = -diffSq/(2.0f*stdDevSq); 28 | const float coeff = 1.0f/sqrtf(dm::twoPi*stdDevSq); 29 | 30 | return coeff * expf(exp); 31 | } 32 | 33 | static inline void latLongFromVec(float _uv[2], const float _vec[3]) 34 | { 35 | const float phi = atan2f(_vec[0], _vec[2]); 36 | const float theta = acosf(_vec[1]); 37 | 38 | _uv[0] = (dm::pi + phi)*dm::invPiHalf; 39 | _uv[1] = theta*dm::invPi; 40 | } 41 | 42 | static inline void vecFromLatLong(float _vec[3], float _u, float _v) 43 | { 44 | const float phi = _u * dm::twoPi; 45 | const float theta = _v * dm::pi; 46 | 47 | _vec[0] = -sinf(theta)*sinf(phi); 48 | _vec[1] = cosf(theta); 49 | _vec[2] = -sinf(theta)*cosf(phi); 50 | } 51 | 52 | static inline void rightFromLong(float _vec[3], float _rot) 53 | { 54 | const float phi = _rot * dm::twoPi; 55 | 56 | _vec[0] = cosf(phi); 57 | _vec[1] = 0.0f; 58 | _vec[2] = -sinf(phi); 59 | } 60 | 61 | struct Transition 62 | { 63 | Transition() 64 | { 65 | m_begin = 0.0; 66 | m_end = 0.0; 67 | m_active = false; 68 | } 69 | 70 | void start(double _transitionDuration = 0.35) 71 | { 72 | m_begin = timerCurrentSec(); 73 | m_end = m_begin+_transitionDuration; 74 | m_active = true; 75 | } 76 | 77 | float progress() 78 | { 79 | if (!m_active) 80 | { 81 | return 0.0f; 82 | } 83 | 84 | const double now = timerCurrentSec(); 85 | const float prog = float((now - m_begin)/(m_end - m_begin)); 86 | m_active = (prog < 1.0f); 87 | return prog; 88 | } 89 | 90 | bool active() const 91 | { 92 | return m_active; 93 | } 94 | 95 | void end() 96 | { 97 | m_active = false; 98 | } 99 | 100 | private: 101 | double m_begin; 102 | double m_end; 103 | bool m_active; 104 | }; 105 | 106 | struct WidgetAnimator 107 | { 108 | void reset(bool _visible = false 109 | , float _x = 0.0f 110 | , float _y = 0.0f 111 | , float _treshold = 35.0f 112 | ) 113 | { 114 | m_x = _x; 115 | m_y = _y; 116 | m_treshold = _treshold; 117 | m_visible = _visible; 118 | m_state = uint8_t(_visible ? AtEnd : AtStart); 119 | } 120 | 121 | void setKeyPoints(float _startX 122 | , float _startY 123 | , float _endX 124 | , float _endY 125 | ) 126 | { 127 | m_startX = _startX; 128 | m_startY = _startY; 129 | m_endX = _endX; 130 | m_endY = _endY; 131 | m_exitX = _startX; 132 | m_exitY = _startY; 133 | 134 | if (AtEnd == m_state) 135 | { 136 | fadeIn(); 137 | } 138 | else if (AtStart == m_state) 139 | { 140 | m_x = m_startX; 141 | m_y = m_startY; 142 | } 143 | } 144 | 145 | void setKeyPoints(float _startX 146 | , float _startY 147 | , float _endX 148 | , float _endY 149 | , float _exitX 150 | , float _exitY 151 | ) 152 | { 153 | m_startX = _startX; 154 | m_startY = _startY; 155 | m_endX = _endX; 156 | m_endY = _endY; 157 | m_exitX = _exitX; 158 | m_exitY = _exitY; 159 | 160 | if (AtEnd == m_state) 161 | { 162 | fadeIn(); 163 | } 164 | else if (AtStart == m_state) 165 | { 166 | m_x = m_startX; 167 | m_y = m_startY; 168 | } 169 | } 170 | 171 | void update(float _dt, float _duration) 172 | { 173 | CS_CHECK(_duration >= _dt, "Duration param must be longer or equals to deltaTime!"); 174 | 175 | if (FadingIn == m_state) 176 | { 177 | m_visible = true; 178 | 179 | m_x = lerp(m_x, m_endX + 0.5f, _dt, _duration); 180 | m_y = lerp(m_y, m_endY + 0.5f, _dt, _duration); 181 | 182 | if (fabsf(m_endX-m_x) < 0.1f 183 | && fabsf(m_endY-m_y) < 0.1f) 184 | { 185 | m_x = m_endX; 186 | m_y = m_endY; 187 | m_state = AtEnd; 188 | } 189 | } 190 | else if (FadingOut == m_state) 191 | { 192 | m_visible = true; 193 | 194 | m_x = lerp(m_x, m_exitX, _dt, _duration); 195 | m_y = lerp(m_y, m_exitY, _dt, _duration); 196 | 197 | if (fabsf(m_exitX-m_x) < m_treshold 198 | && fabsf(m_exitY-m_y) < m_treshold) 199 | { 200 | m_x = m_exitX; 201 | m_y = m_exitY; 202 | m_visible = false; 203 | m_state = AtStart; 204 | } 205 | } 206 | } 207 | 208 | void fadeIn() 209 | { 210 | m_state = FadingIn; 211 | } 212 | 213 | void fadeOut() 214 | { 215 | if (m_visible) 216 | { 217 | m_state = FadingOut; 218 | } 219 | } 220 | 221 | void toggle() 222 | { 223 | if (m_visible) 224 | { 225 | fadeOut(); 226 | } 227 | else 228 | { 229 | fadeIn(); 230 | } 231 | } 232 | 233 | bool isVisible() const 234 | { 235 | return m_visible; 236 | } 237 | 238 | enum State 239 | { 240 | AtStart, 241 | AtEnd, 242 | FadingIn, 243 | FadingOut, 244 | }; 245 | 246 | float m_x; 247 | float m_y; 248 | float m_startX; 249 | float m_startY; 250 | float m_endX; 251 | float m_endY; 252 | float m_exitX; 253 | float m_exitY; 254 | float m_treshold; 255 | bool m_visible; 256 | uint8_t m_state; 257 | }; 258 | 259 | #endif // CMFTSTUDIO_UTILS_H_HEADER_GUARD 260 | 261 | /* vim: set sw=4 ts=4 expandtab: */ 262 | -------------------------------------------------------------------------------- /src/context_res.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #if !defined(TEXUNI_DESC) 7 | #define TEXUNI_DESC(_enum, _stage, _name) 8 | #endif //!defined(TEXUNI_DESC) 9 | TEXUNI_DESC( PmremPrev, 4, "u_texPmremPrev" ) 10 | TEXUNI_DESC( Skybox, 5, "u_texSkybox" ) 11 | TEXUNI_DESC( Pmrem, 6, "u_texPmrem" ) 12 | TEXUNI_DESC( Iem, 7, "u_texIem" ) 13 | TEXUNI_DESC( Lum, 1, "u_texLum" ) 14 | TEXUNI_DESC( Blur, 2, "u_texBlur" ) 15 | TEXUNI_DESC( Color, 0, "u_texColor" ) 16 | TEXUNI_DESC( Normal, 1, "u_texNormal" ) 17 | TEXUNI_DESC( Surface, 2, "u_texSurface" ) 18 | TEXUNI_DESC( Reflectivity, 3, "u_texReflectivity" ) 19 | TEXUNI_DESC( Occlusion, 8, "u_texAO" ) 20 | TEXUNI_DESC( Emissive, 9, "u_texEmissive" ) 21 | #undef TEXUNI_DESC 22 | 23 | #if !defined(PROG_DESC) 24 | #define PROG_DESC(_name, _vs, _fs) 25 | #endif //!defined(PROG_DESC) 26 | PROG_DESC( Mesh , vs_mesh , fs_mesh ) 27 | PROG_DESC( MeshRgbe8 , vs_mesh , fs_mesh_rgbe8 ) 28 | PROG_DESC( MeshRgbe8Trans , vs_mesh , fs_mesh_rgbe8_trans ) 29 | PROG_DESC( MeshNormal , vs_mesh_normal , fs_mesh_normal ) 30 | PROG_DESC( MeshNormalRgbe8 , vs_mesh_normal , fs_mesh_normal_rgbe8 ) 31 | PROG_DESC( MeshNormalRgbe8Trans , vs_mesh_normal , fs_mesh_normal_rgbe8_trans ) 32 | PROG_DESC( Sky , vs_skybox , fs_skybox ) 33 | PROG_DESC( SkyTrans , vs_skybox , fs_skybox_trans ) 34 | PROG_DESC( Tonemap , vs_tonemap , fs_tonemap ) 35 | PROG_DESC( Material , vs_material , fs_mesh ) 36 | PROG_DESC( MaterialNormal , vs_material_normal, fs_mesh_normal ) 37 | PROG_DESC( Blur , vs_blur , fs_blur ) 38 | PROG_DESC( Color , vs_plain , fs_color ) 39 | PROG_DESC( Overlay , vs_plain , fs_overlay ) 40 | PROG_DESC( Wireframe , vs_plain , fs_wireframe ) 41 | PROG_DESC( Bright , vs_texcoord , fs_bright ) 42 | PROG_DESC( Lum , vs_texcoord , fs_lum ) 43 | PROG_DESC( LumAvg , vs_texcoord , fs_lumavg ) 44 | PROG_DESC( LumDownscale , vs_texcoord , fs_lumdownscale ) 45 | PROG_DESC( Image , vs_texcoord , fs_image ) 46 | PROG_DESC( Latlong , vs_texcoord , fs_latlong ) 47 | PROG_DESC( ImageRe8 , vs_texcoord , fs_image_re8 ) 48 | PROG_DESC( SunIcon , vs_texcoord , fs_sun_icon ) 49 | PROG_DESC( CubemapTonemap , vs_texcoord , fs_cubemap_tonemap ) 50 | PROG_DESC( Equals , vs_texcoord , fs_equals ) 51 | PROG_DESC( Fxaa , vs_texcoord , fs_fxaa ) 52 | #undef PROG_DESC 53 | 54 | #if !defined(PROG_NORM) 55 | #define PROG_NORM(_prog, _normal) 56 | #endif //!defined(PROG_NORM) 57 | PROG_NORM( Mesh , MeshNormal ) 58 | PROG_NORM( MeshRgbe8 , MeshNormalRgbe8 ) 59 | PROG_NORM( MeshRgbe8Trans , MeshNormalRgbe8Trans ) 60 | PROG_NORM( Material , MaterialNormal ) 61 | #undef PROG_NORM 62 | 63 | #if !defined(PROG_TRANS) 64 | #define PROG_TRANS(_prog, _trans) 65 | #endif //!defined(PROG_TRANS) 66 | PROG_TRANS( MeshRgbe8 , MeshRgbe8Trans ) 67 | PROG_TRANS( MeshNormalRgbe8 , MeshNormalRgbe8Trans ) 68 | #undef PROG_TRANS 69 | 70 | /* vim: set sw=4 ts=4 expandtab: */ 71 | -------------------------------------------------------------------------------- /src/eventstate.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #include "common/common.h" 7 | #include "eventstate.h" 8 | 9 | #include 10 | 11 | #include "common/timer.h" 12 | #include 13 | 14 | struct EventImpl 15 | { 16 | EventImpl() 17 | { 18 | m_currFrame = 0; 19 | m_activeEvents = 0; 20 | } 21 | 22 | void trigger(Event::Enum _event) 23 | { 24 | m_activeEvents |= _event; 25 | } 26 | 27 | void triggerAfter(uint8_t _numFrames, Event::Enum _event) 28 | { 29 | const uint32_t frame = m_currFrame + _numFrames; 30 | m_frame. add(frame); 31 | m_frameEvents.add(_event); 32 | } 33 | 34 | void triggerAfter(float _sec, Event::Enum _event) 35 | { 36 | const float time = float(timerCurrentSec()) + _sec; 37 | m_time .add(time); 38 | m_timeEvents.add(_event); 39 | } 40 | 41 | void frame() 42 | { 43 | ++m_currFrame; 44 | for (uint32_t ii = m_frame.count(); ii--; ) 45 | { 46 | if (m_currFrame == m_frame[ii]) 47 | { 48 | trigger(m_frameEvents[ii]); 49 | 50 | m_frame .removeSwap(ii); 51 | m_frameEvents.removeSwap(ii); 52 | } 53 | } 54 | 55 | const float currTime = float(timerCurrentSec()); 56 | for (uint32_t ii = m_time.count(); ii--; ) 57 | { 58 | if (currTime > m_time[ii]) 59 | { 60 | trigger(m_timeEvents[ii]); 61 | 62 | m_time .removeSwap(ii); 63 | m_timeEvents.removeSwap(ii); 64 | } 65 | } 66 | } 67 | 68 | bool check(Event::Enum _event) 69 | { 70 | return (0 != (m_activeEvents & _event)); 71 | } 72 | 73 | void markAsHandled(Event::Enum _event) 74 | { 75 | m_activeEvents &= ~_event; 76 | } 77 | 78 | bool handle(Event::Enum _event) 79 | { 80 | const bool didHappen = check(_event); 81 | if (didHappen) 82 | { 83 | markAsHandled(_event); 84 | return true; 85 | } 86 | else 87 | { 88 | return false; 89 | } 90 | } 91 | 92 | void clear() 93 | { 94 | m_activeEvents = 0; 95 | } 96 | 97 | enum { MaxPendingEvents = 32 }; 98 | 99 | uint32_t m_currFrame; 100 | uint8_t m_activeEvents; 101 | dm::ArrayT m_frame; 102 | dm::ArrayT m_frameEvents; 103 | dm::ArrayT m_time; 104 | dm::ArrayT m_timeEvents; 105 | }; 106 | static EventImpl s_events; 107 | 108 | void eventTrigger(Event::Enum _event) 109 | { 110 | s_events.trigger(_event); 111 | } 112 | 113 | void eventTriggerAfter(uint8_t _numFrames, Event::Enum _event) 114 | { 115 | s_events.triggerAfter(_numFrames, _event); 116 | } 117 | 118 | void eventTriggerAfterTime(float _sec, Event::Enum _event) 119 | { 120 | s_events.triggerAfter(_sec, _event); 121 | } 122 | 123 | bool eventCheck(Event::Enum _event) 124 | { 125 | return s_events.check(_event); 126 | } 127 | 128 | bool eventHandle(Event::Enum _event) 129 | { 130 | return s_events.handle(_event); 131 | } 132 | 133 | void eventFrame() 134 | { 135 | s_events.frame(); 136 | } 137 | 138 | struct StateImpl 139 | { 140 | StateImpl() 141 | { 142 | m_curr = State::None; 143 | m_lastCurr = State::None; 144 | m_prev = State::None; 145 | m_lastPrev = State::None; 146 | } 147 | 148 | void enter(State::Enum _newState) 149 | { 150 | m_prev = m_curr; 151 | m_curr = _newState; 152 | } 153 | 154 | void frame() 155 | { 156 | m_lastCurr = m_curr; 157 | m_lastPrev = m_prev; 158 | } 159 | 160 | State::Enum m_curr; 161 | State::Enum m_lastCurr; 162 | State::Enum m_prev; 163 | State::Enum m_lastPrev; 164 | }; 165 | static StateImpl s_state; 166 | 167 | bool onState(State::Enum _state) 168 | { 169 | return (_state == s_state.m_curr); 170 | } 171 | 172 | bool onStateEnter(State::Enum _state) 173 | { 174 | return (s_state.m_curr != s_state.m_lastCurr) && (_state == s_state.m_curr); 175 | } 176 | 177 | bool onStateLeave(State::Enum _state) 178 | { 179 | return (s_state.m_prev != s_state.m_lastPrev) && (_state == s_state.m_prev); 180 | } 181 | 182 | bool onStateChange(State::Enum _from, State::Enum _to) 183 | { 184 | return (_to == s_state.m_curr) && (_from == s_state.m_prev); 185 | } 186 | 187 | void stateEnter(State::Enum _newState) 188 | { 189 | s_state.enter(_newState); 190 | } 191 | 192 | void stateFrame() 193 | { 194 | s_state.frame(); 195 | } 196 | 197 | /* vim: set sw=4 ts=4 expandtab: */ 198 | -------------------------------------------------------------------------------- /src/eventstate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_EVENTS_H_HEADER_GUARD 7 | #define CMFTSTUDIO_EVENTS_H_HEADER_GUARD 8 | 9 | struct Event 10 | { 11 | enum Enum 12 | { 13 | ProjectIsLoading = 0x1, 14 | ProjectLoaded = 0x2, 15 | BeginLoadTransition = 0x4, 16 | LoadTransitionComplete = 0x8, 17 | }; 18 | }; 19 | 20 | void eventTrigger(Event::Enum _event); 21 | void eventTriggerAfter(uint8_t _num, Event::Enum _event); 22 | void eventTriggerAfterTime(float _sec, Event::Enum _event); 23 | bool eventCheck(Event::Enum _event); 24 | bool eventHandle(Event::Enum _event); 25 | void eventFrame(); // Call this in the current frame, before handling events. 26 | 27 | struct State 28 | { 29 | enum Enum 30 | { 31 | None, 32 | SplashScreen, 33 | IntroAnimation, 34 | MainState, 35 | SendResourcesToGpu, 36 | ProjectLoadTransition, 37 | }; 38 | }; 39 | 40 | bool onState(State::Enum _state); 41 | bool onStateEnter(State::Enum _state); 42 | bool onStateLeave(State::Enum _state); 43 | bool onStateChange(State::Enum _from, State::Enum _to); 44 | void stateEnter(State::Enum _newState); 45 | void stateFrame(); // Call this in the current frame, after handling state changes. 46 | 47 | #endif // CMFTSTUDIO_EVENTS_H_HEADER_GUARD 48 | 49 | /* vim: set sw=4 ts=4 expandtab: */ 50 | -------------------------------------------------------------------------------- /src/geometry/geometry.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #include "../common/common.h" 7 | #include "geometry.h" 8 | 9 | #include <../../src/vertexdecl.h> // bgfx::VertexDecl 10 | 11 | #define BGFX_CHUNK_MAGIC_VB BX_MAKEFOURCC('V', 'B', ' ', 0x1) 12 | #define BGFX_CHUNK_MAGIC_IB BX_MAKEFOURCC('I', 'B', ' ', 0x0) 13 | #define BGFX_CHUNK_MAGIC_PRI BX_MAKEFOURCC('P', 'R', 'I', 0x0) 14 | #define CMFTSTUDIO_CHUNK_MAGIC_MSH_MISC BX_MAKEFOURCC('M', 'S', 'H', 0x2) 15 | #define CMFTSTUDIO_CHUNK_MAGIC_MSH_DONE BX_MAKEFOURCC('M', 'S', 'H', 0x3) 16 | 17 | void write(bx::WriterI* _writer, const void* _vertices, uint32_t _numVertices, uint32_t _stride, uint32_t _obbSteps) 18 | { 19 | Sphere maxSphere; 20 | calcMaxBoundingSphere(maxSphere, _vertices, _numVertices, _stride); 21 | 22 | Sphere minSphere; 23 | calcMinBoundingSphere(minSphere, _vertices, _numVertices, _stride); 24 | 25 | if (minSphere.m_radius > maxSphere.m_radius) 26 | { 27 | bx::write(_writer, maxSphere); 28 | } 29 | else 30 | { 31 | bx::write(_writer, minSphere); 32 | } 33 | 34 | Aabb aabb; 35 | calcAabb(aabb, _vertices, _numVertices, _stride); 36 | bx::write(_writer, aabb); 37 | 38 | Obb obb; 39 | calcObb(obb, _vertices, _numVertices, _stride, DM_CLAMP(_obbSteps, 1, 90)); 40 | bx::write(_writer, obb); 41 | } 42 | 43 | void write(bx::WriterI* _writer 44 | , const uint8_t* _vertices 45 | , uint32_t _numVertices 46 | , const bgfx::VertexDecl& _decl 47 | , const uint16_t* _indices 48 | , uint32_t _numIndices 49 | , const char* _material 50 | , const Primitive* _primitives 51 | , uint32_t _primitiveCount 52 | , uint32_t _obbSteps 53 | ) 54 | { 55 | using namespace bx; 56 | using namespace bgfx; 57 | 58 | uint32_t stride = _decl.getStride(); 59 | write(_writer, BGFX_CHUNK_MAGIC_VB); 60 | write(_writer, _vertices, _numVertices, stride, _obbSteps); 61 | 62 | write(_writer, _decl); 63 | 64 | write(_writer, uint16_t(_numVertices) ); 65 | write(_writer, _vertices, _numVertices*stride); 66 | 67 | write(_writer, BGFX_CHUNK_MAGIC_IB); 68 | write(_writer, _numIndices); 69 | write(_writer, _indices, _numIndices*2); 70 | 71 | write(_writer, BGFX_CHUNK_MAGIC_PRI); 72 | uint16_t nameLen = uint16_t(strlen(_material)); 73 | write(_writer, nameLen); 74 | write(_writer, _material, nameLen); 75 | write(_writer, uint16_t(_primitiveCount)); 76 | 77 | for (uint32_t ii = 0, end = _primitiveCount; ii < end; ++ii) 78 | { 79 | const Primitive& prim = _primitives[ii]; 80 | nameLen = uint16_t(strlen(prim.m_name)); 81 | write(_writer, nameLen); 82 | write(_writer, prim.m_name, nameLen); 83 | write(_writer, prim.m_startIndex); 84 | write(_writer, prim.m_numIndices); 85 | write(_writer, prim.m_startVertex); 86 | write(_writer, prim.m_numVertices); 87 | write(_writer, &_vertices[prim.m_startVertex*stride], prim.m_numVertices, stride, _obbSteps); 88 | } 89 | } 90 | 91 | /* vim: set sw=4 ts=4 expandtab: */ 92 | -------------------------------------------------------------------------------- /src/geometry/geometry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_GEOMETRY_H_HEADER_GUARD 7 | #define CMFTSTUDIO_GEOMETRY_H_HEADER_GUARD 8 | 9 | #include "../common/common.h" 10 | 11 | #include // bgfx::VertexDecl 12 | #include // Sphere, Aabb, Obb 13 | 14 | #include //bx::WriterI 15 | #include 16 | 17 | struct Primitive 18 | { 19 | enum { NameLen = 128 }; 20 | 21 | uint32_t m_startIndex; 22 | uint32_t m_numIndices; 23 | uint32_t m_startVertex; 24 | uint32_t m_numVertices; 25 | 26 | Sphere m_sphere; 27 | Aabb m_aabb; 28 | Obb m_obb; 29 | 30 | char m_name[NameLen]; 31 | }; 32 | typedef dm::ObjArray PrimitiveArray; 33 | 34 | struct Group 35 | { 36 | enum { MaterialNameLen = 128 }; 37 | 38 | ~Group() 39 | { 40 | m_prims.destroy(); 41 | } 42 | 43 | void* m_vertexData; 44 | uint32_t m_vertexSize; 45 | uint32_t m_numVertices; 46 | 47 | void* m_indexData; 48 | uint32_t m_indexSize; 49 | uint32_t m_numIndices; 50 | 51 | bool m_32bitIndexBuffer; 52 | 53 | Sphere m_sphere; 54 | Aabb m_aabb; 55 | Obb m_obb; 56 | 57 | PrimitiveArray m_prims; 58 | 59 | char m_materialName[MaterialNameLen]; 60 | }; 61 | typedef dm::ObjArray GroupArray; 62 | 63 | struct Geometry 64 | { 65 | bool isValid() const 66 | { 67 | return (0 != m_groups.count()); 68 | } 69 | 70 | bgfx::VertexDecl m_decl; 71 | GroupArray m_groups; 72 | }; 73 | 74 | void write(bx::WriterI* _writer 75 | , const void* _vertices 76 | , uint32_t _numVertices 77 | , uint32_t _stride 78 | , uint32_t _obbSteps 79 | ); 80 | void write(bx::WriterI* _writer 81 | , const uint8_t* _vertices 82 | , uint32_t _numVertices 83 | , const bgfx::VertexDecl& _decl 84 | , const uint16_t* _indices 85 | , uint32_t _numIndices 86 | , const char* _material 87 | , const Primitive* _primitives 88 | , uint32_t _primitiveCount 89 | , uint32_t _obbSteps = 17 90 | ); 91 | 92 | #endif // CMFTSTUDIO_GEOMETRY_H_HEADER_GUARD 93 | 94 | /* vim: set sw=4 ts=4 expandtab: */ 95 | -------------------------------------------------------------------------------- /src/geometry/loader_bgfxbin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_LOADERBGFXBIN_H_HEADER_GUARD 7 | #define CMFTSTUDIO_LOADERBGFXBIN_H_HEADER_GUARD 8 | 9 | #include "../common/common.h" 10 | #include "loadermanager.h" 11 | 12 | #include // PRId64 13 | 14 | namespace bgfx 15 | { 16 | int32_t read(bx::ReaderI* _reader, bgfx::VertexDecl& _decl); 17 | } 18 | 19 | // Bgfx bin format loader. 20 | //----- 21 | 22 | #define BGFX_CHUNK_MAGIC_VB BX_MAKEFOURCC('V', 'B', ' ', 0x1) 23 | #define BGFX_CHUNK_MAGIC_IB BX_MAKEFOURCC('I', 'B', ' ', 0x0) 24 | #define BGFX_CHUNK_MAGIC_PRI BX_MAKEFOURCC('P', 'R', 'I', 0x0) 25 | #define CMFTSTUDIO_CHUNK_MAGIC_MSH_MISC BX_MAKEFOURCC('M', 'S', 'H', 0x2) 26 | #define CMFTSTUDIO_CHUNK_MAGIC_MSH_DONE BX_MAKEFOURCC('M', 'S', 'H', 0x3) 27 | 28 | struct BgfxBinInData 29 | { 30 | }; 31 | 32 | struct BgfxBinOutData : public cs::OutDataHeader 33 | { 34 | float m_normScale; 35 | uint16_t m_handle; 36 | }; 37 | 38 | static bool loaderBgfxBin(Geometry& _geometry 39 | , dm::ReaderSeekerI* _reader 40 | , dm::StackAllocatorI* _stack 41 | , void* _inData 42 | , cs::OutDataHeader** _outData 43 | , bx::ReallocatorI* _allocator 44 | ) 45 | { 46 | BX_UNUSED(_inData); 47 | 48 | enum 49 | { 50 | MaxGroupsEstimate = 64, 51 | MaxPrimitivesPerGroupEstimate = 32, 52 | }; 53 | _geometry.m_groups.init(MaxGroupsEstimate, dm::mainAlloc); 54 | 55 | Group* group = _geometry.m_groups.addNew(); 56 | group->m_prims.init(MaxPrimitivesPerGroupEstimate, dm::mainAlloc); 57 | 58 | bool done = false; 59 | uint32_t chunk; 60 | while (!done && 4 == bx::read(_reader, chunk)) 61 | { 62 | switch (chunk) 63 | { 64 | case BGFX_CHUNK_MAGIC_VB: 65 | { 66 | if (NULL == group) 67 | { 68 | group = _geometry.m_groups.addNew(); 69 | group->m_prims.init(MaxPrimitivesPerGroupEstimate, dm::mainAlloc); 70 | } 71 | 72 | bx::read(_reader, group->m_sphere); 73 | bx::read(_reader, group->m_aabb); 74 | bx::read(_reader, group->m_obb); 75 | 76 | bgfx::read(_reader, _geometry.m_decl); 77 | const uint16_t stride = _geometry.m_decl.getStride(); 78 | 79 | uint16_t numVertices; 80 | bx::read(_reader, numVertices); 81 | group->m_numVertices = numVertices; 82 | 83 | group->m_vertexSize = group->m_numVertices*stride; 84 | group->m_vertexData = BX_ALLOC(dm::mainAlloc, group->m_vertexSize); 85 | bx::read(_reader, group->m_vertexData, group->m_vertexSize); 86 | } 87 | break; 88 | 89 | case BGFX_CHUNK_MAGIC_IB: 90 | { 91 | if (NULL == group) 92 | { 93 | group = _geometry.m_groups.addNew(); 94 | group->m_prims.init(MaxPrimitivesPerGroupEstimate, dm::mainAlloc); 95 | } 96 | 97 | bx::read(_reader, group->m_numIndices); 98 | 99 | group->m_32bitIndexBuffer = false; 100 | group->m_indexSize = group->m_numIndices*sizeof(uint16_t); 101 | group->m_indexData = BX_ALLOC(dm::mainAlloc, group->m_indexSize); 102 | bx::read(_reader, group->m_indexData, group->m_indexSize); 103 | } 104 | break; 105 | 106 | case BGFX_CHUNK_MAGIC_PRI: 107 | { 108 | if (NULL == group) 109 | { 110 | group = _geometry.m_groups.addNew(); 111 | group->m_prims.init(MaxPrimitivesPerGroupEstimate, dm::mainAlloc); 112 | } 113 | 114 | uint16_t len; 115 | bx::read(_reader, len); 116 | 117 | if (len < Group::MaterialNameLen) 118 | { 119 | bx::read(_reader, group->m_materialName, len); 120 | group->m_materialName[len] = '\0'; 121 | } 122 | else 123 | { 124 | dm::StackAllocScope scope(_stack); 125 | 126 | void* matName = BX_ALLOC(_stack, len); 127 | 128 | bx::read(_reader, matName, len); 129 | 130 | memcpy(group->m_materialName, matName, Group::MaterialNameLen-1); 131 | group->m_materialName[Group::MaterialNameLen-1] = '\0'; 132 | 133 | BX_FREE(_stack, matName); 134 | } 135 | 136 | uint16_t num; 137 | bx::read(_reader, num); 138 | 139 | for (uint32_t ii = 0; ii < num; ++ii) 140 | { 141 | bx::read(_reader, len); 142 | 143 | if (len < 256) 144 | { 145 | char name[256]; 146 | bx::read(_reader, name, len); 147 | } 148 | else 149 | { 150 | dm::StackAllocScope scope(_stack); 151 | 152 | void* matName = BX_ALLOC(_stack, len); 153 | 154 | bx::read(_reader, matName, len); 155 | 156 | BX_FREE(_stack, matName); 157 | } 158 | 159 | Primitive* prim = group->m_prims.addNew(); 160 | bx::read(_reader, prim->m_startIndex); 161 | bx::read(_reader, prim->m_numIndices); 162 | bx::read(_reader, prim->m_startVertex); 163 | bx::read(_reader, prim->m_numVertices); 164 | bx::read(_reader, prim->m_sphere); 165 | bx::read(_reader, prim->m_aabb); 166 | bx::read(_reader, prim->m_obb); 167 | } 168 | 169 | group->m_prims.shrink(); 170 | group = NULL; 171 | } 172 | break; 173 | 174 | case CMFTSTUDIO_CHUNK_MAGIC_MSH_MISC: 175 | { 176 | uint16_t id; 177 | bx::read(_reader, id); 178 | 179 | float normScale; 180 | bx::read(_reader, normScale); 181 | 182 | if (NULL != _outData) 183 | { 184 | BgfxBinOutData* mesh = (BgfxBinOutData*)BX_ALLOC(_allocator, sizeof(BgfxBinOutData)); 185 | mesh->m_format = cs::FileFormat::BgfxBin; 186 | mesh->m_normScale = normScale; 187 | mesh->m_handle = id; 188 | 189 | *_outData = (cs::OutDataHeader*)mesh; 190 | } 191 | } 192 | break; 193 | 194 | case CMFTSTUDIO_CHUNK_MAGIC_MSH_DONE: 195 | { 196 | done = true; 197 | } 198 | break; 199 | 200 | default: 201 | CS_CHECK(false, "%08x at %" PRId64 "", chunk, _reader->seek()); 202 | break; 203 | } 204 | } 205 | 206 | _geometry.m_groups.shrink(); 207 | 208 | return true; 209 | } 210 | 211 | #endif // CMFTSTUDIO_LOADERBGFXBIN_H_HEADER_GUARD 212 | 213 | /* vim: set sw=4 ts=4 expandtab: */ 214 | -------------------------------------------------------------------------------- /src/geometry/loader_obj.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_LOADEROBJ_H_HEADER_GUARD 7 | #define CMFTSTUDIO_LOADEROBJ_H_HEADER_GUARD 8 | 9 | #include "../common/common.h" 10 | #include "loadermanager.h" 11 | 12 | #include "objtobin.h" // objToBin() 13 | #include "loader_bgfxbin.h" // bgfxBinLoader() 14 | 15 | // Wavefront Obj loader. 16 | //----- 17 | 18 | struct ObjInData 19 | { 20 | float m_scale; 21 | uint32_t m_packUv; 22 | uint32_t m_packNormal; 23 | bool m_ccw; 24 | bool m_flipV; 25 | bool m_calcTangent; 26 | }; 27 | 28 | struct ObjOutData : public cs::OutDataHeader 29 | { 30 | }; 31 | 32 | static bool loaderObj(Geometry& _geometry 33 | , dm::ReaderSeekerI* _reader 34 | , dm::StackAllocatorI* _stack 35 | , void* _inData 36 | , cs::OutDataHeader** _outData 37 | , bx::ReallocatorI* _allocator 38 | ) 39 | { 40 | BX_UNUSED(_outData, _allocator); 41 | 42 | ObjInData* inputParams; 43 | ObjInData defaultValues; 44 | if (NULL != _inData) 45 | { 46 | inputParams = (ObjInData*)_inData; 47 | } 48 | else 49 | { 50 | defaultValues.m_scale = 1.0f; 51 | defaultValues.m_packUv = 1; 52 | defaultValues.m_packNormal = 1; 53 | defaultValues.m_ccw = false; 54 | defaultValues.m_flipV = false; 55 | defaultValues.m_calcTangent = true; 56 | 57 | inputParams = &defaultValues; 58 | } 59 | 60 | dm::StackAllocScope scope(_stack); 61 | 62 | uint8_t* objData = NULL; 63 | if (_reader->getType() == dm::ReaderWriterTypes::MemoryReader) 64 | { 65 | dm::MemoryReader* memory = (dm::MemoryReader*)_reader; 66 | objData = (uint8_t*)memory->getDataPtr() + _reader->seek(); 67 | } 68 | else // (_reader->getType() == dm::ReaderWriterTypes::CrtFileReader). 69 | { 70 | uint32_t objSize = (uint32_t)bx::getSize(_reader); 71 | objData = (uint8_t*)BX_ALLOC(_stack, objSize+1); 72 | objSize = bx::read(_reader, objData, objSize); 73 | objData[objSize] = '\0'; 74 | } 75 | 76 | void* data; 77 | uint32_t dataSize; 78 | objToBin(objData 79 | , data 80 | , dataSize 81 | , _stack 82 | , inputParams->m_packUv 83 | , inputParams->m_packNormal 84 | , inputParams->m_ccw 85 | , inputParams->m_flipV 86 | , inputParams->m_calcTangent 87 | , inputParams->m_scale 88 | ); 89 | 90 | dm::MemoryReader reader(data, dataSize); 91 | 92 | return loaderBgfxBin(_geometry, &reader, _stack, NULL, NULL, NULL); 93 | } 94 | 95 | #endif // CMFTSTUDIO_LOADEROBJ_H_HEADER_GUARD 96 | 97 | /* vim: set sw=4 ts=4 expandtab: */ 98 | 99 | -------------------------------------------------------------------------------- /src/geometry/loadermanager.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #include "../common/common.h" 7 | #include "loadermanager.h" 8 | 9 | #include 10 | #include // dm::ReaderSeekerI 11 | 12 | namespace cs 13 | { 14 | struct GeometryLoader 15 | { 16 | enum 17 | { 18 | MaxNameLen = 127+1, 19 | MaxExtLen = 7+1, 20 | }; 21 | 22 | char m_name[MaxNameLen]; 23 | char m_ext[MaxExtLen]; 24 | GeometryLoadFn m_loadFunc; 25 | }; 26 | 27 | struct GeometryLoaders 28 | { 29 | void registerLoader(const char* _name, const char* _ext, GeometryLoadFn _loadFunc) 30 | { 31 | GeometryLoader* obj = m_loaders.addNew(); 32 | dm::strscpya(obj->m_name, _name); 33 | dm::strscpya(obj->m_ext, _ext); 34 | obj->m_loadFunc = _loadFunc; 35 | } 36 | 37 | void unregisterLoaderByName(const char* _name) 38 | { 39 | for (uint8_t ii = m_loaders.count(); ii--; ) 40 | { 41 | if (0 == bx::stricmp(m_loaders[ii].m_name, _name)) 42 | { 43 | m_loaders.removeSwap(ii); 44 | return; 45 | } 46 | } 47 | } 48 | 49 | void unregisterLoaderByExt(const char* _ext) 50 | { 51 | for (uint8_t ii = m_loaders.count(); ii--; ) 52 | { 53 | if (0 == bx::stricmp(m_loaders[ii].m_ext, _ext)) 54 | { 55 | m_loaders.removeSwap(ii); 56 | return; 57 | } 58 | } 59 | } 60 | 61 | void getNames(const char* _names[CS_MAX_GEOMETRY_LOADERS]) const 62 | { 63 | for (uint8_t ii = m_loaders.count(); ii--; ) 64 | { 65 | _names[ii] = m_loaders[ii].m_name; 66 | } 67 | } 68 | 69 | void getExtensions(const char* _extensions[CS_MAX_GEOMETRY_LOADERS]) const 70 | { 71 | for (uint8_t ii = m_loaders.count(); ii--; ) 72 | { 73 | _extensions[ii] = m_loaders[ii].m_ext; 74 | } 75 | } 76 | 77 | uint8_t count() const 78 | { 79 | return m_loaders.count(); 80 | } 81 | 82 | bool load(Geometry& _geometry, dm::ReaderSeekerI* _reader, const char* _fileExtension, dm::StackAllocatorI* _stack, void* _inData, OutDataHeader** _outData, bx::ReallocatorI* _outDataAlloc = dm::mainAlloc) 83 | { 84 | for (uint8_t ii = m_loaders.count(); ii--; ) 85 | { 86 | if (0 == bx::stricmp(m_loaders[ii].m_ext, _fileExtension)) 87 | { 88 | return m_loaders[ii].m_loadFunc(_geometry, _reader, _stack, _inData, _outData, _outDataAlloc); 89 | } 90 | } 91 | return false; 92 | } 93 | 94 | bool load(Geometry& _geometry, const char* _path, dm::StackAllocatorI* _stack, void* _inData, OutDataHeader** _outData, bx::ReallocatorI* _outDataAlloc = dm::mainAlloc) 95 | { 96 | dm::CrtFileReader fileReader; 97 | if (fileReader.open(_path)) 98 | { 99 | CS_CHECK(false, "Could not open file %s for reading.", _path); 100 | return false; 101 | } 102 | 103 | const char* ext = dm::fileExt(_path); 104 | const bool result = load(_geometry, &fileReader, ext, _stack, _inData, _outData, _outDataAlloc); 105 | 106 | fileReader.close(); 107 | 108 | return result; 109 | } 110 | 111 | bool load(Geometry& _geometry, const void* _data, size_t _size, const char* _ext, dm::StackAllocatorI* _stack, void* _inData, OutDataHeader** _outData, bx::ReallocatorI* _outDataAlloc = dm::mainAlloc) 112 | { 113 | dm::MemoryReader reader(_data, (uint32_t)_size); // Notice: size is limited to 32bit. 114 | return load(_geometry, &reader, _ext, _stack, _inData, _outData, _outDataAlloc); 115 | } 116 | 117 | private: 118 | dm::ObjArrayT m_loaders; 119 | }; 120 | static GeometryLoaders s_geometryLoaders; 121 | 122 | void geometryLoaderRegister(const char* _name, const char* _ext, GeometryLoadFn _loadFunc) 123 | { 124 | s_geometryLoaders.registerLoader(_name, _ext, _loadFunc); 125 | } 126 | 127 | void geometryLoaderUnregisterByName(const char* _name) 128 | { 129 | s_geometryLoaders.unregisterLoaderByName(_name); 130 | } 131 | 132 | void geometryLoaderUnregisterByExt(const char* _ext) 133 | { 134 | s_geometryLoaders.unregisterLoaderByExt(_ext); 135 | } 136 | 137 | void geometryLoaderGetNames(const char* _names[CS_MAX_GEOMETRY_LOADERS]) 138 | { 139 | s_geometryLoaders.getNames(_names); 140 | } 141 | 142 | void geometryLoaderGetExtensions(const char* _extensions[CS_MAX_GEOMETRY_LOADERS]) 143 | { 144 | s_geometryLoaders.getExtensions(_extensions); 145 | } 146 | 147 | uint8_t geometryLoaderCount() 148 | { 149 | return s_geometryLoaders.count(); 150 | } 151 | 152 | bool geometryLoad(Geometry& _geometry, const char* _path, dm::StackAllocatorI* _stack, void* _inData, OutDataHeader** _outData, bx::ReallocatorI* _outDataAlloc) 153 | { 154 | return s_geometryLoaders.load(_geometry, _path, _stack, _inData, _outData, _outDataAlloc); 155 | } 156 | 157 | bool geometryLoad(Geometry& _geometry, const void* _data, size_t _size, const char* _ext, dm::StackAllocatorI* _stack, void* _inData, OutDataHeader** _outData, bx::ReallocatorI* _outDataAlloc) 158 | { 159 | return s_geometryLoaders.load(_geometry, _data, _size, _ext, _stack, _inData, _outData, _outDataAlloc); 160 | } 161 | 162 | bool geometryLoad(Geometry& _geometry, dm::ReaderSeekerI* _reader, const char* _ext, dm::StackAllocatorI* _stack, void* _inData, OutDataHeader** _outData, bx::ReallocatorI* _outDataAlloc) 163 | { 164 | return s_geometryLoaders.load(_geometry, _reader, _ext, _stack, _inData, _outData, _outDataAlloc); 165 | } 166 | 167 | } // namespace cs 168 | 169 | /* vim: set sw=4 ts=4 expandtab: */ 170 | -------------------------------------------------------------------------------- /src/geometry/loadermanager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_LOADERMANAGER_H_HEADER_GUARD 7 | #define CMFTSTUDIO_LOADERMANAGER_H_HEADER_GUARD 8 | 9 | #include "../common/common.h" 10 | 11 | #include "geometry.h" // Geometry 12 | #include // dm::ReaderSeekerI 13 | 14 | #define BGFX_CHUNK_MAGIC_VB BX_MAKEFOURCC('V', 'B', ' ', 0x1) 15 | #define BGFX_CHUNK_MAGIC_IB BX_MAKEFOURCC('I', 'B', ' ', 0x0) 16 | #define BGFX_CHUNK_MAGIC_PRI BX_MAKEFOURCC('P', 'R', 'I', 0x0) 17 | #define CMFTSTUDIO_CHUNK_MAGIC_MSH_MISC BX_MAKEFOURCC('M', 'S', 'H', 0x2) 18 | #define CMFTSTUDIO_CHUNK_MAGIC_MSH_DONE BX_MAKEFOURCC('M', 'S', 'H', 0x3) 19 | 20 | namespace cs 21 | { 22 | struct FileFormat 23 | { 24 | enum 25 | { 26 | Undefined, 27 | 28 | BgfxBin, 29 | Obj, 30 | }; 31 | }; 32 | 33 | struct OutDataHeader 34 | { 35 | uint16_t m_format; 36 | }; 37 | typedef bool (*GeometryLoadFn)(Geometry& _geometry 38 | , dm::ReaderSeekerI* _reader 39 | , dm::StackAllocatorI* _stack 40 | , void* _inData 41 | , OutDataHeader** _outData 42 | , bx::ReallocatorI* _outDataAlloc 43 | ); 44 | 45 | void geometryLoaderRegister(const char* _name, const char* _ext, GeometryLoadFn _loadFunc); 46 | void geometryLoaderUnregisterByName(const char* _name); 47 | void geometryLoaderUnregisterByExt(const char* _ext); 48 | 49 | void geometryLoaderGetNames(const char* _names[CS_MAX_GEOMETRY_LOADERS]); 50 | void geometryLoaderGetExtensions(const char* _extensions[CS_MAX_GEOMETRY_LOADERS]); 51 | uint8_t geometryLoaderCount(); 52 | 53 | bool geometryLoad(Geometry& _geometry 54 | , const char* _path 55 | , dm::StackAllocatorI* _stack = dm::stackAlloc 56 | , void* _inData = NULL 57 | , OutDataHeader** _outData = NULL 58 | , bx::ReallocatorI* _outDataAlloc = dm::mainAlloc 59 | ); 60 | bool geometryLoad(Geometry& _geometry 61 | , const void* _data, size_t _size, const char* _ext 62 | , dm::StackAllocatorI* _stack = dm::stackAlloc 63 | , void* _inData = NULL 64 | , OutDataHeader** _outData = NULL 65 | , bx::ReallocatorI* _outDataAlloc = dm::mainAlloc 66 | ); 67 | bool geometryLoad(Geometry& _geometry 68 | , dm::ReaderSeekerI* _reader, const char* _ext 69 | , dm::StackAllocatorI* _stack = dm::stackAlloc 70 | , void* _inData = NULL 71 | , OutDataHeader** _outData = NULL 72 | , bx::ReallocatorI* _outDataAlloc = dm::mainAlloc 73 | ); 74 | 75 | } // namespace cs 76 | 77 | #endif // CMFTSTUDIO_LOADERMANAGER_H_HEADER_GUARD 78 | 79 | /* vim: set sw=4 ts=4 expandtab: */ 80 | -------------------------------------------------------------------------------- /src/geometry/loaders.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_LOADERS_H_HEADER_GUARD 7 | #define CMFTSTUDIO_LOADERS_H_HEADER_GUARD 8 | 9 | #include "../common/common.h" 10 | #include "loadermanager.h" 11 | 12 | #include "loader_bgfxbin.h" 13 | #include "loader_obj.h" 14 | 15 | static inline void initGeometryLoaders() 16 | { 17 | // Initialize geometry loaders. 18 | geometryLoaderRegister("Wavefront obj", "obj", loaderObj); 19 | geometryLoaderRegister("Bgfx bin loader", "bin", loaderBgfxBin); 20 | } 21 | 22 | #endif // CMFTSTUDIO_LOADERS_H_HEADER_GUARD 23 | 24 | /* vim: set sw=4 ts=4 expandtab: */ 25 | -------------------------------------------------------------------------------- /src/geometry/objtobin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_OBJTOBIN_H_HEADER_GUARD 7 | #define CMFTSTUDIO_OBJTOBIN_H_HEADER_GUARD 8 | 9 | #include 10 | 11 | namespace bx 12 | { 13 | struct WriterSeekerI; 14 | struct ReallocatorI; 15 | } 16 | 17 | uint32_t objToBin(const char* _filePath 18 | , bx::WriterSeekerI* _writer 19 | , uint32_t _packUv = 0 20 | , uint32_t _packNormal = 0 21 | , bool _ccw = false 22 | , bool _flipV = false 23 | , bool _hasTangent = false 24 | , float _scale = 1.0f 25 | ); 26 | uint32_t objToBin(const char* _filePath 27 | , void*& _outData 28 | , uint32_t& _outDataSize 29 | , bx::ReallocatorI* _allocator 30 | , uint32_t _packUv = 0 31 | , uint32_t _packNormal = 0 32 | , bool _ccw = false 33 | , bool _flipV = false 34 | , bool _hasTangent = false 35 | , float _scale = 1.0f 36 | ); 37 | uint32_t objToBin(const uint8_t* _objData 38 | , bx::WriterSeekerI* _writer 39 | , uint32_t _packUv = 0 40 | , uint32_t _packNormal = 0 41 | , bool _ccw = false 42 | , bool _flipV = false 43 | , bool _hasTangent = false 44 | , float _scale = 1.0f 45 | ); 46 | uint32_t objToBin(const uint8_t* _objData 47 | , void*& _outData 48 | , uint32_t& _outDataSize 49 | , bx::ReallocatorI* _allocator 50 | , uint32_t _packUv = 0 51 | , uint32_t _packNormal = 0 52 | , bool _ccw = false 53 | , bool _flipV = false 54 | , bool _hasTangent = false 55 | , float _scale = 1.0f 56 | ); 57 | 58 | #endif // CMFTSTUDIO_OBJTOBIN_H_HEADER_GUARD 59 | 60 | /* vim: set sw=4 ts=4 expandtab: */ 61 | -------------------------------------------------------------------------------- /src/gui_res.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | // Font. 7 | //----- 8 | 9 | #if !defined(FONT_DESC_FILE) 10 | #define FONT_DESC_FILE(_name, _fontSize, _path) 11 | #endif //!defined(FONT_DESC_FILE) 12 | //FONT_DESC_FILE( DroidSansMono, 14.0f, "font/DroidSansMono.ttf" ) 13 | //FONT_DESC_FILE( StatusFont, 18.0f, "font/DroidSans.ttf" ) 14 | #undef FONT_DESC_FILE 15 | 16 | #if !defined(FONT_DESC_MEM) 17 | #define FONT_DESC_MEM(_name, _fontSize, _data) 18 | #endif //!defined(FONT_DESC_MEM) 19 | FONT_DESC_MEM( DroidSansMono, 14.0f, g_droidSansMono ) 20 | FONT_DESC_MEM( StatusFont, 18.0f, g_droidSans ) 21 | #undef FONT_DESC_MEM 22 | 23 | // Resources. 24 | //----- 25 | 26 | #ifndef RES_DESC 27 | #define RES_DESC(_defaultFont, _defaultFontDataSize, _defaultFontSize, _sunIconData, _sunIconDataSize) 28 | #endif //!defined(RES_DESC) 29 | RES_DESC(g_droidSans, g_droidSansSize, 15.0f, g_sunIcon, g_sunIconSize) 30 | #undef RES_DESC 31 | 32 | // About text. 33 | //----- 34 | 35 | #ifndef ABOUT_LINE 36 | #define ABOUT_LINE(_str) 37 | #endif //!defined(ABOUT_LINE) 38 | ABOUT_LINE("-------------------------------------------------------------------------------") 39 | ABOUT_LINE("cmftStudio v1.1") 40 | ABOUT_LINE("Copyright 2014-2015 Dario Manesku. All rights reserved.") 41 | ABOUT_LINE("https://github.com/dariomanesku/cmftStudio") 42 | ABOUT_LINE("-------------------------------------------------------------------------------") 43 | ABOUT_LINE("") 44 | ABOUT_LINE("Controls:") 45 | ABOUT_LINE(" Ctrl/Meta + F -> Toggle full screen.") 46 | ABOUT_LINE(" Ctrl/Meta + Q -> Quit application.") 47 | ABOUT_LINE("") 48 | ABOUT_LINE("All features related to cubemap filtering are also available for use from the command-line interface.") 49 | ABOUT_LINE("Check out cmft project - https://github.com/dariomanesku/cmft") 50 | ABOUT_LINE("") 51 | ABOUT_LINE("") 52 | ABOUT_LINE("Feel free to reach me at any time on Github or Twitter @dariomanesku.") 53 | #undef ABOUT_LINE 54 | 55 | /* vim: set sw=4 ts=4 expandtab: */ 56 | -------------------------------------------------------------------------------- /src/guimanager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_GUIMANAGER_H_HEADER_GUARD 7 | #define CMFTSTUDIO_GUIMANAGER_H_HEADER_GUARD 8 | 9 | #include "common/common.h" 10 | #include "gui.h" 11 | #include 12 | 13 | // Imgui status. 14 | //----- 15 | 16 | struct StatusWindowId 17 | { 18 | enum Enum 19 | { 20 | None, 21 | 22 | LoadWarning, 23 | LoadError, 24 | 25 | FilterIem, 26 | FilterPmrem, 27 | 28 | WarpFilterInfo0, 29 | WarpFilterInfo1, 30 | 31 | ProjectSave, 32 | ProjectLoad, 33 | 34 | MeshConversion, 35 | }; 36 | }; 37 | 38 | void imguiStatusMessage(const char* _msg 39 | , float _durationSec 40 | , bool _isWarning = false 41 | , const char* _button = NULL 42 | , uint16_t _buttonEvent = 0 43 | , StatusWindowId::Enum _id = StatusWindowId::None 44 | ); 45 | void imguiRemoveStatusMessage(StatusWindowId::Enum _id); 46 | uint16_t imguiGetStatusEvent(); 47 | 48 | // Output window. 49 | //----- 50 | 51 | void outputWindowInit(OutputWindowState* _state); 52 | void outputWindowPrint(const char* _format, ...); 53 | void outputWindowClear(); 54 | void outputWindowShow(); 55 | 56 | // Widgets. 57 | //----- 58 | 59 | struct Widget 60 | { 61 | enum Enum 62 | { 63 | // LeftSideWidget 64 | MeshSaveWidget = 0x00000001, 65 | MeshBrowser = 0x00000002, 66 | TexPickerAlbedo = 0x00000004, 67 | TexPickerNormal = 0x00000008, 68 | TexPickerSurface = 0x00000010, 69 | TexPickerReflectivity = 0x00000020, 70 | TexPickerOcclusion = 0x00000040, 71 | TexPickerEmissive = 0x00000080, 72 | TexPickerMask = 0x000000fc, 73 | LeftSideWidgetMask = 0x000000ff, 74 | LeftSideWidgetShift = 0, 75 | 76 | // LeftSideSubwidget 77 | TextureFileBrowser = 0x00000100, 78 | LeftSideSubWidgetMask = 0x00000100, 79 | LeftSideSubWidgetShift = 8, 80 | 81 | // RightSideWidget 82 | EnvWidget = 0x00000200, 83 | RightSideWidgetMask = 0x00000200, 84 | RightSideWidgetShift = 9, 85 | 86 | // RightSideSubwidget 87 | CmftInfoSkyboxWidget = 0x00000400, 88 | CmftInfoPmremWidget = 0x00000800, 89 | CmftInfoIemWidget = 0x00001000, 90 | CmftSaveSkyboxWidget = 0x00002000, 91 | CmftSavePmremWidget = 0x00004000, 92 | CmftSaveIemWidget = 0x00008000, 93 | CmftPmremWidget = 0x00010000, 94 | CmftIemWidget = 0x00020000, 95 | CmftTransformWidget = 0x00040000, 96 | TonemapWidget = 0x00080000, 97 | SkyboxBrowser = 0x00100000, 98 | PmremBrowser = 0x00200000, 99 | IemBrowser = 0x00400000, 100 | RightSideSubwidgetMask = 0x007ffc00, 101 | RightSideSubwidgetShift = 10, 102 | 103 | // ModalWindow 104 | OutputWindow = 0x00800000, 105 | AboutWindow = 0x01000000, 106 | ProjectWindow = 0x02000000, 107 | MagnifyWindow = 0x04000000, 108 | ModalWindowMask = 0x07800000, 109 | ModalWindowShift = 23, 110 | 111 | // ScrollArea 112 | Left = 0x08000000, 113 | Right = 0x10000000, 114 | ScrollAreaMask = 0x18000000, 115 | ScrollAreaShift = 26, 116 | }; 117 | }; 118 | 119 | void widgetShow(Widget::Enum _widget); 120 | void widgetHide(Widget::Enum _widget); 121 | void widgetHide(uint64_t _mask); 122 | void widgetToggle(Widget::Enum _widget); 123 | void widgetSetOrClear(Widget::Enum _widget, uint64_t _mask); 124 | bool widgetIsVisible(Widget::Enum _widget); 125 | 126 | /// Draws entire gui. 127 | bool guiDraw(ImguiState& _guiState 128 | , Settings& _settings 129 | , GuiWidgetState& _widgetStates 130 | , const Mouse& _mouse 131 | , char _ascii 132 | , float _deltaTime 133 | , cs::MeshInstanceList& _meshInstList 134 | , const cs::TextureList& _textureList 135 | , const cs::MaterialList& _materialList 136 | , const cs::EnvList& _envList 137 | , float _widgetAnimDuration = 0.1f 138 | , float _modalWindowAnimDuration = 0.06f 139 | , uint8_t _viewId = RenderPipeline::ViewIdGui 140 | ); 141 | 142 | #endif // CMFTSTUDIO_GUIMANAGER_H_HEADER_GUARD 143 | 144 | /* vim: set sw=4 ts=4 expandtab: */ 145 | -------------------------------------------------------------------------------- /src/inflatedeflate.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #include "common/common.h" 7 | 8 | // Include minz implementation. 9 | #define MZ_MALLOC(x) DM_ALLOC(dm::stackAlloc, x) 10 | #define MZ_FREE(x) DM_FREE(dm::stackAlloc, x) 11 | #define MZ_REALLOC(p, x) DM_REALLOC(dm::stackAlloc, p, x) 12 | #define MINIZ_NO_MALLOC 13 | #include "common/miniz.h" 14 | 15 | /* vim: set sw=4 ts=4 expandtab: */ 16 | -------------------------------------------------------------------------------- /src/mouse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTVIEWER_MOUSE_H_HEADER_GUARD 7 | #define CMFTVIEWER_MOUSE_H_HEADER_GUARD 8 | 9 | #include //uint8_t 10 | #include //entry::MouseState 11 | 12 | struct Mouse 13 | { 14 | Mouse() 15 | { 16 | m_vx = 0.0f; 17 | m_vy = 0.0f; 18 | 19 | m_dx = 0.0f; 20 | m_dy = 0.0f; 21 | 22 | m_scroll = 0; 23 | m_scrollPrev = 0; 24 | 25 | m_left = 0; 26 | m_middle = 0; 27 | m_right = 0; 28 | } 29 | 30 | void update(entry::MouseState& _mouseState, uint32_t _width, uint32_t _height) 31 | { 32 | const float widthf = float(int32_t(_width)); 33 | const float heightf = float(int32_t(_height)); 34 | 35 | const uint8_t buttonEnumIds[ButtonCount] = 36 | { 37 | entry::MouseButton::Left, 38 | entry::MouseButton::Middle, 39 | entry::MouseButton::Right 40 | }; 41 | 42 | //Buttons. 43 | memcpy(&m_curr, &_mouseState, sizeof(entry::MouseState)); 44 | 45 | for (uint8_t btn = 0; btn < ButtonCount; ++btn) 46 | { 47 | const uint8_t p = m_prev.m_buttons[buttonEnumIds[btn]]; 48 | const uint8_t c = m_curr.m_buttons[buttonEnumIds[btn]] << 1; 49 | m_buttons[btn] = p|c; 50 | } 51 | 52 | if (Down == (m_left|m_middle|m_right)) 53 | { 54 | m_prev.m_mx = m_curr.m_mx; 55 | m_prev.m_my = m_curr.m_my; 56 | m_prev.m_mz = m_curr.m_mz; 57 | } 58 | 59 | memcpy(&m_prev.m_buttons, &m_curr.m_buttons, sizeof(m_prev.m_buttons)); 60 | 61 | // Screen position. 62 | m_vx = 2.0f*m_curr.m_mx/widthf - 1.0f; 63 | m_vy = 2.0f*m_curr.m_my/heightf - 1.0f; 64 | 65 | // Delta movement. 66 | m_dx = float(m_curr.m_mx - m_prev.m_mx)/widthf; 67 | m_dy = float(m_curr.m_my - m_prev.m_my)/heightf; 68 | m_prev.m_mx = m_curr.m_mx; 69 | m_prev.m_my = m_curr.m_my; 70 | m_prev.m_mz = m_curr.m_mz; 71 | 72 | // Scroll. 73 | int32_t scrollNow = m_curr.m_mz; 74 | m_scroll = scrollNow - m_scrollPrev; 75 | m_scrollPrev = scrollNow; 76 | } 77 | 78 | enum Enum 79 | { 80 | None = 0x0, 81 | Down = 0x2, 82 | Hold = 0x3, 83 | Up = 0x1, 84 | }; 85 | 86 | enum 87 | { 88 | ButtonCount = 3, 89 | }; 90 | 91 | float m_vx; // Screen space [-1.0, 1.0]. 92 | float m_vy; 93 | float m_dx; // Screen space. 94 | float m_dy; 95 | int32_t m_scroll; 96 | int32_t m_scrollPrev; 97 | union 98 | { 99 | struct 100 | { 101 | uint8_t m_left; 102 | uint8_t m_middle; 103 | uint8_t m_right; 104 | }; 105 | 106 | uint8_t m_buttons[3]; 107 | }; 108 | entry::MouseState m_curr; 109 | entry::MouseState m_prev; 110 | }; 111 | 112 | #endif // CMFTSTUDIO_MOUSE_H_HEADER_GUARD 113 | 114 | /* vim: set sw=4 ts=4 expandtab: */ 115 | -------------------------------------------------------------------------------- /src/project.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_PROJECT_H_HEADER_GUARD 7 | #define CMFTSTUDIO_PROJECT_H_HEADER_GUARD 8 | 9 | #include "context.h" // cs::MaterialList,EnvList,MeshInstanceList 10 | 11 | struct CmftStudioProject 12 | { 13 | enum Error 14 | { 15 | FileIOError, 16 | InvalidMagic, 17 | InvalidVersion, 18 | }; 19 | }; 20 | 21 | typedef void (*OnValidFile)(uint32_t _flags, const void* _data); 22 | typedef void (*OnInvalidFile)(uint32_t _flags, const void* _data); 23 | 24 | struct Settings; 25 | 26 | bool projectSave(const char* _path 27 | , const cs::MaterialList& _materialList 28 | , const cs::EnvList& _envList 29 | , const cs::MeshInstanceList& _meshInstList 30 | , const Settings& _savedSettings 31 | , int32_t _compressionLevel = 6 /*from 0 to 10*/ 32 | , OnValidFile _validFileCallback = NULL 33 | , OnInvalidFile _invalidFileCallback = NULL 34 | , dm::StackAllocatorI* _stackAlloc = dm::stackAlloc 35 | ); 36 | 37 | bool projectLoad(const char* _path 38 | , cs::TextureList& _textureList 39 | , cs::MaterialList& _materialList 40 | , cs::EnvList& _envList 41 | , cs::MeshInstanceList& _meshInstList 42 | , Settings& _settings 43 | , OnValidFile _validFileCallback = NULL 44 | , OnInvalidFile _invalidFileCallback = NULL 45 | , dm::StackAllocatorI* _stackAlloc = dm::stackAlloc 46 | ); 47 | 48 | #endif // CMFTSTUDIO_PROJECT_H_HEADER_GUARD 49 | 50 | /* vim: set sw=4 ts=4 expandtab: */ 51 | -------------------------------------------------------------------------------- /src/renderpipeline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_RENDERPIPELINE_H_HEADER_GUARD 7 | #define CMFTSTUDIO_RENDERPIPELINE_H_HEADER_GUARD 8 | 9 | #include // uint32_t 10 | #include "context.h" // cs::* 11 | 12 | namespace bgfx { struct TextureHandle; } 13 | 14 | // Utils. 15 | //----- 16 | 17 | // Must be called before screenSpaceQuad(), screenQuad() and drawSplashScreen(). 18 | void initVertexDecls(); 19 | 20 | // Full screen quad. 21 | void screenSpaceQuad(float _textureWidth 22 | , float _textureHeight 23 | , bool _originBottomLeft = false 24 | , float _width = 1.0f 25 | , float _height = 1.0f 26 | ); 27 | void screenQuad(int32_t _x, int32_t _y, int32_t _width, int32_t _height, bool _originBottomLeft = false); 28 | void drawSplashScreen(cs::TextureHandle _texture, uint32_t _width, uint32_t _height); 29 | 30 | // Render pipeline. 31 | //----- 32 | 33 | struct RenderPipeline 34 | { 35 | enum 36 | { 37 | ViewIdSkybox, 38 | ViewIdMesh, 39 | ViewIdLum0, 40 | ViewIdLum1, 41 | ViewIdLum2, 42 | ViewIdLum3, 43 | ViewIdLum4, 44 | ViewIdBright, 45 | ViewIdBloom, 46 | ViewIdTonemap, 47 | ViewIdFxaa, 48 | ViewIdMaterial, 49 | ViewIdTonemapImage, 50 | ViewIdWireframe, 51 | ViewIdUpdateLastLum, 52 | ViewIdSplashScreen, 53 | 54 | ViewIdDebug0, 55 | ViewIdDebug1, 56 | ViewIdDebug2, 57 | ViewIdDebug3, 58 | ViewIdDebug4, 59 | ViewIdDebug5, 60 | 61 | ViewIdGui, 62 | }; 63 | }; 64 | 65 | void renderPipelineInit(uint32_t _width, uint32_t _height, uint32_t _reset); 66 | 67 | void renderPipelineUpdateSize(uint32_t _width, uint32_t _height, uint32_t _reset); 68 | void renderPipelineSetupFrame(bool _doLightAdapt, bool _doBloom, bool _doFxaa); 69 | void renderPipelineSetActiveCamera(float* _camView, float* _camProj); 70 | void renderPipelineSubmitSkybox(cs::EnvHandle _env, cs::Environment::Enum _which = cs::Environment::Skybox, float _lod = 0.0f); 71 | void renderPipelineSubmitSkybox(cs::EnvHandle _nextEnv 72 | , cs::EnvHandle _currEnv 73 | , float _progress = 0.0f 74 | , cs::Environment::Enum _nextWhich = cs::Environment::Skybox 75 | , cs::Environment::Enum _currWhich = cs::Environment::Skybox 76 | , float _nextLod = 0.0f 77 | , float _currLod = 0.0f 78 | ); 79 | void renderPipelineSubmitFrame(float _bloomStdDev = 0.8f); 80 | void renderPipelineFlush(); 81 | void renderPipelineCleanup(); 82 | 83 | void updateWireframePreview(cs::MeshHandle _mesh, uint16_t _groupIdx = 0); 84 | void updateMaterialPreview(cs::MaterialHandle _material, cs::EnvHandle _env, const float _eye[3]); 85 | void updateTonemapImage(cs::TextureHandle _image, float _gamma, float _minLum, float _lumRange); 86 | bgfx::TextureHandle getWireframeTexture(); 87 | bgfx::TextureHandle getMaterialTexture(); 88 | bgfx::TextureHandle getTonemapTexture(); 89 | 90 | #endif // CMFTSTUDIO_RENDERPIPELINE_H_HEADER_GUARD 91 | 92 | /* vim: set sw=4 ts=4 expandtab: */ 93 | -------------------------------------------------------------------------------- /src/shaders/fs_blur.sc: -------------------------------------------------------------------------------- 1 | $input v_texcoord0, v_texcoord1, v_texcoord2, v_texcoord3, v_texcoord4 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #include "shader.shdr" 9 | #include "utils.shdr" 10 | 11 | SAMPLER2D(u_texColor, 0); 12 | 13 | void main() 14 | { 15 | gl_FragColor = blur9(u_texColor 16 | , v_texcoord0 17 | , v_texcoord1 18 | , v_texcoord2 19 | , v_texcoord3 20 | , v_texcoord4 21 | , u_weight0 22 | , u_weight1 23 | , u_weight2 24 | , u_weight3 25 | , u_weight4 26 | ); 27 | } 28 | 29 | /* vim: set sw=4 ts=4 expandtab: */ 30 | -------------------------------------------------------------------------------- /src/shaders/fs_bright.sc: -------------------------------------------------------------------------------- 1 | $input v_texcoord0 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #include "shader.shdr" 9 | #include "utils.shdr" 10 | #include "tonemap.shdr" 11 | 12 | SAMPLER2D(u_texColor, 0); 13 | SAMPLER2D(u_texLum, 1); 14 | 15 | void main() 16 | { 17 | float lumAvg; 18 | if (1.0 == u_doLightAdapt) 19 | { 20 | lumAvg = clamp(decodeRE8(texture2D(u_texLum, v_texcoord0)), 0.1, 1.0); 21 | } 22 | else 23 | { 24 | lumAvg = 0.18; 25 | } 26 | //float middleGray = 1.03 - 2.0/(2.0+log10(lumAvg+1.0)); 27 | float middleGray = u_middleGray; 28 | 29 | vec3 rgb = vec3(0.0, 0.0, 0.0); 30 | rgb += decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets0)); 31 | rgb += decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets1)); 32 | rgb += decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets2)); 33 | rgb += decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets3)); 34 | rgb += decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets4)); 35 | rgb += decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets5)); 36 | rgb += decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets6)); 37 | rgb += decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets7)); 38 | rgb += decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets8)); 39 | rgb *= 1.0/9.0; 40 | 41 | float lumRgb = lumf(rgb); 42 | float lumScale = lumRgb * middleGray / (lumAvg+0.0001); 43 | float lumScale2 = max(0.0, lumScale*(1.0+lumScale/u_whiteSqr)-u_treshold); 44 | rgb *= (lumScale2/lumRgb); 45 | 46 | rgb = tonemap(rgb, u_whiteSqr); 47 | 48 | gl_FragColor = vec4(rgb, 1.0); 49 | } 50 | 51 | /* vim: set sw=4 ts=4 expandtab: */ 52 | -------------------------------------------------------------------------------- /src/shaders/fs_color.sc: -------------------------------------------------------------------------------- 1 | $input 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #include "shader.shdr" 9 | 10 | void main() 11 | { 12 | gl_FragColor = u_rgba; 13 | } 14 | 15 | /* vim: set sw=4 ts=4 expandtab: */ 16 | -------------------------------------------------------------------------------- /src/shaders/fs_cubemap_tonemap.sc: -------------------------------------------------------------------------------- 1 | $input v_texcoord0 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #include "shader.shdr" 9 | #include "utils.shdr" 10 | 11 | SAMPLERCUBE(u_texSkybox, 5); 12 | 13 | void main() 14 | { 15 | vec3 dir = vecFromLatLong(v_texcoord0); 16 | vec3 color = textureCube(u_texSkybox, dir).xyz; 17 | 18 | // Apply gamma. 19 | vec3 gamma = vec3_splat(u_tonemapGamma); 20 | color = pow(abs(color), gamma); 21 | 22 | // Normalize. 23 | color = (color-u_tonemapMinLum)/u_tonemapLumRange; 24 | 25 | gl_FragColor.xyz = color; 26 | gl_FragColor.w = 1.0; 27 | } 28 | 29 | /* vim: set sw=4 ts=4 expandtab: */ 30 | -------------------------------------------------------------------------------- /src/shaders/fs_equals.sc: -------------------------------------------------------------------------------- 1 | $input v_texcoord0 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #include "shader.shdr" 9 | 10 | SAMPLER2D(u_texColor, 0); 11 | 12 | void main() 13 | { 14 | gl_FragColor = texture2D(u_texColor, v_texcoord0); 15 | } 16 | 17 | /* vim: set sw=4 ts=4 expandtab: */ 18 | -------------------------------------------------------------------------------- /src/shaders/fs_fxaa.sc: -------------------------------------------------------------------------------- 1 | $input v_texcoord0 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #include "shader.shdr" 9 | 10 | SAMPLER2D(u_texColor, 0); 11 | 12 | // FXAA 3.11 by Timothy Lottes 13 | //----- 14 | 15 | #define FXAA_PC 1 16 | #define FXAA_GLSL_120 1 17 | #define FXAA_GREEN_AS_LUMA 1 18 | #define FXAA_QUALITY__PRESET 39 19 | #define FXAA_FAST_PIXEL_OFFSET 0 20 | #define FXAA_GATHER4_ALPHA 0 21 | #include "fxaa3_11.h" 22 | 23 | vec4 fxaa_311(sampler2D _sampler, vec2 _coord, vec2 _invScrSize, float _quality, float _treshold, float _tresholdMin) 24 | { 25 | return FxaaPixelShader(_coord*_invScrSize //pos 26 | , vec4_splat(0.0) //fxaaConsolePosPos - placeholder 27 | , _sampler //tex 28 | , _sampler //fxaaConsole360TexExpBiasNegOne - placeholder 29 | , _sampler //fxaaConsole360TexExpBiasNegTwo - placeholder 30 | , _invScrSize //fxaaQualityRcpFrame 31 | , vec4_splat(0.0) //fxaaConsoleRcpFrameOpt - placeholder 32 | , vec4_splat(0.0) //fxaaConsoleRcpFrameOpt2 - placeholder 33 | , vec4_splat(0.0) //fxaaConsole360RcpFrameOpt2 - placeholder 34 | , _quality //fxaaQualitySubpix 35 | , _treshold //fxaaQualityEdgeThreshold 36 | , _tresholdMin //fxaaQualityEdgeThresholdMin 37 | , 0.0 //fxaaConsoleEdgeSharpness - placeholder 38 | , 0.0 //fxaaConsoleEdgeThreshold - placeholder 39 | , 0.0 //fxaaConsoleEdgeThresholdMin - placeholder 40 | , vec4_splat(0.0) //fxaaConsole360ConstDir - placeholder 41 | ); 42 | } 43 | 44 | vec4 fxaa_311(sampler2D _sampler, vec2 _coord, vec2 _invScrSize) 45 | { 46 | float quality = 1.0; 47 | float treshold = 0.063; 48 | float tresholdMin = 0.0312; 49 | 50 | return fxaa_311(_sampler, _coord, _invScrSize, quality, treshold, tresholdMin); 51 | } 52 | 53 | void main() 54 | { 55 | vec4 color = fxaa_311(u_texColor, gl_FragCoord.xy+u_texelHalf, u_viewTexel.xy); 56 | gl_FragColor = color; 57 | } 58 | 59 | /* vim: set sw=4 ts=4 expandtab: */ 60 | -------------------------------------------------------------------------------- /src/shaders/fs_image.sc: -------------------------------------------------------------------------------- 1 | $input v_texcoord0 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #include "shader.shdr" 9 | 10 | SAMPLER2D(u_texColor, 0); 11 | 12 | void main() 13 | { 14 | vec4 color = texture2D(u_texColor, v_texcoord0); 15 | 16 | gl_FragColor.xyz = color.xyz; 17 | gl_FragColor.w = 1.0; 18 | } 19 | 20 | /* vim: set sw=4 ts=4 expandtab: */ 21 | -------------------------------------------------------------------------------- /src/shaders/fs_image_re8.sc: -------------------------------------------------------------------------------- 1 | $input v_texcoord0 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #include "shader.shdr" 9 | #include "utils.shdr" 10 | 11 | SAMPLER2D(u_texColor, 0); 12 | 13 | void main() 14 | { 15 | float lum = decodeRE8(texture2D(u_texColor, v_texcoord0)); 16 | 17 | gl_FragColor.xyz = vec3_splat(lum); 18 | gl_FragColor.w = 1.0; 19 | } 20 | 21 | /* vim: set sw=4 ts=4 expandtab: */ 22 | -------------------------------------------------------------------------------- /src/shaders/fs_latlong.sc: -------------------------------------------------------------------------------- 1 | $input v_texcoord0 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #include "shader.shdr" 9 | #include "utils.shdr" 10 | 11 | SAMPLERCUBE(u_texSkybox, 5); 12 | 13 | void main() 14 | { 15 | vec3 dir = vecFromLatLong(v_texcoord0); 16 | vec3 color = textureCubeLod(u_texSkybox, dir, u_lod).xyz; 17 | float alpha = 0.2 + 0.8*u_enabled; 18 | 19 | gl_FragColor = vec4(color, alpha); 20 | } 21 | 22 | /* vim: set sw=4 ts=4 expandtab: */ 23 | -------------------------------------------------------------------------------- /src/shaders/fs_lum.sc: -------------------------------------------------------------------------------- 1 | $input v_texcoord0 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #include "shader.shdr" 9 | #include "utils.shdr" 10 | 11 | SAMPLER2D(u_texColor, 0); 12 | 13 | void main() 14 | { 15 | vec3 rgb0 = decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets0)); 16 | vec3 rgb1 = decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets1)); 17 | vec3 rgb2 = decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets2)); 18 | vec3 rgb3 = decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets3)); 19 | vec3 rgb4 = decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets4)); 20 | vec3 rgb5 = decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets5)); 21 | vec3 rgb6 = decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets6)); 22 | vec3 rgb7 = decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets7)); 23 | vec3 rgb8 = decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets8)); 24 | vec3 rgb9 = decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets9)); 25 | vec3 rgb10 = decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets10)); 26 | vec3 rgb11 = decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets11)); 27 | vec3 rgb12 = decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets12)); 28 | vec3 rgb13 = decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets13)); 29 | vec3 rgb14 = decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets14)); 30 | vec3 rgb15 = decodeRGBE8(texture2D(u_texColor, v_texcoord0+u_offsets15)); 31 | float avg = log(lumf(rgb0) + 0.00001) 32 | + log(lumf(rgb1) + 0.00001) 33 | + log(lumf(rgb2) + 0.00001) 34 | + log(lumf(rgb3) + 0.00001) 35 | + log(lumf(rgb4) + 0.00001) 36 | + log(lumf(rgb5) + 0.00001) 37 | + log(lumf(rgb6) + 0.00001) 38 | + log(lumf(rgb7) + 0.00001) 39 | + log(lumf(rgb8) + 0.00001) 40 | + log(lumf(rgb9) + 0.00001) 41 | + log(lumf(rgb10) + 0.00001) 42 | + log(lumf(rgb11) + 0.00001) 43 | + log(lumf(rgb12) + 0.00001) 44 | + log(lumf(rgb13) + 0.00001) 45 | + log(lumf(rgb14) + 0.00001) 46 | + log(lumf(rgb15) + 0.00001) 47 | ; 48 | avg = exp(avg*(1.0/16.0)); 49 | 50 | gl_FragColor = encodeRE8(avg); 51 | } 52 | 53 | /* vim: set sw=4 ts=4 expandtab: */ 54 | -------------------------------------------------------------------------------- /src/shaders/fs_lumavg.sc: -------------------------------------------------------------------------------- 1 | $input v_texcoord0 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #include "shader.shdr" 9 | #include "utils.shdr" 10 | 11 | SAMPLER2D(u_texColor, 0); 12 | SAMPLER2D(u_texLum, 1); 13 | 14 | void main() 15 | { 16 | float last = decodeRE8(texture2D(u_texLum, v_texcoord0)); 17 | 18 | float sum; 19 | sum = decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets0)); 20 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets1)); 21 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets2)); 22 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets3)); 23 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets4)); 24 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets5)); 25 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets6)); 26 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets7)); 27 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets8)); 28 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets9)); 29 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets10)); 30 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets11)); 31 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets12)); 32 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets13)); 33 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets14)); 34 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets15)); 35 | float curr = sum*(1.0/16.0); 36 | 37 | float updateSpeed; 38 | if (0.1 < u_skyboxTransition && u_skyboxTransition < 0.95) 39 | { 40 | updateSpeed = mix(0.1, u_time, u_skyboxTransition); 41 | } 42 | else 43 | { 44 | updateSpeed = u_time; 45 | } 46 | 47 | float adapted = last + min(0.01, (curr - last)*updateSpeed); 48 | 49 | gl_FragColor = encodeRE8(adapted); 50 | } 51 | 52 | /* vim: set sw=4 ts=4 expandtab: */ 53 | -------------------------------------------------------------------------------- /src/shaders/fs_lumdownscale.sc: -------------------------------------------------------------------------------- 1 | $input v_texcoord0 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #include "shader.shdr" 9 | #include "utils.shdr" 10 | 11 | SAMPLER2D(u_texColor, 0); 12 | 13 | void main() 14 | { 15 | float sum; 16 | sum = decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets0)); 17 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets1)); 18 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets2)); 19 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets3)); 20 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets4)); 21 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets5)); 22 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets6)); 23 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets7)); 24 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets8)); 25 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets9)); 26 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets10)); 27 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets11)); 28 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets12)); 29 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets13)); 30 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets14)); 31 | sum += decodeRE8(texture2D(u_texColor, v_texcoord0+u_offsets15)); 32 | float avg = sum*(1.0/16.0); 33 | gl_FragColor = encodeRE8(avg); 34 | } 35 | 36 | /* vim: set sw=4 ts=4 expandtab: */ 37 | -------------------------------------------------------------------------------- /src/shaders/fs_mesh.sc: -------------------------------------------------------------------------------- 1 | $input v_view, v_normal, v_texcoord0 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #define DIRECTIONAL_LIGHT 9 | #include "fs_mesh.shdr" 10 | -------------------------------------------------------------------------------- /src/shaders/fs_mesh_normal.sc: -------------------------------------------------------------------------------- 1 | $input v_view, v_normal, v_tangent, v_bitangent, v_texcoord0 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #define DIRECTIONAL_LIGHT 9 | #define NORMAL_MAP 10 | #include "fs_mesh.shdr" 11 | -------------------------------------------------------------------------------- /src/shaders/fs_mesh_normal_rgbe8.sc: -------------------------------------------------------------------------------- 1 | $input v_view, v_normal, v_tangent, v_bitangent, v_texcoord0 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #define NORMAL_MAP 9 | #define DIRECTIONAL_LIGHT 10 | #define RGBE8_OUTPUT 11 | #include "fs_mesh.shdr" 12 | -------------------------------------------------------------------------------- /src/shaders/fs_mesh_normal_rgbe8_trans.sc: -------------------------------------------------------------------------------- 1 | $input v_view, v_normal, v_tangent, v_bitangent, v_texcoord0 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #define NORMAL_MAP 9 | #define DIRECTIONAL_LIGHT 10 | #define RGBE8_OUTPUT 11 | #define SKYBOX_TRANSITION 12 | #include "fs_mesh.shdr" 13 | -------------------------------------------------------------------------------- /src/shaders/fs_mesh_rgbe8.sc: -------------------------------------------------------------------------------- 1 | $input v_view, v_normal, v_texcoord0 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #define DIRECTIONAL_LIGHT 9 | #define RGBE8_OUTPUT 10 | #include "fs_mesh.shdr" 11 | -------------------------------------------------------------------------------- /src/shaders/fs_mesh_rgbe8_trans.sc: -------------------------------------------------------------------------------- 1 | $input v_view, v_normal, v_texcoord0 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #define DIRECTIONAL_LIGHT 9 | #define RGBE8_OUTPUT 10 | #define SKYBOX_TRANSITION 11 | #include "fs_mesh.shdr" 12 | -------------------------------------------------------------------------------- /src/shaders/fs_overlay.sc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | void main() 7 | { 8 | gl_FragColor = vec4(0.3, 0.3, 0.3, 0.5); 9 | } 10 | 11 | /* vim: set sw=4 ts=4 expandtab: */ 12 | -------------------------------------------------------------------------------- /src/shaders/fs_skybox.sc: -------------------------------------------------------------------------------- 1 | $input v_dir 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #include "shader.shdr" 9 | #include "utils.shdr" 10 | 11 | SAMPLERCUBE(u_texSkybox, 5); 12 | 13 | void main() 14 | { 15 | vec3 dir = normalize(v_dir); 16 | 17 | if (0.0 != u_edgeFixup) 18 | { 19 | dir = fixCubeLookup(dir, u_lod, u_mipSize); 20 | } 21 | 22 | vec3 color = toLinear(textureCubeLod(u_texSkybox, dir, u_lod).xyz); 23 | 24 | gl_FragColor = encodeRGBE8(color); 25 | } 26 | 27 | /* vim: set sw=4 ts=4 expandtab: */ 28 | -------------------------------------------------------------------------------- /src/shaders/fs_skybox_trans.sc: -------------------------------------------------------------------------------- 1 | $input v_dir 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #include "shader.shdr" 9 | #include "utils.shdr" 10 | 11 | SAMPLERCUBE(u_texSkybox, 5); // Destination skybox. 12 | SAMPLERCUBE(u_texIem, 7); // Source skybox. 13 | 14 | void main() 15 | { 16 | vec3 dirSrc = normalize(v_dir); 17 | vec3 dirDst = dirSrc; 18 | 19 | if (0.0 != u_prevEdgeFixup) { dirSrc = fixCubeLookup(dirSrc, u_prevLod, u_prevMipSize); } 20 | if (0.0 != u_edgeFixup) { dirDst = fixCubeLookup(dirDst, u_lod, u_mipSize); } 21 | 22 | vec3 src = toLinear(textureCubeLod(u_texIem, dirSrc, u_prevLod).xyz); 23 | vec3 dst = toLinear(textureCubeLod(u_texSkybox, dirDst, u_lod).xyz); 24 | 25 | float progress = clamp(u_skyboxTransition, 0.0, 1.0); 26 | 27 | vec3 color = mix(src, dst, progress); 28 | 29 | gl_FragColor = encodeRGBE8(color); 30 | } 31 | 32 | /* vim: set sw=4 ts=4 expandtab: */ 33 | -------------------------------------------------------------------------------- /src/shaders/fs_sun_icon.sc: -------------------------------------------------------------------------------- 1 | $input v_texcoord0 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #include "shader.shdr" 9 | #include "utils.shdr" 10 | 11 | SAMPLER2D(u_texColor, 0); 12 | 13 | void main() 14 | { 15 | vec4 tex = texture2D(u_texColor, v_texcoord0); 16 | 17 | float stroke = tex.b; 18 | float sun = tex.r * clamp(u_rgba.a, 0.0, 1.0); 19 | float bloom = tex.g * clamp(u_rgba.a-1.0, 0.0, 5.0)*0.2; 20 | 21 | vec3 color = u_rgba.rgb*(sun + bloom - stroke*8.0*u_selectedLight); 22 | float alpha = max(sun, bloom-0.1) + stroke; 23 | 24 | gl_FragColor.rgb = color; 25 | gl_FragColor.a = clamp(alpha, 0.0, 1.0); 26 | } 27 | 28 | /* vim: set sw=4 ts=4 expandtab: */ 29 | -------------------------------------------------------------------------------- /src/shaders/fs_tex.sc: -------------------------------------------------------------------------------- 1 | $input v_texcoord0 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #include "shader.shdr" 9 | #include "utils.shdr" 10 | 11 | SAMPLER2D(u_texColor, 0); 12 | 13 | void main() 14 | { 15 | vec4 color = texture2D(u_texColor, v_texcoord0); 16 | 17 | gl_FragColor.xyz = vec3_splat(decodeRE8(color)); 18 | gl_FragColor.w = 1.0; 19 | } 20 | 21 | /* vim: set sw=4 ts=4 expandtab: */ 22 | 23 | -------------------------------------------------------------------------------- /src/shaders/fs_tonemap.sc: -------------------------------------------------------------------------------- 1 | $input v_texcoord0, v_texcoord1, v_texcoord2, v_texcoord3, v_texcoord4 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #include "shader.shdr" 9 | #include "tonemap.shdr" 10 | #include "utils.shdr" 11 | 12 | SAMPLER2D(u_texColor, 0); 13 | SAMPLER2D(u_texLum, 1); 14 | SAMPLER2D(u_texBlur, 2); 15 | 16 | void main() 17 | { 18 | vec3 rgb = decodeRGBE8(texture2D(u_texColor, v_texcoord0)); 19 | float lumAvg; 20 | if (1.0 == u_doLightAdapt) 21 | { 22 | lumAvg = clamp(decodeRE8(texture2D(u_texLum, v_texcoord0)), 0.1, 1.0); 23 | } 24 | else 25 | { 26 | lumAvg = 0.18; 27 | } 28 | 29 | float middleGray = u_middleGray; 30 | 31 | float lumRgb = lumf(rgb); 32 | float lumScale = lumRgb * middleGray / (lumAvg+0.0001); 33 | rgb *= (lumScale / lumRgb); 34 | 35 | rgb = tonemap(rgb, u_whiteSqr); 36 | 37 | // Bloom. 38 | if (1.0 == u_doBloom) 39 | { 40 | // Vertical blur. 41 | vec4 blur = blur9(u_texBlur 42 | , v_texcoord0 43 | , v_texcoord1 44 | , v_texcoord2 45 | , v_texcoord3 46 | , v_texcoord4 47 | , u_weight0 48 | , u_weight1 49 | , u_weight2 50 | , u_weight3 51 | , u_weight4 52 | ); 53 | 54 | rgb += u_blurCoeff * blur.xyz; 55 | } 56 | 57 | // Apply exposure. 58 | rgb *= exp2(u_exposure); 59 | 60 | // Apply contrast. 61 | rgb = mix(vec3_splat(0.18), rgb, u_contrast); 62 | 63 | // Apply brightness. 64 | rgb = max(vec3_splat(0.0), rgb+u_brightness); 65 | 66 | // Apply gamma. 67 | rgb = pow(rgb, vec3_splat(u_gamma)); 68 | 69 | // Apply saturation. 70 | rgb = mix(luma(rgb), rgb, u_saturation); 71 | 72 | // Vignette. 73 | vec2 coord = (gl_FragCoord.xy * u_viewTexel.xy)*2.0-1.0; 74 | coord.y *= 0.35; 75 | float dist = distance(vec2_splat(0.0), coord)*0.5; 76 | float vignette = (1.0 - dist*dist*u_vignette); 77 | rgb *= vignette; 78 | 79 | gl_FragColor.xyz = rgb; 80 | gl_FragColor.w = 1.0; 81 | } 82 | 83 | /* vim: set sw=4 ts=4 expandtab: */ 84 | -------------------------------------------------------------------------------- /src/shaders/fs_wireframe.sc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | 7 | void main() 8 | { 9 | gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); 10 | } 11 | 12 | /* vim: set sw=4 ts=4 expandtab: */ 13 | -------------------------------------------------------------------------------- /src/shaders/gen_headers.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2014-2015 Dario Manesku. All rights reserved. 4 | # License: http://www.opensource.org/licenses/BSD-2-Clause 5 | # 6 | 7 | FILENAME="headers/shaders.h" 8 | 9 | echo "Generating '$FILENAME'..." 10 | 11 | # Erase contents. 12 | > $FILENAME 13 | 14 | echo "#ifndef CMFTSTUDIO_SHADERS_H_HEADER_GUARD" >> $FILENAME 15 | echo "#define CMFTSTUDIO_SHADERS_H_HEADER_GUARD" >> $FILENAME 16 | echo "" >> $FILENAME 17 | 18 | # Append each header. 19 | for HEADER in $(ls headers/vs_*.h headers/fs_*.h) 20 | do 21 | echo "#include \"$(basename $HEADER)\"" >> $FILENAME 22 | done 23 | 24 | echo "" >> $FILENAME 25 | echo "#endif // CMFTSTUDIO_SHADERS_H_HEADER_GUARD" >> $FILENAME 26 | 27 | echo "Done." 28 | -------------------------------------------------------------------------------- /src/shaders/headers/fs_color.bin.h: -------------------------------------------------------------------------------- 1 | static const uint8_t fs_color_glsl[112] = 2 | { 3 | 0x46, 0x53, 0x48, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x75, 0x5f, 0x75, 0x6e, 0x69, // FSH........u_uni 4 | 0x66, 0x6f, 0x72, 0x6d, 0x73, 0x02, 0x38, 0x00, 0x00, 0x38, 0x00, 0x50, 0x00, 0x00, 0x00, 0x75, // forms.8..8.P...u 5 | 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x75, 0x5f, 0x75, 0x6e, // niform vec4 u_un 6 | 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x73, 0x5b, 0x35, 0x36, 0x5d, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, // iforms[56];.void 7 | 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, // main ().{. gl_ 8 | 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x75, 0x5f, 0x75, 0x6e, // FragColor = u_un 9 | 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x73, 0x5b, 0x32, 0x35, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // iforms[25];.}... 10 | }; 11 | static const uint8_t fs_color_dx9[194] = 12 | { 13 | 0x46, 0x53, 0x48, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x75, 0x5f, 0x75, 0x6e, 0x69, // FSH........u_uni 14 | 0x66, 0x6f, 0x72, 0x6d, 0x73, 0x12, 0x38, 0x00, 0x00, 0x1a, 0x00, 0xa4, 0x00, 0x00, 0x03, 0xff, // forms.8......... 15 | 0xff, 0xfe, 0xff, 0x23, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1c, 0x00, 0x00, 0x00, 0x53, 0x00, 0x00, // ...#.CTAB....S.. 16 | 0x00, 0x00, 0x03, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, // ................ 17 | 0x00, 0x4c, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, // .L...0.......... 18 | 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x75, 0x5f, 0x75, 0x6e, 0x69, 0x66, 0x6f, // .<.......u_unifo 19 | 0x72, 0x6d, 0x73, 0x00, 0xab, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x00, 0x38, 0x00, 0x00, // rms..........8.. 20 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, // .....ps_3_0.Micr 21 | 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, // osoft (R) HLSL S 22 | 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x39, // hader Compiler 9 23 | 0x2e, 0x33, 0x30, 0x2e, 0x39, 0x32, 0x30, 0x30, 0x2e, 0x31, 0x36, 0x33, 0x38, 0x34, 0x00, 0xab, // .30.9200.16384.. 24 | 0xab, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x0f, 0x80, 0x19, 0x00, 0xe4, 0xa0, 0xff, 0xff, 0x00, // ................ 25 | 0x00, 0x00, // .. 26 | }; 27 | static const uint8_t fs_color_dx11[253] = 28 | { 29 | 0x46, 0x53, 0x48, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x75, 0x5f, 0x75, 0x6e, 0x69, // FSH........u_uni 30 | 0x66, 0x6f, 0x72, 0x6d, 0x73, 0x12, 0x38, 0x00, 0x00, 0x38, 0x00, 0xdc, 0x00, 0x44, 0x58, 0x42, // forms.8..8...DXB 31 | 0x43, 0x71, 0xb1, 0x07, 0x11, 0xbb, 0x85, 0x4b, 0x98, 0x53, 0xf2, 0x4c, 0x1f, 0x3c, 0x72, 0x3f, // Cq.....K.S.L........ 45 | }; 46 | -------------------------------------------------------------------------------- /src/shaders/headers/fs_equals.bin.h: -------------------------------------------------------------------------------- 1 | static const uint8_t fs_equals_glsl[160] = 2 | { 3 | 0x46, 0x53, 0x48, 0x04, 0x6f, 0x1e, 0x3e, 0x3c, 0x01, 0x00, 0x0a, 0x75, 0x5f, 0x74, 0x65, 0x78, // FSH.o.><...u_tex 4 | 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x80, 0x00, 0x00, 0x00, 0x76, // Color..........v 5 | 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x76, 0x5f, 0x74, 0x65, // arying vec2 v_te 6 | 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, // xcoord0;.uniform 7 | 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x32, 0x44, 0x20, 0x75, 0x5f, 0x74, 0x65, 0x78, // sampler2D u_tex 8 | 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, // Color;.void main 9 | 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, // ().{. gl_FragC 10 | 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x32, 0x44, // olor = texture2D 11 | 0x20, 0x28, 0x75, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x2c, 0x20, 0x76, 0x5f, // (u_texColor, v_ 12 | 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x29, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // texcoord0);.}... 13 | }; 14 | static const uint8_t fs_equals_dx9[205] = 15 | { 16 | 0x46, 0x53, 0x48, 0x04, 0x6f, 0x1e, 0x3e, 0x3c, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x03, 0xff, 0xff, // FSH.o.><........ 17 | 0xfe, 0xff, 0x23, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1c, 0x00, 0x00, 0x00, 0x53, 0x00, 0x00, 0x00, // ..#.CTAB....S... 18 | 0x00, 0x03, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, // ................ 19 | 0x4c, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, // L...0........... 20 | 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x75, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, // <.......u_texCol 21 | 0x6f, 0x72, 0x00, 0xab, 0x04, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, // or.............. 22 | 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f, // ....ps_3_0.Micro 23 | 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, // soft (R) HLSL Sh 24 | 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x39, 0x2e, // ader Compiler 9. 25 | 0x33, 0x30, 0x2e, 0x39, 0x32, 0x30, 0x30, 0x2e, 0x31, 0x36, 0x33, 0x38, 0x34, 0x00, 0xab, 0xab, // 30.9200.16384... 26 | 0x1f, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x80, 0x00, 0x00, 0x03, 0x90, 0x1f, 0x00, 0x00, 0x02, // ................ 27 | 0x00, 0x00, 0x00, 0x90, 0x00, 0x08, 0x0f, 0xa0, 0x42, 0x00, 0x00, 0x03, 0x00, 0x08, 0x0f, 0x80, // ........B....... 28 | 0x00, 0x00, 0xe4, 0x90, 0x00, 0x08, 0xe4, 0xa0, 0xff, 0xff, 0x00, 0x00, 0x00, // ............. 29 | }; 30 | static const uint8_t fs_equals_dx11[308] = 31 | { 32 | 0x46, 0x53, 0x48, 0x04, 0x6f, 0x1e, 0x3e, 0x3c, 0x00, 0x00, 0x24, 0x01, 0x44, 0x58, 0x42, 0x43, // FSH.o.><..$.DXBC 33 | 0xd2, 0x06, 0xf2, 0xc5, 0xaf, 0x16, 0x4c, 0x7f, 0x92, 0xa3, 0x07, 0x81, 0x5d, 0x0d, 0x15, 0x05, // ......L.....]... 34 | 0x01, 0x00, 0x00, 0x00, 0x24, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, // ....$.......,... 35 | 0x84, 0x00, 0x00, 0x00, 0xb8, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x4e, 0x50, 0x00, 0x00, 0x00, // ........ISGNP... 36 | 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........8....... 37 | 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, // ................ 38 | 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // D............... 39 | 0x01, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, // ........SV_POSIT 40 | 0x49, 0x4f, 0x4e, 0x00, 0x54, 0x45, 0x58, 0x43, 0x4f, 0x4f, 0x52, 0x44, 0x00, 0xab, 0xab, 0xab, // ION.TEXCOORD.... 41 | 0x4f, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, // OSGN,........... 42 | 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // ............... 43 | 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x54, 0x41, 0x52, 0x47, 0x45, // ........SV_TARGE 44 | 0x54, 0x00, 0xab, 0xab, 0x53, 0x48, 0x44, 0x52, 0x64, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, // T...SHDRd...@... 45 | 0x19, 0x00, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x03, 0x00, 0x60, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ....Z....`...... 46 | 0x58, 0x18, 0x00, 0x04, 0x00, 0x70, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, // X....p......UU.. 47 | 0x62, 0x10, 0x00, 0x03, 0x32, 0x10, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, // b...2.......e... 48 | 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x09, 0xf2, 0x20, 0x10, 0x00, // . ......E.... .. 49 | 0x00, 0x00, 0x00, 0x00, 0x46, 0x10, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x7e, 0x10, 0x00, // ....F.......F~.. 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x01, // .....`......>... 51 | 0x00, 0x00, 0x00, 0x00, // .... 52 | }; 53 | -------------------------------------------------------------------------------- /src/shaders/headers/fs_image.bin.h: -------------------------------------------------------------------------------- 1 | static const uint8_t fs_image_glsl[192] = 2 | { 3 | 0x46, 0x53, 0x48, 0x04, 0x6f, 0x1e, 0x3e, 0x3c, 0x01, 0x00, 0x0a, 0x75, 0x5f, 0x74, 0x65, 0x78, // FSH.o.><...u_tex 4 | 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x76, // Color..........v 5 | 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x76, 0x5f, 0x74, 0x65, // arying vec2 v_te 6 | 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, // xcoord0;.uniform 7 | 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x32, 0x44, 0x20, 0x75, 0x5f, 0x74, 0x65, 0x78, // sampler2D u_tex 8 | 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, // Color;.void main 9 | 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, // ().{. gl_FragC 10 | 0x6f, 0x6c, 0x6f, 0x72, 0x2e, 0x78, 0x79, 0x7a, 0x20, 0x3d, 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, // olor.xyz = textu 11 | 0x72, 0x65, 0x32, 0x44, 0x20, 0x28, 0x75, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, // re2D (u_texColor 12 | 0x2c, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x29, 0x2e, 0x78, // , v_texcoord0).x 13 | 0x79, 0x7a, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, // yz;. gl_FragCol 14 | 0x6f, 0x72, 0x2e, 0x77, 0x20, 0x3d, 0x20, 0x31, 0x2e, 0x30, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // or.w = 1.0;.}... 15 | }; 16 | static const uint8_t fs_image_dx9[253] = 17 | { 18 | 0x46, 0x53, 0x48, 0x04, 0x6f, 0x1e, 0x3e, 0x3c, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x03, 0xff, 0xff, // FSH.o.><........ 19 | 0xfe, 0xff, 0x23, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1c, 0x00, 0x00, 0x00, 0x53, 0x00, 0x00, 0x00, // ..#.CTAB....S... 20 | 0x00, 0x03, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, // ................ 21 | 0x4c, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, // L...0........... 22 | 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x75, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, // <.......u_texCol 23 | 0x6f, 0x72, 0x00, 0xab, 0x04, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, // or.............. 24 | 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f, // ....ps_3_0.Micro 25 | 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, // soft (R) HLSL Sh 26 | 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x39, 0x2e, // ader Compiler 9. 27 | 0x33, 0x30, 0x2e, 0x39, 0x32, 0x30, 0x30, 0x2e, 0x31, 0x36, 0x33, 0x38, 0x34, 0x00, 0xab, 0xab, // 30.9200.16384... 28 | 0x51, 0x00, 0x00, 0x05, 0x00, 0x00, 0x0f, 0xa0, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, // Q..........?.... 29 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x80, // ................ 30 | 0x00, 0x00, 0x03, 0x90, 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x90, 0x00, 0x08, 0x0f, 0xa0, // ................ 31 | 0x42, 0x00, 0x00, 0x03, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0x90, 0x00, 0x08, 0xe4, 0xa0, // B............... 32 | 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x07, 0x80, 0x00, 0x00, 0xe4, 0x80, 0x01, 0x00, 0x00, 0x02, // ................ 33 | 0x00, 0x08, 0x08, 0x80, 0x00, 0x00, 0x00, 0xa0, 0xff, 0xff, 0x00, 0x00, 0x00, // ............. 34 | }; 35 | static const uint8_t fs_image_dx11[356] = 36 | { 37 | 0x46, 0x53, 0x48, 0x04, 0x6f, 0x1e, 0x3e, 0x3c, 0x00, 0x00, 0x54, 0x01, 0x44, 0x58, 0x42, 0x43, // FSH.o.><..T.DXBC 38 | 0xbd, 0x57, 0x05, 0x82, 0xa8, 0x94, 0xe5, 0xe7, 0xab, 0x25, 0xe0, 0x04, 0xa5, 0x29, 0x1c, 0x50, // .W.......%...).P 39 | 0x01, 0x00, 0x00, 0x00, 0x54, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, // ....T.......,... 40 | 0x84, 0x00, 0x00, 0x00, 0xb8, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x4e, 0x50, 0x00, 0x00, 0x00, // ........ISGNP... 41 | 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........8....... 42 | 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, // ................ 43 | 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // D............... 44 | 0x01, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, // ........SV_POSIT 45 | 0x49, 0x4f, 0x4e, 0x00, 0x54, 0x45, 0x58, 0x43, 0x4f, 0x4f, 0x52, 0x44, 0x00, 0xab, 0xab, 0xab, // ION.TEXCOORD.... 46 | 0x4f, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, // OSGN,........... 47 | 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // ............... 48 | 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x54, 0x41, 0x52, 0x47, 0x45, // ........SV_TARGE 49 | 0x54, 0x00, 0xab, 0xab, 0x53, 0x48, 0x44, 0x52, 0x94, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, // T...SHDR....@... 50 | 0x25, 0x00, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x03, 0x00, 0x60, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // %...Z....`...... 51 | 0x58, 0x18, 0x00, 0x04, 0x00, 0x70, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, // X....p......UU.. 52 | 0x62, 0x10, 0x00, 0x03, 0x32, 0x10, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, // b...2.......e... 53 | 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, // . ......h....... 54 | 0x45, 0x00, 0x00, 0x09, 0xf2, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x10, 0x10, 0x00, // E...........F... 55 | 0x01, 0x00, 0x00, 0x00, 0x46, 0x7e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x10, 0x00, // ....F~.......`.. 56 | 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x05, 0x72, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ....6...r ...... 57 | 0x46, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x05, 0x82, 0x20, 0x10, 0x00, // F.......6.... .. 58 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x3e, 0x00, 0x00, 0x01, // .....@.....?>... 59 | 0x00, 0x00, 0x00, 0x00, // .... 60 | }; 61 | -------------------------------------------------------------------------------- /src/shaders/headers/fs_overlay.bin.h: -------------------------------------------------------------------------------- 1 | static const uint8_t fs_overlay_glsl[76] = 2 | { 3 | 0x46, 0x53, 0x48, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x00, 0x00, 0x76, 0x6f, // FSH.......=...vo 4 | 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x67, // id main ().{. g 5 | 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x76, 0x65, // l_FragColor = ve 6 | 0x63, 0x34, 0x28, 0x30, 0x2e, 0x33, 0x2c, 0x20, 0x30, 0x2e, 0x33, 0x2c, 0x20, 0x30, 0x2e, 0x33, // c4(0.3, 0.3, 0.3 7 | 0x2c, 0x20, 0x30, 0x2e, 0x35, 0x29, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // , 0.5);.}... 8 | }; 9 | static const uint8_t fs_overlay_dx9[153] = 10 | { 11 | 0x46, 0x53, 0x48, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x00, 0x00, 0x03, 0xff, 0xff, // FSH............. 12 | 0xfe, 0xff, 0x17, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1c, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, // ....CTAB....#... 13 | 0x00, 0x03, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, // ................ 14 | 0x1c, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f, // ....ps_3_0.Micro 15 | 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, // soft (R) HLSL Sh 16 | 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x39, 0x2e, // ader Compiler 9. 17 | 0x33, 0x30, 0x2e, 0x39, 0x32, 0x30, 0x30, 0x2e, 0x31, 0x36, 0x33, 0x38, 0x34, 0x00, 0xab, 0xab, // 30.9200.16384... 18 | 0x51, 0x00, 0x00, 0x05, 0x00, 0x00, 0x0f, 0xa0, 0x9a, 0x99, 0x99, 0x3e, 0x00, 0x00, 0x00, 0x3f, // Q..........>...? 19 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x0f, 0x80, // ................ 20 | 0x00, 0x00, 0x40, 0xa0, 0xff, 0xff, 0x00, 0x00, 0x00, // ..@...... 21 | }; 22 | static const uint8_t fs_overlay_dx11[228] = 23 | { 24 | 0x46, 0x53, 0x48, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x44, 0x58, 0x42, 0x43, // FSH.........DXBC 25 | 0x71, 0x6f, 0x86, 0x7e, 0x05, 0x1e, 0x51, 0x7d, 0x1b, 0x2d, 0xe5, 0xc9, 0x1a, 0x33, 0x71, 0x29, // qo.~..Q}.-...3q) 26 | 0x01, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, // ............,... 27 | 0x60, 0x00, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, 0x00, // `.......ISGN,... 28 | 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........ ....... 29 | 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, // ................ 30 | 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x4f, 0x53, 0x47, 0x4e, // SV_POSITION.OSGN 31 | 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, // ,........... ... 32 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ 33 | 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x54, 0x41, 0x52, 0x47, 0x45, 0x54, 0x00, 0xab, 0xab, // ....SV_TARGET... 34 | 0x53, 0x48, 0x44, 0x52, 0x38, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, // SHDR8...@....... 35 | 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x08, // e.... ......6... 36 | 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x9a, 0x99, 0x99, 0x3e, // . .......@.....> 37 | 0x9a, 0x99, 0x99, 0x3e, 0x9a, 0x99, 0x99, 0x3e, 0x00, 0x00, 0x00, 0x3f, 0x3e, 0x00, 0x00, 0x01, // ...>...>...?>... 38 | 0x00, 0x00, 0x00, 0x00, // .... 39 | }; 40 | -------------------------------------------------------------------------------- /src/shaders/headers/fs_tex.bin.h: -------------------------------------------------------------------------------- 1 | static const uint8_t fs_tex_glsl[285] = 2 | { 3 | 0x46, 0x53, 0x48, 0x04, 0x6f, 0x1e, 0x3e, 0x3c, 0x01, 0x00, 0x0a, 0x75, 0x5f, 0x74, 0x65, 0x78, // FSH.o.><...u_tex 4 | 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0xfd, 0x00, 0x00, 0x00, 0x76, // Color..........v 5 | 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x76, 0x5f, 0x74, 0x65, // arying vec2 v_te 6 | 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, // xcoord0;.uniform 7 | 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x32, 0x44, 0x20, 0x75, 0x5f, 0x74, 0x65, 0x78, // sampler2D u_tex 8 | 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, // Color;.void main 9 | 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, // ().{. vec4 tmp 10 | 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, // var_1;. tmpvar_ 11 | 0x31, 0x20, 0x3d, 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x32, 0x44, 0x20, 0x28, 0x75, // 1 = texture2D (u 12 | 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x2c, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, // _texColor, v_tex 13 | 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, // coord0);. gl_Fr 14 | 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x2e, 0x78, 0x79, 0x7a, 0x20, 0x3d, 0x20, 0x76, 0x65, // agColor.xyz = ve 15 | 0x63, 0x33, 0x28, 0x28, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x78, 0x20, 0x2a, // c3((tmpvar_1.x * 16 | 0x20, 0x65, 0x78, 0x70, 0x32, 0x28, 0x28, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x28, 0x74, 0x6d, 0x70, // exp2((. (tmp 17 | 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x77, 0x20, 0x2a, 0x20, 0x32, 0x35, 0x35, 0x2e, 0x30, 0x29, // var_1.w * 255.0) 18 | 0x0a, 0x20, 0x20, 0x20, 0x2d, 0x20, 0x31, 0x32, 0x38, 0x2e, 0x30, 0x29, 0x29, 0x29, 0x29, 0x3b, // . - 128.0)))); 19 | 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x2e, // . gl_FragColor. 20 | 0x77, 0x20, 0x3d, 0x20, 0x31, 0x2e, 0x30, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // w = 1.0;.}... 21 | }; 22 | static const uint8_t fs_tex_dx9[289] = 23 | { 24 | 0x46, 0x53, 0x48, 0x04, 0x6f, 0x1e, 0x3e, 0x3c, 0x00, 0x00, 0x14, 0x01, 0x00, 0x03, 0xff, 0xff, // FSH.o.><........ 25 | 0xfe, 0xff, 0x23, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1c, 0x00, 0x00, 0x00, 0x53, 0x00, 0x00, 0x00, // ..#.CTAB....S... 26 | 0x00, 0x03, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, // ................ 27 | 0x4c, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, // L...0........... 28 | 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x75, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, // <.......u_texCol 29 | 0x6f, 0x72, 0x00, 0xab, 0x04, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, // or.............. 30 | 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f, // ....ps_3_0.Micro 31 | 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, // soft (R) HLSL Sh 32 | 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x39, 0x2e, // ader Compiler 9. 33 | 0x33, 0x30, 0x2e, 0x39, 0x32, 0x30, 0x30, 0x2e, 0x31, 0x36, 0x33, 0x38, 0x34, 0x00, 0xab, 0xab, // 30.9200.16384... 34 | 0x51, 0x00, 0x00, 0x05, 0x00, 0x00, 0x0f, 0xa0, 0x00, 0x00, 0x7f, 0x43, 0x00, 0x00, 0x00, 0xc3, // Q..........C.... 35 | 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x80, // ...?............ 36 | 0x00, 0x00, 0x03, 0x90, 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x90, 0x00, 0x08, 0x0f, 0xa0, // ................ 37 | 0x42, 0x00, 0x00, 0x03, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0x90, 0x00, 0x08, 0xe4, 0xa0, // B............... 38 | 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x02, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0x00, 0xa0, // ................ 39 | 0x00, 0x00, 0x55, 0xa0, 0x0e, 0x00, 0x00, 0x02, 0x00, 0x00, 0x02, 0x80, 0x00, 0x00, 0x55, 0x80, // ..U...........U. 40 | 0x05, 0x00, 0x00, 0x03, 0x00, 0x08, 0x07, 0x80, 0x00, 0x00, 0x55, 0x80, 0x00, 0x00, 0x00, 0x80, // ..........U..... 41 | 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x08, 0x80, 0x00, 0x00, 0xaa, 0xa0, 0xff, 0xff, 0x00, 0x00, // ................ 42 | 0x00, // . 43 | }; 44 | static const uint8_t fs_tex_dx11[420] = 45 | { 46 | 0x46, 0x53, 0x48, 0x04, 0x6f, 0x1e, 0x3e, 0x3c, 0x00, 0x00, 0x94, 0x01, 0x44, 0x58, 0x42, 0x43, // FSH.o.><....DXBC 47 | 0x53, 0xc7, 0x60, 0x12, 0x49, 0x32, 0xca, 0x62, 0xc9, 0xce, 0x9b, 0x45, 0xe1, 0xbe, 0x42, 0x96, // S.`.I2.b...E..B. 48 | 0x01, 0x00, 0x00, 0x00, 0x94, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, // ............,... 49 | 0x84, 0x00, 0x00, 0x00, 0xb8, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x4e, 0x50, 0x00, 0x00, 0x00, // ........ISGNP... 50 | 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........8....... 51 | 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, // ................ 52 | 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // D............... 53 | 0x01, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, // ........SV_POSIT 54 | 0x49, 0x4f, 0x4e, 0x00, 0x54, 0x45, 0x58, 0x43, 0x4f, 0x4f, 0x52, 0x44, 0x00, 0xab, 0xab, 0xab, // ION.TEXCOORD.... 55 | 0x4f, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, // OSGN,........... 56 | 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // ............... 57 | 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x54, 0x41, 0x52, 0x47, 0x45, // ........SV_TARGE 58 | 0x54, 0x00, 0xab, 0xab, 0x53, 0x48, 0x44, 0x52, 0xd4, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, // T...SHDR....@... 59 | 0x35, 0x00, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x03, 0x00, 0x60, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // 5...Z....`...... 60 | 0x58, 0x18, 0x00, 0x04, 0x00, 0x70, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, // X....p......UU.. 61 | 0x62, 0x10, 0x00, 0x03, 0x32, 0x10, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, // b...2.......e... 62 | 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, // . ......h....... 63 | 0x45, 0x00, 0x00, 0x09, 0xf2, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x10, 0x10, 0x00, // E...........F... 64 | 0x01, 0x00, 0x00, 0x00, 0x46, 0x7e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x10, 0x00, // ....F~.......`.. 65 | 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x09, 0x22, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ....2..."....... 66 | 0x3a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x43, // :........@.....C 67 | 0x01, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x19, 0x00, 0x00, 0x05, 0x22, 0x00, 0x10, 0x00, // .@.........."... 68 | 0x00, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x07, // ............8... 69 | 0x72, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x05, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // r ......V....... 70 | 0x06, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x05, 0x82, 0x20, 0x10, 0x00, // ........6.... .. 71 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x3e, 0x00, 0x00, 0x01, // .....@.....?>... 72 | 0x00, 0x00, 0x00, 0x00, // .... 73 | }; 74 | -------------------------------------------------------------------------------- /src/shaders/headers/fs_wireframe.bin.h: -------------------------------------------------------------------------------- 1 | static const uint8_t fs_wireframe_glsl[76] = 2 | { 3 | 0x46, 0x53, 0x48, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x00, 0x00, 0x76, 0x6f, // FSH.......=...vo 4 | 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x67, // id main ().{. g 5 | 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x76, 0x65, // l_FragColor = ve 6 | 0x63, 0x34, 0x28, 0x30, 0x2e, 0x30, 0x2c, 0x20, 0x30, 0x2e, 0x30, 0x2c, 0x20, 0x30, 0x2e, 0x30, // c4(0.0, 0.0, 0.0 7 | 0x2c, 0x20, 0x31, 0x2e, 0x30, 0x29, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // , 1.0);.}... 8 | }; 9 | static const uint8_t fs_wireframe_dx9[153] = 10 | { 11 | 0x46, 0x53, 0x48, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x00, 0x00, 0x03, 0xff, 0xff, // FSH............. 12 | 0xfe, 0xff, 0x17, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1c, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, // ....CTAB....#... 13 | 0x00, 0x03, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, // ................ 14 | 0x1c, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f, // ....ps_3_0.Micro 15 | 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, // soft (R) HLSL Sh 16 | 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x39, 0x2e, // ader Compiler 9. 17 | 0x33, 0x30, 0x2e, 0x39, 0x32, 0x30, 0x30, 0x2e, 0x31, 0x36, 0x33, 0x38, 0x34, 0x00, 0xab, 0xab, // 30.9200.16384... 18 | 0x51, 0x00, 0x00, 0x05, 0x00, 0x00, 0x0f, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, // Q..............? 19 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x0f, 0x80, // ................ 20 | 0x00, 0x00, 0x40, 0xa0, 0xff, 0xff, 0x00, 0x00, 0x00, // ..@...... 21 | }; 22 | static const uint8_t fs_wireframe_dx11[228] = 23 | { 24 | 0x46, 0x53, 0x48, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x44, 0x58, 0x42, 0x43, // FSH.........DXBC 25 | 0x1d, 0x92, 0x8a, 0x7c, 0xde, 0x26, 0x00, 0x95, 0x3b, 0x8f, 0x2c, 0xdd, 0x84, 0x5a, 0xac, 0x4d, // ...|.&..;.,..Z.M 26 | 0x01, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, // ............,... 27 | 0x60, 0x00, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, 0x00, // `.......ISGN,... 28 | 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........ ....... 29 | 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, // ................ 30 | 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x4f, 0x53, 0x47, 0x4e, // SV_POSITION.OSGN 31 | 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, // ,........... ... 32 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ 33 | 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x54, 0x41, 0x52, 0x47, 0x45, 0x54, 0x00, 0xab, 0xab, // ....SV_TARGET... 34 | 0x53, 0x48, 0x44, 0x52, 0x38, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, // SHDR8...@....... 35 | 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x08, // e.... ......6... 36 | 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // . .......@...... 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x3e, 0x00, 0x00, 0x01, // ...........?>... 38 | 0x00, 0x00, 0x00, 0x00, // .... 39 | }; 40 | -------------------------------------------------------------------------------- /src/shaders/headers/shaders.h: -------------------------------------------------------------------------------- 1 | #ifndef CMFTSTUDIO_SHADERS_H_HEADER_GUARD 2 | #define CMFTSTUDIO_SHADERS_H_HEADER_GUARD 3 | 4 | #include "fs_blur.bin.h" 5 | #include "fs_bright.bin.h" 6 | #include "fs_color.bin.h" 7 | #include "fs_cubemap_tonemap.bin.h" 8 | #include "fs_equals.bin.h" 9 | #include "fs_fxaa.bin.h" 10 | #include "fs_image.bin.h" 11 | #include "fs_image_re8.bin.h" 12 | #include "fs_latlong.bin.h" 13 | #include "fs_lum.bin.h" 14 | #include "fs_lumavg.bin.h" 15 | #include "fs_lumdownscale.bin.h" 16 | #include "fs_mesh.bin.h" 17 | #include "fs_mesh_normal.bin.h" 18 | #include "fs_mesh_normal_rgbe8.bin.h" 19 | #include "fs_mesh_normal_rgbe8_trans.bin.h" 20 | #include "fs_mesh_rgbe8.bin.h" 21 | #include "fs_mesh_rgbe8_trans.bin.h" 22 | #include "fs_overlay.bin.h" 23 | #include "fs_skybox.bin.h" 24 | #include "fs_skybox_trans.bin.h" 25 | #include "fs_sun_icon.bin.h" 26 | #include "fs_tex.bin.h" 27 | #include "fs_tonemap.bin.h" 28 | #include "fs_wireframe.bin.h" 29 | #include "vs_blur.bin.h" 30 | #include "vs_material.bin.h" 31 | #include "vs_material_normal.bin.h" 32 | #include "vs_mesh.bin.h" 33 | #include "vs_mesh_color.bin.h" 34 | #include "vs_mesh_normal.bin.h" 35 | #include "vs_mesh_tex.bin.h" 36 | #include "vs_plain.bin.h" 37 | #include "vs_skybox.bin.h" 38 | #include "vs_texcoord.bin.h" 39 | #include "vs_tonemap.bin.h" 40 | 41 | #endif // CMFTSTUDIO_SHADERS_H_HEADER_GUARD 42 | -------------------------------------------------------------------------------- /src/shaders/headers/vs_plain.bin.h: -------------------------------------------------------------------------------- 1 | static const uint8_t vs_plain_glsl[224] = 2 | { 3 | 0x56, 0x53, 0x48, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0f, 0x75, 0x5f, 0x6d, 0x6f, 0x64, // VSH........u_mod 4 | 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x01, 0x00, 0x00, 0x01, 0x00, // elViewProj...... 5 | 0xbb, 0x00, 0x00, 0x00, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x76, 0x65, // ....attribute ve 6 | 0x63, 0x33, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, 0x75, // c3 a_position;.u 7 | 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x6d, 0x61, 0x74, 0x34, 0x20, 0x75, 0x5f, 0x6d, 0x6f, // niform mat4 u_mo 8 | 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x3b, 0x0a, 0x76, 0x6f, 0x69, // delViewProj;.voi 9 | 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x76, 0x65, // d main ().{. ve 10 | 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x74, // c4 tmpvar_1;. t 11 | 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x77, 0x20, 0x3d, 0x20, 0x31, 0x2e, 0x30, 0x3b, // mpvar_1.w = 1.0; 12 | 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x78, 0x79, 0x7a, 0x20, // . tmpvar_1.xyz 13 | 0x3d, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, 0x20, 0x20, // = a_position;. 14 | 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x28, 0x75, // gl_Position = (u 15 | 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x20, 0x2a, // _modelViewProj * 16 | 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x29, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // tmpvar_1);.}... 17 | }; 18 | static const uint8_t vs_plain_dx9[287] = 19 | { 20 | 0x56, 0x53, 0x48, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0f, 0x75, 0x5f, 0x6d, 0x6f, 0x64, // VSH........u_mod 21 | 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x01, 0x00, 0x00, 0x04, 0x00, // elViewProj...... 22 | 0xfc, 0x00, 0x00, 0x03, 0xfe, 0xff, 0xfe, 0xff, 0x24, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1c, 0x00, // ........$.CTAB.. 23 | 0x00, 0x00, 0x57, 0x00, 0x00, 0x00, 0x00, 0x03, 0xfe, 0xff, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, // ..W............. 24 | 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, // ......P...0..... 25 | 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x75, 0x5f, // ......@.......u_ 26 | 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x00, 0x03, 0x00, // modelViewProj... 27 | 0x03, 0x00, 0x04, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0x73, // ..............vs 28 | 0x5f, 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, // _3_0.Microsoft ( 29 | 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, // R) HLSL Shader C 30 | 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x39, 0x2e, 0x33, 0x30, 0x2e, 0x39, 0x32, 0x30, // ompiler 9.30.920 31 | 0x30, 0x2e, 0x31, 0x36, 0x33, 0x38, 0x34, 0x00, 0xab, 0xab, 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, // 0.16384......... 32 | 0x00, 0x80, 0x00, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, // ................ 33 | 0x0f, 0xe0, 0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x0f, 0x80, 0x01, 0x00, 0xe4, 0xa0, 0x00, 0x00, // ................ 34 | 0x55, 0x90, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0xa0, 0x00, 0x00, // U............... 35 | 0x00, 0x90, 0x00, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x0f, 0x80, 0x02, 0x00, // ................ 36 | 0xe4, 0xa0, 0x00, 0x00, 0xaa, 0x90, 0x00, 0x00, 0xe4, 0x80, 0x02, 0x00, 0x00, 0x03, 0x00, 0x00, // ................ 37 | 0x0f, 0xe0, 0x00, 0x00, 0xe4, 0x80, 0x03, 0x00, 0xe4, 0xa0, 0xff, 0xff, 0x00, 0x00, 0x00, // ............... 38 | }; 39 | static const uint8_t vs_plain_dx11[404] = 40 | { 41 | 0x56, 0x53, 0x48, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0f, 0x75, 0x5f, 0x6d, 0x6f, 0x64, // VSH........u_mod 42 | 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, // elViewProj...... 43 | 0x6c, 0x01, 0x44, 0x58, 0x42, 0x43, 0x87, 0x3c, 0x16, 0xa4, 0x8d, 0x3d, 0x5b, 0xea, 0x61, 0x5c, // l.DXBC.<...=[.a. 44 | 0x10, 0x3b, 0xa1, 0xf8, 0xf8, 0xa1, 0x01, 0x00, 0x00, 0x00, 0x6c, 0x01, 0x00, 0x00, 0x03, 0x00, // .;........l..... 45 | 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, 0x49, 0x53, // ..,...`.......IS 46 | 0x47, 0x4e, 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, // GN,........... . 47 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ 48 | 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0xab, // ......POSITION.. 49 | 0xab, 0xab, 0x4f, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, // ..OSGN,......... 50 | 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, // .. ............. 51 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, // ..........SV_POS 52 | 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x53, 0x48, 0x44, 0x52, 0xd0, 0x00, 0x00, 0x00, 0x40, 0x00, // ITION.SHDR....@. 53 | 0x01, 0x00, 0x34, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x04, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, // ..4...Y...F. ... 54 | 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x03, 0x72, 0x10, 0x10, 0x00, 0x00, 0x00, // ......_...r..... 55 | 0x00, 0x00, 0x67, 0x00, 0x00, 0x04, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, // ..g.... ........ 56 | 0x00, 0x00, 0x68, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x08, 0xf2, 0x00, // ..h.......8..... 57 | 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x15, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x8e, // ......V.......F. 58 | 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x0a, 0xf2, 0x00, // .........2..... 59 | 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ......F. ....... 60 | 0x00, 0x00, 0x06, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x0e, 0x10, 0x00, 0x00, 0x00, // ..........F..... 61 | 0x00, 0x00, 0x32, 0x00, 0x00, 0x0a, 0xf2, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x8e, // ..2...........F. 62 | 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xa6, 0x1a, 0x10, 0x00, 0x00, 0x00, // ............... 63 | 0x00, 0x00, 0x46, 0x0e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xf2, 0x20, // ..F............ 64 | 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x0e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x8e, // ......F.......F. 65 | 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x01, 0x00, 0x01, // .........>..... 66 | 0x01, 0x00, 0x40, 0x00, // ..@. 67 | }; 68 | -------------------------------------------------------------------------------- /src/shaders/makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | # License: http://www.opensource.org/licenses/BSD-2-Clause 4 | # 5 | 6 | BGFX_DIR=../../dependency/bgfx 7 | RUNTIME_DIR=../../runtime 8 | BUILD_DIR=../../_build 9 | 10 | include $(BGFX_DIR)/scripts/shader.mk 11 | 12 | rebuild: 13 | @make -s --no-print-directory TARGET=0 clean all 14 | @make -s --no-print-directory TARGET=1 clean all 15 | @make -s --no-print-directory TARGET=2 clean all 16 | @make -s --no-print-directory TARGET=3 clean all 17 | @make -s --no-print-directory TARGET=4 clean all 18 | -------------------------------------------------------------------------------- /src/shaders/makefile_headers: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | # License: http://www.opensource.org/licenses/BSD-2-Clause 4 | # 5 | 6 | BGFX_DIR=../../dependency/bgfx 7 | RUNTIME_DIR=../../runtime 8 | BUILD_DIR=../../_build 9 | SCRIPT_DIR=$(BGFX_DIR)/scripts 10 | 11 | THISDIR:=$(SCRIPT_DIR) 12 | include $(THISDIR)/tools.mk 13 | 14 | VS_FLAGS+=-i $(THISDIR)../src/ --type vertex 15 | FS_FLAGS+=-i $(THISDIR)../src/ --type fragment 16 | 17 | VS_SOURCES=$(wildcard vs_*.sc) 18 | FS_SOURCES=$(wildcard fs_*.sc) 19 | 20 | VS_BIN = $(addsuffix .bin.h, $(notdir $(basename $(VS_SOURCES)))) 21 | FS_BIN = $(addsuffix .bin.h, $(notdir $(basename $(FS_SOURCES)))) 22 | 23 | DEST_DIR = /headers/ 24 | 25 | BIN = $(VS_BIN) $(FS_BIN) 26 | 27 | SHADER_TMP = .tmp_shader 28 | 29 | vs_%.bin.h : vs_%.sc 30 | $(SILENT) echo [$(<)] 31 | $(SILENT) $(SHADERC) $(VS_FLAGS) --platform linux -p 120 -f $(<) -o $(SHADER_TMP) --bin2c $(basename $( $(addsuffix $(@F), $(addsuffix $(DEST_DIR), $(@D))) 33 | -$(SILENT) $(SHADERC) $(VS_FLAGS) --platform windows -p vs_3_0 -O 3 -f $(<) -o $(SHADER_TMP) --bin2c $(basename $(> $(addsuffix $(@F), $(addsuffix $(DEST_DIR), $(@D))) 35 | -$(SILENT) $(SHADERC) $(VS_FLAGS) --platform windows -p vs_4_0 -O 3 -f $(<) -o $(SHADER_TMP) --bin2c $(basename $(> $(addsuffix $(@F), $(addsuffix $(DEST_DIR), $(@D))) 37 | 38 | fs_%.bin.h : fs_%.sc 39 | $(SILENT) echo [$(<)] 40 | $(SILENT) $(SHADERC) $(FS_FLAGS) --platform linux -p 120 -f $(<) -o $(SHADER_TMP) --bin2c $(basename $( $(addsuffix $(@F), $(addsuffix $(DEST_DIR), $(@D))) 42 | -$(SILENT) $(SHADERC) $(FS_FLAGS) --platform windows -p ps_3_0 -O 3 -f $(<) -o $(SHADER_TMP) --bin2c $(basename $(> $(addsuffix $(@F), $(addsuffix $(DEST_DIR), $(@D))) 44 | -$(SILENT) $(SHADERC) $(FS_FLAGS) --platform windows -p ps_4_0 -O 3 -f $(<) -o $(SHADER_TMP) --bin2c $(basename $(> $(addsuffix $(@F), $(addsuffix $(DEST_DIR), $(@D))) 46 | 47 | .PHONY: all 48 | all: $(BIN) 49 | $(SILENT) rm $(SHADER_TMP) 50 | 51 | .PHONY: generate 52 | generate: 53 | $(SILENT) sh gen_headers.sh 54 | 55 | .PHONY: clean 56 | clean: 57 | @echo Cleaning... 58 | @-rm -vf $(BIN) 59 | 60 | .PHONY: rebuild 61 | rebuild: all clean 62 | 63 | rebuild: 64 | @make -s --no-print-directory clean all 65 | -------------------------------------------------------------------------------- /src/shaders/shader.shdr: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_SHADER_SHDR_HEADER_GUARD 7 | #define CMFTSTUDIO_SHADER_SHDR_HEADER_GUARD 8 | 9 | #include 10 | #include "uniforms.shdr" 11 | 12 | #endif // CMFTSTUDIO_SHADER_SHDR_HEADER_GUARD 13 | 14 | /* vim: set sw=4 ts=4 expandtab: */ 15 | -------------------------------------------------------------------------------- /src/shaders/tonemap.shdr: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_TONEMAP_SHDR_HEADER_GUARD 7 | #define CMFTSTUDIO_TONEMAP_SHDR_HEADER_GUARD 8 | 9 | #include "utils.shdr" //toGamma(), toFilmic() 10 | 11 | vec3 toReinhard1(vec3 _rgb) 12 | { 13 | float lumRgb = lumf(_rgb); 14 | float lumScale = lumRgb/(lumRgb+1.0); 15 | return toGamma(_rgb*lumScale/lumRgb); 16 | } 17 | 18 | vec3 toReinhard2(vec3 _rgb, float _whiteSq) 19 | { 20 | float lumRgb = lumf(_rgb); 21 | float lumScale = (lumRgb * (1.0 + lumRgb / _whiteSq))/(1.0 + lumRgb); 22 | return toGamma(_rgb*lumScale/lumRgb); 23 | } 24 | 25 | vec3 toUncharted2(vec3 _x) 26 | { 27 | float a = 0.22; 28 | float b = 0.30; 29 | float c = 0.10; 30 | float d = 0.20; 31 | float e = 0.01; 32 | float f = 0.30; 33 | float w = 11.2; 34 | return ((_x*(a*_x+c*b)+d*e)/(_x*(a*_x+b)+d*f))-e/f; 35 | } 36 | 37 | vec3 toUncharted2(float _x) 38 | { 39 | vec3 x = vec3_splat(_x); 40 | float a = 0.22; 41 | float b = 0.30; 42 | float c = 0.10; 43 | float d = 0.20; 44 | float e = 0.01; 45 | float f = 0.30; 46 | float w = 11.2; 47 | return ((x*(a*x+c*b)+d*e)/(x*(a*x+b)+d*f))-e/f; 48 | } 49 | 50 | vec3 tonemap(vec3 _rgb, float _whiteSq) 51 | { 52 | if (0.0 == u_toneMapping) // Linear 53 | { 54 | return _rgb; 55 | } 56 | if (1.0 == u_toneMapping) // Gamma 57 | { 58 | return toGamma(_rgb); 59 | } 60 | else if (2.0 == u_toneMapping) // Reinhard 61 | { 62 | return toReinhard1(_rgb); 63 | } 64 | else if (3.0 == u_toneMapping) // Reinhard2 65 | { 66 | return toReinhard2(_rgb, _whiteSq); 67 | } 68 | else if (4.0 == u_toneMapping) // Filmic 69 | { 70 | return toFilmic(_rgb); 71 | } 72 | else //if (5.0 == u_toneMapping). // Uncharted2 73 | { 74 | float exposureBias = 2.0f; 75 | vec3 curr = exposureBias*toUncharted2(_rgb); 76 | 77 | float w = 11.2; 78 | vec3 whiteScale = 1.0f/toUncharted2(w); 79 | 80 | _rgb = curr*whiteScale; 81 | 82 | return toGamma(_rgb); 83 | } 84 | } 85 | 86 | #endif // CMFTSTUDIO_TONEMAP_SHDR_HEADER_GUARD 87 | 88 | /* vim: set sw=4 ts=4 expandtab: */ 89 | -------------------------------------------------------------------------------- /src/shaders/uniforms.shdr: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_UNIFORMS_SHDR_HEADER_GUARD 7 | #define CMFTSTUDIO_UNIFORMS_SHDR_HEADER_GUARD 8 | 9 | uniform vec4 u_uniforms[56]; 10 | 11 | #define MAX_NUM_LIGHTS 6 12 | 13 | #define u_mtx0 u_uniforms[0] 14 | #define u_mtx1 u_uniforms[1] 15 | #define u_mtx2 u_uniforms[2] 16 | #define u_mtx3 u_uniforms[3] 17 | #define u_offsets0 u_uniforms[4].xy 18 | #define u_offsets1 u_uniforms[5].xy 19 | #define u_offsets2 u_uniforms[6].xy 20 | #define u_offsets3 u_uniforms[7].xy 21 | #define u_offsets4 u_uniforms[8].xy 22 | #define u_offsets5 u_uniforms[9].xy 23 | #define u_offsets6 u_uniforms[10].xy 24 | #define u_offsets7 u_uniforms[11].xy 25 | #define u_offsets8 u_uniforms[12].xy 26 | #define u_offsets9 u_uniforms[13].xy 27 | #define u_offsets10 u_uniforms[14].xy 28 | #define u_offsets11 u_uniforms[15].xy 29 | #define u_offsets12 u_uniforms[16].xy 30 | #define u_offsets13 u_uniforms[17].xy 31 | #define u_offsets14 u_uniforms[18].xy 32 | #define u_offsets15 u_uniforms[19].xy 33 | #define u_weight0 u_uniforms[20].x 34 | #define u_weight1 u_uniforms[20].y 35 | #define u_weight2 u_uniforms[20].z 36 | #define u_weight3 u_uniforms[20].w 37 | #define u_weight4 u_uniforms[21].x 38 | #define u_weight5 u_uniforms[21].y 39 | #define u_weight6 u_uniforms[21].z 40 | #define u_weight7 u_uniforms[21].w 41 | #define u_skyboxTransition u_uniforms[22].x 42 | #define u_enabled u_uniforms[22].y 43 | #define u_lod u_uniforms[22].z 44 | #define u_prevLod u_uniforms[22].w 45 | #define u_tonemapGamma u_uniforms[23].x 46 | #define u_tonemapMinLum u_uniforms[23].y 47 | #define u_tonemapLumRange u_uniforms[23].z 48 | #define u_texelHalf u_uniforms[23].w 49 | #define u_camPos u_uniforms[24].xyz 50 | #define u_time u_uniforms[24].w 51 | #define u_rgba u_uniforms[25] 52 | #define u_doLightAdapt u_uniforms[26].x 53 | #define u_envTransition u_uniforms[26].y 54 | #define u_edgeFixup u_uniforms[26].z 55 | #define u_prevEdgeFixup u_uniforms[26].w 56 | #define u_brightness u_uniforms[27].x 57 | #define u_contrast u_uniforms[27].y 58 | #define u_saturation u_uniforms[27].z 59 | #define u_unused270 u_uniforms[27].w 60 | #define u_backgroundSelection u_uniforms[28].x 61 | #define u_fov u_uniforms[28].y 62 | #define u_blurCoeff u_uniforms[28].z 63 | #define u_toneMapping u_uniforms[28].w 64 | #define u_mipCount u_uniforms[29].x 65 | #define u_prevMipCount u_uniforms[29].y 66 | #define u_mipSize u_uniforms[29].z 67 | #define u_prevMipSize u_uniforms[29].w 68 | #define u_exposure u_uniforms[30].x 69 | #define u_gamma u_uniforms[30].y 70 | #define u_vignette u_uniforms[30].z 71 | #define u_unused300 u_uniforms[30].w 72 | #define u_middleGray u_uniforms[31].x 73 | #define u_whiteSqr u_uniforms[31].y 74 | #define u_treshold u_uniforms[31].z 75 | #define u_doBloom u_uniforms[31].w 76 | #define u_doEnvDiff u_uniforms[32].x 77 | #define u_doEnvSpec u_uniforms[32].y 78 | #define u_ambientLightStrenght u_uniforms[32].z 79 | #define u_lightingModel u_uniforms[32].w 80 | #define u_matCam u_uniforms[33].xyz 81 | #define u_selectedLight u_uniforms[33].w 82 | #define u_lightColorStrenght0 u_uniforms[34] 83 | #define u_lightDirEnabled0 u_uniforms[35] 84 | #define u_lightColorStrenght1 u_uniforms[36] 85 | #define u_lightDirEnabled1 u_uniforms[37] 86 | #define u_lightColorStrenght2 u_uniforms[38] 87 | #define u_lightDirEnabled2 u_uniforms[39] 88 | #define u_lightColorStrenght3 u_uniforms[40] 89 | #define u_lightDirEnabled3 u_uniforms[41] 90 | #define u_lightColorStrenght4 u_uniforms[42] 91 | #define u_lightDirEnabled4 u_uniforms[43] 92 | #define u_lightColorStrenght5 u_uniforms[44] 93 | #define u_lightDirEnabled5 u_uniforms[45] 94 | 95 | // Material. 96 | #define u_albedoColor u_uniforms[46].xyz 97 | #define u_sampleAlbedo u_uniforms[46].w 98 | #define u_reflectivityColor u_uniforms[47].xyz 99 | #define u_sampleReflectivity u_uniforms[47].w 100 | #define u_emissiveColor u_uniforms[48].xyz 101 | #define u_sampleEmissive u_uniforms[48].w 102 | #define u_gloss u_uniforms[49].x 103 | #define u_sampleGloss u_uniforms[49].y 104 | #define u_normalMul u_uniforms[49].z 105 | #define u_sampleNormal u_uniforms[49].w 106 | #define u_reflectivity u_uniforms[50].x 107 | #define u_metalOrSpec u_uniforms[50].y 108 | #define u_fresnel u_uniforms[50].z 109 | #define u_specAttn u_uniforms[50].w 110 | #define u_invGloss u_uniforms[51].x 111 | #define u_invMetalness u_uniforms[51].y 112 | #define u_texMultiplier u_uniforms[51].z 113 | #define u_unusedM0 u_uniforms[51].w 114 | #define u_sampleAo u_uniforms[52].x 115 | #define u_aoBias u_uniforms[52].y 116 | #define u_emissiveIntensity u_uniforms[52].z 117 | #define u_unusedM1 u_uniforms[52].w 118 | #define u_swizSurface u_uniforms[53] 119 | #define u_swizReflectivity u_uniforms[54] 120 | #define u_swizAo u_uniforms[55] 121 | 122 | #endif // CMFTSTUDIO_UNIFORMS_SHDR_HEADER_GUARD 123 | 124 | /* vim: set sw=4 ts=4 expandtab: */ 125 | -------------------------------------------------------------------------------- /src/shaders/utils.shdr: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_UTILS_SHDR_HEADER_GUARD 7 | #define CMFTSTUDIO_UTILS_SHDR_HEADER_GUARD 8 | 9 | #include "../../../bgfx/examples/common/shaderlib.sh" 10 | 11 | float lumf(vec3 _rgb) 12 | { 13 | return dot(vec3(0.2126729, 0.7151522, 0.0721750), _rgb); 14 | } 15 | 16 | vec3 grayscaleFade(vec3 _src, vec3 _dst, float _a) 17 | { 18 | float grayPhase = 0.3; 19 | return mix(mix(luma(_src), _src, smoothstep(1.0-grayPhase, 0.0, _a)) 20 | , mix(luma(_dst), _dst, smoothstep( grayPhase, 1.0, _a)) 21 | , _a 22 | ); 23 | } 24 | 25 | vec4 blur9(sampler2D _sampler 26 | , vec2 _uv0 27 | , vec4 _uv1 28 | , vec4 _uv2 29 | , vec4 _uv3 30 | , vec4 _uv4 31 | , float _weight0 32 | , float _weight1 33 | , float _weight2 34 | , float _weight3 35 | , float _weight4 36 | ) 37 | { 38 | vec4 blur; 39 | blur = texture2D(_sampler, _uv0) *_weight0; 40 | blur += texture2D(_sampler, _uv1.xy)*_weight1; 41 | blur += texture2D(_sampler, _uv1.zw)*_weight1; 42 | blur += texture2D(_sampler, _uv2.xy)*_weight2; 43 | blur += texture2D(_sampler, _uv2.zw)*_weight2; 44 | blur += texture2D(_sampler, _uv3.xy)*_weight3; 45 | blur += texture2D(_sampler, _uv3.zw)*_weight3; 46 | blur += texture2D(_sampler, _uv4.xy)*_weight4; 47 | blur += texture2D(_sampler, _uv4.zw)*_weight4; 48 | return blur; 49 | } 50 | 51 | // Ref: http://the-witness.net/news/2012/02/seamless-cube-map-filtering/ 52 | vec3 fixCubeLookup(vec3 _v, float _lod, float _topLevelCubeSize) 53 | { 54 | float ax = abs(_v.x); 55 | float ay = abs(_v.y); 56 | float az = abs(_v.z); 57 | float vmax = max(max(ax, ay), az); 58 | float scale = 1.0 - exp2(_lod) / _topLevelCubeSize; 59 | if (ax != vmax) { _v.x *= scale; } 60 | if (ay != vmax) { _v.y *= scale; } 61 | if (az != vmax) { _v.z *= scale; } 62 | return _v; 63 | } 64 | 65 | vec3 vecFromLatLong(vec2 _uv) 66 | { 67 | float pi = 3.14159265; 68 | float twoPi = 2.0*pi; 69 | float phi = _uv.x * twoPi; 70 | float theta = _uv.y * pi; 71 | 72 | vec3 result; 73 | result.x = -sin(theta)*sin(phi); 74 | result.y = cos(theta); 75 | result.z = -sin(theta)*cos(phi); 76 | 77 | return result; 78 | } 79 | 80 | #endif // CMFTSTUDIO_UTILS_SHDR_HEADER_GUARD 81 | 82 | /* vim: set sw=4 ts=4 expandtab: */ 83 | -------------------------------------------------------------------------------- /src/shaders/varying.def.sc: -------------------------------------------------------------------------------- 1 | vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0); 2 | vec4 v_texcoord1 : TEXCOORD1 = vec4(0.0, 0.0, 0.0, 0.0); 3 | vec4 v_texcoord2 : TEXCOORD2 = vec4(0.0, 0.0, 0.0, 0.0); 4 | vec4 v_texcoord3 : TEXCOORD3 = vec4(0.0, 0.0, 0.0, 0.0); 5 | vec4 v_texcoord4 : TEXCOORD4 = vec4(0.0, 0.0, 0.0, 0.0); 6 | vec3 v_dir : TEXCOORD5 = vec3(0.0, 0.0, 0.0); 7 | vec3 v_view : TEXCOORD6 = vec3(0.0, 0.0, 0.0); 8 | vec3 v_normal : NORMAL = vec3(0.0, 0.0, 1.0); 9 | vec3 v_tangent : TANGENT = vec3(1.0, 0.0, 0.0); 10 | vec3 v_bitangent : BINORMAL = vec3(0.0, 1.0, 0.0); 11 | 12 | vec4 v_normal4 : NORMAL = vec4(0.0, 0.0, 1.0, 1.0); 13 | vec4 v_tangent4 : TANGENT = vec4(1.0, 0.0, 0.0, 1.0); 14 | 15 | vec3 a_position : POSITION; 16 | vec2 a_texcoord0 : TEXCOORD0; 17 | vec4 a_normal : NORMAL; 18 | vec4 a_tangent : TANGENT; 19 | -------------------------------------------------------------------------------- /src/shaders/vs_blur.sc: -------------------------------------------------------------------------------- 1 | $input a_position, a_texcoord0 2 | $output v_texcoord0, v_texcoord1, v_texcoord2, v_texcoord3, v_texcoord4 3 | 4 | /* 5 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 6 | * License: http://www.opensource.org/licenses/BSD-2-Clause 7 | */ 8 | 9 | #include "shader.shdr" 10 | 11 | void main() 12 | { 13 | gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) ); 14 | v_texcoord0 = a_texcoord0; 15 | v_texcoord1 = vec4(a_texcoord0.x, a_texcoord0.y - u_viewTexel.y*1.0, 16 | a_texcoord0.x, a_texcoord0.y + u_viewTexel.y*1.0 17 | ); 18 | v_texcoord2 = vec4(a_texcoord0.x, a_texcoord0.y - u_viewTexel.y*2.0, 19 | a_texcoord0.x, a_texcoord0.y + u_viewTexel.y*2.0 20 | ); 21 | v_texcoord3 = vec4(a_texcoord0.x, a_texcoord0.y - u_viewTexel.y*3.0, 22 | a_texcoord0.x, a_texcoord0.y + u_viewTexel.y*3.0 23 | ); 24 | v_texcoord4 = vec4(a_texcoord0.x, a_texcoord0.y - u_viewTexel.y*4.0, 25 | a_texcoord0.x, a_texcoord0.y + u_viewTexel.y*4.0 26 | ); 27 | } 28 | 29 | /* vim: set sw=4 ts=4 expandtab: */ 30 | -------------------------------------------------------------------------------- /src/shaders/vs_material.sc: -------------------------------------------------------------------------------- 1 | $input a_position, a_normal, a_texcoord0 2 | $output v_view, v_normal, v_texcoord0 3 | 4 | /* 5 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 6 | * License: http://www.opensource.org/licenses/BSD-2-Clause 7 | */ 8 | 9 | #define CameraPos u_matCam 10 | 11 | #include "vs_mesh.shdr" 12 | -------------------------------------------------------------------------------- /src/shaders/vs_material_normal.sc: -------------------------------------------------------------------------------- 1 | $input a_position, a_normal, a_tangent, a_texcoord0 2 | $output v_view, v_normal, v_tangent, v_bitangent, v_texcoord0 3 | 4 | /* 5 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 6 | * License: http://www.opensource.org/licenses/BSD-2-Clause 7 | */ 8 | 9 | #define CameraPos u_matCam 10 | 11 | #define NORMAL_MAP 12 | #include "vs_mesh.shdr" 13 | -------------------------------------------------------------------------------- /src/shaders/vs_mesh.sc: -------------------------------------------------------------------------------- 1 | $input a_position, a_normal, a_texcoord0 2 | $output v_view, v_normal, v_texcoord0 3 | 4 | /* 5 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 6 | * License: http://www.opensource.org/licenses/BSD-2-Clause 7 | */ 8 | 9 | #include "vs_mesh.shdr" 10 | -------------------------------------------------------------------------------- /src/shaders/vs_mesh.shdr: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #include "shader.shdr" 7 | 8 | #ifndef CameraPos 9 | #define CameraPos u_camPos 10 | #endif 11 | 12 | void main() 13 | { 14 | gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) ); 15 | 16 | vec4 normal = a_normal * 2.0 - 1.0; 17 | vec3 viewNormal = normalize(mul(u_model[0], vec4(normal.xyz, 0.0)).xyz); 18 | 19 | v_normal = viewNormal; 20 | v_view = normalize(CameraPos - mul(u_model[0], vec4(a_position, 1.0)).xyz); 21 | 22 | v_texcoord0 = a_texcoord0; 23 | 24 | #ifdef NORMAL_MAP 25 | vec4 tangent = a_tangent * 2.0 - 1.0; 26 | vec3 viewTangent = normalize(mul(u_model[0], vec4(tangent.xyz, 0.0)).xyz); 27 | 28 | vec3 viewBitangent = cross(viewNormal, viewTangent) * tangent.w; 29 | 30 | v_tangent = viewTangent; 31 | v_bitangent = viewBitangent; 32 | #endif 33 | } 34 | 35 | /* vim: set sw=4 ts=4 expandtab: */ 36 | -------------------------------------------------------------------------------- /src/shaders/vs_mesh_color.sc: -------------------------------------------------------------------------------- 1 | $input a_position, a_normal 2 | $output v_view, v_normal 3 | 4 | /* 5 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 6 | * License: http://www.opensource.org/licenses/BSD-2-Clause 7 | */ 8 | 9 | #include "shader.shdr" 10 | 11 | void main() 12 | { 13 | gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) ); 14 | 15 | vec4 normal = a_normal * 2.0 - 1.0; 16 | v_normal = mul(u_model[0], vec4(normal.xyz, 0.0) ).xyz; 17 | v_view = normalize(u_camPos - mul(u_model[0], vec4(a_position, 1.0)).xyz); 18 | } 19 | -------------------------------------------------------------------------------- /src/shaders/vs_mesh_normal.sc: -------------------------------------------------------------------------------- 1 | $input a_position, a_normal, a_tangent, a_texcoord0 2 | $output v_view, v_normal, v_tangent, v_bitangent, v_texcoord0 3 | 4 | /* 5 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 6 | * License: http://www.opensource.org/licenses/BSD-2-Clause 7 | */ 8 | 9 | #define NORMAL_MAP 10 | #include "vs_mesh.shdr" 11 | -------------------------------------------------------------------------------- /src/shaders/vs_mesh_tex.sc: -------------------------------------------------------------------------------- 1 | $input a_position, a_normal, a_tangent, a_texcoord0 2 | $output v_view, v_normal4, v_tangent4, v_bitangent, v_texcoord0 3 | 4 | /* 5 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 6 | * License: http://www.opensource.org/licenses/BSD-2-Clause 7 | */ 8 | 9 | #include "shader.shdr" 10 | 11 | void main() 12 | { 13 | gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) ); 14 | 15 | vec4 normal = a_normal * 2.0 - 1.0; 16 | vec4 tangent = a_tangent; 17 | tangent.xyz = tangent.xyz * 2.0 - 1.0; 18 | 19 | //TODO 20 | //vec3 viewNormal = normalize(mul(u_model[0], vec4(normal.xyz, 0.0)).xyz); 21 | //vec3 viewTangent = normalize(mul(u_model[0], vec4(tangent.xyz, 0.0)).xyz); 22 | //vec3 viewBitangent = cross(viewNormal, viewTangent) * tangent.w; 23 | //mat3 tbn = mat3(viewTangent, viewBitangent, viewNormal); 24 | 25 | v_view = normalize(u_camPos - mul(u_model[0], vec4(a_position, 1.0)).xyz); 26 | 27 | //v_normal = viewNormal; 28 | //v_tangent = viewTangent; 29 | v_normal4 = normal; 30 | v_tangent4 = tangent; 31 | v_bitangent = vec3_splat(1.0); 32 | v_texcoord0 = a_texcoord0; 33 | } 34 | 35 | /* vim: set sw=4 ts=4 expandtab: */ 36 | -------------------------------------------------------------------------------- /src/shaders/vs_plain.sc: -------------------------------------------------------------------------------- 1 | $input a_position 2 | 3 | /* 4 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | * License: http://www.opensource.org/licenses/BSD-2-Clause 6 | */ 7 | 8 | #include "shader.shdr" 9 | 10 | void main() 11 | { 12 | gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0)); 13 | } 14 | 15 | /* vim: set sw=4 ts=4 expandtab: */ 16 | -------------------------------------------------------------------------------- /src/shaders/vs_skybox.sc: -------------------------------------------------------------------------------- 1 | $input a_position, a_texcoord0 2 | $output v_dir 3 | 4 | /* 5 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 6 | * License: http://www.opensource.org/licenses/BSD-2-Clause 7 | */ 8 | 9 | #include "shader.shdr" 10 | 11 | void main() 12 | { 13 | gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) ); 14 | 15 | float height = tan(u_fov*0.5); 16 | float aspect = height*(4.0/3.0); 17 | 18 | vec2 tex = (2.0*a_texcoord0-1.0) * vec2(aspect, height); 19 | 20 | mat4 mtx; 21 | mtx[0] = u_mtx0; 22 | mtx[1] = u_mtx1; 23 | mtx[2] = u_mtx2; 24 | mtx[3] = u_mtx3; 25 | v_dir = instMul(mtx, vec4(tex, 1.0, 0.0) ).xyz; 26 | } 27 | 28 | /* vim: set sw=4 ts=4 expandtab: */ 29 | -------------------------------------------------------------------------------- /src/shaders/vs_texcoord.sc: -------------------------------------------------------------------------------- 1 | $input a_position, a_texcoord0 2 | $output v_texcoord0 3 | 4 | /* 5 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 6 | * License: http://www.opensource.org/licenses/BSD-2-Clause 7 | */ 8 | 9 | #include "shader.shdr" 10 | 11 | void main() 12 | { 13 | gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0)); 14 | v_texcoord0 = a_texcoord0; 15 | } 16 | 17 | /* vim: set sw=4 ts=4 expandtab: */ 18 | -------------------------------------------------------------------------------- /src/shaders/vs_tonemap.sc: -------------------------------------------------------------------------------- 1 | $input a_position, a_texcoord0 2 | $output v_texcoord0, v_texcoord1, v_texcoord2, v_texcoord3, v_texcoord4 3 | 4 | /* 5 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 6 | * License: http://www.opensource.org/licenses/BSD-2-Clause 7 | */ 8 | 9 | #include "shader.shdr" 10 | 11 | void main() 12 | { 13 | float offset = u_viewTexel.x*6.0; 14 | 15 | gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) ); 16 | v_texcoord0 = a_texcoord0; 17 | v_texcoord1 = vec4(a_texcoord0.x - offset*1.0, a_texcoord0.y, 18 | a_texcoord0.x + offset*1.0, a_texcoord0.y 19 | ); 20 | v_texcoord2 = vec4(a_texcoord0.x - offset*2.0, a_texcoord0.y, 21 | a_texcoord0.x + offset*2.0, a_texcoord0.y 22 | ); 23 | v_texcoord3 = vec4(a_texcoord0.x - offset*3.0, a_texcoord0.y, 24 | a_texcoord0.x + offset*3.0, a_texcoord0.y 25 | ); 26 | v_texcoord4 = vec4(a_texcoord0.x - offset*4.0, a_texcoord0.y, 27 | a_texcoord0.x + offset*4.0, a_texcoord0.y 28 | ); 29 | } 30 | 31 | /* vim: set sw=4 ts=4 expandtab: */ 32 | -------------------------------------------------------------------------------- /src/staticres.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #include "common/common.h" 7 | #include "staticres.h" 8 | 9 | #include "inflatedeflate.h" 10 | #include 11 | 12 | // Resource headers. 13 | #define SR_INCLUDE 14 | #include "staticres_res.h" 15 | 16 | // Declarations. 17 | #define SR_DESC(_name, _dataArray) \ 18 | void* g_ ## _name; \ 19 | uint32_t g_ ## _name ## Size; 20 | #include "staticres_res.h" 21 | 22 | #define SR_DESC_COMPR(_name, _dataArray) \ 23 | void* g_ ## _name; \ 24 | uint32_t g_ ## _name ## Size; 25 | #include "staticres_res.h" 26 | 27 | static inline void readCompressedData(void*& _out, uint32_t& _outSize, const void* _inData, uint32_t _inDataSize) 28 | { 29 | // Take all available static memory. 30 | const uint32_t available = (uint32_t)dm::allocRemainingStaticMemory(); 31 | void* mem = DM_ALLOC(dm::staticAlloc, available); 32 | bx::StaticMemoryBlockWriter memBlock(mem, available); 33 | 34 | // Read and decompress data. 35 | bx::MemoryReader reader(_inData, _inDataSize); 36 | const bool result = cs::readInflate(&memBlock, &reader, _inDataSize, dm::stackAlloc); 37 | CS_CHECK(result, "cs::readInflate() failed!"); 38 | BX_UNUSED(result); 39 | 40 | // Return back unused memory. 41 | const uint32_t size = (uint32_t)memBlock.seek(0, bx::Whence::Current); 42 | void* data = DM_REALLOC(dm::staticAlloc, mem, size); 43 | 44 | _out = data; 45 | _outSize = size; 46 | } 47 | 48 | void initStaticResources() 49 | { 50 | #define SR_DESC(_name, _dataArray) \ 51 | g_##_name = (void*)&_dataArray; \ 52 | g_##_name##Size = sizeof(_dataArray); 53 | #include "staticres_res.h" 54 | 55 | #define SR_DESC_COMPR(_name, _dataArray) \ 56 | readCompressedData(g_##_name, g_##_name##Size, (void*)_dataArray, sizeof(_dataArray)); 57 | #include "staticres_res.h" 58 | } 59 | 60 | /* vim: set sw=4 ts=4 expandtab: */ 61 | -------------------------------------------------------------------------------- /src/staticres.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFTSTUDIO_STATIC_RESOURCES_H_HEADER_GUARD 7 | #define CMFTSTUDIO_STATIC_RESOURCES_H_HEADER_GUARD 8 | 9 | #include 10 | 11 | // Extern declarations. 12 | #define SR_DESC(_name, _dataArray) \ 13 | extern void* g_ ## _name; \ 14 | extern uint32_t g_ ## _name ## Size; 15 | #include "staticres_res.h" 16 | 17 | #define SR_DESC_COMPR(_name, _dataArray) \ 18 | extern void* g_ ## _name; \ 19 | extern uint32_t g_ ## _name ## Size; 20 | #include "staticres_res.h" 21 | 22 | void initStaticResources(); 23 | 24 | #endif // CMFTSTUDIO_STATIC_RESOURCES_H_HEADER_GUARD 25 | 26 | /* vim: set sw=4 ts=4 expandtab: */ 27 | -------------------------------------------------------------------------------- /src/staticres_res.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | // Resource headers. 7 | //----- 8 | 9 | #ifdef SR_INCLUDE 10 | #include "res/sphere.h" 11 | #include "res/sphereSurfaceTex.h" 12 | #include "res/loading_screen.h" 13 | #include "res/sun_icon.h" 14 | #include "res/logo_skybox.h" 15 | #include "res/logo_pmrem.h" 16 | #include "res/logo_iem.h" 17 | #include "res/brick_n.h" 18 | #include "res/brick_ao.h" 19 | #include "res/stripes_s.h" 20 | #include "res/droidsans.h" 21 | #include "res/droidsansmono.h" 22 | #undef SR_INCLUDE 23 | #endif //SR_INCLUDE 24 | 25 | // Uncompressed resources. 26 | //----- 27 | 28 | #ifndef SR_DESC 29 | #define SR_DESC(_name, _dataArray) 30 | #endif //!defined(SR_DESC) 31 | SR_DESC(sphereMesh, sc_sphereMesh) 32 | #undef SR_DESC 33 | 34 | // Compressed resources. 35 | //----- 36 | 37 | #ifndef SR_DESC_COMPR 38 | #define SR_DESC_COMPR(_name, _dataArray) 39 | #endif //!defined(SR_DESC_COMPR) 40 | // Textures: 41 | SR_DESC_COMPR(loadingScreenTex , sc_loadingScreenCompressed) 42 | SR_DESC_COMPR(sphereSurfaceTex , sc_sphereSurfaceTexCompressed) 43 | SR_DESC_COMPR(sunIcon , sc_sunIconCompressed) 44 | SR_DESC_COMPR(bricksN , sc_brickNCompressed) 45 | SR_DESC_COMPR(bricksAo , sc_brickAoCompressed) 46 | SR_DESC_COMPR(stripesS , sc_stripesSCompressed) 47 | // Cubemaps: 48 | SR_DESC_COMPR(logoSkybox , sc_logoSkyboxCompressed) 49 | SR_DESC_COMPR(logoPmrem , sc_logoPmremCompressed) 50 | SR_DESC_COMPR(logoIem , sc_logoIemCompressed) 51 | // Fonts: 52 | SR_DESC_COMPR(droidSans , sc_droidSansCompressed) 53 | SR_DESC_COMPR(droidSansMono , sc_droidSansMonoCompressed) 54 | #undef SR_DESC_COMPR 55 | 56 | /* vim: set sw=4 ts=4 expandtab: */ 57 | 58 | -------------------------------------------------------------------------------- /tools/bin/windows/rawcompress.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmftStudio/46f006f22a8c6683da23cee015c6898eb5ab6d3f/tools/bin/windows/rawcompress.exe -------------------------------------------------------------------------------- /tools/src/rawcompress.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | // Miniz configuration. 15 | BX_PRAGMA_DIAGNOSTIC_PUSH_GCC() 16 | BX_PRAGMA_DIAGNOSTIC_IGNORED_GCC("-Wstrict-aliasing") 17 | #define MINIZ_NO_TIME 18 | #define MINIZ_NO_ARCHIVE_APIS 19 | #define MINIZ_NO_ARCHIVE_WRITING_APIS 20 | #include 21 | BX_PRAGMA_DIAGNOSTIC_POP_GCC() 22 | 23 | // Misc. 24 | #define MEGABYTES(_MB) (_MB<<20) 25 | 26 | #define RC_MIN(_a, _b) (_a)<(_b)?(_a):(_b) 27 | #define RC_MAX(_a, _b) (_a)>(_b)?(_a):(_b) 28 | #define RC_CLAMP(_val, _min, _max) RC_MIN(RC_MAX(_val, _min), _max) 29 | 30 | struct DeflateFileWriter : public bx::FileWriterI 31 | { 32 | DeflateFileWriter(int32_t _writeCacheBufferSize, uint32_t _deflateBufferSize, int _compressionLevel) 33 | { 34 | m_writeCacheBufferSize = _writeCacheBufferSize; 35 | m_deflateBufferSize = _deflateBufferSize; 36 | 37 | m_file = NULL; 38 | m_consumed = 0; 39 | m_total = 0; 40 | m_totalCompressed = 0; 41 | 42 | m_inBuf = (uint8_t*)malloc(m_writeCacheBufferSize+m_deflateBufferSize); 43 | m_outBuf = m_inBuf + m_writeCacheBufferSize; 44 | 45 | memset(&m_stream, 0, sizeof(m_stream)); 46 | m_stream.next_in = m_inBuf; 47 | m_stream.avail_in = 0; 48 | m_stream.next_out = m_outBuf; 49 | m_stream.avail_out = m_deflateBufferSize; 50 | 51 | deflateInit(&m_stream, _compressionLevel); 52 | } 53 | 54 | virtual ~DeflateFileWriter() 55 | { 56 | if (NULL != m_inBuf) 57 | { 58 | free(m_inBuf); 59 | } 60 | } 61 | 62 | void assign(FILE* _file) 63 | { 64 | m_file = _file; 65 | } 66 | 67 | virtual int32_t open(const char* _filePath, bool _append = false) BX_OVERRIDE 68 | { 69 | if (_append) 70 | { 71 | m_file = fopen(_filePath, "ab"); 72 | } 73 | else 74 | { 75 | m_file = fopen(_filePath, "wb"); 76 | } 77 | 78 | return (NULL == m_file); 79 | } 80 | 81 | virtual int64_t seek(int64_t _offset = 0, bx::Whence::Enum _whence = bx::Whence::Current) BX_OVERRIDE 82 | { 83 | fseeko64(m_file, _offset, _whence); 84 | return ftello64(m_file); 85 | } 86 | 87 | virtual int32_t write(const void* _data, int32_t _size) BX_OVERRIDE 88 | { 89 | int32_t queued = _size; 90 | 91 | while (queued > 0) 92 | { 93 | const uint32_t srcOffset = _size-queued; 94 | const uint32_t dstOffset = m_consumed; 95 | 96 | const uint32_t available = m_writeCacheBufferSize - m_consumed; 97 | const uint32_t size = RC_MIN(available, uint32_t(queued)); 98 | 99 | memcpy((uint8_t*)m_inBuf+dstOffset, (uint8_t*)_data+srcOffset, size); 100 | m_consumed += size; 101 | m_total += size; 102 | queued -= size; 103 | 104 | if (m_consumed == m_writeCacheBufferSize) 105 | { 106 | if (0 != deflateWrite()) 107 | { 108 | return EXIT_FAILURE; 109 | } 110 | } 111 | 112 | } 113 | 114 | return _size; 115 | } 116 | 117 | int32_t deflateWrite(int _flush = MZ_NO_FLUSH) 118 | { 119 | m_stream.next_in = m_inBuf; 120 | m_stream.avail_in = m_consumed; 121 | m_stream.next_out = m_outBuf; 122 | m_stream.avail_out = m_deflateBufferSize; 123 | 124 | m_consumed = 0; 125 | 126 | while (0 != m_stream.avail_in) 127 | { 128 | if (deflate(&m_stream, _flush) < 0) 129 | { 130 | return EXIT_FAILURE; 131 | } 132 | 133 | if (m_stream.avail_out != m_deflateBufferSize) 134 | { 135 | const size_t size = m_deflateBufferSize - m_stream.avail_out; 136 | if (fwrite(m_outBuf, 1, size, m_file) != size) 137 | { 138 | return EXIT_FAILURE; 139 | } 140 | m_totalCompressed += size; 141 | m_stream.next_out = m_outBuf; 142 | m_stream.avail_out = m_deflateBufferSize; 143 | } 144 | } 145 | 146 | return EXIT_SUCCESS; 147 | } 148 | 149 | uint64_t getTotal() const 150 | { 151 | return m_total; 152 | } 153 | 154 | uint64_t getTotalCompressed() const 155 | { 156 | return m_totalCompressed; 157 | } 158 | 159 | virtual int32_t close() BX_OVERRIDE 160 | { 161 | deflateWrite(MZ_FINISH); 162 | const int32_t status = deflateEnd(&m_stream); 163 | fclose(m_file); 164 | 165 | return status; 166 | } 167 | 168 | private: 169 | uint32_t m_writeCacheBufferSize; 170 | uint32_t m_deflateBufferSize; 171 | FILE* m_file; 172 | uint32_t m_consumed; 173 | uint64_t m_total; 174 | uint64_t m_totalCompressed; 175 | uint8_t* m_inBuf; 176 | uint8_t* m_outBuf; 177 | z_stream m_stream; 178 | }; 179 | 180 | static void help(const char* _error = NULL) 181 | { 182 | if (NULL != _error) 183 | { 184 | fprintf(stderr, "Error:\n%s\n\n", _error); 185 | } 186 | 187 | fprintf(stderr 188 | , "Usage: rawcompress -i -o \n" 189 | 190 | "\n" 191 | "Options:\n" 192 | " -i Input file path.\n" 193 | " -o Output file path.\n" 194 | ); 195 | } 196 | 197 | int main(int _argc, const char* _argv[]) 198 | { 199 | bx::CommandLine cmdLine(_argc, _argv); 200 | 201 | if (cmdLine.hasArg('h', "help") ) 202 | { 203 | help(); 204 | return EXIT_FAILURE; 205 | } 206 | 207 | const char* filePath = cmdLine.findOption('i'); 208 | if (NULL == filePath) 209 | { 210 | help("Input file name must be specified."); 211 | return EXIT_FAILURE; 212 | } 213 | 214 | const char* outFilePath = cmdLine.findOption('o'); 215 | if (NULL == outFilePath) 216 | { 217 | help("Output file name must be specified."); 218 | return EXIT_FAILURE; 219 | } 220 | 221 | void* data = NULL; 222 | uint32_t size = 0; 223 | 224 | bx::CrtFileReader fr; 225 | if (0 == bx::open(&fr, filePath) ) 226 | { 227 | size = (uint32_t)bx::getSize(&fr); 228 | data = malloc(size); 229 | bx::read(&fr, data, size); 230 | 231 | FILE* file = fopen(outFilePath, "wb"); 232 | if (NULL != file) 233 | { 234 | enum { CompressionLevel = 10 }; 235 | DeflateFileWriter writer(MEGABYTES(20), MEGABYTES(20), CompressionLevel); 236 | writer.assign(file); 237 | writer.write(data, size); 238 | writer.close(); 239 | } 240 | 241 | free(data); 242 | } 243 | 244 | return 0; 245 | } 246 | 247 | /* vim: set sw=4 ts=4 expandtab: */ 248 | --------------------------------------------------------------------------------