From 6a640532566d31c58a984e0ef3a9681466778789 Mon Sep 17 00:00:00 2001 From: Warchamp7 Date: Wed, 17 Dec 2025 19:25:30 -0500 Subject: [PATCH] libobs: Remove "using namespace std" from headers --- libobs-d3d11/d3d11-shader.cpp | 36 +++++++++---------- libobs-d3d11/d3d11-shaderprocessor.hpp | 8 ++--- libobs-d3d11/d3d11-subsystem.cpp | 10 +++--- libobs-d3d11/d3d11-subsystem.hpp | 50 +++++++++++++------------- libobs-d3d11/d3d11-texture2d.cpp | 4 +-- libobs-d3d11/d3d11-texture3d.cpp | 4 +-- 6 files changed, 55 insertions(+), 57 deletions(-) diff --git a/libobs-d3d11/d3d11-shader.cpp b/libobs-d3d11/d3d11-shader.cpp index d77c72946..3e4aaa1cc 100644 --- a/libobs-d3d11/d3d11-shader.cpp +++ b/libobs-d3d11/d3d11-shader.cpp @@ -28,7 +28,7 @@ #include #include -void gs_vertex_shader::GetBuffersExpected(const vector &inputs) +void gs_vertex_shader::GetBuffersExpected(const std::vector &inputs) { for (size_t i = 0; i < inputs.size(); i++) { const D3D11_INPUT_ELEMENT_DESC &input = inputs[i]; @@ -52,7 +52,7 @@ gs_vertex_shader::gs_vertex_shader(gs_device_t *device, const char *file, const { ShaderProcessor processor(device); ComPtr shaderBlob; - string outputString; + std::string outputString; HRESULT hr; processor.Process(shaderString, file); @@ -88,7 +88,7 @@ gs_pixel_shader::gs_pixel_shader(gs_device_t *device, const char *file, const ch { ShaderProcessor processor(device); ComPtr shaderBlob; - string outputString; + std::string outputString; HRESULT hr; processor.Process(shaderString, file); @@ -226,26 +226,26 @@ void gs_shader::Compile(const char *shaderString, const char *file, const char * snprintf(hashstr, sizeof(hashstr), "%02llx", hash); BPtr program_data = os_get_program_data_path_ptr("obs-studio/shader-cache"); - auto cachePath = filesystem::u8path(program_data.Get()) / hashstr; + auto cachePath = std::filesystem::u8path(program_data.Get()) / hashstr; // Increment if on-disk format changes cachePath += ".v2"; std::fstream cacheFile; - cacheFile.exceptions(fstream::badbit | fstream::eofbit); + cacheFile.exceptions(std::fstream::badbit | std::fstream::eofbit); - if (filesystem::exists(cachePath) && !filesystem::is_empty(cachePath)) - cacheFile.open(cachePath, ios::in | ios::binary | ios::ate); + if (std::filesystem::exists(cachePath) && !std::filesystem::is_empty(cachePath)) + cacheFile.open(cachePath, std::ios::in | std::ios::binary | std::ios::ate); if (cacheFile.is_open()) { uint64_t checksum; try { - streampos len = cacheFile.tellg(); + std::streampos len = cacheFile.tellg(); // Not enough data for checksum + shader if (len <= sizeof(checksum)) - throw length_error("File truncated"); + throw std::length_error("File truncated"); - cacheFile.seekg(0, ios::beg); + cacheFile.seekg(0, std::ios::beg); len -= sizeof(checksum); D3DCreateBlob(len, shader); @@ -254,14 +254,14 @@ void gs_shader::Compile(const char *shaderString, const char *file, const char * cacheFile.read((char *)&checksum, sizeof(checksum)); if (calculated_checksum != checksum) - throw exception("Checksum mismatch"); + throw std::exception("Checksum mismatch"); is_cached = true; - } catch (const exception &e) { + } catch (const std::exception &e) { // Something went wrong reading the cache file, delete it blog(LOG_WARNING, "Loading shader cache file failed with \"%s\": %s", e.what(), file); cacheFile.close(); - filesystem::remove(cachePath); + std::filesystem::remove(cachePath); } } @@ -275,7 +275,7 @@ void gs_shader::Compile(const char *shaderString, const char *file, const char * throw HRError("Failed to compile shader", hr); } - cacheFile.open(cachePath, ios::out | ios::binary); + cacheFile.open(cachePath, std::ios::out | std::ios::binary); if (cacheFile.is_open()) { try { uint64_t calculated_checksum = @@ -283,10 +283,10 @@ void gs_shader::Compile(const char *shaderString, const char *file, const char * cacheFile.write((char *)(*shader)->GetBufferPointer(), (*shader)->GetBufferSize()); cacheFile.write((char *)&calculated_checksum, sizeof(calculated_checksum)); - } catch (const exception &e) { + } catch (const std::exception &e) { blog(LOG_WARNING, "Writing shader cache file failed with \"%s\": %s", e.what(), file); cacheFile.close(); - filesystem::remove(cachePath); + std::filesystem::remove(cachePath); } } } @@ -303,7 +303,7 @@ void gs_shader::Compile(const char *shaderString, const char *file, const char * #endif } -inline void gs_shader::UpdateParam(vector &constData, gs_shader_param ¶m, bool &upload) +inline void gs_shader::UpdateParam(std::vector &constData, gs_shader_param ¶m, bool &upload) { if (param.type != GS_SHADER_PARAM_TEXTURE) { if (!param.curValue.size()) @@ -342,7 +342,7 @@ inline void gs_shader::UpdateParam(vector &constData, gs_shader_param & void gs_shader::UploadParams() { - vector constData; + std::vector constData; bool upload = false; constData.reserve(constantSize); diff --git a/libobs-d3d11/d3d11-shaderprocessor.hpp b/libobs-d3d11/d3d11-shaderprocessor.hpp index b15a94d54..32974e6b6 100644 --- a/libobs-d3d11/d3d11-shaderprocessor.hpp +++ b/libobs-d3d11/d3d11-shaderprocessor.hpp @@ -28,10 +28,10 @@ struct ShaderProcessor { gs_device_t *device; ShaderParser parser; - void BuildInputLayout(vector &inputs); - void BuildParams(vector ¶ms); - void BuildSamplers(vector> &samplers); - void BuildString(string &outputString); + void BuildInputLayout(std::vector &inputs); + void BuildParams(std::vector ¶ms); + void BuildSamplers(std::vector> &samplers); + void BuildString(std::string &outputString); void Process(const char *shader_string, const char *file); inline ShaderProcessor(gs_device_t *device) : device(device) {} diff --git a/libobs-d3d11/d3d11-subsystem.cpp b/libobs-d3d11/d3d11-subsystem.cpp index 1ef405763..ad42718c6 100644 --- a/libobs-d3d11/d3d11-subsystem.cpp +++ b/libobs-d3d11/d3d11-subsystem.cpp @@ -479,9 +479,9 @@ struct HagsStatus { } } - string ToString() const + std::string ToString() const { - string status = enabled ? "Enabled" : "Disabled"; + std::string status = enabled ? "Enabled" : "Disabled"; status += " (Default: "; status += enabled_by_default ? "Yes" : "No"; status += ", Driver status: "; @@ -509,9 +509,9 @@ private: } }; -static optional GetAdapterHagsStatus(const DXGI_ADAPTER_DESC *desc) +static std::optional GetAdapterHagsStatus(const DXGI_ADAPTER_DESC *desc) { - optional ret; + std::optional ret; D3DKMT_OPENADAPTERFROMLUID d3dkmt_openluid{}; d3dkmt_openluid.AdapterLuid = desc->AdapterLuid; @@ -586,7 +586,7 @@ static bool FastClearSupported(UINT vendorId, uint64_t version) void gs_device::InitDevice(uint32_t adapterIdx) { - wstring adapterName; + std::wstring adapterName; DXGI_ADAPTER_DESC desc; D3D_FEATURE_LEVEL levelUsed = D3D_FEATURE_LEVEL_10_0; LARGE_INTEGER umd; diff --git a/libobs-d3d11/d3d11-subsystem.hpp b/libobs-d3d11/d3d11-subsystem.hpp index 9278d49ed..1162ce6a7 100644 --- a/libobs-d3d11/d3d11-subsystem.hpp +++ b/libobs-d3d11/d3d11-subsystem.hpp @@ -43,8 +43,6 @@ struct shader_var; struct shader_sampler; struct gs_vertex_shader; -using namespace std; - /* * Just to clarify, all structs, and all public. These are exporting only * via encapsulated C bindings, not C++ bindings, so the whole concept of @@ -376,12 +374,12 @@ struct gs_vertex_buffer : gs_obj { ComPtr normalBuffer; ComPtr colorBuffer; ComPtr tangentBuffer; - vector> uvBuffers; + std::vector> uvBuffers; bool dynamic; VBDataPtr vbd; size_t numVerts; - vector uvSizes; + std::vector uvSizes; void FlushBuffer(ID3D11Buffer *buffer, void *array, size_t elementSize); @@ -516,11 +514,11 @@ struct gs_texture_2d : gs_texture { bool chroma = false; bool acquired = false; - vector> data; - vector srd; + std::vector> data; + std::vector srd; D3D11_TEXTURE2D_DESC td = {}; - void InitSRD(vector &srd); + void InitSRD(std::vector &srd); void InitTexture(const uint8_t *const *data); void InitResourceView(); void InitRenderTargets(); @@ -571,11 +569,11 @@ struct gs_texture_3d : gs_texture { bool chroma = false; bool acquired = false; - vector> data; - vector srd; + std::vector> data; + std::vector srd; D3D11_TEXTURE3D_DESC td = {}; - void InitSRD(vector &srd); + void InitSRD(std::vector &srd); void InitTexture(const uint8_t *const *data); void InitResourceView(); void BackupTexture(const uint8_t *const *data); @@ -655,7 +653,7 @@ struct gs_sampler_state : gs_obj { }; struct gs_shader_param { - string name; + std::string name; gs_shader_param_type type; uint32_t textureID; @@ -665,8 +663,8 @@ struct gs_shader_param { size_t pos; - vector curValue; - vector defaultValue; + std::vector curValue; + std::vector defaultValue; bool changed; gs_shader_param(shader_var &var, uint32_t &texCounter); @@ -681,14 +679,14 @@ struct ShaderError { struct gs_shader : gs_obj { gs_shader_type type; - vector params; + std::vector params; ComPtr constants; size_t constantSize; D3D11_BUFFER_DESC bd = {}; - vector data; + std::vector data; - inline void UpdateParam(vector &constData, gs_shader_param ¶m, bool &upload); + inline void UpdateParam(std::vector &constData, gs_shader_param ¶m, bool &upload); void UploadParams(); void BuildConstantBuffer(); @@ -705,7 +703,7 @@ struct gs_shader : gs_obj { }; struct ShaderSampler { - string name; + std::string name; gs_sampler_state sampler; inline ShaderSampler(const char *name, gs_device_t *device, gs_sampler_info *info) @@ -721,7 +719,7 @@ struct gs_vertex_shader : gs_shader { gs_shader_param *world, *viewProj; - vector layoutData; + std::vector layoutData; bool hasNormals; bool hasColors; @@ -750,7 +748,7 @@ struct gs_vertex_shader : gs_shader { return count; } - void GetBuffersExpected(const vector &inputs); + void GetBuffersExpected(const std::vector &inputs); gs_vertex_shader(gs_device_t *device, const char *file, const char *shaderString); }; @@ -775,7 +773,7 @@ struct gs_duplicator : gs_obj { struct gs_pixel_shader : gs_shader { ComPtr shader; - vector> samplers; + std::vector> samplers; void Rebuild(ID3D11Device *dev); @@ -987,9 +985,9 @@ struct gs_device { ZStencilState zstencilState; RasterState rasterState; BlendState blendState; - vector zstencilStates; - vector rasterStates; - vector blendStates; + std::vector zstencilStates; + std::vector rasterStates; + std::vector blendStates; ID3D11DepthStencilState *curDepthStencilState = nullptr; ID3D11RasterizerState *curRasterState = nullptr; ID3D11BlendState *curBlendState = nullptr; @@ -997,16 +995,16 @@ struct gs_device { gs_rect viewport; - vector projStack; + std::vector projStack; matrix4 curProjMatrix; matrix4 curViewMatrix; matrix4 curViewProjMatrix; - vector loss_callbacks; + std::vector loss_callbacks; gs_obj *first_obj = nullptr; - vector> monitor_to_hdr; + std::vector> monitor_to_hdr; void InitFactory(); void InitAdapter(uint32_t adapterIdx); diff --git a/libobs-d3d11/d3d11-texture2d.cpp b/libobs-d3d11/d3d11-texture2d.cpp index cbb54762b..beb98ab2a 100644 --- a/libobs-d3d11/d3d11-texture2d.cpp +++ b/libobs-d3d11/d3d11-texture2d.cpp @@ -18,7 +18,7 @@ #include #include "d3d11-subsystem.hpp" -void gs_texture_2d::InitSRD(vector &srd) +void gs_texture_2d::InitSRD(std::vector &srd) { uint32_t rowSizeBytes = width * gs_get_format_bpp(format); uint32_t texSizeBytes = height * rowSizeBytes / 8; @@ -66,7 +66,7 @@ void gs_texture_2d::BackupTexture(const uint8_t *const *data) uint32_t texSize = bbp * w * h / 8; - vector &subData = this->data[i]; + std::vector &subData = this->data[i]; subData.resize(texSize); memcpy(&subData[0], data[i], texSize); diff --git a/libobs-d3d11/d3d11-texture3d.cpp b/libobs-d3d11/d3d11-texture3d.cpp index f40abbd69..87aaa29f4 100644 --- a/libobs-d3d11/d3d11-texture3d.cpp +++ b/libobs-d3d11/d3d11-texture3d.cpp @@ -18,7 +18,7 @@ #include #include "d3d11-subsystem.hpp" -void gs_texture_3d::InitSRD(vector &srd) +void gs_texture_3d::InitSRD(std::vector &srd) { uint32_t rowSizeBits = width * gs_get_format_bpp(format); uint32_t sliceSizeBytes = height * rowSizeBits / 8; @@ -58,7 +58,7 @@ void gs_texture_3d::BackupTexture(const uint8_t *const *data) const uint32_t texSize = bbp * w * h * d / 8; this->data[i].resize(texSize); - vector &subData = this->data[i]; + std::vector &subData = this->data[i]; memcpy(&subData[0], data[i], texSize); if (w > 1)