StreamBuffer: Make factory function return a std::unique_ptr

This commit is contained in:
Lioncash 2015-12-21 10:15:17 -05:00
parent ec71452706
commit d20ba76ab3
5 changed files with 22 additions and 20 deletions

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <memory>
#include <string> #include <string>
#include "Common/Common.h" #include "Common/Common.h"
@ -28,7 +29,7 @@ static const u32 UBO_LENGTH = 32*1024*1024;
u32 ProgramShaderCache::s_ubo_buffer_size; u32 ProgramShaderCache::s_ubo_buffer_size;
s32 ProgramShaderCache::s_ubo_align; s32 ProgramShaderCache::s_ubo_align;
static StreamBuffer *s_buffer; static std::unique_ptr<StreamBuffer> s_buffer;
static int num_failures = 0; static int num_failures = 0;
static LinearDiskCache<SHADERUID, u8> g_program_disk_cache; static LinearDiskCache<SHADERUID, u8> g_program_disk_cache;
@ -505,8 +506,7 @@ void ProgramShaderCache::Shutdown()
pixel_uid_checker.Invalidate(); pixel_uid_checker.Invalidate();
vertex_uid_checker.Invalidate(); vertex_uid_checker.Invalidate();
delete s_buffer; s_buffer.reset();
s_buffer = nullptr;
} }
void ProgramShaderCache::CreateHeader() void ProgramShaderCache::CreateHeader()

View File

@ -355,17 +355,17 @@ public:
u8* m_pointer; u8* m_pointer;
}; };
// choose best streaming library based on the supported extensions and known issues // Chooses the best streaming method based on the supported extensions and known issues
StreamBuffer* StreamBuffer::Create(u32 type, u32 size) std::unique_ptr<StreamBuffer> StreamBuffer::Create(u32 type, u32 size)
{ {
// without basevertex support, only streaming methods whith uploads everything to zero works fine: // without basevertex support, only streaming methods whith uploads everything to zero works fine:
if (!g_ogl_config.bSupportsGLBaseVertex) if (!g_ogl_config.bSupportsGLBaseVertex)
{ {
if (!DriverDetails::HasBug(DriverDetails::BUG_BROKENBUFFERSTREAM)) if (!DriverDetails::HasBug(DriverDetails::BUG_BROKENBUFFERSTREAM))
return new BufferSubData(type, size); return std::make_unique<BufferSubData>(type, size);
// BufferData is by far the worst way, only use it if needed // BufferData is by far the worst way, only use it if needed
return new BufferData(type, size); return std::make_unique<BufferData>(type, size);
} }
// Prefer the syncing buffers over the orphaning one // 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 // pinned memory is much faster than buffer storage on AMD cards
if (g_ogl_config.bSupportsGLPinnedMemory && if (g_ogl_config.bSupportsGLPinnedMemory &&
!(DriverDetails::HasBug(DriverDetails::BUG_BROKENPINNEDMEMORY) && type == GL_ELEMENT_ARRAY_BUFFER)) !(DriverDetails::HasBug(DriverDetails::BUG_BROKENPINNEDMEMORY) && type == GL_ELEMENT_ARRAY_BUFFER))
return new PinnedMemory(type, size); return std::make_unique<PinnedMemory>(type, size);
// buffer storage works well in most situations // buffer storage works well in most situations
if (g_ogl_config.bSupportsGLBufferStorage && if (g_ogl_config.bSupportsGLBufferStorage &&
!(DriverDetails::HasBug(DriverDetails::BUG_BROKENBUFFERSTORAGE) && type == GL_ARRAY_BUFFER) && !(DriverDetails::HasBug(DriverDetails::BUG_BROKENBUFFERSTORAGE) && type == GL_ARRAY_BUFFER) &&
!(DriverDetails::HasBug(DriverDetails::BUG_INTELBROKENBUFFERSTORAGE) && type == GL_ELEMENT_ARRAY_BUFFER)) !(DriverDetails::HasBug(DriverDetails::BUG_INTELBROKENBUFFERSTORAGE) && type == GL_ELEMENT_ARRAY_BUFFER))
return new BufferStorage(type, size); return std::make_unique<BufferStorage>(type, size);
// don't fall back to MapAnd* for Nvidia drivers // don't fall back to MapAnd* for Nvidia drivers
if (DriverDetails::HasBug(DriverDetails::BUG_BROKENUNSYNCMAPPING)) if (DriverDetails::HasBug(DriverDetails::BUG_BROKENUNSYNCMAPPING))
return new BufferSubData(type, size); return std::make_unique<BufferSubData>(type, size);
// mapping fallback // mapping fallback
if (g_ogl_config.bSupportsGLSync) if (g_ogl_config.bSupportsGLSync)
return new MapAndSync(type, size); return std::make_unique<MapAndSync>(type, size);
} }
// default fallback, should work everywhere, but isn't the best way to do this job // default fallback, should work everywhere, but isn't the best way to do this job
return new MapAndOrphan(type, size); return std::make_unique<MapAndOrphan>(type, size);
} }
} }

