]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rmain.c
added polygonoffset as a texture property, used on submodels (such as
[xonotic/darkplaces.git] / gl_rmain.c
index 8e46d7be55c3604496d307fe3aeed52b8de16c63..a0bd28084ee083a6a055465552b310ca89e383dd 100644 (file)
@@ -61,6 +61,8 @@ cvar_t r_fullbrights = {CVAR_SAVE, "r_fullbrights", "1", "enables glowing pixels
 cvar_t r_shadows = {CVAR_SAVE, "r_shadows", "0", "casts fake stencil shadows from models onto the world (rtlights are unaffected by this)"};
 cvar_t r_shadows_throwdistance = {CVAR_SAVE, "r_shadows_throwdistance", "500", "how far to cast shadows from models"};
 cvar_t r_q1bsp_skymasking = {0, "r_q1bsp_skymasking", "1", "allows sky polygons in quake1 maps to obscure other geometry"};
+cvar_t r_polygonoffset_submodel_factor = {0, "r_polygonoffset_submodel_factor", "0", "biases depth values of world submodels such as doors, to prevent z-fighting artifacts in Quake maps"};
+cvar_t r_polygonoffset_submodel_offset = {0, "r_polygonoffset_submodel_offset", "2", "biases depth values of world submodels such as doors, to prevent z-fighting artifacts in Quake maps"};
 
 cvar_t gl_fogenable = {0, "gl_fogenable", "0", "nehahra fog enable (for Nehahra compatibility only)"};
 cvar_t gl_fogdensity = {0, "gl_fogdensity", "0.25", "nehahra fog density (recommend values below 0.1) (for Nehahra compatibility only)"};
@@ -1493,6 +1495,8 @@ void GL_Main_Init(void)
        Cvar_RegisterVariable(&r_shadows);
        Cvar_RegisterVariable(&r_shadows_throwdistance);
        Cvar_RegisterVariable(&r_q1bsp_skymasking);
+       Cvar_RegisterVariable(&r_polygonoffset_submodel_factor);
+       Cvar_RegisterVariable(&r_polygonoffset_submodel_offset);
        Cvar_RegisterVariable(&r_textureunits);
        Cvar_RegisterVariable(&r_glsl);
        Cvar_RegisterVariable(&r_glsl_offsetmapping);
@@ -1987,7 +1991,7 @@ void R_ResetViewRendering2D(void)
        GL_DepthTest(false);
        R_Mesh_Matrix(&identitymatrix);
        R_Mesh_ResetTextureState();
-       qglPolygonOffset(r_refdef.polygonfactor, r_refdef.polygonoffset);CHECKGLERROR
+       GL_PolygonOffset(0, 0);
        qglEnable(GL_POLYGON_OFFSET_FILL);CHECKGLERROR
        qglDepthFunc(GL_LEQUAL);CHECKGLERROR
        qglDisable(GL_STENCIL_TEST);CHECKGLERROR
@@ -2020,7 +2024,7 @@ void R_ResetViewRendering3D(void)
        GL_DepthTest(true);
        R_Mesh_Matrix(&identitymatrix);
        R_Mesh_ResetTextureState();
-       qglPolygonOffset(r_refdef.polygonfactor, r_refdef.polygonoffset);CHECKGLERROR
+       GL_PolygonOffset(r_refdef.polygonfactor, r_refdef.polygonoffset);
        qglEnable(GL_POLYGON_OFFSET_FILL);CHECKGLERROR
        qglDepthFunc(GL_LEQUAL);CHECKGLERROR
        qglDisable(GL_STENCIL_TEST);CHECKGLERROR
@@ -2734,6 +2738,7 @@ void R_DrawBBoxMesh(vec3_t mins, vec3_t maxs, float cr, float cg, float cb, floa
        GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        GL_DepthMask(false);
        GL_DepthRange(0, 1);
+       GL_PolygonOffset(r_refdef.polygonfactor, r_refdef.polygonoffset);
        R_Mesh_Matrix(&identitymatrix);
        R_Mesh_ResetTextureState();
 
@@ -2870,6 +2875,7 @@ void R_DrawNoModel_TransparentCallback(const entity_render_t *ent, const rtlight
                GL_DepthMask(true);
        }
        GL_DepthRange(0, (ent->flags & RENDER_VIEWMODEL) ? 0.0625 : 1);
+       GL_PolygonOffset(r_refdef.polygonfactor, r_refdef.polygonoffset);
        GL_DepthTest(!(ent->effects & EF_NODEPTHTEST));
        GL_CullFace((ent->effects & EF_DOUBLESIDED) ? GL_NONE : GL_FRONT); // quake is backwards, this culls back faces
        R_Mesh_VertexPointer(nomodelvertex3f, 0, 0);
@@ -2966,6 +2972,7 @@ void R_DrawSprite(int blendfunc1, int blendfunc2, rtexture_t *texture, rtexture_
 
        GL_DepthMask(false);
        GL_DepthRange(0, depthshort ? 0.0625 : 1);
+       GL_PolygonOffset(r_refdef.polygonfactor, r_refdef.polygonoffset);
        GL_DepthTest(!depthdisable);
 
        vertex3f[ 0] = origin[0] + left[0] * scalex2 + up[0] * scaley1;
@@ -3177,6 +3184,7 @@ void R_UpdateTextureInfo(const entity_render_t *ent, texture_t *t)
        model_t *model = ent->model;
        float f;
        float tcmat[12];
+       q3shaderinfo_layer_tcmod_t *tcmod;
 
        // switch to an alternate material if this is a q1bsp animated material
        {
@@ -3242,10 +3250,10 @@ void R_UpdateTextureInfo(const entity_render_t *ent, texture_t *t)
        if (t->backgroundnumskinframes && !(t->currentmaterialflags & MATERIALFLAGMASK_DEPTHSORTED))
                t->currentmaterialflags |= MATERIALFLAG_VERTEXTEXTUREBLEND;
 
-       for (i = 0;i < Q3MAXTCMODS && (t->tcmod[i] || i < 1);i++)
+       for (i = 0, tcmod = t->tcmods;i < Q3MAXTCMODS && (tcmod->tcmod || i < 1);i++, tcmod++)
        {
                matrix4x4_t matrix;
-               switch(t->tcmod[i])
+               switch(tcmod->tcmod)
                {
                case Q3TCMOD_COUNT:
                case Q3TCMOD_NONE:
@@ -3261,24 +3269,24 @@ void R_UpdateTextureInfo(const entity_render_t *ent, texture_t *t)
                        break;
                case Q3TCMOD_ROTATE:
                        Matrix4x4_CreateTranslate(&matrix, 0.5, 0.5, 0);
-                       Matrix4x4_ConcatRotate(&matrix, t->tcmod_parms[i][0] * r_refdef.time, 0, 0, 1);
+                       Matrix4x4_ConcatRotate(&matrix, tcmod->parms[0] * r_refdef.time, 0, 0, 1);
                        Matrix4x4_ConcatTranslate(&matrix, -0.5, -0.5, 0);
                        break;
                case Q3TCMOD_SCALE:
-                       Matrix4x4_CreateScale3(&matrix, t->tcmod_parms[i][0], t->tcmod_parms[i][1], 1);
+                       Matrix4x4_CreateScale3(&matrix, tcmod->parms[0], tcmod->parms[1], 1);
                        break;
                case Q3TCMOD_SCROLL:
-                       Matrix4x4_CreateTranslate(&matrix, t->tcmod_parms[i][0] * r_refdef.time, t->tcmod_parms[i][1] * r_refdef.time, 0);
+                       Matrix4x4_CreateTranslate(&matrix, tcmod->parms[0] * r_refdef.time, tcmod->parms[1] * r_refdef.time, 0);
                        break;
                case Q3TCMOD_STRETCH:
-                       f = 1.0f / R_EvaluateQ3WaveFunc(t->tcmod_wavefunc[i], t->tcmod_parms[i]);
+                       f = 1.0f / R_EvaluateQ3WaveFunc(tcmod->wavefunc, tcmod->waveparms);
                        Matrix4x4_CreateFromQuakeEntity(&matrix, 0.5f * (1 - f), 0.5 * (1 - f), 0, 0, 0, 0, f);
                        break;
                case Q3TCMOD_TRANSFORM:
-                       VectorSet(tcmat +  0, t->tcmod_parms[i][0], t->tcmod_parms[i][1], 0);
-                       VectorSet(tcmat +  3, t->tcmod_parms[i][2], t->tcmod_parms[i][3], 0);
+                       VectorSet(tcmat +  0, tcmod->parms[0], tcmod->parms[1], 0);
+                       VectorSet(tcmat +  3, tcmod->parms[2], tcmod->parms[3], 0);
                        VectorSet(tcmat +  6, 0                   , 0                , 1);
-                       VectorSet(tcmat +  9, t->tcmod_parms[i][4], t->tcmod_parms[i][5], 0);
+                       VectorSet(tcmat +  9, tcmod->parms[4], tcmod->parms[5], 0);
                        Matrix4x4_FromArray12FloatGL(&matrix, tcmat);
                        break;
                case Q3TCMOD_TURBULENT:
@@ -3319,6 +3327,18 @@ void R_UpdateTextureInfo(const entity_render_t *ent, texture_t *t)
                        t->specularscale = r_shadow_gloss2intensity.value;
        }
 
+       t->currentpolygonfactor = r_refdef.polygonfactor;
+       t->currentpolygonoffset = r_refdef.polygonoffset;
+       // submodels are biased to avoid z-fighting with world surfaces that they
+       // may be exactly overlapping (avoids z-fighting artifacts on certain
+       // doors and things in Quake maps)
+       if (ent->model->brush.submodel)
+       {
+               t->currentpolygonfactor = r_refdef.polygonfactor + r_polygonoffset_submodel_factor.value;
+               t->currentpolygonoffset = r_refdef.polygonoffset + r_polygonoffset_submodel_offset.value;
+       }
+
+       VectorClear(t->dlightcolor);
        t->currentnumlayers = 0;
        if (!(t->currentmaterialflags & MATERIALFLAG_NODRAW))
        {
@@ -3365,6 +3385,8 @@ void R_UpdateTextureInfo(const entity_render_t *ent, texture_t *t)
                                else
                                {
                                        float colorscale;
+                                       // set the color tint used for lights affecting this surface
+                                       VectorSet(t->dlightcolor, ent->colormod[0] * t->currentalpha, ent->colormod[1] * t->currentalpha, ent->colormod[2] * t->currentalpha);
                                        colorscale = 2;
                                        // q3bsp has no lightmap updates, so the lightstylevalue that
                                        // would normally be baked into the lightmap must be
@@ -3639,7 +3661,7 @@ void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generateta
        // if vertices are dynamic (animated models), generate them into the temporary rsurface.array_model* arrays and point rsurface.model* at them instead of the static data from the model itself
        if (rsurface.generatedvertex)
        {
-               if (rsurface.texture->tcgen == Q3TCGEN_ENVIRONMENT)
+               if (rsurface.texture->tcgen.tcgen == Q3TCGEN_ENVIRONMENT)
                        generatenormals = true;
                for (i = 0;i < Q3MAXDEFORMS;i++)
                {
@@ -3853,9 +3875,9 @@ void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generateta
                                        float *normal = (rsurface.array_deformednormal3f  + 3 * surface->num_firstvertex) + j*3;
                                        VectorScale((rsurface.vertex3f  + 3 * surface->num_firstvertex) + j*3, 0.98f, vertex);
                                        VectorCopy((rsurface.normal3f  + 3 * surface->num_firstvertex) + j*3, normal);
-                                       normal[0] += deform->deform_parms[0] * noise4f(      vertex[0], vertex[1], vertex[2], r_refdef.time * deform->deform_parms[1]);
-                                       normal[1] += deform->deform_parms[0] * noise4f( 98 + vertex[0], vertex[1], vertex[2], r_refdef.time * deform->deform_parms[1]);
-                                       normal[2] += deform->deform_parms[0] * noise4f(196 + vertex[0], vertex[1], vertex[2], r_refdef.time * deform->deform_parms[1]);
+                                       normal[0] += deform->parms[0] * noise4f(      vertex[0], vertex[1], vertex[2], r_refdef.time * deform->parms[1]);
+                                       normal[1] += deform->parms[0] * noise4f( 98 + vertex[0], vertex[1], vertex[2], r_refdef.time * deform->parms[1]);
+                                       normal[2] += deform->parms[0] * noise4f(196 + vertex[0], vertex[1], vertex[2], r_refdef.time * deform->parms[1]);
                                        VectorNormalize(normal);
                                }
                                Mod_BuildTextureVectorsFromNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface.vertex3f, rsurface.modeltexcoordtexture2f, rsurface.array_deformednormal3f, rsurface.modelelement3i + surface->num_firsttriangle * 3, rsurface.array_deformedsvector3f, rsurface.array_deformedtvector3f, r_smoothnormals_areaweighting.integer);
@@ -3872,13 +3894,13 @@ void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generateta
                        break;
                case Q3DEFORM_WAVE:
                        // deform vertex array to make wavey water and flags and such
-                       waveparms[0] = deform->deform_waveparms[0];
-                       waveparms[1] = deform->deform_waveparms[1];
-                       waveparms[2] = deform->deform_waveparms[2];
-                       waveparms[3] = deform->deform_waveparms[3];
+                       waveparms[0] = deform->waveparms[0];
+                       waveparms[1] = deform->waveparms[1];
+                       waveparms[2] = deform->waveparms[2];
+                       waveparms[3] = deform->waveparms[3];
                        // this is how a divisor of vertex influence on deformation
-                       animpos = deform->deform_parms[0] ? 1.0f / deform->deform_parms[0] : 100.0f;
-                       scale = R_EvaluateQ3WaveFunc(deform->deform_wavefunc, waveparms);
+                       animpos = deform->parms[0] ? 1.0f / deform->parms[0] : 100.0f;
+                       scale = R_EvaluateQ3WaveFunc(deform->wavefunc, waveparms);
                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                        {
                                const msurface_t *surface = texturesurfacelist[texturesurfaceindex];
@@ -3889,8 +3911,8 @@ void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generateta
                                        // if the wavefunc depends on time, evaluate it per-vertex
                                        if (waveparms[3])
                                        {
-                                               waveparms[2] = deform->deform_waveparms[2] + (vertex[0] + vertex[1] + vertex[2]) * animpos;
-                                               scale = R_EvaluateQ3WaveFunc(deform->deform_wavefunc, waveparms);
+                                               waveparms[2] = deform->waveparms[2] + (vertex[0] + vertex[1] + vertex[2]) * animpos;
+                                               scale = R_EvaluateQ3WaveFunc(deform->wavefunc, waveparms);
                                        }
                                        VectorMA(vertex, scale, (rsurface.normal3f  + 3 * surface->num_firstvertex) + j*3, vertex);
                                }
@@ -3906,7 +3928,7 @@ void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generateta
                                const msurface_t *surface = texturesurfacelist[texturesurfaceindex];
                                for (j = 0;j < surface->num_vertices;j++)
                                {
-                                       scale = sin((rsurface.modeltexcoordtexture2f[2 * (surface->num_firstvertex + j)] * deform->deform_parms[0] + r_refdef.time * deform->deform_parms[2])) * deform->deform_parms[1];
+                                       scale = sin((rsurface.modeltexcoordtexture2f[2 * (surface->num_firstvertex + j)] * deform->parms[0] + r_refdef.time * deform->parms[2])) * deform->parms[1];
                                        VectorMA(rsurface.vertex3f + 3 * (surface->num_firstvertex + j), scale, rsurface.normal3f + 3 * (surface->num_firstvertex + j), rsurface.array_deformedvertex3f + 3 * (surface->num_firstvertex + j));
                                }
                        }
@@ -3916,8 +3938,8 @@ void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generateta
                        break;
                case Q3DEFORM_MOVE:
                        // deform vertex array
-                       scale = R_EvaluateQ3WaveFunc(deform->deform_wavefunc, deform->deform_waveparms);
-                       VectorScale(deform->deform_parms, scale, waveparms);
+                       scale = R_EvaluateQ3WaveFunc(deform->wavefunc, deform->waveparms);
+                       VectorScale(deform->parms, scale, waveparms);
                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                        {
                                const msurface_t *surface = texturesurfacelist[texturesurfaceindex];
@@ -3931,7 +3953,7 @@ void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generateta
                }
        }
        // generate texcoords based on the chosen texcoord source
-       switch(rsurface.texture->tcgen)
+       switch(rsurface.texture->tcgen.tcgen)
        {
        default:
        case Q3TCGEN_TEXTURE:
@@ -3950,8 +3972,8 @@ void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generateta
                        const msurface_t *surface = texturesurfacelist[texturesurfaceindex];
                        for (j = 0, v1 = rsurface.modelvertex3f + 3 * surface->num_firstvertex, out_tc = rsurface.array_generatedtexcoordtexture2f + 2 * surface->num_firstvertex;j < surface->num_vertices;j++, v1 += 3, out_tc += 2)
                        {
-                               out_tc[0] = DotProduct(v1, rsurface.texture->tcgen_parms);
-                               out_tc[1] = DotProduct(v1, rsurface.texture->tcgen_parms + 3);
+                               out_tc[0] = DotProduct(v1, rsurface.texture->tcgen.parms);
+                               out_tc[1] = DotProduct(v1, rsurface.texture->tcgen.parms + 3);
                        }
                }
                rsurface.texcoordtexture2f               = rsurface.array_generatedtexcoordtexture2f;
@@ -3986,10 +4008,10 @@ void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generateta
        // and we only support that as the first one
        // (handling a mixture of turbulent and other tcmods would be problematic
        //  without punting it entirely to a software path)
-       if (rsurface.texture->tcmod[0] == Q3TCMOD_TURBULENT)
+       if (rsurface.texture->tcmods[0].tcmod == Q3TCMOD_TURBULENT)
        {
-               amplitude = rsurface.texture->tcmod_parms[0][1];
-               animpos = rsurface.texture->tcmod_parms[0][2] + r_refdef.time * rsurface.texture->tcmod_parms[0][3];
+               amplitude = rsurface.texture->tcmods[0].parms[1];
+               animpos = rsurface.texture->tcmods[0].parms[2] + r_refdef.time * rsurface.texture->tcmods[0].parms[3];
                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                {
                        const msurface_t *surface = texturesurfacelist[texturesurfaceindex];
@@ -4438,6 +4460,7 @@ static void RSurf_DrawBatch_GL11_VertexShade(int texturenumsurfaces, msurface_t
 static void R_DrawTextureSurfaceList_ShowSurfaces(int texturenumsurfaces, msurface_t **texturesurfacelist)
 {
        GL_DepthRange(0, (rsurface.texture->currentmaterialflags & MATERIALFLAG_SHORTDEPTHRANGE) ? 0.0625 : 1);
+       GL_PolygonOffset(rsurface.texture->currentpolygonfactor, rsurface.texture->currentpolygonoffset);
        GL_DepthTest(!(rsurface.texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST));
        GL_CullFace((rsurface.texture->currentmaterialflags & MATERIALFLAG_NOCULLFACE) ? GL_NONE : GL_FRONT); // quake is backwards, this culls back faces
        if (rsurface.mode != RSURFMODE_SHOWSURFACES)
@@ -4473,6 +4496,7 @@ static void R_DrawTextureSurfaceList_Sky(int texturenumsurfaces, msurface_t **te
                R_Mesh_Matrix(&rsurface.matrix);
        }
        GL_DepthRange(0, (rsurface.texture->currentmaterialflags & MATERIALFLAG_SHORTDEPTHRANGE) ? 0.0625 : 1);
+       GL_PolygonOffset(rsurface.texture->currentpolygonfactor, rsurface.texture->currentpolygonoffset);
        GL_DepthTest(!(rsurface.texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST));
        GL_CullFace((rsurface.texture->currentmaterialflags & MATERIALFLAG_NOCULLFACE) ? GL_NONE : GL_FRONT); // quake is backwards, this culls back faces
        GL_DepthMask(true);
@@ -4837,6 +4861,7 @@ static void R_DrawTextureSurfaceList(int texturenumsurfaces, msurface_t **textur
                        GL_Color(1,1,1,1);
                }
                GL_DepthRange(0, (rsurface.texture->currentmaterialflags & MATERIALFLAG_SHORTDEPTHRANGE) ? 0.0625 : 1);
+               GL_PolygonOffset(rsurface.texture->currentpolygonfactor, rsurface.texture->currentpolygonoffset);
                GL_CullFace((rsurface.texture->currentmaterialflags & MATERIALFLAG_NOCULLFACE) ? GL_NONE : GL_FRONT); // quake is backwards, this culls back faces
                GL_DepthTest(true);
                GL_BlendFunc(GL_ONE, GL_ZERO);
@@ -4856,6 +4881,7 @@ static void R_DrawTextureSurfaceList(int texturenumsurfaces, msurface_t **textur
                if (rsurface.mode != RSURFMODE_MULTIPASS)
                        rsurface.mode = RSURFMODE_MULTIPASS;
                GL_DepthRange(0, (rsurface.texture->currentmaterialflags & MATERIALFLAG_SHORTDEPTHRANGE) ? 0.0625 : 1);
+               GL_PolygonOffset(rsurface.texture->currentpolygonfactor, rsurface.texture->currentpolygonoffset);
                GL_DepthTest(true);
                GL_CullFace((rsurface.texture->currentmaterialflags & MATERIALFLAG_NOCULLFACE) ? GL_NONE : GL_FRONT); // quake is backwards, this culls back faces
                GL_BlendFunc(GL_ONE, GL_ZERO);
@@ -4907,6 +4933,7 @@ static void R_DrawTextureSurfaceList(int texturenumsurfaces, msurface_t **textur
                if (!writedepth && (rsurface.texture->currentmaterialflags & (MATERIALFLAG_BLENDED | MATERIALFLAG_ALPHATEST)))
                        writedepth = true;
                GL_DepthRange(0, (rsurface.texture->currentmaterialflags & MATERIALFLAG_SHORTDEPTHRANGE) ? 0.0625 : 1);
+               GL_PolygonOffset(rsurface.texture->currentpolygonfactor, rsurface.texture->currentpolygonoffset);
                GL_DepthTest(!(rsurface.texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST));
                GL_CullFace((rsurface.texture->currentmaterialflags & MATERIALFLAG_NOCULLFACE) ? GL_NONE : GL_FRONT); // quake is backwards, this culls back faces
                GL_BlendFunc(rsurface.texture->currentlayers[0].blendfunc1, rsurface.texture->currentlayers[0].blendfunc2);
@@ -5046,6 +5073,7 @@ void R_DrawLoc_Callback(const entity_render_t *ent, const rtlight_t *rtlight, in
        GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        GL_DepthMask(false);
        GL_DepthRange(0, 1);
+       GL_PolygonOffset(r_refdef.polygonfactor, r_refdef.polygonoffset);
        GL_DepthTest(true);
        GL_CullFace(GL_NONE);
        R_Mesh_Matrix(&identitymatrix);
@@ -5106,14 +5134,14 @@ void R_DrawCollisionBrushes(entity_render_t *ent)
        GL_DepthMask(false);
        GL_DepthRange(0, 1);
        GL_DepthTest(!r_showdisabledepthtest.integer);
-       qglPolygonOffset(r_refdef.polygonfactor + r_showcollisionbrushes_polygonfactor.value, r_refdef.polygonoffset + r_showcollisionbrushes_polygonoffset.value);CHECKGLERROR
+       GL_PolygonOffset(r_refdef.polygonfactor + r_showcollisionbrushes_polygonfactor.value, r_refdef.polygonoffset + r_showcollisionbrushes_polygonoffset.value);
        for (i = 0, brush = model->brush.data_brushes + model->firstmodelbrush;i < model->nummodelbrushes;i++, brush++)
                if (brush->colbrushf && brush->colbrushf->numtriangles)
                        R_DrawCollisionBrush(brush->colbrushf);
        for (i = 0, surface = model->data_surfaces + model->firstmodelsurface;i < model->nummodelsurfaces;i++, surface++)
                if (surface->num_collisiontriangles)
                        R_DrawCollisionSurface(ent, surface);
-       qglPolygonOffset(r_refdef.polygonfactor, r_refdef.polygonoffset);CHECKGLERROR
+       GL_PolygonOffset(r_refdef.polygonfactor, r_refdef.polygonoffset);
 }
 
 void R_DrawTrianglesAndNormals(entity_render_t *ent, qboolean drawtris, qboolean drawnormals, int flagsmask)
@@ -5126,6 +5154,7 @@ void R_DrawTrianglesAndNormals(entity_render_t *ent, qboolean drawtris, qboolean
        CHECKGLERROR
        GL_DepthRange(0, 1);
        GL_DepthTest(!r_showdisabledepthtest.integer);
+       GL_PolygonOffset(r_refdef.polygonfactor, r_refdef.polygonoffset);
        GL_DepthMask(true);
        GL_BlendFunc(GL_ONE, GL_ZERO);
        R_Mesh_ColorPointer(NULL, 0, 0);