Class: Gl::GlInternalMarked

Inherits:
Object
  • Object
show all
Defined in:
lib/opengl-core/aux/marked.rb

Direct Known Subclasses

Buffer, Program, Shader, Texture, VertexArray

Constant Summary collapse

@@allocated__ =
{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.__marked_allocated__Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a Hash of marked objects.



56
57
58
# File 'lib/opengl-core/aux/marked.rb', line 56

def self.__marked_allocated__
  (@@allocated__[self.class] || (@@allocated__[self.class] = {}))
end

.allocatedObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns all allocated marked objects for this class.



62
63
64
# File 'lib/opengl-core/aux/marked.rb', line 62

def self.allocated
  __marked_allocated__.keys
end

.clear_allObject

Clears all marked objects. If deletion is already guaranteed for all marked objects, you may use this to let all marked objects of this type get GC’d.



25
26
27
# File 'lib/opengl-core/aux/marked.rb', line 25

def self.clear_all
  __marked_allocated__.clear
end

.delete_allObject

Deletes all objects of the given type. Should be used carefully if at all.



19
20
21
# File 'lib/opengl-core/aux/marked.rb', line 19

def self.delete_all
  __marked_allocated__.keys.each { |marked| marked.delete }
end

.inherited(subclass) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Allocates a hash for the subclass. This will be done regardless of whether this function is called.



50
51
52
# File 'lib/opengl-core/aux/marked.rb', line 50

def self.inherited(subclass)
  @@allocated__[subclass] = @@allocated__[subclass] || {}
end

Instance Method Details

#==(other) ⇒ Object



7
8
9
# File 'lib/opengl-core/aux/marked.rb', line 7

def ==(other)
  (self.kind_of?(other.class) || other.kind_of?(self.class)) && (self.name == other.name)
end

#__mark__Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Marks the class to prevent it from being garbage collected.



31
32
33
# File 'lib/opengl-core/aux/marked.rb', line 31

def __mark__
  self.class.__marked_allocated__[self] = true
end

#__unmark__Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Unmarks the class and allows it to be garbage collected.



37
38
39
# File 'lib/opengl-core/aux/marked.rb', line 37

def __unmark__
  self.class.__marked_allocated__.delete(self)
end

#deleteObject

Should be overridden by subclasses to handle freeing resources when marked. If unmarked, should be a no-op.



13
14
15
16
# File 'lib/opengl-core/aux/marked.rb', line 13

def delete
  __unmark__
  self
end

#marked?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns whether the object is currently marked to keep it from being GC’d.

Returns:

  • (Boolean)


43
44
45
# File 'lib/opengl-core/aux/marked.rb', line 43

def marked?
  self.class.__marked_allocated__.include?(self)
end