FS2_Open
Open source remastering of the Freespace 2 engine
modelrender.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) Freespace Open 2013. All rights reserved.
3  *
4  * All source code herein is the property of Freespace Open. You may not sell
5  * or otherwise commercially exploit the source or things you created based on the
6  * source.
7  *
8 */
9 
10 #ifndef _MODELRENDER_H
11 #define _MODELRENDER_H
12 
13 #include "graphics/gropengltnl.h"
14 #include "lighting/lighting.h"
15 #include "math/vecmat.h"
16 #include "model/model.h"
17 
18 extern light Lights[MAX_LIGHTS];
19 extern int Num_lights;
20 
21 extern bool Rendering_to_shadow_map;
22 
23 extern matrix Object_matrix;
24 extern vec3d Object_position;
25 
27 
28 inline int in_box(vec3d *min, vec3d *max, vec3d *pos, vec3d *view_pos)
29 {
30  vec3d point;
31 
32  vm_vec_sub(&point, view_pos, pos);
33 
34  if ( (point.xyz.x >= min->xyz.x) && (point.xyz.x <= max->xyz.x)
35  && (point.xyz.y >= min->xyz.y) && (point.xyz.y <= max->xyz.y)
36  && (point.xyz.z >= min->xyz.z) && (point.xyz.z <= max->xyz.z) )
37  {
38  return 1;
39  }
40 
41  return -1;
42 }
43 
44 inline int in_sphere(vec3d *pos, float radius, vec3d *view_pos)
45 {
46  if ( vm_vec_dist(view_pos, pos) <= radius )
47  return 1;
48  else
49  return -1;
50 }
51 
52 extern int model_interp_get_texture(texture_info *tinfo, fix base_frametime);
53 
54 struct transform
55 {
58 
60  transform(matrix *m, vec3d *v): basis(*m), origin(*v) {}
61 };
62 
64 {
65  uint Model_flags;
66  uint Debug_flags;
67 
68  int Objnum;
69 
70  int Detail_level_locked;
71 
72  float Depth_scale;
73 
74  int Warp_bitmap;
75  float Warp_alpha;
76  vec3d Warp_scale;
77 
78  color Color;
79 
80  float Xparent_alpha;
81 
82  int Forced_bitmap;
83 
84  int Insignia_bitmap;
85 
86  int *Replacement_textures;
87 
88  bool Team_color_set;
89  team_color Current_team_color;
90 
91  bool Clip_plane_set;
92  vec3d Clip_normal;
93  vec3d Clip_pos;
94 
95  int Animated_effect;
96  float Animated_timer;
97 
98  mst_info Thruster_info;
99 public:
101 
102  void set_flags(uint flags);
103  void set_debug_flags(uint flags);
104  void set_object_number(int num);
105  void set_detail_level_lock(int detail_level_lock);
106  void set_depth_scale(float scale);
107  void set_warp_params(int bitmap, float alpha, vec3d &scale);
108  void set_color(color &clr);
109  void set_color(int r, int g, int b);
110  void set_alpha(float alpha);
111  void set_forced_bitmap(int bitmap);
112  void set_insignia_bitmap(int bitmap);
114  void set_team_color(team_color &clr);
115  void set_team_color(const SCP_string &team, const SCP_string &secondaryteam, fix timestamp, int fadetime);
116  void set_clip_plane(vec3d &pos, vec3d &normal);
117  void set_animated_effect(int effect_num, float timer);
118  void set_thruster_info(mst_info &info);
119 
120  bool is_clip_plane_set();
121  bool is_team_color_set();
122 
125  int get_object_number();
126  int get_detail_level_lock();
127  float get_depth_scale();
128  int get_warp_bitmap();
129  float get_warp_alpha();
130  const vec3d& get_warp_scale();
131  const color& get_color();
132  float get_alpha();
133  int get_forced_bitmap();
134  int get_insignia_bitmap();
135  const int* get_replacement_textures();
136  const team_color& get_team_color();
137  const vec3d& get_clip_plane_pos();
138  const vec3d& get_clip_plane_normal();
141  const mst_info& get_thruster_info();
142 };
143 
145 {
148 };
149 
151 {
157  float width;
158 };
159 
161 {
166 
167  // if there's a clip plane
169 };
170 
172 {
178  int zbias;
180 
183 
184  bool lighting;
187 
189 
193 
194  // fog state maybe shouldn't belong here. if we have fog, then it's probably occurring for all objects in scene.
195  int fog_mode;
196  int r;
197  int g;
198  int b;
199  float fog_near;
200  float fog_far;
201 
203  {
204  clip_plane_handle = -1;
205  texture_addressing = TMAP_ADDRESS_WRAP;
206  fill_mode = GR_FILL_MODE_SOLID;
207 
208  buffer_id = -1;
209 
210  lighting = false;
211 
212  fog_mode = GR_FOGMODE_NONE;
213  r = 0;
214  g = 0;
215  b = 0;
216  fog_near = -1.0f;
217  fog_far = -1.0f;
218 
219  lights.index_start = 0;
220  lights.num_lights = 0;
221  light_factor = 1.0f;
222 
223  animated_timer = 0.0f;
224  animated_effect = 0;
225 
226  thrust_scale = -1.0f;
227 
228  gr_init_color(&clr, 255, 255, 255);
229  }
230 };
231 
233 {
237 
240  float alpha;
242 
245 
247  int texi;
248  int flags;
250 
252 
254  {
255  depth_mode = GR_ZBUFF_FULL;
256 
257  texture_maps[TM_BASE_TYPE] = -1;
258  texture_maps[TM_GLOW_TYPE] = -1;
259  texture_maps[TM_HEIGHT_TYPE] = -1;
260  texture_maps[TM_MISC_TYPE] = -1;
261  texture_maps[TM_NORMAL_TYPE] = -1;
262  texture_maps[TM_SPECULAR_TYPE] = -1;
263  }
264 };
265 
267 {
269  int n_verts;
270 
273 };
274 
276 {
277  SCP_vector<matrix4> Submodel_matrices;
278  void* Mem_alloc;
279  uint Mem_alloc_size;
280 
281  int Current_offset;
282 
283  void allocate_memory();
284 public:
285  model_batch_buffer() : Mem_alloc(NULL), Mem_alloc_size(0), Current_offset(0) {};
286 
287  void reset();
288 
289  int get_buffer_offset();
290  void set_num_models(int n_models);
291  void set_model_transform(matrix4 &transform, int model_id);
292 
293  void submit_buffer_data();
294 
295  void add_matrix(matrix4 &mat);
296 };
297 
299 {
300  transform Current_transform;
301  vec3d Current_scale;
302  SCP_vector<transform> Transform_stack;
303 
304  render_state Current_render_state;
305  bool Dirty_render_state;
306 
307  scene_lights Scene_light_handler;
308 
309  int Current_textures[TM_NUM_TYPES];
310  int Current_blend_filter;
311  float Current_alpha;
312  int Current_depth_mode;
313 
314  int Current_set_clip_plane;
315  light_indexing_info Current_lights_set;
316 
317  void render_arc(arc_effect &arc);
318  void render_insignia(insignia_draw_data &insignia_info);
319  void render_outline(outline_draw &outline_info);
320  void render_buffer(queued_buffer_draw &render_elements);
321  uint determine_shader_flags(render_state *state, queued_buffer_draw *draw_info, vertex_buffer *buffer, int tmap_flags);
322 
323  SCP_vector<clip_plane_state> Clip_planes;
324  SCP_vector<render_state> Render_states;
325  SCP_vector<queued_buffer_draw> Render_elements;
326  SCP_vector<int> Render_keys;
327 
330  SCP_vector<outline_draw> Outlines;
331 
332  static draw_list *Target;
333  static bool sort_draw_pair(const int a, const int b);
334  void sort_draws();
335 public:
336  draw_list();
337  void init();
338 
339  void reset_state();
340  void set_clip_plane(const vec3d &position, const vec3d &normal);
341  void set_clip_plane();
342  void set_thrust_scale(float scale = -1.0f);
343  void set_texture(int texture_type, int texture_handle);
344  void set_depth_mode(int depth_set);
345  void set_blend_filter(int filter, float alpha);
346  void set_texture_addressing(int addressing);
347  void set_fog(int fog_mode, int r, int g, int b, float fog_near = -1.0f, float fog_far = -1.0f);
348  void set_fill_mode(int mode);
349  void set_cull_mode(int mode);
350  void set_zbias(int bias);
351  void set_center_alpha(int center_alpha);
352  void set_lighting(bool mode);
353  void set_buffer(int buffer);
354  void set_team_color(const team_color &clr);
355  void set_team_color();
356  void set_color(const color &clr);
357  void set_animated_timer(float time);
358  void set_animated_effect(int effect);
360  void start_model_batch(int n_models);
361 
362  void add_buffer_draw(vertex_buffer *buffer, int texi, uint tmap_flags, model_render_params *interp);
363 
365  void clear_transforms();
367  void pop_transform();
368  void set_scale(vec3d *scale = NULL);
369 
370  void add_arc(vec3d *v1, vec3d *v2, color *primary, color *secondary, float arc_width);
371  void render_arcs();
372 
373  void add_insignia(polymodel *pm, int detail_level, int bitmap_num);
374  void render_insignias();
375 
376  void add_outline(vertex* vert_array, int n_verts, color *clr);
377  void render_outlines();
378 
379  void set_light_filter(int objnum, vec3d *pos, float rad);
380  void set_light_factor(float factor);
381 
382  void init_render(bool sort = true);
383  void render_all(int depth_mode = -1);
384  void reset();
385 };
386 
388 {
389  static draw_list *Target;
390 public:
391  static void sort(draw_list *target);
392  static int sortDrawPair(const void* a, const void* b);
393 };
394 
395 void model_render_immediate(model_render_params *render_info, int model_num, matrix *orient, vec3d * pos, int render = MODEL_RENDER_ALL, bool sort = true);
396 void model_render_queue(model_render_params *render_info, draw_list* scene, int model_num, matrix *orient, vec3d *pos);
399 void model_render_buffers(draw_list* scene, model_render_params* interp, vertex_buffer *buffer, polymodel *pm, int mn, int detail_level, uint tmap_flags);
401 void model_render_set_clip_plane(model_render_params *interp, vec3d *pos = NULL, vec3d *normal = NULL);
404 
405 #endif
int clip_plane_handle
Definition: modelrender.h:173
void add_outline(vertex *vert_array, int n_verts, color *clr)
int timestamp(int delta_ms)
Definition: timer.cpp:226
int Num_lights
Definition: lighting.cpp:29
#define TM_BASE_TYPE
Definition: model.h:657
int in_sphere(vec3d *pos, float radius, vec3d *view_pos)
Definition: modelrender.h:44
float width
Definition: modelrender.h:157
void add_insignia(polymodel *pm, int detail_level, int bitmap_num)
matrix basis
Definition: modelrender.h:56
color secondary
Definition: modelrender.h:156
void set_animated_effect(int effect)
#define MAX_LIGHTS
Definition: globals.h:86
void set_thruster_info(mst_info &info)
static int sortDrawPair(const void *a, const void *b)
void set_fog(int fog_mode, int r, int g, int b, float fog_near=-1.0f, float fog_far=-1.0f)
void set_team_color()
void submodel_render_immediate(model_render_params *render_info, int model_num, int submodel_num, matrix *orient, vec3d *pos)
void set_cull_mode(int mode)
float fog_near
Definition: modelrender.h:199
Definition: pstypes.h:88
Definition: 2d.h:95
void set_flags(uint flags)
transform transformation
Definition: modelrender.h:152
#define GR_ZBUFF_FULL
Definition: 2d.h:675
struct vec3d::@225::@227 xyz
CButton * team
GLclampf f
Definition: Glext.h:7097
GLfloat bias
Definition: Glext.h:7380
void render_arcs()
void add_buffer_draw(vertex_buffer *buffer, int texi, uint tmap_flags, model_render_params *interp)
void set_buffer(int buffer)
float factor
Definition: lua.cpp:440
void init()
vec3d origin
Definition: modelrender.h:57
void set_detail_level_lock(int detail_level_lock)
GLenum mode
Definition: Glext.h:5794
void set_insignia_bitmap(int bitmap)
#define GR_FILL_MODE_SOLID
Definition: 2d.h:670
hull_check orient
Definition: lua.cpp:5049
std::basic_string< char, std::char_traits< char >, std::allocator< char > > SCP_string
Definition: vmallocator.h:21
void add_matrix(matrix4 &mat)
GLenum GLenum GLenum GLenum GLenum scale
Definition: Glext.h:8503
GLfloat GLfloat GLfloat v2
Definition: Glext.h:5640
#define TM_SPECULAR_TYPE
Definition: model.h:659
void set_lighting(bool mode)
vec3d view_pos
Definition: fredrender.cpp:103
hull_check submodel_num
Definition: lua.cpp:5048
matrix Object_matrix
Definition: 3dsetup.cpp:43
float get_animated_effect_timer()
#define TM_NUM_TYPES
Definition: model.h:663
int texture_addressing
Definition: modelrender.h:174
transform transformation
Definition: modelrender.h:243
void pop_transform()
int texture_maps[TM_NUM_TYPES]
Definition: modelrender.h:235
const vec3d & get_warp_scale()
float light_factor
Definition: modelrender.h:186
void set_alpha(float alpha)
team_color tm_color
Definition: modelrender.h:191
void set_center_alpha(int center_alpha)
vec3d Object_position
Definition: 3dsetup.cpp:42
void set_debug_flags(uint flags)
GLdouble GLdouble GLdouble r
Definition: Glext.h:5337
unsigned int uint
Definition: pstypes.h:64
void set_animated_timer(float time)
GLboolean GLboolean g
Definition: Glext.h:5781
void reset()
GLboolean GLboolean GLboolean GLboolean a
Definition: Glext.h:5781
void render_insignias()
void set_light_filter(int objnum, vec3d *pos, float rad)
polymodel * pm
Definition: modelrender.h:163
void set_team_color(team_color &clr)
team_color * Current_team_color
Definition: gropengltnl.cpp:78
Definition: bmpman.h:101
GLuint buffer
Definition: Glext.h:5492
float vm_vec_dist(const vec3d *v0, const vec3d *v1)
Definition: vecmat.cpp:355
light_indexing_info lights
Definition: modelrender.h:185
float animated_timer
Definition: modelrender.h:181
void init_render(bool sort=true)
void set_texture_addressing(int addressing)
void reset_state()
transform transformation
Definition: modelrender.h:271
const GLuint * textures
Definition: Glext.h:7569
void set_color(color &clr)
void set_forced_bitmap(int bitmap)
#define MODEL_RENDER_ALL
Definition: model.h:935
long fix
Definition: pstypes.h:54
void set_replacement_textures(int *textures)
color primary
Definition: modelrender.h:155
void add_submodel_to_batch(int model_num)
void add_arc(vec3d *v1, vec3d *v2, color *primary, color *secondary, float arc_width)
const vec3d & get_clip_plane_pos()
GLfloat GLfloat v1
Definition: Glext.h:5639
int model_interp_get_texture(texture_info *tinfo, fix base_frametime)
#define TMAP_ADDRESS_WRAP
Definition: tmapper.h:94
void model_render_queue(model_render_params *render_info, draw_list *scene, int model_num, matrix *orient, vec3d *pos)
bool using_team_color
Definition: modelrender.h:190
void set_clip_plane()
void set_scale(vec3d *scale=NULL)
GLbitfield flags
Definition: Glext.h:6722
transform transformation
Definition: modelrender.h:162
Definition: 2d.h:109
Definition: lighting.h:32
float thrust_scale
Definition: modelrender.h:188
void set_depth_scale(float scale)
int animated_effect
Definition: modelrender.h:182
void vm_vec_sub(vec3d *dest, const vec3d *src0, const vec3d *src1)
Definition: vecmat.cpp:168
void model_render_set_clip_plane(model_render_params *interp, vec3d *pos=NULL, vec3d *normal=NULL)
void set_model_transform(matrix4 &transform, int model_id)
#define TM_GLOW_TYPE
Definition: model.h:658
GLboolean GLboolean GLboolean b
Definition: Glext.h:5781
void model_render_set_thrust(model_render_params *interp, int model_num, mst_info *mst)
void model_render_buffers(draw_list *scene, model_render_params *interp, vertex_buffer *buffer, polymodel *pm, int mn, int detail_level, uint tmap_flags)
GLuint GLuint num
Definition: Glext.h:9089
transform(matrix *m, vec3d *v)
Definition: modelrender.h:60
vertex * vert_array
Definition: modelrender.h:268
bool model_render_check_detail_box(vec3d *view_pos, polymodel *pm, int submodel_num, uint flags)
void set_color(const color &clr)
void clear_transforms()
GLenum target
Definition: Glext.h:6872
void set_blend_filter(int filter, float alpha)
void set_warp_params(int bitmap, float alpha, vec3d &scale)
GLuint interp
Definition: Glext.h:8983
void render_all(int depth_mode=-1)
void set_light_factor(float factor)
const int * get_replacement_textures()
#define TM_HEIGHT_TYPE
Definition: model.h:661
hull_check pos
Definition: lua.cpp:5050
const GLfloat * m
Definition: Glext.h:10319
void model_render_immediate(model_render_params *render_info, int model_num, matrix *orient, vec3d *pos, int render=MODEL_RENDER_ALL, bool sort=true)
const color & get_color()
void set_clip_plane(vec3d &pos, vec3d &normal)
void set_depth_mode(int depth_set)
void render_outlines()
void submodel_render_queue(model_render_params *render_info, draw_list *scene, int model_num, int submodel_num, matrix *orient, vec3d *pos)
void set_animated_effect(int effect_num, float timer)
int in_box(vec3d *min, vec3d *max, vec3d *pos, vec3d *view_pos)
Definition: modelrender.h:28
polymodel * pm
Definition: lua.cpp:1598
const team_color & get_team_color()
light Lights[MAX_LIGHTS]
Definition: lighting.cpp:28
void set_zbias(int bias)
vertex_buffer * buffer
Definition: modelrender.h:246
vec3d get_view_position()
int model_num
Definition: lua.cpp:4996
GLclampf GLclampf GLclampf alpha
Definition: Glext.h:5177
void set_object_number(int num)
vec3d vmd_zero_vector
Definition: vecmat.cpp:24
void start_model_batch(int n_models)
fix model_render_determine_base_frametime(int objnum, uint flags)
bool Rendering_to_shadow_map
Definition: gropengltnl.cpp:88
const GLdouble * v
Definition: Glext.h:5322
void gr_init_color(color *c, int r, int g, int b)
Definition: 2d.cpp:1155
matrix vmd_identity_matrix
Definition: vecmat.cpp:28
void set_texture(int texture_type, int texture_handle)
const vec3d & get_clip_plane_normal()
#define TM_MISC_TYPE
Definition: model.h:662
#define TM_NORMAL_TYPE
Definition: model.h:660
void push_transform(vec3d *pos, matrix *orient)
const mst_info & get_thruster_info()
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: Glext.h:6566
static void sort(draw_list *target)
void set_fill_mode(int mode)
#define GR_FOGMODE_NONE
Definition: 2d.h:355
void set_num_models(int n_models)
void set_thrust_scale(float scale=-1.0f)