├── .gitattributes
├── .gitignore
└── DirectX 11 Engine VS2017
├── DirectX 11 Engine VS2017.sln
└── DirectX 11 Engine VS2017
├── DirectX 11 Engine VS2017.vcxproj
├── DirectX 11 Engine VS2017.vcxproj.filters
├── Includes
├── Audio.h
├── CommonStates.h
├── DDSTextureLoader.h
├── DirectXHelpers.h
├── Effects.h
├── GamePad.h
├── GeometricPrimitive.h
├── GraphicsMemory.h
├── Keyboard.h
├── Model.h
├── Mouse.h
├── PostProcess.h
├── PrimitiveBatch.h
├── ScreenGrab.h
├── SimpleMath.h
├── SimpleMath.inl
├── SpriteBatch.h
├── SpriteFont.h
├── VertexTypes.h
├── WICTextureLoader.h
└── XboxDDSTextureLoader.h
└── Source.cpp
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # NCrunch
114 | _NCrunch_*
115 | .*crunch*.local.xml
116 | nCrunchTemp_*
117 |
118 | # MightyMoose
119 | *.mm.*
120 | AutoTest.Net/
121 |
122 | # Web workbench (sass)
123 | .sass-cache/
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.[Pp]ublish.xml
143 | *.azurePubxml
144 | # TODO: Comment the next line if you want to checkin your web deploy settings
145 | # but database connection strings (with potential passwords) will be unencrypted
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
150 | # checkin your Azure Web App publish settings, but sensitive information contained
151 | # in these scripts will be unencrypted
152 | PublishScripts/
153 |
154 | # NuGet Packages
155 | *.nupkg
156 | # The packages folder can be ignored because of Package Restore
157 | **/packages/*
158 | # except build/, which is used as an MSBuild target.
159 | !**/packages/build/
160 | # Uncomment if necessary however generally it will be regenerated when needed
161 | #!**/packages/repositories.config
162 | # NuGet v3's project.json files produces more ignoreable files
163 | *.nuget.props
164 | *.nuget.targets
165 |
166 | # Microsoft Azure Build Output
167 | csx/
168 | *.build.csdef
169 |
170 | # Microsoft Azure Emulator
171 | ecf/
172 | rcf/
173 |
174 | # Windows Store app package directories and files
175 | AppPackages/
176 | BundleArtifacts/
177 | Package.StoreAssociation.xml
178 | _pkginfo.txt
179 |
180 | # Visual Studio cache files
181 | # files ending in .cache can be ignored
182 | *.[Cc]ache
183 | # but keep track of directories ending in .cache
184 | !*.[Cc]ache/
185 |
186 | # Others
187 | ClientBin/
188 | ~$*
189 | *~
190 | *.dbmdl
191 | *.dbproj.schemaview
192 | *.jfm
193 | *.pfx
194 | *.publishsettings
195 | node_modules/
196 | orleans.codegen.cs
197 |
198 | # Since there are multiple workflows, uncomment next line to ignore bower_components
199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200 | #bower_components/
201 |
202 | # RIA/Silverlight projects
203 | Generated_Code/
204 |
205 | # Backup & report files from converting an old project file
206 | # to a newer Visual Studio version. Backup files are not needed,
207 | # because we have git ;-)
208 | _UpgradeReport_Files/
209 | Backup*/
210 | UpgradeLog*.XML
211 | UpgradeLog*.htm
212 |
213 | # SQL Server files
214 | *.mdf
215 | *.ldf
216 |
217 | # Business Intelligence projects
218 | *.rdl.data
219 | *.bim.layout
220 | *.bim_*.settings
221 |
222 | # Microsoft Fakes
223 | FakesAssemblies/
224 |
225 | # GhostDoc plugin setting file
226 | *.GhostDoc.xml
227 |
228 | # Node.js Tools for Visual Studio
229 | .ntvs_analysis.dat
230 |
231 | # Visual Studio 6 build log
232 | *.plg
233 |
234 | # Visual Studio 6 workspace options file
235 | *.opt
236 |
237 | # Visual Studio LightSwitch build output
238 | **/*.HTMLClient/GeneratedArtifacts
239 | **/*.DesktopClient/GeneratedArtifacts
240 | **/*.DesktopClient/ModelManifest.xml
241 | **/*.Server/GeneratedArtifacts
242 | **/*.Server/ModelManifest.xml
243 | _Pvt_Extensions
244 |
245 | # Paket dependency manager
246 | .paket/paket.exe
247 | paket-files/
248 |
249 | # FAKE - F# Make
250 | .fake/
251 |
252 | # JetBrains Rider
253 | .idea/
254 | *.sln.iml
255 |
256 | # CodeRush
257 | .cr/
258 |
259 | # Python Tools for Visual Studio (PTVS)
260 | __pycache__/
261 | *.pyc
--------------------------------------------------------------------------------
/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.28010.2016
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DirectX 11 Engine VS2017", "DirectX 11 Engine VS2017\DirectX 11 Engine VS2017.vcxproj", "{05F48A78-883F-45F3-8AA0-772438E5D60B}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {05F48A78-883F-45F3-8AA0-772438E5D60B}.Debug|x64.ActiveCfg = Debug|x64
17 | {05F48A78-883F-45F3-8AA0-772438E5D60B}.Debug|x64.Build.0 = Debug|x64
18 | {05F48A78-883F-45F3-8AA0-772438E5D60B}.Debug|x86.ActiveCfg = Debug|Win32
19 | {05F48A78-883F-45F3-8AA0-772438E5D60B}.Debug|x86.Build.0 = Debug|Win32
20 | {05F48A78-883F-45F3-8AA0-772438E5D60B}.Release|x64.ActiveCfg = Release|x64
21 | {05F48A78-883F-45F3-8AA0-772438E5D60B}.Release|x64.Build.0 = Release|x64
22 | {05F48A78-883F-45F3-8AA0-772438E5D60B}.Release|x86.ActiveCfg = Release|Win32
23 | {05F48A78-883F-45F3-8AA0-772438E5D60B}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {8EF11314-E31D-42AB-8B11-B62F109A81FC}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | 15.0
23 | {05F48A78-883F-45F3-8AA0-772438E5D60B}
24 | Win32Proj
25 | DirectX11EngineVS2017
26 | 10.0.17134.0
27 |
28 |
29 |
30 | Application
31 | true
32 | v141
33 | Unicode
34 |
35 |
36 | Application
37 | false
38 | v141
39 | true
40 | Unicode
41 |
42 |
43 | Application
44 | true
45 | v141
46 | Unicode
47 |
48 |
49 | Application
50 | false
51 | v141
52 | true
53 | Unicode
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 | true
75 | $(SolutionDir)DirectX 11 Engine VS2017\Includes;$(IncludePath)
76 | $(SolutionDir)DirectX 11 Engine VS2017\Libs\x86\Debug;$(LibraryPath)
77 |
78 |
79 | true
80 | $(SolutionDir)DirectX 11 Engine VS2017\Includes;$(IncludePath)
81 | $(SolutionDir)DirectX 11 Engine VS2017\Libs\x64\Debug;$(LibraryPath)
82 |
83 |
84 | false
85 | $(SolutionDir)DirectX 11 Engine VS2017\Includes;$(IncludePath)
86 | $(SolutionDir)DirectX 11 Engine VS2017\Libs\x86\Release;$(LibraryPath)
87 |
88 |
89 | false
90 | $(SolutionDir)DirectX 11 Engine VS2017\Includes;$(IncludePath)
91 | $(SolutionDir)DirectX 11 Engine VS2017\Libs\x64\Release;$(LibraryPath)
92 |
93 |
94 |
95 | Level3
96 | Disabled
97 | WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)
98 | true
99 |
100 |
101 | true
102 | Windows
103 |
104 |
105 |
106 |
107 | Level3
108 | Disabled
109 | _DEBUG;_WINDOWS;%(PreprocessorDefinitions)
110 | true
111 |
112 |
113 | true
114 | Windows
115 |
116 |
117 |
118 |
119 | Level3
120 | MaxSpeed
121 | true
122 | true
123 | WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)
124 | true
125 |
126 |
127 | true
128 | true
129 | true
130 | Windows
131 |
132 |
133 |
134 |
135 | Level3
136 | MaxSpeed
137 | true
138 | true
139 | NDEBUG;_WINDOWS;%(PreprocessorDefinitions)
140 | true
141 |
142 |
143 | true
144 | true
145 | true
146 | Windows
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
--------------------------------------------------------------------------------
/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017/Includes/Audio.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: Audio.h
3 | //
4 | // DirectXTK for Audio header
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | // Licensed under the MIT License.
8 | //
9 | // http://go.microsoft.com/fwlink/?LinkId=248929
10 | // http://go.microsoft.com/fwlink/?LinkID=615561
11 | //--------------------------------------------------------------------------------------
12 |
13 | #pragma once
14 |
15 | #include
16 | #include
17 | #include
18 |
19 | #if defined(_XBOX_ONE) && defined(_TITLE)
20 | #include
21 | #pragma comment(lib,"acphal.lib")
22 | #endif
23 |
24 | #ifndef XAUDIO2_HELPER_FUNCTIONS
25 | #define XAUDIO2_HELPER_FUNCTIONS
26 | #endif
27 |
28 | #if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
29 | #include
30 | #include
31 | #include
32 | #include
33 | #pragma comment(lib,"xaudio2.lib")
34 | #else
35 | // Using XAudio 2.7 requires the DirectX SDK
36 | #include
37 | #include
38 | #include
39 | #include
40 | #pragma warning(push)
41 | #pragma warning( disable : 4005 )
42 | #include
43 | #pragma warning(pop)
44 | #pragma comment(lib,"x3daudio.lib")
45 | #pragma comment(lib,"xapofx.lib")
46 | #endif
47 |
48 | #include
49 |
50 | #include
51 | #include
52 | #include
53 | #include
54 | #include
55 |
56 |
57 | namespace DirectX
58 | {
59 | class SoundEffectInstance;
60 |
61 | //----------------------------------------------------------------------------------
62 | struct AudioStatistics
63 | {
64 | size_t playingOneShots; // Number of one-shot sounds currently playing
65 | size_t playingInstances; // Number of sound effect instances currently playing
66 | size_t allocatedInstances; // Number of SoundEffectInstance allocated
67 | size_t allocatedVoices; // Number of XAudio2 voices allocated (standard, 3D, one-shots, and idle one-shots)
68 | size_t allocatedVoices3d; // Number of XAudio2 voices allocated for 3D
69 | size_t allocatedVoicesOneShot; // Number of XAudio2 voices allocated for one-shot sounds
70 | size_t allocatedVoicesIdle; // Number of XAudio2 voices allocated for one-shot sounds but not currently in use
71 | size_t audioBytes; // Total wave data (in bytes) in SoundEffects and in-memory WaveBanks
72 | #if defined(_XBOX_ONE) && defined(_TITLE)
73 | size_t xmaAudioBytes; // Total wave data (in bytes) in SoundEffects and in-memory WaveBanks allocated with ApuAlloc
74 | #endif
75 | };
76 |
77 |
78 | //----------------------------------------------------------------------------------
79 | class IVoiceNotify
80 | {
81 | public:
82 | virtual ~IVoiceNotify() = default;
83 |
84 | IVoiceNotify(const IVoiceNotify&) = delete;
85 | IVoiceNotify& operator=(const IVoiceNotify&) = delete;
86 |
87 | IVoiceNotify(IVoiceNotify&&) = delete;
88 | IVoiceNotify& operator=(IVoiceNotify&&) = delete;
89 |
90 | virtual void __cdecl OnBufferEnd() = 0;
91 | // Notfication that a voice buffer has finished
92 | // Note this is called from XAudio2's worker thread, so it should perform very minimal and thread-safe operations
93 |
94 | virtual void __cdecl OnCriticalError() = 0;
95 | // Notification that the audio engine encountered a critical error
96 |
97 | virtual void __cdecl OnReset() = 0;
98 | // Notification of an audio engine reset
99 |
100 | virtual void __cdecl OnUpdate() = 0;
101 | // Notification of an audio engine per-frame update (opt-in)
102 |
103 | virtual void __cdecl OnDestroyEngine() = 0;
104 | // Notification that the audio engine is being destroyed
105 |
106 | virtual void __cdecl OnTrim() = 0;
107 | // Notification of a request to trim the voice pool
108 |
109 | virtual void __cdecl GatherStatistics(AudioStatistics& stats) const = 0;
110 | // Contribute to statistics request
111 |
112 | protected:
113 | IVoiceNotify() = default;
114 | };
115 |
116 | //----------------------------------------------------------------------------------
117 | enum AUDIO_ENGINE_FLAGS
118 | {
119 | AudioEngine_Default = 0x0,
120 |
121 | AudioEngine_EnvironmentalReverb = 0x1,
122 | AudioEngine_ReverbUseFilters = 0x2,
123 | AudioEngine_UseMasteringLimiter = 0x4,
124 |
125 | AudioEngine_Debug = 0x10000,
126 | AudioEngine_ThrowOnNoAudioHW = 0x20000,
127 | AudioEngine_DisableVoiceReuse = 0x40000,
128 | };
129 |
130 | inline AUDIO_ENGINE_FLAGS operator|(AUDIO_ENGINE_FLAGS a, AUDIO_ENGINE_FLAGS b) { return static_cast( static_cast(a) | static_cast(b) ); }
131 |
132 | enum SOUND_EFFECT_INSTANCE_FLAGS
133 | {
134 | SoundEffectInstance_Default = 0x0,
135 |
136 | SoundEffectInstance_Use3D = 0x1,
137 | SoundEffectInstance_ReverbUseFilters = 0x2,
138 | SoundEffectInstance_NoSetPitch = 0x4,
139 |
140 | SoundEffectInstance_UseRedirectLFE = 0x10000,
141 | };
142 |
143 | inline SOUND_EFFECT_INSTANCE_FLAGS operator|(SOUND_EFFECT_INSTANCE_FLAGS a, SOUND_EFFECT_INSTANCE_FLAGS b) { return static_cast(static_cast(a) | static_cast(b)); }
144 |
145 | enum AUDIO_ENGINE_REVERB
146 | {
147 | Reverb_Off,
148 | Reverb_Default,
149 | Reverb_Generic,
150 | Reverb_Forest,
151 | Reverb_PaddedCell,
152 | Reverb_Room,
153 | Reverb_Bathroom,
154 | Reverb_LivingRoom,
155 | Reverb_StoneRoom,
156 | Reverb_Auditorium,
157 | Reverb_ConcertHall,
158 | Reverb_Cave,
159 | Reverb_Arena,
160 | Reverb_Hangar,
161 | Reverb_CarpetedHallway,
162 | Reverb_Hallway,
163 | Reverb_StoneCorridor,
164 | Reverb_Alley,
165 | Reverb_City,
166 | Reverb_Mountains,
167 | Reverb_Quarry,
168 | Reverb_Plain,
169 | Reverb_ParkingLot,
170 | Reverb_SewerPipe,
171 | Reverb_Underwater,
172 | Reverb_SmallRoom,
173 | Reverb_MediumRoom,
174 | Reverb_LargeRoom,
175 | Reverb_MediumHall,
176 | Reverb_LargeHall,
177 | Reverb_Plate,
178 | Reverb_MAX
179 | };
180 |
181 | enum SoundState
182 | {
183 | STOPPED = 0,
184 | PLAYING,
185 | PAUSED
186 | };
187 |
188 |
189 | //----------------------------------------------------------------------------------
190 | class AudioEngine
191 | {
192 | public:
193 | explicit AudioEngine(
194 | AUDIO_ENGINE_FLAGS flags = AudioEngine_Default, _In_opt_ const WAVEFORMATEX* wfx = nullptr, _In_opt_z_ const wchar_t* deviceId = nullptr,
195 | AUDIO_STREAM_CATEGORY category = AudioCategory_GameEffects) noexcept(false);
196 |
197 | AudioEngine(AudioEngine&& moveFrom) noexcept;
198 | AudioEngine& operator= (AudioEngine&& moveFrom) noexcept;
199 |
200 | AudioEngine(AudioEngine const&) = delete;
201 | AudioEngine& operator= (AudioEngine const&) = delete;
202 |
203 | virtual ~AudioEngine();
204 |
205 | bool __cdecl Update();
206 | // Performs per-frame processing for the audio engine, returns false if in 'silent mode'
207 |
208 | bool __cdecl Reset(_In_opt_ const WAVEFORMATEX* wfx = nullptr, _In_opt_z_ const wchar_t* deviceId = nullptr);
209 | // Reset audio engine from critical error/silent mode using a new device; can also 'migrate' the graph
210 | // Returns true if succesfully reset, false if in 'silent mode' due to no default device
211 | // Note: One shots are lost, all SoundEffectInstances are in the STOPPED state after successful reset
212 |
213 | void __cdecl Suspend();
214 | void __cdecl Resume();
215 | // Suspend/resumes audio processing (i.e. global pause/resume)
216 |
217 | float __cdecl GetMasterVolume() const;
218 | void __cdecl SetMasterVolume(float volume);
219 | // Master volume property for all sounds
220 |
221 | void __cdecl SetReverb(AUDIO_ENGINE_REVERB reverb);
222 | void __cdecl SetReverb(_In_opt_ const XAUDIO2FX_REVERB_PARAMETERS* native);
223 | // Sets environmental reverb for 3D positional audio (if active)
224 |
225 | void __cdecl SetMasteringLimit(int release, int loudness);
226 | // Sets the mastering volume limiter properties (if active)
227 |
228 | AudioStatistics __cdecl GetStatistics() const;
229 | // Gathers audio engine statistics
230 |
231 | WAVEFORMATEXTENSIBLE __cdecl GetOutputFormat() const;
232 | // Returns the format consumed by the mastering voice (which is the same as the device output if defaults are used)
233 |
234 | uint32_t __cdecl GetChannelMask() const;
235 | // Returns the output channel mask
236 |
237 | int __cdecl GetOutputChannels() const;
238 | // Returns the number of output channels
239 |
240 | bool __cdecl IsAudioDevicePresent() const;
241 | // Returns true if the audio graph is operating normally, false if in 'silent mode'
242 |
243 | bool __cdecl IsCriticalError() const;
244 | // Returns true if the audio graph is halted due to a critical error (which also places the engine into 'silent mode')
245 |
246 | // Voice pool management.
247 | void __cdecl SetDefaultSampleRate(int sampleRate);
248 | // Sample rate for voices in the reuse pool (defaults to 44100)
249 |
250 | void __cdecl SetMaxVoicePool(size_t maxOneShots, size_t maxInstances);
251 | // Maximum number of voices to allocate for one-shots and instances
252 | // Note: one-shots over this limit are ignored; too many instance voices throws an exception
253 |
254 | void __cdecl TrimVoicePool();
255 | // Releases any currently unused voices
256 |
257 | // Internal-use functions
258 | void __cdecl AllocateVoice(_In_ const WAVEFORMATEX* wfx, SOUND_EFFECT_INSTANCE_FLAGS flags, bool oneshot, _Outptr_result_maybenull_ IXAudio2SourceVoice** voice);
259 |
260 | void __cdecl DestroyVoice(_In_ IXAudio2SourceVoice* voice);
261 | // Should only be called for instance voices, not one-shots
262 |
263 | void __cdecl RegisterNotify(_In_ IVoiceNotify* notify, bool usesUpdate);
264 | void __cdecl UnregisterNotify(_In_ IVoiceNotify* notify, bool usesOneShots, bool usesUpdate);
265 |
266 | // XAudio2 interface access
267 | IXAudio2* __cdecl GetInterface() const;
268 | IXAudio2MasteringVoice* __cdecl GetMasterVoice() const;
269 | IXAudio2SubmixVoice* __cdecl GetReverbVoice() const;
270 | X3DAUDIO_HANDLE& __cdecl Get3DHandle() const;
271 |
272 | // Static functions
273 | struct RendererDetail
274 | {
275 | std::wstring deviceId;
276 | std::wstring description;
277 | };
278 |
279 | static std::vector __cdecl GetRendererDetails();
280 | // Returns a list of valid audio endpoint devices
281 |
282 | private:
283 | // Private implementation.
284 | class Impl;
285 | std::unique_ptr pImpl;
286 | };
287 |
288 |
289 | //----------------------------------------------------------------------------------
290 | class WaveBank
291 | {
292 | public:
293 | WaveBank(_In_ AudioEngine* engine, _In_z_ const wchar_t* wbFileName);
294 |
295 | WaveBank(WaveBank&& moveFrom) noexcept;
296 | WaveBank& operator= (WaveBank&& moveFrom) noexcept;
297 |
298 | WaveBank(WaveBank const&) = delete;
299 | WaveBank& operator= (WaveBank const&) = delete;
300 |
301 | virtual ~WaveBank();
302 |
303 | void __cdecl Play(int index);
304 | void __cdecl Play(int index, float volume, float pitch, float pan);
305 |
306 | void __cdecl Play(_In_z_ const char* name);
307 | void __cdecl Play(_In_z_ const char* name, float volume, float pitch, float pan);
308 |
309 | std::unique_ptr __cdecl CreateInstance(int index, SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default);
310 | std::unique_ptr __cdecl CreateInstance(_In_z_ const char* name, SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default);
311 |
312 | bool __cdecl IsPrepared() const;
313 | bool __cdecl IsInUse() const;
314 | bool __cdecl IsStreamingBank() const;
315 |
316 | size_t __cdecl GetSampleSizeInBytes(int index) const;
317 | // Returns size of wave audio data
318 |
319 | size_t __cdecl GetSampleDuration(int index) const;
320 | // Returns the duration in samples
321 |
322 | size_t __cdecl GetSampleDurationMS(int index) const;
323 | // Returns the duration in milliseconds
324 |
325 | const WAVEFORMATEX* __cdecl GetFormat(int index, _Out_writes_bytes_(maxsize) WAVEFORMATEX* wfx, size_t maxsize) const;
326 |
327 | int __cdecl Find(_In_z_ const char* name) const;
328 |
329 | #if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/ )
330 | bool __cdecl FillSubmitBuffer(int index, _Out_ XAUDIO2_BUFFER& buffer, _Out_ XAUDIO2_BUFFER_WMA& wmaBuffer) const;
331 | #else
332 | void __cdecl FillSubmitBuffer(int index, _Out_ XAUDIO2_BUFFER& buffer) const;
333 | #endif
334 |
335 | private:
336 | // Private implementation.
337 | class Impl;
338 |
339 | std::unique_ptr pImpl;
340 |
341 | // Private interface
342 | void __cdecl UnregisterInstance(_In_ SoundEffectInstance* instance);
343 |
344 | friend class SoundEffectInstance;
345 | };
346 |
347 |
348 | //----------------------------------------------------------------------------------
349 | class SoundEffect
350 | {
351 | public:
352 | SoundEffect(_In_ AudioEngine* engine, _In_z_ const wchar_t* waveFileName);
353 |
354 | SoundEffect(_In_ AudioEngine* engine, _Inout_ std::unique_ptr& wavData,
355 | _In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio, size_t audioBytes);
356 |
357 | SoundEffect(_In_ AudioEngine* engine, _Inout_ std::unique_ptr& wavData,
358 | _In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio, size_t audioBytes,
359 | uint32_t loopStart, uint32_t loopLength);
360 |
361 | #if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/)
362 |
363 | SoundEffect(_In_ AudioEngine* engine, _Inout_ std::unique_ptr& wavData,
364 | _In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio, size_t audioBytes,
365 | _In_reads_(seekCount) const uint32_t* seekTable, size_t seekCount);
366 |
367 | #endif
368 |
369 | SoundEffect(SoundEffect&& moveFrom) noexcept;
370 | SoundEffect& operator= (SoundEffect&& moveFrom) noexcept;
371 |
372 | SoundEffect(SoundEffect const&) = delete;
373 | SoundEffect& operator= (SoundEffect const&) = delete;
374 |
375 | virtual ~SoundEffect();
376 |
377 | void __cdecl Play();
378 | void __cdecl Play(float volume, float pitch, float pan);
379 |
380 | std::unique_ptr __cdecl CreateInstance(SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default);
381 |
382 | bool __cdecl IsInUse() const;
383 |
384 | size_t __cdecl GetSampleSizeInBytes() const;
385 | // Returns size of wave audio data
386 |
387 | size_t __cdecl GetSampleDuration() const;
388 | // Returns the duration in samples
389 |
390 | size_t __cdecl GetSampleDurationMS() const;
391 | // Returns the duration in milliseconds
392 |
393 | const WAVEFORMATEX* __cdecl GetFormat() const;
394 |
395 | #if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/)
396 | bool __cdecl FillSubmitBuffer(_Out_ XAUDIO2_BUFFER& buffer, _Out_ XAUDIO2_BUFFER_WMA& wmaBuffer) const;
397 | #else
398 | void __cdecl FillSubmitBuffer(_Out_ XAUDIO2_BUFFER& buffer) const;
399 | #endif
400 |
401 | private:
402 | // Private implementation.
403 | class Impl;
404 |
405 | std::unique_ptr pImpl;
406 |
407 | // Private interface
408 | void __cdecl UnregisterInstance(_In_ SoundEffectInstance* instance);
409 |
410 | friend class SoundEffectInstance;
411 | };
412 |
413 |
414 | //----------------------------------------------------------------------------------
415 | struct AudioListener : public X3DAUDIO_LISTENER
416 | {
417 | AudioListener() noexcept
418 | {
419 | memset(this, 0, sizeof(X3DAUDIO_LISTENER));
420 |
421 | OrientFront.z = -1.f;
422 |
423 | OrientTop.y = 1.f;
424 | }
425 |
426 | void XM_CALLCONV SetPosition(FXMVECTOR v)
427 | {
428 | XMStoreFloat3(reinterpret_cast(&Position), v);
429 | }
430 | void __cdecl SetPosition(const XMFLOAT3& pos)
431 | {
432 | Position.x = pos.x;
433 | Position.y = pos.y;
434 | Position.z = pos.z;
435 | }
436 |
437 | void XM_CALLCONV SetVelocity(FXMVECTOR v)
438 | {
439 | XMStoreFloat3(reinterpret_cast(&Velocity), v);
440 | }
441 | void __cdecl SetVelocity(const XMFLOAT3& vel)
442 | {
443 | Velocity.x = vel.x;
444 | Velocity.y = vel.y;
445 | Velocity.z = vel.z;
446 | }
447 |
448 | void XM_CALLCONV SetOrientation(FXMVECTOR forward, FXMVECTOR up)
449 | {
450 | XMStoreFloat3(reinterpret_cast(&OrientFront), forward);
451 | XMStoreFloat3(reinterpret_cast(&OrientTop), up);
452 | }
453 | void __cdecl SetOrientation(const XMFLOAT3& forward, const XMFLOAT3& up)
454 | {
455 | OrientFront.x = forward.x; OrientTop.x = up.x;
456 | OrientFront.y = forward.y; OrientTop.y = up.y;
457 | OrientFront.z = forward.z; OrientTop.z = up.z;
458 | }
459 |
460 | void XM_CALLCONV SetOrientationFromQuaternion(FXMVECTOR quat)
461 | {
462 | XMVECTOR forward = XMVector3Rotate(g_XMIdentityR2, quat);
463 | XMStoreFloat3(reinterpret_cast(&OrientFront), forward);
464 |
465 | XMVECTOR up = XMVector3Rotate(g_XMIdentityR1, quat);
466 | XMStoreFloat3(reinterpret_cast(&OrientTop), up);
467 | }
468 |
469 | void XM_CALLCONV Update(FXMVECTOR newPos, XMVECTOR upDir, float dt)
470 | // Updates velocity and orientation by tracking changes in position over time...
471 | {
472 | if (dt > 0.f)
473 | {
474 | XMVECTOR lastPos = XMLoadFloat3(reinterpret_cast(&Position));
475 |
476 | XMVECTOR vDelta = XMVectorSubtract(newPos, lastPos);
477 | XMVECTOR vt = XMVectorReplicate(dt);
478 | XMVECTOR v = XMVectorDivide(vDelta, vt);
479 | XMStoreFloat3(reinterpret_cast(&Velocity), v);
480 |
481 | vDelta = XMVector3Normalize(vDelta);
482 | XMStoreFloat3(reinterpret_cast(&OrientFront), vDelta);
483 |
484 | v = XMVector3Cross(upDir, vDelta);
485 | v = XMVector3Normalize(v);
486 |
487 | v = XMVector3Cross(vDelta, v);
488 | v = XMVector3Normalize(v);
489 | XMStoreFloat3(reinterpret_cast(&OrientTop), v);
490 |
491 | XMStoreFloat3(reinterpret_cast(&Position), newPos);
492 | }
493 | }
494 | };
495 |
496 |
497 | //----------------------------------------------------------------------------------
498 | struct AudioEmitter : public X3DAUDIO_EMITTER
499 | {
500 | float EmitterAzimuths[XAUDIO2_MAX_AUDIO_CHANNELS];
501 |
502 | AudioEmitter() noexcept :
503 | EmitterAzimuths{}
504 | {
505 | memset(this, 0, sizeof(X3DAUDIO_EMITTER));
506 |
507 | OrientFront.z = -1.f;
508 |
509 | OrientTop.y =
510 | ChannelRadius =
511 | CurveDistanceScaler =
512 | DopplerScaler = 1.f;
513 |
514 | ChannelCount = 1;
515 | pChannelAzimuths = EmitterAzimuths;
516 |
517 | InnerRadiusAngle = X3DAUDIO_PI / 4.0f;
518 | }
519 |
520 | void XM_CALLCONV SetPosition(FXMVECTOR v)
521 | {
522 | XMStoreFloat3(reinterpret_cast(&Position), v);
523 | }
524 | void __cdecl SetPosition(const XMFLOAT3& pos)
525 | {
526 | Position.x = pos.x;
527 | Position.y = pos.y;
528 | Position.z = pos.z;
529 | }
530 |
531 | void XM_CALLCONV SetVelocity(FXMVECTOR v)
532 | {
533 | XMStoreFloat3(reinterpret_cast(&Velocity), v);
534 | }
535 | void __cdecl SetVelocity(const XMFLOAT3& vel)
536 | {
537 | Velocity.x = vel.x;
538 | Velocity.y = vel.y;
539 | Velocity.z = vel.z;
540 | }
541 |
542 | void XM_CALLCONV SetOrientation(FXMVECTOR forward, FXMVECTOR up)
543 | {
544 | XMStoreFloat3(reinterpret_cast(&OrientFront), forward);
545 | XMStoreFloat3(reinterpret_cast(&OrientTop), up);
546 | }
547 | void __cdecl SetOrientation(const XMFLOAT3& forward, const XMFLOAT3& up)
548 | {
549 | OrientFront.x = forward.x; OrientTop.x = up.x;
550 | OrientFront.y = forward.y; OrientTop.y = up.y;
551 | OrientFront.z = forward.z; OrientTop.z = up.z;
552 | }
553 |
554 | void XM_CALLCONV SetOrientationFromQuaternion(FXMVECTOR quat)
555 | {
556 | XMVECTOR forward = XMVector3Rotate(g_XMIdentityR2, quat);
557 | XMStoreFloat3(reinterpret_cast(&OrientFront), forward);
558 |
559 | XMVECTOR up = XMVector3Rotate(g_XMIdentityR1, quat);
560 | XMStoreFloat3(reinterpret_cast(&OrientTop), up);
561 | }
562 |
563 | void XM_CALLCONV Update(FXMVECTOR newPos, XMVECTOR upDir, float dt)
564 | // Updates velocity and orientation by tracking changes in position over time...
565 | {
566 | if (dt > 0.f)
567 | {
568 | XMVECTOR lastPos = XMLoadFloat3(reinterpret_cast(&Position));
569 |
570 | XMVECTOR vDelta = XMVectorSubtract(newPos, lastPos);
571 | XMVECTOR vt = XMVectorReplicate(dt);
572 | XMVECTOR v = XMVectorDivide(vDelta, vt);
573 | XMStoreFloat3(reinterpret_cast(&Velocity), v);
574 |
575 | vDelta = XMVector3Normalize(vDelta);
576 | XMStoreFloat3(reinterpret_cast(&OrientFront), vDelta);
577 |
578 | v = XMVector3Cross(upDir, vDelta);
579 | v = XMVector3Normalize(v);
580 |
581 | v = XMVector3Cross(vDelta, v);
582 | v = XMVector3Normalize(v);
583 | XMStoreFloat3(reinterpret_cast(&OrientTop), v);
584 |
585 | XMStoreFloat3(reinterpret_cast(&Position), newPos);
586 | }
587 | }
588 | };
589 |
590 |
591 | //----------------------------------------------------------------------------------
592 | class SoundEffectInstance
593 | {
594 | public:
595 | SoundEffectInstance(SoundEffectInstance&& moveFrom) noexcept;
596 | SoundEffectInstance& operator= (SoundEffectInstance&& moveFrom) noexcept;
597 |
598 | SoundEffectInstance(SoundEffectInstance const&) = delete;
599 | SoundEffectInstance& operator= (SoundEffectInstance const&) = delete;
600 |
601 | virtual ~SoundEffectInstance();
602 |
603 | void __cdecl Play(bool loop = false);
604 | void __cdecl Stop(bool immediate = true);
605 | void __cdecl Pause();
606 | void __cdecl Resume();
607 |
608 | void __cdecl SetVolume(float volume);
609 | void __cdecl SetPitch(float pitch);
610 | void __cdecl SetPan(float pan);
611 |
612 | void __cdecl Apply3D(const AudioListener& listener, const AudioEmitter& emitter, bool rhcoords = true);
613 |
614 | bool __cdecl IsLooped() const;
615 |
616 | SoundState __cdecl GetState();
617 |
618 | // Notifications.
619 | void __cdecl OnDestroyParent();
620 |
621 | private:
622 | // Private implementation.
623 | class Impl;
624 |
625 | std::unique_ptr pImpl;
626 |
627 | // Private constructors
628 | SoundEffectInstance(_In_ AudioEngine* engine, _In_ SoundEffect* effect, SOUND_EFFECT_INSTANCE_FLAGS flags);
629 | SoundEffectInstance(_In_ AudioEngine* engine, _In_ WaveBank* effect, int index, SOUND_EFFECT_INSTANCE_FLAGS flags);
630 |
631 | friend std::unique_ptr __cdecl SoundEffect::CreateInstance(SOUND_EFFECT_INSTANCE_FLAGS);
632 | friend std::unique_ptr __cdecl WaveBank::CreateInstance(int, SOUND_EFFECT_INSTANCE_FLAGS);
633 | };
634 |
635 |
636 | //----------------------------------------------------------------------------------
637 | class DynamicSoundEffectInstance
638 | {
639 | public:
640 | DynamicSoundEffectInstance(_In_ AudioEngine* engine,
641 | _In_opt_ std::function bufferNeeded,
642 | int sampleRate, int channels, int sampleBits = 16,
643 | SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default);
644 | DynamicSoundEffectInstance(DynamicSoundEffectInstance&& moveFrom) noexcept;
645 | DynamicSoundEffectInstance& operator= (DynamicSoundEffectInstance&& moveFrom) noexcept;
646 |
647 | DynamicSoundEffectInstance(DynamicSoundEffectInstance const&) = delete;
648 | DynamicSoundEffectInstance& operator= (DynamicSoundEffectInstance const&) = delete;
649 |
650 | virtual ~DynamicSoundEffectInstance();
651 |
652 | void __cdecl Play();
653 | void __cdecl Stop(bool immediate = true);
654 | void __cdecl Pause();
655 | void __cdecl Resume();
656 |
657 | void __cdecl SetVolume(float volume);
658 | void __cdecl SetPitch(float pitch);
659 | void __cdecl SetPan(float pan);
660 |
661 | void __cdecl Apply3D(const AudioListener& listener, const AudioEmitter& emitter, bool rhcoords = true);
662 |
663 | void __cdecl SubmitBuffer(_In_reads_bytes_(audioBytes) const uint8_t* pAudioData, size_t audioBytes);
664 | void __cdecl SubmitBuffer(_In_reads_bytes_(audioBytes) const uint8_t* pAudioData, uint32_t offset, size_t audioBytes);
665 |
666 | SoundState __cdecl GetState();
667 |
668 | size_t __cdecl GetSampleDuration(size_t bytes) const;
669 | // Returns duration in samples of a buffer of a given size
670 |
671 | size_t __cdecl GetSampleDurationMS(size_t bytes) const;
672 | // Returns duration in milliseconds of a buffer of a given size
673 |
674 | size_t __cdecl GetSampleSizeInBytes(uint64_t duration) const;
675 | // Returns size of a buffer for a duration given in milliseconds
676 |
677 | int __cdecl GetPendingBufferCount() const;
678 |
679 | const WAVEFORMATEX* __cdecl GetFormat() const;
680 |
681 | private:
682 | // Private implementation.
683 | class Impl;
684 |
685 | std::unique_ptr pImpl;
686 | };
687 | }
688 |
--------------------------------------------------------------------------------
/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017/Includes/CommonStates.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: CommonStates.h
3 | //
4 | // Copyright (c) Microsoft Corporation. All rights reserved.
5 | // Licensed under the MIT License.
6 | //
7 | // http://go.microsoft.com/fwlink/?LinkId=248929
8 | //--------------------------------------------------------------------------------------
9 |
10 | #pragma once
11 |
12 | #if defined(_XBOX_ONE) && defined(_TITLE)
13 | #include
14 | #else
15 | #include
16 | #endif
17 |
18 | #include
19 |
20 |
21 | namespace DirectX
22 | {
23 | class CommonStates
24 | {
25 | public:
26 | explicit CommonStates(_In_ ID3D11Device* device);
27 | CommonStates(CommonStates&& moveFrom) noexcept;
28 | CommonStates& operator= (CommonStates&& moveFrom) noexcept;
29 |
30 | CommonStates(CommonStates const&) = delete;
31 | CommonStates& operator= (CommonStates const&) = delete;
32 |
33 | virtual ~CommonStates();
34 |
35 | // Blend states.
36 | ID3D11BlendState* __cdecl Opaque() const;
37 | ID3D11BlendState* __cdecl AlphaBlend() const;
38 | ID3D11BlendState* __cdecl Additive() const;
39 | ID3D11BlendState* __cdecl NonPremultiplied() const;
40 |
41 | // Depth stencil states.
42 | ID3D11DepthStencilState* __cdecl DepthNone() const;
43 | ID3D11DepthStencilState* __cdecl DepthDefault() const;
44 | ID3D11DepthStencilState* __cdecl DepthRead() const;
45 |
46 | // Rasterizer states.
47 | ID3D11RasterizerState* __cdecl CullNone() const;
48 | ID3D11RasterizerState* __cdecl CullClockwise() const;
49 | ID3D11RasterizerState* __cdecl CullCounterClockwise() const;
50 | ID3D11RasterizerState* __cdecl Wireframe() const;
51 |
52 | // Sampler states.
53 | ID3D11SamplerState* __cdecl PointWrap() const;
54 | ID3D11SamplerState* __cdecl PointClamp() const;
55 | ID3D11SamplerState* __cdecl LinearWrap() const;
56 | ID3D11SamplerState* __cdecl LinearClamp() const;
57 | ID3D11SamplerState* __cdecl AnisotropicWrap() const;
58 | ID3D11SamplerState* __cdecl AnisotropicClamp() const;
59 |
60 | private:
61 | // Private implementation.
62 | class Impl;
63 |
64 | std::shared_ptr pImpl;
65 | };
66 | }
67 |
--------------------------------------------------------------------------------
/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017/Includes/DDSTextureLoader.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: DDSTextureLoader.h
3 | //
4 | // Functions for loading a DDS texture and creating a Direct3D runtime resource for it
5 | //
6 | // Note these functions are useful as a light-weight runtime loader for DDS files. For
7 | // a full-featured DDS file reader, writer, and texture processing pipeline see
8 | // the 'Texconv' sample and the 'DirectXTex' library.
9 | //
10 | // Copyright (c) Microsoft Corporation. All rights reserved.
11 | // Licensed under the MIT License.
12 | //
13 | // http://go.microsoft.com/fwlink/?LinkId=248926
14 | // http://go.microsoft.com/fwlink/?LinkId=248929
15 | //--------------------------------------------------------------------------------------
16 |
17 | #pragma once
18 |
19 | #if defined(_XBOX_ONE) && defined(_TITLE)
20 | #include
21 | #else
22 | #include
23 | #endif
24 |
25 | #include
26 |
27 |
28 | namespace DirectX
29 | {
30 | enum DDS_ALPHA_MODE
31 | {
32 | DDS_ALPHA_MODE_UNKNOWN = 0,
33 | DDS_ALPHA_MODE_STRAIGHT = 1,
34 | DDS_ALPHA_MODE_PREMULTIPLIED = 2,
35 | DDS_ALPHA_MODE_OPAQUE = 3,
36 | DDS_ALPHA_MODE_CUSTOM = 4,
37 | };
38 |
39 | // Standard version
40 | HRESULT __cdecl CreateDDSTextureFromMemory(
41 | _In_ ID3D11Device* d3dDevice,
42 | _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
43 | _In_ size_t ddsDataSize,
44 | _Outptr_opt_ ID3D11Resource** texture,
45 | _Outptr_opt_ ID3D11ShaderResourceView** textureView,
46 | _In_ size_t maxsize = 0,
47 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
48 |
49 | HRESULT __cdecl CreateDDSTextureFromFile(
50 | _In_ ID3D11Device* d3dDevice,
51 | _In_z_ const wchar_t* szFileName,
52 | _Outptr_opt_ ID3D11Resource** texture,
53 | _Outptr_opt_ ID3D11ShaderResourceView** textureView,
54 | _In_ size_t maxsize = 0,
55 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
56 |
57 | // Standard version with optional auto-gen mipmap support
58 | HRESULT __cdecl CreateDDSTextureFromMemory(
59 | #if defined(_XBOX_ONE) && defined(_TITLE)
60 | _In_ ID3D11DeviceX* d3dDevice,
61 | _In_opt_ ID3D11DeviceContextX* d3dContext,
62 | #else
63 | _In_ ID3D11Device* d3dDevice,
64 | _In_opt_ ID3D11DeviceContext* d3dContext,
65 | #endif
66 | _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
67 | _In_ size_t ddsDataSize,
68 | _Outptr_opt_ ID3D11Resource** texture,
69 | _Outptr_opt_ ID3D11ShaderResourceView** textureView,
70 | _In_ size_t maxsize = 0,
71 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
72 |
73 | HRESULT __cdecl CreateDDSTextureFromFile(
74 | #if defined(_XBOX_ONE) && defined(_TITLE)
75 | _In_ ID3D11DeviceX* d3dDevice,
76 | _In_opt_ ID3D11DeviceContextX* d3dContext,
77 | #else
78 | _In_ ID3D11Device* d3dDevice,
79 | _In_opt_ ID3D11DeviceContext* d3dContext,
80 | #endif
81 | _In_z_ const wchar_t* szFileName,
82 | _Outptr_opt_ ID3D11Resource** texture,
83 | _Outptr_opt_ ID3D11ShaderResourceView** textureView,
84 | _In_ size_t maxsize = 0,
85 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
86 |
87 | // Extended version
88 | HRESULT __cdecl CreateDDSTextureFromMemoryEx(
89 | _In_ ID3D11Device* d3dDevice,
90 | _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
91 | _In_ size_t ddsDataSize,
92 | _In_ size_t maxsize,
93 | _In_ D3D11_USAGE usage,
94 | _In_ unsigned int bindFlags,
95 | _In_ unsigned int cpuAccessFlags,
96 | _In_ unsigned int miscFlags,
97 | _In_ bool forceSRGB,
98 | _Outptr_opt_ ID3D11Resource** texture,
99 | _Outptr_opt_ ID3D11ShaderResourceView** textureView,
100 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
101 |
102 | HRESULT __cdecl CreateDDSTextureFromFileEx(
103 | _In_ ID3D11Device* d3dDevice,
104 | _In_z_ const wchar_t* szFileName,
105 | _In_ size_t maxsize,
106 | _In_ D3D11_USAGE usage,
107 | _In_ unsigned int bindFlags,
108 | _In_ unsigned int cpuAccessFlags,
109 | _In_ unsigned int miscFlags,
110 | _In_ bool forceSRGB,
111 | _Outptr_opt_ ID3D11Resource** texture,
112 | _Outptr_opt_ ID3D11ShaderResourceView** textureView,
113 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
114 |
115 | // Extended version with optional auto-gen mipmap support
116 | HRESULT __cdecl CreateDDSTextureFromMemoryEx(
117 | #if defined(_XBOX_ONE) && defined(_TITLE)
118 | _In_ ID3D11DeviceX* d3dDevice,
119 | _In_opt_ ID3D11DeviceContextX* d3dContext,
120 | #else
121 | _In_ ID3D11Device* d3dDevice,
122 | _In_opt_ ID3D11DeviceContext* d3dContext,
123 | #endif
124 | _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
125 | _In_ size_t ddsDataSize,
126 | _In_ size_t maxsize,
127 | _In_ D3D11_USAGE usage,
128 | _In_ unsigned int bindFlags,
129 | _In_ unsigned int cpuAccessFlags,
130 | _In_ unsigned int miscFlags,
131 | _In_ bool forceSRGB,
132 | _Outptr_opt_ ID3D11Resource** texture,
133 | _Outptr_opt_ ID3D11ShaderResourceView** textureView,
134 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
135 |
136 | HRESULT __cdecl CreateDDSTextureFromFileEx(
137 | #if defined(_XBOX_ONE) && defined(_TITLE)
138 | _In_ ID3D11DeviceX* d3dDevice,
139 | _In_opt_ ID3D11DeviceContextX* d3dContext,
140 | #else
141 | _In_ ID3D11Device* d3dDevice,
142 | _In_opt_ ID3D11DeviceContext* d3dContext,
143 | #endif
144 | _In_z_ const wchar_t* szFileName,
145 | _In_ size_t maxsize,
146 | _In_ D3D11_USAGE usage,
147 | _In_ unsigned int bindFlags,
148 | _In_ unsigned int cpuAccessFlags,
149 | _In_ unsigned int miscFlags,
150 | _In_ bool forceSRGB,
151 | _Outptr_opt_ ID3D11Resource** texture,
152 | _Outptr_opt_ ID3D11ShaderResourceView** textureView,
153 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
154 | }
155 |
--------------------------------------------------------------------------------
/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017/Includes/DirectXHelpers.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: DirectXHelpers.h
3 | //
4 | // Copyright (c) Microsoft Corporation. All rights reserved.
5 | // Licensed under the MIT License.
6 | //
7 | // http://go.microsoft.com/fwlink/?LinkId=248929
8 | //--------------------------------------------------------------------------------------
9 |
10 | #pragma once
11 |
12 | #if defined(_XBOX_ONE) && defined(_TITLE)
13 | #include
14 | #else
15 | #include
16 | #endif
17 |
18 | #if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
19 | #if !defined(_XBOX_ONE) || !defined(_TITLE)
20 | #pragma comment(lib,"dxguid.lib")
21 | #endif
22 | #endif
23 |
24 | #ifndef IID_GRAPHICS_PPV_ARGS
25 | #define IID_GRAPHICS_PPV_ARGS(x) IID_PPV_ARGS(x)
26 | #endif
27 |
28 | #include
29 | #include
30 |
31 | //
32 | // The core Direct3D headers provide the following helper C++ classes
33 | // CD3D11_RECT
34 | // CD3D11_BOX
35 | // CD3D11_DEPTH_STENCIL_DESC
36 | // CD3D11_BLEND_DESC, CD3D11_BLEND_DESC1
37 | // CD3D11_RASTERIZER_DESC, CD3D11_RASTERIZER_DESC1
38 | // CD3D11_BUFFER_DESC
39 | // CD3D11_TEXTURE1D_DESC
40 | // CD3D11_TEXTURE2D_DESC
41 | // CD3D11_TEXTURE3D_DESC
42 | // CD3D11_SHADER_RESOURCE_VIEW_DESC
43 | // CD3D11_RENDER_TARGET_VIEW_DESC
44 | // CD3D11_VIEWPORT
45 | // CD3D11_DEPTH_STENCIL_VIEW_DESC
46 | // CD3D11_UNORDERED_ACCESS_VIEW_DESC
47 | // CD3D11_SAMPLER_DESC
48 | // CD3D11_QUERY_DESC
49 | // CD3D11_COUNTER_DESC
50 | //
51 |
52 |
53 | namespace DirectX
54 | {
55 | // simliar to std::lock_guard for exception-safe Direct3D resource locking
56 | class MapGuard : public D3D11_MAPPED_SUBRESOURCE
57 | {
58 | public:
59 | MapGuard(_In_ ID3D11DeviceContext* context,
60 | _In_ ID3D11Resource *resource,
61 | _In_ UINT subresource,
62 | _In_ D3D11_MAP mapType,
63 | _In_ UINT mapFlags)
64 | : mContext(context), mResource(resource), mSubresource(subresource)
65 | {
66 | HRESULT hr = mContext->Map(resource, subresource, mapType, mapFlags, this);
67 | if (FAILED(hr))
68 | {
69 | throw std::exception();
70 | }
71 | }
72 |
73 | ~MapGuard()
74 | {
75 | mContext->Unmap(mResource, mSubresource);
76 | }
77 |
78 | uint8_t* get() const
79 | {
80 | return static_cast(pData);
81 | }
82 | uint8_t* get(size_t slice) const
83 | {
84 | return static_cast(pData) + (slice * DepthPitch);
85 | }
86 |
87 | uint8_t* scanline(size_t row) const
88 | {
89 | return static_cast(pData) + (row * RowPitch);
90 | }
91 | uint8_t* scanline(size_t slice, size_t row) const
92 | {
93 | return static_cast(pData) + (slice * DepthPitch) + (row * RowPitch);
94 | }
95 |
96 | private:
97 | ID3D11DeviceContext* mContext;
98 | ID3D11Resource* mResource;
99 | UINT mSubresource;
100 |
101 | MapGuard(MapGuard const&);
102 | MapGuard& operator= (MapGuard const&);
103 | };
104 |
105 |
106 | // Helper sets a D3D resource name string (used by PIX and debug layer leak reporting).
107 | template
108 | inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_z_ const char (&name)[TNameLength])
109 | {
110 | #if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
111 | #if defined(_XBOX_ONE) && defined(_TITLE)
112 | wchar_t wname[MAX_PATH];
113 | int result = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, TNameLength, wname, MAX_PATH);
114 | if (result > 0)
115 | {
116 | resource->SetName(wname);
117 | }
118 | #else
119 | resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name);
120 | #endif
121 | #else
122 | UNREFERENCED_PARAMETER(resource);
123 | UNREFERENCED_PARAMETER(name);
124 | #endif
125 | }
126 |
127 | template
128 | inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_z_ const wchar_t (&name)[TNameLength])
129 | {
130 | #if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
131 | #if defined(_XBOX_ONE) && defined(_TITLE)
132 | resource->SetName( name );
133 | #else
134 | char aname[MAX_PATH];
135 | int result = WideCharToMultiByte(CP_ACP, 0, name, TNameLength, aname, MAX_PATH, nullptr, nullptr);
136 | if (result > 0)
137 | {
138 | resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, aname);
139 | }
140 | #endif
141 | #else
142 | UNREFERENCED_PARAMETER(resource);
143 | UNREFERENCED_PARAMETER(name);
144 | #endif
145 | }
146 |
147 | // Helpers for aligning values by a power of 2
148 | template
149 | inline T AlignDown(T size, size_t alignment)
150 | {
151 | if (alignment > 0)
152 | {
153 | assert(((alignment - 1) & alignment) == 0);
154 | T mask = static_cast(alignment - 1);
155 | return size & ~mask;
156 | }
157 | return size;
158 | }
159 |
160 | template
161 | inline T AlignUp(T size, size_t alignment)
162 | {
163 | if (alignment > 0)
164 | {
165 | assert(((alignment - 1) & alignment) == 0);
166 | T mask = static_cast(alignment - 1);
167 | return (size + mask) & ~mask;
168 | }
169 | return size;
170 | }
171 | }
172 |
--------------------------------------------------------------------------------
/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017/Includes/Effects.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: Effects.h
3 | //
4 | // Copyright (c) Microsoft Corporation. All rights reserved.
5 | // Licensed under the MIT License.
6 | //
7 | // http://go.microsoft.com/fwlink/?LinkId=248929
8 | //--------------------------------------------------------------------------------------
9 |
10 | #pragma once
11 |
12 | #if defined(_XBOX_ONE) && defined(_TITLE)
13 | #include
14 | #else
15 | #include
16 | #endif
17 |
18 | #include
19 | #include
20 |
21 |
22 | namespace DirectX
23 | {
24 | //----------------------------------------------------------------------------------
25 | // Abstract interface representing any effect which can be applied onto a D3D device context.
26 | class IEffect
27 | {
28 | public:
29 | virtual ~IEffect() = default;
30 |
31 | IEffect(const IEffect&) = delete;
32 | IEffect& operator=(const IEffect&) = delete;
33 |
34 | IEffect(IEffect&&) = delete;
35 | IEffect& operator=(IEffect&&) = delete;
36 |
37 | virtual void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) = 0;
38 |
39 | virtual void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) = 0;
40 |
41 | protected:
42 | IEffect() = default;
43 | };
44 |
45 |
46 | // Abstract interface for effects with world, view, and projection matrices.
47 | class IEffectMatrices
48 | {
49 | public:
50 | virtual ~IEffectMatrices() = default;
51 |
52 | IEffectMatrices(const IEffectMatrices&) = delete;
53 | IEffectMatrices& operator=(const IEffectMatrices&) = delete;
54 |
55 | IEffectMatrices(IEffectMatrices&&) = delete;
56 | IEffectMatrices& operator=(IEffectMatrices&&) = delete;
57 |
58 | virtual void XM_CALLCONV SetWorld(FXMMATRIX value) = 0;
59 | virtual void XM_CALLCONV SetView(FXMMATRIX value) = 0;
60 | virtual void XM_CALLCONV SetProjection(FXMMATRIX value) = 0;
61 | virtual void XM_CALLCONV SetMatrices(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection);
62 |
63 | protected:
64 | IEffectMatrices() = default;
65 | };
66 |
67 |
68 | // Abstract interface for effects which support directional lighting.
69 | class IEffectLights
70 | {
71 | public:
72 | virtual ~IEffectLights() = default;
73 |
74 | IEffectLights(const IEffectLights&) = delete;
75 | IEffectLights& operator=(const IEffectLights&) = delete;
76 |
77 | IEffectLights(IEffectLights&&) = delete;
78 | IEffectLights& operator=(IEffectLights&&) = delete;
79 |
80 | virtual void __cdecl SetLightingEnabled(bool value) = 0;
81 | virtual void __cdecl SetPerPixelLighting(bool value) = 0;
82 | virtual void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) = 0;
83 |
84 | virtual void __cdecl SetLightEnabled(int whichLight, bool value) = 0;
85 | virtual void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) = 0;
86 | virtual void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) = 0;
87 | virtual void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) = 0;
88 |
89 | virtual void __cdecl EnableDefaultLighting() = 0;
90 |
91 | static const int MaxDirectionalLights = 3;
92 |
93 | protected:
94 | IEffectLights() = default;
95 | };
96 |
97 |
98 | // Abstract interface for effects which support fog.
99 | class IEffectFog
100 | {
101 | public:
102 | virtual ~IEffectFog() = default;
103 |
104 | IEffectFog(const IEffectFog&) = delete;
105 | IEffectFog& operator=(const IEffectFog&) = delete;
106 |
107 | IEffectFog(IEffectFog&&) = delete;
108 | IEffectFog& operator=(IEffectFog&&) = delete;
109 |
110 | virtual void __cdecl SetFogEnabled(bool value) = 0;
111 | virtual void __cdecl SetFogStart(float value) = 0;
112 | virtual void __cdecl SetFogEnd(float value) = 0;
113 | virtual void XM_CALLCONV SetFogColor(FXMVECTOR value) = 0;
114 |
115 | protected:
116 | IEffectFog() = default;
117 | };
118 |
119 |
120 | // Abstract interface for effects which support skinning
121 | class IEffectSkinning
122 | {
123 | public:
124 | virtual ~IEffectSkinning() = default;
125 |
126 | IEffectSkinning(const IEffectSkinning&) = delete;
127 | IEffectSkinning& operator=(const IEffectSkinning&) = delete;
128 |
129 | IEffectSkinning(IEffectSkinning&&) = delete;
130 | IEffectSkinning& operator=(IEffectSkinning&&) = delete;
131 |
132 | virtual void __cdecl SetWeightsPerVertex(int value) = 0;
133 | virtual void __cdecl SetBoneTransforms(_In_reads_(count) XMMATRIX const* value, size_t count) = 0;
134 | virtual void __cdecl ResetBoneTransforms() = 0;
135 |
136 | static const int MaxBones = 72;
137 |
138 | protected:
139 | IEffectSkinning() = default;
140 | };
141 |
142 | //----------------------------------------------------------------------------------
143 | // Built-in shader supports optional texture mapping, vertex coloring, directional lighting, and fog.
144 | class BasicEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog
145 | {
146 | public:
147 | explicit BasicEffect(_In_ ID3D11Device* device);
148 | BasicEffect(BasicEffect&& moveFrom) noexcept;
149 | BasicEffect& operator= (BasicEffect&& moveFrom) noexcept;
150 |
151 | BasicEffect(BasicEffect const&) = delete;
152 | BasicEffect& operator= (BasicEffect const&) = delete;
153 |
154 | virtual ~BasicEffect() override;
155 |
156 | // IEffect methods.
157 | void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override;
158 |
159 | void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override;
160 |
161 | // Camera settings.
162 | void XM_CALLCONV SetWorld(FXMMATRIX value) override;
163 | void XM_CALLCONV SetView(FXMMATRIX value) override;
164 | void XM_CALLCONV SetProjection(FXMMATRIX value) override;
165 | void XM_CALLCONV SetMatrices(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection) override;
166 |
167 | // Material settings.
168 | void XM_CALLCONV SetDiffuseColor(FXMVECTOR value);
169 | void XM_CALLCONV SetEmissiveColor(FXMVECTOR value);
170 | void XM_CALLCONV SetSpecularColor(FXMVECTOR value);
171 | void __cdecl SetSpecularPower(float value);
172 | void __cdecl DisableSpecular();
173 | void __cdecl SetAlpha(float value);
174 | void XM_CALLCONV SetColorAndAlpha(FXMVECTOR value);
175 |
176 | // Light settings.
177 | void __cdecl SetLightingEnabled(bool value) override;
178 | void __cdecl SetPerPixelLighting(bool value) override;
179 | void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override;
180 |
181 | void __cdecl SetLightEnabled(int whichLight, bool value) override;
182 | void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override;
183 | void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override;
184 | void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override;
185 |
186 | void __cdecl EnableDefaultLighting() override;
187 |
188 | // Fog settings.
189 | void __cdecl SetFogEnabled(bool value) override;
190 | void __cdecl SetFogStart(float value) override;
191 | void __cdecl SetFogEnd(float value) override;
192 | void XM_CALLCONV SetFogColor(FXMVECTOR value) override;
193 |
194 | // Vertex color setting.
195 | void __cdecl SetVertexColorEnabled(bool value);
196 |
197 | // Texture setting.
198 | void __cdecl SetTextureEnabled(bool value);
199 | void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
200 |
201 | // Normal compression settings.
202 | void __cdecl SetBiasedVertexNormals(bool value);
203 |
204 | private:
205 | // Private implementation.
206 | class Impl;
207 |
208 | std::unique_ptr pImpl;
209 | };
210 |
211 |
212 |
213 | // Built-in shader supports per-pixel alpha testing.
214 | class AlphaTestEffect : public IEffect, public IEffectMatrices, public IEffectFog
215 | {
216 | public:
217 | explicit AlphaTestEffect(_In_ ID3D11Device* device);
218 | AlphaTestEffect(AlphaTestEffect&& moveFrom) noexcept;
219 | AlphaTestEffect& operator= (AlphaTestEffect&& moveFrom) noexcept;
220 |
221 | AlphaTestEffect(AlphaTestEffect const&) = delete;
222 | AlphaTestEffect& operator= (AlphaTestEffect const&) = delete;
223 |
224 | virtual ~AlphaTestEffect() override;
225 |
226 | // IEffect methods.
227 | void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override;
228 |
229 | void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override;
230 |
231 | // Camera settings.
232 | void XM_CALLCONV SetWorld(FXMMATRIX value) override;
233 | void XM_CALLCONV SetView(FXMMATRIX value) override;
234 | void XM_CALLCONV SetProjection(FXMMATRIX value) override;
235 | void XM_CALLCONV SetMatrices(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection) override;
236 |
237 | // Material settings.
238 | void XM_CALLCONV SetDiffuseColor(FXMVECTOR value);
239 | void __cdecl SetAlpha(float value);
240 | void XM_CALLCONV SetColorAndAlpha(FXMVECTOR value);
241 |
242 | // Fog settings.
243 | void __cdecl SetFogEnabled(bool value) override;
244 | void __cdecl SetFogStart(float value) override;
245 | void __cdecl SetFogEnd(float value) override;
246 | void XM_CALLCONV SetFogColor(FXMVECTOR value) override;
247 |
248 | // Vertex color setting.
249 | void __cdecl SetVertexColorEnabled(bool value);
250 |
251 | // Texture setting.
252 | void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
253 |
254 | // Alpha test settings.
255 | void __cdecl SetAlphaFunction(D3D11_COMPARISON_FUNC value);
256 | void __cdecl SetReferenceAlpha(int value);
257 |
258 | private:
259 | // Private implementation.
260 | class Impl;
261 |
262 | std::unique_ptr pImpl;
263 | };
264 |
265 |
266 |
267 | // Built-in shader supports two layer multitexturing (eg. for lightmaps or detail textures).
268 | class DualTextureEffect : public IEffect, public IEffectMatrices, public IEffectFog
269 | {
270 | public:
271 | explicit DualTextureEffect(_In_ ID3D11Device* device);
272 | DualTextureEffect(DualTextureEffect&& moveFrom) noexcept;
273 | DualTextureEffect& operator= (DualTextureEffect&& moveFrom) noexcept;
274 |
275 | DualTextureEffect(DualTextureEffect const&) = delete;
276 | DualTextureEffect& operator= (DualTextureEffect const&) = delete;
277 |
278 | virtual ~DualTextureEffect() override;
279 |
280 | // IEffect methods.
281 | void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override;
282 |
283 | void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override;
284 |
285 | // Camera settings.
286 | void XM_CALLCONV SetWorld(FXMMATRIX value) override;
287 | void XM_CALLCONV SetView(FXMMATRIX value) override;
288 | void XM_CALLCONV SetProjection(FXMMATRIX value) override;
289 | void XM_CALLCONV SetMatrices(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection) override;
290 |
291 | // Material settings.
292 | void XM_CALLCONV SetDiffuseColor(FXMVECTOR value);
293 | void __cdecl SetAlpha(float value);
294 | void XM_CALLCONV SetColorAndAlpha(FXMVECTOR value);
295 |
296 | // Fog settings.
297 | void __cdecl SetFogEnabled(bool value) override;
298 | void __cdecl SetFogStart(float value) override;
299 | void __cdecl SetFogEnd(float value) override;
300 | void XM_CALLCONV SetFogColor(FXMVECTOR value) override;
301 |
302 | // Vertex color setting.
303 | void __cdecl SetVertexColorEnabled(bool value);
304 |
305 | // Texture settings.
306 | void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
307 | void __cdecl SetTexture2(_In_opt_ ID3D11ShaderResourceView* value);
308 |
309 | private:
310 | // Private implementation.
311 | class Impl;
312 |
313 | std::unique_ptr pImpl;
314 | };
315 |
316 |
317 |
318 | // Built-in shader supports cubic environment mapping.
319 | class EnvironmentMapEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog
320 | {
321 | public:
322 | explicit EnvironmentMapEffect(_In_ ID3D11Device* device);
323 | EnvironmentMapEffect(EnvironmentMapEffect&& moveFrom) noexcept;
324 | EnvironmentMapEffect& operator= (EnvironmentMapEffect&& moveFrom) noexcept;
325 |
326 | EnvironmentMapEffect(EnvironmentMapEffect const&) = delete;
327 | EnvironmentMapEffect& operator= (EnvironmentMapEffect const&) = delete;
328 |
329 | virtual ~EnvironmentMapEffect() override;
330 |
331 | // IEffect methods.
332 | void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override;
333 |
334 | void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override;
335 |
336 | // Camera settings.
337 | void XM_CALLCONV SetWorld(FXMMATRIX value) override;
338 | void XM_CALLCONV SetView(FXMMATRIX value) override;
339 | void XM_CALLCONV SetProjection(FXMMATRIX value) override;
340 | void XM_CALLCONV SetMatrices(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection) override;
341 |
342 | // Material settings.
343 | void XM_CALLCONV SetDiffuseColor(FXMVECTOR value);
344 | void XM_CALLCONV SetEmissiveColor(FXMVECTOR value);
345 | void __cdecl SetAlpha(float value);
346 | void XM_CALLCONV SetColorAndAlpha(FXMVECTOR value);
347 |
348 | // Light settings.
349 | void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override;
350 |
351 | void __cdecl SetPerPixelLighting(bool value) override;
352 | void __cdecl SetLightEnabled(int whichLight, bool value) override;
353 | void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override;
354 | void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override;
355 |
356 | void __cdecl EnableDefaultLighting() override;
357 |
358 | // Fog settings.
359 | void __cdecl SetFogEnabled(bool value) override;
360 | void __cdecl SetFogStart(float value) override;
361 | void __cdecl SetFogEnd(float value) override;
362 | void XM_CALLCONV SetFogColor(FXMVECTOR value) override;
363 |
364 | // Texture setting.
365 | void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
366 |
367 | // Environment map settings.
368 | void __cdecl SetEnvironmentMap(_In_opt_ ID3D11ShaderResourceView* value);
369 | void __cdecl SetEnvironmentMapAmount(float value);
370 | void XM_CALLCONV SetEnvironmentMapSpecular(FXMVECTOR value);
371 | void __cdecl SetFresnelFactor(float value);
372 |
373 | // Normal compression settings.
374 | void __cdecl SetBiasedVertexNormals(bool value);
375 |
376 | private:
377 | // Private implementation.
378 | class Impl;
379 |
380 | std::unique_ptr pImpl;
381 |
382 | // Unsupported interface methods.
383 | void __cdecl SetLightingEnabled(bool value) override;
384 | void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override;
385 | };
386 |
387 |
388 |
389 | // Built-in shader supports skinned animation.
390 | class SkinnedEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog, public IEffectSkinning
391 | {
392 | public:
393 | explicit SkinnedEffect(_In_ ID3D11Device* device);
394 | SkinnedEffect(SkinnedEffect&& moveFrom) noexcept;
395 | SkinnedEffect& operator= (SkinnedEffect&& moveFrom) noexcept;
396 |
397 | SkinnedEffect(SkinnedEffect const&) = delete;
398 | SkinnedEffect& operator= (SkinnedEffect const&) = delete;
399 |
400 | virtual ~SkinnedEffect() override;
401 |
402 | // IEffect methods.
403 | void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override;
404 |
405 | void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override;
406 |
407 | // Camera settings.
408 | void XM_CALLCONV SetWorld(FXMMATRIX value) override;
409 | void XM_CALLCONV SetView(FXMMATRIX value) override;
410 | void XM_CALLCONV SetProjection(FXMMATRIX value) override;
411 | void XM_CALLCONV SetMatrices(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection) override;
412 |
413 | // Material settings.
414 | void XM_CALLCONV SetDiffuseColor(FXMVECTOR value);
415 | void XM_CALLCONV SetEmissiveColor(FXMVECTOR value);
416 | void XM_CALLCONV SetSpecularColor(FXMVECTOR value);
417 | void __cdecl SetSpecularPower(float value);
418 | void __cdecl DisableSpecular();
419 | void __cdecl SetAlpha(float value);
420 | void XM_CALLCONV SetColorAndAlpha(FXMVECTOR value);
421 |
422 | // Light settings.
423 | void __cdecl SetPerPixelLighting(bool value) override;
424 | void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override;
425 |
426 | void __cdecl SetLightEnabled(int whichLight, bool value) override;
427 | void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override;
428 | void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override;
429 | void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override;
430 |
431 | void __cdecl EnableDefaultLighting() override;
432 |
433 | // Fog settings.
434 | void __cdecl SetFogEnabled(bool value) override;
435 | void __cdecl SetFogStart(float value) override;
436 | void __cdecl SetFogEnd(float value) override;
437 | void XM_CALLCONV SetFogColor(FXMVECTOR value) override;
438 |
439 | // Texture setting.
440 | void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
441 |
442 | // Animation settings.
443 | void __cdecl SetWeightsPerVertex(int value) override;
444 | void __cdecl SetBoneTransforms(_In_reads_(count) XMMATRIX const* value, size_t count) override;
445 | void __cdecl ResetBoneTransforms() override;
446 |
447 | // Normal compression settings.
448 | void __cdecl SetBiasedVertexNormals(bool value);
449 |
450 | private:
451 | // Private implementation.
452 | class Impl;
453 |
454 | std::unique_ptr pImpl;
455 |
456 | // Unsupported interface method.
457 | void __cdecl SetLightingEnabled(bool value) override;
458 | };
459 |
460 | //----------------------------------------------------------------------------------
461 | // Built-in effect for Visual Studio Shader Designer (DGSL) shaders
462 | class DGSLEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectSkinning
463 | {
464 | public:
465 | explicit DGSLEffect(_In_ ID3D11Device* device, _In_opt_ ID3D11PixelShader* pixelShader = nullptr,
466 | _In_ bool enableSkinning = false);
467 | DGSLEffect(DGSLEffect&& moveFrom) noexcept;
468 | DGSLEffect& operator= (DGSLEffect&& moveFrom) noexcept;
469 |
470 | DGSLEffect(DGSLEffect const&) = delete;
471 | DGSLEffect& operator= (DGSLEffect const&) = delete;
472 |
473 | virtual ~DGSLEffect() override;
474 |
475 | // IEffect methods.
476 | void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override;
477 |
478 | void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override;
479 |
480 | // Camera settings.
481 | void XM_CALLCONV SetWorld(FXMMATRIX value) override;
482 | void XM_CALLCONV SetView(FXMMATRIX value) override;
483 | void XM_CALLCONV SetProjection(FXMMATRIX value) override;
484 | void XM_CALLCONV SetMatrices(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection) override;
485 |
486 | // Material settings.
487 | void XM_CALLCONV SetAmbientColor(FXMVECTOR value);
488 | void XM_CALLCONV SetDiffuseColor(FXMVECTOR value);
489 | void XM_CALLCONV SetEmissiveColor(FXMVECTOR value);
490 | void XM_CALLCONV SetSpecularColor(FXMVECTOR value);
491 | void __cdecl SetSpecularPower(float value);
492 | void __cdecl DisableSpecular();
493 | void __cdecl SetAlpha(float value);
494 | void XM_CALLCONV SetColorAndAlpha(FXMVECTOR value);
495 |
496 | // Additional settings.
497 | void XM_CALLCONV SetUVTransform(FXMMATRIX value);
498 | void __cdecl SetViewport(float width, float height);
499 | void __cdecl SetTime(float time);
500 | void __cdecl SetAlphaDiscardEnable(bool value);
501 |
502 | // Light settings.
503 | void __cdecl SetLightingEnabled(bool value) override;
504 | void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override;
505 |
506 | void __cdecl SetLightEnabled(int whichLight, bool value) override;
507 | void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override;
508 | void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override;
509 | void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override;
510 |
511 | void __cdecl EnableDefaultLighting() override;
512 |
513 | static const int MaxDirectionalLights = 4;
514 |
515 | // Vertex color setting.
516 | void __cdecl SetVertexColorEnabled(bool value);
517 |
518 | // Texture settings.
519 | void __cdecl SetTextureEnabled(bool value);
520 | void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
521 | void __cdecl SetTexture(int whichTexture, _In_opt_ ID3D11ShaderResourceView* value);
522 |
523 | static const int MaxTextures = 8;
524 |
525 | // Animation setting.
526 | void __cdecl SetWeightsPerVertex(int value) override;
527 | void __cdecl SetBoneTransforms(_In_reads_(count) XMMATRIX const* value, size_t count) override;
528 | void __cdecl ResetBoneTransforms() override;
529 |
530 | private:
531 | // Private implementation.
532 | class Impl;
533 |
534 | std::unique_ptr pImpl;
535 |
536 | // Unsupported interface methods.
537 | void __cdecl SetPerPixelLighting(bool value) override;
538 | };
539 |
540 | //----------------------------------------------------------------------------------
541 | // Built-in shader extends BasicEffect with normal maps and optional specular maps
542 | class NormalMapEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog
543 | {
544 | public:
545 | explicit NormalMapEffect(_In_ ID3D11Device* device);
546 | NormalMapEffect(NormalMapEffect&& moveFrom) noexcept;
547 | NormalMapEffect& operator= (NormalMapEffect&& moveFrom) noexcept;
548 |
549 | NormalMapEffect(NormalMapEffect const&) = delete;
550 | NormalMapEffect& operator= (NormalMapEffect const&) = delete;
551 |
552 | virtual ~NormalMapEffect() override;
553 |
554 | // IEffect methods.
555 | void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override;
556 |
557 | void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override;
558 |
559 | // Camera settings.
560 | void XM_CALLCONV SetWorld(FXMMATRIX value) override;
561 | void XM_CALLCONV SetView(FXMMATRIX value) override;
562 | void XM_CALLCONV SetProjection(FXMMATRIX value) override;
563 | void XM_CALLCONV SetMatrices(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection) override;
564 |
565 | // Material settings.
566 | void XM_CALLCONV SetDiffuseColor(FXMVECTOR value);
567 | void XM_CALLCONV SetEmissiveColor(FXMVECTOR value);
568 | void XM_CALLCONV SetSpecularColor(FXMVECTOR value);
569 | void __cdecl SetSpecularPower(float value);
570 | void __cdecl DisableSpecular();
571 | void __cdecl SetAlpha(float value);
572 | void XM_CALLCONV SetColorAndAlpha(FXMVECTOR value);
573 |
574 | // Light settings.
575 | void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override;
576 |
577 | void __cdecl SetLightEnabled(int whichLight, bool value) override;
578 | void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override;
579 | void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override;
580 | void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override;
581 |
582 | void __cdecl EnableDefaultLighting() override;
583 |
584 | // Fog settings.
585 | void __cdecl SetFogEnabled(bool value) override;
586 | void __cdecl SetFogStart(float value) override;
587 | void __cdecl SetFogEnd(float value) override;
588 | void XM_CALLCONV SetFogColor(FXMVECTOR value) override;
589 |
590 | // Vertex color setting.
591 | void __cdecl SetVertexColorEnabled(bool value);
592 |
593 | // Texture setting - albedo, normal and specular intensity
594 | void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
595 | void __cdecl SetNormalTexture(_In_opt_ ID3D11ShaderResourceView* value);
596 | void __cdecl SetSpecularTexture(_In_opt_ ID3D11ShaderResourceView* value);
597 |
598 | // Normal compression settings.
599 | void __cdecl SetBiasedVertexNormals(bool value);
600 |
601 | private:
602 | // Private implementation.
603 | class Impl;
604 |
605 | std::unique_ptr pImpl;
606 |
607 | // Unsupported interface methods.
608 | void __cdecl SetLightingEnabled(bool value) override;
609 | void __cdecl SetPerPixelLighting(bool value) override;
610 | };
611 |
612 | //----------------------------------------------------------------------------------
613 | // Built-in shader for Physically-Based Rendering (Roughness/Metalness) with Image-based lighting
614 | class PBREffect : public IEffect, public IEffectMatrices, public IEffectLights
615 | {
616 | public:
617 | explicit PBREffect(_In_ ID3D11Device* device);
618 | PBREffect(PBREffect&& moveFrom) noexcept;
619 | PBREffect& operator= (PBREffect&& moveFrom) noexcept;
620 |
621 | PBREffect(PBREffect const&) = delete;
622 | PBREffect& operator= (PBREffect const&) = delete;
623 |
624 | virtual ~PBREffect() override;
625 |
626 | // IEffect methods.
627 | void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override;
628 |
629 | void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override;
630 |
631 | // Camera settings.
632 | void XM_CALLCONV SetWorld(FXMMATRIX value) override;
633 | void XM_CALLCONV SetView(FXMMATRIX value) override;
634 | void XM_CALLCONV SetProjection(FXMMATRIX value) override;
635 | void XM_CALLCONV SetMatrices(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection) override;
636 |
637 | // Light settings.
638 | void __cdecl SetLightEnabled(int whichLight, bool value) override;
639 | void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override;
640 | void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override;
641 |
642 | void __cdecl EnableDefaultLighting() override;
643 |
644 | // PBR Settings.
645 | void __cdecl SetAlpha(float value);
646 | void XM_CALLCONV SetConstantAlbedo(FXMVECTOR value);
647 | void __cdecl SetConstantMetallic(float value);
648 | void __cdecl SetConstantRoughness(float value);
649 |
650 | // Texture settings.
651 | void __cdecl SetSurfaceTextures(
652 | _In_opt_ ID3D11ShaderResourceView* albedo,
653 | _In_opt_ ID3D11ShaderResourceView* normal,
654 | _In_opt_ ID3D11ShaderResourceView* roughnessMetallicAmbientOcclusion);
655 |
656 | void __cdecl SetIBLTextures(
657 | _In_opt_ ID3D11ShaderResourceView* radiance,
658 | int numRadianceMips,
659 | _In_opt_ ID3D11ShaderResourceView* irradiance);
660 |
661 | void __cdecl SetEmissiveTexture(_In_opt_ ID3D11ShaderResourceView* emissive);
662 |
663 | // Normal compression settings.
664 | void __cdecl SetBiasedVertexNormals(bool value);
665 |
666 | // Velocity buffer settings.
667 | void __cdecl SetVelocityGeneration(bool value);
668 |
669 | // Render target size, required for velocity buffer output.
670 | void __cdecl SetRenderTargetSizeInPixels(int width, int height);
671 |
672 | private:
673 | // Private implementation.
674 | class Impl;
675 |
676 | std::unique_ptr pImpl;
677 |
678 | // Unsupported interface methods.
679 | void __cdecl SetLightingEnabled(bool value) override;
680 | void __cdecl SetPerPixelLighting(bool value) override;
681 | void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override;
682 | void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override;
683 | };
684 |
685 | //----------------------------------------------------------------------------------
686 | // Built-in shader for debug visualization of normals, tangents, etc.
687 | class DebugEffect : public IEffect, public IEffectMatrices
688 | {
689 | public:
690 | enum Mode
691 | {
692 | Mode_Default = 0, // Hemispherical ambient lighting
693 | Mode_Normals, // RGB normals
694 | Mode_Tangents, // RGB tangents
695 | Mode_BiTangents, // RGB bi-tangents
696 | };
697 |
698 | explicit DebugEffect(_In_ ID3D11Device* device);
699 | DebugEffect(DebugEffect&& moveFrom) noexcept;
700 | DebugEffect& operator= (DebugEffect&& moveFrom) noexcept;
701 |
702 | DebugEffect(DebugEffect const&) = delete;
703 | DebugEffect& operator= (DebugEffect const&) = delete;
704 |
705 | virtual ~DebugEffect() override;
706 |
707 | // IEffect methods.
708 | void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override;
709 |
710 | void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override;
711 |
712 | // Camera settings.
713 | void XM_CALLCONV SetWorld(FXMMATRIX value) override;
714 | void XM_CALLCONV SetView(FXMMATRIX value) override;
715 | void XM_CALLCONV SetProjection(FXMMATRIX value) override;
716 | void XM_CALLCONV SetMatrices(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection) override;
717 |
718 | // Debug Settings.
719 | void __cdecl SetMode(Mode debugMode);
720 | void XM_CALLCONV SetHemisphericalAmbientColor(FXMVECTOR upper, FXMVECTOR lower);
721 | void __cdecl SetAlpha(float value);
722 |
723 | // Vertex color setting.
724 | void __cdecl SetVertexColorEnabled(bool value);
725 |
726 | // Normal compression settings.
727 | void __cdecl SetBiasedVertexNormals(bool value);
728 |
729 | private:
730 | // Private implementation.
731 | class Impl;
732 |
733 | std::unique_ptr pImpl;
734 | };
735 |
736 | //----------------------------------------------------------------------------------
737 | // Abstract interface to factory for sharing effects and texture resources
738 | class IEffectFactory
739 | {
740 | public:
741 | virtual ~IEffectFactory() = default;
742 |
743 | IEffectFactory(const IEffectFactory&) = delete;
744 | IEffectFactory& operator=(const IEffectFactory&) = delete;
745 |
746 | IEffectFactory(IEffectFactory&&) = delete;
747 | IEffectFactory& operator=(IEffectFactory&&) = delete;
748 |
749 | struct EffectInfo
750 | {
751 | const wchar_t* name;
752 | bool perVertexColor;
753 | bool enableSkinning;
754 | bool enableDualTexture;
755 | bool enableNormalMaps;
756 | bool biasedVertexNormals;
757 | float specularPower;
758 | float alpha;
759 | XMFLOAT3 ambientColor;
760 | XMFLOAT3 diffuseColor;
761 | XMFLOAT3 specularColor;
762 | XMFLOAT3 emissiveColor;
763 | const wchar_t* diffuseTexture;
764 | const wchar_t* specularTexture;
765 | const wchar_t* normalTexture;
766 |
767 | EffectInfo() noexcept :
768 | name(nullptr),
769 | perVertexColor(false),
770 | enableSkinning(false),
771 | enableDualTexture(false),
772 | enableNormalMaps(false),
773 | biasedVertexNormals(false),
774 | specularPower(0),
775 | alpha(0),
776 | ambientColor(0, 0, 0),
777 | diffuseColor(0, 0, 0),
778 | specularColor(0, 0, 0),
779 | emissiveColor(0, 0, 0),
780 | diffuseTexture(nullptr),
781 | specularTexture(nullptr),
782 | normalTexture(nullptr)
783 | {}
784 | };
785 |
786 | virtual std::shared_ptr __cdecl CreateEffect(_In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext) = 0;
787 |
788 | virtual void __cdecl CreateTexture(_In_z_ const wchar_t* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView) = 0;
789 |
790 | protected:
791 | IEffectFactory() = default;
792 | };
793 |
794 |
795 | // Factory for sharing effects and texture resources
796 | class EffectFactory : public IEffectFactory
797 | {
798 | public:
799 | explicit EffectFactory(_In_ ID3D11Device* device);
800 | EffectFactory(EffectFactory&& moveFrom) noexcept;
801 | EffectFactory& operator= (EffectFactory&& moveFrom) noexcept;
802 |
803 | EffectFactory(EffectFactory const&) = delete;
804 | EffectFactory& operator= (EffectFactory const&) = delete;
805 |
806 | virtual ~EffectFactory() override;
807 |
808 | // IEffectFactory methods.
809 | virtual std::shared_ptr __cdecl CreateEffect(_In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext) override;
810 | virtual void __cdecl CreateTexture(_In_z_ const wchar_t* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView) override;
811 |
812 | // Settings.
813 | void __cdecl ReleaseCache();
814 |
815 | void __cdecl SetSharing(bool enabled);
816 |
817 | void __cdecl EnableNormalMapEffect(bool enabled);
818 | void __cdecl EnableForceSRGB(bool forceSRGB);
819 |
820 | void __cdecl SetDirectory(_In_opt_z_ const wchar_t* path);
821 |
822 | // Properties.
823 | ID3D11Device* GetDevice() const;
824 |
825 | private:
826 | // Private implementation.
827 | class Impl;
828 |
829 | std::shared_ptr pImpl;
830 | };
831 |
832 |
833 | // Factory for sharing Visual Studio Shader Designer (DGSL) shaders and texture resources
834 | class DGSLEffectFactory : public IEffectFactory
835 | {
836 | public:
837 | explicit DGSLEffectFactory(_In_ ID3D11Device* device);
838 | DGSLEffectFactory(DGSLEffectFactory&& moveFrom) noexcept;
839 | DGSLEffectFactory& operator= (DGSLEffectFactory&& moveFrom) noexcept;
840 |
841 | DGSLEffectFactory(DGSLEffectFactory const&) = delete;
842 | DGSLEffectFactory& operator= (DGSLEffectFactory const&) = delete;
843 |
844 | virtual ~DGSLEffectFactory() override;
845 |
846 | // IEffectFactory methods.
847 | virtual std::shared_ptr __cdecl CreateEffect(_In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext) override;
848 | virtual void __cdecl CreateTexture(_In_z_ const wchar_t* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView) override;
849 |
850 | // DGSL methods.
851 | struct DGSLEffectInfo : public EffectInfo
852 | {
853 | static const int BaseTextureOffset = 3;
854 |
855 | const wchar_t* textures[DGSLEffect::MaxTextures - BaseTextureOffset];
856 | const wchar_t* pixelShader;
857 |
858 | DGSLEffectInfo() noexcept :
859 | EffectInfo(),
860 | textures{},
861 | pixelShader(nullptr)
862 | {}
863 | };
864 |
865 | virtual std::shared_ptr __cdecl CreateDGSLEffect(_In_ const DGSLEffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext);
866 |
867 | virtual void __cdecl CreatePixelShader(_In_z_ const wchar_t* shader, _Outptr_ ID3D11PixelShader** pixelShader);
868 |
869 | // Settings.
870 | void __cdecl ReleaseCache();
871 |
872 | void __cdecl SetSharing(bool enabled);
873 |
874 | void __cdecl EnableForceSRGB(bool forceSRGB);
875 |
876 | void __cdecl SetDirectory(_In_opt_z_ const wchar_t* path);
877 |
878 | // Properties.
879 | ID3D11Device* GetDevice() const;
880 |
881 | private:
882 | // Private implementation.
883 | class Impl;
884 |
885 | std::shared_ptr pImpl;
886 | };
887 | }
888 |
--------------------------------------------------------------------------------
/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017/Includes/GamePad.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: GamePad.h
3 | //
4 | // Copyright (c) Microsoft Corporation. All rights reserved.
5 | // Licensed under the MIT License.
6 | //
7 | // http://go.microsoft.com/fwlink/?LinkId=248929
8 | // http://go.microsoft.com/fwlink/?LinkID=615561
9 | //--------------------------------------------------------------------------------------
10 |
11 | #pragma once
12 |
13 | #if (_WIN32_WINNT < 0x0A00 /*_WIN32_WINNT_WIN10*/)
14 | #ifndef _XBOX_ONE
15 | #if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP)
16 | #if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/ )
17 | #pragma comment(lib,"xinput.lib")
18 | #else
19 | #pragma comment(lib,"xinput9_1_0.lib")
20 | #endif
21 | #endif
22 | #endif
23 | #endif
24 |
25 | #include
26 | #include
27 |
28 | #if (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
29 | #include
30 | #endif
31 |
32 |
33 | namespace DirectX
34 | {
35 | class GamePad
36 | {
37 | public:
38 | GamePad() noexcept(false);
39 | GamePad(GamePad&& moveFrom) noexcept;
40 | GamePad& operator= (GamePad&& moveFrom) noexcept;
41 |
42 | GamePad(GamePad const&) = delete;
43 | GamePad& operator=(GamePad const&) = delete;
44 |
45 | virtual ~GamePad();
46 |
47 | #if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/ ) || defined(_XBOX_ONE)
48 | static const int MAX_PLAYER_COUNT = 8;
49 | #else
50 | static const int MAX_PLAYER_COUNT = 4;
51 | #endif
52 |
53 | enum DeadZone
54 | {
55 | DEAD_ZONE_INDEPENDENT_AXES = 0,
56 | DEAD_ZONE_CIRCULAR,
57 | DEAD_ZONE_NONE,
58 | };
59 |
60 | struct Buttons
61 | {
62 | bool a;
63 | bool b;
64 | bool x;
65 | bool y;
66 | bool leftStick;
67 | bool rightStick;
68 | bool leftShoulder;
69 | bool rightShoulder;
70 | union
71 | {
72 | bool back;
73 | bool view;
74 | };
75 | union
76 | {
77 | bool start;
78 | bool menu;
79 | };
80 | };
81 |
82 | struct DPad
83 | {
84 | bool up;
85 | bool down;
86 | bool right;
87 | bool left;
88 | };
89 |
90 | struct ThumbSticks
91 | {
92 | float leftX;
93 | float leftY;
94 | float rightX;
95 | float rightY;
96 | };
97 |
98 | struct Triggers
99 | {
100 | float left;
101 | float right;
102 | };
103 |
104 | struct State
105 | {
106 | bool connected;
107 | uint64_t packet;
108 | Buttons buttons;
109 | DPad dpad;
110 | ThumbSticks thumbSticks;
111 | Triggers triggers;
112 |
113 | bool __cdecl IsConnected() const { return connected; }
114 |
115 | // Is the button pressed currently?
116 | bool __cdecl IsAPressed() const { return buttons.a; }
117 | bool __cdecl IsBPressed() const { return buttons.b; }
118 | bool __cdecl IsXPressed() const { return buttons.x; }
119 | bool __cdecl IsYPressed() const { return buttons.y; }
120 |
121 | bool __cdecl IsLeftStickPressed() const { return buttons.leftStick; }
122 | bool __cdecl IsRightStickPressed() const { return buttons.rightStick; }
123 |
124 | bool __cdecl IsLeftShoulderPressed() const { return buttons.leftShoulder; }
125 | bool __cdecl IsRightShoulderPressed() const { return buttons.rightShoulder; }
126 |
127 | bool __cdecl IsBackPressed() const { return buttons.back; }
128 | bool __cdecl IsViewPressed() const { return buttons.view; }
129 | bool __cdecl IsStartPressed() const { return buttons.start; }
130 | bool __cdecl IsMenuPressed() const { return buttons.menu; }
131 |
132 | bool __cdecl IsDPadDownPressed() const { return dpad.down; }
133 | bool __cdecl IsDPadUpPressed() const { return dpad.up; }
134 | bool __cdecl IsDPadLeftPressed() const { return dpad.left; }
135 | bool __cdecl IsDPadRightPressed() const { return dpad.right; }
136 |
137 | bool __cdecl IsLeftThumbStickUp() const { return (thumbSticks.leftY > 0.5f) != 0; }
138 | bool __cdecl IsLeftThumbStickDown() const { return (thumbSticks.leftY < -0.5f) != 0; }
139 | bool __cdecl IsLeftThumbStickLeft() const { return (thumbSticks.leftX < -0.5f) != 0; }
140 | bool __cdecl IsLeftThumbStickRight() const { return (thumbSticks.leftX > 0.5f) != 0; }
141 |
142 | bool __cdecl IsRightThumbStickUp() const { return (thumbSticks.rightY > 0.5f) != 0; }
143 | bool __cdecl IsRightThumbStickDown() const { return (thumbSticks.rightY < -0.5f) != 0; }
144 | bool __cdecl IsRightThumbStickLeft() const { return (thumbSticks.rightX < -0.5f) != 0; }
145 | bool __cdecl IsRightThumbStickRight() const { return (thumbSticks.rightX > 0.5f) != 0; }
146 |
147 | bool __cdecl IsLeftTriggerPressed() const { return (triggers.left > 0.5f) != 0; }
148 | bool __cdecl IsRightTriggerPressed() const { return (triggers.right > 0.5f) != 0; }
149 | };
150 |
151 | struct Capabilities
152 | {
153 | enum Type
154 | {
155 | UNKNOWN = 0,
156 | GAMEPAD,
157 | WHEEL,
158 | ARCADE_STICK,
159 | FLIGHT_STICK,
160 | DANCE_PAD,
161 | GUITAR,
162 | GUITAR_ALTERNATE,
163 | DRUM_KIT,
164 | GUITAR_BASS = 11,
165 | ARCADE_PAD = 19,
166 | };
167 |
168 | bool connected;
169 | Type gamepadType;
170 | #if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/)
171 | std::wstring id;
172 |
173 | Capabilities() noexcept : connected(false), gamepadType(UNKNOWN) {}
174 | #else
175 | uint64_t id;
176 | #endif
177 |
178 | bool __cdecl IsConnected() const { return connected; }
179 | };
180 |
181 | class ButtonStateTracker
182 | {
183 | public:
184 | enum ButtonState
185 | {
186 | UP = 0, // Button is up
187 | HELD = 1, // Button is held down
188 | RELEASED = 2, // Button was just released
189 | PRESSED = 3, // Buton was just pressed
190 | };
191 |
192 | ButtonState a;
193 | ButtonState b;
194 | ButtonState x;
195 | ButtonState y;
196 |
197 | ButtonState leftStick;
198 | ButtonState rightStick;
199 |
200 | ButtonState leftShoulder;
201 | ButtonState rightShoulder;
202 |
203 | union
204 | {
205 | ButtonState back;
206 | ButtonState view;
207 | };
208 |
209 | union
210 | {
211 | ButtonState start;
212 | ButtonState menu;
213 | };
214 |
215 | ButtonState dpadUp;
216 | ButtonState dpadDown;
217 | ButtonState dpadLeft;
218 | ButtonState dpadRight;
219 |
220 | ButtonState leftStickUp;
221 | ButtonState leftStickDown;
222 | ButtonState leftStickLeft;
223 | ButtonState leftStickRight;
224 |
225 | ButtonState rightStickUp;
226 | ButtonState rightStickDown;
227 | ButtonState rightStickLeft;
228 | ButtonState rightStickRight;
229 |
230 | ButtonState leftTrigger;
231 | ButtonState rightTrigger;
232 |
233 | #pragma prefast(suppress: 26495, "Reset() performs the initialization")
234 | ButtonStateTracker() noexcept { Reset(); }
235 |
236 | void __cdecl Update(const State& state);
237 |
238 | void __cdecl Reset() noexcept;
239 |
240 | State __cdecl GetLastState() const { return lastState; }
241 |
242 | private:
243 | State lastState;
244 | };
245 |
246 | // Retrieve the current state of the gamepad of the associated player index
247 | State __cdecl GetState(int player, DeadZone deadZoneMode = DEAD_ZONE_INDEPENDENT_AXES);
248 |
249 | // Retrieve the current capabilities of the gamepad of the associated player index
250 | Capabilities __cdecl GetCapabilities(int player);
251 |
252 | // Set the vibration motor speeds of the gamepad
253 | bool __cdecl SetVibration(int player, float leftMotor, float rightMotor, float leftTrigger = 0.f, float rightTrigger = 0.f);
254 |
255 | // Handle suspending/resuming
256 | void __cdecl Suspend();
257 | void __cdecl Resume();
258 |
259 | #if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/ ) || defined(_XBOX_ONE)
260 | void __cdecl RegisterEvents(void* ctrlChanged, void* userChanged);
261 | #endif
262 |
263 | // Singleton
264 | static GamePad& __cdecl Get();
265 |
266 | private:
267 | // Private implementation.
268 | class Impl;
269 |
270 | std::unique_ptr pImpl;
271 | };
272 | }
273 |
--------------------------------------------------------------------------------
/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017/Includes/GeometricPrimitive.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: GeometricPrimitive.h
3 | //
4 | // Copyright (c) Microsoft Corporation. All rights reserved.
5 | // Licensed under the MIT License.
6 | //
7 | // http://go.microsoft.com/fwlink/?LinkId=248929
8 | //--------------------------------------------------------------------------------------
9 |
10 | #pragma once
11 |
12 | #include "VertexTypes.h"
13 |
14 | #include
15 | #include
16 | #include
17 | #include
18 |
19 |
20 | namespace DirectX
21 | {
22 | class IEffect;
23 |
24 | class GeometricPrimitive
25 | {
26 | public:
27 | GeometricPrimitive(GeometricPrimitive const&) = delete;
28 | GeometricPrimitive& operator= (GeometricPrimitive const&) = delete;
29 |
30 | using VertexType = VertexPositionNormalTexture;
31 |
32 | virtual ~GeometricPrimitive();
33 |
34 | // Factory methods.
35 | static std::unique_ptr __cdecl CreateCube(_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
36 | static std::unique_ptr __cdecl CreateBox(_In_ ID3D11DeviceContext* deviceContext, const XMFLOAT3& size, bool rhcoords = true, bool invertn = false);
37 | static std::unique_ptr __cdecl CreateSphere(_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, size_t tessellation = 16, bool rhcoords = true, bool invertn = false);
38 | static std::unique_ptr __cdecl CreateGeoSphere(_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, size_t tessellation = 3, bool rhcoords = true);
39 | static std::unique_ptr __cdecl CreateCylinder(_In_ ID3D11DeviceContext* deviceContext, float height = 1, float diameter = 1, size_t tessellation = 32, bool rhcoords = true);
40 | static std::unique_ptr __cdecl CreateCone(_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, float height = 1, size_t tessellation = 32, bool rhcoords = true);
41 | static std::unique_ptr __cdecl CreateTorus(_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, float thickness = 0.333f, size_t tessellation = 32, bool rhcoords = true);
42 | static std::unique_ptr __cdecl CreateTetrahedron(_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
43 | static std::unique_ptr __cdecl CreateOctahedron(_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
44 | static std::unique_ptr __cdecl CreateDodecahedron(_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
45 | static std::unique_ptr __cdecl CreateIcosahedron(_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
46 | static std::unique_ptr __cdecl CreateTeapot(_In_ ID3D11DeviceContext* deviceContext, float size = 1, size_t tessellation = 8, bool rhcoords = true);
47 | static std::unique_ptr __cdecl CreateCustom(_In_ ID3D11DeviceContext* deviceContext, const std::vector& vertices, const std::vector& indices);
48 |
49 | static void __cdecl CreateCube(std::vector& vertices, std::vector& indices, float size = 1, bool rhcoords = true);
50 | static void __cdecl CreateBox(std::vector& vertices, std::vector& indices, const XMFLOAT3& size, bool rhcoords = true, bool invertn = false);
51 | static void __cdecl CreateSphere(std::vector& vertices, std::vector& indices, float diameter = 1, size_t tessellation = 16, bool rhcoords = true, bool invertn = false);
52 | static void __cdecl CreateGeoSphere(std::vector& vertices, std::vector& indices, float diameter = 1, size_t tessellation = 3, bool rhcoords = true);
53 | static void __cdecl CreateCylinder(std::vector& vertices, std::vector& indices, float height = 1, float diameter = 1, size_t tessellation = 32, bool rhcoords = true);
54 | static void __cdecl CreateCone(std::vector& vertices, std::vector& indices, float diameter = 1, float height = 1, size_t tessellation = 32, bool rhcoords = true);
55 | static void __cdecl CreateTorus(std::vector& vertices, std::vector& indices, float diameter = 1, float thickness = 0.333f, size_t tessellation = 32, bool rhcoords = true);
56 | static void __cdecl CreateTetrahedron(std::vector& vertices, std::vector& indices, float size = 1, bool rhcoords = true);
57 | static void __cdecl CreateOctahedron(std::vector& vertices, std::vector& indices, float size = 1, bool rhcoords = true);
58 | static void __cdecl CreateDodecahedron(std::vector& vertices, std::vector& indices, float size = 1, bool rhcoords = true);
59 | static void __cdecl CreateIcosahedron(std::vector& vertices, std::vector& indices, float size = 1, bool rhcoords = true);
60 | static void __cdecl CreateTeapot(std::vector& vertices, std::vector& indices, float size = 1, size_t tessellation = 8, bool rhcoords = true);
61 |
62 | // Draw the primitive.
63 | void XM_CALLCONV Draw(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection, FXMVECTOR color = Colors::White, _In_opt_ ID3D11ShaderResourceView* texture = nullptr, bool wireframe = false,
64 | _In_opt_ std::function setCustomState = nullptr) const;
65 |
66 | // Draw the primitive using a custom effect.
67 | void __cdecl Draw(_In_ IEffect* effect, _In_ ID3D11InputLayout* inputLayout, bool alpha = false, bool wireframe = false,
68 | _In_opt_ std::function setCustomState = nullptr) const;
69 |
70 | // Create input layout for drawing with a custom effect.
71 | void __cdecl CreateInputLayout(_In_ IEffect* effect, _Outptr_ ID3D11InputLayout** inputLayout) const;
72 |
73 | private:
74 | GeometricPrimitive() noexcept(false);
75 |
76 | // Private implementation.
77 | class Impl;
78 |
79 | std::unique_ptr pImpl;
80 | };
81 | }
82 |
--------------------------------------------------------------------------------
/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017/Includes/GraphicsMemory.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: GraphicsMemory.h
3 | //
4 | // Copyright (c) Microsoft Corporation. All rights reserved.
5 | // Licensed under the MIT License.
6 | //
7 | // http://go.microsoft.com/fwlink/?LinkId=248929
8 | //--------------------------------------------------------------------------------------
9 |
10 | #pragma once
11 |
12 | #if defined(_XBOX_ONE) && defined(_TITLE)
13 | #include
14 | #else
15 | #include
16 | #endif
17 |
18 | #include
19 |
20 |
21 | namespace DirectX
22 | {
23 | class GraphicsMemory
24 | {
25 | public:
26 | #if defined(_XBOX_ONE) && defined(_TITLE)
27 | GraphicsMemory(_In_ ID3D11DeviceX* device, UINT backBufferCount = 2);
28 | #else
29 | GraphicsMemory(_In_ ID3D11Device* device, UINT backBufferCount = 2);
30 | #endif
31 | GraphicsMemory(GraphicsMemory&& moveFrom) noexcept;
32 | GraphicsMemory& operator= (GraphicsMemory&& moveFrom) noexcept;
33 |
34 | GraphicsMemory(GraphicsMemory const&) = delete;
35 | GraphicsMemory& operator=(GraphicsMemory const&) = delete;
36 |
37 | virtual ~GraphicsMemory();
38 |
39 | void* __cdecl Allocate(_In_opt_ ID3D11DeviceContext* context, size_t size, int alignment);
40 |
41 | void __cdecl Commit();
42 |
43 | // Singleton
44 | static GraphicsMemory& __cdecl Get();
45 |
46 | private:
47 | // Private implementation.
48 | class Impl;
49 |
50 | std::unique_ptr pImpl;
51 | };
52 | }
53 |
--------------------------------------------------------------------------------
/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017/Includes/Keyboard.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: Keyboard.h
3 | //
4 | // Copyright (c) Microsoft Corporation. All rights reserved.
5 | // Licensed under the MIT License.
6 | //
7 | // http://go.microsoft.com/fwlink/?LinkId=248929
8 | // http://go.microsoft.com/fwlink/?LinkID=615561
9 | //--------------------------------------------------------------------------------------
10 |
11 | #pragma once
12 |
13 | #include
14 | #include
15 |
16 | #if (defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)) || (defined(_XBOX_ONE) && defined(_TITLE))
17 | namespace ABI { namespace Windows { namespace UI { namespace Core { struct ICoreWindow; } } } }
18 | #endif
19 |
20 |
21 | namespace DirectX
22 | {
23 | class Keyboard
24 | {
25 | public:
26 | Keyboard() noexcept(false);
27 | Keyboard(Keyboard&& moveFrom) noexcept;
28 | Keyboard& operator= (Keyboard&& moveFrom) noexcept;
29 |
30 | Keyboard(Keyboard const&) = delete;
31 | Keyboard& operator=(Keyboard const&) = delete;
32 |
33 | virtual ~Keyboard();
34 |
35 | enum Keys
36 | {
37 | None = 0,
38 |
39 | Back = 0x8,
40 | Tab = 0x9,
41 |
42 | Enter = 0xd,
43 |
44 | Pause = 0x13,
45 | CapsLock = 0x14,
46 | Kana = 0x15,
47 |
48 | Kanji = 0x19,
49 |
50 | Escape = 0x1b,
51 | ImeConvert = 0x1c,
52 | ImeNoConvert = 0x1d,
53 |
54 | Space = 0x20,
55 | PageUp = 0x21,
56 | PageDown = 0x22,
57 | End = 0x23,
58 | Home = 0x24,
59 | Left = 0x25,
60 | Up = 0x26,
61 | Right = 0x27,
62 | Down = 0x28,
63 | Select = 0x29,
64 | Print = 0x2a,
65 | Execute = 0x2b,
66 | PrintScreen = 0x2c,
67 | Insert = 0x2d,
68 | Delete = 0x2e,
69 | Help = 0x2f,
70 | D0 = 0x30,
71 | D1 = 0x31,
72 | D2 = 0x32,
73 | D3 = 0x33,
74 | D4 = 0x34,
75 | D5 = 0x35,
76 | D6 = 0x36,
77 | D7 = 0x37,
78 | D8 = 0x38,
79 | D9 = 0x39,
80 |
81 | A = 0x41,
82 | B = 0x42,
83 | C = 0x43,
84 | D = 0x44,
85 | E = 0x45,
86 | F = 0x46,
87 | G = 0x47,
88 | H = 0x48,
89 | I = 0x49,
90 | J = 0x4a,
91 | K = 0x4b,
92 | L = 0x4c,
93 | M = 0x4d,
94 | N = 0x4e,
95 | O = 0x4f,
96 | P = 0x50,
97 | Q = 0x51,
98 | R = 0x52,
99 | S = 0x53,
100 | T = 0x54,
101 | U = 0x55,
102 | V = 0x56,
103 | W = 0x57,
104 | X = 0x58,
105 | Y = 0x59,
106 | Z = 0x5a,
107 | LeftWindows = 0x5b,
108 | RightWindows = 0x5c,
109 | Apps = 0x5d,
110 |
111 | Sleep = 0x5f,
112 | NumPad0 = 0x60,
113 | NumPad1 = 0x61,
114 | NumPad2 = 0x62,
115 | NumPad3 = 0x63,
116 | NumPad4 = 0x64,
117 | NumPad5 = 0x65,
118 | NumPad6 = 0x66,
119 | NumPad7 = 0x67,
120 | NumPad8 = 0x68,
121 | NumPad9 = 0x69,
122 | Multiply = 0x6a,
123 | Add = 0x6b,
124 | Separator = 0x6c,
125 | Subtract = 0x6d,
126 |
127 | Decimal = 0x6e,
128 | Divide = 0x6f,
129 | F1 = 0x70,
130 | F2 = 0x71,
131 | F3 = 0x72,
132 | F4 = 0x73,
133 | F5 = 0x74,
134 | F6 = 0x75,
135 | F7 = 0x76,
136 | F8 = 0x77,
137 | F9 = 0x78,
138 | F10 = 0x79,
139 | F11 = 0x7a,
140 | F12 = 0x7b,
141 | F13 = 0x7c,
142 | F14 = 0x7d,
143 | F15 = 0x7e,
144 | F16 = 0x7f,
145 | F17 = 0x80,
146 | F18 = 0x81,
147 | F19 = 0x82,
148 | F20 = 0x83,
149 | F21 = 0x84,
150 | F22 = 0x85,
151 | F23 = 0x86,
152 | F24 = 0x87,
153 |
154 | NumLock = 0x90,
155 | Scroll = 0x91,
156 |
157 | LeftShift = 0xa0,
158 | RightShift = 0xa1,
159 | LeftControl = 0xa2,
160 | RightControl = 0xa3,
161 | LeftAlt = 0xa4,
162 | RightAlt = 0xa5,
163 | BrowserBack = 0xa6,
164 | BrowserForward = 0xa7,
165 | BrowserRefresh = 0xa8,
166 | BrowserStop = 0xa9,
167 | BrowserSearch = 0xaa,
168 | BrowserFavorites = 0xab,
169 | BrowserHome = 0xac,
170 | VolumeMute = 0xad,
171 | VolumeDown = 0xae,
172 | VolumeUp = 0xaf,
173 | MediaNextTrack = 0xb0,
174 | MediaPreviousTrack = 0xb1,
175 | MediaStop = 0xb2,
176 | MediaPlayPause = 0xb3,
177 | LaunchMail = 0xb4,
178 | SelectMedia = 0xb5,
179 | LaunchApplication1 = 0xb6,
180 | LaunchApplication2 = 0xb7,
181 |
182 | OemSemicolon = 0xba,
183 | OemPlus = 0xbb,
184 | OemComma = 0xbc,
185 | OemMinus = 0xbd,
186 | OemPeriod = 0xbe,
187 | OemQuestion = 0xbf,
188 | OemTilde = 0xc0,
189 |
190 | OemOpenBrackets = 0xdb,
191 | OemPipe = 0xdc,
192 | OemCloseBrackets = 0xdd,
193 | OemQuotes = 0xde,
194 | Oem8 = 0xdf,
195 |
196 | OemBackslash = 0xe2,
197 |
198 | ProcessKey = 0xe5,
199 |
200 | OemCopy = 0xf2,
201 | OemAuto = 0xf3,
202 | OemEnlW = 0xf4,
203 |
204 | Attn = 0xf6,
205 | Crsel = 0xf7,
206 | Exsel = 0xf8,
207 | EraseEof = 0xf9,
208 | Play = 0xfa,
209 | Zoom = 0xfb,
210 |
211 | Pa1 = 0xfd,
212 | OemClear = 0xfe,
213 | };
214 |
215 | struct State
216 | {
217 | bool Reserved0 : 8;
218 | bool Back : 1; // VK_BACK, 0x8
219 | bool Tab : 1; // VK_TAB, 0x9
220 | bool Reserved1 : 3;
221 | bool Enter : 1; // VK_RETURN, 0xD
222 | bool Reserved2 : 2;
223 | bool Reserved3 : 3;
224 | bool Pause : 1; // VK_PAUSE, 0x13
225 | bool CapsLock : 1; // VK_CAPITAL, 0x14
226 | bool Kana : 1; // VK_KANA, 0x15
227 | bool Reserved4 : 2;
228 | bool Reserved5 : 1;
229 | bool Kanji : 1; // VK_KANJI, 0x19
230 | bool Reserved6 : 1;
231 | bool Escape : 1; // VK_ESCAPE, 0x1B
232 | bool ImeConvert : 1; // VK_CONVERT, 0x1C
233 | bool ImeNoConvert : 1; // VK_NONCONVERT, 0x1D
234 | bool Reserved7 : 2;
235 | bool Space : 1; // VK_SPACE, 0x20
236 | bool PageUp : 1; // VK_PRIOR, 0x21
237 | bool PageDown : 1; // VK_NEXT, 0x22
238 | bool End : 1; // VK_END, 0x23
239 | bool Home : 1; // VK_HOME, 0x24
240 | bool Left : 1; // VK_LEFT, 0x25
241 | bool Up : 1; // VK_UP, 0x26
242 | bool Right : 1; // VK_RIGHT, 0x27
243 | bool Down : 1; // VK_DOWN, 0x28
244 | bool Select : 1; // VK_SELECT, 0x29
245 | bool Print : 1; // VK_PRINT, 0x2A
246 | bool Execute : 1; // VK_EXECUTE, 0x2B
247 | bool PrintScreen : 1; // VK_SNAPSHOT, 0x2C
248 | bool Insert : 1; // VK_INSERT, 0x2D
249 | bool Delete : 1; // VK_DELETE, 0x2E
250 | bool Help : 1; // VK_HELP, 0x2F
251 | bool D0 : 1; // 0x30
252 | bool D1 : 1; // 0x31
253 | bool D2 : 1; // 0x32
254 | bool D3 : 1; // 0x33
255 | bool D4 : 1; // 0x34
256 | bool D5 : 1; // 0x35
257 | bool D6 : 1; // 0x36
258 | bool D7 : 1; // 0x37
259 | bool D8 : 1; // 0x38
260 | bool D9 : 1; // 0x39
261 | bool Reserved8 : 6;
262 | bool Reserved9 : 1;
263 | bool A : 1; // 0x41
264 | bool B : 1; // 0x42
265 | bool C : 1; // 0x43
266 | bool D : 1; // 0x44
267 | bool E : 1; // 0x45
268 | bool F : 1; // 0x46
269 | bool G : 1; // 0x47
270 | bool H : 1; // 0x48
271 | bool I : 1; // 0x49
272 | bool J : 1; // 0x4A
273 | bool K : 1; // 0x4B
274 | bool L : 1; // 0x4C
275 | bool M : 1; // 0x4D
276 | bool N : 1; // 0x4E
277 | bool O : 1; // 0x4F
278 | bool P : 1; // 0x50
279 | bool Q : 1; // 0x51
280 | bool R : 1; // 0x52
281 | bool S : 1; // 0x53
282 | bool T : 1; // 0x54
283 | bool U : 1; // 0x55
284 | bool V : 1; // 0x56
285 | bool W : 1; // 0x57
286 | bool X : 1; // 0x58
287 | bool Y : 1; // 0x59
288 | bool Z : 1; // 0x5A
289 | bool LeftWindows : 1; // VK_LWIN, 0x5B
290 | bool RightWindows : 1; // VK_RWIN, 0x5C
291 | bool Apps : 1; // VK_APPS, 0x5D
292 | bool Reserved10 : 1;
293 | bool Sleep : 1; // VK_SLEEP, 0x5F
294 | bool NumPad0 : 1; // VK_NUMPAD0, 0x60
295 | bool NumPad1 : 1; // VK_NUMPAD1, 0x61
296 | bool NumPad2 : 1; // VK_NUMPAD2, 0x62
297 | bool NumPad3 : 1; // VK_NUMPAD3, 0x63
298 | bool NumPad4 : 1; // VK_NUMPAD4, 0x64
299 | bool NumPad5 : 1; // VK_NUMPAD5, 0x65
300 | bool NumPad6 : 1; // VK_NUMPAD6, 0x66
301 | bool NumPad7 : 1; // VK_NUMPAD7, 0x67
302 | bool NumPad8 : 1; // VK_NUMPAD8, 0x68
303 | bool NumPad9 : 1; // VK_NUMPAD9, 0x69
304 | bool Multiply : 1; // VK_MULTIPLY, 0x6A
305 | bool Add : 1; // VK_ADD, 0x6B
306 | bool Separator : 1; // VK_SEPARATOR, 0x6C
307 | bool Subtract : 1; // VK_SUBTRACT, 0x6D
308 | bool Decimal : 1; // VK_DECIMANL, 0x6E
309 | bool Divide : 1; // VK_DIVIDE, 0x6F
310 | bool F1 : 1; // VK_F1, 0x70
311 | bool F2 : 1; // VK_F2, 0x71
312 | bool F3 : 1; // VK_F3, 0x72
313 | bool F4 : 1; // VK_F4, 0x73
314 | bool F5 : 1; // VK_F5, 0x74
315 | bool F6 : 1; // VK_F6, 0x75
316 | bool F7 : 1; // VK_F7, 0x76
317 | bool F8 : 1; // VK_F8, 0x77
318 | bool F9 : 1; // VK_F9, 0x78
319 | bool F10 : 1; // VK_F10, 0x79
320 | bool F11 : 1; // VK_F11, 0x7A
321 | bool F12 : 1; // VK_F12, 0x7B
322 | bool F13 : 1; // VK_F13, 0x7C
323 | bool F14 : 1; // VK_F14, 0x7D
324 | bool F15 : 1; // VK_F15, 0x7E
325 | bool F16 : 1; // VK_F16, 0x7F
326 | bool F17 : 1; // VK_F17, 0x80
327 | bool F18 : 1; // VK_F18, 0x81
328 | bool F19 : 1; // VK_F19, 0x82
329 | bool F20 : 1; // VK_F20, 0x83
330 | bool F21 : 1; // VK_F21, 0x84
331 | bool F22 : 1; // VK_F22, 0x85
332 | bool F23 : 1; // VK_F23, 0x86
333 | bool F24 : 1; // VK_F24, 0x87
334 | bool Reserved11 : 8;
335 | bool NumLock : 1; // VK_NUMLOCK, 0x90
336 | bool Scroll : 1; // VK_SCROLL, 0x91
337 | bool Reserved12 : 6;
338 | bool Reserved13 : 8;
339 | bool LeftShift : 1; // VK_LSHIFT, 0xA0
340 | bool RightShift : 1; // VK_RSHIFT, 0xA1
341 | bool LeftControl : 1; // VK_LCONTROL, 0xA2
342 | bool RightControl : 1; // VK_RCONTROL, 0xA3
343 | bool LeftAlt : 1; // VK_LMENU, 0xA4
344 | bool RightAlt : 1; // VK_RMENU, 0xA5
345 | bool BrowserBack : 1; // VK_BROWSER_BACK, 0xA6
346 | bool BrowserForward : 1; // VK_BROWSER_FORWARD, 0xA7
347 | bool BrowserRefresh : 1; // VK_BROWSER_REFRESH, 0xA8
348 | bool BrowserStop : 1; // VK_BROWSER_STOP, 0xA9
349 | bool BrowserSearch : 1; // VK_BROWSER_SEARCH, 0xAA
350 | bool BrowserFavorites : 1; // VK_BROWSER_FAVORITES, 0xAB
351 | bool BrowserHome : 1; // VK_BROWSER_HOME, 0xAC
352 | bool VolumeMute : 1; // VK_VOLUME_MUTE, 0xAD
353 | bool VolumeDown : 1; // VK_VOLUME_DOWN, 0xAE
354 | bool VolumeUp : 1; // VK_VOLUME_UP, 0xAF
355 | bool MediaNextTrack : 1; // VK_MEDIA_NEXT_TRACK, 0xB0
356 | bool MediaPreviousTrack : 1;// VK_MEDIA_PREV_TRACK, 0xB1
357 | bool MediaStop : 1; // VK_MEDIA_STOP, 0xB2
358 | bool MediaPlayPause : 1; // VK_MEDIA_PLAY_PAUSE, 0xB3
359 | bool LaunchMail : 1; // VK_LAUNCH_MAIL, 0xB4
360 | bool SelectMedia : 1; // VK_LAUNCH_MEDIA_SELECT, 0xB5
361 | bool LaunchApplication1 : 1;// VK_LAUNCH_APP1, 0xB6
362 | bool LaunchApplication2 : 1;// VK_LAUNCH_APP2, 0xB7
363 | bool Reserved14 : 2;
364 | bool OemSemicolon : 1; // VK_OEM_1, 0xBA
365 | bool OemPlus : 1; // VK_OEM_PLUS, 0xBB
366 | bool OemComma : 1; // VK_OEM_COMMA, 0xBC
367 | bool OemMinus : 1; // VK_OEM_MINUS, 0xBD
368 | bool OemPeriod : 1; // VK_OEM_PERIOD, 0xBE
369 | bool OemQuestion : 1; // VK_OEM_2, 0xBF
370 | bool OemTilde : 1; // VK_OEM_3, 0xC0
371 | bool Reserved15 : 7;
372 | bool Reserved16 : 8;
373 | bool Reserved17 : 8;
374 | bool Reserved18 : 3;
375 | bool OemOpenBrackets : 1; // VK_OEM_4, 0xDB
376 | bool OemPipe : 1; // VK_OEM_5, 0xDC
377 | bool OemCloseBrackets : 1; // VK_OEM_6, 0xDD
378 | bool OemQuotes : 1; // VK_OEM_7, 0xDE
379 | bool Oem8 : 1; // VK_OEM_8, 0xDF
380 | bool Reserved19 : 2;
381 | bool OemBackslash : 1; // VK_OEM_102, 0xE2
382 | bool Reserved20 : 2;
383 | bool ProcessKey : 1; // VK_PROCESSKEY, 0xE5
384 | bool Reserved21 : 2;
385 | bool Reserved22 : 8;
386 | bool Reserved23 : 2;
387 | bool OemCopy : 1; // 0XF2
388 | bool OemAuto : 1; // 0xF3
389 | bool OemEnlW : 1; // 0xF4
390 | bool Reserved24 : 1;
391 | bool Attn : 1; // VK_ATTN, 0xF6
392 | bool Crsel : 1; // VK_CRSEL, 0xF7
393 | bool Exsel : 1; // VK_EXSEL, 0xF8
394 | bool EraseEof : 1; // VK_EREOF, 0xF9
395 | bool Play : 1; // VK_PLAY, 0xFA
396 | bool Zoom : 1; // VK_ZOOM, 0xFB
397 | bool Reserved25 : 1;
398 | bool Pa1 : 1; // VK_PA1, 0xFD
399 | bool OemClear : 1; // VK_OEM_CLEAR, 0xFE
400 | bool Reserved26: 1;
401 |
402 | bool __cdecl IsKeyDown(Keys key) const
403 | {
404 | if (key >= 0 && key <= 0xfe)
405 | {
406 | auto ptr = reinterpret_cast(this);
407 | unsigned int bf = 1u << (key & 0x1f);
408 | return (ptr[(key >> 5)] & bf) != 0;
409 | }
410 | return false;
411 | }
412 |
413 | bool __cdecl IsKeyUp(Keys key) const
414 | {
415 | if (key >= 0 && key <= 0xfe)
416 | {
417 | auto ptr = reinterpret_cast(this);
418 | unsigned int bf = 1u << (key & 0x1f);
419 | return (ptr[(key >> 5)] & bf) == 0;
420 | }
421 | return false;
422 | }
423 | };
424 |
425 | class KeyboardStateTracker
426 | {
427 | public:
428 | State released;
429 | State pressed;
430 |
431 | #pragma prefast(suppress: 26495, "Reset() performs the initialization")
432 | KeyboardStateTracker() noexcept { Reset(); }
433 |
434 | void __cdecl Update(const State& state);
435 |
436 | void __cdecl Reset() noexcept;
437 |
438 | bool __cdecl IsKeyPressed(Keys key) const { return pressed.IsKeyDown(key); }
439 | bool __cdecl IsKeyReleased(Keys key) const { return released.IsKeyDown(key); }
440 |
441 | State __cdecl GetLastState() const { return lastState; }
442 |
443 | public:
444 | State lastState;
445 | };
446 |
447 | // Retrieve the current state of the keyboard
448 | State __cdecl GetState() const;
449 |
450 | // Reset the keyboard state
451 | void __cdecl Reset();
452 |
453 | // Feature detection
454 | bool __cdecl IsConnected() const;
455 |
456 | #if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP) && defined(WM_USER)
457 | static void __cdecl ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam);
458 | #endif
459 |
460 | #if (defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)) || (defined(_XBOX_ONE) && defined(_TITLE))
461 | void __cdecl SetWindow(ABI::Windows::UI::Core::ICoreWindow* window);
462 | #ifdef __cplusplus_winrt
463 | void __cdecl SetWindow(Windows::UI::Core::CoreWindow^ window)
464 | {
465 | // See https://msdn.microsoft.com/en-us/library/hh755802.aspx
466 | SetWindow(reinterpret_cast(window));
467 | }
468 | #endif
469 | #endif
470 |
471 | // Singleton
472 | static Keyboard& __cdecl Get();
473 |
474 | private:
475 | // Private implementation.
476 | class Impl;
477 |
478 | std::unique_ptr pImpl;
479 | };
480 | }
481 |
--------------------------------------------------------------------------------
/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017/Includes/Model.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: Model.h
3 | //
4 | // Copyright (c) Microsoft Corporation. All rights reserved.
5 | // Licensed under the MIT License.
6 | //
7 | // http://go.microsoft.com/fwlink/?LinkId=248929
8 | //--------------------------------------------------------------------------------------
9 |
10 | #pragma once
11 |
12 | #if defined(_XBOX_ONE) && defined(_TITLE)
13 | #include
14 | #else
15 | #include
16 | #endif
17 |
18 | #include
19 | #include
20 |
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 |
27 | #include
28 |
29 | #include
30 |
31 |
32 | namespace DirectX
33 | {
34 | class IEffect;
35 | class IEffectFactory;
36 | class CommonStates;
37 | class ModelMesh;
38 |
39 | //----------------------------------------------------------------------------------
40 | // Each mesh part is a submesh with a single effect
41 | class ModelMeshPart
42 | {
43 | public:
44 | ModelMeshPart() noexcept;
45 | virtual ~ModelMeshPart();
46 |
47 | uint32_t indexCount;
48 | uint32_t startIndex;
49 | uint32_t vertexOffset;
50 | uint32_t vertexStride;
51 | D3D_PRIMITIVE_TOPOLOGY primitiveType;
52 | DXGI_FORMAT indexFormat;
53 | Microsoft::WRL::ComPtr inputLayout;
54 | Microsoft::WRL::ComPtr indexBuffer;
55 | Microsoft::WRL::ComPtr vertexBuffer;
56 | std::shared_ptr effect;
57 | std::shared_ptr> vbDecl;
58 | bool isAlpha;
59 |
60 | typedef std::vector> Collection;
61 |
62 | // Draw mesh part with custom effect
63 | void __cdecl Draw(_In_ ID3D11DeviceContext* deviceContext, _In_ IEffect* ieffect, _In_ ID3D11InputLayout* iinputLayout,
64 | _In_opt_ std::function setCustomState = nullptr) const;
65 |
66 | void __cdecl DrawInstanced(_In_ ID3D11DeviceContext* deviceContext, _In_ IEffect* ieffect, _In_ ID3D11InputLayout* iinputLayout,
67 | uint32_t instanceCount, uint32_t startInstanceLocation = 0,
68 | _In_opt_ std::function setCustomState = nullptr) const;
69 |
70 | // Create input layout for drawing with a custom effect.
71 | void __cdecl CreateInputLayout(_In_ ID3D11Device* d3dDevice, _In_ IEffect* ieffect, _Outptr_ ID3D11InputLayout** iinputLayout) const;
72 |
73 | // Change effect used by part and regenerate input layout (be sure to call Model::Modified as well)
74 | void __cdecl ModifyEffect(_In_ ID3D11Device* d3dDevice, _In_ std::shared_ptr& ieffect, bool isalpha = false);
75 | };
76 |
77 |
78 | //----------------------------------------------------------------------------------
79 | // A mesh consists of one or more model mesh parts
80 | class ModelMesh
81 | {
82 | public:
83 | ModelMesh() noexcept;
84 | virtual ~ModelMesh();
85 |
86 | BoundingSphere boundingSphere;
87 | BoundingBox boundingBox;
88 | ModelMeshPart::Collection meshParts;
89 | std::wstring name;
90 | bool ccw;
91 | bool pmalpha;
92 |
93 | typedef std::vector> Collection;
94 |
95 | // Setup states for drawing mesh
96 | void __cdecl PrepareForRendering(_In_ ID3D11DeviceContext* deviceContext, const CommonStates& states, bool alpha = false, bool wireframe = false) const;
97 |
98 | // Draw the mesh
99 | void XM_CALLCONV Draw(_In_ ID3D11DeviceContext* deviceContext, FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection,
100 | bool alpha = false, _In_opt_ std::function setCustomState = nullptr) const;
101 | };
102 |
103 |
104 | //----------------------------------------------------------------------------------
105 | // A model consists of one or more meshes
106 | class Model
107 | {
108 | public:
109 | virtual ~Model();
110 |
111 | ModelMesh::Collection meshes;
112 | std::wstring name;
113 |
114 | // Draw all the meshes in the model
115 | void XM_CALLCONV Draw(_In_ ID3D11DeviceContext* deviceContext, const CommonStates& states, FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection,
116 | bool wireframe = false, _In_opt_ std::function setCustomState = nullptr) const;
117 |
118 | // Notify model that effects, parts list, or mesh list has changed
119 | void __cdecl Modified() { mEffectCache.clear(); }
120 |
121 | // Update all effects used by the model
122 | void __cdecl UpdateEffects(_In_ std::function setEffect);
123 |
124 | // Loads a model from a Visual Studio Starter Kit .CMO file
125 | static std::unique_ptr __cdecl CreateFromCMO(_In_ ID3D11Device* d3dDevice, _In_reads_bytes_(dataSize) const uint8_t* meshData, size_t dataSize,
126 | _In_ IEffectFactory& fxFactory, bool ccw = true, bool pmalpha = false);
127 | static std::unique_ptr __cdecl CreateFromCMO(_In_ ID3D11Device* d3dDevice, _In_z_ const wchar_t* szFileName,
128 | _In_ IEffectFactory& fxFactory, bool ccw = true, bool pmalpha = false);
129 |
130 | // Loads a model from a DirectX SDK .SDKMESH file
131 | static std::unique_ptr __cdecl CreateFromSDKMESH(_In_ ID3D11Device* d3dDevice, _In_reads_bytes_(dataSize) const uint8_t* meshData, _In_ size_t dataSize,
132 | _In_ IEffectFactory& fxFactory, bool ccw = false, bool pmalpha = false);
133 | static std::unique_ptr __cdecl CreateFromSDKMESH(_In_ ID3D11Device* d3dDevice, _In_z_ const wchar_t* szFileName,
134 | _In_ IEffectFactory& fxFactory, bool ccw = false, bool pmalpha = false);
135 |
136 | // Loads a model from a .VBO file
137 | static std::unique_ptr __cdecl CreateFromVBO(_In_ ID3D11Device* d3dDevice, _In_reads_bytes_(dataSize) const uint8_t* meshData, _In_ size_t dataSize,
138 | _In_opt_ std::shared_ptr ieffect = nullptr, bool ccw = false, bool pmalpha = false);
139 | static std::unique_ptr __cdecl CreateFromVBO(_In_ ID3D11Device* d3dDevice, _In_z_ const wchar_t* szFileName,
140 | _In_opt_ std::shared_ptr ieffect = nullptr, bool ccw = false, bool pmalpha = false);
141 |
142 | private:
143 | std::set mEffectCache;
144 | };
145 | }
146 |
--------------------------------------------------------------------------------
/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017/Includes/Mouse.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: Mouse.h
3 | //
4 | // Copyright (c) Microsoft Corporation. All rights reserved.
5 | // Licensed under the MIT License.
6 | //
7 | // http://go.microsoft.com/fwlink/?LinkId=248929
8 | // http://go.microsoft.com/fwlink/?LinkID=615561
9 | //--------------------------------------------------------------------------------------
10 |
11 | #pragma once
12 |
13 | #include
14 |
15 | #if (defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)) || (defined(_XBOX_ONE) && defined(_TITLE) && (_XDK_VER >= 0x42D907D1))
16 | namespace ABI { namespace Windows { namespace UI { namespace Core { struct ICoreWindow; } } } }
17 | #endif
18 |
19 |
20 | namespace DirectX
21 | {
22 | class Mouse
23 | {
24 | public:
25 | Mouse() noexcept(false);
26 | Mouse(Mouse&& moveFrom) noexcept;
27 | Mouse& operator= (Mouse&& moveFrom) noexcept;
28 |
29 | Mouse(Mouse const&) = delete;
30 | Mouse& operator=(Mouse const&) = delete;
31 |
32 | virtual ~Mouse();
33 |
34 | enum Mode
35 | {
36 | MODE_ABSOLUTE = 0,
37 | MODE_RELATIVE,
38 | };
39 |
40 | struct State
41 | {
42 | bool leftButton;
43 | bool middleButton;
44 | bool rightButton;
45 | bool xButton1;
46 | bool xButton2;
47 | int x;
48 | int y;
49 | int scrollWheelValue;
50 | Mode positionMode;
51 | };
52 |
53 | class ButtonStateTracker
54 | {
55 | public:
56 | enum ButtonState
57 | {
58 | UP = 0, // Button is up
59 | HELD = 1, // Button is held down
60 | RELEASED = 2, // Button was just released
61 | PRESSED = 3, // Buton was just pressed
62 | };
63 |
64 | ButtonState leftButton;
65 | ButtonState middleButton;
66 | ButtonState rightButton;
67 | ButtonState xButton1;
68 | ButtonState xButton2;
69 |
70 | #pragma prefast(suppress: 26495, "Reset() performs the initialization")
71 | ButtonStateTracker() noexcept { Reset(); }
72 |
73 | void __cdecl Update(const State& state);
74 |
75 | void __cdecl Reset() noexcept;
76 |
77 | State __cdecl GetLastState() const { return lastState; }
78 |
79 | private:
80 | State lastState;
81 | };
82 |
83 | // Retrieve the current state of the mouse
84 | State __cdecl GetState() const;
85 |
86 | // Resets the accumulated scroll wheel value
87 | void __cdecl ResetScrollWheelValue();
88 |
89 | // Sets mouse mode (defaults to absolute)
90 | void __cdecl SetMode(Mode mode);
91 |
92 | // Feature detection
93 | bool __cdecl IsConnected() const;
94 |
95 | // Cursor visibility
96 | bool __cdecl IsVisible() const;
97 | void __cdecl SetVisible(bool visible);
98 |
99 | #if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP) && defined(WM_USER)
100 | void __cdecl SetWindow(HWND window);
101 | static void __cdecl ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam);
102 | #endif
103 |
104 | #if (defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)) || (defined(_XBOX_ONE) && defined(_TITLE) && (_XDK_VER >= 0x42D907D1))
105 | void __cdecl SetWindow(ABI::Windows::UI::Core::ICoreWindow* window);
106 | #ifdef __cplusplus_winrt
107 | void __cdecl SetWindow(Windows::UI::Core::CoreWindow^ window)
108 | {
109 | // See https://msdn.microsoft.com/en-us/library/hh755802.aspx
110 | SetWindow(reinterpret_cast(window));
111 | }
112 | #endif
113 | static void __cdecl SetDpi(float dpi);
114 | #endif
115 |
116 | // Singleton
117 | static Mouse& __cdecl Get();
118 |
119 | private:
120 | // Private implementation.
121 | class Impl;
122 |
123 | std::unique_ptr pImpl;
124 | };
125 | }
126 |
--------------------------------------------------------------------------------
/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017/Includes/PostProcess.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: PostProcess.h
3 | //
4 | // Copyright (c) Microsoft Corporation. All rights reserved.
5 | // Licensed under the MIT License.
6 | //
7 | // http://go.microsoft.com/fwlink/?LinkId=248929
8 | //--------------------------------------------------------------------------------------
9 |
10 | #pragma once
11 |
12 | #if defined(_XBOX_ONE) && defined(_TITLE)
13 | #include
14 | #else
15 | #include
16 | #endif
17 |
18 | #include
19 | #include
20 | #include
21 |
22 |
23 | namespace DirectX
24 | {
25 | //----------------------------------------------------------------------------------
26 | // Abstract interface representing a post-process pass
27 | class IPostProcess
28 | {
29 | public:
30 | virtual ~IPostProcess() = default;
31 |
32 | IPostProcess(const IPostProcess&) = delete;
33 | IPostProcess& operator=(const IPostProcess&) = delete;
34 |
35 | IPostProcess(IPostProcess&&) = delete;
36 | IPostProcess& operator=(IPostProcess&&) = delete;
37 |
38 | virtual void __cdecl Process(_In_ ID3D11DeviceContext* deviceContext, _In_opt_ std::function setCustomState = nullptr) = 0;
39 |
40 | protected:
41 | IPostProcess() = default;
42 | };
43 |
44 |
45 | //----------------------------------------------------------------------------------
46 | // Basic post-process
47 | class BasicPostProcess : public IPostProcess
48 | {
49 | public:
50 | enum Effect
51 | {
52 | Copy,
53 | Monochrome,
54 | Sepia,
55 | DownScale_2x2,
56 | DownScale_4x4,
57 | GaussianBlur_5x5,
58 | BloomExtract,
59 | BloomBlur,
60 | Effect_Max
61 | };
62 |
63 | explicit BasicPostProcess(_In_ ID3D11Device* device);
64 | BasicPostProcess(BasicPostProcess&& moveFrom) noexcept;
65 | BasicPostProcess& operator= (BasicPostProcess&& moveFrom) noexcept;
66 |
67 | BasicPostProcess(BasicPostProcess const&) = delete;
68 | BasicPostProcess& operator= (BasicPostProcess const&) = delete;
69 |
70 | virtual ~BasicPostProcess() override;
71 |
72 | // IPostProcess methods.
73 | void __cdecl Process(_In_ ID3D11DeviceContext* deviceContext, _In_opt_ std::function setCustomState = nullptr) override;
74 |
75 | // Shader control
76 | void __cdecl SetEffect(Effect fx);
77 |
78 | // Properties
79 | void __cdecl SetSourceTexture(_In_opt_ ID3D11ShaderResourceView* value);
80 |
81 | // Sets multiplier for GaussianBlur_5x5
82 | void __cdecl SetGaussianParameter(float multiplier);
83 |
84 | // Sets parameters for BloomExtract
85 | void __cdecl SetBloomExtractParameter(float threshold);
86 |
87 | // Sets parameters for BloomBlur
88 | void __cdecl SetBloomBlurParameters(bool horizontal, float size, float brightness);
89 |
90 | private:
91 | // Private implementation.
92 | class Impl;
93 |
94 | std::unique_ptr pImpl;
95 | };
96 |
97 |
98 | //----------------------------------------------------------------------------------
99 | // Dual-texure post-process
100 | class DualPostProcess : public IPostProcess
101 | {
102 | public:
103 | enum Effect
104 | {
105 | Merge,
106 | BloomCombine,
107 | Effect_Max
108 | };
109 |
110 | explicit DualPostProcess(_In_ ID3D11Device* device);
111 | DualPostProcess(DualPostProcess&& moveFrom) noexcept;
112 | DualPostProcess& operator= (DualPostProcess&& moveFrom) noexcept;
113 |
114 | DualPostProcess(DualPostProcess const&) = delete;
115 | DualPostProcess& operator= (DualPostProcess const&) = delete;
116 |
117 | virtual ~DualPostProcess() override;
118 |
119 | // IPostProcess methods.
120 | void __cdecl Process(_In_ ID3D11DeviceContext* deviceContext, _In_opt_ std::function setCustomState = nullptr) override;
121 |
122 | // Shader control
123 | void __cdecl SetEffect(Effect fx);
124 |
125 | // Properties
126 | void __cdecl SetSourceTexture(_In_opt_ ID3D11ShaderResourceView* value);
127 | void __cdecl SetSourceTexture2(_In_opt_ ID3D11ShaderResourceView* value);
128 |
129 | // Sets parameters for Merge
130 | void __cdecl SetMergeParameters(float weight1, float weight2);
131 |
132 | // Sets parameters for BloomCombine
133 | void __cdecl SetBloomCombineParameters(float bloom, float base, float bloomSaturation, float baseSaturation);
134 |
135 | private:
136 | // Private implementation.
137 | class Impl;
138 |
139 | std::unique_ptr pImpl;
140 | };
141 |
142 |
143 | //----------------------------------------------------------------------------------
144 | // Tone-map post-process
145 | class ToneMapPostProcess : public IPostProcess
146 | {
147 | public:
148 | enum Operator // Tone-mapping operator
149 | {
150 | None, // Pass-through
151 | Saturate, // Clamp [0,1]
152 | Reinhard, // x/(1+x)
153 | ACESFilmic,
154 | Operator_Max
155 | };
156 |
157 | enum TransferFunction // Electro-Optical Transfer Function (EOTF)
158 | {
159 | Linear, // Pass-through
160 | SRGB, // sRGB (Rec.709 and approximate sRGB display curve)
161 | ST2084, // HDR10 (Rec.2020 color primaries and ST.2084 display curve)
162 | TransferFunction_Max
163 | };
164 |
165 | explicit ToneMapPostProcess(_In_ ID3D11Device* device);
166 | ToneMapPostProcess(ToneMapPostProcess&& moveFrom) noexcept;
167 | ToneMapPostProcess& operator= (ToneMapPostProcess&& moveFrom) noexcept;
168 |
169 | ToneMapPostProcess(ToneMapPostProcess const&) = delete;
170 | ToneMapPostProcess& operator= (ToneMapPostProcess const&) = delete;
171 |
172 | virtual ~ToneMapPostProcess() override;
173 |
174 | // IPostProcess methods.
175 | void __cdecl Process(_In_ ID3D11DeviceContext* deviceContext, _In_opt_ std::function setCustomState = nullptr) override;
176 |
177 | // Shader control
178 | void __cdecl SetOperator(Operator op);
179 |
180 | void __cdecl SetTransferFunction(TransferFunction func);
181 |
182 | #if defined(_XBOX_ONE) && defined(_TITLE)
183 | // Uses Multiple Render Targets to generate both HDR10 and GameDVR SDR signals
184 | void __cdecl SetMRTOutput(bool value = true);
185 | #endif
186 |
187 | // Properties
188 | void __cdecl SetHDRSourceTexture(_In_opt_ ID3D11ShaderResourceView* value);
189 |
190 | // Sets exposure value for LDR tonemap operators
191 | void SetExposure(float exposureValue);
192 |
193 | // Sets ST.2084 parameter for how bright white should be in nits
194 | void SetST2084Parameter(float paperWhiteNits);
195 |
196 | private:
197 | // Private implementation.
198 | class Impl;
199 |
200 | std::unique_ptr pImpl;
201 | };
202 | }
203 |
--------------------------------------------------------------------------------
/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017/Includes/PrimitiveBatch.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: PrimitiveBatch.h
3 | //
4 | // Copyright (c) Microsoft Corporation. All rights reserved.
5 | // Licensed under the MIT License.
6 | //
7 | // http://go.microsoft.com/fwlink/?LinkId=248929
8 | //--------------------------------------------------------------------------------------
9 |
10 | #pragma once
11 |
12 | #if defined(_XBOX_ONE) && defined(_TITLE)
13 | #include
14 | #else
15 | #include
16 | #endif
17 |
18 | #include
19 | #include
20 | #include
21 |
22 |
23 | namespace DirectX
24 | {
25 | namespace Internal
26 | {
27 | // Base class, not to be used directly: clients should access this via the derived PrimitiveBatch.
28 | class PrimitiveBatchBase
29 | {
30 | protected:
31 | PrimitiveBatchBase(_In_ ID3D11DeviceContext* deviceContext, size_t maxIndices, size_t maxVertices, size_t vertexSize);
32 | PrimitiveBatchBase(PrimitiveBatchBase&& moveFrom) noexcept;
33 | PrimitiveBatchBase& operator= (PrimitiveBatchBase&& moveFrom) noexcept;
34 |
35 | PrimitiveBatchBase(PrimitiveBatchBase const&) = delete;
36 | PrimitiveBatchBase& operator= (PrimitiveBatchBase const&) = delete;
37 |
38 | virtual ~PrimitiveBatchBase();
39 |
40 | public:
41 | // Begin/End a batch of primitive drawing operations.
42 | void __cdecl Begin();
43 | void __cdecl End();
44 |
45 | protected:
46 | // Internal, untyped drawing method.
47 | void __cdecl Draw(D3D11_PRIMITIVE_TOPOLOGY topology, bool isIndexed, _In_opt_count_(indexCount) uint16_t const* indices, size_t indexCount, size_t vertexCount, _Out_ void** pMappedVertices);
48 |
49 | private:
50 | // Private implementation.
51 | class Impl;
52 |
53 | std::unique_ptr pImpl;
54 | };
55 | }
56 |
57 |
58 | // Template makes the API typesafe, eg. PrimitiveBatch.
59 | template
60 | class PrimitiveBatch : public Internal::PrimitiveBatchBase
61 | {
62 | static const size_t DefaultBatchSize = 2048;
63 |
64 | public:
65 | explicit PrimitiveBatch(_In_ ID3D11DeviceContext* deviceContext, size_t maxIndices = DefaultBatchSize * 3, size_t maxVertices = DefaultBatchSize)
66 | : PrimitiveBatchBase(deviceContext, maxIndices, maxVertices, sizeof(TVertex))
67 | { }
68 |
69 | PrimitiveBatch(PrimitiveBatch&& moveFrom) noexcept
70 | : PrimitiveBatchBase(std::move(moveFrom))
71 | { }
72 |
73 | PrimitiveBatch& operator= (PrimitiveBatch&& moveFrom) noexcept
74 | {
75 | PrimitiveBatchBase::operator=(std::move(moveFrom));
76 | return *this;
77 | }
78 |
79 |
80 | // Similar to the D3D9 API DrawPrimitiveUP.
81 | void Draw(D3D11_PRIMITIVE_TOPOLOGY topology, _In_reads_(vertexCount) TVertex const* vertices, size_t vertexCount)
82 | {
83 | void* mappedVertices;
84 |
85 | PrimitiveBatchBase::Draw(topology, false, nullptr, 0, vertexCount, &mappedVertices);
86 |
87 | memcpy(mappedVertices, vertices, vertexCount * sizeof(TVertex));
88 | }
89 |
90 |
91 | // Similar to the D3D9 API DrawIndexedPrimitiveUP.
92 | void DrawIndexed(D3D11_PRIMITIVE_TOPOLOGY topology, _In_reads_(indexCount) uint16_t const* indices, size_t indexCount, _In_reads_(vertexCount) TVertex const* vertices, size_t vertexCount)
93 | {
94 | void* mappedVertices;
95 |
96 | PrimitiveBatchBase::Draw(topology, true, indices, indexCount, vertexCount, &mappedVertices);
97 |
98 | memcpy(mappedVertices, vertices, vertexCount * sizeof(TVertex));
99 | }
100 |
101 |
102 | void DrawLine(TVertex const& v1, TVertex const& v2)
103 | {
104 | TVertex* mappedVertices;
105 |
106 | PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_LINELIST, false, nullptr, 0, 2, reinterpret_cast(&mappedVertices));
107 |
108 | mappedVertices[0] = v1;
109 | mappedVertices[1] = v2;
110 | }
111 |
112 |
113 | void DrawTriangle(TVertex const& v1, TVertex const& v2, TVertex const& v3)
114 | {
115 | TVertex* mappedVertices;
116 |
117 | PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, false, nullptr, 0, 3, reinterpret_cast(&mappedVertices));
118 |
119 | mappedVertices[0] = v1;
120 | mappedVertices[1] = v2;
121 | mappedVertices[2] = v3;
122 | }
123 |
124 |
125 | void DrawQuad(TVertex const& v1, TVertex const& v2, TVertex const& v3, TVertex const& v4)
126 | {
127 | static const uint16_t quadIndices[] = { 0, 1, 2, 0, 2, 3 };
128 |
129 | TVertex* mappedVertices;
130 |
131 | PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, true, quadIndices, 6, 4, reinterpret_cast(&mappedVertices));
132 |
133 | mappedVertices[0] = v1;
134 | mappedVertices[1] = v2;
135 | mappedVertices[2] = v3;
136 | mappedVertices[3] = v4;
137 | }
138 | };
139 | }
140 |
--------------------------------------------------------------------------------
/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017/Includes/ScreenGrab.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: ScreenGrab.h
3 | //
4 | // Function for capturing a 2D texture and saving it to a file (aka a 'screenshot'
5 | // when used on a Direct3D Render Target).
6 | //
7 | // Note these functions are useful as a light-weight runtime screen grabber. For
8 | // full-featured texture capture, DDS writer, and texture processing pipeline,
9 | // see the 'Texconv' sample and the 'DirectXTex' library.
10 | //
11 | // Copyright (c) Microsoft Corporation. All rights reserved.
12 | // Licensed under the MIT License.
13 | //
14 | // http://go.microsoft.com/fwlink/?LinkId=248926
15 | // http://go.microsoft.com/fwlink/?LinkId=248929
16 | //--------------------------------------------------------------------------------------
17 |
18 | #pragma once
19 |
20 | #if defined(_XBOX_ONE) && defined(_TITLE)
21 | #include
22 | #else
23 | #include
24 | #endif
25 |
26 | #include
27 |
28 | #include
29 | #include
30 |
31 |
32 | namespace DirectX
33 | {
34 | HRESULT __cdecl SaveDDSTextureToFile(
35 | _In_ ID3D11DeviceContext* pContext,
36 | _In_ ID3D11Resource* pSource,
37 | _In_z_ const wchar_t* fileName);
38 |
39 | HRESULT __cdecl SaveWICTextureToFile(
40 | _In_ ID3D11DeviceContext* pContext,
41 | _In_ ID3D11Resource* pSource,
42 | _In_ REFGUID guidContainerFormat,
43 | _In_z_ const wchar_t* fileName,
44 | _In_opt_ const GUID* targetFormat = nullptr,
45 | _In_opt_ std::function setCustomProps = nullptr);
46 | }
47 |
--------------------------------------------------------------------------------
/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017/Includes/SpriteBatch.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: SpriteBatch.h
3 | //
4 | // Copyright (c) Microsoft Corporation. All rights reserved.
5 | // Licensed under the MIT License.
6 | //
7 | // http://go.microsoft.com/fwlink/?LinkId=248929
8 | //--------------------------------------------------------------------------------------
9 |
10 | #pragma once
11 |
12 | #if defined(_XBOX_ONE) && defined(_TITLE)
13 | #include
14 | #else
15 | #include
16 | #endif
17 |
18 | #include
19 | #include
20 | #include
21 | #include
22 |
23 |
24 | namespace DirectX
25 | {
26 | enum SpriteSortMode
27 | {
28 | SpriteSortMode_Deferred,
29 | SpriteSortMode_Immediate,
30 | SpriteSortMode_Texture,
31 | SpriteSortMode_BackToFront,
32 | SpriteSortMode_FrontToBack,
33 | };
34 |
35 |
36 | enum SpriteEffects
37 | {
38 | SpriteEffects_None = 0,
39 | SpriteEffects_FlipHorizontally = 1,
40 | SpriteEffects_FlipVertically = 2,
41 | SpriteEffects_FlipBoth = SpriteEffects_FlipHorizontally | SpriteEffects_FlipVertically,
42 | };
43 |
44 |
45 | class SpriteBatch
46 | {
47 | public:
48 | explicit SpriteBatch(_In_ ID3D11DeviceContext* deviceContext);
49 | SpriteBatch(SpriteBatch&& moveFrom) noexcept;
50 | SpriteBatch& operator= (SpriteBatch&& moveFrom) noexcept;
51 |
52 | SpriteBatch(SpriteBatch const&) = delete;
53 | SpriteBatch& operator= (SpriteBatch const&) = delete;
54 |
55 | virtual ~SpriteBatch();
56 |
57 | // Begin/End a batch of sprite drawing operations.
58 | void XM_CALLCONV Begin(SpriteSortMode sortMode = SpriteSortMode_Deferred, _In_opt_ ID3D11BlendState* blendState = nullptr, _In_opt_ ID3D11SamplerState* samplerState = nullptr, _In_opt_ ID3D11DepthStencilState* depthStencilState = nullptr, _In_opt_ ID3D11RasterizerState* rasterizerState = nullptr,
59 | _In_opt_ std::function setCustomShaders = nullptr, FXMMATRIX transformMatrix = MatrixIdentity);
60 | void __cdecl End();
61 |
62 | // Draw overloads specifying position, origin and scale as XMFLOAT2.
63 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position, FXMVECTOR color = Colors::White);
64 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0, XMFLOAT2 const& origin = Float2Zero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0);
65 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color, float rotation, XMFLOAT2 const& origin, XMFLOAT2 const& scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0);
66 |
67 | // Draw overloads specifying position, origin and scale via the first two components of an XMVECTOR.
68 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position, FXMVECTOR color = Colors::White);
69 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0, FXMVECTOR origin = g_XMZero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0);
70 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color, float rotation, FXMVECTOR origin, GXMVECTOR scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0);
71 |
72 | // Draw overloads specifying position as a RECT.
73 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, RECT const& destinationRectangle, FXMVECTOR color = Colors::White);
74 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, RECT const& destinationRectangle, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0, XMFLOAT2 const& origin = Float2Zero, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0);
75 |
76 | // Rotation mode to be applied to the sprite transformation
77 | void __cdecl SetRotation(DXGI_MODE_ROTATION mode);
78 | DXGI_MODE_ROTATION __cdecl GetRotation() const;
79 |
80 | // Set viewport for sprite transformation
81 | void __cdecl SetViewport(const D3D11_VIEWPORT& viewPort);
82 |
83 | private:
84 | // Private implementation.
85 | class Impl;
86 |
87 | std::unique_ptr pImpl;
88 |
89 | static const XMMATRIX MatrixIdentity;
90 | static const XMFLOAT2 Float2Zero;
91 | };
92 | }
93 |
--------------------------------------------------------------------------------
/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017/Includes/SpriteFont.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: SpriteFont.h
3 | //
4 | // Copyright (c) Microsoft Corporation. All rights reserved.
5 | // Licensed under the MIT License.
6 | //
7 | // http://go.microsoft.com/fwlink/?LinkId=248929
8 | //--------------------------------------------------------------------------------------
9 |
10 | #pragma once
11 |
12 | #include "SpriteBatch.h"
13 |
14 |
15 | namespace DirectX
16 | {
17 | class SpriteFont
18 | {
19 | public:
20 | struct Glyph;
21 |
22 | SpriteFont(_In_ ID3D11Device* device, _In_z_ wchar_t const* fileName, bool forceSRGB = false);
23 | SpriteFont(_In_ ID3D11Device* device, _In_reads_bytes_(dataSize) uint8_t const* dataBlob, _In_ size_t dataSize, bool forceSRGB = false);
24 | SpriteFont(_In_ ID3D11ShaderResourceView* texture, _In_reads_(glyphCount) Glyph const* glyphs, _In_ size_t glyphCount, _In_ float lineSpacing);
25 |
26 | SpriteFont(SpriteFont&& moveFrom) noexcept;
27 | SpriteFont& operator= (SpriteFont&& moveFrom) noexcept;
28 |
29 | SpriteFont(SpriteFont const&) = delete;
30 | SpriteFont& operator= (SpriteFont const&) = delete;
31 |
32 | virtual ~SpriteFont();
33 |
34 | void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, XMFLOAT2 const& position, FXMVECTOR color = Colors::White, float rotation = 0, XMFLOAT2 const& origin = Float2Zero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const;
35 | void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, XMFLOAT2 const& position, FXMVECTOR color, float rotation, XMFLOAT2 const& origin, XMFLOAT2 const& scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const;
36 | void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, FXMVECTOR position, FXMVECTOR color = Colors::White, float rotation = 0, FXMVECTOR origin = g_XMZero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const;
37 | void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, FXMVECTOR position, FXMVECTOR color, float rotation, FXMVECTOR origin, GXMVECTOR scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const;
38 |
39 | XMVECTOR XM_CALLCONV MeasureString(_In_z_ wchar_t const* text) const;
40 |
41 | RECT __cdecl MeasureDrawBounds(_In_z_ wchar_t const* text, XMFLOAT2 const& position) const;
42 | RECT XM_CALLCONV MeasureDrawBounds(_In_z_ wchar_t const* text, FXMVECTOR position) const;
43 |
44 | // Spacing properties
45 | float __cdecl GetLineSpacing() const;
46 | void __cdecl SetLineSpacing(float spacing);
47 |
48 | // Font properties
49 | wchar_t __cdecl GetDefaultCharacter() const;
50 | void __cdecl SetDefaultCharacter(wchar_t character);
51 |
52 | bool __cdecl ContainsCharacter(wchar_t character) const;
53 |
54 | // Custom layout/rendering
55 | Glyph const* __cdecl FindGlyph(wchar_t character) const;
56 | void __cdecl GetSpriteSheet(ID3D11ShaderResourceView** texture) const;
57 |
58 | // Describes a single character glyph.
59 | struct Glyph
60 | {
61 | uint32_t Character;
62 | RECT Subrect;
63 | float XOffset;
64 | float YOffset;
65 | float XAdvance;
66 | };
67 |
68 |
69 | private:
70 | // Private implementation.
71 | class Impl;
72 |
73 | std::unique_ptr pImpl;
74 |
75 | static const XMFLOAT2 Float2Zero;
76 | };
77 | }
78 |
--------------------------------------------------------------------------------
/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017/Includes/VertexTypes.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: VertexTypes.h
3 | //
4 | // Copyright (c) Microsoft Corporation. All rights reserved.
5 | // Licensed under the MIT License.
6 | //
7 | // http://go.microsoft.com/fwlink/?LinkId=248929
8 | //--------------------------------------------------------------------------------------
9 |
10 | #pragma once
11 |
12 | #if defined(_XBOX_ONE) && defined(_TITLE)
13 | #include
14 | #else
15 | #include
16 | #endif
17 |
18 | #include
19 |
20 |
21 | namespace DirectX
22 | {
23 | // Vertex struct holding position information.
24 | struct VertexPosition
25 | {
26 | VertexPosition() = default;
27 |
28 | VertexPosition(const VertexPosition&) = default;
29 | VertexPosition& operator=(const VertexPosition&) = default;
30 |
31 | VertexPosition(VertexPosition&&) = default;
32 | VertexPosition& operator=(VertexPosition&&) = default;
33 |
34 | VertexPosition(XMFLOAT3 const& position)
35 | : position(position)
36 | { }
37 |
38 | VertexPosition(FXMVECTOR position)
39 | {
40 | XMStoreFloat3(&this->position, position);
41 | }
42 |
43 | XMFLOAT3 position;
44 |
45 | static const int InputElementCount = 1;
46 | static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
47 | };
48 |
49 |
50 | // Vertex struct holding position and color information.
51 | struct VertexPositionColor
52 | {
53 | VertexPositionColor() = default;
54 |
55 | VertexPositionColor(const VertexPositionColor&) = default;
56 | VertexPositionColor& operator=(const VertexPositionColor&) = default;
57 |
58 | VertexPositionColor(VertexPositionColor&&) = default;
59 | VertexPositionColor& operator=(VertexPositionColor&&) = default;
60 |
61 | VertexPositionColor(XMFLOAT3 const& position, XMFLOAT4 const& color)
62 | : position(position),
63 | color(color)
64 | { }
65 |
66 | VertexPositionColor(FXMVECTOR position, FXMVECTOR color)
67 | {
68 | XMStoreFloat3(&this->position, position);
69 | XMStoreFloat4(&this->color, color);
70 | }
71 |
72 | XMFLOAT3 position;
73 | XMFLOAT4 color;
74 |
75 | static const int InputElementCount = 2;
76 | static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
77 | };
78 |
79 |
80 | // Vertex struct holding position and texture mapping information.
81 | struct VertexPositionTexture
82 | {
83 | VertexPositionTexture() = default;
84 |
85 | VertexPositionTexture(const VertexPositionTexture&) = default;
86 | VertexPositionTexture& operator=(const VertexPositionTexture&) = default;
87 |
88 | VertexPositionTexture(VertexPositionTexture&&) = default;
89 | VertexPositionTexture& operator=(VertexPositionTexture&&) = default;
90 |
91 | VertexPositionTexture(XMFLOAT3 const& position, XMFLOAT2 const& textureCoordinate)
92 | : position(position),
93 | textureCoordinate(textureCoordinate)
94 | { }
95 |
96 | VertexPositionTexture(FXMVECTOR position, FXMVECTOR textureCoordinate)
97 | {
98 | XMStoreFloat3(&this->position, position);
99 | XMStoreFloat2(&this->textureCoordinate, textureCoordinate);
100 | }
101 |
102 | XMFLOAT3 position;
103 | XMFLOAT2 textureCoordinate;
104 |
105 | static const int InputElementCount = 2;
106 | static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
107 | };
108 |
109 |
110 | // Vertex struct holding position and dual texture mapping information.
111 | struct VertexPositionDualTexture
112 | {
113 | VertexPositionDualTexture() = default;
114 |
115 | VertexPositionDualTexture(const VertexPositionDualTexture&) = default;
116 | VertexPositionDualTexture& operator=(const VertexPositionDualTexture&) = default;
117 |
118 | VertexPositionDualTexture(VertexPositionDualTexture&&) = default;
119 | VertexPositionDualTexture& operator=(VertexPositionDualTexture&&) = default;
120 |
121 | VertexPositionDualTexture(XMFLOAT3 const& position, XMFLOAT2 const& textureCoordinate0, XMFLOAT2 const& textureCoordinate1)
122 | : position(position),
123 | textureCoordinate0(textureCoordinate0),
124 | textureCoordinate1(textureCoordinate1)
125 | { }
126 |
127 | VertexPositionDualTexture(FXMVECTOR position,
128 | FXMVECTOR textureCoordinate0,
129 | FXMVECTOR textureCoordinate1)
130 | {
131 | XMStoreFloat3(&this->position, position);
132 | XMStoreFloat2(&this->textureCoordinate0, textureCoordinate0);
133 | XMStoreFloat2(&this->textureCoordinate1, textureCoordinate1);
134 | }
135 |
136 | XMFLOAT3 position;
137 | XMFLOAT2 textureCoordinate0;
138 | XMFLOAT2 textureCoordinate1;
139 |
140 | static const int InputElementCount = 3;
141 | static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
142 | };
143 |
144 |
145 | // Vertex struct holding position and normal vector.
146 | struct VertexPositionNormal
147 | {
148 | VertexPositionNormal() = default;
149 |
150 | VertexPositionNormal(const VertexPositionNormal&) = default;
151 | VertexPositionNormal& operator=(const VertexPositionNormal&) = default;
152 |
153 | VertexPositionNormal(VertexPositionNormal&&) = default;
154 | VertexPositionNormal& operator=(VertexPositionNormal&&) = default;
155 |
156 | VertexPositionNormal(XMFLOAT3 const& position, XMFLOAT3 const& normal)
157 | : position(position),
158 | normal(normal)
159 | { }
160 |
161 | VertexPositionNormal(FXMVECTOR position, FXMVECTOR normal)
162 | {
163 | XMStoreFloat3(&this->position, position);
164 | XMStoreFloat3(&this->normal, normal);
165 | }
166 |
167 | XMFLOAT3 position;
168 | XMFLOAT3 normal;
169 |
170 | static const int InputElementCount = 2;
171 | static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
172 | };
173 |
174 |
175 | // Vertex struct holding position, color, and texture mapping information.
176 | struct VertexPositionColorTexture
177 | {
178 | VertexPositionColorTexture() = default;
179 |
180 | VertexPositionColorTexture(const VertexPositionColorTexture&) = default;
181 | VertexPositionColorTexture& operator=(const VertexPositionColorTexture&) = default;
182 |
183 | VertexPositionColorTexture(VertexPositionColorTexture&&) = default;
184 | VertexPositionColorTexture& operator=(VertexPositionColorTexture&&) = default;
185 |
186 | VertexPositionColorTexture(XMFLOAT3 const& position, XMFLOAT4 const& color, XMFLOAT2 const& textureCoordinate)
187 | : position(position),
188 | color(color),
189 | textureCoordinate(textureCoordinate)
190 | { }
191 |
192 | VertexPositionColorTexture(FXMVECTOR position, FXMVECTOR color, FXMVECTOR textureCoordinate)
193 | {
194 | XMStoreFloat3(&this->position, position);
195 | XMStoreFloat4(&this->color, color);
196 | XMStoreFloat2(&this->textureCoordinate, textureCoordinate);
197 | }
198 |
199 | XMFLOAT3 position;
200 | XMFLOAT4 color;
201 | XMFLOAT2 textureCoordinate;
202 |
203 | static const int InputElementCount = 3;
204 | static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
205 | };
206 |
207 |
208 | // Vertex struct holding position, normal vector, and color information.
209 | struct VertexPositionNormalColor
210 | {
211 | VertexPositionNormalColor() = default;
212 |
213 | VertexPositionNormalColor(const VertexPositionNormalColor&) = default;
214 | VertexPositionNormalColor& operator=(const VertexPositionNormalColor&) = default;
215 |
216 | VertexPositionNormalColor(VertexPositionNormalColor&&) = default;
217 | VertexPositionNormalColor& operator=(VertexPositionNormalColor&&) = default;
218 |
219 | VertexPositionNormalColor(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& color)
220 | : position(position),
221 | normal(normal),
222 | color(color)
223 | { }
224 |
225 | VertexPositionNormalColor(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR color)
226 | {
227 | XMStoreFloat3(&this->position, position);
228 | XMStoreFloat3(&this->normal, normal);
229 | XMStoreFloat4(&this->color, color);
230 | }
231 |
232 | XMFLOAT3 position;
233 | XMFLOAT3 normal;
234 | XMFLOAT4 color;
235 |
236 | static const int InputElementCount = 3;
237 | static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
238 | };
239 |
240 |
241 | // Vertex struct holding position, normal vector, and texture mapping information.
242 | struct VertexPositionNormalTexture
243 | {
244 | VertexPositionNormalTexture() = default;
245 |
246 | VertexPositionNormalTexture(const VertexPositionNormalTexture&) = default;
247 | VertexPositionNormalTexture& operator=(const VertexPositionNormalTexture&) = default;
248 |
249 | VertexPositionNormalTexture(VertexPositionNormalTexture&&) = default;
250 | VertexPositionNormalTexture& operator=(VertexPositionNormalTexture&&) = default;
251 |
252 | VertexPositionNormalTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT2 const& textureCoordinate)
253 | : position(position),
254 | normal(normal),
255 | textureCoordinate(textureCoordinate)
256 | { }
257 |
258 | VertexPositionNormalTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR textureCoordinate)
259 | {
260 | XMStoreFloat3(&this->position, position);
261 | XMStoreFloat3(&this->normal, normal);
262 | XMStoreFloat2(&this->textureCoordinate, textureCoordinate);
263 | }
264 |
265 | XMFLOAT3 position;
266 | XMFLOAT3 normal;
267 | XMFLOAT2 textureCoordinate;
268 |
269 | static const int InputElementCount = 3;
270 | static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
271 | };
272 |
273 |
274 | // Vertex struct holding position, normal vector, color, and texture mapping information.
275 | struct VertexPositionNormalColorTexture
276 | {
277 | VertexPositionNormalColorTexture() = default;
278 |
279 | VertexPositionNormalColorTexture(const VertexPositionNormalColorTexture&) = default;
280 | VertexPositionNormalColorTexture& operator=(const VertexPositionNormalColorTexture&) = default;
281 |
282 | VertexPositionNormalColorTexture(VertexPositionNormalColorTexture&&) = default;
283 | VertexPositionNormalColorTexture& operator=(VertexPositionNormalColorTexture&&) = default;
284 |
285 | VertexPositionNormalColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& color, XMFLOAT2 const& textureCoordinate)
286 | : position(position),
287 | normal(normal),
288 | color(color),
289 | textureCoordinate(textureCoordinate)
290 | { }
291 |
292 | VertexPositionNormalColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR color, CXMVECTOR textureCoordinate)
293 | {
294 | XMStoreFloat3(&this->position, position);
295 | XMStoreFloat3(&this->normal, normal);
296 | XMStoreFloat4(&this->color, color);
297 | XMStoreFloat2(&this->textureCoordinate, textureCoordinate);
298 | }
299 |
300 | XMFLOAT3 position;
301 | XMFLOAT3 normal;
302 | XMFLOAT4 color;
303 | XMFLOAT2 textureCoordinate;
304 |
305 | static const int InputElementCount = 4;
306 | static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
307 | };
308 |
309 |
310 | // Vertex struct for Visual Studio Shader Designer (DGSL) holding position, normal,
311 | // tangent, color (RGBA), and texture mapping information
312 | struct VertexPositionNormalTangentColorTexture
313 | {
314 | VertexPositionNormalTangentColorTexture() = default;
315 |
316 | VertexPositionNormalTangentColorTexture(const VertexPositionNormalTangentColorTexture&) = default;
317 | VertexPositionNormalTangentColorTexture& operator=(const VertexPositionNormalTangentColorTexture&) = default;
318 |
319 | VertexPositionNormalTangentColorTexture(VertexPositionNormalTangentColorTexture&&) = default;
320 | VertexPositionNormalTangentColorTexture& operator=(VertexPositionNormalTangentColorTexture&&) = default;
321 |
322 | XMFLOAT3 position;
323 | XMFLOAT3 normal;
324 | XMFLOAT4 tangent;
325 | uint32_t color;
326 | XMFLOAT2 textureCoordinate;
327 |
328 | VertexPositionNormalTangentColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, uint32_t rgba, XMFLOAT2 const& textureCoordinate)
329 | : position(position),
330 | normal(normal),
331 | tangent(tangent),
332 | color(rgba),
333 | textureCoordinate(textureCoordinate)
334 | {
335 | }
336 |
337 | VertexPositionNormalTangentColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, uint32_t rgba, CXMVECTOR textureCoordinate)
338 | : color(rgba)
339 | {
340 | XMStoreFloat3(&this->position, position);
341 | XMStoreFloat3(&this->normal, normal);
342 | XMStoreFloat4(&this->tangent, tangent);
343 | XMStoreFloat2(&this->textureCoordinate, textureCoordinate);
344 | }
345 |
346 | VertexPositionNormalTangentColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, XMFLOAT4 const& color, XMFLOAT2 const& textureCoordinate)
347 | : position(position),
348 | normal(normal),
349 | tangent(tangent),
350 | color{},
351 | textureCoordinate(textureCoordinate)
352 | {
353 | SetColor(color);
354 | }
355 |
356 | VertexPositionNormalTangentColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, CXMVECTOR color, CXMVECTOR textureCoordinate) :
357 | color{}
358 | {
359 | XMStoreFloat3(&this->position, position);
360 | XMStoreFloat3(&this->normal, normal);
361 | XMStoreFloat4(&this->tangent, tangent);
362 | XMStoreFloat2(&this->textureCoordinate, textureCoordinate);
363 |
364 | SetColor(color);
365 | }
366 |
367 | void __cdecl SetColor(XMFLOAT4 const& icolor) { SetColor(XMLoadFloat4(&icolor)); }
368 | void XM_CALLCONV SetColor(FXMVECTOR icolor);
369 |
370 | static const int InputElementCount = 5;
371 | static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
372 | };
373 |
374 |
375 | // Vertex struct for Visual Studio Shader Designer (DGSL) holding position, normal,
376 | // tangent, color (RGBA), texture mapping information, and skinning weights
377 | struct VertexPositionNormalTangentColorTextureSkinning : public VertexPositionNormalTangentColorTexture
378 | {
379 | VertexPositionNormalTangentColorTextureSkinning() = default;
380 |
381 | VertexPositionNormalTangentColorTextureSkinning(const VertexPositionNormalTangentColorTextureSkinning&) = default;
382 | VertexPositionNormalTangentColorTextureSkinning& operator=(const VertexPositionNormalTangentColorTextureSkinning&) = default;
383 |
384 | VertexPositionNormalTangentColorTextureSkinning(VertexPositionNormalTangentColorTextureSkinning&&) = default;
385 | VertexPositionNormalTangentColorTextureSkinning& operator=(VertexPositionNormalTangentColorTextureSkinning&&) = default;
386 |
387 | uint32_t indices;
388 | uint32_t weights;
389 |
390 | VertexPositionNormalTangentColorTextureSkinning(
391 | XMFLOAT3 const& position,
392 | XMFLOAT3 const& normal,
393 | XMFLOAT4 const& tangent,
394 | uint32_t rgba,
395 | XMFLOAT2 const& textureCoordinate,
396 | XMUINT4 const& indices,
397 | XMFLOAT4 const& weights)
398 | : VertexPositionNormalTangentColorTexture(position, normal, tangent, rgba, textureCoordinate),
399 | indices{},
400 | weights{}
401 | {
402 | SetBlendIndices(indices);
403 | SetBlendWeights(weights);
404 | }
405 |
406 | VertexPositionNormalTangentColorTextureSkinning(
407 | FXMVECTOR position,
408 | FXMVECTOR normal,
409 | FXMVECTOR tangent,
410 | uint32_t rgba,
411 | CXMVECTOR textureCoordinate,
412 | XMUINT4 const& indices,
413 | CXMVECTOR weights)
414 | : VertexPositionNormalTangentColorTexture(position, normal, tangent, rgba, textureCoordinate),
415 | indices{},
416 | weights{}
417 | {
418 | SetBlendIndices(indices);
419 | SetBlendWeights(weights);
420 | }
421 |
422 | VertexPositionNormalTangentColorTextureSkinning(
423 | XMFLOAT3 const& position,
424 | XMFLOAT3 const& normal,
425 | XMFLOAT4 const& tangent,
426 | XMFLOAT4 const& color,
427 | XMFLOAT2 const& textureCoordinate,
428 | XMUINT4 const& indices,
429 | XMFLOAT4 const& weights)
430 | : VertexPositionNormalTangentColorTexture(position, normal, tangent, color, textureCoordinate),
431 | indices{},
432 | weights{}
433 | {
434 | SetBlendIndices(indices);
435 | SetBlendWeights(weights);
436 | }
437 |
438 | VertexPositionNormalTangentColorTextureSkinning(
439 | FXMVECTOR position,
440 | FXMVECTOR normal,
441 | FXMVECTOR tangent,
442 | CXMVECTOR color,
443 | CXMVECTOR textureCoordinate,
444 | XMUINT4 const& indices,
445 | CXMVECTOR weights)
446 | : VertexPositionNormalTangentColorTexture(position, normal, tangent, color, textureCoordinate),
447 | indices{},
448 | weights{}
449 | {
450 | SetBlendIndices(indices);
451 | SetBlendWeights(weights);
452 | }
453 |
454 | void __cdecl SetBlendIndices(XMUINT4 const& iindices);
455 |
456 | void __cdecl SetBlendWeights(XMFLOAT4 const& iweights) { SetBlendWeights(XMLoadFloat4(&iweights)); }
457 | void XM_CALLCONV SetBlendWeights(FXMVECTOR iweights);
458 |
459 | static const int InputElementCount = 7;
460 | static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
461 | };
462 | }
463 |
--------------------------------------------------------------------------------
/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017/Includes/WICTextureLoader.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: WICTextureLoader.h
3 | //
4 | // Function for loading a WIC image and creating a Direct3D runtime texture for it
5 | // (auto-generating mipmaps if possible)
6 | //
7 | // Note: Assumes application has already called CoInitializeEx
8 | //
9 | // Warning: CreateWICTexture* functions are not thread-safe if given a d3dContext instance for
10 | // auto-gen mipmap support.
11 | //
12 | // Note these functions are useful for images created as simple 2D textures. For
13 | // more complex resources, DDSTextureLoader is an excellent light-weight runtime loader.
14 | // For a full-featured DDS file reader, writer, and texture processing pipeline see
15 | // the 'Texconv' sample and the 'DirectXTex' library.
16 | //
17 | // Copyright (c) Microsoft Corporation. All rights reserved.
18 | // Licensed under the MIT License.
19 | //
20 | // http://go.microsoft.com/fwlink/?LinkId=248926
21 | // http://go.microsoft.com/fwlink/?LinkId=248929
22 | //--------------------------------------------------------------------------------------
23 |
24 | #pragma once
25 |
26 | #if defined(_XBOX_ONE) && defined(_TITLE)
27 | #include
28 | #else
29 | #include
30 | #endif
31 |
32 | #include
33 |
34 |
35 | namespace DirectX
36 | {
37 | enum WIC_LOADER_FLAGS
38 | {
39 | WIC_LOADER_DEFAULT = 0,
40 | WIC_LOADER_FORCE_SRGB = 0x1,
41 | WIC_LOADER_IGNORE_SRGB = 0x2,
42 | };
43 |
44 | // Standard version
45 | HRESULT __cdecl CreateWICTextureFromMemory(
46 | _In_ ID3D11Device* d3dDevice,
47 | _In_reads_bytes_(wicDataSize) const uint8_t* wicData,
48 | _In_ size_t wicDataSize,
49 | _Outptr_opt_ ID3D11Resource** texture,
50 | _Outptr_opt_ ID3D11ShaderResourceView** textureView,
51 | _In_ size_t maxsize = 0);
52 |
53 | HRESULT __cdecl CreateWICTextureFromFile(
54 | _In_ ID3D11Device* d3dDevice,
55 | _In_z_ const wchar_t* szFileName,
56 | _Outptr_opt_ ID3D11Resource** texture,
57 | _Outptr_opt_ ID3D11ShaderResourceView** textureView,
58 | _In_ size_t maxsize = 0);
59 |
60 | // Standard version with optional auto-gen mipmap support
61 | HRESULT __cdecl CreateWICTextureFromMemory(
62 | #if defined(_XBOX_ONE) && defined(_TITLE)
63 | _In_ ID3D11DeviceX* d3dDevice,
64 | _In_opt_ ID3D11DeviceContextX* d3dContext,
65 | #else
66 | _In_ ID3D11Device* d3dDevice,
67 | _In_opt_ ID3D11DeviceContext* d3dContext,
68 | #endif
69 | _In_reads_bytes_(wicDataSize) const uint8_t* wicData,
70 | _In_ size_t wicDataSize,
71 | _Outptr_opt_ ID3D11Resource** texture,
72 | _Outptr_opt_ ID3D11ShaderResourceView** textureView,
73 | _In_ size_t maxsize = 0);
74 |
75 | HRESULT __cdecl CreateWICTextureFromFile(
76 | #if defined(_XBOX_ONE) && defined(_TITLE)
77 | _In_ ID3D11DeviceX* d3dDevice,
78 | _In_opt_ ID3D11DeviceContextX* d3dContext,
79 | #else
80 | _In_ ID3D11Device* d3dDevice,
81 | _In_opt_ ID3D11DeviceContext* d3dContext,
82 | #endif
83 | _In_z_ const wchar_t* szFileName,
84 | _Outptr_opt_ ID3D11Resource** texture,
85 | _Outptr_opt_ ID3D11ShaderResourceView** textureView,
86 | _In_ size_t maxsize = 0);
87 |
88 | // Extended version
89 | HRESULT __cdecl CreateWICTextureFromMemoryEx(
90 | _In_ ID3D11Device* d3dDevice,
91 | _In_reads_bytes_(wicDataSize) const uint8_t* wicData,
92 | _In_ size_t wicDataSize,
93 | _In_ size_t maxsize,
94 | _In_ D3D11_USAGE usage,
95 | _In_ unsigned int bindFlags,
96 | _In_ unsigned int cpuAccessFlags,
97 | _In_ unsigned int miscFlags,
98 | _In_ unsigned int loadFlags,
99 | _Outptr_opt_ ID3D11Resource** texture,
100 | _Outptr_opt_ ID3D11ShaderResourceView** textureView);
101 |
102 | HRESULT __cdecl CreateWICTextureFromFileEx(
103 | _In_ ID3D11Device* d3dDevice,
104 | _In_z_ const wchar_t* szFileName,
105 | _In_ size_t maxsize,
106 | _In_ D3D11_USAGE usage,
107 | _In_ unsigned int bindFlags,
108 | _In_ unsigned int cpuAccessFlags,
109 | _In_ unsigned int miscFlags,
110 | _In_ unsigned int loadFlags,
111 | _Outptr_opt_ ID3D11Resource** texture,
112 | _Outptr_opt_ ID3D11ShaderResourceView** textureView);
113 |
114 | // Extended version with optional auto-gen mipmap support
115 | HRESULT __cdecl CreateWICTextureFromMemoryEx(
116 | #if defined(_XBOX_ONE) && defined(_TITLE)
117 | _In_ ID3D11DeviceX* d3dDevice,
118 | _In_opt_ ID3D11DeviceContextX* d3dContext,
119 | #else
120 | _In_ ID3D11Device* d3dDevice,
121 | _In_opt_ ID3D11DeviceContext* d3dContext,
122 | #endif
123 | _In_reads_bytes_(wicDataSize) const uint8_t* wicData,
124 | _In_ size_t wicDataSize,
125 | _In_ size_t maxsize,
126 | _In_ D3D11_USAGE usage,
127 | _In_ unsigned int bindFlags,
128 | _In_ unsigned int cpuAccessFlags,
129 | _In_ unsigned int miscFlags,
130 | _In_ unsigned int loadFlags,
131 | _Outptr_opt_ ID3D11Resource** texture,
132 | _Outptr_opt_ ID3D11ShaderResourceView** textureView);
133 |
134 | HRESULT __cdecl CreateWICTextureFromFileEx(
135 | #if defined(_XBOX_ONE) && defined(_TITLE)
136 | _In_ ID3D11DeviceX* d3dDevice,
137 | _In_opt_ ID3D11DeviceContextX* d3dContext,
138 | #else
139 | _In_ ID3D11Device* d3dDevice,
140 | _In_opt_ ID3D11DeviceContext* d3dContext,
141 | #endif
142 | _In_z_ const wchar_t* szFileName,
143 | _In_ size_t maxsize,
144 | _In_ D3D11_USAGE usage,
145 | _In_ unsigned int bindFlags,
146 | _In_ unsigned int cpuAccessFlags,
147 | _In_ unsigned int miscFlags,
148 | _In_ unsigned int loadFlags,
149 | _Outptr_opt_ ID3D11Resource** texture,
150 | _Outptr_opt_ ID3D11ShaderResourceView** textureView);
151 | }
152 |
--------------------------------------------------------------------------------
/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017/Includes/XboxDDSTextureLoader.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: XboxDDSTextureLoader.h
3 | //
4 | // Functions for loading a DDS texture using the XBOX extended header and creating a
5 | // Direct3D11.X runtime resource for it via the CreatePlacement APIs
6 | //
7 | // Note these functions will not load standard DDS files. Use the DDSTextureLoader
8 | // module in the DirectXTex package or as part of the DirectXTK library to load
9 | // these files which use standard Direct3D resource creation APIs.
10 | //
11 | // Copyright (c) Microsoft Corporation. All rights reserved.
12 | // Licensed under the MIT License.
13 | //
14 | // http://go.microsoft.com/fwlink/?LinkId=248926
15 | // http://go.microsoft.com/fwlink/?LinkId=248929
16 | //--------------------------------------------------------------------------------------
17 |
18 | #pragma once
19 |
20 | #if !defined(_XBOX_ONE) || !defined(_TITLE)
21 | #error This module only supports Xbox One exclusive apps
22 | #endif
23 |
24 | #include
25 |
26 | #include
27 |
28 | namespace Xbox
29 | {
30 | enum DDS_ALPHA_MODE
31 | {
32 | DDS_ALPHA_MODE_UNKNOWN = 0,
33 | DDS_ALPHA_MODE_STRAIGHT = 1,
34 | DDS_ALPHA_MODE_PREMULTIPLIED = 2,
35 | DDS_ALPHA_MODE_OPAQUE = 3,
36 | DDS_ALPHA_MODE_CUSTOM = 4,
37 | };
38 |
39 | HRESULT __cdecl CreateDDSTextureFromMemory(
40 | _In_ ID3D11DeviceX* d3dDevice,
41 | _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
42 | _In_ size_t ddsDataSize,
43 | _Outptr_opt_ ID3D11Resource** texture,
44 | _Outptr_opt_ ID3D11ShaderResourceView** textureView,
45 | _Outptr_ void** grfxMemory,
46 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr,
47 | _In_ bool forceSRGB = false);
48 |
49 | HRESULT __cdecl CreateDDSTextureFromFile( _In_ ID3D11DeviceX* d3dDevice,
50 | _In_z_ const wchar_t* szFileName,
51 | _Outptr_opt_ ID3D11Resource** texture,
52 | _Outptr_opt_ ID3D11ShaderResourceView** textureView,
53 | _Outptr_ void** grfxMemory,
54 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr,
55 | _In_ bool forceSRGB = false);
56 |
57 | void FreeDDSTextureMemory( _In_opt_ void* grfxMemory );
58 | }
--------------------------------------------------------------------------------
/DirectX 11 Engine VS2017/DirectX 11 Engine VS2017/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #pragma comment(lib,"d3d11.lib")
3 | #pragma comment(lib,"DirectXTK.lib")
4 |
5 | int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
6 | _In_opt_ HINSTANCE hPrevInstance,
7 | _In_ LPWSTR lpCmdLine,
8 | _In_ int nCmdShow)
9 | {
10 | return 0;
11 | }
--------------------------------------------------------------------------------