Merge pull request #3380 from lioncash/fb

FramebufferManager: Get rid of raw new and delete
This commit is contained in:
Scott Mansell 2015-12-23 12:16:28 +13:00
commit 14e976a5f1
2 changed files with 17 additions and 15 deletions

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included.
#include <memory>
#include <vector>
#include "Common/Common.h"
#include "Common/CommonFuncs.h"
@ -26,14 +27,14 @@ int FramebufferManager::m_targetHeight;
int FramebufferManager::m_msaaSamples;
GLenum FramebufferManager::m_textureType;
GLuint* FramebufferManager::m_efbFramebuffer;
std::vector<GLuint> FramebufferManager::m_efbFramebuffer;
GLuint FramebufferManager::m_xfbFramebuffer;
GLuint FramebufferManager::m_efbColor;
GLuint FramebufferManager::m_efbDepth;
GLuint FramebufferManager::m_efbColorSwap; // for hot swap when reinterpreting EFB pixel formats
// Only used in MSAA mode.
GLuint* FramebufferManager::m_resolvedFramebuffer;
std::vector<GLuint> FramebufferManager::m_resolvedFramebuffer;
GLuint FramebufferManager::m_resolvedColorTexture;
GLuint FramebufferManager::m_resolvedDepthTexture;
@ -79,8 +80,8 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms
m_efbColorSwap = glObj[2];
m_EFBLayers = (g_ActiveConfig.iStereoMode > 0) ? 2 : 1;
m_efbFramebuffer = new GLuint[m_EFBLayers]();
m_resolvedFramebuffer = new GLuint[m_EFBLayers]();
m_efbFramebuffer.resize(m_EFBLayers);
m_resolvedFramebuffer.resize(m_EFBLayers);
// OpenGL MSAA textures are a different kind of texture type and must be allocated
// with a different function, so we create them separately.
@ -183,7 +184,7 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms
glTexImage3D(resolvedType, 0, GL_DEPTH_COMPONENT32F, m_targetWidth, m_targetHeight, m_EFBLayers, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
// Bind resolved textures to resolved framebuffer.
glGenFramebuffers(m_EFBLayers, m_resolvedFramebuffer);
glGenFramebuffers(m_EFBLayers, m_resolvedFramebuffer.data());
glBindFramebuffer(GL_FRAMEBUFFER, m_resolvedFramebuffer[0]);
FramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, resolvedType, m_resolvedColorTexture, 0);
FramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, resolvedType, m_resolvedDepthTexture, 0);
@ -201,7 +202,7 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms
glGenFramebuffers(1, &m_xfbFramebuffer);
// Bind target textures to EFB framebuffer.
glGenFramebuffers(m_EFBLayers, m_efbFramebuffer);
glGenFramebuffers(m_EFBLayers, m_efbFramebuffer.data());
glBindFramebuffer(GL_FRAMEBUFFER, m_efbFramebuffer[0]);
FramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_textureType, m_efbColor, 0);
FramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_textureType, m_efbDepth, 0);
@ -414,12 +415,12 @@ FramebufferManager::~FramebufferManager()
// Note: OpenGL deletion functions silently ignore parameters of "0".
glDeleteFramebuffers(m_EFBLayers, m_efbFramebuffer);
glDeleteFramebuffers(m_EFBLayers, m_resolvedFramebuffer);
delete [] m_efbFramebuffer;
delete [] m_resolvedFramebuffer;
m_efbFramebuffer = nullptr;
m_resolvedFramebuffer = nullptr;
glDeleteFramebuffers(m_EFBLayers, m_efbFramebuffer.data());
glDeleteFramebuffers(m_EFBLayers, m_resolvedFramebuffer.data());
// Required, as these are static class members
m_efbFramebuffer.clear();
m_resolvedFramebuffer.clear();
glDeleteFramebuffers(1, &m_xfbFramebuffer);
m_xfbFramebuffer = 0;

View File

@ -5,6 +5,7 @@
#pragma once
#include <memory>
#include <vector>
#include "Common/GL/GLUtil.h"
#include "VideoBackends/OGL/ProgramShaderCache.h"
@ -69,7 +70,7 @@ public:
static GLuint GetEFBColorTexture(const EFBRectangle& sourceRc);
static GLuint GetEFBDepthTexture(const EFBRectangle& sourceRc);
static GLuint GetEFBFramebuffer(unsigned int layer = 0) { return (layer < m_EFBLayers) ? m_efbFramebuffer[layer] : m_efbFramebuffer[m_EFBLayers - 1]; }
static GLuint GetEFBFramebuffer(unsigned int layer = 0) { return (layer < m_EFBLayers) ? m_efbFramebuffer[layer] : m_efbFramebuffer.back(); }
static GLuint GetXFBFramebuffer() { return m_xfbFramebuffer; }
// Resolved framebuffer is only used in MSAA mode.
@ -105,14 +106,14 @@ private:
static int m_msaaSamples;
static GLenum m_textureType;
static GLuint* m_efbFramebuffer;
static std::vector<GLuint> m_efbFramebuffer;
static GLuint m_xfbFramebuffer;
static GLuint m_efbColor;
static GLuint m_efbDepth;
static GLuint m_efbColorSwap;// will be hot swapped with m_efbColor when reinterpreting EFB pixel formats
// Only used in MSAA mode, TODO: try to avoid them
static GLuint* m_resolvedFramebuffer;
static std::vector<GLuint> m_resolvedFramebuffer;
static GLuint m_resolvedColorTexture;
static GLuint m_resolvedDepthTexture;