View File

@ -5,6 +5,7 @@
#pragma once #pragma once
#include <array> #include <array>
#include <memory>
#include <utility> #include <utility>
#include "Common/GL/GLUtil.h" #include "Common/GL/GLUtil.h"
@ -20,7 +21,7 @@ class StreamBuffer
{ {
public: public:
static StreamBuffer* Create(u32 type, u32 size); static std::unique_ptr<StreamBuffer> Create(u32 type, u32 size);
virtual ~StreamBuffer(); virtual ~StreamBuffer();
/* This mapping function will return a pair of: /* This mapping function will return a pair of:

View File

@ -5,6 +5,7 @@
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <fstream> #include <fstream>
#include <memory>
#include <vector> #include <vector>
#include "Common/Common.h" #include "Common/Common.h"
@ -51,7 +52,7 @@ static u32 s_Textures[8];
static u32 s_ActiveTexture; static u32 s_ActiveTexture;
static SHADER s_palette_pixel_shader[3]; static SHADER s_palette_pixel_shader[3];
static StreamBuffer* s_palette_stream_buffer = nullptr; static std::unique_ptr<StreamBuffer> s_palette_stream_buffer;
static GLuint s_palette_resolv_texture; static GLuint s_palette_resolv_texture;
static GLuint s_palette_buffer_offset_uniform[3]; static GLuint s_palette_buffer_offset_uniform[3];
static GLuint s_palette_multiplier_uniform[3]; static GLuint s_palette_multiplier_uniform[3];
@ -318,8 +319,7 @@ TextureCache::~TextureCache()
if (g_ActiveConfig.backend_info.bSupportsPaletteConversion) if (g_ActiveConfig.backend_info.bSupportsPaletteConversion)
{ {
delete s_palette_stream_buffer; s_palette_stream_buffer.reset();
s_palette_stream_buffer = nullptr;
glDeleteTextures(1, &s_palette_resolv_texture); glDeleteTextures(1, &s_palette_resolv_texture);
} }
} }

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <fstream> #include <fstream>
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
@ -36,8 +37,8 @@ namespace OGL
const u32 MAX_IBUFFER_SIZE = 2*1024*1024; const u32 MAX_IBUFFER_SIZE = 2*1024*1024;
const u32 MAX_VBUFFER_SIZE = 32*1024*1024; const u32 MAX_VBUFFER_SIZE = 32*1024*1024;
static StreamBuffer *s_vertexBuffer; static std::unique_ptr<StreamBuffer> s_vertexBuffer;
static StreamBuffer *s_indexBuffer; static std::unique_ptr<StreamBuffer> s_indexBuffer;
static size_t s_baseVertex; static size_t s_baseVertex;
static size_t s_index_offset; static size_t s_index_offset;
@ -65,8 +66,8 @@ void VertexManager::CreateDeviceObjects()
void VertexManager::DestroyDeviceObjects() void VertexManager::DestroyDeviceObjects()
{ {
delete s_vertexBuffer; s_vertexBuffer.reset();
delete s_indexBuffer; s_indexBuffer.reset();
} }
void VertexManager::PrepareDrawBuffers(u32 stride) void VertexManager::PrepareDrawBuffers(u32 stride)