├── .clang-format ├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── build ├── msvc │ ├── build.default.props │ ├── render.sln │ ├── render.vcxproj │ ├── render.vcxproj.filters │ ├── test │ │ ├── all.vcxproj │ │ ├── all.vcxproj.filters │ │ ├── render.vcxproj │ │ └── render.vcxproj.filters │ └── tools │ │ ├── rendercompile.vcxproj │ │ ├── renderimport.vcxproj │ │ └── shaderview.vcxproj ├── ninja │ ├── android.py │ ├── clang.py │ ├── codesign.py │ ├── gcc.py │ ├── generator.py │ ├── msvc.py │ ├── platform.py │ ├── plist.py │ ├── syntax.py │ ├── toolchain.py │ ├── version.py │ ├── vslocate.py │ └── xcode.py ├── render.sublime-project └── xcode │ ├── ios │ ├── render.xcodeproj │ │ └── project.pbxproj │ └── test.xcodeproj │ │ └── project.pbxproj │ ├── macos │ ├── render.xcodeproj │ │ └── project.pbxproj │ └── test.xcodeproj │ │ └── project.pbxproj │ ├── render-ios.xcworkspace │ └── contents.xcworkspacedata │ └── render-macos.xcworkspace │ └── contents.xcworkspacedata ├── config └── test.json ├── configure.py ├── render ├── backend.c ├── backend.h ├── buffer.c ├── buffer.h ├── build.h ├── compile.c ├── compile.h ├── directx12 │ ├── backend.c │ └── backend.h ├── event.c ├── event.h ├── hashstrings.h ├── hashstrings.txt ├── import.c ├── import.h ├── internal.h ├── metal │ ├── backend.c │ ├── backend.h │ └── backend.m ├── null │ ├── backend.c │ └── backend.h ├── pipeline.c ├── pipeline.h ├── projection.c ├── projection.h ├── render.c ├── render.h ├── shader.c ├── shader.h ├── target.c ├── target.h ├── texture.c ├── texture.h ├── types.h ├── version.c └── vulkan │ ├── backend.c │ └── backend.h ├── resource ├── import.map └── shader │ ├── color.metal │ ├── color.shader │ ├── pipeline.metal │ ├── pipeline.shader │ ├── white.metal │ └── white.shader ├── test ├── all │ ├── android │ │ ├── AndroidManifest.xml │ │ ├── drawable-hdpi │ │ │ └── icon.png │ │ ├── drawable-ldpi │ │ │ └── icon.png │ │ ├── drawable-mdpi │ │ │ └── icon.png │ │ ├── drawable-xhdpi │ │ │ └── icon.png │ │ ├── drawable-xxhdpi │ │ │ └── icon.png │ │ ├── drawable-xxxhdpi │ │ │ └── icon.png │ │ ├── java │ │ │ └── com │ │ │ │ └── maniccoder │ │ │ │ └── render │ │ │ │ └── test │ │ │ │ └── TestActivity.java │ │ ├── layout │ │ │ └── main.xml │ │ └── values │ │ │ └── strings.xml │ ├── ios │ │ ├── Images.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ ├── Contents.json │ │ │ │ ├── icon_100.png │ │ │ │ ├── icon_114.png │ │ │ │ ├── icon_120.png │ │ │ │ ├── icon_144.png │ │ │ │ ├── icon_152.png │ │ │ │ ├── icon_180.png │ │ │ │ ├── icon_29-1.png │ │ │ │ ├── icon_29.png │ │ │ │ ├── icon_40.png │ │ │ │ ├── icon_50.png │ │ │ │ ├── icon_57.png │ │ │ │ ├── icon_58-1.png │ │ │ │ ├── icon_58.png │ │ │ │ ├── icon_72.png │ │ │ │ ├── icon_76.png │ │ │ │ ├── icon_80-1.png │ │ │ │ └── icon_80.png │ │ │ └── LaunchImage.launchimage │ │ │ │ ├── Contents.json │ │ │ │ ├── launch_1024_748.png │ │ │ │ ├── launch_1024_768.png │ │ │ │ ├── launch_1536_2008.png │ │ │ │ ├── launch_1536_2048.png │ │ │ │ ├── launch_2048_1496.png │ │ │ │ ├── launch_2048_1536.png │ │ │ │ ├── launch_320_480.png │ │ │ │ ├── launch_640_1136.png │ │ │ │ ├── launch_640_960.png │ │ │ │ ├── launch_768_1004.png │ │ │ │ └── launch_768_1024.png │ │ ├── test-all.plist │ │ ├── test-all.xib │ │ ├── viewcontroller.h │ │ └── viewcontroller.m │ ├── main.c │ └── tizen │ │ ├── res │ │ └── tizenapp.png │ │ └── tizen-manifest.xml └── render │ ├── macos │ ├── Images.xcassets │ │ ├── AppIcon-2.appiconset │ │ │ └── Contents.json │ │ └── AppIcon.appiconset │ │ │ ├── Contents.json │ │ │ ├── icon_1024.png │ │ │ ├── icon_128.png │ │ │ ├── icon_16.png │ │ │ ├── icon_256-1.png │ │ │ ├── icon_256.png │ │ │ ├── icon_32-1.png │ │ │ ├── icon_32.png │ │ │ ├── icon_512-1.png │ │ │ ├── icon_512.png │ │ │ └── icon_64.png │ ├── test-render.entitlements │ ├── test-render.plist │ └── test-render.xib │ └── main.c └── tools ├── rendercompile ├── errorcodes.h └── main.c ├── renderimport ├── errorcodes.h ├── main.c └── main.h └── shaderview └── main.c /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | AlignAfterOpenBracket: Align 3 | AlignConsecutiveAssignments: 'false' 4 | AlignConsecutiveDeclarations: 'false' 5 | AlignOperands: 'true' 6 | AlignTrailingComments: 'true' 7 | AllowAllParametersOfDeclarationOnNextLine: 'false' 8 | AllowShortBlocksOnASingleLine: 'false' 9 | AllowShortCaseLabelsOnASingleLine: 'false' 10 | AllowShortFunctionsOnASingleLine: None 11 | AllowShortIfStatementsOnASingleLine: 'false' 12 | AllowShortLoopsOnASingleLine: 'false' 13 | AlwaysBreakAfterDefinitionReturnType: TopLevel 14 | AlwaysBreakAfterReturnType: TopLevel 15 | AlwaysBreakBeforeMultilineStrings: 'true' 16 | AlwaysBreakTemplateDeclarations: 'true' 17 | BinPackArguments: 'true' 18 | BinPackParameters: 'true' 19 | BreakBeforeBinaryOperators: None 20 | BreakBeforeBraces: Attach 21 | BreakBeforeTernaryOperators: 'false' 22 | ColumnLimit: '120' 23 | ConstructorInitializerAllOnOneLineOrOnePerLine: 'false' 24 | DerivePointerAlignment: 'false' 25 | ExperimentalAutoDetectBinPacking: 'false' 26 | IndentCaseLabels: 'true' 27 | IndentWidth: '4' 28 | IndentWrappedFunctionNames: 'false' 29 | KeepEmptyLinesAtTheStartOfBlocks: 'false' 30 | MaxEmptyLinesToKeep: '1' 31 | NamespaceIndentation: None 32 | ObjCSpaceAfterProperty: 'true' 33 | ObjCSpaceBeforeProtocolList: 'true' 34 | PointerAlignment: Left 35 | SortIncludes: 'false' 36 | SpaceAfterCStyleCast: 'false' 37 | SpaceAfterTemplateKeyword: 'true' 38 | SpaceBeforeAssignmentOperators: 'true' 39 | SpaceBeforeParens: ControlStatements 40 | SpaceInEmptyParentheses: 'false' 41 | SpacesInAngles: 'false' 42 | SpacesInCStyleCastParentheses: 'false' 43 | SpacesInContainerLiterals: 'false' 44 | SpacesInParentheses: 'false' 45 | SpacesInSquareBrackets: 'false' 46 | TabWidth: '4' 47 | UseTab: ForIndentation 48 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Never mangle resource blob files 5 | *.blob -text 6 | 7 | # Custom for Visual Studio 8 | *.cs diff=csharp 9 | *.sln merge=union 10 | *.csproj merge=union 11 | *.vbproj merge=union 12 | *.fsproj merge=union 13 | *.dbproj merge=union 14 | 15 | # Standard to msysgit 16 | *.doc diff=astextplain 17 | *.DOC diff=astextplain 18 | *.docx diff=astextplain 19 | *.DOCX diff=astextplain 20 | *.dot diff=astextplain 21 | *.DOT diff=astextplain 22 | *.pdf diff=astextplain 23 | *.PDF diff=astextplain 24 | *.rtf diff=astextplain 25 | *.RTF diff=astextplain 26 | 27 | # Ignore build scripts in language stats 28 | build/* linguist-vendored 29 | configure.py linguist-vendored=true 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gitconfig 2 | *.pydevproject 3 | .project 4 | .metadata 5 | bin/ 6 | tmp/ 7 | *.tmp 8 | *.bak 9 | *.swp 10 | *~.nib 11 | local.properties 12 | .classpath 13 | .settings/ 14 | .loadpath 15 | .ninja* 16 | build.ninja 17 | 18 | # Generated version 19 | version.c 20 | 21 | # External tool builders 22 | .externalToolBuilders/ 23 | 24 | # Locally stored "Eclipse launch configurations" 25 | *.launch 26 | 27 | # CDT-specific 28 | .cproject 29 | 30 | # PDT-specific 31 | .buildpath 32 | 33 | #Android local build files 34 | build/android/assets 35 | build/android/libs 36 | 37 | #Xcode build 38 | build/xcode/foundation/build 39 | 40 | #Doxygen generated 41 | doc/html 42 | 43 | #Coverity scan 44 | cov-int/ 45 | cov-int.* 46 | 47 | ################# 48 | ## Visual Studio 49 | ################# 50 | 51 | ## Ignore Visual Studio temporary files, build results, and 52 | ## files generated by popular Visual Studio add-ons. 53 | 54 | # User-specific files 55 | *.suo 56 | *.user 57 | *.sln.docstates 58 | 59 | # Build results 60 | [Dd]ebug/ 61 | [Rr]elease/ 62 | [Pp]rofile/ 63 | [Dd]eploy/ 64 | *_i.c 65 | *_p.c 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.pch 70 | *.pchi 71 | *.pdb 72 | *.pgc 73 | *.pgd 74 | *.rsp 75 | *.sbr 76 | *.tlb 77 | *.tli 78 | *.tlh 79 | *.tmp 80 | *.vspscc 81 | .builds 82 | *.dotCover 83 | *.lastbuildstate 84 | *.unsuccessfulbuild 85 | *.opendb 86 | *.vc 87 | *.VC.db 88 | *.db-shm 89 | *.db-wal 90 | 91 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 92 | #packages/ 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opensdf 99 | *.sdf 100 | 101 | # Visual Studio profiler 102 | *.psess 103 | *.vsp 104 | 105 | # ReSharper is a .NET coding add-in 106 | _ReSharper* 107 | 108 | # Installshield output folder 109 | [Ee]xpress 110 | 111 | # DocProject is a documentation generator add-in 112 | DocProject/buildhelp/ 113 | DocProject/Help/*.HxT 114 | DocProject/Help/*.HxC 115 | DocProject/Help/*.hhc 116 | DocProject/Help/*.hhk 117 | DocProject/Help/*.hhp 118 | DocProject/Help/Html2 119 | DocProject/Help/html 120 | 121 | # Click-Once directory 122 | publish 123 | 124 | # Others 125 | [Bb]in 126 | [Oo]bj 127 | sql 128 | TestResults 129 | *.Cache 130 | ClientBin 131 | stylecop.* 132 | ~$* 133 | *.dbmdl 134 | Generated_Code #added for RIA/Silverlight projects 135 | 136 | # Backup & report files from converting an old project file to a newer 137 | # Visual Studio version. Backup files are not needed, because we have git ;-) 138 | _UpgradeReport_Files/ 139 | Backup*/ 140 | UpgradeLog*.XML 141 | 142 | 143 | ############ 144 | ## Windows 145 | ############ 146 | 147 | # Windows image file caches 148 | Thumbs.db 149 | 150 | # Folder config file 151 | Desktop.ini 152 | 153 | 154 | ############# 155 | ## Python 156 | ############# 157 | 158 | *.py[co] 159 | 160 | # Packages 161 | *.egg 162 | *.egg-info 163 | dist 164 | eggs 165 | parts 166 | var 167 | sdist 168 | develop-eggs 169 | .installed.cfg 170 | 171 | # Installer logs 172 | pip-log.txt 173 | 174 | # Unit test / coverage reports 175 | .coverage 176 | .tox 177 | 178 | #Translations 179 | *.mo 180 | 181 | #Mr Developer 182 | .mr.developer.cfg 183 | 184 | # Mac crap 185 | .DS_Store 186 | 187 | 188 | ############### 189 | ## Generic 190 | ############### 191 | 192 | #Project builds 193 | lib/** 194 | bin/** 195 | dist/** 196 | libs/** 197 | 198 | #Log files 199 | *.log 200 | *.tlog 201 | 202 | #Scons build 203 | .sconsign.dblite 204 | build/scons/debug* 205 | build/scons/release* 206 | build/scons/profi* 207 | build/scons/deploy* 208 | 209 | #Backups 210 | *~ 211 | 212 | #Object files 213 | *.o 214 | 215 | #XCode 216 | xcuserdata 217 | *.xccheckout 218 | xcshareddata 219 | 220 | #SublimeText local workspace 221 | *.sublime-workspace 222 | 223 | #Never store keystores in version control! 224 | *.keystore 225 | 226 | #Do not store local build prefs 227 | build.json 228 | codesign.json 229 | coveralls.json 230 | coverallsreport.json 231 | codecov.json 232 | codecovreport.json 233 | 234 | #Imported resource source files 235 | resource/source 236 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Render Library - Public Domain 2 | 3 | This library provides a cross-platform rendering library in C11 providing 4 | basic 2D/3D rendering functionality for projects based on our foundation library. 5 | 6 | The latest source code maintained by Mattias Jansson is always available at 7 | 8 | https://github.com/mjansson/render_lib 9 | 10 | The foundation library source code maintained by Mattias Jansson is always available at 11 | 12 | https://github.com/mjansson/foundation_lib 13 | 14 | This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | 16 | -------------------------------------------------------------------------------- /build/msvc/render.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Win32Proj 5 | render 6 | 10.0 7 | StaticLibrary 8 | {54B53CC6-0852-47EB-9864-35B0CEC69DC7} 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | $(IntDir)backend.directx12.obj 25 | $(IntDir)backend.directx12.obj 26 | $(IntDir)backend.directx12.obj 27 | $(IntDir)backend.directx12.obj 28 | 29 | 30 | 31 | 32 | $(IntDir)backend.metal.obj 33 | $(IntDir)backend.metal.obj 34 | $(IntDir)backend.metal.obj 35 | $(IntDir)backend.metal.obj 36 | 37 | 38 | $(IntDir)backend.null.obj 39 | $(IntDir)backend.null.obj 40 | $(IntDir)backend.null.obj 41 | $(IntDir)backend.null.obj 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | $(IntDir)backend.vulkan.obj 51 | $(IntDir)backend.vulkan.obj 52 | $(IntDir)backend.vulkan.obj 53 | $(IntDir)backend.vulkan.obj 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | $(ProjectDir)..\..\..\foundation;$(ProjectDir)..\..\..\foundation_lib;$(ProjectDir)..\..\..\window;$(ProjectDir)..\..\..\window_lib;$(ProjectDir)..\..\..\resource;$(ProjectDir)..\..\..\resource_lib;$(ProjectDir)..\..\..\task;$(ProjectDir)..\..\..\task_lib;$(ProjectDir)..\..\..\vector;$(ProjectDir)..\..\..\vector_lib;$(VK_SDK_PATH)\Include;%(AdditionalIncludeDirectories) 84 | RENDER_COMPILE=1;%(PreprocessorDefinitions) 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /build/msvc/render.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {1c5ef782-edbd-424e-bbd7-609c7b908a0d} 6 | 7 | 8 | {dd3e7e2b-65a9-4e8a-99a4-97f91235ae40} 9 | 10 | 11 | {cafa6f9e-ee5c-40c8-b5c8-3eb75b6c875b} 12 | 13 | 14 | {d98cf1ad-a2ee-4414-9844-865ec75bac8d} 15 | 16 | 17 | 18 | 19 | null 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | directx12 34 | 35 | 36 | metal 37 | 38 | 39 | vulkan 40 | 41 | 42 | 43 | 44 | null 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | directx12 61 | 62 | 63 | metal 64 | 65 | 66 | vulkan 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | metal 75 | 76 | 77 | -------------------------------------------------------------------------------- /build/msvc/test/all.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /build/msvc/test/render.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {0741c629-8ac4-4b4d-981a-6d56408d6afe} 5 | Win32Proj 6 | render 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | $(Platform)\$(Configuration)\$(ProjectName)\ 19 | test-$(ProjectName) 20 | true 21 | ..\..\..\bin\windows\debug\x86-64\ 22 | 23 | 24 | $(Platform)\$(Configuration)\$(ProjectName)\ 25 | test-$(ProjectName) 26 | false 27 | ..\..\..\bin\windows\release\x86-64\ 28 | 29 | 30 | $(Platform)\$(Configuration)\$(ProjectName)\ 31 | test-$(ProjectName) 32 | false 33 | ..\..\..\bin\windows\deploy\x86-64\ 34 | 35 | 36 | $(Platform)\$(Configuration)\$(ProjectName)\ 37 | test-$(ProjectName) 38 | false 39 | ..\..\..\bin\windows\profile\x86-64\ 40 | 41 | 42 | 43 | 44 | 45 | 46 | {54b53cc6-0852-47eb-9864-35b0cec69dc7} 47 | 48 | 49 | 50 | 51 | $(ProjectDir)..\..\..;$(ProjectDir)..\..\..\..\foundation\test;$(ProjectDir)..\..\..\..\foundation_lib\test;$(ProjectDir)..\..\..\..\foundation;$(ProjectDir)..\..\..\..\foundation_lib;$(ProjectDir)..\..\..\..\window;$(ProjectDir)..\..\..\..\window_lib;$(ProjectDir)..\..\..\..\resource;$(ProjectDir)..\..\..\..\resource_lib;$(ProjectDir)..\..\..\..\network;$(ProjectDir)..\..\..\..\network_lib;$(ProjectDir)..\..\..\..\task;$(ProjectDir)..\..\..\..\task_lib;$(ProjectDir)..\..\..\..\vector;$(ProjectDir)..\..\..\..\vector_lib;%(AdditionalIncludeDirectories) 52 | 53 | 54 | window.lib;resource.lib;network.lib;vector.lib;test.lib;foundation.lib;vulkan-1.lib;%(AdditionalDependencies) 55 | $(SolutionDir)..\..\..\window_lib\lib\windows\debug\x86-64;$(SolutionDir)..\..\..\window\lib\windows\debug\x86-64;$(SolutionDir)..\..\..\resource_lib\lib\windows\debug\x86-64;$(SolutionDir)..\..\..\resource\lib\windows\debug\x86-64;$(SolutionDir)..\..\..\foundation_lib\lib\windows\debug\x86-64;$(SolutionDir)..\..\..\foundation\lib\windows\debug\x86-64;$(SolutionDir)..\..\..\..\..\lib\windows\debug\x86-64;$(VULKAN_SDK)\Lib 56 | $(SolutionDir)..\..\..\window_lib\lib\windows\release\x86-64;$(SolutionDir)..\..\..\window\lib\windows\release\x86-64;$(SolutionDir)..\..\..\resource_lib\lib\windows\release\x86-64;$(SolutionDir)..\..\..\resource\lib\windows\release\x86-64;$(SolutionDir)..\..\..\foundation_lib\lib\windows\release\x86-64;$(SolutionDir)..\..\..\foundation\lib\windows\release\x86-64;$(SolutionDir)..\..\..\..\..\lib\windows\release\x86-64;$(VULKAN_SDK)\Lib 57 | $(SolutionDir)..\..\..\window_lib\lib\windows\profile\x86-64;$(SolutionDir)..\..\..\window\lib\windows\profile\x86-64;$(SolutionDir)..\..\..\resource_lib\lib\windows\profile\x86-64;$(SolutionDir)..\..\..\resource\lib\windows\profile\x86-64;$(SolutionDir)..\..\..\foundation_lib\lib\windows\profile\x86-64;$(SolutionDir)..\..\..\foundation\lib\windows\profile\x86-64;$(SolutionDir)..\..\..\..\..\lib\windows\profile\x86-64;$(VULKAN_SDK)\Lib 58 | $(SolutionDir)..\..\..\window_lib\lib\windows\deploy\x86-64;$(SolutionDir)..\..\..\window\lib\windows\deploy\x86-64;$(SolutionDir)..\..\..\resource_lib\lib\windows\deploy\x86-64;$(SolutionDir)..\..\..\resource\lib\windows\deploy\x86-64;$(SolutionDir)..\..\..\foundation_lib\lib\windows\deploy\x86-64;$(SolutionDir)..\..\..\foundation\lib\windows\deploy\x86-64;$(SolutionDir)..\..\..\..\..\lib\windows\deploy\x86-64;$(VULKAN_SDK)\Lib 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /build/msvc/test/render.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /build/msvc/tools/rendercompile.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Win32Proj 5 | render 6 | 10.0 7 | Application 8 | {FED88C5B-49D6-4B96-95D2-1C14B89800CA} 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | {54b53cc6-0852-47eb-9864-35b0cec69dc7} 28 | 29 | 30 | 31 | 32 | $(ProjectDir)..\..\..;..\..\..\..\window_lib;..\..\..\..\window;..\..\..\..\network_lib;..\..\..\..\network;..\..\..\..\resource_lib;..\..\..\..\resource;..\..\..\..\task_lib;..\..\..\..\task;..\..\..\..\vector_lib;..\..\..\..\vector;..\..\..\..\foundation_lib;..\..\..\..\foundation;%(AdditionalIncludeDirectories) 33 | 34 | 35 | vulkan-1.lib;window.lib;resource.lib;network.lib;task.lib;vector.lib;foundation.lib;%(AdditionalDependencies) 36 | $(VK_SDK_PATH)\Lib;%(AdditionalLibraryDirectories) 37 | $(VK_SDK_PATH)\Lib;%(AdditionalLibraryDirectories) 38 | $(VK_SDK_PATH)\Lib;%(AdditionalLibraryDirectories) 39 | $(VK_SDK_PATH)\Lib;%(AdditionalLibraryDirectories) 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /build/msvc/tools/renderimport.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Win32Proj 5 | render 6 | 10.0 7 | Application 8 | {887E994B-5AF1-41D7-89D9-7AAD8D4EE1FF} 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | {54b53cc6-0852-47eb-9864-35b0cec69dc7} 28 | 29 | 30 | 31 | 32 | $(ProjectDir)..\..\..;..\..\..\..\window_lib;..\..\..\..\window;..\..\..\..\network_lib;..\..\..\..\network;..\..\..\..\resource_lib;..\..\..\..\resource;..\..\..\..\task_lib;..\..\..\..\task;..\..\..\..\vector_lib;..\..\..\..\vector;..\..\..\..\foundation_lib;..\..\..\..\foundation;%(AdditionalIncludeDirectories) 33 | 34 | 35 | vulkan-1.lib;window.lib;resource.lib;network.lib;task.lib;vector.lib;foundation.lib;%(AdditionalDependencies) 36 | $(VK_SDK_PATH)\Lib;%(AdditionalLibraryDirectories) 37 | $(VK_SDK_PATH)\Lib;%(AdditionalLibraryDirectories) 38 | $(VK_SDK_PATH)\Lib;%(AdditionalLibraryDirectories) 39 | $(VK_SDK_PATH)\Lib;%(AdditionalLibraryDirectories) 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /build/msvc/tools/shaderview.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Win32Proj 5 | render 6 | 10.0 7 | Application 8 | {901226D7-BF1C-4C30-9830-098961AA0855} 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | {54b53cc6-0852-47eb-9864-35b0cec69dc7} 28 | 29 | 30 | 31 | 32 | $(ProjectDir)..\..\..;..\..\..\..\window_lib;..\..\..\..\window;..\..\..\..\network_lib;..\..\..\..\network;..\..\..\..\resource_lib;..\..\..\..\resource;..\..\..\..\task_lib;..\..\..\..\task;..\..\..\..\vector_lib;..\..\..\..\vector;..\..\..\..\foundation_lib;..\..\..\..\foundation;%(AdditionalIncludeDirectories) 33 | 34 | 35 | vulkan-1.lib;window.lib;resource.lib;network.lib;task.lib;vector.lib;foundation.lib;%(AdditionalDependencies) 36 | $(VK_SDK_PATH)\Lib;%(AdditionalLibraryDirectories) 37 | $(VK_SDK_PATH)\Lib;%(AdditionalLibraryDirectories) 38 | $(VK_SDK_PATH)\Lib;%(AdditionalLibraryDirectories) 39 | $(VK_SDK_PATH)\Lib;%(AdditionalLibraryDirectories) 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /build/ninja/generator.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """Ninja build generator""" 4 | 5 | import argparse 6 | import os 7 | import pipes 8 | import sys 9 | 10 | import platform 11 | import toolchain 12 | import syntax 13 | 14 | class Generator(object): 15 | def __init__(self, project, includepaths = [], dependlibs = [], libpaths = [], variables = None): 16 | parser = argparse.ArgumentParser(description = 'Ninja build generator') 17 | parser.add_argument('-t', '--target', 18 | help = 'Target platform', 19 | choices = platform.supported_platforms()) 20 | parser.add_argument('--host', 21 | help = 'Host platform', 22 | choices = platform.supported_platforms()) 23 | parser.add_argument('--toolchain', 24 | help = 'Toolchain to use', 25 | choices = toolchain.supported_toolchains()) 26 | parser.add_argument('-c', '--config', action = 'append', 27 | help = 'Build configuration', 28 | choices = ['debug', 'release', 'profile', 'deploy'], 29 | default = []) 30 | parser.add_argument('-a', '--arch', action = 'append', 31 | help = 'Add architecture', 32 | choices = toolchain.supported_architectures(), 33 | default = []) 34 | parser.add_argument('-i', '--includepath', action = 'append', 35 | help = 'Add include path', 36 | default = []) 37 | parser.add_argument('--monolithic', action='store_true', 38 | help = 'Build monolithic test suite', 39 | default = False) 40 | parser.add_argument('--coverage', action='store_true', 41 | help = 'Build with code coverage', 42 | default = False) 43 | parser.add_argument('--subninja', action='store', 44 | help = 'Build as subproject (exclude rules and pools) with the given subpath', 45 | default = '') 46 | parser.add_argument('--buildprefs', action='store', 47 | help = 'Read the given build preferences file', 48 | default = '') 49 | parser.add_argument('--updatebuild', action='store_true', 50 | help = 'Update submodule build scripts', 51 | default = '') 52 | parser.add_argument('--lto', action='store_true', 53 | help = 'Build with Link Time Optimization', 54 | default = False) 55 | options = parser.parse_args() 56 | 57 | self.project = project 58 | self.target = platform.Platform(options.target) 59 | self.host = platform.Platform(options.host) 60 | self.subninja = options.subninja 61 | archs = options.arch 62 | configs = options.config 63 | if includepaths is None: 64 | includepaths = [] 65 | if not options.includepath is None: 66 | includepaths += options.includepath 67 | 68 | buildfile = open('build.ninja', 'w') 69 | self.writer = syntax.Writer(buildfile) 70 | 71 | self.writer.variable('ninja_required_version', '1.3') 72 | self.writer.newline() 73 | 74 | self.writer.comment('configure.py arguments') 75 | self.writer.variable('configure_args', ' '.join(sys.argv[1:])) 76 | self.writer.newline() 77 | 78 | self.writer.comment('configure options') 79 | self.writer.variable('configure_target', self.target.platform) 80 | self.writer.variable('configure_host', self.host.platform) 81 | 82 | env_keys = set(['CC', 'AR', 'LINK', 'CFLAGS', 'ARFLAGS', 'LINKFLAGS']) 83 | configure_env = dict((key, os.environ[key]) for key in os.environ if key in env_keys) 84 | if configure_env: 85 | config_str = ' '.join([key + '=' + pipes.quote(configure_env[key]) for key in configure_env]) 86 | self.writer.variable('configure_env', config_str + '$ ') 87 | 88 | if variables is None: 89 | variables = {} 90 | if not isinstance(variables, dict): 91 | variables = dict(variables) 92 | 93 | if options.monolithic: 94 | variables['monolithic'] = True 95 | if options.coverage: 96 | variables['coverage'] = True 97 | if options.lto: 98 | variables['lto'] = True 99 | if self.subninja != '': 100 | variables['internal_deps'] = True 101 | 102 | self.toolchain = toolchain.make_toolchain(self.host, self.target, options.toolchain) 103 | self.toolchain.buildprefs = options.buildprefs 104 | self.toolchain.initialize(project, archs, configs, includepaths, dependlibs, libpaths, variables, self.subninja) 105 | 106 | self.writer.variable('configure_toolchain', self.toolchain.name()) 107 | self.writer.variable('configure_archs', archs) 108 | self.writer.variable('configure_configs', configs) 109 | self.writer.newline() 110 | 111 | self.toolchain.write_variables(self.writer) 112 | if self.subninja == '': 113 | self.toolchain.write_rules(self.writer) 114 | 115 | def target(self): 116 | return self.target 117 | 118 | def host(self): 119 | return self.host 120 | 121 | def toolchain(self): 122 | return self.toolchain 123 | 124 | def writer(self): 125 | return self.writer 126 | 127 | def is_subninja(self): 128 | return self.subninja != '' 129 | 130 | def lib(self, module, sources, libname = None, basepath = None, configs = None, includepaths = None, variables = None): 131 | return self.toolchain.lib(self.writer, module, sources, libname, basepath, configs, includepaths, variables) 132 | 133 | def sharedlib(self, module, sources, libname = None, basepath = None, configs = None, includepaths = None, libpaths = None, implicit_deps = None, dependlibs = None, libs = None, frameworks = None, variables = None): 134 | return self.toolchain.sharedlib(self.writer, module, sources, libname, basepath, configs, includepaths, libpaths, implicit_deps, dependlibs, libs, frameworks, variables) 135 | 136 | def bin(self, module, sources, binname, basepath = None, configs = None, includepaths = None, libpaths = None, implicit_deps = None, dependlibs = None, libs = None, frameworks = None, variables = None): 137 | return self.toolchain.bin(self.writer, module, sources, binname, basepath, configs, includepaths, libpaths, implicit_deps, dependlibs, libs, frameworks, variables) 138 | 139 | def app(self, module, sources, binname, basepath = None, configs = None, includepaths = None, libpaths = None, implicit_deps = None, dependlibs = None, libs = None, frameworks = None, variables = None, resources = None): 140 | return self.toolchain.app(self.writer, module, sources, binname, basepath, configs, includepaths, libpaths, implicit_deps, dependlibs, libs, frameworks, variables, resources) 141 | 142 | def test_includepaths(self): 143 | #TODO: This is ugly 144 | if self.project == "foundation": 145 | return ['test'] 146 | foundation_path = os.path.join('..', 'foundation_lib') 147 | if not os.path.isfile(os.path.join(foundation_path, 'foundation', 'foundation.h')): 148 | foundation_path = os.path.join('..', 'foundation') 149 | return ['test', os.path.join(foundation_path, 'test')] 150 | 151 | def test_monolithic(self): 152 | return self.toolchain.is_monolithic() 153 | -------------------------------------------------------------------------------- /build/ninja/platform.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """Ninja platform abstraction""" 4 | 5 | import sys 6 | 7 | def supported_platforms(): 8 | return [ 'windows', 'linux', 'macos', 'bsd', 'ios', 'android', 'raspberrypi', 'tizen', 'sunos', 'haiku' ] 9 | 10 | class Platform(object): 11 | def __init__(self, platform): 12 | self.platform = platform 13 | if self.platform is None: 14 | self.platform = sys.platform 15 | if self.platform.startswith('linux'): 16 | self.platform = 'linux' 17 | elif self.platform.startswith('darwin'): 18 | self.platform = 'macos' 19 | elif self.platform.startswith('macos'): 20 | self.platform = 'macos' 21 | elif self.platform.startswith('win'): 22 | self.platform = 'windows' 23 | elif 'bsd' in self.platform or self.platform.startswith('dragonfly'): 24 | self.platform = 'bsd' 25 | elif self.platform.startswith('ios'): 26 | self.platform = 'ios' 27 | elif self.platform.startswith('android'): 28 | self.platform = 'android' 29 | elif self.platform.startswith('raspberry'): 30 | self.platform = 'raspberrypi' 31 | elif self.platform.startswith('tizen'): 32 | self.platform = 'tizen' 33 | elif self.platform.startswith('sunos'): 34 | self.platform = 'sunos' 35 | elif self.platform.startswith('haiku'): 36 | self.platform = 'haiku' 37 | 38 | def platform(self): 39 | return self.platform 40 | 41 | def is_linux(self): 42 | return self.platform == 'linux' 43 | 44 | def is_windows(self): 45 | return self.platform == 'windows' 46 | 47 | def is_macos(self): 48 | return self.platform == 'macos' 49 | 50 | def is_bsd(self): 51 | return self.platform == 'bsd' 52 | 53 | def is_ios(self): 54 | return self.platform == 'ios' 55 | 56 | def is_android(self): 57 | return self.platform == 'android' 58 | 59 | def is_raspberrypi(self): 60 | return self.platform == 'raspberrypi' 61 | 62 | def is_tizen(self): 63 | return self.platform == 'tizen' 64 | 65 | def is_sunos(self): 66 | return self.platform == 'sunos' 67 | 68 | def is_haiku(self): 69 | return self.platform == 'haiku' 70 | 71 | def get(self): 72 | return self.platform 73 | -------------------------------------------------------------------------------- /build/ninja/plist.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """PList utility""" 4 | 5 | import argparse 6 | import os 7 | import subprocess 8 | import re 9 | import unicodedata 10 | 11 | def normalize_char(c): 12 | try: 13 | UNICODE_EXISTS = bool(type(unicode)) 14 | except NameError: 15 | unicode = lambda s: str(s) 16 | try: 17 | cname = unicodedata.name( unicode(c) ) 18 | cname = cname[:cname.index( ' WITH' )] 19 | return unicodedata.lookup( cname ) 20 | except ( ValueError, KeyError ): 21 | return c 22 | 23 | def normalize_string(s): 24 | return ''.join( normalize_char(c) for c in s ) 25 | 26 | def replace_var( str, var, val ): 27 | if str.find( '$(' + var + ')' ) != -1: 28 | return str.replace( '$(' + var + ')', val ) 29 | if str.find( '${' + var + '}' ) != -1: 30 | return str.replace( '${' + var + '}', val ) 31 | return str 32 | 33 | 34 | parser = argparse.ArgumentParser( description = 'PList utility for Ninja builds' ) 35 | parser.add_argument( 'files', 36 | metavar = 'file', type=open, nargs='+', 37 | help = 'Source plist file' ) 38 | parser.add_argument( '--exename', type=str, 39 | help = 'Executable name', 40 | default = [] ) 41 | parser.add_argument( '--prodname', type=str, 42 | help = 'Product name', 43 | default = [] ) 44 | parser.add_argument( '--bundle', type=str, 45 | help = 'Bundle identifier', 46 | default = [] ) 47 | parser.add_argument( '--output', type=str, 48 | help = 'Output path', 49 | default = [] ) 50 | parser.add_argument( '--target', type=str, 51 | help = 'Target OS', 52 | default = [] ) 53 | parser.add_argument( '--deploymenttarget', type=str, 54 | help = 'Target OS version', 55 | default = [] ) 56 | options = parser.parse_args() 57 | 58 | if not options.exename: 59 | options.exename = 'unknown' 60 | if not options.prodname: 61 | options.prodname = 'unknown' 62 | if not options.target: 63 | options.target = 'macos' 64 | if not options.deploymenttarget: 65 | if options.target == 'macos': 66 | options.deploymenttarget = '12.0' 67 | else: 68 | options.deploymenttarget = '10.0' 69 | 70 | buildversion = subprocess.check_output( [ 'sw_vers', '-buildVersion' ] ).decode().strip() 71 | 72 | #Merge input plists using first file as base 73 | lines = [] 74 | for f in options.files: 75 | _, extension = os.path.splitext(f.name) 76 | if extension != '.plist': 77 | continue 78 | if lines == []: 79 | lines += [ line.strip( '\n\r' ) for line in f ] 80 | else: 81 | mergelines = [ line.strip( '\n\r' ) for line in f ] 82 | for i in range( 0, len( mergelines ) ): 83 | if re.match( '^$', mergelines[i] ): 84 | break 85 | if re.match( '^$', mergelines[i] ): 86 | for j in range( 0, len( lines ) ): 87 | if re.match( '^$', lines[j] ): 88 | for k in range( i+1, len( mergelines ) ): 89 | if re.match( '^$', mergelines[k] ): 90 | break 91 | lines.insert( j+(k-(i+1)), mergelines[k] ) 92 | break 93 | break 94 | 95 | #Parse input plist to get package type and signature 96 | bundle_package_type = 'APPL' 97 | bundle_signature = '????' 98 | 99 | for i in range( 0, len( lines ) ): 100 | if 'CFBundlePackageType' in lines[i]: 101 | match = re.match( '^.*>(.*)<.*$', lines[i+1] ) 102 | if match: 103 | bundle_package_type = match.group(1) 104 | if 'CFBundleSignature' in lines[i]: 105 | match = re.match( '^.*>(.*)<.*$', lines[i+1] ) 106 | if match: 107 | bundle_signature = match.group(1) 108 | 109 | #Write package type and signature to PkgInfo in output path 110 | with open( os.path.join( os.path.dirname( options.output ), 'PkgInfo' ), 'w' ) as pkginfo_file: 111 | pkginfo_file.write( bundle_package_type + bundle_signature ) 112 | pkginfo_file.close() 113 | 114 | #insert os version 115 | for i in range( 0, len( lines ) ): 116 | if re.match( '^$', lines[i] ): 117 | lines.insert( i+1, '\tBuildMachineOSBuild' ) 118 | lines.insert( i+2, '\t' + buildversion + '' ) 119 | break 120 | 121 | #replace build variables name 122 | for i in range( 0, len( lines ) ): 123 | lines[i] = replace_var( lines[i], 'EXECUTABLE_NAME', options.exename ) 124 | lines[i] = replace_var( lines[i], 'PRODUCT_NAME', options.prodname ) 125 | lines[i] = replace_var( lines[i], 'PRODUCT_NAME:rfc1034identifier', normalize_string( options.exename ).lower() ) 126 | lines[i] = replace_var( lines[i], 'PRODUCT_NAME:c99extidentifier', normalize_string( options.exename ).lower().replace( '-', '_' ).replace( '.', '_' ) ) 127 | lines[i] = replace_var( lines[i], 'IOS_DEPLOYMENT_TARGET', options.deploymenttarget ) 128 | lines[i] = replace_var( lines[i], 'MACOSX_DEPLOYMENT_TARGET', options.deploymenttarget ) 129 | 130 | #replace bundle identifier if given 131 | if not options.bundle is None and options.bundle != '': 132 | for i in range( 0, len( lines ) ): 133 | if lines[i].find( 'CFBundleIdentifier' ) != -1: 134 | lines[i+1] = '\t' + normalize_string( options.bundle ) + '' 135 | break 136 | 137 | #add supported platform, minimum os version and requirements 138 | if options.target == 'ios': 139 | for i in range( 0, len( lines ) ): 140 | if 'CFBundleSignature' in lines[i]: 141 | lines.insert( i+2, '\tCFBundleSupportedPlatforms' ) 142 | lines.insert( i+3, '\t' ) 143 | lines.insert( i+4, '\t\tiPhoneOS' ) 144 | lines.insert( i+5, '\t' ) 145 | lines.insert( i+6, '\tMinimumOSVersion' ) 146 | lines.insert( i+7, '\t6.0' ) 147 | lines.insert( i+8, '\tUIDeviceFamily' ) 148 | lines.insert( i+9, '\t' ) 149 | lines.insert( i+10, '\t\t1' ) 150 | lines.insert( i+11, '\t\t2' ) 151 | lines.insert( i+12, '\t' ) 152 | break 153 | 154 | #add build info 155 | #DTCompiler 156 | #com.apple.compilers.llvm.clang.1_0 157 | #DTPlatformBuild 158 | #12B411 159 | #DTPlatformName 160 | #iphoneos 161 | #DTPlatformVersion 162 | #8.1 163 | #DTSDKBuild 164 | #12B411 165 | #DTSDKName 166 | #iphoneos8.1 167 | #DTXcode 168 | #0611 169 | #DTXcodeBuild 170 | #6A2008a 171 | 172 | #write final Info.plist in output path 173 | with open( options.output, 'w' ) as plist_file: 174 | for line in lines: 175 | #print lines[i] 176 | plist_file.write( line + '\n' ) 177 | plist_file.close() 178 | 179 | #run plutil -convert binary1 180 | sdk = 'iphoneos' 181 | platformpath = subprocess.check_output( [ 'xcrun', '--sdk', sdk, '--show-sdk-platform-path' ] ).decode().strip() 182 | localpath = platformpath + "/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" 183 | plutil = "PATH=" + localpath + " " + subprocess.check_output( [ 'xcrun', '--sdk', sdk, '-f', 'plutil' ] ).decode().strip() 184 | plcommand = plutil + ' -convert binary1 ' + options.output 185 | os.system( plcommand ) 186 | -------------------------------------------------------------------------------- /build/ninja/syntax.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """Python module for generating .ninja files. 4 | 5 | Note that this is emphatically not a required piece of Ninja; it's 6 | just a helpful utility for build-file-generation systems that already 7 | use Python. 8 | """ 9 | 10 | import textwrap 11 | 12 | def escape_path(word): 13 | return word.replace('$ ', '$$ ').replace(' ', '$ ').replace(':', '$:') 14 | 15 | class Writer(object): 16 | def __init__(self, output, width=78): 17 | self.output = output 18 | self.width = width 19 | 20 | def newline(self): 21 | self.output.write('\n') 22 | 23 | def comment(self, text): 24 | for line in textwrap.wrap(text, self.width - 2): 25 | self.output.write('# ' + line + '\n') 26 | 27 | def variable(self, key, value, indent=0): 28 | if value is None: 29 | return 30 | if isinstance(value, list): 31 | value = ' '.join(filter(None, value)) # Filter out empty strings. 32 | self._line('%s = %s' % (key, value), indent) 33 | 34 | def pool(self, name, depth): 35 | self._line('pool %s' % name) 36 | self.variable('depth', depth, indent=1) 37 | 38 | def rule(self, name, command, description=None, depfile=None, 39 | generator=False, pool=None, restat=False, rspfile=None, 40 | rspfile_content=None, deps=None): 41 | self._line('rule %s' % name) 42 | self.variable('command', command, indent=1) 43 | if description: 44 | self.variable('description', description, indent=1) 45 | if depfile: 46 | self.variable('depfile', depfile, indent=1) 47 | if generator: 48 | self.variable('generator', '1', indent=1) 49 | if pool: 50 | self.variable('pool', pool, indent=1) 51 | if restat: 52 | self.variable('restat', '1', indent=1) 53 | if rspfile: 54 | self.variable('rspfile', rspfile, indent=1) 55 | if rspfile_content: 56 | self.variable('rspfile_content', rspfile_content, indent=1) 57 | if deps: 58 | self.variable('deps', deps, indent=1) 59 | 60 | def build(self, outputs, rule, inputs=None, implicit=None, order_only=None, 61 | variables=None): 62 | outputs = self._as_list(outputs) 63 | out_outputs = [escape_path(x) for x in outputs] 64 | all_inputs = [escape_path(x) for x in self._as_list(inputs)] 65 | 66 | if implicit: 67 | implicit = [escape_path(x) for x in self._as_list(implicit)] 68 | all_inputs.append('|') 69 | all_inputs.extend(implicit) 70 | if order_only: 71 | order_only = [escape_path(x) for x in self._as_list(order_only)] 72 | all_inputs.append('||') 73 | all_inputs.extend(order_only) 74 | 75 | self._line('build %s: %s' % (' '.join(out_outputs), 76 | ' '.join([rule] + all_inputs))) 77 | 78 | if variables: 79 | if isinstance(variables, dict): 80 | iterator = iter(variables.items()) 81 | else: 82 | iterator = iter(variables) 83 | 84 | for key, val in iterator: 85 | self.variable(key, val, indent=1) 86 | 87 | return outputs 88 | 89 | def include(self, path): 90 | self._line('include %s' % path) 91 | 92 | def subninja(self, path): 93 | self._line('subninja %s' % path) 94 | 95 | def default(self, paths): 96 | self._line('default %s' % ' '.join(self._as_list(paths))) 97 | 98 | def _count_dollars_before_index(self, s, i): 99 | """Returns the number of '$' characters right in front of s[i].""" 100 | dollar_count = 0 101 | dollar_index = i - 1 102 | while dollar_index > 0 and s[dollar_index] == '$': 103 | dollar_count += 1 104 | dollar_index -= 1 105 | return dollar_count 106 | 107 | def _line(self, text, indent=0): 108 | """Write 'text' word-wrapped at self.width characters.""" 109 | leading_space = ' ' * indent 110 | while len(leading_space) + len(text) > self.width: 111 | # The text is too wide; wrap if possible. 112 | 113 | # Find the rightmost space that would obey our width constraint and 114 | # that's not an escaped space. 115 | available_space = self.width - len(leading_space) - len(' $') 116 | space = available_space 117 | while True: 118 | space = text.rfind(' ', 0, space) 119 | if (space < 0 or 120 | self._count_dollars_before_index(text, space) % 2 == 0): 121 | break 122 | 123 | if space < 0: 124 | # No such space; just use the first unescaped space we can find. 125 | space = available_space - 1 126 | while True: 127 | space = text.find(' ', space + 1) 128 | if (space < 0 or 129 | self._count_dollars_before_index(text, space) % 2 == 0): 130 | break 131 | if space < 0: 132 | # Give up on breaking. 133 | break 134 | 135 | self.output.write(leading_space + text[0:space] + ' $\n') 136 | text = text[space+1:] 137 | 138 | # Subsequent lines are continuations, so indent them. 139 | leading_space = ' ' * (indent+2) 140 | 141 | self.output.write(leading_space + text + '\n') 142 | 143 | def _as_list(self, input): 144 | if input is None: 145 | return [] 146 | if isinstance(input, list): 147 | return input 148 | return [input] 149 | 150 | 151 | def escape(string): 152 | """Escape a string such that it can be embedded into a Ninja file without 153 | further interpretation.""" 154 | assert '\n' not in string, 'Ninja syntax does not allow newlines' 155 | # We only have one special metacharacter: '$'. 156 | return string.replace('$', '$$') 157 | -------------------------------------------------------------------------------- /build/ninja/version.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """Version utility""" 4 | 5 | import subprocess 6 | import os 7 | import sys 8 | 9 | def generate_version_string(libname): 10 | 11 | version_numbers = [] 12 | tokens = [] 13 | 14 | gitcmd = 'git' 15 | if sys.platform.startswith('win'): 16 | gitcmd = 'git.exe' 17 | try: 18 | git_version = subprocess.check_output( [ gitcmd, 'describe', '--tags', '--long' ], stderr = subprocess.STDOUT ).strip() 19 | tokens = git_version.decode().split( '-' ) 20 | version_numbers = tokens[0].split( '.' ) 21 | except Exception: 22 | pass 23 | 24 | version_major = "0" 25 | version_minor = "0" 26 | version_revision = "1" 27 | version_build = "0" 28 | version_scm = "0" 29 | 30 | if version_numbers and len( version_numbers ) > 2: 31 | version_major = version_numbers[0] 32 | version_minor = version_numbers[1] 33 | version_revision = version_numbers[2] 34 | 35 | if tokens and len( tokens ) > 2: 36 | version_build = tokens[1] 37 | version_scm = tokens[2][1:] 38 | 39 | module = "" 40 | if not libname == "foundation": 41 | module = "_module" 42 | 43 | source = """/* ****** AUTOMATICALLY GENERATED, DO NOT EDIT ****** 44 | This file is generated from the git describe command. 45 | Run the configure script to regenerate this file */ 46 | 47 | #include 48 | #include <""" + libname + "/" + libname + """.h> 49 | 50 | version_t 51 | """ + libname + module + """_version(void) { 52 | """ 53 | source += " return version_make(" + version_major + ", " + version_minor + ", " + version_revision + ", " + version_build + ", 0x" + version_scm + ");\n}\n" 54 | return source 55 | 56 | def read_version_string(input_path): 57 | try: 58 | file = open( os.path.join( input_path, 'version.c' ), "r" ) 59 | str = file.read() 60 | file.close() 61 | except IOError: 62 | str = "" 63 | return str 64 | 65 | def write_version_string(output_path, str): 66 | file = open( os.path.join( output_path, 'version.c' ), "w" ) 67 | file.write( str ) 68 | file.close 69 | 70 | def generate_version(libname, output_path): 71 | generated = generate_version_string(libname) 72 | if generated == None: 73 | return 74 | previous = read_version_string(output_path) 75 | 76 | if generated != previous: 77 | write_version_string(output_path, generated) 78 | 79 | if __name__ == "__main__": 80 | generate_version(sys.argv[1], sys.argv[2]) 81 | -------------------------------------------------------------------------------- /build/ninja/vslocate.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """Locate Visual Studio installations with Visual Studio Setup Configuration utility DLL""" 4 | 5 | import os 6 | import ctypes 7 | 8 | def get_vs_installations(): 9 | 10 | class ISetupInstanceVTable(ctypes.Structure): 11 | """Class matching VisualStudio Setup package ISetupInstance vtable""" 12 | pass 13 | 14 | class ISetupInstance(ctypes.Structure): 15 | """COM interface for ISetupInstance""" 16 | _fields_ = [('vtable', ctypes.POINTER(ISetupInstanceVTable))] 17 | 18 | class IEnumSetupInstancesVTable(ctypes.Structure): 19 | """Class matching VisualStudio Setup package IEnumSetupInstances vtable""" 20 | pass 21 | 22 | class IEnumSetupInstances(ctypes.Structure): 23 | """COM interface for IEnumSetupInstances""" 24 | _fields_ = [('vtable', ctypes.POINTER(IEnumSetupInstancesVTable))] 25 | 26 | class ISetupConfigurationVTable(ctypes.Structure): 27 | """Class matching VisualStudio Setup package ISetupConfiguration vtable""" 28 | pass 29 | 30 | class ISetupConfiguration(ctypes.Structure): 31 | """COM interface for ISetupConfiguration""" 32 | _fields_ = [('vtable', ctypes.POINTER(ISetupConfigurationVTable))] 33 | 34 | proto_get_installation_path = ctypes.WINFUNCTYPE( 35 | ctypes.c_int, 36 | ctypes.POINTER(ISetupInstance), 37 | ctypes.POINTER(ctypes.c_wchar_p)) 38 | 39 | proto_get_installation_version = ctypes.WINFUNCTYPE( 40 | ctypes.c_int, 41 | ctypes.POINTER(ISetupInstance), 42 | ctypes.POINTER(ctypes.c_wchar_p)) 43 | 44 | ISetupInstanceVTable._fields_ = ( 45 | ('QueryInterface', ctypes.c_void_p), 46 | ('AddRef', ctypes.c_void_p), 47 | ('Release', ctypes.c_void_p), 48 | ('GetInstanceId', ctypes.c_void_p), 49 | ('GetInstallDate', ctypes.c_void_p), 50 | ('GetInstallationName', ctypes.c_void_p), 51 | ('GetInstallationPath', proto_get_installation_path), 52 | ('GetInstallationVersion', proto_get_installation_version), 53 | ('GetDisplayName', ctypes.c_void_p), 54 | ('GetDescription', ctypes.c_void_p), 55 | ('ResolvePath', ctypes.c_void_p)) 56 | 57 | proto_next = ctypes.WINFUNCTYPE( 58 | ctypes.c_int, 59 | ctypes.POINTER(IEnumSetupInstances), 60 | ctypes.c_int, 61 | ctypes.POINTER(ctypes.POINTER(ISetupInstance)), 62 | ctypes.POINTER(ctypes.c_int)) 63 | 64 | IEnumSetupInstancesVTable._fields_ = ( 65 | ('QueryInterface', ctypes.c_void_p), 66 | ('AddRef', ctypes.c_void_p), 67 | ('Release', ctypes.c_void_p), 68 | ('Next', proto_next), 69 | ('Skip', ctypes.c_void_p), 70 | ('Reset', ctypes.c_void_p), 71 | ('Clone', ctypes.c_void_p)) 72 | 73 | proto_enum_instances = ctypes.WINFUNCTYPE( 74 | ctypes.c_int, 75 | ctypes.POINTER(ISetupConfiguration), 76 | ctypes.POINTER(ctypes.POINTER(IEnumSetupInstances))) 77 | 78 | ISetupConfigurationVTable._fields_ = ( 79 | ('QueryInterface', ctypes.c_void_p), 80 | ('AddRef', ctypes.c_void_p), 81 | ('Release', ctypes.c_void_p), 82 | ('EnumInstances', proto_enum_instances), 83 | ('GetInstanceForCurrentProcess', ctypes.c_void_p), 84 | ('GetInstanceForPath', ctypes.c_void_p)) 85 | 86 | proto_get_setup_configuration = ctypes.WINFUNCTYPE( 87 | ctypes.c_int, 88 | ctypes.POINTER(ctypes.POINTER(ISetupConfiguration)), 89 | ctypes.c_void_p) 90 | 91 | installations = [] 92 | dll = None 93 | 94 | dll_path = os.path.expandvars("$ProgramData\\Microsoft\\VisualStudio\\Setup\\x64\\Microsoft.VisualStudio.Setup.Configuration.Native.dll") 95 | try: 96 | dll = ctypes.WinDLL(dll_path) 97 | except OSError as e: 98 | #print("Failed to load Visual Studio setup configuration DLL: " + str(e)) 99 | return installations 100 | 101 | params_get_setup_configuration = (1, "configuration", 0), (1, "reserved", 0), 102 | 103 | get_setup_configuration = proto_get_setup_configuration(("GetSetupConfiguration", dll), params_get_setup_configuration) 104 | 105 | configuration = ctypes.POINTER(ISetupConfiguration)() 106 | reserved = ctypes.c_void_p(0) 107 | 108 | result = get_setup_configuration(ctypes.byref(configuration), reserved) 109 | if result != 0: 110 | #print("Failed to get setup configuration: " + str(result)) 111 | return installations 112 | 113 | enum_instances = configuration.contents.vtable.contents.EnumInstances 114 | 115 | enum_setup_instances = ctypes.POINTER(IEnumSetupInstances)() 116 | result = enum_instances(configuration, ctypes.byref(enum_setup_instances)) 117 | if result != 0: 118 | #print("Failed to enum setup instances: " + str(result)) 119 | return installations 120 | 121 | 122 | setup_instance = ctypes.POINTER(ISetupInstance)() 123 | fetched = ctypes.c_int(0) 124 | 125 | while True: 126 | next = enum_setup_instances.contents.vtable.contents.Next 127 | result = next(enum_setup_instances, 1, ctypes.byref(setup_instance), ctypes.byref(fetched)) 128 | if result == 1 or fetched == 0: 129 | break 130 | if result != 0: 131 | #print("Failed to get next setup instance: " + str(result)) 132 | break 133 | 134 | version = ctypes.c_wchar_p() 135 | path = ctypes.c_wchar_p() 136 | 137 | get_installation_version = setup_instance.contents.vtable.contents.GetInstallationVersion 138 | get_installation_path = setup_instance.contents.vtable.contents.GetInstallationPath 139 | 140 | result = get_installation_version(setup_instance, ctypes.byref(version)) 141 | if result != 0: 142 | #print("Failed to get setup instance version: " + str(result)) 143 | break 144 | 145 | result = get_installation_path(setup_instance, ctypes.byref(path)) 146 | if result != 0: 147 | #print("Failed to get setup instance version: " + str(result)) 148 | break 149 | 150 | installations.append((version.value, path.value)) 151 | 152 | return installations 153 | 154 | 155 | if __name__ == "__main__": 156 | 157 | installations = get_vs_installations() 158 | 159 | for version, path in installations: 160 | print(version + " " + path) 161 | -------------------------------------------------------------------------------- /build/render.sublime-project: -------------------------------------------------------------------------------- 1 | { 2 | "folders": 3 | [ 4 | { 5 | "follow_symlinks": true, 6 | "path": "../render" 7 | }, 8 | { 9 | "follow_symlinks": true, 10 | "path": "../resource" 11 | }, 12 | { 13 | "follow_symlinks": true, 14 | "path": "../test" 15 | }, 16 | { 17 | "follow_symlinks": true, 18 | "path": "../tools" 19 | }, 20 | { 21 | "follow_symlinks": true, 22 | "path": "../config" 23 | }, 24 | { 25 | "follow_symlinks": true, 26 | "path": "../doc" 27 | } 28 | ], 29 | "build_systems": 30 | [ 31 | { 32 | "name": "Ninja", 33 | "shell_cmd": "ninja", 34 | "working_dir": "${project_path:${folder:${file_path}}}/..", 35 | } 36 | ], 37 | "translate_tabs_to_spaces": false, 38 | "use_tab_stops": true, 39 | "trim_trailing_white_space_on_save": true, 40 | "settings": 41 | { 42 | "AStyleFormatter": 43 | { 44 | "options_default": 45 | { 46 | "style" : "attach", 47 | "pad-oper": true, 48 | "indent-switches" : false, 49 | "indent-cases" : true, 50 | "unpad-paren": true, 51 | "break-closing-brackets": true, 52 | "align-pointer": "type", 53 | "max-code-length": 100, 54 | "max-instatement-indent": 60, 55 | "break-after-logical": true 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /build/xcode/render-ios.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /build/xcode/render-macos.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /config/test.json: -------------------------------------------------------------------------------- 1 | { 2 | "resource" : { 3 | "local_path": "../resource/bin", 4 | "source_path": "../resource/source", 5 | "autoimport_path": "../resource" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /configure.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """Ninja build configurator for window library""" 4 | 5 | import sys 6 | import os 7 | 8 | sys.path.insert(0, os.path.join('build', 'ninja')) 9 | 10 | import generator 11 | 12 | dependlibs = ['resource', 'vector', 'window', 'network', 'task', 'blake3', 'foundation'] 13 | 14 | libpaths = [] 15 | includepaths = [] 16 | if "VK_SDK_PATH" in os.environ: 17 | includepaths += [os.path.expandvars(os.path.join('$VK_SDK_PATH', 'Include'))] 18 | libpaths += [os.path.expandvars(os.path.join('$VK_SDK_PATH', 'Lib'))] 19 | 20 | generator = generator.Generator(project='render', dependlibs=dependlibs, includepaths=includepaths, libpaths=libpaths, 21 | variables=[('bundleidentifier', 'com.maniccoder.render.$(binname)')]) 22 | target = generator.target 23 | writer = generator.writer 24 | toolchain = generator.toolchain 25 | 26 | render_lib = generator.lib(module='render', sources=[ 27 | 'backend.c', 'buffer.c', 'compile.c', 'event.c', 'import.c', 'pipeline.c', 'projection.c', 'render.c', 28 | 'shader.c', 'target.c', 'version.c', 29 | os.path.join('directx12', 'backend.c'), 30 | os.path.join('metal', 'backend.m'), os.path.join('metal', 'backend.c'), 31 | os.path.join('vulkan', 'backend.c'), 32 | os.path.join('null', 'backend.c') 33 | ]) 34 | 35 | extralibs = [] 36 | gfxlibs = [] 37 | gfxframeworks = [] 38 | if target.is_macos(): 39 | gfxframeworks = ['Metal', 'QuartzCore', 'CoreGraphics', 'Carbon'] 40 | elif target.is_ios(): 41 | gfxframeworks = ['Metal', 'QuartzCore', 'OpenGLES'] 42 | if target.is_windows(): 43 | gfxlibs = ['vulkan-1', 'gdi32', 'iphlpapi', 'ws2_32'] 44 | extralibs = ['iphlpapi', 'ws2_32'] 45 | if target.is_linux(): 46 | gfxlibs = ['vulkan', 'Xxf86vm', 'Xext', 'X11', 'GL'] 47 | 48 | dependlibs = ['render'] + dependlibs 49 | linklibs = gfxlibs + extralibs 50 | 51 | if not target.is_ios() and not target.is_android() and not target.is_tizen(): 52 | configs = [config for config in toolchain.configs if config not in [ 53 | 'profile', 'deploy']] 54 | if not configs == []: 55 | generator.bin('renderimport', ['main.c'], 'renderimport', basepath='tools', implicit_deps=[ 56 | render_lib], dependlibs=dependlibs, libs=linklibs, frameworks=gfxframeworks, configs=configs) 57 | generator.bin('rendercompile', ['main.c'], 'rendercompile', basepath='tools', implicit_deps=[ 58 | render_lib], dependlibs=dependlibs, libs=linklibs, frameworks=gfxframeworks, configs=configs) 59 | 60 | includepaths = generator.test_includepaths() 61 | 62 | dependlibs = ['test'] + dependlibs 63 | 64 | test_cases = [ 65 | 'render' 66 | ] 67 | if toolchain.is_monolithic() or target.is_ios() or target.is_android() or target.is_tizen(): 68 | # Build one fat binary with all test cases 69 | test_resources = [] 70 | test_extrasources = [] 71 | test_cases += ['all'] 72 | if target.is_ios(): 73 | test_resources = [os.path.join('all', 'ios', item) for item in [ 74 | 'test-all.plist', 'Images.xcassets', 'test-all.xib']] 75 | test_extrasources = [os.path.join('all', 'ios', 'viewcontroller.m')] 76 | elif target.is_android(): 77 | test_resources = [os.path.join('all', 'android', item) for item in [ 78 | 'AndroidManifest.xml', os.path.join( 79 | 'layout', 'main.xml'), os.path.join('values', 'strings.xml'), 80 | os.path.join('drawable-ldpi', 'icon.png'), os.path.join('drawable-mdpi', 81 | 'icon.png'), os.path.join('drawable-hdpi', 'icon.png'), 82 | os.path.join('drawable-xhdpi', 'icon.png'), os.path.join('drawable-xxhdpi', 83 | 'icon.png'), os.path.join('drawable-xxxhdpi', 'icon.png') 84 | ]] 85 | test_extrasources = [os.path.join('all', 'android', 'java', 'com', 'maniccoder', 'render', 'test', item) for item in [ 86 | 'TestActivity.java' 87 | ]] 88 | elif target.is_tizen(): 89 | test_resources = [os.path.join('all', 'tizen', item) for item in [ 90 | 'tizen-manifest.xml', os.path.join('res', 'tizenapp.png') 91 | ]] 92 | if target.is_macos() or target.is_ios() or target.is_android() or target.is_tizen(): 93 | generator.app(module='', sources=[os.path.join(module, 'main.c') for module in test_cases] + test_extrasources, binname='test-all-render', 94 | basepath='test', implicit_deps=[render_lib], libs=linklibs, frameworks=gfxframeworks, resources=test_resources, includepaths=includepaths) 95 | else: 96 | generator.bin(module='', sources=[os.path.join(module, 'main.c') for module in test_cases] + test_extrasources, binname='test-all-render', 97 | basepath='test', implicit_deps=[render_lib], libs=linklibs, frameworks=gfxframeworks, resources=test_resources, includepaths=includepaths) 98 | else: 99 | # Build one binary per test case 100 | if not generator.is_subninja(): 101 | generator.bin(module='all', sources=['main.c'], binname='test-all', basepath='test', 102 | implicit_deps=[render_lib], libs=['render'] + dependlibs + extralibs, includepaths=includepaths) 103 | for test in test_cases: 104 | if target.is_macos(): 105 | test_resources = [os.path.join('macos', item) for item in [ 106 | 'test-' + test + '.plist', 'test-' + test + '.entitlements', 'Images.xcassets', 'test-' + test + '.xib']] 107 | generator.app(module=test, sources=['main.c'], binname='test-' + test, basepath='test', implicit_deps=[ 108 | render_lib], dependlibs=dependlibs, libs=linklibs, frameworks=gfxframeworks, resources=test_resources, includepaths=includepaths) 109 | else: 110 | generator.bin(module=test, sources=['main.c'], binname='test-' + test, basepath='test', implicit_deps=[ 111 | render_lib], dependlibs=dependlibs, libs=linklibs, frameworks=gfxframeworks, includepaths=includepaths) 112 | -------------------------------------------------------------------------------- /render/backend.c: -------------------------------------------------------------------------------- 1 | /* backend.c - Render library - Public Domain - 2014 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any 15 | * restrictions. 16 | * 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | FOUNDATION_DECLARE_THREAD_LOCAL(render_backend_t*, backend, nullptr) 32 | 33 | static render_api_t 34 | render_api_fallback(render_api_t api) { 35 | switch (api) { 36 | case RENDERAPI_UNKNOWN: 37 | return RENDERAPI_UNKNOWN; 38 | 39 | case RENDERAPI_DEFAULT: 40 | #if FOUNDATION_PLATFORM_WINDOWS 41 | return RENDERAPI_VULKAN; 42 | #elif FOUNDATION_PLATFORM_APPLE 43 | return RENDERAPI_METAL; 44 | #else 45 | return RENDERAPI_NULL; 46 | #endif 47 | 48 | case RENDERAPI_NULL: 49 | return RENDERAPI_UNKNOWN; 50 | 51 | case RENDERAPI_VULKAN: 52 | #if FOUNDATION_PLATFORM_WINDOWS 53 | return RENDERAPI_DIRECTX; 54 | #else 55 | return RENDERAPI_NULL; 56 | #endif 57 | 58 | case RENDERAPI_DIRECTX: 59 | return RENDERAPI_DIRECTX12; 60 | 61 | case RENDERAPI_DIRECTX12: 62 | return RENDERAPI_NULL; 63 | 64 | case RENDERAPI_METAL: 65 | case RENDERAPI_COUNT: 66 | return RENDERAPI_NULL; 67 | 68 | default: 69 | break; 70 | } 71 | return RENDERAPI_UNKNOWN; 72 | } 73 | 74 | render_backend_t** 75 | render_backends(void) { 76 | return render_backends_current; 77 | } 78 | 79 | render_backend_t* 80 | render_backend_allocate(render_api_t api, bool allow_fallback) { 81 | // First find best matching supported backend 82 | render_backend_t* backend = 0; 83 | 84 | memory_context_push(HASH_RENDER); 85 | 86 | if (api == RENDERAPI_DEFAULT) 87 | allow_fallback = true; 88 | 89 | while (!backend) { 90 | while (render_api_disabled[api]) 91 | api = render_api_fallback(api); 92 | switch (api) { 93 | case RENDERAPI_DIRECTX12: 94 | backend = render_backend_directx12_allocate(); 95 | if (!backend || !backend->vtable.construct(backend)) { 96 | log_info(HASH_RENDER, STRING_CONST("Failed to initialize DirectX 12 render backend")); 97 | render_backend_deallocate(backend); 98 | backend = nullptr; 99 | } 100 | break; 101 | 102 | case RENDERAPI_METAL: 103 | backend = render_backend_metal_allocate(); 104 | if (!backend || !backend->vtable.construct(backend)) { 105 | log_info(HASH_RENDER, STRING_CONST("Failed to initialize Metal render backend")); 106 | render_backend_deallocate(backend); 107 | backend = nullptr; 108 | } 109 | break; 110 | 111 | case RENDERAPI_VULKAN: 112 | backend = render_backend_vulkan_allocate(); 113 | if (!backend || !backend->vtable.construct(backend)) { 114 | log_info(HASH_RENDER, STRING_CONST("Failed to initialize Vulkan render backend")); 115 | render_backend_deallocate(backend); 116 | backend = nullptr; 117 | } 118 | break; 119 | 120 | case RENDERAPI_NULL: 121 | backend = render_backend_null_allocate(); 122 | if (!backend || !backend->vtable.construct(backend)) { 123 | log_info(HASH_RENDER, STRING_CONST("Failed to initialize null render backend")); 124 | render_backend_deallocate(backend); 125 | backend = nullptr; 126 | } 127 | break; 128 | 129 | case RENDERAPI_UNKNOWN: 130 | log_warn(HASH_RENDER, WARNING_SUSPICIOUS, 131 | STRING_CONST("No supported and enabled render api found, giving up")); 132 | return 0; 133 | 134 | case RENDERAPI_COUNT: 135 | case RENDERAPI_DEFAULT: 136 | case RENDERAPI_DIRECTX: 137 | default: 138 | // Try loading dynamic library 139 | log_warnf(HASH_RENDER, WARNING_SUSPICIOUS, 140 | STRING_CONST("Unknown render API (%u), dynamic library loading not implemented yet"), api); 141 | break; 142 | } 143 | 144 | if (!backend) { 145 | if (!allow_fallback) { 146 | log_warn(HASH_RENDER, WARNING_UNSUPPORTED, STRING_CONST("Requested render api not supported")); 147 | return 0; 148 | } 149 | 150 | api = render_api_fallback(api); 151 | } 152 | } 153 | 154 | backend->framecount = 1; 155 | 156 | uuidmap_initialize((uuidmap_t*)&backend->shader_table, 157 | sizeof(backend->shader_table.bucket) / sizeof(backend->shader_table.bucket[0]), 0); 158 | 159 | render_backend_set_resource_platform(backend, 0); 160 | 161 | array_push(render_backends_current, backend); 162 | 163 | memory_context_pop(); 164 | 165 | set_thread_backend(backend); 166 | 167 | return backend; 168 | } 169 | 170 | void 171 | render_backend_deallocate(render_backend_t* backend) { 172 | if (!backend) 173 | return; 174 | 175 | backend->vtable.destruct(backend); 176 | 177 | uuidmap_finalize((uuidmap_t*)&backend->shader_table); 178 | 179 | for (size_t ib = 0, bsize = array_size(render_backends_current); ib < bsize; ++ib) { 180 | if (render_backends_current[ib] == backend) { 181 | array_erase(render_backends_current, ib); 182 | break; 183 | } 184 | } 185 | 186 | memory_deallocate(backend); 187 | } 188 | 189 | render_api_t 190 | render_backend_api(render_backend_t* backend) { 191 | return backend ? backend->api : RENDERAPI_UNKNOWN; 192 | } 193 | 194 | size_t 195 | render_backend_enumerate_adapters(render_backend_t* backend, unsigned int* store, size_t capacity) { 196 | return backend->vtable.enumerate_adapters(backend, store, capacity); 197 | } 198 | 199 | size_t 200 | render_backend_enumerate_modes(render_backend_t* backend, unsigned int adapter, render_resolution_t* store, 201 | size_t capacity) { 202 | return backend->vtable.enumerate_modes(backend, adapter, store, capacity); 203 | } 204 | 205 | uint64_t 206 | render_backend_frame_count(render_backend_t* backend) { 207 | return backend->framecount; 208 | } 209 | 210 | render_backend_t* 211 | render_backend_thread(void) { 212 | return get_thread_backend(); 213 | } 214 | 215 | uint64_t 216 | render_backend_resource_platform(render_backend_t* backend) { 217 | return backend->platform; 218 | } 219 | 220 | void 221 | render_backend_set_resource_platform(render_backend_t* backend, uint64_t platform) { 222 | resource_platform_t decl = resource_platform_decompose(platform); 223 | decl.render_api_group = (int)backend->api_group; 224 | decl.render_api = (int)backend->api; 225 | backend->platform = resource_platform(decl); 226 | } 227 | 228 | bool 229 | render_backend_shader_upload(render_backend_t* backend, render_shader_t* shader, const void* buffer, size_t size) { 230 | return backend->vtable.shader_upload(backend, shader, buffer, size); 231 | } 232 | 233 | void 234 | render_backend_shader_finalize(render_backend_t* backend, render_shader_t* shader) { 235 | backend->vtable.shader_finalize(backend, shader); 236 | } 237 | -------------------------------------------------------------------------------- /render/backend.h: -------------------------------------------------------------------------------- 1 | /* backend.h - Render library - Public Domain - 2014 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any 15 | * restrictions. 16 | * 17 | */ 18 | 19 | #pragma once 20 | 21 | /*! \file backend.h 22 | Render backend */ 23 | 24 | #include 25 | 26 | #include 27 | 28 | RENDER_API render_backend_t* 29 | render_backend_allocate(render_api_t api, bool allow_fallback); 30 | 31 | RENDER_API void 32 | render_backend_deallocate(render_backend_t* backend); 33 | 34 | RENDER_API render_api_t 35 | render_backend_api(render_backend_t* backend); 36 | 37 | RENDER_API size_t 38 | render_backend_enumerate_adapters(render_backend_t* backend, unsigned int* store, size_t capacity); 39 | 40 | RENDER_API size_t 41 | render_backend_enumerate_modes(render_backend_t* backend, unsigned int adapter, render_resolution_t* store, 42 | size_t capacity); 43 | 44 | RENDER_API uint64_t 45 | render_backend_frame_count(render_backend_t* backend); 46 | 47 | RENDER_API render_backend_t* 48 | render_backend_thread(void); 49 | 50 | RENDER_API uint64_t 51 | render_backend_resource_platform(render_backend_t* backend); 52 | 53 | RENDER_API void 54 | render_backend_set_resource_platform(render_backend_t* backend, uint64_t platform); 55 | 56 | RENDER_API render_backend_t** 57 | render_backends(void); 58 | 59 | RENDER_API bool 60 | render_backend_shader_upload(render_backend_t* backend, render_shader_t* shader, const void* buffer, size_t size); 61 | 62 | RENDER_API void 63 | render_backend_shader_finalize(render_backend_t* backend, render_shader_t* shader); 64 | 65 | #define render_backend_shader_table(backend) ((uuidmap_t*)&((backend)->shader_table)) 66 | -------------------------------------------------------------------------------- /render/buffer.c: -------------------------------------------------------------------------------- 1 | /* buffer.c - Render library - Public Domain - 2014 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | render_buffer_t* 24 | render_buffer_allocate(render_backend_t* backend, render_usage_t usage, size_t buffer_size, const void* data, 25 | size_t data_size) { 26 | render_buffer_t* buffer = 27 | memory_allocate(HASH_RENDER, sizeof(render_buffer_t), 0, MEMORY_PERSISTENT | MEMORY_ZERO_INITIALIZED); 28 | buffer->backend = backend; 29 | buffer->usage = (uint8_t)usage; 30 | semaphore_initialize(&buffer->lock, 1); 31 | memset(buffer->backend_data, 0, sizeof(buffer->backend_data)); 32 | if (buffer_size) 33 | backend->vtable.buffer_allocate(backend, buffer, buffer_size, data, data_size); 34 | return buffer; 35 | } 36 | 37 | void 38 | render_buffer_deallocate(render_buffer_t* buffer) { 39 | if (buffer) { 40 | buffer->backend->vtable.buffer_deallocate(buffer->backend, buffer, true, true); 41 | semaphore_finalize(&buffer->lock); 42 | memory_deallocate(buffer); 43 | } 44 | } 45 | 46 | void 47 | render_buffer_upload(render_buffer_t* buffer, size_t offset, size_t size) { 48 | if (buffer->flags & RENDERBUFFER_DIRTY) { 49 | buffer->backend->vtable.buffer_upload(buffer->backend, buffer, offset, size); 50 | buffer->flags &= ~(uint)RENDERBUFFER_DIRTY; 51 | } 52 | } 53 | 54 | void 55 | render_buffer_lock(render_buffer_t* buffer, unsigned int lock) { 56 | if (buffer->usage == RENDERUSAGE_GPUONLY) 57 | return; 58 | semaphore_wait(&buffer->lock); 59 | { 60 | buffer->locks++; 61 | buffer->access = buffer->store; 62 | buffer->flags |= (lock & RENDERBUFFER_LOCK_BITS); 63 | } 64 | semaphore_post(&buffer->lock); 65 | } 66 | 67 | void 68 | render_buffer_unlock(render_buffer_t* buffer) { 69 | semaphore_wait(&buffer->lock); 70 | if (buffer->locks) { 71 | --buffer->locks; 72 | if (!buffer->locks) { 73 | buffer->access = nullptr; 74 | if (buffer->flags & RENDERBUFFER_LOCK_WRITE) { 75 | buffer->flags |= RENDERBUFFER_DIRTY; 76 | if ((buffer->flags & RENDERBUFFER_LOCK_WRITE_ALL) == RENDERBUFFER_LOCK_WRITE_ALL) 77 | render_buffer_upload(buffer, 0, 0); 78 | } 79 | buffer->flags &= ~(uint32_t)RENDERBUFFER_LOCK_BITS; 80 | } 81 | } 82 | semaphore_post(&buffer->lock); 83 | } 84 | 85 | void 86 | render_buffer_data_declare(render_buffer_t* buffer, size_t instance_count, const render_buffer_data_t* data, 87 | size_t data_count) { 88 | buffer->backend->vtable.buffer_data_declare(buffer->backend, buffer, instance_count, data, data_count); 89 | } 90 | 91 | void 92 | render_buffer_data_encode_buffer(render_buffer_t* buffer, uint instance, uint index, render_buffer_t* source, 93 | uint offset) { 94 | buffer->backend->vtable.buffer_data_encode_buffer(buffer->backend, buffer, instance, index, source, offset); 95 | } 96 | 97 | void 98 | render_buffer_data_encode_matrix(render_buffer_t* buffer, uint instance, uint index, const matrix_t* matrix) { 99 | buffer->backend->vtable.buffer_data_encode_matrix(buffer->backend, buffer, instance, index, matrix); 100 | } 101 | 102 | void 103 | render_buffer_data_encode_constant(render_buffer_t* buffer, uint instance, uint index, const void* data, uint size) { 104 | buffer->backend->vtable.buffer_data_encode_constant(buffer->backend, buffer, instance, index, data, size); 105 | } 106 | 107 | void 108 | render_buffer_set_label(render_buffer_t* buffer, const char* name, size_t length) { 109 | #if BUILD_DEBUG || BUILD_RELEASE 110 | buffer->backend->vtable.buffer_set_label(buffer->backend, buffer, name, length); 111 | #endif 112 | FOUNDATION_UNUSED(buffer, name, length); 113 | } 114 | -------------------------------------------------------------------------------- /render/buffer.h: -------------------------------------------------------------------------------- 1 | /* buffer.h - Render library - Public Domain - 2014 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #pragma once 19 | 20 | /*! \file buffer.h 21 | Buffer storing arbitrary data on CPU and GPU accessible memory */ 22 | 23 | #include 24 | 25 | #include 26 | 27 | RENDER_API render_buffer_t* 28 | render_buffer_allocate(render_backend_t* backend, uint usage, size_t buffer_size, const void* data, size_t data_size); 29 | 30 | RENDER_API void 31 | render_buffer_deallocate(render_buffer_t* buffer); 32 | 33 | RENDER_API void 34 | render_buffer_lock(render_buffer_t* buffer, unsigned int lock); 35 | 36 | RENDER_API void 37 | render_buffer_dirty(render_buffer_t* buffer, size_t offset, size_t size); 38 | 39 | RENDER_API void 40 | render_buffer_unlock(render_buffer_t* buffer); 41 | 42 | RENDER_API void 43 | render_buffer_upload(render_buffer_t* buffer, size_t offset, size_t size); 44 | 45 | RENDER_API void 46 | render_buffer_free(render_buffer_t* buffer, bool sys, bool aux); 47 | 48 | RENDER_API void 49 | render_buffer_restore(render_buffer_t* buffer); 50 | 51 | RENDER_API void 52 | render_buffer_data_declare(render_buffer_t* buffer, size_t instance_count, const render_buffer_data_t* data, 53 | size_t data_count); 54 | 55 | RENDER_API void 56 | render_buffer_data_encode_buffer(render_buffer_t* buffer, uint instance, uint index, render_buffer_t* source, 57 | uint offset); 58 | 59 | RENDER_API void 60 | render_buffer_data_encode_matrix(render_buffer_t* buffer, uint instance, uint index, const matrix_t* data); 61 | 62 | RENDER_API void 63 | render_buffer_data_encode_constant(render_buffer_t* buffer, uint instance, uint index, const void* data, uint size); 64 | 65 | RENDER_API void 66 | render_buffer_set_label(render_buffer_t* buffer, const char* name, size_t length); 67 | -------------------------------------------------------------------------------- /render/build.h: -------------------------------------------------------------------------------- 1 | /* build.h - Render library - Public Domain - 2013 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #pragma once 19 | 20 | /*! \file build.h 21 | Build setup */ 22 | 23 | #include 24 | 25 | #if defined(RENDER_COMPILE) && RENDER_COMPILE 26 | #ifdef __cplusplus 27 | #define RENDER_EXTERN extern "C" 28 | #define RENDER_API extern "C" 29 | #else 30 | #define RENDER_EXTERN extern 31 | #define RENDER_API extern 32 | #endif 33 | #else 34 | #ifdef __cplusplus 35 | #define RENDER_EXTERN extern "C" 36 | #define RENDER_API extern "C" 37 | #else 38 | #define RENDER_EXTERN extern 39 | #define RENDER_API extern 40 | #endif 41 | #endif 42 | 43 | // Allocation sizes 44 | -------------------------------------------------------------------------------- /render/compile.h: -------------------------------------------------------------------------------- 1 | /* compile.h - Render library - Public Domain - 2013 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #pragma once 19 | 20 | /*! \file compile.h 21 | Render library resource compilation */ 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | /* Compile render resource 29 | \param uuid Resource UUID 30 | \param platform Resource platform 31 | \param source Resource source representation 32 | \param type Type string 33 | \param type_length Length of type string 34 | \return 0 if successful, <0 if error */ 35 | RENDER_API int 36 | render_compile(const uuid_t uuid, uint64_t platform, resource_source_t* source, const blake3_hash_t source_hash, 37 | const char* type, size_t type_length); 38 | -------------------------------------------------------------------------------- /render/directx12/backend.h: -------------------------------------------------------------------------------- 1 | /* backend.h - Render library - Public Domain - 2022 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #pragma once 19 | 20 | /*! \file dx12/backend.h 21 | DirectX 12 render backend */ 22 | 23 | #include 24 | #include 25 | 26 | RENDER_API render_backend_t* 27 | render_backend_directx12_allocate(void); 28 | -------------------------------------------------------------------------------- /render/event.c: -------------------------------------------------------------------------------- 1 | /* event.c - Render library - Public Domain - 2014 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | void 29 | render_event_handle_resource(const event_t* event) { 30 | if ((event->id != RESOURCEEVENT_MODIFY) && (event->id != RESOURCEEVENT_DEPENDS)) 31 | return; 32 | 33 | const uuid_t uuid = resource_event_uuid(event); 34 | 35 | render_backend_t** backends = render_backends(); 36 | for (size_t ib = 0, bsize = array_size(backends); ib < bsize; ++ib) { 37 | render_backend_t* backend = backends[ib]; 38 | 39 | render_shader_t* shader = render_shader_lookup(backend, uuid); 40 | if (shader) { 41 | string_const_t uuidstr = string_from_uuid_static(uuid); 42 | log_debugf(HASH_RENDER, STRING_CONST("Resource event trigger shader reload: %.*s"), STRING_FORMAT(uuidstr)); 43 | 44 | render_shader_reload(shader, uuid); 45 | render_shader_unload(shader); 46 | continue; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /render/event.h: -------------------------------------------------------------------------------- 1 | /* event.h - Render library - Public Domain - 2014 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #pragma once 19 | 20 | /*! \file event.h 21 | Render library event handling */ 22 | 23 | #include 24 | 25 | #include 26 | 27 | /*! Handle resource events. No other event types should be 28 | passed to this function. 29 | \param event Resource event */ 30 | RENDER_API void 31 | render_event_handle_resource(const event_t* event); 32 | -------------------------------------------------------------------------------- /render/hashstrings.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | /* ****** AUTOMATICALLY GENERATED, DO NOT EDIT ****** 6 | Edit corresponding definitions file and rerun 7 | the foundation hashify tool to update this file */ 8 | 9 | #define HASH_RENDER static_hash_string("render", 6, 0xa4479cf9994d11adULL) 10 | #define HASH_API static_hash_string("api", 3, 0x180bbc7ca85a83f7ULL) 11 | #define HASH_DIRECTX12 static_hash_string("directx12", 9, 0x9b1167f6dfd8794eULL) 12 | #define HASH_METAL static_hash_string("metal", 5, 0xbdbab32cc1d7c491ULL) 13 | #define HASH_D3D_DEVICE_REF static_hash_string("d3d_device_ref", 14, 0xd5556aa98d2b4461ULL) 14 | #define HASH_D3D_DEVICE_DEBUG static_hash_string("d3d_device_debug", 16, 0x88f632265968bc35ULL) 15 | #define HASH_D3D_SHADER_DEBUG static_hash_string("d3d_shader_debug", 16, 0xd1be125e006c56e3ULL) 16 | #define HASH_PARAMETER_COUNT static_hash_string("parameter_count", 15, 0x2b2a2cd816c9cf3dULL) 17 | #define HASH_SHADER static_hash_string("shader", 6, 0x65475a9f9c166495ULL) 18 | #define HASH_SHADER_DIRECTX12 static_hash_string("shader_directx12", 16, 0xda40a824b5a787bULL) 19 | #define HASH_SHADER_METAL static_hash_string("shader_metal", 12, 0x95b2922f423fb543ULL) 20 | #define HASH_TEXTURE static_hash_string("texture", 7, 0x4b61d4f340e798f6ULL) 21 | #define HASH_TRANSFORM_MVP static_hash_string("transform_mvp", 13, 0x8b76b4155281b642ULL) 22 | #define HASH_TRANSFORM_MODEL static_hash_string("transform_model", 15, 0x967b3246fd50ab84ULL) 23 | #define HASH_TEX static_hash_string("tex", 3, 0x35bf00462d0bc065ULL) 24 | #define HASH_PARAMETERS static_hash_string("parameters", 10, 0x5f1a2f492b495d26ULL) 25 | #define HASH_ALBEDO static_hash_string("albedo", 6, 0x6b280d23c5140b85ULL) 26 | #define HASH_OCCLUSION static_hash_string("occlusion", 9, 0xa6db7755a05f91f6ULL) 27 | #define HASH_ROUGHNESS static_hash_string("roughness", 9, 0x9909a5f616c2bfb6ULL) 28 | #define HASH_METALLIC static_hash_string("metallic", 8, 0xd391b8d63f3e5160ULL) 29 | #define HASH_SAMPLER_ALBEDO static_hash_string("sampler_albedo", 14, 0xce61fa4d0eb7989cULL) 30 | #define HASH_SAMPLER_OCCLUSION static_hash_string("sampler_occlusion", 17, 0x2886ceccdafe5947ULL) 31 | #define HASH_SAMPLER_ROUGHNESS static_hash_string("sampler_roughness", 17, 0xbbe477400916627aULL) 32 | #define HASH_SAMPLER_METALLIC static_hash_string("sampler_metallic", 16, 0x58c75e9c2184c2e3ULL) 33 | #define HASH_SAMPLER_NORMAL static_hash_string("sampler_normal", 14, 0x27b3b10a3a9b10caULL) 34 | -------------------------------------------------------------------------------- /render/hashstrings.txt: -------------------------------------------------------------------------------- 1 | 2 | HASH_RENDER render 3 | HASH_API api 4 | HASH_DIRECTX12 directx12 5 | HASH_METAL metal 6 | HASH_D3D_DEVICE_REF d3d_device_ref 7 | HASH_D3D_DEVICE_DEBUG d3d_device_debug 8 | HASH_D3D_SHADER_DEBUG d3d_shader_debug 9 | 10 | HASH_PARAMETER_COUNT parameter_count 11 | HASH_SHADER shader 12 | HASH_SHADER_DIRECTX12 shader_directx12 13 | HASH_SHADER_METAL shader_metal 14 | HASH_TEXTURE texture 15 | 16 | HASH_TRANSFORM_MVP transform_mvp 17 | HASH_TRANSFORM_MODEL transform_model 18 | HASH_TEX tex 19 | HASH_PARAMETERS parameters 20 | 21 | HASH_ALBEDO albedo 22 | HASH_OCCLUSION occlusion 23 | HASH_ROUGHNESS roughness 24 | HASH_METALLIC metallic 25 | 26 | HASH_SAMPLER_ALBEDO sampler_albedo 27 | HASH_SAMPLER_OCCLUSION sampler_occlusion 28 | HASH_SAMPLER_ROUGHNESS sampler_roughness 29 | HASH_SAMPLER_METALLIC sampler_metallic 30 | HASH_SAMPLER_NORMAL sampler_normal 31 | -------------------------------------------------------------------------------- /render/import.h: -------------------------------------------------------------------------------- 1 | /* import.h - Render library - Public Domain - 2014 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #pragma once 19 | 20 | /*! \file import.h 21 | Render library resource import */ 22 | 23 | #include 24 | #include 25 | 26 | /* Import render source to a resource 27 | \param stream Source stream 28 | \param uuid Resource UUID 29 | \return 0 if successful, <0 if error */ 30 | RENDER_API int 31 | render_import(stream_t* stream, const uuid_t uuid); 32 | -------------------------------------------------------------------------------- /render/internal.h: -------------------------------------------------------------------------------- 1 | /* internal.h - Render library - Public Domain - 2013 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #pragma once 19 | 20 | /*! \file internal.h 21 | Internal types */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | RENDER_EXTERN bool render_api_disabled[]; 34 | RENDER_EXTERN render_config_t render_config; 35 | RENDER_EXTERN render_backend_t** render_backends_current; 36 | 37 | // INTERNAL FUNCTIONS 38 | -------------------------------------------------------------------------------- /render/metal/backend.c: -------------------------------------------------------------------------------- 1 | /* backend.c - Render library - Public Domain - 2022 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any 15 | * restrictions. 16 | * 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | #if !FOUNDATION_PLATFORM_APPLE 27 | 28 | render_backend_t* 29 | render_backend_metal_allocate(void) { 30 | return nullptr; 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /render/metal/backend.h: -------------------------------------------------------------------------------- 1 | /* backend.h - Render library - Public Domain - 2021 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #pragma once 19 | 20 | /*! \file null/backend.h 21 | Null render backend */ 22 | 23 | #include 24 | #include 25 | 26 | RENDER_API render_backend_t* 27 | render_backend_metal_allocate(void); 28 | -------------------------------------------------------------------------------- /render/null/backend.h: -------------------------------------------------------------------------------- 1 | /* backend.h - Render library - Public Domain - 2014 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #pragma once 19 | 20 | /*! \file null/backend.h 21 | Null render backend */ 22 | 23 | #include 24 | #include 25 | 26 | RENDER_API render_backend_t* 27 | render_backend_null_allocate(void); 28 | -------------------------------------------------------------------------------- /render/pipeline.c: -------------------------------------------------------------------------------- 1 | /* pipeline.c - Render library - Public Domain - 2017 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any 15 | * restrictions. 16 | * 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | render_pipeline_t* 29 | render_pipeline_allocate(render_backend_t* backend, render_indexformat_t index_format, uint capacity) { 30 | return backend->vtable.pipeline_allocate(backend, index_format, capacity); 31 | } 32 | 33 | void 34 | render_pipeline_deallocate(render_pipeline_t* pipeline) { 35 | if (pipeline && pipeline->backend) 36 | pipeline->backend->vtable.pipeline_deallocate(pipeline->backend, pipeline); 37 | } 38 | 39 | void 40 | render_pipeline_set_color_attachment(render_pipeline_t* pipeline, uint slot, render_target_t* target) { 41 | pipeline->backend->vtable.pipeline_set_color_attachment(pipeline->backend, pipeline, slot, target); 42 | } 43 | 44 | void 45 | render_pipeline_set_depth_attachment(render_pipeline_t* pipeline, render_target_t* target) { 46 | pipeline->backend->vtable.pipeline_set_depth_attachment(pipeline->backend, pipeline, target); 47 | } 48 | 49 | void 50 | render_pipeline_set_color_clear(render_pipeline_t* pipeline, uint slot, render_clear_action_t action, vector_t color) { 51 | pipeline->backend->vtable.pipeline_set_color_clear(pipeline->backend, pipeline, slot, action, color); 52 | } 53 | 54 | void 55 | render_pipeline_set_depth_clear(render_pipeline_t* pipeline, render_clear_action_t action, vector_t color) { 56 | pipeline->backend->vtable.pipeline_set_depth_clear(pipeline->backend, pipeline, action, color); 57 | } 58 | 59 | void 60 | render_pipeline_build(render_pipeline_t* pipeline) { 61 | pipeline->backend->vtable.pipeline_build(pipeline->backend, pipeline); 62 | } 63 | 64 | void 65 | render_pipeline_flush(render_pipeline_t* pipeline) { 66 | if (pipeline->barrier) { 67 | task_yield_and_wait(pipeline->barrier); 68 | atomic_thread_fence_acquire(); 69 | } 70 | pipeline->primitive_buffer->used = (uint)atomic_load32(&pipeline->primitive_used, memory_order_relaxed); 71 | pipeline->backend->vtable.pipeline_flush(pipeline->backend, pipeline); 72 | atomic_store32(&pipeline->primitive_used, 0, memory_order_relaxed); 73 | } 74 | 75 | void 76 | render_pipeline_queue(render_pipeline_t* pipeline, render_primitive_type type, const render_primitive_t* primitive) { 77 | FOUNDATION_UNUSED(type); 78 | int32_t index = atomic_incr32(&pipeline->primitive_used, memory_order_release); 79 | if ((uint)index <= pipeline->primitive_buffer->allocated) { 80 | render_primitive_t* primitve_store = pipeline->primitive_buffer->store; 81 | primitve_store[index - 1] = *primitive; 82 | } else { 83 | atomic_store32(&pipeline->primitive_used, (int32_t)pipeline->primitive_buffer->allocated, memory_order_relaxed); 84 | } 85 | } 86 | 87 | void 88 | render_pipeline_use_argument_buffer(render_pipeline_t* pipeline, render_buffer_index_t buffer) { 89 | pipeline->backend->vtable.pipeline_use_argument_buffer(pipeline->backend, pipeline, buffer); 90 | } 91 | 92 | void 93 | render_pipeline_use_render_buffer(render_pipeline_t* pipeline, render_buffer_index_t buffer) { 94 | pipeline->backend->vtable.pipeline_use_render_buffer(pipeline->backend, pipeline, buffer); 95 | } 96 | 97 | render_pipeline_state_t 98 | render_pipeline_state_allocate(render_backend_t* backend, render_pipeline_t* pipeline, render_shader_t* shader) { 99 | return backend->vtable.pipeline_state_allocate(backend, pipeline, shader); 100 | } 101 | 102 | void 103 | render_pipeline_state_deallocate(render_backend_t* backend, render_pipeline_state_t state) { 104 | if (backend) 105 | backend->vtable.pipeline_state_deallocate(backend, state); 106 | } 107 | -------------------------------------------------------------------------------- /render/pipeline.h: -------------------------------------------------------------------------------- 1 | /* pipeline.h - Render library - Public Domain - 2017 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any 15 | * restrictions. 16 | * 17 | */ 18 | 19 | #pragma once 20 | 21 | /*! \file pipeline.h 22 | Render pipeline */ 23 | 24 | #include 25 | 26 | #include 27 | 28 | RENDER_API render_pipeline_t* 29 | render_pipeline_allocate(render_backend_t* backend, render_indexformat_t index_format, uint capacity); 30 | 31 | RENDER_API void 32 | render_pipeline_deallocate(render_pipeline_t* pipeline); 33 | 34 | RENDER_API void 35 | render_pipeline_set_color_attachment(render_pipeline_t* pipeline, uint slot, render_target_t* target); 36 | 37 | RENDER_API void 38 | render_pipeline_set_depth_attachment(render_pipeline_t* pipeline, render_target_t* target); 39 | 40 | RENDER_API void 41 | render_pipeline_set_color_clear(render_pipeline_t* pipeline, uint slot, render_clear_action_t action, vector_t color); 42 | 43 | RENDER_API void 44 | render_pipeline_set_depth_clear(render_pipeline_t* pipeline, render_clear_action_t action, vector_t color); 45 | 46 | RENDER_API void 47 | render_pipeline_build(render_pipeline_t* pipeline); 48 | 49 | RENDER_API void 50 | render_pipeline_flush(render_pipeline_t* pipeline); 51 | 52 | RENDER_API void 53 | render_pipeline_queue(render_pipeline_t* pipeline, render_primitive_type type, const render_primitive_t* primitive); 54 | 55 | RENDER_API void 56 | render_pipeline_use_argument_buffer(render_pipeline_t* pipeline, render_buffer_index_t buffer); 57 | 58 | RENDER_API void 59 | render_pipeline_use_render_buffer(render_pipeline_t* pipeline, render_buffer_index_t buffer); 60 | 61 | RENDER_API render_pipeline_state_t 62 | render_pipeline_state_allocate(render_backend_t* backend, render_pipeline_t* pipeline, render_shader_t* shader); 63 | 64 | RENDER_API void 65 | render_pipeline_state_deallocate(render_backend_t* backend, render_pipeline_state_t state); 66 | -------------------------------------------------------------------------------- /render/projection.c: -------------------------------------------------------------------------------- 1 | /* projection.c - Render library - Public Domain - 2014 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any 15 | * restrictions. 16 | * 17 | */ 18 | 19 | #include "projection.h" 20 | 21 | #include 22 | 23 | matrix_t 24 | render_projection_perspective(real near, real far, real fov, real aspect) { 25 | float32_aligned128_t matrix[4][4]; 26 | memset(matrix, 0, sizeof(float32_t) * 16); 27 | 28 | real tanfov = math_tan(fov * 0.5f); 29 | real height = 2.0f * (near * tanfov); 30 | real width = height * aspect; 31 | 32 | matrix[0][0] = 2.0f * near / width; 33 | matrix[1][1] = 2.0f * near / height; 34 | 35 | // Equals zero 36 | // matrix[2][0] = (left + right) / (left - right); 37 | // matrix[2][1] = (top + bottom) / (top - bottom); 38 | 39 | matrix[2][2] = -(far + near) / (far - near); 40 | matrix[2][3] = -1.0f; 41 | matrix[3][2] = -(2.0f * near * far) / (far - near); 42 | matrix[3][3] = 0.0f; 43 | 44 | return matrix_aligned((float32_t*)matrix); 45 | } 46 | 47 | matrix_t 48 | render_projection_orthographic(real near, real far, real left, real top, real right, real bottom) { 49 | float32_aligned128_t matrix[4][4]; 50 | memset(matrix, 0, sizeof(float32_t) * 16); 51 | 52 | matrix[0][0] = 2.0f / (right - left); 53 | matrix[1][1] = 2.0f / (top - bottom); 54 | 55 | matrix[3][0] = (left + right) / (left - right); 56 | matrix[3][1] = (bottom + top) / (bottom - top); 57 | 58 | matrix[2][2] = 2.0f / (far - near); 59 | matrix[3][2] = -(far + near) / (far - near); 60 | 61 | matrix[3][3] = 1.0f; 62 | 63 | return matrix_aligned((float32_t*)matrix); 64 | } 65 | -------------------------------------------------------------------------------- /render/projection.h: -------------------------------------------------------------------------------- 1 | /* projection.h - Render library - Public Domain - 2014 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #pragma once 19 | 20 | /*! \file projection.h 21 | Projection matrix */ 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | RENDER_API matrix_t 29 | render_projection_perspective(real near, real far, real fov, real aspect); 30 | 31 | RENDER_API matrix_t 32 | render_projection_orthographic(real near, real far, real left, real top, real right, real bottom); 33 | -------------------------------------------------------------------------------- /render/render.c: -------------------------------------------------------------------------------- 1 | /* render.c - Render library - Public Domain - 2013 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | //#include 25 | //#include 26 | #include 27 | 28 | static bool render_initialized; 29 | 30 | // Global data 31 | render_config_t render_config; 32 | bool render_api_disabled[RENDERAPI_COUNT]; 33 | render_backend_t** render_backends_current; 34 | 35 | int 36 | render_module_initialize(render_config_t config) { 37 | if (render_initialized) 38 | return 0; 39 | 40 | FOUNDATION_UNUSED(config); 41 | 42 | render_api_disabled[RENDERAPI_UNKNOWN] = true; 43 | render_api_disabled[RENDERAPI_DEFAULT] = true; 44 | render_api_disabled[RENDERAPI_DIRECTX] = true; 45 | 46 | resource_import_register(render_import); 47 | resource_compile_register(render_compile); 48 | 49 | render_initialized = true; 50 | 51 | return 0; 52 | } 53 | 54 | void 55 | render_module_finalize(void) { 56 | if (!render_initialized) 57 | return; 58 | 59 | array_deallocate(render_backends_current); 60 | 61 | render_initialized = false; 62 | } 63 | 64 | bool 65 | render_module_is_initialized(void) { 66 | return render_initialized; 67 | } 68 | 69 | void 70 | render_api_enable(const render_api_t* api, size_t count) { 71 | for (size_t i = 0; i < count; ++i) { 72 | if ((api[i] > RENDERAPI_DEFAULT) && (api[i] < RENDERAPI_COUNT)) { 73 | // Don't enable the proxies 74 | if (api[i] != RENDERAPI_DIRECTX) 75 | render_api_disabled[api[i]] = false; 76 | } 77 | } 78 | } 79 | 80 | void 81 | render_api_disable(const render_api_t* api, size_t count) { 82 | for (size_t i = 0; i < count; ++i) { 83 | if ((api[i] > RENDERAPI_DEFAULT) && (api[i] < RENDERAPI_COUNT)) 84 | render_api_disabled[api[i]] = true; 85 | } 86 | } 87 | 88 | void 89 | render_module_parse_config(const char* path, size_t path_size, const char* buffer, size_t size, 90 | const json_token_t* tokens, size_t tokens_count) { 91 | FOUNDATION_UNUSED(path, path_size, buffer, size, tokens, tokens_count); 92 | } 93 | -------------------------------------------------------------------------------- /render/render.h: -------------------------------------------------------------------------------- 1 | /* render.h - Render library - Public Domain - 2013 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #pragma once 19 | 20 | /*! \file render.h 21 | Render library entry points */ 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | /*! Initialize render library 37 | \return 0 if success, <0 if error */ 38 | RENDER_API int 39 | render_module_initialize(render_config_t config); 40 | 41 | //! Finalize render library 42 | RENDER_API void 43 | render_module_finalize(void); 44 | 45 | /*! Query if render library is initialized 46 | \return true if library is initialized, false if not */ 47 | RENDER_API bool 48 | render_module_is_initialized(void); 49 | 50 | /*! Query version of render library 51 | \return Library version */ 52 | RENDER_API version_t 53 | render_module_version(void); 54 | 55 | /*! Enable use of the given APIs 56 | \param api Array of API identifiers to enable 57 | \param count Number of elements in array */ 58 | RENDER_API void 59 | render_api_enable(const render_api_t* api, size_t count); 60 | 61 | /*! Enable use of the given APIs 62 | \param api Array of API identifiers to disable 63 | \param count Number of elements in array */ 64 | RENDER_API void 65 | render_api_disable(const render_api_t* api, size_t count); 66 | 67 | /*! Parse config declarations from JSON buffer 68 | \param buffer Data buffer 69 | \param size Size of data buffer 70 | \param tokens JSON tokens 71 | \param tokens_count Number of JSON tokens */ 72 | RENDER_API void 73 | render_module_parse_config(const char* path, size_t path_size, const char* buffer, size_t size, 74 | const json_token_t* tokens, size_t tokens_count); 75 | -------------------------------------------------------------------------------- /render/shader.c: -------------------------------------------------------------------------------- 1 | /* shader.c - Render library - Public Domain - 2014 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | FOUNDATION_STATIC_ASSERT(sizeof(render_shader_t) == 64, "invalid shader size"); 28 | 29 | render_shader_t* 30 | render_shader_allocate(void) { 31 | render_shader_t* shader = memory_allocate(HASH_RENDER, sizeof(render_shader_t), 16, MEMORY_PERSISTENT); 32 | render_shader_initialize(shader); 33 | return shader; 34 | } 35 | 36 | void 37 | render_shader_initialize(render_shader_t* shader) { 38 | memset(shader, 0, sizeof(render_shader_t)); 39 | } 40 | 41 | void 42 | render_shader_finalize(render_shader_t* shader) { 43 | if (shader->backend) { 44 | uuidmap_erase(render_backend_shader_table(shader->backend), shader->uuid); 45 | render_backend_shader_finalize(shader->backend, shader); 46 | } 47 | } 48 | 49 | void 50 | render_shader_deallocate(render_shader_t* shader) { 51 | if (shader) 52 | render_shader_finalize(shader); 53 | memory_deallocate(shader); 54 | } 55 | 56 | render_shader_t* 57 | render_shader_lookup(render_backend_t* backend, const uuid_t uuid) { 58 | render_shader_t* shader = uuidmap_lookup(render_backend_shader_table(backend), uuid); 59 | if (shader) 60 | atomic_incr32(&shader->ref, memory_order_release); 61 | return shader; 62 | } 63 | 64 | render_shader_t* 65 | render_shader_load(render_backend_t* backend, const uuid_t uuid) { 66 | render_shader_t* shader = render_shader_lookup(backend, uuid); 67 | if (shader) 68 | return shader; 69 | 70 | uint64_t platform = render_backend_resource_platform(backend); 71 | stream_t* stream; 72 | resource_header_t header; 73 | bool success = false; 74 | bool recompile = false; 75 | bool recompiled = false; 76 | 77 | error_context_declare_local(char uuidbuf[40]; 78 | const string_t uuidstr = string_from_uuid(uuidbuf, sizeof(uuidbuf), uuid)); 79 | error_context_push(STRING_CONST("loading shader"), STRING_ARGS(uuidstr)); 80 | 81 | retry: 82 | 83 | stream = resource_stream_open_static(uuid, platform); 84 | if (stream) { 85 | header = resource_stream_read_header(stream); 86 | if (header.version == RENDER_SHADER_RESOURCE_VERSION) { 87 | if (header.type == backend->shader_type) 88 | shader = render_shader_allocate(); 89 | if (shader) { 90 | stream_read(stream, shader, sizeof(render_shader_t)); 91 | shader->backend = nullptr; 92 | } 93 | } 94 | if (!shader && !recompiled) { 95 | log_warnf(HASH_RENDER, WARNING_INVALID_VALUE, STRING_CONST("Got unexpected type/version %" PRIx64 " : %u"), 96 | (uint64_t)header.type, (uint32_t)header.version); 97 | recompile = true; 98 | } 99 | stream_deallocate(stream); 100 | stream = nullptr; 101 | } 102 | if (shader) 103 | stream = resource_stream_open_dynamic(uuid, platform); 104 | if (stream) { 105 | char* buffer; 106 | uint32_t version = stream_read_uint32(stream); 107 | /*uint32_t unused =*/ stream_read_uint32(stream); 108 | size_t size = (size_t)stream_read_uint64(stream); 109 | if ((version == RENDER_SHADER_RESOURCE_VERSION) && (size < 128 * 1024)) { 110 | buffer = memory_allocate(HASH_RENDER, size + 1, 0, MEMORY_TEMPORARY); 111 | if (stream_read(stream, buffer, size) == size) { 112 | buffer[size] = 0; 113 | success = render_backend_shader_upload(backend, shader, buffer, size); 114 | } 115 | memory_deallocate(buffer); 116 | } else if (!recompiled) { 117 | log_warnf(HASH_RENDER, WARNING_INVALID_VALUE, 118 | STRING_CONST("Got unexpected version/size when loading blob: %u (%" PRIsize ")"), version, size); 119 | recompile = true; 120 | } 121 | stream_deallocate(stream); 122 | stream = nullptr; 123 | } 124 | 125 | if (!success) { 126 | render_shader_deallocate(shader); 127 | shader = nullptr; 128 | 129 | if (recompile && !recompiled) { 130 | recompiled = resource_compile(uuid, render_backend_resource_platform(backend)); 131 | if (recompiled) 132 | goto retry; 133 | } 134 | } 135 | 136 | if (shader) { 137 | atomic_store32(&shader->ref, 1, memory_order_release); 138 | shader->uuid = uuid; 139 | uuidmap_insert(render_backend_shader_table(backend), uuid, shader); 140 | } 141 | 142 | error_context_pop(); 143 | 144 | return shader; 145 | } 146 | 147 | bool 148 | render_shader_reload(render_shader_t* shader, const uuid_t uuid) { 149 | error_context_declare_local(char uuidbuf[40]; 150 | const string_t uuidstr = string_from_uuid(uuidbuf, sizeof(uuidbuf), uuid)); 151 | error_context_push(STRING_CONST("reloading shader"), STRING_ARGS(uuidstr)); 152 | 153 | render_backend_t* backend = shader->backend; 154 | 155 | bool success = false; 156 | render_shader_t tmpshader = {0}; 157 | uint64_t platform = render_backend_resource_platform(backend); 158 | 159 | stream_t* stream = resource_stream_open_static(uuid, platform); 160 | if (stream) { 161 | resource_header_t header = resource_stream_read_header(stream); 162 | if (header.version == RENDER_SHADER_RESOURCE_VERSION) { 163 | if (header.type == HASH_SHADER) { 164 | render_shader_initialize(&tmpshader); 165 | stream_read(stream, &tmpshader, sizeof(render_shader_t)); 166 | success = true; 167 | } 168 | } 169 | stream_deallocate(stream); 170 | stream = nullptr; 171 | } 172 | if (success) { 173 | stream = resource_stream_open_dynamic(uuid, platform); 174 | success = false; 175 | } 176 | if (stream) { 177 | char* buffer; 178 | uint32_t version = stream_read_uint32(stream); 179 | size_t size = (size_t)stream_read_uint64(stream); 180 | if ((version == RENDER_SHADER_RESOURCE_VERSION) && (size < 128 * 1024)) { 181 | buffer = memory_allocate(HASH_RENDER, size + 1, 0, MEMORY_TEMPORARY); 182 | if (stream_read(stream, buffer, size) == size) { 183 | buffer[size] = 0; 184 | success = render_backend_shader_upload(backend, &tmpshader, buffer, size); 185 | } 186 | memory_deallocate(buffer); 187 | } else { 188 | log_warnf(HASH_RENDER, WARNING_INVALID_VALUE, 189 | STRING_CONST("Got unexpected version/size when loading blob: %u (%" PRIsize ")"), version, size); 190 | } 191 | stream_deallocate(stream); 192 | stream = nullptr; 193 | } 194 | 195 | if (success) { 196 | uintptr_t swapdata[4]; 197 | memcpy(swapdata, shader->backend_data, sizeof(swapdata)); 198 | memcpy(shader->backend_data, tmpshader.backend_data, sizeof(shader->backend_data)); 199 | memcpy(tmpshader.backend_data, swapdata, sizeof(swapdata)); 200 | } 201 | 202 | render_backend_shader_finalize(backend, &tmpshader); 203 | 204 | error_context_pop(); 205 | 206 | return success; 207 | } 208 | 209 | void 210 | render_shader_unload(render_shader_t* shader) { 211 | if (shader && atomic_load32(&shader->ref, memory_order_acquire)) { 212 | if (!atomic_decr32(&shader->ref, memory_order_release)) 213 | render_shader_deallocate(shader); 214 | } 215 | } 216 | -------------------------------------------------------------------------------- /render/shader.h: -------------------------------------------------------------------------------- 1 | /* shader.h - Render library - Public Domain - 2014 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #pragma once 19 | 20 | /*! \file shader.h 21 | Programmable render pipeline shader */ 22 | 23 | #include 24 | 25 | #include 26 | 27 | RENDER_API render_shader_t* 28 | render_shader_allocate(void); 29 | 30 | RENDER_API void 31 | render_shader_initialize(render_shader_t* shader); 32 | 33 | RENDER_API void 34 | render_shader_finalize(render_shader_t* shader); 35 | 36 | RENDER_API void 37 | render_shader_deallocate(render_shader_t* shader); 38 | 39 | /*! Load the shader identified by the given UUID. Returns a pointer 40 | to the existing shader if it is already loaded. When loading a shader, 41 | the reference count will be used and you must call render_shader_unload 42 | to release it, NOT the render_shader_deallocate function. 43 | \param backend Backend 44 | \param uuid Shader UUID 45 | \return Shader */ 46 | RENDER_API render_shader_t* 47 | render_shader_load(render_backend_t* backend, const uuid_t uuid); 48 | 49 | /*! Lookup the shader identified by the given UUID. When looking up 50 | a shader, the reference count will be used and you must remember to 51 | call render_shader_unload to release it. 52 | \param backend Backend 53 | \param uuid Shader UUID 54 | \return Shader */ 55 | RENDER_API render_shader_t* 56 | render_shader_lookup(render_backend_t* backend, const uuid_t uuid); 57 | 58 | RENDER_API bool 59 | render_shader_reload(render_shader_t* shader, const uuid_t uuid); 60 | 61 | RENDER_API void 62 | render_shader_unload(render_shader_t* shader); 63 | 64 | #define RENDER_SHADER_RESOURCE_VERSION 4 65 | 66 | #if RESOURCE_ENABLE_LOCAL_SOURCE 67 | 68 | /* Compile shader resource 69 | \param uuid Shader UUID 70 | \param platform Resource platform 71 | \param source Shader resource source representation 72 | \param type Type string 73 | \param type_length Length of type string 74 | \return 0 if successful, <0 if error */ 75 | RENDER_API int 76 | render_shader_compile(const uuid_t uuid, uint64_t platform, resource_source_t* source, const blake3_hash_t source_hash, 77 | const char* type, size_t type_length); 78 | 79 | #else 80 | 81 | #define render_shader_compile(uuid, platform, source, source_hash, type, type_length) \ 82 | (((void)sizeof(uuid)), ((void)sizeof(platform)), ((void)sizeof(source)), ((void)sizeof(source_hash)), \ 83 | ((void)sizeof(type)), ((void)sizeof(type_length)), -1) 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /render/target.c: -------------------------------------------------------------------------------- 1 | /* target.c - Render library - Public Domain - 2013 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any 15 | * restrictions. 16 | * 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | 25 | render_target_t* 26 | render_target_window_allocate(render_backend_t* backend, window_t* window, uint tag) { 27 | return backend->vtable.target_window_allocate(backend, window, tag); 28 | } 29 | 30 | render_target_t* 31 | render_target_texture_allocate(render_backend_t* backend, uint width, uint height, render_pixelformat_t format) { 32 | return backend->vtable.target_texture_allocate(backend, width, height, format); 33 | } 34 | 35 | void 36 | render_target_deallocate(render_target_t* target) { 37 | if (target && target->backend) 38 | target->backend->vtable.target_deallocate(target->backend, target); 39 | } 40 | -------------------------------------------------------------------------------- /render/target.h: -------------------------------------------------------------------------------- 1 | /* target.h - Render library - Public Domain - 2013 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any 15 | * restrictions. 16 | * 17 | */ 18 | 19 | #pragma once 20 | 21 | /*! \file target.h 22 | Render target */ 23 | 24 | #include 25 | 26 | #include 27 | 28 | RENDER_API render_target_t* 29 | render_target_window_allocate(render_backend_t* backend, window_t* window, uint tag); 30 | 31 | RENDER_API render_target_t* 32 | render_target_texture_allocate(render_backend_t* backend, uint width, uint height, render_pixelformat_t format); 33 | 34 | RENDER_API void 35 | render_target_deallocate(render_target_t* target); 36 | -------------------------------------------------------------------------------- /render/texture.c: -------------------------------------------------------------------------------- 1 | /* texture.c - Render library - Public Domain - 2014 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | FOUNDATION_STATIC_ASSERT(sizeof(render_texture_t) == 96, "invalid texture size"); 28 | 29 | render_texture_t* 30 | render_texture_allocate(void) { 31 | render_texture_t* texture = memory_allocate(HASH_RENDER, sizeof(render_texture_t), 16, MEMORY_PERSISTENT); 32 | render_texture_initialize(texture); 33 | return texture; 34 | } 35 | 36 | void 37 | render_texture_initialize(render_texture_t* texture) { 38 | memset(texture, 0, sizeof(render_texture_t)); 39 | } 40 | 41 | void 42 | render_texture_finalize(render_texture_t* texture) { 43 | if (texture->backend) { 44 | uuidmap_erase(render_backend_texture_table(texture->backend), texture->uuid); 45 | texture->backend->vtable.deallocate_texture(texture->backend, texture); 46 | } 47 | } 48 | 49 | void 50 | render_texture_deallocate(render_texture_t* texture) { 51 | if (texture) 52 | render_texture_finalize(texture); 53 | memory_deallocate(texture); 54 | } 55 | 56 | render_texture_t* 57 | render_texture_load(render_backend_t* backend, const uuid_t uuid) { 58 | render_texture_t* texture = render_texture_lookup(backend, uuid); 59 | if (texture) 60 | return texture; 61 | 62 | uint64_t platform = render_backend_resource_platform(backend); 63 | stream_t* stream; 64 | resource_header_t header; 65 | bool success = false; 66 | bool recompile = false; 67 | bool recompiled = false; 68 | 69 | error_context_declare_local(char uuidbuf[40]; 70 | const string_t uuidstr = string_from_uuid(uuidbuf, sizeof(uuidbuf), uuid)); 71 | error_context_push(STRING_CONST("loading texture"), STRING_ARGS(uuidstr)); 72 | 73 | render_backend_enable_thread(backend); 74 | 75 | retry: 76 | 77 | stream = resource_stream_open_static(uuid, platform); 78 | if (stream) { 79 | header = resource_stream_read_header(stream); 80 | if (header.version == RENDER_TEXTURE_RESOURCE_VERSION) { 81 | if (header.type == HASH_TEXTURE) 82 | texture = render_texture_allocate(); 83 | if (texture) { 84 | stream_read(stream, texture, sizeof(render_texture_t)); 85 | texture->backend = nullptr; 86 | } 87 | } 88 | if (!texture && !recompiled) { 89 | log_warnf(HASH_RENDER, WARNING_INVALID_VALUE, STRING_CONST("Got unexpected type/version %" PRIx64 " : %u"), 90 | (uint64_t)header.type, (uint32_t)header.version); 91 | recompile = true; 92 | } 93 | stream_deallocate(stream); 94 | stream = nullptr; 95 | } 96 | if (texture) 97 | stream = resource_stream_open_dynamic(uuid, platform); 98 | if (stream) { 99 | char* buffer; 100 | uint32_t version = stream_read_uint32(stream); 101 | size_t size = (size_t)stream_read_uint64(stream); 102 | if ((version == RENDER_TEXTURE_RESOURCE_VERSION) && (size < 128 * 1024)) { 103 | buffer = memory_allocate(HASH_RENDER, size + 1, 0, MEMORY_TEMPORARY); 104 | if (stream_read(stream, buffer, size) == size) { 105 | buffer[size] = 0; 106 | success = render_backend_texture_upload(backend, texture, buffer, size); 107 | } 108 | memory_deallocate(buffer); 109 | } else if (!recompiled) { 110 | log_warnf(HASH_RENDER, WARNING_INVALID_VALUE, 111 | STRING_CONST("Got unexpected version/size when loading blob: %u (%" PRIsize ")"), version, size); 112 | recompile = true; 113 | } 114 | stream_deallocate(stream); 115 | stream = nullptr; 116 | } 117 | 118 | if (!success) { 119 | render_texture_deallocate(texture); 120 | texture = nullptr; 121 | 122 | if (recompile && !recompiled) { 123 | recompiled = resource_compile(uuid, render_backend_resource_platform(backend)); 124 | if (recompiled) 125 | goto retry; 126 | } 127 | } 128 | 129 | if (texture) { 130 | atomic_store32(&texture->ref, 1, memory_order_release); 131 | texture->uuid = uuid; 132 | uuidmap_insert(render_backend_texture_table(backend), uuid, texture); 133 | } 134 | 135 | error_context_pop(); 136 | 137 | return texture; 138 | } 139 | 140 | render_texture_t* 141 | render_texture_lookup(render_backend_t* backend, const uuid_t uuid) { 142 | render_texture_t* texture = uuidmap_lookup(render_backend_texture_table(backend), uuid); 143 | if (texture) 144 | atomic_incr32(&texture->ref, memory_order_release); 145 | return texture; 146 | } 147 | 148 | bool 149 | render_texture_reload(render_texture_t* texture, const uuid_t uuid) { 150 | error_context_declare_local(char uuidbuf[40]; 151 | const string_t uuidstr = string_from_uuid(uuidbuf, sizeof(uuidbuf), uuid)); 152 | error_context_push(STRING_CONST("reloading texture"), STRING_ARGS(uuidstr)); 153 | 154 | render_backend_t* backend = texture->backend; 155 | render_backend_enable_thread(backend); 156 | 157 | bool success = false; 158 | render_texture_t tmptexture = {0}; 159 | 160 | uint64_t platform = render_backend_resource_platform(backend); 161 | 162 | stream_t* stream = resource_stream_open_static(uuid, platform); 163 | if (stream) { 164 | resource_header_t header = resource_stream_read_header(stream); 165 | if (header.version == RENDER_TEXTURE_RESOURCE_VERSION) { 166 | if (header.type == HASH_TEXTURE) { 167 | success = true; 168 | stream_read(stream, &tmptexture, sizeof(render_texture_t)); 169 | } 170 | } 171 | stream_deallocate(stream); 172 | stream = nullptr; 173 | } 174 | if (success) { 175 | success = false; 176 | stream = resource_stream_open_dynamic(uuid, platform); 177 | } 178 | if (stream) { 179 | char* buffer; 180 | uint32_t version = stream_read_uint32(stream); 181 | size_t size = (size_t)stream_read_uint64(stream); 182 | if ((version == RENDER_TEXTURE_RESOURCE_VERSION) && (size < 128 * 1024)) { 183 | buffer = memory_allocate(HASH_RENDER, size + 1, 0, MEMORY_TEMPORARY); 184 | if (stream_read(stream, buffer, size) == size) { 185 | buffer[size] = 0; 186 | success = render_backend_texture_upload(backend, &tmptexture, buffer, size); 187 | } 188 | memory_deallocate(buffer); 189 | } else { 190 | log_warnf(HASH_RENDER, WARNING_INVALID_VALUE, 191 | STRING_CONST("Got unexpected version/size when loading blob: %u (%" PRIsize ")"), version, size); 192 | } 193 | stream_deallocate(stream); 194 | stream = nullptr; 195 | } 196 | 197 | if (success) { 198 | uintptr_t swapdata[4]; 199 | memcpy(swapdata, texture->backend_data, sizeof(swapdata)); 200 | memcpy(texture->backend_data, tmptexture.backend_data, sizeof(texture->backend_data)); 201 | memcpy(tmptexture.backend_data, swapdata, sizeof(swapdata)); 202 | texture->pixelformat = tmptexture.pixelformat; 203 | texture->colorspace = tmptexture.colorspace; 204 | texture->width = tmptexture.width; 205 | texture->height = tmptexture.height; 206 | texture->depth = tmptexture.depth; 207 | texture->levels = tmptexture.levels; 208 | } 209 | 210 | backend->vtable.deallocate_texture(backend, &tmptexture); 211 | 212 | error_context_pop(); 213 | 214 | return success; 215 | } 216 | 217 | void 218 | render_texture_unload(render_texture_t* texture) { 219 | if (texture && atomic_load32(&texture->ref, memory_order_acquire)) { 220 | if (!atomic_decr32(&texture->ref, memory_order_release)) 221 | render_texture_deallocate(texture); 222 | } 223 | } 224 | -------------------------------------------------------------------------------- /render/texture.h: -------------------------------------------------------------------------------- 1 | /* texture.h - Render library - Public Domain - 2014 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #pragma once 19 | 20 | /*! \file texture.h 21 | Render texture */ 22 | 23 | #include 24 | 25 | #include 26 | 27 | RENDER_API render_texture_t* 28 | render_texture_allocate(void); 29 | 30 | RENDER_API void 31 | render_texture_initialize(render_texture_t* texture); 32 | 33 | RENDER_API void 34 | render_texture_finalize(render_texture_t* texture); 35 | 36 | RENDER_API void 37 | render_texture_deallocate(render_texture_t* texture); 38 | 39 | /*! Load the texture identified by the given UUID. Returns a pointer 40 | to the existing texture if it is already loaded. When loading a texture, 41 | the reference count will be used and you must call render_texture_unload 42 | to release it, NOT the render_texture_deallocate function. 43 | \param backend Backend 44 | \param uuid Texture UUID 45 | \return Texture */ 46 | RENDER_API render_texture_t* 47 | render_texture_load(render_backend_t* backend, const uuid_t uuid); 48 | 49 | /*! Lookup the texture identified by the given UUID. When looking up 50 | a texture, the reference count will be used and you must remember to 51 | call render_texture_unload to release it, NOT render_texture_deallocate. 52 | \param backend Backend 53 | \param uuid Shader UUID 54 | \return Shader */ 55 | RENDER_API render_texture_t* 56 | render_texture_lookup(render_backend_t* backend, const uuid_t uuid); 57 | 58 | RENDER_API bool 59 | render_texture_reload(render_texture_t* texture, const uuid_t uuid); 60 | 61 | RENDER_API void 62 | render_texture_unload(render_texture_t* texture); 63 | 64 | #define RENDER_TEXTURE_RESOURCE_VERSION 1 65 | 66 | #if RESOURCE_ENABLE_LOCAL_SOURCE 67 | 68 | /* Compile texture resource 69 | \param uuid Texture UUID 70 | \param platform Resource platform 71 | \param source Texture resource source representation 72 | \param type Type string 73 | \param type_length Length of type string 74 | \return 0 if successful, <0 if error */ 75 | RENDER_API int 76 | render_texture_compile(const uuid_t uuid, uint64_t platform, resource_source_t* source, const uint256_t source_hash, 77 | const char* type, size_t type_length); 78 | 79 | #else 80 | 81 | #define render_texture_compile(uuid, platform, source, source_hash, type, type_length) \ 82 | (((void)sizeof(uuid)), ((void)sizeof(platform)), ((void)sizeof(source)), ((void)sizeof(source_hash)), \ 83 | ((void)sizeof(type)), ((void)sizeof(type_length)), -1) 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /render/version.c: -------------------------------------------------------------------------------- 1 | /* ****** AUTOMATICALLY GENERATED, DO NOT EDIT ****** 2 | This file is generated from the git describe command. 3 | Run the configure script to regenerate this file */ 4 | 5 | #include 6 | #include 7 | 8 | version_t 9 | render_module_version(void) { 10 | return version_make(0, 0, 1, 0, 0x0); 11 | } 12 | -------------------------------------------------------------------------------- /render/vulkan/backend.h: -------------------------------------------------------------------------------- 1 | /* backend.h - Render library - Public Domain - 2014 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The dependent library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #pragma once 19 | 20 | /*! \file vulkan/backend.h 21 | Vulkan render backend */ 22 | 23 | #include 24 | #include 25 | 26 | RENDER_API render_backend_t* 27 | render_backend_vulkan_allocate(void); 28 | -------------------------------------------------------------------------------- /resource/import.map: -------------------------------------------------------------------------------- 1 | 005fbe25dac22141 a7a465ed-9fcb-4383-9494-abadc9b80eb9 0eb3ddc4cae85bbbf73dbc2492dd24666df5a7fc shader/color.shader 2 | 1dd3825aefcd7313 5765515d-2662-467a-95cc-5a213c22ad2f 5d5e3037c88d967b9538646e8464a6d7882e876a shader/color.metal 3 | 9db393ecb3973e3d df075392-1934-4c89-a45c-2139d64d9c92 db067e5ad0ee06966e1093f54ef6415d6d85c8da shader/pipeline.shader 4 | aa54105c500207d3 c0faf120-18a7-4ba4-812a-41e293c7807d c22058266bac8bc757e0b5e6bba8e09f10d9d430 shader/pipeline.metal 5 | e8cd7ab45ea0dbbc 3ba6e39a-c3f0-497c-a908-49c41f446f31 1a8ad469a25e84c0ca7f23d3d53868bb6750fbb7 shader/white.shader 6 | 34326b9e8be4f91b 35ca8649-d118-4608-957d-41753532322c 529a09f4718819b3a19cff1d786f35a78f37c351 shader/white.metal 7 | -------------------------------------------------------------------------------- /resource/shader/color.metal: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | using namespace metal; 5 | 6 | // Vertex declaration 7 | typedef struct vertex_t { 8 | vector_float4 position; 9 | vector_float4 color; 10 | } vertex_t; 11 | 12 | // Vertex shader argument buffers 13 | struct vertex_shader_global_arg_t { 14 | const float4x4 world_to_clip [[ id(0) ]]; 15 | }; 16 | 17 | struct vertex_shader_material_arg_t { 18 | const float4 color [[ id(0) ]]; 19 | }; 20 | 21 | struct vertex_shader_instance_arg_t { 22 | const float4x4 model_to_world [[ id(0) ]]; 23 | }; 24 | 25 | // Vertex shader to pixel shader data exchange 26 | struct rasterizer_data_t { 27 | float4 position [[position]]; 28 | half4 color; 29 | }; 30 | 31 | vertex rasterizer_data_t 32 | vertex_shader(uint vid [[ vertex_id ]], 33 | uint iid [[ instance_id ]], 34 | const device vertex_shader_global_arg_t* global [[ buffer(0) ]], 35 | const device vertex_shader_material_arg_t* material [[ buffer(1) ]], 36 | const device vertex_shader_instance_arg_t* instance [[ buffer(2) ]], 37 | const device vertex_t* vertices [[ buffer(3) ]]) { 38 | rasterizer_data_t out; 39 | 40 | instance += iid; 41 | 42 | out.position = (vertices[vid].position * instance->model_to_world) * global->world_to_clip; 43 | out.color = (half4)(vertices[vid].color * material->color); 44 | 45 | return out; 46 | } 47 | 48 | fragment float4 49 | pixel_shader(rasterizer_data_t in [[ stage_in ]]) { 50 | return (float4)in.color; 51 | } 52 | -------------------------------------------------------------------------------- /resource/shader/color.shader: -------------------------------------------------------------------------------- 1 | metal color.metal 2 | -------------------------------------------------------------------------------- /resource/shader/pipeline.metal: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | using namespace metal; 5 | 6 | // Render arguments 7 | struct render_argument_t { 8 | uint index_count; 9 | uint instance_count; 10 | uint index_offset; 11 | uint vertex_offset; 12 | uint instance_offset; 13 | }; 14 | 15 | // Queued render command 16 | struct render_command_t { 17 | uint pipeline_state; 18 | uint argument_buffer; 19 | uint argument_offset; 20 | uint index_buffer; 21 | uint descriptor[4]; 22 | }; 23 | 24 | struct render_buffer_t { 25 | device void* render_buffer; 26 | }; 27 | 28 | struct render_buffer_storage_t { 29 | const device render_buffer_t* buffers[32]; 30 | }; 31 | 32 | struct pipeline_state_storage_t { 33 | const render_pipeline_state pipeline_state[32]; 34 | }; 35 | 36 | // Compute shader argument buffers 37 | struct encode_data_t { 38 | command_buffer indirect_buffer [[ id(0) ]]; 39 | }; 40 | 41 | kernel void 42 | encoding_kernel_index16(uint command_index [[ thread_position_in_grid ]], 43 | const device render_command_t* commands [[ buffer(0) ]], 44 | const device render_buffer_storage_t* buffer_storage [[ buffer(1) ]], 45 | const device pipeline_state_storage_t* state_storage [[ buffer(2) ]], 46 | device encode_data_t* encode [[ buffer(3) ]]) 47 | { 48 | const render_command_t command = commands[command_index]; 49 | 50 | render_command cmd(encode->indirect_buffer, command_index); 51 | 52 | cmd.set_render_pipeline_state(state_storage->pipeline_state[command.pipeline_state]); 53 | 54 | render_argument_t argument = ((const device render_argument_t*)buffer_storage->buffers[command.argument_buffer])[command.argument_offset]; 55 | 56 | cmd.set_vertex_buffer(buffer_storage->buffers[command.descriptor[0]], 0); 57 | cmd.set_vertex_buffer(buffer_storage->buffers[command.descriptor[1]], 1); 58 | cmd.set_vertex_buffer(buffer_storage->buffers[command.descriptor[2]], 2); 59 | cmd.set_vertex_buffer(buffer_storage->buffers[command.descriptor[3]], 3); 60 | 61 | cmd.draw_indexed_primitives(primitive_type::triangle, 62 | argument.index_count, 63 | (device ushort*)((const device char*)buffer_storage->buffers[command.index_buffer] + argument.index_offset), 64 | argument.instance_count, 65 | argument.vertex_offset, 66 | argument.instance_offset); 67 | } 68 | 69 | kernel void 70 | encoding_kernel_index32(uint command_index [[ thread_position_in_grid ]], 71 | const device render_command_t* commands [[ buffer(0) ]], 72 | const device render_buffer_storage_t* buffer_storage [[ buffer(1) ]], 73 | const device pipeline_state_storage_t* state_storage [[ buffer(2) ]], 74 | device encode_data_t* encode [[ buffer(3) ]]) 75 | { 76 | const render_command_t command = commands[command_index]; 77 | 78 | render_command cmd(encode->indirect_buffer, command_index); 79 | 80 | cmd.set_render_pipeline_state(state_storage->pipeline_state[command.pipeline_state]); 81 | 82 | render_argument_t argument = ((const device render_argument_t*)buffer_storage->buffers[command.argument_buffer])[command.argument_offset]; 83 | 84 | cmd.set_vertex_buffer(buffer_storage->buffers[command.descriptor[0]], 0); 85 | cmd.set_vertex_buffer(buffer_storage->buffers[command.descriptor[1]], 1); 86 | cmd.set_vertex_buffer(buffer_storage->buffers[command.descriptor[2]], 2); 87 | cmd.set_vertex_buffer(buffer_storage->buffers[command.descriptor[3]], 3); 88 | 89 | cmd.draw_indexed_primitives(primitive_type::triangle, 90 | argument.index_count, 91 | (device uint*)((const device char*)buffer_storage->buffers[command.index_buffer] + argument.index_offset), 92 | argument.instance_count, 93 | argument.vertex_offset, 94 | argument.instance_offset); 95 | } 96 | -------------------------------------------------------------------------------- /resource/shader/pipeline.shader: -------------------------------------------------------------------------------- 1 | metal pipeline.metal 2 | -------------------------------------------------------------------------------- /resource/shader/white.metal: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | using namespace metal; 5 | 6 | // Vertex declaration 7 | typedef struct vertex_t { 8 | vector_float4 position; 9 | vector_float4 color; 10 | } vertex_t; 11 | 12 | // Vertex shader argument buffers 13 | struct vertex_shader_global_arg_t { 14 | const float4x4 world_to_clip [[ id(0) ]]; 15 | }; 16 | 17 | struct vertex_shader_material_arg_t { 18 | const float4 color [[ id(0) ]]; 19 | }; 20 | 21 | struct vertex_shader_instance_arg_t { 22 | const float4x4 model_to_world [[ id(0) ]]; 23 | }; 24 | 25 | // Vertex shader to pixel shader data exchange 26 | struct rasterizer_data_t { 27 | float4 position [[position]]; 28 | }; 29 | 30 | vertex rasterizer_data_t 31 | vertex_shader(uint vid [[ vertex_id ]], 32 | const device vertex_shader_global_arg_t* global [[ buffer(0) ]], 33 | const device vertex_shader_material_arg_t* material [[ buffer(1) ]], 34 | const device vertex_shader_instance_arg_t* instance [[ buffer(2) ]], 35 | const device vertex_t* vertices [[ buffer(3) ]]) { 36 | rasterizer_data_t out; 37 | 38 | out.position = (vertices[vid].position * instance->model_to_world) * global->world_to_clip; 39 | 40 | return out; 41 | } 42 | 43 | fragment float4 44 | pixel_shader(rasterizer_data_t in [[ stage_in ]]) { 45 | return (float4){1.0, 1.0, 1.0, 1.0}; 46 | } 47 | -------------------------------------------------------------------------------- /resource/shader/white.shader: -------------------------------------------------------------------------------- 1 | metal white.metal 2 | -------------------------------------------------------------------------------- /test/all/android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 13 | 14 | 19 | 20 | 21 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /test/all/android/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/android/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /test/all/android/drawable-ldpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/android/drawable-ldpi/icon.png -------------------------------------------------------------------------------- /test/all/android/drawable-mdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/android/drawable-mdpi/icon.png -------------------------------------------------------------------------------- /test/all/android/drawable-xhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/android/drawable-xhdpi/icon.png -------------------------------------------------------------------------------- /test/all/android/drawable-xxhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/android/drawable-xxhdpi/icon.png -------------------------------------------------------------------------------- /test/all/android/drawable-xxxhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/android/drawable-xxxhdpi/icon.png -------------------------------------------------------------------------------- /test/all/android/java/com/maniccoder/render/test/TestActivity.java: -------------------------------------------------------------------------------- 1 | package com.maniccoder.render.test; 2 | 3 | import android.os.Bundle; 4 | import android.app.NativeActivity; 5 | import android.graphics.Color; 6 | import android.graphics.Point; 7 | import android.widget.TextView; 8 | import android.util.Log; 9 | import android.widget.LinearLayout; 10 | import android.widget.PopupWindow; 11 | import android.view.Gravity; 12 | import android.view.Display; 13 | import android.view.ViewGroup; 14 | import android.view.ViewGroup.LayoutParams; 15 | import android.view.ViewGroup.MarginLayoutParams; 16 | 17 | public class TestActivity extends NativeActivity 18 | { 19 | private TextView textView; 20 | private boolean displayedTextView = false; 21 | 22 | @Override 23 | public void onWindowFocusChanged( boolean hasFocus ) 24 | { 25 | super.onWindowFocusChanged( hasFocus ); 26 | 27 | if( !displayedTextView && hasFocus ) 28 | { 29 | displayedTextView = true; 30 | 31 | setContentView( R.layout.main ); 32 | 33 | textView = (TextView)findViewById( R.id.logtext ); 34 | textView.setText( "" ); 35 | ((ViewGroup)textView.getParent()).removeView(textView); 36 | 37 | final TestActivity activity = this; 38 | 39 | runOnUiThread( new Runnable() { 40 | 41 | @Override 42 | public void run() 43 | { 44 | PopupWindow popup = new PopupWindow( activity ); 45 | 46 | Display display = getWindowManager().getDefaultDisplay(); 47 | Point size = new Point(); 48 | display.getSize( size ); 49 | 50 | popup.setWidth( size.x ); 51 | popup.setHeight( size.y ); 52 | popup.setWindowLayoutMode( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT ); 53 | popup.setClippingEnabled( false ); 54 | 55 | MarginLayoutParams params = new MarginLayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT ); 56 | params.setMargins(0, 0, 0, 0); 57 | 58 | LinearLayout layout = new LinearLayout( activity ); 59 | layout.setOrientation( LinearLayout.VERTICAL ); 60 | layout.addView( activity.textView, params ); 61 | 62 | popup.setContentView( layout ); 63 | 64 | final ViewGroup viewGroup = (ViewGroup)((ViewGroup)activity.findViewById( android.R.id.content )).getChildAt(0); 65 | 66 | popup.showAtLocation( viewGroup, Gravity.TOP, 0, 0 ); 67 | popup.update(); 68 | } 69 | } ); 70 | } 71 | } 72 | 73 | public void appendLog( final String msg ) 74 | { 75 | runOnUiThread( new Runnable() { 76 | @Override 77 | public void run() 78 | { 79 | if( textView != null ) 80 | textView.append( msg ); 81 | } 82 | } ); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /test/all/android/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /test/all/android/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Window Test Suite 4 | 5 | -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "29x29", 5 | "idiom" : "iphone", 6 | "filename" : "icon_29.png", 7 | "scale" : "1x" 8 | }, 9 | { 10 | "size" : "29x29", 11 | "idiom" : "iphone", 12 | "filename" : "icon_58.png", 13 | "scale" : "2x" 14 | }, 15 | { 16 | "size" : "40x40", 17 | "idiom" : "iphone", 18 | "filename" : "icon_80-1.png", 19 | "scale" : "2x" 20 | }, 21 | { 22 | "size" : "57x57", 23 | "idiom" : "iphone", 24 | "filename" : "icon_57.png", 25 | "scale" : "1x" 26 | }, 27 | { 28 | "size" : "57x57", 29 | "idiom" : "iphone", 30 | "filename" : "icon_114.png", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "size" : "60x60", 35 | "idiom" : "iphone", 36 | "filename" : "icon_120.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "60x60", 41 | "idiom" : "iphone", 42 | "filename" : "icon_180.png", 43 | "scale" : "3x" 44 | }, 45 | { 46 | "size" : "29x29", 47 | "idiom" : "ipad", 48 | "filename" : "icon_29-1.png", 49 | "scale" : "1x" 50 | }, 51 | { 52 | "size" : "29x29", 53 | "idiom" : "ipad", 54 | "filename" : "icon_58-1.png", 55 | "scale" : "2x" 56 | }, 57 | { 58 | "size" : "40x40", 59 | "idiom" : "ipad", 60 | "filename" : "icon_40.png", 61 | "scale" : "1x" 62 | }, 63 | { 64 | "size" : "40x40", 65 | "idiom" : "ipad", 66 | "filename" : "icon_80.png", 67 | "scale" : "2x" 68 | }, 69 | { 70 | "size" : "50x50", 71 | "idiom" : "ipad", 72 | "filename" : "icon_50.png", 73 | "scale" : "1x" 74 | }, 75 | { 76 | "size" : "50x50", 77 | "idiom" : "ipad", 78 | "filename" : "icon_100.png", 79 | "scale" : "2x" 80 | }, 81 | { 82 | "size" : "72x72", 83 | "idiom" : "ipad", 84 | "filename" : "icon_72.png", 85 | "scale" : "1x" 86 | }, 87 | { 88 | "size" : "72x72", 89 | "idiom" : "ipad", 90 | "filename" : "icon_144.png", 91 | "scale" : "2x" 92 | }, 93 | { 94 | "size" : "76x76", 95 | "idiom" : "ipad", 96 | "filename" : "icon_76.png", 97 | "scale" : "1x" 98 | }, 99 | { 100 | "size" : "76x76", 101 | "idiom" : "ipad", 102 | "filename" : "icon_152.png", 103 | "scale" : "2x" 104 | } 105 | ], 106 | "info" : { 107 | "version" : 1, 108 | "author" : "xcode" 109 | } 110 | } -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/AppIcon.appiconset/icon_100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/AppIcon.appiconset/icon_100.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/AppIcon.appiconset/icon_114.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/AppIcon.appiconset/icon_114.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/AppIcon.appiconset/icon_120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/AppIcon.appiconset/icon_120.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/AppIcon.appiconset/icon_144.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/AppIcon.appiconset/icon_144.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/AppIcon.appiconset/icon_152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/AppIcon.appiconset/icon_152.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/AppIcon.appiconset/icon_180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/AppIcon.appiconset/icon_180.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/AppIcon.appiconset/icon_29-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/AppIcon.appiconset/icon_29-1.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/AppIcon.appiconset/icon_29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/AppIcon.appiconset/icon_29.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/AppIcon.appiconset/icon_40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/AppIcon.appiconset/icon_40.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/AppIcon.appiconset/icon_50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/AppIcon.appiconset/icon_50.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/AppIcon.appiconset/icon_57.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/AppIcon.appiconset/icon_57.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/AppIcon.appiconset/icon_58-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/AppIcon.appiconset/icon_58-1.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/AppIcon.appiconset/icon_58.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/AppIcon.appiconset/icon_58.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/AppIcon.appiconset/icon_72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/AppIcon.appiconset/icon_72.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/AppIcon.appiconset/icon_76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/AppIcon.appiconset/icon_76.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/AppIcon.appiconset/icon_80-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/AppIcon.appiconset/icon_80-1.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/AppIcon.appiconset/icon_80.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/AppIcon.appiconset/icon_80.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "filename" : "launch_640_960.png", 9 | "scale" : "2x" 10 | }, 11 | { 12 | "extent" : "full-screen", 13 | "idiom" : "iphone", 14 | "subtype" : "retina4", 15 | "filename" : "launch_640_1136.png", 16 | "minimum-system-version" : "7.0", 17 | "orientation" : "portrait", 18 | "scale" : "2x" 19 | }, 20 | { 21 | "orientation" : "portrait", 22 | "idiom" : "ipad", 23 | "extent" : "full-screen", 24 | "minimum-system-version" : "7.0", 25 | "filename" : "launch_768_1024.png", 26 | "scale" : "1x" 27 | }, 28 | { 29 | "orientation" : "landscape", 30 | "idiom" : "ipad", 31 | "extent" : "full-screen", 32 | "minimum-system-version" : "7.0", 33 | "filename" : "launch_1024_768.png", 34 | "scale" : "1x" 35 | }, 36 | { 37 | "orientation" : "portrait", 38 | "idiom" : "ipad", 39 | "extent" : "full-screen", 40 | "minimum-system-version" : "7.0", 41 | "filename" : "launch_1536_2048.png", 42 | "scale" : "2x" 43 | }, 44 | { 45 | "orientation" : "landscape", 46 | "idiom" : "ipad", 47 | "extent" : "full-screen", 48 | "minimum-system-version" : "7.0", 49 | "filename" : "launch_2048_1536.png", 50 | "scale" : "2x" 51 | }, 52 | { 53 | "orientation" : "portrait", 54 | "idiom" : "iphone", 55 | "extent" : "full-screen", 56 | "filename" : "launch_320_480.png", 57 | "scale" : "1x" 58 | }, 59 | { 60 | "orientation" : "portrait", 61 | "idiom" : "iphone", 62 | "extent" : "full-screen", 63 | "filename" : "launch_640_960.png", 64 | "scale" : "2x" 65 | }, 66 | { 67 | "orientation" : "portrait", 68 | "idiom" : "iphone", 69 | "extent" : "full-screen", 70 | "filename" : "launch_640_1136.png", 71 | "subtype" : "retina4", 72 | "scale" : "2x" 73 | }, 74 | { 75 | "orientation" : "portrait", 76 | "idiom" : "ipad", 77 | "extent" : "to-status-bar", 78 | "filename" : "launch_768_1004.png", 79 | "scale" : "1x" 80 | }, 81 | { 82 | "orientation" : "landscape", 83 | "idiom" : "ipad", 84 | "extent" : "to-status-bar", 85 | "filename" : "launch_1024_748.png", 86 | "scale" : "1x" 87 | }, 88 | { 89 | "orientation" : "portrait", 90 | "idiom" : "ipad", 91 | "extent" : "to-status-bar", 92 | "filename" : "launch_1536_2008.png", 93 | "scale" : "2x" 94 | }, 95 | { 96 | "orientation" : "landscape", 97 | "idiom" : "ipad", 98 | "extent" : "to-status-bar", 99 | "filename" : "launch_2048_1496.png", 100 | "scale" : "2x" 101 | } 102 | ], 103 | "info" : { 104 | "version" : 1, 105 | "author" : "xcode" 106 | } 107 | } -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/LaunchImage.launchimage/launch_1024_748.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/LaunchImage.launchimage/launch_1024_748.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/LaunchImage.launchimage/launch_1024_768.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/LaunchImage.launchimage/launch_1024_768.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/LaunchImage.launchimage/launch_1536_2008.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/LaunchImage.launchimage/launch_1536_2008.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/LaunchImage.launchimage/launch_1536_2048.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/LaunchImage.launchimage/launch_1536_2048.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/LaunchImage.launchimage/launch_2048_1496.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/LaunchImage.launchimage/launch_2048_1496.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/LaunchImage.launchimage/launch_2048_1536.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/LaunchImage.launchimage/launch_2048_1536.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/LaunchImage.launchimage/launch_320_480.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/LaunchImage.launchimage/launch_320_480.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/LaunchImage.launchimage/launch_640_1136.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/LaunchImage.launchimage/launch_640_1136.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/LaunchImage.launchimage/launch_640_960.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/LaunchImage.launchimage/launch_640_960.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/LaunchImage.launchimage/launch_768_1004.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/LaunchImage.launchimage/launch_768_1004.png -------------------------------------------------------------------------------- /test/all/ios/Images.xcassets/LaunchImage.launchimage/launch_768_1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/ios/Images.xcassets/LaunchImage.launchimage/launch_768_1024.png -------------------------------------------------------------------------------- /test/all/ios/test-all.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.maniccoder.render.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | Foundation 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | TEST 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | NSMainNibFile 26 | test-all 27 | NSMainNibFile~ipad 28 | test-all 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UIStatusBarHidden 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeLeft 39 | UIInterfaceOrientationLandscapeRight 40 | UIInterfaceOrientationPortraitUpsideDown 41 | 42 | UISupportedInterfaceOrientations~ipad 43 | 44 | UIInterfaceOrientationPortrait 45 | UIInterfaceOrientationPortraitUpsideDown 46 | UIInterfaceOrientationLandscapeLeft 47 | UIInterfaceOrientationLandscapeRight 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /test/all/ios/test-all.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /test/all/ios/viewcontroller.h: -------------------------------------------------------------------------------- 1 | /* viewcontroller.h - Foundation test launcher - Public Domain - 2013 Mattias Jansson 2 | * 3 | * This library provides a cross-platform foundation library in C11 providing basic support 4 | * data types and functions to write applications and games in a platform-independent fashion. 5 | * The latest source code is always available at 6 | * 7 | * https://github.com/mjansson/foundation_lib 8 | * 9 | * This library is put in the public domain; you can redistribute it and/or modify it without 10 | * any restrictions. 11 | */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | 18 | #ifdef __OBJC__ 19 | 20 | @interface ViewController : UIViewController { 21 | @public 22 | } 23 | @end 24 | 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /test/all/ios/viewcontroller.m: -------------------------------------------------------------------------------- 1 | /* viewcontroller.m - Foundation test launcher - Public Domain - 2013 Mattias Jansson 2 | * 3 | * This library provides a cross-platform foundation library in C11 providing basic support 4 | * data types and functions to write applications and games in a platform-independent fashion. 5 | * The latest source code is always available at 6 | * 7 | * https://github.com/mjansson/foundation_lib 8 | * 9 | * This library is put in the public domain; you can redistribute it and/or modify it without 10 | * any restrictions. 11 | */ 12 | 13 | #include "viewcontroller.h" 14 | 15 | @interface ViewController() 16 | @end 17 | 18 | @implementation ViewController 19 | 20 | - (void)viewDidLoad { 21 | [super viewDidLoad]; 22 | 23 | if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) 24 | [self setNeedsStatusBarAppearanceUpdate]; 25 | else 26 | [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; 27 | } 28 | 29 | - (void)didReceiveMemoryWarning { 30 | [super didReceiveMemoryWarning]; 31 | } 32 | 33 | - (BOOL)prefersStatusBarHidden { 34 | return TRUE; 35 | } 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /test/all/tizen/res/tizenapp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/all/tizen/res/tizenapp.png -------------------------------------------------------------------------------- /test/all/tizen/tizen-manifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | tizenapp.png 6 | 7 | 8 | 9 | http://tizen.org/privilege/systemsettings 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/render/macos/Images.xcassets/AppIcon-2.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac", 5 | "scale" : "1x", 6 | "size" : "16x16" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "scale" : "2x", 11 | "size" : "16x16" 12 | }, 13 | { 14 | "idiom" : "mac", 15 | "scale" : "1x", 16 | "size" : "32x32" 17 | }, 18 | { 19 | "idiom" : "mac", 20 | "scale" : "2x", 21 | "size" : "32x32" 22 | }, 23 | { 24 | "idiom" : "mac", 25 | "scale" : "1x", 26 | "size" : "128x128" 27 | }, 28 | { 29 | "idiom" : "mac", 30 | "scale" : "2x", 31 | "size" : "128x128" 32 | }, 33 | { 34 | "idiom" : "mac", 35 | "scale" : "1x", 36 | "size" : "256x256" 37 | }, 38 | { 39 | "idiom" : "mac", 40 | "scale" : "2x", 41 | "size" : "256x256" 42 | }, 43 | { 44 | "idiom" : "mac", 45 | "scale" : "1x", 46 | "size" : "512x512" 47 | }, 48 | { 49 | "idiom" : "mac", 50 | "scale" : "2x", 51 | "size" : "512x512" 52 | } 53 | ], 54 | "info" : { 55 | "author" : "xcode", 56 | "version" : 1 57 | } 58 | } -------------------------------------------------------------------------------- /test/render/macos/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "16x16", 5 | "idiom" : "mac", 6 | "filename" : "icon_16.png", 7 | "scale" : "1x" 8 | }, 9 | { 10 | "size" : "16x16", 11 | "idiom" : "mac", 12 | "filename" : "icon_32-1.png", 13 | "scale" : "2x" 14 | }, 15 | { 16 | "size" : "32x32", 17 | "idiom" : "mac", 18 | "filename" : "icon_32.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "32x32", 23 | "idiom" : "mac", 24 | "filename" : "icon_64.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "128x128", 29 | "idiom" : "mac", 30 | "filename" : "icon_128.png", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "size" : "128x128", 35 | "idiom" : "mac", 36 | "filename" : "icon_256-1.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "256x256", 41 | "idiom" : "mac", 42 | "filename" : "icon_256.png", 43 | "scale" : "1x" 44 | }, 45 | { 46 | "size" : "256x256", 47 | "idiom" : "mac", 48 | "filename" : "icon_512-1.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "512x512", 53 | "idiom" : "mac", 54 | "filename" : "icon_512.png", 55 | "scale" : "1x" 56 | }, 57 | { 58 | "size" : "512x512", 59 | "idiom" : "mac", 60 | "filename" : "icon_1024.png", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /test/render/macos/Images.xcassets/AppIcon.appiconset/icon_1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/render/macos/Images.xcassets/AppIcon.appiconset/icon_1024.png -------------------------------------------------------------------------------- /test/render/macos/Images.xcassets/AppIcon.appiconset/icon_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/render/macos/Images.xcassets/AppIcon.appiconset/icon_128.png -------------------------------------------------------------------------------- /test/render/macos/Images.xcassets/AppIcon.appiconset/icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/render/macos/Images.xcassets/AppIcon.appiconset/icon_16.png -------------------------------------------------------------------------------- /test/render/macos/Images.xcassets/AppIcon.appiconset/icon_256-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/render/macos/Images.xcassets/AppIcon.appiconset/icon_256-1.png -------------------------------------------------------------------------------- /test/render/macos/Images.xcassets/AppIcon.appiconset/icon_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/render/macos/Images.xcassets/AppIcon.appiconset/icon_256.png -------------------------------------------------------------------------------- /test/render/macos/Images.xcassets/AppIcon.appiconset/icon_32-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/render/macos/Images.xcassets/AppIcon.appiconset/icon_32-1.png -------------------------------------------------------------------------------- /test/render/macos/Images.xcassets/AppIcon.appiconset/icon_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/render/macos/Images.xcassets/AppIcon.appiconset/icon_32.png -------------------------------------------------------------------------------- /test/render/macos/Images.xcassets/AppIcon.appiconset/icon_512-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/render/macos/Images.xcassets/AppIcon.appiconset/icon_512-1.png -------------------------------------------------------------------------------- /test/render/macos/Images.xcassets/AppIcon.appiconset/icon_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/render/macos/Images.xcassets/AppIcon.appiconset/icon_512.png -------------------------------------------------------------------------------- /test/render/macos/Images.xcassets/AppIcon.appiconset/icon_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjansson/render_lib/6e32b5823ccb16e2aa99910f85e3ff65dc2dc8f9/test/render/macos/Images.xcassets/AppIcon.appiconset/icon_64.png -------------------------------------------------------------------------------- /test/render/macos/test-render.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.files.user-selected.read-only 8 | 9 | com.apple.security.get-task-allow 10 | 11 | com.apple.security.network.client 12 | 13 | com.apple.security.network.server 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /test/render/macos/test-render.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | MAJA 21 | CFBundleVersion 22 | 1 23 | LSMinimumSystemVersion 24 | ${MACOSX_DEPLOYMENT_TARGET} 25 | NSHumanReadableCopyright 26 | Copyright © 2014 Mattias Jansson. All rights reserved. 27 | NSMainNibFile 28 | test-render 29 | NSPrincipalClass 30 | NSApplication 31 | MetalCaptureEnabled 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /test/render/macos/test-render.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /tools/rendercompile/errorcodes.h: -------------------------------------------------------------------------------- 1 | /* errorcodes.h - Render library compiler - Public Domain - 2015 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The foundation library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson/foundation_lib 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #pragma once 19 | 20 | //Error codes returned by rendercompile tool 21 | #define RENDERCOMPILE_RESULT_OK 0 22 | #define RENDERCOMPILE_RESULT_UNSUPPORTED_INPUT -1 23 | #define RENDERCOMPILE_RESULT_INVALID_INPUT -2 24 | -------------------------------------------------------------------------------- /tools/renderimport/errorcodes.h: -------------------------------------------------------------------------------- 1 | /* errorcodes.h - Render library importer - Public Domain - 2015 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The foundation library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson/foundation_lib 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #pragma once 19 | 20 | //Error codes returned by renderimport tool 21 | #define RENDERIMPORT_RESULT_OK 0 22 | #define RENDERIMPORT_RESULT_UNSUPPORTED_INPUT -1 23 | #define RENDERIMPORT_RESULT_INVALID_ARGUMENT -2 24 | #define RENDERIMPORT_RESULT_UNKNOWN_COMMAND -3 25 | #define RENDERIMPORT_RESULT_UNABLE_TO_OPEN_OUTPUT_FILE -4 26 | #define RENDERIMPORT_RESULT_INVALID_INPUT -5 27 | #define RENDERIMPORT_RESULT_UNABLE_TO_OPEN_MAP_FILE -6 28 | #define RENDERIMPORT_RESULT_UNABLE_TO_WRITE_BLOB -7 29 | #define RENDERIMPORT_RESULT_UNABLE_TO_WRITE_SOURCE -8 30 | #define RENDERIMPORT_RESULT_UUID_MISMATCH -9 31 | -------------------------------------------------------------------------------- /tools/renderimport/main.c: -------------------------------------------------------------------------------- 1 | /* main.c - Render library importer - Public Domain - 2014 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The foundation library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson/foundation_lib 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "main.h" 25 | #include "errorcodes.h" 26 | 27 | typedef struct { 28 | bool display_help; 29 | int binary; 30 | string_const_t source_path; 31 | string_const_t* config_files; 32 | string_const_t* input_files; 33 | } renderimport_input_t; 34 | 35 | static void 36 | renderimport_parse_config(const char* path, size_t path_size, 37 | const char* buffer, size_t size, 38 | const json_token_t* tokens, size_t numtokens); 39 | 40 | static renderimport_input_t 41 | renderimport_parse_command_line(const string_const_t* cmdline); 42 | 43 | static void 44 | renderimport_print_usage(void); 45 | 46 | int 47 | main_initialize(void) { 48 | int ret = 0; 49 | application_t application; 50 | foundation_config_t foundation_config; 51 | resource_config_t resource_config; 52 | window_config_t window_config; 53 | network_config_t network_config; 54 | render_config_t render_config; 55 | 56 | memset(&foundation_config, 0, sizeof(foundation_config)); 57 | memset(&resource_config, 0, sizeof(resource_config)); 58 | memset(&window_config, 0, sizeof(window_config)); 59 | memset(&network_config, 0, sizeof(network_config)); 60 | memset(&render_config, 0, sizeof(render_config)); 61 | 62 | memset(&application, 0, sizeof(application)); 63 | application.name = string_const(STRING_CONST("renderimport")); 64 | application.short_name = string_const(STRING_CONST("renderimport")); 65 | application.company = string_const(STRING_CONST("")); 66 | application.flags = APPLICATION_UTILITY; 67 | application.version = render_module_version(); 68 | 69 | log_enable_prefix(false); 70 | log_set_suppress(0, ERRORLEVEL_WARNING); 71 | 72 | resource_config.enable_local_autoimport = true; 73 | resource_config.enable_local_source = true; 74 | resource_config.enable_local_cache = true; 75 | 76 | if ((ret = foundation_initialize(memory_system_malloc(), application, foundation_config)) < 0) 77 | return ret; 78 | if ((ret = network_module_initialize(network_config)) < 0) 79 | return ret; 80 | if ((ret = resource_module_initialize(resource_config)) < 0) 81 | return ret; 82 | if ((ret = window_module_initialize(window_config)) < 0) 83 | return ret; 84 | if ((ret = render_module_initialize(render_config)) < 0) 85 | return ret; 86 | 87 | log_set_suppress(HASH_RESOURCE, ERRORLEVEL_DEBUG); 88 | 89 | return 0; 90 | } 91 | 92 | int 93 | main_run(void* main_arg) { 94 | int result = RENDERIMPORT_RESULT_OK; 95 | renderimport_input_t input = renderimport_parse_command_line(environment_command_line()); 96 | 97 | FOUNDATION_UNUSED(main_arg); 98 | 99 | for (size_t cfgfile = 0, fsize = array_size(input.config_files); cfgfile < fsize; ++cfgfile) 100 | sjson_parse_path(STRING_ARGS(input.config_files[cfgfile]), renderimport_parse_config); 101 | 102 | if (input.source_path.length) 103 | resource_source_set_path(STRING_ARGS(input.source_path)); 104 | 105 | if (!resource_source_path().length) { 106 | log_errorf(HASH_RESOURCE, ERROR_INVALID_VALUE, STRING_CONST("No source path given")); 107 | input.display_help = true; 108 | } 109 | 110 | if (input.display_help) { 111 | renderimport_print_usage(); 112 | goto exit; 113 | } 114 | 115 | resource_import_register(render_import); 116 | 117 | size_t ifile, fsize; 118 | for (ifile = 0, fsize = array_size(input.input_files); ifile < fsize; ++ifile) { 119 | if (resource_import(STRING_ARGS(input.input_files[ifile]), uuid_null())) 120 | log_infof(HASH_RESOURCE, STRING_CONST("Successfully imported: %.*s"), 121 | STRING_FORMAT(input.input_files[ifile])); 122 | else 123 | log_warnf(HASH_RESOURCE, WARNING_UNSUPPORTED, STRING_CONST("Failed to import: %.*s"), 124 | STRING_FORMAT(input.input_files[ifile])); 125 | } 126 | 127 | exit: 128 | 129 | array_deallocate(input.config_files); 130 | array_deallocate(input.input_files); 131 | 132 | return result; 133 | } 134 | 135 | void 136 | main_finalize(void) { 137 | render_module_finalize(); 138 | window_module_finalize(); 139 | resource_module_finalize(); 140 | foundation_finalize(); 141 | } 142 | 143 | static void 144 | renderimport_parse_config(const char* path, size_t path_size, 145 | const char* buffer, size_t size, 146 | const json_token_t* tokens, size_t numtokens) { 147 | resource_module_parse_config(path, path_size, buffer, size, tokens, numtokens); 148 | render_module_parse_config(path, path_size, buffer, size, tokens, numtokens); 149 | } 150 | 151 | static renderimport_input_t 152 | renderimport_parse_command_line(const string_const_t* cmdline) { 153 | renderimport_input_t input; 154 | size_t arg, asize; 155 | 156 | memset(&input, 0, sizeof(input)); 157 | 158 | for (arg = 1, asize = array_size(cmdline); arg < asize; ++arg) { 159 | if (string_equal(STRING_ARGS(cmdline[arg]), STRING_CONST("--help"))) 160 | input.display_help = true; 161 | else if (string_equal(STRING_ARGS(cmdline[arg]), STRING_CONST("--source"))) { 162 | if (arg < asize - 1) 163 | input.source_path = cmdline[++arg]; 164 | } 165 | else if (string_equal(STRING_ARGS(cmdline[arg]), STRING_CONST("--config"))) { 166 | if (arg < asize - 1) 167 | array_push(input.config_files, cmdline[++arg]); 168 | } 169 | /*else if (string_equal(STRING_ARGS(cmdline[arg]), STRING_CONST("--uuid"))) { 170 | if (arg < asize - 1) { 171 | ++arg; 172 | input.uuid = string_to_uuid(STRING_ARGS(cmdline[arg])); 173 | if (uuid_is_null(input.uuid)) 174 | log_warnf(HASH_RESOURCE, WARNING_INVALID_VALUE, STRING_CONST("Invalid UUID: %.*s"), 175 | STRING_FORMAT(cmdline[arg])); 176 | } 177 | } 178 | else if (string_equal(STRING_ARGS(cmdline[arg]), STRING_CONST("--set"))) { 179 | if (arg < asize - 2) { 180 | input.key = cmdline[++arg]; 181 | input.value = cmdline[++arg]; 182 | } 183 | }*/ 184 | else if (string_equal(STRING_ARGS(cmdline[arg]), STRING_CONST("--binary"))) { 185 | input.binary = 1; 186 | } 187 | else if (string_equal(STRING_ARGS(cmdline[arg]), STRING_CONST("--ascii"))) { 188 | input.binary = 0; 189 | } 190 | else if (string_equal(STRING_ARGS(cmdline[arg]), STRING_CONST("--debug"))) { 191 | log_set_suppress(0, ERRORLEVEL_NONE); 192 | log_set_suppress(HASH_RESOURCE, ERRORLEVEL_NONE); 193 | log_set_suppress(HASH_RENDER, ERRORLEVEL_NONE); 194 | } 195 | else if (string_equal(STRING_ARGS(cmdline[arg]), STRING_CONST("--"))) 196 | break; //Stop parsing cmdline options 197 | else { 198 | array_push(input.input_files, cmdline[arg]); 199 | } 200 | } 201 | error_context_pop(); 202 | 203 | if (!array_size(input.input_files)) { 204 | log_errorf(HASH_RESOURCE, ERROR_INVALID_VALUE, STRING_CONST("No input files given")); 205 | input.display_help = true; 206 | } 207 | 208 | return input; 209 | } 210 | 211 | static void 212 | renderimport_print_usage(void) { 213 | const error_level_t saved_level = log_suppress(0); 214 | log_set_suppress(0, ERRORLEVEL_DEBUG); 215 | log_info(0, STRING_CONST( 216 | "renderimport usage:\n" 217 | " renderimport [--source ] [--config ...] [--ascii] [--binary]\n" 218 | " [--debug] [--help] ... [--]\n" 219 | " Arguments:\n" 220 | " ... Any number of input files\n" 221 | " Optional arguments:\n" 222 | " --source Operate on resource file source structure given by \n" 223 | " --config Read and parse config file given by \n" 224 | " Loads all .json/.sjson files in if it is a directory\n" 225 | " --binary Write binary files\n" 226 | " --ascii Write ASCII files (default)\n" 227 | " --debug Enable debug output\n" 228 | " --help Display this help message\n" 229 | " -- Stop processing command line arguments" 230 | )); 231 | log_set_suppress(0, saved_level); 232 | } 233 | -------------------------------------------------------------------------------- /tools/renderimport/main.h: -------------------------------------------------------------------------------- 1 | /* main.h - Render library importer - Public Domain - 2014 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The foundation library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson/foundation_lib 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | #include "errorcodes.h" 24 | 25 | -------------------------------------------------------------------------------- /tools/shaderview/main.c: -------------------------------------------------------------------------------- 1 | /* main.c - Render library shader view - Public Domain - 2014 Mattias Jansson 2 | * 3 | * This library provides a cross-platform rendering library in C11 providing 4 | * basic 2D/3D rendering functionality for projects based on our foundation library. 5 | * 6 | * The latest source code maintained by Mattias Jansson is always available at 7 | * 8 | * https://github.com/mjansson/render_lib 9 | * 10 | * The foundation library source code maintained by Mattias Jansson is always available at 11 | * 12 | * https://github.com/mjansson/foundation_lib 13 | * 14 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 15 | * 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | typedef struct { 24 | bool display_help; 25 | int binary; 26 | string_const_t source_path; 27 | string_const_t* config_files; 28 | string_const_t* input_files; 29 | } shaderview_input_t; 30 | 31 | static void 32 | shaderview_parse_config(const char* path, size_t path_size, 33 | const char* buffer, size_t size, 34 | const json_token_t* tokens, size_t numtokens); 35 | 36 | static shaderview_input_t 37 | shaderview_parse_command_line(const string_const_t* cmdline); 38 | 39 | static void 40 | shaderview_print_usage(void); 41 | 42 | static void 43 | shaderview_load_config(const char* path, size_t length); 44 | 45 | int 46 | main_initialize(void) { 47 | int ret = 0; 48 | application_t application; 49 | foundation_config_t foundation_config; 50 | resource_config_t resource_config; 51 | window_config_t window_config; 52 | render_config_t render_config; 53 | 54 | memset(&foundation_config, 0, sizeof(foundation_config)); 55 | memset(&resource_config, 0, sizeof(resource_config)); 56 | memset(&window_config, 0, sizeof(window_config)); 57 | memset(&render_config, 0, sizeof(render_config)); 58 | 59 | memset(&application, 0, sizeof(application)); 60 | application.name = string_const(STRING_CONST("shaderview")); 61 | application.short_name = string_const(STRING_CONST("shaderview")); 62 | application.company = string_const(STRING_CONST("")); 63 | application.flags = APPLICATION_UTILITY; 64 | application.version = render_module_version(); 65 | 66 | log_enable_prefix(false); 67 | log_set_suppress(0, ERRORLEVEL_INFO); 68 | 69 | resource_config.enable_local_source = true; 70 | resource_config.enable_local_cache = true; 71 | resource_config.enable_local_autoimport = true; 72 | resource_config.enable_remote_sourced = true; 73 | resource_config.enable_remote_compiled = true; 74 | 75 | if ((ret = foundation_initialize(memory_system_malloc(), application, foundation_config)) < 0) 76 | return ret; 77 | if ((ret = resource_module_initialize(resource_config)) < 0) 78 | return ret; 79 | if ((ret = window_module_initialize(window_config)) < 0) 80 | return ret; 81 | if ((ret = render_module_initialize(render_config)) < 0) 82 | return ret; 83 | 84 | return 0; 85 | } 86 | 87 | int 88 | main_run(void* main_arg) { 89 | int result = 0; 90 | shaderview_input_t input = shaderview_parse_command_line(environment_command_line()); 91 | 92 | FOUNDATION_UNUSED(main_arg); 93 | 94 | for (size_t cfgfile = 0, fsize = array_size(input.config_files); cfgfile < fsize; ++cfgfile) 95 | sjson_parse_path(STRING_ARGS(input.config_files[cfgfile]), shaderview_parse_config); 96 | 97 | if (input.source_path.length) 98 | resource_source_set_path(STRING_ARGS(input.source_path)); 99 | 100 | if (!resource_source_path().length) { 101 | log_errorf(HASH_RESOURCE, ERROR_INVALID_VALUE, STRING_CONST("No source path given")); 102 | input.display_help = true; 103 | } 104 | 105 | if (input.display_help) { 106 | shaderview_print_usage(); 107 | goto exit; 108 | } 109 | 110 | size_t ifile, fsize; 111 | for (ifile = 0, fsize = array_size(input.input_files); ifile < fsize; ++ifile) { 112 | if (resource_import(STRING_ARGS(input.input_files[ifile]), uuid_null())) 113 | log_infof(HASH_RESOURCE, STRING_CONST("Successfully imported: %.*s"), 114 | STRING_FORMAT(input.input_files[ifile])); 115 | else 116 | log_warnf(HASH_RESOURCE, WARNING_UNSUPPORTED, STRING_CONST("Failed to import: %.*s"), 117 | STRING_FORMAT(input.input_files[ifile])); 118 | } 119 | 120 | exit: 121 | 122 | array_deallocate(input.config_files); 123 | array_deallocate(input.input_files); 124 | 125 | return result; 126 | } 127 | 128 | void 129 | main_finalize(void) { 130 | render_module_finalize(); 131 | window_module_finalize(); 132 | resource_module_finalize(); 133 | foundation_finalize(); 134 | } 135 | 136 | static void 137 | shaderview_parse_config(const char* path, size_t path_size, 138 | const char* buffer, size_t size, 139 | const json_token_t* tokens, size_t numtokens) { 140 | resource_module_parse_config(path, path_size, buffer, size, tokens, numtokens); 141 | render_module_parse_config(path, path_size, buffer, size, tokens, numtokens); 142 | } 143 | 144 | static shaderview_input_t 145 | shaderview_parse_command_line(const string_const_t* cmdline) { 146 | shaderview_input_t input; 147 | size_t arg, asize; 148 | 149 | memset(&input, 0, sizeof(input)); 150 | 151 | for (arg = 1, asize = array_size(cmdline); arg < asize; ++arg) { 152 | if (string_equal(STRING_ARGS(cmdline[arg]), STRING_CONST("--help"))) 153 | input.display_help = true; 154 | else if (string_equal(STRING_ARGS(cmdline[arg]), STRING_CONST("--source"))) { 155 | if (arg < asize - 1) 156 | input.source_path = cmdline[++arg]; 157 | } 158 | else if (string_equal(STRING_ARGS(cmdline[arg]), STRING_CONST("--config"))) { 159 | if (arg < asize - 1) 160 | array_push(input.config_files, cmdline[++arg]); 161 | } 162 | /*else if (string_equal(STRING_ARGS(cmdline[arg]), STRING_CONST("--uuid"))) { 163 | if (arg < asize - 1) { 164 | ++arg; 165 | input.uuid = string_to_uuid(STRING_ARGS(cmdline[arg])); 166 | if (uuid_is_null(input.uuid)) 167 | log_warnf(HASH_RESOURCE, WARNING_INVALID_VALUE, STRING_CONST("Invalid UUID: %.*s"), 168 | STRING_FORMAT(cmdline[arg])); 169 | } 170 | } 171 | else if (string_equal(STRING_ARGS(cmdline[arg]), STRING_CONST("--set"))) { 172 | if (arg < asize - 2) { 173 | input.key = cmdline[++arg]; 174 | input.value = cmdline[++arg]; 175 | } 176 | }*/ 177 | else if (string_equal(STRING_ARGS(cmdline[arg]), STRING_CONST("--binary"))) { 178 | input.binary = 1; 179 | } 180 | else if (string_equal(STRING_ARGS(cmdline[arg]), STRING_CONST("--ascii"))) { 181 | input.binary = 0; 182 | } 183 | else if (string_equal(STRING_ARGS(cmdline[arg]), STRING_CONST("--debug"))) { 184 | log_set_suppress(0, ERRORLEVEL_NONE); 185 | log_set_suppress(HASH_RESOURCE, ERRORLEVEL_NONE); 186 | log_set_suppress(HASH_RENDER, ERRORLEVEL_NONE); 187 | } 188 | else if (string_equal(STRING_ARGS(cmdline[arg]), STRING_CONST("--"))) 189 | break; //Stop parsing cmdline options 190 | else { 191 | array_push(input.input_files, cmdline[arg]); 192 | } 193 | } 194 | error_context_pop(); 195 | 196 | if (!array_size(input.input_files)) { 197 | log_errorf(HASH_RESOURCE, ERROR_INVALID_VALUE, STRING_CONST("No input files given")); 198 | input.display_help = true; 199 | } 200 | 201 | return input; 202 | } 203 | 204 | static void 205 | shaderview_print_usage(void) { 206 | const error_level_t saved_level = log_suppress(0); 207 | log_set_suppress(0, ERRORLEVEL_DEBUG); 208 | log_info(0, STRING_CONST( 209 | "shaderview usage:\n" 210 | " shaderview [--source ] [--config ...] [--ascii] [--binary]\n" 211 | " [--debug] [--help] ... [--]\n" 212 | " Arguments:\n" 213 | " ... Any number of input files\n" 214 | " Optional arguments:\n" 215 | " --source Operate on resource file source structure given by \n" 216 | " --config Read and parse config file given by \n" 217 | " Loads all .json/.sjson files in if it is a directory\n" 218 | " --binary Write binary files\n" 219 | " --ascii Write ASCII files (default)\n" 220 | " --debug Enable debug output\n" 221 | " --help Display this help message\n" 222 | " -- Stop processing command line arguments" 223 | )); 224 | log_set_suppress(0, saved_level); 225 | } 226 | --------------------------------------------------------------------------------