diff --git a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp index 84c2ccf4d8..904f1aff06 100644 --- a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp +++ b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include #include #include "Common/Common.h" @@ -28,7 +29,7 @@ static const u32 UBO_LENGTH = 32*1024*1024; u32 ProgramShaderCache::s_ubo_buffer_size; s32 ProgramShaderCache::s_ubo_align; -static StreamBuffer *s_buffer; +static std::unique_ptr s_buffer; static int num_failures = 0; static LinearDiskCache g_program_disk_cache; @@ -505,8 +506,7 @@ void ProgramShaderCache::Shutdown() pixel_uid_checker.Invalidate(); vertex_uid_checker.Invalidate(); - delete s_buffer; - s_buffer = nullptr; + s_buffer.reset(); } void ProgramShaderCache::CreateHeader() diff --git a/Source/Core/VideoBackends/OGL/StreamBuffer.cpp b/Source/Core/VideoBackends/OGL/StreamBuffer.cpp index 5107fe0b17..5268423d72 100644 --- a/Source/Core/VideoBackends/OGL/StreamBuffer.cpp +++ b/Source/Core/VideoBackends/OGL/StreamBuffer.cpp @@ -355,17 +355,17 @@ public: u8* m_pointer; }; -// choose best streaming library based on the supported extensions and known issues -StreamBuffer* StreamBuffer::Create(u32 type, u32 size) +// Chooses the best streaming method based on the supported extensions and known issues +std::unique_ptr StreamBuffer::Create(u32 type, u32 size) { // without basevertex support, only streaming methods whith uploads everything to zero works fine: if (!g_ogl_config.bSupportsGLBaseVertex) { if (!DriverDetails::HasBug(DriverDetails::BUG_BROKENBUFFERSTREAM)) - return new BufferSubData(type, size); + return std::make_unique(type, size); // BufferData is by far the worst way, only use it if needed - return new BufferData(type, size); + return std::make_unique(type, size); } // Prefer the syncing buffers over the orphaning one @@ -374,25 +374,25 @@ StreamBuffer* StreamBuffer::Create(u32 type, u32 size) // pinned memory is much faster than buffer storage on AMD cards if (g_ogl_config.bSupportsGLPinnedMemory && !(DriverDetails::HasBug(DriverDetails::BUG_BROKENPINNEDMEMORY) && type == GL_ELEMENT_ARRAY_BUFFER)) - return new PinnedMemory(type, size); + return std::make_unique(type, size); // buffer storage works well in most situations if (g_ogl_config.bSupportsGLBufferStorage && !(DriverDetails::HasBug(DriverDetails::BUG_BROKENBUFFERSTORAGE) && type == GL_ARRAY_BUFFER) && !(DriverDetails::HasBug(DriverDetails::BUG_INTELBROKENBUFFERSTORAGE) && type == GL_ELEMENT_ARRAY_BUFFER)) - return new BufferStorage(type, size); + return std::make_unique(type, size); // don't fall back to MapAnd* for Nvidia drivers if (DriverDetails::HasBug(DriverDetails::BUG_BROKENUNSYNCMAPPING)) - return new BufferSubData(type, size); + return std::make_unique(type, size); // mapping fallback if (g_ogl_config.bSupportsGLSync) - return new MapAndSync(type, size); + return std::make_unique(type, size); } // default fallback, should work everywhere, but isn't the best way to do this job - return new MapAndOrphan(type, size); + return std::make_unique(type, size); } } diff --git a/Source/Core/VideoBackends/OGL/StreamBuffer.h b/Source/Core/VideoBackends/OGL/StreamBuffer.h index b886e49c53..4cb1c93703 100644 --- a/Source/Core/VideoBackends/OGL/StreamBuffer.h +++ b/Source/Core/VideoBackends/OGL/StreamBuffer.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include "Common/GL/GLUtil.h" @@ -20,7 +21,7 @@ class StreamBuffer { public: - static StreamBuffer* Create(u32 type, u32 size); + static std::unique_ptr Create(u32 type, u32 size); virtual ~StreamBuffer(); /* This mapping function will return a pair of: diff --git a/Source/Core/VideoBackends/OGL/TextureCache.cpp b/Source/Core/VideoBackends/OGL/TextureCache.cpp index 3b07b44319..32cdcd6587 100644 --- a/Source/Core/VideoBackends/OGL/TextureCache.cpp +++ b/Source/Core/VideoBackends/OGL/TextureCache.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "Common/Common.h" @@ -51,7 +52,7 @@ static u32 s_Textures[8]; static u32 s_ActiveTexture; static SHADER s_palette_pixel_shader[3]; -static StreamBuffer* s_palette_stream_buffer = nullptr; +static std::unique_ptr s_palette_stream_buffer; static GLuint s_palette_resolv_texture; static GLuint s_palette_buffer_offset_uniform[3]; static GLuint s_palette_multiplier_uniform[3]; @@ -318,8 +319,7 @@ TextureCache::~TextureCache() if (g_ActiveConfig.backend_info.bSupportsPaletteConversion) { - delete s_palette_stream_buffer; - s_palette_stream_buffer = nullptr; + s_palette_stream_buffer.reset(); glDeleteTextures(1, &s_palette_resolv_texture); } } diff --git a/Source/Core/VideoBackends/OGL/VertexManager.cpp b/Source/Core/VideoBackends/OGL/VertexManager.cpp index 5f5ddc4104..c37f4cbecd 100644 --- a/Source/Core/VideoBackends/OGL/VertexManager.cpp +++ b/Source/Core/VideoBackends/OGL/VertexManager.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include @@ -36,8 +37,8 @@ namespace OGL const u32 MAX_IBUFFER_SIZE = 2*1024*1024; const u32 MAX_VBUFFER_SIZE = 32*1024*1024; -static StreamBuffer *s_vertexBuffer; -static StreamBuffer *s_indexBuffer; +static std::unique_ptr s_vertexBuffer; +static std::unique_ptr s_indexBuffer; static size_t s_baseVertex; static size_t s_index_offset; @@ -65,8 +66,8 @@ void VertexManager::CreateDeviceObjects() void VertexManager::DestroyDeviceObjects() { - delete s_vertexBuffer; - delete s_indexBuffer; + s_vertexBuffer.reset(); + s_indexBuffer.reset(); } void VertexManager::PrepareDrawBuffers(u32 stride)