mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 14:18:24 +02:00
Merge pull request #6829 from Atlante45/render-shape-update
Fix render engine memory leak
This commit is contained in:
commit
1a2764a38c
10 changed files with 41 additions and 117 deletions
|
@ -97,68 +97,16 @@ public:
|
||||||
TransformCamera getEyeCamera(int eye, const StereoState& stereo) const;
|
TransformCamera getEyeCamera(int eye, const StereoState& stereo) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename T >
|
|
||||||
static void setGPUObject(const Buffer& buffer, T* object) {
|
template<typename T, typename U>
|
||||||
buffer.setGPUObject(object);
|
static void setGPUObject(const U& object, T* gpuObject) {
|
||||||
|
object.gpuObject.setGPUObject(gpuObject);
|
||||||
}
|
}
|
||||||
template< typename T >
|
template<typename T, typename U>
|
||||||
static T* getGPUObject(const Buffer& buffer) {
|
static T* getGPUObject(const U& object) {
|
||||||
return reinterpret_cast<T*>(buffer.getGPUObject());
|
return reinterpret_cast<T*>(object.gpuObject.getGPUObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
template< typename T >
|
|
||||||
static void setGPUObject(const Texture& texture, T* object) {
|
|
||||||
texture.setGPUObject(object);
|
|
||||||
}
|
|
||||||
template< typename T >
|
|
||||||
static T* getGPUObject(const Texture& texture) {
|
|
||||||
return reinterpret_cast<T*>(texture.getGPUObject());
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename T >
|
|
||||||
static void setGPUObject(const Shader& shader, T* object) {
|
|
||||||
shader.setGPUObject(object);
|
|
||||||
}
|
|
||||||
template< typename T >
|
|
||||||
static T* getGPUObject(const Shader& shader) {
|
|
||||||
return reinterpret_cast<T*>(shader.getGPUObject());
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename T >
|
|
||||||
static void setGPUObject(const Pipeline& pipeline, T* object) {
|
|
||||||
pipeline.setGPUObject(object);
|
|
||||||
}
|
|
||||||
template< typename T >
|
|
||||||
static T* getGPUObject(const Pipeline& pipeline) {
|
|
||||||
return reinterpret_cast<T*>(pipeline.getGPUObject());
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename T >
|
|
||||||
static void setGPUObject(const State& state, T* object) {
|
|
||||||
state.setGPUObject(object);
|
|
||||||
}
|
|
||||||
template< typename T >
|
|
||||||
static T* getGPUObject(const State& state) {
|
|
||||||
return reinterpret_cast<T*>(state.getGPUObject());
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename T >
|
|
||||||
static void setGPUObject(const Framebuffer& framebuffer, T* object) {
|
|
||||||
framebuffer.setGPUObject(object);
|
|
||||||
}
|
|
||||||
template< typename T >
|
|
||||||
static T* getGPUObject(const Framebuffer& framebuffer) {
|
|
||||||
return reinterpret_cast<T*>(framebuffer.getGPUObject());
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename T >
|
|
||||||
static void setGPUObject(const Query& query, T* object) {
|
|
||||||
query.setGPUObject(object);
|
|
||||||
}
|
|
||||||
template< typename T >
|
|
||||||
static T* getGPUObject(const Query& query) {
|
|
||||||
return reinterpret_cast<T*>(query.getGPUObject());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
StereoState _stereo;
|
StereoState _stereo;
|
||||||
|
|
|
@ -11,15 +11,30 @@
|
||||||
#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 {
|
||||||
|
|
||||||
|
class Backend;
|
||||||
|
|
||||||
class GPUObject {
|
class GPUObject {
|
||||||
public:
|
public:
|
||||||
GPUObject() {}
|
virtual ~GPUObject() = default;
|
||||||
virtual ~GPUObject() {}
|
};
|
||||||
|
|
||||||
|
class GPUObjectPointer {
|
||||||
|
private:
|
||||||
|
using GPUObjectUniquePointer = std::unique_ptr<GPUObject>;
|
||||||
|
|
||||||
|
// This shouldn't be used by anything else than the Backend class with the proper casting.
|
||||||
|
mutable GPUObjectUniquePointer _gpuObject;
|
||||||
|
void setGPUObject(GPUObject* gpuObject) const { _gpuObject.reset(gpuObject); }
|
||||||
|
GPUObject* getGPUObject() const { return _gpuObject.get(); }
|
||||||
|
|
||||||
|
friend class Backend;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef int Stamp;
|
typedef int Stamp;
|
||||||
|
|
|
@ -134,6 +134,8 @@ public:
|
||||||
static const uint32 MAX_NUM_RENDER_BUFFERS = 8;
|
static const uint32 MAX_NUM_RENDER_BUFFERS = 8;
|
||||||
static uint32 getMaxNumRenderBuffers() { return MAX_NUM_RENDER_BUFFERS; }
|
static uint32 getMaxNumRenderBuffers() { return MAX_NUM_RENDER_BUFFERS; }
|
||||||
|
|
||||||
|
const GPUObjectPointer gpuObject {};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
SwapchainPointer _swapchain;
|
SwapchainPointer _swapchain;
|
||||||
|
|
||||||
|
@ -153,12 +155,6 @@ protected:
|
||||||
// Non exposed
|
// Non exposed
|
||||||
Framebuffer(const Framebuffer& framebuffer) = delete;
|
Framebuffer(const Framebuffer& framebuffer) = delete;
|
||||||
Framebuffer() {}
|
Framebuffer() {}
|
||||||
|
|
||||||
// This shouldn't be used by anything else than the Backend class with the proper casting.
|
|
||||||
mutable GPUObject* _gpuObject = NULL;
|
|
||||||
void setGPUObject(GPUObject* gpuObject) const { _gpuObject = gpuObject; }
|
|
||||||
GPUObject* getGPUObject() const { return _gpuObject; }
|
|
||||||
friend class Backend;
|
|
||||||
};
|
};
|
||||||
typedef std::shared_ptr<Framebuffer> FramebufferPointer;
|
typedef std::shared_ptr<Framebuffer> FramebufferPointer;
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,8 @@ public:
|
||||||
|
|
||||||
const StatePointer& getState() const { return _state; }
|
const StatePointer& getState() const { return _state; }
|
||||||
|
|
||||||
|
const GPUObjectPointer gpuObject {};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ShaderPointer _program;
|
ShaderPointer _program;
|
||||||
StatePointer _state;
|
StatePointer _state;
|
||||||
|
@ -38,12 +40,6 @@ protected:
|
||||||
Pipeline();
|
Pipeline();
|
||||||
Pipeline(const Pipeline& pipeline); // deep copy of the sysmem shader
|
Pipeline(const Pipeline& pipeline); // deep copy of the sysmem shader
|
||||||
Pipeline& operator=(const Pipeline& pipeline); // deep copy of the sysmem texture
|
Pipeline& operator=(const Pipeline& pipeline); // deep copy of the sysmem texture
|
||||||
|
|
||||||
// This shouldn't be used by anything else than the Backend class with the proper casting.
|
|
||||||
mutable GPUObject* _gpuObject = nullptr;
|
|
||||||
void setGPUObject(GPUObject* gpuObject) const { _gpuObject = gpuObject; }
|
|
||||||
GPUObject* getGPUObject() const { return _gpuObject; }
|
|
||||||
friend class Backend;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Pipeline::Pointer PipelinePointer;
|
typedef Pipeline::Pointer PipelinePointer;
|
||||||
|
|
|
@ -28,13 +28,7 @@ namespace gpu {
|
||||||
|
|
||||||
double getElapsedTime();
|
double getElapsedTime();
|
||||||
|
|
||||||
protected:
|
const GPUObjectPointer gpuObject {};
|
||||||
|
|
||||||
// This shouldn't be used by anything else than the Backend class with the proper casting.
|
|
||||||
mutable GPUObject* _gpuObject = NULL;
|
|
||||||
void setGPUObject(GPUObject* gpuObject) const { _gpuObject = gpuObject; }
|
|
||||||
GPUObject* getGPUObject() const { return _gpuObject; }
|
|
||||||
friend class Backend;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<Query> QueryPointer;
|
typedef std::shared_ptr<Query> QueryPointer;
|
||||||
|
|
|
@ -170,20 +170,17 @@ Resource::Size Resource::Sysmem::append(Size size, const Byte* bytes) {
|
||||||
|
|
||||||
Buffer::Buffer() :
|
Buffer::Buffer() :
|
||||||
Resource(),
|
Resource(),
|
||||||
_sysmem(new Sysmem()),
|
_sysmem(new Sysmem()) {
|
||||||
_gpuObject(NULL) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer::Buffer(Size size, const Byte* bytes) :
|
Buffer::Buffer(Size size, const Byte* bytes) :
|
||||||
Resource(),
|
Resource(),
|
||||||
_sysmem(new Sysmem(size, bytes)),
|
_sysmem(new Sysmem(size, bytes)) {
|
||||||
_gpuObject(NULL) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer::Buffer(const Buffer& buf) :
|
Buffer::Buffer(const Buffer& buf) :
|
||||||
Resource(),
|
Resource(),
|
||||||
_sysmem(new Sysmem(buf.getSysmem())),
|
_sysmem(new Sysmem(buf.getSysmem())) {
|
||||||
_gpuObject(NULL) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer& Buffer::operator=(const Buffer& buf) {
|
Buffer& Buffer::operator=(const Buffer& buf) {
|
||||||
|
@ -196,10 +193,6 @@ Buffer::~Buffer() {
|
||||||
delete _sysmem;
|
delete _sysmem;
|
||||||
_sysmem = NULL;
|
_sysmem = NULL;
|
||||||
}
|
}
|
||||||
if (_gpuObject) {
|
|
||||||
delete _gpuObject;
|
|
||||||
_gpuObject = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer::Size Buffer::resize(Size size) {
|
Buffer::Size Buffer::resize(Size size) {
|
||||||
|
|
|
@ -153,16 +153,11 @@ public:
|
||||||
const Sysmem& getSysmem() const { assert(_sysmem); return (*_sysmem); }
|
const Sysmem& getSysmem() const { assert(_sysmem); return (*_sysmem); }
|
||||||
Sysmem& editSysmem() { assert(_sysmem); return (*_sysmem); }
|
Sysmem& editSysmem() { assert(_sysmem); return (*_sysmem); }
|
||||||
|
|
||||||
|
const GPUObjectPointer gpuObject {};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
Sysmem* _sysmem = NULL;
|
Sysmem* _sysmem = NULL;
|
||||||
|
|
||||||
|
|
||||||
// This shouldn't be used by anything else than the Backend class with the proper casting.
|
|
||||||
mutable GPUObject* _gpuObject = NULL;
|
|
||||||
void setGPUObject(GPUObject* gpuObject) const { _gpuObject = gpuObject; }
|
|
||||||
GPUObject* getGPUObject() const { return _gpuObject; }
|
|
||||||
friend class Backend;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<Buffer> BufferPointer;
|
typedef std::shared_ptr<Buffer> BufferPointer;
|
||||||
|
|
|
@ -155,6 +155,8 @@ public:
|
||||||
// independant of the graphics api in use underneath (looking at you opengl & vulkan).
|
// independant of the graphics api in use underneath (looking at you opengl & vulkan).
|
||||||
static bool makeProgram(Shader& shader, const Shader::BindingSet& bindings = Shader::BindingSet());
|
static bool makeProgram(Shader& shader, const Shader::BindingSet& bindings = Shader::BindingSet());
|
||||||
|
|
||||||
|
const GPUObjectPointer gpuObject {};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Shader(Type type, const Source& source);
|
Shader(Type type, const Source& source);
|
||||||
Shader(Type type, const Pointer& vertex, const Pointer& pixel);
|
Shader(Type type, const Pointer& vertex, const Pointer& pixel);
|
||||||
|
@ -178,12 +180,6 @@ protected:
|
||||||
|
|
||||||
// The type of the shader, the master key
|
// The type of the shader, the master key
|
||||||
Type _type;
|
Type _type;
|
||||||
|
|
||||||
// This shouldn't be used by anything else than the Backend class with the proper casting.
|
|
||||||
mutable GPUObject* _gpuObject = NULL;
|
|
||||||
void setGPUObject(GPUObject* gpuObject) const { _gpuObject = gpuObject; }
|
|
||||||
GPUObject* getGPUObject() const { return _gpuObject; }
|
|
||||||
friend class Backend;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Shader::Pointer ShaderPointer;
|
typedef Shader::Pointer ShaderPointer;
|
||||||
|
|
|
@ -385,6 +385,8 @@ public:
|
||||||
State(const Data& values);
|
State(const Data& values);
|
||||||
const Data& getValues() const { return _values; }
|
const Data& getValues() const { return _values; }
|
||||||
|
|
||||||
|
const GPUObjectPointer gpuObject {};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
State(const State& state);
|
State(const State& state);
|
||||||
State& operator=(const State& state);
|
State& operator=(const State& state);
|
||||||
|
@ -392,12 +394,6 @@ protected:
|
||||||
Data _values;
|
Data _values;
|
||||||
Signature _signature{0};
|
Signature _signature{0};
|
||||||
Stamp _stamp{0};
|
Stamp _stamp{0};
|
||||||
|
|
||||||
// This shouldn't be used by anything else than the Backend class with the proper casting.
|
|
||||||
mutable GPUObject* _gpuObject = nullptr;
|
|
||||||
void setGPUObject(GPUObject* gpuObject) const { _gpuObject = gpuObject; }
|
|
||||||
GPUObject* getGPUObject() const { return _gpuObject; }
|
|
||||||
friend class Backend;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr< State > StatePointer;
|
typedef std::shared_ptr< State > StatePointer;
|
||||||
|
|
|
@ -356,6 +356,8 @@ public:
|
||||||
// Only callable by the Backend
|
// Only callable by the Backend
|
||||||
void notifyMipFaceGPULoaded(uint16 level, uint8 face) const { return _storage->notifyMipFaceGPULoaded(level, face); }
|
void notifyMipFaceGPULoaded(uint16 level, uint8 face) const { return _storage->notifyMipFaceGPULoaded(level, face); }
|
||||||
|
|
||||||
|
const GPUObjectPointer gpuObject {};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::unique_ptr< Storage > _storage;
|
std::unique_ptr< Storage > _storage;
|
||||||
|
|
||||||
|
@ -386,13 +388,6 @@ protected:
|
||||||
static Texture* create(Type type, const Element& texelFormat, uint16 width, uint16 height, uint16 depth, uint16 numSamples, uint16 numSlices, const Sampler& sampler);
|
static Texture* create(Type type, const Element& texelFormat, uint16 width, uint16 height, uint16 depth, uint16 numSamples, uint16 numSlices, const Sampler& sampler);
|
||||||
|
|
||||||
Size resize(Type type, const Element& texelFormat, uint16 width, uint16 height, uint16 depth, uint16 numSamples, uint16 numSlices);
|
Size resize(Type type, const Element& texelFormat, uint16 width, uint16 height, uint16 depth, uint16 numSamples, uint16 numSlices);
|
||||||
|
|
||||||
// This shouldn't be used by anything else than the Backend class with the proper casting.
|
|
||||||
mutable GPUObject* _gpuObject = NULL;
|
|
||||||
void setGPUObject(GPUObject* gpuObject) const { _gpuObject = gpuObject; }
|
|
||||||
GPUObject* getGPUObject() const { return _gpuObject; }
|
|
||||||
|
|
||||||
friend class Backend;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<Texture> TexturePointer;
|
typedef std::shared_ptr<Texture> TexturePointer;
|
||||||
|
|
Loading…
Reference in a new issue