Beatmup
Beatmup::GL::RecycleBin Class Reference

Stores references to GPU resources that will not be used anymore and needed to be recycled in a thread having access to the GPU. More...

#include <recycle_bin.h>

Inheritance diagram for Beatmup::GL::RecycleBin:
Beatmup::LockableObject Beatmup::Object

Classes

class  Item
 A wrapper for a GPU resource. More...
 

Public Member Functions

 RecycleBin (Context &ctx)
 
 ~RecycleBin ()
 
void put (Item *item)
 Puts an item into the recycle bin. More...
 
void put (std::initializer_list< Item * > items)
 Puts items into the recycle bin. More...
 
void emptyBin ()
 Empty the bin destroying all the items in a GPU-aware thread. More...
 
- Public Member Functions inherited from Beatmup::LockableObject
void lock ()
 
void unlock ()
 
- Public Member Functions inherited from Beatmup::Object
virtual ~Object ()
 

Private Attributes

std::vector< Item * > items
 
Contextctx
 
AbstractTaskrecycler
 

Detailed Description

Stores references to GPU resources that will not be used anymore and needed to be recycled in a thread having access to the GPU.

GPU resources such as texture handles generally cannot be destroyed in a user thread due to OpenGL API restrictions. They are kept in a RecycleBin until the application empties it, which launches a task running in the thread that can access the GPU.

Definition at line 34 of file recycle_bin.h.

Constructor & Destructor Documentation

◆ RecycleBin()

RecycleBin::RecycleBin ( Context ctx)

Definition at line 63 of file recycle_bin.cpp.

63  : ctx(ctx) {
65 }
std::vector< Item * > items
Definition: recycle_bin.h:48
AbstractTask * recycler
Definition: recycle_bin.h:50
A task to empty the recycle bin.
Definition: recycle_bin.cpp:31

◆ ~RecycleBin()

RecycleBin::~RecycleBin ( )

Definition at line 68 of file recycle_bin.cpp.

68  {
69  delete recycler;
70 }

Member Function Documentation

◆ put() [1/2]

void RecycleBin::put ( RecycleBin::Item item)

Puts an item into the recycle bin.

Definition at line 73 of file recycle_bin.cpp.

73  {
74  if (item) {
75  lock();
76  items.push_back(item);
77  unlock();
78  }
79 }

◆ put() [2/2]

void RecycleBin::put ( std::initializer_list< Item * >  items)

Puts items into the recycle bin.

Definition at line 82 of file recycle_bin.cpp.

82  {
83  lock();
84  for (auto item : items)
85  if (item)
86  this->items.push_back(item);
87  unlock();
88 }

◆ emptyBin()

void RecycleBin::emptyBin ( )

Empty the bin destroying all the items in a GPU-aware thread.

Definition at line 91 of file recycle_bin.cpp.

91  {
92  lock();
93  if (items.size() > 0)
95  unlock();
96 }
float performTask(AbstractTask &task, const PoolIndex pool=DEFAULT_POOL)
Performs a given task.
Definition: context.cpp:240

Member Data Documentation

◆ items

std::vector<Item*> Beatmup::GL::RecycleBin::items
private

Definition at line 48 of file recycle_bin.h.

◆ ctx

Context& Beatmup::GL::RecycleBin::ctx
private

Definition at line 49 of file recycle_bin.h.

◆ recycler

AbstractTask* Beatmup::GL::RecycleBin::recycler
private

Definition at line 50 of file recycle_bin.h.


The documentation for this class was generated from the following files: