Use a unique_ptr to track gpu objects

This commit is contained in:
Atlante45 2016-01-13 14:07:48 -08:00
parent 8da027c56f
commit 504939f193

View file

@ -11,8 +11,10 @@
#ifndef hifi_gpu_Format_h #ifndef hifi_gpu_Format_h
#define hifi_gpu_Format_h #define hifi_gpu_Format_h
#include <glm/glm.hpp>
#include <assert.h> #include <assert.h>
#include <memory>
#include <glm/glm.hpp>
namespace gpu { namespace gpu {
@ -25,14 +27,15 @@ public:
class GPUObjectWrapper { class GPUObjectWrapper {
public: public:
virtual ~GPUObjectWrapper() { delete _gpuObject; } virtual ~GPUObjectWrapper() = default;
private: private:
using GPUObjectPointer = std::unique_ptr<GPUObject>;
// This shouldn't be used by anything else than the Backend class with the proper casting. // This shouldn't be used by anything else than the Backend class with the proper casting.
// TODO: Consider using std::unique_ptr to get rid of dtor and ensure correct destruction of GPU objects mutable GPUObjectPointer _gpuObject;
mutable GPUObject* _gpuObject { nullptr }; void setGPUObject(GPUObject* gpuObject) const { _gpuObject.reset(gpuObject); }
void setGPUObject(GPUObject* gpuObject) const { _gpuObject = gpuObject; } GPUObject* getGPUObject() const { return _gpuObject.get(); }
GPUObject* getGPUObject() const { return _gpuObject; }
friend class Backend; friend class Backend;
}; };