GL::SequenceBuilder seq_bld(resources.get<GL::SequenceTemplate>("Desert.seq"));
seq_bld.set_renderable("content", content);
seq_bld.set_debug_name("Main sequence");
- sequence.reset(seq_bld.build(view));
+ sequence = seq_bld.build(view);
GL::SequenceBuilder env_bld(resources.get<GL::SequenceTemplate>("Desert_environment.seq"));
env_bld.set_renderable("content", *sequence->get_steps().front().get_renderable());
env_bld.set_debug_name("Environment sequence");
- env_seq.reset(env_bld.build());
+ env_seq = env_bld.build();
env_map = make_unique<GL::EnvironmentMap>(256, GL::RGBA16F, 7, sphere, *env_seq);
env_map->set_debug_name("Environment map");
GL::SequenceBuilder seq_bld(resources.get<GL::SequenceTemplate>("Forest.seq"));
seq_bld.set_debug_name("Main sequence");
seq_bld.set_renderable("content", content);
- sequence.reset(seq_bld.build(view));
+ sequence = seq_bld.build(view);
GL::SequenceBuilder env_bld(resources.get<GL::SequenceTemplate>("Forest_environment.seq"));
env_bld.set_debug_name("Environment sequence");
env_bld.set_renderable("content", *sequence->get_steps().front().get_renderable());
- env_seq.reset(env_bld.build());
+ env_seq = env_bld.build();
env_map = std::make_unique<GL::EnvironmentMap>(512, GL::RGBA16F, 5, water, *env_seq);
env_map->set_debug_name("Water environment");
namespace Msp {
namespace GL {
-Animation::~Animation()
-{
- for(TimedKeyFrame &k: keyframes)
- if(k.owned)
- delete k.keyframe;
- for(Curve *c: curves)
- delete c;
-}
-
void Animation::set_armature(const Armature &a)
{
if(!keyframes.empty() && &a!=armature)
create_curves();
}
-void Animation::add_keyframe_owned(const Time::TimeDelta &t, const KeyFrame *kf)
+void Animation::add_keyframe(const Time::TimeDelta &t, unique_ptr<KeyFrame> kf)
{
- add_keyframe(t, kf, false, true);
+ add_keyframe(t, kf.get(), false, true);
+ owned_keyframes.emplace_back(move(kf));
create_curves();
}
void Animation::add_keyframe(const Time::TimeDelta &t, const KeyFrame &kf, float slope)
{
- add_keyframe(t, &kf, slope, slope, false);
+ add_keyframe(t, &kf, slope, slope);
create_curves();
}
void Animation::add_keyframe(const Time::TimeDelta &t, const KeyFrame &kf, float ss, float es)
{
- add_keyframe(t, &kf, ss, es, false);
+ add_keyframe(t, &kf, ss, es);
create_curves();
}
add_keyframe(keyframes.back().time, &kf, true, false);
}
-void Animation::add_control_keyframe_owned(const KeyFrame *kf)
+void Animation::add_control_keyframe(unique_ptr<KeyFrame> kf)
{
if(keyframes.empty())
throw invalid_operation("Animation::add_control_keyframe_owned");
- add_keyframe(keyframes.back().time, kf, true, true);
+ add_keyframe(keyframes.back().time, kf.get(), true, true);
+ owned_keyframes.emplace_back(move(kf));
}
-void Animation::add_keyframe(const Time::TimeDelta &t, const KeyFrame *kf, float ss, float es, bool owned)
+void Animation::add_keyframe(const Time::TimeDelta &t, const KeyFrame *kf, float ss, float es)
{
if(keyframes.empty())
- return add_keyframe(t, kf, false, owned);
+ return add_keyframe(t, kf, false);
if(keyframes.back().control)
throw invalid_operation("Animation::add_keyframe");
for(unsigned i=1; i<=2; ++i)
{
float x = (i==1 ? ss/3 : 1-es/3);
- KeyFrame *ckf = new KeyFrame;
+ unique_ptr<KeyFrame> ckf = make_unique<KeyFrame>();
Transform ctrn;
ctrn.set_position(last_trn.get_position()*(1-x)+trn.get_position()*x);
const Transform::AngleVector3 &e1 = last_trn.get_euler();
ckf->set_uniform(kvp.first, uni);
}
- add_keyframe(t, ckf, true, true);
+ add_keyframe(t, ckf.get(), true);
+ owned_keyframes.emplace_back(move(ckf));
}
- add_keyframe(t, kf, false, owned);
+ add_keyframe(t, kf, false);
}
-void Animation::add_keyframe(const Time::TimeDelta &t, const KeyFrame *kf, bool c, bool owned)
+void Animation::add_keyframe(const Time::TimeDelta &t, const KeyFrame *kf, bool c)
{
if(c && keyframes.empty())
throw invalid_argument("Animation::add_keyframe");
tkf.time = t;
tkf.keyframe = kf;
tkf.control = c;
- tkf.owned = owned;
keyframes.push_back(tkf);
void Animation::create_curves()
{
- for(Curve *c: curves)
- delete c;
curves.clear();
curves.reserve(6+uniforms.size());
knots.push_back(knots.back());
}
- curves.push_back(new ValueCurve<N>(target, component, knots));
+ curves.emplace_back(make_unique<ValueCurve<N>>(target, component, knots));
}
bool Animation::extract_position(const KeyFrame &kf, Vector3 &value)
throw logic_error("can't use both slopes and control keyframes in same segment");
}
-void Animation::Loader::add_kf(const KeyFrame *kf, bool c, bool owned)
+void Animation::Loader::add_kf(const KeyFrame *kf, bool c)
{
if(slopes_set && !c)
- obj.add_keyframe(current_time, kf, start_slope, end_slope, owned);
+ obj.add_keyframe(current_time, kf, start_slope, end_slope);
else
- obj.add_keyframe(current_time, kf, c, owned);
+ obj.add_keyframe(current_time, kf, c);
start_slope = end_slope;
end_slope = 1;
void Animation::Loader::load_kf(const string &n, bool c)
{
- add_kf(&get_collection().get<KeyFrame>(n), c, false);
+ add_kf(&get_collection().get<KeyFrame>(n), c);
}
void Animation::Loader::load_kf_inline(bool c)
{
- RefPtr<KeyFrame> kf = new KeyFrame;
+ unique_ptr<KeyFrame> kf = make_unique<KeyFrame>();
if(coll)
{
KeyFrame::Loader ldr(*kf, get_collection());
else
load_sub(*kf);
- add_kf(kf.get(), c, true);
- kf.release();
+ add_kf(kf.get(), c);
+ obj.owned_keyframes.emplace_back(move(kf));
}
void Animation::Loader::control_keyframe(const string &n)
#ifndef MSP_GL_ANIMATION_H_
#define MSP_GL_ANIMATION_H_
-#include <msp/core/refptr.h>
+#include <memory>
#include <msp/datafile/objectloader.h>
#include <msp/interpolate/spline.h>
#include <msp/time/timedelta.h>
void finish() override;
void check_slopes_and_control(bool, bool);
- void add_kf(const KeyFrame *, bool, bool);
+ void add_kf(const KeyFrame *, bool);
void load_kf(const std::string &, bool);
void load_kf_inline(bool);
Time::TimeDelta time;
const KeyFrame *keyframe;
bool control;
- bool owned;
};
struct Event
private:
const Armature *armature = nullptr;
std::vector<TimedKeyFrame> keyframes;
+ std::vector<std::unique_ptr<KeyFrame>> owned_keyframes;
std::vector<Event> events;
bool looping = false;
std::vector<UniformInfo> uniforms;
- std::vector<Curve *> curves;
+ std::vector<std::unique_ptr<Curve>> curves;
unsigned uniform_curve_offset = 0;
public:
- ~Animation();
-
void set_armature(const Armature &);
const Armature *get_armature() const { return armature; }
const std::string &get_uniform_name(unsigned) const;
void add_keyframe(const Time::TimeDelta &, const KeyFrame &);
- void add_keyframe_owned(const Time::TimeDelta &, const KeyFrame *);
+ void add_keyframe(const Time::TimeDelta &, std::unique_ptr<KeyFrame>);
DEPRECATED void add_keyframe(const Time::TimeDelta &, const KeyFrame &, float);
DEPRECATED void add_keyframe(const Time::TimeDelta &, const KeyFrame &, float, float);
void add_control_keyframe(const KeyFrame &);
- void add_control_keyframe_owned(const KeyFrame *);
+ void add_control_keyframe(std::unique_ptr<KeyFrame>);
private:
- void add_keyframe(const Time::TimeDelta &, const KeyFrame *, float, float, bool);
- void add_keyframe(const Time::TimeDelta &, const KeyFrame *, bool, bool);
+ void add_keyframe(const Time::TimeDelta &, const KeyFrame *, float, float);
+ void add_keyframe(const Time::TimeDelta &, const KeyFrame *, bool);
void prepare_keyframe(TimedKeyFrame &);
void create_curves();
void create_curve(CurveTarget, Transform::ComponentMask, ExtractComponent::Extract);
void KeyFrame::Loader::pose_inline()
{
- RefPtr<Pose> p = new Pose;
+ unique_ptr<Pose> p = make_unique<Pose>();
load_sub(*p, get_collection());
- get_collection().add((inline_base_name.empty() ? FS::basename(get_source()) : inline_base_name)+".pose", p.get());
- obj.pose = p.release();
+ Pose *ptr = p.get();
+ get_collection().add((inline_base_name.empty() ? FS::basename(get_source()) : inline_base_name)+".pose", move(p));
+ obj.pose = ptr;
}
void KeyFrame::Loader::position(float x, float y, float z)
#ifndef MSP_GL_KEYFRAME_H_
#define MSP_GL_KEYFRAME_H_
-#include <msp/core/refptr.h>
#include <msp/datafile/objectloader.h>
#include "matrix.h"
#include "mspgl_api.h"
void sub_image(unsigned, int, unsigned, const void *);
public:
- AsyncLoader *load(IO::Seekable &, const Resources * = nullptr) override { return nullptr; }
+ std::unique_ptr<AsyncLoader> load(IO::Seekable &, const Resources * = nullptr) override { return nullptr; }
std::size_t get_data_size() const override;
void unload() override { }
};
}
-OpenGLTexture2D::AsyncTransfer::AsyncTransfer(AsyncTransfer &&other):
- pixel_buffer(other.pixel_buffer)
-{
- other.pixel_buffer = nullptr;
-}
-
-OpenGLTexture2D::AsyncTransfer &OpenGLTexture2D::AsyncTransfer::operator=(AsyncTransfer &&other)
-{
- delete pixel_buffer;
- pixel_buffer = other.pixel_buffer;
- other.pixel_buffer = nullptr;
-
- return *this;
-}
-
-OpenGLTexture2D::AsyncTransfer::~AsyncTransfer()
-{
- delete pixel_buffer;
-}
-
void *OpenGLTexture2D::AsyncTransfer::allocate()
{
const Texture2D::AsyncTransfer &self = *static_cast<const Texture2D::AsyncTransfer *>(this);
- pixel_buffer = new Buffer;
+ pixel_buffer = make_unique<Buffer>();
pixel_buffer->storage(self.data_size, STREAMING);
return pixel_buffer->map();
}
#ifndef MSP_GL_TEXTURE2D_BACKEND_H_
#define MSP_GL_TEXTURE2D_BACKEND_H_
+#include <memory>
#include "mspgl_api.h"
#include "texture.h"
class MSPGL_API AsyncTransfer: public NonCopyable
{
protected:
- Buffer *pixel_buffer = nullptr;
-
- AsyncTransfer() = default;
- AsyncTransfer(AsyncTransfer &&);
- AsyncTransfer &operator=(AsyncTransfer &&);
- ~AsyncTransfer();
+ std::unique_ptr<Buffer> pixel_buffer;
void *allocate();
void finalize();
void allocate();
public:
- AsyncLoader *load(IO::Seekable &, const Resources * = nullptr) override { return nullptr; }
+ std::unique_ptr<AsyncLoader> load(IO::Seekable &, const Resources * = nullptr) override { return nullptr; }
std::size_t get_data_size() const override;
void unload() override { }
};
bool is_array() const;
public:
- AsyncLoader *load(IO::Seekable &, const Resources * = nullptr) override { return nullptr; }
+ std::unique_ptr<AsyncLoader> load(IO::Seekable &, const Resources * = nullptr) override { return nullptr; }
std::size_t get_data_size() const override;
void unload() override { }
};
void sub_image(unsigned, unsigned, int, int, unsigned, unsigned, const void *);
public:
- AsyncLoader *load(IO::Seekable &, const Resources * = nullptr) override { return nullptr; }
+ std::unique_ptr<AsyncLoader> load(IO::Seekable &, const Resources * = nullptr) override { return nullptr; }
std::size_t get_data_size() const override;
void unload() override { }
};
context(wnd, opts),
device(handle_cast<VkDevice>(context.get_private().device)),
graphics_queue(handle_cast<VkQueue>(context.get_private().graphics_queue)),
- functions(new VulkanFunctions(context)),
+ functions(make_unique<VulkanFunctions>(context)),
allocator(*static_cast<Device *>(this)),
destroy_queue(*static_cast<Device *>(this)),
synchronizer(*static_cast<Device *>(this)),
descriptor_pool(*static_cast<Device *>(this))
{ }
-// Cause the destructor of RefPtr<VulkanFunctions> to be emitted here
+// Cause the destructor of unique_ptr<VulkanFunctions> to be emitted here
VulkanDevice::~VulkanDevice()
{ }
#ifndef MSP_GL_DEVICE_BACKEND_H_
#define MSP_GL_DEVICE_BACKEND_H_
+#include <memory>
#include <msp/core/noncopyable.h>
-#include <msp/core/refptr.h>
#include <msp/graphics/vulkancontext.h>
#include "descriptorpool.h"
#include "destroyqueue.h"
Graphics::VulkanContext context;
VkDevice device;
VkQueue graphics_queue;
- RefPtr<VulkanFunctions> functions;
+ std::unique_ptr<VulkanFunctions> functions;
MemoryAllocator allocator;
DestroyQueue destroy_queue;
Synchronizer synchronizer;
#if DEBUG
if(!debug_name.empty())
- if(SpirVModule *spirv = static_cast<Program *>(this)->specialized_spirv)
+ if(SpirVModule *spirv = static_cast<Program *>(this)->specialized_spirv.get())
spirv->set_debug_name(debug_name);
#endif
}
#ifdef DEBUG
debug_name = name;
set_vulkan_object_name();
- if(SpirVModule *spirv = static_cast<Program *>(this)->specialized_spirv)
+ if(SpirVModule *spirv = static_cast<Program *>(this)->specialized_spirv.get())
spirv->set_debug_name(debug_name);
#else
(void)name;
void fill_mipmap_blit(unsigned, void *) override;
public:
- AsyncLoader *load(IO::Seekable &, const Resources * = nullptr) override { return nullptr; }
+ std::unique_ptr<AsyncLoader> load(IO::Seekable &, const Resources * = nullptr) override { return nullptr; }
std::size_t get_data_size() const override;
void unload() override { }
};
void fill_mipmap_blit(unsigned, void *) override { }
public:
- AsyncLoader *load(IO::Seekable &, const Resources * = nullptr) override { return nullptr; }
+ std::unique_ptr<AsyncLoader> load(IO::Seekable &, const Resources * = nullptr) override { return nullptr; }
std::size_t get_data_size() const override;
void unload() override { }
};
bool is_array() const;
public:
- AsyncLoader *load(IO::Seekable &, const Resources * = nullptr) override { return nullptr; }
+ std::unique_ptr<AsyncLoader> load(IO::Seekable &, const Resources * = nullptr) override { return nullptr; }
std::size_t get_data_size() const override;
void unload() override { }
};
void fill_mipmap_blit(unsigned, void *) override;
public:
- AsyncLoader *load(IO::Seekable &, const Resources * = nullptr) override { return nullptr; }
+ std::unique_ptr<AsyncLoader> load(IO::Seekable &, const Resources * = nullptr) override { return nullptr; }
std::size_t get_data_size() const override;
void unload() override { }
};
#include "windowview.h"
#include "windowview_backend.h"
+using namespace std;
+
namespace Msp {
namespace GL {
-VulkanWindowView::~VulkanWindowView()
-{
- delete swap_chain;
-}
+// Hide Semaphore destructor since it's not exported
+VulkanWindowView::~VulkanWindowView() = default;
void VulkanWindowView::render()
{
current_target = &framebuffers[image_index];
if(!internal_renderer)
- internal_renderer = new Renderer;
+ internal_renderer = make_unique<Renderer>();
internal_renderer->begin(sem[0]);
View::render(*internal_renderer);
internal_renderer->end(sem[1]);
Device &device = static_cast<const WindowView *>(this)->device;
framebuffers.clear();
- delete swap_chain;
- swap_chain = new SwapChain(w, h, device.get_n_frames_in_flight());
+ swap_chain = make_unique<SwapChain>(w, h, device.get_n_frames_in_flight());
unsigned n_images = swap_chain->get_n_images();
framebuffers.reserve(n_images);
#ifndef MSP_GL_WINDOWVIEW_BACKEND_H_
#define MSP_GL_WINDOWVIEW_BACKEND_H_
+#include <memory>
#include "device.h"
#include "framebuffer.h"
#include "mspgl_api.h"
class MSPGL_API VulkanWindowView: public View
{
protected:
- SwapChain *swap_chain = nullptr;
+ std::unique_ptr<SwapChain> swap_chain;
std::vector<Framebuffer> framebuffers;
Framebuffer *current_target = nullptr;
Semaphore semaphores[MAX_FRAMES_IN_FLIGHT*2];
void Font::Loader::texture()
{
- RefPtr<Texture2D> tex = new Texture2D;
+ unique_ptr<Texture2D> tex = make_unique<Texture2D>();
load_sub(*tex);
- get_collection().add(FS::basename(get_source())+".tex", tex.get());
- obj.texture = tex.release();
+ Texture2D *ptr = tex.get();
+ get_collection().add(FS::basename(get_source())+".tex", move(tex));
+ obj.texture = ptr;
}
void Font::Loader::texture_ref(const string &name)
void MeshBuilder::begin_()
{
- batch = new Batch(type);
+ batch = make_unique<Batch>(type);
}
void MeshBuilder::end_()
{
mesh.add_batch(move(*batch));
- delete batch;
- batch = nullptr;
+ batch.reset();
}
void MeshBuilder::element_(unsigned i)
#ifndef MSP_GL_MESHBUILDER_H_
#define MSP_GL_MESHBUILDER_H_
+#include <memory>
#include "mspgl_api.h"
#include "primitivebuilder.h"
{
private:
Mesh &mesh;
- Batch *batch = nullptr;
+ std::unique_ptr<Batch> batch;
public:
MeshBuilder(Mesh &);
}
}
-Sequence *SequenceBuilder::build() const
+std::unique_ptr<Sequence> SequenceBuilder::build() const
{
- RefPtr<Sequence> sequence = new Sequence();
+ unique_ptr<Sequence> sequence = make_unique<Sequence>();
build(*sequence);
- return sequence.release();
+ return sequence;
}
-Sequence *SequenceBuilder::build(unsigned w, unsigned h) const
+std::unique_ptr<Sequence> SequenceBuilder::build(unsigned w, unsigned h) const
{
- RefPtr<Sequence> sequence = create_sequence(w, h);
+ unique_ptr<Sequence> sequence = create_sequence(w, h);
build(*sequence);
- return sequence.release();
+ return sequence;
}
-Sequence *SequenceBuilder::build(const View &view) const
+std::unique_ptr<Sequence> SequenceBuilder::build(const View &view) const
{
- RefPtr<Sequence> sequence = create_sequence(view.get_width(), view.get_height());
+ unique_ptr<Sequence> sequence = create_sequence(view.get_width(), view.get_height());
build(*sequence);
- return sequence.release();
+ return sequence;
}
-Sequence *SequenceBuilder::build(const Framebuffer &fbo) const
+std::unique_ptr<Sequence> SequenceBuilder::build(const Framebuffer &fbo) const
{
- RefPtr<Sequence> sequence = create_sequence(fbo.get_width(), fbo.get_height());
+ unique_ptr<Sequence> sequence = create_sequence(fbo.get_width(), fbo.get_height());
build(*sequence);
- return sequence.release();
+ return sequence;
}
-Sequence * SequenceBuilder::create_sequence(unsigned w, unsigned h) const
+std::unique_ptr<Sequence> SequenceBuilder::create_sequence(unsigned w, unsigned h) const
{
if(!w || !h || tmpl.get_postprocessors().empty())
- return new Sequence;
+ return make_unique<Sequence>();
unsigned samples = min(tmpl.get_maximum_multisample(), Device::get_current().get_info().limits.max_samples);
if(samples<tmpl.get_required_multisample())
PixelFormat color_pf = make_pixelformat(RGBA, color_type);
FrameFormat format = (COLOR_ATTACHMENT,color_pf, DEPTH_ATTACHMENT).set_samples(samples);
- return new Sequence(w, h, format);
+ return make_unique<Sequence>(w, h, format);
}
} // namespace GL
#define SEQUENCEBUILDER_H_
#include <map>
+#include <memory>
#include <string>
#include "mspgl_api.h"
void set_debug_name(const std::string &);
void build(Sequence &) const;
- Sequence *build() const;
- Sequence *build(unsigned, unsigned) const;
- Sequence *build(const View &) const;
- Sequence *build(const Framebuffer &) const;
- Sequence *create_sequence(unsigned, unsigned) const;
+ std::unique_ptr<Sequence> build() const;
+ std::unique_ptr<Sequence> build(unsigned, unsigned) const;
+ std::unique_ptr<Sequence> build(const View &) const;
+ std::unique_ptr<Sequence> build(const Framebuffer &) const;
+ std::unique_ptr<Sequence> create_sequence(unsigned, unsigned) const;
};
} // namespace GL
namespace Msp {
namespace GL {
-SequenceTemplate::~SequenceTemplate()
-{
- for(const Renderable &r: renderables)
- delete r.effect_template;
- for(const PostProcessor &p: postprocessors)
- delete p.postprocessor_template;
-}
-
template<>
SequenceTemplate::TemplateRegistry<GL::PostProcessor> &SequenceTemplate::get_registry<GL::PostProcessor>()
{
}
-SequenceTemplate::PostProcessor::PostProcessor(GL::PostProcessor::Template *ppt):
- postprocessor_template(ppt)
-{ }
-
-
DataFile::Loader::ActionMap SequenceTemplate::Loader::shared_actions;
SequenceTemplate::Loader::Loader(SequenceTemplate &t, Collection &c):
Renderable rend;
rend.slot_name = slot;
rend.effect_template = ldr.get_object();
- obj.renderables.push_back(rend);
+ obj.renderables.emplace_back(move(rend));
}
void SequenceTemplate::Loader::multisample(unsigned samples)
PostProcessor pp;
pp.postprocessor_template = ldr.get_object();
pp.slot_name = slot;
- obj.postprocessors.push_back(pp);
+ obj.postprocessors.emplace_back(move(pp));
}
void SequenceTemplate::Loader::renderable(const string &slot)
{
Renderable rend;
rend.slot_name = slot;
- obj.renderables.push_back(rend);
+ obj.renderables.emplace_back(move(rend));
}
void SequenceTemplate::Loader::renderable_with_default(const string &slot, const string &name)
Renderable rend;
rend.renderable = &get_collection().get<GL::Renderable>(name);
rend.slot_name = slot;
- obj.renderables.push_back(rend);
+ obj.renderables.emplace_back(move(rend));
}
void SequenceTemplate::Loader::sequence(const string &slot, const string &name)
rend.slot_name = slot;
SequenceLoader ldr(rend);
load_sub_with(ldr);
- obj.renderables.push_back(rend);
+ obj.renderables.emplace_back(move(rend));
}
void SequenceTemplate::Loader::step(const string &tag, const string &rend)
void SequenceTemplate::Step::Loader::lighting_inline()
{
- RefPtr<Lighting> lightn = new Lighting;
+ unique_ptr<Lighting> lightn = make_unique<Lighting>();
load_sub(*lightn, get_collection());
- get_collection().add(inline_base_name+".lightn", lightn.get());
- obj.lighting = lightn.release();
+ Lighting *ptr = lightn.get();
+ get_collection().add(inline_base_name+".lightn", move(lightn));
+ obj.lighting = ptr;
}
void SequenceTemplate::Step::Loader::lighting(const string &name)
#ifndef SEQUENCETEMPLATE_H_
#define SEQUENCETEMPLATE_H_
+#include <memory>
#include <string>
#include <vector>
#include <msp/core/typeregistry.h>
struct Renderable
{
- Effect::Template *effect_template = nullptr;
+ std::unique_ptr<Effect::Template> effect_template = nullptr;
GL::Renderable *renderable = nullptr;
SequenceTemplate *sequence_template = nullptr;
std::map<std::string, std::string> sequence_renderables;
struct PostProcessor
{
- GL::PostProcessor::Template *postprocessor_template;
+ std::unique_ptr<GL::PostProcessor::Template> postprocessor_template;
std::string slot_name;
-
- PostProcessor(GL::PostProcessor::Template * = nullptr);
};
private:
int clear_stencil = 0;
public:
- ~SequenceTemplate();
-
bool get_hdr() const { return hdr; }
unsigned get_required_multisample() const { return required_multisample; }
unsigned get_maximum_multisample() const { return max_multisample; }
dirty = 0;
}
-Bufferable::AsyncUpdater *Bufferable::create_async_updater() const
+unique_ptr<Bufferable::AsyncUpdater> Bufferable::create_async_updater() const
{
if(!buffer || buffer->get_multiplicity()>1)
throw invalid_operation("Bufferable::create_async_updater");
- return new AsyncUpdater(*this);
+ return make_unique<AsyncUpdater>(*this);
}
#include <cstddef>
#include <cstdint>
+#include <memory>
#include <msp/core/noncopyable.h>
#include "buffer.h"
#include "mspgl_api.h"
/** Returns an object which can be used to upload data to the buffer using
mapped memory. If data is not dirty, returns null. */
- AsyncUpdater *refresh_async() const { return dirty ? create_async_updater() : nullptr; }
+ std::unique_ptr<AsyncUpdater> refresh_async() const { return dirty ? create_async_updater() : nullptr; }
private:
void unlink_from_buffer();
parameter, or null to use the buffer upload interface. */
void upload_data(unsigned, char *) const;
- AsyncUpdater *create_async_updater() const;
+ std::unique_ptr<AsyncUpdater> create_async_updater() const;
};
} // namespace GL
storage(f);
}
-Mesh::Mesh(Mesh &&other):
- Resource(move(other)),
- vertices(move(other.vertices)),
- batches(move(other.batches)),
- vbuf(other.vbuf),
- ibuf(other.ibuf),
- vtx_setup(move(other.vtx_setup)),
- dirty(other.dirty),
- disallow_rendering(other.disallow_rendering),
- face_winding(other.face_winding),
- debug_name(move(other.debug_name))
-{
- other.vbuf = nullptr;
- other.ibuf = nullptr;
-}
-
Mesh::~Mesh()
{
set_manager(nullptr);
batches.clear();
- delete vbuf;
- delete ibuf;
}
void Mesh::storage(const VertexFormat &fmt)
unsigned req_size = vertices.get_required_buffer_size();
if(!vbuf || (vbuf->get_size()>0 && vbuf->get_size()<req_size))
{
- delete vbuf;
- vbuf = new Buffer;
- vertices.use_buffer(vbuf);
+ vbuf = make_unique<Buffer>();
+ vertices.use_buffer(vbuf.get());
if(!vertices.get_format().empty())
vtx_setup.set_vertex_array(vertices);
dirty |= VERTEX_BUFFER;
unsigned req_size = (batches.empty() ? 0 : batches.front().get_required_buffer_size());
if(!ibuf || (ibuf->get_size()>0 && ibuf->get_size()<req_size))
{
- delete ibuf;
- ibuf = new Buffer;
+ ibuf = make_unique<Buffer>();
if(!batches.empty())
- batches.front().change_buffer(ibuf);
+ batches.front().change_buffer(ibuf.get());
dirty |= INDEX_BUFFER;
#ifdef DEBUG
{
batches.emplace_back(move(b));
if(ibuf)
- batches.back().use_buffer(ibuf);
+ batches.back().use_buffer(ibuf.get());
}
else if(batches.back().can_append(b.get_type()))
batches.back().append(b);
prev = nullptr;
for(Batch &a: batches)
{
- a.use_buffer(ibuf, prev);
+ a.use_buffer(ibuf.get(), prev);
prev = &a;
}
}
else
- batches.back().use_buffer(ibuf, prev);
+ batches.back().use_buffer(ibuf.get(), prev);
}
DataType existing_type = batches.front().get_index_type();
dirty = 0;
}
-Resource::AsyncLoader *Mesh::load(IO::Seekable &io, const Resources *)
+unique_ptr<Resource::AsyncLoader> Mesh::load(IO::Seekable &io, const Resources *)
{
- return new AsyncLoader(*this, io);
+ return make_unique<AsyncLoader>(*this, io);
}
uint64_t Mesh::get_data_size() const
vertices.use_buffer(nullptr);
batches.clear();
vtx_setup.unload();
- delete vbuf;
- delete ibuf;
- vbuf = nullptr;
- ibuf = nullptr;
+ vbuf.reset();
+ ibuf.reset();
}
void Mesh::set_debug_name(const string &name)
Mesh::AsyncLoader::~AsyncLoader()
{
mesh.disallow_rendering = false;
- delete vertex_updater;
- delete index_updater;
}
bool Mesh::AsyncLoader::needs_sync() const
}
else if(phase==3)
{
- delete vertex_updater;
- vertex_updater = nullptr;
- delete index_updater;
- index_updater = nullptr;
+ vertex_updater.reset();
+ index_updater.reset();
}
++phase;
#ifndef MSP_GL_MESH_H_
#define MSP_GL_MESH_H_
+#include <memory>
#include <string>
#include <vector>
#include <msp/datafile/objectloader.h>
private:
Mesh &mesh;
IO::Seekable &io;
- Bufferable::AsyncUpdater *vertex_updater = nullptr;
- Bufferable::AsyncUpdater *index_updater = nullptr;
+ std::unique_ptr<Bufferable::AsyncUpdater> vertex_updater;
+ std::unique_ptr<Bufferable::AsyncUpdater> index_updater;
unsigned phase = 0;
public:
VertexArray vertices;
std::vector<Batch> batches;
- Buffer *vbuf = nullptr;
- Buffer *ibuf = nullptr;
+ std::unique_ptr<Buffer> vbuf;
+ std::unique_ptr<Buffer> ibuf;
VertexSetup vtx_setup;
mutable unsigned short dirty = 0;
bool disallow_rendering = false;
public:
Mesh() = default;
Mesh(const VertexFormat &);
- Mesh(Mesh &&);
~Mesh() override;
/** Sets the vertex format for the mesh. It cannot be changed once set. */
public:
const VertexArray &get_vertices() const { return vertices; }
const VertexSetup &get_vertex_setup() const { return vtx_setup; }
- const Buffer *get_index_buffer() const { return ibuf; }
+ const Buffer *get_index_buffer() const { return ibuf.get(); }
std::size_t get_n_vertices() const;
/** Returns a pointer to a vertex. Offsets of individual attributes can be
public:
int get_load_priority() const override { return 1; }
- Resource::AsyncLoader *load(IO::Seekable &, const Resources * = nullptr) override;
+ std::unique_ptr<Resource::AsyncLoader> load(IO::Seekable &, const Resources * = nullptr) override;
std::uint64_t get_data_size() const override;
void unload() override;
}
}
-SpirVModule *SpirVModule::specialize(const map<string, int> &spec_values) const
+unique_ptr<SpirVModule> SpirVModule::specialize(const map<string, int> &spec_values) const
{
vector<uint8_t> flags(code[3], 1);
op += word_count;
}
- SpirVModule *spec_mod = new SpirVModule;
+ unique_ptr<SpirVModule> spec_mod = make_unique<SpirVModule>();
spec_mod->code = move(new_code);
spec_mod->reflect();
spec_mod->create();
#define MSP_GL_MODULE_H_
#include <map>
+#include <memory>
#include <string>
#include <vector>
#include <msp/io/base.h>
bool is_specializable() const { return specializable; }
/** Creates a new module which is a specialized version of this one. */
- SpirVModule *specialize(const std::map<std::string, int> &) const;
+ std::unique_ptr<SpirVModule> specialize(const std::map<std::string, int> &) const;
private:
std::vector<const InstructionBlock *> collect_visited_blocks(const std::map<unsigned, int> &) const;
add_stages(mod, spec_values);
}
-Program::Program(Program &&other):
- ProgramBackend(move(other)),
- reflect_data(move(other.reflect_data)),
- specialized_spirv(other.specialized_spirv)
-{
- other.specialized_spirv = nullptr;
-}
-
-Program::~Program()
-{
- delete specialized_spirv;
-}
-
void Program::add_stages(const Module &mod, const map<string, int> &spec_values)
{
if(has_stages())
if(static_cast<const SpirVModule &>(mod).is_specializable())
{
specialized_spirv = static_cast<const SpirVModule &>(mod).specialize(spec_values);
- final_module = specialized_spirv;
+ final_module = specialized_spirv.get();
}
add_spirv_stages(*static_cast<const SpirVModule *>(final_module), spec_values);
break;
#define MSP_GL_PROGRAM_H_
#include <map>
+#include <memory>
#include <string>
#include <vector>
#include <msp/datafile/objectloader.h>
};
ReflectData reflect_data;
- SpirVModule *specialized_spirv = nullptr;
+ std::unique_ptr<SpirVModule> specialized_spirv;
public:
/// Constructs an empty Program with no shader stages attached.
/// Constructs a Program from a Module, with specialization constants.
Program(const Module &, const std::map<std::string, int> & = std::map<std::string, int>());
- Program(Program &&);
- ~Program();
-
void add_stages(const Module &, const std::map<std::string, int> & = std::map<std::string, int>());
private:
void collect_uniforms(const SpirVModule &);
void Texture::Loader::load_external_image(Graphics::Image &img, const string &fn)
{
- RefPtr<IO::Seekable> io = get_collection().open_raw(fn);
+ unique_ptr<IO::Seekable> io = get_collection().open_raw(fn);
if(!io)
throw IO::file_not_found(fn);
img.load_io(*io);
+#include <memory>
#include <msp/datafile/rawdata.h>
#include <msp/graphics/imageloader.h>
#include "error.h"
IO::Seekable &io;
Texture2D::AsyncTransfer transfer;
Graphics::Image image;
- Graphics::ImageLoader *img_loader = nullptr;
- DataFile::RawData *raw_data = nullptr;
+ std::unique_ptr<Graphics::ImageLoader> img_loader;
+ std::unique_ptr<DataFile::RawData> raw_data;
unsigned n_bytes = 0;
int phase = 0;
public:
AsyncLoader(Texture2D &, IO::Seekable &);
- ~AsyncLoader();
bool needs_sync() const override;
bool process() override;
return LinAl::Vector<unsigned, 2>(w, h);
}
-Resource::AsyncLoader *Texture2D::load(IO::Seekable &io, const Resources *)
+unique_ptr<Resource::AsyncLoader> Texture2D::load(IO::Seekable &io, const Resources *)
{
- return new AsyncLoader(static_cast<Texture2D &>(*this), io);
+ return make_unique<AsyncLoader>(*this, io);
}
if(DataFile::RawData::detect_signature(string(magic, 4)))
{
- raw_data = new DataFile::RawData;
+ raw_data = make_unique<DataFile::RawData>();
raw_data->open_io(io, "async");
}
else
- img_loader = Graphics::ImageLoader::open_io(io);
-}
-
-Texture2D::AsyncLoader::~AsyncLoader()
-{
- delete img_loader;
- delete raw_data;
+ img_loader.reset(Graphics::ImageLoader::open_io(io));
}
bool Texture2D::AsyncLoader::needs_sync() const
LinAl::Vector<unsigned, 2> get_level_size(unsigned) const;
public:
- Resource::AsyncLoader *load(IO::Seekable &, const Resources * = nullptr) override;
+ std::unique_ptr<Resource::AsyncLoader> load(IO::Seekable &, const Resources * = nullptr) override;
};
} // namespace GL
void TextureCube::Loader::external_image(TextureCubeFace face, const string &fn)
{
Graphics::Image img;
- RefPtr<IO::Seekable> io = get_collection().open_raw(fn);
+ unique_ptr<IO::Seekable> io = get_collection().open_raw(fn);
img.load_io(*io);
obj.image(face, img);
if(rotate_lookup)
return *rotate_lookup;
- rotate_lookup = new Texture2D;
+ unique_ptr<Texture2D> owned_ptr = make_unique<Texture2D>();
+ rotate_lookup = owned_ptr.get();
rotate_lookup->storage(RGBA8, 4, 4, 1);
- resources.add(name, rotate_lookup);
unsigned char data[64];
for(unsigned i=0; i<16; ++i)
}
rotate_lookup->image(0, data);
+ resources.add(name, move(owned_ptr));
return *rotate_lookup;
}
AmbientOcclusion *AmbientOcclusion::Template::create(unsigned width, unsigned height) const
{
- RefPtr<AmbientOcclusion> ao = new AmbientOcclusion(width/size_divisor, height/size_divisor);
+ unique_ptr<AmbientOcclusion> ao = make_unique<AmbientOcclusion>(width/size_divisor, height/size_divisor);
ao->set_n_samples(n_samples);
ao->set_occlusion_radius(occlusion_radius);
ao->set_darkness(darkness);
blur_shdata[1].uniform("delta", 0.0f, 1.0f/h);
for(unsigned i=0; i<2; ++i)
- target[i] = new RenderTarget(w, h, (COLOR_ATTACHMENT,RGBA16F));
+ target[i] = make_unique<RenderTarget>(w, h, (COLOR_ATTACHMENT,RGBA16F));
set_radius(2.0f);
set_strength(0.2f);
}
-Bloom::~Bloom()
-{
- for(unsigned i=0; i<2; ++i)
- delete target[i];
-}
-
void Bloom::set_radius(float r)
{
if(r<=0.0f)
Bloom *Bloom::Template::create(unsigned width, unsigned height) const
{
- RefPtr<Bloom> bloom = new Bloom(width/size_divisor, height/size_divisor);
+ unique_ptr<Bloom> bloom = make_unique<Bloom>(width/size_divisor, height/size_divisor);
bloom->set_radius(radius);
bloom->set_strength(strength);
return bloom.release();
};
private:
- RenderTarget *target[2];
+ std::unique_ptr<RenderTarget> target[2];
ProgramData common_shdata;
const Program &blur_shader;
ProgramData blur_shdata[2];
public:
Bloom(unsigned, unsigned);
- ~Bloom() override;
/** Sets the σ value of the gaussian blur. Values much larger than 4.0 are
likely to cause artifacts. */
ColorCurve *ColorCurve::Template::create(unsigned, unsigned) const
{
- RefPtr<ColorCurve> colorcurve = new ColorCurve();
+ unique_ptr<ColorCurve> colorcurve = make_unique<ColorCurve>();
colorcurve->set_exposure_adjust(exposure_adjust);
colorcurve->set_brightness_response(brightness_response);
if(srgb)
if(!content || !environment)
throw invalid_operation("EnvironmentMap::Template::create");
- RefPtr<EnvironmentMap> env_map = new EnvironmentMap(size, format, roughness_levels, *content, *environment);
+ unique_ptr<EnvironmentMap> env_map = make_unique<EnvironmentMap>(size, format, roughness_levels, *content, *environment);
if(use_fixed_position)
env_map->set_fixed_position(fixed_position);
env_map->set_depth_clip(near_clip, far_clip);
if(!content || !lighting)
throw invalid_operation("ShadowMap::Template::create");
- RefPtr<ShadowMap> shadow_map = new ShadowMap(width, height, *content, *lighting);
+ unique_ptr<ShadowMap> shadow_map = make_unique<ShadowMap>(width, height, *content, *lighting);
shadow_map->set_target(target, radius);
shadow_map->set_depth_bias(depth_bias);
shadow_map->set_darkness(darkness);
if(!content || !sun)
throw invalid_operation("Sky::Template::create");
- RefPtr<Sky> sky = new Sky(*content, *sun);
+ unique_ptr<Sky> sky = make_unique<Sky>(*content, *sun);
create_base(*sky);
return sky.release();
{
initialized = true;
- RefPtr<IO::Seekable> io = Resources::get_builtins().open("_builtin.glsl");
+ unique_ptr<IO::Seekable> io = Resources::get_builtins().open("_builtin.glsl");
if(!io)
return nullptr;
ModuleCache::ModuleCache(const ModuleCache &other)
{
for(const auto &kvp: other.modules)
- modules[kvp.first] = new Module(*kvp.second);
+ modules[kvp.first] = make_unique<Module>(*kvp.second);
}
ModuleCache &ModuleCache::operator=(const ModuleCache &other)
{
- for(auto &kvp: modules)
- delete kvp.second;
modules.clear();
for(const auto &kvp: other.modules)
- modules[kvp.first] = new Module(*kvp.second);
+ modules[kvp.first] = make_unique<Module>(*kvp.second);
return *this;
}
-ModuleCache::~ModuleCache()
-{
- for(auto &kvp: modules)
- delete kvp.second;
-}
-
const Module &ModuleCache::add_module(const string &source, const string &src_name)
{
- RefPtr<Module> module = new Module;
+ unique_ptr<Module> module = make_unique<Module>();
Parser parser(this);
unsigned src_index = next_source++;
parser.parse(*module, source, src_name, src_index);
- return *(modules[src_name] = module.release());
+ return *(modules[src_name] = move(module));
}
const Module &ModuleCache::add_module(IO::Base &io, const string &src_name)
{
- RefPtr<Module> module = new Module;
+ unique_ptr<Module> module = make_unique<Module>();
Parser parser(this);
unsigned src_index = next_source++;
parser.parse(*module, io, src_name, src_index);
- return *(modules[src_name] = module.release());
+ return *(modules[src_name] = move(module));
}
const Module &ModuleCache::get_module(const string &name)
if(i!=modules.end())
return *i->second;
- RefPtr<IO::Seekable> io = (resources ? resources->open_raw(fn) : Resources::get_builtins().open(fn));
+ unique_ptr<IO::Seekable> io = (resources ? resources->open_raw(fn) : Resources::get_builtins().open(fn));
if(!io)
throw runtime_error(format("module %s not found", name));
#ifndef MSP_GL_SL_MODULECACHE_H_
#define MSP_GL_SL_MODULECACHE_H_
+#include <memory>
#include <msp/datafile/collection.h>
#include "syntax.h"
{
private:
DataFile::Collection *resources;
- std::map<std::string, Module *> modules;
+ std::map<std::string, std::unique_ptr<Module>> modules;
unsigned next_source = 1;
public:
ModuleCache(DataFile::Collection *);
ModuleCache(const ModuleCache &);
ModuleCache &operator=(const ModuleCache &);
- ~ModuleCache();
const Module &add_module(const std::string &, const std::string &);
const Module &add_module(IO::Base &, const std::string &);
return shprog;
const Module &module = res.get<Module>(module_name);
- shprog = new Program(module, spec_values);
- try
- {
- res.add(name, shprog);
- }
- catch(...)
- {
- delete shprog;
- throw;
- }
-
+ unique_ptr<Program> owned_ptr = make_unique<Program>(module, spec_values);
+ shprog = owned_ptr.get();
+ res.add(name, move(owned_ptr));
return shprog;
}
if(fresnel_lookup)
return *fresnel_lookup;
- fresnel_lookup = new Texture2D;
+ unique_ptr<Texture2D> owned_ptr = make_unique<Texture2D>();
+ fresnel_lookup = owned_ptr.get();
fresnel_lookup->storage(RG8, 128, 128, 1);
- resources.add(name, fresnel_lookup);
const Program &shprog = resources.get<Program>("_pbr_fresnel_lookup.glsl.shader");
ProgramData shdata;
mesh.draw(renderer);
renderer.end();
+ resources.add(name, move(owned_ptr));
return *fresnel_lookup;
}
blocks(move(other.blocks)),
programs(move(other.programs)),
last_buffer_block(other.last_buffer_block),
- buffer(other.buffer),
+ buffer(move(other.buffer)),
dirty(other.dirty),
debug_name(move(other.debug_name))
{
other.blocks.clear();
- other.buffer = nullptr;
}
ProgramData::~ProgramData()
{
if(b.indices.type_flag==0xFE)
delete[] b.indices.dynamic.values;
- delete b.block;
}
- delete buffer;
}
void ProgramData::uniform(Tag tag, DataType type, unsigned array_size, const void *value)
void ProgramData::recreate_buffer() const
{
- Buffer *old_buffer = buffer;
- // Create the new buffer first to ensure it has a different address
- buffer = new Buffer;
- delete old_buffer;
+ /* Ensure that the lifetimes of the buffers overlap so they have different
+ addresses */
+ unique_ptr<Buffer> old_buffer = move(buffer);
+ buffer = make_unique<Buffer>();
if(last_buffer_block)
- last_buffer_block->change_buffer(buffer);
+ last_buffer_block->change_buffer(buffer.get());
#ifdef DEBUG
if(!debug_name.empty())
if(block.used && !block.block)
{
- block.block = new UniformBlock(info);
+ block.block = make_unique<UniformBlock>(info);
if(info.bind_point>=0)
{
if(!buffer)
recreate_buffer();
- block.block->use_buffer(buffer, last_buffer_block);
- last_buffer_block = block.block;
+ block.block->use_buffer(buffer.get(), last_buffer_block);
+ last_buffer_block = block.block.get();
}
}
}
if(shared.dirty==ALL_ONES)
update_block_uniform_indices(shared, b);
prog_begin->masks.used |= shared.used;
- j->block = (shared.used ? shared.block : nullptr);
+ j->block = (shared.used ? shared.block.get() : nullptr);
++j;
}
}
#ifndef MSP_GL_PROGRAMDATA_H_
#define MSP_GL_PROGRAMDATA_H_
+#include <memory>
#include <stdexcept>
#include <msp/core/noncopyable.h>
#include <msp/datafile/objectloader.h>
ReflectData::LayoutHash block_hash = 0;
Mask used = 0;
Mask dirty = 0;
- UniformBlock *block = nullptr;
+ std::unique_ptr<UniformBlock> block;
union
{
std::uint8_t type_flag;
mutable std::vector<SharedBlock> blocks;
mutable std::vector<ProgramBlock> programs;
mutable UniformBlock *last_buffer_block = nullptr;
- mutable Buffer *buffer = nullptr;
+ mutable std::unique_ptr<Buffer> buffer;
bool streaming = false;
mutable Mask dirty = 0;
std::string debug_name;
if(shdata)
{
- RefPtr<ProgramData> old_shdata = shdata;
- shdata = new ProgramData(shprog);
+ shared_ptr<ProgramData> old_shdata = move(shdata);
+ shdata = make_shared<ProgramData>(shprog);
shdata->copy_uniforms(*old_shdata);
}
shprog_from_material = false;
if(data)
{
- shdata = new ProgramData;
+ shdata = make_shared<ProgramData>();
shdata->copy_uniforms(*data);
}
else
void RenderMethod::set_debug_name(const string &name)
{
#ifdef DEBUG
- if(shdata.refcount()==1)
+ if(shdata.use_count()==1)
shdata->set_debug_name(name+": UBO");
#else
(void)name;
obj.shprog_from_material = false;
if(obj.shdata)
{
- RefPtr<ProgramData> old_shdata = obj.shdata;
- obj.shdata = new ProgramData(obj.shprog);
+ shared_ptr<ProgramData> old_shdata = obj.shdata;
+ obj.shdata = make_shared<ProgramData>(obj.shprog);
obj.shdata->copy_uniforms(*old_shdata);
}
}
if(!obj.shprog || obj.shprog_from_material)
throw runtime_error("Shader is required for uniforms");
if(!obj.shdata)
- obj.shdata = new ProgramData(obj.shprog);
- else if(obj.shdata.refcount()>1)
+ obj.shdata = make_shared<ProgramData>(obj.shprog);
+ else if(obj.shdata.use_count()>1)
{
- RefPtr<ProgramData> old_shdata = obj.shdata;
- obj.shdata = new ProgramData;
+ shared_ptr<ProgramData> old_shdata = obj.shdata;
+ obj.shdata = make_shared<ProgramData>();
obj.shdata->copy_uniforms(*old_shdata);
}
load_sub(*obj.shdata);
#ifndef MSP_GL_RENDERPASS_H_
#define MSP_GL_RENDERPASS_H_
-#include <msp/core/refptr.h>
+#include <memory>
#include <msp/datafile/objectloader.h>
#include "blend.h"
#include "cullface.h"
const Program *shprog = nullptr;
bool shprog_from_material = false;
- RefPtr<ProgramData> shdata;
+ std::shared_ptr<ProgramData> shdata;
std::map<Tag, Tag> uniform_slots;
const Material *material = nullptr;
std::string material_slot;
{
}
-SplatMaterial::~SplatMaterial()
-{
- delete base_color_array.texture;
- delete normal_array.texture;
- delete metalness_array.texture;
- delete roughness_array.texture;
- delete occlusion_array.texture;
- delete emission_array.texture;
-}
+SplatMaterial::~SplatMaterial() = default;
void SplatMaterial::fill_program_info(string &module_name, map<string, int> &spec_values) const
{
const Texture *SplatMaterial::get_texture(Tag tag) const
{
if(tag==texture_tags[0])
- return base_color_array.texture;
+ return base_color_array.texture.get();
else if(tag==texture_tags[1])
- return normal_array.texture;
+ return normal_array.texture.get();
else if(tag==texture_tags[2])
- return metalness_array.texture;
+ return metalness_array.texture.get();
else if(tag==texture_tags[3])
- return roughness_array.texture;
+ return roughness_array.texture.get();
else if(tag==texture_tags[4])
- return occlusion_array.texture;
+ return occlusion_array.texture.get();
else if(tag==texture_tags[5])
- return emission_array.texture;
+ return emission_array.texture.get();
else if(tag==texture_tags[6])
return &fresnel_lookup;
else
for(; lowest_free_bit>1; lowest_free_bit>>=1)
++sub.layer;
- RefPtr<IO::Seekable> io = coll.open_raw(sub.source_fn);
+ unique_ptr<IO::Seekable> io = coll.open_raw(sub.source_fn);
char magic[4] = { };
io->read(magic, 4);
io->seek(0, IO::S_BEG);
{
if(!texture && format!=NO_PIXELFORMAT && max_layers>0)
{
- texture = new Texture2DArray;
+ texture = make_unique<Texture2DArray>();
texture->storage(format, width, height, max_layers);
}
}
struct MapArray
{
- Texture2DArray *texture = nullptr;
+ std::unique_ptr<Texture2DArray> texture;
PixelFormat format = NO_PIXELFORMAT;
unsigned width = 0;
unsigned height = 0;
-#include <msp/core/refptr.h>
+#include <memory>
#include <msp/datafile/collection.h>
#include <msp/fs/utils.h>
#include <msp/strings/format.h>
const vector<Tag> &uniform_tags = shdata.get_uniform_tags();
for(auto &kvp: methods)
{
- RefPtr<ProgramData> new_shdata;
+ unique_ptr<ProgramData> new_shdata;
for(Tag t: uniform_tags)
{
Tag tag = kvp.second.get_slotted_uniform_tag(t);
if(!new_shdata)
{
- new_shdata = new ProgramData;
+ new_shdata = make_unique<ProgramData>();
new_shdata->copy_uniforms(*kvp.second.get_shader_data());
}
const VertexFormat &fmt = instance_data.get_format();
matrix_offset = fmt.offset((RAW_ATTRIB4,matrix_location));
- instance_buffer = new Buffer;
- instance_data.use_buffer(instance_buffer);
+ instance_buffer = make_unique<Buffer>();
+ instance_data.use_buffer(instance_buffer.get());
const Mesh *mesh = object.get_mesh();
InstanceArrayBase::~InstanceArrayBase()
{
- delete instance_buffer;
for(Block &b: storage)
delete[] b.begin;
}
#ifndef MSP_GL_INSTANCEARRAY_H_
#define MSP_GL_INSTANCEARRAY_H_
+#include <memory>
#include <vector>
#include <msp/core/noncopyable.h>
#include "mspgl_api.h"
const Object &object;
VertexArray instance_data;
- Buffer *instance_buffer = nullptr;
+ std::unique_ptr<Buffer> instance_buffer;
VertexSetup vtx_setup;
int matrix_location = -1;
unsigned matrix_offset = 0;
void Object::LodLoader::mesh_inline()
{
- RefPtr<Mesh> msh = new Mesh;
+ unique_ptr<Mesh> msh = make_unique<Mesh>();
load_sub(*msh);
- get_collection().add(format("%s/lod%d.mesh", FS::basename(get_source()), index), msh.get());
- lod.mesh = msh.release();
+ Mesh *ptr = msh.get();
+ get_collection().add(format("%s/lod%d.mesh", FS::basename(get_source()), index), move(msh));
+ lod.mesh = ptr;
}
void Object::LodLoader::technique(const string &n)
void Object::LodLoader::technique_inline()
{
- RefPtr<Technique> tech = new Technique;
+ unique_ptr<Technique> tech = make_unique<Technique>();
Technique::Loader ldr(*tech, get_collection());
string name = format("%s/lod%d.tech", FS::basename(get_source()), index);
ldr.set_inline_base_name(name);
load_sub(*tech, get_collection());
- get_collection().add(name, tech.get());
- lod.technique = tech.release();
+ Technique *ptr = tech.get();
+ get_collection().add(name, move(tech));
+ lod.technique = ptr;
}
} // namespace GL
{
PixelFormat pf = get_attachment_pixelformat(a);
- Texture2D *tex2d = new Texture2D;
+ unique_ptr<Texture2D> tex2d = make_unique<Texture2D>();
tex2d->storage(pf, width, height, 1);
if(multisample)
{
- Texture2DMultisample *tex2d_ms = new Texture2DMultisample;
+ unique_ptr<Texture2DMultisample> tex2d_ms = make_unique<Texture2DMultisample>();
tex2d_ms->storage(pf, width, height, samples);
- fbo.attach(a, *tex2d_ms, tex2d);
- textures.push_back(tex2d_ms);
- textures.push_back(tex2d);
+ fbo.attach(a, *tex2d_ms, tex2d.get());
+ textures.push_back(move(tex2d_ms));
+ textures.push_back(move(tex2d));
}
else
{
fbo.attach(a, *tex2d);
- textures.push_back(tex2d);
+ textures.push_back(move(tex2d));
}
}
}
-RenderTarget::~RenderTarget()
-{
- for(Texture *t: textures)
- delete t;
-}
+RenderTarget::~RenderTarget() = default;
const Texture2D &RenderTarget::get_target_texture(unsigned i) const
{
if(fbo.get_format().get_samples()>1)
i = i*2+1;
- return *static_cast<const Texture2D *>(textures[i]);
+ return *static_cast<const Texture2D *>(textures[i].get());
}
const Texture2D &RenderTarget::get_target_texture(FrameAttachment fa) const
#ifndef RENDERTARGET_H_
#define RENDERTARGET_H_
+#include <memory>
#include <msp/core/noncopyable.h>
#include "framebuffer.h"
#include "mspgl_api.h"
private:
unsigned width;
unsigned height;
- std::vector<Texture *> textures;
+ std::vector<std::unique_ptr<Texture>> textures;
Framebuffer fbo;
public:
void Scene::Loader::array(const string &n)
{
- RefPtr<InstanceArray<> > arr = new InstanceArray<>(get_collection().get<GL::Object>(n));
+ unique_ptr<InstanceArray<>> arr = make_unique<InstanceArray<>>(get_collection().get<GL::Object>(n));
load_sub(*arr);
- get_collection().add(format("_scene_array_%d.array", ++inline_counter), arr.get());
- obj.add(*arr.release());
+ InstanceArray<> *ptr = arr.get();
+ get_collection().add(format("_scene_array_%d.array", ++inline_counter), move(arr));
+ obj.add(*ptr);
}
void Scene::Loader::object(const string &n)
void Scene::Loader::object_tagged(const string &n, const string &t)
{
- RefPtr<ObjectInstance> inst = new ObjectInstance(get_collection().get<GL::Object>(n));
+ unique_ptr<ObjectInstance> inst = make_unique<ObjectInstance>(get_collection().get<GL::Object>(n));
load_sub(*inst);
- get_collection().add(format("_scene_object_%d.inst", ++inline_counter), inst.get());
+ ObjectInstance *ptr = inst.get();
+ get_collection().add(format("_scene_object_%d.inst", ++inline_counter), move(inst));
if(content && !t.empty())
- (*content)[t] = inst.get();
- obj.add(*inst.release());
+ (*content)[t] = ptr;
+ obj.add(*ptr);
}
void Scene::Loader::scene(const string &n)
const Tag Sequence::noclear_tag = "noclear";
+// Hide std::unique_ptr<RenderTarget> from the header
+Sequence::Sequence() = default;
+
Sequence::Sequence(unsigned w, unsigned h, const FrameFormat &f):
width(w),
height(h),
FrameFormat postproc_fmt = target_format;
postproc_fmt.set_samples(1);
- target[0] = new RenderTarget(width, height, postproc_fmt);
- target[1] = new RenderTarget(width, height, postproc_fmt);
+ target[0] = make_unique<RenderTarget>(width, height, postproc_fmt);
+ target[1] = make_unique<RenderTarget>(width, height, postproc_fmt);
if(target_format.get_samples()>1)
- target_ms = new RenderTarget(width, height, target_format);
+ target_ms = make_unique<RenderTarget>(width, height, target_format);
}
Sequence::~Sequence()
{
for(OwnedObject &o: owned_data)
o.delete_func(o.pointer);
- delete target[0];
- delete target[1];
- delete target_ms;
}
void Sequence::set_clear_enabled(bool c)
if(target[0])
{
- RenderTarget *source = target[0];
+ RenderTarget *source = target[0].get();
if(target_ms)
{
renderer.resolve_multisample();
- source = target_ms;
+ source = target_ms.get();
}
renderer.set_depth_test(nullptr);
const Texture2D &color = source->get_target_texture(COLOR_ATTACHMENT);
const Texture2D &depth = source->get_target_texture(DEPTH_ATTACHMENT);
postproc[i]->render(renderer, color, depth);
- source = target[j];
+ source = target[j].get();
}
}
}
#ifndef MSP_GL_SEQUENCE_H_
#define MSP_GL_SEQUENCE_H_
+#include <memory>
#include <vector>
#include "color.h"
#include "depthtest.h"
unsigned width = 0;
unsigned height = 0;
FrameFormat target_format;
- RenderTarget *target[2] = { nullptr, nullptr };
- RenderTarget *target_ms = nullptr;
+ std::unique_ptr<RenderTarget> target[2];
+ std::unique_ptr<RenderTarget> target_ms;
bool clear_enabled = false;
std::vector<Color> clear_colors;
float clear_depth = 1.0f;
static const Tag noclear_tag;
public:
- Sequence() = default;
+ Sequence();
Sequence(unsigned, unsigned, const FrameFormat &);
~Sequence() override;
#include "renderer.h"
#include "view.h"
+using namespace std;
+
namespace Msp {
namespace GL {
-View::~View()
-{
- delete internal_renderer;
-}
-
-View::View(View &&other):
- camera(other.camera),
- content(other.content),
- internal_renderer(other.internal_renderer)
-{
- other.internal_renderer = nullptr;
-}
+View::View() = default;
+View::~View() = default;
void View::set_camera(Camera *c)
{
void View::render()
{
if(!internal_renderer)
- internal_renderer = new Renderer;
+ internal_renderer = make_unique<Renderer>();
internal_renderer->begin();
render(*internal_renderer);
internal_renderer->end();
#ifndef MSP_GL_VIEW_H_
#define MSP_GL_VIEW_H_
+#include <memory>
#include <msp/core/noncopyable.h>
#include "framebuffer.h"
#include "mspgl_api.h"
protected:
Camera *camera = nullptr;
Renderable *content = nullptr;
- Renderer *internal_renderer = nullptr;
+ std::unique_ptr<Renderer> internal_renderer;
- View() = default;
+ View();
public:
- View(View &&);
virtual ~View();
virtual unsigned get_width() const { return get_target().get_width(); }
#define MSP_GL_RESOURCE_H_
#include <cstdint>
+#include <memory>
#include <msp/core/noncopyable.h>
#include <msp/io/seekable.h>
#include "mspgl_api.h"
ResourceManager *get_manager() const { return manager; }
void *get_manager_data() const { return manager_data; }
virtual int get_load_priority() const { return 0; }
- virtual AsyncLoader *load(IO::Seekable &, const Resources * = nullptr) = 0;
+ virtual std::unique_ptr<AsyncLoader> load(IO::Seekable &, const Resources * = nullptr) = 0;
virtual bool is_loaded() const;
/** Returns the amount of graphics memory used by this resource. The
throw invalid_operation("ResourceManager::move_resource");
ManagedResource *managed = reinterpret_cast<ManagedResource *>(to.get_manager_data());
MutexLock lock(map_mutex);
- insert_unique(resources, &to, *managed);
+ insert_unique(resources, &to, move(*managed));
resources.erase(&from);
}
loader = resource->load(*io, res);
if(!loader)
{
- delete io;
- io = nullptr;
+ io.reset();
throw logic_error("no loader created");
}
state = LOADING;
void ResourceManager::ManagedResource::finish_loading(bool successful)
{
- delete loader;
- loader = nullptr;
- delete io;
- io = nullptr;
+ loader.reset();
+ io.reset();
if(successful)
{
Resource *resource = nullptr;
ResourceLocation location;
int load_priority = 0;
- IO::Seekable *io = nullptr;
- Resource::AsyncLoader *loader = nullptr;
+ std::unique_ptr<IO::Seekable> io;
+ std::unique_ptr<Resource::AsyncLoader> loader;
State state = NOT_LOADED;
unsigned last_used = 0;
std::uint64_t data_size = 0;
add_type<Animation>().suffix(".anim").keyword("animation");
add_type<Armature>().suffix(".arma").keyword("armature");
add_type<BasicMaterial>().base<Material>().suffix(".mat")
- .creator([this](const string &n) -> BasicMaterial * { create_generic<Material>(n); return nullptr; })
+ .creator([this](const string &n) -> unique_ptr<BasicMaterial> { create_generic<Material>(n); return nullptr; })
.notify(&set_debug_name<Material>);
add_type<Camera>().keyword("camera")
.notify(&set_debug_name<Camera>);
add_type<DirectionalLight>().base<Light>().suffix(".light")
- .creator([this](const string &n) -> DirectionalLight * { create_generic<Light>(n); return nullptr; });
+ .creator([this](const string &n) -> unique_ptr<DirectionalLight> { create_generic<Light>(n); return nullptr; });
add_type<Font>().keyword("font");
add_type<KeyFrame>().suffix(".kframe").keyword("keyframe");
add_type<Lighting>().suffix(".lightn").keyword("lighting")
.notify(&set_debug_name<Module>);
add_type<Object>().base<Renderable>().keyword("object");
add_type<OccludedScene>().base<Scene>().base<Renderable>().suffix(".scene")
- .creator([this](const string &n) -> OccludedScene * { create_generic<Scene>(n); return nullptr; });
+ .creator([this](const string &n) -> unique_ptr<OccludedScene> { create_generic<Scene>(n); return nullptr; });
add_type<OrderedScene>().base<Scene>().base<Renderable>().suffix(".scene")
- .creator([this](const string &n) -> OrderedScene * { create_generic<Scene>(n); return nullptr; });
+ .creator([this](const string &n) -> unique_ptr<OrderedScene> { create_generic<Scene>(n); return nullptr; });
add_type<PbrMaterial>().base<Material>().suffix(".mat")
- .creator([this](const string &n) -> PbrMaterial * { create_generic<Material>(n); return nullptr; })
+ .creator([this](const string &n) -> unique_ptr<PbrMaterial> { create_generic<Material>(n); return nullptr; })
.notify(&set_debug_name<Material>);
add_type<PointLight>().base<Light>().suffix(".light")
- .creator([this](const string &n) -> PointLight * { create_generic<Light>(n); return nullptr; });
+ .creator([this](const string &n) -> unique_ptr<PointLight> { create_generic<Light>(n); return nullptr; });
add_type<SequenceTemplate>().suffix(".seq").keyword("sequence");
add_type<Pose>().keyword("pose");
add_type<Program>().keyword("shader")
add_type<Sampler>().suffix(".samp").keyword("sampler")
.notify(&set_debug_name<Sampler>);
add_type<SimpleScene>().base<Scene>().base<Renderable>().suffix(".scene")
- .creator([this](const string &n) -> SimpleScene * { create_generic<Scene>(n); return nullptr; });
+ .creator([this](const string &n) -> unique_ptr<SimpleScene> { create_generic<Scene>(n); return nullptr; });
add_type<SplatMaterial>().base<Material>().suffix(".mat")
- .creator([this](const string &n) -> SplatMaterial * { create_generic<Material>(n); return nullptr; })
+ .creator([this](const string &n) -> unique_ptr<SplatMaterial> { create_generic<Material>(n); return nullptr; })
.notify(&set_debug_name<Material>);
add_type<Technique>().suffix(".tech").keyword("technique")
.notify(&set_debug_name<Technique>);
add_type<Texture1D>().base<Texture>().suffix(".tex")
- .creator([this](const string &n) -> Texture1D * { create_texture(n); return nullptr; })
+ .creator([this](const string &n) -> unique_ptr<Texture1D> { create_texture(n); return nullptr; })
.notify(&set_debug_name<Texture1D>);
add_type<Texture2D>().base<Texture>().suffix(".tex").suffix(".png").suffix(".jpg")
- .creator([this](const string &n) -> Texture2D * { create_texture(n); return nullptr; })
+ .creator([this](const string &n) -> unique_ptr<Texture2D> { create_texture(n); return nullptr; })
.notify(&set_debug_name<Texture2D>);
add_type<Texture3D>().base<Texture>().suffix(".tex")
- .creator([this](const string &n) -> Texture3D * { create_texture(n); return nullptr; })
+ .creator([this](const string &n) -> unique_ptr<Texture3D> { create_texture(n); return nullptr; })
.notify(&set_debug_name<Texture3D>);
add_type<TextureCube>().base<Texture>().suffix(".tex")
- .creator([this](const string &n) -> TextureCube * { create_texture(n); return nullptr; })
+ .creator([this](const string &n) -> unique_ptr<TextureCube> { create_texture(n); return nullptr; })
.notify(&set_debug_name<TextureCube>);
add_type<Texture2DArray>().base<Texture>().suffix(".tex")
- .creator([this](const string &n) -> Texture2DArray * { create_texture(n); return nullptr; })
+ .creator([this](const string &n) -> unique_ptr<Texture2DArray> { create_texture(n); return nullptr; })
.notify(&set_debug_name<Texture2DArray>);
add_type<UnlitMaterial>().base<Material>().suffix(".mat")
- .creator([this](const string &n) -> UnlitMaterial * { create_generic<Material>(n); return nullptr; })
+ .creator([this](const string &n) -> unique_ptr<UnlitMaterial> { create_generic<Material>(n); return nullptr; })
.notify(&set_debug_name<Material>);
add_type<ZSortedScene>().base<Scene>().base<Renderable>().suffix(".scene")
- .creator([this](const string &n) -> ZSortedScene * { create_generic<Scene>(n); return nullptr; });
+ .creator([this](const string &n) -> unique_ptr<ZSortedScene> { create_generic<Scene>(n); return nullptr; });
add_source(get_builtins());
}
template<typename T, typename L>
-T *Resources::create_generic(const string &name)
+unique_ptr<T> Resources::create_generic(const string &name)
{
- if(RefPtr<IO::Seekable> io = open_raw(name))
+ if(unique_ptr<IO::Seekable> io = open_raw(name))
{
DataFile::Parser parser(*io, name);
L ldr(*this);
return nullptr;
}
-Mesh *Resources::create_mesh(const string &name)
+unique_ptr<Mesh> Resources::create_mesh(const string &name)
{
if(!resource_manager || name[0]=='_')
return nullptr;
- if(RefPtr<IO::Seekable> io = open_raw(name))
+ if(unique_ptr<IO::Seekable> io = open_raw(name))
{
- RefPtr<Mesh> mesh = new Mesh;
+ unique_ptr<Mesh> mesh = make_unique<Mesh>();
mesh->set_manager(resource_manager);
resource_manager->set_resource_location(*mesh, *this, name);
- return mesh.release();
+ return mesh;
}
return nullptr;
}
-Texture *Resources::create_texture(const string &name)
+unique_ptr<Texture> Resources::create_texture(const string &name)
{
bool managed = (resource_manager && name[0]!='_');
return create_generic<Texture>(name);
}
- if(RefPtr<IO::Seekable> io = open_raw(name))
+ if(unique_ptr<IO::Seekable> io = open_raw(name))
{
- RefPtr<Texture2D> tex;
+ unique_ptr<Texture2D> tex;
// Verify that the image is loadable
Graphics::Image image;
if(!managed)
image.load_io(*io);
- tex = new Texture2D;
+ tex = make_unique<Texture2D>();
if(managed)
{
else
tex->image(image);
- add(name, tex.get());
- tex.release();
+ add(name, move(tex));
}
return nullptr;
}
-Module *Resources::create_module(const string &name)
+unique_ptr<Module> Resources::create_module(const string &name)
{
string ext = FS::extpart(name);
if(ext!=".glsl" && ext!=".spv")
return nullptr;
- if(RefPtr<IO::Seekable> io = open_raw(name))
+ if(unique_ptr<IO::Seekable> io = open_raw(name))
{
if(ext==".glsl")
{
- RefPtr<Module> module;
+ unique_ptr<Module> module;
if(get_backend_api()==VULKAN)
- module = new SpirVModule;
+ module = make_unique<SpirVModule>();
else
- module = new GlslModule;
+ module = make_unique<GlslModule>();
module->load_source(*io, this, name);
- return module.release();
+ return module;
}
else if(ext==".spv")
{
- RefPtr<SpirVModule> module = new SpirVModule;
+ unique_ptr<SpirVModule> module = make_unique<SpirVModule>();
module->load_code(*io);
- return module.release();
+ return module;
}
}
else if(ext==".spv")
{
if((io = open_raw(FS::basepart(name)+".glsl")))
{
- RefPtr<SpirVModule> module = new SpirVModule;
+ unique_ptr<SpirVModule> module = make_unique<SpirVModule>();
module->load_source(*io, this, name);
- return module.release();
+ return module;
}
}
return nullptr;
}
-Program *Resources::create_program(const string &name)
+unique_ptr<Program> Resources::create_program(const string &name)
{
string ext = FS::extpart(name);
string base = FS::basepart(name);
if(ext==".shader" && (ext2==".glsl" || ext2==".spv"))
{
Module &module = get<Module>(base);
- RefPtr<Program> shprog = new Program;
+ unique_ptr<Program> shprog = make_unique<Program>();
shprog->add_stages(module);
- return shprog.release();
+ return shprog;
}
return nullptr;
protected:
template<typename T, typename L = typename T::GenericLoader>
- T *create_generic(const std::string &);
+ std::unique_ptr<T> create_generic(const std::string &);
- Mesh *create_mesh(const std::string &);
- Texture *create_texture(const std::string &);
- Module *create_module(const std::string &);
- Program *create_program(const std::string &);
+ std::unique_ptr<Mesh> create_mesh(const std::string &);
+ std::unique_ptr<Texture> create_texture(const std::string &);
+ std::unique_ptr<Module> create_module(const std::string &);
+ std::unique_ptr<Program> create_program(const std::string &);
template<typename T>
static void set_debug_name(const std::string &, T &);
Input::Mouse mouse;
Resources resources;
GL::WindowView view;
- GL::Sequence *sequence = nullptr;
+ unique_ptr<GL::Sequence> sequence;
GL::Renderable *renderable = nullptr;
- GL::AnimatedObject *anim_object = nullptr;
- GL::AnimationPlayer *anim_player = nullptr;
+ unique_ptr<GL::AnimatedObject> anim_object;
+ unique_ptr<GL::AnimationPlayer> anim_player;
GL::DirectionalLight light;
GL::Lighting lighting;
GL::Camera camera;
private:
template<typename T>
T *load(const string &);
-public:
- ~Viewer();
+public:
int main() override;
private:
void tick() override;
GL::Mesh *mesh = nullptr;
if(FS::exists(opts.renderable_name))
{
- mesh = new GL::Mesh;
+ unique_ptr<GL::Mesh> owned_mesh = make_unique<GL::Mesh>();
+ mesh = owned_mesh.get();
DataFile::load(*mesh, opts.renderable_name);
- resources.add("__"+opts.renderable_name, mesh);
+ resources.add("__"+opts.renderable_name, move(owned_mesh));
}
else
mesh = &resources.get<GL::Mesh>(opts.renderable_name);
- object = new GL::Object;
- GL::Technique *tech = new GL::Technique;
+ unique_ptr<GL::Object> owned_object = make_unique<GL::Object>();
+ object = owned_object.get();
+ unique_ptr<GL::Technique> tech = make_unique<GL::Technique>();
tech->add_method(GL::Tag());
object->set_mesh(mesh);
- object->set_technique(tech);
+ object->set_technique(tech.get());
renderable = object;
- resources.add("__.tech", tech);
- resources.add("__.object", object);
+ resources.add("__.tech", move(tech));
+ resources.add("__.object", move(owned_object));
}
else if(ext==".object")
renderable = load<GL::Object>(opts.renderable_name);
IO::BufferedFile in(opts.renderable_name);
DataFile::Parser parser(in, opts.renderable_name);
ldr.load(parser);
- renderable = ldr.get_object();
+ unique_ptr<GL::Scene> scene = ldr.get_object();
+ renderable = scene.get();
+ resources.add("__.scene", move(scene));
}
else
renderable = &resources.get<GL::Scene>(opts.renderable_name);
throw usage_error("Must have an object to animate");
GL::Animation *anim = load<GL::Animation>(opts.animation_name);
- anim_player = new GL::AnimationPlayer;
- anim_object = new GL::AnimatedObject(*object);
+ anim_player = make_unique<GL::AnimationPlayer>();
+ anim_object = make_unique<GL::AnimatedObject>(*object);
anim_player->play(*anim_object, *anim);
- renderable = anim_object;
+ renderable = anim_object.get();
}
window.signal_close.connect(sigc::bind(sigc::mem_fun(this, &Viewer::exit), 0));
if(!sequence)
{
- sequence = new GL::Sequence();
+ sequence = make_unique<GL::Sequence>();
sequence->set_debug_name("Sequence");
sequence->set_clear_enabled(true);
GL::Sequence::Step &step = sequence->add_step(GL::Tag(), *renderable);
step.set_depth_test(GL::LEQUAL);
}
- view.set_content(sequence);
+ view.set_content(sequence.get());
view.set_camera(&camera);
}
{
if(FS::exists(name))
{
- T *thing = new T;
+ unique_ptr<T> owned_thing = make_unique<T>();
+ T *thing = owned_thing.get();
DataFile::load(*thing, name, resources);
- resources.add("__"+name, thing);
+ resources.add("__"+name, move(owned_thing));
return thing;
}
else
return &resources.get<T>(name);
}
-Viewer::~Viewer()
-{
- delete anim_player;
- delete anim_object;
- delete sequence;
-}
-
int Viewer::main()
{
window.show();