Added DirectXTK library
This commit is contained in:
Vendored
+716
@@ -0,0 +1,716 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// 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>
|
||||||
|
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable : 4005)
|
||||||
|
#include <stdint.h>
|
||||||
|
#pragma warning(pop)
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
// VS 2010 doesn't support explicit calling convention for std::function
|
||||||
|
#ifndef DIRECTX_STD_CALLCONV
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER < 1700)
|
||||||
|
#define DIRECTX_STD_CALLCONV
|
||||||
|
#else
|
||||||
|
#define DIRECTX_STD_CALLCONV __cdecl
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// VS 2010/2012 do not support =default =delete
|
||||||
|
#ifndef DIRECTX_CTOR_DEFAULT
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER < 1800)
|
||||||
|
#define DIRECTX_CTOR_DEFAULT {}
|
||||||
|
#define DIRECTX_CTOR_DELETE ;
|
||||||
|
#else
|
||||||
|
#define DIRECTX_CTOR_DEFAULT =default;
|
||||||
|
#define DIRECTX_CTOR_DELETE =delete;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable : 4481)
|
||||||
|
// VS 2010 considers 'override' to be a extension, but it's part of C++11 as of VS 2012
|
||||||
|
|
||||||
|
namespace DirectX
|
||||||
|
{
|
||||||
|
#if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV)
|
||||||
|
#define XM_CALLCONV __fastcall
|
||||||
|
typedef const XMVECTOR& HXMVECTOR;
|
||||||
|
typedef const XMMATRIX& FXMMATRIX;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
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);
|
||||||
|
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;
|
||||||
|
|
||||||
|
// Prevent copying.
|
||||||
|
AudioEngine(AudioEngine const&) DIRECTX_CTOR_DELETE
|
||||||
|
AudioEngine& operator= (AudioEngine const&) DIRECTX_CTOR_DELETE
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
class WaveBank
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WaveBank( _In_ AudioEngine* engine, _In_z_ const wchar_t* wbFileName );
|
||||||
|
|
||||||
|
WaveBank(WaveBank&& moveFrom);
|
||||||
|
WaveBank& operator= (WaveBank&& moveFrom);
|
||||||
|
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;
|
||||||
|
|
||||||
|
// Prevent copying.
|
||||||
|
WaveBank(WaveBank const&) DIRECTX_CTOR_DELETE
|
||||||
|
WaveBank& operator= (WaveBank const&) DIRECTX_CTOR_DELETE
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
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;
|
||||||
|
|
||||||
|
// Prevent copying.
|
||||||
|
SoundEffect(SoundEffect const&) DIRECTX_CTOR_DELETE
|
||||||
|
SoundEffect& operator= (SoundEffect const&) DIRECTX_CTOR_DELETE
|
||||||
|
|
||||||
|
// 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 =
|
||||||
|
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 =
|
||||||
|
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);
|
||||||
|
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 __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 );
|
||||||
|
|
||||||
|
// Prevent copying.
|
||||||
|
SoundEffectInstance(SoundEffectInstance const&) DIRECTX_CTOR_DELETE
|
||||||
|
SoundEffectInstance& operator= (SoundEffectInstance const&) DIRECTX_CTOR_DELETE
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
class DynamicSoundEffectInstance
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DynamicSoundEffectInstance( _In_ AudioEngine* engine,
|
||||||
|
_In_opt_ std::function<void DIRECTX_STD_CALLCONV(DynamicSoundEffectInstance*)> bufferNeeded,
|
||||||
|
int sampleRate, int channels, int sampleBits = 16,
|
||||||
|
SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default );
|
||||||
|
DynamicSoundEffectInstance(DynamicSoundEffectInstance&& moveFrom);
|
||||||
|
DynamicSoundEffectInstance& operator= (DynamicSoundEffectInstance&& moveFrom);
|
||||||
|
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 );
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
// Prevent copying.
|
||||||
|
DynamicSoundEffectInstance(DynamicSoundEffectInstance const&) DIRECTX_CTOR_DELETE
|
||||||
|
DynamicSoundEffectInstance& operator= (DynamicSoundEffectInstance const&) DIRECTX_CTOR_DELETE
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma warning(pop)
|
||||||
+81
@@ -0,0 +1,81 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// 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
|
||||||
|
|
||||||
|
// VS 2010/2012 do not support =default =delete
|
||||||
|
#ifndef DIRECTX_CTOR_DEFAULT
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER < 1800)
|
||||||
|
#define DIRECTX_CTOR_DEFAULT {}
|
||||||
|
#define DIRECTX_CTOR_DELETE ;
|
||||||
|
#else
|
||||||
|
#define DIRECTX_CTOR_DEFAULT =default;
|
||||||
|
#define DIRECTX_CTOR_DELETE =delete;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
|
||||||
|
namespace DirectX
|
||||||
|
{
|
||||||
|
class CommonStates
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit CommonStates(_In_ ID3D11Device* device);
|
||||||
|
CommonStates(CommonStates&& moveFrom);
|
||||||
|
CommonStates& operator= (CommonStates&& moveFrom);
|
||||||
|
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;
|
||||||
|
|
||||||
|
// Prevent copying.
|
||||||
|
CommonStates(CommonStates const&) DIRECTX_CTOR_DELETE
|
||||||
|
CommonStates& operator= (CommonStates const&) DIRECTX_CTOR_DELETE
|
||||||
|
};
|
||||||
|
}
|
||||||
+160
@@ -0,0 +1,160 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// File: DDSTextureLoader.h
|
||||||
|
//
|
||||||
|
// Functions for loading a DDS texture and creating a Direct3D 11 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
|
||||||
|
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable : 4005)
|
||||||
|
#include <stdint.h>
|
||||||
|
#pragma warning(pop)
|
||||||
|
|
||||||
|
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
|
||||||
|
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||||
|
HRESULT __cdecl CreateDDSTextureFromMemory( _In_ ID3D11DeviceX* d3dDevice,
|
||||||
|
_In_opt_ ID3D11DeviceContextX* d3dContext,
|
||||||
|
#else
|
||||||
|
HRESULT __cdecl CreateDDSTextureFromMemory( _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
|
||||||
|
);
|
||||||
|
|
||||||
|
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||||
|
HRESULT __cdecl CreateDDSTextureFromFile( _In_ ID3D11DeviceX* d3dDevice,
|
||||||
|
_In_opt_ ID3D11DeviceContextX* d3dContext,
|
||||||
|
#else
|
||||||
|
HRESULT __cdecl CreateDDSTextureFromFile( _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
|
||||||
|
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||||
|
HRESULT __cdecl CreateDDSTextureFromMemoryEx( _In_ ID3D11DeviceX* d3dDevice,
|
||||||
|
_In_opt_ ID3D11DeviceContextX* d3dContext,
|
||||||
|
#else
|
||||||
|
HRESULT __cdecl CreateDDSTextureFromMemoryEx( _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
|
||||||
|
);
|
||||||
|
|
||||||
|
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||||
|
HRESULT __cdecl CreateDDSTextureFromFileEx( _In_ ID3D11DeviceX* d3dDevice,
|
||||||
|
_In_opt_ ID3D11DeviceContextX* d3dContext,
|
||||||
|
#else
|
||||||
|
HRESULT __cdecl CreateDDSTextureFromFileEx( _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
|
||||||
|
);
|
||||||
|
}
|
||||||
+130
@@ -0,0 +1,130 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// 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
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
|
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable : 4005)
|
||||||
|
#include <stdint.h>
|
||||||
|
#pragma warning(pop)
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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 11 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 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
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+612
@@ -0,0 +1,612 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// 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
|
||||||
|
|
||||||
|
// VS 2010/2012 do not support =default =delete
|
||||||
|
#ifndef DIRECTX_CTOR_DEFAULT
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER < 1800)
|
||||||
|
#define DIRECTX_CTOR_DEFAULT {}
|
||||||
|
#define DIRECTX_CTOR_DELETE ;
|
||||||
|
#else
|
||||||
|
#define DIRECTX_CTOR_DEFAULT =default;
|
||||||
|
#define DIRECTX_CTOR_DELETE =delete;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <DirectXMath.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable : 4481)
|
||||||
|
// VS 2010 considers 'override' to be a extension, but it's part of C++11 as of VS 2012
|
||||||
|
|
||||||
|
namespace DirectX
|
||||||
|
{
|
||||||
|
#if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV)
|
||||||
|
#define XM_CALLCONV __fastcall
|
||||||
|
typedef const XMVECTOR& HXMVECTOR;
|
||||||
|
typedef const XMMATRIX& FXMMATRIX;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// 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;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
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;
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Private implementation.
|
||||||
|
class Impl;
|
||||||
|
|
||||||
|
std::unique_ptr<Impl> pImpl;
|
||||||
|
|
||||||
|
// Prevent copying.
|
||||||
|
BasicEffect(BasicEffect const&) DIRECTX_CTOR_DELETE
|
||||||
|
BasicEffect& operator= (BasicEffect const&) DIRECTX_CTOR_DELETE
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
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;
|
||||||
|
|
||||||
|
// Material settings.
|
||||||
|
void XM_CALLCONV SetDiffuseColor(FXMVECTOR value);
|
||||||
|
void __cdecl SetAlpha(float 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;
|
||||||
|
|
||||||
|
// Prevent copying.
|
||||||
|
AlphaTestEffect(AlphaTestEffect const&) DIRECTX_CTOR_DELETE
|
||||||
|
AlphaTestEffect& operator= (AlphaTestEffect const&) DIRECTX_CTOR_DELETE
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
// Material settings.
|
||||||
|
void XM_CALLCONV SetDiffuseColor(FXMVECTOR value);
|
||||||
|
void __cdecl SetAlpha(float 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;
|
||||||
|
|
||||||
|
// Prevent copying.
|
||||||
|
DualTextureEffect(DualTextureEffect const&) DIRECTX_CTOR_DELETE
|
||||||
|
DualTextureEffect& operator= (DualTextureEffect const&) DIRECTX_CTOR_DELETE
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
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;
|
||||||
|
|
||||||
|
// Material settings.
|
||||||
|
void XM_CALLCONV SetDiffuseColor(FXMVECTOR value);
|
||||||
|
void XM_CALLCONV SetEmissiveColor(FXMVECTOR value);
|
||||||
|
void __cdecl SetAlpha(float 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 __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);
|
||||||
|
|
||||||
|
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;
|
||||||
|
void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override;
|
||||||
|
|
||||||
|
// Prevent copying.
|
||||||
|
EnvironmentMapEffect(EnvironmentMapEffect const&) DIRECTX_CTOR_DELETE
|
||||||
|
EnvironmentMapEffect& operator= (EnvironmentMapEffect const&) DIRECTX_CTOR_DELETE
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
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;
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Private implementation.
|
||||||
|
class Impl;
|
||||||
|
|
||||||
|
std::unique_ptr<Impl> pImpl;
|
||||||
|
|
||||||
|
// Unsupported interface method.
|
||||||
|
void __cdecl SetLightingEnabled(bool value) override;
|
||||||
|
|
||||||
|
// Prevent copying.
|
||||||
|
SkinnedEffect(SkinnedEffect const&) DIRECTX_CTOR_DELETE
|
||||||
|
SkinnedEffect& operator= (SkinnedEffect const&) DIRECTX_CTOR_DELETE
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// 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);
|
||||||
|
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;
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// 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 SetTexture2(_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;
|
||||||
|
|
||||||
|
// Prevent copying.
|
||||||
|
DGSLEffect(DGSLEffect const&) DIRECTX_CTOR_DELETE
|
||||||
|
DGSLEffect& operator= (DGSLEffect const&) DIRECTX_CTOR_DELETE
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Abstract interface to factory for sharing effects and texture resources
|
||||||
|
class IEffectFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~IEffectFactory() {}
|
||||||
|
|
||||||
|
struct EffectInfo
|
||||||
|
{
|
||||||
|
const WCHAR* name;
|
||||||
|
bool perVertexColor;
|
||||||
|
bool enableSkinning;
|
||||||
|
bool enableDualTexture;
|
||||||
|
float specularPower;
|
||||||
|
float alpha;
|
||||||
|
DirectX::XMFLOAT3 ambientColor;
|
||||||
|
DirectX::XMFLOAT3 diffuseColor;
|
||||||
|
DirectX::XMFLOAT3 specularColor;
|
||||||
|
DirectX::XMFLOAT3 emissiveColor;
|
||||||
|
const WCHAR* texture;
|
||||||
|
const WCHAR* texture2;
|
||||||
|
|
||||||
|
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* 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);
|
||||||
|
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* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) override;
|
||||||
|
|
||||||
|
// Settings.
|
||||||
|
void __cdecl ReleaseCache();
|
||||||
|
|
||||||
|
void __cdecl SetSharing( bool enabled );
|
||||||
|
|
||||||
|
void __cdecl SetDirectory( _In_opt_z_ const WCHAR* path );
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Private implementation.
|
||||||
|
class Impl;
|
||||||
|
|
||||||
|
std::shared_ptr<Impl> pImpl;
|
||||||
|
|
||||||
|
// Prevent copying.
|
||||||
|
EffectFactory(EffectFactory const&) DIRECTX_CTOR_DELETE
|
||||||
|
EffectFactory& operator= (EffectFactory const&) DIRECTX_CTOR_DELETE
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
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* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) override;
|
||||||
|
|
||||||
|
// DGSL methods.
|
||||||
|
struct DGSLEffectInfo : public EffectInfo
|
||||||
|
{
|
||||||
|
const WCHAR* textures[6];
|
||||||
|
const WCHAR* 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* shader, _Outptr_ ID3D11PixelShader** pixelShader );
|
||||||
|
|
||||||
|
// Settings.
|
||||||
|
void __cdecl ReleaseCache();
|
||||||
|
|
||||||
|
void __cdecl SetSharing( bool enabled );
|
||||||
|
|
||||||
|
void __cdecl SetDirectory( _In_opt_z_ const WCHAR* path );
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Private implementation.
|
||||||
|
class Impl;
|
||||||
|
|
||||||
|
std::shared_ptr<Impl> pImpl;
|
||||||
|
|
||||||
|
// Prevent copying.
|
||||||
|
DGSLEffectFactory(DGSLEffectFactory const&) DIRECTX_CTOR_DELETE
|
||||||
|
DGSLEffectFactory& operator= (DGSLEffectFactory const&) DIRECTX_CTOR_DELETE
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma warning(pop)
|
||||||
Vendored
+244
@@ -0,0 +1,244 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// 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
|
||||||
|
|
||||||
|
// VS 2010/2012 do not support =default =delete
|
||||||
|
#ifndef DIRECTX_CTOR_DEFAULT
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER < 1800)
|
||||||
|
#define DIRECTX_CTOR_DEFAULT {}
|
||||||
|
#define DIRECTX_CTOR_DELETE ;
|
||||||
|
#else
|
||||||
|
#define DIRECTX_CTOR_DEFAULT =default;
|
||||||
|
#define DIRECTX_CTOR_DELETE =delete;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable : 4005)
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <intsafe.h>
|
||||||
|
#pragma warning(pop)
|
||||||
|
|
||||||
|
|
||||||
|
namespace DirectX
|
||||||
|
{
|
||||||
|
class GamePad
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GamePad();
|
||||||
|
GamePad(GamePad&& moveFrom);
|
||||||
|
GamePad& operator= (GamePad&& moveFrom);
|
||||||
|
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;
|
||||||
|
bool back;
|
||||||
|
bool start;
|
||||||
|
};
|
||||||
|
|
||||||
|
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.back; }
|
||||||
|
bool __cdecl IsStartPressed() const { return buttons.start; }
|
||||||
|
bool __cdecl IsMenuPressed() const { return buttons.start; }
|
||||||
|
|
||||||
|
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;
|
||||||
|
uint64_t id;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
ButtonState back;
|
||||||
|
ButtonState start;
|
||||||
|
|
||||||
|
ButtonState dpadUp;
|
||||||
|
ButtonState dpadDown;
|
||||||
|
ButtonState dpadLeft;
|
||||||
|
ButtonState dpadRight;
|
||||||
|
|
||||||
|
ButtonStateTracker() { Reset(); }
|
||||||
|
|
||||||
|
void __cdecl Update( const State& state );
|
||||||
|
|
||||||
|
void __cdecl Reset();
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
// Singleton
|
||||||
|
static GamePad& __cdecl Get();
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Private implementation.
|
||||||
|
class Impl;
|
||||||
|
|
||||||
|
std::unique_ptr<Impl> pImpl;
|
||||||
|
|
||||||
|
// Prevent copying.
|
||||||
|
GamePad(GamePad const&) DIRECTX_CTOR_DELETE
|
||||||
|
GamePad& operator=(GamePad const&) DIRECTX_CTOR_DELETE
|
||||||
|
};
|
||||||
|
}
|
||||||
+100
@@ -0,0 +1,100 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// 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
|
||||||
|
|
||||||
|
#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>
|
||||||
|
|
||||||
|
// VS 2010 doesn't support explicit calling convention for std::function
|
||||||
|
#ifndef DIRECTX_STD_CALLCONV
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER < 1700)
|
||||||
|
#define DIRECTX_STD_CALLCONV
|
||||||
|
#else
|
||||||
|
#define DIRECTX_STD_CALLCONV __cdecl
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// VS 2010/2012 do not support =default =delete
|
||||||
|
#ifndef DIRECTX_CTOR_DEFAULT
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER < 1800)
|
||||||
|
#define DIRECTX_CTOR_DEFAULT {}
|
||||||
|
#define DIRECTX_CTOR_DELETE ;
|
||||||
|
#else
|
||||||
|
#define DIRECTX_CTOR_DEFAULT =default;
|
||||||
|
#define DIRECTX_CTOR_DELETE =delete;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
namespace DirectX
|
||||||
|
{
|
||||||
|
#if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV)
|
||||||
|
#define XM_CALLCONV __fastcall
|
||||||
|
typedef const XMVECTOR& HXMVECTOR;
|
||||||
|
typedef const XMMATRIX& FXMMATRIX;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class IEffect;
|
||||||
|
|
||||||
|
class GeometricPrimitive
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
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);
|
||||||
|
|
||||||
|
// 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 DIRECTX_STD_CALLCONV()> setCustomState = nullptr );
|
||||||
|
|
||||||
|
// 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 DIRECTX_STD_CALLCONV()> setCustomState = nullptr );
|
||||||
|
|
||||||
|
// Create input layout for drawing with a custom effect.
|
||||||
|
void __cdecl CreateInputLayout( _In_ IEffect* effect, _Outptr_ ID3D11InputLayout** inputLayout );
|
||||||
|
|
||||||
|
private:
|
||||||
|
GeometricPrimitive();
|
||||||
|
|
||||||
|
// Private implementation.
|
||||||
|
class Impl;
|
||||||
|
|
||||||
|
std::unique_ptr<Impl> pImpl;
|
||||||
|
|
||||||
|
// Prevent copying.
|
||||||
|
GeometricPrimitive(GeometricPrimitive const&) DIRECTX_CTOR_DELETE
|
||||||
|
GeometricPrimitive& operator= (GeometricPrimitive const&) DIRECTX_CTOR_DELETE
|
||||||
|
};
|
||||||
|
}
|
||||||
Vendored
+490
@@ -0,0 +1,490 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// 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
|
||||||
|
|
||||||
|
// VS 2010/2012 do not support =default =delete
|
||||||
|
#ifndef DIRECTX_CTOR_DEFAULT
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER < 1800)
|
||||||
|
#define DIRECTX_CTOR_DEFAULT {}
|
||||||
|
#define DIRECTX_CTOR_DELETE ;
|
||||||
|
#else
|
||||||
|
#define DIRECTX_CTOR_DEFAULT =default;
|
||||||
|
#define DIRECTX_CTOR_DELETE =delete;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable : 4005)
|
||||||
|
#include <stdint.h>
|
||||||
|
#pragma warning(pop)
|
||||||
|
|
||||||
|
#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 Keyboard
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Keyboard();
|
||||||
|
Keyboard(Keyboard&& moveFrom);
|
||||||
|
Keyboard& operator= (Keyboard&& moveFrom);
|
||||||
|
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 : 1;
|
||||||
|
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 : 4;
|
||||||
|
bool Reserved22 : 8;
|
||||||
|
bool OemCopy : 1; // 0XF2
|
||||||
|
bool OemAuto : 1; // 0xF3
|
||||||
|
bool OemEnlW : 1; // 0xF4
|
||||||
|
bool Reserved23 : 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 Reserved24 : 1;
|
||||||
|
bool Pa1 : 1; // VK_PA1, 0xFD
|
||||||
|
bool OemClear : 1; // VK_OEM_CLEAR, 0xFE
|
||||||
|
|
||||||
|
bool __cdecl IsKeyDown(Keys key) const
|
||||||
|
{
|
||||||
|
if (key >= 0 && key <= 0xff)
|
||||||
|
{
|
||||||
|
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); }
|
||||||
|
|
||||||
|
public:
|
||||||
|
State lastState;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Retrieve the current state of the keyboard
|
||||||
|
State __cdecl GetState() const;
|
||||||
|
|
||||||
|
// Reset the keyboard state
|
||||||
|
void __cdecl Reset();
|
||||||
|
|
||||||
|
#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;
|
||||||
|
|
||||||
|
// Prevent copying.
|
||||||
|
Keyboard(Keyboard const&) DIRECTX_CTOR_DELETE
|
||||||
|
Keyboard& operator=(Keyboard const&) DIRECTX_CTOR_DELETE
|
||||||
|
};
|
||||||
|
}
|
||||||
Vendored
+163
@@ -0,0 +1,163 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// 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>
|
||||||
|
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable : 4005)
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <intsafe.h>
|
||||||
|
#pragma warning(pop)
|
||||||
|
|
||||||
|
#include <wrl\client.h>
|
||||||
|
|
||||||
|
// VS 2010 doesn't support explicit calling convention for std::function
|
||||||
|
#ifndef DIRECTX_STD_CALLCONV
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER < 1700)
|
||||||
|
#define DIRECTX_STD_CALLCONV
|
||||||
|
#else
|
||||||
|
#define DIRECTX_STD_CALLCONV __cdecl
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace DirectX
|
||||||
|
{
|
||||||
|
#if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV)
|
||||||
|
#define XM_CALLCONV __fastcall
|
||||||
|
typedef const XMVECTOR& HXMVECTOR;
|
||||||
|
typedef const XMMATRIX& FXMMATRIX;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
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 DIRECTX_STD_CALLCONV()> setCustomState = nullptr ) const;
|
||||||
|
|
||||||
|
// Create input layout for drawing with a custom effect.
|
||||||
|
void __cdecl CreateInputLayout( _In_ ID3D11Device* d3dDevice, _In_ IEffect* ieffect, _Outptr_ ID3D11InputLayout** iinputLayout );
|
||||||
|
|
||||||
|
// 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, 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 DIRECTX_STD_CALLCONV()> 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, CommonStates& states, FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection,
|
||||||
|
bool wireframe = false, _In_opt_ std::function<void DIRECTX_STD_CALLCONV()> 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 DIRECTX_STD_CALLCONV(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;
|
||||||
|
};
|
||||||
|
}
|
||||||
Vendored
+129
@@ -0,0 +1,129 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// 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
|
||||||
|
|
||||||
|
// VS 2010/2012 do not support =default =delete
|
||||||
|
#ifndef DIRECTX_CTOR_DEFAULT
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER < 1800)
|
||||||
|
#define DIRECTX_CTOR_DEFAULT {}
|
||||||
|
#define DIRECTX_CTOR_DELETE ;
|
||||||
|
#else
|
||||||
|
#define DIRECTX_CTOR_DEFAULT =default;
|
||||||
|
#define DIRECTX_CTOR_DELETE =delete;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#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);
|
||||||
|
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();
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
#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;
|
||||||
|
|
||||||
|
// Prevent copying.
|
||||||
|
Mouse(Mouse const&) DIRECTX_CTOR_DELETE
|
||||||
|
Mouse& operator=(Mouse const&) DIRECTX_CTOR_DELETE
|
||||||
|
};
|
||||||
|
}
|
||||||
+158
@@ -0,0 +1,158 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// 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
|
||||||
|
|
||||||
|
// VS 2010/2012 do not support =default =delete
|
||||||
|
#ifndef DIRECTX_CTOR_DEFAULT
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER < 1800)
|
||||||
|
#define DIRECTX_CTOR_DEFAULT {}
|
||||||
|
#define DIRECTX_CTOR_DELETE ;
|
||||||
|
#else
|
||||||
|
#define DIRECTX_CTOR_DEFAULT =default;
|
||||||
|
#define DIRECTX_CTOR_DELETE =delete;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <memory.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable: 4005)
|
||||||
|
#include <stdint.h>
|
||||||
|
#pragma warning(pop)
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
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;
|
||||||
|
|
||||||
|
// Prevent copying.
|
||||||
|
PrimitiveBatchBase(PrimitiveBatchBase const&) DIRECTX_CTOR_DELETE
|
||||||
|
PrimitiveBatchBase& operator= (PrimitiveBatchBase const&) DIRECTX_CTOR_DELETE
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Template makes the API typesafe, eg. PrimitiveBatch<VertexPositionColor>.
|
||||||
|
template<typename TVertex>
|
||||||
|
class PrimitiveBatch : public Internal::PrimitiveBatchBase
|
||||||
|
{
|
||||||
|
static const size_t DefaultBatchSize = 2048;
|
||||||
|
|
||||||
|
public:
|
||||||
|
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& __cdecl operator= (PrimitiveBatch&& moveFrom)
|
||||||
|
{
|
||||||
|
PrimitiveBatchBase::operator=(std::move(moveFrom));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Similar to the D3D9 API DrawPrimitiveUP.
|
||||||
|
void __cdecl 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 __cdecl 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 __cdecl 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 __cdecl 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 __cdecl 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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
Vendored
+64
@@ -0,0 +1,64 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// File: ScreenGrab.h
|
||||||
|
//
|
||||||
|
// Function for capturing a 2D texture and saving it to a file (aka a 'screenshot'
|
||||||
|
// when used on a Direct3D 11 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>
|
||||||
|
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable : 4005)
|
||||||
|
#include <stdint.h>
|
||||||
|
#pragma warning(pop)
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
// VS 2010 doesn't support explicit calling convention for std::function
|
||||||
|
#ifndef DIRECTX_STD_CALLCONV
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER < 1700)
|
||||||
|
#define DIRECTX_STD_CALLCONV
|
||||||
|
#else
|
||||||
|
#define DIRECTX_STD_CALLCONV __cdecl
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace DirectX
|
||||||
|
{
|
||||||
|
HRESULT __cdecl SaveDDSTextureToFile( _In_ ID3D11DeviceContext* pContext,
|
||||||
|
_In_ ID3D11Resource* pSource,
|
||||||
|
_In_z_ LPCWSTR fileName );
|
||||||
|
|
||||||
|
#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) || (_WIN32_WINNT > _WIN32_WINNT_WIN8)
|
||||||
|
|
||||||
|
HRESULT __cdecl SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext,
|
||||||
|
_In_ ID3D11Resource* pSource,
|
||||||
|
_In_ REFGUID guidContainerFormat,
|
||||||
|
_In_z_ LPCWSTR fileName,
|
||||||
|
_In_opt_ const GUID* targetFormat = nullptr,
|
||||||
|
_In_opt_ std::function<void DIRECTX_STD_CALLCONV(IPropertyBag2*)> setCustomProps = nullptr );
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
Vendored
+845
@@ -0,0 +1,845 @@
|
|||||||
|
//-------------------------------------------------------------------------------------
|
||||||
|
// SimpleMath.h -- Simplified C++ Math wrapper for DirectXMath
|
||||||
|
//
|
||||||
|
// 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 <functional>
|
||||||
|
#include <memory.h>
|
||||||
|
|
||||||
|
#include <DirectXMath.h>
|
||||||
|
#include <DirectXPackedVector.h>
|
||||||
|
#include <DirectXCollision.h>
|
||||||
|
|
||||||
|
namespace DirectX
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace SimpleMath
|
||||||
|
{
|
||||||
|
|
||||||
|
struct Vector4;
|
||||||
|
struct Matrix;
|
||||||
|
struct Quaternion;
|
||||||
|
struct Plane;
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// 2D vector
|
||||||
|
struct Vector2 : public XMFLOAT2
|
||||||
|
{
|
||||||
|
Vector2() : XMFLOAT2(0.f, 0.f) {}
|
||||||
|
explicit Vector2(float x) : XMFLOAT2( x, x ) {}
|
||||||
|
Vector2(float _x, float _y) : XMFLOAT2(_x, _y) {}
|
||||||
|
explicit Vector2(_In_reads_(2) const float *pArray) : XMFLOAT2(pArray) {}
|
||||||
|
Vector2(FXMVECTOR V) { XMStoreFloat2( this, V ); }
|
||||||
|
Vector2(const XMFLOAT2& V) { this->x = V.x; this->y = V.y; }
|
||||||
|
|
||||||
|
operator XMVECTOR() const { return XMLoadFloat2( this ); }
|
||||||
|
|
||||||
|
// Comparision operators
|
||||||
|
bool operator == ( const Vector2& V ) const;
|
||||||
|
bool operator != ( const Vector2& V ) const;
|
||||||
|
|
||||||
|
// Assignment operators
|
||||||
|
Vector2& operator= (const Vector2& V) { x = V.x; y = V.y; return *this; }
|
||||||
|
Vector2& operator= (const XMFLOAT2& V) { x = V.x; y = V.y; return *this; }
|
||||||
|
Vector2& operator+= (const Vector2& V);
|
||||||
|
Vector2& operator-= (const Vector2& V);
|
||||||
|
Vector2& operator*= (const Vector2& V);
|
||||||
|
Vector2& operator*= (float S);
|
||||||
|
Vector2& operator/= (float S);
|
||||||
|
|
||||||
|
// Urnary operators
|
||||||
|
Vector2 operator+ () const { return *this; }
|
||||||
|
Vector2 operator- () const { return Vector2(-x, -y); }
|
||||||
|
|
||||||
|
// Vector operations
|
||||||
|
bool InBounds( const Vector2& Bounds ) const;
|
||||||
|
|
||||||
|
float Length() const;
|
||||||
|
float LengthSquared() const;
|
||||||
|
|
||||||
|
float Dot( const Vector2& V ) const;
|
||||||
|
void Cross( const Vector2& V, Vector2& result ) const;
|
||||||
|
Vector2 Cross( const Vector2& V ) const;
|
||||||
|
|
||||||
|
void Normalize();
|
||||||
|
void Normalize( Vector2& result ) const;
|
||||||
|
|
||||||
|
void Clamp( const Vector2& vmin, const Vector2& vmax );
|
||||||
|
void Clamp( const Vector2& vmin, const Vector2& vmax, Vector2& result ) const;
|
||||||
|
|
||||||
|
// Static functions
|
||||||
|
static float Distance( const Vector2& v1, const Vector2& v2 );
|
||||||
|
static float DistanceSquared( const Vector2& v1, const Vector2& v2 );
|
||||||
|
|
||||||
|
static void Min( const Vector2& v1, const Vector2& v2, Vector2& result );
|
||||||
|
static Vector2 Min( const Vector2& v1, const Vector2& v2 );
|
||||||
|
|
||||||
|
static void Max( const Vector2& v1, const Vector2& v2, Vector2& result );
|
||||||
|
static Vector2 Max( const Vector2& v1, const Vector2& v2 );
|
||||||
|
|
||||||
|
static void Lerp( const Vector2& v1, const Vector2& v2, float t, Vector2& result );
|
||||||
|
static Vector2 Lerp( const Vector2& v1, const Vector2& v2, float t );
|
||||||
|
|
||||||
|
static void SmoothStep( const Vector2& v1, const Vector2& v2, float t, Vector2& result );
|
||||||
|
static Vector2 SmoothStep( const Vector2& v1, const Vector2& v2, float t );
|
||||||
|
|
||||||
|
static void Barycentric( const Vector2& v1, const Vector2& v2, const Vector2& v3, float f, float g, Vector2& result );
|
||||||
|
static Vector2 Barycentric( const Vector2& v1, const Vector2& v2, const Vector2& v3, float f, float g );
|
||||||
|
|
||||||
|
static void CatmullRom( const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float t, Vector2& result );
|
||||||
|
static Vector2 CatmullRom( const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float t );
|
||||||
|
|
||||||
|
static void Hermite( const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, float t, Vector2& result );
|
||||||
|
static Vector2 Hermite( const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, float t );
|
||||||
|
|
||||||
|
static void Reflect( const Vector2& ivec, const Vector2& nvec, Vector2& result );
|
||||||
|
static Vector2 Reflect( const Vector2& ivec, const Vector2& nvec );
|
||||||
|
|
||||||
|
static void Refract( const Vector2& ivec, const Vector2& nvec, float refractionIndex, Vector2& result );
|
||||||
|
static Vector2 Refract( const Vector2& ivec, const Vector2& nvec, float refractionIndex );
|
||||||
|
|
||||||
|
static void Transform( const Vector2& v, const Quaternion& quat, Vector2& result );
|
||||||
|
static Vector2 Transform( const Vector2& v, const Quaternion& quat );
|
||||||
|
|
||||||
|
static void Transform( const Vector2& v, const Matrix& m, Vector2& result );
|
||||||
|
static Vector2 Transform( const Vector2& v, const Matrix& m );
|
||||||
|
static void Transform( _In_reads_(count) const Vector2* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector2* resultArray );
|
||||||
|
|
||||||
|
static void Transform( const Vector2& v, const Matrix& m, Vector4& result );
|
||||||
|
static void Transform( _In_reads_(count) const Vector2* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector4* resultArray );
|
||||||
|
|
||||||
|
static void TransformNormal( const Vector2& v, const Matrix& m, Vector2& result );
|
||||||
|
static Vector2 TransformNormal( const Vector2& v, const Matrix& m );
|
||||||
|
static void TransformNormal( _In_reads_(count) const Vector2* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector2* resultArray );
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
static const Vector2 Zero;
|
||||||
|
static const Vector2 One;
|
||||||
|
static const Vector2 UnitX;
|
||||||
|
static const Vector2 UnitY;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Binary operators
|
||||||
|
Vector2 operator+ (const Vector2& V1, const Vector2& V2);
|
||||||
|
Vector2 operator- (const Vector2& V1, const Vector2& V2);
|
||||||
|
Vector2 operator* (const Vector2& V1, const Vector2& V2);
|
||||||
|
Vector2 operator* (const Vector2& V, float S);
|
||||||
|
Vector2 operator/ (const Vector2& V1, const Vector2& V2);
|
||||||
|
Vector2 operator* (float S, const Vector2& V);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// 3D vector
|
||||||
|
struct Vector3 : public XMFLOAT3
|
||||||
|
{
|
||||||
|
Vector3() : XMFLOAT3(0.f, 0.f, 0.f) {}
|
||||||
|
explicit Vector3(float x) : XMFLOAT3( x, x, x ) {}
|
||||||
|
Vector3(float _x, float _y, float _z) : XMFLOAT3(_x, _y, _z) {}
|
||||||
|
explicit Vector3(_In_reads_(3) const float *pArray) : XMFLOAT3(pArray) {}
|
||||||
|
Vector3(FXMVECTOR V) { XMStoreFloat3( this, V ); }
|
||||||
|
Vector3(const XMFLOAT3& V) { this->x = V.x; this->y = V.y; this->z = V.z; }
|
||||||
|
|
||||||
|
operator XMVECTOR() const { return XMLoadFloat3( this ); }
|
||||||
|
|
||||||
|
// Comparision operators
|
||||||
|
bool operator == ( const Vector3& V ) const;
|
||||||
|
bool operator != ( const Vector3& V ) const;
|
||||||
|
|
||||||
|
// Assignment operators
|
||||||
|
Vector3& operator= (const Vector3& V) { x = V.x; y = V.y; z = V.z; return *this; }
|
||||||
|
Vector3& operator= (const XMFLOAT3& V) { x = V.x; y = V.y; z = V.z; return *this; }
|
||||||
|
Vector3& operator+= (const Vector3& V);
|
||||||
|
Vector3& operator-= (const Vector3& V);
|
||||||
|
Vector3& operator*= (const Vector3& V);
|
||||||
|
Vector3& operator*= (float S);
|
||||||
|
Vector3& operator/= (float S);
|
||||||
|
|
||||||
|
// Urnary operators
|
||||||
|
Vector3 operator+ () const { return *this; }
|
||||||
|
Vector3 operator- () const;
|
||||||
|
|
||||||
|
// Vector operations
|
||||||
|
bool InBounds( const Vector3& Bounds ) const;
|
||||||
|
|
||||||
|
float Length() const;
|
||||||
|
float LengthSquared() const;
|
||||||
|
|
||||||
|
float Dot( const Vector3& V ) const;
|
||||||
|
void Cross( const Vector3& V, Vector3& result ) const;
|
||||||
|
Vector3 Cross( const Vector3& V ) const;
|
||||||
|
|
||||||
|
void Normalize();
|
||||||
|
void Normalize( Vector3& result ) const;
|
||||||
|
|
||||||
|
void Clamp( const Vector3& vmin, const Vector3& vmax );
|
||||||
|
void Clamp( const Vector3& vmin, const Vector3& vmax, Vector3& result ) const;
|
||||||
|
|
||||||
|
// Static functions
|
||||||
|
static float Distance( const Vector3& v1, const Vector3& v2 );
|
||||||
|
static float DistanceSquared( const Vector3& v1, const Vector3& v2 );
|
||||||
|
|
||||||
|
static void Min( const Vector3& v1, const Vector3& v2, Vector3& result );
|
||||||
|
static Vector3 Min( const Vector3& v1, const Vector3& v2 );
|
||||||
|
|
||||||
|
static void Max( const Vector3& v1, const Vector3& v2, Vector3& result );
|
||||||
|
static Vector3 Max( const Vector3& v1, const Vector3& v2 );
|
||||||
|
|
||||||
|
static void Lerp( const Vector3& v1, const Vector3& v2, float t, Vector3& result );
|
||||||
|
static Vector3 Lerp( const Vector3& v1, const Vector3& v2, float t );
|
||||||
|
|
||||||
|
static void SmoothStep( const Vector3& v1, const Vector3& v2, float t, Vector3& result );
|
||||||
|
static Vector3 SmoothStep( const Vector3& v1, const Vector3& v2, float t );
|
||||||
|
|
||||||
|
static void Barycentric( const Vector3& v1, const Vector3& v2, const Vector3& v3, float f, float g, Vector3& result );
|
||||||
|
static Vector3 Barycentric( const Vector3& v1, const Vector3& v2, const Vector3& v3, float f, float g );
|
||||||
|
|
||||||
|
static void CatmullRom( const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, float t, Vector3& result );
|
||||||
|
static Vector3 CatmullRom( const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, float t );
|
||||||
|
|
||||||
|
static void Hermite( const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, float t, Vector3& result );
|
||||||
|
static Vector3 Hermite( const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, float t );
|
||||||
|
|
||||||
|
static void Reflect( const Vector3& ivec, const Vector3& nvec, Vector3& result );
|
||||||
|
static Vector3 Reflect( const Vector3& ivec, const Vector3& nvec );
|
||||||
|
|
||||||
|
static void Refract( const Vector3& ivec, const Vector3& nvec, float refractionIndex, Vector3& result );
|
||||||
|
static Vector3 Refract( const Vector3& ivec, const Vector3& nvec, float refractionIndex );
|
||||||
|
|
||||||
|
static void Transform( const Vector3& v, const Quaternion& quat, Vector3& result );
|
||||||
|
static Vector3 Transform( const Vector3& v, const Quaternion& quat );
|
||||||
|
|
||||||
|
static void Transform( const Vector3& v, const Matrix& m, Vector3& result );
|
||||||
|
static Vector3 Transform( const Vector3& v, const Matrix& m );
|
||||||
|
static void Transform( _In_reads_(count) const Vector3* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector3* resultArray );
|
||||||
|
|
||||||
|
static void Transform( const Vector3& v, const Matrix& m, Vector4& result );
|
||||||
|
static void Transform( _In_reads_(count) const Vector3* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector4* resultArray );
|
||||||
|
|
||||||
|
static void TransformNormal( const Vector3& v, const Matrix& m, Vector3& result );
|
||||||
|
static Vector3 TransformNormal( const Vector3& v, const Matrix& m );
|
||||||
|
static void TransformNormal( _In_reads_(count) const Vector3* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector3* resultArray );
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
static const Vector3 Zero;
|
||||||
|
static const Vector3 One;
|
||||||
|
static const Vector3 UnitX;
|
||||||
|
static const Vector3 UnitY;
|
||||||
|
static const Vector3 UnitZ;
|
||||||
|
static const Vector3 Up;
|
||||||
|
static const Vector3 Down;
|
||||||
|
static const Vector3 Right;
|
||||||
|
static const Vector3 Left;
|
||||||
|
static const Vector3 Forward;
|
||||||
|
static const Vector3 Backward;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Binary operators
|
||||||
|
Vector3 operator+ (const Vector3& V1, const Vector3& V2);
|
||||||
|
Vector3 operator- (const Vector3& V1, const Vector3& V2);
|
||||||
|
Vector3 operator* (const Vector3& V1, const Vector3& V2);
|
||||||
|
Vector3 operator* (const Vector3& V, float S);
|
||||||
|
Vector3 operator/ (const Vector3& V1, const Vector3& V2);
|
||||||
|
Vector3 operator* (float S, const Vector3& V);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// 4D vector
|
||||||
|
struct Vector4 : public XMFLOAT4
|
||||||
|
{
|
||||||
|
Vector4() : XMFLOAT4(0.f, 0.f, 0.f, 0.f) {}
|
||||||
|
explicit Vector4(float x) : XMFLOAT4( x, x, x, x ) {}
|
||||||
|
Vector4(float _x, float _y, float _z, float _w) : XMFLOAT4(_x, _y, _z, _w) {}
|
||||||
|
explicit Vector4(_In_reads_(4) const float *pArray) : XMFLOAT4(pArray) {}
|
||||||
|
Vector4(FXMVECTOR V) { XMStoreFloat4( this, V ); }
|
||||||
|
Vector4(const XMFLOAT4& V) { this->x = V.x; this->y = V.y; this->z = V.z; this->w = V.w; }
|
||||||
|
|
||||||
|
operator XMVECTOR() const { return XMLoadFloat4( this ); }
|
||||||
|
|
||||||
|
// Comparision operators
|
||||||
|
bool operator == ( const Vector4& V ) const;
|
||||||
|
bool operator != ( const Vector4& V ) const;
|
||||||
|
|
||||||
|
// Assignment operators
|
||||||
|
Vector4& operator= (const Vector4& V) { x = V.x; y = V.y; z = V.z; w = V.w; return *this; }
|
||||||
|
Vector4& operator= (const XMFLOAT4& V) { x = V.x; y = V.y; z = V.z; w = V.w; return *this; }
|
||||||
|
Vector4& operator+= (const Vector4& V);
|
||||||
|
Vector4& operator-= (const Vector4& V);
|
||||||
|
Vector4& operator*= (const Vector4& V);
|
||||||
|
Vector4& operator*= (float S);
|
||||||
|
Vector4& operator/= (float S);
|
||||||
|
|
||||||
|
// Urnary operators
|
||||||
|
Vector4 operator+ () const { return *this; }
|
||||||
|
Vector4 operator- () const;
|
||||||
|
|
||||||
|
// Vector operations
|
||||||
|
bool InBounds( const Vector4& Bounds ) const;
|
||||||
|
|
||||||
|
float Length() const;
|
||||||
|
float LengthSquared() const;
|
||||||
|
|
||||||
|
float Dot( const Vector4& V ) const;
|
||||||
|
void Cross( const Vector4& v1, const Vector4& v2, Vector4& result ) const;
|
||||||
|
Vector4 Cross( const Vector4& v1, const Vector4& v2 ) const;
|
||||||
|
|
||||||
|
void Normalize();
|
||||||
|
void Normalize( Vector4& result ) const;
|
||||||
|
|
||||||
|
void Clamp( const Vector4& vmin, const Vector4& vmax );
|
||||||
|
void Clamp( const Vector4& vmin, const Vector4& vmax, Vector4& result ) const;
|
||||||
|
|
||||||
|
// Static functions
|
||||||
|
static float Distance( const Vector4& v1, const Vector4& v2 );
|
||||||
|
static float DistanceSquared( const Vector4& v1, const Vector4& v2 );
|
||||||
|
|
||||||
|
static void Min( const Vector4& v1, const Vector4& v2, Vector4& result );
|
||||||
|
static Vector4 Min( const Vector4& v1, const Vector4& v2 );
|
||||||
|
|
||||||
|
static void Max( const Vector4& v1, const Vector4& v2, Vector4& result );
|
||||||
|
static Vector4 Max( const Vector4& v1, const Vector4& v2 );
|
||||||
|
|
||||||
|
static void Lerp( const Vector4& v1, const Vector4& v2, float t, Vector4& result );
|
||||||
|
static Vector4 Lerp( const Vector4& v1, const Vector4& v2, float t );
|
||||||
|
|
||||||
|
static void SmoothStep( const Vector4& v1, const Vector4& v2, float t, Vector4& result );
|
||||||
|
static Vector4 SmoothStep( const Vector4& v1, const Vector4& v2, float t );
|
||||||
|
|
||||||
|
static void Barycentric( const Vector4& v1, const Vector4& v2, const Vector4& v3, float f, float g, Vector4& result );
|
||||||
|
static Vector4 Barycentric( const Vector4& v1, const Vector4& v2, const Vector4& v3, float f, float g );
|
||||||
|
|
||||||
|
static void CatmullRom( const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, float t, Vector4& result );
|
||||||
|
static Vector4 CatmullRom( const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, float t );
|
||||||
|
|
||||||
|
static void Hermite( const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, float t, Vector4& result );
|
||||||
|
static Vector4 Hermite( const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, float t );
|
||||||
|
|
||||||
|
static void Reflect( const Vector4& ivec, const Vector4& nvec, Vector4& result );
|
||||||
|
static Vector4 Reflect( const Vector4& ivec, const Vector4& nvec );
|
||||||
|
|
||||||
|
static void Refract( const Vector4& ivec, const Vector4& nvec, float refractionIndex, Vector4& result );
|
||||||
|
static Vector4 Refract( const Vector4& ivec, const Vector4& nvec, float refractionIndex );
|
||||||
|
|
||||||
|
static void Transform( const Vector2& v, const Quaternion& quat, Vector4& result );
|
||||||
|
static Vector4 Transform( const Vector2& v, const Quaternion& quat );
|
||||||
|
|
||||||
|
static void Transform( const Vector3& v, const Quaternion& quat, Vector4& result );
|
||||||
|
static Vector4 Transform( const Vector3& v, const Quaternion& quat );
|
||||||
|
|
||||||
|
static void Transform( const Vector4& v, const Quaternion& quat, Vector4& result );
|
||||||
|
static Vector4 Transform( const Vector4& v, const Quaternion& quat );
|
||||||
|
|
||||||
|
static void Transform( const Vector4& v, const Matrix& m, Vector4& result );
|
||||||
|
static Vector4 Transform( const Vector4& v, const Matrix& m );
|
||||||
|
static void Transform( _In_reads_(count) const Vector4* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector4* resultArray );
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
static const Vector4 Zero;
|
||||||
|
static const Vector4 One;
|
||||||
|
static const Vector4 UnitX;
|
||||||
|
static const Vector4 UnitY;
|
||||||
|
static const Vector4 UnitZ;
|
||||||
|
static const Vector4 UnitW;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Binary operators
|
||||||
|
Vector4 operator+ (const Vector4& V1, const Vector4& V2);
|
||||||
|
Vector4 operator- (const Vector4& V1, const Vector4& V2);
|
||||||
|
Vector4 operator* (const Vector4& V1, const Vector4& V2);
|
||||||
|
Vector4 operator* (const Vector4& V, float S);
|
||||||
|
Vector4 operator/ (const Vector4& V1, const Vector4& V2);
|
||||||
|
Vector4 operator* (float S, const Vector4& V);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// 4x4 Matrix (assumes right-handed cooordinates)
|
||||||
|
struct Matrix : public XMFLOAT4X4
|
||||||
|
{
|
||||||
|
Matrix() : XMFLOAT4X4( 1.f, 0, 0, 0,
|
||||||
|
0, 1.f, 0, 0,
|
||||||
|
0, 0, 1.f, 0,
|
||||||
|
0, 0, 0, 1.f ) {}
|
||||||
|
Matrix(float m00, float m01, float m02, float m03,
|
||||||
|
float m10, float m11, float m12, float m13,
|
||||||
|
float m20, float m21, float m22, float m23,
|
||||||
|
float m30, float m31, float m32, float m33) : XMFLOAT4X4(m00, m01, m02, m03,
|
||||||
|
m10, m11, m12, m13,
|
||||||
|
m20, m21, m22, m23,
|
||||||
|
m30, m31, m32, m33) {}
|
||||||
|
explicit Matrix( const Vector3& r0, const Vector3& r1, const Vector3& r2 ) : XMFLOAT4X4( r0.x, r0.y, r0.z, 0,
|
||||||
|
r1.x, r1.y, r1.z, 0,
|
||||||
|
r2.x, r2.y, r2.z, 0,
|
||||||
|
0, 0, 0, 1.f ) {}
|
||||||
|
explicit Matrix( const Vector4& r0, const Vector4& r1, const Vector4& r2, const Vector4& r3 ) : XMFLOAT4X4( r0.x, r0.y, r0.z, r0.w,
|
||||||
|
r1.x, r1.y, r1.z, r1.w,
|
||||||
|
r2.x, r2.y, r2.z, r2.w,
|
||||||
|
r3.x, r3.y, r3.z, r3.w ) {}
|
||||||
|
Matrix(const XMFLOAT4X4& M) { memcpy_s(this, sizeof(float)*16, &M, sizeof(XMFLOAT4X4)); }
|
||||||
|
|
||||||
|
explicit Matrix(_In_reads_(16) const float *pArray) : XMFLOAT4X4(pArray) {}
|
||||||
|
Matrix( CXMMATRIX M ) { XMStoreFloat4x4( this, M ); }
|
||||||
|
|
||||||
|
operator XMMATRIX() const { return XMLoadFloat4x4( this ); }
|
||||||
|
|
||||||
|
// Comparision operators
|
||||||
|
bool operator == ( const Matrix& M ) const;
|
||||||
|
bool operator != ( const Matrix& M ) const;
|
||||||
|
|
||||||
|
// Assignment operators
|
||||||
|
Matrix& operator= (const Matrix& M) { memcpy_s( this, sizeof(float)*16, &M, sizeof(float)*16 ); return *this; }
|
||||||
|
Matrix& operator= (const XMFLOAT4X4& M) { memcpy_s( this, sizeof(float)*16, &M, sizeof(XMFLOAT4X4) ); return *this; }
|
||||||
|
Matrix& operator+= (const Matrix& M);
|
||||||
|
Matrix& operator-= (const Matrix& M);
|
||||||
|
Matrix& operator*= (const Matrix& M);
|
||||||
|
Matrix& operator*= (float S);
|
||||||
|
Matrix& operator/= (float S);
|
||||||
|
|
||||||
|
Matrix& operator/= (const Matrix& M);
|
||||||
|
// Element-wise divide
|
||||||
|
|
||||||
|
// Urnary operators
|
||||||
|
Matrix operator+ () const { return *this; }
|
||||||
|
Matrix operator- () const;
|
||||||
|
|
||||||
|
// Properties
|
||||||
|
Vector3 Up() const { return Vector3( _21, _22, _23); }
|
||||||
|
void Up( const Vector3& v ) { _21 = v.x; _22 = v.y; _23 = v.z; }
|
||||||
|
|
||||||
|
Vector3 Down() const { return Vector3( -_21, -_22, -_23); }
|
||||||
|
void Down( const Vector3& v ) { _21 = -v.x; _22 = -v.y; _23 = -v.z; }
|
||||||
|
|
||||||
|
Vector3 Right() const { return Vector3( _11, _12, _13 ); }
|
||||||
|
void Right( const Vector3& v ) { _11 = v.x; _12 = v.y; _13 = v.z; }
|
||||||
|
|
||||||
|
Vector3 Left() const { return Vector3( -_11, -_12, -_13 ); }
|
||||||
|
void Left( const Vector3& v ) { _11 = -v.x; _12 = -v.y; _13 = -v.z; }
|
||||||
|
|
||||||
|
Vector3 Forward() const { return Vector3( -_31, -_32, -_33 ); }
|
||||||
|
void Forward( const Vector3& v ) { _31 = -v.x; _32 = -v.y; _33 = -v.z; }
|
||||||
|
|
||||||
|
Vector3 Backward() const { return Vector3( _31, _32, _33 ); }
|
||||||
|
void Backward( const Vector3& v ) { _31 = v.x; _32 = v.y; _33 = v.z; }
|
||||||
|
|
||||||
|
Vector3 Translation() const { return Vector3( _41, _42, _43 ); }
|
||||||
|
void Translation( const Vector3& v ) { _41 = v.x; _42 = v.y; _43 = v.z; }
|
||||||
|
|
||||||
|
// Matrix operations
|
||||||
|
bool Decompose( Vector3& scale, Quaternion& rotation, Vector3& translation );
|
||||||
|
|
||||||
|
Matrix Transpose() const;
|
||||||
|
void Transpose( Matrix& result ) const;
|
||||||
|
|
||||||
|
Matrix Invert() const;
|
||||||
|
void Invert( Matrix& result ) const;
|
||||||
|
|
||||||
|
float Determinant() const;
|
||||||
|
|
||||||
|
// Static functions
|
||||||
|
static Matrix CreateBillboard( const Vector3& object, const Vector3& cameraPosition, const Vector3& cameraUp, _In_opt_ const Vector3* cameraForward = nullptr );
|
||||||
|
|
||||||
|
static Matrix CreateConstrainedBillboard( const Vector3& object, const Vector3& cameraPosition, const Vector3& rotateAxis,
|
||||||
|
_In_opt_ const Vector3* cameraForward = nullptr, _In_opt_ const Vector3* objectForward = nullptr);
|
||||||
|
|
||||||
|
static Matrix CreateTranslation( const Vector3& position );
|
||||||
|
static Matrix CreateTranslation( float x, float y, float z );
|
||||||
|
|
||||||
|
static Matrix CreateScale( const Vector3& scales );
|
||||||
|
static Matrix CreateScale( float xs, float ys, float zs );
|
||||||
|
static Matrix CreateScale( float scale );
|
||||||
|
|
||||||
|
static Matrix CreateRotationX( float radians );
|
||||||
|
static Matrix CreateRotationY( float radians );
|
||||||
|
static Matrix CreateRotationZ( float radians );
|
||||||
|
|
||||||
|
static Matrix CreateFromAxisAngle( const Vector3& axis, float angle );
|
||||||
|
|
||||||
|
static Matrix CreatePerspectiveFieldOfView( float fov, float aspectRatio, float nearPlane, float farPlane );
|
||||||
|
static Matrix CreatePerspective( float width, float height, float nearPlane, float farPlane );
|
||||||
|
static Matrix CreatePerspectiveOffCenter( float left, float right, float bottom, float top, float nearPlane, float farPlane );
|
||||||
|
static Matrix CreateOrthographic( float width, float height, float zNearPlane, float zFarPlane );
|
||||||
|
static Matrix CreateOrthographicOffCenter( float left, float right, float bottom, float top, float zNearPlane, float zFarPlane );
|
||||||
|
|
||||||
|
static Matrix CreateLookAt( const Vector3& position, const Vector3& target, const Vector3& up );
|
||||||
|
static Matrix CreateWorld( const Vector3& position, const Vector3& forward, const Vector3& up );
|
||||||
|
|
||||||
|
static Matrix CreateFromQuaternion( const Quaternion& quat );
|
||||||
|
|
||||||
|
static Matrix CreateFromYawPitchRoll( float yaw, float pitch, float roll );
|
||||||
|
|
||||||
|
static Matrix CreateShadow( const Vector3& lightDir, const Plane& plane );
|
||||||
|
|
||||||
|
static Matrix CreateReflection( const Plane& plane );
|
||||||
|
|
||||||
|
static void Lerp( const Matrix& M1, const Matrix& M2, float t, Matrix& result );
|
||||||
|
static Matrix Lerp( const Matrix& M1, const Matrix& M2, float t );
|
||||||
|
|
||||||
|
static void Transform( const Matrix& M, const Quaternion& rotation, Matrix& result );
|
||||||
|
static Matrix Transform( const Matrix& M, const Quaternion& rotation );
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
static const Matrix Identity;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Binary operators
|
||||||
|
Matrix operator+ (const Matrix& M1, const Matrix& M2);
|
||||||
|
Matrix operator- (const Matrix& M1, const Matrix& M2);
|
||||||
|
Matrix operator* (const Matrix& M1, const Matrix& M2);
|
||||||
|
Matrix operator* (const Matrix& M, float S);
|
||||||
|
Matrix operator/ (const Matrix& M, float S);
|
||||||
|
Matrix operator/ (const Matrix& M1, const Matrix& M2);
|
||||||
|
// Element-wise divide
|
||||||
|
Matrix operator* (float S, const Matrix& M);
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Plane
|
||||||
|
struct Plane : public XMFLOAT4
|
||||||
|
{
|
||||||
|
Plane() : XMFLOAT4(0.f, 1.f, 0.f, 0.f) {}
|
||||||
|
Plane(float _x, float _y, float _z, float _w) : XMFLOAT4(_x, _y, _z, _w) {}
|
||||||
|
Plane(const Vector3& normal, float d) : XMFLOAT4(normal.x, normal.y, normal.z, d) {}
|
||||||
|
Plane(const Vector3& point1, const Vector3& point2, const Vector3& point3 );
|
||||||
|
Plane(const Vector3& point, const Vector3& normal);
|
||||||
|
explicit Plane(const Vector4& v) : XMFLOAT4(v.x, v.y, v.z, v.w) {}
|
||||||
|
explicit Plane(_In_reads_(4) const float *pArray) : XMFLOAT4(pArray) {}
|
||||||
|
Plane(FXMVECTOR V) { XMStoreFloat4( this, V ); }
|
||||||
|
Plane(const XMFLOAT4& p) { this->x = p.x; this->y = p.y; this->z = p.z; this->w = p.w; }
|
||||||
|
|
||||||
|
operator XMVECTOR() const { return XMLoadFloat4( this ); }
|
||||||
|
|
||||||
|
// Comparision operators
|
||||||
|
bool operator == ( const Plane& p ) const;
|
||||||
|
bool operator != ( const Plane& p ) const;
|
||||||
|
|
||||||
|
// Assignment operators
|
||||||
|
Plane& operator= (const Plane& p) { x = p.x; y = p.y; z = p.z; w = p.w; return *this; }
|
||||||
|
Plane& operator= (const XMFLOAT4& p) { x = p.x; y = p.y; z = p.z; w = p.w; return *this; }
|
||||||
|
|
||||||
|
// Properties
|
||||||
|
Vector3 Normal() const { return Vector3( x, y, z ); }
|
||||||
|
void Normal( const Vector3& normal ) { x = normal.x; y = normal.y; z = normal.z; }
|
||||||
|
|
||||||
|
float D() const { return w; }
|
||||||
|
void D(float d) { w = d; }
|
||||||
|
|
||||||
|
// Plane operations
|
||||||
|
void Normalize();
|
||||||
|
void Normalize( Plane& result ) const;
|
||||||
|
|
||||||
|
float Dot( const Vector4& v ) const;
|
||||||
|
float DotCoordinate( const Vector3& position ) const;
|
||||||
|
float DotNormal( const Vector3& normal ) const;
|
||||||
|
|
||||||
|
// Static functions
|
||||||
|
static void Transform( const Plane& plane, const Matrix& M, Plane& result );
|
||||||
|
static Plane Transform( const Plane& plane, const Matrix& M );
|
||||||
|
|
||||||
|
static void Transform( const Plane& plane, const Quaternion& rotation, Plane& result );
|
||||||
|
static Plane Transform( const Plane& plane, const Quaternion& rotation );
|
||||||
|
// Input quaternion must be the inverse transpose of the transformation
|
||||||
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Quaternion
|
||||||
|
struct Quaternion : public XMFLOAT4
|
||||||
|
{
|
||||||
|
Quaternion() : XMFLOAT4(0, 0, 0, 1.f) {}
|
||||||
|
Quaternion( float _x, float _y, float _z, float _w ) : XMFLOAT4(_x, _y, _z, _w) {}
|
||||||
|
Quaternion( const Vector3& v, float scalar ) : XMFLOAT4( v.x, v.y, v.z, scalar ) {}
|
||||||
|
explicit Quaternion( const Vector4& v ) : XMFLOAT4( v.x, v.y, v.z, v.w ) {}
|
||||||
|
explicit Quaternion(_In_reads_(4) const float *pArray) : XMFLOAT4(pArray) {}
|
||||||
|
Quaternion(FXMVECTOR V) { XMStoreFloat4( this, V ); }
|
||||||
|
Quaternion(const XMFLOAT4& q) { this->x = q.x; this->y = q.y; this->z = q.z; this->w = q.w; }
|
||||||
|
|
||||||
|
operator XMVECTOR() const { return XMLoadFloat4( this ); }
|
||||||
|
|
||||||
|
// Comparision operators
|
||||||
|
bool operator == ( const Quaternion& q ) const;
|
||||||
|
bool operator != ( const Quaternion& q ) const;
|
||||||
|
|
||||||
|
// Assignment operators
|
||||||
|
Quaternion& operator= (const Quaternion& q) { x = q.x; y = q.y; z = q.z; w = q.w; return *this; }
|
||||||
|
Quaternion& operator= (const XMFLOAT4& q) { x = q.x; y = q.y; z = q.z; w = q.w; return *this; }
|
||||||
|
Quaternion& operator+= (const Quaternion& q);
|
||||||
|
Quaternion& operator-= (const Quaternion& q);
|
||||||
|
Quaternion& operator*= (const Quaternion& q);
|
||||||
|
Quaternion& operator*= (float S);
|
||||||
|
Quaternion& operator/= (const Quaternion& q);
|
||||||
|
|
||||||
|
// Urnary operators
|
||||||
|
Quaternion operator+ () const { return *this; }
|
||||||
|
Quaternion operator- () const;
|
||||||
|
|
||||||
|
// Quaternion operations
|
||||||
|
float Length() const;
|
||||||
|
float LengthSquared() const;
|
||||||
|
|
||||||
|
void Normalize();
|
||||||
|
void Normalize( Quaternion& result ) const;
|
||||||
|
|
||||||
|
void Conjugate();
|
||||||
|
void Conjugate( Quaternion& result ) const;
|
||||||
|
|
||||||
|
void Inverse( Quaternion& result ) const;
|
||||||
|
|
||||||
|
float Dot( const Quaternion& Q ) const;
|
||||||
|
|
||||||
|
// Static functions
|
||||||
|
static Quaternion CreateFromAxisAngle( const Vector3& axis, float angle );
|
||||||
|
static Quaternion CreateFromYawPitchRoll( float yaw, float pitch, float roll );
|
||||||
|
static Quaternion CreateFromRotationMatrix( const Matrix& M );
|
||||||
|
|
||||||
|
static void Lerp( const Quaternion& q1, const Quaternion& q2, float t, Quaternion& result );
|
||||||
|
static Quaternion Lerp( const Quaternion& q1, const Quaternion& q2, float t );
|
||||||
|
|
||||||
|
static void Slerp( const Quaternion& q1, const Quaternion& q2, float t, Quaternion& result );
|
||||||
|
static Quaternion Slerp( const Quaternion& q1, const Quaternion& q2, float t );
|
||||||
|
|
||||||
|
static void Concatenate( const Quaternion& q1, const Quaternion& q2, Quaternion& result );
|
||||||
|
static Quaternion Concatenate( const Quaternion& q1, const Quaternion& q2 );
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
static const Quaternion Identity;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Binary operators
|
||||||
|
Quaternion operator+ (const Quaternion& Q1, const Quaternion& Q2);
|
||||||
|
Quaternion operator- (const Quaternion& Q1, const Quaternion& Q2);
|
||||||
|
Quaternion operator* (const Quaternion& Q1, const Quaternion& Q2);
|
||||||
|
Quaternion operator* (const Quaternion& Q, float S);
|
||||||
|
Quaternion operator/ (const Quaternion& Q1, const Quaternion& Q2);
|
||||||
|
Quaternion operator* (float S, const Quaternion& Q);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Color
|
||||||
|
struct Color : public XMFLOAT4
|
||||||
|
{
|
||||||
|
Color() : XMFLOAT4(0, 0, 0, 1.f) {}
|
||||||
|
Color( float _r, float _g, float _b ) : XMFLOAT4(_r, _g, _b, 1.f) {}
|
||||||
|
Color( float _r, float _g, float _b, float _a ) : XMFLOAT4(_r, _g, _b, _a) {}
|
||||||
|
explicit Color( const Vector3& clr ) : XMFLOAT4( clr.x, clr.y, clr.z, 1.f ) {}
|
||||||
|
explicit Color( const Vector4& clr ) : XMFLOAT4( clr.x, clr.y, clr.z, clr.w ) {}
|
||||||
|
explicit Color(_In_reads_(4) const float *pArray) : XMFLOAT4(pArray) {}
|
||||||
|
Color(FXMVECTOR V) { XMStoreFloat4( this, V ); }
|
||||||
|
Color(const XMFLOAT4& c) { this->x = c.x; this->y = c.y; this->z = c.z; this->w = c.w; }
|
||||||
|
|
||||||
|
explicit Color( const DirectX::PackedVector::XMCOLOR& Packed );
|
||||||
|
// BGRA Direct3D 9 D3DCOLOR packed color
|
||||||
|
|
||||||
|
explicit Color( const DirectX::PackedVector::XMUBYTEN4& Packed );
|
||||||
|
// RGBA XNA Game Studio packed color
|
||||||
|
|
||||||
|
operator XMVECTOR() const { return XMLoadFloat4( this ); }
|
||||||
|
operator const float*() const { return reinterpret_cast<const float*>(this); }
|
||||||
|
|
||||||
|
// Comparision operators
|
||||||
|
bool operator == ( const Color& c ) const;
|
||||||
|
bool operator != ( const Color& c ) const;
|
||||||
|
|
||||||
|
// Assignment operators
|
||||||
|
Color& operator= (const Color& c) { x = c.x; y = c.y; z = c.z; w = c.w; return *this; }
|
||||||
|
Color& operator= (const XMFLOAT4& c) { x = c.x; y = c.y; z = c.z; w = c.w; return *this; }
|
||||||
|
Color& operator+= (const Color& c);
|
||||||
|
Color& operator-= (const Color& c);
|
||||||
|
Color& operator*= (const Color& c);
|
||||||
|
Color& operator*= (float S);
|
||||||
|
Color& operator/= (const Color& c);
|
||||||
|
|
||||||
|
// Urnary operators
|
||||||
|
Color operator+ () const { return *this; }
|
||||||
|
Color operator- () const;
|
||||||
|
|
||||||
|
// Properties
|
||||||
|
float R() const { return x; }
|
||||||
|
void R(float r) { x = r; }
|
||||||
|
|
||||||
|
float G() const { return y; }
|
||||||
|
void G(float g) { y = g; }
|
||||||
|
|
||||||
|
float B() const { return z; }
|
||||||
|
void B(float b) { z = b; }
|
||||||
|
|
||||||
|
float A() const { return w; }
|
||||||
|
void A(float a) { w = a; }
|
||||||
|
|
||||||
|
// Color operations
|
||||||
|
DirectX::PackedVector::XMCOLOR BGRA() const;
|
||||||
|
DirectX::PackedVector::XMUBYTEN4 RGBA() const;
|
||||||
|
|
||||||
|
Vector3 ToVector3() const;
|
||||||
|
Vector4 ToVector4() const;
|
||||||
|
|
||||||
|
void Negate();
|
||||||
|
void Negate( Color& result ) const;
|
||||||
|
|
||||||
|
void Saturate();
|
||||||
|
void Saturate( Color& result ) const;
|
||||||
|
|
||||||
|
void Premultiply();
|
||||||
|
void Premultiply( Color& result ) const;
|
||||||
|
|
||||||
|
void AdjustSaturation( float sat );
|
||||||
|
void AdjustSaturation( float sat, Color& result ) const;
|
||||||
|
|
||||||
|
void AdjustContrast( float contrast );
|
||||||
|
void AdjustContrast( float contrast, Color& result ) const;
|
||||||
|
|
||||||
|
// Static functions
|
||||||
|
static void Modulate( const Color& c1, const Color& c2, Color& result );
|
||||||
|
static Color Modulate( const Color& c1, const Color& c2 );
|
||||||
|
|
||||||
|
static void Lerp( const Color& c1, const Color& c2, float t, Color& result );
|
||||||
|
static Color Lerp( const Color& c1, const Color& c2, float t );
|
||||||
|
};
|
||||||
|
|
||||||
|
// Binary operators
|
||||||
|
Color operator+ (const Color& C1, const Color& C2);
|
||||||
|
Color operator- (const Color& C1, const Color& C2);
|
||||||
|
Color operator* (const Color& C1, const Color& C2);
|
||||||
|
Color operator* (const Color& C, float S);
|
||||||
|
Color operator/ (const Color& C1, const Color& C2);
|
||||||
|
Color operator* (float S, const Color& C);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Ray
|
||||||
|
class Ray
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Vector3 position;
|
||||||
|
Vector3 direction;
|
||||||
|
|
||||||
|
Ray() : position(0,0,0), direction(0,0,1) {}
|
||||||
|
Ray( const Vector3& pos, const Vector3& dir ) : position(pos), direction(dir) {}
|
||||||
|
|
||||||
|
// Comparision operators
|
||||||
|
bool operator == ( const Ray& r ) const;
|
||||||
|
bool operator != ( const Ray& r ) const;
|
||||||
|
|
||||||
|
// Ray operations
|
||||||
|
bool Intersects( const BoundingSphere& sphere, _Out_ float& Dist ) const;
|
||||||
|
bool Intersects( const BoundingBox& box, _Out_ float& Dist ) const;
|
||||||
|
bool Intersects( const Vector3& tri0, const Vector3& tri1, const Vector3& tri2, _Out_ float& Dist ) const;
|
||||||
|
bool Intersects( const Plane& plane, _Out_ float& Dist ) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#include "SimpleMath.inl"
|
||||||
|
|
||||||
|
}; // namespace SimpleMath
|
||||||
|
|
||||||
|
}; // namespace DirectX
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Support for SimpleMath and Standard C++ Library containers
|
||||||
|
namespace std
|
||||||
|
{
|
||||||
|
|
||||||
|
template<> struct less<DirectX::SimpleMath::Vector2>
|
||||||
|
{
|
||||||
|
bool operator()(const DirectX::SimpleMath::Vector2& V1, const DirectX::SimpleMath::Vector2& V2) const
|
||||||
|
{
|
||||||
|
return ( (V1.x < V2.x) || ((V1.x == V2.x) && (V1.y < V2.y)) );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct less<DirectX::SimpleMath::Vector3>
|
||||||
|
{
|
||||||
|
bool operator()(const DirectX::SimpleMath::Vector3& V1, const DirectX::SimpleMath::Vector3& V2) const
|
||||||
|
{
|
||||||
|
return ( (V1.x < V2.x)
|
||||||
|
|| ((V1.x == V2.x) && (V1.y < V2.y))
|
||||||
|
|| ((V1.x == V2.x) && (V1.y == V2.y) && (V1.z < V2.z)) );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct less<DirectX::SimpleMath::Vector4>
|
||||||
|
{
|
||||||
|
bool operator()(const DirectX::SimpleMath::Vector4& V1, const DirectX::SimpleMath::Vector4& V2) const
|
||||||
|
{
|
||||||
|
return ( (V1.x < V2.x)
|
||||||
|
|| ((V1.x == V2.x) && (V1.y < V2.y))
|
||||||
|
|| ((V1.x == V2.x) && (V1.y == V2.y) && (V1.z < V2.z))
|
||||||
|
|| ((V1.x == V2.x) && (V1.y == V2.y) && (V1.z == V2.z) && (V1.w < V2.w)) );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct less<DirectX::SimpleMath::Matrix>
|
||||||
|
{
|
||||||
|
bool operator()(const DirectX::SimpleMath::Matrix& M1, const DirectX::SimpleMath::Matrix& M2) const
|
||||||
|
{
|
||||||
|
if (M1._11 != M2._11) return M1._11 < M2._11;
|
||||||
|
if (M1._12 != M2._12) return M1._12 < M2._12;
|
||||||
|
if (M1._13 != M2._13) return M1._13 < M2._13;
|
||||||
|
if (M1._14 != M2._14) return M1._14 < M2._14;
|
||||||
|
if (M1._21 != M2._21) return M1._21 < M2._21;
|
||||||
|
if (M1._22 != M2._22) return M1._22 < M2._22;
|
||||||
|
if (M1._23 != M2._23) return M1._23 < M2._23;
|
||||||
|
if (M1._24 != M2._24) return M1._24 < M2._24;
|
||||||
|
if (M1._31 != M2._31) return M1._31 < M2._31;
|
||||||
|
if (M1._32 != M2._32) return M1._32 < M2._32;
|
||||||
|
if (M1._33 != M2._33) return M1._33 < M2._33;
|
||||||
|
if (M1._34 != M2._34) return M1._34 < M2._34;
|
||||||
|
if (M1._41 != M2._41) return M1._41 < M2._41;
|
||||||
|
if (M1._42 != M2._42) return M1._42 < M2._42;
|
||||||
|
if (M1._43 != M2._43) return M1._43 < M2._43;
|
||||||
|
if (M1._44 != M2._44) return M1._44 < M2._44;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct less<DirectX::SimpleMath::Plane>
|
||||||
|
{
|
||||||
|
bool operator()(const DirectX::SimpleMath::Plane& P1, const DirectX::SimpleMath::Plane& P2) const
|
||||||
|
{
|
||||||
|
return ( (P1.x < P2.x)
|
||||||
|
|| ((P1.x == P2.x) && (P1.y < P2.y))
|
||||||
|
|| ((P1.x == P2.x) && (P1.y == P2.y) && (P1.z < P2.z))
|
||||||
|
|| ((P1.x == P2.x) && (P1.y == P2.y) && (P1.z == P2.z) && (P1.w < P2.w)) );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct less<DirectX::SimpleMath::Quaternion>
|
||||||
|
{
|
||||||
|
bool operator()(const DirectX::SimpleMath::Quaternion& Q1, const DirectX::SimpleMath::Quaternion& Q2) const
|
||||||
|
{
|
||||||
|
return ( (Q1.x < Q2.x)
|
||||||
|
|| ((Q1.x == Q2.x) && (Q1.y < Q2.y))
|
||||||
|
|| ((Q1.x == Q2.x) && (Q1.y == Q2.y) && (Q1.z < Q2.z))
|
||||||
|
|| ((Q1.x == Q2.x) && (Q1.y == Q2.y) && (Q1.z == Q2.z) && (Q1.w < Q2.w)) );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct less<DirectX::SimpleMath::Color>
|
||||||
|
{
|
||||||
|
bool operator()(const DirectX::SimpleMath::Color& C1, const DirectX::SimpleMath::Color& C2) const
|
||||||
|
{
|
||||||
|
return ( (C1.x < C2.x)
|
||||||
|
|| ((C1.x == C2.x) && (C1.y < C2.y))
|
||||||
|
|| ((C1.x == C2.x) && (C1.y == C2.y) && (C1.z < C2.z))
|
||||||
|
|| ((C1.x == C2.x) && (C1.y == C2.y) && (C1.z == C2.z) && (C1.w < C2.w)) );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct less<DirectX::SimpleMath::Ray>
|
||||||
|
{
|
||||||
|
bool operator()(const DirectX::SimpleMath::Ray& R1, const DirectX::SimpleMath::Ray& R2) const
|
||||||
|
{
|
||||||
|
if (R1.position.x != R2.position.x) return R1.position.x < R2.position.x;
|
||||||
|
if (R1.position.y != R2.position.y) return R1.position.y < R2.position.y;
|
||||||
|
if (R1.position.z != R2.position.z) return R1.position.z < R2.position.z;
|
||||||
|
|
||||||
|
if (R1.direction.x != R2.direction.x) return R1.direction.x < R2.direction.x;
|
||||||
|
if (R1.direction.y != R2.direction.y) return R1.direction.y < R2.direction.y;
|
||||||
|
if (R1.direction.z != R2.direction.z) return R1.direction.z < R2.direction.z;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace std
|
||||||
+3409
File diff suppressed because it is too large
Load Diff
Vendored
+121
@@ -0,0 +1,121 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// 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
|
||||||
|
|
||||||
|
// VS 2010/2012 do not support =default =delete
|
||||||
|
#ifndef DIRECTX_CTOR_DEFAULT
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER < 1800)
|
||||||
|
#define DIRECTX_CTOR_DEFAULT {}
|
||||||
|
#define DIRECTX_CTOR_DELETE ;
|
||||||
|
#else
|
||||||
|
#define DIRECTX_CTOR_DEFAULT =default;
|
||||||
|
#define DIRECTX_CTOR_DELETE =delete;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <DirectXMath.h>
|
||||||
|
#include <DirectXColors.h>
|
||||||
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
// VS 2010 doesn't support explicit calling convention for std::function
|
||||||
|
#ifndef DIRECTX_STD_CALLCONV
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER < 1700)
|
||||||
|
#define DIRECTX_STD_CALLCONV
|
||||||
|
#else
|
||||||
|
#define DIRECTX_STD_CALLCONV __cdecl
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace DirectX
|
||||||
|
{
|
||||||
|
#if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV)
|
||||||
|
#define XM_CALLCONV __fastcall
|
||||||
|
typedef const XMVECTOR& HXMVECTOR;
|
||||||
|
typedef const XMMATRIX& FXMMATRIX;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
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);
|
||||||
|
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 DIRECTX_STD_CALLCONV()> 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;
|
||||||
|
|
||||||
|
// Prevent copying.
|
||||||
|
SpriteBatch(SpriteBatch const&) DIRECTX_CTOR_DELETE
|
||||||
|
SpriteBatch& operator= (SpriteBatch const&) DIRECTX_CTOR_DELETE
|
||||||
|
};
|
||||||
|
}
|
||||||
Vendored
+89
@@ -0,0 +1,89 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// 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"
|
||||||
|
|
||||||
|
// VS 2010/2012 do not support =default =delete
|
||||||
|
#ifndef DIRECTX_CTOR_DEFAULT
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER < 1800)
|
||||||
|
#define DIRECTX_CTOR_DEFAULT {}
|
||||||
|
#define DIRECTX_CTOR_DELETE ;
|
||||||
|
#else
|
||||||
|
#define DIRECTX_CTOR_DEFAULT =default;
|
||||||
|
#define DIRECTX_CTOR_DELETE =delete;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
namespace DirectX
|
||||||
|
{
|
||||||
|
class SpriteFont
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct Glyph;
|
||||||
|
|
||||||
|
SpriteFont(_In_ ID3D11Device* device, _In_z_ wchar_t const* fileName);
|
||||||
|
SpriteFont(_In_ ID3D11Device* device, _In_reads_bytes_(dataSize) uint8_t const* dataBlob, _In_ size_t dataSize);
|
||||||
|
SpriteFont(_In_ ID3D11ShaderResourceView* texture, _In_reads_(glyphCount) Glyph const* glyphs, _In_ size_t glyphCount, _In_ float lineSpacing);
|
||||||
|
|
||||||
|
SpriteFont(SpriteFont&& moveFrom);
|
||||||
|
SpriteFont& operator= (SpriteFont&& moveFrom);
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
|
||||||
|
XMVECTOR XM_CALLCONV MeasureString(_In_z_ wchar_t const* text) 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 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;
|
||||||
|
|
||||||
|
// Prevent copying.
|
||||||
|
SpriteFont(SpriteFont const&) DIRECTX_CTOR_DELETE
|
||||||
|
SpriteFont& operator= (SpriteFont const&) DIRECTX_CTOR_DELETE
|
||||||
|
};
|
||||||
|
}
|
||||||
Vendored
+333
@@ -0,0 +1,333 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// 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
|
||||||
|
|
||||||
|
// VS 2010/2012 do not support =default =delete
|
||||||
|
#ifndef DIRECTX_CTOR_DEFAULT
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER < 1800)
|
||||||
|
#define DIRECTX_CTOR_DEFAULT {}
|
||||||
|
#define DIRECTX_CTOR_DELETE ;
|
||||||
|
#else
|
||||||
|
#define DIRECTX_CTOR_DEFAULT =default;
|
||||||
|
#define DIRECTX_CTOR_DELETE =delete;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <DirectXMath.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace DirectX
|
||||||
|
{
|
||||||
|
#if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV)
|
||||||
|
#define XM_CALLCONV __fastcall
|
||||||
|
typedef const XMVECTOR& HXMVECTOR;
|
||||||
|
typedef const XMMATRIX& FXMMATRIX;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Vertex struct holding position and color information.
|
||||||
|
struct VertexPositionColor
|
||||||
|
{
|
||||||
|
VertexPositionColor() DIRECTX_CTOR_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() DIRECTX_CTOR_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 normal vector.
|
||||||
|
struct VertexPositionNormal
|
||||||
|
{
|
||||||
|
VertexPositionNormal() DIRECTX_CTOR_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() DIRECTX_CTOR_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() DIRECTX_CTOR_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() DIRECTX_CTOR_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() DIRECTX_CTOR_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() DIRECTX_CTOR_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() DIRECTX_CTOR_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];
|
||||||
|
};
|
||||||
|
}
|
||||||
+154
@@ -0,0 +1,154 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// File: WICTextureLoader.h
|
||||||
|
//
|
||||||
|
// Function for loading a WIC image and creating a Direct3D 11 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(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) && (_WIN32_WINNT <= _WIN32_WINNT_WIN8)
|
||||||
|
#error WIC is not supported on Windows Phone 8.0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||||
|
#include <d3d11_x.h>
|
||||||
|
#else
|
||||||
|
#include <d3d11_1.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable : 4005)
|
||||||
|
#include <stdint.h>
|
||||||
|
#pragma warning(pop)
|
||||||
|
|
||||||
|
namespace DirectX
|
||||||
|
{
|
||||||
|
// Standard version
|
||||||
|
HRESULT __cdecl CreateWICTextureFromMemory( _In_ ID3D11Device* d3dDevice,
|
||||||
|
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
|
||||||
|
_In_ size_t wicDataSize,
|
||||||
|
_Out_opt_ ID3D11Resource** texture,
|
||||||
|
_Out_opt_ ID3D11ShaderResourceView** textureView,
|
||||||
|
_In_ size_t maxsize = 0
|
||||||
|
);
|
||||||
|
|
||||||
|
HRESULT __cdecl CreateWICTextureFromFile( _In_ ID3D11Device* d3dDevice,
|
||||||
|
_In_z_ const wchar_t* szFileName,
|
||||||
|
_Out_opt_ ID3D11Resource** texture,
|
||||||
|
_Out_opt_ ID3D11ShaderResourceView** textureView,
|
||||||
|
_In_ size_t maxsize = 0
|
||||||
|
);
|
||||||
|
|
||||||
|
// Standard version with optional auto-gen mipmap support
|
||||||
|
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||||
|
HRESULT __cdecl CreateWICTextureFromMemory( _In_ ID3D11DeviceX* d3dDevice,
|
||||||
|
_In_opt_ ID3D11DeviceContextX* d3dContext,
|
||||||
|
#else
|
||||||
|
HRESULT __cdecl CreateWICTextureFromMemory( _In_ ID3D11Device* d3dDevice,
|
||||||
|
_In_opt_ ID3D11DeviceContext* d3dContext,
|
||||||
|
#endif
|
||||||
|
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
|
||||||
|
_In_ size_t wicDataSize,
|
||||||
|
_Out_opt_ ID3D11Resource** texture,
|
||||||
|
_Out_opt_ ID3D11ShaderResourceView** textureView,
|
||||||
|
_In_ size_t maxsize = 0
|
||||||
|
);
|
||||||
|
|
||||||
|
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||||
|
HRESULT __cdecl CreateWICTextureFromFile( _In_ ID3D11DeviceX* d3dDevice,
|
||||||
|
_In_opt_ ID3D11DeviceContextX* d3dContext,
|
||||||
|
#else
|
||||||
|
HRESULT __cdecl CreateWICTextureFromFile( _In_ ID3D11Device* d3dDevice,
|
||||||
|
_In_opt_ ID3D11DeviceContext* d3dContext,
|
||||||
|
#endif
|
||||||
|
_In_z_ const wchar_t* szFileName,
|
||||||
|
_Out_opt_ ID3D11Resource** texture,
|
||||||
|
_Out_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_ bool forceSRGB,
|
||||||
|
_Out_opt_ ID3D11Resource** texture,
|
||||||
|
_Out_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_ bool forceSRGB,
|
||||||
|
_Out_opt_ ID3D11Resource** texture,
|
||||||
|
_Out_opt_ ID3D11ShaderResourceView** textureView
|
||||||
|
);
|
||||||
|
|
||||||
|
// Extended version with optional auto-gen mipmap support
|
||||||
|
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||||
|
HRESULT __cdecl CreateWICTextureFromMemoryEx( _In_ ID3D11DeviceX* d3dDevice,
|
||||||
|
_In_opt_ ID3D11DeviceContextX* d3dContext,
|
||||||
|
#else
|
||||||
|
HRESULT __cdecl CreateWICTextureFromMemoryEx( _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_ bool forceSRGB,
|
||||||
|
_Out_opt_ ID3D11Resource** texture,
|
||||||
|
_Out_opt_ ID3D11ShaderResourceView** textureView
|
||||||
|
);
|
||||||
|
|
||||||
|
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||||
|
HRESULT __cdecl CreateWICTextureFromFileEx( _In_ ID3D11DeviceX* d3dDevice,
|
||||||
|
_In_opt_ ID3D11DeviceContextX* d3dContext,
|
||||||
|
#else
|
||||||
|
HRESULT __cdecl CreateWICTextureFromFileEx( _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,
|
||||||
|
_Out_opt_ ID3D11Resource** texture,
|
||||||
|
_Out_opt_ ID3D11ShaderResourceView** textureView
|
||||||
|
);
|
||||||
|
}
|
||||||
+61
@@ -0,0 +1,61 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// 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 11 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
|
||||||
|
);
|
||||||
|
}
|
||||||
Vendored
BIN
Binary file not shown.
Reference in New Issue
Block a user