UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
r_state.h
Go to the documentation of this file.
1 
6 /*
7 All original material Copyright (C) 2002-2020 UFO: Alien Invasion.
8 
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 
18 See the GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 
24 */
25 
26 #pragma once
27 
28 #include "../../shared/cxx.h"
29 
30 #include "r_program.h"
31 #include "r_material.h"
32 #include "r_framebuffer.h"
33 #include "r_light.h"
34 #include "r_image.h"
35 
41 #define SKYBOX_DEPTH -9999.0f
42 
43 /* vertex arrays are used for many things */
44 #define GL_ARRAY_LENGTH_CHUNK 4096
45 extern const vec2_t default_texcoords[4];
46 
48 typedef struct gltexunit_s {
49  bool enabled;
53  GLfloat* texcoord_array;
54  /* Size of the array above - it's dynamically reallocated */
56 } gltexunit_t;
57 
58 #define MAX_GL_TEXUNITS 6
59 
60 /* these are defined for convenience */
61 #define texunit_0 r_state.texunits[0]
62 #define texunit_1 r_state.texunits[1]
63 #define texunit_2 r_state.texunits[2]
64 #define texunit_3 r_state.texunits[3]
65 #define texunit_4 r_state.texunits[4]
66 #define texunit_5 r_state.texunits[5]
67 
68 #define texunit_diffuse texunit_0
69 #define texunit_lightmap texunit_1
70 #define texunit_deluxemap texunit_2
71 #define texunit_normalmap texunit_3
72 #define texunit_glowmap texunit_4
73 #define texunit_specularmap texunit_5
74 #define texunit_roughnessmap texunit_2
75 
76 #define COMPONENTS_VERTEX_ARRAY3D 3
77 #define COMPONENTS_VERTEX_ARRAY2D 2
78 #define COMPONENTS_COLOR_ARRAY 4
79 #define COMPONENTS_INDEX_ARRAY 1
80 #define COMPONENTS_NORMAL_ARRAY 3
81 #define COMPONENTS_TANGENT_ARRAY 4
82 #define COMPONENTS_TEXCOORD_ARRAY 2
83 
84 #define DOWNSAMPLE_PASSES 5
85 #define DOWNSAMPLE_SCALE 2
86 
87 #define fbo_screen nullptr
88 #define fbo_render r_state.renderBuffer
89 #define fbo_bloom0 r_state.bloomBuffer0
90 #define fbo_bloom1 r_state.bloomBuffer1
91 
92 #define default_program nullptr
93 
94 struct mAliasMesh_s;
95 
96 typedef struct rstate_s {
97  bool fullscreen;
98 
99  /* arrays */
100  GLfloat* vertex_array_3d;
101  GLshort* vertex_array_2d;
102  GLfloat* color_array;
104  GLfloat* normal_array;
105  GLfloat* tangent_array;
109 
110  /* Size of all arrays above - it's dynamically reallocated */
112 
113  /* multitexture texunits */
115 
116  /* texunit in use */
118 
119  /* framebuffer objects*/
128 
129  /* shaders */
141 
142  /* blend function */
144 
146 
147  /* states */
166  const struct image_s* active_normalmap;
167 } rstate_t;
168 
169 extern rstate_t r_state;
170 
171 void R_SetDefaultState(void);
172 void R_Setup2D(void);
173 void R_Setup3D(void);
174 void R_ReallocateStateArrays(int size);
175 void R_ReallocateTexunitArray(gltexunit_t* texunit, int size);
176 
177 void R_TexEnv(GLenum value);
178 void R_TexOverride (vec4_t rgba);
179 void R_BlendFunc(GLenum src, GLenum dest);
180 
181 bool R_SelectTexture(gltexunit_t* texunit);
182 
183 void R_BindTextureDebug(int texnum, const char* file, int line, const char* function);
184 #define R_BindTexture(tn) R_BindTextureDebug(tn, __FILE__, __LINE__, __PRETTY_FUNCTION__)
189 void R_BindBuffer(GLenum target, GLenum type, GLuint id);
190 void R_BindArray(GLenum target, GLenum type, const void* array);
191 void R_BindDefaultArray(GLenum target);
192 void R_EnableStencilTest(bool enable);
193 void R_EnableTexture(gltexunit_t* texunit, bool enable);
194 void R_EnableMultisample(bool enable);
195 void R_EnableBlend(bool enable);
196 void R_EnableAlphaTest(bool enable);
197 void R_EnableColorArray(bool enable);
198 bool R_EnableLighting(r_program_t* program, bool enable);
199 void R_EnableBumpmap(const struct image_s* normalmap);
200 void R_EnableWarp(r_program_t* program, bool enable);
201 void R_EnableBlur(r_program_t* program, bool enable, r_framebuffer_t* source, r_framebuffer_t* dest, int dir);
202 void R_EnableShell(bool enable);
203 void R_EnableFog(bool enable);
204 void R_EnableDrawAsGlow(bool enable);
205 void R_EnableGlowMap(const struct image_s* image);
206 void R_EnableSpecularMap(const struct image_s* image, bool enable);
207 void R_EnableRoughnessMap(const struct image_s* image, bool enable);
208 void R_SetupSpotLight(int index, const light_t* light);
209 void R_DisableSpotLight(int index);
210 void R_EnableAnimation(const struct mAliasMesh_s* mesh, float backlerp, bool enable);
211 
212 void R_UseMaterial (const material_t* material);
void R_EnableBlur(r_program_t *program, bool enable, r_framebuffer_t *source, r_framebuffer_t *dest, int dir)
Definition: r_state.cpp:523
void R_EnableShell(bool enable)
Definition: r_state.cpp:551
r_program_t * warp_program
Definition: r_state.h:134
bool fog_enabled
Definition: r_state.h:156
#define MAX_GL_TEXUNITS
Definition: r_state.h:58
void R_BindArray(GLenum target, GLenum type, const void *array)
Definition: r_state.cpp:148
QGL_EXTERN GLint GLenum type
Definition: r_gl.h:94
void R_Setup2D(void)
Definition: r_state.cpp:825
void R_ReallocateStateArrays(int size)
Reallocate arrays of GL primitives if needed.
Definition: r_state.cpp:1029
r_framebuffer_t * buffers2[DOWNSAMPLE_PASSES]
Definition: r_state.h:125
void R_EnableBumpmap(const struct image_s *normalmap)
bool roughnessmap_enabled
Definition: r_state.h:162
void R_EnableRoughnessMap(const struct image_s *image, bool enable)
bool multisample_enabled
Definition: r_state.h:150
r_framebuffer_t * renderBuffer
Definition: r_state.h:120
r_program_t * atmosphere_program
Definition: r_state.h:138
r_program_t * active_program
Definition: r_state.h:140
void R_SetDefaultState(void)
Definition: r_state.cpp:860
GLfloat * vertex_array_3d
Definition: r_state.h:100
bool warp_enabled
Definition: r_state.h:155
const GLenum *typedef GLint
Definition: r_gl.h:205
void R_EnableFog(bool enable)
Definition: r_state.cpp:586
int array_size
Definition: r_state.h:55
GLfloat * normal_array
Definition: r_state.h:104
r_program_t * combine2_program
Definition: r_state.h:137
struct rstate_s rstate_t
GLenum texenv
Definition: r_state.h:52
void R_TexOverride(vec4_t rgba)
Sets special texture environment mode to override texture color; don't forget to call R_TexOverride(n...
Definition: r_state.cpp:968
GLenum texture
Definition: r_state.h:50
bool blur_enabled
Definition: r_state.h:157
bool R_EnableLighting(r_program_t *program, bool enable)
Enables hardware-accelerated lighting with the specified program. This should be called after any tex...
Definition: r_state.cpp:350
bool animation_enabled
Definition: r_state.h:163
QGL_EXTERN GLuint
Definition: r_gl.h:124
gltexunit_t texunits[MAX_GL_TEXUNITS]
Definition: r_state.h:114
a light source
Definition: r_light.h:29
bool renderbuffer_enabled
Definition: r_state.h:164
const GLuint *typedef GLuint *typedef GLenum
Definition: r_gl.h:190
void R_EnableMultisample(bool enable)
Definition: r_state.cpp:243
GLshort * vertex_array_2d
Definition: r_state.h:101
void R_EnableDrawAsGlow(bool enable)
Definition: r_state.cpp:692
void R_BindDeluxemapTexture(GLuint texnum)
Definition: r_state.cpp:95
bool lighting_enabled
Definition: r_state.h:154
void R_EnableAnimation(const struct mAliasMesh_s *mesh, float backlerp, bool enable)
const r_framebuffer_t * activeFramebuffer
Definition: r_state.h:127
GLfloat * tangent_array
Definition: r_state.h:105
GLenum blend_dest
Definition: r_state.h:143
r_framebuffer_t * bloomBuffer0
Definition: r_state.h:121
bool draw_glow_enabled
Definition: r_state.h:159
gltexunit_t * active_texunit
Definition: r_state.h:117
const vec2_t default_texcoords[4]
Definition: r_state.cpp:30
GLsizei size
Definition: r_gl.h:152
bool enabled
Definition: r_state.h:49
#define MAX_PROGRAMS
Definition: r_program.h:65
#define DOWNSAMPLE_PASSES
Definition: r_state.h:84
bool frameBufferObjectsInitialized
Definition: r_state.h:126
void R_TexEnv(GLenum value)
Definition: r_state.cpp:956
void R_SetupSpotLight(int index, const light_t *light)
Definition: r_state.cpp:376
int array_size
Definition: r_state.h:111
texunits maintain multitexture state
Definition: r_state.h:48
void R_EnableTexture(gltexunit_t *texunit, bool enable)
Definition: r_state.cpp:303
GLfloat * next_vertex_array_3d
Definition: r_state.h:106
void R_EnableBlend(bool enable)
Definition: r_state.cpp:261
r_program_t * geoscape_program
Definition: r_state.h:135
r_program_t programs[MAX_PROGRAMS]
Definition: r_state.h:131
GLint * index_array
Definition: r_state.h:103
void R_BindTextureDebug(int texnum, const char *file, int line, const char *function)
Definition: r_state.cpp:69
void R_BindBuffer(GLenum target, GLenum type, GLuint id)
Definition: r_state.cpp:213
void R_UseMaterial(const material_t *material)
Definition: r_state.cpp:105
QGL_EXTERN GLenum GLuint * dest
Definition: r_gl.h:101
bool R_SelectTexture(gltexunit_t *texunit)
Returns false if the texunit is not supported.
Definition: r_state.cpp:40
r_program_t * simple_glow_program
Definition: r_state.h:139
bool color_array_enabled
Definition: r_state.h:151
QGL_EXTERN GLuint index
Definition: r_gl.h:110
bool dynamic_lighting_enabled
Definition: r_state.h:160
void R_EnableAlphaTest(bool enable)
Definition: r_state.cpp:277
void R_EnableStencilTest(bool enable)
Definition: r_state.cpp:290
r_framebuffer_t * buffers0[DOWNSAMPLE_PASSES]
Definition: r_state.h:123
r_program_t * world_program
Definition: r_state.h:132
void R_BindLightmapTexture(GLuint texnum)
Definition: r_state.cpp:90
bool shell_enabled
Definition: r_state.h:148
r_framebuffer_t * bloomBuffer1
Definition: r_state.h:122
void R_BlendFunc(GLenum src, GLenum dest)
Definition: r_state.cpp:232
const material_t * active_material
Definition: r_state.h:145
r_shader_t shaders[MAX_SHADERS]
Definition: r_state.h:130
#define MAX_SHADERS
Definition: r_program.h:66
void R_Setup3D(void)
Definition: r_state.cpp:763
bool alpha_test_enabled
Definition: r_state.h:152
void R_EnableGlowMap(const struct image_s *image)
GLfloat * next_normal_array
Definition: r_state.h:107
GLenum blend_src
Definition: r_state.h:143
vec_t vec2_t[2]
Definition: ufotypes.h:38
void R_DisableSpotLight(int index)
Definition: r_state.cpp:403
bool fullscreen
Definition: r_state.h:97
r_program_t * model_program
Definition: r_state.h:133
bool glowmap_enabled
Definition: r_state.h:158
r_framebuffer_t * buffers1[DOWNSAMPLE_PASSES]
Definition: r_state.h:124
GLfloat * color_array
Definition: r_state.h:102
void R_EnableWarp(r_program_t *program, bool enable)
Definition: r_state.cpp:496
struct image_s * normalmap
Definition: r_image.h:69
void R_EnableSpecularMap(const struct image_s *image, bool enable)
r_program_t * convolve_program
Definition: r_state.h:136
bool stencil_test_enabled
Definition: r_state.h:153
bool specularmap_enabled
Definition: r_state.h:161
GLfloat * next_tangent_array
Definition: r_state.h:108
struct gltexunit_s gltexunit_t
texunits maintain multitexture state
bool blend_enabled
Definition: r_state.h:149
void R_ReallocateTexunitArray(gltexunit_t *texunit, int size)
Reallocate texcoord array of the specified texunit, if needed.
Definition: r_state.cpp:1059
rstate_t r_state
Definition: r_main.cpp:48
material_t material
Definition: r_image.h:68
void R_BindDefaultArray(GLenum target)
Binds the appropriate shared vertex array to the specified target.
Definition: r_state.cpp:182
const struct image_s * active_normalmap
Definition: r_state.h:166
GLint texnum
Definition: r_state.h:51
void R_EnableColorArray(bool enable)
Definition: r_state.cpp:332
void R_BindNormalmapTexture(GLuint texnum)
Definition: r_state.cpp:100
GLfloat * texcoord_array
Definition: r_state.h:53
void R_BindTextureForTexUnit(GLuint texnum, gltexunit_t *texunit)
Definition: r_state.cpp:77
Header file for the render material subsystem.
GLuint texnum
Definition: r_image.h:66
vec_t vec4_t[4]
Definition: ufotypes.h:40