diff --git a/.gitmodules b/.gitmodules index e2393907..d51c6d4d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,7 @@ +[submodule "external/eigen"] + path = external/eigen + url = https://gitlab.com/libeigen/eigen.git + branch = 3.2.10 [submodule "external/mLib"] path = external/mLib - url = https://github.com/niessner/mLib.git + url = https://github.com/ybh1998/mLib.git diff --git a/FriedLiver/CompiledShaders/PhongLighting.hlsl.PhongPS.p b/FriedLiver/CompiledShaders/PhongLighting.hlsl.PhongPS.p deleted file mode 100644 index 0e153ba1..00000000 Binary files a/FriedLiver/CompiledShaders/PhongLighting.hlsl.PhongPS.p and /dev/null differ diff --git a/FriedLiver/CompiledShaders/QuadDrawer.hlsl.QuadFloatPS.p b/FriedLiver/CompiledShaders/QuadDrawer.hlsl.QuadFloatPS.p deleted file mode 100644 index 32833664..00000000 Binary files a/FriedLiver/CompiledShaders/QuadDrawer.hlsl.QuadFloatPS.p and /dev/null differ diff --git a/FriedLiver/CompiledShaders/QuadDrawer.hlsl.QuadRGBAPS.p b/FriedLiver/CompiledShaders/QuadDrawer.hlsl.QuadRGBAPS.p deleted file mode 100644 index 31298d26..00000000 Binary files a/FriedLiver/CompiledShaders/QuadDrawer.hlsl.QuadRGBAPS.p and /dev/null differ diff --git a/FriedLiver/CompiledShaders/QuadDrawer.hlsl.QuadVS.p b/FriedLiver/CompiledShaders/QuadDrawer.hlsl.QuadVS.p deleted file mode 100644 index 7a1a3195..00000000 Binary files a/FriedLiver/CompiledShaders/QuadDrawer.hlsl.QuadVS.p and /dev/null differ diff --git a/FriedLiver/CompiledShaders/RGBDRenderer.hlsl.EmptyVS.p b/FriedLiver/CompiledShaders/RGBDRenderer.hlsl.EmptyVS.p deleted file mode 100644 index 2bf11c88..00000000 Binary files a/FriedLiver/CompiledShaders/RGBDRenderer.hlsl.EmptyVS.p and /dev/null differ diff --git a/FriedLiver/CompiledShaders/RGBDRenderer.hlsl.RGBDRendererGS.p b/FriedLiver/CompiledShaders/RGBDRenderer.hlsl.RGBDRendererGS.p deleted file mode 100644 index c5b96dc5..00000000 Binary files a/FriedLiver/CompiledShaders/RGBDRenderer.hlsl.RGBDRendererGS.p and /dev/null differ diff --git a/FriedLiver/CompiledShaders/RGBDRenderer.hlsl.RGBDRendererRawDepthPS.p b/FriedLiver/CompiledShaders/RGBDRenderer.hlsl.RGBDRendererRawDepthPS.p deleted file mode 100644 index f307903c..00000000 Binary files a/FriedLiver/CompiledShaders/RGBDRenderer.hlsl.RGBDRendererRawDepthPS.p and /dev/null differ diff --git a/FriedLiver/CompiledShaders/RayIntervalSplatting.hlsl.PS.p b/FriedLiver/CompiledShaders/RayIntervalSplatting.hlsl.PS.p deleted file mode 100644 index 70c0004f..00000000 Binary files a/FriedLiver/CompiledShaders/RayIntervalSplatting.hlsl.PS.p and /dev/null differ diff --git a/FriedLiver/CompiledShaders/RayIntervalSplatting.hlsl.VS.p b/FriedLiver/CompiledShaders/RayIntervalSplatting.hlsl.VS.p deleted file mode 100644 index ef2970a2..00000000 Binary files a/FriedLiver/CompiledShaders/RayIntervalSplatting.hlsl.VS.p and /dev/null differ diff --git a/FriedLiver/FriedLiver.vcxproj b/FriedLiver/FriedLiver.vcxproj index 4db5bef5..a77f0467 100644 --- a/FriedLiver/FriedLiver.vcxproj +++ b/FriedLiver/FriedLiver.vcxproj @@ -15,25 +15,24 @@ Win32Proj DepthWithColor.D3D FriedLiver - 10.0.16299.0 + 10.0.17763.0 Application true Unicode - v141 + v142 Application - false true Unicode - v141 + v142 - + @@ -44,17 +43,15 @@ true - $(WindowsSDK_ExecutablePath_x86);$(WindowsSDK_ExecutablePath_x64);$(ExecutablePath) - $(IncludePath);$(WindowsSDK_IncludePath);$(KINECTSDK10_DIR)\inc;$(KINECTSDK20_DIR)\inc;$(OPENNI2_INCLUDE64);$(DXSDK_DIR)Include;./Source/;./Source/SiftGPU/;./Include;./Include/Intel;./Include/cutil/inc;./Include/Uplink;../external/mlib/include;../../mlibExternal/include - $(LibraryPath);$(DXSDK_DIR)Lib\x64;$(KINECTSDK10_DIR)\lib\amd64;$(CUDA_LIB_PATH);$(KINECTSDK20_DIR)\lib\x64;$(OPENNI2_LIB64);Libs;../../mlibExternal/libsWindows/lib64 + $(WindowsSDK_ExecutablePath_x64);$(ExecutablePath) + $(IncludePath);$(WindowsSDK_IncludePath);$(KINECTSDK10_DIR)\inc;$(KINECTSDK20_DIR)\inc;$(OPENNI2_INCLUDE64);./Source/;./Source/SiftGPU/;./Include;./Include/Intel;./Include/cutil/inc;./Include/Uplink;../external/mlib/include;../external/eigen;../../mlibExternal/include + $(LibraryPath);$(KINECTSDK10_DIR)\lib\amd64;$(CUDA_LIB_PATH);$(KINECTSDK20_DIR)\lib\x64;$(OPENNI2_LIB64);Libs;../../mlibExternal/libsWindows/lib64 $(VC_SourcePath); false - $(DXSDK_DIR)Utilities\bin\x64;$(DXSDK_DIR)Utilities\bin\x86;$(ExecutablePath) - $(IncludePath);$(WindowsSDK_IncludePath);$(KINECTSDK10_DIR)\inc;$(KINECTSDK20_DIR)\inc;$(OPENNI2_INCLUDE64);$(DXSDK_DIR)Include;./Source/;./Source/SiftGPU/;./Include;./Include/Intel;./Include/cutil/inc;./Include/Uplink;../external/mlib/include;../../mlibExternal/include - $(LibraryPath);$(DXSDK_DIR)Lib\x64;$(KINECTSDK10_DIR)\lib\amd64;$(CUDA_LIB_PATH);$(KINECTSDK20_DIR)\lib\x64;$(OPENNI2_LIB64);Libs;../../mlibExternal/libsWindows/lib64 - $(VC_SourcePath); + $(IncludePath);$(WindowsSDK_IncludePath);$(KINECTSDK10_DIR)\inc;$(KINECTSDK20_DIR)\inc;$(OPENNI2_INCLUDE64);./Source/;./Source/SiftGPU/;./Include;./Include/Intel;./Include/cutil/inc;./Include/Uplink;../external/mlib/include;../external/eigen;../../mlibExternal/include + $(LibraryPath);$(KINECTSDK10_DIR)\lib\amd64;$(CUDA_LIB_PATH);$(KINECTSDK20_DIR)\lib\x64;$(OPENNI2_LIB64);Libs;../../mlibExternal/libsWindows/lib64 @@ -92,10 +89,7 @@ - Level3 - MaxSpeed MultiThreaded - false true true Fast @@ -402,6 +396,6 @@ - + \ No newline at end of file diff --git a/FriedLiver/FriedLiver.vcxproj.user b/FriedLiver/FriedLiver.vcxproj.user deleted file mode 100644 index be250787..00000000 --- a/FriedLiver/FriedLiver.vcxproj.user +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/FriedLiver/Source/BinaryDumpReader.cpp b/FriedLiver/Source/BinaryDumpReader.cpp index 1c6f32f8..798ff82c 100644 --- a/FriedLiver/Source/BinaryDumpReader.cpp +++ b/FriedLiver/Source/BinaryDumpReader.cpp @@ -128,12 +128,14 @@ bool BinaryDumpReader::processDepth() if(GlobalAppState::get().s_playData) { float* depth = getDepthFloat(); + vec4uc color; memcpy(depth, m_data.m_DepthImages[m_CurrFrame], sizeof(float)*getDepthWidth()*getDepthHeight()); incrementRingbufIdx(); if (m_bHasColorData) { - memcpy(m_colorRGBX, m_data.m_ColorImages[m_CurrFrame], sizeof(vec4uc)*getColorWidth()*getColorHeight()); + memcpy(&color, m_data.m_ColorImages[m_CurrFrame], sizeof(vec4uc)*getColorWidth()*getColorHeight()); + *m_colorRGBX = color / 255.0f; } m_CurrFrame++; diff --git a/FriedLiver/Source/Bundler.cpp b/FriedLiver/Source/Bundler.cpp index 8d0f892c..0de39da6 100644 --- a/FriedLiver/Source/Bundler.cpp +++ b/FriedLiver/Source/Bundler.cpp @@ -276,7 +276,7 @@ bool Bundler::optimize(unsigned int numNonLinIterations, unsigned int numLinIter return ret; } -void Bundler::storeCachedFrame(unsigned int depthWidth, unsigned int depthHeight, const uchar4* d_inputColor, unsigned int colorWidth, unsigned int colorHeight, const float* d_inputDepthRaw) +void Bundler::storeCachedFrame(unsigned int depthWidth, unsigned int depthHeight, const float4* d_inputColor, unsigned int colorWidth, unsigned int colorHeight, const float* d_inputDepthRaw) { m_cudaCache->storeFrame(d_inputDepthRaw, depthWidth, depthHeight, d_inputColor, colorWidth, colorHeight); } diff --git a/FriedLiver/Source/Bundler.h b/FriedLiver/Source/Bundler.h index 5273dec7..040ab4f8 100644 --- a/FriedLiver/Source/Bundler.h +++ b/FriedLiver/Source/Bundler.h @@ -36,7 +36,7 @@ class Bundler //TODO should this live outside? void detectFeatures(float* d_intensitySift, const float* d_inputDepthFilt); - void storeCachedFrame(unsigned int depthWidth, unsigned int depthHeight, const uchar4* d_inputColor, + void storeCachedFrame(unsigned int depthWidth, unsigned int depthHeight, const float4* d_inputColor, unsigned int colorWidth, unsigned int colorHeight, const float* d_inputDepthRaw); void copyFrame(const Bundler* b, unsigned int frame); void addInvalidFrame(); diff --git a/FriedLiver/Source/CUDACache.cpp b/FriedLiver/Source/CUDACache.cpp index c9cda93a..506fabe8 100644 --- a/FriedLiver/Source/CUDACache.cpp +++ b/FriedLiver/Source/CUDACache.cpp @@ -43,7 +43,7 @@ CUDACache::CUDACache(unsigned int widthDepthInput, unsigned int heightDepthInput void CUDACache::storeFrame(const float* d_depth, unsigned int inputDepthWidth, unsigned int inputDepthHeight, - const uchar4* d_color, unsigned int inputColorWidth, unsigned int inputColorHeight) + const float4* d_color, unsigned int inputColorWidth, unsigned int inputColorHeight) { CUDACachedFrame& frame = m_cache[m_currentFrame]; //depth diff --git a/FriedLiver/Source/CUDACache.h b/FriedLiver/Source/CUDACache.h index e7606655..37bc8c32 100644 --- a/FriedLiver/Source/CUDACache.h +++ b/FriedLiver/Source/CUDACache.h @@ -12,7 +12,7 @@ class CUDACache { } void storeFrame(const float* d_depth, unsigned int inputDepthWidth, unsigned int inputDepthHeight, - const uchar4* d_color, unsigned int inputColorWidth, unsigned int inputColorHeight); + const float4* d_color, unsigned int inputColorWidth, unsigned int inputColorHeight); void reset() { m_currentFrame = 0; @@ -23,7 +23,7 @@ class CUDACache { void copyCacheFrameFrom(CUDACache* other, unsigned int frameFrom) { MLIB_CUDA_SAFE_CALL(cudaMemcpy(m_cache[m_currentFrame].d_depthDownsampled, other->m_cache[frameFrom].d_depthDownsampled, sizeof(float) * m_width * m_height, cudaMemcpyDeviceToDevice)); - //MLIB_CUDA_SAFE_CALL(cudaMemcpy(m_cache[m_currentFrame].d_colorDownsampled, other->m_cache[frameFrom].d_colorDownsampled, sizeof(uchar4) * m_width * m_height, cudaMemcpyDeviceToDevice)); + //MLIB_CUDA_SAFE_CALL(cudaMemcpy(m_cache[m_currentFrame].d_colorDownsampled, other->m_cache[frameFrom].d_colorDownsampled, sizeof(float4) * m_width * m_height, cudaMemcpyDeviceToDevice)); MLIB_CUDA_SAFE_CALL(cudaMemcpy(m_cache[m_currentFrame].d_cameraposDownsampled, other->m_cache[frameFrom].d_cameraposDownsampled, sizeof(float4) * m_width * m_height, cudaMemcpyDeviceToDevice)); MLIB_CUDA_SAFE_CALL(cudaMemcpy(m_cache[m_currentFrame].d_intensityDownsampled, other->m_cache[frameFrom].d_intensityDownsampled, sizeof(float) * m_width * m_height, cudaMemcpyDeviceToDevice)); @@ -72,7 +72,7 @@ class CUDACache { const CUDACachedFrame& f = m_cache[i]; MLIB_CUDA_SAFE_CALL(cudaMemcpy(depth.getData(), f.d_depthDownsampled, sizeof(float)*depth.getNumPixels(), cudaMemcpyDeviceToHost)); MLIB_CUDA_SAFE_CALL(cudaMemcpy(camPos.getData(), f.d_cameraposDownsampled, sizeof(float4)*camPos.getNumPixels(), cudaMemcpyDeviceToHost)); - //MLIB_CUDA_SAFE_CALL(cudaMemcpy(color.getData(), f.d_colorDownsampled, sizeof(uchar4)*color.getNumPixels(), cudaMemcpyDeviceToHost)); + //MLIB_CUDA_SAFE_CALL(cudaMemcpy(color.getData(), f.d_colorDownsampled, sizeof(float4)*color.getNumPixels(), cudaMemcpyDeviceToHost)); MLIB_CUDA_SAFE_CALL(cudaMemcpy(intensity.getData(), f.d_intensityDownsampled, sizeof(float)*intensity.getNumPixels(), cudaMemcpyDeviceToHost)); MLIB_CUDA_SAFE_CALL(cudaMemcpy(intensityDerivative.getData(), f.d_intensityDerivsDownsampled, sizeof(float2)*intensityDerivative.getNumPixels(), cudaMemcpyDeviceToHost)); #ifdef CUDACACHE_UCHAR_NORMALS @@ -128,7 +128,7 @@ class CUDACache { s >> intensityOrig; MLIB_CUDA_SAFE_CALL(cudaMemcpy(f.d_depthDownsampled, depth.getData(), sizeof(float)*depth.getNumPixels(), cudaMemcpyHostToDevice)); MLIB_CUDA_SAFE_CALL(cudaMemcpy(f.d_cameraposDownsampled, camPos.getData(), sizeof(float4)*camPos.getNumPixels(), cudaMemcpyHostToDevice)); - //MLIB_CUDA_SAFE_CALL(cudaMemcpy(f.d_colorDownsampled, color.getData(), sizeof(uchar4)*color.getNumPixels(), cudaMemcpyHostToDevice)); + //MLIB_CUDA_SAFE_CALL(cudaMemcpy(f.d_colorDownsampled, color.getData(), sizeof(float4)*color.getNumPixels(), cudaMemcpyHostToDevice)); MLIB_CUDA_SAFE_CALL(cudaMemcpy(f.d_intensityDownsampled, intensity.getData(), sizeof(float)*intensity.getNumPixels(), cudaMemcpyHostToDevice)); MLIB_CUDA_SAFE_CALL(cudaMemcpy(f.d_intensityDerivsDownsampled, intensityDerivative.getData(), sizeof(float2)*intensityDerivative.getNumPixels(), cudaMemcpyHostToDevice)); #ifdef CUDACACHE_UCHAR_NORMALS @@ -182,7 +182,7 @@ class CUDACache { MLIB_ASSERT(cachedFrames.size() <= m_cache.size()); for (unsigned int i = 0; i < cachedFrames.size(); i++) { MLIB_CUDA_SAFE_CALL(cudaMemcpy(m_cache[i].d_depthDownsampled, cachedFrames[i].d_depthDownsampled, sizeof(float) * m_width * m_height, cudaMemcpyDeviceToDevice)); - //MLIB_CUDA_SAFE_CALL(cudaMemcpy(m_cache[i].d_colorDownsampled, cachedFrames[i].d_colorDownsampled, sizeof(uchar4) * m_width * m_height, cudaMemcpyDeviceToDevice)); + //MLIB_CUDA_SAFE_CALL(cudaMemcpy(m_cache[i].d_colorDownsampled, cachedFrames[i].d_colorDownsampled, sizeof(float4) * m_width * m_height, cudaMemcpyDeviceToDevice)); MLIB_CUDA_SAFE_CALL(cudaMemcpy(m_cache[i].d_cameraposDownsampled, cachedFrames[i].d_cameraposDownsampled, sizeof(float4) * m_width * m_height, cudaMemcpyDeviceToDevice)); MLIB_CUDA_SAFE_CALL(cudaMemcpy(m_cache[i].d_intensityDownsampled, cachedFrames[i].d_intensityDownsampled, sizeof(float) * m_width * m_height, cudaMemcpyDeviceToDevice)); diff --git a/FriedLiver/Source/CUDAImageManager.cpp b/FriedLiver/Source/CUDAImageManager.cpp index fd9b6e14..53e4cdc3 100644 --- a/FriedLiver/Source/CUDAImageManager.cpp +++ b/FriedLiver/Source/CUDAImageManager.cpp @@ -9,7 +9,7 @@ unsigned int CUDAImageManager::ManagedRGBDInputFrame::s_width = 0; unsigned int CUDAImageManager::ManagedRGBDInputFrame::s_height = 0; float* CUDAImageManager::ManagedRGBDInputFrame::s_depthIntegrationGlobal = NULL; -uchar4* CUDAImageManager::ManagedRGBDInputFrame::s_colorIntegrationGlobal = NULL; +float4* CUDAImageManager::ManagedRGBDInputFrame::s_colorIntegrationGlobal = NULL; CUDAImageManager::ManagedRGBDInputFrame* CUDAImageManager::ManagedRGBDInputFrame::s_activeColorGPU = NULL; CUDAImageManager::ManagedRGBDInputFrame* CUDAImageManager::ManagedRGBDInputFrame::s_activeDepthGPU = NULL; @@ -39,24 +39,23 @@ bool CUDAImageManager::process() //////////////////////////////////////////////////////////////////////////////////// const unsigned int bufferDimColorInput = m_RGBDSensor->getColorWidth()*m_RGBDSensor->getColorHeight(); - MLIB_CUDA_SAFE_CALL(cudaMemcpy(d_colorInput, m_RGBDSensor->getColorRGBX(), sizeof(uchar4)*bufferDimColorInput, cudaMemcpyHostToDevice)); - + MLIB_CUDA_SAFE_CALL(cudaMemcpy(d_colorInput, m_RGBDSensor->getColorRGBX(), sizeof(float4)*bufferDimColorInput, cudaMemcpyHostToDevice)); if ((m_RGBDSensor->getColorWidth() == m_widthIntegration) && (m_RGBDSensor->getColorHeight() == m_heightIntegration)) { if (ManagedRGBDInputFrame::s_bIsOnGPU) { - CUDAImageUtil::copy(frame.m_colorIntegration, d_colorInput, m_widthIntegration, m_heightIntegration); + CUDAImageUtil::copy(frame.m_colorIntegration, d_colorInput, m_widthIntegration, m_heightIntegration); //std::swap(frame.m_colorIntegration, d_colorInput); } else { - memcpy(frame.m_colorIntegration, m_RGBDSensor->getColorRGBX(), sizeof(uchar4)*bufferDimColorInput); + memcpy(frame.m_colorIntegration, m_RGBDSensor->getColorRGBX(), sizeof(float4)*bufferDimColorInput); } } else { if (ManagedRGBDInputFrame::s_bIsOnGPU) { - CUDAImageUtil::resampleUCHAR4(frame.m_colorIntegration, m_widthIntegration, m_heightIntegration, d_colorInput, m_RGBDSensor->getColorWidth(), m_RGBDSensor->getColorHeight()); + CUDAImageUtil::resampleFloat4(frame.m_colorIntegration, m_widthIntegration, m_heightIntegration, d_colorInput, m_RGBDSensor->getColorWidth(), m_RGBDSensor->getColorHeight()); } else { - CUDAImageUtil::resampleUCHAR4(frame.s_colorIntegrationGlobal, m_widthIntegration, m_heightIntegration, d_colorInput, m_RGBDSensor->getColorWidth(), m_RGBDSensor->getColorHeight()); - MLIB_CUDA_SAFE_CALL(cudaMemcpy(frame.m_colorIntegration, frame.s_colorIntegrationGlobal, sizeof(uchar4)*m_widthIntegration*m_heightIntegration, cudaMemcpyDeviceToHost)); + CUDAImageUtil::resampleFloat4(frame.s_colorIntegrationGlobal, m_widthIntegration, m_heightIntegration, d_colorInput, m_RGBDSensor->getColorWidth(), m_RGBDSensor->getColorHeight()); + MLIB_CUDA_SAFE_CALL(cudaMemcpy(frame.m_colorIntegration, frame.s_colorIntegrationGlobal, sizeof(float4)*m_widthIntegration*m_heightIntegration, cudaMemcpyDeviceToHost)); frame.s_activeColorGPU = &frame; } } @@ -67,7 +66,6 @@ bool CUDAImageManager::process() const unsigned int bufferDimDepthInput = m_RGBDSensor->getDepthWidth()*m_RGBDSensor->getDepthHeight(); MLIB_CUDA_SAFE_CALL(cudaMemcpy(d_depthInputRaw, m_RGBDSensor->getDepthFloat(), sizeof(float)*m_RGBDSensor->getDepthWidth()* m_RGBDSensor->getDepthHeight(), cudaMemcpyHostToDevice)); - //////////////////////////////////////////////////////////////////////////////////// // Render to Color Space //////////////////////////////////////////////////////////////////////////////////// @@ -152,7 +150,6 @@ bool CUDAImageManager::process() //CUDAImageUtil::resampleToIntensity(d_intensitySIFT, m_widthSIFT, m_heightSIFT, d_colorInput, m_RGBDSensor->getColorWidth(), m_RGBDSensor->getColorHeight()); if (GlobalBundlingState::get().s_enableGlobalTimings) { cudaDeviceSynchronize(); s_timer.stop(); TimingLog::getFrameTiming(true).timeSensorProcess = s_timer.getElapsedTimeMS(); } - m_currFrame++; return true; } diff --git a/FriedLiver/Source/CUDAImageManager.h b/FriedLiver/Source/CUDAImageManager.h index e7561c94..3fe1ade7 100644 --- a/FriedLiver/Source/CUDAImageManager.h +++ b/FriedLiver/Source/CUDAImageManager.h @@ -24,11 +24,11 @@ class CUDAImageManager { if (!s_bIsOnGPU) { MLIB_CUDA_SAFE_CALL(cudaMalloc(&s_depthIntegrationGlobal, sizeof(float)*width*height)); - MLIB_CUDA_SAFE_CALL(cudaMalloc(&s_colorIntegrationGlobal, sizeof(uchar4)*width*height)); + MLIB_CUDA_SAFE_CALL(cudaMalloc(&s_colorIntegrationGlobal, sizeof(float4)*width*height)); } else { s_depthIntegrationGlobal = new float[width*height]; - s_colorIntegrationGlobal = new uchar4[width*height]; + s_colorIntegrationGlobal = new float4[width*height]; } } static void globalFree() @@ -47,11 +47,11 @@ class CUDAImageManager { void alloc() { if (s_bIsOnGPU) { MLIB_CUDA_SAFE_CALL(cudaMalloc(&m_depthIntegration, sizeof(float)*s_width*s_height)); - MLIB_CUDA_SAFE_CALL(cudaMalloc(&m_colorIntegration, sizeof(uchar4)*s_width*s_height)); + MLIB_CUDA_SAFE_CALL(cudaMalloc(&m_colorIntegration, sizeof(float4)*s_width*s_height)); } else { m_depthIntegration = new float[s_width*s_height]; - m_colorIntegration = new uchar4[s_width*s_height]; + m_colorIntegration = new float4[s_width*s_height]; } } @@ -80,13 +80,13 @@ class CUDAImageManager { return s_depthIntegrationGlobal; } } - const uchar4* getColorFrameGPU() { //be aware that only one depth frame is globally valid at a time + const float4* getColorFrameGPU() { //be aware that only one depth frame is globally valid at a time if (s_bIsOnGPU) { return m_colorIntegration; } else { if (this != s_activeColorGPU) { - MLIB_CUDA_SAFE_CALL(cudaMemcpy(s_colorIntegrationGlobal, m_colorIntegration, sizeof(uchar4)*s_width*s_height, cudaMemcpyHostToDevice)); + MLIB_CUDA_SAFE_CALL(cudaMemcpy(s_colorIntegrationGlobal, m_colorIntegration, sizeof(float4)*s_width*s_height, cudaMemcpyHostToDevice)); s_activeColorGPU = this; } return s_colorIntegrationGlobal; @@ -105,10 +105,10 @@ class CUDAImageManager { return m_depthIntegration; } } - const uchar4* getColorFrameCPU() { + const float4* getColorFrameCPU() { if (s_bIsOnGPU) { if (this != s_activeColorCPU) { - MLIB_CUDA_SAFE_CALL(cudaMemcpy(s_colorIntegrationGlobal, m_colorIntegration, sizeof(uchar4)*s_width*s_height, cudaMemcpyDeviceToHost)); + MLIB_CUDA_SAFE_CALL(cudaMemcpy(s_colorIntegrationGlobal, m_colorIntegration, sizeof(float4)*s_width*s_height, cudaMemcpyDeviceToHost)); s_activeDepthCPU = this; } return s_colorIntegrationGlobal; @@ -120,19 +120,19 @@ class CUDAImageManager { private: float* m_depthIntegration; //either on the GPU or CPU - uchar4* m_colorIntegration; //either on the GPU or CPU + float4* m_colorIntegration; //either on the GPU or CPU static bool s_bIsOnGPU; static unsigned int s_width; static unsigned int s_height; static float* s_depthIntegrationGlobal; - static uchar4* s_colorIntegrationGlobal; + static float4* s_colorIntegrationGlobal; static ManagedRGBDInputFrame* s_activeColorGPU; static ManagedRGBDInputFrame* s_activeDepthGPU; static float* s_depthIntegrationGlobalCPU; - static uchar4* s_colorIntegrationGlobalCPU; + static float4* s_colorIntegrationGlobalCPU; static ManagedRGBDInputFrame* s_activeColorCPU; static ManagedRGBDInputFrame* s_activeDepthCPU; }; @@ -151,7 +151,7 @@ class CUDAImageManager { MLIB_CUDA_SAFE_CALL(cudaMalloc(&d_depthInputRaw, sizeof(float)*bufferDimDepthInput)); MLIB_CUDA_SAFE_CALL(cudaMalloc(&d_depthInputFiltered, sizeof(float)*bufferDimDepthInput)); - MLIB_CUDA_SAFE_CALL(cudaMalloc(&d_colorInput, sizeof(uchar4)*bufferDimColorInput)); + MLIB_CUDA_SAFE_CALL(cudaMalloc(&d_colorInput, sizeof(float4)*bufferDimColorInput)); m_currFrame = 0; @@ -220,10 +220,10 @@ class CUDAImageManager { bool process(); - void copyToBundling(float* d_depthRaw, float* d_depthFilt, uchar4* d_color) const { + void copyToBundling(float* d_depthRaw, float* d_depthFilt, float4* d_color) const { MLIB_CUDA_SAFE_CALL(cudaMemcpy(d_depthRaw, d_depthInputRaw, sizeof(float)*m_RGBDSensor->getDepthWidth()* m_RGBDSensor->getDepthHeight(), cudaMemcpyDeviceToDevice)); MLIB_CUDA_SAFE_CALL(cudaMemcpy(d_depthFilt, d_depthInputFiltered, sizeof(float)*m_RGBDSensor->getDepthWidth()* m_RGBDSensor->getDepthHeight(), cudaMemcpyDeviceToDevice)); - MLIB_CUDA_SAFE_CALL(cudaMemcpy(d_color, d_colorInput, sizeof(uchar4)*m_RGBDSensor->getColorWidth()*m_RGBDSensor->getColorHeight(), cudaMemcpyDeviceToDevice)); + MLIB_CUDA_SAFE_CALL(cudaMemcpy(d_color, d_colorInput, sizeof(float4)*m_RGBDSensor->getColorWidth()*m_RGBDSensor->getColorHeight(), cudaMemcpyDeviceToDevice)); } @@ -323,7 +323,7 @@ class CUDAImageManager { //! temporary GPU storage for inputting the current frame float* d_depthInputRaw; - uchar4* d_colorInput; + float4* d_colorInput; float* d_depthInputFiltered; unsigned int m_widthSIFTdepth; diff --git a/FriedLiver/Source/CUDAImageUtil.cu b/FriedLiver/Source/CUDAImageUtil.cu index 76505b57..db58cf90 100644 --- a/FriedLiver/Source/CUDAImageUtil.cu +++ b/FriedLiver/Source/CUDAImageUtil.cu @@ -193,9 +193,14 @@ void CUDAImageUtil::resampleUCHAR4(uchar4* d_output, unsigned int outputWidth, u // Color to Intensity //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +__host__ __device__ +float convertToIntensity(const float4& c) { + return (0.299f * c.x + 0.587f * c.y + 0.114f * c.z); +} + __host__ __device__ float convertToIntensity(const uchar4& c) { - return (0.299f*c.x + 0.587f*c.y + 0.114f*c.z) / 255.0f; + return (0.299f * c.x + 0.587f * c.y + 0.114f * c.z) / 255.0f; } __global__ void convertUCHAR4ToIntensityFloat_Kernel(float* d_output, const uchar4* d_input, unsigned int width, unsigned int height) @@ -221,7 +226,7 @@ void CUDAImageUtil::convertUCHAR4ToIntensityFloat(float* d_output, const uchar4* #endif } -__global__ void resampleToIntensity_Kernel(float* d_output, unsigned int outputWidth, unsigned int outputHeight, const uchar4* d_input, unsigned int inputWidth, unsigned int inputHeight) +__global__ void resampleToIntensity_Kernel(float* d_output, unsigned int outputWidth, unsigned int outputHeight, const float4* d_input, unsigned int inputWidth, unsigned int inputHeight) { const unsigned int x = blockIdx.x*blockDim.x + threadIdx.x; const unsigned int y = blockIdx.y*blockDim.y + threadIdx.y; @@ -240,7 +245,7 @@ __global__ void resampleToIntensity_Kernel(float* d_output, unsigned int outputW } } -void CUDAImageUtil::resampleToIntensity(float* d_output, unsigned int outputWidth, unsigned int outputHeight, const uchar4* d_input, unsigned int inputWidth, unsigned int inputHeight) { +void CUDAImageUtil::resampleToIntensity(float* d_output, unsigned int outputWidth, unsigned int outputHeight, const float4* d_input, unsigned int inputWidth, unsigned int inputHeight) { const dim3 gridSize((outputWidth + T_PER_BLOCK - 1) / T_PER_BLOCK, (outputHeight + T_PER_BLOCK - 1) / T_PER_BLOCK); const dim3 blockSize(T_PER_BLOCK, T_PER_BLOCK); diff --git a/FriedLiver/Source/CUDAImageUtil.h b/FriedLiver/Source/CUDAImageUtil.h index ab0ea887..8656feb4 100644 --- a/FriedLiver/Source/CUDAImageUtil.h +++ b/FriedLiver/Source/CUDAImageUtil.h @@ -9,7 +9,7 @@ class CUDAImageUtil { public: template static void copy(T* d_output, T* d_input, unsigned int width, unsigned int height); //template static void resample(T* d_output, unsigned int outputWidth, unsigned int outputHeight, T* d_input, unsigned int inputWidth, unsigned int inputHeight); - static void resampleToIntensity(float* d_output, unsigned int outputWidth, unsigned int outputHeight, const uchar4* d_input, unsigned int inputWidth, unsigned int inputHeight); + static void resampleToIntensity(float* d_output, unsigned int outputWidth, unsigned int outputHeight, const float4* d_input, unsigned int inputWidth, unsigned int inputHeight); static void resampleFloat4(float4* d_output, unsigned int outputWidth, unsigned int outputHeight, const float4* d_input, unsigned int inputWidth, unsigned int inputHeight); static void resampleFloat(float* d_output, unsigned int outputWidth, unsigned int outputHeight, const float* d_input, unsigned int inputWidth, unsigned int inputHeight); @@ -48,6 +48,7 @@ class CUDAImageUtil { //TODO template void CUDAImageUtil::copy(float*, float*, unsigned int, unsigned int); template void CUDAImageUtil::copy(uchar4*, uchar4*, unsigned int, unsigned int); +template void CUDAImageUtil::copy(float4*, float4*, unsigned int, unsigned int); //template void CUDAImageUtil::resample(float*, unsigned int, unsigned int, float*, unsigned int, unsigned int); //template void CUDAImageUtil::resample(uchar4*, unsigned int, unsigned int, uchar4*, unsigned int, unsigned int); diff --git a/FriedLiver/Source/DXUT/.editorconfig b/FriedLiver/Source/DXUT/.editorconfig new file mode 100644 index 00000000..6a8f10a3 --- /dev/null +++ b/FriedLiver/Source/DXUT/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*.{cpp,h}] +indent_size = 4 +indent_style = space +trim_trailing_whitespace = true +insert_final_newline = true +end_of_line = crlf +charset = latin1 diff --git a/FriedLiver/Source/DXUT/.gitattributes b/FriedLiver/Source/DXUT/.gitattributes new file mode 100644 index 00000000..efb4018e --- /dev/null +++ b/FriedLiver/Source/DXUT/.gitattributes @@ -0,0 +1,19 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Explicitly declare code/VS files as CRLF +*.cpp eol=crlf +*.h eol=crlf +*.hlsl eol=crlf +*.hlsli eol=crlf +*.fx eol=crlf +*.fxh eol=crlf +*.inc eol=crlf +*.vcxproj eol=crlf +*.filters eol=crlf +*.sln eol=crlf +*.props eol=crlf + +# Explicitly declare resource files as binary +*.pdb binary +*.dds binary diff --git a/FriedLiver/Source/DXUT/.gitignore b/FriedLiver/Source/DXUT/.gitignore new file mode 100644 index 00000000..80d9abb6 --- /dev/null +++ b/FriedLiver/Source/DXUT/.gitignore @@ -0,0 +1,22 @@ +*.psess +*.vsp +*.log +*.err +*.wrn +*.suo +*.sdf +*.user +*.i +*.vspscc +*.opensdf +*.opendb +*.ipch +*.cache +*.tlog +*.lastbuildstate +*.ilk +*.VC.db +.vs +/ipch +Bin +/wiki diff --git a/FriedLiver/Source/DXUT/Core/DDSTextureLoader.cpp b/FriedLiver/Source/DXUT/Core/DDSTextureLoader.cpp index fad01411..df19b4af 100644 --- a/FriedLiver/Source/DXUT/Core/DDSTextureLoader.cpp +++ b/FriedLiver/Source/DXUT/Core/DDSTextureLoader.cpp @@ -67,7 +67,6 @@ struct DDS_PIXELFORMAT #define DDS_HEADER_FLAGS_VOLUME 0x00800000 // DDSD_DEPTH #define DDS_HEIGHT 0x00000002 // DDSD_HEIGHT -#define DDS_WIDTH 0x00000004 // DDSD_WIDTH #define DDS_CUBEMAP_POSITIVEX 0x00000600 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEX #define DDS_CUBEMAP_NEGATIVEX 0x00000a00 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX @@ -136,6 +135,71 @@ namespace #endif } + //-------------------------------------------------------------------------------------- + HRESULT LoadTextureDataFromMemory( + _In_reads_(ddsDataSize) const uint8_t* ddsData, + size_t ddsDataSize, + const DDS_HEADER** header, + const uint8_t** bitData, + size_t* bitSize) + { + if (!header || !bitData || !bitSize) + { + return E_POINTER; + } + + if (ddsDataSize > UINT32_MAX) + { + return E_FAIL; + } + + if (ddsDataSize < (sizeof(uint32_t) + sizeof(DDS_HEADER))) + { + return E_FAIL; + } + + // DDS files always start with the same magic number ("DDS ") + auto dwMagicNumber = *reinterpret_cast(ddsData); + if (dwMagicNumber != DDS_MAGIC) + { + return E_FAIL; + } + + auto hdr = reinterpret_cast(ddsData + sizeof(uint32_t)); + + // Verify header to validate DDS file + if (hdr->size != sizeof(DDS_HEADER) || + hdr->ddspf.size != sizeof(DDS_PIXELFORMAT)) + { + return E_FAIL; + } + + // Check for DX10 extension + bool bDXT10Header = false; + if ((hdr->ddspf.flags & DDS_FOURCC) && + (MAKEFOURCC('D', 'X', '1', '0') == hdr->ddspf.fourCC)) + { + // Must be long enough for both headers and magic value + if (ddsDataSize < (sizeof(DDS_HEADER) + sizeof(uint32_t) + sizeof(DDS_HEADER_DXT10))) + { + return E_FAIL; + } + + bDXT10Header = true; + } + + // setup the pointers in the process request + *header = hdr; + auto offset = sizeof(uint32_t) + + sizeof(DDS_HEADER) + + (bDXT10Header ? sizeof(DDS_HEADER_DXT10) : 0); + *bitData = ddsData + offset; + *bitSize = ddsDataSize - offset; + + return S_OK; + } + + //-------------------------------------------------------------------------------------- HRESULT LoadTextureDataFromFile( _In_z_ const wchar_t* fileName, @@ -185,7 +249,7 @@ namespace } // Need at least enough data to fill the header and magic number to be a valid DDS - if (fileInfo.EndOfFile.LowPart < (sizeof(DDS_HEADER) + sizeof(uint32_t))) + if (fileInfo.EndOfFile.LowPart < (sizeof(uint32_t) + sizeof(DDS_HEADER))) { return E_FAIL; } @@ -215,7 +279,7 @@ namespace } // DDS files always start with the same magic number ("DDS ") - uint32_t dwMagicNumber = *reinterpret_cast(ddsData.get()); + auto dwMagicNumber = *reinterpret_cast(ddsData.get()); if (dwMagicNumber != DDS_MAGIC) { return E_FAIL; @@ -246,7 +310,7 @@ namespace // setup the pointers in the process request *header = hdr; - ptrdiff_t offset = sizeof(uint32_t) + sizeof(DDS_HEADER) + auto offset = sizeof(uint32_t) + sizeof(DDS_HEADER) + (bDXT10Header ? sizeof(DDS_HEADER_DXT10) : 0); *bitData = ddsData.get() + offset; *bitSize = fileInfo.EndOfFile.LowPart - offset; @@ -408,7 +472,7 @@ namespace //-------------------------------------------------------------------------------------- // Get surface information for a particular format //-------------------------------------------------------------------------------------- - void GetSurfaceInfo( + HRESULT GetSurfaceInfo( _In_ size_t width, _In_ size_t height, _In_ DXGI_FORMAT fmt, @@ -416,9 +480,9 @@ namespace _Out_opt_ size_t* outRowBytes, _Out_opt_ size_t* outNumRows) { - size_t numBytes = 0; - size_t rowBytes = 0; - size_t numRows = 0; + uint64_t numBytes = 0; + uint64_t rowBytes = 0; + uint64_t numRows = 0; bool bc = false; bool packed = false; @@ -479,19 +543,22 @@ namespace planar = true; bpe = 4; break; + + default: + break; } if (bc) { - size_t numBlocksWide = 0; + uint64_t numBlocksWide = 0; if (width > 0) { - numBlocksWide = std::max(1, (width + 3) / 4); + numBlocksWide = std::max(1u, (uint64_t(width) + 3u) / 4u); } - size_t numBlocksHigh = 0; + uint64_t numBlocksHigh = 0; if (height > 0) { - numBlocksHigh = std::max(1, (height + 3) / 4); + numBlocksHigh = std::max(1u, (uint64_t(height) + 3u) / 4u); } rowBytes = numBlocksWide * bpe; numRows = numBlocksHigh; @@ -499,42 +566,55 @@ namespace } else if (packed) { - rowBytes = ((width + 1) >> 1) * bpe; - numRows = height; + rowBytes = ((uint64_t(width) + 1u) >> 1) * bpe; + numRows = uint64_t(height); numBytes = rowBytes * height; } else if (fmt == DXGI_FORMAT_NV11) { - rowBytes = ((width + 3) >> 2) * 4; - numRows = height * 2; // Direct3D makes this simplifying assumption, although it is larger than the 4:1:1 data + rowBytes = ((uint64_t(width) + 3u) >> 2) * 4u; + numRows = uint64_t(height) * 2u; // Direct3D makes this simplifying assumption, although it is larger than the 4:1:1 data numBytes = rowBytes * numRows; } else if (planar) { - rowBytes = ((width + 1) >> 1) * bpe; - numBytes = (rowBytes * height) + ((rowBytes * height + 1) >> 1); - numRows = height + ((height + 1) >> 1); + rowBytes = ((uint64_t(width) + 1u) >> 1) * bpe; + numBytes = (rowBytes * uint64_t(height)) + ((rowBytes * uint64_t(height) + 1u) >> 1); + numRows = height + ((uint64_t(height) + 1u) >> 1); } else { size_t bpp = BitsPerPixel(fmt); - rowBytes = (width * bpp + 7) / 8; // round up to nearest byte - numRows = height; + if (!bpp) + return E_INVALIDARG; + + rowBytes = (uint64_t(width) * bpp + 7u) / 8u; // round up to nearest byte + numRows = uint64_t(height); numBytes = rowBytes * height; } +#if defined(_M_IX86) || defined(_M_ARM) || defined(_M_HYBRID_X86_ARM64) + static_assert(sizeof(size_t) == 4, "Not a 32-bit platform!"); + if (numBytes > UINT32_MAX || rowBytes > UINT32_MAX || numRows > UINT32_MAX) + return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); +#else + static_assert(sizeof(size_t) == 8, "Not a 64-bit platform!"); +#endif + if (outNumBytes) { - *outNumBytes = numBytes; + *outNumBytes = static_cast(numBytes); } if (outRowBytes) { - *outRowBytes = rowBytes; + *outRowBytes = static_cast(rowBytes); } if (outNumRows) { - *outNumRows = numRows; + *outNumRows = static_cast(numRows); } + + return S_OK; } @@ -853,13 +933,12 @@ namespace size_t d = depth; for (size_t i = 0; i < mipCount; i++) { - GetSurfaceInfo(w, - h, - format, - &NumBytes, - &RowBytes, - nullptr - ); + HRESULT hr = GetSurfaceInfo(w, h, format, &NumBytes, &RowBytes, nullptr); + if (FAILED(hr)) + return hr; + + if (NumBytes > UINT32_MAX || RowBytes > UINT32_MAX) + return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); if ((mipCount <= 1) || !maxsize || (w <= maxsize && h <= maxsize && d <= maxsize)) { @@ -872,7 +951,7 @@ namespace assert(index < mipCount * arraySize); _Analysis_assume_(index < mipCount * arraySize); - initData[index].pSysMem = (const void*)pSrcBits; + initData[index].pSysMem = pSrcBits; initData[index].SysMemPitch = static_cast(RowBytes); initData[index].SysMemSlicePitch = static_cast(NumBytes); ++index; @@ -954,16 +1033,16 @@ namespace desc.Usage = usage; desc.BindFlags = bindFlags; desc.CPUAccessFlags = cpuAccessFlags; - desc.MiscFlags = miscFlags & ~D3D11_RESOURCE_MISC_TEXTURECUBE; + desc.MiscFlags = miscFlags & ~static_cast(D3D11_RESOURCE_MISC_TEXTURECUBE); ID3D11Texture1D* tex = nullptr; hr = d3dDevice->CreateTexture1D(&desc, initData, &tex ); - if (SUCCEEDED(hr) && tex != 0) + if (SUCCEEDED(hr) && tex) { - if (textureView != 0) + if (textureView) { D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc = {}; SRVDesc.Format = format; @@ -971,13 +1050,13 @@ namespace if (arraySize > 1) { SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1DARRAY; - SRVDesc.Texture1DArray.MipLevels = (!mipCount) ? -1 : desc.MipLevels; + SRVDesc.Texture1DArray.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels; SRVDesc.Texture1DArray.ArraySize = static_cast(arraySize); } else { SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D; - SRVDesc.Texture1D.MipLevels = (!mipCount) ? -1 : desc.MipLevels; + SRVDesc.Texture1D.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels; } hr = d3dDevice->CreateShaderResourceView(tex, @@ -991,7 +1070,7 @@ namespace } } - if (texture != 0) + if (texture) { *texture = tex; } @@ -1023,7 +1102,7 @@ namespace } else { - desc.MiscFlags = miscFlags & ~D3D11_RESOURCE_MISC_TEXTURECUBE; + desc.MiscFlags = miscFlags & ~static_cast(D3D11_RESOURCE_MISC_TEXTURECUBE); } ID3D11Texture2D* tex = nullptr; @@ -1031,9 +1110,9 @@ namespace initData, &tex ); - if (SUCCEEDED(hr) && tex != 0) + if (SUCCEEDED(hr) && tex) { - if (textureView != 0) + if (textureView) { D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc = {}; SRVDesc.Format = format; @@ -1043,7 +1122,7 @@ namespace if (arraySize > 6) { SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBEARRAY; - SRVDesc.TextureCubeArray.MipLevels = (!mipCount) ? -1 : desc.MipLevels; + SRVDesc.TextureCubeArray.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels; // Earlier we set arraySize to (NumCubes * 6) SRVDesc.TextureCubeArray.NumCubes = static_cast(arraySize / 6); @@ -1051,19 +1130,19 @@ namespace else { SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; - SRVDesc.TextureCube.MipLevels = (!mipCount) ? -1 : desc.MipLevels; + SRVDesc.TextureCube.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels; } } else if (arraySize > 1) { SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY; - SRVDesc.Texture2DArray.MipLevels = (!mipCount) ? -1 : desc.MipLevels; + SRVDesc.Texture2DArray.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels; SRVDesc.Texture2DArray.ArraySize = static_cast(arraySize); } else { SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - SRVDesc.Texture2D.MipLevels = (!mipCount) ? -1 : desc.MipLevels; + SRVDesc.Texture2D.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels; } hr = d3dDevice->CreateShaderResourceView(tex, @@ -1077,7 +1156,7 @@ namespace } } - if (texture != 0) + if (texture) { *texture = tex; } @@ -1101,22 +1180,22 @@ namespace desc.Usage = usage; desc.BindFlags = bindFlags; desc.CPUAccessFlags = cpuAccessFlags; - desc.MiscFlags = miscFlags & ~D3D11_RESOURCE_MISC_TEXTURECUBE; + desc.MiscFlags = miscFlags & ~static_cast(D3D11_RESOURCE_MISC_TEXTURECUBE); ID3D11Texture3D* tex = nullptr; hr = d3dDevice->CreateTexture3D(&desc, initData, &tex ); - if (SUCCEEDED(hr) && tex != 0) + if (SUCCEEDED(hr) && tex) { - if (textureView != 0) + if (textureView) { D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc = {}; SRVDesc.Format = format; SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D; - SRVDesc.Texture3D.MipLevels = (!mipCount) ? -1 : desc.MipLevels; + SRVDesc.Texture3D.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels; hr = d3dDevice->CreateShaderResourceView(tex, &SRVDesc, @@ -1129,7 +1208,7 @@ namespace } } - if (texture != 0) + if (texture) { *texture = tex; } @@ -1146,7 +1225,6 @@ namespace return hr; } - //-------------------------------------------------------------------------------------- HRESULT CreateTextureFromDDS( _In_ ID3D11Device* d3dDevice, @@ -1183,7 +1261,7 @@ namespace if ((header->ddspf.flags & DDS_FOURCC) && (MAKEFOURCC('D', 'X', '1', '0') == header->ddspf.fourCC)) { - auto d3d10ext = reinterpret_cast((const char*)header + sizeof(DDS_HEADER)); + auto d3d10ext = reinterpret_cast(reinterpret_cast(header) + sizeof(DDS_HEADER)); arraySize = d3d10ext->arraySize; if (arraySize == 0) @@ -1310,8 +1388,8 @@ namespace } } else if ((arraySize > D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION) || - (width > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION) || - (height > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION)) + (width > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION) || + (height > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION)) { return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); } @@ -1332,7 +1410,7 @@ namespace } bool autogen = false; - if (mipCount == 1 && d3dContext != 0 && textureView != 0) // Must have context and shader-view to auto generate mipmaps + if (mipCount == 1 && d3dContext && textureView) // Must have context and shader-view to auto generate mipmaps { // See if format is supported for auto-gen mipmaps (varies by feature level) UINT fmtSupport = 0; @@ -1352,17 +1430,24 @@ namespace { // Create texture with auto-generated mipmaps ID3D11Resource* tex = nullptr; - hr = CreateD3DResources(d3dDevice, resDim, width, height, depth, 0, arraySize, - format, usage, + hr = CreateD3DResources(d3dDevice, + resDim, width, height, depth, 0, arraySize, + format, + usage, bindFlags | D3D11_BIND_RENDER_TARGET, cpuAccessFlags, - miscFlags | D3D11_RESOURCE_MISC_GENERATE_MIPS, forceSRGB, - isCubeMap, nullptr, &tex, textureView); + miscFlags | D3D11_RESOURCE_MISC_GENERATE_MIPS, + forceSRGB, + isCubeMap, + nullptr, + &tex, textureView); if (SUCCEEDED(hr)) { size_t numBytes = 0; size_t rowBytes = 0; - GetSurfaceInfo(width, height, format, &numBytes, &rowBytes, nullptr); + hr = GetSurfaceInfo(width, height, format, &numBytes, &rowBytes, nullptr); + if (FAILED(hr)) + return hr; if (numBytes > bitSize) { @@ -1372,6 +1457,9 @@ namespace return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF); } + if (numBytes > UINT32_MAX || rowBytes > UINT32_MAX) + return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); + D3D11_SHADER_RESOURCE_VIEW_DESC desc; (*textureView)->GetDesc(&desc); @@ -1442,14 +1530,20 @@ namespace size_t twidth = 0; size_t theight = 0; size_t tdepth = 0; - hr = FillInitData(width, height, depth, mipCount, arraySize, format, maxsize, bitSize, bitData, + hr = FillInitData(width, height, depth, mipCount, arraySize, + format, maxsize, bitSize, bitData, twidth, theight, tdepth, skipMip, initData.get()); if (SUCCEEDED(hr)) { - hr = CreateD3DResources(d3dDevice, resDim, twidth, theight, tdepth, mipCount - skipMip, arraySize, - format, usage, bindFlags, cpuAccessFlags, miscFlags, forceSRGB, - isCubeMap, initData.get(), texture, textureView); + hr = CreateD3DResources(d3dDevice, + resDim, twidth, theight, tdepth, mipCount - skipMip, arraySize, + format, + usage, bindFlags, cpuAccessFlags, miscFlags, + forceSRGB, + isCubeMap, + initData.get(), + texture, textureView); if (FAILED(hr) && !maxsize && (mipCount > 1)) { @@ -1487,9 +1581,14 @@ namespace twidth, theight, tdepth, skipMip, initData.get()); if (SUCCEEDED(hr)) { - hr = CreateD3DResources(d3dDevice, resDim, twidth, theight, tdepth, mipCount - skipMip, arraySize, - format, usage, bindFlags, cpuAccessFlags, miscFlags, forceSRGB, - isCubeMap, initData.get(), texture, textureView); + hr = CreateD3DResources(d3dDevice, + resDim, twidth, theight, tdepth, mipCount - skipMip, arraySize, + format, + usage, bindFlags, cpuAccessFlags, miscFlags, + forceSRGB, + isCubeMap, + initData.get(), + texture, textureView); } } } @@ -1506,7 +1605,7 @@ namespace { if (MAKEFOURCC('D', 'X', '1', '0') == header->ddspf.fourCC) { - auto d3d10ext = reinterpret_cast((const char*)header + sizeof(DDS_HEADER)); + auto d3d10ext = reinterpret_cast(reinterpret_cast(header) + sizeof(DDS_HEADER)); auto mode = static_cast(d3d10ext->miscFlags2 & DDS_MISC_FLAGS2_ALPHA_MODE_MASK); switch (mode) { @@ -1515,6 +1614,10 @@ namespace case DDS_ALPHA_MODE_OPAQUE: case DDS_ALPHA_MODE_CUSTOM: return mode; + + case DDS_ALPHA_MODE_UNKNOWN: + default: + break; } } else if ((MAKEFOURCC('D', 'X', 'T', '2') == header->ddspf.fourCC) @@ -1526,11 +1629,67 @@ namespace return DDS_ALPHA_MODE_UNKNOWN; } + + //-------------------------------------------------------------------------------------- + void SetDebugTextureInfo( + _In_z_ const wchar_t* fileName, + _In_opt_ ID3D11Resource** texture, + _In_opt_ ID3D11ShaderResourceView** textureView) + { +#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) ) + if (texture || textureView) + { + CHAR strFileA[MAX_PATH]; + int result = WideCharToMultiByte(CP_UTF8, + WC_NO_BEST_FIT_CHARS, + fileName, + -1, + strFileA, + MAX_PATH, + nullptr, + nullptr + ); + if (result > 0) + { + const char* pstrName = strrchr(strFileA, '\\'); + if (!pstrName) + { + pstrName = strFileA; + } + else + { + pstrName++; + } + + if (texture && *texture) + { + (*texture)->SetPrivateData(WKPDID_D3DDebugObjectName, + static_cast(strnlen_s(pstrName, MAX_PATH)), + pstrName + ); + } + + if (textureView && *textureView) + { + (*textureView)->SetPrivateData(WKPDID_D3DDebugObjectName, + static_cast(strnlen_s(pstrName, MAX_PATH)), + pstrName + ); + } + } + } +#else + UNREFERENCED_PARAMETER(fileName); + UNREFERENCED_PARAMETER(texture); + UNREFERENCED_PARAMETER(textureView); +#endif + } } // anonymous namespace //-------------------------------------------------------------------------------------- _Use_decl_annotations_ -HRESULT DirectX::CreateDDSTextureFromMemory(ID3D11Device* d3dDevice, +HRESULT DirectX::CreateDDSTextureFromMemory( + ID3D11Device* d3dDevice, const uint8_t* ddsData, size_t ddsDataSize, ID3D11Resource** texture, @@ -1538,13 +1697,17 @@ HRESULT DirectX::CreateDDSTextureFromMemory(ID3D11Device* d3dDevice, size_t maxsize, DDS_ALPHA_MODE* alphaMode) { - return CreateDDSTextureFromMemoryEx(d3dDevice, nullptr, ddsData, ddsDataSize, maxsize, - D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, false, + return CreateDDSTextureFromMemoryEx(d3dDevice, nullptr, + ddsData, ddsDataSize, + maxsize, + D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, + false, texture, textureView, alphaMode); } _Use_decl_annotations_ -HRESULT DirectX::CreateDDSTextureFromMemory(ID3D11Device* d3dDevice, +HRESULT DirectX::CreateDDSTextureFromMemory( + ID3D11Device* d3dDevice, ID3D11DeviceContext* d3dContext, const uint8_t* ddsData, size_t ddsDataSize, @@ -1553,13 +1716,17 @@ HRESULT DirectX::CreateDDSTextureFromMemory(ID3D11Device* d3dDevice, size_t maxsize, DDS_ALPHA_MODE* alphaMode) { - return CreateDDSTextureFromMemoryEx(d3dDevice, d3dContext, ddsData, ddsDataSize, maxsize, - D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, false, + return CreateDDSTextureFromMemoryEx(d3dDevice, d3dContext, + ddsData, ddsDataSize, + maxsize, + D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, + false, texture, textureView, alphaMode); } _Use_decl_annotations_ -HRESULT DirectX::CreateDDSTextureFromMemoryEx(ID3D11Device* d3dDevice, +HRESULT DirectX::CreateDDSTextureFromMemoryEx( + ID3D11Device* d3dDevice, const uint8_t* ddsData, size_t ddsDataSize, size_t maxsize, @@ -1572,13 +1739,17 @@ HRESULT DirectX::CreateDDSTextureFromMemoryEx(ID3D11Device* d3dDevice, ID3D11ShaderResourceView** textureView, DDS_ALPHA_MODE* alphaMode) { - return CreateDDSTextureFromMemoryEx(d3dDevice, nullptr, ddsData, ddsDataSize, maxsize, - usage, bindFlags, cpuAccessFlags, miscFlags, forceSRGB, + return CreateDDSTextureFromMemoryEx(d3dDevice, nullptr, + ddsData, ddsDataSize, + maxsize, + usage, bindFlags, cpuAccessFlags, miscFlags, + forceSRGB, texture, textureView, alphaMode); } _Use_decl_annotations_ -HRESULT DirectX::CreateDDSTextureFromMemoryEx(ID3D11Device* d3dDevice, +HRESULT DirectX::CreateDDSTextureFromMemoryEx( + ID3D11Device* d3dDevice, ID3D11DeviceContext* d3dContext, const uint8_t* ddsData, size_t ddsDataSize, @@ -1610,57 +1781,40 @@ HRESULT DirectX::CreateDDSTextureFromMemoryEx(ID3D11Device* d3dDevice, return E_INVALIDARG; } - // Validate DDS file in memory - if (ddsDataSize < (sizeof(uint32_t) + sizeof(DDS_HEADER))) + if (textureView && !(bindFlags & D3D11_BIND_SHADER_RESOURCE)) { - return E_FAIL; - } - - uint32_t dwMagicNumber = *(const uint32_t*)(ddsData); - if (dwMagicNumber != DDS_MAGIC) - { - return E_FAIL; + return E_INVALIDARG; } - auto header = reinterpret_cast(ddsData + sizeof(uint32_t)); - - // Verify header to validate DDS file - if (header->size != sizeof(DDS_HEADER) || - header->ddspf.size != sizeof(DDS_PIXELFORMAT)) - { - return E_FAIL; - } + // Validate DDS file in memory + const DDS_HEADER* header = nullptr; + const uint8_t* bitData = nullptr; + size_t bitSize = 0; - // Check for DX10 extension - bool bDXT10Header = false; - if ((header->ddspf.flags & DDS_FOURCC) && - (MAKEFOURCC('D', 'X', '1', '0') == header->ddspf.fourCC)) + HRESULT hr = LoadTextureDataFromMemory(ddsData, ddsDataSize, + &header, + &bitData, + &bitSize + ); + if (FAILED(hr)) { - // Must be long enough for both headers and magic value - if (ddsDataSize < (sizeof(DDS_HEADER) + sizeof(uint32_t) + sizeof(DDS_HEADER_DXT10))) - { - return E_FAIL; - } - - bDXT10Header = true; + return hr; } - ptrdiff_t offset = sizeof(uint32_t) - + sizeof(DDS_HEADER) - + (bDXT10Header ? sizeof(DDS_HEADER_DXT10) : 0); - - HRESULT hr = CreateTextureFromDDS(d3dDevice, d3dContext, header, - ddsData + offset, ddsDataSize - offset, maxsize, - usage, bindFlags, cpuAccessFlags, miscFlags, forceSRGB, + hr = CreateTextureFromDDS(d3dDevice, d3dContext, + header, bitData, bitSize, + maxsize, + usage, bindFlags, cpuAccessFlags, miscFlags, + forceSRGB, texture, textureView); if (SUCCEEDED(hr)) { - if (texture != 0 && *texture != 0) + if (texture && *texture) { SetDebugObjectName(*texture, "DDSTextureLoader"); } - if (textureView != 0 && *textureView != 0) + if (textureView && *textureView) { SetDebugObjectName(*textureView, "DDSTextureLoader"); } @@ -1674,20 +1828,24 @@ HRESULT DirectX::CreateDDSTextureFromMemoryEx(ID3D11Device* d3dDevice, //-------------------------------------------------------------------------------------- _Use_decl_annotations_ -HRESULT DirectX::CreateDDSTextureFromFile(ID3D11Device* d3dDevice, +HRESULT DirectX::CreateDDSTextureFromFile( + ID3D11Device* d3dDevice, const wchar_t* fileName, ID3D11Resource** texture, ID3D11ShaderResourceView** textureView, size_t maxsize, DDS_ALPHA_MODE* alphaMode) { - return CreateDDSTextureFromFileEx(d3dDevice, nullptr, fileName, maxsize, - D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, false, + return CreateDDSTextureFromFileEx(d3dDevice, nullptr, + fileName, maxsize, + D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, + false, texture, textureView, alphaMode); } _Use_decl_annotations_ -HRESULT DirectX::CreateDDSTextureFromFile(ID3D11Device* d3dDevice, +HRESULT DirectX::CreateDDSTextureFromFile( + ID3D11Device* d3dDevice, ID3D11DeviceContext* d3dContext, const wchar_t* fileName, ID3D11Resource** texture, @@ -1695,13 +1853,17 @@ HRESULT DirectX::CreateDDSTextureFromFile(ID3D11Device* d3dDevice, size_t maxsize, DDS_ALPHA_MODE* alphaMode) { - return CreateDDSTextureFromFileEx(d3dDevice, d3dContext, fileName, maxsize, - D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, false, + return CreateDDSTextureFromFileEx(d3dDevice, d3dContext, + fileName, + maxsize, + D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, + false, texture, textureView, alphaMode); } _Use_decl_annotations_ -HRESULT DirectX::CreateDDSTextureFromFileEx(ID3D11Device* d3dDevice, +HRESULT DirectX::CreateDDSTextureFromFileEx( + ID3D11Device* d3dDevice, const wchar_t* fileName, size_t maxsize, D3D11_USAGE usage, @@ -1713,13 +1875,17 @@ HRESULT DirectX::CreateDDSTextureFromFileEx(ID3D11Device* d3dDevice, ID3D11ShaderResourceView** textureView, DDS_ALPHA_MODE* alphaMode) { - return CreateDDSTextureFromFileEx(d3dDevice, nullptr, fileName, maxsize, - usage, bindFlags, cpuAccessFlags, miscFlags, forceSRGB, + return CreateDDSTextureFromFileEx(d3dDevice, nullptr, + fileName, + maxsize, + usage, bindFlags, cpuAccessFlags, miscFlags, + forceSRGB, texture, textureView, alphaMode); } _Use_decl_annotations_ -HRESULT DirectX::CreateDDSTextureFromFileEx(ID3D11Device* d3dDevice, +HRESULT DirectX::CreateDDSTextureFromFileEx( + ID3D11Device* d3dDevice, ID3D11DeviceContext* d3dContext, const wchar_t* fileName, size_t maxsize, @@ -1750,6 +1916,11 @@ HRESULT DirectX::CreateDDSTextureFromFileEx(ID3D11Device* d3dDevice, return E_INVALIDARG; } + if (textureView && !(bindFlags & D3D11_BIND_SHADER_RESOURCE)) + { + return E_INVALIDARG; + } + const DDS_HEADER* header = nullptr; const uint8_t* bitData = nullptr; size_t bitSize = 0; @@ -1766,56 +1937,16 @@ HRESULT DirectX::CreateDDSTextureFromFileEx(ID3D11Device* d3dDevice, return hr; } - hr = CreateTextureFromDDS(d3dDevice, d3dContext, header, - bitData, bitSize, maxsize, - usage, bindFlags, cpuAccessFlags, miscFlags, forceSRGB, + hr = CreateTextureFromDDS(d3dDevice, d3dContext, + header, bitData, bitSize, + maxsize, + usage, bindFlags, cpuAccessFlags, miscFlags, + forceSRGB, texture, textureView); if (SUCCEEDED(hr)) { -#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) ) - if (texture != 0 || textureView != 0) - { - CHAR strFileA[MAX_PATH]; - int result = WideCharToMultiByte(CP_ACP, - WC_NO_BEST_FIT_CHARS, - fileName, - -1, - strFileA, - MAX_PATH, - nullptr, - FALSE - ); - if (result > 0) - { - const CHAR* pstrName = strrchr(strFileA, '\\'); - if (!pstrName) - { - pstrName = strFileA; - } - else - { - pstrName++; - } - - if (texture != 0 && *texture != 0) - { - (*texture)->SetPrivateData(WKPDID_D3DDebugObjectName, - static_cast(strnlen_s(pstrName, MAX_PATH)), - pstrName - ); - } - - if (textureView != 0 && *textureView != 0) - { - (*textureView)->SetPrivateData(WKPDID_D3DDebugObjectName, - static_cast(strnlen_s(pstrName, MAX_PATH)), - pstrName - ); - } - } - } -#endif + SetDebugTextureInfo(fileName, texture, textureView); if (alphaMode) *alphaMode = GetAlphaMode(header); diff --git a/FriedLiver/Source/DXUT/Core/DXUT.h b/FriedLiver/Source/DXUT/Core/DXUT.h index c70fd47a..5585c8b7 100644 --- a/FriedLiver/Source/DXUT/Core/DXUT.h +++ b/FriedLiver/Source/DXUT/Core/DXUT.h @@ -131,7 +131,7 @@ ((DWORD)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff))) #endif -#define DXUT_VERSION 1122 +#define DXUT_VERSION 1123 //-------------------------------------------------------------------------------------- // Structs diff --git a/FriedLiver/Source/DXUT/Core/DXUTDevice9.cpp b/FriedLiver/Source/DXUT/Core/DXUTDevice9.cpp deleted file mode 100644 index a1d12e38..00000000 --- a/FriedLiver/Source/DXUT/Core/DXUTDevice9.cpp +++ /dev/null @@ -1,1177 +0,0 @@ -//-------------------------------------------------------------------------------------- -// File: DXUTDevice9.cpp -// -// Enumerates D3D adapters, devices, modes, etc. -// -// Copyright (c) Microsoft Corporation. All rights reserved. -//-------------------------------------------------------------------------------------- -#include "DXUT.h" -#undef min // use __min instead -#undef max // use __max instead - -//-------------------------------------------------------------------------------------- -// Forward declarations -//-------------------------------------------------------------------------------------- -extern void DXUTGetCallbackD3D9DeviceAcceptable( LPDXUTCALLBACKISD3D9DEVICEACCEPTABLE* ppCallbackIsDeviceAcceptable, void** ppUserContext ); - - - - -static int __cdecl SortModesCallback( const void* arg1, const void* arg2 ); - - -CD3D9Enumeration* g_pDXUTD3D9Enumeration = NULL; - -HRESULT WINAPI DXUTCreateD3D9Enumeration() -{ - if( g_pDXUTD3D9Enumeration == NULL ) - { - g_pDXUTD3D9Enumeration = new CD3D9Enumeration(); - if( NULL == g_pDXUTD3D9Enumeration ) - return E_OUTOFMEMORY; - } - return S_OK; -} - -void WINAPI DXUTDestroyD3D9Enumeration() -{ - SAFE_DELETE( g_pDXUTD3D9Enumeration ); -} - -class DXUTMemoryHelperD3D9Enum -{ -public: -DXUTMemoryHelperD3D9Enum() -{ - DXUTCreateD3D9Enumeration(); -} -~DXUTMemoryHelperD3D9Enum() -{ - DXUTDestroyD3D9Enumeration(); -} -}; - -//-------------------------------------------------------------------------------------- -CD3D9Enumeration* WINAPI DXUTGetD3D9Enumeration( bool bForceEnumerate ) -{ - // Using an static class with accessor function to allow control of the construction order - static DXUTMemoryHelperD3D9Enum d3d9enumMemory; - - if( g_pDXUTD3D9Enumeration && ( !g_pDXUTD3D9Enumeration->HasEnumerated() || bForceEnumerate ) ) - { - LPDXUTCALLBACKISD3D9DEVICEACCEPTABLE pCallbackIsDeviceAcceptable; - void* pUserContext; - DXUTGetCallbackD3D9DeviceAcceptable( &pCallbackIsDeviceAcceptable, &pUserContext ); - g_pDXUTD3D9Enumeration->Enumerate( pCallbackIsDeviceAcceptable, pUserContext ); - } - - return g_pDXUTD3D9Enumeration; -} - - -//-------------------------------------------------------------------------------------- -CD3D9Enumeration::CD3D9Enumeration() -{ - m_bHasEnumerated = false; - m_pD3D = NULL; - m_IsD3D9DeviceAcceptableFunc = NULL; - m_pIsD3D9DeviceAcceptableFuncUserContext = NULL; - m_bRequirePostPixelShaderBlending = true; - - m_nMinWidth = 640; - m_nMinHeight = 480; - m_nMaxWidth = UINT_MAX; - m_nMaxHeight = UINT_MAX; - - m_nRefreshMin = 0; - m_nRefreshMax = UINT_MAX; - - m_nMultisampleQualityMax = 0xFFFF; - - ResetPossibleDepthStencilFormats(); - ResetPossibleMultisampleTypeList(); - ResetPossiblePresentIntervalList(); - SetPossibleVertexProcessingList( true, true, true, false ); -} - - -//-------------------------------------------------------------------------------------- -CD3D9Enumeration::~CD3D9Enumeration() -{ - ClearAdapterInfoList(); -} - - - -//-------------------------------------------------------------------------------------- -// Enumerate for each adapter all of the supported display modes, -// device types, adapter formats, back buffer formats, window/full screen support, -// depth stencil formats, multisampling types/qualities, and presentations intervals. -// -// For each combination of device type (HAL/REF), adapter format, back buffer format, and -// IsWindowed it will call the app's ConfirmDevice callback. This allows the app -// to reject or allow that combination based on its caps/etc. It also allows the -// app to change the BehaviorFlags. The BehaviorFlags defaults non-pure HWVP -// if supported otherwise it will default to SWVP, however the app can change this -// through the ConfirmDevice callback. -//-------------------------------------------------------------------------------------- -HRESULT CD3D9Enumeration::Enumerate( LPDXUTCALLBACKISD3D9DEVICEACCEPTABLE IsD3D9DeviceAcceptableFunc, - void* pIsD3D9DeviceAcceptableFuncUserContext ) -{ - CDXUTPerfEventGenerator eventGenerator( DXUT_PERFEVENTCOLOR, L"DXUT D3D9 Enumeration" ); - IDirect3D9* pD3D = DXUTGetD3D9Object(); - if( pD3D == NULL ) - { - pD3D = DXUTGetD3D9Object(); - if( pD3D == NULL ) - return DXUTERR_NODIRECT3D; - } - - m_bHasEnumerated = true; - m_pD3D = pD3D; - m_IsD3D9DeviceAcceptableFunc = IsD3D9DeviceAcceptableFunc; - m_pIsD3D9DeviceAcceptableFuncUserContext = pIsD3D9DeviceAcceptableFuncUserContext; - - HRESULT hr; - ClearAdapterInfoList(); - CGrowableArray adapterFormatList; - - const D3DFORMAT allowedAdapterFormatArray[] = - { - D3DFMT_X8R8G8B8, - D3DFMT_X1R5G5B5, - D3DFMT_R5G6B5, - D3DFMT_A2R10G10B10 - }; - const UINT allowedAdapterFormatArrayCount = sizeof( allowedAdapterFormatArray ) / sizeof - ( allowedAdapterFormatArray[0] ); - - UINT numAdapters = pD3D->GetAdapterCount(); - for( UINT adapterOrdinal = 0; adapterOrdinal < numAdapters; adapterOrdinal++ ) - { - CD3D9EnumAdapterInfo* pAdapterInfo = new CD3D9EnumAdapterInfo; - if( pAdapterInfo == NULL ) - return E_OUTOFMEMORY; - - pAdapterInfo->AdapterOrdinal = adapterOrdinal; - pD3D->GetAdapterIdentifier( adapterOrdinal, 0, &pAdapterInfo->AdapterIdentifier ); - - // Get list of all display modes on this adapter. - // Also build a temporary list of all display adapter formats. - adapterFormatList.RemoveAll(); - - for( UINT iFormatList = 0; iFormatList < allowedAdapterFormatArrayCount; iFormatList++ ) - { - D3DFORMAT allowedAdapterFormat = allowedAdapterFormatArray[iFormatList]; - UINT numAdapterModes = pD3D->GetAdapterModeCount( adapterOrdinal, allowedAdapterFormat ); - for( UINT mode = 0; mode < numAdapterModes; mode++ ) - { - D3DDISPLAYMODE displayMode; - pD3D->EnumAdapterModes( adapterOrdinal, allowedAdapterFormat, mode, &displayMode ); - - if( displayMode.Width < m_nMinWidth || - displayMode.Height < m_nMinHeight || - displayMode.Width > m_nMaxWidth || - displayMode.Height > m_nMaxHeight || - displayMode.RefreshRate < m_nRefreshMin || - displayMode.RefreshRate > m_nRefreshMax ) - { - continue; - } - - pAdapterInfo->displayModeList.Add( displayMode ); - - if( !adapterFormatList.Contains( displayMode.Format ) ) - adapterFormatList.Add( displayMode.Format ); - } - - } - - D3DDISPLAYMODE displayMode; - pD3D->GetAdapterDisplayMode( adapterOrdinal, &displayMode ); - if( !adapterFormatList.Contains( displayMode.Format ) ) - adapterFormatList.Add( displayMode.Format ); - - // Sort displaymode list - qsort( pAdapterInfo->displayModeList.GetData(), - pAdapterInfo->displayModeList.GetSize(), sizeof( D3DDISPLAYMODE ), - SortModesCallback ); - - // Get info for each device on this adapter - if( FAILED( EnumerateDevices( pAdapterInfo, &adapterFormatList ) ) ) - { - delete pAdapterInfo; - continue; - } - - // If at least one device on this adapter is available and compatible - // with the app, add the adapterInfo to the list - if( pAdapterInfo->deviceInfoList.GetSize() > 0 ) - { - hr = m_AdapterInfoList.Add( pAdapterInfo ); - if( FAILED( hr ) ) - return hr; - } - else - delete pAdapterInfo; - } - - // - // Check for 2 or more adapters with the same name. Append the name - // with some instance number if that's the case to help distinguish - // them. - // - bool bUniqueDesc = true; - CD3D9EnumAdapterInfo* pAdapterInfo; - for( int i = 0; i < m_AdapterInfoList.GetSize(); i++ ) - { - CD3D9EnumAdapterInfo* pAdapterInfo1 = m_AdapterInfoList.GetAt( i ); - - for( int j = i + 1; j < m_AdapterInfoList.GetSize(); j++ ) - { - CD3D9EnumAdapterInfo* pAdapterInfo2 = m_AdapterInfoList.GetAt( j ); - if( _stricmp( pAdapterInfo1->AdapterIdentifier.Description, - pAdapterInfo2->AdapterIdentifier.Description ) == 0 ) - { - bUniqueDesc = false; - break; - } - } - - if( !bUniqueDesc ) - break; - } - - for( int i = 0; i < m_AdapterInfoList.GetSize(); i++ ) - { - pAdapterInfo = m_AdapterInfoList.GetAt( i ); - - MultiByteToWideChar( CP_ACP, 0, - pAdapterInfo->AdapterIdentifier.Description, -1, - pAdapterInfo->szUniqueDescription, 100 ); - pAdapterInfo->szUniqueDescription[100] = 0; - - if( !bUniqueDesc ) - { - WCHAR sz[100]; - swprintf_s( sz, 100, L" (#%d)", pAdapterInfo->AdapterOrdinal ); - wcscat_s( pAdapterInfo->szUniqueDescription, 256, sz ); - - } - } - - return S_OK; -} - - - -//-------------------------------------------------------------------------------------- -// Enumerates D3D devices for a particular adapter. -//-------------------------------------------------------------------------------------- -HRESULT CD3D9Enumeration::EnumerateDevices( CD3D9EnumAdapterInfo* pAdapterInfo, - CGrowableArray * pAdapterFormatList ) -{ - HRESULT hr; - - const D3DDEVTYPE devTypeArray[] = - { - D3DDEVTYPE_HAL, - D3DDEVTYPE_SW, - D3DDEVTYPE_REF - }; - const UINT devTypeArrayCount = sizeof( devTypeArray ) / sizeof( devTypeArray[0] ); - - // Enumerate each Direct3D device type - for( UINT iDeviceType = 0; iDeviceType < devTypeArrayCount; iDeviceType++ ) - { - CD3D9EnumDeviceInfo* pDeviceInfo = new CD3D9EnumDeviceInfo; - if( pDeviceInfo == NULL ) - return E_OUTOFMEMORY; - - // Fill struct w/ AdapterOrdinal and D3DDEVTYPE - pDeviceInfo->AdapterOrdinal = pAdapterInfo->AdapterOrdinal; - pDeviceInfo->DeviceType = devTypeArray[iDeviceType]; - - // Store device caps - if( FAILED( hr = m_pD3D->GetDeviceCaps( pAdapterInfo->AdapterOrdinal, pDeviceInfo->DeviceType, - &pDeviceInfo->Caps ) ) ) - { - delete pDeviceInfo; - continue; - } - - if( pDeviceInfo->DeviceType != D3DDEVTYPE_HAL ) - { - // Create a temp device to verify that it is really possible to create a REF device - // [the developer DirectX redist has to be installed] - D3DDISPLAYMODE Mode; - m_pD3D->GetAdapterDisplayMode( 0, &Mode ); - D3DPRESENT_PARAMETERS pp; - ZeroMemory( &pp, sizeof( D3DPRESENT_PARAMETERS ) ); - pp.BackBufferWidth = 1; - pp.BackBufferHeight = 1; - pp.BackBufferFormat = Mode.Format; - pp.BackBufferCount = 1; - pp.SwapEffect = D3DSWAPEFFECT_COPY; - pp.Windowed = TRUE; - pp.hDeviceWindow = DXUTGetHWNDFocus(); - IDirect3DDevice9* pDevice = NULL; - if( FAILED( hr = m_pD3D->CreateDevice( pAdapterInfo->AdapterOrdinal, pDeviceInfo->DeviceType, - DXUTGetHWNDFocus(), - D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &pp, - &pDevice ) ) ) - { - delete pDeviceInfo; - continue; - } - SAFE_RELEASE( pDevice ); - } - - // Get info for each devicecombo on this device - if( FAILED( hr = EnumerateDeviceCombos( pAdapterInfo, pDeviceInfo, pAdapterFormatList ) ) ) - { - delete pDeviceInfo; - continue; - } - - // If at least one devicecombo for this device is found, - // add the deviceInfo to the list - if( pDeviceInfo->deviceSettingsComboList.GetSize() > 0 ) - pAdapterInfo->deviceInfoList.Add( pDeviceInfo ); - else - delete pDeviceInfo; - } - - return S_OK; -} - - - -//-------------------------------------------------------------------------------------- -// Enumerates DeviceCombos for a particular device. -//-------------------------------------------------------------------------------------- -HRESULT CD3D9Enumeration::EnumerateDeviceCombos( CD3D9EnumAdapterInfo* pAdapterInfo, CD3D9EnumDeviceInfo* pDeviceInfo, - CGrowableArray * pAdapterFormatList ) -{ - const D3DFORMAT backBufferFormatArray[] = - { - D3DFMT_A8R8G8B8, - D3DFMT_X8R8G8B8, - D3DFMT_A2R10G10B10, - D3DFMT_R5G6B5, - D3DFMT_A1R5G5B5, - D3DFMT_X1R5G5B5 - }; - const UINT backBufferFormatArrayCount = sizeof( backBufferFormatArray ) / sizeof( backBufferFormatArray[0] ); - - // See which adapter formats are supported by this device - for( int iFormat = 0; iFormat < pAdapterFormatList->GetSize(); iFormat++ ) - { - D3DFORMAT adapterFormat = pAdapterFormatList->GetAt( iFormat ); - - for( UINT iBackBufferFormat = 0; iBackBufferFormat < backBufferFormatArrayCount; iBackBufferFormat++ ) - { - D3DFORMAT backBufferFormat = backBufferFormatArray[iBackBufferFormat]; - - for( int nWindowed = 0; nWindowed < 2; nWindowed++ ) - { - if( !nWindowed && pAdapterInfo->displayModeList.GetSize() == 0 ) - continue; - - if( FAILED( m_pD3D->CheckDeviceType( pAdapterInfo->AdapterOrdinal, pDeviceInfo->DeviceType, - adapterFormat, backBufferFormat, nWindowed ) ) ) - { - continue; - } - - if( m_bRequirePostPixelShaderBlending ) - { - // If the backbuffer format doesn't support D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING - // then alpha test, pixel fog, render-target blending, color write enable, and dithering. - // are not supported. - if( FAILED( m_pD3D->CheckDeviceFormat( pAdapterInfo->AdapterOrdinal, pDeviceInfo->DeviceType, - adapterFormat, D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, - D3DRTYPE_TEXTURE, backBufferFormat ) ) ) - { - continue; - } - } - - // If an application callback function has been provided, make sure this device - // is acceptable to the app. - if( m_IsD3D9DeviceAcceptableFunc != NULL ) - { - if( !m_IsD3D9DeviceAcceptableFunc( &pDeviceInfo->Caps, adapterFormat, backBufferFormat, - FALSE != nWindowed, m_pIsD3D9DeviceAcceptableFuncUserContext ) ) - continue; - } - - // At this point, we have an adapter/device/adapterformat/backbufferformat/iswindowed - // DeviceCombo that is supported by the system and acceptable to the app. We still - // need to find one or more suitable depth/stencil buffer format, - // multisample type, and present interval. - CD3D9EnumDeviceSettingsCombo* pDeviceCombo = new CD3D9EnumDeviceSettingsCombo; - if( pDeviceCombo == NULL ) - return E_OUTOFMEMORY; - - pDeviceCombo->AdapterOrdinal = pAdapterInfo->AdapterOrdinal; - pDeviceCombo->DeviceType = pDeviceInfo->DeviceType; - pDeviceCombo->AdapterFormat = adapterFormat; - pDeviceCombo->BackBufferFormat = backBufferFormat; - pDeviceCombo->Windowed = ( nWindowed != 0 ); - - BuildDepthStencilFormatList( pDeviceCombo ); - BuildMultiSampleTypeList( pDeviceCombo ); - if( pDeviceCombo->multiSampleTypeList.GetSize() == 0 ) - { - delete pDeviceCombo; - continue; - } - BuildDSMSConflictList( pDeviceCombo ); - BuildPresentIntervalList( pDeviceInfo, pDeviceCombo ); - pDeviceCombo->pAdapterInfo = pAdapterInfo; - pDeviceCombo->pDeviceInfo = pDeviceInfo; - - if( FAILED( pDeviceInfo->deviceSettingsComboList.Add( pDeviceCombo ) ) ) - delete pDeviceCombo; - } - } - } - - return S_OK; -} - - - -//-------------------------------------------------------------------------------------- -// Adds all depth/stencil formats that are compatible with the device -// and app to the given D3DDeviceCombo. -//-------------------------------------------------------------------------------------- -void CD3D9Enumeration::BuildDepthStencilFormatList( CD3D9EnumDeviceSettingsCombo* pDeviceCombo ) -{ - D3DFORMAT depthStencilFmt; - for( int idsf = 0; idsf < m_DepthStencilPossibleList.GetSize(); idsf++ ) - { - depthStencilFmt = m_DepthStencilPossibleList.GetAt( idsf ); - if( SUCCEEDED( m_pD3D->CheckDeviceFormat( pDeviceCombo->AdapterOrdinal, - pDeviceCombo->DeviceType, pDeviceCombo->AdapterFormat, - D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, depthStencilFmt ) ) ) - { - if( SUCCEEDED( m_pD3D->CheckDepthStencilMatch( pDeviceCombo->AdapterOrdinal, - pDeviceCombo->DeviceType, pDeviceCombo->AdapterFormat, - pDeviceCombo->BackBufferFormat, depthStencilFmt ) ) ) - { - pDeviceCombo->depthStencilFormatList.Add( depthStencilFmt ); - } - } - } -} - - - - -//-------------------------------------------------------------------------------------- -// Adds all multisample types that are compatible with the device and app to -// the given D3DDeviceCombo. -//-------------------------------------------------------------------------------------- -void CD3D9Enumeration::BuildMultiSampleTypeList( CD3D9EnumDeviceSettingsCombo* pDeviceCombo ) -{ - D3DMULTISAMPLE_TYPE msType; - DWORD msQuality; - for( int imst = 0; imst < m_MultiSampleTypeList.GetSize(); imst++ ) - { - msType = m_MultiSampleTypeList.GetAt( imst ); - if( SUCCEEDED( m_pD3D->CheckDeviceMultiSampleType( pDeviceCombo->AdapterOrdinal, - pDeviceCombo->DeviceType, pDeviceCombo->BackBufferFormat, - pDeviceCombo->Windowed, msType, &msQuality ) ) ) - { - pDeviceCombo->multiSampleTypeList.Add( msType ); - if( msQuality > m_nMultisampleQualityMax + 1 ) - msQuality = m_nMultisampleQualityMax + 1; - pDeviceCombo->multiSampleQualityList.Add( msQuality ); - } - } -} - - - - -//-------------------------------------------------------------------------------------- -// Find any conflicts between the available depth/stencil formats and -// multisample types. -//-------------------------------------------------------------------------------------- -void CD3D9Enumeration::BuildDSMSConflictList( CD3D9EnumDeviceSettingsCombo* pDeviceCombo ) -{ - CD3D9EnumDSMSConflict DSMSConflict; - - for( int iDS = 0; iDS < pDeviceCombo->depthStencilFormatList.GetSize(); iDS++ ) - { - D3DFORMAT dsFmt = pDeviceCombo->depthStencilFormatList.GetAt( iDS ); - - for( int iMS = 0; iMS < pDeviceCombo->multiSampleTypeList.GetSize(); iMS++ ) - { - D3DMULTISAMPLE_TYPE msType = pDeviceCombo->multiSampleTypeList.GetAt( iMS ); - - if( FAILED( m_pD3D->CheckDeviceMultiSampleType( pDeviceCombo->AdapterOrdinal, pDeviceCombo->DeviceType, - dsFmt, pDeviceCombo->Windowed, msType, NULL ) ) ) - { - DSMSConflict.DSFormat = dsFmt; - DSMSConflict.MSType = msType; - pDeviceCombo->DSMSConflictList.Add( DSMSConflict ); - } - } - } -} - - -//-------------------------------------------------------------------------------------- -// Adds all present intervals that are compatible with the device and app -// to the given D3DDeviceCombo. -//-------------------------------------------------------------------------------------- -void CD3D9Enumeration::BuildPresentIntervalList( CD3D9EnumDeviceInfo* pDeviceInfo, - CD3D9EnumDeviceSettingsCombo* pDeviceCombo ) -{ - UINT pi; - for( int ipi = 0; ipi < m_PresentIntervalList.GetSize(); ipi++ ) - { - pi = m_PresentIntervalList.GetAt( ipi ); - if( pDeviceCombo->Windowed ) - { - if( pi == D3DPRESENT_INTERVAL_TWO || - pi == D3DPRESENT_INTERVAL_THREE || - pi == D3DPRESENT_INTERVAL_FOUR ) - { - // These intervals are not supported in windowed mode. - continue; - } - } - // Note that D3DPRESENT_INTERVAL_DEFAULT is zero, so you - // can't do a caps check for it -- it is always available. - if( pi == D3DPRESENT_INTERVAL_DEFAULT || - ( pDeviceInfo->Caps.PresentationIntervals & pi ) ) - { - pDeviceCombo->presentIntervalList.Add( pi ); - } - } -} - - - -//-------------------------------------------------------------------------------------- -// Release all the allocated CD3D9EnumAdapterInfo objects and empty the list -//-------------------------------------------------------------------------------------- -void CD3D9Enumeration::ClearAdapterInfoList() -{ - CD3D9EnumAdapterInfo* pAdapterInfo; - for( int i = 0; i < m_AdapterInfoList.GetSize(); i++ ) - { - pAdapterInfo = m_AdapterInfoList.GetAt( i ); - delete pAdapterInfo; - } - - m_AdapterInfoList.RemoveAll(); -} - - - -//-------------------------------------------------------------------------------------- -// Call GetAdapterInfoList() after Enumerate() to get a STL vector of -// CD3D9EnumAdapterInfo* -//-------------------------------------------------------------------------------------- -CGrowableArray * CD3D9Enumeration::GetAdapterInfoList() -{ - return &m_AdapterInfoList; -} - - - -//-------------------------------------------------------------------------------------- -CD3D9EnumAdapterInfo* CD3D9Enumeration::GetAdapterInfo( UINT AdapterOrdinal ) -{ - for( int iAdapter = 0; iAdapter < m_AdapterInfoList.GetSize(); iAdapter++ ) - { - CD3D9EnumAdapterInfo* pAdapterInfo = m_AdapterInfoList.GetAt( iAdapter ); - if( pAdapterInfo->AdapterOrdinal == AdapterOrdinal ) - return pAdapterInfo; - } - - return NULL; -} - - -//-------------------------------------------------------------------------------------- -CD3D9EnumDeviceInfo* CD3D9Enumeration::GetDeviceInfo( UINT AdapterOrdinal, D3DDEVTYPE DeviceType ) -{ - CD3D9EnumAdapterInfo* pAdapterInfo = GetAdapterInfo( AdapterOrdinal ); - if( pAdapterInfo ) - { - for( int iDeviceInfo = 0; iDeviceInfo < pAdapterInfo->deviceInfoList.GetSize(); iDeviceInfo++ ) - { - CD3D9EnumDeviceInfo* pDeviceInfo = pAdapterInfo->deviceInfoList.GetAt( iDeviceInfo ); - if( pDeviceInfo->DeviceType == DeviceType ) - return pDeviceInfo; - } - } - - return NULL; -} - - -//-------------------------------------------------------------------------------------- -// -//-------------------------------------------------------------------------------------- -CD3D9EnumDeviceSettingsCombo* CD3D9Enumeration::GetDeviceSettingsCombo( UINT AdapterOrdinal, D3DDEVTYPE DeviceType, - D3DFORMAT AdapterFormat, - D3DFORMAT BackBufferFormat, BOOL bWindowed ) -{ - CD3D9EnumDeviceInfo* pDeviceInfo = GetDeviceInfo( AdapterOrdinal, DeviceType ); - if( pDeviceInfo ) - { - for( int iDeviceCombo = 0; iDeviceCombo < pDeviceInfo->deviceSettingsComboList.GetSize(); iDeviceCombo++ ) - { - CD3D9EnumDeviceSettingsCombo* pDeviceSettingsCombo = pDeviceInfo->deviceSettingsComboList.GetAt( - iDeviceCombo ); - if( pDeviceSettingsCombo->AdapterFormat == AdapterFormat && - pDeviceSettingsCombo->BackBufferFormat == BackBufferFormat && - pDeviceSettingsCombo->Windowed == bWindowed ) - return pDeviceSettingsCombo; - } - } - - return NULL; -} - - -//-------------------------------------------------------------------------------------- -// Returns the number of color channel bits in the specified D3DFORMAT -//-------------------------------------------------------------------------------------- -UINT WINAPI DXUTGetD3D9ColorChannelBits( D3DFORMAT fmt ) -{ - switch( fmt ) - { - case D3DFMT_R8G8B8: - return 8; - case D3DFMT_A8R8G8B8: - return 8; - case D3DFMT_X8R8G8B8: - return 8; - case D3DFMT_R5G6B5: - return 5; - case D3DFMT_X1R5G5B5: - return 5; - case D3DFMT_A1R5G5B5: - return 5; - case D3DFMT_A4R4G4B4: - return 4; - case D3DFMT_R3G3B2: - return 2; - case D3DFMT_A8R3G3B2: - return 2; - case D3DFMT_X4R4G4B4: - return 4; - case D3DFMT_A2B10G10R10: - return 10; - case D3DFMT_A8B8G8R8: - return 8; - case D3DFMT_A2R10G10B10: - return 10; - case D3DFMT_A16B16G16R16: - return 16; - default: - return 0; - } -} - - -//-------------------------------------------------------------------------------------- -// Returns the number of alpha channel bits in the specified D3DFORMAT -//-------------------------------------------------------------------------------------- -UINT WINAPI DXUTGetAlphaChannelBits( D3DFORMAT fmt ) -{ - switch( fmt ) - { - case D3DFMT_R8G8B8: - return 0; - case D3DFMT_A8R8G8B8: - return 8; - case D3DFMT_X8R8G8B8: - return 0; - case D3DFMT_R5G6B5: - return 0; - case D3DFMT_X1R5G5B5: - return 0; - case D3DFMT_A1R5G5B5: - return 1; - case D3DFMT_A4R4G4B4: - return 4; - case D3DFMT_R3G3B2: - return 0; - case D3DFMT_A8R3G3B2: - return 8; - case D3DFMT_X4R4G4B4: - return 0; - case D3DFMT_A2B10G10R10: - return 2; - case D3DFMT_A8B8G8R8: - return 8; - case D3DFMT_A2R10G10B10: - return 2; - case D3DFMT_A16B16G16R16: - return 16; - default: - return 0; - } -} - - -//-------------------------------------------------------------------------------------- -// Returns the number of depth bits in the specified D3DFORMAT -//-------------------------------------------------------------------------------------- -UINT WINAPI DXUTGetDepthBits( D3DFORMAT fmt ) -{ - switch( fmt ) - { - case D3DFMT_D32F_LOCKABLE: - case D3DFMT_D32: - return 32; - - case D3DFMT_D24X8: - case D3DFMT_D24S8: - case D3DFMT_D24X4S4: - case D3DFMT_D24FS8: - return 24; - - case D3DFMT_D16_LOCKABLE: - case D3DFMT_D16: - return 16; - - case D3DFMT_D15S1: - return 15; - - default: - return 0; - } -} - - - - -//-------------------------------------------------------------------------------------- -// Returns the number of stencil bits in the specified D3DFORMAT -//-------------------------------------------------------------------------------------- -UINT WINAPI DXUTGetStencilBits( D3DFORMAT fmt ) -{ - switch( fmt ) - { - case D3DFMT_D16_LOCKABLE: - case D3DFMT_D16: - case D3DFMT_D32F_LOCKABLE: - case D3DFMT_D32: - case D3DFMT_D24X8: - return 0; - - case D3DFMT_D15S1: - return 1; - - case D3DFMT_D24X4S4: - return 4; - - case D3DFMT_D24S8: - case D3DFMT_D24FS8: - return 8; - - default: - return 0; - } -} - - - -//-------------------------------------------------------------------------------------- -// Used to sort D3DDISPLAYMODEs -//-------------------------------------------------------------------------------------- -static int __cdecl SortModesCallback( const void* arg1, const void* arg2 ) -{ - D3DDISPLAYMODE* pdm1 = ( D3DDISPLAYMODE* )arg1; - D3DDISPLAYMODE* pdm2 = ( D3DDISPLAYMODE* )arg2; - - if( pdm1->Width > pdm2->Width ) - return 1; - if( pdm1->Width < pdm2->Width ) - return -1; - if( pdm1->Height > pdm2->Height ) - return 1; - if( pdm1->Height < pdm2->Height ) - return -1; - if( pdm1->Format > pdm2->Format ) - return 1; - if( pdm1->Format < pdm2->Format ) - return -1; - if( pdm1->RefreshRate > pdm2->RefreshRate ) - return 1; - if( pdm1->RefreshRate < pdm2->RefreshRate ) - return -1; - return 0; -} - - - -//-------------------------------------------------------------------------------------- -CD3D9EnumAdapterInfo::~CD3D9EnumAdapterInfo( void ) -{ - CD3D9EnumDeviceInfo* pDeviceInfo; - for( int i = 0; i < deviceInfoList.GetSize(); i++ ) - { - pDeviceInfo = deviceInfoList.GetAt( i ); - delete pDeviceInfo; - } - deviceInfoList.RemoveAll(); -} - - - - -//-------------------------------------------------------------------------------------- -CD3D9EnumDeviceInfo::~CD3D9EnumDeviceInfo( void ) -{ - CD3D9EnumDeviceSettingsCombo* pDeviceCombo; - for( int i = 0; i < deviceSettingsComboList.GetSize(); i++ ) - { - pDeviceCombo = deviceSettingsComboList.GetAt( i ); - delete pDeviceCombo; - } - deviceSettingsComboList.RemoveAll(); -} - - -//-------------------------------------------------------------------------------------- -void CD3D9Enumeration::ResetPossibleDepthStencilFormats() -{ - m_DepthStencilPossibleList.RemoveAll(); - m_DepthStencilPossibleList.Add( D3DFMT_D16 ); - m_DepthStencilPossibleList.Add( D3DFMT_D15S1 ); - m_DepthStencilPossibleList.Add( D3DFMT_D24X8 ); - m_DepthStencilPossibleList.Add( D3DFMT_D24S8 ); - m_DepthStencilPossibleList.Add( D3DFMT_D24X4S4 ); - m_DepthStencilPossibleList.Add( D3DFMT_D32 ); -} - - -//-------------------------------------------------------------------------------------- -CGrowableArray * CD3D9Enumeration::GetPossibleDepthStencilFormatList() -{ - return &m_DepthStencilPossibleList; -} - - -//-------------------------------------------------------------------------------------- -CGrowableArray * CD3D9Enumeration::GetPossibleMultisampleTypeList() -{ - return &m_MultiSampleTypeList; -} - - -//-------------------------------------------------------------------------------------- -void CD3D9Enumeration::ResetPossibleMultisampleTypeList() -{ - m_MultiSampleTypeList.RemoveAll(); - m_MultiSampleTypeList.Add( D3DMULTISAMPLE_NONE ); - m_MultiSampleTypeList.Add( D3DMULTISAMPLE_NONMASKABLE ); - m_MultiSampleTypeList.Add( D3DMULTISAMPLE_2_SAMPLES ); - m_MultiSampleTypeList.Add( D3DMULTISAMPLE_3_SAMPLES ); - m_MultiSampleTypeList.Add( D3DMULTISAMPLE_4_SAMPLES ); - m_MultiSampleTypeList.Add( D3DMULTISAMPLE_5_SAMPLES ); - m_MultiSampleTypeList.Add( D3DMULTISAMPLE_6_SAMPLES ); - m_MultiSampleTypeList.Add( D3DMULTISAMPLE_7_SAMPLES ); - m_MultiSampleTypeList.Add( D3DMULTISAMPLE_8_SAMPLES ); - m_MultiSampleTypeList.Add( D3DMULTISAMPLE_9_SAMPLES ); - m_MultiSampleTypeList.Add( D3DMULTISAMPLE_10_SAMPLES ); - m_MultiSampleTypeList.Add( D3DMULTISAMPLE_11_SAMPLES ); - m_MultiSampleTypeList.Add( D3DMULTISAMPLE_12_SAMPLES ); - m_MultiSampleTypeList.Add( D3DMULTISAMPLE_13_SAMPLES ); - m_MultiSampleTypeList.Add( D3DMULTISAMPLE_14_SAMPLES ); - m_MultiSampleTypeList.Add( D3DMULTISAMPLE_15_SAMPLES ); - m_MultiSampleTypeList.Add( D3DMULTISAMPLE_16_SAMPLES ); -} - - -//-------------------------------------------------------------------------------------- -void CD3D9Enumeration::GetPossibleVertexProcessingList( bool* pbSoftwareVP, bool* pbHardwareVP, bool* pbPureHarewareVP, - bool* pbMixedVP ) -{ - *pbSoftwareVP = m_bSoftwareVP; - *pbHardwareVP = m_bHardwareVP; - *pbPureHarewareVP = m_bPureHarewareVP; - *pbMixedVP = m_bMixedVP; -} - - -//-------------------------------------------------------------------------------------- -void CD3D9Enumeration::SetPossibleVertexProcessingList( bool bSoftwareVP, bool bHardwareVP, bool bPureHarewareVP, - bool bMixedVP ) -{ - m_bSoftwareVP = bSoftwareVP; - m_bHardwareVP = bHardwareVP; - m_bPureHarewareVP = bPureHarewareVP; - m_bMixedVP = bMixedVP; -} - - -//-------------------------------------------------------------------------------------- -CGrowableArray * CD3D9Enumeration::GetPossiblePresentIntervalList() -{ - return &m_PresentIntervalList; -} - - -//-------------------------------------------------------------------------------------- -void CD3D9Enumeration::ResetPossiblePresentIntervalList() -{ - m_PresentIntervalList.RemoveAll(); - m_PresentIntervalList.Add( D3DPRESENT_INTERVAL_IMMEDIATE ); - m_PresentIntervalList.Add( D3DPRESENT_INTERVAL_DEFAULT ); - m_PresentIntervalList.Add( D3DPRESENT_INTERVAL_ONE ); - m_PresentIntervalList.Add( D3DPRESENT_INTERVAL_TWO ); - m_PresentIntervalList.Add( D3DPRESENT_INTERVAL_THREE ); - m_PresentIntervalList.Add( D3DPRESENT_INTERVAL_FOUR ); -} - - -//-------------------------------------------------------------------------------------- -void CD3D9Enumeration::SetResolutionMinMax( UINT nMinWidth, UINT nMinHeight, - UINT nMaxWidth, UINT nMaxHeight ) -{ - m_nMinWidth = nMinWidth; - m_nMinHeight = nMinHeight; - m_nMaxWidth = nMaxWidth; - m_nMaxHeight = nMaxHeight; -} - - -//-------------------------------------------------------------------------------------- -void CD3D9Enumeration::SetRefreshMinMax( UINT nMin, UINT nMax ) -{ - m_nRefreshMin = nMin; - m_nRefreshMax = nMax; -} - - -//-------------------------------------------------------------------------------------- -void CD3D9Enumeration::SetMultisampleQualityMax( UINT nMax ) -{ - if( nMax > 0xFFFF ) - nMax = 0xFFFF; - m_nMultisampleQualityMax = nMax; -} - - - -//-------------------------------------------------------------------------------------- -// Returns a ranking number that describes how closely this device -// combo matches the optimal combo based on the match options and the optimal device settings -//-------------------------------------------------------------------------------------- -float DXUTRankD3D9DeviceCombo( CD3D9EnumDeviceSettingsCombo* pDeviceSettingsCombo, - DXUTD3D9DeviceSettings* pOptimalDeviceSettings, - D3DDISPLAYMODE* pAdapterDesktopDisplayMode, - int &bestModeIndex, - int &bestMSAAIndex - ) -{ - float fCurRanking = 0.0f; - - // Arbitrary weights. Gives preference to the ordinal, device type, and windowed - const float fAdapterOrdinalWeight = 1000.0f; - const float fDeviceTypeWeight = 100.0f; - const float fWindowWeight = 10.0f; - const float fAdapterFormatWeight = 1.0f; - const float fVertexProcessingWeight = 1.0f; - const float fResolutionWeight = 1.0f; - const float fBackBufferFormatWeight = 1.0f; - const float fMultiSampleWeight = 1.0f; - const float fDepthStencilWeight = 1.0f; - const float fRefreshRateWeight = 1.0f; - const float fPresentIntervalWeight = 1.0f; - - //--------------------- - // Adapter ordinal - //--------------------- - if( pDeviceSettingsCombo->AdapterOrdinal == pOptimalDeviceSettings->AdapterOrdinal ) - fCurRanking += fAdapterOrdinalWeight; - - //--------------------- - // Device type - //--------------------- - if( pDeviceSettingsCombo->DeviceType == pOptimalDeviceSettings->DeviceType ) - fCurRanking += fDeviceTypeWeight; - // Slightly prefer HAL - if( pDeviceSettingsCombo->DeviceType == D3DDEVTYPE_HAL ) - fCurRanking += 0.1f; - - //--------------------- - // Windowed - //--------------------- - if( pDeviceSettingsCombo->Windowed == pOptimalDeviceSettings->pp.Windowed ) - fCurRanking += fWindowWeight; - - //--------------------- - // Adapter format - //--------------------- - if( pDeviceSettingsCombo->AdapterFormat == pOptimalDeviceSettings->AdapterFormat ) - { - fCurRanking += fAdapterFormatWeight; - } - else - { - int nBitDepthDelta = abs( ( long )DXUTGetD3D9ColorChannelBits( pDeviceSettingsCombo->AdapterFormat ) - - ( long )DXUTGetD3D9ColorChannelBits( pOptimalDeviceSettings->AdapterFormat ) ); - float fScale = __max( 0.9f - ( float )nBitDepthDelta * 0.2f, 0.0f ); - fCurRanking += fScale * fAdapterFormatWeight; - } - - if( !pDeviceSettingsCombo->Windowed ) - { - // Slightly prefer when it matches the desktop format or is D3DFMT_X8R8G8B8 - bool bAdapterOptimalMatch; - if( DXUTGetD3D9ColorChannelBits( pAdapterDesktopDisplayMode->Format ) >= 8 ) - bAdapterOptimalMatch = ( pDeviceSettingsCombo->AdapterFormat == pAdapterDesktopDisplayMode->Format ); - else - bAdapterOptimalMatch = ( pDeviceSettingsCombo->AdapterFormat == D3DFMT_X8R8G8B8 ); - - if( bAdapterOptimalMatch ) - fCurRanking += 0.1f; - } - - //--------------------- - // Vertex processing - //--------------------- - if( ( pOptimalDeviceSettings->BehaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING ) != 0 || - ( pOptimalDeviceSettings->BehaviorFlags & D3DCREATE_MIXED_VERTEXPROCESSING ) != 0 ) - { - if( ( pDeviceSettingsCombo->pDeviceInfo->Caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ) != 0 ) - fCurRanking += fVertexProcessingWeight; - } - // Slightly prefer HW T&L - if( ( pDeviceSettingsCombo->pDeviceInfo->Caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ) != 0 ) - fCurRanking += 0.1f; - - //--------------------- - // Resolution - //--------------------- - bool bResolutionFound = false; - unsigned int best = 0xffffffff; - bestModeIndex=0; - - - - - - for( int idm = 0; idm < pDeviceSettingsCombo->pAdapterInfo->displayModeList.GetSize(); idm++ ) - { - D3DDISPLAYMODE displayMode = pDeviceSettingsCombo->pAdapterInfo->displayModeList.GetAt( idm ); - if( displayMode.Format != pDeviceSettingsCombo->AdapterFormat ) - continue; - if( displayMode.Width == pOptimalDeviceSettings->pp.BackBufferWidth && - displayMode.Height == pOptimalDeviceSettings->pp.BackBufferHeight ) - bResolutionFound = true; - - unsigned int current = - (UINT) abs ((int)displayMode.Width - (int)pOptimalDeviceSettings->pp.BackBufferWidth) + - (UINT) abs ((int)displayMode.Height - (int)pOptimalDeviceSettings->pp.BackBufferHeight ); - if (current < best) { - best = current; - bestModeIndex= idm; - - } - - - } - if( bResolutionFound ) - fCurRanking += fResolutionWeight; - - //--------------------- - // Back buffer format - //--------------------- - if( pDeviceSettingsCombo->BackBufferFormat == pOptimalDeviceSettings->pp.BackBufferFormat ) - { - fCurRanking += fBackBufferFormatWeight; - } - else - { - int nBitDepthDelta = abs( ( long )DXUTGetD3D9ColorChannelBits( pDeviceSettingsCombo->BackBufferFormat ) - - ( long )DXUTGetD3D9ColorChannelBits( pOptimalDeviceSettings->pp.BackBufferFormat ) ); - float fScale = __max( 0.9f - ( float )nBitDepthDelta * 0.2f, 0.0f ); - fCurRanking += fScale * fBackBufferFormatWeight; - } - - // Check if this back buffer format is the same as - // the adapter format since this is preferred. - bool bAdapterMatchesBB = ( pDeviceSettingsCombo->BackBufferFormat == pDeviceSettingsCombo->AdapterFormat ); - if( bAdapterMatchesBB ) - fCurRanking += 0.1f; - - //--------------------- - // Back buffer count - //--------------------- - // No caps for the back buffer count - - //--------------------- - // Multisample - //--------------------- - bool bMultiSampleFound = false; - for( int i = 0; i < pDeviceSettingsCombo->multiSampleTypeList.GetSize(); i++ ) - { - D3DMULTISAMPLE_TYPE msType = pDeviceSettingsCombo->multiSampleTypeList.GetAt( i ); - DWORD msQuality = pDeviceSettingsCombo->multiSampleQualityList.GetAt( i ); - - if( msType == pOptimalDeviceSettings->pp.MultiSampleType && - msQuality > pOptimalDeviceSettings->pp.MultiSampleQuality ) - { - bMultiSampleFound = true; - bestMSAAIndex = i; - break; - } - } - if( bMultiSampleFound ) - fCurRanking += fMultiSampleWeight; - - //--------------------- - // Swap effect - //--------------------- - // No caps for swap effects - - //--------------------- - // Depth stencil - //--------------------- - if( pDeviceSettingsCombo->depthStencilFormatList.Contains( pOptimalDeviceSettings->pp.AutoDepthStencilFormat ) ) - fCurRanking += fDepthStencilWeight; - - //--------------------- - // Present flags - //--------------------- - // No caps for the present flags - - //--------------------- - // Refresh rate - //--------------------- - bool bRefreshFound = false; - for( int idm = 0; idm < pDeviceSettingsCombo->pAdapterInfo->displayModeList.GetSize(); idm++ ) - { - D3DDISPLAYMODE displayMode = pDeviceSettingsCombo->pAdapterInfo->displayModeList.GetAt( idm ); - if( displayMode.Format != pDeviceSettingsCombo->AdapterFormat ) - continue; - if( displayMode.RefreshRate == pOptimalDeviceSettings->pp.FullScreen_RefreshRateInHz ) - bRefreshFound = true; - } - if( bRefreshFound ) - fCurRanking += fRefreshRateWeight; - - //--------------------- - // Present interval - //--------------------- - // If keep present interval then check that the present interval is supported by this combo - if( pDeviceSettingsCombo->presentIntervalList.Contains( pOptimalDeviceSettings->pp.PresentationInterval ) ) - fCurRanking += fPresentIntervalWeight; - - return fCurRanking; -} - diff --git a/FriedLiver/Source/DXUT/Core/DXUTDevice9.h b/FriedLiver/Source/DXUT/Core/DXUTDevice9.h deleted file mode 100644 index c5ee6db8..00000000 --- a/FriedLiver/Source/DXUT/Core/DXUTDevice9.h +++ /dev/null @@ -1,207 +0,0 @@ -//-------------------------------------------------------------------------------------- -// File: DXUTDevice9.h -// -// Enumerates D3D adapters, devices, modes, etc. -// -// Copyright (c) Microsoft Corporation. All rights reserved. -//-------------------------------------------------------------------------------------- -#pragma once -#ifndef DXUT_DEVICE9_H -#define DXUT_DEVICE9_H - -//void DXUTApplyDefaultDeviceSettings(DXUTDeviceSettings *modifySettings); - -//-------------------------------------------------------------------------------------- -// Functions to get bit depth from formats -//-------------------------------------------------------------------------------------- -UINT WINAPI DXUTGetD3D9ColorChannelBits( D3DFORMAT fmt ); -UINT WINAPI DXUTGetAlphaChannelBits( D3DFORMAT fmt ); -UINT WINAPI DXUTGetStencilBits( D3DFORMAT fmt ); -UINT WINAPI DXUTGetDepthBits( D3DFORMAT fmt ); -UINT WINAPI DXUTGetDXGIColorChannelBits( DXGI_FORMAT fmt ); - - -//-------------------------------------------------------------------------------------- -// Forward declarations -//-------------------------------------------------------------------------------------- - -class CD3D9EnumAdapterInfo; -class CD3D9EnumDeviceInfo; -struct CD3D9EnumDeviceSettingsCombo; -struct CD3D9EnumDSMSConflict; - - - - - -//-------------------------------------------------------------------------------------- -// Optional memory create/destory functions. If not call, these will be called automatically -//-------------------------------------------------------------------------------------- -HRESULT WINAPI DXUTCreateD3D9Enumeration(); -void WINAPI DXUTDestroyD3D9Enumeration(); - - - -//-------------------------------------------------------------------------------------- -// Enumerates available Direct3D9 adapters, devices, modes, etc. -// Use DXUTGetD3D9Enumeration() to access global instance -//-------------------------------------------------------------------------------------- -class CD3D9Enumeration -{ -public: - // These should be called before Enumerate(). - // - // Use these calls and the IsDeviceAcceptable to control the contents of - // the enumeration object, which affects the device selection and the device settings dialog. - void SetRequirePostPixelShaderBlending( bool bRequire ) { m_bRequirePostPixelShaderBlending = bRequire; } - void SetResolutionMinMax( UINT nMinWidth, UINT nMinHeight, UINT nMaxWidth, UINT nMaxHeight ); - void SetRefreshMinMax( UINT nMin, UINT nMax ); - void SetMultisampleQualityMax( UINT nMax ); - void GetPossibleVertexProcessingList( bool* pbSoftwareVP, bool* pbHardwareVP, bool* pbPureHarewareVP, bool* pbMixedVP ); - void SetPossibleVertexProcessingList( bool bSoftwareVP, bool bHardwareVP, bool bPureHarewareVP, bool bMixedVP ); - CGrowableArray* GetPossibleDepthStencilFormatList(); - CGrowableArray* GetPossibleMultisampleTypeList(); - CGrowableArray* GetPossiblePresentIntervalList(); - void ResetPossibleDepthStencilFormats(); - void ResetPossibleMultisampleTypeList(); - void ResetPossiblePresentIntervalList(); - - // Call Enumerate() to enumerate available D3D adapters, devices, modes, etc. - bool HasEnumerated() { return m_bHasEnumerated; } - HRESULT Enumerate( LPDXUTCALLBACKISD3D9DEVICEACCEPTABLE IsD3D9DeviceAcceptableFunc = NULL, - void* pIsD3D9DeviceAcceptableFuncUserContext = NULL ); - - // These should be called after Enumerate() is called - CGrowableArray* GetAdapterInfoList(); - CD3D9EnumAdapterInfo* GetAdapterInfo( UINT AdapterOrdinal ); - CD3D9EnumDeviceInfo* GetDeviceInfo( UINT AdapterOrdinal, D3DDEVTYPE DeviceType ); - CD3D9EnumDeviceSettingsCombo* GetDeviceSettingsCombo( DXUTD3D9DeviceSettings* pD3D9DeviceSettings ) { return GetDeviceSettingsCombo( pD3D9DeviceSettings->AdapterOrdinal, pD3D9DeviceSettings->DeviceType, pD3D9DeviceSettings->AdapterFormat, pD3D9DeviceSettings->pp.BackBufferFormat, pD3D9DeviceSettings->pp.Windowed ); } - CD3D9EnumDeviceSettingsCombo* GetDeviceSettingsCombo( UINT AdapterOrdinal, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat, BOOL Windowed ); - - ~CD3D9Enumeration(); - -private: - friend HRESULT WINAPI DXUTCreateD3D9Enumeration(); - - // Use DXUTGetD3D9Enumeration() to access global instance - CD3D9Enumeration(); - - bool m_bHasEnumerated; - IDirect3D9* m_pD3D; - LPDXUTCALLBACKISD3D9DEVICEACCEPTABLE m_IsD3D9DeviceAcceptableFunc; - void* m_pIsD3D9DeviceAcceptableFuncUserContext; - bool m_bRequirePostPixelShaderBlending; - CGrowableArray m_DepthStencilPossibleList; - CGrowableArray m_MultiSampleTypeList; - CGrowableArray m_PresentIntervalList; - - bool m_bSoftwareVP; - bool m_bHardwareVP; - bool m_bPureHarewareVP; - bool m_bMixedVP; - - UINT m_nMinWidth; - UINT m_nMaxWidth; - UINT m_nMinHeight; - UINT m_nMaxHeight; - UINT m_nRefreshMin; - UINT m_nRefreshMax; - UINT m_nMultisampleQualityMax; - - // Array of CD3D9EnumAdapterInfo* with unique AdapterOrdinals - CGrowableArray m_AdapterInfoList; - - HRESULT EnumerateDevices( CD3D9EnumAdapterInfo* pAdapterInfo, CGrowableArray* pAdapterFormatList ); - HRESULT EnumerateDeviceCombos( CD3D9EnumAdapterInfo* pAdapterInfo, CD3D9EnumDeviceInfo* pDeviceInfo, CGrowableArray* pAdapterFormatList ); - void BuildDepthStencilFormatList( CD3D9EnumDeviceSettingsCombo* pDeviceCombo ); - void BuildMultiSampleTypeList( CD3D9EnumDeviceSettingsCombo* pDeviceCombo ); - void BuildDSMSConflictList( CD3D9EnumDeviceSettingsCombo* pDeviceCombo ); - void BuildPresentIntervalList( CD3D9EnumDeviceInfo* pDeviceInfo, CD3D9EnumDeviceSettingsCombo* pDeviceCombo ); - void ClearAdapterInfoList(); -}; - -CD3D9Enumeration* WINAPI DXUTGetD3D9Enumeration( bool bForceEnumerate = false ); - - -//-------------------------------------------------------------------------------------- -// A class describing an adapter which contains a unique adapter ordinal -// that is installed on the system -//-------------------------------------------------------------------------------------- -class CD3D9EnumAdapterInfo -{ -public: - ~CD3D9EnumAdapterInfo(); - - UINT AdapterOrdinal; - D3DADAPTER_IDENTIFIER9 AdapterIdentifier; - WCHAR szUniqueDescription[256]; - - CGrowableArray displayModeList; // Array of supported D3DDISPLAYMODEs - CGrowableArray deviceInfoList; // Array of CD3D9EnumDeviceInfo* with unique supported DeviceTypes -}; - - -//-------------------------------------------------------------------------------------- -// A class describing a Direct3D device that contains a -// unique supported device type -//-------------------------------------------------------------------------------------- -class CD3D9EnumDeviceInfo -{ -public: - ~CD3D9EnumDeviceInfo(); - - UINT AdapterOrdinal; - D3DDEVTYPE DeviceType; - D3DCAPS9 Caps; - - // List of CD3D9EnumDeviceSettingsCombo* with a unique set - // of AdapterFormat, BackBufferFormat, and Windowed - CGrowableArray deviceSettingsComboList; -}; - - -//-------------------------------------------------------------------------------------- -// A struct describing device settings that contains a unique combination of -// adapter format, back buffer format, and windowed that is compatible with a -// particular Direct3D device and the app. -//-------------------------------------------------------------------------------------- -struct CD3D9EnumDeviceSettingsCombo -{ - UINT AdapterOrdinal; - D3DDEVTYPE DeviceType; - D3DFORMAT AdapterFormat; - D3DFORMAT BackBufferFormat; - BOOL Windowed; - - CGrowableArray depthStencilFormatList; // List of D3DFORMATs - CGrowableArray multiSampleTypeList; // List of D3DMULTISAMPLE_TYPEs - CGrowableArray multiSampleQualityList; // List of number of quality levels for each multisample type - CGrowableArray presentIntervalList; // List of D3DPRESENT flags - CGrowableArray DSMSConflictList; // List of CD3D9EnumDSMSConflict - - CD3D9EnumAdapterInfo* pAdapterInfo; - CD3D9EnumDeviceInfo* pDeviceInfo; -}; - - -//-------------------------------------------------------------------------------------- -// A depth/stencil buffer format that is incompatible with a -// multisample type. -//-------------------------------------------------------------------------------------- -struct CD3D9EnumDSMSConflict -{ - D3DFORMAT DSFormat; - D3DMULTISAMPLE_TYPE MSType; -}; - - - -float DXUTRankD3D9DeviceCombo( CD3D9EnumDeviceSettingsCombo* pDeviceSettingsCombo, - DXUTD3D9DeviceSettings* pOptimalDeviceSettings, - D3DDISPLAYMODE* pAdapterDesktopDisplayMode, - int &bestModeIndex, - int &bestMSAAIndex - ); - - -#endif diff --git a/FriedLiver/Source/DXUT/Core/ScreenGrab.cpp b/FriedLiver/Source/DXUT/Core/ScreenGrab.cpp index 4296091c..a028a91a 100644 --- a/FriedLiver/Source/DXUT/Core/ScreenGrab.cpp +++ b/FriedLiver/Source/DXUT/Core/ScreenGrab.cpp @@ -82,9 +82,6 @@ namespace #define DDS_HEADER_FLAGS_PITCH 0x00000008 // DDSD_PITCH #define DDS_HEADER_FLAGS_LINEARSIZE 0x00080000 // DDSD_LINEARSIZE - #define DDS_HEIGHT 0x00000002 // DDSD_HEIGHT - #define DDS_WIDTH 0x00000004 // DDSD_WIDTH - #define DDS_SURFACE_FLAGS_TEXTURE 0x00001000 // DDSCAPS_TEXTURE typedef struct @@ -215,7 +212,7 @@ namespace } } - void clear() { m_handle = 0; } + void clear() { m_handle = nullptr; } private: HANDLE m_handle; @@ -227,7 +224,7 @@ namespace class auto_delete_file_wic { public: - auto_delete_file_wic(ComPtr& hFile, const wchar_t* szFile) : m_handle(hFile), m_filename(szFile) {} + auto_delete_file_wic(ComPtr& hFile, const wchar_t* szFile) : m_filename(szFile), m_handle(hFile) {} ~auto_delete_file_wic() { if (m_filename) @@ -237,7 +234,7 @@ namespace } } - void clear() { m_filename = 0; } + void clear() { m_filename = nullptr; } private: const wchar_t* m_filename; @@ -436,17 +433,17 @@ namespace //-------------------------------------------------------------------------------------- // Get surface information for a particular format //-------------------------------------------------------------------------------------- - void GetSurfaceInfo( + HRESULT GetSurfaceInfo( _In_ size_t width, _In_ size_t height, _In_ DXGI_FORMAT fmt, _Out_opt_ size_t* outNumBytes, _Out_opt_ size_t* outRowBytes, - _Out_opt_ size_t* outNumRows ) + _Out_opt_ size_t* outNumRows) { - size_t numBytes = 0; - size_t rowBytes = 0; - size_t numRows = 0; + uint64_t numBytes = 0; + uint64_t rowBytes = 0; + uint64_t numRows = 0; bool bc = false; bool packed = false; @@ -460,7 +457,7 @@ namespace case DXGI_FORMAT_BC4_TYPELESS: case DXGI_FORMAT_BC4_UNORM: case DXGI_FORMAT_BC4_SNORM: - bc=true; + bc = true; bpe = 8; break; @@ -507,19 +504,22 @@ namespace planar = true; bpe = 4; break; + + default: + break; } if (bc) { - size_t numBlocksWide = 0; + uint64_t numBlocksWide = 0; if (width > 0) { - numBlocksWide = std::max( 1, (width + 3) / 4 ); + numBlocksWide = std::max(1u, (uint64_t(width) + 3u) / 4u); } - size_t numBlocksHigh = 0; + uint64_t numBlocksHigh = 0; if (height > 0) { - numBlocksHigh = std::max( 1, (height + 3) / 4 ); + numBlocksHigh = std::max(1u, (uint64_t(height) + 3u) / 4u); } rowBytes = numBlocksWide * bpe; numRows = numBlocksHigh; @@ -527,42 +527,55 @@ namespace } else if (packed) { - rowBytes = ( ( width + 1 ) >> 1 ) * bpe; - numRows = height; + rowBytes = ((uint64_t(width) + 1u) >> 1) * bpe; + numRows = uint64_t(height); numBytes = rowBytes * height; } - else if ( fmt == DXGI_FORMAT_NV11 ) + else if (fmt == DXGI_FORMAT_NV11) { - rowBytes = ( ( width + 3 ) >> 2 ) * 4; - numRows = height * 2; // Direct3D makes this simplifying assumption, although it is larger than the 4:1:1 data + rowBytes = ((uint64_t(width) + 3u) >> 2) * 4u; + numRows = uint64_t(height) * 2u; // Direct3D makes this simplifying assumption, although it is larger than the 4:1:1 data numBytes = rowBytes * numRows; } else if (planar) { - rowBytes = ( ( width + 1 ) >> 1 ) * bpe; - numBytes = ( rowBytes * height ) + ( ( rowBytes * height + 1 ) >> 1 ); - numRows = height + ( ( height + 1 ) >> 1 ); + rowBytes = ((uint64_t(width) + 1u) >> 1) * bpe; + numBytes = (rowBytes * uint64_t(height)) + ((rowBytes * uint64_t(height) + 1u) >> 1); + numRows = height + ((uint64_t(height) + 1u) >> 1); } else { - size_t bpp = BitsPerPixel( fmt ); - rowBytes = ( width * bpp + 7 ) / 8; // round up to nearest byte - numRows = height; + size_t bpp = BitsPerPixel(fmt); + if (!bpp) + return E_INVALIDARG; + + rowBytes = (uint64_t(width) * bpp + 7u) / 8u; // round up to nearest byte + numRows = uint64_t(height); numBytes = rowBytes * height; } +#if defined(_M_IX86) || defined(_M_ARM) || defined(_M_HYBRID_X86_ARM64) + static_assert(sizeof(size_t) == 4, "Not a 32-bit platform!"); + if (numBytes > UINT32_MAX || rowBytes > UINT32_MAX || numRows > UINT32_MAX) + return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); +#else + static_assert(sizeof(size_t) == 8, "Not a 64-bit platform!"); +#endif + if (outNumBytes) { - *outNumBytes = numBytes; + *outNumBytes = static_cast(numBytes); } if (outRowBytes) { - *outRowBytes = rowBytes; + *outRowBytes = static_cast(rowBytes); } if (outNumRows) { - *outNumRows = numRows; + *outNumRows = static_cast(numRows); } + + return S_OK; } @@ -613,7 +626,7 @@ namespace return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED ); ComPtr pTexture; - HRESULT hr = pSource->QueryInterface(IID_PPV_ARGS(pTexture.GetAddressOf())); + HRESULT hr = pSource->QueryInterface(IID_ID3D11Texture2D, reinterpret_cast(pTexture.GetAddressOf())); if ( FAILED(hr) ) return hr; @@ -631,7 +644,7 @@ namespace desc.SampleDesc.Quality = 0; ComPtr pTemp; - hr = d3dDevice->CreateTexture2D( &desc, 0, pTemp.GetAddressOf() ); + hr = d3dDevice->CreateTexture2D( &desc, nullptr, pTemp.GetAddressOf() ); if ( FAILED(hr) ) return hr; @@ -661,7 +674,7 @@ namespace desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; desc.Usage = D3D11_USAGE_STAGING; - hr = d3dDevice->CreateTexture2D(&desc, 0, pStaging.ReleaseAndGetAddressOf()); + hr = d3dDevice->CreateTexture2D(&desc, nullptr, pStaging.ReleaseAndGetAddressOf()); if ( FAILED(hr) ) return hr; @@ -682,7 +695,7 @@ namespace desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; desc.Usage = D3D11_USAGE_STAGING; - hr = d3dDevice->CreateTexture2D(&desc, 0, pStaging.ReleaseAndGetAddressOf()); + hr = d3dDevice->CreateTexture2D(&desc, nullptr, pStaging.ReleaseAndGetAddressOf()); if ( FAILED(hr) ) return hr; @@ -747,9 +760,11 @@ namespace //-------------------------------------------------------------------------------------- -HRESULT DirectX::SaveDDSTextureToFile( _In_ ID3D11DeviceContext* pContext, - _In_ ID3D11Resource* pSource, - _In_z_ const wchar_t* fileName ) +_Use_decl_annotations_ +HRESULT DirectX::SaveDDSTextureToFile( + ID3D11DeviceContext* pContext, + ID3D11Resource* pSource, + const wchar_t* fileName ) { if ( !fileName ) return E_INVALIDARG; @@ -836,7 +851,7 @@ HRESULT DirectX::SaveDDSTextureToFile( _In_ ID3D11DeviceContext* pContext, memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_DX10, sizeof(DDS_PIXELFORMAT) ); headerSize += sizeof(DDS_HEADER_DXT10); - extHeader = reinterpret_cast( reinterpret_cast(&fileHeader[0]) + sizeof(uint32_t) + sizeof(DDS_HEADER) ); + extHeader = reinterpret_cast( fileHeader + sizeof(uint32_t) + sizeof(DDS_HEADER) ); memset( extHeader, 0, sizeof(DDS_HEADER_DXT10) ); extHeader->dxgiFormat = desc.Format; extHeader->resourceDimension = D3D11_RESOURCE_DIMENSION_TEXTURE2D; @@ -845,7 +860,12 @@ HRESULT DirectX::SaveDDSTextureToFile( _In_ ID3D11DeviceContext* pContext, } size_t rowPitch, slicePitch, rowCount; - GetSurfaceInfo( desc.Width, desc.Height, desc.Format, &slicePitch, &rowPitch, &rowCount ); + hr = GetSurfaceInfo( desc.Width, desc.Height, desc.Format, &slicePitch, &rowPitch, &rowCount ); + if (FAILED(hr)) + return hr; + + if (rowPitch > UINT32_MAX || slicePitch > UINT32_MAX) + return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); if ( IsCompressed( desc.Format ) ) { @@ -868,7 +888,7 @@ HRESULT DirectX::SaveDDSTextureToFile( _In_ ID3D11DeviceContext* pContext, if ( FAILED(hr) ) return hr; - auto sptr = reinterpret_cast( mapped.pData ); + auto sptr = static_cast( mapped.pData ); if ( !sptr ) { pContext->Unmap( pStaging.Get(), 0 ); @@ -907,12 +927,15 @@ HRESULT DirectX::SaveDDSTextureToFile( _In_ ID3D11DeviceContext* pContext, } //-------------------------------------------------------------------------------------- -HRESULT DirectX::SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext, - _In_ ID3D11Resource* pSource, - _In_ REFGUID guidContainerFormat, - _In_z_ const wchar_t* fileName, - _In_opt_ const GUID* targetFormat, - _In_opt_ std::function setCustomProps ) +_Use_decl_annotations_ +HRESULT DirectX::SaveWICTextureToFile( + ID3D11DeviceContext* pContext, + ID3D11Resource* pSource, + REFGUID guidContainerFormat, + const wchar_t* fileName, + const GUID* targetFormat, + std::function setCustomProps, + bool forceSRGB) { if ( !fileName ) return E_INVALIDARG; @@ -925,7 +948,7 @@ HRESULT DirectX::SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext, // Determine source format's WIC equivalent WICPixelFormatGUID pfGuid; - bool sRGB = false; + bool sRGB = forceSRGB; switch ( desc.Format ) { case DXGI_FORMAT_R32G32B32A32_FLOAT: pfGuid = GUID_WICPixelFormat128bppRGBAFloat; break; @@ -1039,7 +1062,7 @@ HRESULT DirectX::SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext, } else { - // Screenshots don’t typically include the alpha channel of the render target + // Screenshots don't typically include the alpha channel of the render target switch ( desc.Format ) { #if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE) @@ -1143,7 +1166,7 @@ HRESULT DirectX::SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext, ComPtr source; hr = pWIC->CreateBitmapFromMemory( desc.Width, desc.Height, pfGuid, mapped.RowPitch, mapped.RowPitch * desc.Height, - reinterpret_cast( mapped.pData ), source.GetAddressOf() ); + static_cast( mapped.pData ), source.GetAddressOf() ); if ( FAILED(hr) ) { pContext->Unmap( pStaging.Get(), 0 ); @@ -1183,7 +1206,7 @@ HRESULT DirectX::SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext, else { // No conversion required - hr = frame->WritePixels( desc.Height, mapped.RowPitch, mapped.RowPitch * desc.Height, reinterpret_cast( mapped.pData ) ); + hr = frame->WritePixels( desc.Height, mapped.RowPitch, mapped.RowPitch * desc.Height, static_cast( mapped.pData ) ); if ( FAILED(hr) ) return hr; } diff --git a/FriedLiver/Source/DXUT/Core/ScreenGrab.h b/FriedLiver/Source/DXUT/Core/ScreenGrab.h index 1f185394..0bb12abc 100644 --- a/FriedLiver/Source/DXUT/Core/ScreenGrab.h +++ b/FriedLiver/Source/DXUT/Core/ScreenGrab.h @@ -19,21 +19,23 @@ #include -#include -#include +#include #include namespace DirectX { - HRESULT SaveDDSTextureToFile( _In_ ID3D11DeviceContext* pContext, - _In_ ID3D11Resource* pSource, - _In_z_ const wchar_t* fileName ); + HRESULT __cdecl SaveDDSTextureToFile( + _In_ ID3D11DeviceContext* pContext, + _In_ ID3D11Resource* pSource, + _In_z_ const wchar_t* fileName); - HRESULT SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext, - _In_ ID3D11Resource* pSource, - _In_ REFGUID guidContainerFormat, - _In_z_ const wchar_t* fileName, - _In_opt_ const GUID* targetFormat = nullptr, - _In_opt_ std::function setCustomProps = nullptr ); -} \ No newline at end of file + HRESULT __cdecl SaveWICTextureToFile( + _In_ ID3D11DeviceContext* pContext, + _In_ ID3D11Resource* pSource, + _In_ REFGUID guidContainerFormat, + _In_z_ const wchar_t* fileName, + _In_opt_ const GUID* targetFormat = nullptr, + _In_opt_ std::function setCustomProps = nullptr, + _In_ bool forceSRGB = false); +} diff --git a/FriedLiver/Source/DXUT/Core/WICTextureLoader.cpp b/FriedLiver/Source/DXUT/Core/WICTextureLoader.cpp index f74bee45..fcc0bb6a 100644 --- a/FriedLiver/Source/DXUT/Core/WICTextureLoader.cpp +++ b/FriedLiver/Source/DXUT/Core/WICTextureLoader.cpp @@ -313,6 +313,9 @@ namespace if (FAILED(hr)) return hr; + if (maxsize > UINT32_MAX) + return E_INVALIDARG; + assert(width > 0 && height > 0); if (!maxsize) @@ -374,7 +377,7 @@ namespace return hr; WICPixelFormatGUID convertGUID; - memcpy(&convertGUID, &pixelFormat, sizeof(WICPixelFormatGUID)); + memcpy_s(&convertGUID, sizeof(WICPixelFormatGUID), &pixelFormat, sizeof(GUID)); size_t bpp = 0; @@ -386,14 +389,14 @@ namespace #if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE) if (g_WIC2) { - memcpy(&convertGUID, &GUID_WICPixelFormat96bppRGBFloat, sizeof(WICPixelFormatGUID)); + memcpy_s(&convertGUID, sizeof(WICPixelFormatGUID), &GUID_WICPixelFormat96bppRGBFloat, sizeof(GUID)); format = DXGI_FORMAT_R32G32B32_FLOAT; bpp = 96; } else #endif { - memcpy(&convertGUID, &GUID_WICPixelFormat128bppRGBAFloat, sizeof(WICPixelFormatGUID)); + memcpy_s(&convertGUID, sizeof(WICPixelFormatGUID), &GUID_WICPixelFormat128bppRGBAFloat, sizeof(GUID)); format = DXGI_FORMAT_R32G32B32A32_FLOAT; bpp = 128; } @@ -404,7 +407,7 @@ namespace { if (memcmp(&g_WICConvert[i].source, &pixelFormat, sizeof(WICPixelFormatGUID)) == 0) { - memcpy(&convertGUID, &g_WICConvert[i].target, sizeof(WICPixelFormatGUID)); + memcpy_s(&convertGUID, sizeof(WICPixelFormatGUID), &g_WICConvert[i].target, sizeof(GUID)); format = _WICToDXGI(g_WICConvert[i].target); assert(format != DXGI_FORMAT_UNKNOWN); @@ -423,7 +426,7 @@ namespace } #if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE) - if ((format == DXGI_FORMAT_R32G32B32_FLOAT) && d3dContext != 0 && textureView != 0) + if ((format == DXGI_FORMAT_R32G32B32_FLOAT) && d3dContext && textureView) { // Special case test for optional device support for autogen mipchains for R32G32B32_FLOAT UINT fmtSupport = 0; @@ -431,7 +434,7 @@ namespace if (FAILED(hr) || !(fmtSupport & D3D11_FORMAT_SUPPORT_MIP_AUTOGEN)) { // Use R32G32B32A32_FLOAT instead which is required for Feature Level 10.0 and up - memcpy(&convertGUID, &GUID_WICPixelFormat128bppRGBAFloat, sizeof(WICPixelFormatGUID)); + memcpy_s(&convertGUID, sizeof(WICPixelFormatGUID), &GUID_WICPixelFormat128bppRGBAFloat, sizeof(GUID)); format = DXGI_FORMAT_R32G32B32A32_FLOAT; bpp = 128; } @@ -488,14 +491,20 @@ namespace if (FAILED(hr) || !(support & D3D11_FORMAT_SUPPORT_TEXTURE2D)) { // Fallback to RGBA 32-bit format which is supported by all devices - memcpy(&convertGUID, &GUID_WICPixelFormat32bppRGBA, sizeof(WICPixelFormatGUID)); + memcpy_s(&convertGUID, sizeof(WICPixelFormatGUID), &GUID_WICPixelFormat32bppRGBA, sizeof(GUID)); format = DXGI_FORMAT_R8G8B8A8_UNORM; bpp = 32; } // Allocate temporary memory for image - size_t rowPitch = (twidth * bpp + 7) / 8; - size_t imageSize = rowPitch * theight; + uint64_t rowBytes = (uint64_t(twidth) * uint64_t(bpp) + 7u) / 8u; + uint64_t numBytes = rowBytes * uint64_t(height); + + if (rowBytes > UINT32_MAX || numBytes > UINT32_MAX) + return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); + + auto rowPitch = static_cast(rowBytes); + auto imageSize = static_cast(numBytes); std::unique_ptr temp(new (std::nothrow) uint8_t[imageSize]); if (!temp) @@ -592,7 +601,7 @@ namespace // See if format is supported for auto-gen mipmaps (varies by feature level) bool autogen = false; - if (d3dContext != 0 && textureView != 0) // Must have context and shader-view to auto generate mipmaps + if (d3dContext && textureView) // Must have context and shader-view to auto generate mipmaps { UINT fmtSupport = 0; hr = d3dDevice->CheckFormatSupport(format, &fmtSupport); @@ -632,15 +641,15 @@ namespace ID3D11Texture2D* tex = nullptr; hr = d3dDevice->CreateTexture2D(&desc, (autogen) ? nullptr : &initData, &tex); - if (SUCCEEDED(hr) && tex != 0) + if (SUCCEEDED(hr) && tex) { - if (textureView != 0) + if (textureView) { D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc = {}; SRVDesc.Format = desc.Format; SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - SRVDesc.Texture2D.MipLevels = (autogen) ? -1 : 1; + SRVDesc.Texture2D.MipLevels = (autogen) ? UINT(-1) : 1; hr = d3dDevice->CreateShaderResourceView(tex, &SRVDesc, textureView); if (FAILED(hr)) @@ -651,13 +660,13 @@ namespace if (autogen) { - assert(d3dContext != 0); + assert(d3dContext != nullptr); d3dContext->UpdateSubresource(tex, 0, nullptr, temp.get(), static_cast(rowPitch), static_cast(imageSize)); d3dContext->GenerateMips(*textureView); } } - if (texture != 0) + if (texture) { *texture = tex; } @@ -670,24 +679,85 @@ namespace return hr; } + + + //-------------------------------------------------------------------------------------- + void SetDebugTextureInfo( + _In_z_ const wchar_t* fileName, + _In_opt_ ID3D11Resource** texture, + _In_opt_ ID3D11ShaderResourceView** textureView) + { +#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) ) + if (texture || textureView) + { + CHAR strFileA[MAX_PATH]; + int result = WideCharToMultiByte(CP_UTF8, + WC_NO_BEST_FIT_CHARS, + fileName, + -1, + strFileA, + MAX_PATH, + nullptr, + nullptr + ); + if (result > 0) + { + const char* pstrName = strrchr(strFileA, '\\'); + if (!pstrName) + { + pstrName = strFileA; + } + else + { + pstrName++; + } + + if (texture && *texture) + { + (*texture)->SetPrivateData(WKPDID_D3DDebugObjectName, + static_cast(strnlen_s(pstrName, MAX_PATH)), + pstrName + ); + } + + if (textureView && *textureView) + { + (*textureView)->SetPrivateData(WKPDID_D3DDebugObjectName, + static_cast(strnlen_s(pstrName, MAX_PATH)), + pstrName + ); + } + } + } +#else + UNREFERENCED_PARAMETER(fileName); + UNREFERENCED_PARAMETER(texture); + UNREFERENCED_PARAMETER(textureView); +#endif + } } // anonymous namespace //-------------------------------------------------------------------------------------- _Use_decl_annotations_ -HRESULT DirectX::CreateWICTextureFromMemory(ID3D11Device* d3dDevice, +HRESULT DirectX::CreateWICTextureFromMemory( + ID3D11Device* d3dDevice, const uint8_t* wicData, size_t wicDataSize, ID3D11Resource** texture, ID3D11ShaderResourceView** textureView, size_t maxsize) { - return CreateWICTextureFromMemoryEx(d3dDevice, nullptr, wicData, wicDataSize, maxsize, - D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, WIC_LOADER_DEFAULT, + return CreateWICTextureFromMemoryEx(d3dDevice, nullptr, + wicData, wicDataSize, + maxsize, + D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, + WIC_LOADER_DEFAULT, texture, textureView); } _Use_decl_annotations_ -HRESULT DirectX::CreateWICTextureFromMemory(ID3D11Device* d3dDevice, +HRESULT DirectX::CreateWICTextureFromMemory( + ID3D11Device* d3dDevice, ID3D11DeviceContext* d3dContext, const uint8_t* wicData, size_t wicDataSize, @@ -695,13 +765,17 @@ HRESULT DirectX::CreateWICTextureFromMemory(ID3D11Device* d3dDevice, ID3D11ShaderResourceView** textureView, size_t maxsize) { - return CreateWICTextureFromMemoryEx(d3dDevice, d3dContext, wicData, wicDataSize, maxsize, - D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, WIC_LOADER_DEFAULT, + return CreateWICTextureFromMemoryEx(d3dDevice, d3dContext, + wicData, wicDataSize, + maxsize, + D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, + WIC_LOADER_DEFAULT, texture, textureView); } _Use_decl_annotations_ -HRESULT DirectX::CreateWICTextureFromMemoryEx(ID3D11Device* d3dDevice, +HRESULT DirectX::CreateWICTextureFromMemoryEx( + ID3D11Device* d3dDevice, const uint8_t* wicData, size_t wicDataSize, size_t maxsize, @@ -713,13 +787,17 @@ HRESULT DirectX::CreateWICTextureFromMemoryEx(ID3D11Device* d3dDevice, ID3D11Resource** texture, ID3D11ShaderResourceView** textureView) { - return CreateWICTextureFromMemoryEx(d3dDevice, nullptr, wicData, wicDataSize, maxsize, - usage, bindFlags, cpuAccessFlags, miscFlags, loadFlags, + return CreateWICTextureFromMemoryEx(d3dDevice, nullptr, + wicData, wicDataSize, + maxsize, + usage, bindFlags, cpuAccessFlags, miscFlags, + loadFlags, texture, textureView); } _Use_decl_annotations_ -HRESULT DirectX::CreateWICTextureFromMemoryEx(ID3D11Device* d3dDevice, +HRESULT DirectX::CreateWICTextureFromMemoryEx( + ID3D11Device* d3dDevice, ID3D11DeviceContext* d3dContext, const uint8_t* wicData, size_t wicDataSize, @@ -742,7 +820,14 @@ HRESULT DirectX::CreateWICTextureFromMemoryEx(ID3D11Device* d3dDevice, } if (!d3dDevice || !wicData || (!texture && !textureView)) + { return E_INVALIDARG; + } + + if (textureView && !(bindFlags & D3D11_BIND_SHADER_RESOURCE)) + { + return E_INVALIDARG; + } if (!wicDataSize) return E_FAIL; @@ -775,18 +860,21 @@ HRESULT DirectX::CreateWICTextureFromMemoryEx(ID3D11Device* d3dDevice, if (FAILED(hr)) return hr; - hr = CreateTextureFromWIC(d3dDevice, d3dContext, frame.Get(), maxsize, - usage, bindFlags, cpuAccessFlags, miscFlags, loadFlags, + hr = CreateTextureFromWIC(d3dDevice, d3dContext, + frame.Get(), + maxsize, + usage, bindFlags, cpuAccessFlags, miscFlags, + loadFlags, texture, textureView); if (FAILED(hr)) return hr; - if (texture != 0 && *texture != 0) + if (texture && *texture) { SetDebugObjectName(*texture, "WICTextureLoader"); } - if (textureView != 0 && *textureView != 0) + if (textureView && *textureView) { SetDebugObjectName(*textureView, "WICTextureLoader"); } @@ -796,32 +884,40 @@ HRESULT DirectX::CreateWICTextureFromMemoryEx(ID3D11Device* d3dDevice, //-------------------------------------------------------------------------------------- _Use_decl_annotations_ -HRESULT DirectX::CreateWICTextureFromFile(ID3D11Device* d3dDevice, +HRESULT DirectX::CreateWICTextureFromFile( + ID3D11Device* d3dDevice, const wchar_t* fileName, ID3D11Resource** texture, ID3D11ShaderResourceView** textureView, size_t maxsize) { - return CreateWICTextureFromFileEx(d3dDevice, nullptr, fileName, maxsize, - D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, WIC_LOADER_DEFAULT, + return CreateWICTextureFromFileEx(d3dDevice, nullptr, + fileName, maxsize, + D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, + WIC_LOADER_DEFAULT, texture, textureView); } _Use_decl_annotations_ -HRESULT DirectX::CreateWICTextureFromFile(ID3D11Device* d3dDevice, +HRESULT DirectX::CreateWICTextureFromFile( + ID3D11Device* d3dDevice, ID3D11DeviceContext* d3dContext, const wchar_t* fileName, ID3D11Resource** texture, ID3D11ShaderResourceView** textureView, size_t maxsize) { - return CreateWICTextureFromFileEx(d3dDevice, d3dContext, fileName, maxsize, - D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, WIC_LOADER_DEFAULT, + return CreateWICTextureFromFileEx(d3dDevice, d3dContext, + fileName, + maxsize, + D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, + WIC_LOADER_DEFAULT, texture, textureView); } _Use_decl_annotations_ -HRESULT DirectX::CreateWICTextureFromFileEx(ID3D11Device* d3dDevice, +HRESULT DirectX::CreateWICTextureFromFileEx( + ID3D11Device* d3dDevice, const wchar_t* fileName, size_t maxsize, D3D11_USAGE usage, @@ -832,13 +928,17 @@ HRESULT DirectX::CreateWICTextureFromFileEx(ID3D11Device* d3dDevice, ID3D11Resource** texture, ID3D11ShaderResourceView** textureView) { - return CreateWICTextureFromFileEx(d3dDevice, nullptr, fileName, maxsize, - usage, bindFlags, cpuAccessFlags, miscFlags, loadFlags, + return CreateWICTextureFromFileEx(d3dDevice, nullptr, + fileName, + maxsize, + usage, bindFlags, cpuAccessFlags, miscFlags, + loadFlags, texture, textureView); } _Use_decl_annotations_ -HRESULT DirectX::CreateWICTextureFromFileEx(ID3D11Device* d3dDevice, +HRESULT DirectX::CreateWICTextureFromFileEx( + ID3D11Device* d3dDevice, ID3D11DeviceContext* d3dContext, const wchar_t* fileName, size_t maxsize, @@ -860,7 +960,14 @@ HRESULT DirectX::CreateWICTextureFromFileEx(ID3D11Device* d3dDevice, } if (!d3dDevice || !fileName || (!texture && !textureView)) + { + return E_INVALIDARG; + } + + if (textureView && !(bindFlags & D3D11_BIND_SHADER_RESOURCE)) + { return E_INVALIDARG; + } auto pWIC = _GetWIC(); if (!pWIC) @@ -868,7 +975,11 @@ HRESULT DirectX::CreateWICTextureFromFileEx(ID3D11Device* d3dDevice, // Initialize WIC ComPtr decoder; - HRESULT hr = pWIC->CreateDecoderFromFilename(fileName, nullptr, GENERIC_READ, WICDecodeMetadataCacheOnDemand, decoder.GetAddressOf()); + HRESULT hr = pWIC->CreateDecoderFromFilename(fileName, + nullptr, + GENERIC_READ, + WICDecodeMetadataCacheOnDemand, + decoder.GetAddressOf()); if (FAILED(hr)) return hr; @@ -877,56 +988,17 @@ HRESULT DirectX::CreateWICTextureFromFileEx(ID3D11Device* d3dDevice, if (FAILED(hr)) return hr; - hr = CreateTextureFromWIC(d3dDevice, d3dContext, frame.Get(), maxsize, - usage, bindFlags, cpuAccessFlags, miscFlags, loadFlags, + hr = CreateTextureFromWIC(d3dDevice, d3dContext, + frame.Get(), + maxsize, + usage, bindFlags, cpuAccessFlags, miscFlags, + loadFlags, texture, textureView); -#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) ) if (SUCCEEDED(hr)) { - if (texture != 0 || textureView != 0) - { - char strFileA[MAX_PATH]; - int result = WideCharToMultiByte(CP_ACP, - WC_NO_BEST_FIT_CHARS, - fileName, - -1, - strFileA, - MAX_PATH, - nullptr, - FALSE - ); - if (result > 0) - { - const char* pstrName = strrchr(strFileA, '\\'); - if (!pstrName) - { - pstrName = strFileA; - } - else - { - pstrName++; - } - - if (texture != 0 && *texture != 0) - { - (*texture)->SetPrivateData(WKPDID_D3DDebugObjectName, - static_cast(strnlen_s(pstrName, MAX_PATH)), - pstrName - ); - } - - if (textureView != 0 && *textureView != 0) - { - (*textureView)->SetPrivateData(WKPDID_D3DDebugObjectName, - static_cast(strnlen_s(pstrName, MAX_PATH)), - pstrName - ); - } - } - } + SetDebugTextureInfo(fileName, texture, textureView); } -#endif return hr; } diff --git a/FriedLiver/Source/DXUT/DXUT_2015.sln b/FriedLiver/Source/DXUT/DXUT_2015.sln new file mode 100644 index 00000000..c58339af --- /dev/null +++ b/FriedLiver/Source/DXUT/DXUT_2015.sln @@ -0,0 +1,58 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUT", "Core\DXUT_2015.vcxproj", "{85344B7F-5AA0-4E12-A065-D1333D11F6CA}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUTOpt", "Optional\DXUTOpt_2015.vcxproj", "{61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Profile|Win32 = Profile|Win32 + Profile|x64 = Profile|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.ActiveCfg = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.Build.0 = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.Deploy.0 = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.ActiveCfg = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.Build.0 = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.Deploy.0 = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.ActiveCfg = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.Build.0 = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.Deploy.0 = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.ActiveCfg = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.Build.0 = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.Deploy.0 = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.ActiveCfg = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.Build.0 = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.Deploy.0 = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.ActiveCfg = Release|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.Build.0 = Release|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.Deploy.0 = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.ActiveCfg = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.Build.0 = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.Deploy.0 = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.ActiveCfg = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.Build.0 = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.Deploy.0 = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.ActiveCfg = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.Build.0 = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.Deploy.0 = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.ActiveCfg = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.Build.0 = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.Deploy.0 = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.ActiveCfg = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.Build.0 = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.Deploy.0 = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.ActiveCfg = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.Build.0 = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.Deploy.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/FriedLiver/Source/DXUT/DXUT_2015_Win10.sln b/FriedLiver/Source/DXUT/DXUT_2015_Win10.sln new file mode 100644 index 00000000..eddd7092 --- /dev/null +++ b/FriedLiver/Source/DXUT/DXUT_2015_Win10.sln @@ -0,0 +1,58 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUT", "Core\DXUT_2015_Win10.vcxproj", "{85344B7F-5AA0-4E12-A065-D1333D11F6CA}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUTOpt", "Optional\DXUTOpt_2015_Win10.vcxproj", "{61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Profile|Win32 = Profile|Win32 + Profile|x64 = Profile|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.ActiveCfg = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.Build.0 = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.Deploy.0 = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.ActiveCfg = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.Build.0 = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.Deploy.0 = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.ActiveCfg = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.Build.0 = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.Deploy.0 = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.ActiveCfg = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.Build.0 = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.Deploy.0 = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.ActiveCfg = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.Build.0 = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.Deploy.0 = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.ActiveCfg = Release|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.Build.0 = Release|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.Deploy.0 = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.ActiveCfg = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.Build.0 = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.Deploy.0 = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.ActiveCfg = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.Build.0 = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.Deploy.0 = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.ActiveCfg = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.Build.0 = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.Deploy.0 = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.ActiveCfg = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.Build.0 = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.Deploy.0 = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.ActiveCfg = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.Build.0 = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.Deploy.0 = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.ActiveCfg = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.Build.0 = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.Deploy.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/FriedLiver/Source/DXUT/DXUT_2017_Win10.sln b/FriedLiver/Source/DXUT/DXUT_2017_Win10.sln new file mode 100644 index 00000000..10b88269 --- /dev/null +++ b/FriedLiver/Source/DXUT/DXUT_2017_Win10.sln @@ -0,0 +1,68 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27703.2000 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUT", "Core\DXUT_2017_Win10.vcxproj", "{85344B7F-5AA0-4E12-A065-D1333D11F6CA}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUTOpt", "Optional\DXUTOpt_2017_Win10.vcxproj", "{61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4C959E18-6969-4523-88A8-05DA5B36F168}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Profile|Win32 = Profile|Win32 + Profile|x64 = Profile|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.ActiveCfg = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.Build.0 = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.Deploy.0 = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.ActiveCfg = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.Build.0 = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.Deploy.0 = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.ActiveCfg = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.Build.0 = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.Deploy.0 = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.ActiveCfg = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.Build.0 = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.Deploy.0 = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.ActiveCfg = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.Build.0 = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.Deploy.0 = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.ActiveCfg = Release|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.Build.0 = Release|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.Deploy.0 = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.ActiveCfg = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.Build.0 = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.Deploy.0 = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.ActiveCfg = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.Build.0 = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.Deploy.0 = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.ActiveCfg = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.Build.0 = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.Deploy.0 = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.ActiveCfg = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.Build.0 = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.Deploy.0 = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.ActiveCfg = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.Build.0 = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.Deploy.0 = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.ActiveCfg = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.Build.0 = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.Deploy.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {47CE266D-B0B1-44CE-A32C-E57A18C54CF3} + EndGlobalSection +EndGlobal diff --git a/FriedLiver/Source/DXUT/DXUT_2019_Win10.sln b/FriedLiver/Source/DXUT/DXUT_2019_Win10.sln new file mode 100644 index 00000000..73177327 --- /dev/null +++ b/FriedLiver/Source/DXUT/DXUT_2019_Win10.sln @@ -0,0 +1,68 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 16 +VisualStudioVersion = 15.0.27703.2000 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUT", "Core\DXUT_2019_Win10.vcxproj", "{85344B7F-5AA0-4E12-A065-D1333D11F6CA}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUTOpt", "Optional\DXUTOpt_2019_Win10.vcxproj", "{61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4C959E18-6969-4523-88A8-05DA5B36F168}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Profile|Win32 = Profile|Win32 + Profile|x64 = Profile|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.ActiveCfg = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.Build.0 = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.Deploy.0 = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.ActiveCfg = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.Build.0 = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.Deploy.0 = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.ActiveCfg = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.Build.0 = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.Deploy.0 = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.ActiveCfg = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.Build.0 = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.Deploy.0 = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.ActiveCfg = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.Build.0 = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.Deploy.0 = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.ActiveCfg = Release|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.Build.0 = Release|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.Deploy.0 = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.ActiveCfg = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.Build.0 = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.Deploy.0 = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.ActiveCfg = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.Build.0 = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.Deploy.0 = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.ActiveCfg = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.Build.0 = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.Deploy.0 = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.ActiveCfg = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.Build.0 = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.Deploy.0 = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.ActiveCfg = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.Build.0 = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.Deploy.0 = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.ActiveCfg = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.Build.0 = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.Deploy.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {47CE266D-B0B1-44CE-A32C-E57A18C54CF3} + EndGlobalSection +EndGlobal diff --git a/FriedLiver/Source/DXUT/DXUT_DirectXTK_2015.sln b/FriedLiver/Source/DXUT/DXUT_DirectXTK_2015.sln new file mode 100644 index 00000000..e96bdae4 --- /dev/null +++ b/FriedLiver/Source/DXUT/DXUT_DirectXTK_2015.sln @@ -0,0 +1,84 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUT", "Core\DXUT_DirectXTK_2015.vcxproj", "{85344B7F-5AA0-4E12-A065-D1333D11F6CA}" + ProjectSection(ProjectDependencies) = postProject + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E} = {E0B52AE7-E160-4D32-BF3F-910B785E5A8E} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUTOpt", "Optional\DXUTOpt_DirectXTK_2015.vcxproj", "{61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}" + ProjectSection(ProjectDependencies) = postProject + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E} = {E0B52AE7-E160-4D32-BF3F-910B785E5A8E} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DirectXTK_Desktop_2015", "..\DirectXTK\DirectXTK_Desktop_2015.vcxproj", "{E0B52AE7-E160-4D32-BF3F-910B785E5A8E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Profile|Win32 = Profile|Win32 + Profile|x64 = Profile|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.ActiveCfg = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.Build.0 = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.Deploy.0 = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.ActiveCfg = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.Build.0 = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.Deploy.0 = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.ActiveCfg = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.Build.0 = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.Deploy.0 = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.ActiveCfg = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.Build.0 = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.Deploy.0 = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.ActiveCfg = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.Build.0 = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.Deploy.0 = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.ActiveCfg = Release|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.Build.0 = Release|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.Deploy.0 = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.ActiveCfg = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.Build.0 = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.Deploy.0 = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.ActiveCfg = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.Build.0 = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.Deploy.0 = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.ActiveCfg = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.Build.0 = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.Deploy.0 = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.ActiveCfg = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.Build.0 = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.Deploy.0 = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.ActiveCfg = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.Build.0 = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.Deploy.0 = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.ActiveCfg = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.Build.0 = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.Deploy.0 = Release|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|Win32.ActiveCfg = Debug|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|Win32.Build.0 = Debug|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|Win32.Deploy.0 = Debug|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|x64.ActiveCfg = Debug|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|x64.Build.0 = Debug|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|x64.Deploy.0 = Debug|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Profile|Win32.ActiveCfg = Release|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Profile|Win32.Build.0 = Release|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Profile|Win32.Deploy.0 = Release|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Profile|x64.ActiveCfg = Release|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Profile|x64.Build.0 = Release|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Profile|x64.Deploy.0 = Release|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Release|Win32.ActiveCfg = Release|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Release|Win32.Build.0 = Release|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Release|Win32.Deploy.0 = Release|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Release|x64.ActiveCfg = Release|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Release|x64.Build.0 = Release|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Release|x64.Deploy.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/FriedLiver/Source/DXUT/DXUT_DirectXTK_2015_Win10.sln b/FriedLiver/Source/DXUT/DXUT_DirectXTK_2015_Win10.sln new file mode 100644 index 00000000..050ce0a5 --- /dev/null +++ b/FriedLiver/Source/DXUT/DXUT_DirectXTK_2015_Win10.sln @@ -0,0 +1,80 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUT", "Core\DXUT_DirectXTK_2015_Win10.vcxproj", "{85344B7F-5AA0-4E12-A065-D1333D11F6CA}" + ProjectSection(ProjectDependencies) = postProject + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E} = {E0B52AE7-E160-4D32-BF3F-910B785E5A8E} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUTOpt", "Optional\DXUTOpt_DirectXTK_2015_Win10.vcxproj", "{61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}" + ProjectSection(ProjectDependencies) = postProject + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E} = {E0B52AE7-E160-4D32-BF3F-910B785E5A8E} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DirectXTK_Desktop_2015_Win10", "..\directxtk\DirectXTK_Desktop_2015_Win10.vcxproj", "{E0B52AE7-E160-4D32-BF3F-910B785E5A8E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Profile|Win32 = Profile|Win32 + Profile|x64 = Profile|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.ActiveCfg = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.Build.0 = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.Deploy.0 = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.ActiveCfg = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.Build.0 = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.Deploy.0 = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.ActiveCfg = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.Build.0 = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.Deploy.0 = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.ActiveCfg = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.Build.0 = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.Deploy.0 = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.ActiveCfg = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.Build.0 = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.Deploy.0 = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.ActiveCfg = Release|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.Build.0 = Release|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.Deploy.0 = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.ActiveCfg = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.Build.0 = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.Deploy.0 = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.ActiveCfg = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.Build.0 = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.Deploy.0 = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.ActiveCfg = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.Build.0 = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.Deploy.0 = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.ActiveCfg = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.Build.0 = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.Deploy.0 = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.ActiveCfg = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.Build.0 = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.Deploy.0 = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.ActiveCfg = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.Build.0 = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.Deploy.0 = Release|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|Win32.ActiveCfg = Debug|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|Win32.Build.0 = Debug|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|x64.ActiveCfg = Debug|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|x64.Build.0 = Debug|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Profile|Win32.ActiveCfg = Release|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Profile|Win32.Build.0 = Release|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Profile|x64.ActiveCfg = Release|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Profile|x64.Build.0 = Release|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Release|Win32.ActiveCfg = Release|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Release|Win32.Build.0 = Release|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Release|x64.ActiveCfg = Release|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/FriedLiver/Source/DXUT/DXUT_DirectXTK_2017_Win10.sln b/FriedLiver/Source/DXUT/DXUT_DirectXTK_2017_Win10.sln new file mode 100644 index 00000000..042ea70a --- /dev/null +++ b/FriedLiver/Source/DXUT/DXUT_DirectXTK_2017_Win10.sln @@ -0,0 +1,94 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27703.2000 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUT", "Core\DXUT_DirectXTK_2017_Win10.vcxproj", "{85344B7F-5AA0-4E12-A065-D1333D11F6CA}" + ProjectSection(ProjectDependencies) = postProject + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E} = {E0B52AE7-E160-4D32-BF3F-910B785E5A8E} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUTOpt", "Optional\DXUTOpt_DirectXTK_2017_Win10.vcxproj", "{61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}" + ProjectSection(ProjectDependencies) = postProject + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E} = {E0B52AE7-E160-4D32-BF3F-910B785E5A8E} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DirectXTK_Desktop_2017", "..\DirectXTK\DirectXTK_Desktop_2017.vcxproj", "{E0B52AE7-E160-4D32-BF3F-910B785E5A8E}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3EACA61D-02C5-45AC-AB92-6665F9022F62}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Profile|Win32 = Profile|Win32 + Profile|x64 = Profile|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.ActiveCfg = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.Build.0 = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.Deploy.0 = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.ActiveCfg = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.Build.0 = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.Deploy.0 = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.ActiveCfg = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.Build.0 = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.Deploy.0 = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.ActiveCfg = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.Build.0 = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.Deploy.0 = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.ActiveCfg = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.Build.0 = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.Deploy.0 = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.ActiveCfg = Release|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.Build.0 = Release|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.Deploy.0 = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.ActiveCfg = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.Build.0 = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.Deploy.0 = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.ActiveCfg = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.Build.0 = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.Deploy.0 = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.ActiveCfg = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.Build.0 = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.Deploy.0 = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.ActiveCfg = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.Build.0 = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.Deploy.0 = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.ActiveCfg = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.Build.0 = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.Deploy.0 = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.ActiveCfg = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.Build.0 = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.Deploy.0 = Release|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|Win32.ActiveCfg = Debug|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|Win32.Build.0 = Debug|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|Win32.Deploy.0 = Debug|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|x64.ActiveCfg = Debug|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|x64.Build.0 = Debug|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|x64.Deploy.0 = Debug|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Profile|Win32.ActiveCfg = Release|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Profile|Win32.Build.0 = Release|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Profile|Win32.Deploy.0 = Release|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Profile|x64.ActiveCfg = Release|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Profile|x64.Build.0 = Release|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Profile|x64.Deploy.0 = Release|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Release|Win32.ActiveCfg = Release|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Release|Win32.Build.0 = Release|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Release|Win32.Deploy.0 = Release|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Release|x64.ActiveCfg = Release|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Release|x64.Build.0 = Release|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Release|x64.Deploy.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {298153E7-D73B-4B15-9824-69D4725B153C} + EndGlobalSection +EndGlobal diff --git a/FriedLiver/Source/DXUT/DXUT_DirectXTK_2019_Win10.sln b/FriedLiver/Source/DXUT/DXUT_DirectXTK_2019_Win10.sln new file mode 100644 index 00000000..602c2a4e --- /dev/null +++ b/FriedLiver/Source/DXUT/DXUT_DirectXTK_2019_Win10.sln @@ -0,0 +1,94 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 16 +VisualStudioVersion = 15.0.27703.2000 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUT", "Core\DXUT_DirectXTK_2019_Win10.vcxproj", "{85344B7F-5AA0-4E12-A065-D1333D11F6CA}" + ProjectSection(ProjectDependencies) = postProject + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E} = {E0B52AE7-E160-4D32-BF3F-910B785E5A8E} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUTOpt", "Optional\DXUTOpt_DirectXTK_2019_Win10.vcxproj", "{61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}" + ProjectSection(ProjectDependencies) = postProject + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E} = {E0B52AE7-E160-4D32-BF3F-910B785E5A8E} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DirectXTK_Desktop_2019", "..\DirectXTK\DirectXTK_Desktop_2019.vcxproj", "{E0B52AE7-E160-4D32-BF3F-910B785E5A8E}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3EACA61D-02C5-45AC-AB92-6665F9022F62}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Profile|Win32 = Profile|Win32 + Profile|x64 = Profile|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.ActiveCfg = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.Build.0 = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|Win32.Deploy.0 = Debug|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.ActiveCfg = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.Build.0 = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Debug|x64.Deploy.0 = Debug|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.ActiveCfg = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.Build.0 = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|Win32.Deploy.0 = Profile|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.ActiveCfg = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.Build.0 = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Profile|x64.Deploy.0 = Profile|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.ActiveCfg = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.Build.0 = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|Win32.Deploy.0 = Release|Win32 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.ActiveCfg = Release|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.Build.0 = Release|x64 + {85344B7F-5AA0-4E12-A065-D1333D11F6CA}.Release|x64.Deploy.0 = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.ActiveCfg = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.Build.0 = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|Win32.Deploy.0 = Debug|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.ActiveCfg = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.Build.0 = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Debug|x64.Deploy.0 = Debug|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.ActiveCfg = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.Build.0 = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|Win32.Deploy.0 = Profile|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.ActiveCfg = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.Build.0 = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Profile|x64.Deploy.0 = Profile|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.ActiveCfg = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.Build.0 = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|Win32.Deploy.0 = Release|Win32 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.ActiveCfg = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.Build.0 = Release|x64 + {61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}.Release|x64.Deploy.0 = Release|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|Win32.ActiveCfg = Debug|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|Win32.Build.0 = Debug|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|Win32.Deploy.0 = Debug|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|x64.ActiveCfg = Debug|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|x64.Build.0 = Debug|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|x64.Deploy.0 = Debug|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Profile|Win32.ActiveCfg = Release|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Profile|Win32.Build.0 = Release|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Profile|Win32.Deploy.0 = Release|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Profile|x64.ActiveCfg = Release|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Profile|x64.Build.0 = Release|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Profile|x64.Deploy.0 = Release|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Release|Win32.ActiveCfg = Release|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Release|Win32.Build.0 = Release|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Release|Win32.Deploy.0 = Release|Win32 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Release|x64.ActiveCfg = Release|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Release|x64.Build.0 = Release|x64 + {E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Release|x64.Deploy.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {298153E7-D73B-4B15-9824-69D4725B153C} + EndGlobalSection +EndGlobal diff --git a/FriedLiver/Source/DXUT/HISTORY.md b/FriedLiver/Source/DXUT/HISTORY.md new file mode 100644 index 00000000..f55251ac --- /dev/null +++ b/FriedLiver/Source/DXUT/HISTORY.md @@ -0,0 +1,115 @@ +# DXUT for Direct3D 11 + +http://go.microsoft.com/fwlink/?LinkId=320437 + +## Release History + +### January 16, 2020 (11.23) +* Updated DDSTextureLoader, WICTextureLoader, and ScreenGrab + +### April 26, 2019 (11.22) +* Added VS 2019 desktop projects +* VS 2017 updated for Windows 10 October 2018 Update SDK (17763) +* Minor code cleanup + +### July 12, 2018 (11.21) +* Code cleanup + +### May 31, 2018 (11.20) +* VS 2017 updated for Windows 10 April 2018 Update SDK (17134) + +### May 11, 2018 (11.19) +* Support for Direct3D 11.2 no longer requires define ``USE_DIRECT3D11_2`` +* Retired VS 2013 projects +* Code cleanup + +### February 27, 2018 (11.18) +* Fixed array length mismatch issue with ``TOTAL_FEATURE_LEVELS`` +* Fixed optional Direct3D 11.4 support in VS 2013/2015 projects +* Minor code cleanup + +### November 2, 2017 (11.17) +* VS 2017 updated for Windows 10 Fall Creators Update SDK (16299) +* Optional support for Direct3D 11.4 (define ``USE_DIRECT3D11_4`` in projects using the 14393 or later Windows 10 SDK) + +### October 13, 2017 (11.16) +* Updated DDSTextureLoader, WICTextureLoader, and ScreenGrab +* Updated for VS 2017 update 15.1 - 15.3 and Windows 10 SDK (15063) + +### March 10, 2017 (11.15) +* Add VS 2017 projects +* Minor code cleanup + +### September 15, 2016 (11.14) +* Updated WICTextureLoader and ScreenGrab + +### August 2, 2016 (11.13) +* Updated for VS 2015 Update 3 and Windows 10 SDK (14393) + +### April 26, 2016 (11.12) +* Updated DDSTextureLoader, WICTextureLoader, and ScreenGrab +* Retired VS 2012 projects and obsolete adapter code +* Minor code and project file cleanup + +### November 30, 2015 (11.11) +* Updated DDSTextureLoader, ScreenGrab, DXERR +* Updated for VS 2015 Update 1 and Windows 10 SDK (10586) + +### July 29, 2015 (11.10) +* Updated for VS 2015 and Windows 10 SDK RTM +* Retired VS 2010 projects + +### June 16, 2015 (11.09) +* Optional support for Direct3D 11.3 (define ``USE_DIRECT3D11_3`` in VS 2015 projects) + +### April 14, 2015 (11.08) +* Fix for auto-gen of volume textures +* More updates for VS 2015 + +### November 24, 2014 (11.07) +* Minor fix for Present usage +* Minor fix for CBaseCamera::GetInput +* Minor fix for WIC usage of IWICFormatConverter +* Updates for Visual Studio 2015 Technical Preview + +### July 28, 2014 (11.06) +* Optional support for Direct3D 11.2 (define ``USE_DIRECT3D11_2`` in VS 2013 projects) +* Fixes for various UI and F2 device settings dialog issues +* Fixes for device and format enumeration +* Changed default resolution to 800x600 +* Code review fixes + +### January 24, 2014 (11.05) +* Added use of DXGI debugging when available +* Resolved CRT heap leak report +* Fixed compile bug in DXUTLockFreePipe +* Fixed bug reported in DXUT's sprite implementation +* Code cleanup (removed ``DXGI_1_2_FORMATS`` control define; ScopedObject typedef removed) + +### October 21, 2013 (11.04) +* Updated for Visual Studio 2013 and Windows 8.1 SDK RTM +* Minor fixes for systems which only have a "Microsoft Basic Renderer" device + +### September 2013 (11.03) +* Removed dependencies on the D3DX9 and D3DX11 libraries, so DXUT no longer requires the legacy DirectX SDK to build. +* It does require the d3dcompiler.h header from the Windows 8.x SDK. +* Includes standalone DDSTextureLoader, WICTexureLoader, ScreenGrab, and DxErr modules. +* Removed support for Direct3D 9 and Windows XP +* Deleted the DXUTDevice9.h/.cpp, SDKSound.h/.cpp, and SDKWaveFile.h/.cpp files +* Deleted legacy support for MCE relaunch +* General C++ code cleanups (nullptr, auto keyword, C++ style casting, Safer CRT, etc.) which are compatible with Visual C++ 2010 and 2012 +* SAL2 annotation and /analyze cleanup +* Added DXUTCompileFromFile, DXUTCreateShaderResourceViewFromFile, DXUTCreateTextureFromFile, DXUTSaveTextureToFile helpers +* Added ``-forcewarp`` command-line switch +* Added support for DXGI 1.1 and 1.2 formats +* Added Direct3D 11.1 Device/Context state +* Support Feature Level 11.1 when available + +### June 2010 (11.02) +* The DirectX SDK (June 2010) included an update to DXUT11. This is the last version to support Visual Studio 2008, Windows XP, or Direct3D 9. The source code is located in ``Samples\C++\DXUT11``. + +### February 2010 (11.01) +* An update was shipped with the DirectX SDK (February 2010). This is the last version to support Visual Studio 2005. The source code is located in ``Samples\C++\DXUT11``. + +### August 2009 (11.00) +* The initial release of DXUT11 was in DirectX SDK (August 2009). The source code is located in Samples\C++\DXUT11. This was a port of the original DXUT which supported Direct3D 10 / Direct3D 9 applications on Windows XP and Windows Vista. diff --git a/FriedLiver/Source/DXUT/LICENSE b/FriedLiver/Source/DXUT/LICENSE new file mode 100644 index 00000000..a8090696 --- /dev/null +++ b/FriedLiver/Source/DXUT/LICENSE @@ -0,0 +1,21 @@ + The MIT License (MIT) + +Copyright (c) 2004-2020 Microsoft Corp + +Permission is hereby granted, free of charge, to any person obtaining a copy of this +software and associated documentation files (the "Software"), to deal in the Software +without restriction, including without limitation the rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/FriedLiver/Source/DXUT/Optional/DXUTcamera.cpp b/FriedLiver/Source/DXUT/Optional/DXUTcamera.cpp index fe2f2ec0..e63e6275 100644 --- a/FriedLiver/Source/DXUT/Optional/DXUTcamera.cpp +++ b/FriedLiver/Source/DXUT/Optional/DXUTcamera.cpp @@ -268,7 +268,7 @@ void CBaseCamera::SetViewParams( FXMVECTOR vEyePt, FXMVECTOR vLookatPt ) // The axis basis vectors and camera position are stored inside the // position matrix in the 4 rows of the camera's world matrix. // To figure out the yaw/pitch of the camera, we just need the Z basis vector - DirectX::XMFLOAT3 zBasis; + XMFLOAT3 zBasis; XMStoreFloat3( &zBasis, mInvView.r[2] ); m_fCameraYawAngle = atan2f( zBasis.x, zBasis.z ); @@ -434,7 +434,7 @@ LRESULT CBaseCamera::HandleMessages( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM _Use_decl_annotations_ void CBaseCamera::GetInput( bool bGetKeyboardInput, bool bGetMouseInput, bool bGetGamepadInput ) { - m_vKeyboardDirection = DirectX::XMFLOAT3( 0, 0, 0 ); + m_vKeyboardDirection = XMFLOAT3( 0, 0, 0 ); if( bGetKeyboardInput ) { // Update acceleration vector based on keyboard state @@ -462,8 +462,8 @@ void CBaseCamera::GetInput( bool bGetKeyboardInput, bool bGetMouseInput, bool bG if( bGetGamepadInput ) { - m_vGamePadLeftThumb = DirectX::XMFLOAT3( 0, 0, 0 ); - m_vGamePadRightThumb = DirectX::XMFLOAT3( 0, 0, 0 ); + m_vGamePadLeftThumb = XMFLOAT3( 0, 0, 0 ); + m_vGamePadRightThumb = XMFLOAT3( 0, 0, 0 ); // Get controller state for( DWORD iUserIndex = 0; iUserIndex < DXUT_MAX_CONTROLLERS; iUserIndex++ ) @@ -611,7 +611,7 @@ void CBaseCamera::UpdateVelocity( _In_ float fElapsedTime ) else { // Zero velocity - m_vVelocity = DirectX::XMFLOAT3( 0, 0, 0 ); + m_vVelocity = XMFLOAT3( 0, 0, 0 ); } } } @@ -831,7 +831,7 @@ CModelViewerCamera::CModelViewerCamera() noexcept : XMStoreFloat4x4( &m_mModelRot, id ); XMStoreFloat4x4( &m_mModelLastRot, id ); XMStoreFloat4x4( &m_mCameraRotLast, id ); - m_vModelCenter = DirectX::XMFLOAT3( 0, 0, 0 ); + m_vModelCenter = XMFLOAT3( 0, 0, 0 ); m_bEnablePositionMovement = false; } @@ -1095,7 +1095,7 @@ CDXUTDirectionWidget::CDXUTDirectionWidget() noexcept : m_fRadius(1.0f), m_nRotateMask(MOUSE_RIGHT_BUTTON) { - m_vDefaultDir = DirectX::XMFLOAT3( 0, 1, 0 ); + m_vDefaultDir = XMFLOAT3( 0, 1, 0 ); m_vCurrentDir = m_vDefaultDir; XMMATRIX id = XMMatrixIdentity(); diff --git a/FriedLiver/Source/DXUT/Optional/DXUTgui.cpp b/FriedLiver/Source/DXUT/Optional/DXUTgui.cpp index 2d223b98..0029d03b 100644 --- a/FriedLiver/Source/DXUT/Optional/DXUTgui.cpp +++ b/FriedLiver/Source/DXUT/Optional/DXUTgui.cpp @@ -42,9 +42,9 @@ using namespace DirectX; #define DXUT_MAX_GUI_SPRITES 500 -inline DirectX::XMFLOAT4 D3DCOLOR_TO_D3DCOLORVALUE( DWORD c ) +inline XMFLOAT4 D3DCOLOR_TO_D3DCOLORVALUE( DWORD c ) { - return DirectX::XMFLOAT4 ( ( ( c >> 16 ) & 0xFF ) / 255.0f, + return XMFLOAT4 ( ( ( c >> 16 ) & 0xFF ) / 255.0f, ( ( c >> 8 ) & 0xFF ) / 255.0f, ( c & 0xFF ) / 255.0f, ( ( c >> 24 ) & 0xFF ) / 255.0f ); @@ -183,7 +183,7 @@ struct DXUT_SCREEN_VERTEX_UNTEX struct DXUT_SCREEN_VERTEX_10 { float x, y, z; - DirectX::XMFLOAT4 color; + XMFLOAT4 color; float tu, tv; }; @@ -241,7 +241,7 @@ void BeginText11() //-------------------------------------------------------------------------------------- _Use_decl_annotations_ void DrawText11DXUT( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3d11DeviceContext, - LPCWSTR strText, const RECT& rcScreen, DirectX::XMFLOAT4 vFontColor, + LPCWSTR strText, const RECT& rcScreen, XMFLOAT4 vFontColor, float fBBWidth, float fBBHeight, bool bCenter ) { float fCharTexSizeX = 0.010526315f; @@ -295,34 +295,34 @@ void DrawText11DXUT( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3d11Device float fTexRight = fTexLeft + fCharTexSizeX; // tri1 - SpriteVertex.vPos = DirectX::XMFLOAT3( fRectLeft, fRectTop, fDepth ); - SpriteVertex.vTex = DirectX::XMFLOAT2( fTexLeft, fTexTop ); + SpriteVertex.vPos = XMFLOAT3( fRectLeft, fRectTop, fDepth ); + SpriteVertex.vTex = XMFLOAT2( fTexLeft, fTexTop ); SpriteVertex.vColor = vFontColor; g_FontVertices.push_back( SpriteVertex ); - SpriteVertex.vPos = DirectX::XMFLOAT3( fRectRight, fRectTop, fDepth ); - SpriteVertex.vTex = DirectX::XMFLOAT2( fTexRight, fTexTop ); + SpriteVertex.vPos = XMFLOAT3( fRectRight, fRectTop, fDepth ); + SpriteVertex.vTex = XMFLOAT2( fTexRight, fTexTop ); SpriteVertex.vColor = vFontColor; g_FontVertices.push_back( SpriteVertex ); - SpriteVertex.vPos = DirectX::XMFLOAT3( fRectLeft, fRectBottom, fDepth ); - SpriteVertex.vTex = DirectX::XMFLOAT2( fTexLeft, fTexBottom ); + SpriteVertex.vPos = XMFLOAT3( fRectLeft, fRectBottom, fDepth ); + SpriteVertex.vTex = XMFLOAT2( fTexLeft, fTexBottom ); SpriteVertex.vColor = vFontColor; g_FontVertices.push_back( SpriteVertex ); // tri2 - SpriteVertex.vPos = DirectX::XMFLOAT3( fRectRight, fRectTop, fDepth ); - SpriteVertex.vTex = DirectX::XMFLOAT2( fTexRight, fTexTop ); + SpriteVertex.vPos = XMFLOAT3( fRectRight, fRectTop, fDepth ); + SpriteVertex.vTex = XMFLOAT2( fTexRight, fTexTop ); SpriteVertex.vColor = vFontColor; g_FontVertices.push_back( SpriteVertex ); - SpriteVertex.vPos = DirectX::XMFLOAT3( fRectRight, fRectBottom, fDepth ); - SpriteVertex.vTex = DirectX::XMFLOAT2( fTexRight, fTexBottom ); + SpriteVertex.vPos = XMFLOAT3( fRectRight, fRectBottom, fDepth ); + SpriteVertex.vTex = XMFLOAT2( fTexRight, fTexBottom ); SpriteVertex.vColor = vFontColor; g_FontVertices.push_back( SpriteVertex ); - SpriteVertex.vPos = DirectX::XMFLOAT3( fRectLeft, fRectBottom, fDepth ); - SpriteVertex.vTex = DirectX::XMFLOAT2( fTexLeft, fTexBottom ); + SpriteVertex.vPos = XMFLOAT3( fRectLeft, fRectBottom, fDepth ); + SpriteVertex.vTex = XMFLOAT2( fTexLeft, fTexBottom ); SpriteVertex.vColor = vFontColor; g_FontVertices.push_back( SpriteVertex ); @@ -1650,34 +1650,34 @@ HRESULT CDXUTDialog::DrawSprite( CDXUTElement* pElement, const RECT* prcDest, fl DXUTSpriteVertex SpriteVertex = {}; // tri1 - SpriteVertex.vPos = DirectX::XMFLOAT3( fRectLeft, fRectTop, fDepth ); - SpriteVertex.vTex = DirectX::XMFLOAT2( fTexLeft, fTexTop ); + SpriteVertex.vPos = XMFLOAT3( fRectLeft, fRectTop, fDepth ); + SpriteVertex.vTex = XMFLOAT2( fTexLeft, fTexTop ); SpriteVertex.vColor = pElement->TextureColor.Current; m_pManager->m_SpriteVertices.push_back( SpriteVertex ); - SpriteVertex.vPos = DirectX::XMFLOAT3( fRectRight, fRectTop, fDepth ); - SpriteVertex.vTex = DirectX::XMFLOAT2( fTexRight, fTexTop ); + SpriteVertex.vPos = XMFLOAT3( fRectRight, fRectTop, fDepth ); + SpriteVertex.vTex = XMFLOAT2( fTexRight, fTexTop ); SpriteVertex.vColor = pElement->TextureColor.Current; m_pManager->m_SpriteVertices.push_back( SpriteVertex ); - SpriteVertex.vPos = DirectX::XMFLOAT3( fRectLeft, fRectBottom, fDepth ); - SpriteVertex.vTex = DirectX::XMFLOAT2( fTexLeft, fTexBottom ); + SpriteVertex.vPos = XMFLOAT3( fRectLeft, fRectBottom, fDepth ); + SpriteVertex.vTex = XMFLOAT2( fTexLeft, fTexBottom ); SpriteVertex.vColor = pElement->TextureColor.Current; m_pManager->m_SpriteVertices.push_back( SpriteVertex ); // tri2 - SpriteVertex.vPos = DirectX::XMFLOAT3( fRectRight, fRectTop, fDepth ); - SpriteVertex.vTex = DirectX::XMFLOAT2( fTexRight, fTexTop ); + SpriteVertex.vPos = XMFLOAT3( fRectRight, fRectTop, fDepth ); + SpriteVertex.vTex = XMFLOAT2( fTexRight, fTexTop ); SpriteVertex.vColor = pElement->TextureColor.Current; m_pManager->m_SpriteVertices.push_back( SpriteVertex ); - SpriteVertex.vPos = DirectX::XMFLOAT3( fRectRight, fRectBottom, fDepth ); - SpriteVertex.vTex = DirectX::XMFLOAT2( fTexRight, fTexBottom ); + SpriteVertex.vPos = XMFLOAT3( fRectRight, fRectBottom, fDepth ); + SpriteVertex.vTex = XMFLOAT2( fTexRight, fTexBottom ); SpriteVertex.vColor = pElement->TextureColor.Current; m_pManager->m_SpriteVertices.push_back( SpriteVertex ); - SpriteVertex.vPos = DirectX::XMFLOAT3( fRectLeft, fRectBottom, fDepth ); - SpriteVertex.vTex = DirectX::XMFLOAT2( fTexLeft, fTexBottom ); + SpriteVertex.vPos = XMFLOAT3( fRectLeft, fRectBottom, fDepth ); + SpriteVertex.vTex = XMFLOAT2( fTexLeft, fTexBottom ); SpriteVertex.vColor = pElement->TextureColor.Current; m_pManager->m_SpriteVertices.push_back( SpriteVertex ); @@ -1732,14 +1732,14 @@ HRESULT CDXUTDialog::DrawText( LPCWSTR strText, CDXUTElement* pElement, const RE RECT rcShadow = rcScreen; OffsetRect( &rcShadow, 1, 1 ); - DirectX::XMFLOAT4 vShadowColor( 0,0,0, 1.0f ); + XMFLOAT4 vShadowColor( 0,0,0, 1.0f ); DrawText11DXUT( pd3dDevice, pd3d11DeviceContext, strText, rcShadow, vShadowColor, fBBWidth, fBBHeight, bCenter ); } - DirectX::XMFLOAT4 vFontColor( pElement->FontColor.Current.x, pElement->FontColor.Current.y, pElement->FontColor.Current.z, 1.0f ); + XMFLOAT4 vFontColor( pElement->FontColor.Current.x, pElement->FontColor.Current.y, pElement->FontColor.Current.z, 1.0f ); DrawText11DXUT( pd3dDevice, pd3d11DeviceContext, strText, rcScreen, vFontColor, fBBWidth, fBBHeight, bCenter ); @@ -6630,7 +6630,7 @@ void DXUTBlendColor::Init( DWORD defaultColor, DWORD disabledColor, DWORD hidden _Use_decl_annotations_ void DXUTBlendColor::Blend( UINT iState, float fElapsedTime, float fRate ) { - DirectX::XMFLOAT4 destColor = D3DCOLOR_TO_D3DCOLORVALUE( States[ iState ] ); + XMFLOAT4 destColor = D3DCOLOR_TO_D3DCOLORVALUE( States[ iState ] ); XMVECTOR clr1 = XMLoadFloat4( &destColor ); XMVECTOR clr = XMLoadFloat4( &Current ); clr = XMVectorLerp( clr, clr1, 1.0f - powf( fRate, 30 * fElapsedTime ) ); diff --git a/FriedLiver/Source/DXUT/Optional/SDKmesh.cpp b/FriedLiver/Source/DXUT/Optional/SDKmesh.cpp index 9df5d119..1ac296d0 100644 --- a/FriedLiver/Source/DXUT/Optional/SDKmesh.cpp +++ b/FriedLiver/Source/DXUT/Optional/SDKmesh.cpp @@ -234,8 +234,8 @@ HRESULT CDXUTSDKMesh::CreateFromMemory( ID3D11Device* pDev11, bool bCopyStatic, SDKMESH_CALLBACKS11* pLoaderCallbacks11 ) { - DirectX::XMFLOAT3 lower; - DirectX::XMFLOAT3 upper; + XMFLOAT3 lower; + XMFLOAT3 upper; m_pDev11 = pDev11; @@ -338,20 +338,20 @@ HRESULT CDXUTSDKMesh::CreateFromMemory( ID3D11Device* pDev11, LoadMaterials( pDev11, m_pMaterialArray, m_pMeshHeader->NumMaterials, pLoaderCallbacks11 ); // Create a place to store our bind pose frame matrices - m_pBindPoseFrameMatrices = new (std::nothrow) DirectX::XMFLOAT4X4[ m_pMeshHeader->NumFrames ]; + m_pBindPoseFrameMatrices = new (std::nothrow) XMFLOAT4X4[ m_pMeshHeader->NumFrames ]; if( !m_pBindPoseFrameMatrices ) { return E_OUTOFMEMORY; } // Create a place to store our transformed frame matrices - m_pTransformedFrameMatrices = new (std::nothrow) DirectX::XMFLOAT4X4[ m_pMeshHeader->NumFrames ]; + m_pTransformedFrameMatrices = new (std::nothrow) XMFLOAT4X4[ m_pMeshHeader->NumFrames ]; if( !m_pTransformedFrameMatrices ) { return E_OUTOFMEMORY; } - m_pWorldPoseFrameMatrices = new (std::nothrow) DirectX::XMFLOAT4X4[ m_pMeshHeader->NumFrames ]; + m_pWorldPoseFrameMatrices = new (std::nothrow) XMFLOAT4X4[ m_pMeshHeader->NumFrames ]; if( !m_pWorldPoseFrameMatrices ) { return E_OUTOFMEMORY; @@ -412,7 +412,7 @@ HRESULT CDXUTSDKMesh::CreateFromMemory( ID3D11Device* pDev11, current_ind = ind[vertind]; } tris++; - DirectX::XMFLOAT3 *pt = (DirectX::XMFLOAT3*)&(verts[stride * current_ind]); + XMFLOAT3 *pt = (XMFLOAT3*)&(verts[stride * current_ind]); if (pt->x < lower.x) { lower.x = pt->x; } @@ -437,7 +437,7 @@ HRESULT CDXUTSDKMesh::CreateFromMemory( ID3D11Device* pDev11, //pd3dDeviceContext->DrawIndexed( IndexCount, IndexStart, VertexStart ); } - DirectX::XMFLOAT3 half( ( upper.x - lower.x ) * 0.5f, + XMFLOAT3 half( ( upper.x - lower.x ) * 0.5f, ( upper.y - lower.y ) * 0.5f, ( upper.z - lower.z ) * 0.5f ); @@ -499,7 +499,7 @@ void CDXUTSDKMesh::TransformFrame( UINT iFrame, CXMMATRIX parentWorld, double fT auto pData = &pFrameData->pAnimationData[ iTick ]; // turn it into a matrix (Ignore scaling for now) - DirectX::XMFLOAT3 parentPos = pData->Translation; + XMFLOAT3 parentPos = pData->Translation; XMMATRIX mTranslate = XMMatrixTranslation( parentPos.x, parentPos.y, parentPos.z ); XMVECTOR quat = XMVectorSet( pData->Orientation.x, pData->Orientation.y, pData->Orientation.z, pData->Orientation.w ); diff --git a/FriedLiver/Source/DXUT/Optional/SDKmisc.cpp b/FriedLiver/Source/DXUT/Optional/SDKmisc.cpp index 3246eb02..51d0b2db 100644 --- a/FriedLiver/Source/DXUT/Optional/SDKmisc.cpp +++ b/FriedLiver/Source/DXUT/Optional/SDKmisc.cpp @@ -921,7 +921,7 @@ CDXUTTextHelper::~CDXUTTextHelper() //-------------------------------------------------------------------------------------- void CDXUTTextHelper::Init( _In_ int nLineHeight ) { - m_clr = DirectX::XMFLOAT4( 1, 1, 1, 1 ); + m_clr = XMFLOAT4( 1, 1, 1, 1 ); m_pt.x = 0; m_pt.y = 0; m_nLineHeight = nLineHeight; diff --git a/FriedLiver/Source/DXUT/Optional/SDKsound.cpp b/FriedLiver/Source/DXUT/Optional/SDKsound.cpp deleted file mode 100644 index a1256c75..00000000 --- a/FriedLiver/Source/DXUT/Optional/SDKsound.cpp +++ /dev/null @@ -1,1053 +0,0 @@ -//----------------------------------------------------------------------------- -// File: DXUTsound.cpp -// -// Desc: DirectSound framework classes for playing wav files in DirectSound -// buffers. Feel free to use these classes as a starting point for adding -// extra functionality. -// -// Copyright (c) Microsoft Corp. All rights reserved. -//----------------------------------------------------------------------------- -#define STRICT -#include "DXUT.h" -#include -#include -#include "SDKsound.h" -#include "SDKwavefile.h" -#undef min // use __min instead -#undef max // use __max instead - - -//----------------------------------------------------------------------------- -// Name: CSoundManager::CSoundManager() -// Desc: Constructs the class -//----------------------------------------------------------------------------- -CSoundManager::CSoundManager() -{ - m_pDS = NULL; -} - - -//----------------------------------------------------------------------------- -// Name: CSoundManager::~CSoundManager() -// Desc: Destroys the class -//----------------------------------------------------------------------------- -CSoundManager::~CSoundManager() -{ - SAFE_RELEASE( m_pDS ); -} - - -//----------------------------------------------------------------------------- -// Name: CSoundManager::Initialize() -// Desc: Initializes the IDirectSound object and also sets the primary buffer -// format. This function must be called before any others. -//----------------------------------------------------------------------------- -HRESULT CSoundManager::Initialize( HWND hWnd, - DWORD dwCoopLevel ) -{ - HRESULT hr; - - SAFE_RELEASE( m_pDS ); - - // Create IDirectSound using the primary sound device - if( FAILED( hr = DirectSoundCreate8( NULL, &m_pDS, NULL ) ) ) - return DXUT_ERR( L"DirectSoundCreate8", hr ); - - // Set DirectSound coop level - if( FAILED( hr = m_pDS->SetCooperativeLevel( hWnd, dwCoopLevel ) ) ) - return DXUT_ERR( L"SetCooperativeLevel", hr ); - - return S_OK; -} - - -//----------------------------------------------------------------------------- -// Name: CSoundManager::SetPrimaryBufferFormat() -// Desc: Set primary buffer to a specified format -// !WARNING! - Setting the primary buffer format and then using this -// same DirectSound object for DirectMusic messes up -// DirectMusic! -// For example, to set the primary buffer format to 22kHz stereo, 16-bit -// then: dwPrimaryChannels = 2 -// dwPrimaryFreq = 22050, -// dwPrimaryBitRate = 16 -//----------------------------------------------------------------------------- -HRESULT CSoundManager::SetPrimaryBufferFormat( DWORD dwPrimaryChannels, - DWORD dwPrimaryFreq, - DWORD dwPrimaryBitRate ) -{ - HRESULT hr; - LPDIRECTSOUNDBUFFER pDSBPrimary = NULL; - - if( m_pDS == NULL ) - return CO_E_NOTINITIALIZED; - - // Get the primary buffer - DSBUFFERDESC dsbd; - ZeroMemory( &dsbd, sizeof( DSBUFFERDESC ) ); - dsbd.dwSize = sizeof( DSBUFFERDESC ); - dsbd.dwFlags = DSBCAPS_PRIMARYBUFFER; - dsbd.dwBufferBytes = 0; - dsbd.lpwfxFormat = NULL; - - if( FAILED( hr = m_pDS->CreateSoundBuffer( &dsbd, &pDSBPrimary, NULL ) ) ) - return DXUT_ERR( L"CreateSoundBuffer", hr ); - - WAVEFORMATEX wfx; - ZeroMemory( &wfx, sizeof( WAVEFORMATEX ) ); - wfx.wFormatTag = ( WORD )WAVE_FORMAT_PCM; - wfx.nChannels = ( WORD )dwPrimaryChannels; - wfx.nSamplesPerSec = ( DWORD )dwPrimaryFreq; - wfx.wBitsPerSample = ( WORD )dwPrimaryBitRate; - wfx.nBlockAlign = ( WORD )( wfx.wBitsPerSample / 8 * wfx.nChannels ); - wfx.nAvgBytesPerSec = ( DWORD )( wfx.nSamplesPerSec * wfx.nBlockAlign ); - - if( FAILED( hr = pDSBPrimary->SetFormat( &wfx ) ) ) - return DXUT_ERR( L"SetFormat", hr ); - - SAFE_RELEASE( pDSBPrimary ); - - return S_OK; -} - - -//----------------------------------------------------------------------------- -// Name: CSoundManager::Get3DListenerInterface() -// Desc: Returns the 3D listener interface associated with primary buffer. -//----------------------------------------------------------------------------- -HRESULT CSoundManager::Get3DListenerInterface( LPDIRECTSOUND3DLISTENER* ppDSListener ) -{ - HRESULT hr; - DSBUFFERDESC dsbdesc; - LPDIRECTSOUNDBUFFER pDSBPrimary = NULL; - - if( ppDSListener == NULL ) - return E_INVALIDARG; - if( m_pDS == NULL ) - return CO_E_NOTINITIALIZED; - - *ppDSListener = NULL; - - // Obtain primary buffer, asking it for 3D control - ZeroMemory( &dsbdesc, sizeof( DSBUFFERDESC ) ); - dsbdesc.dwSize = sizeof( DSBUFFERDESC ); - dsbdesc.dwFlags = DSBCAPS_CTRL3D | DSBCAPS_PRIMARYBUFFER; - if( FAILED( hr = m_pDS->CreateSoundBuffer( &dsbdesc, &pDSBPrimary, NULL ) ) ) - return DXUT_ERR( L"CreateSoundBuffer", hr ); - - if( FAILED( hr = pDSBPrimary->QueryInterface( IID_IDirectSound3DListener, - ( VOID** )ppDSListener ) ) ) - { - SAFE_RELEASE( pDSBPrimary ); - return DXUT_ERR( L"QueryInterface", hr ); - } - - // Release the primary buffer, since it is not need anymore - SAFE_RELEASE( pDSBPrimary ); - - return S_OK; -} - - -//----------------------------------------------------------------------------- -// Name: CSoundManager::Create() -// Desc: -//----------------------------------------------------------------------------- -HRESULT CSoundManager::Create( CSound** ppSound, - LPWSTR strWaveFileName, - DWORD dwCreationFlags, - GUID guid3DAlgorithm, - DWORD dwNumBuffers ) -{ - HRESULT hr; - HRESULT hrRet = S_OK; - DWORD i; - LPDIRECTSOUNDBUFFER* apDSBuffer = NULL; - DWORD dwDSBufferSize = NULL; - CWaveFile* pWaveFile = NULL; - - if( m_pDS == NULL ) - return CO_E_NOTINITIALIZED; - if( strWaveFileName == NULL || ppSound == NULL || dwNumBuffers < 1 ) - return E_INVALIDARG; - - apDSBuffer = new LPDIRECTSOUNDBUFFER[dwNumBuffers]; - if( apDSBuffer == NULL ) - { - hr = E_OUTOFMEMORY; - goto LFail; - } - - pWaveFile = new CWaveFile(); - if( pWaveFile == NULL ) - { - hr = E_OUTOFMEMORY; - goto LFail; - } - - pWaveFile->Open( strWaveFileName, NULL, WAVEFILE_READ ); - - if( pWaveFile->GetSize() == 0 ) - { - // Wave is blank, so don't create it. - hr = E_FAIL; - goto LFail; - } - - // Make the DirectSound buffer the same size as the wav file - dwDSBufferSize = pWaveFile->GetSize(); - - // Create the direct sound buffer, and only request the flags needed - // since each requires some overhead and limits if the buffer can - // be hardware accelerated - DSBUFFERDESC dsbd; - ZeroMemory( &dsbd, sizeof( DSBUFFERDESC ) ); - dsbd.dwSize = sizeof( DSBUFFERDESC ); - dsbd.dwFlags = dwCreationFlags; - dsbd.dwBufferBytes = dwDSBufferSize; - dsbd.guid3DAlgorithm = guid3DAlgorithm; - dsbd.lpwfxFormat = pWaveFile->m_pwfx; - - // DirectSound is only guarenteed to play PCM data. Other - // formats may or may not work depending the sound card driver. - hr = m_pDS->CreateSoundBuffer( &dsbd, &apDSBuffer[0], NULL ); - - // Be sure to return this error code if it occurs so the - // callers knows this happened. - if( hr == DS_NO_VIRTUALIZATION ) - hrRet = DS_NO_VIRTUALIZATION; - - if( FAILED( hr ) ) - { - // DSERR_BUFFERTOOSMALL will be returned if the buffer is - // less than DSBSIZE_FX_MIN and the buffer is created - // with DSBCAPS_CTRLFX. - - // It might also fail if hardware buffer mixing was requested - // on a device that doesn't support it. - DXUT_ERR( L"CreateSoundBuffer", hr ); - - goto LFail; - } - - // Default to use DuplicateSoundBuffer() when created extra buffers since always - // create a buffer that uses the same memory however DuplicateSoundBuffer() will fail if - // DSBCAPS_CTRLFX is used, so use CreateSoundBuffer() instead in this case. - if( ( dwCreationFlags & DSBCAPS_CTRLFX ) == 0 ) - { - for( i = 1; i < dwNumBuffers; i++ ) - { - if( FAILED( hr = m_pDS->DuplicateSoundBuffer( apDSBuffer[0], &apDSBuffer[i] ) ) ) - { - DXUT_ERR( L"DuplicateSoundBuffer", hr ); - goto LFail; - } - } - } - else - { - for( i = 1; i < dwNumBuffers; i++ ) - { - hr = m_pDS->CreateSoundBuffer( &dsbd, &apDSBuffer[i], NULL ); - if( FAILED( hr ) ) - { - DXUT_ERR( L"CreateSoundBuffer", hr ); - goto LFail; - } - } - } - - // Create the sound - *ppSound = new CSound( apDSBuffer, dwDSBufferSize, dwNumBuffers, pWaveFile, dwCreationFlags ); - - SAFE_DELETE_ARRAY( apDSBuffer ); - return hrRet; - -LFail: - // Cleanup - SAFE_DELETE( pWaveFile ); - SAFE_DELETE_ARRAY( apDSBuffer ); - return hr; -} - - -//----------------------------------------------------------------------------- -// Name: CSoundManager::CreateFromMemory() -// Desc: -//----------------------------------------------------------------------------- -HRESULT CSoundManager::CreateFromMemory( CSound** ppSound, - BYTE* pbData, - ULONG ulDataSize, - LPWAVEFORMATEX pwfx, - DWORD dwCreationFlags, - GUID guid3DAlgorithm, - DWORD dwNumBuffers ) -{ - HRESULT hr; - DWORD i; - LPDIRECTSOUNDBUFFER* apDSBuffer = NULL; - DWORD dwDSBufferSize = NULL; - CWaveFile* pWaveFile = NULL; - - if( m_pDS == NULL ) - return CO_E_NOTINITIALIZED; - if( pbData == NULL || ppSound == NULL || dwNumBuffers < 1 ) - return E_INVALIDARG; - - apDSBuffer = new LPDIRECTSOUNDBUFFER[dwNumBuffers]; - if( apDSBuffer == NULL ) - { - hr = E_OUTOFMEMORY; - goto LFail; - } - - pWaveFile = new CWaveFile(); - if( pWaveFile == NULL ) - { - hr = E_OUTOFMEMORY; - goto LFail; - } - - pWaveFile->OpenFromMemory( pbData, ulDataSize, pwfx, WAVEFILE_READ ); - - - // Make the DirectSound buffer the same size as the wav file - dwDSBufferSize = ulDataSize; - - // Create the direct sound buffer, and only request the flags needed - // since each requires some overhead and limits if the buffer can - // be hardware accelerated - DSBUFFERDESC dsbd; - ZeroMemory( &dsbd, sizeof( DSBUFFERDESC ) ); - dsbd.dwSize = sizeof( DSBUFFERDESC ); - dsbd.dwFlags = dwCreationFlags; - dsbd.dwBufferBytes = dwDSBufferSize; - dsbd.guid3DAlgorithm = guid3DAlgorithm; - dsbd.lpwfxFormat = pwfx; - - if( FAILED( hr = m_pDS->CreateSoundBuffer( &dsbd, &apDSBuffer[0], NULL ) ) ) - { - DXUT_ERR( L"CreateSoundBuffer", hr ); - goto LFail; - } - - // Default to use DuplicateSoundBuffer() when created extra buffers since always - // create a buffer that uses the same memory however DuplicateSoundBuffer() will fail if - // DSBCAPS_CTRLFX is used, so use CreateSoundBuffer() instead in this case. - if( ( dwCreationFlags & DSBCAPS_CTRLFX ) == 0 ) - { - for( i = 1; i < dwNumBuffers; i++ ) - { - if( FAILED( hr = m_pDS->DuplicateSoundBuffer( apDSBuffer[0], &apDSBuffer[i] ) ) ) - { - DXUT_ERR( L"DuplicateSoundBuffer", hr ); - goto LFail; - } - } - } - else - { - for( i = 1; i < dwNumBuffers; i++ ) - { - hr = m_pDS->CreateSoundBuffer( &dsbd, &apDSBuffer[i], NULL ); - if( FAILED( hr ) ) - { - DXUT_ERR( L"CreateSoundBuffer", hr ); - goto LFail; - } - } - } - - // Create the sound - *ppSound = new CSound( apDSBuffer, dwDSBufferSize, dwNumBuffers, pWaveFile, dwCreationFlags ); - - SAFE_DELETE_ARRAY( apDSBuffer ); - return S_OK; - -LFail: - // Cleanup - - SAFE_DELETE_ARRAY( apDSBuffer ); - return hr; -} - - -//----------------------------------------------------------------------------- -// Name: CSoundManager::CreateStreaming() -// Desc: -//----------------------------------------------------------------------------- -HRESULT CSoundManager::CreateStreaming( CStreamingSound** ppStreamingSound, - LPWSTR strWaveFileName, - DWORD dwCreationFlags, - GUID guid3DAlgorithm, - DWORD dwNotifyCount, - DWORD dwNotifySize, - HANDLE hNotifyEvent ) -{ - HRESULT hr; - - if( m_pDS == NULL ) - return CO_E_NOTINITIALIZED; - if( strWaveFileName == NULL || ppStreamingSound == NULL || hNotifyEvent == NULL ) - return E_INVALIDARG; - - LPDIRECTSOUNDBUFFER pDSBuffer = NULL; - DWORD dwDSBufferSize = NULL; - CWaveFile* pWaveFile = NULL; - DSBPOSITIONNOTIFY* aPosNotify = NULL; - LPDIRECTSOUNDNOTIFY pDSNotify = NULL; - - pWaveFile = new CWaveFile(); - if( pWaveFile == NULL ) - return E_OUTOFMEMORY; - pWaveFile->Open( strWaveFileName, NULL, WAVEFILE_READ ); - - // Figure out how big the DirectSound buffer should be - dwDSBufferSize = dwNotifySize * dwNotifyCount; - - // Set up the direct sound buffer. Request the NOTIFY flag, so - // that we are notified as the sound buffer plays. Note, that using this flag - // may limit the amount of hardware acceleration that can occur. - DSBUFFERDESC dsbd; - ZeroMemory( &dsbd, sizeof( DSBUFFERDESC ) ); - dsbd.dwSize = sizeof( DSBUFFERDESC ); - dsbd.dwFlags = dwCreationFlags | - DSBCAPS_CTRLPOSITIONNOTIFY | - DSBCAPS_GETCURRENTPOSITION2; - dsbd.dwBufferBytes = dwDSBufferSize; - dsbd.guid3DAlgorithm = guid3DAlgorithm; - dsbd.lpwfxFormat = pWaveFile->m_pwfx; - - if( FAILED( hr = m_pDS->CreateSoundBuffer( &dsbd, &pDSBuffer, NULL ) ) ) - { - // If wave format isn't then it will return - // either DSERR_BADFORMAT or E_INVALIDARG - if( hr == DSERR_BADFORMAT || hr == E_INVALIDARG ) - return DXUT_ERR( L"CreateSoundBuffer", hr ); - - return DXUT_ERR( L"CreateSoundBuffer", hr ); - } - - // Create the notification events, so that we know when to fill - // the buffer as the sound plays. - if( FAILED( hr = pDSBuffer->QueryInterface( IID_IDirectSoundNotify, - ( VOID** )&pDSNotify ) ) ) - { - SAFE_DELETE_ARRAY( aPosNotify ); - return DXUT_ERR( L"QueryInterface", hr ); - } - - aPosNotify = new DSBPOSITIONNOTIFY[ dwNotifyCount ]; - if( aPosNotify == NULL ) - return E_OUTOFMEMORY; - - for( DWORD i = 0; i < dwNotifyCount; i++ ) - { - aPosNotify[i].dwOffset = ( dwNotifySize * i ) + dwNotifySize - 1; - aPosNotify[i].hEventNotify = hNotifyEvent; - } - - // Tell DirectSound when to notify us. The notification will come in the from - // of signaled events that are handled in WinMain() - if( FAILED( hr = pDSNotify->SetNotificationPositions( dwNotifyCount, - aPosNotify ) ) ) - { - SAFE_RELEASE( pDSNotify ); - SAFE_DELETE_ARRAY( aPosNotify ); - return DXUT_ERR( L"SetNotificationPositions", hr ); - } - - SAFE_RELEASE( pDSNotify ); - SAFE_DELETE_ARRAY( aPosNotify ); - - // Create the sound - *ppStreamingSound = new CStreamingSound( pDSBuffer, dwDSBufferSize, pWaveFile, dwNotifySize ); - - return S_OK; -} - - -//----------------------------------------------------------------------------- -// Name: CSound::CSound() -// Desc: Constructs the class -//----------------------------------------------------------------------------- -CSound::CSound( LPDIRECTSOUNDBUFFER* apDSBuffer, DWORD dwDSBufferSize, - DWORD dwNumBuffers, CWaveFile* pWaveFile, DWORD dwCreationFlags ) -{ - DWORD i; - - if( dwNumBuffers <= 0 ) - return; - - m_apDSBuffer = new LPDIRECTSOUNDBUFFER[dwNumBuffers]; - if( NULL != m_apDSBuffer ) - { - for( i = 0; i < dwNumBuffers; i++ ) - m_apDSBuffer[i] = apDSBuffer[i]; - - m_dwDSBufferSize = dwDSBufferSize; - m_dwNumBuffers = dwNumBuffers; - m_pWaveFile = pWaveFile; - m_dwCreationFlags = dwCreationFlags; - - FillBufferWithSound( m_apDSBuffer[0], FALSE ); - } -} - - -//----------------------------------------------------------------------------- -// Name: CSound::~CSound() -// Desc: Destroys the class -//----------------------------------------------------------------------------- -CSound::~CSound() -{ - for( DWORD i = 0; i < m_dwNumBuffers; i++ ) - { - SAFE_RELEASE( m_apDSBuffer[i] ); - } - - SAFE_DELETE_ARRAY( m_apDSBuffer ); - SAFE_DELETE( m_pWaveFile ); -} - - -//----------------------------------------------------------------------------- -// Name: CSound::FillBufferWithSound() -// Desc: Fills a DirectSound buffer with a sound file -//----------------------------------------------------------------------------- -HRESULT CSound::FillBufferWithSound( LPDIRECTSOUNDBUFFER pDSB, BOOL bRepeatWavIfBufferLarger ) -{ - HRESULT hr; - VOID* pDSLockedBuffer = NULL; // Pointer to locked buffer memory - DWORD dwDSLockedBufferSize = 0; // Size of the locked DirectSound buffer - DWORD dwWavDataRead = 0; // Amount of data read from the wav file - - if( pDSB == NULL ) - return CO_E_NOTINITIALIZED; - - // Make sure we have focus, and we didn't just switch in from - // an app which had a DirectSound device - if( FAILED( hr = RestoreBuffer( pDSB, NULL ) ) ) - return DXUT_ERR( L"RestoreBuffer", hr ); - - // Lock the buffer down - if( FAILED( hr = pDSB->Lock( 0, m_dwDSBufferSize, - &pDSLockedBuffer, &dwDSLockedBufferSize, - NULL, NULL, 0L ) ) ) - return DXUT_ERR( L"Lock", hr ); - - // Reset the wave file to the beginning - m_pWaveFile->ResetFile(); - - if( FAILED( hr = m_pWaveFile->Read( ( BYTE* )pDSLockedBuffer, - dwDSLockedBufferSize, - &dwWavDataRead ) ) ) - return DXUT_ERR( L"Read", hr ); - - if( dwWavDataRead == 0 ) - { - // Wav is blank, so just fill with silence - FillMemory( ( BYTE* )pDSLockedBuffer, - dwDSLockedBufferSize, - ( BYTE )( m_pWaveFile->m_pwfx->wBitsPerSample == 8 ? 128 : 0 ) ); - } - else if( dwWavDataRead < dwDSLockedBufferSize ) - { - // If the wav file was smaller than the DirectSound buffer, - // we need to fill the remainder of the buffer with data - if( bRepeatWavIfBufferLarger ) - { - // Reset the file and fill the buffer with wav data - DWORD dwReadSoFar = dwWavDataRead; // From previous call above. - while( dwReadSoFar < dwDSLockedBufferSize ) - { - // This will keep reading in until the buffer is full - // for very short files - if( FAILED( hr = m_pWaveFile->ResetFile() ) ) - return DXUT_ERR( L"ResetFile", hr ); - - hr = m_pWaveFile->Read( ( BYTE* )pDSLockedBuffer + dwReadSoFar, - dwDSLockedBufferSize - dwReadSoFar, - &dwWavDataRead ); - if( FAILED( hr ) ) - return DXUT_ERR( L"Read", hr ); - - dwReadSoFar += dwWavDataRead; - } - } - else - { - // Don't repeat the wav file, just fill in silence - FillMemory( ( BYTE* )pDSLockedBuffer + dwWavDataRead, - dwDSLockedBufferSize - dwWavDataRead, - ( BYTE )( m_pWaveFile->m_pwfx->wBitsPerSample == 8 ? 128 : 0 ) ); - } - } - - // Unlock the buffer, we don't need it anymore. - pDSB->Unlock( pDSLockedBuffer, dwDSLockedBufferSize, NULL, 0 ); - - return S_OK; -} - - -//----------------------------------------------------------------------------- -// Name: CSound::RestoreBuffer() -// Desc: Restores the lost buffer. *pbWasRestored returns TRUE if the buffer was -// restored. It can also NULL if the information is not needed. -//----------------------------------------------------------------------------- -HRESULT CSound::RestoreBuffer( LPDIRECTSOUNDBUFFER pDSB, BOOL* pbWasRestored ) -{ - HRESULT hr; - - if( pDSB == NULL ) - return CO_E_NOTINITIALIZED; - if( pbWasRestored ) - *pbWasRestored = FALSE; - - DWORD dwStatus; - if( FAILED( hr = pDSB->GetStatus( &dwStatus ) ) ) - return DXUT_ERR( L"GetStatus", hr ); - - if( dwStatus & DSBSTATUS_BUFFERLOST ) - { - // Since the app could have just been activated, then - // DirectSound may not be giving us control yet, so - // the restoring the buffer may fail. - // If it does, sleep until DirectSound gives us control. - do - { - hr = pDSB->Restore(); - if( hr == DSERR_BUFFERLOST ) - Sleep( 10 ); - } while( ( hr = pDSB->Restore() ) == DSERR_BUFFERLOST ); - - if( pbWasRestored != NULL ) - *pbWasRestored = TRUE; - - return S_OK; - } - else - { - return S_FALSE; - } -} - - -//----------------------------------------------------------------------------- -// Name: CSound::GetFreeBuffer() -// Desc: Finding the first buffer that is not playing and return a pointer to -// it, or if all are playing return a pointer to a randomly selected buffer. -//----------------------------------------------------------------------------- -LPDIRECTSOUNDBUFFER CSound::GetFreeBuffer() -{ - if( m_apDSBuffer == NULL ) - return FALSE; - - DWORD i; - for( i = 0; i < m_dwNumBuffers; i++ ) - { - if( m_apDSBuffer[i] ) - { - DWORD dwStatus = 0; - m_apDSBuffer[i]->GetStatus( &dwStatus ); - if( ( dwStatus & DSBSTATUS_PLAYING ) == 0 ) - break; - } - } - - if( i != m_dwNumBuffers ) - return m_apDSBuffer[ i ]; - else - return m_apDSBuffer[ rand() % m_dwNumBuffers ]; -} - - -//----------------------------------------------------------------------------- -// Name: CSound::GetBuffer() -// Desc: -//----------------------------------------------------------------------------- -LPDIRECTSOUNDBUFFER CSound::GetBuffer( DWORD dwIndex ) -{ - if( m_apDSBuffer == NULL ) - return NULL; - if( dwIndex >= m_dwNumBuffers ) - return NULL; - - return m_apDSBuffer[dwIndex]; -} - - -//----------------------------------------------------------------------------- -// Name: CSound::Get3DBufferInterface() -// Desc: -//----------------------------------------------------------------------------- -HRESULT CSound::Get3DBufferInterface( DWORD dwIndex, LPDIRECTSOUND3DBUFFER* ppDS3DBuffer ) -{ - if( m_apDSBuffer == NULL ) - return CO_E_NOTINITIALIZED; - if( dwIndex >= m_dwNumBuffers ) - return E_INVALIDARG; - - *ppDS3DBuffer = NULL; - - return m_apDSBuffer[dwIndex]->QueryInterface( IID_IDirectSound3DBuffer, - ( VOID** )ppDS3DBuffer ); -} - - -//----------------------------------------------------------------------------- -// Name: CSound::Play() -// Desc: Plays the sound using voice management flags. Pass in DSBPLAY_LOOPING -// in the dwFlags to loop the sound -//----------------------------------------------------------------------------- -HRESULT CSound::Play( DWORD dwPriority, DWORD dwFlags, LONG lVolume, LONG lFrequency, LONG lPan ) -{ - HRESULT hr; - BOOL bRestored; - - if( m_apDSBuffer == NULL ) - return CO_E_NOTINITIALIZED; - - LPDIRECTSOUNDBUFFER pDSB = GetFreeBuffer(); - - if( pDSB == NULL ) - return DXUT_ERR( L"GetFreeBuffer", E_FAIL ); - - // Restore the buffer if it was lost - if( FAILED( hr = RestoreBuffer( pDSB, &bRestored ) ) ) - return DXUT_ERR( L"RestoreBuffer", hr ); - - if( bRestored ) - { - // The buffer was restored, so we need to fill it with new data - if( FAILED( hr = FillBufferWithSound( pDSB, FALSE ) ) ) - return DXUT_ERR( L"FillBufferWithSound", hr ); - } - - if( m_dwCreationFlags & DSBCAPS_CTRLVOLUME ) - { - pDSB->SetVolume( lVolume ); - } - - if( lFrequency != -1 && - ( m_dwCreationFlags & DSBCAPS_CTRLFREQUENCY ) ) - { - pDSB->SetFrequency( lFrequency ); - } - - if( m_dwCreationFlags & DSBCAPS_CTRLPAN ) - { - pDSB->SetPan( lPan ); - } - - return pDSB->Play( 0, dwPriority, dwFlags ); -} - - -//----------------------------------------------------------------------------- -// Name: CSound::Play3D() -// Desc: Plays the sound using voice management flags. Pass in DSBPLAY_LOOPING -// in the dwFlags to loop the sound -//----------------------------------------------------------------------------- -HRESULT CSound::Play3D( LPDS3DBUFFER p3DBuffer, DWORD dwPriority, DWORD dwFlags, LONG lFrequency ) -{ - HRESULT hr; - BOOL bRestored; - DWORD dwBaseFrequency; - - if( m_apDSBuffer == NULL ) - return CO_E_NOTINITIALIZED; - - LPDIRECTSOUNDBUFFER pDSB = GetFreeBuffer(); - if( pDSB == NULL ) - return DXUT_ERR( L"GetFreeBuffer", E_FAIL ); - - // Restore the buffer if it was lost - if( FAILED( hr = RestoreBuffer( pDSB, &bRestored ) ) ) - return DXUT_ERR( L"RestoreBuffer", hr ); - - if( bRestored ) - { - // The buffer was restored, so we need to fill it with new data - if( FAILED( hr = FillBufferWithSound( pDSB, FALSE ) ) ) - return DXUT_ERR( L"FillBufferWithSound", hr ); - } - - if( m_dwCreationFlags & DSBCAPS_CTRLFREQUENCY ) - { - pDSB->GetFrequency( &dwBaseFrequency ); - pDSB->SetFrequency( dwBaseFrequency + lFrequency ); - } - - // QI for the 3D buffer - LPDIRECTSOUND3DBUFFER pDS3DBuffer; - hr = pDSB->QueryInterface( IID_IDirectSound3DBuffer, ( VOID** )&pDS3DBuffer ); - if( SUCCEEDED( hr ) ) - { - hr = pDS3DBuffer->SetAllParameters( p3DBuffer, DS3D_IMMEDIATE ); - if( SUCCEEDED( hr ) ) - { - hr = pDSB->Play( 0, dwPriority, dwFlags ); - } - - pDS3DBuffer->Release(); - } - - return hr; -} - - -//----------------------------------------------------------------------------- -// Name: CSound::Stop() -// Desc: Stops the sound from playing -//----------------------------------------------------------------------------- -HRESULT CSound::Stop() -{ - if( m_apDSBuffer == NULL ) - return CO_E_NOTINITIALIZED; - - HRESULT hr = 0; - - for( DWORD i = 0; i < m_dwNumBuffers; i++ ) - hr |= m_apDSBuffer[i]->Stop(); - - return hr; -} - - -//----------------------------------------------------------------------------- -// Name: CSound::Reset() -// Desc: Reset all of the sound buffers -//----------------------------------------------------------------------------- -HRESULT CSound::Reset() -{ - if( m_apDSBuffer == NULL ) - return CO_E_NOTINITIALIZED; - - HRESULT hr = 0; - - for( DWORD i = 0; i < m_dwNumBuffers; i++ ) - hr |= m_apDSBuffer[i]->SetCurrentPosition( 0 ); - - return hr; -} - - -//----------------------------------------------------------------------------- -// Name: CSound::IsSoundPlaying() -// Desc: Checks to see if a buffer is playing and returns TRUE if it is. -//----------------------------------------------------------------------------- -BOOL CSound::IsSoundPlaying() -{ - BOOL bIsPlaying = FALSE; - - if( m_apDSBuffer == NULL ) - return FALSE; - - for( DWORD i = 0; i < m_dwNumBuffers; i++ ) - { - if( m_apDSBuffer[i] ) - { - DWORD dwStatus = 0; - m_apDSBuffer[i]->GetStatus( &dwStatus ); - bIsPlaying |= ( ( dwStatus & DSBSTATUS_PLAYING ) != 0 ); - } - } - - return bIsPlaying; -} - - -//----------------------------------------------------------------------------- -// Name: CStreamingSound::CStreamingSound() -// Desc: Setups up a buffer so data can be streamed from the wave file into -// a buffer. This is very useful for large wav files that would take a -// while to load. The buffer is initially filled with data, then -// as sound is played the notification events are signaled and more data -// is written into the buffer by calling HandleWaveStreamNotification() -//----------------------------------------------------------------------------- -CStreamingSound::CStreamingSound( LPDIRECTSOUNDBUFFER pDSBuffer, DWORD dwDSBufferSize, - CWaveFile* pWaveFile, DWORD dwNotifySize ) : CSound( &pDSBuffer, dwDSBufferSize, 1, - pWaveFile, 0 ) -{ - m_dwLastPlayPos = 0; - m_dwPlayProgress = 0; - m_dwNotifySize = dwNotifySize; - m_dwNextWriteOffset = 0; - m_bFillNextNotificationWithSilence = FALSE; -} - - -//----------------------------------------------------------------------------- -// Name: CStreamingSound::~CStreamingSound() -// Desc: Destroys the class -//----------------------------------------------------------------------------- -CStreamingSound::~CStreamingSound() -{ -} - - -//----------------------------------------------------------------------------- -// Name: CStreamingSound::HandleWaveStreamNotification() -// Desc: Handle the notification that tells us to put more wav data in the -// circular buffer -//----------------------------------------------------------------------------- -HRESULT CStreamingSound::HandleWaveStreamNotification( BOOL bLoopedPlay ) -{ - HRESULT hr; - DWORD dwCurrentPlayPos; - DWORD dwPlayDelta; - DWORD dwBytesWrittenToBuffer; - VOID* pDSLockedBuffer = NULL; - VOID* pDSLockedBuffer2 = NULL; - DWORD dwDSLockedBufferSize; - DWORD dwDSLockedBufferSize2; - - if( m_apDSBuffer == NULL || m_pWaveFile == NULL ) - return CO_E_NOTINITIALIZED; - - // Restore the buffer if it was lost - BOOL bRestored; - if( FAILED( hr = RestoreBuffer( m_apDSBuffer[0], &bRestored ) ) ) - return DXUT_ERR( L"RestoreBuffer", hr ); - - if( bRestored ) - { - // The buffer was restored, so we need to fill it with new data - if( FAILED( hr = FillBufferWithSound( m_apDSBuffer[0], FALSE ) ) ) - return DXUT_ERR( L"FillBufferWithSound", hr ); - return S_OK; - } - - // Lock the DirectSound buffer - if( FAILED( hr = m_apDSBuffer[0]->Lock( m_dwNextWriteOffset, m_dwNotifySize, - &pDSLockedBuffer, &dwDSLockedBufferSize, - &pDSLockedBuffer2, &dwDSLockedBufferSize2, 0L ) ) ) - return DXUT_ERR( L"Lock", hr ); - - // m_dwDSBufferSize and m_dwNextWriteOffset are both multiples of m_dwNotifySize, - // it should the second buffer, so it should never be valid - if( pDSLockedBuffer2 != NULL ) - return E_UNEXPECTED; - - if( !m_bFillNextNotificationWithSilence ) - { - // Fill the DirectSound buffer with wav data - if( FAILED( hr = m_pWaveFile->Read( ( BYTE* )pDSLockedBuffer, - dwDSLockedBufferSize, - &dwBytesWrittenToBuffer ) ) ) - return DXUT_ERR( L"Read", hr ); - } - else - { - // Fill the DirectSound buffer with silence - FillMemory( pDSLockedBuffer, dwDSLockedBufferSize, - ( BYTE )( m_pWaveFile->m_pwfx->wBitsPerSample == 8 ? 128 : 0 ) ); - dwBytesWrittenToBuffer = dwDSLockedBufferSize; - } - - // If the number of bytes written is less than the - // amount we requested, we have a short file. - if( dwBytesWrittenToBuffer < dwDSLockedBufferSize ) - { - if( !bLoopedPlay ) - { - // Fill in silence for the rest of the buffer. - FillMemory( ( BYTE* )pDSLockedBuffer + dwBytesWrittenToBuffer, - dwDSLockedBufferSize - dwBytesWrittenToBuffer, - ( BYTE )( m_pWaveFile->m_pwfx->wBitsPerSample == 8 ? 128 : 0 ) ); - - // Any future notifications should just fill the buffer with silence - m_bFillNextNotificationWithSilence = TRUE; - } - else - { - // We are looping, so reset the file and fill the buffer with wav data - DWORD dwReadSoFar = dwBytesWrittenToBuffer; // From previous call above. - while( dwReadSoFar < dwDSLockedBufferSize ) - { - // This will keep reading in until the buffer is full (for very short files). - if( FAILED( hr = m_pWaveFile->ResetFile() ) ) - return DXUT_ERR( L"ResetFile", hr ); - - if( FAILED( hr = m_pWaveFile->Read( ( BYTE* )pDSLockedBuffer + dwReadSoFar, - dwDSLockedBufferSize - dwReadSoFar, - &dwBytesWrittenToBuffer ) ) ) - return DXUT_ERR( L"Read", hr ); - - dwReadSoFar += dwBytesWrittenToBuffer; - } - } - } - - // Unlock the DirectSound buffer - m_apDSBuffer[0]->Unlock( pDSLockedBuffer, dwDSLockedBufferSize, NULL, 0 ); - - // Figure out how much data has been played so far. When we have played - // past the end of the file, we will either need to start filling the - // buffer with silence or starting reading from the beginning of the file, - // depending if the user wants to loop the sound - if( FAILED( hr = m_apDSBuffer[0]->GetCurrentPosition( &dwCurrentPlayPos, NULL ) ) ) - return DXUT_ERR( L"GetCurrentPosition", hr ); - - // Check to see if the position counter looped - if( dwCurrentPlayPos < m_dwLastPlayPos ) - dwPlayDelta = ( m_dwDSBufferSize - m_dwLastPlayPos ) + dwCurrentPlayPos; - else - dwPlayDelta = dwCurrentPlayPos - m_dwLastPlayPos; - - m_dwPlayProgress += dwPlayDelta; - m_dwLastPlayPos = dwCurrentPlayPos; - - // If we are now filling the buffer with silence, then we have found the end so - // check to see if the entire sound has played, if it has then stop the buffer. - if( m_bFillNextNotificationWithSilence ) - { - // We don't want to cut off the sound before it's done playing. - if( m_dwPlayProgress >= m_pWaveFile->GetSize() ) - { - m_apDSBuffer[0]->Stop(); - } - } - - // Update where the buffer will lock (for next time) - m_dwNextWriteOffset += dwDSLockedBufferSize; - m_dwNextWriteOffset %= m_dwDSBufferSize; // Circular buffer - - return S_OK; -} - - -//----------------------------------------------------------------------------- -// Name: CStreamingSound::Reset() -// Desc: Resets the sound so it will begin playing at the beginning -//----------------------------------------------------------------------------- -HRESULT CStreamingSound::Reset() -{ - HRESULT hr; - - if( m_apDSBuffer[0] == NULL || m_pWaveFile == NULL ) - return CO_E_NOTINITIALIZED; - - m_dwLastPlayPos = 0; - m_dwPlayProgress = 0; - m_dwNextWriteOffset = 0; - m_bFillNextNotificationWithSilence = FALSE; - - // Restore the buffer if it was lost - BOOL bRestored; - if( FAILED( hr = RestoreBuffer( m_apDSBuffer[0], &bRestored ) ) ) - return DXUT_ERR( L"RestoreBuffer", hr ); - - if( bRestored ) - { - // The buffer was restored, so we need to fill it with new data - if( FAILED( hr = FillBufferWithSound( m_apDSBuffer[0], FALSE ) ) ) - return DXUT_ERR( L"FillBufferWithSound", hr ); - } - - m_pWaveFile->ResetFile(); - - return m_apDSBuffer[0]->SetCurrentPosition( 0L ); -} diff --git a/FriedLiver/Source/DXUT/Optional/SDKsound.h b/FriedLiver/Source/DXUT/Optional/SDKsound.h deleted file mode 100644 index b79054a5..00000000 --- a/FriedLiver/Source/DXUT/Optional/SDKsound.h +++ /dev/null @@ -1,124 +0,0 @@ -//----------------------------------------------------------------------------- -// File: DXUTsound.h -// -// Copyright (c) Microsoft Corp. All rights reserved. -//----------------------------------------------------------------------------- -#ifndef DXUTSOUND_H -#define DXUTSOUND_H - -//----------------------------------------------------------------------------- -// Header Includes -//----------------------------------------------------------------------------- -#include -#include - -//----------------------------------------------------------------------------- -// Classes used by this header -//----------------------------------------------------------------------------- -class CSoundManager; -class CSound; -class CStreamingSound; -class CWaveFile; - - -//----------------------------------------------------------------------------- -// Typing macros -//----------------------------------------------------------------------------- -#define DXUT_StopSound(s) { if(s) s->Stop(); } -#define DXUT_PlaySound(s) { if(s) s->Play( 0, 0 ); } -#define DXUT_PlaySoundLooping(s) { if(s) s->Play( 0, DSBPLAY_LOOPING ); } - - -//----------------------------------------------------------------------------- -// Name: class CSoundManager -// Desc: -//----------------------------------------------------------------------------- -class CSoundManager -{ -protected: - IDirectSound8* m_pDS; - -public: - CSoundManager(); - ~CSoundManager(); - - HRESULT Initialize( HWND hWnd, DWORD dwCoopLevel ); - inline LPDIRECTSOUND8 GetDirectSound() - { - return m_pDS; - } - HRESULT SetPrimaryBufferFormat( DWORD dwPrimaryChannels, DWORD dwPrimaryFreq, - DWORD dwPrimaryBitRate ); - HRESULT Get3DListenerInterface( LPDIRECTSOUND3DLISTENER* ppDSListener ); - - HRESULT Create( CSound** ppSound, LPWSTR strWaveFileName, DWORD dwCreationFlags = 0, - GUID guid3DAlgorithm = GUID_NULL, DWORD dwNumBuffers = 1 ); - HRESULT CreateFromMemory( CSound** ppSound, BYTE* pbData, ULONG ulDataSize, LPWAVEFORMATEX pwfx, - DWORD dwCreationFlags = 0, GUID guid3DAlgorithm = GUID_NULL, - DWORD dwNumBuffers = 1 ); - HRESULT CreateStreaming( CStreamingSound** ppStreamingSound, LPWSTR strWaveFileName, - DWORD dwCreationFlags, GUID guid3DAlgorithm, DWORD dwNotifyCount, - DWORD dwNotifySize, HANDLE hNotifyEvent ); -}; - - -//----------------------------------------------------------------------------- -// Name: class CSound -// Desc: Encapsulates functionality of a DirectSound buffer. -//----------------------------------------------------------------------------- -class CSound -{ -protected: - LPDIRECTSOUNDBUFFER* m_apDSBuffer; - DWORD m_dwDSBufferSize; - CWaveFile* m_pWaveFile; - DWORD m_dwNumBuffers; - DWORD m_dwCreationFlags; - - HRESULT RestoreBuffer( LPDIRECTSOUNDBUFFER pDSB, BOOL* pbWasRestored ); - -public: - CSound( LPDIRECTSOUNDBUFFER* apDSBuffer, DWORD dwDSBufferSize, DWORD dwNumBuffers, - CWaveFile* pWaveFile, DWORD dwCreationFlags ); - virtual ~CSound(); - - HRESULT Get3DBufferInterface( DWORD dwIndex, LPDIRECTSOUND3DBUFFER* ppDS3DBuffer ); - HRESULT FillBufferWithSound( LPDIRECTSOUNDBUFFER pDSB, BOOL bRepeatWavIfBufferLarger ); - LPDIRECTSOUNDBUFFER GetFreeBuffer(); - LPDIRECTSOUNDBUFFER GetBuffer( DWORD dwIndex ); - - HRESULT Play( DWORD dwPriority = 0, DWORD dwFlags = 0, LONG lVolume = 0, LONG lFrequency = -1, - LONG lPan = 0 ); - HRESULT Play3D( LPDS3DBUFFER p3DBuffer, DWORD dwPriority = 0, DWORD dwFlags = 0, LONG lFrequency = 0 ); - HRESULT Stop(); - HRESULT Reset(); - BOOL IsSoundPlaying(); -}; - - -//----------------------------------------------------------------------------- -// Name: class CStreamingSound -// Desc: Encapsulates functionality to play a wave file with DirectSound. -// The Create() method loads a chunk of wave file into the buffer, -// and as sound plays more is written to the buffer by calling -// HandleWaveStreamNotification() whenever hNotifyEvent is signaled. -//----------------------------------------------------------------------------- -class CStreamingSound : public CSound -{ -protected: - DWORD m_dwLastPlayPos; - DWORD m_dwPlayProgress; - DWORD m_dwNotifySize; - DWORD m_dwNextWriteOffset; - BOOL m_bFillNextNotificationWithSilence; - -public: - CStreamingSound( LPDIRECTSOUNDBUFFER pDSBuffer, DWORD dwDSBufferSize, CWaveFile* pWaveFile, - DWORD dwNotifySize ); - ~CStreamingSound(); - - HRESULT HandleWaveStreamNotification( BOOL bLoopedPlay ); - HRESULT Reset(); -}; - -#endif // DXUTSOUND_H diff --git a/FriedLiver/Source/DXUT/Optional/SDKwavefile.cpp b/FriedLiver/Source/DXUT/Optional/SDKwavefile.cpp deleted file mode 100644 index 9f706977..00000000 --- a/FriedLiver/Source/DXUT/Optional/SDKwavefile.cpp +++ /dev/null @@ -1,546 +0,0 @@ -//----------------------------------------------------------------------------- -// File: SDKWaveFile.cpp -// -// Desc: Classes for reading and writing wav files. Feel free to use this class -// as a starting point for adding extra functionality. -// -// XNA Developer Connection -// -// Copyright (c) Microsoft Corp. All rights reserved. -//----------------------------------------------------------------------------- -#define STRICT -#include "DXUT.h" -#include "SDKwavefile.h" -#undef min // use __min instead -#undef max // use __max instead - -//----------------------------------------------------------------------------- -// Name: CWaveFile::CWaveFile() -// Desc: Constructs the class. Call Open() to open a wave file for reading. -// Then call Read() as needed. Calling the destructor or Close() -// will close the file. -//----------------------------------------------------------------------------- -CWaveFile::CWaveFile() -{ - m_pwfx = NULL; - m_hmmio = NULL; - m_pResourceBuffer = NULL; - m_dwSize = 0; - m_bIsReadingFromMemory = FALSE; -} - - -//----------------------------------------------------------------------------- -// Name: CWaveFile::~CWaveFile() -// Desc: Destructs the class -//----------------------------------------------------------------------------- -CWaveFile::~CWaveFile() -{ - Close(); - - if( !m_bIsReadingFromMemory ) - SAFE_DELETE_ARRAY( m_pwfx ); -} - - -//----------------------------------------------------------------------------- -// Name: CWaveFile::Open() -// Desc: Opens a wave file for reading -//----------------------------------------------------------------------------- -HRESULT CWaveFile::Open( LPWSTR strFileName, WAVEFORMATEX* pwfx, DWORD dwFlags ) -{ - HRESULT hr; - - m_dwFlags = dwFlags; - m_bIsReadingFromMemory = FALSE; - - if( m_dwFlags == WAVEFILE_READ ) - { - if( strFileName == NULL ) - return E_INVALIDARG; - SAFE_DELETE_ARRAY( m_pwfx ); - - m_hmmio = mmioOpen( strFileName, NULL, MMIO_ALLOCBUF | MMIO_READ ); - - if( NULL == m_hmmio ) - { - HRSRC hResInfo; - HGLOBAL hResData; - DWORD dwSize; - VOID* pvRes; - - // Loading it as a file failed, so try it as a resource - if( NULL == ( hResInfo = FindResource( NULL, strFileName, L"WAVE" ) ) ) - { - if( NULL == ( hResInfo = FindResource( NULL, strFileName, L"WAV" ) ) ) - return DXTRACE_ERR( L"FindResource", E_FAIL ); - } - - if( NULL == ( hResData = LoadResource( GetModuleHandle( NULL ), hResInfo ) ) ) - return DXTRACE_ERR( L"LoadResource", E_FAIL ); - - if( 0 == ( dwSize = SizeofResource( GetModuleHandle( NULL ), hResInfo ) ) ) - return DXTRACE_ERR( L"SizeofResource", E_FAIL ); - - if( NULL == ( pvRes = LockResource( hResData ) ) ) - return DXTRACE_ERR( L"LockResource", E_FAIL ); - - m_pResourceBuffer = new CHAR[ dwSize ]; - if( m_pResourceBuffer == NULL ) - return DXTRACE_ERR( L"new", E_OUTOFMEMORY ); - memcpy( m_pResourceBuffer, pvRes, dwSize ); - - MMIOINFO mmioInfo; - ZeroMemory( &mmioInfo, sizeof( mmioInfo ) ); - mmioInfo.fccIOProc = FOURCC_MEM; - mmioInfo.cchBuffer = dwSize; - mmioInfo.pchBuffer = ( CHAR* )m_pResourceBuffer; - - m_hmmio = mmioOpen( NULL, &mmioInfo, MMIO_ALLOCBUF | MMIO_READ ); - } - - if( FAILED( hr = ReadMMIO() ) ) - { - // ReadMMIO will fail if its an not a wave file - mmioClose( m_hmmio, 0 ); - return DXTRACE_ERR( L"ReadMMIO", hr ); - } - - if( FAILED( hr = ResetFile() ) ) - return DXTRACE_ERR( L"ResetFile", hr ); - - // After the reset, the size of the wav file is m_ck.cksize so store it now - m_dwSize = m_ck.cksize; - } - else - { - m_hmmio = mmioOpen( strFileName, NULL, MMIO_ALLOCBUF | - MMIO_READWRITE | - MMIO_CREATE ); - if( NULL == m_hmmio ) - return DXTRACE_ERR( L"mmioOpen", E_FAIL ); - - if( FAILED( hr = WriteMMIO( pwfx ) ) ) - { - mmioClose( m_hmmio, 0 ); - return DXTRACE_ERR( L"WriteMMIO", hr ); - } - - if( FAILED( hr = ResetFile() ) ) - return DXTRACE_ERR( L"ResetFile", hr ); - } - - return hr; -} - - -//----------------------------------------------------------------------------- -// Name: CWaveFile::OpenFromMemory() -// Desc: copy data to CWaveFile member variable from memory -//----------------------------------------------------------------------------- -HRESULT CWaveFile::OpenFromMemory( BYTE* pbData, ULONG ulDataSize, - WAVEFORMATEX* pwfx, DWORD dwFlags ) -{ - m_pwfx = pwfx; - m_ulDataSize = ulDataSize; - m_pbData = pbData; - m_pbDataCur = m_pbData; - m_bIsReadingFromMemory = TRUE; - - if( dwFlags != WAVEFILE_READ ) - return E_NOTIMPL; - - return S_OK; -} - - -//----------------------------------------------------------------------------- -// Name: CWaveFile::ReadMMIO() -// Desc: Support function for reading from a multimedia I/O stream. -// m_hmmio must be valid before calling. This function uses it to -// update m_ckRiff, and m_pwfx. -//----------------------------------------------------------------------------- -HRESULT CWaveFile::ReadMMIO() -{ - MMCKINFO ckIn; // chunk info. for general use. - PCMWAVEFORMAT pcmWaveFormat; // Temp PCM structure to load in. - - memset( &ckIn, 0, sizeof(ckIn) ); - - m_pwfx = NULL; - - if( ( 0 != mmioDescend( m_hmmio, &m_ckRiff, NULL, 0 ) ) ) - return DXTRACE_ERR( L"mmioDescend", E_FAIL ); - - // Check to make sure this is a valid wave file - if( ( m_ckRiff.ckid != FOURCC_RIFF ) || - ( m_ckRiff.fccType != mmioFOURCC( 'W', 'A', 'V', 'E' ) ) ) - return DXTRACE_ERR( L"mmioFOURCC", E_FAIL ); - - // Search the input file for for the 'fmt ' chunk. - ckIn.ckid = mmioFOURCC( 'f', 'm', 't', ' ' ); - if( 0 != mmioDescend( m_hmmio, &ckIn, &m_ckRiff, MMIO_FINDCHUNK ) ) - return DXTRACE_ERR( L"mmioDescend", E_FAIL ); - - // Expect the 'fmt' chunk to be at least as large as ; - // if there are extra parameters at the end, we'll ignore them - if( ckIn.cksize < ( LONG )sizeof( PCMWAVEFORMAT ) ) - return DXTRACE_ERR( L"sizeof(PCMWAVEFORMAT)", E_FAIL ); - - // Read the 'fmt ' chunk into . - if( mmioRead( m_hmmio, ( HPSTR )&pcmWaveFormat, - sizeof( pcmWaveFormat ) ) != sizeof( pcmWaveFormat ) ) - return DXTRACE_ERR( L"mmioRead", E_FAIL ); - - // Allocate the waveformatex, but if its not pcm format, read the next - // word, and thats how many extra bytes to allocate. - if( pcmWaveFormat.wf.wFormatTag == WAVE_FORMAT_PCM ) - { - m_pwfx = ( WAVEFORMATEX* )new CHAR[ sizeof( WAVEFORMATEX ) ]; - if( NULL == m_pwfx ) - return DXTRACE_ERR( L"m_pwfx", E_FAIL ); - - // Copy the bytes from the pcm structure to the waveformatex structure - memcpy( m_pwfx, &pcmWaveFormat, sizeof( pcmWaveFormat ) ); - m_pwfx->cbSize = 0; - } - else - { - // Read in length of extra bytes. - WORD cbExtraBytes = 0L; - if( mmioRead( m_hmmio, ( CHAR* )&cbExtraBytes, sizeof( WORD ) ) != sizeof( WORD ) ) - return DXTRACE_ERR( L"mmioRead", E_FAIL ); - - m_pwfx = ( WAVEFORMATEX* )new CHAR[ sizeof( WAVEFORMATEX ) + cbExtraBytes ]; - if( NULL == m_pwfx ) - return DXTRACE_ERR( L"new", E_FAIL ); - - // Copy the bytes from the pcm structure to the waveformatex structure - memcpy( m_pwfx, &pcmWaveFormat, sizeof( pcmWaveFormat ) ); - m_pwfx->cbSize = cbExtraBytes; - - // Now, read those extra bytes into the structure, if cbExtraAlloc != 0. - if( mmioRead( m_hmmio, ( CHAR* )( ( ( BYTE* )&( m_pwfx->cbSize ) ) + sizeof( WORD ) ), - cbExtraBytes ) != cbExtraBytes ) - { - SAFE_DELETE( m_pwfx ); - return DXTRACE_ERR( L"mmioRead", E_FAIL ); - } - } - - // Ascend the input file out of the 'fmt ' chunk. - if( 0 != mmioAscend( m_hmmio, &ckIn, 0 ) ) - { - SAFE_DELETE( m_pwfx ); - return DXTRACE_ERR( L"mmioAscend", E_FAIL ); - } - - return S_OK; -} - - -//----------------------------------------------------------------------------- -// Name: CWaveFile::GetSize() -// Desc: Retuns the size of the read access wave file -//----------------------------------------------------------------------------- -DWORD CWaveFile::GetSize() -{ - return m_dwSize; -} - - -//----------------------------------------------------------------------------- -// Name: CWaveFile::ResetFile() -// Desc: Resets the internal m_ck pointer so reading starts from the -// beginning of the file again -//----------------------------------------------------------------------------- -HRESULT CWaveFile::ResetFile() -{ - if( m_bIsReadingFromMemory ) - { - m_pbDataCur = m_pbData; - } - else - { - if( m_hmmio == NULL ) - return CO_E_NOTINITIALIZED; - - if( m_dwFlags == WAVEFILE_READ ) - { - // Seek to the data - if( -1 == mmioSeek( m_hmmio, m_ckRiff.dwDataOffset + sizeof( FOURCC ), - SEEK_SET ) ) - return DXTRACE_ERR( L"mmioSeek", E_FAIL ); - - // Search the input file for the 'data' chunk. - m_ck.ckid = mmioFOURCC( 'd', 'a', 't', 'a' ); - if( 0 != mmioDescend( m_hmmio, &m_ck, &m_ckRiff, MMIO_FINDCHUNK ) ) - return DXTRACE_ERR( L"mmioDescend", E_FAIL ); - } - else - { - // Create the 'data' chunk that holds the waveform samples. - m_ck.ckid = mmioFOURCC( 'd', 'a', 't', 'a' ); - m_ck.cksize = 0; - - if( 0 != mmioCreateChunk( m_hmmio, &m_ck, 0 ) ) - return DXTRACE_ERR( L"mmioCreateChunk", E_FAIL ); - - if( 0 != mmioGetInfo( m_hmmio, &m_mmioinfoOut, 0 ) ) - return DXTRACE_ERR( L"mmioGetInfo", E_FAIL ); - } - } - - return S_OK; -} - - -//----------------------------------------------------------------------------- -// Name: CWaveFile::Read() -// Desc: Reads section of data from a wave file into pBuffer and returns -// how much read in pdwSizeRead, reading not more than dwSizeToRead. -// This uses m_ck to determine where to start reading from. So -// subsequent calls will be continue where the last left off unless -// Reset() is called. -//----------------------------------------------------------------------------- -HRESULT CWaveFile::Read( BYTE* pBuffer, DWORD dwSizeToRead, DWORD* pdwSizeRead ) -{ - if( m_bIsReadingFromMemory ) - { - if( m_pbDataCur == NULL ) - return CO_E_NOTINITIALIZED; - if( pdwSizeRead != NULL ) - *pdwSizeRead = 0; - - if( ( BYTE* )( m_pbDataCur + dwSizeToRead ) > - ( BYTE* )( m_pbData + m_ulDataSize ) ) - { - dwSizeToRead = m_ulDataSize - ( DWORD )( m_pbDataCur - m_pbData ); - } - -#pragma warning( disable: 4616 ) // disable warning about warning number '22104' being out of range -#pragma warning( disable: 22104 ) // disable PREfast warning during static code analysis - CopyMemory( pBuffer, m_pbDataCur, dwSizeToRead ); -#pragma warning( default: 22104 ) -#pragma warning( default: 4616 ) - - if( pdwSizeRead != NULL ) - *pdwSizeRead = dwSizeToRead; - - return S_OK; - } - else - { - MMIOINFO mmioinfoIn; // current status of m_hmmio - - if( m_hmmio == NULL ) - return CO_E_NOTINITIALIZED; - if( pBuffer == NULL || pdwSizeRead == NULL ) - return E_INVALIDARG; - - *pdwSizeRead = 0; - - if( 0 != mmioGetInfo( m_hmmio, &mmioinfoIn, 0 ) ) - return DXTRACE_ERR( L"mmioGetInfo", E_FAIL ); - - UINT cbDataIn = dwSizeToRead; - if( cbDataIn > m_ck.cksize ) - cbDataIn = m_ck.cksize; - - m_ck.cksize -= cbDataIn; - - for( DWORD cT = 0; cT < cbDataIn; cT++ ) - { - // Copy the bytes from the io to the buffer. - if( mmioinfoIn.pchNext == mmioinfoIn.pchEndRead ) - { - if( 0 != mmioAdvance( m_hmmio, &mmioinfoIn, MMIO_READ ) ) - return DXTRACE_ERR( L"mmioAdvance", E_FAIL ); - - if( mmioinfoIn.pchNext == mmioinfoIn.pchEndRead ) - return DXTRACE_ERR( L"mmioinfoIn.pchNext", E_FAIL ); - } - - // Actual copy. - *( ( BYTE* )pBuffer + cT ) = *( ( BYTE* )mmioinfoIn.pchNext ); - mmioinfoIn.pchNext++; - } - - if( 0 != mmioSetInfo( m_hmmio, &mmioinfoIn, 0 ) ) - return DXTRACE_ERR( L"mmioSetInfo", E_FAIL ); - - *pdwSizeRead = cbDataIn; - - return S_OK; - } -} - - -//----------------------------------------------------------------------------- -// Name: CWaveFile::Close() -// Desc: Closes the wave file -//----------------------------------------------------------------------------- -HRESULT CWaveFile::Close() -{ - if( m_dwFlags == WAVEFILE_READ ) - { - if ( m_hmmio != NULL ) - { - mmioClose( m_hmmio, 0 ); - m_hmmio = NULL; - } - SAFE_DELETE_ARRAY( m_pResourceBuffer ); - } - else - { - m_mmioinfoOut.dwFlags |= MMIO_DIRTY; - - if( m_hmmio == NULL ) - return CO_E_NOTINITIALIZED; - - if( 0 != mmioSetInfo( m_hmmio, &m_mmioinfoOut, 0 ) ) - return DXTRACE_ERR( L"mmioSetInfo", E_FAIL ); - - // Ascend the output file out of the 'data' chunk -- this will cause - // the chunk size of the 'data' chunk to be written. - if( 0 != mmioAscend( m_hmmio, &m_ck, 0 ) ) - return DXTRACE_ERR( L"mmioAscend", E_FAIL ); - - // Do this here instead... - if( 0 != mmioAscend( m_hmmio, &m_ckRiff, 0 ) ) - return DXTRACE_ERR( L"mmioAscend", E_FAIL ); - - mmioSeek( m_hmmio, 0, SEEK_SET ); - - if( 0 != ( INT )mmioDescend( m_hmmio, &m_ckRiff, NULL, 0 ) ) - return DXTRACE_ERR( L"mmioDescend", E_FAIL ); - - m_ck.ckid = mmioFOURCC( 'f', 'a', 'c', 't' ); - - if( 0 == mmioDescend( m_hmmio, &m_ck, &m_ckRiff, MMIO_FINDCHUNK ) ) - { - DWORD dwSamples = 0; - mmioWrite( m_hmmio, ( HPSTR )&dwSamples, sizeof( DWORD ) ); - mmioAscend( m_hmmio, &m_ck, 0 ); - } - - // Ascend the output file out of the 'RIFF' chunk -- this will cause - // the chunk size of the 'RIFF' chunk to be written. - if( 0 != mmioAscend( m_hmmio, &m_ckRiff, 0 ) ) - return DXTRACE_ERR( L"mmioAscend", E_FAIL ); - - mmioClose( m_hmmio, 0 ); - m_hmmio = NULL; - } - - return S_OK; -} - - -//----------------------------------------------------------------------------- -// Name: CWaveFile::WriteMMIO() -// Desc: Support function for reading from a multimedia I/O stream -// pwfxDest is the WAVEFORMATEX for this new wave file. -// m_hmmio must be valid before calling. This function uses it to -// update m_ckRiff, and m_ck. -//----------------------------------------------------------------------------- -HRESULT CWaveFile::WriteMMIO( WAVEFORMATEX* pwfxDest ) -{ - DWORD dwFactChunk; // Contains the actual fact chunk. Garbage until WaveCloseWriteFile. - MMCKINFO ckOut1; - - memset( &ckOut1, 0, sizeof(ckOut1) ); - - dwFactChunk = ( DWORD )-1; - - // Create the output file RIFF chunk of form type 'WAVE'. - m_ckRiff.fccType = mmioFOURCC( 'W', 'A', 'V', 'E' ); - m_ckRiff.cksize = 0; - - if( 0 != mmioCreateChunk( m_hmmio, &m_ckRiff, MMIO_CREATERIFF ) ) - return DXTRACE_ERR( L"mmioCreateChunk", E_FAIL ); - - // We are now descended into the 'RIFF' chunk we just created. - // Now create the 'fmt ' chunk. Since we know the size of this chunk, - // specify it in the MMCKINFO structure so MMIO doesn't have to seek - // back and set the chunk size after ascending from the chunk. - m_ck.ckid = mmioFOURCC( 'f', 'm', 't', ' ' ); - m_ck.cksize = sizeof( PCMWAVEFORMAT ); - - if( 0 != mmioCreateChunk( m_hmmio, &m_ck, 0 ) ) - return DXTRACE_ERR( L"mmioCreateChunk", E_FAIL ); - - // Write the PCMWAVEFORMAT structure to the 'fmt ' chunk if its that type. - if( pwfxDest->wFormatTag == WAVE_FORMAT_PCM ) - { - if( mmioWrite( m_hmmio, ( HPSTR )pwfxDest, - sizeof( PCMWAVEFORMAT ) ) != sizeof( PCMWAVEFORMAT ) ) - return DXTRACE_ERR( L"mmioWrite", E_FAIL ); - } - else - { - // Write the variable length size. - if( ( UINT )mmioWrite( m_hmmio, ( HPSTR )pwfxDest, - sizeof( *pwfxDest ) + pwfxDest->cbSize ) != - ( sizeof( *pwfxDest ) + pwfxDest->cbSize ) ) - return DXTRACE_ERR( L"mmioWrite", E_FAIL ); - } - - // Ascend out of the 'fmt ' chunk, back into the 'RIFF' chunk. - if( 0 != mmioAscend( m_hmmio, &m_ck, 0 ) ) - return DXTRACE_ERR( L"mmioAscend", E_FAIL ); - - // Now create the fact chunk, not required for PCM but nice to have. This is filled - // in when the close routine is called. - ckOut1.ckid = mmioFOURCC( 'f', 'a', 'c', 't' ); - ckOut1.cksize = 0; - - if( 0 != mmioCreateChunk( m_hmmio, &ckOut1, 0 ) ) - return DXTRACE_ERR( L"mmioCreateChunk", E_FAIL ); - - if( mmioWrite( m_hmmio, ( HPSTR )&dwFactChunk, sizeof( dwFactChunk ) ) != - sizeof( dwFactChunk ) ) - return DXTRACE_ERR( L"mmioWrite", E_FAIL ); - - // Now ascend out of the fact chunk... - if( 0 != mmioAscend( m_hmmio, &ckOut1, 0 ) ) - return DXTRACE_ERR( L"mmioAscend", E_FAIL ); - - return S_OK; -} - - -//----------------------------------------------------------------------------- -// Name: CWaveFile::Write() -// Desc: Writes data to the open wave file -//----------------------------------------------------------------------------- -HRESULT CWaveFile::Write( UINT nSizeToWrite, BYTE* pbSrcData, UINT* pnSizeWrote ) -{ - UINT cT; - - if( m_bIsReadingFromMemory ) - return E_NOTIMPL; - if( m_hmmio == NULL ) - return CO_E_NOTINITIALIZED; - if( pnSizeWrote == NULL || pbSrcData == NULL ) - return E_INVALIDARG; - - *pnSizeWrote = 0; - - for( cT = 0; cT < nSizeToWrite; cT++ ) - { - if( m_mmioinfoOut.pchNext == m_mmioinfoOut.pchEndWrite ) - { - m_mmioinfoOut.dwFlags |= MMIO_DIRTY; - if( 0 != mmioAdvance( m_hmmio, &m_mmioinfoOut, MMIO_WRITE ) ) - return DXTRACE_ERR( L"mmioAdvance", E_FAIL ); - } - - *( ( BYTE* )m_mmioinfoOut.pchNext ) = *( ( BYTE* )pbSrcData + cT ); - ( BYTE* )m_mmioinfoOut.pchNext++; - - ( *pnSizeWrote )++; - } - - return S_OK; -} diff --git a/FriedLiver/Source/DXUT/Optional/SDKwavefile.h b/FriedLiver/Source/DXUT/Optional/SDKwavefile.h deleted file mode 100644 index 921f1d46..00000000 --- a/FriedLiver/Source/DXUT/Optional/SDKwavefile.h +++ /dev/null @@ -1,59 +0,0 @@ -//----------------------------------------------------------------------------- -// File: WaveFile.h -// -// Copyright (c) Microsoft Corp. All rights reserved. -//----------------------------------------------------------------------------- -#ifndef DXUTWAVEFILE_H -#define DXUTWAVEFILE_H - -//----------------------------------------------------------------------------- -// Typing macros -//----------------------------------------------------------------------------- -#define WAVEFILE_READ 1 -#define WAVEFILE_WRITE 2 - -//----------------------------------------------------------------------------- -// Name: class CWaveFile -// Desc: Encapsulates reading or writing sound data to or from a wave file -//----------------------------------------------------------------------------- -class CWaveFile -{ -public: - WAVEFORMATEX* m_pwfx; // Pointer to WAVEFORMATEX structure - HMMIO m_hmmio; // MM I/O handle for the WAVE - MMCKINFO m_ck; // Multimedia RIFF chunk - MMCKINFO m_ckRiff; // Use in opening a WAVE file - DWORD m_dwSize; // The size of the wave file - MMIOINFO m_mmioinfoOut; - DWORD m_dwFlags; - BOOL m_bIsReadingFromMemory; - BYTE* m_pbData; - BYTE* m_pbDataCur; - ULONG m_ulDataSize; - CHAR* m_pResourceBuffer; - -protected: - HRESULT ReadMMIO(); - HRESULT WriteMMIO( WAVEFORMATEX* pwfxDest ); - -public: - CWaveFile(); - ~CWaveFile(); - - HRESULT Open( LPWSTR strFileName, WAVEFORMATEX* pwfx, DWORD dwFlags ); - HRESULT OpenFromMemory( BYTE* pbData, ULONG ulDataSize, WAVEFORMATEX* pwfx, DWORD dwFlags ); - HRESULT Close(); - - HRESULT Read( BYTE* pBuffer, DWORD dwSizeToRead, DWORD* pdwSizeRead ); - HRESULT Write( UINT nSizeToWrite, BYTE* pbData, UINT* pnSizeWrote ); - - DWORD GetSize(); - HRESULT ResetFile(); - WAVEFORMATEX* GetFormat() - { - return m_pwfx; - }; -}; - - -#endif // DXUTWAVEFILE_H diff --git a/FriedLiver/Source/DXUT/README.md b/FriedLiver/Source/DXUT/README.md new file mode 100644 index 00000000..56fcb5c0 --- /dev/null +++ b/FriedLiver/Source/DXUT/README.md @@ -0,0 +1,49 @@ +![DirectX Logo](https://github.com/Microsoft/DXUT/wiki/Dx_logo.GIF) + +# DXUT for Direct3D 11 + +http://go.microsoft.com/fwlink/?LinkId=320437 + +Copyright (c) Microsoft Corporation. All rights reserved. + +**January 16, 2020** + +DXUT is a "GLUT"-like framework for Direct3D 11.x Win32 desktop applications; primarily +samples, demos, and prototypes. + +This code is designed to build with Visual Studio 2015, Visual Studio 2017, or Visual Studio 2019. It is recommended that you make use of the latest updates (VS 2015 Update 3, VS 2017 15.9 update, etc.). + +These components are designed to work without requiring any content from the legacy DirectX SDK. For details, see [Where is the DirectX SDK?](https://aka.ms/dxsdk). + +## Documentation + +Documentation is available on the [GitHub wiki](https://github.com/Microsoft/DXUT/wiki). + +## Notices + +*This project is 'archived'. It is still available for use for legacy projects, but use of it for new projects is not recommended.* + +All content and source code for this package are subject to the terms of the [MIT License](http://opensource.org/licenses/MIT). + +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. + +## Samples + +* Direct3D Tutorial08 - 10 +* BasicHLSL11, EmptyProject11, SimpleSample11 +* DXUT+DirectXTK Simple Sample + +These are hosted on [GitHub](https://github.com/walbourn/directx-sdk-samples) + +## Disclaimer + +DXUT is being provided as a porting aid for older code that makes use of the legacy DirectX SDK, the deprecated D3DX9/D3DX11 library, and the DXUT11 framework. It is a cleaned up version of the original DXUT11 that will build with the Windows 8.1 / 10 SDK and does not make use of any legacy DirectX SDK or DirectSetup deployed components. + +The DXUT framework is for use in Win32 desktop applications. It not usable for Universal Windows Platform apps, Windows Store apps, +Xbox One apps, or Windows phone. + +This version of DXUT only supports Direct3D 11, and therefore is not compatible with Windows XP or early versions of Windows Vista. + +## Release Notes + +* The VS 2017/2019 projects make use of ``/permissive-`` for improved C++ standard conformance. Use of a Windows 10 SDK prior to the Fall Creators Update (16299) or an Xbox One XDK prior to June 2017 QFE 4 may result in failures due to problems with the system headers. You can work around these by disabling this switch in the project files which is found in the ```` elements, or in some cases adding ``/Zc:twoPhase-`` to the ```` elements. diff --git a/FriedLiver/Source/DepthSensing/CUDARayCastSDF.cpp b/FriedLiver/Source/DepthSensing/CUDARayCastSDF.cpp index c73b3b36..a49e392e 100644 --- a/FriedLiver/Source/DepthSensing/CUDARayCastSDF.cpp +++ b/FriedLiver/Source/DepthSensing/CUDARayCastSDF.cpp @@ -49,7 +49,6 @@ void CUDARayCastSDF::render(const HashDataStruct& hashData, const HashParams& ha cutilSafeCall(cudaDeviceSynchronize()); m_timer.start(); } - renderCS(hashData, m_data, m_params); //convertToCameraSpace(cameraData); diff --git a/FriedLiver/Source/DepthSensing/CUDASceneRepHashSDF.cu b/FriedLiver/Source/DepthSensing/CUDASceneRepHashSDF.cu index 702c9f91..6b431d7d 100644 --- a/FriedLiver/Source/DepthSensing/CUDASceneRepHashSDF.cu +++ b/FriedLiver/Source/DepthSensing/CUDASceneRepHashSDF.cu @@ -10,7 +10,7 @@ #define T_PER_BLOCK 8 texture depthTextureRef; -texture colorTextureRef; +texture colorTextureRef; extern "C" void bindInputDepthColorTextures(const DepthCameraData& depthCameraData, unsigned int width, unsigned int height) { @@ -18,7 +18,7 @@ extern "C" void bindInputDepthColorTextures(const DepthCameraData& depthCameraDa //cutilSafeCall(cudaBindTextureToArray(colorTextureRef, depthCameraData.d_colorArray, depthCameraData.h_colorChannelDesc)); cutilSafeCall(cudaBindTexture2D(0, depthTextureRef, depthCameraData.d_depthData, depthTextureRef.channelDesc, width, height, sizeof(float)*width)); - cutilSafeCall(cudaBindTexture2D(0, colorTextureRef, depthCameraData.d_colorData, colorTextureRef.channelDesc, width, height, sizeof(uchar4)*width)); + cutilSafeCall(cudaBindTexture2D(0, colorTextureRef, depthCameraData.d_colorData, colorTextureRef.channelDesc, width, height, sizeof(float4)*width)); depthTextureRef.filterMode = cudaFilterModePoint; colorTextureRef.filterMode = cudaFilterModePoint; @@ -399,12 +399,12 @@ inline __device__ float4 bilinearFilterColor(const float2& screenPos) { const float beta = (screenPos.y - p00.y)*dir.y; float4 s0 = make_float4(0.0f, 0.0f, 0.0f, 0.0f); float w0 = 0.0f; - if (p00.x >= 0 && p00.x < imageWidth && p00.y >= 0 && p00.y < imageHeight) { uchar4 v00_uc = tex2D(colorTextureRef, p00.x, p00.y); float4 v00 = make_float4(v00_uc.x, v00_uc.y, v00_uc.z, v00_uc.w); if (v00.x != MINF) { s0 += (1.0f - alpha)*v00; w0 += (1.0f - alpha); } } - if (p10.x >= 0 && p10.x < imageWidth && p10.y >= 0 && p10.y < imageHeight) { uchar4 v10_uc = tex2D(colorTextureRef, p10.x, p10.y); float4 v10 = make_float4(v10_uc.x, v10_uc.y, v10_uc.z, v10_uc.w); if (v10.x != MINF) { s0 += alpha *v10; w0 += alpha; } } + if (p00.x >= 0 && p00.x < imageWidth && p00.y >= 0 && p00.y < imageHeight) { float4 v00_uc = tex2D(colorTextureRef, p00.x, p00.y); float4 v00 = make_float4(v00_uc.x, v00_uc.y, v00_uc.z, v00_uc.w); if (v00.x != MINF) { s0 += (1.0f - alpha)*v00; w0 += (1.0f - alpha); } } + if (p10.x >= 0 && p10.x < imageWidth && p10.y >= 0 && p10.y < imageHeight) { float4 v10_uc = tex2D(colorTextureRef, p10.x, p10.y); float4 v10 = make_float4(v10_uc.x, v10_uc.y, v10_uc.z, v10_uc.w); if (v10.x != MINF) { s0 += alpha *v10; w0 += alpha; } } float4 s1 = make_float4(0.0f, 0.0f, 0.0f, 0.0f); float w1 = 0.0f; - if (p01.x >= 0 && p01.x < imageWidth && p01.y >= 0 && p01.y < imageHeight) { uchar4 v01_uc = tex2D(colorTextureRef, p01.x, p01.y); float4 v01 = make_float4(v01_uc.x, v01_uc.y, v01_uc.z, v01_uc.w); if (v01.x != MINF) { s1 += (1.0f - alpha)*v01; w1 += (1.0f - alpha); } } - if (p11.x >= 0 && p11.x < imageWidth && p11.y >= 0 && p11.y < imageHeight) { uchar4 v11_uc = tex2D(colorTextureRef, p11.x, p11.y); float4 v11 = make_float4(v11_uc.x, v11_uc.y, v11_uc.z, v11_uc.w); if (v11.x != MINF) { s1 += alpha *v11; w1 += alpha; } } + if (p01.x >= 0 && p01.x < imageWidth && p01.y >= 0 && p01.y < imageHeight) { float4 v01_uc = tex2D(colorTextureRef, p01.x, p01.y); float4 v01 = make_float4(v01_uc.x, v01_uc.y, v01_uc.z, v01_uc.w); if (v01.x != MINF) { s1 += (1.0f - alpha)*v01; w1 += (1.0f - alpha); } } + if (p11.x >= 0 && p11.x < imageWidth && p11.y >= 0 && p11.y < imageHeight) { float4 v11_uc = tex2D(colorTextureRef, p11.x, p11.y); float4 v11 = make_float4(v11_uc.x, v11_uc.y, v11_uc.z, v11_uc.w); if (v11.x != MINF) { s1 += alpha *v11; w1 += alpha; } } const float4 p0 = s0/w0; const float4 p1 = s1/w1; @@ -438,12 +438,8 @@ __global__ void integrateDepthMapKernel(HashDataStruct hashData, DepthCameraData //float depth = g_InputDepth[screenPos]; float depth = tex2D(depthTextureRef, screenPos.x, screenPos.y); - float4 color = make_float4(MINF, MINF, MINF, MINF); - if (cameraData.d_colorData) { - uchar4 color_uc = tex2D(colorTextureRef, screenPos.x, screenPos.y); - color = make_float4(color_uc.x, color_uc.y, color_uc.z, color_uc.w); - //color = bilinearFilterColor(cameraData.cameraToKinectScreenFloat(pf)); - } + float4 color = tex2D(colorTextureRef, screenPos.x, screenPos.y); + //color = bilinearFilterColor(cameraData.cameraToKinectScreenFloat(pf)); if (color.x != MINF && depth != MINF) { // valid depth and color //if (depth != MINF) { //valid depth @@ -470,9 +466,9 @@ __global__ void integrateDepthMapKernel(HashDataStruct hashData, DepthCameraData curr.weight = weightUpdate; if (cameraData.d_colorData) { - curr.color = make_uchar4(color.x, color.y, color.z, 255); + curr.color = make_float4(color.x, color.y, color.z, color.w); } else { - curr.color = make_uchar4(0,255,0,0); + curr.color = make_float4(0,1.0f,0,0); } uint idx = entry.ptr + i; @@ -481,39 +477,32 @@ __global__ void integrateDepthMapKernel(HashDataStruct hashData, DepthCameraData Voxel newVoxel; float3 oldColor = make_float3(oldVoxel.color.x, oldVoxel.color.y, oldVoxel.color.z); + float oldColorWeight = oldVoxel.color.w; float3 currColor = make_float3(curr.color.x, curr.color.y, curr.color.z); + float currColorWeight = curr.color.w; - if (!deIntegrate) { //integration - //hashData.combineVoxel(hashData.d_SDFBlocks[idx], curr, newVoxel); - float3 res; - if (oldVoxel.weight == 0) res = currColor; - //else res = (currColor + oldColor) / 2; - else res = 0.2f * currColor + 0.8f * oldColor; - //float3 res = (currColor*curr.weight + oldColor*oldVoxel.weight) / (curr.weight + oldVoxel.weight); - res = make_float3(round(res.x), round(res.y), round(res.z)); - res = fmaxf(make_float3(0.0f), fminf(res, make_float3(254.5f))); - //newVoxel.color.x = (uchar)(res.x + 0.5f); newVoxel.color.y = (uchar)(res.y + 0.5f); newVoxel.color.z = (uchar)(res.z + 0.5f); - newVoxel.color = make_uchar4(res.x, res.y, res.z, 255); + if (!deIntegrate) { + float3 res = (oldColor * oldColorWeight + currColor * currColorWeight) / (oldColorWeight + currColorWeight); + float ColorWeight = oldColorWeight + currColorWeight; + newVoxel.color = make_float4(res.x, res.y, res.z, ColorWeight); newVoxel.sdf = (curr.sdf*curr.weight + oldVoxel.sdf*oldVoxel.weight) / (curr.weight + oldVoxel.weight); newVoxel.weight = min((float)c_hashParams.m_integrationWeightMax, curr.weight + oldVoxel.weight); } else { //deintegration - //float3 res = 2 * c0 - c1; - float3 res = (oldColor*oldVoxel.weight - currColor*curr.weight) / (oldVoxel.weight - curr.weight); - res = make_float3(round(res.x), round(res.y), round(res.z)); - res = fmaxf(make_float3(0.0f), fminf(res, make_float3(254.5f))); - //newVoxel.color.x = (uchar)(res.x + 0.5f); newVoxel.color.y = (uchar)(res.y + 0.5f); newVoxel.color.z = (uchar)(res.z + 0.5f); - newVoxel.color = make_uchar4(res.x, res.y, res.z, 255); + float3 res = (oldColor * oldColorWeight - currColor * currColorWeight) / (oldColorWeight - currColorWeight); + float ColorWeight = oldColorWeight - currColorWeight; + newVoxel.color = make_float4(res.x, res.y, res.z, ColorWeight); newVoxel.sdf = (oldVoxel.sdf*oldVoxel.weight - curr.sdf*curr.weight) / (oldVoxel.weight - curr.weight); newVoxel.weight = max(0.0f, oldVoxel.weight - curr.weight); if (newVoxel.weight <= 0.001f) { newVoxel.sdf = 0.0f; - newVoxel.color = make_uchar4(0,0,0,0); + newVoxel.color = make_float4(0,0,0,0); newVoxel.weight = 0.0f; } } hashData.d_SDFBlocks[idx] = newVoxel; + //printf("%f\n", newVoxel.color.x); } } } diff --git a/FriedLiver/Source/DepthSensing/DX11QuadDrawer.cpp b/FriedLiver/Source/DepthSensing/DX11QuadDrawer.cpp index c9d3320e..73134c5c 100644 --- a/FriedLiver/Source/DepthSensing/DX11QuadDrawer.cpp +++ b/FriedLiver/Source/DepthSensing/DX11QuadDrawer.cpp @@ -286,7 +286,7 @@ HRESULT DX11QuadDrawer::RenderQuadDynamicUCHAR4(ID3D11Device* pd3dDevice, ID3D11 } -HRESULT DX11QuadDrawer::RenderQuadDynamic(ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dDeviceContext, float* d_data, unsigned int nChannels, unsigned int width, unsigned int height, float scale /*= 1.0f */, DirectX::XMFLOAT2 Pow2Ratios /*= DirectX::XMFLOAT2(1.0f, 1.0f)*/, ID3D11PixelShader* pixelShader /*= NULL*/) +HRESULT DX11QuadDrawer::RenderQuadDynamic(ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dDeviceContext, const float* d_data, unsigned int nChannels, unsigned int width, unsigned int height, float scale /*= 1.0f */, DirectX::XMFLOAT2 Pow2Ratios /*= DirectX::XMFLOAT2(1.0f, 1.0f)*/, ID3D11PixelShader* pixelShader /*= NULL*/) { HRESULT hr = S_OK; @@ -329,7 +329,7 @@ HRESULT DX11QuadDrawer::RenderQuadDynamic(ID3D11Device* pd3dDevice, ID3D11Device return hr; } -void DX11QuadDrawer::RenderQuadHelper(ID3D11DeviceContext* pd3dDeviceContext, float* d_data, cudaGraphicsResource* pCuda, ID3D11ShaderResourceView* pTmpTextureSRV, unsigned int size, float scale, DirectX::XMFLOAT2 Pow2Ratios , ID3D11PixelShader* pixelShader) +void DX11QuadDrawer::RenderQuadHelper(ID3D11DeviceContext* pd3dDeviceContext, const float* d_data, cudaGraphicsResource* pCuda, ID3D11ShaderResourceView* pTmpTextureSRV, unsigned int size, float scale, DirectX::XMFLOAT2 Pow2Ratios , ID3D11PixelShader* pixelShader) { cudaArray* in_array; cutilSafeCall(cudaGraphicsMapResources(1, &pCuda, 0)); // Map DX texture to Cuda @@ -339,7 +339,7 @@ void DX11QuadDrawer::RenderQuadHelper(ID3D11DeviceContext* pd3dDeviceContext, fl RenderQuad(pd3dDeviceContext, pTmpTextureSRV, scale, Pow2Ratios, pixelShader); } -void DX11QuadDrawer::RenderQuad(ID3D11DeviceContext* pd3dDeviceContext, float* d_data, unsigned int nChannels, unsigned int width, unsigned int height, float scale /*= 1.0f */, DirectX::XMFLOAT2 Pow2Ratios /*= float2(1.0f, 1.0f)*/, ID3D11PixelShader* pixelShader /*= NULL*/) +void DX11QuadDrawer::RenderQuad(ID3D11DeviceContext* pd3dDeviceContext, const float* d_data, unsigned int nChannels, unsigned int width, unsigned int height, float scale /*= 1.0f */, DirectX::XMFLOAT2 Pow2Ratios /*= float2(1.0f, 1.0f)*/, ID3D11PixelShader* pixelShader /*= NULL*/) { if(nChannels == 4) { diff --git a/FriedLiver/Source/DepthSensing/DX11QuadDrawer.h b/FriedLiver/Source/DepthSensing/DX11QuadDrawer.h index 5e46845a..cc57154a 100644 --- a/FriedLiver/Source/DepthSensing/DX11QuadDrawer.h +++ b/FriedLiver/Source/DepthSensing/DX11QuadDrawer.h @@ -29,15 +29,15 @@ class DX11QuadDrawer static HRESULT RenderQuadDynamicDEPTHasHSV(ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dDeviceContext, const float* d_data, float minDepth, float maxDepth, unsigned int width, unsigned int height, float scale = 1.0f, DirectX::XMFLOAT2 Pow2Ratios = DirectX::XMFLOAT2(1.0f, 1.0f), ID3D11PixelShader* pixelShader = NULL); static HRESULT RenderQuadDynamicUCHAR4(ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dDeviceContext, const uchar4* d_data, unsigned int width, unsigned int height, float scale = 1.0f, DirectX::XMFLOAT2 Pow2Ratios = DirectX::XMFLOAT2(1.0f, 1.0f), ID3D11PixelShader* pixelShader = NULL); - static HRESULT RenderQuadDynamic(ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dDeviceContext, float* d_data, unsigned int nChannels, unsigned int width, unsigned int height, float scale = 1.0f, DirectX::XMFLOAT2 Pow2Ratios = DirectX::XMFLOAT2(1.0f, 1.0f), ID3D11PixelShader* pixelShader = NULL); + static HRESULT RenderQuadDynamic(ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dDeviceContext, const float* d_data, unsigned int nChannels, unsigned int width, unsigned int height, float scale = 1.0f, DirectX::XMFLOAT2 Pow2Ratios = DirectX::XMFLOAT2(1.0f, 1.0f), ID3D11PixelShader* pixelShader = NULL); - static void RenderQuad(ID3D11DeviceContext* pd3dDeviceContext, float* d_data, unsigned int nChannels, unsigned int width, unsigned int height, float scale = 1.0f , DirectX::XMFLOAT2 Pow2Ratios = DirectX::XMFLOAT2(1.0f, 1.0f), ID3D11PixelShader* pixelShader = NULL ); + static void RenderQuad(ID3D11DeviceContext* pd3dDeviceContext, const float* d_data, unsigned int nChannels, unsigned int width, unsigned int height, float scale = 1.0f , DirectX::XMFLOAT2 Pow2Ratios = DirectX::XMFLOAT2(1.0f, 1.0f), ID3D11PixelShader* pixelShader = NULL ); static void RenderQuad(ID3D11DeviceContext* pd3dDeviceContext, ID3D11PixelShader* pixelShader, ID3D11ShaderResourceView** srvs, UINT numShaderResourceViews, DirectX::XMFLOAT2 Pow2Ratios = DirectX::XMFLOAT2(1.0f, 1.0f)); static void RenderQuad(ID3D11DeviceContext* pd3dDeviceContext, ID3D11ShaderResourceView* srv, float scale = 1.0f, DirectX::XMFLOAT2 Pow2Ratios = DirectX::XMFLOAT2(1.0f, 1.0f), ID3D11PixelShader* pixelShader = NULL); private: - static void RenderQuadHelper(ID3D11DeviceContext* pd3dDeviceContext, float* d_data, cudaGraphicsResource* pCuda, ID3D11ShaderResourceView* pTmpTextureSRV, unsigned int size, float scale, DirectX::XMFLOAT2 Pow2Ratios , ID3D11PixelShader* pixelShader); + static void RenderQuadHelper(ID3D11DeviceContext* pd3dDeviceContext, const float* d_data, cudaGraphicsResource* pCuda, ID3D11ShaderResourceView* pTmpTextureSRV, unsigned int size, float scale, DirectX::XMFLOAT2 Pow2Ratios , ID3D11PixelShader* pixelShader); static ID3D11InputLayout* s_VertexLayout; static ID3D11Buffer* s_VertexBuffer; diff --git a/FriedLiver/Source/DepthSensing/DepthCameraUtil.h b/FriedLiver/Source/DepthSensing/DepthCameraUtil.h index 504e3a54..aa5d6c97 100644 --- a/FriedLiver/Source/DepthSensing/DepthCameraUtil.h +++ b/FriedLiver/Source/DepthSensing/DepthCameraUtil.h @@ -26,7 +26,7 @@ struct DepthCameraData { d_colorData = NULL; } - DepthCameraData(const float* depthData, const uchar4* colorData) { + DepthCameraData(const float* depthData, const float4* colorData) { d_depthData = depthData; d_colorData = colorData; } @@ -144,7 +144,7 @@ struct DepthCameraData { } const float* d_depthData; //depth data of the current frame (in screen space):: TODO data allocation lives in RGBD Sensor - const uchar4* d_colorData; //color data of the current frame (in screen space):: TODO data allocation lives in RGBD Sensor + const float4* d_colorData; //color data of the current frame (in screen space):: TODO data allocation lives in RGBD Sensor //// cuda arrays for texture access //cudaArray* d_depthArray; diff --git a/FriedLiver/Source/DepthSensing/DepthSensing.cpp b/FriedLiver/Source/DepthSensing/DepthSensing.cpp index eccf4554..7b28a333 100644 --- a/FriedLiver/Source/DepthSensing/DepthSensing.cpp +++ b/FriedLiver/Source/DepthSensing/DepthSensing.cpp @@ -298,7 +298,7 @@ cs.m_trajectory.resize(cs.m_DepthNumFrames); tm->lockUpdateTransforms(); for (unsigned int i = 0; i < numFrames; i++) { const float* depth = g_CudaImageManager->getIntegrateFrame(i).getDepthFrameCPU(); -const uchar4* color = g_CudaImageManager->getIntegrateFrame(i).getColorFrameCPU(); +const float4* color = g_CudaImageManager->getIntegrateFrame(i).getColorFrameCPU(); cs.m_DepthImages[i] = (float*)depth; // this non-const cast is hacky cs.m_ColorImages[i] = (vec4uc*)color; // this non-const cast is hacky @@ -836,8 +836,8 @@ void visualizeFrame(ID3D11DeviceContext* pd3dImmediateContext, ID3D11Device* pd3 } else if (GlobalAppState::get().s_RenderMode == 3) { //color input - const uchar4* d_color = g_CudaImageManager->getLastIntegrateFrame().getColorFrameGPU(); - DX11QuadDrawer::RenderQuadDynamicUCHAR4(DXUTGetD3D11Device(), pd3dImmediateContext, d_color, g_CudaImageManager->getIntegrationWidth(), g_CudaImageManager->getIntegrationHeight()); + const float4* d_color = g_CudaImageManager->getLastIntegrateFrame().getColorFrameGPU(); + DX11QuadDrawer::RenderQuadDynamic(DXUTGetD3D11Device(), pd3dImmediateContext, (const float*)d_color, 4, g_CudaImageManager->getIntegrationWidth(), g_CudaImageManager->getIntegrationHeight()); } else if (GlobalAppState::get().s_RenderMode == 4) { const float* d_depth = g_CudaImageManager->getLastIntegrateFrame().getDepthFrameGPU(); diff --git a/FriedLiver/Source/DepthSensing/MarchingCubesSDFUtil.h b/FriedLiver/Source/DepthSensing/MarchingCubesSDFUtil.h index de98eae6..a63bed14 100644 --- a/FriedLiver/Source/DepthSensing/MarchingCubesSDFUtil.h +++ b/FriedLiver/Source/DepthSensing/MarchingCubesSDFUtil.h @@ -130,14 +130,14 @@ struct MarchingCubesData { const float P = hashParams.m_virtualVoxelSize/2.0f; const float M = -P; - float3 p000 = worldPos+make_float3(M, M, M); float dist000; uchar3 color000; bool valid000 = rayCastData.trilinearInterpolationSimpleFastFast(hashData, p000, dist000, color000); - float3 p100 = worldPos+make_float3(P, M, M); float dist100; uchar3 color100; bool valid100 = rayCastData.trilinearInterpolationSimpleFastFast(hashData, p100, dist100, color100); - float3 p010 = worldPos+make_float3(M, P, M); float dist010; uchar3 color010; bool valid010 = rayCastData.trilinearInterpolationSimpleFastFast(hashData, p010, dist010, color010); - float3 p001 = worldPos+make_float3(M, M, P); float dist001; uchar3 color001; bool valid001 = rayCastData.trilinearInterpolationSimpleFastFast(hashData, p001, dist001, color001); - float3 p110 = worldPos+make_float3(P, P, M); float dist110; uchar3 color110; bool valid110 = rayCastData.trilinearInterpolationSimpleFastFast(hashData, p110, dist110, color110); - float3 p011 = worldPos+make_float3(M, P, P); float dist011; uchar3 color011; bool valid011 = rayCastData.trilinearInterpolationSimpleFastFast(hashData, p011, dist011, color011); - float3 p101 = worldPos+make_float3(P, M, P); float dist101; uchar3 color101; bool valid101 = rayCastData.trilinearInterpolationSimpleFastFast(hashData, p101, dist101, color101); - float3 p111 = worldPos+make_float3(P, P, P); float dist111; uchar3 color111; bool valid111 = rayCastData.trilinearInterpolationSimpleFastFast(hashData, p111, dist111, color111); + float3 p000 = worldPos+make_float3(M, M, M); float dist000; float3 color000; bool valid000 = rayCastData.trilinearInterpolationSimpleFastFast(hashData, p000, dist000, color000); + float3 p100 = worldPos+make_float3(P, M, M); float dist100; float3 color100; bool valid100 = rayCastData.trilinearInterpolationSimpleFastFast(hashData, p100, dist100, color100); + float3 p010 = worldPos+make_float3(M, P, M); float dist010; float3 color010; bool valid010 = rayCastData.trilinearInterpolationSimpleFastFast(hashData, p010, dist010, color010); + float3 p001 = worldPos+make_float3(M, M, P); float dist001; float3 color001; bool valid001 = rayCastData.trilinearInterpolationSimpleFastFast(hashData, p001, dist001, color001); + float3 p110 = worldPos+make_float3(P, P, M); float dist110; float3 color110; bool valid110 = rayCastData.trilinearInterpolationSimpleFastFast(hashData, p110, dist110, color110); + float3 p011 = worldPos+make_float3(M, P, P); float dist011; float3 color011; bool valid011 = rayCastData.trilinearInterpolationSimpleFastFast(hashData, p011, dist011, color011); + float3 p101 = worldPos+make_float3(P, M, P); float dist101; float3 color101; bool valid101 = rayCastData.trilinearInterpolationSimpleFastFast(hashData, p101, dist101, color101); + float3 p111 = worldPos+make_float3(P, P, P); float dist111; float3 color111; bool valid111 = rayCastData.trilinearInterpolationSimpleFastFast(hashData, p111, dist111, color111); if(!valid000 || !valid100 || !valid010 || !valid001 || !valid110 || !valid011 || !valid101 || !valid111) return; @@ -203,10 +203,10 @@ struct MarchingCubesData { } __device__ - Vertex vertexInterp(float isolevel, const float3& p1, const float3& p2, float d1, float d2, const uchar4& c1, const uchar4& c2) const + Vertex vertexInterp(float isolevel, const float3& p1, const float3& p2, float d1, float d2, const float4& c1, const float4& c2) const { - Vertex r1; r1.p = p1; r1.c = make_float3(c1.x, c1.y, c1.z) / 255.f; - Vertex r2; r2.p = p2; r2.c = make_float3(c2.x, c2.y, c2.z) / 255.f; + Vertex r1; r1.p = p1; r1.c = make_float3(c1.x, c1.y, c1.z); + Vertex r2; r2.p = p2; r2.c = make_float3(c2.x, c2.y, c2.z); if(abs(isolevel-d1) < 0.00001f) return r1; if(abs(isolevel-d2) < 0.00001f) return r2; @@ -219,9 +219,9 @@ struct MarchingCubesData { res.p.y = p1.y + mu * (p2.y - p1.y); res.p.z = p1.z + mu * (p2.z - p1.z); - res.c.x = (float)(c1.x + mu * (float)(c2.x - c1.x)) / 255.f; // Color - res.c.y = (float)(c1.y + mu * (float)(c2.y - c1.y)) / 255.f; - res.c.z = (float)(c1.z + mu * (float)(c2.z - c1.z)) / 255.f; + res.c.x = (float)(c1.x + mu * (float)(c2.x - c1.x)); // Color + res.c.y = (float)(c1.y + mu * (float)(c2.y - c1.y)); + res.c.z = (float)(c1.z + mu * (float)(c2.z - c1.z)); return res; } diff --git a/FriedLiver/Source/DepthSensing/RayCastSDFUtil.h b/FriedLiver/Source/DepthSensing/RayCastSDFUtil.h index 20c18eed..2f430338 100644 --- a/FriedLiver/Source/DepthSensing/RayCastSDFUtil.h +++ b/FriedLiver/Source/DepthSensing/RayCastSDFUtil.h @@ -94,7 +94,7 @@ struct RayCastData { } __device__ - bool trilinearInterpolationSimpleFastFast(const HashDataStruct& hash, const float3& pos, float& dist, uchar3& color) const { + bool trilinearInterpolationSimpleFastFast(const HashDataStruct& hash, const float3& pos, float& dist, float3& color) const { const float oSet = c_hashParams.m_virtualVoxelSize; const float3 posDual = pos-make_float3(oSet/2.0f, oSet/2.0f, oSet/2.0f); float3 weight = frac(hash.worldToVirtualVoxelPosFloat(pos)); @@ -109,13 +109,13 @@ struct RayCastData { v = hash.getVoxel(posDual+make_float3(0.0f, oSet, oSet)); if(v.weight == 0) return false; vColor = make_float3(v.color.x, v.color.y, v.color.z); dist+= (1.0f-weight.x)* weight.y * weight.z *v.sdf; colorFloat+= (1.0f-weight.x)* weight.y * weight.z *vColor; v = hash.getVoxel(posDual+make_float3(oSet, 0.0f, oSet)); if(v.weight == 0) return false; vColor = make_float3(v.color.x, v.color.y, v.color.z); dist+= weight.x *(1.0f-weight.y)* weight.z *v.sdf; colorFloat+= weight.x *(1.0f-weight.y)* weight.z *vColor; v = hash.getVoxel(posDual+make_float3(oSet, oSet, oSet)); if(v.weight == 0) return false; vColor = make_float3(v.color.x, v.color.y, v.color.z); dist+= weight.x * weight.y * weight.z *v.sdf; colorFloat+= weight.x * weight.y * weight.z *vColor; - - color = make_uchar3(colorFloat.x, colorFloat.y, colorFloat.z);//v.color; + //printf("%f\n", v.color.y); + color = make_float3(colorFloat.x, colorFloat.y, colorFloat.z);//v.color; return true; } //__device__ - //bool trilinearInterpolationSimpleFastFast(const HashData& hash, const float3& pos, float& dist, uchar3& color) const { + //bool trilinearInterpolationSimpleFastFast(const HashData& hash, const float3& pos, float& dist, float3& color) const { // const float oSet = c_hashParams.m_virtualVoxelSize; // const float3 posDual = pos-make_float3(oSet/2.0f, oSet/2.0f, oSet/2.0f); // float3 weight = frac(hash.worldToVirtualVoxelPosFloat(pos)); @@ -146,7 +146,7 @@ struct RayCastData { // d0 near, d1 far __device__ - bool findIntersectionBisection(const HashDataStruct& hash, const float3& worldCamPos, const float3& worldDir, float d0, float r0, float d1, float r1, float& alpha, uchar3& color) const + bool findIntersectionBisection(const HashDataStruct& hash, const float3& worldCamPos, const float3& worldDir, float d0, float r0, float d1, float r1, float& alpha, float3& color) const { float a = r0; float aDist = d0; float b = r1; float bDist = d1; @@ -176,13 +176,13 @@ struct RayCastData { const float voxelSize = c_hashParams.m_virtualVoxelSize; float3 offset = make_float3(voxelSize, voxelSize, voxelSize); - float distp00; uchar3 colorp00; trilinearInterpolationSimpleFastFast(hash, pos-make_float3(0.5f*offset.x, 0.0f, 0.0f), distp00, colorp00); - float dist0p0; uchar3 color0p0; trilinearInterpolationSimpleFastFast(hash, pos-make_float3(0.0f, 0.5f*offset.y, 0.0f), dist0p0, color0p0); - float dist00p; uchar3 color00p; trilinearInterpolationSimpleFastFast(hash, pos-make_float3(0.0f, 0.0f, 0.5f*offset.z), dist00p, color00p); + float distp00; float3 colorp00; trilinearInterpolationSimpleFastFast(hash, pos-make_float3(0.5f*offset.x, 0.0f, 0.0f), distp00, colorp00); + float dist0p0; float3 color0p0; trilinearInterpolationSimpleFastFast(hash, pos-make_float3(0.0f, 0.5f*offset.y, 0.0f), dist0p0, color0p0); + float dist00p; float3 color00p; trilinearInterpolationSimpleFastFast(hash, pos-make_float3(0.0f, 0.0f, 0.5f*offset.z), dist00p, color00p); - float dist100; uchar3 color100; trilinearInterpolationSimpleFastFast(hash, pos+make_float3(0.5f*offset.x, 0.0f, 0.0f), dist100, color100); - float dist010; uchar3 color010; trilinearInterpolationSimpleFastFast(hash, pos+make_float3(0.0f, 0.5f*offset.y, 0.0f), dist010, color010); - float dist001; uchar3 color001; trilinearInterpolationSimpleFastFast(hash, pos+make_float3(0.0f, 0.0f, 0.5f*offset.z), dist001, color001); + float dist100; float3 color100; trilinearInterpolationSimpleFastFast(hash, pos+make_float3(0.5f*offset.x, 0.0f, 0.0f), dist100, color100); + float dist010; float3 color010; trilinearInterpolationSimpleFastFast(hash, pos+make_float3(0.0f, 0.5f*offset.y, 0.0f), dist010, color010); + float dist001; float3 color001; trilinearInterpolationSimpleFastFast(hash, pos+make_float3(0.0f, 0.0f, 0.5f*offset.z), dist001, color001); float3 grad = make_float3((distp00-dist100)/offset.x, (dist0p0-dist010)/offset.y, (dist00p-dist001)/offset.z); @@ -239,7 +239,7 @@ struct RayCastData { while(rayCurrent < rayEnd) { float3 currentPosWorld = worldCamPos+rayCurrent*worldDir; - float dist; uchar3 color; + float dist; float3 color; if(trilinearInterpolationSimpleFastFast(hash, currentPosWorld, dist, color)) { @@ -248,7 +248,7 @@ struct RayCastData { { float alpha; // = findIntersectionLinear(lastSample.alpha, rayCurrent, lastSample.sdf, dist); - uchar3 color2; + float3 color2; bool b = findIntersectionBisection(hash, worldCamPos, worldDir, lastSample.sdf, lastSample.alpha, dist, rayCurrent, alpha, color2); float3 currentIso = worldCamPos+alpha*worldDir; @@ -260,7 +260,7 @@ struct RayCastData { d_depth[dTid.y*rayCastParams.m_width+dTid.x] = depth; d_depth4[dTid.y*rayCastParams.m_width+dTid.x] = make_float4(depthToCamera(dTid.x, dTid.y, depth), 1.0f); - d_colors[dTid.y*rayCastParams.m_width+dTid.x] = make_float4(color2.x/255.f, color2.y/255.f, color2.z/255.f, 1.0f); + d_colors[dTid.y*rayCastParams.m_width+dTid.x] = make_float4(color2.x, color2.y, color2.z, 1.0f); if(rayCastParams.m_useGradients) { diff --git a/FriedLiver/Source/DepthSensing/VoxelUtilHashSDF.h b/FriedLiver/Source/DepthSensing/VoxelUtilHashSDF.h index ca94f130..32b12f86 100644 --- a/FriedLiver/Source/DepthSensing/VoxelUtilHashSDF.h +++ b/FriedLiver/Source/DepthSensing/VoxelUtilHashSDF.h @@ -77,13 +77,13 @@ struct HashEntry struct Voxel { float sdf; //signed distance function float weight; //accumulated sdf weight - uchar4 color; //color + float4 color; //color //unsigned short sdf; //unsigned short weight; //uchar4 color; - __device__ void operator=(const struct Voxel& v) { + /*__device__ void operator=(const struct Voxel& v) { ((int*)this)[0] = ((const int*)&v)[0]; ((int*)this)[1] = ((const int*)&v)[1]; ((int*)this)[2] = ((const int*)&v)[2]; @@ -93,7 +93,7 @@ struct Voxel { //this needs align, which unfortunately is problematic as __align__(16) would require more memory... //((long long*)this)[0] = ((const long long*)&v)[0]; //8 bytes //((int*)this)[2] = ((const int*)&v)[2]; //4 bytes - } + }*/ }; @@ -393,7 +393,7 @@ struct HashDataStruct { __device__ void deleteVoxel(Voxel& v) const { - v.color = make_uchar4(0,0,0,0); + v.color = make_float4(0,0,0,0); v.weight = 0.0f; v.sdf = 0.0f; } diff --git a/FriedLiver/Source/GlobalAppState.h b/FriedLiver/Source/GlobalAppState.h index d3f9f902..544a1bcb 100644 --- a/FriedLiver/Source/GlobalAppState.h +++ b/FriedLiver/Source/GlobalAppState.h @@ -2,7 +2,7 @@ //#define KINECT //#define KINECT_ONE -//#define OPEN_NI +#define OPEN_NI #define BINARY_DUMP_READER //#define INTEL_SENSOR //#define REAL_SENSE @@ -93,6 +93,7 @@ X(bool, s_recordData) \ X(bool, s_recordCompression) \ X(std::string, s_recordDataFile) \ + X(std::string, s_oniFile) \ X(bool, s_reconstructionEnabled) \ X(bool, s_generateVideo) \ X(std::string, s_generateVideoDir) \ diff --git a/FriedLiver/Source/OnlineBundler.cpp b/FriedLiver/Source/OnlineBundler.cpp index ec1b9698..bbf919f5 100644 --- a/FriedLiver/Source/OnlineBundler.cpp +++ b/FriedLiver/Source/OnlineBundler.cpp @@ -108,7 +108,6 @@ void OnlineBundler::getCurrentFrame() m_cudaImageManager->copyToBundling(m_input.d_inputDepthRaw, m_input.d_inputDepthFilt, m_input.d_inputColor); CUDAImageUtil::resampleToIntensity(m_input.d_intensitySIFT, m_input.m_widthSIFT, m_input.m_heightSIFT, m_input.d_inputColor, m_input.m_inputColorWidth, m_input.m_inputColorHeight); - if (m_input.m_bFilterIntensity) { CUDAImageUtil::gaussFilterIntensity(m_input.d_intensityFilterHelper, m_input.d_intensitySIFT, m_input.m_intensitySigmaD, m_input.m_widthSIFT, m_input.m_heightSIFT); std::swap(m_input.d_intensityFilterHelper, m_input.d_intensitySIFT); diff --git a/FriedLiver/Source/OnlineBundlerHelper.h b/FriedLiver/Source/OnlineBundlerHelper.h index 939b8c26..cd09e4b0 100644 --- a/FriedLiver/Source/OnlineBundlerHelper.h +++ b/FriedLiver/Source/OnlineBundlerHelper.h @@ -13,7 +13,7 @@ struct BundlerInputData { mat4f m_SIFTIntrinsicsInv; //data float* d_inputDepthFilt, *d_inputDepthRaw; - uchar4* d_inputColor; + float4* d_inputColor; float* d_intensitySIFT; float* d_intensityFilterHelper; //TODO check if used //filtering //TODO option for depth filter @@ -40,7 +40,7 @@ struct BundlerInputData { MLIB_CUDA_SAFE_CALL(cudaMalloc(&d_inputDepthFilt, sizeof(float)*m_inputDepthWidth*m_inputDepthHeight)); MLIB_CUDA_SAFE_CALL(cudaMalloc(&d_inputDepthRaw, sizeof(float)*m_inputDepthWidth*m_inputDepthHeight)); MLIB_CUDA_SAFE_CALL(cudaMalloc(&d_intensityFilterHelper, sizeof(float)*m_widthSIFT*m_heightSIFT)); - MLIB_CUDA_SAFE_CALL(cudaMalloc(&d_inputColor, sizeof(uchar4)*m_inputColorWidth*m_inputColorHeight)); + MLIB_CUDA_SAFE_CALL(cudaMalloc(&d_inputColor, sizeof(float4)*m_inputColorWidth*m_inputColorHeight)); MLIB_CUDA_SAFE_CALL(cudaMalloc(&d_intensitySIFT, sizeof(float)*m_widthSIFT*m_heightSIFT)); m_SIFTIntrinsics = sensor->getColorIntrinsics(); diff --git a/FriedLiver/Source/PrimeSenseSensor - Copy.cpp b/FriedLiver/Source/PrimeSenseSensor - Copy.cpp new file mode 100644 index 00000000..2a141b3a --- /dev/null +++ b/FriedLiver/Source/PrimeSenseSensor - Copy.cpp @@ -0,0 +1,280 @@ + +#include "stdafx.h" + +#include "PrimeSenseSensor.h" + +//Only working with OpenNI 2 SDK (which wants to run on Win8) +#ifdef OPEN_NI + +PrimeSenseSensor::PrimeSenseSensor() +{ + m_bDepthReceived = false; + m_bColorReceived = false; + + m_bDepthImageIsUpdated = false; + m_bDepthImageCameraIsUpdated = false; + m_bNormalImageCameraIsUpdated = false; +} + +PrimeSenseSensor::~PrimeSenseSensor() +{ + if (m_streams != NULL) + { + delete[] m_streams; + } + + m_depthStream.stop(); + m_colorStream.stop(); + m_depthStream.destroy(); + m_colorStream.destroy(); + m_device.close(); + openni::OpenNI::shutdown(); + + /*openni::Recorder recorder; + recorder.create("test.oni"); + + recorder.attach(m_depthStream, false); + recorder.attach(m_colorStream, false); + + recorder.start(); + recorder.stop(); + + recorder.destroy();*/ +} + +void PrimeSenseSensor::createFirstConnected() +{ + openni::Status rc = openni::STATUS_OK; + const char* deviceURI = openni::ANY_DEVICE; + + rc = openni::OpenNI::initialize(); + + std::cout << "After initialization: " << openni::OpenNI::getExtendedError() << std::endl; + + // Create Device + rc = m_device.open("../data/6.oni");//m_device.open(deviceURI); + record_exposure = fopen("../data/6_frame_exp.txt", "r"); + FILE *record_curve = fopen("../data/6_curve.txt", "r"); + for (int i = 0; i < 256; i++) { + fscanf(record_curve, "%f", curve + i); + curve[i] = exp(curve[i]); + } + fclose(record_curve); + if (rc != openni::STATUS_OK) + { + std::cout << "Device open failed: " << openni::OpenNI::getExtendedError() << std::endl; + openni::OpenNI::shutdown(); + return; + } + + openni::PlaybackControl* pc = m_device.getPlaybackControl(); + pc->setSpeed(-1.0); + pc->setRepeatEnabled(false); + // Create Depth Stream + rc = m_depthStream.create(m_device, openni::SENSOR_DEPTH); + if (rc == openni::STATUS_OK) + { + rc = m_depthStream.start(); + if (rc != openni::STATUS_OK) + { + std::cout << "Couldn't start depth stream: " << openni::OpenNI::getExtendedError() << std::endl; + m_depthStream.destroy(); + } + } + else + { + std::cout << "Couldn't find depth stream: " << openni::OpenNI::getExtendedError() << std::endl; + } + + // Create Color Stream + rc = m_colorStream.create(m_device, openni::SENSOR_COLOR); + if (rc == openni::STATUS_OK) + { + rc = m_colorStream.start(); + if (rc != openni::STATUS_OK) + { + std::cout << "Couldn't start color stream: " << openni::OpenNI::getExtendedError() << " Return code: " << rc << std::endl; + m_colorStream.destroy(); + } + } + else + { + std::cout << "Couldn't find color stream: " << openni::OpenNI::getExtendedError() << std::endl; + } + + // Check Streams + if (!m_depthStream.isValid() || !m_colorStream.isValid()) + { + std::cout << "No valid streams. Exiting" << std::endl; + openni::OpenNI::shutdown(); + return; + } + + m_colorStream.setMirroringEnabled(false); + m_depthStream.setMirroringEnabled(false); + openni::CameraSettings* cs = m_colorStream.getCameraSettings(); + + //cs->setAutoWhiteBalanceEnabled(false); + //cs->setAutoExposureEnabled(false); + //cs->setGain(1); + //cs->setExposure(10); + if (cs) + { + std::cout << "getGain: " << cs->getGain() << std::endl; + std::cout << "getExposure: " << cs->getExposure() << std::endl; + std::cout << "getAutoExposureEnabled: " << cs->getAutoExposureEnabled() << std::endl; + std::cout << "getAutoWhiteBalanceEnabled: " << cs->getAutoWhiteBalanceEnabled() << std::endl; + } + + // Get Dimensions + m_depthVideoMode = m_depthStream.getVideoMode(); + m_colorVideoMode = m_colorStream.getVideoMode(); + + int depthWidth = m_depthVideoMode.getResolutionX(); + int depthHeight = m_depthVideoMode.getResolutionY(); + int colorWidth = m_colorVideoMode.getResolutionX(); + int colorHeight = m_colorVideoMode.getResolutionY(); + + RGBDSensor::init(depthWidth, depthHeight, colorWidth, colorHeight, 1); + + m_streams = new openni::VideoStream*[2]; + m_streams[0] = &m_depthStream; + m_streams[1] = &m_colorStream; + + if (rc != openni::STATUS_OK) + { + openni::OpenNI::shutdown(); + return; + } + + m_device.setImageRegistrationMode(openni::IMAGE_REGISTRATION_DEPTH_TO_COLOR); + + float focalLengthX = (depthWidth / 2.0f) / tan(m_depthStream.getHorizontalFieldOfView() / 2.0f); + float focalLengthY = (depthHeight / 2.0f) / tan(m_depthStream.getVerticalFieldOfView() / 2.0f); + initializeDepthIntrinsics(focalLengthX, focalLengthY, depthWidth / 2.0f, depthHeight / 2.0f); + + focalLengthX = (colorWidth / 2.0f) / tan(m_colorStream.getHorizontalFieldOfView() / 2.0f); + focalLengthY = (colorHeight / 2.0f) / tan(m_colorStream.getVerticalFieldOfView() / 2.0f); + initializeColorIntrinsics(focalLengthX, focalLengthY, colorWidth / 2.0f, colorHeight / 2.0f); + + initializeColorExtrinsics(mat4f::identity()); + + mat4f depthExtrinsics = mat4f::identity(); + depthExtrinsics(0, 0) = 9.9991741106823473e-001; depthExtrinsics(0, 1) = 3.0752530258331304e-003; depthExtrinsics(0, 2) = -1.2478536028949385e-002; + depthExtrinsics(1, 0) = -3.0607678272497924e-003; depthExtrinsics(1, 1) = 9.9999461994140826e-001; depthExtrinsics(1, 2) = 1.1797408808971066e-003; + depthExtrinsics(2, 0) = 1.2482096895408091e-002; depthExtrinsics(2, 1) = -1.1414495457493831e-003; depthExtrinsics(2, 2) = 9.9992144408949846e-001; + + //t[0] = -2.5331974929667012e+001; t[1] = 6.1798287248283634e-001; t[2] = 3.8510108109251804e+000; + //t[0] /= 1000.0f; t[1] /= 1000.0f; t[2] /= 1000.0f; + // + //initializeDepthExtrinsics(R, t); +} + +bool PrimeSenseSensor::processDepth() +{ + + bool hr = true; + + m_bDepthImageIsUpdated = false; + m_bDepthImageCameraIsUpdated = false; + m_bNormalImageCameraIsUpdated = false; + + static int cnt = 0; + printf("primesense: %d\n", cnt++); + hr = readDepthAndColor(getDepthFloat(), m_colorRGBX); + + m_bDepthImageIsUpdated = true; + m_bDepthImageCameraIsUpdated = true; + m_bNormalImageCameraIsUpdated = true; + + m_bDepthReceived = true; + m_bColorReceived = true; + + return hr; +} + +bool PrimeSenseSensor::readDepthAndColor(float* depthFloat, vec4uc* colorRGBX) +{ + bool hr = true; + + int changedIndex; + openni::Status rc; + do + { + Sleep(10); + rc = openni::OpenNI::waitForAnyStream(&m_streams[0], 1, &changedIndex, 0); + } while (rc != openni::STATUS_OK); + + openni::Status sd = m_depthStream.readFrame(&m_depthFrame); + openni::Status sc = m_colorStream.readFrame(&m_colorFrame); + + assert(m_colorFrame.getWidth() == m_depthFrame.getWidth()); + assert(m_colorFrame.getHeight() == m_depthFrame.getHeight()); + + const openni::DepthPixel* pDepth = (const openni::DepthPixel*)m_depthFrame.getData(); + const openni::RGB888Pixel* pImage = (const openni::RGB888Pixel*)m_colorFrame.getData(); + + // check if we need to draw depth frame to texture + if (m_depthFrame.isValid() && m_colorFrame.isValid()) + { + unsigned int width = m_depthFrame.getWidth(); + unsigned int nPixels = m_depthFrame.getWidth()*m_depthFrame.getHeight(); + + for (unsigned int i = 0; i < nPixels; i++) { + const int x = i%width; + const int y = i / width; + const int src = y*width + (width - 1 - x); + const openni::DepthPixel& p = pDepth[src]; + + float dF = (float)p*0.00011f; + if (dF >= GlobalAppState::get().s_sensorDepthMin && dF <= GlobalAppState::get().s_sensorDepthMax) depthFloat[i] = dF; + else depthFloat[i] = -std::numeric_limits::infinity(); + } + incrementRingbufIdx(); + } + fscanf(record_exposure, "%d", &exposure); + printf("Exposure: %d\n", exposure); + if (exposure == 0) exposure = 16; + // check if we need to draw depth frame to texture + if (m_depthFrame.isValid() && m_colorFrame.isValid()) + { + unsigned int width = m_colorFrame.getWidth(); + unsigned int height = m_colorFrame.getHeight(); + unsigned int nPixels = m_colorFrame.getWidth()*m_colorFrame.getHeight(); + + for (unsigned int i = 0; i < nPixels; i++) + { + const int x = i%width; + const int y = i / width; + + int y2 = 0; + if (m_colorWidth == 1280) y2 = y + 64 / 2 - 10 - (unsigned int)(((float)y / ((float)(height - 1))) * 64 + 0.5f); + else y2 = y; + + if (y2 >= 0 && y2 < (int)height) + { + //unsigned int Index1D = y2*width+x; + unsigned int Index1D = y2*width + (width - 1 - x); //x-flip here + + const openni::RGB888Pixel& pixel = pImage[Index1D]; + float b, g, r; + b = curve[pixel.b] * 1500 / exposure; + g = curve[pixel.g] * 1500 / exposure; + r = curve[pixel.r] * 1500 / exposure; + unsigned int c = 0; + c |= min(b, 255); + c <<= 8; + c |= min(g, 255); + c <<= 8; + c |= min(r, 255); + c |= 0xFF000000; + ((LONG*)colorRGBX)[y * width + x] = c; + } + } + } + + + return hr; +} + +#endif diff --git a/FriedLiver/Source/PrimeSenseSensor.cpp b/FriedLiver/Source/PrimeSenseSensor.cpp index c2f772aa..3e3f1093 100644 --- a/FriedLiver/Source/PrimeSenseSensor.cpp +++ b/FriedLiver/Source/PrimeSenseSensor.cpp @@ -29,17 +29,6 @@ PrimeSenseSensor::~PrimeSenseSensor() m_colorStream.destroy(); m_device.close(); openni::OpenNI::shutdown(); - - /*openni::Recorder recorder; - recorder.create("test.oni"); - - recorder.attach(m_depthStream, false); - recorder.attach(m_colorStream, false); - - recorder.start(); - recorder.stop(); - - recorder.destroy();*/ } void PrimeSenseSensor::createFirstConnected() @@ -52,7 +41,18 @@ void PrimeSenseSensor::createFirstConnected() std::cout << "After initialization: " << openni::OpenNI::getExtendedError() << std::endl; // Create Device - rc = m_device.open("../data/readingroom.oni");//m_device.open(deviceURI); + std::string filename = GlobalAppState::getInstance().s_oniFile + ".oni"; + printf("OpenNI Record File: %s\n", filename.c_str()); + rc = m_device.open(filename.c_str());//m_device.open(deviceURI); + filename = GlobalAppState::getInstance().s_oniFile + "_frame_exp.txt"; + record_exposure = fopen(filename.c_str(), "r"); + filename = GlobalAppState::getInstance().s_oniFile + "_curve.txt"; + FILE* record_curve = fopen(filename.c_str(), "r"); + for (int i = 0; i < 256; i++) { + fscanf(record_curve, "%f", curve + i); + curve[i] = exp(curve[i]); + } + fclose(record_curve); if (rc != openni::STATUS_OK) { std::cout << "Device open failed: " << openni::OpenNI::getExtendedError() << std::endl; @@ -61,7 +61,8 @@ void PrimeSenseSensor::createFirstConnected() } openni::PlaybackControl* pc = m_device.getPlaybackControl(); - + pc->setSpeed(-1.0); + pc->setRepeatEnabled(false); // Create Depth Stream rc = m_depthStream.create(m_device, openni::SENSOR_DEPTH); if (rc == openni::STATUS_OK) @@ -102,17 +103,8 @@ void PrimeSenseSensor::createFirstConnected() return; } - openni::CameraSettings* cs = m_colorStream.getCameraSettings(); - - //cs->setAutoWhiteBalanceEnabled(false); - //cs->setAutoExposureEnabled(false); - //cs->setGain(1); - //cs->setExposure(10); - - std::cout << "getGain: " << cs->getGain() << std::endl; - std::cout << "getExposure: " << cs->getExposure() << std::endl; - std::cout << "getAutoExposureEnabled: " << cs->getAutoExposureEnabled() << std::endl; - std::cout << "getAutoWhiteBalanceEnabled: " << cs->getAutoWhiteBalanceEnabled() << std::endl; + m_colorStream.setMirroringEnabled(true); + m_depthStream.setMirroringEnabled(true); // Get Dimensions m_depthVideoMode = m_depthStream.getVideoMode(); @@ -125,7 +117,7 @@ void PrimeSenseSensor::createFirstConnected() RGBDSensor::init(depthWidth, depthHeight, colorWidth, colorHeight, 1); - m_streams = new openni::VideoStream*[2]; + m_streams = new openni::VideoStream * [2]; m_streams[0] = &m_depthStream; m_streams[1] = &m_colorStream; @@ -146,57 +138,45 @@ void PrimeSenseSensor::createFirstConnected() initializeColorIntrinsics(focalLengthX, focalLengthY, colorWidth / 2.0f, colorHeight / 2.0f); initializeColorExtrinsics(mat4f::identity()); - - mat4f depthExtrinsics = mat4f::identity(); - depthExtrinsics(0, 0) = 9.9991741106823473e-001; depthExtrinsics(0, 1) = 3.0752530258331304e-003; depthExtrinsics(0, 2) = -1.2478536028949385e-002; - depthExtrinsics(1, 0) = -3.0607678272497924e-003; depthExtrinsics(1, 1) = 9.9999461994140826e-001; depthExtrinsics(1, 2) = 1.1797408808971066e-003; - depthExtrinsics(2, 0) = 1.2482096895408091e-002; depthExtrinsics(2, 1) = -1.1414495457493831e-003; depthExtrinsics(2, 2) = 9.9992144408949846e-001; - - //t[0] = -2.5331974929667012e+001; t[1] = 6.1798287248283634e-001; t[2] = 3.8510108109251804e+000; - //t[0] /= 1000.0f; t[1] /= 1000.0f; t[2] /= 1000.0f; - // - //initializeDepthExtrinsics(R, t); } bool PrimeSenseSensor::processDepth() { - - bool hr = true; - m_bDepthImageIsUpdated = false; m_bDepthImageCameraIsUpdated = false; m_bNormalImageCameraIsUpdated = false; - hr = readDepthAndColor(getDepthFloat(), m_colorRGBX); - - m_bDepthImageIsUpdated = true; - m_bDepthImageCameraIsUpdated = true; - m_bNormalImageCameraIsUpdated = true; - - m_bDepthReceived = true; - m_bColorReceived = true; + static int cnt = 0; + printf("primesense: %d\n", cnt++); + if (readDepthAndColor(getDepthFloat(), m_colorRGBX)) + { + m_bDepthImageIsUpdated = true; + m_bDepthImageCameraIsUpdated = true; + m_bNormalImageCameraIsUpdated = true; - return hr; + m_bDepthReceived = true; + m_bColorReceived = true; + return true; + } + return false; } -bool PrimeSenseSensor::readDepthAndColor(float* depthFloat, vec4uc* colorRGBX) +bool PrimeSenseSensor::readDepthAndColor(float* depthFloat, vec4f* colorRGBX) { bool hr = true; - - int changedIndex; - openni::Status rc = openni::OpenNI::waitForAnyStream(&m_streams[0], 1, &changedIndex, 0); - if (rc != openni::STATUS_OK) { - return false; //no frame available + int exposure = 0; + if (record_exposure) { + if (fscanf(record_exposure, "%d", &exposure) != 1) + return false; + printf("Exposure: %d\n", exposure); } - - rc = openni::OpenNI::waitForAnyStream(&m_streams[1], 1, &changedIndex, 0); - if (rc != openni::STATUS_OK) { - return false; //no frame available - } - + if (exposure == 0) exposure = 16; openni::Status sd = m_depthStream.readFrame(&m_depthFrame); openni::Status sc = m_colorStream.readFrame(&m_colorFrame); + if (sd != openni::Status::STATUS_OK || sc != openni::Status::STATUS_OK) + return false; + assert(m_colorFrame.getWidth() == m_depthFrame.getWidth()); assert(m_colorFrame.getHeight() == m_depthFrame.getHeight()); @@ -207,31 +187,31 @@ bool PrimeSenseSensor::readDepthAndColor(float* depthFloat, vec4uc* colorRGBX) if (m_depthFrame.isValid() && m_colorFrame.isValid()) { unsigned int width = m_depthFrame.getWidth(); - unsigned int nPixels = m_depthFrame.getWidth()*m_depthFrame.getHeight(); + unsigned int nPixels = m_depthFrame.getWidth() * m_depthFrame.getHeight(); - for (unsigned int i = 0; i < nPixels; i++) { - const int x = i%width; + for (unsigned int i = 0; i < nPixels; i++) { + const int x = i % width; const int y = i / width; - const int src = y*width + (width - 1 - x); + const int src = y * width + (width - 1 - x); const openni::DepthPixel& p = pDepth[src]; - float dF = (float)p*0.001f; + float dF = (float)p * 0.0001f; + //float dF = (float)p * 0.001f; if (dF >= GlobalAppState::get().s_sensorDepthMin && dF <= GlobalAppState::get().s_sensorDepthMax) depthFloat[i] = dF; else depthFloat[i] = -std::numeric_limits::infinity(); } incrementRingbufIdx(); } - // check if we need to draw depth frame to texture if (m_depthFrame.isValid() && m_colorFrame.isValid()) { unsigned int width = m_colorFrame.getWidth(); unsigned int height = m_colorFrame.getHeight(); - unsigned int nPixels = m_colorFrame.getWidth()*m_colorFrame.getHeight(); + unsigned int nPixels = m_colorFrame.getWidth() * m_colorFrame.getHeight(); for (unsigned int i = 0; i < nPixels; i++) { - const int x = i%width; + const int x = i % width; const int y = i / width; int y2 = 0; @@ -241,19 +221,36 @@ bool PrimeSenseSensor::readDepthAndColor(float* depthFloat, vec4uc* colorRGBX) if (y2 >= 0 && y2 < (int)height) { //unsigned int Index1D = y2*width+x; - unsigned int Index1D = y2*width + (width - 1 - x); //x-flip here + unsigned int Index1D = y2 * width + (width - 1 - x); //x-flip here const openni::RGB888Pixel& pixel = pImage[Index1D]; - - unsigned int c = 0; - c |= pixel.r; + float b, g, r, w = 0; + w = max(w, min(pixel.b + 1, 256 - pixel.b)); + w = max(w, min(pixel.g + 1, 256 - pixel.g)); + w = max(w, min(pixel.r + 1, 256 - pixel.r)); + w /= 256; + if (record_exposure) + { + b = curve[pixel.b] * 8 / exposure; + g = curve[pixel.g] * 8 / exposure; + r = curve[pixel.r] * 8 / exposure; + } + else { + b = pixel.r / 255.0f; + g = pixel.g / 255.0f; + r = pixel.b / 255.0f; + } + /* unsigned int c = 0; + c |= min(b, 255); c <<= 8; - c |= pixel.g; + c |= min(g, 255); c <<= 8; - c |= pixel.b; - c |= 0xFF000000; - - ((LONG*)colorRGBX)[y*width + x] = c; + c |= min(r, 255); + c |= 0xFF000000; */ + colorRGBX[y * width + x][0] = b; + colorRGBX[y * width + x][1] = g; + colorRGBX[y * width + x][2] = r; + colorRGBX[y * width + x][3] = w; } } } diff --git a/FriedLiver/Source/PrimeSenseSensor.h b/FriedLiver/Source/PrimeSenseSensor.h index 4c5a8a44..6d998e01 100644 --- a/FriedLiver/Source/PrimeSenseSensor.h +++ b/FriedLiver/Source/PrimeSenseSensor.h @@ -44,7 +44,7 @@ class PrimeSenseSensor : public RGBDSensor protected: //! reads depth and color from the sensor - bool readDepthAndColor(float* depthFloat, vec4uc* colorRGBX); + bool readDepthAndColor(float* depthFloat, vec4f* colorRGBX); // to prevent drawing until we have data for both streams @@ -68,7 +68,8 @@ class PrimeSenseSensor : public RGBDSensor openni::VideoStream m_depthStream; openni::VideoStream m_colorStream; openni::VideoStream** m_streams; - + FILE* record_exposure; + float curve[256]; }; #endif diff --git a/FriedLiver/Source/RGBDSensor.cpp b/FriedLiver/Source/RGBDSensor.cpp index cc9003ee..b523659c 100644 --- a/FriedLiver/Source/RGBDSensor.cpp +++ b/FriedLiver/Source/RGBDSensor.cpp @@ -57,7 +57,7 @@ void RGBDSensor::init(unsigned int depthWidth, unsigned int depthHeight, unsigne } SAFE_DELETE_ARRAY(m_colorRGBX); - m_colorRGBX = new vec4uc[m_colorWidth*m_colorHeight]; + m_colorRGBX = new vec4f[m_colorWidth*m_colorHeight]; m_recordDataWidth = GlobalAppState::get().s_recordDataWidth; m_recordDataHeight = GlobalAppState::get().s_recordDataHeight; @@ -186,11 +186,11 @@ void RGBDSensor::incrementRingbufIdx() } //! gets the pointer to color array -vec4uc* RGBDSensor::getColorRGBX() { +vec4f* RGBDSensor::getColorRGBX() { return m_colorRGBX; } -const vec4uc* RGBDSensor::getColorRGBX() const { +const vec4f* RGBDSensor::getColorRGBX() const { return m_colorRGBX; } @@ -332,11 +332,11 @@ void RGBDSensor::recordFrame() if ((m_recordDataWidth == 0 && m_recordDataHeight == 0) || (getColorWidth() == m_recordDataWidth && getColorHeight() == m_recordDataHeight)) { m_recordedColorData.push_back(m_colorRGBX); - m_colorRGBX = new vec4uc[getColorWidth()*getColorHeight()]; + m_colorRGBX = new vec4f[getColorWidth()*getColorHeight()]; } else { - m_recordedColorData.push_back(new vec4uc[m_recordDataWidth*m_recordDataHeight]); - vec4uc* color = m_recordedColorData.back(); + m_recordedColorData.push_back(new vec4f[m_recordDataWidth*m_recordDataHeight]); + vec4f* color = m_recordedColorData.back(); float scaleX = (float)(getColorWidth() - 1) / (m_recordDataWidth - 1); float scaleY = (float)(getColorHeight() - 1) / (m_recordDataHeight - 1); for (unsigned int y = 0; y < m_recordDataHeight; y++) { diff --git a/FriedLiver/Source/RGBDSensor.h b/FriedLiver/Source/RGBDSensor.h index 85b13458..1e2824e5 100644 --- a/FriedLiver/Source/RGBDSensor.h +++ b/FriedLiver/Source/RGBDSensor.h @@ -52,8 +52,8 @@ class RGBDSensor const float* getDepthFloat() const; //! gets the pointer to color array - vec4uc* getColorRGBX(); - const vec4uc* getColorRGBX() const; + vec4f* getColorRGBX(); + const vec4f* getColorRGBX() const; unsigned int getColorWidth() const; unsigned int getColorHeight() const; @@ -116,7 +116,7 @@ class RGBDSensor mat4f m_colorExtrinsicsInv; std::vector m_depthFloat; - vec4uc* m_colorRGBX; + vec4f* m_colorRGBX; LONG m_depthWidth; LONG m_depthHeight; @@ -140,7 +140,7 @@ class RGBDSensor bool m_bUseModernSensFilesForRecording; std::list m_recordedDepthData; - std::list m_recordedColorData; + std::list m_recordedColorData; std::vector m_recordedPoints; diff --git a/FriedLiver/Source/SensorDataReader.cpp b/FriedLiver/Source/SensorDataReader.cpp index 72807c7d..4803c544 100644 --- a/FriedLiver/Source/SensorDataReader.cpp +++ b/FriedLiver/Source/SensorDataReader.cpp @@ -110,7 +110,7 @@ bool SensorDataReader::processDepth() if (m_bHasColorData) { for (unsigned int i = 0; i < getColorWidth()*getColorHeight(); i++) { - m_colorRGBX[i] = vec4uc(frameState.m_colorFrame[i]); + m_colorRGBX[i] = vec4f(frameState.m_colorFrame[i]) / 255.0f; } } frameState.free(); diff --git a/FriedLiver/zParametersBundlingDefault.txt b/FriedLiver/zParametersBundlingDefault.txt index 7b899a8f..a50b3139 100644 --- a/FriedLiver/zParametersBundlingDefault.txt +++ b/FriedLiver/zParametersBundlingDefault.txt @@ -7,8 +7,8 @@ s_sendUplinkFeedbackImage = true; s_recordSolverConvergence = false; -s_enablePerFrameTimings = false; -s_enableGlobalTimings = false; +s_enablePerFrameTimings = true; +s_enableGlobalTimings = true; s_widthSIFT = 640; s_heightSIFT = 480; @@ -24,7 +24,7 @@ s_denseNormalThresh = 0.97f; s_denseColorThresh = 0.1f; s_denseColorGradientMin = 0.005f; s_denseDepthMin = 0.5f; -s_denseDepthMax = 4.0f; +s_denseDepthMax = 5.0f; s_denseOverlapCheckSubsampleFactor = 4; s_maxNumImages = 1200; diff --git a/FriedLiver/zParametersDefault.txt b/FriedLiver/zParametersDefault.txt index 72be9447..3079a54b 100644 --- a/FriedLiver/zParametersDefault.txt +++ b/FriedLiver/zParametersDefault.txt @@ -1,5 +1,5 @@ // 0=Kinect; 1=PrimeSense; 2=KinectOne; 3=BinaryDumpReader; 4=NetworkSensor; 5=IntelSensor; 6=RealSense; 7=StructureSensor; 8=SensorDataReader (for offline processing) -s_sensorIdx = 8; +s_sensorIdx = 1; s_numSolveFramesBeforeExit = 30;//-1 //#frames to run after solve done, then saves and exits; -1 to stop after no more reintegration ops @@ -42,7 +42,7 @@ s_SDFTruncation = 0.06f; //truncation in meter s_SDFTruncationScale = 0.02f; //truncation scale in meter per meter s_SDFMaxIntegrationDistance = 3.0f; //maximum integration in meter s_SDFIntegrationWeightSample = 1; //weight for an integrated depth value -s_SDFIntegrationWeightMax = 99999999; //maximum integration weight for a voxel +s_SDFIntegrationWeightMax = 100000000; //maximum integration weight for a voxel // s_SDFBlockSize is pound defined (SDF_BLOCK_SIZE) // s_hashBucketSize is pound defined (HASH_BUCKET_SIZE) s_hashNumBuckets = 400000; //smaller voxels require more space @@ -94,7 +94,7 @@ s_remappingDepthDiscontinuityThresLin = 0.01f; s_bUseCameraCalibration = false; -s_marchingCubesMaxNumTriangles = 3000000; // max buffer size for marching cube +s_marchingCubesMaxNumTriangles = 6000000; // max buffer size for marching cube //streaming parameters (streaming disabled for BundleFusion) s_streamingEnabled = false; @@ -106,6 +106,10 @@ s_streamingRadius = 5.0f; // Depends on DepthMin and DepthMax s_streamingPos = 0.0f 0.0f 3.0f 1.0f; // Depends on DepthMin and DepthMax s_streamingOutParts = 80; // number of frames required to sweep through the entire hash +//OpenNI file configuration +s_oniFile = "../data/6"; //?????,??*.oni,*_curve.txt,*_frame_exp.txt??? + + //recording of the input data s_recordData = false; // master flag for data recording: enables or disables data recording s_recordCompression = true; //if recoding is enabled; then compression is used (.sens instead of .sensor) diff --git a/README.md b/README.md index 189b2c65..62ac5d34 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,19 @@ -# BundleFusion +# HDRBundleFusion -![BundleFusion](img/test.gif) +![HDRBundleFusion](img/test.gif) -This is a modern port for [BundleFusion](http://graphics.stanford.edu/projects/bundlefusion/). Since DirectX SDK has been deprecated and Nvidia changed some CUDA apis, original BundleFusion code would not run smoothly on latest platforms. For example, code compiled in VS2017 does not run in Release mode. Also, the original code hangs on GPU synchronize function if you use new volta/turing GPUs. + +Fork from [BundleFusion](https://github.com/wuyingnan/BundleFusion/). The license is the same with original BundleFusion. (Please see [License.txt](LICENSE.txt)). ## Installation -The modified code was tested under VS2017 with CUDA10.1 and a RTX2060. +The modified code was tested under VS2019 with CUDA10.2 and a GTX 1660. Requirements: - Windows SDK (Install it from your Visual Studio) -- DirectX SDK **IS NOT NEEDED** -- NVIDIA CUDA 10.1 +- NVIDIA CUDA 10.2 +- eigen, a git submodule in external/eigen - research library mLib, a git submodule in external/mLib - mLib external libraries can be downloaded [here](http://kaldir.vc.in.tum.de/mLib/mLibExternal.zip) @@ -30,7 +31,6 @@ BundleFusion-master │──libsOSX └──libsWindows ``` -Put sequence.sens in BundleFusion-master/BundleFusion/data/. +Put *.oni *_curve.txt and *_frame_exp.txt files in BundleFusion/data/. ## End -You may star me if you find it useful. :) diff --git a/README.md.old b/README_old.md similarity index 100% rename from README.md.old rename to README_old.md diff --git a/README_old2.md b/README_old2.md new file mode 100644 index 00000000..189b2c65 --- /dev/null +++ b/README_old2.md @@ -0,0 +1,36 @@ +# BundleFusion + +![BundleFusion](img/test.gif) + +This is a modern port for [BundleFusion](http://graphics.stanford.edu/projects/bundlefusion/). Since DirectX SDK has been deprecated and Nvidia changed some CUDA apis, original BundleFusion code would not run smoothly on latest platforms. For example, code compiled in VS2017 does not run in Release mode. Also, the original code hangs on GPU synchronize function if you use new volta/turing GPUs. + +The license is the same with original BundleFusion. (Please see [License.txt](LICENSE.txt)). + +## Installation +The modified code was tested under VS2017 with CUDA10.1 and a RTX2060. + +Requirements: +- Windows SDK (Install it from your Visual Studio) +- DirectX SDK **IS NOT NEEDED** +- NVIDIA CUDA 10.1 +- research library mLib, a git submodule in external/mLib +- mLib external libraries can be downloaded [here](http://kaldir.vc.in.tum.de/mLib/mLibExternal.zip) + +Default file tree: +``` +BundleFusion-master +├──BundleFusion +│ │──data +│ │──external +│ │──FriedLiver +│ └──img +└──mlibExternal + │──include + │──libsLinux + │──libsOSX + └──libsWindows +``` +Put sequence.sens in BundleFusion-master/BundleFusion/data/. + +## End +You may star me if you find it useful. :) diff --git a/external/eigen b/external/eigen new file mode 160000 index 00000000..1c9aa054 --- /dev/null +++ b/external/eigen @@ -0,0 +1 @@ +Subproject commit 1c9aa054c776e16ef872cbd58cb77eef2b732891 diff --git a/external/mLib b/external/mLib index ac6b9e9d..3c9c04c7 160000 --- a/external/mLib +++ b/external/mLib @@ -1 +1 @@ -Subproject commit ac6b9e9d1da1df00a2293da64a9f146c123fa2ca +Subproject commit 3c9c04c7a69534100c0241c2869fa7961662c4f9