]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_backend.c
made deformvertexes autosprite2 work properly
[xonotic/darkplaces.git] / gl_backend.c
index 8b4dbdcbaf5bebff8d7dfc962fafc4a81e7966a0..8d3a8c3fdad82b981086048e1844b89e1360de60 100644 (file)
@@ -14,9 +14,9 @@ cvar_t gl_polyblend = {CVAR_SAVE, "gl_polyblend", "1", "tints view while underwa
 cvar_t gl_dither = {CVAR_SAVE, "gl_dither", "1", "enables OpenGL dithering (16bit looks bad with this off)"};
 cvar_t gl_lockarrays = {0, "gl_lockarrays", "0", "enables use of glLockArraysEXT, may cause glitches with some broken drivers, and may be slower than normal"};
 cvar_t gl_lockarrays_minimumvertices = {0, "gl_lockarrays_minimumvertices", "1", "minimum number of vertices required for use of glLockArraysEXT, setting this too low may reduce performance"};
-cvar_t gl_vbo = {0, "gl_vbo", "1", "make use of GL_ARB_vertex_buffer_object extension to store static geometry in video memory for faster rendering"};
+cvar_t gl_vbo = {CVAR_SAVE, "gl_vbo", "1", "make use of GL_ARB_vertex_buffer_object extension to store static geometry in video memory for faster rendering"};
 
-cvar_t v_flipped = {0, "v_flipped", "0", "mirror the screen (poor man's left handed mode"};
+cvar_t v_flipped = {0, "v_flipped", "0", "mirror the screen (poor man's left handed mode)"};
 qboolean v_flipped_state = false;
 
 int gl_maxdrawrangeelementsvertices;
@@ -270,10 +270,12 @@ void gl_backend_init(void)
        R_RegisterModule("GL_Backend", gl_backend_start, gl_backend_shutdown, gl_backend_newmap);
 }
 
+void GL_SetMirrorState(qboolean state);
+
 void GL_SetupView_Orientation_Identity (void)
 {
        backend_viewmatrix = identitymatrix;
-       v_flipped_state = false;
+       GL_SetMirrorState(false);
        memset(&backend_modelmatrix, 0, sizeof(backend_modelmatrix));
 }
 
@@ -285,7 +287,7 @@ void GL_SetupView_Orientation_FromEntity(const matrix4x4_t *matrix)
        Matrix4x4_ConcatRotate(&basematrix, 90, 0, 0, 1);
        Matrix4x4_Concat(&backend_viewmatrix, &basematrix, &tempmatrix);
 
-       v_flipped_state = v_flipped.integer;
+       GL_SetMirrorState(v_flipped.integer);
        if(v_flipped_state)
        {
                Matrix4x4_Transpose(&basematrix, &backend_viewmatrix);
@@ -394,6 +396,7 @@ static struct gl_state_s
        int colormask; // stored as bottom 4 bits: r g b a (3 2 1 0 order)
        int depthtest;
        float depthrange[2];
+       float polygonoffset[2];
        int alphatest;
        int scissortest;
        unsigned int unit;
@@ -544,8 +547,10 @@ void GL_Backend_ResetState(void)
        gl_state.color4f[0] = gl_state.color4f[1] = gl_state.color4f[2] = gl_state.color4f[3] = 1;
        gl_state.lockrange_first = 0;
        gl_state.lockrange_count = 0;
-       gl_state.cullface = GL_FRONT; // quake is backwards, this culls back faces
+       gl_state.cullface = v_flipped_state ? GL_BACK : GL_FRONT; // quake is backwards, this culls back faces
        gl_state.cullfaceenable = true;
+       gl_state.polygonoffset[0] = 0;
+       gl_state.polygonoffset[1] = 0;
 
        CHECKGLERROR
 
@@ -559,6 +564,7 @@ void GL_Backend_ResetState(void)
        qglDepthFunc(GL_LEQUAL);CHECKGLERROR
        qglEnable(GL_DEPTH_TEST);CHECKGLERROR
        qglDepthMask(gl_state.depthmask);CHECKGLERROR
+       qglPolygonOffset(gl_state.polygonoffset[0], gl_state.polygonoffset[1]);
 
        if (gl_support_arb_vertex_buffer_object)
        {
@@ -678,6 +684,29 @@ void GL_DepthRange(float nearfrac, float farfrac)
        }
 }
 
+void GL_PolygonOffset(float planeoffset, float depthoffset)
+{
+       if (gl_state.polygonoffset[0] != planeoffset || gl_state.polygonoffset[1] != depthoffset)
+       {
+               gl_state.polygonoffset[0] = planeoffset;
+               gl_state.polygonoffset[1] = depthoffset;
+               qglPolygonOffset(planeoffset, depthoffset);
+       }
+}
+
+void GL_SetMirrorState(qboolean state)
+{
+       if(!state != !v_flipped_state)
+       {
+               // change cull face mode!
+               if(gl_state.cullface == GL_BACK)
+                       qglCullFace((gl_state.cullface = GL_FRONT));
+               else if(gl_state.cullface == GL_FRONT)
+                       qglCullFace((gl_state.cullface = GL_BACK));
+       }
+       v_flipped_state = state;
+}
+
 void GL_CullFace(int state)
 {
        CHECKGLERROR