template project, first version
This commit is contained in:
682
DirectXTK/Inc/Audio.h
Normal file
682
DirectXTK/Inc/Audio.h
Normal file
@@ -0,0 +1,682 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// File: Audio.h
|
||||
//
|
||||
// DirectXTK for Audio header
|
||||
//
|
||||
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
||||
// PARTICULAR PURPOSE.
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248929
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <objbase.h>
|
||||
#include <mmreg.h>
|
||||
#include <audioclient.h>
|
||||
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
#include <xma2defs.h>
|
||||
#pragma comment(lib,"acphal.lib")
|
||||
#endif
|
||||
|
||||
#if defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
||||
#pragma comment(lib,"PhoneAudioSes.lib")
|
||||
#endif
|
||||
|
||||
#ifndef XAUDIO2_HELPER_FUNCTIONS
|
||||
#define XAUDIO2_HELPER_FUNCTIONS
|
||||
#endif
|
||||
|
||||
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1700)
|
||||
#error DirectX Tool Kit for Audio does not support VS 2010 without the DirectX SDK
|
||||
#endif
|
||||
#include <xaudio2.h>
|
||||
#include <xaudio2fx.h>
|
||||
#include <x3daudio.h>
|
||||
#include <xapofx.h>
|
||||
#pragma comment(lib,"xaudio2.lib")
|
||||
#else
|
||||
// Using XAudio 2.7 requires the DirectX SDK
|
||||
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\comdecl.h>
|
||||
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\xaudio2.h>
|
||||
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\xaudio2fx.h>
|
||||
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\xapofx.h>
|
||||
#pragma warning(push)
|
||||
#pragma warning( disable : 4005 )
|
||||
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\x3daudio.h>
|
||||
#pragma warning(pop)
|
||||
#pragma comment(lib,"x3daudio.lib")
|
||||
#pragma comment(lib,"xapofx.lib")
|
||||
#endif
|
||||
|
||||
#include <DirectXMath.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace DirectX
|
||||
{
|
||||
class SoundEffectInstance;
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
struct AudioStatistics
|
||||
{
|
||||
size_t playingOneShots; // Number of one-shot sounds currently playing
|
||||
size_t playingInstances; // Number of sound effect instances currently playing
|
||||
size_t allocatedInstances; // Number of SoundEffectInstance allocated
|
||||
size_t allocatedVoices; // Number of XAudio2 voices allocated (standard, 3D, one-shots, and idle one-shots)
|
||||
size_t allocatedVoices3d; // Number of XAudio2 voices allocated for 3D
|
||||
size_t allocatedVoicesOneShot; // Number of XAudio2 voices allocated for one-shot sounds
|
||||
size_t allocatedVoicesIdle; // Number of XAudio2 voices allocated for one-shot sounds but not currently in use
|
||||
size_t audioBytes; // Total wave data (in bytes) in SoundEffects and in-memory WaveBanks
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
size_t xmaAudioBytes; // Total wave data (in bytes) in SoundEffects and in-memory WaveBanks allocated with ApuAlloc
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
class IVoiceNotify
|
||||
{
|
||||
public:
|
||||
virtual void __cdecl OnBufferEnd() = 0;
|
||||
// Notfication that a voice buffer has finished
|
||||
// Note this is called from XAudio2's worker thread, so it should perform very minimal and thread-safe operations
|
||||
|
||||
virtual void __cdecl OnCriticalError() = 0;
|
||||
// Notification that the audio engine encountered a critical error
|
||||
|
||||
virtual void __cdecl OnReset() = 0;
|
||||
// Notification of an audio engine reset
|
||||
|
||||
virtual void __cdecl OnUpdate() = 0;
|
||||
// Notification of an audio engine per-frame update (opt-in)
|
||||
|
||||
virtual void __cdecl OnDestroyEngine() = 0;
|
||||
// Notification that the audio engine is being destroyed
|
||||
|
||||
virtual void __cdecl OnTrim() = 0;
|
||||
// Notification of a request to trim the voice pool
|
||||
|
||||
virtual void __cdecl GatherStatistics( AudioStatistics& stats ) const = 0;
|
||||
// Contribute to statistics request
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
enum AUDIO_ENGINE_FLAGS
|
||||
{
|
||||
AudioEngine_Default = 0x0,
|
||||
|
||||
AudioEngine_EnvironmentalReverb = 0x1,
|
||||
AudioEngine_ReverbUseFilters = 0x2,
|
||||
AudioEngine_UseMasteringLimiter = 0x4,
|
||||
|
||||
AudioEngine_Debug = 0x10000,
|
||||
AudioEngine_ThrowOnNoAudioHW = 0x20000,
|
||||
AudioEngine_DisableVoiceReuse = 0x40000,
|
||||
};
|
||||
|
||||
inline AUDIO_ENGINE_FLAGS operator|(AUDIO_ENGINE_FLAGS a, AUDIO_ENGINE_FLAGS b) { return static_cast<AUDIO_ENGINE_FLAGS>( static_cast<int>(a) | static_cast<int>(b) ); }
|
||||
|
||||
enum SOUND_EFFECT_INSTANCE_FLAGS
|
||||
{
|
||||
SoundEffectInstance_Default = 0x0,
|
||||
|
||||
SoundEffectInstance_Use3D = 0x1,
|
||||
SoundEffectInstance_ReverbUseFilters = 0x2,
|
||||
SoundEffectInstance_NoSetPitch = 0x4,
|
||||
|
||||
SoundEffectInstance_UseRedirectLFE = 0x10000,
|
||||
};
|
||||
|
||||
inline SOUND_EFFECT_INSTANCE_FLAGS operator|(SOUND_EFFECT_INSTANCE_FLAGS a, SOUND_EFFECT_INSTANCE_FLAGS b) { return static_cast<SOUND_EFFECT_INSTANCE_FLAGS>( static_cast<int>(a) | static_cast<int>(b) ); }
|
||||
|
||||
enum AUDIO_ENGINE_REVERB
|
||||
{
|
||||
Reverb_Off,
|
||||
Reverb_Default,
|
||||
Reverb_Generic,
|
||||
Reverb_Forest,
|
||||
Reverb_PaddedCell,
|
||||
Reverb_Room,
|
||||
Reverb_Bathroom,
|
||||
Reverb_LivingRoom,
|
||||
Reverb_StoneRoom,
|
||||
Reverb_Auditorium,
|
||||
Reverb_ConcertHall,
|
||||
Reverb_Cave,
|
||||
Reverb_Arena,
|
||||
Reverb_Hangar,
|
||||
Reverb_CarpetedHallway,
|
||||
Reverb_Hallway,
|
||||
Reverb_StoneCorridor,
|
||||
Reverb_Alley,
|
||||
Reverb_City,
|
||||
Reverb_Mountains,
|
||||
Reverb_Quarry,
|
||||
Reverb_Plain,
|
||||
Reverb_ParkingLot,
|
||||
Reverb_SewerPipe,
|
||||
Reverb_Underwater,
|
||||
Reverb_SmallRoom,
|
||||
Reverb_MediumRoom,
|
||||
Reverb_LargeRoom,
|
||||
Reverb_MediumHall,
|
||||
Reverb_LargeHall,
|
||||
Reverb_Plate,
|
||||
Reverb_MAX
|
||||
};
|
||||
|
||||
enum SoundState
|
||||
{
|
||||
STOPPED = 0,
|
||||
PLAYING,
|
||||
PAUSED
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
class AudioEngine
|
||||
{
|
||||
public:
|
||||
explicit AudioEngine( AUDIO_ENGINE_FLAGS flags = AudioEngine_Default, _In_opt_ const WAVEFORMATEX* wfx = nullptr, _In_opt_z_ const wchar_t* deviceId = nullptr,
|
||||
AUDIO_STREAM_CATEGORY category = AudioCategory_GameEffects );
|
||||
|
||||
AudioEngine(AudioEngine&& moveFrom);
|
||||
AudioEngine& operator= (AudioEngine&& moveFrom);
|
||||
|
||||
AudioEngine(AudioEngine const&) = delete;
|
||||
AudioEngine& operator= (AudioEngine const&) = delete;
|
||||
|
||||
virtual ~AudioEngine();
|
||||
|
||||
bool __cdecl Update();
|
||||
// Performs per-frame processing for the audio engine, returns false if in 'silent mode'
|
||||
|
||||
bool __cdecl Reset( _In_opt_ const WAVEFORMATEX* wfx = nullptr, _In_opt_z_ const wchar_t* deviceId = nullptr );
|
||||
// Reset audio engine from critical error/silent mode using a new device; can also 'migrate' the graph
|
||||
// Returns true if succesfully reset, false if in 'silent mode' due to no default device
|
||||
// Note: One shots are lost, all SoundEffectInstances are in the STOPPED state after successful reset
|
||||
|
||||
void __cdecl Suspend();
|
||||
void __cdecl Resume();
|
||||
// Suspend/resumes audio processing (i.e. global pause/resume)
|
||||
|
||||
float __cdecl GetMasterVolume() const;
|
||||
void __cdecl SetMasterVolume( float volume );
|
||||
// Master volume property for all sounds
|
||||
|
||||
void __cdecl SetReverb( AUDIO_ENGINE_REVERB reverb );
|
||||
void __cdecl SetReverb( _In_opt_ const XAUDIO2FX_REVERB_PARAMETERS* native );
|
||||
// Sets environmental reverb for 3D positional audio (if active)
|
||||
|
||||
void __cdecl SetMasteringLimit( int release, int loudness );
|
||||
// Sets the mastering volume limiter properties (if active)
|
||||
|
||||
AudioStatistics __cdecl GetStatistics() const;
|
||||
// Gathers audio engine statistics
|
||||
|
||||
WAVEFORMATEXTENSIBLE __cdecl GetOutputFormat() const;
|
||||
// Returns the format consumed by the mastering voice (which is the same as the device output if defaults are used)
|
||||
|
||||
uint32_t __cdecl GetChannelMask() const;
|
||||
// Returns the output channel mask
|
||||
|
||||
int __cdecl GetOutputChannels() const;
|
||||
// Returns the number of output channels
|
||||
|
||||
bool __cdecl IsAudioDevicePresent() const;
|
||||
// Returns true if the audio graph is operating normally, false if in 'silent mode'
|
||||
|
||||
bool __cdecl IsCriticalError() const;
|
||||
// Returns true if the audio graph is halted due to a critical error (which also places the engine into 'silent mode')
|
||||
|
||||
// Voice pool management.
|
||||
void __cdecl SetDefaultSampleRate( int sampleRate );
|
||||
// Sample rate for voices in the reuse pool (defaults to 44100)
|
||||
|
||||
void __cdecl SetMaxVoicePool( size_t maxOneShots, size_t maxInstances );
|
||||
// Maximum number of voices to allocate for one-shots and instances
|
||||
// Note: one-shots over this limit are ignored; too many instance voices throws an exception
|
||||
|
||||
void __cdecl TrimVoicePool();
|
||||
// Releases any currently unused voices
|
||||
|
||||
// Internal-use functions
|
||||
void __cdecl AllocateVoice( _In_ const WAVEFORMATEX* wfx, SOUND_EFFECT_INSTANCE_FLAGS flags, bool oneshot, _Outptr_result_maybenull_ IXAudio2SourceVoice** voice );
|
||||
|
||||
void __cdecl DestroyVoice( _In_ IXAudio2SourceVoice* voice );
|
||||
// Should only be called for instance voices, not one-shots
|
||||
|
||||
void __cdecl RegisterNotify( _In_ IVoiceNotify* notify, bool usesUpdate );
|
||||
void __cdecl UnregisterNotify( _In_ IVoiceNotify* notify, bool usesOneShots, bool usesUpdate );
|
||||
|
||||
// XAudio2 interface access
|
||||
IXAudio2* __cdecl GetInterface() const;
|
||||
IXAudio2MasteringVoice* __cdecl GetMasterVoice() const;
|
||||
IXAudio2SubmixVoice* __cdecl GetReverbVoice() const;
|
||||
X3DAUDIO_HANDLE& __cdecl Get3DHandle() const;
|
||||
|
||||
// Static functions
|
||||
struct RendererDetail
|
||||
{
|
||||
std::wstring deviceId;
|
||||
std::wstring description;
|
||||
};
|
||||
|
||||
static std::vector<RendererDetail> __cdecl GetRendererDetails();
|
||||
// Returns a list of valid audio endpoint devices
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
class WaveBank
|
||||
{
|
||||
public:
|
||||
WaveBank( _In_ AudioEngine* engine, _In_z_ const wchar_t* wbFileName );
|
||||
|
||||
WaveBank(WaveBank&& moveFrom);
|
||||
WaveBank& operator= (WaveBank&& moveFrom);
|
||||
|
||||
WaveBank(WaveBank const&) = delete;
|
||||
WaveBank& operator= (WaveBank const&) = delete;
|
||||
|
||||
virtual ~WaveBank();
|
||||
|
||||
void __cdecl Play( int index );
|
||||
void __cdecl Play( int index, float volume, float pitch, float pan );
|
||||
|
||||
void __cdecl Play( _In_z_ const char* name );
|
||||
void __cdecl Play( _In_z_ const char* name, float volume, float pitch, float pan );
|
||||
|
||||
std::unique_ptr<SoundEffectInstance> __cdecl CreateInstance( int index, SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default );
|
||||
std::unique_ptr<SoundEffectInstance> __cdecl CreateInstance( _In_z_ const char* name, SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default );
|
||||
|
||||
bool __cdecl IsPrepared() const;
|
||||
bool __cdecl IsInUse() const;
|
||||
bool __cdecl IsStreamingBank() const;
|
||||
|
||||
size_t __cdecl GetSampleSizeInBytes( int index ) const;
|
||||
// Returns size of wave audio data
|
||||
|
||||
size_t __cdecl GetSampleDuration( int index ) const;
|
||||
// Returns the duration in samples
|
||||
|
||||
size_t __cdecl GetSampleDurationMS( int index ) const;
|
||||
// Returns the duration in milliseconds
|
||||
|
||||
const WAVEFORMATEX* __cdecl GetFormat( int index, _Out_writes_bytes_(maxsize) WAVEFORMATEX* wfx, size_t maxsize ) const;
|
||||
|
||||
int __cdecl Find( _In_z_ const char* name ) const;
|
||||
|
||||
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/ )
|
||||
bool __cdecl FillSubmitBuffer( int index, _Out_ XAUDIO2_BUFFER& buffer, _Out_ XAUDIO2_BUFFER_WMA& wmaBuffer ) const;
|
||||
#else
|
||||
void __cdecl FillSubmitBuffer( int index, _Out_ XAUDIO2_BUFFER& buffer ) const;
|
||||
#endif
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
|
||||
// Private interface
|
||||
void __cdecl UnregisterInstance( _In_ SoundEffectInstance* instance );
|
||||
|
||||
friend class SoundEffectInstance;
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
class SoundEffect
|
||||
{
|
||||
public:
|
||||
SoundEffect( _In_ AudioEngine* engine, _In_z_ const wchar_t* waveFileName );
|
||||
|
||||
SoundEffect( _In_ AudioEngine* engine, _Inout_ std::unique_ptr<uint8_t[]>& wavData,
|
||||
_In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio, size_t audioBytes );
|
||||
|
||||
SoundEffect( _In_ AudioEngine* engine, _Inout_ std::unique_ptr<uint8_t[]>& wavData,
|
||||
_In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio, size_t audioBytes,
|
||||
uint32_t loopStart, uint32_t loopLength );
|
||||
|
||||
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/)
|
||||
|
||||
SoundEffect( _In_ AudioEngine* engine, _Inout_ std::unique_ptr<uint8_t[]>& wavData,
|
||||
_In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio, size_t audioBytes,
|
||||
_In_reads_(seekCount) const uint32_t* seekTable, size_t seekCount );
|
||||
|
||||
#endif
|
||||
|
||||
SoundEffect(SoundEffect&& moveFrom);
|
||||
SoundEffect& operator= (SoundEffect&& moveFrom);
|
||||
|
||||
SoundEffect(SoundEffect const&) = delete;
|
||||
SoundEffect& operator= (SoundEffect const&) = delete;
|
||||
|
||||
virtual ~SoundEffect();
|
||||
|
||||
void __cdecl Play();
|
||||
void __cdecl Play(float volume, float pitch, float pan);
|
||||
|
||||
std::unique_ptr<SoundEffectInstance> __cdecl CreateInstance( SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default );
|
||||
|
||||
bool __cdecl IsInUse() const;
|
||||
|
||||
size_t __cdecl GetSampleSizeInBytes() const;
|
||||
// Returns size of wave audio data
|
||||
|
||||
size_t __cdecl GetSampleDuration() const;
|
||||
// Returns the duration in samples
|
||||
|
||||
size_t __cdecl GetSampleDurationMS() const;
|
||||
// Returns the duration in milliseconds
|
||||
|
||||
const WAVEFORMATEX* __cdecl GetFormat() const;
|
||||
|
||||
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/)
|
||||
bool __cdecl FillSubmitBuffer( _Out_ XAUDIO2_BUFFER& buffer, _Out_ XAUDIO2_BUFFER_WMA& wmaBuffer ) const;
|
||||
#else
|
||||
void __cdecl FillSubmitBuffer( _Out_ XAUDIO2_BUFFER& buffer ) const;
|
||||
#endif
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
|
||||
// Private interface
|
||||
void __cdecl UnregisterInstance( _In_ SoundEffectInstance* instance );
|
||||
|
||||
friend class SoundEffectInstance;
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
struct AudioListener : public X3DAUDIO_LISTENER
|
||||
{
|
||||
AudioListener()
|
||||
{
|
||||
memset( this, 0, sizeof(X3DAUDIO_LISTENER) );
|
||||
|
||||
OrientFront.z = -1.f;
|
||||
|
||||
OrientTop.y = 1.f;
|
||||
}
|
||||
|
||||
void XM_CALLCONV SetPosition( FXMVECTOR v )
|
||||
{
|
||||
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &Position ), v );
|
||||
}
|
||||
void __cdecl SetPosition( const XMFLOAT3& pos )
|
||||
{
|
||||
Position.x = pos.x;
|
||||
Position.y = pos.y;
|
||||
Position.z = pos.z;
|
||||
}
|
||||
|
||||
void XM_CALLCONV SetVelocity( FXMVECTOR v )
|
||||
{
|
||||
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &Velocity ), v );
|
||||
}
|
||||
void __cdecl SetVelocity( const XMFLOAT3& vel )
|
||||
{
|
||||
Velocity.x = vel.x;
|
||||
Velocity.y = vel.y;
|
||||
Velocity.z = vel.z;
|
||||
}
|
||||
|
||||
void XM_CALLCONV SetOrientation( FXMVECTOR forward, FXMVECTOR up )
|
||||
{
|
||||
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientFront ), forward );
|
||||
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientTop ), up );
|
||||
}
|
||||
void __cdecl SetOrientation( const XMFLOAT3& forward, const XMFLOAT3& up )
|
||||
{
|
||||
OrientFront.x = forward.x; OrientTop.x = up.x;
|
||||
OrientFront.y = forward.y; OrientTop.y = up.y;
|
||||
OrientFront.z = forward.z; OrientTop.z = up.z;
|
||||
}
|
||||
|
||||
void XM_CALLCONV SetOrientationFromQuaternion( FXMVECTOR quat )
|
||||
{
|
||||
XMVECTOR forward = XMVector3Rotate( g_XMIdentityR2, quat );
|
||||
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientFront ), forward );
|
||||
|
||||
XMVECTOR up = XMVector3Rotate( g_XMIdentityR1, quat );
|
||||
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientTop ), up );
|
||||
}
|
||||
|
||||
void XM_CALLCONV Update( FXMVECTOR newPos, XMVECTOR upDir, float dt )
|
||||
// Updates velocity and orientation by tracking changes in position over time...
|
||||
{
|
||||
if ( dt > 0.f )
|
||||
{
|
||||
XMVECTOR lastPos = XMLoadFloat3( reinterpret_cast<const XMFLOAT3*>( &Position ) );
|
||||
|
||||
XMVECTOR vDelta = ( newPos - lastPos );
|
||||
XMVECTOR v = vDelta / dt;
|
||||
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &Velocity ), v );
|
||||
|
||||
vDelta = XMVector3Normalize( vDelta );
|
||||
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientFront ), vDelta );
|
||||
|
||||
v = XMVector3Cross( upDir, vDelta );
|
||||
v = XMVector3Normalize( v );
|
||||
|
||||
v = XMVector3Cross( vDelta, v );
|
||||
v = XMVector3Normalize( v );
|
||||
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientTop ), v );
|
||||
|
||||
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &Position ), newPos );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
struct AudioEmitter : public X3DAUDIO_EMITTER
|
||||
{
|
||||
float EmitterAzimuths[XAUDIO2_MAX_AUDIO_CHANNELS];
|
||||
|
||||
AudioEmitter()
|
||||
{
|
||||
memset( this, 0, sizeof(X3DAUDIO_EMITTER) );
|
||||
memset( EmitterAzimuths, 0, sizeof(EmitterAzimuths) );
|
||||
|
||||
OrientFront.z = -1.f;
|
||||
|
||||
OrientTop.y =
|
||||
ChannelRadius =
|
||||
CurveDistanceScaler =
|
||||
DopplerScaler = 1.f;
|
||||
|
||||
ChannelCount = 1;
|
||||
pChannelAzimuths = EmitterAzimuths;
|
||||
|
||||
InnerRadiusAngle = X3DAUDIO_PI / 4.0f;
|
||||
}
|
||||
|
||||
void XM_CALLCONV SetPosition( FXMVECTOR v )
|
||||
{
|
||||
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &Position ), v );
|
||||
}
|
||||
void __cdecl SetPosition( const XMFLOAT3& pos )
|
||||
{
|
||||
Position.x = pos.x;
|
||||
Position.y = pos.y;
|
||||
Position.z = pos.z;
|
||||
}
|
||||
|
||||
void XM_CALLCONV SetVelocity( FXMVECTOR v )
|
||||
{
|
||||
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &Velocity ), v );
|
||||
}
|
||||
void __cdecl SetVelocity( const XMFLOAT3& vel )
|
||||
{
|
||||
Velocity.x = vel.x;
|
||||
Velocity.y = vel.y;
|
||||
Velocity.z = vel.z;
|
||||
}
|
||||
|
||||
void XM_CALLCONV SetOrientation( FXMVECTOR forward, FXMVECTOR up )
|
||||
{
|
||||
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientFront ), forward );
|
||||
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientTop ), up );
|
||||
}
|
||||
void __cdecl SetOrientation( const XMFLOAT3& forward, const XMFLOAT3& up )
|
||||
{
|
||||
OrientFront.x = forward.x; OrientTop.x = up.x;
|
||||
OrientFront.y = forward.y; OrientTop.y = up.y;
|
||||
OrientFront.z = forward.z; OrientTop.z = up.z;
|
||||
}
|
||||
|
||||
void XM_CALLCONV SetOrientationFromQuaternion( FXMVECTOR quat )
|
||||
{
|
||||
XMVECTOR forward = XMVector3Rotate( g_XMIdentityR2, quat );
|
||||
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientFront ), forward );
|
||||
|
||||
XMVECTOR up = XMVector3Rotate( g_XMIdentityR1, quat );
|
||||
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientTop ), up );
|
||||
}
|
||||
|
||||
void XM_CALLCONV Update( FXMVECTOR newPos, XMVECTOR upDir, float dt )
|
||||
// Updates velocity and orientation by tracking changes in position over time...
|
||||
{
|
||||
if ( dt > 0.f )
|
||||
{
|
||||
XMVECTOR lastPos = XMLoadFloat3( reinterpret_cast<const XMFLOAT3*>( &Position ) );
|
||||
|
||||
XMVECTOR vDelta = ( newPos - lastPos );
|
||||
XMVECTOR v = vDelta / dt;
|
||||
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &Velocity ), v );
|
||||
|
||||
vDelta = XMVector3Normalize( vDelta );
|
||||
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientFront ), vDelta );
|
||||
|
||||
v = XMVector3Cross( upDir, vDelta );
|
||||
v = XMVector3Normalize( v );
|
||||
|
||||
v = XMVector3Cross( vDelta, v );
|
||||
v = XMVector3Normalize( v );
|
||||
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientTop ), v );
|
||||
|
||||
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &Position ), newPos );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
class SoundEffectInstance
|
||||
{
|
||||
public:
|
||||
SoundEffectInstance(SoundEffectInstance&& moveFrom);
|
||||
SoundEffectInstance& operator= (SoundEffectInstance&& moveFrom);
|
||||
|
||||
SoundEffectInstance(SoundEffectInstance const&) = delete;
|
||||
SoundEffectInstance& operator= (SoundEffectInstance const&) = delete;
|
||||
|
||||
virtual ~SoundEffectInstance();
|
||||
|
||||
void __cdecl Play( bool loop = false );
|
||||
void __cdecl Stop( bool immediate = true );
|
||||
void __cdecl Pause();
|
||||
void __cdecl Resume();
|
||||
|
||||
void __cdecl SetVolume( float volume );
|
||||
void __cdecl SetPitch( float pitch );
|
||||
void __cdecl SetPan( float pan );
|
||||
|
||||
void __cdecl Apply3D( const AudioListener& listener, const AudioEmitter& emitter, bool rhcoords = true );
|
||||
|
||||
bool __cdecl IsLooped() const;
|
||||
|
||||
SoundState __cdecl GetState();
|
||||
|
||||
// Notifications.
|
||||
void __cdecl OnDestroyParent();
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
|
||||
// Private constructors
|
||||
SoundEffectInstance( _In_ AudioEngine* engine, _In_ SoundEffect* effect, SOUND_EFFECT_INSTANCE_FLAGS flags );
|
||||
SoundEffectInstance( _In_ AudioEngine* engine, _In_ WaveBank* effect, int index, SOUND_EFFECT_INSTANCE_FLAGS flags );
|
||||
|
||||
friend std::unique_ptr<SoundEffectInstance> __cdecl SoundEffect::CreateInstance( SOUND_EFFECT_INSTANCE_FLAGS );
|
||||
friend std::unique_ptr<SoundEffectInstance> __cdecl WaveBank::CreateInstance( int, SOUND_EFFECT_INSTANCE_FLAGS );
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
class DynamicSoundEffectInstance
|
||||
{
|
||||
public:
|
||||
DynamicSoundEffectInstance( _In_ AudioEngine* engine,
|
||||
_In_opt_ std::function<void __cdecl(DynamicSoundEffectInstance*)> bufferNeeded,
|
||||
int sampleRate, int channels, int sampleBits = 16,
|
||||
SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default );
|
||||
DynamicSoundEffectInstance(DynamicSoundEffectInstance&& moveFrom);
|
||||
DynamicSoundEffectInstance& operator= (DynamicSoundEffectInstance&& moveFrom);
|
||||
|
||||
DynamicSoundEffectInstance(DynamicSoundEffectInstance const&) = delete;
|
||||
DynamicSoundEffectInstance& operator= (DynamicSoundEffectInstance const&) = delete;
|
||||
|
||||
virtual ~DynamicSoundEffectInstance();
|
||||
|
||||
void __cdecl Play();
|
||||
void __cdecl Stop( bool immediate = true );
|
||||
void __cdecl Pause();
|
||||
void __cdecl Resume();
|
||||
|
||||
void __cdecl SetVolume( float volume );
|
||||
void __cdecl SetPitch( float pitch );
|
||||
void __cdecl SetPan( float pan );
|
||||
|
||||
void __cdecl Apply3D( const AudioListener& listener, const AudioEmitter& emitter, bool rhcoords = true );
|
||||
|
||||
void __cdecl SubmitBuffer( _In_reads_bytes_(audioBytes) const uint8_t* pAudioData, size_t audioBytes );
|
||||
void __cdecl SubmitBuffer( _In_reads_bytes_(audioBytes) const uint8_t* pAudioData, uint32_t offset, size_t audioBytes );
|
||||
|
||||
SoundState __cdecl GetState();
|
||||
|
||||
size_t __cdecl GetSampleDuration( size_t bytes ) const;
|
||||
// Returns duration in samples of a buffer of a given size
|
||||
|
||||
size_t __cdecl GetSampleDurationMS( size_t bytes ) const;
|
||||
// Returns duration in milliseconds of a buffer of a given size
|
||||
|
||||
size_t __cdecl GetSampleSizeInBytes( uint64_t duration ) const;
|
||||
// Returns size of a buffer for a duration given in milliseconds
|
||||
|
||||
int __cdecl GetPendingBufferCount() const;
|
||||
|
||||
const WAVEFORMATEX* __cdecl GetFormat() const;
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
};
|
||||
}
|
||||
70
DirectXTK/Inc/CommonStates.h
Normal file
70
DirectXTK/Inc/CommonStates.h
Normal file
@@ -0,0 +1,70 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// File: CommonStates.h
|
||||
//
|
||||
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
||||
// PARTICULAR PURPOSE.
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248929
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
#include <d3d11_x.h>
|
||||
#else
|
||||
#include <d3d11_1.h>
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace DirectX
|
||||
{
|
||||
class CommonStates
|
||||
{
|
||||
public:
|
||||
explicit CommonStates(_In_ ID3D11Device* device);
|
||||
CommonStates(CommonStates&& moveFrom);
|
||||
CommonStates& operator= (CommonStates&& moveFrom);
|
||||
|
||||
CommonStates(CommonStates const&) = delete;
|
||||
CommonStates& operator= (CommonStates const&) = delete;
|
||||
|
||||
virtual ~CommonStates();
|
||||
|
||||
// Blend states.
|
||||
ID3D11BlendState* __cdecl Opaque() const;
|
||||
ID3D11BlendState* __cdecl AlphaBlend() const;
|
||||
ID3D11BlendState* __cdecl Additive() const;
|
||||
ID3D11BlendState* __cdecl NonPremultiplied() const;
|
||||
|
||||
// Depth stencil states.
|
||||
ID3D11DepthStencilState* __cdecl DepthNone() const;
|
||||
ID3D11DepthStencilState* __cdecl DepthDefault() const;
|
||||
ID3D11DepthStencilState* __cdecl DepthRead() const;
|
||||
|
||||
// Rasterizer states.
|
||||
ID3D11RasterizerState* __cdecl CullNone() const;
|
||||
ID3D11RasterizerState* __cdecl CullClockwise() const;
|
||||
ID3D11RasterizerState* __cdecl CullCounterClockwise() const;
|
||||
ID3D11RasterizerState* __cdecl Wireframe() const;
|
||||
|
||||
// Sampler states.
|
||||
ID3D11SamplerState* __cdecl PointWrap() const;
|
||||
ID3D11SamplerState* __cdecl PointClamp() const;
|
||||
ID3D11SamplerState* __cdecl LinearWrap() const;
|
||||
ID3D11SamplerState* __cdecl LinearClamp() const;
|
||||
ID3D11SamplerState* __cdecl AnisotropicWrap() const;
|
||||
ID3D11SamplerState* __cdecl AnisotropicClamp() const;
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::shared_ptr<Impl> pImpl;
|
||||
};
|
||||
}
|
||||
158
DirectXTK/Inc/DDSTextureLoader.h
Normal file
158
DirectXTK/Inc/DDSTextureLoader.h
Normal file
@@ -0,0 +1,158 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// File: DDSTextureLoader.h
|
||||
//
|
||||
// Functions for loading a DDS texture and creating a Direct3D runtime resource for it
|
||||
//
|
||||
// Note these functions are useful as a light-weight runtime loader for DDS files. For
|
||||
// a full-featured DDS file reader, writer, and texture processing pipeline see
|
||||
// the 'Texconv' sample and the 'DirectXTex' library.
|
||||
//
|
||||
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
||||
// PARTICULAR PURPOSE.
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248926
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248929
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
#include <d3d11_x.h>
|
||||
#else
|
||||
#include <d3d11_1.h>
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
namespace DirectX
|
||||
{
|
||||
enum DDS_ALPHA_MODE
|
||||
{
|
||||
DDS_ALPHA_MODE_UNKNOWN = 0,
|
||||
DDS_ALPHA_MODE_STRAIGHT = 1,
|
||||
DDS_ALPHA_MODE_PREMULTIPLIED = 2,
|
||||
DDS_ALPHA_MODE_OPAQUE = 3,
|
||||
DDS_ALPHA_MODE_CUSTOM = 4,
|
||||
};
|
||||
|
||||
// Standard version
|
||||
HRESULT __cdecl CreateDDSTextureFromMemory(
|
||||
_In_ ID3D11Device* d3dDevice,
|
||||
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
|
||||
_In_ size_t ddsDataSize,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_In_ size_t maxsize = 0,
|
||||
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
|
||||
|
||||
HRESULT __cdecl CreateDDSTextureFromFile(
|
||||
_In_ ID3D11Device* d3dDevice,
|
||||
_In_z_ const wchar_t* szFileName,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_In_ size_t maxsize = 0,
|
||||
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
|
||||
|
||||
// Standard version with optional auto-gen mipmap support
|
||||
HRESULT __cdecl CreateDDSTextureFromMemory(
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
_In_ ID3D11DeviceX* d3dDevice,
|
||||
_In_opt_ ID3D11DeviceContextX* d3dContext,
|
||||
#else
|
||||
_In_ ID3D11Device* d3dDevice,
|
||||
_In_opt_ ID3D11DeviceContext* d3dContext,
|
||||
#endif
|
||||
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
|
||||
_In_ size_t ddsDataSize,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_In_ size_t maxsize = 0,
|
||||
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
|
||||
|
||||
HRESULT __cdecl CreateDDSTextureFromFile(
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
_In_ ID3D11DeviceX* d3dDevice,
|
||||
_In_opt_ ID3D11DeviceContextX* d3dContext,
|
||||
#else
|
||||
_In_ ID3D11Device* d3dDevice,
|
||||
_In_opt_ ID3D11DeviceContext* d3dContext,
|
||||
#endif
|
||||
_In_z_ const wchar_t* szFileName,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_In_ size_t maxsize = 0,
|
||||
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
|
||||
|
||||
// Extended version
|
||||
HRESULT __cdecl CreateDDSTextureFromMemoryEx(
|
||||
_In_ ID3D11Device* d3dDevice,
|
||||
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
|
||||
_In_ size_t ddsDataSize,
|
||||
_In_ size_t maxsize,
|
||||
_In_ D3D11_USAGE usage,
|
||||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_In_ bool forceSRGB,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
|
||||
|
||||
HRESULT __cdecl CreateDDSTextureFromFileEx(
|
||||
_In_ ID3D11Device* d3dDevice,
|
||||
_In_z_ const wchar_t* szFileName,
|
||||
_In_ size_t maxsize,
|
||||
_In_ D3D11_USAGE usage,
|
||||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_In_ bool forceSRGB,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
|
||||
|
||||
// Extended version with optional auto-gen mipmap support
|
||||
HRESULT __cdecl CreateDDSTextureFromMemoryEx(
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
_In_ ID3D11DeviceX* d3dDevice,
|
||||
_In_opt_ ID3D11DeviceContextX* d3dContext,
|
||||
#else
|
||||
_In_ ID3D11Device* d3dDevice,
|
||||
_In_opt_ ID3D11DeviceContext* d3dContext,
|
||||
#endif
|
||||
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
|
||||
_In_ size_t ddsDataSize,
|
||||
_In_ size_t maxsize,
|
||||
_In_ D3D11_USAGE usage,
|
||||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_In_ bool forceSRGB,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
|
||||
|
||||
HRESULT __cdecl CreateDDSTextureFromFileEx(
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
_In_ ID3D11DeviceX* d3dDevice,
|
||||
_In_opt_ ID3D11DeviceContextX* d3dContext,
|
||||
#else
|
||||
_In_ ID3D11Device* d3dDevice,
|
||||
_In_opt_ ID3D11DeviceContext* d3dContext,
|
||||
#endif
|
||||
_In_z_ const wchar_t* szFileName,
|
||||
_In_ size_t maxsize,
|
||||
_In_ D3D11_USAGE usage,
|
||||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_In_ bool forceSRGB,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
|
||||
}
|
||||
150
DirectXTK/Inc/DirectXHelpers.h
Normal file
150
DirectXTK/Inc/DirectXHelpers.h
Normal file
@@ -0,0 +1,150 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// File: DirectXHelpers.h
|
||||
//
|
||||
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
||||
// PARTICULAR PURPOSE.
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248929
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
#include <d3d11_x.h>
|
||||
#else
|
||||
#include <d3d11_1.h>
|
||||
#endif
|
||||
|
||||
#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
|
||||
#if !defined(_XBOX_ONE) || !defined(_TITLE)
|
||||
#pragma comment(lib,"dxguid.lib")
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef IID_GRAPHICS_PPV_ARGS
|
||||
#define IID_GRAPHICS_PPV_ARGS(x) IID_PPV_ARGS(x)
|
||||
#endif
|
||||
|
||||
#include <exception>
|
||||
#include <stdint.h>
|
||||
|
||||
//
|
||||
// The core Direct3D headers provide the following helper C++ classes
|
||||
// CD3D11_RECT
|
||||
// CD3D11_BOX
|
||||
// CD3D11_DEPTH_STENCIL_DESC
|
||||
// CD3D11_BLEND_DESC, CD3D11_BLEND_DESC1
|
||||
// CD3D11_RASTERIZER_DESC, CD3D11_RASTERIZER_DESC1
|
||||
// CD3D11_BUFFER_DESC
|
||||
// CD3D11_TEXTURE1D_DESC
|
||||
// CD3D11_TEXTURE2D_DESC
|
||||
// CD3D11_TEXTURE3D_DESC
|
||||
// CD3D11_SHADER_RESOURCE_VIEW_DESC
|
||||
// CD3D11_RENDER_TARGET_VIEW_DESC
|
||||
// CD3D11_VIEWPORT
|
||||
// CD3D11_DEPTH_STENCIL_VIEW_DESC
|
||||
// CD3D11_UNORDERED_ACCESS_VIEW_DESC
|
||||
// CD3D11_SAMPLER_DESC
|
||||
// CD3D11_QUERY_DESC
|
||||
// CD3D11_COUNTER_DESC
|
||||
//
|
||||
|
||||
|
||||
namespace DirectX
|
||||
{
|
||||
// simliar to std::lock_guard for exception-safe Direct3D resource locking
|
||||
class MapGuard : public D3D11_MAPPED_SUBRESOURCE
|
||||
{
|
||||
public:
|
||||
MapGuard( _In_ ID3D11DeviceContext* context,
|
||||
_In_ ID3D11Resource *resource,
|
||||
_In_ UINT subresource,
|
||||
_In_ D3D11_MAP mapType,
|
||||
_In_ UINT mapFlags )
|
||||
: mContext(context), mResource(resource), mSubresource(subresource)
|
||||
{
|
||||
HRESULT hr = mContext->Map( resource, subresource, mapType, mapFlags, this );
|
||||
if (FAILED(hr))
|
||||
{
|
||||
throw std::exception();
|
||||
}
|
||||
}
|
||||
|
||||
~MapGuard()
|
||||
{
|
||||
mContext->Unmap( mResource, mSubresource );
|
||||
}
|
||||
|
||||
uint8_t* get() const
|
||||
{
|
||||
return reinterpret_cast<uint8_t*>( pData );
|
||||
}
|
||||
uint8_t* get(size_t slice) const
|
||||
{
|
||||
return reinterpret_cast<uint8_t*>( pData ) + ( slice * DepthPitch );
|
||||
}
|
||||
|
||||
uint8_t* scanline(size_t row) const
|
||||
{
|
||||
return reinterpret_cast<uint8_t*>( pData ) + ( row * RowPitch );
|
||||
}
|
||||
uint8_t* scanline(size_t slice, size_t row) const
|
||||
{
|
||||
return reinterpret_cast<uint8_t*>( pData ) + ( slice * DepthPitch ) + ( row * RowPitch );
|
||||
}
|
||||
|
||||
private:
|
||||
ID3D11DeviceContext* mContext;
|
||||
ID3D11Resource* mResource;
|
||||
UINT mSubresource;
|
||||
|
||||
MapGuard(MapGuard const&);
|
||||
MapGuard& operator= (MapGuard const&);
|
||||
};
|
||||
|
||||
|
||||
// Helper sets a D3D resource name string (used by PIX and debug layer leak reporting).
|
||||
template<UINT TNameLength>
|
||||
inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_z_ const char (&name)[TNameLength])
|
||||
{
|
||||
#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
wchar_t wname[MAX_PATH];
|
||||
int result = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, name, TNameLength, wname, MAX_PATH );
|
||||
if ( result > 0 )
|
||||
{
|
||||
resource->SetName( wname );
|
||||
}
|
||||
#else
|
||||
resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name);
|
||||
#endif
|
||||
#else
|
||||
UNREFERENCED_PARAMETER(resource);
|
||||
UNREFERENCED_PARAMETER(name);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<UINT TNameLength>
|
||||
inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_z_ const wchar_t (&name)[TNameLength])
|
||||
{
|
||||
#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
resource->SetName( name );
|
||||
#else
|
||||
char aname[MAX_PATH];
|
||||
int result = WideCharToMultiByte( CP_ACP, 0, name, TNameLength, aname, MAX_PATH, nullptr, nullptr );
|
||||
if ( result > 0 )
|
||||
{
|
||||
resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, aname);
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
UNREFERENCED_PARAMETER(resource);
|
||||
UNREFERENCED_PARAMETER(name);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
691
DirectXTK/Inc/Effects.h
Normal file
691
DirectXTK/Inc/Effects.h
Normal file
@@ -0,0 +1,691 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// File: Effects.h
|
||||
//
|
||||
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
||||
// PARTICULAR PURPOSE.
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248929
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
#include <d3d11_x.h>
|
||||
#else
|
||||
#include <d3d11_1.h>
|
||||
#endif
|
||||
|
||||
#include <DirectXMath.h>
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace DirectX
|
||||
{
|
||||
//----------------------------------------------------------------------------------
|
||||
// Abstract interface representing any effect which can be applied onto a D3D device context.
|
||||
class IEffect
|
||||
{
|
||||
public:
|
||||
virtual ~IEffect() { }
|
||||
|
||||
virtual void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) = 0;
|
||||
|
||||
virtual void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) = 0;
|
||||
};
|
||||
|
||||
|
||||
// Abstract interface for effects with world, view, and projection matrices.
|
||||
class IEffectMatrices
|
||||
{
|
||||
public:
|
||||
virtual ~IEffectMatrices() { }
|
||||
|
||||
virtual void XM_CALLCONV SetWorld(FXMMATRIX value) = 0;
|
||||
virtual void XM_CALLCONV SetView(FXMMATRIX value) = 0;
|
||||
virtual void XM_CALLCONV SetProjection(FXMMATRIX value) = 0;
|
||||
virtual void XM_CALLCONV SetMatrices(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection);
|
||||
};
|
||||
|
||||
|
||||
// Abstract interface for effects which support directional lighting.
|
||||
class IEffectLights
|
||||
{
|
||||
public:
|
||||
virtual ~IEffectLights() { }
|
||||
|
||||
virtual void __cdecl SetLightingEnabled(bool value) = 0;
|
||||
virtual void __cdecl SetPerPixelLighting(bool value) = 0;
|
||||
virtual void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) = 0;
|
||||
|
||||
virtual void __cdecl SetLightEnabled(int whichLight, bool value) = 0;
|
||||
virtual void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) = 0;
|
||||
virtual void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) = 0;
|
||||
virtual void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) = 0;
|
||||
|
||||
virtual void __cdecl EnableDefaultLighting() = 0;
|
||||
|
||||
static const int MaxDirectionalLights = 3;
|
||||
};
|
||||
|
||||
|
||||
// Abstract interface for effects which support fog.
|
||||
class IEffectFog
|
||||
{
|
||||
public:
|
||||
virtual ~IEffectFog() { }
|
||||
|
||||
virtual void __cdecl SetFogEnabled(bool value) = 0;
|
||||
virtual void __cdecl SetFogStart(float value) = 0;
|
||||
virtual void __cdecl SetFogEnd(float value) = 0;
|
||||
virtual void XM_CALLCONV SetFogColor(FXMVECTOR value) = 0;
|
||||
};
|
||||
|
||||
|
||||
// Abstract interface for effects which support skinning
|
||||
class IEffectSkinning
|
||||
{
|
||||
public:
|
||||
virtual ~IEffectSkinning() { }
|
||||
|
||||
virtual void __cdecl SetWeightsPerVertex(int value) = 0;
|
||||
virtual void __cdecl SetBoneTransforms(_In_reads_(count) XMMATRIX const* value, size_t count) = 0;
|
||||
virtual void __cdecl ResetBoneTransforms() = 0;
|
||||
|
||||
static const int MaxBones = 72;
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Built-in shader supports optional texture mapping, vertex coloring, directional lighting, and fog.
|
||||
class BasicEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog
|
||||
{
|
||||
public:
|
||||
explicit BasicEffect(_In_ ID3D11Device* device);
|
||||
BasicEffect(BasicEffect&& moveFrom);
|
||||
BasicEffect& operator= (BasicEffect&& moveFrom);
|
||||
|
||||
BasicEffect(BasicEffect const&) = delete;
|
||||
BasicEffect& operator= (BasicEffect const&) = delete;
|
||||
|
||||
virtual ~BasicEffect();
|
||||
|
||||
// IEffect methods.
|
||||
void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override;
|
||||
|
||||
void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override;
|
||||
|
||||
// Camera settings.
|
||||
void XM_CALLCONV SetWorld(FXMMATRIX value) override;
|
||||
void XM_CALLCONV SetView(FXMMATRIX value) override;
|
||||
void XM_CALLCONV SetProjection(FXMMATRIX value) override;
|
||||
void XM_CALLCONV SetMatrices(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection) override;
|
||||
|
||||
// Material settings.
|
||||
void XM_CALLCONV SetDiffuseColor(FXMVECTOR value);
|
||||
void XM_CALLCONV SetEmissiveColor(FXMVECTOR value);
|
||||
void XM_CALLCONV SetSpecularColor(FXMVECTOR value);
|
||||
void __cdecl SetSpecularPower(float value);
|
||||
void __cdecl DisableSpecular();
|
||||
void __cdecl SetAlpha(float value);
|
||||
void XM_CALLCONV SetColorAndAlpha(FXMVECTOR value);
|
||||
|
||||
// Light settings.
|
||||
void __cdecl SetLightingEnabled(bool value) override;
|
||||
void __cdecl SetPerPixelLighting(bool value) override;
|
||||
void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override;
|
||||
|
||||
void __cdecl SetLightEnabled(int whichLight, bool value) override;
|
||||
void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override;
|
||||
void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override;
|
||||
void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override;
|
||||
|
||||
void __cdecl EnableDefaultLighting() override;
|
||||
|
||||
// Fog settings.
|
||||
void __cdecl SetFogEnabled(bool value) override;
|
||||
void __cdecl SetFogStart(float value) override;
|
||||
void __cdecl SetFogEnd(float value) override;
|
||||
void XM_CALLCONV SetFogColor(FXMVECTOR value) override;
|
||||
|
||||
// Vertex color setting.
|
||||
void __cdecl SetVertexColorEnabled(bool value);
|
||||
|
||||
// Texture setting.
|
||||
void __cdecl SetTextureEnabled(bool value);
|
||||
void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
|
||||
|
||||
// Normal compression settings.
|
||||
void __cdecl SetBiasedVertexNormals(bool value);
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Built-in shader supports per-pixel alpha testing.
|
||||
class AlphaTestEffect : public IEffect, public IEffectMatrices, public IEffectFog
|
||||
{
|
||||
public:
|
||||
explicit AlphaTestEffect(_In_ ID3D11Device* device);
|
||||
AlphaTestEffect(AlphaTestEffect&& moveFrom);
|
||||
AlphaTestEffect& operator= (AlphaTestEffect&& moveFrom);
|
||||
|
||||
AlphaTestEffect(AlphaTestEffect const&) = delete;
|
||||
AlphaTestEffect& operator= (AlphaTestEffect const&) = delete;
|
||||
|
||||
virtual ~AlphaTestEffect();
|
||||
|
||||
// IEffect methods.
|
||||
void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override;
|
||||
|
||||
void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override;
|
||||
|
||||
// Camera settings.
|
||||
void XM_CALLCONV SetWorld(FXMMATRIX value) override;
|
||||
void XM_CALLCONV SetView(FXMMATRIX value) override;
|
||||
void XM_CALLCONV SetProjection(FXMMATRIX value) override;
|
||||
void XM_CALLCONV SetMatrices(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection) override;
|
||||
|
||||
// Material settings.
|
||||
void XM_CALLCONV SetDiffuseColor(FXMVECTOR value);
|
||||
void __cdecl SetAlpha(float value);
|
||||
void XM_CALLCONV SetColorAndAlpha(FXMVECTOR value);
|
||||
|
||||
// Fog settings.
|
||||
void __cdecl SetFogEnabled(bool value) override;
|
||||
void __cdecl SetFogStart(float value) override;
|
||||
void __cdecl SetFogEnd(float value) override;
|
||||
void XM_CALLCONV SetFogColor(FXMVECTOR value) override;
|
||||
|
||||
// Vertex color setting.
|
||||
void __cdecl SetVertexColorEnabled(bool value);
|
||||
|
||||
// Texture setting.
|
||||
void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
|
||||
|
||||
// Alpha test settings.
|
||||
void __cdecl SetAlphaFunction(D3D11_COMPARISON_FUNC value);
|
||||
void __cdecl SetReferenceAlpha(int value);
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Built-in shader supports two layer multitexturing (eg. for lightmaps or detail textures).
|
||||
class DualTextureEffect : public IEffect, public IEffectMatrices, public IEffectFog
|
||||
{
|
||||
public:
|
||||
explicit DualTextureEffect(_In_ ID3D11Device* device);
|
||||
DualTextureEffect(DualTextureEffect&& moveFrom);
|
||||
DualTextureEffect& operator= (DualTextureEffect&& moveFrom);
|
||||
|
||||
DualTextureEffect(DualTextureEffect const&) = delete;
|
||||
DualTextureEffect& operator= (DualTextureEffect const&) = delete;
|
||||
|
||||
~DualTextureEffect();
|
||||
|
||||
// IEffect methods.
|
||||
void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override;
|
||||
|
||||
void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override;
|
||||
|
||||
// Camera settings.
|
||||
void XM_CALLCONV SetWorld(FXMMATRIX value) override;
|
||||
void XM_CALLCONV SetView(FXMMATRIX value) override;
|
||||
void XM_CALLCONV SetProjection(FXMMATRIX value) override;
|
||||
void XM_CALLCONV SetMatrices(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection) override;
|
||||
|
||||
// Material settings.
|
||||
void XM_CALLCONV SetDiffuseColor(FXMVECTOR value);
|
||||
void __cdecl SetAlpha(float value);
|
||||
void XM_CALLCONV SetColorAndAlpha(FXMVECTOR value);
|
||||
|
||||
// Fog settings.
|
||||
void __cdecl SetFogEnabled(bool value) override;
|
||||
void __cdecl SetFogStart(float value) override;
|
||||
void __cdecl SetFogEnd(float value) override;
|
||||
void XM_CALLCONV SetFogColor(FXMVECTOR value) override;
|
||||
|
||||
// Vertex color setting.
|
||||
void __cdecl SetVertexColorEnabled(bool value);
|
||||
|
||||
// Texture settings.
|
||||
void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
|
||||
void __cdecl SetTexture2(_In_opt_ ID3D11ShaderResourceView* value);
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Built-in shader supports cubic environment mapping.
|
||||
class EnvironmentMapEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog
|
||||
{
|
||||
public:
|
||||
explicit EnvironmentMapEffect(_In_ ID3D11Device* device);
|
||||
EnvironmentMapEffect(EnvironmentMapEffect&& moveFrom);
|
||||
EnvironmentMapEffect& operator= (EnvironmentMapEffect&& moveFrom);
|
||||
|
||||
EnvironmentMapEffect(EnvironmentMapEffect const&) = delete;
|
||||
EnvironmentMapEffect& operator= (EnvironmentMapEffect const&) = delete;
|
||||
|
||||
virtual ~EnvironmentMapEffect();
|
||||
|
||||
// IEffect methods.
|
||||
void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override;
|
||||
|
||||
void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override;
|
||||
|
||||
// Camera settings.
|
||||
void XM_CALLCONV SetWorld(FXMMATRIX value) override;
|
||||
void XM_CALLCONV SetView(FXMMATRIX value) override;
|
||||
void XM_CALLCONV SetProjection(FXMMATRIX value) override;
|
||||
void XM_CALLCONV SetMatrices(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection) override;
|
||||
|
||||
// Material settings.
|
||||
void XM_CALLCONV SetDiffuseColor(FXMVECTOR value);
|
||||
void XM_CALLCONV SetEmissiveColor(FXMVECTOR value);
|
||||
void __cdecl SetAlpha(float value);
|
||||
void XM_CALLCONV SetColorAndAlpha(FXMVECTOR value);
|
||||
|
||||
// Light settings.
|
||||
void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override;
|
||||
|
||||
void __cdecl SetPerPixelLighting(bool value) override;
|
||||
void __cdecl SetLightEnabled(int whichLight, bool value) override;
|
||||
void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override;
|
||||
void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override;
|
||||
|
||||
void __cdecl EnableDefaultLighting() override;
|
||||
|
||||
// Fog settings.
|
||||
void __cdecl SetFogEnabled(bool value) override;
|
||||
void __cdecl SetFogStart(float value) override;
|
||||
void __cdecl SetFogEnd(float value) override;
|
||||
void XM_CALLCONV SetFogColor(FXMVECTOR value) override;
|
||||
|
||||
// Texture setting.
|
||||
void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
|
||||
|
||||
// Environment map settings.
|
||||
void __cdecl SetEnvironmentMap(_In_opt_ ID3D11ShaderResourceView* value);
|
||||
void __cdecl SetEnvironmentMapAmount(float value);
|
||||
void XM_CALLCONV SetEnvironmentMapSpecular(FXMVECTOR value);
|
||||
void __cdecl SetFresnelFactor(float value);
|
||||
|
||||
// Normal compression settings.
|
||||
void __cdecl SetBiasedVertexNormals(bool value);
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
|
||||
// Unsupported interface methods.
|
||||
void __cdecl SetLightingEnabled(bool value) override;
|
||||
void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Built-in shader supports skinned animation.
|
||||
class SkinnedEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog, public IEffectSkinning
|
||||
{
|
||||
public:
|
||||
explicit SkinnedEffect(_In_ ID3D11Device* device);
|
||||
SkinnedEffect(SkinnedEffect&& moveFrom);
|
||||
SkinnedEffect& operator= (SkinnedEffect&& moveFrom);
|
||||
|
||||
SkinnedEffect(SkinnedEffect const&) = delete;
|
||||
SkinnedEffect& operator= (SkinnedEffect const&) = delete;
|
||||
|
||||
virtual ~SkinnedEffect();
|
||||
|
||||
// IEffect methods.
|
||||
void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override;
|
||||
|
||||
void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override;
|
||||
|
||||
// Camera settings.
|
||||
void XM_CALLCONV SetWorld(FXMMATRIX value) override;
|
||||
void XM_CALLCONV SetView(FXMMATRIX value) override;
|
||||
void XM_CALLCONV SetProjection(FXMMATRIX value) override;
|
||||
void XM_CALLCONV SetMatrices(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection) override;
|
||||
|
||||
// Material settings.
|
||||
void XM_CALLCONV SetDiffuseColor(FXMVECTOR value);
|
||||
void XM_CALLCONV SetEmissiveColor(FXMVECTOR value);
|
||||
void XM_CALLCONV SetSpecularColor(FXMVECTOR value);
|
||||
void __cdecl SetSpecularPower(float value);
|
||||
void __cdecl DisableSpecular();
|
||||
void __cdecl SetAlpha(float value);
|
||||
void XM_CALLCONV SetColorAndAlpha(FXMVECTOR value);
|
||||
|
||||
// Light settings.
|
||||
void __cdecl SetPerPixelLighting(bool value) override;
|
||||
void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override;
|
||||
|
||||
void __cdecl SetLightEnabled(int whichLight, bool value) override;
|
||||
void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override;
|
||||
void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override;
|
||||
void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override;
|
||||
|
||||
void __cdecl EnableDefaultLighting() override;
|
||||
|
||||
// Fog settings.
|
||||
void __cdecl SetFogEnabled(bool value) override;
|
||||
void __cdecl SetFogStart(float value) override;
|
||||
void __cdecl SetFogEnd(float value) override;
|
||||
void XM_CALLCONV SetFogColor(FXMVECTOR value) override;
|
||||
|
||||
// Texture setting.
|
||||
void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
|
||||
|
||||
// Animation settings.
|
||||
void __cdecl SetWeightsPerVertex(int value) override;
|
||||
void __cdecl SetBoneTransforms(_In_reads_(count) XMMATRIX const* value, size_t count) override;
|
||||
void __cdecl ResetBoneTransforms() override;
|
||||
|
||||
// Normal compression settings.
|
||||
void __cdecl SetBiasedVertexNormals(bool value);
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
|
||||
// Unsupported interface method.
|
||||
void __cdecl SetLightingEnabled(bool value) override;
|
||||
};
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Built-in effect for Visual Studio Shader Designer (DGSL) shaders
|
||||
class DGSLEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectSkinning
|
||||
{
|
||||
public:
|
||||
explicit DGSLEffect( _In_ ID3D11Device* device, _In_opt_ ID3D11PixelShader* pixelShader = nullptr,
|
||||
_In_ bool enableSkinning = false );
|
||||
DGSLEffect(DGSLEffect&& moveFrom);
|
||||
DGSLEffect& operator= (DGSLEffect&& moveFrom);
|
||||
|
||||
DGSLEffect(DGSLEffect const&) = delete;
|
||||
DGSLEffect& operator= (DGSLEffect const&) = delete;
|
||||
|
||||
virtual ~DGSLEffect();
|
||||
|
||||
// IEffect methods.
|
||||
void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override;
|
||||
|
||||
void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override;
|
||||
|
||||
// Camera settings.
|
||||
void XM_CALLCONV SetWorld(FXMMATRIX value) override;
|
||||
void XM_CALLCONV SetView(FXMMATRIX value) override;
|
||||
void XM_CALLCONV SetProjection(FXMMATRIX value) override;
|
||||
void XM_CALLCONV SetMatrices(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection) override;
|
||||
|
||||
// Material settings.
|
||||
void XM_CALLCONV SetAmbientColor(FXMVECTOR value);
|
||||
void XM_CALLCONV SetDiffuseColor(FXMVECTOR value);
|
||||
void XM_CALLCONV SetEmissiveColor(FXMVECTOR value);
|
||||
void XM_CALLCONV SetSpecularColor(FXMVECTOR value);
|
||||
void __cdecl SetSpecularPower(float value);
|
||||
void __cdecl DisableSpecular();
|
||||
void __cdecl SetAlpha(float value);
|
||||
void XM_CALLCONV SetColorAndAlpha(FXMVECTOR value);
|
||||
|
||||
// Additional settings.
|
||||
void XM_CALLCONV SetUVTransform(FXMMATRIX value);
|
||||
void __cdecl SetViewport( float width, float height );
|
||||
void __cdecl SetTime( float time );
|
||||
void __cdecl SetAlphaDiscardEnable(bool value);
|
||||
|
||||
// Light settings.
|
||||
void __cdecl SetLightingEnabled(bool value) override;
|
||||
void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override;
|
||||
|
||||
void __cdecl SetLightEnabled(int whichLight, bool value) override;
|
||||
void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override;
|
||||
void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override;
|
||||
void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override;
|
||||
|
||||
void __cdecl EnableDefaultLighting() override;
|
||||
|
||||
static const int MaxDirectionalLights = 4;
|
||||
|
||||
// Vertex color setting.
|
||||
void __cdecl SetVertexColorEnabled(bool value);
|
||||
|
||||
// Texture settings.
|
||||
void __cdecl SetTextureEnabled(bool value);
|
||||
void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
|
||||
void __cdecl SetTexture(int whichTexture, _In_opt_ ID3D11ShaderResourceView* value);
|
||||
|
||||
static const int MaxTextures = 8;
|
||||
|
||||
// Animation setting.
|
||||
void __cdecl SetWeightsPerVertex(int value) override;
|
||||
void __cdecl SetBoneTransforms(_In_reads_(count) XMMATRIX const* value, size_t count) override;
|
||||
void __cdecl ResetBoneTransforms() override;
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
|
||||
// Unsupported interface methods.
|
||||
void __cdecl SetPerPixelLighting(bool value) override;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Built-in shader extends BasicEffect with normal maps and optional specular maps
|
||||
class NormalMapEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog
|
||||
{
|
||||
public:
|
||||
explicit NormalMapEffect(_In_ ID3D11Device* device);
|
||||
NormalMapEffect(NormalMapEffect&& moveFrom);
|
||||
NormalMapEffect& operator= (NormalMapEffect&& moveFrom);
|
||||
|
||||
NormalMapEffect(NormalMapEffect const&) = delete;
|
||||
NormalMapEffect& operator= (NormalMapEffect const&) = delete;
|
||||
|
||||
virtual ~NormalMapEffect();
|
||||
|
||||
// IEffect methods.
|
||||
void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override;
|
||||
|
||||
void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override;
|
||||
|
||||
// Camera settings.
|
||||
void XM_CALLCONV SetWorld(FXMMATRIX value) override;
|
||||
void XM_CALLCONV SetView(FXMMATRIX value) override;
|
||||
void XM_CALLCONV SetProjection(FXMMATRIX value) override;
|
||||
void XM_CALLCONV SetMatrices(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection) override;
|
||||
|
||||
// Material settings.
|
||||
void XM_CALLCONV SetDiffuseColor(FXMVECTOR value);
|
||||
void XM_CALLCONV SetEmissiveColor(FXMVECTOR value);
|
||||
void XM_CALLCONV SetSpecularColor(FXMVECTOR value);
|
||||
void __cdecl SetSpecularPower(float value);
|
||||
void __cdecl DisableSpecular();
|
||||
void __cdecl SetAlpha(float value);
|
||||
void XM_CALLCONV SetColorAndAlpha(FXMVECTOR value);
|
||||
|
||||
// Light settings.
|
||||
void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override;
|
||||
|
||||
void __cdecl SetLightEnabled(int whichLight, bool value) override;
|
||||
void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override;
|
||||
void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override;
|
||||
void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override;
|
||||
|
||||
void __cdecl EnableDefaultLighting() override;
|
||||
|
||||
// Fog settings.
|
||||
void __cdecl SetFogEnabled(bool value) override;
|
||||
void __cdecl SetFogStart(float value) override;
|
||||
void __cdecl SetFogEnd(float value) override;
|
||||
void XM_CALLCONV SetFogColor(FXMVECTOR value) override;
|
||||
|
||||
// Vertex color setting.
|
||||
void __cdecl SetVertexColorEnabled(bool value);
|
||||
|
||||
// Texture setting - albedo, normal and specular intensity
|
||||
void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
|
||||
void __cdecl SetNormalTexture(_In_opt_ ID3D11ShaderResourceView* value);
|
||||
void __cdecl SetSpecularTexture(_In_opt_ ID3D11ShaderResourceView* value);
|
||||
|
||||
// Normal compression settings.
|
||||
void __cdecl SetBiasedVertexNormalsAndTangents(bool value);
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
|
||||
// Unsupported interface methods.
|
||||
void __cdecl SetLightingEnabled(bool value) override;
|
||||
void __cdecl SetPerPixelLighting(bool value) override;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Abstract interface to factory for sharing effects and texture resources
|
||||
class IEffectFactory
|
||||
{
|
||||
public:
|
||||
virtual ~IEffectFactory() {}
|
||||
|
||||
struct EffectInfo
|
||||
{
|
||||
const wchar_t* name;
|
||||
bool perVertexColor;
|
||||
bool enableSkinning;
|
||||
bool enableDualTexture;
|
||||
bool enableNormalMaps;
|
||||
bool biasedVertexNormals;
|
||||
float specularPower;
|
||||
float alpha;
|
||||
DirectX::XMFLOAT3 ambientColor;
|
||||
DirectX::XMFLOAT3 diffuseColor;
|
||||
DirectX::XMFLOAT3 specularColor;
|
||||
DirectX::XMFLOAT3 emissiveColor;
|
||||
const wchar_t* diffuseTexture;
|
||||
const wchar_t* specularTexture;
|
||||
const wchar_t* normalTexture;
|
||||
|
||||
EffectInfo() { memset( this, 0, sizeof(EffectInfo) ); };
|
||||
};
|
||||
|
||||
virtual std::shared_ptr<IEffect> __cdecl CreateEffect( _In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext ) = 0;
|
||||
|
||||
virtual void __cdecl CreateTexture( _In_z_ const wchar_t* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) = 0;
|
||||
};
|
||||
|
||||
|
||||
// Factory for sharing effects and texture resources
|
||||
class EffectFactory : public IEffectFactory
|
||||
{
|
||||
public:
|
||||
explicit EffectFactory(_In_ ID3D11Device* device);
|
||||
EffectFactory(EffectFactory&& moveFrom);
|
||||
EffectFactory& operator= (EffectFactory&& moveFrom);
|
||||
|
||||
EffectFactory(EffectFactory const&) = delete;
|
||||
EffectFactory& operator= (EffectFactory const&) = delete;
|
||||
|
||||
virtual ~EffectFactory();
|
||||
|
||||
// IEffectFactory methods.
|
||||
virtual std::shared_ptr<IEffect> __cdecl CreateEffect( _In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext ) override;
|
||||
virtual void __cdecl CreateTexture( _In_z_ const wchar_t* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) override;
|
||||
|
||||
// Settings.
|
||||
void __cdecl ReleaseCache();
|
||||
|
||||
void __cdecl SetSharing( bool enabled );
|
||||
|
||||
void __cdecl EnableNormalMapEffect( bool enabled );
|
||||
void __cdecl EnableForceSRGB( bool forceSRGB );
|
||||
|
||||
void __cdecl SetDirectory( _In_opt_z_ const wchar_t* path );
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::shared_ptr<Impl> pImpl;
|
||||
};
|
||||
|
||||
|
||||
// Factory for sharing Visual Studio Shader Designer (DGSL) shaders and texture resources
|
||||
class DGSLEffectFactory : public IEffectFactory
|
||||
{
|
||||
public:
|
||||
explicit DGSLEffectFactory(_In_ ID3D11Device* device);
|
||||
DGSLEffectFactory(DGSLEffectFactory&& moveFrom);
|
||||
DGSLEffectFactory& operator= (DGSLEffectFactory&& moveFrom);
|
||||
|
||||
DGSLEffectFactory(DGSLEffectFactory const&) = delete;
|
||||
DGSLEffectFactory& operator= (DGSLEffectFactory const&) = delete;
|
||||
|
||||
virtual ~DGSLEffectFactory();
|
||||
|
||||
// IEffectFactory methods.
|
||||
virtual std::shared_ptr<IEffect> __cdecl CreateEffect( _In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext ) override;
|
||||
virtual void __cdecl CreateTexture( _In_z_ const wchar_t* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) override;
|
||||
|
||||
// DGSL methods.
|
||||
struct DGSLEffectInfo : public EffectInfo
|
||||
{
|
||||
static const int BaseTextureOffset = 3;
|
||||
|
||||
const wchar_t* textures[DGSLEffect::MaxTextures - BaseTextureOffset];
|
||||
const wchar_t* pixelShader;
|
||||
|
||||
DGSLEffectInfo() { memset( this, 0, sizeof(DGSLEffectInfo) ); };
|
||||
};
|
||||
|
||||
virtual std::shared_ptr<IEffect> __cdecl CreateDGSLEffect( _In_ const DGSLEffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext );
|
||||
|
||||
virtual void __cdecl CreatePixelShader( _In_z_ const wchar_t* shader, _Outptr_ ID3D11PixelShader** pixelShader );
|
||||
|
||||
// Settings.
|
||||
void __cdecl ReleaseCache();
|
||||
|
||||
void __cdecl SetSharing( bool enabled );
|
||||
|
||||
void __cdecl EnableForceSRGB( bool forceSRGB );
|
||||
|
||||
void __cdecl SetDirectory( _In_opt_z_ const wchar_t* path );
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::shared_ptr<Impl> pImpl;
|
||||
};
|
||||
|
||||
}
|
||||
272
DirectXTK/Inc/GamePad.h
Normal file
272
DirectXTK/Inc/GamePad.h
Normal file
@@ -0,0 +1,272 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// File: GamePad.h
|
||||
//
|
||||
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
||||
// PARTICULAR PURPOSE.
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248929
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#if (_WIN32_WINNT < 0x0A00 /*_WIN32_WINNT_WIN10*/)
|
||||
#ifndef _XBOX_ONE
|
||||
#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP)
|
||||
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/ )
|
||||
#pragma comment(lib,"xinput.lib")
|
||||
#else
|
||||
#pragma comment(lib,"xinput9_1_0.lib")
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <stdint.h>
|
||||
|
||||
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
|
||||
#include <string>
|
||||
#endif
|
||||
|
||||
|
||||
namespace DirectX
|
||||
{
|
||||
class GamePad
|
||||
{
|
||||
public:
|
||||
GamePad();
|
||||
GamePad(GamePad&& moveFrom);
|
||||
GamePad& operator= (GamePad&& moveFrom);
|
||||
|
||||
GamePad(GamePad const&) = delete;
|
||||
GamePad& operator=(GamePad const&) = delete;
|
||||
|
||||
virtual ~GamePad();
|
||||
|
||||
#if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/ ) || defined(_XBOX_ONE)
|
||||
static const int MAX_PLAYER_COUNT = 8;
|
||||
#else
|
||||
static const int MAX_PLAYER_COUNT = 4;
|
||||
#endif
|
||||
|
||||
enum DeadZone
|
||||
{
|
||||
DEAD_ZONE_INDEPENDENT_AXES = 0,
|
||||
DEAD_ZONE_CIRCULAR,
|
||||
DEAD_ZONE_NONE,
|
||||
};
|
||||
|
||||
struct Buttons
|
||||
{
|
||||
bool a;
|
||||
bool b;
|
||||
bool x;
|
||||
bool y;
|
||||
bool leftStick;
|
||||
bool rightStick;
|
||||
bool leftShoulder;
|
||||
bool rightShoulder;
|
||||
union
|
||||
{
|
||||
bool back;
|
||||
bool view;
|
||||
};
|
||||
union
|
||||
{
|
||||
bool start;
|
||||
bool menu;
|
||||
};
|
||||
};
|
||||
|
||||
struct DPad
|
||||
{
|
||||
bool up;
|
||||
bool down;
|
||||
bool right;
|
||||
bool left;
|
||||
};
|
||||
|
||||
struct ThumbSticks
|
||||
{
|
||||
float leftX;
|
||||
float leftY;
|
||||
float rightX;
|
||||
float rightY;
|
||||
};
|
||||
|
||||
struct Triggers
|
||||
{
|
||||
float left;
|
||||
float right;
|
||||
};
|
||||
|
||||
struct State
|
||||
{
|
||||
bool connected;
|
||||
uint64_t packet;
|
||||
Buttons buttons;
|
||||
DPad dpad;
|
||||
ThumbSticks thumbSticks;
|
||||
Triggers triggers;
|
||||
|
||||
bool __cdecl IsConnected() const { return connected; }
|
||||
|
||||
// Is the button pressed currently?
|
||||
bool __cdecl IsAPressed() const { return buttons.a; }
|
||||
bool __cdecl IsBPressed() const { return buttons.b; }
|
||||
bool __cdecl IsXPressed() const { return buttons.x; }
|
||||
bool __cdecl IsYPressed() const { return buttons.y; }
|
||||
|
||||
bool __cdecl IsLeftStickPressed() const { return buttons.leftStick; }
|
||||
bool __cdecl IsRightStickPressed() const { return buttons.rightStick; }
|
||||
|
||||
bool __cdecl IsLeftShoulderPressed() const { return buttons.leftShoulder; }
|
||||
bool __cdecl IsRightShoulderPressed() const { return buttons.rightShoulder; }
|
||||
|
||||
bool __cdecl IsBackPressed() const { return buttons.back; }
|
||||
bool __cdecl IsViewPressed() const { return buttons.view; }
|
||||
bool __cdecl IsStartPressed() const { return buttons.start; }
|
||||
bool __cdecl IsMenuPressed() const { return buttons.menu; }
|
||||
|
||||
bool __cdecl IsDPadDownPressed() const { return dpad.down; };
|
||||
bool __cdecl IsDPadUpPressed() const { return dpad.up; };
|
||||
bool __cdecl IsDPadLeftPressed() const { return dpad.left; };
|
||||
bool __cdecl IsDPadRightPressed() const { return dpad.right; };
|
||||
|
||||
bool __cdecl IsLeftThumbStickUp() const { return (thumbSticks.leftY > 0.5f) != 0; }
|
||||
bool __cdecl IsLeftThumbStickDown() const { return (thumbSticks.leftY < -0.5f) != 0; }
|
||||
bool __cdecl IsLeftThumbStickLeft() const { return (thumbSticks.leftX < -0.5f) != 0; }
|
||||
bool __cdecl IsLeftThumbStickRight() const { return (thumbSticks.leftX > 0.5f) != 0; }
|
||||
|
||||
bool __cdecl IsRightThumbStickUp() const { return (thumbSticks.rightY > 0.5f ) != 0; }
|
||||
bool __cdecl IsRightThumbStickDown() const { return (thumbSticks.rightY < -0.5f) != 0; }
|
||||
bool __cdecl IsRightThumbStickLeft() const { return (thumbSticks.rightX < -0.5f) != 0; }
|
||||
bool __cdecl IsRightThumbStickRight() const { return (thumbSticks.rightX > 0.5f) != 0; }
|
||||
|
||||
bool __cdecl IsLeftTriggerPressed() const { return (triggers.left > 0.5f) != 0; }
|
||||
bool __cdecl IsRightTriggerPressed() const { return (triggers.right > 0.5f) != 0; }
|
||||
};
|
||||
|
||||
struct Capabilities
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
UNKNOWN = 0,
|
||||
GAMEPAD,
|
||||
WHEEL,
|
||||
ARCADE_STICK,
|
||||
FLIGHT_STICK,
|
||||
DANCE_PAD,
|
||||
GUITAR,
|
||||
GUITAR_ALTERNATE,
|
||||
DRUM_KIT,
|
||||
GUITAR_BASS = 11,
|
||||
ARCADE_PAD = 19,
|
||||
};
|
||||
|
||||
bool connected;
|
||||
Type gamepadType;
|
||||
#if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/)
|
||||
std::wstring id;
|
||||
#else
|
||||
uint64_t id;
|
||||
#endif
|
||||
|
||||
bool __cdecl IsConnected() const { return connected; }
|
||||
};
|
||||
|
||||
class ButtonStateTracker
|
||||
{
|
||||
public:
|
||||
enum ButtonState
|
||||
{
|
||||
UP = 0, // Button is up
|
||||
HELD = 1, // Button is held down
|
||||
RELEASED = 2, // Button was just released
|
||||
PRESSED = 3, // Buton was just pressed
|
||||
};
|
||||
|
||||
ButtonState a;
|
||||
ButtonState b;
|
||||
ButtonState x;
|
||||
ButtonState y;
|
||||
|
||||
ButtonState leftStick;
|
||||
ButtonState rightStick;
|
||||
|
||||
ButtonState leftShoulder;
|
||||
ButtonState rightShoulder;
|
||||
|
||||
union
|
||||
{
|
||||
ButtonState back;
|
||||
ButtonState view;
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
ButtonState start;
|
||||
ButtonState menu;
|
||||
};
|
||||
|
||||
ButtonState dpadUp;
|
||||
ButtonState dpadDown;
|
||||
ButtonState dpadLeft;
|
||||
ButtonState dpadRight;
|
||||
|
||||
ButtonState leftStickUp;
|
||||
ButtonState leftStickDown;
|
||||
ButtonState leftStickLeft;
|
||||
ButtonState leftStickRight;
|
||||
|
||||
ButtonState rightStickUp;
|
||||
ButtonState rightStickDown;
|
||||
ButtonState rightStickLeft;
|
||||
ButtonState rightStickRight;
|
||||
|
||||
ButtonState leftTrigger;
|
||||
ButtonState rightTrigger;
|
||||
|
||||
ButtonStateTracker() { Reset(); }
|
||||
|
||||
void __cdecl Update( const State& state );
|
||||
|
||||
void __cdecl Reset();
|
||||
|
||||
State __cdecl GetLastState() const { return lastState; }
|
||||
|
||||
private:
|
||||
State lastState;
|
||||
};
|
||||
|
||||
// Retrieve the current state of the gamepad of the associated player index
|
||||
State __cdecl GetState(int player, DeadZone deadZoneMode = DEAD_ZONE_INDEPENDENT_AXES);
|
||||
|
||||
// Retrieve the current capabilities of the gamepad of the associated player index
|
||||
Capabilities __cdecl GetCapabilities(int player);
|
||||
|
||||
// Set the vibration motor speeds of the gamepad
|
||||
bool __cdecl SetVibration( int player, float leftMotor, float rightMotor, float leftTrigger = 0.f, float rightTrigger = 0.f );
|
||||
|
||||
// Handle suspending/resuming
|
||||
void __cdecl Suspend();
|
||||
void __cdecl Resume();
|
||||
|
||||
#if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/ ) || defined(_XBOX_ONE)
|
||||
void __cdecl RegisterEvents(void* ctrlChanged, void* userChanged);
|
||||
#endif
|
||||
|
||||
// Singleton
|
||||
static GamePad& __cdecl Get();
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
};
|
||||
}
|
||||
83
DirectXTK/Inc/GeometricPrimitive.h
Normal file
83
DirectXTK/Inc/GeometricPrimitive.h
Normal file
@@ -0,0 +1,83 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// File: GeometricPrimitive.h
|
||||
//
|
||||
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
||||
// PARTICULAR PURPOSE.
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248929
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "VertexTypes.h"
|
||||
|
||||
#include <DirectXColors.h>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace DirectX
|
||||
{
|
||||
class IEffect;
|
||||
|
||||
class GeometricPrimitive
|
||||
{
|
||||
public:
|
||||
GeometricPrimitive(GeometricPrimitive const&) = delete;
|
||||
GeometricPrimitive& operator= (GeometricPrimitive const&) = delete;
|
||||
|
||||
virtual ~GeometricPrimitive();
|
||||
|
||||
// Factory methods.
|
||||
static std::unique_ptr<GeometricPrimitive> __cdecl CreateCube (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
|
||||
static std::unique_ptr<GeometricPrimitive> __cdecl CreateBox (_In_ ID3D11DeviceContext* deviceContext, const XMFLOAT3& size, bool rhcoords = true, bool invertn = false);
|
||||
static std::unique_ptr<GeometricPrimitive> __cdecl CreateSphere (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, size_t tessellation = 16, bool rhcoords = true, bool invertn = false);
|
||||
static std::unique_ptr<GeometricPrimitive> __cdecl CreateGeoSphere (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, size_t tessellation = 3, bool rhcoords = true);
|
||||
static std::unique_ptr<GeometricPrimitive> __cdecl CreateCylinder (_In_ ID3D11DeviceContext* deviceContext, float height = 1, float diameter = 1, size_t tessellation = 32, bool rhcoords = true);
|
||||
static std::unique_ptr<GeometricPrimitive> __cdecl CreateCone (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, float height = 1, size_t tessellation = 32, bool rhcoords = true);
|
||||
static std::unique_ptr<GeometricPrimitive> __cdecl CreateTorus (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, float thickness = 0.333f, size_t tessellation = 32, bool rhcoords = true);
|
||||
static std::unique_ptr<GeometricPrimitive> __cdecl CreateTetrahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
|
||||
static std::unique_ptr<GeometricPrimitive> __cdecl CreateOctahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
|
||||
static std::unique_ptr<GeometricPrimitive> __cdecl CreateDodecahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
|
||||
static std::unique_ptr<GeometricPrimitive> __cdecl CreateIcosahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
|
||||
static std::unique_ptr<GeometricPrimitive> __cdecl CreateTeapot (_In_ ID3D11DeviceContext* deviceContext, float size = 1, size_t tessellation = 8, bool rhcoords = true);
|
||||
static std::unique_ptr<GeometricPrimitive> __cdecl CreateCustom (_In_ ID3D11DeviceContext* deviceContext, const std::vector<VertexPositionNormalTexture>& vertices, const std::vector<uint16_t>& indices);
|
||||
|
||||
static void __cdecl CreateCube (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, float size = 1, bool rhcoords = true);
|
||||
static void __cdecl CreateBox (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, const XMFLOAT3& size, bool rhcoords = true, bool invertn = false);
|
||||
static void __cdecl CreateSphere (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, float diameter = 1, size_t tessellation = 16, bool rhcoords = true, bool invertn = false);
|
||||
static void __cdecl CreateGeoSphere (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, float diameter = 1, size_t tessellation = 3, bool rhcoords = true);
|
||||
static void __cdecl CreateCylinder (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, float height = 1, float diameter = 1, size_t tessellation = 32, bool rhcoords = true);
|
||||
static void __cdecl CreateCone (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, float diameter = 1, float height = 1, size_t tessellation = 32, bool rhcoords = true);
|
||||
static void __cdecl CreateTorus (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, float diameter = 1, float thickness = 0.333f, size_t tessellation = 32, bool rhcoords = true);
|
||||
static void __cdecl CreateTetrahedron (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, float size = 1, bool rhcoords = true);
|
||||
static void __cdecl CreateOctahedron (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, float size = 1, bool rhcoords = true);
|
||||
static void __cdecl CreateDodecahedron (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, float size = 1, bool rhcoords = true);
|
||||
static void __cdecl CreateIcosahedron (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, float size = 1, bool rhcoords = true);
|
||||
static void __cdecl CreateTeapot (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, float size = 1, size_t tessellation = 8, bool rhcoords = true);
|
||||
|
||||
// Draw the primitive.
|
||||
void XM_CALLCONV Draw(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection, FXMVECTOR color = Colors::White, _In_opt_ ID3D11ShaderResourceView* texture = nullptr, bool wireframe = false,
|
||||
_In_opt_ std::function<void __cdecl()> setCustomState = nullptr ) const;
|
||||
|
||||
// Draw the primitive using a custom effect.
|
||||
void __cdecl Draw( _In_ IEffect* effect, _In_ ID3D11InputLayout* inputLayout, bool alpha = false, bool wireframe = false,
|
||||
_In_opt_ std::function<void __cdecl()> setCustomState = nullptr ) const;
|
||||
|
||||
// Create input layout for drawing with a custom effect.
|
||||
void __cdecl CreateInputLayout( _In_ IEffect* effect, _Outptr_ ID3D11InputLayout** inputLayout ) const;
|
||||
|
||||
private:
|
||||
GeometricPrimitive();
|
||||
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
};
|
||||
}
|
||||
56
DirectXTK/Inc/GraphicsMemory.h
Normal file
56
DirectXTK/Inc/GraphicsMemory.h
Normal file
@@ -0,0 +1,56 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// File: GraphicsMemory.h
|
||||
//
|
||||
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
||||
// PARTICULAR PURPOSE.
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248929
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
#include <d3d11_x.h>
|
||||
#else
|
||||
#include <d3d11_1.h>
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace DirectX
|
||||
{
|
||||
class GraphicsMemory
|
||||
{
|
||||
public:
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
GraphicsMemory(_In_ ID3D11DeviceX* device, UINT backBufferCount = 2);
|
||||
#else
|
||||
GraphicsMemory(_In_ ID3D11Device* device, UINT backBufferCount = 2);
|
||||
#endif
|
||||
GraphicsMemory(GraphicsMemory&& moveFrom);
|
||||
GraphicsMemory& operator= (GraphicsMemory&& moveFrom);
|
||||
|
||||
GraphicsMemory(GraphicsMemory const&) = delete;
|
||||
GraphicsMemory& operator=(GraphicsMemory const&) = delete;
|
||||
|
||||
virtual ~GraphicsMemory();
|
||||
|
||||
void* __cdecl Allocate(_In_opt_ ID3D11DeviceContext* context, size_t size, int alignment);
|
||||
|
||||
void __cdecl Commit();
|
||||
|
||||
// Singleton
|
||||
static GraphicsMemory& __cdecl Get();
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
};
|
||||
}
|
||||
482
DirectXTK/Inc/Keyboard.h
Normal file
482
DirectXTK/Inc/Keyboard.h
Normal file
@@ -0,0 +1,482 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// File: Keyboard.h
|
||||
//
|
||||
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
||||
// PARTICULAR PURPOSE.
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248929
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
|
||||
namespace ABI { namespace Windows { namespace UI { namespace Core { struct ICoreWindow; } } } }
|
||||
#endif
|
||||
|
||||
|
||||
namespace DirectX
|
||||
{
|
||||
class Keyboard
|
||||
{
|
||||
public:
|
||||
Keyboard();
|
||||
Keyboard(Keyboard&& moveFrom);
|
||||
Keyboard& operator= (Keyboard&& moveFrom);
|
||||
|
||||
Keyboard(Keyboard const&) = delete;
|
||||
Keyboard& operator=(Keyboard const&) = delete;
|
||||
|
||||
virtual ~Keyboard();
|
||||
|
||||
enum Keys
|
||||
{
|
||||
None = 0,
|
||||
|
||||
Back = 0x8,
|
||||
Tab = 0x9,
|
||||
|
||||
Enter = 0xd,
|
||||
|
||||
Pause = 0x13,
|
||||
CapsLock = 0x14,
|
||||
Kana = 0x15,
|
||||
|
||||
Kanji = 0x19,
|
||||
|
||||
Escape = 0x1b,
|
||||
ImeConvert = 0x1c,
|
||||
ImeNoConvert = 0x1d,
|
||||
|
||||
Space = 0x20,
|
||||
PageUp = 0x21,
|
||||
PageDown = 0x22,
|
||||
End = 0x23,
|
||||
Home = 0x24,
|
||||
Left = 0x25,
|
||||
Up = 0x26,
|
||||
Right = 0x27,
|
||||
Down = 0x28,
|
||||
Select = 0x29,
|
||||
Print = 0x2a,
|
||||
Execute = 0x2b,
|
||||
PrintScreen = 0x2c,
|
||||
Insert = 0x2d,
|
||||
Delete = 0x2e,
|
||||
Help = 0x2f,
|
||||
D0 = 0x30,
|
||||
D1 = 0x31,
|
||||
D2 = 0x32,
|
||||
D3 = 0x33,
|
||||
D4 = 0x34,
|
||||
D5 = 0x35,
|
||||
D6 = 0x36,
|
||||
D7 = 0x37,
|
||||
D8 = 0x38,
|
||||
D9 = 0x39,
|
||||
|
||||
A = 0x41,
|
||||
B = 0x42,
|
||||
C = 0x43,
|
||||
D = 0x44,
|
||||
E = 0x45,
|
||||
F = 0x46,
|
||||
G = 0x47,
|
||||
H = 0x48,
|
||||
I = 0x49,
|
||||
J = 0x4a,
|
||||
K = 0x4b,
|
||||
L = 0x4c,
|
||||
M = 0x4d,
|
||||
N = 0x4e,
|
||||
O = 0x4f,
|
||||
P = 0x50,
|
||||
Q = 0x51,
|
||||
R = 0x52,
|
||||
S = 0x53,
|
||||
T = 0x54,
|
||||
U = 0x55,
|
||||
V = 0x56,
|
||||
W = 0x57,
|
||||
X = 0x58,
|
||||
Y = 0x59,
|
||||
Z = 0x5a,
|
||||
LeftWindows = 0x5b,
|
||||
RightWindows = 0x5c,
|
||||
Apps = 0x5d,
|
||||
|
||||
Sleep = 0x5f,
|
||||
NumPad0 = 0x60,
|
||||
NumPad1 = 0x61,
|
||||
NumPad2 = 0x62,
|
||||
NumPad3 = 0x63,
|
||||
NumPad4 = 0x64,
|
||||
NumPad5 = 0x65,
|
||||
NumPad6 = 0x66,
|
||||
NumPad7 = 0x67,
|
||||
NumPad8 = 0x68,
|
||||
NumPad9 = 0x69,
|
||||
Multiply = 0x6a,
|
||||
Add = 0x6b,
|
||||
Separator = 0x6c,
|
||||
Subtract = 0x6d,
|
||||
|
||||
Decimal = 0x6e,
|
||||
Divide = 0x6f,
|
||||
F1 = 0x70,
|
||||
F2 = 0x71,
|
||||
F3 = 0x72,
|
||||
F4 = 0x73,
|
||||
F5 = 0x74,
|
||||
F6 = 0x75,
|
||||
F7 = 0x76,
|
||||
F8 = 0x77,
|
||||
F9 = 0x78,
|
||||
F10 = 0x79,
|
||||
F11 = 0x7a,
|
||||
F12 = 0x7b,
|
||||
F13 = 0x7c,
|
||||
F14 = 0x7d,
|
||||
F15 = 0x7e,
|
||||
F16 = 0x7f,
|
||||
F17 = 0x80,
|
||||
F18 = 0x81,
|
||||
F19 = 0x82,
|
||||
F20 = 0x83,
|
||||
F21 = 0x84,
|
||||
F22 = 0x85,
|
||||
F23 = 0x86,
|
||||
F24 = 0x87,
|
||||
|
||||
NumLock = 0x90,
|
||||
Scroll = 0x91,
|
||||
|
||||
LeftShift = 0xa0,
|
||||
RightShift = 0xa1,
|
||||
LeftControl = 0xa2,
|
||||
RightControl = 0xa3,
|
||||
LeftAlt = 0xa4,
|
||||
RightAlt = 0xa5,
|
||||
BrowserBack = 0xa6,
|
||||
BrowserForward = 0xa7,
|
||||
BrowserRefresh = 0xa8,
|
||||
BrowserStop = 0xa9,
|
||||
BrowserSearch = 0xaa,
|
||||
BrowserFavorites = 0xab,
|
||||
BrowserHome = 0xac,
|
||||
VolumeMute = 0xad,
|
||||
VolumeDown = 0xae,
|
||||
VolumeUp = 0xaf,
|
||||
MediaNextTrack = 0xb0,
|
||||
MediaPreviousTrack = 0xb1,
|
||||
MediaStop = 0xb2,
|
||||
MediaPlayPause = 0xb3,
|
||||
LaunchMail = 0xb4,
|
||||
SelectMedia = 0xb5,
|
||||
LaunchApplication1 = 0xb6,
|
||||
LaunchApplication2 = 0xb7,
|
||||
|
||||
OemSemicolon = 0xba,
|
||||
OemPlus = 0xbb,
|
||||
OemComma = 0xbc,
|
||||
OemMinus = 0xbd,
|
||||
OemPeriod = 0xbe,
|
||||
OemQuestion = 0xbf,
|
||||
OemTilde = 0xc0,
|
||||
|
||||
OemOpenBrackets = 0xdb,
|
||||
OemPipe = 0xdc,
|
||||
OemCloseBrackets = 0xdd,
|
||||
OemQuotes = 0xde,
|
||||
Oem8 = 0xdf,
|
||||
|
||||
OemBackslash = 0xe2,
|
||||
|
||||
ProcessKey = 0xe5,
|
||||
|
||||
OemCopy = 0xf2,
|
||||
OemAuto = 0xf3,
|
||||
OemEnlW = 0xf4,
|
||||
|
||||
Attn = 0xf6,
|
||||
Crsel = 0xf7,
|
||||
Exsel = 0xf8,
|
||||
EraseEof = 0xf9,
|
||||
Play = 0xfa,
|
||||
Zoom = 0xfb,
|
||||
|
||||
Pa1 = 0xfd,
|
||||
OemClear = 0xfe,
|
||||
};
|
||||
|
||||
struct State
|
||||
{
|
||||
bool Reserved0 : 8;
|
||||
bool Back : 1; // VK_BACK, 0x8
|
||||
bool Tab : 1; // VK_TAB, 0x9
|
||||
bool Reserved1 : 3;
|
||||
bool Enter : 1; // VK_RETURN, 0xD
|
||||
bool Reserved2 : 2;
|
||||
bool Reserved3 : 3;
|
||||
bool Pause : 1; // VK_PAUSE, 0x13
|
||||
bool CapsLock : 1; // VK_CAPITAL, 0x14
|
||||
bool Kana : 1; // VK_KANA, 0x15
|
||||
bool Reserved4 : 2;
|
||||
bool Reserved5 : 1;
|
||||
bool Kanji : 1; // VK_KANJI, 0x19
|
||||
bool Reserved6 : 1;
|
||||
bool Escape : 1; // VK_ESCAPE, 0x1B
|
||||
bool ImeConvert : 1; // VK_CONVERT, 0x1C
|
||||
bool ImeNoConvert : 1; // VK_NONCONVERT, 0x1D
|
||||
bool Reserved7 : 2;
|
||||
bool Space : 1; // VK_SPACE, 0x20
|
||||
bool PageUp : 1; // VK_PRIOR, 0x21
|
||||
bool PageDown : 1; // VK_NEXT, 0x22
|
||||
bool End : 1; // VK_END, 0x23
|
||||
bool Home : 1; // VK_HOME, 0x24
|
||||
bool Left : 1; // VK_LEFT, 0x25
|
||||
bool Up : 1; // VK_UP, 0x26
|
||||
bool Right : 1; // VK_RIGHT, 0x27
|
||||
bool Down : 1; // VK_DOWN, 0x28
|
||||
bool Select : 1; // VK_SELECT, 0x29
|
||||
bool Print : 1; // VK_PRINT, 0x2A
|
||||
bool Execute : 1; // VK_EXECUTE, 0x2B
|
||||
bool PrintScreen : 1; // VK_SNAPSHOT, 0x2C
|
||||
bool Insert : 1; // VK_INSERT, 0x2D
|
||||
bool Delete : 1; // VK_DELETE, 0x2E
|
||||
bool Help : 1; // VK_HELP, 0x2F
|
||||
bool D0 : 1; // 0x30
|
||||
bool D1 : 1; // 0x31
|
||||
bool D2 : 1; // 0x32
|
||||
bool D3 : 1; // 0x33
|
||||
bool D4 : 1; // 0x34
|
||||
bool D5 : 1; // 0x35
|
||||
bool D6 : 1; // 0x36
|
||||
bool D7 : 1; // 0x37
|
||||
bool D8 : 1; // 0x38
|
||||
bool D9 : 1; // 0x39
|
||||
bool Reserved8 : 6;
|
||||
bool Reserved9 : 1;
|
||||
bool A : 1; // 0x41
|
||||
bool B : 1; // 0x42
|
||||
bool C : 1; // 0x43
|
||||
bool D : 1; // 0x44
|
||||
bool E : 1; // 0x45
|
||||
bool F : 1; // 0x46
|
||||
bool G : 1; // 0x47
|
||||
bool H : 1; // 0x48
|
||||
bool I : 1; // 0x49
|
||||
bool J : 1; // 0x4A
|
||||
bool K : 1; // 0x4B
|
||||
bool L : 1; // 0x4C
|
||||
bool M : 1; // 0x4D
|
||||
bool N : 1; // 0x4E
|
||||
bool O : 1; // 0x4F
|
||||
bool P : 1; // 0x50
|
||||
bool Q : 1; // 0x51
|
||||
bool R : 1; // 0x52
|
||||
bool S : 1; // 0x53
|
||||
bool T : 1; // 0x54
|
||||
bool U : 1; // 0x55
|
||||
bool V : 1; // 0x56
|
||||
bool W : 1; // 0x57
|
||||
bool X : 1; // 0x58
|
||||
bool Y : 1; // 0x59
|
||||
bool Z : 1; // 0x5A
|
||||
bool LeftWindows : 1; // VK_LWIN, 0x5B
|
||||
bool RightWindows : 1; // VK_RWIN, 0x5C
|
||||
bool Apps : 1; // VK_APPS, 0x5D
|
||||
bool Reserved10 : 1;
|
||||
bool Sleep : 1; // VK_SLEEP, 0x5F
|
||||
bool NumPad0 : 1; // VK_NUMPAD0, 0x60
|
||||
bool NumPad1 : 1; // VK_NUMPAD1, 0x61
|
||||
bool NumPad2 : 1; // VK_NUMPAD2, 0x62
|
||||
bool NumPad3 : 1; // VK_NUMPAD3, 0x63
|
||||
bool NumPad4 : 1; // VK_NUMPAD4, 0x64
|
||||
bool NumPad5 : 1; // VK_NUMPAD5, 0x65
|
||||
bool NumPad6 : 1; // VK_NUMPAD6, 0x66
|
||||
bool NumPad7 : 1; // VK_NUMPAD7, 0x67
|
||||
bool NumPad8 : 1; // VK_NUMPAD8, 0x68
|
||||
bool NumPad9 : 1; // VK_NUMPAD9, 0x69
|
||||
bool Multiply : 1; // VK_MULTIPLY, 0x6A
|
||||
bool Add : 1; // VK_ADD, 0x6B
|
||||
bool Separator : 1; // VK_SEPARATOR, 0x6C
|
||||
bool Subtract : 1; // VK_SUBTRACT, 0x6D
|
||||
bool Decimal : 1; // VK_DECIMANL, 0x6E
|
||||
bool Divide : 1; // VK_DIVIDE, 0x6F
|
||||
bool F1 : 1; // VK_F1, 0x70
|
||||
bool F2 : 1; // VK_F2, 0x71
|
||||
bool F3 : 1; // VK_F3, 0x72
|
||||
bool F4 : 1; // VK_F4, 0x73
|
||||
bool F5 : 1; // VK_F5, 0x74
|
||||
bool F6 : 1; // VK_F6, 0x75
|
||||
bool F7 : 1; // VK_F7, 0x76
|
||||
bool F8 : 1; // VK_F8, 0x77
|
||||
bool F9 : 1; // VK_F9, 0x78
|
||||
bool F10 : 1; // VK_F10, 0x79
|
||||
bool F11 : 1; // VK_F11, 0x7A
|
||||
bool F12 : 1; // VK_F12, 0x7B
|
||||
bool F13 : 1; // VK_F13, 0x7C
|
||||
bool F14 : 1; // VK_F14, 0x7D
|
||||
bool F15 : 1; // VK_F15, 0x7E
|
||||
bool F16 : 1; // VK_F16, 0x7F
|
||||
bool F17 : 1; // VK_F17, 0x80
|
||||
bool F18 : 1; // VK_F18, 0x81
|
||||
bool F19 : 1; // VK_F19, 0x82
|
||||
bool F20 : 1; // VK_F20, 0x83
|
||||
bool F21 : 1; // VK_F21, 0x84
|
||||
bool F22 : 1; // VK_F22, 0x85
|
||||
bool F23 : 1; // VK_F23, 0x86
|
||||
bool F24 : 1; // VK_F24, 0x87
|
||||
bool Reserved11 : 8;
|
||||
bool NumLock : 1; // VK_NUMLOCK, 0x90
|
||||
bool Scroll : 1; // VK_SCROLL, 0x91
|
||||
bool Reserved12 : 6;
|
||||
bool Reserved13 : 8;
|
||||
bool LeftShift : 1; // VK_LSHIFT, 0xA0
|
||||
bool RightShift : 1; // VK_RSHIFT, 0xA1
|
||||
bool LeftControl : 1; // VK_LCONTROL, 0xA2
|
||||
bool RightControl : 1; // VK_RCONTROL, 0xA3
|
||||
bool LeftAlt : 1; // VK_LMENU, 0xA4
|
||||
bool RightAlt : 1; // VK_RMENU, 0xA5
|
||||
bool BrowserBack : 1; // VK_BROWSER_BACK, 0xA6
|
||||
bool BrowserForward : 1; // VK_BROWSER_FORWARD, 0xA7
|
||||
bool BrowserRefresh : 1; // VK_BROWSER_REFRESH, 0xA8
|
||||
bool BrowserStop : 1; // VK_BROWSER_STOP, 0xA9
|
||||
bool BrowserSearch : 1; // VK_BROWSER_SEARCH, 0xAA
|
||||
bool BrowserFavorites : 1; // VK_BROWSER_FAVORITES, 0xAB
|
||||
bool BrowserHome : 1; // VK_BROWSER_HOME, 0xAC
|
||||
bool VolumeMute : 1; // VK_VOLUME_MUTE, 0xAD
|
||||
bool VolumeDown : 1; // VK_VOLUME_DOWN, 0xAE
|
||||
bool VolumeUp : 1; // VK_VOLUME_UP, 0xAF
|
||||
bool MediaNextTrack : 1; // VK_MEDIA_NEXT_TRACK, 0xB0
|
||||
bool MediaPreviousTrack : 1;// VK_MEDIA_PREV_TRACK, 0xB1
|
||||
bool MediaStop : 1; // VK_MEDIA_STOP, 0xB2
|
||||
bool MediaPlayPause : 1; // VK_MEDIA_PLAY_PAUSE, 0xB3
|
||||
bool LaunchMail : 1; // VK_LAUNCH_MAIL, 0xB4
|
||||
bool SelectMedia : 1; // VK_LAUNCH_MEDIA_SELECT, 0xB5
|
||||
bool LaunchApplication1 : 1;// VK_LAUNCH_APP1, 0xB6
|
||||
bool LaunchApplication2 : 1;// VK_LAUNCH_APP2, 0xB7
|
||||
bool Reserved14 : 2;
|
||||
bool OemSemicolon : 1; // VK_OEM_1, 0xBA
|
||||
bool OemPlus : 1; // VK_OEM_PLUS, 0xBB
|
||||
bool OemComma : 1; // VK_OEM_COMMA, 0xBC
|
||||
bool OemMinus : 1; // VK_OEM_MINUS, 0xBD
|
||||
bool OemPeriod : 1; // VK_OEM_PERIOD, 0xBE
|
||||
bool OemQuestion : 1; // VK_OEM_2, 0xBF
|
||||
bool OemTilde : 1; // VK_OEM_3, 0xC0
|
||||
bool Reserved15 : 7;
|
||||
bool Reserved16 : 8;
|
||||
bool Reserved17 : 8;
|
||||
bool Reserved18 : 3;
|
||||
bool OemOpenBrackets : 1; // VK_OEM_4, 0xDB
|
||||
bool OemPipe : 1; // VK_OEM_5, 0xDC
|
||||
bool OemCloseBrackets : 1; // VK_OEM_6, 0xDD
|
||||
bool OemQuotes : 1; // VK_OEM_7, 0xDE
|
||||
bool Oem8 : 1; // VK_OEM_8, 0xDF
|
||||
bool Reserved19 : 2;
|
||||
bool OemBackslash : 1; // VK_OEM_102, 0xE2
|
||||
bool Reserved20 : 2;
|
||||
bool ProcessKey : 1; // VK_PROCESSKEY, 0xE5
|
||||
bool Reserved21 : 2;
|
||||
bool Reserved22 : 8;
|
||||
bool Reserved23 : 2;
|
||||
bool OemCopy : 1; // 0XF2
|
||||
bool OemAuto : 1; // 0xF3
|
||||
bool OemEnlW : 1; // 0xF4
|
||||
bool Reserved24 : 1;
|
||||
bool Attn : 1; // VK_ATTN, 0xF6
|
||||
bool Crsel : 1; // VK_CRSEL, 0xF7
|
||||
bool Exsel : 1; // VK_EXSEL, 0xF8
|
||||
bool EraseEof : 1; // VK_EREOF, 0xF9
|
||||
bool Play : 1; // VK_PLAY, 0xFA
|
||||
bool Zoom : 1; // VK_ZOOM, 0xFB
|
||||
bool Reserved25 : 1;
|
||||
bool Pa1 : 1; // VK_PA1, 0xFD
|
||||
bool OemClear : 1; // VK_OEM_CLEAR, 0xFE
|
||||
bool Reserved26: 1;
|
||||
|
||||
bool __cdecl IsKeyDown(Keys key) const
|
||||
{
|
||||
if (key >= 0 && key <= 0xfe)
|
||||
{
|
||||
auto ptr = reinterpret_cast<const uint32_t*>(this);
|
||||
unsigned int bf = 1u << (key & 0x1f);
|
||||
return (ptr[(key >> 5)] & bf) != 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool __cdecl IsKeyUp(Keys key) const
|
||||
{
|
||||
if (key >= 0 && key <= 0xfe)
|
||||
{
|
||||
auto ptr = reinterpret_cast<const uint32_t*>(this);
|
||||
unsigned int bf = 1u << (key & 0x1f);
|
||||
return (ptr[(key >> 5)] & bf) == 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class KeyboardStateTracker
|
||||
{
|
||||
public:
|
||||
State released;
|
||||
State pressed;
|
||||
|
||||
KeyboardStateTracker() { Reset(); }
|
||||
|
||||
void __cdecl Update(const State& state);
|
||||
|
||||
void __cdecl Reset();
|
||||
|
||||
bool __cdecl IsKeyPressed(Keys key) const { return pressed.IsKeyDown(key); }
|
||||
bool __cdecl IsKeyReleased(Keys key) const { return released.IsKeyDown(key); }
|
||||
|
||||
State __cdecl GetLastState() const { return lastState; }
|
||||
|
||||
public:
|
||||
State lastState;
|
||||
};
|
||||
|
||||
// Retrieve the current state of the keyboard
|
||||
State __cdecl GetState() const;
|
||||
|
||||
// Reset the keyboard state
|
||||
void __cdecl Reset();
|
||||
|
||||
// Feature detection
|
||||
bool __cdecl IsConnected() const;
|
||||
|
||||
#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP) && defined(WM_USER)
|
||||
static void __cdecl ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam);
|
||||
#endif
|
||||
|
||||
#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
|
||||
void __cdecl SetWindow(ABI::Windows::UI::Core::ICoreWindow* window);
|
||||
#ifdef __cplusplus_winrt
|
||||
void __cdecl SetWindow(Windows::UI::Core::CoreWindow^ window)
|
||||
{
|
||||
// See https://msdn.microsoft.com/en-us/library/hh755802.aspx
|
||||
SetWindow(reinterpret_cast<ABI::Windows::UI::Core::ICoreWindow*>(window));
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Singleton
|
||||
static Keyboard& __cdecl Get();
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
};
|
||||
}
|
||||
145
DirectXTK/Inc/Model.h
Normal file
145
DirectXTK/Inc/Model.h
Normal file
@@ -0,0 +1,145 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// File: Model.h
|
||||
//
|
||||
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
||||
// PARTICULAR PURPOSE.
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248929
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
#include <d3d11_x.h>
|
||||
#else
|
||||
#include <d3d11_1.h>
|
||||
#endif
|
||||
|
||||
#include <DirectXMath.h>
|
||||
#include <DirectXCollision.h>
|
||||
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <wrl\client.h>
|
||||
|
||||
|
||||
namespace DirectX
|
||||
{
|
||||
class IEffect;
|
||||
class IEffectFactory;
|
||||
class CommonStates;
|
||||
class ModelMesh;
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Each mesh part is a submesh with a single effect
|
||||
class ModelMeshPart
|
||||
{
|
||||
public:
|
||||
ModelMeshPart();
|
||||
virtual ~ModelMeshPart();
|
||||
|
||||
uint32_t indexCount;
|
||||
uint32_t startIndex;
|
||||
uint32_t vertexOffset;
|
||||
uint32_t vertexStride;
|
||||
D3D_PRIMITIVE_TOPOLOGY primitiveType;
|
||||
DXGI_FORMAT indexFormat;
|
||||
Microsoft::WRL::ComPtr<ID3D11InputLayout> inputLayout;
|
||||
Microsoft::WRL::ComPtr<ID3D11Buffer> indexBuffer;
|
||||
Microsoft::WRL::ComPtr<ID3D11Buffer> vertexBuffer;
|
||||
std::shared_ptr<IEffect> effect;
|
||||
std::shared_ptr<std::vector<D3D11_INPUT_ELEMENT_DESC>> vbDecl;
|
||||
bool isAlpha;
|
||||
|
||||
typedef std::vector<std::unique_ptr<ModelMeshPart>> Collection;
|
||||
|
||||
// Draw mesh part with custom effect
|
||||
void __cdecl Draw( _In_ ID3D11DeviceContext* deviceContext, _In_ IEffect* ieffect, _In_ ID3D11InputLayout* iinputLayout,
|
||||
_In_opt_ std::function<void __cdecl()> setCustomState = nullptr ) const;
|
||||
|
||||
// Create input layout for drawing with a custom effect.
|
||||
void __cdecl CreateInputLayout( _In_ ID3D11Device* d3dDevice, _In_ IEffect* ieffect, _Outptr_ ID3D11InputLayout** iinputLayout ) const;
|
||||
|
||||
// Change effect used by part and regenerate input layout (be sure to call Model::Modified as well)
|
||||
void __cdecl ModifyEffect( _In_ ID3D11Device* d3dDevice, _In_ std::shared_ptr<IEffect>& ieffect, bool isalpha = false );
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// A mesh consists of one or more model mesh parts
|
||||
class ModelMesh
|
||||
{
|
||||
public:
|
||||
ModelMesh();
|
||||
virtual ~ModelMesh();
|
||||
|
||||
BoundingSphere boundingSphere;
|
||||
BoundingBox boundingBox;
|
||||
ModelMeshPart::Collection meshParts;
|
||||
std::wstring name;
|
||||
bool ccw;
|
||||
bool pmalpha;
|
||||
|
||||
typedef std::vector<std::shared_ptr<ModelMesh>> Collection;
|
||||
|
||||
// Setup states for drawing mesh
|
||||
void __cdecl PrepareForRendering( _In_ ID3D11DeviceContext* deviceContext, const CommonStates& states, bool alpha = false, bool wireframe = false ) const;
|
||||
|
||||
// Draw the mesh
|
||||
void XM_CALLCONV Draw( _In_ ID3D11DeviceContext* deviceContext, FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection,
|
||||
bool alpha = false, _In_opt_ std::function<void __cdecl()> setCustomState = nullptr ) const;
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// A model consists of one or more meshes
|
||||
class Model
|
||||
{
|
||||
public:
|
||||
virtual ~Model();
|
||||
|
||||
ModelMesh::Collection meshes;
|
||||
std::wstring name;
|
||||
|
||||
// Draw all the meshes in the model
|
||||
void XM_CALLCONV Draw( _In_ ID3D11DeviceContext* deviceContext, const CommonStates& states, FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection,
|
||||
bool wireframe = false, _In_opt_ std::function<void __cdecl()> setCustomState = nullptr ) const;
|
||||
|
||||
// Notify model that effects, parts list, or mesh list has changed
|
||||
void __cdecl Modified() { mEffectCache.clear(); }
|
||||
|
||||
// Update all effects used by the model
|
||||
void __cdecl UpdateEffects( _In_ std::function<void __cdecl(IEffect*)> setEffect );
|
||||
|
||||
// Loads a model from a Visual Studio Starter Kit .CMO file
|
||||
static std::unique_ptr<Model> __cdecl CreateFromCMO( _In_ ID3D11Device* d3dDevice, _In_reads_bytes_(dataSize) const uint8_t* meshData, size_t dataSize,
|
||||
_In_ IEffectFactory& fxFactory, bool ccw = true, bool pmalpha = false );
|
||||
static std::unique_ptr<Model> __cdecl CreateFromCMO( _In_ ID3D11Device* d3dDevice, _In_z_ const wchar_t* szFileName,
|
||||
_In_ IEffectFactory& fxFactory, bool ccw = true, bool pmalpha = false );
|
||||
|
||||
// Loads a model from a DirectX SDK .SDKMESH file
|
||||
static std::unique_ptr<Model> __cdecl CreateFromSDKMESH( _In_ ID3D11Device* d3dDevice, _In_reads_bytes_(dataSize) const uint8_t* meshData, _In_ size_t dataSize,
|
||||
_In_ IEffectFactory& fxFactory, bool ccw = false, bool pmalpha = false );
|
||||
static std::unique_ptr<Model> __cdecl CreateFromSDKMESH( _In_ ID3D11Device* d3dDevice, _In_z_ const wchar_t* szFileName,
|
||||
_In_ IEffectFactory& fxFactory, bool ccw = false, bool pmalpha = false );
|
||||
|
||||
// Loads a model from a .VBO file
|
||||
static std::unique_ptr<Model> __cdecl CreateFromVBO( _In_ ID3D11Device* d3dDevice, _In_reads_bytes_(dataSize) const uint8_t* meshData, _In_ size_t dataSize,
|
||||
_In_opt_ std::shared_ptr<IEffect> ieffect = nullptr, bool ccw = false, bool pmalpha = false );
|
||||
static std::unique_ptr<Model> __cdecl CreateFromVBO( _In_ ID3D11Device* d3dDevice, _In_z_ const wchar_t* szFileName,
|
||||
_In_opt_ std::shared_ptr<IEffect> ieffect = nullptr, bool ccw = false, bool pmalpha = false );
|
||||
|
||||
private:
|
||||
std::set<IEffect*> mEffectCache;
|
||||
};
|
||||
}
|
||||
123
DirectXTK/Inc/Mouse.h
Normal file
123
DirectXTK/Inc/Mouse.h
Normal file
@@ -0,0 +1,123 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// File: Mouse.h
|
||||
//
|
||||
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
||||
// PARTICULAR PURPOSE.
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248929
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
|
||||
namespace ABI { namespace Windows { namespace UI { namespace Core { struct ICoreWindow; } } } }
|
||||
#endif
|
||||
|
||||
|
||||
namespace DirectX
|
||||
{
|
||||
class Mouse
|
||||
{
|
||||
public:
|
||||
Mouse();
|
||||
Mouse(Mouse&& moveFrom);
|
||||
Mouse& operator= (Mouse&& moveFrom);
|
||||
|
||||
Mouse(Mouse const&) = delete;
|
||||
Mouse& operator=(Mouse const&) = delete;
|
||||
|
||||
virtual ~Mouse();
|
||||
|
||||
enum Mode
|
||||
{
|
||||
MODE_ABSOLUTE = 0,
|
||||
MODE_RELATIVE,
|
||||
};
|
||||
|
||||
struct State
|
||||
{
|
||||
bool leftButton;
|
||||
bool middleButton;
|
||||
bool rightButton;
|
||||
bool xButton1;
|
||||
bool xButton2;
|
||||
int x;
|
||||
int y;
|
||||
int scrollWheelValue;
|
||||
Mode positionMode;
|
||||
};
|
||||
|
||||
class ButtonStateTracker
|
||||
{
|
||||
public:
|
||||
enum ButtonState
|
||||
{
|
||||
UP = 0, // Button is up
|
||||
HELD = 1, // Button is held down
|
||||
RELEASED = 2, // Button was just released
|
||||
PRESSED = 3, // Buton was just pressed
|
||||
};
|
||||
|
||||
ButtonState leftButton;
|
||||
ButtonState middleButton;
|
||||
ButtonState rightButton;
|
||||
ButtonState xButton1;
|
||||
ButtonState xButton2;
|
||||
|
||||
ButtonStateTracker() { Reset(); }
|
||||
|
||||
void __cdecl Update( const State& state );
|
||||
|
||||
void __cdecl Reset();
|
||||
|
||||
State __cdecl GetLastState() const { return lastState; }
|
||||
|
||||
private:
|
||||
State lastState;
|
||||
};
|
||||
|
||||
// Retrieve the current state of the mouse
|
||||
State __cdecl GetState() const;
|
||||
|
||||
// Resets the accumulated scroll wheel value
|
||||
void __cdecl ResetScrollWheelValue();
|
||||
|
||||
// Sets mouse mode (defaults to absolute)
|
||||
void __cdecl SetMode(Mode mode);
|
||||
|
||||
// Feature detection
|
||||
bool __cdecl IsConnected() const;
|
||||
|
||||
#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP) && defined(WM_USER)
|
||||
void __cdecl SetWindow(HWND window);
|
||||
static void __cdecl ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam);
|
||||
#endif
|
||||
|
||||
#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
|
||||
void __cdecl SetWindow(ABI::Windows::UI::Core::ICoreWindow* window);
|
||||
#ifdef __cplusplus_winrt
|
||||
void __cdecl SetWindow(Windows::UI::Core::CoreWindow^ window)
|
||||
{
|
||||
// See https://msdn.microsoft.com/en-us/library/hh755802.aspx
|
||||
SetWindow(reinterpret_cast<ABI::Windows::UI::Core::ICoreWindow*>(window));
|
||||
}
|
||||
#endif
|
||||
static void __cdecl SetDpi(float dpi);
|
||||
#endif
|
||||
|
||||
// Singleton
|
||||
static Mouse& __cdecl Get();
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
};
|
||||
}
|
||||
201
DirectXTK/Inc/PostProcess.h
Normal file
201
DirectXTK/Inc/PostProcess.h
Normal file
@@ -0,0 +1,201 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// File: PostProcess.h
|
||||
//
|
||||
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
||||
// PARTICULAR PURPOSE.
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248929
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
||||
#error Post-processing not supported for Windows Phone 8.x; requires Direct3D hardware Feature Level 10.0 or better
|
||||
#endif
|
||||
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
#include <d3d11_x.h>
|
||||
#else
|
||||
#include <d3d11_1.h>
|
||||
#endif
|
||||
|
||||
#include <DirectXMath.h>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
|
||||
namespace DirectX
|
||||
{
|
||||
//----------------------------------------------------------------------------------
|
||||
// Abstract interface representing a post-process pass
|
||||
class IPostProcess
|
||||
{
|
||||
public:
|
||||
virtual ~IPostProcess() { }
|
||||
|
||||
virtual void __cdecl Process(_In_ ID3D11DeviceContext* deviceContext, _In_opt_ std::function<void __cdecl()> setCustomState = nullptr) = 0;
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Basic post-process
|
||||
class BasicPostProcess : public IPostProcess
|
||||
{
|
||||
public:
|
||||
enum Effect
|
||||
{
|
||||
Copy,
|
||||
Monochrome,
|
||||
Sepia,
|
||||
DownScale_2x2,
|
||||
DownScale_4x4,
|
||||
GaussianBlur_5x5,
|
||||
BloomExtract,
|
||||
BloomBlur,
|
||||
Effect_Max
|
||||
};
|
||||
|
||||
explicit BasicPostProcess(_In_ ID3D11Device* device);
|
||||
BasicPostProcess(BasicPostProcess&& moveFrom);
|
||||
BasicPostProcess& operator= (BasicPostProcess&& moveFrom);
|
||||
|
||||
BasicPostProcess(BasicPostProcess const&) = delete;
|
||||
BasicPostProcess& operator= (BasicPostProcess const&) = delete;
|
||||
|
||||
virtual ~BasicPostProcess();
|
||||
|
||||
// IPostProcess methods.
|
||||
void __cdecl Process(_In_ ID3D11DeviceContext* deviceContext, _In_opt_ std::function<void __cdecl()> setCustomState = nullptr) override;
|
||||
|
||||
// Shader control
|
||||
void __cdecl SetEffect(Effect fx);
|
||||
|
||||
// Properties
|
||||
void __cdecl SetSourceTexture(_In_opt_ ID3D11ShaderResourceView* value);
|
||||
|
||||
// Sets multiplier for GaussianBlur_5x5
|
||||
void __cdecl SetGaussianParameter(float multiplier);
|
||||
|
||||
// Sets parameters for BloomExtract
|
||||
void __cdecl SetBloomExtractParameter(float threshold);
|
||||
|
||||
// Sets parameters for BloomBlur
|
||||
void __cdecl SetBloomBlurParameters(bool horizontal, float size, float brightness);
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Dual-texure post-process
|
||||
class DualPostProcess : public IPostProcess
|
||||
{
|
||||
public:
|
||||
enum Effect
|
||||
{
|
||||
Merge,
|
||||
BloomCombine,
|
||||
Effect_Max
|
||||
};
|
||||
|
||||
explicit DualPostProcess(_In_ ID3D11Device* device);
|
||||
DualPostProcess(DualPostProcess&& moveFrom);
|
||||
DualPostProcess& operator= (DualPostProcess&& moveFrom);
|
||||
|
||||
DualPostProcess(DualPostProcess const&) = delete;
|
||||
DualPostProcess& operator= (DualPostProcess const&) = delete;
|
||||
|
||||
virtual ~DualPostProcess();
|
||||
|
||||
// IPostProcess methods.
|
||||
void __cdecl Process(_In_ ID3D11DeviceContext* deviceContext, _In_opt_ std::function<void __cdecl()> setCustomState = nullptr) override;
|
||||
|
||||
// Shader control
|
||||
void __cdecl SetEffect(Effect fx);
|
||||
|
||||
// Properties
|
||||
void __cdecl SetSourceTexture(_In_opt_ ID3D11ShaderResourceView* value);
|
||||
void __cdecl SetSourceTexture2(_In_opt_ ID3D11ShaderResourceView* value);
|
||||
|
||||
// Sets parameters for Merge
|
||||
void __cdecl SetMergeParameters(float weight1, float weight2);
|
||||
|
||||
// Sets parameters for BloomCombine
|
||||
void __cdecl SetBloomCombineParameters(float bloom, float base, float bloomSaturation, float baseSaturation);
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Tone-map post-process
|
||||
class ToneMapPostProcess : public IPostProcess
|
||||
{
|
||||
public:
|
||||
enum Operator // Tone-mapping operator
|
||||
{
|
||||
None, // Pass-through
|
||||
Saturate, // Clamp [0,1]
|
||||
Reinhard, // x/(1+x)
|
||||
ACESFilmic,
|
||||
Operator_Max
|
||||
};
|
||||
|
||||
enum TransferFunction // Electro-Optical Transfer Function (EOTF)
|
||||
{
|
||||
Linear, // Pass-through
|
||||
SRGB, // sRGB (Rec.709 and approximate sRGB display curve)
|
||||
ST2084, // HDR10 (Rec.2020 color primaries and ST.2084 display curve)
|
||||
TransferFunction_Max
|
||||
};
|
||||
|
||||
explicit ToneMapPostProcess(_In_ ID3D11Device* device);
|
||||
ToneMapPostProcess(ToneMapPostProcess&& moveFrom);
|
||||
ToneMapPostProcess& operator= (ToneMapPostProcess&& moveFrom);
|
||||
|
||||
ToneMapPostProcess(ToneMapPostProcess const&) = delete;
|
||||
ToneMapPostProcess& operator= (ToneMapPostProcess const&) = delete;
|
||||
|
||||
virtual ~ToneMapPostProcess();
|
||||
|
||||
// IPostProcess methods.
|
||||
void __cdecl Process(_In_ ID3D11DeviceContext* deviceContext, _In_opt_ std::function<void __cdecl()> setCustomState = nullptr) override;
|
||||
|
||||
// Shader control
|
||||
void __cdecl SetOperator(Operator op);
|
||||
|
||||
void __cdecl SetTransferFunction(TransferFunction func);
|
||||
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
// Uses Multiple Render Targets to generate both HDR10 and GameDVR SDR signals
|
||||
void __cdecl SetMRTOutput(bool value = true);
|
||||
#endif
|
||||
|
||||
// Properties
|
||||
void __cdecl SetHDRSourceTexture(_In_opt_ ID3D11ShaderResourceView* value);
|
||||
|
||||
// Sets exposure value for LDR tonemap operators
|
||||
void SetExposure(float exposureValue);
|
||||
|
||||
// Sets ST.2084 parameter for how bright white should be in nits
|
||||
void SetST2084Parameter(float paperWhiteNits);
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
};
|
||||
}
|
||||
143
DirectXTK/Inc/PrimitiveBatch.h
Normal file
143
DirectXTK/Inc/PrimitiveBatch.h
Normal file
@@ -0,0 +1,143 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// File: PrimitiveBatch.h
|
||||
//
|
||||
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
||||
// PARTICULAR PURPOSE.
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248929
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
#include <d3d11_x.h>
|
||||
#else
|
||||
#include <d3d11_1.h>
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
namespace DirectX
|
||||
{
|
||||
namespace Internal
|
||||
{
|
||||
// Base class, not to be used directly: clients should access this via the derived PrimitiveBatch<T>.
|
||||
class PrimitiveBatchBase
|
||||
{
|
||||
protected:
|
||||
PrimitiveBatchBase(_In_ ID3D11DeviceContext* deviceContext, size_t maxIndices, size_t maxVertices, size_t vertexSize);
|
||||
PrimitiveBatchBase(PrimitiveBatchBase&& moveFrom);
|
||||
PrimitiveBatchBase& operator= (PrimitiveBatchBase&& moveFrom);
|
||||
|
||||
PrimitiveBatchBase(PrimitiveBatchBase const&) = delete;
|
||||
PrimitiveBatchBase& operator= (PrimitiveBatchBase const&) = delete;
|
||||
|
||||
virtual ~PrimitiveBatchBase();
|
||||
|
||||
public:
|
||||
// Begin/End a batch of primitive drawing operations.
|
||||
void __cdecl Begin();
|
||||
void __cdecl End();
|
||||
|
||||
protected:
|
||||
// Internal, untyped drawing method.
|
||||
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);
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// Template makes the API typesafe, eg. PrimitiveBatch<VertexPositionColor>.
|
||||
template<typename TVertex>
|
||||
class PrimitiveBatch : public Internal::PrimitiveBatchBase
|
||||
{
|
||||
static const size_t DefaultBatchSize = 2048;
|
||||
|
||||
public:
|
||||
explicit PrimitiveBatch(_In_ ID3D11DeviceContext* deviceContext, size_t maxIndices = DefaultBatchSize * 3, size_t maxVertices = DefaultBatchSize)
|
||||
: PrimitiveBatchBase(deviceContext, maxIndices, maxVertices, sizeof(TVertex))
|
||||
{ }
|
||||
|
||||
PrimitiveBatch(PrimitiveBatch&& moveFrom)
|
||||
: PrimitiveBatchBase(std::move(moveFrom))
|
||||
{ }
|
||||
|
||||
PrimitiveBatch& operator= (PrimitiveBatch&& moveFrom)
|
||||
{
|
||||
PrimitiveBatchBase::operator=(std::move(moveFrom));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// Similar to the D3D9 API DrawPrimitiveUP.
|
||||
void Draw(D3D11_PRIMITIVE_TOPOLOGY topology, _In_reads_(vertexCount) TVertex const* vertices, size_t vertexCount)
|
||||
{
|
||||
void* mappedVertices;
|
||||
|
||||
PrimitiveBatchBase::Draw(topology, false, nullptr, 0, vertexCount, &mappedVertices);
|
||||
|
||||
memcpy(mappedVertices, vertices, vertexCount * sizeof(TVertex));
|
||||
}
|
||||
|
||||
|
||||
// Similar to the D3D9 API DrawIndexedPrimitiveUP.
|
||||
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)
|
||||
{
|
||||
void* mappedVertices;
|
||||
|
||||
PrimitiveBatchBase::Draw(topology, true, indices, indexCount, vertexCount, &mappedVertices);
|
||||
|
||||
memcpy(mappedVertices, vertices, vertexCount * sizeof(TVertex));
|
||||
}
|
||||
|
||||
|
||||
void DrawLine(TVertex const& v1, TVertex const& v2)
|
||||
{
|
||||
TVertex* mappedVertices;
|
||||
|
||||
PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_LINELIST, false, nullptr, 0, 2, reinterpret_cast<void**>(&mappedVertices));
|
||||
|
||||
mappedVertices[0] = v1;
|
||||
mappedVertices[1] = v2;
|
||||
}
|
||||
|
||||
|
||||
void DrawTriangle(TVertex const& v1, TVertex const& v2, TVertex const& v3)
|
||||
{
|
||||
TVertex* mappedVertices;
|
||||
|
||||
PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, false, nullptr, 0, 3, reinterpret_cast<void**>(&mappedVertices));
|
||||
|
||||
mappedVertices[0] = v1;
|
||||
mappedVertices[1] = v2;
|
||||
mappedVertices[2] = v3;
|
||||
}
|
||||
|
||||
|
||||
void DrawQuad(TVertex const& v1, TVertex const& v2, TVertex const& v3, TVertex const& v4)
|
||||
{
|
||||
static const uint16_t quadIndices[] = { 0, 1, 2, 0, 2, 3 };
|
||||
|
||||
TVertex* mappedVertices;
|
||||
|
||||
PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, true, quadIndices, 6, 4, reinterpret_cast<void**>(&mappedVertices));
|
||||
|
||||
mappedVertices[0] = v1;
|
||||
mappedVertices[1] = v2;
|
||||
mappedVertices[2] = v3;
|
||||
mappedVertices[3] = v4;
|
||||
}
|
||||
};
|
||||
}
|
||||
50
DirectXTK/Inc/ScreenGrab.h
Normal file
50
DirectXTK/Inc/ScreenGrab.h
Normal file
@@ -0,0 +1,50 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// File: ScreenGrab.h
|
||||
//
|
||||
// Function for capturing a 2D texture and saving it to a file (aka a 'screenshot'
|
||||
// when used on a Direct3D Render Target).
|
||||
//
|
||||
// Note these functions are useful as a light-weight runtime screen grabber. For
|
||||
// full-featured texture capture, DDS writer, and texture processing pipeline,
|
||||
// see the 'Texconv' sample and the 'DirectXTex' library.
|
||||
//
|
||||
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
||||
// PARTICULAR PURPOSE.
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248926
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248929
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
#include <d3d11_x.h>
|
||||
#else
|
||||
#include <d3d11_1.h>
|
||||
#endif
|
||||
|
||||
#include <ocidl.h>
|
||||
|
||||
#include <functional>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
namespace DirectX
|
||||
{
|
||||
HRESULT __cdecl SaveDDSTextureToFile(
|
||||
_In_ ID3D11DeviceContext* pContext,
|
||||
_In_ ID3D11Resource* pSource,
|
||||
_In_z_ const wchar_t* fileName);
|
||||
|
||||
HRESULT __cdecl SaveWICTextureToFile(
|
||||
_In_ ID3D11DeviceContext* pContext,
|
||||
_In_ ID3D11Resource* pSource,
|
||||
_In_ REFGUID guidContainerFormat,
|
||||
_In_z_ const wchar_t* fileName,
|
||||
_In_opt_ const GUID* targetFormat = nullptr,
|
||||
_In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = nullptr);
|
||||
}
|
||||
1026
DirectXTK/Inc/SimpleMath.h
Normal file
1026
DirectXTK/Inc/SimpleMath.h
Normal file
File diff suppressed because it is too large
Load Diff
3706
DirectXTK/Inc/SimpleMath.inl
Normal file
3706
DirectXTK/Inc/SimpleMath.inl
Normal file
File diff suppressed because it is too large
Load Diff
96
DirectXTK/Inc/SpriteBatch.h
Normal file
96
DirectXTK/Inc/SpriteBatch.h
Normal file
@@ -0,0 +1,96 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// File: SpriteBatch.h
|
||||
//
|
||||
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
||||
// PARTICULAR PURPOSE.
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248929
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
#include <d3d11_x.h>
|
||||
#else
|
||||
#include <d3d11_1.h>
|
||||
#endif
|
||||
|
||||
#include <DirectXMath.h>
|
||||
#include <DirectXColors.h>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace DirectX
|
||||
{
|
||||
enum SpriteSortMode
|
||||
{
|
||||
SpriteSortMode_Deferred,
|
||||
SpriteSortMode_Immediate,
|
||||
SpriteSortMode_Texture,
|
||||
SpriteSortMode_BackToFront,
|
||||
SpriteSortMode_FrontToBack,
|
||||
};
|
||||
|
||||
|
||||
enum SpriteEffects
|
||||
{
|
||||
SpriteEffects_None = 0,
|
||||
SpriteEffects_FlipHorizontally = 1,
|
||||
SpriteEffects_FlipVertically = 2,
|
||||
SpriteEffects_FlipBoth = SpriteEffects_FlipHorizontally | SpriteEffects_FlipVertically,
|
||||
};
|
||||
|
||||
|
||||
class SpriteBatch
|
||||
{
|
||||
public:
|
||||
explicit SpriteBatch(_In_ ID3D11DeviceContext* deviceContext);
|
||||
SpriteBatch(SpriteBatch&& moveFrom);
|
||||
SpriteBatch& operator= (SpriteBatch&& moveFrom);
|
||||
|
||||
SpriteBatch(SpriteBatch const&) = delete;
|
||||
SpriteBatch& operator= (SpriteBatch const&) = delete;
|
||||
|
||||
virtual ~SpriteBatch();
|
||||
|
||||
// Begin/End a batch of sprite drawing operations.
|
||||
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,
|
||||
_In_opt_ std::function<void __cdecl()> setCustomShaders = nullptr, FXMMATRIX transformMatrix = MatrixIdentity);
|
||||
void __cdecl End();
|
||||
|
||||
// Draw overloads specifying position, origin and scale as XMFLOAT2.
|
||||
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position, FXMVECTOR color = Colors::White);
|
||||
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);
|
||||
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);
|
||||
|
||||
// Draw overloads specifying position, origin and scale via the first two components of an XMVECTOR.
|
||||
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position, FXMVECTOR color = Colors::White);
|
||||
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);
|
||||
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);
|
||||
|
||||
// Draw overloads specifying position as a RECT.
|
||||
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, RECT const& destinationRectangle, FXMVECTOR color = Colors::White);
|
||||
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);
|
||||
|
||||
// Rotation mode to be applied to the sprite transformation
|
||||
void __cdecl SetRotation( DXGI_MODE_ROTATION mode );
|
||||
DXGI_MODE_ROTATION __cdecl GetRotation() const;
|
||||
|
||||
// Set viewport for sprite transformation
|
||||
void __cdecl SetViewport( const D3D11_VIEWPORT& viewPort );
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
|
||||
static const XMMATRIX MatrixIdentity;
|
||||
static const XMFLOAT2 Float2Zero;
|
||||
};
|
||||
}
|
||||
81
DirectXTK/Inc/SpriteFont.h
Normal file
81
DirectXTK/Inc/SpriteFont.h
Normal file
@@ -0,0 +1,81 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// File: SpriteFont.h
|
||||
//
|
||||
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
||||
// PARTICULAR PURPOSE.
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248929
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SpriteBatch.h"
|
||||
|
||||
|
||||
namespace DirectX
|
||||
{
|
||||
class SpriteFont
|
||||
{
|
||||
public:
|
||||
struct Glyph;
|
||||
|
||||
SpriteFont(_In_ ID3D11Device* device, _In_z_ wchar_t const* fileName, bool forceSRGB = false);
|
||||
SpriteFont(_In_ ID3D11Device* device, _In_reads_bytes_(dataSize) uint8_t const* dataBlob, _In_ size_t dataSize, bool forceSRGB = false);
|
||||
SpriteFont(_In_ ID3D11ShaderResourceView* texture, _In_reads_(glyphCount) Glyph const* glyphs, _In_ size_t glyphCount, _In_ float lineSpacing);
|
||||
|
||||
SpriteFont(SpriteFont&& moveFrom);
|
||||
SpriteFont& operator= (SpriteFont&& moveFrom);
|
||||
|
||||
SpriteFont(SpriteFont const&) = delete;
|
||||
SpriteFont& operator= (SpriteFont const&) = delete;
|
||||
|
||||
virtual ~SpriteFont();
|
||||
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
|
||||
XMVECTOR XM_CALLCONV MeasureString(_In_z_ wchar_t const* text) const;
|
||||
|
||||
RECT __cdecl MeasureDrawBounds(_In_z_ wchar_t const* text, XMFLOAT2 const& position) const;
|
||||
RECT XM_CALLCONV MeasureDrawBounds(_In_z_ wchar_t const* text, FXMVECTOR position) const;
|
||||
|
||||
// Spacing properties
|
||||
float __cdecl GetLineSpacing() const;
|
||||
void __cdecl SetLineSpacing(float spacing);
|
||||
|
||||
// Font properties
|
||||
wchar_t __cdecl GetDefaultCharacter() const;
|
||||
void __cdecl SetDefaultCharacter(wchar_t character);
|
||||
|
||||
bool __cdecl ContainsCharacter(wchar_t character) const;
|
||||
|
||||
// Custom layout/rendering
|
||||
Glyph const* __cdecl FindGlyph(wchar_t character) const;
|
||||
void __cdecl GetSpriteSheet( ID3D11ShaderResourceView** texture ) const;
|
||||
|
||||
// Describes a single character glyph.
|
||||
struct Glyph
|
||||
{
|
||||
uint32_t Character;
|
||||
RECT Subrect;
|
||||
float XOffset;
|
||||
float YOffset;
|
||||
float XAdvance;
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
// Private implementation.
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
|
||||
static const XMFLOAT2 Float2Zero;
|
||||
};
|
||||
}
|
||||
366
DirectXTK/Inc/VertexTypes.h
Normal file
366
DirectXTK/Inc/VertexTypes.h
Normal file
@@ -0,0 +1,366 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// File: VertexTypes.h
|
||||
//
|
||||
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
||||
// PARTICULAR PURPOSE.
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248929
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
#include <d3d11_x.h>
|
||||
#else
|
||||
#include <d3d11_1.h>
|
||||
#endif
|
||||
|
||||
#include <DirectXMath.h>
|
||||
|
||||
|
||||
namespace DirectX
|
||||
{
|
||||
// Vertex struct holding position information.
|
||||
struct VertexPosition
|
||||
{
|
||||
VertexPosition() = default;
|
||||
|
||||
VertexPosition(XMFLOAT3 const& position)
|
||||
: position(position)
|
||||
{ }
|
||||
|
||||
VertexPosition(FXMVECTOR position)
|
||||
{
|
||||
XMStoreFloat3(&this->position, position);
|
||||
}
|
||||
|
||||
XMFLOAT3 position;
|
||||
|
||||
static const int InputElementCount = 1;
|
||||
static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
|
||||
};
|
||||
|
||||
|
||||
// Vertex struct holding position and color information.
|
||||
struct VertexPositionColor
|
||||
{
|
||||
VertexPositionColor() = default;
|
||||
|
||||
VertexPositionColor(XMFLOAT3 const& position, XMFLOAT4 const& color)
|
||||
: position(position),
|
||||
color(color)
|
||||
{ }
|
||||
|
||||
VertexPositionColor(FXMVECTOR position, FXMVECTOR color)
|
||||
{
|
||||
XMStoreFloat3(&this->position, position);
|
||||
XMStoreFloat4(&this->color, color);
|
||||
}
|
||||
|
||||
XMFLOAT3 position;
|
||||
XMFLOAT4 color;
|
||||
|
||||
static const int InputElementCount = 2;
|
||||
static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
|
||||
};
|
||||
|
||||
|
||||
// Vertex struct holding position and texture mapping information.
|
||||
struct VertexPositionTexture
|
||||
{
|
||||
VertexPositionTexture() = default;
|
||||
|
||||
VertexPositionTexture(XMFLOAT3 const& position, XMFLOAT2 const& textureCoordinate)
|
||||
: position(position),
|
||||
textureCoordinate(textureCoordinate)
|
||||
{ }
|
||||
|
||||
VertexPositionTexture(FXMVECTOR position, FXMVECTOR textureCoordinate)
|
||||
{
|
||||
XMStoreFloat3(&this->position, position);
|
||||
XMStoreFloat2(&this->textureCoordinate, textureCoordinate);
|
||||
}
|
||||
|
||||
XMFLOAT3 position;
|
||||
XMFLOAT2 textureCoordinate;
|
||||
|
||||
static const int InputElementCount = 2;
|
||||
static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
|
||||
};
|
||||
|
||||
|
||||
// Vertex struct holding position and dual texture mapping information.
|
||||
struct VertexPositionDualTexture
|
||||
{
|
||||
VertexPositionDualTexture() = default;
|
||||
|
||||
VertexPositionDualTexture(XMFLOAT3 const& position, XMFLOAT2 const& textureCoordinate0, XMFLOAT2 const& textureCoordinate1)
|
||||
: position(position),
|
||||
textureCoordinate0(textureCoordinate0),
|
||||
textureCoordinate1(textureCoordinate1)
|
||||
{ }
|
||||
|
||||
VertexPositionDualTexture(FXMVECTOR position,
|
||||
FXMVECTOR textureCoordinate0,
|
||||
FXMVECTOR textureCoordinate1)
|
||||
{
|
||||
XMStoreFloat3(&this->position, position);
|
||||
XMStoreFloat2(&this->textureCoordinate0, textureCoordinate0);
|
||||
XMStoreFloat2(&this->textureCoordinate1, textureCoordinate1);
|
||||
}
|
||||
|
||||
XMFLOAT3 position;
|
||||
XMFLOAT2 textureCoordinate0;
|
||||
XMFLOAT2 textureCoordinate1;
|
||||
|
||||
static const int InputElementCount = 3;
|
||||
static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
|
||||
};
|
||||
|
||||
|
||||
// Vertex struct holding position and normal vector.
|
||||
struct VertexPositionNormal
|
||||
{
|
||||
VertexPositionNormal() = default;
|
||||
|
||||
VertexPositionNormal(XMFLOAT3 const& position, XMFLOAT3 const& normal)
|
||||
: position(position),
|
||||
normal(normal)
|
||||
{ }
|
||||
|
||||
VertexPositionNormal(FXMVECTOR position, FXMVECTOR normal)
|
||||
{
|
||||
XMStoreFloat3(&this->position, position);
|
||||
XMStoreFloat3(&this->normal, normal);
|
||||
}
|
||||
|
||||
XMFLOAT3 position;
|
||||
XMFLOAT3 normal;
|
||||
|
||||
static const int InputElementCount = 2;
|
||||
static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
|
||||
};
|
||||
|
||||
|
||||
// Vertex struct holding position, color, and texture mapping information.
|
||||
struct VertexPositionColorTexture
|
||||
{
|
||||
VertexPositionColorTexture() = default;
|
||||
|
||||
VertexPositionColorTexture(XMFLOAT3 const& position, XMFLOAT4 const& color, XMFLOAT2 const& textureCoordinate)
|
||||
: position(position),
|
||||
color(color),
|
||||
textureCoordinate(textureCoordinate)
|
||||
{ }
|
||||
|
||||
VertexPositionColorTexture(FXMVECTOR position, FXMVECTOR color, FXMVECTOR textureCoordinate)
|
||||
{
|
||||
XMStoreFloat3(&this->position, position);
|
||||
XMStoreFloat4(&this->color, color);
|
||||
XMStoreFloat2(&this->textureCoordinate, textureCoordinate);
|
||||
}
|
||||
|
||||
XMFLOAT3 position;
|
||||
XMFLOAT4 color;
|
||||
XMFLOAT2 textureCoordinate;
|
||||
|
||||
static const int InputElementCount = 3;
|
||||
static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
|
||||
};
|
||||
|
||||
|
||||
// Vertex struct holding position, normal vector, and color information.
|
||||
struct VertexPositionNormalColor
|
||||
{
|
||||
VertexPositionNormalColor() = default;
|
||||
|
||||
VertexPositionNormalColor(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& color)
|
||||
: position(position),
|
||||
normal(normal),
|
||||
color(color)
|
||||
{ }
|
||||
|
||||
VertexPositionNormalColor(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR color)
|
||||
{
|
||||
XMStoreFloat3(&this->position, position);
|
||||
XMStoreFloat3(&this->normal, normal);
|
||||
XMStoreFloat4(&this->color, color);
|
||||
}
|
||||
|
||||
XMFLOAT3 position;
|
||||
XMFLOAT3 normal;
|
||||
XMFLOAT4 color;
|
||||
|
||||
static const int InputElementCount = 3;
|
||||
static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
|
||||
};
|
||||
|
||||
|
||||
// Vertex struct holding position, normal vector, and texture mapping information.
|
||||
struct VertexPositionNormalTexture
|
||||
{
|
||||
VertexPositionNormalTexture() = default;
|
||||
|
||||
VertexPositionNormalTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT2 const& textureCoordinate)
|
||||
: position(position),
|
||||
normal(normal),
|
||||
textureCoordinate(textureCoordinate)
|
||||
{ }
|
||||
|
||||
VertexPositionNormalTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR textureCoordinate)
|
||||
{
|
||||
XMStoreFloat3(&this->position, position);
|
||||
XMStoreFloat3(&this->normal, normal);
|
||||
XMStoreFloat2(&this->textureCoordinate, textureCoordinate);
|
||||
}
|
||||
|
||||
XMFLOAT3 position;
|
||||
XMFLOAT3 normal;
|
||||
XMFLOAT2 textureCoordinate;
|
||||
|
||||
static const int InputElementCount = 3;
|
||||
static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
|
||||
};
|
||||
|
||||
|
||||
// Vertex struct holding position, normal vector, color, and texture mapping information.
|
||||
struct VertexPositionNormalColorTexture
|
||||
{
|
||||
VertexPositionNormalColorTexture() = default;
|
||||
|
||||
VertexPositionNormalColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& color, XMFLOAT2 const& textureCoordinate)
|
||||
: position(position),
|
||||
normal(normal),
|
||||
color(color),
|
||||
textureCoordinate(textureCoordinate)
|
||||
{ }
|
||||
|
||||
VertexPositionNormalColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR color, CXMVECTOR textureCoordinate)
|
||||
{
|
||||
XMStoreFloat3(&this->position, position);
|
||||
XMStoreFloat3(&this->normal, normal);
|
||||
XMStoreFloat4(&this->color, color);
|
||||
XMStoreFloat2(&this->textureCoordinate, textureCoordinate);
|
||||
}
|
||||
|
||||
XMFLOAT3 position;
|
||||
XMFLOAT3 normal;
|
||||
XMFLOAT4 color;
|
||||
XMFLOAT2 textureCoordinate;
|
||||
|
||||
static const int InputElementCount = 4;
|
||||
static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
|
||||
};
|
||||
|
||||
|
||||
// Vertex struct for Visual Studio Shader Designer (DGSL) holding position, normal,
|
||||
// tangent, color (RGBA), and texture mapping information
|
||||
struct VertexPositionNormalTangentColorTexture
|
||||
{
|
||||
VertexPositionNormalTangentColorTexture() = default;
|
||||
|
||||
XMFLOAT3 position;
|
||||
XMFLOAT3 normal;
|
||||
XMFLOAT4 tangent;
|
||||
uint32_t color;
|
||||
XMFLOAT2 textureCoordinate;
|
||||
|
||||
VertexPositionNormalTangentColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, uint32_t rgba, XMFLOAT2 const& textureCoordinate)
|
||||
: position(position),
|
||||
normal(normal),
|
||||
tangent(tangent),
|
||||
color(rgba),
|
||||
textureCoordinate(textureCoordinate)
|
||||
{
|
||||
}
|
||||
|
||||
VertexPositionNormalTangentColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, uint32_t rgba, CXMVECTOR textureCoordinate)
|
||||
: color(rgba)
|
||||
{
|
||||
XMStoreFloat3(&this->position, position);
|
||||
XMStoreFloat3(&this->normal, normal);
|
||||
XMStoreFloat4(&this->tangent, tangent);
|
||||
XMStoreFloat2(&this->textureCoordinate, textureCoordinate);
|
||||
}
|
||||
|
||||
VertexPositionNormalTangentColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, XMFLOAT4 const& color, XMFLOAT2 const& textureCoordinate)
|
||||
: position(position),
|
||||
normal(normal),
|
||||
tangent(tangent),
|
||||
textureCoordinate(textureCoordinate)
|
||||
{
|
||||
SetColor( color );
|
||||
}
|
||||
|
||||
VertexPositionNormalTangentColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, CXMVECTOR color, CXMVECTOR textureCoordinate)
|
||||
{
|
||||
XMStoreFloat3(&this->position, position);
|
||||
XMStoreFloat3(&this->normal, normal);
|
||||
XMStoreFloat4(&this->tangent, tangent);
|
||||
XMStoreFloat2(&this->textureCoordinate, textureCoordinate);
|
||||
|
||||
SetColor( color );
|
||||
}
|
||||
|
||||
void __cdecl SetColor( XMFLOAT4 const& icolor ) { SetColor( XMLoadFloat4( &icolor ) ); }
|
||||
void XM_CALLCONV SetColor( FXMVECTOR icolor );
|
||||
|
||||
static const int InputElementCount = 5;
|
||||
static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
|
||||
};
|
||||
|
||||
|
||||
// Vertex struct for Visual Studio Shader Designer (DGSL) holding position, normal,
|
||||
// tangent, color (RGBA), texture mapping information, and skinning weights
|
||||
struct VertexPositionNormalTangentColorTextureSkinning : public VertexPositionNormalTangentColorTexture
|
||||
{
|
||||
VertexPositionNormalTangentColorTextureSkinning() = default;
|
||||
|
||||
uint32_t indices;
|
||||
uint32_t weights;
|
||||
|
||||
VertexPositionNormalTangentColorTextureSkinning(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, uint32_t rgba,
|
||||
XMFLOAT2 const& textureCoordinate, XMUINT4 const& indices, XMFLOAT4 const& weights)
|
||||
: VertexPositionNormalTangentColorTexture(position,normal,tangent,rgba,textureCoordinate)
|
||||
{
|
||||
SetBlendIndices( indices );
|
||||
SetBlendWeights( weights );
|
||||
}
|
||||
|
||||
VertexPositionNormalTangentColorTextureSkinning(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, uint32_t rgba, CXMVECTOR textureCoordinate,
|
||||
XMUINT4 const& indices, CXMVECTOR weights)
|
||||
: VertexPositionNormalTangentColorTexture(position,normal,tangent,rgba,textureCoordinate)
|
||||
{
|
||||
SetBlendIndices( indices );
|
||||
SetBlendWeights( weights );
|
||||
}
|
||||
|
||||
VertexPositionNormalTangentColorTextureSkinning(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, XMFLOAT4 const& color,
|
||||
XMFLOAT2 const& textureCoordinate, XMUINT4 const& indices, XMFLOAT4 const& weights)
|
||||
: VertexPositionNormalTangentColorTexture(position,normal,tangent,color,textureCoordinate)
|
||||
{
|
||||
SetBlendIndices( indices );
|
||||
SetBlendWeights( weights );
|
||||
}
|
||||
|
||||
VertexPositionNormalTangentColorTextureSkinning(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, CXMVECTOR color, CXMVECTOR textureCoordinate,
|
||||
XMUINT4 const& indices, CXMVECTOR weights)
|
||||
: VertexPositionNormalTangentColorTexture(position,normal,tangent,color,textureCoordinate)
|
||||
{
|
||||
SetBlendIndices( indices );
|
||||
SetBlendWeights( weights );
|
||||
}
|
||||
|
||||
void __cdecl SetBlendIndices( XMUINT4 const& iindices );
|
||||
|
||||
void __cdecl SetBlendWeights( XMFLOAT4 const& iweights ) { SetBlendWeights( XMLoadFloat4( &iweights ) ); }
|
||||
void XM_CALLCONV SetBlendWeights( FXMVECTOR iweights );
|
||||
|
||||
static const int InputElementCount = 7;
|
||||
static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
|
||||
};
|
||||
}
|
||||
155
DirectXTK/Inc/WICTextureLoader.h
Normal file
155
DirectXTK/Inc/WICTextureLoader.h
Normal file
@@ -0,0 +1,155 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// File: WICTextureLoader.h
|
||||
//
|
||||
// Function for loading a WIC image and creating a Direct3D runtime texture for it
|
||||
// (auto-generating mipmaps if possible)
|
||||
//
|
||||
// Note: Assumes application has already called CoInitializeEx
|
||||
//
|
||||
// Warning: CreateWICTexture* functions are not thread-safe if given a d3dContext instance for
|
||||
// auto-gen mipmap support.
|
||||
//
|
||||
// Note these functions are useful for images created as simple 2D textures. For
|
||||
// more complex resources, DDSTextureLoader is an excellent light-weight runtime loader.
|
||||
// For a full-featured DDS file reader, writer, and texture processing pipeline see
|
||||
// the 'Texconv' sample and the 'DirectXTex' library.
|
||||
//
|
||||
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
||||
// PARTICULAR PURPOSE.
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248926
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248929
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
#include <d3d11_x.h>
|
||||
#else
|
||||
#include <d3d11_1.h>
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
namespace DirectX
|
||||
{
|
||||
enum WIC_LOADER_FLAGS
|
||||
{
|
||||
WIC_LOADER_DEFAULT = 0,
|
||||
WIC_LOADER_FORCE_SRGB = 0x1,
|
||||
WIC_LOADER_IGNORE_SRGB = 0x2,
|
||||
};
|
||||
|
||||
// Standard version
|
||||
HRESULT __cdecl CreateWICTextureFromMemory(
|
||||
_In_ ID3D11Device* d3dDevice,
|
||||
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
|
||||
_In_ size_t wicDataSize,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_In_ size_t maxsize = 0);
|
||||
|
||||
HRESULT __cdecl CreateWICTextureFromFile(
|
||||
_In_ ID3D11Device* d3dDevice,
|
||||
_In_z_ const wchar_t* szFileName,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_In_ size_t maxsize = 0);
|
||||
|
||||
// Standard version with optional auto-gen mipmap support
|
||||
HRESULT __cdecl CreateWICTextureFromMemory(
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
_In_ ID3D11DeviceX* d3dDevice,
|
||||
_In_opt_ ID3D11DeviceContextX* d3dContext,
|
||||
#else
|
||||
_In_ ID3D11Device* d3dDevice,
|
||||
_In_opt_ ID3D11DeviceContext* d3dContext,
|
||||
#endif
|
||||
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
|
||||
_In_ size_t wicDataSize,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_In_ size_t maxsize = 0);
|
||||
|
||||
HRESULT __cdecl CreateWICTextureFromFile(
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
_In_ ID3D11DeviceX* d3dDevice,
|
||||
_In_opt_ ID3D11DeviceContextX* d3dContext,
|
||||
#else
|
||||
_In_ ID3D11Device* d3dDevice,
|
||||
_In_opt_ ID3D11DeviceContext* d3dContext,
|
||||
#endif
|
||||
_In_z_ const wchar_t* szFileName,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_In_ size_t maxsize = 0);
|
||||
|
||||
// Extended version
|
||||
HRESULT __cdecl CreateWICTextureFromMemoryEx(
|
||||
_In_ ID3D11Device* d3dDevice,
|
||||
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
|
||||
_In_ size_t wicDataSize,
|
||||
_In_ size_t maxsize,
|
||||
_In_ D3D11_USAGE usage,
|
||||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_In_ unsigned int loadFlags,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView);
|
||||
|
||||
HRESULT __cdecl CreateWICTextureFromFileEx(
|
||||
_In_ ID3D11Device* d3dDevice,
|
||||
_In_z_ const wchar_t* szFileName,
|
||||
_In_ size_t maxsize,
|
||||
_In_ D3D11_USAGE usage,
|
||||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_In_ unsigned int loadFlags,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView);
|
||||
|
||||
// Extended version with optional auto-gen mipmap support
|
||||
HRESULT __cdecl CreateWICTextureFromMemoryEx(
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
_In_ ID3D11DeviceX* d3dDevice,
|
||||
_In_opt_ ID3D11DeviceContextX* d3dContext,
|
||||
#else
|
||||
_In_ ID3D11Device* d3dDevice,
|
||||
_In_opt_ ID3D11DeviceContext* d3dContext,
|
||||
#endif
|
||||
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
|
||||
_In_ size_t wicDataSize,
|
||||
_In_ size_t maxsize,
|
||||
_In_ D3D11_USAGE usage,
|
||||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_In_ unsigned int loadFlags,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView);
|
||||
|
||||
HRESULT __cdecl CreateWICTextureFromFileEx(
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
_In_ ID3D11DeviceX* d3dDevice,
|
||||
_In_opt_ ID3D11DeviceContextX* d3dContext,
|
||||
#else
|
||||
_In_ ID3D11Device* d3dDevice,
|
||||
_In_opt_ ID3D11DeviceContext* d3dContext,
|
||||
#endif
|
||||
_In_z_ const wchar_t* szFileName,
|
||||
_In_ size_t maxsize,
|
||||
_In_ D3D11_USAGE usage,
|
||||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_In_ unsigned int loadFlags,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView);
|
||||
}
|
||||
62
DirectXTK/Inc/XboxDDSTextureLoader.h
Normal file
62
DirectXTK/Inc/XboxDDSTextureLoader.h
Normal file
@@ -0,0 +1,62 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// File: XboxDDSTextureLoader.h
|
||||
//
|
||||
// Functions for loading a DDS texture using the XBOX extended header and creating a
|
||||
// Direct3D11.X runtime resource for it via the CreatePlacement APIs
|
||||
//
|
||||
// Note these functions will not load standard DDS files. Use the DDSTextureLoader
|
||||
// module in the DirectXTex package or as part of the DirectXTK library to load
|
||||
// these files which use standard Direct3D resource creation APIs.
|
||||
//
|
||||
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
||||
// PARTICULAR PURPOSE.
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248926
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248929
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(_XBOX_ONE) || !defined(_TITLE)
|
||||
#error This module only supports Xbox One exclusive apps
|
||||
#endif
|
||||
|
||||
#include <d3d11_x.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace Xbox
|
||||
{
|
||||
enum DDS_ALPHA_MODE
|
||||
{
|
||||
DDS_ALPHA_MODE_UNKNOWN = 0,
|
||||
DDS_ALPHA_MODE_STRAIGHT = 1,
|
||||
DDS_ALPHA_MODE_PREMULTIPLIED = 2,
|
||||
DDS_ALPHA_MODE_OPAQUE = 3,
|
||||
DDS_ALPHA_MODE_CUSTOM = 4,
|
||||
};
|
||||
|
||||
HRESULT __cdecl CreateDDSTextureFromMemory(
|
||||
_In_ ID3D11DeviceX* d3dDevice,
|
||||
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
|
||||
_In_ size_t ddsDataSize,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_Outptr_ void** grfxMemory,
|
||||
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr,
|
||||
_In_ bool forceSRGB = false);
|
||||
|
||||
HRESULT __cdecl CreateDDSTextureFromFile( _In_ ID3D11DeviceX* d3dDevice,
|
||||
_In_z_ const wchar_t* szFileName,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_Outptr_ void** grfxMemory,
|
||||
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr,
|
||||
_In_ bool forceSRGB = false);
|
||||
|
||||
void FreeDDSTextureMemory( _In_opt_ void* grfxMemory );
|
||||
}
|
||||
Reference in New Issue
Block a user