| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- /************************************************************************************
- Filename : Util_Direct3D.cpp
- Content : Shared code for Direct3D
- Created : Oct 14, 2014
- Authors : Chris Taylor
- Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
- Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
- you may not use the Oculus VR Rift SDK except in compliance with the License,
- which is provided at the time of installation or download, or which
- otherwise accompanies this software in either electronic or hard copy form.
- You may obtain a copy of the License at
- http://www.oculusvr.com/licenses/LICENSE-3.2
- Unless required by applicable law or agreed to in writing, the Oculus VR SDK
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- ************************************************************************************/
- #include "Util_Direct3D.h"
- #include "Kernel/OVR_Log.h"
- namespace OVR { namespace D3DUtil {
- bool VerifyHRESULT(const char* file, int line, HRESULT hr)
- {
- if (FAILED(hr))
- {
- LogError("D3D function returned fail HRESULT at %s on line %d : %s",
- file, line, D3DUtil::GetWindowsErrorString(hr).ToCStr());
- OVR_ASSERT(false);
- return false;
- }
- return true;
- }
- String GetWindowsErrorString(HRESULT hr)
- {
- wchar_t errorTextAddr[256] = {};
- DWORD slen = FormatMessageW(
- // use system message tables to retrieve error text
- FORMAT_MESSAGE_FROM_SYSTEM
- // allocate buffer on local heap for error text
- | FORMAT_MESSAGE_ALLOCATE_BUFFER
- // Important! will fail otherwise, since we're not
- // (and CANNOT) pass insertion parameters
- | FORMAT_MESSAGE_IGNORE_INSERTS,
- nullptr, // unused with FORMAT_MESSAGE_FROM_SYSTEM
- hr,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- errorTextAddr, // output
- 256, // minimum size for output buffer
- nullptr); // arguments - see note
- char errorText[256];
- OVR::UTF8Util::Strlcpy(errorTextAddr, OVR_ARRAY_COUNT(errorTextAddr), errorText, 256);
- char formatStr[512];
- OVR_snprintf(formatStr, sizeof(formatStr), "[Code=%x = %d]", hr, hr);
- String retStr = formatStr;
- if (slen > 0 && errorText)
- {
- retStr += " ";
- retStr += errorText;
- // release memory allocated by FormatMessage()
- LocalFree(errorText);
- }
- return retStr;
- }
- void LogD3DCompileError(HRESULT hr, ID3DBlob* blob)
- {
- if (FAILED(hr))
- {
- char* errStr = (char*)blob->GetBufferPointer();
- SIZE_T len = blob->GetBufferSize();
- if (errStr && len > 0)
- {
- LogError("Error compiling shader: %s", errStr);
- }
- }
- }
- }} // namespace OVR::D3DUtil
|