Class: Rugl::Resources::Renderbuffer

Inherits:
Base
  • Object
show all
Defined in:
lib/rugl/resources/renderbuffer.rb

Constant Summary collapse

FORMAT_MAP =
{
  depth_component24: :DEPTH_COMPONENT24,
  depth24_stencil8: :DEPTH24_STENCIL8,
  rgba8: :RGBA8
}.freeze

Instance Attribute Summary collapse

Attributes inherited from Base

#context, #id

Instance Method Summary collapse

Methods inherited from Base

#destroyed?

Constructor Details

#initialize(context, opts) ⇒ Renderbuffer

Returns a new instance of Renderbuffer.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rugl/resources/renderbuffer.rb', line 14

def initialize(context, opts)
  super(context)
  @width = opts.fetch(:width).to_i
  @height = opts.fetch(:height).to_i
  @format = opts.fetch(:format, :depth_component24).to_sym
  @target = gl_const(:RENDERBUFFER)
  @id = allocate_gl_id(:GenRenderbuffers)

  bind
  allocate_storage(@width, @height)
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



12
13
14
# File 'lib/rugl/resources/renderbuffer.rb', line 12

def format
  @format
end

#heightObject (readonly)

Returns the value of attribute height.



12
13
14
# File 'lib/rugl/resources/renderbuffer.rb', line 12

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



12
13
14
# File 'lib/rugl/resources/renderbuffer.rb', line 12

def width
  @width
end

Instance Method Details

#bindObject



26
27
28
29
30
# File 'lib/rugl/resources/renderbuffer.rb', line 26

def bind
  ensure_alive!
  gl_call(:BindRenderbuffer, @target, @id)
  self
end

#destroyObject



41
42
43
44
45
46
47
# File 'lib/rugl/resources/renderbuffer.rb', line 41

def destroy
  return if destroyed?

  delete_gl_id(:DeleteRenderbuffers, @id)
  mark_destroyed!
  nil
end

#resize(width, height) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/rugl/resources/renderbuffer.rb', line 32

def resize(width, height)
  ensure_alive!
  @width = width.to_i
  @height = height.to_i
  bind
  allocate_storage(@width, @height)
  self
end