1 
2 #ifndef RENDER_H
3 #define RENDER_H
4 
5 #include <stdint.h>
6 #include <SDL2/SDL_platform.h>
7 #include <SDL2/SDL_opengl.h>
8 
9 #include "../core/vmath.h"
10 
11 #define R_DRAW_WIRE             0x00000001      // Wireframe rendering
12 #define R_DRAW_ROOMBOXES        0x00000002      // Show room bounds
13 #define R_DRAW_BOXES            0x00000004      // Show boxes
14 #define R_DRAW_PORTALS          0x00000008      // Show portals
15 #define R_DRAW_FRUSTUMS         0x00000010      // Show frustums
16 #define R_DRAW_NORMALS          0x00000020      // Show normals
17 #define R_DRAW_AXIS             0x00000040      // Show axes
18 #define R_SKIP_ROOM             0x00000080      // Hide rooms
19 #define R_SKIP_STATIC           0x00000100      // Hide statics
20 #define R_SKIP_ENTITIES         0x00000200      // Hide entities
21 #define R_DRAW_NULLMESHES       0x00000400      // Draw nullmesh entities
22 #define R_DRAW_DUMMY_STATICS    0x00000800      // Draw empty static meshes
23 #define R_DRAW_COLL             0x00001000      // Draw Bullet physics world
24 #define R_DRAW_SKYBOX           0x00002000      // Draw skybox
25 #define R_DRAW_POINTS           0x00004000      // Points rendering
26 #define R_DRAW_FLYBY            0x00008000      // FlyBy cameras spline rendering
27 #define R_DRAW_CINEMATICS       0x00010000      // Cinematics path rendering
28 #define R_DRAW_CAMERAS          0x00020000      // Cameras and sinks drawing
29 #define R_DRAW_TRIGGERS         0x00040000      // Trigger sectors drawing
30 #define R_DRAW_AI_BOXES         0x00080000      // AI boxes drawing
31 #define R_DRAW_AI_OBJECTS       0x00100000      // AI objects drawing
32 #define R_DRAW_AI_PATH          0x00200000      // AI character target path drawing
33 
34 #define STENCIL_FRUSTUM 1
35 
36 struct portal_s;
37 struct frustum_s;
38 struct world_s;
39 struct room_s;
40 struct camera_s;
41 struct entity_s;
42 struct sprite_s;
43 struct base_mesh_s;
44 struct obb_s;
45 struct lit_shader_description;
46 
47 // Native TR blending modes.
48 
49 enum BlendingMode
50 {
51     BM_OPAQUE,
52     BM_TRANSPARENT,
53     BM_MULTIPLY,
54     BM_SIMPLE_SHADE,
55     BM_TRANSPARENT_IGNORE_Z,
56     BM_INVERT_SRC,
57     BM_WIREFRAME,
58     BM_TRANSPARENT_ALPHA,
59     BM_INVERT_DEST,
60     BM_SCREEN,
61     BM_HIDE,
62     BM_ANIMATED_TEX
63 };
64 
65 // Animated texture types
66 
67 #define TR_ANIMTEXTURE_FORWARD           0
68 #define TR_ANIMTEXTURE_BACKWARD          1
69 #define TR_ANIMTEXTURE_REVERSE           2
70 
71 
72 typedef struct render_settings_s
73 {
74     float     lod_bias;
75     uint32_t  mipmap_mode;
76     uint32_t  mipmaps;
77     uint32_t  anisotropy;
78     int8_t    antialias;
79     int8_t    antialias_samples;
80     int8_t    texture_border;
81     int8_t    z_depth;
82     int8_t    fog_enabled;
83     GLfloat   fog_color[4];
84     float     fog_start_depth;
85     float     fog_end_depth;
86 }render_settings_t, *render_settings_p;
87 
88 
89 class CRenderDebugDrawer
90 {
91     public:
92         // engine debug function
93         CRenderDebugDrawer();
94         virtual ~CRenderDebugDrawer();
IsEmpty()95         bool IsEmpty()
96         {
97             return m_lines == 0;
98         }
99         void Reset();
100         void Render();
SetColor(GLfloat r,GLfloat g,GLfloat b)101         void SetColor(GLfloat r, GLfloat g, GLfloat b)
102         {
103             m_color[0] = r;
104             m_color[1] = g;
105             m_color[2] = b;
106         }
107         void DrawAxis(float r, float transform[16]);
108         void DrawPortal(struct portal_s *p);
109         void DrawFrustum(struct frustum_s *f);
110         void DrawBBox(float bb_min[3], float bb_max[3], float *transform);
111         void DrawOBB(struct obb_s *obb);
112         void DrawMeshDebugLines(struct base_mesh_s *mesh, float transform[16], const float *overrideVertices, const float *overrideNormals);
113         void DrawSkeletalModelDebugLines(struct ss_bone_frame_s *bframe, float transform[16]);
114         void DrawEntityDebugLines(struct entity_s *entity);
115         void DrawSectorDebugLines(struct room_sector_s *rs);
116         void DrawRoomDebugLines(struct room_s *room, struct camera_s *cam);
117 
118         // physics debug interface
119         void   DrawLine(const float from[3], const float to[3], const float color_from[3], const float color_to[3]);
120         void   DrawContactPoint(const float pointOnB[3], const float normalOnB[3], float distance, int lifeTime, const float color[3]);
SetDrawFlags(uint32_t flags)121         void     SetDrawFlags(uint32_t flags) {m_drawFlags = flags;};
GetDrawFlags()122         uint32_t GetDrawFlags() const {return m_drawFlags;}
123 
124     private:
125         uint32_t m_drawFlags;
126         uint32_t m_max_lines;
127         uint32_t m_lines;
128         bool     m_need_realloc;
129 
130         GLuint   m_gl_vbo;
131         GLfloat  m_color[3];
132         GLfloat *m_buffer;
133 
134         struct obb_s *m_obb;
135 };
136 
137 
138 class CRender
139 {
140     public:
141         CRender();
142        ~CRender();
143         void DoShaders();
144         void ResetWorld(struct room_s *rooms, uint32_t rooms_count, struct anim_seq_s *anim_sequences, uint32_t anim_sequences_count);
145         void UpdateAnimTextures();
146 
147         void GenWorldList(struct camera_s *cam);
148         void DrawList();
149         void DrawListDebugLines();
150         void CleanList();
151 
152         void DrawBSPPolygon(struct bsp_polygon_s *p);
153         void DrawBSPFrontToBack(struct bsp_node_s *root);
154         void DrawBSPBackToFront(struct bsp_node_s *root);
155 
156         void DrawMesh(struct base_mesh_s *mesh, const float *overrideVertices, const float *overrideNormals);
157         void DrawSkinMesh(struct base_mesh_s *mesh, struct base_mesh_s *parent_mesh, uint32_t *map, float transform[16]);
158         void DrawSkyBox(const float matrix[16]);
159 
160         void DrawSkeletalModel(const struct lit_shader_description *shader, struct ss_bone_frame_s *bframe, const float mvMatrix[16], const float mvpMatrix[16]);
161         void DrawEntity(struct entity_s *entity, const float modelViewMatrix[16], const float modelViewProjectionMatrix[16]);
162 
163         void DrawRoom(struct room_s *room, const float matrix[16], const float modelViewProjectionMatrix[16]);
164         void DrawRoomSprites(struct room_s *room);
165 
166         struct gl_text_line_s *OutTextXYZ(GLfloat x, GLfloat y, GLfloat z, const char *fmt, ...);
167 
168     private:
169         struct render_list_s
170         {
171             char               active;
172             struct room_s     *room;
173             float              dist;
174         };
175 
176         void InitSettings();
177         int  AddRoom(struct room_s *room);
178         int  ProcessRoom(struct portal_s *portal, struct frustum_s *frus);
179         const lit_shader_description *SetupEntityLight(struct entity_s *entity, const float modelViewMatrix[16]);
180 
181         struct camera_s            *m_camera;
182 
183         struct room_s              *m_rooms;
184         uint32_t                    m_rooms_count;
185         struct anim_seq_s          *m_anim_sequences;
186         uint32_t                    m_anim_sequences_count;
187 
188         uint16_t                    m_active_transparency;
189         GLuint                      m_active_texture;
190 
191         uint32_t                    r_list_size;
192         uint32_t                    r_list_active_count;
193         struct render_list_s       *r_list;
194         class CFrustumManager      *frustumManager;
195 
196     public:
197         struct render_settings_s    settings;
198         class shader_manager       *shaderManager;
199         class CRenderDebugDrawer   *debugDrawer;
200         class CDynamicBSP          *dynamicBSP;
201         uint32_t                    r_flags;
202 };
203 
204 
205 extern CRender renderer;
206 
207 #endif
208