Class: Quake::Renderer::GLTextured

Inherits:
Object
  • Object
show all
Defined in:
lib/quake/renderer/gl_textured.rb

Constant Summary collapse

TEX_SPECIAL =
1

Instance Method Summary collapse

Constructor Details

#initialize(level, texture_manager, lightmap: nil, sky: nil, water: nil) ⇒ GLTextured

Returns a new instance of GLTextured.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/quake/renderer/gl_textured.rb', line 10

def initialize(level, texture_manager, lightmap: nil, sky: nil, water: nil)
  @level = level
  @texture_manager = texture_manager
  @lightmap = lightmap
  @sky = sky
  @water = water
  @last_leaf = -1
  @visible_surface_cache = nil

  # Precompute ALL surfaces grouped by texture (for non-VIS fallback
  # and as source data for VIS filtering)
  @all_surfaces_by_texture = precompute_surfaces
  @face_to_surface = build_face_index

  puts "Precomputed #{@all_surfaces_by_texture.values.sum(&:size)} surfaces across #{@all_surfaces_by_texture.size} textures"
end

Instance Method Details

#render(camera, aspect) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/quake/renderer/gl_textured.rb', line 27

def render(camera, aspect)
  GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT)

  camera.apply_projection_gl(aspect)
  camera.apply_gl

  # Determine visible surfaces via PVS
  surfaces_by_texture = visible_surfaces(camera)

  # Render opaque world geometry
  GL.Enable(GL::TEXTURE_2D)

  if @lightmap
    render_with_lightmaps(surfaces_by_texture)
  else
    render_without_lightmaps(surfaces_by_texture)
  end

  # Sky drawn before translucent water so translucent water can
  # alpha-blend over sky-tinted background. PVS-cull keeps distant
  # outdoor sky polys out, and TEXTURE_2D must stay enabled or sky
  # polys render as untextured white shapes.
  @sky&.render(camera, visible_face_set: @last_visible_face_set)

  # Translucent water last so it alpha-blends over everything else.
  @water&.render(alpha: 0.5)

  GL.Disable(GL::TEXTURE_2D)
end

#update(dt) ⇒ Object



57
58
59
60
# File 'lib/quake/renderer/gl_textured.rb', line 57

def update(dt)
  @sky&.update(dt)
  @water&.update(dt)
end