Class: Rendering::RenderTexture

Inherits:
Object
  • Object
show all
Defined in:
lib/engine/rendering/render_texture.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width, height, num_color_attachments: 1) ⇒ RenderTexture

Returns a new instance of RenderTexture.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/engine/rendering/render_texture.rb', line 7

def initialize(width, height, num_color_attachments: 1)
  @width = width
  @height = height
  @num_color_attachments = num_color_attachments
  @color_textures = []
  create_framebuffer
  create_color_textures
  create_depth_stencil_texture
  attach_to_framebuffer
  check_framebuffer_complete
end

Instance Attribute Details

#color_texturesObject (readonly)

Returns the value of attribute color_textures.



5
6
7
# File 'lib/engine/rendering/render_texture.rb', line 5

def color_textures
  @color_textures
end

#depth_stencil_textureObject (readonly) Also known as: depth_texture

Returns the value of attribute depth_stencil_texture.



5
6
7
# File 'lib/engine/rendering/render_texture.rb', line 5

def depth_stencil_texture
  @depth_stencil_texture
end

#framebufferObject (readonly)

Returns the value of attribute framebuffer.



5
6
7
# File 'lib/engine/rendering/render_texture.rb', line 5

def framebuffer
  @framebuffer
end

#heightObject (readonly)

Returns the value of attribute height.



5
6
7
# File 'lib/engine/rendering/render_texture.rb', line 5

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



5
6
7
# File 'lib/engine/rendering/render_texture.rb', line 5

def width
  @width
end

Instance Method Details

#bindObject



31
32
33
34
# File 'lib/engine/rendering/render_texture.rb', line 31

def bind
  Engine::GL.BindFramebuffer(Engine::GL::FRAMEBUFFER, @framebuffer)
  Engine::GL.Viewport(0, 0, @width, @height)
end

#color_textureObject



19
20
21
# File 'lib/engine/rendering/render_texture.rb', line 19

def color_texture
  @color_textures[0]
end

#normal_textureObject

Accessor for normal+roughness texture (second attachment)



24
25
26
# File 'lib/engine/rendering/render_texture.rb', line 24

def normal_texture
  @color_textures[1]
end

#resize(width, height) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/engine/rendering/render_texture.rb', line 36

def resize(width, height)
  return if width == @width && height == @height

  @width = width
  @height = height

  @color_textures.each do |tex|
    Engine::GL.BindTexture(Engine::GL::TEXTURE_2D, tex)
    Engine::GL.TexImage2D(Engine::GL::TEXTURE_2D, 0, Engine::GL::RGBA16F, @width, @height, 0, Engine::GL::RGBA, Engine::GL::FLOAT, nil)
  end

  Engine::GL.BindTexture(Engine::GL::TEXTURE_2D, @depth_stencil_texture)
  Engine::GL.TexImage2D(Engine::GL::TEXTURE_2D, 0, Engine::GL::DEPTH24_STENCIL8, @width, @height, 0, Engine::GL::DEPTH_STENCIL, Engine::GL::UNSIGNED_INT_24_8, nil)
end