Replce GPUObjectWrapper by public const member

This commit is contained in:
Atlante45 2016-01-13 14:55:49 -08:00
parent 504939f193
commit ef5af45acd
9 changed files with 30 additions and 19 deletions

View file

@ -98,13 +98,13 @@ public:
}; };
template<typename T> template<typename T, typename U>
static void setGPUObject(const GPUObjectWrapper& wrapper, T* object) { static void setGPUObject(const U& object, T* gpuObject) {
wrapper.setGPUObject(object); object.gpuObject.setGPUObject(gpuObject);
} }
template<typename T> template<typename T, typename U>
static T* getGPUObject(const GPUObjectWrapper& wrapper) { static T* getGPUObject(const U& object) {
return reinterpret_cast<T*>(wrapper.getGPUObject()); return reinterpret_cast<T*>(object.gpuObject.getGPUObject());
} }

View file

@ -25,15 +25,12 @@ public:
virtual ~GPUObject() = default; virtual ~GPUObject() = default;
}; };
class GPUObjectWrapper { class GPUObjectPointer {
public:
virtual ~GPUObjectWrapper() = default;
private: private:
using GPUObjectPointer = std::unique_ptr<GPUObject>; using GPUObjectUniquePointer = 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.
mutable GPUObjectPointer _gpuObject; mutable GPUObjectUniquePointer _gpuObject;
void setGPUObject(GPUObject* gpuObject) const { _gpuObject.reset(gpuObject); } void setGPUObject(GPUObject* gpuObject) const { _gpuObject.reset(gpuObject); }
GPUObject* getGPUObject() const { return _gpuObject.get(); } GPUObject* getGPUObject() const { return _gpuObject.get(); }

View file

@ -64,7 +64,7 @@ protected:
typedef std::shared_ptr<Swapchain> SwapchainPointer; typedef std::shared_ptr<Swapchain> SwapchainPointer;
class Framebuffer : public GPUObjectWrapper { class Framebuffer {
public: public:
enum BufferMask { enum BufferMask {
BUFFER_COLOR0 = 1, BUFFER_COLOR0 = 1,
@ -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;

View file

@ -20,7 +20,7 @@
namespace gpu { namespace gpu {
class Pipeline : public GPUObjectWrapper { class Pipeline {
public: public:
using Pointer = std::shared_ptr< Pipeline >; using Pointer = std::shared_ptr< Pipeline >;
@ -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;

View file

@ -19,7 +19,7 @@
namespace gpu { namespace gpu {
class Query : public GPUObjectWrapper { class Query {
public: public:
Query(); Query();
~Query(); ~Query();
@ -27,6 +27,8 @@ namespace gpu {
uint32 queryResult; uint32 queryResult;
double getElapsedTime(); double getElapsedTime();
const GPUObjectPointer gpuObject {};
}; };
typedef std::shared_ptr<Query> QueryPointer; typedef std::shared_ptr<Query> QueryPointer;

View file

@ -108,7 +108,7 @@ protected:
}; };
class Buffer : public Resource, public GPUObjectWrapper { class Buffer : public Resource {
public: public:
Buffer(); Buffer();
@ -153,6 +153,8 @@ 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;

View file

@ -20,7 +20,7 @@
namespace gpu { namespace gpu {
class Shader : public GPUObjectWrapper { class Shader {
public: public:
typedef std::shared_ptr< Shader > Pointer; typedef std::shared_ptr< Shader > Pointer;
@ -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);

View file

@ -36,7 +36,7 @@ namespace gpu {
class GPUObject; class GPUObject;
class State : public GPUObjectWrapper { class State {
public: public:
State(); State();
virtual ~State(); virtual ~State();
@ -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);

View file

@ -136,7 +136,7 @@ protected:
Desc _desc; Desc _desc;
}; };
class Texture : public Resource, public GPUObjectWrapper { class Texture : public Resource {
public: public:
class Pixels { class Pixels {
@ -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;