FS2_Open
Open source remastering of the Freespace 2 engine
grbatch.h
Go to the documentation of this file.
1 /*
2  * Code created by Thomas Whittaker (RT) for a FreeSpace 2 source code project
3  *
4  * You may not sell or otherwise commercially exploit the source or things you
5  * created based on the source.
6  *
7 */
8 
9 #ifndef __GRBATCH_H__
10 #define __GRBATCH_H__
11 
12 
14 {
15 private:
16  int n_to_render; // the number of primitives to render
17  int n_allocated; // the number of verts allocated
18  vertex *vert;
19 
20  bool use_radius;
21  float *radius_list; // radiuses associated with the vertices in vert
22 
23  int buffer_offset;
24 
25  // makes sure we have enough space in the memory buffer for the geometry we are about to put into it
26  // you need to figure out how many verts are going to be required
27  void allocate_internal(int n_verts);
28 
29  void clone(const geometry_batcher &geo);
30 
31 public:
32  geometry_batcher(): n_to_render(0), n_allocated(0), vert(NULL), use_radius(true), radius_list(NULL), buffer_offset(-1) {}
34 
35  geometry_batcher(const geometry_batcher &geo) { clone(geo); }
36  const geometry_batcher &operator=(const geometry_batcher &geo);
37 
38  // initial memory space needed
39  // NOTE: This MUST be called BEFORE calling any of the draw_*() functions!!
40  void allocate(int quad, int n_tri = 0);
41 
42  // allocate an additional block of memory to what we already have (this is a resize function)
43  void add_allocate(int quad, int n_tri = 0);
44 
45  // draw a bitmap into the geometry batcher
46  void draw_bitmap(vertex *position, int orient, float rad, float depth = 0);
47 
48  // draw a rotated bitmap
49  void draw_bitmap(vertex *position, float rad, float angle, float depth);
50 
51  // draw a simple 3 vert polygon
52  void draw_tri(vertex *verts);
53 
54  // draw a simple 4 vert polygon
55  void draw_quad(vertex *verts);
56 
57  // draw a beam
58  void draw_beam(vec3d *start, vec3d *end, float width, float intensity = 1.0f, float offset = 0.0f);
59 
60  //draw a laser
61  float draw_laser(vec3d *p0, float width1, vec3d *p1, float width2, int r, int g, int b);
62 
63  // draw all of the batched geometry to the back buffer and flushes the cache
64  // accepts tmap flags so you can use anything you want really
65  void render(int flags, float radius = 0.0f);
66 
67  void load_buffer(effect_vertex* buffer, int *n_verts);
68 
69  void render_buffer(int buffer_handle, int flags);
70 
71  // determine if we even need to try and render this (helpful for particle system)
72  int need_to_render() { return n_to_render; }
73 
74  void operator =(int){}
75 };
76 
78 {
79  SCP_vector<particle_pnt> vertices;
80 
81  int buffer_offset;
82 public:
83  // draw a bitmap into the geometry batcher
84  void draw_bitmap(vertex *position, int orient, float rad, float depth = 0);
85 
86  // draw a rotated bitmap
87 // void draw_bitmap(vertex *position, float rad, float angle, float depth);
88 
89  void load_buffer(particle_pnt* buffer, int *n_verts);
90 
91  void render_buffer(int buffer_handle, int flags);
92 
93  int need_to_render() { return vertices.size(); };
94 };
95 
96 
97 float batch_add_laser(int texture, vec3d *p0, float width1, vec3d *p1, float width2, int r = 255, int g = 255, int b = 255);
98 int batch_add_bitmap(int texture, int tmap_flags, vertex *pnt, int orient, float rad, float alpha = 1.0f, float depth = 0.0f);
99 int batch_add_bitmap_rotated(int texture, int tmap_flags, vertex *pnt, float angle, float rad, float alpha = 1.0f, float depth = 0.0f);
100 int batch_add_beam(int texture, int tmap_flags, vec3d *start, vec3d *end, float width, float intensity = 1.0f);
101 int batch_add_polygon(int texture, int tmap_flags, vec3d *pos, matrix *orient, float width, float height, float alpha = 1.0f);
102 int batch_add_tri(int texture, int tmap_flags, vertex *verts, float alpha = 1.0f);
103 int batch_add_quad(int texture, int tmap_flags, vertex *verts, float alpha = 1.0f);
104 int distortion_add_bitmap_rotated(int texture, int tmap_flags, vertex *pnt, float angle, float rad, float alpha = 1.0f, float depth = 0.0f);
105 int distortion_add_beam(int texture, int tmap_flags, vec3d *start, vec3d *end, float width, float intensity = 1.0f, float offset = 0.0f);
106 void batch_render_all(int stream_buffer = -1);
107 void batch_render_geometry_map_bitmaps(int buffer_handle = -1);
109 void batch_render_lasers(int buffer_handle = -1);
110 void batch_load_buffer_lasers(effect_vertex* buffer, int *n_verts);
111 void batch_reset();
112 void batch_render_distortion_map_bitmaps(int buffer_handle = -1);
114 
115 int batch_get_size();
116 void batch_render_close();
117 
118 int geometry_batch_add_bitmap(int texture, int tmap_flags, vertex *pnt, int orient, float rad, float alpha, float depth);
121 void geometry_batch_render(int stream_buffer);
123 
124 #endif
void batch_render_geometry_map_bitmaps(int buffer_handle=-1)
Definition: grbatch.cpp:1033
void batch_render_close()
Definition: grbatch.cpp:1165
int batch_get_size()
Definition: grbatch.cpp:1281
Definition: pstypes.h:88
GLint GLint GLsizei GLsizei GLsizei depth
Definition: Glext.h:5180
void render_buffer(int buffer_handle, int flags)
Definition: grbatch.cpp:563
void batch_load_buffer_geometry_shader_map_bitmaps(particle_pnt *buffer, int *n_verts)
Definition: grbatch.cpp:1084
hull_check p0
Definition: lua.cpp:5051
int need_to_render()
Definition: grbatch.h:72
GLclampf f
Definition: Glext.h:7097
GLenum GLuint texture
Definition: Glext.h:5872
void batch_render_geometry_shader_map_bitmaps()
void draw_bitmap(vertex *position, int orient, float rad, float depth=0)
Definition: grbatch.cpp:618
int batch_add_tri(int texture, int tmap_flags, vertex *verts, float alpha=1.0f)
Definition: grbatch.cpp:828
float batch_add_laser(int texture, vec3d *p0, float width1, vec3d *p1, float width2, int r=255, int g=255, int b=255)
Definition: grbatch.cpp:698
hull_check orient
Definition: lua.cpp:5049
int batch_add_polygon(int texture, int tmap_flags, vec3d *pos, matrix *orient, float width, float height, float alpha=1.0f)
Definition: grbatch.cpp:888
GLint GLsizei width
Definition: Gl.h:1505
GLfloat angle
Definition: Glext.h:10324
GLintptr offset
Definition: Glext.h:5497
void batch_render_distortion_map_bitmaps(int buffer_handle=-1)
Definition: grbatch.cpp:1245
GLdouble GLdouble GLdouble r
Definition: Glext.h:5337
int batch_add_beam(int texture, int tmap_flags, vec3d *start, vec3d *end, float width, float intensity=1.0f)
Definition: grbatch.cpp:968
GLboolean GLboolean g
Definition: Glext.h:5781
void draw_quad(vertex *verts)
Definition: grbatch.cpp:345
int geometry_batch_get_size()
Definition: grbatch.cpp:1300
void load_buffer(particle_pnt *buffer, int *n_verts)
Definition: grbatch.cpp:604
void batch_render_lasers(int buffer_handle=-1)
Definition: grbatch.cpp:998
int batch_add_bitmap_rotated(int texture, int tmap_flags, vertex *pnt, float angle, float rad, float alpha=1.0f, float depth=0.0f)
Definition: grbatch.cpp:793
void batch_load_buffer_geometry_map_bitmaps(effect_vertex *buffer, int *n_verts)
Definition: grbatch.cpp:1069
hull_check p1
Definition: lua.cpp:5052
void add_allocate(int quad, int n_tri=0)
Definition: grbatch.cpp:83
GLuint buffer
Definition: Glext.h:5492
int batch_add_bitmap(int texture, int tmap_flags, vertex *pnt, int orient, float rad, float alpha=1.0f, float depth=0.0f)
Definition: grbatch.cpp:724
void batch_render_all(int stream_buffer=-1)
Definition: grbatch.cpp:1124
int distortion_add_beam(int texture, int tmap_flags, vec3d *start, vec3d *end, float width, float intensity=1.0f, float offset=0.0f)
Definition: grbatch.cpp:1210
GLuint start
Definition: Gl.h:1502
GLbitfield flags
Definition: Glext.h:6722
void allocate(int quad, int n_tri=0)
Definition: grbatch.cpp:66
int distortion_add_bitmap_rotated(int texture, int tmap_flags, vertex *pnt, float angle, float rad, float alpha=1.0f, float depth=0.0f)
Definition: grbatch.cpp:1175
GLboolean GLboolean GLboolean b
Definition: Glext.h:5781
GLint GLsizei GLsizei height
Definition: Gl.h:1505
void render_buffer(int buffer_handle, int flags)
Definition: grbatch.cpp:584
int batch_add_quad(int texture, int tmap_flags, vertex *verts, float alpha=1.0f)
Definition: grbatch.cpp:858
void draw_tri(vertex *verts)
Definition: grbatch.cpp:334
float draw_laser(vec3d *p0, float width1, vec3d *p1, float width2, int r, int g, int b)
Definition: grbatch.cpp:429
void load_buffer(effect_vertex *buffer, int *n_verts)
Definition: grbatch.cpp:537
void draw_beam(vec3d *start, vec3d *end, float width, float intensity=1.0f, float offset=0.0f)
Definition: grbatch.cpp:362
void batch_load_buffer_lasers(effect_vertex *buffer, int *n_verts)
Definition: grbatch.cpp:1018
hull_check pos
Definition: lua.cpp:5050
void geometry_batch_render(int stream_buffer)
Definition: grbatch.cpp:1099
void render(int flags, float radius=0.0f)
Definition: grbatch.cpp:523
void draw_bitmap(vertex *position, int orient, float rad, float depth=0)
Definition: grbatch.cpp:157
GLclampf GLclampf GLclampf alpha
Definition: Glext.h:5177
const geometry_batcher & operator=(const geometry_batcher &geo)
Definition: grbatch.cpp:142
int geometry_batch_add_bitmap(int texture, int tmap_flags, vertex *pnt, int orient, float rad, float alpha, float depth)
Definition: grbatch.cpp:766
GLuint GLuint end
Definition: Gl.h:1502
geometry_batcher(const geometry_batcher &geo)
Definition: grbatch.h:35
void batch_load_buffer_distortion_map_bitmaps(effect_vertex *buffer, int *n_verts)
Definition: grbatch.cpp:1266
void batch_reset()
Definition: grbatch.cpp:1159