]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_backend.c
Remove gl_dither cvar, it isn't supported in GL3.2 Core Profile.
[xonotic/darkplaces.git] / gl_backend.c
index 691f6eeb20703ab7aba01cc70a61b5193f70da89..73c011029e1f0158c884179fc16c0bdb64d0b767 100644 (file)
@@ -82,8 +82,6 @@ cvar_t r_render = {0, "r_render", "1", "enables rendering 3D views (you want thi
 cvar_t r_renderview = {0, "r_renderview", "1", "enables rendering 3D views (you want this on!)"};
 cvar_t r_waterwarp = {CVAR_SAVE, "r_waterwarp", "1", "warp view while underwater"};
 cvar_t gl_polyblend = {CVAR_SAVE, "gl_polyblend", "1", "tints view while underwater, hurt, etc"};
-cvar_t gl_dither = {CVAR_SAVE, "gl_dither", "1", "enables OpenGL dithering (16bit looks bad with this off)"};
-cvar_t gl_fbo = {CVAR_SAVE, "gl_fbo", "1", "make use of GL_ARB_framebuffer_object extension to enable shadowmaps and other features using pixel formats different from the framebuffer"};
 
 cvar_t v_flipped = {0, "v_flipped", "0", "mirror the screen (poor man's left handed mode)"};
 qboolean v_flipped_state = false;
@@ -1108,7 +1106,7 @@ void R_Mesh_SetRenderTargets(int fbo, rtexture_t *depthtexture, rtexture_t *colo
        // unbind any matching textures immediately, otherwise D3D will complain about a bound texture being used as a render target
        for (j = 0;j < 5;j++)
                if (textures[j])
-                       for (i = 0;i < vid.teximageunits;i++)
+                       for (i = 0;i < MAX_TEXTUREUNITS;i++)
                                if (gl_state.units[i].texture == textures[j])
                                        R_Mesh_TexBind(i, NULL);
        // set up framebuffer object or render targets for the active rendering API
@@ -1127,7 +1125,6 @@ void R_Mesh_SetRenderTargets(int fbo, rtexture_t *depthtexture, rtexture_t *colo
 
 static void GL_Backend_ResetState(void)
 {
-       unsigned int i;
        gl_state.active = true;
        gl_state.depthtest = true;
        gl_state.alphatest = false;
@@ -1171,18 +1168,6 @@ static void GL_Backend_ResetState(void)
                qglVertexAttrib4f(GLSLATTRIB_COLOR, 1, 1, 1, 1);
                gl_state.unit = MAX_TEXTUREUNITS;
                gl_state.clientunit = MAX_TEXTUREUNITS;
-               for (i = 0;i < vid.teximageunits;i++)
-               {
-                       GL_ActiveTexture(i);
-                       qglBindTexture(GL_TEXTURE_2D, 0);CHECKGLERROR
-                       qglBindTexture(GL_TEXTURE_3D, 0);CHECKGLERROR
-                       qglBindTexture(GL_TEXTURE_CUBE_MAP, 0);CHECKGLERROR
-               }
-               for (i = 0;i < vid.texarrayunits;i++)
-               {
-                       GL_BindVBO(0);
-                       qglDisableVertexAttribArray(i+GLSLATTRIB_TEXCOORD0);CHECKGLERROR
-               }
                CHECKGLERROR
                break;
        }
@@ -1655,8 +1640,7 @@ unsigned int GL_Backend_CompileProgram(int vertexstrings_count, const char **ver
        qglBindAttribLocation(programobject, GLSLATTRIB_TEXCOORD6, "Attrib_SkeletalIndex");
        qglBindAttribLocation(programobject, GLSLATTRIB_TEXCOORD7, "Attrib_SkeletalWeight");
 #ifndef USE_GLES2
-       if(vid.support.gl20shaders130)
-               qglBindFragDataLocation(programobject, 0, "dp_FragColor");
+       qglBindFragDataLocation(programobject, 0, "dp_FragColor");
 #endif
        CHECKGLERROR
 
@@ -2022,6 +2006,8 @@ void R_Mesh_ColorPointer(int components, int gltype, size_t stride, const void *
 void R_Mesh_TexCoordPointer(unsigned int unitnum, int components, int gltype, size_t stride, const void *pointer, const r_meshbuffer_t *vertexbuffer, size_t bufferoffset)
 {
        gltextureunit_t *unit = gl_state.units + unitnum;
+       if (unitnum >= MAX_TEXTUREUNITS)
+               Sys_Error("R_Mesh_TexCoordPointer: unitnum %i > max units %i\n", unitnum, MAX_TEXTUREUNITS);
        // update array settings
        // note: there is no need to check bufferobject here because all cases
        // that involve a valid bufferobject also supply a texcoord array
@@ -2069,8 +2055,8 @@ void R_Mesh_TexCoordPointer(unsigned int unitnum, int components, int gltype, si
 int R_Mesh_TexBound(unsigned int unitnum, int id)
 {
        gltextureunit_t *unit = gl_state.units + unitnum;
-       if (unitnum >= vid.teximageunits)
-               return 0;
+       if (unitnum >= MAX_TEXTUREUNITS)
+               Sys_Error("R_Mesh_TexCoordPointer: unitnum %i > max units %i\n", unitnum, MAX_TEXTUREUNITS);
        if (id == GL_TEXTURE_2D)
                return unit->t2d;
        if (id == GL_TEXTURE_3D)
@@ -2097,16 +2083,12 @@ void R_Mesh_ClearBindingsForTexture(int texnum)
 {
        gltextureunit_t *unit;
        unsigned int unitnum;
-       // this doesn't really unbind the texture, but it does prevent a mistaken "do nothing" behavior on the next time this same texnum is bound on the same unit as the same type (this mainly affects r_shadow_bouncegrid because 3D textures are so rarely used)
-       for (unitnum = 0;unitnum < vid.teximageunits;unitnum++)
+       // unbind the texture from any units it is bound on - this prevents accidental reuse of certain textures whose bindings can linger far too long otherwise (e.g. bouncegrid which is a 3D texture) and confuse the driver later.
+       for (unitnum = 0; unitnum < MAX_TEXTUREUNITS; unitnum++)
        {
                unit = gl_state.units + unitnum;
-               if (unit->t2d == texnum)
-                       unit->t2d = -1;
-               if (unit->t3d == texnum)
-                       unit->t3d = -1;
-               if (unit->tcubemap == texnum)
-                       unit->tcubemap = -1;
+               if (unit->texture && unit->texture->texnum == texnum)
+                       R_Mesh_TexBind(unitnum, NULL);
        }
 }
 
@@ -2114,8 +2096,8 @@ void R_Mesh_TexBind(unsigned int unitnum, rtexture_t *tex)
 {
        gltextureunit_t *unit = gl_state.units + unitnum;
        int texnum;
-       if (unitnum >= vid.teximageunits)
-               return;
+       if (unitnum >= MAX_TEXTUREUNITS)
+               Sys_Error("R_Mesh_TexBind: unitnum %i > max units %i\n", unitnum, MAX_TEXTUREUNITS);
        if (unit->texture == tex)
                return;
        switch(vid.renderpath)
@@ -2147,9 +2129,9 @@ void R_Mesh_ResetTextureState(void)
 
        BACKENDACTIVECHECK
 
-       for (unitnum = 0;unitnum < vid.teximageunits;unitnum++)
+       for (unitnum = 0;unitnum < MAX_TEXTUREUNITS;unitnum++)
                R_Mesh_TexBind(unitnum, NULL);
-       for (unitnum = 0;unitnum < vid.texarrayunits;unitnum++)
+       for (unitnum = 0;unitnum < MAX_TEXTUREUNITS;unitnum++)
                R_Mesh_TexCoordPointer(unitnum, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0);
 }