31 {0.0, 0.0}, {1.0, 0.0}, {1.0, 1.0}, {0.0, 1.0}
42 if (texunit ==
r_state.active_texunit)
49 r_state.active_texunit = texunit;
51 qglActiveTexture(texunit->
texture);
52 qglClientActiveTexture(texunit->
texture);
58 if (texnum ==
r_state.active_texunit->texnum)
63 r_state.active_texunit->texnum = texnum;
72 Com_Printf(
"Bad texnum (%d) in: %s (%d): %s\n", texnum, file, line, function);
80 if (texnum == texunit->
texnum)
107 static float last_b, last_p, last_s, last_h;
110 if (
r_state.active_material == material)
117 r_state.active_material = material;
150 const int v =
static_cast<int>(target);
152 case GL_VERTEX_ARRAY:
155 case GL_TEXTURE_COORD_ARRAY:
161 case GL_NORMAL_ARRAY:
162 glNormalPointer(
type, 0, array);
184 const int v =
static_cast<int>(target);
186 case GL_VERTEX_ARRAY:
189 case GL_TEXTURE_COORD_ARRAY:
195 case GL_NORMAL_ARRAY:
221 if (target == GL_ELEMENT_ARRAY_BUFFER) {
222 qglBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
id);
225 qglBindBuffer(GL_ARRAY_BUFFER,
id);
240 glBlendFunc(src,
dest);
248 if (
r_state.multisample_enabled == enable)
251 r_state.multisample_enabled = enable;
254 glEnable(GL_MULTISAMPLE);
256 glDisable(GL_MULTISAMPLE);
263 if (
r_state.blend_enabled == enable)
266 r_state.blend_enabled = enable;
270 glDepthMask(GL_FALSE);
273 glDepthMask(GL_TRUE);
279 if (
r_state.alpha_test_enabled == enable)
282 r_state.alpha_test_enabled = enable;
285 glEnable(GL_ALPHA_TEST);
287 glDisable(GL_ALPHA_TEST);
292 if (
r_state.stencil_test_enabled == enable)
295 r_state.stencil_test_enabled = enable;
298 glEnable(GL_STENCIL_TEST);
300 glDisable(GL_STENCIL_TEST);
305 if (enable == texunit->
enabled)
314 glEnable(GL_TEXTURE_2D);
316 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
326 glDisable(GL_TEXTURE_2D);
327 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
334 if (
r_state.color_array_enabled == enable)
337 r_state.color_array_enabled = enable;
340 glEnableClientState(GL_COLOR_ARRAY);
342 glDisableClientState(GL_COLOR_ARRAY);
353 return r_state.lighting_enabled;
355 if (enable && (!program || !program->
id))
356 return r_state.lighting_enabled;
358 if (
r_state.lighting_enabled == enable &&
r_state.active_program == program)
359 return r_state.lighting_enabled;
361 r_state.lighting_enabled = enable;
366 glEnableClientState(GL_NORMAL_ARRAY);
368 glDisableClientState(GL_NORMAL_ARRAY);
373 return r_state.lighting_enabled;
378 const vec4_t blackColor = {0.0, 0.0, 0.0, 1.0};
391 glLightf(
index, GL_LINEAR_ATTENUATION, 0);
392 glLightf(
index, GL_QUADRATIC_ATTENUATION, 16.0 / (light->
radius * light->
radius));
397 glLightfv(
index, GL_POSITION, position);
398 glLightfv(
index, GL_AMBIENT, blackColor);
400 glLightfv(
index, GL_SPECULAR, blackColor);
405 const vec4_t blackColor = {0.0, 0.0, 0.0, 1.0};
417 glLightf(
index, GL_LINEAR_ATTENUATION, 0.0);
418 glLightf(
index, GL_QUADRATIC_ATTENUATION, 0.0);
419 glLightfv(
index, GL_AMBIENT, blackColor);
420 glLightfv(
index, GL_DIFFUSE, blackColor);
421 glLightfv(
index, GL_SPECULAR, blackColor);
435 r_state.animation_enabled = enable;
473 if (
r_state.active_normalmap == normalmap)
480 r_state.active_normalmap = normalmap;
484 if (!
r_state.active_normalmap) {
493 r_state.active_normalmap = normalmap;
501 if (enable && (!program || !program->
id))
512 glEnable(GL_TEXTURE_2D);
516 glDisable(GL_TEXTURE_2D);
528 if (enable && (!program || !program->
id))
539 float userdata[] = {
static_cast<float>(source->
width),
static_cast<float>(dir) };
553 if (enable ==
r_state.shell_enabled)
556 r_state.shell_enabled = enable;
559 glEnable(GL_POLYGON_OFFSET_FILL);
560 glPolygonOffset(-1.0, 1.0);
573 glPolygonOffset(0.0, 0.0);
574 glDisable(GL_POLYGON_OFFSET_FILL);
581#define FOG_START 300.0
582#define FOG_END 2500.0
598 glFogfv(GL_FOG_COLOR,
refdef.fogColor);
599 glFogf(GL_FOG_DENSITY,
refdef.fogColor[3]);
609 glFogf(GL_FOG_DENSITY, 0.0);
618#ifndef GL_VERSION_ES_CM_1_0
619 static GLenum glowRenderTarget = GL_COLOR_ATTACHMENT1_EXT;
623 if (
r_state.draw_glow_enabled) {
639 if (
r_state.draw_glow_enabled) {
643 if (!
r_state.glowmap_enabled) {
676 r_state.glowmap_enabled = !!image;
700 r_state.draw_glow_enabled = enable;
709 if (!
r_state.dynamic_lighting_enabled)
715 if (enable && image !=
nullptr) {
718 r_state.specularmap_enabled = enable;
721 r_state.specularmap_enabled =
false;
727 if (!
r_state.dynamic_lighting_enabled)
730 if (enable && image !=
nullptr) {
733 r_state.roughnessmap_enabled = enable;
736 r_state.roughnessmap_enabled =
false;
745 GLfloat xmin, xmax, ymin, ymax, yaspect = (float)
viddef.context.height /
viddef.context.width;
748 glOrtho(-10 *
refdef.fieldOfViewX, 10 *
refdef.fieldOfViewX, -10 *
refdef.fieldOfViewX * yaspect, 10 *
refdef.fieldOfViewX * yaspect, -zFar, zFar);
750 xmax = zNear * tan(
refdef.fieldOfViewX * (
M_PI / 360.0));
753 ymin = xmin * yaspect;
754 ymax = xmax * yaspect;
756 glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
767 int x, x2, y2, y, w, h;
778 glViewport(x, y2, w, h);
783 glMatrixMode(GL_PROJECTION);
791 x *= 2.0f / (float)
viddef.virtualWidth;
792 y *= 2.0f / (float)
viddef.virtualHeight;
793 glTranslatef(x, -y, 0.0f);
797 glMatrixMode(GL_MODELVIEW);
799 glRotatef(-90.0, 1.0, 0.0, 0.0);
800 glRotatef(90.0, 0.0, 0.0, 1.0);
801 glRotatef(-
refdef.viewAngles[2], 1.0, 0.0, 0.0);
802 glRotatef(-
refdef.viewAngles[0], 0.0, 1.0, 0.0);
803 glRotatef(-
refdef.viewAngles[1], 0.0, 0.0, 1.0);
807 glGetFloatv(GL_MODELVIEW_MATRIX,
r_locals.world_matrix);
814 glEnable(GL_DEPTH_TEST);
830 glViewport(0, 0,
viddef.context.width,
viddef.context.height);
833 glMatrixMode(GL_PROJECTION);
840 glMatrixMode(GL_MODELVIEW);
850 glDisable(GL_DEPTH_TEST);
852 glDisable(GL_LIGHTING);
864 r_state.color_array_enabled =
false;
865 r_state.alpha_test_enabled =
false;
866 r_state.stencil_test_enabled =
false;
867 r_state.lighting_enabled =
false;
871 r_state.glowmap_enabled =
false;
872 r_state.draw_glow_enabled =
false;
873 r_state.dynamic_lighting_enabled =
false;
874 r_state.specularmap_enabled =
false;
875 r_state.roughnessmap_enabled =
false;
876 r_state.animation_enabled =
false;
877 r_state.renderbuffer_enabled =
false;
878 r_state.active_material =
nullptr;
881 r_state.active_texunit =
nullptr;
883 glClearColor(0, 0, 0, 0);
885 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
895 glEnableClientState(GL_VERTEX_ARRAY);
902 glEnableClientState(GL_NORMAL_ARRAY);
904 glDisableClientState(GL_NORMAL_ARRAY);
931 glAlphaFunc(GL_GREATER, 0.01f);
934 glFogi(GL_FOG_MODE, GL_LINEAR);
939 glStencilFunc(GL_GEQUAL, 1, 0xff);
940 glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
943 glPolygonOffset(1, 1);
961 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,
mode);
974 glDisable(GL_TEXTURE_2D);
979 glEnable(GL_TEXTURE_2D);
986 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
988 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
990 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);
991 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);
993 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
995 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
997 glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, rgba);
1019 glColor4f(color[0], color[1], color[2], color[3]);
1066 r_state.active_texunit = texunit;
void Com_Printf(const char *const fmt,...)
#define MAX_WORLD_WIDTH
-MAX_WORLD_WIDTH up tp +MAX_WORLD_WIDTH
void glBindTexture(GLenum target, GLuint id)
#define Mem_SafeReAlloc(ptr, size)
void R_BindColorAttachments(unsigned int n, unsigned int *attachments)
Activate draw buffer(s).
void R_UseFramebuffer(const r_framebuffer_t *buf)
bind specified framebuffer object so we render to it
bool R_EnableRenderbuffer(bool enable)
Enable the render to the framebuffer.
void R_DrawBuffers(unsigned int drawBufferNum)
Activate draw buffer(s).
QGL_EXTERN GLenum GLuint * dest
#define GL_NEXT_TANGENT_ARRAY
#define GL_NEXT_VERTEX_ARRAY
QGL_EXTERN int GLboolean GLfloat * v
QGL_EXTERN GLint GLenum type
#define GL_NEXT_NORMAL_ARRAY
QGL_EXTERN const GLuint *QGL_EXTERN GLuint *QGL_EXTERN GLenum
void R_ClearStaticLights(void)
Remove all static light data.
local graphics definitions
#define MIN_GL_CONSTANT_ATTENUATION
cvar_t * r_dynamic_lights
material_t defaultMaterial
void R_ProgramParameter1i(const char *name, GLint value)
void R_EnableAttribute(const char *name)
void R_ProgramParameter2fv(const char *name, GLfloat *value)
void R_ProgramParameter1f(const char *name, GLfloat value)
void R_DisableAttribute(const char *name)
void R_AttributePointer(const char *name, GLuint size, const GLvoid *array)
void R_UseProgram(r_program_t *prog)
void R_ProgramParameter3fv(const char *name, GLfloat *value)
static void R_BindTexture_(int texnum)
void R_EnableAlphaTest(bool enable)
void R_BindBuffer(GLenum target, GLenum type, GLuint id)
void R_EnableTexture(gltexunit_t *texunit, bool enable)
void R_BindDefaultArray(GLenum target)
Binds the appropriate shared vertex array to the specified target.
void R_TexOverride(vec4_t rgba)
Sets special texture environment mode to override texture color; don't forget to call R_TexOverride(n...
void R_EnableGlowMap(const image_t *image)
void R_BlendFunc(GLenum src, GLenum dest)
void R_EnableDrawAsGlow(bool enable)
void R_SetDefaultState(void)
void R_EnableBlur(r_program_t *program, bool enable, r_framebuffer_t *source, r_framebuffer_t *dest, int dir)
void R_SetupSpotLight(int index, const light_t *light)
void R_EnableMultisample(bool enable)
static void R_UpdateGlowBufferBinding(void)
bool R_EnableLighting(r_program_t *program, bool enable)
Enables hardware-accelerated lighting with the specified program. This should be called after any tex...
bool R_SelectTexture(gltexunit_t *texunit)
Returns false if the texunit is not supported.
static void MYgluPerspective(GLfloat zNear, GLfloat zFar)
void R_BindLightmapTexture(GLuint texnum)
void R_DisableSpotLight(int index)
void R_BindDeluxemapTexture(GLuint texnum)
void R_UseMaterial(const material_t *material)
void R_EnableBumpmap(const image_t *normalmap)
Enables bumpmapping and binds the given normalmap.
void R_EnableWarp(r_program_t *program, bool enable)
void R_EnableBlend(bool enable)
void R_TexEnv(GLenum mode)
void R_EnableSpecularMap(const image_t *image, bool enable)
void R_EnableRoughnessMap(const image_t *image, bool enable)
const vec2_t default_texcoords[4]
void R_BindTextureForTexUnit(GLuint texnum, gltexunit_t *texunit)
void R_ReallocateTexunitArray(gltexunit_t *texunit, int size)
Reallocate texcoord array of the specified texunit, if needed.
void R_EnableShell(bool enable)
void R_EnableColorArray(bool enable)
void R_BindNormalmapTexture(GLuint texnum)
void R_Color(const vec4_t rgba)
Change the color to given value.
void R_EnableFog(bool enable)
void R_ReallocateStateArrays(int size)
Reallocate arrays of GL primitives if needed.
static r_program_t * lastProgram
void R_BindArray(GLenum target, GLenum type, const void *array)
void R_EnableAnimation(const mAliasMesh_t *mesh, float backlerp, bool enable)
Enables animation using keyframe interpolation on the GPU.
void R_EnableStencilTest(bool enable)
void R_BindTextureDebug(int texnum, const char *file, int line, const char *function)
#define COMPONENTS_NORMAL_ARRAY
#define GL_ARRAY_LENGTH_CHUNK
#define texunit_roughnessmap
#define COMPONENTS_VERTEX_ARRAY2D
#define texunit_deluxemap
#define texunit_specularmap
#define COMPONENTS_COLOR_ARRAY
#define SKYBOX_DEPTH
Center position of skybox along z-axis. This is used to make sure we see only the inside of Skybox.
#define COMPONENTS_VERTEX_ARRAY3D
#define COMPONENTS_TEXCOORD_ARRAY
#define COMPONENTS_INDEX_ARRAY
#define COMPONENTS_TANGENT_ARRAY
#define R_BindTexture(tn)
#define texunit_normalmap
texunits maintain multitexture state
#define VectorCopy(src, dest)