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
26
# 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
  @time = 0.0

  # 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, time: @time || 0.0) ⇒ Object



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
56
# File 'lib/quake/renderer/gl_textured.rb', line 28

def render(camera, aspect, time: @time || 0.0)
  @time = time.to_f

  GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT)

  camera.apply_projection_gl(aspect)
  camera.apply_gl

  # 3D scene culls front faces (Quake winding); 2D passes disable this
  GL.Enable(GL::CULL_FACE)

  # 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

  # 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)

  GL.Disable(GL::TEXTURE_2D)
end

#render_water(alpha: 1.0) ⇒ Object

Water is drawn after entities/viewmodel like R_DrawWaterSurfaces so translucent water blends over everything behind it. GLQuake's default r_wateralpha is 1.0.



61
62
63
64
65
66
67
# File 'lib/quake/renderer/gl_textured.rb', line 61

def render_water(alpha: 1.0)
  return unless @water

  GL.Enable(GL::TEXTURE_2D)
  @water.render(alpha: alpha)
  GL.Disable(GL::TEXTURE_2D)
end

#update(dt) ⇒ Object



69
70
71
72
# File 'lib/quake/renderer/gl_textured.rb', line 69

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