Simulant  21.12-574
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
gl1x_render_queue_visitor.h
1 #pragma once
2 
3 #include "../../assets/material.h"
4 #include "../batching/renderable.h"
5 #include "../gl_renderer.h"
6 
7 namespace smlt {
8 
9 class GL1RenderGroupImpl;
10 class GL1XRenderer;
11 
13  Renderable* renderable;
14  MaterialPass* pass;
15  LightPtr light;
16  batcher::Iteration iteration;
17  GL1RenderGroupImpl* render_group_impl;
18 };
19 
20 
22 public:
23  GL1RenderQueueVisitor(GL1XRenderer* renderer, CameraPtr camera);
24 
25  void start_traversal(const batcher::RenderQueue& queue, uint64_t frame_id, Stage* stage);
26  void visit(const Renderable* renderable, const MaterialPass* pass, batcher::Iteration);
27  void end_traversal(const batcher::RenderQueue &queue, Stage* stage);
28 
29  void change_render_group(const batcher::RenderGroup *prev, const batcher::RenderGroup *next);
30  void change_material_pass(const MaterialPass* prev, const MaterialPass* next);
31  void apply_lights(const LightPtr* lights, const uint8_t count);
32 
33 private:
34  GL1XRenderer* renderer_;
35  CameraPtr camera_;
36  Colour global_ambient_;
37 
38  const MaterialPass* pass_ = nullptr;
39  LightPtr light_;
40 
41  GL1RenderGroupImpl* current_group_ = nullptr;
42 
43  void do_visit(const Renderable* renderable, const MaterialPass* material_pass, batcher::Iteration iteration);
44 
45  void enable_vertex_arrays(bool force=false);
46  void disable_vertex_arrays(bool force=false);
47 
48  void enable_normal_arrays(bool force=false);
49  void disable_normal_arrays(bool force=false);
50 
51  void enable_colour_arrays(bool force=false);
52  void disable_colour_arrays(bool force=false);
53 
54  void enable_texcoord_array(uint8_t which, bool force=false);
55  void disable_texcoord_array(uint8_t which, bool force=false);
56 
57  bool positions_enabled_ = false;
58  bool colours_enabled_ = false;
59  bool normals_enabled_ = false;
60  bool textures_enabled_[_S_GL_MAX_TEXTURE_UNITS] = {0};
61 
62  uint32_t default_texture_name_ = 0;
63 
64  struct LightState {
65  bool initialized = false;
66  bool enabled = false;
67  Vec4 position;
68  Colour diffuse;
69  Colour ambient;
70  Colour specular;
71  float constant_att = 0;
72  float linear_att = 0;
73  float quadratic_att = 0;
74 
75  LightState() = default;
76  LightState(bool enabled, Vec4 pos, Colour diffuse, Colour ambient, Colour specular, float constant_att, float linear_att, float quadratic_att):
77  enabled(enabled),
78  position(pos),
79  diffuse(diffuse),
80  ambient(ambient),
81  specular(specular),
82  constant_att(constant_att),
83  linear_att(linear_att),
84  quadratic_att(quadratic_att) {}
85 
86  bool operator!=(const LightState& rhs) const {
87  return !(*this == rhs);
88  }
89 
90  bool operator==(const LightState& rhs) const {
91  return (
92  enabled == rhs.enabled &&
93  position == rhs.position &&
94  diffuse == rhs.diffuse &&
95  ambient == rhs.ambient &&
96  specular == rhs.specular &&
97  constant_att == rhs.constant_att &&
98  linear_att == rhs.linear_att &&
99  quadratic_att == rhs.quadratic_att
100  );
101  }
102  };
103 
104  LightState light_states_[MAX_LIGHTS_PER_RENDERABLE];
105 };
106 
107 
108 }
smlt::Stage
Definition: stage.h:80
smlt
Definition: animation.cpp:25
smlt::batcher::RenderQueue
Definition: render_queue.h:156
smlt::batcher::RenderQueueVisitor
Definition: render_queue.h:114
smlt::GL1RenderQueueVisitor
Definition: gl1x_render_queue_visitor.h:21
smlt::GL1RenderGroupImpl
Definition: gl1x_render_group_impl.h:18
smlt::MaterialPass
Definition: material.h:47
smlt::GL1RenderState
Definition: gl1x_render_queue_visitor.h:12
smlt::batcher::RenderGroup
Definition: render_queue.h:47
smlt::default_init_ptr< Light >
smlt::Renderable
Definition: renderable.h:67
smlt::GL1XRenderer
Definition: gl1x_renderer.h:27
smlt::Colour
Definition: colour.h:29
smlt::Vec4
Definition: vec4.h:12