зеркало из https://github.com/microsoft/DirectXTK.git
Constify variables
This commit is contained in:
Родитель
bf1bd57512
Коммит
3aa9f8f45b
|
@ -190,7 +190,7 @@ namespace
|
|||
return 0;
|
||||
}
|
||||
|
||||
uint32_t tag = GetFormatTag(wfx);
|
||||
const uint32_t tag = GetFormatTag(wfx);
|
||||
switch (tag)
|
||||
{
|
||||
case WAVE_FORMAT_PCM:
|
||||
|
@ -911,7 +911,7 @@ void AudioEngine::Impl::AllocateVoice(
|
|||
char buff[64] = {};
|
||||
auto wfmt = reinterpret_cast<WAVEFORMATEX*>(buff);
|
||||
|
||||
uint32_t tag = GetFormatTag(wfx);
|
||||
const uint32_t tag = GetFormatTag(wfx);
|
||||
switch (tag)
|
||||
{
|
||||
case WAVE_FORMAT_PCM:
|
||||
|
@ -980,7 +980,7 @@ void AudioEngine::Impl::AllocateVoice(
|
|||
throw std::runtime_error("Too many instance voices");
|
||||
}
|
||||
|
||||
UINT32 vflags = (flags & SoundEffectInstance_NoSetPitch) ? XAUDIO2_VOICE_NOPITCH : 0u;
|
||||
const UINT32 vflags = (flags & SoundEffectInstance_NoSetPitch) ? XAUDIO2_VOICE_NOPITCH : 0u;
|
||||
|
||||
HRESULT hr;
|
||||
if (flags & SoundEffectInstance_Use3D)
|
||||
|
|
|
@ -211,7 +211,7 @@ void DynamicSoundEffectInstance::Impl::SubmitBuffer(const uint8_t* pAudioData, u
|
|||
|
||||
void DynamicSoundEffectInstance::Impl::OnUpdate()
|
||||
{
|
||||
DWORD result = WaitForSingleObjectEx(mBufferEvent.get(), 0, FALSE);
|
||||
const DWORD result = WaitForSingleObjectEx(mBufferEvent.get(), 0, FALSE);
|
||||
switch (result)
|
||||
{
|
||||
case WAIT_TIMEOUT:
|
||||
|
|
|
@ -179,9 +179,9 @@ bool DirectX::IsValid(_In_ const WAVEFORMATEX* wfx) noexcept
|
|||
return false;
|
||||
}
|
||||
|
||||
int nHeaderBytes = 7 /*MSADPCM_HEADER_LENGTH*/ * wfx->nChannels;
|
||||
int nBitsPerFrame = 4 /*MSADPCM_BITS_PER_SAMPLE*/ * wfx->nChannels;
|
||||
int nPcmFramesPerBlock = (wfx->nBlockAlign - nHeaderBytes) * 8 / nBitsPerFrame + 2;
|
||||
const int nHeaderBytes = 7 /*MSADPCM_HEADER_LENGTH*/ * wfx->nChannels;
|
||||
const int nBitsPerFrame = 4 /*MSADPCM_BITS_PER_SAMPLE*/ * wfx->nChannels;
|
||||
const int nPcmFramesPerBlock = (wfx->nBlockAlign - nHeaderBytes) * 8 / nBitsPerFrame + 2;
|
||||
|
||||
if (wfadpcm->wSamplesPerBlock != nPcmFramesPerBlock)
|
||||
{
|
||||
|
@ -468,7 +468,7 @@ bool DirectX::IsValid(_In_ const WAVEFORMATEX* wfx) noexcept
|
|||
|
||||
if (wfex->dwChannelMask)
|
||||
{
|
||||
auto channelBits = ChannelsSpecifiedInMask(wfex->dwChannelMask);
|
||||
auto const channelBits = ChannelsSpecifiedInMask(wfex->dwChannelMask);
|
||||
if (channelBits != wfx->nChannels)
|
||||
{
|
||||
DebugTrace("ERROR: WAVEFORMATEXTENSIBLE: nChannels=%u but ChannelMask has %u bits set\n",
|
||||
|
@ -511,7 +511,7 @@ void DirectX::CreateIntegerPCM(
|
|||
int channels,
|
||||
int sampleBits) noexcept
|
||||
{
|
||||
int blockAlign = channels * sampleBits / 8;
|
||||
const int blockAlign = channels * sampleBits / 8;
|
||||
|
||||
wfx->wFormatTag = WAVE_FORMAT_PCM;
|
||||
wfx->nChannels = static_cast<WORD>(channels);
|
||||
|
@ -531,7 +531,7 @@ void DirectX::CreateFloatPCM(
|
|||
int sampleRate,
|
||||
int channels) noexcept
|
||||
{
|
||||
int blockAlign = channels * 4;
|
||||
const int blockAlign = channels * 4;
|
||||
|
||||
wfx->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
|
||||
wfx->nChannels = static_cast<WORD>(channels);
|
||||
|
@ -566,7 +566,7 @@ void DirectX::CreateADPCM(
|
|||
throw std::invalid_argument("ADPCMWAVEFORMAT");
|
||||
}
|
||||
|
||||
int blockAlign = (7 /*MSADPCM_HEADER_LENGTH*/) * channels
|
||||
const int blockAlign = (7 /*MSADPCM_HEADER_LENGTH*/) * channels
|
||||
+ (samplesPerBlock - 2) * (4 /* MSADPCM_BITS_PER_SAMPLE */) * channels / 8;
|
||||
|
||||
wfx->wFormatTag = WAVE_FORMAT_ADPCM;
|
||||
|
|
|
@ -95,12 +95,15 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
HRESULT Initialize(_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,
|
||||
#ifdef DIRECTX_ENABLE_SEEK_TABLES
|
||||
_In_reads_opt_(seekCount) const uint32_t* seekTable, size_t seekCount,
|
||||
#endif
|
||||
uint32_t loopStart, uint32_t loopLength) noexcept;
|
||||
HRESULT Initialize(
|
||||
_In_ const AudioEngine* engine,
|
||||
_Inout_ std::unique_ptr<uint8_t[]>& wavData,
|
||||
_In_ const WAVEFORMATEX* wfx,
|
||||
_In_reads_bytes_(audioBytes) const uint8_t* startAudio, size_t audioBytes,
|
||||
#ifdef DIRECTX_ENABLE_SEEK_TABLES
|
||||
_In_reads_opt_(seekCount) const uint32_t* seekTable, size_t seekCount,
|
||||
#endif
|
||||
uint32_t loopStart, uint32_t loopLength) noexcept;
|
||||
|
||||
void Play(float volume, float pitch, float pan);
|
||||
|
||||
|
@ -176,12 +179,15 @@ private:
|
|||
|
||||
|
||||
_Use_decl_annotations_
|
||||
HRESULT SoundEffect::Impl::Initialize(AudioEngine* engine, std::unique_ptr<uint8_t[]>& wavData,
|
||||
const WAVEFORMATEX* wfx, const uint8_t* startAudio, size_t audioBytes,
|
||||
#ifdef DIRECTX_ENABLE_SEEK_TABLES
|
||||
const uint32_t* seekTable, size_t seekCount,
|
||||
#endif
|
||||
uint32_t loopStart, uint32_t loopLength) noexcept
|
||||
HRESULT SoundEffect::Impl::Initialize(
|
||||
const AudioEngine* engine,
|
||||
std::unique_ptr<uint8_t[]>& wavData,
|
||||
const WAVEFORMATEX* wfx,
|
||||
const uint8_t* startAudio, size_t audioBytes,
|
||||
#ifdef DIRECTX_ENABLE_SEEK_TABLES
|
||||
const uint32_t* seekTable, size_t seekCount,
|
||||
#endif
|
||||
uint32_t loopStart, uint32_t loopLength) noexcept
|
||||
{
|
||||
if (!engine || !IsValid(wfx) || !startAudio || !audioBytes || !wavData)
|
||||
return E_INVALIDARG;
|
||||
|
@ -191,96 +197,96 @@ HRESULT SoundEffect::Impl::Initialize(AudioEngine* engine, std::unique_ptr<uint8
|
|||
|
||||
switch (GetFormatTag(wfx))
|
||||
{
|
||||
case WAVE_FORMAT_PCM:
|
||||
case WAVE_FORMAT_IEEE_FLOAT:
|
||||
case WAVE_FORMAT_ADPCM:
|
||||
// Take ownership of the buffer
|
||||
mWavData.reset(wavData.release());
|
||||
case WAVE_FORMAT_PCM:
|
||||
case WAVE_FORMAT_IEEE_FLOAT:
|
||||
case WAVE_FORMAT_ADPCM:
|
||||
// Take ownership of the buffer
|
||||
mWavData.reset(wavData.release());
|
||||
|
||||
// WARNING: We assume the wfx and startAudio parameters are pointers into the wavData memory buffer
|
||||
mWaveFormat = wfx;
|
||||
mStartAudio = startAudio;
|
||||
break;
|
||||
// WARNING: We assume the wfx and startAudio parameters are pointers into the wavData memory buffer
|
||||
mWaveFormat = wfx;
|
||||
mStartAudio = startAudio;
|
||||
break;
|
||||
|
||||
#ifdef DIRECTX_ENABLE_XWMA
|
||||
#ifdef DIRECTX_ENABLE_XWMA
|
||||
|
||||
case WAVE_FORMAT_WMAUDIO2:
|
||||
case WAVE_FORMAT_WMAUDIO3:
|
||||
if (!seekCount || !seekTable)
|
||||
{
|
||||
DebugTrace("ERROR: SoundEffect format xWMA requires seek table\n");
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (seekCount > UINT32_MAX)
|
||||
return E_INVALIDARG;
|
||||
|
||||
// Take ownership of the buffer
|
||||
mWavData.reset(wavData.release());
|
||||
|
||||
// WARNING: We assume the wfx, startAudio, and mSeekTable parameters are pointers into the wavData memory buffer
|
||||
mWaveFormat = wfx;
|
||||
mStartAudio = startAudio;
|
||||
mSeekCount = static_cast<uint32_t>(seekCount);
|
||||
mSeekTable = seekTable;
|
||||
break;
|
||||
|
||||
#endif // xWMA
|
||||
|
||||
#ifdef DIRECTX_ENABLE_XMA2
|
||||
|
||||
case WAVE_FORMAT_XMA2:
|
||||
if (!seekCount || !seekTable)
|
||||
{
|
||||
DebugTrace("ERROR: SoundEffect format XMA2 requires seek table\n");
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (seekCount > UINT32_MAX)
|
||||
return E_INVALIDARG;
|
||||
|
||||
{
|
||||
HRESULT hr = ApuAlloc(&mXMAMemory, nullptr,
|
||||
static_cast<UINT32>(audioBytes), SHAPE_XMA_INPUT_BUFFER_ALIGNMENT);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
DebugTrace("ERROR: ApuAlloc failed. Did you allocate a large enough heap with ApuCreateHeap for all your XMA wave data?\n");
|
||||
return hr;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(mXMAMemory, startAudio, audioBytes);
|
||||
mStartAudio = reinterpret_cast<const uint8_t*>(mXMAMemory);
|
||||
|
||||
mWavData.reset(new (std::nothrow) uint8_t[sizeof(XMA2WAVEFORMATEX) + (seekCount * sizeof(uint32_t))]);
|
||||
if (!mWavData)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
memcpy(mWavData.get(), wfx, sizeof(XMA2WAVEFORMATEX));
|
||||
mWaveFormat = reinterpret_cast<WAVEFORMATEX*>(mWavData.get());
|
||||
|
||||
// XMA seek table is Big-Endian
|
||||
{
|
||||
auto dest = reinterpret_cast<uint32_t*>(mWavData.get() + sizeof(XMA2WAVEFORMATEX));
|
||||
for (size_t k = 0; k < seekCount; ++k)
|
||||
{
|
||||
dest[k] = _byteswap_ulong(seekTable[k]);
|
||||
}
|
||||
}
|
||||
|
||||
mSeekCount = static_cast<uint32_t>(seekCount);
|
||||
mSeekTable = reinterpret_cast<const uint32_t*>(mWavData.get() + sizeof(XMA2WAVEFORMATEX));
|
||||
|
||||
wavData.reset();
|
||||
break;
|
||||
|
||||
#endif // XMA2
|
||||
|
||||
default:
|
||||
case WAVE_FORMAT_WMAUDIO2:
|
||||
case WAVE_FORMAT_WMAUDIO3:
|
||||
if (!seekCount || !seekTable)
|
||||
{
|
||||
DebugTrace("ERROR: SoundEffect encountered an unsupported format tag (%u)\n", wfx->wFormatTag);
|
||||
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
|
||||
DebugTrace("ERROR: SoundEffect format xWMA requires seek table\n");
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (seekCount > UINT32_MAX)
|
||||
return E_INVALIDARG;
|
||||
|
||||
// Take ownership of the buffer
|
||||
mWavData.reset(wavData.release());
|
||||
|
||||
// WARNING: We assume the wfx, startAudio, and mSeekTable parameters are pointers into the wavData memory buffer
|
||||
mWaveFormat = wfx;
|
||||
mStartAudio = startAudio;
|
||||
mSeekCount = static_cast<uint32_t>(seekCount);
|
||||
mSeekTable = seekTable;
|
||||
break;
|
||||
|
||||
#endif // xWMA
|
||||
|
||||
#ifdef DIRECTX_ENABLE_XMA2
|
||||
|
||||
case WAVE_FORMAT_XMA2:
|
||||
if (!seekCount || !seekTable)
|
||||
{
|
||||
DebugTrace("ERROR: SoundEffect format XMA2 requires seek table\n");
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (seekCount > UINT32_MAX)
|
||||
return E_INVALIDARG;
|
||||
|
||||
{
|
||||
HRESULT hr = ApuAlloc(&mXMAMemory, nullptr,
|
||||
static_cast<UINT32>(audioBytes), SHAPE_XMA_INPUT_BUFFER_ALIGNMENT);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
DebugTrace("ERROR: ApuAlloc failed. Did you allocate a large enough heap with ApuCreateHeap for all your XMA wave data?\n");
|
||||
return hr;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(mXMAMemory, startAudio, audioBytes);
|
||||
mStartAudio = reinterpret_cast<const uint8_t*>(mXMAMemory);
|
||||
|
||||
mWavData.reset(new (std::nothrow) uint8_t[sizeof(XMA2WAVEFORMATEX) + (seekCount * sizeof(uint32_t))]);
|
||||
if (!mWavData)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
memcpy(mWavData.get(), wfx, sizeof(XMA2WAVEFORMATEX));
|
||||
mWaveFormat = reinterpret_cast<WAVEFORMATEX*>(mWavData.get());
|
||||
|
||||
// XMA seek table is Big-Endian
|
||||
{
|
||||
auto dest = reinterpret_cast<uint32_t*>(mWavData.get() + sizeof(XMA2WAVEFORMATEX));
|
||||
for (size_t k = 0; k < seekCount; ++k)
|
||||
{
|
||||
dest[k] = _byteswap_ulong(seekTable[k]);
|
||||
}
|
||||
}
|
||||
|
||||
mSeekCount = static_cast<uint32_t>(seekCount);
|
||||
mSeekTable = reinterpret_cast<const uint32_t*>(mWavData.get() + sizeof(XMA2WAVEFORMATEX));
|
||||
|
||||
wavData.reset();
|
||||
break;
|
||||
|
||||
#endif // XMA2
|
||||
|
||||
default:
|
||||
{
|
||||
DebugTrace("ERROR: SoundEffect encountered an unsupported format tag (%u)\n", wfx->wFormatTag);
|
||||
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
|
||||
}
|
||||
}
|
||||
|
||||
mAudioBytes = static_cast<uint32_t>(audioBytes);
|
||||
|
@ -311,7 +317,7 @@ void SoundEffect::Impl::Play(float volume, float pitch, float pan)
|
|||
|
||||
if (pitch != 0.f)
|
||||
{
|
||||
float fr = XAudio2SemitonesToFrequencyRatio(pitch * 12.f);
|
||||
const float fr = XAudio2SemitonesToFrequencyRatio(pitch * 12.f);
|
||||
|
||||
HRESULT hr = voice->SetFrequencyRatio(fr);
|
||||
ThrowIfFailed(hr);
|
||||
|
@ -337,7 +343,7 @@ void SoundEffect::Impl::Play(float volume, float pitch, float pan)
|
|||
buffer.pContext = this;
|
||||
|
||||
#ifdef DIRECTX_ENABLE_XWMA
|
||||
uint32_t tag = GetFormatTag(mWaveFormat);
|
||||
const uint32_t tag = GetFormatTag(mWaveFormat);
|
||||
if (tag == WAVE_FORMAT_WMAUDIO2 || tag == WAVE_FORMAT_WMAUDIO3)
|
||||
{
|
||||
XAUDIO2_BUFFER_WMA wmaBuffer = {};
|
||||
|
@ -517,7 +523,7 @@ size_t SoundEffect::GetSampleDuration() const noexcept
|
|||
auto adpcmFmt = reinterpret_cast<const ADPCMWAVEFORMAT*>(pImpl->mWaveFormat);
|
||||
|
||||
uint64_t duration = uint64_t(pImpl->mAudioBytes / adpcmFmt->wfx.nBlockAlign) * adpcmFmt->wSamplesPerBlock;
|
||||
unsigned int partial = pImpl->mAudioBytes % adpcmFmt->wfx.nBlockAlign;
|
||||
const unsigned int partial = pImpl->mAudioBytes % adpcmFmt->wfx.nBlockAlign;
|
||||
if (partial)
|
||||
{
|
||||
if (partial >= (7u * adpcmFmt->wfx.nChannels))
|
||||
|
@ -562,7 +568,7 @@ size_t SoundEffect::GetSampleDurationMS() const noexcept
|
|||
if (!pImpl->mWaveFormat || !pImpl->mWaveFormat->nSamplesPerSec)
|
||||
return 0;
|
||||
|
||||
uint64_t samples = GetSampleDuration();
|
||||
const uint64_t samples = GetSampleDuration();
|
||||
return static_cast<size_t>((samples * 1000) / pImpl->mWaveFormat->nSamplesPerSec);
|
||||
}
|
||||
|
||||
|
@ -585,7 +591,7 @@ bool SoundEffect::FillSubmitBuffer(_Out_ XAUDIO2_BUFFER& buffer, _Out_ XAUDIO2_B
|
|||
buffer.LoopBegin = pImpl->mLoopStart;
|
||||
buffer.LoopLength = pImpl->mLoopLength;
|
||||
|
||||
uint32_t tag = GetFormatTag(pImpl->mWaveFormat);
|
||||
const uint32_t tag = GetFormatTag(pImpl->mWaveFormat);
|
||||
if (tag == WAVE_FORMAT_WMAUDIO2 || tag == WAVE_FORMAT_WMAUDIO3)
|
||||
{
|
||||
wmaBuffer.PacketCount = pImpl->mSeekCount;
|
||||
|
|
|
@ -209,7 +209,7 @@ void SoundEffectInstance::Impl::Play(bool loop)
|
|||
auto wfx = (mWaveBank) ? mWaveBank->GetFormat(mIndex, reinterpret_cast<WAVEFORMATEX*>(buff), sizeof(buff))
|
||||
: mEffect->GetFormat();
|
||||
|
||||
size_t length = (mWaveBank) ? mWaveBank->GetSampleSizeInBytes(mIndex) : mEffect->GetSampleSizeInBytes();
|
||||
const size_t length = (mWaveBank) ? mWaveBank->GetSampleSizeInBytes(mIndex) : mEffect->GetSampleSizeInBytes();
|
||||
|
||||
DebugTrace("\tFormat Tag %u, %u channels, %u-bit, %u Hz, %zu bytes\n",
|
||||
wfx->wFormatTag, wfx->nChannels, wfx->wBitsPerSample, wfx->nSamplesPerSec, length);
|
||||
|
|
|
@ -39,16 +39,16 @@ using namespace DirectX;
|
|||
|
||||
namespace
|
||||
{
|
||||
const size_t DVD_SECTOR_SIZE = 2048;
|
||||
const size_t ADVANCED_FORMAT_SECTOR_SIZE = 4096;
|
||||
const size_t MAX_BUFFER_COUNT = 3;
|
||||
constexpr size_t DVD_SECTOR_SIZE = 2048;
|
||||
constexpr size_t ADVANCED_FORMAT_SECTOR_SIZE = 4096;
|
||||
constexpr size_t MAX_BUFFER_COUNT = 3;
|
||||
|
||||
#ifdef DIRECTX_ENABLE_SEEK_TABLES
|
||||
const size_t MAX_STREAMING_SEEK_PACKETS = 2048;
|
||||
constexpr size_t MAX_STREAMING_SEEK_PACKETS = 2048;
|
||||
#endif
|
||||
|
||||
#ifdef DIRECTX_ENABLE_XMA2
|
||||
const size_t XMA2_64KBLOCKINBYTES = 65536;
|
||||
constexpr size_t XMA2_64KBLOCKINBYTES = 65536;
|
||||
|
||||
struct apu_deleter { void operator()(void* p) noexcept { if (p) ApuFree(p); } };
|
||||
#endif
|
||||
|
@ -401,7 +401,7 @@ HRESULT SoundStreamInstance::Impl::AllocateStreamingBuffers(const WAVEFORMATEX*
|
|||
if (!wfx)
|
||||
return E_INVALIDARG;
|
||||
|
||||
uint32_t tag = GetFormatTag(wfx);
|
||||
const uint32_t tag = GetFormatTag(wfx);
|
||||
|
||||
size_t packetSize = ComputeAsyncPacketSize(wfx, tag, mAsyncAlign);
|
||||
if (!packetSize)
|
||||
|
@ -511,7 +511,7 @@ HRESULT SoundStreamInstance::Impl::ReadBuffers() noexcept
|
|||
|
||||
HANDLE async = mWaveBank->GetAsyncHandle();
|
||||
|
||||
uint32_t readBuffer = mCurrentDiskReadBuffer;
|
||||
const uint32_t readBuffer = mCurrentDiskReadBuffer;
|
||||
for (uint32_t j = 0; j < MAX_BUFFER_COUNT; ++j)
|
||||
{
|
||||
uint32_t entry = (j + readBuffer) % uint32_t(MAX_BUFFER_COUNT);
|
||||
|
@ -519,7 +519,7 @@ HRESULT SoundStreamInstance::Impl::ReadBuffers() noexcept
|
|||
{
|
||||
if (mCurrentPosition < mLengthInBytes)
|
||||
{
|
||||
auto cbValid = static_cast<uint32_t>(std::min(mPacketSize, mLengthInBytes - mCurrentPosition));
|
||||
auto const cbValid = static_cast<uint32_t>(std::min(mPacketSize, mLengthInBytes - mCurrentPosition));
|
||||
|
||||
mPackets[entry].valid = cbValid;
|
||||
mPackets[entry].audioBytes = 0;
|
||||
|
@ -528,7 +528,7 @@ HRESULT SoundStreamInstance::Impl::ReadBuffers() noexcept
|
|||
|
||||
if (!ReadFile(async, mPackets[entry].buffer, uint32_t(mPacketSize), nullptr, &mPackets[entry].request))
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
const DWORD error = GetLastError();
|
||||
if (error != ERROR_IO_PENDING)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
|
@ -573,9 +573,9 @@ HRESULT SoundStreamInstance::Impl::PlayBuffers() noexcept
|
|||
{
|
||||
DWORD cb = 0;
|
||||
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
|
||||
BOOL result = GetOverlappedResultEx(async, &mPackets[j].request, &cb, 0, FALSE);
|
||||
const BOOL result = GetOverlappedResultEx(async, &mPackets[j].request, &cb, 0, FALSE);
|
||||
#else
|
||||
BOOL result = GetOverlappedResult(async, &mPackets[j].request, &cb, FALSE);
|
||||
const BOOL result = GetOverlappedResult(async, &mPackets[j].request, &cb, FALSE);
|
||||
#endif
|
||||
if (result)
|
||||
{
|
||||
|
@ -583,7 +583,7 @@ HRESULT SoundStreamInstance::Impl::PlayBuffers() noexcept
|
|||
}
|
||||
else
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
const DWORD error = GetLastError();
|
||||
if (error != ERROR_IO_INCOMPLETE)
|
||||
{
|
||||
ThrowIfFailed(HRESULT_FROM_WIN32(error));
|
||||
|
@ -625,7 +625,7 @@ HRESULT SoundStreamInstance::Impl::PlayBuffers() noexcept
|
|||
// Compute how many bytes at the start of our current packet are the tail of the partial block.
|
||||
thisFrameStitch = mBlockAlign - prevFrameStitch;
|
||||
|
||||
uint32_t k = (mCurrentPlayBuffer + MAX_BUFFER_COUNT - 1) % MAX_BUFFER_COUNT;
|
||||
const uint32_t k = (mCurrentPlayBuffer + MAX_BUFFER_COUNT - 1) % MAX_BUFFER_COUNT;
|
||||
if (mPackets[k].state == State::READY || mPackets[k].state == State::PLAYING)
|
||||
{
|
||||
// Compute how many bytes at the start of the previous packet were the tail of the previous stitch block.
|
||||
|
@ -633,7 +633,7 @@ HRESULT SoundStreamInstance::Impl::PlayBuffers() noexcept
|
|||
prevFrameStitchOffset = (prevFrameStitchOffset > 0) ? (mBlockAlign - prevFrameStitchOffset) : 0u;
|
||||
|
||||
// Point to the start of the partial block's head in the previous packet.
|
||||
auto prevBuffer = mPackets[k].buffer + prevFrameStitchOffset + mPackets[k].audioBytes;
|
||||
const auto *prevBuffer = mPackets[k].buffer + prevFrameStitchOffset + mPackets[k].audioBytes;
|
||||
|
||||
// Merge the the head partial block in the previous packet with the tail partial block at the start of our packet.
|
||||
memcpy(buffer, prevBuffer, prevFrameStitch);
|
||||
|
@ -659,7 +659,7 @@ HRESULT SoundStreamInstance::Impl::PlayBuffers() noexcept
|
|||
wmaBuf.pDecodedPacketCumulativeBytes = mSeekTableCopy;
|
||||
wmaBuf.PacketCount = 1;
|
||||
|
||||
uint32_t seekOffset = (mPackets[k].startPosition + prevFrameStitchOffset + mPackets[k].audioBytes) / mBlockAlign;
|
||||
const uint32_t seekOffset = (mPackets[k].startPosition + prevFrameStitchOffset + mPackets[k].audioBytes) / mBlockAlign;
|
||||
assert(seekOffset > 0);
|
||||
mSeekTableCopy[0] = mSeekTable[seekOffset] - mSeekTable[seekOffset - 1];
|
||||
|
||||
|
@ -697,7 +697,7 @@ HRESULT SoundStreamInstance::Impl::PlayBuffers() noexcept
|
|||
|
||||
wmaBuf.PacketCount = valid / mBlockAlign;
|
||||
|
||||
uint32_t seekOffset = mPackets[mCurrentPlayBuffer].startPosition / mBlockAlign;
|
||||
const uint32_t seekOffset = mPackets[mCurrentPlayBuffer].startPosition / mBlockAlign;
|
||||
if (seekOffset > MAX_STREAMING_SEEK_PACKETS)
|
||||
{
|
||||
DebugTrace("ERROR: xWMA packet seek count exceeds %zu\n", MAX_STREAMING_SEEK_PACKETS);
|
||||
|
@ -835,7 +835,7 @@ bool SoundStreamInstance::IsLooped() const noexcept
|
|||
|
||||
SoundState SoundStreamInstance::GetState() noexcept
|
||||
{
|
||||
SoundState state = pImpl->mBase.GetState(pImpl->mEndStream);
|
||||
const SoundState state = pImpl->mBase.GetState(pImpl->mEndStream);
|
||||
if (state == STOPPED)
|
||||
{
|
||||
pImpl->mPlaying = false;
|
||||
|
|
|
@ -123,7 +123,7 @@ namespace
|
|||
if (header->tag == tag)
|
||||
return header;
|
||||
|
||||
auto offset = header->size + sizeof(RIFFChunk);
|
||||
auto const offset = header->size + sizeof(RIFFChunk);
|
||||
ptr += offset;
|
||||
}
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
HRESULT Initialize(_In_ AudioEngine* engine, _In_z_ const wchar_t* wbFileName) noexcept;
|
||||
HRESULT Initialize(_In_ const AudioEngine* engine, _In_z_ const wchar_t* wbFileName) noexcept;
|
||||
|
||||
void Play(unsigned int index, float volume, float pitch, float pan);
|
||||
|
||||
|
@ -138,7 +138,7 @@ public:
|
|||
|
||||
|
||||
_Use_decl_annotations_
|
||||
HRESULT WaveBank::Impl::Initialize(AudioEngine* engine, const wchar_t* wbFileName) noexcept
|
||||
HRESULT WaveBank::Impl::Initialize(const AudioEngine* engine, const wchar_t* wbFileName) noexcept
|
||||
{
|
||||
if (!engine || !wbFileName)
|
||||
return E_INVALIDARG;
|
||||
|
@ -197,7 +197,7 @@ void WaveBank::Impl::Play(unsigned int index, float volume, float pitch, float p
|
|||
|
||||
if (pitch != 0.f)
|
||||
{
|
||||
float fr = XAudio2SemitonesToFrequencyRatio(pitch * 12.f);
|
||||
const float fr = XAudio2SemitonesToFrequencyRatio(pitch * 12.f);
|
||||
|
||||
hr = voice->SetFrequencyRatio(fr);
|
||||
ThrowIfFailed(hr);
|
||||
|
@ -298,7 +298,7 @@ void WaveBank::Play(unsigned int index, float volume, float pitch, float pan)
|
|||
|
||||
void WaveBank::Play(_In_z_ const char* name)
|
||||
{
|
||||
unsigned int index = pImpl->mReader.Find(name);
|
||||
const unsigned int index = pImpl->mReader.Find(name);
|
||||
if (index == unsigned(-1))
|
||||
{
|
||||
DebugTrace("WARNING: Name '%hs' not found in wave bank, one-shot not triggered\n", name);
|
||||
|
@ -311,7 +311,7 @@ void WaveBank::Play(_In_z_ const char* name)
|
|||
|
||||
void WaveBank::Play(_In_z_ const char* name, float volume, float pitch, float pan)
|
||||
{
|
||||
unsigned int index = pImpl->mReader.Find(name);
|
||||
const unsigned int index = pImpl->mReader.Find(name);
|
||||
if (index == unsigned(-1))
|
||||
{
|
||||
DebugTrace("WARNING: Name '%hs' not found in wave bank, one-shot not triggered\n", name);
|
||||
|
@ -354,7 +354,7 @@ std::unique_ptr<SoundEffectInstance> WaveBank::CreateInstance(unsigned int index
|
|||
|
||||
std::unique_ptr<SoundEffectInstance> WaveBank::CreateInstance(_In_z_ const char* name, SOUND_EFFECT_INSTANCE_FLAGS flags)
|
||||
{
|
||||
unsigned int index = pImpl->mReader.Find(name);
|
||||
const unsigned int index = pImpl->mReader.Find(name);
|
||||
if (index == unsigned(-1))
|
||||
{
|
||||
// We don't throw an exception here as titles often simply ignore missing assets rather than fail
|
||||
|
@ -397,7 +397,7 @@ std::unique_ptr<SoundStreamInstance> WaveBank::CreateStreamInstance(unsigned int
|
|||
|
||||
std::unique_ptr<SoundStreamInstance> WaveBank::CreateStreamInstance(_In_z_ const char* name, SOUND_EFFECT_INSTANCE_FLAGS flags)
|
||||
{
|
||||
unsigned int index = pImpl->mReader.Find(name);
|
||||
const unsigned int index = pImpl->mReader.Find(name);
|
||||
if (index == unsigned(-1))
|
||||
{
|
||||
// We don't throw an exception here as titles often simply ignore missing assets rather than fail
|
||||
|
|
|
@ -176,7 +176,7 @@ namespace
|
|||
1280
|
||||
};
|
||||
|
||||
uint32_t dwBlockAlignIndex = wBlockAlign & 0x1F;
|
||||
const uint32_t dwBlockAlignIndex = wBlockAlign & 0x1F;
|
||||
if (dwBlockAlignIndex < 17)
|
||||
return aWMABlockAlign[dwBlockAlignIndex];
|
||||
}
|
||||
|
@ -198,8 +198,8 @@ namespace
|
|||
|
||||
case TAG_ADPCM:
|
||||
{
|
||||
uint32_t blockAlign = BlockAlign();
|
||||
uint32_t samplesPerAdpcmBlock = AdpcmSamplesPerBlock();
|
||||
const uint32_t blockAlign = BlockAlign();
|
||||
const uint32_t samplesPerAdpcmBlock = AdpcmSamplesPerBlock();
|
||||
return blockAlign * nSamplesPerSec / samplesPerAdpcmBlock;
|
||||
}
|
||||
|
||||
|
@ -217,7 +217,7 @@ namespace
|
|||
};
|
||||
// bitrate = entry * 8
|
||||
|
||||
uint32_t dwBytesPerSecIndex = wBlockAlign >> 5;
|
||||
const uint32_t dwBytesPerSecIndex = wBlockAlign >> 5;
|
||||
if (dwBytesPerSecIndex < 7)
|
||||
return aWMAAvgBytesPerSec[dwBytesPerSecIndex];
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ namespace
|
|||
|
||||
DWORD AdpcmSamplesPerBlock() const noexcept
|
||||
{
|
||||
uint32_t nBlockAlign = (wBlockAlign + ADPCM_BLOCKALIGN_CONVERSION_OFFSET) * nChannels;
|
||||
const uint32_t nBlockAlign = (wBlockAlign + ADPCM_BLOCKALIGN_CONVERSION_OFFSET) * nChannels;
|
||||
return nBlockAlign * 2 / uint32_t(nChannels) - 12;
|
||||
}
|
||||
|
||||
|
@ -349,7 +349,7 @@ namespace
|
|||
case MINIWAVEFORMAT::TAG_ADPCM:
|
||||
{
|
||||
uint32_t duration = (length / data.CompactFormat.BlockAlign()) * data.CompactFormat.AdpcmSamplesPerBlock();
|
||||
uint32_t partial = length % data.CompactFormat.BlockAlign();
|
||||
const uint32_t partial = length % data.CompactFormat.BlockAlign();
|
||||
if (partial)
|
||||
{
|
||||
if (partial >= (7u * data.CompactFormat.nChannels))
|
||||
|
@ -361,7 +361,7 @@ namespace
|
|||
case MINIWAVEFORMAT::TAG_WMA:
|
||||
if (seekTable)
|
||||
{
|
||||
uint32_t seekCount = *seekTable;
|
||||
const uint32_t seekCount = *seekTable;
|
||||
if (seekCount > 0)
|
||||
{
|
||||
return seekTable[seekCount] / uint32_t(2 * data.CompactFormat.nChannels);
|
||||
|
@ -372,7 +372,7 @@ namespace
|
|||
case MINIWAVEFORMAT::TAG_XMA:
|
||||
if (seekTable)
|
||||
{
|
||||
uint32_t seekCount = *seekTable;
|
||||
const uint32_t seekCount = *seekTable;
|
||||
if (seekCount > 0)
|
||||
{
|
||||
return seekTable[seekCount];
|
||||
|
@ -394,7 +394,7 @@ namespace
|
|||
if (!seekTable || index >= data.dwEntryCount)
|
||||
return nullptr;
|
||||
|
||||
uint32_t seekSize = header.Segments[HEADER::SEGIDX_SEEKTABLES].dwLength;
|
||||
const uint32_t seekSize = header.Segments[HEADER::SEGIDX_SEEKTABLES].dwLength;
|
||||
|
||||
if ((index * sizeof(uint32_t)) > seekSize)
|
||||
return nullptr;
|
||||
|
@ -544,7 +544,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
|
|||
bool wait = false;
|
||||
if (!ReadFile(hFile.get(), &m_header, sizeof(m_header), nullptr, &request))
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
const DWORD error = GetLastError();
|
||||
if (error != ERROR_IO_PENDING)
|
||||
return HRESULT_FROM_WIN32(error);
|
||||
wait = true;
|
||||
|
@ -574,7 +574,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
|
|||
return E_FAIL;
|
||||
}
|
||||
|
||||
bool be = (m_header.dwSignature == HEADER::BE_SIGNATURE);
|
||||
const bool be = (m_header.dwSignature == HEADER::BE_SIGNATURE);
|
||||
if (be)
|
||||
{
|
||||
DebugTrace("INFO: \"%ls\" is a big-endian (Xbox 360) wave bank\n", szFileName);
|
||||
|
@ -594,7 +594,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
|
|||
wait = false;
|
||||
if (!ReadFile(hFile.get(), &m_data, sizeof(m_data), nullptr, &request))
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
const DWORD error = GetLastError();
|
||||
if (error != ERROR_IO_PENDING)
|
||||
return HRESULT_FROM_WIN32(error);
|
||||
wait = true;
|
||||
|
@ -657,14 +657,14 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
|
|||
}
|
||||
}
|
||||
|
||||
DWORD metadataBytes = m_header.Segments[HEADER::SEGIDX_ENTRYMETADATA].dwLength;
|
||||
const DWORD metadataBytes = m_header.Segments[HEADER::SEGIDX_ENTRYMETADATA].dwLength;
|
||||
if (metadataBytes != (m_data.dwEntryCount * m_data.dwEntryMetaDataElementSize))
|
||||
{
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
// Load names
|
||||
DWORD namesBytes = m_header.Segments[HEADER::SEGIDX_ENTRYNAMES].dwLength;
|
||||
const DWORD namesBytes = m_header.Segments[HEADER::SEGIDX_ENTRYNAMES].dwLength;
|
||||
if (namesBytes > 0)
|
||||
{
|
||||
if (namesBytes >= (m_data.dwEntryNameElementSize * m_data.dwEntryCount))
|
||||
|
@ -680,7 +680,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
|
|||
wait = false;
|
||||
if (!ReadFile(hFile.get(), temp.get(), namesBytes, nullptr, &request))
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
const DWORD error = GetLastError();
|
||||
if (error != ERROR_IO_PENDING)
|
||||
return HRESULT_FROM_WIN32(error);
|
||||
wait = true;
|
||||
|
@ -704,7 +704,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
|
|||
|
||||
for (uint32_t j = 0; j < m_data.dwEntryCount; ++j)
|
||||
{
|
||||
DWORD n = m_data.dwEntryNameElementSize * j;
|
||||
const DWORD n = m_data.dwEntryNameElementSize * j;
|
||||
|
||||
char name[64] = {};
|
||||
strncpy_s(name, &temp[n], sizeof(name));
|
||||
|
@ -733,7 +733,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
|
|||
wait = false;
|
||||
if (!ReadFile(hFile.get(), m_entries.get(), metadataBytes, nullptr, &request))
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
const DWORD error = GetLastError();
|
||||
if (error != ERROR_IO_PENDING)
|
||||
return HRESULT_FROM_WIN32(error);
|
||||
wait = true;
|
||||
|
@ -772,7 +772,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
|
|||
}
|
||||
|
||||
// Load seek tables (XMA2 / xWMA)
|
||||
DWORD seekLen = m_header.Segments[HEADER::SEGIDX_SEEKTABLES].dwLength;
|
||||
const DWORD seekLen = m_header.Segments[HEADER::SEGIDX_SEEKTABLES].dwLength;
|
||||
if (seekLen > 0)
|
||||
{
|
||||
m_seekData.reset(new (std::nothrow) uint8_t[seekLen]);
|
||||
|
@ -786,7 +786,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
|
|||
wait = false;
|
||||
if (!ReadFile(hFile.get(), m_seekData.get(), seekLen, nullptr, &request))
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
const DWORD error = GetLastError();
|
||||
if (error != ERROR_IO_PENDING)
|
||||
return HRESULT_FROM_WIN32(error);
|
||||
wait = true;
|
||||
|
@ -818,7 +818,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
|
|||
}
|
||||
}
|
||||
|
||||
DWORD waveLen = m_header.Segments[HEADER::SEGIDX_ENTRYWAVEDATA].dwLength;
|
||||
const DWORD waveLen = m_header.Segments[HEADER::SEGIDX_ENTRYWAVEDATA].dwLength;
|
||||
if (!waveLen)
|
||||
{
|
||||
return HRESULT_FROM_WIN32(ERROR_NO_DATA);
|
||||
|
@ -907,7 +907,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
|
|||
|
||||
if (!ReadFile(hFile.get(), dest, waveLen, nullptr, &m_request))
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
const DWORD error = GetLastError();
|
||||
if (error != ERROR_IO_PENDING)
|
||||
return HRESULT_FROM_WIN32(error);
|
||||
}
|
||||
|
@ -1232,7 +1232,7 @@ HRESULT WaveBankReader::Impl::GetMetadata(uint32_t index, Metadata& metadata) co
|
|||
|
||||
if (m_data.dwFlags & BANKDATA::TYPE_STREAMING)
|
||||
{
|
||||
uint64_t offset = uint64_t(metadata.offsetBytes) + uint64_t(m_header.Segments[HEADER::SEGIDX_ENTRYWAVEDATA].dwOffset);
|
||||
const uint64_t offset = uint64_t(metadata.offsetBytes) + uint64_t(m_header.Segments[HEADER::SEGIDX_ENTRYWAVEDATA].dwOffset);
|
||||
if (offset > UINT32_MAX)
|
||||
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
|
||||
|
||||
|
@ -1256,9 +1256,9 @@ bool WaveBankReader::Impl::UpdatePrepared() noexcept
|
|||
|
||||
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
|
||||
DWORD bytes;
|
||||
BOOL result = GetOverlappedResultEx(m_async, &m_request, &bytes, 0, FALSE);
|
||||
const BOOL result = GetOverlappedResultEx(m_async, &m_request, &bytes, 0, FALSE);
|
||||
#else
|
||||
bool result = HasOverlappedIoCompleted(&m_request);
|
||||
const bool result = HasOverlappedIoCompleted(&m_request);
|
||||
#endif
|
||||
if (result)
|
||||
{
|
||||
|
|
16
Inc/Audio.h
16
Inc/Audio.h
|
@ -479,10 +479,10 @@ namespace DirectX
|
|||
|
||||
void XM_CALLCONV SetOrientationFromQuaternion(FXMVECTOR quat) noexcept
|
||||
{
|
||||
XMVECTOR forward = XMVector3Rotate(g_XMIdentityR2, quat);
|
||||
const XMVECTOR forward = XMVector3Rotate(g_XMIdentityR2, quat);
|
||||
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&OrientFront), forward);
|
||||
|
||||
XMVECTOR up = XMVector3Rotate(g_XMIdentityR1, quat);
|
||||
const XMVECTOR up = XMVector3Rotate(g_XMIdentityR1, quat);
|
||||
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&OrientTop), up);
|
||||
}
|
||||
|
||||
|
@ -491,10 +491,10 @@ namespace DirectX
|
|||
{
|
||||
if (dt > 0.f)
|
||||
{
|
||||
XMVECTOR lastPos = XMLoadFloat3(reinterpret_cast<const XMFLOAT3*>(&Position));
|
||||
const XMVECTOR lastPos = XMLoadFloat3(reinterpret_cast<const XMFLOAT3*>(&Position));
|
||||
|
||||
XMVECTOR vDelta = XMVectorSubtract(newPos, lastPos);
|
||||
XMVECTOR vt = XMVectorReplicate(dt);
|
||||
const XMVECTOR vt = XMVectorReplicate(dt);
|
||||
XMVECTOR v = XMVectorDivide(vDelta, vt);
|
||||
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&Velocity), v);
|
||||
|
||||
|
@ -573,10 +573,10 @@ namespace DirectX
|
|||
|
||||
void XM_CALLCONV SetOrientationFromQuaternion(FXMVECTOR quat) noexcept
|
||||
{
|
||||
XMVECTOR forward = XMVector3Rotate(g_XMIdentityR2, quat);
|
||||
const XMVECTOR forward = XMVector3Rotate(g_XMIdentityR2, quat);
|
||||
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&OrientFront), forward);
|
||||
|
||||
XMVECTOR up = XMVector3Rotate(g_XMIdentityR1, quat);
|
||||
const XMVECTOR up = XMVector3Rotate(g_XMIdentityR1, quat);
|
||||
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&OrientTop), up);
|
||||
}
|
||||
|
||||
|
@ -585,10 +585,10 @@ namespace DirectX
|
|||
{
|
||||
if (dt > 0.f)
|
||||
{
|
||||
XMVECTOR lastPos = XMLoadFloat3(reinterpret_cast<const XMFLOAT3*>(&Position));
|
||||
const XMVECTOR lastPos = XMLoadFloat3(reinterpret_cast<const XMFLOAT3*>(&Position));
|
||||
|
||||
XMVECTOR vDelta = XMVectorSubtract(newPos, lastPos);
|
||||
XMVECTOR vt = XMVectorReplicate(dt);
|
||||
const XMVECTOR vt = XMVectorReplicate(dt);
|
||||
XMVECTOR v = XMVectorDivide(vDelta, vt);
|
||||
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&Velocity), v);
|
||||
|
||||
|
|
|
@ -413,7 +413,7 @@ namespace DirectX
|
|||
if (key <= 0xfe)
|
||||
{
|
||||
auto ptr = reinterpret_cast<const uint32_t*>(this);
|
||||
unsigned int bf = 1u << (key & 0x1f);
|
||||
const unsigned int bf = 1u << (key & 0x1f);
|
||||
return (ptr[(key >> 5)] & bf) != 0;
|
||||
}
|
||||
return false;
|
||||
|
@ -424,7 +424,7 @@ namespace DirectX
|
|||
if (key <= 0xfe)
|
||||
{
|
||||
auto ptr = reinterpret_cast<const uint32_t*>(this);
|
||||
unsigned int bf = 1u << (key & 0x1f);
|
||||
const unsigned int bf = 1u << (key & 0x1f);
|
||||
return (ptr[(key >> 5)] & bf) == 0;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -142,7 +142,7 @@ namespace DirectX
|
|||
void __cdecl CreateInputLayout(_In_ ID3D11Device* device, _In_ IEffect* ieffect, _Outptr_ ID3D11InputLayout** iinputLayout) const;
|
||||
|
||||
// Change effect used by part and regenerate input layout (be sure to call Model::Modified as well)
|
||||
void __cdecl ModifyEffect(_In_ ID3D11Device* device, _In_ std::shared_ptr<IEffect>& ieffect, bool isalpha = false);
|
||||
void __cdecl ModifyEffect(_In_ ID3D11Device* device, _In_ const std::shared_ptr<IEffect>& ieffect, bool isalpha = false);
|
||||
};
|
||||
|
||||
|
||||
|
|
1480
Inc/SimpleMath.inl
1480
Inc/SimpleMath.inl
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -195,10 +195,10 @@ void AlphaTestEffect::Impl::Apply(_In_ ID3D11DeviceContext* deviceContext)
|
|||
if (dirtyFlags & EffectDirtyFlags::AlphaTest)
|
||||
{
|
||||
// Convert reference alpha from 8 bit integer to 0-1 float format.
|
||||
auto reference = static_cast<float>(referenceAlpha) / 255.0f;
|
||||
auto const reference = static_cast<float>(referenceAlpha) / 255.0f;
|
||||
|
||||
// Comparison tolerance of half the 8 bit integer precision.
|
||||
const float threshold = 0.5f / 255.0f;
|
||||
constexpr float threshold = 0.5f / 255.0f;
|
||||
|
||||
// What to do if the alpha comparison passes or fails. Positive accepts the pixel, negative clips it.
|
||||
static const XMVECTORF32 selectIfTrue = { { { 1, -1 } } };
|
||||
|
|
|
@ -152,7 +152,7 @@ class BasicPostProcess::Impl : public AlignedNew<PostProcessConstants>
|
|||
public:
|
||||
explicit Impl(_In_ ID3D11Device* device);
|
||||
|
||||
void Process(_In_ ID3D11DeviceContext* deviceContext, std::function<void __cdecl()>& setCustomState);
|
||||
void Process(_In_ ID3D11DeviceContext* deviceContext, const std::function<void __cdecl()>& setCustomState);
|
||||
|
||||
void SetConstants(bool value = true) noexcept { mUseConstants = value; mDirtyFlags = INT_MAX; }
|
||||
void SetDirtyFlag() noexcept { mDirtyFlags = INT_MAX; }
|
||||
|
@ -219,7 +219,7 @@ BasicPostProcess::Impl::Impl(_In_ ID3D11Device* device)
|
|||
// Sets our state onto the D3D device.
|
||||
void BasicPostProcess::Impl::Process(
|
||||
_In_ ID3D11DeviceContext* deviceContext,
|
||||
std::function<void __cdecl()>& setCustomState)
|
||||
const std::function<void __cdecl()>& setCustomState)
|
||||
{
|
||||
// Set the texture.
|
||||
ID3D11ShaderResourceView* textures[1] = { texture.Get() };
|
||||
|
@ -321,8 +321,8 @@ void BasicPostProcess::Impl::DownScale2x2()
|
|||
throw std::logic_error("Call SetSourceTexture before setting post-process effect");
|
||||
}
|
||||
|
||||
float tu = 1.0f / float(texWidth);
|
||||
float tv = 1.0f / float(texHeight);
|
||||
const float tu = 1.0f / float(texWidth);
|
||||
const float tv = 1.0f / float(texHeight);
|
||||
|
||||
// Sample from the 4 surrounding points. Since the center point will be in the exact
|
||||
// center of 4 texels, a 0.5f offset is needed to specify a texel center.
|
||||
|
@ -348,8 +348,8 @@ void BasicPostProcess::Impl::DownScale4x4()
|
|||
throw std::logic_error("Call SetSourceTexture before setting post-process effect");
|
||||
}
|
||||
|
||||
float tu = 1.0f / float(texWidth);
|
||||
float tv = 1.0f / float(texHeight);
|
||||
const float tu = 1.0f / float(texWidth);
|
||||
const float tv = 1.0f / float(texHeight);
|
||||
|
||||
// Sample from the 16 surrounding points. Since the center point will be in the
|
||||
// exact center of 16 texels, a 1.5f offset is needed to specify a texel center.
|
||||
|
@ -376,8 +376,8 @@ void BasicPostProcess::Impl::GaussianBlur5x5(float multiplier)
|
|||
throw std::logic_error("Call SetSourceTexture before setting post-process effect");
|
||||
}
|
||||
|
||||
float tu = 1.0f / float(texWidth);
|
||||
float tv = 1.0f / float(texHeight);
|
||||
const float tu = 1.0f / float(texWidth);
|
||||
const float tv = 1.0f / float(texHeight);
|
||||
|
||||
float totalWeight = 0.0f;
|
||||
size_t index = 0;
|
||||
|
@ -400,7 +400,7 @@ void BasicPostProcess::Impl::GaussianBlur5x5(float multiplier)
|
|||
offsets[index].z = 0.0f;
|
||||
offsets[index].w = 0.0f;
|
||||
|
||||
float g = GaussianDistribution(float(x), float(y), 1.0f);
|
||||
const float g = GaussianDistribution(float(x), float(y), 1.0f);
|
||||
weights[index] = XMVectorReplicate(g);
|
||||
|
||||
totalWeight += XMVectorGetX(weights[index]);
|
||||
|
@ -413,8 +413,8 @@ void BasicPostProcess::Impl::GaussianBlur5x5(float multiplier)
|
|||
// blur kernels add to 1.0f to ensure that the intensity of the image isn't
|
||||
// changed when the blur occurs. An optional multiplier variable is used to
|
||||
// add or remove image intensity during the blur.
|
||||
XMVECTOR vtw = XMVectorReplicate(totalWeight);
|
||||
XMVECTOR vm = XMVectorReplicate(multiplier);
|
||||
const XMVECTOR vtw = XMVectorReplicate(totalWeight);
|
||||
const XMVECTOR vm = XMVectorReplicate(multiplier);
|
||||
for (size_t i = 0; i < index; ++i)
|
||||
{
|
||||
weights[i] = XMVectorDivide(weights[i], vtw);
|
||||
|
|
48
Src/Bezier.h
48
Src/Bezier.h
|
@ -33,10 +33,10 @@ namespace Bezier
|
|||
{
|
||||
using namespace DirectX;
|
||||
|
||||
XMVECTOR T0 = XMVectorReplicate((1 - t) * (1 - t) * (1 - t));
|
||||
XMVECTOR T1 = XMVectorReplicate(3 * t * (1 - t) * (1 - t));
|
||||
XMVECTOR T2 = XMVectorReplicate(3 * t * t * (1 - t));
|
||||
XMVECTOR T3 = XMVectorReplicate(t * t * t);
|
||||
const XMVECTOR T0 = XMVectorReplicate((1 - t) * (1 - t) * (1 - t));
|
||||
const XMVECTOR T1 = XMVectorReplicate(3 * t * (1 - t) * (1 - t));
|
||||
const XMVECTOR T2 = XMVectorReplicate(3 * t * t * (1 - t));
|
||||
const XMVECTOR T3 = XMVectorReplicate(t * t * t);
|
||||
|
||||
XMVECTOR Result = XMVectorMultiply(p1, T0);
|
||||
Result = XMVectorMultiplyAdd(p2, T1, Result);
|
||||
|
@ -62,10 +62,10 @@ namespace Bezier
|
|||
{
|
||||
using namespace DirectX;
|
||||
|
||||
XMVECTOR T0 = XMVectorReplicate(-1 + 2 * t - t * t);
|
||||
XMVECTOR T1 = XMVectorReplicate(1 - 4 * t + 3 * t * t);
|
||||
XMVECTOR T2 = XMVectorReplicate(2 * t - 3 * t * t);
|
||||
XMVECTOR T3 = XMVectorReplicate(t * t);
|
||||
const XMVECTOR T0 = XMVectorReplicate(-1 + 2 * t - t * t);
|
||||
const XMVECTOR T1 = XMVectorReplicate(1 - 4 * t + 3 * t * t);
|
||||
const XMVECTOR T2 = XMVectorReplicate(2 * t - 3 * t * t);
|
||||
const XMVECTOR T3 = XMVectorReplicate(t * t);
|
||||
|
||||
XMVECTOR Result = XMVectorMultiply(p1, T0);
|
||||
Result = XMVectorMultiplyAdd(p2, T1, Result);
|
||||
|
@ -80,39 +80,39 @@ namespace Bezier
|
|||
// Calls the specified outputVertex function for each generated vertex,
|
||||
// passing the position, normal, and texture coordinate as parameters.
|
||||
template<typename TOutputFunc>
|
||||
void CreatePatchVertices(_In_reads_(16) DirectX::XMVECTOR patch[16], size_t tessellation, bool isMirrored, TOutputFunc outputVertex)
|
||||
void CreatePatchVertices(_In_reads_(16) const DirectX::XMVECTOR patch[16], size_t tessellation, bool isMirrored, TOutputFunc outputVertex)
|
||||
{
|
||||
using namespace DirectX;
|
||||
|
||||
for (size_t i = 0; i <= tessellation; i++)
|
||||
{
|
||||
float u = float(i) / float(tessellation);
|
||||
const float u = float(i) / float(tessellation);
|
||||
|
||||
for (size_t j = 0; j <= tessellation; j++)
|
||||
{
|
||||
float v = float(j) / float(tessellation);
|
||||
const float v = float(j) / float(tessellation);
|
||||
|
||||
// Perform four horizontal bezier interpolations
|
||||
// between the control points of this patch.
|
||||
XMVECTOR p1 = CubicInterpolate(patch[0], patch[1], patch[2], patch[3], u);
|
||||
XMVECTOR p2 = CubicInterpolate(patch[4], patch[5], patch[6], patch[7], u);
|
||||
XMVECTOR p3 = CubicInterpolate(patch[8], patch[9], patch[10], patch[11], u);
|
||||
XMVECTOR p4 = CubicInterpolate(patch[12], patch[13], patch[14], patch[15], u);
|
||||
const XMVECTOR p1 = CubicInterpolate(patch[0], patch[1], patch[2], patch[3], u);
|
||||
const XMVECTOR p2 = CubicInterpolate(patch[4], patch[5], patch[6], patch[7], u);
|
||||
const XMVECTOR p3 = CubicInterpolate(patch[8], patch[9], patch[10], patch[11], u);
|
||||
const XMVECTOR p4 = CubicInterpolate(patch[12], patch[13], patch[14], patch[15], u);
|
||||
|
||||
// Perform a vertical interpolation between the results of the
|
||||
// previous horizontal interpolations, to compute the position.
|
||||
XMVECTOR position = CubicInterpolate(p1, p2, p3, p4, v);
|
||||
const XMVECTOR position = CubicInterpolate(p1, p2, p3, p4, v);
|
||||
|
||||
// Perform another four bezier interpolations between the control
|
||||
// points, but this time vertically rather than horizontally.
|
||||
XMVECTOR q1 = CubicInterpolate(patch[0], patch[4], patch[8], patch[12], v);
|
||||
XMVECTOR q2 = CubicInterpolate(patch[1], patch[5], patch[9], patch[13], v);
|
||||
XMVECTOR q3 = CubicInterpolate(patch[2], patch[6], patch[10], patch[14], v);
|
||||
XMVECTOR q4 = CubicInterpolate(patch[3], patch[7], patch[11], patch[15], v);
|
||||
const XMVECTOR q1 = CubicInterpolate(patch[0], patch[4], patch[8], patch[12], v);
|
||||
const XMVECTOR q2 = CubicInterpolate(patch[1], patch[5], patch[9], patch[13], v);
|
||||
const XMVECTOR q3 = CubicInterpolate(patch[2], patch[6], patch[10], patch[14], v);
|
||||
const XMVECTOR q4 = CubicInterpolate(patch[3], patch[7], patch[11], patch[15], v);
|
||||
|
||||
// Compute vertical and horizontal tangent vectors.
|
||||
XMVECTOR tangent1 = CubicTangent(p1, p2, p3, p4, v);
|
||||
XMVECTOR tangent2 = CubicTangent(q1, q2, q3, q4, u);
|
||||
const XMVECTOR tangent1 = CubicTangent(p1, p2, p3, p4, v);
|
||||
const XMVECTOR tangent2 = CubicTangent(q1, q2, q3, q4, u);
|
||||
|
||||
// Cross the two tangent vectors to compute the normal.
|
||||
XMVECTOR normal = XMVector3Cross(tangent1, tangent2);
|
||||
|
@ -145,9 +145,9 @@ namespace Bezier
|
|||
}
|
||||
|
||||
// Compute the texture coordinate.
|
||||
float mirroredU = isMirrored ? 1 - u : u;
|
||||
const float mirroredU = isMirrored ? 1 - u : u;
|
||||
|
||||
XMVECTOR textureCoordinate = XMVectorSet(mirroredU, v, 0, 0);
|
||||
const XMVECTOR textureCoordinate = XMVectorSet(mirroredU, v, 0, 0);
|
||||
|
||||
// Output this vertex.
|
||||
outputVertex(position, normal, textureCoordinate);
|
||||
|
|
|
@ -33,7 +33,7 @@ HRESULT DirectX::CreateStaticBuffer(
|
|||
if (!device || !ptr || !count || !stride)
|
||||
return E_INVALIDARG;
|
||||
|
||||
uint64_t sizeInbytes = uint64_t(count) * uint64_t(stride);
|
||||
const uint64_t sizeInbytes = uint64_t(count) * uint64_t(stride);
|
||||
|
||||
static constexpr uint64_t c_maxBytes = D3D11_REQ_RESOURCE_SIZE_IN_MEGABYTES_EXPRESSION_A_TERM * 1024u * 1024u;
|
||||
static_assert(c_maxBytes <= UINT32_MAX, "Exceeded integer limits");
|
||||
|
|
|
@ -386,7 +386,7 @@ namespace
|
|||
{
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
UINT width = header->width;
|
||||
const UINT width = header->width;
|
||||
UINT height = header->height;
|
||||
UINT depth = header->depth;
|
||||
|
||||
|
@ -743,7 +743,7 @@ namespace
|
|||
return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF);
|
||||
}
|
||||
|
||||
UINT res = D3D11CalcSubresource(0, item, mipLevels);
|
||||
const UINT res = D3D11CalcSubresource(0, item, mipLevels);
|
||||
d3dContext->UpdateSubresource(tex, res, nullptr, pSrcBits, static_cast<UINT>(rowBytes), static_cast<UINT>(numBytes));
|
||||
pSrcBits += numBytes;
|
||||
}
|
||||
|
@ -876,7 +876,7 @@ namespace
|
|||
}
|
||||
#else
|
||||
CHAR strFileA[MAX_PATH];
|
||||
int result = WideCharToMultiByte(CP_UTF8,
|
||||
const int result = WideCharToMultiByte(CP_UTF8,
|
||||
WC_NO_BEST_FIT_CHARS,
|
||||
fileName,
|
||||
-1,
|
||||
|
|
|
@ -241,7 +241,7 @@ public:
|
|||
{
|
||||
weightsPerVertex = enableSkinning ? 4 : 0;
|
||||
|
||||
XMMATRIX id = XMMatrixIdentity();
|
||||
const XMMATRIX id = XMMatrixIdentity();
|
||||
world = id;
|
||||
view = id;
|
||||
projection = id;
|
||||
|
@ -376,7 +376,7 @@ void DGSLEffect::Impl::Apply(_In_ ID3D11DeviceContext* deviceContext)
|
|||
constants.object.LocalToWorld4x4 = XMMatrixTranspose(world);
|
||||
constants.object.WorldToView4x4 = XMMatrixTranspose(view);
|
||||
|
||||
XMMATRIX worldView = XMMatrixMultiply(world, view);
|
||||
const XMMATRIX worldView = XMMatrixMultiply(world, view);
|
||||
|
||||
constants.object.LocalToProjected4x4 = XMMatrixTranspose(XMMatrixMultiply(worldView, projection));
|
||||
|
||||
|
@ -386,7 +386,7 @@ void DGSLEffect::Impl::Apply(_In_ ID3D11DeviceContext* deviceContext)
|
|||
|
||||
if (dirtyFlags & EffectDirtyFlags::WorldInverseTranspose)
|
||||
{
|
||||
XMMATRIX worldInverse = XMMatrixInverse(nullptr, world);
|
||||
const XMMATRIX worldInverse = XMMatrixInverse(nullptr, world);
|
||||
|
||||
constants.object.WorldToLocal4x4 = XMMatrixTranspose(worldInverse);
|
||||
|
||||
|
@ -396,7 +396,7 @@ void DGSLEffect::Impl::Apply(_In_ ID3D11DeviceContext* deviceContext)
|
|||
|
||||
if (dirtyFlags & EffectDirtyFlags::EyePosition)
|
||||
{
|
||||
XMMATRIX viewInverse = XMMatrixInverse(nullptr, view);
|
||||
const XMMATRIX viewInverse = XMMatrixInverse(nullptr, view);
|
||||
|
||||
constants.object.EyePosition = viewInverse.r[3];
|
||||
|
||||
|
@ -532,7 +532,7 @@ void DGSLEffect::Impl::GetVertexShaderBytecode(_Out_ void const** pShaderByteCod
|
|||
{
|
||||
assert(pShaderByteCode != nullptr && pByteCodeLength != nullptr);
|
||||
|
||||
int permutation = GetCurrentVSPermutation();
|
||||
const int permutation = GetCurrentVSPermutation();
|
||||
assert(permutation < DGSLEffectTraits::VertexShaderCount);
|
||||
_Analysis_assume_(permutation < DGSLEffectTraits::VertexShaderCount);
|
||||
|
||||
|
|
|
@ -406,7 +406,7 @@ void DGSLEffectFactory::Impl::CreateTexture(const wchar_t* name, ID3D11DeviceCon
|
|||
|
||||
wchar_t ext[_MAX_EXT] = {};
|
||||
_wsplitpath_s(name, nullptr, 0, nullptr, 0, nullptr, 0, ext, _MAX_EXT);
|
||||
bool isdds = _wcsicmp(ext, L".dds") == 0;
|
||||
const bool isdds = _wcsicmp(ext, L".dds") == 0;
|
||||
|
||||
if (isdds)
|
||||
{
|
||||
|
|
|
@ -279,7 +279,7 @@ void DebugEffect::Impl::Apply(_In_ ID3D11DeviceContext* deviceContext)
|
|||
{
|
||||
constants.world = XMMatrixTranspose(matrices.world);
|
||||
|
||||
XMMATRIX worldInverse = XMMatrixInverse(nullptr, matrices.world);
|
||||
const XMMATRIX worldInverse = XMMatrixInverse(nullptr, matrices.world);
|
||||
|
||||
constants.worldInverseTranspose[0] = worldInverse.r[0];
|
||||
constants.worldInverseTranspose[1] = worldInverse.r[1];
|
||||
|
|
|
@ -128,7 +128,7 @@ class DualPostProcess::Impl : public AlignedNew<PostProcessConstants>
|
|||
public:
|
||||
explicit Impl(_In_ ID3D11Device* device);
|
||||
|
||||
void Process(_In_ ID3D11DeviceContext* deviceContext, std::function<void __cdecl()>& setCustomState);
|
||||
void Process(_In_ ID3D11DeviceContext* deviceContext, const std::function<void __cdecl()>& setCustomState);
|
||||
|
||||
void SetDirtyFlag() noexcept { mDirtyFlags = INT_MAX; }
|
||||
|
||||
|
@ -186,7 +186,7 @@ DualPostProcess::Impl::Impl(_In_ ID3D11Device* device)
|
|||
// Sets our state onto the D3D device.
|
||||
void DualPostProcess::Impl::Process(
|
||||
_In_ ID3D11DeviceContext* deviceContext,
|
||||
std::function<void __cdecl()>& setCustomState)
|
||||
const std::function<void __cdecl()>& setCustomState)
|
||||
{
|
||||
// Set the texture.
|
||||
ID3D11ShaderResourceView* textures[2] = { texture.Get(), texture2.Get() };
|
||||
|
|
|
@ -27,7 +27,7 @@ void XM_CALLCONV IEffectMatrices::SetMatrices(FXMMATRIX world, CXMMATRIX view, C
|
|||
// Constructor initializes default matrix values.
|
||||
EffectMatrices::EffectMatrices() noexcept
|
||||
{
|
||||
XMMATRIX id = XMMatrixIdentity();
|
||||
const XMMATRIX id = XMMatrixIdentity();
|
||||
world = id;
|
||||
view = id;
|
||||
projection = id;
|
||||
|
@ -83,11 +83,12 @@ void XM_CALLCONV EffectFog::SetConstants(int& dirtyFlags, FXMMATRIX worldView, X
|
|||
// with a single dot product, using only the Z row of the world+view matrix.
|
||||
|
||||
// _13, _23, _33, _43
|
||||
XMVECTOR worldViewZ = XMVectorMergeXY(XMVectorMergeZW(worldView.r[0], worldView.r[2]),
|
||||
XMVectorMergeZW(worldView.r[1], worldView.r[3]));
|
||||
const XMVECTOR worldViewZ = XMVectorMergeXY(
|
||||
XMVectorMergeZW(worldView.r[0], worldView.r[2]),
|
||||
XMVectorMergeZW(worldView.r[1], worldView.r[3]));
|
||||
|
||||
// 0, 0, 0, fogStart
|
||||
XMVECTOR wOffset = XMVectorSwizzle<1, 2, 3, 0>(XMLoadFloat(&start));
|
||||
const XMVECTOR wOffset = XMVectorSwizzle<1, 2, 3, 0>(XMLoadFloat(&start));
|
||||
|
||||
// (worldViewZ + wOffset) / (start - end);
|
||||
fogVectorConstant = XMVectorDivide(XMVectorAdd(worldViewZ, wOffset), XMVectorReplicate(start - end));
|
||||
|
@ -124,7 +125,7 @@ void EffectColor::SetConstants(_Inout_ int& dirtyFlags, _Inout_ XMVECTOR& diffus
|
|||
{
|
||||
if (dirtyFlags & EffectDirtyFlags::MaterialColor)
|
||||
{
|
||||
XMVECTOR alphaVector = XMVectorReplicate(alpha);
|
||||
const XMVECTOR alphaVector = XMVectorReplicate(alpha);
|
||||
|
||||
// xyz = diffuse * alpha, w = alpha.
|
||||
diffuseColorConstant = XMVectorSelect(alphaVector, XMVectorMultiply(diffuseColor, alphaVector), g_XMSelect1110);
|
||||
|
@ -188,7 +189,7 @@ _Use_decl_annotations_ void EffectLights::SetConstants(int& dirtyFlags, EffectMa
|
|||
{
|
||||
worldConstant = XMMatrixTranspose(matrices.world);
|
||||
|
||||
XMMATRIX worldInverse = XMMatrixInverse(nullptr, matrices.world);
|
||||
const XMMATRIX worldInverse = XMMatrixInverse(nullptr, matrices.world);
|
||||
|
||||
worldInverseTransposeConstant[0] = worldInverse.r[0];
|
||||
worldInverseTransposeConstant[1] = worldInverse.r[1];
|
||||
|
@ -234,7 +235,7 @@ _Use_decl_annotations_ void EffectLights::SetConstants(int& dirtyFlags, EffectMa
|
|||
if (dirtyFlags & EffectDirtyFlags::MaterialColor)
|
||||
{
|
||||
XMVECTOR diffuse = diffuseColor;
|
||||
XMVECTOR alphaVector = XMVectorReplicate(alpha);
|
||||
const XMVECTOR alphaVector = XMVectorReplicate(alpha);
|
||||
|
||||
if (lightingEnabled)
|
||||
{
|
||||
|
|
|
@ -181,7 +181,7 @@ namespace DirectX
|
|||
assert(pShaderByteCode != nullptr && pByteCodeLength != nullptr);
|
||||
assert(permutation >= 0 && permutation < Traits::ShaderPermutationCount);
|
||||
_Analysis_assume_(permutation >= 0 && permutation < Traits::ShaderPermutationCount);
|
||||
int shaderIndex = VertexShaderIndices[permutation];
|
||||
const int shaderIndex = VertexShaderIndices[permutation];
|
||||
assert(shaderIndex >= 0 && shaderIndex < Traits::VertexShaderCount);
|
||||
_Analysis_assume_(shaderIndex >= 0 && shaderIndex < Traits::VertexShaderCount);
|
||||
|
||||
|
|
|
@ -226,7 +226,7 @@ std::shared_ptr<IEffect> EffectFactory::Impl::CreateEffect(IEffectFactory* facto
|
|||
effect->SetVertexColorEnabled(true);
|
||||
}
|
||||
|
||||
XMVECTOR color = XMLoadFloat3(&info.diffuseColor);
|
||||
const XMVECTOR color = XMLoadFloat3(&info.diffuseColor);
|
||||
effect->SetDiffuseColor(color);
|
||||
|
||||
if (info.diffuseTexture && *info.diffuseTexture)
|
||||
|
@ -404,7 +404,7 @@ void EffectFactory::Impl::CreateTexture(const wchar_t* name, ID3D11DeviceContext
|
|||
|
||||
wchar_t ext[_MAX_EXT] = {};
|
||||
_wsplitpath_s(name, nullptr, 0, nullptr, 0, nullptr, 0, ext, _MAX_EXT);
|
||||
bool isdds = _wcsicmp(ext, L".dds") == 0;
|
||||
const bool isdds = _wcsicmp(ext, L".dds") == 0;
|
||||
|
||||
if (isdds)
|
||||
{
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace
|
|||
}
|
||||
|
||||
// Scale into 0-1 range.
|
||||
float scaledValue = value / (maxValue - deadZoneSize);
|
||||
const float scaledValue = value / (maxValue - deadZoneSize);
|
||||
return std::max(-1.f, std::min(scaledValue, 1.f));
|
||||
}
|
||||
|
||||
|
@ -62,10 +62,10 @@ namespace
|
|||
|
||||
case GamePad::DEAD_ZONE_CIRCULAR:
|
||||
{
|
||||
float dist = sqrtf(x*x + y * y);
|
||||
float wanted = ApplyLinearDeadZone(dist, maxValue, deadZoneSize);
|
||||
const float dist = sqrtf(x*x + y * y);
|
||||
const float wanted = ApplyLinearDeadZone(dist, maxValue, deadZoneSize);
|
||||
|
||||
float scale = (wanted > 0.f) ? (wanted / dist) : 0.f;
|
||||
const float scale = (wanted > 0.f) ? (wanted / dist) : 0.f;
|
||||
|
||||
resultX = std::max(-1.f, std::min(x * scale, 1.f));
|
||||
resultY = std::max(-1.f, std::min(y * scale, 1.f));
|
||||
|
@ -1273,7 +1273,7 @@ public:
|
|||
if (player == c_MostRecent)
|
||||
player = GetMostRecent();
|
||||
|
||||
ULONGLONG time = GetTickCount64();
|
||||
const ULONGLONG time = GetTickCount64();
|
||||
|
||||
if (!ThrottleRetry(player, time))
|
||||
{
|
||||
|
@ -1287,7 +1287,7 @@ public:
|
|||
#endif
|
||||
|
||||
XINPUT_STATE xstate;
|
||||
DWORD result = XInputGetState(DWORD(player), &xstate);
|
||||
const DWORD result = XInputGetState(DWORD(player), &xstate);
|
||||
if (result == ERROR_DEVICE_NOT_CONNECTED)
|
||||
{
|
||||
ClearSlot(player, time);
|
||||
|
@ -1302,7 +1302,7 @@ public:
|
|||
state.connected = true;
|
||||
state.packet = xstate.dwPacketNumber;
|
||||
|
||||
WORD xbuttons = xstate.Gamepad.wButtons;
|
||||
const WORD xbuttons = xstate.Gamepad.wButtons;
|
||||
state.buttons.a = (xbuttons & XINPUT_GAMEPAD_A) != 0;
|
||||
state.buttons.b = (xbuttons & XINPUT_GAMEPAD_B) != 0;
|
||||
state.buttons.x = (xbuttons & XINPUT_GAMEPAD_X) != 0;
|
||||
|
@ -1350,12 +1350,12 @@ public:
|
|||
if (player == c_MostRecent)
|
||||
player = GetMostRecent();
|
||||
|
||||
ULONGLONG time = GetTickCount64();
|
||||
const ULONGLONG time = GetTickCount64();
|
||||
|
||||
if (!ThrottleRetry(player, time))
|
||||
{
|
||||
XINPUT_CAPABILITIES xcaps;
|
||||
DWORD result = XInputGetCapabilities(DWORD(player), 0, &xcaps);
|
||||
const DWORD result = XInputGetCapabilities(DWORD(player), 0, &xcaps);
|
||||
if (result == ERROR_DEVICE_NOT_CONNECTED)
|
||||
{
|
||||
ClearSlot(player, time);
|
||||
|
@ -1407,7 +1407,7 @@ public:
|
|||
if (player == c_MostRecent)
|
||||
player = GetMostRecent();
|
||||
|
||||
ULONGLONG time = GetTickCount64();
|
||||
const ULONGLONG time = GetTickCount64();
|
||||
|
||||
if (ThrottleRetry(player, time))
|
||||
{
|
||||
|
@ -1430,7 +1430,7 @@ public:
|
|||
XINPUT_VIBRATION xvibration;
|
||||
xvibration.wLeftMotorSpeed = WORD(leftMotor * 0xFFFF);
|
||||
xvibration.wRightMotorSpeed = WORD(rightMotor * 0xFFFF);
|
||||
DWORD result = XInputSetState(DWORD(player), &xvibration);
|
||||
const DWORD result = XInputSetState(DWORD(player), &xvibration);
|
||||
if (result == ERROR_DEVICE_NOT_CONNECTED)
|
||||
{
|
||||
ClearSlot(player, time);
|
||||
|
@ -1481,7 +1481,7 @@ public:
|
|||
// For XInput 9.1.0, we have to emulate the behavior of XInputEnable( TRUE )
|
||||
if (mSuspended)
|
||||
{
|
||||
ULONGLONG time = GetTickCount64();
|
||||
const ULONGLONG time = GetTickCount64();
|
||||
|
||||
for (int j = 0; j < XUSER_MAX_COUNT; ++j)
|
||||
{
|
||||
|
@ -1490,7 +1490,7 @@ public:
|
|||
XINPUT_VIBRATION xvibration;
|
||||
xvibration.wLeftMotorSpeed = WORD(mLeftMotor[j] * 0xFFFF);
|
||||
xvibration.wRightMotorSpeed = WORD(mRightMotor[j] * 0xFFFF);
|
||||
DWORD result = XInputSetState(DWORD(j), &xvibration);
|
||||
const DWORD result = XInputSetState(DWORD(j), &xvibration);
|
||||
if (result == ERROR_DEVICE_NOT_CONNECTED)
|
||||
{
|
||||
ClearSlot(j, time);
|
||||
|
@ -1534,7 +1534,7 @@ private:
|
|||
{
|
||||
if (!mConnected[j])
|
||||
{
|
||||
LONGLONG delta = LONGLONG(time) - LONGLONG(mLastReadTime[j]);
|
||||
const LONGLONG delta = LONGLONG(time) - LONGLONG(mLastReadTime[j]);
|
||||
|
||||
LONGLONG interval = 1000;
|
||||
if (j != player)
|
||||
|
|
|
@ -32,19 +32,19 @@ public:
|
|||
FXMVECTOR color,
|
||||
_In_opt_ ID3D11ShaderResourceView* texture,
|
||||
bool wireframe,
|
||||
std::function<void()>& setCustomState) const;
|
||||
const std::function<void()>& setCustomState) const;
|
||||
|
||||
void Draw(_In_ IEffect* effect,
|
||||
_In_ ID3D11InputLayout* inputLayout,
|
||||
bool alpha, bool wireframe,
|
||||
std::function<void()>& setCustomState) const;
|
||||
const std::function<void()>& setCustomState) const;
|
||||
|
||||
void DrawInstanced(_In_ IEffect* effect,
|
||||
_In_ ID3D11InputLayout* inputLayout,
|
||||
uint32_t instanceCount,
|
||||
bool alpha, bool wireframe,
|
||||
uint32_t startInstanceLocation,
|
||||
std::function<void()>& setCustomState) const;
|
||||
const std::function<void()>& setCustomState) const;
|
||||
|
||||
void CreateInputLayout(_In_ IEffect* effect, _Outptr_ ID3D11InputLayout** inputLayout) const;
|
||||
|
||||
|
@ -189,7 +189,7 @@ void XM_CALLCONV GeometricPrimitive::Impl::Draw(
|
|||
FXMVECTOR color,
|
||||
ID3D11ShaderResourceView* texture,
|
||||
bool wireframe,
|
||||
std::function<void()>& setCustomState) const
|
||||
const std::function<void()>& setCustomState) const
|
||||
{
|
||||
assert(mResources);
|
||||
auto effect = mResources->effect.get();
|
||||
|
@ -215,7 +215,7 @@ void XM_CALLCONV GeometricPrimitive::Impl::Draw(
|
|||
|
||||
effect->SetColorAndAlpha(color);
|
||||
|
||||
float alpha = XMVectorGetW(color);
|
||||
const float alpha = XMVectorGetW(color);
|
||||
Draw(effect, inputLayout, (alpha < 1.f), wireframe, setCustomState);
|
||||
}
|
||||
|
||||
|
@ -227,7 +227,7 @@ void GeometricPrimitive::Impl::Draw(
|
|||
ID3D11InputLayout* inputLayout,
|
||||
bool alpha,
|
||||
bool wireframe,
|
||||
std::function<void()>& setCustomState) const
|
||||
const std::function<void()>& setCustomState) const
|
||||
{
|
||||
assert(mResources);
|
||||
auto deviceContext = mResources->mDeviceContext.Get();
|
||||
|
@ -246,8 +246,8 @@ void GeometricPrimitive::Impl::Draw(
|
|||
|
||||
// Set the vertex and index buffer.
|
||||
auto vertexBuffer = mVertexBuffer.Get();
|
||||
UINT vertexStride = sizeof(VertexType);
|
||||
UINT vertexOffset = 0;
|
||||
constexpr UINT vertexStride = sizeof(VertexType);
|
||||
constexpr UINT vertexOffset = 0;
|
||||
|
||||
deviceContext->IASetVertexBuffers(0, 1, &vertexBuffer, &vertexStride, &vertexOffset);
|
||||
|
||||
|
@ -273,7 +273,7 @@ void GeometricPrimitive::Impl::DrawInstanced(
|
|||
bool alpha,
|
||||
bool wireframe,
|
||||
uint32_t startInstanceLocation,
|
||||
std::function<void()>& setCustomState) const
|
||||
const std::function<void()>& setCustomState) const
|
||||
{
|
||||
assert(mResources);
|
||||
auto deviceContext = mResources->mDeviceContext.Get();
|
||||
|
@ -292,8 +292,8 @@ void GeometricPrimitive::Impl::DrawInstanced(
|
|||
|
||||
// Set the vertex and index buffer.
|
||||
auto vertexBuffer = mVertexBuffer.Get();
|
||||
UINT vertexStride = sizeof(VertexType);
|
||||
UINT vertexOffset = 0;
|
||||
constexpr UINT vertexStride = sizeof(VertexType);
|
||||
constexpr UINT vertexOffset = 0;
|
||||
|
||||
deviceContext->IASetVertexBuffers(0, 1, &vertexBuffer, &vertexStride, &vertexOffset);
|
||||
|
||||
|
@ -821,7 +821,7 @@ std::unique_ptr<GeometricPrimitive> GeometricPrimitive::CreateCustom(
|
|||
if (indices.size() % 3)
|
||||
throw std::invalid_argument("Expected triangular faces");
|
||||
|
||||
size_t nVerts = vertices.size();
|
||||
const size_t nVerts = vertices.size();
|
||||
if (nVerts >= USHRT_MAX)
|
||||
throw std::out_of_range("Too many vertices for 16-bit index buffer");
|
||||
|
||||
|
|
174
Src/Geometry.cpp
174
Src/Geometry.cpp
|
@ -100,16 +100,16 @@ void DirectX::ComputeBox(VertexCollection& vertices, IndexCollection& indices, c
|
|||
// Create each face in turn.
|
||||
for (int i = 0; i < FaceCount; i++)
|
||||
{
|
||||
XMVECTOR normal = faceNormals[i];
|
||||
const XMVECTOR normal = faceNormals[i];
|
||||
|
||||
// Get two vectors perpendicular both to the face normal and to each other.
|
||||
XMVECTOR basis = (i >= 4) ? g_XMIdentityR2 : g_XMIdentityR1;
|
||||
const XMVECTOR basis = (i >= 4) ? g_XMIdentityR2 : g_XMIdentityR1;
|
||||
|
||||
XMVECTOR side1 = XMVector3Cross(normal, basis);
|
||||
XMVECTOR side2 = XMVector3Cross(normal, side1);
|
||||
const XMVECTOR side1 = XMVector3Cross(normal, basis);
|
||||
const XMVECTOR side2 = XMVector3Cross(normal, side1);
|
||||
|
||||
// Six indices (two triangles) per face.
|
||||
size_t vbase = vertices.size();
|
||||
const size_t vbase = vertices.size();
|
||||
index_push_back(indices, vbase + 0);
|
||||
index_push_back(indices, vbase + 1);
|
||||
index_push_back(indices, vbase + 2);
|
||||
|
@ -152,17 +152,17 @@ void DirectX::ComputeSphere(VertexCollection& vertices, IndexCollection& indices
|
|||
if (tessellation < 3)
|
||||
throw std::invalid_argument("tesselation parameter must be at least 3");
|
||||
|
||||
size_t verticalSegments = tessellation;
|
||||
size_t horizontalSegments = tessellation * 2;
|
||||
const size_t verticalSegments = tessellation;
|
||||
const size_t horizontalSegments = tessellation * 2;
|
||||
|
||||
float radius = diameter / 2;
|
||||
const float radius = diameter / 2;
|
||||
|
||||
// Create rings of vertices at progressively higher latitudes.
|
||||
for (size_t i = 0; i <= verticalSegments; i++)
|
||||
{
|
||||
float v = 1 - float(i) / float(verticalSegments);
|
||||
const float v = 1 - float(i) / float(verticalSegments);
|
||||
|
||||
float latitude = (float(i) * XM_PI / float(verticalSegments)) - XM_PIDIV2;
|
||||
const float latitude = (float(i) * XM_PI / float(verticalSegments)) - XM_PIDIV2;
|
||||
float dy, dxz;
|
||||
|
||||
XMScalarSinCos(&dy, &dxz, latitude);
|
||||
|
@ -170,9 +170,9 @@ void DirectX::ComputeSphere(VertexCollection& vertices, IndexCollection& indices
|
|||
// Create a single ring of vertices at this latitude.
|
||||
for (size_t j = 0; j <= horizontalSegments; j++)
|
||||
{
|
||||
float u = float(j) / float(horizontalSegments);
|
||||
const float u = float(j) / float(horizontalSegments);
|
||||
|
||||
float longitude = float(j) * XM_2PI / float(horizontalSegments);
|
||||
const float longitude = float(j) * XM_2PI / float(horizontalSegments);
|
||||
float dx, dz;
|
||||
|
||||
XMScalarSinCos(&dx, &dz, longitude);
|
||||
|
@ -180,22 +180,22 @@ void DirectX::ComputeSphere(VertexCollection& vertices, IndexCollection& indices
|
|||
dx *= dxz;
|
||||
dz *= dxz;
|
||||
|
||||
XMVECTOR normal = XMVectorSet(dx, dy, dz, 0);
|
||||
XMVECTOR textureCoordinate = XMVectorSet(u, v, 0, 0);
|
||||
const XMVECTOR normal = XMVectorSet(dx, dy, dz, 0);
|
||||
const XMVECTOR textureCoordinate = XMVectorSet(u, v, 0, 0);
|
||||
|
||||
vertices.push_back(VertexPositionNormalTexture(XMVectorScale(normal, radius), normal, textureCoordinate));
|
||||
}
|
||||
}
|
||||
|
||||
// Fill the index buffer with triangles joining each pair of latitude rings.
|
||||
size_t stride = horizontalSegments + 1;
|
||||
const size_t stride = horizontalSegments + 1;
|
||||
|
||||
for (size_t i = 0; i < verticalSegments; i++)
|
||||
{
|
||||
for (size_t j = 0; j <= horizontalSegments; j++)
|
||||
{
|
||||
size_t nextI = i + 1;
|
||||
size_t nextJ = (j + 1) % stride;
|
||||
const size_t nextI = i + 1;
|
||||
const size_t nextJ = (j + 1) % stride;
|
||||
|
||||
index_push_back(indices, i * stride + j);
|
||||
index_push_back(indices, nextI * stride + j);
|
||||
|
@ -274,8 +274,8 @@ void DirectX::ComputeGeoSphere(VertexCollection& vertices, IndexCollection& indi
|
|||
// We know these values by looking at the above index list for the octahedron. Despite the subdivisions that are
|
||||
// about to go on, these values aren't ever going to change because the vertices don't move around in the array.
|
||||
// We'll need these values later on to fix the singularities that show up at the poles.
|
||||
const uint16_t northPoleIndex = 0;
|
||||
const uint16_t southPoleIndex = 5;
|
||||
constexpr uint16_t northPoleIndex = 0;
|
||||
constexpr uint16_t southPoleIndex = 5;
|
||||
|
||||
for (size_t iSubdivision = 0; iSubdivision < tessellation; ++iSubdivision)
|
||||
{
|
||||
|
@ -294,9 +294,9 @@ void DirectX::ComputeGeoSphere(VertexCollection& vertices, IndexCollection& indi
|
|||
// The winding order of the triangles we output are the same as the winding order of the inputs.
|
||||
|
||||
// Indices of the vertices making up this triangle
|
||||
uint16_t iv0 = indices[iTriangle * 3 + 0];
|
||||
uint16_t iv1 = indices[iTriangle * 3 + 1];
|
||||
uint16_t iv2 = indices[iTriangle * 3 + 2];
|
||||
const uint16_t iv0 = indices[iTriangle * 3 + 0];
|
||||
const uint16_t iv1 = indices[iTriangle * 3 + 1];
|
||||
const uint16_t iv2 = indices[iTriangle * 3 + 2];
|
||||
|
||||
// Get the new vertices
|
||||
XMFLOAT3 v01; // vertex on the midpoint of v0 and v1
|
||||
|
@ -307,7 +307,7 @@ void DirectX::ComputeGeoSphere(VertexCollection& vertices, IndexCollection& indi
|
|||
uint16_t iv20; // index of v20
|
||||
|
||||
// Function that, when given the index of two vertices, creates a new vertex at the midpoint of those vertices.
|
||||
auto divideEdge = [&](uint16_t i0, uint16_t i1, XMFLOAT3& outVertex, uint16_t& outIndex)
|
||||
auto const divideEdge = [&](uint16_t i0, uint16_t i1, XMFLOAT3& outVertex, uint16_t& outIndex)
|
||||
{
|
||||
const UndirectedEdge edge = makeUndirectedEdge(i0, i1);
|
||||
|
||||
|
@ -372,20 +372,20 @@ void DirectX::ComputeGeoSphere(VertexCollection& vertices, IndexCollection& indi
|
|||
vertices.reserve(vertexPositions.size());
|
||||
for (const auto& it : vertexPositions)
|
||||
{
|
||||
auto normal = XMVector3Normalize(XMLoadFloat3(&it));
|
||||
auto pos = XMVectorScale(normal, radius);
|
||||
auto const normal = XMVector3Normalize(XMLoadFloat3(&it));
|
||||
auto const pos = XMVectorScale(normal, radius);
|
||||
|
||||
XMFLOAT3 normalFloat3;
|
||||
XMStoreFloat3(&normalFloat3, normal);
|
||||
|
||||
// calculate texture coordinates for this vertex
|
||||
float longitude = atan2f(normalFloat3.x, -normalFloat3.z);
|
||||
float latitude = acosf(normalFloat3.y);
|
||||
const float longitude = atan2f(normalFloat3.x, -normalFloat3.z);
|
||||
const float latitude = acosf(normalFloat3.y);
|
||||
|
||||
float u = longitude / XM_2PI + 0.5f;
|
||||
float v = latitude / XM_PI;
|
||||
const float u = longitude / XM_2PI + 0.5f;
|
||||
const float v = latitude / XM_PI;
|
||||
|
||||
auto texcoord = XMVectorSet(1.0f - u, v, 0.0f, 0.0f);
|
||||
auto const texcoord = XMVectorSet(1.0f - u, v, 0.0f, 0.0f);
|
||||
vertices.push_back(VertexPositionNormalTexture(pos, normal, texcoord));
|
||||
}
|
||||
|
||||
|
@ -399,11 +399,11 @@ void DirectX::ComputeGeoSphere(VertexCollection& vertices, IndexCollection& indi
|
|||
// completed sphere. If you imagine the vertices along that edge, they circumscribe a semicircular arc starting at
|
||||
// y=1 and ending at y=-1, and sweeping across the range of z=0 to z=1. x stays zero. It's along this edge that we
|
||||
// need to duplicate our vertices - and provide the correct texture coordinates.
|
||||
size_t preFixupVertexCount = vertices.size();
|
||||
const size_t preFixupVertexCount = vertices.size();
|
||||
for (size_t i = 0; i < preFixupVertexCount; ++i)
|
||||
{
|
||||
// This vertex is on the prime meridian if position.x and texcoord.u are both zero (allowing for small epsilon).
|
||||
bool isOnPrimeMeridian = XMVector2NearEqual(
|
||||
const bool isOnPrimeMeridian = XMVector2NearEqual(
|
||||
XMVectorSet(vertices[i].position.x, vertices[i].textureCoordinate.x, 0.0f, 0.0f),
|
||||
XMVectorZero(),
|
||||
XMVectorSplatEpsilon());
|
||||
|
@ -468,7 +468,7 @@ void DirectX::ComputeGeoSphere(VertexCollection& vertices, IndexCollection& indi
|
|||
// onto a single point. In general there's no real way to do that right. But to match the behavior of non-geodesic
|
||||
// spheres, we need to duplicate the pole vertex for every triangle that uses it. This will introduce seams near the
|
||||
// poles, but reduce stretching.
|
||||
auto fixPole = [&](size_t poleIndex)
|
||||
auto const fixPole = [&](size_t poleIndex)
|
||||
{
|
||||
const auto& poleVertex = vertices[poleIndex];
|
||||
bool overwrittenPoleVertex = false; // overwriting the original pole vertex saves us one vertex
|
||||
|
@ -544,23 +544,23 @@ namespace
|
|||
// Helper computes a point on a unit circle, aligned to the x/z plane and centered on the origin.
|
||||
inline XMVECTOR GetCircleVector(size_t i, size_t tessellation) noexcept
|
||||
{
|
||||
float angle = float(i) * XM_2PI / float(tessellation);
|
||||
const float angle = float(i) * XM_2PI / float(tessellation);
|
||||
float dx, dz;
|
||||
|
||||
XMScalarSinCos(&dx, &dz, angle);
|
||||
|
||||
XMVECTORF32 v = { { { dx, 0, dz, 0 } } };
|
||||
const XMVECTORF32 v = { { { dx, 0, dz, 0 } } };
|
||||
return v;
|
||||
}
|
||||
|
||||
inline XMVECTOR GetCircleTangent(size_t i, size_t tessellation) noexcept
|
||||
{
|
||||
float angle = (float(i) * XM_2PI / float(tessellation)) + XM_PIDIV2;
|
||||
const float angle = (float(i) * XM_2PI / float(tessellation)) + XM_PIDIV2;
|
||||
float dx, dz;
|
||||
|
||||
XMScalarSinCos(&dx, &dz, angle);
|
||||
|
||||
XMVECTORF32 v = { { { dx, 0, dz, 0 } } };
|
||||
const XMVECTORF32 v = { { { dx, 0, dz, 0 } } };
|
||||
return v;
|
||||
}
|
||||
|
||||
|
@ -579,7 +579,7 @@ namespace
|
|||
std::swap(i1, i2);
|
||||
}
|
||||
|
||||
size_t vbase = vertices.size();
|
||||
const size_t vbase = vertices.size();
|
||||
index_push_back(indices, vbase);
|
||||
index_push_back(indices, vbase + i1);
|
||||
index_push_back(indices, vbase + i2);
|
||||
|
@ -598,11 +598,11 @@ namespace
|
|||
// Create cap vertices.
|
||||
for (size_t i = 0; i < tessellation; i++)
|
||||
{
|
||||
XMVECTOR circleVector = GetCircleVector(i, tessellation);
|
||||
const XMVECTOR circleVector = GetCircleVector(i, tessellation);
|
||||
|
||||
XMVECTOR position = XMVectorAdd(XMVectorScale(circleVector, radius), XMVectorScale(normal, height));
|
||||
const XMVECTOR position = XMVectorAdd(XMVectorScale(circleVector, radius), XMVectorScale(normal, height));
|
||||
|
||||
XMVECTOR textureCoordinate = XMVectorMultiplyAdd(XMVectorSwizzle<0, 2, 3, 3>(circleVector), textureScale, g_XMOneHalf);
|
||||
const XMVECTOR textureCoordinate = XMVectorMultiplyAdd(XMVectorSwizzle<0, 2, 3, 3>(circleVector), textureScale, g_XMOneHalf);
|
||||
|
||||
vertices.push_back(VertexPositionNormalTexture(position, normal, textureCoordinate));
|
||||
}
|
||||
|
@ -619,21 +619,21 @@ void DirectX::ComputeCylinder(VertexCollection& vertices, IndexCollection& indic
|
|||
|
||||
height /= 2;
|
||||
|
||||
XMVECTOR topOffset = XMVectorScale(g_XMIdentityR1, height);
|
||||
const XMVECTOR topOffset = XMVectorScale(g_XMIdentityR1, height);
|
||||
|
||||
float radius = diameter / 2;
|
||||
size_t stride = tessellation + 1;
|
||||
const float radius = diameter / 2;
|
||||
const size_t stride = tessellation + 1;
|
||||
|
||||
// Create a ring of triangles around the outside of the cylinder.
|
||||
for (size_t i = 0; i <= tessellation; i++)
|
||||
{
|
||||
XMVECTOR normal = GetCircleVector(i, tessellation);
|
||||
const XMVECTOR normal = GetCircleVector(i, tessellation);
|
||||
|
||||
XMVECTOR sideOffset = XMVectorScale(normal, radius);
|
||||
const XMVECTOR sideOffset = XMVectorScale(normal, radius);
|
||||
|
||||
float u = float(i) / float(tessellation);
|
||||
const float u = float(i) / float(tessellation);
|
||||
|
||||
XMVECTOR textureCoordinate = XMLoadFloat(&u);
|
||||
const XMVECTOR textureCoordinate = XMLoadFloat(&u);
|
||||
|
||||
vertices.push_back(VertexPositionNormalTexture(XMVectorAdd(sideOffset, topOffset), normal, textureCoordinate));
|
||||
vertices.push_back(VertexPositionNormalTexture(XMVectorSubtract(sideOffset, topOffset), normal, XMVectorAdd(textureCoordinate, g_XMIdentityR1)));
|
||||
|
@ -668,23 +668,23 @@ void DirectX::ComputeCone(VertexCollection& vertices, IndexCollection& indices,
|
|||
|
||||
height /= 2;
|
||||
|
||||
XMVECTOR topOffset = XMVectorScale(g_XMIdentityR1, height);
|
||||
const XMVECTOR topOffset = XMVectorScale(g_XMIdentityR1, height);
|
||||
|
||||
float radius = diameter / 2;
|
||||
size_t stride = tessellation + 1;
|
||||
const float radius = diameter / 2;
|
||||
const size_t stride = tessellation + 1;
|
||||
|
||||
// Create a ring of triangles around the outside of the cone.
|
||||
for (size_t i = 0; i <= tessellation; i++)
|
||||
{
|
||||
XMVECTOR circlevec = GetCircleVector(i, tessellation);
|
||||
const XMVECTOR circlevec = GetCircleVector(i, tessellation);
|
||||
|
||||
XMVECTOR sideOffset = XMVectorScale(circlevec, radius);
|
||||
const XMVECTOR sideOffset = XMVectorScale(circlevec, radius);
|
||||
|
||||
float u = float(i) / float(tessellation);
|
||||
const float u = float(i) / float(tessellation);
|
||||
|
||||
XMVECTOR textureCoordinate = XMLoadFloat(&u);
|
||||
const XMVECTOR textureCoordinate = XMLoadFloat(&u);
|
||||
|
||||
XMVECTOR pt = XMVectorSubtract(sideOffset, topOffset);
|
||||
const XMVECTOR pt = XMVectorSubtract(sideOffset, topOffset);
|
||||
|
||||
XMVECTOR normal = XMVector3Cross(
|
||||
GetCircleTangent(i, tessellation),
|
||||
|
@ -720,25 +720,25 @@ void DirectX::ComputeTorus(VertexCollection& vertices, IndexCollection& indices,
|
|||
if (tessellation < 3)
|
||||
throw std::invalid_argument("tesselation parameter must be at least 3");
|
||||
|
||||
size_t stride = tessellation + 1;
|
||||
const size_t stride = tessellation + 1;
|
||||
|
||||
// First we loop around the main ring of the torus.
|
||||
for (size_t i = 0; i <= tessellation; i++)
|
||||
{
|
||||
float u = float(i) / float(tessellation);
|
||||
const float u = float(i) / float(tessellation);
|
||||
|
||||
float outerAngle = float(i) * XM_2PI / float(tessellation) - XM_PIDIV2;
|
||||
const float outerAngle = float(i) * XM_2PI / float(tessellation) - XM_PIDIV2;
|
||||
|
||||
// Create a transform matrix that will align geometry to
|
||||
// slice perpendicularly though the current ring position.
|
||||
XMMATRIX transform = XMMatrixTranslation(diameter / 2, 0, 0) * XMMatrixRotationY(outerAngle);
|
||||
const XMMATRIX transform = XMMatrixTranslation(diameter / 2, 0, 0) * XMMatrixRotationY(outerAngle);
|
||||
|
||||
// Now we loop along the other axis, around the side of the tube.
|
||||
for (size_t j = 0; j <= tessellation; j++)
|
||||
{
|
||||
float v = 1 - float(j) / float(tessellation);
|
||||
const float v = 1 - float(j) / float(tessellation);
|
||||
|
||||
float innerAngle = float(j) * XM_2PI / float(tessellation) + XM_PI;
|
||||
const float innerAngle = float(j) * XM_2PI / float(tessellation) + XM_PI;
|
||||
float dx, dy;
|
||||
|
||||
XMScalarSinCos(&dy, &dx, innerAngle);
|
||||
|
@ -746,7 +746,7 @@ void DirectX::ComputeTorus(VertexCollection& vertices, IndexCollection& indices,
|
|||
// Create a vertex.
|
||||
XMVECTOR normal = XMVectorSet(dx, dy, 0, 0);
|
||||
XMVECTOR position = XMVectorScale(normal, thickness / 2);
|
||||
XMVECTOR textureCoordinate = XMVectorSet(u, v, 0, 0);
|
||||
const XMVECTOR textureCoordinate = XMVectorSet(u, v, 0, 0);
|
||||
|
||||
position = XMVector3Transform(position, transform);
|
||||
normal = XMVector3TransformNormal(normal, transform);
|
||||
|
@ -754,8 +754,8 @@ void DirectX::ComputeTorus(VertexCollection& vertices, IndexCollection& indices,
|
|||
vertices.push_back(VertexPositionNormalTexture(position, normal, textureCoordinate));
|
||||
|
||||
// And create indices for two triangles.
|
||||
size_t nextI = (i + 1) % stride;
|
||||
size_t nextJ = (j + 1) % stride;
|
||||
const size_t nextI = (i + 1) % stride;
|
||||
const size_t nextJ = (j + 1) % stride;
|
||||
|
||||
index_push_back(indices, i * stride + j);
|
||||
index_push_back(indices, i * stride + nextJ);
|
||||
|
@ -799,16 +799,16 @@ void DirectX::ComputeTetrahedron(VertexCollection& vertices, IndexCollection& in
|
|||
|
||||
for (size_t j = 0; j < std::size(faces); j += 3)
|
||||
{
|
||||
uint32_t v0 = faces[j];
|
||||
uint32_t v1 = faces[j + 1];
|
||||
uint32_t v2 = faces[j + 2];
|
||||
const uint32_t v0 = faces[j];
|
||||
const uint32_t v1 = faces[j + 1];
|
||||
const uint32_t v2 = faces[j + 2];
|
||||
|
||||
XMVECTOR normal = XMVector3Cross(
|
||||
XMVectorSubtract(verts[v1].v, verts[v0].v),
|
||||
XMVectorSubtract(verts[v2].v, verts[v0].v));
|
||||
normal = XMVector3Normalize(normal);
|
||||
|
||||
size_t base = vertices.size();
|
||||
const size_t base = vertices.size();
|
||||
index_push_back(indices, base);
|
||||
index_push_back(indices, base + 1);
|
||||
index_push_back(indices, base + 2);
|
||||
|
@ -865,16 +865,16 @@ void DirectX::ComputeOctahedron(VertexCollection& vertices, IndexCollection& ind
|
|||
|
||||
for (size_t j = 0; j < std::size(faces); j += 3)
|
||||
{
|
||||
uint32_t v0 = faces[j];
|
||||
uint32_t v1 = faces[j + 1];
|
||||
uint32_t v2 = faces[j + 2];
|
||||
const uint32_t v0 = faces[j];
|
||||
const uint32_t v1 = faces[j + 1];
|
||||
const uint32_t v2 = faces[j + 2];
|
||||
|
||||
XMVECTOR normal = XMVector3Cross(
|
||||
XMVectorSubtract(verts[v1].v, verts[v0].v),
|
||||
XMVectorSubtract(verts[v2].v, verts[v0].v));
|
||||
normal = XMVector3Normalize(normal);
|
||||
|
||||
size_t base = vertices.size();
|
||||
const size_t base = vertices.size();
|
||||
index_push_back(indices, base);
|
||||
index_push_back(indices, base + 1);
|
||||
index_push_back(indices, base + 2);
|
||||
|
@ -979,18 +979,18 @@ void DirectX::ComputeDodecahedron(VertexCollection& vertices, IndexCollection& i
|
|||
size_t t = 0;
|
||||
for (size_t j = 0; j < std::size(faces); j += 5, ++t)
|
||||
{
|
||||
uint32_t v0 = faces[j];
|
||||
uint32_t v1 = faces[j + 1];
|
||||
uint32_t v2 = faces[j + 2];
|
||||
uint32_t v3 = faces[j + 3];
|
||||
uint32_t v4 = faces[j + 4];
|
||||
const uint32_t v0 = faces[j];
|
||||
const uint32_t v1 = faces[j + 1];
|
||||
const uint32_t v2 = faces[j + 2];
|
||||
const uint32_t v3 = faces[j + 3];
|
||||
const uint32_t v4 = faces[j + 4];
|
||||
|
||||
XMVECTOR normal = XMVector3Cross(
|
||||
XMVectorSubtract(verts[v1].v, verts[v0].v),
|
||||
XMVectorSubtract(verts[v2].v, verts[v0].v));
|
||||
normal = XMVector3Normalize(normal);
|
||||
|
||||
size_t base = vertices.size();
|
||||
const size_t base = vertices.size();
|
||||
|
||||
index_push_back(indices, base);
|
||||
index_push_back(indices, base + 1);
|
||||
|
@ -1083,16 +1083,16 @@ void DirectX::ComputeIcosahedron(VertexCollection& vertices, IndexCollection& in
|
|||
|
||||
for (size_t j = 0; j < std::size(faces); j += 3)
|
||||
{
|
||||
uint32_t v0 = faces[j];
|
||||
uint32_t v1 = faces[j + 1];
|
||||
uint32_t v2 = faces[j + 2];
|
||||
const uint32_t v0 = faces[j];
|
||||
const uint32_t v1 = faces[j + 1];
|
||||
const uint32_t v2 = faces[j + 2];
|
||||
|
||||
XMVECTOR normal = XMVector3Cross(
|
||||
XMVectorSubtract(verts[v1].v, verts[v0].v),
|
||||
XMVectorSubtract(verts[v2].v, verts[v0].v));
|
||||
normal = XMVector3Normalize(normal);
|
||||
|
||||
size_t base = vertices.size();
|
||||
const size_t base = vertices.size();
|
||||
index_push_back(indices, base);
|
||||
index_push_back(indices, base + 1);
|
||||
index_push_back(indices, base + 2);
|
||||
|
@ -1162,11 +1162,11 @@ void DirectX::ComputeTeapot(VertexCollection& vertices, IndexCollection& indices
|
|||
if (tessellation < 1)
|
||||
throw std::invalid_argument("tesselation parameter must be non-zero");
|
||||
|
||||
XMVECTOR scaleVector = XMVectorReplicate(size);
|
||||
const XMVECTOR scaleVector = XMVectorReplicate(size);
|
||||
|
||||
XMVECTOR scaleNegateX = XMVectorMultiply(scaleVector, g_XMNegateX);
|
||||
XMVECTOR scaleNegateZ = XMVectorMultiply(scaleVector, g_XMNegateZ);
|
||||
XMVECTOR scaleNegateXZ = XMVectorMultiply(scaleVector, XMVectorMultiply(g_XMNegateX, g_XMNegateZ));
|
||||
const XMVECTOR scaleNegateX = XMVectorMultiply(scaleVector, g_XMNegateX);
|
||||
const XMVECTOR scaleNegateZ = XMVectorMultiply(scaleVector, g_XMNegateZ);
|
||||
const XMVECTOR scaleNegateXZ = XMVectorMultiply(scaleVector, XMVectorMultiply(g_XMNegateX, g_XMNegateZ));
|
||||
|
||||
for (size_t i = 0; i < std::size(TeapotPatches); i++)
|
||||
{
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace
|
|||
|
||||
auto ptr = reinterpret_cast<uint32_t*>(&state);
|
||||
|
||||
unsigned int bf = 1u << (key & 0x1f);
|
||||
const unsigned int bf = 1u << (key & 0x1f);
|
||||
ptr[(key >> 5)] |= bf;
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ namespace
|
|||
|
||||
auto ptr = reinterpret_cast<uint32_t*>(&state);
|
||||
|
||||
unsigned int bf = 1u << (key & 0x1f);
|
||||
const unsigned int bf = 1u << (key & 0x1f);
|
||||
ptr[(key >> 5)] &= ~bf;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -309,7 +309,7 @@ namespace DirectX
|
|||
}
|
||||
|
||||
// DDS files always start with the same magic number ("DDS ")
|
||||
auto dwMagicNumber = *reinterpret_cast<const uint32_t*>(ddsData);
|
||||
auto const dwMagicNumber = *reinterpret_cast<const uint32_t*>(ddsData);
|
||||
if (dwMagicNumber != DDS_MAGIC)
|
||||
{
|
||||
return E_FAIL;
|
||||
|
@ -430,7 +430,7 @@ namespace DirectX
|
|||
}
|
||||
|
||||
// DDS files always start with the same magic number ("DDS ")
|
||||
auto dwMagicNumber = *reinterpret_cast<const uint32_t*>(ddsData.get());
|
||||
auto const dwMagicNumber = *reinterpret_cast<const uint32_t*>(ddsData.get());
|
||||
if (dwMagicNumber != DDS_MAGIC)
|
||||
{
|
||||
ddsData.reset();
|
||||
|
@ -601,7 +601,7 @@ namespace DirectX
|
|||
}
|
||||
else
|
||||
{
|
||||
size_t bpp = BitsPerPixel(fmt);
|
||||
const size_t bpp = BitsPerPixel(fmt);
|
||||
if (!bpp)
|
||||
return E_INVALIDARG;
|
||||
|
||||
|
@ -912,7 +912,7 @@ namespace DirectX
|
|||
if (MAKEFOURCC('D', 'X', '1', '0') == header->ddspf.fourCC)
|
||||
{
|
||||
auto d3d10ext = reinterpret_cast<const DDS_HEADER_DXT10*>(reinterpret_cast<const uint8_t*>(header) + sizeof(DDS_HEADER));
|
||||
auto mode = static_cast<DDS_ALPHA_MODE>(d3d10ext->miscFlags2 & DDS_MISC_FLAGS2_ALPHA_MODE_MASK);
|
||||
auto const mode = static_cast<DDS_ALPHA_MODE>(d3d10ext->miscFlags2 & DDS_MISC_FLAGS2_ALPHA_MODE_MASK);
|
||||
switch (mode)
|
||||
{
|
||||
case DDS_ALPHA_MODE_STRAIGHT:
|
||||
|
@ -1008,7 +1008,7 @@ namespace DirectX
|
|||
|
||||
inline void FitPowerOf2(UINT origx, UINT origy, _Inout_ UINT& targetx, _Inout_ UINT& targety, size_t maxsize)
|
||||
{
|
||||
float origAR = float(origx) / float(origy);
|
||||
const float origAR = float(origx) / float(origy);
|
||||
|
||||
if (origx > origy)
|
||||
{
|
||||
|
@ -1019,7 +1019,7 @@ namespace DirectX
|
|||
float bestScore = FLT_MAX;
|
||||
for (size_t y = maxsize; y > 0; y >>= 1)
|
||||
{
|
||||
float score = fabsf((float(x) / float(y)) - origAR);
|
||||
const float score = fabsf((float(x) / float(y)) - origAR);
|
||||
if (score < bestScore)
|
||||
{
|
||||
bestScore = score;
|
||||
|
@ -1036,7 +1036,7 @@ namespace DirectX
|
|||
float bestScore = FLT_MAX;
|
||||
for (size_t x = maxsize; x > 0; x >>= 1)
|
||||
{
|
||||
float score = fabsf((float(x) / float(y)) - origAR);
|
||||
const float score = fabsf((float(x) / float(y)) - origAR);
|
||||
if (score < bestScore)
|
||||
{
|
||||
bestScore = score;
|
||||
|
|
|
@ -52,8 +52,8 @@ void ModelMeshPart::Draw(
|
|||
deviceContext->IASetInputLayout(iinputLayout);
|
||||
|
||||
auto vb = vertexBuffer.Get();
|
||||
UINT vbStride = vertexStride;
|
||||
UINT vbOffset = 0;
|
||||
const UINT vbStride = vertexStride;
|
||||
constexpr UINT vbOffset = 0;
|
||||
deviceContext->IASetVertexBuffers(0, 1, &vb, &vbStride, &vbOffset);
|
||||
|
||||
// Note that if indexFormat is DXGI_FORMAT_R32_UINT, this model mesh part requires a Feature Level 9.2 or greater device
|
||||
|
@ -87,8 +87,8 @@ void ModelMeshPart::DrawInstanced(
|
|||
deviceContext->IASetInputLayout(iinputLayout);
|
||||
|
||||
auto vb = vertexBuffer.Get();
|
||||
UINT vbStride = vertexStride;
|
||||
UINT vbOffset = 0;
|
||||
const UINT vbStride = vertexStride;
|
||||
constexpr UINT vbOffset = 0;
|
||||
deviceContext->IASetVertexBuffers(0, 1, &vb, &vbStride, &vbOffset);
|
||||
|
||||
// Note that if indexFormat is DXGI_FORMAT_R32_UINT, this model mesh part requires a Feature Level 9.2 or greater device
|
||||
|
@ -139,7 +139,7 @@ void ModelMeshPart::CreateInputLayout(ID3D11Device* d3dDevice, IEffect* ieffect,
|
|||
|
||||
// Assigns a new effect and re-generates input layout.
|
||||
_Use_decl_annotations_
|
||||
void ModelMeshPart::ModifyEffect(ID3D11Device* d3dDevice, std::shared_ptr<IEffect>& ieffect, bool isalpha)
|
||||
void ModelMeshPart::ModifyEffect(ID3D11Device* d3dDevice, const std::shared_ptr<IEffect>& ieffect, bool isalpha)
|
||||
{
|
||||
if (!vbDecl || vbDecl->empty())
|
||||
throw std::runtime_error("Model mesh part missing vertex buffer input elements data");
|
||||
|
@ -393,7 +393,7 @@ void XM_CALLCONV ModelMesh::DrawSkinned(
|
|||
else if (imatrices)
|
||||
{
|
||||
// Fallback for if we encounter a non-skinning effect in the model
|
||||
XMMATRIX bm = (boneIndex != ModelBone::c_Invalid && boneIndex < nbones)
|
||||
const XMMATRIX bm = (boneIndex != ModelBone::c_Invalid && boneIndex < nbones)
|
||||
? boneTransforms[boneIndex] : XMMatrixIdentity();
|
||||
|
||||
imatrices->SetWorld(XMMatrixMultiply(bm, world));
|
||||
|
@ -466,7 +466,7 @@ void XM_CALLCONV Model::Draw(
|
|||
// Draw opaque parts
|
||||
for (const auto& it : meshes)
|
||||
{
|
||||
auto mesh = it.get();
|
||||
const auto *mesh = it.get();
|
||||
assert(mesh != nullptr);
|
||||
|
||||
mesh->PrepareForRendering(deviceContext, states, false, wireframe);
|
||||
|
@ -477,7 +477,7 @@ void XM_CALLCONV Model::Draw(
|
|||
// Draw alpha parts
|
||||
for (const auto& it : meshes)
|
||||
{
|
||||
auto mesh = it.get();
|
||||
const auto *mesh = it.get();
|
||||
assert(mesh != nullptr);
|
||||
|
||||
mesh->PrepareForRendering(deviceContext, states, true, wireframe);
|
||||
|
@ -505,7 +505,7 @@ void XM_CALLCONV Model::Draw(
|
|||
// Draw opaque parts
|
||||
for (const auto& it : meshes)
|
||||
{
|
||||
auto mesh = it.get();
|
||||
const auto *mesh = it.get();
|
||||
assert(mesh != nullptr);
|
||||
|
||||
mesh->PrepareForRendering(deviceContext, states, false, wireframe);
|
||||
|
@ -516,7 +516,7 @@ void XM_CALLCONV Model::Draw(
|
|||
// Draw alpha parts
|
||||
for (const auto& it : meshes)
|
||||
{
|
||||
auto mesh = it.get();
|
||||
const auto *mesh = it.get();
|
||||
assert(mesh != nullptr);
|
||||
|
||||
mesh->PrepareForRendering(deviceContext, states, true, wireframe);
|
||||
|
@ -544,7 +544,7 @@ void XM_CALLCONV Model::DrawSkinned(
|
|||
// Draw opaque parts
|
||||
for (const auto& it : meshes)
|
||||
{
|
||||
auto mesh = it.get();
|
||||
const auto *mesh = it.get();
|
||||
assert(mesh != nullptr);
|
||||
|
||||
mesh->PrepareForRendering(deviceContext, states, false, wireframe);
|
||||
|
@ -555,7 +555,7 @@ void XM_CALLCONV Model::DrawSkinned(
|
|||
// Draw alpha parts
|
||||
for (const auto& it : meshes)
|
||||
{
|
||||
auto mesh = it.get();
|
||||
const auto *mesh = it.get();
|
||||
assert(mesh != nullptr);
|
||||
|
||||
mesh->PrepareForRendering(deviceContext, states, true, wireframe);
|
||||
|
@ -588,7 +588,7 @@ void Model::CopyAbsoluteBoneTransformsTo(
|
|||
|
||||
memset(boneTransforms, 0, sizeof(XMMATRIX) * nbones);
|
||||
|
||||
XMMATRIX id = XMMatrixIdentity();
|
||||
const XMMATRIX id = XMMatrixIdentity();
|
||||
size_t visited = 0;
|
||||
ComputeAbsolute(0, id, bones.size(), boneMatrices.get(), boneTransforms, visited);
|
||||
}
|
||||
|
@ -618,7 +618,7 @@ void Model::CopyAbsoluteBoneTransforms(
|
|||
|
||||
memset(outBoneTransforms, 0, sizeof(XMMATRIX) * nbones);
|
||||
|
||||
XMMATRIX id = XMMatrixIdentity();
|
||||
const XMMATRIX id = XMMatrixIdentity();
|
||||
size_t visited = 0;
|
||||
ComputeAbsolute(0, id, bones.size(), inBoneTransforms, outBoneTransforms, visited);
|
||||
}
|
||||
|
|
|
@ -450,7 +450,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
|
|||
throw std::runtime_error("IB too large for DirectX 11");
|
||||
}
|
||||
|
||||
auto ibBytes = static_cast<size_t>(sizeInBytes);
|
||||
auto const ibBytes = static_cast<size_t>(sizeInBytes);
|
||||
|
||||
auto indexes = reinterpret_cast<const uint16_t*>(meshData + usedSize);
|
||||
usedSize += ibBytes;
|
||||
|
@ -569,8 +569,8 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
|
|||
mesh->boundingSphere.Center.z = extents->CenterZ;
|
||||
mesh->boundingSphere.Radius = extents->Radius;
|
||||
|
||||
XMVECTOR min = XMVectorSet(extents->MinX, extents->MinY, extents->MinZ, 0.f);
|
||||
XMVECTOR max = XMVectorSet(extents->MaxX, extents->MaxY, extents->MaxZ, 0.f);
|
||||
const XMVECTOR min = XMVectorSet(extents->MinX, extents->MinY, extents->MinZ, 0.f);
|
||||
const XMVECTOR max = XMVectorSet(extents->MaxX, extents->MaxY, extents->MaxZ, 0.f);
|
||||
BoundingBox::CreateFromPoints(mesh->boundingBox, min, max);
|
||||
|
||||
// Load model bones (if present and requested)
|
||||
|
@ -627,7 +627,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
|
|||
if (visited >= *nBones)
|
||||
throw std::runtime_error("Skeleton bones form an invalid graph");
|
||||
|
||||
uint32_t sibling = bones[index].siblingIndex;
|
||||
const uint32_t sibling = bones[index].siblingIndex;
|
||||
if (sibling == ModelBone::c_Invalid)
|
||||
{
|
||||
bones[index].siblingIndex = j;
|
||||
|
@ -667,7 +667,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
|
|||
if (visited >= *nBones)
|
||||
throw std::runtime_error("Skeleton bones form an invalid graph");
|
||||
|
||||
uint32_t sibling = bones[index].siblingIndex;
|
||||
const uint32_t sibling = bones[index].siblingIndex;
|
||||
if (sibling == ModelBone::c_Invalid)
|
||||
{
|
||||
bones[index].siblingIndex = j;
|
||||
|
@ -706,7 +706,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
|
|||
}
|
||||
}
|
||||
|
||||
bool enableSkinning = (*nSkinVBs) != 0 && !(flags & ModelLoader_DisableSkinning);
|
||||
const bool enableSkinning = (*nSkinVBs) != 0 && !(flags & ModelLoader_DisableSkinning);
|
||||
|
||||
// Build vertex buffers
|
||||
std::vector<ComPtr<ID3D11Buffer>> vbs;
|
||||
|
@ -795,7 +795,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
|
|||
|| (sm.MaterialIndex >= materials.size()))
|
||||
throw std::out_of_range("Invalid submesh found\n");
|
||||
|
||||
XMMATRIX uvTransform = XMLoadFloat4x4(&materials[sm.MaterialIndex].pMaterial->UVTransform);
|
||||
const XMMATRIX uvTransform = XMLoadFloat4x4(&materials[sm.MaterialIndex].pMaterial->UVTransform);
|
||||
|
||||
auto ib = ibData[sm.IndexBufferIndex].ptr;
|
||||
|
||||
|
@ -824,7 +824,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
|
|||
else if (visited[v] != sm.MaterialIndex)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
XMMATRIX uv2 = XMLoadFloat4x4(&materials[visited[v]].pMaterial->UVTransform);
|
||||
const XMMATRIX uv2 = XMLoadFloat4x4(&materials[visited[v]].pMaterial->UVTransform);
|
||||
|
||||
if (XMVector4NotEqual(uvTransform.r[0], uv2.r[0])
|
||||
|| XMVector4NotEqual(uvTransform.r[1], uv2.r[1])
|
||||
|
@ -853,7 +853,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
|
|||
assert(vbs.size() == *nVBs);
|
||||
|
||||
// Create Effects
|
||||
bool srgb = (flags & ModelLoader_MaterialColorsSRGB) != 0;
|
||||
const bool srgb = (flags & ModelLoader_MaterialColorsSRGB) != 0;
|
||||
|
||||
for (size_t j = 0; j < materials.size(); ++j)
|
||||
{
|
||||
|
|
|
@ -376,14 +376,14 @@ std::unique_ptr<Model> DirectX::Model::CreateFromSDKMESH(
|
|||
if (!d3dDevice || !meshData)
|
||||
throw std::invalid_argument("Device and meshData cannot be null");
|
||||
|
||||
uint64_t dataSize = idataSize;
|
||||
const uint64_t dataSize = idataSize;
|
||||
|
||||
// File Headers
|
||||
if (dataSize < sizeof(DXUT::SDKMESH_HEADER))
|
||||
throw std::runtime_error("End of file");
|
||||
auto header = reinterpret_cast<const DXUT::SDKMESH_HEADER*>(meshData);
|
||||
|
||||
size_t headerSize = sizeof(DXUT::SDKMESH_HEADER)
|
||||
const size_t headerSize = sizeof(DXUT::SDKMESH_HEADER)
|
||||
+ header->NumVertexBuffers * sizeof(DXUT::SDKMESH_VERTEX_BUFFER_HEADER)
|
||||
+ header->NumIndexBuffers * sizeof(DXUT::SDKMESH_INDEX_BUFFER_HEADER);
|
||||
if (header->HeaderSize != headerSize)
|
||||
|
@ -463,7 +463,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromSDKMESH(
|
|||
}
|
||||
|
||||
// Buffer data
|
||||
uint64_t bufferDataOffset = header->HeaderSize + header->NonBufferDataSize;
|
||||
const uint64_t bufferDataOffset = header->HeaderSize + header->NonBufferDataSize;
|
||||
if ((dataSize < bufferDataOffset)
|
||||
|| (dataSize < bufferDataOffset + header->BufferDataSize))
|
||||
throw std::runtime_error("End of file");
|
||||
|
@ -638,7 +638,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromSDKMESH(
|
|||
mesh->meshParts.reserve(mh.NumSubsets);
|
||||
for (size_t j = 0; j < mh.NumSubsets; ++j)
|
||||
{
|
||||
auto sIndex = subsets[j];
|
||||
auto const sIndex = subsets[j];
|
||||
if (sIndex >= header->NumTotalSubsets)
|
||||
throw std::out_of_range("Invalid mesh found");
|
||||
|
||||
|
@ -672,7 +672,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromSDKMESH(
|
|||
|
||||
if (!mat.effect)
|
||||
{
|
||||
size_t vi = mh.VertexBuffers[0];
|
||||
const size_t vi = mh.VertexBuffers[0];
|
||||
|
||||
if (materialArray_v2)
|
||||
{
|
||||
|
@ -745,7 +745,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromSDKMESH(
|
|||
|
||||
transforms[j] = XMLoadFloat4x4(&frameArray[j].Matrix);
|
||||
|
||||
uint32_t index = frameArray[j].Mesh;
|
||||
const uint32_t index = frameArray[j].Mesh;
|
||||
if (index != DXUT::INVALID_MESH)
|
||||
{
|
||||
if (index >= model->meshes.size())
|
||||
|
|
|
@ -77,7 +77,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromVBO(
|
|||
throw std::runtime_error("VB too large for DirectX 11");
|
||||
}
|
||||
|
||||
auto vertSize = static_cast<size_t>(sizeInBytes);
|
||||
auto const vertSize = static_cast<size_t>(sizeInBytes);
|
||||
|
||||
if (dataSize < (vertSize + sizeof(VBO::header_t)))
|
||||
throw std::runtime_error("End of file");
|
||||
|
@ -94,7 +94,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromVBO(
|
|||
throw std::runtime_error("IB too large for DirectX 11");
|
||||
}
|
||||
|
||||
auto indexSize = static_cast<size_t>(sizeInBytes);
|
||||
auto const indexSize = static_cast<size_t>(sizeInBytes);
|
||||
|
||||
if (dataSize < (sizeof(VBO::header_t) + vertSize + indexSize))
|
||||
throw std::runtime_error("End of file");
|
||||
|
|
|
@ -554,7 +554,7 @@ public:
|
|||
throw std::system_error(std::error_code(static_cast<int>(GetLastError()), std::system_category()), "GetCursorInfo");
|
||||
}
|
||||
|
||||
bool isvisible = (info.flags & CURSOR_SHOWING) != 0;
|
||||
const bool isvisible = (info.flags & CURSOR_SHOWING) != 0;
|
||||
if (isvisible != visible)
|
||||
{
|
||||
ShowCursor(visible);
|
||||
|
@ -721,7 +721,7 @@ void Mouse::ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam)
|
|||
}
|
||||
else
|
||||
{
|
||||
int scrollWheel = pImpl->mState.scrollWheelValue;
|
||||
const int scrollWheel = pImpl->mState.scrollWheelValue;
|
||||
memset(&pImpl->mState, 0, sizeof(State));
|
||||
pImpl->mState.scrollWheelValue = scrollWheel;
|
||||
|
||||
|
@ -740,7 +740,7 @@ void Mouse::ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam)
|
|||
RAWINPUT raw;
|
||||
UINT rawSize = sizeof(raw);
|
||||
|
||||
UINT resultData = GetRawInputData(reinterpret_cast<HRAWINPUT>(lParam), RID_INPUT, &raw, &rawSize, sizeof(RAWINPUTHEADER));
|
||||
const UINT resultData = GetRawInputData(reinterpret_cast<HRAWINPUT>(lParam), RID_INPUT, &raw, &rawSize, sizeof(RAWINPUTHEADER));
|
||||
if (resultData == UINT(-1))
|
||||
{
|
||||
throw std::runtime_error("GetRawInputData");
|
||||
|
@ -761,8 +761,8 @@ void Mouse::ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam)
|
|||
const int width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
|
||||
const int height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
|
||||
|
||||
int x = static_cast<int>((float(raw.data.mouse.lLastX) / 65535.0f) * float(width));
|
||||
int y = static_cast<int>((float(raw.data.mouse.lLastY) / 65535.0f) * float(height));
|
||||
auto const x = static_cast<int>((float(raw.data.mouse.lLastX) / 65535.0f) * float(width));
|
||||
auto const y = static_cast<int>((float(raw.data.mouse.lLastY) / 65535.0f) * float(height));
|
||||
|
||||
if (pImpl->mRelativeX == INT32_MAX)
|
||||
{
|
||||
|
@ -851,8 +851,8 @@ void Mouse::ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam)
|
|||
if (pImpl->mMode == MODE_ABSOLUTE)
|
||||
{
|
||||
// All mouse messages provide a new pointer position
|
||||
int xPos = static_cast<short>(LOWORD(lParam)); // GET_X_LPARAM(lParam);
|
||||
int yPos = static_cast<short>(HIWORD(lParam)); // GET_Y_LPARAM(lParam);
|
||||
const int xPos = static_cast<short>(LOWORD(lParam)); // GET_X_LPARAM(lParam);
|
||||
const int yPos = static_cast<short>(HIWORD(lParam)); // GET_Y_LPARAM(lParam);
|
||||
|
||||
pImpl->mState.x = pImpl->mLastX = xPos;
|
||||
pImpl->mState.y = pImpl->mLastY = yPos;
|
||||
|
|
|
@ -355,7 +355,7 @@ void PBREffect::Impl::Apply(_In_ ID3D11DeviceContext* deviceContext)
|
|||
{
|
||||
constants.world = XMMatrixTranspose(matrices.world);
|
||||
|
||||
XMMATRIX worldInverse = XMMatrixInverse(nullptr, matrices.world);
|
||||
const XMMATRIX worldInverse = XMMatrixInverse(nullptr, matrices.world);
|
||||
|
||||
constants.worldInverseTranspose[0] = worldInverse.r[0];
|
||||
constants.worldInverseTranspose[1] = worldInverse.r[1];
|
||||
|
@ -368,7 +368,7 @@ void PBREffect::Impl::Apply(_In_ ID3D11DeviceContext* deviceContext)
|
|||
// Eye position vector.
|
||||
if (dirtyFlags & EffectDirtyFlags::EyePosition)
|
||||
{
|
||||
XMMATRIX viewInverse = XMMatrixInverse(nullptr, matrices.view);
|
||||
const XMMATRIX viewInverse = XMMatrixInverse(nullptr, matrices.view);
|
||||
|
||||
constants.eyePosition = viewInverse.r[3];
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ namespace
|
|||
else
|
||||
{
|
||||
// Untextured material (for PBR this still requires texture coordinates)
|
||||
XMVECTOR color = XMLoadFloat3(&info.diffuseColor);
|
||||
const XMVECTOR color = XMLoadFloat3(&info.diffuseColor);
|
||||
effect->SetConstantAlbedo(color);
|
||||
|
||||
if (info.specularColor.x != 0 || info.specularColor.y != 0 || info.specularColor.z != 0)
|
||||
|
@ -71,7 +71,7 @@ namespace
|
|||
// Derived from specularPower = 2 / roughness ^ 4 - 2
|
||||
// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html
|
||||
|
||||
float roughness = powf(2.f / (info.specularPower + 2.f), 1.f / 4.f);
|
||||
const float roughness = powf(2.f / (info.specularPower + 2.f), 1.f / 4.f);
|
||||
effect->SetConstantRoughness(roughness);
|
||||
}
|
||||
|
||||
|
@ -236,7 +236,7 @@ void PBREffectFactory::Impl::CreateTexture(
|
|||
|
||||
wchar_t ext[_MAX_EXT] = {};
|
||||
_wsplitpath_s(name, nullptr, 0, nullptr, 0, nullptr, 0, ext, _MAX_EXT);
|
||||
bool isdds = _wcsicmp(ext, L".dds") == 0;
|
||||
const bool isdds = _wcsicmp(ext, L".dds") == 0;
|
||||
|
||||
if (isdds)
|
||||
{
|
||||
|
|
|
@ -135,12 +135,12 @@ PrimitiveBatchBase::Impl::Impl(_In_ ID3D11DeviceContext* deviceContext, size_t m
|
|||
if (vertexSize > D3D11_REQ_MULTI_ELEMENT_STRUCTURE_SIZE_IN_BYTES)
|
||||
throw std::invalid_argument("Vertex size is too large for DirectX 11");
|
||||
|
||||
uint64_t ibBytes = uint64_t(maxIndices) * sizeof(uint16_t);
|
||||
const uint64_t ibBytes = uint64_t(maxIndices) * sizeof(uint16_t);
|
||||
if (ibBytes > uint64_t(D3D11_REQ_RESOURCE_SIZE_IN_MEGABYTES_EXPRESSION_A_TERM * 1024u * 1024u)
|
||||
|| ibBytes > UINT32_MAX)
|
||||
throw std::invalid_argument("IB too large for DirectX 11");
|
||||
|
||||
uint64_t vbBytes = uint64_t(maxVertices) * uint64_t(vertexSize);
|
||||
const uint64_t vbBytes = uint64_t(maxVertices) * uint64_t(vertexSize);
|
||||
if (vbBytes > uint64_t(D3D11_REQ_RESOURCE_SIZE_IN_MEGABYTES_EXPRESSION_A_TERM * 1024u * 1024u)
|
||||
|| vbBytes > UINT32_MAX)
|
||||
throw std::invalid_argument("VB too large for DirectX 11");
|
||||
|
@ -193,8 +193,8 @@ void PrimitiveBatchBase::Impl::Begin()
|
|||
|
||||
// Bind the vertex buffer.
|
||||
auto vertexBuffer = mVertexBuffer.Get();
|
||||
UINT vertexStride = static_cast<UINT>(mVertexSize);
|
||||
UINT vertexOffset = 0;
|
||||
const UINT vertexStride = static_cast<UINT>(mVertexSize);
|
||||
constexpr UINT vertexOffset = 0;
|
||||
|
||||
mDeviceContext->IASetVertexBuffers(0, 1, &vertexBuffer, &vertexStride, &vertexOffset);
|
||||
#endif
|
||||
|
@ -249,7 +249,7 @@ namespace
|
|||
// Helper for locking a vertex or index buffer.
|
||||
void LockBuffer(_In_ ID3D11DeviceContext* deviceContext, _In_ ID3D11Buffer* buffer, size_t currentPosition, _Out_ size_t* basePosition, _Out_ D3D11_MAPPED_SUBRESOURCE* mappedResource)
|
||||
{
|
||||
D3D11_MAP mapType = (currentPosition == 0) ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE_NO_OVERWRITE;
|
||||
const D3D11_MAP mapType = (currentPosition == 0) ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE_NO_OVERWRITE;
|
||||
|
||||
ThrowIfFailed(
|
||||
deviceContext->Map(buffer, 0, mapType, 0, mappedResource)
|
||||
|
@ -278,8 +278,8 @@ void PrimitiveBatchBase::Impl::Draw(D3D11_PRIMITIVE_TOPOLOGY topology, bool isIn
|
|||
throw std::logic_error("Begin must be called before Draw");
|
||||
|
||||
// Can we merge this primitive in with an existing batch, or must we flush first?
|
||||
bool wrapIndexBuffer = (mCurrentIndex + indexCount > mMaxIndices);
|
||||
bool wrapVertexBuffer = (mCurrentVertex + vertexCount > mMaxVertices);
|
||||
const bool wrapIndexBuffer = (mCurrentIndex + indexCount > mMaxIndices);
|
||||
const bool wrapVertexBuffer = (mCurrentVertex + vertexCount > mMaxVertices);
|
||||
|
||||
if ((topology != mCurrentTopology) ||
|
||||
(isIndexed != mCurrentlyIndexed) ||
|
||||
|
|
|
@ -85,7 +85,7 @@ namespace
|
|||
|
||||
assert(pTemp);
|
||||
|
||||
DXGI_FORMAT fmt = EnsureNotTypeless(desc.Format);
|
||||
const DXGI_FORMAT fmt = EnsureNotTypeless(desc.Format);
|
||||
|
||||
UINT support = 0;
|
||||
hr = d3dDevice->CheckFormatSupport(fmt, &support);
|
||||
|
@ -99,7 +99,7 @@ namespace
|
|||
{
|
||||
for (UINT level = 0; level < desc.MipLevels; ++level)
|
||||
{
|
||||
UINT index = D3D11CalcSubresource(level, item, desc.MipLevels);
|
||||
const UINT index = D3D11CalcSubresource(level, item, desc.MipLevels);
|
||||
pContext->ResolveSubresource(pTemp.Get(), index, pSource, index, fmt);
|
||||
}
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ HRESULT DirectX::SaveDDSTextureToFile(
|
|||
auto_delete_file delonfail(hFile.get());
|
||||
|
||||
// Setup header
|
||||
const size_t MAX_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_DXT10);
|
||||
constexpr size_t MAX_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_DXT10);
|
||||
uint8_t fileHeader[MAX_HEADER_SIZE] = {};
|
||||
|
||||
*reinterpret_cast<uint32_t*>(&fileHeader[0]) = DDS_MAGIC;
|
||||
|
@ -313,7 +313,7 @@ HRESULT DirectX::SaveDDSTextureToFile(
|
|||
|
||||
uint8_t* dptr = pixels.get();
|
||||
|
||||
size_t msize = std::min<size_t>(rowPitch, mapped.RowPitch);
|
||||
const size_t msize = std::min<size_t>(rowPitch, mapped.RowPitch);
|
||||
for (size_t h = 0; h < rowCount; ++h)
|
||||
{
|
||||
memcpy(dptr, sptr, msize);
|
||||
|
@ -617,7 +617,7 @@ HRESULT DirectX::SaveWICTextureToFile(
|
|||
if (FAILED(hr))
|
||||
return hr;
|
||||
|
||||
uint64_t imageSize = uint64_t(mapped.RowPitch) * uint64_t(desc.Height);
|
||||
const uint64_t imageSize = uint64_t(mapped.RowPitch) * uint64_t(desc.Height);
|
||||
if (imageSize > UINT32_MAX)
|
||||
{
|
||||
pContext->Unmap(pStaging.Get(), 0);
|
||||
|
|
|
@ -89,9 +89,9 @@ namespace DirectX
|
|||
|
||||
~WrappedData()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mResourceMap->mutex);
|
||||
const std::lock_guard<std::mutex> lock(mResourceMap->mutex);
|
||||
|
||||
auto pos = mResourceMap->find(mKey);
|
||||
auto const pos = mResourceMap->find(mKey);
|
||||
|
||||
// Check for weak reference expiry before erasing, in case DemandCreate runs on
|
||||
// a different thread at the same time as a previous instance is being destroyed.
|
||||
|
|
|
@ -65,18 +65,18 @@ using namespace DirectX::SimpleMath;
|
|||
|
||||
void Quaternion::RotateTowards(const Quaternion& target, float maxAngle, Quaternion& result) const noexcept
|
||||
{
|
||||
XMVECTOR T = XMLoadFloat4(this);
|
||||
const XMVECTOR T = XMLoadFloat4(this);
|
||||
|
||||
// We can use the conjugate here instead of inverse assuming q1 & q2 are normalized.
|
||||
XMVECTOR R = XMQuaternionMultiply(XMQuaternionConjugate(T), target);
|
||||
const XMVECTOR R = XMQuaternionMultiply(XMQuaternionConjugate(T), target);
|
||||
|
||||
float rs = XMVectorGetW(R);
|
||||
XMVECTOR L = XMVector3Length(R);
|
||||
float angle = 2.f * atan2f(XMVectorGetX(L), rs);
|
||||
const float rs = XMVectorGetW(R);
|
||||
const XMVECTOR L = XMVector3Length(R);
|
||||
const float angle = 2.f * atan2f(XMVectorGetX(L), rs);
|
||||
if (angle > maxAngle)
|
||||
{
|
||||
XMVECTOR delta = XMQuaternionRotationAxis(R, maxAngle);
|
||||
XMVECTOR Q = XMQuaternionMultiply(delta, T);
|
||||
const XMVECTOR delta = XMQuaternionRotationAxis(R, maxAngle);
|
||||
const XMVECTOR Q = XMQuaternionMultiply(delta, T);
|
||||
XMStoreFloat4(&result, Q);
|
||||
}
|
||||
else
|
||||
|
@ -90,10 +90,10 @@ void Quaternion::FromToRotation(const Vector3& fromDir, const Vector3& toDir, Qu
|
|||
{
|
||||
// Melax, "The Shortest Arc Quaternion", Game Programming Gems, Charles River Media (2000).
|
||||
|
||||
XMVECTOR F = XMVector3Normalize(fromDir);
|
||||
XMVECTOR T = XMVector3Normalize(toDir);
|
||||
const XMVECTOR F = XMVector3Normalize(fromDir);
|
||||
const XMVECTOR T = XMVector3Normalize(toDir);
|
||||
|
||||
float dot = XMVectorGetX(XMVector3Dot(F, T));
|
||||
const float dot = XMVectorGetX(XMVector3Dot(F, T));
|
||||
if (dot >= 1.f)
|
||||
{
|
||||
result = Identity;
|
||||
|
@ -106,15 +106,15 @@ void Quaternion::FromToRotation(const Vector3& fromDir, const Vector3& toDir, Qu
|
|||
axis = XMVector3Cross(F, Vector3::Up);
|
||||
}
|
||||
|
||||
XMVECTOR Q = XMQuaternionRotationAxis(axis, XM_PI);
|
||||
const XMVECTOR Q = XMQuaternionRotationAxis(axis, XM_PI);
|
||||
XMStoreFloat4(&result, Q);
|
||||
}
|
||||
else
|
||||
{
|
||||
XMVECTOR C = XMVector3Cross(F, T);
|
||||
const XMVECTOR C = XMVector3Cross(F, T);
|
||||
XMStoreFloat4(&result, C);
|
||||
|
||||
float s = sqrtf((1.f + dot) * 2.f);
|
||||
const float s = sqrtf((1.f + dot) * 2.f);
|
||||
result.x /= s;
|
||||
result.y /= s;
|
||||
result.z /= s;
|
||||
|
@ -127,7 +127,7 @@ void Quaternion::LookRotation(const Vector3& forward, const Vector3& up, Quatern
|
|||
Quaternion q1;
|
||||
FromToRotation(Vector3::Forward, forward, q1);
|
||||
|
||||
XMVECTOR C = XMVector3Cross(forward, up);
|
||||
const XMVECTOR C = XMVector3Cross(forward, up);
|
||||
if (XMVector3NearEqual(XMVector3LengthSq(C), g_XMZero, g_XMEpsilon))
|
||||
{
|
||||
// forward and up are co-linear
|
||||
|
@ -135,7 +135,7 @@ void Quaternion::LookRotation(const Vector3& forward, const Vector3& up, Quatern
|
|||
return;
|
||||
}
|
||||
|
||||
XMVECTOR U = XMQuaternionMultiply(q1, Vector3::Up);
|
||||
const XMVECTOR U = XMQuaternionMultiply(q1, Vector3::Up);
|
||||
|
||||
Quaternion q2;
|
||||
FromToRotation(U, up, q2);
|
||||
|
@ -190,7 +190,7 @@ RECT Viewport::ComputeDisplayArea(DXGI_SCALING scaling, UINT backBufferWidth, UI
|
|||
// Note: This scaling option is not supported for legacy Win32 windows swap chains
|
||||
{
|
||||
assert(backBufferHeight > 0);
|
||||
float aspectRatio = float(backBufferWidth) / float(backBufferHeight);
|
||||
const float aspectRatio = float(backBufferWidth) / float(backBufferHeight);
|
||||
|
||||
// Horizontal fill
|
||||
float scaledWidth = float(outputWidth);
|
||||
|
@ -202,8 +202,8 @@ RECT Viewport::ComputeDisplayArea(DXGI_SCALING scaling, UINT backBufferWidth, UI
|
|||
scaledHeight = float(outputHeight);
|
||||
}
|
||||
|
||||
float offsetX = (float(outputWidth) - scaledWidth) * 0.5f;
|
||||
float offsetY = (float(outputHeight) - scaledHeight) * 0.5f;
|
||||
const float offsetX = (float(outputWidth) - scaledWidth) * 0.5f;
|
||||
const float offsetY = (float(outputHeight) - scaledHeight) * 0.5f;
|
||||
|
||||
rct.left = static_cast<LONG>(offsetX);
|
||||
rct.top = static_cast<LONG>(offsetY);
|
||||
|
@ -234,8 +234,8 @@ RECT Viewport::ComputeDisplayArea(DXGI_SCALING scaling, UINT backBufferWidth, UI
|
|||
|
||||
RECT Viewport::ComputeTitleSafeArea(UINT backBufferWidth, UINT backBufferHeight) noexcept
|
||||
{
|
||||
float safew = (float(backBufferWidth) + 19.f) / 20.f;
|
||||
float safeh = (float(backBufferHeight) + 19.f) / 20.f;
|
||||
const float safew = (float(backBufferWidth) + 19.f) / 20.f;
|
||||
const float safeh = (float(backBufferHeight) + 19.f) / 20.f;
|
||||
|
||||
RECT rct;
|
||||
rct.left = static_cast<LONG>(safew);
|
||||
|
|
|
@ -69,7 +69,7 @@ public:
|
|||
_In_opt_ ID3D11SamplerState* samplerState,
|
||||
_In_opt_ ID3D11DepthStencilState* depthStencilState,
|
||||
_In_opt_ ID3D11RasterizerState* rasterizerState,
|
||||
std::function<void()>& setCustomShaders,
|
||||
const std::function<void()>& setCustomShaders,
|
||||
FXMMATRIX transformMatrix);
|
||||
void End();
|
||||
|
||||
|
@ -297,7 +297,7 @@ std::vector<short> SpriteBatch::Impl::DeviceResources::CreateIndexValues()
|
|||
|
||||
for (size_t j = 0; j < MaxBatchSize * VerticesPerSprite; j += VerticesPerSprite)
|
||||
{
|
||||
short i = static_cast<short>(j);
|
||||
const short i = static_cast<short>(j);
|
||||
|
||||
indices.push_back(i);
|
||||
indices.push_back(i + 1);
|
||||
|
@ -389,7 +389,7 @@ void XM_CALLCONV SpriteBatch::Impl::Begin(SpriteSortMode sortMode,
|
|||
ID3D11SamplerState* samplerState,
|
||||
ID3D11DepthStencilState* depthStencilState,
|
||||
ID3D11RasterizerState* rasterizerState,
|
||||
std::function<void()>& setCustomShaders,
|
||||
const std::function<void()>& setCustomShaders,
|
||||
FXMMATRIX transformMatrix)
|
||||
{
|
||||
if (mInBeginEndPair)
|
||||
|
@ -475,7 +475,7 @@ void XM_CALLCONV SpriteBatch::Impl::Draw(ID3D11ShaderResourceView* texture,
|
|||
if (sourceRectangle)
|
||||
{
|
||||
// User specified an explicit source region.
|
||||
XMVECTOR source = LoadRect(sourceRectangle);
|
||||
const XMVECTOR source = LoadRect(sourceRectangle);
|
||||
|
||||
XMStoreFloat4A(&sprite->source, source);
|
||||
|
||||
|
@ -529,7 +529,7 @@ void XM_CALLCONV SpriteBatch::Impl::Draw(ID3D11ShaderResourceView* texture,
|
|||
void SpriteBatch::Impl::GrowSpriteQueue()
|
||||
{
|
||||
// Grow by a factor of 2.
|
||||
size_t newSize = std::max(InitialQueueSize, mSpriteQueueArraySize * 2);
|
||||
const size_t newSize = std::max(InitialQueueSize, mSpriteQueueArraySize * 2);
|
||||
|
||||
// Allocate the new array.
|
||||
auto newArray = std::make_unique<SpriteInfo[]>(newSize);
|
||||
|
@ -574,8 +574,8 @@ void SpriteBatch::Impl::PrepareForRendering()
|
|||
// Set the vertex and index buffer.
|
||||
#if !defined(_XBOX_ONE) || !defined(_TITLE)
|
||||
auto vertexBuffer = mContextResources->vertexBuffer.Get();
|
||||
UINT vertexStride = sizeof(VertexPositionColorTexture);
|
||||
UINT vertexOffset = 0;
|
||||
constexpr UINT vertexStride = sizeof(VertexPositionColorTexture);
|
||||
constexpr UINT vertexOffset = 0;
|
||||
|
||||
deviceContext->IASetVertexBuffers(0, 1, &vertexBuffer, &vertexStride, &vertexOffset);
|
||||
#endif
|
||||
|
@ -583,7 +583,7 @@ void SpriteBatch::Impl::PrepareForRendering()
|
|||
deviceContext->IASetIndexBuffer(mDeviceResources->indexBuffer.Get(), DXGI_FORMAT_R16_UINT, 0);
|
||||
|
||||
// Set the transform matrix.
|
||||
XMMATRIX transformMatrix = (mRotation == DXGI_MODE_ROTATION_UNSPECIFIED)
|
||||
const XMMATRIX transformMatrix = (mRotation == DXGI_MODE_ROTATION_UNSPECIFIED)
|
||||
? mTransformMatrix
|
||||
: (mTransformMatrix * GetViewportTransform(deviceContext, mRotation));
|
||||
|
||||
|
@ -709,7 +709,7 @@ void SpriteBatch::Impl::SortSprites()
|
|||
// Populates the mSortedSprites vector with pointers to individual elements of the mSpriteQueue array.
|
||||
void SpriteBatch::Impl::GrowSortedSprites()
|
||||
{
|
||||
size_t previousSize = mSortedSprites.size();
|
||||
const size_t previousSize = mSortedSprites.size();
|
||||
|
||||
mSortedSprites.resize(mSpriteQueueCount);
|
||||
|
||||
|
@ -729,8 +729,8 @@ void SpriteBatch::Impl::RenderBatch(ID3D11ShaderResourceView* texture, SpriteInf
|
|||
// Draw using the specified texture.
|
||||
deviceContext->PSSetShaderResources(0, 1, &texture);
|
||||
|
||||
XMVECTOR textureSize = GetTextureSize(texture);
|
||||
XMVECTOR inverseTextureSize = XMVectorReciprocal(textureSize);
|
||||
const XMVECTOR textureSize = GetTextureSize(texture);
|
||||
const XMVECTOR inverseTextureSize = XMVectorReciprocal(textureSize);
|
||||
|
||||
while (count > 0)
|
||||
{
|
||||
|
@ -738,7 +738,7 @@ void SpriteBatch::Impl::RenderBatch(ID3D11ShaderResourceView* texture, SpriteInf
|
|||
size_t batchSize = count;
|
||||
|
||||
// How many sprites does the D3D vertex buffer have room for?
|
||||
size_t remainingSpace = MaxBatchSize - mContextResources->vertexBufferPosition;
|
||||
const size_t remainingSpace = MaxBatchSize - mContextResources->vertexBufferPosition;
|
||||
|
||||
if (batchSize > remainingSpace)
|
||||
{
|
||||
|
@ -762,7 +762,7 @@ void SpriteBatch::Impl::RenderBatch(ID3D11ShaderResourceView* texture, SpriteInf
|
|||
auto vertices = static_cast<VertexPositionColorTexture*>(grfxMemory);
|
||||
#else
|
||||
// Lock the vertex buffer.
|
||||
D3D11_MAP mapType = (mContextResources->vertexBufferPosition == 0) ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE_NO_OVERWRITE;
|
||||
const D3D11_MAP mapType = (mContextResources->vertexBufferPosition == 0) ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE_NO_OVERWRITE;
|
||||
|
||||
D3D11_MAPPED_SUBRESOURCE mappedBuffer;
|
||||
|
||||
|
@ -790,8 +790,8 @@ void SpriteBatch::Impl::RenderBatch(ID3D11ShaderResourceView* texture, SpriteInf
|
|||
#endif
|
||||
|
||||
// Ok lads, the time has come for us draw ourselves some sprites!
|
||||
auto startIndex = static_cast<UINT>(mContextResources->vertexBufferPosition * IndicesPerSprite);
|
||||
auto indexCount = static_cast<UINT>(batchSize * IndicesPerSprite);
|
||||
auto const startIndex = static_cast<UINT>(mContextResources->vertexBufferPosition * IndicesPerSprite);
|
||||
auto const indexCount = static_cast<UINT>(batchSize * IndicesPerSprite);
|
||||
|
||||
deviceContext->DrawIndexed(indexCount, startIndex, 0);
|
||||
|
||||
|
@ -815,20 +815,20 @@ void XM_CALLCONV SpriteBatch::Impl::RenderSprite(SpriteInfo const* sprite,
|
|||
{
|
||||
// Load sprite parameters into SIMD registers.
|
||||
XMVECTOR source = XMLoadFloat4A(&sprite->source);
|
||||
XMVECTOR destination = XMLoadFloat4A(&sprite->destination);
|
||||
XMVECTOR color = XMLoadFloat4A(&sprite->color);
|
||||
XMVECTOR originRotationDepth = XMLoadFloat4A(&sprite->originRotationDepth);
|
||||
const XMVECTOR destination = XMLoadFloat4A(&sprite->destination);
|
||||
const XMVECTOR color = XMLoadFloat4A(&sprite->color);
|
||||
const XMVECTOR originRotationDepth = XMLoadFloat4A(&sprite->originRotationDepth);
|
||||
|
||||
float rotation = sprite->originRotationDepth.z;
|
||||
unsigned int flags = sprite->flags;
|
||||
const float rotation = sprite->originRotationDepth.z;
|
||||
const unsigned int flags = sprite->flags;
|
||||
|
||||
// Extract the source and destination sizes into separate vectors.
|
||||
XMVECTOR sourceSize = XMVectorSwizzle<2, 3, 2, 3>(source);
|
||||
XMVECTOR destinationSize = XMVectorSwizzle<2, 3, 2, 3>(destination);
|
||||
|
||||
// Scale the origin offset by source size, taking care to avoid overflow if the source region is zero.
|
||||
XMVECTOR isZeroMask = XMVectorEqual(sourceSize, XMVectorZero());
|
||||
XMVECTOR nonZeroSourceSize = XMVectorSelect(sourceSize, g_XMEpsilon, isZeroMask);
|
||||
const XMVECTOR isZeroMask = XMVectorEqual(sourceSize, XMVectorZero());
|
||||
const XMVECTOR nonZeroSourceSize = XMVectorSelect(sourceSize, g_XMEpsilon, isZeroMask);
|
||||
|
||||
XMVECTOR origin = XMVectorDivide(originRotationDepth, nonZeroSourceSize);
|
||||
|
||||
|
@ -859,8 +859,8 @@ void XM_CALLCONV SpriteBatch::Impl::RenderSprite(SpriteInfo const* sprite,
|
|||
|
||||
XMScalarSinCos(&sin, &cos, rotation);
|
||||
|
||||
XMVECTOR sinV = XMLoadFloat(&sin);
|
||||
XMVECTOR cosV = XMLoadFloat(&cos);
|
||||
const XMVECTOR sinV = XMLoadFloat(&sin);
|
||||
const XMVECTOR cosV = XMLoadFloat(&cos);
|
||||
|
||||
rotationMatrix1 = XMVectorMergeXY(cosV, sinV);
|
||||
rotationMatrix2 = XMVectorMergeXY(XMVectorNegate(sinV), cosV);
|
||||
|
@ -896,14 +896,14 @@ void XM_CALLCONV SpriteBatch::Impl::RenderSprite(SpriteInfo const* sprite,
|
|||
for (size_t i = 0; i < VerticesPerSprite; i++)
|
||||
{
|
||||
// Calculate position.
|
||||
XMVECTOR cornerOffset = XMVectorMultiply(XMVectorSubtract(cornerOffsets[i], origin), destinationSize);
|
||||
const XMVECTOR cornerOffset = XMVectorMultiply(XMVectorSubtract(cornerOffsets[i], origin), destinationSize);
|
||||
|
||||
// Apply 2x2 rotation matrix.
|
||||
XMVECTOR position1 = XMVectorMultiplyAdd(XMVectorSplatX(cornerOffset), rotationMatrix1, destination);
|
||||
XMVECTOR position2 = XMVectorMultiplyAdd(XMVectorSplatY(cornerOffset), rotationMatrix2, position1);
|
||||
const XMVECTOR position1 = XMVectorMultiplyAdd(XMVectorSplatX(cornerOffset), rotationMatrix1, destination);
|
||||
const XMVECTOR position2 = XMVectorMultiplyAdd(XMVectorSplatY(cornerOffset), rotationMatrix2, position1);
|
||||
|
||||
// Set z = depth.
|
||||
XMVECTOR position = XMVectorPermute<0, 1, 7, 6>(position2, originRotationDepth);
|
||||
const XMVECTOR position = XMVectorPermute<0, 1, 7, 6>(position2, originRotationDepth);
|
||||
|
||||
// Write position as a Float4, even though VertexPositionColor::position is an XMFLOAT3.
|
||||
// This is faster, and harmless as we are just clobbering the first element of the
|
||||
|
@ -914,7 +914,7 @@ void XM_CALLCONV SpriteBatch::Impl::RenderSprite(SpriteInfo const* sprite,
|
|||
XMStoreFloat4(&vertices[i].color, color);
|
||||
|
||||
// Compute and write the texture coordinate.
|
||||
XMVECTOR textureCoordinate = XMVectorMultiplyAdd(cornerOffsets[static_cast<unsigned int>(i) ^ mirrorBits], sourceSize, source);
|
||||
const XMVECTOR textureCoordinate = XMVectorMultiplyAdd(cornerOffsets[static_cast<unsigned int>(i) ^ mirrorBits], sourceSize, source);
|
||||
|
||||
XMStoreFloat2(&vertices[i].textureCoordinate, textureCoordinate);
|
||||
}
|
||||
|
@ -943,8 +943,9 @@ XMVECTOR SpriteBatch::Impl::GetTextureSize(_In_ ID3D11ShaderResourceView* textur
|
|||
texture2D->GetDesc(&desc);
|
||||
|
||||
// Convert to vector format.
|
||||
XMVECTOR size = XMVectorMergeXY(XMLoadInt(&desc.Width),
|
||||
XMLoadInt(&desc.Height));
|
||||
const XMVECTOR size = XMVectorMergeXY(
|
||||
XMLoadInt(&desc.Width),
|
||||
XMLoadInt(&desc.Height));
|
||||
|
||||
return XMConvertVectorUIntToFloat(size, 0);
|
||||
}
|
||||
|
@ -965,8 +966,8 @@ XMMATRIX SpriteBatch::Impl::GetViewportTransform(_In_ ID3D11DeviceContext* devic
|
|||
}
|
||||
|
||||
// Compute the matrix.
|
||||
float xScale = (mViewPort.Width > 0) ? 2.0f / mViewPort.Width : 0.0f;
|
||||
float yScale = (mViewPort.Height > 0) ? 2.0f / mViewPort.Height : 0.0f;
|
||||
const float xScale = (mViewPort.Width > 0) ? 2.0f / mViewPort.Width : 0.0f;
|
||||
const float yScale = (mViewPort.Height > 0) ? 2.0f / mViewPort.Height : 0.0f;
|
||||
|
||||
switch (rotation)
|
||||
{
|
||||
|
@ -1043,7 +1044,7 @@ void SpriteBatch::End()
|
|||
_Use_decl_annotations_
|
||||
void XM_CALLCONV SpriteBatch::Draw(ID3D11ShaderResourceView* texture, XMFLOAT2 const& position, FXMVECTOR color)
|
||||
{
|
||||
XMVECTOR destination = XMVectorPermute<0, 1, 4, 5>(XMLoadFloat2(&position), g_XMOne); // x, y, 1, 1
|
||||
const XMVECTOR destination = XMVectorPermute<0, 1, 4, 5>(XMLoadFloat2(&position), g_XMOne); // x, y, 1, 1
|
||||
|
||||
pImpl->Draw(texture, destination, nullptr, color, g_XMZero, 0);
|
||||
}
|
||||
|
@ -1060,9 +1061,9 @@ void XM_CALLCONV SpriteBatch::Draw(ID3D11ShaderResourceView* texture,
|
|||
SpriteEffects effects,
|
||||
float layerDepth)
|
||||
{
|
||||
XMVECTOR destination = XMVectorPermute<0, 1, 4, 4>(XMLoadFloat2(&position), XMLoadFloat(&scale)); // x, y, scale, scale
|
||||
const XMVECTOR destination = XMVectorPermute<0, 1, 4, 4>(XMLoadFloat2(&position), XMLoadFloat(&scale)); // x, y, scale, scale
|
||||
|
||||
XMVECTOR originRotationDepth = XMVectorSet(origin.x, origin.y, rotation, layerDepth);
|
||||
const XMVECTOR originRotationDepth = XMVectorSet(origin.x, origin.y, rotation, layerDepth);
|
||||
|
||||
pImpl->Draw(texture, destination, sourceRectangle, color, originRotationDepth, static_cast<unsigned int>(effects));
|
||||
}
|
||||
|
@ -1079,9 +1080,9 @@ void XM_CALLCONV SpriteBatch::Draw(ID3D11ShaderResourceView* texture,
|
|||
SpriteEffects effects,
|
||||
float layerDepth)
|
||||
{
|
||||
XMVECTOR destination = XMVectorPermute<0, 1, 4, 5>(XMLoadFloat2(&position), XMLoadFloat2(&scale)); // x, y, scale.x, scale.y
|
||||
const XMVECTOR destination = XMVectorPermute<0, 1, 4, 5>(XMLoadFloat2(&position), XMLoadFloat2(&scale)); // x, y, scale.x, scale.y
|
||||
|
||||
XMVECTOR originRotationDepth = XMVectorSet(origin.x, origin.y, rotation, layerDepth);
|
||||
const XMVECTOR originRotationDepth = XMVectorSet(origin.x, origin.y, rotation, layerDepth);
|
||||
|
||||
pImpl->Draw(texture, destination, sourceRectangle, color, originRotationDepth, static_cast<unsigned int>(effects));
|
||||
}
|
||||
|
@ -1090,7 +1091,7 @@ void XM_CALLCONV SpriteBatch::Draw(ID3D11ShaderResourceView* texture,
|
|||
_Use_decl_annotations_
|
||||
void XM_CALLCONV SpriteBatch::Draw(ID3D11ShaderResourceView* texture, FXMVECTOR position, FXMVECTOR color)
|
||||
{
|
||||
XMVECTOR destination = XMVectorPermute<0, 1, 4, 5>(position, g_XMOne); // x, y, 1, 1
|
||||
const XMVECTOR destination = XMVectorPermute<0, 1, 4, 5>(position, g_XMOne); // x, y, 1, 1
|
||||
|
||||
pImpl->Draw(texture, destination, nullptr, color, g_XMZero, 0);
|
||||
}
|
||||
|
@ -1107,11 +1108,11 @@ void XM_CALLCONV SpriteBatch::Draw(ID3D11ShaderResourceView* texture,
|
|||
SpriteEffects effects,
|
||||
float layerDepth)
|
||||
{
|
||||
XMVECTOR destination = XMVectorPermute<0, 1, 4, 4>(position, XMLoadFloat(&scale)); // x, y, scale, scale
|
||||
const XMVECTOR destination = XMVectorPermute<0, 1, 4, 4>(position, XMLoadFloat(&scale)); // x, y, scale, scale
|
||||
|
||||
XMVECTOR rotationDepth = XMVectorMergeXY(XMVectorReplicate(rotation), XMVectorReplicate(layerDepth));
|
||||
const XMVECTOR rotationDepth = XMVectorMergeXY(XMVectorReplicate(rotation), XMVectorReplicate(layerDepth));
|
||||
|
||||
XMVECTOR originRotationDepth = XMVectorPermute<0, 1, 4, 5>(origin, rotationDepth);
|
||||
const XMVECTOR originRotationDepth = XMVectorPermute<0, 1, 4, 5>(origin, rotationDepth);
|
||||
|
||||
pImpl->Draw(texture, destination, sourceRectangle, color, originRotationDepth, static_cast<unsigned int>(effects));
|
||||
}
|
||||
|
@ -1128,11 +1129,11 @@ void XM_CALLCONV SpriteBatch::Draw(ID3D11ShaderResourceView* texture,
|
|||
SpriteEffects effects,
|
||||
float layerDepth)
|
||||
{
|
||||
XMVECTOR destination = XMVectorPermute<0, 1, 4, 5>(position, scale); // x, y, scale.x, scale.y
|
||||
const XMVECTOR destination = XMVectorPermute<0, 1, 4, 5>(position, scale); // x, y, scale.x, scale.y
|
||||
|
||||
XMVECTOR rotationDepth = XMVectorMergeXY(XMVectorReplicate(rotation), XMVectorReplicate(layerDepth));
|
||||
const XMVECTOR rotationDepth = XMVectorMergeXY(XMVectorReplicate(rotation), XMVectorReplicate(layerDepth));
|
||||
|
||||
XMVECTOR originRotationDepth = XMVectorPermute<0, 1, 4, 5>(origin, rotationDepth);
|
||||
const XMVECTOR originRotationDepth = XMVectorPermute<0, 1, 4, 5>(origin, rotationDepth);
|
||||
|
||||
pImpl->Draw(texture, destination, sourceRectangle, color, originRotationDepth, static_cast<unsigned int>(effects));
|
||||
}
|
||||
|
@ -1141,7 +1142,7 @@ void XM_CALLCONV SpriteBatch::Draw(ID3D11ShaderResourceView* texture,
|
|||
_Use_decl_annotations_
|
||||
void XM_CALLCONV SpriteBatch::Draw(ID3D11ShaderResourceView* texture, RECT const& destinationRectangle, FXMVECTOR color)
|
||||
{
|
||||
XMVECTOR destination = LoadRect(&destinationRectangle); // x, y, w, h
|
||||
const XMVECTOR destination = LoadRect(&destinationRectangle); // x, y, w, h
|
||||
|
||||
pImpl->Draw(texture, destination, nullptr, color, g_XMZero, Impl::SpriteInfo::DestSizeInPixels);
|
||||
}
|
||||
|
@ -1157,9 +1158,9 @@ void XM_CALLCONV SpriteBatch::Draw(ID3D11ShaderResourceView* texture,
|
|||
SpriteEffects effects,
|
||||
float layerDepth)
|
||||
{
|
||||
XMVECTOR destination = LoadRect(&destinationRectangle); // x, y, w, h
|
||||
const XMVECTOR destination = LoadRect(&destinationRectangle); // x, y, w, h
|
||||
|
||||
XMVECTOR originRotationDepth = XMVectorSet(origin.x, origin.y, rotation, layerDepth);
|
||||
const XMVECTOR originRotationDepth = XMVectorSet(origin.x, origin.y, rotation, layerDepth);
|
||||
|
||||
pImpl->Draw(texture, destination, sourceRectangle, color, originRotationDepth, static_cast<unsigned int>(effects) | Impl::SpriteInfo::DestSizeInPixels);
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ SpriteFont::Impl::Impl(
|
|||
auto textureStride = reader->Read<uint32_t>();
|
||||
auto textureRows = reader->Read<uint32_t>();
|
||||
|
||||
uint64_t dataSize = uint64_t(textureStride) * uint64_t(textureRows);
|
||||
const uint64_t dataSize = uint64_t(textureStride) * uint64_t(textureRows);
|
||||
if (dataSize > UINT32_MAX)
|
||||
{
|
||||
DebugTrace("ERROR: SpriteFont provided with an invalid .spritefont file\n");
|
||||
|
@ -251,7 +251,7 @@ void SpriteFont::Impl::ForEachGlyph(_In_z_ wchar_t const* text, TAction action,
|
|||
|
||||
for (; *text; text++)
|
||||
{
|
||||
wchar_t character = *text;
|
||||
const wchar_t character = *text;
|
||||
|
||||
switch (character)
|
||||
{
|
||||
|
@ -274,7 +274,7 @@ void SpriteFont::Impl::ForEachGlyph(_In_z_ wchar_t const* text, TAction action,
|
|||
if (x < 0)
|
||||
x = 0;
|
||||
|
||||
float advance = float(glyph->Subrect.right) - float(glyph->Subrect.left) + glyph->XAdvance;
|
||||
const float advance = float(glyph->Subrect.right) - float(glyph->Subrect.left) + glyph->XAdvance;
|
||||
|
||||
if (!ignoreWhitespace
|
||||
|| !iswspace(character)
|
||||
|
@ -299,7 +299,7 @@ void SpriteFont::Impl::CreateTextureResource(
|
|||
uint32_t stride, uint32_t rows,
|
||||
const uint8_t* data) noexcept(false)
|
||||
{
|
||||
uint64_t sliceBytes = uint64_t(stride) * uint64_t(rows);
|
||||
const uint64_t sliceBytes = uint64_t(stride) * uint64_t(rows);
|
||||
if (sliceBytes > UINT32_MAX)
|
||||
{
|
||||
DebugTrace("ERROR: SpriteFont provided with an invalid .spritefont file\n");
|
||||
|
@ -480,7 +480,7 @@ XMVECTOR XM_CALLCONV SpriteFont::MeasureString(_In_z_ wchar_t const* text, bool
|
|||
{
|
||||
UNREFERENCED_PARAMETER(advance);
|
||||
|
||||
auto w = static_cast<float>(glyph->Subrect.right - glyph->Subrect.left);
|
||||
auto const w = static_cast<float>(glyph->Subrect.right - glyph->Subrect.left);
|
||||
auto h = static_cast<float>(glyph->Subrect.bottom - glyph->Subrect.top) + glyph->YOffset;
|
||||
|
||||
h = iswspace(wchar_t(glyph->Character)) ?
|
||||
|
@ -500,17 +500,17 @@ RECT SpriteFont::MeasureDrawBounds(_In_z_ wchar_t const* text, XMFLOAT2 const& p
|
|||
|
||||
pImpl->ForEachGlyph(text, [&](Glyph const* glyph, float x, float y, float advance) noexcept
|
||||
{
|
||||
auto isWhitespace = iswspace(wchar_t(glyph->Character));
|
||||
auto w = static_cast<float>(glyph->Subrect.right - glyph->Subrect.left);
|
||||
auto h = isWhitespace ?
|
||||
auto const isWhitespace = iswspace(wchar_t(glyph->Character));
|
||||
auto const w = static_cast<float>(glyph->Subrect.right - glyph->Subrect.left);
|
||||
auto const h = isWhitespace ?
|
||||
pImpl->lineSpacing :
|
||||
static_cast<float>(glyph->Subrect.bottom - glyph->Subrect.top);
|
||||
|
||||
float minX = position.x + x;
|
||||
float minY = position.y + y + (isWhitespace ? 0.0f : glyph->YOffset);
|
||||
const float minX = position.x + x;
|
||||
const float minY = position.y + y + (isWhitespace ? 0.0f : glyph->YOffset);
|
||||
|
||||
float maxX = std::max(minX + advance, minX + w);
|
||||
float maxY = minY + h;
|
||||
const float maxX = std::max(minX + advance, minX + w);
|
||||
const float maxY = minY + h;
|
||||
|
||||
if (minX < float(result.left))
|
||||
result.left = long(minX);
|
||||
|
|
|
@ -242,7 +242,7 @@ class ToneMapPostProcess::Impl : public AlignedNew<ToneMapConstants>
|
|||
public:
|
||||
explicit Impl(_In_ ID3D11Device* device);
|
||||
|
||||
void Process(_In_ ID3D11DeviceContext* deviceContext, std::function<void __cdecl()>& setCustomState);
|
||||
void Process(_In_ ID3D11DeviceContext* deviceContext, const std::function<void __cdecl()>& setCustomState);
|
||||
|
||||
void SetDirtyFlag() noexcept { mDirtyFlags = INT_MAX; }
|
||||
|
||||
|
@ -300,7 +300,7 @@ ToneMapPostProcess::Impl::Impl(_In_ ID3D11Device* device)
|
|||
// Sets our state onto the D3D device.
|
||||
void ToneMapPostProcess::Impl::Process(
|
||||
_In_ ID3D11DeviceContext* deviceContext,
|
||||
std::function<void __cdecl()>& setCustomState)
|
||||
const std::function<void __cdecl()>& setCustomState)
|
||||
{
|
||||
// Set the texture.
|
||||
ID3D11ShaderResourceView* textures[1] = { hdrTexture.Get() };
|
||||
|
@ -447,7 +447,7 @@ void ToneMapPostProcess::SetColorRotation(ColorPrimaryRotation value)
|
|||
|
||||
void ToneMapPostProcess::SetColorRotation(CXMMATRIX value)
|
||||
{
|
||||
XMMATRIX transpose = XMMatrixTranspose(value);
|
||||
const XMMATRIX transpose = XMMatrixTranspose(value);
|
||||
pImpl->constants.colorRotation[0] = transpose.r[0];
|
||||
pImpl->constants.colorRotation[1] = transpose.r[1];
|
||||
pImpl->constants.colorRotation[2] = transpose.r[2];
|
||||
|
|
|
@ -333,7 +333,7 @@ namespace
|
|||
}
|
||||
else if (width > maxsize || height > maxsize)
|
||||
{
|
||||
float ar = static_cast<float>(height) / static_cast<float>(width);
|
||||
const float ar = static_cast<float>(height) / static_cast<float>(width);
|
||||
if (width > height)
|
||||
{
|
||||
twidth = static_cast<UINT>(maxsize);
|
||||
|
@ -530,14 +530,14 @@ namespace
|
|||
}
|
||||
|
||||
// Allocate temporary memory for image
|
||||
uint64_t rowBytes = (uint64_t(twidth) * uint64_t(bpp) + 7u) / 8u;
|
||||
uint64_t numBytes = rowBytes * uint64_t(theight);
|
||||
const uint64_t rowBytes = (uint64_t(twidth) * uint64_t(bpp) + 7u) / 8u;
|
||||
const uint64_t numBytes = rowBytes * uint64_t(theight);
|
||||
|
||||
if (rowBytes > UINT32_MAX || numBytes > UINT32_MAX)
|
||||
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
|
||||
|
||||
auto rowPitch = static_cast<size_t>(rowBytes);
|
||||
auto imageSize = static_cast<size_t>(numBytes);
|
||||
auto const rowPitch = static_cast<size_t>(rowBytes);
|
||||
auto const imageSize = static_cast<size_t>(numBytes);
|
||||
|
||||
std::unique_ptr<uint8_t[]> temp(new (std::nothrow) uint8_t[imageSize]);
|
||||
if (!temp)
|
||||
|
@ -762,7 +762,7 @@ namespace
|
|||
}
|
||||
#else
|
||||
CHAR strFileA[MAX_PATH];
|
||||
int result = WideCharToMultiByte(CP_UTF8,
|
||||
const int result = WideCharToMultiByte(CP_UTF8,
|
||||
WC_NO_BEST_FIT_CHARS,
|
||||
fileName,
|
||||
-1,
|
||||
|
|
Загрузка…
Ссылка в новой задаче