├── .gitattributes ├── .gitignore ├── .ide.vim ├── .makebg.sh ├── LICENSE ├── Makefile ├── README.md ├── dependency ├── CL │ ├── cl.h │ ├── cl_d3d10.h │ ├── cl_d3d11.h │ ├── cl_dx9_media_sharing.h │ ├── cl_egl.h │ ├── cl_ext.h │ ├── cl_gl.h │ ├── cl_gl_ext.h │ ├── cl_platform.h │ └── opencl.h ├── bx │ ├── .editorconfig │ ├── .gitattributes │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── makefile │ └── tools │ │ ├── bin │ │ ├── darwin │ │ │ └── genie │ │ ├── linux │ │ │ └── genie │ │ └── windows │ │ │ └── genie.exe │ │ └── bin2c │ │ └── bin2c.cpp └── stb │ └── stb_image.h ├── include └── cmft │ ├── allocator.h │ ├── clcontext.h │ ├── cubemapfilter.h │ ├── image.h │ └── print.h ├── res ├── cmft_cover.jpg └── cmft_performance_chart.png ├── runtime ├── .gitignore ├── cmft_lin.sh ├── cmft_osx.sh ├── cmft_win.bat └── okretnica.tga ├── scripts ├── cmft.lua ├── cmft_cli.lua ├── main.lua └── toolchain.lua └── src ├── cmft ├── allocator.cpp ├── clcontext.cpp ├── clcontext_internal.h ├── common │ ├── cl.h │ ├── commandline.h │ ├── config.h │ ├── fpumath.h │ ├── halffloat.h │ ├── handlealloc.h │ ├── os.h │ ├── platform.h │ ├── print.cpp │ ├── stb_image.cpp │ ├── stb_image.h │ ├── timer.h │ └── utils.h ├── cubemapfilter.cpp ├── cubemaputils.h ├── image.cpp ├── radiance.cl └── radiance.h ├── cmft_cli └── cmft_cli.h ├── cmft_tests ├── tests.h └── tokenize.h └── main.cpp /.gitattributes: -------------------------------------------------------------------------------- 1 | *.cpp eol=lf 2 | *.h eol=lf 3 | *.sc eol=lf 4 | *.sh eol=lf 5 | *.md eol=lf 6 | *.lua eol=lf 7 | *.mk eol=lf 8 | makefile eol=lf 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | _build/ 2 | _projects/ 3 | .svn/ 4 | tags 5 | .DS_Store 6 | .vim 7 | make.log 8 | -------------------------------------------------------------------------------- /.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_name = "cmft" 12 | let s:proj_root = expand(":p:h") 13 | let s:makebg_file = s:proj_root."/.makebg.sh" 14 | let s:log_file = s:proj_root."/make.log" 15 | 16 | let s:exec_action = "!../_build/linux64_gcc/bin/".s:proj_name."Debug" 17 | let s:gdb_action = "!gdb -x ".s:proj_root."/.gdbinit"." --args ../_build/linux64_gcc/bin/".s:proj_name."Debug" 18 | 19 | let s:make_action = "linux-debug64" 20 | 21 | function! SetDebug() 22 | let s:make_action = "linux-debug64" 23 | let s:exec_action = "!../_build/linux64_gcc/bin/".s:proj_name."Debug" 24 | endfunc 25 | command! -nargs=0 SetDebug :call SetDebug() 26 | 27 | function! SetRelease() 28 | let s:make_action = "linux-release64" 29 | let s:exec_action = "!../_build/linux64_gcc/bin/".s:proj_name."Release" 30 | endfunc 31 | command! -nargs=0 SetRelease :call SetRelease() 32 | 33 | function! Build() 34 | let s:make_command = "make ".s:proj_root." ".s:make_action 35 | let s:build_action = "!".s:makebg_file." ".v:servername." \"".s:make_command."\" ".s:log_file 36 | let curr_dir = getcwd() 37 | exec 'cd' s:proj_root 38 | exec s:build_action 39 | exec 'cd' curr_dir 40 | endfunc 41 | 42 | function! Execute() 43 | let s:runtime_dir = s:proj_root."/runtime" 44 | let curr_dir = getcwd() 45 | exec 'cd' s:runtime_dir 46 | exec s:exec_action 47 | exec 'cd' curr_dir 48 | endfunc 49 | 50 | function! DebugGdb() 51 | let s:runtime_dir = s:proj_root."/runtime" 52 | let curr_dir = getcwd() 53 | exec 'cd' s:runtime_dir 54 | exec s:gdb_action 55 | exec 'cd' curr_dir 56 | endfunc 57 | 58 | nmap ,rr :call Build() 59 | nmap ,ee :call Execute() 60 | nmap ,gdb :call DebugGdb() 61 | 62 | endif 63 | -------------------------------------------------------------------------------- /.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/cmft 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/cmft/blob/master/LICENSE 27 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | # License: http://www.opensource.org/licenses/BSD-2-Clause 4 | # 5 | 6 | VS2008_DEVENV_DIR=C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE 7 | VS2010_DEVENV_DIR=C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE 8 | VS2012_DEVENV_DIR=C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE 9 | 10 | ifeq ($(OS),Windows_NT) 11 | OS=windows 12 | else 13 | UNAME := $(shell uname -s) 14 | ifeq ($(UNAME),Darwin) 15 | OS=darwin 16 | endif 17 | ifeq ($(UNAME),Linux) 18 | OS=linux 19 | endif 20 | endif 21 | 22 | GENIE=./dependency/bx/tools/bin/$(OS)/genie 23 | 24 | export CMFT_WIN_CLANG_DIR_=$(subst \,\\,$(subst /,\,$(WIN_CLANG_DIR))) 25 | export CMFT_WIN_MINGW_DIR_=$(subst \,\\,$(subst /,\,$(WIN_MINGW_DIR))) 26 | 27 | .PHONY: all 28 | all: 29 | $(GENIE) --file=scripts/main.lua xcode4 30 | $(GENIE) --file=scripts/main.lua vs2008 31 | $(GENIE) --file=scripts/main.lua vs2010 32 | $(GENIE) --file=scripts/main.lua vs2012 33 | $(GENIE) --file=scripts/main.lua vs2013 34 | $(GENIE) --file=scripts/main.lua vs2015 35 | $(GENIE) --file=scripts/main.lua --gcc=mingw-gcc gmake 36 | $(GENIE) --file=scripts/main.lua --gcc=linux-gcc gmake 37 | $(GENIE) --file=scripts/main.lua --gcc=osx gmake 38 | 39 | .PHONY: clean-projects 40 | clean-projects: 41 | @echo Removing _projects folder. 42 | -@rm -rf _projects 43 | 44 | .PHONY: clean-build 45 | clean-build: 46 | @echo Removing _build folder. 47 | -@rm -rf _build 48 | 49 | .PHONY: clean 50 | clean: clean-build clean-projects 51 | 52 | _projects/xcode4: 53 | $(GENIE) --file=scripts/main.lua xcode4 54 | 55 | _projects/vs2008: 56 | $(GENIE) --file=scripts/main.lua vs2008 57 | vs2008-debug32: 58 | "$(subst /,\\,$(VS2008_DEVENV_DIR))\devenv" _projects/vs2008/cmft.sln /Build "Debug|Win32" 59 | vs2008-release32: 60 | "$(subst /,\\,$(VS2008_DEVENV_DIR))\devenv" _projects/vs2008/cmft.sln /Build "Release|Win32" 61 | vs2008-debug64: 62 | "$(subst /,\\,$(VS2008_DEVENV_DIR))\devenv" _projects/vs2008/cmft.sln /Build "Debug|x64" 63 | vs2008-release64: 64 | "$(subst /,\\,$(VS2008_DEVENV_DIR))\devenv" _projects/vs2008/cmft.sln /Build "Release|x64" 65 | vs2008: vs2008-debug32 vs2008-release32 vs2008-debug64 vs2008-release64 66 | 67 | _projects/vs2010: 68 | $(GENIE) --file=scripts/main.lua vs2010 69 | vs2010-debug32: 70 | "$(subst /,\\,$(VS2010_DEVENV_DIR))\devenv" _projects/vs2010/cmft.sln /Build "Debug|Win32" 71 | vs2010-release32: 72 | "$(subst /,\\,$(VS2010_DEVENV_DIR))\devenv" _projects/vs2010/cmft.sln /Build "Release|Win32" 73 | vs2010-debug64: 74 | "$(subst /,\\,$(VS2010_DEVENV_DIR))\devenv" _projects/vs2010/cmft.sln /Build "Debug|x64" 75 | vs2010-release64: 76 | "$(subst /,\\,$(VS2010_DEVENV_DIR))\devenv" _projects/vs2010/cmft.sln /Build "Release|x64" 77 | 78 | _projects/vs2012: 79 | $(GENIE) --file=scripts/main.lua vs2012 80 | vs2012-debug32: 81 | "$(subst /,\\,$(VS2012_DEVENV_DIR))\devenv" _projects/vs2012/cmft.sln /Build "Debug|Win32" 82 | vs2012-release32: 83 | "$(subst /,\\,$(VS2012_DEVENV_DIR))\devenv" _projects/vs2012/cmft.sln /Build "Release|Win32" 84 | vs2012-debug64: 85 | "$(subst /,\\,$(VS2012_DEVENV_DIR))\devenv" _projects/vs2012/cmft.sln /Build "Debug|x64" 86 | vs2012-release64: 87 | "$(subst /,\\,$(VS2012_DEVENV_DIR))\devenv" _projects/vs2012/cmft.sln /Build "Release|x64" 88 | 89 | _projects/vs2013: 90 | $(GENIE) --file=scripts/main.lua vs2013 91 | vs2013-debug32: 92 | "$(subst /,\\,$(VS2013_DEVENV_DIR))\devenv" _projects/vs2013/cmft.sln /Build "Debug|Win32" 93 | vs2013-release32: 94 | "$(subst /,\\,$(VS2013_DEVENV_DIR))\devenv" _projects/vs2013/cmft.sln /Build "Release|Win32" 95 | vs2013-debug64: 96 | "$(subst /,\\,$(VS2013_DEVENV_DIR))\devenv" _projects/vs2013/cmft.sln /Build "Debug|x64" 97 | vs2013-release64: 98 | "$(subst /,\\,$(VS2013_DEVENV_DIR))\devenv" _projects/vs2013/cmft.sln /Build "Release|x64" 99 | 100 | _projects/vs2015: 101 | $(GENIE) --file=scripts/main.lua vs2015 102 | vs2015-debug32: 103 | "$(subst /,\\,$(VS2015_DEVENV_DIR))\devenv" _projects/vs2015/cmft.sln /Build "Debug|Win32" 104 | vs2015-release32: 105 | "$(subst /,\\,$(VS2015_DEVENV_DIR))\devenv" _projects/vs2015/cmft.sln /Build "Release|Win32" 106 | vs2015-debug64: 107 | "$(subst /,\\,$(VS2015_DEVENV_DIR))\devenv" _projects/vs2015/cmft.sln /Build "Debug|x64" 108 | vs2015-release64: 109 | "$(subst /,\\,$(VS2015_DEVENV_DIR))\devenv" _projects/vs2015/cmft.sln /Build "Release|x64" 110 | 111 | _projects/gmake-linux: 112 | $(GENIE) --file=scripts/main.lua --gcc=linux-gcc gmake 113 | linux-debug32: _projects/gmake-linux 114 | make -R -C _projects/gmake-linux config=debug32 115 | linux-release32: _projects/gmake-linux 116 | make -R -C _projects/gmake-linux config=release32 117 | linux-debug64: _projects/gmake-linux 118 | make -R -C _projects/gmake-linux config=debug64 119 | linux-release64: _projects/gmake-linux 120 | make -R -C _projects/gmake-linux config=release64 121 | linux: linux-debug32 linux-release32 linux-debug64 linux-release64 122 | 123 | _projects/gmake-osx: 124 | $(GENIE) --file=scripts/main.lua --gcc=osx gmake 125 | osx-debug32: _projects/gmake-osx 126 | make -R -C _projects/gmake-osx config=debug32 127 | osx-release32: _projects/gmake-osx 128 | make -R -C _projects/gmake-osx config=release32 129 | osx-debug64: _projects/gmake-osx 130 | make -R -C _projects/gmake-osx config=debug64 131 | osx-release64: _projects/gmake-osx 132 | make -R -C _projects/gmake-osx config=release64 133 | osx: osx-debug32 osx-release32 osx-debug64 osx-release64 134 | 135 | #_projects/gmake-linux-clang: 136 | # $(GENIE) --file=scripts/main.lua --clang=linux-clang gmake 137 | #linux-clang-debug32: _projects/gmake-linux-clang 138 | # make -R -C _projects/gmake-linux-clang config=debug32 139 | #linux-clang-release32: _projects/gmake-linux-clang 140 | # make -R -C _projects/gmake-linux-clang config=release32 141 | #linux-clang-debug64: _projects/gmake-linux-clang 142 | # make -R -C _projects/gmake-linux-clang config=debug64 143 | #linux-clang-release64: _projects/gmake-linux-clang 144 | # make -R -C _projects/gmake-linux-clang config=release64 145 | #linux-clang: linux-debug32 linux-release32 linux-debug64 linux-release64 146 | 147 | #_projects/gmake-win-clang: 148 | # $(GENIE) --file=scripts/main.lua --clang=win-clang gmake 149 | #win-clang-debug32: _projects/gmake-win-clang 150 | # make -R -C _projects/gmake-win-clang config=debug32 151 | #win-clang-release32: _projects/gmake-win-clang 152 | # make -R -C _projects/gmake-win-clang config=release32 153 | #win-clang-debug64: _projects/gmake-win-clang 154 | # make -R -C _projects/gmake-win-clang config=debug64 155 | #win-clang-release64: _projects/gmake-win-clang 156 | # make -R -C _projects/gmake-win-clang config=release64 157 | #win-clang: win-debug32 win-release32 win-debug64 win-release64 158 | 159 | _projects/gmake-mingw-gcc: 160 | $(GENIE) --file=scripts/main.lua --gcc=mingw-gcc gmake 161 | mingw-gcc-debug32: _projects/gmake-mingw-gcc 162 | make -R -C _projects/gmake-mingw-gcc config=debug32 163 | mingw-gcc-release32: _projects/gmake-mingw-gcc 164 | make -R -C _projects/gmake-mingw-gcc config=release32 165 | mingw-gcc-debug64: _projects/gmake-mingw-gcc 166 | make -R -C _projects/gmake-mingw-gcc config=debug64 167 | mingw-gcc-release64: _projects/gmake-mingw-gcc 168 | make -R -C _projects/gmake-mingw-gcc config=release64 169 | mingw: mingw-gcc-debug32 mingw-gcc-release32 mingw-gcc-debug64 mingw-gcc-release64 170 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [cmft](https://github.com/dariomanesku/cmft) - cubemap filtering tool 2 | ===================================================================== 3 | 4 | Cross-platform open-source command-line cubemap filtering tool. 5 | 6 | It reaches very fast processing speeds by utilizing both multi-core CPU and OpenCL GPU at the same time! (check [perfomance charts](https://github.com/dariomanesku/cmft#performance)) 7 | 8 | Download 9 | -------- 10 | 11 | cmft - Windows 64bit
12 | [cmft - Linux 64bit](https://github.com/dariomanesku/cmft-bin/raw/master/cmft_lin64.zip) (updated: 16. Mar 2015)
13 | [cmft - OSX 64bit](https://github.com/dariomanesku/cmft-bin/raw/master/cmft_osx64.zip) (updated: 16. Mar 2015)
14 | *In case you need 32bit binaries, compile from source.*
15 | 16 | 17 | ![cmft-cover](https://github.com/dariomanesku/cmft/raw/master/res/cmft_cover.jpg) 18 | 19 | - Supported input/output formats: \*.dds, \*.ktx, \*.hdr, \*.tga. 20 | - Supported input/output types: cubemap, cube cross, latlong, face list, horizontal/vertical strip, octant. 21 | 22 | 23 | See it in action - [here](https://github.com/dariomanesku/cmftStudio) 24 | ------------ 25 | Screenshot from [cmftStudio](https://github.com/dariomanesku/cmftStudio): 26 | ![cmftStudioScreenshot](https://raw.githubusercontent.com/dariomanesku/cmftStudio/master/screenshots/cmftStudio_osx0.jpg) 27 | 28 | 29 | Remark ! 30 | -------- 31 | 32 | - If you are running OpenCL procesing on the same GPU that it connected to your monitor you may experience the following problem: when you are processing big cubemaps (~1024 face size) with small 'glossScale' parameter (<7 for example), OpenCL kernels may take a long time to execute and that may cause the operative system to step in and kill the display/gpu driver in the middle of processing! In case this happens, the processing will continue on CPU. You will get the expected results but the processing will run slower. To avoid this you can: 33 | - Use smaller input size. (this is crucial!) 34 | - Choose a bigger 'glossScale' parameter. 35 | - Use a workaround on Windows: increase the TdrDelay or modify the TdrLevel in the registry and restart the machine. More details here: http://msdn.microsoft.com/en-us/library/windows/hardware/ff569918%28v=vs.85%29.aspx 36 | - Run cmft on a faster GPU. 37 | - Run cmft on a GPU that is not connected to the monitor. 38 | 39 | 40 | Building 41 | -------- 42 | 43 | git clone git://github.com/dariomanesku/cmft.git 44 | cd cmft 45 | make 46 | 47 | - After calling `make`, *\_projects* folder will be created with all supported project files. Deleting *\_projects* folder is safe at any time. 48 | - All compiler generated files will be in *\_build* folder. Again, deleting *\_build* folder is safe at any time. 49 | 50 | ### Windows 51 | 52 | - Visual Studio 53 | - Visual Studio solution will be located in *\_projects/vs20XX/*. 54 | - MinGW 55 | - MinGW Makefile will be located in *\_projects/gmake-mingw-gcc/*. 56 | - Project can be build from the root directory by running `make mingw-gcc-release64` (or similar). 57 | - Remember to edit CMFT variable in *runtime/cmft_win.bat* accordingly to match the build configuration you are using. 58 | 59 | ### Linux 60 | 61 | - Makefile will be loacted in *\_projects/gmake-linux/*. 62 | - Project can be build from the root directory by running `make linux-release64` (or similar). 63 | - Vim users can source *.ide.vim* and make use of Build() and Execute() functions from inside Vim. 64 | - Remember to edit CMFT variable in *runtime/cmft_lin.sh* accordingly to match the build configuration you are using. 65 | 66 | ### OS X 67 | 68 | - XCode 69 | - XCode solution will be located in *\_projects/xcode4/*. 70 | - XCode project contains one scheme with 4 build configurations (debug/release 32/64bit). Select desired build configuration manually and/or setup schemes manually as desired. In case you need 64bit build, it is possible to just set *Build Settings -> Architectures -> Standard Architectures (64-bit Intel) (x86_64).* 71 | - Also it is probably necessary to manually set runtime directory (it is not picking it from genie for some reason). This is done by going to "*Product -> Scheme -> Edit Scheme... -> Run cmftDebug -> Options -> Working Directory (Use custom working directory)*" and specifying *runtime/* directory from cmft root folder. 72 | - Makefile 73 | - Makefile can be found in *\_projects/gmake-osx/*. 74 | - Project can be build from the root directory by running `make osx-release64` (or similar). 75 | - Vim users can source *.ide.vim* and make use of Build() and Execute() functions from inside Vim. 76 | - Remember to edit CMFT variable in *runtime/cmft_osx.sh* accordingly to match the build configuration you are using. 77 | 78 | ### Other 79 | - Also other compilation options may be available, have a look inside *\_projects* directory. 80 | - Additional build configurations will be available in the future. If one is there and not described here in this document, it is probably not yet set up properly and may not work out-of-the-box as expected without some care. 81 | 82 | ### Known issues 83 | - Linux GCC build noticeably slower comparing to Windows build (haven't yet figured out why). 84 | - PVRTexTool is not properly opening mipmapped \*.ktx files from cmft. This appears to be the problem with the current version of PVRTexTool. Has to be further investigated. 85 | 86 | 87 | Performance 88 | ----------- 89 | 90 | cmft was compared with the popular CubeMapGen tool for processing performance. 91 | Test machine: Intel i5-3570 @ 3.8ghz, Nvidia GTX 560 Ti 448. 92 | 93 | Filter settings: 94 | - Gloss scale: 8 95 | - Gloss bias: 1 96 | - Mip count: 8 97 | - Exclude base: false 98 | 99 | Test case #1: 100 | - Src face size: 256 101 | - Dst face size: 256 102 | - Lighting model: phongbrdf 103 | 104 | Test case #2: 105 | - Src face size: 256 106 | - Dst face size: 256 107 | - Lighting model: blinnbrdf 108 | 109 | Test case #3: 110 | - Src face size: 512 111 | - Dst face size: 256 112 | - Lighting model: phongbrdf 113 | 114 | Test case #4: 115 | - Src face size: 512 116 | - Dst face size: 256 117 | - Lighting model: blinnbrdf 118 | 119 | 120 | 121 | |Test case| CubeMapGen | cmft Cpu only | cmft Gpu only | cmft | 122 | |:--------|:-------------|:--------------|:--------------|:------| 123 | |#1 |01:27.7 |00:08.6 |00:18.7 |00:06.0| 124 | |#2 |04:39.5 |00:29.7 |00:19.6 |00:11.2| 125 | |#3 |05:38.1 |00:33.4 |01:03.7 |00:21.6| 126 | |#4 |18:34.1 |01:58.2 |01:07.7 |00:35.5| 127 | 128 | ![cmft-performance-chart](https://github.com/dariomanesku/cmft/raw/master/res/cmft_performance_chart.png) 129 | 130 | *Notice: performance tests are outdated. cmft is now running noticeably faster than displayed!* 131 | 132 | 133 | Environment maps 134 | ------------ 135 | 136 | - [NoEmotion HDRs](http://noemotionhdrs.net/). 137 | - [sIBL Archive - Hdrlabs.com](http://www.hdrlabs.com/sibl/archive.html). 138 | 139 | 140 | Recommended tools 141 | ------------ 142 | 143 | - [PVRTexTool](http://community.imgtec.com/developers/powervr/) - for opening \*.dds and \*.ktx files. 144 | - [GIMP](http://www.gimp.org) - for opening \*.tga files. 145 | - [Luminance HDR](http://qtpfsgui.sourceforge.net/) - for opening \*.hdr files. 146 | 147 | 148 | Similar projects 149 | ------------ 150 | 151 | - [CubeMapGen](http://developer.amd.com/tools-and-sdks/archive/legacy-cpu-gpu-tools/cubemapgen/) - A well known tool for cubemap filtering from AMD. 152 | - [Marmoset Skyshop](http://www.marmoset.co/skyshop) - Commercial plugin for Unity3D Game engine. 153 | - [Knald Lys](https://www.knaldtech.com/lys-open-beta/) - Commercial tool from KnaldTech. 154 | 155 | 156 | Useful links 157 | ------------ 158 | 159 | - [Sebastien Lagarde Blog - AMD Cubemapgen for physically based rendering](http://seblagarde.wordpress.com/2012/06/10/amd-cubemapgen-for-physically-based-rendering/) by [Sébastien Lagarde](https://twitter.com/SebLagarde) 160 | - [The Witness Blog - Seamless Cube Map Filtering](http://the-witness.net/news/2012/02/seamless-cube-map-filtering/) by [Ignacio Castaño](https://twitter.com/castano) 161 | 162 | 163 | Contribution 164 | ----------- 165 | 166 | In case you are using cmft for your game/project, please let me know. Tell me your use case, what is working well and what is not. I will be happy to help you using cmft and also to fix possible bugs and extend cmft to match your use case. 167 | 168 | Other than that, everyone is welcome to contribute to cmft by submitting bug reports, feature requests, testing on different platforms, profiling, etc. 169 | 170 | When contributing to the cmft project you must agree to the BSD 2-clause licensing terms. 171 | 172 | Contributors 173 | ------------ 174 | 175 | * Mmxix productions ([@mmxix](https://github.com/mmxix/)) - Vstrip image format. 176 | * [Pierre Lepers](https://twitter.com/_pil_) ([@plepers](https://github.com/plepers)) - Octant image format. 177 | 178 | 179 | Thanks to 180 | ------------ 181 | 182 | * [Marko Radak](http://markoradak.com/) - Initial cover photo design and realization. 183 | * [Dorian Cioban](https://www.linkedin.com/in/doriancioban) - Additional cover photo improvements. 184 | 185 | 186 | Contact 187 | ------------ 188 | 189 | Reach me via Twitter: [@dariomanesku](https://twitter.com/dariomanesku). 190 | 191 | 192 | [License (BSD 2-clause)](https://github.com/dariomanesku/cmft/blob/master/LICENSE) 193 | ------------------------------------------------------------------------------- 194 | 195 | Copyright 2014-2015 Dario Manesku. All rights reserved. 196 | 197 | https://github.com/dariomanesku/cmft 198 | 199 | Redistribution and use in source and binary forms, with or without 200 | modification, are permitted provided that the following conditions are met: 201 | 202 | 1. Redistributions of source code must retain the above copyright notice, 203 | this list of conditions and the following disclaimer. 204 | 205 | 2. Redistributions in binary form must reproduce the above copyright notice, 206 | this list of conditions and the following disclaimer in the documentation 207 | and/or other materials provided with the distribution. 208 | 209 | THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR 210 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 211 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 212 | EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 213 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 214 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 215 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 216 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 217 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 218 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 219 | -------------------------------------------------------------------------------- /dependency/CL/cl_d3d10.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * Copyright (c) 2008-2012 The Khronos Group Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and/or associated documentation files (the 6 | * "Materials"), to deal in the Materials without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Materials, and to 9 | * permit persons to whom the Materials are furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Materials. 14 | * 15 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 22 | **********************************************************************************/ 23 | 24 | /* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ 25 | 26 | #ifndef __OPENCL_CL_D3D10_H 27 | #define __OPENCL_CL_D3D10_H 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /****************************************************************************** 38 | * cl_khr_d3d10_sharing */ 39 | #define cl_khr_d3d10_sharing 1 40 | 41 | typedef cl_uint cl_d3d10_device_source_khr; 42 | typedef cl_uint cl_d3d10_device_set_khr; 43 | 44 | /******************************************************************************/ 45 | 46 | // Error Codes 47 | #define CL_INVALID_D3D10_DEVICE_KHR -1002 48 | #define CL_INVALID_D3D10_RESOURCE_KHR -1003 49 | #define CL_D3D10_RESOURCE_ALREADY_ACQUIRED_KHR -1004 50 | #define CL_D3D10_RESOURCE_NOT_ACQUIRED_KHR -1005 51 | 52 | // cl_d3d10_device_source_nv 53 | #define CL_D3D10_DEVICE_KHR 0x4010 54 | #define CL_D3D10_DXGI_ADAPTER_KHR 0x4011 55 | 56 | // cl_d3d10_device_set_nv 57 | #define CL_PREFERRED_DEVICES_FOR_D3D10_KHR 0x4012 58 | #define CL_ALL_DEVICES_FOR_D3D10_KHR 0x4013 59 | 60 | // cl_context_info 61 | #define CL_CONTEXT_D3D10_DEVICE_KHR 0x4014 62 | #define CL_CONTEXT_D3D10_PREFER_SHARED_RESOURCES_KHR 0x402C 63 | 64 | // cl_mem_info 65 | #define CL_MEM_D3D10_RESOURCE_KHR 0x4015 66 | 67 | // cl_image_info 68 | #define CL_IMAGE_D3D10_SUBRESOURCE_KHR 0x4016 69 | 70 | // cl_command_type 71 | #define CL_COMMAND_ACQUIRE_D3D10_OBJECTS_KHR 0x4017 72 | #define CL_COMMAND_RELEASE_D3D10_OBJECTS_KHR 0x4018 73 | 74 | /******************************************************************************/ 75 | 76 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D10KHR_fn)( 77 | cl_platform_id platform, 78 | cl_d3d10_device_source_khr d3d_device_source, 79 | void * d3d_object, 80 | cl_d3d10_device_set_khr d3d_device_set, 81 | cl_uint num_entries, 82 | cl_device_id * devices, 83 | cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_0; 84 | 85 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10BufferKHR_fn)( 86 | cl_context context, 87 | cl_mem_flags flags, 88 | ID3D10Buffer * resource, 89 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 90 | 91 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture2DKHR_fn)( 92 | cl_context context, 93 | cl_mem_flags flags, 94 | ID3D10Texture2D * resource, 95 | UINT subresource, 96 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 97 | 98 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture3DKHR_fn)( 99 | cl_context context, 100 | cl_mem_flags flags, 101 | ID3D10Texture3D * resource, 102 | UINT subresource, 103 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 104 | 105 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D10ObjectsKHR_fn)( 106 | cl_command_queue command_queue, 107 | cl_uint num_objects, 108 | const cl_mem * mem_objects, 109 | cl_uint num_events_in_wait_list, 110 | const cl_event * event_wait_list, 111 | cl_event * event) CL_API_SUFFIX__VERSION_1_0; 112 | 113 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D10ObjectsKHR_fn)( 114 | cl_command_queue command_queue, 115 | cl_uint num_objects, 116 | const cl_mem * mem_objects, 117 | cl_uint num_events_in_wait_list, 118 | const cl_event * event_wait_list, 119 | cl_event * event) CL_API_SUFFIX__VERSION_1_0; 120 | 121 | #ifdef __cplusplus 122 | } 123 | #endif 124 | 125 | #endif // __OPENCL_CL_D3D10_H 126 | 127 | -------------------------------------------------------------------------------- /dependency/CL/cl_d3d11.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * Copyright (c) 2008-2012 The Khronos Group Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and/or associated documentation files (the 6 | * "Materials"), to deal in the Materials without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Materials, and to 9 | * permit persons to whom the Materials are furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Materials. 14 | * 15 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 22 | **********************************************************************************/ 23 | 24 | /* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ 25 | 26 | #ifndef __OPENCL_CL_D3D11_H 27 | #define __OPENCL_CL_D3D11_H 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /****************************************************************************** 38 | * cl_khr_d3d11_sharing */ 39 | #define cl_khr_d3d11_sharing 1 40 | 41 | typedef cl_uint cl_d3d11_device_source_khr; 42 | typedef cl_uint cl_d3d11_device_set_khr; 43 | 44 | /******************************************************************************/ 45 | 46 | // Error Codes 47 | #define CL_INVALID_D3D11_DEVICE_KHR -1006 48 | #define CL_INVALID_D3D11_RESOURCE_KHR -1007 49 | #define CL_D3D11_RESOURCE_ALREADY_ACQUIRED_KHR -1008 50 | #define CL_D3D11_RESOURCE_NOT_ACQUIRED_KHR -1009 51 | 52 | // cl_d3d11_device_source 53 | #define CL_D3D11_DEVICE_KHR 0x4019 54 | #define CL_D3D11_DXGI_ADAPTER_KHR 0x401A 55 | 56 | // cl_d3d11_device_set 57 | #define CL_PREFERRED_DEVICES_FOR_D3D11_KHR 0x401B 58 | #define CL_ALL_DEVICES_FOR_D3D11_KHR 0x401C 59 | 60 | // cl_context_info 61 | #define CL_CONTEXT_D3D11_DEVICE_KHR 0x401D 62 | #define CL_CONTEXT_D3D11_PREFER_SHARED_RESOURCES_KHR 0x402D 63 | 64 | // cl_mem_info 65 | #define CL_MEM_D3D11_RESOURCE_KHR 0x401E 66 | 67 | // cl_image_info 68 | #define CL_IMAGE_D3D11_SUBRESOURCE_KHR 0x401F 69 | 70 | // cl_command_type 71 | #define CL_COMMAND_ACQUIRE_D3D11_OBJECTS_KHR 0x4020 72 | #define CL_COMMAND_RELEASE_D3D11_OBJECTS_KHR 0x4021 73 | 74 | /******************************************************************************/ 75 | 76 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D11KHR_fn)( 77 | cl_platform_id platform, 78 | cl_d3d11_device_source_khr d3d_device_source, 79 | void * d3d_object, 80 | cl_d3d11_device_set_khr d3d_device_set, 81 | cl_uint num_entries, 82 | cl_device_id * devices, 83 | cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_2; 84 | 85 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11BufferKHR_fn)( 86 | cl_context context, 87 | cl_mem_flags flags, 88 | ID3D11Buffer * resource, 89 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; 90 | 91 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture2DKHR_fn)( 92 | cl_context context, 93 | cl_mem_flags flags, 94 | ID3D11Texture2D * resource, 95 | UINT subresource, 96 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; 97 | 98 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture3DKHR_fn)( 99 | cl_context context, 100 | cl_mem_flags flags, 101 | ID3D11Texture3D * resource, 102 | UINT subresource, 103 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; 104 | 105 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D11ObjectsKHR_fn)( 106 | cl_command_queue command_queue, 107 | cl_uint num_objects, 108 | const cl_mem * mem_objects, 109 | cl_uint num_events_in_wait_list, 110 | const cl_event * event_wait_list, 111 | cl_event * event) CL_API_SUFFIX__VERSION_1_2; 112 | 113 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D11ObjectsKHR_fn)( 114 | cl_command_queue command_queue, 115 | cl_uint num_objects, 116 | const cl_mem * mem_objects, 117 | cl_uint num_events_in_wait_list, 118 | const cl_event * event_wait_list, 119 | cl_event * event) CL_API_SUFFIX__VERSION_1_2; 120 | 121 | #ifdef __cplusplus 122 | } 123 | #endif 124 | 125 | #endif // __OPENCL_CL_D3D11_H 126 | 127 | -------------------------------------------------------------------------------- /dependency/CL/cl_dx9_media_sharing.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * Copyright (c) 2008-2012 The Khronos Group Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and/or associated documentation files (the 6 | * "Materials"), to deal in the Materials without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Materials, and to 9 | * permit persons to whom the Materials are furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Materials. 14 | * 15 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 22 | **********************************************************************************/ 23 | 24 | /* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ 25 | 26 | #ifndef __OPENCL_CL_DX9_MEDIA_SHARING_H 27 | #define __OPENCL_CL_DX9_MEDIA_SHARING_H 28 | 29 | #include 30 | #include 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /****************************************************************************** 37 | /* cl_khr_dx9_media_sharing */ 38 | #define cl_khr_dx9_media_sharing 1 39 | 40 | typedef cl_uint cl_dx9_media_adapter_type_khr; 41 | typedef cl_uint cl_dx9_media_adapter_set_khr; 42 | 43 | #if defined(_WIN32) 44 | #include 45 | typedef struct _cl_dx9_surface_info_khr 46 | { 47 | IDirect3DSurface9 *resource; 48 | HANDLE shared_handle; 49 | } cl_dx9_surface_info_khr; 50 | #endif 51 | 52 | 53 | /******************************************************************************/ 54 | 55 | // Error Codes 56 | #define CL_INVALID_DX9_MEDIA_ADAPTER_KHR -1010 57 | #define CL_INVALID_DX9_MEDIA_SURFACE_KHR -1011 58 | #define CL_DX9_MEDIA_SURFACE_ALREADY_ACQUIRED_KHR -1012 59 | #define CL_DX9_MEDIA_SURFACE_NOT_ACQUIRED_KHR -1013 60 | 61 | // cl_media_adapter_type_khr 62 | #define CL_ADAPTER_D3D9_KHR 0x2020 63 | #define CL_ADAPTER_D3D9EX_KHR 0x2021 64 | #define CL_ADAPTER_DXVA_KHR 0x2022 65 | 66 | // cl_media_adapter_set_khr 67 | #define CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR 0x2023 68 | #define CL_ALL_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR 0x2024 69 | 70 | // cl_context_info 71 | #define CL_CONTEXT_ADAPTER_D3D9_KHR 0x2025 72 | #define CL_CONTEXT_ADAPTER_D3D9EX_KHR 0x2026 73 | #define CL_CONTEXT_ADAPTER_DXVA_KHR 0x2027 74 | 75 | // cl_mem_info 76 | #define CL_MEM_DX9_MEDIA_ADAPTER_TYPE_KHR 0x2028 77 | #define CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR 0x2029 78 | 79 | // cl_image_info 80 | #define CL_IMAGE_DX9_MEDIA_PLANE_KHR 0x202A 81 | 82 | // cl_command_type 83 | #define CL_COMMAND_ACQUIRE_DX9_MEDIA_SURFACES_KHR 0x202B 84 | #define CL_COMMAND_RELEASE_DX9_MEDIA_SURFACES_KHR 0x202C 85 | 86 | /******************************************************************************/ 87 | 88 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromDX9MediaAdapterKHR_fn)( 89 | cl_platform_id platform, 90 | cl_uint num_media_adapters, 91 | cl_dx9_media_adapter_type_khr * media_adapter_type, 92 | void * media_adapters, 93 | cl_dx9_media_adapter_set_khr media_adapter_set, 94 | cl_uint num_entries, 95 | cl_device_id * devices, 96 | cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_2; 97 | 98 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromDX9MediaSurfaceKHR_fn)( 99 | cl_context context, 100 | cl_mem_flags flags, 101 | cl_dx9_media_adapter_type_khr adapter_type, 102 | void * surface_info, 103 | cl_uint plane, 104 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; 105 | 106 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireDX9MediaSurfacesKHR_fn)( 107 | cl_command_queue command_queue, 108 | cl_uint num_objects, 109 | const cl_mem * mem_objects, 110 | cl_uint num_events_in_wait_list, 111 | const cl_event * event_wait_list, 112 | cl_event * event) CL_API_SUFFIX__VERSION_1_2; 113 | 114 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseDX9MediaSurfacesKHR_fn)( 115 | cl_command_queue command_queue, 116 | cl_uint num_objects, 117 | const cl_mem * mem_objects, 118 | cl_uint num_events_in_wait_list, 119 | const cl_event * event_wait_list, 120 | cl_event * event) CL_API_SUFFIX__VERSION_1_2; 121 | 122 | #ifdef __cplusplus 123 | } 124 | #endif 125 | 126 | #endif // __OPENCL_CL_DX9_MEDIA_SHARING_H 127 | 128 | -------------------------------------------------------------------------------- /dependency/CL/cl_egl.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2008-2010 The Khronos Group Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and/or associated documentation files (the 6 | * "Materials"), to deal in the Materials without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Materials, and to 9 | * permit persons to whom the Materials are furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Materials. 14 | * 15 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 22 | ******************************************************************************/ 23 | 24 | #ifndef __OPENCL_CL_EGL_H 25 | #define __OPENCL_CL_EGL_H 26 | 27 | #ifdef __APPLE__ 28 | 29 | #else 30 | #include 31 | #include 32 | #include 33 | #endif 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | 40 | /* Command type for events created with clEnqueueAcquireEGLObjectsKHR */ 41 | #define CL_COMMAND_EGL_FENCE_SYNC_OBJECT_KHR 0x202F 42 | #define CL_COMMAND_ACQUIRE_EGL_OBJECTS_KHR 0x202D 43 | #define CL_COMMAND_RELEASE_EGL_OBJECTS_KHR 0x202E 44 | 45 | /* Error type for clCreateFromEGLImageKHR */ 46 | #define CL_INVALID_EGL_OBJECT_KHR -1093 47 | #define CL_EGL_RESOURCE_NOT_ACQUIRED_KHR -1092 48 | 49 | /* CLeglImageKHR is an opaque handle to an EGLImage */ 50 | typedef void* CLeglImageKHR; 51 | 52 | /* CLeglDisplayKHR is an opaque handle to an EGLDisplay */ 53 | typedef void* CLeglDisplayKHR; 54 | 55 | /* properties passed to clCreateFromEGLImageKHR */ 56 | typedef intptr_t cl_egl_image_properties_khr; 57 | 58 | 59 | #define cl_khr_egl_image 1 60 | 61 | extern CL_API_ENTRY cl_mem CL_API_CALL 62 | clCreateFromEGLImageKHR(cl_context /* context */, 63 | CLeglDisplayKHR /* egldisplay */, 64 | CLeglImageKHR /* eglimage */, 65 | cl_mem_flags /* flags */, 66 | const cl_egl_image_properties_khr * /* properties */, 67 | cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; 68 | 69 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromEGLImageKHR_fn)( 70 | cl_context context, 71 | CLeglDisplayKHR egldisplay, 72 | CLeglImageKHR eglimage, 73 | cl_mem_flags flags, 74 | const cl_egl_image_properties_khr * properties, 75 | cl_int * errcode_ret); 76 | 77 | 78 | extern CL_API_ENTRY cl_int CL_API_CALL 79 | clEnqueueAcquireEGLObjectsKHR(cl_command_queue /* command_queue */, 80 | cl_uint /* num_objects */, 81 | const cl_mem * /* mem_objects */, 82 | cl_uint /* num_events_in_wait_list */, 83 | const cl_event * /* event_wait_list */, 84 | cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; 85 | 86 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireEGLObjectsKHR_fn)( 87 | cl_command_queue command_queue, 88 | cl_uint num_objects, 89 | const cl_mem * mem_objects, 90 | cl_uint num_events_in_wait_list, 91 | const cl_event * event_wait_list, 92 | cl_event * event); 93 | 94 | 95 | extern CL_API_ENTRY cl_int CL_API_CALL 96 | clEnqueueReleaseEGLObjectsKHR(cl_command_queue /* command_queue */, 97 | cl_uint /* num_objects */, 98 | const cl_mem * /* mem_objects */, 99 | cl_uint /* num_events_in_wait_list */, 100 | const cl_event * /* event_wait_list */, 101 | cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; 102 | 103 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseEGLObjectsKHR_fn)( 104 | cl_command_queue command_queue, 105 | cl_uint num_objects, 106 | const cl_mem * mem_objects, 107 | cl_uint num_events_in_wait_list, 108 | const cl_event * event_wait_list, 109 | cl_event * event); 110 | 111 | 112 | #define cl_khr_egl_event 1 113 | 114 | extern CL_API_ENTRY cl_event CL_API_CALL 115 | clCreateEventFromEGLSyncKHR(cl_context /* context */, 116 | EGLSyncKHR /* sync */, 117 | EGLDisplay /* display */, 118 | cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; 119 | 120 | typedef CL_API_ENTRY cl_event (CL_API_CALL *clCreateEventFromEGLSyncKHR_fn)( 121 | cl_context context, 122 | EGLSyncKHR sync, 123 | EGLDisplay display, 124 | cl_int * errcode_ret); 125 | 126 | 127 | #ifdef __cplusplus 128 | } 129 | #endif 130 | 131 | #endif /* __OPENCL_CL_EGL_H */ 132 | -------------------------------------------------------------------------------- /dependency/CL/cl_ext.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2008-2013 The Khronos Group Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and/or associated documentation files (the 6 | * "Materials"), to deal in the Materials without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Materials, and to 9 | * permit persons to whom the Materials are furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Materials. 14 | * 15 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 22 | ******************************************************************************/ 23 | 24 | /* $Revision: 11928 $ on $Date: 2010-07-13 09:04:56 -0700 (Tue, 13 Jul 2010) $ */ 25 | 26 | /* cl_ext.h contains OpenCL extensions which don't have external */ 27 | /* (OpenGL, D3D) dependencies. */ 28 | 29 | #ifndef __CL_EXT_H 30 | #define __CL_EXT_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #ifdef __APPLE__ 37 | #include 38 | #include 39 | #else 40 | #include 41 | #endif 42 | 43 | /* cl_khr_fp16 extension - no extension #define since it has no functions */ 44 | #define CL_DEVICE_HALF_FP_CONFIG 0x1033 45 | 46 | /* Memory object destruction 47 | * 48 | * Apple extension for use to manage externally allocated buffers used with cl_mem objects with CL_MEM_USE_HOST_PTR 49 | * 50 | * Registers a user callback function that will be called when the memory object is deleted and its resources 51 | * freed. Each call to clSetMemObjectCallbackFn registers the specified user callback function on a callback 52 | * stack associated with memobj. The registered user callback functions are called in the reverse order in 53 | * which they were registered. The user callback functions are called and then the memory object is deleted 54 | * and its resources freed. This provides a mechanism for the application (and libraries) using memobj to be 55 | * notified when the memory referenced by host_ptr, specified when the memory object is created and used as 56 | * the storage bits for the memory object, can be reused or freed. 57 | * 58 | * The application may not call CL api's with the cl_mem object passed to the pfn_notify. 59 | * 60 | * Please check for the "cl_APPLE_SetMemObjectDestructor" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS) 61 | * before using. 62 | */ 63 | #define cl_APPLE_SetMemObjectDestructor 1 64 | cl_int CL_API_ENTRY clSetMemObjectDestructorAPPLE( cl_mem /* memobj */, 65 | void (* /*pfn_notify*/)( cl_mem /* memobj */, void* /*user_data*/), 66 | void * /*user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; 67 | 68 | 69 | /* Context Logging Functions 70 | * 71 | * The next three convenience functions are intended to be used as the pfn_notify parameter to clCreateContext(). 72 | * Please check for the "cl_APPLE_ContextLoggingFunctions" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS) 73 | * before using. 74 | * 75 | * clLogMessagesToSystemLog fowards on all log messages to the Apple System Logger 76 | */ 77 | #define cl_APPLE_ContextLoggingFunctions 1 78 | extern void CL_API_ENTRY clLogMessagesToSystemLogAPPLE( const char * /* errstr */, 79 | const void * /* private_info */, 80 | size_t /* cb */, 81 | void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; 82 | 83 | /* clLogMessagesToStdout sends all log messages to the file descriptor stdout */ 84 | extern void CL_API_ENTRY clLogMessagesToStdoutAPPLE( const char * /* errstr */, 85 | const void * /* private_info */, 86 | size_t /* cb */, 87 | void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; 88 | 89 | /* clLogMessagesToStderr sends all log messages to the file descriptor stderr */ 90 | extern void CL_API_ENTRY clLogMessagesToStderrAPPLE( const char * /* errstr */, 91 | const void * /* private_info */, 92 | size_t /* cb */, 93 | void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; 94 | 95 | 96 | /************************ 97 | * cl_khr_icd extension * 98 | ************************/ 99 | #define cl_khr_icd 1 100 | 101 | /* cl_platform_info */ 102 | #define CL_PLATFORM_ICD_SUFFIX_KHR 0x0920 103 | 104 | /* Additional Error Codes */ 105 | #define CL_PLATFORM_NOT_FOUND_KHR -1001 106 | 107 | extern CL_API_ENTRY cl_int CL_API_CALL 108 | clIcdGetPlatformIDsKHR(cl_uint /* num_entries */, 109 | cl_platform_id * /* platforms */, 110 | cl_uint * /* num_platforms */); 111 | 112 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clIcdGetPlatformIDsKHR_fn)( 113 | cl_uint /* num_entries */, 114 | cl_platform_id * /* platforms */, 115 | cl_uint * /* num_platforms */); 116 | 117 | 118 | /* Extension: cl_khr_image2D_buffer 119 | * 120 | * This extension allows a 2D image to be created from a cl_mem buffer without a copy. 121 | * The type associated with a 2D image created from a buffer in an OpenCL program is image2d_t. 122 | * Both the sampler and sampler-less read_image built-in functions are supported for 2D images 123 | * and 2D images created from a buffer. Similarly, the write_image built-ins are also supported 124 | * for 2D images created from a buffer. 125 | * 126 | * When the 2D image from buffer is created, the client must specify the width, 127 | * height, image format (i.e. channel order and channel data type) and optionally the row pitch 128 | * 129 | * The pitch specified must be a multiple of CL_DEVICE_IMAGE_PITCH_ALIGNMENT pixels. 130 | * The base address of the buffer must be aligned to CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT pixels. 131 | */ 132 | 133 | /************************************* 134 | * cl_khr_initalize_memory extension * 135 | *************************************/ 136 | 137 | #define CL_CONTEXT_MEMORY_INITIALIZE_KHR 0x200E 138 | 139 | 140 | /************************************** 141 | * cl_khr_terminate_context extension * 142 | **************************************/ 143 | 144 | #define CL_DEVICE_TERMINATE_CAPABILITY_KHR 0x200F 145 | #define CL_CONTEXT_TERMINATE_KHR 0x2010 146 | 147 | #define cl_khr_terminate_context 1 148 | extern CL_API_ENTRY cl_int CL_API_CALL clTerminateContextKHR(cl_context /* context */) CL_EXT_SUFFIX__VERSION_1_2; 149 | 150 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clTerminateContextKHR_fn)(cl_context /* context */) CL_EXT_SUFFIX__VERSION_1_2; 151 | 152 | 153 | /* 154 | * Extension: cl_khr_spir 155 | * 156 | * This extension adds support to create an OpenCL program object from a 157 | * Standard Portable Intermediate Representation (SPIR) instance 158 | */ 159 | 160 | /****************************************** 161 | * cl_nv_device_attribute_query extension * 162 | ******************************************/ 163 | /* cl_nv_device_attribute_query extension - no extension #define since it has no functions */ 164 | #define CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV 0x4000 165 | #define CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV 0x4001 166 | #define CL_DEVICE_REGISTERS_PER_BLOCK_NV 0x4002 167 | #define CL_DEVICE_WARP_SIZE_NV 0x4003 168 | #define CL_DEVICE_GPU_OVERLAP_NV 0x4004 169 | #define CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV 0x4005 170 | #define CL_DEVICE_INTEGRATED_MEMORY_NV 0x4006 171 | 172 | /********************************* 173 | * cl_amd_device_attribute_query * 174 | *********************************/ 175 | #define CL_DEVICE_PROFILING_TIMER_OFFSET_AMD 0x4036 176 | 177 | #ifdef CL_VERSION_1_1 178 | /*********************************** 179 | * cl_ext_device_fission extension * 180 | ***********************************/ 181 | #define cl_ext_device_fission 1 182 | 183 | extern CL_API_ENTRY cl_int CL_API_CALL 184 | clReleaseDeviceEXT( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; 185 | 186 | typedef CL_API_ENTRY cl_int 187 | (CL_API_CALL *clReleaseDeviceEXT_fn)( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; 188 | 189 | extern CL_API_ENTRY cl_int CL_API_CALL 190 | clRetainDeviceEXT( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; 191 | 192 | typedef CL_API_ENTRY cl_int 193 | (CL_API_CALL *clRetainDeviceEXT_fn)( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; 194 | 195 | typedef cl_ulong cl_device_partition_property_ext; 196 | extern CL_API_ENTRY cl_int CL_API_CALL 197 | clCreateSubDevicesEXT( cl_device_id /*in_device*/, 198 | const cl_device_partition_property_ext * /* properties */, 199 | cl_uint /*num_entries*/, 200 | cl_device_id * /*out_devices*/, 201 | cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; 202 | 203 | typedef CL_API_ENTRY cl_int 204 | ( CL_API_CALL * clCreateSubDevicesEXT_fn)( cl_device_id /*in_device*/, 205 | const cl_device_partition_property_ext * /* properties */, 206 | cl_uint /*num_entries*/, 207 | cl_device_id * /*out_devices*/, 208 | cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; 209 | 210 | /* cl_device_partition_property_ext */ 211 | #define CL_DEVICE_PARTITION_EQUALLY_EXT 0x4050 212 | #define CL_DEVICE_PARTITION_BY_COUNTS_EXT 0x4051 213 | #define CL_DEVICE_PARTITION_BY_NAMES_EXT 0x4052 214 | #define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN_EXT 0x4053 215 | 216 | /* clDeviceGetInfo selectors */ 217 | #define CL_DEVICE_PARENT_DEVICE_EXT 0x4054 218 | #define CL_DEVICE_PARTITION_TYPES_EXT 0x4055 219 | #define CL_DEVICE_AFFINITY_DOMAINS_EXT 0x4056 220 | #define CL_DEVICE_REFERENCE_COUNT_EXT 0x4057 221 | #define CL_DEVICE_PARTITION_STYLE_EXT 0x4058 222 | 223 | /* error codes */ 224 | #define CL_DEVICE_PARTITION_FAILED_EXT -1057 225 | #define CL_INVALID_PARTITION_COUNT_EXT -1058 226 | #define CL_INVALID_PARTITION_NAME_EXT -1059 227 | 228 | /* CL_AFFINITY_DOMAINs */ 229 | #define CL_AFFINITY_DOMAIN_L1_CACHE_EXT 0x1 230 | #define CL_AFFINITY_DOMAIN_L2_CACHE_EXT 0x2 231 | #define CL_AFFINITY_DOMAIN_L3_CACHE_EXT 0x3 232 | #define CL_AFFINITY_DOMAIN_L4_CACHE_EXT 0x4 233 | #define CL_AFFINITY_DOMAIN_NUMA_EXT 0x10 234 | #define CL_AFFINITY_DOMAIN_NEXT_FISSIONABLE_EXT 0x100 235 | 236 | /* cl_device_partition_property_ext list terminators */ 237 | #define CL_PROPERTIES_LIST_END_EXT ((cl_device_partition_property_ext) 0) 238 | #define CL_PARTITION_BY_COUNTS_LIST_END_EXT ((cl_device_partition_property_ext) 0) 239 | #define CL_PARTITION_BY_NAMES_LIST_END_EXT ((cl_device_partition_property_ext) 0 - 1) 240 | 241 | /********************************* 242 | * cl_qcom_ext_host_ptr extension 243 | *********************************/ 244 | 245 | #define CL_MEM_EXT_HOST_PTR_QCOM (1 << 29) 246 | 247 | #define CL_DEVICE_EXT_MEM_PADDING_IN_BYTES_QCOM 0x40A0 248 | #define CL_DEVICE_PAGE_SIZE_QCOM 0x40A1 249 | #define CL_IMAGE_ROW_ALIGNMENT_QCOM 0x40A2 250 | #define CL_IMAGE_SLICE_ALIGNMENT_QCOM 0x40A3 251 | #define CL_MEM_HOST_UNCACHED_QCOM 0x40A4 252 | #define CL_MEM_HOST_WRITEBACK_QCOM 0x40A5 253 | #define CL_MEM_HOST_WRITETHROUGH_QCOM 0x40A6 254 | #define CL_MEM_HOST_WRITE_COMBINING_QCOM 0x40A7 255 | 256 | typedef cl_uint cl_image_pitch_info_qcom; 257 | 258 | extern CL_API_ENTRY cl_int CL_API_CALL 259 | clGetDeviceImageInfoQCOM(cl_device_id device, 260 | size_t image_width, 261 | size_t image_height, 262 | const cl_image_format *image_format, 263 | cl_image_pitch_info_qcom param_name, 264 | size_t param_value_size, 265 | void *param_value, 266 | size_t *param_value_size_ret); 267 | 268 | typedef struct _cl_mem_ext_host_ptr 269 | { 270 | // Type of external memory allocation. 271 | // Legal values will be defined in layered extensions. 272 | cl_uint allocation_type; 273 | 274 | // Host cache policy for this external memory allocation. 275 | cl_uint host_cache_policy; 276 | 277 | } cl_mem_ext_host_ptr; 278 | 279 | /********************************* 280 | * cl_qcom_ion_host_ptr extension 281 | *********************************/ 282 | 283 | #define CL_MEM_ION_HOST_PTR_QCOM 0x40A8 284 | 285 | typedef struct _cl_mem_ion_host_ptr 286 | { 287 | // Type of external memory allocation. 288 | // Must be CL_MEM_ION_HOST_PTR_QCOM for ION allocations. 289 | cl_mem_ext_host_ptr ext_host_ptr; 290 | 291 | // ION file descriptor 292 | int ion_filedesc; 293 | 294 | // Host pointer to the ION allocated memory 295 | void* ion_hostptr; 296 | 297 | } cl_mem_ion_host_ptr; 298 | 299 | #endif /* CL_VERSION_1_1 */ 300 | 301 | #ifdef __cplusplus 302 | } 303 | #endif 304 | 305 | 306 | #endif /* __CL_EXT_H */ 307 | -------------------------------------------------------------------------------- /dependency/CL/cl_gl.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * Copyright (c) 2008 - 2012 The Khronos Group Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and/or associated documentation files (the 6 | * "Materials"), to deal in the Materials without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Materials, and to 9 | * permit persons to whom the Materials are furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Materials. 14 | * 15 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 22 | **********************************************************************************/ 23 | 24 | #ifndef __OPENCL_CL_GL_H 25 | #define __OPENCL_CL_GL_H 26 | 27 | #ifdef __APPLE__ 28 | #include 29 | #else 30 | #include 31 | #endif 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | typedef cl_uint cl_gl_object_type; 38 | typedef cl_uint cl_gl_texture_info; 39 | typedef cl_uint cl_gl_platform_info; 40 | typedef struct __GLsync *cl_GLsync; 41 | 42 | /* cl_gl_object_type = 0x2000 - 0x200F enum values are currently taken */ 43 | #define CL_GL_OBJECT_BUFFER 0x2000 44 | #define CL_GL_OBJECT_TEXTURE2D 0x2001 45 | #define CL_GL_OBJECT_TEXTURE3D 0x2002 46 | #define CL_GL_OBJECT_RENDERBUFFER 0x2003 47 | #define CL_GL_OBJECT_TEXTURE2D_ARRAY 0x200E 48 | #define CL_GL_OBJECT_TEXTURE1D 0x200F 49 | #define CL_GL_OBJECT_TEXTURE1D_ARRAY 0x2010 50 | #define CL_GL_OBJECT_TEXTURE_BUFFER 0x2011 51 | 52 | /* cl_gl_texture_info */ 53 | #define CL_GL_TEXTURE_TARGET 0x2004 54 | #define CL_GL_MIPMAP_LEVEL 0x2005 55 | #define CL_GL_NUM_SAMPLES 0x2012 56 | 57 | 58 | extern CL_API_ENTRY cl_mem CL_API_CALL 59 | clCreateFromGLBuffer(cl_context /* context */, 60 | cl_mem_flags /* flags */, 61 | cl_GLuint /* bufobj */, 62 | int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; 63 | 64 | extern CL_API_ENTRY cl_mem CL_API_CALL 65 | clCreateFromGLTexture(cl_context /* context */, 66 | cl_mem_flags /* flags */, 67 | cl_GLenum /* target */, 68 | cl_GLint /* miplevel */, 69 | cl_GLuint /* texture */, 70 | cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; 71 | 72 | extern CL_API_ENTRY cl_mem CL_API_CALL 73 | clCreateFromGLRenderbuffer(cl_context /* context */, 74 | cl_mem_flags /* flags */, 75 | cl_GLuint /* renderbuffer */, 76 | cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; 77 | 78 | extern CL_API_ENTRY cl_int CL_API_CALL 79 | clGetGLObjectInfo(cl_mem /* memobj */, 80 | cl_gl_object_type * /* gl_object_type */, 81 | cl_GLuint * /* gl_object_name */) CL_API_SUFFIX__VERSION_1_0; 82 | 83 | extern CL_API_ENTRY cl_int CL_API_CALL 84 | clGetGLTextureInfo(cl_mem /* memobj */, 85 | cl_gl_texture_info /* param_name */, 86 | size_t /* param_value_size */, 87 | void * /* param_value */, 88 | size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; 89 | 90 | extern CL_API_ENTRY cl_int CL_API_CALL 91 | clEnqueueAcquireGLObjects(cl_command_queue /* command_queue */, 92 | cl_uint /* num_objects */, 93 | const cl_mem * /* mem_objects */, 94 | cl_uint /* num_events_in_wait_list */, 95 | const cl_event * /* event_wait_list */, 96 | cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; 97 | 98 | extern CL_API_ENTRY cl_int CL_API_CALL 99 | clEnqueueReleaseGLObjects(cl_command_queue /* command_queue */, 100 | cl_uint /* num_objects */, 101 | const cl_mem * /* mem_objects */, 102 | cl_uint /* num_events_in_wait_list */, 103 | const cl_event * /* event_wait_list */, 104 | cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; 105 | 106 | 107 | // Deprecated OpenCL 1.1 APIs 108 | extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL 109 | clCreateFromGLTexture2D(cl_context /* context */, 110 | cl_mem_flags /* flags */, 111 | cl_GLenum /* target */, 112 | cl_GLint /* miplevel */, 113 | cl_GLuint /* texture */, 114 | cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; 115 | 116 | extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL 117 | clCreateFromGLTexture3D(cl_context /* context */, 118 | cl_mem_flags /* flags */, 119 | cl_GLenum /* target */, 120 | cl_GLint /* miplevel */, 121 | cl_GLuint /* texture */, 122 | cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; 123 | 124 | /* cl_khr_gl_sharing extension */ 125 | 126 | #define cl_khr_gl_sharing 1 127 | 128 | typedef cl_uint cl_gl_context_info; 129 | 130 | /* Additional Error Codes */ 131 | #define CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR -1000 132 | 133 | /* cl_gl_context_info */ 134 | #define CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR 0x2006 135 | #define CL_DEVICES_FOR_GL_CONTEXT_KHR 0x2007 136 | 137 | /* Additional cl_context_properties */ 138 | #define CL_GL_CONTEXT_KHR 0x2008 139 | #define CL_EGL_DISPLAY_KHR 0x2009 140 | #define CL_GLX_DISPLAY_KHR 0x200A 141 | #define CL_WGL_HDC_KHR 0x200B 142 | #define CL_CGL_SHAREGROUP_KHR 0x200C 143 | 144 | extern CL_API_ENTRY cl_int CL_API_CALL 145 | clGetGLContextInfoKHR(const cl_context_properties * /* properties */, 146 | cl_gl_context_info /* param_name */, 147 | size_t /* param_value_size */, 148 | void * /* param_value */, 149 | size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; 150 | 151 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetGLContextInfoKHR_fn)( 152 | const cl_context_properties * properties, 153 | cl_gl_context_info param_name, 154 | size_t param_value_size, 155 | void * param_value, 156 | size_t * param_value_size_ret); 157 | 158 | #ifdef __cplusplus 159 | } 160 | #endif 161 | 162 | #endif /* __OPENCL_CL_GL_H */ 163 | -------------------------------------------------------------------------------- /dependency/CL/cl_gl_ext.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * Copyright (c) 2008-2012 The Khronos Group Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and/or associated documentation files (the 6 | * "Materials"), to deal in the Materials without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Materials, and to 9 | * permit persons to whom the Materials are furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Materials. 14 | * 15 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 22 | **********************************************************************************/ 23 | 24 | /* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ 25 | 26 | /* cl_gl_ext.h contains vendor (non-KHR) OpenCL extensions which have */ 27 | /* OpenGL dependencies. */ 28 | 29 | #ifndef __OPENCL_CL_GL_EXT_H 30 | #define __OPENCL_CL_GL_EXT_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #ifdef __APPLE__ 37 | #include 38 | #else 39 | #include 40 | #endif 41 | 42 | /* 43 | * For each extension, follow this template 44 | * cl_VEN_extname extension */ 45 | /* #define cl_VEN_extname 1 46 | * ... define new types, if any 47 | * ... define new tokens, if any 48 | * ... define new APIs, if any 49 | * 50 | * If you need GLtypes here, mirror them with a cl_GLtype, rather than including a GL header 51 | * This allows us to avoid having to decide whether to include GL headers or GLES here. 52 | */ 53 | 54 | /* 55 | * cl_khr_gl_event extension 56 | * See section 9.9 in the OpenCL 1.1 spec for more information 57 | */ 58 | #define CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR 0x200D 59 | 60 | extern CL_API_ENTRY cl_event CL_API_CALL 61 | clCreateEventFromGLsyncKHR(cl_context /* context */, 62 | cl_GLsync /* cl_GLsync */, 63 | cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1; 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif /* __OPENCL_CL_GL_EXT_H */ 70 | -------------------------------------------------------------------------------- /dependency/CL/opencl.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2008-2012 The Khronos Group Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and/or associated documentation files (the 6 | * "Materials"), to deal in the Materials without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Materials, and to 9 | * permit persons to whom the Materials are furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Materials. 14 | * 15 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 22 | ******************************************************************************/ 23 | 24 | /* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ 25 | 26 | #ifndef __OPENCL_H 27 | #define __OPENCL_H 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #ifdef __APPLE__ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #else 41 | 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | #endif 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif /* __OPENCL_H */ 54 | 55 | -------------------------------------------------------------------------------- /dependency/bx/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | indent_size = 4 6 | end_of_line = lf 7 | max_line_length = 100 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | max_line_length = 80 14 | -------------------------------------------------------------------------------- /dependency/bx/.gitattributes: -------------------------------------------------------------------------------- 1 | *.c eol=lf 2 | *.cpp eol=lf 3 | *.h eol=lf 4 | *.sc eol=lf 5 | *.sh eol=lf 6 | *.m eol=lf 7 | *.mm eol=lf 8 | *.md eol=lf 9 | *.lua eol=lf 10 | *.mk eol=lf 11 | makefile eol=lf 12 | -------------------------------------------------------------------------------- /dependency/bx/.gitignore: -------------------------------------------------------------------------------- 1 | .git 2 | .build 3 | .debug 4 | .svn 5 | tags 6 | .DS_Store 7 | -------------------------------------------------------------------------------- /dependency/bx/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2010-2015 Branimir Karadzic. All rights reserved. 2 | 3 | https://github.com/bkaradzic/bx 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/bkaradzic/bx/blob/master/LICENSE 27 | -------------------------------------------------------------------------------- /dependency/bx/README.md: -------------------------------------------------------------------------------- 1 | bx 2 | == 3 | 4 | Base library. 5 | 6 | Contact 7 | ------- 8 | 9 | [@bkaradzic](https://twitter.com/bkaradzic) 10 | 11 | Project page 12 | https://github.com/bkaradzic/bx 13 | 14 | [License (BSD 2-clause)](https://github.com/bkaradzic/bx/blob/master/LICENSE) 15 | ----------------------------------------------------------------------------- 16 | 17 | Copyright 2010-2015 Branimir Karadzic. All rights reserved. 18 | 19 | https://github.com/bkaradzic/bx 20 | 21 | Redistribution and use in source and binary forms, with or without 22 | modification, are permitted provided that the following conditions are met: 23 | 24 | 1. Redistributions of source code must retain the above copyright notice, 25 | this list of conditions and the following disclaimer. 26 | 27 | 2. Redistributions in binary form must reproduce the above copyright notice, 28 | this list of conditions and the following disclaimer in the documentation 29 | and/or other materials provided with the distribution. 30 | 31 | THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR 32 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 33 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 34 | EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 35 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 36 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 37 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 38 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 39 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 40 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 41 | -------------------------------------------------------------------------------- /dependency/bx/makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2011-2015 Branimir Karadzic. All rights reserved. 3 | # License: http://www.opensource.org/licenses/BSD-2-Clause 4 | # 5 | 6 | UNAME := $(shell uname) 7 | ifeq ($(UNAME),$(filter $(UNAME),Linux Darwin)) 8 | ifeq ($(UNAME),$(filter $(UNAME),Darwin)) 9 | OS=darwin 10 | else 11 | OS=linux 12 | endif 13 | else 14 | OS=windows 15 | endif 16 | 17 | GENIE=../bx/tools/bin/$(OS)/genie 18 | 19 | all: 20 | $(GENIE) vs2008 21 | $(GENIE) vs2010 22 | $(GENIE) vs2012 23 | $(GENIE) vs2013 24 | $(GENIE) --gcc=android-arm gmake 25 | $(GENIE) --gcc=android-mips gmake 26 | $(GENIE) --gcc=android-x86 gmake 27 | $(GENIE) --gcc=nacl gmake 28 | $(GENIE) --gcc=nacl-arm gmake 29 | $(GENIE) --gcc=pnacl gmake 30 | $(GENIE) --gcc=mingw-gcc gmake 31 | $(GENIE) --gcc=linux-gcc gmake 32 | $(GENIE) --gcc=osx gmake 33 | $(GENIE) --gcc=ios-arm gmake 34 | $(GENIE) --gcc=ios-simulator gmake 35 | $(GENIE) xcode4 36 | 37 | .build/projects/gmake-android-arm: 38 | $(GENIE) --gcc=android-arm gmake 39 | android-arm-debug: .build/projects/gmake-android-arm 40 | make -R -C .build/projects/gmake-android-arm config=debug 41 | android-arm-release: .build/projects/gmake-android-arm 42 | make -R -C .build/projects/gmake-android-arm config=release 43 | android-arm: android-arm-debug android-arm-release 44 | 45 | .build/projects/gmake-android-mips: 46 | $(GENIE) --gcc=android-mips gmake 47 | android-mips-debug: .build/projects/gmake-android-mips 48 | make -R -C .build/projects/gmake-android-mips config=debug 49 | android-mips-release: .build/projects/gmake-android-mips 50 | make -R -C .build/projects/gmake-android-mips config=release 51 | android-mips: android-mips-debug android-mips-release 52 | 53 | .build/projects/gmake-android-x86: 54 | $(GENIE) --gcc=android-x86 gmake 55 | android-x86-debug: .build/projects/gmake-android-x86 56 | make -R -C .build/projects/gmake-android-x86 config=debug 57 | android-x86-release: .build/projects/gmake-android-x86 58 | make -R -C .build/projects/gmake-android-x86 config=release 59 | android-x86: android-x86-debug android-x86-release 60 | 61 | .build/projects/gmake-linux: 62 | $(GENIE) --gcc=linux-gcc gmake 63 | linux-debug32: .build/projects/gmake-linux 64 | make -R -C .build/projects/gmake-linux config=debug32 65 | linux-release32: .build/projects/gmake-linux 66 | make -R -C .build/projects/gmake-linux config=release32 67 | linux-debug64: .build/projects/gmake-linux 68 | make -R -C .build/projects/gmake-linux config=debug64 69 | linux-release64: .build/projects/gmake-linux 70 | make -R -C .build/projects/gmake-linux config=release64 71 | linux: linux-debug32 linux-release32 linux-debug64 linux-release64 72 | 73 | .build/projects/gmake-mingw-gcc: 74 | $(GENIE) --gcc=mingw-gcc gmake 75 | mingw-gcc-debug32: .build/projects/gmake-mingw-gcc 76 | make -R -C .build/projects/gmake-mingw-gcc config=debug32 77 | mingw-gcc-release32: .build/projects/gmake-mingw-gcc 78 | make -R -C .build/projects/gmake-mingw-gcc config=release32 79 | mingw-gcc-debug64: .build/projects/gmake-mingw-gcc 80 | make -R -C .build/projects/gmake-mingw-gcc config=debug64 81 | mingw-gcc-release64: .build/projects/gmake-mingw-gcc 82 | make -R -C .build/projects/gmake-mingw-gcc config=release64 83 | mingw-gcc: mingw-gcc-debug32 mingw-gcc-release32 mingw-gcc-debug64 mingw-gcc-release64 84 | 85 | .build/projects/gmake-mingw-clang: 86 | $(GENIE) --clang=mingw-clang gmake 87 | mingw-clang-debug32: .build/projects/gmake-mingw-clang 88 | make -R -C .build/projects/gmake-mingw-clang config=debug32 89 | mingw-clang-release32: .build/projects/gmake-mingw-clang 90 | make -R -C .build/projects/gmake-mingw-clang config=release32 91 | mingw-clang-debug64: .build/projects/gmake-mingw-clang 92 | make -R -C .build/projects/gmake-mingw-clang config=debug64 93 | mingw-clang-release64: .build/projects/gmake-mingw-clang 94 | make -R -C .build/projects/gmake-mingw-clang config=release64 95 | mingw-clang: mingw-clang-debug32 mingw-clang-release32 mingw-clang-debug64 mingw-clang-release64 96 | 97 | .build/projects/vs2008: 98 | $(GENIE) vs2008 99 | vs2008-debug32: 100 | devenv .build/projects/vs2008/bgfx.sln /Build "Debug|Win32" 101 | vs2008-release32: 102 | devenv .build/projects/vs2008/bgfx.sln /Build "Release|Win32" 103 | vs2008-debug64: 104 | devenv .build/projects/vs2008/bgfx.sln /Build "Debug|x64" 105 | vs2008-release64: 106 | devenv .build/projects/vs2008/bgfx.sln /Build "Release|x64" 107 | vs2008: vs2008-debug32 vs2008-release32 vs2008-debug64 vs2008-release64 108 | 109 | .build/projects/vs2010: 110 | $(GENIE) vs2010 111 | 112 | .build/projects/vs2012: 113 | $(GENIE) vs2012 114 | 115 | .build/projects/vs2013: 116 | $(GENIE) vs2013 117 | 118 | .build/projects/gmake-nacl: 119 | $(GENIE) --gcc=nacl gmake 120 | nacl-debug32: .build/projects/gmake-nacl 121 | make -R -C .build/projects/gmake-nacl config=debug32 122 | nacl-release32: .build/projects/gmake-nacl 123 | make -R -C .build/projects/gmake-nacl config=release32 124 | nacl-debug64: .build/projects/gmake-nacl 125 | make -R -C .build/projects/gmake-nacl config=debug64 126 | nacl-release64: .build/projects/gmake-nacl 127 | make -R -C .build/projects/gmake-nacl config=release64 128 | nacl: nacl-debug32 nacl-release32 nacl-debug64 nacl-release64 129 | 130 | .build/projects/gmake-nacl-arm: 131 | $(GENIE) --gcc=nacl-arm gmake 132 | nacl-arm-debug: .build/projects/gmake-nacl-arm 133 | make -R -C .build/projects/gmake-nacl-arm config=debug 134 | nacl-arm-release: .build/projects/gmake-nacl-arm 135 | make -R -C .build/projects/gmake-nacl-arm config=release 136 | nacl-arm: nacl-arm-debug32 nacl-arm-release32 137 | 138 | .build/projects/gmake-pnacl: 139 | $(GENIE) --gcc=pnacl gmake 140 | pnacl-debug: .build/projects/gmake-pnacl 141 | make -R -C .build/projects/gmake-pnacl config=debug 142 | pnacl-release: .build/projects/gmake-pnacl 143 | make -R -C .build/projects/gmake-pnacl config=release 144 | pnacl: pnacl-debug pnacl-release 145 | 146 | .build/projects/gmake-osx: 147 | $(GENIE) --gcc=osx gmake 148 | osx-debug32: .build/projects/gmake-osx 149 | make -C .build/projects/gmake-osx config=debug32 150 | osx-release32: .build/projects/gmake-osx 151 | make -C .build/projects/gmake-osx config=release32 152 | osx-debug64: .build/projects/gmake-osx 153 | make -C .build/projects/gmake-osx config=debug64 154 | osx-release64: .build/projects/gmake-osx 155 | make -C .build/projects/gmake-osx config=release64 156 | osx: osx-debug32 osx-release32 osx-debug64 osx-release64 157 | 158 | .build/projects/gmake-ios-arm: 159 | $(GENIE) --gcc=ios-arm gmake 160 | ios-arm-debug: .build/projects/gmake-ios-arm 161 | make -R -C .build/projects/gmake-ios-arm config=debug 162 | ios-arm-release: .build/projects/gmake-ios-arm 163 | make -R -C .build/projects/gmake-ios-arm config=release 164 | ios-arm: ios-arm-debug ios-arm-release 165 | 166 | .build/projects/gmake-ios-simulator: 167 | $(GENIE) --gcc=ios-simulator gmake 168 | ios-simulator-debug: .build/projects/gmake-ios-simulator 169 | make -R -C .build/projects/gmake-ios-simulator config=debug 170 | ios-simulator-release: .build/projects/gmake-ios-simulator 171 | make -R -C .build/projects/gmake-ios-simulator config=release 172 | ios-simulator: ios-simulator-debug ios-simulator-release 173 | 174 | rebuild-shaders: 175 | make -R -C examples rebuild 176 | 177 | analyze: 178 | cppcheck src/ 179 | cppcheck examples/ 180 | 181 | docs: 182 | doxygen scripts/bgfx.doxygen 183 | markdown README.md > .build/docs/readme.html 184 | 185 | clean: 186 | @echo Cleaning... 187 | -@rm -rf .build 188 | 189 | ### 190 | 191 | SILENT ?= @ 192 | 193 | UNAME := $(shell uname) 194 | ifeq ($(UNAME),$(filter $(UNAME),Linux Darwin)) 195 | ifeq ($(UNAME),$(filter $(UNAME),Darwin)) 196 | OS=darwin 197 | BUILD_PROJECT_DIR=gmake-osx 198 | BUILD_OUTPUT_DIR=osx64_clang 199 | BUILD_TOOLS_CONFIG=release64 200 | EXE= 201 | else 202 | OS=linux 203 | BUILD_PROJECT_DIR=gmake-linux 204 | BUILD_OUTPUT_DIR=linux64_gcc 205 | BUILD_TOOLS_CONFIG=release64 206 | EXE= 207 | endif 208 | else 209 | OS=windows 210 | BUILD_PROJECT_DIR=gmake-mingw-gcc 211 | BUILD_OUTPUT_DIR=win32_mingw-gcc 212 | BUILD_TOOLS_CONFIG=release32 213 | EXE=.exe 214 | endif 215 | 216 | .build/$(BUILD_OUTPUT_DIR)/bin/bin2cRelease$(EXE): .build/projects/$(BUILD_PROJECT_DIR) 217 | $(SILENT) make -C .build/projects/$(BUILD_PROJECT_DIR) -f bin2c.make config=$(BUILD_TOOLS_CONFIG) 218 | 219 | tools/bin/$(OS)/bin2c$(EXE): .build/$(BUILD_OUTPUT_DIR)/bin/bin2cRelease$(EXE) 220 | $(SILENT) cp $(<) $(@) 221 | 222 | tools: tools/bin/$(OS)/bin2c$(EXE) 223 | -------------------------------------------------------------------------------- /dependency/bx/tools/bin/darwin/genie: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmft/cad5f31bac66fd05987d667af62311c444df6d46/dependency/bx/tools/bin/darwin/genie -------------------------------------------------------------------------------- /dependency/bx/tools/bin/linux/genie: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmft/cad5f31bac66fd05987d667af62311c444df6d46/dependency/bx/tools/bin/linux/genie -------------------------------------------------------------------------------- /dependency/bx/tools/bin/windows/genie.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmft/cad5f31bac66fd05987d667af62311c444df6d46/dependency/bx/tools/bin/windows/genie.exe -------------------------------------------------------------------------------- /dependency/bx/tools/bin2c/bin2c.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2015 Branimir Karadzic. 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 | 13 | class Bin2cWriter : public bx::WriterI 14 | { 15 | public: 16 | Bin2cWriter(bx::WriterI* _writer, const char* _name) 17 | : m_writer(_writer) 18 | , m_name(_name) 19 | { 20 | } 21 | 22 | virtual ~Bin2cWriter() 23 | { 24 | } 25 | 26 | virtual int32_t write(const void* _data, int32_t _size) BX_OVERRIDE 27 | { 28 | const char* data = (const char*)_data; 29 | m_buffer.insert(m_buffer.end(), data, data+_size); 30 | return _size; 31 | } 32 | 33 | void finish() 34 | { 35 | #define HEX_DUMP_WIDTH 16 36 | #define HEX_DUMP_SPACE_WIDTH 96 37 | #define HEX_DUMP_FORMAT "%-" BX_STRINGIZE(HEX_DUMP_SPACE_WIDTH) "." BX_STRINGIZE(HEX_DUMP_SPACE_WIDTH) "s" 38 | const uint8_t* data = &m_buffer[0]; 39 | uint32_t size = (uint32_t)m_buffer.size(); 40 | 41 | bx::writePrintf(m_writer, "static const uint8_t %s[%d] =\n{\n", m_name.c_str(), size); 42 | 43 | if (NULL != data) 44 | { 45 | char hex[HEX_DUMP_SPACE_WIDTH+1]; 46 | char ascii[HEX_DUMP_WIDTH+1]; 47 | uint32_t hexPos = 0; 48 | uint32_t asciiPos = 0; 49 | for (uint32_t ii = 0; ii < size; ++ii) 50 | { 51 | bx::snprintf(&hex[hexPos], sizeof(hex)-hexPos, "0x%02x, ", data[asciiPos]); 52 | hexPos += 6; 53 | 54 | ascii[asciiPos] = isprint(data[asciiPos]) && data[asciiPos] != '\\' ? data[asciiPos] : '.'; 55 | asciiPos++; 56 | 57 | if (HEX_DUMP_WIDTH == asciiPos) 58 | { 59 | ascii[asciiPos] = '\0'; 60 | bx::writePrintf(m_writer, "\t" HEX_DUMP_FORMAT "// %s\n", hex, ascii); 61 | data += asciiPos; 62 | hexPos = 0; 63 | asciiPos = 0; 64 | } 65 | } 66 | 67 | if (0 != asciiPos) 68 | { 69 | ascii[asciiPos] = '\0'; 70 | bx::writePrintf(m_writer, "\t" HEX_DUMP_FORMAT "// %s\n", hex, ascii); 71 | } 72 | } 73 | 74 | bx::writePrintf(m_writer, "};\n"); 75 | #undef HEX_DUMP_WIDTH 76 | #undef HEX_DUMP_SPACE_WIDTH 77 | #undef HEX_DUMP_FORMAT 78 | 79 | m_buffer.clear(); 80 | } 81 | 82 | bx::WriterI* m_writer; 83 | std::string m_filePath; 84 | std::string m_name; 85 | typedef std::vector Buffer; 86 | Buffer m_buffer; 87 | }; 88 | 89 | void help(const char* _error = NULL) 90 | { 91 | if (NULL != _error) 92 | { 93 | fprintf(stderr, "Error:\n%s\n\n", _error); 94 | } 95 | 96 | fprintf(stderr 97 | , "bin2c, binary to C\n" 98 | "Copyright 2011-2015 Branimir Karadzic. All rights reserved.\n" 99 | "License: http://www.opensource.org/licenses/BSD-2-Clause\n\n" 100 | ); 101 | 102 | fprintf(stderr 103 | , "Usage: bin2c -f -o -n \n" 104 | 105 | "\n" 106 | "Options:\n" 107 | " -f Input file path.\n" 108 | " -o Output file path.\n" 109 | " -n Array name.\n" 110 | 111 | "\n" 112 | "For additional information, see https://github.com/bkaradzic/bx\n" 113 | ); 114 | } 115 | 116 | 117 | int main(int _argc, const char* _argv[]) 118 | { 119 | bx::CommandLine cmdLine(_argc, _argv); 120 | 121 | if (cmdLine.hasArg('h', "help") ) 122 | { 123 | help(); 124 | return EXIT_FAILURE; 125 | } 126 | 127 | const char* filePath = cmdLine.findOption('f'); 128 | if (NULL == filePath) 129 | { 130 | help("Input file name must be specified."); 131 | return EXIT_FAILURE; 132 | } 133 | 134 | const char* outFilePath = cmdLine.findOption('o'); 135 | if (NULL == outFilePath) 136 | { 137 | help("Output file name must be specified."); 138 | return EXIT_FAILURE; 139 | } 140 | 141 | const char* name = cmdLine.findOption('n'); 142 | if (NULL == name) 143 | { 144 | name = "data"; 145 | } 146 | 147 | void* data = NULL; 148 | size_t size = 0; 149 | 150 | bx::CrtFileReader fr; 151 | if (0 == bx::open(&fr, filePath) ) 152 | { 153 | size = (size_t)bx::getSize(&fr); 154 | data = malloc(size); 155 | bx::read(&fr, data, size); 156 | 157 | bx::CrtFileWriter fw; 158 | if (0 == bx::open(&fw, outFilePath) ) 159 | { 160 | Bin2cWriter writer(&fw, name); 161 | bx::write(&writer, data, size); 162 | writer.finish(); 163 | bx::close(&fw); 164 | } 165 | 166 | free(data); 167 | } 168 | 169 | return 0; 170 | } 171 | -------------------------------------------------------------------------------- /include/cmft/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 CMFT_ALLOCATOR_H_HEADER_GUARD 7 | #define CMFT_ALLOCATOR_H_HEADER_GUARD 8 | 9 | #include // size_t 10 | 11 | #include 12 | #include 13 | 14 | namespace cmft 15 | { 16 | #ifndef CMFT_ALLOCATOR_DEBUG 17 | # define CMFT_ALLOCATOR_DEBUG 0 18 | #endif // CMFT_ALLOCATOR_DEBUG 19 | 20 | #ifndef CMFT_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT 21 | # define CMFT_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT 8 22 | #endif // CMFT_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT 23 | 24 | #if defined(_MSC_VER) 25 | # define CMFT_NO_VTABLE __declspec(novtable) 26 | #else 27 | # define CMFT_NO_VTABLE 28 | #endif 29 | 30 | struct CMFT_NO_VTABLE AllocatorI 31 | { 32 | virtual void* realloc(void* _ptr, size_t _size, size_t _align, const char* _file, size_t _line) = 0; 33 | }; 34 | 35 | struct CMFT_NO_VTABLE StackAllocatorI : AllocatorI 36 | { 37 | virtual void push(const char* _file, size_t _line) = 0; 38 | virtual void pop(const char* _file, size_t _line) = 0; 39 | }; 40 | 41 | struct StackAllocatorScope 42 | { 43 | StackAllocatorScope(StackAllocatorI* _stackAlloc) : m_stack(_stackAlloc) 44 | { 45 | m_stack->push(0,0); 46 | } 47 | 48 | ~StackAllocatorScope() 49 | { 50 | m_stack->pop(0,0); 51 | } 52 | 53 | private: 54 | StackAllocatorI* m_stack; 55 | }; 56 | 57 | #if CMFT_ALLOCATOR_DEBUG 58 | # define CMFT_ALLOC(_allocator, _size) (_allocator)->realloc(NULL, _size, 0, __FILE__, __LINE__) 59 | # define CMFT_REALLOC(_allocator, _ptr, _size) (_allocator)->realloc(_ptr, _size, 0, __FILE__, __LINE__) 60 | # define CMFT_FREE(_allocator, _ptr) (_allocator)->realloc(_ptr, 0, 0, __FILE__, __LINE__) 61 | # define CMFT_ALIGNED_ALLOC(_allocator, _size, _align) (_allocator)->realloc(NULL, _size, _align, __FILE__, __LINE__) 62 | # define CMFT_ALIGNED_REALLOC(_allocator, _ptr, _size, _align) (_allocator)->realloc(_ptr, _size, _align, __FILE__, __LINE__) 63 | # define CMFT_ALIGNED_FREE(_allocator, _ptr, _align) (_allocator)->realloc(_ptr, 0, _align, __FILE__, __LINE__) 64 | # define CMFT_PUSH(_stackAllocator) (_stackAllocator)->push(__FILE__, __LINE__) 65 | # define CMFT_POP(_stackAllocator) (_stackAllocator)->pop(__FILE__, __LINE__) 66 | #else 67 | # define CMFT_ALLOC(_allocator, _size) (_allocator)->realloc(NULL, _size, 0, 0, 0) 68 | # define CMFT_REALLOC(_allocator, _ptr, _size) (_allocator)->realloc(_ptr, _size, 0, 0, 0) 69 | # define CMFT_FREE(_allocator, _ptr) (_allocator)->realloc(_ptr, 0, 0, 0, 0) 70 | # define CMFT_ALIGNED_ALLOC(_allocator, _size, _align) (_allocator)->realloc(NULL, _size, _align, 0, 0) 71 | # define CMFT_ALIGNED_REALLOC(_allocator, _ptr, _size, _align) (_allocator)->realloc(_ptr, _size, _align, 0, 0) 72 | # define CMFT_ALIGNED_FREE(_allocator, _ptr, _align) (_allocator)->realloc(_ptr, 0, _align, 0, 0) 73 | # define CMFT_PUSH(_stackAllocator) (_stackAllocator)->push(0, 0) 74 | # define CMFT_POP(_stackAllocator) (_stackAllocator)->pop(0, 0) 75 | #endif // CMFT_ALLOCATOR_DEBUG 76 | 77 | struct CrtAllocator : AllocatorI 78 | { 79 | virtual void* realloc(void* _ptr, size_t _size, size_t _align, const char* /*_file*/, size_t /*_line*/) 80 | { 81 | (void)_align; // Ignoring alignment for now. 82 | 83 | if (0 == _ptr) 84 | { 85 | return ::malloc(_size); 86 | } 87 | else if (0 == _size) 88 | { 89 | ::free(_ptr); 90 | return NULL; 91 | } 92 | else 93 | { 94 | return ::realloc(_ptr, _size); 95 | } 96 | } 97 | }; 98 | extern CrtAllocator g_crtAllocator; 99 | 100 | struct CrtStackAllocator : StackAllocatorI 101 | { 102 | virtual void* realloc(void* _ptr, size_t _size, size_t _align, const char* /*_file*/, size_t /*_line*/) 103 | { 104 | (void)_align; // Ignoring alignment for now. 105 | 106 | if (0 == _ptr) 107 | { 108 | void* ptr = ::malloc(_size); 109 | m_ptrs[m_curr++] = ptr; 110 | return ptr; 111 | } 112 | else if (0 == _size) 113 | { 114 | ::free(_ptr); 115 | return NULL; 116 | } 117 | else 118 | { 119 | void* ptr = ::realloc(_ptr, _size); 120 | m_ptrs[m_curr++] = ptr; 121 | return ptr; 122 | } 123 | } 124 | 125 | virtual void push(const char* /*_file*/, size_t /*_line*/) 126 | { 127 | m_frames[m_frameIdx++] = m_curr; 128 | } 129 | 130 | virtual void pop(const char* /*_file*/, size_t /*_line*/) 131 | { 132 | uint16_t prev = m_frames[--m_frameIdx]; 133 | for (uint16_t ii = prev, iiEnd = m_curr; ii < iiEnd; ++ii) 134 | { 135 | ::free(m_ptrs[ii]); 136 | } 137 | m_curr = prev; 138 | } 139 | 140 | enum 141 | { 142 | MaxAllocations = 4096, 143 | MaxFrames = 4096, 144 | }; 145 | 146 | uint16_t m_curr; 147 | uint16_t m_frameIdx; 148 | void* m_ptrs[MaxAllocations]; 149 | uint16_t m_frames[MaxAllocations]; 150 | }; 151 | extern CrtStackAllocator g_crtStackAllocator; 152 | 153 | extern AllocatorI* g_allocator; 154 | extern StackAllocatorI* g_stackAllocator; 155 | 156 | void setAllocator(AllocatorI* _allocator); 157 | void setStackAllocator(StackAllocatorI* _stackAllocator); 158 | }; 159 | 160 | #endif // CMFT_ALLOCATOR_H_HEADER_GUARD 161 | 162 | /* vim: set sw=4 ts=4 expandtab: */ 163 | -------------------------------------------------------------------------------- /include/cmft/clcontext.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFT_CLCONTEXT_H_HEADER_GUARD 7 | #define CMFT_CLCONTEXT_H_HEADER_GUARD 8 | 9 | #include 10 | 11 | #define CMFT_CL_VENDOR_INTEL (0x1) 12 | #define CMFT_CL_VENDOR_AMD (0x2) 13 | #define CMFT_CL_VENDOR_NVIDIA (0x4) 14 | #define CMFT_CL_VENDOR_OTHER (0x8) 15 | #define CMFT_CL_VENDOR_ANY_GPU (CMFT_CL_VENDOR_AMD|CMFT_CL_VENDOR_NVIDIA) 16 | #define CMFT_CL_VENDOR_ANY_CPU (CMFT_CL_VENDOR_AMD|CMFT_CL_VENDOR_INTEL) 17 | 18 | #define CMFT_CL_DEVICE_TYPE_DEFAULT (1 << 0) /* CL_DEVICE_TYPE_DEFAULT */ 19 | #define CMFT_CL_DEVICE_TYPE_CPU (1 << 1) /* CL_DEVICE_TYPE_CPU */ 20 | #define CMFT_CL_DEVICE_TYPE_GPU (1 << 2) /* CL_DEVICE_TYPE_GPU */ 21 | #define CMFT_CL_DEVICE_TYPE_ACCELERATOR (1 << 3) /* CL_DEVICE_TYPE_ACCELERATOR */ 22 | #define CMFT_CL_DEVICE_TYPE_ALL (0xFFFFFFFF) /* CL_DEVICE_TYPE_ALL */ 23 | 24 | namespace cmft 25 | { 26 | // OpenCl. 27 | //---- 28 | 29 | int32_t clLoad(); 30 | void clPrintDevices(); 31 | int32_t clUnload(); 32 | 33 | 34 | // ClContext. 35 | //----- 36 | 37 | struct ClContext; 38 | 39 | ClContext* clInit(uint32_t _vendor = CMFT_CL_VENDOR_ANY_GPU 40 | , uint32_t _preferredDeviceType = CMFT_CL_DEVICE_TYPE_GPU 41 | , uint32_t _preferredDeviceIdx = 0 42 | , const char* _vendorStrPart = NULL 43 | ); 44 | void clDestroy(ClContext* _context); 45 | 46 | } // namespace cmft 47 | 48 | #endif //CMFT_CLCONTEXT_H_HEADER_GUARD 49 | 50 | /* vim: set sw=4 ts=4 expandtab: */ 51 | -------------------------------------------------------------------------------- /include/cmft/cubemapfilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFT_CUBEMAPFILTER_H_HEADER_GUARD 7 | #define CMFT_CUBEMAPFILTER_H_HEADER_GUARD 8 | 9 | #include "image.h" 10 | #include //uint32_t 11 | 12 | namespace cmft 13 | { 14 | #define SH_COEFF_NUM 25 15 | 16 | /// Computes spherical harominics coefficients for given cubemap data. 17 | /// Input data should be in RGBA32F format. 18 | void cubemapShCoeffs(double _shCoeffs[SH_COEFF_NUM][3], void* _data, uint32_t _faceSize, uint32_t _faceOffsets[6]); 19 | 20 | /// Computes spherical harominics coefficients for given cubemap image. 21 | bool imageShCoeffs(double _shCoeffs[SH_COEFF_NUM][3], const Image& _image, AllocatorI* _allocator = g_allocator); 22 | 23 | /// Creates irradiance cubemap. Uses fast spherical harmonics implementation. 24 | bool imageIrradianceFilterSh(Image& _dst, uint32_t _dstFaceSize, const Image& _src, AllocatorI* _allocator = g_allocator); 25 | 26 | /// Converts cubemap image into irradiance cubemap. Uses fast spherical harmonics implementation. 27 | void imageIrradianceFilterSh(Image& _image, uint32_t _faceSize, AllocatorI* _allocator = g_allocator); 28 | 29 | struct LightingModel 30 | { 31 | enum Enum 32 | { 33 | Phong, 34 | PhongBrdf, 35 | Blinn, 36 | BlinnBrdf, 37 | 38 | Count 39 | }; 40 | }; 41 | 42 | /// Warp edge fixup is used for DirectX 9 and OpenGL without ARB_seamless_cube_map where 43 | /// there is no support for seamless filtering across cubemap faces. For cubemaps filtered 44 | /// with Warp filter, this code needs to be called in the shader at runtime: 45 | /// vec3 fixCubeLookup(vec3 _v, float _lod, float _topLevelCubeSize) 46 | /// { 47 | /// float ax = abs(_v.x); 48 | /// float ay = abs(_v.y); 49 | /// float az = abs(_v.z); 50 | /// float vmax = max(max(ax, ay), az); 51 | /// float scale = 1.0 - exp2(_lod)/_topLevelCubeSize; 52 | /// if (ax != vmax) { _v.x *= scale; } 53 | /// if (ay != vmax) { _v.y *= scale; } 54 | /// if (az != vmax) { _v.z *= scale; } 55 | /// return _v; 56 | /// } 57 | /// 58 | /// For aditional details see: http://the-witness.net/news/2012/02/seamless-cube-map-filtering/ 59 | /// 60 | struct EdgeFixup 61 | { 62 | enum Enum 63 | { 64 | None, 65 | Warp, 66 | }; 67 | }; 68 | 69 | /// Helper functions. 70 | float specularPowerFor(float _mip, float _mipCount, float _glossScale, float _glossBias); 71 | float applyLightningModel(float _specularPower, LightingModel::Enum _lightingModel); 72 | 73 | struct ClContext; 74 | 75 | /// Creates radiance cubemap image. 76 | bool imageRadianceFilter(Image& _dst 77 | , uint32_t _dstFaceSize 78 | , LightingModel::Enum _lightingModel 79 | , bool _excludeBase 80 | , uint8_t _mipCount 81 | , uint8_t _glossScale 82 | , uint8_t _glossBias 83 | , const Image& _src 84 | , EdgeFixup::Enum _edgeFixup = EdgeFixup::None 85 | , uint8_t _numCpuProcessingThreads = 0 86 | , ClContext* _clContext = NULL 87 | , AllocatorI* _allocator = g_allocator 88 | ); 89 | 90 | /// Converts cubemap image into radiance cubemap. 91 | bool imageRadianceFilter(Image& _image 92 | , uint32_t _dstFaceSize 93 | , LightingModel::Enum _lightingModel 94 | , bool _excludeBase 95 | , uint8_t _mipCount 96 | , uint8_t _glossScale 97 | , uint8_t _glossBias 98 | , EdgeFixup::Enum _edgeFixup = EdgeFixup::None 99 | , uint8_t _numCpuProcessingThreads = 0 100 | , ClContext* _clContext = NULL 101 | , AllocatorI* _allocator = g_allocator 102 | ); 103 | 104 | } // namespace cmft 105 | 106 | #endif // CMFT_CUBEMAPFILTER_H_HEADER_GUARD 107 | 108 | /* vim: set sw=4 ts=4 expandtab: */ 109 | -------------------------------------------------------------------------------- /include/cmft/image.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFT_IMAGE_H_HEADER_GUARD 7 | #define CMFT_IMAGE_H_HEADER_GUARD 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "allocator.h" 14 | 15 | #ifndef UINT8_MAX // Fixing mingw bug. 16 | #define UINT8_MAX (255) 17 | #endif //UINT8_MAX 18 | 19 | namespace cmft 20 | { 21 | #define CUBE_FACE_NUM 6 22 | #define MAX_MIP_NUM 16 23 | 24 | enum ImageTransformArgs 25 | { 26 | IMAGE_FACE_POSITIVEX = 0x0000, 27 | IMAGE_FACE_NEGATIVEX = 0x0001, 28 | IMAGE_FACE_POSITIVEY = 0x0002, 29 | IMAGE_FACE_NEGATIVEY = 0x0003, 30 | IMAGE_FACE_POSITIVEZ = 0x0004, 31 | IMAGE_FACE_NEGATIVEZ = 0x0005, 32 | IMAGE_FACE_SHIFT = 0, 33 | IMAGE_FACE_MASK = 0x0007, 34 | 35 | IMAGE_OP_ROT_90 = 0x0100, 36 | IMAGE_OP_ROT_180 = 0x0200, 37 | IMAGE_OP_ROT_270 = 0x0400, 38 | IMAGE_OP_FLIP_X = 0x1000, 39 | IMAGE_OP_FLIP_Y = 0x2000, 40 | IMAGE_OP_SHIFT = 8, 41 | IMAGE_OP_MASK = 0xff00, 42 | }; 43 | 44 | struct ImageFileType 45 | { 46 | enum Enum 47 | { 48 | DDS, 49 | KTX, 50 | TGA, 51 | HDR, 52 | 53 | Count 54 | }; 55 | }; 56 | 57 | struct OutputType 58 | { 59 | enum Enum 60 | { 61 | LatLong, 62 | Cubemap, 63 | HCross, 64 | VCross, 65 | HStrip, 66 | VStrip, 67 | FaceList, 68 | Octant, 69 | 70 | Count, 71 | Null = -1, 72 | }; 73 | }; 74 | 75 | struct TextureFormat 76 | { 77 | enum Enum 78 | { 79 | BGR8, 80 | RGB8, 81 | RGB16, 82 | RGB16F, 83 | RGB32F, 84 | RGBE, 85 | 86 | BGRA8, 87 | RGBA8, 88 | RGBA16, 89 | RGBA16F, 90 | RGBA32F, 91 | 92 | RGBM, 93 | 94 | Count, 95 | Null = -1, 96 | }; 97 | }; 98 | 99 | struct ImageDataInfo 100 | { 101 | uint8_t m_bytesPerPixel; 102 | uint8_t m_numChanels; 103 | uint8_t m_hasAlpha; 104 | uint8_t m_pixelType; 105 | }; 106 | 107 | struct Image 108 | { 109 | Image() 110 | { 111 | m_width = 0; 112 | m_height = 0; 113 | m_dataSize = 0; 114 | m_format = TextureFormat::Null; 115 | m_numMips = 0; 116 | m_numFaces = 0; 117 | m_data = NULL; 118 | } 119 | 120 | uint32_t m_width; 121 | uint32_t m_height; 122 | uint32_t m_dataSize; 123 | TextureFormat::Enum m_format; 124 | uint8_t m_numMips; 125 | uint8_t m_numFaces; 126 | void* m_data; 127 | }; 128 | 129 | extern AllocatorI* g_allocator; 130 | 131 | /// 132 | const char* getFileTypeStr(ImageFileType::Enum _ft); 133 | 134 | /// 135 | const char* getOutputTypeStr(OutputType::Enum _ot); 136 | 137 | /// 138 | const char* getCubemapFaceIdStr(uint8_t _face); 139 | 140 | /// 141 | const char* getFilenameExtensionStr(ImageFileType::Enum _ft); 142 | 143 | /// 144 | const char* getTextureFormatStr(TextureFormat::Enum _format); 145 | 146 | /// Returns a OutputType::Null terminating array of valid output types for requested file type. 147 | const OutputType::Enum* getValidOutputTypes(ImageFileType::Enum _fileType); 148 | 149 | /// 150 | void getValidOutputTypesStr(char* _str, ImageFileType::Enum _fileType); 151 | 152 | /// 153 | bool checkValidOutputType(ImageFileType::Enum _fileType, OutputType::Enum _outputType); 154 | 155 | /// Returns a TextureFormat::Null terminating array of valid texture formats for requested file type. 156 | const TextureFormat::Enum* getValidTextureFormats(ImageFileType::Enum _fileType); 157 | 158 | /// 159 | void getValidTextureFormatsStr(char* _str, ImageFileType::Enum _fileType); 160 | 161 | /// 162 | bool checkValidTextureFormat(ImageFileType::Enum _fileType, TextureFormat::Enum _textureFormat); 163 | 164 | /// 165 | const ImageDataInfo& getImageDataInfo(TextureFormat::Enum _format); 166 | 167 | /// 168 | uint8_t getNaturalAlignment(TextureFormat::Enum _format); 169 | 170 | /// 171 | void imageCreate(Image& _image, uint32_t _width, uint32_t _height, uint32_t _rgba = 0x303030ff, uint8_t _numMips = 1, uint8_t _numFaces = 1, TextureFormat::Enum _format = TextureFormat::RGBA32F, AllocatorI* _allocator = g_allocator); 172 | 173 | /// 174 | void imageUnload(Image& _image, AllocatorI* _allocator = g_allocator); 175 | 176 | /// 177 | void imageMove(Image& _dst, Image& _src, AllocatorI* _allocator = g_allocator); 178 | 179 | /// 180 | void imageCopy(Image& _dst, const Image& _src, AllocatorI* _allocator = g_allocator); 181 | 182 | /// 183 | uint32_t imageGetNumPixels(const Image& _image); 184 | 185 | /// 186 | void imageGetMipOffsets(uint32_t _offsets[CUBE_FACE_NUM][MAX_MIP_NUM], const Image& _image); 187 | 188 | /// 189 | void imageGetFaceOffsets(uint32_t _faceOffsets[CUBE_FACE_NUM], const Image& _image); 190 | 191 | /// 192 | void toRgba32f(float _rgba32f[4], TextureFormat::Enum _srcFormat, const void* _src); 193 | 194 | /// 195 | void imageToRgba32f(Image& _dst, const Image& _src, AllocatorI* _allocator = g_allocator); 196 | 197 | /// 198 | void imageToRgba32f(Image& _image, AllocatorI* _allocator = g_allocator); 199 | 200 | /// 201 | void fromRgba32f(void* _out, TextureFormat::Enum _format, const float _rgba32f[4]); 202 | 203 | /// 204 | void imageFromRgba32f(Image& _dst, TextureFormat::Enum _dstFormat, const Image& _src, AllocatorI* _allocator = g_allocator); 205 | 206 | /// 207 | void imageFromRgba32f(Image& _image, TextureFormat::Enum _textureFormat, AllocatorI* _allocator = g_allocator); 208 | 209 | /// 210 | void imageConvert(Image& _dst, TextureFormat::Enum _dstFormat, const Image& _src, AllocatorI* _allocator = g_allocator); 211 | 212 | /// 213 | void imageConvert(Image& _image, TextureFormat::Enum _format, AllocatorI* _allocator = g_allocator); 214 | 215 | /// 216 | void imageGetPixel(void* _out, TextureFormat::Enum _format, uint32_t _x, uint32_t _y, uint8_t _face, uint8_t _mip, const Image& _image); 217 | 218 | /// 219 | void imageCubemapGetPixel(void* _out, TextureFormat::Enum _format, float _dir[3], uint8_t _mip, const Image& _image); 220 | 221 | /// 222 | void imageResize(Image& _dst, uint32_t _width, uint32_t _height, const Image& _src, AllocatorI* _allocator = g_allocator); 223 | 224 | /// 225 | void imageResize(Image& _image, uint32_t _width, uint32_t _height, AllocatorI* _allocator = g_allocator); 226 | 227 | /// 228 | void imageResize(Image& _dst, uint32_t _faceSize, const Image& _src, AllocatorI* _allocator = g_allocator); 229 | 230 | /// 231 | void imageResize(Image& _image, uint32_t _faceSize, AllocatorI* _allocator = g_allocator); 232 | 233 | /// 234 | uint32_t imageGetCubemapFaceSize(const Image& _image); 235 | 236 | /// Notice: because all transformations are done on data in place, 237 | /// rotations work properly only when image width == image height (which is true for cubemap images). 238 | /// Flip operations work properly regardless of aspect ratio. 239 | #define imageTransform(_image, ...) imageTransformUseMacroInstead(&(_image), __VA_ARGS__, UINT32_MAX) 240 | void imageTransformUseMacroInstead(Image* _image, ...); 241 | 242 | /// Notice: _argList should end with UINT32_MAX. 243 | void imageTransformArg(Image& _image, va_list _argList); 244 | 245 | /// 246 | void imageGenerateMipMapChain(Image& _image, uint8_t _numMips=UINT8_MAX, AllocatorI* _allocator = g_allocator); 247 | 248 | /// 249 | void imageEncodeRGBM(Image& _image, AllocatorI* _allocator = g_allocator); 250 | 251 | /// 252 | void imageApplyGamma(Image& _image, float _gammaPow, AllocatorI* _allocator = g_allocator); 253 | 254 | /// 255 | void imageClamp(Image& _dst, const Image& _src, AllocatorI* _allocator = g_allocator); 256 | 257 | /// 258 | void imageClamp(Image& _image, AllocatorI* _allocator = g_allocator); 259 | 260 | /// .....___.... 261 | /// +------+ ....__....... . | | . _________________ ___ ___ _______________ 262 | /// /| /| . | | . .___|___|___. | | |___| | |_ | . | 263 | /// +-+----+ | .__|__|__ __. | | | | | | __ __ __ __ __ __ |___| |___| |_ | . . . | 264 | /// | | | | | | | | | |___|___|___| | | | | | | | | | |___| |___| |_ | . . . | 265 | /// | +----+-+ |__|__|__|__| . | | . | | |__|__|__|__|__|__| |___| |___| |_ |...............| 266 | /// |/ |/ . | | . . |___| . |_________________| |___| |___| |_ | . . . | 267 | /// +------+ ...|__|...... . | | . |___| |___| | | . . . | 268 | /// ....|___|.... |___| |_______._______| 269 | /// 270 | /// Cubemap HCross VCross Lat Long HStrip VStrip Face list Octant 271 | /// 272 | /// Octant: 273 | /// Octahedron environment maps: http://www.vis.uni-stuttgart.de/~dachsbcn/download/vmvOctaMaps.pdf 274 | /// A survey of efficient representations for independent unit vectors: http://jcgt.org/published/0003/02/01/paper.pdf (page 8. and 9.) 275 | /// 276 | 277 | /// 278 | bool imageIsCubemap(const Image& _image); 279 | 280 | /// 281 | /// Checks if image is a latlong image. Not an actual test, just checks the image ratio. 282 | /// 283 | bool imageIsLatLong(const Image& _image); 284 | 285 | /// 286 | bool imageIsHStrip(const Image& _image); 287 | 288 | /// 289 | bool imageIsVStrip(const Image& _image); 290 | 291 | /// 292 | bool imageIsOctant(const Image& _image); 293 | 294 | /// 295 | bool imageValidCubemapFaceList(const Image _faceList[6]); 296 | 297 | /// 298 | bool imageIsCubeCross(const Image& _image, bool _fastCheck = false); 299 | 300 | /// 301 | bool imageIsEnvironmentMap(const Image& _image, bool _fastCheck = false); 302 | 303 | /// 304 | bool imageCubemapFromCross(Image& _dst, const Image& _src, AllocatorI* _allocator = g_allocator); 305 | 306 | /// 307 | bool imageCubemapFromCross(Image& _image, AllocatorI* _allocator = g_allocator); 308 | 309 | /// 310 | bool imageCubemapFromLatLong(Image& _dst, const Image& _src, bool _useBilinearInterpolation = true, AllocatorI* _allocator = g_allocator); 311 | 312 | /// 313 | bool imageCubemapFromLatLong(Image& _image, bool _useBilinearInterpolation = true, AllocatorI* _allocator = g_allocator); 314 | 315 | /// 316 | bool imageLatLongFromCubemap(Image& _dst, const Image& _src, bool _useBilinearInterpolation = true, AllocatorI* _allocator = g_allocator); 317 | 318 | /// 319 | bool imageLatLongFromCubemap(Image& _cubemap, bool _useBilinearInterpolation = true, AllocatorI* _allocator = g_allocator); 320 | 321 | /// 322 | bool imageStripFromCubemap(Image& _dst, const Image& _src, bool _vertical = false, AllocatorI* _allocator = g_allocator); 323 | 324 | /// 325 | bool imageStripFromCubemap(Image& _image, bool _vertical = false, AllocatorI* _allocator = g_allocator); 326 | 327 | /// 328 | bool imageCubemapFromStrip(Image& _dst, const Image& _src, AllocatorI* _allocator = g_allocator); 329 | 330 | /// 331 | bool imageCubemapFromStrip(Image& _image, AllocatorI* _allocator = g_allocator); 332 | 333 | /// 334 | bool imageFaceListFromCubemap(Image _faceList[6], const Image& _cubemap, AllocatorI* _allocator = g_allocator); 335 | 336 | /// 337 | bool imageCubemapFromFaceList(Image& _cubemap, const Image _faceList[6], AllocatorI* _allocator = g_allocator); 338 | 339 | /// 340 | bool imageCrossFromCubemap(Image& _dst, const Image& _src, bool _vertical = true, AllocatorI* _allocator = g_allocator); 341 | 342 | /// 343 | bool imageCrossFromCubemap(Image& _image, bool _vertical = true, AllocatorI* _allocator = g_allocator); 344 | 345 | /// 346 | bool imageToCubemap(Image& _dst, const Image& _src, AllocatorI* _allocator = g_allocator); 347 | 348 | /// 349 | bool imageToCubemap(Image& _image, AllocatorI* _allocator = g_allocator); 350 | 351 | /// 352 | bool imageOctantFromCubemap(Image& _dst, const Image& _src, bool _useBilinearInterpolation, AllocatorI* _allocator); 353 | 354 | /// 355 | bool imageCubemapFromOctant(Image& _dst, const Image& _src, bool _useBilinearInterpolation = true, AllocatorI* _allocator = g_allocator); 356 | 357 | /// 358 | bool imageCubemapFromOctant(Image& _image, bool _useBilinearInterpolation = true, AllocatorI* _allocator = g_allocator); 359 | 360 | /// 361 | bool imageLoad(Image& _image, const char* _filePath, TextureFormat::Enum _convertTo = TextureFormat::Null, AllocatorI* _allocator = g_allocator); 362 | 363 | /// 364 | bool imageLoad(Image& _image, const void* _data, uint32_t _dataSize, TextureFormat::Enum _convertTo = TextureFormat::Null, AllocatorI* _allocator = g_allocator); 365 | 366 | /// 367 | bool imageLoadStb(Image& _image, const char* _filePath, TextureFormat::Enum _convertTo = TextureFormat::Null, AllocatorI* _allocator = g_allocator); 368 | 369 | /// 370 | bool imageLoadStb(Image& _image, const void* _data, uint32_t _dataSize, TextureFormat::Enum _convertTo = TextureFormat::Null, AllocatorI* _allocator = g_allocator); 371 | 372 | /// 373 | bool imageIsValid(const Image& _image); 374 | 375 | /// 376 | bool imageSave(const Image& _image, const char* _fileName, ImageFileType::Enum _ft, TextureFormat::Enum _convertTo = TextureFormat::Null, AllocatorI* _allocator = g_allocator); 377 | 378 | /// 379 | bool imageSave(const Image& _image, const char* _fileName, ImageFileType::Enum _ft, OutputType::Enum _ot, TextureFormat::Enum _tf = TextureFormat::Null, bool _printOutput = false, AllocatorI* _allocator = g_allocator); 380 | 381 | // ImageRef 382 | //----- 383 | 384 | struct ImageSoftRef : public Image 385 | { 386 | ImageSoftRef() 387 | { 388 | m_isRef = false; 389 | } 390 | 391 | inline bool isRef() const { return m_isRef; } 392 | inline bool isCopy() const { return !m_isRef; } 393 | 394 | bool m_isRef; 395 | }; 396 | 397 | struct ImageHardRef : public Image 398 | { 399 | ImageHardRef() 400 | { 401 | m_origDataPtr = NULL; 402 | } 403 | 404 | inline bool isRef() const { return (NULL != m_origDataPtr); } 405 | inline bool isCopy() const { return (NULL == m_origDataPtr); } 406 | 407 | void** m_origDataPtr; 408 | }; 409 | 410 | /// 411 | bool imageAsCubemap(ImageSoftRef& _dst, const Image& _src, AllocatorI* _allocator = g_allocator); 412 | 413 | /// If requested format is the same as source, _dst becomes a reference to _src. 414 | /// Otherwise, _dst is filled with a converted copy of the image. 415 | /// Either way, imageUnload() should be called on _dst and it will free the data in case a copy was made. 416 | void imageRefOrConvert(ImageHardRef& _dst, TextureFormat::Enum _format, Image& _src, AllocatorI* _allocator = g_allocator); 417 | 418 | /// 419 | void imageRefOrConvert(ImageSoftRef& _dst, TextureFormat::Enum _format, const Image& _src, AllocatorI* _allocator = g_allocator); 420 | 421 | /// 422 | void imageRef(ImageSoftRef& _dst, const Image& _src); 423 | 424 | /// 425 | void imageRef(ImageHardRef& _dst, Image& _src); 426 | 427 | /// 428 | void imageMove(Image& _dst, ImageSoftRef& _src, AllocatorI* _allocator = g_allocator); 429 | 430 | /// 431 | void imageMove(Image& _dst, ImageHardRef& _src, AllocatorI* _allocator = g_allocator); 432 | 433 | /// 434 | void imageUnload(ImageSoftRef& _image, AllocatorI* _allocator = g_allocator); 435 | 436 | /// 437 | void imageUnload(ImageHardRef& _image, AllocatorI* _allocator = g_allocator); 438 | 439 | } // namespace cmft 440 | 441 | #endif //CMFT_IMAGE_H_HEADER_GUARD 442 | 443 | /* vim: set sw=4 ts=4 expandtab: */ 444 | -------------------------------------------------------------------------------- /include/cmft/print.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFT_PRINT_H_HEADER_GUARD 7 | #define CMFT_PRINT_H_HEADER_GUARD 8 | 9 | namespace cmft 10 | { 11 | typedef int (*PrintFunc)(const char* _format, ...); 12 | 13 | void setWarningPrintf(PrintFunc _printf); 14 | void setInfoPrintf(PrintFunc _printf); 15 | 16 | } // namespace cmft 17 | 18 | #endif //CMFT_PRINT_H_HEADER_GUARD 19 | 20 | /* vim: set sw=4 ts=4 expandtab: */ 21 | -------------------------------------------------------------------------------- /res/cmft_cover.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmft/cad5f31bac66fd05987d667af62311c444df6d46/res/cmft_cover.jpg -------------------------------------------------------------------------------- /res/cmft_performance_chart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmft/cad5f31bac66fd05987d667af62311c444df6d46/res/cmft_performance_chart.png -------------------------------------------------------------------------------- /runtime/.gitignore: -------------------------------------------------------------------------------- 1 | *.dds 2 | *.hdr 3 | *.tga 4 | *.ktx 5 | *.jpg 6 | -------------------------------------------------------------------------------- /runtime/cmft_lin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | # License: http://www.opensource.org/licenses/BSD-2-Clause 6 | # 7 | 8 | CMFT=./../_build/linux64_gcc/bin/cmftRelease 9 | 10 | # Prints help. 11 | #eval $CMFT --help 12 | 13 | # Use this to list available OpenCL devices that can be used with cmft for processing. 14 | #eval $CMFT --printCLDevices 15 | 16 | # Typical parameters for irradiance filter. 17 | #eval $CMFT $@ --input "okretnica.tga" \ 18 | # --filter irradiance \ 19 | # --srcFaceSize 0 \ 20 | # --dstFaceSize 0 \ 21 | # --outputNum 1 \ 22 | # --output0 "okretnica_irr" \ 23 | # --output0params dds,bgra8,cubemap 24 | 25 | # Typical parameters for generating spherical harmonics coefficients. 26 | #eval $CMFT $@ --input "okretnica.tga" \ 27 | # --filter shcoeffs \ 28 | # --outputNum 1 \ 29 | # --output0 "okretnica" 30 | 31 | # Typical parameters for radiance filter. 32 | eval $CMFT $@ --input "okretnica.tga" \ 33 | ::Filter options \ 34 | --filter radiance \ 35 | --srcFaceSize 256 \ 36 | --excludeBase false \ 37 | --mipCount 7 \ 38 | --glossScale 10 \ 39 | --glossBias 3 \ 40 | --lightingModel blinnbrdf \ 41 | --edgeFixup none \ 42 | --dstFaceSize 256 \ 43 | ::Processing devices \ 44 | --numCpuProcessingThreads 4 \ 45 | --useOpenCL true \ 46 | --clVendor anyGpuVendor \ 47 | --deviceType gpu \ 48 | --deviceIndex 0 \ 49 | ::Aditional operations \ 50 | --inputGammaNumerator 2.2 \ 51 | --inputGammaDenominator 1.0 \ 52 | --outputGammaNumerator 1.0 \ 53 | --outputGammaDenominator 2.2 \ 54 | --generateMipChain false \ 55 | ::Output \ 56 | --outputNum 2 \ 57 | --output0 "okretnica_pmrem" \ 58 | --output0params dds,bgra8,cubemap \ 59 | --output1 "okretnica_pmrem" \ 60 | --output1params ktx,rgba8,cubemap 61 | 62 | # Cmft can also be run without any processing filter. This can be used for performing image manipulations or exporting different image format. 63 | #eval $CMFT $@ --input "okretnica.tga" \ 64 | # --filter none \ 65 | # ::Aditional operations \ 66 | # --inputGamma 1.0 \ 67 | # --inputGammaDenominator 1.0 \ 68 | # --outputGamma 1.0 \ 69 | # --outputGammaDenominator 1.0 \ 70 | # --generateMipChain true \ 71 | # ::Cubemap transformations \ 72 | # --posXrotate90 \ 73 | # --posXrotate180 \ 74 | # --posXrotate270 \ 75 | # --posXflipH \ 76 | # --posXflipV \ 77 | # --negXrotate90 \ 78 | # --negXrotate180 \ 79 | # --negXrotate270 \ 80 | # --negXflipH \ 81 | # --negXflipV \ 82 | # --posYrotate90 \ 83 | # --posYrotate180 \ 84 | # --posYrotate270 \ 85 | # --posYflipH \ 86 | # --posYflipV \ 87 | # --negYrotate90 \ 88 | # --negYrotate180 \ 89 | # --negYrotate270 \ 90 | # --negYflipH \ 91 | # --negYflipV \ 92 | # --posZrotate90 \ 93 | # --posZrotate180 \ 94 | # --posZrotate270 \ 95 | # --posZflipH \ 96 | # --posZflipV \ 97 | # --negZrotate90 \ 98 | # --negZrotate180 \ 99 | # --negZrotate270 \ 100 | # --negZflipH \ 101 | # --negZflipV \ 102 | # ::Output \ 103 | # --outputNum 1 \ 104 | # --output0 "okretnica_dds" \ 105 | # --output0params dds,bgra8,cubemap \ 106 | 107 | # Cmft with all parameters listed. This is mainly to have a look at what is all possible. 108 | #eval $CMFT $@ --input "okretnica.tga" \ 109 | # ::Filter options \ 110 | # --filter radiance \ 111 | # --srcFaceSize 256 \ 112 | # --excludeBase false \ 113 | # --mipCount 7 \ 114 | # --glossScale 10 \ 115 | # --glossBias 3 \ 116 | # --lightingModel blinnbrdf \ 117 | # --edgeFixup none \ 118 | # --dstFaceSize 256 \ 119 | # ::Processing devices \ 120 | # --numCpuProcessingThreads 4 \ 121 | # --useOpenCL true \ 122 | # --clVendor anyGpuVendor \ 123 | # --deviceType gpu \ 124 | # --deviceIndex 0 \ 125 | # ::Aditional operations \ 126 | # --inputGamma 1.0 \ 127 | # --inputGammaDenominator 1.0 \ 128 | # --outputGamma 1.0 \ 129 | # --outputGammaDenominator 1.0 \ 130 | # --generateMipChain false \ 131 | # ::Cubemap transformations \ 132 | # --posXrotate90 \ 133 | # --posXrotate180 \ 134 | # --posXrotate270 \ 135 | # --posXflipH \ 136 | # --posXflipV \ 137 | # --negXrotate90 \ 138 | # --negXrotate180 \ 139 | # --negXrotate270 \ 140 | # --negXflipH \ 141 | # --negXflipV \ 142 | # --posYrotate90 \ 143 | # --posYrotate180 \ 144 | # --posYrotate270 \ 145 | # --posYflipH \ 146 | # --posYflipV \ 147 | # --negYrotate90 \ 148 | # --negYrotate180 \ 149 | # --negYrotate270 \ 150 | # --negYflipH \ 151 | # --negYflipV \ 152 | # --posZrotate90 \ 153 | # --posZrotate180 \ 154 | # --posZrotate270 \ 155 | # --posZflipH \ 156 | # --posZflipV \ 157 | # --negZrotate90 \ 158 | # --negZrotate180 \ 159 | # --negZrotate270 \ 160 | # --negZflipH \ 161 | # --negZflipV \ 162 | # ::Output \ 163 | # --outputNum 5 \ 164 | # --output0 "cmft_cubemap" --output0params dds,bgra8,cubemap \ 165 | # --output1 "cmft_hstrip" --output1params dds,bgra8,hstrip \ 166 | # --output2 "cmft_cubecross" --output2params ktx,rgba32f,hcross \ 167 | # --output3 "cmft_facelist" --output3params tga,bgra8,facelist \ 168 | # --output4 "cmft_latlong" --output4params hdr,rgbe,latlong 169 | -------------------------------------------------------------------------------- /runtime/cmft_osx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Copyright 2014-2015 Dario Manesku. All rights reserved. 5 | # License: http://www.opensource.org/licenses/BSD-2-Clause 6 | # 7 | 8 | #CMFT=./../_build/osx64_xcode4/bin/cmftRelease 9 | CMFT=./../_build/osx64_clang/bin/cmftRelease 10 | 11 | # Prints help. 12 | #eval $CMFT --help 13 | 14 | # Use this to list available OpenCL devices that can be used with cmft for processing. 15 | #eval $CMFT --printCLDevices 16 | 17 | # Typical parameters for irradiance filter. 18 | #eval $CMFT $@ --input "okretnica.tga" \ 19 | # --filter irradiance \ 20 | # --srcFaceSize 0 \ 21 | # --dstFaceSize 0 \ 22 | # --outputNum 1 \ 23 | # --output0 "okretnica_irr" \ 24 | # --output0params dds,bgra8,cubemap 25 | 26 | # Typical parameters for generating spherical harmonics coefficients. 27 | #eval $CMFT $@ --input "okretnica.tga" \ 28 | # --filter shcoeffs \ 29 | # --outputNum 1 \ 30 | # --output0 "okretnica" 31 | 32 | # Typical parameters for radiance filter. 33 | eval $CMFT $@ --input "okretnica.tga" \ 34 | ::Filter options \ 35 | --filter radiance \ 36 | --srcFaceSize 256 \ 37 | --excludeBase false \ 38 | --mipCount 7 \ 39 | --glossScale 10 \ 40 | --glossBias 3 \ 41 | --lightingModel blinnbrdf \ 42 | --edgeFixup none \ 43 | --dstFaceSize 256 \ 44 | ::Processing devices \ 45 | --numCpuProcessingThreads 4 \ 46 | --useOpenCL true \ 47 | --clVendor anyGpuVendor \ 48 | --deviceType gpu \ 49 | --deviceIndex 0 \ 50 | ::Aditional operations \ 51 | --inputGammaNumerator 2.2 \ 52 | --inputGammaDenominator 1.0 \ 53 | --outputGammaNumerator 1.0 \ 54 | --outputGammaDenominator 2.2 \ 55 | --generateMipChain false \ 56 | ::Output \ 57 | --outputNum 2 \ 58 | --output0 "okretnica_pmrem" \ 59 | --output0params dds,bgra8,cubemap \ 60 | --output1 "okretnica_pmrem" \ 61 | --output1params ktx,rgba8,cubemap 62 | 63 | # Cmft can also be run without any processing filter. This can be used for performing image manipulations or exporting different image format. 64 | #eval $CMFT $@ --input "okretnica.tga" \ 65 | # --filter none \ 66 | # ::Aditional operations \ 67 | # --inputGamma 1.0 \ 68 | # --inputGammaDenominator 1.0 \ 69 | # --outputGamma 1.0 \ 70 | # --outputGammaDenominator 1.0 \ 71 | # --generateMipChain true \ 72 | # ::Cubemap transformations \ 73 | # --posXrotate90 \ 74 | # --posXrotate180 \ 75 | # --posXrotate270 \ 76 | # --posXflipH \ 77 | # --posXflipV \ 78 | # --negXrotate90 \ 79 | # --negXrotate180 \ 80 | # --negXrotate270 \ 81 | # --negXflipH \ 82 | # --negXflipV \ 83 | # --posYrotate90 \ 84 | # --posYrotate180 \ 85 | # --posYrotate270 \ 86 | # --posYflipH \ 87 | # --posYflipV \ 88 | # --negYrotate90 \ 89 | # --negYrotate180 \ 90 | # --negYrotate270 \ 91 | # --negYflipH \ 92 | # --negYflipV \ 93 | # --posZrotate90 \ 94 | # --posZrotate180 \ 95 | # --posZrotate270 \ 96 | # --posZflipH \ 97 | # --posZflipV \ 98 | # --negZrotate90 \ 99 | # --negZrotate180 \ 100 | # --negZrotate270 \ 101 | # --negZflipH \ 102 | # --negZflipV \ 103 | # ::Output \ 104 | # --outputNum 1 \ 105 | # --output0 "okretnica_dds" \ 106 | # --output0params dds,bgra8,cubemap \ 107 | 108 | # Cmft with all parameters listed. This is mainly to have a look at what is all possible. 109 | #eval $CMFT $@ --input "okretnica.tga" \ 110 | # ::Filter options \ 111 | # --filter radiance \ 112 | # --srcFaceSize 256 \ 113 | # --excludeBase false \ 114 | # --mipCount 7 \ 115 | # --glossScale 10 \ 116 | # --glossBias 3 \ 117 | # --lightingModel blinnbrdf \ 118 | # --edgeFixup none \ 119 | # --dstFaceSize 256 \ 120 | # ::Processing devices \ 121 | # --numCpuProcessingThreads 4 \ 122 | # --useOpenCL true \ 123 | # --clVendor anyGpuVendor \ 124 | # --deviceType gpu \ 125 | # --deviceIndex 0 \ 126 | # ::Aditional operations \ 127 | # --inputGamma 1.0 \ 128 | # --inputGammaDenominator 1.0 \ 129 | # --outputGamma 1.0 \ 130 | # --outputGammaDenominator 1.0 \ 131 | # --generateMipChain false \ 132 | # ::Cubemap transformations \ 133 | # --posXrotate90 \ 134 | # --posXrotate180 \ 135 | # --posXrotate270 \ 136 | # --posXflipH \ 137 | # --posXflipV \ 138 | # --negXrotate90 \ 139 | # --negXrotate180 \ 140 | # --negXrotate270 \ 141 | # --negXflipH \ 142 | # --negXflipV \ 143 | # --posYrotate90 \ 144 | # --posYrotate180 \ 145 | # --posYrotate270 \ 146 | # --posYflipH \ 147 | # --posYflipV \ 148 | # --negYrotate90 \ 149 | # --negYrotate180 \ 150 | # --negYrotate270 \ 151 | # --negYflipH \ 152 | # --negYflipV \ 153 | # --posZrotate90 \ 154 | # --posZrotate180 \ 155 | # --posZrotate270 \ 156 | # --posZflipH \ 157 | # --posZflipV \ 158 | # --negZrotate90 \ 159 | # --negZrotate180 \ 160 | # --negZrotate270 \ 161 | # --negZflipH \ 162 | # --negZflipV \ 163 | # ::Output \ 164 | # --outputNum 5 \ 165 | # --output0 "cmft_cubemap" --output0params dds,bgra8,cubemap \ 166 | # --output1 "cmft_hstrip" --output1params dds,bgra8,hstrip \ 167 | # --output2 "cmft_cubecross" --output2params ktx,rgba32f,hcross \ 168 | # --output3 "cmft_facelist" --output3params tga,bgra8,facelist \ 169 | # --output4 "cmft_latlong" --output4params hdr,rgbe,latlong 170 | -------------------------------------------------------------------------------- /runtime/cmft_win.bat: -------------------------------------------------------------------------------- 1 | :: 2 | :: Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | :: License: http://www.opensource.org/licenses/BSD-2-Clause 4 | :: 5 | 6 | @echo off 7 | SET cmft="./../_build/win64_vs2012/bin/cmftRelease.exe" 8 | 9 | :: Prints help. 10 | REM %cmft% --help 11 | 12 | :: Use this to list available OpenCL devices that can be used with cmft for processing. 13 | ::%cmft% --printCLDevices 14 | 15 | ::Typical parameters for irradiance filter. 16 | REM %cmft% %* --input "okretnica.tga" ^ 17 | REM --filter irradiance ^ 18 | REM --srcFaceSize 0 ^ 19 | REM --dstFaceSize 0 ^ 20 | REM --outputNum 1 ^ 21 | REM --output0 "okretnica_irr" ^ 22 | REM --output0params dds,bgra8,cubemap 23 | 24 | :: Typical parameters for generating spherical harmonics coefficients. 25 | REM %cmft% %* --input "okretnica.tga" ^ 26 | REM --filter shcoeffs ^ 27 | REM --outputNum 1 ^ 28 | REM --output0 "okretnica" 29 | 30 | :: Typical parameters for radiance filter. 31 | %cmft% %* --input "okretnica.tga" ^ 32 | ::Filter options ^ 33 | --filter radiance ^ 34 | --srcFaceSize 256 ^ 35 | --excludeBase false ^ 36 | --mipCount 7 ^ 37 | --glossScale 10 ^ 38 | --glossBias 3 ^ 39 | --lightingModel blinnbrdf ^ 40 | --edgeFixup none ^ 41 | --dstFaceSize 256 ^ 42 | ::Processing devices ^ 43 | --numCpuProcessingThreads 4 ^ 44 | --useOpenCL true ^ 45 | --clVendor anyGpuVendor ^ 46 | --deviceType gpu ^ 47 | --deviceIndex 0 ^ 48 | ::Aditional operations ^ 49 | --inputGammaNumerator 2.2 ^ 50 | --inputGammaDenominator 1.0 ^ 51 | --outputGammaNumerator 1.0 ^ 52 | --outputGammaDenominator 2.2 ^ 53 | --generateMipChain false ^ 54 | ::Output ^ 55 | --outputNum 2 ^ 56 | --output0 "okretnica_pmrem" ^ 57 | --output0params dds,bgra8,cubemap ^ 58 | --output1 "okretnica_pmrem" ^ 59 | --output1params ktx,rgba8,cubemap 60 | 61 | :: Cmft can also be run without any processing filter. This can be used for performing image manipulations or exporting different image format. 62 | REM %cmft% %* --input "okretnica.tga" ^ 63 | REM --filter none ^ 64 | REM ::Aditional operations ^ 65 | REM --inputGamma 1.0 ^ 66 | REM --inputGammaDenominator 1.0 ^ 67 | REM --outputGamma 1.0 ^ 68 | REM --outputGammaDenominator 1.0 ^ 69 | REM --generateMipChain true ^ 70 | REM ::Cubemap transformations ^ 71 | REM --posXrotate90 ^ 72 | REM --posXrotate180 ^ 73 | REM --posXrotate270 ^ 74 | REM --posXflipH ^ 75 | REM --posXflipV ^ 76 | REM --negXrotate90 ^ 77 | REM --negXrotate180 ^ 78 | REM --negXrotate270 ^ 79 | REM --negXflipH ^ 80 | REM --negXflipV ^ 81 | REM --posYrotate90 ^ 82 | REM --posYrotate180 ^ 83 | REM --posYrotate270 ^ 84 | REM --posYflipH ^ 85 | REM --posYflipV ^ 86 | REM --negYrotate90 ^ 87 | REM --negYrotate180 ^ 88 | REM --negYrotate270 ^ 89 | REM --negYflipH ^ 90 | REM --negYflipV ^ 91 | REM --posZrotate90 ^ 92 | REM --posZrotate180 ^ 93 | REM --posZrotate270 ^ 94 | REM --posZflipH ^ 95 | REM --posZflipV ^ 96 | REM --negZrotate90 ^ 97 | REM --negZrotate180 ^ 98 | REM --negZrotate270 ^ 99 | REM --negZflipH ^ 100 | REM --negZflipV ^ 101 | REM ::Output ^ 102 | REM --outputNum 1 ^ 103 | REM --output0 "okretnica_dds" ^ 104 | REM --output0params dds,bgra8,cubemap ^ 105 | 106 | :: Cmft with all parameters listed. This is mainly to have a look at what is all possible. 107 | REM %cmft% %* --inputFacePosX "okretnica_posx.tga" ^ 108 | REM --inputFaceNegX "okretnica_negx.tga" ^ 109 | REM --inputFacePosY "okretnica_posy.tga" ^ 110 | REM --inputFaceNegY "okretnica_negy.tga" ^ 111 | REM --inputFacePosZ "okretnica_posz.tga" ^ 112 | REM --inputFaceNegZ "okretnica_negz.tga" ^ 113 | REM ::Filter options ^ 114 | REM --filter radiance ^ 115 | REM --srcFaceSize 256 ^ 116 | REM --excludeBase false ^ 117 | REM --mipCount 7 ^ 118 | REM --glossScale 10 ^ 119 | REM --glossBias 3 ^ 120 | REM --lightingModel blinnbrdf ^ 121 | REM --edgeFixup none ^ 122 | REM --dstFaceSize 256 ^ 123 | REM ::Processing devices ^ 124 | REM --numCpuProcessingThreads 4 ^ 125 | REM --useOpenCL true ^ 126 | REM --clVendor anyGpuVendor ^ 127 | REM --deviceType gpu ^ 128 | REM --deviceIndex 0 ^ 129 | REM ::Aditional operations ^ 130 | REM --inputGamma 1.0 ^ 131 | REM --inputGammaDenominator 1.0 ^ 132 | REM --outputGamma 1.0 ^ 133 | REM --outputGammaDenominator 1.0 ^ 134 | REM --generateMipChain false ^ 135 | REM ::Cubemap transformations ^ 136 | REM --posXrotate90 ^ 137 | REM --posXrotate180 ^ 138 | REM --posXrotate270 ^ 139 | REM --posXflipH ^ 140 | REM --posXflipV ^ 141 | REM --negXrotate90 ^ 142 | REM --negXrotate180 ^ 143 | REM --negXrotate270 ^ 144 | REM --negXflipH ^ 145 | REM --negXflipV ^ 146 | REM --posYrotate90 ^ 147 | REM --posYrotate180 ^ 148 | REM --posYrotate270 ^ 149 | REM --posYflipH ^ 150 | REM --posYflipV ^ 151 | REM --negYrotate90 ^ 152 | REM --negYrotate180 ^ 153 | REM --negYrotate270 ^ 154 | REM --negYflipH ^ 155 | REM --negYflipV ^ 156 | REM --posZrotate90 ^ 157 | REM --posZrotate180 ^ 158 | REM --posZrotate270 ^ 159 | REM --posZflipH ^ 160 | REM --posZflipV ^ 161 | REM --negZrotate90 ^ 162 | REM --negZrotate180 ^ 163 | REM --negZrotate270 ^ 164 | REM --negZflipH ^ 165 | REM --negZflipV ^ 166 | REM ::Output ^ 167 | REM --outputNum 5 ^ 168 | REM --output0 "cmft_cubemap" --output0params dds,bgra8,cubemap ^ 169 | REM --output1 "cmft_hstrip" --output1params dds,bgra8,hstrip ^ 170 | REM --output2 "cmft_cubecross" --output2params ktx,rgba32f,hcross ^ 171 | REM --output3 "cmft_facelist" --output3params tga,bgra8,facelist ^ 172 | REM --output4 "cmft_latlong" --output4params hdr,rgbe,latlong ^ 173 | REM ::Misc ^ 174 | REM --silent 175 | -------------------------------------------------------------------------------- /runtime/okretnica.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dariomanesku/cmft/cad5f31bac66fd05987d667af62311c444df6d46/runtime/okretnica.tga -------------------------------------------------------------------------------- /scripts/cmft.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | -- License: http://www.opensource.org/licenses/BSD-2-Clause 4 | -- 5 | 6 | function cmftProject(_cmftDir) 7 | 8 | local CMFT_INCLUDE_DIR = (_cmftDir .. "include/") 9 | local CMFT_SRC_DIR = (_cmftDir .. "src/cmft/") 10 | local CMFT_DEPENDENCY_DIR = (_cmftDir .. "dependency/") 11 | 12 | project "cmft" 13 | uuid("0809b9fb-eaf6-4e80-9d80-7b490e29f212") 14 | kind "StaticLib" 15 | 16 | configuration { "linux-*" } 17 | links 18 | { 19 | "dl", 20 | "pthread", 21 | } 22 | 23 | configuration { "vs*" } 24 | buildoptions 25 | { 26 | "/wd 4127" -- disable 'conditional expression is constant' for do {} while(0) 27 | } 28 | 29 | configuration {} 30 | 31 | files 32 | { 33 | CMFT_SRC_DIR .. "**.h", 34 | CMFT_SRC_DIR .. "**.cpp", 35 | CMFT_SRC_DIR .. "**/**.h", 36 | CMFT_SRC_DIR .. "**/**.cpp", 37 | 38 | CMFT_INCLUDE_DIR .. "**.h", 39 | } 40 | 41 | includedirs 42 | { 43 | CMFT_DEPENDENCY_DIR, 44 | CMFT_INCLUDE_DIR, 45 | CMFT_SRC_DIR, 46 | } 47 | 48 | end -- cmftProject 49 | 50 | -- vim: set sw=4 ts=4 expandtab: 51 | -------------------------------------------------------------------------------- /scripts/cmft_cli.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | -- License: http://www.opensource.org/licenses/BSD-2-Clause 4 | -- 5 | 6 | function cmftCliProject(_cmftDir) 7 | 8 | local CMFT_INCLUDE_DIR = (_cmftDir .. "include/") 9 | local CMFT_SRC_DIR = (_cmftDir .. "src/cmft/") 10 | local CMFT_CLI_SRC_DIR = (_cmftDir .. "src/") 11 | local CMFT_RUNTIME_DIR = (_cmftDir .. "runtime/") 12 | local CMFT_DEPENDENCY_DIR = (_cmftDir .. "dependency/") 13 | 14 | project "cmft_cli" 15 | uuid("52267a12-34bf-4834-8245-2bead0100dc8") 16 | kind "ConsoleApp" 17 | 18 | targetname ("cmft") 19 | 20 | configuration { "linux-*" } 21 | links 22 | { 23 | "dl", 24 | "pthread", 25 | } 26 | 27 | configuration { "vs*" } 28 | buildoptions 29 | { 30 | "/wd 4127" -- disable 'conditional expression is constant' for do {} while(0) 31 | } 32 | 33 | configuration {} 34 | 35 | debugdir (CMFT_RUNTIME_DIR) 36 | 37 | files 38 | { 39 | CMFT_SRC_DIR .. "**.h", 40 | CMFT_SRC_DIR .. "**.cpp", 41 | CMFT_SRC_DIR .. "**/**.h", 42 | CMFT_SRC_DIR .. "**/**.cpp", 43 | 44 | CMFT_CLI_SRC_DIR .. "**.h", 45 | CMFT_CLI_SRC_DIR .. "**.cpp", 46 | 47 | CMFT_INCLUDE_DIR .. "**.h", 48 | } 49 | 50 | includedirs 51 | { 52 | CMFT_DEPENDENCY_DIR, 53 | CMFT_SRC_DIR, 54 | CMFT_CLI_SRC_DIR, 55 | CMFT_INCLUDE_DIR, 56 | } 57 | 58 | end -- cmftCliProject 59 | 60 | -- vim: set sw=4 ts=4 expandtab: 61 | -------------------------------------------------------------------------------- /scripts/main.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- Copyright 2014-2015 Dario Manesku. All rights reserved. 3 | -- License: http://www.opensource.org/licenses/BSD-2-Clause 4 | -- 5 | 6 | local CMFT_DIR = (path.getabsolute("..") .. "/") 7 | local DEPENDENCY_DIR = (CMFT_DIR .. "dependency/") 8 | 9 | local BX_DIR = (DEPENDENCY_DIR .. "bx/") 10 | local DM_DIR = (DEPENDENCY_DIR .. "dm/") 11 | 12 | local CMFT_BUILD_DIR = (CMFT_DIR .. "_build/") 13 | local CMFT_PROJECTS_DIR = (CMFT_DIR .. "_projects/") 14 | 15 | local DM_SCRIPTS_DIR = (DM_DIR .. "scripts/") 16 | 17 | -- 18 | -- Solution. 19 | -- 20 | solution "cmft" 21 | language "C++" 22 | configurations { "Debug", "Release" } 23 | platforms { "x32", "x64" } 24 | 25 | -- Toolchain. 26 | dofile "toolchain.lua" 27 | cmft_toolchain(CMFT_BUILD_DIR, CMFT_PROJECTS_DIR, DEPENDENCY_DIR, BX_DIR) 28 | 29 | -- cmft_cli project. 30 | dofile "cmft_cli.lua" 31 | cmftCliProject(CMFT_DIR) 32 | 33 | -- cmft project. 34 | dofile "cmft.lua" 35 | cmftProject(CMFT_DIR) 36 | 37 | strip() 38 | 39 | -- vim: set sw=4 ts=4 expandtab: 40 | -------------------------------------------------------------------------------- /src/cmft/allocator.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 | 8 | namespace cmft 9 | { 10 | CrtAllocator g_crtAllocator; 11 | CrtStackAllocator g_crtStackAllocator; 12 | 13 | AllocatorI* g_allocator = &g_crtAllocator; 14 | StackAllocatorI* g_stackAllocator = &g_crtStackAllocator; 15 | 16 | void setAllocator(AllocatorI* _allocator) 17 | { 18 | g_allocator = (NULL != _allocator) ? _allocator : &g_crtAllocator; 19 | } 20 | 21 | void setStackAllocator(StackAllocatorI* _stackAllocator) 22 | { 23 | g_stackAllocator = (NULL != _stackAllocator) ? _stackAllocator : &g_crtStackAllocator; 24 | } 25 | 26 | } // namespace cmft 27 | 28 | /* vim: set sw=4 ts=4 expandtab: */ 29 | -------------------------------------------------------------------------------- /src/cmft/clcontext.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2016 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #define CMFT_CL_IMPLEMENTATION 7 | #include "common/cl.h" 8 | 9 | #include 10 | #include "clcontext_internal.h" 11 | 12 | #include 13 | 14 | #include "common/config.h" 15 | #include "common/utils.h" 16 | #include "common/handlealloc.h" 17 | 18 | namespace cmft 19 | { 20 | struct ClContextStorage 21 | { 22 | ClContext* alloc() 23 | { 24 | return &m_context[m_handleAlloc.alloc()]; 25 | } 26 | 27 | void free(ClContext* _context) 28 | { 29 | if (&m_context[0] <= _context && _context <= &m_context[MaxClContexts]) 30 | { 31 | uint32_t idx = uint32_t(_context - m_context); 32 | if (m_handleAlloc.contains(idx)) 33 | { 34 | m_handleAlloc.free(idx); 35 | } 36 | } 37 | } 38 | 39 | enum { MaxClContexts = 1024 }; 40 | 41 | HandleAllocT m_handleAlloc; 42 | ClContext m_context[MaxClContexts]; 43 | }; 44 | static ClContextStorage s_clContextStorage; 45 | 46 | ClContext* clInit(uint32_t _vendor 47 | , uint32_t _preferredDeviceType 48 | , uint32_t _preferredDeviceIdx 49 | , const char* _vendorStrPart 50 | ) 51 | { 52 | cl_int err = CL_SUCCESS; 53 | 54 | // Enumerate platforms. 55 | cl_platform_id platforms[8]; 56 | cl_uint numPlatforms; 57 | CL_CHECK(clGetPlatformIDs(8, platforms, &numPlatforms)); 58 | 59 | // Choose preferred platform. 60 | cl_platform_id choosenPlatform = platforms[0]; 61 | if (NULL != _vendorStrPart) 62 | { 63 | char buffer[256]; 64 | for (cl_uint ii = 0; ii < numPlatforms; ++ii) 65 | { 66 | // Get platform vendor. 67 | CL_CHECK(clGetPlatformInfo(platforms[ii], CL_PLATFORM_VENDOR, 256, buffer, NULL)); 68 | 69 | if (_vendor&CMFT_CL_VENDOR_OTHER) 70 | { 71 | // If specific vendor is requested, check for it. 72 | const char* searchSpecific = cmft::stristr(buffer, _vendorStrPart, 256); 73 | if (NULL != searchSpecific) 74 | { 75 | choosenPlatform = platforms[ii]; 76 | break; 77 | } 78 | } 79 | else 80 | { 81 | bool found = false; 82 | 83 | // Check for predefined vendors. 84 | if (_vendor&CMFT_CL_VENDOR_AMD) 85 | { 86 | const char* searchAmd = cmft::stristr(buffer, "advanced micro devices", 256); 87 | found |= (NULL != searchAmd); 88 | } 89 | 90 | if (_vendor&CMFT_CL_VENDOR_INTEL) 91 | { 92 | const char* searchIntel = cmft::stristr(buffer, "intel", 256); 93 | found |= (NULL != searchIntel); 94 | } 95 | 96 | if (_vendor&CMFT_CL_VENDOR_NVIDIA) 97 | { 98 | const char* searchNvidia = cmft::stristr(buffer, "nvidia", 256); 99 | found |= (NULL != searchNvidia); 100 | } 101 | 102 | if (found) 103 | { 104 | choosenPlatform = platforms[ii]; 105 | break; 106 | } 107 | } 108 | } 109 | } 110 | 111 | // Enumerate devices. 112 | cl_device_id devices[8] = { 0 }; 113 | cl_uint numDevices = 0; 114 | 115 | // First try to get preferred device type. 116 | for (cl_uint ii = 0; ii < numPlatforms; ++ii) 117 | { 118 | err = clGetDeviceIDs(platforms[ii], (cl_device_type)_preferredDeviceType, 8, devices, &numDevices); 119 | if (CL_SUCCESS == err) 120 | { 121 | choosenPlatform = platforms[ii]; 122 | break; 123 | } 124 | } 125 | 126 | // If failed, just get anything there is. 127 | if (CL_SUCCESS != err) 128 | { 129 | for (cl_uint ii = 0; ii < numPlatforms; ++ii) 130 | { 131 | err = clGetDeviceIDs(platforms[ii], CL_DEVICE_TYPE_ALL, 8, devices, &numDevices); 132 | if (CL_SUCCESS == err) 133 | { 134 | choosenPlatform = platforms[ii]; 135 | break; 136 | } 137 | } 138 | } 139 | 140 | if (CL_SUCCESS != err) 141 | { 142 | WARN("OpenCL context initialization failed!"); 143 | return NULL; 144 | } 145 | 146 | // Choose preferred device and create context. 147 | cl_uint preferredDeviceIdx = (_preferredDeviceIdx < numDevices) ? _preferredDeviceIdx : 0; 148 | cl_device_id chosenDevice = devices[preferredDeviceIdx]; 149 | cl_context context = clCreateContext(NULL, 1, &chosenDevice, NULL, NULL, &err); 150 | if (CL_SUCCESS != err) 151 | { 152 | chosenDevice = devices[0]; 153 | context = clCreateContext(NULL, 1, &chosenDevice, NULL, NULL, &err); 154 | if (CL_SUCCESS != err) 155 | { 156 | WARN("OpenCL context initialization failed!"); 157 | return NULL; 158 | } 159 | } 160 | 161 | // Create command queue 162 | cl_command_queue commandQueue; 163 | commandQueue = clCreateCommandQueue(context, chosenDevice, 0, &err); 164 | if (CL_SUCCESS != err) 165 | { 166 | WARN("OpenCL context initialization failed!"); 167 | return NULL; 168 | } 169 | 170 | ClContext* clContext = s_clContextStorage.alloc(); 171 | 172 | // Get device name, vendor and type. 173 | char deviceVendor[128]; 174 | CL_CHECK(clGetPlatformInfo(choosenPlatform, CL_PLATFORM_VENDOR, sizeof(deviceVendor), deviceVendor, NULL)); 175 | char deviceName[128]; 176 | CL_CHECK(clGetDeviceInfo(chosenDevice, CL_DEVICE_NAME, sizeof(deviceName), deviceName, NULL)); 177 | CL_CHECK(clGetDeviceInfo(chosenDevice, CL_DEVICE_TYPE, sizeof(clContext->m_deviceType), &clContext->m_deviceType, NULL)); 178 | 179 | // Fill structure. 180 | cmft::stracpy(clContext->m_deviceVendor, cmft::trim(deviceVendor)); 181 | cmft::stracpy(clContext->m_deviceName, cmft::trim(deviceName)); 182 | clContext->m_device = chosenDevice; 183 | clContext->m_context = context; 184 | clContext->m_commandQueue = commandQueue; 185 | 186 | return clContext; 187 | } 188 | 189 | void clPrintDevices() 190 | { 191 | cl_int err; 192 | 193 | // Enumerate platforms. 194 | cl_platform_id platforms[8]; 195 | cl_uint numPlatforms; 196 | CL_CHECK(clGetPlatformIDs(8, platforms, &numPlatforms)); 197 | 198 | for (cl_uint ii = 0; ii < numPlatforms; ++ii) 199 | { 200 | // Get platform vendor. 201 | char vendor[256]; 202 | CL_CHECK(clGetPlatformInfo(platforms[ii], CL_PLATFORM_VENDOR, 256, vendor, NULL)); 203 | 204 | // Check for known vendors and save vendor str for later printing. 205 | char platformOutputStr[32]; 206 | if (NULL != cmft::stristr(vendor, "advanced micro devices", 256)) 207 | { 208 | cmft::stracpy(platformOutputStr, "amd"); 209 | } 210 | else if (NULL != cmft::stristr(vendor, "intel", 256)) 211 | { 212 | cmft::stracpy(platformOutputStr, "intel"); 213 | } 214 | else if (NULL != cmft::stristr(vendor, "nvidia", 256)) 215 | { 216 | cmft::stracpy(platformOutputStr, "nvidia"); 217 | } 218 | else 219 | { 220 | cmft::stracpy(platformOutputStr, cmft::trim(vendor)); 221 | } 222 | 223 | // Enumerate current platform devices. 224 | cl_device_id devices[8]; 225 | cl_uint numDevices; 226 | err = clGetDeviceIDs(platforms[ii], CL_DEVICE_TYPE_ALL, 8, devices, &numDevices); 227 | if (CL_SUCCESS == err) 228 | { 229 | for (cl_uint jj = 0; jj < numDevices; ++jj) 230 | { 231 | // Get device name. 232 | char deviceName[128]; 233 | CL_CHECK(clGetDeviceInfo(devices[jj], CL_DEVICE_NAME, sizeof(deviceName), deviceName, NULL)); 234 | 235 | // Get device type. 236 | cl_device_type deviceType; 237 | CL_CHECK(clGetDeviceInfo(devices[jj], CL_DEVICE_TYPE, sizeof(deviceType), &deviceType, NULL)); 238 | 239 | // Get device type str. 240 | char deviceTypeOutputStr[16]; 241 | if (CMFT_CL_DEVICE_TYPE_GPU == deviceType) 242 | { 243 | cmft::stracpy(deviceTypeOutputStr, "gpu"); 244 | } 245 | else if (CMFT_CL_DEVICE_TYPE_CPU == deviceType) 246 | { 247 | cmft::stracpy(deviceTypeOutputStr, "cpu"); 248 | } 249 | else if (CMFT_CL_DEVICE_TYPE_ACCELERATOR == deviceType) 250 | { 251 | cmft::stracpy(deviceTypeOutputStr, "accelerator"); 252 | } 253 | else //if (CMFT_CL_DEVICE_TYPE_DEFAULT == deviceType) 254 | { 255 | cmft::stracpy(deviceTypeOutputStr, "default"); 256 | } 257 | 258 | // Print device info. 259 | INFO("%-40s --clVendor %-6s --deviceIndex %u --deviceType %s" 260 | , cmft::trim(deviceName) 261 | , platformOutputStr 262 | , uint32_t(jj) 263 | , deviceTypeOutputStr 264 | ); 265 | } 266 | } 267 | } 268 | } 269 | 270 | void clDestroy(ClContext* _clContext) 271 | { 272 | if (NULL == _clContext) 273 | { 274 | return; 275 | } 276 | 277 | if (NULL != _clContext->m_commandQueue) 278 | { 279 | clReleaseCommandQueue(_clContext->m_commandQueue); 280 | _clContext->m_commandQueue = NULL; 281 | } 282 | 283 | if (NULL != _clContext->m_context) 284 | { 285 | clReleaseContext(_clContext->m_context); 286 | _clContext->m_context = NULL; 287 | } 288 | 289 | s_clContextStorage.free(_clContext); 290 | } 291 | 292 | } // namespace cmft 293 | 294 | /* vim: set sw=4 ts=4 expandtab: */ 295 | -------------------------------------------------------------------------------- /src/cmft/clcontext_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFT_CLCONTEXT_INTERNAL_H_HEADER_GUARD 7 | #define CMFT_CLCONTEXT_INTERNAL_H_HEADER_GUARD 8 | 9 | #include "common/cl.h" 10 | 11 | namespace cmft 12 | { 13 | struct ClContext 14 | { 15 | ClContext() 16 | { 17 | m_device = NULL; 18 | m_context = NULL; 19 | m_commandQueue = NULL; 20 | m_deviceVendor[0] = '\0'; 21 | m_deviceName[0] = '\0'; 22 | } 23 | 24 | cl_device_id m_device; 25 | cl_context m_context; 26 | cl_command_queue m_commandQueue; 27 | cl_device_type m_deviceType; 28 | char m_deviceVendor[128]; 29 | char m_deviceName[128]; 30 | }; 31 | 32 | } // namespace cmft 33 | 34 | #endif //CMFT_CLCONTEXT_INTERNAL_H_HEADER_GUARD 35 | 36 | /* vim: set sw=4 ts=4 expandtab: */ 37 | 38 | -------------------------------------------------------------------------------- /src/cmft/common/commandline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFT_COMMANDLINE_H_HEADER_GUARD 7 | #define CMFT_COMMANDLINE_H_HEADER_GUARD 8 | 9 | namespace cmft 10 | { 11 | /* 12 | * Adapted from: https://github.com/bkaradzic/bx/include/bx/commandline.h 13 | * 14 | * Copyright 2010-2016 Branimir Karadzic. All rights reserved. 15 | * License: https://github.com/bkaradzic/bx#license-bsd-2-clause 16 | */ 17 | 18 | struct CommandLine 19 | { 20 | CommandLine(int _argc, char const* const* _argv) 21 | : m_argc(_argc) 22 | , m_argv(_argv) 23 | { 24 | } 25 | 26 | const char* findOption(const char* _long, const char* _default) const 27 | { 28 | const char* result = find(0, '\0', _long, 1); 29 | return result == NULL ? _default : result; 30 | } 31 | 32 | const char* findOption(const char _short, const char* _long, const char* _default) const 33 | { 34 | const char* result = find(0, _short, _long, 1); 35 | return result == NULL ? _default : result; 36 | } 37 | 38 | const char* findOption(const char* _long, int _numParams = 1) const 39 | { 40 | const char* result = find(0, '\0', _long, _numParams); 41 | return result; 42 | } 43 | 44 | const char* findOption(const char _short, const char* _long = NULL, int _numParams = 1) const 45 | { 46 | const char* result = find(0, _short, _long, _numParams); 47 | return result; 48 | } 49 | 50 | const char* findOption(int _skip, const char _short, const char* _long = NULL, int _numParams = 1) const 51 | { 52 | const char* result = find(_skip, _short, _long, _numParams); 53 | return result; 54 | } 55 | 56 | bool hasArg(const char _short, const char* _long = NULL) const 57 | { 58 | const char* arg = findOption(_short, _long, 0); 59 | return NULL != arg; 60 | } 61 | 62 | bool hasArg(const char* _long) const 63 | { 64 | const char* arg = findOption('\0', _long, 0); 65 | return NULL != arg; 66 | } 67 | 68 | bool hasArg(const char*& _value, const char _short, const char* _long = NULL) const 69 | { 70 | const char* arg = findOption(_short, _long, 1); 71 | _value = arg; 72 | return NULL != arg; 73 | } 74 | 75 | bool hasArg(int& _value, const char _short, const char* _long = NULL) const 76 | { 77 | const char* arg = findOption(_short, _long, 1); 78 | if (NULL != arg) 79 | { 80 | _value = atoi(arg); 81 | return true; 82 | } 83 | 84 | return false; 85 | } 86 | 87 | bool hasArg(unsigned int& _value, const char _short, const char* _long = NULL) const 88 | { 89 | const char* arg = findOption(_short, _long, 1); 90 | if (NULL != arg) 91 | { 92 | _value = atoi(arg); 93 | return true; 94 | } 95 | 96 | return false; 97 | } 98 | 99 | bool hasArg(float& _value, const char _short, const char* _long = NULL) const 100 | { 101 | const char* arg = findOption(_short, _long, 1); 102 | if (NULL != arg) 103 | { 104 | _value = float(atof(arg)); 105 | return true; 106 | } 107 | 108 | return false; 109 | } 110 | 111 | bool hasArg(double& _value, const char _short, const char* _long = NULL) const 112 | { 113 | const char* arg = findOption(_short, _long, 1); 114 | if (NULL != arg) 115 | { 116 | _value = atof(arg); 117 | return true; 118 | } 119 | 120 | return false; 121 | } 122 | 123 | bool hasArg(bool& _value, const char _short, const char* _long = NULL) const 124 | { 125 | const char* arg = findOption(_short, _long, 1); 126 | if (NULL != arg) 127 | { 128 | if ('0' == *arg || (0 == stricmp(arg, "false") ) ) 129 | { 130 | _value = false; 131 | } 132 | else if ('0' != *arg || (0 == stricmp(arg, "true") ) ) 133 | { 134 | _value = true; 135 | } 136 | 137 | return true; 138 | } 139 | 140 | return false; 141 | } 142 | 143 | private: 144 | const char* find(int _skip, const char _short, const char* _long, int _numParams) const 145 | { 146 | for (int ii = 0; ii < m_argc; ++ii) 147 | { 148 | const char* arg = m_argv[ii]; 149 | if ('-' == *arg) 150 | { 151 | ++arg; 152 | if (_short == *arg) 153 | { 154 | if (1 == strlen(arg) ) 155 | { 156 | if (0 == _skip) 157 | { 158 | if (0 == _numParams) 159 | { 160 | return ""; 161 | } 162 | else if (ii+_numParams < m_argc 163 | && '-' != *m_argv[ii+1] ) 164 | { 165 | return m_argv[ii+1]; 166 | } 167 | 168 | return NULL; 169 | } 170 | 171 | --_skip; 172 | ii += _numParams; 173 | } 174 | } 175 | else if (NULL != _long 176 | && '-' == *arg 177 | && 0 == stricmp(arg+1, _long) ) 178 | { 179 | if (0 == _skip) 180 | { 181 | if (0 == _numParams) 182 | { 183 | return ""; 184 | } 185 | else if (ii+_numParams < m_argc 186 | && '-' != *m_argv[ii+1] ) 187 | { 188 | return m_argv[ii+1]; 189 | } 190 | 191 | return NULL; 192 | } 193 | 194 | --_skip; 195 | ii += _numParams; 196 | } 197 | } 198 | } 199 | 200 | return NULL; 201 | } 202 | 203 | int m_argc; 204 | char const* const* m_argv; 205 | }; 206 | } 207 | 208 | #endif // CMFT_COMMANDLINE_H_HEADER_GUARD 209 | 210 | /* vim: set sw=4 ts=4 expandtab: */ 211 | -------------------------------------------------------------------------------- /src/cmft/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 CMFT_CONFIG_H_HEADER_GUARD 7 | #define CMFT_CONFIG_H_HEADER_GUARD 8 | 9 | #include //abort() 10 | #include //stderr 11 | #include // PrintFunc 12 | 13 | // Config. 14 | //----- 15 | 16 | // This flags can also be specified in the build tool by defining CMFT_CUSTOM_CONFIG. 17 | #ifndef CMFT_CUSTOM_CONFIG 18 | // Output messages. 19 | #define CMFT_ENABLE_INFO_MESSAGES 1 20 | #define CMFT_ENABLE_WARNINGS 1 21 | #define CMFT_ENABLE_PROGRESS_REPORT 0 22 | 23 | // Flush output. 24 | #define CMFT_ALWAYS_FLUSH_OUTPUT 0 25 | 26 | // Checks. 27 | #define CMFT_ENABLE_CL_CHECK 0 28 | #define CMFT_ENABLE_DEBUG_CHECK 0 29 | #define CMFT_ENABLE_FILE_ERROR_CHECK 0 30 | #define CMFT_ENABLE_MEMORY_ALLOC_CHECK 0 31 | #endif // CMFT_CUSTOM_CONFIG 32 | 33 | // When CMFT_TEST_BUILD is 0, 'src/cmft_cli/cmft_cli.h' gets executed. 34 | // When CMFT_TEST_BUILD is 1, 'src/tests/test.h' gets executed. 35 | #define CMFT_TEST_BUILD 0 36 | 37 | // Implementation. 38 | //----- 39 | 40 | // Flush output. 41 | #ifndef CMFT_ALWAYS_FLUSH_OUTPUT 42 | #define CMFT_ALWAYS_FLUSH_OUTPUT 0 43 | #endif //CMFT_ALWAYS_FLUSH_OUTPUT 44 | 45 | #if CMFT_ALWAYS_FLUSH_OUTPUT 46 | #define CMFT_FLUSH_OUTPUT() do { fflush(stdout); fflush(stderr); } while(0) 47 | #else 48 | #define CMFT_FLUSH_OUTPUT() do {} while(0) 49 | #endif 50 | 51 | // Cmft progress. 52 | #ifndef CMFT_ENABLE_PROGRESS_REPORT 53 | #define CMFT_ENABLE_PROGRESS_REPORT 0 54 | #endif 55 | 56 | #if CMFT_ENABLE_PROGRESS_REPORT 57 | #define CMFT_PROGRESS(_format, ...) \ 58 | do \ 59 | { \ 60 | printf(_format "\n", ##__VA_ARGS__); \ 61 | CMFT_FLUSH_OUTPUT(); \ 62 | } while(0) 63 | #else 64 | #define CMFT_PROGRESS(...) do {} while(0) 65 | #endif 66 | 67 | // Cmft info. 68 | #ifndef CMFT_ENABLE_INFO_MESSAGES 69 | #define CMFT_ENABLE_INFO_MESSAGES 0 70 | #endif 71 | 72 | #if CMFT_ENABLE_INFO_MESSAGES 73 | #define INFO _INFO 74 | #else 75 | #define INFO(...) do {} while(0) 76 | #endif 77 | 78 | namespace cmft { extern PrintFunc printfInfo; } 79 | #define _INFO(_format, ...) \ 80 | do \ 81 | { \ 82 | if (NULL != cmft::printfInfo) \ 83 | { \ 84 | cmft::printfInfo("CMFT info: " _format "\n", ##__VA_ARGS__); \ 85 | } \ 86 | } while(0) 87 | 88 | // Cmft warning. 89 | #ifndef CMFT_ENABLE_WARNINGS 90 | #define CMFT_ENABLE_WARNINGS 0 91 | #endif 92 | 93 | #if CMFT_ENABLE_WARNINGS 94 | #define WARN _WARN 95 | #else 96 | #define WARN(...) do {} while(0) 97 | #endif 98 | 99 | namespace cmft { extern PrintFunc printfWarning; } 100 | #define _WARN(_format, ...) \ 101 | do \ 102 | { \ 103 | if (NULL != cmft::printfWarning) \ 104 | { \ 105 | cmft::printfWarning("CMFT WARNING: " _format "\n", ##__VA_ARGS__); \ 106 | } \ 107 | } while(0) 108 | 109 | // File error check. 110 | #ifndef CMFT_ENABLE_FILE_ERROR_CHECK 111 | #define CMFT_ENABLE_FILE_ERROR_CHECK 0 112 | #endif 113 | 114 | #if CMFT_ENABLE_FILE_ERROR_CHECK 115 | #define FERROR_CHECK _FERROR_CHECK 116 | #else 117 | #define FERROR_CHECK(_fp) do {} while(0) 118 | #endif 119 | 120 | #define _FERROR_CHECK(_fp) \ 121 | do \ 122 | { \ 123 | if (ferror(_fp)) \ 124 | { \ 125 | fprintf(stderr, "CMFT FILE I/O ERROR " _FILE_LINE_ ".\n"); \ 126 | CMFT_FLUSH_OUTPUT(); \ 127 | } \ 128 | } while(0) 129 | 130 | // Memory alloc check. 131 | #ifndef CMFT_ENABLE_MEMORY_ALLOC_CHECK 132 | #define CMFT_ENABLE_MEMORY_ALLOC_CHECK 0 133 | #endif 134 | 135 | #if CMFT_ENABLE_MEMORY_ALLOC_CHECK 136 | #define MALLOC_CHECK _MALLOC_CHECK 137 | #else 138 | #define MALLOC_CHECK(_fp) do {} while(0) 139 | #endif 140 | 141 | #define _MALLOC_CHECK(_ptr) \ 142 | do \ 143 | { \ 144 | if (NULL == _ptr) \ 145 | { \ 146 | fprintf(stderr, "CMFT MEMORY ALLOC ERROR " _FILE_LINE_ ".\n"); \ 147 | CMFT_FLUSH_OUTPUT(); \ 148 | } \ 149 | } while(0) 150 | 151 | // Debug check. 152 | #ifndef CMFT_ENABLE_DEBUG_CHECK 153 | #define CMFT_ENABLE_DEBUG_CHECK 0 154 | #endif 155 | 156 | #if CMFT_ENABLE_DEBUG_CHECK 157 | #define DEBUG_CHECK _DEBUG_CHECK 158 | #else 159 | #define DEBUG_CHECK(_condition, ...) do {} while(0) 160 | #endif 161 | 162 | #define _DEBUG_CHECK(_condition, _format, ...) \ 163 | do \ 164 | { \ 165 | if (!(_condition)) \ 166 | { \ 167 | fprintf(stderr, "CMFT DEBUG CHECK " _FILE_LINE_ ": " _format "\n", ##__VA_ARGS__); \ 168 | CMFT_FLUSH_OUTPUT(); \ 169 | abort(); \ 170 | } \ 171 | } while(0) 172 | 173 | // CL check. 174 | #ifndef CMFT_ENABLE_CL_CHECK 175 | #define CMFT_ENABLE_CL_CHECK 0 176 | #endif 177 | 178 | #if CMFT_ENABLE_CL_CHECK 179 | #define CL_CHECK _CL_CHECK 180 | #define CL_CHECK_ERR _CL_CHECK_ERR 181 | #else 182 | #define CL_CHECK(_expr) _expr 183 | #define CL_CHECK_ERR(_expr) BX_UNUSED(_expr) 184 | #endif 185 | 186 | #define _CL_CHECK(_expr) \ 187 | do \ 188 | { \ 189 | cl_int err = _expr; \ 190 | if (CL_SUCCESS != err) \ 191 | { \ 192 | fprintf(stderr, "CMFT OpenCL Error: '%s' returned %d!\n", #_expr, (int)err); \ 193 | CMFT_FLUSH_OUTPUT(); \ 194 | abort(); \ 195 | } \ 196 | } while (0) 197 | 198 | #define _CL_CHECK_ERR(_err) \ 199 | if (CL_SUCCESS != _err) \ 200 | { \ 201 | fprintf(stderr, "CMFT OpenCL Error: %d!\n", (int)_err); \ 202 | CMFT_FLUSH_OUTPUT(); \ 203 | abort(); \ 204 | } 205 | 206 | #endif //CMFT_CONFIG_H_HEADER_GUARD 207 | 208 | /* vim: set sw=4 ts=4 expandtab: */ 209 | -------------------------------------------------------------------------------- /src/cmft/common/fpumath.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2014 Branimir Karadzic. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | // FPU math lib 7 | 8 | #ifndef FPU_MATH_H_HEADER_GUARD 9 | #define FPU_MATH_H_HEADER_GUARD 10 | 11 | #define _USE_MATH_DEFINES 12 | #include 13 | #include 14 | 15 | #ifndef M_PI 16 | #define M_PI 3.14159265358979323846 17 | #endif 18 | 19 | #if defined(_MSC_VER) 20 | inline float fminf(float _a, float _b) 21 | { 22 | return _a < _b ? _a : _b; 23 | } 24 | 25 | inline float fmaxf(float _a, float _b) 26 | { 27 | return _a > _b ? _a : _b; 28 | } 29 | #endif // BX_COMPILER_MSVC 30 | 31 | inline float toRad(float _deg) 32 | { 33 | return _deg * float(M_PI / 180.0); 34 | } 35 | 36 | inline float toDeg(float _rad) 37 | { 38 | return _rad * float(180.0 / M_PI); 39 | } 40 | 41 | inline float fclamp(float _a, float _min, float _max) 42 | { 43 | return fminf(fmaxf(_a, _min), _max); 44 | } 45 | 46 | inline float fsaturate(float _a) 47 | { 48 | return fclamp(_a, 0.0f, 1.0f); 49 | } 50 | 51 | inline float flerp(float _a, float _b, float _t) 52 | { 53 | return _a + (_b - _a) * _t; 54 | } 55 | 56 | inline float fsign(float _a) 57 | { 58 | return _a < 0.0f ? -1.0f : 1.0f; 59 | } 60 | 61 | inline void vec3Move(float* __restrict _result, const float* __restrict _a) 62 | { 63 | _result[0] = _a[0]; 64 | _result[1] = _a[1]; 65 | _result[2] = _a[2]; 66 | } 67 | 68 | inline void vec3Abs(float* __restrict _result, const float* __restrict _a) 69 | { 70 | _result[0] = fabsf(_a[0]); 71 | _result[1] = fabsf(_a[1]); 72 | _result[2] = fabsf(_a[2]); 73 | } 74 | 75 | inline void vec3Neg(float* __restrict _result, const float* __restrict _a) 76 | { 77 | _result[0] = -_a[0]; 78 | _result[1] = -_a[1]; 79 | _result[2] = -_a[2]; 80 | } 81 | 82 | inline void vec3Add(float* __restrict _result, const float* __restrict _a, const float* __restrict _b) 83 | { 84 | _result[0] = _a[0] + _b[0]; 85 | _result[1] = _a[1] + _b[1]; 86 | _result[2] = _a[2] + _b[2]; 87 | } 88 | 89 | inline void vec3Sub(float* __restrict _result, const float* __restrict _a, const float* __restrict _b) 90 | { 91 | _result[0] = _a[0] - _b[0]; 92 | _result[1] = _a[1] - _b[1]; 93 | _result[2] = _a[2] - _b[2]; 94 | } 95 | 96 | inline void vec3Mul(float* __restrict _result, const float* __restrict _a, const float* __restrict _b) 97 | { 98 | _result[0] = _a[0] * _b[0]; 99 | _result[1] = _a[1] * _b[1]; 100 | _result[2] = _a[2] * _b[2]; 101 | } 102 | 103 | inline void vec3Mul(float* __restrict _result, const float* __restrict _a, float _b) 104 | { 105 | _result[0] = _a[0] * _b; 106 | _result[1] = _a[1] * _b; 107 | _result[2] = _a[2] * _b; 108 | } 109 | 110 | inline void vec4Mul(float* __restrict _result, const float* __restrict _a, float _b) 111 | { 112 | _result[0] = _a[0] * _b; 113 | _result[1] = _a[1] * _b; 114 | _result[2] = _a[2] * _b; 115 | _result[3] = _a[3] * _b; 116 | } 117 | 118 | inline float vec3Dot(const float* __restrict _a, const float* __restrict _b) 119 | { 120 | return _a[0]*_b[0] + _a[1]*_b[1] + _a[2]*_b[2]; 121 | } 122 | 123 | inline void vec3Cross(float* __restrict _result, const float* __restrict _a, const float* __restrict _b) 124 | { 125 | _result[0] = _a[1]*_b[2] - _a[2]*_b[1]; 126 | _result[1] = _a[2]*_b[0] - _a[0]*_b[2]; 127 | _result[2] = _a[0]*_b[1] - _a[1]*_b[0]; 128 | } 129 | 130 | inline float vec3Length(const float* _a) 131 | { 132 | return sqrtf(vec3Dot(_a, _a) ); 133 | } 134 | 135 | inline float vec3Norm(float* __restrict _result, const float* __restrict _a) 136 | { 137 | const float len = vec3Length(_a); 138 | const float invLen = 1.0f/len; 139 | _result[0] = _a[0] * invLen; 140 | _result[1] = _a[1] * invLen; 141 | _result[2] = _a[2] * invLen; 142 | return len; 143 | } 144 | 145 | #endif // FPU_MATH_H_HEADER_GUARD 146 | -------------------------------------------------------------------------------- /src/cmft/common/handlealloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFT_HANDLEALLOC_H_HEADER_GUARD 7 | #define CMFT_HANDLEALLOC_H_HEADER_GUARD 8 | 9 | #include 10 | 11 | #ifdef max 12 | # undef max 13 | #endif // max 14 | 15 | #ifdef min 16 | # undef min 17 | #endif // max 18 | 19 | namespace cmft 20 | { 21 | template 22 | struct HandleAllocImpl : HandleAllocStorageTy 23 | { 24 | /// Expected interface: 25 | /// struct HandleAllocStorageTemplate 26 | /// { 27 | /// typedef typename bestfit_type::type HandleType; 28 | /// HandleType* handles(); 29 | /// HandleType* indices(); 30 | /// HandleType max(); 31 | /// }; 32 | typedef typename HandleAllocStorageTy::HandleType HandleTy; 33 | using HandleAllocStorageTy::handles; 34 | using HandleAllocStorageTy::indices; 35 | using HandleAllocStorageTy::max; 36 | 37 | HandleAllocImpl() : HandleAllocStorageTy() 38 | { 39 | } 40 | 41 | void init() 42 | { 43 | m_numHandles = 0; 44 | for (HandleTy ii = 0, end = max(); ii < end; ++ii) 45 | { 46 | handles()[ii] = ii; 47 | } 48 | } 49 | 50 | HandleTy alloc() 51 | { 52 | const HandleTy index = m_numHandles++; 53 | const HandleTy handle = handles()[index]; 54 | indices()[handle] = index; 55 | 56 | return handle; 57 | } 58 | 59 | bool contains(uint32_t _handle) 60 | { 61 | HandleTy index = indices()[_handle]; 62 | 63 | return (index < m_numHandles && handles()[index] == _handle); 64 | } 65 | 66 | void free(uint32_t _handle) 67 | { 68 | HandleTy index = indices()[_handle]; 69 | 70 | if (index < m_numHandles && handles()[index] == _handle) 71 | { 72 | --m_numHandles; 73 | HandleTy temp = handles()[m_numHandles]; 74 | handles()[m_numHandles] = _handle; 75 | indices()[temp] = index; 76 | handles()[index] = temp; 77 | } 78 | } 79 | 80 | HandleTy getHandleAt(uint32_t _idx) 81 | { 82 | return handles()[_idx]; 83 | } 84 | 85 | HandleTy getIdxOf(uint32_t _handle) 86 | { 87 | return indices()[_handle]; 88 | } 89 | 90 | void reset() 91 | { 92 | m_numHandles = 0; 93 | } 94 | 95 | HandleTy count() 96 | { 97 | return m_numHandles; 98 | } 99 | 100 | private: 101 | HandleTy m_numHandles; 102 | }; 103 | 104 | template 105 | struct HandleAllocStorageT 106 | { 107 | typedef uint16_t HandleType; 108 | 109 | HandleType* handles() 110 | { 111 | return m_handles; 112 | } 113 | 114 | HandleType* indices() 115 | { 116 | return m_indices; 117 | } 118 | 119 | HandleType max() const 120 | { 121 | return MaxHandlesT; 122 | } 123 | 124 | private: 125 | HandleType m_handles[MaxHandlesT]; 126 | HandleType m_indices[MaxHandlesT]; 127 | }; 128 | 129 | template 130 | struct HandleAllocT : HandleAllocImpl< HandleAllocStorageT > 131 | { 132 | typedef HandleAllocImpl< HandleAllocStorageT > Base; 133 | 134 | HandleAllocT() 135 | { 136 | Base::init(); 137 | } 138 | }; 139 | } 140 | 141 | #endif // CMFT_HANDLEALLOC_H_HEADER_GUARD 142 | 143 | /* vim: set sw=4 ts=4 expandtab: */ 144 | 145 | -------------------------------------------------------------------------------- /src/cmft/common/os.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | /* 7 | * Copyright 2010-2016 Branimir Karadzic. All rights reserved. 8 | * License: https://github.com/bkaradzic/bx#license-bsd-2-clause 9 | */ 10 | 11 | // Copyright 2006 Mike Acton 12 | // 13 | // Permission is hereby granted, free of charge, to any person obtaining a 14 | // copy of this software and associated documentation files (the "Software"), 15 | // to deal in the Software without restriction, including without limitation 16 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | // and/or sell copies of the Software, and to permit persons to whom the 18 | // Software is furnished to do so, subject to the following conditions: 19 | // 20 | // The above copyright notice and this permission notice shall be included 21 | // in all copies or substantial portions of the Software. 22 | // 23 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | // THE SOFTWARE 30 | 31 | #ifndef CMFT_OS_H_HEADER_GUARD 32 | #define CMFT_OS_H_HEADER_GUARD 33 | 34 | #include "platform.h" 35 | #include 36 | 37 | #if CMFT_PLATFORM_WINDOWS 38 | # include 39 | #elif CMFT_PLATFORM_LINUX || CMFT_PLATFORM_APPLE 40 | # include // sched_yield 41 | # if CMFT_PLATFORM_APPLE 42 | # include // mach_port_t 43 | # endif // CMFT_PLATFORM_* 44 | # 45 | # include // dlopen, dlclose, dlsym 46 | # 47 | # if CMFT_PLATFORM_LINUX 48 | # include // syscall 49 | # include 50 | # endif // CMFT_PLATFORM_LINUX 51 | #endif // CMFT_PLATFORM_ 52 | 53 | namespace cmft 54 | { 55 | inline void* dlopen(const char* _filePath) 56 | { 57 | #if CMFT_PLATFORM_WINDOWS 58 | return (void*)::LoadLibraryA(_filePath); 59 | #else 60 | return ::dlopen(_filePath, RTLD_LOCAL|RTLD_LAZY); 61 | #endif // CMFT_PLATFORM_ 62 | } 63 | 64 | inline void dlclose(void* _handle) 65 | { 66 | #if CMFT_PLATFORM_WINDOWS 67 | ::FreeLibrary( (HMODULE)_handle); 68 | #else 69 | ::dlclose(_handle); 70 | #endif // CMFT_PLATFORM_ 71 | } 72 | 73 | inline void* dlsym(void* _handle, const char* _symbol) 74 | { 75 | #if CMFT_PLATFORM_WINDOWS 76 | return (void*)::GetProcAddress( (HMODULE)_handle, _symbol); 77 | #else 78 | return ::dlsym(_handle, _symbol); 79 | #endif // CMFT_PLATFORM_ 80 | } 81 | } 82 | 83 | #endif // CMFT_OS_H_HEADER_GUARD 84 | 85 | /* vim: set sw=4 ts=4 expandtab: */ 86 | 87 | -------------------------------------------------------------------------------- /src/cmft/common/platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFT_PLATFORM_HEADER_GUARD 7 | #define CMFT_PLATFORM_HEADER_GUARD 8 | 9 | /// Pre-defined C/C++ Compiler Macros: http://sourceforge.net/p/predef/wiki/Home/ 10 | 11 | //------------------------------------------------------------ 12 | // Options. 13 | //------------------------------------------------------------ 14 | 15 | #define CMFT_COMPILER_MSVC 0 16 | #define CMFT_COMPILER_GCC 0 17 | #define CMFT_COMPILER_CLANG 0 18 | 19 | #define CMFT_ARCH_32BIT 0 20 | #define CMFT_ARCH_64BIT 0 21 | 22 | #define CMFT_PTR_SIZE 0 23 | 24 | #define CMFT_PLATFORM_LINUX 0 25 | #define CMFT_PLATFORM_APPLE 0 26 | #define CMFT_PLATFORM_WINDOWS 0 27 | 28 | #define CMFT_PLATFORM_UNIX 0 29 | #define CMFT_PLATFORM_POSIX 0 30 | 31 | #define CMFT_CPP11 0 32 | #define CMFT_CPP14 0 33 | 34 | //------------------------------------------------------------ 35 | // Impl. 36 | //------------------------------------------------------------ 37 | 38 | #if defined(_WIN32) || defined(_WIN64) 39 | # undef CMFT_COMPILER_MSVC 40 | # define CMFT_COMPILER_MSVC 1 41 | #elif defined(__GNUC__) 42 | # undef CMFT_COMPILER_GCC 43 | # define CMFT_COMPILER_GCC 1 44 | #elif defined(__clang__) 45 | # undef CMFT_COMPILER_CLANG 46 | # define CMFT_COMPILER_CLANG 1 47 | #endif 48 | 49 | #if (0 \ 50 | || defined (__amd64__) \ 51 | || defined (__amd64) \ 52 | || defined (__x86_64__) \ 53 | || defined (__x86_64) \ 54 | || defined (_M_X64) \ 55 | || defined (_M_AMD64) ) 56 | # undef CMFT_ARCH_64BIT 57 | # define CMFT_ARCH_64BIT 1 58 | # undef CMFT_PTR_SIZE 59 | # define CMFT_PTR_SIZE 8 60 | #elif (0 \ 61 | || defined(i386) \ 62 | || defined(__i386) \ 63 | || defined(__i386__) \ 64 | || defined(__i386) \ 65 | || defined(__IA32__) \ 66 | || defined(_M_I86) \ 67 | || defined(_M_IX86) \ 68 | || defined(_X86_) \ 69 | || defined(__X86__) ) 70 | # undef CMFT_ARCH_32BIT 71 | # define CMFT_ARCH_32BIT 1 72 | # undef CMFT_PTR_SIZE 73 | # define CMFT_PTR_SIZE 4 74 | #else 75 | # error Unsupported platform! 76 | #endif 77 | 78 | #if (0 \ 79 | || defined(__linux__) \ 80 | || defined(linux) \ 81 | || defined(__linux) \ 82 | || defined(__gnu_linux__) ) 83 | # undef CMFT_PLATFORM_LINUX 84 | # define CMFT_PLATFORM_LINUX 1 85 | #elif (0 \ 86 | || defined(__APPLE__) \ 87 | || defined(macintosh) \ 88 | || defined(Macintosh) ) 89 | # undef CMFT_PLATFORM_APPLE 90 | # define CMFT_PLATFORM_APPLE 1 91 | #elif (0 \ 92 | || defined(_WIN16) \ 93 | || defined(_WIN32) \ 94 | || defined(_WIN64) \ 95 | || defined(__WIN32__) \ 96 | || defined(__TOS_WIN__) \ 97 | || defined(__WINDOWS__) ) 98 | # undef CMFT_PLATFORM_WINDOWS 99 | # define CMFT_PLATFORM_WINDOWS 1 100 | #endif 101 | 102 | #if defined(__unix__) || defined(__unix) 103 | # undef CMFT_PLATFORM_UNIX 104 | # define CMFT_PLATFORM_UNIX 1 105 | #endif 106 | 107 | #undef CMFT_PLATFORM_POSIX 108 | #define CMFT_PLATFORM_POSIX (CMFT_PLATFORM_LINUX || CMFT_PLATFORM_APPLE || CMFT_PLATFORM_UNIX) 109 | 110 | #undef CMFT_CPP11 111 | #define CMFT_CPP11 (__cplusplus >= 201103L) 112 | #undef CMFT_CPP14 113 | #define CMFT_CPP14 (__cplusplus >= 201402L) 114 | 115 | #endif // CMFT_PLATFORM_HEADER_GUARD 116 | 117 | /* vim: set sw=4 ts=4 expandtab: */ 118 | 119 | -------------------------------------------------------------------------------- /src/cmft/common/print.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 "config.h" 7 | #include 8 | #include // ::printf 9 | 10 | namespace cmft 11 | { 12 | PrintFunc printfWarning = ::printf; 13 | PrintFunc printfInfo = ::printf; 14 | 15 | void setWarningPrintf(PrintFunc _printf) 16 | { 17 | printfWarning = _printf; 18 | } 19 | 20 | void setInfoPrintf(PrintFunc _printf) 21 | { 22 | printfInfo = _printf; 23 | } 24 | 25 | } // namespace cmft 26 | 27 | /* vim: set sw=4 ts=4 expandtab: */ 28 | -------------------------------------------------------------------------------- /src/cmft/common/stb_image.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2016 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #include "utils.h" 7 | 8 | CMFT_PRAGMA_DIAGNOSTIC_PUSH(); 9 | CMFT_PRAGMA_DIAGNOSTIC_IGNORED_CLANG_GCC("-Wshadow"); 10 | CMFT_PRAGMA_DIAGNOSTIC_IGNORED_CLANG_GCC("-Wunused-function"); 11 | CMFT_PRAGMA_DIAGNOSTIC_IGNORED_CLANG_GCC("-Wcast-qual"); 12 | #define STB_IMAGE_IMPLEMENTATION 13 | #include 14 | CMFT_PRAGMA_DIAGNOSTIC_POP(); 15 | 16 | /* vim: set sw=4 ts=4 expandtab: */ 17 | -------------------------------------------------------------------------------- /src/cmft/common/stb_image.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | #ifndef CMFT_STB_IMAGE_H_HEADER_GUARD 7 | #define CMFT_STB_IMAGE_H_HEADER_GUARD 8 | 9 | #include 10 | 11 | #endif // CMFT_STB_IMAGE_HEADER_GUARD 12 | 13 | /* vim: set sw=4 ts=4 expandtab: */ 14 | 15 | -------------------------------------------------------------------------------- /src/cmft/common/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Dario Manesku. All rights reserved. 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause 4 | */ 5 | 6 | /* 7 | * Adapted from: https://github.com/bkaradzic/bx/include/bx/timer.h 8 | * Copyright 2010-2016 Branimir Karadzic. All rights reserved. 9 | * License: https://github.com/bkaradzic/bx#license-bsd-2-clause 10 | */ 11 | #ifndef CMFT_OS_H_HEADER_GUARD 12 | #define CMFT_OS_H_HEADER_GUARD 13 | 14 | #include "platform.h" 15 | #include 16 | 17 | #if CMFT_PLATFORM_WINDOWS 18 | # include 19 | #else 20 | # include // gettimeofday 21 | #endif // CMFT_PLATFORM_ 22 | 23 | namespace cmft 24 | { 25 | inline int64_t getHPCounter() 26 | { 27 | #if CMFT_PLATFORM_WINDOWS 28 | LARGE_INTEGER li; 29 | // Performance counter value may unexpectedly leap forward 30 | // http://support.microsoft.com/kb/274323 31 | QueryPerformanceCounter(&li); 32 | int64_t i64 = li.QuadPart; 33 | #else 34 | struct timeval now; 35 | gettimeofday(&now, 0); 36 | int64_t i64 = now.tv_sec*INT64_C(1000000) + now.tv_usec; 37 | #endif // CMFT_PLATFORM_ 38 | 39 | return i64; 40 | } 41 | 42 | inline int64_t getHPFrequency() 43 | { 44 | #if CMFT_PLATFORM_WINDOWS 45 | LARGE_INTEGER li; 46 | QueryPerformanceFrequency(&li); 47 | return li.QuadPart; 48 | #else 49 | return INT64_C(1000000); 50 | #endif // CMFT_PLATFORM_ 51 | } 52 | } 53 | 54 | #endif // CMFT_OS_H_HEADER_GUARD 55 | 56 | /* vim: set sw=4 ts=4 expandtab: */ 57 | 58 | -------------------------------------------------------------------------------- /src/cmft/cubemaputils.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 CMFT_CUBEMAPUTILS_H_HEADER_GUARD 7 | #define CMFT_CUBEMAPUTILS_H_HEADER_GUARD 8 | 9 | #include "common/fpumath.h" 10 | 11 | namespace cmft 12 | { 13 | #define CMFT_PI 3.14159265358979323846f 14 | #define CMFT_RPI 0.31830988618379067153f 15 | #define CMFT_2PI 6.28318530717958647692f 16 | #define CMFT_DEGTORAD 0.01745329251994329576f 17 | #define CMFT_RADTODEG 57.2957795130823208767f 18 | 19 | /// 20 | /// 21 | /// +----------+ 22 | /// | +---->+x | 23 | /// | | | 24 | /// | | +y | 25 | /// |+z 2 | 26 | /// +----------+----------+----------+----------+ 27 | /// | +---->+z | +---->+x | +---->-z | +---->-x | 28 | /// | | | | | | | | | 29 | /// | | -x | | +z | | +x | | -z | 30 | /// |-y 1 |-y 4 |-y 0 |-y 5 | 31 | /// +----------+----------+----------+----------+ 32 | /// | +---->+x | 33 | /// | | | 34 | /// | | -y | 35 | /// |-z 3 | 36 | /// +----------+ 37 | /// 38 | static const float s_faceUvVectors[6][3][3] = 39 | { 40 | { // +x face 41 | { 0.0f, 0.0f, -1.0f }, // u -> -z 42 | { 0.0f, -1.0f, 0.0f }, // v -> -y 43 | { 1.0f, 0.0f, 0.0f }, // +x face 44 | }, 45 | { // -x face 46 | { 0.0f, 0.0f, 1.0f }, // u -> +z 47 | { 0.0f, -1.0f, 0.0f }, // v -> -y 48 | { -1.0f, 0.0f, 0.0f }, // -x face 49 | }, 50 | { // +y face 51 | { 1.0f, 0.0f, 0.0f }, // u -> +x 52 | { 0.0f, 0.0f, 1.0f }, // v -> +z 53 | { 0.0f, 1.0f, 0.0f }, // +y face 54 | }, 55 | { // -y face 56 | { 1.0f, 0.0f, 0.0f }, // u -> +x 57 | { 0.0f, 0.0f, -1.0f }, // v -> -z 58 | { 0.0f, -1.0f, 0.0f }, // -y face 59 | }, 60 | { // +z face 61 | { 1.0f, 0.0f, 0.0f }, // u -> +x 62 | { 0.0f, -1.0f, 0.0f }, // v -> -y 63 | { 0.0f, 0.0f, 1.0f }, // +z face 64 | }, 65 | { // -z face 66 | { -1.0f, 0.0f, 0.0f }, // u -> -x 67 | { 0.0f, -1.0f, 0.0f }, // v -> -y 68 | { 0.0f, 0.0f, -1.0f }, // -z face 69 | } 70 | }; 71 | 72 | enum 73 | { 74 | CMFT_FACE_POS_X = 0, 75 | CMFT_FACE_NEG_X = 1, 76 | CMFT_FACE_POS_Y = 2, 77 | CMFT_FACE_NEG_Y = 3, 78 | CMFT_FACE_POS_Z = 4, 79 | CMFT_FACE_NEG_Z = 5, 80 | }; 81 | 82 | enum 83 | { 84 | CMFT_EDGE_LEFT = 0, 85 | CMFT_EDGE_RIGHT = 1, 86 | CMFT_EDGE_TOP = 2, 87 | CMFT_EDGE_BOTTOM = 3, 88 | }; 89 | 90 | /// 91 | /// --> U _____ 92 | /// | | | 93 | /// v | +Y | 94 | /// V _____|_____|_____ _____ 95 | /// | | | | | 96 | /// | -X | +Z | +X | -Z | 97 | /// |_____|_____|_____|_____| 98 | /// | | 99 | /// | -Y | 100 | /// |_____| 101 | /// 102 | /// Neighbour faces in order: left, right, top, bottom. 103 | /// FaceEdge is the edge that belongs to the neighbour face. 104 | static const struct CubeFaceNeighbour 105 | { 106 | uint8_t m_faceIdx; 107 | uint8_t m_faceEdge; 108 | } s_cubeFaceNeighbours[6][4] = 109 | { 110 | { //POS_X 111 | { CMFT_FACE_POS_Z, CMFT_EDGE_RIGHT }, 112 | { CMFT_FACE_NEG_Z, CMFT_EDGE_LEFT }, 113 | { CMFT_FACE_POS_Y, CMFT_EDGE_RIGHT }, 114 | { CMFT_FACE_NEG_Y, CMFT_EDGE_RIGHT }, 115 | }, 116 | { //NEG_X 117 | { CMFT_FACE_NEG_Z, CMFT_EDGE_RIGHT }, 118 | { CMFT_FACE_POS_Z, CMFT_EDGE_LEFT }, 119 | { CMFT_FACE_POS_Y, CMFT_EDGE_LEFT }, 120 | { CMFT_FACE_NEG_Y, CMFT_EDGE_LEFT }, 121 | }, 122 | { //POS_Y 123 | { CMFT_FACE_NEG_X, CMFT_EDGE_TOP }, 124 | { CMFT_FACE_POS_X, CMFT_EDGE_TOP }, 125 | { CMFT_FACE_NEG_Z, CMFT_EDGE_TOP }, 126 | { CMFT_FACE_POS_Z, CMFT_EDGE_TOP }, 127 | }, 128 | { //NEG_Y 129 | { CMFT_FACE_NEG_X, CMFT_EDGE_BOTTOM }, 130 | { CMFT_FACE_POS_X, CMFT_EDGE_BOTTOM }, 131 | { CMFT_FACE_POS_Z, CMFT_EDGE_BOTTOM }, 132 | { CMFT_FACE_NEG_Z, CMFT_EDGE_BOTTOM }, 133 | }, 134 | { //POS_Z 135 | { CMFT_FACE_NEG_X, CMFT_EDGE_RIGHT }, 136 | { CMFT_FACE_POS_X, CMFT_EDGE_LEFT }, 137 | { CMFT_FACE_POS_Y, CMFT_EDGE_BOTTOM }, 138 | { CMFT_FACE_NEG_Y, CMFT_EDGE_TOP }, 139 | }, 140 | { //NEG_Z 141 | { CMFT_FACE_POS_X, CMFT_EDGE_RIGHT }, 142 | { CMFT_FACE_NEG_X, CMFT_EDGE_LEFT }, 143 | { CMFT_FACE_POS_Y, CMFT_EDGE_TOP }, 144 | { CMFT_FACE_NEG_Y, CMFT_EDGE_BOTTOM }, 145 | } 146 | }; 147 | 148 | /// _u and _v should be center adressing and in [-1.0+invSize..1.0-invSize] range. 149 | static inline void texelCoordToVec(float* _out3f, float _u, float _v, uint8_t _faceId) 150 | { 151 | // out = u * s_faceUv[0] + v * s_faceUv[1] + s_faceUv[2]. 152 | _out3f[0] = s_faceUvVectors[_faceId][0][0] * _u + s_faceUvVectors[_faceId][1][0] * _v + s_faceUvVectors[_faceId][2][0]; 153 | _out3f[1] = s_faceUvVectors[_faceId][0][1] * _u + s_faceUvVectors[_faceId][1][1] * _v + s_faceUvVectors[_faceId][2][1]; 154 | _out3f[2] = s_faceUvVectors[_faceId][0][2] * _u + s_faceUvVectors[_faceId][1][2] * _v + s_faceUvVectors[_faceId][2][2]; 155 | 156 | // Normalize. 157 | const float invLen = 1.0f/sqrtf(_out3f[0]*_out3f[0] + _out3f[1]*_out3f[1] + _out3f[2]*_out3f[2]); 158 | _out3f[0] *= invLen; 159 | _out3f[1] *= invLen; 160 | _out3f[2] *= invLen; 161 | } 162 | 163 | /// Notice: _faceSize should not be equal to one! 164 | static inline float warpFixupFactor(float _faceSize) 165 | { 166 | // Edge fixup. 167 | // Based on Nvtt : http://code.google.com/p/nvidia-texture-tools/source/browse/trunk/src/nvtt/CubeSurface.cpp 168 | if (_faceSize == 1.0f) 169 | { 170 | return 1.0f; 171 | } 172 | 173 | const float fs = _faceSize; 174 | const float fsmo = fs - 1.0f; 175 | return (fs*fs) / (fsmo*fsmo*fsmo); 176 | } 177 | 178 | /// _u and _v should be center adressing and in [-1.0+invSize..1.0-invSize] range. 179 | static inline void texelCoordToVecWarp(float* _out3f, float _u, float _v, uint8_t _faceId, float _warpFixup) 180 | { 181 | _u = (_warpFixup * _u*_u*_u) + _u; 182 | _v = (_warpFixup * _v*_v*_v) + _v; 183 | 184 | texelCoordToVec(_out3f, _u, _v, _faceId); 185 | } 186 | 187 | /// _u and _v are in [0.0 .. 1.0] range. 188 | static inline void vecToTexelCoord(float& _u, float& _v, uint8_t& _faceIdx, const float* _vec) 189 | { 190 | const float absVec[3] = 191 | { 192 | fabsf(_vec[0]), 193 | fabsf(_vec[1]), 194 | fabsf(_vec[2]), 195 | }; 196 | const float max = fmaxf(fmaxf(absVec[0], absVec[1]), absVec[2]); 197 | 198 | // Get face id (max component == face vector). 199 | if (max == absVec[0]) 200 | { 201 | _faceIdx = (_vec[0] >= 0.0f) ? uint8_t(CMFT_FACE_POS_X) : uint8_t(CMFT_FACE_NEG_X); 202 | } 203 | else if (max == absVec[1]) 204 | { 205 | _faceIdx = (_vec[1] >= 0.0f) ? uint8_t(CMFT_FACE_POS_Y) : uint8_t(CMFT_FACE_NEG_Y); 206 | } 207 | else //if (max == absVec[2]) 208 | { 209 | _faceIdx = (_vec[2] >= 0.0f) ? uint8_t(CMFT_FACE_POS_Z) : uint8_t(CMFT_FACE_NEG_Z); 210 | } 211 | 212 | // Divide by max component. 213 | float faceVec[3]; 214 | vec3Mul(faceVec, _vec, 1.0f/max); 215 | 216 | // Project other two components to face uv basis. 217 | _u = (vec3Dot(s_faceUvVectors[_faceIdx][0], faceVec) + 1.0f) * 0.5f; 218 | _v = (vec3Dot(s_faceUvVectors[_faceIdx][1], faceVec) + 1.0f) * 0.5f; 219 | } 220 | 221 | static inline void latLongFromVec(float& _u, float& _v, const float _vec[3]) 222 | { 223 | const float phi = atan2f(_vec[0], _vec[2]); 224 | const float theta = acosf(_vec[1]); 225 | 226 | _u = (CMFT_PI + phi)*(0.5f/CMFT_PI); 227 | _v = theta*CMFT_RPI; 228 | } 229 | 230 | static inline void vecFromLatLong(float _vec[3], float _u, float _v) 231 | { 232 | const float phi = _u * CMFT_2PI; 233 | const float theta = _v * CMFT_PI; 234 | 235 | _vec[0] = -sinf(theta)*sinf(phi); 236 | _vec[1] = cosf(theta); 237 | _vec[2] = -sinf(theta)*cosf(phi); 238 | } 239 | 240 | // Assume normalized _vec. 241 | // Output is on [0, 1] for each component 242 | static inline void octantFromVec(float& _u, float& _v, const float _vec[3]) 243 | { 244 | // Project the sphere onto the octahedron, and then onto the xy plane. 245 | float dot = fabsf(_vec[0]) + fabsf(_vec[1]) + fabsf(_vec[2]); 246 | float px = _vec[0] / dot; 247 | float py = _vec[2] / dot; 248 | 249 | // Reflect the folds of the lower hemisphere over the diagonals. 250 | if (_vec[1] <= 0.0f) 251 | { 252 | _u = ((1.0f - fabsf(py)) * fsign(px)); 253 | _v = ((1.0f - fabsf(px)) * fsign(py)); 254 | } 255 | else 256 | { 257 | _u = px; 258 | _v = py; 259 | } 260 | 261 | _u = _u * 0.5f + 0.5f; 262 | _v = _v * 0.5f + 0.5f; 263 | } 264 | 265 | static inline void vecFromOctant(float _vec[3], float _u, float _v) 266 | { 267 | _u = _u*2.0f - 1.0f; 268 | _v = _v*2.0f - 1.0f; 269 | 270 | _vec[1] = 1.0f - fabsf(_u) - fabsf(_v); 271 | 272 | if (_vec[1] < 0.0f) 273 | { 274 | _vec[0] = (1.0f - fabsf(_v)) * fsign(_u); 275 | _vec[2] = (1.0f - fabsf(_u)) * fsign(_v); 276 | } 277 | else 278 | { 279 | _vec[0] = _u; 280 | _vec[2] = _v; 281 | } 282 | 283 | const float invLen = 1.0f/vec3Length(_vec); 284 | _vec[0] *= invLen; 285 | _vec[1] *= invLen; 286 | _vec[2] *= invLen; 287 | } 288 | 289 | /// http://www.mpia-hd.mpg.de/~mathar/public/mathar20051002.pdf 290 | /// http://www.rorydriscoll.com/2012/01/15/cubemap-texel-solid-angle/ 291 | static inline float areaElement(float _x, float _y) 292 | { 293 | return atan2f(_x*_y, sqrtf(_x*_x + _y*_y + 1.0f)); 294 | } 295 | 296 | /// _u and _v should be center adressing and in [-1.0+invSize..1.0-invSize] range. 297 | static inline float texelSolidAngle(float _u, float _v, float _invFaceSize) 298 | { 299 | // Specify texel area. 300 | const float x0 = _u - _invFaceSize; 301 | const float x1 = _u + _invFaceSize; 302 | const float y0 = _v - _invFaceSize; 303 | const float y1 = _v + _invFaceSize; 304 | 305 | // Compute solid angle of texel area. 306 | const float solidAngle = areaElement(x1, y1) 307 | - areaElement(x0, y1) 308 | - areaElement(x1, y0) 309 | + areaElement(x0, y0) 310 | ; 311 | 312 | return solidAngle; 313 | } 314 | 315 | } // namespace cmft 316 | 317 | #endif //CMFT_CUBEMAPUTILS_H_HEADER_GUARD 318 | 319 | /* vim: set sw=4 ts=4 expandtab: */ 320 | -------------------------------------------------------------------------------- /src/cmft_tests/tests.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 CMFT_TESTS_H_HEADER_GUARD 7 | #define CMFT_TESTS_H_HEADER_GUARD 8 | 9 | #include "../cmft_cli/cmft_cli.h" 10 | #include "tokenize.h" 11 | 12 | static const char s_radianceTest[] = 13 | { 14 | "--input \"okretnica.tga\" " 15 | "--filter radiance " 16 | "--srcFaceSize 256 " 17 | "--excludeBase false " 18 | "--mipCount 7 " 19 | "--glossScale 10 " 20 | "--glossBias 3 " 21 | "--lightingModel blinnbrdf " 22 | "--dstFaceSize 256 " 23 | "--numCpuProcessingThreads 4 " 24 | "--useOpenCL true " 25 | "--clVendor anyGpuVendor " 26 | "--deviceType gpu " 27 | "--deviceIndex 0 " 28 | "--inputGammaNumerator 2.2 " 29 | "--inputGammaDenominator 1.0 " 30 | "--outputGammaNumerator 1.0 " 31 | "--outputGammaDenominator 2.2 " 32 | "--generateMipChain false " 33 | "--outputNum 1 " 34 | "--output0 \"okretnicaPmrem\" " 35 | "--output0params dds,bgra8,cubemap " 36 | }; 37 | 38 | static const char s_tgaRadianceTest[] = 39 | { 40 | "--input \"okretnica.tga\" " 41 | "--filter radiance " 42 | "--srcFaceSize 256 " 43 | "--excludeBase false " 44 | "--mipCount 7 " 45 | "--glossScale 10 " 46 | "--glossBias 3 " 47 | "--lightingModel blinnbrdf " 48 | "--dstFaceSize 256 " 49 | "--numCpuProcessingThreads 4 " 50 | "--useOpenCL true " 51 | "--clVendor anyGpuVendor " 52 | "--deviceType gpu " 53 | "--deviceIndex 0 " 54 | "--inputGammaNumerator 2.2 " 55 | "--inputGammaDenominator 1.0 " 56 | "--outputGammaNumerator 1.0 " 57 | "--outputGammaDenominator 2.2 " 58 | "--generateMipChain false " 59 | "--outputNum 1 " 60 | "--output0 \"okretnicaPmrem\" " 61 | "--output0params tga,bgra8,facelist " 62 | }; 63 | 64 | static const char s_outputTest[] = 65 | { 66 | "--input \"okretnica.tga\" " 67 | "--filter none " 68 | "--outputNum 7 " 69 | "--output0 \"okretnica_cubemap\" " 70 | "--output0params dds,bgra8,cubemap " 71 | "--output1 \"okretnica_latlong\" " 72 | "--output1params dds,bgra8,latlong " 73 | "--output2 \"okretnica_hcross\" " 74 | "--output2params dds,bgra8,hcross " 75 | "--output3 \"okretnica_vcross\" " 76 | "--output3params dds,bgra8,vcross " 77 | "--output4 \"okretnica_hstrip\" " 78 | "--output4params dds,bgra8,hstrip " 79 | "--output5 \"okretnica_vstrip\" " 80 | "--output5params dds,bgra8,vstrip " 81 | "--output6 \"okretnica_facelist\" " 82 | "--output6params dds,bgra8,facelist " 83 | }; 84 | 85 | static const char s_gpuTest[] = 86 | { 87 | "--input \"okretnica.tga\" " 88 | "--filter radiance " 89 | "--srcFaceSize 256 " 90 | "--excludeBase false " 91 | "--mipCount 7 " 92 | "--glossScale 10 " 93 | "--glossBias 3 " 94 | "--lightingModel blinnbrdf " 95 | "--edgeFixup none " 96 | "--dstFaceSize 256 " 97 | "--numCpuProcessingThreads 0 " 98 | "--useOpenCL true " 99 | "--clVendor anyGpuVendor " 100 | "--deviceType gpu " 101 | "--deviceIndex 0 " 102 | "--inputGammaNumerator 2.2 " 103 | "--inputGammaDenominator 1.0 " 104 | "--outputGammaNumerator 1.0 " 105 | "--outputGammaDenominator 2.2 " 106 | "--generateMipChain false " 107 | "--outputNum 1 " 108 | "--output0 \"okretnica_gpu\" " 109 | "--output0params dds,bgra8,latlong " 110 | }; 111 | 112 | static const char s_test0[] = 113 | { 114 | "--input \"okretnica.tga\" " 115 | "--outputGammaNumerator 1.0 " 116 | "--outputGammaDenominator 2.2 " 117 | "--outputNum 1 " 118 | "--output0 \"okretnica_test0\" " 119 | "--output0params dds,bgra8,cubemap " 120 | }; 121 | 122 | static const char s_test1[] = 123 | { 124 | "--input \"okretnica.tga\" " 125 | "--filter irradiance " 126 | "--useOpenCL true " 127 | "--mipCount 12 " 128 | "--generateMipChain true " 129 | "--dstFaceSize 256 " 130 | "--outputNum 1 " 131 | "--output0 \"okretnica_test1\" " 132 | "--output0params dds,rgba16,cubemap " 133 | }; 134 | 135 | int test(const char* _cmd) 136 | { 137 | char data[2048]; 138 | uint32_t dataSize; 139 | int argc; 140 | char* argv[128]; 141 | tokenizeCommandLine(_cmd, data, dataSize, argc, argv, CMFT_COUNTOF(argv), '\0'); 142 | return cmftMain(argc, argv); 143 | } 144 | 145 | int testsMain(int /*_argc*/, char const* const* /*_argv*/) 146 | { 147 | test(s_radianceTest); 148 | //test(s_tgaRadianceTest); 149 | //test(s_outputTest); 150 | //test(s_gpuTest); 151 | //test(s_test0); 152 | //test(s_test1); 153 | 154 | char c; 155 | const int unused = scanf("%c", &c); 156 | CMFT_UNUSED(c); 157 | CMFT_UNUSED(unused); 158 | 159 | return 0; 160 | } 161 | 162 | #endif //CMFT_TESTS_H_HEADER_GUARD 163 | 164 | /* vim: set sw=4 ts=4 expandtab: */ 165 | -------------------------------------------------------------------------------- /src/cmft_tests/tokenize.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 CMFT_TOKENIZE_H_HEADER_GUARD 7 | #define CMFT_TOKENIZE_H_HEADER_GUARD 8 | 9 | /// Code from: https://github.com/bkaradzic/bgfx/blob/master/tools/geometryc/tokenizecmd.cpp 10 | /* 11 | * Copyright 2012-2014 Branimir Karadzic. All rights reserved. 12 | * License: http://www.opensource.org/licenses/BSD-2-Clause 13 | */ 14 | 15 | const char* tokenizeCommandLine(const char* _commandLine, char* _buffer, uint32_t& _bufferSize, int& _argc, char* _argv[], int _maxArgvs, char _term) 16 | { 17 | int argc = 0; 18 | const char* curr = _commandLine; 19 | char* currOut = _buffer; 20 | char term = ' '; 21 | bool sub = false; 22 | 23 | enum ParserState 24 | { 25 | SkipWhitespace, 26 | SetTerm, 27 | Copy, 28 | Escape, 29 | End, 30 | }; 31 | 32 | ParserState state = SkipWhitespace; 33 | 34 | while ('\0' != *curr 35 | && _term != *curr 36 | && argc < _maxArgvs) 37 | { 38 | switch (state) 39 | { 40 | case SkipWhitespace: 41 | for (; isspace(*curr); ++curr) {}; // skip whitespace 42 | state = SetTerm; 43 | break; 44 | 45 | case SetTerm: 46 | if ('"' == *curr) 47 | { 48 | term = '"'; 49 | ++curr; // skip begining quote 50 | } 51 | else 52 | { 53 | term = ' '; 54 | } 55 | 56 | _argv[argc] = currOut; 57 | ++argc; 58 | 59 | state = Copy; 60 | break; 61 | 62 | case Copy: 63 | if ('\\' == *curr) 64 | { 65 | state = Escape; 66 | } 67 | else if ('"' == *curr 68 | && '"' != term) 69 | { 70 | sub = !sub; 71 | } 72 | else if (isspace(*curr) && !sub) 73 | { 74 | state = End; 75 | } 76 | else if (term != *curr || sub) 77 | { 78 | *currOut = *curr; 79 | ++currOut; 80 | } 81 | else 82 | { 83 | state = End; 84 | } 85 | ++curr; 86 | break; 87 | 88 | case Escape: 89 | { 90 | const char* start = --curr; 91 | for (; '\\' == *curr; ++curr) {}; 92 | 93 | if ('"' != *curr) 94 | { 95 | int count = (int)(curr-start); 96 | 97 | curr = start; 98 | for (int ii = 0; ii < count; ++ii) 99 | { 100 | *currOut = *curr; 101 | ++currOut; 102 | ++curr; 103 | } 104 | } 105 | else 106 | { 107 | curr = start+1; 108 | *currOut = *curr; 109 | ++currOut; 110 | ++curr; 111 | } 112 | } 113 | state = Copy; 114 | break; 115 | 116 | case End: 117 | *currOut = '\0'; 118 | ++currOut; 119 | state = SkipWhitespace; 120 | break; 121 | } 122 | } 123 | 124 | *currOut = '\0'; 125 | if (0 < argc 126 | && '\0' == _argv[argc-1][0]) 127 | { 128 | --argc; 129 | } 130 | 131 | _bufferSize = (uint32_t)(currOut - _buffer); 132 | _argc = argc; 133 | 134 | if ('\0' != *curr) 135 | { 136 | ++curr; 137 | } 138 | 139 | return curr; 140 | } 141 | 142 | #endif //CMFT_TOKENIZE_H_HEADER_GUARD 143 | 144 | /* vim: set sw=4 ts=4 expandtab: */ 145 | -------------------------------------------------------------------------------- /src/main.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 | 8 | #ifndef CMFT_TEST_BUILD 9 | #define CMFT_TEST_BUILD 0 10 | #endif 11 | 12 | #if CMFT_TEST_BUILD 13 | #include "cmft_tests/tests.h" 14 | int main(int _argc, char const* const* _argv) 15 | { 16 | return testsMain(_argc, _argv); 17 | } 18 | #else 19 | #include "cmft_cli/cmft_cli.h" 20 | int main(int _argc, char const* const* _argv) 21 | { 22 | return cmftMain(_argc, _argv); 23 | } 24 | #endif //CMFT_TEST_BUILD 25 | 26 | /* vim: set sw=4 ts=4 expandtab: */ 27 | --------------------------------------------------------------------------------